repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
tequila/mongodb-odm
src/Proxy/Traits/RootProxyTrait.php
RootProxyTrait.setOnInsert
public function setOnInsert(string $field, $value) { $this->update(); $this->mongoDbUpdate['$setOnInsert'][$field] = $value; return $this; }
php
public function setOnInsert(string $field, $value) { $this->update(); $this->mongoDbUpdate['$setOnInsert'][$field] = $value; return $this; }
[ "public", "function", "setOnInsert", "(", "string", "$", "field", ",", "$", "value", ")", "{", "$", "this", "->", "update", "(", ")", ";", "$", "this", "->", "mongoDbUpdate", "[", "'$setOnInsert'", "]", "[", "$", "field", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
@param string $field @param mixed $value @return $this
[ "@param", "string", "$field", "@param", "mixed", "$value" ]
train
https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/Proxy/Traits/RootProxyTrait.php#L270-L276
tequila/mongodb-odm
src/Proxy/Traits/RootProxyTrait.php
RootProxyTrait.set
public function set(string $field, $value) { $this->update(); $this->mongoDbUpdate['$set'][$field] = $value; return $this; }
php
public function set(string $field, $value) { $this->update(); $this->mongoDbUpdate['$set'][$field] = $value; return $this; }
[ "public", "function", "set", "(", "string", "$", "field", ",", "$", "value", ")", "{", "$", "this", "->", "update", "(", ")", ";", "$", "this", "->", "mongoDbUpdate", "[", "'$set'", "]", "[", "$", "field", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
@param string $field @param mixed $value @return $this
[ "@param", "string", "$field", "@param", "mixed", "$value" ]
train
https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/Proxy/Traits/RootProxyTrait.php#L284-L290
php-lug/lug
src/Component/Grid/Filter/Filterer.php
Filterer.filter
public function filter(DataSourceBuilderInterface $builder, GridInterface $grid, array $filters = []) { foreach ($filters as $name => $filter) { if (!$grid->hasFilter($name)) { continue; } $gridFilter = $grid->getFilter($name); $types = $this->resolveTypes($gridFilter->getType()); $resolver = new OptionsResolver(); foreach ($types as $type) { $type->configureOptions($resolver); } reset($types)->filter($filter, $resolver->resolve(array_merge( ['filter' => $gridFilter, 'grid' => $grid, 'builder' => $builder], $gridFilter->getOptions() ))); } }
php
public function filter(DataSourceBuilderInterface $builder, GridInterface $grid, array $filters = []) { foreach ($filters as $name => $filter) { if (!$grid->hasFilter($name)) { continue; } $gridFilter = $grid->getFilter($name); $types = $this->resolveTypes($gridFilter->getType()); $resolver = new OptionsResolver(); foreach ($types as $type) { $type->configureOptions($resolver); } reset($types)->filter($filter, $resolver->resolve(array_merge( ['filter' => $gridFilter, 'grid' => $grid, 'builder' => $builder], $gridFilter->getOptions() ))); } }
[ "public", "function", "filter", "(", "DataSourceBuilderInterface", "$", "builder", ",", "GridInterface", "$", "grid", ",", "array", "$", "filters", "=", "[", "]", ")", "{", "foreach", "(", "$", "filters", "as", "$", "name", "=>", "$", "filter", ")", "{", "if", "(", "!", "$", "grid", "->", "hasFilter", "(", "$", "name", ")", ")", "{", "continue", ";", "}", "$", "gridFilter", "=", "$", "grid", "->", "getFilter", "(", "$", "name", ")", ";", "$", "types", "=", "$", "this", "->", "resolveTypes", "(", "$", "gridFilter", "->", "getType", "(", ")", ")", ";", "$", "resolver", "=", "new", "OptionsResolver", "(", ")", ";", "foreach", "(", "$", "types", "as", "$", "type", ")", "{", "$", "type", "->", "configureOptions", "(", "$", "resolver", ")", ";", "}", "reset", "(", "$", "types", ")", "->", "filter", "(", "$", "filter", ",", "$", "resolver", "->", "resolve", "(", "array_merge", "(", "[", "'filter'", "=>", "$", "gridFilter", ",", "'grid'", "=>", "$", "grid", ",", "'builder'", "=>", "$", "builder", "]", ",", "$", "gridFilter", "->", "getOptions", "(", ")", ")", ")", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Filter/Filterer.php#L41-L61
php-lug/lug
src/Component/Grid/Filter/Filterer.php
Filterer.resolveTypes
private function resolveTypes($type) { $filterTypes = []; do { $filterTypes[] = $filterType = $this->filterRegistry[$type]; } while (($type = $filterType->getParent()) !== null); return $filterTypes; }
php
private function resolveTypes($type) { $filterTypes = []; do { $filterTypes[] = $filterType = $this->filterRegistry[$type]; } while (($type = $filterType->getParent()) !== null); return $filterTypes; }
[ "private", "function", "resolveTypes", "(", "$", "type", ")", "{", "$", "filterTypes", "=", "[", "]", ";", "do", "{", "$", "filterTypes", "[", "]", "=", "$", "filterType", "=", "$", "this", "->", "filterRegistry", "[", "$", "type", "]", ";", "}", "while", "(", "(", "$", "type", "=", "$", "filterType", "->", "getParent", "(", ")", ")", "!==", "null", ")", ";", "return", "$", "filterTypes", ";", "}" ]
@param string $type @return TypeInterface[]
[ "@param", "string", "$type" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Filter/Filterer.php#L68-L77
simbiosis-group/yii2-helper
actions/EnvelopeAction.php
EnvelopeAction.run
public function run() { $mpdf = $this->mpdf; foreach ($this->data as $record) { $mpdf->AddPage(); $mpdf->WriteHTML($this->controller->renderPartial( $this->envelopeViewPath, [ 'data' => $record, 'adjustment' => $this->adjustment, 'adjustmentPadding' => $this->adjustmentPadding, 'adjustmentFont' => $this->adjustmentFont, 'adjustmentLabelFont' => $this->adjustmentLabelFont, ] ),2); } $mpdf->Output(); }
php
public function run() { $mpdf = $this->mpdf; foreach ($this->data as $record) { $mpdf->AddPage(); $mpdf->WriteHTML($this->controller->renderPartial( $this->envelopeViewPath, [ 'data' => $record, 'adjustment' => $this->adjustment, 'adjustmentPadding' => $this->adjustmentPadding, 'adjustmentFont' => $this->adjustmentFont, 'adjustmentLabelFont' => $this->adjustmentLabelFont, ] ),2); } $mpdf->Output(); }
[ "public", "function", "run", "(", ")", "{", "$", "mpdf", "=", "$", "this", "->", "mpdf", ";", "foreach", "(", "$", "this", "->", "data", "as", "$", "record", ")", "{", "$", "mpdf", "->", "AddPage", "(", ")", ";", "$", "mpdf", "->", "WriteHTML", "(", "$", "this", "->", "controller", "->", "renderPartial", "(", "$", "this", "->", "envelopeViewPath", ",", "[", "'data'", "=>", "$", "record", ",", "'adjustment'", "=>", "$", "this", "->", "adjustment", ",", "'adjustmentPadding'", "=>", "$", "this", "->", "adjustmentPadding", ",", "'adjustmentFont'", "=>", "$", "this", "->", "adjustmentFont", ",", "'adjustmentLabelFont'", "=>", "$", "this", "->", "adjustmentLabelFont", ",", "]", ")", ",", "2", ")", ";", "}", "$", "mpdf", "->", "Output", "(", ")", ";", "}" ]
Runs the action @return string result content
[ "Runs", "the", "action" ]
train
https://github.com/simbiosis-group/yii2-helper/blob/c85c4204dd06b16e54210e75fe6deb51869d1dd9/actions/EnvelopeAction.php#L81-L100
php-lug/lug
src/Bundle/StorageBundle/DependencyInjection/LugStorageExtension.php
LugStorageExtension.loadInternal
protected function loadInternal(array $config, ContainerBuilder $container) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $this->loadCookie($config['cookie'], $loader); $this->loadDoctrine($config['doctrine'], $loader, $container); $this->loadSession($config['session'], $loader); }
php
protected function loadInternal(array $config, ContainerBuilder $container) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $this->loadCookie($config['cookie'], $loader); $this->loadDoctrine($config['doctrine'], $loader, $container); $this->loadSession($config['session'], $loader); }
[ "protected", "function", "loadInternal", "(", "array", "$", "config", ",", "ContainerBuilder", "$", "container", ")", "{", "$", "loader", "=", "new", "XmlFileLoader", "(", "$", "container", ",", "new", "FileLocator", "(", "__DIR__", ".", "'/../Resources/config'", ")", ")", ";", "$", "this", "->", "loadCookie", "(", "$", "config", "[", "'cookie'", "]", ",", "$", "loader", ")", ";", "$", "this", "->", "loadDoctrine", "(", "$", "config", "[", "'doctrine'", "]", ",", "$", "loader", ",", "$", "container", ")", ";", "$", "this", "->", "loadSession", "(", "$", "config", "[", "'session'", "]", ",", "$", "loader", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/StorageBundle/DependencyInjection/LugStorageExtension.php#L29-L36
zhouyl/mellivora
Mellivora/Database/Console/Migrations/MigrateMakeCommand.php
MigrateMakeCommand.fire
public function fire() { // It's possible for the developer to specify the tables to modify in this // schema operation. The developer may also specify if this table needs // to be freshly created so we can create the appropriate migrations. $name = trim($this->input->getArgument('name')); $table = $this->input->getOption('table'); $create = $this->input->getOption('create') ?: false; // If no table was given as an option but a create option is given then we // will use the "create" option as the table name. This allows the devs // to pass a table name into this option as a short-cut for creating. if (!$table && is_string($create)) { $table = $create; $create = true; } // Now we are ready to write the migration out to disk. Once we've written // the migration out, we will dump-autoload for the entire framework to // make sure that the migrations are registered by the class loaders. $this->writeMigration($name, $table, $create); }
php
public function fire() { // It's possible for the developer to specify the tables to modify in this // schema operation. The developer may also specify if this table needs // to be freshly created so we can create the appropriate migrations. $name = trim($this->input->getArgument('name')); $table = $this->input->getOption('table'); $create = $this->input->getOption('create') ?: false; // If no table was given as an option but a create option is given then we // will use the "create" option as the table name. This allows the devs // to pass a table name into this option as a short-cut for creating. if (!$table && is_string($create)) { $table = $create; $create = true; } // Now we are ready to write the migration out to disk. Once we've written // the migration out, we will dump-autoload for the entire framework to // make sure that the migrations are registered by the class loaders. $this->writeMigration($name, $table, $create); }
[ "public", "function", "fire", "(", ")", "{", "// It's possible for the developer to specify the tables to modify in this", "// schema operation. The developer may also specify if this table needs", "// to be freshly created so we can create the appropriate migrations.", "$", "name", "=", "trim", "(", "$", "this", "->", "input", "->", "getArgument", "(", "'name'", ")", ")", ";", "$", "table", "=", "$", "this", "->", "input", "->", "getOption", "(", "'table'", ")", ";", "$", "create", "=", "$", "this", "->", "input", "->", "getOption", "(", "'create'", ")", "?", ":", "false", ";", "// If no table was given as an option but a create option is given then we", "// will use the \"create\" option as the table name. This allows the devs", "// to pass a table name into this option as a short-cut for creating.", "if", "(", "!", "$", "table", "&&", "is_string", "(", "$", "create", ")", ")", "{", "$", "table", "=", "$", "create", ";", "$", "create", "=", "true", ";", "}", "// Now we are ready to write the migration out to disk. Once we've written", "// the migration out, we will dump-autoload for the entire framework to", "// make sure that the migrations are registered by the class loaders.", "$", "this", "->", "writeMigration", "(", "$", "name", ",", "$", "table", ",", "$", "create", ")", ";", "}" ]
Execute the console command. @return void
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Console/Migrations/MigrateMakeCommand.php#L29-L53
zhouyl/mellivora
Mellivora/Database/Console/Migrations/MigrateMakeCommand.php
MigrateMakeCommand.getMigrationPath
protected function getMigrationPath() { if (!is_null($targetPath = $this->input->getOption('path'))) { return root_path($targetPath); } return parent::getMigrationPath(); }
php
protected function getMigrationPath() { if (!is_null($targetPath = $this->input->getOption('path'))) { return root_path($targetPath); } return parent::getMigrationPath(); }
[ "protected", "function", "getMigrationPath", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "targetPath", "=", "$", "this", "->", "input", "->", "getOption", "(", "'path'", ")", ")", ")", "{", "return", "root_path", "(", "$", "targetPath", ")", ";", "}", "return", "parent", "::", "getMigrationPath", "(", ")", ";", "}" ]
Get migration path (either specified by '--path' option or default location). @return string
[ "Get", "migration", "path", "(", "either", "specified", "by", "--", "path", "option", "or", "default", "location", ")", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Console/Migrations/MigrateMakeCommand.php#L81-L88
mvccore/ext-router-module
src/MvcCore/Ext/Routers/Modules/Route/Matching.php
Matching.matchesGetSubject
protected function matchesGetSubject (\MvcCore\IRequest & $request) { $subject = $this->matchesGetSubjectHostAndBase($request) ; if (!$this->flags[0]) { $selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__; throw new \InvalidArgumentException( "[".$selfClass."] Domain route pattern or reverse must be defined as " ."absolute with `//`, `http://` or `https://` at the beginning (`//www.domain.com`)." ); } return $subject; }
php
protected function matchesGetSubject (\MvcCore\IRequest & $request) { $subject = $this->matchesGetSubjectHostAndBase($request) ; if (!$this->flags[0]) { $selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__; throw new \InvalidArgumentException( "[".$selfClass."] Domain route pattern or reverse must be defined as " ."absolute with `//`, `http://` or `https://` at the beginning (`//www.domain.com`)." ); } return $subject; }
[ "protected", "function", "matchesGetSubject", "(", "\\", "MvcCore", "\\", "IRequest", "&", "$", "request", ")", "{", "$", "subject", "=", "$", "this", "->", "matchesGetSubjectHostAndBase", "(", "$", "request", ")", ";", "if", "(", "!", "$", "this", "->", "flags", "[", "0", "]", ")", "{", "$", "selfClass", "=", "version_compare", "(", "PHP_VERSION", ",", "'5.5'", ",", "'>'", ")", "?", "self", "::", "class", ":", "__CLASS__", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "\"[\"", ".", "$", "selfClass", ".", "\"] Domain route pattern or reverse must be defined as \"", ".", "\"absolute with `//`, `http://` or `https://` at the beginning (`//www.domain.com`).\"", ")", ";", "}", "return", "$", "subject", ";", "}" ]
Return subject value used for `preg_match_all()` route match processing. Complete subject by route flags. Route `pattern` (or `reverse`) must contain domain part or/and base path. Prepare those values from request object. @param \MvcCore\IRequest $request @throws \InvalidArgumentException Domain route pattern or reverse must be defined as absolute. @return string
[ "Return", "subject", "value", "used", "for", "preg_match_all", "()", "route", "match", "processing", ".", "Complete", "subject", "by", "route", "flags", ".", "Route", "pattern", "(", "or", "reverse", ")", "must", "contain", "domain", "part", "or", "/", "and", "base", "path", ".", "Prepare", "those", "values", "from", "request", "object", "." ]
train
https://github.com/mvccore/ext-router-module/blob/7695784a451db86cca6a43c98d076803cd0a50a7/src/MvcCore/Ext/Routers/Modules/Route/Matching.php#L28-L38
mvccore/ext-router-module
src/MvcCore/Ext/Routers/Modules/Route/Matching.php
Matching.&
protected function & matchesParseRewriteParams (& $matchedValues, & $defaults) { $matchedParams = []; array_shift($matchedValues); // first item is always matched whole `$request->GetPath()` string. foreach ($matchedValues as $key => $matchedValueArr) { if (is_numeric($key)) continue; $matchedValue = (string) current($matchedValueArr); if (!isset($defaults[$key])) $defaults[$key] = NULL; $matchedEmptyString = mb_strlen($matchedValue) === 0; if ($matchedEmptyString) $matchedValue = $defaults[$key]; // continue if there is already valid ctrl and action from route ctrl or action configuration if (isset($matchedParams[$key]) && $matchedEmptyString) continue; $matchedParams[$key] = $matchedValue; } return $matchedParams; }
php
protected function & matchesParseRewriteParams (& $matchedValues, & $defaults) { $matchedParams = []; array_shift($matchedValues); // first item is always matched whole `$request->GetPath()` string. foreach ($matchedValues as $key => $matchedValueArr) { if (is_numeric($key)) continue; $matchedValue = (string) current($matchedValueArr); if (!isset($defaults[$key])) $defaults[$key] = NULL; $matchedEmptyString = mb_strlen($matchedValue) === 0; if ($matchedEmptyString) $matchedValue = $defaults[$key]; // continue if there is already valid ctrl and action from route ctrl or action configuration if (isset($matchedParams[$key]) && $matchedEmptyString) continue; $matchedParams[$key] = $matchedValue; } return $matchedParams; }
[ "protected", "function", "&", "matchesParseRewriteParams", "(", "&", "$", "matchedValues", ",", "&", "$", "defaults", ")", "{", "$", "matchedParams", "=", "[", "]", ";", "array_shift", "(", "$", "matchedValues", ")", ";", "// first item is always matched whole `$request->GetPath()` string.", "foreach", "(", "$", "matchedValues", "as", "$", "key", "=>", "$", "matchedValueArr", ")", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "continue", ";", "$", "matchedValue", "=", "(", "string", ")", "current", "(", "$", "matchedValueArr", ")", ";", "if", "(", "!", "isset", "(", "$", "defaults", "[", "$", "key", "]", ")", ")", "$", "defaults", "[", "$", "key", "]", "=", "NULL", ";", "$", "matchedEmptyString", "=", "mb_strlen", "(", "$", "matchedValue", ")", "===", "0", ";", "if", "(", "$", "matchedEmptyString", ")", "$", "matchedValue", "=", "$", "defaults", "[", "$", "key", "]", ";", "// continue if there is already valid ctrl and action from route ctrl or action configuration", "if", "(", "isset", "(", "$", "matchedParams", "[", "$", "key", "]", ")", "&&", "$", "matchedEmptyString", ")", "continue", ";", "$", "matchedParams", "[", "$", "key", "]", "=", "$", "matchedValue", ";", "}", "return", "$", "matchedParams", ";", "}" ]
Parse rewrite params from `preg_match_all()` `$matches` result array into array, keyed by param name with parsed value. @param array $matchedValues @param array $defaults @return array
[ "Parse", "rewrite", "params", "from", "preg_match_all", "()", "$matches", "result", "array", "into", "array", "keyed", "by", "param", "name", "with", "parsed", "value", "." ]
train
https://github.com/mvccore/ext-router-module/blob/7695784a451db86cca6a43c98d076803cd0a50a7/src/MvcCore/Ext/Routers/Modules/Route/Matching.php#L47-L63
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/transport_connection.php
ezcMailTransportConnection.sendData
public function sendData( $data ) { if ( is_resource( $this->connection ) ) { if ( fwrite( $this->connection, $data . self::CRLF, strlen( $data ) + strlen( self::CRLF ) ) === false ) { throw new ezcMailTransportException( 'Could not write to the stream. It was probably terminated by the host.' ); } } }
php
public function sendData( $data ) { if ( is_resource( $this->connection ) ) { if ( fwrite( $this->connection, $data . self::CRLF, strlen( $data ) + strlen( self::CRLF ) ) === false ) { throw new ezcMailTransportException( 'Could not write to the stream. It was probably terminated by the host.' ); } } }
[ "public", "function", "sendData", "(", "$", "data", ")", "{", "if", "(", "is_resource", "(", "$", "this", "->", "connection", ")", ")", "{", "if", "(", "fwrite", "(", "$", "this", "->", "connection", ",", "$", "data", ".", "self", "::", "CRLF", ",", "strlen", "(", "$", "data", ")", "+", "strlen", "(", "self", "::", "CRLF", ")", ")", "===", "false", ")", "{", "throw", "new", "ezcMailTransportException", "(", "'Could not write to the stream. It was probably terminated by the host.'", ")", ";", "}", "}", "}" ]
Send $data to the server through the connection. This method appends one line-break at the end of $data. @throws ezcMailTransportException if there is no valid connection. @param string $data
[ "Send", "$data", "to", "the", "server", "through", "the", "connection", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/transport_connection.php#L177-L187
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/transport_connection.php
ezcMailTransportConnection.getLine
public function getLine( $trim = false ) { $data = ''; $line = ''; if ( is_resource( $this->connection ) ) { // in case there is a problem with the connection fgets() returns false while ( strpos( $data, self::CRLF ) === false ) { $line = fgets( $this->connection, 512 ); /* If the mail server aborts the connection, fgets() will * return false. We need to throw an exception here to prevent * the calling code from looping indefinitely. */ if ( $line === false ) { $this->connection = null; throw new ezcMailTransportException( 'Could not read from the stream. It was probably terminated by the host.' ); } $data .= $line; } if ( $trim == false ) { return $data; } else { return rtrim( $data, "\r\n" ); } } throw new ezcMailTransportException( 'Could not read from the stream. It was probably terminated by the host.' ); }
php
public function getLine( $trim = false ) { $data = ''; $line = ''; if ( is_resource( $this->connection ) ) { // in case there is a problem with the connection fgets() returns false while ( strpos( $data, self::CRLF ) === false ) { $line = fgets( $this->connection, 512 ); /* If the mail server aborts the connection, fgets() will * return false. We need to throw an exception here to prevent * the calling code from looping indefinitely. */ if ( $line === false ) { $this->connection = null; throw new ezcMailTransportException( 'Could not read from the stream. It was probably terminated by the host.' ); } $data .= $line; } if ( $trim == false ) { return $data; } else { return rtrim( $data, "\r\n" ); } } throw new ezcMailTransportException( 'Could not read from the stream. It was probably terminated by the host.' ); }
[ "public", "function", "getLine", "(", "$", "trim", "=", "false", ")", "{", "$", "data", "=", "''", ";", "$", "line", "=", "''", ";", "if", "(", "is_resource", "(", "$", "this", "->", "connection", ")", ")", "{", "// in case there is a problem with the connection fgets() returns false", "while", "(", "strpos", "(", "$", "data", ",", "self", "::", "CRLF", ")", "===", "false", ")", "{", "$", "line", "=", "fgets", "(", "$", "this", "->", "connection", ",", "512", ")", ";", "/* If the mail server aborts the connection, fgets() will\n * return false. We need to throw an exception here to prevent\n * the calling code from looping indefinitely. */", "if", "(", "$", "line", "===", "false", ")", "{", "$", "this", "->", "connection", "=", "null", ";", "throw", "new", "ezcMailTransportException", "(", "'Could not read from the stream. It was probably terminated by the host.'", ")", ";", "}", "$", "data", ".=", "$", "line", ";", "}", "if", "(", "$", "trim", "==", "false", ")", "{", "return", "$", "data", ";", "}", "else", "{", "return", "rtrim", "(", "$", "data", ",", "\"\\r\\n\"", ")", ";", "}", "}", "throw", "new", "ezcMailTransportException", "(", "'Could not read from the stream. It was probably terminated by the host.'", ")", ";", "}" ]
Returns one line of data from the stream. The returned line will have linebreaks removed if the $trim option is set. @throws ezcMailTransportConnection if there is no valid connection @param bool $trim @return string
[ "Returns", "one", "line", "of", "data", "from", "the", "stream", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/transport_connection.php#L199-L233
Erdiko/core
src/cache/File.php
File.put
public function put($key, $data) { $filename = $this->getKeyCode($key); $data = json_encode($data); $this->write($data, $filename); }
php
public function put($key, $data) { $filename = $this->getKeyCode($key); $data = json_encode($data); $this->write($data, $filename); }
[ "public", "function", "put", "(", "$", "key", ",", "$", "data", ")", "{", "$", "filename", "=", "$", "this", "->", "getKeyCode", "(", "$", "key", ")", ";", "$", "data", "=", "json_encode", "(", "$", "data", ")", ";", "$", "this", "->", "write", "(", "$", "data", ",", "$", "filename", ")", ";", "}" ]
Put Key @param mixed $key @param mixed $data
[ "Put", "Key" ]
train
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/cache/File.php#L43-L48
Erdiko/core
src/cache/File.php
File.get
public function get($key) { $filename = $this->getKeyCode($key); if ($this->fileExists($filename)) { $value = $this->read($filename); } else { return null; } return json_decode($value, true); }
php
public function get($key) { $filename = $this->getKeyCode($key); if ($this->fileExists($filename)) { $value = $this->read($filename); } else { return null; } return json_decode($value, true); }
[ "public", "function", "get", "(", "$", "key", ")", "{", "$", "filename", "=", "$", "this", "->", "getKeyCode", "(", "$", "key", ")", ";", "if", "(", "$", "this", "->", "fileExists", "(", "$", "filename", ")", ")", "{", "$", "value", "=", "$", "this", "->", "read", "(", "$", "filename", ")", ";", "}", "else", "{", "return", "null", ";", "}", "return", "json_decode", "(", "$", "value", ",", "true", ")", ";", "}" ]
Get Key @param string @key @return mixed
[ "Get", "Key" ]
train
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/cache/File.php#L56-L67
Erdiko/core
src/cache/File.php
File.delete
public function delete($key, $path = null) { $filename = $this->getKeyCode($key); parent::delete($filename, $path); }
php
public function delete($key, $path = null) { $filename = $this->getKeyCode($key); parent::delete($filename, $path); }
[ "public", "function", "delete", "(", "$", "key", ",", "$", "path", "=", "null", ")", "{", "$", "filename", "=", "$", "this", "->", "getKeyCode", "(", "$", "key", ")", ";", "parent", "::", "delete", "(", "$", "filename", ",", "$", "path", ")", ";", "}" ]
Delete a key @param string @key @note path is only for compatibility, do not use
[ "Delete", "a", "key" ]
train
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/cache/File.php#L75-L79
Erdiko/core
src/cache/File.php
File.clear
public function clear() { $files = glob(ERDIKO_VAR."/cache/*"); foreach ($files as $file) { if (is_file($file)) { parent::delete(basename($file)); } } }
php
public function clear() { $files = glob(ERDIKO_VAR."/cache/*"); foreach ($files as $file) { if (is_file($file)) { parent::delete(basename($file)); } } }
[ "public", "function", "clear", "(", ")", "{", "$", "files", "=", "glob", "(", "ERDIKO_VAR", ".", "\"/cache/*\"", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "if", "(", "is_file", "(", "$", "file", ")", ")", "{", "parent", "::", "delete", "(", "basename", "(", "$", "file", ")", ")", ";", "}", "}", "}" ]
Delete all keys
[ "Delete", "all", "keys" ]
train
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/cache/File.php#L84-L92
php-lug/lug
src/Bundle/TranslationBundle/Form/Type/TranslatableType.php
TranslatableType.buildForm
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('translations', TranslationsFormsType::class, [ 'form_type' => $options['resource']->getRelation('translation')->getForm(), 'empty_data' => function () { return new ArrayCollection(); }, ]); }
php
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('translations', TranslationsFormsType::class, [ 'form_type' => $options['resource']->getRelation('translation')->getForm(), 'empty_data' => function () { return new ArrayCollection(); }, ]); }
[ "public", "function", "buildForm", "(", "FormBuilderInterface", "$", "builder", ",", "array", "$", "options", ")", "{", "$", "builder", "->", "add", "(", "'translations'", ",", "TranslationsFormsType", "::", "class", ",", "[", "'form_type'", "=>", "$", "options", "[", "'resource'", "]", "->", "getRelation", "(", "'translation'", ")", "->", "getForm", "(", ")", ",", "'empty_data'", "=>", "function", "(", ")", "{", "return", "new", "ArrayCollection", "(", ")", ";", "}", ",", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/TranslationBundle/Form/Type/TranslatableType.php#L28-L36
Visithor/visithor
src/Visithor/Client/GuzzleClient.php
GuzzleClient.buildClient
public function buildClient() { //Handle redirect configuration for guzzle 6 if (class_exists('\GuzzleHttp\Psr7\Request')) { $options = ['allow_redirects' => false]; } else { $options = [ 'defaults' => [ 'allow_redirects' => false ] ]; } $this->client = new Client( $options ); }
php
public function buildClient() { //Handle redirect configuration for guzzle 6 if (class_exists('\GuzzleHttp\Psr7\Request')) { $options = ['allow_redirects' => false]; } else { $options = [ 'defaults' => [ 'allow_redirects' => false ] ]; } $this->client = new Client( $options ); }
[ "public", "function", "buildClient", "(", ")", "{", "//Handle redirect configuration for guzzle 6", "if", "(", "class_exists", "(", "'\\GuzzleHttp\\Psr7\\Request'", ")", ")", "{", "$", "options", "=", "[", "'allow_redirects'", "=>", "false", "]", ";", "}", "else", "{", "$", "options", "=", "[", "'defaults'", "=>", "[", "'allow_redirects'", "=>", "false", "]", "]", ";", "}", "$", "this", "->", "client", "=", "new", "Client", "(", "$", "options", ")", ";", "}" ]
Build client @return $this Self object
[ "Build", "client" ]
train
https://github.com/Visithor/visithor/blob/201ba2cfc536a0875983c79226947aa20b9f4dca/src/Visithor/Client/GuzzleClient.php#L39-L55
Visithor/visithor
src/Visithor/Client/GuzzleClient.php
GuzzleClient.getResponseHTTPCode
public function getResponseHTTPCode(Url $url) { try { $verb = $url->getOption('verb', 'GET'); $client = $this->client; $result = $client ->send( class_exists('\GuzzleHttp\Psr7\Request') ? new \GuzzleHttp\Psr7\Request($verb, $url->getPath()) : $client->createRequest($verb, $url->getPath()) ) ->getStatusCode(); } catch (Exception $e) { $result = 400; } return $result; }
php
public function getResponseHTTPCode(Url $url) { try { $verb = $url->getOption('verb', 'GET'); $client = $this->client; $result = $client ->send( class_exists('\GuzzleHttp\Psr7\Request') ? new \GuzzleHttp\Psr7\Request($verb, $url->getPath()) : $client->createRequest($verb, $url->getPath()) ) ->getStatusCode(); } catch (Exception $e) { $result = 400; } return $result; }
[ "public", "function", "getResponseHTTPCode", "(", "Url", "$", "url", ")", "{", "try", "{", "$", "verb", "=", "$", "url", "->", "getOption", "(", "'verb'", ",", "'GET'", ")", ";", "$", "client", "=", "$", "this", "->", "client", ";", "$", "result", "=", "$", "client", "->", "send", "(", "class_exists", "(", "'\\GuzzleHttp\\Psr7\\Request'", ")", "?", "new", "\\", "GuzzleHttp", "\\", "Psr7", "\\", "Request", "(", "$", "verb", ",", "$", "url", "->", "getPath", "(", ")", ")", ":", "$", "client", "->", "createRequest", "(", "$", "verb", ",", "$", "url", "->", "getPath", "(", ")", ")", ")", "->", "getStatusCode", "(", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "result", "=", "400", ";", "}", "return", "$", "result", ";", "}" ]
Get the HTTP Code Response given an URL instance @param Url $url Url @return int Response HTTP Code
[ "Get", "the", "HTTP", "Code", "Response", "given", "an", "URL", "instance" ]
train
https://github.com/Visithor/visithor/blob/201ba2cfc536a0875983c79226947aa20b9f4dca/src/Visithor/Client/GuzzleClient.php#L64-L81
phpgears/dto
src/AbstractDTOCollection.php
AbstractDTOCollection.verifyElementsType
private function verifyElementsType(array $elements): void { $allowedType = $this->getAllowedType(); if ($allowedType !== DTO::class && (!\class_exists($allowedType) || !\in_array(DTO::class, \class_implements($allowedType), true)) ) { throw new InvalidCollectionTypeException(\sprintf( 'Allowed class type for %s should be a %s, %s given', static::class, DTO::class, $allowedType )); } foreach ($elements as $element) { if (!\is_object($element) || !\is_a($element, $allowedType)) { throw new InvalidParameterException(\sprintf( 'All elements of %s should be instances of %s, %s given', static::class, $allowedType, \is_object($element) ? \get_class($element) : \gettype($element) )); } } }
php
private function verifyElementsType(array $elements): void { $allowedType = $this->getAllowedType(); if ($allowedType !== DTO::class && (!\class_exists($allowedType) || !\in_array(DTO::class, \class_implements($allowedType), true)) ) { throw new InvalidCollectionTypeException(\sprintf( 'Allowed class type for %s should be a %s, %s given', static::class, DTO::class, $allowedType )); } foreach ($elements as $element) { if (!\is_object($element) || !\is_a($element, $allowedType)) { throw new InvalidParameterException(\sprintf( 'All elements of %s should be instances of %s, %s given', static::class, $allowedType, \is_object($element) ? \get_class($element) : \gettype($element) )); } } }
[ "private", "function", "verifyElementsType", "(", "array", "$", "elements", ")", ":", "void", "{", "$", "allowedType", "=", "$", "this", "->", "getAllowedType", "(", ")", ";", "if", "(", "$", "allowedType", "!==", "DTO", "::", "class", "&&", "(", "!", "\\", "class_exists", "(", "$", "allowedType", ")", "||", "!", "\\", "in_array", "(", "DTO", "::", "class", ",", "\\", "class_implements", "(", "$", "allowedType", ")", ",", "true", ")", ")", ")", "{", "throw", "new", "InvalidCollectionTypeException", "(", "\\", "sprintf", "(", "'Allowed class type for %s should be a %s, %s given'", ",", "static", "::", "class", ",", "DTO", "::", "class", ",", "$", "allowedType", ")", ")", ";", "}", "foreach", "(", "$", "elements", "as", "$", "element", ")", "{", "if", "(", "!", "\\", "is_object", "(", "$", "element", ")", "||", "!", "\\", "is_a", "(", "$", "element", ",", "$", "allowedType", ")", ")", "{", "throw", "new", "InvalidParameterException", "(", "\\", "sprintf", "(", "'All elements of %s should be instances of %s, %s given'", ",", "static", "::", "class", ",", "$", "allowedType", ",", "\\", "is_object", "(", "$", "element", ")", "?", "\\", "get_class", "(", "$", "element", ")", ":", "\\", "gettype", "(", "$", "element", ")", ")", ")", ";", "}", "}", "}" ]
Verify collection elements type. @param mixed[] $elements @throws InvalidCollectionTypeException @throws InvalidParameterException
[ "Verify", "collection", "elements", "type", "." ]
train
https://github.com/phpgears/dto/blob/404b2cdea108538b55caa261c29280062dd0e3db/src/AbstractDTOCollection.php#L76-L100
alevilar/ristorantino-vendor
Risto/Model/Behavior/MediaUploadableBehavior.php
MediaUploadableBehavior.setUp
function setUp(Model $Model, $options = array()) { if ( array_key_exists('mediaUploadFieldName', $options) ) { $this->_form_field_name = $options['mediaUploadFieldName']; } if ( array_key_exists('mediaUploadFk', $options) ) { $this->_form_fk = $options['mediaUploadFk']; } $Model->bindModel( array('belongsTo' => array( 'Media' => array( 'className' => 'Risto.Media' ) ) ) ); /* $Model->validate['media_file'] = array( 'rule' => 'uploadError', 'message' => __('Falló al subir el archivo. Es mas grande que %s?', ini_get('upload_max_filesize')), 'allowEmpty' => true, 'required' => false, ); */ // Inside a model class $Model->validator()->add('uploadError', false, array( 'rule' => 'uploadError', 'message' => __('Falló al subir el archivo. Es mas grande que %s?', ini_get('upload_max_filesize')), )); }
php
function setUp(Model $Model, $options = array()) { if ( array_key_exists('mediaUploadFieldName', $options) ) { $this->_form_field_name = $options['mediaUploadFieldName']; } if ( array_key_exists('mediaUploadFk', $options) ) { $this->_form_fk = $options['mediaUploadFk']; } $Model->bindModel( array('belongsTo' => array( 'Media' => array( 'className' => 'Risto.Media' ) ) ) ); /* $Model->validate['media_file'] = array( 'rule' => 'uploadError', 'message' => __('Falló al subir el archivo. Es mas grande que %s?', ini_get('upload_max_filesize')), 'allowEmpty' => true, 'required' => false, ); */ // Inside a model class $Model->validator()->add('uploadError', false, array( 'rule' => 'uploadError', 'message' => __('Falló al subir el archivo. Es mas grande que %s?', ini_get('upload_max_filesize')), )); }
[ "function", "setUp", "(", "Model", "$", "Model", ",", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "array_key_exists", "(", "'mediaUploadFieldName'", ",", "$", "options", ")", ")", "{", "$", "this", "->", "_form_field_name", "=", "$", "options", "[", "'mediaUploadFieldName'", "]", ";", "}", "if", "(", "array_key_exists", "(", "'mediaUploadFk'", ",", "$", "options", ")", ")", "{", "$", "this", "->", "_form_fk", "=", "$", "options", "[", "'mediaUploadFk'", "]", ";", "}", "$", "Model", "->", "bindModel", "(", "array", "(", "'belongsTo'", "=>", "array", "(", "'Media'", "=>", "array", "(", "'className'", "=>", "'Risto.Media'", ")", ")", ")", ")", ";", "/*\n \t$Model->validate['media_file'] = array(\n 'rule' => 'uploadError',\n 'message' => __('Falló al subir el archivo. Es mas grande que %s?', ini_get('upload_max_filesize')),\n 'allowEmpty' => true,\n 'required' => false,\n );\n */", "// Inside a model class", "$", "Model", "->", "validator", "(", ")", "->", "add", "(", "'uploadError'", ",", "false", ",", "array", "(", "'rule'", "=>", "'uploadError'", ",", "'message'", "=>", "__", "(", "'Falló al subir el archivo. Es mas grande que %s?',", " ", "ni_get(", "'", "upload_max_filesize')", ")", ",", "", ")", ")", ";", "}" ]
Setup the behavior
[ "Setup", "the", "behavior" ]
train
https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Model/Behavior/MediaUploadableBehavior.php#L11-L44
alevilar/ristorantino-vendor
Risto/Model/Behavior/MediaUploadableBehavior.php
MediaUploadableBehavior.beforeSave
function beforeSave( Model $Model, $options = array() ){ if ( !array_key_exists('Media', $Model->belongsTo) ) { $Model->bindModel( array('belongsTo' => array( 'Media' => array( 'className' => 'Risto.Media' ) ) ) ); } if( isset($Model->data[$Model->alias][$this->_form_field_name]) && isset( $Model->data[$Model->alias][$this->_form_field_name]['error'] ) && $Model->data[$Model->alias][$this->_form_field_name]['error'] == 0 ){ $data = array('Media' => $Model->data[$Model->alias][$this->_form_field_name]); $data['Media']['file'] = file_get_contents($Model->data[$Model->alias][$this->_form_field_name]['tmp_name']); $data['Media']['model'] = $Model->name; $Model->Media->create(); if ( !$Model->Media->save($data)) { // error $Model->validationErrors[$this->_form_field_name] = $Model->Media->validationErrors; return false; } $Model->data[$Model->alias][$this->_form_fk] = $Model->Media->id; } return true; }
php
function beforeSave( Model $Model, $options = array() ){ if ( !array_key_exists('Media', $Model->belongsTo) ) { $Model->bindModel( array('belongsTo' => array( 'Media' => array( 'className' => 'Risto.Media' ) ) ) ); } if( isset($Model->data[$Model->alias][$this->_form_field_name]) && isset( $Model->data[$Model->alias][$this->_form_field_name]['error'] ) && $Model->data[$Model->alias][$this->_form_field_name]['error'] == 0 ){ $data = array('Media' => $Model->data[$Model->alias][$this->_form_field_name]); $data['Media']['file'] = file_get_contents($Model->data[$Model->alias][$this->_form_field_name]['tmp_name']); $data['Media']['model'] = $Model->name; $Model->Media->create(); if ( !$Model->Media->save($data)) { // error $Model->validationErrors[$this->_form_field_name] = $Model->Media->validationErrors; return false; } $Model->data[$Model->alias][$this->_form_fk] = $Model->Media->id; } return true; }
[ "function", "beforeSave", "(", "Model", "$", "Model", ",", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "!", "array_key_exists", "(", "'Media'", ",", "$", "Model", "->", "belongsTo", ")", ")", "{", "$", "Model", "->", "bindModel", "(", "array", "(", "'belongsTo'", "=>", "array", "(", "'Media'", "=>", "array", "(", "'className'", "=>", "'Risto.Media'", ")", ")", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "Model", "->", "data", "[", "$", "Model", "->", "alias", "]", "[", "$", "this", "->", "_form_field_name", "]", ")", "&&", "isset", "(", "$", "Model", "->", "data", "[", "$", "Model", "->", "alias", "]", "[", "$", "this", "->", "_form_field_name", "]", "[", "'error'", "]", ")", "&&", "$", "Model", "->", "data", "[", "$", "Model", "->", "alias", "]", "[", "$", "this", "->", "_form_field_name", "]", "[", "'error'", "]", "==", "0", ")", "{", "$", "data", "=", "array", "(", "'Media'", "=>", "$", "Model", "->", "data", "[", "$", "Model", "->", "alias", "]", "[", "$", "this", "->", "_form_field_name", "]", ")", ";", "$", "data", "[", "'Media'", "]", "[", "'file'", "]", "=", "file_get_contents", "(", "$", "Model", "->", "data", "[", "$", "Model", "->", "alias", "]", "[", "$", "this", "->", "_form_field_name", "]", "[", "'tmp_name'", "]", ")", ";", "$", "data", "[", "'Media'", "]", "[", "'model'", "]", "=", "$", "Model", "->", "name", ";", "$", "Model", "->", "Media", "->", "create", "(", ")", ";", "if", "(", "!", "$", "Model", "->", "Media", "->", "save", "(", "$", "data", ")", ")", "{", "// error", "$", "Model", "->", "validationErrors", "[", "$", "this", "->", "_form_field_name", "]", "=", "$", "Model", "->", "Media", "->", "validationErrors", ";", "return", "false", ";", "}", "$", "Model", "->", "data", "[", "$", "Model", "->", "alias", "]", "[", "$", "this", "->", "_form_fk", "]", "=", "$", "Model", "->", "Media", "->", "id", ";", "}", "return", "true", ";", "}" ]
beforeSave if a file is found, upload it, and then save the filename according to the settings
[ "beforeSave", "if", "a", "file", "is", "found", "upload", "it", "and", "then", "save", "the", "filename", "according", "to", "the", "settings" ]
train
https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Model/Behavior/MediaUploadableBehavior.php#L52-L82
maestroprog/saw-php
src/Service/ApplicationLoader.php
ApplicationLoader.instanceApp
public function instanceApp(string $applicationClass): ApplicationInterface { if (!$this->applicationConfig->isApplicationClassValid($applicationClass)) { throw new \RuntimeException('Invalid application class: ' . $applicationClass); } try { $arguments = $this->applicationConfig->getApplicationArguments( $this->applicationConfig->getApplicationIdByClass($applicationClass) ); } catch (\RuntimeException $e) { $arguments = []; } $appId = $this->applicationConfig->getApplicationIdByClass($applicationClass); return $this->instanceAppWith( $applicationClass, $arguments, ['appId' => $appId] ); }
php
public function instanceApp(string $applicationClass): ApplicationInterface { if (!$this->applicationConfig->isApplicationClassValid($applicationClass)) { throw new \RuntimeException('Invalid application class: ' . $applicationClass); } try { $arguments = $this->applicationConfig->getApplicationArguments( $this->applicationConfig->getApplicationIdByClass($applicationClass) ); } catch (\RuntimeException $e) { $arguments = []; } $appId = $this->applicationConfig->getApplicationIdByClass($applicationClass); return $this->instanceAppWith( $applicationClass, $arguments, ['appId' => $appId] ); }
[ "public", "function", "instanceApp", "(", "string", "$", "applicationClass", ")", ":", "ApplicationInterface", "{", "if", "(", "!", "$", "this", "->", "applicationConfig", "->", "isApplicationClassValid", "(", "$", "applicationClass", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Invalid application class: '", ".", "$", "applicationClass", ")", ";", "}", "try", "{", "$", "arguments", "=", "$", "this", "->", "applicationConfig", "->", "getApplicationArguments", "(", "$", "this", "->", "applicationConfig", "->", "getApplicationIdByClass", "(", "$", "applicationClass", ")", ")", ";", "}", "catch", "(", "\\", "RuntimeException", "$", "e", ")", "{", "$", "arguments", "=", "[", "]", ";", "}", "$", "appId", "=", "$", "this", "->", "applicationConfig", "->", "getApplicationIdByClass", "(", "$", "applicationClass", ")", ";", "return", "$", "this", "->", "instanceAppWith", "(", "$", "applicationClass", ",", "$", "arguments", ",", "[", "'appId'", "=>", "$", "appId", "]", ")", ";", "}" ]
Инстанцирует новый объект приложения. Используется скриптом index.php. @param string $applicationClass @return ApplicationInterface
[ "Инстанцирует", "новый", "объект", "приложения", ".", "Используется", "скриптом", "index", ".", "php", "." ]
train
https://github.com/maestroprog/saw-php/blob/159215a4d7a951cca2a9c2eed3e1aa4f5b624cfb/src/Service/ApplicationLoader.php#L31-L51
maestroprog/saw-php
src/Service/ApplicationLoader.php
ApplicationLoader.instanceAllApps
public function instanceAllApps(): array { $allAppIds = $this->applicationConfig->getAllApplicationIds(); return array_map(function (string $id) { return $this->instanceAppById($id); }, $allAppIds); }
php
public function instanceAllApps(): array { $allAppIds = $this->applicationConfig->getAllApplicationIds(); return array_map(function (string $id) { return $this->instanceAppById($id); }, $allAppIds); }
[ "public", "function", "instanceAllApps", "(", ")", ":", "array", "{", "$", "allAppIds", "=", "$", "this", "->", "applicationConfig", "->", "getAllApplicationIds", "(", ")", ";", "return", "array_map", "(", "function", "(", "string", "$", "id", ")", "{", "return", "$", "this", "->", "instanceAppById", "(", "$", "id", ")", ";", "}", ",", "$", "allAppIds", ")", ";", "}" ]
Создаёт инстансы для всех приложений, описанных в разделе "applications" конфига. @return ApplicationInterface[]
[ "Создаёт", "инстансы", "для", "всех", "приложений", "описанных", "в", "разделе", "applications", "конфига", "." ]
train
https://github.com/maestroprog/saw-php/blob/159215a4d7a951cca2a9c2eed3e1aa4f5b624cfb/src/Service/ApplicationLoader.php#L76-L83
phPoirot/psr7
HttpRequest.php
HttpRequest.withUri
function withUri(UriInterface $uri, $preserveHost = false) { $new = clone $this; $new->uri = $uri; if ($preserveHost && $this->hasHeader('Host')) return $new; if (! $uri->getHost()) return $new; $host = $uri->getHost(); if ($uri->getPort()) $host .= ':' . $uri->getPort(); $new->_c_headerNormalized['host'] = 'Host'; // Remove an existing host header if present, regardless of current // de-normalization of the header name. foreach (array_keys($new->headers) as $header) { if (strtolower($header) === 'host') unset($new->headers[$header]); } $new->headers['Host'] = array($host); return $new; }
php
function withUri(UriInterface $uri, $preserveHost = false) { $new = clone $this; $new->uri = $uri; if ($preserveHost && $this->hasHeader('Host')) return $new; if (! $uri->getHost()) return $new; $host = $uri->getHost(); if ($uri->getPort()) $host .= ':' . $uri->getPort(); $new->_c_headerNormalized['host'] = 'Host'; // Remove an existing host header if present, regardless of current // de-normalization of the header name. foreach (array_keys($new->headers) as $header) { if (strtolower($header) === 'host') unset($new->headers[$header]); } $new->headers['Host'] = array($host); return $new; }
[ "function", "withUri", "(", "UriInterface", "$", "uri", ",", "$", "preserveHost", "=", "false", ")", "{", "$", "new", "=", "clone", "$", "this", ";", "$", "new", "->", "uri", "=", "$", "uri", ";", "if", "(", "$", "preserveHost", "&&", "$", "this", "->", "hasHeader", "(", "'Host'", ")", ")", "return", "$", "new", ";", "if", "(", "!", "$", "uri", "->", "getHost", "(", ")", ")", "return", "$", "new", ";", "$", "host", "=", "$", "uri", "->", "getHost", "(", ")", ";", "if", "(", "$", "uri", "->", "getPort", "(", ")", ")", "$", "host", ".=", "':'", ".", "$", "uri", "->", "getPort", "(", ")", ";", "$", "new", "->", "_c_headerNormalized", "[", "'host'", "]", "=", "'Host'", ";", "// Remove an existing host header if present, regardless of current", "// de-normalization of the header name.", "foreach", "(", "array_keys", "(", "$", "new", "->", "headers", ")", "as", "$", "header", ")", "{", "if", "(", "strtolower", "(", "$", "header", ")", "===", "'host'", ")", "unset", "(", "$", "new", "->", "headers", "[", "$", "header", "]", ")", ";", "}", "$", "new", "->", "headers", "[", "'Host'", "]", "=", "array", "(", "$", "host", ")", ";", "return", "$", "new", ";", "}" ]
Returns an instance with the provided URI. This method MUST update the Host header of the returned request by default if the URI contains a host component. If the URI does not contain a host component, any pre-existing Host header MUST be carried over to the returned request. You can opt-in to preserving the original state of the Host header by setting `$preserveHost` to `true`. When `$preserveHost` is set to `true`, this method interacts with the Host header in the following ways: - If the the Host header is missing or empty, and the new URI contains a host component, this method MUST update the Host header in the returned request. - If the Host header is missing or empty, and the new URI does not contain a host component, this method MUST NOT update the Host header in the returned request. - If a Host header is present and non-empty, this method MUST NOT update the Host header in the returned request. This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new UriInterface instance. @link http://tools.ietf.org/html/rfc3986#section-4.3 @param UriInterface $uri New request URI to use. @param bool $preserveHost Preserve the original state of the Host header. @return self
[ "Returns", "an", "instance", "with", "the", "provided", "URI", "." ]
train
https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/HttpRequest.php#L235-L262
phPoirot/psr7
HttpRequest.php
HttpRequest.getHeaders
function getHeaders() { $headers = $this->headers; if (! $this->hasHeader('host')) { if ($this->uri && $this->uri->getHost()) $headers['Host'] = array($this->_getHostFromUri()); } return $headers; }
php
function getHeaders() { $headers = $this->headers; if (! $this->hasHeader('host')) { if ($this->uri && $this->uri->getHost()) $headers['Host'] = array($this->_getHostFromUri()); } return $headers; }
[ "function", "getHeaders", "(", ")", "{", "$", "headers", "=", "$", "this", "->", "headers", ";", "if", "(", "!", "$", "this", "->", "hasHeader", "(", "'host'", ")", ")", "{", "if", "(", "$", "this", "->", "uri", "&&", "$", "this", "->", "uri", "->", "getHost", "(", ")", ")", "$", "headers", "[", "'Host'", "]", "=", "array", "(", "$", "this", "->", "_getHostFromUri", "(", ")", ")", ";", "}", "return", "$", "headers", ";", "}" ]
@Override {@inheritdoc}
[ "@Override" ]
train
https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/HttpRequest.php#L272-L281
phPoirot/psr7
HttpRequest.php
HttpRequest.getHeader
function getHeader($header) { if (! $this->hasHeader($header)) { if (strtolower($header) === 'host' && ($this->uri && $this->uri->getHost()) ) return array($this->_getHostFromUri()); return array(); } $header = $this->_c_headerNormalized[strtolower($header)]; $value = $this->headers[$header]; $value = is_array($value) ? $value : array($value); return $value; }
php
function getHeader($header) { if (! $this->hasHeader($header)) { if (strtolower($header) === 'host' && ($this->uri && $this->uri->getHost()) ) return array($this->_getHostFromUri()); return array(); } $header = $this->_c_headerNormalized[strtolower($header)]; $value = $this->headers[$header]; $value = is_array($value) ? $value : array($value); return $value; }
[ "function", "getHeader", "(", "$", "header", ")", "{", "if", "(", "!", "$", "this", "->", "hasHeader", "(", "$", "header", ")", ")", "{", "if", "(", "strtolower", "(", "$", "header", ")", "===", "'host'", "&&", "(", "$", "this", "->", "uri", "&&", "$", "this", "->", "uri", "->", "getHost", "(", ")", ")", ")", "return", "array", "(", "$", "this", "->", "_getHostFromUri", "(", ")", ")", ";", "return", "array", "(", ")", ";", "}", "$", "header", "=", "$", "this", "->", "_c_headerNormalized", "[", "strtolower", "(", "$", "header", ")", "]", ";", "$", "value", "=", "$", "this", "->", "headers", "[", "$", "header", "]", ";", "$", "value", "=", "is_array", "(", "$", "value", ")", "?", "$", "value", ":", "array", "(", "$", "value", ")", ";", "return", "$", "value", ";", "}" ]
@Override {@inheritdoc}
[ "@Override" ]
train
https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/HttpRequest.php#L288-L303
phPoirot/psr7
HttpRequest.php
HttpRequest._getHostFromUri
protected function _getHostFromUri() { $host = $this->uri->getHost(); $host .= $this->uri->getPort() ? ':' . $this->uri->getPort() : ''; return $host; }
php
protected function _getHostFromUri() { $host = $this->uri->getHost(); $host .= $this->uri->getPort() ? ':' . $this->uri->getPort() : ''; return $host; }
[ "protected", "function", "_getHostFromUri", "(", ")", "{", "$", "host", "=", "$", "this", "->", "uri", "->", "getHost", "(", ")", ";", "$", "host", ".=", "$", "this", "->", "uri", "->", "getPort", "(", ")", "?", "':'", ".", "$", "this", "->", "uri", "->", "getPort", "(", ")", ":", "''", ";", "return", "$", "host", ";", "}" ]
Retrieve the host from the URI instance @return string
[ "Retrieve", "the", "host", "from", "the", "URI", "instance" ]
train
https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/HttpRequest.php#L310-L315
dragonmantank/fillet
src/Fillet/Writer/WriterFactory.php
WriterFactory.create
public static function create($postType, $config, $throwExceptionOnInvalidWriter = false) { $className = 'Fillet\\Writer\\' . ucfirst($postType) . 'Writer'; if(class_exists($className)) { /** @var WriterInterface $writer */ $writer = new $className($config['destinationFolders'][$postType], $config); return $writer; } if($throwExceptionOnInvalidWriter) { throw new \Exception('There is no writer for ' . $postType); } }
php
public static function create($postType, $config, $throwExceptionOnInvalidWriter = false) { $className = 'Fillet\\Writer\\' . ucfirst($postType) . 'Writer'; if(class_exists($className)) { /** @var WriterInterface $writer */ $writer = new $className($config['destinationFolders'][$postType], $config); return $writer; } if($throwExceptionOnInvalidWriter) { throw new \Exception('There is no writer for ' . $postType); } }
[ "public", "static", "function", "create", "(", "$", "postType", ",", "$", "config", ",", "$", "throwExceptionOnInvalidWriter", "=", "false", ")", "{", "$", "className", "=", "'Fillet\\\\Writer\\\\'", ".", "ucfirst", "(", "$", "postType", ")", ".", "'Writer'", ";", "if", "(", "class_exists", "(", "$", "className", ")", ")", "{", "/** @var WriterInterface $writer */", "$", "writer", "=", "new", "$", "className", "(", "$", "config", "[", "'destinationFolders'", "]", "[", "$", "postType", "]", ",", "$", "config", ")", ";", "return", "$", "writer", ";", "}", "if", "(", "$", "throwExceptionOnInvalidWriter", ")", "{", "throw", "new", "\\", "Exception", "(", "'There is no writer for '", ".", "$", "postType", ")", ";", "}", "}" ]
Create a new instance of a writer based on the post type @param string $postType Post type we are working against @param array $config Config to use to generate the writer @param bool $throwExceptionOnInvalidWriter Whether to throw an exception if an unknown writer is requested @return WriterInterface @throws \Exception
[ "Create", "a", "new", "instance", "of", "a", "writer", "based", "on", "the", "post", "type" ]
train
https://github.com/dragonmantank/fillet/blob/b197947608c05ac2318e8f6b296345494004d9c6/src/Fillet/Writer/WriterFactory.php#L22-L34
EmanuelNikolov/IgdbApiBundle
Igdb/Parameter/ParameterBuilder.php
ParameterBuilder.setFilters
public function setFilters( string $field, string $postfix ): ParameterBuilderInterface { $this->filters[$field] = $postfix; return $this; }
php
public function setFilters( string $field, string $postfix ): ParameterBuilderInterface { $this->filters[$field] = $postfix; return $this; }
[ "public", "function", "setFilters", "(", "string", "$", "field", ",", "string", "$", "postfix", ")", ":", "ParameterBuilderInterface", "{", "$", "this", "->", "filters", "[", "$", "field", "]", "=", "$", "postfix", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/EmanuelNikolov/IgdbApiBundle/blob/eedfc80298064a424990ebc5924649afdeaa00c8/Igdb/Parameter/ParameterBuilder.php#L82-L88
EmanuelNikolov/IgdbApiBundle
Igdb/Parameter/ParameterBuilder.php
ParameterBuilder.buildQueryString
public function buildQueryString(): string { $propsArr = get_object_vars($this); foreach ($propsArr as $key => $prop) { // faster than is_array smh if ((array)$prop === $prop && $key !== 'filters') { $propsArr[$key] = implode(',', $prop); } } $ids = $propsArr['ids']; unset($propsArr['ids']); empty($propsArr['fields']) ? $propsArr['fields'] = '*' : null; $filters = ''; if (isset($propsArr['filters'])) { foreach ($propsArr['filters'] as $field => $postfix) { $filters .= "&filter{$field}={$postfix}"; } unset($propsArr['filters']); } // using urldecode because http_build_query encodes commas :| return $ids . '?' . urldecode(http_build_query($propsArr)) . $filters; }
php
public function buildQueryString(): string { $propsArr = get_object_vars($this); foreach ($propsArr as $key => $prop) { // faster than is_array smh if ((array)$prop === $prop && $key !== 'filters') { $propsArr[$key] = implode(',', $prop); } } $ids = $propsArr['ids']; unset($propsArr['ids']); empty($propsArr['fields']) ? $propsArr['fields'] = '*' : null; $filters = ''; if (isset($propsArr['filters'])) { foreach ($propsArr['filters'] as $field => $postfix) { $filters .= "&filter{$field}={$postfix}"; } unset($propsArr['filters']); } // using urldecode because http_build_query encodes commas :| return $ids . '?' . urldecode(http_build_query($propsArr)) . $filters; }
[ "public", "function", "buildQueryString", "(", ")", ":", "string", "{", "$", "propsArr", "=", "get_object_vars", "(", "$", "this", ")", ";", "foreach", "(", "$", "propsArr", "as", "$", "key", "=>", "$", "prop", ")", "{", "// faster than is_array smh", "if", "(", "(", "array", ")", "$", "prop", "===", "$", "prop", "&&", "$", "key", "!==", "'filters'", ")", "{", "$", "propsArr", "[", "$", "key", "]", "=", "implode", "(", "','", ",", "$", "prop", ")", ";", "}", "}", "$", "ids", "=", "$", "propsArr", "[", "'ids'", "]", ";", "unset", "(", "$", "propsArr", "[", "'ids'", "]", ")", ";", "empty", "(", "$", "propsArr", "[", "'fields'", "]", ")", "?", "$", "propsArr", "[", "'fields'", "]", "=", "'*'", ":", "null", ";", "$", "filters", "=", "''", ";", "if", "(", "isset", "(", "$", "propsArr", "[", "'filters'", "]", ")", ")", "{", "foreach", "(", "$", "propsArr", "[", "'filters'", "]", "as", "$", "field", "=>", "$", "postfix", ")", "{", "$", "filters", ".=", "\"&filter{$field}={$postfix}\"", ";", "}", "unset", "(", "$", "propsArr", "[", "'filters'", "]", ")", ";", "}", "// using urldecode because http_build_query encodes commas :|", "return", "$", "ids", ".", "'?'", ".", "urldecode", "(", "http_build_query", "(", "$", "propsArr", ")", ")", ".", "$", "filters", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/EmanuelNikolov/IgdbApiBundle/blob/eedfc80298064a424990ebc5924649afdeaa00c8/Igdb/Parameter/ParameterBuilder.php#L156-L184
EmanuelNikolov/IgdbApiBundle
Igdb/Parameter/ParameterBuilder.php
ParameterBuilder.clear
public function clear(): void { $props = get_object_vars($this); foreach ($props as $key => $prop) { $this->$key = null; } }
php
public function clear(): void { $props = get_object_vars($this); foreach ($props as $key => $prop) { $this->$key = null; } }
[ "public", "function", "clear", "(", ")", ":", "void", "{", "$", "props", "=", "get_object_vars", "(", "$", "this", ")", ";", "foreach", "(", "$", "props", "as", "$", "key", "=>", "$", "prop", ")", "{", "$", "this", "->", "$", "key", "=", "null", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/EmanuelNikolov/IgdbApiBundle/blob/eedfc80298064a424990ebc5924649afdeaa00c8/Igdb/Parameter/ParameterBuilder.php#L189-L196
rinvex/renamed-attributes
src/Traits/Attributable.php
Attributable.relationsToArray
public function relationsToArray() { $eavAttributes = []; $attributes = parent::relationsToArray(); $relations = array_keys($this->getEntityAttributeRelations()); foreach ($relations as $relation) { if (array_key_exists($relation, $attributes)) { $eavAttributes[$relation] = $this->getAttribute($relation) instanceof BaseCollection ? $this->getAttribute($relation)->toArray() : $this->getAttribute($relation); // By unsetting the relation from the attributes array we will make // sure we do not provide a duplicity when adding the namespace. // Otherwise it would keep the relation as a key in the root. unset($attributes[$relation]); } } if (is_null($namespace = $this->getEntityAttributesNamespace())) { $attributes = array_merge($attributes, $eavAttributes); } else { Arr::set($attributes, $namespace, $eavAttributes); } return $attributes; }
php
public function relationsToArray() { $eavAttributes = []; $attributes = parent::relationsToArray(); $relations = array_keys($this->getEntityAttributeRelations()); foreach ($relations as $relation) { if (array_key_exists($relation, $attributes)) { $eavAttributes[$relation] = $this->getAttribute($relation) instanceof BaseCollection ? $this->getAttribute($relation)->toArray() : $this->getAttribute($relation); // By unsetting the relation from the attributes array we will make // sure we do not provide a duplicity when adding the namespace. // Otherwise it would keep the relation as a key in the root. unset($attributes[$relation]); } } if (is_null($namespace = $this->getEntityAttributesNamespace())) { $attributes = array_merge($attributes, $eavAttributes); } else { Arr::set($attributes, $namespace, $eavAttributes); } return $attributes; }
[ "public", "function", "relationsToArray", "(", ")", "{", "$", "eavAttributes", "=", "[", "]", ";", "$", "attributes", "=", "parent", "::", "relationsToArray", "(", ")", ";", "$", "relations", "=", "array_keys", "(", "$", "this", "->", "getEntityAttributeRelations", "(", ")", ")", ";", "foreach", "(", "$", "relations", "as", "$", "relation", ")", "{", "if", "(", "array_key_exists", "(", "$", "relation", ",", "$", "attributes", ")", ")", "{", "$", "eavAttributes", "[", "$", "relation", "]", "=", "$", "this", "->", "getAttribute", "(", "$", "relation", ")", "instanceof", "BaseCollection", "?", "$", "this", "->", "getAttribute", "(", "$", "relation", ")", "->", "toArray", "(", ")", ":", "$", "this", "->", "getAttribute", "(", "$", "relation", ")", ";", "// By unsetting the relation from the attributes array we will make", "// sure we do not provide a duplicity when adding the namespace.", "// Otherwise it would keep the relation as a key in the root.", "unset", "(", "$", "attributes", "[", "$", "relation", "]", ")", ";", "}", "}", "if", "(", "is_null", "(", "$", "namespace", "=", "$", "this", "->", "getEntityAttributesNamespace", "(", ")", ")", ")", "{", "$", "attributes", "=", "array_merge", "(", "$", "attributes", ",", "$", "eavAttributes", ")", ";", "}", "else", "{", "Arr", "::", "set", "(", "$", "attributes", ",", "$", "namespace", ",", "$", "eavAttributes", ")", ";", "}", "return", "$", "attributes", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/rinvex/renamed-attributes/blob/5cd6807783e6c8356a3805f15a0d8ea621c48a63/src/Traits/Attributable.php#L81-L106
mmanos/laravel-casset
src/Mmanos/Casset/Container.php
Container.add
public function add($source, array $attributes = array(), array $dependencies = array()) { $ext = pathinfo($source, PATHINFO_EXTENSION); $this->assets[$source] = compact('ext', 'source', 'attributes', 'dependencies'); }
php
public function add($source, array $attributes = array(), array $dependencies = array()) { $ext = pathinfo($source, PATHINFO_EXTENSION); $this->assets[$source] = compact('ext', 'source', 'attributes', 'dependencies'); }
[ "public", "function", "add", "(", "$", "source", ",", "array", "$", "attributes", "=", "array", "(", ")", ",", "array", "$", "dependencies", "=", "array", "(", ")", ")", "{", "$", "ext", "=", "pathinfo", "(", "$", "source", ",", "PATHINFO_EXTENSION", ")", ";", "$", "this", "->", "assets", "[", "$", "source", "]", "=", "compact", "(", "'ext'", ",", "'source'", ",", "'attributes'", ",", "'dependencies'", ")", ";", "}" ]
Add an asset (of any type) to the container. Accepts a source relative to the configured 'assets_dir'. eg: 'js/jquery.js' Also accepts a source relative to a package. eg: 'package::js/file.js' @param string $source Relative path to file. @param array $attributes Attribuets array. @param array $dependencies Dependencies array. @return Container
[ "Add", "an", "asset", "(", "of", "any", "type", ")", "to", "the", "container", "." ]
train
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L154-L159
mmanos/laravel-casset
src/Mmanos/Casset/Container.php
Container.styles
public function styles() { $assets = array(); foreach ($this->assets as $asset) { if ('css' !== $asset['ext'] && 'less' !== $asset['ext']) { continue; } $assets[] = $this->route ? $asset : $this->process($asset); } if (empty($assets)) { return ''; } if ($this->route) { return $this->prepareForController($assets, 'style'); } if ($this->combine) { $assets = $this->combine($assets, 'style'); } $links = array(); foreach ($assets as $asset) { $url = $this->cdn ? $this->cdn . $asset['url'] : $asset['url']; $links[] = HTML::style($url, $asset['attributes']); } return implode('', $links); }
php
public function styles() { $assets = array(); foreach ($this->assets as $asset) { if ('css' !== $asset['ext'] && 'less' !== $asset['ext']) { continue; } $assets[] = $this->route ? $asset : $this->process($asset); } if (empty($assets)) { return ''; } if ($this->route) { return $this->prepareForController($assets, 'style'); } if ($this->combine) { $assets = $this->combine($assets, 'style'); } $links = array(); foreach ($assets as $asset) { $url = $this->cdn ? $this->cdn . $asset['url'] : $asset['url']; $links[] = HTML::style($url, $asset['attributes']); } return implode('', $links); }
[ "public", "function", "styles", "(", ")", "{", "$", "assets", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "assets", "as", "$", "asset", ")", "{", "if", "(", "'css'", "!==", "$", "asset", "[", "'ext'", "]", "&&", "'less'", "!==", "$", "asset", "[", "'ext'", "]", ")", "{", "continue", ";", "}", "$", "assets", "[", "]", "=", "$", "this", "->", "route", "?", "$", "asset", ":", "$", "this", "->", "process", "(", "$", "asset", ")", ";", "}", "if", "(", "empty", "(", "$", "assets", ")", ")", "{", "return", "''", ";", "}", "if", "(", "$", "this", "->", "route", ")", "{", "return", "$", "this", "->", "prepareForController", "(", "$", "assets", ",", "'style'", ")", ";", "}", "if", "(", "$", "this", "->", "combine", ")", "{", "$", "assets", "=", "$", "this", "->", "combine", "(", "$", "assets", ",", "'style'", ")", ";", "}", "$", "links", "=", "array", "(", ")", ";", "foreach", "(", "$", "assets", "as", "$", "asset", ")", "{", "$", "url", "=", "$", "this", "->", "cdn", "?", "$", "this", "->", "cdn", ".", "$", "asset", "[", "'url'", "]", ":", "$", "asset", "[", "'url'", "]", ";", "$", "links", "[", "]", "=", "HTML", "::", "style", "(", "$", "url", ",", "$", "asset", "[", "'attributes'", "]", ")", ";", "}", "return", "implode", "(", "''", ",", "$", "links", ")", ";", "}" ]
Get the HTML links to all of the registered CSS assets. @return string
[ "Get", "the", "HTML", "links", "to", "all", "of", "the", "registered", "CSS", "assets", "." ]
train
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L166-L197
mmanos/laravel-casset
src/Mmanos/Casset/Container.php
Container.scripts
public function scripts() { $assets = array(); foreach ($this->assets as $asset) { if ('js' !== $asset['ext']) { continue; } $assets[] = $this->route ? $asset : $this->process($asset); } if (empty($assets)) { return ''; } if ($this->route) { return $this->prepareForController($assets, 'script'); } if ($this->combine) { $assets = $this->combine($assets, 'script'); } $links = array(); foreach ($assets as $asset) { $url = $this->cdn ? $this->cdn . $asset['url'] : $asset['url']; $links[] = HTML::script($url, $asset['attributes']); } return implode('', $links); }
php
public function scripts() { $assets = array(); foreach ($this->assets as $asset) { if ('js' !== $asset['ext']) { continue; } $assets[] = $this->route ? $asset : $this->process($asset); } if (empty($assets)) { return ''; } if ($this->route) { return $this->prepareForController($assets, 'script'); } if ($this->combine) { $assets = $this->combine($assets, 'script'); } $links = array(); foreach ($assets as $asset) { $url = $this->cdn ? $this->cdn . $asset['url'] : $asset['url']; $links[] = HTML::script($url, $asset['attributes']); } return implode('', $links); }
[ "public", "function", "scripts", "(", ")", "{", "$", "assets", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "assets", "as", "$", "asset", ")", "{", "if", "(", "'js'", "!==", "$", "asset", "[", "'ext'", "]", ")", "{", "continue", ";", "}", "$", "assets", "[", "]", "=", "$", "this", "->", "route", "?", "$", "asset", ":", "$", "this", "->", "process", "(", "$", "asset", ")", ";", "}", "if", "(", "empty", "(", "$", "assets", ")", ")", "{", "return", "''", ";", "}", "if", "(", "$", "this", "->", "route", ")", "{", "return", "$", "this", "->", "prepareForController", "(", "$", "assets", ",", "'script'", ")", ";", "}", "if", "(", "$", "this", "->", "combine", ")", "{", "$", "assets", "=", "$", "this", "->", "combine", "(", "$", "assets", ",", "'script'", ")", ";", "}", "$", "links", "=", "array", "(", ")", ";", "foreach", "(", "$", "assets", "as", "$", "asset", ")", "{", "$", "url", "=", "$", "this", "->", "cdn", "?", "$", "this", "->", "cdn", ".", "$", "asset", "[", "'url'", "]", ":", "$", "asset", "[", "'url'", "]", ";", "$", "links", "[", "]", "=", "HTML", "::", "script", "(", "$", "url", ",", "$", "asset", "[", "'attributes'", "]", ")", ";", "}", "return", "implode", "(", "''", ",", "$", "links", ")", ";", "}" ]
Get the HTML links to all of the registered JavaScript assets. @return string
[ "Get", "the", "HTML", "links", "to", "all", "of", "the", "registered", "JavaScript", "assets", "." ]
train
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L204-L235
mmanos/laravel-casset
src/Mmanos/Casset/Container.php
Container.prepareForController
public function prepareForController($assets, $type) { $controller_url = $this->cdn ? $this->cdn . '/' : '/'; $controller_url .= $this->route . '/' . $type; $controller_url .= '?c=' . urlencode($this->name); $links = array(); foreach ($assets as &$asset) { $attributes = $asset['attributes']; unset($asset['attributes']); unset($asset['ext']); if (empty($asset['dependencies'])) { unset($asset['dependencies']); } if (!$this->combine) { $url = $controller_url . '&files=' . base64_encode(json_encode(array($asset))); $url .= $this->version ? '&v=' . $this->version : ''; if ('style' == $type) { $links[] = HTML::style($url, $attributes); } else { $links[] = HTML::script($url, $attributes); } } } if ($this->combine) { $url = $controller_url . '&files=' . base64_encode(json_encode($assets)); $url .= $this->version ? '&v=' . $this->version : ''; if ('style' == $type) { $links[] = HTML::style($url); } else { $links[] = HTML::script($url); } } return implode('', $links); }
php
public function prepareForController($assets, $type) { $controller_url = $this->cdn ? $this->cdn . '/' : '/'; $controller_url .= $this->route . '/' . $type; $controller_url .= '?c=' . urlencode($this->name); $links = array(); foreach ($assets as &$asset) { $attributes = $asset['attributes']; unset($asset['attributes']); unset($asset['ext']); if (empty($asset['dependencies'])) { unset($asset['dependencies']); } if (!$this->combine) { $url = $controller_url . '&files=' . base64_encode(json_encode(array($asset))); $url .= $this->version ? '&v=' . $this->version : ''; if ('style' == $type) { $links[] = HTML::style($url, $attributes); } else { $links[] = HTML::script($url, $attributes); } } } if ($this->combine) { $url = $controller_url . '&files=' . base64_encode(json_encode($assets)); $url .= $this->version ? '&v=' . $this->version : ''; if ('style' == $type) { $links[] = HTML::style($url); } else { $links[] = HTML::script($url); } } return implode('', $links); }
[ "public", "function", "prepareForController", "(", "$", "assets", ",", "$", "type", ")", "{", "$", "controller_url", "=", "$", "this", "->", "cdn", "?", "$", "this", "->", "cdn", ".", "'/'", ":", "'/'", ";", "$", "controller_url", ".=", "$", "this", "->", "route", ".", "'/'", ".", "$", "type", ";", "$", "controller_url", ".=", "'?c='", ".", "urlencode", "(", "$", "this", "->", "name", ")", ";", "$", "links", "=", "array", "(", ")", ";", "foreach", "(", "$", "assets", "as", "&", "$", "asset", ")", "{", "$", "attributes", "=", "$", "asset", "[", "'attributes'", "]", ";", "unset", "(", "$", "asset", "[", "'attributes'", "]", ")", ";", "unset", "(", "$", "asset", "[", "'ext'", "]", ")", ";", "if", "(", "empty", "(", "$", "asset", "[", "'dependencies'", "]", ")", ")", "{", "unset", "(", "$", "asset", "[", "'dependencies'", "]", ")", ";", "}", "if", "(", "!", "$", "this", "->", "combine", ")", "{", "$", "url", "=", "$", "controller_url", ".", "'&files='", ".", "base64_encode", "(", "json_encode", "(", "array", "(", "$", "asset", ")", ")", ")", ";", "$", "url", ".=", "$", "this", "->", "version", "?", "'&v='", ".", "$", "this", "->", "version", ":", "''", ";", "if", "(", "'style'", "==", "$", "type", ")", "{", "$", "links", "[", "]", "=", "HTML", "::", "style", "(", "$", "url", ",", "$", "attributes", ")", ";", "}", "else", "{", "$", "links", "[", "]", "=", "HTML", "::", "script", "(", "$", "url", ",", "$", "attributes", ")", ";", "}", "}", "}", "if", "(", "$", "this", "->", "combine", ")", "{", "$", "url", "=", "$", "controller_url", ".", "'&files='", ".", "base64_encode", "(", "json_encode", "(", "$", "assets", ")", ")", ";", "$", "url", ".=", "$", "this", "->", "version", "?", "'&v='", ".", "$", "this", "->", "version", ":", "''", ";", "if", "(", "'style'", "==", "$", "type", ")", "{", "$", "links", "[", "]", "=", "HTML", "::", "style", "(", "$", "url", ")", ";", "}", "else", "{", "$", "links", "[", "]", "=", "HTML", "::", "script", "(", "$", "url", ")", ";", "}", "}", "return", "implode", "(", "''", ",", "$", "links", ")", ";", "}" ]
Prepare the given assets to be rendered to call the Casset controller and return the HTML link to that resource. @param array $assets @param string $type @return string
[ "Prepare", "the", "given", "assets", "to", "be", "rendered", "to", "call", "the", "Casset", "controller", "and", "return", "the", "HTML", "link", "to", "that", "resource", "." ]
train
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L246-L289
mmanos/laravel-casset
src/Mmanos/Casset/Container.php
Container.content
public function content($type) { $assets = array(); foreach ($this->assets as $asset) { if ('style' == $type && 'css' !== $asset['ext'] && 'less' !== $asset['ext']) { continue; } else if ('script' == $type && 'js' !== $asset['ext']) { continue; } $assets[] = $this->process($asset); } if (empty($assets)) { return ''; } if (count($assets) > 1 || $this->minify) { $assets = $this->combine($assets, $type); } $content = array(); foreach ($assets as $asset) { $content[] = File::get(array_get($asset, 'path')); } return implode("\n\n", $content); }
php
public function content($type) { $assets = array(); foreach ($this->assets as $asset) { if ('style' == $type && 'css' !== $asset['ext'] && 'less' !== $asset['ext']) { continue; } else if ('script' == $type && 'js' !== $asset['ext']) { continue; } $assets[] = $this->process($asset); } if (empty($assets)) { return ''; } if (count($assets) > 1 || $this->minify) { $assets = $this->combine($assets, $type); } $content = array(); foreach ($assets as $asset) { $content[] = File::get(array_get($asset, 'path')); } return implode("\n\n", $content); }
[ "public", "function", "content", "(", "$", "type", ")", "{", "$", "assets", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "assets", "as", "$", "asset", ")", "{", "if", "(", "'style'", "==", "$", "type", "&&", "'css'", "!==", "$", "asset", "[", "'ext'", "]", "&&", "'less'", "!==", "$", "asset", "[", "'ext'", "]", ")", "{", "continue", ";", "}", "else", "if", "(", "'script'", "==", "$", "type", "&&", "'js'", "!==", "$", "asset", "[", "'ext'", "]", ")", "{", "continue", ";", "}", "$", "assets", "[", "]", "=", "$", "this", "->", "process", "(", "$", "asset", ")", ";", "}", "if", "(", "empty", "(", "$", "assets", ")", ")", "{", "return", "''", ";", "}", "if", "(", "count", "(", "$", "assets", ")", ">", "1", "||", "$", "this", "->", "minify", ")", "{", "$", "assets", "=", "$", "this", "->", "combine", "(", "$", "assets", ",", "$", "type", ")", ";", "}", "$", "content", "=", "array", "(", ")", ";", "foreach", "(", "$", "assets", "as", "$", "asset", ")", "{", "$", "content", "[", "]", "=", "File", "::", "get", "(", "array_get", "(", "$", "asset", ",", "'path'", ")", ")", ";", "}", "return", "implode", "(", "\"\\n\\n\"", ",", "$", "content", ")", ";", "}" ]
Process and return the contents for this container for the requested file type. @param string $type 'style' or 'script' @return string
[ "Process", "and", "return", "the", "contents", "for", "this", "container", "for", "the", "requested", "file", "type", "." ]
train
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L299-L329
mmanos/laravel-casset
src/Mmanos/Casset/Container.php
Container.image
public function image($source, $alt = null, $attributes = array()) { $url = $source; if (false === strstr($source, '://') && '//' !== substr($source, 0, 2)) { $url = $this->cdn($source); } return HTML::image($url, $alt, $attributes); }
php
public function image($source, $alt = null, $attributes = array()) { $url = $source; if (false === strstr($source, '://') && '//' !== substr($source, 0, 2)) { $url = $this->cdn($source); } return HTML::image($url, $alt, $attributes); }
[ "public", "function", "image", "(", "$", "source", ",", "$", "alt", "=", "null", ",", "$", "attributes", "=", "array", "(", ")", ")", "{", "$", "url", "=", "$", "source", ";", "if", "(", "false", "===", "strstr", "(", "$", "source", ",", "'://'", ")", "&&", "'//'", "!==", "substr", "(", "$", "source", ",", "0", ",", "2", ")", ")", "{", "$", "url", "=", "$", "this", "->", "cdn", "(", "$", "source", ")", ";", "}", "return", "HTML", "::", "image", "(", "$", "url", ",", "$", "alt", ",", "$", "attributes", ")", ";", "}" ]
Add an image asset to the container. @param string $source @param string $alt @param array $attributes @return string
[ "Add", "an", "image", "asset", "to", "the", "container", "." ]
train
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L340-L349
mmanos/laravel-casset
src/Mmanos/Casset/Container.php
Container.cdn
public function cdn($source) { $url = str_ireplace($this->public_path, '', $this->assets_path . '/' . ltrim($source, '/')); $url = $this->cdn ? $this->cdn . $url : $url; return $url; }
php
public function cdn($source) { $url = str_ireplace($this->public_path, '', $this->assets_path . '/' . ltrim($source, '/')); $url = $this->cdn ? $this->cdn . $url : $url; return $url; }
[ "public", "function", "cdn", "(", "$", "source", ")", "{", "$", "url", "=", "str_ireplace", "(", "$", "this", "->", "public_path", ",", "''", ",", "$", "this", "->", "assets_path", ".", "'/'", ".", "ltrim", "(", "$", "source", ",", "'/'", ")", ")", ";", "$", "url", "=", "$", "this", "->", "cdn", "?", "$", "this", "->", "cdn", ".", "$", "url", ":", "$", "url", ";", "return", "$", "url", ";", "}" ]
Get the URL to the CDN for an asset. @param string $source @return string
[ "Get", "the", "URL", "to", "the", "CDN", "for", "an", "asset", "." ]
train
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L358-L363
mmanos/laravel-casset
src/Mmanos/Casset/Container.php
Container.path
public function path($source) { if (false === stristr($source, '::')) { return $this->assets_path . '/' . ltrim($source, '/'); } $source_parts = explode('::', $source); $package_name = current($source_parts); // Is this relative to the public dir? $path = '/public/' . ltrim(end($source_parts), '/'); if ('/' === substr(end($source_parts), 0, 1)) { $path = end($source_parts); } // Check local cache first. if (array_key_exists($package_name, static::$cached_paths)) { return static::$cached_paths[$package_name] . $path; } $finder = \Symfony\Component\Finder\Finder::create(); // Try to find in workbench, first. $workbench = base_path() . '/workbench'; if (file_exists($workbench . '/' . $package_name . $path)) { return $workbench . '/' . $package_name . $path; } // Use package path. $vendor = base_path() . '/vendor'; return $vendor . '/' . $package_name . $path; }
php
public function path($source) { if (false === stristr($source, '::')) { return $this->assets_path . '/' . ltrim($source, '/'); } $source_parts = explode('::', $source); $package_name = current($source_parts); // Is this relative to the public dir? $path = '/public/' . ltrim(end($source_parts), '/'); if ('/' === substr(end($source_parts), 0, 1)) { $path = end($source_parts); } // Check local cache first. if (array_key_exists($package_name, static::$cached_paths)) { return static::$cached_paths[$package_name] . $path; } $finder = \Symfony\Component\Finder\Finder::create(); // Try to find in workbench, first. $workbench = base_path() . '/workbench'; if (file_exists($workbench . '/' . $package_name . $path)) { return $workbench . '/' . $package_name . $path; } // Use package path. $vendor = base_path() . '/vendor'; return $vendor . '/' . $package_name . $path; }
[ "public", "function", "path", "(", "$", "source", ")", "{", "if", "(", "false", "===", "stristr", "(", "$", "source", ",", "'::'", ")", ")", "{", "return", "$", "this", "->", "assets_path", ".", "'/'", ".", "ltrim", "(", "$", "source", ",", "'/'", ")", ";", "}", "$", "source_parts", "=", "explode", "(", "'::'", ",", "$", "source", ")", ";", "$", "package_name", "=", "current", "(", "$", "source_parts", ")", ";", "// Is this relative to the public dir?", "$", "path", "=", "'/public/'", ".", "ltrim", "(", "end", "(", "$", "source_parts", ")", ",", "'/'", ")", ";", "if", "(", "'/'", "===", "substr", "(", "end", "(", "$", "source_parts", ")", ",", "0", ",", "1", ")", ")", "{", "$", "path", "=", "end", "(", "$", "source_parts", ")", ";", "}", "// Check local cache first.", "if", "(", "array_key_exists", "(", "$", "package_name", ",", "static", "::", "$", "cached_paths", ")", ")", "{", "return", "static", "::", "$", "cached_paths", "[", "$", "package_name", "]", ".", "$", "path", ";", "}", "$", "finder", "=", "\\", "Symfony", "\\", "Component", "\\", "Finder", "\\", "Finder", "::", "create", "(", ")", ";", "// Try to find in workbench, first.", "$", "workbench", "=", "base_path", "(", ")", ".", "'/workbench'", ";", "if", "(", "file_exists", "(", "$", "workbench", ".", "'/'", ".", "$", "package_name", ".", "$", "path", ")", ")", "{", "return", "$", "workbench", ".", "'/'", ".", "$", "package_name", ".", "$", "path", ";", "}", "// Use package path.", "$", "vendor", "=", "base_path", "(", ")", ".", "'/vendor'", ";", "return", "$", "vendor", ".", "'/'", ".", "$", "package_name", ".", "$", "path", ";", "}" ]
Get the full path to the given asset source. Will try to load from a package/workbench if prefixed with: "{package_name}::". @param string $source Asset source. @return string
[ "Get", "the", "full", "path", "to", "the", "given", "asset", "source", ".", "Will", "try", "to", "load", "from", "a", "package", "/", "workbench", "if", "prefixed", "with", ":", "{", "package_name", "}", "::", "." ]
train
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L385-L416
mmanos/laravel-casset
src/Mmanos/Casset/Container.php
Container.publicPath
public function publicPath(array $asset) { $path = $this->path($asset['source']); $is_public = (bool) stristr($path, $this->public_path); $compiled_exts = array('less'); if ($is_public && !in_array($asset['ext'], $compiled_exts)) { return $path; } $cache_path = $this->cache_path . '/' . str_replace(array('/', '::'), '-', $asset['source']); $cache_path .= ('less' === $asset['ext']) ? '.css' : ''; return $cache_path; }
php
public function publicPath(array $asset) { $path = $this->path($asset['source']); $is_public = (bool) stristr($path, $this->public_path); $compiled_exts = array('less'); if ($is_public && !in_array($asset['ext'], $compiled_exts)) { return $path; } $cache_path = $this->cache_path . '/' . str_replace(array('/', '::'), '-', $asset['source']); $cache_path .= ('less' === $asset['ext']) ? '.css' : ''; return $cache_path; }
[ "public", "function", "publicPath", "(", "array", "$", "asset", ")", "{", "$", "path", "=", "$", "this", "->", "path", "(", "$", "asset", "[", "'source'", "]", ")", ";", "$", "is_public", "=", "(", "bool", ")", "stristr", "(", "$", "path", ",", "$", "this", "->", "public_path", ")", ";", "$", "compiled_exts", "=", "array", "(", "'less'", ")", ";", "if", "(", "$", "is_public", "&&", "!", "in_array", "(", "$", "asset", "[", "'ext'", "]", ",", "$", "compiled_exts", ")", ")", "{", "return", "$", "path", ";", "}", "$", "cache_path", "=", "$", "this", "->", "cache_path", ".", "'/'", ".", "str_replace", "(", "array", "(", "'/'", ",", "'::'", ")", ",", "'-'", ",", "$", "asset", "[", "'source'", "]", ")", ";", "$", "cache_path", ".=", "(", "'less'", "===", "$", "asset", "[", "'ext'", "]", ")", "?", "'.css'", ":", "''", ";", "return", "$", "cache_path", ";", "}" ]
Return the public path to the given asset. If the file is not in the public directory, or if it needs to be compiled (less, etc...), then the public cache path is returned. @param array $asset Asset array. @return string
[ "Return", "the", "public", "path", "to", "the", "given", "asset", ".", "If", "the", "file", "is", "not", "in", "the", "public", "directory", "or", "if", "it", "needs", "to", "be", "compiled", "(", "less", "etc", "...", ")", "then", "the", "public", "cache", "path", "is", "returned", "." ]
train
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L428-L445
mmanos/laravel-casset
src/Mmanos/Casset/Container.php
Container.needsProcessing
public function needsProcessing(array $asset) { if (isset(static::$needs_processing[$asset['source']])) { return static::$needs_processing[$asset['source']]; } $path = $this->path($asset['source']); $is_public = (bool) stristr($path, $this->public_path); $compiled_exts = array('less'); // Any dependencies that need processing? $dependencies = isset($asset['dependencies']) ? $asset['dependencies'] : array(); $dependencies = array_unique(array_merge(array_get($this->dependencies, $asset['ext'], array()), $dependencies)); if (!empty($dependencies)) { foreach ($dependencies as $dep_source) { if (!empty(static::$needs_processing[$dep_source])) { return static::$needs_processing[$asset['source']] = true; } } } // This file does not require processing. if ($is_public && !in_array($asset['ext'], $compiled_exts)) { return static::$needs_processing[$asset['source']] = false; } $cache_path = $this->publicPath($asset); // Does file exist? if (!File::exists($cache_path)) { return static::$needs_processing[$asset['source']] = true; } // Is cached file newer than the original? if (File::lastModified($cache_path) >= File::lastModified($path)) { return static::$needs_processing[$asset['source']] = false; } // Check md5 to see if content is the same. if ($f = fopen($cache_path, 'r')) { $line = (string) fgets($f); fclose($f); if (false !== strstr($line, '*/')) { $md5 = trim(str_replace(array('/*', '*/'), '', $line)); if (32 == strlen($md5)) { $file_md5 = md5_file($path); // Skip compiling and touch existing file. if ($file_md5 === $md5) { touch($cache_path); return false; } } } } return static::$needs_processing[$asset['source']] = true; }
php
public function needsProcessing(array $asset) { if (isset(static::$needs_processing[$asset['source']])) { return static::$needs_processing[$asset['source']]; } $path = $this->path($asset['source']); $is_public = (bool) stristr($path, $this->public_path); $compiled_exts = array('less'); // Any dependencies that need processing? $dependencies = isset($asset['dependencies']) ? $asset['dependencies'] : array(); $dependencies = array_unique(array_merge(array_get($this->dependencies, $asset['ext'], array()), $dependencies)); if (!empty($dependencies)) { foreach ($dependencies as $dep_source) { if (!empty(static::$needs_processing[$dep_source])) { return static::$needs_processing[$asset['source']] = true; } } } // This file does not require processing. if ($is_public && !in_array($asset['ext'], $compiled_exts)) { return static::$needs_processing[$asset['source']] = false; } $cache_path = $this->publicPath($asset); // Does file exist? if (!File::exists($cache_path)) { return static::$needs_processing[$asset['source']] = true; } // Is cached file newer than the original? if (File::lastModified($cache_path) >= File::lastModified($path)) { return static::$needs_processing[$asset['source']] = false; } // Check md5 to see if content is the same. if ($f = fopen($cache_path, 'r')) { $line = (string) fgets($f); fclose($f); if (false !== strstr($line, '*/')) { $md5 = trim(str_replace(array('/*', '*/'), '', $line)); if (32 == strlen($md5)) { $file_md5 = md5_file($path); // Skip compiling and touch existing file. if ($file_md5 === $md5) { touch($cache_path); return false; } } } } return static::$needs_processing[$asset['source']] = true; }
[ "public", "function", "needsProcessing", "(", "array", "$", "asset", ")", "{", "if", "(", "isset", "(", "static", "::", "$", "needs_processing", "[", "$", "asset", "[", "'source'", "]", "]", ")", ")", "{", "return", "static", "::", "$", "needs_processing", "[", "$", "asset", "[", "'source'", "]", "]", ";", "}", "$", "path", "=", "$", "this", "->", "path", "(", "$", "asset", "[", "'source'", "]", ")", ";", "$", "is_public", "=", "(", "bool", ")", "stristr", "(", "$", "path", ",", "$", "this", "->", "public_path", ")", ";", "$", "compiled_exts", "=", "array", "(", "'less'", ")", ";", "// Any dependencies that need processing?", "$", "dependencies", "=", "isset", "(", "$", "asset", "[", "'dependencies'", "]", ")", "?", "$", "asset", "[", "'dependencies'", "]", ":", "array", "(", ")", ";", "$", "dependencies", "=", "array_unique", "(", "array_merge", "(", "array_get", "(", "$", "this", "->", "dependencies", ",", "$", "asset", "[", "'ext'", "]", ",", "array", "(", ")", ")", ",", "$", "dependencies", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "dependencies", ")", ")", "{", "foreach", "(", "$", "dependencies", "as", "$", "dep_source", ")", "{", "if", "(", "!", "empty", "(", "static", "::", "$", "needs_processing", "[", "$", "dep_source", "]", ")", ")", "{", "return", "static", "::", "$", "needs_processing", "[", "$", "asset", "[", "'source'", "]", "]", "=", "true", ";", "}", "}", "}", "// This file does not require processing.", "if", "(", "$", "is_public", "&&", "!", "in_array", "(", "$", "asset", "[", "'ext'", "]", ",", "$", "compiled_exts", ")", ")", "{", "return", "static", "::", "$", "needs_processing", "[", "$", "asset", "[", "'source'", "]", "]", "=", "false", ";", "}", "$", "cache_path", "=", "$", "this", "->", "publicPath", "(", "$", "asset", ")", ";", "// Does file exist?", "if", "(", "!", "File", "::", "exists", "(", "$", "cache_path", ")", ")", "{", "return", "static", "::", "$", "needs_processing", "[", "$", "asset", "[", "'source'", "]", "]", "=", "true", ";", "}", "// Is cached file newer than the original?", "if", "(", "File", "::", "lastModified", "(", "$", "cache_path", ")", ">=", "File", "::", "lastModified", "(", "$", "path", ")", ")", "{", "return", "static", "::", "$", "needs_processing", "[", "$", "asset", "[", "'source'", "]", "]", "=", "false", ";", "}", "// Check md5 to see if content is the same.", "if", "(", "$", "f", "=", "fopen", "(", "$", "cache_path", ",", "'r'", ")", ")", "{", "$", "line", "=", "(", "string", ")", "fgets", "(", "$", "f", ")", ";", "fclose", "(", "$", "f", ")", ";", "if", "(", "false", "!==", "strstr", "(", "$", "line", ",", "'*/'", ")", ")", "{", "$", "md5", "=", "trim", "(", "str_replace", "(", "array", "(", "'/*'", ",", "'*/'", ")", ",", "''", ",", "$", "line", ")", ")", ";", "if", "(", "32", "==", "strlen", "(", "$", "md5", ")", ")", "{", "$", "file_md5", "=", "md5_file", "(", "$", "path", ")", ";", "// Skip compiling and touch existing file.", "if", "(", "$", "file_md5", "===", "$", "md5", ")", "{", "touch", "(", "$", "cache_path", ")", ";", "return", "false", ";", "}", "}", "}", "}", "return", "static", "::", "$", "needs_processing", "[", "$", "asset", "[", "'source'", "]", "]", "=", "true", ";", "}" ]
Returns whether or not a file needs to be processed. @param array $asset Asset array. @return boolean
[ "Returns", "whether", "or", "not", "a", "file", "needs", "to", "be", "processed", "." ]
train
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L454-L513
mmanos/laravel-casset
src/Mmanos/Casset/Container.php
Container.process
public function process(array $asset) { // Any dependencies that need processing? $dependencies = isset($asset['dependencies']) ? $asset['dependencies'] : array(); $dependencies = array_unique(array_merge(array_get($this->dependencies, $asset['ext'], array()), $dependencies)); if (!empty($dependencies)) { foreach ($dependencies as $dep_source) { if ($asset['source'] == $dep_source) { continue; } $this->process(array( 'source' => $dep_source, 'ext' => pathinfo($dep_source, PATHINFO_EXTENSION), )); } } $path = $this->path($asset['source']); $public_path = $this->publicPath($asset); if (empty(static::$processed[$asset['source']]) && $this->needsProcessing($asset)) { if (File::exists($path)) { File::put($public_path, $this->compile($path)); } } $asset['path'] = $public_path; $asset['url'] = str_ireplace($this->public_path, '', $public_path); static::$processed[$asset['source']] = true; return $asset; }
php
public function process(array $asset) { // Any dependencies that need processing? $dependencies = isset($asset['dependencies']) ? $asset['dependencies'] : array(); $dependencies = array_unique(array_merge(array_get($this->dependencies, $asset['ext'], array()), $dependencies)); if (!empty($dependencies)) { foreach ($dependencies as $dep_source) { if ($asset['source'] == $dep_source) { continue; } $this->process(array( 'source' => $dep_source, 'ext' => pathinfo($dep_source, PATHINFO_EXTENSION), )); } } $path = $this->path($asset['source']); $public_path = $this->publicPath($asset); if (empty(static::$processed[$asset['source']]) && $this->needsProcessing($asset)) { if (File::exists($path)) { File::put($public_path, $this->compile($path)); } } $asset['path'] = $public_path; $asset['url'] = str_ireplace($this->public_path, '', $public_path); static::$processed[$asset['source']] = true; return $asset; }
[ "public", "function", "process", "(", "array", "$", "asset", ")", "{", "// Any dependencies that need processing?", "$", "dependencies", "=", "isset", "(", "$", "asset", "[", "'dependencies'", "]", ")", "?", "$", "asset", "[", "'dependencies'", "]", ":", "array", "(", ")", ";", "$", "dependencies", "=", "array_unique", "(", "array_merge", "(", "array_get", "(", "$", "this", "->", "dependencies", ",", "$", "asset", "[", "'ext'", "]", ",", "array", "(", ")", ")", ",", "$", "dependencies", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "dependencies", ")", ")", "{", "foreach", "(", "$", "dependencies", "as", "$", "dep_source", ")", "{", "if", "(", "$", "asset", "[", "'source'", "]", "==", "$", "dep_source", ")", "{", "continue", ";", "}", "$", "this", "->", "process", "(", "array", "(", "'source'", "=>", "$", "dep_source", ",", "'ext'", "=>", "pathinfo", "(", "$", "dep_source", ",", "PATHINFO_EXTENSION", ")", ",", ")", ")", ";", "}", "}", "$", "path", "=", "$", "this", "->", "path", "(", "$", "asset", "[", "'source'", "]", ")", ";", "$", "public_path", "=", "$", "this", "->", "publicPath", "(", "$", "asset", ")", ";", "if", "(", "empty", "(", "static", "::", "$", "processed", "[", "$", "asset", "[", "'source'", "]", "]", ")", "&&", "$", "this", "->", "needsProcessing", "(", "$", "asset", ")", ")", "{", "if", "(", "File", "::", "exists", "(", "$", "path", ")", ")", "{", "File", "::", "put", "(", "$", "public_path", ",", "$", "this", "->", "compile", "(", "$", "path", ")", ")", ";", "}", "}", "$", "asset", "[", "'path'", "]", "=", "$", "public_path", ";", "$", "asset", "[", "'url'", "]", "=", "str_ireplace", "(", "$", "this", "->", "public_path", ",", "''", ",", "$", "public_path", ")", ";", "static", "::", "$", "processed", "[", "$", "asset", "[", "'source'", "]", "]", "=", "true", ";", "return", "$", "asset", ";", "}" ]
Process the given asset. Make public, if needed. Compile, if needed (less, etc...). Returns a valid asset. @param array $asset Asset array. @return array [url, attributes]
[ "Process", "the", "given", "asset", ".", "Make", "public", "if", "needed", ".", "Compile", "if", "needed", "(", "less", "etc", "...", ")", "." ]
train
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L526-L559
mmanos/laravel-casset
src/Mmanos/Casset/Container.php
Container.compile
public function compile($path) { switch (pathinfo($path, PATHINFO_EXTENSION)) { case 'less': $less = new Less_Parser; $content = '/*' . md5(File::get($path)) . "*/\n" . $less->parseFile($path)->getCss(); break; default: $content = File::get($path); } return $content; }
php
public function compile($path) { switch (pathinfo($path, PATHINFO_EXTENSION)) { case 'less': $less = new Less_Parser; $content = '/*' . md5(File::get($path)) . "*/\n" . $less->parseFile($path)->getCss(); break; default: $content = File::get($path); } return $content; }
[ "public", "function", "compile", "(", "$", "path", ")", "{", "switch", "(", "pathinfo", "(", "$", "path", ",", "PATHINFO_EXTENSION", ")", ")", "{", "case", "'less'", ":", "$", "less", "=", "new", "Less_Parser", ";", "$", "content", "=", "'/*'", ".", "md5", "(", "File", "::", "get", "(", "$", "path", ")", ")", ".", "\"*/\\n\"", ".", "$", "less", "->", "parseFile", "(", "$", "path", ")", "->", "getCss", "(", ")", ";", "break", ";", "default", ":", "$", "content", "=", "File", "::", "get", "(", "$", "path", ")", ";", "}", "return", "$", "content", ";", "}" ]
Compile and return the content for the given asset according to it's extension. @param string $path Asset path. @return string
[ "Compile", "and", "return", "the", "content", "for", "the", "given", "asset", "according", "to", "it", "s", "extension", "." ]
train
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L569-L583
mmanos/laravel-casset
src/Mmanos/Casset/Container.php
Container.combine
public function combine(array $assets, $type) { $paths = array(); $lastmod = 0; foreach ($assets as $asset) { $paths[] = $asset['path']; $mod = File::lastModified($asset['path']); if ($mod > $lastmod) { $lastmod = $mod; } } $file = $this->cache_path . '/casset-' . md5(implode(',', $paths) . $lastmod) . '-' . $this->name; $file .= ('script' === $type) ? '.js' : '.css'; $combine = false; if (!File::exists($file)) { $combine = true; } else if (File::lastModified($file) < $lastmod) { $combine = true; } if ($combine) { $content = ''; foreach ($assets as $asset) { if (!File::exists($asset['path'])) { continue; } $c = File::get($asset['path']); if ($this->minify && !(stripos($asset['source'], '.min') || stripos($asset['source'], '-min') ) ) { switch ($type) { case 'style': $c = Compressors\Css::process($c); break; case 'script': $c = Compressors\Js::minify($c); break; } } $content .= "/* {$asset['source']} */\n$c\n\n"; } File::put($file, $content); } return array(array( 'path' => $file, 'attributes' => array(), 'url' => str_ireplace($this->public_path, '', $file), )); }
php
public function combine(array $assets, $type) { $paths = array(); $lastmod = 0; foreach ($assets as $asset) { $paths[] = $asset['path']; $mod = File::lastModified($asset['path']); if ($mod > $lastmod) { $lastmod = $mod; } } $file = $this->cache_path . '/casset-' . md5(implode(',', $paths) . $lastmod) . '-' . $this->name; $file .= ('script' === $type) ? '.js' : '.css'; $combine = false; if (!File::exists($file)) { $combine = true; } else if (File::lastModified($file) < $lastmod) { $combine = true; } if ($combine) { $content = ''; foreach ($assets as $asset) { if (!File::exists($asset['path'])) { continue; } $c = File::get($asset['path']); if ($this->minify && !(stripos($asset['source'], '.min') || stripos($asset['source'], '-min') ) ) { switch ($type) { case 'style': $c = Compressors\Css::process($c); break; case 'script': $c = Compressors\Js::minify($c); break; } } $content .= "/* {$asset['source']} */\n$c\n\n"; } File::put($file, $content); } return array(array( 'path' => $file, 'attributes' => array(), 'url' => str_ireplace($this->public_path, '', $file), )); }
[ "public", "function", "combine", "(", "array", "$", "assets", ",", "$", "type", ")", "{", "$", "paths", "=", "array", "(", ")", ";", "$", "lastmod", "=", "0", ";", "foreach", "(", "$", "assets", "as", "$", "asset", ")", "{", "$", "paths", "[", "]", "=", "$", "asset", "[", "'path'", "]", ";", "$", "mod", "=", "File", "::", "lastModified", "(", "$", "asset", "[", "'path'", "]", ")", ";", "if", "(", "$", "mod", ">", "$", "lastmod", ")", "{", "$", "lastmod", "=", "$", "mod", ";", "}", "}", "$", "file", "=", "$", "this", "->", "cache_path", ".", "'/casset-'", ".", "md5", "(", "implode", "(", "','", ",", "$", "paths", ")", ".", "$", "lastmod", ")", ".", "'-'", ".", "$", "this", "->", "name", ";", "$", "file", ".=", "(", "'script'", "===", "$", "type", ")", "?", "'.js'", ":", "'.css'", ";", "$", "combine", "=", "false", ";", "if", "(", "!", "File", "::", "exists", "(", "$", "file", ")", ")", "{", "$", "combine", "=", "true", ";", "}", "else", "if", "(", "File", "::", "lastModified", "(", "$", "file", ")", "<", "$", "lastmod", ")", "{", "$", "combine", "=", "true", ";", "}", "if", "(", "$", "combine", ")", "{", "$", "content", "=", "''", ";", "foreach", "(", "$", "assets", "as", "$", "asset", ")", "{", "if", "(", "!", "File", "::", "exists", "(", "$", "asset", "[", "'path'", "]", ")", ")", "{", "continue", ";", "}", "$", "c", "=", "File", "::", "get", "(", "$", "asset", "[", "'path'", "]", ")", ";", "if", "(", "$", "this", "->", "minify", "&&", "!", "(", "stripos", "(", "$", "asset", "[", "'source'", "]", ",", "'.min'", ")", "||", "stripos", "(", "$", "asset", "[", "'source'", "]", ",", "'-min'", ")", ")", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "'style'", ":", "$", "c", "=", "Compressors", "\\", "Css", "::", "process", "(", "$", "c", ")", ";", "break", ";", "case", "'script'", ":", "$", "c", "=", "Compressors", "\\", "Js", "::", "minify", "(", "$", "c", ")", ";", "break", ";", "}", "}", "$", "content", ".=", "\"/* {$asset['source']} */\\n$c\\n\\n\"", ";", "}", "File", "::", "put", "(", "$", "file", ",", "$", "content", ")", ";", "}", "return", "array", "(", "array", "(", "'path'", "=>", "$", "file", ",", "'attributes'", "=>", "array", "(", ")", ",", "'url'", "=>", "str_ireplace", "(", "$", "this", "->", "public_path", ",", "''", ",", "$", "file", ")", ",", ")", ")", ";", "}" ]
Combine the given array of assets. Minify, if enabled. Returns new array containing one asset. @param array $assets Array of assets. @param string $type File type (script, style). @return array
[ "Combine", "the", "given", "array", "of", "assets", ".", "Minify", "if", "enabled", ".", "Returns", "new", "array", "containing", "one", "asset", "." ]
train
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L594-L654
pvsaintpe/yii2-grid
components/ColumnTrait.php
ColumnTrait.fetchContentOptions
protected function fetchContentOptions($model, $key, $index) { $options = parent::fetchContentOptions($model, $key, $index); if (!empty($this->columnOptions)) { foreach ($this->columnOptions as $option => $value) { $options['data-column-' . $option] = $value; } } return $options; }
php
protected function fetchContentOptions($model, $key, $index) { $options = parent::fetchContentOptions($model, $key, $index); if (!empty($this->columnOptions)) { foreach ($this->columnOptions as $option => $value) { $options['data-column-' . $option] = $value; } } return $options; }
[ "protected", "function", "fetchContentOptions", "(", "$", "model", ",", "$", "key", ",", "$", "index", ")", "{", "$", "options", "=", "parent", "::", "fetchContentOptions", "(", "$", "model", ",", "$", "key", ",", "$", "index", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "columnOptions", ")", ")", "{", "foreach", "(", "$", "this", "->", "columnOptions", "as", "$", "option", "=>", "$", "value", ")", "{", "$", "options", "[", "'data-column-'", ".", "$", "option", "]", "=", "$", "value", ";", "}", "}", "return", "$", "options", ";", "}" ]
Parses and fetches updated content options for grid visibility and format @param mixed $model the data model being rendered @param mixed $key the key associated with the data model @param integer $index the zero-based index of the data item among the item array returned by [[GridView::dataProvider]]. @return array
[ "Parses", "and", "fetches", "updated", "content", "options", "for", "grid", "visibility", "and", "format" ]
train
https://github.com/pvsaintpe/yii2-grid/blob/8c91a1737412070775dc3fbee6a89384a67ca2cf/components/ColumnTrait.php#L41-L52
ShaoZeMing/laravel-merchant
src/Controllers/ModelForm.php
ModelForm.destroy
public function destroy($id) { if ($this->form()->destroy($id)) { return response()->json([ 'status' => true, 'message' => trans('merchant.delete_succeeded'), ]); } else { return response()->json([ 'status' => false, 'message' => trans('merchant.delete_failed'), ]); } }
php
public function destroy($id) { if ($this->form()->destroy($id)) { return response()->json([ 'status' => true, 'message' => trans('merchant.delete_succeeded'), ]); } else { return response()->json([ 'status' => false, 'message' => trans('merchant.delete_failed'), ]); } }
[ "public", "function", "destroy", "(", "$", "id", ")", "{", "if", "(", "$", "this", "->", "form", "(", ")", "->", "destroy", "(", "$", "id", ")", ")", "{", "return", "response", "(", ")", "->", "json", "(", "[", "'status'", "=>", "true", ",", "'message'", "=>", "trans", "(", "'merchant.delete_succeeded'", ")", ",", "]", ")", ";", "}", "else", "{", "return", "response", "(", ")", "->", "json", "(", "[", "'status'", "=>", "false", ",", "'message'", "=>", "trans", "(", "'merchant.delete_failed'", ")", ",", "]", ")", ";", "}", "}" ]
Remove the specified resource from storage. @param int $id @return \Illuminate\Http\Response
[ "Remove", "the", "specified", "resource", "from", "storage", "." ]
train
https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Controllers/ModelForm.php#L38-L51
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/Builder/AssemblerFactory.php
AssemblerFactory.get
public function get($criteria) { foreach (array_merge($this->assemblers, $this->fallbackAssemblers) as $candidate) { $matcher = $candidate['matcher']; if ($matcher($criteria) === true) { return $candidate['assembler']; } } return null; }
php
public function get($criteria) { foreach (array_merge($this->assemblers, $this->fallbackAssemblers) as $candidate) { $matcher = $candidate['matcher']; if ($matcher($criteria) === true) { return $candidate['assembler']; } } return null; }
[ "public", "function", "get", "(", "$", "criteria", ")", "{", "foreach", "(", "array_merge", "(", "$", "this", "->", "assemblers", ",", "$", "this", "->", "fallbackAssemblers", ")", "as", "$", "candidate", ")", "{", "$", "matcher", "=", "$", "candidate", "[", "'matcher'", "]", ";", "if", "(", "$", "matcher", "(", "$", "criteria", ")", "===", "true", ")", "{", "return", "$", "candidate", "[", "'assembler'", "]", ";", "}", "}", "return", "null", ";", "}" ]
Retrieves a matching Assembler based on the provided criteria or null if none was found. @param mixed $criteria @return AssemblerInterface|null
[ "Retrieves", "a", "matching", "Assembler", "based", "on", "the", "provided", "criteria", "or", "null", "if", "none", "was", "found", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/Builder/AssemblerFactory.php#L67-L77
WScore/Validation
src/Utils/ValueArray.php
ValueArray.getValue
public function getValue() { $values = []; foreach($this->values as $key => $value) { $values[$key] = $value->getValue(); } return $values; }
php
public function getValue() { $values = []; foreach($this->values as $key => $value) { $values[$key] = $value->getValue(); } return $values; }
[ "public", "function", "getValue", "(", ")", "{", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "values", "[", "$", "key", "]", "=", "$", "value", "->", "getValue", "(", ")", ";", "}", "return", "$", "values", ";", "}" ]
returns the value. the value maybe invalid. @return mixed
[ "returns", "the", "value", ".", "the", "value", "maybe", "invalid", "." ]
train
https://github.com/WScore/Validation/blob/25c0dca37d624bb0bb22f8e79ba54db2f69e0950/src/Utils/ValueArray.php#L50-L57
WScore/Validation
src/Utils/ValueArray.php
ValueArray.getValidValue
public function getValidValue() { $values = []; foreach($this->values as $key => $value) { if ($this->isValidValue($value)) { $values[$key] = $value->getValidValue(); } } return $values; }
php
public function getValidValue() { $values = []; foreach($this->values as $key => $value) { if ($this->isValidValue($value)) { $values[$key] = $value->getValidValue(); } } return $values; }
[ "public", "function", "getValidValue", "(", ")", "{", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "this", "->", "isValidValue", "(", "$", "value", ")", ")", "{", "$", "values", "[", "$", "key", "]", "=", "$", "value", "->", "getValidValue", "(", ")", ";", "}", "}", "return", "$", "values", ";", "}" ]
return the validated value. returns false if validation fails. @return bool|mixed
[ "return", "the", "validated", "value", ".", "returns", "false", "if", "validation", "fails", "." ]
train
https://github.com/WScore/Validation/blob/25c0dca37d624bb0bb22f8e79ba54db2f69e0950/src/Utils/ValueArray.php#L76-L85
WScore/Validation
src/Utils/ValueArray.php
ValueArray.message
public function message() { $messages = []; foreach($this->values as $key => $value) { if ($value->fails()) { $messages[$key] = $value->message(); } } return $messages; }
php
public function message() { $messages = []; foreach($this->values as $key => $value) { if ($value->fails()) { $messages[$key] = $value->message(); } } return $messages; }
[ "public", "function", "message", "(", ")", "{", "$", "messages", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "->", "fails", "(", ")", ")", "{", "$", "messages", "[", "$", "key", "]", "=", "$", "value", "->", "message", "(", ")", ";", "}", "}", "return", "$", "messages", ";", "}" ]
gets message regardless of the error state of this ValueTO. use this message ONLY WHEN valueTO is error. @return string|array
[ "gets", "message", "regardless", "of", "the", "error", "state", "of", "this", "ValueTO", ".", "use", "this", "message", "ONLY", "WHEN", "valueTO", "is", "error", "." ]
train
https://github.com/WScore/Validation/blob/25c0dca37d624bb0bb22f8e79ba54db2f69e0950/src/Utils/ValueArray.php#L112-L121
alexandresalome/journal-extension
src/Behat/JournalExtension/Formatter/Driver/MinkDriver.php
MinkDriver.getScreenshot
public function getScreenshot() { $driver = $this->mink->getSession()->getDriver(); if ($driver instanceof SeleniumDriver) { $out = $driver->getBrowser()->captureEntirePageScreenshotToString(""); $out = str_replace("\n", "", $out); return base64_decode($out); } elseif ($driver instanceof Selenium2Driver) { return base64_decode($driver->getWebDriverSession()->screenshot()); } elseif($driver instanceof WebkitDriver) { return $driver->getScreenshot(); } return; }
php
public function getScreenshot() { $driver = $this->mink->getSession()->getDriver(); if ($driver instanceof SeleniumDriver) { $out = $driver->getBrowser()->captureEntirePageScreenshotToString(""); $out = str_replace("\n", "", $out); return base64_decode($out); } elseif ($driver instanceof Selenium2Driver) { return base64_decode($driver->getWebDriverSession()->screenshot()); } elseif($driver instanceof WebkitDriver) { return $driver->getScreenshot(); } return; }
[ "public", "function", "getScreenshot", "(", ")", "{", "$", "driver", "=", "$", "this", "->", "mink", "->", "getSession", "(", ")", "->", "getDriver", "(", ")", ";", "if", "(", "$", "driver", "instanceof", "SeleniumDriver", ")", "{", "$", "out", "=", "$", "driver", "->", "getBrowser", "(", ")", "->", "captureEntirePageScreenshotToString", "(", "\"\"", ")", ";", "$", "out", "=", "str_replace", "(", "\"\\n\"", ",", "\"\"", ",", "$", "out", ")", ";", "return", "base64_decode", "(", "$", "out", ")", ";", "}", "elseif", "(", "$", "driver", "instanceof", "Selenium2Driver", ")", "{", "return", "base64_decode", "(", "$", "driver", "->", "getWebDriverSession", "(", ")", "->", "screenshot", "(", ")", ")", ";", "}", "elseif", "(", "$", "driver", "instanceof", "WebkitDriver", ")", "{", "return", "$", "driver", "->", "getScreenshot", "(", ")", ";", "}", "return", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/alexandresalome/journal-extension/blob/de87304abb52abfa6905f1b83d2e35cc7bc52c0d/src/Behat/JournalExtension/Formatter/Driver/MinkDriver.php#L22-L38
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack/lfu_meta_data.php
ezcCacheStackLfuMetaData.addItemToReplacementData
public function addItemToReplacementData( $itemId ) { if ( !isset( $this->replacementData[$itemId] ) ) { $this->replacementData[$itemId] = 0; } ++$this->replacementData[$itemId]; }
php
public function addItemToReplacementData( $itemId ) { if ( !isset( $this->replacementData[$itemId] ) ) { $this->replacementData[$itemId] = 0; } ++$this->replacementData[$itemId]; }
[ "public", "function", "addItemToReplacementData", "(", "$", "itemId", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "replacementData", "[", "$", "itemId", "]", ")", ")", "{", "$", "this", "->", "replacementData", "[", "$", "itemId", "]", "=", "0", ";", "}", "++", "$", "this", "->", "replacementData", "[", "$", "itemId", "]", ";", "}" ]
Adds the given $itemId to the replacement data. Initializes the entry for $itemId with 1, if it does not exist, yet. Increments the entry by 1, if it does exist. @param string $itemId
[ "Adds", "the", "given", "$itemId", "to", "the", "replacement", "data", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack/lfu_meta_data.php#L32-L39
gregorybesson/PlaygroundCms
src/Mapper/Dynablock.php
Dynablock.findByDynarea
public function findByDynarea($dynarea) { $er = $this->em->getRepository($this->options->getDynablockEntityClass()); $entities = $er->findBy(array('dynarea' => $dynarea), array('position' => 'ASC')); return $entities; }
php
public function findByDynarea($dynarea) { $er = $this->em->getRepository($this->options->getDynablockEntityClass()); $entities = $er->findBy(array('dynarea' => $dynarea), array('position' => 'ASC')); return $entities; }
[ "public", "function", "findByDynarea", "(", "$", "dynarea", ")", "{", "$", "er", "=", "$", "this", "->", "em", "->", "getRepository", "(", "$", "this", "->", "options", "->", "getDynablockEntityClass", "(", ")", ")", ";", "$", "entities", "=", "$", "er", "->", "findBy", "(", "array", "(", "'dynarea'", "=>", "$", "dynarea", ")", ",", "array", "(", "'position'", "=>", "'ASC'", ")", ")", ";", "return", "$", "entities", ";", "}" ]
Find entity by integer id or string identifier @param $identifier @return object @throws \Exception
[ "Find", "entity", "by", "integer", "id", "or", "string", "identifier" ]
train
https://github.com/gregorybesson/PlaygroundCms/blob/e929a283f2a6e82d4f248c930f7aa454ce20cbc3/src/Mapper/Dynablock.php#L72-L79
gregorybesson/PlaygroundCms
src/Mapper/Dynablock.php
Dynablock.find
public function find($identifier) { if (is_int($identifier)) { $entity = $this->findById($identifier); } elseif (is_string($identifier)) { $entity = $this->findByIdentifier($identifier); } else { throw new \Exception('Wrong block identifier provided.'); } return $entity; }
php
public function find($identifier) { if (is_int($identifier)) { $entity = $this->findById($identifier); } elseif (is_string($identifier)) { $entity = $this->findByIdentifier($identifier); } else { throw new \Exception('Wrong block identifier provided.'); } return $entity; }
[ "public", "function", "find", "(", "$", "identifier", ")", "{", "if", "(", "is_int", "(", "$", "identifier", ")", ")", "{", "$", "entity", "=", "$", "this", "->", "findById", "(", "$", "identifier", ")", ";", "}", "elseif", "(", "is_string", "(", "$", "identifier", ")", ")", "{", "$", "entity", "=", "$", "this", "->", "findByIdentifier", "(", "$", "identifier", ")", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "'Wrong block identifier provided.'", ")", ";", "}", "return", "$", "entity", ";", "}" ]
Find entity by integer id or string identifier @param $identifier @return object @throws \Exception
[ "Find", "entity", "by", "integer", "id", "or", "string", "identifier" ]
train
https://github.com/gregorybesson/PlaygroundCms/blob/e929a283f2a6e82d4f248c930f7aa454ce20cbc3/src/Mapper/Dynablock.php#L104-L115
zhouyl/mellivora
Mellivora/Http/Request.php
Request.fullUrlWithQuery
public function fullUrlWithQuery(array $query) { parse_str($this->getUri()->getQuery(), $queryParts); return (string) $this->getUri() ->withQuery(http_build_query($query + $queryParts)); }
php
public function fullUrlWithQuery(array $query) { parse_str($this->getUri()->getQuery(), $queryParts); return (string) $this->getUri() ->withQuery(http_build_query($query + $queryParts)); }
[ "public", "function", "fullUrlWithQuery", "(", "array", "$", "query", ")", "{", "parse_str", "(", "$", "this", "->", "getUri", "(", ")", "->", "getQuery", "(", ")", ",", "$", "queryParts", ")", ";", "return", "(", "string", ")", "$", "this", "->", "getUri", "(", ")", "->", "withQuery", "(", "http_build_query", "(", "$", "query", "+", "$", "queryParts", ")", ")", ";", "}" ]
Get the full URL for the request with the added query string parameters. @param array $query @return string
[ "Get", "the", "full", "URL", "for", "the", "request", "with", "the", "added", "query", "string", "parameters", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Request.php#L85-L91
zhouyl/mellivora
Mellivora/Http/Request.php
Request.fullUrlIs
public function fullUrlIs() { $url = $this->fullUrl(); foreach (func_get_args() as $pattern) { if (Str::is($pattern, $url)) { return true; } } return false; }
php
public function fullUrlIs() { $url = $this->fullUrl(); foreach (func_get_args() as $pattern) { if (Str::is($pattern, $url)) { return true; } } return false; }
[ "public", "function", "fullUrlIs", "(", ")", "{", "$", "url", "=", "$", "this", "->", "fullUrl", "(", ")", ";", "foreach", "(", "func_get_args", "(", ")", "as", "$", "pattern", ")", "{", "if", "(", "Str", "::", "is", "(", "$", "pattern", ",", "$", "url", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Determine if the current request URL and query string matches a pattern. @return bool
[ "Determine", "if", "the", "current", "request", "URL", "and", "query", "string", "matches", "a", "pattern", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Request.php#L146-L157
zhouyl/mellivora
Mellivora/Http/Request.php
Request.getClientAddress
public function getClientAddress() { if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // When a HTTP request is proxied, some proxy server will add requester's // IP address to $_SERVER['HTTP_X_FORWARDED_FOR']. // As a request may go through several proxies, // $_SERVER['HTTP_X_FORWARDED_FOR'] can contain several IP addresses separated with comma. foreach (explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']) as $address) { $address = trim($address); // Skip RFC 1918 IP's 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 if (!preg_match('/^(?:10|172\.(?:1[6-9]|2\d|3[01])|192\.168)\./', $address)) { if (ip2long($address) !== false) { return $address; break; } } } } return Arr::get($_SERVER, 'HTTP_CLIENT_IP', $_SERVER['REMOTE_ADDR']); }
php
public function getClientAddress() { if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // When a HTTP request is proxied, some proxy server will add requester's // IP address to $_SERVER['HTTP_X_FORWARDED_FOR']. // As a request may go through several proxies, // $_SERVER['HTTP_X_FORWARDED_FOR'] can contain several IP addresses separated with comma. foreach (explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']) as $address) { $address = trim($address); // Skip RFC 1918 IP's 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 if (!preg_match('/^(?:10|172\.(?:1[6-9]|2\d|3[01])|192\.168)\./', $address)) { if (ip2long($address) !== false) { return $address; break; } } } } return Arr::get($_SERVER, 'HTTP_CLIENT_IP', $_SERVER['REMOTE_ADDR']); }
[ "public", "function", "getClientAddress", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_FOR'", "]", ")", ")", "{", "// When a HTTP request is proxied, some proxy server will add requester's", "// IP address to $_SERVER['HTTP_X_FORWARDED_FOR'].", "// As a request may go through several proxies,", "// $_SERVER['HTTP_X_FORWARDED_FOR'] can contain several IP addresses separated with comma.", "foreach", "(", "explode", "(", "','", ",", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_FOR'", "]", ")", "as", "$", "address", ")", "{", "$", "address", "=", "trim", "(", "$", "address", ")", ";", "// Skip RFC 1918 IP's 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16", "if", "(", "!", "preg_match", "(", "'/^(?:10|172\\.(?:1[6-9]|2\\d|3[01])|192\\.168)\\./'", ",", "$", "address", ")", ")", "{", "if", "(", "ip2long", "(", "$", "address", ")", "!==", "false", ")", "{", "return", "$", "address", ";", "break", ";", "}", "}", "}", "}", "return", "Arr", "::", "get", "(", "$", "_SERVER", ",", "'HTTP_CLIENT_IP'", ",", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ")", ";", "}" ]
Returns the client IP address. @return string
[ "Returns", "the", "client", "IP", "address", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Request.php#L194-L216
zhouyl/mellivora
Mellivora/Http/Request.php
Request.only
public function only($keys) { $keys = is_array($keys) ? $keys : func_get_args(); $results = []; $input = $this->all(); foreach ($keys as $key) { Arr::set($results, $key, data_get($input, $key)); } return $results; }
php
public function only($keys) { $keys = is_array($keys) ? $keys : func_get_args(); $results = []; $input = $this->all(); foreach ($keys as $key) { Arr::set($results, $key, data_get($input, $key)); } return $results; }
[ "public", "function", "only", "(", "$", "keys", ")", "{", "$", "keys", "=", "is_array", "(", "$", "keys", ")", "?", "$", "keys", ":", "func_get_args", "(", ")", ";", "$", "results", "=", "[", "]", ";", "$", "input", "=", "$", "this", "->", "all", "(", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "Arr", "::", "set", "(", "$", "results", ",", "$", "key", ",", "data_get", "(", "$", "input", ",", "$", "key", ")", ")", ";", "}", "return", "$", "results", ";", "}" ]
Get a subset containing the provided keys with values from the input data. @param array|mixed $keys @return array
[ "Get", "a", "subset", "containing", "the", "provided", "keys", "with", "values", "from", "the", "input", "data", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Request.php#L348-L361
zhouyl/mellivora
Mellivora/Http/Request.php
Request.query
public function query($key = null, $default = null) { $queries = $this->getQueryParams(); return is_null($key) ? $queries : data_get($queries, $key, $default); }
php
public function query($key = null, $default = null) { $queries = $this->getQueryParams(); return is_null($key) ? $queries : data_get($queries, $key, $default); }
[ "public", "function", "query", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "$", "queries", "=", "$", "this", "->", "getQueryParams", "(", ")", ";", "return", "is_null", "(", "$", "key", ")", "?", "$", "queries", ":", "data_get", "(", "$", "queries", ",", "$", "key", ",", "$", "default", ")", ";", "}" ]
Retrieve a query string item from the request. @param string $key @param null|array|string $default @return array|string
[ "Retrieve", "a", "query", "string", "item", "from", "the", "request", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Request.php#L402-L407
zhouyl/mellivora
Mellivora/Http/Request.php
Request.post
public function post($key = null, $default = null) { $posts = $this->getPostParams(); return is_null($key) ? $posts : data_get($posts, $key, $default); }
php
public function post($key = null, $default = null) { $posts = $this->getPostParams(); return is_null($key) ? $posts : data_get($posts, $key, $default); }
[ "public", "function", "post", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "$", "posts", "=", "$", "this", "->", "getPostParams", "(", ")", ";", "return", "is_null", "(", "$", "key", ")", "?", "$", "posts", ":", "data_get", "(", "$", "posts", ",", "$", "key", ",", "$", "default", ")", ";", "}" ]
Retrieve a post data item from the request. @param string $key @param null|array|string $default @return array|string
[ "Retrieve", "a", "post", "data", "item", "from", "the", "request", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Request.php#L417-L422
zhouyl/mellivora
Mellivora/Http/Request.php
Request.server
public function server($key = null, $default = null) { $servers = $this->getServerParams(); return is_null($key) ? $servers : data_get($servers, $key, $default); }
php
public function server($key = null, $default = null) { $servers = $this->getServerParams(); return is_null($key) ? $servers : data_get($servers, $key, $default); }
[ "public", "function", "server", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "$", "servers", "=", "$", "this", "->", "getServerParams", "(", ")", ";", "return", "is_null", "(", "$", "key", ")", "?", "$", "servers", ":", "data_get", "(", "$", "servers", ",", "$", "key", ",", "$", "default", ")", ";", "}" ]
Retrieve a server variable from the request. @param string $key @param null|array|string $default @return array|string
[ "Retrieve", "a", "server", "variable", "from", "the", "request", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Request.php#L432-L437
zhouyl/mellivora
Mellivora/Http/Request.php
Request.cookie
public function cookie($key = null, $default = null) { $cookies = $this->getCookieParams(); return is_null($key) ? $cookies : data_get($cookies, $key, $default); }
php
public function cookie($key = null, $default = null) { $cookies = $this->getCookieParams(); return is_null($key) ? $cookies : data_get($cookies, $key, $default); }
[ "public", "function", "cookie", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "$", "cookies", "=", "$", "this", "->", "getCookieParams", "(", ")", ";", "return", "is_null", "(", "$", "key", ")", "?", "$", "cookies", ":", "data_get", "(", "$", "cookies", ",", "$", "key", ",", "$", "default", ")", ";", "}" ]
Retrieve a cookie from the request. @param string $key @param null|array|string $default @return array|string
[ "Retrieve", "a", "cookie", "from", "the", "request", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Request.php#L447-L452
zhouyl/mellivora
Mellivora/Http/Request.php
Request.file
public function file($key = null, $default = null) { $files = $this->getUploadedFiles(); return is_null($key) ? $files : data_get($files, $key, $default); }
php
public function file($key = null, $default = null) { $files = $this->getUploadedFiles(); return is_null($key) ? $files : data_get($files, $key, $default); }
[ "public", "function", "file", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "$", "files", "=", "$", "this", "->", "getUploadedFiles", "(", ")", ";", "return", "is_null", "(", "$", "key", ")", "?", "$", "files", ":", "data_get", "(", "$", "files", ",", "$", "key", ",", "$", "default", ")", ";", "}" ]
Retrieve a file from the request. @param string $key @param mixed $default @return null|array
[ "Retrieve", "a", "file", "from", "the", "request", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Request.php#L462-L467
inhere/php-librarys
src/Helpers/PhpHelper.php
PhpHelper.getMaxUploadSize
public static function getMaxUploadSize($max_size = 0): int { $post_max_size = FormatHelper::convertBytes(ini_get('post_max_size')); $upload_max_fileSize = FormatHelper::convertBytes(ini_get('upload_max_filesize')); if ($max_size > 0) { $result = min($post_max_size, $upload_max_fileSize, $max_size); } else { $result = min($post_max_size, $upload_max_fileSize); } return $result; }
php
public static function getMaxUploadSize($max_size = 0): int { $post_max_size = FormatHelper::convertBytes(ini_get('post_max_size')); $upload_max_fileSize = FormatHelper::convertBytes(ini_get('upload_max_filesize')); if ($max_size > 0) { $result = min($post_max_size, $upload_max_fileSize, $max_size); } else { $result = min($post_max_size, $upload_max_fileSize); } return $result; }
[ "public", "static", "function", "getMaxUploadSize", "(", "$", "max_size", "=", "0", ")", ":", "int", "{", "$", "post_max_size", "=", "FormatHelper", "::", "convertBytes", "(", "ini_get", "(", "'post_max_size'", ")", ")", ";", "$", "upload_max_fileSize", "=", "FormatHelper", "::", "convertBytes", "(", "ini_get", "(", "'upload_max_filesize'", ")", ")", ";", "if", "(", "$", "max_size", ">", "0", ")", "{", "$", "result", "=", "min", "(", "$", "post_max_size", ",", "$", "upload_max_fileSize", ",", "$", "max_size", ")", ";", "}", "else", "{", "$", "result", "=", "min", "(", "$", "post_max_size", ",", "$", "upload_max_fileSize", ")", ";", "}", "return", "$", "result", ";", "}" ]
根据服务器设置得到文件上传大小的最大值 @param int $max_size optional max file size @return int max file size in bytes
[ "根据服务器设置得到文件上传大小的最大值" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/PhpHelper.php#L99-L111
inhere/php-librarys
src/Helpers/PhpHelper.php
PhpHelper.exceptionToString
public static function exceptionToString($e, $getTrace = true, $catcher = null): string { return PhpException::toString($e, $getTrace, $catcher); }
php
public static function exceptionToString($e, $getTrace = true, $catcher = null): string { return PhpException::toString($e, $getTrace, $catcher); }
[ "public", "static", "function", "exceptionToString", "(", "$", "e", ",", "$", "getTrace", "=", "true", ",", "$", "catcher", "=", "null", ")", ":", "string", "{", "return", "PhpException", "::", "toString", "(", "$", "e", ",", "$", "getTrace", ",", "$", "catcher", ")", ";", "}" ]
Converts an exception into a simple string. @param \Exception|\Throwable $e the exception being converted @param bool $getTrace @param null|string $catcher @return string the string representation of the exception.
[ "Converts", "an", "exception", "into", "a", "simple", "string", "." ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/PhpHelper.php#L120-L123
inhere/php-librarys
src/Helpers/PhpHelper.php
PhpHelper.printVars
public static function printVars(...$args): string { $string = ''; foreach ($args as $arg) { $string .= print_r($arg, 1) . PHP_EOL; } return preg_replace("/Array\n\s+\(/", 'Array (', $string); }
php
public static function printVars(...$args): string { $string = ''; foreach ($args as $arg) { $string .= print_r($arg, 1) . PHP_EOL; } return preg_replace("/Array\n\s+\(/", 'Array (', $string); }
[ "public", "static", "function", "printVars", "(", "...", "$", "args", ")", ":", "string", "{", "$", "string", "=", "''", ";", "foreach", "(", "$", "args", "as", "$", "arg", ")", "{", "$", "string", ".=", "print_r", "(", "$", "arg", ",", "1", ")", ".", "PHP_EOL", ";", "}", "return", "preg_replace", "(", "\"/Array\\n\\s+\\(/\"", ",", "'Array ('", ",", "$", "string", ")", ";", "}" ]
print vars @param array ...$args @return string
[ "print", "vars" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/PhpHelper.php#L170-L179
thelia-modules/CustomerGroup
Handler/ConfigurationFileHandler.php
ConfigurationFileHandler.loadConfigurationFile
public function loadConfigurationFile(Module $module) { $finder = (new Finder) // TODO: Flip when yaml parsing will be up // ->name('#customer[-_\.]?group\.(?:xml|yml|yaml)#i') ->name('#customer[-_\.]?group\.xml#i') ->in($module->getAbsoluteConfigPath()); $count = $finder->count(); if ($count > 1) { throw new InvalidConfigurationException('Too many configuration file.'); } else { foreach ($finder as $file) { if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'xml') { $moduleConfig = $this->parseXml($file); } else { $moduleConfig = $this->parseYml($file); } $this->applyConfig($moduleConfig); } } }
php
public function loadConfigurationFile(Module $module) { $finder = (new Finder) // TODO: Flip when yaml parsing will be up // ->name('#customer[-_\.]?group\.(?:xml|yml|yaml)#i') ->name('#customer[-_\.]?group\.xml#i') ->in($module->getAbsoluteConfigPath()); $count = $finder->count(); if ($count > 1) { throw new InvalidConfigurationException('Too many configuration file.'); } else { foreach ($finder as $file) { if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'xml') { $moduleConfig = $this->parseXml($file); } else { $moduleConfig = $this->parseYml($file); } $this->applyConfig($moduleConfig); } } }
[ "public", "function", "loadConfigurationFile", "(", "Module", "$", "module", ")", "{", "$", "finder", "=", "(", "new", "Finder", ")", "// TODO: Flip when yaml parsing will be up", "// ->name('#customer[-_\\.]?group\\.(?:xml|yml|yaml)#i')", "->", "name", "(", "'#customer[-_\\.]?group\\.xml#i'", ")", "->", "in", "(", "$", "module", "->", "getAbsoluteConfigPath", "(", ")", ")", ";", "$", "count", "=", "$", "finder", "->", "count", "(", ")", ";", "if", "(", "$", "count", ">", "1", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "'Too many configuration file.'", ")", ";", "}", "else", "{", "foreach", "(", "$", "finder", "as", "$", "file", ")", "{", "if", "(", "strtolower", "(", "pathinfo", "(", "$", "file", ",", "PATHINFO_EXTENSION", ")", ")", "===", "'xml'", ")", "{", "$", "moduleConfig", "=", "$", "this", "->", "parseXml", "(", "$", "file", ")", ";", "}", "else", "{", "$", "moduleConfig", "=", "$", "this", "->", "parseYml", "(", "$", "file", ")", ";", "}", "$", "this", "->", "applyConfig", "(", "$", "moduleConfig", ")", ";", "}", "}", "}" ]
Find, parse and load customer group configuration file for module @param Module $module A module object @throws InvalidConfigurationException
[ "Find", "parse", "and", "load", "customer", "group", "configuration", "file", "for", "module" ]
train
https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Handler/ConfigurationFileHandler.php#L25-L47
thelia-modules/CustomerGroup
Handler/ConfigurationFileHandler.php
ConfigurationFileHandler.applyConfig
protected function applyConfig(array $moduleConfiguration) { foreach ($moduleConfiguration['customer_group'] as $customerGroupData) { if (CustomerGroupQuery::create()->findOneByCode($customerGroupData['code']) === null) { $customerGroup = (new CustomerGroup) ->setCode($customerGroupData['code']); foreach ($customerGroupData['descriptive'] as $descriptiveData) { $customerGroup ->setLocale($descriptiveData['locale']) ->setTitle($descriptiveData['title']) ->setDescription($descriptiveData['description']); } $customerGroup->save(); } } if ($moduleConfiguration['default']) { $customerGroup = CustomerGroupQuery::create()->findOneByCode($moduleConfiguration['default']); if ($customerGroup !== null) { $this->resetDefault(); $customerGroup ->setIsDefault(true) ->save(); } } }
php
protected function applyConfig(array $moduleConfiguration) { foreach ($moduleConfiguration['customer_group'] as $customerGroupData) { if (CustomerGroupQuery::create()->findOneByCode($customerGroupData['code']) === null) { $customerGroup = (new CustomerGroup) ->setCode($customerGroupData['code']); foreach ($customerGroupData['descriptive'] as $descriptiveData) { $customerGroup ->setLocale($descriptiveData['locale']) ->setTitle($descriptiveData['title']) ->setDescription($descriptiveData['description']); } $customerGroup->save(); } } if ($moduleConfiguration['default']) { $customerGroup = CustomerGroupQuery::create()->findOneByCode($moduleConfiguration['default']); if ($customerGroup !== null) { $this->resetDefault(); $customerGroup ->setIsDefault(true) ->save(); } } }
[ "protected", "function", "applyConfig", "(", "array", "$", "moduleConfiguration", ")", "{", "foreach", "(", "$", "moduleConfiguration", "[", "'customer_group'", "]", "as", "$", "customerGroupData", ")", "{", "if", "(", "CustomerGroupQuery", "::", "create", "(", ")", "->", "findOneByCode", "(", "$", "customerGroupData", "[", "'code'", "]", ")", "===", "null", ")", "{", "$", "customerGroup", "=", "(", "new", "CustomerGroup", ")", "->", "setCode", "(", "$", "customerGroupData", "[", "'code'", "]", ")", ";", "foreach", "(", "$", "customerGroupData", "[", "'descriptive'", "]", "as", "$", "descriptiveData", ")", "{", "$", "customerGroup", "->", "setLocale", "(", "$", "descriptiveData", "[", "'locale'", "]", ")", "->", "setTitle", "(", "$", "descriptiveData", "[", "'title'", "]", ")", "->", "setDescription", "(", "$", "descriptiveData", "[", "'description'", "]", ")", ";", "}", "$", "customerGroup", "->", "save", "(", ")", ";", "}", "}", "if", "(", "$", "moduleConfiguration", "[", "'default'", "]", ")", "{", "$", "customerGroup", "=", "CustomerGroupQuery", "::", "create", "(", ")", "->", "findOneByCode", "(", "$", "moduleConfiguration", "[", "'default'", "]", ")", ";", "if", "(", "$", "customerGroup", "!==", "null", ")", "{", "$", "this", "->", "resetDefault", "(", ")", ";", "$", "customerGroup", "->", "setIsDefault", "(", "true", ")", "->", "save", "(", ")", ";", "}", "}", "}" ]
Save new customer group to database @param array $moduleConfiguration Customer group module configuration
[ "Save", "new", "customer", "group", "to", "database" ]
train
https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Handler/ConfigurationFileHandler.php#L105-L133
thelia-modules/CustomerGroup
Handler/ConfigurationFileHandler.php
ConfigurationFileHandler.resetDefault
protected function resetDefault() { $defaultGroups = CustomerGroupQuery::create() ->filterByIsDefault(true) ->find(); foreach ($defaultGroups as $defaultGroup) { $defaultGroup ->setIsDefault(false) ->save(); } }
php
protected function resetDefault() { $defaultGroups = CustomerGroupQuery::create() ->filterByIsDefault(true) ->find(); foreach ($defaultGroups as $defaultGroup) { $defaultGroup ->setIsDefault(false) ->save(); } }
[ "protected", "function", "resetDefault", "(", ")", "{", "$", "defaultGroups", "=", "CustomerGroupQuery", "::", "create", "(", ")", "->", "filterByIsDefault", "(", "true", ")", "->", "find", "(", ")", ";", "foreach", "(", "$", "defaultGroups", "as", "$", "defaultGroup", ")", "{", "$", "defaultGroup", "->", "setIsDefault", "(", "false", ")", "->", "save", "(", ")", ";", "}", "}" ]
Remove is_default flag
[ "Remove", "is_default", "flag" ]
train
https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Handler/ConfigurationFileHandler.php#L138-L150
NuclearCMS/Hierarchy
src/Providers/BuilderServiceProvider.php
BuilderServiceProvider.register
public function register() { $this->registerModelBuilder(); $this->registerMigrationBuilder(); $this->registerFormBuilder(); $this->registerCacheBuilder(); $this->registerBuilderService(); }
php
public function register() { $this->registerModelBuilder(); $this->registerMigrationBuilder(); $this->registerFormBuilder(); $this->registerCacheBuilder(); $this->registerBuilderService(); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "registerModelBuilder", "(", ")", ";", "$", "this", "->", "registerMigrationBuilder", "(", ")", ";", "$", "this", "->", "registerFormBuilder", "(", ")", ";", "$", "this", "->", "registerCacheBuilder", "(", ")", ";", "$", "this", "->", "registerBuilderService", "(", ")", ";", "}" ]
Register the service provider. @return void
[ "Register", "the", "service", "provider", "." ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Providers/BuilderServiceProvider.php#L38-L45
webdevvie/pheanstalk-task-queue-bundle
Service/TaskCommandGenerator.php
TaskCommandGenerator.generate
public function generate(WorkPackage $work) { $description = $work->getTaskDescription(); $command =$description->getCommand(); if (!$this->isValidCommand($command)) { throw new TaskCommandGeneratorException("This command is not usable '{$command}' is not valid"); } $cmd = escapeshellarg($command); $cmd .= $this->generateArguments($description); $cmd .= $this->generateOptions($description); return $cmd; }
php
public function generate(WorkPackage $work) { $description = $work->getTaskDescription(); $command =$description->getCommand(); if (!$this->isValidCommand($command)) { throw new TaskCommandGeneratorException("This command is not usable '{$command}' is not valid"); } $cmd = escapeshellarg($command); $cmd .= $this->generateArguments($description); $cmd .= $this->generateOptions($description); return $cmd; }
[ "public", "function", "generate", "(", "WorkPackage", "$", "work", ")", "{", "$", "description", "=", "$", "work", "->", "getTaskDescription", "(", ")", ";", "$", "command", "=", "$", "description", "->", "getCommand", "(", ")", ";", "if", "(", "!", "$", "this", "->", "isValidCommand", "(", "$", "command", ")", ")", "{", "throw", "new", "TaskCommandGeneratorException", "(", "\"This command is not usable '{$command}' is not valid\"", ")", ";", "}", "$", "cmd", "=", "escapeshellarg", "(", "$", "command", ")", ";", "$", "cmd", ".=", "$", "this", "->", "generateArguments", "(", "$", "description", ")", ";", "$", "cmd", ".=", "$", "this", "->", "generateOptions", "(", "$", "description", ")", ";", "return", "$", "cmd", ";", "}" ]
Generates a symfony2 console command to execute from the task @param WorkPackage $work @throws TaskCommandGeneratorException @return string
[ "Generates", "a", "symfony2", "console", "command", "to", "execute", "from", "the", "task" ]
train
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Service/TaskCommandGenerator.php#L25-L36
webdevvie/pheanstalk-task-queue-bundle
Service/TaskCommandGenerator.php
TaskCommandGenerator.generateArguments
private function generateArguments(TaskDescriptionInterface $description) { $cmdPart = ''; $arguments = $description->getArguments(); if (!is_array($arguments)) { return $cmdPart; } foreach ($arguments as $argumentValue) { if (is_string($argumentValue) || is_integer($argumentValue)) { $cmdPart .= ' ' . escapeshellarg($argumentValue); } } return $cmdPart; }
php
private function generateArguments(TaskDescriptionInterface $description) { $cmdPart = ''; $arguments = $description->getArguments(); if (!is_array($arguments)) { return $cmdPart; } foreach ($arguments as $argumentValue) { if (is_string($argumentValue) || is_integer($argumentValue)) { $cmdPart .= ' ' . escapeshellarg($argumentValue); } } return $cmdPart; }
[ "private", "function", "generateArguments", "(", "TaskDescriptionInterface", "$", "description", ")", "{", "$", "cmdPart", "=", "''", ";", "$", "arguments", "=", "$", "description", "->", "getArguments", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "arguments", ")", ")", "{", "return", "$", "cmdPart", ";", "}", "foreach", "(", "$", "arguments", "as", "$", "argumentValue", ")", "{", "if", "(", "is_string", "(", "$", "argumentValue", ")", "||", "is_integer", "(", "$", "argumentValue", ")", ")", "{", "$", "cmdPart", ".=", "' '", ".", "escapeshellarg", "(", "$", "argumentValue", ")", ";", "}", "}", "return", "$", "cmdPart", ";", "}" ]
Generates the argument part of the command @param TaskDescriptionInterface $description @return string
[ "Generates", "the", "argument", "part", "of", "the", "command" ]
train
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Service/TaskCommandGenerator.php#L44-L57
webdevvie/pheanstalk-task-queue-bundle
Service/TaskCommandGenerator.php
TaskCommandGenerator.generateOptions
private function generateOptions(TaskDescriptionInterface $description) { $cmdPart = ''; $options = $description->getOptions(); if (!is_array($options)) { return $cmdPart; } foreach ($options as $optionName => $optionValue) { //validate the option name if (!$this->isValidOptionName($optionName)) { continue; } if (is_bool($optionValue) && $optionValue) { $cmdPart .= ' --' . $optionName; } elseif (is_string($optionValue)|| is_integer($optionValue)) { $cmdPart .= ' --' . $optionName . '=' . escapeshellarg($optionValue); } } return $cmdPart; }
php
private function generateOptions(TaskDescriptionInterface $description) { $cmdPart = ''; $options = $description->getOptions(); if (!is_array($options)) { return $cmdPart; } foreach ($options as $optionName => $optionValue) { //validate the option name if (!$this->isValidOptionName($optionName)) { continue; } if (is_bool($optionValue) && $optionValue) { $cmdPart .= ' --' . $optionName; } elseif (is_string($optionValue)|| is_integer($optionValue)) { $cmdPart .= ' --' . $optionName . '=' . escapeshellarg($optionValue); } } return $cmdPart; }
[ "private", "function", "generateOptions", "(", "TaskDescriptionInterface", "$", "description", ")", "{", "$", "cmdPart", "=", "''", ";", "$", "options", "=", "$", "description", "->", "getOptions", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "options", ")", ")", "{", "return", "$", "cmdPart", ";", "}", "foreach", "(", "$", "options", "as", "$", "optionName", "=>", "$", "optionValue", ")", "{", "//validate the option name", "if", "(", "!", "$", "this", "->", "isValidOptionName", "(", "$", "optionName", ")", ")", "{", "continue", ";", "}", "if", "(", "is_bool", "(", "$", "optionValue", ")", "&&", "$", "optionValue", ")", "{", "$", "cmdPart", ".=", "' --'", ".", "$", "optionName", ";", "}", "elseif", "(", "is_string", "(", "$", "optionValue", ")", "||", "is_integer", "(", "$", "optionValue", ")", ")", "{", "$", "cmdPart", ".=", "' --'", ".", "$", "optionName", ".", "'='", ".", "escapeshellarg", "(", "$", "optionValue", ")", ";", "}", "}", "return", "$", "cmdPart", ";", "}" ]
Generates the options part of the command @param TaskDescriptionInterface $description @return string
[ "Generates", "the", "options", "part", "of", "the", "command" ]
train
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Service/TaskCommandGenerator.php#L65-L85
oroinc/OroLayoutComponent
Extension/Theme/Model/ThemeManager.php
ThemeManager.getTheme
public function getTheme($themeName) { if (empty($themeName)) { throw new \InvalidArgumentException('The theme name must not be empty.'); } elseif (!$this->hasTheme($themeName)) { throw new \LogicException(sprintf('Unable to retrieve definition for theme "%s".', $themeName)); } if (!isset($this->instances[$themeName])) { $theme = $this->themeFactory->create($themeName, $this->themeDefinitions[$themeName]); $this->instances[$themeName] = $this->mergePageTemplates($theme); } return $this->instances[$themeName]; }
php
public function getTheme($themeName) { if (empty($themeName)) { throw new \InvalidArgumentException('The theme name must not be empty.'); } elseif (!$this->hasTheme($themeName)) { throw new \LogicException(sprintf('Unable to retrieve definition for theme "%s".', $themeName)); } if (!isset($this->instances[$themeName])) { $theme = $this->themeFactory->create($themeName, $this->themeDefinitions[$themeName]); $this->instances[$themeName] = $this->mergePageTemplates($theme); } return $this->instances[$themeName]; }
[ "public", "function", "getTheme", "(", "$", "themeName", ")", "{", "if", "(", "empty", "(", "$", "themeName", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The theme name must not be empty.'", ")", ";", "}", "elseif", "(", "!", "$", "this", "->", "hasTheme", "(", "$", "themeName", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "sprintf", "(", "'Unable to retrieve definition for theme \"%s\".'", ",", "$", "themeName", ")", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "instances", "[", "$", "themeName", "]", ")", ")", "{", "$", "theme", "=", "$", "this", "->", "themeFactory", "->", "create", "(", "$", "themeName", ",", "$", "this", "->", "themeDefinitions", "[", "$", "themeName", "]", ")", ";", "$", "this", "->", "instances", "[", "$", "themeName", "]", "=", "$", "this", "->", "mergePageTemplates", "(", "$", "theme", ")", ";", "}", "return", "$", "this", "->", "instances", "[", "$", "themeName", "]", ";", "}" ]
Gets theme model instance @param string $themeName @return Theme
[ "Gets", "theme", "model", "instance" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/Model/ThemeManager.php#L55-L69
oroinc/OroLayoutComponent
Extension/Theme/Model/ThemeManager.php
ThemeManager.mergePageTemplates
private function mergePageTemplates(Theme $theme) { if ($theme->getParentTheme()) { $parentTheme = $this->getTheme($theme->getParentTheme()); foreach ($parentTheme->getPageTemplates() as $parentPageTemplate) { $theme->addPageTemplate($parentPageTemplate); } foreach ($parentTheme->getPageTemplateTitles() as $route => $title) { if (!$theme->getPageTemplateTitle($route)) { $theme->addPageTemplateTitle($route, $title); } } } return $theme; }
php
private function mergePageTemplates(Theme $theme) { if ($theme->getParentTheme()) { $parentTheme = $this->getTheme($theme->getParentTheme()); foreach ($parentTheme->getPageTemplates() as $parentPageTemplate) { $theme->addPageTemplate($parentPageTemplate); } foreach ($parentTheme->getPageTemplateTitles() as $route => $title) { if (!$theme->getPageTemplateTitle($route)) { $theme->addPageTemplateTitle($route, $title); } } } return $theme; }
[ "private", "function", "mergePageTemplates", "(", "Theme", "$", "theme", ")", "{", "if", "(", "$", "theme", "->", "getParentTheme", "(", ")", ")", "{", "$", "parentTheme", "=", "$", "this", "->", "getTheme", "(", "$", "theme", "->", "getParentTheme", "(", ")", ")", ";", "foreach", "(", "$", "parentTheme", "->", "getPageTemplates", "(", ")", "as", "$", "parentPageTemplate", ")", "{", "$", "theme", "->", "addPageTemplate", "(", "$", "parentPageTemplate", ")", ";", "}", "foreach", "(", "$", "parentTheme", "->", "getPageTemplateTitles", "(", ")", "as", "$", "route", "=>", "$", "title", ")", "{", "if", "(", "!", "$", "theme", "->", "getPageTemplateTitle", "(", "$", "route", ")", ")", "{", "$", "theme", "->", "addPageTemplateTitle", "(", "$", "route", ",", "$", "title", ")", ";", "}", "}", "}", "return", "$", "theme", ";", "}" ]
@param Theme $theme @return Theme
[ "@param", "Theme", "$theme" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/Model/ThemeManager.php#L76-L93
oroinc/OroLayoutComponent
Extension/Theme/Model/ThemeManager.php
ThemeManager.getAllThemes
public function getAllThemes($groups = null) { $names = $this->getThemeNames(); $themes = array_combine( $names, array_map( function ($themeName) { return $this->getTheme($themeName); }, $names ) ); if (!empty($groups)) { $groups = is_array($groups) ? $groups : [$groups]; $themes = array_filter( $themes, function (Theme $theme) use ($groups) { return count(array_intersect($groups, $theme->getGroups())) > 0; } ); } return $themes; }
php
public function getAllThemes($groups = null) { $names = $this->getThemeNames(); $themes = array_combine( $names, array_map( function ($themeName) { return $this->getTheme($themeName); }, $names ) ); if (!empty($groups)) { $groups = is_array($groups) ? $groups : [$groups]; $themes = array_filter( $themes, function (Theme $theme) use ($groups) { return count(array_intersect($groups, $theme->getGroups())) > 0; } ); } return $themes; }
[ "public", "function", "getAllThemes", "(", "$", "groups", "=", "null", ")", "{", "$", "names", "=", "$", "this", "->", "getThemeNames", "(", ")", ";", "$", "themes", "=", "array_combine", "(", "$", "names", ",", "array_map", "(", "function", "(", "$", "themeName", ")", "{", "return", "$", "this", "->", "getTheme", "(", "$", "themeName", ")", ";", "}", ",", "$", "names", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "groups", ")", ")", "{", "$", "groups", "=", "is_array", "(", "$", "groups", ")", "?", "$", "groups", ":", "[", "$", "groups", "]", ";", "$", "themes", "=", "array_filter", "(", "$", "themes", ",", "function", "(", "Theme", "$", "theme", ")", "use", "(", "$", "groups", ")", "{", "return", "count", "(", "array_intersect", "(", "$", "groups", ",", "$", "theme", "->", "getGroups", "(", ")", ")", ")", ">", "0", ";", "}", ")", ";", "}", "return", "$", "themes", ";", "}" ]
@param null|string|array $groups @return Theme[]
[ "@param", "null|string|array", "$groups" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/Model/ThemeManager.php#L100-L125
opsbears/piccolo
src/Module/AbstractModule.php
AbstractModule.getRequiredModule
protected function getRequiredModule(string $className) { if (\array_key_exists($className, $this->modules)) { return $this->modules[$className]; } else { throw new ConfigurationException(__CLASS__ . ' tried to request module ' . $className . ', but it was not listed as a dependency or has not yet added.'); } }
php
protected function getRequiredModule(string $className) { if (\array_key_exists($className, $this->modules)) { return $this->modules[$className]; } else { throw new ConfigurationException(__CLASS__ . ' tried to request module ' . $className . ', but it was not listed as a dependency or has not yet added.'); } }
[ "protected", "function", "getRequiredModule", "(", "string", "$", "className", ")", "{", "if", "(", "\\", "array_key_exists", "(", "$", "className", ",", "$", "this", "->", "modules", ")", ")", "{", "return", "$", "this", "->", "modules", "[", "$", "className", "]", ";", "}", "else", "{", "throw", "new", "ConfigurationException", "(", "__CLASS__", ".", "' tried to request module '", ".", "$", "className", ".", "', but it was not listed as a dependency or has not yet added.'", ")", ";", "}", "}" ]
Returns a module that has been set as required. This is only available after the constructor has finished. @param string $className @return Module @throws ConfigurationException
[ "Returns", "a", "module", "that", "has", "been", "set", "as", "required", ".", "This", "is", "only", "available", "after", "the", "constructor", "has", "finished", "." ]
train
https://github.com/opsbears/piccolo/blob/ebba9f892ed35965140265ba1c61b2c645eab6e0/src/Module/AbstractModule.php#L81-L88
mvccore/ext-router-module
src/MvcCore/Ext/Routers/Module/Redirect.php
Redirect.redirectToVersion
protected function redirectToVersion ($systemParams) { /** @var $request \MvcCore\Request */ $request = & $this->request; // get domain with base path URL section, // path with query string URL section // system params for URL prefixes // and if path with query string URL section targeting `/` or `/index.php` $targetModule = NULL; $domainParamsDefault = []; $domainParams = []; if ($this->currentDomainRoute !== NULL) { $targetModule = $this->currentModule; $domainParamsDefault = $this->requestedDomainParams; } if ($targetModule !== NULL) { // remove domain module params and complete URL address base part by module domain $domainParams = array_intersect_key($systemParams, $domainParamsDefault); //$systemParamsClone = array_diff_key($systemParams, $domainParamsDefault); $defaultDomainParams = array_merge([], $this->GetDefaultParams() ?: []); if (method_exists($this, 'redirectCorrectDomainSystemParams')) $this->redirectCorrectDomainSystemParams($domainParams); list($domainUrlBaseSection,) = $this->currentDomainRoute->Url( $request, $domainParams, $defaultDomainParams, '' ); } else { $domainUrlBaseSection = NULL; } list ($urlBaseSection, $urlPathWithQuerySection, $systemParams, $urlPathWithQueryIsHome) = $this->redirectToVersionSections($systemParams); $targetUrl = $this->urlByRoutePrefixSystemParams( $domainUrlBaseSection ?: $urlBaseSection, $urlPathWithQuerySection, array_diff_key($systemParams, $domainParamsDefault), $urlPathWithQueryIsHome ); $questionMarkPos = mb_strpos($targetUrl, '?'); if ($questionMarkPos !== FALSE) $targetUrl = mb_substr($targetUrl, 0, $questionMarkPos); $fullOriginalUrl = $request->GetBaseUrl() . $request->GetOriginalPath(); if ($fullOriginalUrl === $targetUrl) return TRUE; $this->redirect($targetUrl, $this->redirectStatusCode); return FALSE; }
php
protected function redirectToVersion ($systemParams) { /** @var $request \MvcCore\Request */ $request = & $this->request; // get domain with base path URL section, // path with query string URL section // system params for URL prefixes // and if path with query string URL section targeting `/` or `/index.php` $targetModule = NULL; $domainParamsDefault = []; $domainParams = []; if ($this->currentDomainRoute !== NULL) { $targetModule = $this->currentModule; $domainParamsDefault = $this->requestedDomainParams; } if ($targetModule !== NULL) { // remove domain module params and complete URL address base part by module domain $domainParams = array_intersect_key($systemParams, $domainParamsDefault); //$systemParamsClone = array_diff_key($systemParams, $domainParamsDefault); $defaultDomainParams = array_merge([], $this->GetDefaultParams() ?: []); if (method_exists($this, 'redirectCorrectDomainSystemParams')) $this->redirectCorrectDomainSystemParams($domainParams); list($domainUrlBaseSection,) = $this->currentDomainRoute->Url( $request, $domainParams, $defaultDomainParams, '' ); } else { $domainUrlBaseSection = NULL; } list ($urlBaseSection, $urlPathWithQuerySection, $systemParams, $urlPathWithQueryIsHome) = $this->redirectToVersionSections($systemParams); $targetUrl = $this->urlByRoutePrefixSystemParams( $domainUrlBaseSection ?: $urlBaseSection, $urlPathWithQuerySection, array_diff_key($systemParams, $domainParamsDefault), $urlPathWithQueryIsHome ); $questionMarkPos = mb_strpos($targetUrl, '?'); if ($questionMarkPos !== FALSE) $targetUrl = mb_substr($targetUrl, 0, $questionMarkPos); $fullOriginalUrl = $request->GetBaseUrl() . $request->GetOriginalPath(); if ($fullOriginalUrl === $targetUrl) return TRUE; $this->redirect($targetUrl, $this->redirectStatusCode); return FALSE; }
[ "protected", "function", "redirectToVersion", "(", "$", "systemParams", ")", "{", "/** @var $request \\MvcCore\\Request */", "$", "request", "=", "&", "$", "this", "->", "request", ";", "// get domain with base path URL section, ", "// path with query string URL section ", "// system params for URL prefixes", "// and if path with query string URL section targeting `/` or `/index.php`", "$", "targetModule", "=", "NULL", ";", "$", "domainParamsDefault", "=", "[", "]", ";", "$", "domainParams", "=", "[", "]", ";", "if", "(", "$", "this", "->", "currentDomainRoute", "!==", "NULL", ")", "{", "$", "targetModule", "=", "$", "this", "->", "currentModule", ";", "$", "domainParamsDefault", "=", "$", "this", "->", "requestedDomainParams", ";", "}", "if", "(", "$", "targetModule", "!==", "NULL", ")", "{", "// remove domain module params and complete URL address base part by module domain", "$", "domainParams", "=", "array_intersect_key", "(", "$", "systemParams", ",", "$", "domainParamsDefault", ")", ";", "//$systemParamsClone = array_diff_key($systemParams, $domainParamsDefault);", "$", "defaultDomainParams", "=", "array_merge", "(", "[", "]", ",", "$", "this", "->", "GetDefaultParams", "(", ")", "?", ":", "[", "]", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "'redirectCorrectDomainSystemParams'", ")", ")", "$", "this", "->", "redirectCorrectDomainSystemParams", "(", "$", "domainParams", ")", ";", "list", "(", "$", "domainUrlBaseSection", ",", ")", "=", "$", "this", "->", "currentDomainRoute", "->", "Url", "(", "$", "request", ",", "$", "domainParams", ",", "$", "defaultDomainParams", ",", "''", ")", ";", "}", "else", "{", "$", "domainUrlBaseSection", "=", "NULL", ";", "}", "list", "(", "$", "urlBaseSection", ",", "$", "urlPathWithQuerySection", ",", "$", "systemParams", ",", "$", "urlPathWithQueryIsHome", ")", "=", "$", "this", "->", "redirectToVersionSections", "(", "$", "systemParams", ")", ";", "$", "targetUrl", "=", "$", "this", "->", "urlByRoutePrefixSystemParams", "(", "$", "domainUrlBaseSection", "?", ":", "$", "urlBaseSection", ",", "$", "urlPathWithQuerySection", ",", "array_diff_key", "(", "$", "systemParams", ",", "$", "domainParamsDefault", ")", ",", "$", "urlPathWithQueryIsHome", ")", ";", "$", "questionMarkPos", "=", "mb_strpos", "(", "$", "targetUrl", ",", "'?'", ")", ";", "if", "(", "$", "questionMarkPos", "!==", "FALSE", ")", "$", "targetUrl", "=", "mb_substr", "(", "$", "targetUrl", ",", "0", ",", "$", "questionMarkPos", ")", ";", "$", "fullOriginalUrl", "=", "$", "request", "->", "GetBaseUrl", "(", ")", ".", "$", "request", "->", "GetOriginalPath", "(", ")", ";", "if", "(", "$", "fullOriginalUrl", "===", "$", "targetUrl", ")", "return", "TRUE", ";", "$", "this", "->", "redirect", "(", "$", "targetUrl", ",", "$", "this", "->", "redirectStatusCode", ")", ";", "return", "FALSE", ";", "}" ]
Redirect to target media site version with path and by cloned request object global `$_GET` collection. Return always `FALSE`. @param array $systemParams @return bool
[ "Redirect", "to", "target", "media", "site", "version", "with", "path", "and", "by", "cloned", "request", "object", "global", "$_GET", "collection", ".", "Return", "always", "FALSE", "." ]
train
https://github.com/mvccore/ext-router-module/blob/7695784a451db86cca6a43c98d076803cd0a50a7/src/MvcCore/Ext/Routers/Module/Redirect.php#L24-L77
antaresproject/notifications
src/Listener/ConfigurationListener.php
ConfigurationListener.handle
public function handle(Fluent $model, Grid $grid) { $grid->fieldset(function(Fieldset $fieldset) { $fieldset->legend(trans('antares/notifications::logs.form.notifications_config_legend')); $fieldset->control('input:text', 'days') ->label('') ->field(function() { $memory = app('antares.memory')->make('primary'); return '<div class="col-group"><div class="col-dt-16 col-16 col-mb-16">' . trans('antares/notifications::logs.form.notifications_config_days_label', ['x' => '<input class="w50" type="number" name="days" value="' . $memory->get('notifications_remove_after_days', '') . '" size="2" max-length="2" />']) . '</div><div class="col-dt-16 col-16 col-mb-16 "><div class="input-field__desc">' . trans('antares/notifications::logs.form.notifications_config_days_help') . '</div></div></div>'; }); }); $grid->rules(array_merge($grid->rules, [ 'days' => ['numeric'], ])); }
php
public function handle(Fluent $model, Grid $grid) { $grid->fieldset(function(Fieldset $fieldset) { $fieldset->legend(trans('antares/notifications::logs.form.notifications_config_legend')); $fieldset->control('input:text', 'days') ->label('') ->field(function() { $memory = app('antares.memory')->make('primary'); return '<div class="col-group"><div class="col-dt-16 col-16 col-mb-16">' . trans('antares/notifications::logs.form.notifications_config_days_label', ['x' => '<input class="w50" type="number" name="days" value="' . $memory->get('notifications_remove_after_days', '') . '" size="2" max-length="2" />']) . '</div><div class="col-dt-16 col-16 col-mb-16 "><div class="input-field__desc">' . trans('antares/notifications::logs.form.notifications_config_days_help') . '</div></div></div>'; }); }); $grid->rules(array_merge($grid->rules, [ 'days' => ['numeric'], ])); }
[ "public", "function", "handle", "(", "Fluent", "$", "model", ",", "Grid", "$", "grid", ")", "{", "$", "grid", "->", "fieldset", "(", "function", "(", "Fieldset", "$", "fieldset", ")", "{", "$", "fieldset", "->", "legend", "(", "trans", "(", "'antares/notifications::logs.form.notifications_config_legend'", ")", ")", ";", "$", "fieldset", "->", "control", "(", "'input:text'", ",", "'days'", ")", "->", "label", "(", "''", ")", "->", "field", "(", "function", "(", ")", "{", "$", "memory", "=", "app", "(", "'antares.memory'", ")", "->", "make", "(", "'primary'", ")", ";", "return", "'<div class=\"col-group\"><div class=\"col-dt-16 col-16 col-mb-16\">'", ".", "trans", "(", "'antares/notifications::logs.form.notifications_config_days_label'", ",", "[", "'x'", "=>", "'<input class=\"w50\" type=\"number\" name=\"days\" value=\"'", ".", "$", "memory", "->", "get", "(", "'notifications_remove_after_days'", ",", "''", ")", ".", "'\" size=\"2\" max-length=\"2\" />'", "]", ")", ".", "'</div><div class=\"col-dt-16 col-16 col-mb-16 \"><div class=\"input-field__desc\">'", ".", "trans", "(", "'antares/notifications::logs.form.notifications_config_days_help'", ")", ".", "'</div></div></div>'", ";", "}", ")", ";", "}", ")", ";", "$", "grid", "->", "rules", "(", "array_merge", "(", "$", "grid", "->", "rules", ",", "[", "'days'", "=>", "[", "'numeric'", "]", ",", "]", ")", ")", ";", "}" ]
Handles the security form event. @param SecurityFormSubmitted $securityFormSubmitted
[ "Handles", "the", "security", "form", "event", "." ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Listener/ConfigurationListener.php#L18-L33
antaresproject/notifications
src/Listener/ConfigurationListener.php
ConfigurationListener.updated
public function updated(Option $model) { $option = Option::query()->firstOrNew([ 'name' => 'notifications_remove_after_days' ]); $option->value = input('days'); return $option->save(); }
php
public function updated(Option $model) { $option = Option::query()->firstOrNew([ 'name' => 'notifications_remove_after_days' ]); $option->value = input('days'); return $option->save(); }
[ "public", "function", "updated", "(", "Option", "$", "model", ")", "{", "$", "option", "=", "Option", "::", "query", "(", ")", "->", "firstOrNew", "(", "[", "'name'", "=>", "'notifications_remove_after_days'", "]", ")", ";", "$", "option", "->", "value", "=", "input", "(", "'days'", ")", ";", "return", "$", "option", "->", "save", "(", ")", ";", "}" ]
Save notifications configuration @param Option $model
[ "Save", "notifications", "configuration" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Listener/ConfigurationListener.php#L40-L48
ezsystems/ezcomments-ls-extension
classes/ezcomsubscription.php
ezcomSubscription.countWithSubscriberID
static function countWithSubscriberID( $subscriberID, $languageID =false , $enabled = false ) { $cond = array(); $cond['subscriber_id'] = $subscriberID; if ( $enabled !== false ) { $cond['enabled'] = $enabled; } if ( $languageID !== false ) { $cond['language_id'] = $languageID; } $count = eZPersistentObject::count( self::definition(), $cond ); return $count; }
php
static function countWithSubscriberID( $subscriberID, $languageID =false , $enabled = false ) { $cond = array(); $cond['subscriber_id'] = $subscriberID; if ( $enabled !== false ) { $cond['enabled'] = $enabled; } if ( $languageID !== false ) { $cond['language_id'] = $languageID; } $count = eZPersistentObject::count( self::definition(), $cond ); return $count; }
[ "static", "function", "countWithSubscriberID", "(", "$", "subscriberID", ",", "$", "languageID", "=", "false", ",", "$", "enabled", "=", "false", ")", "{", "$", "cond", "=", "array", "(", ")", ";", "$", "cond", "[", "'subscriber_id'", "]", "=", "$", "subscriberID", ";", "if", "(", "$", "enabled", "!==", "false", ")", "{", "$", "cond", "[", "'enabled'", "]", "=", "$", "enabled", ";", "}", "if", "(", "$", "languageID", "!==", "false", ")", "{", "$", "cond", "[", "'language_id'", "]", "=", "$", "languageID", ";", "}", "$", "count", "=", "eZPersistentObject", "::", "count", "(", "self", "::", "definition", "(", ")", ",", "$", "cond", ")", ";", "return", "$", "count", ";", "}" ]
get the count of subscription in a subscriber ID @param $subscriberID @param $status @return unknown_type
[ "get", "the", "count", "of", "subscription", "in", "a", "subscriber", "ID" ]
train
https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/classes/ezcomsubscription.php#L143-L157
ezsystems/ezcomments-ls-extension
classes/ezcomsubscription.php
ezcomSubscription.contentObject
public function contentObject() { $contentID = $this->attribute( 'content_id' ); //TODO:try to get the language id $languageID = $this->attribute( 'language_id' ); return eZContentObject::fetch( $contentID ); }
php
public function contentObject() { $contentID = $this->attribute( 'content_id' ); //TODO:try to get the language id $languageID = $this->attribute( 'language_id' ); return eZContentObject::fetch( $contentID ); }
[ "public", "function", "contentObject", "(", ")", "{", "$", "contentID", "=", "$", "this", "->", "attribute", "(", "'content_id'", ")", ";", "//TODO:try to get the language id", "$", "languageID", "=", "$", "this", "->", "attribute", "(", "'language_id'", ")", ";", "return", "eZContentObject", "::", "fetch", "(", "$", "contentID", ")", ";", "}" ]
get the content of the subscription @return ezcontentobject
[ "get", "the", "content", "of", "the", "subscription" ]
train
https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/classes/ezcomsubscription.php#L182-L188
ezsystems/ezcomments-ls-extension
classes/ezcomsubscription.php
ezcomSubscription.cleanupSubscription
static function cleanupSubscription( $email, $contentobjectID, $languageID ) { //2. get subscriber $subscriber = ezcomSubscriber::fetchByEmail( $email ); if ( is_null( $subscriber ) ) { return false; } $subscriberID = $subscriber->attribute( 'id' ); //3. clean up subscription $querySubscription = "DELETE FROM ezcomment_subscription" . " WHERE subscriber_id = $subscriberID ". " AND content_id = $contentID" . " AND language_id= $languageID"; $db->query($querySubscription); return true; }
php
static function cleanupSubscription( $email, $contentobjectID, $languageID ) { //2. get subscriber $subscriber = ezcomSubscriber::fetchByEmail( $email ); if ( is_null( $subscriber ) ) { return false; } $subscriberID = $subscriber->attribute( 'id' ); //3. clean up subscription $querySubscription = "DELETE FROM ezcomment_subscription" . " WHERE subscriber_id = $subscriberID ". " AND content_id = $contentID" . " AND language_id= $languageID"; $db->query($querySubscription); return true; }
[ "static", "function", "cleanupSubscription", "(", "$", "email", ",", "$", "contentobjectID", ",", "$", "languageID", ")", "{", "//2. get subscriber", "$", "subscriber", "=", "ezcomSubscriber", "::", "fetchByEmail", "(", "$", "email", ")", ";", "if", "(", "is_null", "(", "$", "subscriber", ")", ")", "{", "return", "false", ";", "}", "$", "subscriberID", "=", "$", "subscriber", "->", "attribute", "(", "'id'", ")", ";", "//3. clean up subscription", "$", "querySubscription", "=", "\"DELETE FROM ezcomment_subscription\"", ".", "\" WHERE subscriber_id = $subscriberID \"", ".", "\" AND content_id = $contentID\"", ".", "\" AND language_id= $languageID\"", ";", "$", "db", "->", "query", "(", "$", "querySubscription", ")", ";", "return", "true", ";", "}" ]
clean up subscription based on an email address and content, language, make the subscription consistent. example: @param string $email @return true - there is subscription deleted false - no subscription deleted null - error
[ "clean", "up", "subscription", "based", "on", "an", "email", "address", "and", "content", "language", "make", "the", "subscription", "consistent", ".", "example", ":" ]
train
https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/classes/ezcomsubscription.php#L199-L215
ezsystems/ezcomments-ls-extension
classes/ezcomsubscription.php
ezcomSubscription.exists
static function exists( $contentID, $languageID , $subscriptionType, $email = null, $enabled = false ) { $emailString = ''; if ( !is_null($email) ) { $emailString = " WHERE email = '$email'"; } $countArray = null; $db = eZDB::instance(); if ( $enabled === false ) { $countArray = $db->arrayQuery( "SELECT count(*) AS count" . " FROM ezcomment_subscription" . " WHERE " . " content_id = $contentID" . " AND language_id = $languageID" . " AND subscription_type = '$subscriptionType'" . " AND subscriber_id IN" . "( SELECT id FROM ezcomment_subscriber" . "$emailString )"); } else if ( $enabled === 1 || $enabled === 0 ) { $enabledString = "enabled = $enabled"; if ( $emailString != '' ) { $enabledString = " AND " . $enabledString; } else { $enabledString = " WHERE " . $enabledString; } $countArray = $db->arrayQuery( "SELECT count(*) AS count" . " FROM ezcomment_subscription" . " WHERE" . " content_id = $contentID" . " AND language_id = $languageID" . " AND subscription_type = '$subscriptionType'" . " AND subscriber_id IN" . " ( SELECT id FROM ezcomment_subscriber" . $emailString . "$enabledString )" ); } else { return null; } $totalCount = $countArray[0]['count']; if ( $totalCount === '0' ) { return false; } else { return true; } }
php
static function exists( $contentID, $languageID , $subscriptionType, $email = null, $enabled = false ) { $emailString = ''; if ( !is_null($email) ) { $emailString = " WHERE email = '$email'"; } $countArray = null; $db = eZDB::instance(); if ( $enabled === false ) { $countArray = $db->arrayQuery( "SELECT count(*) AS count" . " FROM ezcomment_subscription" . " WHERE " . " content_id = $contentID" . " AND language_id = $languageID" . " AND subscription_type = '$subscriptionType'" . " AND subscriber_id IN" . "( SELECT id FROM ezcomment_subscriber" . "$emailString )"); } else if ( $enabled === 1 || $enabled === 0 ) { $enabledString = "enabled = $enabled"; if ( $emailString != '' ) { $enabledString = " AND " . $enabledString; } else { $enabledString = " WHERE " . $enabledString; } $countArray = $db->arrayQuery( "SELECT count(*) AS count" . " FROM ezcomment_subscription" . " WHERE" . " content_id = $contentID" . " AND language_id = $languageID" . " AND subscription_type = '$subscriptionType'" . " AND subscriber_id IN" . " ( SELECT id FROM ezcomment_subscriber" . $emailString . "$enabledString )" ); } else { return null; } $totalCount = $countArray[0]['count']; if ( $totalCount === '0' ) { return false; } else { return true; } }
[ "static", "function", "exists", "(", "$", "contentID", ",", "$", "languageID", ",", "$", "subscriptionType", ",", "$", "email", "=", "null", ",", "$", "enabled", "=", "false", ")", "{", "$", "emailString", "=", "''", ";", "if", "(", "!", "is_null", "(", "$", "email", ")", ")", "{", "$", "emailString", "=", "\" WHERE email = '$email'\"", ";", "}", "$", "countArray", "=", "null", ";", "$", "db", "=", "eZDB", "::", "instance", "(", ")", ";", "if", "(", "$", "enabled", "===", "false", ")", "{", "$", "countArray", "=", "$", "db", "->", "arrayQuery", "(", "\"SELECT count(*) AS count\"", ".", "\" FROM ezcomment_subscription\"", ".", "\" WHERE \"", ".", "\" content_id = $contentID\"", ".", "\" AND language_id = $languageID\"", ".", "\" AND subscription_type = '$subscriptionType'\"", ".", "\" AND subscriber_id IN\"", ".", "\"( SELECT id FROM ezcomment_subscriber\"", ".", "\"$emailString )\"", ")", ";", "}", "else", "if", "(", "$", "enabled", "===", "1", "||", "$", "enabled", "===", "0", ")", "{", "$", "enabledString", "=", "\"enabled = $enabled\"", ";", "if", "(", "$", "emailString", "!=", "''", ")", "{", "$", "enabledString", "=", "\" AND \"", ".", "$", "enabledString", ";", "}", "else", "{", "$", "enabledString", "=", "\" WHERE \"", ".", "$", "enabledString", ";", "}", "$", "countArray", "=", "$", "db", "->", "arrayQuery", "(", "\"SELECT count(*) AS count\"", ".", "\" FROM ezcomment_subscription\"", ".", "\" WHERE\"", ".", "\" content_id = $contentID\"", ".", "\" AND language_id = $languageID\"", ".", "\" AND subscription_type = '$subscriptionType'\"", ".", "\" AND subscriber_id IN\"", ".", "\" ( SELECT id FROM ezcomment_subscriber\"", ".", "$", "emailString", ".", "\"$enabledString )\"", ")", ";", "}", "else", "{", "return", "null", ";", "}", "$", "totalCount", "=", "$", "countArray", "[", "0", "]", "[", "'count'", "]", ";", "if", "(", "$", "totalCount", "===", "'0'", ")", "{", "return", "false", ";", "}", "else", "{", "return", "true", ";", "}", "}" ]
Check if the subscription exists by a given contentID @param string $contentID : the ID of content subscribed @param string $languageID : the language ID of content @param string $subscriptionType : type of the subscription @param string $email : email in table subscriber @param integer $enabled : 1/0 - check if the subscriber is enabled. Empty/false - not check if the subscriber is enabled @return boolean: true if existing, false if not, null if error happens
[ "Check", "if", "the", "subscription", "exists", "by", "a", "given", "contentID" ]
train
https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/classes/ezcomsubscription.php#L227-L285
ShaoZeMing/laravel-merchant
src/Tree.php
Tree.render
public function render() { Merchant::script($this->script()); view()->share([ 'path' => $this->path, 'keyName' => $this->model->getKeyName(), 'branchView' => $this->view['branch'], 'branchCallback' => $this->branchCallback, ]); return view($this->view['tree'], $this->variables())->render(); }
php
public function render() { Merchant::script($this->script()); view()->share([ 'path' => $this->path, 'keyName' => $this->model->getKeyName(), 'branchView' => $this->view['branch'], 'branchCallback' => $this->branchCallback, ]); return view($this->view['tree'], $this->variables())->render(); }
[ "public", "function", "render", "(", ")", "{", "Merchant", "::", "script", "(", "$", "this", "->", "script", "(", ")", ")", ";", "view", "(", ")", "->", "share", "(", "[", "'path'", "=>", "$", "this", "->", "path", ",", "'keyName'", "=>", "$", "this", "->", "model", "->", "getKeyName", "(", ")", ",", "'branchView'", "=>", "$", "this", "->", "view", "[", "'branch'", "]", ",", "'branchCallback'", "=>", "$", "this", "->", "branchCallback", ",", "]", ")", ";", "return", "view", "(", "$", "this", "->", "view", "[", "'tree'", "]", ",", "$", "this", "->", "variables", "(", ")", ")", "->", "render", "(", ")", ";", "}" ]
Render a tree. @return \Illuminate\Http\JsonResponse|string
[ "Render", "a", "tree", "." ]
train
https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Tree.php#L356-L368
fortis/silex-graphite
src/Graphite/Silex/Client/GraphiteClient.php
GraphiteClient.send
public function send($data) { $pieces = [ $this->config['apiKey'], $this->config['prefix'], $data.' '.time(), ]; $message = implode('.', $pieces).PHP_EOL; return $this->sendData($this->config['host'], $this->config['port'], $message); }
php
public function send($data) { $pieces = [ $this->config['apiKey'], $this->config['prefix'], $data.' '.time(), ]; $message = implode('.', $pieces).PHP_EOL; return $this->sendData($this->config['host'], $this->config['port'], $message); }
[ "public", "function", "send", "(", "$", "data", ")", "{", "$", "pieces", "=", "[", "$", "this", "->", "config", "[", "'apiKey'", "]", ",", "$", "this", "->", "config", "[", "'prefix'", "]", ",", "$", "data", ".", "' '", ".", "time", "(", ")", ",", "]", ";", "$", "message", "=", "implode", "(", "'.'", ",", "$", "pieces", ")", ".", "PHP_EOL", ";", "return", "$", "this", "->", "sendData", "(", "$", "this", "->", "config", "[", "'host'", "]", ",", "$", "this", "->", "config", "[", "'port'", "]", ",", "$", "message", ")", ";", "}" ]
Data to send to Graphite host @param string $data @return bool
[ "Data", "to", "send", "to", "Graphite", "host" ]
train
https://github.com/fortis/silex-graphite/blob/1faf4b53531c62d19b281b736a1dda326e127c7f/src/Graphite/Silex/Client/GraphiteClient.php#L21-L31
fortis/silex-graphite
src/Graphite/Silex/Client/GraphiteClient.php
GraphiteClient.sendData
protected function sendData($host, $port, $message) { $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); return socket_sendto($socket, $message, strlen($message), 0, $host, $port); }
php
protected function sendData($host, $port, $message) { $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); return socket_sendto($socket, $message, strlen($message), 0, $host, $port); }
[ "protected", "function", "sendData", "(", "$", "host", ",", "$", "port", ",", "$", "message", ")", "{", "$", "socket", "=", "socket_create", "(", "AF_INET", ",", "SOCK_DGRAM", ",", "SOL_UDP", ")", ";", "return", "socket_sendto", "(", "$", "socket", ",", "$", "message", ",", "strlen", "(", "$", "message", ")", ",", "0", ",", "$", "host", ",", "$", "port", ")", ";", "}" ]
@param string $host @param int $port @param string $message @return int
[ "@param", "string", "$host", "@param", "int", "$port", "@param", "string", "$message" ]
train
https://github.com/fortis/silex-graphite/blob/1faf4b53531c62d19b281b736a1dda326e127c7f/src/Graphite/Silex/Client/GraphiteClient.php#L40-L45
WellCommerce/AppBundle
Repository/LocaleRepository.php
LocaleRepository.getAvailableLocaleCodes
public function getAvailableLocaleCodes() : array { if (empty($this->currentLocales)) { $this->currentLocales = $this->getAvailableLocales(); } $codes = []; foreach ($this->currentLocales as $locale) { $codes[$locale['code']] = $locale['code']; } return $codes; }
php
public function getAvailableLocaleCodes() : array { if (empty($this->currentLocales)) { $this->currentLocales = $this->getAvailableLocales(); } $codes = []; foreach ($this->currentLocales as $locale) { $codes[$locale['code']] = $locale['code']; } return $codes; }
[ "public", "function", "getAvailableLocaleCodes", "(", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "this", "->", "currentLocales", ")", ")", "{", "$", "this", "->", "currentLocales", "=", "$", "this", "->", "getAvailableLocales", "(", ")", ";", "}", "$", "codes", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "currentLocales", "as", "$", "locale", ")", "{", "$", "codes", "[", "$", "locale", "[", "'code'", "]", "]", "=", "$", "locale", "[", "'code'", "]", ";", "}", "return", "$", "codes", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/AppBundle/blob/2add687d1c898dd0b24afd611d896e3811a0eac3/Repository/LocaleRepository.php#L29-L42
WellCommerce/AppBundle
Repository/LocaleRepository.php
LocaleRepository.getLocaleNames
public function getLocaleNames() : array { $locales = Intl::getLocaleBundle()->getLocaleNames(); $Data = []; foreach ($locales as $locale => $name) { $Data[$locale] = sprintf('%s (%s)', $name, $locale); } return $Data; }
php
public function getLocaleNames() : array { $locales = Intl::getLocaleBundle()->getLocaleNames(); $Data = []; foreach ($locales as $locale => $name) { $Data[$locale] = sprintf('%s (%s)', $name, $locale); } return $Data; }
[ "public", "function", "getLocaleNames", "(", ")", ":", "array", "{", "$", "locales", "=", "Intl", "::", "getLocaleBundle", "(", ")", "->", "getLocaleNames", "(", ")", ";", "$", "Data", "=", "[", "]", ";", "foreach", "(", "$", "locales", "as", "$", "locale", "=>", "$", "name", ")", "{", "$", "Data", "[", "$", "locale", "]", "=", "sprintf", "(", "'%s (%s)'", ",", "$", "name", ",", "$", "locale", ")", ";", "}", "return", "$", "Data", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/AppBundle/blob/2add687d1c898dd0b24afd611d896e3811a0eac3/Repository/LocaleRepository.php#L58-L69
alevilar/ristorantino-vendor
Product/Model/Producto.php
Producto.beforeSave
public function beforeSave($options = array()) { if ( !empty($this->data['Producto']['precio']) ) { $this->data['Producto']['precio'] = formatearPrecio($this->data['Producto']['precio']); } if ( !empty($this->data['ProductosPreciosFuturo']['precio']) ) { $this->data['ProductosPreciosFuturo']['precio'] = formatearPrecio($this->data['ProductosPreciosFuturo']['precio']); } return true; }
php
public function beforeSave($options = array()) { if ( !empty($this->data['Producto']['precio']) ) { $this->data['Producto']['precio'] = formatearPrecio($this->data['Producto']['precio']); } if ( !empty($this->data['ProductosPreciosFuturo']['precio']) ) { $this->data['ProductosPreciosFuturo']['precio'] = formatearPrecio($this->data['ProductosPreciosFuturo']['precio']); } return true; }
[ "public", "function", "beforeSave", "(", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "data", "[", "'Producto'", "]", "[", "'precio'", "]", ")", ")", "{", "$", "this", "->", "data", "[", "'Producto'", "]", "[", "'precio'", "]", "=", "formatearPrecio", "(", "$", "this", "->", "data", "[", "'Producto'", "]", "[", "'precio'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "data", "[", "'ProductosPreciosFuturo'", "]", "[", "'precio'", "]", ")", ")", "{", "$", "this", "->", "data", "[", "'ProductosPreciosFuturo'", "]", "[", "'precio'", "]", "=", "formatearPrecio", "(", "$", "this", "->", "data", "[", "'ProductosPreciosFuturo'", "]", "[", "'precio'", "]", ")", ";", "}", "return", "true", ";", "}" ]
}
[ "}" ]
train
https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Product/Model/Producto.php#L252-L263
ArrowSphere/Client
src/xAC/MagicFactoryTrait.php
MagicFactoryTrait.__callstatic
public static function __callstatic($name, $arguments) { // Get global services or entity services $services = Client::getServices(isset($arguments['context']) ? $arguments['context'] : null); if (array_key_exists($name, $services)) { $service = $services[$name]; switch ($service['type']) { case 'collection': return new Cursor( $service, Client::getInstance(), isset($arguments['context']) ? $arguments['context'] : null ); break; case 'entity': return new Entity( $service, Client::getInstance(), isset($arguments[0]) ? $arguments[0] : null ); break; // $name represents an action on an entity case 'action': return new Action( $service, $arguments['context'], Client::getInstance() ); break; default: throw new \Exception("Don't know of any service type named '$name'"); break; } } else { throw new \Exception("can't find service definition for '$name'"); } }
php
public static function __callstatic($name, $arguments) { // Get global services or entity services $services = Client::getServices(isset($arguments['context']) ? $arguments['context'] : null); if (array_key_exists($name, $services)) { $service = $services[$name]; switch ($service['type']) { case 'collection': return new Cursor( $service, Client::getInstance(), isset($arguments['context']) ? $arguments['context'] : null ); break; case 'entity': return new Entity( $service, Client::getInstance(), isset($arguments[0]) ? $arguments[0] : null ); break; // $name represents an action on an entity case 'action': return new Action( $service, $arguments['context'], Client::getInstance() ); break; default: throw new \Exception("Don't know of any service type named '$name'"); break; } } else { throw new \Exception("can't find service definition for '$name'"); } }
[ "public", "static", "function", "__callstatic", "(", "$", "name", ",", "$", "arguments", ")", "{", "// Get global services or entity services", "$", "services", "=", "Client", "::", "getServices", "(", "isset", "(", "$", "arguments", "[", "'context'", "]", ")", "?", "$", "arguments", "[", "'context'", "]", ":", "null", ")", ";", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "services", ")", ")", "{", "$", "service", "=", "$", "services", "[", "$", "name", "]", ";", "switch", "(", "$", "service", "[", "'type'", "]", ")", "{", "case", "'collection'", ":", "return", "new", "Cursor", "(", "$", "service", ",", "Client", "::", "getInstance", "(", ")", ",", "isset", "(", "$", "arguments", "[", "'context'", "]", ")", "?", "$", "arguments", "[", "'context'", "]", ":", "null", ")", ";", "break", ";", "case", "'entity'", ":", "return", "new", "Entity", "(", "$", "service", ",", "Client", "::", "getInstance", "(", ")", ",", "isset", "(", "$", "arguments", "[", "0", "]", ")", "?", "$", "arguments", "[", "0", "]", ":", "null", ")", ";", "break", ";", "// $name represents an action on an entity", "case", "'action'", ":", "return", "new", "Action", "(", "$", "service", ",", "$", "arguments", "[", "'context'", "]", ",", "Client", "::", "getInstance", "(", ")", ")", ";", "break", ";", "default", ":", "throw", "new", "\\", "Exception", "(", "\"Don't know of any service type named '$name'\"", ")", ";", "break", ";", "}", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "\"can't find service definition for '$name'\"", ")", ";", "}", "}" ]
Magic method for static calls @param string $name @param array $arguments @return mixed
[ "Magic", "method", "for", "static", "calls" ]
train
https://github.com/ArrowSphere/Client/blob/6608f8257060375e7d3a27c485b23268b73f6ef7/src/xAC/MagicFactoryTrait.php#L17-L59
ajgarlag/AjglSessionConcurrency
src/Http/Session/CompositeSessionAuthenticationStrategy.php
CompositeSessionAuthenticationStrategy.onAuthentication
public function onAuthentication(Request $request, TokenInterface $token) { foreach ($this->delegateStrategies as $strategy) { $strategy->onAuthentication($request, $token); } }
php
public function onAuthentication(Request $request, TokenInterface $token) { foreach ($this->delegateStrategies as $strategy) { $strategy->onAuthentication($request, $token); } }
[ "public", "function", "onAuthentication", "(", "Request", "$", "request", ",", "TokenInterface", "$", "token", ")", "{", "foreach", "(", "$", "this", "->", "delegateStrategies", "as", "$", "strategy", ")", "{", "$", "strategy", "->", "onAuthentication", "(", "$", "request", ",", "$", "token", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/ajgarlag/AjglSessionConcurrency/blob/daa3b1ff3ad4951947f7192e12b2496555e135fb/src/Http/Session/CompositeSessionAuthenticationStrategy.php#L44-L49
Eresus/EresusCMS
src/core/content.php
TContent.adminRender
public function adminRender(Eresus_CMS_Request $request) { if (!UserRights(EDITOR)) { return ''; } $legacyKernel = Eresus_CMS::getLegacyKernel(); $plugins = Eresus_Plugin_Registry::getInstance(); /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = ''; $sections = Eresus_Kernel::app()->getLegacyKernel()->sections; $item = $sections->get(arg('section', 'int')); $page->id = $item['id']; if (!array_key_exists($item['type'], $plugins->list)) { switch ($item['type']) { case 'default': $editor = new ContentPlugin(); if (arg('update')) { $editor->update(); } else { $result = $editor->adminRenderContent(); } break; case 'list': if (arg('update')) { $item['content'] = arg('content', 'dbsafe'); $legacyKernel->sections->update($item); HTTP::redirect(arg('submitURL')); } else { $form = array( 'name' => 'editURL', 'caption' => ADM_EDIT, 'width' => '100%', 'fields' => array ( array('type'=>'hidden','name'=>'update', 'value'=>$item['id']), array ('type' => 'html', 'name' => 'content', 'label' => admTemplListLabel, 'height' => '300px', 'value'=>isset($item['content'])?$item['content']:'$(items)'), ), 'buttons' => array('apply', 'cancel'), ); $result = $page->renderForm($form); } break; case 'url': $controller = new Eresus_Admin_Controller_Content_Url(); break; default: $result = $page-> box(sprintf(errContentPluginNotFound, $item['type']), 'errorBox', errError); break; } if (isset($controller) && $controller instanceof Eresus_Admin_Controller_Content_Interface) { $result = $controller->getHtml($request); } } else { $plugin = $plugins->load($item['type']); if (false === $plugin) { return ErrorBox( sprintf(_('Отсутствует модуль расширения для работы с разделами типа "%s"'), $item['type'])); } $page->module = $plugin; $provider = new Eresus_Admin_ContentProvider_Plugin($plugin); $result = $provider->adminRenderContent($request); } return $result; }
php
public function adminRender(Eresus_CMS_Request $request) { if (!UserRights(EDITOR)) { return ''; } $legacyKernel = Eresus_CMS::getLegacyKernel(); $plugins = Eresus_Plugin_Registry::getInstance(); /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = ''; $sections = Eresus_Kernel::app()->getLegacyKernel()->sections; $item = $sections->get(arg('section', 'int')); $page->id = $item['id']; if (!array_key_exists($item['type'], $plugins->list)) { switch ($item['type']) { case 'default': $editor = new ContentPlugin(); if (arg('update')) { $editor->update(); } else { $result = $editor->adminRenderContent(); } break; case 'list': if (arg('update')) { $item['content'] = arg('content', 'dbsafe'); $legacyKernel->sections->update($item); HTTP::redirect(arg('submitURL')); } else { $form = array( 'name' => 'editURL', 'caption' => ADM_EDIT, 'width' => '100%', 'fields' => array ( array('type'=>'hidden','name'=>'update', 'value'=>$item['id']), array ('type' => 'html', 'name' => 'content', 'label' => admTemplListLabel, 'height' => '300px', 'value'=>isset($item['content'])?$item['content']:'$(items)'), ), 'buttons' => array('apply', 'cancel'), ); $result = $page->renderForm($form); } break; case 'url': $controller = new Eresus_Admin_Controller_Content_Url(); break; default: $result = $page-> box(sprintf(errContentPluginNotFound, $item['type']), 'errorBox', errError); break; } if (isset($controller) && $controller instanceof Eresus_Admin_Controller_Content_Interface) { $result = $controller->getHtml($request); } } else { $plugin = $plugins->load($item['type']); if (false === $plugin) { return ErrorBox( sprintf(_('Отсутствует модуль расширения для работы с разделами типа "%s"'), $item['type'])); } $page->module = $plugin; $provider = new Eresus_Admin_ContentProvider_Plugin($plugin); $result = $provider->adminRenderContent($request); } return $result; }
[ "public", "function", "adminRender", "(", "Eresus_CMS_Request", "$", "request", ")", "{", "if", "(", "!", "UserRights", "(", "EDITOR", ")", ")", "{", "return", "''", ";", "}", "$", "legacyKernel", "=", "Eresus_CMS", "::", "getLegacyKernel", "(", ")", ";", "$", "plugins", "=", "Eresus_Plugin_Registry", "::", "getInstance", "(", ")", ";", "/** @var TAdminUI $page */", "$", "page", "=", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", ";", "$", "result", "=", "''", ";", "$", "sections", "=", "Eresus_Kernel", "::", "app", "(", ")", "->", "getLegacyKernel", "(", ")", "->", "sections", ";", "$", "item", "=", "$", "sections", "->", "get", "(", "arg", "(", "'section'", ",", "'int'", ")", ")", ";", "$", "page", "->", "id", "=", "$", "item", "[", "'id'", "]", ";", "if", "(", "!", "array_key_exists", "(", "$", "item", "[", "'type'", "]", ",", "$", "plugins", "->", "list", ")", ")", "{", "switch", "(", "$", "item", "[", "'type'", "]", ")", "{", "case", "'default'", ":", "$", "editor", "=", "new", "ContentPlugin", "(", ")", ";", "if", "(", "arg", "(", "'update'", ")", ")", "{", "$", "editor", "->", "update", "(", ")", ";", "}", "else", "{", "$", "result", "=", "$", "editor", "->", "adminRenderContent", "(", ")", ";", "}", "break", ";", "case", "'list'", ":", "if", "(", "arg", "(", "'update'", ")", ")", "{", "$", "item", "[", "'content'", "]", "=", "arg", "(", "'content'", ",", "'dbsafe'", ")", ";", "$", "legacyKernel", "->", "sections", "->", "update", "(", "$", "item", ")", ";", "HTTP", "::", "redirect", "(", "arg", "(", "'submitURL'", ")", ")", ";", "}", "else", "{", "$", "form", "=", "array", "(", "'name'", "=>", "'editURL'", ",", "'caption'", "=>", "ADM_EDIT", ",", "'width'", "=>", "'100%'", ",", "'fields'", "=>", "array", "(", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'update'", ",", "'value'", "=>", "$", "item", "[", "'id'", "]", ")", ",", "array", "(", "'type'", "=>", "'html'", ",", "'name'", "=>", "'content'", ",", "'label'", "=>", "admTemplListLabel", ",", "'height'", "=>", "'300px'", ",", "'value'", "=>", "isset", "(", "$", "item", "[", "'content'", "]", ")", "?", "$", "item", "[", "'content'", "]", ":", "'$(items)'", ")", ",", ")", ",", "'buttons'", "=>", "array", "(", "'apply'", ",", "'cancel'", ")", ",", ")", ";", "$", "result", "=", "$", "page", "->", "renderForm", "(", "$", "form", ")", ";", "}", "break", ";", "case", "'url'", ":", "$", "controller", "=", "new", "Eresus_Admin_Controller_Content_Url", "(", ")", ";", "break", ";", "default", ":", "$", "result", "=", "$", "page", "->", "box", "(", "sprintf", "(", "errContentPluginNotFound", ",", "$", "item", "[", "'type'", "]", ")", ",", "'errorBox'", ",", "errError", ")", ";", "break", ";", "}", "if", "(", "isset", "(", "$", "controller", ")", "&&", "$", "controller", "instanceof", "Eresus_Admin_Controller_Content_Interface", ")", "{", "$", "result", "=", "$", "controller", "->", "getHtml", "(", "$", "request", ")", ";", "}", "}", "else", "{", "$", "plugin", "=", "$", "plugins", "->", "load", "(", "$", "item", "[", "'type'", "]", ")", ";", "if", "(", "false", "===", "$", "plugin", ")", "{", "return", "ErrorBox", "(", "sprintf", "(", "_", "(", "'Отсутствует модуль расширения для работы с разделами типа \"%s\"'),", "", "", "$", "item", "[", "'type'", "]", ")", ")", ";", "}", "$", "page", "->", "module", "=", "$", "plugin", ";", "$", "provider", "=", "new", "Eresus_Admin_ContentProvider_Plugin", "(", "$", "plugin", ")", ";", "$", "result", "=", "$", "provider", "->", "adminRenderContent", "(", "$", "request", ")", ";", "}", "return", "$", "result", ";", "}" ]
Возвращает разметку интерфейса управления контентом текущего раздела @param Eresus_CMS_Request $request @return string|Eresus_HTTP_Response HTML
[ "Возвращает", "разметку", "интерфейса", "управления", "контентом", "текущего", "раздела" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/content.php#L46-L129
php-lug/lug
src/Bundle/GridBundle/Form/Type/Batch/GridBatchType.php
GridBatchType.buildForm
public function buildForm(FormBuilderInterface $builder, array $options) { $grid = $options['grid']; $driver = $grid->getDefinition()->getResource()->getDriver(); $builder ->add('all', GridBatchAllType::class, ['grid' => $grid]) ->add('type', GridBatchTypeType::class, ['grid' => $grid]) ->add('batch', SubmitType::class, ['label' => 'lug.batch.submit']) ->addEventSubscriber($this->gridBatchSubscriberRegistry[$driver]); }
php
public function buildForm(FormBuilderInterface $builder, array $options) { $grid = $options['grid']; $driver = $grid->getDefinition()->getResource()->getDriver(); $builder ->add('all', GridBatchAllType::class, ['grid' => $grid]) ->add('type', GridBatchTypeType::class, ['grid' => $grid]) ->add('batch', SubmitType::class, ['label' => 'lug.batch.submit']) ->addEventSubscriber($this->gridBatchSubscriberRegistry[$driver]); }
[ "public", "function", "buildForm", "(", "FormBuilderInterface", "$", "builder", ",", "array", "$", "options", ")", "{", "$", "grid", "=", "$", "options", "[", "'grid'", "]", ";", "$", "driver", "=", "$", "grid", "->", "getDefinition", "(", ")", "->", "getResource", "(", ")", "->", "getDriver", "(", ")", ";", "$", "builder", "->", "add", "(", "'all'", ",", "GridBatchAllType", "::", "class", ",", "[", "'grid'", "=>", "$", "grid", "]", ")", "->", "add", "(", "'type'", ",", "GridBatchTypeType", "::", "class", ",", "[", "'grid'", "=>", "$", "grid", "]", ")", "->", "add", "(", "'batch'", ",", "SubmitType", "::", "class", ",", "[", "'label'", "=>", "'lug.batch.submit'", "]", ")", "->", "addEventSubscriber", "(", "$", "this", "->", "gridBatchSubscriberRegistry", "[", "$", "driver", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Form/Type/Batch/GridBatchType.php#L42-L52
Eresus/EresusCMS
src/core/i18n.php
I18n.getInstance
static public function getInstance() { if (!self::$instance) { self::$instance = new I18n(Eresus_Kernel::app()->getFsRoot() . '/lang'); } return self::$instance; }
php
static public function getInstance() { if (!self::$instance) { self::$instance = new I18n(Eresus_Kernel::app()->getFsRoot() . '/lang'); } return self::$instance; }
[ "static", "public", "function", "getInstance", "(", ")", "{", "if", "(", "!", "self", "::", "$", "instance", ")", "{", "self", "::", "$", "instance", "=", "new", "I18n", "(", "Eresus_Kernel", "::", "app", "(", ")", "->", "getFsRoot", "(", ")", ".", "'/lang'", ")", ";", "}", "return", "self", "::", "$", "instance", ";", "}" ]
Возвращает экземпляр-одиночку @return I18n
[ "Возвращает", "экземпляр", "-", "одиночку" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/i18n.php#L66-L74
NuclearCMS/Hierarchy
src/Tags/TagRepository.php
TagRepository.getTagAndSetLocale
public function getTagAndSetLocale($name, $locale = null) { $tag = $this->getTag($name); // Override locale or use tag locale // this is for when a tag does not have to be translated // and the app locale is determined via route parameter (etiket|tag) $locale = $locale ?: $tag->getLocaleForName($name); set_app_locale($locale); return $tag; }
php
public function getTagAndSetLocale($name, $locale = null) { $tag = $this->getTag($name); // Override locale or use tag locale // this is for when a tag does not have to be translated // and the app locale is determined via route parameter (etiket|tag) $locale = $locale ?: $tag->getLocaleForName($name); set_app_locale($locale); return $tag; }
[ "public", "function", "getTagAndSetLocale", "(", "$", "name", ",", "$", "locale", "=", "null", ")", "{", "$", "tag", "=", "$", "this", "->", "getTag", "(", "$", "name", ")", ";", "// Override locale or use tag locale", "// this is for when a tag does not have to be translated", "// and the app locale is determined via route parameter (etiket|tag)", "$", "locale", "=", "$", "locale", "?", ":", "$", "tag", "->", "getLocaleForName", "(", "$", "name", ")", ";", "set_app_locale", "(", "$", "locale", ")", ";", "return", "$", "tag", ";", "}" ]
Returns a tag by name and sets the locale @param string $name @param string $locale @return Tag
[ "Returns", "a", "tag", "by", "name", "and", "sets", "the", "locale" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Tags/TagRepository.php#L27-L39
OKTOTV/OktolabMediaBundle
Controller/EpisodeController.php
EpisodeController.createAction
public function createAction(Request $request) { $entity = $this->get('oktolab_media')->createEpisode(); $form = $this->createCreateForm($entity); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); $this->get('session')->getFlashBag()->add( 'success', 'oktolab_media.success_create_episode' ); return $this->redirect( $this->generateUrl( 'oktolab_episode_show', ['uniqID' => $entity->getUniqID()] ) ); } else { $this->get('session')->getFlashBag()->add( 'error', 'oktolab_media.error_create_episode' ); } return [ 'entity' => $entity, 'form' => $form->createView(), ]; }
php
public function createAction(Request $request) { $entity = $this->get('oktolab_media')->createEpisode(); $form = $this->createCreateForm($entity); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); $this->get('session')->getFlashBag()->add( 'success', 'oktolab_media.success_create_episode' ); return $this->redirect( $this->generateUrl( 'oktolab_episode_show', ['uniqID' => $entity->getUniqID()] ) ); } else { $this->get('session')->getFlashBag()->add( 'error', 'oktolab_media.error_create_episode' ); } return [ 'entity' => $entity, 'form' => $form->createView(), ]; }
[ "public", "function", "createAction", "(", "Request", "$", "request", ")", "{", "$", "entity", "=", "$", "this", "->", "get", "(", "'oktolab_media'", ")", "->", "createEpisode", "(", ")", ";", "$", "form", "=", "$", "this", "->", "createCreateForm", "(", "$", "entity", ")", ";", "$", "form", "->", "handleRequest", "(", "$", "request", ")", ";", "if", "(", "$", "form", "->", "isValid", "(", ")", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getManager", "(", ")", ";", "$", "em", "->", "persist", "(", "$", "entity", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "$", "this", "->", "get", "(", "'session'", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "'success'", ",", "'oktolab_media.success_create_episode'", ")", ";", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "generateUrl", "(", "'oktolab_episode_show'", ",", "[", "'uniqID'", "=>", "$", "entity", "->", "getUniqID", "(", ")", "]", ")", ")", ";", "}", "else", "{", "$", "this", "->", "get", "(", "'session'", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "'error'", ",", "'oktolab_media.error_create_episode'", ")", ";", "}", "return", "[", "'entity'", "=>", "$", "entity", ",", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", "]", ";", "}" ]
Creates a new Episode entity. @Route("/", name="oktolab_episode_create") @Method("POST") @Template("OktolabMediaBundle:Episode:new.html.twig")
[ "Creates", "a", "new", "Episode", "entity", "." ]
train
https://github.com/OKTOTV/OktolabMediaBundle/blob/f9c1eac4f6b19d2ab25288b301dd0d9350478bb3/Controller/EpisodeController.php#L35-L68
OKTOTV/OktolabMediaBundle
Controller/EpisodeController.php
EpisodeController.createCreateForm
private function createCreateForm(Episode $entity) { $form = $this->createForm(EpisodeType::class, $entity, array( 'action' => $this->generateUrl('oktolab_episode_create'), 'method' => 'POST', )); $form->add( 'submit', SubmitType::class, [ 'label' => 'oktolab_media.new_episode_create_button', 'attr' => ['class' => 'btn btn-primary'] ] ); return $form; }
php
private function createCreateForm(Episode $entity) { $form = $this->createForm(EpisodeType::class, $entity, array( 'action' => $this->generateUrl('oktolab_episode_create'), 'method' => 'POST', )); $form->add( 'submit', SubmitType::class, [ 'label' => 'oktolab_media.new_episode_create_button', 'attr' => ['class' => 'btn btn-primary'] ] ); return $form; }
[ "private", "function", "createCreateForm", "(", "Episode", "$", "entity", ")", "{", "$", "form", "=", "$", "this", "->", "createForm", "(", "EpisodeType", "::", "class", ",", "$", "entity", ",", "array", "(", "'action'", "=>", "$", "this", "->", "generateUrl", "(", "'oktolab_episode_create'", ")", ",", "'method'", "=>", "'POST'", ",", ")", ")", ";", "$", "form", "->", "add", "(", "'submit'", ",", "SubmitType", "::", "class", ",", "[", "'label'", "=>", "'oktolab_media.new_episode_create_button'", ",", "'attr'", "=>", "[", "'class'", "=>", "'btn btn-primary'", "]", "]", ")", ";", "return", "$", "form", ";", "}" ]
Creates a form to create a Episode entity. @param Episode $entity The entity @return \Symfony\Component\Form\Form The form
[ "Creates", "a", "form", "to", "create", "a", "Episode", "entity", "." ]
train
https://github.com/OKTOTV/OktolabMediaBundle/blob/f9c1eac4f6b19d2ab25288b301dd0d9350478bb3/Controller/EpisodeController.php#L99-L116