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
listlengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
listlengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/Match.php | Match.addPlayerInTeam | function addPlayerInTeam($login, $teamId)
{
switch($teamId)
{
case 0:
if(array_search($login, $this->team2))
{
throw new \InvalidArgumentException();
}
if(!array_search($login, $this->team1))
{
$this->team1[] = $login;
}
break;
case 1:
if(array_search($login, $this->team1))
{
throw new \InvalidArgumentException();
}
if(!array_search($login, $this->team2))
{
$this->team2[] = $login;
}
break;
default:
throw new \InvalidArgumentException();
}
} | php | function addPlayerInTeam($login, $teamId)
{
switch($teamId)
{
case 0:
if(array_search($login, $this->team2))
{
throw new \InvalidArgumentException();
}
if(!array_search($login, $this->team1))
{
$this->team1[] = $login;
}
break;
case 1:
if(array_search($login, $this->team1))
{
throw new \InvalidArgumentException();
}
if(!array_search($login, $this->team2))
{
$this->team2[] = $login;
}
break;
default:
throw new \InvalidArgumentException();
}
} | [
"function",
"addPlayerInTeam",
"(",
"$",
"login",
",",
"$",
"teamId",
")",
"{",
"switch",
"(",
"$",
"teamId",
")",
"{",
"case",
"0",
":",
"if",
"(",
"array_search",
"(",
"$",
"login",
",",
"$",
"this",
"->",
"team2",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"array_search",
"(",
"$",
"login",
",",
"$",
"this",
"->",
"team1",
")",
")",
"{",
"$",
"this",
"->",
"team1",
"[",
"]",
"=",
"$",
"login",
";",
"}",
"break",
";",
"case",
"1",
":",
"if",
"(",
"array_search",
"(",
"$",
"login",
",",
"$",
"this",
"->",
"team1",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"array_search",
"(",
"$",
"login",
",",
"$",
"this",
"->",
"team2",
")",
")",
"{",
"$",
"this",
"->",
"team2",
"[",
"]",
"=",
"$",
"login",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"}"
]
| add a login in a team, throw an exception if the login is already teamed or if the team does not exist
@param string $login
@param int $teamId
@throws \InvalidArgumentException | [
"add",
"a",
"login",
"in",
"a",
"team",
"throw",
"an",
"exception",
"if",
"the",
"login",
"is",
"already",
"teamed",
"or",
"if",
"the",
"team",
"does",
"not",
"exist"
]
| train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/Match.php#L112-L139 |
accgit/single-web | src/Single/Configurator.php | Configurator.enableTracy | public function enableTracy($logDirectory = null, $email = null)
{
Tracy\Debugger::$strictMode = true;
Tracy\Debugger::enable($this->mode, $logDirectory, $email);
} | php | public function enableTracy($logDirectory = null, $email = null)
{
Tracy\Debugger::$strictMode = true;
Tracy\Debugger::enable($this->mode, $logDirectory, $email);
} | [
"public",
"function",
"enableTracy",
"(",
"$",
"logDirectory",
"=",
"null",
",",
"$",
"email",
"=",
"null",
")",
"{",
"Tracy",
"\\",
"Debugger",
"::",
"$",
"strictMode",
"=",
"true",
";",
"Tracy",
"\\",
"Debugger",
"::",
"enable",
"(",
"$",
"this",
"->",
"mode",
",",
"$",
"logDirectory",
",",
"$",
"email",
")",
";",
"}"
]
| Enable Tracy Tools.
@param string $logDirectory
@param string $email | [
"Enable",
"Tracy",
"Tools",
"."
]
| train | https://github.com/accgit/single-web/blob/5d0dce3313df9e22ab60749bcf01f1753de8c143/src/Single/Configurator.php#L52-L56 |
accgit/single-web | src/Single/Configurator.php | Configurator.createAutoload | public function createAutoload($path)
{
$loader = new Loaders\RobotLoader;
$loader->setCacheStorage(new Caching\Storages\FileStorage($this->temp));
$loader->addDirectory($path)->register();
return $loader;
} | php | public function createAutoload($path)
{
$loader = new Loaders\RobotLoader;
$loader->setCacheStorage(new Caching\Storages\FileStorage($this->temp));
$loader->addDirectory($path)->register();
return $loader;
} | [
"public",
"function",
"createAutoload",
"(",
"$",
"path",
")",
"{",
"$",
"loader",
"=",
"new",
"Loaders",
"\\",
"RobotLoader",
";",
"$",
"loader",
"->",
"setCacheStorage",
"(",
"new",
"Caching",
"\\",
"Storages",
"\\",
"FileStorage",
"(",
"$",
"this",
"->",
"temp",
")",
")",
";",
"$",
"loader",
"->",
"addDirectory",
"(",
"$",
"path",
")",
"->",
"register",
"(",
")",
";",
"return",
"$",
"loader",
";",
"}"
]
| Autoloading classes.
@param string|array $path
@return Loaders\RobotLoader | [
"Autoloading",
"classes",
"."
]
| train | https://github.com/accgit/single-web/blob/5d0dce3313df9e22ab60749bcf01f1753de8c143/src/Single/Configurator.php#L63-L69 |
JeanWolf/yii2-jrbac | src/JDbManager.php | JDbManager.isRoot | public function isRoot()
{
if(\Yii::$app->getUser()->getIsGuest()) return false;
$user = \Yii::$app->getUser()->getIdentity();
if($user->getId() == 1) return true;
$auth = \Yii::$app->getAuthManager();
$roles = $auth->getRolesByUser($user->getId());
$roleNames = ArrayHelper::getColumn($roles,'name',false);
return in_array('root', $roleNames);
} | php | public function isRoot()
{
if(\Yii::$app->getUser()->getIsGuest()) return false;
$user = \Yii::$app->getUser()->getIdentity();
if($user->getId() == 1) return true;
$auth = \Yii::$app->getAuthManager();
$roles = $auth->getRolesByUser($user->getId());
$roleNames = ArrayHelper::getColumn($roles,'name',false);
return in_array('root', $roleNames);
} | [
"public",
"function",
"isRoot",
"(",
")",
"{",
"if",
"(",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getUser",
"(",
")",
"->",
"getIsGuest",
"(",
")",
")",
"return",
"false",
";",
"$",
"user",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getUser",
"(",
")",
"->",
"getIdentity",
"(",
")",
";",
"if",
"(",
"$",
"user",
"->",
"getId",
"(",
")",
"==",
"1",
")",
"return",
"true",
";",
"$",
"auth",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getAuthManager",
"(",
")",
";",
"$",
"roles",
"=",
"$",
"auth",
"->",
"getRolesByUser",
"(",
"$",
"user",
"->",
"getId",
"(",
")",
")",
";",
"$",
"roleNames",
"=",
"ArrayHelper",
"::",
"getColumn",
"(",
"$",
"roles",
",",
"'name'",
",",
"false",
")",
";",
"return",
"in_array",
"(",
"'root'",
",",
"$",
"roleNames",
")",
";",
"}"
]
| 类|方法 文档属性 eg: /** @jrbac 权限名称 | [
"类|方法",
"文档属性",
"eg:",
"/",
"**"
]
| train | https://github.com/JeanWolf/yii2-jrbac/blob/1e5c80038451bd5b385f83cb9344c3bd5edd85e0/src/JDbManager.php#L28-L37 |
anime-db/app-bundle | src/Command/ProposeUpdateCommand.php | ProposeUpdateCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$root = $this->getContainer()->getParameter('kernel.root_dir').'/../';
$time = filemtime($root.'composer.json');
if (file_exists($root.'composer.lock')) {
$time = max($time, filemtime($root.'composer.lock'));
}
// need update
if ($time + self::INERVAL_UPDATE < time()) {
$output->writeln('Application must be updated');
// send notice
$notice = new Notice();
$notice->setMessage(
$this->getContainer()->get('templating')->render('AnimeDbAppBundle:Notice:propose_update.html.twig')
);
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
$em->persist($notice);
$em->flush();
touch($root.'composer.json', time() + self::INERVAL_NOTIFICATION - self::INERVAL_UPDATE);
} else {
$output->writeln('Application is already updated');
}
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$root = $this->getContainer()->getParameter('kernel.root_dir').'/../';
$time = filemtime($root.'composer.json');
if (file_exists($root.'composer.lock')) {
$time = max($time, filemtime($root.'composer.lock'));
}
// need update
if ($time + self::INERVAL_UPDATE < time()) {
$output->writeln('Application must be updated');
// send notice
$notice = new Notice();
$notice->setMessage(
$this->getContainer()->get('templating')->render('AnimeDbAppBundle:Notice:propose_update.html.twig')
);
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
$em->persist($notice);
$em->flush();
touch($root.'composer.json', time() + self::INERVAL_NOTIFICATION - self::INERVAL_UPDATE);
} else {
$output->writeln('Application is already updated');
}
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"root",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"getParameter",
"(",
"'kernel.root_dir'",
")",
".",
"'/../'",
";",
"$",
"time",
"=",
"filemtime",
"(",
"$",
"root",
".",
"'composer.json'",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"root",
".",
"'composer.lock'",
")",
")",
"{",
"$",
"time",
"=",
"max",
"(",
"$",
"time",
",",
"filemtime",
"(",
"$",
"root",
".",
"'composer.lock'",
")",
")",
";",
"}",
"// need update",
"if",
"(",
"$",
"time",
"+",
"self",
"::",
"INERVAL_UPDATE",
"<",
"time",
"(",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'Application must be updated'",
")",
";",
"// send notice",
"$",
"notice",
"=",
"new",
"Notice",
"(",
")",
";",
"$",
"notice",
"->",
"setMessage",
"(",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'templating'",
")",
"->",
"render",
"(",
"'AnimeDbAppBundle:Notice:propose_update.html.twig'",
")",
")",
";",
"$",
"em",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'doctrine.orm.entity_manager'",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"notice",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"touch",
"(",
"$",
"root",
".",
"'composer.json'",
",",
"time",
"(",
")",
"+",
"self",
"::",
"INERVAL_NOTIFICATION",
"-",
"self",
"::",
"INERVAL_UPDATE",
")",
";",
"}",
"else",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'Application is already updated'",
")",
";",
"}",
"}"
]
| @param InputInterface $input
@param OutputInterface $output
@return bool | [
"@param",
"InputInterface",
"$input",
"@param",
"OutputInterface",
"$output"
]
| train | https://github.com/anime-db/app-bundle/blob/ca3b342081719d41ba018792a75970cbb1f1fe22/src/Command/ProposeUpdateCommand.php#L51-L77 |
fsi-open/doctrine-extensions-bundle | DependencyInjection/FSIDoctrineExtensionsExtension.php | FSIDoctrineExtensionsExtension.load | public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
if (class_exists('\FSi\Bundle\DataGridBundle\DataGridBundle')) {
$loader->load('services/datagrid.xml');
}
$this->setListenersConfiguration($container, $config);
$this->setUploadabbleConfigurationParameter($container, $config['uploadable_configuration']);
} | php | public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
if (class_exists('\FSi\Bundle\DataGridBundle\DataGridBundle')) {
$loader->load('services/datagrid.xml');
}
$this->setListenersConfiguration($container, $config);
$this->setUploadabbleConfigurationParameter($container, $config['uploadable_configuration']);
} | [
"public",
"function",
"load",
"(",
"array",
"$",
"configs",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"configuration",
"=",
"new",
"Configuration",
"(",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"processConfiguration",
"(",
"$",
"configuration",
",",
"$",
"configs",
")",
";",
"$",
"loader",
"=",
"new",
"Loader",
"\\",
"XmlFileLoader",
"(",
"$",
"container",
",",
"new",
"FileLocator",
"(",
"__DIR__",
".",
"'/../Resources/config'",
")",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services.xml'",
")",
";",
"if",
"(",
"class_exists",
"(",
"'\\FSi\\Bundle\\DataGridBundle\\DataGridBundle'",
")",
")",
"{",
"$",
"loader",
"->",
"load",
"(",
"'services/datagrid.xml'",
")",
";",
"}",
"$",
"this",
"->",
"setListenersConfiguration",
"(",
"$",
"container",
",",
"$",
"config",
")",
";",
"$",
"this",
"->",
"setUploadabbleConfigurationParameter",
"(",
"$",
"container",
",",
"$",
"config",
"[",
"'uploadable_configuration'",
"]",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/fsi-open/doctrine-extensions-bundle/blob/1b9c01e0b216b2c1b2af087de233abbf3c84b9fe/DependencyInjection/FSIDoctrineExtensionsExtension.php#L25-L37 |
qcubed/orm | src/Query/ModelTrait.php | ModelTrait.buildQueryStatement | protected static function buildQueryStatement(
&$objQueryBuilder,
iCondition $objConditions,
$objOptionalClauses,
$mixParameterArray,
$blnCountOnly
) {
// Get the Database Object for this Class
$objDatabase = static::getDatabase();
$strTableName = static::getTableName();
// Create/Build out the QueryBuilder object with class-specific SELECT and FROM fields
$objQueryBuilder = new Builder($objDatabase, $strTableName);
$blnAddAllFieldsToSelect = true;
if ($objDatabase->OnlyFullGroupBy) {
// see if we have any group by or aggregation clauses, if yes, don't add all the fields to select clause by default
// because these databases post an error instead of just choosing a value to return when a select item could
// have multiple values
if ($objOptionalClauses instanceof iClause) {
if ($objOptionalClauses instanceof Clause\AggregationBase || $objOptionalClauses instanceof Clause\GroupBy) {
$blnAddAllFieldsToSelect = false;
}
} else {
if (is_array($objOptionalClauses)) {
foreach ($objOptionalClauses as $objClause) {
if ($objClause instanceof Clause\AggregationBase || $objClause instanceof Clause\GroupBy) {
$blnAddAllFieldsToSelect = false;
break;
}
}
}
}
}
$objQueryBuilder->addFromItem($strTableName);
// Set "CountOnly" option (if applicable)
if ($blnCountOnly) {
$objQueryBuilder->setCountOnlyFlag();
}
// Apply Any Conditions
if ($objConditions) {
try {
$objConditions->updateQueryBuilder($objQueryBuilder);
} catch (Caller $objExc) {
$objExc->incrementOffset();
$objExc->incrementOffset();
throw $objExc;
}
}
// Iterate through all the Optional Clauses (if any) and perform accordingly
if ($objOptionalClauses) {
if ($objOptionalClauses instanceof iClause) {
try {
$objOptionalClauses->updateQueryBuilder($objQueryBuilder);
} catch (Caller $objExc) {
$objExc->incrementOffset();
$objExc->incrementOffset();
throw $objExc;
}
} else {
if (is_array($objOptionalClauses)) {
foreach ($objOptionalClauses as $objClause) {
try {
$objClause->updateQueryBuilder($objQueryBuilder);
} catch (Caller $objExc) {
$objExc->incrementOffset();
$objExc->incrementOffset();
throw $objExc;
}
}
} else {
throw new Caller('Optional Clauses must be a iClause object or an array of iClause objects');
}
}
}
// Do this here because it needs to know if distinct clause is included, and that is determined above
$objSelectClauses = QQ::extractSelectClause($objOptionalClauses);
if ($objSelectClauses || $blnAddAllFieldsToSelect) {
static::baseNode()->putSelectFields($objQueryBuilder, null, $objSelectClauses);
}
// Get the SQL Statement
$strQuery = $objQueryBuilder->getStatement();
// Substitute the correct sql variable names for the placeholders specified in the query, if any.
if ($mixParameterArray) {
if (is_array($mixParameterArray)) {
if (count($mixParameterArray)) {
$strQuery = $objDatabase->prepareStatement($strQuery, $mixParameterArray);
}
// Ensure that there are no other Unresolved Named Parameters
if (strpos($strQuery, chr(Node\NamedValue::DELIMITER_CODE) . '{') !== false) {
throw new Caller('Unresolved named parameters in the query');
}
} else {
throw new Caller('Parameter Array must be an array of name-value parameter pairs');
}
}
// Return the Objects
return $strQuery;
} | php | protected static function buildQueryStatement(
&$objQueryBuilder,
iCondition $objConditions,
$objOptionalClauses,
$mixParameterArray,
$blnCountOnly
) {
// Get the Database Object for this Class
$objDatabase = static::getDatabase();
$strTableName = static::getTableName();
// Create/Build out the QueryBuilder object with class-specific SELECT and FROM fields
$objQueryBuilder = new Builder($objDatabase, $strTableName);
$blnAddAllFieldsToSelect = true;
if ($objDatabase->OnlyFullGroupBy) {
// see if we have any group by or aggregation clauses, if yes, don't add all the fields to select clause by default
// because these databases post an error instead of just choosing a value to return when a select item could
// have multiple values
if ($objOptionalClauses instanceof iClause) {
if ($objOptionalClauses instanceof Clause\AggregationBase || $objOptionalClauses instanceof Clause\GroupBy) {
$blnAddAllFieldsToSelect = false;
}
} else {
if (is_array($objOptionalClauses)) {
foreach ($objOptionalClauses as $objClause) {
if ($objClause instanceof Clause\AggregationBase || $objClause instanceof Clause\GroupBy) {
$blnAddAllFieldsToSelect = false;
break;
}
}
}
}
}
$objQueryBuilder->addFromItem($strTableName);
// Set "CountOnly" option (if applicable)
if ($blnCountOnly) {
$objQueryBuilder->setCountOnlyFlag();
}
// Apply Any Conditions
if ($objConditions) {
try {
$objConditions->updateQueryBuilder($objQueryBuilder);
} catch (Caller $objExc) {
$objExc->incrementOffset();
$objExc->incrementOffset();
throw $objExc;
}
}
// Iterate through all the Optional Clauses (if any) and perform accordingly
if ($objOptionalClauses) {
if ($objOptionalClauses instanceof iClause) {
try {
$objOptionalClauses->updateQueryBuilder($objQueryBuilder);
} catch (Caller $objExc) {
$objExc->incrementOffset();
$objExc->incrementOffset();
throw $objExc;
}
} else {
if (is_array($objOptionalClauses)) {
foreach ($objOptionalClauses as $objClause) {
try {
$objClause->updateQueryBuilder($objQueryBuilder);
} catch (Caller $objExc) {
$objExc->incrementOffset();
$objExc->incrementOffset();
throw $objExc;
}
}
} else {
throw new Caller('Optional Clauses must be a iClause object or an array of iClause objects');
}
}
}
// Do this here because it needs to know if distinct clause is included, and that is determined above
$objSelectClauses = QQ::extractSelectClause($objOptionalClauses);
if ($objSelectClauses || $blnAddAllFieldsToSelect) {
static::baseNode()->putSelectFields($objQueryBuilder, null, $objSelectClauses);
}
// Get the SQL Statement
$strQuery = $objQueryBuilder->getStatement();
// Substitute the correct sql variable names for the placeholders specified in the query, if any.
if ($mixParameterArray) {
if (is_array($mixParameterArray)) {
if (count($mixParameterArray)) {
$strQuery = $objDatabase->prepareStatement($strQuery, $mixParameterArray);
}
// Ensure that there are no other Unresolved Named Parameters
if (strpos($strQuery, chr(Node\NamedValue::DELIMITER_CODE) . '{') !== false) {
throw new Caller('Unresolved named parameters in the query');
}
} else {
throw new Caller('Parameter Array must be an array of name-value parameter pairs');
}
}
// Return the Objects
return $strQuery;
} | [
"protected",
"static",
"function",
"buildQueryStatement",
"(",
"&",
"$",
"objQueryBuilder",
",",
"iCondition",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
",",
"$",
"mixParameterArray",
",",
"$",
"blnCountOnly",
")",
"{",
"// Get the Database Object for this Class",
"$",
"objDatabase",
"=",
"static",
"::",
"getDatabase",
"(",
")",
";",
"$",
"strTableName",
"=",
"static",
"::",
"getTableName",
"(",
")",
";",
"// Create/Build out the QueryBuilder object with class-specific SELECT and FROM fields",
"$",
"objQueryBuilder",
"=",
"new",
"Builder",
"(",
"$",
"objDatabase",
",",
"$",
"strTableName",
")",
";",
"$",
"blnAddAllFieldsToSelect",
"=",
"true",
";",
"if",
"(",
"$",
"objDatabase",
"->",
"OnlyFullGroupBy",
")",
"{",
"// see if we have any group by or aggregation clauses, if yes, don't add all the fields to select clause by default",
"// because these databases post an error instead of just choosing a value to return when a select item could",
"// have multiple values",
"if",
"(",
"$",
"objOptionalClauses",
"instanceof",
"iClause",
")",
"{",
"if",
"(",
"$",
"objOptionalClauses",
"instanceof",
"Clause",
"\\",
"AggregationBase",
"||",
"$",
"objOptionalClauses",
"instanceof",
"Clause",
"\\",
"GroupBy",
")",
"{",
"$",
"blnAddAllFieldsToSelect",
"=",
"false",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"objOptionalClauses",
")",
")",
"{",
"foreach",
"(",
"$",
"objOptionalClauses",
"as",
"$",
"objClause",
")",
"{",
"if",
"(",
"$",
"objClause",
"instanceof",
"Clause",
"\\",
"AggregationBase",
"||",
"$",
"objClause",
"instanceof",
"Clause",
"\\",
"GroupBy",
")",
"{",
"$",
"blnAddAllFieldsToSelect",
"=",
"false",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"$",
"objQueryBuilder",
"->",
"addFromItem",
"(",
"$",
"strTableName",
")",
";",
"// Set \"CountOnly\" option (if applicable)",
"if",
"(",
"$",
"blnCountOnly",
")",
"{",
"$",
"objQueryBuilder",
"->",
"setCountOnlyFlag",
"(",
")",
";",
"}",
"// Apply Any Conditions",
"if",
"(",
"$",
"objConditions",
")",
"{",
"try",
"{",
"$",
"objConditions",
"->",
"updateQueryBuilder",
"(",
"$",
"objQueryBuilder",
")",
";",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"}",
"// Iterate through all the Optional Clauses (if any) and perform accordingly",
"if",
"(",
"$",
"objOptionalClauses",
")",
"{",
"if",
"(",
"$",
"objOptionalClauses",
"instanceof",
"iClause",
")",
"{",
"try",
"{",
"$",
"objOptionalClauses",
"->",
"updateQueryBuilder",
"(",
"$",
"objQueryBuilder",
")",
";",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"objOptionalClauses",
")",
")",
"{",
"foreach",
"(",
"$",
"objOptionalClauses",
"as",
"$",
"objClause",
")",
"{",
"try",
"{",
"$",
"objClause",
"->",
"updateQueryBuilder",
"(",
"$",
"objQueryBuilder",
")",
";",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"}",
"}",
"else",
"{",
"throw",
"new",
"Caller",
"(",
"'Optional Clauses must be a iClause object or an array of iClause objects'",
")",
";",
"}",
"}",
"}",
"// Do this here because it needs to know if distinct clause is included, and that is determined above",
"$",
"objSelectClauses",
"=",
"QQ",
"::",
"extractSelectClause",
"(",
"$",
"objOptionalClauses",
")",
";",
"if",
"(",
"$",
"objSelectClauses",
"||",
"$",
"blnAddAllFieldsToSelect",
")",
"{",
"static",
"::",
"baseNode",
"(",
")",
"->",
"putSelectFields",
"(",
"$",
"objQueryBuilder",
",",
"null",
",",
"$",
"objSelectClauses",
")",
";",
"}",
"// Get the SQL Statement",
"$",
"strQuery",
"=",
"$",
"objQueryBuilder",
"->",
"getStatement",
"(",
")",
";",
"// Substitute the correct sql variable names for the placeholders specified in the query, if any.",
"if",
"(",
"$",
"mixParameterArray",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"mixParameterArray",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"mixParameterArray",
")",
")",
"{",
"$",
"strQuery",
"=",
"$",
"objDatabase",
"->",
"prepareStatement",
"(",
"$",
"strQuery",
",",
"$",
"mixParameterArray",
")",
";",
"}",
"// Ensure that there are no other Unresolved Named Parameters",
"if",
"(",
"strpos",
"(",
"$",
"strQuery",
",",
"chr",
"(",
"Node",
"\\",
"NamedValue",
"::",
"DELIMITER_CODE",
")",
".",
"'{'",
")",
"!==",
"false",
")",
"{",
"throw",
"new",
"Caller",
"(",
"'Unresolved named parameters in the query'",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"Caller",
"(",
"'Parameter Array must be an array of name-value parameter pairs'",
")",
";",
"}",
"}",
"// Return the Objects",
"return",
"$",
"strQuery",
";",
"}"
]
| Takes a query builder object and outputs the sql query that corresponds to its structure and the given parameters.
@param Builder &$objQueryBuilder the QueryBuilder object that will be created
@param iCondition $objConditions any conditions on the query, itself
@param iClause[] $objOptionalClauses additional optional iClause object or array of iClause objects for this query
@param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with (sending in null will skip the PrepareStatement step)
@param boolean $blnCountOnly only select a rowcount
@return string the query statement
@throws Caller | [
"Takes",
"a",
"query",
"builder",
"object",
"and",
"outputs",
"the",
"sql",
"query",
"that",
"corresponds",
"to",
"its",
"structure",
"and",
"the",
"given",
"parameters",
"."
]
| train | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/ModelTrait.php#L89-L199 |
qcubed/orm | src/Query/ModelTrait.php | ModelTrait._QuerySingle | protected static function _QuerySingle(
iCondition $objConditions,
$objOptionalClauses = null,
$mixParameterArray = null
) {
// Get the Query Statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, false);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Perform the Query, Get the First Row, and Instantiate a new object
$objDbResult = $objQueryBuilder->Database->query($strQuery);
// Do we have to expand anything?
if ($objQueryBuilder->ExpandAsArrayNode) {
$objToReturn = array();
$objPrevItemArray = array();
while ($objDbRow = $objDbResult->getNextRow()) {
$objItem = static::instantiateDbRow($objDbRow, null, $objQueryBuilder->ExpandAsArrayNode,
$objPrevItemArray, $objQueryBuilder->ColumnAliasArray);
if ($objItem) {
$objToReturn[] = $objItem;
$pk = $objItem->primaryKey();
if ($pk) {
$objPrevItemArray[$pk][] = $objItem;
} else {
$objPrevItemArray[] = $objItem;
}
}
}
if (count($objToReturn)) {
// Since we only want the object to return, lets return the object and not the array.
return $objToReturn[0];
} else {
return null;
}
} else {
// No expands just return the first row
$objDbRow = $objDbResult->getNextRow();
if (null === $objDbRow) {
return null;
}
return static::instantiateDbRow($objDbRow, null, null, null, $objQueryBuilder->ColumnAliasArray);
}
} | php | protected static function _QuerySingle(
iCondition $objConditions,
$objOptionalClauses = null,
$mixParameterArray = null
) {
// Get the Query Statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, false);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Perform the Query, Get the First Row, and Instantiate a new object
$objDbResult = $objQueryBuilder->Database->query($strQuery);
// Do we have to expand anything?
if ($objQueryBuilder->ExpandAsArrayNode) {
$objToReturn = array();
$objPrevItemArray = array();
while ($objDbRow = $objDbResult->getNextRow()) {
$objItem = static::instantiateDbRow($objDbRow, null, $objQueryBuilder->ExpandAsArrayNode,
$objPrevItemArray, $objQueryBuilder->ColumnAliasArray);
if ($objItem) {
$objToReturn[] = $objItem;
$pk = $objItem->primaryKey();
if ($pk) {
$objPrevItemArray[$pk][] = $objItem;
} else {
$objPrevItemArray[] = $objItem;
}
}
}
if (count($objToReturn)) {
// Since we only want the object to return, lets return the object and not the array.
return $objToReturn[0];
} else {
return null;
}
} else {
// No expands just return the first row
$objDbRow = $objDbResult->getNextRow();
if (null === $objDbRow) {
return null;
}
return static::instantiateDbRow($objDbRow, null, null, null, $objQueryBuilder->ColumnAliasArray);
}
} | [
"protected",
"static",
"function",
"_QuerySingle",
"(",
"iCondition",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
"=",
"null",
",",
"$",
"mixParameterArray",
"=",
"null",
")",
"{",
"// Get the Query Statement",
"try",
"{",
"$",
"strQuery",
"=",
"static",
"::",
"buildQueryStatement",
"(",
"$",
"objQueryBuilder",
",",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
",",
"$",
"mixParameterArray",
",",
"false",
")",
";",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"// Perform the Query, Get the First Row, and Instantiate a new object",
"$",
"objDbResult",
"=",
"$",
"objQueryBuilder",
"->",
"Database",
"->",
"query",
"(",
"$",
"strQuery",
")",
";",
"// Do we have to expand anything?",
"if",
"(",
"$",
"objQueryBuilder",
"->",
"ExpandAsArrayNode",
")",
"{",
"$",
"objToReturn",
"=",
"array",
"(",
")",
";",
"$",
"objPrevItemArray",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"objDbRow",
"=",
"$",
"objDbResult",
"->",
"getNextRow",
"(",
")",
")",
"{",
"$",
"objItem",
"=",
"static",
"::",
"instantiateDbRow",
"(",
"$",
"objDbRow",
",",
"null",
",",
"$",
"objQueryBuilder",
"->",
"ExpandAsArrayNode",
",",
"$",
"objPrevItemArray",
",",
"$",
"objQueryBuilder",
"->",
"ColumnAliasArray",
")",
";",
"if",
"(",
"$",
"objItem",
")",
"{",
"$",
"objToReturn",
"[",
"]",
"=",
"$",
"objItem",
";",
"$",
"pk",
"=",
"$",
"objItem",
"->",
"primaryKey",
"(",
")",
";",
"if",
"(",
"$",
"pk",
")",
"{",
"$",
"objPrevItemArray",
"[",
"$",
"pk",
"]",
"[",
"]",
"=",
"$",
"objItem",
";",
"}",
"else",
"{",
"$",
"objPrevItemArray",
"[",
"]",
"=",
"$",
"objItem",
";",
"}",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"objToReturn",
")",
")",
"{",
"// Since we only want the object to return, lets return the object and not the array.",
"return",
"$",
"objToReturn",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"else",
"{",
"// No expands just return the first row",
"$",
"objDbRow",
"=",
"$",
"objDbResult",
"->",
"getNextRow",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"objDbRow",
")",
"{",
"return",
"null",
";",
"}",
"return",
"static",
"::",
"instantiateDbRow",
"(",
"$",
"objDbRow",
",",
"null",
",",
"null",
",",
"null",
",",
"$",
"objQueryBuilder",
"->",
"ColumnAliasArray",
")",
";",
"}",
"}"
]
| Static Qcubed Query method to query for a single <?php echo $objTable->ClassName ?> object.
Uses BuildQueryStatment to perform most of the work.
Is called by QuerySincle function of each object so that the correct return type will be put in the comments.
@param iCondition $objConditions any conditions on the query, itself
@param null $objOptionalClauses
@param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
@throws Exception
@throws Caller
@return null|object the queried object | [
"Static",
"Qcubed",
"Query",
"method",
"to",
"query",
"for",
"a",
"single",
"<?php",
"echo",
"$objTable",
"-",
">",
"ClassName",
"?",
">",
"object",
".",
"Uses",
"BuildQueryStatment",
"to",
"perform",
"most",
"of",
"the",
"work",
".",
"Is",
"called",
"by",
"QuerySincle",
"function",
"of",
"each",
"object",
"so",
"that",
"the",
"correct",
"return",
"type",
"will",
"be",
"put",
"in",
"the",
"comments",
"."
]
| train | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/ModelTrait.php#L213-L261 |
qcubed/orm | src/Query/ModelTrait.php | ModelTrait._QueryArray | protected static function _QueryArray(
iCondition $objConditions,
$objOptionalClauses = null,
$mixParameterArray = null
) {
// Get the Query Statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, false);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Perform the Query and Instantiate the Array Result
$objDbResult = $objQueryBuilder->Database->query($strQuery);
return static::instantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNode,
$objQueryBuilder->ColumnAliasArray);
} | php | protected static function _QueryArray(
iCondition $objConditions,
$objOptionalClauses = null,
$mixParameterArray = null
) {
// Get the Query Statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, false);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Perform the Query and Instantiate the Array Result
$objDbResult = $objQueryBuilder->Database->query($strQuery);
return static::instantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNode,
$objQueryBuilder->ColumnAliasArray);
} | [
"protected",
"static",
"function",
"_QueryArray",
"(",
"iCondition",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
"=",
"null",
",",
"$",
"mixParameterArray",
"=",
"null",
")",
"{",
"// Get the Query Statement",
"try",
"{",
"$",
"strQuery",
"=",
"static",
"::",
"buildQueryStatement",
"(",
"$",
"objQueryBuilder",
",",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
",",
"$",
"mixParameterArray",
",",
"false",
")",
";",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"// Perform the Query and Instantiate the Array Result",
"$",
"objDbResult",
"=",
"$",
"objQueryBuilder",
"->",
"Database",
"->",
"query",
"(",
"$",
"strQuery",
")",
";",
"return",
"static",
"::",
"instantiateDbResult",
"(",
"$",
"objDbResult",
",",
"$",
"objQueryBuilder",
"->",
"ExpandAsArrayNode",
",",
"$",
"objQueryBuilder",
"->",
"ColumnAliasArray",
")",
";",
"}"
]
| Static Qcubed Query method to query for an array of objects.
Uses BuildQueryStatment to perform most of the work.
Is called by QueryArray function of each object so that the correct return type will be put in the comments.
@param iCondition $objConditions any conditions on the query, itself
@param iClause[]|null $objOptionalClauses additional optional iClause objects for this query
@param mixed[]|null $mixParameterArray an array of name-value pairs to substitute in to the placeholders in the query, if needed
@return mixed[] an array of objects
@throws Caller | [
"Static",
"Qcubed",
"Query",
"method",
"to",
"query",
"for",
"an",
"array",
"of",
"objects",
".",
"Uses",
"BuildQueryStatment",
"to",
"perform",
"most",
"of",
"the",
"work",
".",
"Is",
"called",
"by",
"QueryArray",
"function",
"of",
"each",
"object",
"so",
"that",
"the",
"correct",
"return",
"type",
"will",
"be",
"put",
"in",
"the",
"comments",
"."
]
| train | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/ModelTrait.php#L274-L292 |
qcubed/orm | src/Query/ModelTrait.php | ModelTrait.queryCursor | public static function queryCursor(iCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null)
{
// Get the query statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, false);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Pull Expansions
$objExpandAsArrayNode = $objQueryBuilder->ExpandAsArrayNode;
if (!empty ($objExpandAsArrayNode)) {
throw new Caller ("Cannot use QueryCursor with ExpandAsArray");
}
// Perform the query
$objDbResult = $objQueryBuilder->Database->query($strQuery);
// Get the alias array so we know how to instantiate a row from the result
$objDbResult->ColumnAliasArray = $objQueryBuilder->ColumnAliasArray;
return $objDbResult;
} | php | public static function queryCursor(iCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null)
{
// Get the query statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, false);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Pull Expansions
$objExpandAsArrayNode = $objQueryBuilder->ExpandAsArrayNode;
if (!empty ($objExpandAsArrayNode)) {
throw new Caller ("Cannot use QueryCursor with ExpandAsArray");
}
// Perform the query
$objDbResult = $objQueryBuilder->Database->query($strQuery);
// Get the alias array so we know how to instantiate a row from the result
$objDbResult->ColumnAliasArray = $objQueryBuilder->ColumnAliasArray;
return $objDbResult;
} | [
"public",
"static",
"function",
"queryCursor",
"(",
"iCondition",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
"=",
"null",
",",
"$",
"mixParameterArray",
"=",
"null",
")",
"{",
"// Get the query statement",
"try",
"{",
"$",
"strQuery",
"=",
"static",
"::",
"buildQueryStatement",
"(",
"$",
"objQueryBuilder",
",",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
",",
"$",
"mixParameterArray",
",",
"false",
")",
";",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"// Pull Expansions",
"$",
"objExpandAsArrayNode",
"=",
"$",
"objQueryBuilder",
"->",
"ExpandAsArrayNode",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"objExpandAsArrayNode",
")",
")",
"{",
"throw",
"new",
"Caller",
"(",
"\"Cannot use QueryCursor with ExpandAsArray\"",
")",
";",
"}",
"// Perform the query",
"$",
"objDbResult",
"=",
"$",
"objQueryBuilder",
"->",
"Database",
"->",
"query",
"(",
"$",
"strQuery",
")",
";",
"// Get the alias array so we know how to instantiate a row from the result",
"$",
"objDbResult",
"->",
"ColumnAliasArray",
"=",
"$",
"objQueryBuilder",
"->",
"ColumnAliasArray",
";",
"return",
"$",
"objDbResult",
";",
"}"
]
| Static Qcubed query method to issue a query and get a cursor to progressively fetch its results.
Uses BuildQueryStatment to perform most of the work.
@param iCondition $objConditions any conditions on the query, itself
@param iClause[] $objOptionalClauses additional optional iClause objects for this query
@param mixed[] $mixParameterArray an array of name-value pairs to substitute in to the placeholders in the query, if needed
@return Database\ResultBase the cursor resource instance
@throws Exception
@throws Caller | [
"Static",
"Qcubed",
"query",
"method",
"to",
"issue",
"a",
"query",
"and",
"get",
"a",
"cursor",
"to",
"progressively",
"fetch",
"its",
"results",
".",
"Uses",
"BuildQueryStatment",
"to",
"perform",
"most",
"of",
"the",
"work",
"."
]
| train | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/ModelTrait.php#L305-L328 |
qcubed/orm | src/Query/ModelTrait.php | ModelTrait.queryCount | public static function queryCount(iCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null)
{
// Get the Query Statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, true);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Perform the Query and return the row_count
$objDbResult = $objQueryBuilder->Database->query($strQuery);
// Figure out if the query is using GroupBy
$blnGrouped = false;
if ($objOptionalClauses) {
if ($objOptionalClauses instanceof iClause) {
if ($objOptionalClauses instanceof Clause\GroupBy) {
$blnGrouped = true;
}
} else {
if (is_array($objOptionalClauses)) {
foreach ($objOptionalClauses as $objClause) {
if ($objClause instanceof Clause\GroupBy) {
$blnGrouped = true;
break;
}
}
} else {
throw new Caller('Optional Clauses must be a iClause object or an array of iClause objects');
}
}
}
if ($blnGrouped) // Groups in this query - return the count of Groups (which is the count of all rows)
{
return $objDbResult->countRows();
} else {
// No Groups - return the sql-calculated count(*) value
$strDbRow = $objDbResult->fetchRow();
return (integer)$strDbRow[0];
}
} | php | public static function queryCount(iCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null)
{
// Get the Query Statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, true);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Perform the Query and return the row_count
$objDbResult = $objQueryBuilder->Database->query($strQuery);
// Figure out if the query is using GroupBy
$blnGrouped = false;
if ($objOptionalClauses) {
if ($objOptionalClauses instanceof iClause) {
if ($objOptionalClauses instanceof Clause\GroupBy) {
$blnGrouped = true;
}
} else {
if (is_array($objOptionalClauses)) {
foreach ($objOptionalClauses as $objClause) {
if ($objClause instanceof Clause\GroupBy) {
$blnGrouped = true;
break;
}
}
} else {
throw new Caller('Optional Clauses must be a iClause object or an array of iClause objects');
}
}
}
if ($blnGrouped) // Groups in this query - return the count of Groups (which is the count of all rows)
{
return $objDbResult->countRows();
} else {
// No Groups - return the sql-calculated count(*) value
$strDbRow = $objDbResult->fetchRow();
return (integer)$strDbRow[0];
}
} | [
"public",
"static",
"function",
"queryCount",
"(",
"iCondition",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
"=",
"null",
",",
"$",
"mixParameterArray",
"=",
"null",
")",
"{",
"// Get the Query Statement",
"try",
"{",
"$",
"strQuery",
"=",
"static",
"::",
"buildQueryStatement",
"(",
"$",
"objQueryBuilder",
",",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
",",
"$",
"mixParameterArray",
",",
"true",
")",
";",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"// Perform the Query and return the row_count",
"$",
"objDbResult",
"=",
"$",
"objQueryBuilder",
"->",
"Database",
"->",
"query",
"(",
"$",
"strQuery",
")",
";",
"// Figure out if the query is using GroupBy",
"$",
"blnGrouped",
"=",
"false",
";",
"if",
"(",
"$",
"objOptionalClauses",
")",
"{",
"if",
"(",
"$",
"objOptionalClauses",
"instanceof",
"iClause",
")",
"{",
"if",
"(",
"$",
"objOptionalClauses",
"instanceof",
"Clause",
"\\",
"GroupBy",
")",
"{",
"$",
"blnGrouped",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"objOptionalClauses",
")",
")",
"{",
"foreach",
"(",
"$",
"objOptionalClauses",
"as",
"$",
"objClause",
")",
"{",
"if",
"(",
"$",
"objClause",
"instanceof",
"Clause",
"\\",
"GroupBy",
")",
"{",
"$",
"blnGrouped",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"throw",
"new",
"Caller",
"(",
"'Optional Clauses must be a iClause object or an array of iClause objects'",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"blnGrouped",
")",
"// Groups in this query - return the count of Groups (which is the count of all rows)",
"{",
"return",
"$",
"objDbResult",
"->",
"countRows",
"(",
")",
";",
"}",
"else",
"{",
"// No Groups - return the sql-calculated count(*) value",
"$",
"strDbRow",
"=",
"$",
"objDbResult",
"->",
"fetchRow",
"(",
")",
";",
"return",
"(",
"integer",
")",
"$",
"strDbRow",
"[",
"0",
"]",
";",
"}",
"}"
]
| Static Qcubed Query method to query for a count of objects.
Uses BuildQueryStatment to perform most of the work.
@param iCondition $objConditions any conditions on the query, itself
@param iClause[] $objOptionalClauses additional optional iClause objects for this query
@param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
@return integer the count of queried objects as an integer
@throws Caller | [
"Static",
"Qcubed",
"Query",
"method",
"to",
"query",
"for",
"a",
"count",
"of",
"objects",
".",
"Uses",
"BuildQueryStatment",
"to",
"perform",
"most",
"of",
"the",
"work",
"."
]
| train | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/ModelTrait.php#L340-L384 |
qcubed/orm | src/Query/ModelTrait.php | ModelTrait.expandArray | public static function expandArray(
$objDbRow,
$strAliasPrefix,
$objNode,
$objPreviousItemArray,
$strColumnAliasArray
) {
if (!$objNode->ChildNodeArray) {
return null;
}
$blnExpanded = null;
$pk = static::getRowPrimaryKey($objDbRow, $strAliasPrefix, $strColumnAliasArray);
foreach ($objPreviousItemArray as $objPreviousItem) {
if ($pk != $objPreviousItem->primaryKey()) {
continue;
}
foreach ($objNode->ChildNodeArray as $objChildNode) {
$strPropName = $objChildNode->_PropertyName;
$strClassName = $objChildNode->_ClassName;
$strLongAlias = $objChildNode->fullAlias();
$blnExpandAsArray = false;
if ($objChildNode->ExpandAsArray) {
$strPostfix = 'Array';
$blnExpandAsArray = true;
} else {
$strPostfix = '';
}
$nodeType = $objChildNode->_Type;
if ($nodeType == 'reverse_reference') {
$strPrefix = '_obj';
} elseif ($nodeType == 'association') {
$objChildNode = $objChildNode->firstChild();
if ($objChildNode->IsType) {
$strPrefix = '_int';
} else {
$strPrefix = '_obj';
}
} else {
$strPrefix = 'obj';
}
$strVarName = $strPrefix . $strPropName . $strPostfix;
if ($blnExpandAsArray) {
if (null === $objPreviousItem->$strVarName) {
$objPreviousItem->$strVarName = array();
}
if (count($objPreviousItem->$strVarName)) {
$objPreviousChildItems = $objPreviousItem->$strVarName;
$nextAlias = $objChildNode->fullAlias() . '__';
$objChildItem = $strClassName::instantiateDbRow($objDbRow, $nextAlias, $objChildNode,
$objPreviousChildItems, $strColumnAliasArray, true);
if ($objChildItem) {
$objPreviousItem->{$strVarName}[] = $objChildItem;
$blnExpanded = true;
} elseif ($objChildItem === false) {
$blnExpanded = true;
}
}
} elseif (!$objChildNode->IsType) {
// Follow single node if keys match
if (null === $objPreviousItem->$strVarName) {
return false;
}
$objPreviousChildItems = array($objPreviousItem->$strVarName);
$blnResult = $strClassName::expandArray($objDbRow, $strLongAlias . '__', $objChildNode,
$objPreviousChildItems, $strColumnAliasArray);
if ($blnResult) {
$blnExpanded = true;
}
}
}
}
return $blnExpanded;
} | php | public static function expandArray(
$objDbRow,
$strAliasPrefix,
$objNode,
$objPreviousItemArray,
$strColumnAliasArray
) {
if (!$objNode->ChildNodeArray) {
return null;
}
$blnExpanded = null;
$pk = static::getRowPrimaryKey($objDbRow, $strAliasPrefix, $strColumnAliasArray);
foreach ($objPreviousItemArray as $objPreviousItem) {
if ($pk != $objPreviousItem->primaryKey()) {
continue;
}
foreach ($objNode->ChildNodeArray as $objChildNode) {
$strPropName = $objChildNode->_PropertyName;
$strClassName = $objChildNode->_ClassName;
$strLongAlias = $objChildNode->fullAlias();
$blnExpandAsArray = false;
if ($objChildNode->ExpandAsArray) {
$strPostfix = 'Array';
$blnExpandAsArray = true;
} else {
$strPostfix = '';
}
$nodeType = $objChildNode->_Type;
if ($nodeType == 'reverse_reference') {
$strPrefix = '_obj';
} elseif ($nodeType == 'association') {
$objChildNode = $objChildNode->firstChild();
if ($objChildNode->IsType) {
$strPrefix = '_int';
} else {
$strPrefix = '_obj';
}
} else {
$strPrefix = 'obj';
}
$strVarName = $strPrefix . $strPropName . $strPostfix;
if ($blnExpandAsArray) {
if (null === $objPreviousItem->$strVarName) {
$objPreviousItem->$strVarName = array();
}
if (count($objPreviousItem->$strVarName)) {
$objPreviousChildItems = $objPreviousItem->$strVarName;
$nextAlias = $objChildNode->fullAlias() . '__';
$objChildItem = $strClassName::instantiateDbRow($objDbRow, $nextAlias, $objChildNode,
$objPreviousChildItems, $strColumnAliasArray, true);
if ($objChildItem) {
$objPreviousItem->{$strVarName}[] = $objChildItem;
$blnExpanded = true;
} elseif ($objChildItem === false) {
$blnExpanded = true;
}
}
} elseif (!$objChildNode->IsType) {
// Follow single node if keys match
if (null === $objPreviousItem->$strVarName) {
return false;
}
$objPreviousChildItems = array($objPreviousItem->$strVarName);
$blnResult = $strClassName::expandArray($objDbRow, $strLongAlias . '__', $objChildNode,
$objPreviousChildItems, $strColumnAliasArray);
if ($blnResult) {
$blnExpanded = true;
}
}
}
}
return $blnExpanded;
} | [
"public",
"static",
"function",
"expandArray",
"(",
"$",
"objDbRow",
",",
"$",
"strAliasPrefix",
",",
"$",
"objNode",
",",
"$",
"objPreviousItemArray",
",",
"$",
"strColumnAliasArray",
")",
"{",
"if",
"(",
"!",
"$",
"objNode",
"->",
"ChildNodeArray",
")",
"{",
"return",
"null",
";",
"}",
"$",
"blnExpanded",
"=",
"null",
";",
"$",
"pk",
"=",
"static",
"::",
"getRowPrimaryKey",
"(",
"$",
"objDbRow",
",",
"$",
"strAliasPrefix",
",",
"$",
"strColumnAliasArray",
")",
";",
"foreach",
"(",
"$",
"objPreviousItemArray",
"as",
"$",
"objPreviousItem",
")",
"{",
"if",
"(",
"$",
"pk",
"!=",
"$",
"objPreviousItem",
"->",
"primaryKey",
"(",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"objNode",
"->",
"ChildNodeArray",
"as",
"$",
"objChildNode",
")",
"{",
"$",
"strPropName",
"=",
"$",
"objChildNode",
"->",
"_PropertyName",
";",
"$",
"strClassName",
"=",
"$",
"objChildNode",
"->",
"_ClassName",
";",
"$",
"strLongAlias",
"=",
"$",
"objChildNode",
"->",
"fullAlias",
"(",
")",
";",
"$",
"blnExpandAsArray",
"=",
"false",
";",
"if",
"(",
"$",
"objChildNode",
"->",
"ExpandAsArray",
")",
"{",
"$",
"strPostfix",
"=",
"'Array'",
";",
"$",
"blnExpandAsArray",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"strPostfix",
"=",
"''",
";",
"}",
"$",
"nodeType",
"=",
"$",
"objChildNode",
"->",
"_Type",
";",
"if",
"(",
"$",
"nodeType",
"==",
"'reverse_reference'",
")",
"{",
"$",
"strPrefix",
"=",
"'_obj'",
";",
"}",
"elseif",
"(",
"$",
"nodeType",
"==",
"'association'",
")",
"{",
"$",
"objChildNode",
"=",
"$",
"objChildNode",
"->",
"firstChild",
"(",
")",
";",
"if",
"(",
"$",
"objChildNode",
"->",
"IsType",
")",
"{",
"$",
"strPrefix",
"=",
"'_int'",
";",
"}",
"else",
"{",
"$",
"strPrefix",
"=",
"'_obj'",
";",
"}",
"}",
"else",
"{",
"$",
"strPrefix",
"=",
"'obj'",
";",
"}",
"$",
"strVarName",
"=",
"$",
"strPrefix",
".",
"$",
"strPropName",
".",
"$",
"strPostfix",
";",
"if",
"(",
"$",
"blnExpandAsArray",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"objPreviousItem",
"->",
"$",
"strVarName",
")",
"{",
"$",
"objPreviousItem",
"->",
"$",
"strVarName",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"objPreviousItem",
"->",
"$",
"strVarName",
")",
")",
"{",
"$",
"objPreviousChildItems",
"=",
"$",
"objPreviousItem",
"->",
"$",
"strVarName",
";",
"$",
"nextAlias",
"=",
"$",
"objChildNode",
"->",
"fullAlias",
"(",
")",
".",
"'__'",
";",
"$",
"objChildItem",
"=",
"$",
"strClassName",
"::",
"instantiateDbRow",
"(",
"$",
"objDbRow",
",",
"$",
"nextAlias",
",",
"$",
"objChildNode",
",",
"$",
"objPreviousChildItems",
",",
"$",
"strColumnAliasArray",
",",
"true",
")",
";",
"if",
"(",
"$",
"objChildItem",
")",
"{",
"$",
"objPreviousItem",
"->",
"{",
"$",
"strVarName",
"}",
"[",
"]",
"=",
"$",
"objChildItem",
";",
"$",
"blnExpanded",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"objChildItem",
"===",
"false",
")",
"{",
"$",
"blnExpanded",
"=",
"true",
";",
"}",
"}",
"}",
"elseif",
"(",
"!",
"$",
"objChildNode",
"->",
"IsType",
")",
"{",
"// Follow single node if keys match",
"if",
"(",
"null",
"===",
"$",
"objPreviousItem",
"->",
"$",
"strVarName",
")",
"{",
"return",
"false",
";",
"}",
"$",
"objPreviousChildItems",
"=",
"array",
"(",
"$",
"objPreviousItem",
"->",
"$",
"strVarName",
")",
";",
"$",
"blnResult",
"=",
"$",
"strClassName",
"::",
"expandArray",
"(",
"$",
"objDbRow",
",",
"$",
"strLongAlias",
".",
"'__'",
",",
"$",
"objChildNode",
",",
"$",
"objPreviousChildItems",
",",
"$",
"strColumnAliasArray",
")",
";",
"if",
"(",
"$",
"blnResult",
")",
"{",
"$",
"blnExpanded",
"=",
"true",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"blnExpanded",
";",
"}"
]
| Do a possible array expansion on the given node. If the node is an ExpandAsArray node,
it will add to the corresponding array in the object. Otherwise, it will follow the node
so that any leaf expansions can be handled.
@param \QCubed\Database\RowBase $objDbRow
@param string $strAliasPrefix
@param Node\NodeBase $objNode
@param array $objPreviousItemArray
@param string[] $strColumnAliasArray
@return boolean|null Returns true if the we used the row for an expansion, false if we already expanded this node in a previous row, or null if no expansion data was found | [
"Do",
"a",
"possible",
"array",
"expansion",
"on",
"the",
"given",
"node",
".",
"If",
"the",
"node",
"is",
"an",
"ExpandAsArray",
"node",
"it",
"will",
"add",
"to",
"the",
"corresponding",
"array",
"in",
"the",
"object",
".",
"Otherwise",
"it",
"will",
"follow",
"the",
"node",
"so",
"that",
"any",
"leaf",
"expansions",
"can",
"be",
"handled",
"."
]
| train | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/ModelTrait.php#L416-L498 |
netgen/ngopengraph | classes/ngopengraphgmaplocation.php | ngOpenGraphGmapLocation.getData | public function getData()
{
$latitude = trim( $this->ContentObjectAttribute->attribute( 'content' )->attribute( 'latitude' ) );
$longitude = trim( $this->ContentObjectAttribute->attribute( 'content' )->attribute( 'longitude' ) );
return $latitude . ',' . $longitude;
} | php | public function getData()
{
$latitude = trim( $this->ContentObjectAttribute->attribute( 'content' )->attribute( 'latitude' ) );
$longitude = trim( $this->ContentObjectAttribute->attribute( 'content' )->attribute( 'longitude' ) );
return $latitude . ',' . $longitude;
} | [
"public",
"function",
"getData",
"(",
")",
"{",
"$",
"latitude",
"=",
"trim",
"(",
"$",
"this",
"->",
"ContentObjectAttribute",
"->",
"attribute",
"(",
"'content'",
")",
"->",
"attribute",
"(",
"'latitude'",
")",
")",
";",
"$",
"longitude",
"=",
"trim",
"(",
"$",
"this",
"->",
"ContentObjectAttribute",
"->",
"attribute",
"(",
"'content'",
")",
"->",
"attribute",
"(",
"'longitude'",
")",
")",
";",
"return",
"$",
"latitude",
".",
"','",
".",
"$",
"longitude",
";",
"}"
]
| Returns data for the attribute
@return string | [
"Returns",
"data",
"for",
"the",
"attribute"
]
| train | https://github.com/netgen/ngopengraph/blob/68a99862f240ee74174ea9b888a9a33743142e27/classes/ngopengraphgmaplocation.php#L10-L15 |
flipboxstudio/orm-manager | src/Flipbox/OrmManager/DatabaseConnection.php | DatabaseConnection.initDoctrine | protected function initDoctrine()
{
try {
$this->doctrine = $this->db->getDoctrineSchemaManager();
$platform = $this->doctrine->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
$platform->registerDoctrineTypeMapping('json', 'json_array');
$this->connection = true;
} catch (PDOException $e) {
$this->connection = false;
}
} | php | protected function initDoctrine()
{
try {
$this->doctrine = $this->db->getDoctrineSchemaManager();
$platform = $this->doctrine->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
$platform->registerDoctrineTypeMapping('json', 'json_array');
$this->connection = true;
} catch (PDOException $e) {
$this->connection = false;
}
} | [
"protected",
"function",
"initDoctrine",
"(",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"doctrine",
"=",
"$",
"this",
"->",
"db",
"->",
"getDoctrineSchemaManager",
"(",
")",
";",
"$",
"platform",
"=",
"$",
"this",
"->",
"doctrine",
"->",
"getDatabasePlatform",
"(",
")",
";",
"$",
"platform",
"->",
"registerDoctrineTypeMapping",
"(",
"'enum'",
",",
"'string'",
")",
";",
"$",
"platform",
"->",
"registerDoctrineTypeMapping",
"(",
"'json'",
",",
"'json_array'",
")",
";",
"$",
"this",
"->",
"connection",
"=",
"true",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"connection",
"=",
"false",
";",
"}",
"}"
]
| initialize doctrine
@param
@return void | [
"initialize",
"doctrine"
]
| train | https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/DatabaseConnection.php#L61-L74 |
flipboxstudio/orm-manager | src/Flipbox/OrmManager/DatabaseConnection.php | DatabaseConnection.scanDatabase | protected function scanDatabase()
{
if ($this->isConnected()) {
$tables = $this->doctrine->listTableNames();
foreach ($tables as $table) {
$schTable = $this->doctrine->listTableDetails($table);
$this->tables[$table] = $this->getTableFields($schTable);
}
}
} | php | protected function scanDatabase()
{
if ($this->isConnected()) {
$tables = $this->doctrine->listTableNames();
foreach ($tables as $table) {
$schTable = $this->doctrine->listTableDetails($table);
$this->tables[$table] = $this->getTableFields($schTable);
}
}
} | [
"protected",
"function",
"scanDatabase",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isConnected",
"(",
")",
")",
"{",
"$",
"tables",
"=",
"$",
"this",
"->",
"doctrine",
"->",
"listTableNames",
"(",
")",
";",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"table",
")",
"{",
"$",
"schTable",
"=",
"$",
"this",
"->",
"doctrine",
"->",
"listTableDetails",
"(",
"$",
"table",
")",
";",
"$",
"this",
"->",
"tables",
"[",
"$",
"table",
"]",
"=",
"$",
"this",
"->",
"getTableFields",
"(",
"$",
"schTable",
")",
";",
"}",
"}",
"}"
]
| scan database
@return void | [
"scan",
"database"
]
| train | https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/DatabaseConnection.php#L81-L92 |
flipboxstudio/orm-manager | src/Flipbox/OrmManager/DatabaseConnection.php | DatabaseConnection.getTableFields | protected function getTableFields(Table $table)
{
$fileds = [];
foreach ($table->getColumns() as $column) {
$fileds[] = [
'name' => $column->getName(),
'type' => $column->getType()->getName(),
'not_null' => $column->getNotnull(),
'length' => $column->getLength(),
'unsigned' => $column->getUnsigned(),
'autoincrement' => $column->getAutoincrement(),
'primary_key' => $this->isPrimaryKey($table, $column),
'foreign_key' => $this->isForeignKey($table, $column)
];
}
return $fileds;
} | php | protected function getTableFields(Table $table)
{
$fileds = [];
foreach ($table->getColumns() as $column) {
$fileds[] = [
'name' => $column->getName(),
'type' => $column->getType()->getName(),
'not_null' => $column->getNotnull(),
'length' => $column->getLength(),
'unsigned' => $column->getUnsigned(),
'autoincrement' => $column->getAutoincrement(),
'primary_key' => $this->isPrimaryKey($table, $column),
'foreign_key' => $this->isForeignKey($table, $column)
];
}
return $fileds;
} | [
"protected",
"function",
"getTableFields",
"(",
"Table",
"$",
"table",
")",
"{",
"$",
"fileds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"fileds",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"column",
"->",
"getName",
"(",
")",
",",
"'type'",
"=>",
"$",
"column",
"->",
"getType",
"(",
")",
"->",
"getName",
"(",
")",
",",
"'not_null'",
"=>",
"$",
"column",
"->",
"getNotnull",
"(",
")",
",",
"'length'",
"=>",
"$",
"column",
"->",
"getLength",
"(",
")",
",",
"'unsigned'",
"=>",
"$",
"column",
"->",
"getUnsigned",
"(",
")",
",",
"'autoincrement'",
"=>",
"$",
"column",
"->",
"getAutoincrement",
"(",
")",
",",
"'primary_key'",
"=>",
"$",
"this",
"->",
"isPrimaryKey",
"(",
"$",
"table",
",",
"$",
"column",
")",
",",
"'foreign_key'",
"=>",
"$",
"this",
"->",
"isForeignKey",
"(",
"$",
"table",
",",
"$",
"column",
")",
"]",
";",
"}",
"return",
"$",
"fileds",
";",
"}"
]
| get database fileds
@param Table $table
@return array | [
"get",
"database",
"fileds"
]
| train | https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/DatabaseConnection.php#L100-L118 |
flipboxstudio/orm-manager | src/Flipbox/OrmManager/DatabaseConnection.php | DatabaseConnection.isPrimaryKey | protected function isPrimaryKey(Table $table, Column $column)
{
if ($table->hasPrimaryKey()) {
$primaryKeys = $table->getPrimaryKey()->getColumns();
return in_array($column->getName(), $primaryKeys);
}
return false;
} | php | protected function isPrimaryKey(Table $table, Column $column)
{
if ($table->hasPrimaryKey()) {
$primaryKeys = $table->getPrimaryKey()->getColumns();
return in_array($column->getName(), $primaryKeys);
}
return false;
} | [
"protected",
"function",
"isPrimaryKey",
"(",
"Table",
"$",
"table",
",",
"Column",
"$",
"column",
")",
"{",
"if",
"(",
"$",
"table",
"->",
"hasPrimaryKey",
"(",
")",
")",
"{",
"$",
"primaryKeys",
"=",
"$",
"table",
"->",
"getPrimaryKey",
"(",
")",
"->",
"getColumns",
"(",
")",
";",
"return",
"in_array",
"(",
"$",
"column",
"->",
"getName",
"(",
")",
",",
"$",
"primaryKeys",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| check is column primary key
@param Table $table
@param Column $column
@return bool | [
"check",
"is",
"column",
"primary",
"key"
]
| train | https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/DatabaseConnection.php#L127-L136 |
flipboxstudio/orm-manager | src/Flipbox/OrmManager/DatabaseConnection.php | DatabaseConnection.isForeignKey | protected function isForeignKey(Table $table, Column $column)
{
$foreignKey = false;
foreach ($table->getIndexes() as $key => $index) {
if ($key !== 'primary') {
try {
$fkConstrain = $table->getForeignkey($key);
$foreignKey = in_array($column->getName(), $fkConstrain->getColumns());
} catch (Exception $e) {
//do noting
}
}
}
return $foreignKey;
} | php | protected function isForeignKey(Table $table, Column $column)
{
$foreignKey = false;
foreach ($table->getIndexes() as $key => $index) {
if ($key !== 'primary') {
try {
$fkConstrain = $table->getForeignkey($key);
$foreignKey = in_array($column->getName(), $fkConstrain->getColumns());
} catch (Exception $e) {
//do noting
}
}
}
return $foreignKey;
} | [
"protected",
"function",
"isForeignKey",
"(",
"Table",
"$",
"table",
",",
"Column",
"$",
"column",
")",
"{",
"$",
"foreignKey",
"=",
"false",
";",
"foreach",
"(",
"$",
"table",
"->",
"getIndexes",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"index",
")",
"{",
"if",
"(",
"$",
"key",
"!==",
"'primary'",
")",
"{",
"try",
"{",
"$",
"fkConstrain",
"=",
"$",
"table",
"->",
"getForeignkey",
"(",
"$",
"key",
")",
";",
"$",
"foreignKey",
"=",
"in_array",
"(",
"$",
"column",
"->",
"getName",
"(",
")",
",",
"$",
"fkConstrain",
"->",
"getColumns",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"//do noting",
"}",
"}",
"}",
"return",
"$",
"foreignKey",
";",
"}"
]
| check is column foreign key
@param Table $table
@param Column $column
@return bool | [
"check",
"is",
"column",
"foreign",
"key"
]
| train | https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/DatabaseConnection.php#L145-L161 |
flipboxstudio/orm-manager | src/Flipbox/OrmManager/DatabaseConnection.php | DatabaseConnection.getFields | public function getFields($table)
{
if (isset($this->tables[$table])) {
return new Collection($this->tables[$table]);
}
} | php | public function getFields($table)
{
if (isset($this->tables[$table])) {
return new Collection($this->tables[$table]);
}
} | [
"public",
"function",
"getFields",
"(",
"$",
"table",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"tables",
"[",
"$",
"table",
"]",
")",
")",
"{",
"return",
"new",
"Collection",
"(",
"$",
"this",
"->",
"tables",
"[",
"$",
"table",
"]",
")",
";",
"}",
"}"
]
| get table fields
@param string $table
@return array | [
"get",
"table",
"fields"
]
| train | https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/DatabaseConnection.php#L189-L194 |
flipboxstudio/orm-manager | src/Flipbox/OrmManager/DatabaseConnection.php | DatabaseConnection.isFieldExists | public function isFieldExists($table, $field)
{
if (isset($this->tables[$table])) {
$fields = $this->getFields($table);
return $fields->where('name', $field)->count() > 0;
}
return false;
} | php | public function isFieldExists($table, $field)
{
if (isset($this->tables[$table])) {
$fields = $this->getFields($table);
return $fields->where('name', $field)->count() > 0;
}
return false;
} | [
"public",
"function",
"isFieldExists",
"(",
"$",
"table",
",",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"tables",
"[",
"$",
"table",
"]",
")",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"getFields",
"(",
"$",
"table",
")",
";",
"return",
"$",
"fields",
"->",
"where",
"(",
"'name'",
",",
"$",
"field",
")",
"->",
"count",
"(",
")",
">",
"0",
";",
"}",
"return",
"false",
";",
"}"
]
| check is model table exists
@param string $table
@param string $field
@return bool | [
"check",
"is",
"model",
"table",
"exists"
]
| train | https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/DatabaseConnection.php#L214-L223 |
phpmob/changmin | src/PhpMob/CmsBundle/Context/CachedCompositeLocaleContext.php | CachedCompositeLocaleContext.getLocaleCode | public function getLocaleCode(): string
{
if ($this->cachedLocaleCode) {
return $this->cachedLocaleCode;
}
return $this->cachedLocaleCode = $this->compositeContext->getLocaleCode();
} | php | public function getLocaleCode(): string
{
if ($this->cachedLocaleCode) {
return $this->cachedLocaleCode;
}
return $this->cachedLocaleCode = $this->compositeContext->getLocaleCode();
} | [
"public",
"function",
"getLocaleCode",
"(",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"cachedLocaleCode",
")",
"{",
"return",
"$",
"this",
"->",
"cachedLocaleCode",
";",
"}",
"return",
"$",
"this",
"->",
"cachedLocaleCode",
"=",
"$",
"this",
"->",
"compositeContext",
"->",
"getLocaleCode",
"(",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CmsBundle/Context/CachedCompositeLocaleContext.php#L53-L60 |
VincentChalnot/SidusEAVFilterBundle | Filter/Type/AdvancedNumberFilterType.php | AdvancedNumberFilterType.applyAttributeQueryBuilder | protected function applyAttributeQueryBuilder(
AttributeQueryBuilderInterface $attributeQb,
$data
): AttributeQueryBuilderInterface {
$input = $data['input'];
switch ($data['option']) {
case 'exact':
return $attributeQb->equals($input);
case 'greaterthan':
return $attributeQb->gt($input);
case 'lowerthan':
return $attributeQb->lt($input);
case 'greaterthanequals':
return $attributeQb->gte($input);
case 'lowerthanequals':
return $attributeQb->lte($input);
case 'empty':
return $attributeQb->equals('');
case 'notempty':
return $attributeQb->notEquals('');
case 'null':
return $attributeQb->isNull();
case 'notnull':
return $attributeQb->isNotNull();
}
throw new \UnexpectedValueException("Unknown option '{$data['option']}'");
} | php | protected function applyAttributeQueryBuilder(
AttributeQueryBuilderInterface $attributeQb,
$data
): AttributeQueryBuilderInterface {
$input = $data['input'];
switch ($data['option']) {
case 'exact':
return $attributeQb->equals($input);
case 'greaterthan':
return $attributeQb->gt($input);
case 'lowerthan':
return $attributeQb->lt($input);
case 'greaterthanequals':
return $attributeQb->gte($input);
case 'lowerthanequals':
return $attributeQb->lte($input);
case 'empty':
return $attributeQb->equals('');
case 'notempty':
return $attributeQb->notEquals('');
case 'null':
return $attributeQb->isNull();
case 'notnull':
return $attributeQb->isNotNull();
}
throw new \UnexpectedValueException("Unknown option '{$data['option']}'");
} | [
"protected",
"function",
"applyAttributeQueryBuilder",
"(",
"AttributeQueryBuilderInterface",
"$",
"attributeQb",
",",
"$",
"data",
")",
":",
"AttributeQueryBuilderInterface",
"{",
"$",
"input",
"=",
"$",
"data",
"[",
"'input'",
"]",
";",
"switch",
"(",
"$",
"data",
"[",
"'option'",
"]",
")",
"{",
"case",
"'exact'",
":",
"return",
"$",
"attributeQb",
"->",
"equals",
"(",
"$",
"input",
")",
";",
"case",
"'greaterthan'",
":",
"return",
"$",
"attributeQb",
"->",
"gt",
"(",
"$",
"input",
")",
";",
"case",
"'lowerthan'",
":",
"return",
"$",
"attributeQb",
"->",
"lt",
"(",
"$",
"input",
")",
";",
"case",
"'greaterthanequals'",
":",
"return",
"$",
"attributeQb",
"->",
"gte",
"(",
"$",
"input",
")",
";",
"case",
"'lowerthanequals'",
":",
"return",
"$",
"attributeQb",
"->",
"lte",
"(",
"$",
"input",
")",
";",
"case",
"'empty'",
":",
"return",
"$",
"attributeQb",
"->",
"equals",
"(",
"''",
")",
";",
"case",
"'notempty'",
":",
"return",
"$",
"attributeQb",
"->",
"notEquals",
"(",
"''",
")",
";",
"case",
"'null'",
":",
"return",
"$",
"attributeQb",
"->",
"isNull",
"(",
")",
";",
"case",
"'notnull'",
":",
"return",
"$",
"attributeQb",
"->",
"isNotNull",
"(",
")",
";",
"}",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"Unknown option '{$data['option']}'\"",
")",
";",
"}"
]
| @param AttributeQueryBuilderInterface $attributeQb
@param mixed $data
@return AttributeQueryBuilderInterface | [
"@param",
"AttributeQueryBuilderInterface",
"$attributeQb",
"@param",
"mixed",
"$data"
]
| train | https://github.com/VincentChalnot/SidusEAVFilterBundle/blob/25a9e0495fae30cb96ecded56c50cf7fe70c9032/Filter/Type/AdvancedNumberFilterType.php#L20-L46 |
chubbyphp/chubbyphp-api-http | src/Serialization/ApiProblem/AbstractApiProblemMapping.php | AbstractApiProblemMapping.getNormalizationFieldMappings | public function getNormalizationFieldMappings(string $path): array
{
return [
NormalizationFieldMappingBuilder::create('type')->getMapping(),
NormalizationFieldMappingBuilder::create('title')->getMapping(),
NormalizationFieldMappingBuilder::create('detail')->getMapping(),
NormalizationFieldMappingBuilder::create('instance')->getMapping(),
];
} | php | public function getNormalizationFieldMappings(string $path): array
{
return [
NormalizationFieldMappingBuilder::create('type')->getMapping(),
NormalizationFieldMappingBuilder::create('title')->getMapping(),
NormalizationFieldMappingBuilder::create('detail')->getMapping(),
NormalizationFieldMappingBuilder::create('instance')->getMapping(),
];
} | [
"public",
"function",
"getNormalizationFieldMappings",
"(",
"string",
"$",
"path",
")",
":",
"array",
"{",
"return",
"[",
"NormalizationFieldMappingBuilder",
"::",
"create",
"(",
"'type'",
")",
"->",
"getMapping",
"(",
")",
",",
"NormalizationFieldMappingBuilder",
"::",
"create",
"(",
"'title'",
")",
"->",
"getMapping",
"(",
")",
",",
"NormalizationFieldMappingBuilder",
"::",
"create",
"(",
"'detail'",
")",
"->",
"getMapping",
"(",
")",
",",
"NormalizationFieldMappingBuilder",
"::",
"create",
"(",
"'instance'",
")",
"->",
"getMapping",
"(",
")",
",",
"]",
";",
"}"
]
| @param string $path
@return NormalizationFieldMappingInterface[] | [
"@param",
"string",
"$path"
]
| train | https://github.com/chubbyphp/chubbyphp-api-http/blob/675d657b686e96aa16be56d0e9e07aaa844266ed/src/Serialization/ApiProblem/AbstractApiProblemMapping.php#L27-L35 |
ARCANEDEV/Sanitizer | src/Filters/UrlFilter.php | UrlFilter.filter | public function filter($value, array $options = [])
{
if ( ! is_string($value)) return $value;
$value = trim($value);
if ( ! Str::startsWith($value, ['http://', 'https://'])) {
$value = "http://$value";
}
return filter_var($value, FILTER_SANITIZE_URL);
} | php | public function filter($value, array $options = [])
{
if ( ! is_string($value)) return $value;
$value = trim($value);
if ( ! Str::startsWith($value, ['http://', 'https://'])) {
$value = "http://$value";
}
return filter_var($value, FILTER_SANITIZE_URL);
} | [
"public",
"function",
"filter",
"(",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"return",
"$",
"value",
";",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"if",
"(",
"!",
"Str",
"::",
"startsWith",
"(",
"$",
"value",
",",
"[",
"'http://'",
",",
"'https://'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"\"http://$value\"",
";",
"}",
"return",
"filter_var",
"(",
"$",
"value",
",",
"FILTER_SANITIZE_URL",
")",
";",
"}"
]
| Sanitize url of the given string.
@param mixed $value
@param array $options
@return string|mixed | [
"Sanitize",
"url",
"of",
"the",
"given",
"string",
"."
]
| train | https://github.com/ARCANEDEV/Sanitizer/blob/e21990ce6d881366d52a7f4e5040b07cc3ecca96/src/Filters/UrlFilter.php#L26-L37 |
webforge-labs/psc-cms | lib/Psc/UI/Button.php | Button.setLeftIcon | public function setLeftIcon($icon) {
$this->leftIcon = $icon;
$this->widgetOptions['icons']['primary'] = 'ui-icon-'.$this->leftIcon;
return $this;
} | php | public function setLeftIcon($icon) {
$this->leftIcon = $icon;
$this->widgetOptions['icons']['primary'] = 'ui-icon-'.$this->leftIcon;
return $this;
} | [
"public",
"function",
"setLeftIcon",
"(",
"$",
"icon",
")",
"{",
"$",
"this",
"->",
"leftIcon",
"=",
"$",
"icon",
";",
"$",
"this",
"->",
"widgetOptions",
"[",
"'icons'",
"]",
"[",
"'primary'",
"]",
"=",
"'ui-icon-'",
".",
"$",
"this",
"->",
"leftIcon",
";",
"return",
"$",
"this",
";",
"}"
]
| http://jqueryui.com/themeroller
@param string $icon der Name des Icons ohne ui-icon- davor | [
"http",
":",
"//",
"jqueryui",
".",
"com",
"/",
"themeroller"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/UI/Button.php#L96-L100 |
webforge-labs/psc-cms | lib/Psc/UI/Button.php | Button.setRightIcon | public function setRightIcon($icon) {
$this->rightIcon = $icon;
$this->widgetOptions['icons']['secondary'] = 'ui-icon-'.$this->rightIcon;
return $this;
} | php | public function setRightIcon($icon) {
$this->rightIcon = $icon;
$this->widgetOptions['icons']['secondary'] = 'ui-icon-'.$this->rightIcon;
return $this;
} | [
"public",
"function",
"setRightIcon",
"(",
"$",
"icon",
")",
"{",
"$",
"this",
"->",
"rightIcon",
"=",
"$",
"icon",
";",
"$",
"this",
"->",
"widgetOptions",
"[",
"'icons'",
"]",
"[",
"'secondary'",
"]",
"=",
"'ui-icon-'",
".",
"$",
"this",
"->",
"rightIcon",
";",
"return",
"$",
"this",
";",
"}"
]
| http://jqueryui.com/themeroller
@param string $icon der Name des Icons ohne ui-icon- davor | [
"http",
":",
"//",
"jqueryui",
".",
"com",
"/",
"themeroller"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/UI/Button.php#L106-L110 |
webforge-labs/psc-cms | lib/Psc/UI/Button.php | Button.addData | public function addData($key, $value) {
if (!isset($this->data)) $this->data = array();
$this->data[$key] = $value;
return $this;
} | php | public function addData($key, $value) {
if (!isset($this->data)) $this->data = array();
$this->data[$key] = $value;
return $this;
} | [
"public",
"function",
"addData",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
")",
")",
"$",
"this",
"->",
"data",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
]
| Fügt für einen Schlüssel die jQuery Data dem Button hinzu
$button->addData('something', 'myvalue');
// javascript
$('button').data('something') === 'myvalue' | [
"Fügt",
"für",
"einen",
"Schlüssel",
"die",
"jQuery",
"Data",
"dem",
"Button",
"hinzu"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/UI/Button.php#L184-L188 |
AydinHassan/cli-md-renderer | src/Renderer/DocumentRenderer.php | DocumentRenderer.render | public function render(AbstractBlock $block, CliRenderer $renderer)
{
if (!($block instanceof Document)) {
throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
}
$wholeDoc = $renderer->renderBlocks($block->children());
return $wholeDoc === '' ? '' : $wholeDoc . "\n";
} | php | public function render(AbstractBlock $block, CliRenderer $renderer)
{
if (!($block instanceof Document)) {
throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
}
$wholeDoc = $renderer->renderBlocks($block->children());
return $wholeDoc === '' ? '' : $wholeDoc . "\n";
} | [
"public",
"function",
"render",
"(",
"AbstractBlock",
"$",
"block",
",",
"CliRenderer",
"$",
"renderer",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"block",
"instanceof",
"Document",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Incompatible block type: \"%s\"'",
",",
"get_class",
"(",
"$",
"block",
")",
")",
")",
";",
"}",
"$",
"wholeDoc",
"=",
"$",
"renderer",
"->",
"renderBlocks",
"(",
"$",
"block",
"->",
"children",
"(",
")",
")",
";",
"return",
"$",
"wholeDoc",
"===",
"''",
"?",
"''",
":",
"$",
"wholeDoc",
".",
"\"\\n\"",
";",
"}"
]
| @param AbstractBlock $block
@param CliRenderer $renderer
@return string | [
"@param",
"AbstractBlock",
"$block",
"@param",
"CliRenderer",
"$renderer"
]
| train | https://github.com/AydinHassan/cli-md-renderer/blob/521f9ace2aeadd58bf8a3910704be8360f5bd7b2/src/Renderer/DocumentRenderer.php#L24-L32 |
SAREhub/PHP_Commons | src/SAREhub/Commons/Misc/ArrayHelper.php | ArrayHelper.flatten | public static function flatten(array $input, $keySeparator = '.')
{
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($input),
RecursiveIteratorIterator::SELF_FIRST);
$path = [];
$output = [];
foreach ($iterator as $key => $value) {
$path[$iterator->getDepth()] = $key;
if (!is_array($value)) {
$output[implode($keySeparator, array_slice($path, 0, $iterator->getDepth() + 1))] = $value;
}
}
return $output;
} | php | public static function flatten(array $input, $keySeparator = '.')
{
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($input),
RecursiveIteratorIterator::SELF_FIRST);
$path = [];
$output = [];
foreach ($iterator as $key => $value) {
$path[$iterator->getDepth()] = $key;
if (!is_array($value)) {
$output[implode($keySeparator, array_slice($path, 0, $iterator->getDepth() + 1))] = $value;
}
}
return $output;
} | [
"public",
"static",
"function",
"flatten",
"(",
"array",
"$",
"input",
",",
"$",
"keySeparator",
"=",
"'.'",
")",
"{",
"$",
"iterator",
"=",
"new",
"RecursiveIteratorIterator",
"(",
"new",
"RecursiveArrayIterator",
"(",
"$",
"input",
")",
",",
"RecursiveIteratorIterator",
"::",
"SELF_FIRST",
")",
";",
"$",
"path",
"=",
"[",
"]",
";",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"path",
"[",
"$",
"iterator",
"->",
"getDepth",
"(",
")",
"]",
"=",
"$",
"key",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"output",
"[",
"implode",
"(",
"$",
"keySeparator",
",",
"array_slice",
"(",
"$",
"path",
",",
"0",
",",
"$",
"iterator",
"->",
"getDepth",
"(",
")",
"+",
"1",
")",
")",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"output",
";",
"}"
]
| /**
Flattens array into a one-dimensional array.
Each key in the returned one-dimensional array is the join of all keys leading to
each (non-traversable) value, in all dimensions, separated by a given separator.
@param array $input
@param string $keySeparator
@return array | [
"/",
"**",
"Flattens",
"array",
"into",
"a",
"one",
"-",
"dimensional",
"array",
".",
"Each",
"key",
"in",
"the",
"returned",
"one",
"-",
"dimensional",
"array",
"is",
"the",
"join",
"of",
"all",
"keys",
"leading",
"to",
"each",
"(",
"non",
"-",
"traversable",
")",
"value",
"in",
"all",
"dimensions",
"separated",
"by",
"a",
"given",
"separator",
"."
]
| train | https://github.com/SAREhub/PHP_Commons/blob/4e1769ab6411a584112df1151dcc90e6b82fe2bb/src/SAREhub/Commons/Misc/ArrayHelper.php#L22-L38 |
ipunkt/laravel-package-manager | src/Providers/ArtisanServiceProvider.php | ArtisanServiceProvider.register | public function register()
{
if ($this->registerOnlyForConsole && !$this->app->runningInConsole()) {
return;
}
$this->registerCommands($this->commands);
} | php | public function register()
{
if ($this->registerOnlyForConsole && !$this->app->runningInConsole()) {
return;
}
$this->registerCommands($this->commands);
} | [
"public",
"function",
"register",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"registerOnlyForConsole",
"&&",
"!",
"$",
"this",
"->",
"app",
"->",
"runningInConsole",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"registerCommands",
"(",
"$",
"this",
"->",
"commands",
")",
";",
"}"
]
| Register any application services.
@return void | [
"Register",
"any",
"application",
"services",
"."
]
| train | https://github.com/ipunkt/laravel-package-manager/blob/6ecfc9d933c37927e52c441d5019126be69e5817/src/Providers/ArtisanServiceProvider.php#L32-L39 |
ipunkt/laravel-package-manager | src/Providers/ArtisanServiceProvider.php | ArtisanServiceProvider.registerCommands | protected function registerCommands(array $commands)
{
if (!$this->app->runningInConsole()) {
return;
}
foreach ($commands as $key => $command) {
if (is_numeric($key)) {
$key = Str::lower(str_replace("\\", '.', $command));
}
$method = "register{$command}";
try {
if (method_exists($this, $method)) {
call_user_func_array([$this, $method], [$key]);
} else {
$this->app->singleton($key, function ($app) use ($command) {
return $app->make($command);
});
}
$this->commands($key);
} catch (\Exception $e) {
throw $e;
}
}
} | php | protected function registerCommands(array $commands)
{
if (!$this->app->runningInConsole()) {
return;
}
foreach ($commands as $key => $command) {
if (is_numeric($key)) {
$key = Str::lower(str_replace("\\", '.', $command));
}
$method = "register{$command}";
try {
if (method_exists($this, $method)) {
call_user_func_array([$this, $method], [$key]);
} else {
$this->app->singleton($key, function ($app) use ($command) {
return $app->make($command);
});
}
$this->commands($key);
} catch (\Exception $e) {
throw $e;
}
}
} | [
"protected",
"function",
"registerCommands",
"(",
"array",
"$",
"commands",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
"->",
"runningInConsole",
"(",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"commands",
"as",
"$",
"key",
"=>",
"$",
"command",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"Str",
"::",
"lower",
"(",
"str_replace",
"(",
"\"\\\\\"",
",",
"'.'",
",",
"$",
"command",
")",
")",
";",
"}",
"$",
"method",
"=",
"\"register{$command}\"",
";",
"try",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"$",
"method",
"]",
",",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"$",
"key",
",",
"function",
"(",
"$",
"app",
")",
"use",
"(",
"$",
"command",
")",
"{",
"return",
"$",
"app",
"->",
"make",
"(",
"$",
"command",
")",
";",
"}",
")",
";",
"}",
"$",
"this",
"->",
"commands",
"(",
"$",
"key",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"}"
]
| registers an array of commands (key is shortname and value is command class
or part of the registerYYYCommand method name)
@param array $commands
@throws \Exception | [
"registers",
"an",
"array",
"of",
"commands",
"(",
"key",
"is",
"shortname",
"and",
"value",
"is",
"command",
"class",
"or",
"part",
"of",
"the",
"registerYYYCommand",
"method",
"name",
")"
]
| train | https://github.com/ipunkt/laravel-package-manager/blob/6ecfc9d933c37927e52c441d5019126be69e5817/src/Providers/ArtisanServiceProvider.php#L49-L75 |
amostajo/wordpress-plugin-core | src/psr4/Cache.php | Cache.add | public static function add( $key, $value, $expires )
{
$cache = self::instance();
if ( $cache && $value != null) {
$cache->set( $key, $value, $expires * 60 );
}
} | php | public static function add( $key, $value, $expires )
{
$cache = self::instance();
if ( $cache && $value != null) {
$cache->set( $key, $value, $expires * 60 );
}
} | [
"public",
"static",
"function",
"add",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"expires",
")",
"{",
"$",
"cache",
"=",
"self",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"$",
"cache",
"&&",
"$",
"value",
"!=",
"null",
")",
"{",
"$",
"cache",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"expires",
"*",
"60",
")",
";",
"}",
"}"
]
| Adds a value to cache.
@since 1.0
@param string $key Main plugin object as reference.
@param mixed $value Value to cache.
@param int $expires Expiration time in minutes. | [
"Adds",
"a",
"value",
"to",
"cache",
"."
]
| train | https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Cache.php#L89-L95 |
amostajo/wordpress-plugin-core | src/psr4/Cache.php | Cache.has | public static function has( $key )
{
$cache = self::instance();
if ( $cache ) {
return $cache->isExisting( $key );
}
return false;
} | php | public static function has( $key )
{
$cache = self::instance();
if ( $cache ) {
return $cache->isExisting( $key );
}
return false;
} | [
"public",
"static",
"function",
"has",
"(",
"$",
"key",
")",
"{",
"$",
"cache",
"=",
"self",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"$",
"cache",
")",
"{",
"return",
"$",
"cache",
"->",
"isExisting",
"(",
"$",
"key",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Returns flag if a given key has a value in cache or not.
@since 1.0
@param string $key Cache key name.
@return bool | [
"Returns",
"flag",
"if",
"a",
"given",
"key",
"has",
"a",
"value",
"in",
"cache",
"or",
"not",
"."
]
| train | https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Cache.php#L103-L110 |
amostajo/wordpress-plugin-core | src/psr4/Cache.php | Cache.remember | public static function remember( $key, $expires, Closure $closure )
{
$cache = self::instance();
if ( $cache ) {
if ( $cache->isExisting( $key ) ) {
return $cache->get( $key );
} else if ( $closure != null ) {
$value = $closure();
$cache->set( $key, $value, $expires * 60 );
return $value;
}
}
return $closure();
} | php | public static function remember( $key, $expires, Closure $closure )
{
$cache = self::instance();
if ( $cache ) {
if ( $cache->isExisting( $key ) ) {
return $cache->get( $key );
} else if ( $closure != null ) {
$value = $closure();
$cache->set( $key, $value, $expires * 60 );
return $value;
}
}
return $closure();
} | [
"public",
"static",
"function",
"remember",
"(",
"$",
"key",
",",
"$",
"expires",
",",
"Closure",
"$",
"closure",
")",
"{",
"$",
"cache",
"=",
"self",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"$",
"cache",
")",
"{",
"if",
"(",
"$",
"cache",
"->",
"isExisting",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"cache",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"else",
"if",
"(",
"$",
"closure",
"!=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"closure",
"(",
")",
";",
"$",
"cache",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"expires",
"*",
"60",
")",
";",
"return",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"closure",
"(",
")",
";",
"}"
]
| Returns the value of a given key.
If it doesn't exist, then the value pass by is returned.
@since 1.0
@param string $key Main plugin object as reference.
@param int $expires Expiration time in minutes.
@param Closure $value Value to cache.
@return mixed | [
"Returns",
"the",
"value",
"of",
"a",
"given",
"key",
".",
"If",
"it",
"doesn",
"t",
"exist",
"then",
"the",
"value",
"pass",
"by",
"is",
"returned",
"."
]
| train | https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Cache.php#L121-L134 |
dashifen/wordpress-php7-plugin-boilerplate | src/Controller/AbstractController.php | AbstractController.defineActivationHooks | protected function defineActivationHooks(): void {
$backend = $this->getBackend();
$pluginName = $this->getFilename();
$handlers = ["activate", "deactivate", "uninstall"];
foreach ($handlers as $handler) {
// for each of our handlers, we hook an action handler to our
// backend component. the purpose of the BackendInterface is
// to guarantee that we have three methods, one for each of
// these hooks.
$hook = $handler . "_" . $pluginName;
$this->loader->addAction($hook, $backend, $handler);
}
} | php | protected function defineActivationHooks(): void {
$backend = $this->getBackend();
$pluginName = $this->getFilename();
$handlers = ["activate", "deactivate", "uninstall"];
foreach ($handlers as $handler) {
// for each of our handlers, we hook an action handler to our
// backend component. the purpose of the BackendInterface is
// to guarantee that we have three methods, one for each of
// these hooks.
$hook = $handler . "_" . $pluginName;
$this->loader->addAction($hook, $backend, $handler);
}
} | [
"protected",
"function",
"defineActivationHooks",
"(",
")",
":",
"void",
"{",
"$",
"backend",
"=",
"$",
"this",
"->",
"getBackend",
"(",
")",
";",
"$",
"pluginName",
"=",
"$",
"this",
"->",
"getFilename",
"(",
")",
";",
"$",
"handlers",
"=",
"[",
"\"activate\"",
",",
"\"deactivate\"",
",",
"\"uninstall\"",
"]",
";",
"foreach",
"(",
"$",
"handlers",
"as",
"$",
"handler",
")",
"{",
"// for each of our handlers, we hook an action handler to our",
"// backend component. the purpose of the BackendInterface is",
"// to guarantee that we have three methods, one for each of",
"// these hooks.",
"$",
"hook",
"=",
"$",
"handler",
".",
"\"_\"",
".",
"$",
"pluginName",
";",
"$",
"this",
"->",
"loader",
"->",
"addAction",
"(",
"$",
"hook",
",",
"$",
"backend",
",",
"$",
"handler",
")",
";",
"}",
"}"
]
| Defines hooks using the Backend object for the activate,
deactivate, and uninstall actions of this plugin.
@return void | [
"Defines",
"hooks",
"using",
"the",
"Backend",
"object",
"for",
"the",
"activate",
"deactivate",
"and",
"uninstall",
"actions",
"of",
"this",
"plugin",
"."
]
| train | https://github.com/dashifen/wordpress-php7-plugin-boilerplate/blob/c7875deb403d311efca72dc3c8beb566972a56cb/src/Controller/AbstractController.php#L115-L129 |
dashifen/wordpress-php7-plugin-boilerplate | src/Controller/AbstractController.php | AbstractController.getSetting | public function getSetting(string $setting) {
$settings = $this->getSettings();
$keys = array_keys($settings);
if (!in_array($setting, $keys)) {
throw new ControllerException("Unknown setting: $setting.",
ControllerException::UNKNOWN_SETTING);
}
return $settings[$setting];
} | php | public function getSetting(string $setting) {
$settings = $this->getSettings();
$keys = array_keys($settings);
if (!in_array($setting, $keys)) {
throw new ControllerException("Unknown setting: $setting.",
ControllerException::UNKNOWN_SETTING);
}
return $settings[$setting];
} | [
"public",
"function",
"getSetting",
"(",
"string",
"$",
"setting",
")",
"{",
"$",
"settings",
"=",
"$",
"this",
"->",
"getSettings",
"(",
")",
";",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"settings",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"setting",
",",
"$",
"keys",
")",
")",
"{",
"throw",
"new",
"ControllerException",
"(",
"\"Unknown setting: $setting.\"",
",",
"ControllerException",
"::",
"UNKNOWN_SETTING",
")",
";",
"}",
"return",
"$",
"settings",
"[",
"$",
"setting",
"]",
";",
"}"
]
| @param string $setting
@return mixed
@throws ControllerException | [
"@param",
"string",
"$setting"
]
| train | https://github.com/dashifen/wordpress-php7-plugin-boilerplate/blob/c7875deb403d311efca72dc3c8beb566972a56cb/src/Controller/AbstractController.php#L195-L205 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Feed/Builder.php | Zend_Feed_Builder._createHeader | private function _createHeader(array $data)
{
$mandatories = array('title', 'link', 'charset');
foreach ($mandatories as $mandatory) {
if (!isset($data[$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key is missing");
}
}
$this->_header = new Zend_Feed_Builder_Header($data['title'], $data['link'], $data['charset']);
if (isset($data['lastUpdate'])) {
$this->_header->setLastUpdate($data['lastUpdate']);
}
if (isset($data['published'])) {
$this->_header->setPublishedDate($data['published']);
}
if (isset($data['description'])) {
$this->_header->setDescription($data['description']);
}
if (isset($data['author'])) {
$this->_header->setAuthor($data['author']);
}
if (isset($data['email'])) {
$this->_header->setEmail($data['email']);
}
if (isset($data['webmaster'])) {
$this->_header->setWebmaster($data['webmaster']);
}
if (isset($data['copyright'])) {
$this->_header->setCopyright($data['copyright']);
}
if (isset($data['image'])) {
$this->_header->setImage($data['image']);
}
if (isset($data['generator'])) {
$this->_header->setGenerator($data['generator']);
}
if (isset($data['language'])) {
$this->_header->setLanguage($data['language']);
}
if (isset($data['ttl'])) {
$this->_header->setTtl($data['ttl']);
}
if (isset($data['rating'])) {
$this->_header->setRating($data['rating']);
}
if (isset($data['cloud'])) {
$mandatories = array('domain', 'path', 'registerProcedure', 'protocol');
foreach ($mandatories as $mandatory) {
if (!isset($data['cloud'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to define $mandatory property of your cloud");
}
}
$uri_str = 'http://' . $data['cloud']['domain'] . $data['cloud']['path'];
$this->_header->setCloud($uri_str, $data['cloud']['registerProcedure'], $data['cloud']['protocol']);
}
if (isset($data['textInput'])) {
$mandatories = array('title', 'description', 'name', 'link');
foreach ($mandatories as $mandatory) {
if (!isset($data['textInput'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to define $mandatory property of your textInput");
}
}
$this->_header->setTextInput($data['textInput']['title'],
$data['textInput']['description'],
$data['textInput']['name'],
$data['textInput']['link']);
}
if (isset($data['skipHours'])) {
$this->_header->setSkipHours($data['skipHours']);
}
if (isset($data['skipDays'])) {
$this->_header->setSkipDays($data['skipDays']);
}
if (isset($data['itunes'])) {
$itunes = new Zend_Feed_Builder_Header_Itunes($data['itunes']['category']);
if (isset($data['itunes']['author'])) {
$itunes->setAuthor($data['itunes']['author']);
}
if (isset($data['itunes']['owner'])) {
$name = isset($data['itunes']['owner']['name']) ? $data['itunes']['owner']['name'] : '';
$email = isset($data['itunes']['owner']['email']) ? $data['itunes']['owner']['email'] : '';
$itunes->setOwner($name, $email);
}
if (isset($data['itunes']['image'])) {
$itunes->setImage($data['itunes']['image']);
}
if (isset($data['itunes']['subtitle'])) {
$itunes->setSubtitle($data['itunes']['subtitle']);
}
if (isset($data['itunes']['summary'])) {
$itunes->setSummary($data['itunes']['summary']);
}
if (isset($data['itunes']['block'])) {
$itunes->setBlock($data['itunes']['block']);
}
if (isset($data['itunes']['explicit'])) {
$itunes->setExplicit($data['itunes']['explicit']);
}
if (isset($data['itunes']['keywords'])) {
$itunes->setKeywords($data['itunes']['keywords']);
}
if (isset($data['itunes']['new-feed-url'])) {
$itunes->setNewFeedUrl($data['itunes']['new-feed-url']);
}
$this->_header->setITunes($itunes);
}
} | php | private function _createHeader(array $data)
{
$mandatories = array('title', 'link', 'charset');
foreach ($mandatories as $mandatory) {
if (!isset($data[$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key is missing");
}
}
$this->_header = new Zend_Feed_Builder_Header($data['title'], $data['link'], $data['charset']);
if (isset($data['lastUpdate'])) {
$this->_header->setLastUpdate($data['lastUpdate']);
}
if (isset($data['published'])) {
$this->_header->setPublishedDate($data['published']);
}
if (isset($data['description'])) {
$this->_header->setDescription($data['description']);
}
if (isset($data['author'])) {
$this->_header->setAuthor($data['author']);
}
if (isset($data['email'])) {
$this->_header->setEmail($data['email']);
}
if (isset($data['webmaster'])) {
$this->_header->setWebmaster($data['webmaster']);
}
if (isset($data['copyright'])) {
$this->_header->setCopyright($data['copyright']);
}
if (isset($data['image'])) {
$this->_header->setImage($data['image']);
}
if (isset($data['generator'])) {
$this->_header->setGenerator($data['generator']);
}
if (isset($data['language'])) {
$this->_header->setLanguage($data['language']);
}
if (isset($data['ttl'])) {
$this->_header->setTtl($data['ttl']);
}
if (isset($data['rating'])) {
$this->_header->setRating($data['rating']);
}
if (isset($data['cloud'])) {
$mandatories = array('domain', 'path', 'registerProcedure', 'protocol');
foreach ($mandatories as $mandatory) {
if (!isset($data['cloud'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to define $mandatory property of your cloud");
}
}
$uri_str = 'http://' . $data['cloud']['domain'] . $data['cloud']['path'];
$this->_header->setCloud($uri_str, $data['cloud']['registerProcedure'], $data['cloud']['protocol']);
}
if (isset($data['textInput'])) {
$mandatories = array('title', 'description', 'name', 'link');
foreach ($mandatories as $mandatory) {
if (!isset($data['textInput'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to define $mandatory property of your textInput");
}
}
$this->_header->setTextInput($data['textInput']['title'],
$data['textInput']['description'],
$data['textInput']['name'],
$data['textInput']['link']);
}
if (isset($data['skipHours'])) {
$this->_header->setSkipHours($data['skipHours']);
}
if (isset($data['skipDays'])) {
$this->_header->setSkipDays($data['skipDays']);
}
if (isset($data['itunes'])) {
$itunes = new Zend_Feed_Builder_Header_Itunes($data['itunes']['category']);
if (isset($data['itunes']['author'])) {
$itunes->setAuthor($data['itunes']['author']);
}
if (isset($data['itunes']['owner'])) {
$name = isset($data['itunes']['owner']['name']) ? $data['itunes']['owner']['name'] : '';
$email = isset($data['itunes']['owner']['email']) ? $data['itunes']['owner']['email'] : '';
$itunes->setOwner($name, $email);
}
if (isset($data['itunes']['image'])) {
$itunes->setImage($data['itunes']['image']);
}
if (isset($data['itunes']['subtitle'])) {
$itunes->setSubtitle($data['itunes']['subtitle']);
}
if (isset($data['itunes']['summary'])) {
$itunes->setSummary($data['itunes']['summary']);
}
if (isset($data['itunes']['block'])) {
$itunes->setBlock($data['itunes']['block']);
}
if (isset($data['itunes']['explicit'])) {
$itunes->setExplicit($data['itunes']['explicit']);
}
if (isset($data['itunes']['keywords'])) {
$itunes->setKeywords($data['itunes']['keywords']);
}
if (isset($data['itunes']['new-feed-url'])) {
$itunes->setNewFeedUrl($data['itunes']['new-feed-url']);
}
$this->_header->setITunes($itunes);
}
} | [
"private",
"function",
"_createHeader",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"mandatories",
"=",
"array",
"(",
"'title'",
",",
"'link'",
",",
"'charset'",
")",
";",
"foreach",
"(",
"$",
"mandatories",
"as",
"$",
"mandatory",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"mandatory",
"]",
")",
")",
"{",
"/**\n * @see Zend_Feed_Builder_Exception\n */",
"require_once",
"'Zend/Feed/Builder/Exception.php'",
";",
"throw",
"new",
"Zend_Feed_Builder_Exception",
"(",
"\"$mandatory key is missing\"",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_header",
"=",
"new",
"Zend_Feed_Builder_Header",
"(",
"$",
"data",
"[",
"'title'",
"]",
",",
"$",
"data",
"[",
"'link'",
"]",
",",
"$",
"data",
"[",
"'charset'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'lastUpdate'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setLastUpdate",
"(",
"$",
"data",
"[",
"'lastUpdate'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'published'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setPublishedDate",
"(",
"$",
"data",
"[",
"'published'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'description'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setDescription",
"(",
"$",
"data",
"[",
"'description'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'author'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setAuthor",
"(",
"$",
"data",
"[",
"'author'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'email'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setEmail",
"(",
"$",
"data",
"[",
"'email'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'webmaster'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setWebmaster",
"(",
"$",
"data",
"[",
"'webmaster'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'copyright'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setCopyright",
"(",
"$",
"data",
"[",
"'copyright'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'image'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setImage",
"(",
"$",
"data",
"[",
"'image'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'generator'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setGenerator",
"(",
"$",
"data",
"[",
"'generator'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'language'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setLanguage",
"(",
"$",
"data",
"[",
"'language'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'ttl'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setTtl",
"(",
"$",
"data",
"[",
"'ttl'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'rating'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setRating",
"(",
"$",
"data",
"[",
"'rating'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'cloud'",
"]",
")",
")",
"{",
"$",
"mandatories",
"=",
"array",
"(",
"'domain'",
",",
"'path'",
",",
"'registerProcedure'",
",",
"'protocol'",
")",
";",
"foreach",
"(",
"$",
"mandatories",
"as",
"$",
"mandatory",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'cloud'",
"]",
"[",
"$",
"mandatory",
"]",
")",
")",
"{",
"/**\n * @see Zend_Feed_Builder_Exception\n */",
"require_once",
"'Zend/Feed/Builder/Exception.php'",
";",
"throw",
"new",
"Zend_Feed_Builder_Exception",
"(",
"\"you have to define $mandatory property of your cloud\"",
")",
";",
"}",
"}",
"$",
"uri_str",
"=",
"'http://'",
".",
"$",
"data",
"[",
"'cloud'",
"]",
"[",
"'domain'",
"]",
".",
"$",
"data",
"[",
"'cloud'",
"]",
"[",
"'path'",
"]",
";",
"$",
"this",
"->",
"_header",
"->",
"setCloud",
"(",
"$",
"uri_str",
",",
"$",
"data",
"[",
"'cloud'",
"]",
"[",
"'registerProcedure'",
"]",
",",
"$",
"data",
"[",
"'cloud'",
"]",
"[",
"'protocol'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'textInput'",
"]",
")",
")",
"{",
"$",
"mandatories",
"=",
"array",
"(",
"'title'",
",",
"'description'",
",",
"'name'",
",",
"'link'",
")",
";",
"foreach",
"(",
"$",
"mandatories",
"as",
"$",
"mandatory",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'textInput'",
"]",
"[",
"$",
"mandatory",
"]",
")",
")",
"{",
"/**\n * @see Zend_Feed_Builder_Exception\n */",
"require_once",
"'Zend/Feed/Builder/Exception.php'",
";",
"throw",
"new",
"Zend_Feed_Builder_Exception",
"(",
"\"you have to define $mandatory property of your textInput\"",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_header",
"->",
"setTextInput",
"(",
"$",
"data",
"[",
"'textInput'",
"]",
"[",
"'title'",
"]",
",",
"$",
"data",
"[",
"'textInput'",
"]",
"[",
"'description'",
"]",
",",
"$",
"data",
"[",
"'textInput'",
"]",
"[",
"'name'",
"]",
",",
"$",
"data",
"[",
"'textInput'",
"]",
"[",
"'link'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'skipHours'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setSkipHours",
"(",
"$",
"data",
"[",
"'skipHours'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'skipDays'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_header",
"->",
"setSkipDays",
"(",
"$",
"data",
"[",
"'skipDays'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
")",
")",
"{",
"$",
"itunes",
"=",
"new",
"Zend_Feed_Builder_Header_Itunes",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'category'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'author'",
"]",
")",
")",
"{",
"$",
"itunes",
"->",
"setAuthor",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'author'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'owner'",
"]",
")",
")",
"{",
"$",
"name",
"=",
"isset",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'owner'",
"]",
"[",
"'name'",
"]",
")",
"?",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'owner'",
"]",
"[",
"'name'",
"]",
":",
"''",
";",
"$",
"email",
"=",
"isset",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'owner'",
"]",
"[",
"'email'",
"]",
")",
"?",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'owner'",
"]",
"[",
"'email'",
"]",
":",
"''",
";",
"$",
"itunes",
"->",
"setOwner",
"(",
"$",
"name",
",",
"$",
"email",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'image'",
"]",
")",
")",
"{",
"$",
"itunes",
"->",
"setImage",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'image'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'subtitle'",
"]",
")",
")",
"{",
"$",
"itunes",
"->",
"setSubtitle",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'subtitle'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'summary'",
"]",
")",
")",
"{",
"$",
"itunes",
"->",
"setSummary",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'summary'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'block'",
"]",
")",
")",
"{",
"$",
"itunes",
"->",
"setBlock",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'block'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'explicit'",
"]",
")",
")",
"{",
"$",
"itunes",
"->",
"setExplicit",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'explicit'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'keywords'",
"]",
")",
")",
"{",
"$",
"itunes",
"->",
"setKeywords",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'keywords'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'new-feed-url'",
"]",
")",
")",
"{",
"$",
"itunes",
"->",
"setNewFeedUrl",
"(",
"$",
"data",
"[",
"'itunes'",
"]",
"[",
"'new-feed-url'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"_header",
"->",
"setITunes",
"(",
"$",
"itunes",
")",
";",
"}",
"}"
]
| Create the Zend_Feed_Builder_Header instance
@param array $data
@throws Zend_Feed_Builder_Exception
@return void | [
"Create",
"the",
"Zend_Feed_Builder_Header",
"instance"
]
| train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed/Builder.php#L215-L334 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Feed/Builder.php | Zend_Feed_Builder._createEntries | private function _createEntries(array $data)
{
foreach ($data as $row) {
$mandatories = array('title', 'link', 'description');
foreach ($mandatories as $mandatory) {
if (!isset($row[$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key is missing");
}
}
$entry = new Zend_Feed_Builder_Entry($row['title'], $row['link'], $row['description']);
if (isset($row['author'])) {
$entry->setAuthor($row['author']);
}
if (isset($row['guid'])) {
$entry->setId($row['guid']);
}
if (isset($row['content'])) {
$entry->setContent($row['content']);
}
if (isset($row['lastUpdate'])) {
$entry->setLastUpdate($row['lastUpdate']);
}
if (isset($row['comments'])) {
$entry->setCommentsUrl($row['comments']);
}
if (isset($row['commentRss'])) {
$entry->setCommentsRssUrl($row['commentRss']);
}
if (isset($row['source'])) {
$mandatories = array('title', 'url');
foreach ($mandatories as $mandatory) {
if (!isset($row['source'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key of source property is missing");
}
}
$entry->setSource($row['source']['title'], $row['source']['url']);
}
if (isset($row['category'])) {
$entry->setCategories($row['category']);
}
if (isset($row['enclosure'])) {
$entry->setEnclosures($row['enclosure']);
}
$this->_entries[] = $entry;
}
} | php | private function _createEntries(array $data)
{
foreach ($data as $row) {
$mandatories = array('title', 'link', 'description');
foreach ($mandatories as $mandatory) {
if (!isset($row[$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key is missing");
}
}
$entry = new Zend_Feed_Builder_Entry($row['title'], $row['link'], $row['description']);
if (isset($row['author'])) {
$entry->setAuthor($row['author']);
}
if (isset($row['guid'])) {
$entry->setId($row['guid']);
}
if (isset($row['content'])) {
$entry->setContent($row['content']);
}
if (isset($row['lastUpdate'])) {
$entry->setLastUpdate($row['lastUpdate']);
}
if (isset($row['comments'])) {
$entry->setCommentsUrl($row['comments']);
}
if (isset($row['commentRss'])) {
$entry->setCommentsRssUrl($row['commentRss']);
}
if (isset($row['source'])) {
$mandatories = array('title', 'url');
foreach ($mandatories as $mandatory) {
if (!isset($row['source'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key of source property is missing");
}
}
$entry->setSource($row['source']['title'], $row['source']['url']);
}
if (isset($row['category'])) {
$entry->setCategories($row['category']);
}
if (isset($row['enclosure'])) {
$entry->setEnclosures($row['enclosure']);
}
$this->_entries[] = $entry;
}
} | [
"private",
"function",
"_createEntries",
"(",
"array",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"row",
")",
"{",
"$",
"mandatories",
"=",
"array",
"(",
"'title'",
",",
"'link'",
",",
"'description'",
")",
";",
"foreach",
"(",
"$",
"mandatories",
"as",
"$",
"mandatory",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"$",
"mandatory",
"]",
")",
")",
"{",
"/**\n * @see Zend_Feed_Builder_Exception\n */",
"require_once",
"'Zend/Feed/Builder/Exception.php'",
";",
"throw",
"new",
"Zend_Feed_Builder_Exception",
"(",
"\"$mandatory key is missing\"",
")",
";",
"}",
"}",
"$",
"entry",
"=",
"new",
"Zend_Feed_Builder_Entry",
"(",
"$",
"row",
"[",
"'title'",
"]",
",",
"$",
"row",
"[",
"'link'",
"]",
",",
"$",
"row",
"[",
"'description'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'author'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setAuthor",
"(",
"$",
"row",
"[",
"'author'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'guid'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setId",
"(",
"$",
"row",
"[",
"'guid'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'content'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setContent",
"(",
"$",
"row",
"[",
"'content'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'lastUpdate'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setLastUpdate",
"(",
"$",
"row",
"[",
"'lastUpdate'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'comments'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setCommentsUrl",
"(",
"$",
"row",
"[",
"'comments'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'commentRss'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setCommentsRssUrl",
"(",
"$",
"row",
"[",
"'commentRss'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'source'",
"]",
")",
")",
"{",
"$",
"mandatories",
"=",
"array",
"(",
"'title'",
",",
"'url'",
")",
";",
"foreach",
"(",
"$",
"mandatories",
"as",
"$",
"mandatory",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"'source'",
"]",
"[",
"$",
"mandatory",
"]",
")",
")",
"{",
"/**\n * @see Zend_Feed_Builder_Exception\n */",
"require_once",
"'Zend/Feed/Builder/Exception.php'",
";",
"throw",
"new",
"Zend_Feed_Builder_Exception",
"(",
"\"$mandatory key of source property is missing\"",
")",
";",
"}",
"}",
"$",
"entry",
"->",
"setSource",
"(",
"$",
"row",
"[",
"'source'",
"]",
"[",
"'title'",
"]",
",",
"$",
"row",
"[",
"'source'",
"]",
"[",
"'url'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'category'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setCategories",
"(",
"$",
"row",
"[",
"'category'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'enclosure'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setEnclosures",
"(",
"$",
"row",
"[",
"'enclosure'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"_entries",
"[",
"]",
"=",
"$",
"entry",
";",
"}",
"}"
]
| Create the array of article entries
@param array $data
@throws Zend_Feed_Builder_Exception
@return void | [
"Create",
"the",
"array",
"of",
"article",
"entries"
]
| train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed/Builder.php#L343-L397 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.fill | public function fill(array $data)
{
if (empty($data['url']) || !is_string($data['url']) || strpos($data['url'], $this->browser->getHost()) !== 0) {
return;
}
$dom = $this->browser->getDom(substr($data['url'], strlen($this->browser->getHost())));
if (!($dom instanceof \DOMDocument)) {
return;
}
$xpath = new \DOMXPath($dom);
$nodes = $xpath->query(self::XPATH_FOR_FILL);
// get item type
if (!($type = $this->getItemType($data['url']))) {
return;
}
/* @var $body \DOMElement */
if (!($body = $nodes->item(5))) {
throw new \LogicException('Incorrect data structure at source');
}
// item id from source
$id = 0;
if (preg_match('/id=(?<id>\d+)/', $data['url'], $mat)) {
$id = (int) $mat['id'];
}
$item = new Item();
// add source link on world-art
$item->addSource((new Source())->setUrl($data['url']));
// add other source links
/* @var $links \DOMNodeList */
$links = $xpath->query('a', $nodes->item(1));
for ($i = 0; $i < $links->length; ++$i) {
$link = $this->getAttrAsArray($links->item($i));
if (strpos($link['href'], 'http://') !== false &&
strpos($link['href'], $this->browser->getHost()) === false
) {
$item->addSource((new Source())->setUrl($link['href']));
}
}
// add cover
$this->setCover($item, $id, $type);
// fill item studio
if ($studio = $this->getStudio($xpath, $body)) {
$item->setStudio($studio);
}
// fill main data
if ($type == self::ITEM_TYPE_ANIMATION) {
$head = $xpath->query('table[3]/tr[2]/td[3]', $body);
if (!$head->length) {
$head = $xpath->query('table[2]/tr[1]/td[3]', $body);
}
} else {
$head = $xpath->query('table[3]/tr[1]/td[3]', $body);
}
if ($head->length) {
switch ($type) {
case self::ITEM_TYPE_ANIMATION:
$this->fillAnimationNames($item, $xpath, $head->item(0));
break;
default:
$this->fillCinemaNames($item, $xpath, $head->item(0));
}
}
$this->fillHeadData($item, $xpath, $head->item(0));
// fill body data
$this->fillBodyData($item, $xpath, $body, $id, !empty($data['frames']), $type);
return $item;
} | php | public function fill(array $data)
{
if (empty($data['url']) || !is_string($data['url']) || strpos($data['url'], $this->browser->getHost()) !== 0) {
return;
}
$dom = $this->browser->getDom(substr($data['url'], strlen($this->browser->getHost())));
if (!($dom instanceof \DOMDocument)) {
return;
}
$xpath = new \DOMXPath($dom);
$nodes = $xpath->query(self::XPATH_FOR_FILL);
// get item type
if (!($type = $this->getItemType($data['url']))) {
return;
}
/* @var $body \DOMElement */
if (!($body = $nodes->item(5))) {
throw new \LogicException('Incorrect data structure at source');
}
// item id from source
$id = 0;
if (preg_match('/id=(?<id>\d+)/', $data['url'], $mat)) {
$id = (int) $mat['id'];
}
$item = new Item();
// add source link on world-art
$item->addSource((new Source())->setUrl($data['url']));
// add other source links
/* @var $links \DOMNodeList */
$links = $xpath->query('a', $nodes->item(1));
for ($i = 0; $i < $links->length; ++$i) {
$link = $this->getAttrAsArray($links->item($i));
if (strpos($link['href'], 'http://') !== false &&
strpos($link['href'], $this->browser->getHost()) === false
) {
$item->addSource((new Source())->setUrl($link['href']));
}
}
// add cover
$this->setCover($item, $id, $type);
// fill item studio
if ($studio = $this->getStudio($xpath, $body)) {
$item->setStudio($studio);
}
// fill main data
if ($type == self::ITEM_TYPE_ANIMATION) {
$head = $xpath->query('table[3]/tr[2]/td[3]', $body);
if (!$head->length) {
$head = $xpath->query('table[2]/tr[1]/td[3]', $body);
}
} else {
$head = $xpath->query('table[3]/tr[1]/td[3]', $body);
}
if ($head->length) {
switch ($type) {
case self::ITEM_TYPE_ANIMATION:
$this->fillAnimationNames($item, $xpath, $head->item(0));
break;
default:
$this->fillCinemaNames($item, $xpath, $head->item(0));
}
}
$this->fillHeadData($item, $xpath, $head->item(0));
// fill body data
$this->fillBodyData($item, $xpath, $body, $id, !empty($data['frames']), $type);
return $item;
} | [
"public",
"function",
"fill",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'url'",
"]",
")",
"||",
"!",
"is_string",
"(",
"$",
"data",
"[",
"'url'",
"]",
")",
"||",
"strpos",
"(",
"$",
"data",
"[",
"'url'",
"]",
",",
"$",
"this",
"->",
"browser",
"->",
"getHost",
"(",
")",
")",
"!==",
"0",
")",
"{",
"return",
";",
"}",
"$",
"dom",
"=",
"$",
"this",
"->",
"browser",
"->",
"getDom",
"(",
"substr",
"(",
"$",
"data",
"[",
"'url'",
"]",
",",
"strlen",
"(",
"$",
"this",
"->",
"browser",
"->",
"getHost",
"(",
")",
")",
")",
")",
";",
"if",
"(",
"!",
"(",
"$",
"dom",
"instanceof",
"\\",
"DOMDocument",
")",
")",
"{",
"return",
";",
"}",
"$",
"xpath",
"=",
"new",
"\\",
"DOMXPath",
"(",
"$",
"dom",
")",
";",
"$",
"nodes",
"=",
"$",
"xpath",
"->",
"query",
"(",
"self",
"::",
"XPATH_FOR_FILL",
")",
";",
"// get item type",
"if",
"(",
"!",
"(",
"$",
"type",
"=",
"$",
"this",
"->",
"getItemType",
"(",
"$",
"data",
"[",
"'url'",
"]",
")",
")",
")",
"{",
"return",
";",
"}",
"/* @var $body \\DOMElement */",
"if",
"(",
"!",
"(",
"$",
"body",
"=",
"$",
"nodes",
"->",
"item",
"(",
"5",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Incorrect data structure at source'",
")",
";",
"}",
"// item id from source",
"$",
"id",
"=",
"0",
";",
"if",
"(",
"preg_match",
"(",
"'/id=(?<id>\\d+)/'",
",",
"$",
"data",
"[",
"'url'",
"]",
",",
"$",
"mat",
")",
")",
"{",
"$",
"id",
"=",
"(",
"int",
")",
"$",
"mat",
"[",
"'id'",
"]",
";",
"}",
"$",
"item",
"=",
"new",
"Item",
"(",
")",
";",
"// add source link on world-art",
"$",
"item",
"->",
"addSource",
"(",
"(",
"new",
"Source",
"(",
")",
")",
"->",
"setUrl",
"(",
"$",
"data",
"[",
"'url'",
"]",
")",
")",
";",
"// add other source links",
"/* @var $links \\DOMNodeList */",
"$",
"links",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'a'",
",",
"$",
"nodes",
"->",
"item",
"(",
"1",
")",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"links",
"->",
"length",
";",
"++",
"$",
"i",
")",
"{",
"$",
"link",
"=",
"$",
"this",
"->",
"getAttrAsArray",
"(",
"$",
"links",
"->",
"item",
"(",
"$",
"i",
")",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"link",
"[",
"'href'",
"]",
",",
"'http://'",
")",
"!==",
"false",
"&&",
"strpos",
"(",
"$",
"link",
"[",
"'href'",
"]",
",",
"$",
"this",
"->",
"browser",
"->",
"getHost",
"(",
")",
")",
"===",
"false",
")",
"{",
"$",
"item",
"->",
"addSource",
"(",
"(",
"new",
"Source",
"(",
")",
")",
"->",
"setUrl",
"(",
"$",
"link",
"[",
"'href'",
"]",
")",
")",
";",
"}",
"}",
"// add cover",
"$",
"this",
"->",
"setCover",
"(",
"$",
"item",
",",
"$",
"id",
",",
"$",
"type",
")",
";",
"// fill item studio",
"if",
"(",
"$",
"studio",
"=",
"$",
"this",
"->",
"getStudio",
"(",
"$",
"xpath",
",",
"$",
"body",
")",
")",
"{",
"$",
"item",
"->",
"setStudio",
"(",
"$",
"studio",
")",
";",
"}",
"// fill main data",
"if",
"(",
"$",
"type",
"==",
"self",
"::",
"ITEM_TYPE_ANIMATION",
")",
"{",
"$",
"head",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'table[3]/tr[2]/td[3]'",
",",
"$",
"body",
")",
";",
"if",
"(",
"!",
"$",
"head",
"->",
"length",
")",
"{",
"$",
"head",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'table[2]/tr[1]/td[3]'",
",",
"$",
"body",
")",
";",
"}",
"}",
"else",
"{",
"$",
"head",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'table[3]/tr[1]/td[3]'",
",",
"$",
"body",
")",
";",
"}",
"if",
"(",
"$",
"head",
"->",
"length",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"self",
"::",
"ITEM_TYPE_ANIMATION",
":",
"$",
"this",
"->",
"fillAnimationNames",
"(",
"$",
"item",
",",
"$",
"xpath",
",",
"$",
"head",
"->",
"item",
"(",
"0",
")",
")",
";",
"break",
";",
"default",
":",
"$",
"this",
"->",
"fillCinemaNames",
"(",
"$",
"item",
",",
"$",
"xpath",
",",
"$",
"head",
"->",
"item",
"(",
"0",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"fillHeadData",
"(",
"$",
"item",
",",
"$",
"xpath",
",",
"$",
"head",
"->",
"item",
"(",
"0",
")",
")",
";",
"// fill body data",
"$",
"this",
"->",
"fillBodyData",
"(",
"$",
"item",
",",
"$",
"xpath",
",",
"$",
"body",
",",
"$",
"id",
",",
"!",
"empty",
"(",
"$",
"data",
"[",
"'frames'",
"]",
")",
",",
"$",
"type",
")",
";",
"return",
"$",
"item",
";",
"}"
]
| Fill item from source.
@param array $data
@return \AnimeDb\Bundle\CatalogBundle\Entity\Item|null | [
"Fill",
"item",
"from",
"source",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L359-L438 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getAttrAsArray | private function getAttrAsArray(\DOMElement $element)
{
$return = [];
for ($i = 0; $i < $element->attributes->length; ++$i) {
$return[$element->attributes->item($i)->nodeName] = $element->attributes->item($i)->nodeValue;
}
return $return;
} | php | private function getAttrAsArray(\DOMElement $element)
{
$return = [];
for ($i = 0; $i < $element->attributes->length; ++$i) {
$return[$element->attributes->item($i)->nodeName] = $element->attributes->item($i)->nodeValue;
}
return $return;
} | [
"private",
"function",
"getAttrAsArray",
"(",
"\\",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"element",
"->",
"attributes",
"->",
"length",
";",
"++",
"$",
"i",
")",
"{",
"$",
"return",
"[",
"$",
"element",
"->",
"attributes",
"->",
"item",
"(",
"$",
"i",
")",
"->",
"nodeName",
"]",
"=",
"$",
"element",
"->",
"attributes",
"->",
"item",
"(",
"$",
"i",
")",
"->",
"nodeValue",
";",
"}",
"return",
"$",
"return",
";",
"}"
]
| Get element attributes as array.
@param \DOMElement $element
@return array | [
"Get",
"element",
"attributes",
"as",
"array",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L447-L455 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.setCover | private function setCover(Item $item, $id, $type)
{
$item->setCover(self::NAME.'/'.$id.'/1.jpg');
return $this->uploadImage($this->getCoverUrl($id, $type), $item);
} | php | private function setCover(Item $item, $id, $type)
{
$item->setCover(self::NAME.'/'.$id.'/1.jpg');
return $this->uploadImage($this->getCoverUrl($id, $type), $item);
} | [
"private",
"function",
"setCover",
"(",
"Item",
"$",
"item",
",",
"$",
"id",
",",
"$",
"type",
")",
"{",
"$",
"item",
"->",
"setCover",
"(",
"self",
"::",
"NAME",
".",
"'/'",
".",
"$",
"id",
".",
"'/1.jpg'",
")",
";",
"return",
"$",
"this",
"->",
"uploadImage",
"(",
"$",
"this",
"->",
"getCoverUrl",
"(",
"$",
"id",
",",
"$",
"type",
")",
",",
"$",
"item",
")",
";",
"}"
]
| Get cover from source id.
@param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
@param string $id
@param string $type
@return bool | [
"Get",
"cover",
"from",
"source",
"id",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L466-L471 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.fillHeadData | private function fillHeadData(Item $item, \DOMXPath $xpath, \DOMElement $head)
{
/* @var $data \DOMElement */
$data = $xpath->query('font', $head)->item(0);
$length = $data->childNodes->length;
for ($i = 0; $i < $length; ++$i) {
if ($data->childNodes->item($i)->nodeName == 'b') {
switch ($data->childNodes->item($i)->nodeValue) {
// set country
case 'Производство':
$j = 1;
do {
if ($data->childNodes->item($i + $j)->nodeName == 'a') {
$country_name = trim($data->childNodes->item($i + $j)->nodeValue);
if ($country_name && $country = $this->getCountryByName($country_name)) {
$item->setCountry($country);
}
break;
}
++$j;
} while ($data->childNodes->item($i + $j)->nodeName != 'br');
$i += $j;
break;
// add genre
case 'Жанр':
$j = 2;
do {
if ($data->childNodes->item($i + $j)->nodeName == 'a' &&
($genre = $this->getGenreByName($data->childNodes->item($i + $j)->nodeValue))
) {
$item->addGenre($genre);
}
++$j;
} while ($data->childNodes->item($i + $j)->nodeName != 'br');
$i += $j;
break;
// set type and add file info
case 'Тип':
$type = $data->childNodes->item($i + 1)->nodeValue;
if (preg_match('/(?<type>[\w\s]+)(?: \((?:(?<episodes_number>>?\d+) эп.)?(?<file_info>.*)\))?(, (?<duration>\d{1,3}) мин\.)?$/u', $type, $match)) {
// add type
if ($type = $this->getTypeByName(trim($match['type']))) {
$item->setType($type);
}
// add duration
if (!empty($match['duration'])) {
$item->setDuration((int) $match['duration']);
}
// add number of episodes
if (!empty($match['episodes_number'])) {
if ($match['episodes_number'][0] == '>') {
$item->setEpisodesNumber(substr($match['episodes_number'], 1).'+');
} else {
$item->setEpisodesNumber((int) $match['episodes_number']);
}
} elseif ($item->getType()->getId() != 'tv') {
// everything except the TV series consist of a single episode
$item->setEpisodesNumber(1);
}
// add file info
if (!empty($match['file_info'])) {
$file_info = $item->getFileInfo();
$item->setFileInfo(($file_info ? $file_info."\n" : '').trim($match['file_info']));
}
}
++$i;
break;
// set date premiere and date end if exists
case 'Премьера':
case 'Выпуск':
$j = 1;
$date = '';
do {
$date .= $data->childNodes->item($i + $j)->nodeValue;
++$j;
} while ($length > $i + $j && $data->childNodes->item($i + $j)->nodeName != 'br');
$i += $j;
$reg = '/(?<start>(?:(?:\d{2})|(?:\?\?)).\d{2}.\d{4})'.
'(?:.*(?<end>(?:(?:\d{2})|(?:\?\?)).\d{2}.\d{4}))?/';
if (preg_match($reg, $date, $match)) {
$item->setDatePremiere(new \DateTime(str_replace('??', '01', $match['start'])));
if (isset($match['end'])) {
$item->setDateEnd(new \DateTime($match['end']));
}
}
break;
case 'Хронометраж':
if (preg_match('/(?<duration>\d+)/', $data->childNodes->item($i + 1)->nodeValue, $match)) {
$item->setDuration((int) $match['duration']);
}
break;
case 'Кол-во серий':
$number = trim($data->childNodes->item($i + 1)->nodeValue, ' :');
if (strpos($number, '>') !== false) {
$number = str_replace('>', '', $number).'+';
}
$item->setEpisodesNumber($number);
break;
}
}
}
} | php | private function fillHeadData(Item $item, \DOMXPath $xpath, \DOMElement $head)
{
/* @var $data \DOMElement */
$data = $xpath->query('font', $head)->item(0);
$length = $data->childNodes->length;
for ($i = 0; $i < $length; ++$i) {
if ($data->childNodes->item($i)->nodeName == 'b') {
switch ($data->childNodes->item($i)->nodeValue) {
// set country
case 'Производство':
$j = 1;
do {
if ($data->childNodes->item($i + $j)->nodeName == 'a') {
$country_name = trim($data->childNodes->item($i + $j)->nodeValue);
if ($country_name && $country = $this->getCountryByName($country_name)) {
$item->setCountry($country);
}
break;
}
++$j;
} while ($data->childNodes->item($i + $j)->nodeName != 'br');
$i += $j;
break;
// add genre
case 'Жанр':
$j = 2;
do {
if ($data->childNodes->item($i + $j)->nodeName == 'a' &&
($genre = $this->getGenreByName($data->childNodes->item($i + $j)->nodeValue))
) {
$item->addGenre($genre);
}
++$j;
} while ($data->childNodes->item($i + $j)->nodeName != 'br');
$i += $j;
break;
// set type and add file info
case 'Тип':
$type = $data->childNodes->item($i + 1)->nodeValue;
if (preg_match('/(?<type>[\w\s]+)(?: \((?:(?<episodes_number>>?\d+) эп.)?(?<file_info>.*)\))?(, (?<duration>\d{1,3}) мин\.)?$/u', $type, $match)) {
// add type
if ($type = $this->getTypeByName(trim($match['type']))) {
$item->setType($type);
}
// add duration
if (!empty($match['duration'])) {
$item->setDuration((int) $match['duration']);
}
// add number of episodes
if (!empty($match['episodes_number'])) {
if ($match['episodes_number'][0] == '>') {
$item->setEpisodesNumber(substr($match['episodes_number'], 1).'+');
} else {
$item->setEpisodesNumber((int) $match['episodes_number']);
}
} elseif ($item->getType()->getId() != 'tv') {
// everything except the TV series consist of a single episode
$item->setEpisodesNumber(1);
}
// add file info
if (!empty($match['file_info'])) {
$file_info = $item->getFileInfo();
$item->setFileInfo(($file_info ? $file_info."\n" : '').trim($match['file_info']));
}
}
++$i;
break;
// set date premiere and date end if exists
case 'Премьера':
case 'Выпуск':
$j = 1;
$date = '';
do {
$date .= $data->childNodes->item($i + $j)->nodeValue;
++$j;
} while ($length > $i + $j && $data->childNodes->item($i + $j)->nodeName != 'br');
$i += $j;
$reg = '/(?<start>(?:(?:\d{2})|(?:\?\?)).\d{2}.\d{4})'.
'(?:.*(?<end>(?:(?:\d{2})|(?:\?\?)).\d{2}.\d{4}))?/';
if (preg_match($reg, $date, $match)) {
$item->setDatePremiere(new \DateTime(str_replace('??', '01', $match['start'])));
if (isset($match['end'])) {
$item->setDateEnd(new \DateTime($match['end']));
}
}
break;
case 'Хронометраж':
if (preg_match('/(?<duration>\d+)/', $data->childNodes->item($i + 1)->nodeValue, $match)) {
$item->setDuration((int) $match['duration']);
}
break;
case 'Кол-во серий':
$number = trim($data->childNodes->item($i + 1)->nodeValue, ' :');
if (strpos($number, '>') !== false) {
$number = str_replace('>', '', $number).'+';
}
$item->setEpisodesNumber($number);
break;
}
}
}
} | [
"private",
"function",
"fillHeadData",
"(",
"Item",
"$",
"item",
",",
"\\",
"DOMXPath",
"$",
"xpath",
",",
"\\",
"DOMElement",
"$",
"head",
")",
"{",
"/* @var $data \\DOMElement */",
"$",
"data",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'font'",
",",
"$",
"head",
")",
"->",
"item",
"(",
"0",
")",
";",
"$",
"length",
"=",
"$",
"data",
"->",
"childNodes",
"->",
"length",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"++",
"$",
"i",
")",
"{",
"if",
"(",
"$",
"data",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
")",
"->",
"nodeName",
"==",
"'b'",
")",
"{",
"switch",
"(",
"$",
"data",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
")",
"->",
"nodeValue",
")",
"{",
"// set country",
"case",
"'Производство':",
"",
"$",
"j",
"=",
"1",
";",
"do",
"{",
"if",
"(",
"$",
"data",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"$",
"j",
")",
"->",
"nodeName",
"==",
"'a'",
")",
"{",
"$",
"country_name",
"=",
"trim",
"(",
"$",
"data",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"$",
"j",
")",
"->",
"nodeValue",
")",
";",
"if",
"(",
"$",
"country_name",
"&&",
"$",
"country",
"=",
"$",
"this",
"->",
"getCountryByName",
"(",
"$",
"country_name",
")",
")",
"{",
"$",
"item",
"->",
"setCountry",
"(",
"$",
"country",
")",
";",
"}",
"break",
";",
"}",
"++",
"$",
"j",
";",
"}",
"while",
"(",
"$",
"data",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"$",
"j",
")",
"->",
"nodeName",
"!=",
"'br'",
")",
";",
"$",
"i",
"+=",
"$",
"j",
";",
"break",
";",
"// add genre",
"case",
"'Жанр':",
"",
"$",
"j",
"=",
"2",
";",
"do",
"{",
"if",
"(",
"$",
"data",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"$",
"j",
")",
"->",
"nodeName",
"==",
"'a'",
"&&",
"(",
"$",
"genre",
"=",
"$",
"this",
"->",
"getGenreByName",
"(",
"$",
"data",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"$",
"j",
")",
"->",
"nodeValue",
")",
")",
")",
"{",
"$",
"item",
"->",
"addGenre",
"(",
"$",
"genre",
")",
";",
"}",
"++",
"$",
"j",
";",
"}",
"while",
"(",
"$",
"data",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"$",
"j",
")",
"->",
"nodeName",
"!=",
"'br'",
")",
";",
"$",
"i",
"+=",
"$",
"j",
";",
"break",
";",
"// set type and add file info",
"case",
"'Тип':",
"",
"$",
"type",
"=",
"$",
"data",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"1",
")",
"->",
"nodeValue",
";",
"if",
"(",
"preg_match",
"(",
"'/(?<type>[\\w\\s]+)(?: \\((?:(?<episodes_number>>?\\d+) эп.)?(?<file_info>.*)\\))?(, (?<duration>\\d{1,3}) мин\\.)?$/u', $ty",
"p",
",",
" $ma",
"t",
"h",
")) {",
"",
"",
"",
"// add type",
"if",
"(",
"$",
"type",
"=",
"$",
"this",
"->",
"getTypeByName",
"(",
"trim",
"(",
"$",
"match",
"[",
"'type'",
"]",
")",
")",
")",
"{",
"$",
"item",
"->",
"setType",
"(",
"$",
"type",
")",
";",
"}",
"// add duration",
"if",
"(",
"!",
"empty",
"(",
"$",
"match",
"[",
"'duration'",
"]",
")",
")",
"{",
"$",
"item",
"->",
"setDuration",
"(",
"(",
"int",
")",
"$",
"match",
"[",
"'duration'",
"]",
")",
";",
"}",
"// add number of episodes",
"if",
"(",
"!",
"empty",
"(",
"$",
"match",
"[",
"'episodes_number'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"match",
"[",
"'episodes_number'",
"]",
"[",
"0",
"]",
"==",
"'>'",
")",
"{",
"$",
"item",
"->",
"setEpisodesNumber",
"(",
"substr",
"(",
"$",
"match",
"[",
"'episodes_number'",
"]",
",",
"1",
")",
".",
"'+'",
")",
";",
"}",
"else",
"{",
"$",
"item",
"->",
"setEpisodesNumber",
"(",
"(",
"int",
")",
"$",
"match",
"[",
"'episodes_number'",
"]",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"item",
"->",
"getType",
"(",
")",
"->",
"getId",
"(",
")",
"!=",
"'tv'",
")",
"{",
"// everything except the TV series consist of a single episode",
"$",
"item",
"->",
"setEpisodesNumber",
"(",
"1",
")",
";",
"}",
"// add file info",
"if",
"(",
"!",
"empty",
"(",
"$",
"match",
"[",
"'file_info'",
"]",
")",
")",
"{",
"$",
"file_info",
"=",
"$",
"item",
"->",
"getFileInfo",
"(",
")",
";",
"$",
"item",
"->",
"setFileInfo",
"(",
"(",
"$",
"file_info",
"?",
"$",
"file_info",
".",
"\"\\n\"",
":",
"''",
")",
".",
"trim",
"(",
"$",
"match",
"[",
"'file_info'",
"]",
")",
")",
";",
"}",
"}",
"++",
"$",
"i",
";",
"break",
";",
"// set date premiere and date end if exists",
"case",
"'Премьера':",
"",
"case",
"'Выпуск':",
"",
"$",
"j",
"=",
"1",
";",
"$",
"date",
"=",
"''",
";",
"do",
"{",
"$",
"date",
".=",
"$",
"data",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"$",
"j",
")",
"->",
"nodeValue",
";",
"++",
"$",
"j",
";",
"}",
"while",
"(",
"$",
"length",
">",
"$",
"i",
"+",
"$",
"j",
"&&",
"$",
"data",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"$",
"j",
")",
"->",
"nodeName",
"!=",
"'br'",
")",
";",
"$",
"i",
"+=",
"$",
"j",
";",
"$",
"reg",
"=",
"'/(?<start>(?:(?:\\d{2})|(?:\\?\\?)).\\d{2}.\\d{4})'",
".",
"'(?:.*(?<end>(?:(?:\\d{2})|(?:\\?\\?)).\\d{2}.\\d{4}))?/'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"reg",
",",
"$",
"date",
",",
"$",
"match",
")",
")",
"{",
"$",
"item",
"->",
"setDatePremiere",
"(",
"new",
"\\",
"DateTime",
"(",
"str_replace",
"(",
"'??'",
",",
"'01'",
",",
"$",
"match",
"[",
"'start'",
"]",
")",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"'end'",
"]",
")",
")",
"{",
"$",
"item",
"->",
"setDateEnd",
"(",
"new",
"\\",
"DateTime",
"(",
"$",
"match",
"[",
"'end'",
"]",
")",
")",
";",
"}",
"}",
"break",
";",
"case",
"'Хронометраж':",
"",
"if",
"(",
"preg_match",
"(",
"'/(?<duration>\\d+)/'",
",",
"$",
"data",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"1",
")",
"->",
"nodeValue",
",",
"$",
"match",
")",
")",
"{",
"$",
"item",
"->",
"setDuration",
"(",
"(",
"int",
")",
"$",
"match",
"[",
"'duration'",
"]",
")",
";",
"}",
"break",
";",
"case",
"'Кол-во серий':",
"",
"$",
"number",
"=",
"trim",
"(",
"$",
"data",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"1",
")",
"->",
"nodeValue",
",",
"' :'",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"number",
",",
"'>'",
")",
"!==",
"false",
")",
"{",
"$",
"number",
"=",
"str_replace",
"(",
"'>'",
",",
"''",
",",
"$",
"number",
")",
".",
"'+'",
";",
"}",
"$",
"item",
"->",
"setEpisodesNumber",
"(",
"$",
"number",
")",
";",
"break",
";",
"}",
"}",
"}",
"}"
]
| Fill head data.
@param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
@param \DOMXPath $xpath
@param \DOMElement $head
@return \AnimeDb\Bundle\CatalogBundle\Entity\Item | [
"Fill",
"head",
"data",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L482-L584 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.fillBodyData | private function fillBodyData(Item $item, \DOMXPath $xpath, \DOMElement $body, $id, $frames, $type)
{
for ($i = 0; $i < $body->childNodes->length; ++$i) {
if ($value = trim($body->childNodes->item($i)->nodeValue)) {
switch ($value) {
// get summary
case 'Краткое содержание:':
$summary = $xpath->query('tr/td/p[1]', $body->childNodes->item($i + 2));
if ($summary->length) {
$item->setSummary($this->getNodeValueAsText($summary->item(0)));
}
$i += 2;
break;
// get episodes
case 'Эпизоды:':
if (!trim($body->childNodes->item($i + 1)->nodeValue)) { // simple list
$item->setEpisodes($this->getNodeValueAsText($body->childNodes->item($i + 2)));
$i += 2;
} else { // episodes in table
$rows = $xpath->query('tr/td[2]', $body->childNodes->item($i + 1));
$episodes = '';
for ($j = 1; $j < $rows->length; ++$j) {
$episode = $xpath->query('font', $rows->item($j));
$episodes .= $j.'. '.$episode->item(0)->nodeValue;
if ($rows->length > 1) {
$episodes .= ' ('.$episode->item(1)->nodeValue.')';
}
$episodes .= "\n";
}
$item->setEpisodes($episodes);
++$i;
}
break;
// get date premiere
case 'Даты премьер и релизов':
$rows = $xpath->query('tr/td/table/tr/td[3]', $body->childNodes->item($i + 1));
foreach ($rows as $row) {
if (preg_match('/\d{4}\.\d{2}\.\d{2}/', $row->nodeValue, $match)) {
$date = new \DateTime(str_replace('.', '-', $match[0]));
if (!$item->getDatePremiere() || $item->getDatePremiere() > $date) {
$item->setDatePremiere($date);
}
}
}
break;
default:
// get frames
if (
(
strpos($value, 'кадры из аниме') !== false ||
strpos($value, 'Кадры из фильма') !== false
) && $id && $frames
) {
foreach ($this->getFrames($id, $type) as $frame) {
$item->addImage($frame);
}
}
}
}
}
} | php | private function fillBodyData(Item $item, \DOMXPath $xpath, \DOMElement $body, $id, $frames, $type)
{
for ($i = 0; $i < $body->childNodes->length; ++$i) {
if ($value = trim($body->childNodes->item($i)->nodeValue)) {
switch ($value) {
// get summary
case 'Краткое содержание:':
$summary = $xpath->query('tr/td/p[1]', $body->childNodes->item($i + 2));
if ($summary->length) {
$item->setSummary($this->getNodeValueAsText($summary->item(0)));
}
$i += 2;
break;
// get episodes
case 'Эпизоды:':
if (!trim($body->childNodes->item($i + 1)->nodeValue)) { // simple list
$item->setEpisodes($this->getNodeValueAsText($body->childNodes->item($i + 2)));
$i += 2;
} else { // episodes in table
$rows = $xpath->query('tr/td[2]', $body->childNodes->item($i + 1));
$episodes = '';
for ($j = 1; $j < $rows->length; ++$j) {
$episode = $xpath->query('font', $rows->item($j));
$episodes .= $j.'. '.$episode->item(0)->nodeValue;
if ($rows->length > 1) {
$episodes .= ' ('.$episode->item(1)->nodeValue.')';
}
$episodes .= "\n";
}
$item->setEpisodes($episodes);
++$i;
}
break;
// get date premiere
case 'Даты премьер и релизов':
$rows = $xpath->query('tr/td/table/tr/td[3]', $body->childNodes->item($i + 1));
foreach ($rows as $row) {
if (preg_match('/\d{4}\.\d{2}\.\d{2}/', $row->nodeValue, $match)) {
$date = new \DateTime(str_replace('.', '-', $match[0]));
if (!$item->getDatePremiere() || $item->getDatePremiere() > $date) {
$item->setDatePremiere($date);
}
}
}
break;
default:
// get frames
if (
(
strpos($value, 'кадры из аниме') !== false ||
strpos($value, 'Кадры из фильма') !== false
) && $id && $frames
) {
foreach ($this->getFrames($id, $type) as $frame) {
$item->addImage($frame);
}
}
}
}
}
} | [
"private",
"function",
"fillBodyData",
"(",
"Item",
"$",
"item",
",",
"\\",
"DOMXPath",
"$",
"xpath",
",",
"\\",
"DOMElement",
"$",
"body",
",",
"$",
"id",
",",
"$",
"frames",
",",
"$",
"type",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"body",
"->",
"childNodes",
"->",
"length",
";",
"++",
"$",
"i",
")",
"{",
"if",
"(",
"$",
"value",
"=",
"trim",
"(",
"$",
"body",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
")",
"->",
"nodeValue",
")",
")",
"{",
"switch",
"(",
"$",
"value",
")",
"{",
"// get summary",
"case",
"'Краткое содержание:':",
"",
"$",
"summary",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'tr/td/p[1]'",
",",
"$",
"body",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"2",
")",
")",
";",
"if",
"(",
"$",
"summary",
"->",
"length",
")",
"{",
"$",
"item",
"->",
"setSummary",
"(",
"$",
"this",
"->",
"getNodeValueAsText",
"(",
"$",
"summary",
"->",
"item",
"(",
"0",
")",
")",
")",
";",
"}",
"$",
"i",
"+=",
"2",
";",
"break",
";",
"// get episodes",
"case",
"'Эпизоды:':",
"",
"if",
"(",
"!",
"trim",
"(",
"$",
"body",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"1",
")",
"->",
"nodeValue",
")",
")",
"{",
"// simple list",
"$",
"item",
"->",
"setEpisodes",
"(",
"$",
"this",
"->",
"getNodeValueAsText",
"(",
"$",
"body",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"2",
")",
")",
")",
";",
"$",
"i",
"+=",
"2",
";",
"}",
"else",
"{",
"// episodes in table",
"$",
"rows",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'tr/td[2]'",
",",
"$",
"body",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"1",
")",
")",
";",
"$",
"episodes",
"=",
"''",
";",
"for",
"(",
"$",
"j",
"=",
"1",
";",
"$",
"j",
"<",
"$",
"rows",
"->",
"length",
";",
"++",
"$",
"j",
")",
"{",
"$",
"episode",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'font'",
",",
"$",
"rows",
"->",
"item",
"(",
"$",
"j",
")",
")",
";",
"$",
"episodes",
".=",
"$",
"j",
".",
"'. '",
".",
"$",
"episode",
"->",
"item",
"(",
"0",
")",
"->",
"nodeValue",
";",
"if",
"(",
"$",
"rows",
"->",
"length",
">",
"1",
")",
"{",
"$",
"episodes",
".=",
"' ('",
".",
"$",
"episode",
"->",
"item",
"(",
"1",
")",
"->",
"nodeValue",
".",
"')'",
";",
"}",
"$",
"episodes",
".=",
"\"\\n\"",
";",
"}",
"$",
"item",
"->",
"setEpisodes",
"(",
"$",
"episodes",
")",
";",
"++",
"$",
"i",
";",
"}",
"break",
";",
"// get date premiere",
"case",
"'Даты премьер и релизов':",
"",
"$",
"rows",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'tr/td/table/tr/td[3]'",
",",
"$",
"body",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
"+",
"1",
")",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/\\d{4}\\.\\d{2}\\.\\d{2}/'",
",",
"$",
"row",
"->",
"nodeValue",
",",
"$",
"match",
")",
")",
"{",
"$",
"date",
"=",
"new",
"\\",
"DateTime",
"(",
"str_replace",
"(",
"'.'",
",",
"'-'",
",",
"$",
"match",
"[",
"0",
"]",
")",
")",
";",
"if",
"(",
"!",
"$",
"item",
"->",
"getDatePremiere",
"(",
")",
"||",
"$",
"item",
"->",
"getDatePremiere",
"(",
")",
">",
"$",
"date",
")",
"{",
"$",
"item",
"->",
"setDatePremiere",
"(",
"$",
"date",
")",
";",
"}",
"}",
"}",
"break",
";",
"default",
":",
"// get frames",
"if",
"(",
"(",
"strpos",
"(",
"$",
"value",
",",
"'кадры из аниме') !== false ",
"|",
"",
"",
"",
"strpos",
"(",
"$",
"value",
",",
"'Кадры из фильма') !== false",
"",
"",
"",
")",
"&&",
"$",
"id",
"&&",
"$",
"frames",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getFrames",
"(",
"$",
"id",
",",
"$",
"type",
")",
"as",
"$",
"frame",
")",
"{",
"$",
"item",
"->",
"addImage",
"(",
"$",
"frame",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}"
]
| Fill body data.
@param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
@param \DOMXPath $xpath
@param \DOMElement $body
@param int $id
@param bool $frames
@param string $type
@return \AnimeDb\Bundle\CatalogBundle\Entity\Item | [
"Fill",
"body",
"data",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L598-L658 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getCountryByName | private function getCountryByName($name)
{
$name = str_replace('Южная Корея', 'Республика Корея', $name);
$rep = $this->doctrine->getRepository('AnimeDbCatalogBundle:CountryTranslation');
if ($country = $rep->findOneBy(['locale' => 'ru', 'content' => $name])) {
return $country->getObject();
}
} | php | private function getCountryByName($name)
{
$name = str_replace('Южная Корея', 'Республика Корея', $name);
$rep = $this->doctrine->getRepository('AnimeDbCatalogBundle:CountryTranslation');
if ($country = $rep->findOneBy(['locale' => 'ru', 'content' => $name])) {
return $country->getObject();
}
} | [
"private",
"function",
"getCountryByName",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"str_replace",
"(",
"'Южная Корея', 'Республ",
"и",
"а Корея', $name);",
"",
"",
"",
"",
"",
"$",
"rep",
"=",
"$",
"this",
"->",
"doctrine",
"->",
"getRepository",
"(",
"'AnimeDbCatalogBundle:CountryTranslation'",
")",
";",
"if",
"(",
"$",
"country",
"=",
"$",
"rep",
"->",
"findOneBy",
"(",
"[",
"'locale'",
"=>",
"'ru'",
",",
"'content'",
"=>",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"country",
"->",
"getObject",
"(",
")",
";",
"}",
"}"
]
| Get real country by name.
@param string $name
@return \AnimeDb\Bundle\CatalogBundle\Entity\Country|null | [
"Get",
"real",
"country",
"by",
"name",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L680-L687 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getGenreByName | private function getGenreByName($name)
{
if (isset($this->genres[$name])) {
return $this->doctrine
->getRepository('AnimeDbCatalogBundle:Genre')
->findOneByName($this->genres[$name]);
}
} | php | private function getGenreByName($name)
{
if (isset($this->genres[$name])) {
return $this->doctrine
->getRepository('AnimeDbCatalogBundle:Genre')
->findOneByName($this->genres[$name]);
}
} | [
"private",
"function",
"getGenreByName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"genres",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"doctrine",
"->",
"getRepository",
"(",
"'AnimeDbCatalogBundle:Genre'",
")",
"->",
"findOneByName",
"(",
"$",
"this",
"->",
"genres",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}"
]
| Get real genre by name.
@param string $name
@return \AnimeDb\Bundle\CatalogBundle\Entity\Genre|null | [
"Get",
"real",
"genre",
"by",
"name",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L696-L703 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getTypeByName | private function getTypeByName($name)
{
if (isset($this->types[$name])) {
return $this->doctrine
->getRepository('AnimeDbCatalogBundle:Type')
->find($this->types[$name]);
}
} | php | private function getTypeByName($name)
{
if (isset($this->types[$name])) {
return $this->doctrine
->getRepository('AnimeDbCatalogBundle:Type')
->find($this->types[$name]);
}
} | [
"private",
"function",
"getTypeByName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"types",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"doctrine",
"->",
"getRepository",
"(",
"'AnimeDbCatalogBundle:Type'",
")",
"->",
"find",
"(",
"$",
"this",
"->",
"types",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}"
]
| Get real type by name.
@param string $name
@return \AnimeDb\Bundle\CatalogBundle\Entity\Type|null | [
"Get",
"real",
"type",
"by",
"name",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L712-L719 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getFrames | public function getFrames($id, $type)
{
$dom = $this->browser->getDom('/'.$type.'/'.$type.'_photos.php?id='.$id);
if (!$dom) {
return [];
}
$images = (new \DOMXPath($dom))->query('//table//table//table//img');
$frames = [];
foreach ($images as $image) {
$src = $this->getAttrAsArray($image)['src'];
$entity = new Image();
if ($type == self::ITEM_TYPE_ANIMATION) {
$src = str_replace('optimize_b', 'optimize_d', $src);
if (strpos($src, 'http://') === false) {
$src = $this->browser->getHost().'/'.$type.'/'.$src;
}
if (preg_match('/\-(?<image>\d+)\-optimize_d(?<ext>\.jpe?g|png|gif)/', $src, $mat)) {
$entity->setSource(self::NAME.'/'.$id.'/'.$mat['image'].$mat['ext']);
if ($this->uploadImage($src, $entity)) {
$frames[] = $entity;
}
}
} elseif (preg_match('/_(?<round>\d+)\/.+\/(?<id>\d+)-(?<image>\d+)-.+(?<ext>\.jpe?g|png|gif)/', $src, $mat)) {
$src = $this->browser->getHost().'/'.$type.'/img/'.$mat['round'].'/'.$mat['id'].'/'.$mat['image'].$mat['ext'];
$entity->setSource(self::NAME.'/'.$id.'/'.$mat['image'].$mat['ext']);
if ($this->uploadImage($src, $entity)) {
$frames[] = $entity;
}
}
}
return $frames;
} | php | public function getFrames($id, $type)
{
$dom = $this->browser->getDom('/'.$type.'/'.$type.'_photos.php?id='.$id);
if (!$dom) {
return [];
}
$images = (new \DOMXPath($dom))->query('//table//table//table//img');
$frames = [];
foreach ($images as $image) {
$src = $this->getAttrAsArray($image)['src'];
$entity = new Image();
if ($type == self::ITEM_TYPE_ANIMATION) {
$src = str_replace('optimize_b', 'optimize_d', $src);
if (strpos($src, 'http://') === false) {
$src = $this->browser->getHost().'/'.$type.'/'.$src;
}
if (preg_match('/\-(?<image>\d+)\-optimize_d(?<ext>\.jpe?g|png|gif)/', $src, $mat)) {
$entity->setSource(self::NAME.'/'.$id.'/'.$mat['image'].$mat['ext']);
if ($this->uploadImage($src, $entity)) {
$frames[] = $entity;
}
}
} elseif (preg_match('/_(?<round>\d+)\/.+\/(?<id>\d+)-(?<image>\d+)-.+(?<ext>\.jpe?g|png|gif)/', $src, $mat)) {
$src = $this->browser->getHost().'/'.$type.'/img/'.$mat['round'].'/'.$mat['id'].'/'.$mat['image'].$mat['ext'];
$entity->setSource(self::NAME.'/'.$id.'/'.$mat['image'].$mat['ext']);
if ($this->uploadImage($src, $entity)) {
$frames[] = $entity;
}
}
}
return $frames;
} | [
"public",
"function",
"getFrames",
"(",
"$",
"id",
",",
"$",
"type",
")",
"{",
"$",
"dom",
"=",
"$",
"this",
"->",
"browser",
"->",
"getDom",
"(",
"'/'",
".",
"$",
"type",
".",
"'/'",
".",
"$",
"type",
".",
"'_photos.php?id='",
".",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"dom",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"images",
"=",
"(",
"new",
"\\",
"DOMXPath",
"(",
"$",
"dom",
")",
")",
"->",
"query",
"(",
"'//table//table//table//img'",
")",
";",
"$",
"frames",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"images",
"as",
"$",
"image",
")",
"{",
"$",
"src",
"=",
"$",
"this",
"->",
"getAttrAsArray",
"(",
"$",
"image",
")",
"[",
"'src'",
"]",
";",
"$",
"entity",
"=",
"new",
"Image",
"(",
")",
";",
"if",
"(",
"$",
"type",
"==",
"self",
"::",
"ITEM_TYPE_ANIMATION",
")",
"{",
"$",
"src",
"=",
"str_replace",
"(",
"'optimize_b'",
",",
"'optimize_d'",
",",
"$",
"src",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"src",
",",
"'http://'",
")",
"===",
"false",
")",
"{",
"$",
"src",
"=",
"$",
"this",
"->",
"browser",
"->",
"getHost",
"(",
")",
".",
"'/'",
".",
"$",
"type",
".",
"'/'",
".",
"$",
"src",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/\\-(?<image>\\d+)\\-optimize_d(?<ext>\\.jpe?g|png|gif)/'",
",",
"$",
"src",
",",
"$",
"mat",
")",
")",
"{",
"$",
"entity",
"->",
"setSource",
"(",
"self",
"::",
"NAME",
".",
"'/'",
".",
"$",
"id",
".",
"'/'",
".",
"$",
"mat",
"[",
"'image'",
"]",
".",
"$",
"mat",
"[",
"'ext'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"uploadImage",
"(",
"$",
"src",
",",
"$",
"entity",
")",
")",
"{",
"$",
"frames",
"[",
"]",
"=",
"$",
"entity",
";",
"}",
"}",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/_(?<round>\\d+)\\/.+\\/(?<id>\\d+)-(?<image>\\d+)-.+(?<ext>\\.jpe?g|png|gif)/'",
",",
"$",
"src",
",",
"$",
"mat",
")",
")",
"{",
"$",
"src",
"=",
"$",
"this",
"->",
"browser",
"->",
"getHost",
"(",
")",
".",
"'/'",
".",
"$",
"type",
".",
"'/img/'",
".",
"$",
"mat",
"[",
"'round'",
"]",
".",
"'/'",
".",
"$",
"mat",
"[",
"'id'",
"]",
".",
"'/'",
".",
"$",
"mat",
"[",
"'image'",
"]",
".",
"$",
"mat",
"[",
"'ext'",
"]",
";",
"$",
"entity",
"->",
"setSource",
"(",
"self",
"::",
"NAME",
".",
"'/'",
".",
"$",
"id",
".",
"'/'",
".",
"$",
"mat",
"[",
"'image'",
"]",
".",
"$",
"mat",
"[",
"'ext'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"uploadImage",
"(",
"$",
"src",
",",
"$",
"entity",
")",
")",
"{",
"$",
"frames",
"[",
"]",
"=",
"$",
"entity",
";",
"}",
"}",
"}",
"return",
"$",
"frames",
";",
"}"
]
| Get item frames.
@param int $id
@param string $type
@return array | [
"Get",
"item",
"frames",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L729-L761 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getNodeValueAsText | private function getNodeValueAsText(\DOMNode $node)
{
$text = $node->ownerDocument->saveHTML($node);
$text = str_replace(["<br>\n", "\n", '<br>'], ['<br>', ' ', "\n"], $text);
return trim(strip_tags($text));
} | php | private function getNodeValueAsText(\DOMNode $node)
{
$text = $node->ownerDocument->saveHTML($node);
$text = str_replace(["<br>\n", "\n", '<br>'], ['<br>', ' ', "\n"], $text);
return trim(strip_tags($text));
} | [
"private",
"function",
"getNodeValueAsText",
"(",
"\\",
"DOMNode",
"$",
"node",
")",
"{",
"$",
"text",
"=",
"$",
"node",
"->",
"ownerDocument",
"->",
"saveHTML",
"(",
"$",
"node",
")",
";",
"$",
"text",
"=",
"str_replace",
"(",
"[",
"\"<br>\\n\"",
",",
"\"\\n\"",
",",
"'<br>'",
"]",
",",
"[",
"'<br>'",
",",
"' '",
",",
"\"\\n\"",
"]",
",",
"$",
"text",
")",
";",
"return",
"trim",
"(",
"strip_tags",
"(",
"$",
"text",
")",
")",
";",
"}"
]
| Get node value as text.
@param \DOMNode $node
@return string | [
"Get",
"node",
"value",
"as",
"text",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L770-L776 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getStudio | private function getStudio(\DOMXPath $xpath, \DOMNode $body)
{
$studios = $xpath->query('//img[starts-with(@src,"http://www.world-art.ru/img/company_new/")]', $body);
if ($studios->length) {
foreach ($studios as $studio) {
$url = $studio->attributes->getNamedItem('src')->nodeValue;
if (preg_match('/\/(\d+)\./', $url, $mat) && isset($this->studios[$mat[1]])) {
return $this->doctrine
->getRepository('AnimeDbCatalogBundle:Studio')
->findOneByName($this->studios[$mat[1]]);
}
}
}
} | php | private function getStudio(\DOMXPath $xpath, \DOMNode $body)
{
$studios = $xpath->query('//img[starts-with(@src,"http://www.world-art.ru/img/company_new/")]', $body);
if ($studios->length) {
foreach ($studios as $studio) {
$url = $studio->attributes->getNamedItem('src')->nodeValue;
if (preg_match('/\/(\d+)\./', $url, $mat) && isset($this->studios[$mat[1]])) {
return $this->doctrine
->getRepository('AnimeDbCatalogBundle:Studio')
->findOneByName($this->studios[$mat[1]]);
}
}
}
} | [
"private",
"function",
"getStudio",
"(",
"\\",
"DOMXPath",
"$",
"xpath",
",",
"\\",
"DOMNode",
"$",
"body",
")",
"{",
"$",
"studios",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'//img[starts-with(@src,\"http://www.world-art.ru/img/company_new/\")]'",
",",
"$",
"body",
")",
";",
"if",
"(",
"$",
"studios",
"->",
"length",
")",
"{",
"foreach",
"(",
"$",
"studios",
"as",
"$",
"studio",
")",
"{",
"$",
"url",
"=",
"$",
"studio",
"->",
"attributes",
"->",
"getNamedItem",
"(",
"'src'",
")",
"->",
"nodeValue",
";",
"if",
"(",
"preg_match",
"(",
"'/\\/(\\d+)\\./'",
",",
"$",
"url",
",",
"$",
"mat",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"studios",
"[",
"$",
"mat",
"[",
"1",
"]",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"doctrine",
"->",
"getRepository",
"(",
"'AnimeDbCatalogBundle:Studio'",
")",
"->",
"findOneByName",
"(",
"$",
"this",
"->",
"studios",
"[",
"$",
"mat",
"[",
"1",
"]",
"]",
")",
";",
"}",
"}",
"}",
"}"
]
| Get item studio.
@param \DOMXPath $xpath
@param \DOMNode $body
@return \AnimeDb\Bundle\CatalogBundle\Entity\Studio|null | [
"Get",
"item",
"studio",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L786-L799 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getItemType | public function getItemType($url)
{
if (strpos($url, self::ITEM_TYPE_ANIMATION.'/'.self::ITEM_TYPE_ANIMATION) !== false) {
return self::ITEM_TYPE_ANIMATION;
} elseif (strpos($url, self::ITEM_TYPE_CINEMA.'/'.self::ITEM_TYPE_CINEMA) !== false) {
return self::ITEM_TYPE_CINEMA;
} else {
return;
}
} | php | public function getItemType($url)
{
if (strpos($url, self::ITEM_TYPE_ANIMATION.'/'.self::ITEM_TYPE_ANIMATION) !== false) {
return self::ITEM_TYPE_ANIMATION;
} elseif (strpos($url, self::ITEM_TYPE_CINEMA.'/'.self::ITEM_TYPE_CINEMA) !== false) {
return self::ITEM_TYPE_CINEMA;
} else {
return;
}
} | [
"public",
"function",
"getItemType",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"url",
",",
"self",
"::",
"ITEM_TYPE_ANIMATION",
".",
"'/'",
".",
"self",
"::",
"ITEM_TYPE_ANIMATION",
")",
"!==",
"false",
")",
"{",
"return",
"self",
"::",
"ITEM_TYPE_ANIMATION",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"url",
",",
"self",
"::",
"ITEM_TYPE_CINEMA",
".",
"'/'",
".",
"self",
"::",
"ITEM_TYPE_CINEMA",
")",
"!==",
"false",
")",
"{",
"return",
"self",
"::",
"ITEM_TYPE_CINEMA",
";",
"}",
"else",
"{",
"return",
";",
"}",
"}"
]
| Get item type by URL.
@param string $url
@return string | [
"Get",
"item",
"type",
"by",
"URL",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L808-L817 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.fillAnimationNames | protected function fillAnimationNames(Item $item, \DOMXPath $xpath, \DOMElement $head)
{
// add main name
$names = $xpath->query('table[1]/tr/td', $head)->item(0)->nodeValue;
$names = explode("\n", trim($names));
// clear
$name = preg_replace('/\[\d{4}\]/', '', array_shift($names)); // example: [2011]
$name = preg_replace('/\[?(ТВ|OVA|ONA)(\-\d)?\]?/', '', $name); // example: [TV-1]
$name = preg_replace('/\(фильм \w+\)/u', '', $name); // example: (фильм седьмой)
$name = preg_replace('/ - Фильм$/iu', '', $name); // example: - Фильм
$item->setName(trim($name));
// add other names
foreach ($names as $name) {
$name = trim(preg_replace('/(\(\d+\))?/', '', $name));
$item->addName((new Name())->setName($name));
}
return $item;
} | php | protected function fillAnimationNames(Item $item, \DOMXPath $xpath, \DOMElement $head)
{
// add main name
$names = $xpath->query('table[1]/tr/td', $head)->item(0)->nodeValue;
$names = explode("\n", trim($names));
// clear
$name = preg_replace('/\[\d{4}\]/', '', array_shift($names)); // example: [2011]
$name = preg_replace('/\[?(ТВ|OVA|ONA)(\-\d)?\]?/', '', $name); // example: [TV-1]
$name = preg_replace('/\(фильм \w+\)/u', '', $name); // example: (фильм седьмой)
$name = preg_replace('/ - Фильм$/iu', '', $name); // example: - Фильм
$item->setName(trim($name));
// add other names
foreach ($names as $name) {
$name = trim(preg_replace('/(\(\d+\))?/', '', $name));
$item->addName((new Name())->setName($name));
}
return $item;
} | [
"protected",
"function",
"fillAnimationNames",
"(",
"Item",
"$",
"item",
",",
"\\",
"DOMXPath",
"$",
"xpath",
",",
"\\",
"DOMElement",
"$",
"head",
")",
"{",
"// add main name",
"$",
"names",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'table[1]/tr/td'",
",",
"$",
"head",
")",
"->",
"item",
"(",
"0",
")",
"->",
"nodeValue",
";",
"$",
"names",
"=",
"explode",
"(",
"\"\\n\"",
",",
"trim",
"(",
"$",
"names",
")",
")",
";",
"// clear",
"$",
"name",
"=",
"preg_replace",
"(",
"'/\\[\\d{4}\\]/'",
",",
"''",
",",
"array_shift",
"(",
"$",
"names",
")",
")",
";",
"// example: [2011]",
"$",
"name",
"=",
"preg_replace",
"(",
"'/\\[?(ТВ|OVA|ONA)(\\-\\d)?\\]?/', ",
"'",
", ",
"$",
"a",
"me);",
" ",
"/",
" example: [TV-1]",
"$",
"name",
"=",
"preg_replace",
"(",
"'/\\(фильм \\w+\\)/u', '',",
" ",
"na",
"m",
")",
"; //",
" ",
"e",
"ample: (фильм седьмой)",
"$",
"name",
"=",
"preg_replace",
"(",
"'/ - Фильм$/iu', '',",
" ",
"na",
"m",
")",
"; //",
" ",
"e",
"ample: - Фильм",
"$",
"item",
"->",
"setName",
"(",
"trim",
"(",
"$",
"name",
")",
")",
";",
"// add other names",
"foreach",
"(",
"$",
"names",
"as",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"trim",
"(",
"preg_replace",
"(",
"'/(\\(\\d+\\))?/'",
",",
"''",
",",
"$",
"name",
")",
")",
";",
"$",
"item",
"->",
"addName",
"(",
"(",
"new",
"Name",
"(",
")",
")",
"->",
"setName",
"(",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"item",
";",
"}"
]
| Fill names for Animation type.
@param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
@param \DOMXPath $xpath
@param \DOMElement $head
@return \AnimeDb\Bundle\CatalogBundle\Entity\Item | [
"Fill",
"names",
"for",
"Animation",
"type",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L828-L848 |
anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getCoverUrl | public function getCoverUrl($id, $type)
{
switch ($type) {
case self::ITEM_TYPE_ANIMATION:
return $this->browser->getHost().'/'.$type.'/img/'.(ceil($id / 1000) * 1000).'/'.$id.'/1.jpg';
case self::ITEM_TYPE_CINEMA:
return $this->browser->getHost().'/'.$type.'/img/'.(ceil($id / 10000) * 10000).'/'.$id.'/1.jpg';
default:
return;
}
} | php | public function getCoverUrl($id, $type)
{
switch ($type) {
case self::ITEM_TYPE_ANIMATION:
return $this->browser->getHost().'/'.$type.'/img/'.(ceil($id / 1000) * 1000).'/'.$id.'/1.jpg';
case self::ITEM_TYPE_CINEMA:
return $this->browser->getHost().'/'.$type.'/img/'.(ceil($id / 10000) * 10000).'/'.$id.'/1.jpg';
default:
return;
}
} | [
"public",
"function",
"getCoverUrl",
"(",
"$",
"id",
",",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"self",
"::",
"ITEM_TYPE_ANIMATION",
":",
"return",
"$",
"this",
"->",
"browser",
"->",
"getHost",
"(",
")",
".",
"'/'",
".",
"$",
"type",
".",
"'/img/'",
".",
"(",
"ceil",
"(",
"$",
"id",
"/",
"1000",
")",
"*",
"1000",
")",
".",
"'/'",
".",
"$",
"id",
".",
"'/1.jpg'",
";",
"case",
"self",
"::",
"ITEM_TYPE_CINEMA",
":",
"return",
"$",
"this",
"->",
"browser",
"->",
"getHost",
"(",
")",
".",
"'/'",
".",
"$",
"type",
".",
"'/img/'",
".",
"(",
"ceil",
"(",
"$",
"id",
"/",
"10000",
")",
"*",
"10000",
")",
".",
"'/'",
".",
"$",
"id",
".",
"'/1.jpg'",
";",
"default",
":",
"return",
";",
"}",
"}"
]
| Get cover URL.
@param string $id
@param string $type
@return string|null | [
"Get",
"cover",
"URL",
"."
]
| train | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L890-L900 |
EvanDotPro/EdpGithub | src/EdpGithub/Listener/Auth/UrlToken.php | UrlToken.preSend | public function preSend(Event $e)
{
$validator = new NotEmpty();
if (!isset($this->options['tokenOrLogin'])
|| !$validator->isValid($this->options['tokenOrLogin'])
) {
throw new Exception\InvalidArgumentException('You need to set OAuth token!');
}
/* @var Http\Request $request */
$request = $e->getTarget();
$query = $request->getQuery();
$query->set('access_token', $this->options['tokenOrLogin']);
} | php | public function preSend(Event $e)
{
$validator = new NotEmpty();
if (!isset($this->options['tokenOrLogin'])
|| !$validator->isValid($this->options['tokenOrLogin'])
) {
throw new Exception\InvalidArgumentException('You need to set OAuth token!');
}
/* @var Http\Request $request */
$request = $e->getTarget();
$query = $request->getQuery();
$query->set('access_token', $this->options['tokenOrLogin']);
} | [
"public",
"function",
"preSend",
"(",
"Event",
"$",
"e",
")",
"{",
"$",
"validator",
"=",
"new",
"NotEmpty",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'tokenOrLogin'",
"]",
")",
"||",
"!",
"$",
"validator",
"->",
"isValid",
"(",
"$",
"this",
"->",
"options",
"[",
"'tokenOrLogin'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"'You need to set OAuth token!'",
")",
";",
"}",
"/* @var Http\\Request $request */",
"$",
"request",
"=",
"$",
"e",
"->",
"getTarget",
"(",
")",
";",
"$",
"query",
"=",
"$",
"request",
"->",
"getQuery",
"(",
")",
";",
"$",
"query",
"->",
"set",
"(",
"'access_token'",
",",
"$",
"this",
"->",
"options",
"[",
"'tokenOrLogin'",
"]",
")",
";",
"}"
]
| Add access token to Request Parameters
@throws Exception\InvalidArgumentException | [
"Add",
"access",
"token",
"to",
"Request",
"Parameters"
]
| train | https://github.com/EvanDotPro/EdpGithub/blob/51f3e33e02edbef011103e3c2c1629d46af011a3/src/EdpGithub/Listener/Auth/UrlToken.php#L16-L31 |
echo58/sms | src/Pool.php | Pool.registerProvider | public function registerProvider(ProviderInterface $provider)
{
$this->providers[$provider->getName()] = $provider;
$this->sortProviders();
return $this;
} | php | public function registerProvider(ProviderInterface $provider)
{
$this->providers[$provider->getName()] = $provider;
$this->sortProviders();
return $this;
} | [
"public",
"function",
"registerProvider",
"(",
"ProviderInterface",
"$",
"provider",
")",
"{",
"$",
"this",
"->",
"providers",
"[",
"$",
"provider",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"provider",
";",
"$",
"this",
"->",
"sortProviders",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| 添加一个短信接口供应商
@param ProviderInterface $provider
@return $this | [
"添加一个短信接口供应商"
]
| train | https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Pool.php#L72-L78 |
echo58/sms | src/Pool.php | Pool.registerProviders | public function registerProviders(array $providers)
{
foreach ($providers as $provider) {
$this->providers[$provider->getName()] = $provider;
}
$this->sortProviders();
return $this;
} | php | public function registerProviders(array $providers)
{
foreach ($providers as $provider) {
$this->providers[$provider->getName()] = $provider;
}
$this->sortProviders();
return $this;
} | [
"public",
"function",
"registerProviders",
"(",
"array",
"$",
"providers",
")",
"{",
"foreach",
"(",
"$",
"providers",
"as",
"$",
"provider",
")",
"{",
"$",
"this",
"->",
"providers",
"[",
"$",
"provider",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"provider",
";",
"}",
"$",
"this",
"->",
"sortProviders",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| 在现有短信接口供应商列表中添加一批新的短信接口供应商
@param ProviderInterface[] $providers
@return $this | [
"在现有短信接口供应商列表中添加一批新的短信接口供应商"
]
| train | https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Pool.php#L86-L94 |
echo58/sms | src/Pool.php | Pool.sortProviders | protected function sortProviders()
{
// fix: uasort(): Array was modified by the user comparison function
$simpleProviders = [];
foreach ($this->providers as $name => $provider) {
$simpleProviders[$name] = $provider->getPriority();
}
asort($simpleProviders);
$providers = [];
foreach ($simpleProviders as $name => $priority) {
$providers[$name] = $this->providers[$name];
}
$this->providers = $providers;
} | php | protected function sortProviders()
{
// fix: uasort(): Array was modified by the user comparison function
$simpleProviders = [];
foreach ($this->providers as $name => $provider) {
$simpleProviders[$name] = $provider->getPriority();
}
asort($simpleProviders);
$providers = [];
foreach ($simpleProviders as $name => $priority) {
$providers[$name] = $this->providers[$name];
}
$this->providers = $providers;
} | [
"protected",
"function",
"sortProviders",
"(",
")",
"{",
"// fix: uasort(): Array was modified by the user comparison function",
"$",
"simpleProviders",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"providers",
"as",
"$",
"name",
"=>",
"$",
"provider",
")",
"{",
"$",
"simpleProviders",
"[",
"$",
"name",
"]",
"=",
"$",
"provider",
"->",
"getPriority",
"(",
")",
";",
"}",
"asort",
"(",
"$",
"simpleProviders",
")",
";",
"$",
"providers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"simpleProviders",
"as",
"$",
"name",
"=>",
"$",
"priority",
")",
"{",
"$",
"providers",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"providers",
"[",
"$",
"name",
"]",
";",
"}",
"$",
"this",
"->",
"providers",
"=",
"$",
"providers",
";",
"}"
]
| 根据短信接口供应商的优先级对短信接口供应商列表进行排序
优先级数字越小,越靠前 | [
"根据短信接口供应商的优先级对短信接口供应商列表进行排序"
]
| train | https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Pool.php#L101-L114 |
echo58/sms | src/Pool.php | Pool.setMessages | public function setMessages(array $messages)
{
$this->unsetMessages();
foreach ($messages as $message) {
$this->appendMessage($message);
}
return $this;
} | php | public function setMessages(array $messages)
{
$this->unsetMessages();
foreach ($messages as $message) {
$this->appendMessage($message);
}
return $this;
} | [
"public",
"function",
"setMessages",
"(",
"array",
"$",
"messages",
")",
"{",
"$",
"this",
"->",
"unsetMessages",
"(",
")",
";",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"appendMessage",
"(",
"$",
"message",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| 设置需要发送的消息列表
@param Message[] $messages
@return $this | [
"设置需要发送的消息列表"
]
| train | https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Pool.php#L140-L148 |
echo58/sms | src/Pool.php | Pool.addMessage | public function addMessage(Message $message, $prepend = false)
{
if (!$prepend) {
$this->appendMessage($message);
} else {
$this->prependMessage($message);
}
return $this;
} | php | public function addMessage(Message $message, $prepend = false)
{
if (!$prepend) {
$this->appendMessage($message);
} else {
$this->prependMessage($message);
}
return $this;
} | [
"public",
"function",
"addMessage",
"(",
"Message",
"$",
"message",
",",
"$",
"prepend",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"prepend",
")",
"{",
"$",
"this",
"->",
"appendMessage",
"(",
"$",
"message",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"prependMessage",
"(",
"$",
"message",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| 添加一条需要发送的消息
@param Message $message
@param bool $prepend 控制添加的消息是添加在消息队列头部还是尾部,默认添加在尾部
@return $this | [
"添加一条需要发送的消息"
]
| train | https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Pool.php#L170-L179 |
echo58/sms | src/Pool.php | Pool.addMessages | public function addMessages(array $messages, $prepend = false)
{
if ($prepend) {
$messages = array_reverse($messages);
}
foreach ($messages as $message) {
$this->addMessage($message, $prepend);
}
return $this;
} | php | public function addMessages(array $messages, $prepend = false)
{
if ($prepend) {
$messages = array_reverse($messages);
}
foreach ($messages as $message) {
$this->addMessage($message, $prepend);
}
return $this;
} | [
"public",
"function",
"addMessages",
"(",
"array",
"$",
"messages",
",",
"$",
"prepend",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"prepend",
")",
"{",
"$",
"messages",
"=",
"array_reverse",
"(",
"$",
"messages",
")",
";",
"}",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"addMessage",
"(",
"$",
"message",
",",
"$",
"prepend",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| 添加一批需要发送的消息
@param Message[] $messages
@param bool $prepend 控制添加的消息是添加在消息队列头部还是尾部,默认添加在尾部
@return $this | [
"添加一批需要发送的消息"
]
| train | https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Pool.php#L188-L199 |
echo58/sms | src/Pool.php | Pool.send | public function send()
{
$providers = $this->providers;
$messages = $this->messages;
$this->unsetMessages();
foreach ($messages as &$message) {
foreach ($providers as $provider) {
$message->using($provider)->send();
if ($message->getStatus() == MessageStatus::STATUS_SENT) {
break;
} else {
$this->addError($message->getError());
}
}
}
return $messages;
} | php | public function send()
{
$providers = $this->providers;
$messages = $this->messages;
$this->unsetMessages();
foreach ($messages as &$message) {
foreach ($providers as $provider) {
$message->using($provider)->send();
if ($message->getStatus() == MessageStatus::STATUS_SENT) {
break;
} else {
$this->addError($message->getError());
}
}
}
return $messages;
} | [
"public",
"function",
"send",
"(",
")",
"{",
"$",
"providers",
"=",
"$",
"this",
"->",
"providers",
";",
"$",
"messages",
"=",
"$",
"this",
"->",
"messages",
";",
"$",
"this",
"->",
"unsetMessages",
"(",
")",
";",
"foreach",
"(",
"$",
"messages",
"as",
"&",
"$",
"message",
")",
"{",
"foreach",
"(",
"$",
"providers",
"as",
"$",
"provider",
")",
"{",
"$",
"message",
"->",
"using",
"(",
"$",
"provider",
")",
"->",
"send",
"(",
")",
";",
"if",
"(",
"$",
"message",
"->",
"getStatus",
"(",
")",
"==",
"MessageStatus",
"::",
"STATUS_SENT",
")",
"{",
"break",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addError",
"(",
"$",
"message",
"->",
"getError",
"(",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"messages",
";",
"}"
]
| 依次发送当前短信列表中的短信
@return Message[] | [
"依次发送当前短信列表中的短信"
]
| train | https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Pool.php#L254-L271 |
yuncms/framework | src/rest/models/UserRecoveryForm.php | UserRecoveryForm.resetPassword | public function resetPassword()
{
if ($this->validate() && ($user = $this->getUser()) != null) {
$user->resetPassword($this->password);
return true;
}
return false;
} | php | public function resetPassword()
{
if ($this->validate() && ($user = $this->getUser()) != null) {
$user->resetPassword($this->password);
return true;
}
return false;
} | [
"public",
"function",
"resetPassword",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"validate",
"(",
")",
"&&",
"(",
"$",
"user",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
")",
"!=",
"null",
")",
"{",
"$",
"user",
"->",
"resetPassword",
"(",
"$",
"this",
"->",
"password",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| 重置密码
@return boolean | [
"重置密码"
]
| train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/models/UserRecoveryForm.php#L82-L89 |
yuncms/framework | src/user/migrations/m180228_112500Create_user_login_attempt_table.php | m180228_112500Create_user_login_attempt_table.safeUp | public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
}
$this->createTable($this->tableName, [
'id' => $this->primaryKey(),
'key' => $this->string()->notNull(),
'amount' => $this->integer(2)->defaultValue(1),
'reset_at' => $this->unixTimestamp(),
'created_at' => $this->unixTimestamp(),
'updated_at' => $this->unixTimestamp(),
], $tableOptions);
$this->createIndex('user_login_attempt_key_index', $this->tableName, 'key');
$this->createIndex('user_login_attempt_amount_index', $this->tableName, 'amount');
$this->createIndex('user_login_attempt_reset_at_index', $this->tableName, 'reset_at');
} | php | public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
}
$this->createTable($this->tableName, [
'id' => $this->primaryKey(),
'key' => $this->string()->notNull(),
'amount' => $this->integer(2)->defaultValue(1),
'reset_at' => $this->unixTimestamp(),
'created_at' => $this->unixTimestamp(),
'updated_at' => $this->unixTimestamp(),
], $tableOptions);
$this->createIndex('user_login_attempt_key_index', $this->tableName, 'key');
$this->createIndex('user_login_attempt_amount_index', $this->tableName, 'amount');
$this->createIndex('user_login_attempt_reset_at_index', $this->tableName, 'reset_at');
} | [
"public",
"function",
"safeUp",
"(",
")",
"{",
"$",
"tableOptions",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"driverName",
"===",
"'mysql'",
")",
"{",
"// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci",
"$",
"tableOptions",
"=",
"'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB'",
";",
"}",
"$",
"this",
"->",
"createTable",
"(",
"$",
"this",
"->",
"tableName",
",",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"primaryKey",
"(",
")",
",",
"'key'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"notNull",
"(",
")",
",",
"'amount'",
"=>",
"$",
"this",
"->",
"integer",
"(",
"2",
")",
"->",
"defaultValue",
"(",
"1",
")",
",",
"'reset_at'",
"=>",
"$",
"this",
"->",
"unixTimestamp",
"(",
")",
",",
"'created_at'",
"=>",
"$",
"this",
"->",
"unixTimestamp",
"(",
")",
",",
"'updated_at'",
"=>",
"$",
"this",
"->",
"unixTimestamp",
"(",
")",
",",
"]",
",",
"$",
"tableOptions",
")",
";",
"$",
"this",
"->",
"createIndex",
"(",
"'user_login_attempt_key_index'",
",",
"$",
"this",
"->",
"tableName",
",",
"'key'",
")",
";",
"$",
"this",
"->",
"createIndex",
"(",
"'user_login_attempt_amount_index'",
",",
"$",
"this",
"->",
"tableName",
",",
"'amount'",
")",
";",
"$",
"this",
"->",
"createIndex",
"(",
"'user_login_attempt_reset_at_index'",
",",
"$",
"this",
"->",
"tableName",
",",
"'reset_at'",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/migrations/m180228_112500Create_user_login_attempt_table.php#L15-L34 |
dashifen/wordpress-php7-plugin-boilerplate | src/Controller/ControllerTraits/PostStatusesTrait.php | PostStatusesTrait.initPostStatusesTrait | final protected function initPostStatusesTrait(): void {
$postStatuses = $this->getPostStatuses();
// first, we register our statuses. notice that we directly call the
// WordPress add_action() function because we want to use anonymous
// functions here, and there's no good way to add these actions to a
// LoaderInterface object as a result. plus, we want these actions to
// "just happen" without a programmer having to think about them.
$options = [];
foreach ($postStatuses as $postStatus) {
$args = $this->getPostStatusArguments($postStatus);
add_action("init", function () use ($postStatus, $args) {
register_post_status($postStatus, $args);
});
$options[$postStatus] = $args["label"];
}
add_action("post_submitbox_misc_actions",
function (\WP_Post $post) use ($options) {
// registering our post status tells WordPress all about it,
// but WordPress doesn't automatically add them to the <select>
// elements in the DOM. so, we do that here. for more info
// see https://core.trac.wordpress.org/ticket/12706.
$jsonOptions = "{";
$optionFormat = '"%s": { "display": "%s", "selected": %d },';
foreach ($options as $status => $display) {
$selected = (int)$post->post_status === $status;
// for each of our options, we use the above format to
// create a series of JSON strings which we can inject
// into our JavaScript below.
$jsonOptions .= sprintf($optionFormat, $status, $display, $selected);
}
// the loop above adds an extra comma to our JSON string.
// we'll replace that comma with a the closing curly brace
// to end said string.
$jsonOptions = preg_replace("/,$/", "}", $jsonOptions);
ob_start(); ?>
<script id="php7BoilerplateAddPostStatuses">
(function ($) {
// we'll add our statuses into the scope of this
// anonymous functions. that way, it's accessible
// to the other functions, anonymous or otherwise,
// herein. but, it won't conflict with any other
// variable named statuses outside this scope.
var statuses = <?= $jsonOptions ?>;
$(document).ready(function () {
var statusSelect = $("#post_status");
if (statusSelect.length > 0) {
// as long as we have a status <select> in
// the DOM, we'll want to do some work to make
// our custom statuses work.
setDisplayedStatus(statusSelect);
$(".save-post-status").click(setHiddenStatus);
addCustomStatuses(statusSelect);
}
});
function setDisplayedStatus(statusSelect) {
var status = statusSelect.val();
// as long as our status is in our list of custom
// statuses, we want to make sure that the on-
// screen display of the posts's status matches
// the display of the selected option.
if ($.inArray(status, statuses)) {
var display = statusSelect.find("option[value=" + status + "]").text();
$("#post-status-display").text(display);
}
}
function setHiddenStatus() {
var status = $("#post_status").val();
// as long as the status that's selected is a part
// of our list of statuses, we'll want to set the
// the value of the #hidden_post_status field to
// the selected status.
if ($.inArray(status, statuses)) {
$("#hidden_post_status").val(status);
}
}
function addCustomStatuses(statusSelect) {
for(status in statuses) {
if (statuses.hasOwnProperty(status)) {
// for each of our custom statuses, we
// create an <option>. if our status is
// selected, then we set that property.
// otherwise, we set various attributes
// and then append it to our <select>
// element.
var option = $("<option>")
.prop("selected", statuses[status].selected)
.text(statuses[status].display)
.attr("value", status)
.data("custom", true);
statusSelect.append(option);
}
}
// in case we need to do anything else after we've
// changed the DOM, we fire this event, too. then,
// other JS can watch for it and handle any clean
// up or whatever when it's caught.
var event = new jQuery.Event("postStatusesAdded");
statusSelect.trigger(event);
}
})(jQuery);
</script>
<?php echo ob_get_clean();
}
);
} | php | final protected function initPostStatusesTrait(): void {
$postStatuses = $this->getPostStatuses();
// first, we register our statuses. notice that we directly call the
// WordPress add_action() function because we want to use anonymous
// functions here, and there's no good way to add these actions to a
// LoaderInterface object as a result. plus, we want these actions to
// "just happen" without a programmer having to think about them.
$options = [];
foreach ($postStatuses as $postStatus) {
$args = $this->getPostStatusArguments($postStatus);
add_action("init", function () use ($postStatus, $args) {
register_post_status($postStatus, $args);
});
$options[$postStatus] = $args["label"];
}
add_action("post_submitbox_misc_actions",
function (\WP_Post $post) use ($options) {
// registering our post status tells WordPress all about it,
// but WordPress doesn't automatically add them to the <select>
// elements in the DOM. so, we do that here. for more info
// see https://core.trac.wordpress.org/ticket/12706.
$jsonOptions = "{";
$optionFormat = '"%s": { "display": "%s", "selected": %d },';
foreach ($options as $status => $display) {
$selected = (int)$post->post_status === $status;
// for each of our options, we use the above format to
// create a series of JSON strings which we can inject
// into our JavaScript below.
$jsonOptions .= sprintf($optionFormat, $status, $display, $selected);
}
// the loop above adds an extra comma to our JSON string.
// we'll replace that comma with a the closing curly brace
// to end said string.
$jsonOptions = preg_replace("/,$/", "}", $jsonOptions);
ob_start(); ?>
<script id="php7BoilerplateAddPostStatuses">
(function ($) {
// we'll add our statuses into the scope of this
// anonymous functions. that way, it's accessible
// to the other functions, anonymous or otherwise,
// herein. but, it won't conflict with any other
// variable named statuses outside this scope.
var statuses = <?= $jsonOptions ?>;
$(document).ready(function () {
var statusSelect = $("#post_status");
if (statusSelect.length > 0) {
// as long as we have a status <select> in
// the DOM, we'll want to do some work to make
// our custom statuses work.
setDisplayedStatus(statusSelect);
$(".save-post-status").click(setHiddenStatus);
addCustomStatuses(statusSelect);
}
});
function setDisplayedStatus(statusSelect) {
var status = statusSelect.val();
// as long as our status is in our list of custom
// statuses, we want to make sure that the on-
// screen display of the posts's status matches
// the display of the selected option.
if ($.inArray(status, statuses)) {
var display = statusSelect.find("option[value=" + status + "]").text();
$("#post-status-display").text(display);
}
}
function setHiddenStatus() {
var status = $("#post_status").val();
// as long as the status that's selected is a part
// of our list of statuses, we'll want to set the
// the value of the #hidden_post_status field to
// the selected status.
if ($.inArray(status, statuses)) {
$("#hidden_post_status").val(status);
}
}
function addCustomStatuses(statusSelect) {
for(status in statuses) {
if (statuses.hasOwnProperty(status)) {
// for each of our custom statuses, we
// create an <option>. if our status is
// selected, then we set that property.
// otherwise, we set various attributes
// and then append it to our <select>
// element.
var option = $("<option>")
.prop("selected", statuses[status].selected)
.text(statuses[status].display)
.attr("value", status)
.data("custom", true);
statusSelect.append(option);
}
}
// in case we need to do anything else after we've
// changed the DOM, we fire this event, too. then,
// other JS can watch for it and handle any clean
// up or whatever when it's caught.
var event = new jQuery.Event("postStatusesAdded");
statusSelect.trigger(event);
}
})(jQuery);
</script>
<?php echo ob_get_clean();
}
);
} | [
"final",
"protected",
"function",
"initPostStatusesTrait",
"(",
")",
":",
"void",
"{",
"$",
"postStatuses",
"=",
"$",
"this",
"->",
"getPostStatuses",
"(",
")",
";",
"// first, we register our statuses. notice that we directly call the",
"// WordPress add_action() function because we want to use anonymous",
"// functions here, and there's no good way to add these actions to a",
"// LoaderInterface object as a result. plus, we want these actions to",
"// \"just happen\" without a programmer having to think about them.",
"$",
"options",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"postStatuses",
"as",
"$",
"postStatus",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"getPostStatusArguments",
"(",
"$",
"postStatus",
")",
";",
"add_action",
"(",
"\"init\"",
",",
"function",
"(",
")",
"use",
"(",
"$",
"postStatus",
",",
"$",
"args",
")",
"{",
"register_post_status",
"(",
"$",
"postStatus",
",",
"$",
"args",
")",
";",
"}",
")",
";",
"$",
"options",
"[",
"$",
"postStatus",
"]",
"=",
"$",
"args",
"[",
"\"label\"",
"]",
";",
"}",
"add_action",
"(",
"\"post_submitbox_misc_actions\"",
",",
"function",
"(",
"\\",
"WP_Post",
"$",
"post",
")",
"use",
"(",
"$",
"options",
")",
"{",
"// registering our post status tells WordPress all about it,",
"// but WordPress doesn't automatically add them to the <select>",
"// elements in the DOM. so, we do that here. for more info",
"// see https://core.trac.wordpress.org/ticket/12706.",
"$",
"jsonOptions",
"=",
"\"{\"",
";",
"$",
"optionFormat",
"=",
"'\"%s\": { \"display\": \"%s\", \"selected\": %d },'",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"status",
"=>",
"$",
"display",
")",
"{",
"$",
"selected",
"=",
"(",
"int",
")",
"$",
"post",
"->",
"post_status",
"===",
"$",
"status",
";",
"// for each of our options, we use the above format to",
"// create a series of JSON strings which we can inject",
"// into our JavaScript below.",
"$",
"jsonOptions",
".=",
"sprintf",
"(",
"$",
"optionFormat",
",",
"$",
"status",
",",
"$",
"display",
",",
"$",
"selected",
")",
";",
"}",
"// the loop above adds an extra comma to our JSON string.",
"// we'll replace that comma with a the closing curly brace",
"// to end said string.",
"$",
"jsonOptions",
"=",
"preg_replace",
"(",
"\"/,$/\"",
",",
"\"}\"",
",",
"$",
"jsonOptions",
")",
";",
"ob_start",
"(",
")",
";",
"?>\n\n <script id=\"php7BoilerplateAddPostStatuses\">\n\t\t\t\t\t(function ($) {\n\n\t\t\t\t\t\t// we'll add our statuses into the scope of this\n\t\t\t\t\t\t// anonymous functions. that way, it's accessible\n\t\t\t\t\t\t// to the other functions, anonymous or otherwise,\n\t\t\t\t\t\t// herein. but, it won't conflict with any other\n\t\t\t\t\t\t// variable named statuses outside this scope.\n\n\t\t\t\t\t\tvar statuses = <?=",
"$",
"jsonOptions",
"?>;\n\n\t\t\t\t\t\t$(document).ready(function () {\n\t\t\t\t\t\t\tvar statusSelect = $(\"#post_status\");\n\t\t\t\t\t\t\tif (statusSelect.length > 0) {\n\n\t\t\t\t\t\t\t\t// as long as we have a status <select> in\n\t\t\t\t\t\t\t\t// the DOM, we'll want to do some work to make\n // our custom statuses work.\n\n\t\t\t\t\t\t\t\tsetDisplayedStatus(statusSelect);\n\t\t\t\t\t\t\t\t$(\".save-post-status\").click(setHiddenStatus);\n\t\t\t\t\t\t\t\taddCustomStatuses(statusSelect);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\n\t\t\t\t\t\tfunction setDisplayedStatus(statusSelect) {\n\t\t\t\t\t\t\tvar status = statusSelect.val();\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t// as long as our status is in our list of custom\n // statuses, we want to make sure that the on-\n // screen display of the posts's status matches\n // the display of the selected option.\n \n if ($.inArray(status, statuses)) {\n var display = statusSelect.find(\"option[value=\" + status + \"]\").text();\n $(\"#post-status-display\").text(display);\n }\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\tfunction setHiddenStatus() {\n\t\t\t\t\t\t\tvar status = $(\"#post_status\").val();\n\n\t\t\t\t\t\t\t// as long as the status that's selected is a part\n\t\t\t\t\t\t\t// of our list of statuses, we'll want to set the\n\t\t\t\t\t\t\t// the value of the #hidden_post_status field to\n\t\t\t\t\t\t\t// the selected status.\n\n\t\t\t\t\t\t\tif ($.inArray(status, statuses)) {\n\t\t\t\t\t\t\t\t$(\"#hidden_post_status\").val(status);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tfunction addCustomStatuses(statusSelect) {\n\t\t\t\t\t\t\tfor(status in statuses) {\n\t\t\t\t\t\t\t\tif (statuses.hasOwnProperty(status)) {\n\n\t\t\t\t\t\t\t\t\t// for each of our custom statuses, we\n\t\t\t\t\t\t\t\t\t// create an <option>. if our status is\n\t\t\t\t\t\t\t\t\t// selected, then we set that property.\n\t\t\t\t\t\t\t\t\t// otherwise, we set various attributes\n\t\t\t\t\t\t\t\t\t// and then append it to our <select>\n\t\t\t\t\t\t\t\t\t// element.\n\n\t\t\t\t\t\t\t\t\tvar option = $(\"<option>\")\n\t\t\t\t\t\t\t\t\t\t.prop(\"selected\", statuses[status].selected)\n\t\t\t\t\t\t\t\t\t\t.text(statuses[status].display)\n\t\t\t\t\t\t\t\t\t\t.attr(\"value\", status)\n\t\t\t\t\t\t\t\t\t\t.data(\"custom\", true);\n\n\t\t\t\t\t\t\t\t\tstatusSelect.append(option);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// in case we need to do anything else after we've\n\t\t\t\t\t\t\t// changed the DOM, we fire this event, too. then,\n\t\t\t\t\t\t\t// other JS can watch for it and handle any clean\n\t\t\t\t\t\t\t// up or whatever when it's caught.\n\n\t\t\t\t\t\t\tvar event = new jQuery.Event(\"postStatusesAdded\");\n\t\t\t\t\t\t\tstatusSelect.trigger(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t})(jQuery);\n </script>\n\t\t\t\t\n\t\t\t\t<?php",
"echo",
"ob_get_clean",
"(",
")",
";",
"}",
")",
";",
"}"
]
| When we initialize this trait, we want to register our post statuses
and ensure that they appear in the status drop-downs throughout Word-
Press core.
@return void | [
"When",
"we",
"initialize",
"this",
"trait",
"we",
"want",
"to",
"register",
"our",
"post",
"statuses",
"and",
"ensure",
"that",
"they",
"appear",
"in",
"the",
"status",
"drop",
"-",
"downs",
"throughout",
"Word",
"-",
"Press",
"core",
"."
]
| train | https://github.com/dashifen/wordpress-php7-plugin-boilerplate/blob/c7875deb403d311efca72dc3c8beb566972a56cb/src/Controller/ControllerTraits/PostStatusesTrait.php#L38-L171 |
ClanCats/Core | src/bundles/Database/Query.php | Query.insert | public static function insert( $table, $values = array(), $handler = null )
{
return Query_Insert::create( $table, $handler )->values( $values );
} | php | public static function insert( $table, $values = array(), $handler = null )
{
return Query_Insert::create( $table, $handler )->values( $values );
} | [
"public",
"static",
"function",
"insert",
"(",
"$",
"table",
",",
"$",
"values",
"=",
"array",
"(",
")",
",",
"$",
"handler",
"=",
"null",
")",
"{",
"return",
"Query_Insert",
"::",
"create",
"(",
"$",
"table",
",",
"$",
"handler",
")",
"->",
"values",
"(",
"$",
"values",
")",
";",
"}"
]
| Create an insert
@param string $table
@param array $values
@param string $handler
@return DB\Query | [
"Create",
"an",
"insert"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query.php#L50-L53 |
ClanCats/Core | src/bundles/Database/Query.php | Query.update | public static function update( $table, $values = array(), $handler = null )
{
return Query_Update::create( $table, $handler )->set( $values );
} | php | public static function update( $table, $values = array(), $handler = null )
{
return Query_Update::create( $table, $handler )->set( $values );
} | [
"public",
"static",
"function",
"update",
"(",
"$",
"table",
",",
"$",
"values",
"=",
"array",
"(",
")",
",",
"$",
"handler",
"=",
"null",
")",
"{",
"return",
"Query_Update",
"::",
"create",
"(",
"$",
"table",
",",
"$",
"handler",
")",
"->",
"set",
"(",
"$",
"values",
")",
";",
"}"
]
| Create an update
@param string $table
@param array $values
@param string $handler
@return DB\Query | [
"Create",
"an",
"update"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query.php#L63-L66 |
ClanCats/Core | src/bundles/Database/Query.php | Query.select | public static function select( $table, $fields = array(), $handler = null )
{
return Query_Select::create( $table, $handler )->fields( $fields );
} | php | public static function select( $table, $fields = array(), $handler = null )
{
return Query_Select::create( $table, $handler )->fields( $fields );
} | [
"public",
"static",
"function",
"select",
"(",
"$",
"table",
",",
"$",
"fields",
"=",
"array",
"(",
")",
",",
"$",
"handler",
"=",
"null",
")",
"{",
"return",
"Query_Select",
"::",
"create",
"(",
"$",
"table",
",",
"$",
"handler",
")",
"->",
"fields",
"(",
"$",
"fields",
")",
";",
"}"
]
| Select data from the database
@param string $table
@param array $fields
@param string $handler
@return mixed | [
"Select",
"data",
"from",
"the",
"database"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query.php#L88-L91 |
ClanCats/Core | src/bundles/Database/Query.php | Query.where | public function where( $column, $param1 = null, $param2 = null, $type = 'and' )
{
// if this is the first where element we are going to change
// the where type to 'where'
if ( empty( $this->wheres ) )
{
$type = 'where';
}
// when column is an array we assume to make a bulk and where.
// array( 'name' => 'ladina', 'language' => 'de' )
// where name = ladina and language = de
if ( is_array( $column ) )
{
foreach( $column as $key => $val )
{
$this->where( $key, $val, null, $type );
}
return $this;
}
// to make nested wheres possible you can pass an closure
// wich will create a new query where you can add your nested wheres
if ( is_closure( $column ) )
{
$this->wheres[] = array( $type, $column ); return $this;
}
// when param2 is null we replace param2 with param one as the
// value holder and make param1 to the = operator.
if ( is_null( $param2 ) )
{
$param2 = $param1; $param1 = '=';
}
// if the param2 is an array we filter it. Im no more sure why
// but it's there since 2 years so i think i had a reason.
if ( is_array( $param2 ) )
{
$param2 = array_unique( $param2 );
}
$this->wheres[] = array( $type, $column, $param1, $param2 ); return $this;
} | php | public function where( $column, $param1 = null, $param2 = null, $type = 'and' )
{
// if this is the first where element we are going to change
// the where type to 'where'
if ( empty( $this->wheres ) )
{
$type = 'where';
}
// when column is an array we assume to make a bulk and where.
// array( 'name' => 'ladina', 'language' => 'de' )
// where name = ladina and language = de
if ( is_array( $column ) )
{
foreach( $column as $key => $val )
{
$this->where( $key, $val, null, $type );
}
return $this;
}
// to make nested wheres possible you can pass an closure
// wich will create a new query where you can add your nested wheres
if ( is_closure( $column ) )
{
$this->wheres[] = array( $type, $column ); return $this;
}
// when param2 is null we replace param2 with param one as the
// value holder and make param1 to the = operator.
if ( is_null( $param2 ) )
{
$param2 = $param1; $param1 = '=';
}
// if the param2 is an array we filter it. Im no more sure why
// but it's there since 2 years so i think i had a reason.
if ( is_array( $param2 ) )
{
$param2 = array_unique( $param2 );
}
$this->wheres[] = array( $type, $column, $param1, $param2 ); return $this;
} | [
"public",
"function",
"where",
"(",
"$",
"column",
",",
"$",
"param1",
"=",
"null",
",",
"$",
"param2",
"=",
"null",
",",
"$",
"type",
"=",
"'and'",
")",
"{",
"// if this is the first where element we are going to change",
"// the where type to 'where'",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"wheres",
")",
")",
"{",
"$",
"type",
"=",
"'where'",
";",
"}",
"// when column is an array we assume to make a bulk and where.",
"// array( 'name' => 'ladina', 'language' => 'de' )",
"// where name = ladina and language = de",
"if",
"(",
"is_array",
"(",
"$",
"column",
")",
")",
"{",
"foreach",
"(",
"$",
"column",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"where",
"(",
"$",
"key",
",",
"$",
"val",
",",
"null",
",",
"$",
"type",
")",
";",
"}",
"return",
"$",
"this",
";",
"}",
"// to make nested wheres possible you can pass an closure ",
"// wich will create a new query where you can add your nested wheres",
"if",
"(",
"is_closure",
"(",
"$",
"column",
")",
")",
"{",
"$",
"this",
"->",
"wheres",
"[",
"]",
"=",
"array",
"(",
"$",
"type",
",",
"$",
"column",
")",
";",
"return",
"$",
"this",
";",
"}",
"// when param2 is null we replace param2 with param one as the ",
"// value holder and make param1 to the = operator.",
"if",
"(",
"is_null",
"(",
"$",
"param2",
")",
")",
"{",
"$",
"param2",
"=",
"$",
"param1",
";",
"$",
"param1",
"=",
"'='",
";",
"}",
"// if the param2 is an array we filter it. Im no more sure why ",
"// but it's there since 2 years so i think i had a reason.",
"if",
"(",
"is_array",
"(",
"$",
"param2",
")",
")",
"{",
"$",
"param2",
"=",
"array_unique",
"(",
"$",
"param2",
")",
";",
"}",
"$",
"this",
"->",
"wheres",
"[",
"]",
"=",
"array",
"(",
"$",
"type",
",",
"$",
"column",
",",
"$",
"param1",
",",
"$",
"param2",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Create a where statement
where query: <$column> <$param1> <$param2> <$type>
example:
->where( 'name', 'ladina' ) // name = landina
->where( 'age', '>', 18 )
->where( 'name', 'in', array( 'johanna', 'jennifer' ) )
@param string $column The SQL column
@param mixed $param1
@param mixed $param2
@param string $type The where type ( and, or )
@return self | [
"Create",
"a",
"where",
"statement"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query.php#L180-L224 |
ClanCats/Core | src/bundles/Database/Query.php | Query.or_where | public function or_where( $column, $param1 = null, $param2 = null )
{
return $this->where( $column, $param1, $param2, 'or' );
} | php | public function or_where( $column, $param1 = null, $param2 = null )
{
return $this->where( $column, $param1, $param2, 'or' );
} | [
"public",
"function",
"or_where",
"(",
"$",
"column",
",",
"$",
"param1",
"=",
"null",
",",
"$",
"param2",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"where",
"(",
"$",
"column",
",",
"$",
"param1",
",",
"$",
"param2",
",",
"'or'",
")",
";",
"}"
]
| Create an or where statement
This is the same as the normal where just with a fixed type
@param string $column The SQL column
@param mixed $param1
@param mixed $param2
@return self | [
"Create",
"an",
"or",
"where",
"statement"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query.php#L237-L240 |
ClanCats/Core | src/bundles/Database/Query.php | Query.and_where | public function and_where( $column, $param1 = null, $param2 = null )
{
return $this->where( $column, $param1, $param2, 'and' );
} | php | public function and_where( $column, $param1 = null, $param2 = null )
{
return $this->where( $column, $param1, $param2, 'and' );
} | [
"public",
"function",
"and_where",
"(",
"$",
"column",
",",
"$",
"param1",
"=",
"null",
",",
"$",
"param2",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"where",
"(",
"$",
"column",
",",
"$",
"param1",
",",
"$",
"param2",
",",
"'and'",
")",
";",
"}"
]
| Create an and where statement
This is the same as the normal where just with a fixed type
@param string $column The SQL column
@param mixed $param1
@param mixed $param2
@return self | [
"Create",
"an",
"and",
"where",
"statement"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query.php#L253-L256 |
ClanCats/Core | src/bundles/Database/Query.php | Query.run | public function run( $handler = null )
{
if ( !is_null( $handler ) )
{
$this->handler( $handler );
}
return $this->handler->run( $this->build(), $this->handler->builder()->parameters );
} | php | public function run( $handler = null )
{
if ( !is_null( $handler ) )
{
$this->handler( $handler );
}
return $this->handler->run( $this->build(), $this->handler->builder()->parameters );
} | [
"public",
"function",
"run",
"(",
"$",
"handler",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"handler",
")",
")",
"{",
"$",
"this",
"->",
"handler",
"(",
"$",
"handler",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handler",
"->",
"run",
"(",
"$",
"this",
"->",
"build",
"(",
")",
",",
"$",
"this",
"->",
"handler",
"->",
"builder",
"(",
")",
"->",
"parameters",
")",
";",
"}"
]
| Build and execute the current query
This wil run the local build function and pass the parameters
from the builder object in the handler
@param string $handler
@return mixed | [
"Build",
"and",
"execute",
"the",
"current",
"query",
"This",
"wil",
"run",
"the",
"local",
"build",
"function",
"and",
"pass",
"the",
"parameters",
"from",
"the",
"builder",
"object",
"in",
"the",
"handler"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query.php#L319-L327 |
aedart/laravel-helpers | src/Traits/Logging/LogManagerTrait.php | LogManagerTrait.getLogManager | public function getLogManager(): ?LogManager
{
if (!$this->hasLogManager()) {
$this->setLogManager($this->getDefaultLogManager());
}
return $this->logManager;
} | php | public function getLogManager(): ?LogManager
{
if (!$this->hasLogManager()) {
$this->setLogManager($this->getDefaultLogManager());
}
return $this->logManager;
} | [
"public",
"function",
"getLogManager",
"(",
")",
":",
"?",
"LogManager",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasLogManager",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setLogManager",
"(",
"$",
"this",
"->",
"getDefaultLogManager",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"logManager",
";",
"}"
]
| Get log manager
If no log manager has been set, this method will
set and return a default log manager, if any such
value is available
@see getDefaultLogManager()
@return LogManager|null log manager or null if none log manager has been set | [
"Get",
"log",
"manager"
]
| train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Logging/LogManagerTrait.php#L52-L58 |
zodream/thirdparty | src/Pay/ChinaPay.php | ChinaPay.sign | public function sign($content) {
if (is_array($content)) {
$content = $this->getSignContent($content);
}
$sign_flag = openssl_sign($content,
$signature,
$this->privateKey['pkey'],
OPENSSL_ALGO_SHA512);
if (!$sign_flag) {
throw new \Exception('签名失败!');
}
return base64_encode($signature);
} | php | public function sign($content) {
if (is_array($content)) {
$content = $this->getSignContent($content);
}
$sign_flag = openssl_sign($content,
$signature,
$this->privateKey['pkey'],
OPENSSL_ALGO_SHA512);
if (!$sign_flag) {
throw new \Exception('签名失败!');
}
return base64_encode($signature);
} | [
"public",
"function",
"sign",
"(",
"$",
"content",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"content",
")",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"getSignContent",
"(",
"$",
"content",
")",
";",
"}",
"$",
"sign_flag",
"=",
"openssl_sign",
"(",
"$",
"content",
",",
"$",
"signature",
",",
"$",
"this",
"->",
"privateKey",
"[",
"'pkey'",
"]",
",",
"OPENSSL_ALGO_SHA512",
")",
";",
"if",
"(",
"!",
"$",
"sign_flag",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'签名失败!');",
"",
"",
"}",
"return",
"base64_encode",
"(",
"$",
"signature",
")",
";",
"}"
]
| 签名
@param array|string $content
@return string
@throws \Exception
@internal param array|string $args | [
"签名"
]
| train | https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/Pay/ChinaPay.php#L126-L138 |
zodream/thirdparty | src/Pay/ChinaPay.php | ChinaPay.getEncodeArray | public function getEncodeArray(array $args) {
$data = [];
foreach ($args as $key => $item) {
$data[] = sprintf('%s=%s', urlencode($key), urlencode($item));
}
return sprintf('{%s}', implode('&', $data));
} | php | public function getEncodeArray(array $args) {
$data = [];
foreach ($args as $key => $item) {
$data[] = sprintf('%s=%s', urlencode($key), urlencode($item));
}
return sprintf('{%s}', implode('&', $data));
} | [
"public",
"function",
"getEncodeArray",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"sprintf",
"(",
"'%s=%s'",
",",
"urlencode",
"(",
"$",
"key",
")",
",",
"urlencode",
"(",
"$",
"item",
")",
")",
";",
"}",
"return",
"sprintf",
"(",
"'{%s}'",
",",
"implode",
"(",
"'&'",
",",
"$",
"data",
")",
")",
";",
"}"
]
| 数组转换成字符串
@param array $args
@return string | [
"数组转换成字符串"
]
| train | https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/Pay/ChinaPay.php#L178-L184 |
zodream/thirdparty | src/Pay/ChinaPay.php | ChinaPay.oldForm | public function oldForm(array $args, $buttonTip = '立即使用银联支付') {
$data = $this->encodeSign(Http::getMapParameters([
'Version' => '20140728',
'AccessType',// => '0',
'InstuId',
'AcqCode',
'#MerId',
'#MerOrderNo',
'#TranDate',// => date('Ymd'),
'#TranTime',// => date('His'),
'#OrderAmt',// => $order['order_amount'] * 100, 以分为单位
'TranType' => '0001', //0001个人网银支付 0002企业网银支付 0003授信交易 0004快捷支付 0005账单支付、 ChinaPay手机控件支付 0006认证支付 0007分期付款 0008后台支付 0201预授权交易
'BusiType' => '0001',
'CurryNo',// => 'CNY',
'SplitType', //0001:实时分账 0002:延时分账
'SplitMethod', //0:按金额分账 1:按比例分账
'MerSplitMsg',
'BankInstNo',
'#MerPageUrl',// => $pageUrl,
'#MerBgUrl',// => $bgUrl,
'CommodityMsg',
'MerResv' => 'chinapay',
'TranReserved',
'CardTranData',
'PayTimeOut',
'TimeStamp', // YmdHis
'RiskData',
'Signature',
'#RemoteAddr'// => real_ip()
], $this->merge($args)));
$button ='<form action="https://payment.chinapay.com/CTITS/service/rest/page/nref/000000000017/0/0/0/0/0" method="POST" target="_blank">';// (这里action的内容为提交交易数据的URL地址)
foreach ($data as $key => $item) {
$button .= '<input type="hidden" name="'.$key.'" value="'.$item.'">';
}
return $button.'<input type="submit" value="'.$buttonTip.'"/></form>';
} | php | public function oldForm(array $args, $buttonTip = '立即使用银联支付') {
$data = $this->encodeSign(Http::getMapParameters([
'Version' => '20140728',
'AccessType',// => '0',
'InstuId',
'AcqCode',
'#MerId',
'#MerOrderNo',
'#TranDate',// => date('Ymd'),
'#TranTime',// => date('His'),
'#OrderAmt',// => $order['order_amount'] * 100, 以分为单位
'TranType' => '0001', //0001个人网银支付 0002企业网银支付 0003授信交易 0004快捷支付 0005账单支付、 ChinaPay手机控件支付 0006认证支付 0007分期付款 0008后台支付 0201预授权交易
'BusiType' => '0001',
'CurryNo',// => 'CNY',
'SplitType', //0001:实时分账 0002:延时分账
'SplitMethod', //0:按金额分账 1:按比例分账
'MerSplitMsg',
'BankInstNo',
'#MerPageUrl',// => $pageUrl,
'#MerBgUrl',// => $bgUrl,
'CommodityMsg',
'MerResv' => 'chinapay',
'TranReserved',
'CardTranData',
'PayTimeOut',
'TimeStamp', // YmdHis
'RiskData',
'Signature',
'#RemoteAddr'// => real_ip()
], $this->merge($args)));
$button ='<form action="https://payment.chinapay.com/CTITS/service/rest/page/nref/000000000017/0/0/0/0/0" method="POST" target="_blank">';// (这里action的内容为提交交易数据的URL地址)
foreach ($data as $key => $item) {
$button .= '<input type="hidden" name="'.$key.'" value="'.$item.'">';
}
return $button.'<input type="submit" value="'.$buttonTip.'"/></form>';
} | [
"public",
"function",
"oldForm",
"(",
"array",
"$",
"args",
",",
"$",
"buttonTip",
"=",
"'立即使用银联支付') {",
"",
"",
"$",
"data",
"=",
"$",
"this",
"->",
"encodeSign",
"(",
"Http",
"::",
"getMapParameters",
"(",
"[",
"'Version'",
"=>",
"'20140728'",
",",
"'AccessType'",
",",
"// => '0',",
"'InstuId'",
",",
"'AcqCode'",
",",
"'#MerId'",
",",
"'#MerOrderNo'",
",",
"'#TranDate'",
",",
"// => date('Ymd'),",
"'#TranTime'",
",",
"// => date('His'),",
"'#OrderAmt'",
",",
"// => $order['order_amount'] * 100, 以分为单位",
"'TranType'",
"=>",
"'0001'",
",",
"//0001个人网银支付 0002企业网银支付 0003授信交易 0004快捷支付 0005账单支付、 ChinaPay手机控件支付 0006认证支付 0007分期付款 0008后台支付 0201预授权交易",
"'BusiType'",
"=>",
"'0001'",
",",
"'CurryNo'",
",",
"// => 'CNY',",
"'SplitType'",
",",
"//0001:实时分账 0002:延时分账",
"'SplitMethod'",
",",
"//0:按金额分账 1:按比例分账",
"'MerSplitMsg'",
",",
"'BankInstNo'",
",",
"'#MerPageUrl'",
",",
"// => $pageUrl,",
"'#MerBgUrl'",
",",
"// => $bgUrl,",
"'CommodityMsg'",
",",
"'MerResv'",
"=>",
"'chinapay'",
",",
"'TranReserved'",
",",
"'CardTranData'",
",",
"'PayTimeOut'",
",",
"'TimeStamp'",
",",
"// YmdHis",
"'RiskData'",
",",
"'Signature'",
",",
"'#RemoteAddr'",
"// => real_ip()",
"]",
",",
"$",
"this",
"->",
"merge",
"(",
"$",
"args",
")",
")",
")",
";",
"$",
"button",
"=",
"'<form action=\"https://payment.chinapay.com/CTITS/service/rest/page/nref/000000000017/0/0/0/0/0\" method=\"POST\" target=\"_blank\">'",
";",
"// (这里action的内容为提交交易数据的URL地址)",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"button",
".=",
"'<input type=\"hidden\" name=\"'",
".",
"$",
"key",
".",
"'\" value=\"'",
".",
"$",
"item",
".",
"'\">'",
";",
"}",
"return",
"$",
"button",
".",
"'<input type=\"submit\" value=\"'",
".",
"$",
"buttonTip",
".",
"'\"/></form>'",
";",
"}"
]
| 生成提交表单
@param array $args
@param string $buttonTip
@return string
@throws Exception | [
"生成提交表单"
]
| train | https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/Pay/ChinaPay.php#L193-L232 |
zodream/thirdparty | src/Pay/ChinaPay.php | ChinaPay.declareOrder | public function declareOrder(array $args = array()) {
$args = $this->getDeclareOrder()
->parameters($this->merge($args))->json();
// 签名和验签方法不一样,要改
if (!$this->verify($args)) {
throw new Exception('数据验签失败!');
}
if ($args['respCode'] != '01') {
return $args;
}
if ($args["respCode"] == "03"
|| $args["respCode"] == "04"
|| $args["respCode"] == "05") {
throw new Exception('处理超时,请稍后查询');
}
throw new Exception($args['respMsg']);
} | php | public function declareOrder(array $args = array()) {
$args = $this->getDeclareOrder()
->parameters($this->merge($args))->json();
// 签名和验签方法不一样,要改
if (!$this->verify($args)) {
throw new Exception('数据验签失败!');
}
if ($args['respCode'] != '01') {
return $args;
}
if ($args["respCode"] == "03"
|| $args["respCode"] == "04"
|| $args["respCode"] == "05") {
throw new Exception('处理超时,请稍后查询');
}
throw new Exception($args['respMsg']);
} | [
"public",
"function",
"declareOrder",
"(",
"array",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"getDeclareOrder",
"(",
")",
"->",
"parameters",
"(",
"$",
"this",
"->",
"merge",
"(",
"$",
"args",
")",
")",
"->",
"json",
"(",
")",
";",
"// 签名和验签方法不一样,要改",
"if",
"(",
"!",
"$",
"this",
"->",
"verify",
"(",
"$",
"args",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'数据验签失败!');",
"",
"",
"}",
"if",
"(",
"$",
"args",
"[",
"'respCode'",
"]",
"!=",
"'01'",
")",
"{",
"return",
"$",
"args",
";",
"}",
"if",
"(",
"$",
"args",
"[",
"\"respCode\"",
"]",
"==",
"\"03\"",
"||",
"$",
"args",
"[",
"\"respCode\"",
"]",
"==",
"\"04\"",
"||",
"$",
"args",
"[",
"\"respCode\"",
"]",
"==",
"\"05\"",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'处理超时,请稍后查询');",
"",
"",
"}",
"throw",
"new",
"Exception",
"(",
"$",
"args",
"[",
"'respMsg'",
"]",
")",
";",
"}"
]
| 报关
@param array $args
@return array|mixed
@throws Exception | [
"报关"
]
| train | https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/Pay/ChinaPay.php#L258-L274 |
zodream/thirdparty | src/OAuth/BaseOAuth.php | BaseOAuth.login | public function login() {
$state = Str::randomNumber(7);
Factory::session()->set('state', $state);
$this->set('state', $state);
return $this->getLogin()->getUrl();
} | php | public function login() {
$state = Str::randomNumber(7);
Factory::session()->set('state', $state);
$this->set('state', $state);
return $this->getLogin()->getUrl();
} | [
"public",
"function",
"login",
"(",
")",
"{",
"$",
"state",
"=",
"Str",
"::",
"randomNumber",
"(",
"7",
")",
";",
"Factory",
"::",
"session",
"(",
")",
"->",
"set",
"(",
"'state'",
",",
"$",
"state",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'state'",
",",
"$",
"state",
")",
";",
"return",
"$",
"this",
"->",
"getLogin",
"(",
")",
"->",
"getUrl",
"(",
")",
";",
"}"
]
| 返回重定向到登录页面的链接
@return Uri
@throws \Exception | [
"返回重定向到登录页面的链接"
]
| train | https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/OAuth/BaseOAuth.php#L61-L66 |
uthando-cms/uthando-dompdf | src/UthandoDomPdf/Form/View/Helper/PdfTextLineFormCollection.php | PdfTextLineFormCollection.renderTemplate | public function renderTemplate(Collection $collection)
{
$escapeHtmlAttribHelper = $this->getEscapeHtmlAttrHelper();
$fieldsetHelper = $this->getFieldsetHelper();
$templateMarkup = '';
$elementOrFieldset = $collection->getTemplateElement();
if ($elementOrFieldset instanceof PdfTextLineFieldSet) {
$templateMarkup .= sprintf(
$this->rowWrap,
$this->getLineType(),
$fieldsetHelper($elementOrFieldset, $this->shouldWrap()),
ucfirst($this->getLineType())
);
}
return sprintf(
$this->getTemplateWrapper(),
$this->getLineType(),
$escapeHtmlAttribHelper($templateMarkup)
);
} | php | public function renderTemplate(Collection $collection)
{
$escapeHtmlAttribHelper = $this->getEscapeHtmlAttrHelper();
$fieldsetHelper = $this->getFieldsetHelper();
$templateMarkup = '';
$elementOrFieldset = $collection->getTemplateElement();
if ($elementOrFieldset instanceof PdfTextLineFieldSet) {
$templateMarkup .= sprintf(
$this->rowWrap,
$this->getLineType(),
$fieldsetHelper($elementOrFieldset, $this->shouldWrap()),
ucfirst($this->getLineType())
);
}
return sprintf(
$this->getTemplateWrapper(),
$this->getLineType(),
$escapeHtmlAttribHelper($templateMarkup)
);
} | [
"public",
"function",
"renderTemplate",
"(",
"Collection",
"$",
"collection",
")",
"{",
"$",
"escapeHtmlAttribHelper",
"=",
"$",
"this",
"->",
"getEscapeHtmlAttrHelper",
"(",
")",
";",
"$",
"fieldsetHelper",
"=",
"$",
"this",
"->",
"getFieldsetHelper",
"(",
")",
";",
"$",
"templateMarkup",
"=",
"''",
";",
"$",
"elementOrFieldset",
"=",
"$",
"collection",
"->",
"getTemplateElement",
"(",
")",
";",
"if",
"(",
"$",
"elementOrFieldset",
"instanceof",
"PdfTextLineFieldSet",
")",
"{",
"$",
"templateMarkup",
".=",
"sprintf",
"(",
"$",
"this",
"->",
"rowWrap",
",",
"$",
"this",
"->",
"getLineType",
"(",
")",
",",
"$",
"fieldsetHelper",
"(",
"$",
"elementOrFieldset",
",",
"$",
"this",
"->",
"shouldWrap",
"(",
")",
")",
",",
"ucfirst",
"(",
"$",
"this",
"->",
"getLineType",
"(",
")",
")",
")",
";",
"}",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getTemplateWrapper",
"(",
")",
",",
"$",
"this",
"->",
"getLineType",
"(",
")",
",",
"$",
"escapeHtmlAttribHelper",
"(",
"$",
"templateMarkup",
")",
")",
";",
"}"
]
| Only render a template
@param Collection $collection
@return string | [
"Only",
"render",
"a",
"template"
]
| train | https://github.com/uthando-cms/uthando-dompdf/blob/60a750058c2db9ed167476192b20c7f544c32007/src/UthandoDomPdf/Form/View/Helper/PdfTextLineFormCollection.php#L129-L152 |
ClanCats/Core | src/classes/CCFinder.php | CCFinder.bundle | public static function bundle( $name, $path = null )
{
static::$bundles[$name] = $path;
static::$namespaces[$name] = $path.CCDIR_CLASS;
} | php | public static function bundle( $name, $path = null )
{
static::$bundles[$name] = $path;
static::$namespaces[$name] = $path.CCDIR_CLASS;
} | [
"public",
"static",
"function",
"bundle",
"(",
"$",
"name",
",",
"$",
"path",
"=",
"null",
")",
"{",
"static",
"::",
"$",
"bundles",
"[",
"$",
"name",
"]",
"=",
"$",
"path",
";",
"static",
"::",
"$",
"namespaces",
"[",
"$",
"name",
"]",
"=",
"$",
"path",
".",
"CCDIR_CLASS",
";",
"}"
]
| Add a bundle
A bundle is a CCF style package with classes, controllers, views etc.
@param string|array $name
@param path $path
@return void | [
"Add",
"a",
"bundle",
"A",
"bundle",
"is",
"a",
"CCF",
"style",
"package",
"with",
"classes",
"controllers",
"views",
"etc",
"."
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFinder.php#L68-L72 |
ClanCats/Core | src/classes/CCFinder.php | CCFinder.map | public static function map( $name, $path = null )
{
if ( is_array( $name ) )
{
static::$namespaces = array_merge( static::$namespaces, $name ); return;
}
static::$namespaces[$name] = $path;
} | php | public static function map( $name, $path = null )
{
if ( is_array( $name ) )
{
static::$namespaces = array_merge( static::$namespaces, $name ); return;
}
static::$namespaces[$name] = $path;
} | [
"public",
"static",
"function",
"map",
"(",
"$",
"name",
",",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"static",
"::",
"$",
"namespaces",
"=",
"array_merge",
"(",
"static",
"::",
"$",
"namespaces",
",",
"$",
"name",
")",
";",
"return",
";",
"}",
"static",
"::",
"$",
"namespaces",
"[",
"$",
"name",
"]",
"=",
"$",
"path",
";",
"}"
]
| Add one or more maps
A map is simply a class namepsace
@param string|array $name
@param path $path
@return void | [
"Add",
"one",
"or",
"more",
"maps",
"A",
"map",
"is",
"simply",
"a",
"class",
"namepsace"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFinder.php#L82-L89 |
ClanCats/Core | src/classes/CCFinder.php | CCFinder.shadow | public static function shadow( $name, $namespace, $path = null )
{
static::$shadows[$name] = $class = $namespace."\\".$name;
if ( !is_null( $path ) )
{
static::bind( $name, $class );
}
} | php | public static function shadow( $name, $namespace, $path = null )
{
static::$shadows[$name] = $class = $namespace."\\".$name;
if ( !is_null( $path ) )
{
static::bind( $name, $class );
}
} | [
"public",
"static",
"function",
"shadow",
"(",
"$",
"name",
",",
"$",
"namespace",
",",
"$",
"path",
"=",
"null",
")",
"{",
"static",
"::",
"$",
"shadows",
"[",
"$",
"name",
"]",
"=",
"$",
"class",
"=",
"$",
"namespace",
".",
"\"\\\\\"",
".",
"$",
"name",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"path",
")",
")",
"{",
"static",
"::",
"bind",
"(",
"$",
"name",
",",
"$",
"class",
")",
";",
"}",
"}"
]
| Add a shadow class
A shadow class is a global class and gets liftet to the global namespace.
\Some\Longer\Namespace\Foo::bar() -> Foo::bar()
exmpale:
CCFinder::shadow( 'Foo', 'Some\Longer\Namespace', 'myclasses/Foo.php' );
@param string $name The shadow
@param string $namespace The real class namespace
@param string $path The path of the real class
@return void | [
"Add",
"a",
"shadow",
"class",
"A",
"shadow",
"class",
"is",
"a",
"global",
"class",
"and",
"gets",
"liftet",
"to",
"the",
"global",
"namespace",
"."
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFinder.php#L105-L113 |
ClanCats/Core | src/classes/CCFinder.php | CCFinder.alias | public static function alias( $name, $path = null )
{
if ( is_array( $name ) )
{
static::$aliases = array_merge( static::$aliases, $name ); return;
}
static::$aliases[$name] = $path;
} | php | public static function alias( $name, $path = null )
{
if ( is_array( $name ) )
{
static::$aliases = array_merge( static::$aliases, $name ); return;
}
static::$aliases[$name] = $path;
} | [
"public",
"static",
"function",
"alias",
"(",
"$",
"name",
",",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"static",
"::",
"$",
"aliases",
"=",
"array_merge",
"(",
"static",
"::",
"$",
"aliases",
",",
"$",
"name",
")",
";",
"return",
";",
"}",
"static",
"::",
"$",
"aliases",
"[",
"$",
"name",
"]",
"=",
"$",
"path",
";",
"}"
]
| Add one or more aliases
An alias can overwrite an shadow. This way we can extend other classes.
example:
CCFinder::alias( 'Foo', '/path/to/my/Foo.php' );
@param string $name
@param path $path
@return void | [
"Add",
"one",
"or",
"more",
"aliases",
"An",
"alias",
"can",
"overwrite",
"an",
"shadow",
".",
"This",
"way",
"we",
"can",
"extend",
"other",
"classes",
"."
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFinder.php#L126-L133 |
ClanCats/Core | src/classes/CCFinder.php | CCFinder.bind | public static function bind( $name, $path = null )
{
if ( is_array( $name ) )
{
static::$classes = array_merge( static::$classes, $name ); return;
}
static::$classes[$name] = $path;
} | php | public static function bind( $name, $path = null )
{
if ( is_array( $name ) )
{
static::$classes = array_merge( static::$classes, $name ); return;
}
static::$classes[$name] = $path;
} | [
"public",
"static",
"function",
"bind",
"(",
"$",
"name",
",",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"static",
"::",
"$",
"classes",
"=",
"array_merge",
"(",
"static",
"::",
"$",
"classes",
",",
"$",
"name",
")",
";",
"return",
";",
"}",
"static",
"::",
"$",
"classes",
"[",
"$",
"name",
"]",
"=",
"$",
"path",
";",
"}"
]
| Add one or more class to the autoloader
@param string $name
@param path $path
@return void | [
"Add",
"one",
"or",
"more",
"class",
"to",
"the",
"autoloader"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFinder.php#L142-L149 |
ClanCats/Core | src/classes/CCFinder.php | CCFinder.package | public static function package( $dir, $classes )
{
foreach( $classes as $name => $path )
{
static::$classes[$name] = $dir.$path;
}
} | php | public static function package( $dir, $classes )
{
foreach( $classes as $name => $path )
{
static::$classes[$name] = $dir.$path;
}
} | [
"public",
"static",
"function",
"package",
"(",
"$",
"dir",
",",
"$",
"classes",
")",
"{",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"name",
"=>",
"$",
"path",
")",
"{",
"static",
"::",
"$",
"classes",
"[",
"$",
"name",
"]",
"=",
"$",
"dir",
".",
"$",
"path",
";",
"}",
"}"
]
| This simply adds some classes with a prefix
@param string $name
@param path $path
@return void | [
"This",
"simply",
"adds",
"some",
"classes",
"with",
"a",
"prefix"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFinder.php#L159-L165 |
ClanCats/Core | src/classes/CCFinder.php | CCFinder.shadow_package | public static function shadow_package( $dir, $namespace, $shadows )
{
foreach( $shadows as $name => $path )
{
static::$shadows[$name] = $class = $namespace."\\".$name;
static::$classes[$class] = $dir.$path;
}
} | php | public static function shadow_package( $dir, $namespace, $shadows )
{
foreach( $shadows as $name => $path )
{
static::$shadows[$name] = $class = $namespace."\\".$name;
static::$classes[$class] = $dir.$path;
}
} | [
"public",
"static",
"function",
"shadow_package",
"(",
"$",
"dir",
",",
"$",
"namespace",
",",
"$",
"shadows",
")",
"{",
"foreach",
"(",
"$",
"shadows",
"as",
"$",
"name",
"=>",
"$",
"path",
")",
"{",
"static",
"::",
"$",
"shadows",
"[",
"$",
"name",
"]",
"=",
"$",
"class",
"=",
"$",
"namespace",
".",
"\"\\\\\"",
".",
"$",
"name",
";",
"static",
"::",
"$",
"classes",
"[",
"$",
"class",
"]",
"=",
"$",
"dir",
".",
"$",
"path",
";",
"}",
"}"
]
| This simply adds some shadows with a prefix
@param string $name
@param path $path
@return void | [
"This",
"simply",
"adds",
"some",
"shadows",
"with",
"a",
"prefix"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFinder.php#L175-L182 |
ClanCats/Core | src/classes/CCFinder.php | CCFinder.find | public static function find( $class )
{
if ( class_exists( $class, false ) )
{
return;
}
// class with or without namespace?
if ( strpos( $class , '\\' ) !== false )
{
/*
* alias map
*/
if ( array_key_exists( $class, static::$aliases ) )
{
require static::$aliases[$class];
}
/*
* normal map
*/
elseif ( array_key_exists( $class, static::$classes ) )
{
require static::$classes[$class];
}
/*
* try your luck without the map
*/
else
{
$namespace = substr( $class, 0, strrpos( $class, "\\" ) );
$class_name = substr( $class, strrpos( $class, "\\" )+1 );
if ( !array_key_exists( $namespace, static::$namespaces ) )
{
return false;
}
$path = static::$namespaces[$namespace].str_replace( '_', '/', $class_name ).EXT;
if ( !file_exists( $path ) )
{
return false;
}
require $path;
}
/*
* check if we need to create a shadow aka an alias
*/
if ( in_array( $class, static::$shadows ) )
{
$shadow = array_search( $class, static::$shadows );
if ( !class_exists( $shadow, false ) && !array_key_exists( $shadow, static::$aliases ) )
{
class_alias( $class, $shadow );
}
}
}
else
{
/*
* alias map
*/
if ( array_key_exists( $class, static::$aliases ) )
{
require static::$aliases[$class];
}
/*
* check shadows
*/
if ( array_key_exists( $class, static::$shadows ) )
{
return static::find( static::$shadows[$class] );
}
/*
* normal map
*/
elseif ( array_key_exists( $class, static::$classes ) )
{
require static::$classes[$class];
}
/*
* try your luck without the map
*/
else
{
$path = APPPATH.CCDIR_CLASS.str_replace( '_', '/', $class ).EXT;
if ( !file_exists( $path ) )
{
return false;
}
require $path ;
}
}
/*
* run the static init if possible
*/
if ( method_exists( $class, '_init' ) )
{
$class::_init();
}
return true;
} | php | public static function find( $class )
{
if ( class_exists( $class, false ) )
{
return;
}
// class with or without namespace?
if ( strpos( $class , '\\' ) !== false )
{
/*
* alias map
*/
if ( array_key_exists( $class, static::$aliases ) )
{
require static::$aliases[$class];
}
/*
* normal map
*/
elseif ( array_key_exists( $class, static::$classes ) )
{
require static::$classes[$class];
}
/*
* try your luck without the map
*/
else
{
$namespace = substr( $class, 0, strrpos( $class, "\\" ) );
$class_name = substr( $class, strrpos( $class, "\\" )+1 );
if ( !array_key_exists( $namespace, static::$namespaces ) )
{
return false;
}
$path = static::$namespaces[$namespace].str_replace( '_', '/', $class_name ).EXT;
if ( !file_exists( $path ) )
{
return false;
}
require $path;
}
/*
* check if we need to create a shadow aka an alias
*/
if ( in_array( $class, static::$shadows ) )
{
$shadow = array_search( $class, static::$shadows );
if ( !class_exists( $shadow, false ) && !array_key_exists( $shadow, static::$aliases ) )
{
class_alias( $class, $shadow );
}
}
}
else
{
/*
* alias map
*/
if ( array_key_exists( $class, static::$aliases ) )
{
require static::$aliases[$class];
}
/*
* check shadows
*/
if ( array_key_exists( $class, static::$shadows ) )
{
return static::find( static::$shadows[$class] );
}
/*
* normal map
*/
elseif ( array_key_exists( $class, static::$classes ) )
{
require static::$classes[$class];
}
/*
* try your luck without the map
*/
else
{
$path = APPPATH.CCDIR_CLASS.str_replace( '_', '/', $class ).EXT;
if ( !file_exists( $path ) )
{
return false;
}
require $path ;
}
}
/*
* run the static init if possible
*/
if ( method_exists( $class, '_init' ) )
{
$class::_init();
}
return true;
} | [
"public",
"static",
"function",
"find",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"class",
",",
"false",
")",
")",
"{",
"return",
";",
"}",
"// class with or without namespace?",
"if",
"(",
"strpos",
"(",
"$",
"class",
",",
"'\\\\'",
")",
"!==",
"false",
")",
"{",
"/*\n\t\t\t * alias map\n\t\t\t */",
"if",
"(",
"array_key_exists",
"(",
"$",
"class",
",",
"static",
"::",
"$",
"aliases",
")",
")",
"{",
"require",
"static",
"::",
"$",
"aliases",
"[",
"$",
"class",
"]",
";",
"}",
"/* \n\t\t\t * normal map\n\t\t\t */",
"elseif",
"(",
"array_key_exists",
"(",
"$",
"class",
",",
"static",
"::",
"$",
"classes",
")",
")",
"{",
"require",
"static",
"::",
"$",
"classes",
"[",
"$",
"class",
"]",
";",
"}",
"/*\n\t\t\t * try your luck without the map\n\t\t\t */",
"else",
"{",
"$",
"namespace",
"=",
"substr",
"(",
"$",
"class",
",",
"0",
",",
"strrpos",
"(",
"$",
"class",
",",
"\"\\\\\"",
")",
")",
";",
"$",
"class_name",
"=",
"substr",
"(",
"$",
"class",
",",
"strrpos",
"(",
"$",
"class",
",",
"\"\\\\\"",
")",
"+",
"1",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"namespace",
",",
"static",
"::",
"$",
"namespaces",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"path",
"=",
"static",
"::",
"$",
"namespaces",
"[",
"$",
"namespace",
"]",
".",
"str_replace",
"(",
"'_'",
",",
"'/'",
",",
"$",
"class_name",
")",
".",
"EXT",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"require",
"$",
"path",
";",
"}",
"/*\n\t\t\t * check if we need to create a shadow aka an alias\n\t\t\t */",
"if",
"(",
"in_array",
"(",
"$",
"class",
",",
"static",
"::",
"$",
"shadows",
")",
")",
"{",
"$",
"shadow",
"=",
"array_search",
"(",
"$",
"class",
",",
"static",
"::",
"$",
"shadows",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"shadow",
",",
"false",
")",
"&&",
"!",
"array_key_exists",
"(",
"$",
"shadow",
",",
"static",
"::",
"$",
"aliases",
")",
")",
"{",
"class_alias",
"(",
"$",
"class",
",",
"$",
"shadow",
")",
";",
"}",
"}",
"}",
"else",
"{",
"/*\n\t\t\t * alias map\n\t\t\t */",
"if",
"(",
"array_key_exists",
"(",
"$",
"class",
",",
"static",
"::",
"$",
"aliases",
")",
")",
"{",
"require",
"static",
"::",
"$",
"aliases",
"[",
"$",
"class",
"]",
";",
"}",
"/*\n\t\t\t * check shadows\n\t\t\t */",
"if",
"(",
"array_key_exists",
"(",
"$",
"class",
",",
"static",
"::",
"$",
"shadows",
")",
")",
"{",
"return",
"static",
"::",
"find",
"(",
"static",
"::",
"$",
"shadows",
"[",
"$",
"class",
"]",
")",
";",
"}",
"/* \n\t\t\t * normal map\n\t\t\t */",
"elseif",
"(",
"array_key_exists",
"(",
"$",
"class",
",",
"static",
"::",
"$",
"classes",
")",
")",
"{",
"require",
"static",
"::",
"$",
"classes",
"[",
"$",
"class",
"]",
";",
"}",
"/*\n\t\t\t * try your luck without the map\n\t\t\t */",
"else",
"{",
"$",
"path",
"=",
"APPPATH",
".",
"CCDIR_CLASS",
".",
"str_replace",
"(",
"'_'",
",",
"'/'",
",",
"$",
"class",
")",
".",
"EXT",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"require",
"$",
"path",
";",
"}",
"}",
"/*\n\t\t * run the static init if possible\n\t\t */",
"if",
"(",
"method_exists",
"(",
"$",
"class",
",",
"'_init'",
")",
")",
"{",
"$",
"class",
"::",
"_init",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Autoloading handler
@param string $class
@return bool | [
"Autoloading",
"handler"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFinder.php#L190-L298 |
aedart/laravel-helpers | src/Traits/Routing/RedirectTrait.php | RedirectTrait.getRedirect | public function getRedirect(): ?Redirector
{
if (!$this->hasRedirect()) {
$this->setRedirect($this->getDefaultRedirect());
}
return $this->redirect;
} | php | public function getRedirect(): ?Redirector
{
if (!$this->hasRedirect()) {
$this->setRedirect($this->getDefaultRedirect());
}
return $this->redirect;
} | [
"public",
"function",
"getRedirect",
"(",
")",
":",
"?",
"Redirector",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasRedirect",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setRedirect",
"(",
"$",
"this",
"->",
"getDefaultRedirect",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
";",
"}"
]
| Get redirect
If no redirect has been set, this method will
set and return a default redirect, if any such
value is available
@see getDefaultRedirect()
@return Redirector|null redirect or null if none redirect has been set | [
"Get",
"redirect"
]
| train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Routing/RedirectTrait.php#L53-L59 |
redaigbaria/oauth2 | examples/relational/Storage/RefreshTokenStorage.php | RefreshTokenStorage.get | public function get($token)
{
$result = Capsule::table('oauth_refresh_tokens')
->where('refresh_token', $token)
->get();
if (count($result) === 1) {
$token = (new RefreshTokenEntity($this->server))
->setId($result[0]['refresh_token'])
->setExpireTime($result[0]['expire_time'])
->setAccessTokenId($result[0]['access_token']);
return $token;
}
return;
} | php | public function get($token)
{
$result = Capsule::table('oauth_refresh_tokens')
->where('refresh_token', $token)
->get();
if (count($result) === 1) {
$token = (new RefreshTokenEntity($this->server))
->setId($result[0]['refresh_token'])
->setExpireTime($result[0]['expire_time'])
->setAccessTokenId($result[0]['access_token']);
return $token;
}
return;
} | [
"public",
"function",
"get",
"(",
"$",
"token",
")",
"{",
"$",
"result",
"=",
"Capsule",
"::",
"table",
"(",
"'oauth_refresh_tokens'",
")",
"->",
"where",
"(",
"'refresh_token'",
",",
"$",
"token",
")",
"->",
"get",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"result",
")",
"===",
"1",
")",
"{",
"$",
"token",
"=",
"(",
"new",
"RefreshTokenEntity",
"(",
"$",
"this",
"->",
"server",
")",
")",
"->",
"setId",
"(",
"$",
"result",
"[",
"0",
"]",
"[",
"'refresh_token'",
"]",
")",
"->",
"setExpireTime",
"(",
"$",
"result",
"[",
"0",
"]",
"[",
"'expire_time'",
"]",
")",
"->",
"setAccessTokenId",
"(",
"$",
"result",
"[",
"0",
"]",
"[",
"'access_token'",
"]",
")",
";",
"return",
"$",
"token",
";",
"}",
"return",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/examples/relational/Storage/RefreshTokenStorage.php#L15-L31 |
redaigbaria/oauth2 | examples/relational/Storage/RefreshTokenStorage.php | RefreshTokenStorage.create | public function create($token, $expireTime, $accessToken)
{
Capsule::table('oauth_refresh_tokens')
->insert([
'refresh_token' => $token,
'access_token' => $accessToken,
'expire_time' => $expireTime,
]);
} | php | public function create($token, $expireTime, $accessToken)
{
Capsule::table('oauth_refresh_tokens')
->insert([
'refresh_token' => $token,
'access_token' => $accessToken,
'expire_time' => $expireTime,
]);
} | [
"public",
"function",
"create",
"(",
"$",
"token",
",",
"$",
"expireTime",
",",
"$",
"accessToken",
")",
"{",
"Capsule",
"::",
"table",
"(",
"'oauth_refresh_tokens'",
")",
"->",
"insert",
"(",
"[",
"'refresh_token'",
"=>",
"$",
"token",
",",
"'access_token'",
"=>",
"$",
"accessToken",
",",
"'expire_time'",
"=>",
"$",
"expireTime",
",",
"]",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/examples/relational/Storage/RefreshTokenStorage.php#L36-L44 |
Double-Opt-in/php-client-api | src/Client/Commands/LogCommand.php | LogCommand.setData | public function setData($data, $key = null)
{
if (is_array($data) && $key === null) {
$this->data = $data;
return $this;
}
if ($key === null)
$key = 'data';
$this->data[$key] = $data;
return $this;
} | php | public function setData($data, $key = null)
{
if (is_array($data) && $key === null) {
$this->data = $data;
return $this;
}
if ($key === null)
$key = 'data';
$this->data[$key] = $data;
return $this;
} | [
"public",
"function",
"setData",
"(",
"$",
"data",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
"&&",
"$",
"key",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"$",
"key",
"=",
"'data'",
";",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"data",
";",
"return",
"$",
"this",
";",
"}"
]
| setting data to add for the logging action
we suggest setting an array
@param array|mixed $data
@param null $key
@return $this | [
"setting",
"data",
"to",
"add",
"for",
"the",
"logging",
"action"
]
| train | https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Client/Commands/LogCommand.php#L101-L115 |
Double-Opt-in/php-client-api | src/Client/Commands/LogCommand.php | LogCommand.body | public function body(CryptographyEngine $cryptographyEngine)
{
$body = array(
'hash' => $cryptographyEngine->hash($this->email),
'action' => $this->action,
);
if ( ! empty($this->scope))
$body['scope'] = $this->scope;
if ( ! empty($this->data))
$body['data'] = $cryptographyEngine->encrypt(json_encode($this->data), $this->email);
// add overwriting data when possible
if ( ! empty($this->ip))
$body['ip'] = $this->ip;
if ( ! empty($this->useragent))
$body['useragent'] = $this->useragent;
if ( ! empty($this->created_at))
$body['created_at'] = $this->created_at;
return json_encode($body);
} | php | public function body(CryptographyEngine $cryptographyEngine)
{
$body = array(
'hash' => $cryptographyEngine->hash($this->email),
'action' => $this->action,
);
if ( ! empty($this->scope))
$body['scope'] = $this->scope;
if ( ! empty($this->data))
$body['data'] = $cryptographyEngine->encrypt(json_encode($this->data), $this->email);
// add overwriting data when possible
if ( ! empty($this->ip))
$body['ip'] = $this->ip;
if ( ! empty($this->useragent))
$body['useragent'] = $this->useragent;
if ( ! empty($this->created_at))
$body['created_at'] = $this->created_at;
return json_encode($body);
} | [
"public",
"function",
"body",
"(",
"CryptographyEngine",
"$",
"cryptographyEngine",
")",
"{",
"$",
"body",
"=",
"array",
"(",
"'hash'",
"=>",
"$",
"cryptographyEngine",
"->",
"hash",
"(",
"$",
"this",
"->",
"email",
")",
",",
"'action'",
"=>",
"$",
"this",
"->",
"action",
",",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"scope",
")",
")",
"$",
"body",
"[",
"'scope'",
"]",
"=",
"$",
"this",
"->",
"scope",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"data",
")",
")",
"$",
"body",
"[",
"'data'",
"]",
"=",
"$",
"cryptographyEngine",
"->",
"encrypt",
"(",
"json_encode",
"(",
"$",
"this",
"->",
"data",
")",
",",
"$",
"this",
"->",
"email",
")",
";",
"// add overwriting data when possible",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"ip",
")",
")",
"$",
"body",
"[",
"'ip'",
"]",
"=",
"$",
"this",
"->",
"ip",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"useragent",
")",
")",
"$",
"body",
"[",
"'useragent'",
"]",
"=",
"$",
"this",
"->",
"useragent",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"created_at",
")",
")",
"$",
"body",
"[",
"'created_at'",
"]",
"=",
"$",
"this",
"->",
"created_at",
";",
"return",
"json_encode",
"(",
"$",
"body",
")",
";",
"}"
]
| returns the body
hash: email will be hashed before requesting the server
action: action will be transmitted in plain text
scope: optional scope will be transmitted in plain text
data: optional data will be encrypted before requesting the server
@param CryptographyEngine $cryptographyEngine
@return array|\Guzzle\Http\EntityBodyInterface|null|resource|string | [
"returns",
"the",
"body"
]
| train | https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Client/Commands/LogCommand.php#L129-L153 |
Double-Opt-in/php-client-api | src/Client/Commands/LogCommand.php | LogCommand.setIp | public function setIp($ip)
{
if (null !== $ip) {
if ( ! filter_var($ip, FILTER_VALIDATE_IP))
throw new \InvalidArgumentException('Parameter ip is not a valid ip');
}
$this->ip = $ip;
return $this;
} | php | public function setIp($ip)
{
if (null !== $ip) {
if ( ! filter_var($ip, FILTER_VALIDATE_IP))
throw new \InvalidArgumentException('Parameter ip is not a valid ip');
}
$this->ip = $ip;
return $this;
} | [
"public",
"function",
"setIp",
"(",
"$",
"ip",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"ip",
")",
"{",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"ip",
",",
"FILTER_VALIDATE_IP",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Parameter ip is not a valid ip'",
")",
";",
"}",
"$",
"this",
"->",
"ip",
"=",
"$",
"ip",
";",
"return",
"$",
"this",
";",
"}"
]
| sets ip
@param null|string $ip
@return $this
@throws \InvalidArgumentException when ip validation failed | [
"sets",
"ip"
]
| train | https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Client/Commands/LogCommand.php#L176-L186 |
Double-Opt-in/php-client-api | src/Client/Commands/LogCommand.php | LogCommand.setCreatedAt | public function setCreatedAt($created_at)
{
if (null !== $created_at) {
if ($created_at instanceof \DateTime)
$created_at = $created_at->format('Y-m-d H:i:s');
elseif ( ! strtotime($created_at))
throw new \InvalidArgumentException('Parameter created_at is not a valid date string');
}
$this->created_at = $created_at;
return $this;
} | php | public function setCreatedAt($created_at)
{
if (null !== $created_at) {
if ($created_at instanceof \DateTime)
$created_at = $created_at->format('Y-m-d H:i:s');
elseif ( ! strtotime($created_at))
throw new \InvalidArgumentException('Parameter created_at is not a valid date string');
}
$this->created_at = $created_at;
return $this;
} | [
"public",
"function",
"setCreatedAt",
"(",
"$",
"created_at",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"created_at",
")",
"{",
"if",
"(",
"$",
"created_at",
"instanceof",
"\\",
"DateTime",
")",
"$",
"created_at",
"=",
"$",
"created_at",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
";",
"elseif",
"(",
"!",
"strtotime",
"(",
"$",
"created_at",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Parameter created_at is not a valid date string'",
")",
";",
"}",
"$",
"this",
"->",
"created_at",
"=",
"$",
"created_at",
";",
"return",
"$",
"this",
";",
"}"
]
| sets created_at
@param null|string|\DateTime $created_at
@return $this
@throws \InvalidArgumentException when date validation failed | [
"sets",
"created_at"
]
| train | https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Client/Commands/LogCommand.php#L210-L222 |
titon/db | src/Titon/Db/Behavior/HierarchyBehavior.php | HierarchyBehavior.getList | public function getList($id = null, $key = null, $value = null, $spacer = ' ') {
$left = $this->getConfig('leftField');
$right = $this->getConfig('rightField');
$query = $this->getRepository()->select()->orderBy($left, 'asc');
if ($id) {
if ($parentNode = $this->getNode($id)) {
$query->where($left, 'between', [$parentNode[$left], $parentNode[$right]]);
} else {
return [];
}
}
return $this->mapList($query->all()->toArray(), $key, $value, $spacer);
} | php | public function getList($id = null, $key = null, $value = null, $spacer = ' ') {
$left = $this->getConfig('leftField');
$right = $this->getConfig('rightField');
$query = $this->getRepository()->select()->orderBy($left, 'asc');
if ($id) {
if ($parentNode = $this->getNode($id)) {
$query->where($left, 'between', [$parentNode[$left], $parentNode[$right]]);
} else {
return [];
}
}
return $this->mapList($query->all()->toArray(), $key, $value, $spacer);
} | [
"public",
"function",
"getList",
"(",
"$",
"id",
"=",
"null",
",",
"$",
"key",
"=",
"null",
",",
"$",
"value",
"=",
"null",
",",
"$",
"spacer",
"=",
"' '",
")",
"{",
"$",
"left",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'leftField'",
")",
";",
"$",
"right",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'rightField'",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"select",
"(",
")",
"->",
"orderBy",
"(",
"$",
"left",
",",
"'asc'",
")",
";",
"if",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"parentNode",
"=",
"$",
"this",
"->",
"getNode",
"(",
"$",
"id",
")",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"left",
",",
"'between'",
",",
"[",
"$",
"parentNode",
"[",
"$",
"left",
"]",
",",
"$",
"parentNode",
"[",
"$",
"right",
"]",
"]",
")",
";",
"}",
"else",
"{",
"return",
"[",
"]",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"mapList",
"(",
"$",
"query",
"->",
"all",
"(",
")",
"->",
"toArray",
"(",
")",
",",
"$",
"key",
",",
"$",
"value",
",",
"$",
"spacer",
")",
";",
"}"
]
| Return a list of nodes indented to indicate tree level.
The $key and $value will be used to extract values from the node.
If no ID is provided, the top level root will be used.
@param int $id
@param string $key
@param string $value
@param string $spacer
@return array | [
"Return",
"a",
"list",
"of",
"nodes",
"indented",
"to",
"indicate",
"tree",
"level",
".",
"The",
"$key",
"and",
"$value",
"will",
"be",
"used",
"to",
"extract",
"values",
"from",
"the",
"node",
".",
"If",
"no",
"ID",
"is",
"provided",
"the",
"top",
"level",
"root",
"will",
"be",
"used",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Behavior/HierarchyBehavior.php#L95-L110 |
titon/db | src/Titon/Db/Behavior/HierarchyBehavior.php | HierarchyBehavior.getNode | public function getNode($id, $withParent = false) {
$repo = $this->getRepository();
$pk = $repo->getPrimaryKey();
$query = $repo->select();
if ($withParent) {
$query
->where($repo->getAlias() . '.' . $pk, $id)
->leftJoin(
[$repo->getTable(), 'Parent'],
array_keys($repo->getSchema()->getColumns()), // We need the fields or joins fail
[$this->getConfig('parentField') => 'Parent.' . $pk]
);
} else {
$query->where($pk, $id);
}
return $query->first();
} | php | public function getNode($id, $withParent = false) {
$repo = $this->getRepository();
$pk = $repo->getPrimaryKey();
$query = $repo->select();
if ($withParent) {
$query
->where($repo->getAlias() . '.' . $pk, $id)
->leftJoin(
[$repo->getTable(), 'Parent'],
array_keys($repo->getSchema()->getColumns()), // We need the fields or joins fail
[$this->getConfig('parentField') => 'Parent.' . $pk]
);
} else {
$query->where($pk, $id);
}
return $query->first();
} | [
"public",
"function",
"getNode",
"(",
"$",
"id",
",",
"$",
"withParent",
"=",
"false",
")",
"{",
"$",
"repo",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
";",
"$",
"pk",
"=",
"$",
"repo",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"query",
"=",
"$",
"repo",
"->",
"select",
"(",
")",
";",
"if",
"(",
"$",
"withParent",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"repo",
"->",
"getAlias",
"(",
")",
".",
"'.'",
".",
"$",
"pk",
",",
"$",
"id",
")",
"->",
"leftJoin",
"(",
"[",
"$",
"repo",
"->",
"getTable",
"(",
")",
",",
"'Parent'",
"]",
",",
"array_keys",
"(",
"$",
"repo",
"->",
"getSchema",
"(",
")",
"->",
"getColumns",
"(",
")",
")",
",",
"// We need the fields or joins fail",
"[",
"$",
"this",
"->",
"getConfig",
"(",
"'parentField'",
")",
"=>",
"'Parent.'",
".",
"$",
"pk",
"]",
")",
";",
"}",
"else",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"pk",
",",
"$",
"id",
")",
";",
"}",
"return",
"$",
"query",
"->",
"first",
"(",
")",
";",
"}"
]
| Return a node by ID. If $withParent is true, parent data will be joined in.
@param int $id
@param bool $withParent
@return \Titon\Db\Entity | [
"Return",
"a",
"node",
"by",
"ID",
".",
"If",
"$withParent",
"is",
"true",
"parent",
"data",
"will",
"be",
"joined",
"in",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Behavior/HierarchyBehavior.php#L119-L137 |
titon/db | src/Titon/Db/Behavior/HierarchyBehavior.php | HierarchyBehavior.getPath | public function getPath($id) {
$node = $this->getNode($id);
if (!$node) {
return [];
}
$left = $this->getConfig('leftField');
$right = $this->getConfig('rightField');
return $this->getRepository()->select()
->where($left, '<', $node[$left])
->where($right, '>', $node[$right])
->orderBy($left, 'asc')
->all();
} | php | public function getPath($id) {
$node = $this->getNode($id);
if (!$node) {
return [];
}
$left = $this->getConfig('leftField');
$right = $this->getConfig('rightField');
return $this->getRepository()->select()
->where($left, '<', $node[$left])
->where($right, '>', $node[$right])
->orderBy($left, 'asc')
->all();
} | [
"public",
"function",
"getPath",
"(",
"$",
"id",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"getNode",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"node",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"left",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'leftField'",
")",
";",
"$",
"right",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'rightField'",
")",
";",
"return",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"select",
"(",
")",
"->",
"where",
"(",
"$",
"left",
",",
"'<'",
",",
"$",
"node",
"[",
"$",
"left",
"]",
")",
"->",
"where",
"(",
"$",
"right",
",",
"'>'",
",",
"$",
"node",
"[",
"$",
"right",
"]",
")",
"->",
"orderBy",
"(",
"$",
"left",
",",
"'asc'",
")",
"->",
"all",
"(",
")",
";",
"}"
]
| Return the hierarchical path to the current node.
@param int $id
@return \Titon\Db\EntityCollection | [
"Return",
"the",
"hierarchical",
"path",
"to",
"the",
"current",
"node",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Behavior/HierarchyBehavior.php#L145-L160 |
titon/db | src/Titon/Db/Behavior/HierarchyBehavior.php | HierarchyBehavior.getTree | public function getTree($id = null) {
$parent = $this->getConfig('parentField');
$left = $this->getConfig('leftField');
$right = $this->getConfig('rightField');
$query = $this->getRepository()->select()->orderBy($left, 'asc');
if ($id) {
if ($parentNode = $this->getNode($id)) {
$query->where($left, 'between', [$parentNode[$left], $parentNode[$right]]);
} else {
return [];
}
}
$nodes = $query->all();
if ($nodes->isEmpty()) {
return [];
}
$map = [];
$stack = [];
$pk = $this->getRepository()->getPrimaryKey();
foreach ($nodes as $node) {
if ($node[$parent] && $node[$pk] != $id) {
$map[$node[$parent]][] = $node;
} else {
$stack[] = $node;
}
}
$results = $this->mapTree($stack, $map);
if ($id) {
return $results[0];
}
return $results;
} | php | public function getTree($id = null) {
$parent = $this->getConfig('parentField');
$left = $this->getConfig('leftField');
$right = $this->getConfig('rightField');
$query = $this->getRepository()->select()->orderBy($left, 'asc');
if ($id) {
if ($parentNode = $this->getNode($id)) {
$query->where($left, 'between', [$parentNode[$left], $parentNode[$right]]);
} else {
return [];
}
}
$nodes = $query->all();
if ($nodes->isEmpty()) {
return [];
}
$map = [];
$stack = [];
$pk = $this->getRepository()->getPrimaryKey();
foreach ($nodes as $node) {
if ($node[$parent] && $node[$pk] != $id) {
$map[$node[$parent]][] = $node;
} else {
$stack[] = $node;
}
}
$results = $this->mapTree($stack, $map);
if ($id) {
return $results[0];
}
return $results;
} | [
"public",
"function",
"getTree",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'parentField'",
")",
";",
"$",
"left",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'leftField'",
")",
";",
"$",
"right",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'rightField'",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"select",
"(",
")",
"->",
"orderBy",
"(",
"$",
"left",
",",
"'asc'",
")",
";",
"if",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"parentNode",
"=",
"$",
"this",
"->",
"getNode",
"(",
"$",
"id",
")",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"left",
",",
"'between'",
",",
"[",
"$",
"parentNode",
"[",
"$",
"left",
"]",
",",
"$",
"parentNode",
"[",
"$",
"right",
"]",
"]",
")",
";",
"}",
"else",
"{",
"return",
"[",
"]",
";",
"}",
"}",
"$",
"nodes",
"=",
"$",
"query",
"->",
"all",
"(",
")",
";",
"if",
"(",
"$",
"nodes",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"map",
"=",
"[",
"]",
";",
"$",
"stack",
"=",
"[",
"]",
";",
"$",
"pk",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getPrimaryKey",
"(",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"[",
"$",
"parent",
"]",
"&&",
"$",
"node",
"[",
"$",
"pk",
"]",
"!=",
"$",
"id",
")",
"{",
"$",
"map",
"[",
"$",
"node",
"[",
"$",
"parent",
"]",
"]",
"[",
"]",
"=",
"$",
"node",
";",
"}",
"else",
"{",
"$",
"stack",
"[",
"]",
"=",
"$",
"node",
";",
"}",
"}",
"$",
"results",
"=",
"$",
"this",
"->",
"mapTree",
"(",
"$",
"stack",
",",
"$",
"map",
")",
";",
"if",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"results",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"results",
";",
"}"
]
| Return a tree of nested nodes. If no ID is provided, the top level root will be used.
@param int $id
@return array | [
"Return",
"a",
"tree",
"of",
"nested",
"nodes",
".",
"If",
"no",
"ID",
"is",
"provided",
"the",
"top",
"level",
"root",
"will",
"be",
"used",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Behavior/HierarchyBehavior.php#L168-L208 |
titon/db | src/Titon/Db/Behavior/HierarchyBehavior.php | HierarchyBehavior.mapList | public function mapList(array $nodes, $key, $value, $spacer) {
$tree = [];
$stack = [];
$key = $key ?: $this->getRepository()->getPrimaryKey();
$value = $value ?: $this->getRepository()->getDisplayField();
$right = $this->getConfig('rightField');
foreach ($nodes as $node) {
$count = count($stack);
while ($count && $stack[$count - 1] < $node[$right]) {
array_pop($stack);
$count--;
}
$tree[$node[$key]] = str_repeat($spacer, $count) . $node[$value];
$stack[] = $node[$right];
}
return $tree;
} | php | public function mapList(array $nodes, $key, $value, $spacer) {
$tree = [];
$stack = [];
$key = $key ?: $this->getRepository()->getPrimaryKey();
$value = $value ?: $this->getRepository()->getDisplayField();
$right = $this->getConfig('rightField');
foreach ($nodes as $node) {
$count = count($stack);
while ($count && $stack[$count - 1] < $node[$right]) {
array_pop($stack);
$count--;
}
$tree[$node[$key]] = str_repeat($spacer, $count) . $node[$value];
$stack[] = $node[$right];
}
return $tree;
} | [
"public",
"function",
"mapList",
"(",
"array",
"$",
"nodes",
",",
"$",
"key",
",",
"$",
"value",
",",
"$",
"spacer",
")",
"{",
"$",
"tree",
"=",
"[",
"]",
";",
"$",
"stack",
"=",
"[",
"]",
";",
"$",
"key",
"=",
"$",
"key",
"?",
":",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"value",
"=",
"$",
"value",
"?",
":",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getDisplayField",
"(",
")",
";",
"$",
"right",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'rightField'",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"stack",
")",
";",
"while",
"(",
"$",
"count",
"&&",
"$",
"stack",
"[",
"$",
"count",
"-",
"1",
"]",
"<",
"$",
"node",
"[",
"$",
"right",
"]",
")",
"{",
"array_pop",
"(",
"$",
"stack",
")",
";",
"$",
"count",
"--",
";",
"}",
"$",
"tree",
"[",
"$",
"node",
"[",
"$",
"key",
"]",
"]",
"=",
"str_repeat",
"(",
"$",
"spacer",
",",
"$",
"count",
")",
".",
"$",
"node",
"[",
"$",
"value",
"]",
";",
"$",
"stack",
"[",
"]",
"=",
"$",
"node",
"[",
"$",
"right",
"]",
";",
"}",
"return",
"$",
"tree",
";",
"}"
]
| Map a nested tree using the primary key and display field as the values to populate the list.
Nested lists will be prepended with a spacer to indicate indentation.
@param array $nodes
@param string $key
@param string $value
@param string $spacer
@return array | [
"Map",
"a",
"nested",
"tree",
"using",
"the",
"primary",
"key",
"and",
"display",
"field",
"as",
"the",
"values",
"to",
"populate",
"the",
"list",
".",
"Nested",
"lists",
"will",
"be",
"prepended",
"with",
"a",
"spacer",
"to",
"indicate",
"indentation",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Behavior/HierarchyBehavior.php#L220-L241 |
titon/db | src/Titon/Db/Behavior/HierarchyBehavior.php | HierarchyBehavior.mapTree | public function mapTree(array $nodes, array $mappedNodes = []) {
if (!$mappedNodes) {
return $nodes;
}
$tree = [];
$pk = $this->getRepository()->getPrimaryKey();
foreach ($nodes as $node) {
$id = $node[$pk];
if (isset($mappedNodes[$id])) {
$node[$this->getConfig('treeField') ?: 'Nodes'] = $this->mapTree($mappedNodes[$id], $mappedNodes);
}
$tree[] = $node;
}
return $tree;
} | php | public function mapTree(array $nodes, array $mappedNodes = []) {
if (!$mappedNodes) {
return $nodes;
}
$tree = [];
$pk = $this->getRepository()->getPrimaryKey();
foreach ($nodes as $node) {
$id = $node[$pk];
if (isset($mappedNodes[$id])) {
$node[$this->getConfig('treeField') ?: 'Nodes'] = $this->mapTree($mappedNodes[$id], $mappedNodes);
}
$tree[] = $node;
}
return $tree;
} | [
"public",
"function",
"mapTree",
"(",
"array",
"$",
"nodes",
",",
"array",
"$",
"mappedNodes",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"mappedNodes",
")",
"{",
"return",
"$",
"nodes",
";",
"}",
"$",
"tree",
"=",
"[",
"]",
";",
"$",
"pk",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getPrimaryKey",
"(",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"id",
"=",
"$",
"node",
"[",
"$",
"pk",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"mappedNodes",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"node",
"[",
"$",
"this",
"->",
"getConfig",
"(",
"'treeField'",
")",
"?",
":",
"'Nodes'",
"]",
"=",
"$",
"this",
"->",
"mapTree",
"(",
"$",
"mappedNodes",
"[",
"$",
"id",
"]",
",",
"$",
"mappedNodes",
")",
";",
"}",
"$",
"tree",
"[",
"]",
"=",
"$",
"node",
";",
"}",
"return",
"$",
"tree",
";",
"}"
]
| Map a nested tree of arrays using the parent node stack and the mapped nodes by parent ID.
@param array $nodes
@param array $mappedNodes
@return array | [
"Map",
"a",
"nested",
"tree",
"of",
"arrays",
"using",
"the",
"parent",
"node",
"stack",
"and",
"the",
"mapped",
"nodes",
"by",
"parent",
"ID",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Behavior/HierarchyBehavior.php#L250-L269 |
titon/db | src/Titon/Db/Behavior/HierarchyBehavior.php | HierarchyBehavior.moveDown | public function moveDown($id, $count = 1) {
$pk = $this->getRepository()->getPrimaryKey();
$node = $this->getNode($id, true);
if (!$node || empty($node['Parent']['id'])) {
return false;
}
$left = $this->getConfig('leftField');
$right = $this->getConfig('rightField');
$nodeLeft = $node[$left];
$nodeRight = $node[$right];
$inc = ($count * 2);
$newNodeLeft = $nodeLeft + $inc;
$newNodeRight = $nodeRight + $inc;
// Can't go outside of the parent
$parentRight = $node['Parent'][$right];
if ($newNodeLeft >= $parentRight) {
$newNodeLeft = $parentRight - 2;
$newNodeRight = $parentRight - 1;
}
// Exit early if the values are the same
if ($nodeLeft === $newNodeLeft) {
return true;
}
// Move following nodes up
$this->_moveNode(function(Query $query) use ($left, $right, $nodeRight, $newNodeRight) {
$query->where($left, '>', $nodeRight)->where($right, '<=', $newNodeRight);
}, [
$left => Query::expr($left, '-', 2),
$right => Query::expr($right, '-', 2)
]);
// Move node down
$this->_moveNode(function(Query $query) use ($pk, $id) {
$query->where($pk, $id);
}, [
$left => $newNodeLeft,
$right => $newNodeRight
]);
return true;
} | php | public function moveDown($id, $count = 1) {
$pk = $this->getRepository()->getPrimaryKey();
$node = $this->getNode($id, true);
if (!$node || empty($node['Parent']['id'])) {
return false;
}
$left = $this->getConfig('leftField');
$right = $this->getConfig('rightField');
$nodeLeft = $node[$left];
$nodeRight = $node[$right];
$inc = ($count * 2);
$newNodeLeft = $nodeLeft + $inc;
$newNodeRight = $nodeRight + $inc;
// Can't go outside of the parent
$parentRight = $node['Parent'][$right];
if ($newNodeLeft >= $parentRight) {
$newNodeLeft = $parentRight - 2;
$newNodeRight = $parentRight - 1;
}
// Exit early if the values are the same
if ($nodeLeft === $newNodeLeft) {
return true;
}
// Move following nodes up
$this->_moveNode(function(Query $query) use ($left, $right, $nodeRight, $newNodeRight) {
$query->where($left, '>', $nodeRight)->where($right, '<=', $newNodeRight);
}, [
$left => Query::expr($left, '-', 2),
$right => Query::expr($right, '-', 2)
]);
// Move node down
$this->_moveNode(function(Query $query) use ($pk, $id) {
$query->where($pk, $id);
}, [
$left => $newNodeLeft,
$right => $newNodeRight
]);
return true;
} | [
"public",
"function",
"moveDown",
"(",
"$",
"id",
",",
"$",
"count",
"=",
"1",
")",
"{",
"$",
"pk",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"node",
"=",
"$",
"this",
"->",
"getNode",
"(",
"$",
"id",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"node",
"||",
"empty",
"(",
"$",
"node",
"[",
"'Parent'",
"]",
"[",
"'id'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"left",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'leftField'",
")",
";",
"$",
"right",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'rightField'",
")",
";",
"$",
"nodeLeft",
"=",
"$",
"node",
"[",
"$",
"left",
"]",
";",
"$",
"nodeRight",
"=",
"$",
"node",
"[",
"$",
"right",
"]",
";",
"$",
"inc",
"=",
"(",
"$",
"count",
"*",
"2",
")",
";",
"$",
"newNodeLeft",
"=",
"$",
"nodeLeft",
"+",
"$",
"inc",
";",
"$",
"newNodeRight",
"=",
"$",
"nodeRight",
"+",
"$",
"inc",
";",
"// Can't go outside of the parent",
"$",
"parentRight",
"=",
"$",
"node",
"[",
"'Parent'",
"]",
"[",
"$",
"right",
"]",
";",
"if",
"(",
"$",
"newNodeLeft",
">=",
"$",
"parentRight",
")",
"{",
"$",
"newNodeLeft",
"=",
"$",
"parentRight",
"-",
"2",
";",
"$",
"newNodeRight",
"=",
"$",
"parentRight",
"-",
"1",
";",
"}",
"// Exit early if the values are the same",
"if",
"(",
"$",
"nodeLeft",
"===",
"$",
"newNodeLeft",
")",
"{",
"return",
"true",
";",
"}",
"// Move following nodes up",
"$",
"this",
"->",
"_moveNode",
"(",
"function",
"(",
"Query",
"$",
"query",
")",
"use",
"(",
"$",
"left",
",",
"$",
"right",
",",
"$",
"nodeRight",
",",
"$",
"newNodeRight",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"left",
",",
"'>'",
",",
"$",
"nodeRight",
")",
"->",
"where",
"(",
"$",
"right",
",",
"'<='",
",",
"$",
"newNodeRight",
")",
";",
"}",
",",
"[",
"$",
"left",
"=>",
"Query",
"::",
"expr",
"(",
"$",
"left",
",",
"'-'",
",",
"2",
")",
",",
"$",
"right",
"=>",
"Query",
"::",
"expr",
"(",
"$",
"right",
",",
"'-'",
",",
"2",
")",
"]",
")",
";",
"// Move node down",
"$",
"this",
"->",
"_moveNode",
"(",
"function",
"(",
"Query",
"$",
"query",
")",
"use",
"(",
"$",
"pk",
",",
"$",
"id",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"pk",
",",
"$",
"id",
")",
";",
"}",
",",
"[",
"$",
"left",
"=>",
"$",
"newNodeLeft",
",",
"$",
"right",
"=>",
"$",
"newNodeRight",
"]",
")",
";",
"return",
"true",
";",
"}"
]
| Move a child node down in the list and move up neighboring nodes.
If the node does not have a parent (is a root node), this method will not work.
@param int $id
@param int $count
@return bool | [
"Move",
"a",
"child",
"node",
"down",
"in",
"the",
"list",
"and",
"move",
"up",
"neighboring",
"nodes",
".",
"If",
"the",
"node",
"does",
"not",
"have",
"a",
"parent",
"(",
"is",
"a",
"root",
"node",
")",
"this",
"method",
"will",
"not",
"work",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Behavior/HierarchyBehavior.php#L279-L326 |
titon/db | src/Titon/Db/Behavior/HierarchyBehavior.php | HierarchyBehavior.moveTo | public function moveTo($id, $parent_id) {
$pk = $this->getRepository()->getPrimaryKey();
$node = $this->getNode($id);
if (!$node || $node[$this->getConfig('parentField')] == $parent_id) {
return false;
}
$left = $this->getConfig('leftField');
$right = $this->getConfig('rightField');
$data = [];
// Remove the node and reset others
$this->_removeNode($id, $node[$left]);
// Insert into parent
if ($parent_id && ($parentNode = $this->getNode($parent_id))) {
$data = [
$left => $parentNode[$right],
$right => $parentNode[$right] + 1
];
// Or the root
} else if ($lastNode = $this->getLastNode()) {
$data = [
$left => $lastNode[$right] + 1,
$right => $lastNode[$right] + 2
];
}
// Move it
$this->_moveNode(function(Query $query) use ($pk, $id) {
$query->where($pk, $id);
}, $data + [
$this->getConfig('parentField') => $parent_id
]);
$this->_insertNode($id, $data[$left]);
return true;
} | php | public function moveTo($id, $parent_id) {
$pk = $this->getRepository()->getPrimaryKey();
$node = $this->getNode($id);
if (!$node || $node[$this->getConfig('parentField')] == $parent_id) {
return false;
}
$left = $this->getConfig('leftField');
$right = $this->getConfig('rightField');
$data = [];
// Remove the node and reset others
$this->_removeNode($id, $node[$left]);
// Insert into parent
if ($parent_id && ($parentNode = $this->getNode($parent_id))) {
$data = [
$left => $parentNode[$right],
$right => $parentNode[$right] + 1
];
// Or the root
} else if ($lastNode = $this->getLastNode()) {
$data = [
$left => $lastNode[$right] + 1,
$right => $lastNode[$right] + 2
];
}
// Move it
$this->_moveNode(function(Query $query) use ($pk, $id) {
$query->where($pk, $id);
}, $data + [
$this->getConfig('parentField') => $parent_id
]);
$this->_insertNode($id, $data[$left]);
return true;
} | [
"public",
"function",
"moveTo",
"(",
"$",
"id",
",",
"$",
"parent_id",
")",
"{",
"$",
"pk",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"node",
"=",
"$",
"this",
"->",
"getNode",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"node",
"||",
"$",
"node",
"[",
"$",
"this",
"->",
"getConfig",
"(",
"'parentField'",
")",
"]",
"==",
"$",
"parent_id",
")",
"{",
"return",
"false",
";",
"}",
"$",
"left",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'leftField'",
")",
";",
"$",
"right",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'rightField'",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"// Remove the node and reset others",
"$",
"this",
"->",
"_removeNode",
"(",
"$",
"id",
",",
"$",
"node",
"[",
"$",
"left",
"]",
")",
";",
"// Insert into parent",
"if",
"(",
"$",
"parent_id",
"&&",
"(",
"$",
"parentNode",
"=",
"$",
"this",
"->",
"getNode",
"(",
"$",
"parent_id",
")",
")",
")",
"{",
"$",
"data",
"=",
"[",
"$",
"left",
"=>",
"$",
"parentNode",
"[",
"$",
"right",
"]",
",",
"$",
"right",
"=>",
"$",
"parentNode",
"[",
"$",
"right",
"]",
"+",
"1",
"]",
";",
"// Or the root",
"}",
"else",
"if",
"(",
"$",
"lastNode",
"=",
"$",
"this",
"->",
"getLastNode",
"(",
")",
")",
"{",
"$",
"data",
"=",
"[",
"$",
"left",
"=>",
"$",
"lastNode",
"[",
"$",
"right",
"]",
"+",
"1",
",",
"$",
"right",
"=>",
"$",
"lastNode",
"[",
"$",
"right",
"]",
"+",
"2",
"]",
";",
"}",
"// Move it",
"$",
"this",
"->",
"_moveNode",
"(",
"function",
"(",
"Query",
"$",
"query",
")",
"use",
"(",
"$",
"pk",
",",
"$",
"id",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"pk",
",",
"$",
"id",
")",
";",
"}",
",",
"$",
"data",
"+",
"[",
"$",
"this",
"->",
"getConfig",
"(",
"'parentField'",
")",
"=>",
"$",
"parent_id",
"]",
")",
";",
"$",
"this",
"->",
"_insertNode",
"(",
"$",
"id",
",",
"$",
"data",
"[",
"$",
"left",
"]",
")",
";",
"return",
"true",
";",
"}"
]
| Move a node between parents and the root. This will re-order the tree accordingly.
If $parent_id is null, the node will be moved to the root.
@param int $id
@param int $parent_id
@return bool | [
"Move",
"a",
"node",
"between",
"parents",
"and",
"the",
"root",
".",
"This",
"will",
"re",
"-",
"order",
"the",
"tree",
"accordingly",
".",
"If",
"$parent_id",
"is",
"null",
"the",
"node",
"will",
"be",
"moved",
"to",
"the",
"root",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Behavior/HierarchyBehavior.php#L393-L433 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.