repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
inhere/php-librarys
src/DI/ContainerManager.php
ContainerManager.setDefaultGroup
public static function setDefaultGroup($group = 'di') { $group = strtolower(trim($group)); if (!isset(static::$containers[$group])) { static::$containers[$group] = [ 'root' => null, 'children' => [] ]; } static::$defaultGroup = $group; }
php
public static function setDefaultGroup($group = 'di') { $group = strtolower(trim($group)); if (!isset(static::$containers[$group])) { static::$containers[$group] = [ 'root' => null, 'children' => [] ]; } static::$defaultGroup = $group; }
[ "public", "static", "function", "setDefaultGroup", "(", "$", "group", "=", "'di'", ")", "{", "$", "group", "=", "strtolower", "(", "trim", "(", "$", "group", ")", ")", ";", "if", "(", "!", "isset", "(", "static", "::", "$", "containers", "[", "$", "group", "]", ")", ")", "{", "static", "::", "$", "containers", "[", "$", "group", "]", "=", "[", "'root'", "=>", "null", ",", "'children'", "=>", "[", "]", "]", ";", "}", "static", "::", "$", "defaultGroup", "=", "$", "group", ";", "}" ]
setProfile @param string $group @return void
[ "setProfile" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/ContainerManager.php#L78-L90
inhere/php-librarys
src/DI/ContainerManager.php
ContainerManager.get
public static function get($id, $name = '') { $container = self::getContainer($name); return $container->get($id); }
php
public static function get($id, $name = '') { $container = self::getContainer($name); return $container->get($id); }
[ "public", "static", "function", "get", "(", "$", "id", ",", "$", "name", "=", "''", ")", "{", "$", "container", "=", "self", "::", "getContainer", "(", "$", "name", ")", ";", "return", "$", "container", "->", "get", "(", "$", "id", ")", ";", "}" ]
more @see Container::get() @param $id @param string $name 容器名称 @return mixed
[ "more" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/ContainerManager.php#L134-L139
inhere/php-librarys
src/DI/ContainerManager.php
ContainerManager.getNew
public static function getNew($id, $name = '') { $container = self::getContainer($name); return $container->getNew($id); }
php
public static function getNew($id, $name = '') { $container = self::getContainer($name); return $container->getNew($id); }
[ "public", "static", "function", "getNew", "(", "$", "id", ",", "$", "name", "=", "''", ")", "{", "$", "container", "=", "self", "::", "getContainer", "(", "$", "name", ")", ";", "return", "$", "container", "->", "getNew", "(", "$", "id", ")", ";", "}" ]
more @see Container::getNew() @param $id @param string $name @return mixed
[ "more" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/ContainerManager.php#L147-L152
Smile-SA/CronBundle
Repository/SmileCronRepository.php
SmileCronRepository.isQueued
public function isQueued($alias) { $query = $this->createQueryBuilder('c') ->where('c.alias = :alias') ->andWhere('c.ended is NULL') ->setParameter('alias', $alias) ->getQuery(); $result = $query->setMaxResults(1)->getOneOrNullResult(); if ($result) return true; return false; }
php
public function isQueued($alias) { $query = $this->createQueryBuilder('c') ->where('c.alias = :alias') ->andWhere('c.ended is NULL') ->setParameter('alias', $alias) ->getQuery(); $result = $query->setMaxResults(1)->getOneOrNullResult(); if ($result) return true; return false; }
[ "public", "function", "isQueued", "(", "$", "alias", ")", "{", "$", "query", "=", "$", "this", "->", "createQueryBuilder", "(", "'c'", ")", "->", "where", "(", "'c.alias = :alias'", ")", "->", "andWhere", "(", "'c.ended is NULL'", ")", "->", "setParameter", "(", "'alias'", ",", "$", "alias", ")", "->", "getQuery", "(", ")", ";", "$", "result", "=", "$", "query", "->", "setMaxResults", "(", "1", ")", "->", "getOneOrNullResult", "(", ")", ";", "if", "(", "$", "result", ")", "return", "true", ";", "return", "false", ";", "}" ]
Identify of cron command is queued @param string $alias cron alias @return bool true if cron is already queued
[ "Identify", "of", "cron", "command", "is", "queued" ]
train
https://github.com/Smile-SA/CronBundle/blob/3e6d29112915fa957cc04386ba9c6d1fc134d31f/Repository/SmileCronRepository.php#L20-L34
Smile-SA/CronBundle
Repository/SmileCronRepository.php
SmileCronRepository.addQueued
public function addQueued($alias) { $query = $this->createQueryBuilder('c') ->where('c.alias = :alias') ->setParameter('alias', $alias) ->getQuery(); /** @var SmileCron $smileCron */ $smileCron = $query->setMaxResults(1)->getOneOrNullResult(); if (!$smileCron) { $smileCron = new SmileCron(); $smileCron->setAlias($alias); } $now = new \DateTime('now'); $smileCron->setQueued($now); $smileCron->setStarted(null); $smileCron->setEnded(null); $smileCron->setStatus(0); $this->getEntityManager()->persist($smileCron); $this->getEntityManager()->flush(); }
php
public function addQueued($alias) { $query = $this->createQueryBuilder('c') ->where('c.alias = :alias') ->setParameter('alias', $alias) ->getQuery(); /** @var SmileCron $smileCron */ $smileCron = $query->setMaxResults(1)->getOneOrNullResult(); if (!$smileCron) { $smileCron = new SmileCron(); $smileCron->setAlias($alias); } $now = new \DateTime('now'); $smileCron->setQueued($now); $smileCron->setStarted(null); $smileCron->setEnded(null); $smileCron->setStatus(0); $this->getEntityManager()->persist($smileCron); $this->getEntityManager()->flush(); }
[ "public", "function", "addQueued", "(", "$", "alias", ")", "{", "$", "query", "=", "$", "this", "->", "createQueryBuilder", "(", "'c'", ")", "->", "where", "(", "'c.alias = :alias'", ")", "->", "setParameter", "(", "'alias'", ",", "$", "alias", ")", "->", "getQuery", "(", ")", ";", "/** @var SmileCron $smileCron */", "$", "smileCron", "=", "$", "query", "->", "setMaxResults", "(", "1", ")", "->", "getOneOrNullResult", "(", ")", ";", "if", "(", "!", "$", "smileCron", ")", "{", "$", "smileCron", "=", "new", "SmileCron", "(", ")", ";", "$", "smileCron", "->", "setAlias", "(", "$", "alias", ")", ";", "}", "$", "now", "=", "new", "\\", "DateTime", "(", "'now'", ")", ";", "$", "smileCron", "->", "setQueued", "(", "$", "now", ")", ";", "$", "smileCron", "->", "setStarted", "(", "null", ")", ";", "$", "smileCron", "->", "setEnded", "(", "null", ")", ";", "$", "smileCron", "->", "setStatus", "(", "0", ")", ";", "$", "this", "->", "getEntityManager", "(", ")", "->", "persist", "(", "$", "smileCron", ")", ";", "$", "this", "->", "getEntityManager", "(", ")", "->", "flush", "(", ")", ";", "}" ]
Add cron to queued @param string $alias cron alias
[ "Add", "cron", "to", "queued" ]
train
https://github.com/Smile-SA/CronBundle/blob/3e6d29112915fa957cc04386ba9c6d1fc134d31f/Repository/SmileCronRepository.php#L41-L64
Smile-SA/CronBundle
Repository/SmileCronRepository.php
SmileCronRepository.run
public function run(SmileCron $smileCron) { $now = new \DateTime('now'); $smileCron->setStarted($now); $this->getEntityManager()->persist($smileCron); $this->getEntityManager()->flush(); }
php
public function run(SmileCron $smileCron) { $now = new \DateTime('now'); $smileCron->setStarted($now); $this->getEntityManager()->persist($smileCron); $this->getEntityManager()->flush(); }
[ "public", "function", "run", "(", "SmileCron", "$", "smileCron", ")", "{", "$", "now", "=", "new", "\\", "DateTime", "(", "'now'", ")", ";", "$", "smileCron", "->", "setStarted", "(", "$", "now", ")", ";", "$", "this", "->", "getEntityManager", "(", ")", "->", "persist", "(", "$", "smileCron", ")", ";", "$", "this", "->", "getEntityManager", "(", ")", "->", "flush", "(", ")", ";", "}" ]
Run cron command @param SmileCron $smileCron cron command
[ "Run", "cron", "command" ]
train
https://github.com/Smile-SA/CronBundle/blob/3e6d29112915fa957cc04386ba9c6d1fc134d31f/Repository/SmileCronRepository.php#L86-L92
Smile-SA/CronBundle
Repository/SmileCronRepository.php
SmileCronRepository.end
public function end(SmileCron $smileCron, $status = 0) { $now = new \DateTime('now'); $smileCron->setEnded($now); $smileCron->setStatus($status); $this->getEntityManager()->persist($smileCron); $this->getEntityManager()->flush(); }
php
public function end(SmileCron $smileCron, $status = 0) { $now = new \DateTime('now'); $smileCron->setEnded($now); $smileCron->setStatus($status); $this->getEntityManager()->persist($smileCron); $this->getEntityManager()->flush(); }
[ "public", "function", "end", "(", "SmileCron", "$", "smileCron", ",", "$", "status", "=", "0", ")", "{", "$", "now", "=", "new", "\\", "DateTime", "(", "'now'", ")", ";", "$", "smileCron", "->", "setEnded", "(", "$", "now", ")", ";", "$", "smileCron", "->", "setStatus", "(", "$", "status", ")", ";", "$", "this", "->", "getEntityManager", "(", ")", "->", "persist", "(", "$", "smileCron", ")", ";", "$", "this", "->", "getEntityManager", "(", ")", "->", "flush", "(", ")", ";", "}" ]
End cron command @param SmileCron $smileCron cron command @param int $status cron command status
[ "End", "cron", "command" ]
train
https://github.com/Smile-SA/CronBundle/blob/3e6d29112915fa957cc04386ba9c6d1fc134d31f/Repository/SmileCronRepository.php#L100-L107
eymengunay/php-keyclient
src/Client.php
Client.createPaymentUrl
public function createPaymentUrl(PaymentRequestInterface $payment) { $params = $payment->toArray(); $params = array_merge($params, array( 'alias' => $this->alias, 'mac' => $this->calculateMac($payment) )); return sprintf('%s?%s', $this->endpoint, http_build_query($params)); }
php
public function createPaymentUrl(PaymentRequestInterface $payment) { $params = $payment->toArray(); $params = array_merge($params, array( 'alias' => $this->alias, 'mac' => $this->calculateMac($payment) )); return sprintf('%s?%s', $this->endpoint, http_build_query($params)); }
[ "public", "function", "createPaymentUrl", "(", "PaymentRequestInterface", "$", "payment", ")", "{", "$", "params", "=", "$", "payment", "->", "toArray", "(", ")", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "array", "(", "'alias'", "=>", "$", "this", "->", "alias", ",", "'mac'", "=>", "$", "this", "->", "calculateMac", "(", "$", "payment", ")", ")", ")", ";", "return", "sprintf", "(", "'%s?%s'", ",", "$", "this", "->", "endpoint", ",", "http_build_query", "(", "$", "params", ")", ")", ";", "}" ]
Create paymentUrl @param PaymentRequestInterface $payment @return string
[ "Create", "paymentUrl" ]
train
https://github.com/eymengunay/php-keyclient/blob/867e035a2a0707c5df4198a8c321ddfd048a9c56/src/Client.php#L49-L58
eymengunay/php-keyclient
src/Client.php
Client.parsePaymentResponse
public function parsePaymentResponse(Request $request = null) { $response = new PaymentResponse($request); // Verify mac if ($this->verifyMac($response) !== true) { throw new KeyClientException('Mac can not be verified'); } return $response; }
php
public function parsePaymentResponse(Request $request = null) { $response = new PaymentResponse($request); // Verify mac if ($this->verifyMac($response) !== true) { throw new KeyClientException('Mac can not be verified'); } return $response; }
[ "public", "function", "parsePaymentResponse", "(", "Request", "$", "request", "=", "null", ")", "{", "$", "response", "=", "new", "PaymentResponse", "(", "$", "request", ")", ";", "// Verify mac", "if", "(", "$", "this", "->", "verifyMac", "(", "$", "response", ")", "!==", "true", ")", "{", "throw", "new", "KeyClientException", "(", "'Mac can not be verified'", ")", ";", "}", "return", "$", "response", ";", "}" ]
Parse paymentResponse @param Request $request @return PaymentResponse
[ "Parse", "paymentResponse" ]
train
https://github.com/eymengunay/php-keyclient/blob/867e035a2a0707c5df4198a8c321ddfd048a9c56/src/Client.php#L66-L76
eymengunay/php-keyclient
src/Client.php
Client.calculateMac
public function calculateMac(PaymentRequestInterface $paymentRequest) { $mac = strtr('codTrans={transactionCode}divisa={currency}importo={amount}{secret}', array( '{transactionCode}' => $paymentRequest->get('codTrans'), '{currency}' => $paymentRequest->get('divisa'), '{amount}' => $paymentRequest->get('importo'), '{secret}' => $this->secret )); return sha1($mac); }
php
public function calculateMac(PaymentRequestInterface $paymentRequest) { $mac = strtr('codTrans={transactionCode}divisa={currency}importo={amount}{secret}', array( '{transactionCode}' => $paymentRequest->get('codTrans'), '{currency}' => $paymentRequest->get('divisa'), '{amount}' => $paymentRequest->get('importo'), '{secret}' => $this->secret )); return sha1($mac); }
[ "public", "function", "calculateMac", "(", "PaymentRequestInterface", "$", "paymentRequest", ")", "{", "$", "mac", "=", "strtr", "(", "'codTrans={transactionCode}divisa={currency}importo={amount}{secret}'", ",", "array", "(", "'{transactionCode}'", "=>", "$", "paymentRequest", "->", "get", "(", "'codTrans'", ")", ",", "'{currency}'", "=>", "$", "paymentRequest", "->", "get", "(", "'divisa'", ")", ",", "'{amount}'", "=>", "$", "paymentRequest", "->", "get", "(", "'importo'", ")", ",", "'{secret}'", "=>", "$", "this", "->", "secret", ")", ")", ";", "return", "sha1", "(", "$", "mac", ")", ";", "}" ]
Calculate mac @param PaymentRequestInterface $paymentRequest @return string
[ "Calculate", "mac" ]
train
https://github.com/eymengunay/php-keyclient/blob/867e035a2a0707c5df4198a8c321ddfd048a9c56/src/Client.php#L84-L94
eymengunay/php-keyclient
src/Client.php
Client.verifyMac
public function verifyMac(PaymentResponseInterface $paymentResponse) { $mac = strtr('codTrans={transactionCode}esito={result}importo={amount}divisa={currency}data={date}orario={time}codAut={authCode}{secret}', array( '{transactionCode}' => $paymentResponse->get('codTrans'), '{result}' => $paymentResponse->get('esito'), '{amount}' => $paymentResponse->get('importo'), '{currency}' => $paymentResponse->get('divisa'), '{date}' => $paymentResponse->get('data'), '{time}' => $paymentResponse->get('orario'), '{authCode}' => $paymentResponse->get('codAut'), '{secret}' => $this->secret )); $generated = sha1($mac); $given = $paymentResponse->get('mac'); return $generated === $given; }
php
public function verifyMac(PaymentResponseInterface $paymentResponse) { $mac = strtr('codTrans={transactionCode}esito={result}importo={amount}divisa={currency}data={date}orario={time}codAut={authCode}{secret}', array( '{transactionCode}' => $paymentResponse->get('codTrans'), '{result}' => $paymentResponse->get('esito'), '{amount}' => $paymentResponse->get('importo'), '{currency}' => $paymentResponse->get('divisa'), '{date}' => $paymentResponse->get('data'), '{time}' => $paymentResponse->get('orario'), '{authCode}' => $paymentResponse->get('codAut'), '{secret}' => $this->secret )); $generated = sha1($mac); $given = $paymentResponse->get('mac'); return $generated === $given; }
[ "public", "function", "verifyMac", "(", "PaymentResponseInterface", "$", "paymentResponse", ")", "{", "$", "mac", "=", "strtr", "(", "'codTrans={transactionCode}esito={result}importo={amount}divisa={currency}data={date}orario={time}codAut={authCode}{secret}'", ",", "array", "(", "'{transactionCode}'", "=>", "$", "paymentResponse", "->", "get", "(", "'codTrans'", ")", ",", "'{result}'", "=>", "$", "paymentResponse", "->", "get", "(", "'esito'", ")", ",", "'{amount}'", "=>", "$", "paymentResponse", "->", "get", "(", "'importo'", ")", ",", "'{currency}'", "=>", "$", "paymentResponse", "->", "get", "(", "'divisa'", ")", ",", "'{date}'", "=>", "$", "paymentResponse", "->", "get", "(", "'data'", ")", ",", "'{time}'", "=>", "$", "paymentResponse", "->", "get", "(", "'orario'", ")", ",", "'{authCode}'", "=>", "$", "paymentResponse", "->", "get", "(", "'codAut'", ")", ",", "'{secret}'", "=>", "$", "this", "->", "secret", ")", ")", ";", "$", "generated", "=", "sha1", "(", "$", "mac", ")", ";", "$", "given", "=", "$", "paymentResponse", "->", "get", "(", "'mac'", ")", ";", "return", "$", "generated", "===", "$", "given", ";", "}" ]
Verify mac @param PaymentResponseInterface $paymentResponse @return bool
[ "Verify", "mac" ]
train
https://github.com/eymengunay/php-keyclient/blob/867e035a2a0707c5df4198a8c321ddfd048a9c56/src/Client.php#L102-L119
Innmind/neo4j-dbal
src/Transport/Http.php
Http.execute
public function execute(Query $query): Result { $response = ($this->fulfill)( ($this->translate)($query) ); if (!$this->isSuccessful($response)) { throw new QueryFailed($query, $response); } $response = Json::decode((string) $response->body()); $result = Result\Result::fromRaw($response['results'][0] ?? []); return $result; }
php
public function execute(Query $query): Result { $response = ($this->fulfill)( ($this->translate)($query) ); if (!$this->isSuccessful($response)) { throw new QueryFailed($query, $response); } $response = Json::decode((string) $response->body()); $result = Result\Result::fromRaw($response['results'][0] ?? []); return $result; }
[ "public", "function", "execute", "(", "Query", "$", "query", ")", ":", "Result", "{", "$", "response", "=", "(", "$", "this", "->", "fulfill", ")", "(", "(", "$", "this", "->", "translate", ")", "(", "$", "query", ")", ")", ";", "if", "(", "!", "$", "this", "->", "isSuccessful", "(", "$", "response", ")", ")", "{", "throw", "new", "QueryFailed", "(", "$", "query", ",", "$", "response", ")", ";", "}", "$", "response", "=", "Json", "::", "decode", "(", "(", "string", ")", "$", "response", "->", "body", "(", ")", ")", ";", "$", "result", "=", "Result", "\\", "Result", "::", "fromRaw", "(", "$", "response", "[", "'results'", "]", "[", "0", "]", "??", "[", "]", ")", ";", "return", "$", "result", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Transport/Http.php#L40-L54
Innmind/neo4j-dbal
src/Transport/Http.php
Http.ping
public function ping(): Transport { try { $code = ($this->fulfill) ( new Request( Url::fromString('/'), Method::options(), new ProtocolVersion(1, 1) ) ) ->statusCode() ->value(); } catch (\Exception $e) { throw new ServerDown( $e->getMessage(), $e->getCode(), $e ); } if ($code >= 200 && $code < 300) { return $this; } throw new ServerDown; }
php
public function ping(): Transport { try { $code = ($this->fulfill) ( new Request( Url::fromString('/'), Method::options(), new ProtocolVersion(1, 1) ) ) ->statusCode() ->value(); } catch (\Exception $e) { throw new ServerDown( $e->getMessage(), $e->getCode(), $e ); } if ($code >= 200 && $code < 300) { return $this; } throw new ServerDown; }
[ "public", "function", "ping", "(", ")", ":", "Transport", "{", "try", "{", "$", "code", "=", "(", "$", "this", "->", "fulfill", ")", "(", "new", "Request", "(", "Url", "::", "fromString", "(", "'/'", ")", ",", "Method", "::", "options", "(", ")", ",", "new", "ProtocolVersion", "(", "1", ",", "1", ")", ")", ")", "->", "statusCode", "(", ")", "->", "value", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "ServerDown", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "if", "(", "$", "code", ">=", "200", "&&", "$", "code", "<", "300", ")", "{", "return", "$", "this", ";", "}", "throw", "new", "ServerDown", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Transport/Http.php#L59-L85
Innmind/neo4j-dbal
src/Transport/Http.php
Http.isSuccessful
private function isSuccessful(Response $response): bool { if ($response->statusCode()->value() !== 200) { return false; } $json = Json::decode((string) $response->body()); return count($json['errors']) === 0; }
php
private function isSuccessful(Response $response): bool { if ($response->statusCode()->value() !== 200) { return false; } $json = Json::decode((string) $response->body()); return count($json['errors']) === 0; }
[ "private", "function", "isSuccessful", "(", "Response", "$", "response", ")", ":", "bool", "{", "if", "(", "$", "response", "->", "statusCode", "(", ")", "->", "value", "(", ")", "!==", "200", ")", "{", "return", "false", ";", "}", "$", "json", "=", "Json", "::", "decode", "(", "(", "string", ")", "$", "response", "->", "body", "(", ")", ")", ";", "return", "count", "(", "$", "json", "[", "'errors'", "]", ")", "===", "0", ";", "}" ]
Check if the response is successful @param Response $response @return bool
[ "Check", "if", "the", "response", "is", "successful" ]
train
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Transport/Http.php#L94-L103
HedronDev/hedron
src/Parser/ComposerWP.php
ComposerWP.parse
public function parse(GitPostReceiveHandler $handler, CommandStackInterface $commandStack) { $commands = []; $git_directory = $this->getGitDirectoryPath(); $site_directory = $this->getDataDirectoryPath(); $composer_file = "$site_directory/composer.json"; $git_composer = "$git_directory/composer.json"; $version = FALSE; $new = FALSE; $removals = []; if (file_exists($git_composer)) { $composer_content = file_get_contents($git_composer); $git_composer = json_decode($composer_content); if (!empty($git_composer->require->{'johnpbloch/wordpress'})) { $version = $git_composer->require->{'johnpbloch/wordpress'}; } } if (array_search('composer.json', $handler->getCommittedFiles()) !== FALSE) { // Starting a new set of commands since we need the new composer.json // file provided by drupal/drupal before we can continue with merging // the old composer.json. $commands[] = "cd $site_directory"; if ($git_composer) { $composer_content = file_get_contents($composer_file); $new_composer = json_decode($composer_content); $removals = $this->mergeComposerJsonFiles($composer_file, $git_composer, $new_composer, [$this, 'alterComposerFile']); } // If we don't have a vendor dir yet, run install. if (!file_exists("$site_directory/vendor")) { $commands[] = "composer install"; } // Otherwise, just update for the changes made to the composer file. else { $commands[] = "composer update --lock"; } // Update modules directory with changes from the git repository. // @todo only do this if something changed in /modules if (file_exists("$git_directory/modules")) { $commands[] = "rsync -av $git_directory/modules/ $site_directory/modules"; } // Update themes directory with changes from the git repository. // @todo only do this if something changed in /themes if (file_exists("$git_directory/themes")) { $commands[] = "rsync -av $git_directory/themes/ $site_directory/themes"; } // @todo add profiles foreach ($removals as $package) { $commands[] = "composer remove $package"; } $handler->getOutput()->writeln('<info>' . shell_exec(implode('; ', $commands)) . '</info>'); } }
php
public function parse(GitPostReceiveHandler $handler, CommandStackInterface $commandStack) { $commands = []; $git_directory = $this->getGitDirectoryPath(); $site_directory = $this->getDataDirectoryPath(); $composer_file = "$site_directory/composer.json"; $git_composer = "$git_directory/composer.json"; $version = FALSE; $new = FALSE; $removals = []; if (file_exists($git_composer)) { $composer_content = file_get_contents($git_composer); $git_composer = json_decode($composer_content); if (!empty($git_composer->require->{'johnpbloch/wordpress'})) { $version = $git_composer->require->{'johnpbloch/wordpress'}; } } if (array_search('composer.json', $handler->getCommittedFiles()) !== FALSE) { // Starting a new set of commands since we need the new composer.json // file provided by drupal/drupal before we can continue with merging // the old composer.json. $commands[] = "cd $site_directory"; if ($git_composer) { $composer_content = file_get_contents($composer_file); $new_composer = json_decode($composer_content); $removals = $this->mergeComposerJsonFiles($composer_file, $git_composer, $new_composer, [$this, 'alterComposerFile']); } // If we don't have a vendor dir yet, run install. if (!file_exists("$site_directory/vendor")) { $commands[] = "composer install"; } // Otherwise, just update for the changes made to the composer file. else { $commands[] = "composer update --lock"; } // Update modules directory with changes from the git repository. // @todo only do this if something changed in /modules if (file_exists("$git_directory/modules")) { $commands[] = "rsync -av $git_directory/modules/ $site_directory/modules"; } // Update themes directory with changes from the git repository. // @todo only do this if something changed in /themes if (file_exists("$git_directory/themes")) { $commands[] = "rsync -av $git_directory/themes/ $site_directory/themes"; } // @todo add profiles foreach ($removals as $package) { $commands[] = "composer remove $package"; } $handler->getOutput()->writeln('<info>' . shell_exec(implode('; ', $commands)) . '</info>'); } }
[ "public", "function", "parse", "(", "GitPostReceiveHandler", "$", "handler", ",", "CommandStackInterface", "$", "commandStack", ")", "{", "$", "commands", "=", "[", "]", ";", "$", "git_directory", "=", "$", "this", "->", "getGitDirectoryPath", "(", ")", ";", "$", "site_directory", "=", "$", "this", "->", "getDataDirectoryPath", "(", ")", ";", "$", "composer_file", "=", "\"$site_directory/composer.json\"", ";", "$", "git_composer", "=", "\"$git_directory/composer.json\"", ";", "$", "version", "=", "FALSE", ";", "$", "new", "=", "FALSE", ";", "$", "removals", "=", "[", "]", ";", "if", "(", "file_exists", "(", "$", "git_composer", ")", ")", "{", "$", "composer_content", "=", "file_get_contents", "(", "$", "git_composer", ")", ";", "$", "git_composer", "=", "json_decode", "(", "$", "composer_content", ")", ";", "if", "(", "!", "empty", "(", "$", "git_composer", "->", "require", "->", "{", "'johnpbloch/wordpress'", "}", ")", ")", "{", "$", "version", "=", "$", "git_composer", "->", "require", "->", "{", "'johnpbloch/wordpress'", "}", ";", "}", "}", "if", "(", "array_search", "(", "'composer.json'", ",", "$", "handler", "->", "getCommittedFiles", "(", ")", ")", "!==", "FALSE", ")", "{", "// Starting a new set of commands since we need the new composer.json", "// file provided by drupal/drupal before we can continue with merging", "// the old composer.json.", "$", "commands", "[", "]", "=", "\"cd $site_directory\"", ";", "if", "(", "$", "git_composer", ")", "{", "$", "composer_content", "=", "file_get_contents", "(", "$", "composer_file", ")", ";", "$", "new_composer", "=", "json_decode", "(", "$", "composer_content", ")", ";", "$", "removals", "=", "$", "this", "->", "mergeComposerJsonFiles", "(", "$", "composer_file", ",", "$", "git_composer", ",", "$", "new_composer", ",", "[", "$", "this", ",", "'alterComposerFile'", "]", ")", ";", "}", "// If we don't have a vendor dir yet, run install.", "if", "(", "!", "file_exists", "(", "\"$site_directory/vendor\"", ")", ")", "{", "$", "commands", "[", "]", "=", "\"composer install\"", ";", "}", "// Otherwise, just update for the changes made to the composer file.", "else", "{", "$", "commands", "[", "]", "=", "\"composer update --lock\"", ";", "}", "// Update modules directory with changes from the git repository.", "// @todo only do this if something changed in /modules", "if", "(", "file_exists", "(", "\"$git_directory/modules\"", ")", ")", "{", "$", "commands", "[", "]", "=", "\"rsync -av $git_directory/modules/ $site_directory/modules\"", ";", "}", "// Update themes directory with changes from the git repository.", "// @todo only do this if something changed in /themes", "if", "(", "file_exists", "(", "\"$git_directory/themes\"", ")", ")", "{", "$", "commands", "[", "]", "=", "\"rsync -av $git_directory/themes/ $site_directory/themes\"", ";", "}", "// @todo add profiles", "foreach", "(", "$", "removals", "as", "$", "package", ")", "{", "$", "commands", "[", "]", "=", "\"composer remove $package\"", ";", "}", "$", "handler", "->", "getOutput", "(", ")", "->", "writeln", "(", "'<info>'", ".", "shell_exec", "(", "implode", "(", "'; '", ",", "$", "commands", ")", ")", ".", "'</info>'", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/HedronDev/hedron/blob/3b4adec4912f2d7c0b7e7262dc36515fbc2e8e00/src/Parser/ComposerWP.php#L24-L74
FriendsOfApi/phraseapp
src/Api/Locale.php
Locale.download
public function download(string $projectKey, string $localeId, string $ext, array $params = []) { $params['file_format'] = $ext; $response = $this->httpGet(sprintf('/api/v2/projects/%s/locales/%s/download', $projectKey, $localeId), $params); if (!$this->hydrator) { return $response; } if ($response->getStatusCode() !== 200) { $this->handleErrors($response); } return (string) $response->getBody(); }
php
public function download(string $projectKey, string $localeId, string $ext, array $params = []) { $params['file_format'] = $ext; $response = $this->httpGet(sprintf('/api/v2/projects/%s/locales/%s/download', $projectKey, $localeId), $params); if (!$this->hydrator) { return $response; } if ($response->getStatusCode() !== 200) { $this->handleErrors($response); } return (string) $response->getBody(); }
[ "public", "function", "download", "(", "string", "$", "projectKey", ",", "string", "$", "localeId", ",", "string", "$", "ext", ",", "array", "$", "params", "=", "[", "]", ")", "{", "$", "params", "[", "'file_format'", "]", "=", "$", "ext", ";", "$", "response", "=", "$", "this", "->", "httpGet", "(", "sprintf", "(", "'/api/v2/projects/%s/locales/%s/download'", ",", "$", "projectKey", ",", "$", "localeId", ")", ",", "$", "params", ")", ";", "if", "(", "!", "$", "this", "->", "hydrator", ")", "{", "return", "$", "response", ";", "}", "if", "(", "$", "response", "->", "getStatusCode", "(", ")", "!==", "200", ")", "{", "$", "this", "->", "handleErrors", "(", "$", "response", ")", ";", "}", "return", "(", "string", ")", "$", "response", "->", "getBody", "(", ")", ";", "}" ]
Download a locale. @param string $projectKey @param string $localeId @param string $ext @param array $params @throws Exception @return string|ResponseInterface
[ "Download", "a", "locale", "." ]
train
https://github.com/FriendsOfApi/phraseapp/blob/1553bf857eb0858f9a7eb905b085864d24f80886/src/Api/Locale.php#L32-L47
Eresus/EresusCMS
src/core/Client/Controller/Content/List.php
Eresus_Client_Controller_Content_List.getHtml
public function getHtml(Eresus_CMS_Request $request, TClientUI $page) { $legacyKernel = Eresus_CMS::getLegacyKernel(); /* Если в URL указано что-либо кроме адреса раздела, отправляет ответ 404 */ if ($legacyKernel->request['file'] || $legacyKernel->request['query'] || $page->subpage || $page->topic) { throw new Eresus_CMS_Exception_NotFound; } $subItems = $legacyKernel->db->select('pages', "(`owner`='" . $page->id . "') AND (`active`='1') AND (`access` >= '" . ($legacyKernel->user['auth'] ? $legacyKernel->user['access'] : GUEST)."')", "`position`"); if (empty($page->content)) { $page->content = '$(items)'; } $templates = Templates::getInstance(); $template = $templates->get('SectionListItem', 'std'); if (false === $template) { $template = '<h1><a href="$(link)" title="$(hint)">$(caption)</a></h1>$(description)'; } $items = ''; foreach ($subItems as $item) { $items .= str_replace( array( '$(id)', '$(name)', '$(title)', '$(caption)', '$(description)', '$(hint)', '$(link)', ), array( $item['id'], $item['name'], $item['title'], $item['caption'], $item['description'], $item['hint'], $legacyKernel->request['url'] . ($page->name == 'main' && !$page->owner ? 'main/' : '').$item['name'].'/', ), $template ); } $result = str_replace('$(items)', $items, $page->content); return $result; }
php
public function getHtml(Eresus_CMS_Request $request, TClientUI $page) { $legacyKernel = Eresus_CMS::getLegacyKernel(); /* Если в URL указано что-либо кроме адреса раздела, отправляет ответ 404 */ if ($legacyKernel->request['file'] || $legacyKernel->request['query'] || $page->subpage || $page->topic) { throw new Eresus_CMS_Exception_NotFound; } $subItems = $legacyKernel->db->select('pages', "(`owner`='" . $page->id . "') AND (`active`='1') AND (`access` >= '" . ($legacyKernel->user['auth'] ? $legacyKernel->user['access'] : GUEST)."')", "`position`"); if (empty($page->content)) { $page->content = '$(items)'; } $templates = Templates::getInstance(); $template = $templates->get('SectionListItem', 'std'); if (false === $template) { $template = '<h1><a href="$(link)" title="$(hint)">$(caption)</a></h1>$(description)'; } $items = ''; foreach ($subItems as $item) { $items .= str_replace( array( '$(id)', '$(name)', '$(title)', '$(caption)', '$(description)', '$(hint)', '$(link)', ), array( $item['id'], $item['name'], $item['title'], $item['caption'], $item['description'], $item['hint'], $legacyKernel->request['url'] . ($page->name == 'main' && !$page->owner ? 'main/' : '').$item['name'].'/', ), $template ); } $result = str_replace('$(items)', $items, $page->content); return $result; }
[ "public", "function", "getHtml", "(", "Eresus_CMS_Request", "$", "request", ",", "TClientUI", "$", "page", ")", "{", "$", "legacyKernel", "=", "Eresus_CMS", "::", "getLegacyKernel", "(", ")", ";", "/* Если в URL указано что-либо кроме адреса раздела, отправляет ответ 404 */", "if", "(", "$", "legacyKernel", "->", "request", "[", "'file'", "]", "||", "$", "legacyKernel", "->", "request", "[", "'query'", "]", "||", "$", "page", "->", "subpage", "||", "$", "page", "->", "topic", ")", "{", "throw", "new", "Eresus_CMS_Exception_NotFound", ";", "}", "$", "subItems", "=", "$", "legacyKernel", "->", "db", "->", "select", "(", "'pages'", ",", "\"(`owner`='\"", ".", "$", "page", "->", "id", ".", "\"') AND (`active`='1') AND (`access` >= '\"", ".", "(", "$", "legacyKernel", "->", "user", "[", "'auth'", "]", "?", "$", "legacyKernel", "->", "user", "[", "'access'", "]", ":", "GUEST", ")", ".", "\"')\"", ",", "\"`position`\"", ")", ";", "if", "(", "empty", "(", "$", "page", "->", "content", ")", ")", "{", "$", "page", "->", "content", "=", "'$(items)'", ";", "}", "$", "templates", "=", "Templates", "::", "getInstance", "(", ")", ";", "$", "template", "=", "$", "templates", "->", "get", "(", "'SectionListItem'", ",", "'std'", ")", ";", "if", "(", "false", "===", "$", "template", ")", "{", "$", "template", "=", "'<h1><a href=\"$(link)\" title=\"$(hint)\">$(caption)</a></h1>$(description)'", ";", "}", "$", "items", "=", "''", ";", "foreach", "(", "$", "subItems", "as", "$", "item", ")", "{", "$", "items", ".=", "str_replace", "(", "array", "(", "'$(id)'", ",", "'$(name)'", ",", "'$(title)'", ",", "'$(caption)'", ",", "'$(description)'", ",", "'$(hint)'", ",", "'$(link)'", ",", ")", ",", "array", "(", "$", "item", "[", "'id'", "]", ",", "$", "item", "[", "'name'", "]", ",", "$", "item", "[", "'title'", "]", ",", "$", "item", "[", "'caption'", "]", ",", "$", "item", "[", "'description'", "]", ",", "$", "item", "[", "'hint'", "]", ",", "$", "legacyKernel", "->", "request", "[", "'url'", "]", ".", "(", "$", "page", "->", "name", "==", "'main'", "&&", "!", "$", "page", "->", "owner", "?", "'main/'", ":", "''", ")", ".", "$", "item", "[", "'name'", "]", ".", "'/'", ",", ")", ",", "$", "template", ")", ";", "}", "$", "result", "=", "str_replace", "(", "'$(items)'", ",", "$", "items", ",", "$", "page", "->", "content", ")", ";", "return", "$", "result", ";", "}" ]
Возвращает разметку области контента @param Eresus_CMS_Request $request @param TClientUI $page @throws Eresus_CMS_Exception_NotFound @return string|Eresus_HTTP_Response @since 3.01
[ "Возвращает", "разметку", "области", "контента" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Client/Controller/Content/List.php#L47-L102
weew/http
src/Weew/Http/ReceivedRequestParser.php
ReceivedRequestParser.parseRequest
public function parseRequest(array $server, IHttpRequest $request = null) { if ( ! $request instanceof IHttpRequest) { $request = $this->createRequest(); } $this->setMethod($request, $server); $this->setUrl($request, $server); $this->setHeaders($request, $server); $this->setProtocol($request, $server); $this->setContent($request); $this->setServerGlobal($request, $server); return $request; }
php
public function parseRequest(array $server, IHttpRequest $request = null) { if ( ! $request instanceof IHttpRequest) { $request = $this->createRequest(); } $this->setMethod($request, $server); $this->setUrl($request, $server); $this->setHeaders($request, $server); $this->setProtocol($request, $server); $this->setContent($request); $this->setServerGlobal($request, $server); return $request; }
[ "public", "function", "parseRequest", "(", "array", "$", "server", ",", "IHttpRequest", "$", "request", "=", "null", ")", "{", "if", "(", "!", "$", "request", "instanceof", "IHttpRequest", ")", "{", "$", "request", "=", "$", "this", "->", "createRequest", "(", ")", ";", "}", "$", "this", "->", "setMethod", "(", "$", "request", ",", "$", "server", ")", ";", "$", "this", "->", "setUrl", "(", "$", "request", ",", "$", "server", ")", ";", "$", "this", "->", "setHeaders", "(", "$", "request", ",", "$", "server", ")", ";", "$", "this", "->", "setProtocol", "(", "$", "request", ",", "$", "server", ")", ";", "$", "this", "->", "setContent", "(", "$", "request", ")", ";", "$", "this", "->", "setServerGlobal", "(", "$", "request", ",", "$", "server", ")", ";", "return", "$", "request", ";", "}" ]
@param array $server @param IHttpRequest $request @return IHttpRequest
[ "@param", "array", "$server", "@param", "IHttpRequest", "$request" ]
train
https://github.com/weew/http/blob/fd34d3d5643ca01c8e0946e888224a8e8dcc3c0d/src/Weew/Http/ReceivedRequestParser.php#L14-L27
weew/http
src/Weew/Http/ReceivedRequestParser.php
ReceivedRequestParser.parseMethod
public function parseMethod(array $server) { $method = array_get($server, 'REQUEST_METHOD'); if (array_has($server, '_method')) { $_method = strtoupper(array_get($server, '_method')); if (array_contains(HttpRequestMethod::getMethods(), $_method)) { return $_method; } } return $method; }
php
public function parseMethod(array $server) { $method = array_get($server, 'REQUEST_METHOD'); if (array_has($server, '_method')) { $_method = strtoupper(array_get($server, '_method')); if (array_contains(HttpRequestMethod::getMethods(), $_method)) { return $_method; } } return $method; }
[ "public", "function", "parseMethod", "(", "array", "$", "server", ")", "{", "$", "method", "=", "array_get", "(", "$", "server", ",", "'REQUEST_METHOD'", ")", ";", "if", "(", "array_has", "(", "$", "server", ",", "'_method'", ")", ")", "{", "$", "_method", "=", "strtoupper", "(", "array_get", "(", "$", "server", ",", "'_method'", ")", ")", ";", "if", "(", "array_contains", "(", "HttpRequestMethod", "::", "getMethods", "(", ")", ",", "$", "_method", ")", ")", "{", "return", "$", "_method", ";", "}", "}", "return", "$", "method", ";", "}" ]
@param array $server @return mixed
[ "@param", "array", "$server" ]
train
https://github.com/weew/http/blob/fd34d3d5643ca01c8e0946e888224a8e8dcc3c0d/src/Weew/Http/ReceivedRequestParser.php#L43-L55
weew/http
src/Weew/Http/ReceivedRequestParser.php
ReceivedRequestParser.parseUrl
public function parseUrl(array $server) { $protocol = array_has($server, 'HTTPS') ? 'https' : 'http'; $host = array_get($server, 'HTTP_HOST'); $uri = array_get($server, 'REQUEST_URI'); return new Url(s('%s://%s%s', $protocol, $host, $uri)); }
php
public function parseUrl(array $server) { $protocol = array_has($server, 'HTTPS') ? 'https' : 'http'; $host = array_get($server, 'HTTP_HOST'); $uri = array_get($server, 'REQUEST_URI'); return new Url(s('%s://%s%s', $protocol, $host, $uri)); }
[ "public", "function", "parseUrl", "(", "array", "$", "server", ")", "{", "$", "protocol", "=", "array_has", "(", "$", "server", ",", "'HTTPS'", ")", "?", "'https'", ":", "'http'", ";", "$", "host", "=", "array_get", "(", "$", "server", ",", "'HTTP_HOST'", ")", ";", "$", "uri", "=", "array_get", "(", "$", "server", ",", "'REQUEST_URI'", ")", ";", "return", "new", "Url", "(", "s", "(", "'%s://%s%s'", ",", "$", "protocol", ",", "$", "host", ",", "$", "uri", ")", ")", ";", "}" ]
@param array $server @return Url
[ "@param", "array", "$server" ]
train
https://github.com/weew/http/blob/fd34d3d5643ca01c8e0946e888224a8e8dcc3c0d/src/Weew/Http/ReceivedRequestParser.php#L62-L68
yireo-training/magento2-example-cms-block
Model/Config/Source/Block.php
Block.toOptionArray
public function toOptionArray(): array { if (empty($this->options)) { $this->options[] = array( 'value' => '', 'label' => __('Pick a CMS block'), ); $collection = $this->collectionFactory->create(); foreach ($collection as $item) { $this->options[] = array( 'value' => $item->getIdentifier(), 'label' => $item->getTitle(), ); } } return $this->options; }
php
public function toOptionArray(): array { if (empty($this->options)) { $this->options[] = array( 'value' => '', 'label' => __('Pick a CMS block'), ); $collection = $this->collectionFactory->create(); foreach ($collection as $item) { $this->options[] = array( 'value' => $item->getIdentifier(), 'label' => $item->getTitle(), ); } } return $this->options; }
[ "public", "function", "toOptionArray", "(", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "this", "->", "options", ")", ")", "{", "$", "this", "->", "options", "[", "]", "=", "array", "(", "'value'", "=>", "''", ",", "'label'", "=>", "__", "(", "'Pick a CMS block'", ")", ",", ")", ";", "$", "collection", "=", "$", "this", "->", "collectionFactory", "->", "create", "(", ")", ";", "foreach", "(", "$", "collection", "as", "$", "item", ")", "{", "$", "this", "->", "options", "[", "]", "=", "array", "(", "'value'", "=>", "$", "item", "->", "getIdentifier", "(", ")", ",", "'label'", "=>", "$", "item", "->", "getTitle", "(", ")", ",", ")", ";", "}", "}", "return", "$", "this", "->", "options", ";", "}" ]
To option array @return array
[ "To", "option", "array" ]
train
https://github.com/yireo-training/magento2-example-cms-block/blob/db97fff488a92ee25acf83ae2ec56c9c635a4272/Model/Config/Source/Block.php#L36-L56
gordalina/mangopay-php
src/Gordalina/Mangopay/Request/Wallet/ListWalletUsers.php
ListWalletUsers.getPath
public function getPath() { $path = sprintf('/wallets/%s/users', $this->id); if ($this->include) { return sprintf('%s?include=%s', $path, $this->include); } return $path; }
php
public function getPath() { $path = sprintf('/wallets/%s/users', $this->id); if ($this->include) { return sprintf('%s?include=%s', $path, $this->include); } return $path; }
[ "public", "function", "getPath", "(", ")", "{", "$", "path", "=", "sprintf", "(", "'/wallets/%s/users'", ",", "$", "this", "->", "id", ")", ";", "if", "(", "$", "this", "->", "include", ")", "{", "return", "sprintf", "(", "'%s?include=%s'", ",", "$", "path", ",", "$", "this", "->", "include", ")", ";", "}", "return", "$", "path", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/gordalina/mangopay-php/blob/6807992416d964e25670d961b66dbccd7a46ef62/src/Gordalina/Mangopay/Request/Wallet/ListWalletUsers.php#L46-L55
kbond/ControllerUtil
src/View.php
View.createCached
public static function createCached($data, $sharedMaxAge, $statusCode = self::DEFAULT_STATUS_CODE) { return new static($data, $statusCode, null, array('s_maxage' => $sharedMaxAge)); }
php
public static function createCached($data, $sharedMaxAge, $statusCode = self::DEFAULT_STATUS_CODE) { return new static($data, $statusCode, null, array('s_maxage' => $sharedMaxAge)); }
[ "public", "static", "function", "createCached", "(", "$", "data", ",", "$", "sharedMaxAge", ",", "$", "statusCode", "=", "self", "::", "DEFAULT_STATUS_CODE", ")", "{", "return", "new", "static", "(", "$", "data", ",", "$", "statusCode", ",", "null", ",", "array", "(", "'s_maxage'", "=>", "$", "sharedMaxAge", ")", ")", ";", "}" ]
@param mixed $data @param int $sharedMaxAge @param int $statusCode @return static
[ "@param", "mixed", "$data", "@param", "int", "$sharedMaxAge", "@param", "int", "$statusCode" ]
train
https://github.com/kbond/ControllerUtil/blob/67375d43c73d6a3f16356f3d683f62b176766e91/src/View.php#L25-L28
kbond/ControllerUtil
src/View.php
View.getDataAsArray
public function getDataAsArray($key = 'data') { $data = $this->getData(); if (null === $data) { return array(); } if (!is_array($data)) { $data = array($key => $data); } return $data; }
php
public function getDataAsArray($key = 'data') { $data = $this->getData(); if (null === $data) { return array(); } if (!is_array($data)) { $data = array($key => $data); } return $data; }
[ "public", "function", "getDataAsArray", "(", "$", "key", "=", "'data'", ")", "{", "$", "data", "=", "$", "this", "->", "getData", "(", ")", ";", "if", "(", "null", "===", "$", "data", ")", "{", "return", "array", "(", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "$", "data", "=", "array", "(", "$", "key", "=>", "$", "data", ")", ";", "}", "return", "$", "data", ";", "}" ]
@param string $key The key to use when creating array if data isn't already an array @return array
[ "@param", "string", "$key", "The", "key", "to", "use", "when", "creating", "array", "if", "data", "isn", "t", "already", "an", "array" ]
train
https://github.com/kbond/ControllerUtil/blob/67375d43c73d6a3f16356f3d683f62b176766e91/src/View.php#L64-L77
thienhungho/yii2-product-management
src/modules/ProductBase/Product.php
Product.beforeSave
public function beforeSave($insert) { if (parent::beforeSave($insert)) { $feature_img = upload_img('Product[feature_img]'); if (!empty($feature_img)) { $this->feature_img = $feature_img; } elseif(empty($feature_img) && !$this->isNewRecord) { $model = static::findOne(['id' => $this->id]); if ($model) { $this->feature_img = $model->feature_img; } } $gallery = upload_img('Product[gallery]', true); if (!empty($gallery)) { $this->gallery = json_encode($gallery); } elseif (empty($gallery) && !$this->isNewRecord) { $model = static::findOne(['id' => $this->id]); if ($model) { $this->gallery = $model->gallery; } } return true; } return false; }
php
public function beforeSave($insert) { if (parent::beforeSave($insert)) { $feature_img = upload_img('Product[feature_img]'); if (!empty($feature_img)) { $this->feature_img = $feature_img; } elseif(empty($feature_img) && !$this->isNewRecord) { $model = static::findOne(['id' => $this->id]); if ($model) { $this->feature_img = $model->feature_img; } } $gallery = upload_img('Product[gallery]', true); if (!empty($gallery)) { $this->gallery = json_encode($gallery); } elseif (empty($gallery) && !$this->isNewRecord) { $model = static::findOne(['id' => $this->id]); if ($model) { $this->gallery = $model->gallery; } } return true; } return false; }
[ "public", "function", "beforeSave", "(", "$", "insert", ")", "{", "if", "(", "parent", "::", "beforeSave", "(", "$", "insert", ")", ")", "{", "$", "feature_img", "=", "upload_img", "(", "'Product[feature_img]'", ")", ";", "if", "(", "!", "empty", "(", "$", "feature_img", ")", ")", "{", "$", "this", "->", "feature_img", "=", "$", "feature_img", ";", "}", "elseif", "(", "empty", "(", "$", "feature_img", ")", "&&", "!", "$", "this", "->", "isNewRecord", ")", "{", "$", "model", "=", "static", "::", "findOne", "(", "[", "'id'", "=>", "$", "this", "->", "id", "]", ")", ";", "if", "(", "$", "model", ")", "{", "$", "this", "->", "feature_img", "=", "$", "model", "->", "feature_img", ";", "}", "}", "$", "gallery", "=", "upload_img", "(", "'Product[gallery]'", ",", "true", ")", ";", "if", "(", "!", "empty", "(", "$", "gallery", ")", ")", "{", "$", "this", "->", "gallery", "=", "json_encode", "(", "$", "gallery", ")", ";", "}", "elseif", "(", "empty", "(", "$", "gallery", ")", "&&", "!", "$", "this", "->", "isNewRecord", ")", "{", "$", "model", "=", "static", "::", "findOne", "(", "[", "'id'", "=>", "$", "this", "->", "id", "]", ")", ";", "if", "(", "$", "model", ")", "{", "$", "this", "->", "gallery", "=", "$", "model", "->", "gallery", ";", "}", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
@param bool $insert @return bool @throws \yii\base\Exception @throws \yii\base\InvalidConfigException
[ "@param", "bool", "$insert" ]
train
https://github.com/thienhungho/yii2-product-management/blob/72e1237bba123faf671e44491bd93077b50adde9/src/modules/ProductBase/Product.php#L72-L99
mainio/c5pkg_symfony_forms
src/Mainio/C5/Symfony/Form/Extension/Concrete5/Type/DateTimeSelectorType.php
DateTimeSelectorType.buildView
public function buildView(FormView $view, FormInterface $form, array $options) { $dh = \Core::make('helper/form/date_time'); $name = $view->vars["full_name"]; $prefix = substr($name, 0, strlen($name)-1); $selector = $dh->datetime($name, $view->vars["value"]); // Change the c5 generated form names for something that the Symphony // forms understand. Changes e.g. form[date_dt] to form[date][dt]. $prefix = str_replace(array('[', ']'), array('\[', '\]'), $prefix); $pattern = '/name="' . $prefix . '_([^"]+)\]"/'; $selector = preg_replace($pattern, 'name="' . $name . '[\1]"', $selector); $view->vars = array_replace($view->vars, array( 'selector' => $selector )); }
php
public function buildView(FormView $view, FormInterface $form, array $options) { $dh = \Core::make('helper/form/date_time'); $name = $view->vars["full_name"]; $prefix = substr($name, 0, strlen($name)-1); $selector = $dh->datetime($name, $view->vars["value"]); // Change the c5 generated form names for something that the Symphony // forms understand. Changes e.g. form[date_dt] to form[date][dt]. $prefix = str_replace(array('[', ']'), array('\[', '\]'), $prefix); $pattern = '/name="' . $prefix . '_([^"]+)\]"/'; $selector = preg_replace($pattern, 'name="' . $name . '[\1]"', $selector); $view->vars = array_replace($view->vars, array( 'selector' => $selector )); }
[ "public", "function", "buildView", "(", "FormView", "$", "view", ",", "FormInterface", "$", "form", ",", "array", "$", "options", ")", "{", "$", "dh", "=", "\\", "Core", "::", "make", "(", "'helper/form/date_time'", ")", ";", "$", "name", "=", "$", "view", "->", "vars", "[", "\"full_name\"", "]", ";", "$", "prefix", "=", "substr", "(", "$", "name", ",", "0", ",", "strlen", "(", "$", "name", ")", "-", "1", ")", ";", "$", "selector", "=", "$", "dh", "->", "datetime", "(", "$", "name", ",", "$", "view", "->", "vars", "[", "\"value\"", "]", ")", ";", "// Change the c5 generated form names for something that the Symphony", "// forms understand. Changes e.g. form[date_dt] to form[date][dt].", "$", "prefix", "=", "str_replace", "(", "array", "(", "'['", ",", "']'", ")", ",", "array", "(", "'\\['", ",", "'\\]'", ")", ",", "$", "prefix", ")", ";", "$", "pattern", "=", "'/name=\"'", ".", "$", "prefix", ".", "'_([^\"]+)\\]\"/'", ";", "$", "selector", "=", "preg_replace", "(", "$", "pattern", ",", "'name=\"'", ".", "$", "name", ".", "'[\\1]\"'", ",", "$", "selector", ")", ";", "$", "view", "->", "vars", "=", "array_replace", "(", "$", "view", "->", "vars", ",", "array", "(", "'selector'", "=>", "$", "selector", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/mainio/c5pkg_symfony_forms/blob/41a93c293d986574ec5cade8a7c8700e083dbaaa/src/Mainio/C5/Symfony/Form/Extension/Concrete5/Type/DateTimeSelectorType.php#L36-L54
ekuiter/feature-php
FeaturePhp/Generator/CopyGenerator.php
CopyGenerator.processFileSpecification
protected function processFileSpecification($artifact, $fileSpecification) { $this->files[] = fphp\File\StoredFile::fromSpecification($fileSpecification); $this->tracingLinks[] = new fphp\Artifact\TracingLink( "file", $artifact, $fileSpecification->getSourcePlace(), $fileSpecification->getTargetPlace()); $this->logFile->log($artifact, "added file \"{$fileSpecification->getTarget()}\""); }
php
protected function processFileSpecification($artifact, $fileSpecification) { $this->files[] = fphp\File\StoredFile::fromSpecification($fileSpecification); $this->tracingLinks[] = new fphp\Artifact\TracingLink( "file", $artifact, $fileSpecification->getSourcePlace(), $fileSpecification->getTargetPlace()); $this->logFile->log($artifact, "added file \"{$fileSpecification->getTarget()}\""); }
[ "protected", "function", "processFileSpecification", "(", "$", "artifact", ",", "$", "fileSpecification", ")", "{", "$", "this", "->", "files", "[", "]", "=", "fphp", "\\", "File", "\\", "StoredFile", "::", "fromSpecification", "(", "$", "fileSpecification", ")", ";", "$", "this", "->", "tracingLinks", "[", "]", "=", "new", "fphp", "\\", "Artifact", "\\", "TracingLink", "(", "\"file\"", ",", "$", "artifact", ",", "$", "fileSpecification", "->", "getSourcePlace", "(", ")", ",", "$", "fileSpecification", "->", "getTargetPlace", "(", ")", ")", ";", "$", "this", "->", "logFile", "->", "log", "(", "$", "artifact", ",", "\"added file \\\"{$fileSpecification->getTarget()}\\\"\"", ")", ";", "}" ]
Adds a stored file from a specification. Considers globally excluded files. Only exact file names are supported. @param \FeaturePhp\Artifact\Artifact $artifact @param \FeaturePhp\Specification\FileSpecification $fileSpecification
[ "Adds", "a", "stored", "file", "from", "a", "specification", ".", "Considers", "globally", "excluded", "files", ".", "Only", "exact", "file", "names", "are", "supported", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Generator/CopyGenerator.php#L34-L39
oroinc/OroLayoutComponent
LayoutRegistry.php
LayoutRegistry.getType
public function getType($name) { if (!is_string($name)) { throw new Exception\UnexpectedTypeException($name, 'string'); } if (isset($this->types[$name])) { return $this->types[$name]; } $type = null; $extensions = $this->getExtensions(); foreach ($extensions as $extension) { if ($extension->hasType($name)) { $type = $extension->getType($name); break; } } if (!$type) { throw new Exception\InvalidArgumentException(sprintf('Could not load a block type "%s".', $name)); } $this->types[$name] = $type; return $type; }
php
public function getType($name) { if (!is_string($name)) { throw new Exception\UnexpectedTypeException($name, 'string'); } if (isset($this->types[$name])) { return $this->types[$name]; } $type = null; $extensions = $this->getExtensions(); foreach ($extensions as $extension) { if ($extension->hasType($name)) { $type = $extension->getType($name); break; } } if (!$type) { throw new Exception\InvalidArgumentException(sprintf('Could not load a block type "%s".', $name)); } $this->types[$name] = $type; return $type; }
[ "public", "function", "getType", "(", "$", "name", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", ")", "{", "throw", "new", "Exception", "\\", "UnexpectedTypeException", "(", "$", "name", ",", "'string'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "types", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "types", "[", "$", "name", "]", ";", "}", "$", "type", "=", "null", ";", "$", "extensions", "=", "$", "this", "->", "getExtensions", "(", ")", ";", "foreach", "(", "$", "extensions", "as", "$", "extension", ")", "{", "if", "(", "$", "extension", "->", "hasType", "(", "$", "name", ")", ")", "{", "$", "type", "=", "$", "extension", "->", "getType", "(", "$", "name", ")", ";", "break", ";", "}", "}", "if", "(", "!", "$", "type", ")", "{", "throw", "new", "Exception", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Could not load a block type \"%s\".'", ",", "$", "name", ")", ")", ";", "}", "$", "this", "->", "types", "[", "$", "name", "]", "=", "$", "type", ";", "return", "$", "type", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRegistry.php#L29-L54
oroinc/OroLayoutComponent
LayoutRegistry.php
LayoutRegistry.getTypeExtensions
public function getTypeExtensions($name) { return isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : $this->loadTypeExtensions($name); }
php
public function getTypeExtensions($name) { return isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : $this->loadTypeExtensions($name); }
[ "public", "function", "getTypeExtensions", "(", "$", "name", ")", "{", "return", "isset", "(", "$", "this", "->", "typeExtensions", "[", "$", "name", "]", ")", "?", "$", "this", "->", "typeExtensions", "[", "$", "name", "]", ":", "$", "this", "->", "loadTypeExtensions", "(", "$", "name", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRegistry.php#L59-L64
oroinc/OroLayoutComponent
LayoutRegistry.php
LayoutRegistry.getContextConfigurators
public function getContextConfigurators() { $configurators = []; $extensions = $this->getExtensions(); foreach ($extensions as $extension) { if ($extension->hasContextConfigurators()) { $configurators = array_merge($configurators, $extension->getContextConfigurators()); } } return $configurators; }
php
public function getContextConfigurators() { $configurators = []; $extensions = $this->getExtensions(); foreach ($extensions as $extension) { if ($extension->hasContextConfigurators()) { $configurators = array_merge($configurators, $extension->getContextConfigurators()); } } return $configurators; }
[ "public", "function", "getContextConfigurators", "(", ")", "{", "$", "configurators", "=", "[", "]", ";", "$", "extensions", "=", "$", "this", "->", "getExtensions", "(", ")", ";", "foreach", "(", "$", "extensions", "as", "$", "extension", ")", "{", "if", "(", "$", "extension", "->", "hasContextConfigurators", "(", ")", ")", "{", "$", "configurators", "=", "array_merge", "(", "$", "configurators", ",", "$", "extension", "->", "getContextConfigurators", "(", ")", ")", ";", "}", "}", "return", "$", "configurators", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRegistry.php#L69-L81
oroinc/OroLayoutComponent
LayoutRegistry.php
LayoutRegistry.findDataProvider
public function findDataProvider($name) { if (!is_string($name)) { throw new Exception\UnexpectedTypeException($name, 'string'); } if (isset($this->dataProviders[$name])) { return $this->dataProviders[$name]; } $dataProvider = null; $extensions = $this->getExtensions(); foreach ($extensions as $extension) { if ($extension->hasDataProvider($name)) { $dataProvider = $extension->getDataProvider($name); break; } } $this->dataProviders[$name] = $dataProvider; return $dataProvider; }
php
public function findDataProvider($name) { if (!is_string($name)) { throw new Exception\UnexpectedTypeException($name, 'string'); } if (isset($this->dataProviders[$name])) { return $this->dataProviders[$name]; } $dataProvider = null; $extensions = $this->getExtensions(); foreach ($extensions as $extension) { if ($extension->hasDataProvider($name)) { $dataProvider = $extension->getDataProvider($name); break; } } $this->dataProviders[$name] = $dataProvider; return $dataProvider; }
[ "public", "function", "findDataProvider", "(", "$", "name", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", ")", "{", "throw", "new", "Exception", "\\", "UnexpectedTypeException", "(", "$", "name", ",", "'string'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "dataProviders", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "dataProviders", "[", "$", "name", "]", ";", "}", "$", "dataProvider", "=", "null", ";", "$", "extensions", "=", "$", "this", "->", "getExtensions", "(", ")", ";", "foreach", "(", "$", "extensions", "as", "$", "extension", ")", "{", "if", "(", "$", "extension", "->", "hasDataProvider", "(", "$", "name", ")", ")", "{", "$", "dataProvider", "=", "$", "extension", "->", "getDataProvider", "(", "$", "name", ")", ";", "break", ";", "}", "}", "$", "this", "->", "dataProviders", "[", "$", "name", "]", "=", "$", "dataProvider", ";", "return", "$", "dataProvider", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRegistry.php#L86-L108
oroinc/OroLayoutComponent
LayoutRegistry.php
LayoutRegistry.configureOptions
public function configureOptions($name, OptionsResolver $resolver) { $extensions = isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : $this->loadTypeExtensions($name); foreach ($extensions as $extension) { $extension->configureOptions($resolver); } }
php
public function configureOptions($name, OptionsResolver $resolver) { $extensions = isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : $this->loadTypeExtensions($name); foreach ($extensions as $extension) { $extension->configureOptions($resolver); } }
[ "public", "function", "configureOptions", "(", "$", "name", ",", "OptionsResolver", "$", "resolver", ")", "{", "$", "extensions", "=", "isset", "(", "$", "this", "->", "typeExtensions", "[", "$", "name", "]", ")", "?", "$", "this", "->", "typeExtensions", "[", "$", "name", "]", ":", "$", "this", "->", "loadTypeExtensions", "(", "$", "name", ")", ";", "foreach", "(", "$", "extensions", "as", "$", "extension", ")", "{", "$", "extension", "->", "configureOptions", "(", "$", "resolver", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRegistry.php#L113-L122
oroinc/OroLayoutComponent
LayoutRegistry.php
LayoutRegistry.buildBlock
public function buildBlock($name, BlockBuilderInterface $builder, Options $options) { $extensions = isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : $this->loadTypeExtensions($name); foreach ($extensions as $extension) { $extension->buildBlock($builder, $options); } }
php
public function buildBlock($name, BlockBuilderInterface $builder, Options $options) { $extensions = isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : $this->loadTypeExtensions($name); foreach ($extensions as $extension) { $extension->buildBlock($builder, $options); } }
[ "public", "function", "buildBlock", "(", "$", "name", ",", "BlockBuilderInterface", "$", "builder", ",", "Options", "$", "options", ")", "{", "$", "extensions", "=", "isset", "(", "$", "this", "->", "typeExtensions", "[", "$", "name", "]", ")", "?", "$", "this", "->", "typeExtensions", "[", "$", "name", "]", ":", "$", "this", "->", "loadTypeExtensions", "(", "$", "name", ")", ";", "foreach", "(", "$", "extensions", "as", "$", "extension", ")", "{", "$", "extension", "->", "buildBlock", "(", "$", "builder", ",", "$", "options", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRegistry.php#L127-L136
oroinc/OroLayoutComponent
LayoutRegistry.php
LayoutRegistry.buildView
public function buildView($name, BlockView $view, BlockInterface $block, Options $options) { $extensions = isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : $this->loadTypeExtensions($name); foreach ($extensions as $extension) { $extension->buildView($view, $block, $options); } }
php
public function buildView($name, BlockView $view, BlockInterface $block, Options $options) { $extensions = isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : $this->loadTypeExtensions($name); foreach ($extensions as $extension) { $extension->buildView($view, $block, $options); } }
[ "public", "function", "buildView", "(", "$", "name", ",", "BlockView", "$", "view", ",", "BlockInterface", "$", "block", ",", "Options", "$", "options", ")", "{", "$", "extensions", "=", "isset", "(", "$", "this", "->", "typeExtensions", "[", "$", "name", "]", ")", "?", "$", "this", "->", "typeExtensions", "[", "$", "name", "]", ":", "$", "this", "->", "loadTypeExtensions", "(", "$", "name", ")", ";", "foreach", "(", "$", "extensions", "as", "$", "extension", ")", "{", "$", "extension", "->", "buildView", "(", "$", "view", ",", "$", "block", ",", "$", "options", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRegistry.php#L141-L150
oroinc/OroLayoutComponent
LayoutRegistry.php
LayoutRegistry.finishView
public function finishView($name, BlockView $view, BlockInterface $block) { $extensions = isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : $this->loadTypeExtensions($name); foreach ($extensions as $extension) { $extension->finishView($view, $block); } }
php
public function finishView($name, BlockView $view, BlockInterface $block) { $extensions = isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : $this->loadTypeExtensions($name); foreach ($extensions as $extension) { $extension->finishView($view, $block); } }
[ "public", "function", "finishView", "(", "$", "name", ",", "BlockView", "$", "view", ",", "BlockInterface", "$", "block", ")", "{", "$", "extensions", "=", "isset", "(", "$", "this", "->", "typeExtensions", "[", "$", "name", "]", ")", "?", "$", "this", "->", "typeExtensions", "[", "$", "name", "]", ":", "$", "this", "->", "loadTypeExtensions", "(", "$", "name", ")", ";", "foreach", "(", "$", "extensions", "as", "$", "extension", ")", "{", "$", "extension", "->", "finishView", "(", "$", "view", ",", "$", "block", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRegistry.php#L155-L164
oroinc/OroLayoutComponent
LayoutRegistry.php
LayoutRegistry.updateLayout
public function updateLayout($id, LayoutManipulatorInterface $layoutManipulator, LayoutItemInterface $item) { $extensions = $this->getExtensions(); foreach ($extensions as $extension) { if ($extension->hasLayoutUpdates($item)) { $layoutUpdates = $extension->getLayoutUpdates($item); foreach ($layoutUpdates as $layoutUpdate) { $layoutUpdate->updateLayout($layoutManipulator, $item); } } } }
php
public function updateLayout($id, LayoutManipulatorInterface $layoutManipulator, LayoutItemInterface $item) { $extensions = $this->getExtensions(); foreach ($extensions as $extension) { if ($extension->hasLayoutUpdates($item)) { $layoutUpdates = $extension->getLayoutUpdates($item); foreach ($layoutUpdates as $layoutUpdate) { $layoutUpdate->updateLayout($layoutManipulator, $item); } } } }
[ "public", "function", "updateLayout", "(", "$", "id", ",", "LayoutManipulatorInterface", "$", "layoutManipulator", ",", "LayoutItemInterface", "$", "item", ")", "{", "$", "extensions", "=", "$", "this", "->", "getExtensions", "(", ")", ";", "foreach", "(", "$", "extensions", "as", "$", "extension", ")", "{", "if", "(", "$", "extension", "->", "hasLayoutUpdates", "(", "$", "item", ")", ")", "{", "$", "layoutUpdates", "=", "$", "extension", "->", "getLayoutUpdates", "(", "$", "item", ")", ";", "foreach", "(", "$", "layoutUpdates", "as", "$", "layoutUpdate", ")", "{", "$", "layoutUpdate", "->", "updateLayout", "(", "$", "layoutManipulator", ",", "$", "item", ")", ";", "}", "}", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRegistry.php#L169-L180
oroinc/OroLayoutComponent
LayoutRegistry.php
LayoutRegistry.configureContext
public function configureContext(ContextInterface $context) { $extensions = $this->getExtensions(); foreach ($extensions as $extension) { if ($extension->hasContextConfigurators()) { $configurators = $extension->getContextConfigurators(); foreach ($configurators as $configurator) { $configurator->configureContext($context); } } } }
php
public function configureContext(ContextInterface $context) { $extensions = $this->getExtensions(); foreach ($extensions as $extension) { if ($extension->hasContextConfigurators()) { $configurators = $extension->getContextConfigurators(); foreach ($configurators as $configurator) { $configurator->configureContext($context); } } } }
[ "public", "function", "configureContext", "(", "ContextInterface", "$", "context", ")", "{", "$", "extensions", "=", "$", "this", "->", "getExtensions", "(", ")", ";", "foreach", "(", "$", "extensions", "as", "$", "extension", ")", "{", "if", "(", "$", "extension", "->", "hasContextConfigurators", "(", ")", ")", "{", "$", "configurators", "=", "$", "extension", "->", "getContextConfigurators", "(", ")", ";", "foreach", "(", "$", "configurators", "as", "$", "configurator", ")", "{", "$", "configurator", "->", "configureContext", "(", "$", "context", ")", ";", "}", "}", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRegistry.php#L185-L196
oroinc/OroLayoutComponent
LayoutRegistry.php
LayoutRegistry.addExtension
public function addExtension(ExtensionInterface $extension, $priority = 0) { $this->extensions[$priority][] = $extension; $this->sorted = null; $this->typeExtensions = []; }
php
public function addExtension(ExtensionInterface $extension, $priority = 0) { $this->extensions[$priority][] = $extension; $this->sorted = null; $this->typeExtensions = []; }
[ "public", "function", "addExtension", "(", "ExtensionInterface", "$", "extension", ",", "$", "priority", "=", "0", ")", "{", "$", "this", "->", "extensions", "[", "$", "priority", "]", "[", "]", "=", "$", "extension", ";", "$", "this", "->", "sorted", "=", "null", ";", "$", "this", "->", "typeExtensions", "=", "[", "]", ";", "}" ]
Registers an layout extension. @param ExtensionInterface $extension @param int $priority
[ "Registers", "an", "layout", "extension", "." ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRegistry.php#L204-L209
oroinc/OroLayoutComponent
LayoutRegistry.php
LayoutRegistry.getExtensions
protected function getExtensions() { if (null === $this->sorted) { ksort($this->extensions); $this->sorted = !empty($this->extensions) ? call_user_func_array('array_merge', $this->extensions) : []; } return $this->sorted; }
php
protected function getExtensions() { if (null === $this->sorted) { ksort($this->extensions); $this->sorted = !empty($this->extensions) ? call_user_func_array('array_merge', $this->extensions) : []; } return $this->sorted; }
[ "protected", "function", "getExtensions", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "sorted", ")", "{", "ksort", "(", "$", "this", "->", "extensions", ")", ";", "$", "this", "->", "sorted", "=", "!", "empty", "(", "$", "this", "->", "extensions", ")", "?", "call_user_func_array", "(", "'array_merge'", ",", "$", "this", "->", "extensions", ")", ":", "[", "]", ";", "}", "return", "$", "this", "->", "sorted", ";", "}" ]
Returns all registered extensions sorted by priority. @return ExtensionInterface[]
[ "Returns", "all", "registered", "extensions", "sorted", "by", "priority", "." ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRegistry.php#L216-L226
oroinc/OroLayoutComponent
LayoutRegistry.php
LayoutRegistry.loadTypeExtensions
protected function loadTypeExtensions($name) { $typeExtensions = []; $extensions = $this->getExtensions(); foreach ($extensions as $extension) { if ($extension->hasTypeExtensions($name)) { $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($name)); } } $this->typeExtensions[$name] = $typeExtensions; return $typeExtensions; }
php
protected function loadTypeExtensions($name) { $typeExtensions = []; $extensions = $this->getExtensions(); foreach ($extensions as $extension) { if ($extension->hasTypeExtensions($name)) { $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($name)); } } $this->typeExtensions[$name] = $typeExtensions; return $typeExtensions; }
[ "protected", "function", "loadTypeExtensions", "(", "$", "name", ")", "{", "$", "typeExtensions", "=", "[", "]", ";", "$", "extensions", "=", "$", "this", "->", "getExtensions", "(", ")", ";", "foreach", "(", "$", "extensions", "as", "$", "extension", ")", "{", "if", "(", "$", "extension", "->", "hasTypeExtensions", "(", "$", "name", ")", ")", "{", "$", "typeExtensions", "=", "array_merge", "(", "$", "typeExtensions", ",", "$", "extension", "->", "getTypeExtensions", "(", "$", "name", ")", ")", ";", "}", "}", "$", "this", "->", "typeExtensions", "[", "$", "name", "]", "=", "$", "typeExtensions", ";", "return", "$", "typeExtensions", ";", "}" ]
@param string $name @return BlockTypeExtensionInterface[]
[ "@param", "string", "$name" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRegistry.php#L233-L246
ekuiter/feature-php
FeaturePhp/Helper/_String.php
_String.truncate
public static function truncate($text, $chars = 60) { if (!$text) return $text; $lines = explode("\n", $text); foreach ($lines as &$line) $line = trim($line); $text = implode(" ", $lines); if (strlen($text) <= $chars) return $text; $text = $text . " "; $text = substr($text, 0, $chars); $text = substr($text, 0, strrpos($text, ' ')); $text = $text . "..."; return $text; }
php
public static function truncate($text, $chars = 60) { if (!$text) return $text; $lines = explode("\n", $text); foreach ($lines as &$line) $line = trim($line); $text = implode(" ", $lines); if (strlen($text) <= $chars) return $text; $text = $text . " "; $text = substr($text, 0, $chars); $text = substr($text, 0, strrpos($text, ' ')); $text = $text . "..."; return $text; }
[ "public", "static", "function", "truncate", "(", "$", "text", ",", "$", "chars", "=", "60", ")", "{", "if", "(", "!", "$", "text", ")", "return", "$", "text", ";", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "text", ")", ";", "foreach", "(", "$", "lines", "as", "&", "$", "line", ")", "$", "line", "=", "trim", "(", "$", "line", ")", ";", "$", "text", "=", "implode", "(", "\" \"", ",", "$", "lines", ")", ";", "if", "(", "strlen", "(", "$", "text", ")", "<=", "$", "chars", ")", "return", "$", "text", ";", "$", "text", "=", "$", "text", ".", "\" \"", ";", "$", "text", "=", "substr", "(", "$", "text", ",", "0", ",", "$", "chars", ")", ";", "$", "text", "=", "substr", "(", "$", "text", ",", "0", ",", "strrpos", "(", "$", "text", ",", "' '", ")", ")", ";", "$", "text", "=", "$", "text", ".", "\"...\"", ";", "return", "$", "text", ";", "}" ]
Truncates a multi-line string. Appends an ellipsis (see {@see https://stackoverflow.com/q/9219795}). @param string $text @param int $chars @return string
[ "Truncates", "a", "multi", "-", "line", "string", ".", "Appends", "an", "ellipsis", "(", "see", "{" ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Helper/_String.php#L21-L37
ekuiter/feature-php
FeaturePhp/Helper/_String.php
_String.getMaxLength
public static function getMaxLength($array, $key) { $maxLen = 0; foreach ($array as $element) { $str = call_user_func(array($element, $key)); $maxLen = strlen($str) > $maxLen ? strlen($str) : $maxLen; } return $maxLen; }
php
public static function getMaxLength($array, $key) { $maxLen = 0; foreach ($array as $element) { $str = call_user_func(array($element, $key)); $maxLen = strlen($str) > $maxLen ? strlen($str) : $maxLen; } return $maxLen; }
[ "public", "static", "function", "getMaxLength", "(", "$", "array", ",", "$", "key", ")", "{", "$", "maxLen", "=", "0", ";", "foreach", "(", "$", "array", "as", "$", "element", ")", "{", "$", "str", "=", "call_user_func", "(", "array", "(", "$", "element", ",", "$", "key", ")", ")", ";", "$", "maxLen", "=", "strlen", "(", "$", "str", ")", ">", "$", "maxLen", "?", "strlen", "(", "$", "str", ")", ":", "$", "maxLen", ";", "}", "return", "$", "maxLen", ";", "}" ]
Returns the maximum member length of an array of objects. @param array $array @param callable $key @return int
[ "Returns", "the", "maximum", "member", "length", "of", "an", "array", "of", "objects", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Helper/_String.php#L45-L52
qlake/framework
src/Qlake/Config/Config.php
Config.aliases
public function aliases(array $aliases = null) { if (is_null($aliases)) { return $this->aliases; } else { $this->aliases = array_merge($this->aliases, $aliases); } }
php
public function aliases(array $aliases = null) { if (is_null($aliases)) { return $this->aliases; } else { $this->aliases = array_merge($this->aliases, $aliases); } }
[ "public", "function", "aliases", "(", "array", "$", "aliases", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "aliases", ")", ")", "{", "return", "$", "this", "->", "aliases", ";", "}", "else", "{", "$", "this", "->", "aliases", "=", "array_merge", "(", "$", "this", "->", "aliases", ",", "$", "aliases", ")", ";", "}", "}" ]
Set or get config aliases @param array $aliases @return array|null
[ "Set", "or", "get", "config", "aliases" ]
train
https://github.com/qlake/framework/blob/0b7bad459ae0721bc5cdd141344f9dfc1acee28a/src/Qlake/Config/Config.php#L48-L58
qlake/framework
src/Qlake/Config/Config.php
Config.alias
public function alias($alias, $path = null) { if (is_null($path)) { return $this->aliases[$alias] ?: null; } else { $this->aliases[$alias] = $path; } }
php
public function alias($alias, $path = null) { if (is_null($path)) { return $this->aliases[$alias] ?: null; } else { $this->aliases[$alias] = $path; } }
[ "public", "function", "alias", "(", "$", "alias", ",", "$", "path", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "path", ")", ")", "{", "return", "$", "this", "->", "aliases", "[", "$", "alias", "]", "?", ":", "null", ";", "}", "else", "{", "$", "this", "->", "aliases", "[", "$", "alias", "]", "=", "$", "path", ";", "}", "}" ]
Set or get a config alias @param string $alias @param string $path @return string|null
[ "Set", "or", "get", "a", "config", "alias" ]
train
https://github.com/qlake/framework/blob/0b7bad459ae0721bc5cdd141344f9dfc1acee28a/src/Qlake/Config/Config.php#L68-L78
qlake/framework
src/Qlake/Config/Config.php
Config.loadConfig
protected function loadConfig($alias, $configName) { if (isset($this->aliases[$alias])) { $aliasPath = $this->aliases[$alias]; } else { throw new ClearException("Config Alias [$alias] Not Found.", 4); } $file = $aliasPath . $configName . '.php'; if (is_file($file)) { return $this->configs[$alias][$configName] = require $file; } throw new ClearException("The Config File [$file] Not Found.", 4); }
php
protected function loadConfig($alias, $configName) { if (isset($this->aliases[$alias])) { $aliasPath = $this->aliases[$alias]; } else { throw new ClearException("Config Alias [$alias] Not Found.", 4); } $file = $aliasPath . $configName . '.php'; if (is_file($file)) { return $this->configs[$alias][$configName] = require $file; } throw new ClearException("The Config File [$file] Not Found.", 4); }
[ "protected", "function", "loadConfig", "(", "$", "alias", ",", "$", "configName", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "aliases", "[", "$", "alias", "]", ")", ")", "{", "$", "aliasPath", "=", "$", "this", "->", "aliases", "[", "$", "alias", "]", ";", "}", "else", "{", "throw", "new", "ClearException", "(", "\"Config Alias [$alias] Not Found.\"", ",", "4", ")", ";", "}", "$", "file", "=", "$", "aliasPath", ".", "$", "configName", ".", "'.php'", ";", "if", "(", "is_file", "(", "$", "file", ")", ")", "{", "return", "$", "this", "->", "configs", "[", "$", "alias", "]", "[", "$", "configName", "]", "=", "require", "$", "file", ";", "}", "throw", "new", "ClearException", "(", "\"The Config File [$file] Not Found.\"", ",", "4", ")", ";", "}" ]
Open and load configs from a file @param string $alias @param string $configName @return array
[ "Open", "and", "load", "configs", "from", "a", "file" ]
train
https://github.com/qlake/framework/blob/0b7bad459ae0721bc5cdd141344f9dfc1acee28a/src/Qlake/Config/Config.php#L111-L130
qlake/framework
src/Qlake/Config/Config.php
Config.get
public function get($mixedKey, $default = null) { list($alias, $configName, $key) = $this->parseKey($mixedKey); if (is_null($key)) { return $this->configs[$alias][$configName] ?: $this->loadConfig($alias, $configName) ?: $default; } return $this->configs[$alias][$configName][$key] ?: $this->loadConfig($alias, $configName)[$key] ?: $default; }
php
public function get($mixedKey, $default = null) { list($alias, $configName, $key) = $this->parseKey($mixedKey); if (is_null($key)) { return $this->configs[$alias][$configName] ?: $this->loadConfig($alias, $configName) ?: $default; } return $this->configs[$alias][$configName][$key] ?: $this->loadConfig($alias, $configName)[$key] ?: $default; }
[ "public", "function", "get", "(", "$", "mixedKey", ",", "$", "default", "=", "null", ")", "{", "list", "(", "$", "alias", ",", "$", "configName", ",", "$", "key", ")", "=", "$", "this", "->", "parseKey", "(", "$", "mixedKey", ")", ";", "if", "(", "is_null", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "configs", "[", "$", "alias", "]", "[", "$", "configName", "]", "?", ":", "$", "this", "->", "loadConfig", "(", "$", "alias", ",", "$", "configName", ")", "?", ":", "$", "default", ";", "}", "return", "$", "this", "->", "configs", "[", "$", "alias", "]", "[", "$", "configName", "]", "[", "$", "key", "]", "?", ":", "$", "this", "->", "loadConfig", "(", "$", "alias", ",", "$", "configName", ")", "[", "$", "key", "]", "?", ":", "$", "default", ";", "}" ]
Get a config @param string $mixedKey May be a key or a config file name @param mixed $default @return array|mixed
[ "Get", "a", "config" ]
train
https://github.com/qlake/framework/blob/0b7bad459ae0721bc5cdd141344f9dfc1acee28a/src/Qlake/Config/Config.php#L140-L150
qlake/framework
src/Qlake/Config/Config.php
Config.set
public function set($mixedKey, $value) { list($alias, $configName, $key) = $this->parseKey($mixedKey); if (is_null($key)) { $this->configs[$alias][$configName] = $value; } $this->configs[$alias][$configName][$key] = $value; }
php
public function set($mixedKey, $value) { list($alias, $configName, $key) = $this->parseKey($mixedKey); if (is_null($key)) { $this->configs[$alias][$configName] = $value; } $this->configs[$alias][$configName][$key] = $value; }
[ "public", "function", "set", "(", "$", "mixedKey", ",", "$", "value", ")", "{", "list", "(", "$", "alias", ",", "$", "configName", ",", "$", "key", ")", "=", "$", "this", "->", "parseKey", "(", "$", "mixedKey", ")", ";", "if", "(", "is_null", "(", "$", "key", ")", ")", "{", "$", "this", "->", "configs", "[", "$", "alias", "]", "[", "$", "configName", "]", "=", "$", "value", ";", "}", "$", "this", "->", "configs", "[", "$", "alias", "]", "[", "$", "configName", "]", "[", "$", "key", "]", "=", "$", "value", ";", "}" ]
Set a config @param string $mixedKey May be a key or a config file name @param mixed $value @return array|mixed
[ "Set", "a", "config" ]
train
https://github.com/qlake/framework/blob/0b7bad459ae0721bc5cdd141344f9dfc1acee28a/src/Qlake/Config/Config.php#L160-L170
qlake/framework
src/Qlake/Config/Config.php
Config.parseKey
protected function parseKey($mixedKey) { if (preg_match('/^((?P<alias>[\w]+)::)?(?P<name>\w+)(\.(?P<key>\w+))?$/', $mixedKey, $matches) !==1) { throw new ClearException("Invalid Config Variable Name. Name Must Be Like [alias::name.key] Or [name.key].", 4); } $alias = $matches['alias']; $name = $matches['name']; $key = $matches['key'] ?: null; return [$alias ?: 'default', $name, $key]; }
php
protected function parseKey($mixedKey) { if (preg_match('/^((?P<alias>[\w]+)::)?(?P<name>\w+)(\.(?P<key>\w+))?$/', $mixedKey, $matches) !==1) { throw new ClearException("Invalid Config Variable Name. Name Must Be Like [alias::name.key] Or [name.key].", 4); } $alias = $matches['alias']; $name = $matches['name']; $key = $matches['key'] ?: null; return [$alias ?: 'default', $name, $key]; }
[ "protected", "function", "parseKey", "(", "$", "mixedKey", ")", "{", "if", "(", "preg_match", "(", "'/^((?P<alias>[\\w]+)::)?(?P<name>\\w+)(\\.(?P<key>\\w+))?$/'", ",", "$", "mixedKey", ",", "$", "matches", ")", "!==", "1", ")", "{", "throw", "new", "ClearException", "(", "\"Invalid Config Variable Name. Name Must Be Like [alias::name.key] Or [name.key].\"", ",", "4", ")", ";", "}", "$", "alias", "=", "$", "matches", "[", "'alias'", "]", ";", "$", "name", "=", "$", "matches", "[", "'name'", "]", ";", "$", "key", "=", "$", "matches", "[", "'key'", "]", "?", ":", "null", ";", "return", "[", "$", "alias", "?", ":", "'default'", ",", "$", "name", ",", "$", "key", "]", ";", "}" ]
Parse requested mixed-key and split alias, name and key @param string $mixedKey @return array An array like [alias, name, key]
[ "Parse", "requested", "mixed", "-", "key", "and", "split", "alias", "name", "and", "key" ]
train
https://github.com/qlake/framework/blob/0b7bad459ae0721bc5cdd141344f9dfc1acee28a/src/Qlake/Config/Config.php#L179-L191
42mate/towel
src/Towel/BaseApp.php
BaseApp.db
public function db($database = null) { if (empty($database)) { $database = $this->database; } return $this->silex['dbs'][$database]; }
php
public function db($database = null) { if (empty($database)) { $database = $this->database; } return $this->silex['dbs'][$database]; }
[ "public", "function", "db", "(", "$", "database", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "database", ")", ")", "{", "$", "database", "=", "$", "this", "->", "database", ";", "}", "return", "$", "this", "->", "silex", "[", "'dbs'", "]", "[", "$", "database", "]", ";", "}" ]
Gets dbal engine. @param string $database : Database to use, check config to see available sources. default is the default source. @return \Doctrine\DBAL\Connection
[ "Gets", "dbal", "engine", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/BaseApp.php#L55-L61
42mate/towel
src/Towel/BaseApp.php
BaseApp.getCurrentUser
public function getCurrentUser() { if (Towel::isCli()) { return false; //Cli is not logged. } $userRecord = $this->session()->get('user', false); if (!$userRecord) { return false; } $userModel = $this->getInstance('user_model'); $userModel->setRecord($userRecord); return $userModel; }
php
public function getCurrentUser() { if (Towel::isCli()) { return false; //Cli is not logged. } $userRecord = $this->session()->get('user', false); if (!$userRecord) { return false; } $userModel = $this->getInstance('user_model'); $userModel->setRecord($userRecord); return $userModel; }
[ "public", "function", "getCurrentUser", "(", ")", "{", "if", "(", "Towel", "::", "isCli", "(", ")", ")", "{", "return", "false", ";", "//Cli is not logged.", "}", "$", "userRecord", "=", "$", "this", "->", "session", "(", ")", "->", "get", "(", "'user'", ",", "false", ")", ";", "if", "(", "!", "$", "userRecord", ")", "{", "return", "false", ";", "}", "$", "userModel", "=", "$", "this", "->", "getInstance", "(", "'user_model'", ")", ";", "$", "userModel", "->", "setRecord", "(", "$", "userRecord", ")", ";", "return", "$", "userModel", ";", "}" ]
Gets the current user or false if is not authenticated. @returns \Towel\Model\BaseModel
[ "Gets", "the", "current", "user", "or", "false", "if", "is", "not", "authenticated", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/BaseApp.php#L97-L112
42mate/towel
src/Towel/BaseApp.php
BaseApp.sendMail
public function sendMail($to, $subject = '', $message = '', $headers = '') { if (empty($headers)) { $headers = 'From: ' . APP_SYS_EMAIL; } mail($to, $subject, $message, $headers); }
php
public function sendMail($to, $subject = '', $message = '', $headers = '') { if (empty($headers)) { $headers = 'From: ' . APP_SYS_EMAIL; } mail($to, $subject, $message, $headers); }
[ "public", "function", "sendMail", "(", "$", "to", ",", "$", "subject", "=", "''", ",", "$", "message", "=", "''", ",", "$", "headers", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "headers", ")", ")", "{", "$", "headers", "=", "'From: '", ".", "APP_SYS_EMAIL", ";", "}", "mail", "(", "$", "to", ",", "$", "subject", ",", "$", "message", ",", "$", "headers", ")", ";", "}" ]
Sends an Email. @param $to @param string $subject @param string $message @param string $headers
[ "Sends", "an", "Email", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/BaseApp.php#L154-L160
42mate/towel
src/Towel/BaseApp.php
BaseApp.path
public function path($route, $parameters = array()) { return $this->silex['url_generator']->generate($route, $parameters, \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_PATH); }
php
public function path($route, $parameters = array()) { return $this->silex['url_generator']->generate($route, $parameters, \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_PATH); }
[ "public", "function", "path", "(", "$", "route", ",", "$", "parameters", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "silex", "[", "'url_generator'", "]", "->", "generate", "(", "$", "route", ",", "$", "parameters", ",", "\\", "Symfony", "\\", "Component", "\\", "Routing", "\\", "Generator", "\\", "UrlGeneratorInterface", "::", "ABSOLUTE_PATH", ")", ";", "}" ]
Generates a path from the given parameters. @param string $route The name of the route @param mixed $parameters An array of parameters @return string The generated path
[ "Generates", "a", "path", "from", "the", "given", "parameters", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/BaseApp.php#L170-L173
42mate/towel
src/Towel/BaseApp.php
BaseApp.url
public function url($route, $parameters = array()) { return $this->silex['url_generator']->generate($route, $parameters, \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_URL); }
php
public function url($route, $parameters = array()) { return $this->silex['url_generator']->generate($route, $parameters, \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_URL); }
[ "public", "function", "url", "(", "$", "route", ",", "$", "parameters", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "silex", "[", "'url_generator'", "]", "->", "generate", "(", "$", "route", ",", "$", "parameters", ",", "\\", "Symfony", "\\", "Component", "\\", "Routing", "\\", "Generator", "\\", "UrlGeneratorInterface", "::", "ABSOLUTE_URL", ")", ";", "}" ]
Generates an absolute URL from the given parameters. @param string $route The name of the route @param mixed $parameters An array of parameters @return string The generated URL
[ "Generates", "an", "absolute", "URL", "from", "the", "given", "parameters", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/BaseApp.php#L183-L186
42mate/towel
src/Towel/BaseApp.php
BaseApp.getCache
public function getCache() { if (null === self::$cache) { if (!empty($this->appConfig['cache']['driver'])) { // Options definition. if (empty($this->appConfig['cache']['options'])) { $options = array(); } else { $options = $this->appConfig['cache']['options']; } // Driver definition. if ('memcached' !== $this->appConfig['cache']['driver']) { $className = $this->appConfig['cache']['driver']; } else { $className = '\Towel\Cache\TowelMemcached'; } // Driver instantiation $cacheDriver = new $className(); $cacheDriver->setOptions($options); } self::$cache = new TowelCache($cacheDriver); } return self::$cache; }
php
public function getCache() { if (null === self::$cache) { if (!empty($this->appConfig['cache']['driver'])) { // Options definition. if (empty($this->appConfig['cache']['options'])) { $options = array(); } else { $options = $this->appConfig['cache']['options']; } // Driver definition. if ('memcached' !== $this->appConfig['cache']['driver']) { $className = $this->appConfig['cache']['driver']; } else { $className = '\Towel\Cache\TowelMemcached'; } // Driver instantiation $cacheDriver = new $className(); $cacheDriver->setOptions($options); } self::$cache = new TowelCache($cacheDriver); } return self::$cache; }
[ "public", "function", "getCache", "(", ")", "{", "if", "(", "null", "===", "self", "::", "$", "cache", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "appConfig", "[", "'cache'", "]", "[", "'driver'", "]", ")", ")", "{", "// Options definition.", "if", "(", "empty", "(", "$", "this", "->", "appConfig", "[", "'cache'", "]", "[", "'options'", "]", ")", ")", "{", "$", "options", "=", "array", "(", ")", ";", "}", "else", "{", "$", "options", "=", "$", "this", "->", "appConfig", "[", "'cache'", "]", "[", "'options'", "]", ";", "}", "// Driver definition.", "if", "(", "'memcached'", "!==", "$", "this", "->", "appConfig", "[", "'cache'", "]", "[", "'driver'", "]", ")", "{", "$", "className", "=", "$", "this", "->", "appConfig", "[", "'cache'", "]", "[", "'driver'", "]", ";", "}", "else", "{", "$", "className", "=", "'\\Towel\\Cache\\TowelMemcached'", ";", "}", "// Driver instantiation", "$", "cacheDriver", "=", "new", "$", "className", "(", ")", ";", "$", "cacheDriver", "->", "setOptions", "(", "$", "options", ")", ";", "}", "self", "::", "$", "cache", "=", "new", "TowelCache", "(", "$", "cacheDriver", ")", ";", "}", "return", "self", "::", "$", "cache", ";", "}" ]
Instantiate Cache driver @return \Towel\Cache\CacheInterface
[ "Instantiate", "Cache", "driver" ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/BaseApp.php#L192-L219
42mate/towel
src/Towel/BaseApp.php
BaseApp.sluggify
public function sluggify($string) { $human_name = strtolower($string); $human_name = str_replace('á', 'a', $human_name); $human_name = str_replace('é', 'e', $human_name); $human_name = str_replace('í', 'i', $human_name); $human_name = str_replace('ó', 'o', $human_name); $human_name = str_replace('ú', 'u', $human_name); $human_name = str_replace('ñ', 'n', $human_name); return preg_replace(array( '/[^a-zA-Z0-9]+/', '/-+/', '/^-+/', '/-+$/', ), array('-', '-', '', ''), $human_name); }
php
public function sluggify($string) { $human_name = strtolower($string); $human_name = str_replace('á', 'a', $human_name); $human_name = str_replace('é', 'e', $human_name); $human_name = str_replace('í', 'i', $human_name); $human_name = str_replace('ó', 'o', $human_name); $human_name = str_replace('ú', 'u', $human_name); $human_name = str_replace('ñ', 'n', $human_name); return preg_replace(array( '/[^a-zA-Z0-9]+/', '/-+/', '/^-+/', '/-+$/', ), array('-', '-', '', ''), $human_name); }
[ "public", "function", "sluggify", "(", "$", "string", ")", "{", "$", "human_name", "=", "strtolower", "(", "$", "string", ")", ";", "$", "human_name", "=", "str_replace", "(", "'á',", " ", "a',", " ", "h", "uman_name)", ";", "", "$", "human_name", "=", "str_replace", "(", "'é',", " ", "e',", " ", "h", "uman_name)", ";", "", "$", "human_name", "=", "str_replace", "(", "'í',", " ", "i',", " ", "h", "uman_name)", ";", "", "$", "human_name", "=", "str_replace", "(", "'ó',", " ", "o',", " ", "h", "uman_name)", ";", "", "$", "human_name", "=", "str_replace", "(", "'ú',", " ", "u',", " ", "h", "uman_name)", ";", "", "$", "human_name", "=", "str_replace", "(", "'ñ',", " ", "n',", " ", "h", "uman_name)", ";", "", "return", "preg_replace", "(", "array", "(", "'/[^a-zA-Z0-9]+/'", ",", "'/-+/'", ",", "'/^-+/'", ",", "'/-+$/'", ",", ")", ",", "array", "(", "'-'", ",", "'-'", ",", "''", ",", "''", ")", ",", "$", "human_name", ")", ";", "}" ]
Generates a machine readable slug of the string. @param $string @return String A machine readable string.
[ "Generates", "a", "machine", "readable", "slug", "of", "the", "string", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/BaseApp.php#L238-L253
heidelpay/PhpDoc
src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php
Xml.createErrorEntry
protected function createErrorEntry($error, $parse_errors) { $marker_obj = new \DOMElement(strtolower($error->getSeverity())); $parse_errors->appendChild($marker_obj); $message = ($this->getTranslator()) ? vsprintf($this->getTranslator()->translate($error->getCode()), $error->getContext()) : $error->getCode(); $marker_obj->appendChild(new \DOMText($message)); $marker_obj->setAttribute('line', $error->getLine()); $marker_obj->setAttribute('code', $error->getCode()); }
php
protected function createErrorEntry($error, $parse_errors) { $marker_obj = new \DOMElement(strtolower($error->getSeverity())); $parse_errors->appendChild($marker_obj); $message = ($this->getTranslator()) ? vsprintf($this->getTranslator()->translate($error->getCode()), $error->getContext()) : $error->getCode(); $marker_obj->appendChild(new \DOMText($message)); $marker_obj->setAttribute('line', $error->getLine()); $marker_obj->setAttribute('code', $error->getCode()); }
[ "protected", "function", "createErrorEntry", "(", "$", "error", ",", "$", "parse_errors", ")", "{", "$", "marker_obj", "=", "new", "\\", "DOMElement", "(", "strtolower", "(", "$", "error", "->", "getSeverity", "(", ")", ")", ")", ";", "$", "parse_errors", "->", "appendChild", "(", "$", "marker_obj", ")", ";", "$", "message", "=", "(", "$", "this", "->", "getTranslator", "(", ")", ")", "?", "vsprintf", "(", "$", "this", "->", "getTranslator", "(", ")", "->", "translate", "(", "$", "error", "->", "getCode", "(", ")", ")", ",", "$", "error", "->", "getContext", "(", ")", ")", ":", "$", "error", "->", "getCode", "(", ")", ";", "$", "marker_obj", "->", "appendChild", "(", "new", "\\", "DOMText", "(", "$", "message", ")", ")", ";", "$", "marker_obj", "->", "setAttribute", "(", "'line'", ",", "$", "error", "->", "getLine", "(", ")", ")", ";", "$", "marker_obj", "->", "setAttribute", "(", "'code'", ",", "$", "error", "->", "getCode", "(", ")", ")", ";", "}" ]
Creates an entry in the ParseErrors collection of a file for a given error. @param Error $error @param \DOMElement $parse_errors @return void
[ "Creates", "an", "entry", "in", "the", "ParseErrors", "collection", "of", "a", "file", "for", "a", "given", "error", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php#L253-L265
heidelpay/PhpDoc
src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php
Xml.buildFunction
public function buildFunction(\DOMElement $parent, FunctionDescriptor $function, \DOMElement $child = null) { if (!$child) { $child = new \DOMElement('function'); $parent->appendChild($child); } $namespace = $function->getNamespace() ? $function->getNamespace() : $parent->getAttribute('namespace'); $child->setAttribute('namespace', ltrim($namespace, '\\')); $child->setAttribute('line', $function->getLine()); $child->appendChild(new \DOMElement('name', $function->getName())); $child->appendChild(new \DOMElement('full_name', $function->getFullyQualifiedStructuralElementName())); $this->docBlockConverter->convert($child, $function); foreach ($function->getArguments() as $argument) { $this->argumentConverter->convert($child, $argument); } }
php
public function buildFunction(\DOMElement $parent, FunctionDescriptor $function, \DOMElement $child = null) { if (!$child) { $child = new \DOMElement('function'); $parent->appendChild($child); } $namespace = $function->getNamespace() ? $function->getNamespace() : $parent->getAttribute('namespace'); $child->setAttribute('namespace', ltrim($namespace, '\\')); $child->setAttribute('line', $function->getLine()); $child->appendChild(new \DOMElement('name', $function->getName())); $child->appendChild(new \DOMElement('full_name', $function->getFullyQualifiedStructuralElementName())); $this->docBlockConverter->convert($child, $function); foreach ($function->getArguments() as $argument) { $this->argumentConverter->convert($child, $argument); } }
[ "public", "function", "buildFunction", "(", "\\", "DOMElement", "$", "parent", ",", "FunctionDescriptor", "$", "function", ",", "\\", "DOMElement", "$", "child", "=", "null", ")", "{", "if", "(", "!", "$", "child", ")", "{", "$", "child", "=", "new", "\\", "DOMElement", "(", "'function'", ")", ";", "$", "parent", "->", "appendChild", "(", "$", "child", ")", ";", "}", "$", "namespace", "=", "$", "function", "->", "getNamespace", "(", ")", "?", "$", "function", "->", "getNamespace", "(", ")", ":", "$", "parent", "->", "getAttribute", "(", "'namespace'", ")", ";", "$", "child", "->", "setAttribute", "(", "'namespace'", ",", "ltrim", "(", "$", "namespace", ",", "'\\\\'", ")", ")", ";", "$", "child", "->", "setAttribute", "(", "'line'", ",", "$", "function", "->", "getLine", "(", ")", ")", ";", "$", "child", "->", "appendChild", "(", "new", "\\", "DOMElement", "(", "'name'", ",", "$", "function", "->", "getName", "(", ")", ")", ")", ";", "$", "child", "->", "appendChild", "(", "new", "\\", "DOMElement", "(", "'full_name'", ",", "$", "function", "->", "getFullyQualifiedStructuralElementName", "(", ")", ")", ")", ";", "$", "this", "->", "docBlockConverter", "->", "convert", "(", "$", "child", ",", "$", "function", ")", ";", "foreach", "(", "$", "function", "->", "getArguments", "(", ")", "as", "$", "argument", ")", "{", "$", "this", "->", "argumentConverter", "->", "convert", "(", "$", "child", ",", "$", "argument", ")", ";", "}", "}" ]
Export this function definition to the given parent DOMElement. @param \DOMElement $parent Element to augment. @param FunctionDescriptor $function Element to export. @param \DOMElement $child if supplied this element will be augmented instead of freshly added. @return void
[ "Export", "this", "function", "definition", "to", "the", "given", "parent", "DOMElement", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php#L289-L310
heidelpay/PhpDoc
src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php
Xml.buildClass
public function buildClass(\DOMElement $parent, ClassDescriptor $class, \DOMElement $child = null) { if (!$child) { $child = new \DOMElement('class'); $parent->appendChild($child); } $child->setAttribute('final', $class->isFinal() ? 'true' : 'false'); $child->setAttribute('abstract', $class->isAbstract() ? 'true' : 'false'); $parentFqcn = is_string($class->getParent()) ? $class->getParent() : $class->getParent()->getFullyQualifiedStructuralElementName(); $child->appendChild(new \DOMElement('extends', $parentFqcn)); /** @var InterfaceDescriptor $interface */ foreach ($class->getInterfaces() as $interface) { $interfaceFqcn = is_string($interface) ? $interface : $interface->getFullyQualifiedStructuralElementName(); $child->appendChild(new \DOMElement('implements', $interfaceFqcn)); } if ($child === null) { $child = new \DOMElement('interface'); $parent->appendChild($child); } $namespace = $class->getNamespace()->getFullyQualifiedStructuralElementName(); $child->setAttribute('namespace', ltrim($namespace, '\\')); $child->setAttribute('line', $class->getLine()); $child->appendChild(new \DOMElement('name', $class->getName())); $child->appendChild(new \DOMElement('full_name', $class->getFullyQualifiedStructuralElementName())); $this->docBlockConverter->convert($child, $class); foreach ($class->getConstants() as $constant) { // TODO #840: Workaround; for some reason there are NULLs in the constants array. if ($constant) { $this->constantConverter->convert($child, $constant); } } foreach ($class->getInheritedConstants() as $constant) { // TODO #840: Workaround; for some reason there are NULLs in the constants array. if ($constant) { $this->constantConverter->convert($child, $constant); } } foreach ($class->getProperties() as $property) { // TODO #840: Workaround; for some reason there are NULLs in the properties array. if ($property) { $this->propertyConverter->convert($child, $property); } } foreach ($class->getInheritedProperties() as $property) { // TODO #840: Workaround; for some reason there are NULLs in the properties array. if ($property) { $this->propertyConverter->convert($child, $property); } } foreach ($class->getMethods() as $method) { // TODO #840: Workaround; for some reason there are NULLs in the methods array. if ($method) { $this->methodConverter->convert($child, $method); } } foreach ($class->getInheritedMethods() as $method) { // TODO #840: Workaround; for some reason there are NULLs in the methods array. if ($method) { $methodElement = $this->methodConverter->convert($child, $method); $methodElement->appendChild( new \DOMElement( 'inherited_from', $method->getParent()->getFullyQualifiedStructuralElementName() ) ); } } }
php
public function buildClass(\DOMElement $parent, ClassDescriptor $class, \DOMElement $child = null) { if (!$child) { $child = new \DOMElement('class'); $parent->appendChild($child); } $child->setAttribute('final', $class->isFinal() ? 'true' : 'false'); $child->setAttribute('abstract', $class->isAbstract() ? 'true' : 'false'); $parentFqcn = is_string($class->getParent()) ? $class->getParent() : $class->getParent()->getFullyQualifiedStructuralElementName(); $child->appendChild(new \DOMElement('extends', $parentFqcn)); /** @var InterfaceDescriptor $interface */ foreach ($class->getInterfaces() as $interface) { $interfaceFqcn = is_string($interface) ? $interface : $interface->getFullyQualifiedStructuralElementName(); $child->appendChild(new \DOMElement('implements', $interfaceFqcn)); } if ($child === null) { $child = new \DOMElement('interface'); $parent->appendChild($child); } $namespace = $class->getNamespace()->getFullyQualifiedStructuralElementName(); $child->setAttribute('namespace', ltrim($namespace, '\\')); $child->setAttribute('line', $class->getLine()); $child->appendChild(new \DOMElement('name', $class->getName())); $child->appendChild(new \DOMElement('full_name', $class->getFullyQualifiedStructuralElementName())); $this->docBlockConverter->convert($child, $class); foreach ($class->getConstants() as $constant) { // TODO #840: Workaround; for some reason there are NULLs in the constants array. if ($constant) { $this->constantConverter->convert($child, $constant); } } foreach ($class->getInheritedConstants() as $constant) { // TODO #840: Workaround; for some reason there are NULLs in the constants array. if ($constant) { $this->constantConverter->convert($child, $constant); } } foreach ($class->getProperties() as $property) { // TODO #840: Workaround; for some reason there are NULLs in the properties array. if ($property) { $this->propertyConverter->convert($child, $property); } } foreach ($class->getInheritedProperties() as $property) { // TODO #840: Workaround; for some reason there are NULLs in the properties array. if ($property) { $this->propertyConverter->convert($child, $property); } } foreach ($class->getMethods() as $method) { // TODO #840: Workaround; for some reason there are NULLs in the methods array. if ($method) { $this->methodConverter->convert($child, $method); } } foreach ($class->getInheritedMethods() as $method) { // TODO #840: Workaround; for some reason there are NULLs in the methods array. if ($method) { $methodElement = $this->methodConverter->convert($child, $method); $methodElement->appendChild( new \DOMElement( 'inherited_from', $method->getParent()->getFullyQualifiedStructuralElementName() ) ); } } }
[ "public", "function", "buildClass", "(", "\\", "DOMElement", "$", "parent", ",", "ClassDescriptor", "$", "class", ",", "\\", "DOMElement", "$", "child", "=", "null", ")", "{", "if", "(", "!", "$", "child", ")", "{", "$", "child", "=", "new", "\\", "DOMElement", "(", "'class'", ")", ";", "$", "parent", "->", "appendChild", "(", "$", "child", ")", ";", "}", "$", "child", "->", "setAttribute", "(", "'final'", ",", "$", "class", "->", "isFinal", "(", ")", "?", "'true'", ":", "'false'", ")", ";", "$", "child", "->", "setAttribute", "(", "'abstract'", ",", "$", "class", "->", "isAbstract", "(", ")", "?", "'true'", ":", "'false'", ")", ";", "$", "parentFqcn", "=", "is_string", "(", "$", "class", "->", "getParent", "(", ")", ")", "?", "$", "class", "->", "getParent", "(", ")", ":", "$", "class", "->", "getParent", "(", ")", "->", "getFullyQualifiedStructuralElementName", "(", ")", ";", "$", "child", "->", "appendChild", "(", "new", "\\", "DOMElement", "(", "'extends'", ",", "$", "parentFqcn", ")", ")", ";", "/** @var InterfaceDescriptor $interface */", "foreach", "(", "$", "class", "->", "getInterfaces", "(", ")", "as", "$", "interface", ")", "{", "$", "interfaceFqcn", "=", "is_string", "(", "$", "interface", ")", "?", "$", "interface", ":", "$", "interface", "->", "getFullyQualifiedStructuralElementName", "(", ")", ";", "$", "child", "->", "appendChild", "(", "new", "\\", "DOMElement", "(", "'implements'", ",", "$", "interfaceFqcn", ")", ")", ";", "}", "if", "(", "$", "child", "===", "null", ")", "{", "$", "child", "=", "new", "\\", "DOMElement", "(", "'interface'", ")", ";", "$", "parent", "->", "appendChild", "(", "$", "child", ")", ";", "}", "$", "namespace", "=", "$", "class", "->", "getNamespace", "(", ")", "->", "getFullyQualifiedStructuralElementName", "(", ")", ";", "$", "child", "->", "setAttribute", "(", "'namespace'", ",", "ltrim", "(", "$", "namespace", ",", "'\\\\'", ")", ")", ";", "$", "child", "->", "setAttribute", "(", "'line'", ",", "$", "class", "->", "getLine", "(", ")", ")", ";", "$", "child", "->", "appendChild", "(", "new", "\\", "DOMElement", "(", "'name'", ",", "$", "class", "->", "getName", "(", ")", ")", ")", ";", "$", "child", "->", "appendChild", "(", "new", "\\", "DOMElement", "(", "'full_name'", ",", "$", "class", "->", "getFullyQualifiedStructuralElementName", "(", ")", ")", ")", ";", "$", "this", "->", "docBlockConverter", "->", "convert", "(", "$", "child", ",", "$", "class", ")", ";", "foreach", "(", "$", "class", "->", "getConstants", "(", ")", "as", "$", "constant", ")", "{", "// TODO #840: Workaround; for some reason there are NULLs in the constants array.", "if", "(", "$", "constant", ")", "{", "$", "this", "->", "constantConverter", "->", "convert", "(", "$", "child", ",", "$", "constant", ")", ";", "}", "}", "foreach", "(", "$", "class", "->", "getInheritedConstants", "(", ")", "as", "$", "constant", ")", "{", "// TODO #840: Workaround; for some reason there are NULLs in the constants array.", "if", "(", "$", "constant", ")", "{", "$", "this", "->", "constantConverter", "->", "convert", "(", "$", "child", ",", "$", "constant", ")", ";", "}", "}", "foreach", "(", "$", "class", "->", "getProperties", "(", ")", "as", "$", "property", ")", "{", "// TODO #840: Workaround; for some reason there are NULLs in the properties array.", "if", "(", "$", "property", ")", "{", "$", "this", "->", "propertyConverter", "->", "convert", "(", "$", "child", ",", "$", "property", ")", ";", "}", "}", "foreach", "(", "$", "class", "->", "getInheritedProperties", "(", ")", "as", "$", "property", ")", "{", "// TODO #840: Workaround; for some reason there are NULLs in the properties array.", "if", "(", "$", "property", ")", "{", "$", "this", "->", "propertyConverter", "->", "convert", "(", "$", "child", ",", "$", "property", ")", ";", "}", "}", "foreach", "(", "$", "class", "->", "getMethods", "(", ")", "as", "$", "method", ")", "{", "// TODO #840: Workaround; for some reason there are NULLs in the methods array.", "if", "(", "$", "method", ")", "{", "$", "this", "->", "methodConverter", "->", "convert", "(", "$", "child", ",", "$", "method", ")", ";", "}", "}", "foreach", "(", "$", "class", "->", "getInheritedMethods", "(", ")", "as", "$", "method", ")", "{", "// TODO #840: Workaround; for some reason there are NULLs in the methods array.", "if", "(", "$", "method", ")", "{", "$", "methodElement", "=", "$", "this", "->", "methodConverter", "->", "convert", "(", "$", "child", ",", "$", "method", ")", ";", "$", "methodElement", "->", "appendChild", "(", "new", "\\", "DOMElement", "(", "'inherited_from'", ",", "$", "method", "->", "getParent", "(", ")", "->", "getFullyQualifiedStructuralElementName", "(", ")", ")", ")", ";", "}", "}", "}" ]
Exports the given reflection object to the parent XML element. This method creates a new child element on the given parent XML element and takes the properties of the Reflection argument and sets the elements and attributes on the child. If a child DOMElement is provided then the properties and attributes are set on this but the child element is not appended onto the parent. This is the responsibility of the invoker. Essentially this means that the $parent argument is ignored in this case. @param \DOMElement $parent The parent element to augment. @param ClassDescriptor $class The data source. @param \DOMElement $child Optional: child element to use instead of creating a new one on the $parent. @return void
[ "Exports", "the", "given", "reflection", "object", "to", "the", "parent", "XML", "element", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php#L331-L415
heidelpay/PhpDoc
src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php
Xml.buildPackageTree
protected function buildPackageTree(\DOMDocument $dom) { $xpath = new \DOMXPath($dom); $packages = array('global' => true); $qry = $xpath->query('//@package'); for ($i = 0; $i < $qry->length; $i++) { if (isset($packages[$qry->item($i)->nodeValue])) { continue; } $packages[$qry->item($i)->nodeValue] = true; } $packages = $this->generateNamespaceTree(array_keys($packages)); $this->generateNamespaceElements($packages, $dom->documentElement, 'package'); }
php
protected function buildPackageTree(\DOMDocument $dom) { $xpath = new \DOMXPath($dom); $packages = array('global' => true); $qry = $xpath->query('//@package'); for ($i = 0; $i < $qry->length; $i++) { if (isset($packages[$qry->item($i)->nodeValue])) { continue; } $packages[$qry->item($i)->nodeValue] = true; } $packages = $this->generateNamespaceTree(array_keys($packages)); $this->generateNamespaceElements($packages, $dom->documentElement, 'package'); }
[ "protected", "function", "buildPackageTree", "(", "\\", "DOMDocument", "$", "dom", ")", "{", "$", "xpath", "=", "new", "\\", "DOMXPath", "(", "$", "dom", ")", ";", "$", "packages", "=", "array", "(", "'global'", "=>", "true", ")", ";", "$", "qry", "=", "$", "xpath", "->", "query", "(", "'//@package'", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "qry", "->", "length", ";", "$", "i", "++", ")", "{", "if", "(", "isset", "(", "$", "packages", "[", "$", "qry", "->", "item", "(", "$", "i", ")", "->", "nodeValue", "]", ")", ")", "{", "continue", ";", "}", "$", "packages", "[", "$", "qry", "->", "item", "(", "$", "i", ")", "->", "nodeValue", "]", "=", "true", ";", "}", "$", "packages", "=", "$", "this", "->", "generateNamespaceTree", "(", "array_keys", "(", "$", "packages", ")", ")", ";", "$", "this", "->", "generateNamespaceElements", "(", "$", "packages", ",", "$", "dom", "->", "documentElement", ",", "'package'", ")", ";", "}" ]
Collects all packages and subpackages, and adds a new section in the DOM to provide an overview. @param \DOMDocument $dom Packages are extracted and a summary inserted in this object. @return void
[ "Collects", "all", "packages", "and", "subpackages", "and", "adds", "a", "new", "section", "in", "the", "DOM", "to", "provide", "an", "overview", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php#L474-L489
heidelpay/PhpDoc
src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php
Xml.buildNamespaceTree
protected function buildNamespaceTree(\DOMDocument $dom) { $xpath = new \DOMXPath($dom); $namespaces = array(); $qry = $xpath->query('//@namespace'); for ($i = 0; $i < $qry->length; $i++) { if (isset($namespaces[$qry->item($i)->nodeValue])) { continue; } $namespaces[$qry->item($i)->nodeValue] = true; } $namespaces = $this->generateNamespaceTree(array_keys($namespaces)); $this->generateNamespaceElements($namespaces, $dom->documentElement); }
php
protected function buildNamespaceTree(\DOMDocument $dom) { $xpath = new \DOMXPath($dom); $namespaces = array(); $qry = $xpath->query('//@namespace'); for ($i = 0; $i < $qry->length; $i++) { if (isset($namespaces[$qry->item($i)->nodeValue])) { continue; } $namespaces[$qry->item($i)->nodeValue] = true; } $namespaces = $this->generateNamespaceTree(array_keys($namespaces)); $this->generateNamespaceElements($namespaces, $dom->documentElement); }
[ "protected", "function", "buildNamespaceTree", "(", "\\", "DOMDocument", "$", "dom", ")", "{", "$", "xpath", "=", "new", "\\", "DOMXPath", "(", "$", "dom", ")", ";", "$", "namespaces", "=", "array", "(", ")", ";", "$", "qry", "=", "$", "xpath", "->", "query", "(", "'//@namespace'", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "qry", "->", "length", ";", "$", "i", "++", ")", "{", "if", "(", "isset", "(", "$", "namespaces", "[", "$", "qry", "->", "item", "(", "$", "i", ")", "->", "nodeValue", "]", ")", ")", "{", "continue", ";", "}", "$", "namespaces", "[", "$", "qry", "->", "item", "(", "$", "i", ")", "->", "nodeValue", "]", "=", "true", ";", "}", "$", "namespaces", "=", "$", "this", "->", "generateNamespaceTree", "(", "array_keys", "(", "$", "namespaces", ")", ")", ";", "$", "this", "->", "generateNamespaceElements", "(", "$", "namespaces", ",", "$", "dom", "->", "documentElement", ")", ";", "}" ]
Collects all namespaces and sub-namespaces, and adds a new section in the DOM to provide an overview. @param \DOMDocument $dom Namespaces are extracted and a summary inserted in this object. @return void
[ "Collects", "all", "namespaces", "and", "sub", "-", "namespaces", "and", "adds", "a", "new", "section", "in", "the", "DOM", "to", "provide", "an", "overview", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php#L500-L515
heidelpay/PhpDoc
src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php
Xml.generateNamespaceTree
protected function generateNamespaceTree($namespaces) { sort($namespaces); $result = array(); foreach ($namespaces as $namespace) { if (!$namespace) { $namespace = 'global'; } $namespace_list = explode('\\', $namespace); $node = &$result; foreach ($namespace_list as $singular) { if (!isset($node[$singular])) { $node[$singular] = array(); } $node = &$node[$singular]; } } return $result; }
php
protected function generateNamespaceTree($namespaces) { sort($namespaces); $result = array(); foreach ($namespaces as $namespace) { if (!$namespace) { $namespace = 'global'; } $namespace_list = explode('\\', $namespace); $node = &$result; foreach ($namespace_list as $singular) { if (!isset($node[$singular])) { $node[$singular] = array(); } $node = &$node[$singular]; } } return $result; }
[ "protected", "function", "generateNamespaceTree", "(", "$", "namespaces", ")", "{", "sort", "(", "$", "namespaces", ")", ";", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "namespaces", "as", "$", "namespace", ")", "{", "if", "(", "!", "$", "namespace", ")", "{", "$", "namespace", "=", "'global'", ";", "}", "$", "namespace_list", "=", "explode", "(", "'\\\\'", ",", "$", "namespace", ")", ";", "$", "node", "=", "&", "$", "result", ";", "foreach", "(", "$", "namespace_list", "as", "$", "singular", ")", "{", "if", "(", "!", "isset", "(", "$", "node", "[", "$", "singular", "]", ")", ")", "{", "$", "node", "[", "$", "singular", "]", "=", "array", "(", ")", ";", "}", "$", "node", "=", "&", "$", "node", "[", "$", "singular", "]", ";", "}", "}", "return", "$", "result", ";", "}" ]
Generates a hierarchical array of namespaces with their singular name from a single level list of namespaces with their full name. @param array $namespaces the list of namespaces as retrieved from the xml. @return array
[ "Generates", "a", "hierarchical", "array", "of", "namespaces", "with", "their", "singular", "name", "from", "a", "single", "level", "list", "of", "namespaces", "with", "their", "full", "name", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php#L568-L591
heidelpay/PhpDoc
src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php
Xml.generateNamespaceElements
protected function generateNamespaceElements($namespaces, $parent_element, $node_name = 'namespace') { foreach ($namespaces as $name => $sub_namespaces) { $node = new \DOMElement($node_name); $parent_element->appendChild($node); $node->setAttribute('name', $name); $fullName = $parent_element->nodeName == $node_name ? $parent_element->getAttribute('full_name') . '\\' . $name : $name; $node->setAttribute('full_name', $fullName); $this->generateNamespaceElements($sub_namespaces, $node, $node_name); } }
php
protected function generateNamespaceElements($namespaces, $parent_element, $node_name = 'namespace') { foreach ($namespaces as $name => $sub_namespaces) { $node = new \DOMElement($node_name); $parent_element->appendChild($node); $node->setAttribute('name', $name); $fullName = $parent_element->nodeName == $node_name ? $parent_element->getAttribute('full_name') . '\\' . $name : $name; $node->setAttribute('full_name', $fullName); $this->generateNamespaceElements($sub_namespaces, $node, $node_name); } }
[ "protected", "function", "generateNamespaceElements", "(", "$", "namespaces", ",", "$", "parent_element", ",", "$", "node_name", "=", "'namespace'", ")", "{", "foreach", "(", "$", "namespaces", "as", "$", "name", "=>", "$", "sub_namespaces", ")", "{", "$", "node", "=", "new", "\\", "DOMElement", "(", "$", "node_name", ")", ";", "$", "parent_element", "->", "appendChild", "(", "$", "node", ")", ";", "$", "node", "->", "setAttribute", "(", "'name'", ",", "$", "name", ")", ";", "$", "fullName", "=", "$", "parent_element", "->", "nodeName", "==", "$", "node_name", "?", "$", "parent_element", "->", "getAttribute", "(", "'full_name'", ")", ".", "'\\\\'", ".", "$", "name", ":", "$", "name", ";", "$", "node", "->", "setAttribute", "(", "'full_name'", ",", "$", "fullName", ")", ";", "$", "this", "->", "generateNamespaceElements", "(", "$", "sub_namespaces", ",", "$", "node", ",", "$", "node_name", ")", ";", "}", "}" ]
Recursive method to create a hierarchical set of nodes in the dom. @param array[] $namespaces the list of namespaces to process. @param \DOMElement $parent_element the node to receive the children of the above list. @param string $node_name the name of the summary element. @return void
[ "Recursive", "method", "to", "create", "a", "hierarchical", "set", "of", "nodes", "in", "the", "dom", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php#L603-L615
yosymfony/ConfigServiceProvider
src/Yosymfony/Silex/ConfigServiceProvider/ConfigFileLoader.php
ConfigFileLoader.getLocation
public function getLocation($resource) { if(false === $this->isDistExtension($resource)) { try { return $this->getLocator()->locate($resource, null, true); } catch (\InvalidArgumentException $ex) { $resource = $resource . '.dist'; } } return $this->getLocator()->locate($resource, null, true); }
php
public function getLocation($resource) { if(false === $this->isDistExtension($resource)) { try { return $this->getLocator()->locate($resource, null, true); } catch (\InvalidArgumentException $ex) { $resource = $resource . '.dist'; } } return $this->getLocator()->locate($resource, null, true); }
[ "public", "function", "getLocation", "(", "$", "resource", ")", "{", "if", "(", "false", "===", "$", "this", "->", "isDistExtension", "(", "$", "resource", ")", ")", "{", "try", "{", "return", "$", "this", "->", "getLocator", "(", ")", "->", "locate", "(", "$", "resource", ",", "null", ",", "true", ")", ";", "}", "catch", "(", "\\", "InvalidArgumentException", "$", "ex", ")", "{", "$", "resource", "=", "$", "resource", ".", "'.dist'", ";", "}", "}", "return", "$", "this", "->", "getLocator", "(", ")", "->", "locate", "(", "$", "resource", ",", "null", ",", "true", ")", ";", "}" ]
Get the location of a file resource follow the next hierachy: 1. filename.ext 2. filename.ext.dist (if filename.ext not exists) or filename.ext.dist if the .dist is included in the resource. @param string $resource Filename path @return string @throws \InvalidArgumentException When the file is not found
[ "Get", "the", "location", "of", "a", "file", "resource", "follow", "the", "next", "hierachy", ":", "1", ".", "filename", ".", "ext", "2", ".", "filename", ".", "ext", ".", "dist", "(", "if", "filename", ".", "ext", "not", "exists", ")" ]
train
https://github.com/yosymfony/ConfigServiceProvider/blob/f6cb9a9fc707b6c92e0d03201e5ecc17eaee3114/src/Yosymfony/Silex/ConfigServiceProvider/ConfigFileLoader.php#L38-L53
hametuha/wpametu
src/WPametu/Service/Recaptcha.php
Recaptcha.get_html
public function get_html($theme = 'light', $lang = 'en', $type = 'image'){ if( $this->enabled ){ // Option value $option = []; // Select theme switch($theme){ case 'dark': $option['theme'] = $theme; break; case 'red': default: $option['theme'] = 'light'; // Do nothing break; } // Select image switch( $type ){ case 'audio': $option['type'] = $type; break; default: $option['type'] = 'image'; break; } // Select language switch($lang){ case 'ar': case 'bg': case 'ca': case 'zh-CN': case 'zh-TW': case 'hr': case 'cs': case 'da': case 'nl': case 'en-GB': case 'en': case 'fil': case 'fi': case 'fr': case 'fr-CA': case 'de': case 'de-AT': case 'de-CH': case 'el': case 'iw': case 'hi': case 'hu': case 'id': case 'it': case 'ja': case 'ko': case 'lv': case 'lt': case 'no': case 'fa': case 'pl': case 'pt': case 'pt-BR': case 'pt-PT': case 'ro': case 'ru': case 'sr': case 'sk': case 'sl': case 'es': case 'es-419': case 'sv': case 'th': case 'tr': case 'uk': case 'vi': $option['lang'] = $lang; break; default: // Do nothing $option['lang'] = 'en'; break; } /** * wpametu_recaptcha_setting * * Filter option to set for reCaptcha * * @param array $option * @return array */ $option = apply_filters('wpametu_recaptcha_setting', $option); $script = '<script src="https://www.google.com/recaptcha/api.js?hl='.$option['lang'].'" async defer></script>'; $html = <<<HTML <div class="g-recaptcha" data-sitekey="%s" data-theme="%s" data-type="%s"></div> HTML; return $script.sprintf($html, constant(self::PUBLIC_KEY), $option['theme'], $option['type']); }else{ return false; } }
php
public function get_html($theme = 'light', $lang = 'en', $type = 'image'){ if( $this->enabled ){ // Option value $option = []; // Select theme switch($theme){ case 'dark': $option['theme'] = $theme; break; case 'red': default: $option['theme'] = 'light'; // Do nothing break; } // Select image switch( $type ){ case 'audio': $option['type'] = $type; break; default: $option['type'] = 'image'; break; } // Select language switch($lang){ case 'ar': case 'bg': case 'ca': case 'zh-CN': case 'zh-TW': case 'hr': case 'cs': case 'da': case 'nl': case 'en-GB': case 'en': case 'fil': case 'fi': case 'fr': case 'fr-CA': case 'de': case 'de-AT': case 'de-CH': case 'el': case 'iw': case 'hi': case 'hu': case 'id': case 'it': case 'ja': case 'ko': case 'lv': case 'lt': case 'no': case 'fa': case 'pl': case 'pt': case 'pt-BR': case 'pt-PT': case 'ro': case 'ru': case 'sr': case 'sk': case 'sl': case 'es': case 'es-419': case 'sv': case 'th': case 'tr': case 'uk': case 'vi': $option['lang'] = $lang; break; default: // Do nothing $option['lang'] = 'en'; break; } /** * wpametu_recaptcha_setting * * Filter option to set for reCaptcha * * @param array $option * @return array */ $option = apply_filters('wpametu_recaptcha_setting', $option); $script = '<script src="https://www.google.com/recaptcha/api.js?hl='.$option['lang'].'" async defer></script>'; $html = <<<HTML <div class="g-recaptcha" data-sitekey="%s" data-theme="%s" data-type="%s"></div> HTML; return $script.sprintf($html, constant(self::PUBLIC_KEY), $option['theme'], $option['type']); }else{ return false; } }
[ "public", "function", "get_html", "(", "$", "theme", "=", "'light'", ",", "$", "lang", "=", "'en'", ",", "$", "type", "=", "'image'", ")", "{", "if", "(", "$", "this", "->", "enabled", ")", "{", "// Option value", "$", "option", "=", "[", "]", ";", "// Select theme", "switch", "(", "$", "theme", ")", "{", "case", "'dark'", ":", "$", "option", "[", "'theme'", "]", "=", "$", "theme", ";", "break", ";", "case", "'red'", ":", "default", ":", "$", "option", "[", "'theme'", "]", "=", "'light'", ";", "// Do nothing", "break", ";", "}", "// Select image", "switch", "(", "$", "type", ")", "{", "case", "'audio'", ":", "$", "option", "[", "'type'", "]", "=", "$", "type", ";", "break", ";", "default", ":", "$", "option", "[", "'type'", "]", "=", "'image'", ";", "break", ";", "}", "// Select language", "switch", "(", "$", "lang", ")", "{", "case", "'ar'", ":", "case", "'bg'", ":", "case", "'ca'", ":", "case", "'zh-CN'", ":", "case", "'zh-TW'", ":", "case", "'hr'", ":", "case", "'cs'", ":", "case", "'da'", ":", "case", "'nl'", ":", "case", "'en-GB'", ":", "case", "'en'", ":", "case", "'fil'", ":", "case", "'fi'", ":", "case", "'fr'", ":", "case", "'fr-CA'", ":", "case", "'de'", ":", "case", "'de-AT'", ":", "case", "'de-CH'", ":", "case", "'el'", ":", "case", "'iw'", ":", "case", "'hi'", ":", "case", "'hu'", ":", "case", "'id'", ":", "case", "'it'", ":", "case", "'ja'", ":", "case", "'ko'", ":", "case", "'lv'", ":", "case", "'lt'", ":", "case", "'no'", ":", "case", "'fa'", ":", "case", "'pl'", ":", "case", "'pt'", ":", "case", "'pt-BR'", ":", "case", "'pt-PT'", ":", "case", "'ro'", ":", "case", "'ru'", ":", "case", "'sr'", ":", "case", "'sk'", ":", "case", "'sl'", ":", "case", "'es'", ":", "case", "'es-419'", ":", "case", "'sv'", ":", "case", "'th'", ":", "case", "'tr'", ":", "case", "'uk'", ":", "case", "'vi'", ":", "$", "option", "[", "'lang'", "]", "=", "$", "lang", ";", "break", ";", "default", ":", "// Do nothing", "$", "option", "[", "'lang'", "]", "=", "'en'", ";", "break", ";", "}", "/**\n * wpametu_recaptcha_setting\n *\n * Filter option to set for reCaptcha\n *\n * @param array $option\n * @return array\n */", "$", "option", "=", "apply_filters", "(", "'wpametu_recaptcha_setting'", ",", "$", "option", ")", ";", "$", "script", "=", "'<script src=\"https://www.google.com/recaptcha/api.js?hl='", ".", "$", "option", "[", "'lang'", "]", ".", "'\" async defer></script>'", ";", "$", "html", "=", " <<<HTML\n<div class=\"g-recaptcha\" data-sitekey=\"%s\" data-theme=\"%s\" data-type=\"%s\"></div>\nHTML", ";", "return", "$", "script", ".", "sprintf", "(", "$", "html", ",", "constant", "(", "self", "::", "PUBLIC_KEY", ")", ",", "$", "option", "[", "'theme'", "]", ",", "$", "option", "[", "'type'", "]", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Return reCaptcha's HTML @link https://developers.google.com/recaptcha/docs/language @param string $theme light(default), dark @param string $lang en(default), fr, nl, de, pt, ru, es, tr, ja and more. @param string $type image(default) audio @return string|false
[ "Return", "reCaptcha", "s", "HTML" ]
train
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/Service/Recaptcha.php#L70-L167
hametuha/wpametu
src/WPametu/Service/Recaptcha.php
Recaptcha.validate
public function validate(){ if( $this->enabled && ($response = $this->input->request('g-recaptcha-response')) && $this->input->remote_ip() ){ $endpoint = sprintf('https://www.google.com/recaptcha/api/siteverify?secret=%s&response=%s&remoteip=%s', constant(self::PRIVATE_KEY), rawurlencode($response), rawurlencode($this->input->remote_ip())); $response = wp_remote_get($endpoint); if( is_wp_error($response) ){ return false; } $result = json_decode($response['body']); return isset($result->success) && $result->success; }else{ return false; } }
php
public function validate(){ if( $this->enabled && ($response = $this->input->request('g-recaptcha-response')) && $this->input->remote_ip() ){ $endpoint = sprintf('https://www.google.com/recaptcha/api/siteverify?secret=%s&response=%s&remoteip=%s', constant(self::PRIVATE_KEY), rawurlencode($response), rawurlencode($this->input->remote_ip())); $response = wp_remote_get($endpoint); if( is_wp_error($response) ){ return false; } $result = json_decode($response['body']); return isset($result->success) && $result->success; }else{ return false; } }
[ "public", "function", "validate", "(", ")", "{", "if", "(", "$", "this", "->", "enabled", "&&", "(", "$", "response", "=", "$", "this", "->", "input", "->", "request", "(", "'g-recaptcha-response'", ")", ")", "&&", "$", "this", "->", "input", "->", "remote_ip", "(", ")", ")", "{", "$", "endpoint", "=", "sprintf", "(", "'https://www.google.com/recaptcha/api/siteverify?secret=%s&response=%s&remoteip=%s'", ",", "constant", "(", "self", "::", "PRIVATE_KEY", ")", ",", "rawurlencode", "(", "$", "response", ")", ",", "rawurlencode", "(", "$", "this", "->", "input", "->", "remote_ip", "(", ")", ")", ")", ";", "$", "response", "=", "wp_remote_get", "(", "$", "endpoint", ")", ";", "if", "(", "is_wp_error", "(", "$", "response", ")", ")", "{", "return", "false", ";", "}", "$", "result", "=", "json_decode", "(", "$", "response", "[", "'body'", "]", ")", ";", "return", "isset", "(", "$", "result", "->", "success", ")", "&&", "$", "result", "->", "success", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Validate reCaptcha @return bool
[ "Validate", "reCaptcha" ]
train
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/Service/Recaptcha.php#L174-L187
Speicher210/monsum-api
src/Model/Subscription.php
Subscription.isRunning
public function isRunning() { $runningStatuses = [ self::SUBSCRIPTION_STATUS_ACTIVE, self::SUBSCRIPTION_STATUS_TRIAL, ]; return in_array($this->getStatus(), $runningStatuses, true); }
php
public function isRunning() { $runningStatuses = [ self::SUBSCRIPTION_STATUS_ACTIVE, self::SUBSCRIPTION_STATUS_TRIAL, ]; return in_array($this->getStatus(), $runningStatuses, true); }
[ "public", "function", "isRunning", "(", ")", "{", "$", "runningStatuses", "=", "[", "self", "::", "SUBSCRIPTION_STATUS_ACTIVE", ",", "self", "::", "SUBSCRIPTION_STATUS_TRIAL", ",", "]", ";", "return", "in_array", "(", "$", "this", "->", "getStatus", "(", ")", ",", "$", "runningStatuses", ",", "true", ")", ";", "}" ]
Check if the current subscription is running. @return boolean
[ "Check", "if", "the", "current", "subscription", "is", "running", "." ]
train
https://github.com/Speicher210/monsum-api/blob/4611a048097de5d2b0efe9d4426779c783c0af4d/src/Model/Subscription.php#L71-L79
CalderaWP/metaplate-core
src/helper_loader.php
helper_loader.add_helpers
private function add_helpers( $helpers ) { foreach( $helpers as $helper ) { $helper = $this->validate_helper_input( $helper ); if ( is_array( $helper ) ) { $this->add_helper( $helper ); } } }
php
private function add_helpers( $helpers ) { foreach( $helpers as $helper ) { $helper = $this->validate_helper_input( $helper ); if ( is_array( $helper ) ) { $this->add_helper( $helper ); } } }
[ "private", "function", "add_helpers", "(", "$", "helpers", ")", "{", "foreach", "(", "$", "helpers", "as", "$", "helper", ")", "{", "$", "helper", "=", "$", "this", "->", "validate_helper_input", "(", "$", "helper", ")", ";", "if", "(", "is_array", "(", "$", "helper", ")", ")", "{", "$", "this", "->", "add_helper", "(", "$", "helper", ")", ";", "}", "}", "}" ]
Add the helpers to the Handlebars instance, if validation passes. @param array $helpers Array of helpers to add
[ "Add", "the", "helpers", "to", "the", "Handlebars", "instance", "if", "validation", "passes", "." ]
train
https://github.com/CalderaWP/metaplate-core/blob/15ede9c4250ab23112a32f8e45d5393f8278bbb8/src/helper_loader.php#L58-L67
CalderaWP/metaplate-core
src/helper_loader.php
helper_loader.validate_helper_input
private function validate_helper_input( $helper ) { if ( ! is_array( $helper ) || empty( $helper ) ) { return false; } if ( ! isset( $helper[ 'name' ] ) || ! isset( $helper[ 'class' ] ) ) { return false; } //if not set, set callback name to "helper" if ( ! isset( $helper[ 'callback' ] ) ) { $helper[ 'callback' ] = 'helper'; } return $helper; }
php
private function validate_helper_input( $helper ) { if ( ! is_array( $helper ) || empty( $helper ) ) { return false; } if ( ! isset( $helper[ 'name' ] ) || ! isset( $helper[ 'class' ] ) ) { return false; } //if not set, set callback name to "helper" if ( ! isset( $helper[ 'callback' ] ) ) { $helper[ 'callback' ] = 'helper'; } return $helper; }
[ "private", "function", "validate_helper_input", "(", "$", "helper", ")", "{", "if", "(", "!", "is_array", "(", "$", "helper", ")", "||", "empty", "(", "$", "helper", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "isset", "(", "$", "helper", "[", "'name'", "]", ")", "||", "!", "isset", "(", "$", "helper", "[", "'class'", "]", ")", ")", "{", "return", "false", ";", "}", "//if not set, set callback name to \"helper\"", "if", "(", "!", "isset", "(", "$", "helper", "[", "'callback'", "]", ")", ")", "{", "$", "helper", "[", "'callback'", "]", "=", "'helper'", ";", "}", "return", "$", "helper", ";", "}" ]
Make sure each helper passed in is valid. @todo ensure helper class/callback are callable. Preferably, without creating object of the class. @param array $helper Array to add helper with. @return bool|array Returns the array if valid, false if not.
[ "Make", "sure", "each", "helper", "passed", "in", "is", "valid", "." ]
train
https://github.com/CalderaWP/metaplate-core/blob/15ede9c4250ab23112a32f8e45d5393f8278bbb8/src/helper_loader.php#L93-L109
CalderaWP/metaplate-core
src/pods/access.php
access.offsetGet
public function offsetGet($offset) { if ( $this->offsetExists( $offset ) ) { return parent::offsetGet( $offset ); } else { if( 'id' == $offset || 'ID' == $offset ) { $_value = $this->pod->id(); }else{ $_value = $this->pod->field( $offset ); } if( $_value ) { parent::offsetSet( $offset, $_value ); return $_value; } } }
php
public function offsetGet($offset) { if ( $this->offsetExists( $offset ) ) { return parent::offsetGet( $offset ); } else { if( 'id' == $offset || 'ID' == $offset ) { $_value = $this->pod->id(); }else{ $_value = $this->pod->field( $offset ); } if( $_value ) { parent::offsetSet( $offset, $_value ); return $_value; } } }
[ "public", "function", "offsetGet", "(", "$", "offset", ")", "{", "if", "(", "$", "this", "->", "offsetExists", "(", "$", "offset", ")", ")", "{", "return", "parent", "::", "offsetGet", "(", "$", "offset", ")", ";", "}", "else", "{", "if", "(", "'id'", "==", "$", "offset", "||", "'ID'", "==", "$", "offset", ")", "{", "$", "_value", "=", "$", "this", "->", "pod", "->", "id", "(", ")", ";", "}", "else", "{", "$", "_value", "=", "$", "this", "->", "pod", "->", "field", "(", "$", "offset", ")", ";", "}", "if", "(", "$", "_value", ")", "{", "parent", "::", "offsetSet", "(", "$", "offset", ",", "$", "_value", ")", ";", "return", "$", "_value", ";", "}", "}", "}" ]
Get an offset if already set or traverse Pod and then set plus reutrn. @since 0.1.0 @param mixed $offset Offset to get @return mixed
[ "Get", "an", "offset", "if", "already", "set", "or", "traverse", "Pod", "and", "then", "set", "plus", "reutrn", "." ]
train
https://github.com/CalderaWP/metaplate-core/blob/15ede9c4250ab23112a32f8e45d5393f8278bbb8/src/pods/access.php#L66-L81
ezsystems/ezdfs-fsbackend-dispatcher
classes/ezdfsfilehandlerdfsregistry.php
eZDFSFileHandlerDFSRegistry.getHandler
public function getHandler( $path ) { foreach ( $this->pathHandlers as $supportedPath => $handler ) { if ( strstr( $path, $supportedPath ) !== false ) { return $handler; } } return $this->defaultHandler; }
php
public function getHandler( $path ) { foreach ( $this->pathHandlers as $supportedPath => $handler ) { if ( strstr( $path, $supportedPath ) !== false ) { return $handler; } } return $this->defaultHandler; }
[ "public", "function", "getHandler", "(", "$", "path", ")", "{", "foreach", "(", "$", "this", "->", "pathHandlers", "as", "$", "supportedPath", "=>", "$", "handler", ")", "{", "if", "(", "strstr", "(", "$", "path", ",", "$", "supportedPath", ")", "!==", "false", ")", "{", "return", "$", "handler", ";", "}", "}", "return", "$", "this", "->", "defaultHandler", ";", "}" ]
Returns the FSHandler for $path @param $path @return eZDFSFileHandlerDFSBackendInterface @throws OutOfRangeException If no handler supports $path
[ "Returns", "the", "FSHandler", "for", "$path" ]
train
https://github.com/ezsystems/ezdfs-fsbackend-dispatcher/blob/e12c51e58ad452b2376bb6e0ec6deb8be5d8e036/classes/ezdfsfilehandlerdfsregistry.php#L53-L64
ezsystems/ezdfs-fsbackend-dispatcher
classes/ezdfsfilehandlerdfsregistry.php
eZDFSFileHandlerDFSRegistry.build
public static function build() { $ini = eZINI::instance( 'file.ini' ); $defaultHandler = eZDFSFileHandlerBackendFactory::buildHandler( $ini->variable( 'DispatchableDFS', 'DefaultBackend' ) ); $pathHandlers = array(); foreach ( $ini->variable( 'DispatchableDFS', 'PathBackends' ) as $supportedPath => $backendClass ) { // @todo Make it possible to use a Symfony2 service $pathHandlers[$supportedPath] = eZDFSFileHandlerBackendFactory::buildHandler( $backendClass ); } return new static( $defaultHandler, $pathHandlers ); }
php
public static function build() { $ini = eZINI::instance( 'file.ini' ); $defaultHandler = eZDFSFileHandlerBackendFactory::buildHandler( $ini->variable( 'DispatchableDFS', 'DefaultBackend' ) ); $pathHandlers = array(); foreach ( $ini->variable( 'DispatchableDFS', 'PathBackends' ) as $supportedPath => $backendClass ) { // @todo Make it possible to use a Symfony2 service $pathHandlers[$supportedPath] = eZDFSFileHandlerBackendFactory::buildHandler( $backendClass ); } return new static( $defaultHandler, $pathHandlers ); }
[ "public", "static", "function", "build", "(", ")", "{", "$", "ini", "=", "eZINI", "::", "instance", "(", "'file.ini'", ")", ";", "$", "defaultHandler", "=", "eZDFSFileHandlerBackendFactory", "::", "buildHandler", "(", "$", "ini", "->", "variable", "(", "'DispatchableDFS'", ",", "'DefaultBackend'", ")", ")", ";", "$", "pathHandlers", "=", "array", "(", ")", ";", "foreach", "(", "$", "ini", "->", "variable", "(", "'DispatchableDFS'", ",", "'PathBackends'", ")", "as", "$", "supportedPath", "=>", "$", "backendClass", ")", "{", "// @todo Make it possible to use a Symfony2 service", "$", "pathHandlers", "[", "$", "supportedPath", "]", "=", "eZDFSFileHandlerBackendFactory", "::", "buildHandler", "(", "$", "backendClass", ")", ";", "}", "return", "new", "static", "(", "$", "defaultHandler", ",", "$", "pathHandlers", ")", ";", "}" ]
Builds a registry using either the provided configuration, or settings from self::getConfiguration @return self
[ "Builds", "a", "registry", "using", "either", "the", "provided", "configuration", "or", "settings", "from", "self", "::", "getConfiguration" ]
train
https://github.com/ezsystems/ezdfs-fsbackend-dispatcher/blob/e12c51e58ad452b2376bb6e0ec6deb8be5d8e036/classes/ezdfsfilehandlerdfsregistry.php#L77-L92
ekuiter/feature-php
FeaturePhp/Generator/CollaborationGenerator.php
CollaborationGenerator.processFileSpecification
protected function processFileSpecification($artifact, $fileSpecification) { $collaboration = fphp\Collaboration\Collaboration::findByArtifact($this->collaborations, $artifact); if (!$collaboration) $this->collaborations[] = $collaboration = new fphp\Collaboration\Collaboration($artifact); $collaboration->addRoleFromFileSpecification($fileSpecification); $this->tracingLinks[] = new fphp\Artifact\TracingLink( "role", $artifact, $fileSpecification->getSourcePlace(), $fileSpecification->getTargetPlace()); $this->logFile->log($artifact, "using role at \"{$fileSpecification->getTarget()}\""); }
php
protected function processFileSpecification($artifact, $fileSpecification) { $collaboration = fphp\Collaboration\Collaboration::findByArtifact($this->collaborations, $artifact); if (!$collaboration) $this->collaborations[] = $collaboration = new fphp\Collaboration\Collaboration($artifact); $collaboration->addRoleFromFileSpecification($fileSpecification); $this->tracingLinks[] = new fphp\Artifact\TracingLink( "role", $artifact, $fileSpecification->getSourcePlace(), $fileSpecification->getTargetPlace()); $this->logFile->log($artifact, "using role at \"{$fileSpecification->getTarget()}\""); }
[ "protected", "function", "processFileSpecification", "(", "$", "artifact", ",", "$", "fileSpecification", ")", "{", "$", "collaboration", "=", "fphp", "\\", "Collaboration", "\\", "Collaboration", "::", "findByArtifact", "(", "$", "this", "->", "collaborations", ",", "$", "artifact", ")", ";", "if", "(", "!", "$", "collaboration", ")", "$", "this", "->", "collaborations", "[", "]", "=", "$", "collaboration", "=", "new", "fphp", "\\", "Collaboration", "\\", "Collaboration", "(", "$", "artifact", ")", ";", "$", "collaboration", "->", "addRoleFromFileSpecification", "(", "$", "fileSpecification", ")", ";", "$", "this", "->", "tracingLinks", "[", "]", "=", "new", "fphp", "\\", "Artifact", "\\", "TracingLink", "(", "\"role\"", ",", "$", "artifact", ",", "$", "fileSpecification", "->", "getSourcePlace", "(", ")", ",", "$", "fileSpecification", "->", "getTargetPlace", "(", ")", ")", ";", "$", "this", "->", "logFile", "->", "log", "(", "$", "artifact", ",", "\"using role at \\\"{$fileSpecification->getTarget()}\\\"\"", ")", ";", "}" ]
Adds a role from a file to a collaboration. @param \FeaturePhp\Artifact\Artifact $artifact @param \FeaturePhp\Specification\FileSpecification $fileSpecification
[ "Adds", "a", "role", "from", "a", "file", "to", "a", "collaboration", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Generator/CollaborationGenerator.php#L62-L70
ekuiter/feature-php
FeaturePhp/Generator/CollaborationGenerator.php
CollaborationGenerator._generateFiles
protected function _generateFiles() { foreach ($this->getRegisteredArtifacts() as $artifact) { $featureName = $artifact->getFeature()->getName(); if (array_search($featureName, $this->featureOrder) === false) throw new CollaborationGeneratorException("no feature order supplied for \"$featureName\""); } parent::_generateFiles(); $rolePartition = fphp\Helper\Partition::fromObjects($this->collaborations, "getRoles")->partitionBy("correspondsTo"); foreach ($rolePartition as $roleEquivalenceClass) { // sort the roles by their feature order (because role composition is not commutative) $roleEquivalenceClass = fphp\Helper\_Array::schwartzianTransform($roleEquivalenceClass, function($role) { return array_search($role->getCollaboration()->getArtifact()->getFeature()->getName(), $this->featureOrder); }); // take any representative from the equivalence class to extract the file target $fileTarget = $roleEquivalenceClass[0]->getFileSpecification()->getTarget(); $this->files[] = new fphp\File\RefinedFile($fileTarget, $roleEquivalenceClass); $this->logFile->log(null, "added file \"$fileTarget\""); } }
php
protected function _generateFiles() { foreach ($this->getRegisteredArtifacts() as $artifact) { $featureName = $artifact->getFeature()->getName(); if (array_search($featureName, $this->featureOrder) === false) throw new CollaborationGeneratorException("no feature order supplied for \"$featureName\""); } parent::_generateFiles(); $rolePartition = fphp\Helper\Partition::fromObjects($this->collaborations, "getRoles")->partitionBy("correspondsTo"); foreach ($rolePartition as $roleEquivalenceClass) { // sort the roles by their feature order (because role composition is not commutative) $roleEquivalenceClass = fphp\Helper\_Array::schwartzianTransform($roleEquivalenceClass, function($role) { return array_search($role->getCollaboration()->getArtifact()->getFeature()->getName(), $this->featureOrder); }); // take any representative from the equivalence class to extract the file target $fileTarget = $roleEquivalenceClass[0]->getFileSpecification()->getTarget(); $this->files[] = new fphp\File\RefinedFile($fileTarget, $roleEquivalenceClass); $this->logFile->log(null, "added file \"$fileTarget\""); } }
[ "protected", "function", "_generateFiles", "(", ")", "{", "foreach", "(", "$", "this", "->", "getRegisteredArtifacts", "(", ")", "as", "$", "artifact", ")", "{", "$", "featureName", "=", "$", "artifact", "->", "getFeature", "(", ")", "->", "getName", "(", ")", ";", "if", "(", "array_search", "(", "$", "featureName", ",", "$", "this", "->", "featureOrder", ")", "===", "false", ")", "throw", "new", "CollaborationGeneratorException", "(", "\"no feature order supplied for \\\"$featureName\\\"\"", ")", ";", "}", "parent", "::", "_generateFiles", "(", ")", ";", "$", "rolePartition", "=", "fphp", "\\", "Helper", "\\", "Partition", "::", "fromObjects", "(", "$", "this", "->", "collaborations", ",", "\"getRoles\"", ")", "->", "partitionBy", "(", "\"correspondsTo\"", ")", ";", "foreach", "(", "$", "rolePartition", "as", "$", "roleEquivalenceClass", ")", "{", "// sort the roles by their feature order (because role composition is not commutative)", "$", "roleEquivalenceClass", "=", "fphp", "\\", "Helper", "\\", "_Array", "::", "schwartzianTransform", "(", "$", "roleEquivalenceClass", ",", "function", "(", "$", "role", ")", "{", "return", "array_search", "(", "$", "role", "->", "getCollaboration", "(", ")", "->", "getArtifact", "(", ")", "->", "getFeature", "(", ")", "->", "getName", "(", ")", ",", "$", "this", "->", "featureOrder", ")", ";", "}", ")", ";", "// take any representative from the equivalence class to extract the file target", "$", "fileTarget", "=", "$", "roleEquivalenceClass", "[", "0", "]", "->", "getFileSpecification", "(", ")", "->", "getTarget", "(", ")", ";", "$", "this", "->", "files", "[", "]", "=", "new", "fphp", "\\", "File", "\\", "RefinedFile", "(", "$", "fileTarget", ",", "$", "roleEquivalenceClass", ")", ";", "$", "this", "->", "logFile", "->", "log", "(", "null", ",", "\"added file \\\"$fileTarget\\\"\"", ")", ";", "}", "}" ]
Generates the refined files.
[ "Generates", "the", "refined", "files", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Generator/CollaborationGenerator.php#L75-L96
crysalead/storage-stream
src/MultiStream.php
MultiStream.add
public function add($stream) { if (is_scalar($stream) || is_resource($stream)) { $stream = new Stream(['data' => $stream]); } if (!$stream->isReadable()) { throw new InvalidArgumentException("Cannot append on a non readable stream."); } // The stream is only seekable if all streams are seekable if (!$stream->isSeekable()) { $this->_seekable = false; } $this->_streams[] = $stream; return $this; }
php
public function add($stream) { if (is_scalar($stream) || is_resource($stream)) { $stream = new Stream(['data' => $stream]); } if (!$stream->isReadable()) { throw new InvalidArgumentException("Cannot append on a non readable stream."); } // The stream is only seekable if all streams are seekable if (!$stream->isSeekable()) { $this->_seekable = false; } $this->_streams[] = $stream; return $this; }
[ "public", "function", "add", "(", "$", "stream", ")", "{", "if", "(", "is_scalar", "(", "$", "stream", ")", "||", "is_resource", "(", "$", "stream", ")", ")", "{", "$", "stream", "=", "new", "Stream", "(", "[", "'data'", "=>", "$", "stream", "]", ")", ";", "}", "if", "(", "!", "$", "stream", "->", "isReadable", "(", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Cannot append on a non readable stream.\"", ")", ";", "}", "// The stream is only seekable if all streams are seekable", "if", "(", "!", "$", "stream", "->", "isSeekable", "(", ")", ")", "{", "$", "this", "->", "_seekable", "=", "false", ";", "}", "$", "this", "->", "_streams", "[", "]", "=", "$", "stream", ";", "return", "$", "this", ";", "}" ]
Add a stream @param object $stream Stream to append. @throws InvalidArgumentException if the stream is not readable
[ "Add", "a", "stream" ]
train
https://github.com/crysalead/storage-stream/blob/8ec613b42a2dd5d7e951a118f61d6094fe97dd9b/src/MultiStream.php#L129-L146
crysalead/storage-stream
src/MultiStream.php
MultiStream.seek
public function seek($offset, $whence = SEEK_SET) { if (!$this->_seekable) { throw new RuntimeException("Cannot seek on non seekable stream."); } if ($whence !== SEEK_SET) { if (!$offset && $whence === SEEK_END) { return $this->end(); } throw new InvalidArgumentException("This seek operation is not supported on a multi stream container."); } $this->_offset = $this->_current = 0; foreach ($this->_streams as $i => $stream) { $stream->rewind(); } while ($this->_offset < $offset && !$this->eof()) { $result = $this->read(min(8096, $offset - $this->_offset)); if ($result === '') { break; } } }
php
public function seek($offset, $whence = SEEK_SET) { if (!$this->_seekable) { throw new RuntimeException("Cannot seek on non seekable stream."); } if ($whence !== SEEK_SET) { if (!$offset && $whence === SEEK_END) { return $this->end(); } throw new InvalidArgumentException("This seek operation is not supported on a multi stream container."); } $this->_offset = $this->_current = 0; foreach ($this->_streams as $i => $stream) { $stream->rewind(); } while ($this->_offset < $offset && !$this->eof()) { $result = $this->read(min(8096, $offset - $this->_offset)); if ($result === '') { break; } } }
[ "public", "function", "seek", "(", "$", "offset", ",", "$", "whence", "=", "SEEK_SET", ")", "{", "if", "(", "!", "$", "this", "->", "_seekable", ")", "{", "throw", "new", "RuntimeException", "(", "\"Cannot seek on non seekable stream.\"", ")", ";", "}", "if", "(", "$", "whence", "!==", "SEEK_SET", ")", "{", "if", "(", "!", "$", "offset", "&&", "$", "whence", "===", "SEEK_END", ")", "{", "return", "$", "this", "->", "end", "(", ")", ";", "}", "throw", "new", "InvalidArgumentException", "(", "\"This seek operation is not supported on a multi stream container.\"", ")", ";", "}", "$", "this", "->", "_offset", "=", "$", "this", "->", "_current", "=", "0", ";", "foreach", "(", "$", "this", "->", "_streams", "as", "$", "i", "=>", "$", "stream", ")", "{", "$", "stream", "->", "rewind", "(", ")", ";", "}", "while", "(", "$", "this", "->", "_offset", "<", "$", "offset", "&&", "!", "$", "this", "->", "eof", "(", ")", ")", "{", "$", "result", "=", "$", "this", "->", "read", "(", "min", "(", "8096", ",", "$", "offset", "-", "$", "this", "->", "_offset", ")", ")", ";", "if", "(", "$", "result", "===", "''", ")", "{", "break", ";", "}", "}", "}" ]
Attempts to seek to the given position. Only supports SEEK_SET. {@inheritdoc}
[ "Attempts", "to", "seek", "to", "the", "given", "position", ".", "Only", "supports", "SEEK_SET", "." ]
train
https://github.com/crysalead/storage-stream/blob/8ec613b42a2dd5d7e951a118f61d6094fe97dd9b/src/MultiStream.php#L163-L186
crysalead/storage-stream
src/MultiStream.php
MultiStream.end
public function end() { if (!$this->_seekable) { throw new RuntimeException("Cannot seek on non seekable stream."); } if (!count($this->_streams)) { throw new RuntimeException('The stream container is empty no seek operation is possible.'); } $this->_current = count($this->_streams) - 1; $stream = $this->_streams[$this->_current]; $stream->seek(0, SEEK_END); }
php
public function end() { if (!$this->_seekable) { throw new RuntimeException("Cannot seek on non seekable stream."); } if (!count($this->_streams)) { throw new RuntimeException('The stream container is empty no seek operation is possible.'); } $this->_current = count($this->_streams) - 1; $stream = $this->_streams[$this->_current]; $stream->seek(0, SEEK_END); }
[ "public", "function", "end", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_seekable", ")", "{", "throw", "new", "RuntimeException", "(", "\"Cannot seek on non seekable stream.\"", ")", ";", "}", "if", "(", "!", "count", "(", "$", "this", "->", "_streams", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'The stream container is empty no seek operation is possible.'", ")", ";", "}", "$", "this", "->", "_current", "=", "count", "(", "$", "this", "->", "_streams", ")", "-", "1", ";", "$", "stream", "=", "$", "this", "->", "_streams", "[", "$", "this", "->", "_current", "]", ";", "$", "stream", "->", "seek", "(", "0", ",", "SEEK_END", ")", ";", "}" ]
Seek to the end of the stream. @return Boolean
[ "Seek", "to", "the", "end", "of", "the", "stream", "." ]
train
https://github.com/crysalead/storage-stream/blob/8ec613b42a2dd5d7e951a118f61d6094fe97dd9b/src/MultiStream.php#L213-L224
crysalead/storage-stream
src/MultiStream.php
MultiStream.read
public function read($length = null) { $buffer = ''; $total = count($this->_streams) - 1; $remaining = (integer) ($length === null ? $this->_bufferSize : $length); $progressToNext = false; while ($remaining > 0) { // Progress to the next stream if needed. if ($progressToNext || $this->_streams[$this->_current]->eof()) { $progressToNext = false; if ($this->_current === $total) { break; } $this->_current++; } $result = $this->_streams[$this->_current]->read($remaining); if (!$result) { $progressToNext = true; continue; } $buffer .= $result; $remaining = $length - strlen($buffer); } $this->_offset += strlen($buffer); return $buffer; }
php
public function read($length = null) { $buffer = ''; $total = count($this->_streams) - 1; $remaining = (integer) ($length === null ? $this->_bufferSize : $length); $progressToNext = false; while ($remaining > 0) { // Progress to the next stream if needed. if ($progressToNext || $this->_streams[$this->_current]->eof()) { $progressToNext = false; if ($this->_current === $total) { break; } $this->_current++; } $result = $this->_streams[$this->_current]->read($remaining); if (!$result) { $progressToNext = true; continue; } $buffer .= $result; $remaining = $length - strlen($buffer); } $this->_offset += strlen($buffer); return $buffer; }
[ "public", "function", "read", "(", "$", "length", "=", "null", ")", "{", "$", "buffer", "=", "''", ";", "$", "total", "=", "count", "(", "$", "this", "->", "_streams", ")", "-", "1", ";", "$", "remaining", "=", "(", "integer", ")", "(", "$", "length", "===", "null", "?", "$", "this", "->", "_bufferSize", ":", "$", "length", ")", ";", "$", "progressToNext", "=", "false", ";", "while", "(", "$", "remaining", ">", "0", ")", "{", "// Progress to the next stream if needed.", "if", "(", "$", "progressToNext", "||", "$", "this", "->", "_streams", "[", "$", "this", "->", "_current", "]", "->", "eof", "(", ")", ")", "{", "$", "progressToNext", "=", "false", ";", "if", "(", "$", "this", "->", "_current", "===", "$", "total", ")", "{", "break", ";", "}", "$", "this", "->", "_current", "++", ";", "}", "$", "result", "=", "$", "this", "->", "_streams", "[", "$", "this", "->", "_current", "]", "->", "read", "(", "$", "remaining", ")", ";", "if", "(", "!", "$", "result", ")", "{", "$", "progressToNext", "=", "true", ";", "continue", ";", "}", "$", "buffer", ".=", "$", "result", ";", "$", "remaining", "=", "$", "length", "-", "strlen", "(", "$", "buffer", ")", ";", "}", "$", "this", "->", "_offset", "+=", "strlen", "(", "$", "buffer", ")", ";", "return", "$", "buffer", ";", "}" ]
Read data from the stream. Binary-safe. @param integer $length Maximum number of bytes to read (default to buffer size). @return string The data.
[ "Read", "data", "from", "the", "stream", ".", "Binary", "-", "safe", "." ]
train
https://github.com/crysalead/storage-stream/blob/8ec613b42a2dd5d7e951a118f61d6094fe97dd9b/src/MultiStream.php#L233-L264
crysalead/storage-stream
src/MultiStream.php
MultiStream.write
public function write($string, $length = null) { if (!count($this->_streams)) { throw new RuntimeException('The stream container is empty no write operation is possible.'); } $stream = $this->_streams[$this->_current]; return $stream->write($string, $length); }
php
public function write($string, $length = null) { if (!count($this->_streams)) { throw new RuntimeException('The stream container is empty no write operation is possible.'); } $stream = $this->_streams[$this->_current]; return $stream->write($string, $length); }
[ "public", "function", "write", "(", "$", "string", ",", "$", "length", "=", "null", ")", "{", "if", "(", "!", "count", "(", "$", "this", "->", "_streams", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'The stream container is empty no write operation is possible.'", ")", ";", "}", "$", "stream", "=", "$", "this", "->", "_streams", "[", "$", "this", "->", "_current", "]", ";", "return", "$", "stream", "->", "write", "(", "$", "string", ",", "$", "length", ")", ";", "}" ]
Write data to the stream. @param string $string The string that is to be written. @param integer $length If the length argument is given, writing will stop after length bytes have been written or the end of string if reached, whichever comes first. @return integer Number of bytes written
[ "Write", "data", "to", "the", "stream", "." ]
train
https://github.com/crysalead/storage-stream/blob/8ec613b42a2dd5d7e951a118f61d6094fe97dd9b/src/MultiStream.php#L274-L281
crysalead/storage-stream
src/MultiStream.php
MultiStream.append
public function append($string, $length = null) { $this->end(); return $this->write($string, $length); }
php
public function append($string, $length = null) { $this->end(); return $this->write($string, $length); }
[ "public", "function", "append", "(", "$", "string", ",", "$", "length", "=", "null", ")", "{", "$", "this", "->", "end", "(", ")", ";", "return", "$", "this", "->", "write", "(", "$", "string", ",", "$", "length", ")", ";", "}" ]
Append data to the stream. @param string $string The string that is to be written. @param integer $length If the length argument is given, writing will stop after length bytes have been written or the end of string if reached, whichever comes first. @return integer Number of bytes written
[ "Append", "data", "to", "the", "stream", "." ]
train
https://github.com/crysalead/storage-stream/blob/8ec613b42a2dd5d7e951a118f61d6094fe97dd9b/src/MultiStream.php#L291-L295
crysalead/storage-stream
src/MultiStream.php
MultiStream.length
public function length() { $length = 0; foreach ($this->_streams as $stream) { $len = $stream->length(); if ($len === null) { return; } $length += $len; } return $length; }
php
public function length() { $length = 0; foreach ($this->_streams as $stream) { $len = $stream->length(); if ($len === null) { return; } $length += $len; } return $length; }
[ "public", "function", "length", "(", ")", "{", "$", "length", "=", "0", ";", "foreach", "(", "$", "this", "->", "_streams", "as", "$", "stream", ")", "{", "$", "len", "=", "$", "stream", "->", "length", "(", ")", ";", "if", "(", "$", "len", "===", "null", ")", "{", "return", ";", "}", "$", "length", "+=", "$", "len", ";", "}", "return", "$", "length", ";", "}" ]
Tries to calculate the size by adding the size of each stream. If any of the streams do not return a valid number, then the size of the append stream cannot be determined and null is returned.
[ "Tries", "to", "calculate", "the", "size", "by", "adding", "the", "size", "of", "each", "stream", "." ]
train
https://github.com/crysalead/storage-stream/blob/8ec613b42a2dd5d7e951a118f61d6094fe97dd9b/src/MultiStream.php#L304-L316
crysalead/storage-stream
src/MultiStream.php
MultiStream.get
public function get($index) { if (!isset($this->_streams[$index])) { throw new InvalidArgumentException("Unexisting stream index `{$index}`."); } return $this->_streams[$index]; }
php
public function get($index) { if (!isset($this->_streams[$index])) { throw new InvalidArgumentException("Unexisting stream index `{$index}`."); } return $this->_streams[$index]; }
[ "public", "function", "get", "(", "$", "index", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_streams", "[", "$", "index", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Unexisting stream index `{$index}`.\"", ")", ";", "}", "return", "$", "this", "->", "_streams", "[", "$", "index", "]", ";", "}" ]
Return a contained stream. @param integer $index An index. @return object
[ "Return", "a", "contained", "stream", "." ]
train
https://github.com/crysalead/storage-stream/blob/8ec613b42a2dd5d7e951a118f61d6094fe97dd9b/src/MultiStream.php#L335-L341
crysalead/storage-stream
src/MultiStream.php
MultiStream.remove
public function remove($index) { if (!isset($this->_streams[$index])) { throw new InvalidArgumentException("Unexisting stream index `{$index}`."); } $stream = $this->_streams[$index]; unset($this->_streams[$index]); $this->_streams = array_values($this->_streams); return $stream; }
php
public function remove($index) { if (!isset($this->_streams[$index])) { throw new InvalidArgumentException("Unexisting stream index `{$index}`."); } $stream = $this->_streams[$index]; unset($this->_streams[$index]); $this->_streams = array_values($this->_streams); return $stream; }
[ "public", "function", "remove", "(", "$", "index", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_streams", "[", "$", "index", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Unexisting stream index `{$index}`.\"", ")", ";", "}", "$", "stream", "=", "$", "this", "->", "_streams", "[", "$", "index", "]", ";", "unset", "(", "$", "this", "->", "_streams", "[", "$", "index", "]", ")", ";", "$", "this", "->", "_streams", "=", "array_values", "(", "$", "this", "->", "_streams", ")", ";", "return", "$", "stream", ";", "}" ]
Remove a stream. @param integer $index An index. @return object The removed stream.
[ "Remove", "a", "stream", "." ]
train
https://github.com/crysalead/storage-stream/blob/8ec613b42a2dd5d7e951a118f61d6094fe97dd9b/src/MultiStream.php#L349-L358
crysalead/storage-stream
src/MultiStream.php
MultiStream.eof
public function eof() { return !$this->_streams || ($this->_current >= count($this->_streams) - 1 && $this->_streams[$this->_current]->eof()); }
php
public function eof() { return !$this->_streams || ($this->_current >= count($this->_streams) - 1 && $this->_streams[$this->_current]->eof()); }
[ "public", "function", "eof", "(", ")", "{", "return", "!", "$", "this", "->", "_streams", "||", "(", "$", "this", "->", "_current", ">=", "count", "(", "$", "this", "->", "_streams", ")", "-", "1", "&&", "$", "this", "->", "_streams", "[", "$", "this", "->", "_current", "]", "->", "eof", "(", ")", ")", ";", "}" ]
Checks for EOF. @return boolean
[ "Checks", "for", "EOF", "." ]
train
https://github.com/crysalead/storage-stream/blob/8ec613b42a2dd5d7e951a118f61d6094fe97dd9b/src/MultiStream.php#L385-L388
crysalead/storage-stream
src/MultiStream.php
MultiStream.flush
public function flush() { $buffer = ''; while (!$this->eof()) { $buffer .= $this->read($this->_bufferSize); } return $buffer; }
php
public function flush() { $buffer = ''; while (!$this->eof()) { $buffer .= $this->read($this->_bufferSize); } return $buffer; }
[ "public", "function", "flush", "(", ")", "{", "$", "buffer", "=", "''", ";", "while", "(", "!", "$", "this", "->", "eof", "(", ")", ")", "{", "$", "buffer", ".=", "$", "this", "->", "read", "(", "$", "this", "->", "_bufferSize", ")", ";", "}", "return", "$", "buffer", ";", "}" ]
Return the remaining data from the stream. @return string
[ "Return", "the", "remaining", "data", "from", "the", "stream", "." ]
train
https://github.com/crysalead/storage-stream/blob/8ec613b42a2dd5d7e951a118f61d6094fe97dd9b/src/MultiStream.php#L395-L402
crysalead/storage-stream
src/MultiStream.php
MultiStream.detach
public function detach() { $this->_offset = $this->_current = 0; $this->_seekable = true; foreach ($this->_streams as $stream) { $stream->detach(); } $this->_streams = []; }
php
public function detach() { $this->_offset = $this->_current = 0; $this->_seekable = true; foreach ($this->_streams as $stream) { $stream->detach(); } $this->_streams = []; }
[ "public", "function", "detach", "(", ")", "{", "$", "this", "->", "_offset", "=", "$", "this", "->", "_current", "=", "0", ";", "$", "this", "->", "_seekable", "=", "true", ";", "foreach", "(", "$", "this", "->", "_streams", "as", "$", "stream", ")", "{", "$", "stream", "->", "detach", "(", ")", ";", "}", "$", "this", "->", "_streams", "=", "[", "]", ";", "}" ]
Detaches each attached stream. Returns null as it's not clear which underlying stream resource to return.
[ "Detaches", "each", "attached", "stream", "." ]
train
https://github.com/crysalead/storage-stream/blob/8ec613b42a2dd5d7e951a118f61d6094fe97dd9b/src/MultiStream.php#L423-L433
blast-project/BaseEntitiesBundle
src/Loggable/Mapping/Event/Adapter/ODM.php
ODM.getNewVersion
public function getNewVersion($meta, $object) { $dm = $this->getObjectManager(); $objectMeta = $dm->getClassMetadata(get_class($object)); $identifierField = $this->getSingleIdentifierFieldName($objectMeta); $objectId = $objectMeta->getReflectionProperty($identifierField)->getValue($object); $qb = $dm->createQueryBuilder($meta->name); $qb->select('version'); $qb->field('objectId')->equals($objectId); $qb->field('objectClass')->equals($objectMeta->name); $qb->sort('version', 'DESC'); $qb->limit(1); $q = $qb->getQuery(); $q->setHydrate(false); $result = $q->getSingleResult(); if ($result) { $result = $result['version'] + 1; } return $result; }
php
public function getNewVersion($meta, $object) { $dm = $this->getObjectManager(); $objectMeta = $dm->getClassMetadata(get_class($object)); $identifierField = $this->getSingleIdentifierFieldName($objectMeta); $objectId = $objectMeta->getReflectionProperty($identifierField)->getValue($object); $qb = $dm->createQueryBuilder($meta->name); $qb->select('version'); $qb->field('objectId')->equals($objectId); $qb->field('objectClass')->equals($objectMeta->name); $qb->sort('version', 'DESC'); $qb->limit(1); $q = $qb->getQuery(); $q->setHydrate(false); $result = $q->getSingleResult(); if ($result) { $result = $result['version'] + 1; } return $result; }
[ "public", "function", "getNewVersion", "(", "$", "meta", ",", "$", "object", ")", "{", "$", "dm", "=", "$", "this", "->", "getObjectManager", "(", ")", ";", "$", "objectMeta", "=", "$", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "object", ")", ")", ";", "$", "identifierField", "=", "$", "this", "->", "getSingleIdentifierFieldName", "(", "$", "objectMeta", ")", ";", "$", "objectId", "=", "$", "objectMeta", "->", "getReflectionProperty", "(", "$", "identifierField", ")", "->", "getValue", "(", "$", "object", ")", ";", "$", "qb", "=", "$", "dm", "->", "createQueryBuilder", "(", "$", "meta", "->", "name", ")", ";", "$", "qb", "->", "select", "(", "'version'", ")", ";", "$", "qb", "->", "field", "(", "'objectId'", ")", "->", "equals", "(", "$", "objectId", ")", ";", "$", "qb", "->", "field", "(", "'objectClass'", ")", "->", "equals", "(", "$", "objectMeta", "->", "name", ")", ";", "$", "qb", "->", "sort", "(", "'version'", ",", "'DESC'", ")", ";", "$", "qb", "->", "limit", "(", "1", ")", ";", "$", "q", "=", "$", "qb", "->", "getQuery", "(", ")", ";", "$", "q", "->", "setHydrate", "(", "false", ")", ";", "$", "result", "=", "$", "q", "->", "getSingleResult", "(", ")", ";", "if", "(", "$", "result", ")", "{", "$", "result", "=", "$", "result", "[", "'version'", "]", "+", "1", ";", "}", "return", "$", "result", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/blast-project/BaseEntitiesBundle/blob/abd06891fc38922225ab7e4fcb437a286ba2c0c4/src/Loggable/Mapping/Event/Adapter/ODM.php#L46-L68
Innmind/neo4j-dbal
src/Translator/HttpTranslator.php
HttpTranslator.computeEndpoint
private function computeEndpoint(): UrlInterface { if (!$this->transactions->isOpened()) { return Url::fromString('/db/data/transaction/commit'); } return $this->transactions->current()->endpoint(); }
php
private function computeEndpoint(): UrlInterface { if (!$this->transactions->isOpened()) { return Url::fromString('/db/data/transaction/commit'); } return $this->transactions->current()->endpoint(); }
[ "private", "function", "computeEndpoint", "(", ")", ":", "UrlInterface", "{", "if", "(", "!", "$", "this", "->", "transactions", "->", "isOpened", "(", ")", ")", "{", "return", "Url", "::", "fromString", "(", "'/db/data/transaction/commit'", ")", ";", "}", "return", "$", "this", "->", "transactions", "->", "current", "(", ")", "->", "endpoint", "(", ")", ";", "}" ]
Determine the appropriate endpoint based on the transactions
[ "Determine", "the", "appropriate", "endpoint", "based", "on", "the", "transactions" ]
train
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Translator/HttpTranslator.php#L77-L84
Innmind/neo4j-dbal
src/Translator/HttpTranslator.php
HttpTranslator.computeBody
private function computeBody(Query $query): StringStream { $statement = [ 'statement' => $query->cypher(), 'resultDataContents' => ['graph', 'row'], ]; if ($query->hasParameters()) { $parameters = []; foreach ($query->parameters() as $parameter) { $parameters[$parameter->key()] = $parameter->value(); } $statement['parameters'] = $parameters; } return new StringStream(Json::encode([ 'statements' => [$statement], ])); }
php
private function computeBody(Query $query): StringStream { $statement = [ 'statement' => $query->cypher(), 'resultDataContents' => ['graph', 'row'], ]; if ($query->hasParameters()) { $parameters = []; foreach ($query->parameters() as $parameter) { $parameters[$parameter->key()] = $parameter->value(); } $statement['parameters'] = $parameters; } return new StringStream(Json::encode([ 'statements' => [$statement], ])); }
[ "private", "function", "computeBody", "(", "Query", "$", "query", ")", ":", "StringStream", "{", "$", "statement", "=", "[", "'statement'", "=>", "$", "query", "->", "cypher", "(", ")", ",", "'resultDataContents'", "=>", "[", "'graph'", ",", "'row'", "]", ",", "]", ";", "if", "(", "$", "query", "->", "hasParameters", "(", ")", ")", "{", "$", "parameters", "=", "[", "]", ";", "foreach", "(", "$", "query", "->", "parameters", "(", ")", "as", "$", "parameter", ")", "{", "$", "parameters", "[", "$", "parameter", "->", "key", "(", ")", "]", "=", "$", "parameter", "->", "value", "(", ")", ";", "}", "$", "statement", "[", "'parameters'", "]", "=", "$", "parameters", ";", "}", "return", "new", "StringStream", "(", "Json", "::", "encode", "(", "[", "'statements'", "=>", "[", "$", "statement", "]", ",", "]", ")", ")", ";", "}" ]
Build the json payload to be sent to the server
[ "Build", "the", "json", "payload", "to", "be", "sent", "to", "the", "server" ]
train
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Translator/HttpTranslator.php#L89-L109
zicht/z
src/Zicht/Tool/Container/ContainerBuilder.php
ContainerBuilder.isExpressionPath
public function isExpressionPath($path, $node) { if (is_scalar($node)) { foreach ($this->expressionPaths as $callable) { if (call_user_func($callable, $path)) { return true; } } } return false; }
php
public function isExpressionPath($path, $node) { if (is_scalar($node)) { foreach ($this->expressionPaths as $callable) { if (call_user_func($callable, $path)) { return true; } } } return false; }
[ "public", "function", "isExpressionPath", "(", "$", "path", ",", "$", "node", ")", "{", "if", "(", "is_scalar", "(", "$", "node", ")", ")", "{", "foreach", "(", "$", "this", "->", "expressionPaths", "as", "$", "callable", ")", "{", "if", "(", "call_user_func", "(", "$", "callable", ",", "$", "path", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Decides if a node should be an expression. @param array $path @param mixed $node @return bool
[ "Decides", "if", "a", "node", "should", "be", "an", "expression", "." ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/ContainerBuilder.php#L58-L68
zicht/z
src/Zicht/Tool/Container/ContainerBuilder.php
ContainerBuilder.build
public function build() { Debug::enterScope('build'); $traverser = $this->createNodeCreatorTraverser($this->config); $result = $traverser->traverse(); $node = new ContainerNode(); $gatherer = $this->createNodeGathererTraverser($result, $node); $gatherer->traverse(); Debug::exitScope('build'); return $node; }
php
public function build() { Debug::enterScope('build'); $traverser = $this->createNodeCreatorTraverser($this->config); $result = $traverser->traverse(); $node = new ContainerNode(); $gatherer = $this->createNodeGathererTraverser($result, $node); $gatherer->traverse(); Debug::exitScope('build'); return $node; }
[ "public", "function", "build", "(", ")", "{", "Debug", "::", "enterScope", "(", "'build'", ")", ";", "$", "traverser", "=", "$", "this", "->", "createNodeCreatorTraverser", "(", "$", "this", "->", "config", ")", ";", "$", "result", "=", "$", "traverser", "->", "traverse", "(", ")", ";", "$", "node", "=", "new", "ContainerNode", "(", ")", ";", "$", "gatherer", "=", "$", "this", "->", "createNodeGathererTraverser", "(", "$", "result", ",", "$", "node", ")", ";", "$", "gatherer", "->", "traverse", "(", ")", ";", "Debug", "::", "exitScope", "(", "'build'", ")", ";", "return", "$", "node", ";", "}" ]
Build the container node @return ContainerNode
[ "Build", "the", "container", "node" ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/ContainerBuilder.php#L76-L88
zicht/z
src/Zicht/Tool/Container/ContainerBuilder.php
ContainerBuilder.createNodeGathererTraverser
public function createNodeGathererTraverser($result, $containerNode) { $gatherer = new Traverser($result); $gatherer->addVisitor( function ($path, $node) use($containerNode) { $containerNode->append($node); }, function ($path, $node) { return $node instanceof Node; }, Traverser::AFTER ); return $gatherer; }
php
public function createNodeGathererTraverser($result, $containerNode) { $gatherer = new Traverser($result); $gatherer->addVisitor( function ($path, $node) use($containerNode) { $containerNode->append($node); }, function ($path, $node) { return $node instanceof Node; }, Traverser::AFTER ); return $gatherer; }
[ "public", "function", "createNodeGathererTraverser", "(", "$", "result", ",", "$", "containerNode", ")", "{", "$", "gatherer", "=", "new", "Traverser", "(", "$", "result", ")", ";", "$", "gatherer", "->", "addVisitor", "(", "function", "(", "$", "path", ",", "$", "node", ")", "use", "(", "$", "containerNode", ")", "{", "$", "containerNode", "->", "append", "(", "$", "node", ")", ";", "}", ",", "function", "(", "$", "path", ",", "$", "node", ")", "{", "return", "$", "node", "instanceof", "Node", ";", "}", ",", "Traverser", "::", "AFTER", ")", ";", "return", "$", "gatherer", ";", "}" ]
Creates the traverser that gathers all nodes (i.e. Node instances) that are specified in the tree. @param array $result @param \Zicht\Tool\Script\Node\Branch $containerNode @return Traverser
[ "Creates", "the", "traverser", "that", "gathers", "all", "nodes", "(", "i", ".", "e", ".", "Node", "instances", ")", "that", "are", "specified", "in", "the", "tree", "." ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/ContainerBuilder.php#L98-L111
zicht/z
src/Zicht/Tool/Container/ContainerBuilder.php
ContainerBuilder.createArgNode
public function createArgNode($path, $node) { $v = trim($node); if (substr($v, 0, 1) == '?') { $conditional = true; $v = ltrim(substr($v, 1)); } else { $conditional = false; } return new ArgNode(end($path), $this->exprcompiler->parse($v), $conditional); }
php
public function createArgNode($path, $node) { $v = trim($node); if (substr($v, 0, 1) == '?') { $conditional = true; $v = ltrim(substr($v, 1)); } else { $conditional = false; } return new ArgNode(end($path), $this->exprcompiler->parse($v), $conditional); }
[ "public", "function", "createArgNode", "(", "$", "path", ",", "$", "node", ")", "{", "$", "v", "=", "trim", "(", "$", "node", ")", ";", "if", "(", "substr", "(", "$", "v", ",", "0", ",", "1", ")", "==", "'?'", ")", "{", "$", "conditional", "=", "true", ";", "$", "v", "=", "ltrim", "(", "substr", "(", "$", "v", ",", "1", ")", ")", ";", "}", "else", "{", "$", "conditional", "=", "false", ";", "}", "return", "new", "ArgNode", "(", "end", "(", "$", "path", ")", ",", "$", "this", "->", "exprcompiler", "->", "parse", "(", "$", "v", ")", ",", "$", "conditional", ")", ";", "}" ]
Creates a node for the 'args' definition of the task. @param array $path @param string $node @return \Zicht\Tool\Script\Node\Task\ArgNode
[ "Creates", "a", "node", "for", "the", "args", "definition", "of", "the", "task", "." ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/ContainerBuilder.php#L160-L170
zicht/z
src/Zicht/Tool/Container/ContainerBuilder.php
ContainerBuilder.createOptNode
public function createOptNode($path, $node) { return new OptNode(end($path), $this->exprcompiler->parse($node)); }
php
public function createOptNode($path, $node) { return new OptNode(end($path), $this->exprcompiler->parse($node)); }
[ "public", "function", "createOptNode", "(", "$", "path", ",", "$", "node", ")", "{", "return", "new", "OptNode", "(", "end", "(", "$", "path", ")", ",", "$", "this", "->", "exprcompiler", "->", "parse", "(", "$", "node", ")", ")", ";", "}" ]
Creates a node for the 'opts' definition of the task. @param array $path @param string $node @return \Zicht\Tool\Script\Node\Task\OptNode
[ "Creates", "a", "node", "for", "the", "opts", "definition", "of", "the", "task", "." ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/ContainerBuilder.php#L179-L182
zicht/z
src/Zicht/Tool/Container/ContainerBuilder.php
ContainerBuilder.createSetNode
public function createSetNode($path, $node) { return new SetNode(end($path), $this->exprcompiler->parse($node)); }
php
public function createSetNode($path, $node) { return new SetNode(end($path), $this->exprcompiler->parse($node)); }
[ "public", "function", "createSetNode", "(", "$", "path", ",", "$", "node", ")", "{", "return", "new", "SetNode", "(", "end", "(", "$", "path", ")", ",", "$", "this", "->", "exprcompiler", "->", "parse", "(", "$", "node", ")", ")", ";", "}" ]
Creates a node for the 'set' definition of the task. @param array $path @param string $node @return SetNode
[ "Creates", "a", "node", "for", "the", "set", "definition", "of", "the", "task", "." ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/ContainerBuilder.php#L192-L195
zicht/z
src/Zicht/Tool/Container/ContainerBuilder.php
ContainerBuilder.createNodeCreatorTraverser
public function createNodeCreatorTraverser($config) { $traverser = new Traverser($config); $traverser->addVisitor( array($this, 'createArgNode'), function ($path) { return (count($path) == 4 && $path[0] == 'tasks' && $path[2] == 'args'); }, Traverser::BEFORE ); $traverser->addVisitor( array($this, 'createOptNode'), function ($path) { return (count($path) == 4 && $path[0] == 'tasks' && $path[2] == 'opts'); }, Traverser::BEFORE ); $traverser->addVisitor( array($this, 'createSetNode'), function ($path) { return (count($path) == 4 && $path[0] == 'tasks' && $path[2] == 'set'); }, Traverser::BEFORE ); $traverser->addVisitor( array($this, 'createExpressionNode'), function ($path) { return count($path) === 3 && $path[0] == 'tasks' && in_array($path[2], array('unless', 'assert', 'yield', 'if')) ; }, Traverser::BEFORE ); $traverser->addVisitor( array($this, 'createScriptNode'), function ($path) { return count($path) == 4 && $path[0] == 'tasks' && in_array($path[2], array('do', 'pre', 'post')) ; }, Traverser::BEFORE ); $traverser->addVisitor( array($this, 'createTaskNode'), function ($path) { return count($path) == 2 && $path[0] == 'tasks'; }, Traverser::AFTER ); $traverser->addVisitor( array($this, 'createDeclarationNode'), array($this, 'isExpressionPath'), Traverser::AFTER ); $traverser->addVisitor( array($this, 'createDefinitionNode'), function ($path, $node) { return $path[0] !== 'tasks' && (is_scalar($node) || (is_array($node) && count($node) === 0)); }, Traverser::AFTER ); return $traverser; }
php
public function createNodeCreatorTraverser($config) { $traverser = new Traverser($config); $traverser->addVisitor( array($this, 'createArgNode'), function ($path) { return (count($path) == 4 && $path[0] == 'tasks' && $path[2] == 'args'); }, Traverser::BEFORE ); $traverser->addVisitor( array($this, 'createOptNode'), function ($path) { return (count($path) == 4 && $path[0] == 'tasks' && $path[2] == 'opts'); }, Traverser::BEFORE ); $traverser->addVisitor( array($this, 'createSetNode'), function ($path) { return (count($path) == 4 && $path[0] == 'tasks' && $path[2] == 'set'); }, Traverser::BEFORE ); $traverser->addVisitor( array($this, 'createExpressionNode'), function ($path) { return count($path) === 3 && $path[0] == 'tasks' && in_array($path[2], array('unless', 'assert', 'yield', 'if')) ; }, Traverser::BEFORE ); $traverser->addVisitor( array($this, 'createScriptNode'), function ($path) { return count($path) == 4 && $path[0] == 'tasks' && in_array($path[2], array('do', 'pre', 'post')) ; }, Traverser::BEFORE ); $traverser->addVisitor( array($this, 'createTaskNode'), function ($path) { return count($path) == 2 && $path[0] == 'tasks'; }, Traverser::AFTER ); $traverser->addVisitor( array($this, 'createDeclarationNode'), array($this, 'isExpressionPath'), Traverser::AFTER ); $traverser->addVisitor( array($this, 'createDefinitionNode'), function ($path, $node) { return $path[0] !== 'tasks' && (is_scalar($node) || (is_array($node) && count($node) === 0)); }, Traverser::AFTER ); return $traverser; }
[ "public", "function", "createNodeCreatorTraverser", "(", "$", "config", ")", "{", "$", "traverser", "=", "new", "Traverser", "(", "$", "config", ")", ";", "$", "traverser", "->", "addVisitor", "(", "array", "(", "$", "this", ",", "'createArgNode'", ")", ",", "function", "(", "$", "path", ")", "{", "return", "(", "count", "(", "$", "path", ")", "==", "4", "&&", "$", "path", "[", "0", "]", "==", "'tasks'", "&&", "$", "path", "[", "2", "]", "==", "'args'", ")", ";", "}", ",", "Traverser", "::", "BEFORE", ")", ";", "$", "traverser", "->", "addVisitor", "(", "array", "(", "$", "this", ",", "'createOptNode'", ")", ",", "function", "(", "$", "path", ")", "{", "return", "(", "count", "(", "$", "path", ")", "==", "4", "&&", "$", "path", "[", "0", "]", "==", "'tasks'", "&&", "$", "path", "[", "2", "]", "==", "'opts'", ")", ";", "}", ",", "Traverser", "::", "BEFORE", ")", ";", "$", "traverser", "->", "addVisitor", "(", "array", "(", "$", "this", ",", "'createSetNode'", ")", ",", "function", "(", "$", "path", ")", "{", "return", "(", "count", "(", "$", "path", ")", "==", "4", "&&", "$", "path", "[", "0", "]", "==", "'tasks'", "&&", "$", "path", "[", "2", "]", "==", "'set'", ")", ";", "}", ",", "Traverser", "::", "BEFORE", ")", ";", "$", "traverser", "->", "addVisitor", "(", "array", "(", "$", "this", ",", "'createExpressionNode'", ")", ",", "function", "(", "$", "path", ")", "{", "return", "count", "(", "$", "path", ")", "===", "3", "&&", "$", "path", "[", "0", "]", "==", "'tasks'", "&&", "in_array", "(", "$", "path", "[", "2", "]", ",", "array", "(", "'unless'", ",", "'assert'", ",", "'yield'", ",", "'if'", ")", ")", ";", "}", ",", "Traverser", "::", "BEFORE", ")", ";", "$", "traverser", "->", "addVisitor", "(", "array", "(", "$", "this", ",", "'createScriptNode'", ")", ",", "function", "(", "$", "path", ")", "{", "return", "count", "(", "$", "path", ")", "==", "4", "&&", "$", "path", "[", "0", "]", "==", "'tasks'", "&&", "in_array", "(", "$", "path", "[", "2", "]", ",", "array", "(", "'do'", ",", "'pre'", ",", "'post'", ")", ")", ";", "}", ",", "Traverser", "::", "BEFORE", ")", ";", "$", "traverser", "->", "addVisitor", "(", "array", "(", "$", "this", ",", "'createTaskNode'", ")", ",", "function", "(", "$", "path", ")", "{", "return", "count", "(", "$", "path", ")", "==", "2", "&&", "$", "path", "[", "0", "]", "==", "'tasks'", ";", "}", ",", "Traverser", "::", "AFTER", ")", ";", "$", "traverser", "->", "addVisitor", "(", "array", "(", "$", "this", ",", "'createDeclarationNode'", ")", ",", "array", "(", "$", "this", ",", "'isExpressionPath'", ")", ",", "Traverser", "::", "AFTER", ")", ";", "$", "traverser", "->", "addVisitor", "(", "array", "(", "$", "this", ",", "'createDefinitionNode'", ")", ",", "function", "(", "$", "path", ",", "$", "node", ")", "{", "return", "$", "path", "[", "0", "]", "!==", "'tasks'", "&&", "(", "is_scalar", "(", "$", "node", ")", "||", "(", "is_array", "(", "$", "node", ")", "&&", "count", "(", "$", "node", ")", "===", "0", ")", ")", ";", "}", ",", "Traverser", "::", "AFTER", ")", ";", "return", "$", "traverser", ";", "}" ]
Creates the traverser that creates relevant nodes at all known paths. @param array $config @return Traverser
[ "Creates", "the", "traverser", "that", "creates", "relevant", "nodes", "at", "all", "known", "paths", "." ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/ContainerBuilder.php#L230-L299
qlake/framework
src/Qlake/Routing/Route.php
Route.hasParam
public function hasParam($param) { $param = (string)$this->params[$param]; return strlen($param) > 0 ? true : false; }
php
public function hasParam($param) { $param = (string)$this->params[$param]; return strlen($param) > 0 ? true : false; }
[ "public", "function", "hasParam", "(", "$", "param", ")", "{", "$", "param", "=", "(", "string", ")", "$", "this", "->", "params", "[", "$", "param", "]", ";", "return", "strlen", "(", "$", "param", ")", ">", "0", "?", "true", ":", "false", ";", "}" ]
Determine that route param exists. @param string $param @return bool
[ "Determine", "that", "route", "param", "exists", "." ]
train
https://github.com/qlake/framework/blob/0b7bad459ae0721bc5cdd141344f9dfc1acee28a/src/Qlake/Routing/Route.php#L160-L165
qlake/framework
src/Qlake/Routing/Route.php
Route.setPrefixUri
public function setPrefixUri($prefix) { //$prefix = $this->normalizeUri($prefix); if (empty($prefix)) { return $this; } $this->uri = $prefix .'/'. $this->uri; return $this; }
php
public function setPrefixUri($prefix) { //$prefix = $this->normalizeUri($prefix); if (empty($prefix)) { return $this; } $this->uri = $prefix .'/'. $this->uri; return $this; }
[ "public", "function", "setPrefixUri", "(", "$", "prefix", ")", "{", "//$prefix = $this->normalizeUri($prefix);", "if", "(", "empty", "(", "$", "prefix", ")", ")", "{", "return", "$", "this", ";", "}", "$", "this", "->", "uri", "=", "$", "prefix", ".", "'/'", ".", "$", "this", "->", "uri", ";", "return", "$", "this", ";", "}" ]
Set prefix to current route's uri. use by Route::group method. @param string $prefix @return Qlake\Routing\Route
[ "Set", "prefix", "to", "current", "route", "s", "uri", ".", "use", "by", "Route", "::", "group", "method", "." ]
train
https://github.com/qlake/framework/blob/0b7bad459ae0721bc5cdd141344f9dfc1acee28a/src/Qlake/Routing/Route.php#L239-L251
qlake/framework
src/Qlake/Routing/Route.php
Route.isMatch
public function isMatch($pathInfo) { $this->compile(); $pathInfo = trim($pathInfo, '/'); if (!preg_match($this->pattern, $pathInfo, $paramValues)) { return false; } foreach ($this->paramNames as $name) { $this->params[$name] = isset($paramValues[$name]) ? urldecode($paramValues[$name]) : null; } return true; }
php
public function isMatch($pathInfo) { $this->compile(); $pathInfo = trim($pathInfo, '/'); if (!preg_match($this->pattern, $pathInfo, $paramValues)) { return false; } foreach ($this->paramNames as $name) { $this->params[$name] = isset($paramValues[$name]) ? urldecode($paramValues[$name]) : null; } return true; }
[ "public", "function", "isMatch", "(", "$", "pathInfo", ")", "{", "$", "this", "->", "compile", "(", ")", ";", "$", "pathInfo", "=", "trim", "(", "$", "pathInfo", ",", "'/'", ")", ";", "if", "(", "!", "preg_match", "(", "$", "this", "->", "pattern", ",", "$", "pathInfo", ",", "$", "paramValues", ")", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "this", "->", "paramNames", "as", "$", "name", ")", "{", "$", "this", "->", "params", "[", "$", "name", "]", "=", "isset", "(", "$", "paramValues", "[", "$", "name", "]", ")", "?", "urldecode", "(", "$", "paramValues", "[", "$", "name", "]", ")", ":", "null", ";", "}", "return", "true", ";", "}" ]
Determine matching route by given uri. @param string $pathInfo @return bool
[ "Determine", "matching", "route", "by", "given", "uri", "." ]
train
https://github.com/qlake/framework/blob/0b7bad459ae0721bc5cdd141344f9dfc1acee28a/src/Qlake/Routing/Route.php#L261-L278
qlake/framework
src/Qlake/Routing/Route.php
Route.compile
public function compile() { //reset arrays $this->params = []; $this->paramNames = []; $this->conditions = []; $this->compiled = true; $uri = $this->normalizeUri($this->getUri()); // match patterns like /{param?:regex} // tested in https://regex101.com/r/gP6yH7 $regex = preg_replace_callback( '#(?:(\\/)?\\{(\\w+)(\\?)?(?::((?:\\\\\\{|\\\\\\}|[^{}]|\\{\\d(?:\\,(?:\\d)?)?\\})+))?\\})#', [$this, 'createRegex'], $uri ); $regex .= "/?"; $regex = '#^' . $regex . '$#'; if ($this->caseSensitive === false) { $regex .= 'i'; } $this->pattern = $regex; return $this; }
php
public function compile() { //reset arrays $this->params = []; $this->paramNames = []; $this->conditions = []; $this->compiled = true; $uri = $this->normalizeUri($this->getUri()); // match patterns like /{param?:regex} // tested in https://regex101.com/r/gP6yH7 $regex = preg_replace_callback( '#(?:(\\/)?\\{(\\w+)(\\?)?(?::((?:\\\\\\{|\\\\\\}|[^{}]|\\{\\d(?:\\,(?:\\d)?)?\\})+))?\\})#', [$this, 'createRegex'], $uri ); $regex .= "/?"; $regex = '#^' . $regex . '$#'; if ($this->caseSensitive === false) { $regex .= 'i'; } $this->pattern = $regex; return $this; }
[ "public", "function", "compile", "(", ")", "{", "//reset arrays", "$", "this", "->", "params", "=", "[", "]", ";", "$", "this", "->", "paramNames", "=", "[", "]", ";", "$", "this", "->", "conditions", "=", "[", "]", ";", "$", "this", "->", "compiled", "=", "true", ";", "$", "uri", "=", "$", "this", "->", "normalizeUri", "(", "$", "this", "->", "getUri", "(", ")", ")", ";", "// match patterns like /{param?:regex}", "// tested in https://regex101.com/r/gP6yH7", "$", "regex", "=", "preg_replace_callback", "(", "'#(?:(\\\\/)?\\\\{(\\\\w+)(\\\\?)?(?::((?:\\\\\\\\\\\\{|\\\\\\\\\\\\}|[^{}]|\\\\{\\\\d(?:\\\\,(?:\\\\d)?)?\\\\})+))?\\\\})#'", ",", "[", "$", "this", ",", "'createRegex'", "]", ",", "$", "uri", ")", ";", "$", "regex", ".=", "\"/?\"", ";", "$", "regex", "=", "'#^'", ".", "$", "regex", ".", "'$#'", ";", "if", "(", "$", "this", "->", "caseSensitive", "===", "false", ")", "{", "$", "regex", ".=", "'i'", ";", "}", "$", "this", "->", "pattern", "=", "$", "regex", ";", "return", "$", "this", ";", "}" ]
Compile route uri pattern regex @return Qlake\Routing\Route
[ "Compile", "route", "uri", "pattern", "regex" ]
train
https://github.com/qlake/framework/blob/0b7bad459ae0721bc5cdd141344f9dfc1acee28a/src/Qlake/Routing/Route.php#L391-L422
qlake/framework
src/Qlake/Routing/Route.php
Route.createRegex
protected function createRegex($matched) { $startSlash = $matched[1] ? true : false; $param = $matched[2]; $optional = $matched[3] ? true : false; $pattern = $matched[4] ?: null; $pattern = $this->conditions[$param] ?: $pattern ?: '[^/]+'; $this->paramNames[] = $param; if ($startSlash) { $regex = ($optional ? "(/" : '/') .'(?P<' . $param . '>' . $pattern . ')'. ($optional ? ')?' : ''); } else { $regex = '(?P<' . $param . '>' . $pattern . ')'. ($optional ? '?' : ''); } return $regex; }
php
protected function createRegex($matched) { $startSlash = $matched[1] ? true : false; $param = $matched[2]; $optional = $matched[3] ? true : false; $pattern = $matched[4] ?: null; $pattern = $this->conditions[$param] ?: $pattern ?: '[^/]+'; $this->paramNames[] = $param; if ($startSlash) { $regex = ($optional ? "(/" : '/') .'(?P<' . $param . '>' . $pattern . ')'. ($optional ? ')?' : ''); } else { $regex = '(?P<' . $param . '>' . $pattern . ')'. ($optional ? '?' : ''); } return $regex; }
[ "protected", "function", "createRegex", "(", "$", "matched", ")", "{", "$", "startSlash", "=", "$", "matched", "[", "1", "]", "?", "true", ":", "false", ";", "$", "param", "=", "$", "matched", "[", "2", "]", ";", "$", "optional", "=", "$", "matched", "[", "3", "]", "?", "true", ":", "false", ";", "$", "pattern", "=", "$", "matched", "[", "4", "]", "?", ":", "null", ";", "$", "pattern", "=", "$", "this", "->", "conditions", "[", "$", "param", "]", "?", ":", "$", "pattern", "?", ":", "'[^/]+'", ";", "$", "this", "->", "paramNames", "[", "]", "=", "$", "param", ";", "if", "(", "$", "startSlash", ")", "{", "$", "regex", "=", "(", "$", "optional", "?", "\"(/\"", ":", "'/'", ")", ".", "'(?P<'", ".", "$", "param", ".", "'>'", ".", "$", "pattern", ".", "')'", ".", "(", "$", "optional", "?", "')?'", ":", "''", ")", ";", "}", "else", "{", "$", "regex", "=", "'(?P<'", ".", "$", "param", ".", "'>'", ".", "$", "pattern", ".", "')'", ".", "(", "$", "optional", "?", "'?'", ":", "''", ")", ";", "}", "return", "$", "regex", ";", "}" ]
Callback for creating route param names regex @param array $matched @return string
[ "Callback", "for", "creating", "route", "param", "names", "regex" ]
train
https://github.com/qlake/framework/blob/0b7bad459ae0721bc5cdd141344f9dfc1acee28a/src/Qlake/Routing/Route.php#L432-L453