id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
230,700
cygnite/framework
src/Cygnite/FormBuilder/Html/Elements.php
Elements.dateTimeLocal
protected function dateTimeLocal($key, $attributes) { if (isset($attributes['value']) && $attributes['value'] instanceof \DateTime) { $attributes['value'] = $attributes['value']->format('Y-m-d H:m:s'); } return $this->composeElement($key, $attributes, ['type' => 'input'], true); }
php
protected function dateTimeLocal($key, $attributes) { if (isset($attributes['value']) && $attributes['value'] instanceof \DateTime) { $attributes['value'] = $attributes['value']->format('Y-m-d H:m:s'); } return $this->composeElement($key, $attributes, ['type' => 'input'], true); }
[ "protected", "function", "dateTimeLocal", "(", "$", "key", ",", "$", "attributes", ")", "{", "if", "(", "isset", "(", "$", "attributes", "[", "'value'", "]", ")", "&&", "$", "attributes", "[", "'value'", "]", "instanceof", "\\", "DateTime", ")", "{", "$", "attributes", "[", "'value'", "]", "=", "$", "attributes", "[", "'value'", "]", "->", "format", "(", "'Y-m-d H:m:s'", ")", ";", "}", "return", "$", "this", "->", "composeElement", "(", "$", "key", ",", "$", "attributes", ",", "[", "'type'", "=>", "'input'", "]", ",", "true", ")", ";", "}" ]
Create date time local box. @param $key @param $attributes @return Elements
[ "Create", "date", "time", "local", "box", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/FormBuilder/Html/Elements.php#L269-L276
230,701
cygnite/framework
src/Cygnite/FormBuilder/Html/Elements.php
Elements.attributes
protected function attributes($attributes) { $elementStr = ''; foreach ($attributes as $key => $value) { $elementStr .= ($key !== 0) ? "{$key}='{$value}' " : $value; } return $elementStr; }
php
protected function attributes($attributes) { $elementStr = ''; foreach ($attributes as $key => $value) { $elementStr .= ($key !== 0) ? "{$key}='{$value}' " : $value; } return $elementStr; }
[ "protected", "function", "attributes", "(", "$", "attributes", ")", "{", "$", "elementStr", "=", "''", ";", "foreach", "(", "$", "attributes", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "elementStr", ".=", "(", "$", "key", "!==", "0", ")", "?", "\"{$key}='{$value}' \"", ":", "$", "value", ";", "}", "return", "$", "elementStr", ";", "}" ]
Returns html element attributes as string. @param $attributes @return string
[ "Returns", "html", "element", "attributes", "as", "string", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/FormBuilder/Html/Elements.php#L284-L293
230,702
cygnite/framework
src/Cygnite/FormBuilder/Html/Elements.php
Elements.highlightErrorElement
protected function highlightErrorElement($key, $attributes) { $elClass = ''; if ( $this->validator instanceof ValidatorInterface && $this->validator->hasError($key) ) { preg_match_all("#class='([^\s]+)'#", $this->attributes($attributes), $matches); $elClass = "class='".implode(' ', array_merge([$this->errorInputClass], $matches[1]))."'"; unset($attributes['class']); } return [$elClass, $attributes]; }
php
protected function highlightErrorElement($key, $attributes) { $elClass = ''; if ( $this->validator instanceof ValidatorInterface && $this->validator->hasError($key) ) { preg_match_all("#class='([^\s]+)'#", $this->attributes($attributes), $matches); $elClass = "class='".implode(' ', array_merge([$this->errorInputClass], $matches[1]))."'"; unset($attributes['class']); } return [$elClass, $attributes]; }
[ "protected", "function", "highlightErrorElement", "(", "$", "key", ",", "$", "attributes", ")", "{", "$", "elClass", "=", "''", ";", "if", "(", "$", "this", "->", "validator", "instanceof", "ValidatorInterface", "&&", "$", "this", "->", "validator", "->", "hasError", "(", "$", "key", ")", ")", "{", "preg_match_all", "(", "\"#class='([^\\s]+)'#\"", ",", "$", "this", "->", "attributes", "(", "$", "attributes", ")", ",", "$", "matches", ")", ";", "$", "elClass", "=", "\"class='\"", ".", "implode", "(", "' '", ",", "array_merge", "(", "[", "$", "this", "->", "errorInputClass", "]", ",", "$", "matches", "[", "1", "]", ")", ")", ".", "\"'\"", ";", "unset", "(", "$", "attributes", "[", "'class'", "]", ")", ";", "}", "return", "[", "$", "elClass", ",", "$", "attributes", "]", ";", "}" ]
Highlight element which is failed validation. @param $key @param $attributes @return array
[ "Highlight", "element", "which", "is", "failed", "validation", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/FormBuilder/Html/Elements.php#L328-L341
230,703
teamreflex/TidalPHP
src/Tidal/Parts/Artist.php
Artist.getTopTracks
public function getTopTracks(array $options = []) { $deferred = new Deferred(); $options = Options::buildOptions(Options::$defaultOptions, $options, $this->tidal); $this->http->get( Options::replace(Endpoints::ARTIST_TOP_TRACKS, ['id' => $this->id]).$options )->then(function ($response) use ($deferred) { $tracks = new Collection(); foreach ($response['items'] as $track) { $tracks->push(new Track( $this->http, $this->tidal, $track )); } $deferred->resolve($tracks); }, function ($e) use ($deferred) { $deferred->reject($e); }); return $deferred->promise(); }
php
public function getTopTracks(array $options = []) { $deferred = new Deferred(); $options = Options::buildOptions(Options::$defaultOptions, $options, $this->tidal); $this->http->get( Options::replace(Endpoints::ARTIST_TOP_TRACKS, ['id' => $this->id]).$options )->then(function ($response) use ($deferred) { $tracks = new Collection(); foreach ($response['items'] as $track) { $tracks->push(new Track( $this->http, $this->tidal, $track )); } $deferred->resolve($tracks); }, function ($e) use ($deferred) { $deferred->reject($e); }); return $deferred->promise(); }
[ "public", "function", "getTopTracks", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "deferred", "=", "new", "Deferred", "(", ")", ";", "$", "options", "=", "Options", "::", "buildOptions", "(", "Options", "::", "$", "defaultOptions", ",", "$", "options", ",", "$", "this", "->", "tidal", ")", ";", "$", "this", "->", "http", "->", "get", "(", "Options", "::", "replace", "(", "Endpoints", "::", "ARTIST_TOP_TRACKS", ",", "[", "'id'", "=>", "$", "this", "->", "id", "]", ")", ".", "$", "options", ")", "->", "then", "(", "function", "(", "$", "response", ")", "use", "(", "$", "deferred", ")", "{", "$", "tracks", "=", "new", "Collection", "(", ")", ";", "foreach", "(", "$", "response", "[", "'items'", "]", "as", "$", "track", ")", "{", "$", "tracks", "->", "push", "(", "new", "Track", "(", "$", "this", "->", "http", ",", "$", "this", "->", "tidal", ",", "$", "track", ")", ")", ";", "}", "$", "deferred", "->", "resolve", "(", "$", "tracks", ")", ";", "}", ",", "function", "(", "$", "e", ")", "use", "(", "$", "deferred", ")", "{", "$", "deferred", "->", "reject", "(", "$", "e", ")", ";", "}", ")", ";", "return", "$", "deferred", "->", "promise", "(", ")", ";", "}" ]
Returns the artists top tracks. @param array $options An array of options. @return \React\Promise\Promise A collection of top tracks.
[ "Returns", "the", "artists", "top", "tracks", "." ]
5d4948c75ae483d4baf318d94ba338801ec50cfc
https://github.com/teamreflex/TidalPHP/blob/5d4948c75ae483d4baf318d94ba338801ec50cfc/src/Tidal/Parts/Artist.php#L34-L59
230,704
teamreflex/TidalPHP
src/Tidal/Parts/Artist.php
Artist.getVideos
public function getVideos(array $options = []) { $deferred = new Deferred(); $options = Options::buildOptions(Options::$defaultOptions, $options, $this->tidal); $this->http->get( Options::replace(Endpoints::ARTIST_VIDEOS, ['id' => $this->id]).$options )->then(function ($response) use ($deferred) { $videos = new Collection(); foreach ($response['items'] as $video) { $videos->push(new Video( $this->http, $this->tidal, $video )); } $deferred->resolve($videos); }, function ($e) use ($deferred) { $deferred->reject($e); }); return $deferred->promise(); }
php
public function getVideos(array $options = []) { $deferred = new Deferred(); $options = Options::buildOptions(Options::$defaultOptions, $options, $this->tidal); $this->http->get( Options::replace(Endpoints::ARTIST_VIDEOS, ['id' => $this->id]).$options )->then(function ($response) use ($deferred) { $videos = new Collection(); foreach ($response['items'] as $video) { $videos->push(new Video( $this->http, $this->tidal, $video )); } $deferred->resolve($videos); }, function ($e) use ($deferred) { $deferred->reject($e); }); return $deferred->promise(); }
[ "public", "function", "getVideos", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "deferred", "=", "new", "Deferred", "(", ")", ";", "$", "options", "=", "Options", "::", "buildOptions", "(", "Options", "::", "$", "defaultOptions", ",", "$", "options", ",", "$", "this", "->", "tidal", ")", ";", "$", "this", "->", "http", "->", "get", "(", "Options", "::", "replace", "(", "Endpoints", "::", "ARTIST_VIDEOS", ",", "[", "'id'", "=>", "$", "this", "->", "id", "]", ")", ".", "$", "options", ")", "->", "then", "(", "function", "(", "$", "response", ")", "use", "(", "$", "deferred", ")", "{", "$", "videos", "=", "new", "Collection", "(", ")", ";", "foreach", "(", "$", "response", "[", "'items'", "]", "as", "$", "video", ")", "{", "$", "videos", "->", "push", "(", "new", "Video", "(", "$", "this", "->", "http", ",", "$", "this", "->", "tidal", ",", "$", "video", ")", ")", ";", "}", "$", "deferred", "->", "resolve", "(", "$", "videos", ")", ";", "}", ",", "function", "(", "$", "e", ")", "use", "(", "$", "deferred", ")", "{", "$", "deferred", "->", "reject", "(", "$", "e", ")", ";", "}", ")", ";", "return", "$", "deferred", "->", "promise", "(", ")", ";", "}" ]
Returns the artists videos. @param array $options An array of options. @return \React\Promise\Promise A collection of top tracks.
[ "Returns", "the", "artists", "videos", "." ]
5d4948c75ae483d4baf318d94ba338801ec50cfc
https://github.com/teamreflex/TidalPHP/blob/5d4948c75ae483d4baf318d94ba338801ec50cfc/src/Tidal/Parts/Artist.php#L68-L93
230,705
teamreflex/TidalPHP
src/Tidal/Parts/Artist.php
Artist.getBiography
public function getBiography() { $deferred = new Deferred(); $options = Options::buildOptions([], [], $this->tidal); $this->http->get( Options::replace(Endpoints::ARTIST_BIO, ['id' => $this->id]).$options )->then(function ($response) use ($deferred) { $deferred->resolve(new Biography($this->http, $this->tidal, $response)); }, function ($e) use ($deferred) { $deferred->reject($e); }); return $deferred->promise(); }
php
public function getBiography() { $deferred = new Deferred(); $options = Options::buildOptions([], [], $this->tidal); $this->http->get( Options::replace(Endpoints::ARTIST_BIO, ['id' => $this->id]).$options )->then(function ($response) use ($deferred) { $deferred->resolve(new Biography($this->http, $this->tidal, $response)); }, function ($e) use ($deferred) { $deferred->reject($e); }); return $deferred->promise(); }
[ "public", "function", "getBiography", "(", ")", "{", "$", "deferred", "=", "new", "Deferred", "(", ")", ";", "$", "options", "=", "Options", "::", "buildOptions", "(", "[", "]", ",", "[", "]", ",", "$", "this", "->", "tidal", ")", ";", "$", "this", "->", "http", "->", "get", "(", "Options", "::", "replace", "(", "Endpoints", "::", "ARTIST_BIO", ",", "[", "'id'", "=>", "$", "this", "->", "id", "]", ")", ".", "$", "options", ")", "->", "then", "(", "function", "(", "$", "response", ")", "use", "(", "$", "deferred", ")", "{", "$", "deferred", "->", "resolve", "(", "new", "Biography", "(", "$", "this", "->", "http", ",", "$", "this", "->", "tidal", ",", "$", "response", ")", ")", ";", "}", ",", "function", "(", "$", "e", ")", "use", "(", "$", "deferred", ")", "{", "$", "deferred", "->", "reject", "(", "$", "e", ")", ";", "}", ")", ";", "return", "$", "deferred", "->", "promise", "(", ")", ";", "}" ]
Gets the artists biography. @return \React\Promise\Promise The artist's biography.
[ "Gets", "the", "artists", "biography", "." ]
5d4948c75ae483d4baf318d94ba338801ec50cfc
https://github.com/teamreflex/TidalPHP/blob/5d4948c75ae483d4baf318d94ba338801ec50cfc/src/Tidal/Parts/Artist.php#L100-L115
230,706
teamreflex/TidalPHP
src/Tidal/Parts/Artist.php
Artist.getSimilarArtists
public function getSimilarArtists(array $options = []) { $deferred = new Deferred(); $options = Options::buildOptions(Options::$defaultOptions, $options, $this->tidal); $this->http->get( Options::replace(Endpoints::ARTIST_SIMILAR, ['id' => $this->id]).$options )->then(function ($response) use ($deferred) { $artists = new Collection(); foreach ($response['items'] as $artist) { $artists->push(new Artist( $this->http, $this->tidal, $artist )); } $deferred->resolve($artists); }, function ($e) use ($deferred) { $deferred->reject($e); }); return $deferred->promise(); }
php
public function getSimilarArtists(array $options = []) { $deferred = new Deferred(); $options = Options::buildOptions(Options::$defaultOptions, $options, $this->tidal); $this->http->get( Options::replace(Endpoints::ARTIST_SIMILAR, ['id' => $this->id]).$options )->then(function ($response) use ($deferred) { $artists = new Collection(); foreach ($response['items'] as $artist) { $artists->push(new Artist( $this->http, $this->tidal, $artist )); } $deferred->resolve($artists); }, function ($e) use ($deferred) { $deferred->reject($e); }); return $deferred->promise(); }
[ "public", "function", "getSimilarArtists", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "deferred", "=", "new", "Deferred", "(", ")", ";", "$", "options", "=", "Options", "::", "buildOptions", "(", "Options", "::", "$", "defaultOptions", ",", "$", "options", ",", "$", "this", "->", "tidal", ")", ";", "$", "this", "->", "http", "->", "get", "(", "Options", "::", "replace", "(", "Endpoints", "::", "ARTIST_SIMILAR", ",", "[", "'id'", "=>", "$", "this", "->", "id", "]", ")", ".", "$", "options", ")", "->", "then", "(", "function", "(", "$", "response", ")", "use", "(", "$", "deferred", ")", "{", "$", "artists", "=", "new", "Collection", "(", ")", ";", "foreach", "(", "$", "response", "[", "'items'", "]", "as", "$", "artist", ")", "{", "$", "artists", "->", "push", "(", "new", "Artist", "(", "$", "this", "->", "http", ",", "$", "this", "->", "tidal", ",", "$", "artist", ")", ")", ";", "}", "$", "deferred", "->", "resolve", "(", "$", "artists", ")", ";", "}", ",", "function", "(", "$", "e", ")", "use", "(", "$", "deferred", ")", "{", "$", "deferred", "->", "reject", "(", "$", "e", ")", ";", "}", ")", ";", "return", "$", "deferred", "->", "promise", "(", ")", ";", "}" ]
Gets similar artists. @param array $options An array of options. @return \React\Promise\Promise The artist's similar artists.
[ "Gets", "similar", "artists", "." ]
5d4948c75ae483d4baf318d94ba338801ec50cfc
https://github.com/teamreflex/TidalPHP/blob/5d4948c75ae483d4baf318d94ba338801ec50cfc/src/Tidal/Parts/Artist.php#L124-L149
230,707
teamreflex/TidalPHP
src/Tidal/Parts/Artist.php
Artist.getAlbums
public function getAlbums(array $options = []) { $deferred = new Deferred(); // For some reason, TIDAL returns 404 if the filter isn't caps. if (isset($options['filter'])) { $options['filter'] = strtoupper($options['filter']); } $options = Options::buildOptions( array_merge(Options::$defaultOptions, ['filter' => 'COMPILATIONS']), $options, $this->tidal ); $this->http->get( Options::replace(Endpoints::ARTIST_ALBUMS, ['id' => $this->id]).$options )->then(function ($response) use ($deferred) { $albums = new Collection(); foreach ($response['items'] as $album) { $albums->push(new Album( $this->http, $this->tidal, $album )); } $deferred->resolve($albums); }, function ($e) use ($deferred) { $deferred->reject($e); }); return $deferred->promise(); }
php
public function getAlbums(array $options = []) { $deferred = new Deferred(); // For some reason, TIDAL returns 404 if the filter isn't caps. if (isset($options['filter'])) { $options['filter'] = strtoupper($options['filter']); } $options = Options::buildOptions( array_merge(Options::$defaultOptions, ['filter' => 'COMPILATIONS']), $options, $this->tidal ); $this->http->get( Options::replace(Endpoints::ARTIST_ALBUMS, ['id' => $this->id]).$options )->then(function ($response) use ($deferred) { $albums = new Collection(); foreach ($response['items'] as $album) { $albums->push(new Album( $this->http, $this->tidal, $album )); } $deferred->resolve($albums); }, function ($e) use ($deferred) { $deferred->reject($e); }); return $deferred->promise(); }
[ "public", "function", "getAlbums", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "deferred", "=", "new", "Deferred", "(", ")", ";", "// For some reason, TIDAL returns 404 if the filter isn't caps.", "if", "(", "isset", "(", "$", "options", "[", "'filter'", "]", ")", ")", "{", "$", "options", "[", "'filter'", "]", "=", "strtoupper", "(", "$", "options", "[", "'filter'", "]", ")", ";", "}", "$", "options", "=", "Options", "::", "buildOptions", "(", "array_merge", "(", "Options", "::", "$", "defaultOptions", ",", "[", "'filter'", "=>", "'COMPILATIONS'", "]", ")", ",", "$", "options", ",", "$", "this", "->", "tidal", ")", ";", "$", "this", "->", "http", "->", "get", "(", "Options", "::", "replace", "(", "Endpoints", "::", "ARTIST_ALBUMS", ",", "[", "'id'", "=>", "$", "this", "->", "id", "]", ")", ".", "$", "options", ")", "->", "then", "(", "function", "(", "$", "response", ")", "use", "(", "$", "deferred", ")", "{", "$", "albums", "=", "new", "Collection", "(", ")", ";", "foreach", "(", "$", "response", "[", "'items'", "]", "as", "$", "album", ")", "{", "$", "albums", "->", "push", "(", "new", "Album", "(", "$", "this", "->", "http", ",", "$", "this", "->", "tidal", ",", "$", "album", ")", ")", ";", "}", "$", "deferred", "->", "resolve", "(", "$", "albums", ")", ";", "}", ",", "function", "(", "$", "e", ")", "use", "(", "$", "deferred", ")", "{", "$", "deferred", "->", "reject", "(", "$", "e", ")", ";", "}", ")", ";", "return", "$", "deferred", "->", "promise", "(", ")", ";", "}" ]
Gets the artist's albums. @param array $options An array of options. @return \React\Promise\Promise The artist's albums.
[ "Gets", "the", "artist", "s", "albums", "." ]
5d4948c75ae483d4baf318d94ba338801ec50cfc
https://github.com/teamreflex/TidalPHP/blob/5d4948c75ae483d4baf318d94ba338801ec50cfc/src/Tidal/Parts/Artist.php#L158-L192
230,708
marein/php-nchan-client
src/HttpAdapter/HttpStreamWrapperClient.php
HttpStreamWrapperClient.request
private function request(string $method, Request $request): Response { $request = $this->credentials->authenticate($request); $url = $request->url()->toString(); $headers = $request->headers(); $body = $request->body(); $options = [ 'http' => [ 'method' => $method, 'header' => $this->prepareHeadersForStreamContext($headers), 'content' => $body, 'ignore_errors' => true ] ]; $context = stream_context_create($options); $responseBody = @file_get_contents( $url, false, $context ); if ($responseBody === false) { throw new NchanException('Unable to connect to ' . $url . '.'); } return HttpStreamWrapperResponse::fromResponse($http_response_header, $responseBody); }
php
private function request(string $method, Request $request): Response { $request = $this->credentials->authenticate($request); $url = $request->url()->toString(); $headers = $request->headers(); $body = $request->body(); $options = [ 'http' => [ 'method' => $method, 'header' => $this->prepareHeadersForStreamContext($headers), 'content' => $body, 'ignore_errors' => true ] ]; $context = stream_context_create($options); $responseBody = @file_get_contents( $url, false, $context ); if ($responseBody === false) { throw new NchanException('Unable to connect to ' . $url . '.'); } return HttpStreamWrapperResponse::fromResponse($http_response_header, $responseBody); }
[ "private", "function", "request", "(", "string", "$", "method", ",", "Request", "$", "request", ")", ":", "Response", "{", "$", "request", "=", "$", "this", "->", "credentials", "->", "authenticate", "(", "$", "request", ")", ";", "$", "url", "=", "$", "request", "->", "url", "(", ")", "->", "toString", "(", ")", ";", "$", "headers", "=", "$", "request", "->", "headers", "(", ")", ";", "$", "body", "=", "$", "request", "->", "body", "(", ")", ";", "$", "options", "=", "[", "'http'", "=>", "[", "'method'", "=>", "$", "method", ",", "'header'", "=>", "$", "this", "->", "prepareHeadersForStreamContext", "(", "$", "headers", ")", ",", "'content'", "=>", "$", "body", ",", "'ignore_errors'", "=>", "true", "]", "]", ";", "$", "context", "=", "stream_context_create", "(", "$", "options", ")", ";", "$", "responseBody", "=", "@", "file_get_contents", "(", "$", "url", ",", "false", ",", "$", "context", ")", ";", "if", "(", "$", "responseBody", "===", "false", ")", "{", "throw", "new", "NchanException", "(", "'Unable to connect to '", ".", "$", "url", ".", "'.'", ")", ";", "}", "return", "HttpStreamWrapperResponse", "::", "fromResponse", "(", "$", "http_response_header", ",", "$", "responseBody", ")", ";", "}" ]
Perform a request. @param string $method @param Request $request @return Response @throws NchanException
[ "Perform", "a", "request", "." ]
958d7ccb06e49139f3bf720ff3f1bd9dbe33caa9
https://github.com/marein/php-nchan-client/blob/958d7ccb06e49139f3bf720ff3f1bd9dbe33caa9/src/HttpAdapter/HttpStreamWrapperClient.php#L73-L104
230,709
marein/php-nchan-client
src/HttpAdapter/HttpStreamWrapperClient.php
HttpStreamWrapperClient.prepareHeadersForStreamContext
private function prepareHeadersForStreamContext(array $headers): string { return implode("\r\n", array_map(function (string $name, string $value) { return $name . ': ' . $value; }, array_keys($headers), $headers)); }
php
private function prepareHeadersForStreamContext(array $headers): string { return implode("\r\n", array_map(function (string $name, string $value) { return $name . ': ' . $value; }, array_keys($headers), $headers)); }
[ "private", "function", "prepareHeadersForStreamContext", "(", "array", "$", "headers", ")", ":", "string", "{", "return", "implode", "(", "\"\\r\\n\"", ",", "array_map", "(", "function", "(", "string", "$", "name", ",", "string", "$", "value", ")", "{", "return", "$", "name", ".", "': '", ".", "$", "value", ";", "}", ",", "array_keys", "(", "$", "headers", ")", ",", "$", "headers", ")", ")", ";", "}" ]
Prepare the given headers for stream context. Transform the array from [ 'firstHeaderName' => 'firstHeaderValue', 'secondHeaderName' => 'secondHeaderValue' ] to string "firstHeaderName: firstHeaderValue\r\n secondHeaderName: secondHeaderValue". @param array $headers @return string
[ "Prepare", "the", "given", "headers", "for", "stream", "context", "." ]
958d7ccb06e49139f3bf720ff3f1bd9dbe33caa9
https://github.com/marein/php-nchan-client/blob/958d7ccb06e49139f3bf720ff3f1bd9dbe33caa9/src/HttpAdapter/HttpStreamWrapperClient.php#L122-L127
230,710
cygnite/framework
src/Cygnite/Http/CsrfValidator.php
CsrfValidator.setTokenIntoSession
public function setTokenIntoSession() { $token = $this->getRandomToken(); if (empty($this->storage->csrf_tokens)) { $this->storage->csrf_tokens = []; } $this->storage->csrf_tokens = [trim($token) => true]; $this->token = $token; }
php
public function setTokenIntoSession() { $token = $this->getRandomToken(); if (empty($this->storage->csrf_tokens)) { $this->storage->csrf_tokens = []; } $this->storage->csrf_tokens = [trim($token) => true]; $this->token = $token; }
[ "public", "function", "setTokenIntoSession", "(", ")", "{", "$", "token", "=", "$", "this", "->", "getRandomToken", "(", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "storage", "->", "csrf_tokens", ")", ")", "{", "$", "this", "->", "storage", "->", "csrf_tokens", "=", "[", "]", ";", "}", "$", "this", "->", "storage", "->", "csrf_tokens", "=", "[", "trim", "(", "$", "token", ")", "=>", "true", "]", ";", "$", "this", "->", "token", "=", "$", "token", ";", "}" ]
Set unique token for the form and store into session.
[ "Set", "unique", "token", "for", "the", "form", "and", "store", "into", "session", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Http/CsrfValidator.php#L70-L81
230,711
cygnite/framework
src/Cygnite/Http/CsrfValidator.php
CsrfValidator.validateToken
public function validateToken($token) { /* | Return false if given token is not string */ if (!is_string($token)) { return false; } if (isset($this->storage->csrf_tokens[$token])) { $this->storage->csrf_tokens = [trim($token) => null]; return true; } return false; }
php
public function validateToken($token) { /* | Return false if given token is not string */ if (!is_string($token)) { return false; } if (isset($this->storage->csrf_tokens[$token])) { $this->storage->csrf_tokens = [trim($token) => null]; return true; } return false; }
[ "public", "function", "validateToken", "(", "$", "token", ")", "{", "/*\n | Return false if given token is not string\n */", "if", "(", "!", "is_string", "(", "$", "token", ")", ")", "{", "return", "false", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "storage", "->", "csrf_tokens", "[", "$", "token", "]", ")", ")", "{", "$", "this", "->", "storage", "->", "csrf_tokens", "=", "[", "trim", "(", "$", "token", ")", "=>", "null", "]", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Validate token and return boolean value if matched with input. @param $token @return bool
[ "Validate", "token", "and", "return", "boolean", "value", "if", "matched", "with", "input", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Http/CsrfValidator.php#L152-L168
230,712
cygnite/framework
src/Cygnite/Console/Generator/View.php
View.generateLayout
public function generateLayout($layout) { $layout = Inflector::toDirectorySeparator($layout); $file = $this->getViewTemplatePath().$layout.DS.$this->viewLayoutName(); $appViewPath = ''; $appViewPath = $this->command->applicationDir.DS.'Views'.DS; $this->hasDirectory($appViewPath); $this->hasDirectory($appViewPath.'layouts'); $this->hasDirectory($appViewPath.DS.$layout); file_exists($file) or die("Base layout stub file doesn't exists in Cygnite Core"); $layoutFile = $appViewPath.$layout.DS.$this->viewLayoutName(); if ($this->layoutType == 'php') { $layoutFile = str_replace('.stub', EXT, $layoutFile); } else { $layoutFile = str_replace('.stub', '.twig', $layoutFile); } if (file_exists($layoutFile)) { echo "\n Layout file already exists in $layoutFile directory \n"; return true; } /*read operation ->*/ // Open the file to get existing content $fileContent = file_get_contents($file); $handle = null; $handle = fopen($layoutFile, 'w') or die('Cannot open file: '.$layoutFile); fwrite($handle, $fileContent); fclose($handle); }
php
public function generateLayout($layout) { $layout = Inflector::toDirectorySeparator($layout); $file = $this->getViewTemplatePath().$layout.DS.$this->viewLayoutName(); $appViewPath = ''; $appViewPath = $this->command->applicationDir.DS.'Views'.DS; $this->hasDirectory($appViewPath); $this->hasDirectory($appViewPath.'layouts'); $this->hasDirectory($appViewPath.DS.$layout); file_exists($file) or die("Base layout stub file doesn't exists in Cygnite Core"); $layoutFile = $appViewPath.$layout.DS.$this->viewLayoutName(); if ($this->layoutType == 'php') { $layoutFile = str_replace('.stub', EXT, $layoutFile); } else { $layoutFile = str_replace('.stub', '.twig', $layoutFile); } if (file_exists($layoutFile)) { echo "\n Layout file already exists in $layoutFile directory \n"; return true; } /*read operation ->*/ // Open the file to get existing content $fileContent = file_get_contents($file); $handle = null; $handle = fopen($layoutFile, 'w') or die('Cannot open file: '.$layoutFile); fwrite($handle, $fileContent); fclose($handle); }
[ "public", "function", "generateLayout", "(", "$", "layout", ")", "{", "$", "layout", "=", "Inflector", "::", "toDirectorySeparator", "(", "$", "layout", ")", ";", "$", "file", "=", "$", "this", "->", "getViewTemplatePath", "(", ")", ".", "$", "layout", ".", "DS", ".", "$", "this", "->", "viewLayoutName", "(", ")", ";", "$", "appViewPath", "=", "''", ";", "$", "appViewPath", "=", "$", "this", "->", "command", "->", "applicationDir", ".", "DS", ".", "'Views'", ".", "DS", ";", "$", "this", "->", "hasDirectory", "(", "$", "appViewPath", ")", ";", "$", "this", "->", "hasDirectory", "(", "$", "appViewPath", ".", "'layouts'", ")", ";", "$", "this", "->", "hasDirectory", "(", "$", "appViewPath", ".", "DS", ".", "$", "layout", ")", ";", "file_exists", "(", "$", "file", ")", "or", "die", "(", "\"Base layout stub file doesn't exists in Cygnite Core\"", ")", ";", "$", "layoutFile", "=", "$", "appViewPath", ".", "$", "layout", ".", "DS", ".", "$", "this", "->", "viewLayoutName", "(", ")", ";", "if", "(", "$", "this", "->", "layoutType", "==", "'php'", ")", "{", "$", "layoutFile", "=", "str_replace", "(", "'.stub'", ",", "EXT", ",", "$", "layoutFile", ")", ";", "}", "else", "{", "$", "layoutFile", "=", "str_replace", "(", "'.stub'", ",", "'.twig'", ",", "$", "layoutFile", ")", ";", "}", "if", "(", "file_exists", "(", "$", "layoutFile", ")", ")", "{", "echo", "\"\\n Layout file already exists in $layoutFile directory \\n\"", ";", "return", "true", ";", "}", "/*read operation ->*/", "// Open the file to get existing content", "$", "fileContent", "=", "file_get_contents", "(", "$", "file", ")", ";", "$", "handle", "=", "null", ";", "$", "handle", "=", "fopen", "(", "$", "layoutFile", ",", "'w'", ")", "or", "die", "(", "'Cannot open file: '", ".", "$", "layoutFile", ")", ";", "fwrite", "(", "$", "handle", ",", "$", "fileContent", ")", ";", "fclose", "(", "$", "handle", ")", ";", "}" ]
We will get the layout and generate into the application directory. @param $layout @return bool
[ "We", "will", "get", "the", "layout", "and", "generate", "into", "the", "application", "directory", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Console/Generator/View.php#L134-L172
230,713
cygnite/framework
src/Cygnite/Console/Generator/View.php
View.readContents
private function readContents($view, $page = '') { file_exists($view) or die("View Template File doesn't exists"); $content = ''; /*read operation ->*/ $this->filePointer = fopen($view, 'r'); $content = fread($this->filePointer, filesize($view)); switch ($page) { case 'index': $content = $this->replaceIndexTemplateContents($content); break; case 'create': case 'update': $content = $this->replaceCreateOrUpdateTemplateContents($content); break; case 'show': $content = $this->replaceViewTemplateContents($content); break; } $this->replacedContent = $content; }
php
private function readContents($view, $page = '') { file_exists($view) or die("View Template File doesn't exists"); $content = ''; /*read operation ->*/ $this->filePointer = fopen($view, 'r'); $content = fread($this->filePointer, filesize($view)); switch ($page) { case 'index': $content = $this->replaceIndexTemplateContents($content); break; case 'create': case 'update': $content = $this->replaceCreateOrUpdateTemplateContents($content); break; case 'show': $content = $this->replaceViewTemplateContents($content); break; } $this->replacedContent = $content; }
[ "private", "function", "readContents", "(", "$", "view", ",", "$", "page", "=", "''", ")", "{", "file_exists", "(", "$", "view", ")", "or", "die", "(", "\"View Template File doesn't exists\"", ")", ";", "$", "content", "=", "''", ";", "/*read operation ->*/", "$", "this", "->", "filePointer", "=", "fopen", "(", "$", "view", ",", "'r'", ")", ";", "$", "content", "=", "fread", "(", "$", "this", "->", "filePointer", ",", "filesize", "(", "$", "view", ")", ")", ";", "switch", "(", "$", "page", ")", "{", "case", "'index'", ":", "$", "content", "=", "$", "this", "->", "replaceIndexTemplateContents", "(", "$", "content", ")", ";", "break", ";", "case", "'create'", ":", "case", "'update'", ":", "$", "content", "=", "$", "this", "->", "replaceCreateOrUpdateTemplateContents", "(", "$", "content", ")", ";", "break", ";", "case", "'show'", ":", "$", "content", "=", "$", "this", "->", "replaceViewTemplateContents", "(", "$", "content", ")", ";", "break", ";", "}", "$", "this", "->", "replacedContent", "=", "$", "content", ";", "}" ]
Read template view contents. @param $view @param string $page
[ "Read", "template", "view", "contents", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Console/Generator/View.php#L180-L203
230,714
cygnite/framework
src/Cygnite/Console/Generator/View.php
View.generateViews
public function generateViews() { $viewPath = $viewExtension = ''; $viewDir = $this->command->applicationDir.DS.'Views'.DS.$this->controller; $this->hasDirectory($viewDir); $viewExtension = ($this->layoutType == 'php') ? self::EXTENSION : self::TWIG_EXTENSION; $viewType = ($this->layoutType == 'php') ? 'Php'.DS : ''; foreach ($this->views as $key => $view) { $viewPath = $this->viewTemplatePath.'controller'.DS.$viewType.$view.self::TEMP_EXTENSION; $this->readContents($viewPath, $view); $this->generate($view.$viewExtension); } }
php
public function generateViews() { $viewPath = $viewExtension = ''; $viewDir = $this->command->applicationDir.DS.'Views'.DS.$this->controller; $this->hasDirectory($viewDir); $viewExtension = ($this->layoutType == 'php') ? self::EXTENSION : self::TWIG_EXTENSION; $viewType = ($this->layoutType == 'php') ? 'Php'.DS : ''; foreach ($this->views as $key => $view) { $viewPath = $this->viewTemplatePath.'controller'.DS.$viewType.$view.self::TEMP_EXTENSION; $this->readContents($viewPath, $view); $this->generate($view.$viewExtension); } }
[ "public", "function", "generateViews", "(", ")", "{", "$", "viewPath", "=", "$", "viewExtension", "=", "''", ";", "$", "viewDir", "=", "$", "this", "->", "command", "->", "applicationDir", ".", "DS", ".", "'Views'", ".", "DS", ".", "$", "this", "->", "controller", ";", "$", "this", "->", "hasDirectory", "(", "$", "viewDir", ")", ";", "$", "viewExtension", "=", "(", "$", "this", "->", "layoutType", "==", "'php'", ")", "?", "self", "::", "EXTENSION", ":", "self", "::", "TWIG_EXTENSION", ";", "$", "viewType", "=", "(", "$", "this", "->", "layoutType", "==", "'php'", ")", "?", "'Php'", ".", "DS", ":", "''", ";", "foreach", "(", "$", "this", "->", "views", "as", "$", "key", "=>", "$", "view", ")", "{", "$", "viewPath", "=", "$", "this", "->", "viewTemplatePath", ".", "'controller'", ".", "DS", ".", "$", "viewType", ".", "$", "view", ".", "self", "::", "TEMP_EXTENSION", ";", "$", "this", "->", "readContents", "(", "$", "viewPath", ",", "$", "view", ")", ";", "$", "this", "->", "generate", "(", "$", "view", ".", "$", "viewExtension", ")", ";", "}", "}" ]
generate views into application directory.
[ "generate", "views", "into", "application", "directory", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Console/Generator/View.php#L208-L222
230,715
cygnite/framework
src/Cygnite/Console/Generator/View.php
View.replaceIndexTemplateContents
private function replaceIndexTemplateContents($content) { /* Index View Page */ //replace table headers - <th> {%tableColumns%}</th> //replace table td - {%controllerColumns%} $content = str_replace('#controllerName#', $this->controller, $content); $content = str_replace('#ControllerName#', Inflector::classify($this->controller), $content); $content = str_replace('{%primaryKey%}', $this->command->table()->getPrimaryKey(), $content ); $column = ''; $column = $this->replaceTableElements('th'); $content = str_replace('{#thColumns#}', $column.PHP_EOL, $content); $column = $this->replaceTableElements('td'); $content = str_replace('{#tdColumns#}', $column.PHP_EOL, $content); return $content; }
php
private function replaceIndexTemplateContents($content) { /* Index View Page */ //replace table headers - <th> {%tableColumns%}</th> //replace table td - {%controllerColumns%} $content = str_replace('#controllerName#', $this->controller, $content); $content = str_replace('#ControllerName#', Inflector::classify($this->controller), $content); $content = str_replace('{%primaryKey%}', $this->command->table()->getPrimaryKey(), $content ); $column = ''; $column = $this->replaceTableElements('th'); $content = str_replace('{#thColumns#}', $column.PHP_EOL, $content); $column = $this->replaceTableElements('td'); $content = str_replace('{#tdColumns#}', $column.PHP_EOL, $content); return $content; }
[ "private", "function", "replaceIndexTemplateContents", "(", "$", "content", ")", "{", "/* Index View Page */", "//replace table headers - <th> {%tableColumns%}</th>", "//replace table td - {%controllerColumns%}", "$", "content", "=", "str_replace", "(", "'#controllerName#'", ",", "$", "this", "->", "controller", ",", "$", "content", ")", ";", "$", "content", "=", "str_replace", "(", "'#ControllerName#'", ",", "Inflector", "::", "classify", "(", "$", "this", "->", "controller", ")", ",", "$", "content", ")", ";", "$", "content", "=", "str_replace", "(", "'{%primaryKey%}'", ",", "$", "this", "->", "command", "->", "table", "(", ")", "->", "getPrimaryKey", "(", ")", ",", "$", "content", ")", ";", "$", "column", "=", "''", ";", "$", "column", "=", "$", "this", "->", "replaceTableElements", "(", "'th'", ")", ";", "$", "content", "=", "str_replace", "(", "'{#thColumns#}'", ",", "$", "column", ".", "PHP_EOL", ",", "$", "content", ")", ";", "$", "column", "=", "$", "this", "->", "replaceTableElements", "(", "'td'", ")", ";", "$", "content", "=", "str_replace", "(", "'{#tdColumns#}'", ",", "$", "column", ".", "PHP_EOL", ",", "$", "content", ")", ";", "return", "$", "content", ";", "}" ]
Replace the index content with template content. @param $content @return mixed
[ "Replace", "the", "index", "content", "with", "template", "content", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Console/Generator/View.php#L231-L253
230,716
cygnite/framework
src/Cygnite/Console/Generator/View.php
View.replaceTableElements
private function replaceTableElements($type = 'th') { $column = ''; foreach ($this->getTableColumns() as $key => $value) { if ($value['COLUMN_NAME'] !== 'id') { if ($type == 'th') { $tableHead = Inflector::underscoreToSpace($value['COLUMN_NAME']); $column .= "\t\t\t".'<'.$type.'>'.$tableHead.'</'.$type.'>'.PHP_EOL; } else { $rowType = ''; if ($this->layoutType == 'php') { $rowType = '<?php echo $row->'.$value['COLUMN_NAME'].'; ?>'; } else { $rowType = '{{row.'.$value['COLUMN_NAME'].'}}'; } $column .= "\t\t\t".'<'.$type.'>'.$rowType.'</'.$type.'>'.PHP_EOL; } } } return $column; }
php
private function replaceTableElements($type = 'th') { $column = ''; foreach ($this->getTableColumns() as $key => $value) { if ($value['COLUMN_NAME'] !== 'id') { if ($type == 'th') { $tableHead = Inflector::underscoreToSpace($value['COLUMN_NAME']); $column .= "\t\t\t".'<'.$type.'>'.$tableHead.'</'.$type.'>'.PHP_EOL; } else { $rowType = ''; if ($this->layoutType == 'php') { $rowType = '<?php echo $row->'.$value['COLUMN_NAME'].'; ?>'; } else { $rowType = '{{row.'.$value['COLUMN_NAME'].'}}'; } $column .= "\t\t\t".'<'.$type.'>'.$rowType.'</'.$type.'>'.PHP_EOL; } } } return $column; }
[ "private", "function", "replaceTableElements", "(", "$", "type", "=", "'th'", ")", "{", "$", "column", "=", "''", ";", "foreach", "(", "$", "this", "->", "getTableColumns", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "[", "'COLUMN_NAME'", "]", "!==", "'id'", ")", "{", "if", "(", "$", "type", "==", "'th'", ")", "{", "$", "tableHead", "=", "Inflector", "::", "underscoreToSpace", "(", "$", "value", "[", "'COLUMN_NAME'", "]", ")", ";", "$", "column", ".=", "\"\\t\\t\\t\"", ".", "'<'", ".", "$", "type", ".", "'>'", ".", "$", "tableHead", ".", "'</'", ".", "$", "type", ".", "'>'", ".", "PHP_EOL", ";", "}", "else", "{", "$", "rowType", "=", "''", ";", "if", "(", "$", "this", "->", "layoutType", "==", "'php'", ")", "{", "$", "rowType", "=", "'<?php echo $row->'", ".", "$", "value", "[", "'COLUMN_NAME'", "]", ".", "'; ?>'", ";", "}", "else", "{", "$", "rowType", "=", "'{{row.'", ".", "$", "value", "[", "'COLUMN_NAME'", "]", ".", "'}}'", ";", "}", "$", "column", ".=", "\"\\t\\t\\t\"", ".", "'<'", ".", "$", "type", ".", "'>'", ".", "$", "rowType", ".", "'</'", ".", "$", "type", ".", "'>'", ".", "PHP_EOL", ";", "}", "}", "}", "return", "$", "column", ";", "}" ]
Replace table content with database columns. @param string $type @return string
[ "Replace", "table", "content", "with", "database", "columns", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Console/Generator/View.php#L262-L284
230,717
ctbsea/phalapi-smarty
src/Smarty/sysplugins/smarty_template_source.php
Smarty_Template_Source.render
public function render(Smarty_Internal_Template $_template) { if ($_template->source->handler->uncompiled) { if ($_template->smarty->debugging) { $_template->smarty->_debug->start_render($_template); } $this->handler->renderUncompiled($_template->source, $_template); if (isset($_template->parent) && $_template->parent->_objType == 2 && !empty($_template->tpl_function)) { $_template->parent->tpl_function = array_merge($_template->parent->tpl_function, $_template->tpl_function); } if ($_template->smarty->debugging) { $_template->smarty->_debug->end_render($_template); } } }
php
public function render(Smarty_Internal_Template $_template) { if ($_template->source->handler->uncompiled) { if ($_template->smarty->debugging) { $_template->smarty->_debug->start_render($_template); } $this->handler->renderUncompiled($_template->source, $_template); if (isset($_template->parent) && $_template->parent->_objType == 2 && !empty($_template->tpl_function)) { $_template->parent->tpl_function = array_merge($_template->parent->tpl_function, $_template->tpl_function); } if ($_template->smarty->debugging) { $_template->smarty->_debug->end_render($_template); } } }
[ "public", "function", "render", "(", "Smarty_Internal_Template", "$", "_template", ")", "{", "if", "(", "$", "_template", "->", "source", "->", "handler", "->", "uncompiled", ")", "{", "if", "(", "$", "_template", "->", "smarty", "->", "debugging", ")", "{", "$", "_template", "->", "smarty", "->", "_debug", "->", "start_render", "(", "$", "_template", ")", ";", "}", "$", "this", "->", "handler", "->", "renderUncompiled", "(", "$", "_template", "->", "source", ",", "$", "_template", ")", ";", "if", "(", "isset", "(", "$", "_template", "->", "parent", ")", "&&", "$", "_template", "->", "parent", "->", "_objType", "==", "2", "&&", "!", "empty", "(", "$", "_template", "->", "tpl_function", ")", ")", "{", "$", "_template", "->", "parent", "->", "tpl_function", "=", "array_merge", "(", "$", "_template", "->", "parent", "->", "tpl_function", ",", "$", "_template", "->", "tpl_function", ")", ";", "}", "if", "(", "$", "_template", "->", "smarty", "->", "debugging", ")", "{", "$", "_template", "->", "smarty", "->", "_debug", "->", "end_render", "(", "$", "_template", ")", ";", "}", "}", "}" ]
Render uncompiled source @param \Smarty_Internal_Template $_template
[ "Render", "uncompiled", "source" ]
4d40da3e4482c0749f3cfd1605265a109a1c495f
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_template_source.php#L228-L243
230,718
ctbsea/phalapi-smarty
src/Smarty/sysplugins/smarty_template_source.php
Smarty_Template_Source.getTimeStamp
public function getTimeStamp() { if (!isset($this->timestamp)) { $this->handler->populateTimestamp($this); } return $this->timestamp; }
php
public function getTimeStamp() { if (!isset($this->timestamp)) { $this->handler->populateTimestamp($this); } return $this->timestamp; }
[ "public", "function", "getTimeStamp", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "timestamp", ")", ")", "{", "$", "this", "->", "handler", "->", "populateTimestamp", "(", "$", "this", ")", ";", "}", "return", "$", "this", "->", "timestamp", ";", "}" ]
Get source time stamp @return int
[ "Get", "source", "time", "stamp" ]
4d40da3e4482c0749f3cfd1605265a109a1c495f
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_template_source.php#L250-L256
230,719
ctbsea/phalapi-smarty
src/Smarty/sysplugins/smarty_template_source.php
Smarty_Template_Source.getContent
public function getContent() { return isset($this->content) ? $this->content : $this->handler->getContent($this); }
php
public function getContent() { return isset($this->content) ? $this->content : $this->handler->getContent($this); }
[ "public", "function", "getContent", "(", ")", "{", "return", "isset", "(", "$", "this", "->", "content", ")", "?", "$", "this", "->", "content", ":", "$", "this", "->", "handler", "->", "getContent", "(", "$", "this", ")", ";", "}" ]
Get source content @return string
[ "Get", "source", "content" ]
4d40da3e4482c0749f3cfd1605265a109a1c495f
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_template_source.php#L263-L266
230,720
jdesrosiers/silex-swagger-provider
src/SwaggerServiceProvider.php
SwaggerServiceProvider.register
public function register(Application $app) { $app["swagger.apiDocPath"] = "/api/api-docs"; $app["swagger.excludePath"] = array(); $app["swagger.prettyPrint"] = true; $app["swagger.cache"] = array(); $app["swagger.basePath"] = null; $app["swagger.apiVersion"] = null; $app["swagger.swaggerVersion"] = "1.2"; $app["swagger.resourcePrefix"] = "/"; $app["swagger.resourceSuffix"] = ""; $app["swagger"] = $app->share(new SwaggerService()); }
php
public function register(Application $app) { $app["swagger.apiDocPath"] = "/api/api-docs"; $app["swagger.excludePath"] = array(); $app["swagger.prettyPrint"] = true; $app["swagger.cache"] = array(); $app["swagger.basePath"] = null; $app["swagger.apiVersion"] = null; $app["swagger.swaggerVersion"] = "1.2"; $app["swagger.resourcePrefix"] = "/"; $app["swagger.resourceSuffix"] = ""; $app["swagger"] = $app->share(new SwaggerService()); }
[ "public", "function", "register", "(", "Application", "$", "app", ")", "{", "$", "app", "[", "\"swagger.apiDocPath\"", "]", "=", "\"/api/api-docs\"", ";", "$", "app", "[", "\"swagger.excludePath\"", "]", "=", "array", "(", ")", ";", "$", "app", "[", "\"swagger.prettyPrint\"", "]", "=", "true", ";", "$", "app", "[", "\"swagger.cache\"", "]", "=", "array", "(", ")", ";", "$", "app", "[", "\"swagger.basePath\"", "]", "=", "null", ";", "$", "app", "[", "\"swagger.apiVersion\"", "]", "=", "null", ";", "$", "app", "[", "\"swagger.swaggerVersion\"", "]", "=", "\"1.2\"", ";", "$", "app", "[", "\"swagger.resourcePrefix\"", "]", "=", "\"/\"", ";", "$", "app", "[", "\"swagger.resourceSuffix\"", "]", "=", "\"\"", ";", "$", "app", "[", "\"swagger\"", "]", "=", "$", "app", "->", "share", "(", "new", "SwaggerService", "(", ")", ")", ";", "}" ]
Registers the swagger service @param Application $app
[ "Registers", "the", "swagger", "service" ]
47ed21b10965ef14372aa0d42049d88038851345
https://github.com/jdesrosiers/silex-swagger-provider/blob/47ed21b10965ef14372aa0d42049d88038851345/src/SwaggerServiceProvider.php#L43-L56
230,721
ctbsea/phalapi-smarty
src/Smarty/sysplugins/smarty_internal_runtime_getincludepath.php
Smarty_Internal_Runtime_GetIncludePath.isNewIncludePath
public function isNewIncludePath(Smarty $smarty) { $_i_path = get_include_path(); if ($this->_include_path != $_i_path) { $this->_include_dirs = array(); $this->_include_path = $_i_path; $_dirs = (array) explode(PATH_SEPARATOR, $_i_path); foreach ($_dirs as $_path) { if (is_dir($_path)) { $this->_include_dirs[] = $smarty->_realpath($_path . DS, true); } } return true; } return false; }
php
public function isNewIncludePath(Smarty $smarty) { $_i_path = get_include_path(); if ($this->_include_path != $_i_path) { $this->_include_dirs = array(); $this->_include_path = $_i_path; $_dirs = (array) explode(PATH_SEPARATOR, $_i_path); foreach ($_dirs as $_path) { if (is_dir($_path)) { $this->_include_dirs[] = $smarty->_realpath($_path . DS, true); } } return true; } return false; }
[ "public", "function", "isNewIncludePath", "(", "Smarty", "$", "smarty", ")", "{", "$", "_i_path", "=", "get_include_path", "(", ")", ";", "if", "(", "$", "this", "->", "_include_path", "!=", "$", "_i_path", ")", "{", "$", "this", "->", "_include_dirs", "=", "array", "(", ")", ";", "$", "this", "->", "_include_path", "=", "$", "_i_path", ";", "$", "_dirs", "=", "(", "array", ")", "explode", "(", "PATH_SEPARATOR", ",", "$", "_i_path", ")", ";", "foreach", "(", "$", "_dirs", "as", "$", "_path", ")", "{", "if", "(", "is_dir", "(", "$", "_path", ")", ")", "{", "$", "this", "->", "_include_dirs", "[", "]", "=", "$", "smarty", "->", "_realpath", "(", "$", "_path", ".", "DS", ",", "true", ")", ";", "}", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check if include path was updated @param \Smarty $smarty @return bool
[ "Check", "if", "include", "path", "was", "updated" ]
4d40da3e4482c0749f3cfd1605265a109a1c495f
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_internal_runtime_getincludepath.php#L81-L96
230,722
cygnite/framework
src/Cygnite/Cache/Storage/MemCache.php
MemCache.create
public function create($host = '', $port = '') { $this->host = ($host != '') ? $host : 'localhost'; $this->port = ($port != '') ? $port : 11211; if (is_null($this->memory)) { $this->memory = new \Memcache(); $this->isEnabled = true; if (!$this->memory->connect($this->host, $this->port)) { // Instead 'localhost' here can be IP $this->memory = null; $this->isEnabled = true; } } return $this; }
php
public function create($host = '', $port = '') { $this->host = ($host != '') ? $host : 'localhost'; $this->port = ($port != '') ? $port : 11211; if (is_null($this->memory)) { $this->memory = new \Memcache(); $this->isEnabled = true; if (!$this->memory->connect($this->host, $this->port)) { // Instead 'localhost' here can be IP $this->memory = null; $this->isEnabled = true; } } return $this; }
[ "public", "function", "create", "(", "$", "host", "=", "''", ",", "$", "port", "=", "''", ")", "{", "$", "this", "->", "host", "=", "(", "$", "host", "!=", "''", ")", "?", "$", "host", ":", "'localhost'", ";", "$", "this", "->", "port", "=", "(", "$", "port", "!=", "''", ")", "?", "$", "port", ":", "11211", ";", "if", "(", "is_null", "(", "$", "this", "->", "memory", ")", ")", "{", "$", "this", "->", "memory", "=", "new", "\\", "Memcache", "(", ")", ";", "$", "this", "->", "isEnabled", "=", "true", ";", "if", "(", "!", "$", "this", "->", "memory", "->", "connect", "(", "$", "this", "->", "host", ",", "$", "this", "->", "port", ")", ")", "{", "// Instead 'localhost' here can be IP", "$", "this", "->", "memory", "=", "null", ";", "$", "this", "->", "isEnabled", "=", "true", ";", "}", "}", "return", "$", "this", ";", "}" ]
Connect memcache based on its host and port. Connect with default port if hostname and port number not passed. @false string $host @false mix $port @param string $host @param string $port @return void
[ "Connect", "memcache", "based", "on", "its", "host", "and", "port", ".", "Connect", "with", "default", "port", "if", "hostname", "and", "port", "number", "not", "passed", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Cache/Storage/MemCache.php#L65-L81
230,723
franzliedke/lti
src/Storage/AbstractStorage.php
AbstractStorage.quoted
public static function quoted($value, $addQuotes = true) { if (is_null($value)) { $value = 'NULL'; } else { $value = str_replace('\'', '\'\'', $value); if ($addQuotes) { $value = "'{$value}'"; } } return $value; }
php
public static function quoted($value, $addQuotes = true) { if (is_null($value)) { $value = 'NULL'; } else { $value = str_replace('\'', '\'\'', $value); if ($addQuotes) { $value = "'{$value}'"; } } return $value; }
[ "public", "static", "function", "quoted", "(", "$", "value", ",", "$", "addQuotes", "=", "true", ")", "{", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "$", "value", "=", "'NULL'", ";", "}", "else", "{", "$", "value", "=", "str_replace", "(", "'\\''", ",", "'\\'\\''", ",", "$", "value", ")", ";", "if", "(", "$", "addQuotes", ")", "{", "$", "value", "=", "\"'{$value}'\"", ";", "}", "}", "return", "$", "value", ";", "}" ]
Quote a string for use in a database query. Any single quotes in the value passed will be replaced with two single quotes. If a null value is passed, a string of 'NULL' is returned (which will never be enclosed in quotes irrespective of the value of the $addQuotes parameter. @param string $value Value to be quoted @param string $addQuotes If true the returned string will be enclosed in single quotes (optional, default is true) @return boolean True if the user object was successfully deleted
[ "Quote", "a", "string", "for", "use", "in", "a", "database", "query", "." ]
131cf331f2cb87fcc29049ac739c8751e9e5133b
https://github.com/franzliedke/lti/blob/131cf331f2cb87fcc29049ac739c8751e9e5133b/src/Storage/AbstractStorage.php#L310-L322
230,724
cygnite/framework
src/Cygnite/Common/Input/Input.php
Input.cookie
public function cookie(Closure $callback = null) { if ($callback instanceof CookieInterface) { return Cookie::create($callback); } return Cookie::create(); }
php
public function cookie(Closure $callback = null) { if ($callback instanceof CookieInterface) { return Cookie::create($callback); } return Cookie::create(); }
[ "public", "function", "cookie", "(", "Closure", "$", "callback", "=", "null", ")", "{", "if", "(", "$", "callback", "instanceof", "CookieInterface", ")", "{", "return", "Cookie", "::", "create", "(", "$", "callback", ")", ";", "}", "return", "Cookie", "::", "create", "(", ")", ";", "}" ]
Sets or returns the cookie variable value.
[ "Sets", "or", "returns", "the", "cookie", "variable", "value", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Common/Input/Input.php#L226-L233
230,725
ctbsea/phalapi-smarty
src/Smarty/sysplugins/smarty_internal_method_getdebugtemplate.php
Smarty_Internal_Method_GetDebugTemplate.getDebugTemplate
public function getDebugTemplate(Smarty_Internal_TemplateBase $obj) { $smarty = isset($obj->smarty) ? $obj->smarty : $obj; return $smarty->debug_tpl; }
php
public function getDebugTemplate(Smarty_Internal_TemplateBase $obj) { $smarty = isset($obj->smarty) ? $obj->smarty : $obj; return $smarty->debug_tpl; }
[ "public", "function", "getDebugTemplate", "(", "Smarty_Internal_TemplateBase", "$", "obj", ")", "{", "$", "smarty", "=", "isset", "(", "$", "obj", "->", "smarty", ")", "?", "$", "obj", "->", "smarty", ":", "$", "obj", ";", "return", "$", "smarty", "->", "debug_tpl", ";", "}" ]
return name of debugging template @api Smarty::getDebugTemplate() @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj @return string
[ "return", "name", "of", "debugging", "template" ]
4d40da3e4482c0749f3cfd1605265a109a1c495f
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_internal_method_getdebugtemplate.php#L30-L34
230,726
cygnite/framework
src/Cygnite/Common/Zip.php
Zip.zipDirectory
public function zipDirectory($dirName, $outputDir) { if (!is_dir($dirName)) { trigger_error("CreateZipFile FATAL ERROR: Could not locate the specified directory $dirName", E_USER_ERROR); } $tmp = $this->parseDirectory($dirName); $count = count($tmp); $this->addDirectory($outputDir); for ($i = 0; $i < $count; $i++) { $fileToZip = trim($tmp[$i]); $newOutputDir = substr($fileToZip, 0, (strrpos($fileToZip, '/') + 1)); $outputDir = $outputDir.$newOutputDir; $fileContents = file_get_contents($fileToZip); $this->addFile($fileContents, $fileToZip); } }
php
public function zipDirectory($dirName, $outputDir) { if (!is_dir($dirName)) { trigger_error("CreateZipFile FATAL ERROR: Could not locate the specified directory $dirName", E_USER_ERROR); } $tmp = $this->parseDirectory($dirName); $count = count($tmp); $this->addDirectory($outputDir); for ($i = 0; $i < $count; $i++) { $fileToZip = trim($tmp[$i]); $newOutputDir = substr($fileToZip, 0, (strrpos($fileToZip, '/') + 1)); $outputDir = $outputDir.$newOutputDir; $fileContents = file_get_contents($fileToZip); $this->addFile($fileContents, $fileToZip); } }
[ "public", "function", "zipDirectory", "(", "$", "dirName", ",", "$", "outputDir", ")", "{", "if", "(", "!", "is_dir", "(", "$", "dirName", ")", ")", "{", "trigger_error", "(", "\"CreateZipFile FATAL ERROR: Could not locate the specified directory $dirName\"", ",", "E_USER_ERROR", ")", ";", "}", "$", "tmp", "=", "$", "this", "->", "parseDirectory", "(", "$", "dirName", ")", ";", "$", "count", "=", "count", "(", "$", "tmp", ")", ";", "$", "this", "->", "addDirectory", "(", "$", "outputDir", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "fileToZip", "=", "trim", "(", "$", "tmp", "[", "$", "i", "]", ")", ";", "$", "newOutputDir", "=", "substr", "(", "$", "fileToZip", ",", "0", ",", "(", "strrpos", "(", "$", "fileToZip", ",", "'/'", ")", "+", "1", ")", ")", ";", "$", "outputDir", "=", "$", "outputDir", ".", "$", "newOutputDir", ";", "$", "fileContents", "=", "file_get_contents", "(", "$", "fileToZip", ")", ";", "$", "this", "->", "addFile", "(", "$", "fileContents", ",", "$", "fileToZip", ")", ";", "}", "}" ]
Function to Zip entire directory with all its files and subdirectories. @false string $dirName @param $dirName @param $outputDir @return void
[ "Function", "to", "Zip", "entire", "directory", "with", "all", "its", "files", "and", "subdirectories", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Common/Zip.php#L141-L156
230,727
teamreflex/TidalPHP
src/Tidal/Parts/Track.php
Track.getCoverUrlAttribute
public function getCoverUrlAttribute($res = 1280) { return str_replace('-', '/', Options::replace(Endpoints::ART_URL, [ 'key' => $this->album->cover, 'res' => $res, ])); }
php
public function getCoverUrlAttribute($res = 1280) { return str_replace('-', '/', Options::replace(Endpoints::ART_URL, [ 'key' => $this->album->cover, 'res' => $res, ])); }
[ "public", "function", "getCoverUrlAttribute", "(", "$", "res", "=", "1280", ")", "{", "return", "str_replace", "(", "'-'", ",", "'/'", ",", "Options", "::", "replace", "(", "Endpoints", "::", "ART_URL", ",", "[", "'key'", "=>", "$", "this", "->", "album", "->", "cover", ",", "'res'", "=>", "$", "res", ",", "]", ")", ")", ";", "}" ]
Gets the cover URL attribute. @return string The cover URL.
[ "Gets", "the", "cover", "URL", "attribute", "." ]
5d4948c75ae483d4baf318d94ba338801ec50cfc
https://github.com/teamreflex/TidalPHP/blob/5d4948c75ae483d4baf318d94ba338801ec50cfc/src/Tidal/Parts/Track.php#L42-L48
230,728
teamreflex/TidalPHP
src/Tidal/Parts/Track.php
Track.getOfflineUrl
public function getOfflineUrl($quality = null) { $deferred = new Deferred(); $valid = [self::QUALITY_LOSSLESS, self::QUALITY_HIGH, self::QUALITY_LOW]; if (array_search($quality, $valid) === false) { $quality = self::QUALITY_HIGH; } $options = Options::buildOptions([ 'soundQuality' => $quality, ], [], $this->tidal); $this->http->get( Options::replace(Endpoints::TRACK_OFFLINE_URL, ['id' => $this->id]).$options )->then(function ($response) use ($deferred) { $deferred->resolve(new StreamUrl($this->http, $this->tidal, $response)); }, function ($e) use ($deferred) { $deferred->reject($e); }); return $deferred->promise(); }
php
public function getOfflineUrl($quality = null) { $deferred = new Deferred(); $valid = [self::QUALITY_LOSSLESS, self::QUALITY_HIGH, self::QUALITY_LOW]; if (array_search($quality, $valid) === false) { $quality = self::QUALITY_HIGH; } $options = Options::buildOptions([ 'soundQuality' => $quality, ], [], $this->tidal); $this->http->get( Options::replace(Endpoints::TRACK_OFFLINE_URL, ['id' => $this->id]).$options )->then(function ($response) use ($deferred) { $deferred->resolve(new StreamUrl($this->http, $this->tidal, $response)); }, function ($e) use ($deferred) { $deferred->reject($e); }); return $deferred->promise(); }
[ "public", "function", "getOfflineUrl", "(", "$", "quality", "=", "null", ")", "{", "$", "deferred", "=", "new", "Deferred", "(", ")", ";", "$", "valid", "=", "[", "self", "::", "QUALITY_LOSSLESS", ",", "self", "::", "QUALITY_HIGH", ",", "self", "::", "QUALITY_LOW", "]", ";", "if", "(", "array_search", "(", "$", "quality", ",", "$", "valid", ")", "===", "false", ")", "{", "$", "quality", "=", "self", "::", "QUALITY_HIGH", ";", "}", "$", "options", "=", "Options", "::", "buildOptions", "(", "[", "'soundQuality'", "=>", "$", "quality", ",", "]", ",", "[", "]", ",", "$", "this", "->", "tidal", ")", ";", "$", "this", "->", "http", "->", "get", "(", "Options", "::", "replace", "(", "Endpoints", "::", "TRACK_OFFLINE_URL", ",", "[", "'id'", "=>", "$", "this", "->", "id", "]", ")", ".", "$", "options", ")", "->", "then", "(", "function", "(", "$", "response", ")", "use", "(", "$", "deferred", ")", "{", "$", "deferred", "->", "resolve", "(", "new", "StreamUrl", "(", "$", "this", "->", "http", ",", "$", "this", "->", "tidal", ",", "$", "response", ")", ")", ";", "}", ",", "function", "(", "$", "e", ")", "use", "(", "$", "deferred", ")", "{", "$", "deferred", "->", "reject", "(", "$", "e", ")", ";", "}", ")", ";", "return", "$", "deferred", "->", "promise", "(", ")", ";", "}" ]
Gets the track offline URL. @return \React\Promise\Promise The offline URL.
[ "Gets", "the", "track", "offline", "URL", "." ]
5d4948c75ae483d4baf318d94ba338801ec50cfc
https://github.com/teamreflex/TidalPHP/blob/5d4948c75ae483d4baf318d94ba338801ec50cfc/src/Tidal/Parts/Track.php#L129-L152
230,729
cygnite/framework
src/Cygnite/AssetManager/Html.php
Html.specialCharacters
public static function specialCharacters($value) { if (is_null($value)) { throw new InvalidArgumentException('Cannot pass null argument to '.__METHOD__); } return htmlspecialchars($value, ENT_QUOTES, Config::get('global.config', 'encoding'), false); }
php
public static function specialCharacters($value) { if (is_null($value)) { throw new InvalidArgumentException('Cannot pass null argument to '.__METHOD__); } return htmlspecialchars($value, ENT_QUOTES, Config::get('global.config', 'encoding'), false); }
[ "public", "static", "function", "specialCharacters", "(", "$", "value", ")", "{", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Cannot pass null argument to '", ".", "__METHOD__", ")", ";", "}", "return", "htmlspecialchars", "(", "$", "value", ",", "ENT_QUOTES", ",", "Config", "::", "get", "(", "'global.config'", ",", "'encoding'", ")", ",", "false", ")", ";", "}" ]
Convert Html special characters. Encoding will be used based on configuration given in Config file. @false string $value @param $value @throws InvalidArgumentException @return string
[ "Convert", "Html", "special", "characters", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/AssetManager/Html.php#L63-L70
230,730
cygnite/framework
src/Cygnite/AssetManager/Html.php
Html.sanitize
public function sanitize($value, $type = '') { switch ($type) { default: return htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); break; case 'strong': return htmlentities($value, ENT_QUOTES | ENT_IGNORE, 'UTF-8'); break; case 'strict': return urlencode($value); break; } }
php
public function sanitize($value, $type = '') { switch ($type) { default: return htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); break; case 'strong': return htmlentities($value, ENT_QUOTES | ENT_IGNORE, 'UTF-8'); break; case 'strict': return urlencode($value); break; } }
[ "public", "function", "sanitize", "(", "$", "value", ",", "$", "type", "=", "''", ")", "{", "switch", "(", "$", "type", ")", "{", "default", ":", "return", "htmlspecialchars", "(", "$", "value", ",", "ENT_QUOTES", ",", "'UTF-8'", ")", ";", "break", ";", "case", "'strong'", ":", "return", "htmlentities", "(", "$", "value", ",", "ENT_QUOTES", "|", "ENT_IGNORE", ",", "'UTF-8'", ")", ";", "break", ";", "case", "'strict'", ":", "return", "urlencode", "(", "$", "value", ")", ";", "break", ";", "}", "}" ]
The method to sanitize data. @false mixed $data
[ "The", "method", "to", "sanitize", "data", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/AssetManager/Html.php#L77-L90
230,731
cygnite/framework
src/Cygnite/Http/Responses/StreamedResponse.php
StreamedResponse.make
public static function make($callback = null, $status = ResponseHeaders::HTTP_OK, $headers = []) { return new static($callback, $status, $headers); }
php
public static function make($callback = null, $status = ResponseHeaders::HTTP_OK, $headers = []) { return new static($callback, $status, $headers); }
[ "public", "static", "function", "make", "(", "$", "callback", "=", "null", ",", "$", "status", "=", "ResponseHeaders", "::", "HTTP_OK", ",", "$", "headers", "=", "[", "]", ")", "{", "return", "new", "static", "(", "$", "callback", ",", "$", "status", ",", "$", "headers", ")", ";", "}" ]
Factory method to return StreamedResponse object to chain methods. @param type $callback @param type $status @param type $headers @return \static
[ "Factory", "method", "to", "return", "StreamedResponse", "object", "to", "chain", "methods", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Http/Responses/StreamedResponse.php#L46-L49
230,732
cygnite/framework
src/Cygnite/Http/Responses/StreamedResponse.php
StreamedResponse.sendContent
public function sendContent() { if (null === $this->callback) { throw new \LogicException('The SteamedResponse callback must not be null.'); } if (!$this->streamed && $this->callback !== null) { call_user_func($this->callback); $this->streamed = true; } }
php
public function sendContent() { if (null === $this->callback) { throw new \LogicException('The SteamedResponse callback must not be null.'); } if (!$this->streamed && $this->callback !== null) { call_user_func($this->callback); $this->streamed = true; } }
[ "public", "function", "sendContent", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "callback", ")", "{", "throw", "new", "\\", "LogicException", "(", "'The SteamedResponse callback must not be null.'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "streamed", "&&", "$", "this", "->", "callback", "!==", "null", ")", "{", "call_user_func", "(", "$", "this", "->", "callback", ")", ";", "$", "this", "->", "streamed", "=", "true", ";", "}", "}" ]
Send streamed contents. @throws \LogicException
[ "Send", "streamed", "contents", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Http/Responses/StreamedResponse.php#L56-L66
230,733
ctbsea/phalapi-smarty
src/Smarty/sysplugins/smarty_internal_runtime_updatescope.php
Smarty_Internal_Runtime_UpdateScope.updateScope
public function updateScope(Smarty_Internal_Template $tpl, $varName, $scope = Smarty::SCOPE_LOCAL) { if (!$scope && !$tpl->scope) { return; } foreach (array($scope, $tpl->scope) as $s) { $s = ($bubble_up = $s >= Smarty::SCOPE_BUBBLE_UP) ? $s - Smarty::SCOPE_BUBBLE_UP : $s; if ($bubble_up && $s) { $ptr = $tpl->parent; if (isset($ptr)) { $ptr->tpl_vars[$varName] = $tpl->tpl_vars[$varName]; $ptr = $ptr->parent; } if ($s == Smarty::SCOPE_PARENT) { continue; } while (isset($ptr) && $ptr->_objType == 2) { $ptr->tpl_vars[$varName] = $tpl->tpl_vars[$varName]; $ptr = $ptr->parent; } if ($s == Smarty::SCOPE_TPL_ROOT) { continue; } elseif ($s == Smarty::SCOPE_SMARTY) { $tpl->smarty->tpl_vars[$varName] = $tpl->tpl_vars[$varName]; } elseif ($s == Smarty::SCOPE_GLOBAL) { Smarty::$global_tpl_vars[$varName] = $tpl->tpl_vars[$varName]; } elseif ($s == Smarty::SCOPE_ROOT) { while (isset($ptr->parent)) { $ptr = $ptr->parent; } $ptr->tpl_vars[$varName] = $tpl->tpl_vars[$varName]; } } } }
php
public function updateScope(Smarty_Internal_Template $tpl, $varName, $scope = Smarty::SCOPE_LOCAL) { if (!$scope && !$tpl->scope) { return; } foreach (array($scope, $tpl->scope) as $s) { $s = ($bubble_up = $s >= Smarty::SCOPE_BUBBLE_UP) ? $s - Smarty::SCOPE_BUBBLE_UP : $s; if ($bubble_up && $s) { $ptr = $tpl->parent; if (isset($ptr)) { $ptr->tpl_vars[$varName] = $tpl->tpl_vars[$varName]; $ptr = $ptr->parent; } if ($s == Smarty::SCOPE_PARENT) { continue; } while (isset($ptr) && $ptr->_objType == 2) { $ptr->tpl_vars[$varName] = $tpl->tpl_vars[$varName]; $ptr = $ptr->parent; } if ($s == Smarty::SCOPE_TPL_ROOT) { continue; } elseif ($s == Smarty::SCOPE_SMARTY) { $tpl->smarty->tpl_vars[$varName] = $tpl->tpl_vars[$varName]; } elseif ($s == Smarty::SCOPE_GLOBAL) { Smarty::$global_tpl_vars[$varName] = $tpl->tpl_vars[$varName]; } elseif ($s == Smarty::SCOPE_ROOT) { while (isset($ptr->parent)) { $ptr = $ptr->parent; } $ptr->tpl_vars[$varName] = $tpl->tpl_vars[$varName]; } } } }
[ "public", "function", "updateScope", "(", "Smarty_Internal_Template", "$", "tpl", ",", "$", "varName", ",", "$", "scope", "=", "Smarty", "::", "SCOPE_LOCAL", ")", "{", "if", "(", "!", "$", "scope", "&&", "!", "$", "tpl", "->", "scope", ")", "{", "return", ";", "}", "foreach", "(", "array", "(", "$", "scope", ",", "$", "tpl", "->", "scope", ")", "as", "$", "s", ")", "{", "$", "s", "=", "(", "$", "bubble_up", "=", "$", "s", ">=", "Smarty", "::", "SCOPE_BUBBLE_UP", ")", "?", "$", "s", "-", "Smarty", "::", "SCOPE_BUBBLE_UP", ":", "$", "s", ";", "if", "(", "$", "bubble_up", "&&", "$", "s", ")", "{", "$", "ptr", "=", "$", "tpl", "->", "parent", ";", "if", "(", "isset", "(", "$", "ptr", ")", ")", "{", "$", "ptr", "->", "tpl_vars", "[", "$", "varName", "]", "=", "$", "tpl", "->", "tpl_vars", "[", "$", "varName", "]", ";", "$", "ptr", "=", "$", "ptr", "->", "parent", ";", "}", "if", "(", "$", "s", "==", "Smarty", "::", "SCOPE_PARENT", ")", "{", "continue", ";", "}", "while", "(", "isset", "(", "$", "ptr", ")", "&&", "$", "ptr", "->", "_objType", "==", "2", ")", "{", "$", "ptr", "->", "tpl_vars", "[", "$", "varName", "]", "=", "$", "tpl", "->", "tpl_vars", "[", "$", "varName", "]", ";", "$", "ptr", "=", "$", "ptr", "->", "parent", ";", "}", "if", "(", "$", "s", "==", "Smarty", "::", "SCOPE_TPL_ROOT", ")", "{", "continue", ";", "}", "elseif", "(", "$", "s", "==", "Smarty", "::", "SCOPE_SMARTY", ")", "{", "$", "tpl", "->", "smarty", "->", "tpl_vars", "[", "$", "varName", "]", "=", "$", "tpl", "->", "tpl_vars", "[", "$", "varName", "]", ";", "}", "elseif", "(", "$", "s", "==", "Smarty", "::", "SCOPE_GLOBAL", ")", "{", "Smarty", "::", "$", "global_tpl_vars", "[", "$", "varName", "]", "=", "$", "tpl", "->", "tpl_vars", "[", "$", "varName", "]", ";", "}", "elseif", "(", "$", "s", "==", "Smarty", "::", "SCOPE_ROOT", ")", "{", "while", "(", "isset", "(", "$", "ptr", "->", "parent", ")", ")", "{", "$", "ptr", "=", "$", "ptr", "->", "parent", ";", "}", "$", "ptr", "->", "tpl_vars", "[", "$", "varName", "]", "=", "$", "tpl", "->", "tpl_vars", "[", "$", "varName", "]", ";", "}", "}", "}", "}" ]
Update new assigned template variable in other effected scopes @param \Smarty_Internal_Template $tpl template object @param string $varName variable name @param int $scope scope to which bubble up variable value
[ "Update", "new", "assigned", "template", "variable", "in", "other", "effected", "scopes" ]
4d40da3e4482c0749f3cfd1605265a109a1c495f
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_internal_runtime_updatescope.php#L20-L54
230,734
cygnite/framework
src/Cygnite/Common/Security.php
Security.disableGlobals
private function disableGlobals() { // Same effect as disabling register_globals foreach ($GLOBALS as $key => $value) { if (!in_array($key, $this->_superGlobals)) { global $$key; $$key = null; unset($GLOBALS[$key], $$key); } } }
php
private function disableGlobals() { // Same effect as disabling register_globals foreach ($GLOBALS as $key => $value) { if (!in_array($key, $this->_superGlobals)) { global $$key; $$key = null; unset($GLOBALS[$key], $$key); } } }
[ "private", "function", "disableGlobals", "(", ")", "{", "// Same effect as disabling register_globals", "foreach", "(", "$", "GLOBALS", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "in_array", "(", "$", "key", ",", "$", "this", "->", "_superGlobals", ")", ")", "{", "global", "$", "$", "key", ";", "$", "$", "key", "=", "null", ";", "unset", "(", "$", "GLOBALS", "[", "$", "key", "]", ",", "$", "$", "key", ")", ";", "}", "}", "}" ]
disable all global variable.
[ "disable", "all", "global", "variable", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Common/Security.php#L122-L132
230,735
cygnite/framework
src/Cygnite/Common/Security.php
Security.cleanKeys
public function cleanKeys($data) { $pregMatches = (bool) preg_match(self::PREG_PROPERTIES, '?'); $chars = ''; $chars = $pregMatches ? '\pL' : 'a-zA-Z'; if (!preg_match('#^['.$chars.'0-9:_.-]++$#uD', $data)) { throw new \Exception('Illegal key characters in global data'); } return $data; }
php
public function cleanKeys($data) { $pregMatches = (bool) preg_match(self::PREG_PROPERTIES, '?'); $chars = ''; $chars = $pregMatches ? '\pL' : 'a-zA-Z'; if (!preg_match('#^['.$chars.'0-9:_.-]++$#uD', $data)) { throw new \Exception('Illegal key characters in global data'); } return $data; }
[ "public", "function", "cleanKeys", "(", "$", "data", ")", "{", "$", "pregMatches", "=", "(", "bool", ")", "preg_match", "(", "self", "::", "PREG_PROPERTIES", ",", "'?'", ")", ";", "$", "chars", "=", "''", ";", "$", "chars", "=", "$", "pregMatches", "?", "'\\pL'", ":", "'a-zA-Z'", ";", "if", "(", "!", "preg_match", "(", "'#^['", ".", "$", "chars", ".", "'0-9:_.-]++$#uD'", ",", "$", "data", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Illegal key characters in global data'", ")", ";", "}", "return", "$", "data", ";", "}" ]
Enforces W3C specifications to prevent malicious exploitation. @param string Key to clean @throws \Exception @return string
[ "Enforces", "W3C", "specifications", "to", "prevent", "malicious", "exploitation", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Common/Security.php#L163-L175
230,736
cygnite/framework
src/Cygnite/Common/Security.php
Security.create
public static function create(Closure $callback = null) { if (self::$instance === null) { self::$instance = new self(); } if ($callback instanceof Closure) { return $callback(self::$instance); } return self::$instance; }
php
public static function create(Closure $callback = null) { if (self::$instance === null) { self::$instance = new self(); } if ($callback instanceof Closure) { return $callback(self::$instance); } return self::$instance; }
[ "public", "static", "function", "create", "(", "Closure", "$", "callback", "=", "null", ")", "{", "if", "(", "self", "::", "$", "instance", "===", "null", ")", "{", "self", "::", "$", "instance", "=", "new", "self", "(", ")", ";", "}", "if", "(", "$", "callback", "instanceof", "Closure", ")", "{", "return", "$", "callback", "(", "self", "::", "$", "instance", ")", ";", "}", "return", "self", "::", "$", "instance", ";", "}" ]
Gets the instance of the Security class. @param callable| Closure $callback @return object Instance of Security
[ "Gets", "the", "instance", "of", "the", "Security", "class", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Common/Security.php#L503-L514
230,737
cygnite/framework
src/Cygnite/Bootstrappers/BootstrapperDispatcher.php
BootstrapperDispatcher.execute
public function execute() { foreach (array_unique($this->bootstrappers->all()) as $class) { $bootstrapper = $this->create($class); if (!method_exists($bootstrapper, 'run')) { throw new \RuntimeException("$class must have run() method"); } $bootstrapper->run(); } }
php
public function execute() { foreach (array_unique($this->bootstrappers->all()) as $class) { $bootstrapper = $this->create($class); if (!method_exists($bootstrapper, 'run')) { throw new \RuntimeException("$class must have run() method"); } $bootstrapper->run(); } }
[ "public", "function", "execute", "(", ")", "{", "foreach", "(", "array_unique", "(", "$", "this", "->", "bootstrappers", "->", "all", "(", ")", ")", "as", "$", "class", ")", "{", "$", "bootstrapper", "=", "$", "this", "->", "create", "(", "$", "class", ")", ";", "if", "(", "!", "method_exists", "(", "$", "bootstrapper", ",", "'run'", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"$class must have run() method\"", ")", ";", "}", "$", "bootstrapper", "->", "run", "(", ")", ";", "}", "}" ]
Run all defined bootstrappers @throws \RuntimeException
[ "Run", "all", "defined", "bootstrappers" ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Bootstrappers/BootstrapperDispatcher.php#L45-L56
230,738
cygnite/framework
src/Cygnite/Bootstrappers/BootstrapperDispatcher.php
BootstrapperDispatcher.create
public function create(string $class) : BootstrapperInterface { if (!isset($this->instances[$class])) { $this->instances[$class] = new $class($this->container, $this->bootstrappers->getPaths()); } return $this->instances[$class]; }
php
public function create(string $class) : BootstrapperInterface { if (!isset($this->instances[$class])) { $this->instances[$class] = new $class($this->container, $this->bootstrappers->getPaths()); } return $this->instances[$class]; }
[ "public", "function", "create", "(", "string", "$", "class", ")", ":", "BootstrapperInterface", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "instances", "[", "$", "class", "]", ")", ")", "{", "$", "this", "->", "instances", "[", "$", "class", "]", "=", "new", "$", "class", "(", "$", "this", "->", "container", ",", "$", "this", "->", "bootstrappers", "->", "getPaths", "(", ")", ")", ";", "}", "return", "$", "this", "->", "instances", "[", "$", "class", "]", ";", "}" ]
Store all bootstrappers into instance stack @param string $class
[ "Store", "all", "bootstrappers", "into", "instance", "stack" ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Bootstrappers/BootstrapperDispatcher.php#L63-L70
230,739
cygnite/framework
src/Cygnite/Mvc/Controller/AbstractBaseController.php
AbstractBaseController.redirectTo
protected function redirectTo($uri = '', $type = 'location', $httpResponseCode = 302) : AbstractBaseController { $container = $this->container(); if ($container->has('url')) { $container->get('url')->redirectTo($uri, $type, $httpResponseCode); } return $this; }
php
protected function redirectTo($uri = '', $type = 'location', $httpResponseCode = 302) : AbstractBaseController { $container = $this->container(); if ($container->has('url')) { $container->get('url')->redirectTo($uri, $type, $httpResponseCode); } return $this; }
[ "protected", "function", "redirectTo", "(", "$", "uri", "=", "''", ",", "$", "type", "=", "'location'", ",", "$", "httpResponseCode", "=", "302", ")", ":", "AbstractBaseController", "{", "$", "container", "=", "$", "this", "->", "container", "(", ")", ";", "if", "(", "$", "container", "->", "has", "(", "'url'", ")", ")", "{", "$", "container", "->", "get", "(", "'url'", ")", "->", "redirectTo", "(", "$", "uri", ",", "$", "type", ",", "$", "httpResponseCode", ")", ";", "}", "return", "$", "this", ";", "}" ]
Redirect to given url. @param string $uri @param string $type @param int $httpResponseCode @return $this
[ "Redirect", "to", "given", "url", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Mvc/Controller/AbstractBaseController.php#L79-L87
230,740
cygnite/framework
src/Cygnite/Mvc/Controller/AbstractBaseController.php
AbstractBaseController.call
public function call($resource, $arguments = []) { list($name, $method) = explode('@', $resource); $method = $method.'Action'; $class = array_map('ucfirst', explode('.', $name)); $className = Inflector::classify(end($class)).'Controller'; $namespace = str_replace(end($class), '', $class); $class = '\\'.APP_NS.'\\'.implode('\\', $namespace).$className; return $this->_call(new $class(), $method, $arguments); }
php
public function call($resource, $arguments = []) { list($name, $method) = explode('@', $resource); $method = $method.'Action'; $class = array_map('ucfirst', explode('.', $name)); $className = Inflector::classify(end($class)).'Controller'; $namespace = str_replace(end($class), '', $class); $class = '\\'.APP_NS.'\\'.implode('\\', $namespace).$className; return $this->_call(new $class(), $method, $arguments); }
[ "public", "function", "call", "(", "$", "resource", ",", "$", "arguments", "=", "[", "]", ")", "{", "list", "(", "$", "name", ",", "$", "method", ")", "=", "explode", "(", "'@'", ",", "$", "resource", ")", ";", "$", "method", "=", "$", "method", ".", "'Action'", ";", "$", "class", "=", "array_map", "(", "'ucfirst'", ",", "explode", "(", "'.'", ",", "$", "name", ")", ")", ";", "$", "className", "=", "Inflector", "::", "classify", "(", "end", "(", "$", "class", ")", ")", ".", "'Controller'", ";", "$", "namespace", "=", "str_replace", "(", "end", "(", "$", "class", ")", ",", "''", ",", "$", "class", ")", ";", "$", "class", "=", "'\\\\'", ".", "APP_NS", ".", "'\\\\'", ".", "implode", "(", "'\\\\'", ",", "$", "namespace", ")", ".", "$", "className", ";", "return", "$", "this", "->", "_call", "(", "new", "$", "class", "(", ")", ",", "$", "method", ",", "$", "arguments", ")", ";", "}" ]
Call HMVC modules dynamically. <code> // Call the "index" method on the "user" controller $response = $this->call('admin::user@index');. // Call the "user/admin" controller and pass parameters $response = $this->call('modules.admin.user@profile', $arguments); </code>
[ "Call", "HMVC", "modules", "dynamically", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Mvc/Controller/AbstractBaseController.php#L100-L111
230,741
cygnite/framework
src/Cygnite/Mvc/Controller/AbstractBaseController.php
AbstractBaseController.getTemplate
public function getTemplate() { if ($this->templateEngine == false) { return false; } $this->view->setTwigEnvironment(); return $this->view->getTemplate(); }
php
public function getTemplate() { if ($this->templateEngine == false) { return false; } $this->view->setTwigEnvironment(); return $this->view->getTemplate(); }
[ "public", "function", "getTemplate", "(", ")", "{", "if", "(", "$", "this", "->", "templateEngine", "==", "false", ")", "{", "return", "false", ";", "}", "$", "this", "->", "view", "->", "setTwigEnvironment", "(", ")", ";", "return", "$", "this", "->", "view", "->", "getTemplate", "(", ")", ";", "}" ]
Return the Template instance. @return bool
[ "Return", "the", "Template", "instance", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Mvc/Controller/AbstractBaseController.php#L221-L230
230,742
tapestry-cloud/tapestry
src/Modules/ContentTypes/ContentTypeFactory.php
ContentTypeFactory.add
public function add(ContentType $contentType, $overWrite = false) { if (! $overWrite && $this->has($contentType->getPath())) { throw new \Exception('The collection ['.$this->pathLookupTable[$contentType->getPath()].'] already collects for the path ['.$contentType->getPath().']'); } $uid = sha1(md5(get_class($contentType)).'_'.sha1($contentType->getName().'-'.$contentType->getPath())); $this->items[$uid] = $contentType; $this->pathLookupTable[$contentType->getPath()] = $uid; $this->nameLookupTable[$contentType->getName()] = $uid; }
php
public function add(ContentType $contentType, $overWrite = false) { if (! $overWrite && $this->has($contentType->getPath())) { throw new \Exception('The collection ['.$this->pathLookupTable[$contentType->getPath()].'] already collects for the path ['.$contentType->getPath().']'); } $uid = sha1(md5(get_class($contentType)).'_'.sha1($contentType->getName().'-'.$contentType->getPath())); $this->items[$uid] = $contentType; $this->pathLookupTable[$contentType->getPath()] = $uid; $this->nameLookupTable[$contentType->getName()] = $uid; }
[ "public", "function", "add", "(", "ContentType", "$", "contentType", ",", "$", "overWrite", "=", "false", ")", "{", "if", "(", "!", "$", "overWrite", "&&", "$", "this", "->", "has", "(", "$", "contentType", "->", "getPath", "(", ")", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'The collection ['", ".", "$", "this", "->", "pathLookupTable", "[", "$", "contentType", "->", "getPath", "(", ")", "]", ".", "'] already collects for the path ['", ".", "$", "contentType", "->", "getPath", "(", ")", ".", "']'", ")", ";", "}", "$", "uid", "=", "sha1", "(", "md5", "(", "get_class", "(", "$", "contentType", ")", ")", ".", "'_'", ".", "sha1", "(", "$", "contentType", "->", "getName", "(", ")", ".", "'-'", ".", "$", "contentType", "->", "getPath", "(", ")", ")", ")", ";", "$", "this", "->", "items", "[", "$", "uid", "]", "=", "$", "contentType", ";", "$", "this", "->", "pathLookupTable", "[", "$", "contentType", "->", "getPath", "(", ")", "]", "=", "$", "uid", ";", "$", "this", "->", "nameLookupTable", "[", "$", "contentType", "->", "getName", "(", ")", "]", "=", "$", "uid", ";", "}" ]
Add a ContentType to the registry. @param ContentType $contentType @param bool $overWrite should adding overwrite existing; if false an exception will be thrown if a matching collection already found @throws \Exception
[ "Add", "a", "ContentType", "to", "the", "registry", "." ]
f3fc980b2484ccbe609a7f811c65b91254e8720e
https://github.com/tapestry-cloud/tapestry/blob/f3fc980b2484ccbe609a7f811c65b91254e8720e/src/Modules/ContentTypes/ContentTypeFactory.php#L50-L59
230,743
tapestry-cloud/tapestry
src/Modules/ContentTypes/ContentTypeFactory.php
ContentTypeFactory.find
public function find($path) { foreach (array_keys($this->pathLookupTable) as $key) { if (starts_with($path, $key)) { return $key; } } }
php
public function find($path) { foreach (array_keys($this->pathLookupTable) as $key) { if (starts_with($path, $key)) { return $key; } } }
[ "public", "function", "find", "(", "$", "path", ")", "{", "foreach", "(", "array_keys", "(", "$", "this", "->", "pathLookupTable", ")", "as", "$", "key", ")", "{", "if", "(", "starts_with", "(", "$", "path", ",", "$", "key", ")", ")", "{", "return", "$", "key", ";", "}", "}", "}" ]
Returns the absolute path from an input, so that you may then get the ContentType that deals with it. @param string $path @return null|string
[ "Returns", "the", "absolute", "path", "from", "an", "input", "so", "that", "you", "may", "then", "get", "the", "ContentType", "that", "deals", "with", "it", "." ]
f3fc980b2484ccbe609a7f811c65b91254e8720e
https://github.com/tapestry-cloud/tapestry/blob/f3fc980b2484ccbe609a7f811c65b91254e8720e/src/Modules/ContentTypes/ContentTypeFactory.php#L90-L97
230,744
tapestry-cloud/tapestry
src/Modules/ContentTypes/ContentTypeFactory.php
ContentTypeFactory.arrayAccessByKey
public function arrayAccessByKey($key) { if (! isset($this->nameLookupTable[$key])) { return null; } if (isset($this->items[$this->nameLookupTable[$key]])) { return $this->items[$this->nameLookupTable[$key]]; } return null; }
php
public function arrayAccessByKey($key) { if (! isset($this->nameLookupTable[$key])) { return null; } if (isset($this->items[$this->nameLookupTable[$key]])) { return $this->items[$this->nameLookupTable[$key]]; } return null; }
[ "public", "function", "arrayAccessByKey", "(", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "nameLookupTable", "[", "$", "key", "]", ")", ")", "{", "return", "null", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "items", "[", "$", "this", "->", "nameLookupTable", "[", "$", "key", "]", "]", ")", ")", "{", "return", "$", "this", "->", "items", "[", "$", "this", "->", "nameLookupTable", "[", "$", "key", "]", "]", ";", "}", "return", "null", ";", "}" ]
ArrayAccess method for use by ArrayContainer for dot notation key retrieval. @param $key @return mixed|null|ContentType
[ "ArrayAccess", "method", "for", "use", "by", "ArrayContainer", "for", "dot", "notation", "key", "retrieval", "." ]
f3fc980b2484ccbe609a7f811c65b91254e8720e
https://github.com/tapestry-cloud/tapestry/blob/f3fc980b2484ccbe609a7f811c65b91254e8720e/src/Modules/ContentTypes/ContentTypeFactory.php#L129-L140
230,745
ctbsea/phalapi-smarty
src/Smarty/sysplugins/smarty_internal_compilebase.php
Smarty_Internal_CompileBase.closeTag
public function closeTag($compiler, $expectedTag) { if (count($compiler->_tag_stack) > 0) { // get stacked info list($_openTag, $_data) = array_pop($compiler->_tag_stack); // open tag must match with the expected ones if (in_array($_openTag, (array) $expectedTag)) { if (is_null($_data)) { // return opening tag return $_openTag; } else { // return restored data return $_data; } } // wrong nesting of tags $compiler->trigger_template_error("unclosed {$compiler->smarty->left_delimiter}" . $_openTag . "{$compiler->smarty->right_delimiter} tag"); return; } // wrong nesting of tags $compiler->trigger_template_error("unexpected closing tag", null, true); return; }
php
public function closeTag($compiler, $expectedTag) { if (count($compiler->_tag_stack) > 0) { // get stacked info list($_openTag, $_data) = array_pop($compiler->_tag_stack); // open tag must match with the expected ones if (in_array($_openTag, (array) $expectedTag)) { if (is_null($_data)) { // return opening tag return $_openTag; } else { // return restored data return $_data; } } // wrong nesting of tags $compiler->trigger_template_error("unclosed {$compiler->smarty->left_delimiter}" . $_openTag . "{$compiler->smarty->right_delimiter} tag"); return; } // wrong nesting of tags $compiler->trigger_template_error("unexpected closing tag", null, true); return; }
[ "public", "function", "closeTag", "(", "$", "compiler", ",", "$", "expectedTag", ")", "{", "if", "(", "count", "(", "$", "compiler", "->", "_tag_stack", ")", ">", "0", ")", "{", "// get stacked info", "list", "(", "$", "_openTag", ",", "$", "_data", ")", "=", "array_pop", "(", "$", "compiler", "->", "_tag_stack", ")", ";", "// open tag must match with the expected ones", "if", "(", "in_array", "(", "$", "_openTag", ",", "(", "array", ")", "$", "expectedTag", ")", ")", "{", "if", "(", "is_null", "(", "$", "_data", ")", ")", "{", "// return opening tag", "return", "$", "_openTag", ";", "}", "else", "{", "// return restored data", "return", "$", "_data", ";", "}", "}", "// wrong nesting of tags", "$", "compiler", "->", "trigger_template_error", "(", "\"unclosed {$compiler->smarty->left_delimiter}\"", ".", "$", "_openTag", ".", "\"{$compiler->smarty->right_delimiter} tag\"", ")", ";", "return", ";", "}", "// wrong nesting of tags", "$", "compiler", "->", "trigger_template_error", "(", "\"unexpected closing tag\"", ",", "null", ",", "true", ")", ";", "return", ";", "}" ]
Pop closing tag Raise an error if this stack-top doesn't match with expected opening tags @param object $compiler compiler object @param array|string $expectedTag the expected opening tag names @return mixed any type the opening tag's name or saved data
[ "Pop", "closing", "tag", "Raise", "an", "error", "if", "this", "stack", "-", "top", "doesn", "t", "match", "with", "expected", "opening", "tags" ]
4d40da3e4482c0749f3cfd1605265a109a1c495f
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_internal_compilebase.php#L152-L177
230,746
VirgilSecurity/virgil-sdk-php
Virgil/Http/Curl/CurlClient.php
CurlClient.buildHeaders
protected function buildHeaders($requestHeaders) { $requestHeaders = $requestHeaders + $this->requestHeaders; $resultHeaders = []; foreach ($requestHeaders as $headerName => $headerValue) { if (is_array($headerValue)) { $headerValue = implode(',', $headerValue); } $resultHeaders[] = ucfirst($headerName) . ': ' . $headerValue; } return $resultHeaders; }
php
protected function buildHeaders($requestHeaders) { $requestHeaders = $requestHeaders + $this->requestHeaders; $resultHeaders = []; foreach ($requestHeaders as $headerName => $headerValue) { if (is_array($headerValue)) { $headerValue = implode(',', $headerValue); } $resultHeaders[] = ucfirst($headerName) . ': ' . $headerValue; } return $resultHeaders; }
[ "protected", "function", "buildHeaders", "(", "$", "requestHeaders", ")", "{", "$", "requestHeaders", "=", "$", "requestHeaders", "+", "$", "this", "->", "requestHeaders", ";", "$", "resultHeaders", "=", "[", "]", ";", "foreach", "(", "$", "requestHeaders", "as", "$", "headerName", "=>", "$", "headerValue", ")", "{", "if", "(", "is_array", "(", "$", "headerValue", ")", ")", "{", "$", "headerValue", "=", "implode", "(", "','", ",", "$", "headerValue", ")", ";", "}", "$", "resultHeaders", "[", "]", "=", "ucfirst", "(", "$", "headerName", ")", ".", "': '", ".", "$", "headerValue", ";", "}", "return", "$", "resultHeaders", ";", "}" ]
Returns HTTP compatible request headers. @param $requestHeaders @return array
[ "Returns", "HTTP", "compatible", "request", "headers", "." ]
b3dd713f614019da2ee87aa80cebce7011f56f85
https://github.com/VirgilSecurity/virgil-sdk-php/blob/b3dd713f614019da2ee87aa80cebce7011f56f85/Virgil/Http/Curl/CurlClient.php#L150-L165
230,747
VirgilSecurity/virgil-sdk-php
Virgil/Http/Curl/CurlClient.php
CurlClient.buildUrl
protected function buildUrl($requestUrl, $requestParams = []) { if (!empty($requestParams)) { $requestUrl = $requestUrl . '?' . http_build_query($requestParams); } return $requestUrl; }
php
protected function buildUrl($requestUrl, $requestParams = []) { if (!empty($requestParams)) { $requestUrl = $requestUrl . '?' . http_build_query($requestParams); } return $requestUrl; }
[ "protected", "function", "buildUrl", "(", "$", "requestUrl", ",", "$", "requestParams", "=", "[", "]", ")", "{", "if", "(", "!", "empty", "(", "$", "requestParams", ")", ")", "{", "$", "requestUrl", "=", "$", "requestUrl", ".", "'?'", ".", "http_build_query", "(", "$", "requestParams", ")", ";", "}", "return", "$", "requestUrl", ";", "}" ]
Returns HTTP compatible request URL with params if specified. @param $requestUrl @param array $requestParams @return string
[ "Returns", "HTTP", "compatible", "request", "URL", "with", "params", "if", "specified", "." ]
b3dd713f614019da2ee87aa80cebce7011f56f85
https://github.com/VirgilSecurity/virgil-sdk-php/blob/b3dd713f614019da2ee87aa80cebce7011f56f85/Virgil/Http/Curl/CurlClient.php#L176-L183
230,748
cygnite/framework
src/Cygnite/Container/Injector.php
Injector.interfaceInjection
public function interfaceInjection($reflectionParam) { $constructorArgs = null; /* | Check if constructor dependency is Interface or not. | if interface we will check definition for the interface | and inject into controller constructor */ if (!$reflectionParam->IsInstantiable() && $reflectionParam->isInterface()) { $aliases = $this->definition['definition.config']['register.alias']; $interface = Inflector::getClassName($reflectionParam->getName()); if (array_key_exists($interface, $aliases)) { $constructorArgs = $this->container->makeInstance($aliases[$interface]); } } return $constructorArgs; }
php
public function interfaceInjection($reflectionParam) { $constructorArgs = null; /* | Check if constructor dependency is Interface or not. | if interface we will check definition for the interface | and inject into controller constructor */ if (!$reflectionParam->IsInstantiable() && $reflectionParam->isInterface()) { $aliases = $this->definition['definition.config']['register.alias']; $interface = Inflector::getClassName($reflectionParam->getName()); if (array_key_exists($interface, $aliases)) { $constructorArgs = $this->container->makeInstance($aliases[$interface]); } } return $constructorArgs; }
[ "public", "function", "interfaceInjection", "(", "$", "reflectionParam", ")", "{", "$", "constructorArgs", "=", "null", ";", "/*\n | Check if constructor dependency is Interface or not.\n | if interface we will check definition for the interface\n | and inject into controller constructor\n */", "if", "(", "!", "$", "reflectionParam", "->", "IsInstantiable", "(", ")", "&&", "$", "reflectionParam", "->", "isInterface", "(", ")", ")", "{", "$", "aliases", "=", "$", "this", "->", "definition", "[", "'definition.config'", "]", "[", "'register.alias'", "]", ";", "$", "interface", "=", "Inflector", "::", "getClassName", "(", "$", "reflectionParam", "->", "getName", "(", ")", ")", ";", "if", "(", "array_key_exists", "(", "$", "interface", ",", "$", "aliases", ")", ")", "{", "$", "constructorArgs", "=", "$", "this", "->", "container", "->", "makeInstance", "(", "$", "aliases", "[", "$", "interface", "]", ")", ";", "}", "}", "return", "$", "constructorArgs", ";", "}" ]
We will inject interface implementation. @param $reflectionParam @return array
[ "We", "will", "inject", "interface", "implementation", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Container/Injector.php#L49-L67
230,749
ctbsea/phalapi-smarty
src/Smarty/sysplugins/smarty_internal_templateparser.php
Smarty_Internal_Templateparser.mergePrefixCode
public function mergePrefixCode($code) { $tmp = ''; foreach ($this->compiler->prefix_code as $preCode) { $tmp .= $preCode; } $this->compiler->prefix_code = array(); $tmp .= $code; return new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode($tmp, true)); }
php
public function mergePrefixCode($code) { $tmp = ''; foreach ($this->compiler->prefix_code as $preCode) { $tmp .= $preCode; } $this->compiler->prefix_code = array(); $tmp .= $code; return new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode($tmp, true)); }
[ "public", "function", "mergePrefixCode", "(", "$", "code", ")", "{", "$", "tmp", "=", "''", ";", "foreach", "(", "$", "this", "->", "compiler", "->", "prefix_code", "as", "$", "preCode", ")", "{", "$", "tmp", ".=", "$", "preCode", ";", "}", "$", "this", "->", "compiler", "->", "prefix_code", "=", "array", "(", ")", ";", "$", "tmp", ".=", "$", "code", ";", "return", "new", "Smarty_Internal_ParseTree_Tag", "(", "$", "this", ",", "$", "this", "->", "compiler", "->", "processNocacheCode", "(", "$", "tmp", ",", "true", ")", ")", ";", "}" ]
merge PHP code with prefix code and return parse tree tag object @param string $code @return Smarty_Internal_ParseTree_Tag
[ "merge", "PHP", "code", "with", "prefix", "code", "and", "return", "parse", "tree", "tag", "object" ]
4d40da3e4482c0749f3cfd1605265a109a1c495f
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_internal_templateparser.php#L256-L265
230,750
cygnite/framework
src/Cygnite/Console/Command/Command.php
Command.setConfiguration
protected function setConfiguration() { $this->setDescription($this->description); $this->configureArguments($this->arguments, 'addArgument'); $this->configureArguments($this->options); }
php
protected function setConfiguration() { $this->setDescription($this->description); $this->configureArguments($this->arguments, 'addArgument'); $this->configureArguments($this->options); }
[ "protected", "function", "setConfiguration", "(", ")", "{", "$", "this", "->", "setDescription", "(", "$", "this", "->", "description", ")", ";", "$", "this", "->", "configureArguments", "(", "$", "this", "->", "arguments", ",", "'addArgument'", ")", ";", "$", "this", "->", "configureArguments", "(", "$", "this", "->", "options", ")", ";", "}" ]
Set configuration for console command We will set command description, arguments and optional parameters into console command. @return void
[ "Set", "configuration", "for", "console", "command", "We", "will", "set", "command", "description", "arguments", "and", "optional", "parameters", "into", "console", "command", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Console/Command/Command.php#L74-L79
230,751
cygnite/framework
src/Cygnite/Console/Command/Command.php
Command.configureArguments
protected function configureArguments($consoleInputs, $method = 'addOption') { /* | We will loop through all the arguments passed from console | and set all required and optional parameters | into console command | */ foreach ($consoleInputs as $arguments) { call_user_func_array([$this, $method], $arguments); } }
php
protected function configureArguments($consoleInputs, $method = 'addOption') { /* | We will loop through all the arguments passed from console | and set all required and optional parameters | into console command | */ foreach ($consoleInputs as $arguments) { call_user_func_array([$this, $method], $arguments); } }
[ "protected", "function", "configureArguments", "(", "$", "consoleInputs", ",", "$", "method", "=", "'addOption'", ")", "{", "/*\n | We will loop through all the arguments passed from console\n | and set all required and optional parameters\n | into console command\n |\n */", "foreach", "(", "$", "consoleInputs", "as", "$", "arguments", ")", "{", "call_user_func_array", "(", "[", "$", "this", ",", "$", "method", "]", ",", "$", "arguments", ")", ";", "}", "}" ]
We will add arguments and optional parameters into console command. @param $consoleInputs @param string $method
[ "We", "will", "add", "arguments", "and", "optional", "parameters", "into", "console", "command", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Console/Command/Command.php#L88-L99
230,752
cygnite/framework
src/Cygnite/Console/Command/Command.php
Command.ask
public function ask($question, $default = null) { $question = new Question("<question>$question</question> ", $default); return $this->helper('question')->ask($this->input, $this->output, $question); }
php
public function ask($question, $default = null) { $question = new Question("<question>$question</question> ", $default); return $this->helper('question')->ask($this->input, $this->output, $question); }
[ "public", "function", "ask", "(", "$", "question", ",", "$", "default", "=", "null", ")", "{", "$", "question", "=", "new", "Question", "(", "\"<question>$question</question> \"", ",", "$", "default", ")", ";", "return", "$", "this", "->", "helper", "(", "'question'", ")", "->", "ask", "(", "$", "this", "->", "input", ",", "$", "this", "->", "output", ",", "$", "question", ")", ";", "}" ]
We will ask user for input. @param string $question @param string $default @return string
[ "We", "will", "ask", "user", "for", "input", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Console/Command/Command.php#L186-L191
230,753
cygnite/framework
src/Cygnite/Console/Command/Command.php
Command.callCommand
public function callCommand(string $command, array $arguments = []) { $newCommand = $this->getApplication()->find($command); $arguments['command'] = $command; return $newCommand->run(new ArrayInput($arguments), $this->getOutput()); }
php
public function callCommand(string $command, array $arguments = []) { $newCommand = $this->getApplication()->find($command); $arguments['command'] = $command; return $newCommand->run(new ArrayInput($arguments), $this->getOutput()); }
[ "public", "function", "callCommand", "(", "string", "$", "command", ",", "array", "$", "arguments", "=", "[", "]", ")", "{", "$", "newCommand", "=", "$", "this", "->", "getApplication", "(", ")", "->", "find", "(", "$", "command", ")", ";", "$", "arguments", "[", "'command'", "]", "=", "$", "command", ";", "return", "$", "newCommand", "->", "run", "(", "new", "ArrayInput", "(", "$", "arguments", ")", ",", "$", "this", "->", "getOutput", "(", ")", ")", ";", "}" ]
Call any console command. @param string $command @param array $arguments @return int
[ "Call", "any", "console", "command", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Console/Command/Command.php#L311-L318
230,754
cygnite/framework
src/Cygnite/Console/Command/Command.php
Command.argument
public function argument($name) { $input = $this->getInput(); return (is_null($name)) ? $input->getArguments() : $input->getArgument($name); }
php
public function argument($name) { $input = $this->getInput(); return (is_null($name)) ? $input->getArguments() : $input->getArgument($name); }
[ "public", "function", "argument", "(", "$", "name", ")", "{", "$", "input", "=", "$", "this", "->", "getInput", "(", ")", ";", "return", "(", "is_null", "(", "$", "name", ")", ")", "?", "$", "input", "->", "getArguments", "(", ")", ":", "$", "input", "->", "getArgument", "(", "$", "name", ")", ";", "}" ]
Get the value from command argument. @param string $key @return string|array
[ "Get", "the", "value", "from", "command", "argument", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Console/Command/Command.php#L327-L332
230,755
cygnite/framework
src/Cygnite/Console/Command/Command.php
Command.option
public function option($name) { $input = $this->getInput(); return (is_null($name)) ? $input->getOptions() : $input->getOption($name); }
php
public function option($name) { $input = $this->getInput(); return (is_null($name)) ? $input->getOptions() : $input->getOption($name); }
[ "public", "function", "option", "(", "$", "name", ")", "{", "$", "input", "=", "$", "this", "->", "getInput", "(", ")", ";", "return", "(", "is_null", "(", "$", "name", ")", ")", "?", "$", "input", "->", "getOptions", "(", ")", ":", "$", "input", "->", "getOption", "(", "$", "name", ")", ";", "}" ]
Get optional parameter from command argument. @param string $key @return string|array
[ "Get", "optional", "parameter", "from", "command", "argument", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Console/Command/Command.php#L341-L346
230,756
cygnite/framework
src/Cygnite/Console/Generator/Migrator.php
Migrator.updateMigration
public function updateMigration($type = 'up') { $file = $class = null; $file = $this->getAppMigrationDirPath().$this->getVersion().$this->getMigrationClass(); if (is_readable($file.EXT)) { include_once $file.EXT; $class = Inflector::classify($this->getMigrationClass()); } if (trim($type) !== 'down') { $type = 'up'; } //Create migrations table schema if not exists $this->command->table()->makeMigration(); call_user_func_array([new $class(), $type], []); $this->updateMigrationTable(); $this->command->info('Migrated: '.$file.EXT.' OK!'); }
php
public function updateMigration($type = 'up') { $file = $class = null; $file = $this->getAppMigrationDirPath().$this->getVersion().$this->getMigrationClass(); if (is_readable($file.EXT)) { include_once $file.EXT; $class = Inflector::classify($this->getMigrationClass()); } if (trim($type) !== 'down') { $type = 'up'; } //Create migrations table schema if not exists $this->command->table()->makeMigration(); call_user_func_array([new $class(), $type], []); $this->updateMigrationTable(); $this->command->info('Migrated: '.$file.EXT.' OK!'); }
[ "public", "function", "updateMigration", "(", "$", "type", "=", "'up'", ")", "{", "$", "file", "=", "$", "class", "=", "null", ";", "$", "file", "=", "$", "this", "->", "getAppMigrationDirPath", "(", ")", ".", "$", "this", "->", "getVersion", "(", ")", ".", "$", "this", "->", "getMigrationClass", "(", ")", ";", "if", "(", "is_readable", "(", "$", "file", ".", "EXT", ")", ")", "{", "include_once", "$", "file", ".", "EXT", ";", "$", "class", "=", "Inflector", "::", "classify", "(", "$", "this", "->", "getMigrationClass", "(", ")", ")", ";", "}", "if", "(", "trim", "(", "$", "type", ")", "!==", "'down'", ")", "{", "$", "type", "=", "'up'", ";", "}", "//Create migrations table schema if not exists", "$", "this", "->", "command", "->", "table", "(", ")", "->", "makeMigration", "(", ")", ";", "call_user_func_array", "(", "[", "new", "$", "class", "(", ")", ",", "$", "type", "]", ",", "[", "]", ")", ";", "$", "this", "->", "updateMigrationTable", "(", ")", ";", "$", "this", "->", "command", "->", "info", "(", "'Migrated: '", ".", "$", "file", ".", "EXT", ".", "' OK!'", ")", ";", "}" ]
Call migration and do update. @param string $type
[ "Call", "migration", "and", "do", "update", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Console/Generator/Migrator.php#L270-L292
230,757
cygnite/framework
src/Cygnite/Router/Controller/Controller.php
Controller.routeController
public function routeController($controller): Controller { $actions = $this->getActions(); foreach ($actions as $key => $action) { $method = ucfirst(Inflector::pathAction($action)); if (method_exists($this, 'set' . $method . 'Route')) { $this->{'set' . $method . 'Route'}(Inflector::deCamelize($controller), $action); } } $this->mapRoute(); return $this; }
php
public function routeController($controller): Controller { $actions = $this->getActions(); foreach ($actions as $key => $action) { $method = ucfirst(Inflector::pathAction($action)); if (method_exists($this, 'set' . $method . 'Route')) { $this->{'set' . $method . 'Route'}(Inflector::deCamelize($controller), $action); } } $this->mapRoute(); return $this; }
[ "public", "function", "routeController", "(", "$", "controller", ")", ":", "Controller", "{", "$", "actions", "=", "$", "this", "->", "getActions", "(", ")", ";", "foreach", "(", "$", "actions", "as", "$", "key", "=>", "$", "action", ")", "{", "$", "method", "=", "ucfirst", "(", "Inflector", "::", "pathAction", "(", "$", "action", ")", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "'set'", ".", "$", "method", ".", "'Route'", ")", ")", "{", "$", "this", "->", "{", "'set'", ".", "$", "method", ".", "'Route'", "}", "(", "Inflector", "::", "deCamelize", "(", "$", "controller", ")", ",", "$", "action", ")", ";", "}", "}", "$", "this", "->", "mapRoute", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set the controller as Route Controller Cygnite Router knows how to respond to routes controller request automatically. @param $controller @return $this
[ "Set", "the", "controller", "as", "Route", "Controller", "Cygnite", "Router", "knows", "how", "to", "respond", "to", "routes", "controller", "request", "automatically", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Router/Controller/Controller.php#L59-L74
230,758
cygnite/framework
src/Cygnite/Router/Controller/Controller.php
Controller.setActions
public function setActions($actions): Controller { $this->controllerRoutes = array_merge($this->controllerRoutes, $actions); return $this; }
php
public function setActions($actions): Controller { $this->controllerRoutes = array_merge($this->controllerRoutes, $actions); return $this; }
[ "public", "function", "setActions", "(", "$", "actions", ")", ":", "Controller", "{", "$", "this", "->", "controllerRoutes", "=", "array_merge", "(", "$", "this", "->", "controllerRoutes", ",", "$", "actions", ")", ";", "return", "$", "this", ";", "}" ]
Set valid routes actions. @param $actions @return array
[ "Set", "valid", "routes", "actions", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Router/Controller/Controller.php#L82-L87
230,759
cygnite/framework
src/Cygnite/Router/Controller/Controller.php
Controller.implicitController
public function implicitController($controller) { $container = $this->getContainer(); $reflection = $container->getReflection()->setClass($controller); $methods = $reflection->getMethods('public', false, null); foreach ($methods as $key => $method) { if ($method !== '__construct') { list($uri, $verb, $method, $plain) = $this->getRoutesParameters($method, $controller, $reflection); $args = $this->getUriArguments($plain); if (!in_array($verb, $this->verbs)) { throw new \RuntimeException("Invalid HTTP verb ($verb) exception."); } $classParam = ['controller' => $controller, 'method' => $method, 'args' => $args]; $this->handleRoute($container, $classParam, $verb, $uri); } } }
php
public function implicitController($controller) { $container = $this->getContainer(); $reflection = $container->getReflection()->setClass($controller); $methods = $reflection->getMethods('public', false, null); foreach ($methods as $key => $method) { if ($method !== '__construct') { list($uri, $verb, $method, $plain) = $this->getRoutesParameters($method, $controller, $reflection); $args = $this->getUriArguments($plain); if (!in_array($verb, $this->verbs)) { throw new \RuntimeException("Invalid HTTP verb ($verb) exception."); } $classParam = ['controller' => $controller, 'method' => $method, 'args' => $args]; $this->handleRoute($container, $classParam, $verb, $uri); } } }
[ "public", "function", "implicitController", "(", "$", "controller", ")", "{", "$", "container", "=", "$", "this", "->", "getContainer", "(", ")", ";", "$", "reflection", "=", "$", "container", "->", "getReflection", "(", ")", "->", "setClass", "(", "$", "controller", ")", ";", "$", "methods", "=", "$", "reflection", "->", "getMethods", "(", "'public'", ",", "false", ",", "null", ")", ";", "foreach", "(", "$", "methods", "as", "$", "key", "=>", "$", "method", ")", "{", "if", "(", "$", "method", "!==", "'__construct'", ")", "{", "list", "(", "$", "uri", ",", "$", "verb", ",", "$", "method", ",", "$", "plain", ")", "=", "$", "this", "->", "getRoutesParameters", "(", "$", "method", ",", "$", "controller", ",", "$", "reflection", ")", ";", "$", "args", "=", "$", "this", "->", "getUriArguments", "(", "$", "plain", ")", ";", "if", "(", "!", "in_array", "(", "$", "verb", ",", "$", "this", "->", "verbs", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"Invalid HTTP verb ($verb) exception.\"", ")", ";", "}", "$", "classParam", "=", "[", "'controller'", "=>", "$", "controller", ",", "'method'", "=>", "$", "method", ",", "'args'", "=>", "$", "args", "]", ";", "$", "this", "->", "handleRoute", "(", "$", "container", ",", "$", "classParam", ",", "$", "verb", ",", "$", "uri", ")", ";", "}", "}", "}" ]
Route to controller action using HTTP verbs and defined pattern names as arguments. @param $controller
[ "Route", "to", "controller", "action", "using", "HTTP", "verbs", "and", "defined", "pattern", "names", "as", "arguments", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Router/Controller/Controller.php#L235-L255
230,760
cygnite/framework
src/Cygnite/Router/Controller/Controller.php
Controller.handleRoute
public function handleRoute($container, $classParam, $verb, $uri): array { $container->router->{$verb}($uri, function () use ($container, $classParam) { extract($classParam); $container['response'] = $container->router->handleControllerDependencies($controller, $method, $args); return $container['response']; }); }
php
public function handleRoute($container, $classParam, $verb, $uri): array { $container->router->{$verb}($uri, function () use ($container, $classParam) { extract($classParam); $container['response'] = $container->router->handleControllerDependencies($controller, $method, $args); return $container['response']; }); }
[ "public", "function", "handleRoute", "(", "$", "container", ",", "$", "classParam", ",", "$", "verb", ",", "$", "uri", ")", ":", "array", "{", "$", "container", "->", "router", "->", "{", "$", "verb", "}", "(", "$", "uri", ",", "function", "(", ")", "use", "(", "$", "container", ",", "$", "classParam", ")", "{", "extract", "(", "$", "classParam", ")", ";", "$", "container", "[", "'response'", "]", "=", "$", "container", "->", "router", "->", "handleControllerDependencies", "(", "$", "controller", ",", "$", "method", ",", "$", "args", ")", ";", "return", "$", "container", "[", "'response'", "]", ";", "}", ")", ";", "}" ]
Route to controller action. @param $container @param $classParam @param $verb @param $uri
[ "Route", "to", "controller", "action", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Router/Controller/Controller.php#L265-L273
230,761
cygnite/framework
src/Cygnite/Router/Controller/Controller.php
Controller.getUriArguments
public function getUriArguments($url): array { $uriParam = str_replace($url, '', $this->router->getCurrentUri()); return array_filter(explode('/', $uriParam)); }
php
public function getUriArguments($url): array { $uriParam = str_replace($url, '', $this->router->getCurrentUri()); return array_filter(explode('/', $uriParam)); }
[ "public", "function", "getUriArguments", "(", "$", "url", ")", ":", "array", "{", "$", "uriParam", "=", "str_replace", "(", "$", "url", ",", "''", ",", "$", "this", "->", "router", "->", "getCurrentUri", "(", ")", ")", ";", "return", "array_filter", "(", "explode", "(", "'/'", ",", "$", "uriParam", ")", ")", ";", "}" ]
Return uri arguments. @param $url @return array
[ "Return", "uri", "arguments", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Router/Controller/Controller.php#L318-L323
230,762
cygnite/framework
src/Cygnite/Router/Controller/Controller.php
Controller.addUriWildcards
public function addUriWildcards($uri, $reflection, $method): string { $refAction = $reflection->getReflectionClass()->getMethod($method); $parameter = ''; $patterns = $this->router->getPattern(); $arguments = new \CachingIterator(new \ArrayIterator($refAction->getParameters())); foreach ($arguments as $key => $param) { if (!$param->isOptional()) { if (array_key_exists('{:' . $param->getName() . '}', $patterns)) { $slash = ($arguments->hasNext()) ? '/' : ''; $parameter .= '{:' . $param->getName() . '}' . $slash; } } } return $uri . '/' . $parameter; }
php
public function addUriWildcards($uri, $reflection, $method): string { $refAction = $reflection->getReflectionClass()->getMethod($method); $parameter = ''; $patterns = $this->router->getPattern(); $arguments = new \CachingIterator(new \ArrayIterator($refAction->getParameters())); foreach ($arguments as $key => $param) { if (!$param->isOptional()) { if (array_key_exists('{:' . $param->getName() . '}', $patterns)) { $slash = ($arguments->hasNext()) ? '/' : ''; $parameter .= '{:' . $param->getName() . '}' . $slash; } } } return $uri . '/' . $parameter; }
[ "public", "function", "addUriWildcards", "(", "$", "uri", ",", "$", "reflection", ",", "$", "method", ")", ":", "string", "{", "$", "refAction", "=", "$", "reflection", "->", "getReflectionClass", "(", ")", "->", "getMethod", "(", "$", "method", ")", ";", "$", "parameter", "=", "''", ";", "$", "patterns", "=", "$", "this", "->", "router", "->", "getPattern", "(", ")", ";", "$", "arguments", "=", "new", "\\", "CachingIterator", "(", "new", "\\", "ArrayIterator", "(", "$", "refAction", "->", "getParameters", "(", ")", ")", ")", ";", "foreach", "(", "$", "arguments", "as", "$", "key", "=>", "$", "param", ")", "{", "if", "(", "!", "$", "param", "->", "isOptional", "(", ")", ")", "{", "if", "(", "array_key_exists", "(", "'{:'", ".", "$", "param", "->", "getName", "(", ")", ".", "'}'", ",", "$", "patterns", ")", ")", "{", "$", "slash", "=", "(", "$", "arguments", "->", "hasNext", "(", ")", ")", "?", "'/'", ":", "''", ";", "$", "parameter", ".=", "'{:'", ".", "$", "param", "->", "getName", "(", ")", ".", "'}'", ".", "$", "slash", ";", "}", "}", "}", "return", "$", "uri", ".", "'/'", ".", "$", "parameter", ";", "}" ]
Add wildcards to the given URI. @param string $uri * @return string
[ "Add", "wildcards", "to", "the", "given", "URI", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Router/Controller/Controller.php#L372-L390
230,763
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.setModelAttributes
protected function setModelAttributes($model) { $this->setModelClass(Inflector::getClassNameFromNamespace($model)); if (!property_exists($model, 'tableName') || is_null($this->tableName)) { $this->setTableName(Inflector::tabilize($this->getModelClass())); } if (!property_exists($model, 'database') || is_null($this->database)) { $this->setDatabase($this->queryBuilder()->getDefaultConnection()); } else { $this->setDatabase($this->database); } if (is_null($this->getDatabase())) { throw new \InvalidArgumentException( 'Please specify database name in your model. '.get_called_class() ); } $this->setPrimarykey(); }
php
protected function setModelAttributes($model) { $this->setModelClass(Inflector::getClassNameFromNamespace($model)); if (!property_exists($model, 'tableName') || is_null($this->tableName)) { $this->setTableName(Inflector::tabilize($this->getModelClass())); } if (!property_exists($model, 'database') || is_null($this->database)) { $this->setDatabase($this->queryBuilder()->getDefaultConnection()); } else { $this->setDatabase($this->database); } if (is_null($this->getDatabase())) { throw new \InvalidArgumentException( 'Please specify database name in your model. '.get_called_class() ); } $this->setPrimarykey(); }
[ "protected", "function", "setModelAttributes", "(", "$", "model", ")", "{", "$", "this", "->", "setModelClass", "(", "Inflector", "::", "getClassNameFromNamespace", "(", "$", "model", ")", ")", ";", "if", "(", "!", "property_exists", "(", "$", "model", ",", "'tableName'", ")", "||", "is_null", "(", "$", "this", "->", "tableName", ")", ")", "{", "$", "this", "->", "setTableName", "(", "Inflector", "::", "tabilize", "(", "$", "this", "->", "getModelClass", "(", ")", ")", ")", ";", "}", "if", "(", "!", "property_exists", "(", "$", "model", ",", "'database'", ")", "||", "is_null", "(", "$", "this", "->", "database", ")", ")", "{", "$", "this", "->", "setDatabase", "(", "$", "this", "->", "queryBuilder", "(", ")", "->", "getDefaultConnection", "(", ")", ")", ";", "}", "else", "{", "$", "this", "->", "setDatabase", "(", "$", "this", "->", "database", ")", ";", "}", "if", "(", "is_null", "(", "$", "this", "->", "getDatabase", "(", ")", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Please specify database name in your model. '", ".", "get_called_class", "(", ")", ")", ";", "}", "$", "this", "->", "setPrimarykey", "(", ")", ";", "}" ]
Configure and set all attributes into model class. @param $model @throws \InvalidArgumentException
[ "Configure", "and", "set", "all", "attributes", "into", "model", "class", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L142-L163
230,764
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.getId
public function getId($key = null) { return (isset($this->index[$key]) && !is_null($key)) ? $this->index[$key] : $this->index[$this->getKeyName()]; }
php
public function getId($key = null) { return (isset($this->index[$key]) && !is_null($key)) ? $this->index[$key] : $this->index[$this->getKeyName()]; }
[ "public", "function", "getId", "(", "$", "key", "=", "null", ")", "{", "return", "(", "isset", "(", "$", "this", "->", "index", "[", "$", "key", "]", ")", "&&", "!", "is_null", "(", "$", "key", ")", ")", "?", "$", "this", "->", "index", "[", "$", "key", "]", ":", "$", "this", "->", "index", "[", "$", "this", "->", "getKeyName", "(", ")", "]", ";", "}" ]
Get the Id stored into object. @param null $key @return mixed
[ "Get", "the", "Id", "stored", "into", "object", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L256-L261
230,765
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.getTableNameFromClass
public function getTableNameFromClass($class, $property = 'tableName', $default = null) { if (!class_exists($class) || !property_exists($class, $property)) { return $default; } $properties = get_class_vars($class); return $properties[$property]; }
php
public function getTableNameFromClass($class, $property = 'tableName', $default = null) { if (!class_exists($class) || !property_exists($class, $property)) { return $default; } $properties = get_class_vars($class); return $properties[$property]; }
[ "public", "function", "getTableNameFromClass", "(", "$", "class", ",", "$", "property", "=", "'tableName'", ",", "$", "default", "=", "null", ")", "{", "if", "(", "!", "class_exists", "(", "$", "class", ")", "||", "!", "property_exists", "(", "$", "class", ",", "$", "property", ")", ")", "{", "return", "$", "default", ";", "}", "$", "properties", "=", "get_class_vars", "(", "$", "class", ")", ";", "return", "$", "properties", "[", "$", "property", "]", ";", "}" ]
Returns table name from Model class properties. @param $class @param string $property @param null $default @return null
[ "Returns", "table", "name", "from", "Model", "class", "properties", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L296-L305
230,766
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.joinWith
public function joinWith($arguments) { $class = static::model(); $tableWith = Inflector::tabilize($arguments[0]); $params = [ $class->tableName.'.'.$class->primaryKey, '=', $tableWith.'.'.Inflector::singularize($class->tableName).self::DEFAULT_FOREIGN_KEY_SUFFIX, ]; if (isset($arguments[1])) { $params = $arguments[1]; } return $this->queryBuilder()->leftOuterJoin($tableWith, $params, $arguments[2]); }
php
public function joinWith($arguments) { $class = static::model(); $tableWith = Inflector::tabilize($arguments[0]); $params = [ $class->tableName.'.'.$class->primaryKey, '=', $tableWith.'.'.Inflector::singularize($class->tableName).self::DEFAULT_FOREIGN_KEY_SUFFIX, ]; if (isset($arguments[1])) { $params = $arguments[1]; } return $this->queryBuilder()->leftOuterJoin($tableWith, $params, $arguments[2]); }
[ "public", "function", "joinWith", "(", "$", "arguments", ")", "{", "$", "class", "=", "static", "::", "model", "(", ")", ";", "$", "tableWith", "=", "Inflector", "::", "tabilize", "(", "$", "arguments", "[", "0", "]", ")", ";", "$", "params", "=", "[", "$", "class", "->", "tableName", ".", "'.'", ".", "$", "class", "->", "primaryKey", ",", "'='", ",", "$", "tableWith", ".", "'.'", ".", "Inflector", "::", "singularize", "(", "$", "class", "->", "tableName", ")", ".", "self", "::", "DEFAULT_FOREIGN_KEY_SUFFIX", ",", "]", ";", "if", "(", "isset", "(", "$", "arguments", "[", "1", "]", ")", ")", "{", "$", "params", "=", "$", "arguments", "[", "1", "]", ";", "}", "return", "$", "this", "->", "queryBuilder", "(", ")", "->", "leftOuterJoin", "(", "$", "tableWith", ",", "$", "params", ",", "$", "arguments", "[", "2", "]", ")", ";", "}" ]
Join model with another model and return query instance. $model->joinWith(['person', 'constraint', 'alias']); @param $arguments @return mixed
[ "Join", "model", "with", "another", "model", "and", "return", "query", "instance", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L385-L402
230,767
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.setAttributes
public function setAttributes($attributes = []) { if (empty($attributes) || !is_array($attributes)) { throw new DatabaseException(sprintf('Invalid argument passed to %s', __FUNCTION__)); } foreach ($attributes as $key => $value) { $this->__set($key, $value); } }
php
public function setAttributes($attributes = []) { if (empty($attributes) || !is_array($attributes)) { throw new DatabaseException(sprintf('Invalid argument passed to %s', __FUNCTION__)); } foreach ($attributes as $key => $value) { $this->__set($key, $value); } }
[ "public", "function", "setAttributes", "(", "$", "attributes", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "attributes", ")", "||", "!", "is_array", "(", "$", "attributes", ")", ")", "{", "throw", "new", "DatabaseException", "(", "sprintf", "(", "'Invalid argument passed to %s'", ",", "__FUNCTION__", ")", ")", ";", "}", "foreach", "(", "$", "attributes", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "__set", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}" ]
Set array of attributes directly into model object. @param array $attributes @throws DatabaseException @return mixed|void
[ "Set", "array", "of", "attributes", "directly", "into", "model", "object", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L473-L482
230,768
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.save
public function save($attributes = []) { $attributes = (empty($attributes) || is_null($attributes)) ? $this->getAttributes() : $attributes; return $this->_save($attributes); }
php
public function save($attributes = []) { $attributes = (empty($attributes) || is_null($attributes)) ? $this->getAttributes() : $attributes; return $this->_save($attributes); }
[ "public", "function", "save", "(", "$", "attributes", "=", "[", "]", ")", "{", "$", "attributes", "=", "(", "empty", "(", "$", "attributes", ")", "||", "is_null", "(", "$", "attributes", ")", ")", "?", "$", "this", "->", "getAttributes", "(", ")", ":", "$", "attributes", ";", "return", "$", "this", "->", "_save", "(", "$", "attributes", ")", ";", "}" ]
Save model attributes into database. @param array $attributes @return mixed
[ "Save", "model", "attributes", "into", "database", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L628-L633
230,769
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord._save
private function _save($arguments) { if ($this->isNew()) { // insert a new row return $this->setAttributesForInsertOrUpdate($arguments, 'insert'); } //update the row using primary key return $this->setAttributesForInsertOrUpdate($arguments, 'update'); }
php
private function _save($arguments) { if ($this->isNew()) { // insert a new row return $this->setAttributesForInsertOrUpdate($arguments, 'insert'); } //update the row using primary key return $this->setAttributesForInsertOrUpdate($arguments, 'update'); }
[ "private", "function", "_save", "(", "$", "arguments", ")", "{", "if", "(", "$", "this", "->", "isNew", "(", ")", ")", "{", "// insert a new row", "return", "$", "this", "->", "setAttributesForInsertOrUpdate", "(", "$", "arguments", ",", "'insert'", ")", ";", "}", "//update the row using primary key", "return", "$", "this", "->", "setAttributesForInsertOrUpdate", "(", "$", "arguments", ",", "'update'", ")", ";", "}" ]
Interally called to identify user tries to insert or update the object. @param $arguments @return mixed
[ "Interally", "called", "to", "identify", "user", "tries", "to", "insert", "or", "update", "the", "object", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L643-L652
230,770
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.findByPK
public function findByPK($arguments) { $arguments = (array) $arguments; $args = [ 'primaryKey' => $this->getKeyName(), 'args' => $arguments, ]; $fetch = $this->queryBuilder()->find('find', $args); if ($fetch instanceof Collection && empty($fetch->asArray())) { return $this->returnEmptyObject(); } $this->setId($this->getKeyName(), array_shift($arguments)); $this->{$this->getKeyName()} = $fetch[0]->{$this->getKeyName()}; foreach ($fetch[0]->getAttributes() as $key => $value) { $this->{$key} = $value; } $this->assignPropertiesToModel($this->attributes); return $this; }
php
public function findByPK($arguments) { $arguments = (array) $arguments; $args = [ 'primaryKey' => $this->getKeyName(), 'args' => $arguments, ]; $fetch = $this->queryBuilder()->find('find', $args); if ($fetch instanceof Collection && empty($fetch->asArray())) { return $this->returnEmptyObject(); } $this->setId($this->getKeyName(), array_shift($arguments)); $this->{$this->getKeyName()} = $fetch[0]->{$this->getKeyName()}; foreach ($fetch[0]->getAttributes() as $key => $value) { $this->{$key} = $value; } $this->assignPropertiesToModel($this->attributes); return $this; }
[ "public", "function", "findByPK", "(", "$", "arguments", ")", "{", "$", "arguments", "=", "(", "array", ")", "$", "arguments", ";", "$", "args", "=", "[", "'primaryKey'", "=>", "$", "this", "->", "getKeyName", "(", ")", ",", "'args'", "=>", "$", "arguments", ",", "]", ";", "$", "fetch", "=", "$", "this", "->", "queryBuilder", "(", ")", "->", "find", "(", "'find'", ",", "$", "args", ")", ";", "if", "(", "$", "fetch", "instanceof", "Collection", "&&", "empty", "(", "$", "fetch", "->", "asArray", "(", ")", ")", ")", "{", "return", "$", "this", "->", "returnEmptyObject", "(", ")", ";", "}", "$", "this", "->", "setId", "(", "$", "this", "->", "getKeyName", "(", ")", ",", "array_shift", "(", "$", "arguments", ")", ")", ";", "$", "this", "->", "{", "$", "this", "->", "getKeyName", "(", ")", "}", "=", "$", "fetch", "[", "0", "]", "->", "{", "$", "this", "->", "getKeyName", "(", ")", "}", ";", "foreach", "(", "$", "fetch", "[", "0", "]", "->", "getAttributes", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "{", "$", "key", "}", "=", "$", "value", ";", "}", "$", "this", "->", "assignPropertiesToModel", "(", "$", "this", "->", "attributes", ")", ";", "return", "$", "this", ";", "}" ]
Find Record by Primary Key Id. @param $arguments @return $this|mixed
[ "Find", "Record", "by", "Primary", "Key", "Id", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L702-L727
230,771
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.assignPropertiesToModel
protected function assignPropertiesToModel($attributes = []) { $model = null; $model = self::model(); foreach ($attributes as $key => $value) { $model->{$key} = $value; } }
php
protected function assignPropertiesToModel($attributes = []) { $model = null; $model = self::model(); foreach ($attributes as $key => $value) { $model->{$key} = $value; } }
[ "protected", "function", "assignPropertiesToModel", "(", "$", "attributes", "=", "[", "]", ")", "{", "$", "model", "=", "null", ";", "$", "model", "=", "self", "::", "model", "(", ")", ";", "foreach", "(", "$", "attributes", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "model", "->", "{", "$", "key", "}", "=", "$", "value", ";", "}", "}" ]
We will assign values to model properties. @param array $attributes
[ "We", "will", "assign", "values", "to", "model", "properties", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L734-L742
230,772
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.setPageLimit
public function setPageLimit($number = null) { if (is_null($number)) { $number = $this->setPageLimit(); } $pagination = Pagination::make(); $pagination->setPerPage($number); }
php
public function setPageLimit($number = null) { if (is_null($number)) { $number = $this->setPageLimit(); } $pagination = Pagination::make(); $pagination->setPerPage($number); }
[ "public", "function", "setPageLimit", "(", "$", "number", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "number", ")", ")", "{", "$", "number", "=", "$", "this", "->", "setPageLimit", "(", ")", ";", "}", "$", "pagination", "=", "Pagination", "::", "make", "(", ")", ";", "$", "pagination", "->", "setPerPage", "(", "$", "number", ")", ";", "}" ]
Set the pagination limit. @param null $number
[ "Set", "the", "pagination", "limit", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L751-L759
230,773
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.hasOne
protected function hasOne($associatedClass, $foreignKey = null, $mappingKeyInBaseTable = null) { return $this->findHasOneOrMany($associatedClass, $foreignKey, $mappingKeyInBaseTable); }
php
protected function hasOne($associatedClass, $foreignKey = null, $mappingKeyInBaseTable = null) { return $this->findHasOneOrMany($associatedClass, $foreignKey, $mappingKeyInBaseTable); }
[ "protected", "function", "hasOne", "(", "$", "associatedClass", ",", "$", "foreignKey", "=", "null", ",", "$", "mappingKeyInBaseTable", "=", "null", ")", "{", "return", "$", "this", "->", "findHasOneOrMany", "(", "$", "associatedClass", ",", "$", "foreignKey", ",", "$", "mappingKeyInBaseTable", ")", ";", "}" ]
This method is to build one-to-one releationship between two table. @param $associatedClass @param null $foreignKey @param null $mappingKeyInBaseTable @return Query\Builder
[ "This", "method", "is", "to", "build", "one", "-", "to", "-", "one", "releationship", "between", "two", "table", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L867-L870
230,774
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.hasMany
protected function hasMany($associatedClass, $foreignKey = null, $mappingKeyInBaseTable = null) { return $this->findHasOneOrMany($associatedClass, $foreignKey, $mappingKeyInBaseTable); }
php
protected function hasMany($associatedClass, $foreignKey = null, $mappingKeyInBaseTable = null) { return $this->findHasOneOrMany($associatedClass, $foreignKey, $mappingKeyInBaseTable); }
[ "protected", "function", "hasMany", "(", "$", "associatedClass", ",", "$", "foreignKey", "=", "null", ",", "$", "mappingKeyInBaseTable", "=", "null", ")", "{", "return", "$", "this", "->", "findHasOneOrMany", "(", "$", "associatedClass", ",", "$", "foreignKey", ",", "$", "mappingKeyInBaseTable", ")", ";", "}" ]
This method use to construct one-to-many relationship of model class We will build relations based on the foreign key mapped in associated table. @param $associatedClass @param null $foreignKey @param null $mappingKeyInBaseTable @return Query\Builder
[ "This", "method", "use", "to", "construct", "one", "-", "to", "-", "many", "relationship", "of", "model", "class", "We", "will", "build", "relations", "based", "on", "the", "foreign", "key", "mapped", "in", "associated", "table", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L882-L885
230,775
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.belongsTo
protected function belongsTo($associatedClass, $foreignKey = null, $mappingId = null) { $associatedTable = $this->getTableNameFromClass($associatedClass); $foreignKey = $this->buildForeignKeyName($foreignKey, $associatedTable); $associatedTableId = $this->$foreignKey; if (is_null($mappingId)) { return (new $associatedClass())->where($this->primaryKey, '=', $associatedTableId); } return (new $associatedClass())->where($mappingId, '=', $associatedTableId); }
php
protected function belongsTo($associatedClass, $foreignKey = null, $mappingId = null) { $associatedTable = $this->getTableNameFromClass($associatedClass); $foreignKey = $this->buildForeignKeyName($foreignKey, $associatedTable); $associatedTableId = $this->$foreignKey; if (is_null($mappingId)) { return (new $associatedClass())->where($this->primaryKey, '=', $associatedTableId); } return (new $associatedClass())->where($mappingId, '=', $associatedTableId); }
[ "protected", "function", "belongsTo", "(", "$", "associatedClass", ",", "$", "foreignKey", "=", "null", ",", "$", "mappingId", "=", "null", ")", "{", "$", "associatedTable", "=", "$", "this", "->", "getTableNameFromClass", "(", "$", "associatedClass", ")", ";", "$", "foreignKey", "=", "$", "this", "->", "buildForeignKeyName", "(", "$", "foreignKey", ",", "$", "associatedTable", ")", ";", "$", "associatedTableId", "=", "$", "this", "->", "$", "foreignKey", ";", "if", "(", "is_null", "(", "$", "mappingId", ")", ")", "{", "return", "(", "new", "$", "associatedClass", "(", ")", ")", "->", "where", "(", "$", "this", "->", "primaryKey", ",", "'='", ",", "$", "associatedTableId", ")", ";", "}", "return", "(", "new", "$", "associatedClass", "(", ")", ")", "->", "where", "(", "$", "mappingId", ",", "'='", ",", "$", "associatedTableId", ")", ";", "}" ]
This method is use to construct one-to-one and one-to-many relationship Make sure your base table has primary key as 'id' and mapped key table_name_id. example: user : id , comment_id comment: id, commment @param $associatedClass @param null $foreignKey @param null $mappingId @return Query\Builder Object
[ "This", "method", "is", "use", "to", "construct", "one", "-", "to", "-", "one", "and", "one", "-", "to", "-", "many", "relationship", "Make", "sure", "your", "base", "table", "has", "primary", "key", "as", "id", "and", "mapped", "key", "table_name_id", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L900-L911
230,776
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.findHasOneOrMany
protected function findHasOneOrMany($associatedClass, $foreignKey = null, $mappingId = null) { $baseTable = $this->getTableName(); $foreignKey = $this->buildForeignKeyName($foreignKey, $baseTable); $whereValue = ''; $whereValue = $this->{$this->primaryKey}; if (!is_null($mappingId)) { $whereValue = $this->{$mappingId}; } /* | We will build query and return Query Builder object | to the user, to either make use of findAll() or findOne() method | to get data */ return (new $associatedClass())->where($foreignKey, '=', $whereValue); }
php
protected function findHasOneOrMany($associatedClass, $foreignKey = null, $mappingId = null) { $baseTable = $this->getTableName(); $foreignKey = $this->buildForeignKeyName($foreignKey, $baseTable); $whereValue = ''; $whereValue = $this->{$this->primaryKey}; if (!is_null($mappingId)) { $whereValue = $this->{$mappingId}; } /* | We will build query and return Query Builder object | to the user, to either make use of findAll() or findOne() method | to get data */ return (new $associatedClass())->where($foreignKey, '=', $whereValue); }
[ "protected", "function", "findHasOneOrMany", "(", "$", "associatedClass", ",", "$", "foreignKey", "=", "null", ",", "$", "mappingId", "=", "null", ")", "{", "$", "baseTable", "=", "$", "this", "->", "getTableName", "(", ")", ";", "$", "foreignKey", "=", "$", "this", "->", "buildForeignKeyName", "(", "$", "foreignKey", ",", "$", "baseTable", ")", ";", "$", "whereValue", "=", "''", ";", "$", "whereValue", "=", "$", "this", "->", "{", "$", "this", "->", "primaryKey", "}", ";", "if", "(", "!", "is_null", "(", "$", "mappingId", ")", ")", "{", "$", "whereValue", "=", "$", "this", "->", "{", "$", "mappingId", "}", ";", "}", "/*\n | We will build query and return Query Builder object\n | to the user, to either make use of findAll() or findOne() method\n | to get data\n */", "return", "(", "new", "$", "associatedClass", "(", ")", ")", "->", "where", "(", "$", "foreignKey", ",", "'='", ",", "$", "whereValue", ")", ";", "}" ]
This method is use to build queries for hasOne and hasMany methods. @param $associatedClass @param null $foreignKey @param null $mappingId @return Query\Builder Object
[ "This", "method", "is", "use", "to", "build", "queries", "for", "hasOne", "and", "hasMany", "methods", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L922-L940
230,777
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.hasManyThrough
protected function hasManyThrough( $associatedClass, $joinModelClass = null, $baseTableId = null, $associatedTableId = null, $firstKey = null, $secondKey = null ) { $baseClass = get_class($this); if (is_null($joinModelClass)) { $joinModelClass = $this->getJoinClassName($baseClass, $associatedClass); } // Get table names from each model class $classes = [$baseClass, $associatedClass, $joinModelClass]; list($baseTable, $associatedTable, $joinTable) = $this->filterTableNameFromClass($classes); // Get baseTableId & associatedTableId from the given input $baseTableId = (is_null($firstKey)) ? $this->getIdColumn($baseClass) : $firstKey; $associatedTableId = (is_null($secondKey)) ? $this->getIdColumn($associatedClass) : $secondKey; // Get the mappingId and associatedId for joining table $mappingId = $this->buildForeignKeyName($baseTableId, $baseTable); $associatedTableId = $this->buildForeignKeyName($associatedTableId, $associatedTable); return (new $associatedClass()) ->select("{$associatedTable}.*") ->innerJoin($joinTable, [ "{$associatedTable}.{$associatedTableId}", '=', "{$joinTable}.{$associatedTableId}", ] )->where("{$joinTable}.{$mappingId}", '=', $this->$baseTableId); }
php
protected function hasManyThrough( $associatedClass, $joinModelClass = null, $baseTableId = null, $associatedTableId = null, $firstKey = null, $secondKey = null ) { $baseClass = get_class($this); if (is_null($joinModelClass)) { $joinModelClass = $this->getJoinClassName($baseClass, $associatedClass); } // Get table names from each model class $classes = [$baseClass, $associatedClass, $joinModelClass]; list($baseTable, $associatedTable, $joinTable) = $this->filterTableNameFromClass($classes); // Get baseTableId & associatedTableId from the given input $baseTableId = (is_null($firstKey)) ? $this->getIdColumn($baseClass) : $firstKey; $associatedTableId = (is_null($secondKey)) ? $this->getIdColumn($associatedClass) : $secondKey; // Get the mappingId and associatedId for joining table $mappingId = $this->buildForeignKeyName($baseTableId, $baseTable); $associatedTableId = $this->buildForeignKeyName($associatedTableId, $associatedTable); return (new $associatedClass()) ->select("{$associatedTable}.*") ->innerJoin($joinTable, [ "{$associatedTable}.{$associatedTableId}", '=', "{$joinTable}.{$associatedTableId}", ] )->where("{$joinTable}.{$mappingId}", '=', $this->$baseTableId); }
[ "protected", "function", "hasManyThrough", "(", "$", "associatedClass", ",", "$", "joinModelClass", "=", "null", ",", "$", "baseTableId", "=", "null", ",", "$", "associatedTableId", "=", "null", ",", "$", "firstKey", "=", "null", ",", "$", "secondKey", "=", "null", ")", "{", "$", "baseClass", "=", "get_class", "(", "$", "this", ")", ";", "if", "(", "is_null", "(", "$", "joinModelClass", ")", ")", "{", "$", "joinModelClass", "=", "$", "this", "->", "getJoinClassName", "(", "$", "baseClass", ",", "$", "associatedClass", ")", ";", "}", "// Get table names from each model class", "$", "classes", "=", "[", "$", "baseClass", ",", "$", "associatedClass", ",", "$", "joinModelClass", "]", ";", "list", "(", "$", "baseTable", ",", "$", "associatedTable", ",", "$", "joinTable", ")", "=", "$", "this", "->", "filterTableNameFromClass", "(", "$", "classes", ")", ";", "// Get baseTableId & associatedTableId from the given input", "$", "baseTableId", "=", "(", "is_null", "(", "$", "firstKey", ")", ")", "?", "$", "this", "->", "getIdColumn", "(", "$", "baseClass", ")", ":", "$", "firstKey", ";", "$", "associatedTableId", "=", "(", "is_null", "(", "$", "secondKey", ")", ")", "?", "$", "this", "->", "getIdColumn", "(", "$", "associatedClass", ")", ":", "$", "secondKey", ";", "// Get the mappingId and associatedId for joining table", "$", "mappingId", "=", "$", "this", "->", "buildForeignKeyName", "(", "$", "baseTableId", ",", "$", "baseTable", ")", ";", "$", "associatedTableId", "=", "$", "this", "->", "buildForeignKeyName", "(", "$", "associatedTableId", ",", "$", "associatedTable", ")", ";", "return", "(", "new", "$", "associatedClass", "(", ")", ")", "->", "select", "(", "\"{$associatedTable}.*\"", ")", "->", "innerJoin", "(", "$", "joinTable", ",", "[", "\"{$associatedTable}.{$associatedTableId}\"", ",", "'='", ",", "\"{$joinTable}.{$associatedTableId}\"", ",", "]", ")", "->", "where", "(", "\"{$joinTable}.{$mappingId}\"", ",", "'='", ",", "$", "this", "->", "$", "baseTableId", ")", ";", "}" ]
This method is to build many to many relationships using model classes. @param $associatedClass @param null $joinModelClass @param null $baseTableId @param null $associatedTableId @param null $firstKey @param null $secondKey @return Query\Builder Object @note Model Class must contain the property $tableName = 'table_name';
[ "This", "method", "is", "to", "build", "many", "to", "many", "relationships", "using", "model", "classes", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L956-L989
230,778
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.getJoinClassName
private function getJoinClassName($baseClass, $associatedClass) { $classs = [Inflector::getClassName($baseClass), $associatedClass]; sort($classs, SORT_STRING); return implode('', $classs); }
php
private function getJoinClassName($baseClass, $associatedClass) { $classs = [Inflector::getClassName($baseClass), $associatedClass]; sort($classs, SORT_STRING); return implode('', $classs); }
[ "private", "function", "getJoinClassName", "(", "$", "baseClass", ",", "$", "associatedClass", ")", "{", "$", "classs", "=", "[", "Inflector", "::", "getClassName", "(", "$", "baseClass", ")", ",", "$", "associatedClass", "]", ";", "sort", "(", "$", "classs", ",", "SORT_STRING", ")", ";", "return", "implode", "(", "''", ",", "$", "classs", ")", ";", "}" ]
Get Join class name. @param $baseClass @param $associatedClass @return string
[ "Get", "Join", "class", "name", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L1013-L1019
230,779
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.filter
public function filter() { $args = func_get_args(); $filterFunction = array_shift($args); array_unshift($args, $this); if (method_exists($this->modelClassNs, $filterFunction)) { return static::callDynamicMethod([$this->modelClassNs, $filterFunction], $args); } }
php
public function filter() { $args = func_get_args(); $filterFunction = array_shift($args); array_unshift($args, $this); if (method_exists($this->modelClassNs, $filterFunction)) { return static::callDynamicMethod([$this->modelClassNs, $filterFunction], $args); } }
[ "public", "function", "filter", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "filterFunction", "=", "array_shift", "(", "$", "args", ")", ";", "array_unshift", "(", "$", "args", ",", "$", "this", ")", ";", "if", "(", "method_exists", "(", "$", "this", "->", "modelClassNs", ",", "$", "filterFunction", ")", ")", "{", "return", "static", "::", "callDynamicMethod", "(", "[", "$", "this", "->", "modelClassNs", ",", "$", "filterFunction", "]", ",", "$", "args", ")", ";", "}", "}" ]
Middleware method to allow user to dynamically change query before executing and returning back. <code> $book->filter('applyTax')->findMany(); public function applyTax($query) { return $query->where('tax', '=', '10%'); } or $book->filter('applyTax', 'tax', '10%')->findAll(); public function applyTax($query, $column, $value) { return $query->where($column, '=', $value); } </code> @return mixed
[ "Middleware", "method", "to", "allow", "user", "to", "dynamically", "change", "query", "before", "executing", "and", "returning", "back", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L1058-L1067
230,780
cygnite/framework
src/Cygnite/Database/Cyrus/ActiveRecord.php
ActiveRecord.with
public static function with($model) { $data = static::model()->findAll(); $idKey = null; $whereIn = []; foreach ($data as $key => $value) { $idKey = $value->primaryKey; $whereIn[] = $value->{$value->primaryKey}; } $associatedModel = new $model(); $associatedData = $associatedModel ->where(static::getForeignKey(static::model()->tableName), 'IN', implode(',', $whereIn)) ->findAll(); $data = static::buildRelations($data, $associatedModel, $associatedData); return $data; }
php
public static function with($model) { $data = static::model()->findAll(); $idKey = null; $whereIn = []; foreach ($data as $key => $value) { $idKey = $value->primaryKey; $whereIn[] = $value->{$value->primaryKey}; } $associatedModel = new $model(); $associatedData = $associatedModel ->where(static::getForeignKey(static::model()->tableName), 'IN', implode(',', $whereIn)) ->findAll(); $data = static::buildRelations($data, $associatedModel, $associatedData); return $data; }
[ "public", "static", "function", "with", "(", "$", "model", ")", "{", "$", "data", "=", "static", "::", "model", "(", ")", "->", "findAll", "(", ")", ";", "$", "idKey", "=", "null", ";", "$", "whereIn", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "idKey", "=", "$", "value", "->", "primaryKey", ";", "$", "whereIn", "[", "]", "=", "$", "value", "->", "{", "$", "value", "->", "primaryKey", "}", ";", "}", "$", "associatedModel", "=", "new", "$", "model", "(", ")", ";", "$", "associatedData", "=", "$", "associatedModel", "->", "where", "(", "static", "::", "getForeignKey", "(", "static", "::", "model", "(", ")", "->", "tableName", ")", ",", "'IN'", ",", "implode", "(", "','", ",", "$", "whereIn", ")", ")", "->", "findAll", "(", ")", ";", "$", "data", "=", "static", "::", "buildRelations", "(", "$", "data", ",", "$", "associatedModel", ",", "$", "associatedData", ")", ";", "return", "$", "data", ";", "}" ]
We will load associated model eagarly, solve n+1 query problem Only two queries will get executed and build relation collection object. @param $model @return mixed
[ "We", "will", "load", "associated", "model", "eagarly", "solve", "n", "+", "1", "query", "problem", "Only", "two", "queries", "will", "get", "executed", "and", "build", "relation", "collection", "object", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Database/Cyrus/ActiveRecord.php#L1078-L1097
230,781
schnittstabil/psr7-csrf-middleware
src/MiddlewareBuilder.php
MiddlewareBuilder.create
public static function create( $key, $ttl = 1440, $algo = 'SHA512', $middlewareClass = Middleware::class ) { return new self(new TokenService($key, $ttl, $algo), $middlewareClass); }
php
public static function create( $key, $ttl = 1440, $algo = 'SHA512', $middlewareClass = Middleware::class ) { return new self(new TokenService($key, $ttl, $algo), $middlewareClass); }
[ "public", "static", "function", "create", "(", "$", "key", ",", "$", "ttl", "=", "1440", ",", "$", "algo", "=", "'SHA512'", ",", "$", "middlewareClass", "=", "Middleware", "::", "class", ")", "{", "return", "new", "self", "(", "new", "TokenService", "(", "$", "key", ",", "$", "ttl", ",", "$", "algo", ")", ",", "$", "middlewareClass", ")", ";", "}" ]
Create a new MiddlewareBuilder. `$ttl` is used for calculating the expiration time of the tokens, its default value (1440sec === 24min) correspond to the default `session.gc_maxlifetime`. @see http://php.net/manual/en/session.configuration.php Documentation of `session.gc-maxlifetime` @param string $key Shared secret key used for generating token signatures @param int $ttl Default Time to Live in seconds @param string $algo Name of hashing algorithm. See hash_algos() for a list of supported algorithms @param string $middlewareClass Middleware class @return static
[ "Create", "a", "new", "MiddlewareBuilder", "." ]
bbd00834ceb891ebf6419e6fab506b641e04b2bb
https://github.com/schnittstabil/psr7-csrf-middleware/blob/bbd00834ceb891ebf6419e6fab506b641e04b2bb/src/MiddlewareBuilder.php#L54-L61
230,782
schnittstabil/psr7-csrf-middleware
src/MiddlewareBuilder.php
MiddlewareBuilder.buildCookieToHeaderMiddleware
public function buildCookieToHeaderMiddleware( $cookieName = 'XSRF-TOKEN', $headerName = 'X-XSRF-TOKEN', callable $rejectMiddleware = null, callable $cookieModifier = null ) { return (new $this->middlewareClass($this->tokenService)) ->withGuard($rejectMiddleware) ->withAcceptHeaderToken($headerName) ->withAcceptMethods(['GET', 'OPTIONS']) ->withRespondWithCookieToken($cookieName, $cookieModifier); }
php
public function buildCookieToHeaderMiddleware( $cookieName = 'XSRF-TOKEN', $headerName = 'X-XSRF-TOKEN', callable $rejectMiddleware = null, callable $cookieModifier = null ) { return (new $this->middlewareClass($this->tokenService)) ->withGuard($rejectMiddleware) ->withAcceptHeaderToken($headerName) ->withAcceptMethods(['GET', 'OPTIONS']) ->withRespondWithCookieToken($cookieName, $cookieModifier); }
[ "public", "function", "buildCookieToHeaderMiddleware", "(", "$", "cookieName", "=", "'XSRF-TOKEN'", ",", "$", "headerName", "=", "'X-XSRF-TOKEN'", ",", "callable", "$", "rejectMiddleware", "=", "null", ",", "callable", "$", "cookieModifier", "=", "null", ")", "{", "return", "(", "new", "$", "this", "->", "middlewareClass", "(", "$", "this", "->", "tokenService", ")", ")", "->", "withGuard", "(", "$", "rejectMiddleware", ")", "->", "withAcceptHeaderToken", "(", "$", "headerName", ")", "->", "withAcceptMethods", "(", "[", "'GET'", ",", "'OPTIONS'", "]", ")", "->", "withRespondWithCookieToken", "(", "$", "cookieName", ",", "$", "cookieModifier", ")", ";", "}" ]
Build a AngularJS compatible stateless Cookie-To-Header CSRF proptection middleware. + Sends tokens via cookies + Accepts tokens via request headers + Always accepts GET requests @param string $cookieName Cookie name @param string $headerName Header field name @param callable $rejectMiddleware See `\Schnittstabil\Psr7\Csrf\Middlewares\Guard` for details @param callable $cookieModifier See `Schnittstabil\Psr7\Csrf\Middlewares\RespondWithCookieToken` for details @return static
[ "Build", "a", "AngularJS", "compatible", "stateless", "Cookie", "-", "To", "-", "Header", "CSRF", "proptection", "middleware", "." ]
bbd00834ceb891ebf6419e6fab506b641e04b2bb
https://github.com/schnittstabil/psr7-csrf-middleware/blob/bbd00834ceb891ebf6419e6fab506b641e04b2bb/src/MiddlewareBuilder.php#L77-L88
230,783
schnittstabil/psr7-csrf-middleware
src/MiddlewareBuilder.php
MiddlewareBuilder.buildHeaderToHeaderMiddleware
public function buildHeaderToHeaderMiddleware( $responseHeaderName = 'XSRF-TOKEN', $requestHeaderName = 'X-XSRF-TOKEN', callable $rejectMiddleware = null ) { return (new $this->middlewareClass($this->tokenService)) ->withGuard($rejectMiddleware) ->withAcceptHeaderToken($requestHeaderName) ->withAcceptMethods(['GET', 'OPTIONS']) ->withRespondWithHeaderToken($responseHeaderName); }
php
public function buildHeaderToHeaderMiddleware( $responseHeaderName = 'XSRF-TOKEN', $requestHeaderName = 'X-XSRF-TOKEN', callable $rejectMiddleware = null ) { return (new $this->middlewareClass($this->tokenService)) ->withGuard($rejectMiddleware) ->withAcceptHeaderToken($requestHeaderName) ->withAcceptMethods(['GET', 'OPTIONS']) ->withRespondWithHeaderToken($responseHeaderName); }
[ "public", "function", "buildHeaderToHeaderMiddleware", "(", "$", "responseHeaderName", "=", "'XSRF-TOKEN'", ",", "$", "requestHeaderName", "=", "'X-XSRF-TOKEN'", ",", "callable", "$", "rejectMiddleware", "=", "null", ")", "{", "return", "(", "new", "$", "this", "->", "middlewareClass", "(", "$", "this", "->", "tokenService", ")", ")", "->", "withGuard", "(", "$", "rejectMiddleware", ")", "->", "withAcceptHeaderToken", "(", "$", "requestHeaderName", ")", "->", "withAcceptMethods", "(", "[", "'GET'", ",", "'OPTIONS'", "]", ")", "->", "withRespondWithHeaderToken", "(", "$", "responseHeaderName", ")", ";", "}" ]
Build a stateless Header-To-Header CSRF proptection middleware. + Sends tokens via headers + Accepts tokens via request headers + Always accepts GET requests @param string $responseHeaderName Response header field name @param string $requestHeaderName Request header field name @param callable $rejectMiddleware See `\Schnittstabil\Psr7\Csrf\Middlewares\Guard` for details @return static
[ "Build", "a", "stateless", "Header", "-", "To", "-", "Header", "CSRF", "proptection", "middleware", "." ]
bbd00834ceb891ebf6419e6fab506b641e04b2bb
https://github.com/schnittstabil/psr7-csrf-middleware/blob/bbd00834ceb891ebf6419e6fab506b641e04b2bb/src/MiddlewareBuilder.php#L103-L113
230,784
schnittstabil/psr7-csrf-middleware
src/MiddlewareBuilder.php
MiddlewareBuilder.buildSynchronizerTokenPatternMiddleware
public function buildSynchronizerTokenPatternMiddleware( $path = 'X-XSRF-TOKEN', callable $rejectMiddleware = null ) { return (new $this->middlewareClass($this->tokenService)) ->withGuard($rejectMiddleware) ->withAcceptParsedBodyToken($path) ->withAcceptMethods(['GET', 'OPTIONS']); }
php
public function buildSynchronizerTokenPatternMiddleware( $path = 'X-XSRF-TOKEN', callable $rejectMiddleware = null ) { return (new $this->middlewareClass($this->tokenService)) ->withGuard($rejectMiddleware) ->withAcceptParsedBodyToken($path) ->withAcceptMethods(['GET', 'OPTIONS']); }
[ "public", "function", "buildSynchronizerTokenPatternMiddleware", "(", "$", "path", "=", "'X-XSRF-TOKEN'", ",", "callable", "$", "rejectMiddleware", "=", "null", ")", "{", "return", "(", "new", "$", "this", "->", "middlewareClass", "(", "$", "this", "->", "tokenService", ")", ")", "->", "withGuard", "(", "$", "rejectMiddleware", ")", "->", "withAcceptParsedBodyToken", "(", "$", "path", ")", "->", "withAcceptMethods", "(", "[", "'GET'", ",", "'OPTIONS'", "]", ")", ";", "}" ]
Build a stateless Synchronizer Token Pattern CSRF proptection middleware. + Accepts tokens via request body (`ServerRequestInterface::getParsedBody`) + Always accepts GET requests + Tokens have to be generated by `getTokenService()->generate()` and manually rendered into HTML/JSON or XML. @see https://github.com/schnittstabil/get Documentation of `Schnittstabil\Get\getValue` @see http://www.php-fig.org/psr/psr-7 Documentation of `ServerRequestInterface::getParsedBody` @param string|int|mixed[] $path a `Schnittstabil\Get\getValue` path @param callable $rejectMiddleware See `\Schnittstabil\Psr7\Csrf\Middlewares\Guard` for details @return static
[ "Build", "a", "stateless", "Synchronizer", "Token", "Pattern", "CSRF", "proptection", "middleware", "." ]
bbd00834ceb891ebf6419e6fab506b641e04b2bb
https://github.com/schnittstabil/psr7-csrf-middleware/blob/bbd00834ceb891ebf6419e6fab506b641e04b2bb/src/MiddlewareBuilder.php#L131-L139
230,785
brick/event
src/EventDispatcher.php
EventDispatcher.removeListener
public function removeListener(string $event, callable $listener) : void { if (isset($this->listeners[$event])) { foreach ($this->listeners[$event] as $priority => $listeners) { foreach ($this->listeners[$event][$priority] as $key => $instance) { if ($instance === $listener) { unset($this->listeners[$event][$priority][$key]); unset($this->sorted[$event]); if (empty($this->listeners[$event][$priority])) { unset($this->listeners[$event][$priority]); if (empty($this->listeners[$event])) { unset($this->listeners[$event]); } } } } } } }
php
public function removeListener(string $event, callable $listener) : void { if (isset($this->listeners[$event])) { foreach ($this->listeners[$event] as $priority => $listeners) { foreach ($this->listeners[$event][$priority] as $key => $instance) { if ($instance === $listener) { unset($this->listeners[$event][$priority][$key]); unset($this->sorted[$event]); if (empty($this->listeners[$event][$priority])) { unset($this->listeners[$event][$priority]); if (empty($this->listeners[$event])) { unset($this->listeners[$event]); } } } } } } }
[ "public", "function", "removeListener", "(", "string", "$", "event", ",", "callable", "$", "listener", ")", ":", "void", "{", "if", "(", "isset", "(", "$", "this", "->", "listeners", "[", "$", "event", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "listeners", "[", "$", "event", "]", "as", "$", "priority", "=>", "$", "listeners", ")", "{", "foreach", "(", "$", "this", "->", "listeners", "[", "$", "event", "]", "[", "$", "priority", "]", "as", "$", "key", "=>", "$", "instance", ")", "{", "if", "(", "$", "instance", "===", "$", "listener", ")", "{", "unset", "(", "$", "this", "->", "listeners", "[", "$", "event", "]", "[", "$", "priority", "]", "[", "$", "key", "]", ")", ";", "unset", "(", "$", "this", "->", "sorted", "[", "$", "event", "]", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "listeners", "[", "$", "event", "]", "[", "$", "priority", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "listeners", "[", "$", "event", "]", "[", "$", "priority", "]", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "listeners", "[", "$", "event", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "listeners", "[", "$", "event", "]", ")", ";", "}", "}", "}", "}", "}", "}", "}" ]
Removes an event listener. If the listener is not registered for this type, this method does nothing. If the listener has been registered several times for this type, all instances are removed. @param string $event The event name. @param callable $listener The event listener. @return void
[ "Removes", "an", "event", "listener", "." ]
63e3fcc356d5eeada4f493c58af5533c735c6d51
https://github.com/brick/event/blob/63e3fcc356d5eeada4f493c58af5533c735c6d51/src/EventDispatcher.php#L57-L77
230,786
brick/event
src/EventDispatcher.php
EventDispatcher.getListeners
public function getListeners(string $event) : array { if (empty($this->listeners[$event])) { return []; } if (! isset($this->sorted[$event])) { $this->sorted[$event] = $this->sortListeners($this->listeners[$event]); } return $this->sorted[$event]; }
php
public function getListeners(string $event) : array { if (empty($this->listeners[$event])) { return []; } if (! isset($this->sorted[$event])) { $this->sorted[$event] = $this->sortListeners($this->listeners[$event]); } return $this->sorted[$event]; }
[ "public", "function", "getListeners", "(", "string", "$", "event", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "this", "->", "listeners", "[", "$", "event", "]", ")", ")", "{", "return", "[", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "sorted", "[", "$", "event", "]", ")", ")", "{", "$", "this", "->", "sorted", "[", "$", "event", "]", "=", "$", "this", "->", "sortListeners", "(", "$", "this", "->", "listeners", "[", "$", "event", "]", ")", ";", "}", "return", "$", "this", "->", "sorted", "[", "$", "event", "]", ";", "}" ]
Returns all registered listeners for the given type. Listeners are returned in the order they will be called. @param string $event The event name. @return callable[]
[ "Returns", "all", "registered", "listeners", "for", "the", "given", "type", "." ]
63e3fcc356d5eeada4f493c58af5533c735c6d51
https://github.com/brick/event/blob/63e3fcc356d5eeada4f493c58af5533c735c6d51/src/EventDispatcher.php#L88-L99
230,787
brick/event
src/EventDispatcher.php
EventDispatcher.getAllListeners
public function getAllListeners() : array { foreach ($this->listeners as $event => $listeners) { if (! isset($this->sorted[$event])) { $this->sorted[$event] = $this->sortListeners($listeners); } } return $this->sorted; }
php
public function getAllListeners() : array { foreach ($this->listeners as $event => $listeners) { if (! isset($this->sorted[$event])) { $this->sorted[$event] = $this->sortListeners($listeners); } } return $this->sorted; }
[ "public", "function", "getAllListeners", "(", ")", ":", "array", "{", "foreach", "(", "$", "this", "->", "listeners", "as", "$", "event", "=>", "$", "listeners", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "sorted", "[", "$", "event", "]", ")", ")", "{", "$", "this", "->", "sorted", "[", "$", "event", "]", "=", "$", "this", "->", "sortListeners", "(", "$", "listeners", ")", ";", "}", "}", "return", "$", "this", "->", "sorted", ";", "}" ]
Returns all registered listeners indexed by type. Listeners are returned in the order they will be called for each type. @return callable[][]
[ "Returns", "all", "registered", "listeners", "indexed", "by", "type", "." ]
63e3fcc356d5eeada4f493c58af5533c735c6d51
https://github.com/brick/event/blob/63e3fcc356d5eeada4f493c58af5533c735c6d51/src/EventDispatcher.php#L108-L117
230,788
brick/event
src/EventDispatcher.php
EventDispatcher.dispatch
public function dispatch(string $event, ...$parameters) : void { foreach ($this->getListeners($event) as $listener) { if ($listener(...$parameters) === false) { break; } } }
php
public function dispatch(string $event, ...$parameters) : void { foreach ($this->getListeners($event) as $listener) { if ($listener(...$parameters) === false) { break; } } }
[ "public", "function", "dispatch", "(", "string", "$", "event", ",", "...", "$", "parameters", ")", ":", "void", "{", "foreach", "(", "$", "this", "->", "getListeners", "(", "$", "event", ")", "as", "$", "listener", ")", "{", "if", "(", "$", "listener", "(", "...", "$", "parameters", ")", "===", "false", ")", "{", "break", ";", "}", "}", "}" ]
Dispatches an event to the registered listeners. The highest priority listeners will be called first. If several listeners have the same priority, they will be called in the order they have been registered. @param string $event The event name. @param mixed ...$parameters The parameters to pass to the listeners. @return void
[ "Dispatches", "an", "event", "to", "the", "registered", "listeners", "." ]
63e3fcc356d5eeada4f493c58af5533c735c6d51
https://github.com/brick/event/blob/63e3fcc356d5eeada4f493c58af5533c735c6d51/src/EventDispatcher.php#L130-L137
230,789
ARCANEDEV/GeoIP
src/Support/IpDetector.php
IpDetector.detect
public static function detect() { foreach (static::$remotes as $remote) { if ($address = getenv($remote)) { foreach (explode(',', $address) as $ipAddress) { if (IpValidator::validate($ipAddress)) return $ipAddress; } } } return static::$default; }
php
public static function detect() { foreach (static::$remotes as $remote) { if ($address = getenv($remote)) { foreach (explode(',', $address) as $ipAddress) { if (IpValidator::validate($ipAddress)) return $ipAddress; } } } return static::$default; }
[ "public", "static", "function", "detect", "(", ")", "{", "foreach", "(", "static", "::", "$", "remotes", "as", "$", "remote", ")", "{", "if", "(", "$", "address", "=", "getenv", "(", "$", "remote", ")", ")", "{", "foreach", "(", "explode", "(", "','", ",", "$", "address", ")", "as", "$", "ipAddress", ")", "{", "if", "(", "IpValidator", "::", "validate", "(", "$", "ipAddress", ")", ")", "return", "$", "ipAddress", ";", "}", "}", "}", "return", "static", "::", "$", "default", ";", "}" ]
Detect the IP address. @return string
[ "Detect", "the", "IP", "address", "." ]
2b7b5590cbbbb99e9d1a3a2c85ce9e39dd39b318
https://github.com/ARCANEDEV/GeoIP/blob/2b7b5590cbbbb99e9d1a3a2c85ce9e39dd39b318/src/Support/IpDetector.php#L40-L51
230,790
cygnite/framework
src/Cygnite/Helpers/Str.php
Str.random
public static function random($type = 'alnum', $length = 16) { switch ($type) { case 'normal': $key = mt_rand(); break; case 'unique': $key = md5(uniqid(mt_rand())); break; case 'sha1': $key = sha1(uniqid(mt_rand(), true)); break; case 'alnum': $key = '0123456789'.static::$alpha; break; case 'alpha': $key = static::$alpha; break; } $random = ''; for ($i = 0; $i < $length; $i++) { $random .= substr($key, mt_rand(0, strlen($key) - 1), 1); } return $random; }
php
public static function random($type = 'alnum', $length = 16) { switch ($type) { case 'normal': $key = mt_rand(); break; case 'unique': $key = md5(uniqid(mt_rand())); break; case 'sha1': $key = sha1(uniqid(mt_rand(), true)); break; case 'alnum': $key = '0123456789'.static::$alpha; break; case 'alpha': $key = static::$alpha; break; } $random = ''; for ($i = 0; $i < $length; $i++) { $random .= substr($key, mt_rand(0, strlen($key) - 1), 1); } return $random; }
[ "public", "static", "function", "random", "(", "$", "type", "=", "'alnum'", ",", "$", "length", "=", "16", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "'normal'", ":", "$", "key", "=", "mt_rand", "(", ")", ";", "break", ";", "case", "'unique'", ":", "$", "key", "=", "md5", "(", "uniqid", "(", "mt_rand", "(", ")", ")", ")", ";", "break", ";", "case", "'sha1'", ":", "$", "key", "=", "sha1", "(", "uniqid", "(", "mt_rand", "(", ")", ",", "true", ")", ")", ";", "break", ";", "case", "'alnum'", ":", "$", "key", "=", "'0123456789'", ".", "static", "::", "$", "alpha", ";", "break", ";", "case", "'alpha'", ":", "$", "key", "=", "static", "::", "$", "alpha", ";", "break", ";", "}", "$", "random", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "length", ";", "$", "i", "++", ")", "{", "$", "random", ".=", "substr", "(", "$", "key", ",", "mt_rand", "(", "0", ",", "strlen", "(", "$", "key", ")", "-", "1", ")", ",", "1", ")", ";", "}", "return", "$", "random", ";", "}" ]
Generate random key based on type. @param string $type @param int $length @return string
[ "Generate", "random", "key", "based", "on", "type", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Helpers/Str.php#L20-L46
230,791
cygnite/framework
src/Cygnite/Common/File/Upload/Upload.php
Upload.fileSize
private function fileSize($fileSize) { if (isNumeric($fileSize)) { $decr = 1024; $step = 0; while (($fileSize / $decr) > 0.9) { $fileSize = $fileSize / $decr; $step++; } return round($fileSize, 2).' '.strtoupper($this->_prefix[$step]); } else { return 'NaN'; } }
php
private function fileSize($fileSize) { if (isNumeric($fileSize)) { $decr = 1024; $step = 0; while (($fileSize / $decr) > 0.9) { $fileSize = $fileSize / $decr; $step++; } return round($fileSize, 2).' '.strtoupper($this->_prefix[$step]); } else { return 'NaN'; } }
[ "private", "function", "fileSize", "(", "$", "fileSize", ")", "{", "if", "(", "isNumeric", "(", "$", "fileSize", ")", ")", "{", "$", "decr", "=", "1024", ";", "$", "step", "=", "0", ";", "while", "(", "(", "$", "fileSize", "/", "$", "decr", ")", ">", "0.9", ")", "{", "$", "fileSize", "=", "$", "fileSize", "/", "$", "decr", ";", "$", "step", "++", ";", "}", "return", "round", "(", "$", "fileSize", ",", "2", ")", ".", "' '", ".", "strtoupper", "(", "$", "this", "->", "_prefix", "[", "$", "step", "]", ")", ";", "}", "else", "{", "return", "'NaN'", ";", "}", "}" ]
This function to change numeric value to it binary string and to get the file size. @false integer @param $fileSize @return unknown --------------------------------------------------------
[ "This", "function", "to", "change", "numeric", "value", "to", "it", "binary", "string", "and", "to", "get", "the", "file", "size", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Common/File/Upload/Upload.php#L365-L380
230,792
tapestry-cloud/tapestry
src/Plates/Template.php
Template.renderFile
public function renderFile(File $file, array $data = []) { $this->data($data); unset($data); $this->file = $file; $tmpDirectory = $this->engine->getProject()->currentWorkingDirectory.DIRECTORY_SEPARATOR.'.tmp'; if ($layoutName = $file->getData('layout')) { $this->layoutName = (strpos('_templates', $layoutName) === false) ? '_templates'.DIRECTORY_SEPARATOR.$layoutName : $layoutName; $this->layoutData = $file->getData(); $this->engine->getProject()->get('file_layout_cache')->merge([$this->file->getUid() => [$this->layoutName]]); } try { $tmpPathName = $tmpDirectory.DIRECTORY_SEPARATOR.time().'-'.sha1($file->getUid()).'.phtml'; if (! file_exists($tmpDirectory)) { mkdir($tmpDirectory); } file_put_contents($tmpPathName, $file->getContent()); $this->data($file->getData()); $this->data([ 'permalink' => $file->getCompiledPermalink(), 'raw_permalink' => $file->getPermalink(), ]); extract($this->data); $level = ob_get_level(); ob_start(); include $tmpPathName; $content = ob_get_clean(); if (isset($this->layoutName)) { $layout = $this->engine->make($this->layoutName); $layout->setFile($this->file); $layout->sections = array_merge($this->sections, ['content' => $content]); $content = $layout->render($this->layoutData); } return $content; } catch (Throwable $e) { while (ob_get_level() > $level) { ob_end_clean(); } throw $e; } catch (Exception $e) { while (ob_get_level() > $level) { ob_end_clean(); } throw $e; } }
php
public function renderFile(File $file, array $data = []) { $this->data($data); unset($data); $this->file = $file; $tmpDirectory = $this->engine->getProject()->currentWorkingDirectory.DIRECTORY_SEPARATOR.'.tmp'; if ($layoutName = $file->getData('layout')) { $this->layoutName = (strpos('_templates', $layoutName) === false) ? '_templates'.DIRECTORY_SEPARATOR.$layoutName : $layoutName; $this->layoutData = $file->getData(); $this->engine->getProject()->get('file_layout_cache')->merge([$this->file->getUid() => [$this->layoutName]]); } try { $tmpPathName = $tmpDirectory.DIRECTORY_SEPARATOR.time().'-'.sha1($file->getUid()).'.phtml'; if (! file_exists($tmpDirectory)) { mkdir($tmpDirectory); } file_put_contents($tmpPathName, $file->getContent()); $this->data($file->getData()); $this->data([ 'permalink' => $file->getCompiledPermalink(), 'raw_permalink' => $file->getPermalink(), ]); extract($this->data); $level = ob_get_level(); ob_start(); include $tmpPathName; $content = ob_get_clean(); if (isset($this->layoutName)) { $layout = $this->engine->make($this->layoutName); $layout->setFile($this->file); $layout->sections = array_merge($this->sections, ['content' => $content]); $content = $layout->render($this->layoutData); } return $content; } catch (Throwable $e) { while (ob_get_level() > $level) { ob_end_clean(); } throw $e; } catch (Exception $e) { while (ob_get_level() > $level) { ob_end_clean(); } throw $e; } }
[ "public", "function", "renderFile", "(", "File", "$", "file", ",", "array", "$", "data", "=", "[", "]", ")", "{", "$", "this", "->", "data", "(", "$", "data", ")", ";", "unset", "(", "$", "data", ")", ";", "$", "this", "->", "file", "=", "$", "file", ";", "$", "tmpDirectory", "=", "$", "this", "->", "engine", "->", "getProject", "(", ")", "->", "currentWorkingDirectory", ".", "DIRECTORY_SEPARATOR", ".", "'.tmp'", ";", "if", "(", "$", "layoutName", "=", "$", "file", "->", "getData", "(", "'layout'", ")", ")", "{", "$", "this", "->", "layoutName", "=", "(", "strpos", "(", "'_templates'", ",", "$", "layoutName", ")", "===", "false", ")", "?", "'_templates'", ".", "DIRECTORY_SEPARATOR", ".", "$", "layoutName", ":", "$", "layoutName", ";", "$", "this", "->", "layoutData", "=", "$", "file", "->", "getData", "(", ")", ";", "$", "this", "->", "engine", "->", "getProject", "(", ")", "->", "get", "(", "'file_layout_cache'", ")", "->", "merge", "(", "[", "$", "this", "->", "file", "->", "getUid", "(", ")", "=>", "[", "$", "this", "->", "layoutName", "]", "]", ")", ";", "}", "try", "{", "$", "tmpPathName", "=", "$", "tmpDirectory", ".", "DIRECTORY_SEPARATOR", ".", "time", "(", ")", ".", "'-'", ".", "sha1", "(", "$", "file", "->", "getUid", "(", ")", ")", ".", "'.phtml'", ";", "if", "(", "!", "file_exists", "(", "$", "tmpDirectory", ")", ")", "{", "mkdir", "(", "$", "tmpDirectory", ")", ";", "}", "file_put_contents", "(", "$", "tmpPathName", ",", "$", "file", "->", "getContent", "(", ")", ")", ";", "$", "this", "->", "data", "(", "$", "file", "->", "getData", "(", ")", ")", ";", "$", "this", "->", "data", "(", "[", "'permalink'", "=>", "$", "file", "->", "getCompiledPermalink", "(", ")", ",", "'raw_permalink'", "=>", "$", "file", "->", "getPermalink", "(", ")", ",", "]", ")", ";", "extract", "(", "$", "this", "->", "data", ")", ";", "$", "level", "=", "ob_get_level", "(", ")", ";", "ob_start", "(", ")", ";", "include", "$", "tmpPathName", ";", "$", "content", "=", "ob_get_clean", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "layoutName", ")", ")", "{", "$", "layout", "=", "$", "this", "->", "engine", "->", "make", "(", "$", "this", "->", "layoutName", ")", ";", "$", "layout", "->", "setFile", "(", "$", "this", "->", "file", ")", ";", "$", "layout", "->", "sections", "=", "array_merge", "(", "$", "this", "->", "sections", ",", "[", "'content'", "=>", "$", "content", "]", ")", ";", "$", "content", "=", "$", "layout", "->", "render", "(", "$", "this", "->", "layoutData", ")", ";", "}", "return", "$", "content", ";", "}", "catch", "(", "Throwable", "$", "e", ")", "{", "while", "(", "ob_get_level", "(", ")", ">", "$", "level", ")", "{", "ob_end_clean", "(", ")", ";", "}", "throw", "$", "e", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "while", "(", "ob_get_level", "(", ")", ">", "$", "level", ")", "{", "ob_end_clean", "(", ")", ";", "}", "throw", "$", "e", ";", "}", "}" ]
Render the File. @param File $file @param array $data @return string @throws Exception @throws Throwable
[ "Render", "the", "File", "." ]
f3fc980b2484ccbe609a7f811c65b91254e8720e
https://github.com/tapestry-cloud/tapestry/blob/f3fc980b2484ccbe609a7f811c65b91254e8720e/src/Plates/Template.php#L78-L135
230,793
tapestry-cloud/tapestry
src/Plates/Template.php
Template.layout
public function layout($name, array $data = []) { $this->layoutName = $name; $this->layoutData = $data; $this->engine->getProject()->get('file_layout_cache')->merge([$this->file->getUid() => [$this->layoutName]]); }
php
public function layout($name, array $data = []) { $this->layoutName = $name; $this->layoutData = $data; $this->engine->getProject()->get('file_layout_cache')->merge([$this->file->getUid() => [$this->layoutName]]); }
[ "public", "function", "layout", "(", "$", "name", ",", "array", "$", "data", "=", "[", "]", ")", "{", "$", "this", "->", "layoutName", "=", "$", "name", ";", "$", "this", "->", "layoutData", "=", "$", "data", ";", "$", "this", "->", "engine", "->", "getProject", "(", ")", "->", "get", "(", "'file_layout_cache'", ")", "->", "merge", "(", "[", "$", "this", "->", "file", "->", "getUid", "(", ")", "=>", "[", "$", "this", "->", "layoutName", "]", "]", ")", ";", "}" ]
Set the template's layout. @param string $name @param array $data @return void
[ "Set", "the", "template", "s", "layout", "." ]
f3fc980b2484ccbe609a7f811c65b91254e8720e
https://github.com/tapestry-cloud/tapestry/blob/f3fc980b2484ccbe609a7f811c65b91254e8720e/src/Plates/Template.php#L193-L198
230,794
cygnite/framework
src/Cygnite/FormBuilder/Form.php
Form.open
public function open(string $formName, array $attributes = []) : FormInterface { self::$formName = $formName; self::$formHolder[$formName] = $formName; self::$formOpen = true; $this->form($formName, $attributes); return $this; }
php
public function open(string $formName, array $attributes = []) : FormInterface { self::$formName = $formName; self::$formHolder[$formName] = $formName; self::$formOpen = true; $this->form($formName, $attributes); return $this; }
[ "public", "function", "open", "(", "string", "$", "formName", ",", "array", "$", "attributes", "=", "[", "]", ")", ":", "FormInterface", "{", "self", "::", "$", "formName", "=", "$", "formName", ";", "self", "::", "$", "formHolder", "[", "$", "formName", "]", "=", "$", "formName", ";", "self", "::", "$", "formOpen", "=", "true", ";", "$", "this", "->", "form", "(", "$", "formName", ",", "$", "attributes", ")", ";", "return", "$", "this", ";", "}" ]
Form open tag. @param $formName @param array $attributes @return $this
[ "Form", "open", "tag", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/FormBuilder/Form.php#L124-L132
230,795
cygnite/framework
src/Cygnite/FormBuilder/Form.php
Form.createForm
public function createForm() : FormInterface { foreach ($this->value as $key => $val) { if (in_array($val['type'], $this->validMethods)) { $method = $val['type']; unset($val['type']); (!method_exists($this, $method)) ?: $this->{$method}($key, $val); } else { $this->input($key, $val); } if (isset($val['type']) && in_array($val['type'], $this->validArray)) { $this->setValidationError($key, $val); } elseif (!isset($val['type']) && in_array($method, $this->validArray)) { $this->setValidationError($key, $val); } } return $this; }
php
public function createForm() : FormInterface { foreach ($this->value as $key => $val) { if (in_array($val['type'], $this->validMethods)) { $method = $val['type']; unset($val['type']); (!method_exists($this, $method)) ?: $this->{$method}($key, $val); } else { $this->input($key, $val); } if (isset($val['type']) && in_array($val['type'], $this->validArray)) { $this->setValidationError($key, $val); } elseif (!isset($val['type']) && in_array($method, $this->validArray)) { $this->setValidationError($key, $val); } } return $this; }
[ "public", "function", "createForm", "(", ")", ":", "FormInterface", "{", "foreach", "(", "$", "this", "->", "value", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "in_array", "(", "$", "val", "[", "'type'", "]", ",", "$", "this", "->", "validMethods", ")", ")", "{", "$", "method", "=", "$", "val", "[", "'type'", "]", ";", "unset", "(", "$", "val", "[", "'type'", "]", ")", ";", "(", "!", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "?", ":", "$", "this", "->", "{", "$", "method", "}", "(", "$", "key", ",", "$", "val", ")", ";", "}", "else", "{", "$", "this", "->", "input", "(", "$", "key", ",", "$", "val", ")", ";", "}", "if", "(", "isset", "(", "$", "val", "[", "'type'", "]", ")", "&&", "in_array", "(", "$", "val", "[", "'type'", "]", ",", "$", "this", "->", "validArray", ")", ")", "{", "$", "this", "->", "setValidationError", "(", "$", "key", ",", "$", "val", ")", ";", "}", "elseif", "(", "!", "isset", "(", "$", "val", "[", "'type'", "]", ")", "&&", "in_array", "(", "$", "method", ",", "$", "this", "->", "validArray", ")", ")", "{", "$", "this", "->", "setValidationError", "(", "$", "key", ",", "$", "val", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Create form elements. @return $this
[ "Create", "form", "elements", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/FormBuilder/Form.php#L174-L193
230,796
cygnite/framework
src/Cygnite/FormBuilder/Form.php
Form.setValidationError
protected function setValidationError($key, $val) { if (!in_array('submit', $val)) { // Is $validator is instance of ValidatorInterface and given key has error associated // then add a span tag below the input element and display error. if ($this->validator instanceof ValidatorInterface && $this->validator->hasError($key)) { $this->elements[self::$formHolder[self::$formName]][$key.'.error'] = '<span class="'.$this->errorClass.'">'.$this->validator->getErrors($key).'</span>'.PHP_EOL; } } }
php
protected function setValidationError($key, $val) { if (!in_array('submit', $val)) { // Is $validator is instance of ValidatorInterface and given key has error associated // then add a span tag below the input element and display error. if ($this->validator instanceof ValidatorInterface && $this->validator->hasError($key)) { $this->elements[self::$formHolder[self::$formName]][$key.'.error'] = '<span class="'.$this->errorClass.'">'.$this->validator->getErrors($key).'</span>'.PHP_EOL; } } }
[ "protected", "function", "setValidationError", "(", "$", "key", ",", "$", "val", ")", "{", "if", "(", "!", "in_array", "(", "'submit'", ",", "$", "val", ")", ")", "{", "// Is $validator is instance of ValidatorInterface and given key has error associated", "// then add a span tag below the input element and display error.", "if", "(", "$", "this", "->", "validator", "instanceof", "ValidatorInterface", "&&", "$", "this", "->", "validator", "->", "hasError", "(", "$", "key", ")", ")", "{", "$", "this", "->", "elements", "[", "self", "::", "$", "formHolder", "[", "self", "::", "$", "formName", "]", "]", "[", "$", "key", ".", "'.error'", "]", "=", "'<span class=\"'", ".", "$", "this", "->", "errorClass", ".", "'\">'", ".", "$", "this", "->", "validator", "->", "getErrors", "(", "$", "key", ")", ".", "'</span>'", ".", "PHP_EOL", ";", "}", "}", "}" ]
Create validation error element in the form itself. @param $key @param $val
[ "Create", "validation", "error", "element", "in", "the", "form", "itself", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/FormBuilder/Form.php#L201-L211
230,797
cygnite/framework
src/Cygnite/FormBuilder/Form.php
Form.form
protected function form($key, $val) { $type = null; $type = strtolower(__FUNCTION__); $this->attributes[self::$formHolder[self::$formName]][$key] = "<$type name='".self::$formName."' ".$this->attributes($val).'>'.PHP_EOL; }
php
protected function form($key, $val) { $type = null; $type = strtolower(__FUNCTION__); $this->attributes[self::$formHolder[self::$formName]][$key] = "<$type name='".self::$formName."' ".$this->attributes($val).'>'.PHP_EOL; }
[ "protected", "function", "form", "(", "$", "key", ",", "$", "val", ")", "{", "$", "type", "=", "null", ";", "$", "type", "=", "strtolower", "(", "__FUNCTION__", ")", ";", "$", "this", "->", "attributes", "[", "self", "::", "$", "formHolder", "[", "self", "::", "$", "formName", "]", "]", "[", "$", "key", "]", "=", "\"<$type name='\"", ".", "self", "::", "$", "formName", ".", "\"' \"", ".", "$", "this", "->", "attributes", "(", "$", "val", ")", ".", "'>'", ".", "PHP_EOL", ";", "}" ]
Create form open tag. @param $key @param $val
[ "Create", "form", "open", "tag", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/FormBuilder/Form.php#L239-L246
230,798
cygnite/framework
src/Cygnite/FormBuilder/Form.php
Form.getForm
public function getForm() { $elementString = ''; if (isset($this->attributes[self::$formHolder[self::$formName]])) { $elementString .= $this->attributes[self::$formHolder[self::$formName]][self::$formName]; } $elementString .= $this->getHtmlElements(); $close = null; $close = self::$formHolder[self::$formName].'_close'; if (isset($this->attributes[$close])) { $elementString .= $this->attributes[$close]; } return $this->element[self::$formHolder[self::$formName]] = $elementString; }
php
public function getForm() { $elementString = ''; if (isset($this->attributes[self::$formHolder[self::$formName]])) { $elementString .= $this->attributes[self::$formHolder[self::$formName]][self::$formName]; } $elementString .= $this->getHtmlElements(); $close = null; $close = self::$formHolder[self::$formName].'_close'; if (isset($this->attributes[$close])) { $elementString .= $this->attributes[$close]; } return $this->element[self::$formHolder[self::$formName]] = $elementString; }
[ "public", "function", "getForm", "(", ")", "{", "$", "elementString", "=", "''", ";", "if", "(", "isset", "(", "$", "this", "->", "attributes", "[", "self", "::", "$", "formHolder", "[", "self", "::", "$", "formName", "]", "]", ")", ")", "{", "$", "elementString", ".=", "$", "this", "->", "attributes", "[", "self", "::", "$", "formHolder", "[", "self", "::", "$", "formName", "]", "]", "[", "self", "::", "$", "formName", "]", ";", "}", "$", "elementString", ".=", "$", "this", "->", "getHtmlElements", "(", ")", ";", "$", "close", "=", "null", ";", "$", "close", "=", "self", "::", "$", "formHolder", "[", "self", "::", "$", "formName", "]", ".", "'_close'", ";", "if", "(", "isset", "(", "$", "this", "->", "attributes", "[", "$", "close", "]", ")", ")", "{", "$", "elementString", ".=", "$", "this", "->", "attributes", "[", "$", "close", "]", ";", "}", "return", "$", "this", "->", "element", "[", "self", "::", "$", "formHolder", "[", "self", "::", "$", "formName", "]", "]", "=", "$", "elementString", ";", "}" ]
Returns form elements. @return mixed
[ "Returns", "form", "elements", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/FormBuilder/Form.php#L275-L293
230,799
cygnite/framework
src/Cygnite/FormBuilder/Form.php
Form.getHtmlElements
public function getHtmlElements() : string { $elementString = ''; /* | Build a form and store as string */ foreach ($this->elements[self::$formHolder[self::$formName]] as $key => $val) { $elementString .= $val; } return $elementString; }
php
public function getHtmlElements() : string { $elementString = ''; /* | Build a form and store as string */ foreach ($this->elements[self::$formHolder[self::$formName]] as $key => $val) { $elementString .= $val; } return $elementString; }
[ "public", "function", "getHtmlElements", "(", ")", ":", "string", "{", "$", "elementString", "=", "''", ";", "/*\n | Build a form and store as string\n */", "foreach", "(", "$", "this", "->", "elements", "[", "self", "::", "$", "formHolder", "[", "self", "::", "$", "formName", "]", "]", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "elementString", ".=", "$", "val", ";", "}", "return", "$", "elementString", ";", "}" ]
If you wish to get only html elements.
[ "If", "you", "wish", "to", "get", "only", "html", "elements", "." ]
58d0cc1c946415eb0867d76218bd35166e999093
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/FormBuilder/Form.php#L298-L309