id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
27,000
antonmedv/purephp
src/Server.php
Server.onConnection
public function onConnection(ConnectionInterface $connection) { $this->log('New connection from ' . $connection->getRemoteAddress()); $buffer = ''; $connection->on('data', function ($data) use (&$buffer, &$connection) { $buffer .= $data; if (strpos($buffer, Client::END_OF_COMMAND)) { $chunks = explode(Client::END_OF_COMMAND, $buffer); $count = count($chunks); $buffer = $chunks[$count - 1]; for ($i = 0; $i < $count - 1; $i++) { $command = json_decode($chunks[$i], true); $this->runCommand($command, $connection); } } }); }
php
public function onConnection(ConnectionInterface $connection) { $this->log('New connection from ' . $connection->getRemoteAddress()); $buffer = ''; $connection->on('data', function ($data) use (&$buffer, &$connection) { $buffer .= $data; if (strpos($buffer, Client::END_OF_COMMAND)) { $chunks = explode(Client::END_OF_COMMAND, $buffer); $count = count($chunks); $buffer = $chunks[$count - 1]; for ($i = 0; $i < $count - 1; $i++) { $command = json_decode($chunks[$i], true); $this->runCommand($command, $connection); } } }); }
[ "public", "function", "onConnection", "(", "ConnectionInterface", "$", "connection", ")", "{", "$", "this", "->", "log", "(", "'New connection from '", ".", "$", "connection", "->", "getRemoteAddress", "(", ")", ")", ";", "$", "buffer", "=", "''", ";", "$", "connection", "->", "on", "(", "'data'", ",", "function", "(", "$", "data", ")", "use", "(", "&", "$", "buffer", ",", "&", "$", "connection", ")", "{", "$", "buffer", ".=", "$", "data", ";", "if", "(", "strpos", "(", "$", "buffer", ",", "Client", "::", "END_OF_COMMAND", ")", ")", "{", "$", "chunks", "=", "explode", "(", "Client", "::", "END_OF_COMMAND", ",", "$", "buffer", ")", ";", "$", "count", "=", "count", "(", "$", "chunks", ")", ";", "$", "buffer", "=", "$", "chunks", "[", "$", "count", "-", "1", "]", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", "-", "1", ";", "$", "i", "++", ")", "{", "$", "command", "=", "json_decode", "(", "$", "chunks", "[", "$", "i", "]", ",", "true", ")", ";", "$", "this", "->", "runCommand", "(", "$", "command", ",", "$", "connection", ")", ";", "}", "}", "}", ")", ";", "}" ]
On every new connection add event handler to receive commands from clients. @param ConnectionInterface $connection
[ "On", "every", "new", "connection", "add", "event", "handler", "to", "receive", "commands", "from", "clients", "." ]
05aa6b44cea9b0457ec1e5e67e8278cd89d47f21
https://github.com/antonmedv/purephp/blob/05aa6b44cea9b0457ec1e5e67e8278cd89d47f21/src/Server.php#L87-L106
27,001
antonmedv/purephp
src/Server.php
Server.runCommand
private function runCommand($arguments, ConnectionInterface $connection) { try { $commandClass = array_shift($arguments); if (null !== $this->getLogger()) { $this->log( 'Command from ' . $connection->getRemoteAddress() . ": [$commandClass] " . join(', ', array_map('json_encode', $arguments)) ); } if (isset($this->commands[$commandClass])) { $command = $this->commands[$commandClass]; } else { if (!class_exists($commandClass)) { throw new \RuntimeException("Command class `$commandClass` does not found."); } $command = new $commandClass($this); if (!$command instanceof Command\CommandInterface) { throw new \RuntimeException("Every command must implement Command\\CommandInterface."); } $this->commands[$commandClass] = $command; } $result = $command->run($arguments, $connection); $result = [self::RESULT, $result]; } catch (\Exception $e) { $result = [self::EXCEPTION, get_class($e), $e->getMessage()]; $this->log('Exception: ' . $e->getMessage()); } $connection->write(json_encode($result) . self::END_OF_RESULT); }
php
private function runCommand($arguments, ConnectionInterface $connection) { try { $commandClass = array_shift($arguments); if (null !== $this->getLogger()) { $this->log( 'Command from ' . $connection->getRemoteAddress() . ": [$commandClass] " . join(', ', array_map('json_encode', $arguments)) ); } if (isset($this->commands[$commandClass])) { $command = $this->commands[$commandClass]; } else { if (!class_exists($commandClass)) { throw new \RuntimeException("Command class `$commandClass` does not found."); } $command = new $commandClass($this); if (!$command instanceof Command\CommandInterface) { throw new \RuntimeException("Every command must implement Command\\CommandInterface."); } $this->commands[$commandClass] = $command; } $result = $command->run($arguments, $connection); $result = [self::RESULT, $result]; } catch (\Exception $e) { $result = [self::EXCEPTION, get_class($e), $e->getMessage()]; $this->log('Exception: ' . $e->getMessage()); } $connection->write(json_encode($result) . self::END_OF_RESULT); }
[ "private", "function", "runCommand", "(", "$", "arguments", ",", "ConnectionInterface", "$", "connection", ")", "{", "try", "{", "$", "commandClass", "=", "array_shift", "(", "$", "arguments", ")", ";", "if", "(", "null", "!==", "$", "this", "->", "getLogger", "(", ")", ")", "{", "$", "this", "->", "log", "(", "'Command from '", ".", "$", "connection", "->", "getRemoteAddress", "(", ")", ".", "\": [$commandClass] \"", ".", "join", "(", "', '", ",", "array_map", "(", "'json_encode'", ",", "$", "arguments", ")", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "commands", "[", "$", "commandClass", "]", ")", ")", "{", "$", "command", "=", "$", "this", "->", "commands", "[", "$", "commandClass", "]", ";", "}", "else", "{", "if", "(", "!", "class_exists", "(", "$", "commandClass", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"Command class `$commandClass` does not found.\"", ")", ";", "}", "$", "command", "=", "new", "$", "commandClass", "(", "$", "this", ")", ";", "if", "(", "!", "$", "command", "instanceof", "Command", "\\", "CommandInterface", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"Every command must implement Command\\\\CommandInterface.\"", ")", ";", "}", "$", "this", "->", "commands", "[", "$", "commandClass", "]", "=", "$", "command", ";", "}", "$", "result", "=", "$", "command", "->", "run", "(", "$", "arguments", ",", "$", "connection", ")", ";", "$", "result", "=", "[", "self", "::", "RESULT", ",", "$", "result", "]", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "result", "=", "[", "self", "::", "EXCEPTION", ",", "get_class", "(", "$", "e", ")", ",", "$", "e", "->", "getMessage", "(", ")", "]", ";", "$", "this", "->", "log", "(", "'Exception: '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "$", "connection", "->", "write", "(", "json_encode", "(", "$", "result", ")", ".", "self", "::", "END_OF_RESULT", ")", ";", "}" ]
Detect and run command received from client. @param array $arguments @param ConnectionInterface $connection
[ "Detect", "and", "run", "command", "received", "from", "client", "." ]
05aa6b44cea9b0457ec1e5e67e8278cd89d47f21
https://github.com/antonmedv/purephp/blob/05aa6b44cea9b0457ec1e5e67e8278cd89d47f21/src/Server.php#L113-L156
27,002
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Attribute/Import/Xml/Standard.php
Standard.getItems
protected function getItems( array $nodes, array $ref ) { $keys = []; foreach( $nodes as $node ) { if( ( $attr = $node->attributes->getNamedItem( 'ref' ) ) !== null ) { $keys[] = $attr->nodeValue; } } $manager = \Aimeos\MShop::create( $this->getContext(), 'attribute' ); $search = $manager->createSearch()->setSlice( 0, count( $keys ) ); $search->setConditions( $search->compare( '==', 'attribute.key', $keys ) ); return $manager->searchItems( $search, $ref ); }
php
protected function getItems( array $nodes, array $ref ) { $keys = []; foreach( $nodes as $node ) { if( ( $attr = $node->attributes->getNamedItem( 'ref' ) ) !== null ) { $keys[] = $attr->nodeValue; } } $manager = \Aimeos\MShop::create( $this->getContext(), 'attribute' ); $search = $manager->createSearch()->setSlice( 0, count( $keys ) ); $search->setConditions( $search->compare( '==', 'attribute.key', $keys ) ); return $manager->searchItems( $search, $ref ); }
[ "protected", "function", "getItems", "(", "array", "$", "nodes", ",", "array", "$", "ref", ")", "{", "$", "keys", "=", "[", "]", ";", "foreach", "(", "$", "nodes", "as", "$", "node", ")", "{", "if", "(", "(", "$", "attr", "=", "$", "node", "->", "attributes", "->", "getNamedItem", "(", "'ref'", ")", ")", "!==", "null", ")", "{", "$", "keys", "[", "]", "=", "$", "attr", "->", "nodeValue", ";", "}", "}", "$", "manager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "this", "->", "getContext", "(", ")", ",", "'attribute'", ")", ";", "$", "search", "=", "$", "manager", "->", "createSearch", "(", ")", "->", "setSlice", "(", "0", ",", "count", "(", "$", "keys", ")", ")", ";", "$", "search", "->", "setConditions", "(", "$", "search", "->", "compare", "(", "'=='", ",", "'attribute.key'", ",", "$", "keys", ")", ")", ";", "return", "$", "manager", "->", "searchItems", "(", "$", "search", ",", "$", "ref", ")", ";", "}" ]
Returns the attribute items for the given nodes @param \DomElement[] $nodes List of XML attribute item nodes @param string[] $ref Domain names of referenced items that should be fetched too @return \Aimeos\MShop\Attribute\Item\Iface[] Associative list of attribute items with IDs as keys
[ "Returns", "the", "attribute", "items", "for", "the", "given", "nodes" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Attribute/Import/Xml/Standard.php#L134-L150
27,003
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Product/Export/Sitemap/Standard.php
Standard.addItems
protected function addItems( \Aimeos\MW\Container\Content\Iface $content, array $items ) { $config = $this->getContext()->getConfig(); /** controller/jobs/product/export/sitemap/changefreq * Change frequency of the products * * Depending on how often the product content changes (e.g. price updates) * and the site map files are generated you can give search engines a * hint how often they should reindex your site. The site map schema * allows a few pre-defined strings for the change frequency: * * always * * hourly * * daily * * weekly * * monthly * * yearly * * never * * More information can be found at * {@link http://www.sitemaps.org/protocol.html#xmlTagDefinitions sitemap.org} * * @param string One of the pre-defined strings (see description) * @since 2015.01 * @category User * @category Developer * @see controller/jobs/product/export/sitemap/container/options * @see controller/jobs/product/export/sitemap/location * @see controller/jobs/product/export/sitemap/max-items * @see controller/jobs/product/export/sitemap/max-query */ $changefreq = $config->get( 'controller/jobs/product/export/sitemap/changefreq', 'daily' ); /** controller/jobs/product/export/sitemap/standard/template-items * Relative path to the XML items template of the product site map job controller. * * The template file contains the XML code and processing instructions * to generate the site map files. The configuration string is the path * to the template file relative to the templates directory (usually in * controller/jobs/templates). * * You can overwrite the template file configuration in extensions and * provide alternative templates. These alternative templates should be * named like the default one but with the string "standard" replaced by * an unique name. You may use the name of your project for this. If * you've implemented an alternative client class as well, "standard" * should be replaced by the name of the new class. * * @param string Relative path to the template creating XML code for the site map items * @since 2015.01 * @category Developer * @see controller/jobs/product/export/sitemap/standard/template-header * @see controller/jobs/product/export/sitemap/standard/template-footer * @see controller/jobs/product/export/sitemap/standard/template-index */ $tplconf = 'controller/jobs/product/export/sitemap/standard/template-items'; $default = 'product/export/sitemap-items-body-standard'; $context = $this->getContext(); $view = $context->getView(); $view->siteItems = $items; $view->siteFreq = $changefreq; $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); }
php
protected function addItems( \Aimeos\MW\Container\Content\Iface $content, array $items ) { $config = $this->getContext()->getConfig(); /** controller/jobs/product/export/sitemap/changefreq * Change frequency of the products * * Depending on how often the product content changes (e.g. price updates) * and the site map files are generated you can give search engines a * hint how often they should reindex your site. The site map schema * allows a few pre-defined strings for the change frequency: * * always * * hourly * * daily * * weekly * * monthly * * yearly * * never * * More information can be found at * {@link http://www.sitemaps.org/protocol.html#xmlTagDefinitions sitemap.org} * * @param string One of the pre-defined strings (see description) * @since 2015.01 * @category User * @category Developer * @see controller/jobs/product/export/sitemap/container/options * @see controller/jobs/product/export/sitemap/location * @see controller/jobs/product/export/sitemap/max-items * @see controller/jobs/product/export/sitemap/max-query */ $changefreq = $config->get( 'controller/jobs/product/export/sitemap/changefreq', 'daily' ); /** controller/jobs/product/export/sitemap/standard/template-items * Relative path to the XML items template of the product site map job controller. * * The template file contains the XML code and processing instructions * to generate the site map files. The configuration string is the path * to the template file relative to the templates directory (usually in * controller/jobs/templates). * * You can overwrite the template file configuration in extensions and * provide alternative templates. These alternative templates should be * named like the default one but with the string "standard" replaced by * an unique name. You may use the name of your project for this. If * you've implemented an alternative client class as well, "standard" * should be replaced by the name of the new class. * * @param string Relative path to the template creating XML code for the site map items * @since 2015.01 * @category Developer * @see controller/jobs/product/export/sitemap/standard/template-header * @see controller/jobs/product/export/sitemap/standard/template-footer * @see controller/jobs/product/export/sitemap/standard/template-index */ $tplconf = 'controller/jobs/product/export/sitemap/standard/template-items'; $default = 'product/export/sitemap-items-body-standard'; $context = $this->getContext(); $view = $context->getView(); $view->siteItems = $items; $view->siteFreq = $changefreq; $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); }
[ "protected", "function", "addItems", "(", "\\", "Aimeos", "\\", "MW", "\\", "Container", "\\", "Content", "\\", "Iface", "$", "content", ",", "array", "$", "items", ")", "{", "$", "config", "=", "$", "this", "->", "getContext", "(", ")", "->", "getConfig", "(", ")", ";", "/** controller/jobs/product/export/sitemap/changefreq\n\t\t * Change frequency of the products\n\t\t *\n\t\t * Depending on how often the product content changes (e.g. price updates)\n\t\t * and the site map files are generated you can give search engines a\n\t\t * hint how often they should reindex your site. The site map schema\n\t\t * allows a few pre-defined strings for the change frequency:\n\t\t * * always\n\t\t * * hourly\n\t\t * * daily\n\t\t * * weekly\n\t\t * * monthly\n\t\t * * yearly\n\t\t * * never\n\t\t *\n\t\t * More information can be found at\n\t\t * {@link http://www.sitemaps.org/protocol.html#xmlTagDefinitions sitemap.org}\n\t\t *\n\t\t * @param string One of the pre-defined strings (see description)\n\t\t * @since 2015.01\n\t\t * @category User\n\t\t * @category Developer\n\t\t * @see controller/jobs/product/export/sitemap/container/options\n\t\t * @see controller/jobs/product/export/sitemap/location\n\t\t * @see controller/jobs/product/export/sitemap/max-items\n\t\t * @see controller/jobs/product/export/sitemap/max-query\n\t\t */", "$", "changefreq", "=", "$", "config", "->", "get", "(", "'controller/jobs/product/export/sitemap/changefreq'", ",", "'daily'", ")", ";", "/** controller/jobs/product/export/sitemap/standard/template-items\n\t\t * Relative path to the XML items template of the product site map job controller.\n\t\t *\n\t\t * The template file contains the XML code and processing instructions\n\t\t * to generate the site map files. The configuration string is the path\n\t\t * to the template file relative to the templates directory (usually in\n\t\t * controller/jobs/templates).\n\t\t *\n\t\t * You can overwrite the template file configuration in extensions and\n\t\t * provide alternative templates. These alternative templates should be\n\t\t * named like the default one but with the string \"standard\" replaced by\n\t\t * an unique name. You may use the name of your project for this. If\n\t\t * you've implemented an alternative client class as well, \"standard\"\n\t\t * should be replaced by the name of the new class.\n\t\t *\n\t\t * @param string Relative path to the template creating XML code for the site map items\n\t\t * @since 2015.01\n\t\t * @category Developer\n\t\t * @see controller/jobs/product/export/sitemap/standard/template-header\n\t\t * @see controller/jobs/product/export/sitemap/standard/template-footer\n\t\t * @see controller/jobs/product/export/sitemap/standard/template-index\n\t\t */", "$", "tplconf", "=", "'controller/jobs/product/export/sitemap/standard/template-items'", ";", "$", "default", "=", "'product/export/sitemap-items-body-standard'", ";", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "view", "=", "$", "context", "->", "getView", "(", ")", ";", "$", "view", "->", "siteItems", "=", "$", "items", ";", "$", "view", "->", "siteFreq", "=", "$", "changefreq", ";", "$", "content", "->", "add", "(", "$", "view", "->", "render", "(", "$", "context", "->", "getConfig", "(", ")", "->", "get", "(", "$", "tplconf", ",", "$", "default", ")", ")", ")", ";", "}" ]
Adds the given products to the content object for the site map file @param \Aimeos\MW\Container\Content\Iface $content File content object @param \Aimeos\MShop\Product\Item\Iface[] $items List of product items
[ "Adds", "the", "given", "products", "to", "the", "content", "object", "for", "the", "site", "map", "file" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Product/Export/Sitemap/Standard.php#L68-L133
27,004
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Product/Export/Sitemap/Standard.php
Standard.getConfig
protected function getConfig( $name, $default = null ) { $config = $this->getContext()->getConfig(); switch( $name ) { case 'domains': /** controller/jobs/product/export/sitemap/domains * List of associated items from other domains that should be fetched for the sitemap * * Products consist not only of the base data but also of texts, media * files, prices, attrbutes and other details. Those information is * associated to the products via their lists. Using the "domains" option * you can make more or less associated items available in the template. * * @param array List of domain names * @since 2018.07 * @category Developer * @category User * @see controller/jobs/product/export/sitemap/container/options * @see controller/jobs/product/export/sitemap/location * @see controller/jobs/product/export/sitemap/max-items * @see controller/jobs/product/export/sitemap/max-query * @see controller/jobs/product/export/sitemap/changefreq */ return $config->get( 'controller/jobs/product/export/sitemap/domains', $default ); case 'max-items': /** controller/jobs/product/export/sitemap/max-items * Maximum number of products per site map * * Each site map file must not contain more than 50,000 links and it's * size must be less than 10MB. If your product URLs are rather long * and one of your site map files is bigger than 10MB, you should set * the number of products per file to a smaller value until each file * is less than 10MB. * * More details about site maps can be found at * {@link http://www.sitemaps.org/protocol.html sitemaps.org} * * @param integer Number of products per file * @since 2015.01 * @category Developer * @category User * @see controller/jobs/product/export/sitemap/container/options * @see controller/jobs/product/export/sitemap/location * @see controller/jobs/product/export/sitemap/max-query * @see controller/jobs/product/export/sitemap/changefreq * @see controller/jobs/product/export/sitemap/domains */ return $config->get( 'controller/jobs/product/export/sitemap/max-items', 50000 ); case 'max-query': /** controller/jobs/product/export/sitemap/max-query * Maximum number of products per query * * The products are fetched from the database in bunches for efficient * retrieval. The higher the value, the lower the total time the database * is busy finding the records. Higher values also means that record * updates in the tables need to wait longer and the memory consumption * of the PHP process is higher. * * Note: The value of max-query must be smaller than or equal to * {@see controller/jobs/product/export/sitemap/max-items max-items} * * @param integer Number of products per query * @since 2015.01 * @category Developer * @see controller/jobs/product/export/sitemap/container/options * @see controller/jobs/product/export/sitemap/location * @see controller/jobs/product/export/sitemap/max-items * @see controller/jobs/product/export/sitemap/changefreq * @see controller/jobs/product/export/sitemap/domains */ return $config->get( 'controller/jobs/product/export/sitemap/max-query', 1000 ); } return $default; }
php
protected function getConfig( $name, $default = null ) { $config = $this->getContext()->getConfig(); switch( $name ) { case 'domains': /** controller/jobs/product/export/sitemap/domains * List of associated items from other domains that should be fetched for the sitemap * * Products consist not only of the base data but also of texts, media * files, prices, attrbutes and other details. Those information is * associated to the products via their lists. Using the "domains" option * you can make more or less associated items available in the template. * * @param array List of domain names * @since 2018.07 * @category Developer * @category User * @see controller/jobs/product/export/sitemap/container/options * @see controller/jobs/product/export/sitemap/location * @see controller/jobs/product/export/sitemap/max-items * @see controller/jobs/product/export/sitemap/max-query * @see controller/jobs/product/export/sitemap/changefreq */ return $config->get( 'controller/jobs/product/export/sitemap/domains', $default ); case 'max-items': /** controller/jobs/product/export/sitemap/max-items * Maximum number of products per site map * * Each site map file must not contain more than 50,000 links and it's * size must be less than 10MB. If your product URLs are rather long * and one of your site map files is bigger than 10MB, you should set * the number of products per file to a smaller value until each file * is less than 10MB. * * More details about site maps can be found at * {@link http://www.sitemaps.org/protocol.html sitemaps.org} * * @param integer Number of products per file * @since 2015.01 * @category Developer * @category User * @see controller/jobs/product/export/sitemap/container/options * @see controller/jobs/product/export/sitemap/location * @see controller/jobs/product/export/sitemap/max-query * @see controller/jobs/product/export/sitemap/changefreq * @see controller/jobs/product/export/sitemap/domains */ return $config->get( 'controller/jobs/product/export/sitemap/max-items', 50000 ); case 'max-query': /** controller/jobs/product/export/sitemap/max-query * Maximum number of products per query * * The products are fetched from the database in bunches for efficient * retrieval. The higher the value, the lower the total time the database * is busy finding the records. Higher values also means that record * updates in the tables need to wait longer and the memory consumption * of the PHP process is higher. * * Note: The value of max-query must be smaller than or equal to * {@see controller/jobs/product/export/sitemap/max-items max-items} * * @param integer Number of products per query * @since 2015.01 * @category Developer * @see controller/jobs/product/export/sitemap/container/options * @see controller/jobs/product/export/sitemap/location * @see controller/jobs/product/export/sitemap/max-items * @see controller/jobs/product/export/sitemap/changefreq * @see controller/jobs/product/export/sitemap/domains */ return $config->get( 'controller/jobs/product/export/sitemap/max-query', 1000 ); } return $default; }
[ "protected", "function", "getConfig", "(", "$", "name", ",", "$", "default", "=", "null", ")", "{", "$", "config", "=", "$", "this", "->", "getContext", "(", ")", "->", "getConfig", "(", ")", ";", "switch", "(", "$", "name", ")", "{", "case", "'domains'", ":", "/** controller/jobs/product/export/sitemap/domains\n\t\t\t\t * List of associated items from other domains that should be fetched for the sitemap\n\t\t\t\t *\n\t\t\t\t * Products consist not only of the base data but also of texts, media\n\t\t\t\t * files, prices, attrbutes and other details. Those information is\n\t\t\t\t * associated to the products via their lists. Using the \"domains\" option\n\t\t\t\t * you can make more or less associated items available in the template.\n\t\t\t\t *\n\t\t\t\t * @param array List of domain names\n\t\t\t\t * @since 2018.07\n\t\t\t\t * @category Developer\n\t\t\t\t * @category User\n\t\t\t\t * @see controller/jobs/product/export/sitemap/container/options\n\t\t\t\t * @see controller/jobs/product/export/sitemap/location\n\t\t\t\t * @see controller/jobs/product/export/sitemap/max-items\n\t\t\t\t * @see controller/jobs/product/export/sitemap/max-query\n\t\t\t\t * @see controller/jobs/product/export/sitemap/changefreq\n\t\t\t\t */", "return", "$", "config", "->", "get", "(", "'controller/jobs/product/export/sitemap/domains'", ",", "$", "default", ")", ";", "case", "'max-items'", ":", "/** controller/jobs/product/export/sitemap/max-items\n\t\t\t\t * Maximum number of products per site map\n\t\t\t\t *\n\t\t\t\t * Each site map file must not contain more than 50,000 links and it's\n\t\t\t\t * size must be less than 10MB. If your product URLs are rather long\n\t\t\t\t * and one of your site map files is bigger than 10MB, you should set\n\t\t\t\t * the number of products per file to a smaller value until each file\n\t\t\t\t * is less than 10MB.\n\t\t\t\t *\n\t\t\t\t * More details about site maps can be found at\n\t\t\t\t * {@link http://www.sitemaps.org/protocol.html sitemaps.org}\n\t\t\t\t *\n\t\t\t\t * @param integer Number of products per file\n\t\t\t\t * @since 2015.01\n\t\t\t\t * @category Developer\n\t\t\t\t * @category User\n\t\t\t\t * @see controller/jobs/product/export/sitemap/container/options\n\t\t\t\t * @see controller/jobs/product/export/sitemap/location\n\t\t\t\t * @see controller/jobs/product/export/sitemap/max-query\n\t\t\t\t * @see controller/jobs/product/export/sitemap/changefreq\n\t\t\t\t * @see controller/jobs/product/export/sitemap/domains\n\t\t\t\t */", "return", "$", "config", "->", "get", "(", "'controller/jobs/product/export/sitemap/max-items'", ",", "50000", ")", ";", "case", "'max-query'", ":", "/** controller/jobs/product/export/sitemap/max-query\n\t\t\t\t * Maximum number of products per query\n\t\t\t\t *\n\t\t\t\t * The products are fetched from the database in bunches for efficient\n\t\t\t\t * retrieval. The higher the value, the lower the total time the database\n\t\t\t\t * is busy finding the records. Higher values also means that record\n\t\t\t\t * updates in the tables need to wait longer and the memory consumption\n\t\t\t\t * of the PHP process is higher.\n\t\t\t\t *\n\t\t\t\t * Note: The value of max-query must be smaller than or equal to\n\t\t\t\t * {@see controller/jobs/product/export/sitemap/max-items max-items}\n\t\t\t\t *\n\t\t\t\t * @param integer Number of products per query\n\t\t\t\t * @since 2015.01\n\t\t\t\t * @category Developer\n\t\t\t\t * @see controller/jobs/product/export/sitemap/container/options\n\t\t\t\t * @see controller/jobs/product/export/sitemap/location\n\t\t\t\t * @see controller/jobs/product/export/sitemap/max-items\n\t\t\t\t * @see controller/jobs/product/export/sitemap/changefreq\n\t\t\t\t * @see controller/jobs/product/export/sitemap/domains\n\t\t\t\t */", "return", "$", "config", "->", "get", "(", "'controller/jobs/product/export/sitemap/max-query'", ",", "1000", ")", ";", "}", "return", "$", "default", ";", "}" ]
Returns the configuration value for the given name @param string $name One of "domain", "max-items" or "max-query" @param mixed $default Default value if name is unknown @return mixed Configuration value
[ "Returns", "the", "configuration", "value", "for", "the", "given", "name" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Product/Export/Sitemap/Standard.php#L402-L480
27,005
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Customer/Import/Xml/Standard.php
Standard.process
protected function process( \Aimeos\MShop\Customer\Item\Iface $item, \DomElement $node ) { $list = []; foreach( $node->attributes as $attr ) { $list[$attr->nodeName] = $attr->nodeValue; } foreach( $node->childNodes as $tag ) { if( in_array( $tag->nodeName, ['address', 'lists', 'property', 'group'] ) ) { $item = $this->getProcessor( $tag->nodeName, 'customer' )->process( $item, $tag ); } else { $list[$tag->nodeName] = $tag->nodeValue; } } return $item->fromArray( $list, true ); }
php
protected function process( \Aimeos\MShop\Customer\Item\Iface $item, \DomElement $node ) { $list = []; foreach( $node->attributes as $attr ) { $list[$attr->nodeName] = $attr->nodeValue; } foreach( $node->childNodes as $tag ) { if( in_array( $tag->nodeName, ['address', 'lists', 'property', 'group'] ) ) { $item = $this->getProcessor( $tag->nodeName, 'customer' )->process( $item, $tag ); } else { $list[$tag->nodeName] = $tag->nodeValue; } } return $item->fromArray( $list, true ); }
[ "protected", "function", "process", "(", "\\", "Aimeos", "\\", "MShop", "\\", "Customer", "\\", "Item", "\\", "Iface", "$", "item", ",", "\\", "DomElement", "$", "node", ")", "{", "$", "list", "=", "[", "]", ";", "foreach", "(", "$", "node", "->", "attributes", "as", "$", "attr", ")", "{", "$", "list", "[", "$", "attr", "->", "nodeName", "]", "=", "$", "attr", "->", "nodeValue", ";", "}", "foreach", "(", "$", "node", "->", "childNodes", "as", "$", "tag", ")", "{", "if", "(", "in_array", "(", "$", "tag", "->", "nodeName", ",", "[", "'address'", ",", "'lists'", ",", "'property'", ",", "'group'", "]", ")", ")", "{", "$", "item", "=", "$", "this", "->", "getProcessor", "(", "$", "tag", "->", "nodeName", ",", "'customer'", ")", "->", "process", "(", "$", "item", ",", "$", "tag", ")", ";", "}", "else", "{", "$", "list", "[", "$", "tag", "->", "nodeName", "]", "=", "$", "tag", "->", "nodeValue", ";", "}", "}", "return", "$", "item", "->", "fromArray", "(", "$", "list", ",", "true", ")", ";", "}" ]
Updates the customer item and its referenced items using the given DOM node @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object to update @param \DomElement $node DOM node used for updateding the customer item @return \Aimeos\MShop\Customer\Item\Iface $item Updated customer item object
[ "Updates", "the", "customer", "item", "and", "its", "referenced", "items", "using", "the", "given", "DOM", "node" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Customer/Import/Xml/Standard.php#L294-L312
27,006
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Coupon/Import/Csv/Code/Standard.php
Standard.import
protected function import( array $items, array $data, $couponId, \Aimeos\Controller\Common\Coupon\Import\Csv\Processor\Iface $processor ) { $errors = 0; $context = $this->getContext(); $manager = \Aimeos\MShop::create( $context, 'coupon/code' ); foreach( $data as $code => $list ) { $manager->begin(); try { if( isset( $items[$code] ) ) { $item = $items[$code]; } else { $item = $manager->createItem(); } $item->setParentId( $couponId ); $list = $processor->process( $item, $list ); $manager->commit(); } catch( \Exception $e ) { $manager->rollback(); $msg = sprintf( 'Unable to import coupon with code "%1$s": %2$s', $code, $e->getMessage() ); $context->getLogger()->log( $msg ); $errors++; } } return $errors; }
php
protected function import( array $items, array $data, $couponId, \Aimeos\Controller\Common\Coupon\Import\Csv\Processor\Iface $processor ) { $errors = 0; $context = $this->getContext(); $manager = \Aimeos\MShop::create( $context, 'coupon/code' ); foreach( $data as $code => $list ) { $manager->begin(); try { if( isset( $items[$code] ) ) { $item = $items[$code]; } else { $item = $manager->createItem(); } $item->setParentId( $couponId ); $list = $processor->process( $item, $list ); $manager->commit(); } catch( \Exception $e ) { $manager->rollback(); $msg = sprintf( 'Unable to import coupon with code "%1$s": %2$s', $code, $e->getMessage() ); $context->getLogger()->log( $msg ); $errors++; } } return $errors; }
[ "protected", "function", "import", "(", "array", "$", "items", ",", "array", "$", "data", ",", "$", "couponId", ",", "\\", "Aimeos", "\\", "Controller", "\\", "Common", "\\", "Coupon", "\\", "Import", "\\", "Csv", "\\", "Processor", "\\", "Iface", "$", "processor", ")", "{", "$", "errors", "=", "0", ";", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "manager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "context", ",", "'coupon/code'", ")", ";", "foreach", "(", "$", "data", "as", "$", "code", "=>", "$", "list", ")", "{", "$", "manager", "->", "begin", "(", ")", ";", "try", "{", "if", "(", "isset", "(", "$", "items", "[", "$", "code", "]", ")", ")", "{", "$", "item", "=", "$", "items", "[", "$", "code", "]", ";", "}", "else", "{", "$", "item", "=", "$", "manager", "->", "createItem", "(", ")", ";", "}", "$", "item", "->", "setParentId", "(", "$", "couponId", ")", ";", "$", "list", "=", "$", "processor", "->", "process", "(", "$", "item", ",", "$", "list", ")", ";", "$", "manager", "->", "commit", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "manager", "->", "rollback", "(", ")", ";", "$", "msg", "=", "sprintf", "(", "'Unable to import coupon with code \"%1$s\": %2$s'", ",", "$", "code", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "$", "context", "->", "getLogger", "(", ")", "->", "log", "(", "$", "msg", ")", ";", "$", "errors", "++", ";", "}", "}", "return", "$", "errors", ";", "}" ]
Imports the CSV data and creates new coupons or updates existing ones @param \Aimeos\MShop\Coupon\Item\Code\Iface[] $items List of coupons code items @param array $data Associative list of import data as index/value pairs @param string $couponId ID of the coupon item the coupon code should be added to @param \Aimeos\Controller\Common\Coupon\Import\Csv\Processor\Iface $processor Processor object @return integer Number of coupons that couldn't be imported @throws \Aimeos\Controller\Jobs\Exception
[ "Imports", "the", "CSV", "data", "and", "creates", "new", "coupons", "or", "updates", "existing", "ones" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Coupon/Import/Csv/Code/Standard.php#L278-L314
27,007
aimeos/ai-controller-jobs
controller/common/src/Controller/Common/Coupon/Import/Csv/Base.php
Base.getData
protected function getData( \Aimeos\MW\Container\Content\Iface $content, $maxcnt, $codePos ) { $count = 0; $data = []; while( $content->valid() && $count++ < $maxcnt ) { $row = $content->current(); $data[$row[$codePos]] = $row; $content->next(); } return $data; }
php
protected function getData( \Aimeos\MW\Container\Content\Iface $content, $maxcnt, $codePos ) { $count = 0; $data = []; while( $content->valid() && $count++ < $maxcnt ) { $row = $content->current(); $data[$row[$codePos]] = $row; $content->next(); } return $data; }
[ "protected", "function", "getData", "(", "\\", "Aimeos", "\\", "MW", "\\", "Container", "\\", "Content", "\\", "Iface", "$", "content", ",", "$", "maxcnt", ",", "$", "codePos", ")", "{", "$", "count", "=", "0", ";", "$", "data", "=", "[", "]", ";", "while", "(", "$", "content", "->", "valid", "(", ")", "&&", "$", "count", "++", "<", "$", "maxcnt", ")", "{", "$", "row", "=", "$", "content", "->", "current", "(", ")", ";", "$", "data", "[", "$", "row", "[", "$", "codePos", "]", "]", "=", "$", "row", ";", "$", "content", "->", "next", "(", ")", ";", "}", "return", "$", "data", ";", "}" ]
Returns the rows from the CSV file up to the maximum count @param \Aimeos\MW\Container\Content\Iface $content CSV content object @param integer $maxcnt Maximum number of rows that should be retrieved at once @param integer $codePos Column position which contains the unique coupon code (starting from 0) @return array List of arrays with coupon codes as keys and list of values from the CSV file
[ "Returns", "the", "rows", "from", "the", "CSV", "file", "up", "to", "the", "maximum", "count" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/common/src/Controller/Common/Coupon/Import/Csv/Base.php#L54-L67
27,008
aimeos/ai-controller-jobs
controller/common/src/Controller/Common/Coupon/Import/Csv/Base.php
Base.getMappedChunk
protected function getMappedChunk( array &$data, array $mapping ) { $idx = 0; $map = []; foreach( $mapping as $pos => $key ) { if( isset( $map[$idx][$key] ) ) { $idx++; } if( isset( $data[$pos] ) ) { $map[$idx][$key] = $data[$pos]; unset( $data[$pos] ); } } return $map; }
php
protected function getMappedChunk( array &$data, array $mapping ) { $idx = 0; $map = []; foreach( $mapping as $pos => $key ) { if( isset( $map[$idx][$key] ) ) { $idx++; } if( isset( $data[$pos] ) ) { $map[$idx][$key] = $data[$pos]; unset( $data[$pos] ); } } return $map; }
[ "protected", "function", "getMappedChunk", "(", "array", "&", "$", "data", ",", "array", "$", "mapping", ")", "{", "$", "idx", "=", "0", ";", "$", "map", "=", "[", "]", ";", "foreach", "(", "$", "mapping", "as", "$", "pos", "=>", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "map", "[", "$", "idx", "]", "[", "$", "key", "]", ")", ")", "{", "$", "idx", "++", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "$", "pos", "]", ")", ")", "{", "$", "map", "[", "$", "idx", "]", "[", "$", "key", "]", "=", "$", "data", "[", "$", "pos", "]", ";", "unset", "(", "$", "data", "[", "$", "pos", "]", ")", ";", "}", "}", "return", "$", "map", ";", "}" ]
Returns the mapped data from the CSV line @param array $data List of CSV fields with position as key and domain item key as value (mapped data is removed) @param array $mapping List of domain item keys with the CSV field position as key @return array List of associative arrays containing the chunked properties
[ "Returns", "the", "mapped", "data", "from", "the", "CSV", "line" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/common/src/Controller/Common/Coupon/Import/Csv/Base.php#L101-L120
27,009
aimeos/ai-controller-jobs
controller/common/src/Controller/Common/Coupon/Import/Csv/Base.php
Base.getProcessors
protected function getProcessors( array $mappings ) { $context = $this->getContext(); $config = $context->getConfig(); $object = new \Aimeos\Controller\Common\Coupon\Import\Csv\Processor\Done( $context, [] ); foreach( $mappings as $type => $mapping ) { if( ctype_alnum( $type ) === false ) { $classname = is_string( $type ) ? '\\Aimeos\\Controller\\Common\\Coupon\\Import\\Csv\\Processor\\' . $type : '<not a string>'; throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); } $name = $config->get( 'controller/common/coupon/import/csv/processor/' . $type . '/name', 'Standard' ); if( ctype_alnum( $name ) === false ) { $classname = is_string( $name ) ? '\\Aimeos\\Controller\\Common\\Coupon\\Import\\Csv\\Processor\\' . $type . '\\' . $name : '<not a string>'; throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); } $classname = '\\Aimeos\\Controller\\Common\\Coupon\\Import\\Csv\\Processor\\' . ucfirst( $type ) . '\\' . $name; if( class_exists( $classname ) === false ) { throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" not found', $classname ) ); } $object = new $classname( $context, $mapping, $object ); \Aimeos\MW\Common\Base::checkClass( '\\Aimeos\\Controller\\Common\\Coupon\\Import\\Csv\\Processor\\Iface', $object ); } return $object; }
php
protected function getProcessors( array $mappings ) { $context = $this->getContext(); $config = $context->getConfig(); $object = new \Aimeos\Controller\Common\Coupon\Import\Csv\Processor\Done( $context, [] ); foreach( $mappings as $type => $mapping ) { if( ctype_alnum( $type ) === false ) { $classname = is_string( $type ) ? '\\Aimeos\\Controller\\Common\\Coupon\\Import\\Csv\\Processor\\' . $type : '<not a string>'; throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); } $name = $config->get( 'controller/common/coupon/import/csv/processor/' . $type . '/name', 'Standard' ); if( ctype_alnum( $name ) === false ) { $classname = is_string( $name ) ? '\\Aimeos\\Controller\\Common\\Coupon\\Import\\Csv\\Processor\\' . $type . '\\' . $name : '<not a string>'; throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); } $classname = '\\Aimeos\\Controller\\Common\\Coupon\\Import\\Csv\\Processor\\' . ucfirst( $type ) . '\\' . $name; if( class_exists( $classname ) === false ) { throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" not found', $classname ) ); } $object = new $classname( $context, $mapping, $object ); \Aimeos\MW\Common\Base::checkClass( '\\Aimeos\\Controller\\Common\\Coupon\\Import\\Csv\\Processor\\Iface', $object ); } return $object; }
[ "protected", "function", "getProcessors", "(", "array", "$", "mappings", ")", "{", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "config", "=", "$", "context", "->", "getConfig", "(", ")", ";", "$", "object", "=", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Common", "\\", "Coupon", "\\", "Import", "\\", "Csv", "\\", "Processor", "\\", "Done", "(", "$", "context", ",", "[", "]", ")", ";", "foreach", "(", "$", "mappings", "as", "$", "type", "=>", "$", "mapping", ")", "{", "if", "(", "ctype_alnum", "(", "$", "type", ")", "===", "false", ")", "{", "$", "classname", "=", "is_string", "(", "$", "type", ")", "?", "'\\\\Aimeos\\\\Controller\\\\Common\\\\Coupon\\\\Import\\\\Csv\\\\Processor\\\\'", ".", "$", "type", ":", "'<not a string>'", ";", "throw", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Jobs", "\\", "Exception", "(", "sprintf", "(", "'Invalid characters in class name \"%1$s\"'", ",", "$", "classname", ")", ")", ";", "}", "$", "name", "=", "$", "config", "->", "get", "(", "'controller/common/coupon/import/csv/processor/'", ".", "$", "type", ".", "'/name'", ",", "'Standard'", ")", ";", "if", "(", "ctype_alnum", "(", "$", "name", ")", "===", "false", ")", "{", "$", "classname", "=", "is_string", "(", "$", "name", ")", "?", "'\\\\Aimeos\\\\Controller\\\\Common\\\\Coupon\\\\Import\\\\Csv\\\\Processor\\\\'", ".", "$", "type", ".", "'\\\\'", ".", "$", "name", ":", "'<not a string>'", ";", "throw", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Jobs", "\\", "Exception", "(", "sprintf", "(", "'Invalid characters in class name \"%1$s\"'", ",", "$", "classname", ")", ")", ";", "}", "$", "classname", "=", "'\\\\Aimeos\\\\Controller\\\\Common\\\\Coupon\\\\Import\\\\Csv\\\\Processor\\\\'", ".", "ucfirst", "(", "$", "type", ")", ".", "'\\\\'", ".", "$", "name", ";", "if", "(", "class_exists", "(", "$", "classname", ")", "===", "false", ")", "{", "throw", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Jobs", "\\", "Exception", "(", "sprintf", "(", "'Class \"%1$s\" not found'", ",", "$", "classname", ")", ")", ";", "}", "$", "object", "=", "new", "$", "classname", "(", "$", "context", ",", "$", "mapping", ",", "$", "object", ")", ";", "\\", "Aimeos", "\\", "MW", "\\", "Common", "\\", "Base", "::", "checkClass", "(", "'\\\\Aimeos\\\\Controller\\\\Common\\\\Coupon\\\\Import\\\\Csv\\\\Processor\\\\Iface'", ",", "$", "object", ")", ";", "}", "return", "$", "object", ";", "}" ]
Returns the processor object for saving the coupon related information @param array $mappings Associative list of processor types as keys and index/data mappings as values @return \Aimeos\Controller\Common\Coupon\Import\Csv\Processor\Iface Processor object
[ "Returns", "the", "processor", "object", "for", "saving", "the", "coupon", "related", "information" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/common/src/Controller/Common/Coupon/Import/Csv/Base.php#L129-L163
27,010
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Catalog/Export/Sitemap/Standard.php
Standard.createContent
protected function createContent( \Aimeos\MW\Container\Iface $container, $filenum ) { /** controller/jobs/catalog/export/sitemap/standard/template-header * Relative path to the XML site map header template of the catalog site map job controller. * * The template file contains the XML code and processing instructions * to generate the site map header. The configuration string is the path * to the template file relative to the templates directory (usually in * controller/jobs/templates). * * You can overwrite the template file configuration in extensions and * provide alternative templates. These alternative templates should be * named like the default one but with the string "standard" replaced by * an unique name. You may use the name of your project for this. If * you've implemented an alternative client class as well, "standard" * should be replaced by the name of the new class. * * @param string Relative path to the template creating XML code for the site map header * @since 2019.02 * @category Developer * @see controller/jobs/catalog/export/sitemap/standard/template-items * @see controller/jobs/catalog/export/sitemap/standard/template-footer * @see controller/jobs/catalog/export/sitemap/standard/template-index */ $tplconf = 'controller/jobs/catalog/export/sitemap/standard/template-header'; $default = 'catalog/export/sitemap-items-header-standard'; $context = $this->getContext(); $view = $context->getView(); $content = $container->create( $this->getFilename( $filenum ) ); $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); $container->add( $content ); return $content; }
php
protected function createContent( \Aimeos\MW\Container\Iface $container, $filenum ) { /** controller/jobs/catalog/export/sitemap/standard/template-header * Relative path to the XML site map header template of the catalog site map job controller. * * The template file contains the XML code and processing instructions * to generate the site map header. The configuration string is the path * to the template file relative to the templates directory (usually in * controller/jobs/templates). * * You can overwrite the template file configuration in extensions and * provide alternative templates. These alternative templates should be * named like the default one but with the string "standard" replaced by * an unique name. You may use the name of your project for this. If * you've implemented an alternative client class as well, "standard" * should be replaced by the name of the new class. * * @param string Relative path to the template creating XML code for the site map header * @since 2019.02 * @category Developer * @see controller/jobs/catalog/export/sitemap/standard/template-items * @see controller/jobs/catalog/export/sitemap/standard/template-footer * @see controller/jobs/catalog/export/sitemap/standard/template-index */ $tplconf = 'controller/jobs/catalog/export/sitemap/standard/template-header'; $default = 'catalog/export/sitemap-items-header-standard'; $context = $this->getContext(); $view = $context->getView(); $content = $container->create( $this->getFilename( $filenum ) ); $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); $container->add( $content ); return $content; }
[ "protected", "function", "createContent", "(", "\\", "Aimeos", "\\", "MW", "\\", "Container", "\\", "Iface", "$", "container", ",", "$", "filenum", ")", "{", "/** controller/jobs/catalog/export/sitemap/standard/template-header\n\t\t * Relative path to the XML site map header template of the catalog site map job controller.\n\t\t *\n\t\t * The template file contains the XML code and processing instructions\n\t\t * to generate the site map header. The configuration string is the path\n\t\t * to the template file relative to the templates directory (usually in\n\t\t * controller/jobs/templates).\n\t\t *\n\t\t * You can overwrite the template file configuration in extensions and\n\t\t * provide alternative templates. These alternative templates should be\n\t\t * named like the default one but with the string \"standard\" replaced by\n\t\t * an unique name. You may use the name of your project for this. If\n\t\t * you've implemented an alternative client class as well, \"standard\"\n\t\t * should be replaced by the name of the new class.\n\t\t *\n\t\t * @param string Relative path to the template creating XML code for the site map header\n\t\t * @since 2019.02\n\t\t * @category Developer\n\t\t * @see controller/jobs/catalog/export/sitemap/standard/template-items\n\t\t * @see controller/jobs/catalog/export/sitemap/standard/template-footer\n\t\t * @see controller/jobs/catalog/export/sitemap/standard/template-index\n\t\t */", "$", "tplconf", "=", "'controller/jobs/catalog/export/sitemap/standard/template-header'", ";", "$", "default", "=", "'catalog/export/sitemap-items-header-standard'", ";", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "view", "=", "$", "context", "->", "getView", "(", ")", ";", "$", "content", "=", "$", "container", "->", "create", "(", "$", "this", "->", "getFilename", "(", "$", "filenum", ")", ")", ";", "$", "content", "->", "add", "(", "$", "view", "->", "render", "(", "$", "context", "->", "getConfig", "(", ")", "->", "get", "(", "$", "tplconf", ",", "$", "default", ")", ")", ")", ";", "$", "container", "->", "add", "(", "$", "content", ")", ";", "return", "$", "content", ";", "}" ]
Creates a new site map content object @param \Aimeos\MW\Container\Iface $container Container object @param integer $filenum New file number @return \Aimeos\MW\Container\Content\Iface New content object
[ "Creates", "a", "new", "site", "map", "content", "object" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Catalog/Export/Sitemap/Standard.php#L218-L253
27,011
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Catalog/Export/Sitemap/Standard.php
Standard.closeContent
protected function closeContent( \Aimeos\MW\Container\Content\Iface $content ) { /** controller/jobs/catalog/export/sitemap/standard/template-footer * Relative path to the XML site map footer template of the catalog site map job controller. * * The template file contains the XML code and processing instructions * to generate the site map footer. The configuration string is the path * to the template file relative to the templates directory (usually in * controller/jobs/templates). * * You can overwrite the template file configuration in extensions and * provide alternative templates. These alternative templates should be * named like the default one but with the string "standard" replaced by * an unique name. You may use the name of your project for this. If * you've implemented an alternative client class as well, "standard" * should be replaced by the name of the new class. * * @param string Relative path to the template creating XML code for the site map footer * @since 2019.02 * @category Developer * @see controller/jobs/catalog/export/sitemap/standard/template-header * @see controller/jobs/catalog/export/sitemap/standard/template-items * @see controller/jobs/catalog/export/sitemap/standard/template-index */ $tplconf = 'controller/jobs/catalog/export/sitemap/standard/template-footer'; $default = 'catalog/export/sitemap-items-footer-standard'; $context = $this->getContext(); $view = $context->getView(); $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); }
php
protected function closeContent( \Aimeos\MW\Container\Content\Iface $content ) { /** controller/jobs/catalog/export/sitemap/standard/template-footer * Relative path to the XML site map footer template of the catalog site map job controller. * * The template file contains the XML code and processing instructions * to generate the site map footer. The configuration string is the path * to the template file relative to the templates directory (usually in * controller/jobs/templates). * * You can overwrite the template file configuration in extensions and * provide alternative templates. These alternative templates should be * named like the default one but with the string "standard" replaced by * an unique name. You may use the name of your project for this. If * you've implemented an alternative client class as well, "standard" * should be replaced by the name of the new class. * * @param string Relative path to the template creating XML code for the site map footer * @since 2019.02 * @category Developer * @see controller/jobs/catalog/export/sitemap/standard/template-header * @see controller/jobs/catalog/export/sitemap/standard/template-items * @see controller/jobs/catalog/export/sitemap/standard/template-index */ $tplconf = 'controller/jobs/catalog/export/sitemap/standard/template-footer'; $default = 'catalog/export/sitemap-items-footer-standard'; $context = $this->getContext(); $view = $context->getView(); $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); }
[ "protected", "function", "closeContent", "(", "\\", "Aimeos", "\\", "MW", "\\", "Container", "\\", "Content", "\\", "Iface", "$", "content", ")", "{", "/** controller/jobs/catalog/export/sitemap/standard/template-footer\n\t\t * Relative path to the XML site map footer template of the catalog site map job controller.\n\t\t *\n\t\t * The template file contains the XML code and processing instructions\n\t\t * to generate the site map footer. The configuration string is the path\n\t\t * to the template file relative to the templates directory (usually in\n\t\t * controller/jobs/templates).\n\t\t *\n\t\t * You can overwrite the template file configuration in extensions and\n\t\t * provide alternative templates. These alternative templates should be\n\t\t * named like the default one but with the string \"standard\" replaced by\n\t\t * an unique name. You may use the name of your project for this. If\n\t\t * you've implemented an alternative client class as well, \"standard\"\n\t\t * should be replaced by the name of the new class.\n\t\t *\n\t\t * @param string Relative path to the template creating XML code for the site map footer\n\t\t * @since 2019.02\n\t\t * @category Developer\n\t\t * @see controller/jobs/catalog/export/sitemap/standard/template-header\n\t\t * @see controller/jobs/catalog/export/sitemap/standard/template-items\n\t\t * @see controller/jobs/catalog/export/sitemap/standard/template-index\n\t\t */", "$", "tplconf", "=", "'controller/jobs/catalog/export/sitemap/standard/template-footer'", ";", "$", "default", "=", "'catalog/export/sitemap-items-footer-standard'", ";", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "view", "=", "$", "context", "->", "getView", "(", ")", ";", "$", "content", "->", "add", "(", "$", "view", "->", "render", "(", "$", "context", "->", "getConfig", "(", ")", "->", "get", "(", "$", "tplconf", ",", "$", "default", ")", ")", ")", ";", "}" ]
Closes the site map content object @param \Aimeos\MW\Container\Content\Iface $content
[ "Closes", "the", "site", "map", "content", "object" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Catalog/Export/Sitemap/Standard.php#L261-L292
27,012
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Catalog/Export/Sitemap/Standard.php
Standard.createSitemapIndex
protected function createSitemapIndex( \Aimeos\MW\Container\Iface $container, array $files ) { /** controller/jobs/catalog/export/sitemap/standard/template-index * Relative path to the XML site map index template of the catalog site map job controller. * * The template file contains the XML code and processing instructions * to generate the site map index files. The configuration string is the path * to the template file relative to the templates directory (usually in * controller/jobs/templates). * * You can overwrite the template file configuration in extensions and * provide alternative templates. These alternative templates should be * named like the default one but with the string "standard" replaced by * an unique name. You may use the name of your project for this. If * you've implemented an alternative client class as well, "standard" * should be replaced by the name of the new class. * * @param string Relative path to the template creating XML code for the site map index * @since 2019.02 * @category Developer * @see controller/jobs/catalog/export/sitemap/standard/template-header * @see controller/jobs/catalog/export/sitemap/standard/template-items * @see controller/jobs/catalog/export/sitemap/standard/template-footer */ $tplconf = 'controller/jobs/catalog/export/sitemap/standard/template-index'; $default = 'catalog/export/sitemap-index-standard'; $context = $this->getContext(); $view = $context->getView(); $view->siteFiles = $files; $content = $container->create( 'aimeos-catalog-sitemap-index.xml' ); $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); $container->add( $content ); }
php
protected function createSitemapIndex( \Aimeos\MW\Container\Iface $container, array $files ) { /** controller/jobs/catalog/export/sitemap/standard/template-index * Relative path to the XML site map index template of the catalog site map job controller. * * The template file contains the XML code and processing instructions * to generate the site map index files. The configuration string is the path * to the template file relative to the templates directory (usually in * controller/jobs/templates). * * You can overwrite the template file configuration in extensions and * provide alternative templates. These alternative templates should be * named like the default one but with the string "standard" replaced by * an unique name. You may use the name of your project for this. If * you've implemented an alternative client class as well, "standard" * should be replaced by the name of the new class. * * @param string Relative path to the template creating XML code for the site map index * @since 2019.02 * @category Developer * @see controller/jobs/catalog/export/sitemap/standard/template-header * @see controller/jobs/catalog/export/sitemap/standard/template-items * @see controller/jobs/catalog/export/sitemap/standard/template-footer */ $tplconf = 'controller/jobs/catalog/export/sitemap/standard/template-index'; $default = 'catalog/export/sitemap-index-standard'; $context = $this->getContext(); $view = $context->getView(); $view->siteFiles = $files; $content = $container->create( 'aimeos-catalog-sitemap-index.xml' ); $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); $container->add( $content ); }
[ "protected", "function", "createSitemapIndex", "(", "\\", "Aimeos", "\\", "MW", "\\", "Container", "\\", "Iface", "$", "container", ",", "array", "$", "files", ")", "{", "/** controller/jobs/catalog/export/sitemap/standard/template-index\n\t\t * Relative path to the XML site map index template of the catalog site map job controller.\n\t\t *\n\t\t * The template file contains the XML code and processing instructions\n\t\t * to generate the site map index files. The configuration string is the path\n\t\t * to the template file relative to the templates directory (usually in\n\t\t * controller/jobs/templates).\n\t\t *\n\t\t * You can overwrite the template file configuration in extensions and\n\t\t * provide alternative templates. These alternative templates should be\n\t\t * named like the default one but with the string \"standard\" replaced by\n\t\t * an unique name. You may use the name of your project for this. If\n\t\t * you've implemented an alternative client class as well, \"standard\"\n\t\t * should be replaced by the name of the new class.\n\t\t *\n\t\t * @param string Relative path to the template creating XML code for the site map index\n\t\t * @since 2019.02\n\t\t * @category Developer\n\t\t * @see controller/jobs/catalog/export/sitemap/standard/template-header\n\t\t * @see controller/jobs/catalog/export/sitemap/standard/template-items\n\t\t * @see controller/jobs/catalog/export/sitemap/standard/template-footer\n\t\t */", "$", "tplconf", "=", "'controller/jobs/catalog/export/sitemap/standard/template-index'", ";", "$", "default", "=", "'catalog/export/sitemap-index-standard'", ";", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "view", "=", "$", "context", "->", "getView", "(", ")", ";", "$", "view", "->", "siteFiles", "=", "$", "files", ";", "$", "content", "=", "$", "container", "->", "create", "(", "'aimeos-catalog-sitemap-index.xml'", ")", ";", "$", "content", "->", "add", "(", "$", "view", "->", "render", "(", "$", "context", "->", "getConfig", "(", ")", "->", "get", "(", "$", "tplconf", ",", "$", "default", ")", ")", ")", ";", "$", "container", "->", "add", "(", "$", "content", ")", ";", "}" ]
Adds the content for the site map index file @param \Aimeos\MW\Container\Iface $container File container object @param array $files List of generated site map file names
[ "Adds", "the", "content", "for", "the", "site", "map", "index", "file" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Catalog/Export/Sitemap/Standard.php#L301-L336
27,013
aimeos/ai-controller-jobs
controller/common/src/Controller/Common/Product/Import/Csv/Base.php
Base.convertData
protected function convertData( array $convlist, array $data ) { foreach( $convlist as $idx => $converter ) { foreach( $data as $code => $list ) { if( isset( $list[$idx] ) ) { $data[$code][$idx] = $converter->translate( $list[$idx] ); } } } return $data; }
php
protected function convertData( array $convlist, array $data ) { foreach( $convlist as $idx => $converter ) { foreach( $data as $code => $list ) { if( isset( $list[$idx] ) ) { $data[$code][$idx] = $converter->translate( $list[$idx] ); } } } return $data; }
[ "protected", "function", "convertData", "(", "array", "$", "convlist", ",", "array", "$", "data", ")", "{", "foreach", "(", "$", "convlist", "as", "$", "idx", "=>", "$", "converter", ")", "{", "foreach", "(", "$", "data", "as", "$", "code", "=>", "$", "list", ")", "{", "if", "(", "isset", "(", "$", "list", "[", "$", "idx", "]", ")", ")", "{", "$", "data", "[", "$", "code", "]", "[", "$", "idx", "]", "=", "$", "converter", "->", "translate", "(", "$", "list", "[", "$", "idx", "]", ")", ";", "}", "}", "}", "return", "$", "data", ";", "}" ]
Converts the CSV field data using the available converter objects @param array $convlist Associative list of CSV field indexes and converter objects @param array $data Associative list of product codes and lists of CSV field indexes and their data @return array Associative list of CSV field indexes and their converted data
[ "Converts", "the", "CSV", "field", "data", "using", "the", "available", "converter", "objects" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/common/src/Controller/Common/Product/Import/Csv/Base.php#L30-L43
27,014
aimeos/ai-controller-jobs
controller/common/src/Controller/Common/Product/Import/Csv/Base.php
Base.getCache
protected function getCache( $type, $name = null ) { $context = $this->getContext(); $config = $context->getConfig(); if( ctype_alnum( $type ) === false ) { $classname = is_string( $name ) ? '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\' . $type : '<not a string>'; throw new \Aimeos\Controller\Common\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); } if( $name === null ) { $name = $config->get( 'controller/common/product/import/csv/cache/' . $type . '/name', 'Standard' ); } if( ctype_alnum( $name ) === false ) { $classname = is_string( $name ) ? '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\' . $type . '\\' . $name : '<not a string>'; throw new \Aimeos\Controller\Common\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); } $classname = '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\' . ucfirst( $type ) . '\\' . $name; if( class_exists( $classname ) === false ) { throw new \Aimeos\Controller\Common\Exception( sprintf( 'Class "%1$s" not found', $classname ) ); } $object = new $classname( $context ); \Aimeos\MW\Common\Base::checkClass( '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\Iface', $object ); return $object; }
php
protected function getCache( $type, $name = null ) { $context = $this->getContext(); $config = $context->getConfig(); if( ctype_alnum( $type ) === false ) { $classname = is_string( $name ) ? '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\' . $type : '<not a string>'; throw new \Aimeos\Controller\Common\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); } if( $name === null ) { $name = $config->get( 'controller/common/product/import/csv/cache/' . $type . '/name', 'Standard' ); } if( ctype_alnum( $name ) === false ) { $classname = is_string( $name ) ? '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\' . $type . '\\' . $name : '<not a string>'; throw new \Aimeos\Controller\Common\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); } $classname = '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\' . ucfirst( $type ) . '\\' . $name; if( class_exists( $classname ) === false ) { throw new \Aimeos\Controller\Common\Exception( sprintf( 'Class "%1$s" not found', $classname ) ); } $object = new $classname( $context ); \Aimeos\MW\Common\Base::checkClass( '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\Iface', $object ); return $object; }
[ "protected", "function", "getCache", "(", "$", "type", ",", "$", "name", "=", "null", ")", "{", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "config", "=", "$", "context", "->", "getConfig", "(", ")", ";", "if", "(", "ctype_alnum", "(", "$", "type", ")", "===", "false", ")", "{", "$", "classname", "=", "is_string", "(", "$", "name", ")", "?", "'\\\\Aimeos\\\\Controller\\\\Common\\\\Product\\\\Import\\\\Csv\\\\Cache\\\\'", ".", "$", "type", ":", "'<not a string>'", ";", "throw", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Common", "\\", "Exception", "(", "sprintf", "(", "'Invalid characters in class name \"%1$s\"'", ",", "$", "classname", ")", ")", ";", "}", "if", "(", "$", "name", "===", "null", ")", "{", "$", "name", "=", "$", "config", "->", "get", "(", "'controller/common/product/import/csv/cache/'", ".", "$", "type", ".", "'/name'", ",", "'Standard'", ")", ";", "}", "if", "(", "ctype_alnum", "(", "$", "name", ")", "===", "false", ")", "{", "$", "classname", "=", "is_string", "(", "$", "name", ")", "?", "'\\\\Aimeos\\\\Controller\\\\Common\\\\Product\\\\Import\\\\Csv\\\\Cache\\\\'", ".", "$", "type", ".", "'\\\\'", ".", "$", "name", ":", "'<not a string>'", ";", "throw", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Common", "\\", "Exception", "(", "sprintf", "(", "'Invalid characters in class name \"%1$s\"'", ",", "$", "classname", ")", ")", ";", "}", "$", "classname", "=", "'\\\\Aimeos\\\\Controller\\\\Common\\\\Product\\\\Import\\\\Csv\\\\Cache\\\\'", ".", "ucfirst", "(", "$", "type", ")", ".", "'\\\\'", ".", "$", "name", ";", "if", "(", "class_exists", "(", "$", "classname", ")", "===", "false", ")", "{", "throw", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Common", "\\", "Exception", "(", "sprintf", "(", "'Class \"%1$s\" not found'", ",", "$", "classname", ")", ")", ";", "}", "$", "object", "=", "new", "$", "classname", "(", "$", "context", ")", ";", "\\", "Aimeos", "\\", "MW", "\\", "Common", "\\", "Base", "::", "checkClass", "(", "'\\\\Aimeos\\\\Controller\\\\Common\\\\Product\\\\Import\\\\Csv\\\\Cache\\\\Iface'", ",", "$", "object", ")", ";", "return", "$", "object", ";", "}" ]
Returns the cache object for the given type @param string $type Type of the cached data @param string|null Name of the cache implementation @return \Aimeos\Controller\Common\Product\Import\Csv\Cache\Iface Cache object
[ "Returns", "the", "cache", "object", "for", "the", "given", "type" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/common/src/Controller/Common/Product/Import/Csv/Base.php#L53-L85
27,015
aimeos/ai-controller-jobs
controller/common/src/Controller/Common/Product/Import/Csv/Base.php
Base.getConverterList
protected function getConverterList( array $convmap ) { $convlist = []; foreach( $convmap as $idx => $name ) { $convlist[$idx] = \Aimeos\MW\Convert\Factory::createConverter( $name ); } return $convlist; }
php
protected function getConverterList( array $convmap ) { $convlist = []; foreach( $convmap as $idx => $name ) { $convlist[$idx] = \Aimeos\MW\Convert\Factory::createConverter( $name ); } return $convlist; }
[ "protected", "function", "getConverterList", "(", "array", "$", "convmap", ")", "{", "$", "convlist", "=", "[", "]", ";", "foreach", "(", "$", "convmap", "as", "$", "idx", "=>", "$", "name", ")", "{", "$", "convlist", "[", "$", "idx", "]", "=", "\\", "Aimeos", "\\", "MW", "\\", "Convert", "\\", "Factory", "::", "createConverter", "(", "$", "name", ")", ";", "}", "return", "$", "convlist", ";", "}" ]
Returns the list of converter objects based on the given converter map @param array $convmap List of converter names for the values at the position in the CSV file @return array Associative list of positions and converter objects
[ "Returns", "the", "list", "of", "converter", "objects", "based", "on", "the", "given", "converter", "map" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/common/src/Controller/Common/Product/Import/Csv/Base.php#L94-L103
27,016
aimeos/ai-controller-jobs
controller/common/src/Controller/Common/Product/Import/Csv/Base.php
Base.getProducts
protected function getProducts( array $codes, array $domains ) { $result = []; $manager = \Aimeos\MShop::create( $this->getContext(), 'product' ); $search = $manager->createSearch(); $search->setConditions( $search->compare( '==', 'product.code', $codes ) ); $search->setSlice( 0, count( $codes ) ); foreach( $manager->searchItems( $search, $domains ) as $item ) { $result[$item->getCode()] = $item; } return $result; }
php
protected function getProducts( array $codes, array $domains ) { $result = []; $manager = \Aimeos\MShop::create( $this->getContext(), 'product' ); $search = $manager->createSearch(); $search->setConditions( $search->compare( '==', 'product.code', $codes ) ); $search->setSlice( 0, count( $codes ) ); foreach( $manager->searchItems( $search, $domains ) as $item ) { $result[$item->getCode()] = $item; } return $result; }
[ "protected", "function", "getProducts", "(", "array", "$", "codes", ",", "array", "$", "domains", ")", "{", "$", "result", "=", "[", "]", ";", "$", "manager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "this", "->", "getContext", "(", ")", ",", "'product'", ")", ";", "$", "search", "=", "$", "manager", "->", "createSearch", "(", ")", ";", "$", "search", "->", "setConditions", "(", "$", "search", "->", "compare", "(", "'=='", ",", "'product.code'", ",", "$", "codes", ")", ")", ";", "$", "search", "->", "setSlice", "(", "0", ",", "count", "(", "$", "codes", ")", ")", ";", "foreach", "(", "$", "manager", "->", "searchItems", "(", "$", "search", ",", "$", "domains", ")", "as", "$", "item", ")", "{", "$", "result", "[", "$", "item", "->", "getCode", "(", ")", "]", "=", "$", "item", ";", "}", "return", "$", "result", ";", "}" ]
Returns the product items for the given codes @param array $codes List of product codes @param array $domains List of domains whose items should be fetched too @return array Associative list of product codes as key and product items as value
[ "Returns", "the", "product", "items", "for", "the", "given", "codes" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/common/src/Controller/Common/Product/Import/Csv/Base.php#L293-L307
27,017
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Subscription/Export/Csv/Standard.php
Standard.addJob
protected function addJob( $context, $path ) { $manager = \Aimeos\MAdmin::create( $context, 'job' ); $item = $manager->createItem(); $item->setResult( ['file' => $path] ); $item->setLabel( $path ); $manager->saveItem( $item, false ); }
php
protected function addJob( $context, $path ) { $manager = \Aimeos\MAdmin::create( $context, 'job' ); $item = $manager->createItem(); $item->setResult( ['file' => $path] ); $item->setLabel( $path ); $manager->saveItem( $item, false ); }
[ "protected", "function", "addJob", "(", "$", "context", ",", "$", "path", ")", "{", "$", "manager", "=", "\\", "Aimeos", "\\", "MAdmin", "::", "create", "(", "$", "context", ",", "'job'", ")", ";", "$", "item", "=", "$", "manager", "->", "createItem", "(", ")", ";", "$", "item", "->", "setResult", "(", "[", "'file'", "=>", "$", "path", "]", ")", ";", "$", "item", "->", "setLabel", "(", "$", "path", ")", ";", "$", "manager", "->", "saveItem", "(", "$", "item", ",", "false", ")", ";", "}" ]
Creates a new job entry for the exported file @param \Aimeos\MShop\Context\Item\Iface $context Context item @param string $path Absolute path to the exported file
[ "Creates", "a", "new", "job", "entry", "for", "the", "exported", "file" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Subscription/Export/Csv/Standard.php#L142-L151
27,018
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Subscription/Export/Csv/Standard.php
Standard.getContainer
protected function getContainer() { $config = $this->getContext()->getConfig(); /** controller/jobs/subscription/export/csv/location * Temporary file or directory where the content is stored which should be exported * * The path can point to any supported container format as long as the * content is in CSV format, e.g. * * Directory container / CSV file * * Zip container / compressed CSV file * * PHPExcel container / PHPExcel sheet * * @param string Absolute file or directory path * @since 2018.04 * @category Developer * @category User * @see controller/jobs/subscription/export/csv/container/type * @see controller/jobs/subscription/export/csv/container/content * @see controller/jobs/subscription/export/csv/container/options */ $location = $config->get( 'controller/jobs/subscription/export/csv/location', sys_get_temp_dir() ); /** controller/jobs/subscription/export/csv/container/type * Nave of the container type to read the data from * * The container type tells the exporter how it should retrieve the data. * There are currently three container types that support the necessary * CSV content: * * Directory * * Zip * * PHPExcel * * '''Note:''' For the PHPExcel container, you need to install the * "ai-container" extension. * * @param string Container type name * @since 2015.05 * @category Developer * @category User * @see controller/jobs/subscription/export/csv/location * @see controller/jobs/subscription/export/csv/container/content * @see controller/jobs/subscription/export/csv/container/options */ $container = $config->get( 'controller/jobs/subscription/export/csv/container/type', 'Directory' ); /** controller/jobs/subscription/export/csv/container/content * Name of the content type inside the container to read the data from * * The content type must always be a CSV-like format and there are * currently two format types that are supported: * * CSV * * PHPExcel * * '''Note:''' for the PHPExcel content type, you need to install the * "ai-container" extension. * * @param array Content type name * @since 2015.05 * @category Developer * @category User * @see controller/jobs/subscription/export/csv/location * @see controller/jobs/subscription/export/csv/container/type * @see controller/jobs/subscription/export/csv/container/options */ $content = $config->get( 'controller/jobs/subscription/export/csv/container/content', 'CSV' ); /** controller/jobs/subscription/export/csv/container/options * List of file container options for the subscription export files * * Some container/content type allow you to hand over additional settings * for configuration. Please have a look at the article about * {@link http://aimeos.org/docs/Developers/Utility/Create_and_read_files container/content files} * for more information. * * @param array Associative list of option name/value pairs * @since 2015.05 * @category Developer * @category User * @see controller/jobs/subscription/export/csv/location * @see controller/jobs/subscription/export/csv/container/content * @see controller/jobs/subscription/export/csv/container/type */ $options = $config->get( 'controller/jobs/subscription/export/csv/container/options', [] ); return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); }
php
protected function getContainer() { $config = $this->getContext()->getConfig(); /** controller/jobs/subscription/export/csv/location * Temporary file or directory where the content is stored which should be exported * * The path can point to any supported container format as long as the * content is in CSV format, e.g. * * Directory container / CSV file * * Zip container / compressed CSV file * * PHPExcel container / PHPExcel sheet * * @param string Absolute file or directory path * @since 2018.04 * @category Developer * @category User * @see controller/jobs/subscription/export/csv/container/type * @see controller/jobs/subscription/export/csv/container/content * @see controller/jobs/subscription/export/csv/container/options */ $location = $config->get( 'controller/jobs/subscription/export/csv/location', sys_get_temp_dir() ); /** controller/jobs/subscription/export/csv/container/type * Nave of the container type to read the data from * * The container type tells the exporter how it should retrieve the data. * There are currently three container types that support the necessary * CSV content: * * Directory * * Zip * * PHPExcel * * '''Note:''' For the PHPExcel container, you need to install the * "ai-container" extension. * * @param string Container type name * @since 2015.05 * @category Developer * @category User * @see controller/jobs/subscription/export/csv/location * @see controller/jobs/subscription/export/csv/container/content * @see controller/jobs/subscription/export/csv/container/options */ $container = $config->get( 'controller/jobs/subscription/export/csv/container/type', 'Directory' ); /** controller/jobs/subscription/export/csv/container/content * Name of the content type inside the container to read the data from * * The content type must always be a CSV-like format and there are * currently two format types that are supported: * * CSV * * PHPExcel * * '''Note:''' for the PHPExcel content type, you need to install the * "ai-container" extension. * * @param array Content type name * @since 2015.05 * @category Developer * @category User * @see controller/jobs/subscription/export/csv/location * @see controller/jobs/subscription/export/csv/container/type * @see controller/jobs/subscription/export/csv/container/options */ $content = $config->get( 'controller/jobs/subscription/export/csv/container/content', 'CSV' ); /** controller/jobs/subscription/export/csv/container/options * List of file container options for the subscription export files * * Some container/content type allow you to hand over additional settings * for configuration. Please have a look at the article about * {@link http://aimeos.org/docs/Developers/Utility/Create_and_read_files container/content files} * for more information. * * @param array Associative list of option name/value pairs * @since 2015.05 * @category Developer * @category User * @see controller/jobs/subscription/export/csv/location * @see controller/jobs/subscription/export/csv/container/content * @see controller/jobs/subscription/export/csv/container/type */ $options = $config->get( 'controller/jobs/subscription/export/csv/container/options', [] ); return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); }
[ "protected", "function", "getContainer", "(", ")", "{", "$", "config", "=", "$", "this", "->", "getContext", "(", ")", "->", "getConfig", "(", ")", ";", "/** controller/jobs/subscription/export/csv/location\n\t\t * Temporary file or directory where the content is stored which should be exported\n\t\t *\n\t\t * The path can point to any supported container format as long as the\n\t\t * content is in CSV format, e.g.\n\t\t * * Directory container / CSV file\n\t\t * * Zip container / compressed CSV file\n\t\t * * PHPExcel container / PHPExcel sheet\n\t\t *\n\t\t * @param string Absolute file or directory path\n\t\t * @since 2018.04\n\t\t * @category Developer\n\t\t * @category User\n\t\t * @see controller/jobs/subscription/export/csv/container/type\n\t\t * @see controller/jobs/subscription/export/csv/container/content\n\t\t * @see controller/jobs/subscription/export/csv/container/options\n\t\t */", "$", "location", "=", "$", "config", "->", "get", "(", "'controller/jobs/subscription/export/csv/location'", ",", "sys_get_temp_dir", "(", ")", ")", ";", "/** controller/jobs/subscription/export/csv/container/type\n\t\t * Nave of the container type to read the data from\n\t\t *\n\t\t * The container type tells the exporter how it should retrieve the data.\n\t\t * There are currently three container types that support the necessary\n\t\t * CSV content:\n\t\t * * Directory\n\t\t * * Zip\n\t\t * * PHPExcel\n\t\t *\n\t\t * '''Note:''' For the PHPExcel container, you need to install the\n\t\t * \"ai-container\" extension.\n\t\t *\n\t\t * @param string Container type name\n\t\t * @since 2015.05\n\t\t * @category Developer\n\t\t * @category User\n\t\t * @see controller/jobs/subscription/export/csv/location\n\t\t * @see controller/jobs/subscription/export/csv/container/content\n\t\t * @see controller/jobs/subscription/export/csv/container/options\n\t\t */", "$", "container", "=", "$", "config", "->", "get", "(", "'controller/jobs/subscription/export/csv/container/type'", ",", "'Directory'", ")", ";", "/** controller/jobs/subscription/export/csv/container/content\n\t\t * Name of the content type inside the container to read the data from\n\t\t *\n\t\t * The content type must always be a CSV-like format and there are\n\t\t * currently two format types that are supported:\n\t\t * * CSV\n\t\t * * PHPExcel\n\t\t *\n\t\t * '''Note:''' for the PHPExcel content type, you need to install the\n\t\t * \"ai-container\" extension.\n\t\t *\n\t\t * @param array Content type name\n\t\t * @since 2015.05\n\t\t * @category Developer\n\t\t * @category User\n\t\t * @see controller/jobs/subscription/export/csv/location\n\t\t * @see controller/jobs/subscription/export/csv/container/type\n\t\t * @see controller/jobs/subscription/export/csv/container/options\n\t\t */", "$", "content", "=", "$", "config", "->", "get", "(", "'controller/jobs/subscription/export/csv/container/content'", ",", "'CSV'", ")", ";", "/** controller/jobs/subscription/export/csv/container/options\n\t\t * List of file container options for the subscription export files\n\t\t *\n\t\t * Some container/content type allow you to hand over additional settings\n\t\t * for configuration. Please have a look at the article about\n\t\t * {@link http://aimeos.org/docs/Developers/Utility/Create_and_read_files container/content files}\n\t\t * for more information.\n\t\t *\n\t\t * @param array Associative list of option name/value pairs\n\t\t * @since 2015.05\n\t\t * @category Developer\n\t\t * @category User\n\t\t * @see controller/jobs/subscription/export/csv/location\n\t\t * @see controller/jobs/subscription/export/csv/container/content\n\t\t * @see controller/jobs/subscription/export/csv/container/type\n\t\t */", "$", "options", "=", "$", "config", "->", "get", "(", "'controller/jobs/subscription/export/csv/container/options'", ",", "[", "]", ")", ";", "return", "\\", "Aimeos", "\\", "MW", "\\", "Container", "\\", "Factory", "::", "getContainer", "(", "$", "location", ",", "$", "container", ",", "$", "content", ",", "$", "options", ")", ";", "}" ]
Opens and returns the container which includes the subscription data @return \Aimeos\MW\Container\Iface Container object
[ "Opens", "and", "returns", "the", "container", "which", "includes", "the", "subscription", "data" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Subscription/Export/Csv/Standard.php#L159-L245
27,019
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Subscription/Export/Csv/Standard.php
Standard.export
protected function export( array $processors, $msg, $maxcnt ) { $lcontext = $this->getLocaleContext( $msg ); $baseRef = ['order/base/address', 'order/base/product']; $manager = \Aimeos\MShop::create( $lcontext, 'subscription' ); $baseManager = \Aimeos\MShop::create( $lcontext, 'order/base' ); $container = $this->getContainer(); $content = $container->create( 'subscription-export_' . date( 'Y-m-d_H-i-s' ) ); $search = $this->initCriteria( $manager->createSearch()->setSlice( 0, 0x7fffffff ), $msg ); $start = 0; do { $baseIds = []; $search->setSlice( $start, $maxcnt ); $items = $manager->searchItems( $search ); foreach( $items as $item ) { $baseIds[] = $item->getOrderBaseId(); } $baseSearch = $baseManager->createSearch(); $baseSearch->setConditions( $baseSearch->compare( '==', 'order.base.id', $baseIds ) ); $baseSearch->setSlice( 0, count( $baseIds ) ); $baseItems = $baseManager->searchItems( $baseSearch, $baseRef ); foreach( $items as $id => $item ) { foreach( $processors as $type => $processor ) { foreach( $processor->process( $item, $baseItems[$item->getOrderBaseId()] ) as $line ) { $content->add( [0 => $type, 1 => $id] + $line ); } } } $count = count( $items ); $start += $count; } while( $count === $search->getSliceSize() ); $path = $content->getResource(); $container->add( $content ); $container->close(); $path = $this->moveFile( $lcontext, $path ); $this->addJob( $lcontext, $path ); }
php
protected function export( array $processors, $msg, $maxcnt ) { $lcontext = $this->getLocaleContext( $msg ); $baseRef = ['order/base/address', 'order/base/product']; $manager = \Aimeos\MShop::create( $lcontext, 'subscription' ); $baseManager = \Aimeos\MShop::create( $lcontext, 'order/base' ); $container = $this->getContainer(); $content = $container->create( 'subscription-export_' . date( 'Y-m-d_H-i-s' ) ); $search = $this->initCriteria( $manager->createSearch()->setSlice( 0, 0x7fffffff ), $msg ); $start = 0; do { $baseIds = []; $search->setSlice( $start, $maxcnt ); $items = $manager->searchItems( $search ); foreach( $items as $item ) { $baseIds[] = $item->getOrderBaseId(); } $baseSearch = $baseManager->createSearch(); $baseSearch->setConditions( $baseSearch->compare( '==', 'order.base.id', $baseIds ) ); $baseSearch->setSlice( 0, count( $baseIds ) ); $baseItems = $baseManager->searchItems( $baseSearch, $baseRef ); foreach( $items as $id => $item ) { foreach( $processors as $type => $processor ) { foreach( $processor->process( $item, $baseItems[$item->getOrderBaseId()] ) as $line ) { $content->add( [0 => $type, 1 => $id] + $line ); } } } $count = count( $items ); $start += $count; } while( $count === $search->getSliceSize() ); $path = $content->getResource(); $container->add( $content ); $container->close(); $path = $this->moveFile( $lcontext, $path ); $this->addJob( $lcontext, $path ); }
[ "protected", "function", "export", "(", "array", "$", "processors", ",", "$", "msg", ",", "$", "maxcnt", ")", "{", "$", "lcontext", "=", "$", "this", "->", "getLocaleContext", "(", "$", "msg", ")", ";", "$", "baseRef", "=", "[", "'order/base/address'", ",", "'order/base/product'", "]", ";", "$", "manager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "lcontext", ",", "'subscription'", ")", ";", "$", "baseManager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "lcontext", ",", "'order/base'", ")", ";", "$", "container", "=", "$", "this", "->", "getContainer", "(", ")", ";", "$", "content", "=", "$", "container", "->", "create", "(", "'subscription-export_'", ".", "date", "(", "'Y-m-d_H-i-s'", ")", ")", ";", "$", "search", "=", "$", "this", "->", "initCriteria", "(", "$", "manager", "->", "createSearch", "(", ")", "->", "setSlice", "(", "0", ",", "0x7fffffff", ")", ",", "$", "msg", ")", ";", "$", "start", "=", "0", ";", "do", "{", "$", "baseIds", "=", "[", "]", ";", "$", "search", "->", "setSlice", "(", "$", "start", ",", "$", "maxcnt", ")", ";", "$", "items", "=", "$", "manager", "->", "searchItems", "(", "$", "search", ")", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "baseIds", "[", "]", "=", "$", "item", "->", "getOrderBaseId", "(", ")", ";", "}", "$", "baseSearch", "=", "$", "baseManager", "->", "createSearch", "(", ")", ";", "$", "baseSearch", "->", "setConditions", "(", "$", "baseSearch", "->", "compare", "(", "'=='", ",", "'order.base.id'", ",", "$", "baseIds", ")", ")", ";", "$", "baseSearch", "->", "setSlice", "(", "0", ",", "count", "(", "$", "baseIds", ")", ")", ";", "$", "baseItems", "=", "$", "baseManager", "->", "searchItems", "(", "$", "baseSearch", ",", "$", "baseRef", ")", ";", "foreach", "(", "$", "items", "as", "$", "id", "=>", "$", "item", ")", "{", "foreach", "(", "$", "processors", "as", "$", "type", "=>", "$", "processor", ")", "{", "foreach", "(", "$", "processor", "->", "process", "(", "$", "item", ",", "$", "baseItems", "[", "$", "item", "->", "getOrderBaseId", "(", ")", "]", ")", "as", "$", "line", ")", "{", "$", "content", "->", "add", "(", "[", "0", "=>", "$", "type", ",", "1", "=>", "$", "id", "]", "+", "$", "line", ")", ";", "}", "}", "}", "$", "count", "=", "count", "(", "$", "items", ")", ";", "$", "start", "+=", "$", "count", ";", "}", "while", "(", "$", "count", "===", "$", "search", "->", "getSliceSize", "(", ")", ")", ";", "$", "path", "=", "$", "content", "->", "getResource", "(", ")", ";", "$", "container", "->", "add", "(", "$", "content", ")", ";", "$", "container", "->", "close", "(", ")", ";", "$", "path", "=", "$", "this", "->", "moveFile", "(", "$", "lcontext", ",", "$", "path", ")", ";", "$", "this", "->", "addJob", "(", "$", "lcontext", ",", "$", "path", ")", ";", "}" ]
Exports the subscriptions and returns the exported file name @param Aimeos\Controller\Common\Subscription\Export\Csv\Processor\Iface[] List of processor objects @param array $msg Message data passed from the frontend @param integer $maxcnt Maximum number of retrieved subscriptions at once @return string Path of the file containing the exported data
[ "Exports", "the", "subscriptions", "and", "returns", "the", "exported", "file", "name" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Subscription/Export/Csv/Standard.php#L256-L306
27,020
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Subscription/Export/Csv/Standard.php
Standard.getLocaleContext
protected function getLocaleContext( array $msg ) { $lcontext = clone $this->getContext(); $manager = \Aimeos\MShop::create( $lcontext, 'locale' ); $sitecode = ( isset( $msg['sitecode'] ) ? $msg['sitecode'] : 'default' ); $localeItem = $manager->bootstrap( $sitecode, '', '', false, \Aimeos\MShop\Locale\Manager\Base::SITE_ONE ); return $lcontext->setLocale( $localeItem ); }
php
protected function getLocaleContext( array $msg ) { $lcontext = clone $this->getContext(); $manager = \Aimeos\MShop::create( $lcontext, 'locale' ); $sitecode = ( isset( $msg['sitecode'] ) ? $msg['sitecode'] : 'default' ); $localeItem = $manager->bootstrap( $sitecode, '', '', false, \Aimeos\MShop\Locale\Manager\Base::SITE_ONE ); return $lcontext->setLocale( $localeItem ); }
[ "protected", "function", "getLocaleContext", "(", "array", "$", "msg", ")", "{", "$", "lcontext", "=", "clone", "$", "this", "->", "getContext", "(", ")", ";", "$", "manager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "lcontext", ",", "'locale'", ")", ";", "$", "sitecode", "=", "(", "isset", "(", "$", "msg", "[", "'sitecode'", "]", ")", "?", "$", "msg", "[", "'sitecode'", "]", ":", "'default'", ")", ";", "$", "localeItem", "=", "$", "manager", "->", "bootstrap", "(", "$", "sitecode", ",", "''", ",", "''", ",", "false", ",", "\\", "Aimeos", "\\", "MShop", "\\", "Locale", "\\", "Manager", "\\", "Base", "::", "SITE_ONE", ")", ";", "return", "$", "lcontext", "->", "setLocale", "(", "$", "localeItem", ")", ";", "}" ]
Returns a new context including the locale from the message data @param array $msg Message data including a "sitecode" value @return \Aimeos\MShop\Context\Item\Iface New context item with updated locale
[ "Returns", "a", "new", "context", "including", "the", "locale", "from", "the", "message", "data" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Subscription/Export/Csv/Standard.php#L315-L324
27,021
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Subscription/Export/Csv/Standard.php
Standard.initCriteria
protected function initCriteria( \Aimeos\MW\Criteria\Iface $criteria, array $msg ) { if( isset( $msg['filter'] ) ) { $criteria->setConditions( $criteria->toConditions( $msg['filter'] ) ); } if( isset( $msg['sort'] ) ) { $criteria->setSortations( $criteria->toSortations( $msg['sort'] ) ); } return $criteria; }
php
protected function initCriteria( \Aimeos\MW\Criteria\Iface $criteria, array $msg ) { if( isset( $msg['filter'] ) ) { $criteria->setConditions( $criteria->toConditions( $msg['filter'] ) ); } if( isset( $msg['sort'] ) ) { $criteria->setSortations( $criteria->toSortations( $msg['sort'] ) ); } return $criteria; }
[ "protected", "function", "initCriteria", "(", "\\", "Aimeos", "\\", "MW", "\\", "Criteria", "\\", "Iface", "$", "criteria", ",", "array", "$", "msg", ")", "{", "if", "(", "isset", "(", "$", "msg", "[", "'filter'", "]", ")", ")", "{", "$", "criteria", "->", "setConditions", "(", "$", "criteria", "->", "toConditions", "(", "$", "msg", "[", "'filter'", "]", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "msg", "[", "'sort'", "]", ")", ")", "{", "$", "criteria", "->", "setSortations", "(", "$", "criteria", "->", "toSortations", "(", "$", "msg", "[", "'sort'", "]", ")", ")", ";", "}", "return", "$", "criteria", ";", "}" ]
Initializes the search criteria @param \Aimeos\MW\Criteria\Iface $criteria New criteria object @param array $msg Message data @return \Aimeos\MW\Criteria\Iface Initialized criteria object
[ "Initializes", "the", "search", "criteria" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Subscription/Export/Csv/Standard.php#L334-L345
27,022
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Subscription/Export/Csv/Standard.php
Standard.moveFile
protected function moveFile( $context, $path ) { $filename = basename( $path ); $context->getFileSystemManager()->get( 'fs-admin' )->writef( $filename, $path ); unlink( $path ); return $filename; }
php
protected function moveFile( $context, $path ) { $filename = basename( $path ); $context->getFileSystemManager()->get( 'fs-admin' )->writef( $filename, $path ); unlink( $path ); return $filename; }
[ "protected", "function", "moveFile", "(", "$", "context", ",", "$", "path", ")", "{", "$", "filename", "=", "basename", "(", "$", "path", ")", ";", "$", "context", "->", "getFileSystemManager", "(", ")", "->", "get", "(", "'fs-admin'", ")", "->", "writef", "(", "$", "filename", ",", "$", "path", ")", ";", "unlink", "(", "$", "path", ")", ";", "return", "$", "filename", ";", "}" ]
Moves the exported file to the final storage @param \Aimeos\MShop\Context\Item\Iface $context Context item @param string $path Absolute path to the exported file @return string Relative path of the file in the storage
[ "Moves", "the", "exported", "file", "to", "the", "final", "storage" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Subscription/Export/Csv/Standard.php#L355-L362
27,023
aimeos/ai-controller-jobs
controller/common/src/Controller/Common/Subscription/Process/Processor/Cgroup/Standard.php
Standard.begin
public function begin( \Aimeos\MShop\Subscription\Item\Iface $subscription ) { if( empty( $this->groupIds ) ) { return; } $context = $this->getContext(); $manager = \Aimeos\MShop::create( $context, 'customer' ); $baseManager = \Aimeos\MShop::create( $context, 'order/base' ); $baseItem = $baseManager->getItem( $subscription->getOrderBaseId() ); $item = $manager->getItem( $baseItem->getCustomerId(), ['customer/group'] ); $item->setGroups( array_unique( array_merge( $item->getGroups(), $this->groupIds ) ) ); $manager->saveItem( $item ); }
php
public function begin( \Aimeos\MShop\Subscription\Item\Iface $subscription ) { if( empty( $this->groupIds ) ) { return; } $context = $this->getContext(); $manager = \Aimeos\MShop::create( $context, 'customer' ); $baseManager = \Aimeos\MShop::create( $context, 'order/base' ); $baseItem = $baseManager->getItem( $subscription->getOrderBaseId() ); $item = $manager->getItem( $baseItem->getCustomerId(), ['customer/group'] ); $item->setGroups( array_unique( array_merge( $item->getGroups(), $this->groupIds ) ) ); $manager->saveItem( $item ); }
[ "public", "function", "begin", "(", "\\", "Aimeos", "\\", "MShop", "\\", "Subscription", "\\", "Item", "\\", "Iface", "$", "subscription", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "groupIds", ")", ")", "{", "return", ";", "}", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "manager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "context", ",", "'customer'", ")", ";", "$", "baseManager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "context", ",", "'order/base'", ")", ";", "$", "baseItem", "=", "$", "baseManager", "->", "getItem", "(", "$", "subscription", "->", "getOrderBaseId", "(", ")", ")", ";", "$", "item", "=", "$", "manager", "->", "getItem", "(", "$", "baseItem", "->", "getCustomerId", "(", ")", ",", "[", "'customer/group'", "]", ")", ";", "$", "item", "->", "setGroups", "(", "array_unique", "(", "array_merge", "(", "$", "item", "->", "getGroups", "(", ")", ",", "$", "this", "->", "groupIds", ")", ")", ")", ";", "$", "manager", "->", "saveItem", "(", "$", "item", ")", ";", "}" ]
Processes the initial subscription @param \Aimeos\MShop\Subscription\Item\Iface $subscription Subscription item
[ "Processes", "the", "initial", "subscription" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/common/src/Controller/Common/Subscription/Process/Processor/Cgroup/Standard.php#L69-L85
27,024
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Product/Bought/Standard.php
Standard.getSuggestions
protected function getSuggestions( $id, $prodIds, $count, $total, $maxItems, $minSupport, $minConfidence, $date ) { $refIds = []; $context = $this->getContext(); $catalogListManager = \Aimeos\MShop::create( $context, 'catalog/lists' ); $baseProductManager = \Aimeos\MShop::create( $context, 'order/base/product' ); $search = $baseProductManager->createSearch(); $func = $search->createFunction( 'order.base.product.count', array( (string) $id ) ); $expr = array( $search->compare( '==', 'order.base.product.productid', $prodIds ), $search->compare( '>', 'order.base.product.ctime', $date ), $search->compare( '==', $func, 1 ), ); $search->setConditions( $search->combine( '&&', $expr ) ); $relativeCounts = $baseProductManager->aggregate( $search, 'order.base.product.productid' ); $search = $catalogListManager->createSearch(); $expr = array( $search->compare( '==', 'catalog.lists.refid', array_keys( $relativeCounts ) ), $search->compare( '==', 'catalog.lists.domain', 'product' ), ); $search->setConditions( $search->combine( '&&', $expr ) ); foreach( $catalogListManager->searchItems( $search ) as $listItem ) { $refIds[$listItem->getRefId()] = true; } unset( $relativeCounts[$id] ); $supportA = $count / $total; $products = []; foreach( $relativeCounts as $prodId => $relCnt ) { if( !isset( $refIds[$prodId] ) ) { continue; } $supportAB = $relCnt / $total; if( $supportAB > $minSupport && ( $conf = ( $supportAB / $supportA ) ) > $minConfidence ) { $products[$prodId] = $conf; } } arsort( $products ); return array_keys( array_slice( $products, 0, $maxItems, true ) ); }
php
protected function getSuggestions( $id, $prodIds, $count, $total, $maxItems, $minSupport, $minConfidence, $date ) { $refIds = []; $context = $this->getContext(); $catalogListManager = \Aimeos\MShop::create( $context, 'catalog/lists' ); $baseProductManager = \Aimeos\MShop::create( $context, 'order/base/product' ); $search = $baseProductManager->createSearch(); $func = $search->createFunction( 'order.base.product.count', array( (string) $id ) ); $expr = array( $search->compare( '==', 'order.base.product.productid', $prodIds ), $search->compare( '>', 'order.base.product.ctime', $date ), $search->compare( '==', $func, 1 ), ); $search->setConditions( $search->combine( '&&', $expr ) ); $relativeCounts = $baseProductManager->aggregate( $search, 'order.base.product.productid' ); $search = $catalogListManager->createSearch(); $expr = array( $search->compare( '==', 'catalog.lists.refid', array_keys( $relativeCounts ) ), $search->compare( '==', 'catalog.lists.domain', 'product' ), ); $search->setConditions( $search->combine( '&&', $expr ) ); foreach( $catalogListManager->searchItems( $search ) as $listItem ) { $refIds[$listItem->getRefId()] = true; } unset( $relativeCounts[$id] ); $supportA = $count / $total; $products = []; foreach( $relativeCounts as $prodId => $relCnt ) { if( !isset( $refIds[$prodId] ) ) { continue; } $supportAB = $relCnt / $total; if( $supportAB > $minSupport && ( $conf = ( $supportAB / $supportA ) ) > $minConfidence ) { $products[$prodId] = $conf; } } arsort( $products ); return array_keys( array_slice( $products, 0, $maxItems, true ) ); }
[ "protected", "function", "getSuggestions", "(", "$", "id", ",", "$", "prodIds", ",", "$", "count", ",", "$", "total", ",", "$", "maxItems", ",", "$", "minSupport", ",", "$", "minConfidence", ",", "$", "date", ")", "{", "$", "refIds", "=", "[", "]", ";", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "catalogListManager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "context", ",", "'catalog/lists'", ")", ";", "$", "baseProductManager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "context", ",", "'order/base/product'", ")", ";", "$", "search", "=", "$", "baseProductManager", "->", "createSearch", "(", ")", ";", "$", "func", "=", "$", "search", "->", "createFunction", "(", "'order.base.product.count'", ",", "array", "(", "(", "string", ")", "$", "id", ")", ")", ";", "$", "expr", "=", "array", "(", "$", "search", "->", "compare", "(", "'=='", ",", "'order.base.product.productid'", ",", "$", "prodIds", ")", ",", "$", "search", "->", "compare", "(", "'>'", ",", "'order.base.product.ctime'", ",", "$", "date", ")", ",", "$", "search", "->", "compare", "(", "'=='", ",", "$", "func", ",", "1", ")", ",", ")", ";", "$", "search", "->", "setConditions", "(", "$", "search", "->", "combine", "(", "'&&'", ",", "$", "expr", ")", ")", ";", "$", "relativeCounts", "=", "$", "baseProductManager", "->", "aggregate", "(", "$", "search", ",", "'order.base.product.productid'", ")", ";", "$", "search", "=", "$", "catalogListManager", "->", "createSearch", "(", ")", ";", "$", "expr", "=", "array", "(", "$", "search", "->", "compare", "(", "'=='", ",", "'catalog.lists.refid'", ",", "array_keys", "(", "$", "relativeCounts", ")", ")", ",", "$", "search", "->", "compare", "(", "'=='", ",", "'catalog.lists.domain'", ",", "'product'", ")", ",", ")", ";", "$", "search", "->", "setConditions", "(", "$", "search", "->", "combine", "(", "'&&'", ",", "$", "expr", ")", ")", ";", "foreach", "(", "$", "catalogListManager", "->", "searchItems", "(", "$", "search", ")", "as", "$", "listItem", ")", "{", "$", "refIds", "[", "$", "listItem", "->", "getRefId", "(", ")", "]", "=", "true", ";", "}", "unset", "(", "$", "relativeCounts", "[", "$", "id", "]", ")", ";", "$", "supportA", "=", "$", "count", "/", "$", "total", ";", "$", "products", "=", "[", "]", ";", "foreach", "(", "$", "relativeCounts", "as", "$", "prodId", "=>", "$", "relCnt", ")", "{", "if", "(", "!", "isset", "(", "$", "refIds", "[", "$", "prodId", "]", ")", ")", "{", "continue", ";", "}", "$", "supportAB", "=", "$", "relCnt", "/", "$", "total", ";", "if", "(", "$", "supportAB", ">", "$", "minSupport", "&&", "(", "$", "conf", "=", "(", "$", "supportAB", "/", "$", "supportA", ")", ")", ">", "$", "minConfidence", ")", "{", "$", "products", "[", "$", "prodId", "]", "=", "$", "conf", ";", "}", "}", "arsort", "(", "$", "products", ")", ";", "return", "array_keys", "(", "array_slice", "(", "$", "products", ",", "0", ",", "$", "maxItems", ",", "true", ")", ")", ";", "}" ]
Returns the IDs of the suggested products. @param string $id Product ID to calculate the suggestions for @param string[] $prodIds List of product IDs to create suggestions for @param integer $count Number of ordered products @param integer $total Total number of orders @param integer $maxItems Maximum number of suggestions @param float $minSupport Minium support value for calculating the suggested products @param float $minConfidence Minium confidence value for calculating the suggested products @param string $date Date in YYYY-MM-DD HH:mm:ss format after which orders should be used for calculations @return array List of suggested product IDs as key and their confidence as value
[ "Returns", "the", "IDs", "of", "the", "suggested", "products", "." ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Product/Bought/Standard.php#L206-L259
27,025
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Product/Bought/Standard.php
Standard.addListItems
protected function addListItems( $productId, array $productIds ) { if( empty( $productIds ) ) { return; } $manager = \Aimeos\MShop::create( $this->getContext(), 'product/lists' ); $item = $manager->createItem(); foreach( $productIds as $pos => $refid ) { $item->setId( null ); $item->setParentId( $productId ); $item->setDomain( 'product' ); $item->setType( 'bought-together' ); $item->setPosition( $pos ); $item->setRefId( $refid ); $item->setStatus( 1 ); $manager->saveItem( $item, false ); } }
php
protected function addListItems( $productId, array $productIds ) { if( empty( $productIds ) ) { return; } $manager = \Aimeos\MShop::create( $this->getContext(), 'product/lists' ); $item = $manager->createItem(); foreach( $productIds as $pos => $refid ) { $item->setId( null ); $item->setParentId( $productId ); $item->setDomain( 'product' ); $item->setType( 'bought-together' ); $item->setPosition( $pos ); $item->setRefId( $refid ); $item->setStatus( 1 ); $manager->saveItem( $item, false ); } }
[ "protected", "function", "addListItems", "(", "$", "productId", ",", "array", "$", "productIds", ")", "{", "if", "(", "empty", "(", "$", "productIds", ")", ")", "{", "return", ";", "}", "$", "manager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "this", "->", "getContext", "(", ")", ",", "'product/lists'", ")", ";", "$", "item", "=", "$", "manager", "->", "createItem", "(", ")", ";", "foreach", "(", "$", "productIds", "as", "$", "pos", "=>", "$", "refid", ")", "{", "$", "item", "->", "setId", "(", "null", ")", ";", "$", "item", "->", "setParentId", "(", "$", "productId", ")", ";", "$", "item", "->", "setDomain", "(", "'product'", ")", ";", "$", "item", "->", "setType", "(", "'bought-together'", ")", ";", "$", "item", "->", "setPosition", "(", "$", "pos", ")", ";", "$", "item", "->", "setRefId", "(", "$", "refid", ")", ";", "$", "item", "->", "setStatus", "(", "1", ")", ";", "$", "manager", "->", "saveItem", "(", "$", "item", ",", "false", ")", ";", "}", "}" ]
Adds products as referenced products to the product list. @param string $productId Unique ID of the product the given products should be referenced to @param array $productIds List of position as key and product ID as value
[ "Adds", "products", "as", "referenced", "products", "to", "the", "product", "list", "." ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Product/Bought/Standard.php#L268-L289
27,026
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Product/Bought/Standard.php
Standard.removeListItems
protected function removeListItems( $productId ) { $manager = \Aimeos\MShop::create( $this->getContext(), 'product/lists' ); $search = $manager->createSearch(); $expr = array( $search->compare( '==', 'product.lists.parentid', $productId ), $search->compare( '==', 'product.lists.domain', 'product' ), $search->compare( '==', 'product.lists.type', 'bought-together' ), ); $search->setConditions( $search->combine( '&&', $expr ) ); $listItems = $manager->searchItems( $search ); $manager->deleteItems( array_keys( $listItems ) ); }
php
protected function removeListItems( $productId ) { $manager = \Aimeos\MShop::create( $this->getContext(), 'product/lists' ); $search = $manager->createSearch(); $expr = array( $search->compare( '==', 'product.lists.parentid', $productId ), $search->compare( '==', 'product.lists.domain', 'product' ), $search->compare( '==', 'product.lists.type', 'bought-together' ), ); $search->setConditions( $search->combine( '&&', $expr ) ); $listItems = $manager->searchItems( $search ); $manager->deleteItems( array_keys( $listItems ) ); }
[ "protected", "function", "removeListItems", "(", "$", "productId", ")", "{", "$", "manager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "this", "->", "getContext", "(", ")", ",", "'product/lists'", ")", ";", "$", "search", "=", "$", "manager", "->", "createSearch", "(", ")", ";", "$", "expr", "=", "array", "(", "$", "search", "->", "compare", "(", "'=='", ",", "'product.lists.parentid'", ",", "$", "productId", ")", ",", "$", "search", "->", "compare", "(", "'=='", ",", "'product.lists.domain'", ",", "'product'", ")", ",", "$", "search", "->", "compare", "(", "'=='", ",", "'product.lists.type'", ",", "'bought-together'", ")", ",", ")", ";", "$", "search", "->", "setConditions", "(", "$", "search", "->", "combine", "(", "'&&'", ",", "$", "expr", ")", ")", ";", "$", "listItems", "=", "$", "manager", "->", "searchItems", "(", "$", "search", ")", ";", "$", "manager", "->", "deleteItems", "(", "array_keys", "(", "$", "listItems", ")", ")", ";", "}" ]
Remove all suggested products from product list. @param string $productId Unique ID of the product the references should be removed from
[ "Remove", "all", "suggested", "products", "from", "product", "list", "." ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Product/Bought/Standard.php#L297-L312
27,027
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Subscription/Process/Base.php
Base.getProcessors
protected function getProcessors( array $pnames ) { $list = []; $context = $this->getContext(); $config = $context->getConfig(); foreach( $pnames as $pname ) { if( ctype_alnum( $pname ) === false ) { $classname = is_string( $pname ) ? '\\Aimeos\\Controller\\Common\\Subscription\\Process\\Processor\\' . $pname : '<not a string>'; throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); } $name = $config->get( 'controller/common/subscription/process/processor/' . $pname . '/name', 'Standard' ); if( ctype_alnum( $name ) === false ) { $classname = is_string( $name ) ? '\\Aimeos\\Controller\\Common\\Subscription\\Process\\Processor\\' . $pname . '\\' . $name : '<not a string>'; throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); } $classname = '\\Aimeos\\Controller\\Common\\Subscription\\Process\\Processor\\' . ucfirst( $pname ) . '\\' . $name; if( class_exists( $classname ) === false ) { throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" not found', $classname ) ); } $object = new $classname( $context ); \Aimeos\MW\Common\Base::checkClass( '\\Aimeos\\Controller\\Common\\Subscription\\Process\\Processor\\Iface', $object ); $list[$pname] = $object; } return $list; }
php
protected function getProcessors( array $pnames ) { $list = []; $context = $this->getContext(); $config = $context->getConfig(); foreach( $pnames as $pname ) { if( ctype_alnum( $pname ) === false ) { $classname = is_string( $pname ) ? '\\Aimeos\\Controller\\Common\\Subscription\\Process\\Processor\\' . $pname : '<not a string>'; throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); } $name = $config->get( 'controller/common/subscription/process/processor/' . $pname . '/name', 'Standard' ); if( ctype_alnum( $name ) === false ) { $classname = is_string( $name ) ? '\\Aimeos\\Controller\\Common\\Subscription\\Process\\Processor\\' . $pname . '\\' . $name : '<not a string>'; throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); } $classname = '\\Aimeos\\Controller\\Common\\Subscription\\Process\\Processor\\' . ucfirst( $pname ) . '\\' . $name; if( class_exists( $classname ) === false ) { throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" not found', $classname ) ); } $object = new $classname( $context ); \Aimeos\MW\Common\Base::checkClass( '\\Aimeos\\Controller\\Common\\Subscription\\Process\\Processor\\Iface', $object ); $list[$pname] = $object; } return $list; }
[ "protected", "function", "getProcessors", "(", "array", "$", "pnames", ")", "{", "$", "list", "=", "[", "]", ";", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "config", "=", "$", "context", "->", "getConfig", "(", ")", ";", "foreach", "(", "$", "pnames", "as", "$", "pname", ")", "{", "if", "(", "ctype_alnum", "(", "$", "pname", ")", "===", "false", ")", "{", "$", "classname", "=", "is_string", "(", "$", "pname", ")", "?", "'\\\\Aimeos\\\\Controller\\\\Common\\\\Subscription\\\\Process\\\\Processor\\\\'", ".", "$", "pname", ":", "'<not a string>'", ";", "throw", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Jobs", "\\", "Exception", "(", "sprintf", "(", "'Invalid characters in class name \"%1$s\"'", ",", "$", "classname", ")", ")", ";", "}", "$", "name", "=", "$", "config", "->", "get", "(", "'controller/common/subscription/process/processor/'", ".", "$", "pname", ".", "'/name'", ",", "'Standard'", ")", ";", "if", "(", "ctype_alnum", "(", "$", "name", ")", "===", "false", ")", "{", "$", "classname", "=", "is_string", "(", "$", "name", ")", "?", "'\\\\Aimeos\\\\Controller\\\\Common\\\\Subscription\\\\Process\\\\Processor\\\\'", ".", "$", "pname", ".", "'\\\\'", ".", "$", "name", ":", "'<not a string>'", ";", "throw", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Jobs", "\\", "Exception", "(", "sprintf", "(", "'Invalid characters in class name \"%1$s\"'", ",", "$", "classname", ")", ")", ";", "}", "$", "classname", "=", "'\\\\Aimeos\\\\Controller\\\\Common\\\\Subscription\\\\Process\\\\Processor\\\\'", ".", "ucfirst", "(", "$", "pname", ")", ".", "'\\\\'", ".", "$", "name", ";", "if", "(", "class_exists", "(", "$", "classname", ")", "===", "false", ")", "{", "throw", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Jobs", "\\", "Exception", "(", "sprintf", "(", "'Class \"%1$s\" not found'", ",", "$", "classname", ")", ")", ";", "}", "$", "object", "=", "new", "$", "classname", "(", "$", "context", ")", ";", "\\", "Aimeos", "\\", "MW", "\\", "Common", "\\", "Base", "::", "checkClass", "(", "'\\\\Aimeos\\\\Controller\\\\Common\\\\Subscription\\\\Process\\\\Processor\\\\Iface'", ",", "$", "object", ")", ";", "$", "list", "[", "$", "pname", "]", "=", "$", "object", ";", "}", "return", "$", "list", ";", "}" ]
Returns the processor object for managing the subscription resources @param array $pnames List of processor names @return \Aimeos\Controller\Common\Subscription\Export\Csv\Processor\Iface Processor object
[ "Returns", "the", "processor", "object", "for", "managing", "the", "subscription", "resources" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Subscription/Process/Base.php#L30-L66
27,028
pr-of-it/t4
framework/Mvc/Router.php
Router.splitRequestPath
protected function splitRequestPath($path) { // Domain part extract $parts = explode('!', $path); if (count($parts) > 1) { $domain = $parts[0]; $path = $parts[1]; } else { $domain = null; } $parts = parse_url($path); $basePath = !empty($parts['path']) ? $parts['path'] : '/'; if (empty($basePath)) { $extension = null; } else { $extension = pathinfo($basePath, PATHINFO_EXTENSION); $basePath = preg_replace('~\.' . $extension . '$~', '', $basePath); } if (!in_array($extension, $this->allowedExtensions)) { $extension = ''; } return new Route([ 'domain' => $domain, 'basepath' => $basePath, 'extension' => $extension, ]); }
php
protected function splitRequestPath($path) { // Domain part extract $parts = explode('!', $path); if (count($parts) > 1) { $domain = $parts[0]; $path = $parts[1]; } else { $domain = null; } $parts = parse_url($path); $basePath = !empty($parts['path']) ? $parts['path'] : '/'; if (empty($basePath)) { $extension = null; } else { $extension = pathinfo($basePath, PATHINFO_EXTENSION); $basePath = preg_replace('~\.' . $extension . '$~', '', $basePath); } if (!in_array($extension, $this->allowedExtensions)) { $extension = ''; } return new Route([ 'domain' => $domain, 'basepath' => $basePath, 'extension' => $extension, ]); }
[ "protected", "function", "splitRequestPath", "(", "$", "path", ")", "{", "// Domain part extract", "$", "parts", "=", "explode", "(", "'!'", ",", "$", "path", ")", ";", "if", "(", "count", "(", "$", "parts", ")", ">", "1", ")", "{", "$", "domain", "=", "$", "parts", "[", "0", "]", ";", "$", "path", "=", "$", "parts", "[", "1", "]", ";", "}", "else", "{", "$", "domain", "=", "null", ";", "}", "$", "parts", "=", "parse_url", "(", "$", "path", ")", ";", "$", "basePath", "=", "!", "empty", "(", "$", "parts", "[", "'path'", "]", ")", "?", "$", "parts", "[", "'path'", "]", ":", "'/'", ";", "if", "(", "empty", "(", "$", "basePath", ")", ")", "{", "$", "extension", "=", "null", ";", "}", "else", "{", "$", "extension", "=", "pathinfo", "(", "$", "basePath", ",", "PATHINFO_EXTENSION", ")", ";", "$", "basePath", "=", "preg_replace", "(", "'~\\.'", ".", "$", "extension", ".", "'$~'", ",", "''", ",", "$", "basePath", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "extension", ",", "$", "this", "->", "allowedExtensions", ")", ")", "{", "$", "extension", "=", "''", ";", "}", "return", "new", "Route", "(", "[", "'domain'", "=>", "$", "domain", ",", "'basepath'", "=>", "$", "basePath", ",", "'extension'", "=>", "$", "extension", ",", "]", ")", ";", "}" ]
Splits canonical request path into domain, path and extension @param string $path @return \T4\Mvc\Route
[ "Splits", "canonical", "request", "path", "into", "domain", "path", "and", "extension" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Router.php#L103-L133
27,029
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Core/ResourceTypeConfig.php
CKFinder_Connector_Core_ResourceTypeConfig.checkExtension
public function checkExtension(&$fileName, $renameIfRequired = true) { if (strpos($fileName, '.') === false) { return true; } if (is_null($this->_config)) { $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); } if ($this->_config->getCheckDoubleExtension()) { $pieces = explode('.', $fileName); // First, check the last extension (ex. in file.php.jpg, the "jpg"). if ( !$this->checkSingleExtension( $pieces[sizeof($pieces)-1] ) ) { return false; } if ($renameIfRequired) { // Check the other extensions, rebuilding the file name. If an extension is // not allowed, replace the dot with an underscore. $fileName = $pieces[0] ; for ($i=1; $i<sizeof($pieces)-1; $i++) { $fileName .= $this->checkSingleExtension( $pieces[$i] ) ? '.' : '_' ; $fileName .= $pieces[$i]; } // Add the last extension to the final name. $fileName .= '.' . $pieces[sizeof($pieces)-1] ; } } else { // Check only the last extension (ex. in file.php.jpg, only "jpg"). return $this->checkSingleExtension( substr($fileName, strrpos($fileName,'.')+1) ); } return true; }
php
public function checkExtension(&$fileName, $renameIfRequired = true) { if (strpos($fileName, '.') === false) { return true; } if (is_null($this->_config)) { $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); } if ($this->_config->getCheckDoubleExtension()) { $pieces = explode('.', $fileName); // First, check the last extension (ex. in file.php.jpg, the "jpg"). if ( !$this->checkSingleExtension( $pieces[sizeof($pieces)-1] ) ) { return false; } if ($renameIfRequired) { // Check the other extensions, rebuilding the file name. If an extension is // not allowed, replace the dot with an underscore. $fileName = $pieces[0] ; for ($i=1; $i<sizeof($pieces)-1; $i++) { $fileName .= $this->checkSingleExtension( $pieces[$i] ) ? '.' : '_' ; $fileName .= $pieces[$i]; } // Add the last extension to the final name. $fileName .= '.' . $pieces[sizeof($pieces)-1] ; } } else { // Check only the last extension (ex. in file.php.jpg, only "jpg"). return $this->checkSingleExtension( substr($fileName, strrpos($fileName,'.')+1) ); } return true; }
[ "public", "function", "checkExtension", "(", "&", "$", "fileName", ",", "$", "renameIfRequired", "=", "true", ")", "{", "if", "(", "strpos", "(", "$", "fileName", ",", "'.'", ")", "===", "false", ")", "{", "return", "true", ";", "}", "if", "(", "is_null", "(", "$", "this", "->", "_config", ")", ")", "{", "$", "this", "->", "_config", "=", "&", "CKFinder_Connector_Core_Factory", "::", "getInstance", "(", "\"Core_Config\"", ")", ";", "}", "if", "(", "$", "this", "->", "_config", "->", "getCheckDoubleExtension", "(", ")", ")", "{", "$", "pieces", "=", "explode", "(", "'.'", ",", "$", "fileName", ")", ";", "// First, check the last extension (ex. in file.php.jpg, the \"jpg\").", "if", "(", "!", "$", "this", "->", "checkSingleExtension", "(", "$", "pieces", "[", "sizeof", "(", "$", "pieces", ")", "-", "1", "]", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "renameIfRequired", ")", "{", "// Check the other extensions, rebuilding the file name. If an extension is", "// not allowed, replace the dot with an underscore.", "$", "fileName", "=", "$", "pieces", "[", "0", "]", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "sizeof", "(", "$", "pieces", ")", "-", "1", ";", "$", "i", "++", ")", "{", "$", "fileName", ".=", "$", "this", "->", "checkSingleExtension", "(", "$", "pieces", "[", "$", "i", "]", ")", "?", "'.'", ":", "'_'", ";", "$", "fileName", ".=", "$", "pieces", "[", "$", "i", "]", ";", "}", "// Add the last extension to the final name.", "$", "fileName", ".=", "'.'", ".", "$", "pieces", "[", "sizeof", "(", "$", "pieces", ")", "-", "1", "]", ";", "}", "}", "else", "{", "// Check only the last extension (ex. in file.php.jpg, only \"jpg\").", "return", "$", "this", "->", "checkSingleExtension", "(", "substr", "(", "$", "fileName", ",", "strrpos", "(", "$", "fileName", ",", "'.'", ")", "+", "1", ")", ")", ";", "}", "return", "true", ";", "}" ]
Check extension, return true if file name is valid. Return false if extension is on denied list. If allowed extensions are defined, return false if extension isn't on allowed list. @access public @param string $extension extension @param boolean $renameIfRequired whether try to rename file or not @return boolean
[ "Check", "extension", "return", "true", "if", "file", "name", "is", "valid", ".", "Return", "false", "if", "extension", "is", "on", "denied", "list", ".", "If", "allowed", "extensions", "are", "defined", "return", "false", "if", "extension", "isn", "t", "on", "allowed", "list", "." ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Core/ResourceTypeConfig.php#L228-L265
27,030
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Core/ResourceTypeConfig.php
CKFinder_Connector_Core_ResourceTypeConfig.checkIsHiddenFolder
public function checkIsHiddenFolder($folderName) { if (is_null($this->_config)) { $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); } $regex = $this->_config->getHideFoldersRegex(); if ($regex) { return preg_match($regex, $folderName); } return false; }
php
public function checkIsHiddenFolder($folderName) { if (is_null($this->_config)) { $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); } $regex = $this->_config->getHideFoldersRegex(); if ($regex) { return preg_match($regex, $folderName); } return false; }
[ "public", "function", "checkIsHiddenFolder", "(", "$", "folderName", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_config", ")", ")", "{", "$", "this", "->", "_config", "=", "&", "CKFinder_Connector_Core_Factory", "::", "getInstance", "(", "\"Core_Config\"", ")", ";", "}", "$", "regex", "=", "$", "this", "->", "_config", "->", "getHideFoldersRegex", "(", ")", ";", "if", "(", "$", "regex", ")", "{", "return", "preg_match", "(", "$", "regex", ",", "$", "folderName", ")", ";", "}", "return", "false", ";", "}" ]
Check given folder name Return true if folder name matches hidden folder names list @param string $folderName @access public @return boolean
[ "Check", "given", "folder", "name", "Return", "true", "if", "folder", "name", "matches", "hidden", "folder", "names", "list" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Core/ResourceTypeConfig.php#L275-L287
27,031
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Core/ResourceTypeConfig.php
CKFinder_Connector_Core_ResourceTypeConfig.checkIsHiddenFile
public function checkIsHiddenFile($fileName) { if (is_null($this->_config)) { $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); } $regex = $this->_config->getHideFilesRegex(); if ($regex) { return preg_match($regex, $fileName); } return false; }
php
public function checkIsHiddenFile($fileName) { if (is_null($this->_config)) { $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); } $regex = $this->_config->getHideFilesRegex(); if ($regex) { return preg_match($regex, $fileName); } return false; }
[ "public", "function", "checkIsHiddenFile", "(", "$", "fileName", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_config", ")", ")", "{", "$", "this", "->", "_config", "=", "&", "CKFinder_Connector_Core_Factory", "::", "getInstance", "(", "\"Core_Config\"", ")", ";", "}", "$", "regex", "=", "$", "this", "->", "_config", "->", "getHideFilesRegex", "(", ")", ";", "if", "(", "$", "regex", ")", "{", "return", "preg_match", "(", "$", "regex", ",", "$", "fileName", ")", ";", "}", "return", "false", ";", "}" ]
Check given file name Return true if file name matches hidden file names list @param string $fileName @access public @return boolean
[ "Check", "given", "file", "name", "Return", "true", "if", "file", "name", "matches", "hidden", "file", "names", "list" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Core/ResourceTypeConfig.php#L297-L309
27,032
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Core/ResourceTypeConfig.php
CKFinder_Connector_Core_ResourceTypeConfig.checkIsHiddenPath
public function checkIsHiddenPath($path) { $_clientPathParts = explode("/", trim($path, "/")); if ($_clientPathParts) { foreach ($_clientPathParts as $_part) { if ($this->checkIsHiddenFolder($_part)) { return true; } } } return false; }
php
public function checkIsHiddenPath($path) { $_clientPathParts = explode("/", trim($path, "/")); if ($_clientPathParts) { foreach ($_clientPathParts as $_part) { if ($this->checkIsHiddenFolder($_part)) { return true; } } } return false; }
[ "public", "function", "checkIsHiddenPath", "(", "$", "path", ")", "{", "$", "_clientPathParts", "=", "explode", "(", "\"/\"", ",", "trim", "(", "$", "path", ",", "\"/\"", ")", ")", ";", "if", "(", "$", "_clientPathParts", ")", "{", "foreach", "(", "$", "_clientPathParts", "as", "$", "_part", ")", "{", "if", "(", "$", "this", "->", "checkIsHiddenFolder", "(", "$", "_part", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Check given path Return true if path contains folder name that matches hidden folder names list @param string $folderName @access public @return boolean
[ "Check", "given", "path", "Return", "true", "if", "path", "contains", "folder", "name", "that", "matches", "hidden", "folder", "names", "list" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Core/ResourceTypeConfig.php#L319-L331
27,033
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Core/ResourceTypeConfig.php
CKFinder_Connector_Core_ResourceTypeConfig.checkSingleExtension
public function checkSingleExtension($extension) { $extension = strtolower(ltrim($extension,'.')); if (sizeof($this->_deniedExtensions)) { if (in_array($extension, $this->_deniedExtensions)) { return false; } } if (sizeof($this->_allowedExtensions)) { return in_array($extension, $this->_allowedExtensions); } return true; }
php
public function checkSingleExtension($extension) { $extension = strtolower(ltrim($extension,'.')); if (sizeof($this->_deniedExtensions)) { if (in_array($extension, $this->_deniedExtensions)) { return false; } } if (sizeof($this->_allowedExtensions)) { return in_array($extension, $this->_allowedExtensions); } return true; }
[ "public", "function", "checkSingleExtension", "(", "$", "extension", ")", "{", "$", "extension", "=", "strtolower", "(", "ltrim", "(", "$", "extension", ",", "'.'", ")", ")", ";", "if", "(", "sizeof", "(", "$", "this", "->", "_deniedExtensions", ")", ")", "{", "if", "(", "in_array", "(", "$", "extension", ",", "$", "this", "->", "_deniedExtensions", ")", ")", "{", "return", "false", ";", "}", "}", "if", "(", "sizeof", "(", "$", "this", "->", "_allowedExtensions", ")", ")", "{", "return", "in_array", "(", "$", "extension", ",", "$", "this", "->", "_allowedExtensions", ")", ";", "}", "return", "true", ";", "}" ]
Check if extension is allowed Return true if the extension is allowed. @param string $extension @access public @return boolean
[ "Check", "if", "extension", "is", "allowed", "Return", "true", "if", "the", "extension", "is", "allowed", "." ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Core/ResourceTypeConfig.php#L341-L356
27,034
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Product/Export/Standard.php
Standard.createContainer
protected function createContainer() { $config = $this->getContext()->getConfig(); /** controller/jobs/product/export/location * Directory where the generated site maps should be placed into * * You have to configure a directory for the generated files on your * server that is writeable by the process generating the files, e.g. * * /var/www/your/export/path * * @param string Absolute directory to store the exported files into * @since 2015.01 * @category Developer * @category User * @see controller/jobs/product/export/standard/container/options * @see controller/jobs/product/export/max-items * @see controller/jobs/product/export/max-query */ $location = $config->get( 'controller/jobs/product/export/location' ); /** controller/jobs/product/export/standard/container/type * List of file container options for the export files * * The generated files are stored using container/content objects from * the core. * * @param string Container name * @since 2015.01 * @category Developer * @see controller/jobs/product/export/standard/container/content * @see controller/jobs/product/export/standard/container/options * @see controller/jobs/product/export/location * @see controller/jobs/product/export/max-items * @see controller/jobs/product/export/max-query */ $container = $config->get( 'controller/jobs/product/export/standard/container/type', 'Directory' ); /** controller/jobs/product/export/standard/container/content * List of file container options for the export files * * The generated files are stored using container/content objects from * the core. * * @param array Associative list of option name/value pairs * @since 2015.01 * @category Developer * @see controller/jobs/product/export/standard/container/type * @see controller/jobs/product/export/standard/container/options * @see controller/jobs/product/export/location * @see controller/jobs/product/export/max-items * @see controller/jobs/product/export/max-query */ $content = $config->get( 'controller/jobs/product/export/standard/container/content', 'Binary' ); /** controller/jobs/product/export/standard/container/options * List of file container options for the export files * * The generated files are stored using container/content objects from * the core. * * @param array Associative list of option name/value pairs * @since 2015.01 * @category Developer * @see controller/jobs/product/export/standard/container/type * @see controller/jobs/product/export/standard/container/content * @see controller/jobs/product/export/location * @see controller/jobs/product/export/max-items * @see controller/jobs/product/export/max-query */ $options = $config->get( 'controller/jobs/product/export/standard/container/options', [] ); if( $location === null ) { $msg = sprintf( 'Required configuration for "%1$s" is missing', 'controller/jobs/product/export/location' ); throw new \Aimeos\Controller\Jobs\Exception( $msg ); } return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); }
php
protected function createContainer() { $config = $this->getContext()->getConfig(); /** controller/jobs/product/export/location * Directory where the generated site maps should be placed into * * You have to configure a directory for the generated files on your * server that is writeable by the process generating the files, e.g. * * /var/www/your/export/path * * @param string Absolute directory to store the exported files into * @since 2015.01 * @category Developer * @category User * @see controller/jobs/product/export/standard/container/options * @see controller/jobs/product/export/max-items * @see controller/jobs/product/export/max-query */ $location = $config->get( 'controller/jobs/product/export/location' ); /** controller/jobs/product/export/standard/container/type * List of file container options for the export files * * The generated files are stored using container/content objects from * the core. * * @param string Container name * @since 2015.01 * @category Developer * @see controller/jobs/product/export/standard/container/content * @see controller/jobs/product/export/standard/container/options * @see controller/jobs/product/export/location * @see controller/jobs/product/export/max-items * @see controller/jobs/product/export/max-query */ $container = $config->get( 'controller/jobs/product/export/standard/container/type', 'Directory' ); /** controller/jobs/product/export/standard/container/content * List of file container options for the export files * * The generated files are stored using container/content objects from * the core. * * @param array Associative list of option name/value pairs * @since 2015.01 * @category Developer * @see controller/jobs/product/export/standard/container/type * @see controller/jobs/product/export/standard/container/options * @see controller/jobs/product/export/location * @see controller/jobs/product/export/max-items * @see controller/jobs/product/export/max-query */ $content = $config->get( 'controller/jobs/product/export/standard/container/content', 'Binary' ); /** controller/jobs/product/export/standard/container/options * List of file container options for the export files * * The generated files are stored using container/content objects from * the core. * * @param array Associative list of option name/value pairs * @since 2015.01 * @category Developer * @see controller/jobs/product/export/standard/container/type * @see controller/jobs/product/export/standard/container/content * @see controller/jobs/product/export/location * @see controller/jobs/product/export/max-items * @see controller/jobs/product/export/max-query */ $options = $config->get( 'controller/jobs/product/export/standard/container/options', [] ); if( $location === null ) { $msg = sprintf( 'Required configuration for "%1$s" is missing', 'controller/jobs/product/export/location' ); throw new \Aimeos\Controller\Jobs\Exception( $msg ); } return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); }
[ "protected", "function", "createContainer", "(", ")", "{", "$", "config", "=", "$", "this", "->", "getContext", "(", ")", "->", "getConfig", "(", ")", ";", "/** controller/jobs/product/export/location\n\t\t * Directory where the generated site maps should be placed into\n\t\t *\n\t\t * You have to configure a directory for the generated files on your\n\t\t * server that is writeable by the process generating the files, e.g.\n\t\t *\n\t\t * /var/www/your/export/path\n\t\t *\n\t\t * @param string Absolute directory to store the exported files into\n\t\t * @since 2015.01\n\t\t * @category Developer\n\t\t * @category User\n\t\t * @see controller/jobs/product/export/standard/container/options\n\t\t * @see controller/jobs/product/export/max-items\n\t\t * @see controller/jobs/product/export/max-query\n\t\t */", "$", "location", "=", "$", "config", "->", "get", "(", "'controller/jobs/product/export/location'", ")", ";", "/** controller/jobs/product/export/standard/container/type\n\t\t * List of file container options for the export files\n\t\t *\n\t\t * The generated files are stored using container/content objects from\n\t\t * the core.\n\t\t *\n\t\t * @param string Container name\n\t\t * @since 2015.01\n\t\t * @category Developer\n\t\t * @see controller/jobs/product/export/standard/container/content\n\t\t * @see controller/jobs/product/export/standard/container/options\n\t\t * @see controller/jobs/product/export/location\n\t\t * @see controller/jobs/product/export/max-items\n\t\t * @see controller/jobs/product/export/max-query\n\t\t */", "$", "container", "=", "$", "config", "->", "get", "(", "'controller/jobs/product/export/standard/container/type'", ",", "'Directory'", ")", ";", "/** controller/jobs/product/export/standard/container/content\n\t\t * List of file container options for the export files\n\t\t *\n\t\t * The generated files are stored using container/content objects from\n\t\t * the core.\n\t\t *\n\t\t * @param array Associative list of option name/value pairs\n\t\t * @since 2015.01\n\t\t * @category Developer\n\t\t * @see controller/jobs/product/export/standard/container/type\n\t\t * @see controller/jobs/product/export/standard/container/options\n\t\t * @see controller/jobs/product/export/location\n\t\t * @see controller/jobs/product/export/max-items\n\t\t * @see controller/jobs/product/export/max-query\n\t\t */", "$", "content", "=", "$", "config", "->", "get", "(", "'controller/jobs/product/export/standard/container/content'", ",", "'Binary'", ")", ";", "/** controller/jobs/product/export/standard/container/options\n\t\t * List of file container options for the export files\n\t\t *\n\t\t * The generated files are stored using container/content objects from\n\t\t * the core.\n\t\t *\n\t\t * @param array Associative list of option name/value pairs\n\t\t * @since 2015.01\n\t\t * @category Developer\n\t\t * @see controller/jobs/product/export/standard/container/type\n\t\t * @see controller/jobs/product/export/standard/container/content\n\t\t * @see controller/jobs/product/export/location\n\t\t * @see controller/jobs/product/export/max-items\n\t\t * @see controller/jobs/product/export/max-query\n\t\t */", "$", "options", "=", "$", "config", "->", "get", "(", "'controller/jobs/product/export/standard/container/options'", ",", "[", "]", ")", ";", "if", "(", "$", "location", "===", "null", ")", "{", "$", "msg", "=", "sprintf", "(", "'Required configuration for \"%1$s\" is missing'", ",", "'controller/jobs/product/export/location'", ")", ";", "throw", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Jobs", "\\", "Exception", "(", "$", "msg", ")", ";", "}", "return", "\\", "Aimeos", "\\", "MW", "\\", "Container", "\\", "Factory", "::", "getContainer", "(", "$", "location", ",", "$", "container", ",", "$", "content", ",", "$", "options", ")", ";", "}" ]
Creates a new container for the site map file @return \Aimeos\MW\Container\Iface Container object
[ "Creates", "a", "new", "container", "for", "the", "site", "map", "file" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Product/Export/Standard.php#L106-L186
27,035
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Product/Export/Standard.php
Standard.export
protected function export( \Aimeos\MW\Container\Iface $container, $default = true ) { $domains = array( 'attribute', 'media', 'price', 'product', 'text' ); $domains = $this->getConfig( 'domains', $domains ); $maxItems = $this->getConfig( 'max-items', 10000 ); $maxQuery = $this->getConfig( 'max-query', 1000 ); $start = 0; $filenum = 1; $names = []; $manager = \Aimeos\MShop::create( $this->getContext(), 'product' ); $search = $manager->createSearch( $default ); $search->setSortations( array( $search->sort( '+', 'product.id' ) ) ); $search->setSlice( 0, $maxQuery ); $content = $this->createContent( $container, $filenum ); $names[] = $content->getResource(); do { $items = $manager->searchItems( $search, $domains ); $free = $maxItems * $filenum - $start; $count = count( $items ); if( $free < $count ) { $this->addItems( $content, array_slice( $items, 0, $free, true ) ); $items = array_slice( $items, $free, null, true ); $this->closeContent( $content ); $content = $this->createContent( $container, ++$filenum ); $names[] = $content->getResource(); } $this->addItems( $content, $items ); $start += $count; $search->setSlice( $start, $maxQuery ); } while( $count >= $search->getSliceSize() ); $this->closeContent( $content ); return $names; }
php
protected function export( \Aimeos\MW\Container\Iface $container, $default = true ) { $domains = array( 'attribute', 'media', 'price', 'product', 'text' ); $domains = $this->getConfig( 'domains', $domains ); $maxItems = $this->getConfig( 'max-items', 10000 ); $maxQuery = $this->getConfig( 'max-query', 1000 ); $start = 0; $filenum = 1; $names = []; $manager = \Aimeos\MShop::create( $this->getContext(), 'product' ); $search = $manager->createSearch( $default ); $search->setSortations( array( $search->sort( '+', 'product.id' ) ) ); $search->setSlice( 0, $maxQuery ); $content = $this->createContent( $container, $filenum ); $names[] = $content->getResource(); do { $items = $manager->searchItems( $search, $domains ); $free = $maxItems * $filenum - $start; $count = count( $items ); if( $free < $count ) { $this->addItems( $content, array_slice( $items, 0, $free, true ) ); $items = array_slice( $items, $free, null, true ); $this->closeContent( $content ); $content = $this->createContent( $container, ++$filenum ); $names[] = $content->getResource(); } $this->addItems( $content, $items ); $start += $count; $search->setSlice( $start, $maxQuery ); } while( $count >= $search->getSliceSize() ); $this->closeContent( $content ); return $names; }
[ "protected", "function", "export", "(", "\\", "Aimeos", "\\", "MW", "\\", "Container", "\\", "Iface", "$", "container", ",", "$", "default", "=", "true", ")", "{", "$", "domains", "=", "array", "(", "'attribute'", ",", "'media'", ",", "'price'", ",", "'product'", ",", "'text'", ")", ";", "$", "domains", "=", "$", "this", "->", "getConfig", "(", "'domains'", ",", "$", "domains", ")", ";", "$", "maxItems", "=", "$", "this", "->", "getConfig", "(", "'max-items'", ",", "10000", ")", ";", "$", "maxQuery", "=", "$", "this", "->", "getConfig", "(", "'max-query'", ",", "1000", ")", ";", "$", "start", "=", "0", ";", "$", "filenum", "=", "1", ";", "$", "names", "=", "[", "]", ";", "$", "manager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "this", "->", "getContext", "(", ")", ",", "'product'", ")", ";", "$", "search", "=", "$", "manager", "->", "createSearch", "(", "$", "default", ")", ";", "$", "search", "->", "setSortations", "(", "array", "(", "$", "search", "->", "sort", "(", "'+'", ",", "'product.id'", ")", ")", ")", ";", "$", "search", "->", "setSlice", "(", "0", ",", "$", "maxQuery", ")", ";", "$", "content", "=", "$", "this", "->", "createContent", "(", "$", "container", ",", "$", "filenum", ")", ";", "$", "names", "[", "]", "=", "$", "content", "->", "getResource", "(", ")", ";", "do", "{", "$", "items", "=", "$", "manager", "->", "searchItems", "(", "$", "search", ",", "$", "domains", ")", ";", "$", "free", "=", "$", "maxItems", "*", "$", "filenum", "-", "$", "start", ";", "$", "count", "=", "count", "(", "$", "items", ")", ";", "if", "(", "$", "free", "<", "$", "count", ")", "{", "$", "this", "->", "addItems", "(", "$", "content", ",", "array_slice", "(", "$", "items", ",", "0", ",", "$", "free", ",", "true", ")", ")", ";", "$", "items", "=", "array_slice", "(", "$", "items", ",", "$", "free", ",", "null", ",", "true", ")", ";", "$", "this", "->", "closeContent", "(", "$", "content", ")", ";", "$", "content", "=", "$", "this", "->", "createContent", "(", "$", "container", ",", "++", "$", "filenum", ")", ";", "$", "names", "[", "]", "=", "$", "content", "->", "getResource", "(", ")", ";", "}", "$", "this", "->", "addItems", "(", "$", "content", ",", "$", "items", ")", ";", "$", "start", "+=", "$", "count", ";", "$", "search", "->", "setSlice", "(", "$", "start", ",", "$", "maxQuery", ")", ";", "}", "while", "(", "$", "count", ">=", "$", "search", "->", "getSliceSize", "(", ")", ")", ";", "$", "this", "->", "closeContent", "(", "$", "content", ")", ";", "return", "$", "names", ";", "}" ]
Exports the products into the given container @param \Aimeos\MW\Container\Iface $container Container object @param boolean $default True to filter exported products by default criteria @return array List of content (file) names
[ "Exports", "the", "products", "into", "the", "given", "container" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Product/Export/Standard.php#L280-L326
27,036
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.getFileNameWithoutExtension
public static function getFileNameWithoutExtension($fileName, $shortExtensionMode = TRUE) { $dotPos = $shortExtensionMode ? strrpos( $fileName, '.' ) : strpos( $fileName, '.' ); if (false === $dotPos) { return $fileName; } return substr($fileName, 0, $dotPos); }
php
public static function getFileNameWithoutExtension($fileName, $shortExtensionMode = TRUE) { $dotPos = $shortExtensionMode ? strrpos( $fileName, '.' ) : strpos( $fileName, '.' ); if (false === $dotPos) { return $fileName; } return substr($fileName, 0, $dotPos); }
[ "public", "static", "function", "getFileNameWithoutExtension", "(", "$", "fileName", ",", "$", "shortExtensionMode", "=", "TRUE", ")", "{", "$", "dotPos", "=", "$", "shortExtensionMode", "?", "strrpos", "(", "$", "fileName", ",", "'.'", ")", ":", "strpos", "(", "$", "fileName", ",", "'.'", ")", ";", "if", "(", "false", "===", "$", "dotPos", ")", "{", "return", "$", "fileName", ";", "}", "return", "substr", "(", "$", "fileName", ",", "0", ",", "$", "dotPos", ")", ";", "}" ]
Return file name without extension @static @access public @param string $fileName @param boolean $shortExtensionMode If set to false, extension is everything after a first dot @return string
[ "Return", "file", "name", "without", "extension" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L199-L207
27,037
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.readfileChunked
public static function readfileChunked($filename) { $chunksize = 1024 * 10; // how many bytes per chunk $handle = fopen($filename, 'rb'); if ($handle === false) { return false; } while (!feof($handle)) { echo fread($handle, $chunksize); @ob_flush(); flush(); @set_time_limit(8); } fclose($handle); return true; }
php
public static function readfileChunked($filename) { $chunksize = 1024 * 10; // how many bytes per chunk $handle = fopen($filename, 'rb'); if ($handle === false) { return false; } while (!feof($handle)) { echo fread($handle, $chunksize); @ob_flush(); flush(); @set_time_limit(8); } fclose($handle); return true; }
[ "public", "static", "function", "readfileChunked", "(", "$", "filename", ")", "{", "$", "chunksize", "=", "1024", "*", "10", ";", "// how many bytes per chunk", "$", "handle", "=", "fopen", "(", "$", "filename", ",", "'rb'", ")", ";", "if", "(", "$", "handle", "===", "false", ")", "{", "return", "false", ";", "}", "while", "(", "!", "feof", "(", "$", "handle", ")", ")", "{", "echo", "fread", "(", "$", "handle", ",", "$", "chunksize", ")", ";", "@", "ob_flush", "(", ")", ";", "flush", "(", ")", ";", "@", "set_time_limit", "(", "8", ")", ";", "}", "fclose", "(", "$", "handle", ")", ";", "return", "true", ";", "}" ]
Read file, split it into small chunks and send it to the browser @static @access public @param string $filename @return boolean
[ "Read", "file", "split", "it", "into", "small", "chunks", "and", "send", "it", "to", "the", "browser" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L236-L252
27,038
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.secureFileName
public static function secureFileName($fileName) { $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $fileName = str_replace(array(":", "*", "?", "|", "/"), "_", $fileName); if ( $_config->getDisallowUnsafeCharacters() ) { $fileName = str_replace(";", "_", $fileName); } if ($_config->forceAscii()) { $fileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($fileName); } return $fileName; }
php
public static function secureFileName($fileName) { $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $fileName = str_replace(array(":", "*", "?", "|", "/"), "_", $fileName); if ( $_config->getDisallowUnsafeCharacters() ) { $fileName = str_replace(";", "_", $fileName); } if ($_config->forceAscii()) { $fileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($fileName); } return $fileName; }
[ "public", "static", "function", "secureFileName", "(", "$", "fileName", ")", "{", "$", "_config", "=", "&", "CKFinder_Connector_Core_Factory", "::", "getInstance", "(", "\"Core_Config\"", ")", ";", "$", "fileName", "=", "str_replace", "(", "array", "(", "\":\"", ",", "\"*\"", ",", "\"?\"", ",", "\"|\"", ",", "\"/\"", ")", ",", "\"_\"", ",", "$", "fileName", ")", ";", "if", "(", "$", "_config", "->", "getDisallowUnsafeCharacters", "(", ")", ")", "{", "$", "fileName", "=", "str_replace", "(", "\";\"", ",", "\"_\"", ",", "$", "fileName", ")", ";", "}", "if", "(", "$", "_config", "->", "forceAscii", "(", ")", ")", "{", "$", "fileName", "=", "CKFinder_Connector_Utils_FileSystem", "::", "convertToAscii", "(", "$", "fileName", ")", ";", "}", "return", "$", "fileName", ";", "}" ]
Secure file name from unsafe characters @param string $fileName @access public @static @return string $fileName
[ "Secure", "file", "name", "from", "unsafe", "characters" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L338-L351
27,039
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.convertToFilesystemEncoding
public static function convertToFilesystemEncoding($fileName) { $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $encoding = $_config->getFilesystemEncoding(); if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) { return $fileName; } if (!function_exists("iconv")) { if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) { return str_replace("\0", "_", utf8_decode($fileName)); } else if (function_exists('mb_convert_encoding')) { /** * @todo check whether charset is supported - mb_list_encodings */ $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8'); if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) { return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); } else { return str_replace("\0", "_", $encoded); } } else { return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); } } $converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName); if ($converted === false) { return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); } return $converted; }
php
public static function convertToFilesystemEncoding($fileName) { $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $encoding = $_config->getFilesystemEncoding(); if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) { return $fileName; } if (!function_exists("iconv")) { if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) { return str_replace("\0", "_", utf8_decode($fileName)); } else if (function_exists('mb_convert_encoding')) { /** * @todo check whether charset is supported - mb_list_encodings */ $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8'); if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) { return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); } else { return str_replace("\0", "_", $encoded); } } else { return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); } } $converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName); if ($converted === false) { return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName)); } return $converted; }
[ "public", "static", "function", "convertToFilesystemEncoding", "(", "$", "fileName", ")", "{", "$", "_config", "=", "&", "CKFinder_Connector_Core_Factory", "::", "getInstance", "(", "\"Core_Config\"", ")", ";", "$", "encoding", "=", "$", "_config", "->", "getFilesystemEncoding", "(", ")", ";", "if", "(", "is_null", "(", "$", "encoding", ")", "||", "strcasecmp", "(", "$", "encoding", ",", "\"UTF-8\"", ")", "==", "0", "||", "strcasecmp", "(", "$", "encoding", ",", "\"UTF8\"", ")", "==", "0", ")", "{", "return", "$", "fileName", ";", "}", "if", "(", "!", "function_exists", "(", "\"iconv\"", ")", ")", "{", "if", "(", "strcasecmp", "(", "$", "encoding", ",", "\"ISO-8859-1\"", ")", "==", "0", "||", "strcasecmp", "(", "$", "encoding", ",", "\"ISO8859-1\"", ")", "==", "0", "||", "strcasecmp", "(", "$", "encoding", ",", "\"Latin1\"", ")", "==", "0", ")", "{", "return", "str_replace", "(", "\"\\0\"", ",", "\"_\"", ",", "utf8_decode", "(", "$", "fileName", ")", ")", ";", "}", "else", "if", "(", "function_exists", "(", "'mb_convert_encoding'", ")", ")", "{", "/**\n * @todo check whether charset is supported - mb_list_encodings\n */", "$", "encoded", "=", "@", "mb_convert_encoding", "(", "$", "fileName", ",", "$", "encoding", ",", "'UTF-8'", ")", ";", "if", "(", "@", "mb_strlen", "(", "$", "fileName", ",", "\"UTF-8\"", ")", "!=", "@", "mb_strlen", "(", "$", "encoded", ",", "$", "encoding", ")", ")", "{", "return", "str_replace", "(", "\"\\0\"", ",", "\"_\"", ",", "preg_replace", "(", "\"/[^[:ascii:]]/u\"", ",", "\"_\"", ",", "$", "fileName", ")", ")", ";", "}", "else", "{", "return", "str_replace", "(", "\"\\0\"", ",", "\"_\"", ",", "$", "encoded", ")", ";", "}", "}", "else", "{", "return", "str_replace", "(", "\"\\0\"", ",", "\"_\"", ",", "preg_replace", "(", "\"/[^[:ascii:]]/u\"", ",", "\"_\"", ",", "$", "fileName", ")", ")", ";", "}", "}", "$", "converted", "=", "@", "iconv", "(", "\"UTF-8\"", ",", "$", "encoding", ".", "\"//IGNORE//TRANSLIT\"", ",", "$", "fileName", ")", ";", "if", "(", "$", "converted", "===", "false", ")", "{", "return", "str_replace", "(", "\"\\0\"", ",", "\"_\"", ",", "preg_replace", "(", "\"/[^[:ascii:]]/u\"", ",", "\"_\"", ",", "$", "fileName", ")", ")", ";", "}", "return", "$", "converted", ";", "}" ]
Convert file name from UTF-8 to system encoding @static @access public @param string $fileName @return string
[ "Convert", "file", "name", "from", "UTF", "-", "8", "to", "system", "encoding" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L361-L394
27,040
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.convertToConnectorEncoding
public static function convertToConnectorEncoding($fileName) { $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $encoding = $_config->getFilesystemEncoding(); if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) { return $fileName; } if (!function_exists("iconv")) { if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) { return utf8_encode($fileName); } else { return $fileName; } } $converted = @iconv($encoding, "UTF-8", $fileName); if ($converted === false) { return $fileName; } return $converted; }
php
public static function convertToConnectorEncoding($fileName) { $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $encoding = $_config->getFilesystemEncoding(); if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) { return $fileName; } if (!function_exists("iconv")) { if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) { return utf8_encode($fileName); } else { return $fileName; } } $converted = @iconv($encoding, "UTF-8", $fileName); if ($converted === false) { return $fileName; } return $converted; }
[ "public", "static", "function", "convertToConnectorEncoding", "(", "$", "fileName", ")", "{", "$", "_config", "=", "&", "CKFinder_Connector_Core_Factory", "::", "getInstance", "(", "\"Core_Config\"", ")", ";", "$", "encoding", "=", "$", "_config", "->", "getFilesystemEncoding", "(", ")", ";", "if", "(", "is_null", "(", "$", "encoding", ")", "||", "strcasecmp", "(", "$", "encoding", ",", "\"UTF-8\"", ")", "==", "0", "||", "strcasecmp", "(", "$", "encoding", ",", "\"UTF8\"", ")", "==", "0", ")", "{", "return", "$", "fileName", ";", "}", "if", "(", "!", "function_exists", "(", "\"iconv\"", ")", ")", "{", "if", "(", "strcasecmp", "(", "$", "encoding", ",", "\"ISO-8859-1\"", ")", "==", "0", "||", "strcasecmp", "(", "$", "encoding", ",", "\"ISO8859-1\"", ")", "==", "0", "||", "strcasecmp", "(", "$", "encoding", ",", "\"Latin1\"", ")", "==", "0", ")", "{", "return", "utf8_encode", "(", "$", "fileName", ")", ";", "}", "else", "{", "return", "$", "fileName", ";", "}", "}", "$", "converted", "=", "@", "iconv", "(", "$", "encoding", ",", "\"UTF-8\"", ",", "$", "fileName", ")", ";", "if", "(", "$", "converted", "===", "false", ")", "{", "return", "$", "fileName", ";", "}", "return", "$", "converted", ";", "}" ]
Convert file name from system encoding into UTF-8 @static @access public @param string $fileName @return string
[ "Convert", "file", "name", "from", "system", "encoding", "into", "UTF", "-", "8" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L404-L427
27,041
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.getDocumentRootPath
public function getDocumentRootPath() { /** * The absolute pathname of the currently executing script. * Notatka: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php, * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user. */ if (isset($_SERVER['SCRIPT_FILENAME'])) { $sRealPath = dirname($_SERVER['SCRIPT_FILENAME']); } else { /** * realpath — Returns canonicalized absolute pathname */ $sRealPath = realpath('.') ; } $sRealPath = $this->trimPathTrailingSlashes($sRealPath); /** * The filename of the currently executing script, relative to the document root. * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar * would be /test.php/foo.bar. */ $sSelfPath = dirname($_SERVER['PHP_SELF']); $sSelfPath = $this->trimPathTrailingSlashes($sSelfPath); return $this->trimPathTrailingSlashes(substr($sRealPath, 0, strlen($sRealPath) - strlen($sSelfPath))); }
php
public function getDocumentRootPath() { /** * The absolute pathname of the currently executing script. * Notatka: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php, * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user. */ if (isset($_SERVER['SCRIPT_FILENAME'])) { $sRealPath = dirname($_SERVER['SCRIPT_FILENAME']); } else { /** * realpath — Returns canonicalized absolute pathname */ $sRealPath = realpath('.') ; } $sRealPath = $this->trimPathTrailingSlashes($sRealPath); /** * The filename of the currently executing script, relative to the document root. * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar * would be /test.php/foo.bar. */ $sSelfPath = dirname($_SERVER['PHP_SELF']); $sSelfPath = $this->trimPathTrailingSlashes($sSelfPath); return $this->trimPathTrailingSlashes(substr($sRealPath, 0, strlen($sRealPath) - strlen($sSelfPath))); }
[ "public", "function", "getDocumentRootPath", "(", ")", "{", "/**\n * The absolute pathname of the currently executing script.\n * Notatka: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php,\n * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.\n */", "if", "(", "isset", "(", "$", "_SERVER", "[", "'SCRIPT_FILENAME'", "]", ")", ")", "{", "$", "sRealPath", "=", "dirname", "(", "$", "_SERVER", "[", "'SCRIPT_FILENAME'", "]", ")", ";", "}", "else", "{", "/**\n * realpath — Returns canonicalized absolute pathname\n */", "$", "sRealPath", "=", "realpath", "(", "'.'", ")", ";", "}", "$", "sRealPath", "=", "$", "this", "->", "trimPathTrailingSlashes", "(", "$", "sRealPath", ")", ";", "/**\n * The filename of the currently executing script, relative to the document root.\n * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar\n * would be /test.php/foo.bar.\n */", "$", "sSelfPath", "=", "dirname", "(", "$", "_SERVER", "[", "'PHP_SELF'", "]", ")", ";", "$", "sSelfPath", "=", "$", "this", "->", "trimPathTrailingSlashes", "(", "$", "sSelfPath", ")", ";", "return", "$", "this", "->", "trimPathTrailingSlashes", "(", "substr", "(", "$", "sRealPath", ",", "0", ",", "strlen", "(", "$", "sRealPath", ")", "-", "strlen", "(", "$", "sSelfPath", ")", ")", ")", ";", "}" ]
Find document root @return string @access public
[ "Find", "document", "root" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L435-L463
27,042
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.createDirectoryRecursively
public static function createDirectoryRecursively($dir) { if (DIRECTORY_SEPARATOR === "\\") { $dir = str_replace("/", "\\", $dir); } else if (DIRECTORY_SEPARATOR === "/") { $dir = str_replace("\\", "/", $dir); } $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); if ($perms = $_config->getChmodFolders()) { $oldUmask = umask(0); $bCreated = @mkdir($dir, $perms, true); umask($oldUmask); } else { $bCreated = @mkdir($dir, 0777, true); } return $bCreated; }
php
public static function createDirectoryRecursively($dir) { if (DIRECTORY_SEPARATOR === "\\") { $dir = str_replace("/", "\\", $dir); } else if (DIRECTORY_SEPARATOR === "/") { $dir = str_replace("\\", "/", $dir); } $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); if ($perms = $_config->getChmodFolders()) { $oldUmask = umask(0); $bCreated = @mkdir($dir, $perms, true); umask($oldUmask); } else { $bCreated = @mkdir($dir, 0777, true); } return $bCreated; }
[ "public", "static", "function", "createDirectoryRecursively", "(", "$", "dir", ")", "{", "if", "(", "DIRECTORY_SEPARATOR", "===", "\"\\\\\"", ")", "{", "$", "dir", "=", "str_replace", "(", "\"/\"", ",", "\"\\\\\"", ",", "$", "dir", ")", ";", "}", "else", "if", "(", "DIRECTORY_SEPARATOR", "===", "\"/\"", ")", "{", "$", "dir", "=", "str_replace", "(", "\"\\\\\"", ",", "\"/\"", ",", "$", "dir", ")", ";", "}", "$", "_config", "=", "&", "CKFinder_Connector_Core_Factory", "::", "getInstance", "(", "\"Core_Config\"", ")", ";", "if", "(", "$", "perms", "=", "$", "_config", "->", "getChmodFolders", "(", ")", ")", "{", "$", "oldUmask", "=", "umask", "(", "0", ")", ";", "$", "bCreated", "=", "@", "mkdir", "(", "$", "dir", ",", "$", "perms", ",", "true", ")", ";", "umask", "(", "$", "oldUmask", ")", ";", "}", "else", "{", "$", "bCreated", "=", "@", "mkdir", "(", "$", "dir", ",", "0777", ",", "true", ")", ";", "}", "return", "$", "bCreated", ";", "}" ]
Create directory recursively @access public @static @param string $dir @return boolean
[ "Create", "directory", "recursively" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L473-L493
27,043
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.isImageValid
public static function isImageValid($filePath, $extension) { if (!@is_readable($filePath)) { return -1; } $imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'psd', 'bmp', 'tiff'); // version_compare is available since PHP4 >= 4.0.7 if ( function_exists( 'version_compare' ) ) { $sCurrentVersion = phpversion(); if ( version_compare( $sCurrentVersion, "4.2.0" ) >= 0 ) { $imageCheckExtensions[] = "tiff"; $imageCheckExtensions[] = "tif"; } if ( version_compare( $sCurrentVersion, "4.3.0" ) >= 0 ) { $imageCheckExtensions[] = "swc"; } if ( version_compare( $sCurrentVersion, "4.3.2" ) >= 0 ) { $imageCheckExtensions[] = "jpc"; $imageCheckExtensions[] = "jp2"; $imageCheckExtensions[] = "jpx"; $imageCheckExtensions[] = "jb2"; $imageCheckExtensions[] = "xbm"; $imageCheckExtensions[] = "wbmp"; } } if ( !in_array( $extension, $imageCheckExtensions ) ) { return true; } if ( @getimagesize( $filePath ) === false ) { return false ; } return true; }
php
public static function isImageValid($filePath, $extension) { if (!@is_readable($filePath)) { return -1; } $imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'psd', 'bmp', 'tiff'); // version_compare is available since PHP4 >= 4.0.7 if ( function_exists( 'version_compare' ) ) { $sCurrentVersion = phpversion(); if ( version_compare( $sCurrentVersion, "4.2.0" ) >= 0 ) { $imageCheckExtensions[] = "tiff"; $imageCheckExtensions[] = "tif"; } if ( version_compare( $sCurrentVersion, "4.3.0" ) >= 0 ) { $imageCheckExtensions[] = "swc"; } if ( version_compare( $sCurrentVersion, "4.3.2" ) >= 0 ) { $imageCheckExtensions[] = "jpc"; $imageCheckExtensions[] = "jp2"; $imageCheckExtensions[] = "jpx"; $imageCheckExtensions[] = "jb2"; $imageCheckExtensions[] = "xbm"; $imageCheckExtensions[] = "wbmp"; } } if ( !in_array( $extension, $imageCheckExtensions ) ) { return true; } if ( @getimagesize( $filePath ) === false ) { return false ; } return true; }
[ "public", "static", "function", "isImageValid", "(", "$", "filePath", ",", "$", "extension", ")", "{", "if", "(", "!", "@", "is_readable", "(", "$", "filePath", ")", ")", "{", "return", "-", "1", ";", "}", "$", "imageCheckExtensions", "=", "array", "(", "'gif'", ",", "'jpeg'", ",", "'jpg'", ",", "'png'", ",", "'psd'", ",", "'bmp'", ",", "'tiff'", ")", ";", "// version_compare is available since PHP4 >= 4.0.7", "if", "(", "function_exists", "(", "'version_compare'", ")", ")", "{", "$", "sCurrentVersion", "=", "phpversion", "(", ")", ";", "if", "(", "version_compare", "(", "$", "sCurrentVersion", ",", "\"4.2.0\"", ")", ">=", "0", ")", "{", "$", "imageCheckExtensions", "[", "]", "=", "\"tiff\"", ";", "$", "imageCheckExtensions", "[", "]", "=", "\"tif\"", ";", "}", "if", "(", "version_compare", "(", "$", "sCurrentVersion", ",", "\"4.3.0\"", ")", ">=", "0", ")", "{", "$", "imageCheckExtensions", "[", "]", "=", "\"swc\"", ";", "}", "if", "(", "version_compare", "(", "$", "sCurrentVersion", ",", "\"4.3.2\"", ")", ">=", "0", ")", "{", "$", "imageCheckExtensions", "[", "]", "=", "\"jpc\"", ";", "$", "imageCheckExtensions", "[", "]", "=", "\"jp2\"", ";", "$", "imageCheckExtensions", "[", "]", "=", "\"jpx\"", ";", "$", "imageCheckExtensions", "[", "]", "=", "\"jb2\"", ";", "$", "imageCheckExtensions", "[", "]", "=", "\"xbm\"", ";", "$", "imageCheckExtensions", "[", "]", "=", "\"wbmp\"", ";", "}", "}", "if", "(", "!", "in_array", "(", "$", "extension", ",", "$", "imageCheckExtensions", ")", ")", "{", "return", "true", ";", "}", "if", "(", "@", "getimagesize", "(", "$", "filePath", ")", "===", "false", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Check file content. Currently this function validates only image files. Returns false if file is invalid. @static @access public @param string $filePath absolute path to file @param string $extension file extension @param integer $detectionLevel 0 = none, 1 = use getimagesize for images, 2 = use DetectHtml for images @return boolean
[ "Check", "file", "content", ".", "Currently", "this", "function", "validates", "only", "image", "files", ".", "Returns", "false", "if", "file", "is", "invalid", "." ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L567-L604
27,044
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.hasChildren
public static function hasChildren($clientPath, $_resourceType) { $serverPath = CKFinder_Connector_Utils_FileSystem::combinePaths($_resourceType->getDirectory(), $clientPath); if (!is_dir($serverPath) || (false === $fh = @opendir($serverPath))) { return false; } $hasChildren = false; while (false !== ($filename = readdir($fh))) { if ($filename == '.' || $filename == '..') { continue; } else if (is_dir($serverPath . $filename)) { //we have found valid directory $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $_acl = $_config->getAccessControlConfig(); $_aclMask = $_acl->getComputedMask($_resourceType->getName(), $clientPath . $filename); if ( ($_aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) != CKFINDER_CONNECTOR_ACL_FOLDER_VIEW ) { continue; } if ($_resourceType->checkIsHiddenFolder($filename)) { continue; } $hasChildren = true; break; } } closedir($fh); return $hasChildren; }
php
public static function hasChildren($clientPath, $_resourceType) { $serverPath = CKFinder_Connector_Utils_FileSystem::combinePaths($_resourceType->getDirectory(), $clientPath); if (!is_dir($serverPath) || (false === $fh = @opendir($serverPath))) { return false; } $hasChildren = false; while (false !== ($filename = readdir($fh))) { if ($filename == '.' || $filename == '..') { continue; } else if (is_dir($serverPath . $filename)) { //we have found valid directory $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $_acl = $_config->getAccessControlConfig(); $_aclMask = $_acl->getComputedMask($_resourceType->getName(), $clientPath . $filename); if ( ($_aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) != CKFINDER_CONNECTOR_ACL_FOLDER_VIEW ) { continue; } if ($_resourceType->checkIsHiddenFolder($filename)) { continue; } $hasChildren = true; break; } } closedir($fh); return $hasChildren; }
[ "public", "static", "function", "hasChildren", "(", "$", "clientPath", ",", "$", "_resourceType", ")", "{", "$", "serverPath", "=", "CKFinder_Connector_Utils_FileSystem", "::", "combinePaths", "(", "$", "_resourceType", "->", "getDirectory", "(", ")", ",", "$", "clientPath", ")", ";", "if", "(", "!", "is_dir", "(", "$", "serverPath", ")", "||", "(", "false", "===", "$", "fh", "=", "@", "opendir", "(", "$", "serverPath", ")", ")", ")", "{", "return", "false", ";", "}", "$", "hasChildren", "=", "false", ";", "while", "(", "false", "!==", "(", "$", "filename", "=", "readdir", "(", "$", "fh", ")", ")", ")", "{", "if", "(", "$", "filename", "==", "'.'", "||", "$", "filename", "==", "'..'", ")", "{", "continue", ";", "}", "else", "if", "(", "is_dir", "(", "$", "serverPath", ".", "$", "filename", ")", ")", "{", "//we have found valid directory", "$", "_config", "=", "&", "CKFinder_Connector_Core_Factory", "::", "getInstance", "(", "\"Core_Config\"", ")", ";", "$", "_acl", "=", "$", "_config", "->", "getAccessControlConfig", "(", ")", ";", "$", "_aclMask", "=", "$", "_acl", "->", "getComputedMask", "(", "$", "_resourceType", "->", "getName", "(", ")", ",", "$", "clientPath", ".", "$", "filename", ")", ";", "if", "(", "(", "$", "_aclMask", "&", "CKFINDER_CONNECTOR_ACL_FOLDER_VIEW", ")", "!=", "CKFINDER_CONNECTOR_ACL_FOLDER_VIEW", ")", "{", "continue", ";", "}", "if", "(", "$", "_resourceType", "->", "checkIsHiddenFolder", "(", "$", "filename", ")", ")", "{", "continue", ";", "}", "$", "hasChildren", "=", "true", ";", "break", ";", "}", "}", "closedir", "(", "$", "fh", ")", ";", "return", "$", "hasChildren", ";", "}" ]
Returns true if directory is not empty @access public @static @param string $clientPath client path (with trailing slash) @param object $_resourceType resource type configuration @return boolean
[ "Returns", "true", "if", "directory", "is", "not", "empty" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L615-L647
27,045
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.getTmpDir
public static function getTmpDir() { $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $tmpDir = $_config->getTempDirectory(); if ( $tmpDir ) { return $tmpDir; } if ( !function_exists('sys_get_temp_dir')) { function sys_get_temp_dir() { if( $temp=getenv('TMP') ){ return $temp; } if( $temp=getenv('TEMP') ) { return $temp; } if( $temp=getenv('TMPDIR') ) { return $temp; } $temp = tempnam(__FILE__,''); if ( file_exists($temp) ){ unlink($temp); return dirname($temp); } return null; } } return sys_get_temp_dir(); }
php
public static function getTmpDir() { $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $tmpDir = $_config->getTempDirectory(); if ( $tmpDir ) { return $tmpDir; } if ( !function_exists('sys_get_temp_dir')) { function sys_get_temp_dir() { if( $temp=getenv('TMP') ){ return $temp; } if( $temp=getenv('TEMP') ) { return $temp; } if( $temp=getenv('TMPDIR') ) { return $temp; } $temp = tempnam(__FILE__,''); if ( file_exists($temp) ){ unlink($temp); return dirname($temp); } return null; } } return sys_get_temp_dir(); }
[ "public", "static", "function", "getTmpDir", "(", ")", "{", "$", "_config", "=", "&", "CKFinder_Connector_Core_Factory", "::", "getInstance", "(", "\"Core_Config\"", ")", ";", "$", "tmpDir", "=", "$", "_config", "->", "getTempDirectory", "(", ")", ";", "if", "(", "$", "tmpDir", ")", "{", "return", "$", "tmpDir", ";", "}", "if", "(", "!", "function_exists", "(", "'sys_get_temp_dir'", ")", ")", "{", "function", "sys_get_temp_dir", "(", ")", "{", "if", "(", "$", "temp", "=", "getenv", "(", "'TMP'", ")", ")", "{", "return", "$", "temp", ";", "}", "if", "(", "$", "temp", "=", "getenv", "(", "'TEMP'", ")", ")", "{", "return", "$", "temp", ";", "}", "if", "(", "$", "temp", "=", "getenv", "(", "'TMPDIR'", ")", ")", "{", "return", "$", "temp", ";", "}", "$", "temp", "=", "tempnam", "(", "__FILE__", ",", "''", ")", ";", "if", "(", "file_exists", "(", "$", "temp", ")", ")", "{", "unlink", "(", "$", "temp", ")", ";", "return", "dirname", "(", "$", "temp", ")", ";", "}", "return", "null", ";", "}", "}", "return", "sys_get_temp_dir", "(", ")", ";", "}" ]
Retruns temp directory @access public @static @return string
[ "Retruns", "temp", "directory" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L656-L684
27,046
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.isEmptyDir
public static function isEmptyDir($dirname) { $files = scandir($dirname); if ( $files && count($files) > 2) { return false; } return true; }
php
public static function isEmptyDir($dirname) { $files = scandir($dirname); if ( $files && count($files) > 2) { return false; } return true; }
[ "public", "static", "function", "isEmptyDir", "(", "$", "dirname", ")", "{", "$", "files", "=", "scandir", "(", "$", "dirname", ")", ";", "if", "(", "$", "files", "&&", "count", "(", "$", "files", ")", ">", "2", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Check if given directory is empty @param string $dirname @access public @static @return bool
[ "Check", "if", "given", "directory", "is", "empty" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L694-L702
27,047
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.autoRename
public static function autoRename( $filePath, $fileName ) { $sFileNameOrginal = $fileName; $iCounter = 0; while (true) { $sFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($filePath, $fileName); if ( file_exists($sFilePath) ){ $iCounter++; $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($sFileNameOrginal, false) . "(" . $iCounter . ")" . "." .CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal, false); } else { break; } } return $fileName; }
php
public static function autoRename( $filePath, $fileName ) { $sFileNameOrginal = $fileName; $iCounter = 0; while (true) { $sFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($filePath, $fileName); if ( file_exists($sFilePath) ){ $iCounter++; $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($sFileNameOrginal, false) . "(" . $iCounter . ")" . "." .CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal, false); } else { break; } } return $fileName; }
[ "public", "static", "function", "autoRename", "(", "$", "filePath", ",", "$", "fileName", ")", "{", "$", "sFileNameOrginal", "=", "$", "fileName", ";", "$", "iCounter", "=", "0", ";", "while", "(", "true", ")", "{", "$", "sFilePath", "=", "CKFinder_Connector_Utils_FileSystem", "::", "combinePaths", "(", "$", "filePath", ",", "$", "fileName", ")", ";", "if", "(", "file_exists", "(", "$", "sFilePath", ")", ")", "{", "$", "iCounter", "++", ";", "$", "fileName", "=", "CKFinder_Connector_Utils_FileSystem", "::", "getFileNameWithoutExtension", "(", "$", "sFileNameOrginal", ",", "false", ")", ".", "\"(\"", ".", "$", "iCounter", ".", "\")\"", ".", "\".\"", ".", "CKFinder_Connector_Utils_FileSystem", "::", "getExtension", "(", "$", "sFileNameOrginal", ",", "false", ")", ";", "}", "else", "{", "break", ";", "}", "}", "return", "$", "fileName", ";", "}" ]
Autorename file if previous name is already taken @param string $filePath @param string $fileName @param string $sFileNameOrginal
[ "Autorename", "file", "if", "previous", "name", "is", "already", "taken" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L711-L728
27,048
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.sendFile
public static function sendFile( $filePath ){ $config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); if ( $config->getXSendfile() ){ CKFinder_Connector_Utils_FileSystem::sendWithXSendfile($filePath); } else { CKFinder_Connector_Utils_FileSystem::readfileChunked($filePath); } }
php
public static function sendFile( $filePath ){ $config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); if ( $config->getXSendfile() ){ CKFinder_Connector_Utils_FileSystem::sendWithXSendfile($filePath); } else { CKFinder_Connector_Utils_FileSystem::readfileChunked($filePath); } }
[ "public", "static", "function", "sendFile", "(", "$", "filePath", ")", "{", "$", "config", "=", "&", "CKFinder_Connector_Core_Factory", "::", "getInstance", "(", "\"Core_Config\"", ")", ";", "if", "(", "$", "config", "->", "getXSendfile", "(", ")", ")", "{", "CKFinder_Connector_Utils_FileSystem", "::", "sendWithXSendfile", "(", "$", "filePath", ")", ";", "}", "else", "{", "CKFinder_Connector_Utils_FileSystem", "::", "readfileChunked", "(", "$", "filePath", ")", ";", "}", "}" ]
Send file to browser Selects the method depending on the XSendfile setting @param string $filePath
[ "Send", "file", "to", "browser", "Selects", "the", "method", "depending", "on", "the", "XSendfile", "setting" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L735-L742
27,049
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php
CKFinder_Connector_Utils_FileSystem.sendWithXSendfile
public static function sendWithXSendfile ( $filePath ){ if ( stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== FALSE ){ $fallback = true; $config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $XSendfileNginx = $config->getXSendfileNginx(); foreach ( $XSendfileNginx as $location => $root){ if ( false !== stripos($filePath , $root) ){ $fallback = false; $filePath = str_ireplace($root,$location,$filePath); header("X-Accel-Redirect: ".$filePath); // Nginx break; } } // fallback to standar method if ( $fallback ){ CKFinder_Connector_Utils_FileSystem::readfileChunked($filePath); } } elseif ( stripos($_SERVER['SERVER_SOFTWARE'], 'lighttpd/1.4') !== FALSE ){ header("X-LIGHTTPD-send-file: ".$filePath); // Lighttpd v1.4 } else { header("X-Sendfile: ".$filePath); // Apache, Lighttpd v1.5, Cherokee } }
php
public static function sendWithXSendfile ( $filePath ){ if ( stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== FALSE ){ $fallback = true; $config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $XSendfileNginx = $config->getXSendfileNginx(); foreach ( $XSendfileNginx as $location => $root){ if ( false !== stripos($filePath , $root) ){ $fallback = false; $filePath = str_ireplace($root,$location,$filePath); header("X-Accel-Redirect: ".$filePath); // Nginx break; } } // fallback to standar method if ( $fallback ){ CKFinder_Connector_Utils_FileSystem::readfileChunked($filePath); } } elseif ( stripos($_SERVER['SERVER_SOFTWARE'], 'lighttpd/1.4') !== FALSE ){ header("X-LIGHTTPD-send-file: ".$filePath); // Lighttpd v1.4 } else { header("X-Sendfile: ".$filePath); // Apache, Lighttpd v1.5, Cherokee } }
[ "public", "static", "function", "sendWithXSendfile", "(", "$", "filePath", ")", "{", "if", "(", "stripos", "(", "$", "_SERVER", "[", "'SERVER_SOFTWARE'", "]", ",", "'nginx'", ")", "!==", "FALSE", ")", "{", "$", "fallback", "=", "true", ";", "$", "config", "=", "&", "CKFinder_Connector_Core_Factory", "::", "getInstance", "(", "\"Core_Config\"", ")", ";", "$", "XSendfileNginx", "=", "$", "config", "->", "getXSendfileNginx", "(", ")", ";", "foreach", "(", "$", "XSendfileNginx", "as", "$", "location", "=>", "$", "root", ")", "{", "if", "(", "false", "!==", "stripos", "(", "$", "filePath", ",", "$", "root", ")", ")", "{", "$", "fallback", "=", "false", ";", "$", "filePath", "=", "str_ireplace", "(", "$", "root", ",", "$", "location", ",", "$", "filePath", ")", ";", "header", "(", "\"X-Accel-Redirect: \"", ".", "$", "filePath", ")", ";", "// Nginx", "break", ";", "}", "}", "// fallback to standar method", "if", "(", "$", "fallback", ")", "{", "CKFinder_Connector_Utils_FileSystem", "::", "readfileChunked", "(", "$", "filePath", ")", ";", "}", "}", "elseif", "(", "stripos", "(", "$", "_SERVER", "[", "'SERVER_SOFTWARE'", "]", ",", "'lighttpd/1.4'", ")", "!==", "FALSE", ")", "{", "header", "(", "\"X-LIGHTTPD-send-file: \"", ".", "$", "filePath", ")", ";", "// Lighttpd v1.4", "}", "else", "{", "header", "(", "\"X-Sendfile: \"", ".", "$", "filePath", ")", ";", "// Apache, Lighttpd v1.5, Cherokee", "}", "}" ]
Send files using X-Sendfile server module @param string $filePath
[ "Send", "files", "using", "X", "-", "Sendfile", "server", "module" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/connector/php/php5/Utils/FileSystem.php#L749-L771
27,050
aimeos/ai-controller-jobs
controller/common/src/Controller/Common/Subscription/Export/Csv/Processor/Address/Standard.php
Standard.process
public function process( \Aimeos\MShop\Subscription\Item\Iface $subscription, \Aimeos\MShop\Order\Item\Base\Iface $order ) { $result = []; $addresses = $order->getAddresses(); krsort( $addresses ); foreach( $addresses as $items ) { foreach( $items as $item ) { $data = []; $list = $item->toArray(); foreach( $this->getMapping() as $pos => $key ) { if( array_key_exists( $key, $list ) ) { $data[$pos] = $list[$key]; } else { $data[$pos] = ''; } } ksort( $data ); $result[] = $data; } } return $result; }
php
public function process( \Aimeos\MShop\Subscription\Item\Iface $subscription, \Aimeos\MShop\Order\Item\Base\Iface $order ) { $result = []; $addresses = $order->getAddresses(); krsort( $addresses ); foreach( $addresses as $items ) { foreach( $items as $item ) { $data = []; $list = $item->toArray(); foreach( $this->getMapping() as $pos => $key ) { if( array_key_exists( $key, $list ) ) { $data[$pos] = $list[$key]; } else { $data[$pos] = ''; } } ksort( $data ); $result[] = $data; } } return $result; }
[ "public", "function", "process", "(", "\\", "Aimeos", "\\", "MShop", "\\", "Subscription", "\\", "Item", "\\", "Iface", "$", "subscription", ",", "\\", "Aimeos", "\\", "MShop", "\\", "Order", "\\", "Item", "\\", "Base", "\\", "Iface", "$", "order", ")", "{", "$", "result", "=", "[", "]", ";", "$", "addresses", "=", "$", "order", "->", "getAddresses", "(", ")", ";", "krsort", "(", "$", "addresses", ")", ";", "foreach", "(", "$", "addresses", "as", "$", "items", ")", "{", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "data", "=", "[", "]", ";", "$", "list", "=", "$", "item", "->", "toArray", "(", ")", ";", "foreach", "(", "$", "this", "->", "getMapping", "(", ")", "as", "$", "pos", "=>", "$", "key", ")", "{", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "list", ")", ")", "{", "$", "data", "[", "$", "pos", "]", "=", "$", "list", "[", "$", "key", "]", ";", "}", "else", "{", "$", "data", "[", "$", "pos", "]", "=", "''", ";", "}", "}", "ksort", "(", "$", "data", ")", ";", "$", "result", "[", "]", "=", "$", "data", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns the subscription related data @param \Aimeos\MShop\Subscription\Item\Iface $subscription Subscription item @param \Aimeos\MShop\Order\Item\Base\Iface $order Full subscription with associated items @return array Two dimensional associative list of subscription data representing the lines in CSV
[ "Returns", "the", "subscription", "related", "data" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/common/src/Controller/Common/Subscription/Export/Csv/Processor/Address/Standard.php#L43-L72
27,051
pr-of-it/t4
framework/Orm/Extensions/Tree.php
Tree.insertModelAsLastRoot
protected function insertModelAsLastRoot(Model $model) { /** @var \T4\Orm\Model $class */ $class = get_class($model); $tableName = $class::getTableName(); /** @var \T4\Dbal\Connection $connection */ $connection = $class::getDbConnection(); $query = (new Query()) ->select('MAX(__rgt)') ->from($tableName); $maxRgt = (int)$connection->query($query)->fetchScalar(); if ($model->isNew()) { $model->__lft = $maxRgt + 1; $model->__rgt = $model->__lft + 1; $model->__lvl = 0; $model->__prt = null; } else { $query = (new Query()) ->update() ->table($tableName) ->values([ '__lft' => '__lft + :max - :lft + 1', '__rgt' => '__rgt + :max - :lft + 1', '__lvl' => '__lvl - :lvl', ]) ->where('__lft>=:lft AND __rgt<=:rgt') ->params([':max' => $maxRgt, ':lft' => $model->__lft, ':rgt' => $model->__rgt, ':lvl' => $model->__lvl]); $connection->execute($query); $this->removeFromTreeByElement($model); // TODO: calculate new __lft, __rgt! $model->refreshTreeColumns(); $model->__lvl = 0; $model->__prt = null; } }
php
protected function insertModelAsLastRoot(Model $model) { /** @var \T4\Orm\Model $class */ $class = get_class($model); $tableName = $class::getTableName(); /** @var \T4\Dbal\Connection $connection */ $connection = $class::getDbConnection(); $query = (new Query()) ->select('MAX(__rgt)') ->from($tableName); $maxRgt = (int)$connection->query($query)->fetchScalar(); if ($model->isNew()) { $model->__lft = $maxRgt + 1; $model->__rgt = $model->__lft + 1; $model->__lvl = 0; $model->__prt = null; } else { $query = (new Query()) ->update() ->table($tableName) ->values([ '__lft' => '__lft + :max - :lft + 1', '__rgt' => '__rgt + :max - :lft + 1', '__lvl' => '__lvl - :lvl', ]) ->where('__lft>=:lft AND __rgt<=:rgt') ->params([':max' => $maxRgt, ':lft' => $model->__lft, ':rgt' => $model->__rgt, ':lvl' => $model->__lvl]); $connection->execute($query); $this->removeFromTreeByElement($model); // TODO: calculate new __lft, __rgt! $model->refreshTreeColumns(); $model->__lvl = 0; $model->__prt = null; } }
[ "protected", "function", "insertModelAsLastRoot", "(", "Model", "$", "model", ")", "{", "/** @var \\T4\\Orm\\Model $class */", "$", "class", "=", "get_class", "(", "$", "model", ")", ";", "$", "tableName", "=", "$", "class", "::", "getTableName", "(", ")", ";", "/** @var \\T4\\Dbal\\Connection $connection */", "$", "connection", "=", "$", "class", "::", "getDbConnection", "(", ")", ";", "$", "query", "=", "(", "new", "Query", "(", ")", ")", "->", "select", "(", "'MAX(__rgt)'", ")", "->", "from", "(", "$", "tableName", ")", ";", "$", "maxRgt", "=", "(", "int", ")", "$", "connection", "->", "query", "(", "$", "query", ")", "->", "fetchScalar", "(", ")", ";", "if", "(", "$", "model", "->", "isNew", "(", ")", ")", "{", "$", "model", "->", "__lft", "=", "$", "maxRgt", "+", "1", ";", "$", "model", "->", "__rgt", "=", "$", "model", "->", "__lft", "+", "1", ";", "$", "model", "->", "__lvl", "=", "0", ";", "$", "model", "->", "__prt", "=", "null", ";", "}", "else", "{", "$", "query", "=", "(", "new", "Query", "(", ")", ")", "->", "update", "(", ")", "->", "table", "(", "$", "tableName", ")", "->", "values", "(", "[", "'__lft'", "=>", "'__lft + :max - :lft + 1'", ",", "'__rgt'", "=>", "'__rgt + :max - :lft + 1'", ",", "'__lvl'", "=>", "'__lvl - :lvl'", ",", "]", ")", "->", "where", "(", "'__lft>=:lft AND __rgt<=:rgt'", ")", "->", "params", "(", "[", "':max'", "=>", "$", "maxRgt", ",", "':lft'", "=>", "$", "model", "->", "__lft", ",", "':rgt'", "=>", "$", "model", "->", "__rgt", ",", "':lvl'", "=>", "$", "model", "->", "__lvl", "]", ")", ";", "$", "connection", "->", "execute", "(", "$", "query", ")", ";", "$", "this", "->", "removeFromTreeByElement", "(", "$", "model", ")", ";", "// TODO: calculate new __lft, __rgt!", "$", "model", "->", "refreshTreeColumns", "(", ")", ";", "$", "model", "->", "__lvl", "=", "0", ";", "$", "model", "->", "__prt", "=", "null", ";", "}", "}" ]
Prepares model for insert into tree as last root @param \T4\Orm\Model $model
[ "Prepares", "model", "for", "insert", "into", "tree", "as", "last", "root" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Orm/Extensions/Tree.php#L310-L351
27,052
wikimedia/html-formatter
src/HtmlFormatter.php
HtmlFormatter.filterContent
public function filterContent() { $removals = $this->parseItemsToRemove(); // Bail out early if nothing to do if ( \array_reduce( $removals, function ( $carry, $item ) { return $carry && !$item; }, true ) ) { return []; } $doc = $this->getDoc(); // Remove tags // You can't remove DOMNodes from a DOMNodeList as you're iterating // over them in a foreach loop. It will seemingly leave the internal // iterator on the foreach out of wack and results will be quite // strange. Though, making a queue of items to remove seems to work. $domElemsToRemove = []; foreach ( $removals['TAG'] as $tagToRemove ) { $tagToRemoveNodes = $doc->getElementsByTagName( $tagToRemove ); foreach ( $tagToRemoveNodes as $tagToRemoveNode ) { if ( $tagToRemoveNode ) { $domElemsToRemove[] = $tagToRemoveNode; } } } $removed = $this->removeElements( $domElemsToRemove ); // Elements with named IDs $domElemsToRemove = []; foreach ( $removals['ID'] as $itemToRemove ) { $itemToRemoveNode = $doc->getElementById( $itemToRemove ); if ( $itemToRemoveNode ) { $domElemsToRemove[] = $itemToRemoveNode; } } $removed = array_merge( $removed, $this->removeElements( $domElemsToRemove ) ); // CSS Classes $domElemsToRemove = []; $xpath = new \DOMXPath( $doc ); foreach ( $removals['CLASS'] as $classToRemove ) { $elements = $xpath->query( '//*[contains(@class, "' . $classToRemove . '")]' ); /** @var $element \DOMElement */ foreach ( $elements as $element ) { $classes = $element->getAttribute( 'class' ); if ( \preg_match( "/\b$classToRemove\b/", $classes ) && $element->parentNode ) { $domElemsToRemove[] = $element; } } } $removed = \array_merge( $removed, $this->removeElements( $domElemsToRemove ) ); // Tags with CSS Classes foreach ( $removals['TAG_CLASS'] as $classToRemove ) { $parts = explode( '.', $classToRemove ); $elements = $xpath->query( '//' . $parts[0] . '[@class="' . $parts[1] . '"]' ); $removed = array_merge( $removed, $this->removeElements( $elements ) ); } return $removed; }
php
public function filterContent() { $removals = $this->parseItemsToRemove(); // Bail out early if nothing to do if ( \array_reduce( $removals, function ( $carry, $item ) { return $carry && !$item; }, true ) ) { return []; } $doc = $this->getDoc(); // Remove tags // You can't remove DOMNodes from a DOMNodeList as you're iterating // over them in a foreach loop. It will seemingly leave the internal // iterator on the foreach out of wack and results will be quite // strange. Though, making a queue of items to remove seems to work. $domElemsToRemove = []; foreach ( $removals['TAG'] as $tagToRemove ) { $tagToRemoveNodes = $doc->getElementsByTagName( $tagToRemove ); foreach ( $tagToRemoveNodes as $tagToRemoveNode ) { if ( $tagToRemoveNode ) { $domElemsToRemove[] = $tagToRemoveNode; } } } $removed = $this->removeElements( $domElemsToRemove ); // Elements with named IDs $domElemsToRemove = []; foreach ( $removals['ID'] as $itemToRemove ) { $itemToRemoveNode = $doc->getElementById( $itemToRemove ); if ( $itemToRemoveNode ) { $domElemsToRemove[] = $itemToRemoveNode; } } $removed = array_merge( $removed, $this->removeElements( $domElemsToRemove ) ); // CSS Classes $domElemsToRemove = []; $xpath = new \DOMXPath( $doc ); foreach ( $removals['CLASS'] as $classToRemove ) { $elements = $xpath->query( '//*[contains(@class, "' . $classToRemove . '")]' ); /** @var $element \DOMElement */ foreach ( $elements as $element ) { $classes = $element->getAttribute( 'class' ); if ( \preg_match( "/\b$classToRemove\b/", $classes ) && $element->parentNode ) { $domElemsToRemove[] = $element; } } } $removed = \array_merge( $removed, $this->removeElements( $domElemsToRemove ) ); // Tags with CSS Classes foreach ( $removals['TAG_CLASS'] as $classToRemove ) { $parts = explode( '.', $classToRemove ); $elements = $xpath->query( '//' . $parts[0] . '[@class="' . $parts[1] . '"]' ); $removed = array_merge( $removed, $this->removeElements( $elements ) ); } return $removed; }
[ "public", "function", "filterContent", "(", ")", "{", "$", "removals", "=", "$", "this", "->", "parseItemsToRemove", "(", ")", ";", "// Bail out early if nothing to do", "if", "(", "\\", "array_reduce", "(", "$", "removals", ",", "function", "(", "$", "carry", ",", "$", "item", ")", "{", "return", "$", "carry", "&&", "!", "$", "item", ";", "}", ",", "true", ")", ")", "{", "return", "[", "]", ";", "}", "$", "doc", "=", "$", "this", "->", "getDoc", "(", ")", ";", "// Remove tags", "// You can't remove DOMNodes from a DOMNodeList as you're iterating", "// over them in a foreach loop. It will seemingly leave the internal", "// iterator on the foreach out of wack and results will be quite", "// strange. Though, making a queue of items to remove seems to work.", "$", "domElemsToRemove", "=", "[", "]", ";", "foreach", "(", "$", "removals", "[", "'TAG'", "]", "as", "$", "tagToRemove", ")", "{", "$", "tagToRemoveNodes", "=", "$", "doc", "->", "getElementsByTagName", "(", "$", "tagToRemove", ")", ";", "foreach", "(", "$", "tagToRemoveNodes", "as", "$", "tagToRemoveNode", ")", "{", "if", "(", "$", "tagToRemoveNode", ")", "{", "$", "domElemsToRemove", "[", "]", "=", "$", "tagToRemoveNode", ";", "}", "}", "}", "$", "removed", "=", "$", "this", "->", "removeElements", "(", "$", "domElemsToRemove", ")", ";", "// Elements with named IDs", "$", "domElemsToRemove", "=", "[", "]", ";", "foreach", "(", "$", "removals", "[", "'ID'", "]", "as", "$", "itemToRemove", ")", "{", "$", "itemToRemoveNode", "=", "$", "doc", "->", "getElementById", "(", "$", "itemToRemove", ")", ";", "if", "(", "$", "itemToRemoveNode", ")", "{", "$", "domElemsToRemove", "[", "]", "=", "$", "itemToRemoveNode", ";", "}", "}", "$", "removed", "=", "array_merge", "(", "$", "removed", ",", "$", "this", "->", "removeElements", "(", "$", "domElemsToRemove", ")", ")", ";", "// CSS Classes", "$", "domElemsToRemove", "=", "[", "]", ";", "$", "xpath", "=", "new", "\\", "DOMXPath", "(", "$", "doc", ")", ";", "foreach", "(", "$", "removals", "[", "'CLASS'", "]", "as", "$", "classToRemove", ")", "{", "$", "elements", "=", "$", "xpath", "->", "query", "(", "'//*[contains(@class, \"'", ".", "$", "classToRemove", ".", "'\")]'", ")", ";", "/** @var $element \\DOMElement */", "foreach", "(", "$", "elements", "as", "$", "element", ")", "{", "$", "classes", "=", "$", "element", "->", "getAttribute", "(", "'class'", ")", ";", "if", "(", "\\", "preg_match", "(", "\"/\\b$classToRemove\\b/\"", ",", "$", "classes", ")", "&&", "$", "element", "->", "parentNode", ")", "{", "$", "domElemsToRemove", "[", "]", "=", "$", "element", ";", "}", "}", "}", "$", "removed", "=", "\\", "array_merge", "(", "$", "removed", ",", "$", "this", "->", "removeElements", "(", "$", "domElemsToRemove", ")", ")", ";", "// Tags with CSS Classes", "foreach", "(", "$", "removals", "[", "'TAG_CLASS'", "]", "as", "$", "classToRemove", ")", "{", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "classToRemove", ")", ";", "$", "elements", "=", "$", "xpath", "->", "query", "(", "'//'", ".", "$", "parts", "[", "0", "]", ".", "'[@class=\"'", ".", "$", "parts", "[", "1", "]", ".", "'\"]'", ")", ";", "$", "removed", "=", "array_merge", "(", "$", "removed", ",", "$", "this", "->", "removeElements", "(", "$", "elements", ")", ")", ";", "}", "return", "$", "removed", ";", "}" ]
Removes content we've chosen to remove. The text of the removed elements can be extracted with the getText method. @return array Array of removed DOMElements
[ "Removes", "content", "we", "ve", "chosen", "to", "remove", ".", "The", "text", "of", "the", "removed", "elements", "can", "be", "extracted", "with", "the", "getText", "method", "." ]
5e33e3bbb327b3e0d685cc595837ccb024b72f57
https://github.com/wikimedia/html-formatter/blob/5e33e3bbb327b3e0d685cc595837ccb024b72f57/src/HtmlFormatter.php#L137-L206
27,053
wikimedia/html-formatter
src/HtmlFormatter.php
HtmlFormatter.removeElements
private function removeElements( $elements ) { $list = $elements; if ( $elements instanceof \DOMNodeList ) { $list = []; foreach ( $elements as $element ) { $list[] = $element; } } /** @var $element \DOMElement */ foreach ( $list as $element ) { if ( $element->parentNode ) { $element->parentNode->removeChild( $element ); } } return $list; }
php
private function removeElements( $elements ) { $list = $elements; if ( $elements instanceof \DOMNodeList ) { $list = []; foreach ( $elements as $element ) { $list[] = $element; } } /** @var $element \DOMElement */ foreach ( $list as $element ) { if ( $element->parentNode ) { $element->parentNode->removeChild( $element ); } } return $list; }
[ "private", "function", "removeElements", "(", "$", "elements", ")", "{", "$", "list", "=", "$", "elements", ";", "if", "(", "$", "elements", "instanceof", "\\", "DOMNodeList", ")", "{", "$", "list", "=", "[", "]", ";", "foreach", "(", "$", "elements", "as", "$", "element", ")", "{", "$", "list", "[", "]", "=", "$", "element", ";", "}", "}", "/** @var $element \\DOMElement */", "foreach", "(", "$", "list", "as", "$", "element", ")", "{", "if", "(", "$", "element", "->", "parentNode", ")", "{", "$", "element", "->", "parentNode", "->", "removeChild", "(", "$", "element", ")", ";", "}", "}", "return", "$", "list", ";", "}" ]
Removes a list of elelments from DOMDocument @param array|\DOMNodeList $elements @return array Array of removed elements
[ "Removes", "a", "list", "of", "elelments", "from", "DOMDocument" ]
5e33e3bbb327b3e0d685cc595837ccb024b72f57
https://github.com/wikimedia/html-formatter/blob/5e33e3bbb327b3e0d685cc595837ccb024b72f57/src/HtmlFormatter.php#L213-L228
27,054
wikimedia/html-formatter
src/HtmlFormatter.php
HtmlFormatter.fixLibXML
private function fixLibXML( $html ) { // We don't include rules like '&#34;' => '&amp;quot;' because entities had already been // normalized by libxml. Using this function with input not sanitized by libxml is UNSAFE! $replacements = [ '&quot;' => '&amp;quot;', '&amp;' => '&amp;amp;', '&lt;' => '&amp;lt;', '&gt;' => '&amp;gt;', ]; $html = strtr( $html, $replacements ); // Just in case the conversion in getDoc() above used named // entities that aren't known to html_entity_decode(). $html = \mb_convert_encoding( $html, 'UTF-8', 'HTML-ENTITIES' ); return $html; }
php
private function fixLibXML( $html ) { // We don't include rules like '&#34;' => '&amp;quot;' because entities had already been // normalized by libxml. Using this function with input not sanitized by libxml is UNSAFE! $replacements = [ '&quot;' => '&amp;quot;', '&amp;' => '&amp;amp;', '&lt;' => '&amp;lt;', '&gt;' => '&amp;gt;', ]; $html = strtr( $html, $replacements ); // Just in case the conversion in getDoc() above used named // entities that aren't known to html_entity_decode(). $html = \mb_convert_encoding( $html, 'UTF-8', 'HTML-ENTITIES' ); return $html; }
[ "private", "function", "fixLibXML", "(", "$", "html", ")", "{", "// We don't include rules like '&#34;' => '&amp;quot;' because entities had already been", "// normalized by libxml. Using this function with input not sanitized by libxml is UNSAFE!", "$", "replacements", "=", "[", "'&quot;'", "=>", "'&amp;quot;'", ",", "'&amp;'", "=>", "'&amp;amp;'", ",", "'&lt;'", "=>", "'&amp;lt;'", ",", "'&gt;'", "=>", "'&amp;gt;'", ",", "]", ";", "$", "html", "=", "strtr", "(", "$", "html", ",", "$", "replacements", ")", ";", "// Just in case the conversion in getDoc() above used named", "// entities that aren't known to html_entity_decode().", "$", "html", "=", "\\", "mb_convert_encoding", "(", "$", "html", ",", "'UTF-8'", ",", "'HTML-ENTITIES'", ")", ";", "return", "$", "html", ";", "}" ]
libxml in its usual pointlessness converts many chars to entities - this function perfoms a reverse conversion @param string $html @return string
[ "libxml", "in", "its", "usual", "pointlessness", "converts", "many", "chars", "to", "entities", "-", "this", "function", "perfoms", "a", "reverse", "conversion" ]
5e33e3bbb327b3e0d685cc595837ccb024b72f57
https://github.com/wikimedia/html-formatter/blob/5e33e3bbb327b3e0d685cc595837ccb024b72f57/src/HtmlFormatter.php#L236-L251
27,055
aimeos/ai-controller-jobs
controller/common/src/Controller/Common/Product/Import/Csv/Processor/Stock/Standard.php
Standard.process
public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) { $manager = \Aimeos\MShop::create( $this->getContext(), 'stock' ); $manager->begin(); try { $map = $this->getMappedChunk( $data, $this->getMapping() ); $items = $this->getStockItems( $product->getCode() ); foreach( $map as $pos => $list ) { if( !array_key_exists( 'stock.stocklevel', $list ) ) { continue; } $list['stock.productcode'] = $product->getCode(); $list['stock.dateback'] = $this->getValue( $list, 'stock.dateback' ); $list['stock.stocklevel'] = $this->getValue( $list, 'stock.stocklevel' ); $list['stock.type'] = $this->getValue( $list, 'stock.type', 'default' ); if( !in_array( $list['stock.type'], $this->types ) ) { $msg = sprintf( 'Invalid type "%1$s" (%2$s)', $list['stock.type'], 'stock' ); throw new \Aimeos\Controller\Common\Exception( $msg ); } if( ( $item = array_pop( $items ) ) === null ) { $item = $manager->createItem(); } $manager->saveItem( $item->fromArray( $list ), false ); } $manager->deleteItems( array_keys( $items ) ); $data = $this->getObject()->process( $product, $data ); $manager->commit(); } catch( \Exception $e ) { $manager->rollback(); throw $e; } return $data; }
php
public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) { $manager = \Aimeos\MShop::create( $this->getContext(), 'stock' ); $manager->begin(); try { $map = $this->getMappedChunk( $data, $this->getMapping() ); $items = $this->getStockItems( $product->getCode() ); foreach( $map as $pos => $list ) { if( !array_key_exists( 'stock.stocklevel', $list ) ) { continue; } $list['stock.productcode'] = $product->getCode(); $list['stock.dateback'] = $this->getValue( $list, 'stock.dateback' ); $list['stock.stocklevel'] = $this->getValue( $list, 'stock.stocklevel' ); $list['stock.type'] = $this->getValue( $list, 'stock.type', 'default' ); if( !in_array( $list['stock.type'], $this->types ) ) { $msg = sprintf( 'Invalid type "%1$s" (%2$s)', $list['stock.type'], 'stock' ); throw new \Aimeos\Controller\Common\Exception( $msg ); } if( ( $item = array_pop( $items ) ) === null ) { $item = $manager->createItem(); } $manager->saveItem( $item->fromArray( $list ), false ); } $manager->deleteItems( array_keys( $items ) ); $data = $this->getObject()->process( $product, $data ); $manager->commit(); } catch( \Exception $e ) { $manager->rollback(); throw $e; } return $data; }
[ "public", "function", "process", "(", "\\", "Aimeos", "\\", "MShop", "\\", "Product", "\\", "Item", "\\", "Iface", "$", "product", ",", "array", "$", "data", ")", "{", "$", "manager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "this", "->", "getContext", "(", ")", ",", "'stock'", ")", ";", "$", "manager", "->", "begin", "(", ")", ";", "try", "{", "$", "map", "=", "$", "this", "->", "getMappedChunk", "(", "$", "data", ",", "$", "this", "->", "getMapping", "(", ")", ")", ";", "$", "items", "=", "$", "this", "->", "getStockItems", "(", "$", "product", "->", "getCode", "(", ")", ")", ";", "foreach", "(", "$", "map", "as", "$", "pos", "=>", "$", "list", ")", "{", "if", "(", "!", "array_key_exists", "(", "'stock.stocklevel'", ",", "$", "list", ")", ")", "{", "continue", ";", "}", "$", "list", "[", "'stock.productcode'", "]", "=", "$", "product", "->", "getCode", "(", ")", ";", "$", "list", "[", "'stock.dateback'", "]", "=", "$", "this", "->", "getValue", "(", "$", "list", ",", "'stock.dateback'", ")", ";", "$", "list", "[", "'stock.stocklevel'", "]", "=", "$", "this", "->", "getValue", "(", "$", "list", ",", "'stock.stocklevel'", ")", ";", "$", "list", "[", "'stock.type'", "]", "=", "$", "this", "->", "getValue", "(", "$", "list", ",", "'stock.type'", ",", "'default'", ")", ";", "if", "(", "!", "in_array", "(", "$", "list", "[", "'stock.type'", "]", ",", "$", "this", "->", "types", ")", ")", "{", "$", "msg", "=", "sprintf", "(", "'Invalid type \"%1$s\" (%2$s)'", ",", "$", "list", "[", "'stock.type'", "]", ",", "'stock'", ")", ";", "throw", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Common", "\\", "Exception", "(", "$", "msg", ")", ";", "}", "if", "(", "(", "$", "item", "=", "array_pop", "(", "$", "items", ")", ")", "===", "null", ")", "{", "$", "item", "=", "$", "manager", "->", "createItem", "(", ")", ";", "}", "$", "manager", "->", "saveItem", "(", "$", "item", "->", "fromArray", "(", "$", "list", ")", ",", "false", ")", ";", "}", "$", "manager", "->", "deleteItems", "(", "array_keys", "(", "$", "items", ")", ")", ";", "$", "data", "=", "$", "this", "->", "getObject", "(", ")", "->", "process", "(", "$", "product", ",", "$", "data", ")", ";", "$", "manager", "->", "commit", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "manager", "->", "rollback", "(", ")", ";", "throw", "$", "e", ";", "}", "return", "$", "data", ";", "}" ]
Saves the product stock related data to the storage @param \Aimeos\MShop\Product\Item\Iface $product Product item with associated items @param array $data List of CSV fields with position as key and data as value @return array List of data which hasn't been imported
[ "Saves", "the", "product", "stock", "related", "data", "to", "the", "storage" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/common/src/Controller/Common/Product/Import/Csv/Processor/Stock/Standard.php#L66-L113
27,056
aimeos/ai-controller-jobs
controller/common/src/Controller/Common/Product/Import/Csv/Processor/Stock/Standard.php
Standard.getStockItems
protected function getStockItems( $code ) { $manager = \Aimeos\MShop::create( $this->getContext(), 'stock' ); $search = $manager->createSearch(); $search->setConditions( $search->compare( '==', 'stock.productcode', $code ) ); return $manager->searchItems( $search ); }
php
protected function getStockItems( $code ) { $manager = \Aimeos\MShop::create( $this->getContext(), 'stock' ); $search = $manager->createSearch(); $search->setConditions( $search->compare( '==', 'stock.productcode', $code ) ); return $manager->searchItems( $search ); }
[ "protected", "function", "getStockItems", "(", "$", "code", ")", "{", "$", "manager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "this", "->", "getContext", "(", ")", ",", "'stock'", ")", ";", "$", "search", "=", "$", "manager", "->", "createSearch", "(", ")", ";", "$", "search", "->", "setConditions", "(", "$", "search", "->", "compare", "(", "'=='", ",", "'stock.productcode'", ",", "$", "code", ")", ")", ";", "return", "$", "manager", "->", "searchItems", "(", "$", "search", ")", ";", "}" ]
Returns the stock items for the given product code @param string $code Unique product code @return \Aimeos\MShop\Stock\Item\Iface[] Associative list of stock items
[ "Returns", "the", "stock", "items", "for", "the", "given", "product", "code" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/common/src/Controller/Common/Product/Import/Csv/Processor/Stock/Standard.php#L122-L130
27,057
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/ckfinder_php5.php
CKFinder.CreateHtml
public function CreateHtml() { $className = $this->ClassName ; if ( !empty( $className ) ) $className = ' class="' . $className . '"' ; $id = $this->Id ; if ( !empty( $id ) ) $id = ' id="' . $id . '"' ; return '<iframe src="' . $this->_BuildUrl() . '" width="' . $this->Width . '" ' . 'height="' . $this->Height . '"' . $className . $id . ' frameborder="0" scrolling="no"></iframe>' ; }
php
public function CreateHtml() { $className = $this->ClassName ; if ( !empty( $className ) ) $className = ' class="' . $className . '"' ; $id = $this->Id ; if ( !empty( $id ) ) $id = ' id="' . $id . '"' ; return '<iframe src="' . $this->_BuildUrl() . '" width="' . $this->Width . '" ' . 'height="' . $this->Height . '"' . $className . $id . ' frameborder="0" scrolling="no"></iframe>' ; }
[ "public", "function", "CreateHtml", "(", ")", "{", "$", "className", "=", "$", "this", "->", "ClassName", ";", "if", "(", "!", "empty", "(", "$", "className", ")", ")", "$", "className", "=", "' class=\"'", ".", "$", "className", ".", "'\"'", ";", "$", "id", "=", "$", "this", "->", "Id", ";", "if", "(", "!", "empty", "(", "$", "id", ")", ")", "$", "id", "=", "' id=\"'", ".", "$", "id", ".", "'\"'", ";", "return", "'<iframe src=\"'", ".", "$", "this", "->", "_BuildUrl", "(", ")", ".", "'\" width=\"'", ".", "$", "this", "->", "Width", ".", "'\" '", ".", "'height=\"'", ".", "$", "this", "->", "Height", ".", "'\"'", ".", "$", "className", ".", "$", "id", ".", "' frameborder=\"0\" scrolling=\"no\"></iframe>'", ";", "}" ]
Gets the HTML needed to create a CKFinder instance.
[ "Gets", "the", "HTML", "needed", "to", "create", "a", "CKFinder", "instance", "." ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/ckfinder_php5.php#L50-L62
27,058
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/ckfinder_php5.php
CKFinder.CreateStatic
public static function CreateStatic( $basePath = CKFINDER_DEFAULT_BASEPATH, $width = '100%', $height = 400, $selectFunction = null ) { $finder = new CKFinder( $basePath, $width, $height, $selectFunction ) ; $finder->Create() ; }
php
public static function CreateStatic( $basePath = CKFINDER_DEFAULT_BASEPATH, $width = '100%', $height = 400, $selectFunction = null ) { $finder = new CKFinder( $basePath, $width, $height, $selectFunction ) ; $finder->Create() ; }
[ "public", "static", "function", "CreateStatic", "(", "$", "basePath", "=", "CKFINDER_DEFAULT_BASEPATH", ",", "$", "width", "=", "'100%'", ",", "$", "height", "=", "400", ",", "$", "selectFunction", "=", "null", ")", "{", "$", "finder", "=", "new", "CKFinder", "(", "$", "basePath", ",", "$", "width", ",", "$", "height", ",", "$", "selectFunction", ")", ";", "$", "finder", "->", "Create", "(", ")", ";", "}" ]
Static "Create".
[ "Static", "Create", "." ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/ckfinder_php5.php#L132-L136
27,059
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/ckfinder_php5.php
CKFinder.SetupFCKeditor
public static function SetupFCKeditor( &$editorObj, $basePath = CKFINDER_DEFAULT_BASEPATH, $imageType = null, $flashType = null ) { if ( empty( $basePath ) ) $basePath = CKFINDER_DEFAULT_BASEPATH ; $ckfinder = new CKFinder( $basePath ) ; $ckfinder->SetupFCKeditorObject( $editorObj, $imageType, $flashType ); }
php
public static function SetupFCKeditor( &$editorObj, $basePath = CKFINDER_DEFAULT_BASEPATH, $imageType = null, $flashType = null ) { if ( empty( $basePath ) ) $basePath = CKFINDER_DEFAULT_BASEPATH ; $ckfinder = new CKFinder( $basePath ) ; $ckfinder->SetupFCKeditorObject( $editorObj, $imageType, $flashType ); }
[ "public", "static", "function", "SetupFCKeditor", "(", "&", "$", "editorObj", ",", "$", "basePath", "=", "CKFINDER_DEFAULT_BASEPATH", ",", "$", "imageType", "=", "null", ",", "$", "flashType", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "basePath", ")", ")", "$", "basePath", "=", "CKFINDER_DEFAULT_BASEPATH", ";", "$", "ckfinder", "=", "new", "CKFinder", "(", "$", "basePath", ")", ";", "$", "ckfinder", "->", "SetupFCKeditorObject", "(", "$", "editorObj", ",", "$", "imageType", ",", "$", "flashType", ")", ";", "}" ]
Static "SetupFCKeditor".
[ "Static", "SetupFCKeditor", "." ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/ckfinder_php5.php#L139-L146
27,060
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/ckfinder_php5.php
CKFinder.SetupFCKeditorObject
public function SetupFCKeditorObject( &$editorObj, $imageType = null, $flashType = null ) { $url = $this->BasePath ; // If it is a path relative to the current page. if ( isset($url[0]) && $url[0] != '/' && strpos($url, "://") === false ) { $url = substr( $_SERVER[ 'REQUEST_URI' ], 0, strrpos( $_SERVER[ 'REQUEST_URI' ], '/' ) + 1 ) . $url ; } $url = $this->_BuildUrl( $url ) ; $qs = ( strpos($url, "?") !== false ) ? "&" : "?" ; if ( $this->Width !== '100%' && is_numeric( str_ireplace( "px", "", $this->Width ) ) ) { $width = intval( $this->Width ); $editorObj->Config['LinkBrowserWindowWidth'] = $width ; $editorObj->Config['ImageBrowserWindowWidth'] = $width ; $editorObj->Config['FlashBrowserWindowWidth'] = $width ; } if ( $this->Height !== 400 && is_numeric( str_ireplace( "px", "", $this->Height ) ) ) { $height = intval( $this->Height ); $editorObj->Config['LinkBrowserWindowHeight'] = $height ; $editorObj->Config['ImageBrowserWindowHeight'] = $height ; $editorObj->Config['FlashBrowserWindowHeight'] = $height ; } $editorObj->Config['LinkBrowserURL'] = $url ; $editorObj->Config['ImageBrowserURL'] = $url . $qs . 'type=' . ( empty( $imageType ) ? 'Images' : $imageType ) ; $editorObj->Config['FlashBrowserURL'] = $url . $qs . 'type=' . ( empty( $flashType ) ? 'Flash' : $flashType ) ; $dir = substr( $url, 0, strrpos( $url, "/" ) + 1 ) ; $editorObj->Config['LinkUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=Files' ) ; $editorObj->Config['ImageUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=') . ( empty( $imageType ) ? 'Images' : $imageType ) ; $editorObj->Config['FlashUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=') . ( empty( $flashType ) ? 'Flash' : $flashType ) ; }
php
public function SetupFCKeditorObject( &$editorObj, $imageType = null, $flashType = null ) { $url = $this->BasePath ; // If it is a path relative to the current page. if ( isset($url[0]) && $url[0] != '/' && strpos($url, "://") === false ) { $url = substr( $_SERVER[ 'REQUEST_URI' ], 0, strrpos( $_SERVER[ 'REQUEST_URI' ], '/' ) + 1 ) . $url ; } $url = $this->_BuildUrl( $url ) ; $qs = ( strpos($url, "?") !== false ) ? "&" : "?" ; if ( $this->Width !== '100%' && is_numeric( str_ireplace( "px", "", $this->Width ) ) ) { $width = intval( $this->Width ); $editorObj->Config['LinkBrowserWindowWidth'] = $width ; $editorObj->Config['ImageBrowserWindowWidth'] = $width ; $editorObj->Config['FlashBrowserWindowWidth'] = $width ; } if ( $this->Height !== 400 && is_numeric( str_ireplace( "px", "", $this->Height ) ) ) { $height = intval( $this->Height ); $editorObj->Config['LinkBrowserWindowHeight'] = $height ; $editorObj->Config['ImageBrowserWindowHeight'] = $height ; $editorObj->Config['FlashBrowserWindowHeight'] = $height ; } $editorObj->Config['LinkBrowserURL'] = $url ; $editorObj->Config['ImageBrowserURL'] = $url . $qs . 'type=' . ( empty( $imageType ) ? 'Images' : $imageType ) ; $editorObj->Config['FlashBrowserURL'] = $url . $qs . 'type=' . ( empty( $flashType ) ? 'Flash' : $flashType ) ; $dir = substr( $url, 0, strrpos( $url, "/" ) + 1 ) ; $editorObj->Config['LinkUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=Files' ) ; $editorObj->Config['ImageUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=') . ( empty( $imageType ) ? 'Images' : $imageType ) ; $editorObj->Config['FlashUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=') . ( empty( $flashType ) ? 'Flash' : $flashType ) ; }
[ "public", "function", "SetupFCKeditorObject", "(", "&", "$", "editorObj", ",", "$", "imageType", "=", "null", ",", "$", "flashType", "=", "null", ")", "{", "$", "url", "=", "$", "this", "->", "BasePath", ";", "// If it is a path relative to the current page.", "if", "(", "isset", "(", "$", "url", "[", "0", "]", ")", "&&", "$", "url", "[", "0", "]", "!=", "'/'", "&&", "strpos", "(", "$", "url", ",", "\"://\"", ")", "===", "false", ")", "{", "$", "url", "=", "substr", "(", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ",", "0", ",", "strrpos", "(", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ",", "'/'", ")", "+", "1", ")", ".", "$", "url", ";", "}", "$", "url", "=", "$", "this", "->", "_BuildUrl", "(", "$", "url", ")", ";", "$", "qs", "=", "(", "strpos", "(", "$", "url", ",", "\"?\"", ")", "!==", "false", ")", "?", "\"&\"", ":", "\"?\"", ";", "if", "(", "$", "this", "->", "Width", "!==", "'100%'", "&&", "is_numeric", "(", "str_ireplace", "(", "\"px\"", ",", "\"\"", ",", "$", "this", "->", "Width", ")", ")", ")", "{", "$", "width", "=", "intval", "(", "$", "this", "->", "Width", ")", ";", "$", "editorObj", "->", "Config", "[", "'LinkBrowserWindowWidth'", "]", "=", "$", "width", ";", "$", "editorObj", "->", "Config", "[", "'ImageBrowserWindowWidth'", "]", "=", "$", "width", ";", "$", "editorObj", "->", "Config", "[", "'FlashBrowserWindowWidth'", "]", "=", "$", "width", ";", "}", "if", "(", "$", "this", "->", "Height", "!==", "400", "&&", "is_numeric", "(", "str_ireplace", "(", "\"px\"", ",", "\"\"", ",", "$", "this", "->", "Height", ")", ")", ")", "{", "$", "height", "=", "intval", "(", "$", "this", "->", "Height", ")", ";", "$", "editorObj", "->", "Config", "[", "'LinkBrowserWindowHeight'", "]", "=", "$", "height", ";", "$", "editorObj", "->", "Config", "[", "'ImageBrowserWindowHeight'", "]", "=", "$", "height", ";", "$", "editorObj", "->", "Config", "[", "'FlashBrowserWindowHeight'", "]", "=", "$", "height", ";", "}", "$", "editorObj", "->", "Config", "[", "'LinkBrowserURL'", "]", "=", "$", "url", ";", "$", "editorObj", "->", "Config", "[", "'ImageBrowserURL'", "]", "=", "$", "url", ".", "$", "qs", ".", "'type='", ".", "(", "empty", "(", "$", "imageType", ")", "?", "'Images'", ":", "$", "imageType", ")", ";", "$", "editorObj", "->", "Config", "[", "'FlashBrowserURL'", "]", "=", "$", "url", ".", "$", "qs", ".", "'type='", ".", "(", "empty", "(", "$", "flashType", ")", "?", "'Flash'", ":", "$", "flashType", ")", ";", "$", "dir", "=", "substr", "(", "$", "url", ",", "0", ",", "strrpos", "(", "$", "url", ",", "\"/\"", ")", "+", "1", ")", ";", "$", "editorObj", "->", "Config", "[", "'LinkUploadURL'", "]", "=", "$", "dir", ".", "urlencode", "(", "'core/connector/php/connector.php?command=QuickUpload&type=Files'", ")", ";", "$", "editorObj", "->", "Config", "[", "'ImageUploadURL'", "]", "=", "$", "dir", ".", "urlencode", "(", "'core/connector/php/connector.php?command=QuickUpload&type='", ")", ".", "(", "empty", "(", "$", "imageType", ")", "?", "'Images'", ":", "$", "imageType", ")", ";", "$", "editorObj", "->", "Config", "[", "'FlashUploadURL'", "]", "=", "$", "dir", ".", "urlencode", "(", "'core/connector/php/connector.php?command=QuickUpload&type='", ")", ".", "(", "empty", "(", "$", "flashType", ")", "?", "'Flash'", ":", "$", "flashType", ")", ";", "}" ]
Non-static method of attaching CKFinder to FCKeditor
[ "Non", "-", "static", "method", "of", "attaching", "CKFinder", "to", "FCKeditor" ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/ckfinder_php5.php#L149-L185
27,061
pr-of-it/t4
framework/Mvc/Extensions/Ckfinder/lib/core/ckfinder_php5.php
CKFinder.SetupCKEditor
public static function SetupCKEditor( &$editorObj, $basePath = CKFINDER_DEFAULT_BASEPATH, $imageType = null, $flashType = null ) { if ( empty( $basePath ) ) $basePath = CKFINDER_DEFAULT_BASEPATH ; $ckfinder = new CKFinder( $basePath ) ; $ckfinder->SetupCKEditorObject( $editorObj, $imageType, $flashType ); }
php
public static function SetupCKEditor( &$editorObj, $basePath = CKFINDER_DEFAULT_BASEPATH, $imageType = null, $flashType = null ) { if ( empty( $basePath ) ) $basePath = CKFINDER_DEFAULT_BASEPATH ; $ckfinder = new CKFinder( $basePath ) ; $ckfinder->SetupCKEditorObject( $editorObj, $imageType, $flashType ); }
[ "public", "static", "function", "SetupCKEditor", "(", "&", "$", "editorObj", ",", "$", "basePath", "=", "CKFINDER_DEFAULT_BASEPATH", ",", "$", "imageType", "=", "null", ",", "$", "flashType", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "basePath", ")", ")", "$", "basePath", "=", "CKFINDER_DEFAULT_BASEPATH", ";", "$", "ckfinder", "=", "new", "CKFinder", "(", "$", "basePath", ")", ";", "$", "ckfinder", "->", "SetupCKEditorObject", "(", "$", "editorObj", ",", "$", "imageType", ",", "$", "flashType", ")", ";", "}" ]
Static "SetupCKEditor".
[ "Static", "SetupCKEditor", "." ]
8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada
https://github.com/pr-of-it/t4/blob/8a8133e0b3abca9d7718fbdcf65b70c2d85b5ada/framework/Mvc/Extensions/Ckfinder/lib/core/ckfinder_php5.php#L188-L195
27,062
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Product/Import/Csv/Standard.php
Standard.getCodePosition
protected function getCodePosition( array $mapping ) { foreach( $mapping as $pos => $key ) { if( $key === 'product.code' ) { return $pos; } } throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No "product.code" column in CSV mapping found' ) ); }
php
protected function getCodePosition( array $mapping ) { foreach( $mapping as $pos => $key ) { if( $key === 'product.code' ) { return $pos; } } throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No "product.code" column in CSV mapping found' ) ); }
[ "protected", "function", "getCodePosition", "(", "array", "$", "mapping", ")", "{", "foreach", "(", "$", "mapping", "as", "$", "pos", "=>", "$", "key", ")", "{", "if", "(", "$", "key", "===", "'product.code'", ")", "{", "return", "$", "pos", ";", "}", "}", "throw", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Jobs", "\\", "Exception", "(", "sprintf", "(", "'No \"product.code\" column in CSV mapping found'", ")", ")", ";", "}" ]
Returns the position of the "product.code" column from the product item mapping @param array $mapping Mapping of the "item" columns with position as key and code as value @return integer Position of the "product.code" column @throws \Aimeos\Controller\Jobs\Exception If no mapping for "product.code" is found
[ "Returns", "the", "position", "of", "the", "product", ".", "code", "column", "from", "the", "product", "item", "mapping" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Product/Import/Csv/Standard.php#L393-L403
27,063
aimeos/ai-controller-jobs
controller/jobs/src/Controller/Jobs/Product/Import/Csv/Standard.php
Standard.import
protected function import( array $products, array $data, array $mapping, array $types, \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor, $strict ) { $items = []; $errors = 0; $context = $this->getContext(); $manager = \Aimeos\MShop::create( $context, 'product' ); $indexManager = \Aimeos\MShop::create( $context, 'index' ); foreach( $data as $code => $list ) { $manager->begin(); try { $code = trim( $code ); if( isset( $products[$code] ) ) { $product = $products[$code]; } else { $product = $manager->createItem(); } $map = $this->getMappedChunk( $list, $mapping ); if( isset( $map[0] ) ) { $map = $map[0]; // there can only be one chunk for the base product data $map['product.type'] = $this->getValue( $map, 'product.type', 'default' ); if( !in_array( $map['product.type'], $types ) ) { $msg = sprintf( 'Invalid product type "%1$s"', $map['product.type'] ); throw new \Aimeos\Controller\Jobs\Exception( $msg ); } $product = $manager->saveItem( $product->fromArray( $map, true ) ); $list = $processor->process( $product, $list ); $product = $manager->saveItem( $product ); $items[$product->getId()] = $product; } $manager->commit(); } catch( \Exception $e ) { $manager->rollback(); $msg = sprintf( 'Unable to import product with code "%1$s": %2$s', $code, $e->getMessage() ); $context->getLogger()->log( $msg ); $errors++; } if( $strict && !empty( $list ) ) { $context->getLogger()->log( 'Not imported: ' . print_r( $list, true ) ); } } $indexManager->rebuildIndex( $items ); return $errors; }
php
protected function import( array $products, array $data, array $mapping, array $types, \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor, $strict ) { $items = []; $errors = 0; $context = $this->getContext(); $manager = \Aimeos\MShop::create( $context, 'product' ); $indexManager = \Aimeos\MShop::create( $context, 'index' ); foreach( $data as $code => $list ) { $manager->begin(); try { $code = trim( $code ); if( isset( $products[$code] ) ) { $product = $products[$code]; } else { $product = $manager->createItem(); } $map = $this->getMappedChunk( $list, $mapping ); if( isset( $map[0] ) ) { $map = $map[0]; // there can only be one chunk for the base product data $map['product.type'] = $this->getValue( $map, 'product.type', 'default' ); if( !in_array( $map['product.type'], $types ) ) { $msg = sprintf( 'Invalid product type "%1$s"', $map['product.type'] ); throw new \Aimeos\Controller\Jobs\Exception( $msg ); } $product = $manager->saveItem( $product->fromArray( $map, true ) ); $list = $processor->process( $product, $list ); $product = $manager->saveItem( $product ); $items[$product->getId()] = $product; } $manager->commit(); } catch( \Exception $e ) { $manager->rollback(); $msg = sprintf( 'Unable to import product with code "%1$s": %2$s', $code, $e->getMessage() ); $context->getLogger()->log( $msg ); $errors++; } if( $strict && !empty( $list ) ) { $context->getLogger()->log( 'Not imported: ' . print_r( $list, true ) ); } } $indexManager->rebuildIndex( $items ); return $errors; }
[ "protected", "function", "import", "(", "array", "$", "products", ",", "array", "$", "data", ",", "array", "$", "mapping", ",", "array", "$", "types", ",", "\\", "Aimeos", "\\", "Controller", "\\", "Common", "\\", "Product", "\\", "Import", "\\", "Csv", "\\", "Processor", "\\", "Iface", "$", "processor", ",", "$", "strict", ")", "{", "$", "items", "=", "[", "]", ";", "$", "errors", "=", "0", ";", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "manager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "context", ",", "'product'", ")", ";", "$", "indexManager", "=", "\\", "Aimeos", "\\", "MShop", "::", "create", "(", "$", "context", ",", "'index'", ")", ";", "foreach", "(", "$", "data", "as", "$", "code", "=>", "$", "list", ")", "{", "$", "manager", "->", "begin", "(", ")", ";", "try", "{", "$", "code", "=", "trim", "(", "$", "code", ")", ";", "if", "(", "isset", "(", "$", "products", "[", "$", "code", "]", ")", ")", "{", "$", "product", "=", "$", "products", "[", "$", "code", "]", ";", "}", "else", "{", "$", "product", "=", "$", "manager", "->", "createItem", "(", ")", ";", "}", "$", "map", "=", "$", "this", "->", "getMappedChunk", "(", "$", "list", ",", "$", "mapping", ")", ";", "if", "(", "isset", "(", "$", "map", "[", "0", "]", ")", ")", "{", "$", "map", "=", "$", "map", "[", "0", "]", ";", "// there can only be one chunk for the base product data", "$", "map", "[", "'product.type'", "]", "=", "$", "this", "->", "getValue", "(", "$", "map", ",", "'product.type'", ",", "'default'", ")", ";", "if", "(", "!", "in_array", "(", "$", "map", "[", "'product.type'", "]", ",", "$", "types", ")", ")", "{", "$", "msg", "=", "sprintf", "(", "'Invalid product type \"%1$s\"'", ",", "$", "map", "[", "'product.type'", "]", ")", ";", "throw", "new", "\\", "Aimeos", "\\", "Controller", "\\", "Jobs", "\\", "Exception", "(", "$", "msg", ")", ";", "}", "$", "product", "=", "$", "manager", "->", "saveItem", "(", "$", "product", "->", "fromArray", "(", "$", "map", ",", "true", ")", ")", ";", "$", "list", "=", "$", "processor", "->", "process", "(", "$", "product", ",", "$", "list", ")", ";", "$", "product", "=", "$", "manager", "->", "saveItem", "(", "$", "product", ")", ";", "$", "items", "[", "$", "product", "->", "getId", "(", ")", "]", "=", "$", "product", ";", "}", "$", "manager", "->", "commit", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "manager", "->", "rollback", "(", ")", ";", "$", "msg", "=", "sprintf", "(", "'Unable to import product with code \"%1$s\": %2$s'", ",", "$", "code", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "$", "context", "->", "getLogger", "(", ")", "->", "log", "(", "$", "msg", ")", ";", "$", "errors", "++", ";", "}", "if", "(", "$", "strict", "&&", "!", "empty", "(", "$", "list", ")", ")", "{", "$", "context", "->", "getLogger", "(", ")", "->", "log", "(", "'Not imported: '", ".", "print_r", "(", "$", "list", ",", "true", ")", ")", ";", "}", "}", "$", "indexManager", "->", "rebuildIndex", "(", "$", "items", ")", ";", "return", "$", "errors", ";", "}" ]
Imports the CSV data and creates new products or updates existing ones @param array $products List of products items implementing \Aimeos\MShop\Product\Item\Iface @param array $data Associative list of import data as index/value pairs @param array $mapping Associative list of positions and domain item keys @param array $types List of allowed product type codes @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor Processor object @param boolean $strict Log columns not mapped or silently ignore them @return integer Number of products that couldn't be imported @throws \Aimeos\Controller\Jobs\Exception
[ "Imports", "the", "CSV", "data", "and", "creates", "new", "products", "or", "updates", "existing", "ones" ]
e4a2fc47850f72907afff68858a2be5865fa4664
https://github.com/aimeos/ai-controller-jobs/blob/e4a2fc47850f72907afff68858a2be5865fa4664/controller/jobs/src/Controller/Jobs/Product/Import/Csv/Standard.php#L523-L587
27,064
Yoast/yoastcs
Yoast/Sniffs/Yoast/AlternativeFunctionsSniff.php
AlternativeFunctionsSniff.process_matched_token
public function process_matched_token( $stackPtr, $group_name, $matched_content ) { $replacement = ''; if ( isset( $this->groups[ $group_name ]['replacement'] ) ) { $replacement = $this->groups[ $group_name ]['replacement']; } $fixable = true; $message = $this->groups[ $group_name ]['message']; $is_error = ( $this->groups[ $group_name ]['type'] === 'error' ); $error_code = $this->string_to_errorcode( $group_name . '_' . $matched_content ); $data = array( $matched_content, $replacement, ); /* * Deal with specific situations. */ switch ( $matched_content ) { case 'json_encode': case 'wp_json_encode': /* * The function `WPSEO_Utils:format_json_encode()` is only a valid alternative * when only the first parameter is passed. */ if ( $this->get_function_call_parameter_count( $stackPtr ) !== 1 ) { $fixable = false; $error_code .= 'WithAdditionalParams'; } break; } if ( $fixable === false ) { $this->addMessage( $message, $stackPtr, $is_error, $error_code, $data ); return; } $fix = $this->addFixableMessage( $message, $stackPtr, $is_error, $error_code, $data ); if ( $fix === true ) { $namespaced = $this->determine_namespace( $stackPtr ); if ( empty( $namespaced ) || empty( $replacement ) ) { $this->phpcsFile->fixer->replaceToken( $stackPtr, $replacement ); } else { $this->phpcsFile->fixer->replaceToken( $stackPtr, '\\' . $replacement ); } } }
php
public function process_matched_token( $stackPtr, $group_name, $matched_content ) { $replacement = ''; if ( isset( $this->groups[ $group_name ]['replacement'] ) ) { $replacement = $this->groups[ $group_name ]['replacement']; } $fixable = true; $message = $this->groups[ $group_name ]['message']; $is_error = ( $this->groups[ $group_name ]['type'] === 'error' ); $error_code = $this->string_to_errorcode( $group_name . '_' . $matched_content ); $data = array( $matched_content, $replacement, ); /* * Deal with specific situations. */ switch ( $matched_content ) { case 'json_encode': case 'wp_json_encode': /* * The function `WPSEO_Utils:format_json_encode()` is only a valid alternative * when only the first parameter is passed. */ if ( $this->get_function_call_parameter_count( $stackPtr ) !== 1 ) { $fixable = false; $error_code .= 'WithAdditionalParams'; } break; } if ( $fixable === false ) { $this->addMessage( $message, $stackPtr, $is_error, $error_code, $data ); return; } $fix = $this->addFixableMessage( $message, $stackPtr, $is_error, $error_code, $data ); if ( $fix === true ) { $namespaced = $this->determine_namespace( $stackPtr ); if ( empty( $namespaced ) || empty( $replacement ) ) { $this->phpcsFile->fixer->replaceToken( $stackPtr, $replacement ); } else { $this->phpcsFile->fixer->replaceToken( $stackPtr, '\\' . $replacement ); } } }
[ "public", "function", "process_matched_token", "(", "$", "stackPtr", ",", "$", "group_name", ",", "$", "matched_content", ")", "{", "$", "replacement", "=", "''", ";", "if", "(", "isset", "(", "$", "this", "->", "groups", "[", "$", "group_name", "]", "[", "'replacement'", "]", ")", ")", "{", "$", "replacement", "=", "$", "this", "->", "groups", "[", "$", "group_name", "]", "[", "'replacement'", "]", ";", "}", "$", "fixable", "=", "true", ";", "$", "message", "=", "$", "this", "->", "groups", "[", "$", "group_name", "]", "[", "'message'", "]", ";", "$", "is_error", "=", "(", "$", "this", "->", "groups", "[", "$", "group_name", "]", "[", "'type'", "]", "===", "'error'", ")", ";", "$", "error_code", "=", "$", "this", "->", "string_to_errorcode", "(", "$", "group_name", ".", "'_'", ".", "$", "matched_content", ")", ";", "$", "data", "=", "array", "(", "$", "matched_content", ",", "$", "replacement", ",", ")", ";", "/*\n\t\t * Deal with specific situations.\n\t\t */", "switch", "(", "$", "matched_content", ")", "{", "case", "'json_encode'", ":", "case", "'wp_json_encode'", ":", "/*\n\t\t\t\t * The function `WPSEO_Utils:format_json_encode()` is only a valid alternative\n\t\t\t\t * when only the first parameter is passed.\n\t\t\t\t */", "if", "(", "$", "this", "->", "get_function_call_parameter_count", "(", "$", "stackPtr", ")", "!==", "1", ")", "{", "$", "fixable", "=", "false", ";", "$", "error_code", ".=", "'WithAdditionalParams'", ";", "}", "break", ";", "}", "if", "(", "$", "fixable", "===", "false", ")", "{", "$", "this", "->", "addMessage", "(", "$", "message", ",", "$", "stackPtr", ",", "$", "is_error", ",", "$", "error_code", ",", "$", "data", ")", ";", "return", ";", "}", "$", "fix", "=", "$", "this", "->", "addFixableMessage", "(", "$", "message", ",", "$", "stackPtr", ",", "$", "is_error", ",", "$", "error_code", ",", "$", "data", ")", ";", "if", "(", "$", "fix", "===", "true", ")", "{", "$", "namespaced", "=", "$", "this", "->", "determine_namespace", "(", "$", "stackPtr", ")", ";", "if", "(", "empty", "(", "$", "namespaced", ")", "||", "empty", "(", "$", "replacement", ")", ")", "{", "$", "this", "->", "phpcsFile", "->", "fixer", "->", "replaceToken", "(", "$", "stackPtr", ",", "$", "replacement", ")", ";", "}", "else", "{", "$", "this", "->", "phpcsFile", "->", "fixer", "->", "replaceToken", "(", "$", "stackPtr", ",", "'\\\\'", ".", "$", "replacement", ")", ";", "}", "}", "}" ]
Process a matched token. @param int $stackPtr The position of the current token in the stack. @param string $group_name The name of the group which was matched. @param string $matched_content The token content (function name) which was matched. @return int|void Integer stack pointer to skip forward or void to continue normal file processing.
[ "Process", "a", "matched", "token", "." ]
44d4f28bbcf5f83d1111fafe67a17215b28c87d1
https://github.com/Yoast/yoastcs/blob/44d4f28bbcf5f83d1111fafe67a17215b28c87d1/Yoast/Sniffs/Yoast/AlternativeFunctionsSniff.php#L46-L96
27,065
Yoast/yoastcs
Yoast/Sniffs/Files/FileNameSniff.php
FileNameSniff.is_file_excluded
protected function is_file_excluded( File $phpcsFile, $path_to_file ) { $exclude = $this->clean_custom_array_property( $this->exclude, true, true ); if ( ! empty( $exclude ) ) { $exclude = array_map( array( $this, 'normalize_directory_separators' ), $exclude ); $path_to_file = $this->normalize_directory_separators( $path_to_file ); if ( ! isset( $phpcsFile->config->basepath ) ) { $phpcsFile->addWarning( 'For the exclude property to work with relative file path files, the --basepath needs to be set.', 0, 'MissingBasePath' ); } else { $base_path = $this->normalize_directory_separators( $phpcsFile->config->basepath ); $path_to_file = Common::stripBasepath( $path_to_file, $base_path ); } // Lowercase the filename to not interfere with the lowercase/dashes rule. $path_to_file = strtolower( ltrim( $path_to_file, '/' ) ); if ( isset( $exclude[ $path_to_file ] ) ) { // Filename is on the exclude list. return true; } } return false; }
php
protected function is_file_excluded( File $phpcsFile, $path_to_file ) { $exclude = $this->clean_custom_array_property( $this->exclude, true, true ); if ( ! empty( $exclude ) ) { $exclude = array_map( array( $this, 'normalize_directory_separators' ), $exclude ); $path_to_file = $this->normalize_directory_separators( $path_to_file ); if ( ! isset( $phpcsFile->config->basepath ) ) { $phpcsFile->addWarning( 'For the exclude property to work with relative file path files, the --basepath needs to be set.', 0, 'MissingBasePath' ); } else { $base_path = $this->normalize_directory_separators( $phpcsFile->config->basepath ); $path_to_file = Common::stripBasepath( $path_to_file, $base_path ); } // Lowercase the filename to not interfere with the lowercase/dashes rule. $path_to_file = strtolower( ltrim( $path_to_file, '/' ) ); if ( isset( $exclude[ $path_to_file ] ) ) { // Filename is on the exclude list. return true; } } return false; }
[ "protected", "function", "is_file_excluded", "(", "File", "$", "phpcsFile", ",", "$", "path_to_file", ")", "{", "$", "exclude", "=", "$", "this", "->", "clean_custom_array_property", "(", "$", "this", "->", "exclude", ",", "true", ",", "true", ")", ";", "if", "(", "!", "empty", "(", "$", "exclude", ")", ")", "{", "$", "exclude", "=", "array_map", "(", "array", "(", "$", "this", ",", "'normalize_directory_separators'", ")", ",", "$", "exclude", ")", ";", "$", "path_to_file", "=", "$", "this", "->", "normalize_directory_separators", "(", "$", "path_to_file", ")", ";", "if", "(", "!", "isset", "(", "$", "phpcsFile", "->", "config", "->", "basepath", ")", ")", "{", "$", "phpcsFile", "->", "addWarning", "(", "'For the exclude property to work with relative file path files, the --basepath needs to be set.'", ",", "0", ",", "'MissingBasePath'", ")", ";", "}", "else", "{", "$", "base_path", "=", "$", "this", "->", "normalize_directory_separators", "(", "$", "phpcsFile", "->", "config", "->", "basepath", ")", ";", "$", "path_to_file", "=", "Common", "::", "stripBasepath", "(", "$", "path_to_file", ",", "$", "base_path", ")", ";", "}", "// Lowercase the filename to not interfere with the lowercase/dashes rule.", "$", "path_to_file", "=", "strtolower", "(", "ltrim", "(", "$", "path_to_file", ",", "'/'", ")", ")", ";", "if", "(", "isset", "(", "$", "exclude", "[", "$", "path_to_file", "]", ")", ")", "{", "// Filename is on the exclude list.", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check if the file is on the exclude list. @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. @param string $path_to_file The full path to the file currently being examined. @return bool
[ "Check", "if", "the", "file", "is", "on", "the", "exclude", "list", "." ]
44d4f28bbcf5f83d1111fafe67a17215b28c87d1
https://github.com/Yoast/yoastcs/blob/44d4f28bbcf5f83d1111fafe67a17215b28c87d1/Yoast/Sniffs/Files/FileNameSniff.php#L206-L235
27,066
Yoast/yoastcs
Yoast/Sniffs/Files/FileNameSniff.php
FileNameSniff.clean_custom_array_property
protected function clean_custom_array_property( $property, $flip = false, $to_lower = false ) { if ( is_bool( $property ) ) { // Allow for resetting in the unit tests. return array(); } if ( is_string( $property ) ) { $property = explode( ',', $property ); } $property = array_filter( array_map( 'trim', $property ) ); if ( true === $to_lower ) { $property = array_map( 'strtolower', $property ); } if ( true === $flip ) { $property = array_fill_keys( $property, false ); } return $property; }
php
protected function clean_custom_array_property( $property, $flip = false, $to_lower = false ) { if ( is_bool( $property ) ) { // Allow for resetting in the unit tests. return array(); } if ( is_string( $property ) ) { $property = explode( ',', $property ); } $property = array_filter( array_map( 'trim', $property ) ); if ( true === $to_lower ) { $property = array_map( 'strtolower', $property ); } if ( true === $flip ) { $property = array_fill_keys( $property, false ); } return $property; }
[ "protected", "function", "clean_custom_array_property", "(", "$", "property", ",", "$", "flip", "=", "false", ",", "$", "to_lower", "=", "false", ")", "{", "if", "(", "is_bool", "(", "$", "property", ")", ")", "{", "// Allow for resetting in the unit tests.", "return", "array", "(", ")", ";", "}", "if", "(", "is_string", "(", "$", "property", ")", ")", "{", "$", "property", "=", "explode", "(", "','", ",", "$", "property", ")", ";", "}", "$", "property", "=", "array_filter", "(", "array_map", "(", "'trim'", ",", "$", "property", ")", ")", ";", "if", "(", "true", "===", "$", "to_lower", ")", "{", "$", "property", "=", "array_map", "(", "'strtolower'", ",", "$", "property", ")", ";", "}", "if", "(", "true", "===", "$", "flip", ")", "{", "$", "property", "=", "array_fill_keys", "(", "$", "property", ",", "false", ")", ";", "}", "return", "$", "property", ";", "}" ]
Clean a custom array property received from a ruleset. Deals with incorrectly passed custom array properties. - If the property was passed as a string, change it to an array. - Remove whitespace surrounding values. - Remove empty array entries. Optionally flips the array to allow for using `isset` instead of `in_array`. @param mixed $property The current property value. @param bool $flip Whether to flip the array values to keys. @param bool $to_lower Whether to lowercase the array values. @return array
[ "Clean", "a", "custom", "array", "property", "received", "from", "a", "ruleset", "." ]
44d4f28bbcf5f83d1111fafe67a17215b28c87d1
https://github.com/Yoast/yoastcs/blob/44d4f28bbcf5f83d1111fafe67a17215b28c87d1/Yoast/Sniffs/Files/FileNameSniff.php#L253-L274
27,067
Radvance/Radvance
src/Framework/BaseConsoleApplication.php
BaseConsoleApplication.configurePdo
protected function configurePdo() { if (!isset($this['parameters']['pdo'])) { return; } $connector = new Connector(); $this->pdo = $connector->getPdo( $connector->getConfig($this['parameters']['pdo']) ); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this['pdo'] = $this->pdo; }
php
protected function configurePdo() { if (!isset($this['parameters']['pdo'])) { return; } $connector = new Connector(); $this->pdo = $connector->getPdo( $connector->getConfig($this['parameters']['pdo']) ); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this['pdo'] = $this->pdo; }
[ "protected", "function", "configurePdo", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "[", "'parameters'", "]", "[", "'pdo'", "]", ")", ")", "{", "return", ";", "}", "$", "connector", "=", "new", "Connector", "(", ")", ";", "$", "this", "->", "pdo", "=", "$", "connector", "->", "getPdo", "(", "$", "connector", "->", "getConfig", "(", "$", "this", "[", "'parameters'", "]", "[", "'pdo'", "]", ")", ")", ";", "$", "this", "->", "pdo", "->", "setAttribute", "(", "PDO", "::", "ATTR_ERRMODE", ",", "PDO", "::", "ERRMODE_EXCEPTION", ")", ";", "$", "this", "[", "'pdo'", "]", "=", "$", "this", "->", "pdo", ";", "}" ]
Configure PDO.
[ "Configure", "PDO", "." ]
980034dd02da75882089210a25da6d5d74229b2b
https://github.com/Radvance/Radvance/blob/980034dd02da75882089210a25da6d5d74229b2b/src/Framework/BaseConsoleApplication.php#L223-L236
27,068
Radvance/Radvance
src/Framework/BaseConsoleApplication.php
BaseConsoleApplication.configureCache
protected function configureCache() { if (!isset($this['cache'])) { $this['cache'] = [ 'type' => 'array' ]; } if (!isset($this['cache']['type'])) { throw new RuntimeException("cache type not configured correctly"); } switch ($this['cache']['type']) { case 'array': $cache = new \Symfony\Component\Cache\Adapter\ArrayAdapter(); break; case 'filesystem': $directory = $this['cache']['directory']; if (!$directory) { throw new RuntimeException("cache directory not configured (please check doc/cache.md)"); } if (!file_exists($directory)) { mkdir($directory, 0777, true); } $cache = new \Symfony\Component\Cache\Adapter\FilesystemAdapter('', 0, $directory); break; default: throw new RuntimeException("Unsupported cache.type:" . $this['cache']['type']); } $this['cache'] = $cache; }
php
protected function configureCache() { if (!isset($this['cache'])) { $this['cache'] = [ 'type' => 'array' ]; } if (!isset($this['cache']['type'])) { throw new RuntimeException("cache type not configured correctly"); } switch ($this['cache']['type']) { case 'array': $cache = new \Symfony\Component\Cache\Adapter\ArrayAdapter(); break; case 'filesystem': $directory = $this['cache']['directory']; if (!$directory) { throw new RuntimeException("cache directory not configured (please check doc/cache.md)"); } if (!file_exists($directory)) { mkdir($directory, 0777, true); } $cache = new \Symfony\Component\Cache\Adapter\FilesystemAdapter('', 0, $directory); break; default: throw new RuntimeException("Unsupported cache.type:" . $this['cache']['type']); } $this['cache'] = $cache; }
[ "protected", "function", "configureCache", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "[", "'cache'", "]", ")", ")", "{", "$", "this", "[", "'cache'", "]", "=", "[", "'type'", "=>", "'array'", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "[", "'cache'", "]", "[", "'type'", "]", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"cache type not configured correctly\"", ")", ";", "}", "switch", "(", "$", "this", "[", "'cache'", "]", "[", "'type'", "]", ")", "{", "case", "'array'", ":", "$", "cache", "=", "new", "\\", "Symfony", "\\", "Component", "\\", "Cache", "\\", "Adapter", "\\", "ArrayAdapter", "(", ")", ";", "break", ";", "case", "'filesystem'", ":", "$", "directory", "=", "$", "this", "[", "'cache'", "]", "[", "'directory'", "]", ";", "if", "(", "!", "$", "directory", ")", "{", "throw", "new", "RuntimeException", "(", "\"cache directory not configured (please check doc/cache.md)\"", ")", ";", "}", "if", "(", "!", "file_exists", "(", "$", "directory", ")", ")", "{", "mkdir", "(", "$", "directory", ",", "0777", ",", "true", ")", ";", "}", "$", "cache", "=", "new", "\\", "Symfony", "\\", "Component", "\\", "Cache", "\\", "Adapter", "\\", "FilesystemAdapter", "(", "''", ",", "0", ",", "$", "directory", ")", ";", "break", ";", "default", ":", "throw", "new", "RuntimeException", "(", "\"Unsupported cache.type:\"", ".", "$", "this", "[", "'cache'", "]", "[", "'type'", "]", ")", ";", "}", "$", "this", "[", "'cache'", "]", "=", "$", "cache", ";", "}" ]
Configure cache.
[ "Configure", "cache", "." ]
980034dd02da75882089210a25da6d5d74229b2b
https://github.com/Radvance/Radvance/blob/980034dd02da75882089210a25da6d5d74229b2b/src/Framework/BaseConsoleApplication.php#L241-L270
27,069
Radvance/Radvance
src/Framework/BaseConsoleApplication.php
BaseConsoleApplication.configureService
protected function configureService() { // Translations $this['locale_fallbacks'] = array('en_US'); $this->register(new TranslationServiceProvider()); $translator = $this['translator']; $translator->addLoader('yaml', new RecursiveYamlFileMessageLoader()); $files = glob($this->getRootPath() .'/app/l10n/*.yml'); foreach ($files as $filename) { $locale = str_replace('.yml', '', basename($filename)); $translator->addResource('yaml', $filename, $locale); } }
php
protected function configureService() { // Translations $this['locale_fallbacks'] = array('en_US'); $this->register(new TranslationServiceProvider()); $translator = $this['translator']; $translator->addLoader('yaml', new RecursiveYamlFileMessageLoader()); $files = glob($this->getRootPath() .'/app/l10n/*.yml'); foreach ($files as $filename) { $locale = str_replace('.yml', '', basename($filename)); $translator->addResource('yaml', $filename, $locale); } }
[ "protected", "function", "configureService", "(", ")", "{", "// Translations", "$", "this", "[", "'locale_fallbacks'", "]", "=", "array", "(", "'en_US'", ")", ";", "$", "this", "->", "register", "(", "new", "TranslationServiceProvider", "(", ")", ")", ";", "$", "translator", "=", "$", "this", "[", "'translator'", "]", ";", "$", "translator", "->", "addLoader", "(", "'yaml'", ",", "new", "RecursiveYamlFileMessageLoader", "(", ")", ")", ";", "$", "files", "=", "glob", "(", "$", "this", "->", "getRootPath", "(", ")", ".", "'/app/l10n/*.yml'", ")", ";", "foreach", "(", "$", "files", "as", "$", "filename", ")", "{", "$", "locale", "=", "str_replace", "(", "'.yml'", ",", "''", ",", "basename", "(", "$", "filename", ")", ")", ";", "$", "translator", "->", "addResource", "(", "'yaml'", ",", "$", "filename", ",", "$", "locale", ")", ";", "}", "}" ]
Configure services.
[ "Configure", "services", "." ]
980034dd02da75882089210a25da6d5d74229b2b
https://github.com/Radvance/Radvance/blob/980034dd02da75882089210a25da6d5d74229b2b/src/Framework/BaseConsoleApplication.php#L275-L289
27,070
AliyunOpenAPI/php-aliyun-open-api-mns
src/Client.php
Client.createQueue
public function createQueue(CreateQueueRequest $request) { $response = new CreateQueueResponse($request->getQueueName()); return $this->client->sendRequest($request, $response); }
php
public function createQueue(CreateQueueRequest $request) { $response = new CreateQueueResponse($request->getQueueName()); return $this->client->sendRequest($request, $response); }
[ "public", "function", "createQueue", "(", "CreateQueueRequest", "$", "request", ")", "{", "$", "response", "=", "new", "CreateQueueResponse", "(", "$", "request", "->", "getQueueName", "(", ")", ")", ";", "return", "$", "this", "->", "client", "->", "sendRequest", "(", "$", "request", ",", "$", "response", ")", ";", "}" ]
Create Queue and Returns the Queue reference @param CreateQueueRequest $request : the QueueName and QueueAttributes @return CreateQueueResponse $response: the CreateQueueResponse @throws QueueAlreadyExistException if queue already exists @throws InvalidArgumentException if any argument value is invalid @throws MnsException if any other exception happends
[ "Create", "Queue", "and", "Returns", "the", "Queue", "reference" ]
bceb8e02f99cac84f71aad69c8189803333a5f8b
https://github.com/AliyunOpenAPI/php-aliyun-open-api-mns/blob/bceb8e02f99cac84f71aad69c8189803333a5f8b/src/Client.php#L72-L77
27,071
AliyunOpenAPI/php-aliyun-open-api-mns
src/Client.php
Client.listQueue
public function listQueue(ListQueueRequest $request) { $response = new ListQueueResponse(); return $this->client->sendRequest($request, $response); }
php
public function listQueue(ListQueueRequest $request) { $response = new ListQueueResponse(); return $this->client->sendRequest($request, $response); }
[ "public", "function", "listQueue", "(", "ListQueueRequest", "$", "request", ")", "{", "$", "response", "=", "new", "ListQueueResponse", "(", ")", ";", "return", "$", "this", "->", "client", "->", "sendRequest", "(", "$", "request", ",", "$", "response", ")", ";", "}" ]
Query the queues created by current account @param ListQueueRequest $request : define filters for quering queues @return ListQueueResponse: the response containing queueNames
[ "Query", "the", "queues", "created", "by", "current", "account" ]
bceb8e02f99cac84f71aad69c8189803333a5f8b
https://github.com/AliyunOpenAPI/php-aliyun-open-api-mns/blob/bceb8e02f99cac84f71aad69c8189803333a5f8b/src/Client.php#L106-L111
27,072
AliyunOpenAPI/php-aliyun-open-api-mns
src/Client.php
Client.deleteQueue
public function deleteQueue($queueName) { $request = new DeleteQueueRequest($queueName); $response = new DeleteQueueResponse(); return $this->client->sendRequest($request, $response); }
php
public function deleteQueue($queueName) { $request = new DeleteQueueRequest($queueName); $response = new DeleteQueueResponse(); return $this->client->sendRequest($request, $response); }
[ "public", "function", "deleteQueue", "(", "$", "queueName", ")", "{", "$", "request", "=", "new", "DeleteQueueRequest", "(", "$", "queueName", ")", ";", "$", "response", "=", "new", "DeleteQueueResponse", "(", ")", ";", "return", "$", "this", "->", "client", "->", "sendRequest", "(", "$", "request", ",", "$", "response", ")", ";", "}" ]
Delete the specified queue the request will succeed even when the queue does not exist @param $queueName : the queueName @return DeleteQueueResponse
[ "Delete", "the", "specified", "queue", "the", "request", "will", "succeed", "even", "when", "the", "queue", "does", "not", "exist" ]
bceb8e02f99cac84f71aad69c8189803333a5f8b
https://github.com/AliyunOpenAPI/php-aliyun-open-api-mns/blob/bceb8e02f99cac84f71aad69c8189803333a5f8b/src/Client.php#L130-L136
27,073
AliyunOpenAPI/php-aliyun-open-api-mns
src/Client.php
Client.createTopic
public function createTopic(CreateTopicRequest $request) { $response = new CreateTopicResponse($request->getTopicName()); return $this->client->sendRequest($request, $response); }
php
public function createTopic(CreateTopicRequest $request) { $response = new CreateTopicResponse($request->getTopicName()); return $this->client->sendRequest($request, $response); }
[ "public", "function", "createTopic", "(", "CreateTopicRequest", "$", "request", ")", "{", "$", "response", "=", "new", "CreateTopicResponse", "(", "$", "request", "->", "getTopicName", "(", ")", ")", ";", "return", "$", "this", "->", "client", "->", "sendRequest", "(", "$", "request", ",", "$", "response", ")", ";", "}" ]
Create Topic and Returns the Topic reference @param CreateTopicRequest $request : the TopicName and TopicAttributes @return CreateTopicResponse $response: the CreateTopicResponse @throws TopicAlreadyExistException if topic already exists @throws InvalidArgumentException if any argument value is invalid @throws MnsException if any other exception happends
[ "Create", "Topic", "and", "Returns", "the", "Topic", "reference" ]
bceb8e02f99cac84f71aad69c8189803333a5f8b
https://github.com/AliyunOpenAPI/php-aliyun-open-api-mns/blob/bceb8e02f99cac84f71aad69c8189803333a5f8b/src/Client.php#L173-L178
27,074
AliyunOpenAPI/php-aliyun-open-api-mns
src/Client.php
Client.deleteTopic
public function deleteTopic($topicName) { $request = new DeleteTopicRequest($topicName); $response = new DeleteTopicResponse(); return $this->client->sendRequest($request, $response); }
php
public function deleteTopic($topicName) { $request = new DeleteTopicRequest($topicName); $response = new DeleteTopicResponse(); return $this->client->sendRequest($request, $response); }
[ "public", "function", "deleteTopic", "(", "$", "topicName", ")", "{", "$", "request", "=", "new", "DeleteTopicRequest", "(", "$", "topicName", ")", ";", "$", "response", "=", "new", "DeleteTopicResponse", "(", ")", ";", "return", "$", "this", "->", "client", "->", "sendRequest", "(", "$", "request", ",", "$", "response", ")", ";", "}" ]
Delete the specified topic the request will succeed even when the topic does not exist @param $topicName : the topicName @return DeleteTopicResponse
[ "Delete", "the", "specified", "topic", "the", "request", "will", "succeed", "even", "when", "the", "topic", "does", "not", "exist" ]
bceb8e02f99cac84f71aad69c8189803333a5f8b
https://github.com/AliyunOpenAPI/php-aliyun-open-api-mns/blob/bceb8e02f99cac84f71aad69c8189803333a5f8b/src/Client.php#L189-L195
27,075
AliyunOpenAPI/php-aliyun-open-api-mns
src/Client.php
Client.listTopic
public function listTopic(ListTopicRequest $request) { $response = new ListTopicResponse(); return $this->client->sendRequest($request, $response); }
php
public function listTopic(ListTopicRequest $request) { $response = new ListTopicResponse(); return $this->client->sendRequest($request, $response); }
[ "public", "function", "listTopic", "(", "ListTopicRequest", "$", "request", ")", "{", "$", "response", "=", "new", "ListTopicResponse", "(", ")", ";", "return", "$", "this", "->", "client", "->", "sendRequest", "(", "$", "request", ",", "$", "response", ")", ";", "}" ]
Query the topics created by current account @param ListTopicRequest $request : define filters for quering topics @return ListTopicResponse: the response containing topicNames
[ "Query", "the", "topics", "created", "by", "current", "account" ]
bceb8e02f99cac84f71aad69c8189803333a5f8b
https://github.com/AliyunOpenAPI/php-aliyun-open-api-mns/blob/bceb8e02f99cac84f71aad69c8189803333a5f8b/src/Client.php#L205-L210
27,076
AliyunOpenAPI/php-aliyun-open-api-mns
src/Common/XMLParser.php
XMLParser.parseNormalError
static function parseNormalError(\XMLReader $xmlReader) { $result = array( 'Code' => null, 'Message' => null, 'RequestId' => null, 'HostId' => null ); while ($xmlReader->Read()) { if ($xmlReader->nodeType == \XMLReader::ELEMENT) { switch ($xmlReader->name) { case 'Code': $xmlReader->read(); if ($xmlReader->nodeType == \XMLReader::TEXT) { $result['Code'] = $xmlReader->value; } break; case 'Message': $xmlReader->read(); if ($xmlReader->nodeType == \XMLReader::TEXT) { $result['Message'] = $xmlReader->value; } break; case 'RequestId': $xmlReader->read(); if ($xmlReader->nodeType == \XMLReader::TEXT) { $result['RequestId'] = $xmlReader->value; } break; case 'HostId': $xmlReader->read(); if ($xmlReader->nodeType == \XMLReader::TEXT) { $result['HostId'] = $xmlReader->value; } break; } } } return $result; }
php
static function parseNormalError(\XMLReader $xmlReader) { $result = array( 'Code' => null, 'Message' => null, 'RequestId' => null, 'HostId' => null ); while ($xmlReader->Read()) { if ($xmlReader->nodeType == \XMLReader::ELEMENT) { switch ($xmlReader->name) { case 'Code': $xmlReader->read(); if ($xmlReader->nodeType == \XMLReader::TEXT) { $result['Code'] = $xmlReader->value; } break; case 'Message': $xmlReader->read(); if ($xmlReader->nodeType == \XMLReader::TEXT) { $result['Message'] = $xmlReader->value; } break; case 'RequestId': $xmlReader->read(); if ($xmlReader->nodeType == \XMLReader::TEXT) { $result['RequestId'] = $xmlReader->value; } break; case 'HostId': $xmlReader->read(); if ($xmlReader->nodeType == \XMLReader::TEXT) { $result['HostId'] = $xmlReader->value; } break; } } } return $result; }
[ "static", "function", "parseNormalError", "(", "\\", "XMLReader", "$", "xmlReader", ")", "{", "$", "result", "=", "array", "(", "'Code'", "=>", "null", ",", "'Message'", "=>", "null", ",", "'RequestId'", "=>", "null", ",", "'HostId'", "=>", "null", ")", ";", "while", "(", "$", "xmlReader", "->", "Read", "(", ")", ")", "{", "if", "(", "$", "xmlReader", "->", "nodeType", "==", "\\", "XMLReader", "::", "ELEMENT", ")", "{", "switch", "(", "$", "xmlReader", "->", "name", ")", "{", "case", "'Code'", ":", "$", "xmlReader", "->", "read", "(", ")", ";", "if", "(", "$", "xmlReader", "->", "nodeType", "==", "\\", "XMLReader", "::", "TEXT", ")", "{", "$", "result", "[", "'Code'", "]", "=", "$", "xmlReader", "->", "value", ";", "}", "break", ";", "case", "'Message'", ":", "$", "xmlReader", "->", "read", "(", ")", ";", "if", "(", "$", "xmlReader", "->", "nodeType", "==", "\\", "XMLReader", "::", "TEXT", ")", "{", "$", "result", "[", "'Message'", "]", "=", "$", "xmlReader", "->", "value", ";", "}", "break", ";", "case", "'RequestId'", ":", "$", "xmlReader", "->", "read", "(", ")", ";", "if", "(", "$", "xmlReader", "->", "nodeType", "==", "\\", "XMLReader", "::", "TEXT", ")", "{", "$", "result", "[", "'RequestId'", "]", "=", "$", "xmlReader", "->", "value", ";", "}", "break", ";", "case", "'HostId'", ":", "$", "xmlReader", "->", "read", "(", ")", ";", "if", "(", "$", "xmlReader", "->", "nodeType", "==", "\\", "XMLReader", "::", "TEXT", ")", "{", "$", "result", "[", "'HostId'", "]", "=", "$", "xmlReader", "->", "value", ";", "}", "break", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
Most of the error responses are in same format.
[ "Most", "of", "the", "error", "responses", "are", "in", "same", "format", "." ]
bceb8e02f99cac84f71aad69c8189803333a5f8b
https://github.com/AliyunOpenAPI/php-aliyun-open-api-mns/blob/bceb8e02f99cac84f71aad69c8189803333a5f8b/src/Common/XMLParser.php#L11-L46
27,077
vanilla/garden-container
src/Container.php
Container.arrayClone
private function arrayClone(array $array) { return array_map(function ($element) { return ((is_array($element)) ? $this->arrayClone($element) : ((is_object($element)) ? clone $element : $element ) ); }, $array); }
php
private function arrayClone(array $array) { return array_map(function ($element) { return ((is_array($element)) ? $this->arrayClone($element) : ((is_object($element)) ? clone $element : $element ) ); }, $array); }
[ "private", "function", "arrayClone", "(", "array", "$", "array", ")", "{", "return", "array_map", "(", "function", "(", "$", "element", ")", "{", "return", "(", "(", "is_array", "(", "$", "element", ")", ")", "?", "$", "this", "->", "arrayClone", "(", "$", "element", ")", ":", "(", "(", "is_object", "(", "$", "element", ")", ")", "?", "clone", "$", "element", ":", "$", "element", ")", ")", ";", "}", ",", "$", "array", ")", ";", "}" ]
Deep clone an array. @param array $array The array to clone. @return array Returns the cloned array. @see http://stackoverflow.com/a/17729234
[ "Deep", "clone", "an", "array", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L56-L66
27,078
vanilla/garden-container
src/Container.php
Container.rule
public function rule($id) { $id = $this->normalizeID($id); if (!isset($this->rules[$id])) { $this->rules[$id] = []; } $this->currentRuleName = $id; $this->currentRule = &$this->rules[$id]; return $this; }
php
public function rule($id) { $id = $this->normalizeID($id); if (!isset($this->rules[$id])) { $this->rules[$id] = []; } $this->currentRuleName = $id; $this->currentRule = &$this->rules[$id]; return $this; }
[ "public", "function", "rule", "(", "$", "id", ")", "{", "$", "id", "=", "$", "this", "->", "normalizeID", "(", "$", "id", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "rules", "[", "$", "id", "]", ")", ")", "{", "$", "this", "->", "rules", "[", "$", "id", "]", "=", "[", "]", ";", "}", "$", "this", "->", "currentRuleName", "=", "$", "id", ";", "$", "this", "->", "currentRule", "=", "&", "$", "this", "->", "rules", "[", "$", "id", "]", ";", "return", "$", "this", ";", "}" ]
Set the current rule. @param string $id The ID of the rule. @return $this
[ "Set", "the", "current", "rule", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L93-L103
27,079
vanilla/garden-container
src/Container.php
Container.setAliasOf
public function setAliasOf($alias) { $alias = $this->normalizeID($alias); if ($alias === $this->currentRuleName) { trigger_error("You cannot set alias '$alias' to itself.", E_USER_NOTICE); } else { $this->currentRule['aliasOf'] = $alias; } return $this; }
php
public function setAliasOf($alias) { $alias = $this->normalizeID($alias); if ($alias === $this->currentRuleName) { trigger_error("You cannot set alias '$alias' to itself.", E_USER_NOTICE); } else { $this->currentRule['aliasOf'] = $alias; } return $this; }
[ "public", "function", "setAliasOf", "(", "$", "alias", ")", "{", "$", "alias", "=", "$", "this", "->", "normalizeID", "(", "$", "alias", ")", ";", "if", "(", "$", "alias", "===", "$", "this", "->", "currentRuleName", ")", "{", "trigger_error", "(", "\"You cannot set alias '$alias' to itself.\"", ",", "E_USER_NOTICE", ")", ";", "}", "else", "{", "$", "this", "->", "currentRule", "[", "'aliasOf'", "]", "=", "$", "alias", ";", "}", "return", "$", "this", ";", "}" ]
Set the rule that the current rule is an alias of. @param string $alias The name of an entry in the container to point to. @return $this
[ "Set", "the", "rule", "that", "the", "current", "rule", "is", "an", "alias", "of", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L140-L149
27,080
vanilla/garden-container
src/Container.php
Container.addAlias
public function addAlias(...$alias) { foreach ($alias as $name) { $name = $this->normalizeID($name); if ($name === $this->currentRuleName) { trigger_error("Tried to set alias '$name' to self.", E_USER_NOTICE); } else { $this->rules[$name]['aliasOf'] = $this->currentRuleName; } } return $this; }
php
public function addAlias(...$alias) { foreach ($alias as $name) { $name = $this->normalizeID($name); if ($name === $this->currentRuleName) { trigger_error("Tried to set alias '$name' to self.", E_USER_NOTICE); } else { $this->rules[$name]['aliasOf'] = $this->currentRuleName; } } return $this; }
[ "public", "function", "addAlias", "(", "...", "$", "alias", ")", "{", "foreach", "(", "$", "alias", "as", "$", "name", ")", "{", "$", "name", "=", "$", "this", "->", "normalizeID", "(", "$", "name", ")", ";", "if", "(", "$", "name", "===", "$", "this", "->", "currentRuleName", ")", "{", "trigger_error", "(", "\"Tried to set alias '$name' to self.\"", ",", "E_USER_NOTICE", ")", ";", "}", "else", "{", "$", "this", "->", "rules", "[", "$", "name", "]", "[", "'aliasOf'", "]", "=", "$", "this", "->", "currentRuleName", ";", "}", "}", "return", "$", "this", ";", "}" ]
Add an alias of the current rule. Setting an alias to the current rule means that getting an item with the alias' name will be like getting the item with the current rule. If the current rule is shared then the same shared instance will be returned. You can add multiple aliases by passing additional arguments to this method. If {@link Container::addAlias()} is called with an alias that is the same as the current rule then an **E_USER_NOTICE** level error is raised and the alias is not added. @param string ...$alias The alias to set. @return $this @since 1.4 Added the ability to pass multiple aliases.
[ "Add", "an", "alias", "of", "the", "current", "rule", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L165-L176
27,081
vanilla/garden-container
src/Container.php
Container.removeAlias
public function removeAlias($alias) { $alias = $this->normalizeID($alias); if (!empty($this->rules[$alias]['aliasOf']) && $this->rules[$alias]['aliasOf'] !== $this->currentRuleName) { trigger_error("Alias '$alias' does not point to the current rule.", E_USER_NOTICE); } unset($this->rules[$alias]['aliasOf']); return $this; }
php
public function removeAlias($alias) { $alias = $this->normalizeID($alias); if (!empty($this->rules[$alias]['aliasOf']) && $this->rules[$alias]['aliasOf'] !== $this->currentRuleName) { trigger_error("Alias '$alias' does not point to the current rule.", E_USER_NOTICE); } unset($this->rules[$alias]['aliasOf']); return $this; }
[ "public", "function", "removeAlias", "(", "$", "alias", ")", "{", "$", "alias", "=", "$", "this", "->", "normalizeID", "(", "$", "alias", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "rules", "[", "$", "alias", "]", "[", "'aliasOf'", "]", ")", "&&", "$", "this", "->", "rules", "[", "$", "alias", "]", "[", "'aliasOf'", "]", "!==", "$", "this", "->", "currentRuleName", ")", "{", "trigger_error", "(", "\"Alias '$alias' does not point to the current rule.\"", ",", "E_USER_NOTICE", ")", ";", "}", "unset", "(", "$", "this", "->", "rules", "[", "$", "alias", "]", "[", "'aliasOf'", "]", ")", ";", "return", "$", "this", ";", "}" ]
Remove an alias of the current rule. If {@link Container::removeAlias()} is called with an alias that references a different rule then an **E_USER_NOTICE** level error is raised, but the alias is still removed. @param string $alias The alias to remove. @return $this
[ "Remove", "an", "alias", "of", "the", "current", "rule", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L187-L196
27,082
vanilla/garden-container
src/Container.php
Container.getAliases
public function getAliases() { $result = []; foreach ($this->rules as $name => $rule) { if (!empty($rule['aliasOf']) && $rule['aliasOf'] === $this->currentRuleName) { $result[] = $name; } } return $result; }
php
public function getAliases() { $result = []; foreach ($this->rules as $name => $rule) { if (!empty($rule['aliasOf']) && $rule['aliasOf'] === $this->currentRuleName) { $result[] = $name; } } return $result; }
[ "public", "function", "getAliases", "(", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "rules", "as", "$", "name", "=>", "$", "rule", ")", "{", "if", "(", "!", "empty", "(", "$", "rule", "[", "'aliasOf'", "]", ")", "&&", "$", "rule", "[", "'aliasOf'", "]", "===", "$", "this", "->", "currentRuleName", ")", "{", "$", "result", "[", "]", "=", "$", "name", ";", "}", "}", "return", "$", "result", ";", "}" ]
Get all of the aliases of the current rule. This method is intended to aid in debugging and should not be used in production as it walks the entire rule array. @return array Returns an array of strings representing aliases.
[ "Get", "all", "of", "the", "aliases", "of", "the", "current", "rule", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L205-L215
27,083
vanilla/garden-container
src/Container.php
Container.setInstance
public function setInstance($name, $instance) { $this->instances[$this->normalizeID($name)] = $instance; return $this; }
php
public function setInstance($name, $instance) { $this->instances[$this->normalizeID($name)] = $instance; return $this; }
[ "public", "function", "setInstance", "(", "$", "name", ",", "$", "instance", ")", "{", "$", "this", "->", "instances", "[", "$", "this", "->", "normalizeID", "(", "$", "name", ")", "]", "=", "$", "instance", ";", "return", "$", "this", ";", "}" ]
Set a specific shared instance into the container. When you set an instance into the container then it will always be returned by subsequent retrievals, even if a rule is configured that says that instances should not be shared. @param string $name The name of the container entry. @param mixed $instance This instance. @return $this
[ "Set", "a", "specific", "shared", "instance", "into", "the", "container", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L307-L310
27,084
vanilla/garden-container
src/Container.php
Container.makeRule
private function makeRule($nid) { $rule = isset($this->rules[$nid]) ? $this->rules[$nid] : []; if (class_exists($nid)) { for ($class = get_parent_class($nid); !empty($class); $class = get_parent_class($class)) { // Don't add the rule if it doesn't say to inherit. if (!isset($this->rules[$class]) || (isset($this->rules[$class]['inherit']) && !$this->rules[$class]['inherit'])) { break; } $rule += $this->rules[$class]; } // Add the default rule. if (!empty($this->rules['*']['inherit'])) { $rule += $this->rules['*']; } // Add interface calls to the rule. $interfaces = class_implements($nid); foreach ($interfaces as $interface) { if (isset($this->rules[$interface])) { $interfaceRule = $this->rules[$interface]; if (isset($interfaceRule['inherit']) && $interfaceRule['inherit'] === false) { continue; } if (!isset($rule['shared']) && isset($interfaceRule['shared'])) { $rule['shared'] = $interfaceRule['shared']; } if (!isset($rule['constructorArgs']) && isset($interfaceRule['constructorArgs'])) { $rule['constructorArgs'] = $interfaceRule['constructorArgs']; } if (!empty($interfaceRule['calls'])) { $rule['calls'] = array_merge( isset($rule['calls']) ? $rule['calls'] : [], $interfaceRule['calls'] ); } } } } elseif (!empty($this->rules['*']['inherit'])) { // Add the default rule. $rule += $this->rules['*']; } return $rule; }
php
private function makeRule($nid) { $rule = isset($this->rules[$nid]) ? $this->rules[$nid] : []; if (class_exists($nid)) { for ($class = get_parent_class($nid); !empty($class); $class = get_parent_class($class)) { // Don't add the rule if it doesn't say to inherit. if (!isset($this->rules[$class]) || (isset($this->rules[$class]['inherit']) && !$this->rules[$class]['inherit'])) { break; } $rule += $this->rules[$class]; } // Add the default rule. if (!empty($this->rules['*']['inherit'])) { $rule += $this->rules['*']; } // Add interface calls to the rule. $interfaces = class_implements($nid); foreach ($interfaces as $interface) { if (isset($this->rules[$interface])) { $interfaceRule = $this->rules[$interface]; if (isset($interfaceRule['inherit']) && $interfaceRule['inherit'] === false) { continue; } if (!isset($rule['shared']) && isset($interfaceRule['shared'])) { $rule['shared'] = $interfaceRule['shared']; } if (!isset($rule['constructorArgs']) && isset($interfaceRule['constructorArgs'])) { $rule['constructorArgs'] = $interfaceRule['constructorArgs']; } if (!empty($interfaceRule['calls'])) { $rule['calls'] = array_merge( isset($rule['calls']) ? $rule['calls'] : [], $interfaceRule['calls'] ); } } } } elseif (!empty($this->rules['*']['inherit'])) { // Add the default rule. $rule += $this->rules['*']; } return $rule; }
[ "private", "function", "makeRule", "(", "$", "nid", ")", "{", "$", "rule", "=", "isset", "(", "$", "this", "->", "rules", "[", "$", "nid", "]", ")", "?", "$", "this", "->", "rules", "[", "$", "nid", "]", ":", "[", "]", ";", "if", "(", "class_exists", "(", "$", "nid", ")", ")", "{", "for", "(", "$", "class", "=", "get_parent_class", "(", "$", "nid", ")", ";", "!", "empty", "(", "$", "class", ")", ";", "$", "class", "=", "get_parent_class", "(", "$", "class", ")", ")", "{", "// Don't add the rule if it doesn't say to inherit.", "if", "(", "!", "isset", "(", "$", "this", "->", "rules", "[", "$", "class", "]", ")", "||", "(", "isset", "(", "$", "this", "->", "rules", "[", "$", "class", "]", "[", "'inherit'", "]", ")", "&&", "!", "$", "this", "->", "rules", "[", "$", "class", "]", "[", "'inherit'", "]", ")", ")", "{", "break", ";", "}", "$", "rule", "+=", "$", "this", "->", "rules", "[", "$", "class", "]", ";", "}", "// Add the default rule.", "if", "(", "!", "empty", "(", "$", "this", "->", "rules", "[", "'*'", "]", "[", "'inherit'", "]", ")", ")", "{", "$", "rule", "+=", "$", "this", "->", "rules", "[", "'*'", "]", ";", "}", "// Add interface calls to the rule.", "$", "interfaces", "=", "class_implements", "(", "$", "nid", ")", ";", "foreach", "(", "$", "interfaces", "as", "$", "interface", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "rules", "[", "$", "interface", "]", ")", ")", "{", "$", "interfaceRule", "=", "$", "this", "->", "rules", "[", "$", "interface", "]", ";", "if", "(", "isset", "(", "$", "interfaceRule", "[", "'inherit'", "]", ")", "&&", "$", "interfaceRule", "[", "'inherit'", "]", "===", "false", ")", "{", "continue", ";", "}", "if", "(", "!", "isset", "(", "$", "rule", "[", "'shared'", "]", ")", "&&", "isset", "(", "$", "interfaceRule", "[", "'shared'", "]", ")", ")", "{", "$", "rule", "[", "'shared'", "]", "=", "$", "interfaceRule", "[", "'shared'", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "rule", "[", "'constructorArgs'", "]", ")", "&&", "isset", "(", "$", "interfaceRule", "[", "'constructorArgs'", "]", ")", ")", "{", "$", "rule", "[", "'constructorArgs'", "]", "=", "$", "interfaceRule", "[", "'constructorArgs'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "interfaceRule", "[", "'calls'", "]", ")", ")", "{", "$", "rule", "[", "'calls'", "]", "=", "array_merge", "(", "isset", "(", "$", "rule", "[", "'calls'", "]", ")", "?", "$", "rule", "[", "'calls'", "]", ":", "[", "]", ",", "$", "interfaceRule", "[", "'calls'", "]", ")", ";", "}", "}", "}", "}", "elseif", "(", "!", "empty", "(", "$", "this", "->", "rules", "[", "'*'", "]", "[", "'inherit'", "]", ")", ")", "{", "// Add the default rule.", "$", "rule", "+=", "$", "this", "->", "rules", "[", "'*'", "]", ";", "}", "return", "$", "rule", ";", "}" ]
Make a rule based on an ID. @param string $nid A normalized ID. @return array Returns an array representing a rule.
[ "Make", "a", "rule", "based", "on", "an", "ID", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L365-L414
27,085
vanilla/garden-container
src/Container.php
Container.makeFactory
private function makeFactory($nid, array $rule) { $className = empty($rule['class']) ? $nid : $rule['class']; if (!empty($rule['factory'])) { // The instance is created with a user-supplied factory function. $callback = $rule['factory']; $function = $this->reflectCallback($callback); if ($function->getNumberOfParameters() > 0) { $callbackArgs = $this->makeDefaultArgs($function, (array)$rule['constructorArgs']); $factory = function ($args) use ($callback, $callbackArgs) { return call_user_func_array($callback, $this->resolveArgs($callbackArgs, $args)); }; } else { $factory = $callback; } // If a class is specified then still reflect on it so that calls can be made against it. if (class_exists($className)) { $class = new \ReflectionClass($className); } } else { // The instance is created by newing up a class. if (!class_exists($className)) { throw new NotFoundException("Class $className does not exist.", 404); } $class = new \ReflectionClass($className); $constructor = $class->getConstructor(); if ($constructor && $constructor->getNumberOfParameters() > 0) { $constructorArgs = $this->makeDefaultArgs($constructor, (array)$rule['constructorArgs']); $factory = function ($args) use ($className, $constructorArgs) { return new $className(...array_values($this->resolveArgs($constructorArgs, $args))); }; } else { $factory = function () use ($className) { return new $className; }; } } // Add calls to the factory. if (isset($class) && !empty($rule['calls'])) { $calls = []; // Generate the calls array. foreach ($rule['calls'] as $call) { list($methodName, $args) = $call; $method = $class->getMethod($methodName); $calls[] = [$methodName, $this->makeDefaultArgs($method, $args)]; } // Wrap the factory in one that makes the calls. $factory = function ($args) use ($factory, $calls) { $instance = $factory($args); foreach ($calls as $call) { call_user_func_array( [$instance, $call[0]], $this->resolveArgs($call[1], [], $instance) ); } return $instance; }; } return $factory; }
php
private function makeFactory($nid, array $rule) { $className = empty($rule['class']) ? $nid : $rule['class']; if (!empty($rule['factory'])) { // The instance is created with a user-supplied factory function. $callback = $rule['factory']; $function = $this->reflectCallback($callback); if ($function->getNumberOfParameters() > 0) { $callbackArgs = $this->makeDefaultArgs($function, (array)$rule['constructorArgs']); $factory = function ($args) use ($callback, $callbackArgs) { return call_user_func_array($callback, $this->resolveArgs($callbackArgs, $args)); }; } else { $factory = $callback; } // If a class is specified then still reflect on it so that calls can be made against it. if (class_exists($className)) { $class = new \ReflectionClass($className); } } else { // The instance is created by newing up a class. if (!class_exists($className)) { throw new NotFoundException("Class $className does not exist.", 404); } $class = new \ReflectionClass($className); $constructor = $class->getConstructor(); if ($constructor && $constructor->getNumberOfParameters() > 0) { $constructorArgs = $this->makeDefaultArgs($constructor, (array)$rule['constructorArgs']); $factory = function ($args) use ($className, $constructorArgs) { return new $className(...array_values($this->resolveArgs($constructorArgs, $args))); }; } else { $factory = function () use ($className) { return new $className; }; } } // Add calls to the factory. if (isset($class) && !empty($rule['calls'])) { $calls = []; // Generate the calls array. foreach ($rule['calls'] as $call) { list($methodName, $args) = $call; $method = $class->getMethod($methodName); $calls[] = [$methodName, $this->makeDefaultArgs($method, $args)]; } // Wrap the factory in one that makes the calls. $factory = function ($args) use ($factory, $calls) { $instance = $factory($args); foreach ($calls as $call) { call_user_func_array( [$instance, $call[0]], $this->resolveArgs($call[1], [], $instance) ); } return $instance; }; } return $factory; }
[ "private", "function", "makeFactory", "(", "$", "nid", ",", "array", "$", "rule", ")", "{", "$", "className", "=", "empty", "(", "$", "rule", "[", "'class'", "]", ")", "?", "$", "nid", ":", "$", "rule", "[", "'class'", "]", ";", "if", "(", "!", "empty", "(", "$", "rule", "[", "'factory'", "]", ")", ")", "{", "// The instance is created with a user-supplied factory function.", "$", "callback", "=", "$", "rule", "[", "'factory'", "]", ";", "$", "function", "=", "$", "this", "->", "reflectCallback", "(", "$", "callback", ")", ";", "if", "(", "$", "function", "->", "getNumberOfParameters", "(", ")", ">", "0", ")", "{", "$", "callbackArgs", "=", "$", "this", "->", "makeDefaultArgs", "(", "$", "function", ",", "(", "array", ")", "$", "rule", "[", "'constructorArgs'", "]", ")", ";", "$", "factory", "=", "function", "(", "$", "args", ")", "use", "(", "$", "callback", ",", "$", "callbackArgs", ")", "{", "return", "call_user_func_array", "(", "$", "callback", ",", "$", "this", "->", "resolveArgs", "(", "$", "callbackArgs", ",", "$", "args", ")", ")", ";", "}", ";", "}", "else", "{", "$", "factory", "=", "$", "callback", ";", "}", "// If a class is specified then still reflect on it so that calls can be made against it.", "if", "(", "class_exists", "(", "$", "className", ")", ")", "{", "$", "class", "=", "new", "\\", "ReflectionClass", "(", "$", "className", ")", ";", "}", "}", "else", "{", "// The instance is created by newing up a class.", "if", "(", "!", "class_exists", "(", "$", "className", ")", ")", "{", "throw", "new", "NotFoundException", "(", "\"Class $className does not exist.\"", ",", "404", ")", ";", "}", "$", "class", "=", "new", "\\", "ReflectionClass", "(", "$", "className", ")", ";", "$", "constructor", "=", "$", "class", "->", "getConstructor", "(", ")", ";", "if", "(", "$", "constructor", "&&", "$", "constructor", "->", "getNumberOfParameters", "(", ")", ">", "0", ")", "{", "$", "constructorArgs", "=", "$", "this", "->", "makeDefaultArgs", "(", "$", "constructor", ",", "(", "array", ")", "$", "rule", "[", "'constructorArgs'", "]", ")", ";", "$", "factory", "=", "function", "(", "$", "args", ")", "use", "(", "$", "className", ",", "$", "constructorArgs", ")", "{", "return", "new", "$", "className", "(", "...", "array_values", "(", "$", "this", "->", "resolveArgs", "(", "$", "constructorArgs", ",", "$", "args", ")", ")", ")", ";", "}", ";", "}", "else", "{", "$", "factory", "=", "function", "(", ")", "use", "(", "$", "className", ")", "{", "return", "new", "$", "className", ";", "}", ";", "}", "}", "// Add calls to the factory.", "if", "(", "isset", "(", "$", "class", ")", "&&", "!", "empty", "(", "$", "rule", "[", "'calls'", "]", ")", ")", "{", "$", "calls", "=", "[", "]", ";", "// Generate the calls array.", "foreach", "(", "$", "rule", "[", "'calls'", "]", "as", "$", "call", ")", "{", "list", "(", "$", "methodName", ",", "$", "args", ")", "=", "$", "call", ";", "$", "method", "=", "$", "class", "->", "getMethod", "(", "$", "methodName", ")", ";", "$", "calls", "[", "]", "=", "[", "$", "methodName", ",", "$", "this", "->", "makeDefaultArgs", "(", "$", "method", ",", "$", "args", ")", "]", ";", "}", "// Wrap the factory in one that makes the calls.", "$", "factory", "=", "function", "(", "$", "args", ")", "use", "(", "$", "factory", ",", "$", "calls", ")", "{", "$", "instance", "=", "$", "factory", "(", "$", "args", ")", ";", "foreach", "(", "$", "calls", "as", "$", "call", ")", "{", "call_user_func_array", "(", "[", "$", "instance", ",", "$", "call", "[", "0", "]", "]", ",", "$", "this", "->", "resolveArgs", "(", "$", "call", "[", "1", "]", ",", "[", "]", ",", "$", "instance", ")", ")", ";", "}", "return", "$", "instance", ";", "}", ";", "}", "return", "$", "factory", ";", "}" ]
Make a function that creates objects from a rule. @param string $nid The normalized ID of the container item. @param array $rule The resolved rule for the ID. @return \Closure Returns a function that when called will create a new instance of the class. @throws NotFoundException No entry was found for this identifier.
[ "Make", "a", "function", "that", "creates", "objects", "from", "a", "rule", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L424-L493
27,086
vanilla/garden-container
src/Container.php
Container.createSharedInstance
private function createSharedInstance($nid, array $rule, array $args) { if (!empty($rule['factory'])) { // The instance is created with a user-supplied factory function. $callback = $rule['factory']; $function = $this->reflectCallback($callback); if ($function->getNumberOfParameters() > 0) { $callbackArgs = $this->resolveArgs( $this->makeDefaultArgs($function, (array)$rule['constructorArgs']), $args ); $this->instances[$nid] = null; // prevent cyclic dependency from infinite loop. $this->instances[$nid] = $instance = call_user_func_array($callback, $callbackArgs); } else { $this->instances[$nid] = $instance = $callback(); } // Reflect on the instance so that calls can be made against it. if (is_object($instance)) { $class = new \ReflectionClass(get_class($instance)); } } else { $className = empty($rule['class']) ? $nid : $rule['class']; if (!class_exists($className)) { throw new NotFoundException("Class $className does not exist.", 404); } $class = new \ReflectionClass($className); $constructor = $class->getConstructor(); if ($constructor && $constructor->getNumberOfParameters() > 0) { // Instantiate the object first so that this instance can be used for cyclic dependencies. $this->instances[$nid] = $instance = $class->newInstanceWithoutConstructor(); $constructorArgs = $this->resolveArgs( $this->makeDefaultArgs($constructor, (array)$rule['constructorArgs'], $rule), $args ); $constructor->invokeArgs($instance, $constructorArgs); } else { $this->instances[$nid] = $instance = new $class->name; } } // Call subsequent calls on the new object. if (isset($class) && !empty($rule['calls'])) { foreach ($rule['calls'] as $call) { list($methodName, $args) = $call; $method = $class->getMethod($methodName); $args = $this->resolveArgs( $this->makeDefaultArgs($method, $args, $rule), [], $instance ); $method->invokeArgs($instance, $args); } } return $instance; }
php
private function createSharedInstance($nid, array $rule, array $args) { if (!empty($rule['factory'])) { // The instance is created with a user-supplied factory function. $callback = $rule['factory']; $function = $this->reflectCallback($callback); if ($function->getNumberOfParameters() > 0) { $callbackArgs = $this->resolveArgs( $this->makeDefaultArgs($function, (array)$rule['constructorArgs']), $args ); $this->instances[$nid] = null; // prevent cyclic dependency from infinite loop. $this->instances[$nid] = $instance = call_user_func_array($callback, $callbackArgs); } else { $this->instances[$nid] = $instance = $callback(); } // Reflect on the instance so that calls can be made against it. if (is_object($instance)) { $class = new \ReflectionClass(get_class($instance)); } } else { $className = empty($rule['class']) ? $nid : $rule['class']; if (!class_exists($className)) { throw new NotFoundException("Class $className does not exist.", 404); } $class = new \ReflectionClass($className); $constructor = $class->getConstructor(); if ($constructor && $constructor->getNumberOfParameters() > 0) { // Instantiate the object first so that this instance can be used for cyclic dependencies. $this->instances[$nid] = $instance = $class->newInstanceWithoutConstructor(); $constructorArgs = $this->resolveArgs( $this->makeDefaultArgs($constructor, (array)$rule['constructorArgs'], $rule), $args ); $constructor->invokeArgs($instance, $constructorArgs); } else { $this->instances[$nid] = $instance = new $class->name; } } // Call subsequent calls on the new object. if (isset($class) && !empty($rule['calls'])) { foreach ($rule['calls'] as $call) { list($methodName, $args) = $call; $method = $class->getMethod($methodName); $args = $this->resolveArgs( $this->makeDefaultArgs($method, $args, $rule), [], $instance ); $method->invokeArgs($instance, $args); } } return $instance; }
[ "private", "function", "createSharedInstance", "(", "$", "nid", ",", "array", "$", "rule", ",", "array", "$", "args", ")", "{", "if", "(", "!", "empty", "(", "$", "rule", "[", "'factory'", "]", ")", ")", "{", "// The instance is created with a user-supplied factory function.", "$", "callback", "=", "$", "rule", "[", "'factory'", "]", ";", "$", "function", "=", "$", "this", "->", "reflectCallback", "(", "$", "callback", ")", ";", "if", "(", "$", "function", "->", "getNumberOfParameters", "(", ")", ">", "0", ")", "{", "$", "callbackArgs", "=", "$", "this", "->", "resolveArgs", "(", "$", "this", "->", "makeDefaultArgs", "(", "$", "function", ",", "(", "array", ")", "$", "rule", "[", "'constructorArgs'", "]", ")", ",", "$", "args", ")", ";", "$", "this", "->", "instances", "[", "$", "nid", "]", "=", "null", ";", "// prevent cyclic dependency from infinite loop.", "$", "this", "->", "instances", "[", "$", "nid", "]", "=", "$", "instance", "=", "call_user_func_array", "(", "$", "callback", ",", "$", "callbackArgs", ")", ";", "}", "else", "{", "$", "this", "->", "instances", "[", "$", "nid", "]", "=", "$", "instance", "=", "$", "callback", "(", ")", ";", "}", "// Reflect on the instance so that calls can be made against it.", "if", "(", "is_object", "(", "$", "instance", ")", ")", "{", "$", "class", "=", "new", "\\", "ReflectionClass", "(", "get_class", "(", "$", "instance", ")", ")", ";", "}", "}", "else", "{", "$", "className", "=", "empty", "(", "$", "rule", "[", "'class'", "]", ")", "?", "$", "nid", ":", "$", "rule", "[", "'class'", "]", ";", "if", "(", "!", "class_exists", "(", "$", "className", ")", ")", "{", "throw", "new", "NotFoundException", "(", "\"Class $className does not exist.\"", ",", "404", ")", ";", "}", "$", "class", "=", "new", "\\", "ReflectionClass", "(", "$", "className", ")", ";", "$", "constructor", "=", "$", "class", "->", "getConstructor", "(", ")", ";", "if", "(", "$", "constructor", "&&", "$", "constructor", "->", "getNumberOfParameters", "(", ")", ">", "0", ")", "{", "// Instantiate the object first so that this instance can be used for cyclic dependencies.", "$", "this", "->", "instances", "[", "$", "nid", "]", "=", "$", "instance", "=", "$", "class", "->", "newInstanceWithoutConstructor", "(", ")", ";", "$", "constructorArgs", "=", "$", "this", "->", "resolveArgs", "(", "$", "this", "->", "makeDefaultArgs", "(", "$", "constructor", ",", "(", "array", ")", "$", "rule", "[", "'constructorArgs'", "]", ",", "$", "rule", ")", ",", "$", "args", ")", ";", "$", "constructor", "->", "invokeArgs", "(", "$", "instance", ",", "$", "constructorArgs", ")", ";", "}", "else", "{", "$", "this", "->", "instances", "[", "$", "nid", "]", "=", "$", "instance", "=", "new", "$", "class", "->", "name", ";", "}", "}", "// Call subsequent calls on the new object.", "if", "(", "isset", "(", "$", "class", ")", "&&", "!", "empty", "(", "$", "rule", "[", "'calls'", "]", ")", ")", "{", "foreach", "(", "$", "rule", "[", "'calls'", "]", "as", "$", "call", ")", "{", "list", "(", "$", "methodName", ",", "$", "args", ")", "=", "$", "call", ";", "$", "method", "=", "$", "class", "->", "getMethod", "(", "$", "methodName", ")", ";", "$", "args", "=", "$", "this", "->", "resolveArgs", "(", "$", "this", "->", "makeDefaultArgs", "(", "$", "method", ",", "$", "args", ",", "$", "rule", ")", ",", "[", "]", ",", "$", "instance", ")", ";", "$", "method", "->", "invokeArgs", "(", "$", "instance", ",", "$", "args", ")", ";", "}", "}", "return", "$", "instance", ";", "}" ]
Create a shared instance of a class from a rule. This method has the side effect of adding the new instance to the internal instances array of this object. @param string $nid The normalized ID of the container item. @param array $rule The resolved rule for the ID. @param array $args Additional arguments passed during creation. @return object Returns the the new instance. @throws NotFoundException Throws an exception if the class does not exist.
[ "Create", "a", "shared", "instance", "of", "a", "class", "from", "a", "rule", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L506-L567
27,087
vanilla/garden-container
src/Container.php
Container.findRuleClass
private function findRuleClass($nid) { if (!isset($this->rules[$nid])) { return null; } elseif (!empty($this->rules[$nid]['aliasOf'])) { return $this->findRuleClass($this->rules[$nid]['aliasOf']); } elseif (!empty($this->rules[$nid]['class'])) { return $this->rules[$nid]['class']; } return null; }
php
private function findRuleClass($nid) { if (!isset($this->rules[$nid])) { return null; } elseif (!empty($this->rules[$nid]['aliasOf'])) { return $this->findRuleClass($this->rules[$nid]['aliasOf']); } elseif (!empty($this->rules[$nid]['class'])) { return $this->rules[$nid]['class']; } return null; }
[ "private", "function", "findRuleClass", "(", "$", "nid", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "rules", "[", "$", "nid", "]", ")", ")", "{", "return", "null", ";", "}", "elseif", "(", "!", "empty", "(", "$", "this", "->", "rules", "[", "$", "nid", "]", "[", "'aliasOf'", "]", ")", ")", "{", "return", "$", "this", "->", "findRuleClass", "(", "$", "this", "->", "rules", "[", "$", "nid", "]", "[", "'aliasOf'", "]", ")", ";", "}", "elseif", "(", "!", "empty", "(", "$", "this", "->", "rules", "[", "$", "nid", "]", "[", "'class'", "]", ")", ")", "{", "return", "$", "this", "->", "rules", "[", "$", "nid", "]", "[", "'class'", "]", ";", "}", "return", "null", ";", "}" ]
Find the class implemented by an ID. This tries to see if a rule exists for a normalized ID and what class it evaluates to. @param string $nid The normalized ID to look up. @return string|null Returns the name of the class associated with the rule or **null** if one could not be found.
[ "Find", "the", "class", "implemented", "by", "an", "ID", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L578-L588
27,088
vanilla/garden-container
src/Container.php
Container.makeDefaultArgs
private function makeDefaultArgs(\ReflectionFunctionAbstract $function, array $ruleArgs) { $ruleArgs = array_change_key_case($ruleArgs); $result = []; $pos = 0; foreach ($function->getParameters() as $i => $param) { $name = strtolower($param->name); $reflectedClass = null; try { $reflectedClass = $param->getClass(); } catch (\ReflectionException $e) { // If the class is not found in the autoloader a reflection exception is thrown. // Unless the parameter is optional we will want to rethrow. if (!$param->isOptional()) { throw new NotFoundException( "Could not find required constructor param $name in the autoloader.", 500, $e ); } } if (array_key_exists($name, $ruleArgs)) { $value = $ruleArgs[$name]; } elseif ($reflectedClass && isset($ruleArgs[$pos]) && // The argument is a reference that matches the type hint. (($ruleArgs[$pos] instanceof Reference && is_a($this->findRuleClass($ruleArgs[$pos]->getName()), $reflectedClass->getName(), true)) || // The argument is an instance that matches the type hint. (is_object($ruleArgs[$pos]) && is_a($ruleArgs[$pos], $reflectedClass->name))) ) { $value = $ruleArgs[$pos]; $pos++; } elseif ($reflectedClass && ($reflectedClass->isInstantiable() || isset($this->rules[$reflectedClass->name]) || array_key_exists($reflectedClass->name, $this->instances)) ) { $value = new DefaultReference($this->normalizeID($reflectedClass->name)); } elseif (array_key_exists($pos, $ruleArgs)) { $value = $ruleArgs[$pos]; $pos++; } elseif ($param->isDefaultValueAvailable()) { $value = $param->getDefaultValue(); } elseif ($param->isOptional()) { $value = null; } else { $value = new RequiredParameter($param); } $result[$name] = $value; } return $result; }
php
private function makeDefaultArgs(\ReflectionFunctionAbstract $function, array $ruleArgs) { $ruleArgs = array_change_key_case($ruleArgs); $result = []; $pos = 0; foreach ($function->getParameters() as $i => $param) { $name = strtolower($param->name); $reflectedClass = null; try { $reflectedClass = $param->getClass(); } catch (\ReflectionException $e) { // If the class is not found in the autoloader a reflection exception is thrown. // Unless the parameter is optional we will want to rethrow. if (!$param->isOptional()) { throw new NotFoundException( "Could not find required constructor param $name in the autoloader.", 500, $e ); } } if (array_key_exists($name, $ruleArgs)) { $value = $ruleArgs[$name]; } elseif ($reflectedClass && isset($ruleArgs[$pos]) && // The argument is a reference that matches the type hint. (($ruleArgs[$pos] instanceof Reference && is_a($this->findRuleClass($ruleArgs[$pos]->getName()), $reflectedClass->getName(), true)) || // The argument is an instance that matches the type hint. (is_object($ruleArgs[$pos]) && is_a($ruleArgs[$pos], $reflectedClass->name))) ) { $value = $ruleArgs[$pos]; $pos++; } elseif ($reflectedClass && ($reflectedClass->isInstantiable() || isset($this->rules[$reflectedClass->name]) || array_key_exists($reflectedClass->name, $this->instances)) ) { $value = new DefaultReference($this->normalizeID($reflectedClass->name)); } elseif (array_key_exists($pos, $ruleArgs)) { $value = $ruleArgs[$pos]; $pos++; } elseif ($param->isDefaultValueAvailable()) { $value = $param->getDefaultValue(); } elseif ($param->isOptional()) { $value = null; } else { $value = new RequiredParameter($param); } $result[$name] = $value; } return $result; }
[ "private", "function", "makeDefaultArgs", "(", "\\", "ReflectionFunctionAbstract", "$", "function", ",", "array", "$", "ruleArgs", ")", "{", "$", "ruleArgs", "=", "array_change_key_case", "(", "$", "ruleArgs", ")", ";", "$", "result", "=", "[", "]", ";", "$", "pos", "=", "0", ";", "foreach", "(", "$", "function", "->", "getParameters", "(", ")", "as", "$", "i", "=>", "$", "param", ")", "{", "$", "name", "=", "strtolower", "(", "$", "param", "->", "name", ")", ";", "$", "reflectedClass", "=", "null", ";", "try", "{", "$", "reflectedClass", "=", "$", "param", "->", "getClass", "(", ")", ";", "}", "catch", "(", "\\", "ReflectionException", "$", "e", ")", "{", "// If the class is not found in the autoloader a reflection exception is thrown.", "// Unless the parameter is optional we will want to rethrow.", "if", "(", "!", "$", "param", "->", "isOptional", "(", ")", ")", "{", "throw", "new", "NotFoundException", "(", "\"Could not find required constructor param $name in the autoloader.\"", ",", "500", ",", "$", "e", ")", ";", "}", "}", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "ruleArgs", ")", ")", "{", "$", "value", "=", "$", "ruleArgs", "[", "$", "name", "]", ";", "}", "elseif", "(", "$", "reflectedClass", "&&", "isset", "(", "$", "ruleArgs", "[", "$", "pos", "]", ")", "&&", "// The argument is a reference that matches the type hint.", "(", "(", "$", "ruleArgs", "[", "$", "pos", "]", "instanceof", "Reference", "&&", "is_a", "(", "$", "this", "->", "findRuleClass", "(", "$", "ruleArgs", "[", "$", "pos", "]", "->", "getName", "(", ")", ")", ",", "$", "reflectedClass", "->", "getName", "(", ")", ",", "true", ")", ")", "||", "// The argument is an instance that matches the type hint.", "(", "is_object", "(", "$", "ruleArgs", "[", "$", "pos", "]", ")", "&&", "is_a", "(", "$", "ruleArgs", "[", "$", "pos", "]", ",", "$", "reflectedClass", "->", "name", ")", ")", ")", ")", "{", "$", "value", "=", "$", "ruleArgs", "[", "$", "pos", "]", ";", "$", "pos", "++", ";", "}", "elseif", "(", "$", "reflectedClass", "&&", "(", "$", "reflectedClass", "->", "isInstantiable", "(", ")", "||", "isset", "(", "$", "this", "->", "rules", "[", "$", "reflectedClass", "->", "name", "]", ")", "||", "array_key_exists", "(", "$", "reflectedClass", "->", "name", ",", "$", "this", "->", "instances", ")", ")", ")", "{", "$", "value", "=", "new", "DefaultReference", "(", "$", "this", "->", "normalizeID", "(", "$", "reflectedClass", "->", "name", ")", ")", ";", "}", "elseif", "(", "array_key_exists", "(", "$", "pos", ",", "$", "ruleArgs", ")", ")", "{", "$", "value", "=", "$", "ruleArgs", "[", "$", "pos", "]", ";", "$", "pos", "++", ";", "}", "elseif", "(", "$", "param", "->", "isDefaultValueAvailable", "(", ")", ")", "{", "$", "value", "=", "$", "param", "->", "getDefaultValue", "(", ")", ";", "}", "elseif", "(", "$", "param", "->", "isOptional", "(", ")", ")", "{", "$", "value", "=", "null", ";", "}", "else", "{", "$", "value", "=", "new", "RequiredParameter", "(", "$", "param", ")", ";", "}", "$", "result", "[", "$", "name", "]", "=", "$", "value", ";", "}", "return", "$", "result", ";", "}" ]
Make an array of default arguments for a given function. @param \ReflectionFunctionAbstract $function The function to make the arguments for. @param array $ruleArgs An array of default arguments specifically for the function. @return array Returns an array in the form `name => defaultValue`. @throws NotFoundException If a non-optional class param is reflected and does not exist.
[ "Make", "an", "array", "of", "default", "arguments", "for", "a", "given", "function", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L598-L650
27,089
vanilla/garden-container
src/Container.php
Container.resolveArgs
private function resolveArgs(array $defaultArgs, array $args, $instance = null) { // First resolve all passed arguments so their types are known. $args = array_map( function ($arg) use ($instance) { return $arg instanceof ReferenceInterface ? $arg->resolve($this, $instance) : $arg; }, array_change_key_case($args) ); $pos = 0; foreach ($defaultArgs as $name => &$default) { if (array_key_exists($name, $args)) { // This is a named arg and should be used. $value = $args[$name]; } elseif (isset($args[$pos]) && (!($default instanceof DefaultReference) || empty($default->getClass()) || is_a($args[$pos], $default->getClass()))) { // There is an arg at this position and it's the same type as the default arg or the default arg is typeless. $value = $args[$pos]; $pos++; } else { // There is no passed arg, so use the default arg. $value = $default; } if ($value instanceof ReferenceInterface) { $value = $value->resolve($this, $instance); } $default = $value; } return $defaultArgs; }
php
private function resolveArgs(array $defaultArgs, array $args, $instance = null) { // First resolve all passed arguments so their types are known. $args = array_map( function ($arg) use ($instance) { return $arg instanceof ReferenceInterface ? $arg->resolve($this, $instance) : $arg; }, array_change_key_case($args) ); $pos = 0; foreach ($defaultArgs as $name => &$default) { if (array_key_exists($name, $args)) { // This is a named arg and should be used. $value = $args[$name]; } elseif (isset($args[$pos]) && (!($default instanceof DefaultReference) || empty($default->getClass()) || is_a($args[$pos], $default->getClass()))) { // There is an arg at this position and it's the same type as the default arg or the default arg is typeless. $value = $args[$pos]; $pos++; } else { // There is no passed arg, so use the default arg. $value = $default; } if ($value instanceof ReferenceInterface) { $value = $value->resolve($this, $instance); } $default = $value; } return $defaultArgs; }
[ "private", "function", "resolveArgs", "(", "array", "$", "defaultArgs", ",", "array", "$", "args", ",", "$", "instance", "=", "null", ")", "{", "// First resolve all passed arguments so their types are known.", "$", "args", "=", "array_map", "(", "function", "(", "$", "arg", ")", "use", "(", "$", "instance", ")", "{", "return", "$", "arg", "instanceof", "ReferenceInterface", "?", "$", "arg", "->", "resolve", "(", "$", "this", ",", "$", "instance", ")", ":", "$", "arg", ";", "}", ",", "array_change_key_case", "(", "$", "args", ")", ")", ";", "$", "pos", "=", "0", ";", "foreach", "(", "$", "defaultArgs", "as", "$", "name", "=>", "&", "$", "default", ")", "{", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "args", ")", ")", "{", "// This is a named arg and should be used.", "$", "value", "=", "$", "args", "[", "$", "name", "]", ";", "}", "elseif", "(", "isset", "(", "$", "args", "[", "$", "pos", "]", ")", "&&", "(", "!", "(", "$", "default", "instanceof", "DefaultReference", ")", "||", "empty", "(", "$", "default", "->", "getClass", "(", ")", ")", "||", "is_a", "(", "$", "args", "[", "$", "pos", "]", ",", "$", "default", "->", "getClass", "(", ")", ")", ")", ")", "{", "// There is an arg at this position and it's the same type as the default arg or the default arg is typeless.", "$", "value", "=", "$", "args", "[", "$", "pos", "]", ";", "$", "pos", "++", ";", "}", "else", "{", "// There is no passed arg, so use the default arg.", "$", "value", "=", "$", "default", ";", "}", "if", "(", "$", "value", "instanceof", "ReferenceInterface", ")", "{", "$", "value", "=", "$", "value", "->", "resolve", "(", "$", "this", ",", "$", "instance", ")", ";", "}", "$", "default", "=", "$", "value", ";", "}", "return", "$", "defaultArgs", ";", "}" ]
Replace an array of default args with called args. @param array $defaultArgs The default arguments from {@link Container::makeDefaultArgs()}. @param array $args The arguments passed into a creation. @param mixed $instance An object instance if the arguments are being resolved on an already constructed object. @return array Returns an array suitable to be applied to a function call. @throws MissingArgumentException Throws an exception when a required parameter is missing.
[ "Replace", "an", "array", "of", "default", "args", "with", "called", "args", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L661-L692
27,090
vanilla/garden-container
src/Container.php
Container.createInstance
private function createInstance($nid, array $args) { $rule = $this->makeRule($nid); // Cache the instance or its factory for future use. if (empty($rule['shared'])) { $factory = $this->makeFactory($nid, $rule); $instance = $factory($args); $this->factories[$nid] = $factory; } else { $instance = $this->createSharedInstance($nid, $rule, $args); } return $instance; }
php
private function createInstance($nid, array $args) { $rule = $this->makeRule($nid); // Cache the instance or its factory for future use. if (empty($rule['shared'])) { $factory = $this->makeFactory($nid, $rule); $instance = $factory($args); $this->factories[$nid] = $factory; } else { $instance = $this->createSharedInstance($nid, $rule, $args); } return $instance; }
[ "private", "function", "createInstance", "(", "$", "nid", ",", "array", "$", "args", ")", "{", "$", "rule", "=", "$", "this", "->", "makeRule", "(", "$", "nid", ")", ";", "// Cache the instance or its factory for future use.", "if", "(", "empty", "(", "$", "rule", "[", "'shared'", "]", ")", ")", "{", "$", "factory", "=", "$", "this", "->", "makeFactory", "(", "$", "nid", ",", "$", "rule", ")", ";", "$", "instance", "=", "$", "factory", "(", "$", "args", ")", ";", "$", "this", "->", "factories", "[", "$", "nid", "]", "=", "$", "factory", ";", "}", "else", "{", "$", "instance", "=", "$", "this", "->", "createSharedInstance", "(", "$", "nid", ",", "$", "rule", ",", "$", "args", ")", ";", "}", "return", "$", "instance", ";", "}" ]
Create an instance of a container item. This method either creates a new instance or returns an already created shared instance. @param string $nid The normalized ID of the container item. @param array $args Additional arguments to pass to the constructor. @return object Returns an object instance.
[ "Create", "an", "instance", "of", "a", "container", "item", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L703-L715
27,091
vanilla/garden-container
src/Container.php
Container.call
public function call(callable $callback, array $args = []) { $instance = null; if (is_array($callback)) { $function = new \ReflectionMethod($callback[0], $callback[1]); if (is_object($callback[0])) { $instance = $callback[0]; } } else { $function = new \ReflectionFunction($callback); } $args = $this->resolveArgs($this->makeDefaultArgs($function, $args), [], $instance); return call_user_func_array($callback, $args); }
php
public function call(callable $callback, array $args = []) { $instance = null; if (is_array($callback)) { $function = new \ReflectionMethod($callback[0], $callback[1]); if (is_object($callback[0])) { $instance = $callback[0]; } } else { $function = new \ReflectionFunction($callback); } $args = $this->resolveArgs($this->makeDefaultArgs($function, $args), [], $instance); return call_user_func_array($callback, $args); }
[ "public", "function", "call", "(", "callable", "$", "callback", ",", "array", "$", "args", "=", "[", "]", ")", "{", "$", "instance", "=", "null", ";", "if", "(", "is_array", "(", "$", "callback", ")", ")", "{", "$", "function", "=", "new", "\\", "ReflectionMethod", "(", "$", "callback", "[", "0", "]", ",", "$", "callback", "[", "1", "]", ")", ";", "if", "(", "is_object", "(", "$", "callback", "[", "0", "]", ")", ")", "{", "$", "instance", "=", "$", "callback", "[", "0", "]", ";", "}", "}", "else", "{", "$", "function", "=", "new", "\\", "ReflectionFunction", "(", "$", "callback", ")", ";", "}", "$", "args", "=", "$", "this", "->", "resolveArgs", "(", "$", "this", "->", "makeDefaultArgs", "(", "$", "function", ",", "$", "args", ")", ",", "[", "]", ",", "$", "instance", ")", ";", "return", "call_user_func_array", "(", "$", "callback", ",", "$", "args", ")", ";", "}" ]
Call a callback with argument injection. @param callable $callback The callback to call. @param array $args Additional arguments to pass to the callback. @return mixed Returns the result of the callback. @throws ContainerException Throws an exception if the callback cannot be understood.
[ "Call", "a", "callback", "with", "argument", "injection", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L725-L741
27,092
vanilla/garden-container
src/Container.php
Container.hasRule
public function hasRule($id) { $id = $this->normalizeID($id); return !empty($this->rules[$id]); }
php
public function hasRule($id) { $id = $this->normalizeID($id); return !empty($this->rules[$id]); }
[ "public", "function", "hasRule", "(", "$", "id", ")", "{", "$", "id", "=", "$", "this", "->", "normalizeID", "(", "$", "id", ")", ";", "return", "!", "empty", "(", "$", "this", "->", "rules", "[", "$", "id", "]", ")", ";", "}" ]
Determines whether a rule has been defined at a given ID. @param string $id Identifier of the entry to look for. @return bool Returns **true** if a rule has been defined or **false** otherwise.
[ "Determines", "whether", "a", "rule", "has", "been", "defined", "at", "a", "given", "ID", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L762-L765
27,093
vanilla/garden-container
src/Container.php
Container.hasInstance
public function hasInstance($id) { $id = $this->normalizeID($id); return isset($this->instances[$id]); }
php
public function hasInstance($id) { $id = $this->normalizeID($id); return isset($this->instances[$id]); }
[ "public", "function", "hasInstance", "(", "$", "id", ")", "{", "$", "id", "=", "$", "this", "->", "normalizeID", "(", "$", "id", ")", ";", "return", "isset", "(", "$", "this", "->", "instances", "[", "$", "id", "]", ")", ";", "}" ]
Returns true if the container already has an instance for the given identifier. Returns false otherwise. @param string $id Identifier of the entry to look for. @return bool
[ "Returns", "true", "if", "the", "container", "already", "has", "an", "instance", "for", "the", "given", "identifier", ".", "Returns", "false", "otherwise", "." ]
aa467fdd050808a65a27a032d4d62d1b0e293ba6
https://github.com/vanilla/garden-container/blob/aa467fdd050808a65a27a032d4d62d1b0e293ba6/src/Container.php#L774-L778
27,094
ThaDafinser/UserAgentParser
src/Model/Version.php
Version.setComplete
public function setComplete($complete) { // check if the version has only 0 -> so no real result // maybe move this out to the Providers itself? $left = preg_replace('/[0._]/', '', $complete); if ($left === '') { $complete = null; } $this->hydrateFromComplete($complete); $this->complete = $complete; }
php
public function setComplete($complete) { // check if the version has only 0 -> so no real result // maybe move this out to the Providers itself? $left = preg_replace('/[0._]/', '', $complete); if ($left === '') { $complete = null; } $this->hydrateFromComplete($complete); $this->complete = $complete; }
[ "public", "function", "setComplete", "(", "$", "complete", ")", "{", "// check if the version has only 0 -> so no real result", "// maybe move this out to the Providers itself?", "$", "left", "=", "preg_replace", "(", "'/[0._]/'", ",", "''", ",", "$", "complete", ")", ";", "if", "(", "$", "left", "===", "''", ")", "{", "$", "complete", "=", "null", ";", "}", "$", "this", "->", "hydrateFromComplete", "(", "$", "complete", ")", ";", "$", "this", "->", "complete", "=", "$", "complete", ";", "}" ]
Set from the complete version string. @param string $complete
[ "Set", "from", "the", "complete", "version", "string", "." ]
199cc8286e593e8e00b99e8df8144981ed948246
https://github.com/ThaDafinser/UserAgentParser/blob/199cc8286e593e8e00b99e8df8144981ed948246/src/Model/Version.php#L151-L163
27,095
drupal/core-utility
Rectangle.php
Rectangle.rotate
public function rotate($angle) { // PHP 5.5 GD bug: https://bugs.php.net/bug.php?id=65148: To prevent buggy // behavior on negative multiples of 30 degrees we convert any negative // angle to a positive one between 0 and 360 degrees. $angle -= floor($angle / 360) * 360; // For some rotations that are multiple of 30 degrees, we need to correct // an imprecision between GD that uses C floats internally, and PHP that // uses C doubles. Also, for rotations that are not multiple of 90 degrees, // we need to introduce a correction factor of 0.5 to match the GD // algorithm used in PHP 5.5 (and above) to calculate the width and height // of the rotated image. if ((int) $angle == $angle && $angle % 90 == 0) { $imprecision = 0; $correction = 0; } else { $imprecision = -0.00001; $correction = 0.5; } // Do the trigonometry, applying imprecision fixes where needed. $rad = deg2rad($angle); $cos = cos($rad); $sin = sin($rad); $a = $this->width * $cos; $b = $this->height * $sin + $correction; $c = $this->width * $sin; $d = $this->height * $cos + $correction; if ((int) $angle == $angle && in_array($angle, [60, 150, 300])) { $a = $this->fixImprecision($a, $imprecision); $b = $this->fixImprecision($b, $imprecision); $c = $this->fixImprecision($c, $imprecision); $d = $this->fixImprecision($d, $imprecision); } // This is how GD on PHP5.5 calculates the new dimensions. $this->boundingWidth = abs((int) $a) + abs((int) $b); $this->boundingHeight = abs((int) $c) + abs((int) $d); return $this; }
php
public function rotate($angle) { // PHP 5.5 GD bug: https://bugs.php.net/bug.php?id=65148: To prevent buggy // behavior on negative multiples of 30 degrees we convert any negative // angle to a positive one between 0 and 360 degrees. $angle -= floor($angle / 360) * 360; // For some rotations that are multiple of 30 degrees, we need to correct // an imprecision between GD that uses C floats internally, and PHP that // uses C doubles. Also, for rotations that are not multiple of 90 degrees, // we need to introduce a correction factor of 0.5 to match the GD // algorithm used in PHP 5.5 (and above) to calculate the width and height // of the rotated image. if ((int) $angle == $angle && $angle % 90 == 0) { $imprecision = 0; $correction = 0; } else { $imprecision = -0.00001; $correction = 0.5; } // Do the trigonometry, applying imprecision fixes where needed. $rad = deg2rad($angle); $cos = cos($rad); $sin = sin($rad); $a = $this->width * $cos; $b = $this->height * $sin + $correction; $c = $this->width * $sin; $d = $this->height * $cos + $correction; if ((int) $angle == $angle && in_array($angle, [60, 150, 300])) { $a = $this->fixImprecision($a, $imprecision); $b = $this->fixImprecision($b, $imprecision); $c = $this->fixImprecision($c, $imprecision); $d = $this->fixImprecision($d, $imprecision); } // This is how GD on PHP5.5 calculates the new dimensions. $this->boundingWidth = abs((int) $a) + abs((int) $b); $this->boundingHeight = abs((int) $c) + abs((int) $d); return $this; }
[ "public", "function", "rotate", "(", "$", "angle", ")", "{", "// PHP 5.5 GD bug: https://bugs.php.net/bug.php?id=65148: To prevent buggy", "// behavior on negative multiples of 30 degrees we convert any negative", "// angle to a positive one between 0 and 360 degrees.", "$", "angle", "-=", "floor", "(", "$", "angle", "/", "360", ")", "*", "360", ";", "// For some rotations that are multiple of 30 degrees, we need to correct", "// an imprecision between GD that uses C floats internally, and PHP that", "// uses C doubles. Also, for rotations that are not multiple of 90 degrees,", "// we need to introduce a correction factor of 0.5 to match the GD", "// algorithm used in PHP 5.5 (and above) to calculate the width and height", "// of the rotated image.", "if", "(", "(", "int", ")", "$", "angle", "==", "$", "angle", "&&", "$", "angle", "%", "90", "==", "0", ")", "{", "$", "imprecision", "=", "0", ";", "$", "correction", "=", "0", ";", "}", "else", "{", "$", "imprecision", "=", "-", "0.00001", ";", "$", "correction", "=", "0.5", ";", "}", "// Do the trigonometry, applying imprecision fixes where needed.", "$", "rad", "=", "deg2rad", "(", "$", "angle", ")", ";", "$", "cos", "=", "cos", "(", "$", "rad", ")", ";", "$", "sin", "=", "sin", "(", "$", "rad", ")", ";", "$", "a", "=", "$", "this", "->", "width", "*", "$", "cos", ";", "$", "b", "=", "$", "this", "->", "height", "*", "$", "sin", "+", "$", "correction", ";", "$", "c", "=", "$", "this", "->", "width", "*", "$", "sin", ";", "$", "d", "=", "$", "this", "->", "height", "*", "$", "cos", "+", "$", "correction", ";", "if", "(", "(", "int", ")", "$", "angle", "==", "$", "angle", "&&", "in_array", "(", "$", "angle", ",", "[", "60", ",", "150", ",", "300", "]", ")", ")", "{", "$", "a", "=", "$", "this", "->", "fixImprecision", "(", "$", "a", ",", "$", "imprecision", ")", ";", "$", "b", "=", "$", "this", "->", "fixImprecision", "(", "$", "b", ",", "$", "imprecision", ")", ";", "$", "c", "=", "$", "this", "->", "fixImprecision", "(", "$", "c", ",", "$", "imprecision", ")", ";", "$", "d", "=", "$", "this", "->", "fixImprecision", "(", "$", "d", ",", "$", "imprecision", ")", ";", "}", "// This is how GD on PHP5.5 calculates the new dimensions.", "$", "this", "->", "boundingWidth", "=", "abs", "(", "(", "int", ")", "$", "a", ")", "+", "abs", "(", "(", "int", ")", "$", "b", ")", ";", "$", "this", "->", "boundingHeight", "=", "abs", "(", "(", "int", ")", "$", "c", ")", "+", "abs", "(", "(", "int", ")", "$", "d", ")", ";", "return", "$", "this", ";", "}" ]
Rotates the rectangle. @param float $angle Rotation angle. @return $this
[ "Rotates", "the", "rectangle", "." ]
fb1c262da83fb691bcdf1680c3a69791a1d1a01a
https://github.com/drupal/core-utility/blob/fb1c262da83fb691bcdf1680c3a69791a1d1a01a/Rectangle.php#L83-L124
27,096
drupal/core-utility
Rectangle.php
Rectangle.fixImprecision
protected function fixImprecision($input, $imprecision) { if ($this->delta($input) < abs($imprecision)) { return $input + $imprecision; } return $input; }
php
protected function fixImprecision($input, $imprecision) { if ($this->delta($input) < abs($imprecision)) { return $input + $imprecision; } return $input; }
[ "protected", "function", "fixImprecision", "(", "$", "input", ",", "$", "imprecision", ")", "{", "if", "(", "$", "this", "->", "delta", "(", "$", "input", ")", "<", "abs", "(", "$", "imprecision", ")", ")", "{", "return", "$", "input", "+", "$", "imprecision", ";", "}", "return", "$", "input", ";", "}" ]
Performs an imprecision check on the input value and fixes it if needed. GD that uses C floats internally, whereas we at PHP level use C doubles. In some cases, we need to compensate imprecision. @param float $input The input value. @param float $imprecision The imprecision factor. @return float A value, where imprecision is added to input if the delta part of the input is lower than the absolute imprecision.
[ "Performs", "an", "imprecision", "check", "on", "the", "input", "value", "and", "fixes", "it", "if", "needed", "." ]
fb1c262da83fb691bcdf1680c3a69791a1d1a01a
https://github.com/drupal/core-utility/blob/fb1c262da83fb691bcdf1680c3a69791a1d1a01a/Rectangle.php#L141-L146
27,097
drupal/core-utility
UrlHelper.php
UrlHelper.buildQuery
public static function buildQuery(array $query, $parent = '') { $params = []; foreach ($query as $key => $value) { $key = ($parent ? $parent . rawurlencode('[' . $key . ']') : rawurlencode($key)); // Recurse into children. if (is_array($value)) { $params[] = static::buildQuery($value, $key); } // If a query parameter value is NULL, only append its key. elseif (!isset($value)) { $params[] = $key; } else { // For better readability of paths in query strings, we decode slashes. $params[] = $key . '=' . str_replace('%2F', '/', rawurlencode($value)); } } return implode('&', $params); }
php
public static function buildQuery(array $query, $parent = '') { $params = []; foreach ($query as $key => $value) { $key = ($parent ? $parent . rawurlencode('[' . $key . ']') : rawurlencode($key)); // Recurse into children. if (is_array($value)) { $params[] = static::buildQuery($value, $key); } // If a query parameter value is NULL, only append its key. elseif (!isset($value)) { $params[] = $key; } else { // For better readability of paths in query strings, we decode slashes. $params[] = $key . '=' . str_replace('%2F', '/', rawurlencode($value)); } } return implode('&', $params); }
[ "public", "static", "function", "buildQuery", "(", "array", "$", "query", ",", "$", "parent", "=", "''", ")", "{", "$", "params", "=", "[", "]", ";", "foreach", "(", "$", "query", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "key", "=", "(", "$", "parent", "?", "$", "parent", ".", "rawurlencode", "(", "'['", ".", "$", "key", ".", "']'", ")", ":", "rawurlencode", "(", "$", "key", ")", ")", ";", "// Recurse into children.", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "params", "[", "]", "=", "static", "::", "buildQuery", "(", "$", "value", ",", "$", "key", ")", ";", "}", "// If a query parameter value is NULL, only append its key.", "elseif", "(", "!", "isset", "(", "$", "value", ")", ")", "{", "$", "params", "[", "]", "=", "$", "key", ";", "}", "else", "{", "// For better readability of paths in query strings, we decode slashes.", "$", "params", "[", "]", "=", "$", "key", ".", "'='", ".", "str_replace", "(", "'%2F'", ",", "'/'", ",", "rawurlencode", "(", "$", "value", ")", ")", ";", "}", "}", "return", "implode", "(", "'&'", ",", "$", "params", ")", ";", "}" ]
Parses an array into a valid, rawurlencoded query string. rawurlencode() is RFC3986 compliant, and as a consequence RFC3987 compliant. The latter defines the required format of "URLs" in HTML5. urlencode() is almost the same as rawurlencode(), except that it encodes spaces as "+" instead of "%20". This makes its result non compliant to RFC3986 and as a consequence non compliant to RFC3987 and as a consequence not valid as a "URL" in HTML5. @todo Remove this function once PHP 5.4 is required as we can use just http_build_query() directly. @param array $query The query parameter array to be processed; for instance, \Drupal::request()->query->all(). @param string $parent (optional) Internal use only. Used to build the $query array key for nested items. Defaults to an empty string. @return string A rawurlencoded string which can be used as or appended to the URL query string. @ingroup php_wrappers
[ "Parses", "an", "array", "into", "a", "valid", "rawurlencoded", "query", "string", "." ]
fb1c262da83fb691bcdf1680c3a69791a1d1a01a
https://github.com/drupal/core-utility/blob/fb1c262da83fb691bcdf1680c3a69791a1d1a01a/UrlHelper.php#L45-L66
27,098
drupal/core-utility
Random.php
Random.image
public function image($destination, $min_resolution, $max_resolution) { $extension = pathinfo($destination, PATHINFO_EXTENSION); $min = explode('x', $min_resolution); $max = explode('x', $max_resolution); $width = rand((int) $min[0], (int) $max[0]); $height = rand((int) $min[1], (int) $max[1]); // Make an image split into 4 sections with random colors. $im = imagecreate($width, $height); for ($n = 0; $n < 4; $n++) { $color = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255)); $x = $width / 2 * ($n % 2); $y = $height / 2 * (int) ($n >= 2); imagefilledrectangle($im, $x, $y, $x + $width / 2, $y + $height / 2, $color); } // Make a perfect circle in the image middle. $color = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255)); $smaller_dimension = min($width, $height); imageellipse($im, $width / 2, $height / 2, $smaller_dimension, $smaller_dimension, $color); $save_function = 'image' . ($extension == 'jpg' ? 'jpeg' : $extension); $save_function($im, $destination); return $destination; }
php
public function image($destination, $min_resolution, $max_resolution) { $extension = pathinfo($destination, PATHINFO_EXTENSION); $min = explode('x', $min_resolution); $max = explode('x', $max_resolution); $width = rand((int) $min[0], (int) $max[0]); $height = rand((int) $min[1], (int) $max[1]); // Make an image split into 4 sections with random colors. $im = imagecreate($width, $height); for ($n = 0; $n < 4; $n++) { $color = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255)); $x = $width / 2 * ($n % 2); $y = $height / 2 * (int) ($n >= 2); imagefilledrectangle($im, $x, $y, $x + $width / 2, $y + $height / 2, $color); } // Make a perfect circle in the image middle. $color = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255)); $smaller_dimension = min($width, $height); imageellipse($im, $width / 2, $height / 2, $smaller_dimension, $smaller_dimension, $color); $save_function = 'image' . ($extension == 'jpg' ? 'jpeg' : $extension); $save_function($im, $destination); return $destination; }
[ "public", "function", "image", "(", "$", "destination", ",", "$", "min_resolution", ",", "$", "max_resolution", ")", "{", "$", "extension", "=", "pathinfo", "(", "$", "destination", ",", "PATHINFO_EXTENSION", ")", ";", "$", "min", "=", "explode", "(", "'x'", ",", "$", "min_resolution", ")", ";", "$", "max", "=", "explode", "(", "'x'", ",", "$", "max_resolution", ")", ";", "$", "width", "=", "rand", "(", "(", "int", ")", "$", "min", "[", "0", "]", ",", "(", "int", ")", "$", "max", "[", "0", "]", ")", ";", "$", "height", "=", "rand", "(", "(", "int", ")", "$", "min", "[", "1", "]", ",", "(", "int", ")", "$", "max", "[", "1", "]", ")", ";", "// Make an image split into 4 sections with random colors.", "$", "im", "=", "imagecreate", "(", "$", "width", ",", "$", "height", ")", ";", "for", "(", "$", "n", "=", "0", ";", "$", "n", "<", "4", ";", "$", "n", "++", ")", "{", "$", "color", "=", "imagecolorallocate", "(", "$", "im", ",", "rand", "(", "0", ",", "255", ")", ",", "rand", "(", "0", ",", "255", ")", ",", "rand", "(", "0", ",", "255", ")", ")", ";", "$", "x", "=", "$", "width", "/", "2", "*", "(", "$", "n", "%", "2", ")", ";", "$", "y", "=", "$", "height", "/", "2", "*", "(", "int", ")", "(", "$", "n", ">=", "2", ")", ";", "imagefilledrectangle", "(", "$", "im", ",", "$", "x", ",", "$", "y", ",", "$", "x", "+", "$", "width", "/", "2", ",", "$", "y", "+", "$", "height", "/", "2", ",", "$", "color", ")", ";", "}", "// Make a perfect circle in the image middle.", "$", "color", "=", "imagecolorallocate", "(", "$", "im", ",", "rand", "(", "0", ",", "255", ")", ",", "rand", "(", "0", ",", "255", ")", ",", "rand", "(", "0", ",", "255", ")", ")", ";", "$", "smaller_dimension", "=", "min", "(", "$", "width", ",", "$", "height", ")", ";", "imageellipse", "(", "$", "im", ",", "$", "width", "/", "2", ",", "$", "height", "/", "2", ",", "$", "smaller_dimension", ",", "$", "smaller_dimension", ",", "$", "color", ")", ";", "$", "save_function", "=", "'image'", ".", "(", "$", "extension", "==", "'jpg'", "?", "'jpeg'", ":", "$", "extension", ")", ";", "$", "save_function", "(", "$", "im", ",", "$", "destination", ")", ";", "return", "$", "destination", ";", "}" ]
Create a placeholder image. @param string $destination The absolute file path where the image should be stored. @param int $min_resolution @param int $max_resolution @return string Path to image file.
[ "Create", "a", "placeholder", "image", "." ]
fb1c262da83fb691bcdf1680c3a69791a1d1a01a
https://github.com/drupal/core-utility/blob/fb1c262da83fb691bcdf1680c3a69791a1d1a01a/Random.php#L271-L296
27,099
drupal/core-utility
Unicode.php
Unicode.setStatus
public static function setStatus($status) { if (!in_array($status, [static::STATUS_SINGLEBYTE, static::STATUS_MULTIBYTE, static::STATUS_ERROR])) { throw new \InvalidArgumentException('Invalid status value for unicode support.'); } static::$status = $status; }
php
public static function setStatus($status) { if (!in_array($status, [static::STATUS_SINGLEBYTE, static::STATUS_MULTIBYTE, static::STATUS_ERROR])) { throw new \InvalidArgumentException('Invalid status value for unicode support.'); } static::$status = $status; }
[ "public", "static", "function", "setStatus", "(", "$", "status", ")", "{", "if", "(", "!", "in_array", "(", "$", "status", ",", "[", "static", "::", "STATUS_SINGLEBYTE", ",", "static", "::", "STATUS_MULTIBYTE", ",", "static", "::", "STATUS_ERROR", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid status value for unicode support.'", ")", ";", "}", "static", "::", "$", "status", "=", "$", "status", ";", "}" ]
Sets the value for multibyte support status for the current environment. The following status keys are supported: - \Drupal\Component\Utility\Unicode::STATUS_MULTIBYTE Full unicode support using an extension. - \Drupal\Component\Utility\Unicode::STATUS_SINGLEBYTE Standard PHP (emulated) unicode support. - \Drupal\Component\Utility\Unicode::STATUS_ERROR An error occurred. No unicode support. @param int $status The new status of multibyte support.
[ "Sets", "the", "value", "for", "multibyte", "support", "status", "for", "the", "current", "environment", "." ]
fb1c262da83fb691bcdf1680c3a69791a1d1a01a
https://github.com/drupal/core-utility/blob/fb1c262da83fb691bcdf1680c3a69791a1d1a01a/Unicode.php#L127-L132