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
|
---|---|---|---|---|---|---|---|---|---|---|
Danack/GithubArtaxService | lib/GithubService/Operation/searchRepos.php | searchRepos.dispatchAsync | public function dispatchAsync(\Amp\Artax\Request $request, callable $callable) {
return $this->api->executeAsync($request, $this, $callable);
} | php | public function dispatchAsync(\Amp\Artax\Request $request, callable $callable) {
return $this->api->executeAsync($request, $this, $callable);
} | [
"public",
"function",
"dispatchAsync",
"(",
"\\",
"Amp",
"\\",
"Artax",
"\\",
"Request",
"$",
"request",
",",
"callable",
"$",
"callable",
")",
"{",
"return",
"$",
"this",
"->",
"api",
"->",
"executeAsync",
"(",
"$",
"request",
",",
"$",
"this",
",",
"$",
"callable",
")",
";",
"}"
] | Dispatch the request for this operation and process the response asynchronously.
Allows you to modify the request before it is sent.
@return \GithubService\Model\SearchRepos
@param \Amp\Artax\Request $request The request to be processed
@param callable $callable The callable that processes the response | [
"Dispatch",
"the",
"request",
"for",
"this",
"operation",
"and",
"process",
"the",
"response",
"asynchronously",
".",
"Allows",
"you",
"to",
"modify",
"the",
"request",
"before",
"it",
"is",
"sent",
"."
] | train | https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Operation/searchRepos.php#L359-L361 |
Danack/GithubArtaxService | lib/GithubService/Operation/searchRepos.php | searchRepos.processResponse | public function processResponse(\Amp\Artax\Response $response) {
$instance = $this->api->instantiateResult($response, $this);
return $instance;
} | php | public function processResponse(\Amp\Artax\Response $response) {
$instance = $this->api->instantiateResult($response, $this);
return $instance;
} | [
"public",
"function",
"processResponse",
"(",
"\\",
"Amp",
"\\",
"Artax",
"\\",
"Response",
"$",
"response",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"api",
"->",
"instantiateResult",
"(",
"$",
"response",
",",
"$",
"this",
")",
";",
"return",
"$",
"instance",
";",
"}"
] | Dispatch the request for this operation and process the response. Allows you to
modify the request before it is sent.
@return \GithubService\Model\SearchRepos
@param \Amp\Artax\Response $response The HTTP response. | [
"Dispatch",
"the",
"request",
"for",
"this",
"operation",
"and",
"process",
"the",
"response",
".",
"Allows",
"you",
"to",
"modify",
"the",
"request",
"before",
"it",
"is",
"sent",
"."
] | train | https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Operation/searchRepos.php#L370-L374 |
ekuiter/feature-php | FeaturePhp/Generator/Generator.php | Generator.getGeneratorMap | public static function getGeneratorMap() {
$generatorMap = array();
foreach (self::getGenerators() as $generator)
$generatorMap[call_user_func(array($generator, "getKey"))] = $generator;
return $generatorMap;
} | php | public static function getGeneratorMap() {
$generatorMap = array();
foreach (self::getGenerators() as $generator)
$generatorMap[call_user_func(array($generator, "getKey"))] = $generator;
return $generatorMap;
} | [
"public",
"static",
"function",
"getGeneratorMap",
"(",
")",
"{",
"$",
"generatorMap",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"getGenerators",
"(",
")",
"as",
"$",
"generator",
")",
"$",
"generatorMap",
"[",
"call_user_func",
"(",
"array",
"(",
"$",
"generator",
",",
"\"getKey\"",
")",
")",
"]",
"=",
"$",
"generator",
";",
"return",
"$",
"generatorMap",
";",
"}"
] | Returns a map from all generator keys to class names.
@return string[] | [
"Returns",
"a",
"map",
"from",
"all",
"generator",
"keys",
"to",
"class",
"names",
"."
] | train | https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Generator/Generator.php#L68-L73 |
ekuiter/feature-php | FeaturePhp/Generator/Generator.php | Generator.generateFiles | public function generateFiles() {
if ($this->files === null) {
$this->files = array();
$this->tracingLinks = array();
$this->_generateFiles();
}
if ($this->settings->getOptional("logFile", false))
return array_merge(array($this->logFile), $this->files);
else
return $this->files;
} | php | public function generateFiles() {
if ($this->files === null) {
$this->files = array();
$this->tracingLinks = array();
$this->_generateFiles();
}
if ($this->settings->getOptional("logFile", false))
return array_merge(array($this->logFile), $this->files);
else
return $this->files;
} | [
"public",
"function",
"generateFiles",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"files",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"files",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"tracingLinks",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"_generateFiles",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"settings",
"->",
"getOptional",
"(",
"\"logFile\"",
",",
"false",
")",
")",
"return",
"array_merge",
"(",
"array",
"(",
"$",
"this",
"->",
"logFile",
")",
",",
"$",
"this",
"->",
"files",
")",
";",
"else",
"return",
"$",
"this",
"->",
"files",
";",
"}"
] | Generates the files for all registered artifacts.
If the files have already been generated, returns the cached files.
The generator's log file is included.
@return \FeaturePhp\File\File[] | [
"Generates",
"the",
"files",
"for",
"all",
"registered",
"artifacts",
".",
"If",
"the",
"files",
"have",
"already",
"been",
"generated",
"returns",
"the",
"cached",
"files",
".",
"The",
"generator",
"s",
"log",
"file",
"is",
"included",
"."
] | train | https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Generator/Generator.php#L134-L144 |
ekuiter/feature-php | FeaturePhp/Generator/Generator.php | Generator.isSelectedFeature | protected function isSelectedFeature($featureName) {
$isSelected = false;
foreach ($this->selectedArtifacts as $selectedArtifact)
if ($featureName === $selectedArtifact->getFeature()->getName())
$isSelected = true;
return $isSelected;
} | php | protected function isSelectedFeature($featureName) {
$isSelected = false;
foreach ($this->selectedArtifacts as $selectedArtifact)
if ($featureName === $selectedArtifact->getFeature()->getName())
$isSelected = true;
return $isSelected;
} | [
"protected",
"function",
"isSelectedFeature",
"(",
"$",
"featureName",
")",
"{",
"$",
"isSelected",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"selectedArtifacts",
"as",
"$",
"selectedArtifact",
")",
"if",
"(",
"$",
"featureName",
"===",
"$",
"selectedArtifact",
"->",
"getFeature",
"(",
")",
"->",
"getName",
"(",
")",
")",
"$",
"isSelected",
"=",
"true",
";",
"return",
"$",
"isSelected",
";",
"}"
] | Returns whether a feature's artifact is selected.
@param string $featureName
@return bool | [
"Returns",
"whether",
"a",
"feature",
"s",
"artifact",
"is",
"selected",
"."
] | train | https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Generator/Generator.php#L160-L166 |
kenphp/ken | src/Http/MiddlewareFactory.php | MiddlewareFactory.createObject | public function createObject($builder, $parameters = array()) {
if (is_string($builder)) {
if (class_exists($builder)) {
$response = $parameters['response'];
$nextMiddleware = $parameters['next'];
if ($response == null) {
throw new InvalidArgumentException("'response' parameters must be 'Psr\Http\Message\ResponseInterface' instance.");
}
if ($nextMiddleware != null) {
if (($nextMiddleware instanceof BaseMiddleware) == false) {
throw new InvalidArgumentException("'next' parameters must be 'Ken\Http\BaseMiddleware' instance.");
}
}
return new $builder($response, $nextMiddleware);
}
throw new InvalidArgumentException("Class '{$builder}' not found.");
}
throw new InvalidArgumentException("'builder' must be a fully qualified namespace of middleware class.");
} | php | public function createObject($builder, $parameters = array()) {
if (is_string($builder)) {
if (class_exists($builder)) {
$response = $parameters['response'];
$nextMiddleware = $parameters['next'];
if ($response == null) {
throw new InvalidArgumentException("'response' parameters must be 'Psr\Http\Message\ResponseInterface' instance.");
}
if ($nextMiddleware != null) {
if (($nextMiddleware instanceof BaseMiddleware) == false) {
throw new InvalidArgumentException("'next' parameters must be 'Ken\Http\BaseMiddleware' instance.");
}
}
return new $builder($response, $nextMiddleware);
}
throw new InvalidArgumentException("Class '{$builder}' not found.");
}
throw new InvalidArgumentException("'builder' must be a fully qualified namespace of middleware class.");
} | [
"public",
"function",
"createObject",
"(",
"$",
"builder",
",",
"$",
"parameters",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"builder",
")",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"builder",
")",
")",
"{",
"$",
"response",
"=",
"$",
"parameters",
"[",
"'response'",
"]",
";",
"$",
"nextMiddleware",
"=",
"$",
"parameters",
"[",
"'next'",
"]",
";",
"if",
"(",
"$",
"response",
"==",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"'response' parameters must be 'Psr\\Http\\Message\\ResponseInterface' instance.\"",
")",
";",
"}",
"if",
"(",
"$",
"nextMiddleware",
"!=",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"nextMiddleware",
"instanceof",
"BaseMiddleware",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"'next' parameters must be 'Ken\\Http\\BaseMiddleware' instance.\"",
")",
";",
"}",
"}",
"return",
"new",
"$",
"builder",
"(",
"$",
"response",
",",
"$",
"nextMiddleware",
")",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Class '{$builder}' not found.\"",
")",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"'builder' must be a fully qualified namespace of middleware class.\"",
")",
";",
"}"
] | Creates a middleware instance
@param string $builder A fully qualified namespace of middleware class.
The middleware class must extend **Ken\Http\BaseMiddleware** class.
@param array $parameters An array containing :
'response' : an instance of **Psr\Http\Message\ResponseInterface**
'next' : null or an instance of **Ken\Http\BaseMiddleware**
@return \Ken\Http\BaseMiddleware
@throws InvalidArgumentException | [
"Creates",
"a",
"middleware",
"instance"
] | train | https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Http/MiddlewareFactory.php#L23-L46 |
skeeks-cms/cms-log-db-target | src/console/controllers/AgentsController.php | AgentsController.actionClearLogs | public function actionClearLogs()
{
$deleted = LogDbTargetModel::deleteAll([
'<=', 'log_time', \Yii::$app->formatter->asTimestamp(time()) - (int) \Yii::$app->logDbTargetSettings->storeLogsTime
]);
$this->stdout('storeLogsTime: ' . \Yii::$app->logDbTargetSettings->storeLogsTime . "\n");
$this->stdout('Clear logs: ' . $deleted . "\n");
\Yii::info(\Yii::t('skeeks/logdb/app', 'The number of remote logging') . ": " . $deleted);
} | php | public function actionClearLogs()
{
$deleted = LogDbTargetModel::deleteAll([
'<=', 'log_time', \Yii::$app->formatter->asTimestamp(time()) - (int) \Yii::$app->logDbTargetSettings->storeLogsTime
]);
$this->stdout('storeLogsTime: ' . \Yii::$app->logDbTargetSettings->storeLogsTime . "\n");
$this->stdout('Clear logs: ' . $deleted . "\n");
\Yii::info(\Yii::t('skeeks/logdb/app', 'The number of remote logging') . ": " . $deleted);
} | [
"public",
"function",
"actionClearLogs",
"(",
")",
"{",
"$",
"deleted",
"=",
"LogDbTargetModel",
"::",
"deleteAll",
"(",
"[",
"'<='",
",",
"'log_time'",
",",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"formatter",
"->",
"asTimestamp",
"(",
"time",
"(",
")",
")",
"-",
"(",
"int",
")",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"logDbTargetSettings",
"->",
"storeLogsTime",
"]",
")",
";",
"$",
"this",
"->",
"stdout",
"(",
"'storeLogsTime: '",
".",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"logDbTargetSettings",
"->",
"storeLogsTime",
".",
"\"\\n\"",
")",
";",
"$",
"this",
"->",
"stdout",
"(",
"'Clear logs: '",
".",
"$",
"deleted",
".",
"\"\\n\"",
")",
";",
"\\",
"Yii",
"::",
"info",
"(",
"\\",
"Yii",
"::",
"t",
"(",
"'skeeks/logdb/app'",
",",
"'The number of remote logging'",
")",
".",
"\": \"",
".",
"$",
"deleted",
")",
";",
"}"
] | Просмотр созданных бекапов баз данных | [
"Просмотр",
"созданных",
"бекапов",
"баз",
"данных"
] | train | https://github.com/skeeks-cms/cms-log-db-target/blob/cb660a50d0d4d734096230e525f66855a7373d14/src/console/controllers/AgentsController.php#L23-L33 |
mothership-ec/composer | src/Composer/Repository/PlatformRepository.php | PlatformRepository.addPackage | public function addPackage(PackageInterface $package)
{
// Skip if overridden
if (isset($this->overrides[strtolower($package->getName())])) {
return;
}
parent::addPackage($package);
} | php | public function addPackage(PackageInterface $package)
{
// Skip if overridden
if (isset($this->overrides[strtolower($package->getName())])) {
return;
}
parent::addPackage($package);
} | [
"public",
"function",
"addPackage",
"(",
"PackageInterface",
"$",
"package",
")",
"{",
"// Skip if overridden",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"overrides",
"[",
"strtolower",
"(",
"$",
"package",
"->",
"getName",
"(",
")",
")",
"]",
")",
")",
"{",
"return",
";",
"}",
"parent",
"::",
"addPackage",
"(",
"$",
"package",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Repository/PlatformRepository.php#L200-L207 |
asbamboo/database | command/CommandAbstract.php | CommandAbstract.getDbFactory | protected function getDbFactory() : FactoryInterface
{
$guess_config_in_dir = getcwd();
for($i = 0; $i < 3; $i++ ){
$custom_config_path = $guess_config_in_dir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'db-config.php';
if(file_exists($custom_config_path)){
break;
}
$guess_config_in_dir = dirname($guess_config_in_dir);
}
if(file_exists($custom_config_path)){
return include $custom_config_path;
}
} | php | protected function getDbFactory() : FactoryInterface
{
$guess_config_in_dir = getcwd();
for($i = 0; $i < 3; $i++ ){
$custom_config_path = $guess_config_in_dir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'db-config.php';
if(file_exists($custom_config_path)){
break;
}
$guess_config_in_dir = dirname($guess_config_in_dir);
}
if(file_exists($custom_config_path)){
return include $custom_config_path;
}
} | [
"protected",
"function",
"getDbFactory",
"(",
")",
":",
"FactoryInterface",
"{",
"$",
"guess_config_in_dir",
"=",
"getcwd",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"3",
";",
"$",
"i",
"++",
")",
"{",
"$",
"custom_config_path",
"=",
"$",
"guess_config_in_dir",
".",
"DIRECTORY_SEPARATOR",
".",
"'config'",
".",
"DIRECTORY_SEPARATOR",
".",
"'db-config.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"custom_config_path",
")",
")",
"{",
"break",
";",
"}",
"$",
"guess_config_in_dir",
"=",
"dirname",
"(",
"$",
"guess_config_in_dir",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"custom_config_path",
")",
")",
"{",
"return",
"include",
"$",
"custom_config_path",
";",
"}",
"}"
] | 返回一个 Factory 实例
通过在查找项目里面 ../config/db-config.php 文件得到一个 factory
使用本命令工具前你需要首先添加在项目中添加配置文件 config/db-config.php 这个文件返回一个 Factory 实例
@return FactoryInterface | [
"返回一个",
"Factory",
"实例",
"通过在查找项目里面",
"..",
"/",
"config",
"/",
"db",
"-",
"config",
".",
"php",
"文件得到一个",
"factory",
"使用本命令工具前你需要首先添加在项目中添加配置文件",
"config",
"/",
"db",
"-",
"config",
".",
"php",
"这个文件返回一个",
"Factory",
"实例"
] | train | https://github.com/asbamboo/database/blob/cb3260b0b267def7257d728ec639b6776d1b5a10/command/CommandAbstract.php#L42-L55 |
nabab/bbn | src/bbn/file/dir.php | dir.has_file | public static function has_file(string $dir): bool
{
$dir = self::clean($dir);
$as = \func_get_args();
array_shift($as);
foreach ( $as as $a ){
if ( !file_exists($dir.'/'.$a) ){
return false;
}
}
return true;
} | php | public static function has_file(string $dir): bool
{
$dir = self::clean($dir);
$as = \func_get_args();
array_shift($as);
foreach ( $as as $a ){
if ( !file_exists($dir.'/'.$a) ){
return false;
}
}
return true;
} | [
"public",
"static",
"function",
"has_file",
"(",
"string",
"$",
"dir",
")",
":",
"bool",
"{",
"$",
"dir",
"=",
"self",
"::",
"clean",
"(",
"$",
"dir",
")",
";",
"$",
"as",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"array_shift",
"(",
"$",
"as",
")",
";",
"foreach",
"(",
"$",
"as",
"as",
"$",
"a",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dir",
".",
"'/'",
".",
"$",
"a",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks if the given file(s) exists in the directory.
Accepts unlimited arguments (files name).
```php
\bbn\x::dump(\bbn\file\dir::has_file("/home/data/test/file.txt"));
// (bool) true
\bbn\x::dump(\bbn\file\dir::has_file("/home/data/test", "file.txt", "doc.pdf"));
// (bool) true
```
@param string $dir The directory's path.
@return bool | [
"Checks",
"if",
"the",
"given",
"file",
"(",
"s",
")",
"exists",
"in",
"the",
"directory",
".",
"Accepts",
"unlimited",
"arguments",
"(",
"files",
"name",
")",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/dir.php#L55-L66 |
nabab/bbn | src/bbn/file/dir.php | dir.get_dirs | public static function get_dirs($dir, $hidden = false){
$dir = self::clean($dir);
clearstatcache();
if ( $dir === './' ){
$dir = '.';
}
if ( is_dir($dir) && (($dir === '.') || ((strpos(basename($dir), '.') !== 0) || $hidden)) ){
$dirs = [];
$fs = scandir($dir, SCANDIR_SORT_ASCENDING );
foreach ( $fs as $f ){
if ( $f !== '.' && $f !== '..' && is_dir($dir.'/'.$f) ){
$dirs[] = self::cur($dir.'/').$f;
}
}
if ( !empty($dirs) ){
bbn\x::sort($dirs);
}
return $dirs;
}
return false;
} | php | public static function get_dirs($dir, $hidden = false){
$dir = self::clean($dir);
clearstatcache();
if ( $dir === './' ){
$dir = '.';
}
if ( is_dir($dir) && (($dir === '.') || ((strpos(basename($dir), '.') !== 0) || $hidden)) ){
$dirs = [];
$fs = scandir($dir, SCANDIR_SORT_ASCENDING );
foreach ( $fs as $f ){
if ( $f !== '.' && $f !== '..' && is_dir($dir.'/'.$f) ){
$dirs[] = self::cur($dir.'/').$f;
}
}
if ( !empty($dirs) ){
bbn\x::sort($dirs);
}
return $dirs;
}
return false;
} | [
"public",
"static",
"function",
"get_dirs",
"(",
"$",
"dir",
",",
"$",
"hidden",
"=",
"false",
")",
"{",
"$",
"dir",
"=",
"self",
"::",
"clean",
"(",
"$",
"dir",
")",
";",
"clearstatcache",
"(",
")",
";",
"if",
"(",
"$",
"dir",
"===",
"'./'",
")",
"{",
"$",
"dir",
"=",
"'.'",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
"&&",
"(",
"(",
"$",
"dir",
"===",
"'.'",
")",
"||",
"(",
"(",
"strpos",
"(",
"basename",
"(",
"$",
"dir",
")",
",",
"'.'",
")",
"!==",
"0",
")",
"||",
"$",
"hidden",
")",
")",
")",
"{",
"$",
"dirs",
"=",
"[",
"]",
";",
"$",
"fs",
"=",
"scandir",
"(",
"$",
"dir",
",",
"SCANDIR_SORT_ASCENDING",
")",
";",
"foreach",
"(",
"$",
"fs",
"as",
"$",
"f",
")",
"{",
"if",
"(",
"$",
"f",
"!==",
"'.'",
"&&",
"$",
"f",
"!==",
"'..'",
"&&",
"is_dir",
"(",
"$",
"dir",
".",
"'/'",
".",
"$",
"f",
")",
")",
"{",
"$",
"dirs",
"[",
"]",
"=",
"self",
"::",
"cur",
"(",
"$",
"dir",
".",
"'/'",
")",
".",
"$",
"f",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"dirs",
")",
")",
"{",
"bbn",
"\\",
"x",
"::",
"sort",
"(",
"$",
"dirs",
")",
";",
"}",
"return",
"$",
"dirs",
";",
"}",
"return",
"false",
";",
"}"
] | Return an array of directories contained in the given directory.
It will return directories' full path.
@todo vedere il parametro $hidden non mi funziona
```php
\bbn\x::dump(\bbn\file\dir::get_dirs("C:\Docs\Test"));
// (array) ['C:\DocsTest\test1', 'C:\DocsTest\test2', 'C:\DocsTest\test3']
```
@param string $dir The directory's path.
@param bool $hidden If true return the hidden directories' path
@return array|false | [
"Return",
"an",
"array",
"of",
"directories",
"contained",
"in",
"the",
"given",
"directory",
".",
"It",
"will",
"return",
"directories",
"full",
"path",
".",
"@todo",
"vedere",
"il",
"parametro",
"$hidden",
"non",
"mi",
"funziona"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/dir.php#L100-L120 |
nabab/bbn | src/bbn/file/dir.php | dir.get_files | public static function get_files($dir, $including_dirs = false, $hidden = false, $extension = null)
{
$dir = self::clean($dir);
clearstatcache();
if ( $dir === './' ){
$dir = '.';
}
if ( is_dir($dir) && (($dir === '.') || ((strpos(basename($dir), '.') !== 0) || $hidden)) ){
$files = [];
$fs = scandir($dir, SCANDIR_SORT_ASCENDING );
//$encodings = ['UTF-8', 'WINDOWS-1252', 'ISO-8859-1', 'ISO-8859-15'];
foreach ( $fs as $f ){
if ( $f !== '.' && $f !== '..' ){
/*
$enc = mb_detect_encoding($f, $encodings);
if ( $enc !== 'UTF-8' ){
$f = html_entity_decode(htmlentities($f, ENT_QUOTES, $enc), ENT_QUOTES , 'UTF-8');
}
*/
if ( $hidden || (strpos(basename($f), '.') !== 0) ){
if ( $including_dirs ){
$files[] = self::cur($dir.'/').$f;
}
else if ( is_file($dir.'/'.$f) ){
if ( !$extension || (strtolower($extension) === strtolower(bbn\str::file_ext($f))) ){
$files[] = self::cur($dir.'/').$f;
}
}
}
}
}
if ( \count($files) > 0 ){
bbn\x::sort($files);
}
return $files;
}
return false;
} | php | public static function get_files($dir, $including_dirs = false, $hidden = false, $extension = null)
{
$dir = self::clean($dir);
clearstatcache();
if ( $dir === './' ){
$dir = '.';
}
if ( is_dir($dir) && (($dir === '.') || ((strpos(basename($dir), '.') !== 0) || $hidden)) ){
$files = [];
$fs = scandir($dir, SCANDIR_SORT_ASCENDING );
//$encodings = ['UTF-8', 'WINDOWS-1252', 'ISO-8859-1', 'ISO-8859-15'];
foreach ( $fs as $f ){
if ( $f !== '.' && $f !== '..' ){
/*
$enc = mb_detect_encoding($f, $encodings);
if ( $enc !== 'UTF-8' ){
$f = html_entity_decode(htmlentities($f, ENT_QUOTES, $enc), ENT_QUOTES , 'UTF-8');
}
*/
if ( $hidden || (strpos(basename($f), '.') !== 0) ){
if ( $including_dirs ){
$files[] = self::cur($dir.'/').$f;
}
else if ( is_file($dir.'/'.$f) ){
if ( !$extension || (strtolower($extension) === strtolower(bbn\str::file_ext($f))) ){
$files[] = self::cur($dir.'/').$f;
}
}
}
}
}
if ( \count($files) > 0 ){
bbn\x::sort($files);
}
return $files;
}
return false;
} | [
"public",
"static",
"function",
"get_files",
"(",
"$",
"dir",
",",
"$",
"including_dirs",
"=",
"false",
",",
"$",
"hidden",
"=",
"false",
",",
"$",
"extension",
"=",
"null",
")",
"{",
"$",
"dir",
"=",
"self",
"::",
"clean",
"(",
"$",
"dir",
")",
";",
"clearstatcache",
"(",
")",
";",
"if",
"(",
"$",
"dir",
"===",
"'./'",
")",
"{",
"$",
"dir",
"=",
"'.'",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
"&&",
"(",
"(",
"$",
"dir",
"===",
"'.'",
")",
"||",
"(",
"(",
"strpos",
"(",
"basename",
"(",
"$",
"dir",
")",
",",
"'.'",
")",
"!==",
"0",
")",
"||",
"$",
"hidden",
")",
")",
")",
"{",
"$",
"files",
"=",
"[",
"]",
";",
"$",
"fs",
"=",
"scandir",
"(",
"$",
"dir",
",",
"SCANDIR_SORT_ASCENDING",
")",
";",
"//$encodings = ['UTF-8', 'WINDOWS-1252', 'ISO-8859-1', 'ISO-8859-15'];",
"foreach",
"(",
"$",
"fs",
"as",
"$",
"f",
")",
"{",
"if",
"(",
"$",
"f",
"!==",
"'.'",
"&&",
"$",
"f",
"!==",
"'..'",
")",
"{",
"/*\n $enc = mb_detect_encoding($f, $encodings);\n if ( $enc !== 'UTF-8' ){\n $f = html_entity_decode(htmlentities($f, ENT_QUOTES, $enc), ENT_QUOTES , 'UTF-8');\n }\n */",
"if",
"(",
"$",
"hidden",
"||",
"(",
"strpos",
"(",
"basename",
"(",
"$",
"f",
")",
",",
"'.'",
")",
"!==",
"0",
")",
")",
"{",
"if",
"(",
"$",
"including_dirs",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"self",
"::",
"cur",
"(",
"$",
"dir",
".",
"'/'",
")",
".",
"$",
"f",
";",
"}",
"else",
"if",
"(",
"is_file",
"(",
"$",
"dir",
".",
"'/'",
".",
"$",
"f",
")",
")",
"{",
"if",
"(",
"!",
"$",
"extension",
"||",
"(",
"strtolower",
"(",
"$",
"extension",
")",
"===",
"strtolower",
"(",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"$",
"f",
")",
")",
")",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"self",
"::",
"cur",
"(",
"$",
"dir",
".",
"'/'",
")",
".",
"$",
"f",
";",
"}",
"}",
"}",
"}",
"}",
"if",
"(",
"\\",
"count",
"(",
"$",
"files",
")",
">",
"0",
")",
"{",
"bbn",
"\\",
"x",
"::",
"sort",
"(",
"$",
"files",
")",
";",
"}",
"return",
"$",
"files",
";",
"}",
"return",
"false",
";",
"}"
] | Returns an array of files contained in the given directory.
Returns the full path of files.
```php
\bbn\x::dump(\bbn\file\dir::get_files("/home/Docs/Test"));
// (array) ['/home/Docs/Test/file.txt']
\bbn\x::dump(\bbn\file\dir::get_files("/home/Docs/Test",0,1));
// (array) ['/home/Docs/Test/file.txt', '/home/Docs/Test/.doc.pdf']
\bbn\x::dump(\bbn\file\dir::get_files("/home/Docs/Test", 1));
// (array) ['/home/Docs/Test/folder', '/home/Docs/Test/file.txt']
\bbn\x::dump(\bbn\file\dir::get_files("/home/Docs/Test", 1,1));
// (array) ['/home/Docs/Test/folder', '/home/Docs/Test/.folder_test','/home/Docs/Test/file.txt', '/home/Docs/Test/.doc.pdf']
```
@param string $dir The directory's path.
@param bool $including_dirs If set to true it will also returns the folders contained in the given directory.
@param bool $hidden If set to true will also returns the hidden files contained the directory
@return array|false | [
"Returns",
"an",
"array",
"of",
"files",
"contained",
"in",
"the",
"given",
"directory",
".",
"Returns",
"the",
"full",
"path",
"of",
"files",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/dir.php#L142-L179 |
nabab/bbn | src/bbn/file/dir.php | dir.delete | public static function delete(string $dir, bool $full = true): bool
{
$dir = self::clean($dir);
if ( is_dir($dir) ){
$files = self::get_files($dir, 1, 1);
foreach ( $files as $file ){
self::delete($file);
}
if ( $full ){
return rmdir($dir);
}
return true;
}
if ( is_file($dir) ){
return unlink($dir);
}
return false;
} | php | public static function delete(string $dir, bool $full = true): bool
{
$dir = self::clean($dir);
if ( is_dir($dir) ){
$files = self::get_files($dir, 1, 1);
foreach ( $files as $file ){
self::delete($file);
}
if ( $full ){
return rmdir($dir);
}
return true;
}
if ( is_file($dir) ){
return unlink($dir);
}
return false;
} | [
"public",
"static",
"function",
"delete",
"(",
"string",
"$",
"dir",
",",
"bool",
"$",
"full",
"=",
"true",
")",
":",
"bool",
"{",
"$",
"dir",
"=",
"self",
"::",
"clean",
"(",
"$",
"dir",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"files",
"=",
"self",
"::",
"get_files",
"(",
"$",
"dir",
",",
"1",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"self",
"::",
"delete",
"(",
"$",
"file",
")",
";",
"}",
"if",
"(",
"$",
"full",
")",
"{",
"return",
"rmdir",
"(",
"$",
"dir",
")",
";",
"}",
"return",
"true",
";",
"}",
"if",
"(",
"is_file",
"(",
"$",
"dir",
")",
")",
"{",
"return",
"unlink",
"(",
"$",
"dir",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Deletes the given directory and all its content.
```php
\bbn\x::dump(\bbn\file\dir::delete('/home/Docs/Test/')
// (bool) true
\bbn\x::dump(\bbn\file\dir::delete('/home/Docs/Test', 0);
// (bool) false
\bbn\x::dump(\bbn\file\dir::delete('/home/Docs/Test/file.txt');
// (bool) false
```
@param string $dir The directory path's.
@param bool $full If set to '0' will delete only the content of the directory. Default: "1".
@return bool | [
"Deletes",
"the",
"given",
"directory",
"and",
"all",
"its",
"content",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/dir.php#L197-L214 |
nabab/bbn | src/bbn/file/dir.php | dir.scan | public static function scan(string $dir, string $type = null, bool $hidden = false): array
{
$all = [];
$dir = self::clean($dir);
$dirs = self::get_dirs($dir);
if ( \is_array($dirs) ){
if ( $type && (strpos($type, 'file') === 0) ){
$all = self::get_files($dir, false, $hidden);
}
else if ( $type && ((strpos($type, 'dir') === 0) || (strpos($type, 'fold') === 0)) ){
$all = $dirs;
}
else if ( $type ){
$all = array_filter(self::get_files($dir, false, $hidden), function($a)use($type){
$ext = bbn\str::file_ext($a);
return strtolower($ext) === strtolower($type);
});
}
else{
$files = self::get_files($dir, false, $hidden);
if ( \is_array($files) ){
$all = array_merge($dirs, $files);
}
}
foreach ( $dirs as $d ){
$all = array_merge(\is_array($all) ? $all : [], self::scan($d, $type, $hidden));
}
}
return $all;
} | php | public static function scan(string $dir, string $type = null, bool $hidden = false): array
{
$all = [];
$dir = self::clean($dir);
$dirs = self::get_dirs($dir);
if ( \is_array($dirs) ){
if ( $type && (strpos($type, 'file') === 0) ){
$all = self::get_files($dir, false, $hidden);
}
else if ( $type && ((strpos($type, 'dir') === 0) || (strpos($type, 'fold') === 0)) ){
$all = $dirs;
}
else if ( $type ){
$all = array_filter(self::get_files($dir, false, $hidden), function($a)use($type){
$ext = bbn\str::file_ext($a);
return strtolower($ext) === strtolower($type);
});
}
else{
$files = self::get_files($dir, false, $hidden);
if ( \is_array($files) ){
$all = array_merge($dirs, $files);
}
}
foreach ( $dirs as $d ){
$all = array_merge(\is_array($all) ? $all : [], self::scan($d, $type, $hidden));
}
}
return $all;
} | [
"public",
"static",
"function",
"scan",
"(",
"string",
"$",
"dir",
",",
"string",
"$",
"type",
"=",
"null",
",",
"bool",
"$",
"hidden",
"=",
"false",
")",
":",
"array",
"{",
"$",
"all",
"=",
"[",
"]",
";",
"$",
"dir",
"=",
"self",
"::",
"clean",
"(",
"$",
"dir",
")",
";",
"$",
"dirs",
"=",
"self",
"::",
"get_dirs",
"(",
"$",
"dir",
")",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"dirs",
")",
")",
"{",
"if",
"(",
"$",
"type",
"&&",
"(",
"strpos",
"(",
"$",
"type",
",",
"'file'",
")",
"===",
"0",
")",
")",
"{",
"$",
"all",
"=",
"self",
"::",
"get_files",
"(",
"$",
"dir",
",",
"false",
",",
"$",
"hidden",
")",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"&&",
"(",
"(",
"strpos",
"(",
"$",
"type",
",",
"'dir'",
")",
"===",
"0",
")",
"||",
"(",
"strpos",
"(",
"$",
"type",
",",
"'fold'",
")",
"===",
"0",
")",
")",
")",
"{",
"$",
"all",
"=",
"$",
"dirs",
";",
"}",
"else",
"if",
"(",
"$",
"type",
")",
"{",
"$",
"all",
"=",
"array_filter",
"(",
"self",
"::",
"get_files",
"(",
"$",
"dir",
",",
"false",
",",
"$",
"hidden",
")",
",",
"function",
"(",
"$",
"a",
")",
"use",
"(",
"$",
"type",
")",
"{",
"$",
"ext",
"=",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"$",
"a",
")",
";",
"return",
"strtolower",
"(",
"$",
"ext",
")",
"===",
"strtolower",
"(",
"$",
"type",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"$",
"files",
"=",
"self",
"::",
"get_files",
"(",
"$",
"dir",
",",
"false",
",",
"$",
"hidden",
")",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"files",
")",
")",
"{",
"$",
"all",
"=",
"array_merge",
"(",
"$",
"dirs",
",",
"$",
"files",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"d",
")",
"{",
"$",
"all",
"=",
"array_merge",
"(",
"\\",
"is_array",
"(",
"$",
"all",
")",
"?",
"$",
"all",
":",
"[",
"]",
",",
"self",
"::",
"scan",
"(",
"$",
"d",
",",
"$",
"type",
",",
"$",
"hidden",
")",
")",
";",
"}",
"}",
"return",
"$",
"all",
";",
"}"
] | Returns an array with all the content of the given directory.
@todo check the default value for $hidden
```php
\bbn\x::dump(\bbn\file\dir::scan("/home/data/test"));
// (array) ["/home/data/test/Folder", "/home/data/test/Folder_test/image.png"]
\bbn\x::dump(\bbn\file\dir::scan("/home/data/test", "", true));
// (array) ["/home/data/test/Folder", "/home/data/test/Folder_test/image.png", "/home/data/test/.doc.pdf"]
\bbn\x::dump(\bbn\file\dir::scan("/home/data/test", "dir"));
// (array) ["/home/data/test/Folder", "/home/data/test/Folder_test"]
\bbn\x::dump(\bbn\file\dir::scan("/home/data/test", "file"));
// (array) ["/home/data/test/Folder_test/image.png"]
\bbn\x::dump(\bbn\file\dir::scan("/home/data/test", "file", true));
// (array) ["/home/data/test/Folder_test/image.png", "/home/data/test/Folder/.doc.pdf"]
```
@param string $dir The directory's path.
@param string $type The type or the extension of item to return ('file', 'dir', 'php', default is both)
@param bool $hidden If set to true will include the hidden files/directories in the result
@return array | [
"Returns",
"an",
"array",
"with",
"all",
"the",
"content",
"of",
"the",
"given",
"directory",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/dir.php#L238-L267 |
nabab/bbn | src/bbn/file/dir.php | dir.mscan | public static function mscan(string $dir, string $type = null, $hidden = false): array
{
$res = [];
if ( $all = self::scan($dir, $type, $hidden) ){
foreach ($all as $a ){
$t = filemtime($a);
$res[] = ['name' => $a, 'mtime' => $t, 'date' => date('Y-m-d H:i:s', $t)];
}
}
return $res;
} | php | public static function mscan(string $dir, string $type = null, $hidden = false): array
{
$res = [];
if ( $all = self::scan($dir, $type, $hidden) ){
foreach ($all as $a ){
$t = filemtime($a);
$res[] = ['name' => $a, 'mtime' => $t, 'date' => date('Y-m-d H:i:s', $t)];
}
}
return $res;
} | [
"public",
"static",
"function",
"mscan",
"(",
"string",
"$",
"dir",
",",
"string",
"$",
"type",
"=",
"null",
",",
"$",
"hidden",
"=",
"false",
")",
":",
"array",
"{",
"$",
"res",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"all",
"=",
"self",
"::",
"scan",
"(",
"$",
"dir",
",",
"$",
"type",
",",
"$",
"hidden",
")",
")",
"{",
"foreach",
"(",
"$",
"all",
"as",
"$",
"a",
")",
"{",
"$",
"t",
"=",
"filemtime",
"(",
"$",
"a",
")",
";",
"$",
"res",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"a",
",",
"'mtime'",
"=>",
"$",
"t",
",",
"'date'",
"=>",
"date",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"t",
")",
"]",
";",
"}",
"}",
"return",
"$",
"res",
";",
"}"
] | Returns an array of indexed arrays with the 'name' of the file/folder contained in the given directory, the 'mtime', and the 'date' of creation the file/folder.
```php
\bbn\x::dump(\bbn\file\dir::mscan("/home/data/test"));
/* (array)
[
[
"name" => "/home/data/test/Folder",
"mtime" => 1480422173,
"date" => "2016-11-29 13:22:53",
],
[
"name" => "/home/data/test/Folder_test",
"mtime" => 1480422173,
"date" => "2016-11-29 13:22:53",
],
[
"name" => "/home/data/test/Folder_test/image.png",
"mtime" => 1480418947,
"date" => "2016-11-29 12:29:07",
]
]
\bbn\x::dump(\bbn\file\dir::mscan("/home/data/test", "dir"));
/* (array)
[
[
"name" => "/home/data/test/Folder",
"mtime" => 1480422173,
"date" => "2016-11-29 13:22:53",
],
[
"name" => "/home/data/test/Folder_test",
"mtime" => 1480422173,
"date" => "2016-11-29 13:22:53",
]
]
\bbn\x::dump(\bbn\file\dir::mscan("/home/data/test", "file"));
/* (array)
[
[
"name" => "/home/data/test/Folder_test/image.png",
"mtime" => 1480418947,
"date" => "2016-11-29 12:29:07",
]
]
\bbn\x::dump(\bbn\file\dir::mscan("/home/data/test", "file",1));
/* (array)
[
[
"name" => "/home/data/test/Folder_test/image.png",
"mtime" => 1480418947,
"date" => "2016-11-29 12:29:07",
],
[
"name" => "/home/data/test/Folder/.doc.pdf",
"mtime" => 1480418947,
"date" => "2016-11-29 12:29:07",
]
]
```
@param string $dir The directory's path
@param string $type The type or the extension of item to return ('file', 'dir', 'php', default is both)
@param bool $hidden If set to true will also return the hidden files/folders contained in the given directory. Default=false
@return array | [
"Returns",
"an",
"array",
"of",
"indexed",
"arrays",
"with",
"the",
"name",
"of",
"the",
"file",
"/",
"folder",
"contained",
"in",
"the",
"given",
"directory",
"the",
"mtime",
"and",
"the",
"date",
"of",
"creation",
"the",
"file",
"/",
"folder",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/dir.php#L336-L346 |
nabab/bbn | src/bbn/file/dir.php | dir.get_tree | public static function get_tree(string $dir, bool $only_dir = false, callable $filter = null, bool $hidden = false): array
{
$r = [];
$dir = self::clean($dir);
$dirs = self::get_dirs($dir, $hidden);
if ( \is_array($dirs) ){
foreach ( $dirs as $d ){
$x = [
'name' => $d,
'type' => 'dir',
'num_children' => 0,
'items' => self::get_tree($d, $only_dir, $filter, $hidden)
];
$x['num_children'] = \count($x['items']);
if ( $filter ){
if ( $filter($x) ){
$r[] = $x;
}
}
else{
$r[] = $x;
}
}
if ( !$only_dir ){
$files = self::get_files($dir, false, $hidden);
foreach ( $files as $f ){
$x = [
'name' => $f,
'type' => 'file',
'ext' => bbn\str::file_ext($f)
];
if ( $filter ){
if ( $filter($x) ){
$r[] = $x;
}
}
else{
$r[] = $x;
}
}
}
}
return $r;
} | php | public static function get_tree(string $dir, bool $only_dir = false, callable $filter = null, bool $hidden = false): array
{
$r = [];
$dir = self::clean($dir);
$dirs = self::get_dirs($dir, $hidden);
if ( \is_array($dirs) ){
foreach ( $dirs as $d ){
$x = [
'name' => $d,
'type' => 'dir',
'num_children' => 0,
'items' => self::get_tree($d, $only_dir, $filter, $hidden)
];
$x['num_children'] = \count($x['items']);
if ( $filter ){
if ( $filter($x) ){
$r[] = $x;
}
}
else{
$r[] = $x;
}
}
if ( !$only_dir ){
$files = self::get_files($dir, false, $hidden);
foreach ( $files as $f ){
$x = [
'name' => $f,
'type' => 'file',
'ext' => bbn\str::file_ext($f)
];
if ( $filter ){
if ( $filter($x) ){
$r[] = $x;
}
}
else{
$r[] = $x;
}
}
}
}
return $r;
} | [
"public",
"static",
"function",
"get_tree",
"(",
"string",
"$",
"dir",
",",
"bool",
"$",
"only_dir",
"=",
"false",
",",
"callable",
"$",
"filter",
"=",
"null",
",",
"bool",
"$",
"hidden",
"=",
"false",
")",
":",
"array",
"{",
"$",
"r",
"=",
"[",
"]",
";",
"$",
"dir",
"=",
"self",
"::",
"clean",
"(",
"$",
"dir",
")",
";",
"$",
"dirs",
"=",
"self",
"::",
"get_dirs",
"(",
"$",
"dir",
",",
"$",
"hidden",
")",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"dirs",
")",
")",
"{",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"d",
")",
"{",
"$",
"x",
"=",
"[",
"'name'",
"=>",
"$",
"d",
",",
"'type'",
"=>",
"'dir'",
",",
"'num_children'",
"=>",
"0",
",",
"'items'",
"=>",
"self",
"::",
"get_tree",
"(",
"$",
"d",
",",
"$",
"only_dir",
",",
"$",
"filter",
",",
"$",
"hidden",
")",
"]",
";",
"$",
"x",
"[",
"'num_children'",
"]",
"=",
"\\",
"count",
"(",
"$",
"x",
"[",
"'items'",
"]",
")",
";",
"if",
"(",
"$",
"filter",
")",
"{",
"if",
"(",
"$",
"filter",
"(",
"$",
"x",
")",
")",
"{",
"$",
"r",
"[",
"]",
"=",
"$",
"x",
";",
"}",
"}",
"else",
"{",
"$",
"r",
"[",
"]",
"=",
"$",
"x",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"only_dir",
")",
"{",
"$",
"files",
"=",
"self",
"::",
"get_files",
"(",
"$",
"dir",
",",
"false",
",",
"$",
"hidden",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"f",
")",
"{",
"$",
"x",
"=",
"[",
"'name'",
"=>",
"$",
"f",
",",
"'type'",
"=>",
"'file'",
",",
"'ext'",
"=>",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"$",
"f",
")",
"]",
";",
"if",
"(",
"$",
"filter",
")",
"{",
"if",
"(",
"$",
"filter",
"(",
"$",
"x",
")",
")",
"{",
"$",
"r",
"[",
"]",
"=",
"$",
"x",
";",
"}",
"}",
"else",
"{",
"$",
"r",
"[",
"]",
"=",
"$",
"x",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"r",
";",
"}"
] | Return an array with the tree of the folder's content.
```php
\bbn\x::dump(\bbn\file\dir::get_tree("/home/data/test"));
/* (array)
[
[
"name" => "/home/data/test/Folder",
"type" => "dir",
"num_children" => 0,
"items" => [],
],
[
"name" => "/home/data/test/Folder_test",
"type" => "dir",
"num_children" => 1,
"items" => [
[
"name" => "/home/data/test/Folder_test/image.png",
"type" => "file",
"ext" => "png",
],
],
],
]
\bbn\x::dump(\bbn\file\dir::get_tree("/home/data/test", true) );
/* (array)
[
[
"name" => "/home/data/test/Folder",
"type" => "dir",
"num_children" => 0,
"items" => [],
],
[
"name" => "/home/data/test/Folder_test",
"type" => "dir",
"num_children" => 0,
"items" => [],
],
]
\bbn\x::dump(\bbn\file\dir::get_tree("/home/data/test", false, false, true) );
/* (array)
[
[
"name" => "/home/data/test/Folder",
"type" => "dir",
"num_children" => 1,
"items" => [
[
"name" => "/home/data/test/Folder/.doc.pdf",
"type" => "file",
"ext" => "pdf",
],
],
],
[
"name" => "/home/data/test/Folder_test",
"type" => "dir",
"num_children" => 1,
"items" => [
[
"name" => "/home/data/test/Folder_test/image.png",
"type" => "file",
"ext" => "png",
],
],
],
]
```
@param string $dir The directory's path.
@param bool $only_dir If set to true will just return the folder(s), if false will include in the resulr also the file(s). Default = false.
@param callable $filter Filter function
@param bool $hidden If set to true will also return the hidden file(s)/folder(s)
@return array | [
"Return",
"an",
"array",
"with",
"the",
"tree",
"of",
"the",
"folder",
"s",
"content",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/dir.php#L425-L468 |
nabab/bbn | src/bbn/file/dir.php | dir.create_path | public static function create_path(string $dir, $chmod=false){
if ( !$dir || !\is_string($dir) ){
return false;
}
clearstatcache();
if ( !is_dir($dir) ){
$bits = explode('/', $dir);
$path = empty($bits[0]) ? '/' : '';
foreach ( $bits as $i => $b ){
if ( !empty($b) ){
$path .= $b;
if ( !is_dir($path) ){
if ( !mkdir($path) || !is_dir($path) ){
return false;
}
if ( $chmod ){
@chmod($path, $chmod);
}
}
$path .= '/';
}
}
}
return $dir;
} | php | public static function create_path(string $dir, $chmod=false){
if ( !$dir || !\is_string($dir) ){
return false;
}
clearstatcache();
if ( !is_dir($dir) ){
$bits = explode('/', $dir);
$path = empty($bits[0]) ? '/' : '';
foreach ( $bits as $i => $b ){
if ( !empty($b) ){
$path .= $b;
if ( !is_dir($path) ){
if ( !mkdir($path) || !is_dir($path) ){
return false;
}
if ( $chmod ){
@chmod($path, $chmod);
}
}
$path .= '/';
}
}
}
return $dir;
} | [
"public",
"static",
"function",
"create_path",
"(",
"string",
"$",
"dir",
",",
"$",
"chmod",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"dir",
"||",
"!",
"\\",
"is_string",
"(",
"$",
"dir",
")",
")",
"{",
"return",
"false",
";",
"}",
"clearstatcache",
"(",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"bits",
"=",
"explode",
"(",
"'/'",
",",
"$",
"dir",
")",
";",
"$",
"path",
"=",
"empty",
"(",
"$",
"bits",
"[",
"0",
"]",
")",
"?",
"'/'",
":",
"''",
";",
"foreach",
"(",
"$",
"bits",
"as",
"$",
"i",
"=>",
"$",
"b",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"b",
")",
")",
"{",
"$",
"path",
".=",
"$",
"b",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"!",
"mkdir",
"(",
"$",
"path",
")",
"||",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"chmod",
")",
"{",
"@",
"chmod",
"(",
"$",
"path",
",",
"$",
"chmod",
")",
";",
"}",
"}",
"$",
"path",
".=",
"'/'",
";",
"}",
"}",
"}",
"return",
"$",
"dir",
";",
"}"
] | Creates a folder with the given path.
```php
\bbn\x::dump(\bbn\file\dir::create_path("/home/data/test/New"));
\\ (string) "/home/data/test/New"
```
@param string $dir The new directory's path.
@param bool $chmod If set to true the user won't have the permissions to view the content of the folder created
@return string|false | [
"Creates",
"a",
"folder",
"with",
"the",
"given",
"path",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/dir.php#L482-L506 |
nabab/bbn | src/bbn/file/dir.php | dir.move | public static function move($orig, $dest, $st = '_v', $length = 0): bool
{
if ( file_exists($orig) && self::create_path(\dirname($dest)) ){
if ( file_exists($dest) ){
if ( $st === true ){
self::delete($dest);
}
else{
$i = 1;
while ( $i ){
$dir = \dirname($dest).'/';
$file_name = bbn\str::file_ext($dest, 1);
$file = $file_name[0].$st;
if ( $length > 0 ){
$len = \strlen(bbn\str::cast($i));
if ( $len > $length ){
return false;
}
$file .= str_repeat('0', $length - $len);
}
$file .= bbn\str::cast($i);
if ( !empty($file_name[1]) ){
$file .= '.'.$file_name[1];
}
$i++;
if ( !file_exists($dir.$file) ){
$dest = $dir.$file;
$i = false;
}
}
}
}
if ( rename($orig, $dest) ){
return true;
}
}
return false;
} | php | public static function move($orig, $dest, $st = '_v', $length = 0): bool
{
if ( file_exists($orig) && self::create_path(\dirname($dest)) ){
if ( file_exists($dest) ){
if ( $st === true ){
self::delete($dest);
}
else{
$i = 1;
while ( $i ){
$dir = \dirname($dest).'/';
$file_name = bbn\str::file_ext($dest, 1);
$file = $file_name[0].$st;
if ( $length > 0 ){
$len = \strlen(bbn\str::cast($i));
if ( $len > $length ){
return false;
}
$file .= str_repeat('0', $length - $len);
}
$file .= bbn\str::cast($i);
if ( !empty($file_name[1]) ){
$file .= '.'.$file_name[1];
}
$i++;
if ( !file_exists($dir.$file) ){
$dest = $dir.$file;
$i = false;
}
}
}
}
if ( rename($orig, $dest) ){
return true;
}
}
return false;
} | [
"public",
"static",
"function",
"move",
"(",
"$",
"orig",
",",
"$",
"dest",
",",
"$",
"st",
"=",
"'_v'",
",",
"$",
"length",
"=",
"0",
")",
":",
"bool",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"orig",
")",
"&&",
"self",
"::",
"create_path",
"(",
"\\",
"dirname",
"(",
"$",
"dest",
")",
")",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"dest",
")",
")",
"{",
"if",
"(",
"$",
"st",
"===",
"true",
")",
"{",
"self",
"::",
"delete",
"(",
"$",
"dest",
")",
";",
"}",
"else",
"{",
"$",
"i",
"=",
"1",
";",
"while",
"(",
"$",
"i",
")",
"{",
"$",
"dir",
"=",
"\\",
"dirname",
"(",
"$",
"dest",
")",
".",
"'/'",
";",
"$",
"file_name",
"=",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"$",
"dest",
",",
"1",
")",
";",
"$",
"file",
"=",
"$",
"file_name",
"[",
"0",
"]",
".",
"$",
"st",
";",
"if",
"(",
"$",
"length",
">",
"0",
")",
"{",
"$",
"len",
"=",
"\\",
"strlen",
"(",
"bbn",
"\\",
"str",
"::",
"cast",
"(",
"$",
"i",
")",
")",
";",
"if",
"(",
"$",
"len",
">",
"$",
"length",
")",
"{",
"return",
"false",
";",
"}",
"$",
"file",
".=",
"str_repeat",
"(",
"'0'",
",",
"$",
"length",
"-",
"$",
"len",
")",
";",
"}",
"$",
"file",
".=",
"bbn",
"\\",
"str",
"::",
"cast",
"(",
"$",
"i",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"file_name",
"[",
"1",
"]",
")",
")",
"{",
"$",
"file",
".=",
"'.'",
".",
"$",
"file_name",
"[",
"1",
"]",
";",
"}",
"$",
"i",
"++",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dir",
".",
"$",
"file",
")",
")",
"{",
"$",
"dest",
"=",
"$",
"dir",
".",
"$",
"file",
";",
"$",
"i",
"=",
"false",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"rename",
"(",
"$",
"orig",
",",
"$",
"dest",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Moves a file or directory to a new location
```php
\bbn\x::dump(\bbn\file\dir::move("/home/data/test/Folder/image.png","/home/data/test/Folder_test/image.png"));
\\ (string) "image.png"
\bbn\x::dump(\bbn\file\dir::move("/home/data/test/Folder/image.png","/home/data/test/Folder_test/Intro/image.png"));
\\ (string) "image.png"
\bbn\x::dump(\bbn\file\dir::move("/home/data/test/Folder","/home/data/test/Folder_test", true));
\\ (string) "Folder_test"
\bbn\x::dump(\bbn\file\dir::move("/home/data/test/Folder","/home/data/test/Folder_test", "_n", 3));
\\ (string) "Folder_test_n001"
```
@param string $orig The path of the file to move
@param string $dest The full name of the destination (including basename)
@param string | true $st If in the destination folder alredy exists a file with the same name of the file to move it will rename the file adding '_v' (default). If 'string' will change the file name with the given string. If $st=true it will overwrite the file/folder.
@param int $length The number of characters to use for the revision number; will be zerofilled
@return bool Success | [
"Moves",
"a",
"file",
"or",
"directory",
"to",
"a",
"new",
"location"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/dir.php#L528-L565 |
nabab/bbn | src/bbn/file/dir.php | dir.copy | public static function copy($src, $dst): bool
{
if ( is_file($src) ){
return copy($src, $dst);
}
if ( is_dir($src) && self::create_path($dst) ){
$files = self::get_files($src);
$dirs = self::get_dirs($src);
foreach ( $files as $f ){
copy($f, $dst.'/'.basename($f));
}
foreach ( $dirs as $f ){
self::copy($f, $dst.'/'.basename($f));
}
return true;
}
else{
return false;
}
} | php | public static function copy($src, $dst): bool
{
if ( is_file($src) ){
return copy($src, $dst);
}
if ( is_dir($src) && self::create_path($dst) ){
$files = self::get_files($src);
$dirs = self::get_dirs($src);
foreach ( $files as $f ){
copy($f, $dst.'/'.basename($f));
}
foreach ( $dirs as $f ){
self::copy($f, $dst.'/'.basename($f));
}
return true;
}
else{
return false;
}
} | [
"public",
"static",
"function",
"copy",
"(",
"$",
"src",
",",
"$",
"dst",
")",
":",
"bool",
"{",
"if",
"(",
"is_file",
"(",
"$",
"src",
")",
")",
"{",
"return",
"copy",
"(",
"$",
"src",
",",
"$",
"dst",
")",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"src",
")",
"&&",
"self",
"::",
"create_path",
"(",
"$",
"dst",
")",
")",
"{",
"$",
"files",
"=",
"self",
"::",
"get_files",
"(",
"$",
"src",
")",
";",
"$",
"dirs",
"=",
"self",
"::",
"get_dirs",
"(",
"$",
"src",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"f",
")",
"{",
"copy",
"(",
"$",
"f",
",",
"$",
"dst",
".",
"'/'",
".",
"basename",
"(",
"$",
"f",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"f",
")",
"{",
"self",
"::",
"copy",
"(",
"$",
"f",
",",
"$",
"dst",
".",
"'/'",
".",
"basename",
"(",
"$",
"f",
")",
")",
";",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Will move the content of the given folder to a new destination. Doesn't move the hidden files.
```php
\bbn\x::dump(\bbn\file\dir::copy("/home/data/test/Folder","/home/data/test/Folder_test"));
\\ (bool) 1
```
@param string $src The path of the files to move
@param string $dst The new destination of files
@return bool | [
"Will",
"move",
"the",
"content",
"of",
"the",
"given",
"folder",
"to",
"a",
"new",
"destination",
".",
"Doesn",
"t",
"move",
"the",
"hidden",
"files",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/dir.php#L578-L597 |
expectation-php/expect | src/FailedMessage.php | FailedMessage.appendText | public function appendText($value)
{
$text = $this->stringify($value);
$this->message = $this->message . $text;
return $this;
} | php | public function appendText($value)
{
$text = $this->stringify($value);
$this->message = $this->message . $text;
return $this;
} | [
"public",
"function",
"appendText",
"(",
"$",
"value",
")",
"{",
"$",
"text",
"=",
"$",
"this",
"->",
"stringify",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"message",
"=",
"$",
"this",
"->",
"message",
".",
"$",
"text",
";",
"return",
"$",
"this",
";",
"}"
] | Append the text to the last.
@param mixed $value
@return $this | [
"Append",
"the",
"text",
"to",
"the",
"last",
"."
] | train | https://github.com/expectation-php/expect/blob/1a32c5af37f3dc8dabe4e8eedeeb21aea16ce139/src/FailedMessage.php#L41-L47 |
expectation-php/expect | src/FailedMessage.php | FailedMessage.appendSpace | public function appendSpace($length)
{
$paddingLength = (int) $length;
$this->message = $this->message . str_pad('', $paddingLength, ' ');
return $this;
} | php | public function appendSpace($length)
{
$paddingLength = (int) $length;
$this->message = $this->message . str_pad('', $paddingLength, ' ');
return $this;
} | [
"public",
"function",
"appendSpace",
"(",
"$",
"length",
")",
"{",
"$",
"paddingLength",
"=",
"(",
"int",
")",
"$",
"length",
";",
"$",
"this",
"->",
"message",
"=",
"$",
"this",
"->",
"message",
".",
"str_pad",
"(",
"''",
",",
"$",
"paddingLength",
",",
"' '",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Append the length space.
@param int $length
@return $this | [
"Append",
"the",
"length",
"space",
"."
] | train | https://github.com/expectation-php/expect/blob/1a32c5af37f3dc8dabe4e8eedeeb21aea16ce139/src/FailedMessage.php#L56-L62 |
expectation-php/expect | src/FailedMessage.php | FailedMessage.appendValue | public function appendValue($value)
{
$appendValue = $this->formatValue($value);
$this->message = $this->message . $appendValue;
return $this;
} | php | public function appendValue($value)
{
$appendValue = $this->formatValue($value);
$this->message = $this->message . $appendValue;
return $this;
} | [
"public",
"function",
"appendValue",
"(",
"$",
"value",
")",
"{",
"$",
"appendValue",
"=",
"$",
"this",
"->",
"formatValue",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"message",
"=",
"$",
"this",
"->",
"message",
".",
"$",
"appendValue",
";",
"return",
"$",
"this",
";",
"}"
] | Append the value to the last.
@param mixed $value
@return $this | [
"Append",
"the",
"value",
"to",
"the",
"last",
"."
] | train | https://github.com/expectation-php/expect/blob/1a32c5af37f3dc8dabe4e8eedeeb21aea16ce139/src/FailedMessage.php#L71-L77 |
expectation-php/expect | src/FailedMessage.php | FailedMessage.appendValues | public function appendValues(array $values)
{
$appendValues = [];
foreach ($values as $value) {
$appendValues[] = $this->formatValue($value);
}
$this->message = $this->message . implode(', ', $appendValues);
return $this;
} | php | public function appendValues(array $values)
{
$appendValues = [];
foreach ($values as $value) {
$appendValues[] = $this->formatValue($value);
}
$this->message = $this->message . implode(', ', $appendValues);
return $this;
} | [
"public",
"function",
"appendValues",
"(",
"array",
"$",
"values",
")",
"{",
"$",
"appendValues",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"appendValues",
"[",
"]",
"=",
"$",
"this",
"->",
"formatValue",
"(",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"message",
"=",
"$",
"this",
"->",
"message",
".",
"implode",
"(",
"', '",
",",
"$",
"appendValues",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Append the values to the last.
@param array $values
@return $this | [
"Append",
"the",
"values",
"to",
"the",
"last",
"."
] | train | https://github.com/expectation-php/expect/blob/1a32c5af37f3dc8dabe4e8eedeeb21aea16ce139/src/FailedMessage.php#L86-L97 |
zhouyl/mellivora | Mellivora/Validation/Valid.php | Valid.length | public static function length($value, $min = null, $max = null)
{
$length = mb_strlen($value);
if (is_numeric($min) && $min > 0 && $length < $min) {
return false;
}
if (is_numeric($max) && $max > 0 && $length > $max) {
return false;
}
return true;
} | php | public static function length($value, $min = null, $max = null)
{
$length = mb_strlen($value);
if (is_numeric($min) && $min > 0 && $length < $min) {
return false;
}
if (is_numeric($max) && $max > 0 && $length > $max) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"length",
"(",
"$",
"value",
",",
"$",
"min",
"=",
"null",
",",
"$",
"max",
"=",
"null",
")",
"{",
"$",
"length",
"=",
"mb_strlen",
"(",
"$",
"value",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"min",
")",
"&&",
"$",
"min",
">",
"0",
"&&",
"$",
"length",
"<",
"$",
"min",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"max",
")",
"&&",
"$",
"max",
">",
"0",
"&&",
"$",
"length",
">",
"$",
"max",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | 检测字符串是否符合长度范围
@param string $value
@param int $min
@param int $max
@return bool | [
"检测字符串是否符合长度范围"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Validation/Valid.php#L71-L84 |
zhouyl/mellivora | Mellivora/Validation/Valid.php | Valid.lengths | public static function lengths($value, $length)
{
if (is_array($length)) {
foreach ($length as $strlen) {
if (mb_strlen($value) === $strlen) {
return true;
}
}
return false;
}
return mb_strlen($value) === $length;
} | php | public static function lengths($value, $length)
{
if (is_array($length)) {
foreach ($length as $strlen) {
if (mb_strlen($value) === $strlen) {
return true;
}
}
return false;
}
return mb_strlen($value) === $length;
} | [
"public",
"static",
"function",
"lengths",
"(",
"$",
"value",
",",
"$",
"length",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"length",
")",
")",
"{",
"foreach",
"(",
"$",
"length",
"as",
"$",
"strlen",
")",
"{",
"if",
"(",
"mb_strlen",
"(",
"$",
"value",
")",
"===",
"$",
"strlen",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
"return",
"mb_strlen",
"(",
"$",
"value",
")",
"===",
"$",
"length",
";",
"}"
] | 检测字符串是否符合指定的长度
Valid::lengths($value, [10, 20]);
Valid::lengths($value, 10);
@param string $value
@param array|int $length
@return bool | [
"检测字符串是否符合指定的长度"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Validation/Valid.php#L97-L110 |
zhouyl/mellivora | Mellivora/Validation/Valid.php | Valid.equal | public static function equal($value, $target, $ignoreCase = false)
{
if ($ignoreCase) {
if (is_string($value)) {
$value = strtolower($value);
}
if (is_string($target)) {
$target = strtolower($target);
}
}
return $value === $target;
} | php | public static function equal($value, $target, $ignoreCase = false)
{
if ($ignoreCase) {
if (is_string($value)) {
$value = strtolower($value);
}
if (is_string($target)) {
$target = strtolower($target);
}
}
return $value === $target;
} | [
"public",
"static",
"function",
"equal",
"(",
"$",
"value",
",",
"$",
"target",
",",
"$",
"ignoreCase",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"ignoreCase",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"strtolower",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"target",
")",
")",
"{",
"$",
"target",
"=",
"strtolower",
"(",
"$",
"target",
")",
";",
"}",
"}",
"return",
"$",
"value",
"===",
"$",
"target",
";",
"}"
] | 检测两个值是否完全相等
@param string $value
@param string $target
@param bool $ignoreCase
@return bool | [
"检测两个值是否完全相等"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Validation/Valid.php#L121-L134 |
zhouyl/mellivora | Mellivora/Validation/Valid.php | Valid.email | public static function email($value, $strict = false)
{
if (mb_strlen($value) > 254) {
return false;
}
if ($strict === true) {
$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
$atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
$pair = '\\x5c[\\x00-\\x7f]';
$domain_literal = "\\x5b($dtext|$pair)*\\x5d";
$quoted_string = "\\x22($qtext|$pair)*\\x22";
$sub_domain = "($atom|$domain_literal)";
$word = "($atom|$quoted_string)";
$domain = "$sub_domain(\\x2e$sub_domain)*";
$local_part = "$word(\\x2e$word)*";
$expression = "/^$local_part\\x40$domain$/D";
} else {
$expression = '/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})$/iD';
}
return (bool) preg_match($expression, (string) $value);
} | php | public static function email($value, $strict = false)
{
if (mb_strlen($value) > 254) {
return false;
}
if ($strict === true) {
$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
$atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
$pair = '\\x5c[\\x00-\\x7f]';
$domain_literal = "\\x5b($dtext|$pair)*\\x5d";
$quoted_string = "\\x22($qtext|$pair)*\\x22";
$sub_domain = "($atom|$domain_literal)";
$word = "($atom|$quoted_string)";
$domain = "$sub_domain(\\x2e$sub_domain)*";
$local_part = "$word(\\x2e$word)*";
$expression = "/^$local_part\\x40$domain$/D";
} else {
$expression = '/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})$/iD';
}
return (bool) preg_match($expression, (string) $value);
} | [
"public",
"static",
"function",
"email",
"(",
"$",
"value",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"if",
"(",
"mb_strlen",
"(",
"$",
"value",
")",
">",
"254",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"strict",
"===",
"true",
")",
"{",
"$",
"qtext",
"=",
"'[^\\\\x0d\\\\x22\\\\x5c\\\\x80-\\\\xff]'",
";",
"$",
"dtext",
"=",
"'[^\\\\x0d\\\\x5b-\\\\x5d\\\\x80-\\\\xff]'",
";",
"$",
"atom",
"=",
"'[^\\\\x00-\\\\x20\\\\x22\\\\x28\\\\x29\\\\x2c\\\\x2e\\\\x3a-\\\\x3c\\\\x3e\\\\x40\\\\x5b-\\\\x5d\\\\x7f-\\\\xff]+'",
";",
"$",
"pair",
"=",
"'\\\\x5c[\\\\x00-\\\\x7f]'",
";",
"$",
"domain_literal",
"=",
"\"\\\\x5b($dtext|$pair)*\\\\x5d\"",
";",
"$",
"quoted_string",
"=",
"\"\\\\x22($qtext|$pair)*\\\\x22\"",
";",
"$",
"sub_domain",
"=",
"\"($atom|$domain_literal)\"",
";",
"$",
"word",
"=",
"\"($atom|$quoted_string)\"",
";",
"$",
"domain",
"=",
"\"$sub_domain(\\\\x2e$sub_domain)*\"",
";",
"$",
"local_part",
"=",
"\"$word(\\\\x2e$word)*\"",
";",
"$",
"expression",
"=",
"\"/^$local_part\\\\x40$domain$/D\"",
";",
"}",
"else",
"{",
"$",
"expression",
"=",
"'/^[-_a-z0-9\\'+*$^&%=~!?{}]++(?:\\.[-_a-z0-9\\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\\.[a-z]{2,6}|\\d{1,3}(?:\\.\\d{1,3}){3})$/iD'",
";",
"}",
"return",
"(",
"bool",
")",
"preg_match",
"(",
"$",
"expression",
",",
"(",
"string",
")",
"$",
"value",
")",
";",
"}"
] | 检测是否有效的 email 地址
@see http://www.iamcal.com/publish/articles/php/parsing_email/
@see http://www.w3.org/Protocols/rfc822/
@param string $value
@param bool $strict
@return bool | [
"检测是否有效的",
"email",
"地址"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Validation/Valid.php#L161-L186 |
zhouyl/mellivora | Mellivora/Validation/Valid.php | Valid.url | public static function url($value, $onlyHttp = false)
{
if (!is_string($value)) {
return false;
}
// 限制仅允许 http url
if ($onlyHttp && !preg_match('~^https?://.*~i', $value)) {
return false;
}
/*
* This pattern is derived from Symfony\Component\Validator\Constraints\UrlValidator (2.7.4).
*
* (c) Fabien Potencier <[email protected]> http://symfony.com
*/
$pattern = '~^
((aaa|aaas|about|acap|acct|acr|adiumxtra|afp|afs|aim|apt|attachment|aw|barion|beshare|bitcoin|blob|bolo|callto|cap|chrome|chrome-extension|cid|coap|coaps|com-eventbrite-attendee|content|crid|cvs|data|dav|dict|dlna-playcontainer|dlna-playsingle|dns|dntp|dtn|dvb|ed2k|example|facetime|fax|feed|feedready|file|filesystem|finger|fish|ftp|geo|gg|git|gizmoproject|go|gopher|gtalk|h323|ham|hcp|http|https|iax|icap|icon|im|imap|info|iotdisco|ipn|ipp|ipps|irc|irc6|ircs|iris|iris.beep|iris.lwz|iris.xpc|iris.xpcs|itms|jabber|jar|jms|keyparc|lastfm|ldap|ldaps|magnet|mailserver|mailto|maps|market|message|mid|mms|modem|ms-help|ms-settings|ms-settings-airplanemode|ms-settings-bluetooth|ms-settings-camera|ms-settings-cellular|ms-settings-cloudstorage|ms-settings-emailandaccounts|ms-settings-language|ms-settings-location|ms-settings-lock|ms-settings-nfctransactions|ms-settings-notifications|ms-settings-power|ms-settings-privacy|ms-settings-proximity|ms-settings-screenrotation|ms-settings-wifi|ms-settings-workplace|msnim|msrp|msrps|mtqp|mumble|mupdate|mvn|news|nfs|ni|nih|nntp|notes|oid|opaquelocktoken|pack|palm|paparazzi|pkcs11|platform|pop|pres|prospero|proxy|psyc|query|redis|rediss|reload|res|resource|rmi|rsync|rtmfp|rtmp|rtsp|rtsps|rtspu|secondlife|service|session|sftp|sgn|shttp|sieve|sip|sips|skype|smb|sms|smtp|snews|snmp|soap.beep|soap.beeps|soldat|spotify|ssh|steam|stun|stuns|submit|svn|tag|teamspeak|tel|teliaeid|telnet|tftp|things|thismessage|tip|tn3270|turn|turns|tv|udp|unreal|urn|ut2004|vemmi|ventrilo|videotex|view-source|wais|webcal|ws|wss|wtai|wyciwyg|xcon|xcon-userid|xfire|xmlrpc\.beep|xmlrpc.beeps|xmpp|xri|ymsgr|z39\.50|z39\.50r|z39\.50s)):// # protocol
(([\pL\pN-]+:)?([\pL\pN-]+)@)? # basic auth
(
([\pL\pN\pS-\.])+(\.?([\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
| # or
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address
| # or
\[
(?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-f]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,1}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,2}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,3}(?:(?:[0-9a-f]{1,4})))?::(?:(?:[0-9a-f]{1,4})):)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,4}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::))))
\] # an IPv6 address
)
(:[0-9]+)? # a port (optional)
(/?|/\S+|\?\S*|\#\S*) # a /, nothing, a / with something, a query or a fragment
$~ixu';
return preg_match($pattern, $value) > 0;
} | php | public static function url($value, $onlyHttp = false)
{
if (!is_string($value)) {
return false;
}
// 限制仅允许 http url
if ($onlyHttp && !preg_match('~^https?://.*~i', $value)) {
return false;
}
/*
* This pattern is derived from Symfony\Component\Validator\Constraints\UrlValidator (2.7.4).
*
* (c) Fabien Potencier <[email protected]> http://symfony.com
*/
$pattern = '~^
((aaa|aaas|about|acap|acct|acr|adiumxtra|afp|afs|aim|apt|attachment|aw|barion|beshare|bitcoin|blob|bolo|callto|cap|chrome|chrome-extension|cid|coap|coaps|com-eventbrite-attendee|content|crid|cvs|data|dav|dict|dlna-playcontainer|dlna-playsingle|dns|dntp|dtn|dvb|ed2k|example|facetime|fax|feed|feedready|file|filesystem|finger|fish|ftp|geo|gg|git|gizmoproject|go|gopher|gtalk|h323|ham|hcp|http|https|iax|icap|icon|im|imap|info|iotdisco|ipn|ipp|ipps|irc|irc6|ircs|iris|iris.beep|iris.lwz|iris.xpc|iris.xpcs|itms|jabber|jar|jms|keyparc|lastfm|ldap|ldaps|magnet|mailserver|mailto|maps|market|message|mid|mms|modem|ms-help|ms-settings|ms-settings-airplanemode|ms-settings-bluetooth|ms-settings-camera|ms-settings-cellular|ms-settings-cloudstorage|ms-settings-emailandaccounts|ms-settings-language|ms-settings-location|ms-settings-lock|ms-settings-nfctransactions|ms-settings-notifications|ms-settings-power|ms-settings-privacy|ms-settings-proximity|ms-settings-screenrotation|ms-settings-wifi|ms-settings-workplace|msnim|msrp|msrps|mtqp|mumble|mupdate|mvn|news|nfs|ni|nih|nntp|notes|oid|opaquelocktoken|pack|palm|paparazzi|pkcs11|platform|pop|pres|prospero|proxy|psyc|query|redis|rediss|reload|res|resource|rmi|rsync|rtmfp|rtmp|rtsp|rtsps|rtspu|secondlife|service|session|sftp|sgn|shttp|sieve|sip|sips|skype|smb|sms|smtp|snews|snmp|soap.beep|soap.beeps|soldat|spotify|ssh|steam|stun|stuns|submit|svn|tag|teamspeak|tel|teliaeid|telnet|tftp|things|thismessage|tip|tn3270|turn|turns|tv|udp|unreal|urn|ut2004|vemmi|ventrilo|videotex|view-source|wais|webcal|ws|wss|wtai|wyciwyg|xcon|xcon-userid|xfire|xmlrpc\.beep|xmlrpc.beeps|xmpp|xri|ymsgr|z39\.50|z39\.50r|z39\.50s)):// # protocol
(([\pL\pN-]+:)?([\pL\pN-]+)@)? # basic auth
(
([\pL\pN\pS-\.])+(\.?([\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
| # or
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address
| # or
\[
(?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-f]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,1}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,2}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,3}(?:(?:[0-9a-f]{1,4})))?::(?:(?:[0-9a-f]{1,4})):)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,4}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::))))
\] # an IPv6 address
)
(:[0-9]+)? # a port (optional)
(/?|/\S+|\?\S*|\#\S*) # a /, nothing, a / with something, a query or a fragment
$~ixu';
return preg_match($pattern, $value) > 0;
} | [
"public",
"static",
"function",
"url",
"(",
"$",
"value",
",",
"$",
"onlyHttp",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"// 限制仅允许 http url",
"if",
"(",
"$",
"onlyHttp",
"&&",
"!",
"preg_match",
"(",
"'~^https?://.*~i'",
",",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"/*\n * This pattern is derived from Symfony\\Component\\Validator\\Constraints\\UrlValidator (2.7.4).\n *\n * (c) Fabien Potencier <[email protected]> http://symfony.com\n */",
"$",
"pattern",
"=",
"'~^\n ((aaa|aaas|about|acap|acct|acr|adiumxtra|afp|afs|aim|apt|attachment|aw|barion|beshare|bitcoin|blob|bolo|callto|cap|chrome|chrome-extension|cid|coap|coaps|com-eventbrite-attendee|content|crid|cvs|data|dav|dict|dlna-playcontainer|dlna-playsingle|dns|dntp|dtn|dvb|ed2k|example|facetime|fax|feed|feedready|file|filesystem|finger|fish|ftp|geo|gg|git|gizmoproject|go|gopher|gtalk|h323|ham|hcp|http|https|iax|icap|icon|im|imap|info|iotdisco|ipn|ipp|ipps|irc|irc6|ircs|iris|iris.beep|iris.lwz|iris.xpc|iris.xpcs|itms|jabber|jar|jms|keyparc|lastfm|ldap|ldaps|magnet|mailserver|mailto|maps|market|message|mid|mms|modem|ms-help|ms-settings|ms-settings-airplanemode|ms-settings-bluetooth|ms-settings-camera|ms-settings-cellular|ms-settings-cloudstorage|ms-settings-emailandaccounts|ms-settings-language|ms-settings-location|ms-settings-lock|ms-settings-nfctransactions|ms-settings-notifications|ms-settings-power|ms-settings-privacy|ms-settings-proximity|ms-settings-screenrotation|ms-settings-wifi|ms-settings-workplace|msnim|msrp|msrps|mtqp|mumble|mupdate|mvn|news|nfs|ni|nih|nntp|notes|oid|opaquelocktoken|pack|palm|paparazzi|pkcs11|platform|pop|pres|prospero|proxy|psyc|query|redis|rediss|reload|res|resource|rmi|rsync|rtmfp|rtmp|rtsp|rtsps|rtspu|secondlife|service|session|sftp|sgn|shttp|sieve|sip|sips|skype|smb|sms|smtp|snews|snmp|soap.beep|soap.beeps|soldat|spotify|ssh|steam|stun|stuns|submit|svn|tag|teamspeak|tel|teliaeid|telnet|tftp|things|thismessage|tip|tn3270|turn|turns|tv|udp|unreal|urn|ut2004|vemmi|ventrilo|videotex|view-source|wais|webcal|ws|wss|wtai|wyciwyg|xcon|xcon-userid|xfire|xmlrpc\\.beep|xmlrpc.beeps|xmpp|xri|ymsgr|z39\\.50|z39\\.50r|z39\\.50s)):// # protocol\n (([\\pL\\pN-]+:)?([\\pL\\pN-]+)@)? # basic auth\n (\n ([\\pL\\pN\\pS-\\.])+(\\.?([\\pL]|xn\\-\\-[\\pL\\pN-]+)+\\.?) # a domain name\n | # or\n \\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3} # an IP address\n | # or\n \\[\n (?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-f]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,1}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,2}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,3}(?:(?:[0-9a-f]{1,4})))?::(?:(?:[0-9a-f]{1,4})):)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,4}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::))))\n \\] # an IPv6 address\n )\n (:[0-9]+)? # a port (optional)\n (/?|/\\S+|\\?\\S*|\\#\\S*) # a /, nothing, a / with something, a query or a fragment\n $~ixu'",
";",
"return",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"value",
")",
">",
"0",
";",
"}"
] | 检测是否有效的 url 地址
@param string $value
@param bool $onlyHttp
@return bool | [
"检测是否有效的",
"url",
"地址"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Validation/Valid.php#L196-L229 |
zhouyl/mellivora | Mellivora/Validation/Valid.php | Valid.numeric | public static function numeric($value)
{
// Get the decimal point for the current locale
list($decimal) = array_values(localeconv());
// A lookahead is used to make sure the string contains at least one digit (before or after the decimal point)
return (bool) preg_match('/^-?+(?=.*[0-9])[0-9]*+' . preg_quote($decimal) . '?+[0-9]*+$/D', (string) $value);
} | php | public static function numeric($value)
{
// Get the decimal point for the current locale
list($decimal) = array_values(localeconv());
// A lookahead is used to make sure the string contains at least one digit (before or after the decimal point)
return (bool) preg_match('/^-?+(?=.*[0-9])[0-9]*+' . preg_quote($decimal) . '?+[0-9]*+$/D', (string) $value);
} | [
"public",
"static",
"function",
"numeric",
"(",
"$",
"value",
")",
"{",
"// Get the decimal point for the current locale",
"list",
"(",
"$",
"decimal",
")",
"=",
"array_values",
"(",
"localeconv",
"(",
")",
")",
";",
"// A lookahead is used to make sure the string contains at least one digit (before or after the decimal point)",
"return",
"(",
"bool",
")",
"preg_match",
"(",
"'/^-?+(?=.*[0-9])[0-9]*+'",
".",
"preg_quote",
"(",
"$",
"decimal",
")",
".",
"'?+[0-9]*+$/D'",
",",
"(",
"string",
")",
"$",
"value",
")",
";",
"}"
] | 检测是否有效的数字 (包括本地化字符格式)
Uses {@link http://www.php.net/manual/en/function.localeconv.php locale conversion}
to allow decimal point to be locale specific.
@param string input string
@param mixed $value
@return bool | [
"检测是否有效的数字",
"(",
"包括本地化字符格式",
")"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Validation/Valid.php#L356-L363 |
zhouyl/mellivora | Mellivora/Validation/Valid.php | Valid.min | public static function min($value, $min = 0, $equal = true)
{
return $equal ? $value >= $min : $value > $min;
} | php | public static function min($value, $min = 0, $equal = true)
{
return $equal ? $value >= $min : $value > $min;
} | [
"public",
"static",
"function",
"min",
"(",
"$",
"value",
",",
"$",
"min",
"=",
"0",
",",
"$",
"equal",
"=",
"true",
")",
"{",
"return",
"$",
"equal",
"?",
"$",
"value",
">=",
"$",
"min",
":",
"$",
"value",
">",
"$",
"min",
";",
"}"
] | 检测是否大于指定的值
@param int $value
@param int $min
@param bool $equal
@return bool | [
"检测是否大于指定的值"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Validation/Valid.php#L402-L405 |
zhouyl/mellivora | Mellivora/Validation/Valid.php | Valid.max | public static function max($value, $max = 0, $equal = true)
{
return $equal ? $value <= $max : $value < $max;
} | php | public static function max($value, $max = 0, $equal = true)
{
return $equal ? $value <= $max : $value < $max;
} | [
"public",
"static",
"function",
"max",
"(",
"$",
"value",
",",
"$",
"max",
"=",
"0",
",",
"$",
"equal",
"=",
"true",
")",
"{",
"return",
"$",
"equal",
"?",
"$",
"value",
"<=",
"$",
"max",
":",
"$",
"value",
"<",
"$",
"max",
";",
"}"
] | 检测是否小于指定的值
@param int $value
@param int $max
@param bool $equal
@return bool | [
"检测是否小于指定的值"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Validation/Valid.php#L416-L419 |
zhouyl/mellivora | Mellivora/Validation/Valid.php | Valid.json | public static function json($value)
{
if (!is_scalar($value) && !method_exists($value, '__toString')) {
return false;
}
json_decode((string) $value);
return json_last_error() === JSON_ERROR_NONE;
} | php | public static function json($value)
{
if (!is_scalar($value) && !method_exists($value, '__toString')) {
return false;
}
json_decode((string) $value);
return json_last_error() === JSON_ERROR_NONE;
} | [
"public",
"static",
"function",
"json",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
"&&",
"!",
"method_exists",
"(",
"$",
"value",
",",
"'__toString'",
")",
")",
"{",
"return",
"false",
";",
"}",
"json_decode",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"return",
"json_last_error",
"(",
")",
"===",
"JSON_ERROR_NONE",
";",
"}"
] | 检测是否有效的 json 数据
@param string $value
@return bool | [
"检测是否有效的",
"json",
"数据"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Validation/Valid.php#L463-L472 |
tttptd/laravel-responder | src/Http/ResponseBuilder.php | ResponseBuilder.respond | public function respond(int $statusCode = null, array $headers = []):JsonResponse
{
if (! is_null($statusCode)) {
$this->setStatus($statusCode);
}
$data = $this->toArray();
$data = $this->includeStatusCode($data);
$data = $this->includeSuccessFlag($data);
return $this->responseFactory->json($data, $this->statusCode, $headers);
} | php | public function respond(int $statusCode = null, array $headers = []):JsonResponse
{
if (! is_null($statusCode)) {
$this->setStatus($statusCode);
}
$data = $this->toArray();
$data = $this->includeStatusCode($data);
$data = $this->includeSuccessFlag($data);
return $this->responseFactory->json($data, $this->statusCode, $headers);
} | [
"public",
"function",
"respond",
"(",
"int",
"$",
"statusCode",
"=",
"null",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
":",
"JsonResponse",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"statusCode",
")",
")",
"{",
"$",
"this",
"->",
"setStatus",
"(",
"$",
"statusCode",
")",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"toArray",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"includeStatusCode",
"(",
"$",
"data",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"includeSuccessFlag",
"(",
"$",
"data",
")",
";",
"return",
"$",
"this",
"->",
"responseFactory",
"->",
"json",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"statusCode",
",",
"$",
"headers",
")",
";",
"}"
] | Serialize the data and wrap it in a JSON response object.
@param int|null $statusCode
@param array $headers
@return \Illuminate\Http\JsonResponse | [
"Serialize",
"the",
"data",
"and",
"wrap",
"it",
"in",
"a",
"JSON",
"response",
"object",
"."
] | train | https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Http/ResponseBuilder.php#L67-L78 |
flowcode/AmulenUserBundle | src/Flowcode/UserBundle/Controller/AdminUserController.php | AdminUserController.indexAction | public function indexAction(Request $request)
{
/* init filters */
$filter['q'] = $request->get('q');
$em = $this->getDoctrine()->getManager();
$qb = $em->getRepository('AmulenUserBundle:User')->createQueryBuilder('u');
if ($filter['q']) {
$qb->andWhere('(u.username LIKE :username OR u.email LIKE :username OR u.email LIKE :username OR u.firstname LIKE :username OR u.lastname LIKE :username)')->setParameter('username', '%' . $filter['q'] . '%');
}
$paginator = $this->get('knp_paginator')->paginate($qb, $request->query->get('page', 1), 20);
return array(
'paginator' => $paginator,
'filter' => $filter,
);
} | php | public function indexAction(Request $request)
{
/* init filters */
$filter['q'] = $request->get('q');
$em = $this->getDoctrine()->getManager();
$qb = $em->getRepository('AmulenUserBundle:User')->createQueryBuilder('u');
if ($filter['q']) {
$qb->andWhere('(u.username LIKE :username OR u.email LIKE :username OR u.email LIKE :username OR u.firstname LIKE :username OR u.lastname LIKE :username)')->setParameter('username', '%' . $filter['q'] . '%');
}
$paginator = $this->get('knp_paginator')->paginate($qb, $request->query->get('page', 1), 20);
return array(
'paginator' => $paginator,
'filter' => $filter,
);
} | [
"public",
"function",
"indexAction",
"(",
"Request",
"$",
"request",
")",
"{",
"/* init filters */",
"$",
"filter",
"[",
"'q'",
"]",
"=",
"$",
"request",
"->",
"get",
"(",
"'q'",
")",
";",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"qb",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'AmulenUserBundle:User'",
")",
"->",
"createQueryBuilder",
"(",
"'u'",
")",
";",
"if",
"(",
"$",
"filter",
"[",
"'q'",
"]",
")",
"{",
"$",
"qb",
"->",
"andWhere",
"(",
"'(u.username LIKE :username OR u.email LIKE :username OR u.email LIKE :username OR u.firstname LIKE :username OR u.lastname LIKE :username)'",
")",
"->",
"setParameter",
"(",
"'username'",
",",
"'%'",
".",
"$",
"filter",
"[",
"'q'",
"]",
".",
"'%'",
")",
";",
"}",
"$",
"paginator",
"=",
"$",
"this",
"->",
"get",
"(",
"'knp_paginator'",
")",
"->",
"paginate",
"(",
"$",
"qb",
",",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'page'",
",",
"1",
")",
",",
"20",
")",
";",
"return",
"array",
"(",
"'paginator'",
"=>",
"$",
"paginator",
",",
"'filter'",
"=>",
"$",
"filter",
",",
")",
";",
"}"
] | Lists all User entities.
@Route("/", name="admin_user")
@Method("GET")
@Template() | [
"Lists",
"all",
"User",
"entities",
"."
] | train | https://github.com/flowcode/AmulenUserBundle/blob/00055834d9f094e63dcd8d66e2fedb822fcddee0/src/Flowcode/UserBundle/Controller/AdminUserController.php#L30-L47 |
flowcode/AmulenUserBundle | src/Flowcode/UserBundle/Controller/AdminUserController.php | AdminUserController.createAction | public function createAction(Request $request)
{
$entity = new User();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$userService = $this->get("flowcode.user");
$userService->create($entity);
return $this->redirect($this->generateUrl('admin_user_show', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView(),
);
} | php | public function createAction(Request $request)
{
$entity = new User();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$userService = $this->get("flowcode.user");
$userService->create($entity);
return $this->redirect($this->generateUrl('admin_user_show', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView(),
);
} | [
"public",
"function",
"createAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"entity",
"=",
"new",
"User",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createCreateForm",
"(",
"$",
"entity",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"userService",
"=",
"$",
"this",
"->",
"get",
"(",
"\"flowcode.user\"",
")",
";",
"$",
"userService",
"->",
"create",
"(",
"$",
"entity",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'admin_user_show'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"entity",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"return",
"array",
"(",
"'entity'",
"=>",
"$",
"entity",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] | Creates a new User entity.
@Route("/", name="admin_user_create")
@Method("POST")
@Template("FlowcodeUserBundle:User:new.html.twig") | [
"Creates",
"a",
"new",
"User",
"entity",
"."
] | train | https://github.com/flowcode/AmulenUserBundle/blob/00055834d9f094e63dcd8d66e2fedb822fcddee0/src/Flowcode/UserBundle/Controller/AdminUserController.php#L56-L73 |
flowcode/AmulenUserBundle | src/Flowcode/UserBundle/Controller/AdminUserController.php | AdminUserController.newAction | public function newAction()
{
$userManager = $this->container->get('flowcode.user');
$entity = new User();
$form = $this->createCreateForm($entity);
return array(
'entity' => $entity,
'form' => $form->createView(),
);
} | php | public function newAction()
{
$userManager = $this->container->get('flowcode.user');
$entity = new User();
$form = $this->createCreateForm($entity);
return array(
'entity' => $entity,
'form' => $form->createView(),
);
} | [
"public",
"function",
"newAction",
"(",
")",
"{",
"$",
"userManager",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'flowcode.user'",
")",
";",
"$",
"entity",
"=",
"new",
"User",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createCreateForm",
"(",
"$",
"entity",
")",
";",
"return",
"array",
"(",
"'entity'",
"=>",
"$",
"entity",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] | Displays a form to create a new User entity.
@Route("/new", name="admin_user_new")
@Method("GET")
@Template() | [
"Displays",
"a",
"form",
"to",
"create",
"a",
"new",
"User",
"entity",
"."
] | train | https://github.com/flowcode/AmulenUserBundle/blob/00055834d9f094e63dcd8d66e2fedb822fcddee0/src/Flowcode/UserBundle/Controller/AdminUserController.php#L101-L112 |
SporkCode/Spork | src/Filter/DateTime.php | DateTime.filter | public function filter($value)
{
if ($value instanceof \DateTime) {
return $value;
}
try {
$datetime = new \DateTime($value);
} catch (\Exception $exception) {
return false;
}
return $datetime;
} | php | public function filter($value)
{
if ($value instanceof \DateTime) {
return $value;
}
try {
$datetime = new \DateTime($value);
} catch (\Exception $exception) {
return false;
}
return $datetime;
} | [
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
"{",
"return",
"$",
"value",
";",
"}",
"try",
"{",
"$",
"datetime",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"value",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"datetime",
";",
"}"
] | filter
@see \Zend\Filter\FilterInterface::filter()
@param mixed $value
@return \DateTime|boolean | [
"filter"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Filter/DateTime.php#L21-L34 |
yosymfony/ConfigServiceProvider | src/Yosymfony/Silex/ConfigServiceProvider/Config.php | Config.load | public function load($resource, $type = null)
{
$repository = $this->delegatingLoader->load($resource, $type);
if(!$repository instanceof ConfigRepositoryInterface)
{
throw new \UnexpectedValueException('The loader must return a repository instance');
}
return $repository;
} | php | public function load($resource, $type = null)
{
$repository = $this->delegatingLoader->load($resource, $type);
if(!$repository instanceof ConfigRepositoryInterface)
{
throw new \UnexpectedValueException('The loader must return a repository instance');
}
return $repository;
} | [
"public",
"function",
"load",
"(",
"$",
"resource",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"delegatingLoader",
"->",
"load",
"(",
"$",
"resource",
",",
"$",
"type",
")",
";",
"if",
"(",
"!",
"$",
"repository",
"instanceof",
"ConfigRepositoryInterface",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'The loader must return a repository instance'",
")",
";",
"}",
"return",
"$",
"repository",
";",
"}"
] | Loads a resource like file or inline configuration
@param string $resource A resource
@param string $type The resource type. Don't set this argument in files case.
@return ConfigRepositoryInterface
@throws Symfony\Component\Config\Exception\FileLoaderLoadException If the loader not found.
@throws \UnexpectedValueException If the loader not return a repository instance | [
"Loads",
"a",
"resource",
"like",
"file",
"or",
"inline",
"configuration"
] | train | https://github.com/yosymfony/ConfigServiceProvider/blob/f6cb9a9fc707b6c92e0d03201e5ecc17eaee3114/src/Yosymfony/Silex/ConfigServiceProvider/Config.php#L60-L70 |
antaresproject/notifications | src/Widgets/NotificationSender/NotificationsWidget.php | NotificationsWidget.routes | public static function routes()
{
$area = area();
Route::post($area . '/notifications/notifications', NotificationController::class . '@index');
Route::post($area . '/notifications/widgets/send', NotificationController::class . '@send');
} | php | public static function routes()
{
$area = area();
Route::post($area . '/notifications/notifications', NotificationController::class . '@index');
Route::post($area . '/notifications/widgets/send', NotificationController::class . '@send');
} | [
"public",
"static",
"function",
"routes",
"(",
")",
"{",
"$",
"area",
"=",
"area",
"(",
")",
";",
"Route",
"::",
"post",
"(",
"$",
"area",
".",
"'/notifications/notifications'",
",",
"NotificationController",
"::",
"class",
".",
"'@index'",
")",
";",
"Route",
"::",
"post",
"(",
"$",
"area",
".",
"'/notifications/widgets/send'",
",",
"NotificationController",
"::",
"class",
".",
"'@send'",
")",
";",
"}"
] | Widgets routes implementations
@return void | [
"Widgets",
"routes",
"implementations"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Widgets/NotificationSender/NotificationsWidget.php#L85-L90 |
antaresproject/notifications | src/Widgets/NotificationSender/NotificationsWidget.php | NotificationsWidget.render | public function render()
{
app('antares.asset')->container('antares/foundation::application')->add('webpack_forms_basic', '/webpack/forms_basic.js', ['app_cache']);
publish('notifications', ['js/notification-widget.js']);
return view('antares/notifications::widgets.send_notification', ['form' => $this->form->get()])->render();
} | php | public function render()
{
app('antares.asset')->container('antares/foundation::application')->add('webpack_forms_basic', '/webpack/forms_basic.js', ['app_cache']);
publish('notifications', ['js/notification-widget.js']);
return view('antares/notifications::widgets.send_notification', ['form' => $this->form->get()])->render();
} | [
"public",
"function",
"render",
"(",
")",
"{",
"app",
"(",
"'antares.asset'",
")",
"->",
"container",
"(",
"'antares/foundation::application'",
")",
"->",
"add",
"(",
"'webpack_forms_basic'",
",",
"'/webpack/forms_basic.js'",
",",
"[",
"'app_cache'",
"]",
")",
";",
"publish",
"(",
"'notifications'",
",",
"[",
"'js/notification-widget.js'",
"]",
")",
";",
"return",
"view",
"(",
"'antares/notifications::widgets.send_notification'",
",",
"[",
"'form'",
"=>",
"$",
"this",
"->",
"form",
"->",
"get",
"(",
")",
"]",
")",
"->",
"render",
"(",
")",
";",
"}"
] | Renders widget content
@return \Illuminate\View\View | [
"Renders",
"widget",
"content"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Widgets/NotificationSender/NotificationsWidget.php#L97-L103 |
heidelpay/PhpDoc | src/phpDocumentor/Compiler/Pass/ExampleTagsEnricher.php | ExampleTagsEnricher.execute | public function execute(ProjectDescriptor $project)
{
$elements = $project->getIndexes()->get('elements');
/** @var DescriptorAbstract $element */
foreach ($elements as $element) {
$element->setDescription($this->replaceInlineExamples($element));
}
} | php | public function execute(ProjectDescriptor $project)
{
$elements = $project->getIndexes()->get('elements');
/** @var DescriptorAbstract $element */
foreach ($elements as $element) {
$element->setDescription($this->replaceInlineExamples($element));
}
} | [
"public",
"function",
"execute",
"(",
"ProjectDescriptor",
"$",
"project",
")",
"{",
"$",
"elements",
"=",
"$",
"project",
"->",
"getIndexes",
"(",
")",
"->",
"get",
"(",
"'elements'",
")",
";",
"/** @var DescriptorAbstract $element */",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"$",
"element",
"->",
"setDescription",
"(",
"$",
"this",
"->",
"replaceInlineExamples",
"(",
"$",
"element",
")",
")",
";",
"}",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Compiler/Pass/ExampleTagsEnricher.php#L52-L60 |
heidelpay/PhpDoc | src/phpDocumentor/Compiler/Pass/ExampleTagsEnricher.php | ExampleTagsEnricher.replaceInlineExamples | protected function replaceInlineExamples(DescriptorAbstract $element)
{
$description = $element->getDescription();
$matches = array();
if (! $description
|| ! preg_match_all('/\{@example\s(.+?)\}/', $description, $matches)
|| count($matches[0]) < 1
) {
return $description;
}
$matched = array();
foreach ($matches[0] as $index => $match) {
if (isset($matched[$match])) {
continue;
}
$matched[$match] = true;
$exampleReflector = new ExampleTag('example', $matches[1][$index]);
$example = $this->exampleAssembler->create($exampleReflector);
$replacement = '`'.$example->getExample().'`';
if ($example->getDescription()) {
$replacement = '*' . $example->getDescription() . '*' . $replacement;
}
$description = str_replace($match, $replacement, $description);
}
return $description;
} | php | protected function replaceInlineExamples(DescriptorAbstract $element)
{
$description = $element->getDescription();
$matches = array();
if (! $description
|| ! preg_match_all('/\{@example\s(.+?)\}/', $description, $matches)
|| count($matches[0]) < 1
) {
return $description;
}
$matched = array();
foreach ($matches[0] as $index => $match) {
if (isset($matched[$match])) {
continue;
}
$matched[$match] = true;
$exampleReflector = new ExampleTag('example', $matches[1][$index]);
$example = $this->exampleAssembler->create($exampleReflector);
$replacement = '`'.$example->getExample().'`';
if ($example->getDescription()) {
$replacement = '*' . $example->getDescription() . '*' . $replacement;
}
$description = str_replace($match, $replacement, $description);
}
return $description;
} | [
"protected",
"function",
"replaceInlineExamples",
"(",
"DescriptorAbstract",
"$",
"element",
")",
"{",
"$",
"description",
"=",
"$",
"element",
"->",
"getDescription",
"(",
")",
";",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"description",
"||",
"!",
"preg_match_all",
"(",
"'/\\{@example\\s(.+?)\\}/'",
",",
"$",
"description",
",",
"$",
"matches",
")",
"||",
"count",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
"<",
"1",
")",
"{",
"return",
"$",
"description",
";",
"}",
"$",
"matched",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"index",
"=>",
"$",
"match",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"matched",
"[",
"$",
"match",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"matched",
"[",
"$",
"match",
"]",
"=",
"true",
";",
"$",
"exampleReflector",
"=",
"new",
"ExampleTag",
"(",
"'example'",
",",
"$",
"matches",
"[",
"1",
"]",
"[",
"$",
"index",
"]",
")",
";",
"$",
"example",
"=",
"$",
"this",
"->",
"exampleAssembler",
"->",
"create",
"(",
"$",
"exampleReflector",
")",
";",
"$",
"replacement",
"=",
"'`'",
".",
"$",
"example",
"->",
"getExample",
"(",
")",
".",
"'`'",
";",
"if",
"(",
"$",
"example",
"->",
"getDescription",
"(",
")",
")",
"{",
"$",
"replacement",
"=",
"'*'",
".",
"$",
"example",
"->",
"getDescription",
"(",
")",
".",
"'*'",
".",
"$",
"replacement",
";",
"}",
"$",
"description",
"=",
"str_replace",
"(",
"$",
"match",
",",
"$",
"replacement",
",",
"$",
"description",
")",
";",
"}",
"return",
"$",
"description",
";",
"}"
] | Replaces the example tags in the description with the contents of the found example.
@param DescriptorAbstract $element
@return string | [
"Replaces",
"the",
"example",
"tags",
"in",
"the",
"description",
"with",
"the",
"contents",
"of",
"the",
"found",
"example",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Compiler/Pass/ExampleTagsEnricher.php#L69-L101 |
php-lug/lug | src/Bundle/ResourceBundle/EventSubscriber/Doctrine/MongoDB/ResolveTargetDocumentSubscriber.php | ResolveTargetDocumentSubscriber.addResolveTargetDocument | public function addResolveTargetDocument($originalDocument, $newDocument, array $mapping)
{
$mapping['targetDocument'] = ltrim($newDocument, '\\\\');
$this->resolveTargetEntities[ltrim($originalDocument, '\\\\')] = $mapping;
parent::addResolveTargetDocument($originalDocument, $newDocument, $mapping);
} | php | public function addResolveTargetDocument($originalDocument, $newDocument, array $mapping)
{
$mapping['targetDocument'] = ltrim($newDocument, '\\\\');
$this->resolveTargetEntities[ltrim($originalDocument, '\\\\')] = $mapping;
parent::addResolveTargetDocument($originalDocument, $newDocument, $mapping);
} | [
"public",
"function",
"addResolveTargetDocument",
"(",
"$",
"originalDocument",
",",
"$",
"newDocument",
",",
"array",
"$",
"mapping",
")",
"{",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
"=",
"ltrim",
"(",
"$",
"newDocument",
",",
"'\\\\\\\\'",
")",
";",
"$",
"this",
"->",
"resolveTargetEntities",
"[",
"ltrim",
"(",
"$",
"originalDocument",
",",
"'\\\\\\\\'",
")",
"]",
"=",
"$",
"mapping",
";",
"parent",
"::",
"addResolveTargetDocument",
"(",
"$",
"originalDocument",
",",
"$",
"newDocument",
",",
"$",
"mapping",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/ResourceBundle/EventSubscriber/Doctrine/MongoDB/ResolveTargetDocumentSubscriber.php#L41-L47 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/common_sql_reader.php | ezcDbSchemaCommonSqlReader.processSchema | protected function processSchema( array $tables )
{
$schemaDefinition = array();
array_walk( $tables, create_function( '&$item,$key', '$item = $item[0];' ) );
// strip out the prefix and only return tables with the prefix set.
$prefix = ezcDbSchema::$options->tableNamePrefix;
foreach ( $tables as $tableName )
{
$tableNameWithoutPrefix = substr( $tableName, strlen( $prefix ) );
// Process table if there was no prefix, or when a prefix was
// found. In the latter case the prefix would be missing from
// $tableNameWithoutPrefix due to the substr() above, and hence,
// $tableName and $tableNameWithoutPrefix would be different.
if ( $prefix === '' || $tableName !== $tableNameWithoutPrefix )
{
$fields = $this->fetchTableFields( $tableName );
$indexes = $this->fetchTableIndexes( $tableName );
$schemaDefinition[$tableNameWithoutPrefix] = ezcDbSchema::createNewTable( $fields, $indexes );
}
}
return $schemaDefinition;
} | php | protected function processSchema( array $tables )
{
$schemaDefinition = array();
array_walk( $tables, create_function( '&$item,$key', '$item = $item[0];' ) );
// strip out the prefix and only return tables with the prefix set.
$prefix = ezcDbSchema::$options->tableNamePrefix;
foreach ( $tables as $tableName )
{
$tableNameWithoutPrefix = substr( $tableName, strlen( $prefix ) );
// Process table if there was no prefix, or when a prefix was
// found. In the latter case the prefix would be missing from
// $tableNameWithoutPrefix due to the substr() above, and hence,
// $tableName and $tableNameWithoutPrefix would be different.
if ( $prefix === '' || $tableName !== $tableNameWithoutPrefix )
{
$fields = $this->fetchTableFields( $tableName );
$indexes = $this->fetchTableIndexes( $tableName );
$schemaDefinition[$tableNameWithoutPrefix] = ezcDbSchema::createNewTable( $fields, $indexes );
}
}
return $schemaDefinition;
} | [
"protected",
"function",
"processSchema",
"(",
"array",
"$",
"tables",
")",
"{",
"$",
"schemaDefinition",
"=",
"array",
"(",
")",
";",
"array_walk",
"(",
"$",
"tables",
",",
"create_function",
"(",
"'&$item,$key'",
",",
"'$item = $item[0];'",
")",
")",
";",
"// strip out the prefix and only return tables with the prefix set.",
"$",
"prefix",
"=",
"ezcDbSchema",
"::",
"$",
"options",
"->",
"tableNamePrefix",
";",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"tableName",
")",
"{",
"$",
"tableNameWithoutPrefix",
"=",
"substr",
"(",
"$",
"tableName",
",",
"strlen",
"(",
"$",
"prefix",
")",
")",
";",
"// Process table if there was no prefix, or when a prefix was",
"// found. In the latter case the prefix would be missing from",
"// $tableNameWithoutPrefix due to the substr() above, and hence,",
"// $tableName and $tableNameWithoutPrefix would be different.",
"if",
"(",
"$",
"prefix",
"===",
"''",
"||",
"$",
"tableName",
"!==",
"$",
"tableNameWithoutPrefix",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"fetchTableFields",
"(",
"$",
"tableName",
")",
";",
"$",
"indexes",
"=",
"$",
"this",
"->",
"fetchTableIndexes",
"(",
"$",
"tableName",
")",
";",
"$",
"schemaDefinition",
"[",
"$",
"tableNameWithoutPrefix",
"]",
"=",
"ezcDbSchema",
"::",
"createNewTable",
"(",
"$",
"fields",
",",
"$",
"indexes",
")",
";",
"}",
"}",
"return",
"$",
"schemaDefinition",
";",
"}"
] | Loops over all the table names in the array and extracts schema
information.
This method extracts information about a database's schema from the
database itself and returns this schema as an ezcDbSchema object.
@param array(string) $tables
@return ezcDbSchema | [
"Loops",
"over",
"all",
"the",
"table",
"names",
"in",
"the",
"array",
"and",
"extracts",
"schema",
"information",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/common_sql_reader.php#L58-L83 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/common_sql_reader.php | ezcDbSchemaCommonSqlReader.lowercase | protected function lowercase( array $source )
{
$result = array();
foreach ($source as $key => $value )
$result[strtolower($key)] = $value;
return $result;
} | php | protected function lowercase( array $source )
{
$result = array();
foreach ($source as $key => $value )
$result[strtolower($key)] = $value;
return $result;
} | [
"protected",
"function",
"lowercase",
"(",
"array",
"$",
"source",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"source",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"$",
"result",
"[",
"strtolower",
"(",
"$",
"key",
")",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"result",
";",
"}"
] | Lowercase all array keys to conform default Database behaviour
@param array(string=>mixed) $source
@return array | [
"Lowercase",
"all",
"array",
"keys",
"to",
"conform",
"default",
"Database",
"behaviour"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/common_sql_reader.php#L91-L99 |
highday/glitter | database/migrations/2016_12_14_000042_create_store_customer_table.php | CreateStoreCustomerTable.up | public function up()
{
Schema::create('store_customer', function (Blueprint $table) {
$table->increments('id');
$table->integer('store_id')->unsigned();
$table->foreign('store_id')->references('id')->on('stores')->onDelete('cascade');
$table->integer('customer_id')->unsigned();
$table->foreign('customer_id')->references('id')->on('customers')->onDelete('cascade');
$table->integer('address_id')->unsigned()->nullable();
$table->foreign('address_id')->references('id')->on('customer_addresses')->onDelete('cascade');
$table->boolean('accepts_marketing')->default(false);
$table->boolean('tax_exempt')->default(false);
$table->text('note')->nullable();
$table->timestamp('join_at');
});
} | php | public function up()
{
Schema::create('store_customer', function (Blueprint $table) {
$table->increments('id');
$table->integer('store_id')->unsigned();
$table->foreign('store_id')->references('id')->on('stores')->onDelete('cascade');
$table->integer('customer_id')->unsigned();
$table->foreign('customer_id')->references('id')->on('customers')->onDelete('cascade');
$table->integer('address_id')->unsigned()->nullable();
$table->foreign('address_id')->references('id')->on('customer_addresses')->onDelete('cascade');
$table->boolean('accepts_marketing')->default(false);
$table->boolean('tax_exempt')->default(false);
$table->text('note')->nullable();
$table->timestamp('join_at');
});
} | [
"public",
"function",
"up",
"(",
")",
"{",
"Schema",
"::",
"create",
"(",
"'store_customer'",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"increments",
"(",
"'id'",
")",
";",
"$",
"table",
"->",
"integer",
"(",
"'store_id'",
")",
"->",
"unsigned",
"(",
")",
";",
"$",
"table",
"->",
"foreign",
"(",
"'store_id'",
")",
"->",
"references",
"(",
"'id'",
")",
"->",
"on",
"(",
"'stores'",
")",
"->",
"onDelete",
"(",
"'cascade'",
")",
";",
"$",
"table",
"->",
"integer",
"(",
"'customer_id'",
")",
"->",
"unsigned",
"(",
")",
";",
"$",
"table",
"->",
"foreign",
"(",
"'customer_id'",
")",
"->",
"references",
"(",
"'id'",
")",
"->",
"on",
"(",
"'customers'",
")",
"->",
"onDelete",
"(",
"'cascade'",
")",
";",
"$",
"table",
"->",
"integer",
"(",
"'address_id'",
")",
"->",
"unsigned",
"(",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"foreign",
"(",
"'address_id'",
")",
"->",
"references",
"(",
"'id'",
")",
"->",
"on",
"(",
"'customer_addresses'",
")",
"->",
"onDelete",
"(",
"'cascade'",
")",
";",
"$",
"table",
"->",
"boolean",
"(",
"'accepts_marketing'",
")",
"->",
"default",
"(",
"false",
")",
";",
"$",
"table",
"->",
"boolean",
"(",
"'tax_exempt'",
")",
"->",
"default",
"(",
"false",
")",
";",
"$",
"table",
"->",
"text",
"(",
"'note'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"timestamp",
"(",
"'join_at'",
")",
";",
"}",
")",
";",
"}"
] | Run the migrations.
@return void | [
"Run",
"the",
"migrations",
"."
] | train | https://github.com/highday/glitter/blob/d1c7a227fd2343806bd3ec0314e621ced57dfe66/database/migrations/2016_12_14_000042_create_store_customer_table.php#L14-L29 |
sabre-io/cs | lib/PublicVisibility.php | PublicVisibility.fix | function fix(\SplFileInfo $file, $content)
{
$tokens = Tokens::fromCode($content);
$elements = $tokens->getClassyElements();
foreach (array_reverse($elements, true) as $index => $element) {
if ('method' === $element['type']) {
$this->applyAttribs($tokens, $index, $this->grabAttribsBeforeMethodToken($tokens, $index));
// force whitespace between function keyword and function name to be single space char
$tokens[++$index]->setContent(' ');
} elseif ('property' === $element['type']) {
$prevIndex = $tokens->getPrevTokenOfKind($index, [';', ',', '{']);
if (!$prevIndex || !$tokens[$prevIndex]->equals(',')) {
$this->applyAttribs($tokens, $index, $this->grabAttribsBeforePropertyToken($tokens, $index));
}
}
}
return $tokens->generateCode();
} | php | function fix(\SplFileInfo $file, $content)
{
$tokens = Tokens::fromCode($content);
$elements = $tokens->getClassyElements();
foreach (array_reverse($elements, true) as $index => $element) {
if ('method' === $element['type']) {
$this->applyAttribs($tokens, $index, $this->grabAttribsBeforeMethodToken($tokens, $index));
// force whitespace between function keyword and function name to be single space char
$tokens[++$index]->setContent(' ');
} elseif ('property' === $element['type']) {
$prevIndex = $tokens->getPrevTokenOfKind($index, [';', ',', '{']);
if (!$prevIndex || !$tokens[$prevIndex]->equals(',')) {
$this->applyAttribs($tokens, $index, $this->grabAttribsBeforePropertyToken($tokens, $index));
}
}
}
return $tokens->generateCode();
} | [
"function",
"fix",
"(",
"\\",
"SplFileInfo",
"$",
"file",
",",
"$",
"content",
")",
"{",
"$",
"tokens",
"=",
"Tokens",
"::",
"fromCode",
"(",
"$",
"content",
")",
";",
"$",
"elements",
"=",
"$",
"tokens",
"->",
"getClassyElements",
"(",
")",
";",
"foreach",
"(",
"array_reverse",
"(",
"$",
"elements",
",",
"true",
")",
"as",
"$",
"index",
"=>",
"$",
"element",
")",
"{",
"if",
"(",
"'method'",
"===",
"$",
"element",
"[",
"'type'",
"]",
")",
"{",
"$",
"this",
"->",
"applyAttribs",
"(",
"$",
"tokens",
",",
"$",
"index",
",",
"$",
"this",
"->",
"grabAttribsBeforeMethodToken",
"(",
"$",
"tokens",
",",
"$",
"index",
")",
")",
";",
"// force whitespace between function keyword and function name to be single space char",
"$",
"tokens",
"[",
"++",
"$",
"index",
"]",
"->",
"setContent",
"(",
"' '",
")",
";",
"}",
"elseif",
"(",
"'property'",
"===",
"$",
"element",
"[",
"'type'",
"]",
")",
"{",
"$",
"prevIndex",
"=",
"$",
"tokens",
"->",
"getPrevTokenOfKind",
"(",
"$",
"index",
",",
"[",
"';'",
",",
"','",
",",
"'{'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"prevIndex",
"||",
"!",
"$",
"tokens",
"[",
"$",
"prevIndex",
"]",
"->",
"equals",
"(",
"','",
")",
")",
"{",
"$",
"this",
"->",
"applyAttribs",
"(",
"$",
"tokens",
",",
"$",
"index",
",",
"$",
"this",
"->",
"grabAttribsBeforePropertyToken",
"(",
"$",
"tokens",
",",
"$",
"index",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"tokens",
"->",
"generateCode",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/sabre-io/cs/blob/a4c57e213bf3f5e7d6b29a2f70d1ca4b0dce6d86/lib/PublicVisibility.php#L44-L65 |
sabre-io/cs | lib/PublicVisibility.php | PublicVisibility.applyAttribs | private function applyAttribs(Tokens $tokens, $index, array $attribs)
{
$toInsert = [];
foreach ($attribs as $attrib) {
if (null !== $attrib && '' !== $attrib->getContent()) {
$toInsert[] = $attrib;
$toInsert[] = new Token([T_WHITESPACE, ' ']);
}
}
if (!empty($toInsert)) {
$tokens->insertAt($index, $toInsert);
}
} | php | private function applyAttribs(Tokens $tokens, $index, array $attribs)
{
$toInsert = [];
foreach ($attribs as $attrib) {
if (null !== $attrib && '' !== $attrib->getContent()) {
$toInsert[] = $attrib;
$toInsert[] = new Token([T_WHITESPACE, ' ']);
}
}
if (!empty($toInsert)) {
$tokens->insertAt($index, $toInsert);
}
} | [
"private",
"function",
"applyAttribs",
"(",
"Tokens",
"$",
"tokens",
",",
"$",
"index",
",",
"array",
"$",
"attribs",
")",
"{",
"$",
"toInsert",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"attribs",
"as",
"$",
"attrib",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"attrib",
"&&",
"''",
"!==",
"$",
"attrib",
"->",
"getContent",
"(",
")",
")",
"{",
"$",
"toInsert",
"[",
"]",
"=",
"$",
"attrib",
";",
"$",
"toInsert",
"[",
"]",
"=",
"new",
"Token",
"(",
"[",
"T_WHITESPACE",
",",
"' '",
"]",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"toInsert",
")",
")",
"{",
"$",
"tokens",
"->",
"insertAt",
"(",
"$",
"index",
",",
"$",
"toInsert",
")",
";",
"}",
"}"
] | Apply token attributes.
Token at given index is prepended by attributes.
@param Tokens $tokens Tokens collection
@param int $index token index
@param array $attribs array of token attributes | [
"Apply",
"token",
"attributes",
"."
] | train | https://github.com/sabre-io/cs/blob/a4c57e213bf3f5e7d6b29a2f70d1ca4b0dce6d86/lib/PublicVisibility.php#L84-L98 |
sabre-io/cs | lib/PublicVisibility.php | PublicVisibility.grabAttribsBeforeMethodToken | private function grabAttribsBeforeMethodToken(Tokens $tokens, $index)
{
static $tokenAttribsMap = [
T_PRIVATE => 'visibility',
T_PROTECTED => 'visibility',
T_PUBLIC => null, // destroy T_PUBLIC token. This is literally the only change from the original
T_ABSTRACT => 'abstract',
T_FINAL => 'final',
T_STATIC => 'static',
];
return $this->grabAttribsBeforeToken(
$tokens,
$index,
$tokenAttribsMap,
[
'abstract' => null,
'final' => null,
'visibility' => null,
'static' => null,
]
);
} | php | private function grabAttribsBeforeMethodToken(Tokens $tokens, $index)
{
static $tokenAttribsMap = [
T_PRIVATE => 'visibility',
T_PROTECTED => 'visibility',
T_PUBLIC => null, // destroy T_PUBLIC token. This is literally the only change from the original
T_ABSTRACT => 'abstract',
T_FINAL => 'final',
T_STATIC => 'static',
];
return $this->grabAttribsBeforeToken(
$tokens,
$index,
$tokenAttribsMap,
[
'abstract' => null,
'final' => null,
'visibility' => null,
'static' => null,
]
);
} | [
"private",
"function",
"grabAttribsBeforeMethodToken",
"(",
"Tokens",
"$",
"tokens",
",",
"$",
"index",
")",
"{",
"static",
"$",
"tokenAttribsMap",
"=",
"[",
"T_PRIVATE",
"=>",
"'visibility'",
",",
"T_PROTECTED",
"=>",
"'visibility'",
",",
"T_PUBLIC",
"=>",
"null",
",",
"// destroy T_PUBLIC token. This is literally the only change from the original",
"T_ABSTRACT",
"=>",
"'abstract'",
",",
"T_FINAL",
"=>",
"'final'",
",",
"T_STATIC",
"=>",
"'static'",
",",
"]",
";",
"return",
"$",
"this",
"->",
"grabAttribsBeforeToken",
"(",
"$",
"tokens",
",",
"$",
"index",
",",
"$",
"tokenAttribsMap",
",",
"[",
"'abstract'",
"=>",
"null",
",",
"'final'",
"=>",
"null",
",",
"'visibility'",
"=>",
"null",
",",
"'static'",
"=>",
"null",
",",
"]",
")",
";",
"}"
] | Grab attributes before method token at given index.
It's a shorthand for grabAttribsBeforeToken method.
@param Tokens $tokens Tokens collection
@param int $index token index
@return array array of grabbed attributes | [
"Grab",
"attributes",
"before",
"method",
"token",
"at",
"given",
"index",
"."
] | train | https://github.com/sabre-io/cs/blob/a4c57e213bf3f5e7d6b29a2f70d1ca4b0dce6d86/lib/PublicVisibility.php#L110-L132 |
sabre-io/cs | lib/PublicVisibility.php | PublicVisibility.grabAttribsBeforePropertyToken | private function grabAttribsBeforePropertyToken(Tokens $tokens, $index)
{
static $tokenAttribsMap = [
T_VAR => null, // destroy T_VAR token!
T_PRIVATE => 'visibility',
T_PROTECTED => 'visibility',
T_PUBLIC => 'visibility',
T_STATIC => 'static',
];
$result = $this->grabAttribsBeforeToken(
$tokens,
$index,
$tokenAttribsMap,
[
'visibility' => new Token([T_PUBLIC, 'public']),
'static' => null,
]
);
if ($result['visibility'] && 'public' === $result['visibility']->getContent()) {
// If visibility is public and static is set, we remove visibility.
if ($result['static']) {
$result['visibility'] = null;
}
}
return $result;
} | php | private function grabAttribsBeforePropertyToken(Tokens $tokens, $index)
{
static $tokenAttribsMap = [
T_VAR => null, // destroy T_VAR token!
T_PRIVATE => 'visibility',
T_PROTECTED => 'visibility',
T_PUBLIC => 'visibility',
T_STATIC => 'static',
];
$result = $this->grabAttribsBeforeToken(
$tokens,
$index,
$tokenAttribsMap,
[
'visibility' => new Token([T_PUBLIC, 'public']),
'static' => null,
]
);
if ($result['visibility'] && 'public' === $result['visibility']->getContent()) {
// If visibility is public and static is set, we remove visibility.
if ($result['static']) {
$result['visibility'] = null;
}
}
return $result;
} | [
"private",
"function",
"grabAttribsBeforePropertyToken",
"(",
"Tokens",
"$",
"tokens",
",",
"$",
"index",
")",
"{",
"static",
"$",
"tokenAttribsMap",
"=",
"[",
"T_VAR",
"=>",
"null",
",",
"// destroy T_VAR token!",
"T_PRIVATE",
"=>",
"'visibility'",
",",
"T_PROTECTED",
"=>",
"'visibility'",
",",
"T_PUBLIC",
"=>",
"'visibility'",
",",
"T_STATIC",
"=>",
"'static'",
",",
"]",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"grabAttribsBeforeToken",
"(",
"$",
"tokens",
",",
"$",
"index",
",",
"$",
"tokenAttribsMap",
",",
"[",
"'visibility'",
"=>",
"new",
"Token",
"(",
"[",
"T_PUBLIC",
",",
"'public'",
"]",
")",
",",
"'static'",
"=>",
"null",
",",
"]",
")",
";",
"if",
"(",
"$",
"result",
"[",
"'visibility'",
"]",
"&&",
"'public'",
"===",
"$",
"result",
"[",
"'visibility'",
"]",
"->",
"getContent",
"(",
")",
")",
"{",
"// If visibility is public and static is set, we remove visibility.",
"if",
"(",
"$",
"result",
"[",
"'static'",
"]",
")",
"{",
"$",
"result",
"[",
"'visibility'",
"]",
"=",
"null",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Grab attributes before property token at given index.
It's a shorthand for grabAttribsBeforeToken method.
@param Tokens $tokens Tokens collection
@param int $index token index
@return array array of grabbed attributes | [
"Grab",
"attributes",
"before",
"property",
"token",
"at",
"given",
"index",
"."
] | train | https://github.com/sabre-io/cs/blob/a4c57e213bf3f5e7d6b29a2f70d1ca4b0dce6d86/lib/PublicVisibility.php#L144-L170 |
sabre-io/cs | lib/PublicVisibility.php | PublicVisibility.grabAttribsBeforeToken | private function grabAttribsBeforeToken(Tokens $tokens, $index, array $tokenAttribsMap, array $attribs)
{
while (true) {
$token = $tokens[--$index];
if (!$token->isArray()) {
if ($token->equalsAny(['{', '}', '(', ')'])) {
break;
}
continue;
}
// if token is attribute
if (array_key_exists($token->getId(), $tokenAttribsMap)) {
// set token attribute if token map defines attribute name for token
if ($tokenAttribsMap[$token->getId()]) {
$attribs[$tokenAttribsMap[$token->getId()]] = clone $token;
}
// clear the token and whitespaces after it
$tokens[$index]->clear();
$tokens[$index + 1]->clear();
continue;
}
if ($token->isGivenKind([T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])) {
continue;
}
break;
}
return $attribs;
} | php | private function grabAttribsBeforeToken(Tokens $tokens, $index, array $tokenAttribsMap, array $attribs)
{
while (true) {
$token = $tokens[--$index];
if (!$token->isArray()) {
if ($token->equalsAny(['{', '}', '(', ')'])) {
break;
}
continue;
}
// if token is attribute
if (array_key_exists($token->getId(), $tokenAttribsMap)) {
// set token attribute if token map defines attribute name for token
if ($tokenAttribsMap[$token->getId()]) {
$attribs[$tokenAttribsMap[$token->getId()]] = clone $token;
}
// clear the token and whitespaces after it
$tokens[$index]->clear();
$tokens[$index + 1]->clear();
continue;
}
if ($token->isGivenKind([T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])) {
continue;
}
break;
}
return $attribs;
} | [
"private",
"function",
"grabAttribsBeforeToken",
"(",
"Tokens",
"$",
"tokens",
",",
"$",
"index",
",",
"array",
"$",
"tokenAttribsMap",
",",
"array",
"$",
"attribs",
")",
"{",
"while",
"(",
"true",
")",
"{",
"$",
"token",
"=",
"$",
"tokens",
"[",
"--",
"$",
"index",
"]",
";",
"if",
"(",
"!",
"$",
"token",
"->",
"isArray",
"(",
")",
")",
"{",
"if",
"(",
"$",
"token",
"->",
"equalsAny",
"(",
"[",
"'{'",
",",
"'}'",
",",
"'('",
",",
"')'",
"]",
")",
")",
"{",
"break",
";",
"}",
"continue",
";",
"}",
"// if token is attribute",
"if",
"(",
"array_key_exists",
"(",
"$",
"token",
"->",
"getId",
"(",
")",
",",
"$",
"tokenAttribsMap",
")",
")",
"{",
"// set token attribute if token map defines attribute name for token",
"if",
"(",
"$",
"tokenAttribsMap",
"[",
"$",
"token",
"->",
"getId",
"(",
")",
"]",
")",
"{",
"$",
"attribs",
"[",
"$",
"tokenAttribsMap",
"[",
"$",
"token",
"->",
"getId",
"(",
")",
"]",
"]",
"=",
"clone",
"$",
"token",
";",
"}",
"// clear the token and whitespaces after it",
"$",
"tokens",
"[",
"$",
"index",
"]",
"->",
"clear",
"(",
")",
";",
"$",
"tokens",
"[",
"$",
"index",
"+",
"1",
"]",
"->",
"clear",
"(",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"token",
"->",
"isGivenKind",
"(",
"[",
"T_WHITESPACE",
",",
"T_COMMENT",
",",
"T_DOC_COMMENT",
"]",
")",
")",
"{",
"continue",
";",
"}",
"break",
";",
"}",
"return",
"$",
"attribs",
";",
"}"
] | Grab attributes before token at given index.
Grabbed attributes are cleared by overriding them with empty string and should be manually applied with applyTokenAttribs method.
@param Tokens $tokens Tokens collection
@param int $index token index
@param array $tokenAttribsMap token to attribute name map
@param array $attribs array of token attributes
@return array array of grabbed attributes | [
"Grab",
"attributes",
"before",
"token",
"at",
"given",
"index",
"."
] | train | https://github.com/sabre-io/cs/blob/a4c57e213bf3f5e7d6b29a2f70d1ca4b0dce6d86/lib/PublicVisibility.php#L184-L219 |
Laralum/Permissions | src/Controllers/PermissionController.php | PermissionController.store | public function store(Request $request)
{
$this->authorize('create', Permission::class);
if (str_replace(' ', '', $request->slug) != $request->slug) {
return redirect()->back()->withInput()->with('error', __('laralum_permissions::general.slug_cannot_contain_spaces'));
}
$this->validate($request, [
'name' => 'required|max:255',
'slug' => 'required|max:255|unique:laralum_permissions',
'description' => 'required|max:500',
]);
Permission::create($request->all());
return redirect()->route('laralum::permissions.index')->with('success', __('laralum_permissions::general.permission_added'));
} | php | public function store(Request $request)
{
$this->authorize('create', Permission::class);
if (str_replace(' ', '', $request->slug) != $request->slug) {
return redirect()->back()->withInput()->with('error', __('laralum_permissions::general.slug_cannot_contain_spaces'));
}
$this->validate($request, [
'name' => 'required|max:255',
'slug' => 'required|max:255|unique:laralum_permissions',
'description' => 'required|max:500',
]);
Permission::create($request->all());
return redirect()->route('laralum::permissions.index')->with('success', __('laralum_permissions::general.permission_added'));
} | [
"public",
"function",
"store",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"'create'",
",",
"Permission",
"::",
"class",
")",
";",
"if",
"(",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"request",
"->",
"slug",
")",
"!=",
"$",
"request",
"->",
"slug",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withInput",
"(",
")",
"->",
"with",
"(",
"'error'",
",",
"__",
"(",
"'laralum_permissions::general.slug_cannot_contain_spaces'",
")",
")",
";",
"}",
"$",
"this",
"->",
"validate",
"(",
"$",
"request",
",",
"[",
"'name'",
"=>",
"'required|max:255'",
",",
"'slug'",
"=>",
"'required|max:255|unique:laralum_permissions'",
",",
"'description'",
"=>",
"'required|max:500'",
",",
"]",
")",
";",
"Permission",
"::",
"create",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'laralum::permissions.index'",
")",
"->",
"with",
"(",
"'success'",
",",
"__",
"(",
"'laralum_permissions::general.permission_added'",
")",
")",
";",
"}"
] | Store a newly created resource in storage.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\Response | [
"Store",
"a",
"newly",
"created",
"resource",
"in",
"storage",
"."
] | train | https://github.com/Laralum/Permissions/blob/79970ee7d1bff816ad4b9adee29067faead3f756/src/Controllers/PermissionController.php#L51-L67 |
Laralum/Permissions | src/Controllers/PermissionController.php | PermissionController.update | public function update(Request $request, Permission $permission)
{
$this->authorize('update', Permission::class);
if (str_replace(' ', '', $request->slug) != $request->slug) {
return redirect()->back()->withInput()->with('error', __('laralum_permissions::general.slug_cannot_contain_spaces'));
}
$this->validate($request, [
'name' => 'required|max:255',
'slug' => 'required|max:255|unique:laralum_permissions,slug,'.$permission->id,
'description' => 'required|max:500',
]);
$permission->update($request->all());
return redirect()->route('laralum::permissions.index')->with('success', __('laralum_permissions::general.permission_updated', ['id' => $permission->id]));
} | php | public function update(Request $request, Permission $permission)
{
$this->authorize('update', Permission::class);
if (str_replace(' ', '', $request->slug) != $request->slug) {
return redirect()->back()->withInput()->with('error', __('laralum_permissions::general.slug_cannot_contain_spaces'));
}
$this->validate($request, [
'name' => 'required|max:255',
'slug' => 'required|max:255|unique:laralum_permissions,slug,'.$permission->id,
'description' => 'required|max:500',
]);
$permission->update($request->all());
return redirect()->route('laralum::permissions.index')->with('success', __('laralum_permissions::general.permission_updated', ['id' => $permission->id]));
} | [
"public",
"function",
"update",
"(",
"Request",
"$",
"request",
",",
"Permission",
"$",
"permission",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"'update'",
",",
"Permission",
"::",
"class",
")",
";",
"if",
"(",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"request",
"->",
"slug",
")",
"!=",
"$",
"request",
"->",
"slug",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withInput",
"(",
")",
"->",
"with",
"(",
"'error'",
",",
"__",
"(",
"'laralum_permissions::general.slug_cannot_contain_spaces'",
")",
")",
";",
"}",
"$",
"this",
"->",
"validate",
"(",
"$",
"request",
",",
"[",
"'name'",
"=>",
"'required|max:255'",
",",
"'slug'",
"=>",
"'required|max:255|unique:laralum_permissions,slug,'",
".",
"$",
"permission",
"->",
"id",
",",
"'description'",
"=>",
"'required|max:500'",
",",
"]",
")",
";",
"$",
"permission",
"->",
"update",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'laralum::permissions.index'",
")",
"->",
"with",
"(",
"'success'",
",",
"__",
"(",
"'laralum_permissions::general.permission_updated'",
",",
"[",
"'id'",
"=>",
"$",
"permission",
"->",
"id",
"]",
")",
")",
";",
"}"
] | Update the specified resource in storage.
@param \Illuminate\Http\Request $request
@param \Laralum\Permission\Models\Permission $permission
@return \Illuminate\Http\Response | [
"Update",
"the",
"specified",
"resource",
"in",
"storage",
"."
] | train | https://github.com/Laralum/Permissions/blob/79970ee7d1bff816ad4b9adee29067faead3f756/src/Controllers/PermissionController.php#L91-L107 |
Laralum/Permissions | src/Controllers/PermissionController.php | PermissionController.confirmDelete | public function confirmDelete(Permission $permission)
{
$this->authorize('delete', Permission::class);
return view('laralum::pages.confirmation', [
'method' => 'DELETE',
'action' => route('laralum::permissions.destroy', ['permission' => $permission->id]),
]);
} | php | public function confirmDelete(Permission $permission)
{
$this->authorize('delete', Permission::class);
return view('laralum::pages.confirmation', [
'method' => 'DELETE',
'action' => route('laralum::permissions.destroy', ['permission' => $permission->id]),
]);
} | [
"public",
"function",
"confirmDelete",
"(",
"Permission",
"$",
"permission",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"'delete'",
",",
"Permission",
"::",
"class",
")",
";",
"return",
"view",
"(",
"'laralum::pages.confirmation'",
",",
"[",
"'method'",
"=>",
"'DELETE'",
",",
"'action'",
"=>",
"route",
"(",
"'laralum::permissions.destroy'",
",",
"[",
"'permission'",
"=>",
"$",
"permission",
"->",
"id",
"]",
")",
",",
"]",
")",
";",
"}"
] | Displays a view to confirm delete.
@param \Laralum\Permission\Models\Permission $permission
@return \Illuminate\Http\Response | [
"Displays",
"a",
"view",
"to",
"confirm",
"delete",
"."
] | train | https://github.com/Laralum/Permissions/blob/79970ee7d1bff816ad4b9adee29067faead3f756/src/Controllers/PermissionController.php#L116-L124 |
Laralum/Permissions | src/Controllers/PermissionController.php | PermissionController.destroy | public function destroy(Request $request, Permission $permission)
{
$this->authorize('delete', Permission::class);
$permission->delete();
return redirect()->route('laralum::permissions.index')->with('success', __('laralum_permissions::general.permission_deleted', ['id' => $permission->id]));
} | php | public function destroy(Request $request, Permission $permission)
{
$this->authorize('delete', Permission::class);
$permission->delete();
return redirect()->route('laralum::permissions.index')->with('success', __('laralum_permissions::general.permission_deleted', ['id' => $permission->id]));
} | [
"public",
"function",
"destroy",
"(",
"Request",
"$",
"request",
",",
"Permission",
"$",
"permission",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"'delete'",
",",
"Permission",
"::",
"class",
")",
";",
"$",
"permission",
"->",
"delete",
"(",
")",
";",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'laralum::permissions.index'",
")",
"->",
"with",
"(",
"'success'",
",",
"__",
"(",
"'laralum_permissions::general.permission_deleted'",
",",
"[",
"'id'",
"=>",
"$",
"permission",
"->",
"id",
"]",
")",
")",
";",
"}"
] | Remove the specified resource from storage.
@param \Illuminate\Http\Request $request
@param \Laralum\Permission\Models\Permission $permission
@return \Illuminate\Http\Response | [
"Remove",
"the",
"specified",
"resource",
"from",
"storage",
"."
] | train | https://github.com/Laralum/Permissions/blob/79970ee7d1bff816ad4b9adee29067faead3f756/src/Controllers/PermissionController.php#L134-L140 |
tttptd/laravel-responder | src/Exceptions/Handler.php | Handler.render | public function render($request, Exception $exception)
{
$this->transformException($exception);
if ($exception instanceof ApiException) {
return $this->renderApiError($exception);
}
return parent::render($request, $exception);
} | php | public function render($request, Exception $exception)
{
$this->transformException($exception);
if ($exception instanceof ApiException) {
return $this->renderApiError($exception);
}
return parent::render($request, $exception);
} | [
"public",
"function",
"render",
"(",
"$",
"request",
",",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"transformException",
"(",
"$",
"exception",
")",
";",
"if",
"(",
"$",
"exception",
"instanceof",
"ApiException",
")",
"{",
"return",
"$",
"this",
"->",
"renderApiError",
"(",
"$",
"exception",
")",
";",
"}",
"return",
"parent",
"::",
"render",
"(",
"$",
"request",
",",
"$",
"exception",
")",
";",
"}"
] | Render an exception into an HTTP response.
@param \Illuminate\Http\Request $request
@param Exception $exception
@return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse | [
"Render",
"an",
"exception",
"into",
"an",
"HTTP",
"response",
"."
] | train | https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Exceptions/Handler.php#L21-L30 |
mustardandrew/muan-laravel-acl | src/Commands/Role/ViewCommand.php | ViewCommand.handle | public function handle()
{
$roleName = $this->argument('role');
if (! $role = Role::whereName($roleName)->first()) {
$this->warn("Role {$roleName} not found!");
return 1;
}
echo "Role: {$role->name} (ID = {$role->id})", PHP_EOL;
echo "Created at: {$role->created_at}", PHP_EOL;
echo "Updated at: {$role->updated_at}", PHP_EOL;
echo "Permissions:", PHP_EOL;
$data = collect($role->permissions->toArray())->map(function($item) {
unset($item['pivot']);
return $item;
});
if ($role->permissions->count()) {
$this->table(['ID', 'Permission', 'Created At', 'Updated At'], $data);
} else {
$this->warn("Not found any permissions!");
}
return 0;
} | php | public function handle()
{
$roleName = $this->argument('role');
if (! $role = Role::whereName($roleName)->first()) {
$this->warn("Role {$roleName} not found!");
return 1;
}
echo "Role: {$role->name} (ID = {$role->id})", PHP_EOL;
echo "Created at: {$role->created_at}", PHP_EOL;
echo "Updated at: {$role->updated_at}", PHP_EOL;
echo "Permissions:", PHP_EOL;
$data = collect($role->permissions->toArray())->map(function($item) {
unset($item['pivot']);
return $item;
});
if ($role->permissions->count()) {
$this->table(['ID', 'Permission', 'Created At', 'Updated At'], $data);
} else {
$this->warn("Not found any permissions!");
}
return 0;
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"roleName",
"=",
"$",
"this",
"->",
"argument",
"(",
"'role'",
")",
";",
"if",
"(",
"!",
"$",
"role",
"=",
"Role",
"::",
"whereName",
"(",
"$",
"roleName",
")",
"->",
"first",
"(",
")",
")",
"{",
"$",
"this",
"->",
"warn",
"(",
"\"Role {$roleName} not found!\"",
")",
";",
"return",
"1",
";",
"}",
"echo",
"\"Role: {$role->name} (ID = {$role->id})\"",
",",
"PHP_EOL",
";",
"echo",
"\"Created at: {$role->created_at}\"",
",",
"PHP_EOL",
";",
"echo",
"\"Updated at: {$role->updated_at}\"",
",",
"PHP_EOL",
";",
"echo",
"\"Permissions:\"",
",",
"PHP_EOL",
";",
"$",
"data",
"=",
"collect",
"(",
"$",
"role",
"->",
"permissions",
"->",
"toArray",
"(",
")",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"unset",
"(",
"$",
"item",
"[",
"'pivot'",
"]",
")",
";",
"return",
"$",
"item",
";",
"}",
")",
";",
"if",
"(",
"$",
"role",
"->",
"permissions",
"->",
"count",
"(",
")",
")",
"{",
"$",
"this",
"->",
"table",
"(",
"[",
"'ID'",
",",
"'Permission'",
",",
"'Created At'",
",",
"'Updated At'",
"]",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"warn",
"(",
"\"Not found any permissions!\"",
")",
";",
"}",
"return",
"0",
";",
"}"
] | Execute the console command.
@return mixed | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Commands/Role/ViewCommand.php#L34-L60 |
spiral-modules/listing | source/Listing/Traits/SelectorValidationTrait.php | SelectorValidationTrait.validateSelector | protected function validateSelector(PaginatorAwareInterface $selector)
{
if (!$selector instanceof RecordSelector && !$selector instanceof DocumentSelector) {
throw new InvalidSelectorException(
"Only instance of Record/Document selectors are allowed, '"
. get_class($selector) . "'"
);
}
} | php | protected function validateSelector(PaginatorAwareInterface $selector)
{
if (!$selector instanceof RecordSelector && !$selector instanceof DocumentSelector) {
throw new InvalidSelectorException(
"Only instance of Record/Document selectors are allowed, '"
. get_class($selector) . "'"
);
}
} | [
"protected",
"function",
"validateSelector",
"(",
"PaginatorAwareInterface",
"$",
"selector",
")",
"{",
"if",
"(",
"!",
"$",
"selector",
"instanceof",
"RecordSelector",
"&&",
"!",
"$",
"selector",
"instanceof",
"DocumentSelector",
")",
"{",
"throw",
"new",
"InvalidSelectorException",
"(",
"\"Only instance of Record/Document selectors are allowed, '\"",
".",
"get_class",
"(",
"$",
"selector",
")",
".",
"\"'\"",
")",
";",
"}",
"}"
] | @param PaginatorAwareInterface|RecordSelector|DocumentSelector $selector
@throws InvalidSelectorException | [
"@param",
"PaginatorAwareInterface|RecordSelector|DocumentSelector",
"$selector"
] | train | https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/Traits/SelectorValidationTrait.php#L22-L30 |
webignition/guzzle-curl-exception | src/Factory.php | Factory.fromConnectException | public static function fromConnectException(ConnectException $connectException)
{
if (!self::isCurlException($connectException)) {
return null;
}
$curlMessageParts = explode(':', $connectException->getMessage(), 2);
return new Exception(
trim($curlMessageParts[1]),
(int)preg_replace('/[^0-9]/', '', $curlMessageParts[0]),
$connectException
);
} | php | public static function fromConnectException(ConnectException $connectException)
{
if (!self::isCurlException($connectException)) {
return null;
}
$curlMessageParts = explode(':', $connectException->getMessage(), 2);
return new Exception(
trim($curlMessageParts[1]),
(int)preg_replace('/[^0-9]/', '', $curlMessageParts[0]),
$connectException
);
} | [
"public",
"static",
"function",
"fromConnectException",
"(",
"ConnectException",
"$",
"connectException",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"isCurlException",
"(",
"$",
"connectException",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"curlMessageParts",
"=",
"explode",
"(",
"':'",
",",
"$",
"connectException",
"->",
"getMessage",
"(",
")",
",",
"2",
")",
";",
"return",
"new",
"Exception",
"(",
"trim",
"(",
"$",
"curlMessageParts",
"[",
"1",
"]",
")",
",",
"(",
"int",
")",
"preg_replace",
"(",
"'/[^0-9]/'",
",",
"''",
",",
"$",
"curlMessageParts",
"[",
"0",
"]",
")",
",",
"$",
"connectException",
")",
";",
"}"
] | @param ConnectException $connectException
@return null|Exception | [
"@param",
"ConnectException",
"$connectException"
] | train | https://github.com/webignition/guzzle-curl-exception/blob/87b991140030c1e47cb1514635fa48a553ed061d/src/Factory.php#L14-L27 |
hirnsturm/typo3-exceptionhandler | TYPO3/ExceptionHandler/ProductionExceptionHandler.php | ProductionExceptionHandler.sendNotificationMail | protected function sendNotificationMail($exception)
{
// Build message
$message = array();
$message[] = 'Title: ' . $this->getTitle($exception);
$message[] = 'Message: ' . PHP_EOL . $this->getMessage($exception);
$message[] = 'Server name: ' . filter_input(INPUT_SERVER, 'SERVER_NAME');
$message[] = 'Request URI: ' . PHP_EOL
. filter_input(INPUT_SERVER, 'SERVER_NAME')
. filter_input(INPUT_SERVER, 'REQUEST_URI');
$message[] = 'Request-Info: ' . PHP_EOL . print_r(filter_input_array(INPUT_SERVER), true);
$message[] = 'POST: ' . PHP_EOL . print_r(filter_input_array(INPUT_POST), true);
$message[] = 'GET: ' . PHP_EOL . print_r(filter_input_array(INPUT_GET), true);
try {
/** @var \TYPO3\CMS\Core\Mail\MailMessage $mail */
$mail = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
$mail->setFrom(MailUtility::getSystemFrom())
->setTo(array($GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr']))
->setSubject(MailUtility::getSystemFromName() . ' - ' . $this->getTitle($exception))
->setBody(implode(PHP_EOL . PHP_EOL, $message))
->send();
} catch (\Exception $e) {
/** @var $logger \TYPO3\CMS\Core\Log\Logger */
$logger = GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
$logger->error('Could not send exception message to system admin!', array($e->__toString()));
}
} | php | protected function sendNotificationMail($exception)
{
// Build message
$message = array();
$message[] = 'Title: ' . $this->getTitle($exception);
$message[] = 'Message: ' . PHP_EOL . $this->getMessage($exception);
$message[] = 'Server name: ' . filter_input(INPUT_SERVER, 'SERVER_NAME');
$message[] = 'Request URI: ' . PHP_EOL
. filter_input(INPUT_SERVER, 'SERVER_NAME')
. filter_input(INPUT_SERVER, 'REQUEST_URI');
$message[] = 'Request-Info: ' . PHP_EOL . print_r(filter_input_array(INPUT_SERVER), true);
$message[] = 'POST: ' . PHP_EOL . print_r(filter_input_array(INPUT_POST), true);
$message[] = 'GET: ' . PHP_EOL . print_r(filter_input_array(INPUT_GET), true);
try {
/** @var \TYPO3\CMS\Core\Mail\MailMessage $mail */
$mail = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
$mail->setFrom(MailUtility::getSystemFrom())
->setTo(array($GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr']))
->setSubject(MailUtility::getSystemFromName() . ' - ' . $this->getTitle($exception))
->setBody(implode(PHP_EOL . PHP_EOL, $message))
->send();
} catch (\Exception $e) {
/** @var $logger \TYPO3\CMS\Core\Log\Logger */
$logger = GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
$logger->error('Could not send exception message to system admin!', array($e->__toString()));
}
} | [
"protected",
"function",
"sendNotificationMail",
"(",
"$",
"exception",
")",
"{",
"// Build message",
"$",
"message",
"=",
"array",
"(",
")",
";",
"$",
"message",
"[",
"]",
"=",
"'Title: '",
".",
"$",
"this",
"->",
"getTitle",
"(",
"$",
"exception",
")",
";",
"$",
"message",
"[",
"]",
"=",
"'Message: '",
".",
"PHP_EOL",
".",
"$",
"this",
"->",
"getMessage",
"(",
"$",
"exception",
")",
";",
"$",
"message",
"[",
"]",
"=",
"'Server name: '",
".",
"filter_input",
"(",
"INPUT_SERVER",
",",
"'SERVER_NAME'",
")",
";",
"$",
"message",
"[",
"]",
"=",
"'Request URI: '",
".",
"PHP_EOL",
".",
"filter_input",
"(",
"INPUT_SERVER",
",",
"'SERVER_NAME'",
")",
".",
"filter_input",
"(",
"INPUT_SERVER",
",",
"'REQUEST_URI'",
")",
";",
"$",
"message",
"[",
"]",
"=",
"'Request-Info: '",
".",
"PHP_EOL",
".",
"print_r",
"(",
"filter_input_array",
"(",
"INPUT_SERVER",
")",
",",
"true",
")",
";",
"$",
"message",
"[",
"]",
"=",
"'POST: '",
".",
"PHP_EOL",
".",
"print_r",
"(",
"filter_input_array",
"(",
"INPUT_POST",
")",
",",
"true",
")",
";",
"$",
"message",
"[",
"]",
"=",
"'GET: '",
".",
"PHP_EOL",
".",
"print_r",
"(",
"filter_input_array",
"(",
"INPUT_GET",
")",
",",
"true",
")",
";",
"try",
"{",
"/** @var \\TYPO3\\CMS\\Core\\Mail\\MailMessage $mail */",
"$",
"mail",
"=",
"GeneralUtility",
"::",
"makeInstance",
"(",
"'TYPO3\\\\CMS\\\\Core\\\\Mail\\\\MailMessage'",
")",
";",
"$",
"mail",
"->",
"setFrom",
"(",
"MailUtility",
"::",
"getSystemFrom",
"(",
")",
")",
"->",
"setTo",
"(",
"array",
"(",
"$",
"GLOBALS",
"[",
"'TYPO3_CONF_VARS'",
"]",
"[",
"'BE'",
"]",
"[",
"'warning_email_addr'",
"]",
")",
")",
"->",
"setSubject",
"(",
"MailUtility",
"::",
"getSystemFromName",
"(",
")",
".",
"' - '",
".",
"$",
"this",
"->",
"getTitle",
"(",
"$",
"exception",
")",
")",
"->",
"setBody",
"(",
"implode",
"(",
"PHP_EOL",
".",
"PHP_EOL",
",",
"$",
"message",
")",
")",
"->",
"send",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"/** @var $logger \\TYPO3\\CMS\\Core\\Log\\Logger */",
"$",
"logger",
"=",
"GeneralUtility",
"::",
"makeInstance",
"(",
"'TYPO3\\CMS\\Core\\Log\\LogManager'",
")",
"->",
"getLogger",
"(",
"__CLASS__",
")",
";",
"$",
"logger",
"->",
"error",
"(",
"'Could not send exception message to system admin!'",
",",
"array",
"(",
"$",
"e",
"->",
"__toString",
"(",
")",
")",
")",
";",
"}",
"}"
] | Sends an exception as notification e-mail
@param $exception | [
"Sends",
"an",
"exception",
"as",
"notification",
"e",
"-",
"mail"
] | train | https://github.com/hirnsturm/typo3-exceptionhandler/blob/268c3f3269d39b238d6fa1b39d8fbae3f0d5921d/TYPO3/ExceptionHandler/ProductionExceptionHandler.php#L33-L60 |
nikolaposa/ZfOpenGraph | src/ZfOpenGraph/View/Helper/HeadMeta.php | HeadMeta.isValid | protected function isValid($item)
{
if ((!$item instanceof stdClass)
|| !isset($item->type)
|| !isset($item->modifiers)
) {
return false;
}
if ($this->doctypeValidationEnabled) {
if (!isset($item->content)
&& (! $this->view->plugin('doctype')->isHtml5()
|| (! $this->view->plugin('doctype')->isHtml5() && $item->type !== 'charset'))
) {
return false;
}
// <meta itemprop= ... /> is only supported with doctype html
if (! $this->view->plugin('doctype')->isHtml5()
&& $item->type === 'itemprop'
) {
return false;
}
// <meta property= ... /> is only supported with doctype RDFa
if (!$this->view->plugin('doctype')->isRdfa()
&& $item->type === 'property'
) {
return false;
}
}
return true;
} | php | protected function isValid($item)
{
if ((!$item instanceof stdClass)
|| !isset($item->type)
|| !isset($item->modifiers)
) {
return false;
}
if ($this->doctypeValidationEnabled) {
if (!isset($item->content)
&& (! $this->view->plugin('doctype')->isHtml5()
|| (! $this->view->plugin('doctype')->isHtml5() && $item->type !== 'charset'))
) {
return false;
}
// <meta itemprop= ... /> is only supported with doctype html
if (! $this->view->plugin('doctype')->isHtml5()
&& $item->type === 'itemprop'
) {
return false;
}
// <meta property= ... /> is only supported with doctype RDFa
if (!$this->view->plugin('doctype')->isRdfa()
&& $item->type === 'property'
) {
return false;
}
}
return true;
} | [
"protected",
"function",
"isValid",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"(",
"!",
"$",
"item",
"instanceof",
"stdClass",
")",
"||",
"!",
"isset",
"(",
"$",
"item",
"->",
"type",
")",
"||",
"!",
"isset",
"(",
"$",
"item",
"->",
"modifiers",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"doctypeValidationEnabled",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"->",
"content",
")",
"&&",
"(",
"!",
"$",
"this",
"->",
"view",
"->",
"plugin",
"(",
"'doctype'",
")",
"->",
"isHtml5",
"(",
")",
"||",
"(",
"!",
"$",
"this",
"->",
"view",
"->",
"plugin",
"(",
"'doctype'",
")",
"->",
"isHtml5",
"(",
")",
"&&",
"$",
"item",
"->",
"type",
"!==",
"'charset'",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"// <meta itemprop= ... /> is only supported with doctype html",
"if",
"(",
"!",
"$",
"this",
"->",
"view",
"->",
"plugin",
"(",
"'doctype'",
")",
"->",
"isHtml5",
"(",
")",
"&&",
"$",
"item",
"->",
"type",
"===",
"'itemprop'",
")",
"{",
"return",
"false",
";",
"}",
"// <meta property= ... /> is only supported with doctype RDFa",
"if",
"(",
"!",
"$",
"this",
"->",
"view",
"->",
"plugin",
"(",
"'doctype'",
")",
"->",
"isRdfa",
"(",
")",
"&&",
"$",
"item",
"->",
"type",
"===",
"'property'",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Determine if item is valid
@param mixed $item
@return bool | [
"Determine",
"if",
"item",
"is",
"valid"
] | train | https://github.com/nikolaposa/ZfOpenGraph/blob/5e1a9b6ff8d2e149dc9d949635f39786f6acc347/src/ZfOpenGraph/View/Helper/HeadMeta.php#L52-L85 |
arndtteunissen/column-layout | Classes/ViewHelpers/ColumnWrapViewHelper.php | ColumnWrapViewHelper.renderStatic | public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
if (isset($GLOBALS['TX_COLUMN_LAYOUT']['enabled']) && $GLOBALS['TX_COLUMN_LAYOUT']['enabled']) {
return self::wrapContent($arguments, $renderChildrenClosure);
} else {
return $renderChildrenClosure();
}
} | php | public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
if (isset($GLOBALS['TX_COLUMN_LAYOUT']['enabled']) && $GLOBALS['TX_COLUMN_LAYOUT']['enabled']) {
return self::wrapContent($arguments, $renderChildrenClosure);
} else {
return $renderChildrenClosure();
}
} | [
"public",
"static",
"function",
"renderStatic",
"(",
"array",
"$",
"arguments",
",",
"\\",
"Closure",
"$",
"renderChildrenClosure",
",",
"RenderingContextInterface",
"$",
"renderingContext",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'TX_COLUMN_LAYOUT'",
"]",
"[",
"'enabled'",
"]",
")",
"&&",
"$",
"GLOBALS",
"[",
"'TX_COLUMN_LAYOUT'",
"]",
"[",
"'enabled'",
"]",
")",
"{",
"return",
"self",
"::",
"wrapContent",
"(",
"$",
"arguments",
",",
"$",
"renderChildrenClosure",
")",
";",
"}",
"else",
"{",
"return",
"$",
"renderChildrenClosure",
"(",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/arndtteunissen/column-layout/blob/ad737068eef3b084d4d0e3a48e6a3d8277af9560/Classes/ViewHelpers/ColumnWrapViewHelper.php#L60-L67 |
josh-taylor/migrations-generator | src/Describer.php | Describer.describe | public function describe($table)
{
$schema = $this->db->connection()
->getDoctrineConnection()
->getSchemaManager();
return $this->parseSchema(
$schema->listTableColumns($table)
);
} | php | public function describe($table)
{
$schema = $this->db->connection()
->getDoctrineConnection()
->getSchemaManager();
return $this->parseSchema(
$schema->listTableColumns($table)
);
} | [
"public",
"function",
"describe",
"(",
"$",
"table",
")",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"db",
"->",
"connection",
"(",
")",
"->",
"getDoctrineConnection",
"(",
")",
"->",
"getSchemaManager",
"(",
")",
";",
"return",
"$",
"this",
"->",
"parseSchema",
"(",
"$",
"schema",
"->",
"listTableColumns",
"(",
"$",
"table",
")",
")",
";",
"}"
] | Describe all columns in a single table
@param string $table
@return array | [
"Describe",
"all",
"columns",
"in",
"a",
"single",
"table"
] | train | https://github.com/josh-taylor/migrations-generator/blob/bb6edc78773d11491881f12265a658bf058cb218/src/Describer.php#L32-L41 |
josh-taylor/migrations-generator | src/Describer.php | Describer.parseSchema | protected function parseSchema(array $columns)
{
$schema = [];
foreach ($columns as $name => $column) {
$schema[] = [
'name' => $column->getName(),
'type' => $column->getType()->getName()
];
}
return $schema;
} | php | protected function parseSchema(array $columns)
{
$schema = [];
foreach ($columns as $name => $column) {
$schema[] = [
'name' => $column->getName(),
'type' => $column->getType()->getName()
];
}
return $schema;
} | [
"protected",
"function",
"parseSchema",
"(",
"array",
"$",
"columns",
")",
"{",
"$",
"schema",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"name",
"=>",
"$",
"column",
")",
"{",
"$",
"schema",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"column",
"->",
"getName",
"(",
")",
",",
"'type'",
"=>",
"$",
"column",
"->",
"getType",
"(",
")",
"->",
"getName",
"(",
")",
"]",
";",
"}",
"return",
"$",
"schema",
";",
"}"
] | Convert the DBAL schema to an assoc array.
@param array $columns
@return array | [
"Convert",
"the",
"DBAL",
"schema",
"to",
"an",
"assoc",
"array",
"."
] | train | https://github.com/josh-taylor/migrations-generator/blob/bb6edc78773d11491881f12265a658bf058cb218/src/Describer.php#L49-L61 |
heidelpay/PhpDoc | src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Property/HasSummaryValidator.php | HasSummaryValidator.validate | public function validate($value, Constraint $constraint)
{
if (! $value instanceof PropertyDescriptor) {
throw new ConstraintDefinitionException(
'The Property\HasSummary validator may only be used on property objects'
);
}
$var = $value->getVar();
if (! $value->getSummary() && ($var->count() == 0 || ! current($var->getAll())->getDescription())) {
$this->context->addViolationAt('summary', $constraint->message, array(), null, null, $constraint->code);
}
} | php | public function validate($value, Constraint $constraint)
{
if (! $value instanceof PropertyDescriptor) {
throw new ConstraintDefinitionException(
'The Property\HasSummary validator may only be used on property objects'
);
}
$var = $value->getVar();
if (! $value->getSummary() && ($var->count() == 0 || ! current($var->getAll())->getDescription())) {
$this->context->addViolationAt('summary', $constraint->message, array(), null, null, $constraint->code);
}
} | [
"public",
"function",
"validate",
"(",
"$",
"value",
",",
"Constraint",
"$",
"constraint",
")",
"{",
"if",
"(",
"!",
"$",
"value",
"instanceof",
"PropertyDescriptor",
")",
"{",
"throw",
"new",
"ConstraintDefinitionException",
"(",
"'The Property\\HasSummary validator may only be used on property objects'",
")",
";",
"}",
"$",
"var",
"=",
"$",
"value",
"->",
"getVar",
"(",
")",
";",
"if",
"(",
"!",
"$",
"value",
"->",
"getSummary",
"(",
")",
"&&",
"(",
"$",
"var",
"->",
"count",
"(",
")",
"==",
"0",
"||",
"!",
"current",
"(",
"$",
"var",
"->",
"getAll",
"(",
")",
")",
"->",
"getDescription",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"context",
"->",
"addViolationAt",
"(",
"'summary'",
",",
"$",
"constraint",
"->",
"message",
",",
"array",
"(",
")",
",",
"null",
",",
"null",
",",
"$",
"constraint",
"->",
"code",
")",
";",
"}",
"}"
] | Checks if the passed value is valid.
@param PropertyDescriptor $value The value that should be validated
@param Constraint $constraint The constraint for the validation
@throws ConstraintDefinitionException if this is not a constraint on a PropertyDescriptor object. | [
"Checks",
"if",
"the",
"passed",
"value",
"is",
"valid",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Property/HasSummaryValidator.php#L31-L43 |
traderinteractive/filter-arrays-php | src/Arrays.php | Arrays.filter | public static function filter($value, int $minCount = 1, int $maxCount = PHP_INT_MAX) : array
{
if (!is_array($value)) {
throw new FilterException("Value '" . trim(var_export($value, true), "'") . "' is not an array");
}
$count = count($value);
if ($count < $minCount) {
throw new FilterException("\$value count of {$count} is less than {$minCount}");
}
if ($count > $maxCount) {
throw new FilterException("\$value count of {$count} is greater than {$maxCount}");
}
return $value;
} | php | public static function filter($value, int $minCount = 1, int $maxCount = PHP_INT_MAX) : array
{
if (!is_array($value)) {
throw new FilterException("Value '" . trim(var_export($value, true), "'") . "' is not an array");
}
$count = count($value);
if ($count < $minCount) {
throw new FilterException("\$value count of {$count} is less than {$minCount}");
}
if ($count > $maxCount) {
throw new FilterException("\$value count of {$count} is greater than {$maxCount}");
}
return $value;
} | [
"public",
"static",
"function",
"filter",
"(",
"$",
"value",
",",
"int",
"$",
"minCount",
"=",
"1",
",",
"int",
"$",
"maxCount",
"=",
"PHP_INT_MAX",
")",
":",
"array",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"FilterException",
"(",
"\"Value '\"",
".",
"trim",
"(",
"var_export",
"(",
"$",
"value",
",",
"true",
")",
",",
"\"'\"",
")",
".",
"\"' is not an array\"",
")",
";",
"}",
"$",
"count",
"=",
"count",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"count",
"<",
"$",
"minCount",
")",
"{",
"throw",
"new",
"FilterException",
"(",
"\"\\$value count of {$count} is less than {$minCount}\"",
")",
";",
"}",
"if",
"(",
"$",
"count",
">",
"$",
"maxCount",
")",
"{",
"throw",
"new",
"FilterException",
"(",
"\"\\$value count of {$count} is greater than {$maxCount}\"",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Filter an array by throwing if not an array or count not in the min/max range.
@param mixed $value The value to filter.
@param integer $minCount The minimum allowed count in the array.
@param integer $maxCount The maximum allowed count in the array.
@return array
@throws FilterException if $value is not an array
@throws FilterException if $value count is less than $minCount
@throws FilterException if $value count is greater than $maxCount | [
"Filter",
"an",
"array",
"by",
"throwing",
"if",
"not",
"an",
"array",
"or",
"count",
"not",
"in",
"the",
"min",
"/",
"max",
"range",
"."
] | train | https://github.com/traderinteractive/filter-arrays-php/blob/8958109f3e10e6c37fcc6c7c4830d9bcba3ed222/src/Arrays.php#L25-L41 |
traderinteractive/filter-arrays-php | src/Arrays.php | Arrays.in | public static function in($value, array $haystack, bool $strict = true)
{
if (!in_array($value, $haystack, $strict)) {
throw new FilterException(
"Value '" . trim(var_export($value, true), "'") . "' is not in array " . var_export($haystack, true)
);
}
return $value;
} | php | public static function in($value, array $haystack, bool $strict = true)
{
if (!in_array($value, $haystack, $strict)) {
throw new FilterException(
"Value '" . trim(var_export($value, true), "'") . "' is not in array " . var_export($haystack, true)
);
}
return $value;
} | [
"public",
"static",
"function",
"in",
"(",
"$",
"value",
",",
"array",
"$",
"haystack",
",",
"bool",
"$",
"strict",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"haystack",
",",
"$",
"strict",
")",
")",
"{",
"throw",
"new",
"FilterException",
"(",
"\"Value '\"",
".",
"trim",
"(",
"var_export",
"(",
"$",
"value",
",",
"true",
")",
",",
"\"'\"",
")",
".",
"\"' is not in array \"",
".",
"var_export",
"(",
"$",
"haystack",
",",
"true",
")",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Filter an array by throwing if $value is not in $haystack adhering to $strict.
@param mixed $value The searched value.
@param array $haystack The array to be searched.
@param bool $strict Flag to compare strictly or not. @see in_array()
@return mixed The passed in value
@throws FilterException if $value is not in array $haystack | [
"Filter",
"an",
"array",
"by",
"throwing",
"if",
"$value",
"is",
"not",
"in",
"$haystack",
"adhering",
"to",
"$strict",
"."
] | train | https://github.com/traderinteractive/filter-arrays-php/blob/8958109f3e10e6c37fcc6c7c4830d9bcba3ed222/src/Arrays.php#L54-L63 |
traderinteractive/filter-arrays-php | src/Arrays.php | Arrays.flatten | public static function flatten(array $value) : array
{
$result = [];
array_walk_recursive(
$value,
function ($item) use (&$result) {
$result[] = $item;
}
);
return $result;
} | php | public static function flatten(array $value) : array
{
$result = [];
array_walk_recursive(
$value,
function ($item) use (&$result) {
$result[] = $item;
}
);
return $result;
} | [
"public",
"static",
"function",
"flatten",
"(",
"array",
"$",
"value",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"array_walk_recursive",
"(",
"$",
"value",
",",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"&",
"$",
"result",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"item",
";",
"}",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Given a multi-dimensional array, flatten the array to a single level.
The order of the values will be maintained, but the keys will not.
For example, given the array [[1, 2], [3, [4, 5]]], this would result in the array [1, 2, 3, 4, 5].
@param array $value The array to flatten.
@return array The single-dimension array. | [
"Given",
"a",
"multi",
"-",
"dimensional",
"array",
"flatten",
"the",
"array",
"to",
"a",
"single",
"level",
"."
] | train | https://github.com/traderinteractive/filter-arrays-php/blob/8958109f3e10e6c37fcc6c7c4830d9bcba3ed222/src/Arrays.php#L76-L88 |
fabulator/fitbit-api-base | lib/Fabulator/Fitbit/FitbitApiBase.php | FitbitApiBase.getLoginUrl | public function getLoginUrl(
$redirectUri,
$scope,
$responseType = 'code',
$expiresIn = null,
$prompt = 'none',
$state = null)
{
$parameters = [
'response_type' => $responseType,
'client_id' => $this->clientId,
'redirect_uri' => $redirectUri,
'scope' => join(' ', $scope),
'prompt' => $prompt,
];
if ($expiresIn !== null) {
$parameters['expires_in'] = $expiresIn;
}
if ($state !== null) {
$parameters['state'] = $state;
}
return self::FITBIT_OAUTH_URL . '?' . http_build_query($parameters);
} | php | public function getLoginUrl(
$redirectUri,
$scope,
$responseType = 'code',
$expiresIn = null,
$prompt = 'none',
$state = null)
{
$parameters = [
'response_type' => $responseType,
'client_id' => $this->clientId,
'redirect_uri' => $redirectUri,
'scope' => join(' ', $scope),
'prompt' => $prompt,
];
if ($expiresIn !== null) {
$parameters['expires_in'] = $expiresIn;
}
if ($state !== null) {
$parameters['state'] = $state;
}
return self::FITBIT_OAUTH_URL . '?' . http_build_query($parameters);
} | [
"public",
"function",
"getLoginUrl",
"(",
"$",
"redirectUri",
",",
"$",
"scope",
",",
"$",
"responseType",
"=",
"'code'",
",",
"$",
"expiresIn",
"=",
"null",
",",
"$",
"prompt",
"=",
"'none'",
",",
"$",
"state",
"=",
"null",
")",
"{",
"$",
"parameters",
"=",
"[",
"'response_type'",
"=>",
"$",
"responseType",
",",
"'client_id'",
"=>",
"$",
"this",
"->",
"clientId",
",",
"'redirect_uri'",
"=>",
"$",
"redirectUri",
",",
"'scope'",
"=>",
"join",
"(",
"' '",
",",
"$",
"scope",
")",
",",
"'prompt'",
"=>",
"$",
"prompt",
",",
"]",
";",
"if",
"(",
"$",
"expiresIn",
"!==",
"null",
")",
"{",
"$",
"parameters",
"[",
"'expires_in'",
"]",
"=",
"$",
"expiresIn",
";",
"}",
"if",
"(",
"$",
"state",
"!==",
"null",
")",
"{",
"$",
"parameters",
"[",
"'state'",
"]",
"=",
"$",
"state",
";",
"}",
"return",
"self",
"::",
"FITBIT_OAUTH_URL",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"parameters",
")",
";",
"}"
] | Login url for users
https://dev.fitbit.com/docs/oauth2/#authorization-page
@param string $redirectUri Where will be user redirected
@param array(activity, heartrate, location, nutrition, profile, settings, sleep, social, weight) $scope Array of scopes you require
@param string(code, token) $responseType type of Fitbit response
@param null|int $expiresIn Only for token response - time in sec
@param string(none|consent|login|login consent) $prompt type of user authorization
@param null|string $state This parameter will be added to the redirect URI exactly as your application specifies.
@return string url | [
"Login",
"url",
"for",
"users",
"https",
":",
"//",
"dev",
".",
"fitbit",
".",
"com",
"/",
"docs",
"/",
"oauth2",
"/",
"#authorization",
"-",
"page"
] | train | https://github.com/fabulator/fitbit-api-base/blob/c2ef868796f991586fe227a659553f304994bdd9/lib/Fabulator/Fitbit/FitbitApiBase.php#L75-L100 |
fabulator/fitbit-api-base | lib/Fabulator/Fitbit/FitbitApiBase.php | FitbitApiBase.requestAccessToken | public function requestAccessToken($code, $redirectUri, $expiresIn = null, $state = null)
{
$parameters = [
'code' => $code,
'grant_type' => 'authorization_code',
'client_id' => $this->clientId,
'redirect_uri' => $redirectUri,
];
if ($expiresIn != null) {
$parameters['expires_in'] = $expiresIn;
}
if ($state != null) {
$parameters['state'] = $state;
}
return $this->tokenRequest('oauth2/token', $parameters);
} | php | public function requestAccessToken($code, $redirectUri, $expiresIn = null, $state = null)
{
$parameters = [
'code' => $code,
'grant_type' => 'authorization_code',
'client_id' => $this->clientId,
'redirect_uri' => $redirectUri,
];
if ($expiresIn != null) {
$parameters['expires_in'] = $expiresIn;
}
if ($state != null) {
$parameters['state'] = $state;
}
return $this->tokenRequest('oauth2/token', $parameters);
} | [
"public",
"function",
"requestAccessToken",
"(",
"$",
"code",
",",
"$",
"redirectUri",
",",
"$",
"expiresIn",
"=",
"null",
",",
"$",
"state",
"=",
"null",
")",
"{",
"$",
"parameters",
"=",
"[",
"'code'",
"=>",
"$",
"code",
",",
"'grant_type'",
"=>",
"'authorization_code'",
",",
"'client_id'",
"=>",
"$",
"this",
"->",
"clientId",
",",
"'redirect_uri'",
"=>",
"$",
"redirectUri",
",",
"]",
";",
"if",
"(",
"$",
"expiresIn",
"!=",
"null",
")",
"{",
"$",
"parameters",
"[",
"'expires_in'",
"]",
"=",
"$",
"expiresIn",
";",
"}",
"if",
"(",
"$",
"state",
"!=",
"null",
")",
"{",
"$",
"parameters",
"[",
"'state'",
"]",
"=",
"$",
"state",
";",
"}",
"return",
"$",
"this",
"->",
"tokenRequest",
"(",
"'oauth2/token'",
",",
"$",
"parameters",
")",
";",
"}"
] | Request new Fitbit access token.
@param string $code code from Fitbit
@param string $redirectUri redirect uri used to get code
@param int|null $expiresIn set length of token
@param string|null $state This parameter will be added to the redirect URI exactly as your application specifies.
@return ResponseInterface response from Fitbit API | [
"Request",
"new",
"Fitbit",
"access",
"token",
"."
] | train | https://github.com/fabulator/fitbit-api-base/blob/c2ef868796f991586fe227a659553f304994bdd9/lib/Fabulator/Fitbit/FitbitApiBase.php#L111-L129 |
fabulator/fitbit-api-base | lib/Fabulator/Fitbit/FitbitApiBase.php | FitbitApiBase.refreshAccessToken | public function refreshAccessToken($refreshToken, $expiresIn = null)
{
$parameters = [
'grant_type' => 'refresh_token',
'refresh_token' => $refreshToken,
];
if ($expiresIn != null) {
$parameters['expires_in'] = $expiresIn;
}
return $this->tokenRequest('oauth2/token', $parameters);
} | php | public function refreshAccessToken($refreshToken, $expiresIn = null)
{
$parameters = [
'grant_type' => 'refresh_token',
'refresh_token' => $refreshToken,
];
if ($expiresIn != null) {
$parameters['expires_in'] = $expiresIn;
}
return $this->tokenRequest('oauth2/token', $parameters);
} | [
"public",
"function",
"refreshAccessToken",
"(",
"$",
"refreshToken",
",",
"$",
"expiresIn",
"=",
"null",
")",
"{",
"$",
"parameters",
"=",
"[",
"'grant_type'",
"=>",
"'refresh_token'",
",",
"'refresh_token'",
"=>",
"$",
"refreshToken",
",",
"]",
";",
"if",
"(",
"$",
"expiresIn",
"!=",
"null",
")",
"{",
"$",
"parameters",
"[",
"'expires_in'",
"]",
"=",
"$",
"expiresIn",
";",
"}",
"return",
"$",
"this",
"->",
"tokenRequest",
"(",
"'oauth2/token'",
",",
"$",
"parameters",
")",
";",
"}"
] | Refresh Fitbit token.
@param string $refreshToken refresh token
@param int|null $expiresIn set length of token
@return ResponseInterface response from Fitbit API | [
"Refresh",
"Fitbit",
"token",
"."
] | train | https://github.com/fabulator/fitbit-api-base/blob/c2ef868796f991586fe227a659553f304994bdd9/lib/Fabulator/Fitbit/FitbitApiBase.php#L138-L150 |
fabulator/fitbit-api-base | lib/Fabulator/Fitbit/FitbitApiBase.php | FitbitApiBase.tokenRequest | private function tokenRequest($namespace, $parameters)
{
$client = new Client([
'headers' => [
'content-type' => 'application/x-www-form-urlencoded',
'Authorization' => 'Basic '. base64_encode($this->clientId . ':' . $this->secret),
]
]);
return $client->post(self::FITBIT_API_URL . $namespace . '?' . http_build_query($parameters));
} | php | private function tokenRequest($namespace, $parameters)
{
$client = new Client([
'headers' => [
'content-type' => 'application/x-www-form-urlencoded',
'Authorization' => 'Basic '. base64_encode($this->clientId . ':' . $this->secret),
]
]);
return $client->post(self::FITBIT_API_URL . $namespace . '?' . http_build_query($parameters));
} | [
"private",
"function",
"tokenRequest",
"(",
"$",
"namespace",
",",
"$",
"parameters",
")",
"{",
"$",
"client",
"=",
"new",
"Client",
"(",
"[",
"'headers'",
"=>",
"[",
"'content-type'",
"=>",
"'application/x-www-form-urlencoded'",
",",
"'Authorization'",
"=>",
"'Basic '",
".",
"base64_encode",
"(",
"$",
"this",
"->",
"clientId",
".",
"':'",
".",
"$",
"this",
"->",
"secret",
")",
",",
"]",
"]",
")",
";",
"return",
"$",
"client",
"->",
"post",
"(",
"self",
"::",
"FITBIT_API_URL",
".",
"$",
"namespace",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"parameters",
")",
")",
";",
"}"
] | Request token action.
@param string $namespace namespace of request
@param array $parameters request parameters
@return ResponseInterface response from Fitbit API | [
"Request",
"token",
"action",
"."
] | train | https://github.com/fabulator/fitbit-api-base/blob/c2ef868796f991586fe227a659553f304994bdd9/lib/Fabulator/Fitbit/FitbitApiBase.php#L174-L184 |
fabulator/fitbit-api-base | lib/Fabulator/Fitbit/FitbitApiBase.php | FitbitApiBase.send | public function send($url, $method = 'GET', $data = [])
{
$method = strtolower($method);
$settings = [
'headers' => array_merge([
'Authorization' => 'Bearer ' . $this->getToken(),
'Content-Type' => 'application/x-www-form-urlencoded',
], $this->getHeaders()),
];
if ($method == 'post') {
$settings['form_params'] = $data;
}
return $this->client
->$method($url, $settings);
} | php | public function send($url, $method = 'GET', $data = [])
{
$method = strtolower($method);
$settings = [
'headers' => array_merge([
'Authorization' => 'Bearer ' . $this->getToken(),
'Content-Type' => 'application/x-www-form-urlencoded',
], $this->getHeaders()),
];
if ($method == 'post') {
$settings['form_params'] = $data;
}
return $this->client
->$method($url, $settings);
} | [
"public",
"function",
"send",
"(",
"$",
"url",
",",
"$",
"method",
"=",
"'GET'",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"method",
"=",
"strtolower",
"(",
"$",
"method",
")",
";",
"$",
"settings",
"=",
"[",
"'headers'",
"=>",
"array_merge",
"(",
"[",
"'Authorization'",
"=>",
"'Bearer '",
".",
"$",
"this",
"->",
"getToken",
"(",
")",
",",
"'Content-Type'",
"=>",
"'application/x-www-form-urlencoded'",
",",
"]",
",",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
",",
"]",
";",
"if",
"(",
"$",
"method",
"==",
"'post'",
")",
"{",
"$",
"settings",
"[",
"'form_params'",
"]",
"=",
"$",
"data",
";",
"}",
"return",
"$",
"this",
"->",
"client",
"->",
"$",
"method",
"(",
"$",
"url",
",",
"$",
"settings",
")",
";",
"}"
] | Send authorized request to Fitbit API.
@param string $url called url
@param string $method http method
@param array $data data in body
@return ResponseInterface response from Fitbit API | [
"Send",
"authorized",
"request",
"to",
"Fitbit",
"API",
"."
] | train | https://github.com/fabulator/fitbit-api-base/blob/c2ef868796f991586fe227a659553f304994bdd9/lib/Fabulator/Fitbit/FitbitApiBase.php#L239-L256 |
php-lug/lug | src/Component/Grid/DataSource/Doctrine/MongoDB/ExpressionBuilder.php | ExpressionBuilder.notLike | public function notLike($x, $y)
{
return $this->field($x)->not($this->convertLikeToRegex($y));
} | php | public function notLike($x, $y)
{
return $this->field($x)->not($this->convertLikeToRegex($y));
} | [
"public",
"function",
"notLike",
"(",
"$",
"x",
",",
"$",
"y",
")",
"{",
"return",
"$",
"this",
"->",
"field",
"(",
"$",
"x",
")",
"->",
"not",
"(",
"$",
"this",
"->",
"convertLikeToRegex",
"(",
"$",
"y",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/DataSource/Doctrine/MongoDB/ExpressionBuilder.php#L179-L182 |
php-lug/lug | src/Component/Grid/DataSource/Doctrine/MongoDB/ExpressionBuilder.php | ExpressionBuilder.between | public function between($value, $x, $y)
{
return $this->andX([
$this->gte($value, $x),
$this->lte($value, $y),
]);
} | php | public function between($value, $x, $y)
{
return $this->andX([
$this->gte($value, $x),
$this->lte($value, $y),
]);
} | [
"public",
"function",
"between",
"(",
"$",
"value",
",",
"$",
"x",
",",
"$",
"y",
")",
"{",
"return",
"$",
"this",
"->",
"andX",
"(",
"[",
"$",
"this",
"->",
"gte",
"(",
"$",
"value",
",",
"$",
"x",
")",
",",
"$",
"this",
"->",
"lte",
"(",
"$",
"value",
",",
"$",
"y",
")",
",",
"]",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/DataSource/Doctrine/MongoDB/ExpressionBuilder.php#L187-L193 |
php-lug/lug | src/Component/Grid/DataSource/Doctrine/MongoDB/ExpressionBuilder.php | ExpressionBuilder.notBetween | public function notBetween($value, $x, $y)
{
return $this->orX([
$this->lt($value, $x),
$this->gt($value, $y),
]);
} | php | public function notBetween($value, $x, $y)
{
return $this->orX([
$this->lt($value, $x),
$this->gt($value, $y),
]);
} | [
"public",
"function",
"notBetween",
"(",
"$",
"value",
",",
"$",
"x",
",",
"$",
"y",
")",
"{",
"return",
"$",
"this",
"->",
"orX",
"(",
"[",
"$",
"this",
"->",
"lt",
"(",
"$",
"value",
",",
"$",
"x",
")",
",",
"$",
"this",
"->",
"gt",
"(",
"$",
"value",
",",
"$",
"y",
")",
",",
"]",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/DataSource/Doctrine/MongoDB/ExpressionBuilder.php#L198-L204 |
php-lug/lug | src/Component/Grid/DataSource/Doctrine/MongoDB/ExpressionBuilder.php | ExpressionBuilder.convertLikeToRegex | private function convertLikeToRegex($x)
{
$x = preg_quote($x);
$pattern = '.*?';
$regex = null;
if (strpos($x, $like = '%') === 0) {
$regex .= $pattern;
$x = substr($x, 1);
}
if (strrpos($x, $like) === strlen($x) - 1) {
$regex .= substr($x, 0, -1).$pattern;
} else {
$regex .= $x;
}
return new \MongoRegex('/^'.$regex.'$/');
} | php | private function convertLikeToRegex($x)
{
$x = preg_quote($x);
$pattern = '.*?';
$regex = null;
if (strpos($x, $like = '%') === 0) {
$regex .= $pattern;
$x = substr($x, 1);
}
if (strrpos($x, $like) === strlen($x) - 1) {
$regex .= substr($x, 0, -1).$pattern;
} else {
$regex .= $x;
}
return new \MongoRegex('/^'.$regex.'$/');
} | [
"private",
"function",
"convertLikeToRegex",
"(",
"$",
"x",
")",
"{",
"$",
"x",
"=",
"preg_quote",
"(",
"$",
"x",
")",
";",
"$",
"pattern",
"=",
"'.*?'",
";",
"$",
"regex",
"=",
"null",
";",
"if",
"(",
"strpos",
"(",
"$",
"x",
",",
"$",
"like",
"=",
"'%'",
")",
"===",
"0",
")",
"{",
"$",
"regex",
".=",
"$",
"pattern",
";",
"$",
"x",
"=",
"substr",
"(",
"$",
"x",
",",
"1",
")",
";",
"}",
"if",
"(",
"strrpos",
"(",
"$",
"x",
",",
"$",
"like",
")",
"===",
"strlen",
"(",
"$",
"x",
")",
"-",
"1",
")",
"{",
"$",
"regex",
".=",
"substr",
"(",
"$",
"x",
",",
"0",
",",
"-",
"1",
")",
".",
"$",
"pattern",
";",
"}",
"else",
"{",
"$",
"regex",
".=",
"$",
"x",
";",
"}",
"return",
"new",
"\\",
"MongoRegex",
"(",
"'/^'",
".",
"$",
"regex",
".",
"'$/'",
")",
";",
"}"
] | @param string $x
@return \MongoRegex | [
"@param",
"string",
"$x"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/DataSource/Doctrine/MongoDB/ExpressionBuilder.php#L229-L247 |
davedevelopment/twig-inflection | src/DaveDevelopment/TwigInflection/Twig/Extension/Inflection.php | Inflection.singularize | public static function singularize($plural, $count = 1, $singular = null)
{
$count = intval($count);
if ($count != 1) {
return $plural;
}
if (null == $singular) {
$singular = \Doctrine\Common\Inflector\Inflector::singularize($plural);
}
return $singular;
} | php | public static function singularize($plural, $count = 1, $singular = null)
{
$count = intval($count);
if ($count != 1) {
return $plural;
}
if (null == $singular) {
$singular = \Doctrine\Common\Inflector\Inflector::singularize($plural);
}
return $singular;
} | [
"public",
"static",
"function",
"singularize",
"(",
"$",
"plural",
",",
"$",
"count",
"=",
"1",
",",
"$",
"singular",
"=",
"null",
")",
"{",
"$",
"count",
"=",
"intval",
"(",
"$",
"count",
")",
";",
"if",
"(",
"$",
"count",
"!=",
"1",
")",
"{",
"return",
"$",
"plural",
";",
"}",
"if",
"(",
"null",
"==",
"$",
"singular",
")",
"{",
"$",
"singular",
"=",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Inflector",
"\\",
"Inflector",
"::",
"singularize",
"(",
"$",
"plural",
")",
";",
"}",
"return",
"$",
"singular",
";",
"}"
] | Singularize the $plural word if count == 1. If $singular is passed, it
will be used instead of trying to use doctrine\inflector
@param string $plural - chicken
@param int $count - e.g. 4
@param string $singular - (optional) chickens
@return string | [
"Singularize",
"the",
"$plural",
"word",
"if",
"count",
"==",
"1",
".",
"If",
"$singular",
"is",
"passed",
"it",
"will",
"be",
"used",
"instead",
"of",
"trying",
"to",
"use",
"doctrine",
"\\",
"inflector"
] | train | https://github.com/davedevelopment/twig-inflection/blob/c5c64de5673580f1a30790bb8784a64ac6191dde/src/DaveDevelopment/TwigInflection/Twig/Extension/Inflection.php#L29-L42 |
Danzabar/config-builder | src/Data/Converter.php | Converter.setExtension | public function setExtension($ext)
{
$this->extension = $ext;
if(!$this->extensionMap->has($ext))
{
throw new Exceptions\InvalidExtension($ext);
}
return $this;
} | php | public function setExtension($ext)
{
$this->extension = $ext;
if(!$this->extensionMap->has($ext))
{
throw new Exceptions\InvalidExtension($ext);
}
return $this;
} | [
"public",
"function",
"setExtension",
"(",
"$",
"ext",
")",
"{",
"$",
"this",
"->",
"extension",
"=",
"$",
"ext",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"extensionMap",
"->",
"has",
"(",
"$",
"ext",
")",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"InvalidExtension",
"(",
"$",
"ext",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the extension
@param String $ext
@return Converter
@author Dan Cox | [
"Sets",
"the",
"extension"
] | train | https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Data/Converter.php#L63-L73 |
Danzabar/config-builder | src/Data/Converter.php | Converter.process | public function process($data = '')
{
$this->data = $data;
$ext = $this->extensionMap->get($this->extension);
$arr = $ext->load($data)->toArray();
$this->paramBag = new ParamBag($arr);
return true;
} | php | public function process($data = '')
{
$this->data = $data;
$ext = $this->extensionMap->get($this->extension);
$arr = $ext->load($data)->toArray();
$this->paramBag = new ParamBag($arr);
return true;
} | [
"public",
"function",
"process",
"(",
"$",
"data",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
";",
"$",
"ext",
"=",
"$",
"this",
"->",
"extensionMap",
"->",
"get",
"(",
"$",
"this",
"->",
"extension",
")",
";",
"$",
"arr",
"=",
"$",
"ext",
"->",
"load",
"(",
"$",
"data",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"this",
"->",
"paramBag",
"=",
"new",
"ParamBag",
"(",
"$",
"arr",
")",
";",
"return",
"true",
";",
"}"
] | Loads an extension class to convert the data to an array and pass it back as a param bag
@param String $data
@return ParamBag
@author Dan Cox | [
"Loads",
"an",
"extension",
"class",
"to",
"convert",
"the",
"data",
"to",
"an",
"array",
"and",
"pass",
"it",
"back",
"as",
"a",
"param",
"bag"
] | train | https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Data/Converter.php#L82-L92 |
Danzabar/config-builder | src/Data/Converter.php | Converter.toNative | public function toNative(ParamBag $paramBag)
{
// We can assume the extension exists, since it has already been used
$ext = $this->extensionMap->get($this->extension);
$native = $ext->load($paramBag->all())->toNative();
return $native;
} | php | public function toNative(ParamBag $paramBag)
{
// We can assume the extension exists, since it has already been used
$ext = $this->extensionMap->get($this->extension);
$native = $ext->load($paramBag->all())->toNative();
return $native;
} | [
"public",
"function",
"toNative",
"(",
"ParamBag",
"$",
"paramBag",
")",
"{",
"// We can assume the extension exists, since it has already been used",
"$",
"ext",
"=",
"$",
"this",
"->",
"extensionMap",
"->",
"get",
"(",
"$",
"this",
"->",
"extension",
")",
";",
"$",
"native",
"=",
"$",
"ext",
"->",
"load",
"(",
"$",
"paramBag",
"->",
"all",
"(",
")",
")",
"->",
"toNative",
"(",
")",
";",
"return",
"$",
"native",
";",
"}"
] | Converts the parambag instance of the native extension format
@param \Danzabar\Config\Data\ParamBag $paramBag
@return Mixed
@author Dan Cox | [
"Converts",
"the",
"parambag",
"instance",
"of",
"the",
"native",
"extension",
"format"
] | train | https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Data/Converter.php#L101-L108 |
php-lug/lug | src/Bundle/ResourceBundle/LugResourceBundle.php | LugResourceBundle.build | public function build(ContainerBuilder $container)
{
$container
->addCompilerPass(new RegisterResourcePass())
->addCompilerPass(new RegisterDriverMappingPass())
->addCompilerPass(new RegisterFactoryPass())
->addCompilerPass(new RegisterManagerTagPass())
->addCompilerPass(new RegisterManagerPass())
->addCompilerPass(new RegisterRepositoryPass())
->addCompilerPass(new RegisterDomainManagerPass())
->addCompilerPass(new ConfigureResolveTargetEntitySubscriberPass())
->addCompilerPass(new RegisterFlashListenerPass())
->addCompilerPass(new RegisterMessageListenerPass())
->addCompilerPass(new RegisterDomainListenerPass())
->addCompilerPass(new RegisterRestListenerPass())
->addCompilerPass(new ReplaceBase64FileExtensionPass());
} | php | public function build(ContainerBuilder $container)
{
$container
->addCompilerPass(new RegisterResourcePass())
->addCompilerPass(new RegisterDriverMappingPass())
->addCompilerPass(new RegisterFactoryPass())
->addCompilerPass(new RegisterManagerTagPass())
->addCompilerPass(new RegisterManagerPass())
->addCompilerPass(new RegisterRepositoryPass())
->addCompilerPass(new RegisterDomainManagerPass())
->addCompilerPass(new ConfigureResolveTargetEntitySubscriberPass())
->addCompilerPass(new RegisterFlashListenerPass())
->addCompilerPass(new RegisterMessageListenerPass())
->addCompilerPass(new RegisterDomainListenerPass())
->addCompilerPass(new RegisterRestListenerPass())
->addCompilerPass(new ReplaceBase64FileExtensionPass());
} | [
"public",
"function",
"build",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"container",
"->",
"addCompilerPass",
"(",
"new",
"RegisterResourcePass",
"(",
")",
")",
"->",
"addCompilerPass",
"(",
"new",
"RegisterDriverMappingPass",
"(",
")",
")",
"->",
"addCompilerPass",
"(",
"new",
"RegisterFactoryPass",
"(",
")",
")",
"->",
"addCompilerPass",
"(",
"new",
"RegisterManagerTagPass",
"(",
")",
")",
"->",
"addCompilerPass",
"(",
"new",
"RegisterManagerPass",
"(",
")",
")",
"->",
"addCompilerPass",
"(",
"new",
"RegisterRepositoryPass",
"(",
")",
")",
"->",
"addCompilerPass",
"(",
"new",
"RegisterDomainManagerPass",
"(",
")",
")",
"->",
"addCompilerPass",
"(",
"new",
"ConfigureResolveTargetEntitySubscriberPass",
"(",
")",
")",
"->",
"addCompilerPass",
"(",
"new",
"RegisterFlashListenerPass",
"(",
")",
")",
"->",
"addCompilerPass",
"(",
"new",
"RegisterMessageListenerPass",
"(",
")",
")",
"->",
"addCompilerPass",
"(",
"new",
"RegisterDomainListenerPass",
"(",
")",
")",
"->",
"addCompilerPass",
"(",
"new",
"RegisterRestListenerPass",
"(",
")",
")",
"->",
"addCompilerPass",
"(",
"new",
"ReplaceBase64FileExtensionPass",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/ResourceBundle/LugResourceBundle.php#L38-L54 |
GrupaZero/api | src/Gzero/Api/Transformer/LangTransformer.php | LangTransformer.transform | public function transform($lang)
{
$lang = $this->entityToArray(Lang::class, $lang);
return [
'code' => $lang['code'],
'i18n' => $lang['i18n'],
'isEnabled' => (bool) $lang['is_enabled'],
'isDefault' => (bool) $lang['is_default'],
];
} | php | public function transform($lang)
{
$lang = $this->entityToArray(Lang::class, $lang);
return [
'code' => $lang['code'],
'i18n' => $lang['i18n'],
'isEnabled' => (bool) $lang['is_enabled'],
'isDefault' => (bool) $lang['is_default'],
];
} | [
"public",
"function",
"transform",
"(",
"$",
"lang",
")",
"{",
"$",
"lang",
"=",
"$",
"this",
"->",
"entityToArray",
"(",
"Lang",
"::",
"class",
",",
"$",
"lang",
")",
";",
"return",
"[",
"'code'",
"=>",
"$",
"lang",
"[",
"'code'",
"]",
",",
"'i18n'",
"=>",
"$",
"lang",
"[",
"'i18n'",
"]",
",",
"'isEnabled'",
"=>",
"(",
"bool",
")",
"$",
"lang",
"[",
"'is_enabled'",
"]",
",",
"'isDefault'",
"=>",
"(",
"bool",
")",
"$",
"lang",
"[",
"'is_default'",
"]",
",",
"]",
";",
"}"
] | Transforms lang entity
@param Lang|array $lang Lang entity
@return array | [
"Transforms",
"lang",
"entity"
] | train | https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Transformer/LangTransformer.php#L26-L35 |
blast-project/BaseEntitiesBundle | src/Admin/TreeableAdmin.php | TreeableAdmin.create | public function create($object)
{
$em = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager();
$this->prePersist($object);
foreach ($this->extensions as $extension) {
$extension->prePersist($this, $object);
}
$object->setMaterializedPath('');
$em->persist($object);
if ($object->getParentNode() !== null) {
$object->setChildNodeOf($object->getParentNode());
} else {
$object->setParentNode(null);
}
$this->postPersist($object);
foreach ($this->extensions as $extension) {
$extension->postPersist($this, $object);
}
$em->flush();
$this->createObjectSecurity($object);
return $object;
} | php | public function create($object)
{
$em = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager();
$this->prePersist($object);
foreach ($this->extensions as $extension) {
$extension->prePersist($this, $object);
}
$object->setMaterializedPath('');
$em->persist($object);
if ($object->getParentNode() !== null) {
$object->setChildNodeOf($object->getParentNode());
} else {
$object->setParentNode(null);
}
$this->postPersist($object);
foreach ($this->extensions as $extension) {
$extension->postPersist($this, $object);
}
$em->flush();
$this->createObjectSecurity($object);
return $object;
} | [
"public",
"function",
"create",
"(",
"$",
"object",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getConfigurationPool",
"(",
")",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'doctrine'",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"this",
"->",
"prePersist",
"(",
"$",
"object",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"extensions",
"as",
"$",
"extension",
")",
"{",
"$",
"extension",
"->",
"prePersist",
"(",
"$",
"this",
",",
"$",
"object",
")",
";",
"}",
"$",
"object",
"->",
"setMaterializedPath",
"(",
"''",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"object",
")",
";",
"if",
"(",
"$",
"object",
"->",
"getParentNode",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setChildNodeOf",
"(",
"$",
"object",
"->",
"getParentNode",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"object",
"->",
"setParentNode",
"(",
"null",
")",
";",
"}",
"$",
"this",
"->",
"postPersist",
"(",
"$",
"object",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"extensions",
"as",
"$",
"extension",
")",
"{",
"$",
"extension",
"->",
"postPersist",
"(",
"$",
"this",
",",
"$",
"object",
")",
";",
"}",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"createObjectSecurity",
"(",
"$",
"object",
")",
";",
"return",
"$",
"object",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/blast-project/BaseEntitiesBundle/blob/abd06891fc38922225ab7e4fcb437a286ba2c0c4/src/Admin/TreeableAdmin.php#L22-L49 |
blast-project/BaseEntitiesBundle | src/Admin/TreeableAdmin.php | TreeableAdmin.getObject | public function getObject($id)
{
$object = parent::getObject($id);
$parent_node_id = $object->getParentNodeId();
$parent_node = $this->getModelManager()->find($this->getClass(), $parent_node_id);
$object->setParentNode($parent_node);
return $object;
} | php | public function getObject($id)
{
$object = parent::getObject($id);
$parent_node_id = $object->getParentNodeId();
$parent_node = $this->getModelManager()->find($this->getClass(), $parent_node_id);
$object->setParentNode($parent_node);
return $object;
} | [
"public",
"function",
"getObject",
"(",
"$",
"id",
")",
"{",
"$",
"object",
"=",
"parent",
"::",
"getObject",
"(",
"$",
"id",
")",
";",
"$",
"parent_node_id",
"=",
"$",
"object",
"->",
"getParentNodeId",
"(",
")",
";",
"$",
"parent_node",
"=",
"$",
"this",
"->",
"getModelManager",
"(",
")",
"->",
"find",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
",",
"$",
"parent_node_id",
")",
";",
"$",
"object",
"->",
"setParentNode",
"(",
"$",
"parent_node",
")",
";",
"return",
"$",
"object",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/blast-project/BaseEntitiesBundle/blob/abd06891fc38922225ab7e4fcb437a286ba2c0c4/src/Admin/TreeableAdmin.php#L54-L63 |
heidelpay/PhpDoc | src/phpDocumentor/Plugin/Scrybe/Template/Twig.php | Twig.setPath | public function setPath($path)
{
if (!file_exists($path) || !is_dir($path)) {
throw new \InvalidArgumentException(
'Expected the template path to be an existing directory, received: '.$path
);
}
$this->path = $path;
} | php | public function setPath($path)
{
if (!file_exists($path) || !is_dir($path)) {
throw new \InvalidArgumentException(
'Expected the template path to be an existing directory, received: '.$path
);
}
$this->path = $path;
} | [
"public",
"function",
"setPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
"||",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Expected the template path to be an existing directory, received: '",
".",
"$",
"path",
")",
";",
"}",
"$",
"this",
"->",
"path",
"=",
"$",
"path",
";",
"}"
] | Sets the base path where the templates are stored.
@param string $path
@throws \InvalidArgumentException
@return void | [
"Sets",
"the",
"base",
"path",
"where",
"the",
"templates",
"are",
"stored",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Scrybe/Template/Twig.php#L83-L92 |
heidelpay/PhpDoc | src/phpDocumentor/Plugin/Scrybe/Template/Twig.php | Twig.decorate | public function decorate($contents, array $options = array())
{
return $this->getTwigEnvironment()->render(
$this->getTemplateFilename(),
array_merge(array('contents' => $contents), $options)
);
} | php | public function decorate($contents, array $options = array())
{
return $this->getTwigEnvironment()->render(
$this->getTemplateFilename(),
array_merge(array('contents' => $contents), $options)
);
} | [
"public",
"function",
"decorate",
"(",
"$",
"contents",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getTwigEnvironment",
"(",
")",
"->",
"render",
"(",
"$",
"this",
"->",
"getTemplateFilename",
"(",
")",
",",
"array_merge",
"(",
"array",
"(",
"'contents'",
"=>",
"$",
"contents",
")",
",",
"$",
"options",
")",
")",
";",
"}"
] | Applies the relevant template upon the given content.
This method takes the combines the template with the given contents and generates a final piece of text
from that.
The user may add additional options that are set as parameters in the template.
@param string $contents
@param string[] $options
@see getTemplateFileName() how the filename is assembled
@return string | [
"Applies",
"the",
"relevant",
"template",
"upon",
"the",
"given",
"content",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Scrybe/Template/Twig.php#L154-L160 |
heidelpay/PhpDoc | src/phpDocumentor/Plugin/Scrybe/Template/Twig.php | Twig.getAssets | public function getAssets()
{
$finder = new Finder();
return iterator_to_array(
$finder->files()
->in($this->path.DIRECTORY_SEPARATOR . $this->name)
->depth('> 0')
->notName('*.twig')
->sortByName()
);
} | php | public function getAssets()
{
$finder = new Finder();
return iterator_to_array(
$finder->files()
->in($this->path.DIRECTORY_SEPARATOR . $this->name)
->depth('> 0')
->notName('*.twig')
->sortByName()
);
} | [
"public",
"function",
"getAssets",
"(",
")",
"{",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"return",
"iterator_to_array",
"(",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"in",
"(",
"$",
"this",
"->",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"name",
")",
"->",
"depth",
"(",
"'> 0'",
")",
"->",
"notName",
"(",
"'*.twig'",
")",
"->",
"sortByName",
"(",
")",
")",
";",
"}"
] | Returns a list of files that need to be copied to the destination location.
Examples of assets can be:
* CSS files
* Javascript files
* Images
Assets for this template engine means every file that is contained in a subfolder of the template folder and
does not end with the extension twig.
Thus every file in the root of the template folder is ignored and files and directories having only twig
templates (considered as being includes) are not included in this list.
@return string[] | [
"Returns",
"a",
"list",
"of",
"files",
"that",
"need",
"to",
"be",
"copied",
"to",
"the",
"destination",
"location",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Scrybe/Template/Twig.php#L179-L190 |
jasny/codeception-module | src/Connector.php | Connector.setBaseRequest | public function setBaseRequest(ServerRequestInterface $request)
{
if ($request instanceof GlobalEnvironmentInterface && $request->isStale()) {
throw new \RuntimeException("Unable to set base request: ServerRequest is stale");
}
$this->baseRequest = $request;
} | php | public function setBaseRequest(ServerRequestInterface $request)
{
if ($request instanceof GlobalEnvironmentInterface && $request->isStale()) {
throw new \RuntimeException("Unable to set base request: ServerRequest is stale");
}
$this->baseRequest = $request;
} | [
"public",
"function",
"setBaseRequest",
"(",
"ServerRequestInterface",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"request",
"instanceof",
"GlobalEnvironmentInterface",
"&&",
"$",
"request",
"->",
"isStale",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Unable to set base request: ServerRequest is stale\"",
")",
";",
"}",
"$",
"this",
"->",
"baseRequest",
"=",
"$",
"request",
";",
"}"
] | Set the base request
@param ServerRequestInterface $request | [
"Set",
"the",
"base",
"request"
] | train | https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/Connector.php#L77-L84 |
jasny/codeception-module | src/Connector.php | Connector.getBaseRequest | public function getBaseRequest()
{
if (!isset($this->baseRequest)) {
$this->baseRequest = new ServerRequest();
}
$request = $this->baseRequest;
if ($request instanceof GlobalEnvironmentInterface && $request->isStale() === false) {
$request = $request->withGlobalEnvironment(true); // Make sure base request is stale
}
return $request;
} | php | public function getBaseRequest()
{
if (!isset($this->baseRequest)) {
$this->baseRequest = new ServerRequest();
}
$request = $this->baseRequest;
if ($request instanceof GlobalEnvironmentInterface && $request->isStale() === false) {
$request = $request->withGlobalEnvironment(true); // Make sure base request is stale
}
return $request;
} | [
"public",
"function",
"getBaseRequest",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"baseRequest",
")",
")",
"{",
"$",
"this",
"->",
"baseRequest",
"=",
"new",
"ServerRequest",
"(",
")",
";",
"}",
"$",
"request",
"=",
"$",
"this",
"->",
"baseRequest",
";",
"if",
"(",
"$",
"request",
"instanceof",
"GlobalEnvironmentInterface",
"&&",
"$",
"request",
"->",
"isStale",
"(",
")",
"===",
"false",
")",
"{",
"$",
"request",
"=",
"$",
"request",
"->",
"withGlobalEnvironment",
"(",
"true",
")",
";",
"// Make sure base request is stale",
"}",
"return",
"$",
"request",
";",
"}"
] | Get the base request
@return ServerRequestInterface | [
"Get",
"the",
"base",
"request"
] | train | https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/Connector.php#L91-L104 |
jasny/codeception-module | src/Connector.php | Connector.setBaseResponse | public function setBaseResponse(ResponseInterface $response)
{
if ($response instanceof GlobalEnvironmentInterface && $response->isStale()) {
throw new \RuntimeException("Unable to set base response: Response is stale");
}
$this->baseResponse = $response;
} | php | public function setBaseResponse(ResponseInterface $response)
{
if ($response instanceof GlobalEnvironmentInterface && $response->isStale()) {
throw new \RuntimeException("Unable to set base response: Response is stale");
}
$this->baseResponse = $response;
} | [
"public",
"function",
"setBaseResponse",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"if",
"(",
"$",
"response",
"instanceof",
"GlobalEnvironmentInterface",
"&&",
"$",
"response",
"->",
"isStale",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Unable to set base response: Response is stale\"",
")",
";",
"}",
"$",
"this",
"->",
"baseResponse",
"=",
"$",
"response",
";",
"}"
] | Set the base response
@param ResponseInterface $response | [
"Set",
"the",
"base",
"response"
] | train | https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/Connector.php#L112-L119 |
jasny/codeception-module | src/Connector.php | Connector.getBaseResponse | public function getBaseResponse()
{
if (!isset($this->baseResponse)) {
$this->baseResponse = new Response();
}
$response = $this->baseResponse;
if ($response instanceof GlobalEnvironmentInterface && $response->isStale() === false) {
$response = $response->withGlobalEnvironment(true); // Make sure base response is stale
}
return $response;
} | php | public function getBaseResponse()
{
if (!isset($this->baseResponse)) {
$this->baseResponse = new Response();
}
$response = $this->baseResponse;
if ($response instanceof GlobalEnvironmentInterface && $response->isStale() === false) {
$response = $response->withGlobalEnvironment(true); // Make sure base response is stale
}
return $response;
} | [
"public",
"function",
"getBaseResponse",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"baseResponse",
")",
")",
"{",
"$",
"this",
"->",
"baseResponse",
"=",
"new",
"Response",
"(",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"baseResponse",
";",
"if",
"(",
"$",
"response",
"instanceof",
"GlobalEnvironmentInterface",
"&&",
"$",
"response",
"->",
"isStale",
"(",
")",
"===",
"false",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"withGlobalEnvironment",
"(",
"true",
")",
";",
"// Make sure base response is stale",
"}",
"return",
"$",
"response",
";",
"}"
] | Get the base response
@return ResponseInterface | [
"Get",
"the",
"base",
"response"
] | train | https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/Connector.php#L126-L139 |
jasny/codeception-module | src/Connector.php | Connector.resetOutput | protected function resetOutput()
{
if ($this->baseResponse instanceof GlobalEnvironmentInterface) {
$this->baseResponse = $this->baseResponse->revive();
}
// Clear output buffer
if (isset($this->baseResponse) && $this->baseResponse->getBody() instanceof OutputBufferStream) {
$this->baseResponse = $this->baseResponse->withBody(clone $this->baseResponse->getBody());
}
} | php | protected function resetOutput()
{
if ($this->baseResponse instanceof GlobalEnvironmentInterface) {
$this->baseResponse = $this->baseResponse->revive();
}
// Clear output buffer
if (isset($this->baseResponse) && $this->baseResponse->getBody() instanceof OutputBufferStream) {
$this->baseResponse = $this->baseResponse->withBody(clone $this->baseResponse->getBody());
}
} | [
"protected",
"function",
"resetOutput",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"baseResponse",
"instanceof",
"GlobalEnvironmentInterface",
")",
"{",
"$",
"this",
"->",
"baseResponse",
"=",
"$",
"this",
"->",
"baseResponse",
"->",
"revive",
"(",
")",
";",
"}",
"// Clear output buffer",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"baseResponse",
")",
"&&",
"$",
"this",
"->",
"baseResponse",
"->",
"getBody",
"(",
")",
"instanceof",
"OutputBufferStream",
")",
"{",
"$",
"this",
"->",
"baseResponse",
"=",
"$",
"this",
"->",
"baseResponse",
"->",
"withBody",
"(",
"clone",
"$",
"this",
"->",
"baseResponse",
"->",
"getBody",
"(",
")",
")",
";",
"}",
"}"
] | Reset the response | [
"Reset",
"the",
"response"
] | train | https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/Connector.php#L155-L165 |
jasny/codeception-module | src/Connector.php | Connector.doRequest | protected function doRequest($request)
{
if ($this->getRouter() === null) {
throw new \BadMethodCallException("Router not set");
}
$this->reset(); // Reset before each HTTP request
$psrRequest = $this->getRequestConvertor()->convert($request, $this->getBaseRequest());
$router = $this->getRouter();
$psrResponse = $router->handle($psrRequest, $this->getBaseResponse());
return $this->getResponseConvertor()->convert($psrResponse);
} | php | protected function doRequest($request)
{
if ($this->getRouter() === null) {
throw new \BadMethodCallException("Router not set");
}
$this->reset(); // Reset before each HTTP request
$psrRequest = $this->getRequestConvertor()->convert($request, $this->getBaseRequest());
$router = $this->getRouter();
$psrResponse = $router->handle($psrRequest, $this->getBaseResponse());
return $this->getResponseConvertor()->convert($psrResponse);
} | [
"protected",
"function",
"doRequest",
"(",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getRouter",
"(",
")",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"\"Router not set\"",
")",
";",
"}",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"// Reset before each HTTP request",
"$",
"psrRequest",
"=",
"$",
"this",
"->",
"getRequestConvertor",
"(",
")",
"->",
"convert",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"getBaseRequest",
"(",
")",
")",
";",
"$",
"router",
"=",
"$",
"this",
"->",
"getRouter",
"(",
")",
";",
"$",
"psrResponse",
"=",
"$",
"router",
"->",
"handle",
"(",
"$",
"psrRequest",
",",
"$",
"this",
"->",
"getBaseResponse",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"getResponseConvertor",
"(",
")",
"->",
"convert",
"(",
"$",
"psrResponse",
")",
";",
"}"
] | Makes a request.
@param BrowserKitRequest $request
@return BrowserKitResponse | [
"Makes",
"a",
"request",
"."
] | train | https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/Connector.php#L234-L248 |
Eresus/EresusCMS | src/core/framework/core/WWW/HTTP/HttpMessage.php | HttpMessage.fromEnv | public static function fromEnv($messageType, $className = 'HttpMessage')
{
if (Eresus_Kernel::isCLI())
{
return null;
}
/*
* Create message instance
*/
if (!class_exists($className, true))
{
throw new RuntimeException("Class \"$className\" not exists");
}
$message = new $className();
if (! ($message instanceof HttpMessage))
{
throw Eresus_Exception_InvalidArgumentType::factory(__METHOD__, 2,
'descendant of HttpMessage', $className);
}
// Message type
$message->setType($messageType);
/*
* Protocol version
*/
if (isset($_SERVER['SERVER_PROTOCOL']))
{
$dividerPosition = strpos($_SERVER['SERVER_PROTOCOL'], '/');
if ($dividerPosition)
{
$httpVersion = substr($_SERVER['SERVER_PROTOCOL'], $dividerPosition + 1);
}
else
{
$httpVersion = '1.0';
}
}
else
{
$httpVersion = '1.0';
}
$message->setHttpVersion($httpVersion);
return $message;
} | php | public static function fromEnv($messageType, $className = 'HttpMessage')
{
if (Eresus_Kernel::isCLI())
{
return null;
}
/*
* Create message instance
*/
if (!class_exists($className, true))
{
throw new RuntimeException("Class \"$className\" not exists");
}
$message = new $className();
if (! ($message instanceof HttpMessage))
{
throw Eresus_Exception_InvalidArgumentType::factory(__METHOD__, 2,
'descendant of HttpMessage', $className);
}
// Message type
$message->setType($messageType);
/*
* Protocol version
*/
if (isset($_SERVER['SERVER_PROTOCOL']))
{
$dividerPosition = strpos($_SERVER['SERVER_PROTOCOL'], '/');
if ($dividerPosition)
{
$httpVersion = substr($_SERVER['SERVER_PROTOCOL'], $dividerPosition + 1);
}
else
{
$httpVersion = '1.0';
}
}
else
{
$httpVersion = '1.0';
}
$message->setHttpVersion($httpVersion);
return $message;
} | [
"public",
"static",
"function",
"fromEnv",
"(",
"$",
"messageType",
",",
"$",
"className",
"=",
"'HttpMessage'",
")",
"{",
"if",
"(",
"Eresus_Kernel",
"::",
"isCLI",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"/*\n * Create message instance\n */",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
",",
"true",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Class \\\"$className\\\" not exists\"",
")",
";",
"}",
"$",
"message",
"=",
"new",
"$",
"className",
"(",
")",
";",
"if",
"(",
"!",
"(",
"$",
"message",
"instanceof",
"HttpMessage",
")",
")",
"{",
"throw",
"Eresus_Exception_InvalidArgumentType",
"::",
"factory",
"(",
"__METHOD__",
",",
"2",
",",
"'descendant of HttpMessage'",
",",
"$",
"className",
")",
";",
"}",
"// Message type",
"$",
"message",
"->",
"setType",
"(",
"$",
"messageType",
")",
";",
"/*\n * Protocol version\n */",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'SERVER_PROTOCOL'",
"]",
")",
")",
"{",
"$",
"dividerPosition",
"=",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'SERVER_PROTOCOL'",
"]",
",",
"'/'",
")",
";",
"if",
"(",
"$",
"dividerPosition",
")",
"{",
"$",
"httpVersion",
"=",
"substr",
"(",
"$",
"_SERVER",
"[",
"'SERVER_PROTOCOL'",
"]",
",",
"$",
"dividerPosition",
"+",
"1",
")",
";",
"}",
"else",
"{",
"$",
"httpVersion",
"=",
"'1.0'",
";",
"}",
"}",
"else",
"{",
"$",
"httpVersion",
"=",
"'1.0'",
";",
"}",
"$",
"message",
"->",
"setHttpVersion",
"(",
"$",
"httpVersion",
")",
";",
"return",
"$",
"message",
";",
"}"
] | Создаёт объект HttpMessage из окружения
В режиме CLI результат всегда будет null.
@param int $messageType тип сообщения, см. константы TYPE_xxx
@param string $className класс, расширяющий HttpMessage
@return HttpMessage|null объект HttpMessage или null в случае ошибки
@throws RuntimeException если класс $className не существует
@throws Eresus_Exception_InvalidArgumentType если $className не является потомком HttpMessage | [
"Создаёт",
"объект",
"HttpMessage",
"из",
"окружения"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/WWW/HTTP/HttpMessage.php#L86-L136 |
Eresus/EresusCMS | src/core/framework/core/WWW/HTTP/HttpMessage.php | HttpMessage.setHttpVersion | public function setHttpVersion($version)
{
// Version validation pattern
$pattern = '~^1\.[01]$~';
if (! preg_match($pattern, $version))
return false;
$this->httpVersion = $version;
return true;
} | php | public function setHttpVersion($version)
{
// Version validation pattern
$pattern = '~^1\.[01]$~';
if (! preg_match($pattern, $version))
return false;
$this->httpVersion = $version;
return true;
} | [
"public",
"function",
"setHttpVersion",
"(",
"$",
"version",
")",
"{",
"// Version validation pattern",
"$",
"pattern",
"=",
"'~^1\\.[01]$~'",
";",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"version",
")",
")",
"return",
"false",
";",
"$",
"this",
"->",
"httpVersion",
"=",
"$",
"version",
";",
"return",
"true",
";",
"}"
] | Set the HTTP Protocol version of the Message
@param string $version
@return bool Returns TRUE on success, or FALSE if supplied version is out of range (1.0/1.1) | [
"Set",
"the",
"HTTP",
"Protocol",
"version",
"of",
"the",
"Message"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/WWW/HTTP/HttpMessage.php#L167-L177 |
Eresus/EresusCMS | src/core/framework/core/WWW/HTTP/HttpMessage.php | HttpMessage.setRequestMethod | public function setRequestMethod($method)
{
if ($this->getType() !== self::TYPE_REQUEST)
return false;
$method = strtoupper($method);
$REQUEST_METHODS = array('OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE');
if (!in_array($method, $REQUEST_METHODS))
return false;
$this->requestMethod = $method;
return true;
} | php | public function setRequestMethod($method)
{
if ($this->getType() !== self::TYPE_REQUEST)
return false;
$method = strtoupper($method);
$REQUEST_METHODS = array('OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE');
if (!in_array($method, $REQUEST_METHODS))
return false;
$this->requestMethod = $method;
return true;
} | [
"public",
"function",
"setRequestMethod",
"(",
"$",
"method",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getType",
"(",
")",
"!==",
"self",
"::",
"TYPE_REQUEST",
")",
"return",
"false",
";",
"$",
"method",
"=",
"strtoupper",
"(",
"$",
"method",
")",
";",
"$",
"REQUEST_METHODS",
"=",
"array",
"(",
"'OPTIONS'",
",",
"'GET'",
",",
"'HEAD'",
",",
"'POST'",
",",
"'PUT'",
",",
"'DELETE'",
",",
"'TRACE'",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"method",
",",
"$",
"REQUEST_METHODS",
")",
")",
"return",
"false",
";",
"$",
"this",
"->",
"requestMethod",
"=",
"$",
"method",
";",
"return",
"true",
";",
"}"
] | Set the Request Method of the HTTP Message
@param string $method The request method name.
{@link http://tools.ietf.org/html/rfc2068#section-5.1.1 See RFC2068 section 5.1.1}
for list of acceptable methods
@return bool TRUE on success, or FALSE if the message is not of type
HttpMessage::TYPE_REQUEST or an invalid request method was supplied | [
"Set",
"the",
"Request",
"Method",
"of",
"the",
"HTTP",
"Message"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/WWW/HTTP/HttpMessage.php#L200-L213 |
Lansoweb/LosI18n | src/Service/CountryService.php | CountryService.getAllCountries | public function getAllCountries(string $translatedTo = '', bool $filterOfficiallyAssigned = true): array
{
if ('' === $translatedTo) {
$translatedTo = $this->defaultLang;
}
$fileName = $this->path.'/'.$translatedTo.'/countries.php';
if (! file_exists($fileName)) {
throw new \InvalidArgumentException("Language $translatedTo not found.");
}
$countries = include $fileName;
if ($filterOfficiallyAssigned) {
$filterKeys = ['AF','AX','AL','DZ','AS','AD','AO','AI','AQ','AG','AR','AM','AW','AU','AT','AZ','BS','BH','BD','BB','BY','BE','BZ','BJ','BM','BT','BO','BQ','BA','BW','BV','BR','IO','VG','BN','BG','BF','BI','KH','CM','CA','CV','KY','CF','TD','CL','CN','CX','CC','CO','KM','CK','CR','HR','CU','CW','CY','CZ','CD','DK','DJ','DM','DO','TL','EC','EG','SV','GQ','ER','EE','ET','FK','FO','FJ','FI','FR','GF','PF','TF','GA','GM','GE','DE','GH','GI','GR','GL','GD','GP','GU','GT','GG','GN','GW','GY','HT','HM','HN','HK','HU','IS','IN','ID','IR','IQ','IE','IM','IL','IT','CI','JM','JP','JE','JO','KZ','KE','KI','XK','KW','KG','LA','LV','LB','LS','LR','LY','LI','LT','LU','MO','MK','MG','MW','MY','MV','ML','MT','MH','MQ','MR','MU','YT','MX','FM','MD','MC','MN','ME','MS','MA','MZ','MM','NA','NR','NP','NL','NC','NZ','NI','NE','NG','NU','NF','KP','MP','NO','OM','PK','PW','PS','PA','PG','PY','PE','PH','PN','PL','PT','PR','QA','CG','RE','RO','RU','RW','BL','SH','KN','LC','MF','PM','VC','WS','SM','ST','SA','SN','RS','SC','SL','SG','SX','SK','SI','SB','SO','ZA','GS','KR','SS','ES','LK','SD','SR','SJ','SZ','SE','CH','SY','TW','TJ','TZ','TH','TG','TK','TO','TT','TN','TR','TM','TC','TV','VI','UG','UA','AE','GB','US','UM','UY','UZ','VU','VA','VE','VN','WF','EH','YE','ZM','ZW']; // @ignoreCodingStandards
$countries = array_intersect_key($countries, array_flip($filterKeys));
}
return $countries;
} | php | public function getAllCountries(string $translatedTo = '', bool $filterOfficiallyAssigned = true): array
{
if ('' === $translatedTo) {
$translatedTo = $this->defaultLang;
}
$fileName = $this->path.'/'.$translatedTo.'/countries.php';
if (! file_exists($fileName)) {
throw new \InvalidArgumentException("Language $translatedTo not found.");
}
$countries = include $fileName;
if ($filterOfficiallyAssigned) {
$filterKeys = ['AF','AX','AL','DZ','AS','AD','AO','AI','AQ','AG','AR','AM','AW','AU','AT','AZ','BS','BH','BD','BB','BY','BE','BZ','BJ','BM','BT','BO','BQ','BA','BW','BV','BR','IO','VG','BN','BG','BF','BI','KH','CM','CA','CV','KY','CF','TD','CL','CN','CX','CC','CO','KM','CK','CR','HR','CU','CW','CY','CZ','CD','DK','DJ','DM','DO','TL','EC','EG','SV','GQ','ER','EE','ET','FK','FO','FJ','FI','FR','GF','PF','TF','GA','GM','GE','DE','GH','GI','GR','GL','GD','GP','GU','GT','GG','GN','GW','GY','HT','HM','HN','HK','HU','IS','IN','ID','IR','IQ','IE','IM','IL','IT','CI','JM','JP','JE','JO','KZ','KE','KI','XK','KW','KG','LA','LV','LB','LS','LR','LY','LI','LT','LU','MO','MK','MG','MW','MY','MV','ML','MT','MH','MQ','MR','MU','YT','MX','FM','MD','MC','MN','ME','MS','MA','MZ','MM','NA','NR','NP','NL','NC','NZ','NI','NE','NG','NU','NF','KP','MP','NO','OM','PK','PW','PS','PA','PG','PY','PE','PH','PN','PL','PT','PR','QA','CG','RE','RO','RU','RW','BL','SH','KN','LC','MF','PM','VC','WS','SM','ST','SA','SN','RS','SC','SL','SG','SX','SK','SI','SB','SO','ZA','GS','KR','SS','ES','LK','SD','SR','SJ','SZ','SE','CH','SY','TW','TJ','TZ','TH','TG','TK','TO','TT','TN','TR','TM','TC','TV','VI','UG','UA','AE','GB','US','UM','UY','UZ','VU','VA','VE','VN','WF','EH','YE','ZM','ZW']; // @ignoreCodingStandards
$countries = array_intersect_key($countries, array_flip($filterKeys));
}
return $countries;
} | [
"public",
"function",
"getAllCountries",
"(",
"string",
"$",
"translatedTo",
"=",
"''",
",",
"bool",
"$",
"filterOfficiallyAssigned",
"=",
"true",
")",
":",
"array",
"{",
"if",
"(",
"''",
"===",
"$",
"translatedTo",
")",
"{",
"$",
"translatedTo",
"=",
"$",
"this",
"->",
"defaultLang",
";",
"}",
"$",
"fileName",
"=",
"$",
"this",
"->",
"path",
".",
"'/'",
".",
"$",
"translatedTo",
".",
"'/countries.php'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fileName",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Language $translatedTo not found.\"",
")",
";",
"}",
"$",
"countries",
"=",
"include",
"$",
"fileName",
";",
"if",
"(",
"$",
"filterOfficiallyAssigned",
")",
"{",
"$",
"filterKeys",
"=",
"[",
"'AF'",
",",
"'AX'",
",",
"'AL'",
",",
"'DZ'",
",",
"'AS'",
",",
"'AD'",
",",
"'AO'",
",",
"'AI'",
",",
"'AQ'",
",",
"'AG'",
",",
"'AR'",
",",
"'AM'",
",",
"'AW'",
",",
"'AU'",
",",
"'AT'",
",",
"'AZ'",
",",
"'BS'",
",",
"'BH'",
",",
"'BD'",
",",
"'BB'",
",",
"'BY'",
",",
"'BE'",
",",
"'BZ'",
",",
"'BJ'",
",",
"'BM'",
",",
"'BT'",
",",
"'BO'",
",",
"'BQ'",
",",
"'BA'",
",",
"'BW'",
",",
"'BV'",
",",
"'BR'",
",",
"'IO'",
",",
"'VG'",
",",
"'BN'",
",",
"'BG'",
",",
"'BF'",
",",
"'BI'",
",",
"'KH'",
",",
"'CM'",
",",
"'CA'",
",",
"'CV'",
",",
"'KY'",
",",
"'CF'",
",",
"'TD'",
",",
"'CL'",
",",
"'CN'",
",",
"'CX'",
",",
"'CC'",
",",
"'CO'",
",",
"'KM'",
",",
"'CK'",
",",
"'CR'",
",",
"'HR'",
",",
"'CU'",
",",
"'CW'",
",",
"'CY'",
",",
"'CZ'",
",",
"'CD'",
",",
"'DK'",
",",
"'DJ'",
",",
"'DM'",
",",
"'DO'",
",",
"'TL'",
",",
"'EC'",
",",
"'EG'",
",",
"'SV'",
",",
"'GQ'",
",",
"'ER'",
",",
"'EE'",
",",
"'ET'",
",",
"'FK'",
",",
"'FO'",
",",
"'FJ'",
",",
"'FI'",
",",
"'FR'",
",",
"'GF'",
",",
"'PF'",
",",
"'TF'",
",",
"'GA'",
",",
"'GM'",
",",
"'GE'",
",",
"'DE'",
",",
"'GH'",
",",
"'GI'",
",",
"'GR'",
",",
"'GL'",
",",
"'GD'",
",",
"'GP'",
",",
"'GU'",
",",
"'GT'",
",",
"'GG'",
",",
"'GN'",
",",
"'GW'",
",",
"'GY'",
",",
"'HT'",
",",
"'HM'",
",",
"'HN'",
",",
"'HK'",
",",
"'HU'",
",",
"'IS'",
",",
"'IN'",
",",
"'ID'",
",",
"'IR'",
",",
"'IQ'",
",",
"'IE'",
",",
"'IM'",
",",
"'IL'",
",",
"'IT'",
",",
"'CI'",
",",
"'JM'",
",",
"'JP'",
",",
"'JE'",
",",
"'JO'",
",",
"'KZ'",
",",
"'KE'",
",",
"'KI'",
",",
"'XK'",
",",
"'KW'",
",",
"'KG'",
",",
"'LA'",
",",
"'LV'",
",",
"'LB'",
",",
"'LS'",
",",
"'LR'",
",",
"'LY'",
",",
"'LI'",
",",
"'LT'",
",",
"'LU'",
",",
"'MO'",
",",
"'MK'",
",",
"'MG'",
",",
"'MW'",
",",
"'MY'",
",",
"'MV'",
",",
"'ML'",
",",
"'MT'",
",",
"'MH'",
",",
"'MQ'",
",",
"'MR'",
",",
"'MU'",
",",
"'YT'",
",",
"'MX'",
",",
"'FM'",
",",
"'MD'",
",",
"'MC'",
",",
"'MN'",
",",
"'ME'",
",",
"'MS'",
",",
"'MA'",
",",
"'MZ'",
",",
"'MM'",
",",
"'NA'",
",",
"'NR'",
",",
"'NP'",
",",
"'NL'",
",",
"'NC'",
",",
"'NZ'",
",",
"'NI'",
",",
"'NE'",
",",
"'NG'",
",",
"'NU'",
",",
"'NF'",
",",
"'KP'",
",",
"'MP'",
",",
"'NO'",
",",
"'OM'",
",",
"'PK'",
",",
"'PW'",
",",
"'PS'",
",",
"'PA'",
",",
"'PG'",
",",
"'PY'",
",",
"'PE'",
",",
"'PH'",
",",
"'PN'",
",",
"'PL'",
",",
"'PT'",
",",
"'PR'",
",",
"'QA'",
",",
"'CG'",
",",
"'RE'",
",",
"'RO'",
",",
"'RU'",
",",
"'RW'",
",",
"'BL'",
",",
"'SH'",
",",
"'KN'",
",",
"'LC'",
",",
"'MF'",
",",
"'PM'",
",",
"'VC'",
",",
"'WS'",
",",
"'SM'",
",",
"'ST'",
",",
"'SA'",
",",
"'SN'",
",",
"'RS'",
",",
"'SC'",
",",
"'SL'",
",",
"'SG'",
",",
"'SX'",
",",
"'SK'",
",",
"'SI'",
",",
"'SB'",
",",
"'SO'",
",",
"'ZA'",
",",
"'GS'",
",",
"'KR'",
",",
"'SS'",
",",
"'ES'",
",",
"'LK'",
",",
"'SD'",
",",
"'SR'",
",",
"'SJ'",
",",
"'SZ'",
",",
"'SE'",
",",
"'CH'",
",",
"'SY'",
",",
"'TW'",
",",
"'TJ'",
",",
"'TZ'",
",",
"'TH'",
",",
"'TG'",
",",
"'TK'",
",",
"'TO'",
",",
"'TT'",
",",
"'TN'",
",",
"'TR'",
",",
"'TM'",
",",
"'TC'",
",",
"'TV'",
",",
"'VI'",
",",
"'UG'",
",",
"'UA'",
",",
"'AE'",
",",
"'GB'",
",",
"'US'",
",",
"'UM'",
",",
"'UY'",
",",
"'UZ'",
",",
"'VU'",
",",
"'VA'",
",",
"'VE'",
",",
"'VN'",
",",
"'WF'",
",",
"'EH'",
",",
"'YE'",
",",
"'ZM'",
",",
"'ZW'",
"]",
";",
"// @ignoreCodingStandards",
"$",
"countries",
"=",
"array_intersect_key",
"(",
"$",
"countries",
",",
"array_flip",
"(",
"$",
"filterKeys",
")",
")",
";",
"}",
"return",
"$",
"countries",
";",
"}"
] | Returns all countries. If needed it can return only officially assigned ones by passing second parameter as true.
@see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements
@param string $translatedTo
@param bool $filterOfficiallyAssigned
@return array | [
"Returns",
"all",
"countries",
".",
"If",
"needed",
"it",
"can",
"return",
"only",
"officially",
"assigned",
"ones",
"by",
"passing",
"second",
"parameter",
"as",
"true",
".",
"@see",
"https",
":",
"//",
"en",
".",
"wikipedia",
".",
"org",
"/",
"wiki",
"/",
"ISO_3166",
"-",
"1_alpha",
"-",
"2#Officially_assigned_code_elements"
] | train | https://github.com/Lansoweb/LosI18n/blob/ef8c513775bafac7ced62f79bd579e4b1b143f59/src/Service/CountryService.php#L30-L48 |
GrupaZero/api | src/Gzero/Api/Transformer/OptionCategoryTransformer.php | OptionCategoryTransformer.transform | public function transform($option)
{
$options = $this->entityToArray(OptionCategory::class, $option);
$data = ['data' => []];
foreach ($options as $option) {
$data['data'][] = [
'key' => $option,
];
}
return $data;
} | php | public function transform($option)
{
$options = $this->entityToArray(OptionCategory::class, $option);
$data = ['data' => []];
foreach ($options as $option) {
$data['data'][] = [
'key' => $option,
];
}
return $data;
} | [
"public",
"function",
"transform",
"(",
"$",
"option",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"entityToArray",
"(",
"OptionCategory",
"::",
"class",
",",
"$",
"option",
")",
";",
"$",
"data",
"=",
"[",
"'data'",
"=>",
"[",
"]",
"]",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
")",
"{",
"$",
"data",
"[",
"'data'",
"]",
"[",
"]",
"=",
"[",
"'key'",
"=>",
"$",
"option",
",",
"]",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Transforms option category entity
@param array $option OptionCategory entity
@return array | [
"Transforms",
"option",
"category",
"entity"
] | train | https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Transformer/OptionCategoryTransformer.php#L26-L37 |
hametuha/wpametu | src/WPametu/API/QueryHighJack.php | QueryHighJack.query_vars | public function query_vars( array $vars ){
if( !empty($this->query_var) ){
foreach( $this->query_var as $var ){
if( false === array_search($var, $vars) ){
$vars[] = $var;
}
}
}
return $vars;
} | php | public function query_vars( array $vars ){
if( !empty($this->query_var) ){
foreach( $this->query_var as $var ){
if( false === array_search($var, $vars) ){
$vars[] = $var;
}
}
}
return $vars;
} | [
"public",
"function",
"query_vars",
"(",
"array",
"$",
"vars",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"query_var",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"query_var",
"as",
"$",
"var",
")",
"{",
"if",
"(",
"false",
"===",
"array_search",
"(",
"$",
"var",
",",
"$",
"vars",
")",
")",
"{",
"$",
"vars",
"[",
"]",
"=",
"$",
"var",
";",
"}",
"}",
"}",
"return",
"$",
"vars",
";",
"}"
] | Add query var filter
@param array $vars
@return array | [
"Add",
"query",
"var",
"filter"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/API/QueryHighJack.php#L54-L63 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.