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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Menu/Builder.php | Builder.loadRoots | protected function loadRoots(Request $request)
{
$locale = $request->get('_locale', $this->defaultLocale);
if (isset($this->roots[$locale])) {
return $this->roots[$locale];
}
$connection = $this->em->getConnection();
$where = 'lvl=0';
if ($locale) {
$where .= sprintf(' AND (language IS NULL OR language=%s)', $connection->quote($locale));
} else {
$where .= ' AND language IS NULL';
}
$rows = $connection->query('SELECT id, name, language, lft, rgt FROM menu_item WHERE ' . $where)->fetchAll(\PDO::FETCH_NUM);
foreach ($rows as list($id, $name, $language, $lft, $rgt)) {
// if the language is null, and the root items is already loaded; ignore it.
if (null === $language && isset($this->roots[$name])) {
continue;
}
$this->roots[$locale][$name] = [$id, $lft, $rgt];
}
if (!isset($this->roots[$locale])) {
return [];
}
return $this->roots[$locale];
} | php | protected function loadRoots(Request $request)
{
$locale = $request->get('_locale', $this->defaultLocale);
if (isset($this->roots[$locale])) {
return $this->roots[$locale];
}
$connection = $this->em->getConnection();
$where = 'lvl=0';
if ($locale) {
$where .= sprintf(' AND (language IS NULL OR language=%s)', $connection->quote($locale));
} else {
$where .= ' AND language IS NULL';
}
$rows = $connection->query('SELECT id, name, language, lft, rgt FROM menu_item WHERE ' . $where)->fetchAll(\PDO::FETCH_NUM);
foreach ($rows as list($id, $name, $language, $lft, $rgt)) {
// if the language is null, and the root items is already loaded; ignore it.
if (null === $language && isset($this->roots[$name])) {
continue;
}
$this->roots[$locale][$name] = [$id, $lft, $rgt];
}
if (!isset($this->roots[$locale])) {
return [];
}
return $this->roots[$locale];
} | [
"protected",
"function",
"loadRoots",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"locale",
"=",
"$",
"request",
"->",
"get",
"(",
"'_locale'",
",",
"$",
"this",
"->",
"defaultLocale",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"roots",
... | Preload all roots for the specified locale.
@param Request $request
@return array | [
"Preload",
"all",
"roots",
"for",
"the",
"specified",
"locale",
"."
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Menu/Builder.php#L205-L237 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Menu/Builder.php | Builder.addMenuItemHierarchy | public function addMenuItemHierarchy($request, $children, $parent)
{
$ret = 0;
foreach ($children as $child) {
$ret++;
$item = $this->addMenuItem($request, $child, $parent);
if (!empty($child['__children'])) {
$ret += $this->addMenuItemHierarchy($request, $child['__children'], $item);
}
}
return $ret;
} | php | public function addMenuItemHierarchy($request, $children, $parent)
{
$ret = 0;
foreach ($children as $child) {
$ret++;
$item = $this->addMenuItem($request, $child, $parent);
if (!empty($child['__children'])) {
$ret += $this->addMenuItemHierarchy($request, $child['__children'], $item);
}
}
return $ret;
} | [
"public",
"function",
"addMenuItemHierarchy",
"(",
"$",
"request",
",",
"$",
"children",
",",
"$",
"parent",
")",
"{",
"$",
"ret",
"=",
"0",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"ret",
"++",
";",
"$",
"item",
"="... | Add menu item hierarchy
@param Request $request
@param mixed $children
@param ItemInterface $parent
@return int | [
"Add",
"menu",
"item",
"hierarchy"
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Menu/Builder.php#L271-L282 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Menu/Builder.php | Builder.addMenuItem | public function addMenuItem(Request $request, array $item, MenuItem $menu)
{
$attributes = array();
// if the menu item has a name, add it as a css class.
if ($name = $item['name']) {
$attributes['class'] = $name;
}
if (empty($item['path'])) {
$uri = null;
} elseif (preg_match('!^(?:https?://|mailto:)!', $item['path'])) {
$uri = $item['path'];
} else {
$baseUrl = $request->getBaseUrl();
$uri = $baseUrl . '/' . ltrim($item['path'], '/');
}
$menuItem = $menu->addChild(
$item['id'],
array(
'uri' => $uri,
'attributes' => $attributes,
'label' => $item['title']
)
);
if (!empty($item['json_data'])) {
$item['json_data'] = @json_decode($item['json_data']);
}
$menuItem->setExtras($item);
return $menuItem;
} | php | public function addMenuItem(Request $request, array $item, MenuItem $menu)
{
$attributes = array();
// if the menu item has a name, add it as a css class.
if ($name = $item['name']) {
$attributes['class'] = $name;
}
if (empty($item['path'])) {
$uri = null;
} elseif (preg_match('!^(?:https?://|mailto:)!', $item['path'])) {
$uri = $item['path'];
} else {
$baseUrl = $request->getBaseUrl();
$uri = $baseUrl . '/' . ltrim($item['path'], '/');
}
$menuItem = $menu->addChild(
$item['id'],
array(
'uri' => $uri,
'attributes' => $attributes,
'label' => $item['title']
)
);
if (!empty($item['json_data'])) {
$item['json_data'] = @json_decode($item['json_data']);
}
$menuItem->setExtras($item);
return $menuItem;
} | [
"public",
"function",
"addMenuItem",
"(",
"Request",
"$",
"request",
",",
"array",
"$",
"item",
",",
"MenuItem",
"$",
"menu",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
")",
";",
"// if the menu item has a name, add it as a css class.",
"if",
"(",
"$",
"n... | Utility method to convert MenuItem's from the doctrine model to Knp MenuItems
@param \Symfony\Component\HttpFoundation\Request $request
@param array $item
@param MenuItem $menu
@return ItemInterface | [
"Utility",
"method",
"to",
"convert",
"MenuItem",
"s",
"from",
"the",
"doctrine",
"model",
"to",
"Knp",
"MenuItems"
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Menu/Builder.php#L293-L325 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Menu/Builder.php | Builder.addGhostItem | public function addGhostItem(Request $request, $item)
{
$item->addChild(
$this->factory->createItem(
$item['id'],
array(
'uri' => $request->getRequestUri(),
'display' => false,
'label' => $item['title']
)
)
);
} | php | public function addGhostItem(Request $request, $item)
{
$item->addChild(
$this->factory->createItem(
$item['id'],
array(
'uri' => $request->getRequestUri(),
'display' => false,
'label' => $item['title']
)
)
);
} | [
"public",
"function",
"addGhostItem",
"(",
"Request",
"$",
"request",
",",
"$",
"item",
")",
"{",
"$",
"item",
"->",
"addChild",
"(",
"$",
"this",
"->",
"factory",
"->",
"createItem",
"(",
"$",
"item",
"[",
"'id'",
"]",
",",
"array",
"(",
"'uri'",
"=... | Adds an item on the fly that was not originally in the menu.
@param \Symfony\Component\HttpFoundation\Request $request
@param ItemInterface $item
@return void | [
"Adds",
"an",
"item",
"on",
"the",
"fly",
"that",
"was",
"not",
"originally",
"in",
"the",
"menu",
"."
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Menu/Builder.php#L334-L346 | train |
SimplyCodedSoftware/integration-messaging | src/Messaging/Handler/Enricher/Converter/EnrichPayloadWithExpressionBuilder.php | EnrichPayloadWithExpressionBuilder.createWithMapping | public static function createWithMapping(string $propertyPath, string $expression, string $mappingExpression) : self
{
return new self($propertyPath, $expression, $mappingExpression);
} | php | public static function createWithMapping(string $propertyPath, string $expression, string $mappingExpression) : self
{
return new self($propertyPath, $expression, $mappingExpression);
} | [
"public",
"static",
"function",
"createWithMapping",
"(",
"string",
"$",
"propertyPath",
",",
"string",
"$",
"expression",
",",
"string",
"$",
"mappingExpression",
")",
":",
"self",
"{",
"return",
"new",
"self",
"(",
"$",
"propertyPath",
",",
"$",
"expression"... | Enrich multiple paths
@param string $propertyPath path to enriched context e.g. [orders][*][person]
@param string $expression should return array, that will be mapped to set in property path e.g. payload
@param string $mappingExpression when evaluates to true, then specific element is put in property path e.g. requestContext['personId'] == replyContext['personId']
@return EnrichPayloadWithExpressionBuilder | [
"Enrich",
"multiple",
"paths"
] | d2d19c64f115adb554952962853a047d40be08bd | https://github.com/SimplyCodedSoftware/integration-messaging/blob/d2d19c64f115adb554952962853a047d40be08bd/src/Messaging/Handler/Enricher/Converter/EnrichPayloadWithExpressionBuilder.php#L81-L84 | train |
SimplyCodedSoftware/integration-messaging | src/Messaging/Handler/TypeDescriptor.php | TypeDescriptor.resolveGenericTypes | public function resolveGenericTypes() : array
{
if (!$this->isCollection()) {
throw InvalidArgumentException::create("Can't resolve collection type on non collection");
}
preg_match(self::COLLECTION_TYPE_REGEX, $this->type, $match);
return [TypeDescriptor::create(trim($match[1]))];
} | php | public function resolveGenericTypes() : array
{
if (!$this->isCollection()) {
throw InvalidArgumentException::create("Can't resolve collection type on non collection");
}
preg_match(self::COLLECTION_TYPE_REGEX, $this->type, $match);
return [TypeDescriptor::create(trim($match[1]))];
} | [
"public",
"function",
"resolveGenericTypes",
"(",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCollection",
"(",
")",
")",
"{",
"throw",
"InvalidArgumentException",
"::",
"create",
"(",
"\"Can't resolve collection type on non collection\"",
")",
"... | Should be called only, if type descriptor is collection
@return TypeDescriptor[]
@throws InvalidArgumentException
@throws \SimplyCodedSoftware\Messaging\MessagingException | [
"Should",
"be",
"called",
"only",
"if",
"type",
"descriptor",
"is",
"collection"
] | d2d19c64f115adb554952962853a047d40be08bd | https://github.com/SimplyCodedSoftware/integration-messaging/blob/d2d19c64f115adb554952962853a047d40be08bd/src/Messaging/Handler/TypeDescriptor.php#L182-L191 | train |
opis-colibri/framework | src/Application.php | Application.getHttpRouter | public function getHttpRouter(): HttpRouter
{
if ($this->httpRouter === null) {
$this->httpRouter = new HttpRouter($this);
}
return $this->httpRouter;
} | php | public function getHttpRouter(): HttpRouter
{
if ($this->httpRouter === null) {
$this->httpRouter = new HttpRouter($this);
}
return $this->httpRouter;
} | [
"public",
"function",
"getHttpRouter",
"(",
")",
":",
"HttpRouter",
"{",
"if",
"(",
"$",
"this",
"->",
"httpRouter",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"httpRouter",
"=",
"new",
"HttpRouter",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"... | Get the HTTP router
@return HttpRouter | [
"Get",
"the",
"HTTP",
"router"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Application.php#L237-L244 | train |
opis-colibri/framework | src/Application.php | Application.getContainer | public function getContainer(): Container
{
if ($this->containerInstance === null) {
$this->containerInstance = $this->getCollector()->getContracts();
}
return $this->containerInstance;
} | php | public function getContainer(): Container
{
if ($this->containerInstance === null) {
$this->containerInstance = $this->getCollector()->getContracts();
}
return $this->containerInstance;
} | [
"public",
"function",
"getContainer",
"(",
")",
":",
"Container",
"{",
"if",
"(",
"$",
"this",
"->",
"containerInstance",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"containerInstance",
"=",
"$",
"this",
"->",
"getCollector",
"(",
")",
"->",
"getContracts... | Return the dependency injection container
@return Container | [
"Return",
"the",
"dependency",
"injection",
"container"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Application.php#L287-L294 | train |
opis-colibri/framework | src/Application.php | Application.getPlaceholder | public function getPlaceholder(): Placeholder
{
if ($this->placeholderInstance === null) {
$this->placeholderInstance = new Placeholder();
}
return $this->placeholderInstance;
} | php | public function getPlaceholder(): Placeholder
{
if ($this->placeholderInstance === null) {
$this->placeholderInstance = new Placeholder();
}
return $this->placeholderInstance;
} | [
"public",
"function",
"getPlaceholder",
"(",
")",
":",
"Placeholder",
"{",
"if",
"(",
"$",
"this",
"->",
"placeholderInstance",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"placeholderInstance",
"=",
"new",
"Placeholder",
"(",
")",
";",
"}",
"return",
"$",... | Get a placeholder object
@return Placeholder | [
"Get",
"a",
"placeholder",
"object"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Application.php#L338-L345 | train |
opis-colibri/framework | src/Application.php | Application.getValidator | public function getValidator(): Validator
{
if ($this->validator === null) {
$this->validator = new Validator(new ValidatorCollection(), $this->getPlaceholder());
}
return $this->validator;
} | php | public function getValidator(): Validator
{
if ($this->validator === null) {
$this->validator = new Validator(new ValidatorCollection(), $this->getPlaceholder());
}
return $this->validator;
} | [
"public",
"function",
"getValidator",
"(",
")",
":",
"Validator",
"{",
"if",
"(",
"$",
"this",
"->",
"validator",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"validator",
"=",
"new",
"Validator",
"(",
"new",
"ValidatorCollection",
"(",
")",
",",
"$",
"... | Returns validator instance
@return Validator | [
"Returns",
"validator",
"instance"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Application.php#L352-L359 | train |
opis-colibri/framework | src/Application.php | Application.getCache | public function getCache(string $storage = 'default'): CacheInterface
{
if (!isset($this->cache[$storage])) {
if ($storage === 'default') {
if (!isset($this->implicit['cache'])) {
throw new \RuntimeException('The default cache storage was not set');
}
$this->cache[$storage] = $this->implicit['cache'];
} else {
$this->cache[$storage] = $this->getCollector()->getCacheDriver($storage);
}
}
return $this->cache[$storage];
} | php | public function getCache(string $storage = 'default'): CacheInterface
{
if (!isset($this->cache[$storage])) {
if ($storage === 'default') {
if (!isset($this->implicit['cache'])) {
throw new \RuntimeException('The default cache storage was not set');
}
$this->cache[$storage] = $this->implicit['cache'];
} else {
$this->cache[$storage] = $this->getCollector()->getCacheDriver($storage);
}
}
return $this->cache[$storage];
} | [
"public",
"function",
"getCache",
"(",
"string",
"$",
"storage",
"=",
"'default'",
")",
":",
"CacheInterface",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"storage",
"]",
")",
")",
"{",
"if",
"(",
"$",
"storage",
"===",
... | Returns a caching storage
@param string $storage (optional) Storage name
@return CacheInterface | [
"Returns",
"a",
"caching",
"storage"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Application.php#L368-L382 | train |
opis-colibri/framework | src/Application.php | Application.getSession | public function getSession(): ISession
{
if ($this->session === null) {
if (!isset($this->implicit['session'])) {
throw new \RuntimeException('The default session storage was not set');
}
$this->session = new Session($this->getCollector()->getSessionHandler($this->implicit['session']));
}
return $this->session;
} | php | public function getSession(): ISession
{
if ($this->session === null) {
if (!isset($this->implicit['session'])) {
throw new \RuntimeException('The default session storage was not set');
}
$this->session = new Session($this->getCollector()->getSessionHandler($this->implicit['session']));
}
return $this->session;
} | [
"public",
"function",
"getSession",
"(",
")",
":",
"ISession",
"{",
"if",
"(",
"$",
"this",
"->",
"session",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"implicit",
"[",
"'session'",
"]",
")",
")",
"{",
"throw",
"new",... | Returns a session storage
@return ISession | [
"Returns",
"a",
"session",
"storage"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Application.php#L389-L399 | train |
opis-colibri/framework | src/Application.php | Application.getConfig | public function getConfig(string $driver = 'default'): IDataStore
{
if (!isset($this->config[$driver])) {
if ($driver === 'default') {
if (!isset($this->implicit['config'])) {
throw new \RuntimeException('The default config storage was not set');
}
$this->config[$driver] = $this->implicit['config'];
} else {
$this->config[$driver] = $this->getCollector()->getConfigDriver($driver);
}
}
return $this->config[$driver];
} | php | public function getConfig(string $driver = 'default'): IDataStore
{
if (!isset($this->config[$driver])) {
if ($driver === 'default') {
if (!isset($this->implicit['config'])) {
throw new \RuntimeException('The default config storage was not set');
}
$this->config[$driver] = $this->implicit['config'];
} else {
$this->config[$driver] = $this->getCollector()->getConfigDriver($driver);
}
}
return $this->config[$driver];
} | [
"public",
"function",
"getConfig",
"(",
"string",
"$",
"driver",
"=",
"'default'",
")",
":",
"IDataStore",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"$",
"driver",
"]",
")",
")",
"{",
"if",
"(",
"$",
"driver",
"===",
"'de... | Returns a config storage
@param string $driver (optional) Driver's name
@return IDataStore | [
"Returns",
"a",
"config",
"storage"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Application.php#L408-L422 | train |
opis-colibri/framework | src/Application.php | Application.getDatabase | public function getDatabase(string $connection = 'default'): Database
{
if (!isset($this->database[$connection])) {
$this->database[$connection] = new Database($this->getConnection($connection));
}
return $this->database[$connection];
} | php | public function getDatabase(string $connection = 'default'): Database
{
if (!isset($this->database[$connection])) {
$this->database[$connection] = new Database($this->getConnection($connection));
}
return $this->database[$connection];
} | [
"public",
"function",
"getDatabase",
"(",
"string",
"$",
"connection",
"=",
"'default'",
")",
":",
"Database",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"database",
"[",
"$",
"connection",
"]",
")",
")",
"{",
"$",
"this",
"->",
"database",
... | Returns a database abstraction layer
@param string $connection (optional) Connection name
@return Database | [
"Returns",
"a",
"database",
"abstraction",
"layer"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Application.php#L458-L465 | train |
opis-colibri/framework | src/Application.php | Application.getEntityManager | public function getEntityManager(string $connection = 'default'): EntityManager
{
if (!isset($this->entityManager[$connection])) {
$this->entityManager[$connection] = new EntityManager($this->getConnection($connection));
}
return $this->entityManager[$connection];
} | php | public function getEntityManager(string $connection = 'default'): EntityManager
{
if (!isset($this->entityManager[$connection])) {
$this->entityManager[$connection] = new EntityManager($this->getConnection($connection));
}
return $this->entityManager[$connection];
} | [
"public",
"function",
"getEntityManager",
"(",
"string",
"$",
"connection",
"=",
"'default'",
")",
":",
"EntityManager",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"entityManager",
"[",
"$",
"connection",
"]",
")",
")",
"{",
"$",
"this",
"->",... | Returns an entity manager
@param string|null $connection (optional) Connection name
@return EntityManager | [
"Returns",
"an",
"entity",
"manager"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Application.php#L486-L493 | train |
opis-colibri/framework | src/Application.php | Application.getLog | public function getLog(string $logger = 'default'): LoggerInterface
{
if (!isset($this->loggers[$logger])) {
if ($logger === 'default') {
if (!isset($this->implicit['logger'])) {
throw new \RuntimeException('The default logger was not set');
}
$this->loggers[$logger] = $this->implicit['logger'];
} else {
$this->loggers[$logger] = $this->getCollector()->getLogger($logger);
}
}
return $this->loggers[$logger];
} | php | public function getLog(string $logger = 'default'): LoggerInterface
{
if (!isset($this->loggers[$logger])) {
if ($logger === 'default') {
if (!isset($this->implicit['logger'])) {
throw new \RuntimeException('The default logger was not set');
}
$this->loggers[$logger] = $this->implicit['logger'];
} else {
$this->loggers[$logger] = $this->getCollector()->getLogger($logger);
}
}
return $this->loggers[$logger];
} | [
"public",
"function",
"getLog",
"(",
"string",
"$",
"logger",
"=",
"'default'",
")",
":",
"LoggerInterface",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"loggers",
"[",
"$",
"logger",
"]",
")",
")",
"{",
"if",
"(",
"$",
"logger",
"===",
"... | Returns a logger
@param string $logger Logger's name
@return LoggerInterface | [
"Returns",
"a",
"logger"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Application.php#L502-L516 | train |
opis-colibri/framework | src/Application.php | Application.clearCachedObjects | public function clearCachedObjects()
{
$this->containerInstance = null;
$this->eventDispatcher = null;
$this->viewRenderer = null;
$this->session = null;
$this->httpRouter = null;
$this->collectorList = null;
$this->cache = [];
$this->config = [];
$this->connection = [];
$this->database = [];
$this->entityManager = [];
TemplateStream::clearCache();
} | php | public function clearCachedObjects()
{
$this->containerInstance = null;
$this->eventDispatcher = null;
$this->viewRenderer = null;
$this->session = null;
$this->httpRouter = null;
$this->collectorList = null;
$this->cache = [];
$this->config = [];
$this->connection = [];
$this->database = [];
$this->entityManager = [];
TemplateStream::clearCache();
} | [
"public",
"function",
"clearCachedObjects",
"(",
")",
"{",
"$",
"this",
"->",
"containerInstance",
"=",
"null",
";",
"$",
"this",
"->",
"eventDispatcher",
"=",
"null",
";",
"$",
"this",
"->",
"viewRenderer",
"=",
"null",
";",
"$",
"this",
"->",
"session",
... | Clear cached objects | [
"Clear",
"cached",
"objects"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Application.php#L680-L694 | train |
opis-colibri/framework | src/Application.php | Application.enable | public function enable(Module $module, bool $recollect = true, bool $recursive = false): bool
{
$action = function (Module $module): bool {
$installer = $module->installer();
if ($installer === null) {
return true;
}
if (!class_exists($installer) || !is_subclass_of($installer, Installer::class, true)) {
return false;
}
/** @var Installer $installer */
$installer = new $installer($module);
try {
$installer->enable();
return true;
} catch (Throwable $e) {
$installer->enableError($e);
return false;
}
};
$callback = function (Module $module) use ($recollect) {
$this->notify($module, 'enabled', true);
if ($recollect) {
$this->getCollector()->recollect();
}
$this->emit('module.enabled.' . $module->name());
};
$manager = $this->moduleManager();
if ($recursive) {
foreach ($manager->recursiveDependencies($module) as $dependency) {
if (!$dependency->isInstalled()) {
if (!$this->install($dependency, $recollect, false)) {
return false;
}
}
if (!$dependency->isEnabled()) {
if (!$manager->enable($dependency, $action, $callback)) {
return false;
}
}
}
if (!$module->isInstalled() && !$this->install($module, $recollect, false)) {
return false;
}
}
return $manager->enable($module, $action, $callback);
} | php | public function enable(Module $module, bool $recollect = true, bool $recursive = false): bool
{
$action = function (Module $module): bool {
$installer = $module->installer();
if ($installer === null) {
return true;
}
if (!class_exists($installer) || !is_subclass_of($installer, Installer::class, true)) {
return false;
}
/** @var Installer $installer */
$installer = new $installer($module);
try {
$installer->enable();
return true;
} catch (Throwable $e) {
$installer->enableError($e);
return false;
}
};
$callback = function (Module $module) use ($recollect) {
$this->notify($module, 'enabled', true);
if ($recollect) {
$this->getCollector()->recollect();
}
$this->emit('module.enabled.' . $module->name());
};
$manager = $this->moduleManager();
if ($recursive) {
foreach ($manager->recursiveDependencies($module) as $dependency) {
if (!$dependency->isInstalled()) {
if (!$this->install($dependency, $recollect, false)) {
return false;
}
}
if (!$dependency->isEnabled()) {
if (!$manager->enable($dependency, $action, $callback)) {
return false;
}
}
}
if (!$module->isInstalled() && !$this->install($module, $recollect, false)) {
return false;
}
}
return $manager->enable($module, $action, $callback);
} | [
"public",
"function",
"enable",
"(",
"Module",
"$",
"module",
",",
"bool",
"$",
"recollect",
"=",
"true",
",",
"bool",
"$",
"recursive",
"=",
"false",
")",
":",
"bool",
"{",
"$",
"action",
"=",
"function",
"(",
"Module",
"$",
"module",
")",
":",
"boo... | Enable a module
@param Module $module
@param boolean $recollect (optional)
@param boolean $recursive (optional)
@return boolean | [
"Enable",
"a",
"module"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Application.php#L905-L960 | train |
opis-colibri/framework | src/Application.php | Application.disable | public function disable(Module $module, bool $recollect = true, bool $recursive = false): bool
{
$action = function (Module $module) {
$installer = $module->installer();
if ($installer === null) {
return true;
}
if (!class_exists($installer) || !is_subclass_of($installer, Installer::class, true)) {
return false;
}
/** @var Installer $installer */
$installer = new $installer($module);
try {
$installer->disable();
return true;
} catch (Throwable $e) {
$installer->disableError($e);
return false;
}
};
$callback = function (Module $module) use ($recollect) {
$this->notify($module, 'enabled', false);
if ($recollect) {
$this->getCollector()->recollect();
}
$this->emit('module.disabled.' . $module->name());
};
$manager = $this->moduleManager();
if ($recursive) {
foreach ($manager->recursiveDependants($module) as $dependant) {
if ($dependant->isEnabled()) {
if (!$manager->disable($dependant, $action, $callback)) {
return false;
}
}
if ($dependant->isInstalled()) {
if (!$this->uninstall($dependant, $recollect, false)) {
return false;
}
}
}
}
return $manager->disable($module, $action, $callback);
} | php | public function disable(Module $module, bool $recollect = true, bool $recursive = false): bool
{
$action = function (Module $module) {
$installer = $module->installer();
if ($installer === null) {
return true;
}
if (!class_exists($installer) || !is_subclass_of($installer, Installer::class, true)) {
return false;
}
/** @var Installer $installer */
$installer = new $installer($module);
try {
$installer->disable();
return true;
} catch (Throwable $e) {
$installer->disableError($e);
return false;
}
};
$callback = function (Module $module) use ($recollect) {
$this->notify($module, 'enabled', false);
if ($recollect) {
$this->getCollector()->recollect();
}
$this->emit('module.disabled.' . $module->name());
};
$manager = $this->moduleManager();
if ($recursive) {
foreach ($manager->recursiveDependants($module) as $dependant) {
if ($dependant->isEnabled()) {
if (!$manager->disable($dependant, $action, $callback)) {
return false;
}
}
if ($dependant->isInstalled()) {
if (!$this->uninstall($dependant, $recollect, false)) {
return false;
}
}
}
}
return $manager->disable($module, $action, $callback);
} | [
"public",
"function",
"disable",
"(",
"Module",
"$",
"module",
",",
"bool",
"$",
"recollect",
"=",
"true",
",",
"bool",
"$",
"recursive",
"=",
"false",
")",
":",
"bool",
"{",
"$",
"action",
"=",
"function",
"(",
"Module",
"$",
"module",
")",
"{",
"$"... | Disable a module
@param Module $module
@param boolean $recollect (optional)
@param boolean $recursive (optional)
@return boolean | [
"Disable",
"a",
"module"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Application.php#L971-L1022 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Manager/MenuManager.php | MenuManager.flush | public function flush($flushEntityManager = false)
{
$this->queue->rewind();
while ($this->queue->valid()) {
list($item, $mode) = $this->queue->dequeue();
switch ($mode) {
case self::REMOVE:
if (($repo = $this->getRepository(get_class($item))) && $repo instanceof NestedTreeRepository) {
$repo->removeFromTree($item);
} else {
$this->doctrine->getManager()->remove($item);
}
break;
case self::ADD:
$this->doctrine->getManager()->persist($item);
break;
}
$this->queue->next();
}
if ($flushEntityManager) {
$this->doctrine->getManager()->flush();
}
} | php | public function flush($flushEntityManager = false)
{
$this->queue->rewind();
while ($this->queue->valid()) {
list($item, $mode) = $this->queue->dequeue();
switch ($mode) {
case self::REMOVE:
if (($repo = $this->getRepository(get_class($item))) && $repo instanceof NestedTreeRepository) {
$repo->removeFromTree($item);
} else {
$this->doctrine->getManager()->remove($item);
}
break;
case self::ADD:
$this->doctrine->getManager()->persist($item);
break;
}
$this->queue->next();
}
if ($flushEntityManager) {
$this->doctrine->getManager()->flush();
}
} | [
"public",
"function",
"flush",
"(",
"$",
"flushEntityManager",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"queue",
"->",
"rewind",
"(",
")",
";",
"while",
"(",
"$",
"this",
"->",
"queue",
"->",
"valid",
"(",
")",
")",
"{",
"list",
"(",
"$",
"item",... | Registers a menu item to remove
@param bool $flushEntityManager | [
"Registers",
"a",
"menu",
"item",
"to",
"remove"
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Manager/MenuManager.php#L71-L95 | train |
spiral/reactor | src/ClassDeclaration.php | ClassDeclaration.setInterfaces | public function setInterfaces(array $interfaces): ClassDeclaration
{
$this->interfaces = [];
foreach ($interfaces as $interface) {
$this->addInterface($interface);
}
return $this;
} | php | public function setInterfaces(array $interfaces): ClassDeclaration
{
$this->interfaces = [];
foreach ($interfaces as $interface) {
$this->addInterface($interface);
}
return $this;
} | [
"public",
"function",
"setInterfaces",
"(",
"array",
"$",
"interfaces",
")",
":",
"ClassDeclaration",
"{",
"$",
"this",
"->",
"interfaces",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"interfaces",
"as",
"$",
"interface",
")",
"{",
"$",
"this",
"->",
"addIn... | Declare class interfaces.
@param array $interfaces
@return self | [
"Declare",
"class",
"interfaces",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/ClassDeclaration.php#L125-L133 | train |
spiral/reactor | src/ClassDeclaration.php | ClassDeclaration.setTraits | public function setTraits(array $traits): ClassDeclaration
{
$this->traits = [];
foreach ($traits as $trait) {
$this->addTrait($trait);
}
return $this;
} | php | public function setTraits(array $traits): ClassDeclaration
{
$this->traits = [];
foreach ($traits as $trait) {
$this->addTrait($trait);
}
return $this;
} | [
"public",
"function",
"setTraits",
"(",
"array",
"$",
"traits",
")",
":",
"ClassDeclaration",
"{",
"$",
"this",
"->",
"traits",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"traits",
"as",
"$",
"trait",
")",
"{",
"$",
"this",
"->",
"addTrait",
"(",
"$",
... | Declare class traits.
@param array $traits
@return self | [
"Declare",
"class",
"traits",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/ClassDeclaration.php#L188-L196 | train |
spiral/reactor | src/Partial/Property.php | Property.mountIndents | private function mountIndents(string $serialized, int $indentLevel): string
{
$lines = explode("\n", $serialized);
foreach ($lines as &$line) {
$line = $this->addIndent($line, $indentLevel);
unset($line);
}
return ltrim(join("\n", $lines));
} | php | private function mountIndents(string $serialized, int $indentLevel): string
{
$lines = explode("\n", $serialized);
foreach ($lines as &$line) {
$line = $this->addIndent($line, $indentLevel);
unset($line);
}
return ltrim(join("\n", $lines));
} | [
"private",
"function",
"mountIndents",
"(",
"string",
"$",
"serialized",
",",
"int",
"$",
"indentLevel",
")",
":",
"string",
"{",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"serialized",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"&",
"... | Mount indentation to value. Attention, to be applied to arrays only!
@param string $serialized
@param int $indentLevel
@return string | [
"Mount",
"indentation",
"to",
"value",
".",
"Attention",
"to",
"be",
"applied",
"to",
"arrays",
"only!"
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Partial/Property.php#L143-L152 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Twig/Extension.php | Extension.activeTrail | public function activeTrail($item)
{
if (is_null($item)) {
return null;
}
if (!$item instanceof MenuItem) {
throw new \UnexpectedValueException(sprintf('$ITEM must be \Knp\Menu\MenuItem not "%s"', get_class($item)));
}
$stack = array();
do {
$stack[]= $item;
} while ($item = $item->getParent());
return array_reverse($stack);
} | php | public function activeTrail($item)
{
if (is_null($item)) {
return null;
}
if (!$item instanceof MenuItem) {
throw new \UnexpectedValueException(sprintf('$ITEM must be \Knp\Menu\MenuItem not "%s"', get_class($item)));
}
$stack = array();
do {
$stack[]= $item;
} while ($item = $item->getParent());
return array_reverse($stack);
} | [
"public",
"function",
"activeTrail",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"item",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"item",
"instanceof",
"MenuItem",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValu... | Returns the active trail for the given menuItem
@param MenuItem|null $item
@return array | [
"Returns",
"the",
"active",
"trail",
"for",
"the",
"given",
"menuItem"
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Twig/Extension.php#L90-L107 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Twig/Extension.php | Extension.current | public function current($item, $level = null)
{
if (is_null($item)) {
return null;
}
if (!$item instanceof MenuItem) {
throw new \UnexpectedValueException(sprintf('$ITEM must be \Knp\Menu\MenuItem not "%s"', get_class($item)));
}
/** @var MenuItem $child */
foreach ($item->getChildren() as $child) {
if (
(null !== $this->matcher && $this->matcher->isAncestor($child))
|| (null === $this->matcher && $child->isCurrentAncestor())
) {
if ($level !== null and $level == $child->getLevel()) {
return $child;
}
return $this->current($child);
}
if (
(null !== $this->matcher && $this->matcher->isCurrent($child))
|| (null === $this->matcher && $child->isCurrent())
) {
return $child;
}
}
return null;
} | php | public function current($item, $level = null)
{
if (is_null($item)) {
return null;
}
if (!$item instanceof MenuItem) {
throw new \UnexpectedValueException(sprintf('$ITEM must be \Knp\Menu\MenuItem not "%s"', get_class($item)));
}
/** @var MenuItem $child */
foreach ($item->getChildren() as $child) {
if (
(null !== $this->matcher && $this->matcher->isAncestor($child))
|| (null === $this->matcher && $child->isCurrentAncestor())
) {
if ($level !== null and $level == $child->getLevel()) {
return $child;
}
return $this->current($child);
}
if (
(null !== $this->matcher && $this->matcher->isCurrent($child))
|| (null === $this->matcher && $child->isCurrent())
) {
return $child;
}
}
return null;
} | [
"public",
"function",
"current",
"(",
"$",
"item",
",",
"$",
"level",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"item",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"item",
"instanceof",
"MenuItem",
")",
"{",
"thro... | Returns the current menu item given a root menu item
@param MenuItem|null $item
@param int $level
@return MenuItem|null | [
"Returns",
"the",
"current",
"menu",
"item",
"given",
"a",
"root",
"menu",
"item"
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Twig/Extension.php#L116-L148 | train |
spiral/reactor | src/Serializer.php | Serializer.serialize | public function serialize($value): string
{
if (is_array($value)) {
return $this->packArray($value);
}
return $this->packValue($value);
} | php | public function serialize($value): string
{
if (is_array($value)) {
return $this->packArray($value);
}
return $this->packValue($value);
} | [
"public",
"function",
"serialize",
"(",
"$",
"value",
")",
":",
"string",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"packArray",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
"->",
"packVa... | Serialize array.
@param mixed $value
@return string | [
"Serialize",
"array",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Serializer.php#L32-L39 | train |
spiral/reactor | src/Serializer.php | Serializer.packValue | protected function packValue($value): string
{
if ($value instanceof DeclarationInterface) {
//No indentation here
return $value->render();
}
if (is_null($value)) {
return "null";
}
if (is_bool($value)) {
return ($value ? "true" : "false");
}
if (is_object($value) && method_exists($value, '__set_state')) {
return var_export($value, true);
}
if (!is_string($value) && !is_numeric($value)) {
throw new SerializeException("Unable to pack non scalar value");
}
if (is_string($value) && class_exists($value)) {
$reflection = new \ReflectionClass($value);
if ($value === $reflection->getName()) {
return '\\' . $reflection->getName() . '::class';
}
}
return var_export($value, true);
} | php | protected function packValue($value): string
{
if ($value instanceof DeclarationInterface) {
//No indentation here
return $value->render();
}
if (is_null($value)) {
return "null";
}
if (is_bool($value)) {
return ($value ? "true" : "false");
}
if (is_object($value) && method_exists($value, '__set_state')) {
return var_export($value, true);
}
if (!is_string($value) && !is_numeric($value)) {
throw new SerializeException("Unable to pack non scalar value");
}
if (is_string($value) && class_exists($value)) {
$reflection = new \ReflectionClass($value);
if ($value === $reflection->getName()) {
return '\\' . $reflection->getName() . '::class';
}
}
return var_export($value, true);
} | [
"protected",
"function",
"packValue",
"(",
"$",
"value",
")",
":",
"string",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"DeclarationInterface",
")",
"{",
"//No indentation here",
"return",
"$",
"value",
"->",
"render",
"(",
")",
";",
"}",
"if",
"(",
"is_n... | Pack array key value into string.
@param mixed $value
@return string
@throws SerializeException | [
"Pack",
"array",
"key",
"value",
"into",
"string",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Serializer.php#L101-L132 | train |
opis-colibri/framework | src/ItemCollectors/EventHandlerCollector.php | EventHandlerCollector.handle | public function handle(string $event, callable $callback): Route
{
$route = $this->data
->createRoute($event, $callback)
->set('priority', $this->crtPriority);
$this->data->sort();
return $route;
} | php | public function handle(string $event, callable $callback): Route
{
$route = $this->data
->createRoute($event, $callback)
->set('priority', $this->crtPriority);
$this->data->sort();
return $route;
} | [
"public",
"function",
"handle",
"(",
"string",
"$",
"event",
",",
"callable",
"$",
"callback",
")",
":",
"Route",
"{",
"$",
"route",
"=",
"$",
"this",
"->",
"data",
"->",
"createRoute",
"(",
"$",
"event",
",",
"$",
"callback",
")",
"->",
"set",
"(",
... | Register a new event handler
@param string $event Event name
@param callable $callback A callback that will be executed
@return Route | [
"Register",
"a",
"new",
"event",
"handler"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/ItemCollectors/EventHandlerCollector.php#L45-L54 | train |
opis-colibri/framework | src/ItemCollectors/ViewEngineCollector.php | ViewEngineCollector.register | public function register(callable $factory): self
{
$this->data->register($factory, $this->crtPriority);
return $this;
} | php | public function register(callable $factory): self
{
$this->data->register($factory, $this->crtPriority);
return $this;
} | [
"public",
"function",
"register",
"(",
"callable",
"$",
"factory",
")",
":",
"self",
"{",
"$",
"this",
"->",
"data",
"->",
"register",
"(",
"$",
"factory",
",",
"$",
"this",
"->",
"crtPriority",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a new view engine
@param callable $factory
@return ViewEngineCollector | [
"Defines",
"a",
"new",
"view",
"engine"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/ItemCollectors/ViewEngineCollector.php#L43-L47 | train |
spiral/reactor | src/Aggregator.php | Aggregator.has | public function has(string $name): bool
{
foreach ($this->elements as $element) {
if ($element instanceof NamedInterface && $element->getName() == $name) {
return true;
}
}
return false;
} | php | public function has(string $name): bool
{
foreach ($this->elements as $element) {
if ($element instanceof NamedInterface && $element->getName() == $name) {
return true;
}
}
return false;
} | [
"public",
"function",
"has",
"(",
"string",
"$",
"name",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"instanceof",
"NamedInterface",
"&&",
"$",
"element",
"->",
"getNa... | Check if aggregation has named element with given name.
@param string $name
@return bool | [
"Check",
"if",
"aggregation",
"has",
"named",
"element",
"with",
"given",
"name",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Aggregator.php#L67-L76 | train |
spiral/reactor | src/Aggregator.php | Aggregator.add | public function add(DeclarationInterface $element): Aggregator
{
$reflector = new \ReflectionObject($element);
$allowed = false;
foreach ($this->allowed as $class) {
if ($reflector->isSubclassOf($class) || get_class($element) == $class) {
$allowed = true;
break;
}
}
if (!$allowed) {
$type = get_class($element);
throw new ReactorException("Elements with type '{$type}' are not allowed");
}
$this->elements[] = $element;
return $this;
} | php | public function add(DeclarationInterface $element): Aggregator
{
$reflector = new \ReflectionObject($element);
$allowed = false;
foreach ($this->allowed as $class) {
if ($reflector->isSubclassOf($class) || get_class($element) == $class) {
$allowed = true;
break;
}
}
if (!$allowed) {
$type = get_class($element);
throw new ReactorException("Elements with type '{$type}' are not allowed");
}
$this->elements[] = $element;
return $this;
} | [
"public",
"function",
"add",
"(",
"DeclarationInterface",
"$",
"element",
")",
":",
"Aggregator",
"{",
"$",
"reflector",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"element",
")",
";",
"$",
"allowed",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
... | Add new element.
@param DeclarationInterface $element
@return self
@throws ReactorException | [
"Add",
"new",
"element",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Aggregator.php#L86-L106 | train |
spiral/reactor | src/Aggregator.php | Aggregator.remove | public function remove(string $name): Aggregator
{
foreach ($this->elements as $index => $element) {
if ($element instanceof NamedInterface && $element->getName() == $name) {
unset($this->elements[$index]);
}
}
return $this;
} | php | public function remove(string $name): Aggregator
{
foreach ($this->elements as $index => $element) {
if ($element instanceof NamedInterface && $element->getName() == $name) {
unset($this->elements[$index]);
}
}
return $this;
} | [
"public",
"function",
"remove",
"(",
"string",
"$",
"name",
")",
":",
"Aggregator",
"{",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"index",
"=>",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"instanceof",
"NamedInterface",
"&&",
... | Remove element by it's name.
@param string $name
@return self | [
"Remove",
"element",
"by",
"it",
"s",
"name",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Aggregator.php#L129-L138 | train |
opis-colibri/framework | src/Collector/Manager.php | Manager.recollect | public function recollect(bool $fresh = true): bool
{
if (!$this->app->getCache()->clear()) {
return false;
}
$this->collectorsIncluded = false;
$list = $this->app->getCollectorList($fresh);
if ($fresh) {
$this->cache = [];
$this->app->clearCachedObjects();
$this->router = new Router();
$this->container = $container = new Container();
foreach ($list as $name => $collector) {
$container->alias($name, $collector['class']);
$container->singleton($collector['class']);
}
}
foreach (array_keys($list) as $entry) {
$this->collect($entry, $fresh);
}
$this->app->getEventDispatcher()->emit("system.collect");
return true;
} | php | public function recollect(bool $fresh = true): bool
{
if (!$this->app->getCache()->clear()) {
return false;
}
$this->collectorsIncluded = false;
$list = $this->app->getCollectorList($fresh);
if ($fresh) {
$this->cache = [];
$this->app->clearCachedObjects();
$this->router = new Router();
$this->container = $container = new Container();
foreach ($list as $name => $collector) {
$container->alias($name, $collector['class']);
$container->singleton($collector['class']);
}
}
foreach (array_keys($list) as $entry) {
$this->collect($entry, $fresh);
}
$this->app->getEventDispatcher()->emit("system.collect");
return true;
} | [
"public",
"function",
"recollect",
"(",
"bool",
"$",
"fresh",
"=",
"true",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
"->",
"getCache",
"(",
")",
"->",
"clear",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
... | Recollect all items
@param bool $fresh (optional)
@return bool | [
"Recollect",
"all",
"items"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Collector/Manager.php#L331-L358 | train |
opis-colibri/framework | src/Collector/Manager.php | Manager.register | public function register(string $name, string $class, string $description, array $options = [])
{
$name = strtolower($name);
$this->app->getConfig()->write('collectors.' . $name, [
'class' => $class,
'description' => $description,
'options' => $options,
]);
$this->container->singleton($class);
$this->container->alias($name, $class);
} | php | public function register(string $name, string $class, string $description, array $options = [])
{
$name = strtolower($name);
$this->app->getConfig()->write('collectors.' . $name, [
'class' => $class,
'description' => $description,
'options' => $options,
]);
$this->container->singleton($class);
$this->container->alias($name, $class);
} | [
"public",
"function",
"register",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"class",
",",
"string",
"$",
"description",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"$",
"t... | Register a new collector
@param string $name
@param string $class
@param string $description
@param array $options | [
"Register",
"a",
"new",
"collector"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Collector/Manager.php#L368-L379 | train |
spiral/reactor | src/Traits/CommentTrait.php | CommentTrait.setComment | public function setComment($comment): self
{
if (!empty($comment)) {
if (is_array($comment)) {
$this->docComment->setLines($comment);
} elseif (is_string($comment)) {
$this->docComment->setString($comment);
}
}
return $this;
} | php | public function setComment($comment): self
{
if (!empty($comment)) {
if (is_array($comment)) {
$this->docComment->setLines($comment);
} elseif (is_string($comment)) {
$this->docComment->setString($comment);
}
}
return $this;
} | [
"public",
"function",
"setComment",
"(",
"$",
"comment",
")",
":",
"self",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"comment",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"comment",
")",
")",
"{",
"$",
"this",
"->",
"docComment",
"->",
"setLines... | Set comment value.
@param string|array $comment
@return $this | [
"Set",
"comment",
"value",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Traits/CommentTrait.php#L41-L52 | train |
spiral/reactor | src/Traits/CommentTrait.php | CommentTrait.initComment | private function initComment($comment)
{
if (empty($this->docComment)) {
$this->docComment = new Comment();
}
$this->setComment($comment);
} | php | private function initComment($comment)
{
if (empty($this->docComment)) {
$this->docComment = new Comment();
}
$this->setComment($comment);
} | [
"private",
"function",
"initComment",
"(",
"$",
"comment",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"docComment",
")",
")",
"{",
"$",
"this",
"->",
"docComment",
"=",
"new",
"Comment",
"(",
")",
";",
"}",
"$",
"this",
"->",
"setComment",... | Init comment value.
@param string|array $comment | [
"Init",
"comment",
"value",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Traits/CommentTrait.php#L59-L66 | train |
SimplyCodedSoftware/integration-messaging | src/Amqp/AmqpQueue.php | AmqpQueue.withArgument | public function withArgument(string $name, $value) : self
{
$this->enqueueQueue->setArgument($name, $value);
return $this;
} | php | public function withArgument(string $name, $value) : self
{
$this->enqueueQueue->setArgument($name, $value);
return $this;
} | [
"public",
"function",
"withArgument",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"enqueueQueue",
"->",
"setArgument",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] | optional, used by plugins and broker-specific features such as message TTL, queue length limit, etc
@param string $name
@param $value
@return AmqpQueue | [
"optional",
"used",
"by",
"plugins",
"and",
"broker",
"-",
"specific",
"features",
"such",
"as",
"message",
"TTL",
"queue",
"length",
"limit",
"etc"
] | d2d19c64f115adb554952962853a047d40be08bd | https://github.com/SimplyCodedSoftware/integration-messaging/blob/d2d19c64f115adb554952962853a047d40be08bd/src/Amqp/AmqpQueue.php#L110-L115 | train |
SimplyCodedSoftware/integration-messaging | src/DomainModel/Config/AggregateMessagingModule.php | AggregateMessagingModule.create | public static function create(AnnotationRegistrationService $annotationRegistrationService): AnnotationModule
{
return new self(
ParameterConverterAnnotationFactory::create(),
$annotationRegistrationService->findRegistrationsFor(Aggregate::class, CommandHandler::class),
$annotationRegistrationService->findRegistrationsFor(MessageEndpoint::class, CommandHandler::class),
$annotationRegistrationService->findRegistrationsFor(Aggregate::class, QueryHandler::class),
$annotationRegistrationService->findRegistrationsFor(MessageEndpoint::class, QueryHandler::class),
$annotationRegistrationService->findRegistrationsFor(Aggregate::class, EventHandler::class),
$annotationRegistrationService->findRegistrationsFor(MessageEndpoint::class, EventHandler::class)
);
} | php | public static function create(AnnotationRegistrationService $annotationRegistrationService): AnnotationModule
{
return new self(
ParameterConverterAnnotationFactory::create(),
$annotationRegistrationService->findRegistrationsFor(Aggregate::class, CommandHandler::class),
$annotationRegistrationService->findRegistrationsFor(MessageEndpoint::class, CommandHandler::class),
$annotationRegistrationService->findRegistrationsFor(Aggregate::class, QueryHandler::class),
$annotationRegistrationService->findRegistrationsFor(MessageEndpoint::class, QueryHandler::class),
$annotationRegistrationService->findRegistrationsFor(Aggregate::class, EventHandler::class),
$annotationRegistrationService->findRegistrationsFor(MessageEndpoint::class, EventHandler::class)
);
} | [
"public",
"static",
"function",
"create",
"(",
"AnnotationRegistrationService",
"$",
"annotationRegistrationService",
")",
":",
"AnnotationModule",
"{",
"return",
"new",
"self",
"(",
"ParameterConverterAnnotationFactory",
"::",
"create",
"(",
")",
",",
"$",
"annotationR... | In here we should provide messaging component for module
@inheritDoc | [
"In",
"here",
"we",
"should",
"provide",
"messaging",
"component",
"for",
"module"
] | d2d19c64f115adb554952962853a047d40be08bd | https://github.com/SimplyCodedSoftware/integration-messaging/blob/d2d19c64f115adb554952962853a047d40be08bd/src/DomainModel/Config/AggregateMessagingModule.php#L110-L121 | train |
opis-colibri/framework | src/Util/Mutex.php | Mutex.lock | public function lock(bool $wait = true): bool
{
if ($this->fp === null) {
$this->fp = fopen($this->file, 'r');
}
return flock($this->fp, $wait ? LOCK_EX : LOCK_EX | LOCK_NB);
} | php | public function lock(bool $wait = true): bool
{
if ($this->fp === null) {
$this->fp = fopen($this->file, 'r');
}
return flock($this->fp, $wait ? LOCK_EX : LOCK_EX | LOCK_NB);
} | [
"public",
"function",
"lock",
"(",
"bool",
"$",
"wait",
"=",
"true",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"fp",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"fp",
"=",
"fopen",
"(",
"$",
"this",
"->",
"file",
",",
"'r'",
")",
"... | Acquire the mutex
@param bool $wait
@return boolean | [
"Acquire",
"the",
"mutex"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/Util/Mutex.php#L69-L76 | train |
spiral/reactor | src/Partial/Parameter.php | Parameter.setDefaultValue | public function setDefaultValue($defaultValue): Parameter
{
$this->isOptional = true;
$this->defaultValue = $defaultValue;
return $this;
} | php | public function setDefaultValue($defaultValue): Parameter
{
$this->isOptional = true;
$this->defaultValue = $defaultValue;
return $this;
} | [
"public",
"function",
"setDefaultValue",
"(",
"$",
"defaultValue",
")",
":",
"Parameter",
"{",
"$",
"this",
"->",
"isOptional",
"=",
"true",
";",
"$",
"this",
"->",
"defaultValue",
"=",
"$",
"defaultValue",
";",
"return",
"$",
"this",
";",
"}"
] | Set parameter default value.
@param mixed $defaultValue
@return self | [
"Set",
"parameter",
"default",
"value",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Partial/Parameter.php#L113-L119 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Security/Authorization/MenuVoter.php | MenuVoter.userIsAllowed | protected function userIsAllowed(TokenInterface $token)
{
/** @var \Symfony\Component\Security\Core\Role\RoleInterface $role */
foreach ($this->hierarchy->getReachableRoles($token->getRoles()) as $role) {
if ($role->getRole() === self::ROLE_ADMIN_MENU_ITEM) {
return true;
}
}
return false;
} | php | protected function userIsAllowed(TokenInterface $token)
{
/** @var \Symfony\Component\Security\Core\Role\RoleInterface $role */
foreach ($this->hierarchy->getReachableRoles($token->getRoles()) as $role) {
if ($role->getRole() === self::ROLE_ADMIN_MENU_ITEM) {
return true;
}
}
return false;
} | [
"protected",
"function",
"userIsAllowed",
"(",
"TokenInterface",
"$",
"token",
")",
"{",
"/** @var \\Symfony\\Component\\Security\\Core\\Role\\RoleInterface $role */",
"foreach",
"(",
"$",
"this",
"->",
"hierarchy",
"->",
"getReachableRoles",
"(",
"$",
"token",
"->",
"get... | Calculate whether the current token is allowed.
@param TokenInterface $token
@return bool | [
"Calculate",
"whether",
"the",
"current",
"token",
"is",
"allowed",
"."
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Security/Authorization/MenuVoter.php#L95-L104 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Url/MenuItemNameUrlProvider.php | MenuItemNameUrlProvider.supports | public function supports($name)
{
if (!isset($this->loaded[$this->router->getContext()->getParameter('_locale')])) {
$this->loadMappings();
$this->loaded[$this->router->getContext()->getParameter('_locale')] = true;
}
return parent::supports($name);
} | php | public function supports($name)
{
if (!isset($this->loaded[$this->router->getContext()->getParameter('_locale')])) {
$this->loadMappings();
$this->loaded[$this->router->getContext()->getParameter('_locale')] = true;
}
return parent::supports($name);
} | [
"public",
"function",
"supports",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"loaded",
"[",
"$",
"this",
"->",
"router",
"->",
"getContext",
"(",
")",
"->",
"getParameter",
"(",
"'_locale'",
")",
"]",
")",
")",
"{"... | If it supports the given name
@param mixed $name
@return bool|mixed | [
"If",
"it",
"supports",
"the",
"given",
"name"
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Url/MenuItemNameUrlProvider.php#L46-L54 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Url/MenuItemNameUrlProvider.php | MenuItemNameUrlProvider.loadMappings | protected function loadMappings()
{
// using a subquery to allow for FETCH_KEY_PAIR
$query = '
SELECT
name, path
FROM (
SELECT
menu_item.name,
menu_item.path,
COALESCE(menu_item.language, root_item.language) language
FROM
menu_item INNER JOIN menu_item root_item ON (menu_item.root=root_item.id)
WHERE
menu_item.path IS NOT NULL
AND menu_item.name IS NOT NULL AND LENGTH(menu_item.name) > 0
HAVING
language IS NULL OR language=:lang
) s
ORDER BY
language=:lang DESC
';
$stmt = $this->em->getConnection()->prepare($query);
$stmt->execute([':lang' => $this->router->getContext()->getParameter('_locale')]);
$this->addAll($stmt->fetchAll(\PDO::FETCH_KEY_PAIR));
} | php | protected function loadMappings()
{
// using a subquery to allow for FETCH_KEY_PAIR
$query = '
SELECT
name, path
FROM (
SELECT
menu_item.name,
menu_item.path,
COALESCE(menu_item.language, root_item.language) language
FROM
menu_item INNER JOIN menu_item root_item ON (menu_item.root=root_item.id)
WHERE
menu_item.path IS NOT NULL
AND menu_item.name IS NOT NULL AND LENGTH(menu_item.name) > 0
HAVING
language IS NULL OR language=:lang
) s
ORDER BY
language=:lang DESC
';
$stmt = $this->em->getConnection()->prepare($query);
$stmt->execute([':lang' => $this->router->getContext()->getParameter('_locale')]);
$this->addAll($stmt->fetchAll(\PDO::FETCH_KEY_PAIR));
} | [
"protected",
"function",
"loadMappings",
"(",
")",
"{",
"// using a subquery to allow for FETCH_KEY_PAIR",
"$",
"query",
"=",
"'\n SELECT\n name, path\n FROM (\n SELECT\n menu_item.name,\n menu_item.path,\n... | Loads all mappings from the url, based on the current request locale. | [
"Loads",
"all",
"mappings",
"from",
"the",
"url",
"based",
"on",
"the",
"current",
"request",
"locale",
"."
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Url/MenuItemNameUrlProvider.php#L59-L84 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Url/MenuItemNameUrlProvider.php | MenuItemNameUrlProvider.suggest | public function suggest($pattern)
{
$menuItems = $this->repository->createQueryBuilder('m')
->andWhere('m.name LIKE :pattern')
->getQuery()
->execute(array('pattern' => '%' . $pattern . '%'));
$suggestions = array();
foreach ($menuItems as $item) {
$suggestions[]= array(
'value' => $item->getName(),
'label' => sprintf('%s (menu item)', $item)
);
}
return $suggestions;
} | php | public function suggest($pattern)
{
$menuItems = $this->repository->createQueryBuilder('m')
->andWhere('m.name LIKE :pattern')
->getQuery()
->execute(array('pattern' => '%' . $pattern . '%'));
$suggestions = array();
foreach ($menuItems as $item) {
$suggestions[]= array(
'value' => $item->getName(),
'label' => sprintf('%s (menu item)', $item)
);
}
return $suggestions;
} | [
"public",
"function",
"suggest",
"(",
"$",
"pattern",
")",
"{",
"$",
"menuItems",
"=",
"$",
"this",
"->",
"repository",
"->",
"createQueryBuilder",
"(",
"'m'",
")",
"->",
"andWhere",
"(",
"'m.name LIKE :pattern'",
")",
"->",
"getQuery",
"(",
")",
"->",
"ex... | Suggest url's based on the passed pattern. The return value must be an array containing "label" and "value" keys.
@param string $pattern
@return mixed | [
"Suggest",
"url",
"s",
"based",
"on",
"the",
"passed",
"pattern",
".",
"The",
"return",
"value",
"must",
"be",
"an",
"array",
"containing",
"label",
"and",
"value",
"keys",
"."
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Url/MenuItemNameUrlProvider.php#L92-L108 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Form/Subscriber/MenuItemPersistenceSubscriber.php | MenuItemPersistenceSubscriber.postSetData | public function postSetData(FormEvent $e)
{
if ($e->getData() === null) {
return;
}
// Checks if the form has a given property
// A property can be removed in a child class but the eventSubscriber still exists
if (!$e->getForm()->has($this->property)) {
return;
}
if ($this->provider->supports($e->getData())) {
if ($item = $this->mm->getItemBy(array(':path' => $this->provider->url($e->getData())))) {
$item->setAddToMenu(true);
$e->getForm()->get($this->property)->setData($item);
}
}
} | php | public function postSetData(FormEvent $e)
{
if ($e->getData() === null) {
return;
}
// Checks if the form has a given property
// A property can be removed in a child class but the eventSubscriber still exists
if (!$e->getForm()->has($this->property)) {
return;
}
if ($this->provider->supports($e->getData())) {
if ($item = $this->mm->getItemBy(array(':path' => $this->provider->url($e->getData())))) {
$item->setAddToMenu(true);
$e->getForm()->get($this->property)->setData($item);
}
}
} | [
"public",
"function",
"postSetData",
"(",
"FormEvent",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"->",
"getData",
"(",
")",
"===",
"null",
")",
"{",
"return",
";",
"}",
"// Checks if the form has a given property",
"// A property can be removed in a child class but t... | POST_SET_DATA event handler
@param FormEvent $e
@return void | [
"POST_SET_DATA",
"event",
"handler"
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Form/Subscriber/MenuItemPersistenceSubscriber.php#L52-L69 | train |
opis-colibri/framework | src/ItemCollectors/RouterGlobalsCollector.php | RouterGlobalsCollector.mixin | public function mixin(string $name, callable $callback): self
{
$this->data->mixin($name, $callback);
return $this;
} | php | public function mixin(string $name, callable $callback): self
{
$this->data->mixin($name, $callback);
return $this;
} | [
"public",
"function",
"mixin",
"(",
"string",
"$",
"name",
",",
"callable",
"$",
"callback",
")",
":",
"self",
"{",
"$",
"this",
"->",
"data",
"->",
"mixin",
"(",
"$",
"name",
",",
"$",
"callback",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set a global mixin
@param string $name
@param callable $callback
@return $this | [
"Set",
"a",
"global",
"mixin"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/ItemCollectors/RouterGlobalsCollector.php#L44-L48 | train |
opis-colibri/framework | src/ItemCollectors/RouterGlobalsCollector.php | RouterGlobalsCollector.bind | public function bind(string $name, callable $callback): self
{
$this->data->bind($name, $callback);
return $this;
} | php | public function bind(string $name, callable $callback): self
{
$this->data->bind($name, $callback);
return $this;
} | [
"public",
"function",
"bind",
"(",
"string",
"$",
"name",
",",
"callable",
"$",
"callback",
")",
":",
"self",
"{",
"$",
"this",
"->",
"data",
"->",
"bind",
"(",
"$",
"name",
",",
"$",
"callback",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a global binding
@param string $name The name of the binding
@param callable $callback A callback that will return the binding's value
@return $this | [
"Defines",
"a",
"global",
"binding"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/ItemCollectors/RouterGlobalsCollector.php#L58-L62 | train |
opis-colibri/framework | src/ItemCollectors/RouterGlobalsCollector.php | RouterGlobalsCollector.callback | public function callback(string $name, callable $callback): self
{
$this->data->callback($name, $callback);
return $this;
} | php | public function callback(string $name, callable $callback): self
{
$this->data->callback($name, $callback);
return $this;
} | [
"public",
"function",
"callback",
"(",
"string",
"$",
"name",
",",
"callable",
"$",
"callback",
")",
":",
"self",
"{",
"$",
"this",
"->",
"data",
"->",
"callback",
"(",
"$",
"name",
",",
"$",
"callback",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a global callback
@param string $name The name of the callback
@param callable $callback A callback
@return $this | [
"Defines",
"a",
"global",
"callback"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/ItemCollectors/RouterGlobalsCollector.php#L72-L76 | train |
opis-colibri/framework | src/ItemCollectors/RouterGlobalsCollector.php | RouterGlobalsCollector.implicit | public function implicit(string $name, $value): self
{
$this->data->implicit($name, $value);
return $this;
} | php | public function implicit(string $name, $value): self
{
$this->data->implicit($name, $value);
return $this;
} | [
"public",
"function",
"implicit",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"data",
"->",
"implicit",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set a global implicit value for a wildcard
@param string $name The name of the wildcard
@param mixed $value The implicit value
@return $this | [
"Set",
"a",
"global",
"implicit",
"value",
"for",
"a",
"wildcard"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/ItemCollectors/RouterGlobalsCollector.php#L86-L90 | train |
opis-colibri/framework | src/ItemCollectors/RouterGlobalsCollector.php | RouterGlobalsCollector.placeholder | public function placeholder(string $name, string $value): self
{
$this->data->placeholder($name, $value);
return $this;
} | php | public function placeholder(string $name, string $value): self
{
$this->data->placeholder($name, $value);
return $this;
} | [
"public",
"function",
"placeholder",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"data",
"->",
"placeholder",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set a global placeholder
@param string $name The name of the wildcard
@param string $value A regex expression
@return $this | [
"Set",
"a",
"global",
"placeholder"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/ItemCollectors/RouterGlobalsCollector.php#L100-L104 | train |
opis-colibri/framework | src/ItemCollectors/ViewCollector.php | ViewCollector.handle | public function handle(string $pattern, callable $resolver): Route
{
$route = $this->data
->createRoute($pattern, $resolver)
->set('priority', $this->crtPriority);
$this->data->sort();
return $route;
} | php | public function handle(string $pattern, callable $resolver): Route
{
$route = $this->data
->createRoute($pattern, $resolver)
->set('priority', $this->crtPriority);
$this->data->sort();
return $route;
} | [
"public",
"function",
"handle",
"(",
"string",
"$",
"pattern",
",",
"callable",
"$",
"resolver",
")",
":",
"Route",
"{",
"$",
"route",
"=",
"$",
"this",
"->",
"data",
"->",
"createRoute",
"(",
"$",
"pattern",
",",
"$",
"resolver",
")",
"->",
"set",
"... | Defines a new view route
@param string $pattern View's pattern
@param callable $resolver A callback that will resolve a view route into a path
@return Route | [
"Defines",
"a",
"new",
"view",
"route"
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/ItemCollectors/ViewCollector.php#L46-L55 | train |
spiral/reactor | src/NamespaceDeclaration.php | NamespaceDeclaration.addElement | public function addElement(DeclarationInterface $element): NamespaceDeclaration
{
$this->elements->add($element);
if ($element instanceof DependedInterface) {
$this->addUses($element->getDependencies());
}
return $this;
} | php | public function addElement(DeclarationInterface $element): NamespaceDeclaration
{
$this->elements->add($element);
if ($element instanceof DependedInterface) {
$this->addUses($element->getDependencies());
}
return $this;
} | [
"public",
"function",
"addElement",
"(",
"DeclarationInterface",
"$",
"element",
")",
":",
"NamespaceDeclaration",
"{",
"$",
"this",
"->",
"elements",
"->",
"add",
"(",
"$",
"element",
")",
";",
"if",
"(",
"$",
"element",
"instanceof",
"DependedInterface",
")"... | Method will automatically mount requested uses is any.
@param DeclarationInterface $element
@return self
@throws Exception\ReactorException | [
"Method",
"will",
"automatically",
"mount",
"requested",
"uses",
"is",
"any",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/NamespaceDeclaration.php#L54-L62 | train |
opis-colibri/framework | src/ItemCollectors/ContractCollector.php | ContractCollector.alias | public function alias(string $alias, string $concrete): self
{
$this->data->alias($alias, $concrete);
return $this;
} | php | public function alias(string $alias, string $concrete): self
{
$this->data->alias($alias, $concrete);
return $this;
} | [
"public",
"function",
"alias",
"(",
"string",
"$",
"alias",
",",
"string",
"$",
"concrete",
")",
":",
"self",
"{",
"$",
"this",
"->",
"data",
"->",
"alias",
"(",
"$",
"alias",
",",
"$",
"concrete",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Alias a type.
@param string $alias An alias for the specified class or interface
@param string $concrete Concrete class or interface name
@return self Self reference | [
"Alias",
"a",
"type",
"."
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/ItemCollectors/ContractCollector.php#L60-L64 | train |
opis-colibri/framework | src/ItemCollectors/ContractCollector.php | ContractCollector.singleton | public function singleton(string $abstract, $concrete = null, array $arguments = []): self
{
$this->data->singleton($abstract, $concrete, $arguments);
return $this;
} | php | public function singleton(string $abstract, $concrete = null, array $arguments = []): self
{
$this->data->singleton($abstract, $concrete, $arguments);
return $this;
} | [
"public",
"function",
"singleton",
"(",
"string",
"$",
"abstract",
",",
"$",
"concrete",
"=",
"null",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
")",
":",
"self",
"{",
"$",
"this",
"->",
"data",
"->",
"singleton",
"(",
"$",
"abstract",
",",
"$",
... | Register a singleton binding with the container.
@param string $abstract Class name or interface name
@param string|callable|null $concrete
@param array $arguments
@return self | [
"Register",
"a",
"singleton",
"binding",
"with",
"the",
"container",
"."
] | 22b2f0ed31876a05c9a7813c6881d2ba2b5039b8 | https://github.com/opis-colibri/framework/blob/22b2f0ed31876a05c9a7813c6881d2ba2b5039b8/src/ItemCollectors/ContractCollector.php#L88-L92 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Provider/DatabaseMenuProvider.php | DatabaseMenuProvider.get | public function get($name, array $options = array())
{
return $this->builder->build($name, $this->container->get('request_stack')->getCurrentRequest());
} | php | public function get($name, array $options = array())
{
return $this->builder->build($name, $this->container->get('request_stack')->getCurrentRequest());
} | [
"public",
"function",
"get",
"(",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"builder",
"->",
"build",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'request... | Retrieves a menu by its name
@param string $name
@param array $options
@return \Knp\Menu\ItemInterface
@throws \InvalidArgumentException if the menu does not exists | [
"Retrieves",
"a",
"menu",
"by",
"its",
"name"
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Provider/DatabaseMenuProvider.php#L51-L54 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Provider/DatabaseMenuProvider.php | DatabaseMenuProvider.has | public function has($name, array $options = array())
{
$root = $this->builder->hasRootItemByName($name, $this->container->get('request_stack')->getCurrentRequest());
return null !== $root;
} | php | public function has($name, array $options = array())
{
$root = $this->builder->hasRootItemByName($name, $this->container->get('request_stack')->getCurrentRequest());
return null !== $root;
} | [
"public",
"function",
"has",
"(",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"root",
"=",
"$",
"this",
"->",
"builder",
"->",
"hasRootItemByName",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"container",
"->",
"... | Checks whether a menu exists in this provider
@param string $name
@param array $options
@return bool | [
"Checks",
"whether",
"a",
"menu",
"exists",
"in",
"this",
"provider"
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Provider/DatabaseMenuProvider.php#L63-L68 | train |
SimplyCodedSoftware/integration-messaging | src/Amqp/AmqpExchange.php | AmqpExchange.withArgument | public function withArgument(string $name, $value) : self
{
$this->enqueueExchange->setArgument($name, $value);
return $this;
} | php | public function withArgument(string $name, $value) : self
{
$this->enqueueExchange->setArgument($name, $value);
return $this;
} | [
"public",
"function",
"withArgument",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"enqueueExchange",
"->",
"setArgument",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] | optional, used by plugins and broker-specific features
@param string $name
@param $value
@return AmqpExchange | [
"optional",
"used",
"by",
"plugins",
"and",
"broker",
"-",
"specific",
"features"
] | d2d19c64f115adb554952962853a047d40be08bd | https://github.com/SimplyCodedSoftware/integration-messaging/blob/d2d19c64f115adb554952962853a047d40be08bd/src/Amqp/AmqpExchange.php#L72-L77 | train |
spiral/reactor | src/Partial/Method.php | Method.setSource | public function setSource($source): Method
{
if (!empty($source)) {
if (is_array($source)) {
$this->source->setLines($source);
} elseif (is_string($source)) {
$this->source->setString($source);
}
}
return $this;
} | php | public function setSource($source): Method
{
if (!empty($source)) {
if (is_array($source)) {
$this->source->setLines($source);
} elseif (is_string($source)) {
$this->source->setString($source);
}
}
return $this;
} | [
"public",
"function",
"setSource",
"(",
"$",
"source",
")",
":",
"Method",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"source",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"source",
")",
")",
"{",
"$",
"this",
"->",
"source",
"->",
"setLines",
"... | Set method source.
@param string|array $source
@return self | [
"Set",
"method",
"source",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Partial/Method.php#L85-L96 | train |
spiral/reactor | src/Partial/Method.php | Method.initSource | private function initSource($source)
{
if (empty($this->source)) {
$this->source = new Source();
}
if (!empty($source)) {
if (is_array($source)) {
$this->source->setLines($source);
} elseif (is_string($source)) {
$this->source->setString($source);
}
}
} | php | private function initSource($source)
{
if (empty($this->source)) {
$this->source = new Source();
}
if (!empty($source)) {
if (is_array($source)) {
$this->source->setLines($source);
} elseif (is_string($source)) {
$this->source->setString($source);
}
}
} | [
"private",
"function",
"initSource",
"(",
"$",
"source",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"source",
")",
")",
"{",
"$",
"this",
"->",
"source",
"=",
"new",
"Source",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"s... | Init source value.
@param string|array $source | [
"Init",
"source",
"value",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Partial/Method.php#L164-L177 | train |
SidRoberts/phalcon-events | src/View/NotFoundListener.php | NotFoundListener.notFoundView | public function notFoundView(Event $event, ViewInterface $view, $enginePath) : bool
{
if ($enginePath && !is_array($enginePath)) {
$enginePath = [$enginePath];
}
$message = sprintf(
"View was not found in any of the views directory. Active render paths: [%s]",
($enginePath ? join(", ", $enginePath) : gettype($enginePath))
);
$this->logger->error($message);
return true;
} | php | public function notFoundView(Event $event, ViewInterface $view, $enginePath) : bool
{
if ($enginePath && !is_array($enginePath)) {
$enginePath = [$enginePath];
}
$message = sprintf(
"View was not found in any of the views directory. Active render paths: [%s]",
($enginePath ? join(", ", $enginePath) : gettype($enginePath))
);
$this->logger->error($message);
return true;
} | [
"public",
"function",
"notFoundView",
"(",
"Event",
"$",
"event",
",",
"ViewInterface",
"$",
"view",
",",
"$",
"enginePath",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"enginePath",
"&&",
"!",
"is_array",
"(",
"$",
"enginePath",
")",
")",
"{",
"$",
"engine... | Notify about not found views. | [
"Notify",
"about",
"not",
"found",
"views",
"."
] | 3a05bde730cb0fa20aab498746d05e8e11b738cc | https://github.com/SidRoberts/phalcon-events/blob/3a05bde730cb0fa20aab498746d05e8e11b738cc/src/View/NotFoundListener.php#L32-L46 | train |
spiral/reactor | src/Traits/UsesTrait.php | UsesTrait.addUses | public function addUses(array $uses): self
{
foreach ($uses as $class => $alias) {
$this->addUse($class, $alias);
}
return $this;
} | php | public function addUses(array $uses): self
{
foreach ($uses as $class => $alias) {
$this->addUse($class, $alias);
}
return $this;
} | [
"public",
"function",
"addUses",
"(",
"array",
"$",
"uses",
")",
":",
"self",
"{",
"foreach",
"(",
"$",
"uses",
"as",
"$",
"class",
"=>",
"$",
"alias",
")",
"{",
"$",
"this",
"->",
"addUse",
"(",
"$",
"class",
",",
"$",
"alias",
")",
";",
"}",
... | Add additional set of uses.
@param array $uses
@return self | [
"Add",
"additional",
"set",
"of",
"uses",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Traits/UsesTrait.php#L55-L62 | train |
spiral/reactor | src/Partial/Source.php | Source.fromString | public static function fromString(string $string, bool $cutIndents = false): Source
{
$source = new self();
return $source->setString($string, $cutIndents);
} | php | public static function fromString(string $string, bool $cutIndents = false): Source
{
$source = new self();
return $source->setString($string, $cutIndents);
} | [
"public",
"static",
"function",
"fromString",
"(",
"string",
"$",
"string",
",",
"bool",
"$",
"cutIndents",
"=",
"false",
")",
":",
"Source",
"{",
"$",
"source",
"=",
"new",
"self",
"(",
")",
";",
"return",
"$",
"source",
"->",
"setString",
"(",
"$",
... | Create version of source cut from specific string location.
@param string $string
@param bool $cutIndents Function Strings::normalizeIndents will be applied.
@return Source | [
"Create",
"version",
"of",
"source",
"cut",
"from",
"specific",
"string",
"location",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Partial/Source.php#L120-L125 | train |
spiral/reactor | src/Partial/Source.php | Source.fetchLines | protected function fetchLines(string $string, bool $cutIndents): array
{
if ($cutIndents) {
$string = self::normalizeIndents($string, "");
}
$lines = explode("\n", self::normalizeEndings($string, false));
//Pre-processing
return array_map([$this, 'prepareLine'], $lines);
} | php | protected function fetchLines(string $string, bool $cutIndents): array
{
if ($cutIndents) {
$string = self::normalizeIndents($string, "");
}
$lines = explode("\n", self::normalizeEndings($string, false));
//Pre-processing
return array_map([$this, 'prepareLine'], $lines);
} | [
"protected",
"function",
"fetchLines",
"(",
"string",
"$",
"string",
",",
"bool",
"$",
"cutIndents",
")",
":",
"array",
"{",
"if",
"(",
"$",
"cutIndents",
")",
"{",
"$",
"string",
"=",
"self",
"::",
"normalizeIndents",
"(",
"$",
"string",
",",
"\"\"",
... | Converts input string into set of lines.
@param string $string
@param bool $cutIndents
@return array | [
"Converts",
"input",
"string",
"into",
"set",
"of",
"lines",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Partial/Source.php#L135-L145 | train |
spiral/reactor | src/Partial/Source.php | Source.normalizeEndings | public static function normalizeEndings(string $string, bool $joinMultiple = true): string
{
if (!$joinMultiple) {
return str_replace("\r\n", "\n", $string);
}
return preg_replace('/[\n\r]+/', "\n", $string);
} | php | public static function normalizeEndings(string $string, bool $joinMultiple = true): string
{
if (!$joinMultiple) {
return str_replace("\r\n", "\n", $string);
}
return preg_replace('/[\n\r]+/', "\n", $string);
} | [
"public",
"static",
"function",
"normalizeEndings",
"(",
"string",
"$",
"string",
",",
"bool",
"$",
"joinMultiple",
"=",
"true",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"joinMultiple",
")",
"{",
"return",
"str_replace",
"(",
"\"\\r\\n\"",
",",
"\"\\n... | Normalize string endings to avoid EOL problem. Replace \n\r and multiply new lines with
single \n.
@param string $string String to be normalized.
@param bool $joinMultiple Join multiple new lines into one.
@return string | [
"Normalize",
"string",
"endings",
"to",
"avoid",
"EOL",
"problem",
".",
"Replace",
"\\",
"n",
"\\",
"r",
"and",
"multiply",
"new",
"lines",
"with",
"single",
"\\",
"n",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Partial/Source.php#L168-L175 | train |
spiral/reactor | src/Partial/Source.php | Source.normalizeIndents | public static function normalizeIndents(string $string, string $tabulationCost = " "): string
{
$string = self::normalizeEndings($string, false);
$lines = explode("\n", $string);
$minIndent = null;
foreach ($lines as $line) {
if (!trim($line)) {
continue;
}
$line = str_replace("\t", $tabulationCost, $line);
//Getting indent size
if (!preg_match("/^( +)/", $line, $matches)) {
//Some line has no indent
return $string;
}
if ($minIndent === null) {
$minIndent = strlen($matches[1]);
}
$minIndent = min($minIndent, strlen($matches[1]));
}
//Fixing indent
foreach ($lines as &$line) {
if (empty($line)) {
continue;
}
//Getting line indent
preg_match("/^([ \t]+)/", $line, $matches);
$indent = $matches[1];
if (!trim($line)) {
$line = '';
continue;
}
//Getting new indent
$useIndent = str_repeat(
" ",
strlen(str_replace("\t", $tabulationCost, $indent)) - $minIndent
);
$line = $useIndent . substr($line, strlen($indent));
unset($line);
}
return join("\n", $lines);
} | php | public static function normalizeIndents(string $string, string $tabulationCost = " "): string
{
$string = self::normalizeEndings($string, false);
$lines = explode("\n", $string);
$minIndent = null;
foreach ($lines as $line) {
if (!trim($line)) {
continue;
}
$line = str_replace("\t", $tabulationCost, $line);
//Getting indent size
if (!preg_match("/^( +)/", $line, $matches)) {
//Some line has no indent
return $string;
}
if ($minIndent === null) {
$minIndent = strlen($matches[1]);
}
$minIndent = min($minIndent, strlen($matches[1]));
}
//Fixing indent
foreach ($lines as &$line) {
if (empty($line)) {
continue;
}
//Getting line indent
preg_match("/^([ \t]+)/", $line, $matches);
$indent = $matches[1];
if (!trim($line)) {
$line = '';
continue;
}
//Getting new indent
$useIndent = str_repeat(
" ",
strlen(str_replace("\t", $tabulationCost, $indent)) - $minIndent
);
$line = $useIndent . substr($line, strlen($indent));
unset($line);
}
return join("\n", $lines);
} | [
"public",
"static",
"function",
"normalizeIndents",
"(",
"string",
"$",
"string",
",",
"string",
"$",
"tabulationCost",
"=",
"\" \"",
")",
":",
"string",
"{",
"$",
"string",
"=",
"self",
"::",
"normalizeEndings",
"(",
"$",
"string",
",",
"false",
")",
";... | Shift all string lines to have minimum indent size set to 0.
Example:
|-a
|--b
|--c
|---d
Output:
|a
|-b
|-c
|--d
@param string $string Input string with multiple lines.
@param string $tabulationCost How to treat \t symbols relatively to spaces. By default, this
is set to 4 spaces.
@return string | [
"Shift",
"all",
"string",
"lines",
"to",
"have",
"minimum",
"indent",
"size",
"set",
"to",
"0",
"."
] | 222a70249127f1c515238358f2ee0a91d00f9a51 | https://github.com/spiral/reactor/blob/222a70249127f1c515238358f2ee0a91d00f9a51/src/Partial/Source.php#L198-L240 | train |
zicht/menu-bundle | src/Zicht/Bundle/MenuBundle/Url/AliasingStrategy.php | AliasingStrategy.generatePublicAlias | public function generatePublicAlias($subject, $currentAlias = '')
{
$path = $this->urlProvider->url($subject);
$menuItem = $this->menuManager->getItemBy(array(':path' => $path));
if (!empty($menuItem)) {
$parts = array();
for ($item = $menuItem; !is_null($item->getParent()); $item = $item->getParent()) {
$parts [] = Str::systemize($item->getTitle());
}
$alias = '/' . join('/', array_reverse($parts));
} else {
$alias = parent::generatePublicAlias($subject);
}
return $alias;
} | php | public function generatePublicAlias($subject, $currentAlias = '')
{
$path = $this->urlProvider->url($subject);
$menuItem = $this->menuManager->getItemBy(array(':path' => $path));
if (!empty($menuItem)) {
$parts = array();
for ($item = $menuItem; !is_null($item->getParent()); $item = $item->getParent()) {
$parts [] = Str::systemize($item->getTitle());
}
$alias = '/' . join('/', array_reverse($parts));
} else {
$alias = parent::generatePublicAlias($subject);
}
return $alias;
} | [
"public",
"function",
"generatePublicAlias",
"(",
"$",
"subject",
",",
"$",
"currentAlias",
"=",
"''",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"urlProvider",
"->",
"url",
"(",
"$",
"subject",
")",
";",
"$",
"menuItem",
"=",
"$",
"this",
"->",
... | Generate a public alias for the passed object
@param mixed $subject
@param string $currentAlias
@return string | [
"Generate",
"a",
"public",
"alias",
"for",
"the",
"passed",
"object"
] | b6f22d50025297ad686c8f3afb7b6afe736b7f97 | https://github.com/zicht/menu-bundle/blob/b6f22d50025297ad686c8f3afb7b6afe736b7f97/src/Zicht/Bundle/MenuBundle/Url/AliasingStrategy.php#L51-L66 | train |
unicodeveloper/laravel-emoji | src/Emoji.php | Emoji.findByAlias | public function findByAlias($emojiName = null) : string
{
if (is_null($emojiName)) {
throw IsNull::create("Please provide the name of the emoji you are looking for");
}
$emoji = strtolower($emojiName);
if (! array_key_exists($emoji, $this->getEmojis())) {
throw UnknownEmoji::create($emoji);
}
return $this->getEmojis()[$emoji];
} | php | public function findByAlias($emojiName = null) : string
{
if (is_null($emojiName)) {
throw IsNull::create("Please provide the name of the emoji you are looking for");
}
$emoji = strtolower($emojiName);
if (! array_key_exists($emoji, $this->getEmojis())) {
throw UnknownEmoji::create($emoji);
}
return $this->getEmojis()[$emoji];
} | [
"public",
"function",
"findByAlias",
"(",
"$",
"emojiName",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"is_null",
"(",
"$",
"emojiName",
")",
")",
"{",
"throw",
"IsNull",
"::",
"create",
"(",
"\"Please provide the name of the emoji you are looking for\"",
... | Get the emoji by passing the commonly used emoji name
@param string $emojiName
@return unicode
@throws \Unicodeveloper\Emoji\Exceptions\IsNull
@throws \Unicodeveloper\Emoji\Exceptions\UnknownUnicode | [
"Get",
"the",
"emoji",
"by",
"passing",
"the",
"commonly",
"used",
"emoji",
"name"
] | d79dcaed5e6d2ca21886deb7bf5a5036d53d872d | https://github.com/unicodeveloper/laravel-emoji/blob/d79dcaed5e6d2ca21886deb7bf5a5036d53d872d/src/Emoji.php#L34-L47 | train |
unicodeveloper/laravel-emoji | src/Emoji.php | Emoji.findByUnicode | public function findByUnicode($unicode = null) : string
{
if (is_null($unicode)) {
throw IsNull::create("Please provide a valid UTF-8 Unicode value");
}
$emojis = array_flip($this->getEmojis());
if (! array_key_exists($unicode, $emojis)) {
throw UnknownUnicode::create($unicode);
}
return $emojis[$unicode];
} | php | public function findByUnicode($unicode = null) : string
{
if (is_null($unicode)) {
throw IsNull::create("Please provide a valid UTF-8 Unicode value");
}
$emojis = array_flip($this->getEmojis());
if (! array_key_exists($unicode, $emojis)) {
throw UnknownUnicode::create($unicode);
}
return $emojis[$unicode];
} | [
"public",
"function",
"findByUnicode",
"(",
"$",
"unicode",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"is_null",
"(",
"$",
"unicode",
")",
")",
"{",
"throw",
"IsNull",
"::",
"create",
"(",
"\"Please provide a valid UTF-8 Unicode value\"",
")",
";",
"}... | Get the emoji name by passing the unicode value
@param string $unicode
@return string
@throws \Unicodeveloper\Emoji\Exceptions\IsNull
@throws \Unicodeveloper\Emoji\Exceptions\UnknownUnicode | [
"Get",
"the",
"emoji",
"name",
"by",
"passing",
"the",
"unicode",
"value"
] | d79dcaed5e6d2ca21886deb7bf5a5036d53d872d | https://github.com/unicodeveloper/laravel-emoji/blob/d79dcaed5e6d2ca21886deb7bf5a5036d53d872d/src/Emoji.php#L67-L80 | train |
thomastkim/laravel-online-users | src/Kim/Activity/Traits/ActivitySorter.php | ActivitySorter.scopeOrderByUsers | public function scopeOrderByUsers($query, $column, $dir = 'ASC')
{
$table = $this->getTable();
$userModel = config('auth.providers.users.model');
$user = new $userModel;
$userTable = $user->getTable();
$userKey = $user->getKeyName();
return $query->join($userTable, "{$table}.user_id", '=', "{$userTable}.{$userKey}")->orderBy("{$userTable}.{$column}", $dir);
} | php | public function scopeOrderByUsers($query, $column, $dir = 'ASC')
{
$table = $this->getTable();
$userModel = config('auth.providers.users.model');
$user = new $userModel;
$userTable = $user->getTable();
$userKey = $user->getKeyName();
return $query->join($userTable, "{$table}.user_id", '=', "{$userTable}.{$userKey}")->orderBy("{$userTable}.{$column}", $dir);
} | [
"public",
"function",
"scopeOrderByUsers",
"(",
"$",
"query",
",",
"$",
"column",
",",
"$",
"dir",
"=",
"'ASC'",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"userModel",
"=",
"config",
"(",
"'auth.providers.users.model... | Use joins to order by the users' column attributes.
@param \Illuminate\Database\Query\Builder $query
@param string $column
@return \Illuminate\Database\Query\Builder|static | [
"Use",
"joins",
"to",
"order",
"by",
"the",
"users",
"column",
"attributes",
"."
] | 8564a3822fcaad2772d3df403adcdfd56de999e0 | https://github.com/thomastkim/laravel-online-users/blob/8564a3822fcaad2772d3df403adcdfd56de999e0/src/Kim/Activity/Traits/ActivitySorter.php#L38-L48 | train |
odan/phinx-migrations-generator | src/Migration/Adapter/Generator/PhinxMySqlGenerator.php | PhinxMySqlGenerator.eq | protected function eq($arr, $arr2, $keys): bool
{
$val1 = $this->find($arr, $keys);
$val2 = $this->find($arr2, $keys);
return $val1 === $val2;
} | php | protected function eq($arr, $arr2, $keys): bool
{
$val1 = $this->find($arr, $keys);
$val2 = $this->find($arr2, $keys);
return $val1 === $val2;
} | [
"protected",
"function",
"eq",
"(",
"$",
"arr",
",",
"$",
"arr2",
",",
"$",
"keys",
")",
":",
"bool",
"{",
"$",
"val1",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"arr",
",",
"$",
"keys",
")",
";",
"$",
"val2",
"=",
"$",
"this",
"->",
"find",
... | Compare array.
@param array $arr
@param array $arr2
@param array $keys
@return bool | [
"Compare",
"array",
"."
] | 06db032b2ba0c3861361f849d1e16e6c1d6ce271 | https://github.com/odan/phinx-migrations-generator/blob/06db032b2ba0c3861361f849d1e16e6c1d6ce271/src/Migration/Adapter/Generator/PhinxMySqlGenerator.php#L208-L214 | train |
odan/phinx-migrations-generator | src/Migration/Adapter/Generator/PhinxMySqlGenerator.php | PhinxMySqlGenerator.getPhinxTablePrimaryKey | protected function getPhinxTablePrimaryKey(array $attributes, array $table): array
{
$primaryKeys = $this->getPrimaryKeys($table);
$attributes['id'] = false;
if (!empty($primaryKeys)) {
$attributes['primary_key'] = $primaryKeys;
}
return $attributes;
} | php | protected function getPhinxTablePrimaryKey(array $attributes, array $table): array
{
$primaryKeys = $this->getPrimaryKeys($table);
$attributes['id'] = false;
if (!empty($primaryKeys)) {
$attributes['primary_key'] = $primaryKeys;
}
return $attributes;
} | [
"protected",
"function",
"getPhinxTablePrimaryKey",
"(",
"array",
"$",
"attributes",
",",
"array",
"$",
"table",
")",
":",
"array",
"{",
"$",
"primaryKeys",
"=",
"$",
"this",
"->",
"getPrimaryKeys",
"(",
"$",
"table",
")",
";",
"$",
"attributes",
"[",
"'id... | Define table id value.
@param array $attributes
@param array $table
@return array Attributes | [
"Define",
"table",
"id",
"value",
"."
] | 06db032b2ba0c3861361f849d1e16e6c1d6ce271 | https://github.com/odan/phinx-migrations-generator/blob/06db032b2ba0c3861361f849d1e16e6c1d6ce271/src/Migration/Adapter/Generator/PhinxMySqlGenerator.php#L375-L385 | train |
odan/phinx-migrations-generator | src/Migration/Adapter/Generator/PhinxMySqlGenerator.php | PhinxMySqlGenerator.getPrimaryKeys | protected function getPrimaryKeys(array $table): array
{
$primaryKeys = [];
foreach ($table['columns'] as $column) {
$columnName = $column['COLUMN_NAME'];
$columnKey = $column['COLUMN_KEY'];
if ($columnKey !== 'PRI') {
continue;
}
$primaryKeys[] = $columnName;
}
return $primaryKeys;
} | php | protected function getPrimaryKeys(array $table): array
{
$primaryKeys = [];
foreach ($table['columns'] as $column) {
$columnName = $column['COLUMN_NAME'];
$columnKey = $column['COLUMN_KEY'];
if ($columnKey !== 'PRI') {
continue;
}
$primaryKeys[] = $columnName;
}
return $primaryKeys;
} | [
"protected",
"function",
"getPrimaryKeys",
"(",
"array",
"$",
"table",
")",
":",
"array",
"{",
"$",
"primaryKeys",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"table",
"[",
"'columns'",
"]",
"as",
"$",
"column",
")",
"{",
"$",
"columnName",
"=",
"$",
"c... | Collect alternate primary keys.
@param array $table
@return array | [
"Collect",
"alternate",
"primary",
"keys",
"."
] | 06db032b2ba0c3861361f849d1e16e6c1d6ce271 | https://github.com/odan/phinx-migrations-generator/blob/06db032b2ba0c3861361f849d1e16e6c1d6ce271/src/Migration/Adapter/Generator/PhinxMySqlGenerator.php#L394-L407 | train |
odan/phinx-migrations-generator | src/Migration/Adapter/Generator/PhinxMySqlGenerator.php | PhinxMySqlGenerator.getColumnUpdate | protected function getColumnUpdate(array $schema, string $table, string $columnName): string
{
$columns = $schema['tables'][$table]['columns'];
$columnData = $columns[$columnName];
$phinxType = $this->getPhinxColumnType($columnData);
$columnAttributes = $this->getPhinxColumnOptions($phinxType, $columnData, $columns);
$result = sprintf("%s->changeColumn('%s', '%s', $columnAttributes)", $this->ind2, $columnName, $phinxType, $columnAttributes);
return $result;
} | php | protected function getColumnUpdate(array $schema, string $table, string $columnName): string
{
$columns = $schema['tables'][$table]['columns'];
$columnData = $columns[$columnName];
$phinxType = $this->getPhinxColumnType($columnData);
$columnAttributes = $this->getPhinxColumnOptions($phinxType, $columnData, $columns);
$result = sprintf("%s->changeColumn('%s', '%s', $columnAttributes)", $this->ind2, $columnName, $phinxType, $columnAttributes);
return $result;
} | [
"protected",
"function",
"getColumnUpdate",
"(",
"array",
"$",
"schema",
",",
"string",
"$",
"table",
",",
"string",
"$",
"columnName",
")",
":",
"string",
"{",
"$",
"columns",
"=",
"$",
"schema",
"[",
"'tables'",
"]",
"[",
"$",
"table",
"]",
"[",
"'co... | Generate column update.
@param array $schema
@param string $table
@param string $columnName
@return string | [
"Generate",
"column",
"update",
"."
] | 06db032b2ba0c3861361f849d1e16e6c1d6ce271 | https://github.com/odan/phinx-migrations-generator/blob/06db032b2ba0c3861361f849d1e16e6c1d6ce271/src/Migration/Adapter/Generator/PhinxMySqlGenerator.php#L1001-L1011 | train |
odan/phinx-migrations-generator | src/Migration/Adapter/Generator/PhinxMySqlGenerator.php | PhinxMySqlGenerator.getForeignKeyRuleValue | protected function getForeignKeyRuleValue(string $value): string
{
$value = strtolower($value);
if ($value == 'no action') {
return 'NO_ACTION';
}
if ($value == 'cascade') {
return 'CASCADE';
}
if ($value == 'restrict') {
return 'RESTRICT';
}
if ($value == 'set null') {
return 'SET_NULL';
}
return 'NO_ACTION';
} | php | protected function getForeignKeyRuleValue(string $value): string
{
$value = strtolower($value);
if ($value == 'no action') {
return 'NO_ACTION';
}
if ($value == 'cascade') {
return 'CASCADE';
}
if ($value == 'restrict') {
return 'RESTRICT';
}
if ($value == 'set null') {
return 'SET_NULL';
}
return 'NO_ACTION';
} | [
"protected",
"function",
"getForeignKeyRuleValue",
"(",
"string",
"$",
"value",
")",
":",
"string",
"{",
"$",
"value",
"=",
"strtolower",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"==",
"'no action'",
")",
"{",
"return",
"'NO_ACTION'",
";",
"... | Generate foreign key rule value.
@param string $value
@return string | [
"Generate",
"foreign",
"key",
"rule",
"value",
"."
] | 06db032b2ba0c3861361f849d1e16e6c1d6ce271 | https://github.com/odan/phinx-migrations-generator/blob/06db032b2ba0c3861361f849d1e16e6c1d6ce271/src/Migration/Adapter/Generator/PhinxMySqlGenerator.php#L1297-L1314 | train |
odan/phinx-migrations-generator | src/Migration/Adapter/Generator/PhinxMySqlGenerator.php | PhinxMySqlGenerator.prettifyArray | protected function prettifyArray(array $variable, int $tabCount): string
{
$encoder = new PHPEncoder();
return $encoder->encode($variable, [
'array.base' => $tabCount * 4,
'array.inline' => true,
'array.indent' => 4,
'array.eol' => "\n",
]);
} | php | protected function prettifyArray(array $variable, int $tabCount): string
{
$encoder = new PHPEncoder();
return $encoder->encode($variable, [
'array.base' => $tabCount * 4,
'array.inline' => true,
'array.indent' => 4,
'array.eol' => "\n",
]);
} | [
"protected",
"function",
"prettifyArray",
"(",
"array",
"$",
"variable",
",",
"int",
"$",
"tabCount",
")",
":",
"string",
"{",
"$",
"encoder",
"=",
"new",
"PHPEncoder",
"(",
")",
";",
"return",
"$",
"encoder",
"->",
"encode",
"(",
"$",
"variable",
",",
... | Prettify array.
@param array $variable Array to prettify
@param int $tabCount Initial tab count
@return string | [
"Prettify",
"array",
"."
] | 06db032b2ba0c3861361f849d1e16e6c1d6ce271 | https://github.com/odan/phinx-migrations-generator/blob/06db032b2ba0c3861361f849d1e16e6c1d6ce271/src/Migration/Adapter/Generator/PhinxMySqlGenerator.php#L1365-L1375 | train |
odan/phinx-migrations-generator | src/Migration/Generator/MigrationGenerator.php | MigrationGenerator.createClassName | protected function createClassName(string $name): string
{
$result = str_replace('_', ' ', $name);
return str_replace(' ', '', ucwords($result));
} | php | protected function createClassName(string $name): string
{
$result = str_replace('_', ' ', $name);
return str_replace(' ', '', ucwords($result));
} | [
"protected",
"function",
"createClassName",
"(",
"string",
"$",
"name",
")",
":",
"string",
"{",
"$",
"result",
"=",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"name",
")",
";",
"return",
"str_replace",
"(",
"' '",
",",
"''",
",",
"ucwords",
"(",... | Create a class name.
@param string $name Name
@return string Class name | [
"Create",
"a",
"class",
"name",
"."
] | 06db032b2ba0c3861361f849d1e16e6c1d6ce271 | https://github.com/odan/phinx-migrations-generator/blob/06db032b2ba0c3861361f849d1e16e6c1d6ce271/src/Migration/Generator/MigrationGenerator.php#L336-L341 | train |
odan/phinx-migrations-generator | src/Migration/Utility/ArrayUtil.php | ArrayUtil.unsetArrayKeys | public function unsetArrayKeys(array &$array, string $unwantedKey): void
{
unset($array[$unwantedKey]);
foreach ($array as &$value) {
if (is_array($value)) {
$this->unsetArrayKeys($value, $unwantedKey);
}
}
} | php | public function unsetArrayKeys(array &$array, string $unwantedKey): void
{
unset($array[$unwantedKey]);
foreach ($array as &$value) {
if (is_array($value)) {
$this->unsetArrayKeys($value, $unwantedKey);
}
}
} | [
"public",
"function",
"unsetArrayKeys",
"(",
"array",
"&",
"$",
"array",
",",
"string",
"$",
"unwantedKey",
")",
":",
"void",
"{",
"unset",
"(",
"$",
"array",
"[",
"$",
"unwantedKey",
"]",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"&",
"$",
"valu... | Unset array keys.
@param array $array The array
@param string $unwantedKey The key to remove
@return void | [
"Unset",
"array",
"keys",
"."
] | 06db032b2ba0c3861361f849d1e16e6c1d6ce271 | https://github.com/odan/phinx-migrations-generator/blob/06db032b2ba0c3861361f849d1e16e6c1d6ce271/src/Migration/Utility/ArrayUtil.php#L18-L27 | train |
odan/phinx-migrations-generator | src/Migration/Adapter/Database/MySqlSchemaAdapter.php | MySqlSchemaAdapter.createQueryStatement | protected function createQueryStatement(string $sql): PDOStatement
{
$statement = $this->pdo->query($sql);
if (!$statement instanceof PDOStatement) {
throw new RuntimeException('Invalid statement');
}
return $statement;
} | php | protected function createQueryStatement(string $sql): PDOStatement
{
$statement = $this->pdo->query($sql);
if (!$statement instanceof PDOStatement) {
throw new RuntimeException('Invalid statement');
}
return $statement;
} | [
"protected",
"function",
"createQueryStatement",
"(",
"string",
"$",
"sql",
")",
":",
"PDOStatement",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"pdo",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"if",
"(",
"!",
"$",
"statement",
"instanceof",
"PDOStat... | Create a new PDO statement.
@param string $sql The sql
@return PDOStatement The statement | [
"Create",
"a",
"new",
"PDO",
"statement",
"."
] | 06db032b2ba0c3861361f849d1e16e6c1d6ce271 | https://github.com/odan/phinx-migrations-generator/blob/06db032b2ba0c3861361f849d1e16e6c1d6ce271/src/Migration/Adapter/Database/MySqlSchemaAdapter.php#L68-L77 | train |
odan/phinx-migrations-generator | src/Migration/Adapter/Database/MySqlSchemaAdapter.php | MySqlSchemaAdapter.queryFetchAll | protected function queryFetchAll(string $sql): array
{
$statement = $this->createQueryStatement($sql);
$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
if (!$rows) {
return [];
}
return $rows;
} | php | protected function queryFetchAll(string $sql): array
{
$statement = $this->createQueryStatement($sql);
$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
if (!$rows) {
return [];
}
return $rows;
} | [
"protected",
"function",
"queryFetchAll",
"(",
"string",
"$",
"sql",
")",
":",
"array",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"createQueryStatement",
"(",
"$",
"sql",
")",
";",
"$",
"rows",
"=",
"$",
"statement",
"->",
"fetchAll",
"(",
"PDO",
... | Fetch all rows as array.
@param string $sql The sql
@return array The rows | [
"Fetch",
"all",
"rows",
"as",
"array",
"."
] | 06db032b2ba0c3861361f849d1e16e6c1d6ce271 | https://github.com/odan/phinx-migrations-generator/blob/06db032b2ba0c3861361f849d1e16e6c1d6ce271/src/Migration/Adapter/Database/MySqlSchemaAdapter.php#L86-L96 | train |
odan/phinx-migrations-generator | src/Migration/Adapter/Database/MySqlSchemaAdapter.php | MySqlSchemaAdapter.quote | public function quote(?string $value): string
{
if ($value === null) {
return 'NULL';
}
return $this->pdo->quote($value);
} | php | public function quote(?string $value): string
{
if ($value === null) {
return 'NULL';
}
return $this->pdo->quote($value);
} | [
"public",
"function",
"quote",
"(",
"?",
"string",
"$",
"value",
")",
":",
"string",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"'NULL'",
";",
"}",
"return",
"$",
"this",
"->",
"pdo",
"->",
"quote",
"(",
"$",
"value",
")",
"... | Quote value.
@param string|null $value
@return string | [
"Quote",
"value",
"."
] | 06db032b2ba0c3861361f849d1e16e6c1d6ce271 | https://github.com/odan/phinx-migrations-generator/blob/06db032b2ba0c3861361f849d1e16e6c1d6ce271/src/Migration/Adapter/Database/MySqlSchemaAdapter.php#L155-L162 | train |
odan/phinx-migrations-generator | src/Migration/Adapter/Database/MySqlSchemaAdapter.php | MySqlSchemaAdapter.esc | public function esc(?string $value): string
{
if ($value === null) {
return 'NULL';
}
$value = substr($this->pdo->quote($value), 1, -1);
return $value;
} | php | public function esc(?string $value): string
{
if ($value === null) {
return 'NULL';
}
$value = substr($this->pdo->quote($value), 1, -1);
return $value;
} | [
"public",
"function",
"esc",
"(",
"?",
"string",
"$",
"value",
")",
":",
"string",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"'NULL'",
";",
"}",
"$",
"value",
"=",
"substr",
"(",
"$",
"this",
"->",
"pdo",
"->",
"quote",
"("... | Escape value.
@param string|null $value
@return string | [
"Escape",
"value",
"."
] | 06db032b2ba0c3861361f849d1e16e6c1d6ce271 | https://github.com/odan/phinx-migrations-generator/blob/06db032b2ba0c3861361f849d1e16e6c1d6ce271/src/Migration/Adapter/Database/MySqlSchemaAdapter.php#L328-L337 | train |
sobstel/sesshin | src/Session.php | Session.create | public function create()
{
$this->getIdHandler()->generateId();
$this->values = array();
$this->firstTrace = time();
$this->updateLastTrace();
$this->requestsCount = 1;
$this->regenerationTrace = time();
$this->fingerprint = $this->generateFingerprint();
$this->opened = true;
return $this->opened;
} | php | public function create()
{
$this->getIdHandler()->generateId();
$this->values = array();
$this->firstTrace = time();
$this->updateLastTrace();
$this->requestsCount = 1;
$this->regenerationTrace = time();
$this->fingerprint = $this->generateFingerprint();
$this->opened = true;
return $this->opened;
} | [
"public",
"function",
"create",
"(",
")",
"{",
"$",
"this",
"->",
"getIdHandler",
"(",
")",
"->",
"generateId",
"(",
")",
";",
"$",
"this",
"->",
"values",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"firstTrace",
"=",
"time",
"(",
")",
";",
... | Creates new session
It should be called only once at the beginning. If called for existing
session it ovewrites it (clears all values etc).
It can be replaced with {@link self::open()} (called with "true" argument)
@return bool Session opened? | [
"Creates",
"new",
"session"
] | ed95c8128edd31cceb7c440bf9accea6d4a83ad3 | https://github.com/sobstel/sesshin/blob/ed95c8128edd31cceb7c440bf9accea6d4a83ad3/src/Session.php#L81-L98 | train |
sobstel/sesshin | src/Session.php | Session.close | public function close()
{
if ($this->opened) {
if ($this->shouldRegenerateId()) {
$this->regenerateId();
}
$this->updateLastTrace();
$this->save();
$this->values = array();
$this->opened = false;
}
} | php | public function close()
{
if ($this->opened) {
if ($this->shouldRegenerateId()) {
$this->regenerateId();
}
$this->updateLastTrace();
$this->save();
$this->values = array();
$this->opened = false;
}
} | [
"public",
"function",
"close",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"opened",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldRegenerateId",
"(",
")",
")",
"{",
"$",
"this",
"->",
"regenerateId",
"(",
")",
";",
"}",
"$",
"this",
"->",
"upd... | Close the session. | [
"Close",
"the",
"session",
"."
] | ed95c8128edd31cceb7c440bf9accea6d4a83ad3 | https://github.com/sobstel/sesshin/blob/ed95c8128edd31cceb7c440bf9accea6d4a83ad3/src/Session.php#L170-L183 | train |
sobstel/sesshin | src/Session.php | Session.regenerateId | public function regenerateId()
{
if (!$this->idRegenerated) {
$this->getStore()->delete($this->getId());
$this->getIdHandler()->generateId();
$this->regenerationTrace = time();
$this->idRegenerated = true;
return true;
}
return false;
} | php | public function regenerateId()
{
if (!$this->idRegenerated) {
$this->getStore()->delete($this->getId());
$this->getIdHandler()->generateId();
$this->regenerationTrace = time();
$this->idRegenerated = true;
return true;
}
return false;
} | [
"public",
"function",
"regenerateId",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"idRegenerated",
")",
"{",
"$",
"this",
"->",
"getStore",
"(",
")",
"->",
"delete",
"(",
"$",
"this",
"->",
"getId",
"(",
")",
")",
";",
"$",
"this",
"->",
"g... | Regenerates session id.
Destroys current session in store and generates new id, which will be saved
at the end of script execution (together with values).
Id is regenerated at the most once per script execution (even if called a few times).
Mitigates Session Fixation - use it whenever the user's privilege level changes. | [
"Regenerates",
"session",
"id",
"."
] | ed95c8128edd31cceb7c440bf9accea6d4a83ad3 | https://github.com/sobstel/sesshin/blob/ed95c8128edd31cceb7c440bf9accea6d4a83ad3/src/Session.php#L215-L228 | train |
sobstel/sesshin | src/Session.php | Session.getValue | public function getValue($name, $namespace = self::DEFAULT_NAMESPACE)
{
return isset($this->values[$namespace][$name]) ? $this->values[$namespace][$name] : null;
} | php | public function getValue($name, $namespace = self::DEFAULT_NAMESPACE)
{
return isset($this->values[$namespace][$name]) ? $this->values[$namespace][$name] : null;
} | [
"public",
"function",
"getValue",
"(",
"$",
"name",
",",
"$",
"namespace",
"=",
"self",
"::",
"DEFAULT_NAMESPACE",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"namespace",
"]",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this"... | Gets session value from given or default namespace
@param string $name
@param string $namespace
@return mixed | [
"Gets",
"session",
"value",
"from",
"given",
"or",
"default",
"namespace"
] | ed95c8128edd31cceb7c440bf9accea6d4a83ad3 | https://github.com/sobstel/sesshin/blob/ed95c8128edd31cceb7c440bf9accea6d4a83ad3/src/Session.php#L412-L415 | train |
sobstel/sesshin | src/Session.php | Session.load | protected function load()
{
$id = $this->getId();
$values = $this->getStore()->fetch($id);
if ($values === false) {
return false;
}
// metadata
$metadata = $values[self::METADATA_NAMESPACE];
$this->firstTrace = $metadata['firstTrace'];
$this->lastTrace = $metadata['lastTrace'];
$this->regenerationTrace = $metadata['regenerationTrace'];
$this->requestsCount = $metadata['requestsCount'];
$this->fingerprint = $metadata['fingerprint'];
// values
$this->values = $values;
return true;
} | php | protected function load()
{
$id = $this->getId();
$values = $this->getStore()->fetch($id);
if ($values === false) {
return false;
}
// metadata
$metadata = $values[self::METADATA_NAMESPACE];
$this->firstTrace = $metadata['firstTrace'];
$this->lastTrace = $metadata['lastTrace'];
$this->regenerationTrace = $metadata['regenerationTrace'];
$this->requestsCount = $metadata['requestsCount'];
$this->fingerprint = $metadata['fingerprint'];
// values
$this->values = $values;
return true;
} | [
"protected",
"function",
"load",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"getStore",
"(",
")",
"->",
"fetch",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"values",
"===",
... | Loads session data from defined store.
@return bool | [
"Loads",
"session",
"data",
"from",
"defined",
"store",
"."
] | ed95c8128edd31cceb7c440bf9accea6d4a83ad3 | https://github.com/sobstel/sesshin/blob/ed95c8128edd31cceb7c440bf9accea6d4a83ad3/src/Session.php#L514-L535 | train |
sobstel/sesshin | src/Session.php | Session.save | protected function save()
{
$this->flash()->ageFlashData();
$values = $this->values;
$values[self::METADATA_NAMESPACE] = [
'firstTrace' => $this->getFirstTrace(),
'lastTrace' => $this->getLastTrace(),
'regenerationTrace' => $this->getRegenerationTrace(),
'requestsCount' => $this->getRequestsCount(),
'fingerprint' => $this->getFingerprint(),
];
return $this->getStore()->save($this->getId(), $values, $this->ttl);
} | php | protected function save()
{
$this->flash()->ageFlashData();
$values = $this->values;
$values[self::METADATA_NAMESPACE] = [
'firstTrace' => $this->getFirstTrace(),
'lastTrace' => $this->getLastTrace(),
'regenerationTrace' => $this->getRegenerationTrace(),
'requestsCount' => $this->getRequestsCount(),
'fingerprint' => $this->getFingerprint(),
];
return $this->getStore()->save($this->getId(), $values, $this->ttl);
} | [
"protected",
"function",
"save",
"(",
")",
"{",
"$",
"this",
"->",
"flash",
"(",
")",
"->",
"ageFlashData",
"(",
")",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"values",
";",
"$",
"values",
"[",
"self",
"::",
"METADATA_NAMESPACE",
"]",
"=",
"[",
... | Saves session data into defined store.
@return bool | [
"Saves",
"session",
"data",
"into",
"defined",
"store",
"."
] | ed95c8128edd31cceb7c440bf9accea6d4a83ad3 | https://github.com/sobstel/sesshin/blob/ed95c8128edd31cceb7c440bf9accea6d4a83ad3/src/Session.php#L542-L557 | train |
sobstel/sesshin | src/Session.php | Session.push | public function push($key, $value)
{
$array = $this->getValue($key);
$array[] = $value;
$this->setValue($key, $array);
} | php | public function push($key, $value)
{
$array = $this->getValue($key);
$array[] = $value;
$this->setValue($key, $array);
} | [
"public",
"function",
"push",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"array",
"=",
"$",
"this",
"->",
"getValue",
"(",
"$",
"key",
")",
";",
"$",
"array",
"[",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"setValue",
"(",
"$",
... | Push a value onto a session array.
@param string $key
@param mixed $value
@return void | [
"Push",
"a",
"value",
"onto",
"a",
"session",
"array",
"."
] | ed95c8128edd31cceb7c440bf9accea6d4a83ad3 | https://github.com/sobstel/sesshin/blob/ed95c8128edd31cceb7c440bf9accea6d4a83ad3/src/Session.php#L585-L590 | train |
sobstel/sesshin | src/Session.php | Session.flash | public function flash()
{
if (is_null($this->flash)) {
$this->flash = new SessionFlash($this);
}
return $this->flash;
} | php | public function flash()
{
if (is_null($this->flash)) {
$this->flash = new SessionFlash($this);
}
return $this->flash;
} | [
"public",
"function",
"flash",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"flash",
")",
")",
"{",
"$",
"this",
"->",
"flash",
"=",
"new",
"SessionFlash",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
"->",
"flash",
";"... | Call the flash session handler.
@return SessionFlash | [
"Call",
"the",
"flash",
"session",
"handler",
"."
] | ed95c8128edd31cceb7c440bf9accea6d4a83ad3 | https://github.com/sobstel/sesshin/blob/ed95c8128edd31cceb7c440bf9accea6d4a83ad3/src/Session.php#L614-L621 | train |
sobstel/sesshin | src/SessionFlash.php | SessionFlash.getCurrentData | public function getCurrentData()
{
$current_data = $this->session->getValue($this->key_name);
return isset($current_data) ? $current_data : $current_data = array();
} | php | public function getCurrentData()
{
$current_data = $this->session->getValue($this->key_name);
return isset($current_data) ? $current_data : $current_data = array();
} | [
"public",
"function",
"getCurrentData",
"(",
")",
"{",
"$",
"current_data",
"=",
"$",
"this",
"->",
"session",
"->",
"getValue",
"(",
"$",
"this",
"->",
"key_name",
")",
";",
"return",
"isset",
"(",
"$",
"current_data",
")",
"?",
"$",
"current_data",
":"... | Get all the data or data of a type.
@return mixed | [
"Get",
"all",
"the",
"data",
"or",
"data",
"of",
"a",
"type",
"."
] | ed95c8128edd31cceb7c440bf9accea6d4a83ad3 | https://github.com/sobstel/sesshin/blob/ed95c8128edd31cceb7c440bf9accea6d4a83ad3/src/SessionFlash.php#L103-L108 | train |
sobstel/sesshin | src/SessionFlash.php | SessionFlash.reflash | public function reflash()
{
$this->mergeNewFlashes($this->session->getValue($this->key_name.'.old'));
$this->session->setValue($this->key_name.'.old', []);
} | php | public function reflash()
{
$this->mergeNewFlashes($this->session->getValue($this->key_name.'.old'));
$this->session->setValue($this->key_name.'.old', []);
} | [
"public",
"function",
"reflash",
"(",
")",
"{",
"$",
"this",
"->",
"mergeNewFlashes",
"(",
"$",
"this",
"->",
"session",
"->",
"getValue",
"(",
"$",
"this",
"->",
"key_name",
".",
"'.old'",
")",
")",
";",
"$",
"this",
"->",
"session",
"->",
"setValue",... | Reflash all of the session flash data.
@return void | [
"Reflash",
"all",
"of",
"the",
"session",
"flash",
"data",
"."
] | ed95c8128edd31cceb7c440bf9accea6d4a83ad3 | https://github.com/sobstel/sesshin/blob/ed95c8128edd31cceb7c440bf9accea6d4a83ad3/src/SessionFlash.php#L115-L119 | train |
sobstel/sesshin | src/SessionFlash.php | SessionFlash.removeFromOldFlashData | protected function removeFromOldFlashData(array $keys)
{
$old_data = $this->session->getValue($this->key_name.'.old');
if (! is_array($old_data)) {
$old_data = array();
}
$this->session->setValue($this->key_name.'.old', array_diff($old_data, $keys));
} | php | protected function removeFromOldFlashData(array $keys)
{
$old_data = $this->session->getValue($this->key_name.'.old');
if (! is_array($old_data)) {
$old_data = array();
}
$this->session->setValue($this->key_name.'.old', array_diff($old_data, $keys));
} | [
"protected",
"function",
"removeFromOldFlashData",
"(",
"array",
"$",
"keys",
")",
"{",
"$",
"old_data",
"=",
"$",
"this",
"->",
"session",
"->",
"getValue",
"(",
"$",
"this",
"->",
"key_name",
".",
"'.old'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
... | Remove the given keys from the old flash data.
@param array $keys
@return void | [
"Remove",
"the",
"given",
"keys",
"from",
"the",
"old",
"flash",
"data",
"."
] | ed95c8128edd31cceb7c440bf9accea6d4a83ad3 | https://github.com/sobstel/sesshin/blob/ed95c8128edd31cceb7c440bf9accea6d4a83ad3/src/SessionFlash.php#L153-L161 | train |
sobstel/sesshin | src/SessionFlash.php | SessionFlash.singleton | static function singleton(Session $session = null)
{
if (self::$singleton == null) {
self::$singleton = new SessionFlash($session);
}
return self::$singleton;
} | php | static function singleton(Session $session = null)
{
if (self::$singleton == null) {
self::$singleton = new SessionFlash($session);
}
return self::$singleton;
} | [
"static",
"function",
"singleton",
"(",
"Session",
"$",
"session",
"=",
"null",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"singleton",
"==",
"null",
")",
"{",
"self",
"::",
"$",
"singleton",
"=",
"new",
"SessionFlash",
"(",
"$",
"session",
")",
";",
"}... | Calling this class in a singleton way.
@param Session|null $session
@return SessionFlash | [
"Calling",
"this",
"class",
"in",
"a",
"singleton",
"way",
"."
] | ed95c8128edd31cceb7c440bf9accea6d4a83ad3 | https://github.com/sobstel/sesshin/blob/ed95c8128edd31cceb7c440bf9accea6d4a83ad3/src/SessionFlash.php#L196-L203 | train |
dailymotion/dailymotion-sdk-php | Dailymotion.php | Dailymotion.call | public function call($resource, $args = array())
{
$headers = array('Content-Type: application/json');
$payload = json_encode(array(
'call' => $resource,
'args' => $args,
));
$statusCode = null;
try
{
$result = json_decode(
$this->oauthRequest(
$this->apiEndpointUrl,
$payload,
$this->getAccessToken(),
$headers,
$statusCode
),
true
);
}
catch (DailymotionAuthException $e)
{
if ($e->error === 'invalid_token')
{
// Retry by forcing the refresh of the access token
$result = json_decode(
$this->oauthRequest(
$this->apiEndpointUrl,
$payload,
$this->getAccessToken(true),
$headers,
$statusCode
),
true
);
}
else
{
throw $e;
}
}
if (empty($result))
{
throw new DailymotionApiException('Invalid API server response');
}
elseif ($statusCode !== 200)
{
throw new DailymotionApiException("Unknown error: {$statusCode}", $statusCode);
}
elseif (is_array($result) && isset($result['error']))
{
$message = isset($result['error']['message']) ? $result['error']['message'] : null;
$code = isset($result['error']['code']) ? $result['error']['code'] : null;
if ($code === 403)
{
throw new DailymotionAuthRequiredException($message, $code);
}
else
{
throw new DailymotionApiException($message, $code);
}
}
elseif (!isset($result['result']))
{
throw new DailymotionApiException("Invalid API server response: no `result` key found.");
}
return $result['result'];
} | php | public function call($resource, $args = array())
{
$headers = array('Content-Type: application/json');
$payload = json_encode(array(
'call' => $resource,
'args' => $args,
));
$statusCode = null;
try
{
$result = json_decode(
$this->oauthRequest(
$this->apiEndpointUrl,
$payload,
$this->getAccessToken(),
$headers,
$statusCode
),
true
);
}
catch (DailymotionAuthException $e)
{
if ($e->error === 'invalid_token')
{
// Retry by forcing the refresh of the access token
$result = json_decode(
$this->oauthRequest(
$this->apiEndpointUrl,
$payload,
$this->getAccessToken(true),
$headers,
$statusCode
),
true
);
}
else
{
throw $e;
}
}
if (empty($result))
{
throw new DailymotionApiException('Invalid API server response');
}
elseif ($statusCode !== 200)
{
throw new DailymotionApiException("Unknown error: {$statusCode}", $statusCode);
}
elseif (is_array($result) && isset($result['error']))
{
$message = isset($result['error']['message']) ? $result['error']['message'] : null;
$code = isset($result['error']['code']) ? $result['error']['code'] : null;
if ($code === 403)
{
throw new DailymotionAuthRequiredException($message, $code);
}
else
{
throw new DailymotionApiException($message, $code);
}
}
elseif (!isset($result['result']))
{
throw new DailymotionApiException("Invalid API server response: no `result` key found.");
}
return $result['result'];
} | [
"public",
"function",
"call",
"(",
"$",
"resource",
",",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"$",
"headers",
"=",
"array",
"(",
"'Content-Type: application/json'",
")",
";",
"$",
"payload",
"=",
"json_encode",
"(",
"array",
"(",
"'call'",
"=>"... | Call a remote endpoint on the API.
@param string $resource API endpoint to call.
@param array $args Associative array of arguments.
@throws DailymotionApiException If the API itself returned an error.
@throws DailymotionAuthException If we can't authenticate the request.
@throws DailymotionAuthRequiredException If no authentication info is available.
@throws DailymotionTransportException If a network error occurs during the request.
@return mixed Endpoint call response | [
"Call",
"a",
"remote",
"endpoint",
"on",
"the",
"API",
"."
] | 0f558978785f9a6ab9e59c393041d4896550973b | https://github.com/dailymotion/dailymotion-sdk-php/blob/0f558978785f9a6ab9e59c393041d4896550973b/Dailymotion.php#L390-L459 | train |
dailymotion/dailymotion-sdk-php | Dailymotion.php | Dailymotion.getSession | public function getSession()
{
if (empty($this->session))
{
$this->session = $this->readSession();
}
return $this->session;
} | php | public function getSession()
{
if (empty($this->session))
{
$this->session = $this->readSession();
}
return $this->session;
} | [
"public",
"function",
"getSession",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"session",
")",
")",
"{",
"$",
"this",
"->",
"session",
"=",
"$",
"this",
"->",
"readSession",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"session"... | Get the session if any.
@return array Current session or an empty array if none found. | [
"Get",
"the",
"session",
"if",
"any",
"."
] | 0f558978785f9a6ab9e59c393041d4896550973b | https://github.com/dailymotion/dailymotion-sdk-php/blob/0f558978785f9a6ab9e59c393041d4896550973b/Dailymotion.php#L625-L632 | train |
dailymotion/dailymotion-sdk-php | Dailymotion.php | Dailymotion.readSession | protected function readSession()
{
$session = array();
$cookieName = sprintf(self::SESSION_COOKIE, $this->grantInfo['key']);
$cookieValue = filter_input(INPUT_COOKIE, $cookieName);
if (!empty($cookieValue))
{
parse_str(
trim((get_magic_quotes_gpc() ? stripslashes($cookieValue) : $cookieValue), '"'),
$session
);
}
return $session;
} | php | protected function readSession()
{
$session = array();
$cookieName = sprintf(self::SESSION_COOKIE, $this->grantInfo['key']);
$cookieValue = filter_input(INPUT_COOKIE, $cookieName);
if (!empty($cookieValue))
{
parse_str(
trim((get_magic_quotes_gpc() ? stripslashes($cookieValue) : $cookieValue), '"'),
$session
);
}
return $session;
} | [
"protected",
"function",
"readSession",
"(",
")",
"{",
"$",
"session",
"=",
"array",
"(",
")",
";",
"$",
"cookieName",
"=",
"sprintf",
"(",
"self",
"::",
"SESSION_COOKIE",
",",
"$",
"this",
"->",
"grantInfo",
"[",
"'key'",
"]",
")",
";",
"$",
"cookieVa... | Read the session from the session store.
Default storage is cookie, subclass can implement another storage type if needed.
Information stored in the session are useless without the API secret. Storing these information on the client
should thus be safe as long as the API secret is kept... secret.
@return array Stored session or an empty array if none found. | [
"Read",
"the",
"session",
"from",
"the",
"session",
"store",
".",
"Default",
"storage",
"is",
"cookie",
"subclass",
"can",
"implement",
"another",
"storage",
"type",
"if",
"needed",
".",
"Information",
"stored",
"in",
"the",
"session",
"are",
"useless",
"witho... | 0f558978785f9a6ab9e59c393041d4896550973b | https://github.com/dailymotion/dailymotion-sdk-php/blob/0f558978785f9a6ab9e59c393041d4896550973b/Dailymotion.php#L652-L666 | train |
dailymotion/dailymotion-sdk-php | Dailymotion.php | Dailymotion.storeSession | protected function storeSession(array $session = array())
{
if (headers_sent())
{
if (php_sapi_name() !== 'cli')
{
error_log('Could not set session in cookie: headers already sent.');
}
return $this;
}
$cookieName = sprintf(self::SESSION_COOKIE, $this->grantInfo['key']);
if (!empty($session))
{
$value = '"' . http_build_query($session, null, '&') . '"';
$expires = time() + $this->cookieLifeTime;
}
else
{
$cookieValue = filter_input(INPUT_COOKIE, $cookieName);
if (empty($cookieValue))
{
// No need to remove an unexisting cookie
return $this;
}
$value = 'deleted';
$expires = time() - 3600;
}
setcookie($cookieName, $value, $expires, '/', $this->cookieDomain);
return $this;
} | php | protected function storeSession(array $session = array())
{
if (headers_sent())
{
if (php_sapi_name() !== 'cli')
{
error_log('Could not set session in cookie: headers already sent.');
}
return $this;
}
$cookieName = sprintf(self::SESSION_COOKIE, $this->grantInfo['key']);
if (!empty($session))
{
$value = '"' . http_build_query($session, null, '&') . '"';
$expires = time() + $this->cookieLifeTime;
}
else
{
$cookieValue = filter_input(INPUT_COOKIE, $cookieName);
if (empty($cookieValue))
{
// No need to remove an unexisting cookie
return $this;
}
$value = 'deleted';
$expires = time() - 3600;
}
setcookie($cookieName, $value, $expires, '/', $this->cookieDomain);
return $this;
} | [
"protected",
"function",
"storeSession",
"(",
"array",
"$",
"session",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"headers_sent",
"(",
")",
")",
"{",
"if",
"(",
"php_sapi_name",
"(",
")",
"!==",
"'cli'",
")",
"{",
"error_log",
"(",
"'Could not set sess... | Store the given session to the session store.
Default storage is cookie, subclass can implement another storage type if needed.
Information stored in the session are useless without the API secret. Storing these information on the client
should thus be safe as long as the API secret is kept... secret.
@param array $session Session to store, if nothing is passed, the current session is removed from the session store.
@return Dailymotion `$this` | [
"Store",
"the",
"given",
"session",
"to",
"the",
"session",
"store",
".",
"Default",
"storage",
"is",
"cookie",
"subclass",
"can",
"implement",
"another",
"storage",
"type",
"if",
"needed",
".",
"Information",
"stored",
"in",
"the",
"session",
"are",
"useless"... | 0f558978785f9a6ab9e59c393041d4896550973b | https://github.com/dailymotion/dailymotion-sdk-php/blob/0f558978785f9a6ab9e59c393041d4896550973b/Dailymotion.php#L677-L706 | train |
dailymotion/dailymotion-sdk-php | Dailymotion.php | Dailymotion.oauthTokenRequest | protected function oauthTokenRequest(array $args)
{
$statusCode = null;
$responseHeaders = array();
$result = json_decode(
$response = $this->httpRequest(
$this->oauthTokenEndpointUrl,
$args,
null,
$statusCode,
$responseHeaders,
true
),
true
);
if (empty($result))
{
throw new DailymotionAuthException("Invalid token server response: {$response}");
}
elseif (isset($result['error']))
{
$message = isset($result['error_description']) ? $result['error_description'] : null;
$e = new DailymotionAuthException($message);
$e->error = $result['error'];
throw $e;
}
elseif (isset($result['access_token']))
{
return array(
'access_token' => $result['access_token'],
'expires' => time() + $result['expires_in'],
'refresh_token' => isset($result['refresh_token']) ? $result['refresh_token'] : null,
'scope' => isset($result['scope']) ? explode(chr(32), $result['scope']) : array(),
);
}
else
{
throw new DailymotionAuthException('No access token found in the token server response');
}
} | php | protected function oauthTokenRequest(array $args)
{
$statusCode = null;
$responseHeaders = array();
$result = json_decode(
$response = $this->httpRequest(
$this->oauthTokenEndpointUrl,
$args,
null,
$statusCode,
$responseHeaders,
true
),
true
);
if (empty($result))
{
throw new DailymotionAuthException("Invalid token server response: {$response}");
}
elseif (isset($result['error']))
{
$message = isset($result['error_description']) ? $result['error_description'] : null;
$e = new DailymotionAuthException($message);
$e->error = $result['error'];
throw $e;
}
elseif (isset($result['access_token']))
{
return array(
'access_token' => $result['access_token'],
'expires' => time() + $result['expires_in'],
'refresh_token' => isset($result['refresh_token']) ? $result['refresh_token'] : null,
'scope' => isset($result['scope']) ? explode(chr(32), $result['scope']) : array(),
);
}
else
{
throw new DailymotionAuthException('No access token found in the token server response');
}
} | [
"protected",
"function",
"oauthTokenRequest",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"statusCode",
"=",
"null",
";",
"$",
"responseHeaders",
"=",
"array",
"(",
")",
";",
"$",
"result",
"=",
"json_decode",
"(",
"$",
"response",
"=",
"$",
"this",
"->",
... | Perform a request to a token server complient with the OAuth 2.0 specification.
@param array $args Arguments to send to the token server.
@throws DailymotionAuthException If the token server sends an error or invalid response.
@return array Cconfigured session. | [
"Perform",
"a",
"request",
"to",
"a",
"token",
"server",
"complient",
"with",
"the",
"OAuth",
"2",
".",
"0",
"specification",
"."
] | 0f558978785f9a6ab9e59c393041d4896550973b | https://github.com/dailymotion/dailymotion-sdk-php/blob/0f558978785f9a6ab9e59c393041d4896550973b/Dailymotion.php#L715-L754 | train |
dailymotion/dailymotion-sdk-php | Dailymotion.php | Dailymotion.oauthRequest | protected function oauthRequest($url, $payload, $accessToken = null, $headers = array(), &$statusCode = null, &$responseHeaders = array())
{
if ($accessToken !== null)
{
$headers[] = "Authorization: Bearer {$accessToken}";
}
$result = $this->httpRequest(
$url,
$payload,
$headers,
$statusCode,
$responseHeaders
);
switch ($statusCode)
{
case 401: // Invalid or expired token
case 400: // Invalid request
case 403: // Insufficient scope
$error = null;
$message = null;
$match = array();
if (preg_match('/error="(.*?)"(?:, error_description="(.*?)")?/', $responseHeaders['www-authenticate'], $match))
{
$error = $match[1];
$message = $match[2];
}
$e = new DailymotionAuthException($message);
$e->error = $error;
throw $e;
}
return $result;
} | php | protected function oauthRequest($url, $payload, $accessToken = null, $headers = array(), &$statusCode = null, &$responseHeaders = array())
{
if ($accessToken !== null)
{
$headers[] = "Authorization: Bearer {$accessToken}";
}
$result = $this->httpRequest(
$url,
$payload,
$headers,
$statusCode,
$responseHeaders
);
switch ($statusCode)
{
case 401: // Invalid or expired token
case 400: // Invalid request
case 403: // Insufficient scope
$error = null;
$message = null;
$match = array();
if (preg_match('/error="(.*?)"(?:, error_description="(.*?)")?/', $responseHeaders['www-authenticate'], $match))
{
$error = $match[1];
$message = $match[2];
}
$e = new DailymotionAuthException($message);
$e->error = $error;
throw $e;
}
return $result;
} | [
"protected",
"function",
"oauthRequest",
"(",
"$",
"url",
",",
"$",
"payload",
",",
"$",
"accessToken",
"=",
"null",
",",
"$",
"headers",
"=",
"array",
"(",
")",
",",
"&",
"$",
"statusCode",
"=",
"null",
",",
"&",
"$",
"responseHeaders",
"=",
"array",
... | Perform an OAuth 2.0 authenticated request.
@param string $url the URL to perform the HTTP request to.
@param string $payload Encoded method request to POST.
@param string $accessToken OAuth access token to authenticate the request with.
@param array $headers List of headers to send with the request (format `array('Header-Name: header value')`).
@param int &$statusCode Reference variable to store the response status code.
@param array &$responseHeaders Reference variable to store the response headers.
@throws DailymotionAuthException If an OAuth error occurs.
@throws DailymotionTransportException If a network error occurs during the request.
@return string Response body. | [
"Perform",
"an",
"OAuth",
"2",
".",
"0",
"authenticated",
"request",
"."
] | 0f558978785f9a6ab9e59c393041d4896550973b | https://github.com/dailymotion/dailymotion-sdk-php/blob/0f558978785f9a6ab9e59c393041d4896550973b/Dailymotion.php#L771-L803 | train |
dailymotion/dailymotion-sdk-php | Dailymotion.php | Dailymotion.httpRequest | protected function httpRequest($url, $payload, $headers = null, &$statusCode = null, &$responseHeaders = array(), $encodePayload = false)
{
$payload = (is_array($payload) && (true === $encodePayload))
? http_build_query($payload, null, '&')
: $payload;
// Force removal of the Expect: 100-continue header automatically added by cURL
$headers[] = 'Expect:';
// cURL options
$options = array(
CURLOPT_CONNECTTIMEOUT => $this->connectionTimeout,
CURLOPT_TIMEOUT => $this->timeout,
CURLOPT_PROXY => $this->proxy,
CURLOPT_PROXYUSERPWD => $this->proxyCredentials,
CURLOPT_USERAGENT => sprintf('Dailymotion-PHP/%s (PHP %s; %s)', self::VERSION, PHP_VERSION, php_sapi_name()),
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_NOPROGRESS => !($this->debug && is_array($payload) && array_key_exists('file', $payload)),
);
// There is no constructor to this class and I don't intend to add one just for this (PHP 4 legacy and all).
if (is_null($this->followRedirects))
{
// We use filter_var() here because depending on PHP's version, these ini_get() may or may not return:
// true/false or even the strings 'on', 'off', 'true' or 'false' or folder paths... better safe than sorry.
$this->followRedirects =
(false === filter_var(ini_get('open_basedir'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE))
&& (false === filter_var(ini_get('safe_mode'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
}
// If the current server supports it, we follow redirects
if ($this->followRedirects === true)
{
$options[CURLOPT_FOLLOWLOCATION] = true;
$options[CURLOPT_MAXREDIRS] = self::CURLOPT_MAXREDIRS;
}
$this->debugRequest($url, $payload, $headers);
// Execute the cURL request
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
// CURLE_SSL_CACERT error
if (curl_errno($ch) == 60)
{
error_log('Invalid or no certificate authority found, using bundled information');
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/dm_ca_chain_bundle.crt');
$response = curl_exec($ch);
}
// Invalid empty response
if ($response === false)
{
$e = new DailymotionTransportException(curl_error($ch), curl_errno($ch));
curl_close($ch);
throw $e;
}
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
list($responseHeadersString, $payload) = explode("\r\n\r\n", $response, 2);
strtok($responseHeadersString, "\r\n"); // skip status code
while(($name = trim(strtok(":"))) && ($value = trim(strtok("\r\n"))))
{
$responseHeaders[strtolower($name)] = (isset($responseHeaders[$name])
? $responseHeaders[$name] . '; '
: null) . $value;
}
$this->debugResponse($url, $payload, $responseHeaders);
return $payload;
} | php | protected function httpRequest($url, $payload, $headers = null, &$statusCode = null, &$responseHeaders = array(), $encodePayload = false)
{
$payload = (is_array($payload) && (true === $encodePayload))
? http_build_query($payload, null, '&')
: $payload;
// Force removal of the Expect: 100-continue header automatically added by cURL
$headers[] = 'Expect:';
// cURL options
$options = array(
CURLOPT_CONNECTTIMEOUT => $this->connectionTimeout,
CURLOPT_TIMEOUT => $this->timeout,
CURLOPT_PROXY => $this->proxy,
CURLOPT_PROXYUSERPWD => $this->proxyCredentials,
CURLOPT_USERAGENT => sprintf('Dailymotion-PHP/%s (PHP %s; %s)', self::VERSION, PHP_VERSION, php_sapi_name()),
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_NOPROGRESS => !($this->debug && is_array($payload) && array_key_exists('file', $payload)),
);
// There is no constructor to this class and I don't intend to add one just for this (PHP 4 legacy and all).
if (is_null($this->followRedirects))
{
// We use filter_var() here because depending on PHP's version, these ini_get() may or may not return:
// true/false or even the strings 'on', 'off', 'true' or 'false' or folder paths... better safe than sorry.
$this->followRedirects =
(false === filter_var(ini_get('open_basedir'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE))
&& (false === filter_var(ini_get('safe_mode'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
}
// If the current server supports it, we follow redirects
if ($this->followRedirects === true)
{
$options[CURLOPT_FOLLOWLOCATION] = true;
$options[CURLOPT_MAXREDIRS] = self::CURLOPT_MAXREDIRS;
}
$this->debugRequest($url, $payload, $headers);
// Execute the cURL request
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
// CURLE_SSL_CACERT error
if (curl_errno($ch) == 60)
{
error_log('Invalid or no certificate authority found, using bundled information');
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/dm_ca_chain_bundle.crt');
$response = curl_exec($ch);
}
// Invalid empty response
if ($response === false)
{
$e = new DailymotionTransportException(curl_error($ch), curl_errno($ch));
curl_close($ch);
throw $e;
}
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
list($responseHeadersString, $payload) = explode("\r\n\r\n", $response, 2);
strtok($responseHeadersString, "\r\n"); // skip status code
while(($name = trim(strtok(":"))) && ($value = trim(strtok("\r\n"))))
{
$responseHeaders[strtolower($name)] = (isset($responseHeaders[$name])
? $responseHeaders[$name] . '; '
: null) . $value;
}
$this->debugResponse($url, $payload, $responseHeaders);
return $payload;
} | [
"protected",
"function",
"httpRequest",
"(",
"$",
"url",
",",
"$",
"payload",
",",
"$",
"headers",
"=",
"null",
",",
"&",
"$",
"statusCode",
"=",
"null",
",",
"&",
"$",
"responseHeaders",
"=",
"array",
"(",
")",
",",
"$",
"encodePayload",
"=",
"false",... | Perform an HTTP request by posting the given payload and returning the result.
Override this method if you don't want to use cURL.
@param string $url URL to perform the HTTP request to.
@param mixed $payload Data to POST. If it's an associative array and `$encodePayload` is set to true,
it will be url-encoded and the `Content-Type` header will automatically be set
to `multipart/form-data`. If it's a string make sure you set the correct
`Content-Type` header yourself.
@param array $headers List of headers to send with the request (format `array('Header-Name: header value')`).
@param int &$statusCode Reference variable to store the response status code.
@param array &$responseHeaders Reference variable to store the response headers.
@param boolean $encodePayload Whether or not to encode the payload if it's an associative array.
@throws DailymotionTransportException If a network error occurs during the request.
@return string Response body | [
"Perform",
"an",
"HTTP",
"request",
"by",
"posting",
"the",
"given",
"payload",
"and",
"returning",
"the",
"result",
".",
"Override",
"this",
"method",
"if",
"you",
"don",
"t",
"want",
"to",
"use",
"cURL",
"."
] | 0f558978785f9a6ab9e59c393041d4896550973b | https://github.com/dailymotion/dailymotion-sdk-php/blob/0f558978785f9a6ab9e59c393041d4896550973b/Dailymotion.php#L822-L895 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.