repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Loader/Bridge/Doctrine/DoctrineLoaderTrait.php | DoctrineLoaderTrait.toEntityCollection | protected function toEntityCollection($result)
{
switch (true) {
// already a collection ?
case is_object($result) && is_subclass_of($result, $this->collectionClass) :
$collection = $result;
break;
// already a collection ?
case $result instanceof Collection :
$collection = new $this->collectionClass($result->toArray());
break;
// simple related entity ?
case is_object($result) && is_subclass_of($result, $this->entityClass) :
$collection = new $this->collectionClass(array($result));
break;
// simple array ?
case is_array($result) :
$collection = new $this->collectionClass($result);
break;
default:
$collection = new $this->collectionClass();
break;
}
if (is_callable(array($this, 'onLoad'))) {
@trigger_error(
sprintf('%s::onLoad() call is deprecated and will be removed in 2.0. Make "%s" invokable instead if you require to custom every "%s" loaded by ORM.',
static::class,
static::class,
$this->entityClass
),
E_USER_DEPRECATED
);
return $this->onLoad($collection);
}
return $collection;
} | php | protected function toEntityCollection($result)
{
switch (true) {
// already a collection ?
case is_object($result) && is_subclass_of($result, $this->collectionClass) :
$collection = $result;
break;
// already a collection ?
case $result instanceof Collection :
$collection = new $this->collectionClass($result->toArray());
break;
// simple related entity ?
case is_object($result) && is_subclass_of($result, $this->entityClass) :
$collection = new $this->collectionClass(array($result));
break;
// simple array ?
case is_array($result) :
$collection = new $this->collectionClass($result);
break;
default:
$collection = new $this->collectionClass();
break;
}
if (is_callable(array($this, 'onLoad'))) {
@trigger_error(
sprintf('%s::onLoad() call is deprecated and will be removed in 2.0. Make "%s" invokable instead if you require to custom every "%s" loaded by ORM.',
static::class,
static::class,
$this->entityClass
),
E_USER_DEPRECATED
);
return $this->onLoad($collection);
}
return $collection;
} | [
"protected",
"function",
"toEntityCollection",
"(",
"$",
"result",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"// already a collection ?",
"case",
"is_object",
"(",
"$",
"result",
")",
"&&",
"is_subclass_of",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"collectionClass",
")",
":",
"$",
"collection",
"=",
"$",
"result",
";",
"break",
";",
"// already a collection ?",
"case",
"$",
"result",
"instanceof",
"Collection",
":",
"$",
"collection",
"=",
"new",
"$",
"this",
"->",
"collectionClass",
"(",
"$",
"result",
"->",
"toArray",
"(",
")",
")",
";",
"break",
";",
"// simple related entity ?",
"case",
"is_object",
"(",
"$",
"result",
")",
"&&",
"is_subclass_of",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"entityClass",
")",
":",
"$",
"collection",
"=",
"new",
"$",
"this",
"->",
"collectionClass",
"(",
"array",
"(",
"$",
"result",
")",
")",
";",
"break",
";",
"// simple array ?",
"case",
"is_array",
"(",
"$",
"result",
")",
":",
"$",
"collection",
"=",
"new",
"$",
"this",
"->",
"collectionClass",
"(",
"$",
"result",
")",
";",
"break",
";",
"default",
":",
"$",
"collection",
"=",
"new",
"$",
"this",
"->",
"collectionClass",
"(",
")",
";",
"break",
";",
"}",
"if",
"(",
"is_callable",
"(",
"array",
"(",
"$",
"this",
",",
"'onLoad'",
")",
")",
")",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'%s::onLoad() call is deprecated and will be removed in 2.0. Make \"%s\" invokable instead if you require to custom every \"%s\" loaded by ORM.'",
",",
"static",
"::",
"class",
",",
"static",
"::",
"class",
",",
"$",
"this",
"->",
"entityClass",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"return",
"$",
"this",
"->",
"onLoad",
"(",
"$",
"collection",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
] | Convert given array or Collection result set to managed entity collection class.
@param array|Collection $result
@return EntityCollection | [
"Convert",
"given",
"array",
"or",
"Collection",
"result",
"set",
"to",
"managed",
"entity",
"collection",
"class",
"."
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Loader/Bridge/Doctrine/DoctrineLoaderTrait.php#L59-L102 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Loader/Bridge/Doctrine/DoctrineLoaderTrait.php | DoctrineLoaderTrait.createFilteredQuery | private function createFilteredQuery(array $filters)
{
$qb = $this->createQuery('entity');
foreach ($filters as $field => $filter) {
$qb->andWhere(is_array($filter)
? sprintf('entity.%s in (:%s)', $field, $field)
: sprintf('entity.%s = :%s', $field, $field)
)
->setParameter(sprintf(':%s', $field), $filter)
;
}
return $qb->getQuery();
} | php | private function createFilteredQuery(array $filters)
{
$qb = $this->createQuery('entity');
foreach ($filters as $field => $filter) {
$qb->andWhere(is_array($filter)
? sprintf('entity.%s in (:%s)', $field, $field)
: sprintf('entity.%s = :%s', $field, $field)
)
->setParameter(sprintf(':%s', $field), $filter)
;
}
return $qb->getQuery();
} | [
"private",
"function",
"createFilteredQuery",
"(",
"array",
"$",
"filters",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQuery",
"(",
"'entity'",
")",
";",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"field",
"=>",
"$",
"filter",
")",
"{",
"$",
"qb",
"->",
"andWhere",
"(",
"is_array",
"(",
"$",
"filter",
")",
"?",
"sprintf",
"(",
"'entity.%s in (:%s)'",
",",
"$",
"field",
",",
"$",
"field",
")",
":",
"sprintf",
"(",
"'entity.%s = :%s'",
",",
"$",
"field",
",",
"$",
"field",
")",
")",
"->",
"setParameter",
"(",
"sprintf",
"(",
"':%s'",
",",
"$",
"field",
")",
",",
"$",
"filter",
")",
";",
"}",
"return",
"$",
"qb",
"->",
"getQuery",
"(",
")",
";",
"}"
] | create query an filter it with given data.
@param array $filters
@return Query | [
"create",
"query",
"an",
"filter",
"it",
"with",
"given",
"data",
"."
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Loader/Bridge/Doctrine/DoctrineLoaderTrait.php#L126-L140 | train |
codemojo-dr/startkit-php-sdk | src/CodeMojo/OAuth2/GrantType/Password.php | Password.validateParameters | public function validateParameters(&$parameters)
{
if (!isset($parameters['username']))
{
throw new InvalidArgumentException(
'The \'username\' parameter must be defined for the Password grant type',
InvalidArgumentException::MISSING_PARAMETER
);
}
elseif (!isset($parameters['password']))
{
throw new InvalidArgumentException(
'The \'password\' parameter must be defined for the Password grant type',
InvalidArgumentException::MISSING_PARAMETER
);
}
} | php | public function validateParameters(&$parameters)
{
if (!isset($parameters['username']))
{
throw new InvalidArgumentException(
'The \'username\' parameter must be defined for the Password grant type',
InvalidArgumentException::MISSING_PARAMETER
);
}
elseif (!isset($parameters['password']))
{
throw new InvalidArgumentException(
'The \'password\' parameter must be defined for the Password grant type',
InvalidArgumentException::MISSING_PARAMETER
);
}
} | [
"public",
"function",
"validateParameters",
"(",
"&",
"$",
"parameters",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"parameters",
"[",
"'username'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The \\'username\\' parameter must be defined for the Password grant type'",
",",
"InvalidArgumentException",
"::",
"MISSING_PARAMETER",
")",
";",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"parameters",
"[",
"'password'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The \\'password\\' parameter must be defined for the Password grant type'",
",",
"InvalidArgumentException",
"::",
"MISSING_PARAMETER",
")",
";",
"}",
"}"
] | Adds a specific Handling of the parameters
@return array of Specific parameters to be sent.
@param mixed $parameters the parameters array (passed by reference) | [
"Adds",
"a",
"specific",
"Handling",
"of",
"the",
"parameters"
] | cd2227e1a221be2cd75dc96d1c9e0acfda936fb3 | https://github.com/codemojo-dr/startkit-php-sdk/blob/cd2227e1a221be2cd75dc96d1c9e0acfda936fb3/src/CodeMojo/OAuth2/GrantType/Password.php#L24-L40 | train |
dmt-software/auth-middleware | src/Authorization/BasicAuthorization.php | BasicAuthorization.handle | public function handle(RequestInterface $request): RequestInterface
{
return
$request->withHeader(
'Authorization',
sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->user, $this->password)))
);
} | php | public function handle(RequestInterface $request): RequestInterface
{
return
$request->withHeader(
'Authorization',
sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->user, $this->password)))
);
} | [
"public",
"function",
"handle",
"(",
"RequestInterface",
"$",
"request",
")",
":",
"RequestInterface",
"{",
"return",
"$",
"request",
"->",
"withHeader",
"(",
"'Authorization'",
",",
"sprintf",
"(",
"'Basic %s'",
",",
"base64_encode",
"(",
"sprintf",
"(",
"'%s:%s'",
",",
"$",
"this",
"->",
"user",
",",
"$",
"this",
"->",
"password",
")",
")",
")",
")",
";",
"}"
] | Get the http headers associated with the authorization.
@param RequestInterface $request
@return RequestInterface | [
"Get",
"the",
"http",
"headers",
"associated",
"with",
"the",
"authorization",
"."
] | 7a4633224944567c1e2ce63189f40a69acf221a6 | https://github.com/dmt-software/auth-middleware/blob/7a4633224944567c1e2ce63189f40a69acf221a6/src/Authorization/BasicAuthorization.php#L43-L50 | train |
DanweDE/php-bitcoin-address | src/Address.php | Address.equals | function equals( $other ) {
if( ! ( $other instanceof Address ) ) {
return false;
}
return $this === $other
|| $this->asString() === $other->asString();
} | php | function equals( $other ) {
if( ! ( $other instanceof Address ) ) {
return false;
}
return $this === $other
|| $this->asString() === $other->asString();
} | [
"function",
"equals",
"(",
"$",
"other",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"other",
"instanceof",
"Address",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"===",
"$",
"other",
"||",
"$",
"this",
"->",
"asString",
"(",
")",
"===",
"$",
"other",
"->",
"asString",
"(",
")",
";",
"}"
] | Returns whether the address is equal to another given address.
@return bool | [
"Returns",
"whether",
"the",
"address",
"is",
"equal",
"to",
"another",
"given",
"address",
"."
] | 89d717e572086e1cb80e2c4021ef1ec407044a5c | https://github.com/DanweDE/php-bitcoin-address/blob/89d717e572086e1cb80e2c4021ef1ec407044a5c/src/Address.php#L46-L52 | train |
SchulIT/common-bundle | Helper/DateHelper.php | DateHelper.getStartDate | public function getStartDate() {
$now = $this->getNow();
$endOfDay = $this->getToday()->modify('+18 hours');
$currentDay = $this->getToday();
if($now > $endOfDay) {
$currentDay->modify('+1 day');
}
return $currentDay;
} | php | public function getStartDate() {
$now = $this->getNow();
$endOfDay = $this->getToday()->modify('+18 hours');
$currentDay = $this->getToday();
if($now > $endOfDay) {
$currentDay->modify('+1 day');
}
return $currentDay;
} | [
"public",
"function",
"getStartDate",
"(",
")",
"{",
"$",
"now",
"=",
"$",
"this",
"->",
"getNow",
"(",
")",
";",
"$",
"endOfDay",
"=",
"$",
"this",
"->",
"getToday",
"(",
")",
"->",
"modify",
"(",
"'+18 hours'",
")",
";",
"$",
"currentDay",
"=",
"$",
"this",
"->",
"getToday",
"(",
")",
";",
"if",
"(",
"$",
"now",
">",
"$",
"endOfDay",
")",
"{",
"$",
"currentDay",
"->",
"modify",
"(",
"'+1 day'",
")",
";",
"}",
"return",
"$",
"currentDay",
";",
"}"
] | Gets the start date for the timeline
@return \DateTime | [
"Gets",
"the",
"start",
"date",
"for",
"the",
"timeline"
] | ebd4007bce43796be4c8566467f41963262eabfe | https://github.com/SchulIT/common-bundle/blob/ebd4007bce43796be4c8566467f41963262eabfe/Helper/DateHelper.php#L55-L66 | train |
SchulIT/common-bundle | Helper/DateHelper.php | DateHelper.isBetween | public function isBetween(\DateTime $dateTime, \DateTime $start, \DateTime $end) {
return $dateTime >= $start && $dateTime <= $end;
} | php | public function isBetween(\DateTime $dateTime, \DateTime $start, \DateTime $end) {
return $dateTime >= $start && $dateTime <= $end;
} | [
"public",
"function",
"isBetween",
"(",
"\\",
"DateTime",
"$",
"dateTime",
",",
"\\",
"DateTime",
"$",
"start",
",",
"\\",
"DateTime",
"$",
"end",
")",
"{",
"return",
"$",
"dateTime",
">=",
"$",
"start",
"&&",
"$",
"dateTime",
"<=",
"$",
"end",
";",
"}"
] | Checks if a given date is beween a given start and end date
@param \DateTime $dateTime
@param \DateTime $start
@param \DateTime $end
@return bool | [
"Checks",
"if",
"a",
"given",
"date",
"is",
"beween",
"a",
"given",
"start",
"and",
"end",
"date"
] | ebd4007bce43796be4c8566467f41963262eabfe | https://github.com/SchulIT/common-bundle/blob/ebd4007bce43796be4c8566467f41963262eabfe/Helper/DateHelper.php#L104-L106 | train |
mmethner/engine | src/Base/Controller/Controller.php | Controller.http404Action | public function http404Action(): void
{
$header = Http::status(404);
$this->view->header($header);
$this->view->snippet('Base::error/http-404.phtml');
$this->view->assign('message', $header);
} | php | public function http404Action(): void
{
$header = Http::status(404);
$this->view->header($header);
$this->view->snippet('Base::error/http-404.phtml');
$this->view->assign('message', $header);
} | [
"public",
"function",
"http404Action",
"(",
")",
":",
"void",
"{",
"$",
"header",
"=",
"Http",
"::",
"status",
"(",
"404",
")",
";",
"$",
"this",
"->",
"view",
"->",
"header",
"(",
"$",
"header",
")",
";",
"$",
"this",
"->",
"view",
"->",
"snippet",
"(",
"'Base::error/http-404.phtml'",
")",
";",
"$",
"this",
"->",
"view",
"->",
"assign",
"(",
"'message'",
",",
"$",
"header",
")",
";",
"}"
] | default action for unknown pages
@return void | [
"default",
"action",
"for",
"unknown",
"pages"
] | 89e1bcc644cf8cc3712a67ef1697da2ca4008f74 | https://github.com/mmethner/engine/blob/89e1bcc644cf8cc3712a67ef1697da2ca4008f74/src/Base/Controller/Controller.php#L37-L43 | train |
rawphp/RawDateTime | src/RawPHP/RawDateTime/DateTime.php | DateTime.getUtcDateTime | public static function getUtcDateTime( BaseDateTime $date )
{
$newDate = new BaseDateTime( );
$newDate->setTimestamp( $date->getTimestamp() );
$newDate->setTimezone( new DateTimeZone( 'UTC' ) );
return $newDate;
} | php | public static function getUtcDateTime( BaseDateTime $date )
{
$newDate = new BaseDateTime( );
$newDate->setTimestamp( $date->getTimestamp() );
$newDate->setTimezone( new DateTimeZone( 'UTC' ) );
return $newDate;
} | [
"public",
"static",
"function",
"getUtcDateTime",
"(",
"BaseDateTime",
"$",
"date",
")",
"{",
"$",
"newDate",
"=",
"new",
"BaseDateTime",
"(",
")",
";",
"$",
"newDate",
"->",
"setTimestamp",
"(",
"$",
"date",
"->",
"getTimestamp",
"(",
")",
")",
";",
"$",
"newDate",
"->",
"setTimezone",
"(",
"new",
"DateTimeZone",
"(",
"'UTC'",
")",
")",
";",
"return",
"$",
"newDate",
";",
"}"
] | Converts the current date time object to UTC time.
@param BaseDateTime $date the date time object to convert
@return BaseDateTime the UTC date time object | [
"Converts",
"the",
"current",
"date",
"time",
"object",
"to",
"UTC",
"time",
"."
] | 0ea19738c859a211369a663bb7bd3daab7af4a48 | https://github.com/rawphp/RawDateTime/blob/0ea19738c859a211369a663bb7bd3daab7af4a48/src/RawPHP/RawDateTime/DateTime.php#L61-L68 | train |
rawphp/RawDateTime | src/RawPHP/RawDateTime/DateTime.php | DateTime.getUserDateTime | public static function getUserDateTime( BaseDateTime $date, $timezone = '' )
{
$newDate = new BaseDateTime( );
$newDate->setTimestamp( $date->getTimestamp() );
if ( is_string( $timezone ) && !empty( $timezone ) )
{
$timezone = new DateTimeZone( $timezone );
}
if ( empty( $timezone ) )
{
$timezone = new DateTimeZone( ini_get( 'date.timezone' ) );
}
$newDate->setTimezone( $timezone );
return $newDate;
} | php | public static function getUserDateTime( BaseDateTime $date, $timezone = '' )
{
$newDate = new BaseDateTime( );
$newDate->setTimestamp( $date->getTimestamp() );
if ( is_string( $timezone ) && !empty( $timezone ) )
{
$timezone = new DateTimeZone( $timezone );
}
if ( empty( $timezone ) )
{
$timezone = new DateTimeZone( ini_get( 'date.timezone' ) );
}
$newDate->setTimezone( $timezone );
return $newDate;
} | [
"public",
"static",
"function",
"getUserDateTime",
"(",
"BaseDateTime",
"$",
"date",
",",
"$",
"timezone",
"=",
"''",
")",
"{",
"$",
"newDate",
"=",
"new",
"BaseDateTime",
"(",
")",
";",
"$",
"newDate",
"->",
"setTimestamp",
"(",
"$",
"date",
"->",
"getTimestamp",
"(",
")",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"timezone",
")",
"&&",
"!",
"empty",
"(",
"$",
"timezone",
")",
")",
"{",
"$",
"timezone",
"=",
"new",
"DateTimeZone",
"(",
"$",
"timezone",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"timezone",
")",
")",
"{",
"$",
"timezone",
"=",
"new",
"DateTimeZone",
"(",
"ini_get",
"(",
"'date.timezone'",
")",
")",
";",
"}",
"$",
"newDate",
"->",
"setTimezone",
"(",
"$",
"timezone",
")",
";",
"return",
"$",
"newDate",
";",
"}"
] | Converts the UTC date time object to user time.
@param BaseDateTime $date the date time to convert
@param string $timezone the time zone
@return BaseDateTime the user timezone date time object | [
"Converts",
"the",
"UTC",
"date",
"time",
"object",
"to",
"user",
"time",
"."
] | 0ea19738c859a211369a663bb7bd3daab7af4a48 | https://github.com/rawphp/RawDateTime/blob/0ea19738c859a211369a663bb7bd3daab7af4a48/src/RawPHP/RawDateTime/DateTime.php#L78-L95 | train |
rawphp/RawDateTime | src/RawPHP/RawDateTime/DateTime.php | DateTime.getSpan | public static function getSpan( BaseDateTime $date1, BaseDateTime $date2,
$type = self::SPAN_HOURS, $absolute = TRUE
)
{
$diff = $date1->diff( $date2, $absolute );
$span = 0;
switch( $type )
{
case self::SPAN_YEARS:
$span = ( int )$diff->y;
break;
case self::SPAN_MONTHS:
$span = $diff->y * 12;
$span += $diff->m;
$span = ( int )$span;
break;
case self::SPAN_WEEKS:
$span += $diff->days;
$span = ( int )( $span / 7 );
break;
case self::SPAN_DAYS:
$span = ( int )$diff->days;
break;
case self::SPAN_HOURS:
$span = ( $diff->days * 24 );
$span += $diff->h;
$span = ( int )$span;
break;
case self::SPAN_MINUTES:
$span = ( $diff->days * 24 );
$span += $diff->h;
$span = ( $span * 60 );
$span += $diff->i;
$span = ( int )$span;
break;
case self::SPAN_SECONDS:
$span = ( $diff->days * 24 );
$span += $diff->h;
$span = ( $span * 60 );
$span += $diff->i;
$span = ( int )( $span * 60 );
$span += $diff->s;
break;
default:
$span = FALSE;
break;
}
if ( FALSE === $span )
{
return $span;
}
if ( 1 == $diff->invert )
{
return ( $span * -1 );
}
return $span;
} | php | public static function getSpan( BaseDateTime $date1, BaseDateTime $date2,
$type = self::SPAN_HOURS, $absolute = TRUE
)
{
$diff = $date1->diff( $date2, $absolute );
$span = 0;
switch( $type )
{
case self::SPAN_YEARS:
$span = ( int )$diff->y;
break;
case self::SPAN_MONTHS:
$span = $diff->y * 12;
$span += $diff->m;
$span = ( int )$span;
break;
case self::SPAN_WEEKS:
$span += $diff->days;
$span = ( int )( $span / 7 );
break;
case self::SPAN_DAYS:
$span = ( int )$diff->days;
break;
case self::SPAN_HOURS:
$span = ( $diff->days * 24 );
$span += $diff->h;
$span = ( int )$span;
break;
case self::SPAN_MINUTES:
$span = ( $diff->days * 24 );
$span += $diff->h;
$span = ( $span * 60 );
$span += $diff->i;
$span = ( int )$span;
break;
case self::SPAN_SECONDS:
$span = ( $diff->days * 24 );
$span += $diff->h;
$span = ( $span * 60 );
$span += $diff->i;
$span = ( int )( $span * 60 );
$span += $diff->s;
break;
default:
$span = FALSE;
break;
}
if ( FALSE === $span )
{
return $span;
}
if ( 1 == $diff->invert )
{
return ( $span * -1 );
}
return $span;
} | [
"public",
"static",
"function",
"getSpan",
"(",
"BaseDateTime",
"$",
"date1",
",",
"BaseDateTime",
"$",
"date2",
",",
"$",
"type",
"=",
"self",
"::",
"SPAN_HOURS",
",",
"$",
"absolute",
"=",
"TRUE",
")",
"{",
"$",
"diff",
"=",
"$",
"date1",
"->",
"diff",
"(",
"$",
"date2",
",",
"$",
"absolute",
")",
";",
"$",
"span",
"=",
"0",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"self",
"::",
"SPAN_YEARS",
":",
"$",
"span",
"=",
"(",
"int",
")",
"$",
"diff",
"->",
"y",
";",
"break",
";",
"case",
"self",
"::",
"SPAN_MONTHS",
":",
"$",
"span",
"=",
"$",
"diff",
"->",
"y",
"*",
"12",
";",
"$",
"span",
"+=",
"$",
"diff",
"->",
"m",
";",
"$",
"span",
"=",
"(",
"int",
")",
"$",
"span",
";",
"break",
";",
"case",
"self",
"::",
"SPAN_WEEKS",
":",
"$",
"span",
"+=",
"$",
"diff",
"->",
"days",
";",
"$",
"span",
"=",
"(",
"int",
")",
"(",
"$",
"span",
"/",
"7",
")",
";",
"break",
";",
"case",
"self",
"::",
"SPAN_DAYS",
":",
"$",
"span",
"=",
"(",
"int",
")",
"$",
"diff",
"->",
"days",
";",
"break",
";",
"case",
"self",
"::",
"SPAN_HOURS",
":",
"$",
"span",
"=",
"(",
"$",
"diff",
"->",
"days",
"*",
"24",
")",
";",
"$",
"span",
"+=",
"$",
"diff",
"->",
"h",
";",
"$",
"span",
"=",
"(",
"int",
")",
"$",
"span",
";",
"break",
";",
"case",
"self",
"::",
"SPAN_MINUTES",
":",
"$",
"span",
"=",
"(",
"$",
"diff",
"->",
"days",
"*",
"24",
")",
";",
"$",
"span",
"+=",
"$",
"diff",
"->",
"h",
";",
"$",
"span",
"=",
"(",
"$",
"span",
"*",
"60",
")",
";",
"$",
"span",
"+=",
"$",
"diff",
"->",
"i",
";",
"$",
"span",
"=",
"(",
"int",
")",
"$",
"span",
";",
"break",
";",
"case",
"self",
"::",
"SPAN_SECONDS",
":",
"$",
"span",
"=",
"(",
"$",
"diff",
"->",
"days",
"*",
"24",
")",
";",
"$",
"span",
"+=",
"$",
"diff",
"->",
"h",
";",
"$",
"span",
"=",
"(",
"$",
"span",
"*",
"60",
")",
";",
"$",
"span",
"+=",
"$",
"diff",
"->",
"i",
";",
"$",
"span",
"=",
"(",
"int",
")",
"(",
"$",
"span",
"*",
"60",
")",
";",
"$",
"span",
"+=",
"$",
"diff",
"->",
"s",
";",
"break",
";",
"default",
":",
"$",
"span",
"=",
"FALSE",
";",
"break",
";",
"}",
"if",
"(",
"FALSE",
"===",
"$",
"span",
")",
"{",
"return",
"$",
"span",
";",
"}",
"if",
"(",
"1",
"==",
"$",
"diff",
"->",
"invert",
")",
"{",
"return",
"(",
"$",
"span",
"*",
"-",
"1",
")",
";",
"}",
"return",
"$",
"span",
";",
"}"
] | Returns the span between the two dates.
@param BaseDateTime $date1 first date
@param BaseDateTime $date2 second date
@param string $type the scale of span output
[ years, months, days, hours, minutes, seconds ]
@param bool $absolute should the output be forced to be positive
@return mixed the span between the dates or FALSE on error | [
"Returns",
"the",
"span",
"between",
"the",
"two",
"dates",
"."
] | 0ea19738c859a211369a663bb7bd3daab7af4a48 | https://github.com/rawphp/RawDateTime/blob/0ea19738c859a211369a663bb7bd3daab7af4a48/src/RawPHP/RawDateTime/DateTime.php#L108-L176 | train |
Kris-Kuiper/sFire-Framework | src/Permissions/Resources.php | Resources.setResources | public function setResources($resources) {
if(false === is_array($resources)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($resources)), E_USER_ERROR);
}
$this -> resources = $resources;
} | php | public function setResources($resources) {
if(false === is_array($resources)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($resources)), E_USER_ERROR);
}
$this -> resources = $resources;
} | [
"public",
"function",
"setResources",
"(",
"$",
"resources",
")",
"{",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"resources",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"resources",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"resources",
"=",
"$",
"resources",
";",
"}"
] | Sets the resources
@param array $resources | [
"Sets",
"the",
"resources"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Permissions/Resources.php#L25-L32 | train |
Kris-Kuiper/sFire-Framework | src/Permissions/Resources.php | Resources.hasResource | public function hasResource($resource) {
if(null !== $resource && false === is_string($resource)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($resource)), E_USER_ERROR);
}
return true === array_key_exists($resource, $this -> resources);
} | php | public function hasResource($resource) {
if(null !== $resource && false === is_string($resource)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($resource)), E_USER_ERROR);
}
return true === array_key_exists($resource, $this -> resources);
} | [
"public",
"function",
"hasResource",
"(",
"$",
"resource",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"resource",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"resource",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"resource",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"return",
"true",
"===",
"array_key_exists",
"(",
"$",
"resource",
",",
"$",
"this",
"->",
"resources",
")",
";",
"}"
] | Check if a resource exists
@param string $resource
@return boolean | [
"Check",
"if",
"a",
"resource",
"exists"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Permissions/Resources.php#L65-L72 | train |
native5/native5-sdk-client-php | src/Native5/Route/RoutingEngine.php | RoutingEngine.route | public function route()
{
global $logger;
try {
// TODO : Refactor Code :
// $url = URLParser::parse();
// $route = RouteMapper::getRoute($url['route']);
// $router = new Router();
// $router->route($route);
$urlInterpreter = new UrlInterpreter();
$command = $urlInterpreter->getCommand();
$router = new Router($command);
$logger->debug('Routing to : '.$command->getControllerName());
$router->route();
} catch (Exception $e) {
throw new RouteNotFoundException();
}
} | php | public function route()
{
global $logger;
try {
// TODO : Refactor Code :
// $url = URLParser::parse();
// $route = RouteMapper::getRoute($url['route']);
// $router = new Router();
// $router->route($route);
$urlInterpreter = new UrlInterpreter();
$command = $urlInterpreter->getCommand();
$router = new Router($command);
$logger->debug('Routing to : '.$command->getControllerName());
$router->route();
} catch (Exception $e) {
throw new RouteNotFoundException();
}
} | [
"public",
"function",
"route",
"(",
")",
"{",
"global",
"$",
"logger",
";",
"try",
"{",
"// TODO : Refactor Code :",
"// $url = URLParser::parse();",
"// $route = RouteMapper::getRoute($url['route']);",
"// $router = new Router();",
"// $router->route($route);",
"$",
"urlInterpreter",
"=",
"new",
"UrlInterpreter",
"(",
")",
";",
"$",
"command",
"=",
"$",
"urlInterpreter",
"->",
"getCommand",
"(",
")",
";",
"$",
"router",
"=",
"new",
"Router",
"(",
"$",
"command",
")",
";",
"$",
"logger",
"->",
"debug",
"(",
"'Routing to : '",
".",
"$",
"command",
"->",
"getControllerName",
"(",
")",
")",
";",
"$",
"router",
"->",
"route",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"RouteNotFoundException",
"(",
")",
";",
"}",
"}"
] | route Handles incoming requests.
@access public
@return void | [
"route",
"Handles",
"incoming",
"requests",
"."
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Route/RoutingEngine.php#L49-L66 | train |
codeinchq/media-types | src/MediaTypes.php | MediaTypes.getExtensionMediaType | public static function getExtensionMediaType(string $extension, ?string $defaultMediaType = null):?string
{
return self::getMediaTypes()[strtolower($extension)] ?? $defaultMediaType;
} | php | public static function getExtensionMediaType(string $extension, ?string $defaultMediaType = null):?string
{
return self::getMediaTypes()[strtolower($extension)] ?? $defaultMediaType;
} | [
"public",
"static",
"function",
"getExtensionMediaType",
"(",
"string",
"$",
"extension",
",",
"?",
"string",
"$",
"defaultMediaType",
"=",
"null",
")",
":",
"?",
"string",
"{",
"return",
"self",
"::",
"getMediaTypes",
"(",
")",
"[",
"strtolower",
"(",
"$",
"extension",
")",
"]",
"??",
"$",
"defaultMediaType",
";",
"}"
] | Returns the media type for a given extension.
@param string $extension File type
@param null|string $defaultMediaType Media type returned if the file's media type can not determined
@return null|string
@throws MediaTypesException | [
"Returns",
"the",
"media",
"type",
"for",
"a",
"given",
"extension",
"."
] | 923b4491f3a626ebb01217fae3b0e8bf77ce4b3f | https://github.com/codeinchq/media-types/blob/923b4491f3a626ebb01217fae3b0e8bf77ce4b3f/src/MediaTypes.php#L74-L77 | train |
codeinchq/media-types | src/MediaTypes.php | MediaTypes.getFilenameMediaType | public static function getFilenameMediaType(string $filename, ?string $defaultMediaType = null):?string
{
if (preg_match('|\\.([^.]+)$|u', $filename, $matches)) {
return self::getExtensionMediaType($matches[1]);
}
return $defaultMediaType;
} | php | public static function getFilenameMediaType(string $filename, ?string $defaultMediaType = null):?string
{
if (preg_match('|\\.([^.]+)$|u', $filename, $matches)) {
return self::getExtensionMediaType($matches[1]);
}
return $defaultMediaType;
} | [
"public",
"static",
"function",
"getFilenameMediaType",
"(",
"string",
"$",
"filename",
",",
"?",
"string",
"$",
"defaultMediaType",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"preg_match",
"(",
"'|\\\\.([^.]+)$|u'",
",",
"$",
"filename",
",",
"$",
"matches",
")",
")",
"{",
"return",
"self",
"::",
"getExtensionMediaType",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
"return",
"$",
"defaultMediaType",
";",
"}"
] | Returns the media type for a given file name.
@param string $filename File name or path (must include an extension)
@param null|string $defaultMediaType Media type returned if the file's media type can not determined
@return null|string
@throws MediaTypesException | [
"Returns",
"the",
"media",
"type",
"for",
"a",
"given",
"file",
"name",
"."
] | 923b4491f3a626ebb01217fae3b0e8bf77ce4b3f | https://github.com/codeinchq/media-types/blob/923b4491f3a626ebb01217fae3b0e8bf77ce4b3f/src/MediaTypes.php#L87-L93 | train |
codeinchq/media-types | src/MediaTypes.php | MediaTypes.getMediaTypeExtensions | public static function getMediaTypeExtensions(string $mediaType):array
{
$mediaType = strtolower($mediaType);
$extensions = [];
foreach (self::getMediaTypes() as $extension => $listMediaType) {
if ($listMediaType == $mediaType) {
$extensions[] = $extension;
}
}
return $extensions;
} | php | public static function getMediaTypeExtensions(string $mediaType):array
{
$mediaType = strtolower($mediaType);
$extensions = [];
foreach (self::getMediaTypes() as $extension => $listMediaType) {
if ($listMediaType == $mediaType) {
$extensions[] = $extension;
}
}
return $extensions;
} | [
"public",
"static",
"function",
"getMediaTypeExtensions",
"(",
"string",
"$",
"mediaType",
")",
":",
"array",
"{",
"$",
"mediaType",
"=",
"strtolower",
"(",
"$",
"mediaType",
")",
";",
"$",
"extensions",
"=",
"[",
"]",
";",
"foreach",
"(",
"self",
"::",
"getMediaTypes",
"(",
")",
"as",
"$",
"extension",
"=>",
"$",
"listMediaType",
")",
"{",
"if",
"(",
"$",
"listMediaType",
"==",
"$",
"mediaType",
")",
"{",
"$",
"extensions",
"[",
"]",
"=",
"$",
"extension",
";",
"}",
"}",
"return",
"$",
"extensions",
";",
"}"
] | Returnes all the known extensions for a given media type.
@param string $mediaType
@return array
@throws MediaTypesException | [
"Returnes",
"all",
"the",
"known",
"extensions",
"for",
"a",
"given",
"media",
"type",
"."
] | 923b4491f3a626ebb01217fae3b0e8bf77ce4b3f | https://github.com/codeinchq/media-types/blob/923b4491f3a626ebb01217fae3b0e8bf77ce4b3f/src/MediaTypes.php#L102-L112 | train |
squareproton/Bond | src/Bond/Entity/Uid.php | Uid.count | public function count()
{
return ( self::$assigned[$this->type] - self::START_AT + self::INCREMENT ) / self::INCREMENT;
} | php | public function count()
{
return ( self::$assigned[$this->type] - self::START_AT + self::INCREMENT ) / self::INCREMENT;
} | [
"public",
"function",
"count",
"(",
")",
"{",
"return",
"(",
"self",
"::",
"$",
"assigned",
"[",
"$",
"this",
"->",
"type",
"]",
"-",
"self",
"::",
"START_AT",
"+",
"self",
"::",
"INCREMENT",
")",
"/",
"self",
"::",
"INCREMENT",
";",
"}"
] | How many keys have been instantiated so far
@return int | [
"How",
"many",
"keys",
"have",
"been",
"instantiated",
"so",
"far"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Uid.php#L95-L98 | train |
koolkode/meta | src/Source/SourceStream.php | SourceStream.next | public function next(SourceBuffer $generator)
{
while(isset($this->tokens[$this->index]))
{
$tok = $this->tokens[$this->index++];
if(is_array($tok))
{
switch($tok[0])
{
case T_COMMENT:
$generator->append($tok);
$this->comment = '';
continue 2;
case T_WHITESPACE:
$generator->append($tok);
continue 2;
case T_DOC_COMMENT:
$generator->append($tok);
$this->comment = trim($tok[1]);
continue 2;
case T_CURLY_OPEN:
case T_DOLLAR_OPEN_CURLY_BRACES:
case T_STRING_VARNAME:
$this->depth++;
$this->comment = '';
break;
case T_CLOSE_TAG:
$this->comment = '';
break;
}
}
else
{
switch($tok)
{
case '{':
$this->depth++;
$this->comment = '';
break;
case '}':
$this->depth--;
$this->comment = '';
break;
case ';':
case ',':
$this->comment = '';
break;
}
}
return $tok;
}
return false;
} | php | public function next(SourceBuffer $generator)
{
while(isset($this->tokens[$this->index]))
{
$tok = $this->tokens[$this->index++];
if(is_array($tok))
{
switch($tok[0])
{
case T_COMMENT:
$generator->append($tok);
$this->comment = '';
continue 2;
case T_WHITESPACE:
$generator->append($tok);
continue 2;
case T_DOC_COMMENT:
$generator->append($tok);
$this->comment = trim($tok[1]);
continue 2;
case T_CURLY_OPEN:
case T_DOLLAR_OPEN_CURLY_BRACES:
case T_STRING_VARNAME:
$this->depth++;
$this->comment = '';
break;
case T_CLOSE_TAG:
$this->comment = '';
break;
}
}
else
{
switch($tok)
{
case '{':
$this->depth++;
$this->comment = '';
break;
case '}':
$this->depth--;
$this->comment = '';
break;
case ';':
case ',':
$this->comment = '';
break;
}
}
return $tok;
}
return false;
} | [
"public",
"function",
"next",
"(",
"SourceBuffer",
"$",
"generator",
")",
"{",
"while",
"(",
"isset",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"index",
"]",
")",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"index",
"++",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"tok",
")",
")",
"{",
"switch",
"(",
"$",
"tok",
"[",
"0",
"]",
")",
"{",
"case",
"T_COMMENT",
":",
"$",
"generator",
"->",
"append",
"(",
"$",
"tok",
")",
";",
"$",
"this",
"->",
"comment",
"=",
"''",
";",
"continue",
"2",
";",
"case",
"T_WHITESPACE",
":",
"$",
"generator",
"->",
"append",
"(",
"$",
"tok",
")",
";",
"continue",
"2",
";",
"case",
"T_DOC_COMMENT",
":",
"$",
"generator",
"->",
"append",
"(",
"$",
"tok",
")",
";",
"$",
"this",
"->",
"comment",
"=",
"trim",
"(",
"$",
"tok",
"[",
"1",
"]",
")",
";",
"continue",
"2",
";",
"case",
"T_CURLY_OPEN",
":",
"case",
"T_DOLLAR_OPEN_CURLY_BRACES",
":",
"case",
"T_STRING_VARNAME",
":",
"$",
"this",
"->",
"depth",
"++",
";",
"$",
"this",
"->",
"comment",
"=",
"''",
";",
"break",
";",
"case",
"T_CLOSE_TAG",
":",
"$",
"this",
"->",
"comment",
"=",
"''",
";",
"break",
";",
"}",
"}",
"else",
"{",
"switch",
"(",
"$",
"tok",
")",
"{",
"case",
"'{'",
":",
"$",
"this",
"->",
"depth",
"++",
";",
"$",
"this",
"->",
"comment",
"=",
"''",
";",
"break",
";",
"case",
"'}'",
":",
"$",
"this",
"->",
"depth",
"--",
";",
"$",
"this",
"->",
"comment",
"=",
"''",
";",
"break",
";",
"case",
"';'",
":",
"case",
"','",
":",
"$",
"this",
"->",
"comment",
"=",
"''",
";",
"break",
";",
"}",
"}",
"return",
"$",
"tok",
";",
"}",
"return",
"false",
";",
"}"
] | Read the next token from the stream, comments and whitespace will be ignored.
@param SourceBuffer $generator
@return mixed A token as array or string or false on EOF. | [
"Read",
"the",
"next",
"token",
"from",
"the",
"stream",
"comments",
"and",
"whitespace",
"will",
"be",
"ignored",
"."
] | 339db24d3ce461190f552c96e243bca21010f360 | https://github.com/koolkode/meta/blob/339db24d3ce461190f552c96e243bca21010f360/src/Source/SourceStream.php#L154-L209 | train |
koolkode/meta | src/Source/SourceStream.php | SourceStream.peek | public function peek($distance = 1)
{
if($distance < 0)
{
throw new \InvalidArgumentException('Peek must be a lookahead => distance must be greater than or equal to 0');
}
$idx = $this->index + $distance - 1;
while(isset($this->tokens[$idx]))
{
$tok = $this->tokens[$idx++];
if(is_array($tok))
{
switch($tok[0])
{
case T_COMMENT:
case T_WHITESPACE:
case T_DOC_COMMENT:
continue 2;
}
}
return $tok;
}
return false;
} | php | public function peek($distance = 1)
{
if($distance < 0)
{
throw new \InvalidArgumentException('Peek must be a lookahead => distance must be greater than or equal to 0');
}
$idx = $this->index + $distance - 1;
while(isset($this->tokens[$idx]))
{
$tok = $this->tokens[$idx++];
if(is_array($tok))
{
switch($tok[0])
{
case T_COMMENT:
case T_WHITESPACE:
case T_DOC_COMMENT:
continue 2;
}
}
return $tok;
}
return false;
} | [
"public",
"function",
"peek",
"(",
"$",
"distance",
"=",
"1",
")",
"{",
"if",
"(",
"$",
"distance",
"<",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Peek must be a lookahead => distance must be greater than or equal to 0'",
")",
";",
"}",
"$",
"idx",
"=",
"$",
"this",
"->",
"index",
"+",
"$",
"distance",
"-",
"1",
";",
"while",
"(",
"isset",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"idx",
"]",
")",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"tokens",
"[",
"$",
"idx",
"++",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"tok",
")",
")",
"{",
"switch",
"(",
"$",
"tok",
"[",
"0",
"]",
")",
"{",
"case",
"T_COMMENT",
":",
"case",
"T_WHITESPACE",
":",
"case",
"T_DOC_COMMENT",
":",
"continue",
"2",
";",
"}",
"}",
"return",
"$",
"tok",
";",
"}",
"return",
"false",
";",
"}"
] | Lookahead at a token relative to the current position.
@param integer $distance
@return mixed Token as array / string or false on EOF.
@throws \InvalidArgumentException When the given distance is less than 0. | [
"Lookahead",
"at",
"a",
"token",
"relative",
"to",
"the",
"current",
"position",
"."
] | 339db24d3ce461190f552c96e243bca21010f360 | https://github.com/koolkode/meta/blob/339db24d3ce461190f552c96e243bca21010f360/src/Source/SourceStream.php#L219-L247 | train |
koolkode/meta | src/Source/SourceStream.php | SourceStream.preceededBy | public function preceededBy($token)
{
if(is_integer($token))
{
$tok = $this->tokens[$this->index - 1];
if(is_array($tok) && $tok[0] == $token)
{
return true;
}
}
else
{
return $token == $this->tokens[$this->index - 1];
}
} | php | public function preceededBy($token)
{
if(is_integer($token))
{
$tok = $this->tokens[$this->index - 1];
if(is_array($tok) && $tok[0] == $token)
{
return true;
}
}
else
{
return $token == $this->tokens[$this->index - 1];
}
} | [
"public",
"function",
"preceededBy",
"(",
"$",
"token",
")",
"{",
"if",
"(",
"is_integer",
"(",
"$",
"token",
")",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"index",
"-",
"1",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"tok",
")",
"&&",
"$",
"tok",
"[",
"0",
"]",
"==",
"$",
"token",
")",
"{",
"return",
"true",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"token",
"==",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"index",
"-",
"1",
"]",
";",
"}",
"}"
] | Check if the token at the current position is preceeded by the given token.
@param mixed $token
@return boolean | [
"Check",
"if",
"the",
"token",
"at",
"the",
"current",
"position",
"is",
"preceeded",
"by",
"the",
"given",
"token",
"."
] | 339db24d3ce461190f552c96e243bca21010f360 | https://github.com/koolkode/meta/blob/339db24d3ce461190f552c96e243bca21010f360/src/Source/SourceStream.php#L255-L270 | train |
koolkode/meta | src/Source/SourceStream.php | SourceStream.previous | public function previous()
{
if(isset($this->tokens[$this->index - 2]))
{
return $this->tokens[$this->index - 2];
}
return false;
} | php | public function previous()
{
if(isset($this->tokens[$this->index - 2]))
{
return $this->tokens[$this->index - 2];
}
return false;
} | [
"public",
"function",
"previous",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"index",
"-",
"2",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"index",
"-",
"2",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Get the previous token, returns false when there is no such token.
@return mixed | [
"Get",
"the",
"previous",
"token",
"returns",
"false",
"when",
"there",
"is",
"no",
"such",
"token",
"."
] | 339db24d3ce461190f552c96e243bca21010f360 | https://github.com/koolkode/meta/blob/339db24d3ce461190f552c96e243bca21010f360/src/Source/SourceStream.php#L277-L285 | train |
koolkode/meta | src/Source/SourceStream.php | SourceStream.preceedingTokens | public function preceedingTokens(array $types)
{
$result = [];
for($x = $this->index - 2; $x >= 0; $x--)
{
$tok = $this->tokens[$x];
if(is_array($tok))
{
switch($tok[0])
{
case T_COMMENT:
case T_WHITESPACE:
continue 2;
}
if(!in_array($tok[0], $types, true))
{
break;
}
}
else
{
if(!in_array($tok, $types, true))
{
break;
}
}
$result[] = $tok;
}
return $result;
} | php | public function preceedingTokens(array $types)
{
$result = [];
for($x = $this->index - 2; $x >= 0; $x--)
{
$tok = $this->tokens[$x];
if(is_array($tok))
{
switch($tok[0])
{
case T_COMMENT:
case T_WHITESPACE:
continue 2;
}
if(!in_array($tok[0], $types, true))
{
break;
}
}
else
{
if(!in_array($tok, $types, true))
{
break;
}
}
$result[] = $tok;
}
return $result;
} | [
"public",
"function",
"preceedingTokens",
"(",
"array",
"$",
"types",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"x",
"=",
"$",
"this",
"->",
"index",
"-",
"2",
";",
"$",
"x",
">=",
"0",
";",
"$",
"x",
"--",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"tokens",
"[",
"$",
"x",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"tok",
")",
")",
"{",
"switch",
"(",
"$",
"tok",
"[",
"0",
"]",
")",
"{",
"case",
"T_COMMENT",
":",
"case",
"T_WHITESPACE",
":",
"continue",
"2",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"tok",
"[",
"0",
"]",
",",
"$",
"types",
",",
"true",
")",
")",
"{",
"break",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"tok",
",",
"$",
"types",
",",
"true",
")",
")",
"{",
"break",
";",
"}",
"}",
"$",
"result",
"[",
"]",
"=",
"$",
"tok",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get all preceeding tokens matching the given token types, will stop when a token is encountered
that does not match the given filter.
@param array $types Valid token types (all other tokens cause halt).
@return array All the tokens that matched the filter. | [
"Get",
"all",
"preceeding",
"tokens",
"matching",
"the",
"given",
"token",
"types",
"will",
"stop",
"when",
"a",
"token",
"is",
"encountered",
"that",
"does",
"not",
"match",
"the",
"given",
"filter",
"."
] | 339db24d3ce461190f552c96e243bca21010f360 | https://github.com/koolkode/meta/blob/339db24d3ce461190f552c96e243bca21010f360/src/Source/SourceStream.php#L294-L328 | train |
jenskooij/cloudcontrol | src/components/CachableBaseComponent.php | CachableBaseComponent.createCache | private function createCache($renderedContent)
{
if (!CmsComponent::isCmsLoggedIn()) {
Cache::getInstance()->setCacheForPath(Request::$requestUri, $renderedContent, json_encode(ResponseHeaders::getHeaders()));
}
} | php | private function createCache($renderedContent)
{
if (!CmsComponent::isCmsLoggedIn()) {
Cache::getInstance()->setCacheForPath(Request::$requestUri, $renderedContent, json_encode(ResponseHeaders::getHeaders()));
}
} | [
"private",
"function",
"createCache",
"(",
"$",
"renderedContent",
")",
"{",
"if",
"(",
"!",
"CmsComponent",
"::",
"isCmsLoggedIn",
"(",
")",
")",
"{",
"Cache",
"::",
"getInstance",
"(",
")",
"->",
"setCacheForPath",
"(",
"Request",
"::",
"$",
"requestUri",
",",
"$",
"renderedContent",
",",
"json_encode",
"(",
"ResponseHeaders",
"::",
"getHeaders",
"(",
")",
")",
")",
";",
"}",
"}"
] | Sets the new cache, unless a cms user is logged in
@param $renderedContent
@throws \RuntimeException | [
"Sets",
"the",
"new",
"cache",
"unless",
"a",
"cms",
"user",
"is",
"logged",
"in"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/CachableBaseComponent.php#L121-L126 | train |
WellCommerce/DistributionBundle | Locator/BundleLocator.php | BundleLocator.getBundleClass | private function getBundleClass(SplFileInfo $fileInfo)
{
$reflection = new ReflectionFile($fileInfo->getRealPath());
$baseName = $fileInfo->getBasename('.php');
foreach ($reflection->getNamespaces() as $namespace) {
return $namespace . '\\' . $baseName;
}
return null;
} | php | private function getBundleClass(SplFileInfo $fileInfo)
{
$reflection = new ReflectionFile($fileInfo->getRealPath());
$baseName = $fileInfo->getBasename('.php');
foreach ($reflection->getNamespaces() as $namespace) {
return $namespace . '\\' . $baseName;
}
return null;
} | [
"private",
"function",
"getBundleClass",
"(",
"SplFileInfo",
"$",
"fileInfo",
")",
"{",
"$",
"reflection",
"=",
"new",
"ReflectionFile",
"(",
"$",
"fileInfo",
"->",
"getRealPath",
"(",
")",
")",
";",
"$",
"baseName",
"=",
"$",
"fileInfo",
"->",
"getBasename",
"(",
"'.php'",
")",
";",
"foreach",
"(",
"$",
"reflection",
"->",
"getNamespaces",
"(",
")",
"as",
"$",
"namespace",
")",
"{",
"return",
"$",
"namespace",
".",
"'\\\\'",
".",
"$",
"baseName",
";",
"}",
"return",
"null",
";",
"}"
] | Returns FQCN for file
@param SplFileInfo $fileInfo
@return string|null | [
"Returns",
"FQCN",
"for",
"file"
] | 82b1b4c2c5a59536aaae22506b23ccd5d141cbb0 | https://github.com/WellCommerce/DistributionBundle/blob/82b1b4c2c5a59536aaae22506b23ccd5d141cbb0/Locator/BundleLocator.php#L82-L92 | train |
vpg/titon.utility | src/Titon/Utility/Path.php | Path.alias | public static function alias($file, array $paths = array()) {
if (empty($file)) {
return '[internal]';
}
$file = static::ds($file);
// Inherit titon constants
foreach (array('vendor', 'app', 'modules', 'resources', 'temp', 'views', 'web') as $type) {
$constant = strtoupper($type) . '_DIR';
if (empty($paths[$type]) && defined($constant)) {
$paths[$type] = constant($constant);
}
}
// Define source locations
foreach (array('src', 'lib') as $source) {
if (empty($paths[$source]) && strpos($file, $source) !== false) {
$parts = explode($source, $file);
$paths[$source] = $parts[0] . $source;
}
}
foreach ($paths as $key => $path) {
$path = trim(static::ds($path), static::SEPARATOR) . static::SEPARATOR;
if (mb_strpos($file, $path) !== false) {
$file = trim(str_replace($path, '[' . $key . ']', $file), static::SEPARATOR);
break;
}
}
return $file;
} | php | public static function alias($file, array $paths = array()) {
if (empty($file)) {
return '[internal]';
}
$file = static::ds($file);
// Inherit titon constants
foreach (array('vendor', 'app', 'modules', 'resources', 'temp', 'views', 'web') as $type) {
$constant = strtoupper($type) . '_DIR';
if (empty($paths[$type]) && defined($constant)) {
$paths[$type] = constant($constant);
}
}
// Define source locations
foreach (array('src', 'lib') as $source) {
if (empty($paths[$source]) && strpos($file, $source) !== false) {
$parts = explode($source, $file);
$paths[$source] = $parts[0] . $source;
}
}
foreach ($paths as $key => $path) {
$path = trim(static::ds($path), static::SEPARATOR) . static::SEPARATOR;
if (mb_strpos($file, $path) !== false) {
$file = trim(str_replace($path, '[' . $key . ']', $file), static::SEPARATOR);
break;
}
}
return $file;
} | [
"public",
"static",
"function",
"alias",
"(",
"$",
"file",
",",
"array",
"$",
"paths",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"file",
")",
")",
"{",
"return",
"'[internal]'",
";",
"}",
"$",
"file",
"=",
"static",
"::",
"ds",
"(",
"$",
"file",
")",
";",
"// Inherit titon constants",
"foreach",
"(",
"array",
"(",
"'vendor'",
",",
"'app'",
",",
"'modules'",
",",
"'resources'",
",",
"'temp'",
",",
"'views'",
",",
"'web'",
")",
"as",
"$",
"type",
")",
"{",
"$",
"constant",
"=",
"strtoupper",
"(",
"$",
"type",
")",
".",
"'_DIR'",
";",
"if",
"(",
"empty",
"(",
"$",
"paths",
"[",
"$",
"type",
"]",
")",
"&&",
"defined",
"(",
"$",
"constant",
")",
")",
"{",
"$",
"paths",
"[",
"$",
"type",
"]",
"=",
"constant",
"(",
"$",
"constant",
")",
";",
"}",
"}",
"// Define source locations",
"foreach",
"(",
"array",
"(",
"'src'",
",",
"'lib'",
")",
"as",
"$",
"source",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"paths",
"[",
"$",
"source",
"]",
")",
"&&",
"strpos",
"(",
"$",
"file",
",",
"$",
"source",
")",
"!==",
"false",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"$",
"source",
",",
"$",
"file",
")",
";",
"$",
"paths",
"[",
"$",
"source",
"]",
"=",
"$",
"parts",
"[",
"0",
"]",
".",
"$",
"source",
";",
"}",
"}",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"key",
"=>",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"trim",
"(",
"static",
"::",
"ds",
"(",
"$",
"path",
")",
",",
"static",
"::",
"SEPARATOR",
")",
".",
"static",
"::",
"SEPARATOR",
";",
"if",
"(",
"mb_strpos",
"(",
"$",
"file",
",",
"$",
"path",
")",
"!==",
"false",
")",
"{",
"$",
"file",
"=",
"trim",
"(",
"str_replace",
"(",
"$",
"path",
",",
"'['",
".",
"$",
"key",
".",
"']'",
",",
"$",
"file",
")",
",",
"static",
"::",
"SEPARATOR",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"file",
";",
"}"
] | Parse the file path to remove absolute paths and replace with a constant name.
@param string $file
@param array $paths
@return string | [
"Parse",
"the",
"file",
"path",
"to",
"remove",
"absolute",
"paths",
"and",
"replace",
"with",
"a",
"constant",
"name",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Path.php#L42-L76 | train |
vpg/titon.utility | src/Titon/Utility/Path.php | Path.ds | public static function ds($path, $endSlash = false) {
$path = str_replace(array('\\', '/'), static::SEPARATOR, $path);
if ($endSlash && substr($path, -1) !== static::SEPARATOR) {
$path .= static::SEPARATOR;
}
return $path;
} | php | public static function ds($path, $endSlash = false) {
$path = str_replace(array('\\', '/'), static::SEPARATOR, $path);
if ($endSlash && substr($path, -1) !== static::SEPARATOR) {
$path .= static::SEPARATOR;
}
return $path;
} | [
"public",
"static",
"function",
"ds",
"(",
"$",
"path",
",",
"$",
"endSlash",
"=",
"false",
")",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"array",
"(",
"'\\\\'",
",",
"'/'",
")",
",",
"static",
"::",
"SEPARATOR",
",",
"$",
"path",
")",
";",
"if",
"(",
"$",
"endSlash",
"&&",
"substr",
"(",
"$",
"path",
",",
"-",
"1",
")",
"!==",
"static",
"::",
"SEPARATOR",
")",
"{",
"$",
"path",
".=",
"static",
"::",
"SEPARATOR",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Converts OS directory separators to the standard forward slash.
@param string $path
@param bool $endSlash
@return string | [
"Converts",
"OS",
"directory",
"separators",
"to",
"the",
"standard",
"forward",
"slash",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Path.php#L96-L104 | train |
vpg/titon.utility | src/Titon/Utility/Path.php | Path.includePath | public static function includePath($paths) {
$current = array(get_include_path());
if (is_array($paths)) {
$current = array_merge($current, $paths);
} else {
$current[] = $paths;
}
$path = implode(static::DELIMITER, $current);
set_include_path($path);
return $path;
} | php | public static function includePath($paths) {
$current = array(get_include_path());
if (is_array($paths)) {
$current = array_merge($current, $paths);
} else {
$current[] = $paths;
}
$path = implode(static::DELIMITER, $current);
set_include_path($path);
return $path;
} | [
"public",
"static",
"function",
"includePath",
"(",
"$",
"paths",
")",
"{",
"$",
"current",
"=",
"array",
"(",
"get_include_path",
"(",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"paths",
")",
")",
"{",
"$",
"current",
"=",
"array_merge",
"(",
"$",
"current",
",",
"$",
"paths",
")",
";",
"}",
"else",
"{",
"$",
"current",
"[",
"]",
"=",
"$",
"paths",
";",
"}",
"$",
"path",
"=",
"implode",
"(",
"static",
"::",
"DELIMITER",
",",
"$",
"current",
")",
";",
"set_include_path",
"(",
"$",
"path",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Define additional include paths for PHP to detect within.
@param string|array $paths
@return array | [
"Define",
"additional",
"include",
"paths",
"for",
"PHP",
"to",
"detect",
"within",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Path.php#L122-L136 | train |
vpg/titon.utility | src/Titon/Utility/Path.php | Path.join | public static function join(array $paths, $above = true, $join = true) {
$clean = array();
$parts = array();
$ds = static::SEPARATOR;
$up = 0;
// First pass expands sub-paths
foreach ($paths as $path) {
if (!is_string($path)) {
throw new InvalidTypeException('Path parts must be strings');
}
$path = trim(static::ds($path), $ds);
if (strpos($path, $ds) !== false) {
$clean = array_merge($clean, explode($ds, $path));
} else {
$clean[] = $path;
}
}
// Second pass flattens dot paths
foreach (array_reverse($clean) as $path) {
if ($path === '.' || !$path) {
continue;
} else if ($path === '..') {
$up++;
} else if ($up) {
$up--;
} else {
$parts[] = $path;
}
}
// Append double dots above root
if ($above) {
while ($up) {
$parts[] = '..';
$up--;
}
}
$parts = array_reverse($parts);
if ($join) {
return implode($parts, $ds);
}
return $parts;
} | php | public static function join(array $paths, $above = true, $join = true) {
$clean = array();
$parts = array();
$ds = static::SEPARATOR;
$up = 0;
// First pass expands sub-paths
foreach ($paths as $path) {
if (!is_string($path)) {
throw new InvalidTypeException('Path parts must be strings');
}
$path = trim(static::ds($path), $ds);
if (strpos($path, $ds) !== false) {
$clean = array_merge($clean, explode($ds, $path));
} else {
$clean[] = $path;
}
}
// Second pass flattens dot paths
foreach (array_reverse($clean) as $path) {
if ($path === '.' || !$path) {
continue;
} else if ($path === '..') {
$up++;
} else if ($up) {
$up--;
} else {
$parts[] = $path;
}
}
// Append double dots above root
if ($above) {
while ($up) {
$parts[] = '..';
$up--;
}
}
$parts = array_reverse($parts);
if ($join) {
return implode($parts, $ds);
}
return $parts;
} | [
"public",
"static",
"function",
"join",
"(",
"array",
"$",
"paths",
",",
"$",
"above",
"=",
"true",
",",
"$",
"join",
"=",
"true",
")",
"{",
"$",
"clean",
"=",
"array",
"(",
")",
";",
"$",
"parts",
"=",
"array",
"(",
")",
";",
"$",
"ds",
"=",
"static",
"::",
"SEPARATOR",
";",
"$",
"up",
"=",
"0",
";",
"// First pass expands sub-paths",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"InvalidTypeException",
"(",
"'Path parts must be strings'",
")",
";",
"}",
"$",
"path",
"=",
"trim",
"(",
"static",
"::",
"ds",
"(",
"$",
"path",
")",
",",
"$",
"ds",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"$",
"ds",
")",
"!==",
"false",
")",
"{",
"$",
"clean",
"=",
"array_merge",
"(",
"$",
"clean",
",",
"explode",
"(",
"$",
"ds",
",",
"$",
"path",
")",
")",
";",
"}",
"else",
"{",
"$",
"clean",
"[",
"]",
"=",
"$",
"path",
";",
"}",
"}",
"// Second pass flattens dot paths",
"foreach",
"(",
"array_reverse",
"(",
"$",
"clean",
")",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"path",
"===",
"'.'",
"||",
"!",
"$",
"path",
")",
"{",
"continue",
";",
"}",
"else",
"if",
"(",
"$",
"path",
"===",
"'..'",
")",
"{",
"$",
"up",
"++",
";",
"}",
"else",
"if",
"(",
"$",
"up",
")",
"{",
"$",
"up",
"--",
";",
"}",
"else",
"{",
"$",
"parts",
"[",
"]",
"=",
"$",
"path",
";",
"}",
"}",
"// Append double dots above root",
"if",
"(",
"$",
"above",
")",
"{",
"while",
"(",
"$",
"up",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"'..'",
";",
"$",
"up",
"--",
";",
"}",
"}",
"$",
"parts",
"=",
"array_reverse",
"(",
"$",
"parts",
")",
";",
"if",
"(",
"$",
"join",
")",
"{",
"return",
"implode",
"(",
"$",
"parts",
",",
"$",
"ds",
")",
";",
"}",
"return",
"$",
"parts",
";",
"}"
] | Join all path parts and return a normalized path.
@param array $paths
@param bool $above - Go above the root path if .. is used
@param bool $join - Join all the path parts into a string
@return string
@throws \Titon\Utility\Exception\InvalidTypeException | [
"Join",
"all",
"path",
"parts",
"and",
"return",
"a",
"normalized",
"path",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Path.php#L167-L219 | train |
vpg/titon.utility | src/Titon/Utility/Path.php | Path.relativeTo | public static function relativeTo($from, $to) {
if (static::isRelative($from) || static::isRelative($to)) {
throw new InvalidArgumentException('Cannot determine relative path without two absolute paths');
}
$ds = static::SEPARATOR;
$from = explode($ds, static::ds($from, true));
$to = explode($ds, static::ds($to, true));
$relative = $to;
foreach ($from as $depth => $dir) {
// Find first non-matching dir and ignore it
if ($dir === $to[$depth]) {
array_shift($relative);
// Get count of remaining dirs to $from
} else {
$remaining = count($from) - $depth;
// Add traversals up to first matching dir
if ($remaining > 1) {
$padLength = (count($relative) + $remaining - 1) * -1;
$relative = array_pad($relative, $padLength, '..');
break;
} else {
$relative[0] = '.' . $ds . $relative[0];
}
}
}
if (!$relative) {
return '.' . $ds;
}
return implode($ds, $relative);
} | php | public static function relativeTo($from, $to) {
if (static::isRelative($from) || static::isRelative($to)) {
throw new InvalidArgumentException('Cannot determine relative path without two absolute paths');
}
$ds = static::SEPARATOR;
$from = explode($ds, static::ds($from, true));
$to = explode($ds, static::ds($to, true));
$relative = $to;
foreach ($from as $depth => $dir) {
// Find first non-matching dir and ignore it
if ($dir === $to[$depth]) {
array_shift($relative);
// Get count of remaining dirs to $from
} else {
$remaining = count($from) - $depth;
// Add traversals up to first matching dir
if ($remaining > 1) {
$padLength = (count($relative) + $remaining - 1) * -1;
$relative = array_pad($relative, $padLength, '..');
break;
} else {
$relative[0] = '.' . $ds . $relative[0];
}
}
}
if (!$relative) {
return '.' . $ds;
}
return implode($ds, $relative);
} | [
"public",
"static",
"function",
"relativeTo",
"(",
"$",
"from",
",",
"$",
"to",
")",
"{",
"if",
"(",
"static",
"::",
"isRelative",
"(",
"$",
"from",
")",
"||",
"static",
"::",
"isRelative",
"(",
"$",
"to",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Cannot determine relative path without two absolute paths'",
")",
";",
"}",
"$",
"ds",
"=",
"static",
"::",
"SEPARATOR",
";",
"$",
"from",
"=",
"explode",
"(",
"$",
"ds",
",",
"static",
"::",
"ds",
"(",
"$",
"from",
",",
"true",
")",
")",
";",
"$",
"to",
"=",
"explode",
"(",
"$",
"ds",
",",
"static",
"::",
"ds",
"(",
"$",
"to",
",",
"true",
")",
")",
";",
"$",
"relative",
"=",
"$",
"to",
";",
"foreach",
"(",
"$",
"from",
"as",
"$",
"depth",
"=>",
"$",
"dir",
")",
"{",
"// Find first non-matching dir and ignore it",
"if",
"(",
"$",
"dir",
"===",
"$",
"to",
"[",
"$",
"depth",
"]",
")",
"{",
"array_shift",
"(",
"$",
"relative",
")",
";",
"// Get count of remaining dirs to $from",
"}",
"else",
"{",
"$",
"remaining",
"=",
"count",
"(",
"$",
"from",
")",
"-",
"$",
"depth",
";",
"// Add traversals up to first matching dir",
"if",
"(",
"$",
"remaining",
">",
"1",
")",
"{",
"$",
"padLength",
"=",
"(",
"count",
"(",
"$",
"relative",
")",
"+",
"$",
"remaining",
"-",
"1",
")",
"*",
"-",
"1",
";",
"$",
"relative",
"=",
"array_pad",
"(",
"$",
"relative",
",",
"$",
"padLength",
",",
"'..'",
")",
";",
"break",
";",
"}",
"else",
"{",
"$",
"relative",
"[",
"0",
"]",
"=",
"'.'",
".",
"$",
"ds",
".",
"$",
"relative",
"[",
"0",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"relative",
")",
"{",
"return",
"'.'",
".",
"$",
"ds",
";",
"}",
"return",
"implode",
"(",
"$",
"ds",
",",
"$",
"relative",
")",
";",
"}"
] | Determine the relative path between two absolute paths.
@param string $from
@param string $to
@return string
@throws \Titon\Utility\Exception\InvalidArgumentException | [
"Determine",
"the",
"relative",
"path",
"between",
"two",
"absolute",
"paths",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Path.php#L251-L286 | train |
vpg/titon.utility | src/Titon/Utility/Path.php | Path.toNamespace | public static function toNamespace($path) {
$path = static::ds(static::stripExt($path));
// Attempt to split path at source folder
foreach (array('lib', 'src') as $folder) {
if (mb_strpos($path, $folder . static::SEPARATOR) !== false) {
$paths = explode($folder . static::SEPARATOR, $path);
$path = $paths[1];
}
}
return trim(str_replace('/', static::PACKAGE, $path), static::PACKAGE);
} | php | public static function toNamespace($path) {
$path = static::ds(static::stripExt($path));
// Attempt to split path at source folder
foreach (array('lib', 'src') as $folder) {
if (mb_strpos($path, $folder . static::SEPARATOR) !== false) {
$paths = explode($folder . static::SEPARATOR, $path);
$path = $paths[1];
}
}
return trim(str_replace('/', static::PACKAGE, $path), static::PACKAGE);
} | [
"public",
"static",
"function",
"toNamespace",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"static",
"::",
"ds",
"(",
"static",
"::",
"stripExt",
"(",
"$",
"path",
")",
")",
";",
"// Attempt to split path at source folder",
"foreach",
"(",
"array",
"(",
"'lib'",
",",
"'src'",
")",
"as",
"$",
"folder",
")",
"{",
"if",
"(",
"mb_strpos",
"(",
"$",
"path",
",",
"$",
"folder",
".",
"static",
"::",
"SEPARATOR",
")",
"!==",
"false",
")",
"{",
"$",
"paths",
"=",
"explode",
"(",
"$",
"folder",
".",
"static",
"::",
"SEPARATOR",
",",
"$",
"path",
")",
";",
"$",
"path",
"=",
"$",
"paths",
"[",
"1",
"]",
";",
"}",
"}",
"return",
"trim",
"(",
"str_replace",
"(",
"'/'",
",",
"static",
"::",
"PACKAGE",
",",
"$",
"path",
")",
",",
"static",
"::",
"PACKAGE",
")",
";",
"}"
] | Converts a path to a namespace package.
@param string $path
@return string | [
"Converts",
"a",
"path",
"to",
"a",
"namespace",
"package",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Path.php#L308-L320 | train |
vpg/titon.utility | src/Titon/Utility/Path.php | Path.toPath | public static function toPath($path, $ext = 'php', $root = '') {
$ds = static::SEPARATOR;
$path = static::ds($path);
$dirs = explode($ds, $path);
$file = array_pop($dirs);
$path = implode($ds, $dirs) . $ds . str_replace('_', $ds, $file);
if ($ext && mb_substr($path, -mb_strlen($ext)) !== $ext) {
$path .= '.' . $ext;
}
if ($root) {
$path = $root . $path;
}
return $path;
} | php | public static function toPath($path, $ext = 'php', $root = '') {
$ds = static::SEPARATOR;
$path = static::ds($path);
$dirs = explode($ds, $path);
$file = array_pop($dirs);
$path = implode($ds, $dirs) . $ds . str_replace('_', $ds, $file);
if ($ext && mb_substr($path, -mb_strlen($ext)) !== $ext) {
$path .= '.' . $ext;
}
if ($root) {
$path = $root . $path;
}
return $path;
} | [
"public",
"static",
"function",
"toPath",
"(",
"$",
"path",
",",
"$",
"ext",
"=",
"'php'",
",",
"$",
"root",
"=",
"''",
")",
"{",
"$",
"ds",
"=",
"static",
"::",
"SEPARATOR",
";",
"$",
"path",
"=",
"static",
"::",
"ds",
"(",
"$",
"path",
")",
";",
"$",
"dirs",
"=",
"explode",
"(",
"$",
"ds",
",",
"$",
"path",
")",
";",
"$",
"file",
"=",
"array_pop",
"(",
"$",
"dirs",
")",
";",
"$",
"path",
"=",
"implode",
"(",
"$",
"ds",
",",
"$",
"dirs",
")",
".",
"$",
"ds",
".",
"str_replace",
"(",
"'_'",
",",
"$",
"ds",
",",
"$",
"file",
")",
";",
"if",
"(",
"$",
"ext",
"&&",
"mb_substr",
"(",
"$",
"path",
",",
"-",
"mb_strlen",
"(",
"$",
"ext",
")",
")",
"!==",
"$",
"ext",
")",
"{",
"$",
"path",
".=",
"'.'",
".",
"$",
"ext",
";",
"}",
"if",
"(",
"$",
"root",
")",
"{",
"$",
"path",
"=",
"$",
"root",
".",
"$",
"path",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Converts a namespace to a relative or absolute file system path.
@param string $path
@param string $ext
@param string $root
@return string | [
"Converts",
"a",
"namespace",
"to",
"a",
"relative",
"or",
"absolute",
"file",
"system",
"path",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Path.php#L330-L346 | train |
linguisticteam/xml-sitemap | src/sitemap_iterator.php | SiteMapUrlSet.addImage | public function addImage( $key, $location, $caption = '', $geolocation = '', $title = '', $license = '' )
{
/**
* @var \Lti\Sitemap\SitemapUrl $node
*/
$node = $this->get( $key );
if ( ! is_null( $node )) {
$node->addImage( new SitemapImage( $location, $caption, $geolocation, $title, $license ) );
$this->hasImages = true;
}
} | php | public function addImage( $key, $location, $caption = '', $geolocation = '', $title = '', $license = '' )
{
/**
* @var \Lti\Sitemap\SitemapUrl $node
*/
$node = $this->get( $key );
if ( ! is_null( $node )) {
$node->addImage( new SitemapImage( $location, $caption, $geolocation, $title, $license ) );
$this->hasImages = true;
}
} | [
"public",
"function",
"addImage",
"(",
"$",
"key",
",",
"$",
"location",
",",
"$",
"caption",
"=",
"''",
",",
"$",
"geolocation",
"=",
"''",
",",
"$",
"title",
"=",
"''",
",",
"$",
"license",
"=",
"''",
")",
"{",
"/**\n * @var \\Lti\\Sitemap\\SitemapUrl $node\n */",
"$",
"node",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"node",
")",
")",
"{",
"$",
"node",
"->",
"addImage",
"(",
"new",
"SitemapImage",
"(",
"$",
"location",
",",
"$",
"caption",
",",
"$",
"geolocation",
",",
"$",
"title",
",",
"$",
"license",
")",
")",
";",
"$",
"this",
"->",
"hasImages",
"=",
"true",
";",
"}",
"}"
] | Adding an image at a specific index in our array of SitemapUrls
@param int $key
@param $location
@param string $caption
@param string $geolocation
@param string $title
@param string $license | [
"Adding",
"an",
"image",
"at",
"a",
"specific",
"index",
"in",
"our",
"array",
"of",
"SitemapUrls"
] | b600a31ad9c1c136fa6f3d3b6a394002121d42f0 | https://github.com/linguisticteam/xml-sitemap/blob/b600a31ad9c1c136fa6f3d3b6a394002121d42f0/src/sitemap_iterator.php#L128-L138 | train |
libreworks/caridea-acl | src/Service.php | Service.assert | public function assert(array $subjects, string $verb, Target $target): void
{
try {
if ($this->get($target, $subjects)->can($subjects, $verb)) {
return;
}
} catch (\Exception $ex) {
throw new Exception\Forbidden("Access denied to $verb the target", 0, $ex);
}
throw new Exception\Forbidden("Access denied to $verb the target");
} | php | public function assert(array $subjects, string $verb, Target $target): void
{
try {
if ($this->get($target, $subjects)->can($subjects, $verb)) {
return;
}
} catch (\Exception $ex) {
throw new Exception\Forbidden("Access denied to $verb the target", 0, $ex);
}
throw new Exception\Forbidden("Access denied to $verb the target");
} | [
"public",
"function",
"assert",
"(",
"array",
"$",
"subjects",
",",
"string",
"$",
"verb",
",",
"Target",
"$",
"target",
")",
":",
"void",
"{",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"$",
"target",
",",
"$",
"subjects",
")",
"->",
"can",
"(",
"$",
"subjects",
",",
"$",
"verb",
")",
")",
"{",
"return",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"Forbidden",
"(",
"\"Access denied to $verb the target\"",
",",
"0",
",",
"$",
"ex",
")",
";",
"}",
"throw",
"new",
"Exception",
"\\",
"Forbidden",
"(",
"\"Access denied to $verb the target\"",
")",
";",
"}"
] | Asserts that one of the provided subjects can verb the Target.
@param Subject[] $subjects An array of `Subject`s
@param string $verb The verb (e.g. `read`, `create`, `delete`)
@param \Caridea\Acl\Target $target The target
@throws Exception\Forbidden if the subject cannot *verb* the Target | [
"Asserts",
"that",
"one",
"of",
"the",
"provided",
"subjects",
"can",
"verb",
"the",
"Target",
"."
] | 64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916 | https://github.com/libreworks/caridea-acl/blob/64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916/src/Service.php#L54-L64 | train |
libreworks/caridea-acl | src/Service.php | Service.can | public function can(array $subjects, string $verb, Target $target): bool
{
try {
return $this->get($target, $subjects)->can($subjects, $verb);
} catch (\Exception $ex) {
// just return false below
}
return false;
} | php | public function can(array $subjects, string $verb, Target $target): bool
{
try {
return $this->get($target, $subjects)->can($subjects, $verb);
} catch (\Exception $ex) {
// just return false below
}
return false;
} | [
"public",
"function",
"can",
"(",
"array",
"$",
"subjects",
",",
"string",
"$",
"verb",
",",
"Target",
"$",
"target",
")",
":",
"bool",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"target",
",",
"$",
"subjects",
")",
"->",
"can",
"(",
"$",
"subjects",
",",
"$",
"verb",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"// just return false below",
"}",
"return",
"false",
";",
"}"
] | Whether any of the provided subjects has permission to verb the Target.
@param Subject[] $subjects An array of `Subject`s
@param string $verb The verb (e.g. `read`, `create`, `delete`)
@param \Caridea\Acl\Target $target The target
@return bool Whether one of the subjects can *verb* the provided Target | [
"Whether",
"any",
"of",
"the",
"provided",
"subjects",
"has",
"permission",
"to",
"verb",
"the",
"Target",
"."
] | 64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916 | https://github.com/libreworks/caridea-acl/blob/64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916/src/Service.php#L74-L82 | train |
libreworks/caridea-acl | src/Service.php | Service.get | public function get(Target $target, array $subjects): Acl
{
return $this->strategy->load($target, $subjects, $this);
} | php | public function get(Target $target, array $subjects): Acl
{
return $this->strategy->load($target, $subjects, $this);
} | [
"public",
"function",
"get",
"(",
"Target",
"$",
"target",
",",
"array",
"$",
"subjects",
")",
":",
"Acl",
"{",
"return",
"$",
"this",
"->",
"strategy",
"->",
"load",
"(",
"$",
"target",
",",
"$",
"subjects",
",",
"$",
"this",
")",
";",
"}"
] | Gets an access control list for a Target.
@param Target $target The Target whose ACL will be loaded
@param Subject[] $subjects An array of `Subject`s
@return Acl The Acl found
@throws Exception\Unloadable If the target provided is invalid
@throws \InvalidArgumentException If the `subjects` argument contains invalid values | [
"Gets",
"an",
"access",
"control",
"list",
"for",
"a",
"Target",
"."
] | 64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916 | https://github.com/libreworks/caridea-acl/blob/64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916/src/Service.php#L93-L96 | train |
libreworks/caridea-acl | src/Service.php | Service.getAll | public function getAll(array $targets, array $subjects): array
{
$acls = [];
if ($this->strategy instanceof MultiStrategy) {
$acls = $this->strategy->loadAll($targets, $subjects, $this);
} else {
foreach ($targets as $target) {
$acls[(string)$target] = $this->strategy->load($target, $subjects, $this);
}
}
$missing = array_diff(array_map(function ($a) {
return (string) $a;
}, $targets), array_keys($acls));
// Check every requested target was found
if (!empty($missing)) {
throw new Exception\Unloadable("Unable to load ACL for " . implode(", ", $missing));
}
return $acls;
} | php | public function getAll(array $targets, array $subjects): array
{
$acls = [];
if ($this->strategy instanceof MultiStrategy) {
$acls = $this->strategy->loadAll($targets, $subjects, $this);
} else {
foreach ($targets as $target) {
$acls[(string)$target] = $this->strategy->load($target, $subjects, $this);
}
}
$missing = array_diff(array_map(function ($a) {
return (string) $a;
}, $targets), array_keys($acls));
// Check every requested target was found
if (!empty($missing)) {
throw new Exception\Unloadable("Unable to load ACL for " . implode(", ", $missing));
}
return $acls;
} | [
"public",
"function",
"getAll",
"(",
"array",
"$",
"targets",
",",
"array",
"$",
"subjects",
")",
":",
"array",
"{",
"$",
"acls",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"strategy",
"instanceof",
"MultiStrategy",
")",
"{",
"$",
"acls",
"=",
"$",
"this",
"->",
"strategy",
"->",
"loadAll",
"(",
"$",
"targets",
",",
"$",
"subjects",
",",
"$",
"this",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"targets",
"as",
"$",
"target",
")",
"{",
"$",
"acls",
"[",
"(",
"string",
")",
"$",
"target",
"]",
"=",
"$",
"this",
"->",
"strategy",
"->",
"load",
"(",
"$",
"target",
",",
"$",
"subjects",
",",
"$",
"this",
")",
";",
"}",
"}",
"$",
"missing",
"=",
"array_diff",
"(",
"array_map",
"(",
"function",
"(",
"$",
"a",
")",
"{",
"return",
"(",
"string",
")",
"$",
"a",
";",
"}",
",",
"$",
"targets",
")",
",",
"array_keys",
"(",
"$",
"acls",
")",
")",
";",
"// Check every requested target was found",
"if",
"(",
"!",
"empty",
"(",
"$",
"missing",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"Unloadable",
"(",
"\"Unable to load ACL for \"",
".",
"implode",
"(",
"\", \"",
",",
"$",
"missing",
")",
")",
";",
"}",
"return",
"$",
"acls",
";",
"}"
] | Gets access control lists for several Targets.
@since 2.1.0
@param \Caridea\Acl\Target[] $targets The `Target` whose ACL will be loaded
@param \Caridea\Acl\Subject[] $subjects An array of `Subject`s
@return array<string,\Caridea\Acl\Acl> The loaded ACLs
@throws \Caridea\Acl\Exception\Unloadable If the target provided is invalid
@throws \InvalidArgumentException If the `targets` or `subjects` argument contains invalid values | [
"Gets",
"access",
"control",
"lists",
"for",
"several",
"Targets",
"."
] | 64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916 | https://github.com/libreworks/caridea-acl/blob/64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916/src/Service.php#L108-L126 | train |
AnonymPHP/Anonym-Database | Pagination/Paginator.php | Paginator.render | public function render()
{
$render = new Render($this);
if ($this->getMode() === static::MODE_SIMPLE) {
return $render->simpleRende();
}else{
return $render->standartRende();
}
} | php | public function render()
{
$render = new Render($this);
if ($this->getMode() === static::MODE_SIMPLE) {
return $render->simpleRende();
}else{
return $render->standartRende();
}
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"render",
"=",
"new",
"Render",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getMode",
"(",
")",
"===",
"static",
"::",
"MODE_SIMPLE",
")",
"{",
"return",
"$",
"render",
"->",
"simpleRende",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"render",
"->",
"standartRende",
"(",
")",
";",
"}",
"}"
] | rende the pagination to string
@return string | [
"rende",
"the",
"pagination",
"to",
"string"
] | 4d034219e0e3eb2833fa53204e9f52a74a9a7e4b | https://github.com/AnonymPHP/Anonym-Database/blob/4d034219e0e3eb2833fa53204e9f52a74a9a7e4b/Pagination/Paginator.php#L148-L158 | train |
AnonymPHP/Anonym-Database | Pagination/Paginator.php | Paginator.rendeToArray | public function rendeToArray(){
$render = new Render($this);
if ($this->getMode() === static::MODE_SIMPLE) {
return $render->simpleRendeArray();
}else{
return $render->standartRendeArray();
}
} | php | public function rendeToArray(){
$render = new Render($this);
if ($this->getMode() === static::MODE_SIMPLE) {
return $render->simpleRendeArray();
}else{
return $render->standartRendeArray();
}
} | [
"public",
"function",
"rendeToArray",
"(",
")",
"{",
"$",
"render",
"=",
"new",
"Render",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getMode",
"(",
")",
"===",
"static",
"::",
"MODE_SIMPLE",
")",
"{",
"return",
"$",
"render",
"->",
"simpleRendeArray",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"render",
"->",
"standartRendeArray",
"(",
")",
";",
"}",
"}"
] | rende the pagination to an array
@return array | [
"rende",
"the",
"pagination",
"to",
"an",
"array"
] | 4d034219e0e3eb2833fa53204e9f52a74a9a7e4b | https://github.com/AnonymPHP/Anonym-Database/blob/4d034219e0e3eb2833fa53204e9f52a74a9a7e4b/Pagination/Paginator.php#L165-L172 | train |
phossa/phossa-di | src/Phossa/Di/Extension/Provider/ProviderExtension.php | ProviderExtension.addProvider | public function addProvider($providerOrClass)
{
// get the provider object
$prov = $this->getProviderInstance($providerOrClass);
// check added or not
$class = get_class($prov);
if (isset($this->providers[$class])) {
throw new LogicException(
Message::get(
Message::EXT_PROVIDER_DUPPED,
get_class($prov)
),
Message::EXT_PROVIDER_DUPPED
);
} else {
// add to the pool
$this->providers[$class] =
$prov->setContainer($this->getContainer());
}
} | php | public function addProvider($providerOrClass)
{
// get the provider object
$prov = $this->getProviderInstance($providerOrClass);
// check added or not
$class = get_class($prov);
if (isset($this->providers[$class])) {
throw new LogicException(
Message::get(
Message::EXT_PROVIDER_DUPPED,
get_class($prov)
),
Message::EXT_PROVIDER_DUPPED
);
} else {
// add to the pool
$this->providers[$class] =
$prov->setContainer($this->getContainer());
}
} | [
"public",
"function",
"addProvider",
"(",
"$",
"providerOrClass",
")",
"{",
"// get the provider object",
"$",
"prov",
"=",
"$",
"this",
"->",
"getProviderInstance",
"(",
"$",
"providerOrClass",
")",
";",
"// check added or not",
"$",
"class",
"=",
"get_class",
"(",
"$",
"prov",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"providers",
"[",
"$",
"class",
"]",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"EXT_PROVIDER_DUPPED",
",",
"get_class",
"(",
"$",
"prov",
")",
")",
",",
"Message",
"::",
"EXT_PROVIDER_DUPPED",
")",
";",
"}",
"else",
"{",
"// add to the pool",
"$",
"this",
"->",
"providers",
"[",
"$",
"class",
"]",
"=",
"$",
"prov",
"->",
"setContainer",
"(",
"$",
"this",
"->",
"getContainer",
"(",
")",
")",
";",
"}",
"}"
] | Add provider to the registry
@param ProviderAbstract|string $providerOrClass provider or classname
@return void
@access public
@internal | [
"Add",
"provider",
"to",
"the",
"registry"
] | bbe1e95b081068e2bc49c6cd465f38aab0374be5 | https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Extension/Provider/ProviderExtension.php#L57-L77 | train |
phossa/phossa-di | src/Phossa/Di/Extension/Provider/ProviderExtension.php | ProviderExtension.getProviderInstance | public function getProviderInstance($providerOrClass)
{
if (is_a($providerOrClass, ProviderAbstract::PROVIDER_CLASS, true)) {
if (!is_object($providerOrClass)) {
$providerOrClass = new $providerOrClass;
}
return $providerOrClass;
} else {
throw new LogicException(
Message::get(Message::EXT_PROVIDER_ERROR, $providerOrClass),
Message::EXT_PROVIDER_ERROR
);
}
} | php | public function getProviderInstance($providerOrClass)
{
if (is_a($providerOrClass, ProviderAbstract::PROVIDER_CLASS, true)) {
if (!is_object($providerOrClass)) {
$providerOrClass = new $providerOrClass;
}
return $providerOrClass;
} else {
throw new LogicException(
Message::get(Message::EXT_PROVIDER_ERROR, $providerOrClass),
Message::EXT_PROVIDER_ERROR
);
}
} | [
"public",
"function",
"getProviderInstance",
"(",
"$",
"providerOrClass",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"providerOrClass",
",",
"ProviderAbstract",
"::",
"PROVIDER_CLASS",
",",
"true",
")",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"providerOrClass",
")",
")",
"{",
"$",
"providerOrClass",
"=",
"new",
"$",
"providerOrClass",
";",
"}",
"return",
"$",
"providerOrClass",
";",
"}",
"else",
"{",
"throw",
"new",
"LogicException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"EXT_PROVIDER_ERROR",
",",
"$",
"providerOrClass",
")",
",",
"Message",
"::",
"EXT_PROVIDER_ERROR",
")",
";",
"}",
"}"
] | Get the provider object
@param string|ProviderAbstract $providerOrClass class or object
@return ProviderAbstract
@throws LogicException
@access protected | [
"Get",
"the",
"provider",
"object"
] | bbe1e95b081068e2bc49c6cd465f38aab0374be5 | https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Extension/Provider/ProviderExtension.php#L105-L118 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/PageQuery.php | PageQuery.filterBySourceId | public function filterBySourceId($sourceId = null, $comparison = null)
{
if (is_array($sourceId)) {
$useMinMax = false;
if (isset($sourceId['min'])) {
$this->addUsingAlias(PageTableMap::COL_SOURCE_ID, $sourceId['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($sourceId['max'])) {
$this->addUsingAlias(PageTableMap::COL_SOURCE_ID, $sourceId['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_SOURCE_ID, $sourceId, $comparison);
} | php | public function filterBySourceId($sourceId = null, $comparison = null)
{
if (is_array($sourceId)) {
$useMinMax = false;
if (isset($sourceId['min'])) {
$this->addUsingAlias(PageTableMap::COL_SOURCE_ID, $sourceId['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($sourceId['max'])) {
$this->addUsingAlias(PageTableMap::COL_SOURCE_ID, $sourceId['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_SOURCE_ID, $sourceId, $comparison);
} | [
"public",
"function",
"filterBySourceId",
"(",
"$",
"sourceId",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"sourceId",
")",
")",
"{",
"$",
"useMinMax",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"sourceId",
"[",
"'min'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addUsingAlias",
"(",
"PageTableMap",
"::",
"COL_SOURCE_ID",
",",
"$",
"sourceId",
"[",
"'min'",
"]",
",",
"Criteria",
"::",
"GREATER_EQUAL",
")",
";",
"$",
"useMinMax",
"=",
"true",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"sourceId",
"[",
"'max'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addUsingAlias",
"(",
"PageTableMap",
"::",
"COL_SOURCE_ID",
",",
"$",
"sourceId",
"[",
"'max'",
"]",
",",
"Criteria",
"::",
"LESS_EQUAL",
")",
";",
"$",
"useMinMax",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"useMinMax",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"PageTableMap",
"::",
"COL_SOURCE_ID",
",",
"$",
"sourceId",
",",
"$",
"comparison",
")",
";",
"}"
] | Filter the query on the source_id column
Example usage:
<code>
$query->filterBySourceId(1234); // WHERE source_id = 1234
$query->filterBySourceId(array(12, 34)); // WHERE source_id IN (12, 34)
$query->filterBySourceId(array('min' => 12)); // WHERE source_id > 12
</code>
@see filterBySource()
@param mixed $sourceId The value to use as filter.
Use scalar values for equality.
Use array values for in_array() equivalent.
Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return $this|ChildPageQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"on",
"the",
"source_id",
"column"
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/PageQuery.php#L378-L399 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/PageQuery.php | PageQuery.filterByPageid | public function filterByPageid($pageid = null, $comparison = null)
{
if (is_array($pageid)) {
$useMinMax = false;
if (isset($pageid['min'])) {
$this->addUsingAlias(PageTableMap::COL_PAGEID, $pageid['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($pageid['max'])) {
$this->addUsingAlias(PageTableMap::COL_PAGEID, $pageid['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_PAGEID, $pageid, $comparison);
} | php | public function filterByPageid($pageid = null, $comparison = null)
{
if (is_array($pageid)) {
$useMinMax = false;
if (isset($pageid['min'])) {
$this->addUsingAlias(PageTableMap::COL_PAGEID, $pageid['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($pageid['max'])) {
$this->addUsingAlias(PageTableMap::COL_PAGEID, $pageid['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_PAGEID, $pageid, $comparison);
} | [
"public",
"function",
"filterByPageid",
"(",
"$",
"pageid",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"pageid",
")",
")",
"{",
"$",
"useMinMax",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"pageid",
"[",
"'min'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addUsingAlias",
"(",
"PageTableMap",
"::",
"COL_PAGEID",
",",
"$",
"pageid",
"[",
"'min'",
"]",
",",
"Criteria",
"::",
"GREATER_EQUAL",
")",
";",
"$",
"useMinMax",
"=",
"true",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"pageid",
"[",
"'max'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addUsingAlias",
"(",
"PageTableMap",
"::",
"COL_PAGEID",
",",
"$",
"pageid",
"[",
"'max'",
"]",
",",
"Criteria",
"::",
"LESS_EQUAL",
")",
";",
"$",
"useMinMax",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"useMinMax",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"PageTableMap",
"::",
"COL_PAGEID",
",",
"$",
"pageid",
",",
"$",
"comparison",
")",
";",
"}"
] | Filter the query on the pageid column
Example usage:
<code>
$query->filterByPageid(1234); // WHERE pageid = 1234
$query->filterByPageid(array(12, 34)); // WHERE pageid IN (12, 34)
$query->filterByPageid(array('min' => 12)); // WHERE pageid > 12
</code>
@param mixed $pageid The value to use as filter.
Use scalar values for equality.
Use array values for in_array() equivalent.
Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return $this|ChildPageQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"on",
"the",
"pageid",
"column"
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/PageQuery.php#L419-L440 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/PageQuery.php | PageQuery.filterByDisplaytitle | public function filterByDisplaytitle($displaytitle = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($displaytitle)) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_DISPLAYTITLE, $displaytitle, $comparison);
} | php | public function filterByDisplaytitle($displaytitle = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($displaytitle)) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_DISPLAYTITLE, $displaytitle, $comparison);
} | [
"public",
"function",
"filterByDisplaytitle",
"(",
"$",
"displaytitle",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"displaytitle",
")",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"PageTableMap",
"::",
"COL_DISPLAYTITLE",
",",
"$",
"displaytitle",
",",
"$",
"comparison",
")",
";",
"}"
] | Filter the query on the displaytitle column
Example usage:
<code>
$query->filterByDisplaytitle('fooValue'); // WHERE displaytitle = 'fooValue'
$query->filterByDisplaytitle('%fooValue%', Criteria::LIKE); // WHERE displaytitle LIKE '%fooValue%'
</code>
@param string $displaytitle The value to use as filter.
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return $this|ChildPageQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"on",
"the",
"displaytitle",
"column"
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/PageQuery.php#L481-L490 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/PageQuery.php | PageQuery.filterByPageImageFree | public function filterByPageImageFree($pageImageFree = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($pageImageFree)) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_PAGE_IMAGE_FREE, $pageImageFree, $comparison);
} | php | public function filterByPageImageFree($pageImageFree = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($pageImageFree)) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_PAGE_IMAGE_FREE, $pageImageFree, $comparison);
} | [
"public",
"function",
"filterByPageImageFree",
"(",
"$",
"pageImageFree",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"pageImageFree",
")",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"PageTableMap",
"::",
"COL_PAGE_IMAGE_FREE",
",",
"$",
"pageImageFree",
",",
"$",
"comparison",
")",
";",
"}"
] | Filter the query on the page_image_free column
Example usage:
<code>
$query->filterByPageImageFree('fooValue'); // WHERE page_image_free = 'fooValue'
$query->filterByPageImageFree('%fooValue%', Criteria::LIKE); // WHERE page_image_free LIKE '%fooValue%'
</code>
@param string $pageImageFree The value to use as filter.
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return $this|ChildPageQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"on",
"the",
"page_image_free",
"column"
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/PageQuery.php#L506-L515 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/PageQuery.php | PageQuery.filterByWikibaseItem | public function filterByWikibaseItem($wikibaseItem = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($wikibaseItem)) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_WIKIBASE_ITEM, $wikibaseItem, $comparison);
} | php | public function filterByWikibaseItem($wikibaseItem = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($wikibaseItem)) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_WIKIBASE_ITEM, $wikibaseItem, $comparison);
} | [
"public",
"function",
"filterByWikibaseItem",
"(",
"$",
"wikibaseItem",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"wikibaseItem",
")",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"PageTableMap",
"::",
"COL_WIKIBASE_ITEM",
",",
"$",
"wikibaseItem",
",",
"$",
"comparison",
")",
";",
"}"
] | Filter the query on the wikibase_item column
Example usage:
<code>
$query->filterByWikibaseItem('fooValue'); // WHERE wikibase_item = 'fooValue'
$query->filterByWikibaseItem('%fooValue%', Criteria::LIKE); // WHERE wikibase_item LIKE '%fooValue%'
</code>
@param string $wikibaseItem The value to use as filter.
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return $this|ChildPageQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"on",
"the",
"wikibase_item",
"column"
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/PageQuery.php#L531-L540 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/PageQuery.php | PageQuery.filterByDisambiguation | public function filterByDisambiguation($disambiguation = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($disambiguation)) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_DISAMBIGUATION, $disambiguation, $comparison);
} | php | public function filterByDisambiguation($disambiguation = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($disambiguation)) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_DISAMBIGUATION, $disambiguation, $comparison);
} | [
"public",
"function",
"filterByDisambiguation",
"(",
"$",
"disambiguation",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"disambiguation",
")",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"PageTableMap",
"::",
"COL_DISAMBIGUATION",
",",
"$",
"disambiguation",
",",
"$",
"comparison",
")",
";",
"}"
] | Filter the query on the disambiguation column
Example usage:
<code>
$query->filterByDisambiguation('fooValue'); // WHERE disambiguation = 'fooValue'
$query->filterByDisambiguation('%fooValue%', Criteria::LIKE); // WHERE disambiguation LIKE '%fooValue%'
</code>
@param string $disambiguation The value to use as filter.
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return $this|ChildPageQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"on",
"the",
"disambiguation",
"column"
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/PageQuery.php#L556-L565 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/PageQuery.php | PageQuery.filterByDefaultsort | public function filterByDefaultsort($defaultsort = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($defaultsort)) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_DEFAULTSORT, $defaultsort, $comparison);
} | php | public function filterByDefaultsort($defaultsort = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($defaultsort)) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(PageTableMap::COL_DEFAULTSORT, $defaultsort, $comparison);
} | [
"public",
"function",
"filterByDefaultsort",
"(",
"$",
"defaultsort",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"defaultsort",
")",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"PageTableMap",
"::",
"COL_DEFAULTSORT",
",",
"$",
"defaultsort",
",",
"$",
"comparison",
")",
";",
"}"
] | Filter the query on the defaultsort column
Example usage:
<code>
$query->filterByDefaultsort('fooValue'); // WHERE defaultsort = 'fooValue'
$query->filterByDefaultsort('%fooValue%', Criteria::LIKE); // WHERE defaultsort LIKE '%fooValue%'
</code>
@param string $defaultsort The value to use as filter.
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return $this|ChildPageQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"on",
"the",
"defaultsort",
"column"
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/PageQuery.php#L581-L590 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/PageQuery.php | PageQuery.useSourceQuery | public function useSourceQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
return $this
->joinSource($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'Source', '\Attogram\SharedMedia\Orm\SourceQuery');
} | php | public function useSourceQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
return $this
->joinSource($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'Source', '\Attogram\SharedMedia\Orm\SourceQuery');
} | [
"public",
"function",
"useSourceQuery",
"(",
"$",
"relationAlias",
"=",
"null",
",",
"$",
"joinType",
"=",
"Criteria",
"::",
"LEFT_JOIN",
")",
"{",
"return",
"$",
"this",
"->",
"joinSource",
"(",
"$",
"relationAlias",
",",
"$",
"joinType",
")",
"->",
"useQuery",
"(",
"$",
"relationAlias",
"?",
"$",
"relationAlias",
":",
"'Source'",
",",
"'\\Attogram\\SharedMedia\\Orm\\SourceQuery'",
")",
";",
"}"
] | Use the Source relation Source object
@see useQuery()
@param string $relationAlias optional alias for the relation,
to be used as main alias in the secondary query
@param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
@return \Attogram\SharedMedia\Orm\SourceQuery A secondary query class using the current class as primary query | [
"Use",
"the",
"Source",
"relation",
"Source",
"object"
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/PageQuery.php#L748-L753 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/PageQuery.php | PageQuery.filterByC2P | public function filterByC2P($c2P, $comparison = null)
{
if ($c2P instanceof \Attogram\SharedMedia\Orm\C2P) {
return $this
->addUsingAlias(PageTableMap::COL_ID, $c2P->getPageId(), $comparison);
} elseif ($c2P instanceof ObjectCollection) {
return $this
->useC2PQuery()
->filterByPrimaryKeys($c2P->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByC2P() only accepts arguments of type \Attogram\SharedMedia\Orm\C2P or Collection');
}
} | php | public function filterByC2P($c2P, $comparison = null)
{
if ($c2P instanceof \Attogram\SharedMedia\Orm\C2P) {
return $this
->addUsingAlias(PageTableMap::COL_ID, $c2P->getPageId(), $comparison);
} elseif ($c2P instanceof ObjectCollection) {
return $this
->useC2PQuery()
->filterByPrimaryKeys($c2P->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByC2P() only accepts arguments of type \Attogram\SharedMedia\Orm\C2P or Collection');
}
} | [
"public",
"function",
"filterByC2P",
"(",
"$",
"c2P",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"c2P",
"instanceof",
"\\",
"Attogram",
"\\",
"SharedMedia",
"\\",
"Orm",
"\\",
"C2P",
")",
"{",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"PageTableMap",
"::",
"COL_ID",
",",
"$",
"c2P",
"->",
"getPageId",
"(",
")",
",",
"$",
"comparison",
")",
";",
"}",
"elseif",
"(",
"$",
"c2P",
"instanceof",
"ObjectCollection",
")",
"{",
"return",
"$",
"this",
"->",
"useC2PQuery",
"(",
")",
"->",
"filterByPrimaryKeys",
"(",
"$",
"c2P",
"->",
"getPrimaryKeys",
"(",
")",
")",
"->",
"endUse",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"PropelException",
"(",
"'filterByC2P() only accepts arguments of type \\Attogram\\SharedMedia\\Orm\\C2P or Collection'",
")",
";",
"}",
"}"
] | Filter the query by a related \Attogram\SharedMedia\Orm\C2P object
@param \Attogram\SharedMedia\Orm\C2P|ObjectCollection $c2P the related object to use as filter
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return ChildPageQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"by",
"a",
"related",
"\\",
"Attogram",
"\\",
"SharedMedia",
"\\",
"Orm",
"\\",
"C2P",
"object"
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/PageQuery.php#L763-L776 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/PageQuery.php | PageQuery.useC2PQuery | public function useC2PQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinC2P($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'C2P', '\Attogram\SharedMedia\Orm\C2PQuery');
} | php | public function useC2PQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinC2P($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'C2P', '\Attogram\SharedMedia\Orm\C2PQuery');
} | [
"public",
"function",
"useC2PQuery",
"(",
"$",
"relationAlias",
"=",
"null",
",",
"$",
"joinType",
"=",
"Criteria",
"::",
"INNER_JOIN",
")",
"{",
"return",
"$",
"this",
"->",
"joinC2P",
"(",
"$",
"relationAlias",
",",
"$",
"joinType",
")",
"->",
"useQuery",
"(",
"$",
"relationAlias",
"?",
"$",
"relationAlias",
":",
"'C2P'",
",",
"'\\Attogram\\SharedMedia\\Orm\\C2PQuery'",
")",
";",
"}"
] | Use the C2P relation C2P object
@see useQuery()
@param string $relationAlias optional alias for the relation,
to be used as main alias in the secondary query
@param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
@return \Attogram\SharedMedia\Orm\C2PQuery A secondary query class using the current class as primary query | [
"Use",
"the",
"C2P",
"relation",
"C2P",
"object"
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/PageQuery.php#L821-L826 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/PageQuery.php | PageQuery.useM2PQuery | public function useM2PQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinM2P($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'M2P', '\Attogram\SharedMedia\Orm\M2PQuery');
} | php | public function useM2PQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinM2P($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'M2P', '\Attogram\SharedMedia\Orm\M2PQuery');
} | [
"public",
"function",
"useM2PQuery",
"(",
"$",
"relationAlias",
"=",
"null",
",",
"$",
"joinType",
"=",
"Criteria",
"::",
"INNER_JOIN",
")",
"{",
"return",
"$",
"this",
"->",
"joinM2P",
"(",
"$",
"relationAlias",
",",
"$",
"joinType",
")",
"->",
"useQuery",
"(",
"$",
"relationAlias",
"?",
"$",
"relationAlias",
":",
"'M2P'",
",",
"'\\Attogram\\SharedMedia\\Orm\\M2PQuery'",
")",
";",
"}"
] | Use the M2P relation M2P object
@see useQuery()
@param string $relationAlias optional alias for the relation,
to be used as main alias in the secondary query
@param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
@return \Attogram\SharedMedia\Orm\M2PQuery A secondary query class using the current class as primary query | [
"Use",
"the",
"M2P",
"relation",
"M2P",
"object"
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/PageQuery.php#L894-L899 | train |
Kris-Kuiper/sFire-Framework | src/Cache/Driver/Filesystem.php | Filesystem.clear | public function clear() {
$files = glob(Path :: get('cache-shared') . '*');
if(true === is_array($files)) {
foreach($files as $file) {
$file = new File($file);
$file -> delete();
}
}
return $this;
} | php | public function clear() {
$files = glob(Path :: get('cache-shared') . '*');
if(true === is_array($files)) {
foreach($files as $file) {
$file = new File($file);
$file -> delete();
}
}
return $this;
} | [
"public",
"function",
"clear",
"(",
")",
"{",
"$",
"files",
"=",
"glob",
"(",
"Path",
"::",
"get",
"(",
"'cache-shared'",
")",
".",
"'*'",
")",
";",
"if",
"(",
"true",
"===",
"is_array",
"(",
"$",
"files",
")",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"file",
"=",
"new",
"File",
"(",
"$",
"file",
")",
";",
"$",
"file",
"->",
"delete",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Clear all cache files
@return sFire\Cache\Filesystem | [
"Clear",
"all",
"cache",
"files"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Cache/Driver/Filesystem.php#L122-L136 | train |
Kris-Kuiper/sFire-Framework | src/Cache/Driver/Filesystem.php | Filesystem.clearExpired | public function clearExpired() {
$files = glob(Path :: get('cache-shared') . '*');
if(true === is_array($files) && count($files) > 0) {
foreach($files as $file) {
$file = new File($file);
$expiration = $this -> extractExpiration($file);
if($expiration -> time <= time()) {
$file -> delete();
}
}
}
return $this;
} | php | public function clearExpired() {
$files = glob(Path :: get('cache-shared') . '*');
if(true === is_array($files) && count($files) > 0) {
foreach($files as $file) {
$file = new File($file);
$expiration = $this -> extractExpiration($file);
if($expiration -> time <= time()) {
$file -> delete();
}
}
}
return $this;
} | [
"public",
"function",
"clearExpired",
"(",
")",
"{",
"$",
"files",
"=",
"glob",
"(",
"Path",
"::",
"get",
"(",
"'cache-shared'",
")",
".",
"'*'",
")",
";",
"if",
"(",
"true",
"===",
"is_array",
"(",
"$",
"files",
")",
"&&",
"count",
"(",
"$",
"files",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"file",
"=",
"new",
"File",
"(",
"$",
"file",
")",
";",
"$",
"expiration",
"=",
"$",
"this",
"->",
"extractExpiration",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"expiration",
"->",
"time",
"<=",
"time",
"(",
")",
")",
"{",
"$",
"file",
"->",
"delete",
"(",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Clear all expired cache
@return sFire\Cache\Filesystem | [
"Clear",
"all",
"expired",
"cache"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Cache/Driver/Filesystem.php#L143-L161 | train |
Kris-Kuiper/sFire-Framework | src/Cache/Driver/Filesystem.php | Filesystem.generateName | private function generateName($key, $expiration = null) {
if(null !== $expiration && false === ('-' . intval($expiration) == '-' . $expiration)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($expiration)), E_USER_ERROR);
}
return md5(serialize($key)) . '-' . ($expiration ? $expiration : '*') . '-' . ($expiration ? (time() + $expiration) : '*') . Application :: get(['extensions', 'cache']);
} | php | private function generateName($key, $expiration = null) {
if(null !== $expiration && false === ('-' . intval($expiration) == '-' . $expiration)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($expiration)), E_USER_ERROR);
}
return md5(serialize($key)) . '-' . ($expiration ? $expiration : '*') . '-' . ($expiration ? (time() + $expiration) : '*') . Application :: get(['extensions', 'cache']);
} | [
"private",
"function",
"generateName",
"(",
"$",
"key",
",",
"$",
"expiration",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"expiration",
"&&",
"false",
"===",
"(",
"'-'",
".",
"intval",
"(",
"$",
"expiration",
")",
"==",
"'-'",
".",
"$",
"expiration",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"expiration",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"return",
"md5",
"(",
"serialize",
"(",
"$",
"key",
")",
")",
".",
"'-'",
".",
"(",
"$",
"expiration",
"?",
"$",
"expiration",
":",
"'*'",
")",
".",
"'-'",
".",
"(",
"$",
"expiration",
"?",
"(",
"time",
"(",
")",
"+",
"$",
"expiration",
")",
":",
"'*'",
")",
".",
"Application",
"::",
"get",
"(",
"[",
"'extensions'",
",",
"'cache'",
"]",
")",
";",
"}"
] | Generates the cache file name
@param mixed $key
@param int $expiration
@return string | [
"Generates",
"the",
"cache",
"file",
"name"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Cache/Driver/Filesystem.php#L222-L229 | train |
Kris-Kuiper/sFire-Framework | src/Cache/Driver/Filesystem.php | Filesystem.extractExpiration | private function extractExpiration(File $file) {
$expiration = explode('-', $file -> entity() -> getName());
if(count($expiration) > 2) {
return (object) ['time' => $expiration[2], 'expiration' => $expiration[1]];
}
return (object) ['time' => 0, 'expiration' => 0];
} | php | private function extractExpiration(File $file) {
$expiration = explode('-', $file -> entity() -> getName());
if(count($expiration) > 2) {
return (object) ['time' => $expiration[2], 'expiration' => $expiration[1]];
}
return (object) ['time' => 0, 'expiration' => 0];
} | [
"private",
"function",
"extractExpiration",
"(",
"File",
"$",
"file",
")",
"{",
"$",
"expiration",
"=",
"explode",
"(",
"'-'",
",",
"$",
"file",
"->",
"entity",
"(",
")",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"expiration",
")",
">",
"2",
")",
"{",
"return",
"(",
"object",
")",
"[",
"'time'",
"=>",
"$",
"expiration",
"[",
"2",
"]",
",",
"'expiration'",
"=>",
"$",
"expiration",
"[",
"1",
"]",
"]",
";",
"}",
"return",
"(",
"object",
")",
"[",
"'time'",
"=>",
"0",
",",
"'expiration'",
"=>",
"0",
"]",
";",
"}"
] | Returns the expiration time of cache file
@param sFire\System\File $file
@return object | [
"Returns",
"the",
"expiration",
"time",
"of",
"cache",
"file"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Cache/Driver/Filesystem.php#L237-L246 | train |
eureka-framework/component-orm | src/Orm/Type/Factory.php | Factory.create | public static function create($sqlType)
{
$matches = array();
if (!(bool) preg_match('`([a-z]+)\(?([0-9]*)\)? ?(.*)`', $sqlType, $matches)) {
throw new \Exception();
}
$type = (string) $matches[1];
$display = (int) $matches[2];
$other = (string) $matches[3];
switch (strtolower($type)) {
//~ Special case for tinyint used as boolean value.
case 'tinyint':
$type = ($display === 1 ? new TypeBool() : new TypeTinyint());
break;
//~ Other case
default:
$classname = __NAMESPACE__ . '\Type' . ucfirst($type);
if (!class_exists($classname)) {
throw new \RangeException('Sql type cannot be converted into php type! (type: ' . $type . ')');
}
$type = new $classname();
break;
}
$type->setDisplay($display);
switch (strtolower($other)) {
case 'unsigned':
$type->setIsUnsigned(true);
break;
default:
$type->setOther($other);
}
return $type;
} | php | public static function create($sqlType)
{
$matches = array();
if (!(bool) preg_match('`([a-z]+)\(?([0-9]*)\)? ?(.*)`', $sqlType, $matches)) {
throw new \Exception();
}
$type = (string) $matches[1];
$display = (int) $matches[2];
$other = (string) $matches[3];
switch (strtolower($type)) {
//~ Special case for tinyint used as boolean value.
case 'tinyint':
$type = ($display === 1 ? new TypeBool() : new TypeTinyint());
break;
//~ Other case
default:
$classname = __NAMESPACE__ . '\Type' . ucfirst($type);
if (!class_exists($classname)) {
throw new \RangeException('Sql type cannot be converted into php type! (type: ' . $type . ')');
}
$type = new $classname();
break;
}
$type->setDisplay($display);
switch (strtolower($other)) {
case 'unsigned':
$type->setIsUnsigned(true);
break;
default:
$type->setOther($other);
}
return $type;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"sqlType",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"(",
"bool",
")",
"preg_match",
"(",
"'`([a-z]+)\\(?([0-9]*)\\)? ?(.*)`'",
",",
"$",
"sqlType",
",",
"$",
"matches",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
")",
";",
"}",
"$",
"type",
"=",
"(",
"string",
")",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"display",
"=",
"(",
"int",
")",
"$",
"matches",
"[",
"2",
"]",
";",
"$",
"other",
"=",
"(",
"string",
")",
"$",
"matches",
"[",
"3",
"]",
";",
"switch",
"(",
"strtolower",
"(",
"$",
"type",
")",
")",
"{",
"//~ Special case for tinyint used as boolean value.",
"case",
"'tinyint'",
":",
"$",
"type",
"=",
"(",
"$",
"display",
"===",
"1",
"?",
"new",
"TypeBool",
"(",
")",
":",
"new",
"TypeTinyint",
"(",
")",
")",
";",
"break",
";",
"//~ Other case",
"default",
":",
"$",
"classname",
"=",
"__NAMESPACE__",
".",
"'\\Type'",
".",
"ucfirst",
"(",
"$",
"type",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"classname",
")",
")",
"{",
"throw",
"new",
"\\",
"RangeException",
"(",
"'Sql type cannot be converted into php type! (type: '",
".",
"$",
"type",
".",
"')'",
")",
";",
"}",
"$",
"type",
"=",
"new",
"$",
"classname",
"(",
")",
";",
"break",
";",
"}",
"$",
"type",
"->",
"setDisplay",
"(",
"$",
"display",
")",
";",
"switch",
"(",
"strtolower",
"(",
"$",
"other",
")",
")",
"{",
"case",
"'unsigned'",
":",
"$",
"type",
"->",
"setIsUnsigned",
"(",
"true",
")",
";",
"break",
";",
"default",
":",
"$",
"type",
"->",
"setOther",
"(",
"$",
"other",
")",
";",
"}",
"return",
"$",
"type",
";",
"}"
] | Instantiate new type.
@param string $sqlType
@return TypeInterface
@throws \RangeException
@throws \Exception | [
"Instantiate",
"new",
"type",
"."
] | bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Type/Factory.php#L27-L67 | train |
mattferris/configuration | src/Configuration.php | Configuration.& | protected function &resolveKey($key)
{
// check if the key is a compound key
if (strpos($key, '.') !== false) {
// key is compound, so split it into parts
$parts = explode('.', $key);
$config = &$this->config;
// recurse into the config array using the key parts
while (is_array($config) && ($part = array_shift($parts)) !== null) {
if (!isset($config[$part]) && array_key_exists($part, $config)) {
throw new KeyDoesNotExistException($key);
}
$config = &$config[$part];
}
// if there are still key parts left, then the key doesn't exist
if (count($parts) > 0) {
throw new KeyDoesNotExistException($key);
}
} else {
// key is not compound, so just check if it exists and get value
if (!isset($this->config[$key]) && !array_key_exists($key, $this->config)) {
throw new KeyDoesNotExistException($key);
}
$config = &$this->config[$key];
}
return $config;
} | php | protected function &resolveKey($key)
{
// check if the key is a compound key
if (strpos($key, '.') !== false) {
// key is compound, so split it into parts
$parts = explode('.', $key);
$config = &$this->config;
// recurse into the config array using the key parts
while (is_array($config) && ($part = array_shift($parts)) !== null) {
if (!isset($config[$part]) && array_key_exists($part, $config)) {
throw new KeyDoesNotExistException($key);
}
$config = &$config[$part];
}
// if there are still key parts left, then the key doesn't exist
if (count($parts) > 0) {
throw new KeyDoesNotExistException($key);
}
} else {
// key is not compound, so just check if it exists and get value
if (!isset($this->config[$key]) && !array_key_exists($key, $this->config)) {
throw new KeyDoesNotExistException($key);
}
$config = &$this->config[$key];
}
return $config;
} | [
"protected",
"function",
"&",
"resolveKey",
"(",
"$",
"key",
")",
"{",
"// check if the key is a compound key",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"// key is compound, so split it into parts",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"config",
"=",
"&",
"$",
"this",
"->",
"config",
";",
"// recurse into the config array using the key parts",
"while",
"(",
"is_array",
"(",
"$",
"config",
")",
"&&",
"(",
"$",
"part",
"=",
"array_shift",
"(",
"$",
"parts",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"$",
"part",
"]",
")",
"&&",
"array_key_exists",
"(",
"$",
"part",
",",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"KeyDoesNotExistException",
"(",
"$",
"key",
")",
";",
"}",
"$",
"config",
"=",
"&",
"$",
"config",
"[",
"$",
"part",
"]",
";",
"}",
"// if there are still key parts left, then the key doesn't exist",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
">",
"0",
")",
"{",
"throw",
"new",
"KeyDoesNotExistException",
"(",
"$",
"key",
")",
";",
"}",
"}",
"else",
"{",
"// key is not compound, so just check if it exists and get value",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"$",
"key",
"]",
")",
"&&",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"config",
")",
")",
"{",
"throw",
"new",
"KeyDoesNotExistException",
"(",
"$",
"key",
")",
";",
"}",
"$",
"config",
"=",
"&",
"$",
"this",
"->",
"config",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"config",
";",
"}"
] | Resolve a key to it's value.
@param string $key The key to resolve
@return A reference to the key's value
@throws KeyDoesNotExistException If the key doesn't exist | [
"Resolve",
"a",
"key",
"to",
"it",
"s",
"value",
"."
] | 28985400060959744922a0657ffb2e1751d7f6bb | https://github.com/mattferris/configuration/blob/28985400060959744922a0657ffb2e1751d7f6bb/src/Configuration.php#L162-L195 | train |
mattferris/configuration | src/Configuration.php | Configuration.getParentChildKeys | protected function getParentChildKeys($key)
{
$parts = explode('.', $key);
$child = array_pop($parts);
return [implode('.', $parts), $child];
} | php | protected function getParentChildKeys($key)
{
$parts = explode('.', $key);
$child = array_pop($parts);
return [implode('.', $parts), $child];
} | [
"protected",
"function",
"getParentChildKeys",
"(",
"$",
"key",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"child",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"return",
"[",
"implode",
"(",
"'.'",
",",
"$",
"parts",
")",
",",
"$",
"child",
"]",
";",
"}"
] | Get the parent key, and the child part of the key.
@param string $key The key to get the parent and child part from
@return array The parent and child part | [
"Get",
"the",
"parent",
"key",
"and",
"the",
"child",
"part",
"of",
"the",
"key",
"."
] | 28985400060959744922a0657ffb2e1751d7f6bb | https://github.com/mattferris/configuration/blob/28985400060959744922a0657ffb2e1751d7f6bb/src/Configuration.php#L203-L208 | train |
mattferris/configuration | src/Configuration.php | Configuration.merge | protected function merge($key, $result)
{
if (is_null($key)) {
// key is null, so just merge with root
$this->config = array_merge($this->config, $result);
} elseif (strpos($key, '.') === false) {
// non-compound key, just merge key with incoming data
if (!isset($this->config[$key]) && !array_key_exists($key, $this->config)) {
throw new KeyDoesNotExistException($key);
}
// if $this->config[$key] is not an array, we convert it one before merging
if (!is_array($this->config[$key])) {
$this->config[$key] = [];
}
$this->config[$key] = array_merge($this->config[$key], $result);
} else {
// compound key, so merge with parent reference
list($parent, $child) = $this->getParentChildKeys($key);
$config = $this->resolveKey($parent);
$config[$child] = array_merge($config[$child], $result);
}
} | php | protected function merge($key, $result)
{
if (is_null($key)) {
// key is null, so just merge with root
$this->config = array_merge($this->config, $result);
} elseif (strpos($key, '.') === false) {
// non-compound key, just merge key with incoming data
if (!isset($this->config[$key]) && !array_key_exists($key, $this->config)) {
throw new KeyDoesNotExistException($key);
}
// if $this->config[$key] is not an array, we convert it one before merging
if (!is_array($this->config[$key])) {
$this->config[$key] = [];
}
$this->config[$key] = array_merge($this->config[$key], $result);
} else {
// compound key, so merge with parent reference
list($parent, $child) = $this->getParentChildKeys($key);
$config = $this->resolveKey($parent);
$config[$child] = array_merge($config[$child], $result);
}
} | [
"protected",
"function",
"merge",
"(",
"$",
"key",
",",
"$",
"result",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"// key is null, so just merge with root",
"$",
"this",
"->",
"config",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"result",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"key",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"// non-compound key, just merge key with incoming data",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"$",
"key",
"]",
")",
"&&",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"config",
")",
")",
"{",
"throw",
"new",
"KeyDoesNotExistException",
"(",
"$",
"key",
")",
";",
"}",
"// if $this->config[$key] is not an array, we convert it one before merging",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"config",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"$",
"key",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"config",
"[",
"$",
"key",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"config",
"[",
"$",
"key",
"]",
",",
"$",
"result",
")",
";",
"}",
"else",
"{",
"// compound key, so merge with parent reference",
"list",
"(",
"$",
"parent",
",",
"$",
"child",
")",
"=",
"$",
"this",
"->",
"getParentChildKeys",
"(",
"$",
"key",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"resolveKey",
"(",
"$",
"parent",
")",
";",
"$",
"config",
"[",
"$",
"child",
"]",
"=",
"array_merge",
"(",
"$",
"config",
"[",
"$",
"child",
"]",
",",
"$",
"result",
")",
";",
"}",
"}"
] | Merge values into a key.
@param string $key The key to merge into
@param mixed $result The data to merge
@throws KeyDoesNotExistException If the key doesn't exist | [
"Merge",
"values",
"into",
"a",
"key",
"."
] | 28985400060959744922a0657ffb2e1751d7f6bb | https://github.com/mattferris/configuration/blob/28985400060959744922a0657ffb2e1751d7f6bb/src/Configuration.php#L217-L246 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Entity.php | Entity.setTable | public function setTable($table) {
if(false === is_string($table)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($table)), E_USER_ERROR);
}
$this -> table = $table;
return $this;
} | php | public function setTable($table) {
if(false === is_string($table)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($table)), E_USER_ERROR);
}
$this -> table = $table;
return $this;
} | [
"public",
"function",
"setTable",
"(",
"$",
"table",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"table",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"table",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"table",
"=",
"$",
"table",
";",
"return",
"$",
"this",
";",
"}"
] | Set the current table
@param string $table
@return $this | [
"Set",
"the",
"current",
"table"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Entity.php#L117-L126 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Entity.php | Entity.getTable | public function getTable() {
if(null === $this -> table) {
$path = $this -> getNamespace($this, ['directory', 'entity'], ['directory', 'entity']) . Application :: get(['prefix', 'entity']);
$path = str_replace(DIRECTORY_SEPARATOR, '\\', $path);
$class = new \ReflectionClass(get_class($this));
$this -> table = NameConvert :: toSnakecase(str_replace($path, '', $class -> name));
}
return $this -> table;
} | php | public function getTable() {
if(null === $this -> table) {
$path = $this -> getNamespace($this, ['directory', 'entity'], ['directory', 'entity']) . Application :: get(['prefix', 'entity']);
$path = str_replace(DIRECTORY_SEPARATOR, '\\', $path);
$class = new \ReflectionClass(get_class($this));
$this -> table = NameConvert :: toSnakecase(str_replace($path, '', $class -> name));
}
return $this -> table;
} | [
"public",
"function",
"getTable",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"table",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getNamespace",
"(",
"$",
"this",
",",
"[",
"'directory'",
",",
"'entity'",
"]",
",",
"[",
"'directory'",
",",
"'entity'",
"]",
")",
".",
"Application",
"::",
"get",
"(",
"[",
"'prefix'",
",",
"'entity'",
"]",
")",
";",
"$",
"path",
"=",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'\\\\'",
",",
"$",
"path",
")",
";",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"$",
"this",
"->",
"table",
"=",
"NameConvert",
"::",
"toSnakecase",
"(",
"str_replace",
"(",
"$",
"path",
",",
"''",
",",
"$",
"class",
"->",
"name",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"table",
";",
"}"
] | Returns the table from current namespace or from table variable if set
@return string | [
"Returns",
"the",
"table",
"from",
"current",
"namespace",
"or",
"from",
"table",
"variable",
"if",
"set"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Entity.php#L133-L145 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Entity.php | Entity.setDateFormat | public function setDateFormat($formats) {
if(false === is_array($formats)) {
$formats = [$formats];
}
$this -> date_formats = $formats;
return $this;
} | php | public function setDateFormat($formats) {
if(false === is_array($formats)) {
$formats = [$formats];
}
$this -> date_formats = $formats;
return $this;
} | [
"public",
"function",
"setDateFormat",
"(",
"$",
"formats",
")",
"{",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"formats",
")",
")",
"{",
"$",
"formats",
"=",
"[",
"$",
"formats",
"]",
";",
"}",
"$",
"this",
"->",
"date_formats",
"=",
"$",
"formats",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a string or array of date formats so selected dates which matches the formats will be converted automatically to Date Objects
@param array|string $formats
@return $this | [
"Adds",
"a",
"string",
"or",
"array",
"of",
"date",
"formats",
"so",
"selected",
"dates",
"which",
"matches",
"the",
"formats",
"will",
"be",
"converted",
"automatically",
"to",
"Date",
"Objects"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Entity.php#L153-L162 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Entity.php | Entity.convertToJson | public function convertToJson($convert = true) {
if(false === is_bool($convert)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type Boolean, "%s" given', __METHOD__, gettype($convert)), E_USER_ERROR);
}
$this -> convert_json = $convert;
return $this;
} | php | public function convertToJson($convert = true) {
if(false === is_bool($convert)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type Boolean, "%s" given', __METHOD__, gettype($convert)), E_USER_ERROR);
}
$this -> convert_json = $convert;
return $this;
} | [
"public",
"function",
"convertToJson",
"(",
"$",
"convert",
"=",
"true",
")",
"{",
"if",
"(",
"false",
"===",
"is_bool",
"(",
"$",
"convert",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type Boolean, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"convert",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"convert_json",
"=",
"$",
"convert",
";",
"return",
"$",
"this",
";",
"}"
] | Columns containing valid JSON will be converted to Array's automatically
@param boolean $convert
@return $this | [
"Columns",
"containing",
"valid",
"JSON",
"will",
"be",
"converted",
"to",
"Array",
"s",
"automatically"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Entity.php#L170-L179 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Entity.php | Entity.fromArray | public function fromArray($data) {
if(false === is_array($data)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type Array, "%s" given', __METHOD__, gettype($data)), E_USER_ERROR);
}
$this -> beforeLoad();
foreach($data as $column => $value) {
$value = $this -> convertToDate($value);
$value = $this -> convertJsonToArray($value);
$col = NameConvert :: toCamelcase($column, true);
$method = 'set' . $col;
if(true === method_exists($this, $method)) {
call_user_func_array([$this, $method], [$value]);
}
else {
$this -> addValue($column, $value, $col);
}
}
$this -> afterLoad();
return $this;
} | php | public function fromArray($data) {
if(false === is_array($data)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type Array, "%s" given', __METHOD__, gettype($data)), E_USER_ERROR);
}
$this -> beforeLoad();
foreach($data as $column => $value) {
$value = $this -> convertToDate($value);
$value = $this -> convertJsonToArray($value);
$col = NameConvert :: toCamelcase($column, true);
$method = 'set' . $col;
if(true === method_exists($this, $method)) {
call_user_func_array([$this, $method], [$value]);
}
else {
$this -> addValue($column, $value, $col);
}
}
$this -> afterLoad();
return $this;
} | [
"public",
"function",
"fromArray",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type Array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"data",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"beforeLoad",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"convertToDate",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"convertJsonToArray",
"(",
"$",
"value",
")",
";",
"$",
"col",
"=",
"NameConvert",
"::",
"toCamelcase",
"(",
"$",
"column",
",",
"true",
")",
";",
"$",
"method",
"=",
"'set'",
".",
"$",
"col",
";",
"if",
"(",
"true",
"===",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"$",
"method",
"]",
",",
"[",
"$",
"value",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addValue",
"(",
"$",
"column",
",",
"$",
"value",
",",
"$",
"col",
")",
";",
"}",
"}",
"$",
"this",
"->",
"afterLoad",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Converts given array to entity data
@param array $data
@return $this | [
"Converts",
"given",
"array",
"to",
"entity",
"data"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Entity.php#L187-L213 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Entity.php | Entity.toArray | public function toArray() {
$class = new \ReflectionClass($this);
$props = $class -> getProperties();
$data = [];
foreach($props as $prop) {
if($class -> name === $prop -> class) {
if(true === isset($this -> {$prop -> name})) {
$data[$prop -> name] = $this -> {$prop -> name};
}
}
}
foreach($this -> columns as $column) {
$data[key($column)] = $column[key($column)];
}
return $data;
} | php | public function toArray() {
$class = new \ReflectionClass($this);
$props = $class -> getProperties();
$data = [];
foreach($props as $prop) {
if($class -> name === $prop -> class) {
if(true === isset($this -> {$prop -> name})) {
$data[$prop -> name] = $this -> {$prop -> name};
}
}
}
foreach($this -> columns as $column) {
$data[key($column)] = $column[key($column)];
}
return $data;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
")",
";",
"$",
"props",
"=",
"$",
"class",
"->",
"getProperties",
"(",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"props",
"as",
"$",
"prop",
")",
"{",
"if",
"(",
"$",
"class",
"->",
"name",
"===",
"$",
"prop",
"->",
"class",
")",
"{",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"{",
"$",
"prop",
"->",
"name",
"}",
")",
")",
"{",
"$",
"data",
"[",
"$",
"prop",
"->",
"name",
"]",
"=",
"$",
"this",
"->",
"{",
"$",
"prop",
"->",
"name",
"}",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"columns",
"as",
"$",
"column",
")",
"{",
"$",
"data",
"[",
"key",
"(",
"$",
"column",
")",
"]",
"=",
"$",
"column",
"[",
"key",
"(",
"$",
"column",
")",
"]",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Returns all variables to a single Array
@return array | [
"Returns",
"all",
"variables",
"to",
"a",
"single",
"Array"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Entity.php#L220-L241 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Entity.php | Entity.setIdentifier | public function setIdentifier($identifier) {
if(false === is_array($identifier)) {
$identifier = [$identifier];
}
$this -> identifier = $identifier;
} | php | public function setIdentifier($identifier) {
if(false === is_array($identifier)) {
$identifier = [$identifier];
}
$this -> identifier = $identifier;
} | [
"public",
"function",
"setIdentifier",
"(",
"$",
"identifier",
")",
"{",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"identifier",
")",
")",
"{",
"$",
"identifier",
"=",
"[",
"$",
"identifier",
"]",
";",
"}",
"$",
"this",
"->",
"identifier",
"=",
"$",
"identifier",
";",
"}"
] | Sets the identifier
@param string|array $identifier | [
"Sets",
"the",
"identifier"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Entity.php#L275-L282 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Entity.php | Entity.setExclude | public function setExclude($exclude) {
if(false === is_array($exclude)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type Array, "%s" given', __METHOD__, gettype($exclude)), E_USER_ERROR);
}
$this -> exclude = $exclude;
return $this;
} | php | public function setExclude($exclude) {
if(false === is_array($exclude)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type Array, "%s" given', __METHOD__, gettype($exclude)), E_USER_ERROR);
}
$this -> exclude = $exclude;
return $this;
} | [
"public",
"function",
"setExclude",
"(",
"$",
"exclude",
")",
"{",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"exclude",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type Array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"exclude",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"exclude",
"=",
"$",
"exclude",
";",
"return",
"$",
"this",
";",
"}"
] | Sets exclude column names to be excluded when entity is saved. This will prevent data saved to MySQL generated columns which will trigger an error
@param string|array $identifier | [
"Sets",
"exclude",
"column",
"names",
"to",
"be",
"excluded",
"when",
"entity",
"is",
"saved",
".",
"This",
"will",
"prevent",
"data",
"saved",
"to",
"MySQL",
"generated",
"columns",
"which",
"will",
"trigger",
"an",
"error"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Entity.php#L289-L298 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Entity.php | Entity.getIdentifier | public function getIdentifier() {
if(false === isset($this -> identifier)) {
$cl = new \ReflectionClass($this);
return trigger_error(sprintf('No table identifier specified in "%s" class', $cl -> getFileName()), E_USER_ERROR);
}
return $this -> identifier;
} | php | public function getIdentifier() {
if(false === isset($this -> identifier)) {
$cl = new \ReflectionClass($this);
return trigger_error(sprintf('No table identifier specified in "%s" class', $cl -> getFileName()), E_USER_ERROR);
}
return $this -> identifier;
} | [
"public",
"function",
"getIdentifier",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"this",
"->",
"identifier",
")",
")",
"{",
"$",
"cl",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
")",
";",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'No table identifier specified in \"%s\" class'",
",",
"$",
"cl",
"->",
"getFileName",
"(",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"return",
"$",
"this",
"->",
"identifier",
";",
"}"
] | Returns the identifier
@return string | [
"Returns",
"the",
"identifier"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Entity.php#L305-L314 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Entity.php | Entity.save | public function save() {
if(null === $this -> getAdapter()) {
return trigger_error('Adapter is not set. Set the adapter with the setAdapter() method', E_USER_ERROR);
}
//Execute user defined before save function
$this -> beforeSave();
$class = new \ReflectionClass(get_class($this));
$values = $this -> toArray();
$columns = [];
array_walk($values, function($a, $b) use (&$columns, &$values) {
if(true === in_array($b, $this -> exclude)) {
unset($values[$b]);
return;
}
if($a instanceof DateTime) {
$values[$b] = $a -> loadFormat();
}
if(true === is_array($a)) {
$values[$b] = json_encode($a);
}
$columns[] = sprintf('`%s` = VALUES(`%s`)', $this -> getAdapter() -> escape($b), $this -> getAdapter() -> escape($b));
});
//Convert column names to column names with backtics
foreach($values as $column => $value) {
$values['`' . $column . '`'] = $value;
unset($values[$column]);
}
$query = sprintf('INSERT INTO %s (%s) VALUES(%s) ON DUPLICATE KEY UPDATE %s', $this -> getAdapter() -> escape($this -> getTable()), implode(array_keys($values), ', '), implode(array_fill(0, count($values), '?'), ','), implode($columns, ', '));
$this -> getAdapter() -> query($query, array_values($values));
$success = $this -> getAdapter() -> execute();
//Set new id if last id is not null
$id = $this -> getAdapter() -> getLastId();
$ids = $this -> getIdentifier();
$affected = $this -> getAdapter() -> getAffected();
if(count($ids) > 0 && $affected > 0) {
$method = sprintf('set%s', NameConvert :: toCamelcase($ids[0], true));
if(true === method_exists($this, $method)) {
call_user_func_array([$this, $method], [$id]);
}
}
//Execute user defined after save function
$this -> afterSave();
return $success;
} | php | public function save() {
if(null === $this -> getAdapter()) {
return trigger_error('Adapter is not set. Set the adapter with the setAdapter() method', E_USER_ERROR);
}
//Execute user defined before save function
$this -> beforeSave();
$class = new \ReflectionClass(get_class($this));
$values = $this -> toArray();
$columns = [];
array_walk($values, function($a, $b) use (&$columns, &$values) {
if(true === in_array($b, $this -> exclude)) {
unset($values[$b]);
return;
}
if($a instanceof DateTime) {
$values[$b] = $a -> loadFormat();
}
if(true === is_array($a)) {
$values[$b] = json_encode($a);
}
$columns[] = sprintf('`%s` = VALUES(`%s`)', $this -> getAdapter() -> escape($b), $this -> getAdapter() -> escape($b));
});
//Convert column names to column names with backtics
foreach($values as $column => $value) {
$values['`' . $column . '`'] = $value;
unset($values[$column]);
}
$query = sprintf('INSERT INTO %s (%s) VALUES(%s) ON DUPLICATE KEY UPDATE %s', $this -> getAdapter() -> escape($this -> getTable()), implode(array_keys($values), ', '), implode(array_fill(0, count($values), '?'), ','), implode($columns, ', '));
$this -> getAdapter() -> query($query, array_values($values));
$success = $this -> getAdapter() -> execute();
//Set new id if last id is not null
$id = $this -> getAdapter() -> getLastId();
$ids = $this -> getIdentifier();
$affected = $this -> getAdapter() -> getAffected();
if(count($ids) > 0 && $affected > 0) {
$method = sprintf('set%s', NameConvert :: toCamelcase($ids[0], true));
if(true === method_exists($this, $method)) {
call_user_func_array([$this, $method], [$id]);
}
}
//Execute user defined after save function
$this -> afterSave();
return $success;
} | [
"public",
"function",
"save",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"getAdapter",
"(",
")",
")",
"{",
"return",
"trigger_error",
"(",
"'Adapter is not set. Set the adapter with the setAdapter() method'",
",",
"E_USER_ERROR",
")",
";",
"}",
"//Execute user defined before save function\r",
"$",
"this",
"->",
"beforeSave",
"(",
")",
";",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"toArray",
"(",
")",
";",
"$",
"columns",
"=",
"[",
"]",
";",
"array_walk",
"(",
"$",
"values",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"&",
"$",
"columns",
",",
"&",
"$",
"values",
")",
"{",
"if",
"(",
"true",
"===",
"in_array",
"(",
"$",
"b",
",",
"$",
"this",
"->",
"exclude",
")",
")",
"{",
"unset",
"(",
"$",
"values",
"[",
"$",
"b",
"]",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"a",
"instanceof",
"DateTime",
")",
"{",
"$",
"values",
"[",
"$",
"b",
"]",
"=",
"$",
"a",
"->",
"loadFormat",
"(",
")",
";",
"}",
"if",
"(",
"true",
"===",
"is_array",
"(",
"$",
"a",
")",
")",
"{",
"$",
"values",
"[",
"$",
"b",
"]",
"=",
"json_encode",
"(",
"$",
"a",
")",
";",
"}",
"$",
"columns",
"[",
"]",
"=",
"sprintf",
"(",
"'`%s` = VALUES(`%s`)'",
",",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"escape",
"(",
"$",
"b",
")",
",",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"escape",
"(",
"$",
"b",
")",
")",
";",
"}",
")",
";",
"//Convert column names to column names with backtics\r",
"foreach",
"(",
"$",
"values",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"values",
"[",
"'`'",
".",
"$",
"column",
".",
"'`'",
"]",
"=",
"$",
"value",
";",
"unset",
"(",
"$",
"values",
"[",
"$",
"column",
"]",
")",
";",
"}",
"$",
"query",
"=",
"sprintf",
"(",
"'INSERT INTO %s (%s) VALUES(%s) ON DUPLICATE KEY UPDATE %s'",
",",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"escape",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
")",
",",
"implode",
"(",
"array_keys",
"(",
"$",
"values",
")",
",",
"', '",
")",
",",
"implode",
"(",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"values",
")",
",",
"'?'",
")",
",",
"','",
")",
",",
"implode",
"(",
"$",
"columns",
",",
"', '",
")",
")",
";",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"query",
"(",
"$",
"query",
",",
"array_values",
"(",
"$",
"values",
")",
")",
";",
"$",
"success",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"execute",
"(",
")",
";",
"//Set new id if last id is not null\r",
"$",
"id",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"getLastId",
"(",
")",
";",
"$",
"ids",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
")",
";",
"$",
"affected",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"getAffected",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"ids",
")",
">",
"0",
"&&",
"$",
"affected",
">",
"0",
")",
"{",
"$",
"method",
"=",
"sprintf",
"(",
"'set%s'",
",",
"NameConvert",
"::",
"toCamelcase",
"(",
"$",
"ids",
"[",
"0",
"]",
",",
"true",
")",
")",
";",
"if",
"(",
"true",
"===",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"$",
"method",
"]",
",",
"[",
"$",
"id",
"]",
")",
";",
"}",
"}",
"//Execute user defined after save function\r",
"$",
"this",
"->",
"afterSave",
"(",
")",
";",
"return",
"$",
"success",
";",
"}"
] | Inserts or updates entity based on identifier
@return boolean | [
"Inserts",
"or",
"updates",
"entity",
"based",
"on",
"identifier"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Entity.php#L330-L393 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Entity.php | Entity.delete | public function delete() {
if(null === $this -> getAdapter()) {
return trigger_error('Adapter is not set. Set the adapter with the setAdapter() method', E_USER_ERROR);
}
//Execute user defined before deleting function
$this -> beforeDelete();
$class = new \ReflectionClass(get_class($this));
$identifiers = $this -> getIdentifier();
$values = $this -> toArray();
$ids = [];
$escape = [];
if(0 === count($identifiers)) {
return trigger_error(sprintf('Identifier is NULL. Can not delete entity without a valid value as identifier in %s', $class -> getFileName()), E_USER_ERROR);
}
foreach($identifiers as $identifier) {
$ids[] = sprintf('%s = ?', $this -> getAdapter() -> escape($identifier));
if(true === isset($values[$identifier])) {
$escape[] = $values[$identifier];
}
else {
$escape[] = null;
}
}
$query = sprintf('DELETE FROM %s WHERE %s LIMIT 1', $this -> getAdapter() -> escape($this -> getTable()), implode($ids, ' AND '));
$this -> getAdapter() -> query($query, $escape);
$success = $this -> getAdapter() -> execute();
//Execute user defined after deleting function
$this -> afterDelete();
return $success;
} | php | public function delete() {
if(null === $this -> getAdapter()) {
return trigger_error('Adapter is not set. Set the adapter with the setAdapter() method', E_USER_ERROR);
}
//Execute user defined before deleting function
$this -> beforeDelete();
$class = new \ReflectionClass(get_class($this));
$identifiers = $this -> getIdentifier();
$values = $this -> toArray();
$ids = [];
$escape = [];
if(0 === count($identifiers)) {
return trigger_error(sprintf('Identifier is NULL. Can not delete entity without a valid value as identifier in %s', $class -> getFileName()), E_USER_ERROR);
}
foreach($identifiers as $identifier) {
$ids[] = sprintf('%s = ?', $this -> getAdapter() -> escape($identifier));
if(true === isset($values[$identifier])) {
$escape[] = $values[$identifier];
}
else {
$escape[] = null;
}
}
$query = sprintf('DELETE FROM %s WHERE %s LIMIT 1', $this -> getAdapter() -> escape($this -> getTable()), implode($ids, ' AND '));
$this -> getAdapter() -> query($query, $escape);
$success = $this -> getAdapter() -> execute();
//Execute user defined after deleting function
$this -> afterDelete();
return $success;
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"getAdapter",
"(",
")",
")",
"{",
"return",
"trigger_error",
"(",
"'Adapter is not set. Set the adapter with the setAdapter() method'",
",",
"E_USER_ERROR",
")",
";",
"}",
"//Execute user defined before deleting function\r",
"$",
"this",
"->",
"beforeDelete",
"(",
")",
";",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"$",
"identifiers",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
")",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"toArray",
"(",
")",
";",
"$",
"ids",
"=",
"[",
"]",
";",
"$",
"escape",
"=",
"[",
"]",
";",
"if",
"(",
"0",
"===",
"count",
"(",
"$",
"identifiers",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Identifier is NULL. Can not delete entity without a valid value as identifier in %s'",
",",
"$",
"class",
"->",
"getFileName",
"(",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"foreach",
"(",
"$",
"identifiers",
"as",
"$",
"identifier",
")",
"{",
"$",
"ids",
"[",
"]",
"=",
"sprintf",
"(",
"'%s = ?'",
",",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"escape",
"(",
"$",
"identifier",
")",
")",
";",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"values",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"$",
"escape",
"[",
"]",
"=",
"$",
"values",
"[",
"$",
"identifier",
"]",
";",
"}",
"else",
"{",
"$",
"escape",
"[",
"]",
"=",
"null",
";",
"}",
"}",
"$",
"query",
"=",
"sprintf",
"(",
"'DELETE FROM %s WHERE %s LIMIT 1'",
",",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"escape",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
")",
",",
"implode",
"(",
"$",
"ids",
",",
"' AND '",
")",
")",
";",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"query",
"(",
"$",
"query",
",",
"$",
"escape",
")",
";",
"$",
"success",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"execute",
"(",
")",
";",
"//Execute user defined after deleting function\r",
"$",
"this",
"->",
"afterDelete",
"(",
")",
";",
"return",
"$",
"success",
";",
"}"
] | Delete the current entitiy based on identifier
@return boolean | [
"Delete",
"the",
"current",
"entitiy",
"based",
"on",
"identifier"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Entity.php#L400-L441 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Entity.php | Entity.convertToDate | public function convertToDate($value) {
foreach($this -> date_formats as $format) {
if(false !== \DateTime :: createFromFormat($format, $value)) {
$d = new DateTime($value);
$d -> createFromFormat($format, $value);
if($d && $d -> format($format) == $value) {
$d -> saveFormat($format);
return $d;
}
}
}
return $value;
} | php | public function convertToDate($value) {
foreach($this -> date_formats as $format) {
if(false !== \DateTime :: createFromFormat($format, $value)) {
$d = new DateTime($value);
$d -> createFromFormat($format, $value);
if($d && $d -> format($format) == $value) {
$d -> saveFormat($format);
return $d;
}
}
}
return $value;
} | [
"public",
"function",
"convertToDate",
"(",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"date_formats",
"as",
"$",
"format",
")",
"{",
"if",
"(",
"false",
"!==",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"value",
")",
")",
"{",
"$",
"d",
"=",
"new",
"DateTime",
"(",
"$",
"value",
")",
";",
"$",
"d",
"->",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"d",
"&&",
"$",
"d",
"->",
"format",
"(",
"$",
"format",
")",
"==",
"$",
"value",
")",
"{",
"$",
"d",
"->",
"saveFormat",
"(",
"$",
"format",
")",
";",
"return",
"$",
"d",
";",
"}",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] | Tries to check if given value is a valid date. If so, return the used format and returns a sFire DateTime object. Otherwise, returns the given value
@param string $value
@return mixed | [
"Tries",
"to",
"check",
"if",
"given",
"value",
"is",
"a",
"valid",
"date",
".",
"If",
"so",
"return",
"the",
"used",
"format",
"and",
"returns",
"a",
"sFire",
"DateTime",
"object",
".",
"Otherwise",
"returns",
"the",
"given",
"value"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Entity.php#L565-L583 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Entity.php | Entity.convertJsonToArray | public function convertJsonToArray($value) {
if(true === $this -> convert_json) {
if(true === is_string($value)) {
$tmp = @json_decode($value, true);
if(true === (json_last_error() == JSON_ERROR_NONE)) {
$value = $tmp;
}
}
}
return $value;
} | php | public function convertJsonToArray($value) {
if(true === $this -> convert_json) {
if(true === is_string($value)) {
$tmp = @json_decode($value, true);
if(true === (json_last_error() == JSON_ERROR_NONE)) {
$value = $tmp;
}
}
}
return $value;
} | [
"public",
"function",
"convertJsonToArray",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"convert_json",
")",
"{",
"if",
"(",
"true",
"===",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"tmp",
"=",
"@",
"json_decode",
"(",
"$",
"value",
",",
"true",
")",
";",
"if",
"(",
"true",
"===",
"(",
"json_last_error",
"(",
")",
"==",
"JSON_ERROR_NONE",
")",
")",
"{",
"$",
"value",
"=",
"$",
"tmp",
";",
"}",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] | Tries covnert values to JSON strings. Otherwise, returns the given value
@param string $value
@return mixed | [
"Tries",
"covnert",
"values",
"to",
"JSON",
"strings",
".",
"Otherwise",
"returns",
"the",
"given",
"value"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Entity.php#L591-L606 | train |
mylxsw/FocusPHP | src/Config/ArrayConfig.php | ArrayConfig.get | public function get($key, $default = null)
{
if (!isset($this->_configs[$key])) {
$cfg = get_cfg_var($key);
if ($cfg !== false) {
return $cfg;
}
return $default;
}
return $this->_configs[$key];
} | php | public function get($key, $default = null)
{
if (!isset($this->_configs[$key])) {
$cfg = get_cfg_var($key);
if ($cfg !== false) {
return $cfg;
}
return $default;
}
return $this->_configs[$key];
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_configs",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"cfg",
"=",
"get_cfg_var",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"cfg",
"!==",
"false",
")",
"{",
"return",
"$",
"cfg",
";",
"}",
"return",
"$",
"default",
";",
"}",
"return",
"$",
"this",
"->",
"_configs",
"[",
"$",
"key",
"]",
";",
"}"
] | Get config info.
@param string $key
@param mixed $default
@return null|string | [
"Get",
"config",
"info",
"."
] | 33922bacbea66f11f874d991d7308a36cdf5831a | https://github.com/mylxsw/FocusPHP/blob/33922bacbea66f11f874d991d7308a36cdf5831a/src/Config/ArrayConfig.php#L32-L44 | train |
koolkode/context | src/ContainerCompiler.php | ContainerCompiler.compile | public function compile(ContainerBuilder $builder, $proxyCachePath = NULL, array $additionalProxies = [])
{
try
{
return $this->compileBuilder($builder, $proxyCachePath, $additionalProxies);
}
finally
{
$this->methods = [];
$this->namespaceContextCache = [];
}
} | php | public function compile(ContainerBuilder $builder, $proxyCachePath = NULL, array $additionalProxies = [])
{
try
{
return $this->compileBuilder($builder, $proxyCachePath, $additionalProxies);
}
finally
{
$this->methods = [];
$this->namespaceContextCache = [];
}
} | [
"public",
"function",
"compile",
"(",
"ContainerBuilder",
"$",
"builder",
",",
"$",
"proxyCachePath",
"=",
"NULL",
",",
"array",
"$",
"additionalProxies",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"compileBuilder",
"(",
"$",
"builder",
",",
"$",
"proxyCachePath",
",",
"$",
"additionalProxies",
")",
";",
"}",
"finally",
"{",
"$",
"this",
"->",
"methods",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"namespaceContextCache",
"=",
"[",
"]",
";",
"}",
"}"
] | Generate PHP code of an optimized DI container from the given builder.
@param ContainerBuilder $builder
@param string $proxyCachePath Cache directory for scoped proxies, NULL deactivates pre-generation of proxies.
@param array<string> $additionalProxies Additional type names that need a scoped proxy.
@return string | [
"Generate",
"PHP",
"code",
"of",
"an",
"optimized",
"DI",
"container",
"from",
"the",
"given",
"builder",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/ContainerCompiler.php#L69-L80 | train |
koolkode/context | src/ContainerCompiler.php | ContainerCompiler.compileBuilder | protected function compileBuilder(ContainerBuilder $builder, $proxyCachePath = NULL, array $additionalProxies = [])
{
$imports = [
DelegateBinding::class,
ContextLookupException::class,
InjectionPoint::class,
InjectionPointInterface::class
];
$code = '<?php' . "\n\n";
$code .= 'namespace ' . $this->namespace . " {\n";
foreach($imports as $typeName)
{
$code .= "\nuse " . ltrim($typeName, '\\') . ";";
}
if(!empty($imports))
{
$code .= "\n";
}
$code .= "\nfinal class {$this->typeName} extends \KoolKode\Context\CompiledContainer {\n\n";
$bindings = $builder->getBindings();
$marked = [];
// Write bound properties:
$bound = [];
foreach($bindings as $binding)
{
$bound[$binding->getTypeName()] = true;
}
$code .= "\tprotected \$bound = " . var_export($bound, true) . ";\n";
foreach($bindings as $binding)
{
foreach($binding->getMarkers() as $marker)
{
$marked[get_class($marker)][(string)$binding] = $binding;
}
$code .= $this->compileBinding($binding);
}
$code .= $this->compileMarkerLookup($marked);
foreach($this->methods as $method)
{
$code .= "\n\n" . $method . "\n";
}
if($proxyCachePath !== NULL)
{
$code .= $this->compileScopedProxies($builder, $proxyCachePath, $additionalProxies);
}
$code .= "}\n\n";
$code .= "}\n\n";
return $code;
} | php | protected function compileBuilder(ContainerBuilder $builder, $proxyCachePath = NULL, array $additionalProxies = [])
{
$imports = [
DelegateBinding::class,
ContextLookupException::class,
InjectionPoint::class,
InjectionPointInterface::class
];
$code = '<?php' . "\n\n";
$code .= 'namespace ' . $this->namespace . " {\n";
foreach($imports as $typeName)
{
$code .= "\nuse " . ltrim($typeName, '\\') . ";";
}
if(!empty($imports))
{
$code .= "\n";
}
$code .= "\nfinal class {$this->typeName} extends \KoolKode\Context\CompiledContainer {\n\n";
$bindings = $builder->getBindings();
$marked = [];
// Write bound properties:
$bound = [];
foreach($bindings as $binding)
{
$bound[$binding->getTypeName()] = true;
}
$code .= "\tprotected \$bound = " . var_export($bound, true) . ";\n";
foreach($bindings as $binding)
{
foreach($binding->getMarkers() as $marker)
{
$marked[get_class($marker)][(string)$binding] = $binding;
}
$code .= $this->compileBinding($binding);
}
$code .= $this->compileMarkerLookup($marked);
foreach($this->methods as $method)
{
$code .= "\n\n" . $method . "\n";
}
if($proxyCachePath !== NULL)
{
$code .= $this->compileScopedProxies($builder, $proxyCachePath, $additionalProxies);
}
$code .= "}\n\n";
$code .= "}\n\n";
return $code;
} | [
"protected",
"function",
"compileBuilder",
"(",
"ContainerBuilder",
"$",
"builder",
",",
"$",
"proxyCachePath",
"=",
"NULL",
",",
"array",
"$",
"additionalProxies",
"=",
"[",
"]",
")",
"{",
"$",
"imports",
"=",
"[",
"DelegateBinding",
"::",
"class",
",",
"ContextLookupException",
"::",
"class",
",",
"InjectionPoint",
"::",
"class",
",",
"InjectionPointInterface",
"::",
"class",
"]",
";",
"$",
"code",
"=",
"'<?php'",
".",
"\"\\n\\n\"",
";",
"$",
"code",
".=",
"'namespace '",
".",
"$",
"this",
"->",
"namespace",
".",
"\" {\\n\"",
";",
"foreach",
"(",
"$",
"imports",
"as",
"$",
"typeName",
")",
"{",
"$",
"code",
".=",
"\"\\nuse \"",
".",
"ltrim",
"(",
"$",
"typeName",
",",
"'\\\\'",
")",
".",
"\";\"",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"imports",
")",
")",
"{",
"$",
"code",
".=",
"\"\\n\"",
";",
"}",
"$",
"code",
".=",
"\"\\nfinal class {$this->typeName} extends \\KoolKode\\Context\\CompiledContainer {\\n\\n\"",
";",
"$",
"bindings",
"=",
"$",
"builder",
"->",
"getBindings",
"(",
")",
";",
"$",
"marked",
"=",
"[",
"]",
";",
"// Write bound properties:",
"$",
"bound",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"bindings",
"as",
"$",
"binding",
")",
"{",
"$",
"bound",
"[",
"$",
"binding",
"->",
"getTypeName",
"(",
")",
"]",
"=",
"true",
";",
"}",
"$",
"code",
".=",
"\"\\tprotected \\$bound = \"",
".",
"var_export",
"(",
"$",
"bound",
",",
"true",
")",
".",
"\";\\n\"",
";",
"foreach",
"(",
"$",
"bindings",
"as",
"$",
"binding",
")",
"{",
"foreach",
"(",
"$",
"binding",
"->",
"getMarkers",
"(",
")",
"as",
"$",
"marker",
")",
"{",
"$",
"marked",
"[",
"get_class",
"(",
"$",
"marker",
")",
"]",
"[",
"(",
"string",
")",
"$",
"binding",
"]",
"=",
"$",
"binding",
";",
"}",
"$",
"code",
".=",
"$",
"this",
"->",
"compileBinding",
"(",
"$",
"binding",
")",
";",
"}",
"$",
"code",
".=",
"$",
"this",
"->",
"compileMarkerLookup",
"(",
"$",
"marked",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"methods",
"as",
"$",
"method",
")",
"{",
"$",
"code",
".=",
"\"\\n\\n\"",
".",
"$",
"method",
".",
"\"\\n\"",
";",
"}",
"if",
"(",
"$",
"proxyCachePath",
"!==",
"NULL",
")",
"{",
"$",
"code",
".=",
"$",
"this",
"->",
"compileScopedProxies",
"(",
"$",
"builder",
",",
"$",
"proxyCachePath",
",",
"$",
"additionalProxies",
")",
";",
"}",
"$",
"code",
".=",
"\"}\\n\\n\"",
";",
"$",
"code",
".=",
"\"}\\n\\n\"",
";",
"return",
"$",
"code",
";",
"}"
] | Compiles the given container builder and takes care of scoped proxy generation.
@param ContainerBuilder $builder
@param string $proxyCachePath
@param array<string> $additionalProxies
@return string | [
"Compiles",
"the",
"given",
"container",
"builder",
"and",
"takes",
"care",
"of",
"scoped",
"proxy",
"generation",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/ContainerCompiler.php#L90-L154 | train |
koolkode/context | src/ContainerCompiler.php | ContainerCompiler.compileBinding | protected function compileBinding(Binding $binding)
{
$prop = str_replace('\\', '_', $binding->getTypeName());
$code = "\tpublic function binding_" . $prop . "() {\n\n";
$code .= "\t\t\t\$binding = new DelegateBinding(" . var_export($binding->getTypeName(), true);
$code .= ', ' . var_export($binding->getScope(), true);
$code .= ', ' . var_export($binding->getOptions(), true) . ', function(InjectionPointInterface $point = NULL) {' . "\n";
switch($binding->getOptions() & BindingInterface::MASK_TYPE)
{
case BindingInterface::TYPE_ALIAS:
$code .= "return \$this->get(" . var_export($binding->getTarget(), true) . ", \$point);\n";
break;
case BindingInterface::TYPE_IMPLEMENTATION:
$code .= $this->compileImplementationBinding($binding);
break;
case BindingInterface::TYPE_FACTORY_ALIAS:
$code .= $this->compileFactoryBinding($binding);
break;
case BindingInterface::TYPE_FACTORY:
$code .= $this->compileInlineFactoryBinding($binding);
}
$code .= "});\n";
$code .= "\t\treturn \$binding;\n";
$code .= "\t}\n\n";
return $code;
} | php | protected function compileBinding(Binding $binding)
{
$prop = str_replace('\\', '_', $binding->getTypeName());
$code = "\tpublic function binding_" . $prop . "() {\n\n";
$code .= "\t\t\t\$binding = new DelegateBinding(" . var_export($binding->getTypeName(), true);
$code .= ', ' . var_export($binding->getScope(), true);
$code .= ', ' . var_export($binding->getOptions(), true) . ', function(InjectionPointInterface $point = NULL) {' . "\n";
switch($binding->getOptions() & BindingInterface::MASK_TYPE)
{
case BindingInterface::TYPE_ALIAS:
$code .= "return \$this->get(" . var_export($binding->getTarget(), true) . ", \$point);\n";
break;
case BindingInterface::TYPE_IMPLEMENTATION:
$code .= $this->compileImplementationBinding($binding);
break;
case BindingInterface::TYPE_FACTORY_ALIAS:
$code .= $this->compileFactoryBinding($binding);
break;
case BindingInterface::TYPE_FACTORY:
$code .= $this->compileInlineFactoryBinding($binding);
}
$code .= "});\n";
$code .= "\t\treturn \$binding;\n";
$code .= "\t}\n\n";
return $code;
} | [
"protected",
"function",
"compileBinding",
"(",
"Binding",
"$",
"binding",
")",
"{",
"$",
"prop",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'_'",
",",
"$",
"binding",
"->",
"getTypeName",
"(",
")",
")",
";",
"$",
"code",
"=",
"\"\\tpublic function binding_\"",
".",
"$",
"prop",
".",
"\"() {\\n\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\t\\t\\$binding = new DelegateBinding(\"",
".",
"var_export",
"(",
"$",
"binding",
"->",
"getTypeName",
"(",
")",
",",
"true",
")",
";",
"$",
"code",
".=",
"', '",
".",
"var_export",
"(",
"$",
"binding",
"->",
"getScope",
"(",
")",
",",
"true",
")",
";",
"$",
"code",
".=",
"', '",
".",
"var_export",
"(",
"$",
"binding",
"->",
"getOptions",
"(",
")",
",",
"true",
")",
".",
"', function(InjectionPointInterface $point = NULL) {'",
".",
"\"\\n\"",
";",
"switch",
"(",
"$",
"binding",
"->",
"getOptions",
"(",
")",
"&",
"BindingInterface",
"::",
"MASK_TYPE",
")",
"{",
"case",
"BindingInterface",
"::",
"TYPE_ALIAS",
":",
"$",
"code",
".=",
"\"return \\$this->get(\"",
".",
"var_export",
"(",
"$",
"binding",
"->",
"getTarget",
"(",
")",
",",
"true",
")",
".",
"\", \\$point);\\n\"",
";",
"break",
";",
"case",
"BindingInterface",
"::",
"TYPE_IMPLEMENTATION",
":",
"$",
"code",
".=",
"$",
"this",
"->",
"compileImplementationBinding",
"(",
"$",
"binding",
")",
";",
"break",
";",
"case",
"BindingInterface",
"::",
"TYPE_FACTORY_ALIAS",
":",
"$",
"code",
".=",
"$",
"this",
"->",
"compileFactoryBinding",
"(",
"$",
"binding",
")",
";",
"break",
";",
"case",
"BindingInterface",
"::",
"TYPE_FACTORY",
":",
"$",
"code",
".=",
"$",
"this",
"->",
"compileInlineFactoryBinding",
"(",
"$",
"binding",
")",
";",
"}",
"$",
"code",
".=",
"\"});\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\treturn \\$binding;\\n\"",
";",
"$",
"code",
".=",
"\"\\t}\\n\\n\"",
";",
"return",
"$",
"code",
";",
"}"
] | Compiles PHP code for the given binding.
@param Binding $binding
@return string | [
"Compiles",
"PHP",
"code",
"for",
"the",
"given",
"binding",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/ContainerCompiler.php#L162-L192 | train |
koolkode/context | src/ContainerCompiler.php | ContainerCompiler.compileInlineFactoryBinding | protected function compileInlineFactoryBinding(Binding $binding)
{
$code = '';
$num = count($this->methods);
$ref = new \ReflectionFunction($binding->getTarget());
$sig = $this->generateReplacementMethodSignature($ref, $num);
$body = $this->extractClosureCode($ref);
$this->methods[] = "\t\t" . $sig . " {\n" . $body . "\n\t\t}";
$resolvers = (array)$binding->getResolvers();
foreach($ref->getParameters() as $param)
{
if($this->getParamType($param) === Configuration::class)
{
$con = "\$this->config->getConfig(" . var_export(str_replace('\\', '.', $binding->getTypeName()), true) . ')';
$resolvers[$param->name] = new CompiledCodeFragment($con);
}
}
foreach($ref->getParameters() as $param)
{
if(!$param->isOptional() && InjectionPointInterface::class === $this->getParamType($param))
{
$code .= "\t\tif(\$point === NULL) {\n";
$code .= "\t\t\tthrow new ContextLookupException(";
$code .= var_export(sprintf('Factory for %s requires access to an injection point', $binding->getTypeName()), true);
$code .= ");\n";
$code .= "\t\t}\n";
}
}
$call = $this->generateCallCode($binding->getTypeName(), $ref, $num, [], $resolvers);
$setterInjection = $binding->isMarked(SetterInjection::class);
$initializers = (array)$binding->getInitializers();
if(empty($initializers) && !$setterInjection)
{
$code .= "\t\treturn \$this->initialize(" . $call . ");\n";
}
else
{
$code .= "\t\t\$obj = \$this->initialize(" . $call . ");\n";
if($setterInjection)
{
$code .= "\t\t" . $this->compileSetterInjector($binding, false) . "\n";
}
foreach($initializers as $initializer)
{
$num = count($this->methods);
$ref = new \ReflectionFunction($initializer);
$sig = $this->generateReplacementMethodSignature($ref, $num);
$body = $this->extractClosureCode($ref);
$this->methods[] = "\t\t" . $sig . " {\n" . $body . "\n\t\t}";
$code .= "\t\t\$obj = " . $this->generateCallCode($binding->getTypeName(), $ref, $num, ['$obj']) . " ?: \$obj;\n";
}
$code .= "\t\treturn \$obj;\n";
}
return $code;
} | php | protected function compileInlineFactoryBinding(Binding $binding)
{
$code = '';
$num = count($this->methods);
$ref = new \ReflectionFunction($binding->getTarget());
$sig = $this->generateReplacementMethodSignature($ref, $num);
$body = $this->extractClosureCode($ref);
$this->methods[] = "\t\t" . $sig . " {\n" . $body . "\n\t\t}";
$resolvers = (array)$binding->getResolvers();
foreach($ref->getParameters() as $param)
{
if($this->getParamType($param) === Configuration::class)
{
$con = "\$this->config->getConfig(" . var_export(str_replace('\\', '.', $binding->getTypeName()), true) . ')';
$resolvers[$param->name] = new CompiledCodeFragment($con);
}
}
foreach($ref->getParameters() as $param)
{
if(!$param->isOptional() && InjectionPointInterface::class === $this->getParamType($param))
{
$code .= "\t\tif(\$point === NULL) {\n";
$code .= "\t\t\tthrow new ContextLookupException(";
$code .= var_export(sprintf('Factory for %s requires access to an injection point', $binding->getTypeName()), true);
$code .= ");\n";
$code .= "\t\t}\n";
}
}
$call = $this->generateCallCode($binding->getTypeName(), $ref, $num, [], $resolvers);
$setterInjection = $binding->isMarked(SetterInjection::class);
$initializers = (array)$binding->getInitializers();
if(empty($initializers) && !$setterInjection)
{
$code .= "\t\treturn \$this->initialize(" . $call . ");\n";
}
else
{
$code .= "\t\t\$obj = \$this->initialize(" . $call . ");\n";
if($setterInjection)
{
$code .= "\t\t" . $this->compileSetterInjector($binding, false) . "\n";
}
foreach($initializers as $initializer)
{
$num = count($this->methods);
$ref = new \ReflectionFunction($initializer);
$sig = $this->generateReplacementMethodSignature($ref, $num);
$body = $this->extractClosureCode($ref);
$this->methods[] = "\t\t" . $sig . " {\n" . $body . "\n\t\t}";
$code .= "\t\t\$obj = " . $this->generateCallCode($binding->getTypeName(), $ref, $num, ['$obj']) . " ?: \$obj;\n";
}
$code .= "\t\treturn \$obj;\n";
}
return $code;
} | [
"protected",
"function",
"compileInlineFactoryBinding",
"(",
"Binding",
"$",
"binding",
")",
"{",
"$",
"code",
"=",
"''",
";",
"$",
"num",
"=",
"count",
"(",
"$",
"this",
"->",
"methods",
")",
";",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"binding",
"->",
"getTarget",
"(",
")",
")",
";",
"$",
"sig",
"=",
"$",
"this",
"->",
"generateReplacementMethodSignature",
"(",
"$",
"ref",
",",
"$",
"num",
")",
";",
"$",
"body",
"=",
"$",
"this",
"->",
"extractClosureCode",
"(",
"$",
"ref",
")",
";",
"$",
"this",
"->",
"methods",
"[",
"]",
"=",
"\"\\t\\t\"",
".",
"$",
"sig",
".",
"\" {\\n\"",
".",
"$",
"body",
".",
"\"\\n\\t\\t}\"",
";",
"$",
"resolvers",
"=",
"(",
"array",
")",
"$",
"binding",
"->",
"getResolvers",
"(",
")",
";",
"foreach",
"(",
"$",
"ref",
"->",
"getParameters",
"(",
")",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getParamType",
"(",
"$",
"param",
")",
"===",
"Configuration",
"::",
"class",
")",
"{",
"$",
"con",
"=",
"\"\\$this->config->getConfig(\"",
".",
"var_export",
"(",
"str_replace",
"(",
"'\\\\'",
",",
"'.'",
",",
"$",
"binding",
"->",
"getTypeName",
"(",
")",
")",
",",
"true",
")",
".",
"')'",
";",
"$",
"resolvers",
"[",
"$",
"param",
"->",
"name",
"]",
"=",
"new",
"CompiledCodeFragment",
"(",
"$",
"con",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"ref",
"->",
"getParameters",
"(",
")",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"!",
"$",
"param",
"->",
"isOptional",
"(",
")",
"&&",
"InjectionPointInterface",
"::",
"class",
"===",
"$",
"this",
"->",
"getParamType",
"(",
"$",
"param",
")",
")",
"{",
"$",
"code",
".=",
"\"\\t\\tif(\\$point === NULL) {\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\t\\tthrow new ContextLookupException(\"",
";",
"$",
"code",
".=",
"var_export",
"(",
"sprintf",
"(",
"'Factory for %s requires access to an injection point'",
",",
"$",
"binding",
"->",
"getTypeName",
"(",
")",
")",
",",
"true",
")",
";",
"$",
"code",
".=",
"\");\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\t}\\n\"",
";",
"}",
"}",
"$",
"call",
"=",
"$",
"this",
"->",
"generateCallCode",
"(",
"$",
"binding",
"->",
"getTypeName",
"(",
")",
",",
"$",
"ref",
",",
"$",
"num",
",",
"[",
"]",
",",
"$",
"resolvers",
")",
";",
"$",
"setterInjection",
"=",
"$",
"binding",
"->",
"isMarked",
"(",
"SetterInjection",
"::",
"class",
")",
";",
"$",
"initializers",
"=",
"(",
"array",
")",
"$",
"binding",
"->",
"getInitializers",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"initializers",
")",
"&&",
"!",
"$",
"setterInjection",
")",
"{",
"$",
"code",
".=",
"\"\\t\\treturn \\$this->initialize(\"",
".",
"$",
"call",
".",
"\");\\n\"",
";",
"}",
"else",
"{",
"$",
"code",
".=",
"\"\\t\\t\\$obj = \\$this->initialize(\"",
".",
"$",
"call",
".",
"\");\\n\"",
";",
"if",
"(",
"$",
"setterInjection",
")",
"{",
"$",
"code",
".=",
"\"\\t\\t\"",
".",
"$",
"this",
"->",
"compileSetterInjector",
"(",
"$",
"binding",
",",
"false",
")",
".",
"\"\\n\"",
";",
"}",
"foreach",
"(",
"$",
"initializers",
"as",
"$",
"initializer",
")",
"{",
"$",
"num",
"=",
"count",
"(",
"$",
"this",
"->",
"methods",
")",
";",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"initializer",
")",
";",
"$",
"sig",
"=",
"$",
"this",
"->",
"generateReplacementMethodSignature",
"(",
"$",
"ref",
",",
"$",
"num",
")",
";",
"$",
"body",
"=",
"$",
"this",
"->",
"extractClosureCode",
"(",
"$",
"ref",
")",
";",
"$",
"this",
"->",
"methods",
"[",
"]",
"=",
"\"\\t\\t\"",
".",
"$",
"sig",
".",
"\" {\\n\"",
".",
"$",
"body",
".",
"\"\\n\\t\\t}\"",
";",
"$",
"code",
".=",
"\"\\t\\t\\$obj = \"",
".",
"$",
"this",
"->",
"generateCallCode",
"(",
"$",
"binding",
"->",
"getTypeName",
"(",
")",
",",
"$",
"ref",
",",
"$",
"num",
",",
"[",
"'$obj'",
"]",
")",
".",
"\" ?: \\$obj;\\n\"",
";",
"}",
"$",
"code",
".=",
"\"\\t\\treturn \\$obj;\\n\"",
";",
"}",
"return",
"$",
"code",
";",
"}"
] | Compiles an inline factory binding by creating a replacement method in the DI container.
@param Binding $binding
@return string | [
"Compiles",
"an",
"inline",
"factory",
"binding",
"by",
"creating",
"a",
"replacement",
"method",
"in",
"the",
"DI",
"container",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/ContainerCompiler.php#L361-L431 | train |
koolkode/context | src/ContainerCompiler.php | ContainerCompiler.compileMarkerLookup | protected function compileMarkerLookup(array $marked)
{
$code = '';
foreach($marked as $markerType => $markedBindings)
{
$code .= "\tpublic function markedBindings_" . str_replace('\\', '_', $markerType) . "() {\n";
$code .= "\t\tstatic \$bindings;\n";
$code .= "\t\tif(\$bindings === NULL) {\n";
$code .= "\t\t\t\$bindings = [\n";
$index = 0;
foreach($markedBindings as $binding)
{
foreach($binding->getMarkers() as $marker)
{
if(!$marker instanceof $markerType)
{
continue;
}
if($index++ != 0)
{
$code .= ",\n";
}
$vars = get_object_vars($marker);
$code .= "\t\t\t\t[\$this->reviveMarker(";
$code .= var_export(get_class($marker), true);
if(!empty($vars))
{
$code .= ', ' . var_export($vars, true);
}
$prop = str_replace('\\', '_', $binding->getTypeName());
$code .= "), (\$this->bound[" . var_export($binding->getTypeName(), true);
$code .= "] !== true) ? \$this->bound[" . var_export($binding->getTypeName(), true);
$code .= "] : (\$this->bound[" . var_export($binding->getTypeName(), true);
$code .= "] = \$this->binding_$prop())]";
}
}
$code .= "\n\t\t\t];\n\t\t}\n";
$code .= "\t\treturn \$bindings;\n";
$code .= "\t}\n\n";
}
return $code;
} | php | protected function compileMarkerLookup(array $marked)
{
$code = '';
foreach($marked as $markerType => $markedBindings)
{
$code .= "\tpublic function markedBindings_" . str_replace('\\', '_', $markerType) . "() {\n";
$code .= "\t\tstatic \$bindings;\n";
$code .= "\t\tif(\$bindings === NULL) {\n";
$code .= "\t\t\t\$bindings = [\n";
$index = 0;
foreach($markedBindings as $binding)
{
foreach($binding->getMarkers() as $marker)
{
if(!$marker instanceof $markerType)
{
continue;
}
if($index++ != 0)
{
$code .= ",\n";
}
$vars = get_object_vars($marker);
$code .= "\t\t\t\t[\$this->reviveMarker(";
$code .= var_export(get_class($marker), true);
if(!empty($vars))
{
$code .= ', ' . var_export($vars, true);
}
$prop = str_replace('\\', '_', $binding->getTypeName());
$code .= "), (\$this->bound[" . var_export($binding->getTypeName(), true);
$code .= "] !== true) ? \$this->bound[" . var_export($binding->getTypeName(), true);
$code .= "] : (\$this->bound[" . var_export($binding->getTypeName(), true);
$code .= "] = \$this->binding_$prop())]";
}
}
$code .= "\n\t\t\t];\n\t\t}\n";
$code .= "\t\treturn \$bindings;\n";
$code .= "\t}\n\n";
}
return $code;
} | [
"protected",
"function",
"compileMarkerLookup",
"(",
"array",
"$",
"marked",
")",
"{",
"$",
"code",
"=",
"''",
";",
"foreach",
"(",
"$",
"marked",
"as",
"$",
"markerType",
"=>",
"$",
"markedBindings",
")",
"{",
"$",
"code",
".=",
"\"\\tpublic function markedBindings_\"",
".",
"str_replace",
"(",
"'\\\\'",
",",
"'_'",
",",
"$",
"markerType",
")",
".",
"\"() {\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\tstatic \\$bindings;\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\tif(\\$bindings === NULL) {\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\t\\t\\$bindings = [\\n\"",
";",
"$",
"index",
"=",
"0",
";",
"foreach",
"(",
"$",
"markedBindings",
"as",
"$",
"binding",
")",
"{",
"foreach",
"(",
"$",
"binding",
"->",
"getMarkers",
"(",
")",
"as",
"$",
"marker",
")",
"{",
"if",
"(",
"!",
"$",
"marker",
"instanceof",
"$",
"markerType",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"index",
"++",
"!=",
"0",
")",
"{",
"$",
"code",
".=",
"\",\\n\"",
";",
"}",
"$",
"vars",
"=",
"get_object_vars",
"(",
"$",
"marker",
")",
";",
"$",
"code",
".=",
"\"\\t\\t\\t\\t[\\$this->reviveMarker(\"",
";",
"$",
"code",
".=",
"var_export",
"(",
"get_class",
"(",
"$",
"marker",
")",
",",
"true",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"vars",
")",
")",
"{",
"$",
"code",
".=",
"', '",
".",
"var_export",
"(",
"$",
"vars",
",",
"true",
")",
";",
"}",
"$",
"prop",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'_'",
",",
"$",
"binding",
"->",
"getTypeName",
"(",
")",
")",
";",
"$",
"code",
".=",
"\"), (\\$this->bound[\"",
".",
"var_export",
"(",
"$",
"binding",
"->",
"getTypeName",
"(",
")",
",",
"true",
")",
";",
"$",
"code",
".=",
"\"] !== true) ? \\$this->bound[\"",
".",
"var_export",
"(",
"$",
"binding",
"->",
"getTypeName",
"(",
")",
",",
"true",
")",
";",
"$",
"code",
".=",
"\"] : (\\$this->bound[\"",
".",
"var_export",
"(",
"$",
"binding",
"->",
"getTypeName",
"(",
")",
",",
"true",
")",
";",
"$",
"code",
".=",
"\"] = \\$this->binding_$prop())]\"",
";",
"}",
"}",
"$",
"code",
".=",
"\"\\n\\t\\t\\t];\\n\\t\\t}\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\treturn \\$bindings;\\n\"",
";",
"$",
"code",
".=",
"\"\\t}\\n\\n\"",
";",
"}",
"return",
"$",
"code",
";",
"}"
] | Compiles lookup methods for marked bindings.
@param array<string, array<string, Binding>> $marked
@return string | [
"Compiles",
"lookup",
"methods",
"for",
"marked",
"bindings",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/ContainerCompiler.php#L439-L491 | train |
koolkode/context | src/ContainerCompiler.php | ContainerCompiler.compileScopedProxies | protected function compileScopedProxies(ContainerBuilder $builder, $proxyCachePath, array $additionalProxies = [])
{
$code = "\t\tpublic function loadScopedProxy(\$typeName) {\n";
$code .= "\t\tswitch(\$typeName) {\n";
$proxyTypes = [];
foreach($builder->getProxyBindings() as $binding)
{
$ref = new \ReflectionClass($binding->getTypeName());
$proxyTypes[$ref->name] = $ref;
}
foreach($additionalProxies as $add)
{
$ref = new \ReflectionClass($add);
$proxyTypes[$ref->name] = $ref;
}
foreach($proxyTypes as $ref)
{
$parent = $ref;
$mtime = filemtime($ref->getFileName());
while($parent = $ref->getParentClass())
{
$mtime = max($mtime, filemtime($parent->getFileName()));
}
$file = $proxyCachePath . '/' . md5(strtolower($ref->name)) . '.php';
$create = !is_file($file) || filemtime($file) < $mtime;
if($create)
{
$proxyCode = '<?php' . "\n\n" . $this->proxyGenerator->generateProxyCode($ref);
Filesystem::writeFile($file, $proxyCode);
}
$code .= "\t\t\tcase " . var_export($ref->name, true) . ":\n";
$code .= "\t\t\t\trequire_once " . var_export($file, true) . ";\n";
$code .= "\t\t\t\treturn \$typeName . '__scoped';\n";
$code .= "\t\t\t\tbreak;\n";
}
$code .= "\t\t}\n";
$code .= "\t\treturn parent::loadScopedProxy(\$typeName);\n";
$code .= "\t\t}\n\n";
return $code;
} | php | protected function compileScopedProxies(ContainerBuilder $builder, $proxyCachePath, array $additionalProxies = [])
{
$code = "\t\tpublic function loadScopedProxy(\$typeName) {\n";
$code .= "\t\tswitch(\$typeName) {\n";
$proxyTypes = [];
foreach($builder->getProxyBindings() as $binding)
{
$ref = new \ReflectionClass($binding->getTypeName());
$proxyTypes[$ref->name] = $ref;
}
foreach($additionalProxies as $add)
{
$ref = new \ReflectionClass($add);
$proxyTypes[$ref->name] = $ref;
}
foreach($proxyTypes as $ref)
{
$parent = $ref;
$mtime = filemtime($ref->getFileName());
while($parent = $ref->getParentClass())
{
$mtime = max($mtime, filemtime($parent->getFileName()));
}
$file = $proxyCachePath . '/' . md5(strtolower($ref->name)) . '.php';
$create = !is_file($file) || filemtime($file) < $mtime;
if($create)
{
$proxyCode = '<?php' . "\n\n" . $this->proxyGenerator->generateProxyCode($ref);
Filesystem::writeFile($file, $proxyCode);
}
$code .= "\t\t\tcase " . var_export($ref->name, true) . ":\n";
$code .= "\t\t\t\trequire_once " . var_export($file, true) . ";\n";
$code .= "\t\t\t\treturn \$typeName . '__scoped';\n";
$code .= "\t\t\t\tbreak;\n";
}
$code .= "\t\t}\n";
$code .= "\t\treturn parent::loadScopedProxy(\$typeName);\n";
$code .= "\t\t}\n\n";
return $code;
} | [
"protected",
"function",
"compileScopedProxies",
"(",
"ContainerBuilder",
"$",
"builder",
",",
"$",
"proxyCachePath",
",",
"array",
"$",
"additionalProxies",
"=",
"[",
"]",
")",
"{",
"$",
"code",
"=",
"\"\\t\\tpublic function loadScopedProxy(\\$typeName) {\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\tswitch(\\$typeName) {\\n\"",
";",
"$",
"proxyTypes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"builder",
"->",
"getProxyBindings",
"(",
")",
"as",
"$",
"binding",
")",
"{",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"binding",
"->",
"getTypeName",
"(",
")",
")",
";",
"$",
"proxyTypes",
"[",
"$",
"ref",
"->",
"name",
"]",
"=",
"$",
"ref",
";",
"}",
"foreach",
"(",
"$",
"additionalProxies",
"as",
"$",
"add",
")",
"{",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"add",
")",
";",
"$",
"proxyTypes",
"[",
"$",
"ref",
"->",
"name",
"]",
"=",
"$",
"ref",
";",
"}",
"foreach",
"(",
"$",
"proxyTypes",
"as",
"$",
"ref",
")",
"{",
"$",
"parent",
"=",
"$",
"ref",
";",
"$",
"mtime",
"=",
"filemtime",
"(",
"$",
"ref",
"->",
"getFileName",
"(",
")",
")",
";",
"while",
"(",
"$",
"parent",
"=",
"$",
"ref",
"->",
"getParentClass",
"(",
")",
")",
"{",
"$",
"mtime",
"=",
"max",
"(",
"$",
"mtime",
",",
"filemtime",
"(",
"$",
"parent",
"->",
"getFileName",
"(",
")",
")",
")",
";",
"}",
"$",
"file",
"=",
"$",
"proxyCachePath",
".",
"'/'",
".",
"md5",
"(",
"strtolower",
"(",
"$",
"ref",
"->",
"name",
")",
")",
".",
"'.php'",
";",
"$",
"create",
"=",
"!",
"is_file",
"(",
"$",
"file",
")",
"||",
"filemtime",
"(",
"$",
"file",
")",
"<",
"$",
"mtime",
";",
"if",
"(",
"$",
"create",
")",
"{",
"$",
"proxyCode",
"=",
"'<?php'",
".",
"\"\\n\\n\"",
".",
"$",
"this",
"->",
"proxyGenerator",
"->",
"generateProxyCode",
"(",
"$",
"ref",
")",
";",
"Filesystem",
"::",
"writeFile",
"(",
"$",
"file",
",",
"$",
"proxyCode",
")",
";",
"}",
"$",
"code",
".=",
"\"\\t\\t\\tcase \"",
".",
"var_export",
"(",
"$",
"ref",
"->",
"name",
",",
"true",
")",
".",
"\":\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\t\\t\\trequire_once \"",
".",
"var_export",
"(",
"$",
"file",
",",
"true",
")",
".",
"\";\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\t\\t\\treturn \\$typeName . '__scoped';\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\t\\t\\tbreak;\\n\"",
";",
"}",
"$",
"code",
".=",
"\"\\t\\t}\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\treturn parent::loadScopedProxy(\\$typeName);\\n\"",
";",
"$",
"code",
".=",
"\"\\t\\t}\\n\\n\"",
";",
"return",
"$",
"code",
";",
"}"
] | Compiles scoped proxy types and saves them on the filesystem.
@param ContainerBuilder $builder
@param string $proxyCachePath
@param array<stribg> $additionalProxies
@return string | [
"Compiles",
"scoped",
"proxy",
"types",
"and",
"saves",
"them",
"on",
"the",
"filesystem",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/ContainerCompiler.php#L501-L551 | train |
koolkode/context | src/ContainerCompiler.php | ContainerCompiler.compileSetterInjector | protected function compileSetterInjector(Binding $binding, $wrapClosure = true)
{
$setters = $binding->getMarkers(SetterInjection::class);
if(empty($setters))
{
return 'NULL';
}
$setterTypeName = $binding->isImplementationBinding() ? $binding->getTarget() : $binding->getTypeName();
$code = $wrapClosure ? 'function($obj) { ' : '';
$ref = new \ReflectionClass($setterTypeName);
foreach($setters as $setter)
{
foreach($this->collectSetterMethods($ref, $setter) as $method)
{
$params = $method->getParameters();
if(empty($params))
{
continue;
}
$injector = '$obj->' . $method->getName() . '(';
foreach($params as $i => $param)
{
if(NULL === ($paramTypeName = $param->getClass()))
{
continue 2;
}
if($i != 0)
{
$injector .= ', ';
}
$nullable = $param->isOptional() ? 'Nullable' : '';
$injector .= '$this->get' . $nullable . '(' . var_export($paramTypeName->name, true) . ', new InjectionPoint(';
$injector .= 'get_class($obj), ' . var_export($method->getName(), true) . '))';
}
$code .= $injector . '); ';
}
}
return $wrapClosure ? ($code . '}') : $code;
} | php | protected function compileSetterInjector(Binding $binding, $wrapClosure = true)
{
$setters = $binding->getMarkers(SetterInjection::class);
if(empty($setters))
{
return 'NULL';
}
$setterTypeName = $binding->isImplementationBinding() ? $binding->getTarget() : $binding->getTypeName();
$code = $wrapClosure ? 'function($obj) { ' : '';
$ref = new \ReflectionClass($setterTypeName);
foreach($setters as $setter)
{
foreach($this->collectSetterMethods($ref, $setter) as $method)
{
$params = $method->getParameters();
if(empty($params))
{
continue;
}
$injector = '$obj->' . $method->getName() . '(';
foreach($params as $i => $param)
{
if(NULL === ($paramTypeName = $param->getClass()))
{
continue 2;
}
if($i != 0)
{
$injector .= ', ';
}
$nullable = $param->isOptional() ? 'Nullable' : '';
$injector .= '$this->get' . $nullable . '(' . var_export($paramTypeName->name, true) . ', new InjectionPoint(';
$injector .= 'get_class($obj), ' . var_export($method->getName(), true) . '))';
}
$code .= $injector . '); ';
}
}
return $wrapClosure ? ($code . '}') : $code;
} | [
"protected",
"function",
"compileSetterInjector",
"(",
"Binding",
"$",
"binding",
",",
"$",
"wrapClosure",
"=",
"true",
")",
"{",
"$",
"setters",
"=",
"$",
"binding",
"->",
"getMarkers",
"(",
"SetterInjection",
"::",
"class",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"setters",
")",
")",
"{",
"return",
"'NULL'",
";",
"}",
"$",
"setterTypeName",
"=",
"$",
"binding",
"->",
"isImplementationBinding",
"(",
")",
"?",
"$",
"binding",
"->",
"getTarget",
"(",
")",
":",
"$",
"binding",
"->",
"getTypeName",
"(",
")",
";",
"$",
"code",
"=",
"$",
"wrapClosure",
"?",
"'function($obj) { '",
":",
"''",
";",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"setterTypeName",
")",
";",
"foreach",
"(",
"$",
"setters",
"as",
"$",
"setter",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"collectSetterMethods",
"(",
"$",
"ref",
",",
"$",
"setter",
")",
"as",
"$",
"method",
")",
"{",
"$",
"params",
"=",
"$",
"method",
"->",
"getParameters",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"continue",
";",
"}",
"$",
"injector",
"=",
"'$obj->'",
".",
"$",
"method",
"->",
"getName",
"(",
")",
".",
"'('",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"i",
"=>",
"$",
"param",
")",
"{",
"if",
"(",
"NULL",
"===",
"(",
"$",
"paramTypeName",
"=",
"$",
"param",
"->",
"getClass",
"(",
")",
")",
")",
"{",
"continue",
"2",
";",
"}",
"if",
"(",
"$",
"i",
"!=",
"0",
")",
"{",
"$",
"injector",
".=",
"', '",
";",
"}",
"$",
"nullable",
"=",
"$",
"param",
"->",
"isOptional",
"(",
")",
"?",
"'Nullable'",
":",
"''",
";",
"$",
"injector",
".=",
"'$this->get'",
".",
"$",
"nullable",
".",
"'('",
".",
"var_export",
"(",
"$",
"paramTypeName",
"->",
"name",
",",
"true",
")",
".",
"', new InjectionPoint('",
";",
"$",
"injector",
".=",
"'get_class($obj), '",
".",
"var_export",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"true",
")",
".",
"'))'",
";",
"}",
"$",
"code",
".=",
"$",
"injector",
".",
"'); '",
";",
"}",
"}",
"return",
"$",
"wrapClosure",
"?",
"(",
"$",
"code",
".",
"'}'",
")",
":",
"$",
"code",
";",
"}"
] | Compile a setter injector for a binding.
@param Binding $binding
@param boolean $wrapClosure
@return string | [
"Compile",
"a",
"setter",
"injector",
"for",
"a",
"binding",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/ContainerCompiler.php#L560-L610 | train |
koolkode/context | src/ContainerCompiler.php | ContainerCompiler.collectSetterMethods | protected function collectSetterMethods(\ReflectionClass $ref, SetterInjection $setter)
{
$methods = [];
foreach($ref->getMethods() as $method)
{
if($method->isStatic() || $method->isAbstract() || !$method->isPublic())
{
continue;
}
if($setter->accept($method))
{
$methods[strtolower($method->getName())] = $method;
}
}
return $methods;
} | php | protected function collectSetterMethods(\ReflectionClass $ref, SetterInjection $setter)
{
$methods = [];
foreach($ref->getMethods() as $method)
{
if($method->isStatic() || $method->isAbstract() || !$method->isPublic())
{
continue;
}
if($setter->accept($method))
{
$methods[strtolower($method->getName())] = $method;
}
}
return $methods;
} | [
"protected",
"function",
"collectSetterMethods",
"(",
"\\",
"ReflectionClass",
"$",
"ref",
",",
"SetterInjection",
"$",
"setter",
")",
"{",
"$",
"methods",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"ref",
"->",
"getMethods",
"(",
")",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"$",
"method",
"->",
"isStatic",
"(",
")",
"||",
"$",
"method",
"->",
"isAbstract",
"(",
")",
"||",
"!",
"$",
"method",
"->",
"isPublic",
"(",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"setter",
"->",
"accept",
"(",
"$",
"method",
")",
")",
"{",
"$",
"methods",
"[",
"strtolower",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
")",
"]",
"=",
"$",
"method",
";",
"}",
"}",
"return",
"$",
"methods",
";",
"}"
] | Collect all matching setter injetion methods for the given type.
@param \ReflectionClass $ref
@param SetterInjection $setter
@return array<string, MethodInfoInterface> | [
"Collect",
"all",
"matching",
"setter",
"injetion",
"methods",
"for",
"the",
"given",
"type",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/ContainerCompiler.php#L619-L637 | train |
koolkode/context | src/ContainerCompiler.php | ContainerCompiler.generateCallCode | protected function generateCallCode($typeName, \ReflectionFunction $ref, $num, array $prepend = [], array $resolvers = NULL)
{
$code = '$this->call_' . $num . '(';
foreach($ref->getParameters() as $i => $param)
{
if($i != 0)
{
$code .= ', ';
}
if(array_key_exists($i, $prepend))
{
$code .= $prepend[$i];
continue;
}
if($resolvers !== NULL && array_key_exists($param->name, $resolvers))
{
$resolver = $resolvers[$param->name];
if($resolver instanceof \Closure)
{
$num = count($this->methods);
$ref = new \ReflectionFunction($resolver);
$sig = $this->generateReplacementMethodSignature($ref, $num);
$body = $this->extractClosureCode($ref);
$this->methods[] = "\t\t" . $sig . " {\n" . $body . "\n\t\t}";
$code .= $this->generateCallCode($typeName, $ref, $num);
continue;
}
elseif($resolver instanceof CompiledCodeFragment)
{
$code .= $resolver;
continue;
}
$code .= var_export($resolver, true);
continue;
}
if(NULL !== ($ptype = $this->getParamType($param)))
{
if($ptype === InjectionPointInterface::class)
{
$code .= '$point';
continue;
}
$code .= '$this->get(' . var_export($ptype, true) . ', isset($point) ? $point : NULL)';
continue;
}
if($param->isOptional())
{
$code .= $param->isDefaultValueAvailable() ? var_export($param->getDefaultValue(), true) : 'NULL';
continue;
}
throw new TypeNotFoundException(sprintf('Cannot populate closure param "%s" without type hint or resolver', $param->name));
}
return $code . ')';
} | php | protected function generateCallCode($typeName, \ReflectionFunction $ref, $num, array $prepend = [], array $resolvers = NULL)
{
$code = '$this->call_' . $num . '(';
foreach($ref->getParameters() as $i => $param)
{
if($i != 0)
{
$code .= ', ';
}
if(array_key_exists($i, $prepend))
{
$code .= $prepend[$i];
continue;
}
if($resolvers !== NULL && array_key_exists($param->name, $resolvers))
{
$resolver = $resolvers[$param->name];
if($resolver instanceof \Closure)
{
$num = count($this->methods);
$ref = new \ReflectionFunction($resolver);
$sig = $this->generateReplacementMethodSignature($ref, $num);
$body = $this->extractClosureCode($ref);
$this->methods[] = "\t\t" . $sig . " {\n" . $body . "\n\t\t}";
$code .= $this->generateCallCode($typeName, $ref, $num);
continue;
}
elseif($resolver instanceof CompiledCodeFragment)
{
$code .= $resolver;
continue;
}
$code .= var_export($resolver, true);
continue;
}
if(NULL !== ($ptype = $this->getParamType($param)))
{
if($ptype === InjectionPointInterface::class)
{
$code .= '$point';
continue;
}
$code .= '$this->get(' . var_export($ptype, true) . ', isset($point) ? $point : NULL)';
continue;
}
if($param->isOptional())
{
$code .= $param->isDefaultValueAvailable() ? var_export($param->getDefaultValue(), true) : 'NULL';
continue;
}
throw new TypeNotFoundException(sprintf('Cannot populate closure param "%s" without type hint or resolver', $param->name));
}
return $code . ')';
} | [
"protected",
"function",
"generateCallCode",
"(",
"$",
"typeName",
",",
"\\",
"ReflectionFunction",
"$",
"ref",
",",
"$",
"num",
",",
"array",
"$",
"prepend",
"=",
"[",
"]",
",",
"array",
"$",
"resolvers",
"=",
"NULL",
")",
"{",
"$",
"code",
"=",
"'$this->call_'",
".",
"$",
"num",
".",
"'('",
";",
"foreach",
"(",
"$",
"ref",
"->",
"getParameters",
"(",
")",
"as",
"$",
"i",
"=>",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"i",
"!=",
"0",
")",
"{",
"$",
"code",
".=",
"', '",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"i",
",",
"$",
"prepend",
")",
")",
"{",
"$",
"code",
".=",
"$",
"prepend",
"[",
"$",
"i",
"]",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"resolvers",
"!==",
"NULL",
"&&",
"array_key_exists",
"(",
"$",
"param",
"->",
"name",
",",
"$",
"resolvers",
")",
")",
"{",
"$",
"resolver",
"=",
"$",
"resolvers",
"[",
"$",
"param",
"->",
"name",
"]",
";",
"if",
"(",
"$",
"resolver",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"num",
"=",
"count",
"(",
"$",
"this",
"->",
"methods",
")",
";",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"resolver",
")",
";",
"$",
"sig",
"=",
"$",
"this",
"->",
"generateReplacementMethodSignature",
"(",
"$",
"ref",
",",
"$",
"num",
")",
";",
"$",
"body",
"=",
"$",
"this",
"->",
"extractClosureCode",
"(",
"$",
"ref",
")",
";",
"$",
"this",
"->",
"methods",
"[",
"]",
"=",
"\"\\t\\t\"",
".",
"$",
"sig",
".",
"\" {\\n\"",
".",
"$",
"body",
".",
"\"\\n\\t\\t}\"",
";",
"$",
"code",
".=",
"$",
"this",
"->",
"generateCallCode",
"(",
"$",
"typeName",
",",
"$",
"ref",
",",
"$",
"num",
")",
";",
"continue",
";",
"}",
"elseif",
"(",
"$",
"resolver",
"instanceof",
"CompiledCodeFragment",
")",
"{",
"$",
"code",
".=",
"$",
"resolver",
";",
"continue",
";",
"}",
"$",
"code",
".=",
"var_export",
"(",
"$",
"resolver",
",",
"true",
")",
";",
"continue",
";",
"}",
"if",
"(",
"NULL",
"!==",
"(",
"$",
"ptype",
"=",
"$",
"this",
"->",
"getParamType",
"(",
"$",
"param",
")",
")",
")",
"{",
"if",
"(",
"$",
"ptype",
"===",
"InjectionPointInterface",
"::",
"class",
")",
"{",
"$",
"code",
".=",
"'$point'",
";",
"continue",
";",
"}",
"$",
"code",
".=",
"'$this->get('",
".",
"var_export",
"(",
"$",
"ptype",
",",
"true",
")",
".",
"', isset($point) ? $point : NULL)'",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"param",
"->",
"isOptional",
"(",
")",
")",
"{",
"$",
"code",
".=",
"$",
"param",
"->",
"isDefaultValueAvailable",
"(",
")",
"?",
"var_export",
"(",
"$",
"param",
"->",
"getDefaultValue",
"(",
")",
",",
"true",
")",
":",
"'NULL'",
";",
"continue",
";",
"}",
"throw",
"new",
"TypeNotFoundException",
"(",
"sprintf",
"(",
"'Cannot populate closure param \"%s\" without type hint or resolver'",
",",
"$",
"param",
"->",
"name",
")",
")",
";",
"}",
"return",
"$",
"code",
".",
"')'",
";",
"}"
] | Generate code calling a replacement method with arguments.
@param string $typeName
@param \ReflectionFunction $ref
@param integer $num
@param array<string> $prepend
@return string
@throws \RuntimeException When a param value could not be populated. | [
"Generate",
"code",
"calling",
"a",
"replacement",
"method",
"with",
"arguments",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/ContainerCompiler.php#L650-L723 | train |
koolkode/context | src/ContainerCompiler.php | ContainerCompiler.generateReplacementMethodSignature | protected function generateReplacementMethodSignature(\ReflectionFunction $ref, $num)
{
$code = 'protected function call_' . $num . '(';
foreach($ref->getParameters() as $i => $param)
{
if($i != 0)
{
$code .= ', ';
}
if(NULL !== ($ptype = $this->getParamType($param)))
{
$code .= '\\' . $ptype . ' ';
}
if($param->isPassedByReference())
{
$code .= '& ';
}
$code .= '$' . $param->name;
if($param->isOptional() && $param->isDefaultValueAvailable())
{
$code .= ' = ' . var_export($param->getDefaultValue(), true);
}
}
return $code . ')';
} | php | protected function generateReplacementMethodSignature(\ReflectionFunction $ref, $num)
{
$code = 'protected function call_' . $num . '(';
foreach($ref->getParameters() as $i => $param)
{
if($i != 0)
{
$code .= ', ';
}
if(NULL !== ($ptype = $this->getParamType($param)))
{
$code .= '\\' . $ptype . ' ';
}
if($param->isPassedByReference())
{
$code .= '& ';
}
$code .= '$' . $param->name;
if($param->isOptional() && $param->isDefaultValueAvailable())
{
$code .= ' = ' . var_export($param->getDefaultValue(), true);
}
}
return $code . ')';
} | [
"protected",
"function",
"generateReplacementMethodSignature",
"(",
"\\",
"ReflectionFunction",
"$",
"ref",
",",
"$",
"num",
")",
"{",
"$",
"code",
"=",
"'protected function call_'",
".",
"$",
"num",
".",
"'('",
";",
"foreach",
"(",
"$",
"ref",
"->",
"getParameters",
"(",
")",
"as",
"$",
"i",
"=>",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"i",
"!=",
"0",
")",
"{",
"$",
"code",
".=",
"', '",
";",
"}",
"if",
"(",
"NULL",
"!==",
"(",
"$",
"ptype",
"=",
"$",
"this",
"->",
"getParamType",
"(",
"$",
"param",
")",
")",
")",
"{",
"$",
"code",
".=",
"'\\\\'",
".",
"$",
"ptype",
".",
"' '",
";",
"}",
"if",
"(",
"$",
"param",
"->",
"isPassedByReference",
"(",
")",
")",
"{",
"$",
"code",
".=",
"'& '",
";",
"}",
"$",
"code",
".=",
"'$'",
".",
"$",
"param",
"->",
"name",
";",
"if",
"(",
"$",
"param",
"->",
"isOptional",
"(",
")",
"&&",
"$",
"param",
"->",
"isDefaultValueAvailable",
"(",
")",
")",
"{",
"$",
"code",
".=",
"' = '",
".",
"var_export",
"(",
"$",
"param",
"->",
"getDefaultValue",
"(",
")",
",",
"true",
")",
";",
"}",
"}",
"return",
"$",
"code",
".",
"')'",
";",
"}"
] | Generate a signature for a method replacing the given closure.
@param \ReflectionFunction $ref
@param integer $num
@return string | [
"Generate",
"a",
"signature",
"for",
"a",
"method",
"replacing",
"the",
"given",
"closure",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/ContainerCompiler.php#L732-L762 | train |
koolkode/context | src/ContainerCompiler.php | ContainerCompiler.extractClosureCode | protected function extractClosureCode(\ReflectionFunction $ref)
{
$file = $ref->getFileName();
$lines = file($file, FILE_IGNORE_NEW_LINES);
if(isset($this->namespaceContextCache[$file]))
{
$namespaceContext = $this->namespaceContextCache[$file];
}
else
{
$tokens = token_get_all(implode("\n", $lines));
$namespaceContext = $this->namespaceContextCache[$file] = $this->generateNamespaceContext($tokens);
}
// Extract closure code from file source.
$funcLines = array_slice($lines, $ref->getStartLine() - 1, $ref->getEndLine() - $ref->getStartLine() + 1);
$snippet = implode("\n", array_map('trim', $funcLines));
$snippet = preg_replace("'^.*\{'", '', $snippet);
$snippet = preg_replace("'\}.*$'", '', $snippet);
// Parse closure code snippet and expand unqualified names.
$tokens = array_slice(token_get_all('<?php ' . $snippet), 1);
$buffer = $this->expandNames($tokens, $namespaceContext);
return str_replace("\n", "\n\t\t", "\n" . trim($buffer));
} | php | protected function extractClosureCode(\ReflectionFunction $ref)
{
$file = $ref->getFileName();
$lines = file($file, FILE_IGNORE_NEW_LINES);
if(isset($this->namespaceContextCache[$file]))
{
$namespaceContext = $this->namespaceContextCache[$file];
}
else
{
$tokens = token_get_all(implode("\n", $lines));
$namespaceContext = $this->namespaceContextCache[$file] = $this->generateNamespaceContext($tokens);
}
// Extract closure code from file source.
$funcLines = array_slice($lines, $ref->getStartLine() - 1, $ref->getEndLine() - $ref->getStartLine() + 1);
$snippet = implode("\n", array_map('trim', $funcLines));
$snippet = preg_replace("'^.*\{'", '', $snippet);
$snippet = preg_replace("'\}.*$'", '', $snippet);
// Parse closure code snippet and expand unqualified names.
$tokens = array_slice(token_get_all('<?php ' . $snippet), 1);
$buffer = $this->expandNames($tokens, $namespaceContext);
return str_replace("\n", "\n\t\t", "\n" . trim($buffer));
} | [
"protected",
"function",
"extractClosureCode",
"(",
"\\",
"ReflectionFunction",
"$",
"ref",
")",
"{",
"$",
"file",
"=",
"$",
"ref",
"->",
"getFileName",
"(",
")",
";",
"$",
"lines",
"=",
"file",
"(",
"$",
"file",
",",
"FILE_IGNORE_NEW_LINES",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"namespaceContextCache",
"[",
"$",
"file",
"]",
")",
")",
"{",
"$",
"namespaceContext",
"=",
"$",
"this",
"->",
"namespaceContextCache",
"[",
"$",
"file",
"]",
";",
"}",
"else",
"{",
"$",
"tokens",
"=",
"token_get_all",
"(",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
")",
";",
"$",
"namespaceContext",
"=",
"$",
"this",
"->",
"namespaceContextCache",
"[",
"$",
"file",
"]",
"=",
"$",
"this",
"->",
"generateNamespaceContext",
"(",
"$",
"tokens",
")",
";",
"}",
"// Extract closure code from file source.",
"$",
"funcLines",
"=",
"array_slice",
"(",
"$",
"lines",
",",
"$",
"ref",
"->",
"getStartLine",
"(",
")",
"-",
"1",
",",
"$",
"ref",
"->",
"getEndLine",
"(",
")",
"-",
"$",
"ref",
"->",
"getStartLine",
"(",
")",
"+",
"1",
")",
";",
"$",
"snippet",
"=",
"implode",
"(",
"\"\\n\"",
",",
"array_map",
"(",
"'trim'",
",",
"$",
"funcLines",
")",
")",
";",
"$",
"snippet",
"=",
"preg_replace",
"(",
"\"'^.*\\{'\"",
",",
"''",
",",
"$",
"snippet",
")",
";",
"$",
"snippet",
"=",
"preg_replace",
"(",
"\"'\\}.*$'\"",
",",
"''",
",",
"$",
"snippet",
")",
";",
"// Parse closure code snippet and expand unqualified names.",
"$",
"tokens",
"=",
"array_slice",
"(",
"token_get_all",
"(",
"'<?php '",
".",
"$",
"snippet",
")",
",",
"1",
")",
";",
"$",
"buffer",
"=",
"$",
"this",
"->",
"expandNames",
"(",
"$",
"tokens",
",",
"$",
"namespaceContext",
")",
";",
"return",
"str_replace",
"(",
"\"\\n\"",
",",
"\"\\n\\t\\t\"",
",",
"\"\\n\"",
".",
"trim",
"(",
"$",
"buffer",
")",
")",
";",
"}"
] | Extract code of the given closure and process it for use in a replacement method.
@param \ReflectionFunction $ref
@return string | [
"Extract",
"code",
"of",
"the",
"given",
"closure",
"and",
"process",
"it",
"for",
"use",
"in",
"a",
"replacement",
"method",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/ContainerCompiler.php#L770-L796 | train |
koolkode/context | src/ContainerCompiler.php | ContainerCompiler.generateNamespaceContext | protected function generateNamespaceContext(array & $tokens)
{
$namespaceContext = new NamespaceContext();
for($size = count($tokens), $i = 0; $i < $size; $i++)
{
if(is_array($tokens[$i]))
{
switch($tokens[$i][0])
{
case T_NAMESPACE:
$namespace = '';
for($i++; $i < $size; $i++)
{
if(is_array($tokens[$i]))
{
switch($tokens[$i][0])
{
case T_WHITESPACE:
case T_COMMENT:
case T_DOC_COMMENT:
continue 2;
case T_NS_SEPARATOR:
case T_STRING:
$namespace .= $tokens[$i][1];
continue 2;
}
}
break;
}
$namespaceContext = new NamespaceContext($namespace);
break;
case T_USE:
do
{
$i++;
$this->readImport($tokens, $i, $namespaceContext);
}
while($tokens[$i] == ',');
break;
case T_CLASS:
case T_INTERFACE:
case T_TRAIT:
// Abort namespace detection as soon as code declaring a type is reached.
break 2;
}
}
}
return $namespaceContext;
} | php | protected function generateNamespaceContext(array & $tokens)
{
$namespaceContext = new NamespaceContext();
for($size = count($tokens), $i = 0; $i < $size; $i++)
{
if(is_array($tokens[$i]))
{
switch($tokens[$i][0])
{
case T_NAMESPACE:
$namespace = '';
for($i++; $i < $size; $i++)
{
if(is_array($tokens[$i]))
{
switch($tokens[$i][0])
{
case T_WHITESPACE:
case T_COMMENT:
case T_DOC_COMMENT:
continue 2;
case T_NS_SEPARATOR:
case T_STRING:
$namespace .= $tokens[$i][1];
continue 2;
}
}
break;
}
$namespaceContext = new NamespaceContext($namespace);
break;
case T_USE:
do
{
$i++;
$this->readImport($tokens, $i, $namespaceContext);
}
while($tokens[$i] == ',');
break;
case T_CLASS:
case T_INTERFACE:
case T_TRAIT:
// Abort namespace detection as soon as code declaring a type is reached.
break 2;
}
}
}
return $namespaceContext;
} | [
"protected",
"function",
"generateNamespaceContext",
"(",
"array",
"&",
"$",
"tokens",
")",
"{",
"$",
"namespaceContext",
"=",
"new",
"NamespaceContext",
"(",
")",
";",
"for",
"(",
"$",
"size",
"=",
"count",
"(",
"$",
"tokens",
")",
",",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"size",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
")",
"{",
"case",
"T_NAMESPACE",
":",
"$",
"namespace",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"++",
";",
"$",
"i",
"<",
"$",
"size",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
")",
"{",
"case",
"T_WHITESPACE",
":",
"case",
"T_COMMENT",
":",
"case",
"T_DOC_COMMENT",
":",
"continue",
"2",
";",
"case",
"T_NS_SEPARATOR",
":",
"case",
"T_STRING",
":",
"$",
"namespace",
".=",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"1",
"]",
";",
"continue",
"2",
";",
"}",
"}",
"break",
";",
"}",
"$",
"namespaceContext",
"=",
"new",
"NamespaceContext",
"(",
"$",
"namespace",
")",
";",
"break",
";",
"case",
"T_USE",
":",
"do",
"{",
"$",
"i",
"++",
";",
"$",
"this",
"->",
"readImport",
"(",
"$",
"tokens",
",",
"$",
"i",
",",
"$",
"namespaceContext",
")",
";",
"}",
"while",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
"==",
"','",
")",
";",
"break",
";",
"case",
"T_CLASS",
":",
"case",
"T_INTERFACE",
":",
"case",
"T_TRAIT",
":",
"// Abort namespace detection as soon as code declaring a type is reached.",
"break",
"2",
";",
"}",
"}",
"}",
"return",
"$",
"namespaceContext",
";",
"}"
] | Read namespace context from the given PHP source tokens.
@param array $tokens
@return NamespaceContext | [
"Read",
"namespace",
"context",
"from",
"the",
"given",
"PHP",
"source",
"tokens",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/ContainerCompiler.php#L804-L860 | train |
koolkode/context | src/ContainerCompiler.php | ContainerCompiler.readImport | protected function readImport(array $tokens, & $i, NamespaceContext $context)
{
$import = '';
for($size = count($tokens); $i < $size; $i++)
{
if(is_array($tokens[$i]))
{
switch($tokens[$i][0])
{
case T_WHITESPACE:
case T_COMMENT:
case T_DOC_COMMENT:
continue 2;
case T_NS_SEPARATOR:
case T_STRING:
$import .= $tokens[$i][1];
continue 2;
}
}
break;
}
if(is_array($tokens[$i]) && $tokens[$i][0] == T_AS)
{
$i++;
$alias = '';
for($size = count($tokens); $i < $size; $i++)
{
if(is_array($tokens[$i]))
{
switch($tokens[$i][0])
{
case T_WHITESPACE:
case T_COMMENT:
case T_DOC_COMMENT:
continue 2;
case T_STRING:
$alias .= $tokens[$i][1];
continue 2;
}
}
break;
}
$context->addAliasedImport($alias, $import);
}
else
{
$context->addImport($import);
}
} | php | protected function readImport(array $tokens, & $i, NamespaceContext $context)
{
$import = '';
for($size = count($tokens); $i < $size; $i++)
{
if(is_array($tokens[$i]))
{
switch($tokens[$i][0])
{
case T_WHITESPACE:
case T_COMMENT:
case T_DOC_COMMENT:
continue 2;
case T_NS_SEPARATOR:
case T_STRING:
$import .= $tokens[$i][1];
continue 2;
}
}
break;
}
if(is_array($tokens[$i]) && $tokens[$i][0] == T_AS)
{
$i++;
$alias = '';
for($size = count($tokens); $i < $size; $i++)
{
if(is_array($tokens[$i]))
{
switch($tokens[$i][0])
{
case T_WHITESPACE:
case T_COMMENT:
case T_DOC_COMMENT:
continue 2;
case T_STRING:
$alias .= $tokens[$i][1];
continue 2;
}
}
break;
}
$context->addAliasedImport($alias, $import);
}
else
{
$context->addImport($import);
}
} | [
"protected",
"function",
"readImport",
"(",
"array",
"$",
"tokens",
",",
"&",
"$",
"i",
",",
"NamespaceContext",
"$",
"context",
")",
"{",
"$",
"import",
"=",
"''",
";",
"for",
"(",
"$",
"size",
"=",
"count",
"(",
"$",
"tokens",
")",
";",
"$",
"i",
"<",
"$",
"size",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
")",
"{",
"case",
"T_WHITESPACE",
":",
"case",
"T_COMMENT",
":",
"case",
"T_DOC_COMMENT",
":",
"continue",
"2",
";",
"case",
"T_NS_SEPARATOR",
":",
"case",
"T_STRING",
":",
"$",
"import",
".=",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"1",
"]",
";",
"continue",
"2",
";",
"}",
"}",
"break",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
")",
"&&",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
"==",
"T_AS",
")",
"{",
"$",
"i",
"++",
";",
"$",
"alias",
"=",
"''",
";",
"for",
"(",
"$",
"size",
"=",
"count",
"(",
"$",
"tokens",
")",
";",
"$",
"i",
"<",
"$",
"size",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
")",
"{",
"case",
"T_WHITESPACE",
":",
"case",
"T_COMMENT",
":",
"case",
"T_DOC_COMMENT",
":",
"continue",
"2",
";",
"case",
"T_STRING",
":",
"$",
"alias",
".=",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"1",
"]",
";",
"continue",
"2",
";",
"}",
"}",
"break",
";",
"}",
"$",
"context",
"->",
"addAliasedImport",
"(",
"$",
"alias",
",",
"$",
"import",
")",
";",
"}",
"else",
"{",
"$",
"context",
"->",
"addImport",
"(",
"$",
"import",
")",
";",
"}",
"}"
] | Read a PHP import statement and register it with the given namespace context.
@param array $tokens
@param integer $i
@param NamespaceContext $context | [
"Read",
"a",
"PHP",
"import",
"statement",
"and",
"register",
"it",
"with",
"the",
"given",
"namespace",
"context",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/ContainerCompiler.php#L1003-L1057 | train |
stubbles/stubbles-date | src/main/php/span/Day.php | Day.isToday | public function isToday(): bool
{
return $this->date->format('Y-m-d') === Date::now($this->date->timezone())->format('Y-m-d');
} | php | public function isToday(): bool
{
return $this->date->format('Y-m-d') === Date::now($this->date->timezone())->format('Y-m-d');
} | [
"public",
"function",
"isToday",
"(",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"date",
"->",
"format",
"(",
"'Y-m-d'",
")",
"===",
"Date",
"::",
"now",
"(",
"$",
"this",
"->",
"date",
"->",
"timezone",
"(",
")",
")",
"->",
"format",
"(",
"'Y-m-d'",
")",
";",
"}"
] | checks if it represents the current day
@return bool | [
"checks",
"if",
"it",
"represents",
"the",
"current",
"day"
] | 98553392bec03affc53a6e3eb7f88408c2720d1c | https://github.com/stubbles/stubbles-date/blob/98553392bec03affc53a6e3eb7f88408c2720d1c/src/main/php/span/Day.php#L109-L112 | train |
ZeeCoder/good-to-know | src/ZeeCoder/GoodToKnow/Repository/AbstractFileRepository.php | AbstractFileRepository.mapDataToFactObjects | private function mapDataToFactObjects(array $data)
{
return array_map(function($factData) {
return (new Fact)
->setText($factData['text'])
->setGroups($factData['groups'])
;
}, $data);
} | php | private function mapDataToFactObjects(array $data)
{
return array_map(function($factData) {
return (new Fact)
->setText($factData['text'])
->setGroups($factData['groups'])
;
}, $data);
} | [
"private",
"function",
"mapDataToFactObjects",
"(",
"array",
"$",
"data",
")",
"{",
"return",
"array_map",
"(",
"function",
"(",
"$",
"factData",
")",
"{",
"return",
"(",
"new",
"Fact",
")",
"->",
"setText",
"(",
"$",
"factData",
"[",
"'text'",
"]",
")",
"->",
"setGroups",
"(",
"$",
"factData",
"[",
"'groups'",
"]",
")",
";",
"}",
",",
"$",
"data",
")",
";",
"}"
] | Converts an array of data to an array of Fact objects.
@param array $data An array of data with two keys: "text" and "groups"
where text must be a string and groups must be an array of strings.
@return array | [
"Converts",
"an",
"array",
"of",
"data",
"to",
"an",
"array",
"of",
"Fact",
"objects",
"."
] | 53a8ea6ab4a2cb0f2fd8e1371e7a4a4841be5ede | https://github.com/ZeeCoder/good-to-know/blob/53a8ea6ab4a2cb0f2fd8e1371e7a4a4841be5ede/src/ZeeCoder/GoodToKnow/Repository/AbstractFileRepository.php#L47-L55 | train |
fridge-project/dbal | src/Fridge/DBAL/Connection/Connection.php | Connection.bindStatementParameters | private function bindStatementParameters(DriverStatementInterface $statement, array $parameters, array $types)
{
foreach ($parameters as $key => $parameter) {
if (is_int($key)) {
$placeholder = $key + 1;
} else {
$placeholder = ':'.$key;
}
if (isset($types[$key])) {
list($parameter, $type) = TypeUtility::convertToDatabase(
$parameter,
$types[$key],
$this->getPlatform()
);
$statement->bindValue($placeholder, $parameter, $type);
} else {
$statement->bindValue($placeholder, $parameter);
}
}
} | php | private function bindStatementParameters(DriverStatementInterface $statement, array $parameters, array $types)
{
foreach ($parameters as $key => $parameter) {
if (is_int($key)) {
$placeholder = $key + 1;
} else {
$placeholder = ':'.$key;
}
if (isset($types[$key])) {
list($parameter, $type) = TypeUtility::convertToDatabase(
$parameter,
$types[$key],
$this->getPlatform()
);
$statement->bindValue($placeholder, $parameter, $type);
} else {
$statement->bindValue($placeholder, $parameter);
}
}
} | [
"private",
"function",
"bindStatementParameters",
"(",
"DriverStatementInterface",
"$",
"statement",
",",
"array",
"$",
"parameters",
",",
"array",
"$",
"types",
")",
"{",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"parameter",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"$",
"placeholder",
"=",
"$",
"key",
"+",
"1",
";",
"}",
"else",
"{",
"$",
"placeholder",
"=",
"':'",
".",
"$",
"key",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"types",
"[",
"$",
"key",
"]",
")",
")",
"{",
"list",
"(",
"$",
"parameter",
",",
"$",
"type",
")",
"=",
"TypeUtility",
"::",
"convertToDatabase",
"(",
"$",
"parameter",
",",
"$",
"types",
"[",
"$",
"key",
"]",
",",
"$",
"this",
"->",
"getPlatform",
"(",
")",
")",
";",
"$",
"statement",
"->",
"bindValue",
"(",
"$",
"placeholder",
",",
"$",
"parameter",
",",
"$",
"type",
")",
";",
"}",
"else",
"{",
"$",
"statement",
"->",
"bindValue",
"(",
"$",
"placeholder",
",",
"$",
"parameter",
")",
";",
"}",
"}",
"}"
] | Binds typed parameters to a statement.
@param \Fridge\DBAL\Driver\Statement\DriverStatementInterface $statement The statement to bind on.
@param array $parameters The statement parameters.
@param array $types The statement parameter types. | [
"Binds",
"typed",
"parameters",
"to",
"a",
"statement",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Connection/Connection.php#L681-L702 | train |
fridge-project/dbal | src/Fridge/DBAL/Connection/Connection.php | Connection.createQueryDebugger | private function createQueryDebugger($query, array $parameters = array(), array $types = array())
{
if ($this->getConfiguration()->getDebug()) {
return new QueryDebugger($query, $parameters, $types);
}
} | php | private function createQueryDebugger($query, array $parameters = array(), array $types = array())
{
if ($this->getConfiguration()->getDebug()) {
return new QueryDebugger($query, $parameters, $types);
}
} | [
"private",
"function",
"createQueryDebugger",
"(",
"$",
"query",
",",
"array",
"$",
"parameters",
"=",
"array",
"(",
")",
",",
"array",
"$",
"types",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getDebug",
"(",
")",
")",
"{",
"return",
"new",
"QueryDebugger",
"(",
"$",
"query",
",",
"$",
"parameters",
",",
"$",
"types",
")",
";",
"}",
"}"
] | Creates a query debugger if the query needs to be debugged.
@param string $query The query to debug.
@param array $parameters The query parameters to debug.
@param array $types The query parameter types to debug.
@return \Fridge\DBAL\Debug\QueryDebugger|null The query debugger or null if the query does need to be debugged. | [
"Creates",
"a",
"query",
"debugger",
"if",
"the",
"query",
"needs",
"to",
"be",
"debugged",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Connection/Connection.php#L713-L718 | train |
fridge-project/dbal | src/Fridge/DBAL/Connection/Connection.php | Connection.debugQuery | private function debugQuery(QueryDebugger $queryDebugger = null)
{
if ($queryDebugger === null) {
return;
}
$queryDebugger->stop();
$this->getConfiguration()->getEventDispatcher()->dispatch(
Events::QUERY_DEBUG,
new QueryDebugEvent($queryDebugger)
);
} | php | private function debugQuery(QueryDebugger $queryDebugger = null)
{
if ($queryDebugger === null) {
return;
}
$queryDebugger->stop();
$this->getConfiguration()->getEventDispatcher()->dispatch(
Events::QUERY_DEBUG,
new QueryDebugEvent($queryDebugger)
);
} | [
"private",
"function",
"debugQuery",
"(",
"QueryDebugger",
"$",
"queryDebugger",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"queryDebugger",
"===",
"null",
")",
"{",
"return",
";",
"}",
"$",
"queryDebugger",
"->",
"stop",
"(",
")",
";",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"Events",
"::",
"QUERY_DEBUG",
",",
"new",
"QueryDebugEvent",
"(",
"$",
"queryDebugger",
")",
")",
";",
"}"
] | Debugs a query.
@param \Fridge\DBAL\Debug\QueryDebugger|null $queryDebugger The query debugger. | [
"Debugs",
"a",
"query",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Connection/Connection.php#L725-L737 | train |
mikyprog/LocationBundle | Manager/LocationManager.php | LocationManager.updateLocation | public function updateLocation(Location $location, $andFlush = true)
{
$this->objectManager->persist($location);
if ($andFlush) {
$this->objectManager->flush();
}
} | php | public function updateLocation(Location $location, $andFlush = true)
{
$this->objectManager->persist($location);
if ($andFlush) {
$this->objectManager->flush();
}
} | [
"public",
"function",
"updateLocation",
"(",
"Location",
"$",
"location",
",",
"$",
"andFlush",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"objectManager",
"->",
"persist",
"(",
"$",
"location",
")",
";",
"if",
"(",
"$",
"andFlush",
")",
"{",
"$",
"this",
"->",
"objectManager",
"->",
"flush",
"(",
")",
";",
"}",
"}"
] | Updates a Location.
@param Location $location
@param Boolean $andFlush Whether to flush the changes (default true) | [
"Updates",
"a",
"Location",
"."
] | ffbbc8e6b7c759f0dbf0dec6d36a8f3150322f23 | https://github.com/mikyprog/LocationBundle/blob/ffbbc8e6b7c759f0dbf0dec6d36a8f3150322f23/Manager/LocationManager.php#L86-L92 | train |
mikyprog/LocationBundle | Manager/LocationManager.php | LocationManager.refreshLocation | public function refreshLocation(Location $location)
{
$refreshedLocation = $this->findLocationBy(array('id' => $location->getId()));
if (null === $refreshedLocation) {
throw new UsernameNotFoundException(sprintf('User with ID "%d" could not be reloaded.', $location->getId()));
}
return $refreshedLocation;
} | php | public function refreshLocation(Location $location)
{
$refreshedLocation = $this->findLocationBy(array('id' => $location->getId()));
if (null === $refreshedLocation) {
throw new UsernameNotFoundException(sprintf('User with ID "%d" could not be reloaded.', $location->getId()));
}
return $refreshedLocation;
} | [
"public",
"function",
"refreshLocation",
"(",
"Location",
"$",
"location",
")",
"{",
"$",
"refreshedLocation",
"=",
"$",
"this",
"->",
"findLocationBy",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"location",
"->",
"getId",
"(",
")",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"refreshedLocation",
")",
"{",
"throw",
"new",
"UsernameNotFoundException",
"(",
"sprintf",
"(",
"'User with ID \"%d\" could not be reloaded.'",
",",
"$",
"location",
"->",
"getId",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"refreshedLocation",
";",
"}"
] | Refreshed a Location by Location Instance
@param LocationInterface $location
@return Ad | [
"Refreshed",
"a",
"Location",
"by",
"Location",
"Instance"
] | ffbbc8e6b7c759f0dbf0dec6d36a8f3150322f23 | https://github.com/mikyprog/LocationBundle/blob/ffbbc8e6b7c759f0dbf0dec6d36a8f3150322f23/Manager/LocationManager.php#L113-L121 | train |
itcreator/custom-cmf | Module/Url/src/Cmf/Url/Builder/Adapter/Get.php | Get.buildRecursive | protected function buildRecursive($key, $value)
{
$url = '';
if (is_array($value)) {
foreach ($value as $key2 => $val) {
if ($part = $this->buildRecursive($key . '[' . $key2 . ']', $val)) {
$url .= ($url ? '&' : '') . $part;
}
}
} else {
$url .= ($url ? '&' : '') . urlencode($key) . '=' . urlencode($value);
}
return $url;
} | php | protected function buildRecursive($key, $value)
{
$url = '';
if (is_array($value)) {
foreach ($value as $key2 => $val) {
if ($part = $this->buildRecursive($key . '[' . $key2 . ']', $val)) {
$url .= ($url ? '&' : '') . $part;
}
}
} else {
$url .= ($url ? '&' : '') . urlencode($key) . '=' . urlencode($value);
}
return $url;
} | [
"protected",
"function",
"buildRecursive",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"url",
"=",
"''",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"key2",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"part",
"=",
"$",
"this",
"->",
"buildRecursive",
"(",
"$",
"key",
".",
"'['",
".",
"$",
"key2",
".",
"']'",
",",
"$",
"val",
")",
")",
"{",
"$",
"url",
".=",
"(",
"$",
"url",
"?",
"'&'",
":",
"''",
")",
".",
"$",
"part",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"url",
".=",
"(",
"$",
"url",
"?",
"'&'",
":",
"''",
")",
".",
"urlencode",
"(",
"$",
"key",
")",
".",
"'='",
".",
"urlencode",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | arrays in request
@param string $key
@param string|array $value
@return string | [
"arrays",
"in",
"request"
] | 42fc0535dfa0f641856f06673f6ab596b2020c40 | https://github.com/itcreator/custom-cmf/blob/42fc0535dfa0f641856f06673f6ab596b2020c40/Module/Url/src/Cmf/Url/Builder/Adapter/Get.php#L81-L95 | train |
dmitrya2e/filtration-bundle | Filter/FilterOption/FilterOptionHandler.php | FilterOptionHandler.validateFilterOptions | protected function validateFilterOptions(array $options, array $validOptions)
{
foreach ($options as $option => $value) {
// Check if the option is allowed.
if (!array_key_exists($option, $validOptions)) {
throw new FilterOptionValidatorException(sprintf(
'Option "%s" is not found in valid option list: [%s].',
$option, implode(', ', array_keys($validOptions))
));
}
// Check the type if it is required.
if (array_key_exists('type', $validOptions[$option])) {
$types = $validOptions[$option]['type'];
// Convert single type into array of types.
if (!is_array($types)) {
$types = [$types];
} elseif (count($types) === 0) {
throw new FilterOptionException('Type option must not be empty.');
}
$typeCount = count($types);
$typeCheckedCount = 0;
$valueType = '';
foreach ($types as $type) {
$typeCheckedCount++;
$typeFunction = sprintf('is_%s', $type);
if (!function_exists($typeFunction)) {
throw new FilterOptionException(sprintf('There is no such function "%s".', $typeFunction));
}
if (!$typeFunction($value)) {
if ($typeCount === $typeCheckedCount) {
throw new FilterOptionValidatorException(sprintf(
'Option "%s" has invalid value type "%s" (which must be "%s").',
$option, gettype($value), $type
));
}
} else {
$valueType = $type;
break;
}
}
// Check class instance if it is required.
if (
$valueType === 'object'
&& in_array('object', $types, true)
&& array_key_exists('instance_of', $validOptions[$option])
&& !($value instanceof $validOptions[$option]['instance_of'])
) {
throw new FilterOptionValidatorException(sprintf(
'Option "%s" must be an instance of %s.', $option, $validOptions[$option]['instance_of']
));
}
}
if (
array_key_exists('empty', $validOptions[$option])
&& $validOptions[$option]['empty'] === false
&& (string) $value === ''
) {
throw new FilterOptionValidatorException(sprintf(
'Option "%s" with value "%s" can not be empty.',
$option, is_scalar($value) ? (string) $value : '[...]'
));
}
}
return $this;
} | php | protected function validateFilterOptions(array $options, array $validOptions)
{
foreach ($options as $option => $value) {
// Check if the option is allowed.
if (!array_key_exists($option, $validOptions)) {
throw new FilterOptionValidatorException(sprintf(
'Option "%s" is not found in valid option list: [%s].',
$option, implode(', ', array_keys($validOptions))
));
}
// Check the type if it is required.
if (array_key_exists('type', $validOptions[$option])) {
$types = $validOptions[$option]['type'];
// Convert single type into array of types.
if (!is_array($types)) {
$types = [$types];
} elseif (count($types) === 0) {
throw new FilterOptionException('Type option must not be empty.');
}
$typeCount = count($types);
$typeCheckedCount = 0;
$valueType = '';
foreach ($types as $type) {
$typeCheckedCount++;
$typeFunction = sprintf('is_%s', $type);
if (!function_exists($typeFunction)) {
throw new FilterOptionException(sprintf('There is no such function "%s".', $typeFunction));
}
if (!$typeFunction($value)) {
if ($typeCount === $typeCheckedCount) {
throw new FilterOptionValidatorException(sprintf(
'Option "%s" has invalid value type "%s" (which must be "%s").',
$option, gettype($value), $type
));
}
} else {
$valueType = $type;
break;
}
}
// Check class instance if it is required.
if (
$valueType === 'object'
&& in_array('object', $types, true)
&& array_key_exists('instance_of', $validOptions[$option])
&& !($value instanceof $validOptions[$option]['instance_of'])
) {
throw new FilterOptionValidatorException(sprintf(
'Option "%s" must be an instance of %s.', $option, $validOptions[$option]['instance_of']
));
}
}
if (
array_key_exists('empty', $validOptions[$option])
&& $validOptions[$option]['empty'] === false
&& (string) $value === ''
) {
throw new FilterOptionValidatorException(sprintf(
'Option "%s" with value "%s" can not be empty.',
$option, is_scalar($value) ? (string) $value : '[...]'
));
}
}
return $this;
} | [
"protected",
"function",
"validateFilterOptions",
"(",
"array",
"$",
"options",
",",
"array",
"$",
"validOptions",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"// Check if the option is allowed.",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"option",
",",
"$",
"validOptions",
")",
")",
"{",
"throw",
"new",
"FilterOptionValidatorException",
"(",
"sprintf",
"(",
"'Option \"%s\" is not found in valid option list: [%s].'",
",",
"$",
"option",
",",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"validOptions",
")",
")",
")",
")",
";",
"}",
"// Check the type if it is required.",
"if",
"(",
"array_key_exists",
"(",
"'type'",
",",
"$",
"validOptions",
"[",
"$",
"option",
"]",
")",
")",
"{",
"$",
"types",
"=",
"$",
"validOptions",
"[",
"$",
"option",
"]",
"[",
"'type'",
"]",
";",
"// Convert single type into array of types.",
"if",
"(",
"!",
"is_array",
"(",
"$",
"types",
")",
")",
"{",
"$",
"types",
"=",
"[",
"$",
"types",
"]",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"types",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"FilterOptionException",
"(",
"'Type option must not be empty.'",
")",
";",
"}",
"$",
"typeCount",
"=",
"count",
"(",
"$",
"types",
")",
";",
"$",
"typeCheckedCount",
"=",
"0",
";",
"$",
"valueType",
"=",
"''",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"typeCheckedCount",
"++",
";",
"$",
"typeFunction",
"=",
"sprintf",
"(",
"'is_%s'",
",",
"$",
"type",
")",
";",
"if",
"(",
"!",
"function_exists",
"(",
"$",
"typeFunction",
")",
")",
"{",
"throw",
"new",
"FilterOptionException",
"(",
"sprintf",
"(",
"'There is no such function \"%s\".'",
",",
"$",
"typeFunction",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"typeFunction",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"typeCount",
"===",
"$",
"typeCheckedCount",
")",
"{",
"throw",
"new",
"FilterOptionValidatorException",
"(",
"sprintf",
"(",
"'Option \"%s\" has invalid value type \"%s\" (which must be \"%s\").'",
",",
"$",
"option",
",",
"gettype",
"(",
"$",
"value",
")",
",",
"$",
"type",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"valueType",
"=",
"$",
"type",
";",
"break",
";",
"}",
"}",
"// Check class instance if it is required.",
"if",
"(",
"$",
"valueType",
"===",
"'object'",
"&&",
"in_array",
"(",
"'object'",
",",
"$",
"types",
",",
"true",
")",
"&&",
"array_key_exists",
"(",
"'instance_of'",
",",
"$",
"validOptions",
"[",
"$",
"option",
"]",
")",
"&&",
"!",
"(",
"$",
"value",
"instanceof",
"$",
"validOptions",
"[",
"$",
"option",
"]",
"[",
"'instance_of'",
"]",
")",
")",
"{",
"throw",
"new",
"FilterOptionValidatorException",
"(",
"sprintf",
"(",
"'Option \"%s\" must be an instance of %s.'",
",",
"$",
"option",
",",
"$",
"validOptions",
"[",
"$",
"option",
"]",
"[",
"'instance_of'",
"]",
")",
")",
";",
"}",
"}",
"if",
"(",
"array_key_exists",
"(",
"'empty'",
",",
"$",
"validOptions",
"[",
"$",
"option",
"]",
")",
"&&",
"$",
"validOptions",
"[",
"$",
"option",
"]",
"[",
"'empty'",
"]",
"===",
"false",
"&&",
"(",
"string",
")",
"$",
"value",
"===",
"''",
")",
"{",
"throw",
"new",
"FilterOptionValidatorException",
"(",
"sprintf",
"(",
"'Option \"%s\" with value \"%s\" can not be empty.'",
",",
"$",
"option",
",",
"is_scalar",
"(",
"$",
"value",
")",
"?",
"(",
"string",
")",
"$",
"value",
":",
"'[...]'",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Validates filter options.
@param array $options User set options
@param array $validOptions FilterOptionInterface::getValidOptions()
@return static
@throws FilterOptionException On unexpected errors (e.g. function for type checking does not exist)
@throws FilterOptionValidatorException On validation error | [
"Validates",
"filter",
"options",
"."
] | fed5764af4e43871835744fb84957b2a76e9a215 | https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/FilterOption/FilterOptionHandler.php#L68-L141 | train |
dmitrya2e/filtration-bundle | Filter/FilterOption/FilterOptionHandler.php | FilterOptionHandler.setFilterOptions | protected function setFilterOptions(FilterOptionInterface $filter, array $options, array $validOptions)
{
foreach ($options as $option => $value) {
if (!array_key_exists('setter', $validOptions[$option])) {
throw new FilterOptionException(sprintf(
'Key "setter" is not present in option "%s" restrictions array (filter "%s").',
$option, get_class($filter)
));
}
$optionSetter = $validOptions[$option]['setter'];
if (!method_exists($filter, $optionSetter)) {
throw new FilterOptionException(sprintf(
'There is no such method "%s" in filter "%s".', $optionSetter, get_class($filter)
));
}
$filter->$optionSetter($value);
}
return $this;
} | php | protected function setFilterOptions(FilterOptionInterface $filter, array $options, array $validOptions)
{
foreach ($options as $option => $value) {
if (!array_key_exists('setter', $validOptions[$option])) {
throw new FilterOptionException(sprintf(
'Key "setter" is not present in option "%s" restrictions array (filter "%s").',
$option, get_class($filter)
));
}
$optionSetter = $validOptions[$option]['setter'];
if (!method_exists($filter, $optionSetter)) {
throw new FilterOptionException(sprintf(
'There is no such method "%s" in filter "%s".', $optionSetter, get_class($filter)
));
}
$filter->$optionSetter($value);
}
return $this;
} | [
"protected",
"function",
"setFilterOptions",
"(",
"FilterOptionInterface",
"$",
"filter",
",",
"array",
"$",
"options",
",",
"array",
"$",
"validOptions",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'setter'",
",",
"$",
"validOptions",
"[",
"$",
"option",
"]",
")",
")",
"{",
"throw",
"new",
"FilterOptionException",
"(",
"sprintf",
"(",
"'Key \"setter\" is not present in option \"%s\" restrictions array (filter \"%s\").'",
",",
"$",
"option",
",",
"get_class",
"(",
"$",
"filter",
")",
")",
")",
";",
"}",
"$",
"optionSetter",
"=",
"$",
"validOptions",
"[",
"$",
"option",
"]",
"[",
"'setter'",
"]",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"filter",
",",
"$",
"optionSetter",
")",
")",
"{",
"throw",
"new",
"FilterOptionException",
"(",
"sprintf",
"(",
"'There is no such method \"%s\" in filter \"%s\".'",
",",
"$",
"optionSetter",
",",
"get_class",
"(",
"$",
"filter",
")",
")",
")",
";",
"}",
"$",
"filter",
"->",
"$",
"optionSetter",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets filter options.
Options must be validated before setting them.
@param FilterOptionInterface $filter
@param array $options User set options
@param array $validOptions FilterOptionInterface::getValidOptions()
@return static
@throws FilterOptionException On unexpected error (such as if setter method does not exist in filter class, etc) | [
"Sets",
"filter",
"options",
".",
"Options",
"must",
"be",
"validated",
"before",
"setting",
"them",
"."
] | fed5764af4e43871835744fb84957b2a76e9a215 | https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/FilterOption/FilterOptionHandler.php#L154-L176 | train |
Krinkle/toollabs-base | src/GlobalConfig.php | GlobalConfig.writeDebugLog | public function writeDebugLog( $val ) {
if ( $this->debugMode === false ) {
return;
}
$this->runlog .= $this->getLogSection() . '> '
. $val
. "\n";
} | php | public function writeDebugLog( $val ) {
if ( $this->debugMode === false ) {
return;
}
$this->runlog .= $this->getLogSection() . '> '
. $val
. "\n";
} | [
"public",
"function",
"writeDebugLog",
"(",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"debugMode",
"===",
"false",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"runlog",
".=",
"$",
"this",
"->",
"getLogSection",
"(",
")",
".",
"'> '",
".",
"$",
"val",
".",
"\"\\n\"",
";",
"}"
] | Write one or more lines to the debug log | [
"Write",
"one",
"or",
"more",
"lines",
"to",
"the",
"debug",
"log"
] | 784150ca58f4b48cc89534fd6142c54b4f138cd2 | https://github.com/Krinkle/toollabs-base/blob/784150ca58f4b48cc89534fd6142c54b4f138cd2/src/GlobalConfig.php#L98-L106 | train |
liip/DataAggregator | src/Liip/DataAggregator/DataAggregatorBatch.php | DataAggregatorBatch.run | public function run()
{
Assertion::notEmpty(
$this->loaders,
'No loader attached.',
DataAggregatorException::NO_LOADER_ATTACHED
);
foreach ($this->loaders as $identifier => $loader) {
$this->executeLoader($loader);
}
} | php | public function run()
{
Assertion::notEmpty(
$this->loaders,
'No loader attached.',
DataAggregatorException::NO_LOADER_ATTACHED
);
foreach ($this->loaders as $identifier => $loader) {
$this->executeLoader($loader);
}
} | [
"public",
"function",
"run",
"(",
")",
"{",
"Assertion",
"::",
"notEmpty",
"(",
"$",
"this",
"->",
"loaders",
",",
"'No loader attached.'",
",",
"DataAggregatorException",
"::",
"NO_LOADER_ATTACHED",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"loaders",
"as",
"$",
"identifier",
"=>",
"$",
"loader",
")",
"{",
"$",
"this",
"->",
"executeLoader",
"(",
"$",
"loader",
")",
";",
"}",
"}"
] | Executes the processing of every attached loader.
Run each loader with limit and offset as long as it
returns not less than the limit of items persist
after each batch.
@throws \Assert\InvalidArgumentException in case no loader is attached. | [
"Executes",
"the",
"processing",
"of",
"every",
"attached",
"loader",
"."
] | 53da08ed3f5f24597be9f40ecf8ec44da7765e47 | https://github.com/liip/DataAggregator/blob/53da08ed3f5f24597be9f40ecf8ec44da7765e47/src/Liip/DataAggregator/DataAggregatorBatch.php#L57-L68 | train |
liip/DataAggregator | src/Liip/DataAggregator/DataAggregatorBatch.php | DataAggregatorBatch.executeLoader | protected function executeLoader(LoaderInterface $loader)
{
$offset = 0;
try {
while ($result = $loader->load($this->limit, $offset)) {
$this->persist($result);
$offset += $this->limit;
}
} catch (LoaderException $e) {
$this->getLogger()->error($e->getMessage());
}
} | php | protected function executeLoader(LoaderInterface $loader)
{
$offset = 0;
try {
while ($result = $loader->load($this->limit, $offset)) {
$this->persist($result);
$offset += $this->limit;
}
} catch (LoaderException $e) {
$this->getLogger()->error($e->getMessage());
}
} | [
"protected",
"function",
"executeLoader",
"(",
"LoaderInterface",
"$",
"loader",
")",
"{",
"$",
"offset",
"=",
"0",
";",
"try",
"{",
"while",
"(",
"$",
"result",
"=",
"$",
"loader",
"->",
"load",
"(",
"$",
"this",
"->",
"limit",
",",
"$",
"offset",
")",
")",
"{",
"$",
"this",
"->",
"persist",
"(",
"$",
"result",
")",
";",
"$",
"offset",
"+=",
"$",
"this",
"->",
"limit",
";",
"}",
"}",
"catch",
"(",
"LoaderException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Runs the addressed loader to retrieve its' data.
Any exception or error will be logged to the systems error log.
@param LoaderInterface $loader | [
"Runs",
"the",
"addressed",
"loader",
"to",
"retrieve",
"its",
"data",
"."
] | 53da08ed3f5f24597be9f40ecf8ec44da7765e47 | https://github.com/liip/DataAggregator/blob/53da08ed3f5f24597be9f40ecf8ec44da7765e47/src/Liip/DataAggregator/DataAggregatorBatch.php#L77-L92 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.