repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
sellerlabs/injected | src/SellerLabs/Injected/InjectedTrait.php | InjectedTrait.mockDependencies | protected function mockDependencies()
{
$dependencies = $this->getDependencyMapping();
foreach ($dependencies as $interface => $memberName) {
if (!isset($this->$memberName)) {
$this->$memberName = Mockery::mock($interface);
}
// Update with the actual instance.
$dependencies[$interface] = $this->$memberName;
}
return $dependencies;
} | php | protected function mockDependencies()
{
$dependencies = $this->getDependencyMapping();
foreach ($dependencies as $interface => $memberName) {
if (!isset($this->$memberName)) {
$this->$memberName = Mockery::mock($interface);
}
// Update with the actual instance.
$dependencies[$interface] = $this->$memberName;
}
return $dependencies;
} | [
"protected",
"function",
"mockDependencies",
"(",
")",
"{",
"$",
"dependencies",
"=",
"$",
"this",
"->",
"getDependencyMapping",
"(",
")",
";",
"foreach",
"(",
"$",
"dependencies",
"as",
"$",
"interface",
"=>",
"$",
"memberName",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"$",
"memberName",
")",
")",
"{",
"$",
"this",
"->",
"$",
"memberName",
"=",
"Mockery",
"::",
"mock",
"(",
"$",
"interface",
")",
";",
"}",
"// Update with the actual instance.",
"$",
"dependencies",
"[",
"$",
"interface",
"]",
"=",
"$",
"this",
"->",
"$",
"memberName",
";",
"}",
"return",
"$",
"dependencies",
";",
"}"
] | Mock all dependencies that were not set yet
@return array
@throws Exception | [
"Mock",
"all",
"dependencies",
"that",
"were",
"not",
"set",
"yet"
] | 89f90334ccc392c67c79fb1eba258b34cfa9edd6 | https://github.com/sellerlabs/injected/blob/89f90334ccc392c67c79fb1eba258b34cfa9edd6/src/SellerLabs/Injected/InjectedTrait.php#L77-L91 | train |
hal-platform/hal-core | src/VersionControl/GitHub/GitHubDownloader.php | GitHubDownloader.download | public function download(Application $application, string $commit, string $targetFile): bool
{
$username = $application->parameter('gh.owner');
$repository = $application->parameter('gh.repo');
if (!$username || !$repository) {
throw new VCSException(self::ERR_APP_MISCONFIGURED);
}
$endpoint = implode('/', [
'repos',
rawurlencode($username),
rawurlencode($repository),
'tarball',
rawurlencode($commit),
]);
$options = [
'sink' => new LazyOpenStream($targetFile, 'w+'),
];
try {
$response = $this->guzzle->request('GET', $endpoint, $options);
} catch (Exception $e) {
throw new VCSException($e->getMessage(), $e->getCode(), $e);
}
return ($response->getStatusCode() === 200);
} | php | public function download(Application $application, string $commit, string $targetFile): bool
{
$username = $application->parameter('gh.owner');
$repository = $application->parameter('gh.repo');
if (!$username || !$repository) {
throw new VCSException(self::ERR_APP_MISCONFIGURED);
}
$endpoint = implode('/', [
'repos',
rawurlencode($username),
rawurlencode($repository),
'tarball',
rawurlencode($commit),
]);
$options = [
'sink' => new LazyOpenStream($targetFile, 'w+'),
];
try {
$response = $this->guzzle->request('GET', $endpoint, $options);
} catch (Exception $e) {
throw new VCSException($e->getMessage(), $e->getCode(), $e);
}
return ($response->getStatusCode() === 200);
} | [
"public",
"function",
"download",
"(",
"Application",
"$",
"application",
",",
"string",
"$",
"commit",
",",
"string",
"$",
"targetFile",
")",
":",
"bool",
"{",
"$",
"username",
"=",
"$",
"application",
"->",
"parameter",
"(",
"'gh.owner'",
")",
";",
"$",
"repository",
"=",
"$",
"application",
"->",
"parameter",
"(",
"'gh.repo'",
")",
";",
"if",
"(",
"!",
"$",
"username",
"||",
"!",
"$",
"repository",
")",
"{",
"throw",
"new",
"VCSException",
"(",
"self",
"::",
"ERR_APP_MISCONFIGURED",
")",
";",
"}",
"$",
"endpoint",
"=",
"implode",
"(",
"'/'",
",",
"[",
"'repos'",
",",
"rawurlencode",
"(",
"$",
"username",
")",
",",
"rawurlencode",
"(",
"$",
"repository",
")",
",",
"'tarball'",
",",
"rawurlencode",
"(",
"$",
"commit",
")",
",",
"]",
")",
";",
"$",
"options",
"=",
"[",
"'sink'",
"=>",
"new",
"LazyOpenStream",
"(",
"$",
"targetFile",
",",
"'w+'",
")",
",",
"]",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"guzzle",
"->",
"request",
"(",
"'GET'",
",",
"$",
"endpoint",
",",
"$",
"options",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"VCSException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"return",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
"===",
"200",
")",
";",
"}"
] | Get content of archives in a repository
@link http://developer.github.com/v3/repos/contents/
@param Application $application
@param string $commit
@param string $targetFile
@throws VCSException
@return bool | [
"Get",
"content",
"of",
"archives",
"in",
"a",
"repository"
] | 30d456f8392fc873301ad4217d2ae90436c67090 | https://github.com/hal-platform/hal-core/blob/30d456f8392fc873301ad4217d2ae90436c67090/src/VersionControl/GitHub/GitHubDownloader.php#L47-L75 | train |
openclerk/users | src/UserOAuth2.php | UserOAuth2.auth | static function auth(ProviderInterface $provider) {
if (!require_get("code", false)) {
redirect($provider->getAuthorizationUrl());
return false;
} else {
// optionally check for abuse etc
if (!\Openclerk\Events::trigger('oauth2_auth', $provider)) {
throw new UserAuthenticationException("Login was cancelled by the system.");
}
$token = $provider->getAccessToken('authorization_code', array(
'code' => require_get("code"),
));
// now find the relevant user
return $provider->getUserDetails($token);
}
} | php | static function auth(ProviderInterface $provider) {
if (!require_get("code", false)) {
redirect($provider->getAuthorizationUrl());
return false;
} else {
// optionally check for abuse etc
if (!\Openclerk\Events::trigger('oauth2_auth', $provider)) {
throw new UserAuthenticationException("Login was cancelled by the system.");
}
$token = $provider->getAccessToken('authorization_code', array(
'code' => require_get("code"),
));
// now find the relevant user
return $provider->getUserDetails($token);
}
} | [
"static",
"function",
"auth",
"(",
"ProviderInterface",
"$",
"provider",
")",
"{",
"if",
"(",
"!",
"require_get",
"(",
"\"code\"",
",",
"false",
")",
")",
"{",
"redirect",
"(",
"$",
"provider",
"->",
"getAuthorizationUrl",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"// optionally check for abuse etc",
"if",
"(",
"!",
"\\",
"Openclerk",
"\\",
"Events",
"::",
"trigger",
"(",
"'oauth2_auth'",
",",
"$",
"provider",
")",
")",
"{",
"throw",
"new",
"UserAuthenticationException",
"(",
"\"Login was cancelled by the system.\"",
")",
";",
"}",
"$",
"token",
"=",
"$",
"provider",
"->",
"getAccessToken",
"(",
"'authorization_code'",
",",
"array",
"(",
"'code'",
"=>",
"require_get",
"(",
"\"code\"",
")",
",",
")",
")",
";",
"// now find the relevant user",
"return",
"$",
"provider",
"->",
"getUserDetails",
"(",
"$",
"token",
")",
";",
"}",
"}"
] | Execute OAuth2 authentication and return the user. | [
"Execute",
"OAuth2",
"authentication",
"and",
"return",
"the",
"user",
"."
] | 550c7610c154a2f6655ce65a2df377ccb207bc6d | https://github.com/openclerk/users/blob/550c7610c154a2f6655ce65a2df377ccb207bc6d/src/UserOAuth2.php#L66-L83 | train |
openclerk/users | src/UserOAuth2.php | UserOAuth2.removeIdentity | static function removeIdentity(\Db\Connection $db, User $user, $provider, $uid) {
if (!$user) {
throw new \InvalidArgumentException("No user provided.");
}
$q = $db->prepare("DELETE FROM user_oauth2_identities WHERE user_id=? AND provider=? AND uid=? LIMIT 1");
return $q->execute(array($user->getId(), $provider, $uid));
} | php | static function removeIdentity(\Db\Connection $db, User $user, $provider, $uid) {
if (!$user) {
throw new \InvalidArgumentException("No user provided.");
}
$q = $db->prepare("DELETE FROM user_oauth2_identities WHERE user_id=? AND provider=? AND uid=? LIMIT 1");
return $q->execute(array($user->getId(), $provider, $uid));
} | [
"static",
"function",
"removeIdentity",
"(",
"\\",
"Db",
"\\",
"Connection",
"$",
"db",
",",
"User",
"$",
"user",
",",
"$",
"provider",
",",
"$",
"uid",
")",
"{",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"No user provided.\"",
")",
";",
"}",
"$",
"q",
"=",
"$",
"db",
"->",
"prepare",
"(",
"\"DELETE FROM user_oauth2_identities WHERE user_id=? AND provider=? AND uid=? LIMIT 1\"",
")",
";",
"return",
"$",
"q",
"->",
"execute",
"(",
"array",
"(",
"$",
"user",
"->",
"getId",
"(",
")",
",",
"$",
"provider",
",",
"$",
"uid",
")",
")",
";",
"}"
] | Remove the given OAuth2 identity from the given user. | [
"Remove",
"the",
"given",
"OAuth2",
"identity",
"from",
"the",
"given",
"user",
"."
] | 550c7610c154a2f6655ce65a2df377ccb207bc6d | https://github.com/openclerk/users/blob/550c7610c154a2f6655ce65a2df377ccb207bc6d/src/UserOAuth2.php#L178-L186 | train |
PHPColibri/framework | Database/Query.php | Query.select | public static function select(array $columns = ['*'], ...$joinsColumns)
{
$query = new static(Query\Type::SELECT);
$query->columns['t'] = $columns;
$alias = 'j1';
foreach ($joinsColumns as $joinColumns) {
$query->columns[$alias] = (array)$joinColumns;
$alias++;
}
return $query;
} | php | public static function select(array $columns = ['*'], ...$joinsColumns)
{
$query = new static(Query\Type::SELECT);
$query->columns['t'] = $columns;
$alias = 'j1';
foreach ($joinsColumns as $joinColumns) {
$query->columns[$alias] = (array)$joinColumns;
$alias++;
}
return $query;
} | [
"public",
"static",
"function",
"select",
"(",
"array",
"$",
"columns",
"=",
"[",
"'*'",
"]",
",",
"...",
"$",
"joinsColumns",
")",
"{",
"$",
"query",
"=",
"new",
"static",
"(",
"Query",
"\\",
"Type",
"::",
"SELECT",
")",
";",
"$",
"query",
"->",
"columns",
"[",
"'t'",
"]",
"=",
"$",
"columns",
";",
"$",
"alias",
"=",
"'j1'",
";",
"foreach",
"(",
"$",
"joinsColumns",
"as",
"$",
"joinColumns",
")",
"{",
"$",
"query",
"->",
"columns",
"[",
"$",
"alias",
"]",
"=",
"(",
"array",
")",
"$",
"joinColumns",
";",
"$",
"alias",
"++",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Creates instance of select-type Query.
@param array $columns
@param array $joinsColumns
@return static | [
"Creates",
"instance",
"of",
"select",
"-",
"type",
"Query",
"."
] | 7e5b77141da5e5e7c63afc83592671321ac52f36 | https://github.com/PHPColibri/framework/blob/7e5b77141da5e5e7c63afc83592671321ac52f36/Database/Query.php#L68-L80 | train |
schpill/thin | src/Temp.php | Temp.getTmpPath | protected function getTmpPath()
{
$tmpDir = sys_get_temp_dir();
if (!empty($this->prefix)) {
$tmpDir .= DIRECTORY_SEPARATOR . $this->prefix;
}
$tmpDir .= DIRECTORY_SEPARATOR . uniqid('run-', true);
return $tmpDir;
} | php | protected function getTmpPath()
{
$tmpDir = sys_get_temp_dir();
if (!empty($this->prefix)) {
$tmpDir .= DIRECTORY_SEPARATOR . $this->prefix;
}
$tmpDir .= DIRECTORY_SEPARATOR . uniqid('run-', true);
return $tmpDir;
} | [
"protected",
"function",
"getTmpPath",
"(",
")",
"{",
"$",
"tmpDir",
"=",
"sys_get_temp_dir",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"prefix",
")",
")",
"{",
"$",
"tmpDir",
".=",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"prefix",
";",
"}",
"$",
"tmpDir",
".=",
"DIRECTORY_SEPARATOR",
".",
"uniqid",
"(",
"'run-'",
",",
"true",
")",
";",
"return",
"$",
"tmpDir",
";",
"}"
] | Get path to temp directory
@return string | [
"Get",
"path",
"to",
"temp",
"directory"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Temp.php#L64-L75 | train |
schpill/thin | src/Temp.php | Temp.createTmpFile | public function createTmpFile($suffix = null, $preserve = false)
{
$this->initRunFolder();
$file = uniqid();
if ($suffix) {
$file .= '-' . $suffix;
}
$fileInfo = new \SplFileInfo($this->tmpRunFolder . DIRECTORY_SEPARATOR . $file);
$this->filesystem->touch($fileInfo);
$this->files[] = array(
'file' => $fileInfo,
'preserve' => $preserve
);
$this->filesystem->chmod($fileInfo, 0600);
return $fileInfo;
} | php | public function createTmpFile($suffix = null, $preserve = false)
{
$this->initRunFolder();
$file = uniqid();
if ($suffix) {
$file .= '-' . $suffix;
}
$fileInfo = new \SplFileInfo($this->tmpRunFolder . DIRECTORY_SEPARATOR . $file);
$this->filesystem->touch($fileInfo);
$this->files[] = array(
'file' => $fileInfo,
'preserve' => $preserve
);
$this->filesystem->chmod($fileInfo, 0600);
return $fileInfo;
} | [
"public",
"function",
"createTmpFile",
"(",
"$",
"suffix",
"=",
"null",
",",
"$",
"preserve",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"initRunFolder",
"(",
")",
";",
"$",
"file",
"=",
"uniqid",
"(",
")",
";",
"if",
"(",
"$",
"suffix",
")",
"{",
"$",
"file",
".=",
"'-'",
".",
"$",
"suffix",
";",
"}",
"$",
"fileInfo",
"=",
"new",
"\\",
"SplFileInfo",
"(",
"$",
"this",
"->",
"tmpRunFolder",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"touch",
"(",
"$",
"fileInfo",
")",
";",
"$",
"this",
"->",
"files",
"[",
"]",
"=",
"array",
"(",
"'file'",
"=>",
"$",
"fileInfo",
",",
"'preserve'",
"=>",
"$",
"preserve",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"chmod",
"(",
"$",
"fileInfo",
",",
"0600",
")",
";",
"return",
"$",
"fileInfo",
";",
"}"
] | Create empty file in TMP directory
@param string $suffix filename suffix
@param bool $preserve
@throws \Exception
@return \SplFileInfo | [
"Create",
"empty",
"file",
"in",
"TMP",
"directory"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Temp.php#L95-L116 | train |
schpill/thin | src/Temp.php | Temp.createFile | public function createFile($fileName, $preserve = false)
{
$this->initRunFolder();
$fileInfo = new \SplFileInfo($this->tmpRunFolder . DIRECTORY_SEPARATOR . $fileName);
$this->filesystem->touch($fileInfo);
$this->files[] = array(
'file' => $fileInfo,
'preserve' => $preserve
);
$this->filesystem->chmod($fileInfo, 0600);
return $fileInfo;
} | php | public function createFile($fileName, $preserve = false)
{
$this->initRunFolder();
$fileInfo = new \SplFileInfo($this->tmpRunFolder . DIRECTORY_SEPARATOR . $fileName);
$this->filesystem->touch($fileInfo);
$this->files[] = array(
'file' => $fileInfo,
'preserve' => $preserve
);
$this->filesystem->chmod($fileInfo, 0600);
return $fileInfo;
} | [
"public",
"function",
"createFile",
"(",
"$",
"fileName",
",",
"$",
"preserve",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"initRunFolder",
"(",
")",
";",
"$",
"fileInfo",
"=",
"new",
"\\",
"SplFileInfo",
"(",
"$",
"this",
"->",
"tmpRunFolder",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"fileName",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"touch",
"(",
"$",
"fileInfo",
")",
";",
"$",
"this",
"->",
"files",
"[",
"]",
"=",
"array",
"(",
"'file'",
"=>",
"$",
"fileInfo",
",",
"'preserve'",
"=>",
"$",
"preserve",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"chmod",
"(",
"$",
"fileInfo",
",",
"0600",
")",
";",
"return",
"$",
"fileInfo",
";",
"}"
] | Creates named temporary file
@param $fileName
@param bool $preserve
@return \SplFileInfo
@throws \Exception | [
"Creates",
"named",
"temporary",
"file"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Temp.php#L126-L142 | train |
Vyki/mva-dbm | src/Mva/Dbm/Query/QueryProcessor.php | QueryProcessor.processUpdate | public function processUpdate(array $data)
{
$set = $this->formatCmd('set');
$data[$set] = isset($data[$set]) ? $data[$set] : [];
foreach ($data as $index => $value) {
if (substr($index, 0, 1) !== $this->cmd) {
$data[$set][$index] = $value;
unset($data[$index]);
continue;
}
$ckey = substr($index, 1);
if ($ckey === 'unset') {
$data[$index] = array_fill_keys(array_values((array) $value), '');
} elseif (in_array($ckey, ['setOnInsert', 'addToSet', 'push'])) {
$data[$index] = $this->processData($value);
}
}
if (empty($data[$set])) {
unset($data[$set]);
} else {
$data[$set] = $this->processData($data[$set]);
}
return $data;
} | php | public function processUpdate(array $data)
{
$set = $this->formatCmd('set');
$data[$set] = isset($data[$set]) ? $data[$set] : [];
foreach ($data as $index => $value) {
if (substr($index, 0, 1) !== $this->cmd) {
$data[$set][$index] = $value;
unset($data[$index]);
continue;
}
$ckey = substr($index, 1);
if ($ckey === 'unset') {
$data[$index] = array_fill_keys(array_values((array) $value), '');
} elseif (in_array($ckey, ['setOnInsert', 'addToSet', 'push'])) {
$data[$index] = $this->processData($value);
}
}
if (empty($data[$set])) {
unset($data[$set]);
} else {
$data[$set] = $this->processData($data[$set]);
}
return $data;
} | [
"public",
"function",
"processUpdate",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"set",
"=",
"$",
"this",
"->",
"formatCmd",
"(",
"'set'",
")",
";",
"$",
"data",
"[",
"$",
"set",
"]",
"=",
"isset",
"(",
"$",
"data",
"[",
"$",
"set",
"]",
")",
"?",
"$",
"data",
"[",
"$",
"set",
"]",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"index",
",",
"0",
",",
"1",
")",
"!==",
"$",
"this",
"->",
"cmd",
")",
"{",
"$",
"data",
"[",
"$",
"set",
"]",
"[",
"$",
"index",
"]",
"=",
"$",
"value",
";",
"unset",
"(",
"$",
"data",
"[",
"$",
"index",
"]",
")",
";",
"continue",
";",
"}",
"$",
"ckey",
"=",
"substr",
"(",
"$",
"index",
",",
"1",
")",
";",
"if",
"(",
"$",
"ckey",
"===",
"'unset'",
")",
"{",
"$",
"data",
"[",
"$",
"index",
"]",
"=",
"array_fill_keys",
"(",
"array_values",
"(",
"(",
"array",
")",
"$",
"value",
")",
",",
"''",
")",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"ckey",
",",
"[",
"'setOnInsert'",
",",
"'addToSet'",
",",
"'push'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"processData",
"(",
"$",
"value",
")",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"$",
"set",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"$",
"set",
"]",
")",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"set",
"]",
"=",
"$",
"this",
"->",
"processData",
"(",
"$",
"data",
"[",
"$",
"set",
"]",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Process update data
@param array ['a' => 1, 'b%s' => 2, '$set' => ['c%i' => '3'], '$unset' => ['d', 'e'], ...]
@return array ['$set' => ['a' => 1, 'b' => '2', 'c' => 3], '$unset' => ['d' => '', 'e' => ''], ...] | [
"Process",
"update",
"data"
] | 587d840e0620331a9f63a6867f3400a293a9d3c6 | https://github.com/Vyki/mva-dbm/blob/587d840e0620331a9f63a6867f3400a293a9d3c6/src/Mva/Dbm/Query/QueryProcessor.php#L98-L128 | train |
Vyki/mva-dbm | src/Mva/Dbm/Query/QueryProcessor.php | QueryProcessor.processCondition | public function processCondition(array $conditions, $depth = 0)
{
if (empty($conditions)) {
return [];
}
$parsed = [];
foreach ($conditions as $key => $condition) {
if (is_int($key)) {
if ($depth > 0 && is_array($condition)) {
throw new InvalidArgumentException('Too deep sets of condition!');
}
if (is_array($condition)) {
$parsed = array_merge($parsed, $this->processCondition($condition, $depth + 1));
} else {
$parsed[] = $this->parseCondition($condition);
}
} else {
$parsed[] = $this->parseCondition($key, $condition);
}
}
return $depth > 0 ? $parsed : (count($parsed) > 1 ? [$this->formatCmd('and') => $parsed] : $parsed[0]);
} | php | public function processCondition(array $conditions, $depth = 0)
{
if (empty($conditions)) {
return [];
}
$parsed = [];
foreach ($conditions as $key => $condition) {
if (is_int($key)) {
if ($depth > 0 && is_array($condition)) {
throw new InvalidArgumentException('Too deep sets of condition!');
}
if (is_array($condition)) {
$parsed = array_merge($parsed, $this->processCondition($condition, $depth + 1));
} else {
$parsed[] = $this->parseCondition($condition);
}
} else {
$parsed[] = $this->parseCondition($key, $condition);
}
}
return $depth > 0 ? $parsed : (count($parsed) > 1 ? [$this->formatCmd('and') => $parsed] : $parsed[0]);
} | [
"public",
"function",
"processCondition",
"(",
"array",
"$",
"conditions",
",",
"$",
"depth",
"=",
"0",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"conditions",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"parsed",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"conditions",
"as",
"$",
"key",
"=>",
"$",
"condition",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"$",
"depth",
">",
"0",
"&&",
"is_array",
"(",
"$",
"condition",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Too deep sets of condition!'",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"condition",
")",
")",
"{",
"$",
"parsed",
"=",
"array_merge",
"(",
"$",
"parsed",
",",
"$",
"this",
"->",
"processCondition",
"(",
"$",
"condition",
",",
"$",
"depth",
"+",
"1",
")",
")",
";",
"}",
"else",
"{",
"$",
"parsed",
"[",
"]",
"=",
"$",
"this",
"->",
"parseCondition",
"(",
"$",
"condition",
")",
";",
"}",
"}",
"else",
"{",
"$",
"parsed",
"[",
"]",
"=",
"$",
"this",
"->",
"parseCondition",
"(",
"$",
"key",
",",
"$",
"condition",
")",
";",
"}",
"}",
"return",
"$",
"depth",
">",
"0",
"?",
"$",
"parsed",
":",
"(",
"count",
"(",
"$",
"parsed",
")",
">",
"1",
"?",
"[",
"$",
"this",
"->",
"formatCmd",
"(",
"'and'",
")",
"=>",
"$",
"parsed",
"]",
":",
"$",
"parsed",
"[",
"0",
"]",
")",
";",
"}"
] | Process sets of conditions and merges them by AND operator
@param array in format [['a' => 1], ['b IN' => [1, 2]], [...]] or ['a' => 1, 'b IN' => [1, 2], ...]
@param array single condition ['a' => 1] or multiple condition ['$and' => ['a' => 1, 'b' => ['$in' => [1, 2]]], ...] | [
"Process",
"sets",
"of",
"conditions",
"and",
"merges",
"them",
"by",
"AND",
"operator"
] | 587d840e0620331a9f63a6867f3400a293a9d3c6 | https://github.com/Vyki/mva-dbm/blob/587d840e0620331a9f63a6867f3400a293a9d3c6/src/Mva/Dbm/Query/QueryProcessor.php#L135-L159 | train |
Vyki/mva-dbm | src/Mva/Dbm/Query/QueryProcessor.php | QueryProcessor.parseCondition | private function parseCondition($condition, $parameters = [])
{
if (strpos($condition, ' ')) {
$match = preg_match('~^
(.+)\s ## identifier
(
(?:\$\w+) | ## $mongoOperator
(?:[A-Z]+(?:_[A-Z]+)*) | ## NAMED_OPERATOR or
(?:[\<\>\!]?\=|\>|\<\>?) ## logical operator
)
(?:
\s%(\w+(?:\[\])?) | ## modifier or
\s(.+) ## value
)?$~xs', $condition, $cond);
//['cond IN' => [...]], ['cond = %s' => 'param'], ['cond $gt' => 20]
if (!empty($match)) {
if (substr($cond[1], 0, 1) === $this->cmd) {
throw new InvalidArgumentException("Field name cannot start with '{$this->cmd}'");
}
if ($parameters === [] && !isset($cond[4])) {
throw new InvalidArgumentException("Missing value for item '{$cond[1]}'");
}
return $this->formatCondition($cond[1], trim($cond[2], $this->cmd), isset($cond[4]) ? $cond[4] : $parameters, isset($cond[3]) ? $cond[3] : NULL);
}
}
if ($parameters === []) {
throw new InvalidArgumentException("Missing value for item '{$condition}'");
}
if (is_array($parameters) && ($value = reset($parameters))) {
//['$cond' => $param[]]
if (substr($condition, 0, 1) === $this->cmd) {
return [$condition => $this->parseDeepCondition($parameters, TRUE)];
}
//['cond' => ['param', ...]]
if (substr($key = key($parameters), 0, 1) !== $this->cmd) {
return $this->formatCondition($condition, 'IN', $parameters);
}
//['cond' => ['$param' => [...]]]
if (is_array($value)) {
return [$condition => [$key => $this->parseDeepCondition($value)]];
}
}
// [cond => param]
return [$condition => $parameters];
} | php | private function parseCondition($condition, $parameters = [])
{
if (strpos($condition, ' ')) {
$match = preg_match('~^
(.+)\s ## identifier
(
(?:\$\w+) | ## $mongoOperator
(?:[A-Z]+(?:_[A-Z]+)*) | ## NAMED_OPERATOR or
(?:[\<\>\!]?\=|\>|\<\>?) ## logical operator
)
(?:
\s%(\w+(?:\[\])?) | ## modifier or
\s(.+) ## value
)?$~xs', $condition, $cond);
//['cond IN' => [...]], ['cond = %s' => 'param'], ['cond $gt' => 20]
if (!empty($match)) {
if (substr($cond[1], 0, 1) === $this->cmd) {
throw new InvalidArgumentException("Field name cannot start with '{$this->cmd}'");
}
if ($parameters === [] && !isset($cond[4])) {
throw new InvalidArgumentException("Missing value for item '{$cond[1]}'");
}
return $this->formatCondition($cond[1], trim($cond[2], $this->cmd), isset($cond[4]) ? $cond[4] : $parameters, isset($cond[3]) ? $cond[3] : NULL);
}
}
if ($parameters === []) {
throw new InvalidArgumentException("Missing value for item '{$condition}'");
}
if (is_array($parameters) && ($value = reset($parameters))) {
//['$cond' => $param[]]
if (substr($condition, 0, 1) === $this->cmd) {
return [$condition => $this->parseDeepCondition($parameters, TRUE)];
}
//['cond' => ['param', ...]]
if (substr($key = key($parameters), 0, 1) !== $this->cmd) {
return $this->formatCondition($condition, 'IN', $parameters);
}
//['cond' => ['$param' => [...]]]
if (is_array($value)) {
return [$condition => [$key => $this->parseDeepCondition($value)]];
}
}
// [cond => param]
return [$condition => $parameters];
} | [
"private",
"function",
"parseCondition",
"(",
"$",
"condition",
",",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"condition",
",",
"' '",
")",
")",
"{",
"$",
"match",
"=",
"preg_match",
"(",
"'~^\n\t\t\t\t(.+)\\s ## identifier \n\t\t\t\t(\n\t\t\t\t\t(?:\\$\\w+) | ## $mongoOperator\n\t\t\t\t\t(?:[A-Z]+(?:_[A-Z]+)*) | ## NAMED_OPERATOR or \n\t\t\t\t\t(?:[\\<\\>\\!]?\\=|\\>|\\<\\>?) ## logical operator\n\t\t\t\t)\t\n\t\t\t\t(?:\n\t\t\t\t\t\\s%(\\w+(?:\\[\\])?) | ## modifier or\n\t\t\t\t\t\\s(.+) ## value\n\t\t\t\t)?$~xs'",
",",
"$",
"condition",
",",
"$",
"cond",
")",
";",
"//['cond IN' => [...]], ['cond = %s' => 'param'], ['cond $gt' => 20]",
"if",
"(",
"!",
"empty",
"(",
"$",
"match",
")",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"cond",
"[",
"1",
"]",
",",
"0",
",",
"1",
")",
"===",
"$",
"this",
"->",
"cmd",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Field name cannot start with '{$this->cmd}'\"",
")",
";",
"}",
"if",
"(",
"$",
"parameters",
"===",
"[",
"]",
"&&",
"!",
"isset",
"(",
"$",
"cond",
"[",
"4",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Missing value for item '{$cond[1]}'\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"formatCondition",
"(",
"$",
"cond",
"[",
"1",
"]",
",",
"trim",
"(",
"$",
"cond",
"[",
"2",
"]",
",",
"$",
"this",
"->",
"cmd",
")",
",",
"isset",
"(",
"$",
"cond",
"[",
"4",
"]",
")",
"?",
"$",
"cond",
"[",
"4",
"]",
":",
"$",
"parameters",
",",
"isset",
"(",
"$",
"cond",
"[",
"3",
"]",
")",
"?",
"$",
"cond",
"[",
"3",
"]",
":",
"NULL",
")",
";",
"}",
"}",
"if",
"(",
"$",
"parameters",
"===",
"[",
"]",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Missing value for item '{$condition}'\"",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"parameters",
")",
"&&",
"(",
"$",
"value",
"=",
"reset",
"(",
"$",
"parameters",
")",
")",
")",
"{",
"//['$cond' => $param[]]",
"if",
"(",
"substr",
"(",
"$",
"condition",
",",
"0",
",",
"1",
")",
"===",
"$",
"this",
"->",
"cmd",
")",
"{",
"return",
"[",
"$",
"condition",
"=>",
"$",
"this",
"->",
"parseDeepCondition",
"(",
"$",
"parameters",
",",
"TRUE",
")",
"]",
";",
"}",
"//['cond' => ['param', ...]]",
"if",
"(",
"substr",
"(",
"$",
"key",
"=",
"key",
"(",
"$",
"parameters",
")",
",",
"0",
",",
"1",
")",
"!==",
"$",
"this",
"->",
"cmd",
")",
"{",
"return",
"$",
"this",
"->",
"formatCondition",
"(",
"$",
"condition",
",",
"'IN'",
",",
"$",
"parameters",
")",
";",
"}",
"//['cond' => ['$param' => [...]]]",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"[",
"$",
"condition",
"=>",
"[",
"$",
"key",
"=>",
"$",
"this",
"->",
"parseDeepCondition",
"(",
"$",
"value",
")",
"]",
"]",
";",
"}",
"}",
"// [cond => param]",
"return",
"[",
"$",
"condition",
"=>",
"$",
"parameters",
"]",
";",
"}"
] | Parses single condition
@param $condition string
@param $parameters mixed
@throws InvalidArgumentException | [
"Parses",
"single",
"condition"
] | 587d840e0620331a9f63a6867f3400a293a9d3c6 | https://github.com/Vyki/mva-dbm/blob/587d840e0620331a9f63a6867f3400a293a9d3c6/src/Mva/Dbm/Query/QueryProcessor.php#L167-L219 | train |
Vyki/mva-dbm | src/Mva/Dbm/Query/QueryProcessor.php | QueryProcessor.parseDeepCondition | private function parseDeepCondition(array $parameters, $toArray = FALSE)
{
$opcond = [];
foreach ($parameters as $key => $param) {
$ccond = is_int($key) ? $this->parseCondition($param) : $this->parseCondition($key, $param);
if ($toArray) {
$opcond[] = $ccond;
} else {
reset($ccond);
$opcond[key($ccond)] = current($ccond);
}
}
return $opcond;
} | php | private function parseDeepCondition(array $parameters, $toArray = FALSE)
{
$opcond = [];
foreach ($parameters as $key => $param) {
$ccond = is_int($key) ? $this->parseCondition($param) : $this->parseCondition($key, $param);
if ($toArray) {
$opcond[] = $ccond;
} else {
reset($ccond);
$opcond[key($ccond)] = current($ccond);
}
}
return $opcond;
} | [
"private",
"function",
"parseDeepCondition",
"(",
"array",
"$",
"parameters",
",",
"$",
"toArray",
"=",
"FALSE",
")",
"{",
"$",
"opcond",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"param",
")",
"{",
"$",
"ccond",
"=",
"is_int",
"(",
"$",
"key",
")",
"?",
"$",
"this",
"->",
"parseCondition",
"(",
"$",
"param",
")",
":",
"$",
"this",
"->",
"parseCondition",
"(",
"$",
"key",
",",
"$",
"param",
")",
";",
"if",
"(",
"$",
"toArray",
")",
"{",
"$",
"opcond",
"[",
"]",
"=",
"$",
"ccond",
";",
"}",
"else",
"{",
"reset",
"(",
"$",
"ccond",
")",
";",
"$",
"opcond",
"[",
"key",
"(",
"$",
"ccond",
")",
"]",
"=",
"current",
"(",
"$",
"ccond",
")",
";",
"}",
"}",
"return",
"$",
"opcond",
";",
"}"
] | Parses inner conditions
@param array
@param bool indicates that output should be list | [
"Parses",
"inner",
"conditions"
] | 587d840e0620331a9f63a6867f3400a293a9d3c6 | https://github.com/Vyki/mva-dbm/blob/587d840e0620331a9f63a6867f3400a293a9d3c6/src/Mva/Dbm/Query/QueryProcessor.php#L226-L242 | train |
Vyki/mva-dbm | src/Mva/Dbm/Query/QueryProcessor.php | QueryProcessor.processData | public function processData(array $data, $expand = FALSE)
{
$return = [];
foreach ($data as $key => $item) {
list($modified, $key) = $this->doubledModifier($key, '%');
if ($modified && preg_match('#^(.*)%(\w+(?:\[\])?)$#', $key, $parts)) {
$key = $parts[1];
$item = $this->processModifier($parts[2], $item);
} elseif ($item instanceof \DateTime || $item instanceof \DateTimeImmutable) {
$item = $this->processModifier('dt', $item);
} elseif (is_array($item)) {
$item = $this->processData($item);
}
if ($expand && strpos($key, '.') !== FALSE) {
Helpers::expandRow($return, $key, $item);
} else {
$return[$key] = $item;
}
}
return $return;
} | php | public function processData(array $data, $expand = FALSE)
{
$return = [];
foreach ($data as $key => $item) {
list($modified, $key) = $this->doubledModifier($key, '%');
if ($modified && preg_match('#^(.*)%(\w+(?:\[\])?)$#', $key, $parts)) {
$key = $parts[1];
$item = $this->processModifier($parts[2], $item);
} elseif ($item instanceof \DateTime || $item instanceof \DateTimeImmutable) {
$item = $this->processModifier('dt', $item);
} elseif (is_array($item)) {
$item = $this->processData($item);
}
if ($expand && strpos($key, '.') !== FALSE) {
Helpers::expandRow($return, $key, $item);
} else {
$return[$key] = $item;
}
}
return $return;
} | [
"public",
"function",
"processData",
"(",
"array",
"$",
"data",
",",
"$",
"expand",
"=",
"FALSE",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"list",
"(",
"$",
"modified",
",",
"$",
"key",
")",
"=",
"$",
"this",
"->",
"doubledModifier",
"(",
"$",
"key",
",",
"'%'",
")",
";",
"if",
"(",
"$",
"modified",
"&&",
"preg_match",
"(",
"'#^(.*)%(\\w+(?:\\[\\])?)$#'",
",",
"$",
"key",
",",
"$",
"parts",
")",
")",
"{",
"$",
"key",
"=",
"$",
"parts",
"[",
"1",
"]",
";",
"$",
"item",
"=",
"$",
"this",
"->",
"processModifier",
"(",
"$",
"parts",
"[",
"2",
"]",
",",
"$",
"item",
")",
";",
"}",
"elseif",
"(",
"$",
"item",
"instanceof",
"\\",
"DateTime",
"||",
"$",
"item",
"instanceof",
"\\",
"DateTimeImmutable",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"processModifier",
"(",
"'dt'",
",",
"$",
"item",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"item",
")",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"processData",
"(",
"$",
"item",
")",
";",
"}",
"if",
"(",
"$",
"expand",
"&&",
"strpos",
"(",
"$",
"key",
",",
"'.'",
")",
"!==",
"FALSE",
")",
"{",
"Helpers",
"::",
"expandRow",
"(",
"$",
"return",
",",
"$",
"key",
",",
"$",
"item",
")",
";",
"}",
"else",
"{",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | Formats data types by modifiers
@param array ['name' => 'roman', 'age%i' => '27', 'numbers%i[]' => ['1', 2, 2.3]]
@return array | [
"Formats",
"data",
"types",
"by",
"modifiers"
] | 587d840e0620331a9f63a6867f3400a293a9d3c6 | https://github.com/Vyki/mva-dbm/blob/587d840e0620331a9f63a6867f3400a293a9d3c6/src/Mva/Dbm/Query/QueryProcessor.php#L294-L318 | train |
Vyki/mva-dbm | src/Mva/Dbm/Query/QueryProcessor.php | QueryProcessor.processLikeOperator | protected function processLikeOperator($value)
{
$value = preg_quote($value);
$value = substr($value, 0, 1) === '%' ? (substr($value, -1, 1) === '%' ? substr($value, 1, -1) : substr($value, 1) . '$') : (substr($value, -1, 1) === '%' ? '^' . substr($value, 0, -1) : $value);
return '/' . $value . '/i';
} | php | protected function processLikeOperator($value)
{
$value = preg_quote($value);
$value = substr($value, 0, 1) === '%' ? (substr($value, -1, 1) === '%' ? substr($value, 1, -1) : substr($value, 1) . '$') : (substr($value, -1, 1) === '%' ? '^' . substr($value, 0, -1) : $value);
return '/' . $value . '/i';
} | [
"protected",
"function",
"processLikeOperator",
"(",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"preg_quote",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"1",
")",
"===",
"'%'",
"?",
"(",
"substr",
"(",
"$",
"value",
",",
"-",
"1",
",",
"1",
")",
"===",
"'%'",
"?",
"substr",
"(",
"$",
"value",
",",
"1",
",",
"-",
"1",
")",
":",
"substr",
"(",
"$",
"value",
",",
"1",
")",
".",
"'$'",
")",
":",
"(",
"substr",
"(",
"$",
"value",
",",
"-",
"1",
",",
"1",
")",
"===",
"'%'",
"?",
"'^'",
".",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"-",
"1",
")",
":",
"$",
"value",
")",
";",
"return",
"'/'",
".",
"$",
"value",
".",
"'/i'",
";",
"}"
] | Converts SQL LIKE to MongoRegex
@param string value with wildcard - %test, test%, %test% | [
"Converts",
"SQL",
"LIKE",
"to",
"MongoRegex"
] | 587d840e0620331a9f63a6867f3400a293a9d3c6 | https://github.com/Vyki/mva-dbm/blob/587d840e0620331a9f63a6867f3400a293a9d3c6/src/Mva/Dbm/Query/QueryProcessor.php#L419-L425 | train |
Vyki/mva-dbm | src/Mva/Dbm/Query/QueryProcessor.php | QueryProcessor.processArray | protected function processArray($modifier, array &$values)
{
foreach ($values as &$item) {
$item = $this->processModifier($modifier, $item);
}
} | php | protected function processArray($modifier, array &$values)
{
foreach ($values as &$item) {
$item = $this->processModifier($modifier, $item);
}
} | [
"protected",
"function",
"processArray",
"(",
"$",
"modifier",
",",
"array",
"&",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"&",
"$",
"item",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"processModifier",
"(",
"$",
"modifier",
",",
"$",
"item",
")",
";",
"}",
"}"
] | Applies modifier to the inner array via reference
@param string modifier
@param array sets of values | [
"Applies",
"modifier",
"to",
"the",
"inner",
"array",
"via",
"reference"
] | 587d840e0620331a9f63a6867f3400a293a9d3c6 | https://github.com/Vyki/mva-dbm/blob/587d840e0620331a9f63a6867f3400a293a9d3c6/src/Mva/Dbm/Query/QueryProcessor.php#L433-L438 | train |
dotkernel/dot-session | src/ConfigProvider.php | ConfigProvider.getDependencyConfig | public function getDependencyConfig(): array
{
return [
'aliases' => [
SessionManager::class => ManagerInterface::class,
],
'factories' => [
ConfigInterface::class => SessionConfigFactory::class,
ManagerInterface::class => SessionManagerFactory::class,
StorageInterface::class => StorageFactory::class,
SessionOptions::class => SessionOptionsFactory::class,
SessionMiddleware::class => SessionMiddlewareFactory::class,
],
'abstract_factories' => [
ContainerAbstractServiceFactory::class,
]
];
} | php | public function getDependencyConfig(): array
{
return [
'aliases' => [
SessionManager::class => ManagerInterface::class,
],
'factories' => [
ConfigInterface::class => SessionConfigFactory::class,
ManagerInterface::class => SessionManagerFactory::class,
StorageInterface::class => StorageFactory::class,
SessionOptions::class => SessionOptionsFactory::class,
SessionMiddleware::class => SessionMiddlewareFactory::class,
],
'abstract_factories' => [
ContainerAbstractServiceFactory::class,
]
];
} | [
"public",
"function",
"getDependencyConfig",
"(",
")",
":",
"array",
"{",
"return",
"[",
"'aliases'",
"=>",
"[",
"SessionManager",
"::",
"class",
"=>",
"ManagerInterface",
"::",
"class",
",",
"]",
",",
"'factories'",
"=>",
"[",
"ConfigInterface",
"::",
"class",
"=>",
"SessionConfigFactory",
"::",
"class",
",",
"ManagerInterface",
"::",
"class",
"=>",
"SessionManagerFactory",
"::",
"class",
",",
"StorageInterface",
"::",
"class",
"=>",
"StorageFactory",
"::",
"class",
",",
"SessionOptions",
"::",
"class",
"=>",
"SessionOptionsFactory",
"::",
"class",
",",
"SessionMiddleware",
"::",
"class",
"=>",
"SessionMiddlewareFactory",
"::",
"class",
",",
"]",
",",
"'abstract_factories'",
"=>",
"[",
"ContainerAbstractServiceFactory",
"::",
"class",
",",
"]",
"]",
";",
"}"
] | Merge our config with Zend Session dependencies
@return array | [
"Merge",
"our",
"config",
"with",
"Zend",
"Session",
"dependencies"
] | 9808072c807a9cc708a0cae5475a29f70e3f450e | https://github.com/dotkernel/dot-session/blob/9808072c807a9cc708a0cae5475a29f70e3f450e/src/ConfigProvider.php#L70-L88 | train |
mvccore/ext-view-helper-assets | src/MvcCore/Ext/Views/Helpers/Assets.php | Assets.& | public function & SetView (\MvcCore\IView & $view) {
parent::SetView($view);
if (self::$appRoot === NULL) self::$appRoot = $this->request->GetAppRoot();
if (self::$basePath === NULL) self::$basePath = $this->request->GetBasePath();
if (self::$scriptName === NULL) self::$scriptName = ltrim($this->request->GetScriptName(), '/.');
$app = $view->GetController()->GetApplication();
$configClass =$app->GetConfigClass();
self::$loggingAndExceptions = $configClass::IsDevelopment(TRUE);
$mvcCoreCompiledMode = $app->GetCompiled();
self::$ctrlActionKey = $this->request->GetControllerName() . '/' . $this->request->GetActionName();
// file checking is true only for classic development mode, not for single file mode
if (!$mvcCoreCompiledMode) self::$fileChecking = TRUE;
// file rendering is true for classic development state, SFU app mode
if (!$mvcCoreCompiledMode || $mvcCoreCompiledMode == 'SFU') {
self::$fileRendering = TRUE;
}
if (is_null(self::$assetsUrlCompletion)) {
// set URL addresses completion to true by default for:
// - all package modes outside PHP_STRICT_HDD and outside development
if ($mvcCoreCompiledMode && $mvcCoreCompiledMode != 'PHP_STRICT_HDD') {
self::$assetsUrlCompletion = TRUE;
} else {
self::$assetsUrlCompletion = FALSE;
}
}
self::$systemConfigHash = md5(json_encode(self::$globalOptions));
return $this;
} | php | public function & SetView (\MvcCore\IView & $view) {
parent::SetView($view);
if (self::$appRoot === NULL) self::$appRoot = $this->request->GetAppRoot();
if (self::$basePath === NULL) self::$basePath = $this->request->GetBasePath();
if (self::$scriptName === NULL) self::$scriptName = ltrim($this->request->GetScriptName(), '/.');
$app = $view->GetController()->GetApplication();
$configClass =$app->GetConfigClass();
self::$loggingAndExceptions = $configClass::IsDevelopment(TRUE);
$mvcCoreCompiledMode = $app->GetCompiled();
self::$ctrlActionKey = $this->request->GetControllerName() . '/' . $this->request->GetActionName();
// file checking is true only for classic development mode, not for single file mode
if (!$mvcCoreCompiledMode) self::$fileChecking = TRUE;
// file rendering is true for classic development state, SFU app mode
if (!$mvcCoreCompiledMode || $mvcCoreCompiledMode == 'SFU') {
self::$fileRendering = TRUE;
}
if (is_null(self::$assetsUrlCompletion)) {
// set URL addresses completion to true by default for:
// - all package modes outside PHP_STRICT_HDD and outside development
if ($mvcCoreCompiledMode && $mvcCoreCompiledMode != 'PHP_STRICT_HDD') {
self::$assetsUrlCompletion = TRUE;
} else {
self::$assetsUrlCompletion = FALSE;
}
}
self::$systemConfigHash = md5(json_encode(self::$globalOptions));
return $this;
} | [
"public",
"function",
"&",
"SetView",
"(",
"\\",
"MvcCore",
"\\",
"IView",
"&",
"$",
"view",
")",
"{",
"parent",
"::",
"SetView",
"(",
"$",
"view",
")",
";",
"if",
"(",
"self",
"::",
"$",
"appRoot",
"===",
"NULL",
")",
"self",
"::",
"$",
"appRoot",
"=",
"$",
"this",
"->",
"request",
"->",
"GetAppRoot",
"(",
")",
";",
"if",
"(",
"self",
"::",
"$",
"basePath",
"===",
"NULL",
")",
"self",
"::",
"$",
"basePath",
"=",
"$",
"this",
"->",
"request",
"->",
"GetBasePath",
"(",
")",
";",
"if",
"(",
"self",
"::",
"$",
"scriptName",
"===",
"NULL",
")",
"self",
"::",
"$",
"scriptName",
"=",
"ltrim",
"(",
"$",
"this",
"->",
"request",
"->",
"GetScriptName",
"(",
")",
",",
"'/.'",
")",
";",
"$",
"app",
"=",
"$",
"view",
"->",
"GetController",
"(",
")",
"->",
"GetApplication",
"(",
")",
";",
"$",
"configClass",
"=",
"$",
"app",
"->",
"GetConfigClass",
"(",
")",
";",
"self",
"::",
"$",
"loggingAndExceptions",
"=",
"$",
"configClass",
"::",
"IsDevelopment",
"(",
"TRUE",
")",
";",
"$",
"mvcCoreCompiledMode",
"=",
"$",
"app",
"->",
"GetCompiled",
"(",
")",
";",
"self",
"::",
"$",
"ctrlActionKey",
"=",
"$",
"this",
"->",
"request",
"->",
"GetControllerName",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"request",
"->",
"GetActionName",
"(",
")",
";",
"// file checking is true only for classic development mode, not for single file mode",
"if",
"(",
"!",
"$",
"mvcCoreCompiledMode",
")",
"self",
"::",
"$",
"fileChecking",
"=",
"TRUE",
";",
"// file rendering is true for classic development state, SFU app mode",
"if",
"(",
"!",
"$",
"mvcCoreCompiledMode",
"||",
"$",
"mvcCoreCompiledMode",
"==",
"'SFU'",
")",
"{",
"self",
"::",
"$",
"fileRendering",
"=",
"TRUE",
";",
"}",
"if",
"(",
"is_null",
"(",
"self",
"::",
"$",
"assetsUrlCompletion",
")",
")",
"{",
"// set URL addresses completion to true by default for:",
"// - all package modes outside PHP_STRICT_HDD and outside development",
"if",
"(",
"$",
"mvcCoreCompiledMode",
"&&",
"$",
"mvcCoreCompiledMode",
"!=",
"'PHP_STRICT_HDD'",
")",
"{",
"self",
"::",
"$",
"assetsUrlCompletion",
"=",
"TRUE",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"assetsUrlCompletion",
"=",
"FALSE",
";",
"}",
"}",
"self",
"::",
"$",
"systemConfigHash",
"=",
"md5",
"(",
"json_encode",
"(",
"self",
"::",
"$",
"globalOptions",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Insert a \MvcCore\View in each helper constructing
@param \MvcCore\View|\MvcCore\IView $view
@return \MvcCore\Ext\Views\Helpers\AbstractHelper | [
"Insert",
"a",
"\\",
"MvcCore",
"\\",
"View",
"in",
"each",
"helper",
"constructing"
] | 5672575aca6d63f2340c912f9b9754bbb896d97b | https://github.com/mvccore/ext-view-helper-assets/blob/5672575aca6d63f2340c912f9b9754bbb896d97b/src/MvcCore/Ext/Views/Helpers/Assets.php#L150-L184 | train |
mvccore/ext-view-helper-assets | src/MvcCore/Ext/Views/Helpers/Assets.php | Assets.CssJsFileUrl | public function CssJsFileUrl ($path = '') {
$result = '';
if (self::$assetsUrlCompletion) {
// for \MvcCore\Application::GetInstance()->GetCompiled() equal to: 'PHAR', 'SFU', 'PHP_STRICT_PACKAGE', 'PHP_PRESERVE_PACKAGE', 'PHP_PRESERVE_HDD'
$result = $this->view->AssetUrl($path);
} else {
// for \MvcCore\Application::GetInstance()->GetCompiled() equal to: '' (development), 'PHP_STRICT_HDD'
$result = self::$basePath . $path;
}
return $result;
} | php | public function CssJsFileUrl ($path = '') {
$result = '';
if (self::$assetsUrlCompletion) {
// for \MvcCore\Application::GetInstance()->GetCompiled() equal to: 'PHAR', 'SFU', 'PHP_STRICT_PACKAGE', 'PHP_PRESERVE_PACKAGE', 'PHP_PRESERVE_HDD'
$result = $this->view->AssetUrl($path);
} else {
// for \MvcCore\Application::GetInstance()->GetCompiled() equal to: '' (development), 'PHP_STRICT_HDD'
$result = self::$basePath . $path;
}
return $result;
} | [
"public",
"function",
"CssJsFileUrl",
"(",
"$",
"path",
"=",
"''",
")",
"{",
"$",
"result",
"=",
"''",
";",
"if",
"(",
"self",
"::",
"$",
"assetsUrlCompletion",
")",
"{",
"// for \\MvcCore\\Application::GetInstance()->GetCompiled() equal to: 'PHAR', 'SFU', 'PHP_STRICT_PACKAGE', 'PHP_PRESERVE_PACKAGE', 'PHP_PRESERVE_HDD'",
"$",
"result",
"=",
"$",
"this",
"->",
"view",
"->",
"AssetUrl",
"(",
"$",
"path",
")",
";",
"}",
"else",
"{",
"// for \\MvcCore\\Application::GetInstance()->GetCompiled() equal to: '' (development), 'PHP_STRICT_HDD'",
"$",
"result",
"=",
"self",
"::",
"$",
"basePath",
".",
"$",
"path",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Completes CSS or JS file url.
If application compile mode is in development state or packed in strict HDD mode,
there is generated standard URL with \MvcCore\Request->GetBasePath() (current app location)
plus called $path param. Because those application compile modes presume by default,
that those files are placed beside php code on hard drive.
If application compile mode is in php preserve package, php preserve HDD,
php strict package or in single file URL mode, there is generated URL by \MvcCore
in form: 'index.php?controller=controller&action=asset&path=...'.
Feel free to change this css/js file URL completion to any custom way.
There could be typically only: "$result = self::$basePath . $path;",
but if you want to complete URL for assets on hard drive or
to any other CDN place, use \MvcCore\Ext\Views\Helpers\Assets::SetBasePath($cdnBasePath);
@param string $path relative path from application document root with slash in begin
@return string | [
"Completes",
"CSS",
"or",
"JS",
"file",
"url",
"."
] | 5672575aca6d63f2340c912f9b9754bbb896d97b | https://github.com/mvccore/ext-view-helper-assets/blob/5672575aca6d63f2340c912f9b9754bbb896d97b/src/MvcCore/Ext/Views/Helpers/Assets.php#L301-L311 | train |
mvccore/ext-view-helper-assets | src/MvcCore/Ext/Views/Helpers/Assets.php | Assets.filterItemsForNotPossibleMinifiedAndPossibleMinifiedItems | protected function filterItemsForNotPossibleMinifiedAndPossibleMinifiedItems ($items) {
$itemsToRenderMinimized = [];
$itemsToRenderSeparately = []; // some configurations is not possible to render together and minimized
// go for every item to complete existing combinations in attributes
foreach ($items as & $item) {
$itemArr = array_merge((array) $item, []);
unset($itemArr['path']);
if (isset($itemArr['render'])) unset($itemArr['render']);
if (isset($itemArr['external'])) unset($itemArr['external']);
$renderArrayKey = md5(json_encode($itemArr));
if ($itemArr['doNotMinify']) {
if (isset($itemsToRenderSeparately[$renderArrayKey])) {
$itemsToRenderSeparately[$renderArrayKey][] = $item;
} else {
$itemsToRenderSeparately[$renderArrayKey] = [$item];
}
} else {
if (isset($itemsToRenderMinimized[$renderArrayKey])) {
$itemsToRenderMinimized[$renderArrayKey][] = $item;
} else {
$itemsToRenderMinimized[$renderArrayKey] = [$item];
}
}
}
return [
$itemsToRenderMinimized,
$itemsToRenderSeparately,
];
} | php | protected function filterItemsForNotPossibleMinifiedAndPossibleMinifiedItems ($items) {
$itemsToRenderMinimized = [];
$itemsToRenderSeparately = []; // some configurations is not possible to render together and minimized
// go for every item to complete existing combinations in attributes
foreach ($items as & $item) {
$itemArr = array_merge((array) $item, []);
unset($itemArr['path']);
if (isset($itemArr['render'])) unset($itemArr['render']);
if (isset($itemArr['external'])) unset($itemArr['external']);
$renderArrayKey = md5(json_encode($itemArr));
if ($itemArr['doNotMinify']) {
if (isset($itemsToRenderSeparately[$renderArrayKey])) {
$itemsToRenderSeparately[$renderArrayKey][] = $item;
} else {
$itemsToRenderSeparately[$renderArrayKey] = [$item];
}
} else {
if (isset($itemsToRenderMinimized[$renderArrayKey])) {
$itemsToRenderMinimized[$renderArrayKey][] = $item;
} else {
$itemsToRenderMinimized[$renderArrayKey] = [$item];
}
}
}
return [
$itemsToRenderMinimized,
$itemsToRenderSeparately,
];
} | [
"protected",
"function",
"filterItemsForNotPossibleMinifiedAndPossibleMinifiedItems",
"(",
"$",
"items",
")",
"{",
"$",
"itemsToRenderMinimized",
"=",
"[",
"]",
";",
"$",
"itemsToRenderSeparately",
"=",
"[",
"]",
";",
"// some configurations is not possible to render together and minimized",
"// go for every item to complete existing combinations in attributes",
"foreach",
"(",
"$",
"items",
"as",
"&",
"$",
"item",
")",
"{",
"$",
"itemArr",
"=",
"array_merge",
"(",
"(",
"array",
")",
"$",
"item",
",",
"[",
"]",
")",
";",
"unset",
"(",
"$",
"itemArr",
"[",
"'path'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"itemArr",
"[",
"'render'",
"]",
")",
")",
"unset",
"(",
"$",
"itemArr",
"[",
"'render'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"itemArr",
"[",
"'external'",
"]",
")",
")",
"unset",
"(",
"$",
"itemArr",
"[",
"'external'",
"]",
")",
";",
"$",
"renderArrayKey",
"=",
"md5",
"(",
"json_encode",
"(",
"$",
"itemArr",
")",
")",
";",
"if",
"(",
"$",
"itemArr",
"[",
"'doNotMinify'",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"itemsToRenderSeparately",
"[",
"$",
"renderArrayKey",
"]",
")",
")",
"{",
"$",
"itemsToRenderSeparately",
"[",
"$",
"renderArrayKey",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"else",
"{",
"$",
"itemsToRenderSeparately",
"[",
"$",
"renderArrayKey",
"]",
"=",
"[",
"$",
"item",
"]",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"itemsToRenderMinimized",
"[",
"$",
"renderArrayKey",
"]",
")",
")",
"{",
"$",
"itemsToRenderMinimized",
"[",
"$",
"renderArrayKey",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"else",
"{",
"$",
"itemsToRenderMinimized",
"[",
"$",
"renderArrayKey",
"]",
"=",
"[",
"$",
"item",
"]",
";",
"}",
"}",
"}",
"return",
"[",
"$",
"itemsToRenderMinimized",
",",
"$",
"itemsToRenderSeparately",
",",
"]",
";",
"}"
] | Look for every item to render if there is any 'doNotMinify' record to render item separately
@param array $items
@return array[] $itemsToRenderMinimized $itemsToRenderSeparately | [
"Look",
"for",
"every",
"item",
"to",
"render",
"if",
"there",
"is",
"any",
"doNotMinify",
"record",
"to",
"render",
"item",
"separately"
] | 5672575aca6d63f2340c912f9b9754bbb896d97b | https://github.com/mvccore/ext-view-helper-assets/blob/5672575aca6d63f2340c912f9b9754bbb896d97b/src/MvcCore/Ext/Views/Helpers/Assets.php#L326-L354 | train |
mvccore/ext-view-helper-assets | src/MvcCore/Ext/Views/Helpers/Assets.php | Assets.addFileModificationImprintToHrefUrl | protected function addFileModificationImprintToHrefUrl ($url, $path) {
$questionMarkPos = strpos($url, '?');
$separator = ($questionMarkPos === FALSE) ? '?' : '&';
$strippedUrl = $questionMarkPos !== FALSE ? substr($url, $questionMarkPos) : $url ;
$srcPath = $this->getAppRoot() . substr($strippedUrl, strlen(self::$basePath));
if (self::$globalOptions['fileChecking'] == 'filemtime') {
$fileMTime = self::getFileImprint($srcPath);
$url .= $separator . '_fmt=' . date(
self::FILE_MODIFICATION_DATE_FORMAT,
(int)$fileMTime
);
} else {
$url .= $separator . '_md5=' . self::getFileImprint($srcPath);
}
return $url;
} | php | protected function addFileModificationImprintToHrefUrl ($url, $path) {
$questionMarkPos = strpos($url, '?');
$separator = ($questionMarkPos === FALSE) ? '?' : '&';
$strippedUrl = $questionMarkPos !== FALSE ? substr($url, $questionMarkPos) : $url ;
$srcPath = $this->getAppRoot() . substr($strippedUrl, strlen(self::$basePath));
if (self::$globalOptions['fileChecking'] == 'filemtime') {
$fileMTime = self::getFileImprint($srcPath);
$url .= $separator . '_fmt=' . date(
self::FILE_MODIFICATION_DATE_FORMAT,
(int)$fileMTime
);
} else {
$url .= $separator . '_md5=' . self::getFileImprint($srcPath);
}
return $url;
} | [
"protected",
"function",
"addFileModificationImprintToHrefUrl",
"(",
"$",
"url",
",",
"$",
"path",
")",
"{",
"$",
"questionMarkPos",
"=",
"strpos",
"(",
"$",
"url",
",",
"'?'",
")",
";",
"$",
"separator",
"=",
"(",
"$",
"questionMarkPos",
"===",
"FALSE",
")",
"?",
"'?'",
":",
"'&'",
";",
"$",
"strippedUrl",
"=",
"$",
"questionMarkPos",
"!==",
"FALSE",
"?",
"substr",
"(",
"$",
"url",
",",
"$",
"questionMarkPos",
")",
":",
"$",
"url",
";",
"$",
"srcPath",
"=",
"$",
"this",
"->",
"getAppRoot",
"(",
")",
".",
"substr",
"(",
"$",
"strippedUrl",
",",
"strlen",
"(",
"self",
"::",
"$",
"basePath",
")",
")",
";",
"if",
"(",
"self",
"::",
"$",
"globalOptions",
"[",
"'fileChecking'",
"]",
"==",
"'filemtime'",
")",
"{",
"$",
"fileMTime",
"=",
"self",
"::",
"getFileImprint",
"(",
"$",
"srcPath",
")",
";",
"$",
"url",
".=",
"$",
"separator",
".",
"'_fmt='",
".",
"date",
"(",
"self",
"::",
"FILE_MODIFICATION_DATE_FORMAT",
",",
"(",
"int",
")",
"$",
"fileMTime",
")",
";",
"}",
"else",
"{",
"$",
"url",
".=",
"$",
"separator",
".",
"'_md5='",
".",
"self",
"::",
"getFileImprint",
"(",
"$",
"srcPath",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Add to href URL file modification param by original file
@param string $url
@param string $path
@return string | [
"Add",
"to",
"href",
"URL",
"file",
"modification",
"param",
"by",
"original",
"file"
] | 5672575aca6d63f2340c912f9b9754bbb896d97b | https://github.com/mvccore/ext-view-helper-assets/blob/5672575aca6d63f2340c912f9b9754bbb896d97b/src/MvcCore/Ext/Views/Helpers/Assets.php#L362-L377 | train |
mvccore/ext-view-helper-assets | src/MvcCore/Ext/Views/Helpers/Assets.php | Assets.getIndentString | protected function getIndentString($indent = 0) {
$indentStr = '';
if (is_numeric($indent)) {
$indInt = intval($indent);
if ($indInt > 0) {
$i = 0;
while ($i < $indInt) {
$indentStr .= "\t";
$i += 1;
}
}
} else if (is_string($indent)) {
$indentStr = $indent;
}
return $indentStr;
} | php | protected function getIndentString($indent = 0) {
$indentStr = '';
if (is_numeric($indent)) {
$indInt = intval($indent);
if ($indInt > 0) {
$i = 0;
while ($i < $indInt) {
$indentStr .= "\t";
$i += 1;
}
}
} else if (is_string($indent)) {
$indentStr = $indent;
}
return $indentStr;
} | [
"protected",
"function",
"getIndentString",
"(",
"$",
"indent",
"=",
"0",
")",
"{",
"$",
"indentStr",
"=",
"''",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"indent",
")",
")",
"{",
"$",
"indInt",
"=",
"intval",
"(",
"$",
"indent",
")",
";",
"if",
"(",
"$",
"indInt",
">",
"0",
")",
"{",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"$",
"i",
"<",
"$",
"indInt",
")",
"{",
"$",
"indentStr",
".=",
"\"\\t\"",
";",
"$",
"i",
"+=",
"1",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"indent",
")",
")",
"{",
"$",
"indentStr",
"=",
"$",
"indent",
";",
"}",
"return",
"$",
"indentStr",
";",
"}"
] | Get indent string
@param string|int $indent
@return string | [
"Get",
"indent",
"string"
] | 5672575aca6d63f2340c912f9b9754bbb896d97b | https://github.com/mvccore/ext-view-helper-assets/blob/5672575aca6d63f2340c912f9b9754bbb896d97b/src/MvcCore/Ext/Views/Helpers/Assets.php#L384-L399 | train |
mvccore/ext-view-helper-assets | src/MvcCore/Ext/Views/Helpers/Assets.php | Assets.getTmpDir | protected function getTmpDir() {
if (!self::$tmpDir) {
$tmpDir = $this->getAppRoot() . self::$globalOptions['tmpDir'];
if (!\MvcCore\Application::GetInstance()->GetCompiled()) {
if (!is_dir($tmpDir)) mkdir($tmpDir, 0777, TRUE);
if (!is_writable($tmpDir)) {
try {
@chmod($tmpDir, 0777);
} catch (\Exception $e) {
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
throw new \Exception('['.$selfClass.'] ' . $e->getMessage());
}
}
}
self::$tmpDir = $tmpDir;
}
return self::$tmpDir;
} | php | protected function getTmpDir() {
if (!self::$tmpDir) {
$tmpDir = $this->getAppRoot() . self::$globalOptions['tmpDir'];
if (!\MvcCore\Application::GetInstance()->GetCompiled()) {
if (!is_dir($tmpDir)) mkdir($tmpDir, 0777, TRUE);
if (!is_writable($tmpDir)) {
try {
@chmod($tmpDir, 0777);
} catch (\Exception $e) {
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
throw new \Exception('['.$selfClass.'] ' . $e->getMessage());
}
}
}
self::$tmpDir = $tmpDir;
}
return self::$tmpDir;
} | [
"protected",
"function",
"getTmpDir",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"tmpDir",
")",
"{",
"$",
"tmpDir",
"=",
"$",
"this",
"->",
"getAppRoot",
"(",
")",
".",
"self",
"::",
"$",
"globalOptions",
"[",
"'tmpDir'",
"]",
";",
"if",
"(",
"!",
"\\",
"MvcCore",
"\\",
"Application",
"::",
"GetInstance",
"(",
")",
"->",
"GetCompiled",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"tmpDir",
")",
")",
"mkdir",
"(",
"$",
"tmpDir",
",",
"0777",
",",
"TRUE",
")",
";",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"tmpDir",
")",
")",
"{",
"try",
"{",
"@",
"chmod",
"(",
"$",
"tmpDir",
",",
"0777",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"selfClass",
"=",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.5'",
",",
"'>'",
")",
"?",
"self",
"::",
"class",
":",
"__CLASS__",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"'['",
".",
"$",
"selfClass",
".",
"'] '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}",
"self",
"::",
"$",
"tmpDir",
"=",
"$",
"tmpDir",
";",
"}",
"return",
"self",
"::",
"$",
"tmpDir",
";",
"}"
] | Return and store application document root from controller view request object
@throws \Exception
@return string | [
"Return",
"and",
"store",
"application",
"document",
"root",
"from",
"controller",
"view",
"request",
"object"
] | 5672575aca6d63f2340c912f9b9754bbb896d97b | https://github.com/mvccore/ext-view-helper-assets/blob/5672575aca6d63f2340c912f9b9754bbb896d97b/src/MvcCore/Ext/Views/Helpers/Assets.php#L414-L431 | train |
mvccore/ext-view-helper-assets | src/MvcCore/Ext/Views/Helpers/Assets.php | Assets.saveFileContent | protected function saveFileContent ($fullPath = '', & $fileContent = '') {
$toolClass = \MvcCore\Application::GetInstance()->GetToolClass();
$toolClass::SingleProcessWrite($fullPath, $fileContent);
@chmod($fullPath, 0766);
} | php | protected function saveFileContent ($fullPath = '', & $fileContent = '') {
$toolClass = \MvcCore\Application::GetInstance()->GetToolClass();
$toolClass::SingleProcessWrite($fullPath, $fileContent);
@chmod($fullPath, 0766);
} | [
"protected",
"function",
"saveFileContent",
"(",
"$",
"fullPath",
"=",
"''",
",",
"&",
"$",
"fileContent",
"=",
"''",
")",
"{",
"$",
"toolClass",
"=",
"\\",
"MvcCore",
"\\",
"Application",
"::",
"GetInstance",
"(",
")",
"->",
"GetToolClass",
"(",
")",
";",
"$",
"toolClass",
"::",
"SingleProcessWrite",
"(",
"$",
"fullPath",
",",
"$",
"fileContent",
")",
";",
"@",
"chmod",
"(",
"$",
"fullPath",
",",
"0766",
")",
";",
"}"
] | Save atomically file content in full path by 1 MB to not overflow any memory limits
@param string $fullPath
@param string $fileContent
@return void | [
"Save",
"atomically",
"file",
"content",
"in",
"full",
"path",
"by",
"1",
"MB",
"to",
"not",
"overflow",
"any",
"memory",
"limits"
] | 5672575aca6d63f2340c912f9b9754bbb896d97b | https://github.com/mvccore/ext-view-helper-assets/blob/5672575aca6d63f2340c912f9b9754bbb896d97b/src/MvcCore/Ext/Views/Helpers/Assets.php#L439-L443 | train |
mvccore/ext-view-helper-assets | src/MvcCore/Ext/Views/Helpers/Assets.php | Assets.log | protected function log ($msg = '', $logType = 'debug') {
if (self::$loggingAndExceptions) {
\MvcCore\Debug::Log($msg, $logType);
}
} | php | protected function log ($msg = '', $logType = 'debug') {
if (self::$loggingAndExceptions) {
\MvcCore\Debug::Log($msg, $logType);
}
} | [
"protected",
"function",
"log",
"(",
"$",
"msg",
"=",
"''",
",",
"$",
"logType",
"=",
"'debug'",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"loggingAndExceptions",
")",
"{",
"\\",
"MvcCore",
"\\",
"Debug",
"::",
"Log",
"(",
"$",
"msg",
",",
"$",
"logType",
")",
";",
"}",
"}"
] | Log any render messages with optional log file name
@param string $msg
@param string $logType
@return void | [
"Log",
"any",
"render",
"messages",
"with",
"optional",
"log",
"file",
"name"
] | 5672575aca6d63f2340c912f9b9754bbb896d97b | https://github.com/mvccore/ext-view-helper-assets/blob/5672575aca6d63f2340c912f9b9754bbb896d97b/src/MvcCore/Ext/Views/Helpers/Assets.php#L451-L455 | train |
mvccore/ext-view-helper-assets | src/MvcCore/Ext/Views/Helpers/Assets.php | Assets.warning | protected function warning ($msg) {
if (self::$loggingAndExceptions) {
\MvcCore\Debug::BarDump('[' . get_class($this) . '] ' . $msg, \MvcCore\IDebug::DEBUG);
}
} | php | protected function warning ($msg) {
if (self::$loggingAndExceptions) {
\MvcCore\Debug::BarDump('[' . get_class($this) . '] ' . $msg, \MvcCore\IDebug::DEBUG);
}
} | [
"protected",
"function",
"warning",
"(",
"$",
"msg",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"loggingAndExceptions",
")",
"{",
"\\",
"MvcCore",
"\\",
"Debug",
"::",
"BarDump",
"(",
"'['",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"'] '",
".",
"$",
"msg",
",",
"\\",
"MvcCore",
"\\",
"IDebug",
"::",
"DEBUG",
")",
";",
"}",
"}"
] | Throw exception with given message with actual helper class name before
@param string $msg
@return void | [
"Throw",
"exception",
"with",
"given",
"message",
"with",
"actual",
"helper",
"class",
"name",
"before"
] | 5672575aca6d63f2340c912f9b9754bbb896d97b | https://github.com/mvccore/ext-view-helper-assets/blob/5672575aca6d63f2340c912f9b9754bbb896d97b/src/MvcCore/Ext/Views/Helpers/Assets.php#L474-L478 | train |
mvccore/ext-view-helper-assets | src/MvcCore/Ext/Views/Helpers/Assets.php | Assets.getTmpFileFullPathByPartFilesInfo | protected function getTmpFileFullPathByPartFilesInfo ($filesGroupInfo = [], $minify = FALSE, $extension = '') {
return implode('', [
$this->getTmpDir(),
'/' . ($minify ? 'minified' : 'rendered') . '_' . $extension . '_',
md5(implode(',', $filesGroupInfo) . '_' . $minify),
'.' . $extension
]);
} | php | protected function getTmpFileFullPathByPartFilesInfo ($filesGroupInfo = [], $minify = FALSE, $extension = '') {
return implode('', [
$this->getTmpDir(),
'/' . ($minify ? 'minified' : 'rendered') . '_' . $extension . '_',
md5(implode(',', $filesGroupInfo) . '_' . $minify),
'.' . $extension
]);
} | [
"protected",
"function",
"getTmpFileFullPathByPartFilesInfo",
"(",
"$",
"filesGroupInfo",
"=",
"[",
"]",
",",
"$",
"minify",
"=",
"FALSE",
",",
"$",
"extension",
"=",
"''",
")",
"{",
"return",
"implode",
"(",
"''",
",",
"[",
"$",
"this",
"->",
"getTmpDir",
"(",
")",
",",
"'/'",
".",
"(",
"$",
"minify",
"?",
"'minified'",
":",
"'rendered'",
")",
".",
"'_'",
".",
"$",
"extension",
".",
"'_'",
",",
"md5",
"(",
"implode",
"(",
"','",
",",
"$",
"filesGroupInfo",
")",
".",
"'_'",
".",
"$",
"minify",
")",
",",
"'.'",
".",
"$",
"extension",
"]",
")",
";",
"}"
] | Complete items group tmp directory file name by group source files info
@param array $filesGroupInfo
@param boolean $minify
@return string | [
"Complete",
"items",
"group",
"tmp",
"directory",
"file",
"name",
"by",
"group",
"source",
"files",
"info"
] | 5672575aca6d63f2340c912f9b9754bbb896d97b | https://github.com/mvccore/ext-view-helper-assets/blob/5672575aca6d63f2340c912f9b9754bbb896d97b/src/MvcCore/Ext/Views/Helpers/Assets.php#L497-L504 | train |
schpill/thin | src/Multithread.php | Multithread.run | public function run($jobs)
{
$lenTab = count($jobs);
for ($i = 0 ; $i < $lenTab ; $i++) {
$jobID = rand(0, 100);
while (count($this->currentJobs) >= $this->maxProcesses) {
sleep($this->sleepTime);
}
$launched = $this->launchJobProcess($jobID, "Jobs", $jobs[$i]);
}
while (count($this->currentJobs)) {
sleep($this->sleepTime);
}
} | php | public function run($jobs)
{
$lenTab = count($jobs);
for ($i = 0 ; $i < $lenTab ; $i++) {
$jobID = rand(0, 100);
while (count($this->currentJobs) >= $this->maxProcesses) {
sleep($this->sleepTime);
}
$launched = $this->launchJobProcess($jobID, "Jobs", $jobs[$i]);
}
while (count($this->currentJobs)) {
sleep($this->sleepTime);
}
} | [
"public",
"function",
"run",
"(",
"$",
"jobs",
")",
"{",
"$",
"lenTab",
"=",
"count",
"(",
"$",
"jobs",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"lenTab",
";",
"$",
"i",
"++",
")",
"{",
"$",
"jobID",
"=",
"rand",
"(",
"0",
",",
"100",
")",
";",
"while",
"(",
"count",
"(",
"$",
"this",
"->",
"currentJobs",
")",
">=",
"$",
"this",
"->",
"maxProcesses",
")",
"{",
"sleep",
"(",
"$",
"this",
"->",
"sleepTime",
")",
";",
"}",
"$",
"launched",
"=",
"$",
"this",
"->",
"launchJobProcess",
"(",
"$",
"jobID",
",",
"\"Jobs\"",
",",
"$",
"jobs",
"[",
"$",
"i",
"]",
")",
";",
"}",
"while",
"(",
"count",
"(",
"$",
"this",
"->",
"currentJobs",
")",
")",
"{",
"sleep",
"(",
"$",
"this",
"->",
"sleepTime",
")",
";",
"}",
"}"
] | Run the Daemon | [
"Run",
"the",
"Daemon"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Multithread.php#L24-L39 | train |
schpill/thin | src/Multithread.php | Multithread.launchJob | protected function launchJob($jobID)
{
$pid = pcntl_fork();
if ($pid == -1) {
error_log('Could not launch new job, exiting');
echo 'Could not launch new job, exiting';
return false;
} else if ($pid) {
$this->currentJobs[$pid] = $jobID;
if (isset($this->signalQueue[$pid])) {
$this->childSignalHandler(SIGCHLD, $pid, $this->signalQueue[$pid]);
unset($this->signalQueue[$pid]);
}
} else {
$exitStatus = 0; //Error code if you need to or whatever
exit($exitStatus);
}
return true;
} | php | protected function launchJob($jobID)
{
$pid = pcntl_fork();
if ($pid == -1) {
error_log('Could not launch new job, exiting');
echo 'Could not launch new job, exiting';
return false;
} else if ($pid) {
$this->currentJobs[$pid] = $jobID;
if (isset($this->signalQueue[$pid])) {
$this->childSignalHandler(SIGCHLD, $pid, $this->signalQueue[$pid]);
unset($this->signalQueue[$pid]);
}
} else {
$exitStatus = 0; //Error code if you need to or whatever
exit($exitStatus);
}
return true;
} | [
"protected",
"function",
"launchJob",
"(",
"$",
"jobID",
")",
"{",
"$",
"pid",
"=",
"pcntl_fork",
"(",
")",
";",
"if",
"(",
"$",
"pid",
"==",
"-",
"1",
")",
"{",
"error_log",
"(",
"'Could not launch new job, exiting'",
")",
";",
"echo",
"'Could not launch new job, exiting'",
";",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"$",
"pid",
")",
"{",
"$",
"this",
"->",
"currentJobs",
"[",
"$",
"pid",
"]",
"=",
"$",
"jobID",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"signalQueue",
"[",
"$",
"pid",
"]",
")",
")",
"{",
"$",
"this",
"->",
"childSignalHandler",
"(",
"SIGCHLD",
",",
"$",
"pid",
",",
"$",
"this",
"->",
"signalQueue",
"[",
"$",
"pid",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"signalQueue",
"[",
"$",
"pid",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"exitStatus",
"=",
"0",
";",
"//Error code if you need to or whatever",
"exit",
"(",
"$",
"exitStatus",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Launch a job from the job queue | [
"Launch",
"a",
"job",
"from",
"the",
"job",
"queue"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Multithread.php#L83-L101 | train |
rzajac/php-test-helper | src/Database/Driver/MySQL.php | MySQL.getTableNames | protected function getTableNames(): array
{
$dbName = $this->config[DbItf::DB_CFG_DATABASE];
$resp = $this->dbRunQuery(sprintf('SHOW FULL TABLES FROM `%s`', $dbName));
$tableAndViewNames = [];
while ($row = $resp->fetch_assoc()) {
$tableAndViewNames[] = array_change_key_case($row);
}
return $tableAndViewNames;
} | php | protected function getTableNames(): array
{
$dbName = $this->config[DbItf::DB_CFG_DATABASE];
$resp = $this->dbRunQuery(sprintf('SHOW FULL TABLES FROM `%s`', $dbName));
$tableAndViewNames = [];
while ($row = $resp->fetch_assoc()) {
$tableAndViewNames[] = array_change_key_case($row);
}
return $tableAndViewNames;
} | [
"protected",
"function",
"getTableNames",
"(",
")",
":",
"array",
"{",
"$",
"dbName",
"=",
"$",
"this",
"->",
"config",
"[",
"DbItf",
"::",
"DB_CFG_DATABASE",
"]",
";",
"$",
"resp",
"=",
"$",
"this",
"->",
"dbRunQuery",
"(",
"sprintf",
"(",
"'SHOW FULL TABLES FROM `%s`'",
",",
"$",
"dbName",
")",
")",
";",
"$",
"tableAndViewNames",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"resp",
"->",
"fetch_assoc",
"(",
")",
")",
"{",
"$",
"tableAndViewNames",
"[",
"]",
"=",
"array_change_key_case",
"(",
"$",
"row",
")",
";",
"}",
"return",
"$",
"tableAndViewNames",
";",
"}"
] | Return table and view names form the database.
@throws DatabaseEx
@return array | [
"Return",
"table",
"and",
"view",
"names",
"form",
"the",
"database",
"."
] | 37280e9ff639b25cf9413909cc080c5d8deb311c | https://github.com/rzajac/php-test-helper/blob/37280e9ff639b25cf9413909cc080c5d8deb311c/src/Database/Driver/MySQL.php#L164-L175 | train |
wdbo/webdocbook | src/WebDocBook/Filesystem/Helper.php | Helper.slashDirname | public static function slashDirname($dirname = null)
{
if (is_null($dirname) || empty($dirname)) {
return '';
}
return rtrim($dirname, '/ '.DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
} | php | public static function slashDirname($dirname = null)
{
if (is_null($dirname) || empty($dirname)) {
return '';
}
return rtrim($dirname, '/ '.DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
} | [
"public",
"static",
"function",
"slashDirname",
"(",
"$",
"dirname",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"dirname",
")",
"||",
"empty",
"(",
"$",
"dirname",
")",
")",
"{",
"return",
"''",
";",
"}",
"return",
"rtrim",
"(",
"$",
"dirname",
",",
"'/ '",
".",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"}"
] | Get a dirname with one and only trailing slash
@param string $dirname
@return string | [
"Get",
"a",
"dirname",
"with",
"one",
"and",
"only",
"trailing",
"slash"
] | 7d4e806f674b6222c9a3e85bfed34e72bc9d584e | https://github.com/wdbo/webdocbook/blob/7d4e806f674b6222c9a3e85bfed34e72bc9d584e/src/WebDocBook/Filesystem/Helper.php#L43-L49 | train |
wdbo/webdocbook | src/WebDocBook/Filesystem/Helper.php | Helper.isGitClone | public static function isGitClone($path = null)
{
if (is_null($path) || empty($path)) {
return false;
}
$dir_path = self::slashDirname($path).'.git';
return (bool) (file_exists($dir_path) && is_dir($dir_path));
} | php | public static function isGitClone($path = null)
{
if (is_null($path) || empty($path)) {
return false;
}
$dir_path = self::slashDirname($path).'.git';
return (bool) (file_exists($dir_path) && is_dir($dir_path));
} | [
"public",
"static",
"function",
"isGitClone",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"path",
")",
"||",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"dir_path",
"=",
"self",
"::",
"slashDirname",
"(",
"$",
"path",
")",
".",
"'.git'",
";",
"return",
"(",
"bool",
")",
"(",
"file_exists",
"(",
"$",
"dir_path",
")",
"&&",
"is_dir",
"(",
"$",
"dir_path",
")",
")",
";",
"}"
] | Test if a path seems to be a git clone
@param string $path
@return bool | [
"Test",
"if",
"a",
"path",
"seems",
"to",
"be",
"a",
"git",
"clone"
] | 7d4e806f674b6222c9a3e85bfed34e72bc9d584e | https://github.com/wdbo/webdocbook/blob/7d4e806f674b6222c9a3e85bfed34e72bc9d584e/src/WebDocBook/Filesystem/Helper.php#L57-L64 | train |
wdbo/webdocbook | src/WebDocBook/Filesystem/Helper.php | Helper.isDotPath | public static function isDotPath($path = null)
{
if (is_null($path) || empty($path)) {
return false;
}
return (bool) ('.'===substr(basename($path), 0, 1));
} | php | public static function isDotPath($path = null)
{
if (is_null($path) || empty($path)) {
return false;
}
return (bool) ('.'===substr(basename($path), 0, 1));
} | [
"public",
"static",
"function",
"isDotPath",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"path",
")",
"||",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"bool",
")",
"(",
"'.'",
"===",
"substr",
"(",
"basename",
"(",
"$",
"path",
")",
",",
"0",
",",
"1",
")",
")",
";",
"}"
] | Test if a filename seems to have a dot as first character
@param string $path
@return bool | [
"Test",
"if",
"a",
"filename",
"seems",
"to",
"have",
"a",
"dot",
"as",
"first",
"character"
] | 7d4e806f674b6222c9a3e85bfed34e72bc9d584e | https://github.com/wdbo/webdocbook/blob/7d4e806f674b6222c9a3e85bfed34e72bc9d584e/src/WebDocBook/Filesystem/Helper.php#L72-L78 | train |
wdbo/webdocbook | src/WebDocBook/Filesystem/Helper.php | Helper.remove | public static function remove($path, $parent = true)
{
$ok = true;
if (true===self::ensureExists($path)) {
if (false===@is_dir($path) || true===is_link($path)) {
return @unlink($path);
}
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path),
\RecursiveIteratorIterator::SELF_FIRST | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS
);
foreach($iterator as $item) {
if (in_array($item->getFilename(), array('.', '..'))) {
continue;
}
if ($item->isDir()) {
$ok = self::remove($item);
} else {
$ok = @unlink($item);
}
}
if ($ok && $parent) {
@rmdir($path);
}
@clearstatcache();
}
return $ok;
} | php | public static function remove($path, $parent = true)
{
$ok = true;
if (true===self::ensureExists($path)) {
if (false===@is_dir($path) || true===is_link($path)) {
return @unlink($path);
}
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path),
\RecursiveIteratorIterator::SELF_FIRST | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS
);
foreach($iterator as $item) {
if (in_array($item->getFilename(), array('.', '..'))) {
continue;
}
if ($item->isDir()) {
$ok = self::remove($item);
} else {
$ok = @unlink($item);
}
}
if ($ok && $parent) {
@rmdir($path);
}
@clearstatcache();
}
return $ok;
} | [
"public",
"static",
"function",
"remove",
"(",
"$",
"path",
",",
"$",
"parent",
"=",
"true",
")",
"{",
"$",
"ok",
"=",
"true",
";",
"if",
"(",
"true",
"===",
"self",
"::",
"ensureExists",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"false",
"===",
"@",
"is_dir",
"(",
"$",
"path",
")",
"||",
"true",
"===",
"is_link",
"(",
"$",
"path",
")",
")",
"{",
"return",
"@",
"unlink",
"(",
"$",
"path",
")",
";",
"}",
"$",
"iterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"path",
")",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"SELF_FIRST",
"|",
"\\",
"FilesystemIterator",
"::",
"CURRENT_AS_FILEINFO",
"|",
"\\",
"FilesystemIterator",
"::",
"SKIP_DOTS",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"item",
"->",
"getFilename",
"(",
")",
",",
"array",
"(",
"'.'",
",",
"'..'",
")",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"item",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"ok",
"=",
"self",
"::",
"remove",
"(",
"$",
"item",
")",
";",
"}",
"else",
"{",
"$",
"ok",
"=",
"@",
"unlink",
"(",
"$",
"item",
")",
";",
"}",
"}",
"if",
"(",
"$",
"ok",
"&&",
"$",
"parent",
")",
"{",
"@",
"rmdir",
"(",
"$",
"path",
")",
";",
"}",
"@",
"clearstatcache",
"(",
")",
";",
"}",
"return",
"$",
"ok",
";",
"}"
] | Try to remove a path
@param string $path
@param bool $parent
@return bool | [
"Try",
"to",
"remove",
"a",
"path"
] | 7d4e806f674b6222c9a3e85bfed34e72bc9d584e | https://github.com/wdbo/webdocbook/blob/7d4e806f674b6222c9a3e85bfed34e72bc9d584e/src/WebDocBook/Filesystem/Helper.php#L117-L144 | train |
wdbo/webdocbook | src/WebDocBook/Filesystem/Helper.php | Helper.parseIni | public static function parseIni($path)
{
if (true===@file_exists($path)) {
$data = parse_ini_file($path, true);
if ($data && !empty($data)) {
return $data;
}
}
return false;
} | php | public static function parseIni($path)
{
if (true===@file_exists($path)) {
$data = parse_ini_file($path, true);
if ($data && !empty($data)) {
return $data;
}
}
return false;
} | [
"public",
"static",
"function",
"parseIni",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"true",
"===",
"@",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"data",
"=",
"parse_ini_file",
"(",
"$",
"path",
",",
"true",
")",
";",
"if",
"(",
"$",
"data",
"&&",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Read and parse a INI content file
@param $path
@return array|bool | [
"Read",
"and",
"parse",
"a",
"INI",
"content",
"file"
] | 7d4e806f674b6222c9a3e85bfed34e72bc9d584e | https://github.com/wdbo/webdocbook/blob/7d4e806f674b6222c9a3e85bfed34e72bc9d584e/src/WebDocBook/Filesystem/Helper.php#L152-L161 | train |
wdbo/webdocbook | src/WebDocBook/Filesystem/Helper.php | Helper.parseJson | public static function parseJson($path)
{
if (true===@file_exists($path)) {
$ctt = file_get_contents($path);
if ($ctt!==false) {
$data = json_decode($ctt, true);
if ($data && !empty($data)) {
return $data;
}
}
}
return false;
} | php | public static function parseJson($path)
{
if (true===@file_exists($path)) {
$ctt = file_get_contents($path);
if ($ctt!==false) {
$data = json_decode($ctt, true);
if ($data && !empty($data)) {
return $data;
}
}
}
return false;
} | [
"public",
"static",
"function",
"parseJson",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"true",
"===",
"@",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"ctt",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"ctt",
"!==",
"false",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"ctt",
",",
"true",
")",
";",
"if",
"(",
"$",
"data",
"&&",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Read and parse a JSON content file
@param $path
@return bool|mixed | [
"Read",
"and",
"parse",
"a",
"JSON",
"content",
"file"
] | 7d4e806f674b6222c9a3e85bfed34e72bc9d584e | https://github.com/wdbo/webdocbook/blob/7d4e806f674b6222c9a3e85bfed34e72bc9d584e/src/WebDocBook/Filesystem/Helper.php#L169-L181 | train |
PhoxPHP/Glider | src/Console/Command/Migration.php | Migration.create | protected function create(Array $arguments=[])
{
$migrationsDirectory = $this->cmd->getConfigOpt('migrations_storage');
$templateTags = [];
$migrationName = $this->cmd->question('Migration filename?');
$filename = trim($migrationName);
$path = $migrationsDirectory . '/' . $filename . '.php';
if (file_exists($path)) {
throw new MigrationFileInvalidException(
sprintf(
'Migration file [%s] exists.',
$filename
)
);
}
$templateTags['phx:class'] = Helper::getQualifiedClassName($filename);
$builder = new TemplateBuilder($this->cmd, $this->env);
$builder->createClassTemplate('migration', $filename, $migrationsDirectory, $templateTags);
// After migration class has been created, the record needs to go to the database and be set to pending.
$model = new Model();
$model->class_name = $templateTags['phx:class'];
$model->status = Attribute::STATUS_PENDING;
$model->path = $path;
$model->save();
$this->env->sendOutput('Created migration is now pending', 'green');
} | php | protected function create(Array $arguments=[])
{
$migrationsDirectory = $this->cmd->getConfigOpt('migrations_storage');
$templateTags = [];
$migrationName = $this->cmd->question('Migration filename?');
$filename = trim($migrationName);
$path = $migrationsDirectory . '/' . $filename . '.php';
if (file_exists($path)) {
throw new MigrationFileInvalidException(
sprintf(
'Migration file [%s] exists.',
$filename
)
);
}
$templateTags['phx:class'] = Helper::getQualifiedClassName($filename);
$builder = new TemplateBuilder($this->cmd, $this->env);
$builder->createClassTemplate('migration', $filename, $migrationsDirectory, $templateTags);
// After migration class has been created, the record needs to go to the database and be set to pending.
$model = new Model();
$model->class_name = $templateTags['phx:class'];
$model->status = Attribute::STATUS_PENDING;
$model->path = $path;
$model->save();
$this->env->sendOutput('Created migration is now pending', 'green');
} | [
"protected",
"function",
"create",
"(",
"Array",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"$",
"migrationsDirectory",
"=",
"$",
"this",
"->",
"cmd",
"->",
"getConfigOpt",
"(",
"'migrations_storage'",
")",
";",
"$",
"templateTags",
"=",
"[",
"]",
";",
"$",
"migrationName",
"=",
"$",
"this",
"->",
"cmd",
"->",
"question",
"(",
"'Migration filename?'",
")",
";",
"$",
"filename",
"=",
"trim",
"(",
"$",
"migrationName",
")",
";",
"$",
"path",
"=",
"$",
"migrationsDirectory",
".",
"'/'",
".",
"$",
"filename",
".",
"'.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"MigrationFileInvalidException",
"(",
"sprintf",
"(",
"'Migration file [%s] exists.'",
",",
"$",
"filename",
")",
")",
";",
"}",
"$",
"templateTags",
"[",
"'phx:class'",
"]",
"=",
"Helper",
"::",
"getQualifiedClassName",
"(",
"$",
"filename",
")",
";",
"$",
"builder",
"=",
"new",
"TemplateBuilder",
"(",
"$",
"this",
"->",
"cmd",
",",
"$",
"this",
"->",
"env",
")",
";",
"$",
"builder",
"->",
"createClassTemplate",
"(",
"'migration'",
",",
"$",
"filename",
",",
"$",
"migrationsDirectory",
",",
"$",
"templateTags",
")",
";",
"// After migration class has been created, the record needs to go to the database and be set to pending.\r",
"$",
"model",
"=",
"new",
"Model",
"(",
")",
";",
"$",
"model",
"->",
"class_name",
"=",
"$",
"templateTags",
"[",
"'phx:class'",
"]",
";",
"$",
"model",
"->",
"status",
"=",
"Attribute",
"::",
"STATUS_PENDING",
";",
"$",
"model",
"->",
"path",
"=",
"$",
"path",
";",
"$",
"model",
"->",
"save",
"(",
")",
";",
"$",
"this",
"->",
"env",
"->",
"sendOutput",
"(",
"'Created migration is now pending'",
",",
"'green'",
")",
";",
"}"
] | Creates a migration.
@param $arguments <Array>
@access protected
@return <void> | [
"Creates",
"a",
"migration",
"."
] | 17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042 | https://github.com/PhoxPHP/Glider/blob/17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042/src/Console/Command/Migration.php#L145-L177 | train |
PhoxPHP/Glider | src/Console/Command/Migration.php | Migration.processMigration | protected function processMigration(Array $arguments)
{
$migrationClass = $arguments[0];
$migration = Model::findByclass_name($migrationClass);
if (!$migration) {
throw new MigrationClassNotFoundException(
sprintf(
'Migration class [%s] does not exist',
$migrationClass
)
);
}
if (isset($arguments[1]) && $arguments[1] == '--down') {
self::$migrationType = Attribute::DOWNGRADE;
}
$this->migrator->runSingleMigration($migration);
} | php | protected function processMigration(Array $arguments)
{
$migrationClass = $arguments[0];
$migration = Model::findByclass_name($migrationClass);
if (!$migration) {
throw new MigrationClassNotFoundException(
sprintf(
'Migration class [%s] does not exist',
$migrationClass
)
);
}
if (isset($arguments[1]) && $arguments[1] == '--down') {
self::$migrationType = Attribute::DOWNGRADE;
}
$this->migrator->runSingleMigration($migration);
} | [
"protected",
"function",
"processMigration",
"(",
"Array",
"$",
"arguments",
")",
"{",
"$",
"migrationClass",
"=",
"$",
"arguments",
"[",
"0",
"]",
";",
"$",
"migration",
"=",
"Model",
"::",
"findByclass_name",
"(",
"$",
"migrationClass",
")",
";",
"if",
"(",
"!",
"$",
"migration",
")",
"{",
"throw",
"new",
"MigrationClassNotFoundException",
"(",
"sprintf",
"(",
"'Migration class [%s] does not exist'",
",",
"$",
"migrationClass",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"arguments",
"[",
"1",
"]",
")",
"&&",
"$",
"arguments",
"[",
"1",
"]",
"==",
"'--down'",
")",
"{",
"self",
"::",
"$",
"migrationType",
"=",
"Attribute",
"::",
"DOWNGRADE",
";",
"}",
"$",
"this",
"->",
"migrator",
"->",
"runSingleMigration",
"(",
"$",
"migration",
")",
";",
"}"
] | Processes a specific migration.
@param $arguments <Array>
@access protected
@return <void> | [
"Processes",
"a",
"specific",
"migration",
"."
] | 17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042 | https://github.com/PhoxPHP/Glider/blob/17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042/src/Console/Command/Migration.php#L199-L218 | train |
iwyg/xmlconf | src/Thapp/XmlConf/Cache/Cache.php | Cache.getCacheModificationDate | protected function getCacheModificationDate($file)
{
$storageKey = $this->getStorageKey() . '.lasmodified';
$filemtime = filemtime($file);
$lastmodified = $this->storage->has($storageKey) ? $this->storage->get($storageKey) : $filemtime - 1;
return array($filemtime, $lastmodified);
} | php | protected function getCacheModificationDate($file)
{
$storageKey = $this->getStorageKey() . '.lasmodified';
$filemtime = filemtime($file);
$lastmodified = $this->storage->has($storageKey) ? $this->storage->get($storageKey) : $filemtime - 1;
return array($filemtime, $lastmodified);
} | [
"protected",
"function",
"getCacheModificationDate",
"(",
"$",
"file",
")",
"{",
"$",
"storageKey",
"=",
"$",
"this",
"->",
"getStorageKey",
"(",
")",
".",
"'.lasmodified'",
";",
"$",
"filemtime",
"=",
"filemtime",
"(",
"$",
"file",
")",
";",
"$",
"lastmodified",
"=",
"$",
"this",
"->",
"storage",
"->",
"has",
"(",
"$",
"storageKey",
")",
"?",
"$",
"this",
"->",
"storage",
"->",
"get",
"(",
"$",
"storageKey",
")",
":",
"$",
"filemtime",
"-",
"1",
";",
"return",
"array",
"(",
"$",
"filemtime",
",",
"$",
"lastmodified",
")",
";",
"}"
] | Returns the modification date of a given file and the the
date of the last cache write.
@access protected
@return array | [
"Returns",
"the",
"modification",
"date",
"of",
"a",
"given",
"file",
"and",
"the",
"the",
"date",
"of",
"the",
"last",
"cache",
"write",
"."
] | 1d8a657073f3fd46dacfb6bf5d173f9d5283661b | https://github.com/iwyg/xmlconf/blob/1d8a657073f3fd46dacfb6bf5d173f9d5283661b/src/Thapp/XmlConf/Cache/Cache.php#L97-L104 | train |
crodas/ConcurrentFileWriter | src/ConcurrentFileWriter/ConcurrentFileWriter.php | ConcurrentFileWriter.create | public function create(array $metadata = array())
{
if (is_file($this->file)) {
return false;
}
$this->createTemporaryFolder();
file_put_contents($this->file, $this->placeholderContent($metadata), LOCK_EX);
return true;
} | php | public function create(array $metadata = array())
{
if (is_file($this->file)) {
return false;
}
$this->createTemporaryFolder();
file_put_contents($this->file, $this->placeholderContent($metadata), LOCK_EX);
return true;
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"metadata",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"this",
"->",
"file",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"createTemporaryFolder",
"(",
")",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"file",
",",
"$",
"this",
"->",
"placeholderContent",
"(",
"$",
"metadata",
")",
",",
"LOCK_EX",
")",
";",
"return",
"true",
";",
"}"
] | Creates the file. It creates a placeholder file with some metadata on it and will
create all the temporary files and folders.
Writing without creating first will throw an exception. Creating twice will not throw an
exception but will return false. That means it is OK to call `create()` before calling
`write()`. Ideally it should be called once when the writing of the file is initialized.
@param array $metadata
@return bool | [
"Creates",
"the",
"file",
".",
"It",
"creates",
"a",
"placeholder",
"file",
"with",
"some",
"metadata",
"on",
"it",
"and",
"will",
"create",
"all",
"the",
"temporary",
"files",
"and",
"folders",
"."
] | 13f88d8c2daf5fe9c70f8be6aeb3d862cd2a5e5a | https://github.com/crodas/ConcurrentFileWriter/blob/13f88d8c2daf5fe9c70f8be6aeb3d862cd2a5e5a/src/ConcurrentFileWriter/ConcurrentFileWriter.php#L72-L82 | train |
crodas/ConcurrentFileWriter | src/ConcurrentFileWriter/ConcurrentFileWriter.php | ConcurrentFileWriter.createTemporaryFolder | protected function createTemporaryFolder()
{
Util::mkdir($this->blocks);
Util::mkdir(dirname($this->file));
file_put_contents($this->tmp . '.lock', '', LOCK_EX);
} | php | protected function createTemporaryFolder()
{
Util::mkdir($this->blocks);
Util::mkdir(dirname($this->file));
file_put_contents($this->tmp . '.lock', '', LOCK_EX);
} | [
"protected",
"function",
"createTemporaryFolder",
"(",
")",
"{",
"Util",
"::",
"mkdir",
"(",
"$",
"this",
"->",
"blocks",
")",
";",
"Util",
"::",
"mkdir",
"(",
"dirname",
"(",
"$",
"this",
"->",
"file",
")",
")",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"tmp",
".",
"'.lock'",
",",
"''",
",",
"LOCK_EX",
")",
";",
"}"
] | Creates the needed temporary files and folders in prepartion for
the file writer. | [
"Creates",
"the",
"needed",
"temporary",
"files",
"and",
"folders",
"in",
"prepartion",
"for",
"the",
"file",
"writer",
"."
] | 13f88d8c2daf5fe9c70f8be6aeb3d862cd2a5e5a | https://github.com/crodas/ConcurrentFileWriter/blob/13f88d8c2daf5fe9c70f8be6aeb3d862cd2a5e5a/src/ConcurrentFileWriter/ConcurrentFileWriter.php#L88-L93 | train |
crodas/ConcurrentFileWriter | src/ConcurrentFileWriter/ConcurrentFileWriter.php | ConcurrentFileWriter.getWroteBlocks | public function getWroteBlocks()
{
if (!is_dir($this->blocks)) {
throw new RuntimeException("cannot obtain the blocks ({$this->blocks})");
}
$files = array_filter(array_map(function($file) {
$basename = basename($file);
if (!is_numeric($basename)) {
return false;
}
return [
'offset' => (int)$basename,
'file' => $file,
'size' => filesize($file)
];
}, glob($this->blocks . "*")));
uasort($files, function($a, $b) {
return $a['offset'] - $b['offset'];
});
return $files;
} | php | public function getWroteBlocks()
{
if (!is_dir($this->blocks)) {
throw new RuntimeException("cannot obtain the blocks ({$this->blocks})");
}
$files = array_filter(array_map(function($file) {
$basename = basename($file);
if (!is_numeric($basename)) {
return false;
}
return [
'offset' => (int)$basename,
'file' => $file,
'size' => filesize($file)
];
}, glob($this->blocks . "*")));
uasort($files, function($a, $b) {
return $a['offset'] - $b['offset'];
});
return $files;
} | [
"public",
"function",
"getWroteBlocks",
"(",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"blocks",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"cannot obtain the blocks ({$this->blocks})\"",
")",
";",
"}",
"$",
"files",
"=",
"array_filter",
"(",
"array_map",
"(",
"function",
"(",
"$",
"file",
")",
"{",
"$",
"basename",
"=",
"basename",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"basename",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"[",
"'offset'",
"=>",
"(",
"int",
")",
"$",
"basename",
",",
"'file'",
"=>",
"$",
"file",
",",
"'size'",
"=>",
"filesize",
"(",
"$",
"file",
")",
"]",
";",
"}",
",",
"glob",
"(",
"$",
"this",
"->",
"blocks",
".",
"\"*\"",
")",
")",
")",
";",
"uasort",
"(",
"$",
"files",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"return",
"$",
"a",
"[",
"'offset'",
"]",
"-",
"$",
"b",
"[",
"'offset'",
"]",
";",
"}",
")",
";",
"return",
"$",
"files",
";",
"}"
] | Returns all the wrote blocks of files. All the blocks are sorted by their offset.
@return array | [
"Returns",
"all",
"the",
"wrote",
"blocks",
"of",
"files",
".",
"All",
"the",
"blocks",
"are",
"sorted",
"by",
"their",
"offset",
"."
] | 13f88d8c2daf5fe9c70f8be6aeb3d862cd2a5e5a | https://github.com/crodas/ConcurrentFileWriter/blob/13f88d8c2daf5fe9c70f8be6aeb3d862cd2a5e5a/src/ConcurrentFileWriter/ConcurrentFileWriter.php#L139-L161 | train |