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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
thephpleague/container | src/Definition/Definition.php | Definition.resolveCallable | protected function resolveCallable(callable $concrete)
{
$resolved = $this->resolveArguments($this->arguments);
return call_user_func_array($concrete, $resolved);
} | php | protected function resolveCallable(callable $concrete)
{
$resolved = $this->resolveArguments($this->arguments);
return call_user_func_array($concrete, $resolved);
} | [
"protected",
"function",
"resolveCallable",
"(",
"callable",
"$",
"concrete",
")",
"{",
"$",
"resolved",
"=",
"$",
"this",
"->",
"resolveArguments",
"(",
"$",
"this",
"->",
"arguments",
")",
";",
"return",
"call_user_func_array",
"(",
"$",
"concrete",
",",
"... | Resolve a callable.
@param callable $concrete
@return mixed | [
"Resolve",
"a",
"callable",
"."
] | 087e9a98876efee4db878c8fd72e04c228cb8aa9 | https://github.com/thephpleague/container/blob/087e9a98876efee4db878c8fd72e04c228cb8aa9/src/Definition/Definition.php#L229-L234 | train |
thephpleague/container | src/Definition/Definition.php | Definition.invokeMethods | protected function invokeMethods($instance)
{
foreach ($this->methods as $method) {
$args = $this->resolveArguments($method['arguments']);
call_user_func_array([$instance, $method['method']], $args);
}
return $instance;
} | php | protected function invokeMethods($instance)
{
foreach ($this->methods as $method) {
$args = $this->resolveArguments($method['arguments']);
call_user_func_array([$instance, $method['method']], $args);
}
return $instance;
} | [
"protected",
"function",
"invokeMethods",
"(",
"$",
"instance",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"methods",
"as",
"$",
"method",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"resolveArguments",
"(",
"$",
"method",
"[",
"'arguments'",
"]",
... | Invoke methods on resolved instance.
@param object $instance
@return object | [
"Invoke",
"methods",
"on",
"resolved",
"instance",
"."
] | 087e9a98876efee4db878c8fd72e04c228cb8aa9 | https://github.com/thephpleague/container/blob/087e9a98876efee4db878c8fd72e04c228cb8aa9/src/Definition/Definition.php#L258-L266 | train |
thephpleague/container | src/Container.php | Container.share | public function share(string $id, $concrete = null) : DefinitionInterface
{
return $this->add($id, $concrete, true);
} | php | public function share(string $id, $concrete = null) : DefinitionInterface
{
return $this->add($id, $concrete, true);
} | [
"public",
"function",
"share",
"(",
"string",
"$",
"id",
",",
"$",
"concrete",
"=",
"null",
")",
":",
"DefinitionInterface",
"{",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"id",
",",
"$",
"concrete",
",",
"true",
")",
";",
"}"
] | Proxy to add with shared as true.
@param string $id
@param mixed $concrete
@return \League\Container\Definition\DefinitionInterface | [
"Proxy",
"to",
"add",
"with",
"shared",
"as",
"true",
"."
] | 087e9a98876efee4db878c8fd72e04c228cb8aa9 | https://github.com/thephpleague/container/blob/087e9a98876efee4db878c8fd72e04c228cb8aa9/src/Container.php#L92-L95 | train |
thephpleague/container | src/Container.php | Container.extend | public function extend(string $id) : DefinitionInterface
{
if ($this->providers->provides($id)) {
$this->providers->register($id);
}
if ($this->definitions->has($id)) {
return $this->definitions->getDefinition($id);
}
throw new NotFoundException(
sprintf('Unable to extend alias (%s) as it is not being managed as a definition', $id)
);
} | php | public function extend(string $id) : DefinitionInterface
{
if ($this->providers->provides($id)) {
$this->providers->register($id);
}
if ($this->definitions->has($id)) {
return $this->definitions->getDefinition($id);
}
throw new NotFoundException(
sprintf('Unable to extend alias (%s) as it is not being managed as a definition', $id)
);
} | [
"public",
"function",
"extend",
"(",
"string",
"$",
"id",
")",
":",
"DefinitionInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"providers",
"->",
"provides",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"providers",
"->",
"register",
"(",
"$",
"i... | Get a definition to extend.
@param string $id [description]
@return \League\Container\Definition\DefinitionInterface | [
"Get",
"a",
"definition",
"to",
"extend",
"."
] | 087e9a98876efee4db878c8fd72e04c228cb8aa9 | https://github.com/thephpleague/container/blob/087e9a98876efee4db878c8fd72e04c228cb8aa9/src/Container.php#L118-L131 | train |
thephpleague/container | src/Container.php | Container.inflector | public function inflector(string $type, callable $callback = null) : InflectorInterface
{
return $this->inflectors->add($type, $callback);
} | php | public function inflector(string $type, callable $callback = null) : InflectorInterface
{
return $this->inflectors->add($type, $callback);
} | [
"public",
"function",
"inflector",
"(",
"string",
"$",
"type",
",",
"callable",
"$",
"callback",
"=",
"null",
")",
":",
"InflectorInterface",
"{",
"return",
"$",
"this",
"->",
"inflectors",
"->",
"add",
"(",
"$",
"type",
",",
"$",
"callback",
")",
";",
... | Allows for manipulation of specific types on resolution.
@param string $type
@param callable|null $callback
@return \League\Container\Inflector\InflectorInterface | [
"Allows",
"for",
"manipulation",
"of",
"specific",
"types",
"on",
"resolution",
"."
] | 087e9a98876efee4db878c8fd72e04c228cb8aa9 | https://github.com/thephpleague/container/blob/087e9a98876efee4db878c8fd72e04c228cb8aa9/src/Container.php#L216-L219 | train |
wimverstuyf/php-coda-parser | src/LinesParser.php | LinesParser.fileToCodaLines | private function fileToCodaLines(string $codaFile): array
{
return array_map(
function($line) {
return mb_convert_encoding($line, "UTF-8", "ISO-8859-1");
},
file($codaFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
} | php | private function fileToCodaLines(string $codaFile): array
{
return array_map(
function($line) {
return mb_convert_encoding($line, "UTF-8", "ISO-8859-1");
},
file($codaFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
} | [
"private",
"function",
"fileToCodaLines",
"(",
"string",
"$",
"codaFile",
")",
":",
"array",
"{",
"return",
"array_map",
"(",
"function",
"(",
"$",
"line",
")",
"{",
"return",
"mb_convert_encoding",
"(",
"$",
"line",
",",
"\"UTF-8\"",
",",
"\"ISO-8859-1\"",
... | Read contents from file and put every line as an entry in the result array
@param string $codaFile Filepath
@return string[] | [
"Read",
"contents",
"from",
"file",
"and",
"put",
"every",
"line",
"as",
"an",
"entry",
"in",
"the",
"result",
"array"
] | 7f19560542478f8a99a021638ee35a98bb4ff32e | https://github.com/wimverstuyf/php-coda-parser/blob/7f19560542478f8a99a021638ee35a98bb4ff32e/src/LinesParser.php#L93-L100 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader.php | ClassLoader.setClass | protected function setClass()
{
if (!isset($this->rawOptions['class'])) {
$this->rawOptions['class'] = static::DEFAULT_CLASS;
}
$this->class = $this->rawOptions['class'];
unset($this->rawOptions['class']);
} | php | protected function setClass()
{
if (!isset($this->rawOptions['class'])) {
$this->rawOptions['class'] = static::DEFAULT_CLASS;
}
$this->class = $this->rawOptions['class'];
unset($this->rawOptions['class']);
} | [
"protected",
"function",
"setClass",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"rawOptions",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"rawOptions",
"[",
"'class'",
"]",
"=",
"static",
"::",
"DEFAULT_CLASS",
";",
"}... | Set the class you want to load from the raw option array | [
"Set",
"the",
"class",
"you",
"want",
"to",
"load",
"from",
"the",
"raw",
"option",
"array"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader.php#L90-L98 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader.php | ClassLoader.loadChildClasses | protected function loadChildClasses()
{
foreach ($this->rawOptions as &$option) {
if (is_array($option)
&& array_key_exists('class', $option)
&& class_exists($option['class'])
) {
$classLoader = new ClassLoader($option);
$option = $classLoader->load();
}
}
} | php | protected function loadChildClasses()
{
foreach ($this->rawOptions as &$option) {
if (is_array($option)
&& array_key_exists('class', $option)
&& class_exists($option['class'])
) {
$classLoader = new ClassLoader($option);
$option = $classLoader->load();
}
}
} | [
"protected",
"function",
"loadChildClasses",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"rawOptions",
"as",
"&",
"$",
"option",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"option",
")",
"&&",
"array_key_exists",
"(",
"'class'",
",",
"$",
"option",... | Recursively loads objects into any of the rawOptions that represent
a class | [
"Recursively",
"loads",
"objects",
"into",
"any",
"of",
"the",
"rawOptions",
"that",
"represent",
"a",
"class"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader.php#L104-L115 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader.php | ClassLoader.optionsToCamelCase | public static function optionsToCamelCase(array $options)
{
$optionsByName = array();
if (count($options)) {
foreach ($options as $name => $value) {
$optionsByName[Util::snakeToCamelCase($name)] = $value;
}
}
return $optionsByName;
} | php | public static function optionsToCamelCase(array $options)
{
$optionsByName = array();
if (count($options)) {
foreach ($options as $name => $value) {
$optionsByName[Util::snakeToCamelCase($name)] = $value;
}
}
return $optionsByName;
} | [
"public",
"static",
"function",
"optionsToCamelCase",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"optionsByName",
"=",
"array",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"options",
")",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"name",
... | Return option values indexed by name using camelCased keys
@param array $options Array of options
@return mixed[] Array of options indexed by (camelCased) name | [
"Return",
"option",
"values",
"indexed",
"by",
"name",
"using",
"camelCased",
"keys"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader.php#L124-L135 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader.php | ClassLoader.load | public function load()
{
$this->loadChildClasses();
list($constructorResolvedOptions, $extraResolvedOptions) = $this->resolveOptions();
$instance = $this->reflected->newInstanceArgs($constructorResolvedOptions);
$this->loadExtraOptions($extraResolvedOptions, $instance);
return $instance;
} | php | public function load()
{
$this->loadChildClasses();
list($constructorResolvedOptions, $extraResolvedOptions) = $this->resolveOptions();
$instance = $this->reflected->newInstanceArgs($constructorResolvedOptions);
$this->loadExtraOptions($extraResolvedOptions, $instance);
return $instance;
} | [
"public",
"function",
"load",
"(",
")",
"{",
"$",
"this",
"->",
"loadChildClasses",
"(",
")",
";",
"list",
"(",
"$",
"constructorResolvedOptions",
",",
"$",
"extraResolvedOptions",
")",
"=",
"$",
"this",
"->",
"resolveOptions",
"(",
")",
";",
"$",
"instanc... | Instantiate the reflected object using the parsed contructor args and set
extra options if any
@return mixed Instance of the reflected object | [
"Instantiate",
"the",
"reflected",
"object",
"using",
"the",
"parsed",
"contructor",
"args",
"and",
"set",
"extra",
"options",
"if",
"any"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader.php#L179-L189 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader.php | ClassLoader.canHandle | public function canHandle($extraOptionName)
{
return
isset(self::$extraOptionHandlers['*'][$extraOptionName]) ||
isset(self::$extraOptionHandlers[$this->class][$extraOptionName]);
} | php | public function canHandle($extraOptionName)
{
return
isset(self::$extraOptionHandlers['*'][$extraOptionName]) ||
isset(self::$extraOptionHandlers[$this->class][$extraOptionName]);
} | [
"public",
"function",
"canHandle",
"(",
"$",
"extraOptionName",
")",
"{",
"return",
"isset",
"(",
"self",
"::",
"$",
"extraOptionHandlers",
"[",
"'*'",
"]",
"[",
"$",
"extraOptionName",
"]",
")",
"||",
"isset",
"(",
"self",
"::",
"$",
"extraOptionHandlers",
... | Indicates whether or not an option is supported by the loader
@param string $extraOptionName Option name
@return boolean Whether or not an option is supported by the loader | [
"Indicates",
"whether",
"or",
"not",
"an",
"option",
"is",
"supported",
"by",
"the",
"loader"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader.php#L198-L203 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader.php | ClassLoader.getExtraOptionsHandler | public function getExtraOptionsHandler($extraOptionName)
{
// Check extraOption handlers that are valid for all classes
if (isset(self::$extraOptionHandlers['*'][$extraOptionName])) {
return self::$extraOptionHandlers['*'][$extraOptionName];
}
// Check extraOption handlers that are valid for the given class
if (isset(self::$extraOptionHandlers[$this->class][$extraOptionName])) {
return self::$extraOptionHandlers[$this->class][$extraOptionName];
}
return null;
} | php | public function getExtraOptionsHandler($extraOptionName)
{
// Check extraOption handlers that are valid for all classes
if (isset(self::$extraOptionHandlers['*'][$extraOptionName])) {
return self::$extraOptionHandlers['*'][$extraOptionName];
}
// Check extraOption handlers that are valid for the given class
if (isset(self::$extraOptionHandlers[$this->class][$extraOptionName])) {
return self::$extraOptionHandlers[$this->class][$extraOptionName];
}
return null;
} | [
"public",
"function",
"getExtraOptionsHandler",
"(",
"$",
"extraOptionName",
")",
"{",
"// Check extraOption handlers that are valid for all classes",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"extraOptionHandlers",
"[",
"'*'",
"]",
"[",
"$",
"extraOptionName",
"]",
... | Get the corresponding handler for a given option
@param string $extraOptionName Option name
@return \Closure|null Corresponding Closure object or null if not found | [
"Get",
"the",
"corresponding",
"handler",
"for",
"a",
"given",
"option"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader.php#L212-L225 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader.php | ClassLoader.loadExtraOptions | public function loadExtraOptions($extraOptions, $instance)
{
foreach ($extraOptions as $name => $value) {
if ($this->reflected->hasMethod($name)) {
// There is a method to handle this option
call_user_func_array(
array($instance, $name),
is_array($value) ? $value : array($value)
);
continue;
}
if ($this->reflected->hasProperty($name) &&
$this->reflected->getProperty($name)->isPublic()
) {
// There is a public member we can set for this option
$instance->$name = $value;
continue;
}
if ($this->canHandle($name)) {
// There is a custom handler for that option
$closure = $this->getExtraOptionsHandler($name);
$closure($instance, $value);
}
}
} | php | public function loadExtraOptions($extraOptions, $instance)
{
foreach ($extraOptions as $name => $value) {
if ($this->reflected->hasMethod($name)) {
// There is a method to handle this option
call_user_func_array(
array($instance, $name),
is_array($value) ? $value : array($value)
);
continue;
}
if ($this->reflected->hasProperty($name) &&
$this->reflected->getProperty($name)->isPublic()
) {
// There is a public member we can set for this option
$instance->$name = $value;
continue;
}
if ($this->canHandle($name)) {
// There is a custom handler for that option
$closure = $this->getExtraOptionsHandler($name);
$closure($instance, $value);
}
}
} | [
"public",
"function",
"loadExtraOptions",
"(",
"$",
"extraOptions",
",",
"$",
"instance",
")",
"{",
"foreach",
"(",
"$",
"extraOptions",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"reflected",
"->",
"hasMethod",
"(",
... | Set extra options if any were requested
@param array $extraOptions Array of extra options (key => value)
@param mixed $instance Instance you want to set options for | [
"Set",
"extra",
"options",
"if",
"any",
"were",
"requested"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader.php#L233-L258 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader/LoggerLoader.php | LoggerLoader.addHandlers | private function addHandlers(array $handlers)
{
// We need to reverse the array because Monolog "pushes" handlers to top of the stack
foreach (array_reverse($handlers) as $handler) {
$this->logger->pushHandler($handler);
}
} | php | private function addHandlers(array $handlers)
{
// We need to reverse the array because Monolog "pushes" handlers to top of the stack
foreach (array_reverse($handlers) as $handler) {
$this->logger->pushHandler($handler);
}
} | [
"private",
"function",
"addHandlers",
"(",
"array",
"$",
"handlers",
")",
"{",
"// We need to reverse the array because Monolog \"pushes\" handlers to top of the stack",
"foreach",
"(",
"array_reverse",
"(",
"$",
"handlers",
")",
"as",
"$",
"handler",
")",
"{",
"$",
"th... | Add handlers to the Logger
@param Monolog\Handler\HandlerInterface[] Array of Monolog handlers | [
"Add",
"handlers",
"to",
"the",
"Logger"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader/LoggerLoader.php#L152-L158 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader/LoggerLoader.php | LoggerLoader.addProcessors | private function addProcessors(array $processors)
{
// We need to reverse the array because Monolog "pushes" processors to top of the stack
foreach (array_reverse($processors) as $processor) {
$this->logger->pushProcessor($processor);
}
} | php | private function addProcessors(array $processors)
{
// We need to reverse the array because Monolog "pushes" processors to top of the stack
foreach (array_reverse($processors) as $processor) {
$this->logger->pushProcessor($processor);
}
} | [
"private",
"function",
"addProcessors",
"(",
"array",
"$",
"processors",
")",
"{",
"// We need to reverse the array because Monolog \"pushes\" processors to top of the stack",
"foreach",
"(",
"array_reverse",
"(",
"$",
"processors",
")",
"as",
"$",
"processor",
")",
"{",
... | Add processors to the Logger
@param callable[] Array of Monolog processors | [
"Add",
"processors",
"to",
"the",
"Logger"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader/LoggerLoader.php#L165-L171 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader/LoggerLoader.php | LoggerLoader.load | public function load()
{
$this->addHandlers($this->resolveHandlers($this->loggerOptions, $this->handlers));
$this->addProcessors($this->resolveProcessors($this->loggerOptions, $this->processors));
return $this->logger;
} | php | public function load()
{
$this->addHandlers($this->resolveHandlers($this->loggerOptions, $this->handlers));
$this->addProcessors($this->resolveProcessors($this->loggerOptions, $this->processors));
return $this->logger;
} | [
"public",
"function",
"load",
"(",
")",
"{",
"$",
"this",
"->",
"addHandlers",
"(",
"$",
"this",
"->",
"resolveHandlers",
"(",
"$",
"this",
"->",
"loggerOptions",
",",
"$",
"this",
"->",
"handlers",
")",
")",
";",
"$",
"this",
"->",
"addProcessors",
"(... | Return the instantiated Logger object based on its name
@return Monolog\Logger Logger object | [
"Return",
"the",
"instantiated",
"Logger",
"object",
"based",
"on",
"its",
"name"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader/LoggerLoader.php#L178-L184 | train |
theorchard/monolog-cascade | src/Config.php | Config.configureFormatters | protected function configureFormatters(array $formatters = array())
{
foreach ($formatters as $formatterId => $formatterOptions) {
$formatterLoader = new FormatterLoader($formatterOptions);
$this->formatters[$formatterId] = $formatterLoader->load();
}
} | php | protected function configureFormatters(array $formatters = array())
{
foreach ($formatters as $formatterId => $formatterOptions) {
$formatterLoader = new FormatterLoader($formatterOptions);
$this->formatters[$formatterId] = $formatterLoader->load();
}
} | [
"protected",
"function",
"configureFormatters",
"(",
"array",
"$",
"formatters",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"formatters",
"as",
"$",
"formatterId",
"=>",
"$",
"formatterOptions",
")",
"{",
"$",
"formatterLoader",
"=",
"new",
"Form... | Configure the formatters
@param array $formatters Array of formatter options | [
"Configure",
"the",
"formatters"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config.php#L131-L137 | train |
theorchard/monolog-cascade | src/Config.php | Config.configureHandlers | protected function configureHandlers(array $handlers)
{
foreach ($handlers as $handlerId => $handlerOptions) {
$handlerLoader = new HandlerLoader($handlerOptions, $this->formatters, $this->processors, $this->handlers);
$this->handlers[$handlerId] = $handlerLoader->load();
}
} | php | protected function configureHandlers(array $handlers)
{
foreach ($handlers as $handlerId => $handlerOptions) {
$handlerLoader = new HandlerLoader($handlerOptions, $this->formatters, $this->processors, $this->handlers);
$this->handlers[$handlerId] = $handlerLoader->load();
}
} | [
"protected",
"function",
"configureHandlers",
"(",
"array",
"$",
"handlers",
")",
"{",
"foreach",
"(",
"$",
"handlers",
"as",
"$",
"handlerId",
"=>",
"$",
"handlerOptions",
")",
"{",
"$",
"handlerLoader",
"=",
"new",
"HandlerLoader",
"(",
"$",
"handlerOptions"... | Configure the handlers
@param array $handlers Array of handler options | [
"Configure",
"the",
"handlers"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config.php#L144-L150 | train |
theorchard/monolog-cascade | src/Config.php | Config.configureProcessors | protected function configureProcessors(array $processors)
{
foreach ($processors as $processorName => $processorOptions) {
$processorLoader = new ProcessorLoader($processorOptions, $this->processors);
$this->processors[$processorName] = $processorLoader->load();
}
} | php | protected function configureProcessors(array $processors)
{
foreach ($processors as $processorName => $processorOptions) {
$processorLoader = new ProcessorLoader($processorOptions, $this->processors);
$this->processors[$processorName] = $processorLoader->load();
}
} | [
"protected",
"function",
"configureProcessors",
"(",
"array",
"$",
"processors",
")",
"{",
"foreach",
"(",
"$",
"processors",
"as",
"$",
"processorName",
"=>",
"$",
"processorOptions",
")",
"{",
"$",
"processorLoader",
"=",
"new",
"ProcessorLoader",
"(",
"$",
... | Configure the processors
@param array $processors Array of processor options | [
"Configure",
"the",
"processors"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config.php#L157-L163 | train |
theorchard/monolog-cascade | src/Config.php | Config.configureLoggers | protected function configureLoggers(array $loggers)
{
foreach ($loggers as $loggerName => $loggerOptions) {
$loggerLoader = new LoggerLoader($loggerName, $loggerOptions, $this->handlers, $this->processors);
$this->loggers[$loggerName] = $loggerLoader->load();
}
} | php | protected function configureLoggers(array $loggers)
{
foreach ($loggers as $loggerName => $loggerOptions) {
$loggerLoader = new LoggerLoader($loggerName, $loggerOptions, $this->handlers, $this->processors);
$this->loggers[$loggerName] = $loggerLoader->load();
}
} | [
"protected",
"function",
"configureLoggers",
"(",
"array",
"$",
"loggers",
")",
"{",
"foreach",
"(",
"$",
"loggers",
"as",
"$",
"loggerName",
"=>",
"$",
"loggerOptions",
")",
"{",
"$",
"loggerLoader",
"=",
"new",
"LoggerLoader",
"(",
"$",
"loggerName",
",",
... | Configure the loggers
@param array $loggers Array of logger options | [
"Configure",
"the",
"loggers"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config.php#L170-L176 | train |
theorchard/monolog-cascade | src/Config/Loader/FileLoader/PhpArray.php | PhpArray.load | public function load($resource, $type = null)
{
$config = include $resource;
if (!is_array($config)) {
throw new \InvalidArgumentException(
sprintf('The file "%s" did not return a valid PHP array when included', $resource)
);
}
return $config;
} | php | public function load($resource, $type = null)
{
$config = include $resource;
if (!is_array($config)) {
throw new \InvalidArgumentException(
sprintf('The file "%s" did not return a valid PHP array when included', $resource)
);
}
return $config;
} | [
"public",
"function",
"load",
"(",
"$",
"resource",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"config",
"=",
"include",
"$",
"resource",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentExc... | Load a PHP file
@param string $resource File path to a PHP file that returns an array
@param string|null $type This is not used
@return array Array containing data from the PHP file | [
"Load",
"a",
"PHP",
"file"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/FileLoader/PhpArray.php#L32-L43 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader/Resolver/ConstructorResolver.php | ConstructorResolver.configureOptions | protected function configureOptions(OptionsResolver $optionsResolver)
{
foreach ($this->constructorArgs as $name => $param) {
if ($param->isOptional() && $param->isDefaultValueAvailable()) {
$optionsResolver->setDefault($name, $param->getDefaultValue());
} else {
$optionsResolver->setRequired($name);
}
}
} | php | protected function configureOptions(OptionsResolver $optionsResolver)
{
foreach ($this->constructorArgs as $name => $param) {
if ($param->isOptional() && $param->isDefaultValueAvailable()) {
$optionsResolver->setDefault($name, $param->getDefaultValue());
} else {
$optionsResolver->setRequired($name);
}
}
} | [
"protected",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"optionsResolver",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"constructorArgs",
"as",
"$",
"name",
"=>",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"param",
"->",
"isOptional",
"(",
... | Configure options for the provided OptionResolver to match contructor args requirements
@param OptionsResolver $optionsResolver OptionResolver to configure | [
"Configure",
"options",
"for",
"the",
"provided",
"OptionResolver",
"to",
"match",
"contructor",
"args",
"requirements"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader/Resolver/ConstructorResolver.php#L99-L108 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader/Resolver/ConstructorResolver.php | ConstructorResolver.hashToArgsArray | public function hashToArgsArray($hashOfOptions)
{
$optionsArray = new \SplFixedArray(count($hashOfOptions));
foreach ($this->constructorArgs as $name => $param) {
$optionsArray[$param->getPosition()] = $hashOfOptions[$name];
}
return $optionsArray->toArray();
} | php | public function hashToArgsArray($hashOfOptions)
{
$optionsArray = new \SplFixedArray(count($hashOfOptions));
foreach ($this->constructorArgs as $name => $param) {
$optionsArray[$param->getPosition()] = $hashOfOptions[$name];
}
return $optionsArray->toArray();
} | [
"public",
"function",
"hashToArgsArray",
"(",
"$",
"hashOfOptions",
")",
"{",
"$",
"optionsArray",
"=",
"new",
"\\",
"SplFixedArray",
"(",
"count",
"(",
"$",
"hashOfOptions",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"constructorArgs",
"as",
"$",
"... | Loops through constructor args and buid an ordered array of args using
the option values passed in. We assume the passed in array has been resolved already.
i.e. That the arg name has an entry in the option array.
@param array $hashOfOptions Array of options
@return array Array of ordered args | [
"Loops",
"through",
"constructor",
"args",
"and",
"buid",
"an",
"ordered",
"array",
"of",
"args",
"using",
"the",
"option",
"values",
"passed",
"in",
".",
"We",
"assume",
"the",
"passed",
"in",
"array",
"has",
"been",
"resolved",
"already",
".",
"i",
".",
... | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader/Resolver/ConstructorResolver.php#L119-L128 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader/Resolver/ConstructorResolver.php | ConstructorResolver.resolve | public function resolve(array $options)
{
$reflectedClassName = $this->reflected->getName();
// We check if that constructor has been configured before and is in the registry
if (!isset(self::$resolvers[$reflectedClassName])) {
self::$resolvers[$reflectedClassName] = new OptionsResolver();
$this->configureOptions(self::$resolvers[$reflectedClassName]);
}
return $this->hashToArgsArray(
self::$resolvers[$reflectedClassName]->resolve($options)
);
} | php | public function resolve(array $options)
{
$reflectedClassName = $this->reflected->getName();
// We check if that constructor has been configured before and is in the registry
if (!isset(self::$resolvers[$reflectedClassName])) {
self::$resolvers[$reflectedClassName] = new OptionsResolver();
$this->configureOptions(self::$resolvers[$reflectedClassName]);
}
return $this->hashToArgsArray(
self::$resolvers[$reflectedClassName]->resolve($options)
);
} | [
"public",
"function",
"resolve",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"reflectedClassName",
"=",
"$",
"this",
"->",
"reflected",
"->",
"getName",
"(",
")",
";",
"// We check if that constructor has been configured before and is in the registry",
"if",
"(",
"!"... | Resolve options against constructor args
@param array $options Array of option values. Expected array looks like:
array(
'someParam' => 'def',
'someOtherParam' => 'sdsad'
)
@return array Array of resolved ordered args | [
"Resolve",
"options",
"against",
"constructor",
"args"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader/Resolver/ConstructorResolver.php#L141-L155 | train |
theorchard/monolog-cascade | src/Cascade.php | Cascade.getLogger | public static function getLogger($name)
{
return Registry::hasLogger($name) ? Registry::getInstance($name) : self::createLogger($name);
} | php | public static function getLogger($name)
{
return Registry::hasLogger($name) ? Registry::getInstance($name) : self::createLogger($name);
} | [
"public",
"static",
"function",
"getLogger",
"(",
"$",
"name",
")",
"{",
"return",
"Registry",
"::",
"hasLogger",
"(",
"$",
"name",
")",
"?",
"Registry",
"::",
"getInstance",
"(",
"$",
"name",
")",
":",
"self",
"::",
"createLogger",
"(",
"$",
"name",
"... | Get a Logger instance by name. Creates a new one if a Logger with the
provided name does not exist
@param string $name Name of the requested Logger instance
@return Logger Requested instance of Logger or new instance | [
"Get",
"a",
"Logger",
"instance",
"by",
"name",
".",
"Creates",
"a",
"new",
"one",
"if",
"a",
"Logger",
"with",
"the",
"provided",
"name",
"does",
"not",
"exist"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Cascade.php#L72-L75 | train |
theorchard/monolog-cascade | src/Cascade.php | Cascade.fileConfig | public static function fileConfig($resource)
{
self::$config = new Config($resource, new ConfigLoader());
self::$config->load();
self::$config->configure();
} | php | public static function fileConfig($resource)
{
self::$config = new Config($resource, new ConfigLoader());
self::$config->load();
self::$config->configure();
} | [
"public",
"static",
"function",
"fileConfig",
"(",
"$",
"resource",
")",
"{",
"self",
"::",
"$",
"config",
"=",
"new",
"Config",
"(",
"$",
"resource",
",",
"new",
"ConfigLoader",
"(",
")",
")",
";",
"self",
"::",
"$",
"config",
"->",
"load",
"(",
")"... | Load configuration options from a file, a JSON or Yaml string or an array.
@param string|array $resource Path to config file or configuration as string or array | [
"Load",
"configuration",
"options",
"from",
"a",
"file",
"a",
"JSON",
"or",
"Yaml",
"string",
"or",
"an",
"array",
"."
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Cascade.php#L105-L110 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader/HandlerLoader.php | HandlerLoader.populateFormatters | private function populateFormatters(array &$handlerOptions, array $formatters)
{
if (isset($handlerOptions['formatter'])) {
if (isset($formatters[$handlerOptions['formatter']])) {
$handlerOptions['formatter'] = $formatters[$handlerOptions['formatter']];
} else {
throw new \InvalidArgumentException(
sprintf(
'Formatter %s not found in the configured formatters',
$handlerOptions['formatter']
)
);
}
}
} | php | private function populateFormatters(array &$handlerOptions, array $formatters)
{
if (isset($handlerOptions['formatter'])) {
if (isset($formatters[$handlerOptions['formatter']])) {
$handlerOptions['formatter'] = $formatters[$handlerOptions['formatter']];
} else {
throw new \InvalidArgumentException(
sprintf(
'Formatter %s not found in the configured formatters',
$handlerOptions['formatter']
)
);
}
}
} | [
"private",
"function",
"populateFormatters",
"(",
"array",
"&",
"$",
"handlerOptions",
",",
"array",
"$",
"formatters",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"handlerOptions",
"[",
"'formatter'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"forma... | Replace the formatter name in the option array with the corresponding object from the
formatter array passed in if it exists.
If no formatter is specified in the options, Monolog will use its default formatter for the
handler
@throws \InvalidArgumentException
@param array &$handlerOptions Handler options
@param FormatterInterface[] $formatters Array of formatter to pick from | [
"Replace",
"the",
"formatter",
"name",
"in",
"the",
"option",
"array",
"with",
"the",
"corresponding",
"object",
"from",
"the",
"formatter",
"array",
"passed",
"in",
"if",
"it",
"exists",
"."
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader/HandlerLoader.php#L70-L84 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader/HandlerLoader.php | HandlerLoader.populateProcessors | private function populateProcessors(array &$handlerOptions, array $processors)
{
$processorArray = array();
if (isset($handlerOptions['processors'])) {
foreach ($handlerOptions['processors'] as $processorId) {
if (isset($processors[$processorId])) {
$processorArray[] = $processors[$processorId];
} else {
throw new \InvalidArgumentException(
sprintf(
'Cannot add processor "%s" to the handler. Processor not found.',
$processorId
)
);
}
}
$handlerOptions['processors'] = $processorArray;
}
} | php | private function populateProcessors(array &$handlerOptions, array $processors)
{
$processorArray = array();
if (isset($handlerOptions['processors'])) {
foreach ($handlerOptions['processors'] as $processorId) {
if (isset($processors[$processorId])) {
$processorArray[] = $processors[$processorId];
} else {
throw new \InvalidArgumentException(
sprintf(
'Cannot add processor "%s" to the handler. Processor not found.',
$processorId
)
);
}
}
$handlerOptions['processors'] = $processorArray;
}
} | [
"private",
"function",
"populateProcessors",
"(",
"array",
"&",
"$",
"handlerOptions",
",",
"array",
"$",
"processors",
")",
"{",
"$",
"processorArray",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"handlerOptions",
"[",
"'processors'",
"]",
... | Replace the processors in the option array with the corresponding callable from the
array of loaded and callable processors, if it exists.
@throws \InvalidArgumentException
@param array &$handlerOptions Handler options
@param callable[] $processors Array of processors to pick from | [
"Replace",
"the",
"processors",
"in",
"the",
"option",
"array",
"with",
"the",
"corresponding",
"callable",
"from",
"the",
"array",
"of",
"loaded",
"and",
"callable",
"processors",
"if",
"it",
"exists",
"."
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader/HandlerLoader.php#L95-L115 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader/HandlerLoader.php | HandlerLoader.initExtraOptionsHandlers | public static function initExtraOptionsHandlers()
{
self::$extraOptionHandlers = array(
'*' => array(
'formatter' => function (HandlerInterface $instance, FormatterInterface $formatter) {
$instance->setFormatter($formatter);
},
'processors' => function (HandlerInterface $instance, array $processors) {
// We need to reverse the array because Monolog "pushes" processors to top of the stack
foreach (array_reverse($processors) as $processor) {
$instance->pushProcessor($processor);
}
}
),
'Monolog\Handler\LogglyHandler' => array(
'tags' => function (LogglyHandler $instance, $tags) {
$instance->setTag($tags);
}
)
);
} | php | public static function initExtraOptionsHandlers()
{
self::$extraOptionHandlers = array(
'*' => array(
'formatter' => function (HandlerInterface $instance, FormatterInterface $formatter) {
$instance->setFormatter($formatter);
},
'processors' => function (HandlerInterface $instance, array $processors) {
// We need to reverse the array because Monolog "pushes" processors to top of the stack
foreach (array_reverse($processors) as $processor) {
$instance->pushProcessor($processor);
}
}
),
'Monolog\Handler\LogglyHandler' => array(
'tags' => function (LogglyHandler $instance, $tags) {
$instance->setTag($tags);
}
)
);
} | [
"public",
"static",
"function",
"initExtraOptionsHandlers",
"(",
")",
"{",
"self",
"::",
"$",
"extraOptionHandlers",
"=",
"array",
"(",
"'*'",
"=>",
"array",
"(",
"'formatter'",
"=>",
"function",
"(",
"HandlerInterface",
"$",
"instance",
",",
"FormatterInterface",... | Loads the closures as option handlers. Add handlers to this function if
you want to support additional custom options.
The syntax is the following:
array(
'\Full\Absolute\Namespace\ClassName' => array(
'myOption' => Closure
), ...
)
You can use the '*' wildcard if you want to set up an option for all
Handler classes | [
"Loads",
"the",
"closures",
"as",
"option",
"handlers",
".",
"Add",
"handlers",
"to",
"this",
"function",
"if",
"you",
"want",
"to",
"support",
"additional",
"custom",
"options",
"."
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader/HandlerLoader.php#L177-L197 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader/Resolver/ExtraOptionsResolver.php | ExtraOptionsResolver.configureOptions | protected function configureOptions(OptionsResolver $resolver, ClassLoader $classLoader = null)
{
foreach ($this->params as $name) {
if ($this->reflected->hasMethod($name)) {
// There is a method to handle this option
$resolver->setDefined($name);
continue;
}
if ($this->reflected->hasProperty($name) &&
$this->reflected->getProperty($name)->isPublic()
) {
// There is a public member we can set to handle this option
$resolver->setDefined($name);
continue;
}
// Option that cannot be handled by a regular setter but
// requires specific pre-processing and/or handling to be set
// e.g. like LogglyHandler::addTag for instance
if (!is_null($classLoader) && $classLoader->canHandle($name)) {
$resolver->setDefined($name);
}
}
} | php | protected function configureOptions(OptionsResolver $resolver, ClassLoader $classLoader = null)
{
foreach ($this->params as $name) {
if ($this->reflected->hasMethod($name)) {
// There is a method to handle this option
$resolver->setDefined($name);
continue;
}
if ($this->reflected->hasProperty($name) &&
$this->reflected->getProperty($name)->isPublic()
) {
// There is a public member we can set to handle this option
$resolver->setDefined($name);
continue;
}
// Option that cannot be handled by a regular setter but
// requires specific pre-processing and/or handling to be set
// e.g. like LogglyHandler::addTag for instance
if (!is_null($classLoader) && $classLoader->canHandle($name)) {
$resolver->setDefined($name);
}
}
} | [
"protected",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"resolver",
",",
"ClassLoader",
"$",
"classLoader",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"... | Configure options for the provided OptionResolver to match extra params requirements
@param OptionsResolver $resolver OptionResolver to configure
@param ClassLoader|null $classLoader Optional class loader if you want to use custom
handlers for some of the extra options | [
"Configure",
"options",
"for",
"the",
"provided",
"OptionResolver",
"to",
"match",
"extra",
"params",
"requirements"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader/Resolver/ExtraOptionsResolver.php#L105-L128 | train |
theorchard/monolog-cascade | src/Config/Loader/ClassLoader/Resolver/ExtraOptionsResolver.php | ExtraOptionsResolver.resolve | public function resolve($options, ClassLoader $classLoader = null)
{
$hashKey = self::generateParamsHashKey($this->params);
// Was configureOptions() executed before for this class?
if (!isset(self::$resolvers[$hashKey])) {
self::$resolvers[$hashKey] = new OptionsResolver();
$this->configureOptions(self::$resolvers[$hashKey], $classLoader);
}
return self::$resolvers[$hashKey]->resolve($options);
} | php | public function resolve($options, ClassLoader $classLoader = null)
{
$hashKey = self::generateParamsHashKey($this->params);
// Was configureOptions() executed before for this class?
if (!isset(self::$resolvers[$hashKey])) {
self::$resolvers[$hashKey] = new OptionsResolver();
$this->configureOptions(self::$resolvers[$hashKey], $classLoader);
}
return self::$resolvers[$hashKey]->resolve($options);
} | [
"public",
"function",
"resolve",
"(",
"$",
"options",
",",
"ClassLoader",
"$",
"classLoader",
"=",
"null",
")",
"{",
"$",
"hashKey",
"=",
"self",
"::",
"generateParamsHashKey",
"(",
"$",
"this",
"->",
"params",
")",
";",
"// Was configureOptions() executed befor... | Resolve options against extra params requirements
@param array $options Array of option values
@param ClassLoader|null $classLoader Optional class loader if you want to use custom
handlers to resolve the extra options
@return array Array of resolved options | [
"Resolve",
"options",
"against",
"extra",
"params",
"requirements"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/ClassLoader/Resolver/ExtraOptionsResolver.php#L139-L150 | train |
theorchard/monolog-cascade | src/Config/Loader/FileLoader/Json.php | Json.supports | public function supports($resource, $type = null)
{
if (is_string($resource)) {
if ($this->isFile($resource)) {
return $this->validateExtension($resource);
} else {
return $this->isJson($resource);
}
}
return false;
} | php | public function supports($resource, $type = null)
{
if (is_string($resource)) {
if ($this->isFile($resource)) {
return $this->validateExtension($resource);
} else {
return $this->isJson($resource);
}
}
return false;
} | [
"public",
"function",
"supports",
"(",
"$",
"resource",
",",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"resource",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isFile",
"(",
"$",
"resource",
")",
")",
"{",
"return",
"... | Return whether or not the passed in resource is supported by this loader
@param string $resource Plain string or filepath
@param string $type Not used
@return boolean Whether or not the passed in resource is supported by this loader | [
"Return",
"whether",
"or",
"not",
"the",
"passed",
"in",
"resource",
"is",
"supported",
"by",
"this",
"loader"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/FileLoader/Json.php#L66-L77 | train |
theorchard/monolog-cascade | src/Util.php | Util.snakeToCamelCase | public static function snakeToCamelCase($input)
{
if (!is_string($input)) {
return null;
}
$output = preg_replace_callback('/(^|_)+(.)/', function ($match) {
return strtoupper($match[2]);
}, $input);
return lcfirst($output);
} | php | public static function snakeToCamelCase($input)
{
if (!is_string($input)) {
return null;
}
$output = preg_replace_callback('/(^|_)+(.)/', function ($match) {
return strtoupper($match[2]);
}, $input);
return lcfirst($output);
} | [
"public",
"static",
"function",
"snakeToCamelCase",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"input",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"output",
"=",
"preg_replace_callback",
"(",
"'/(^|_)+(.)/'",
",",
"function",
... | Convert a string from snake_case to camelCase.
If the input is not a string, null is returned.
@param string $input Input snake_case string
@return null|string Output camelCase string | [
"Convert",
"a",
"string",
"from",
"snake_case",
"to",
"camelCase",
"."
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Util.php#L21-L32 | train |
theorchard/monolog-cascade | src/Config/Loader/FileLoader/FileLoaderAbstract.php | FileLoaderAbstract.readFrom | public function readFrom($input)
{
if ($this->isFile($input)) {
if (is_readable($input) === false) {
throw new \RuntimeException(
sprintf('Unable to parse "%s" as the file is not readable.', $input)
);
}
// $input is a filepath, so we load that file
$input = file_get_contents($input);
}
return trim($input);
} | php | public function readFrom($input)
{
if ($this->isFile($input)) {
if (is_readable($input) === false) {
throw new \RuntimeException(
sprintf('Unable to parse "%s" as the file is not readable.', $input)
);
}
// $input is a filepath, so we load that file
$input = file_get_contents($input);
}
return trim($input);
} | [
"public",
"function",
"readFrom",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isFile",
"(",
"$",
"input",
")",
")",
"{",
"if",
"(",
"is_readable",
"(",
"$",
"input",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"RuntimeExcep... | Read from a file or string
@throws \RuntimeException if the file is not readable
@param string $input Filepath or string
@return string Return a string from read file or directly from $input | [
"Read",
"from",
"a",
"file",
"or",
"string"
] | 39ff6a4dfb41d19d916b97a362d501d25e98f62a | https://github.com/theorchard/monolog-cascade/blob/39ff6a4dfb41d19d916b97a362d501d25e98f62a/src/Config/Loader/FileLoader/FileLoaderAbstract.php#L33-L47 | train |
Behat/Symfony2Extension | src/Behat/Symfony2Extension/Context/Argument/ServiceArgumentResolver.php | ServiceArgumentResolver.resolveArgument | private function resolveArgument($argument)
{
if (is_array($argument)) {
return array_map(array($this, 'resolveArgument'), $argument);
}
if (!is_string($argument)) {
return $argument;
}
$container = $this->kernel->getContainer();
$container = $container->has('test.service_container') ? $container->get('test.service_container') : $container;
if ($service = $this->getService($container, $argument)) {
return $service;
}
$resolvedParam = $this->replaceParameters($container, $argument);
if (!is_string($resolvedParam)) {
return $resolvedParam;
}
return $this->escape($resolvedParam);
} | php | private function resolveArgument($argument)
{
if (is_array($argument)) {
return array_map(array($this, 'resolveArgument'), $argument);
}
if (!is_string($argument)) {
return $argument;
}
$container = $this->kernel->getContainer();
$container = $container->has('test.service_container') ? $container->get('test.service_container') : $container;
if ($service = $this->getService($container, $argument)) {
return $service;
}
$resolvedParam = $this->replaceParameters($container, $argument);
if (!is_string($resolvedParam)) {
return $resolvedParam;
}
return $this->escape($resolvedParam);
} | [
"private",
"function",
"resolveArgument",
"(",
"$",
"argument",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"argument",
")",
")",
"{",
"return",
"array_map",
"(",
"array",
"(",
"$",
"this",
",",
"'resolveArgument'",
")",
",",
"$",
"argument",
")",
";",
... | Resolves single argument using container.
@param string $argument
@return mixed | [
"Resolves",
"single",
"argument",
"using",
"container",
"."
] | 31258ea704144c2cd55db1ce58de000c5d59a77b | https://github.com/Behat/Symfony2Extension/blob/31258ea704144c2cd55db1ce58de000c5d59a77b/src/Behat/Symfony2Extension/Context/Argument/ServiceArgumentResolver.php#L62-L86 | train |
Behat/Symfony2Extension | src/Behat/Symfony2Extension/Context/Argument/ServiceArgumentResolver.php | ServiceArgumentResolver.replaceParameters | private function replaceParameters(ContainerInterface $container, $argument)
{
if (preg_match('/^(?<!%)%([^%]+)%(?!%)$/', $argument, $matches)) {
$replaced = $matches[1];
if ($container->hasParameter($replaced)) {
return $container->getParameter($replaced);
}
return $replaced;
}
return preg_replace_callback(
'/(?<!%)%([^%]+)%(?!%)/',
function ($matches) use ($container) {
$parameter = $container->getParameter($matches[1]);
if (is_array($parameter)) {
throw new InvalidArgumentException(
'Cannot reference a collection-type parameter with string interpolation.'
);
}
return $parameter;
},
$argument
);
} | php | private function replaceParameters(ContainerInterface $container, $argument)
{
if (preg_match('/^(?<!%)%([^%]+)%(?!%)$/', $argument, $matches)) {
$replaced = $matches[1];
if ($container->hasParameter($replaced)) {
return $container->getParameter($replaced);
}
return $replaced;
}
return preg_replace_callback(
'/(?<!%)%([^%]+)%(?!%)/',
function ($matches) use ($container) {
$parameter = $container->getParameter($matches[1]);
if (is_array($parameter)) {
throw new InvalidArgumentException(
'Cannot reference a collection-type parameter with string interpolation.'
);
}
return $parameter;
},
$argument
);
} | [
"private",
"function",
"replaceParameters",
"(",
"ContainerInterface",
"$",
"container",
",",
"$",
"argument",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^(?<!%)%([^%]+)%(?!%)$/'",
",",
"$",
"argument",
",",
"$",
"matches",
")",
")",
"{",
"$",
"replaced",
"=",... | Sanitise the container key given by the Behat config file,
and retrieve the parameter from the Container.
First, check if the whole string is one substitution, if it is, then pull it from the container.
Secondly, iterate over all substitutions in the string. Exception is thrown if referencing a
collection-type parameter when the key is not an entire substitution.
This is to handle the case where we're given an argument which should return a
collection-type parameter from the container.
@param ContainerInterface $container
@param string $argument
@throws InvalidArgumentException
@return mixed | [
"Sanitise",
"the",
"container",
"key",
"given",
"by",
"the",
"Behat",
"config",
"file",
"and",
"retrieve",
"the",
"parameter",
"from",
"the",
"Container",
"."
] | 31258ea704144c2cd55db1ce58de000c5d59a77b | https://github.com/Behat/Symfony2Extension/blob/31258ea704144c2cd55db1ce58de000c5d59a77b/src/Behat/Symfony2Extension/Context/Argument/ServiceArgumentResolver.php#L133-L160 | train |
Behat/Symfony2Extension | features/bootstrap/FeatureContext.php | FeatureContext.prepareProcess | public function prepareProcess()
{
$phpFinder = new PhpExecutableFinder();
if (false === $php = $phpFinder->find()) {
throw new \RuntimeException('Unable to find the PHP executable.');
}
$this->phpBin = $php;
$this->process = new Process(null);
} | php | public function prepareProcess()
{
$phpFinder = new PhpExecutableFinder();
if (false === $php = $phpFinder->find()) {
throw new \RuntimeException('Unable to find the PHP executable.');
}
$this->phpBin = $php;
$this->process = new Process(null);
} | [
"public",
"function",
"prepareProcess",
"(",
")",
"{",
"$",
"phpFinder",
"=",
"new",
"PhpExecutableFinder",
"(",
")",
";",
"if",
"(",
"false",
"===",
"$",
"php",
"=",
"$",
"phpFinder",
"->",
"find",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeExc... | Prepares test folders in the temporary directory.
@BeforeScenario | [
"Prepares",
"test",
"folders",
"in",
"the",
"temporary",
"directory",
"."
] | 31258ea704144c2cd55db1ce58de000c5d59a77b | https://github.com/Behat/Symfony2Extension/blob/31258ea704144c2cd55db1ce58de000c5d59a77b/features/bootstrap/FeatureContext.php#L27-L35 | train |
Behat/Symfony2Extension | src/Behat/Symfony2Extension/Context/Initializer/KernelAwareInitializer.php | KernelAwareInitializer.usesKernelDictionary | private function usesKernelDictionary(Context $context)
{
$refl = new \ReflectionObject($context);
if (method_exists($refl, 'getTraitNames')) {
if (in_array('Behat\\Symfony2Extension\\Context\\KernelDictionary', $refl->getTraitNames())) {
return true;
}
}
return false;
} | php | private function usesKernelDictionary(Context $context)
{
$refl = new \ReflectionObject($context);
if (method_exists($refl, 'getTraitNames')) {
if (in_array('Behat\\Symfony2Extension\\Context\\KernelDictionary', $refl->getTraitNames())) {
return true;
}
}
return false;
} | [
"private",
"function",
"usesKernelDictionary",
"(",
"Context",
"$",
"context",
")",
"{",
"$",
"refl",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"context",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"refl",
",",
"'getTraitNames'",
")",
")",
"{",
... | Checks whether the context uses the KernelDictionary trait.
@param Context $context
@return boolean | [
"Checks",
"whether",
"the",
"context",
"uses",
"the",
"KernelDictionary",
"trait",
"."
] | 31258ea704144c2cd55db1ce58de000c5d59a77b | https://github.com/Behat/Symfony2Extension/blob/31258ea704144c2cd55db1ce58de000c5d59a77b/src/Behat/Symfony2Extension/Context/Initializer/KernelAwareInitializer.php#L81-L91 | train |
anlutro/laravel-settings | src/DatabaseSettingStore.php | DatabaseSettingStore.prepareInsertData | protected function prepareInsertData(array $data)
{
$dbData = array();
if ($this->extraColumns) {
foreach ($data as $key => $value) {
$dbData[] = array_merge(
$this->extraColumns,
array($this->keyColumn => $key, $this->valueColumn => $value)
);
}
} else {
foreach ($data as $key => $value) {
$dbData[] = array($this->keyColumn => $key, $this->valueColumn => $value);
}
}
return $dbData;
} | php | protected function prepareInsertData(array $data)
{
$dbData = array();
if ($this->extraColumns) {
foreach ($data as $key => $value) {
$dbData[] = array_merge(
$this->extraColumns,
array($this->keyColumn => $key, $this->valueColumn => $value)
);
}
} else {
foreach ($data as $key => $value) {
$dbData[] = array($this->keyColumn => $key, $this->valueColumn => $value);
}
}
return $dbData;
} | [
"protected",
"function",
"prepareInsertData",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"dbData",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"extraColumns",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
... | Transforms settings data into an array ready to be insterted into the
database. Call array_dot on a multidimensional array before passing it
into this method!
@param array $data Call array_dot on a multidimensional array before passing it into this method!
@return array | [
"Transforms",
"settings",
"data",
"into",
"an",
"array",
"ready",
"to",
"be",
"insterted",
"into",
"the",
"database",
".",
"Call",
"array_dot",
"on",
"a",
"multidimensional",
"array",
"before",
"passing",
"it",
"into",
"this",
"method!"
] | fa9635df8c17d78bd1928a4f31c5ecdd17a080bd | https://github.com/anlutro/laravel-settings/blob/fa9635df8c17d78bd1928a4f31c5ecdd17a080bd/src/DatabaseSettingStore.php#L200-L218 | train |
anlutro/laravel-settings | src/ServiceProvider.php | ServiceProvider.register | public function register()
{
$method = version_compare(Application::VERSION, '5.2', '>=') ? 'singleton' : 'bindShared';
// Bind the manager as a singleton on the container.
$this->app->$method('anlutro\LaravelSettings\SettingsManager', function($app) {
// When the class has been resolved once, make sure that settings
// are saved when the application shuts down.
if (version_compare(Application::VERSION, '5.0', '<')) {
$app->shutdown(function($app) {
$app->make('anlutro\LaravelSettings\SettingStore')->save();
});
}
/**
* Construct the actual manager.
*/
return new SettingsManager($app);
});
// Provide a shortcut to the SettingStore for injecting into classes.
$this->app->bind('anlutro\LaravelSettings\SettingStore', function($app) {
return $app->make('anlutro\LaravelSettings\SettingsManager')->driver();
});
$this->app->alias('anlutro\LaravelSettings\SettingStore', 'setting');
if (version_compare(Application::VERSION, '5.0', '>=')) {
$this->mergeConfigFrom(__DIR__ . '/config/config.php', 'settings');
}
} | php | public function register()
{
$method = version_compare(Application::VERSION, '5.2', '>=') ? 'singleton' : 'bindShared';
// Bind the manager as a singleton on the container.
$this->app->$method('anlutro\LaravelSettings\SettingsManager', function($app) {
// When the class has been resolved once, make sure that settings
// are saved when the application shuts down.
if (version_compare(Application::VERSION, '5.0', '<')) {
$app->shutdown(function($app) {
$app->make('anlutro\LaravelSettings\SettingStore')->save();
});
}
/**
* Construct the actual manager.
*/
return new SettingsManager($app);
});
// Provide a shortcut to the SettingStore for injecting into classes.
$this->app->bind('anlutro\LaravelSettings\SettingStore', function($app) {
return $app->make('anlutro\LaravelSettings\SettingsManager')->driver();
});
$this->app->alias('anlutro\LaravelSettings\SettingStore', 'setting');
if (version_compare(Application::VERSION, '5.0', '>=')) {
$this->mergeConfigFrom(__DIR__ . '/config/config.php', 'settings');
}
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"method",
"=",
"version_compare",
"(",
"Application",
"::",
"VERSION",
",",
"'5.2'",
",",
"'>='",
")",
"?",
"'singleton'",
":",
"'bindShared'",
";",
"// Bind the manager as a singleton on the container.",
"$",
... | Register IoC bindings. | [
"Register",
"IoC",
"bindings",
"."
] | fa9635df8c17d78bd1928a4f31c5ecdd17a080bd | https://github.com/anlutro/laravel-settings/blob/fa9635df8c17d78bd1928a4f31c5ecdd17a080bd/src/ServiceProvider.php#L26-L56 | train |
auraphp/Aura.Di | src/Resolver/Blueprint.php | Blueprint.merge | public function merge(Blueprint $mergeBlueprint): Blueprint
{
return new Blueprint(
$this->className,
$this->mergeParams($mergeBlueprint),
$this->mergeSetters($mergeBlueprint),
$this->mergeMutations($mergeBlueprint)
);
} | php | public function merge(Blueprint $mergeBlueprint): Blueprint
{
return new Blueprint(
$this->className,
$this->mergeParams($mergeBlueprint),
$this->mergeSetters($mergeBlueprint),
$this->mergeMutations($mergeBlueprint)
);
} | [
"public",
"function",
"merge",
"(",
"Blueprint",
"$",
"mergeBlueprint",
")",
":",
"Blueprint",
"{",
"return",
"new",
"Blueprint",
"(",
"$",
"this",
"->",
"className",
",",
"$",
"this",
"->",
"mergeParams",
"(",
"$",
"mergeBlueprint",
")",
",",
"$",
"this",... | Merges all parameters and invokes the lazy ones.
@param Blueprint $mergeBlueprint The overrides during merging
@return Blueprint The merged blueprint | [
"Merges",
"all",
"parameters",
"and",
"invokes",
"the",
"lazy",
"ones",
"."
] | ea4b166e9006babca411732c4d45ee14efa32259 | https://github.com/auraphp/Aura.Di/blob/ea4b166e9006babca411732c4d45ee14efa32259/src/Resolver/Blueprint.php#L65-L73 | train |
auraphp/Aura.Di | src/Resolver/Resolver.php | Resolver.expandParams | protected function expandParams(Blueprint $blueprint): Blueprint
{
$class = $blueprint->getClassName();
$params = $blueprint->getParams();
$variadicParams = [];
foreach ($this->reflector->getParams($class) as $reflectParam) {
$paramName = $reflectParam->getName();
if ($reflectParam->isVariadic() && is_array($params[$paramName])) {
$variadicParams = array_merge($variadicParams, $params[$paramName]);
unset($params[$paramName]);
break; // There can only be one
}
if ($params[$paramName] instanceof DefaultValueParam) {
$params[$paramName] = $params[$paramName]->getValue();
}
}
return $blueprint->replaceParams(array_merge($params, array_values($variadicParams)));
} | php | protected function expandParams(Blueprint $blueprint): Blueprint
{
$class = $blueprint->getClassName();
$params = $blueprint->getParams();
$variadicParams = [];
foreach ($this->reflector->getParams($class) as $reflectParam) {
$paramName = $reflectParam->getName();
if ($reflectParam->isVariadic() && is_array($params[$paramName])) {
$variadicParams = array_merge($variadicParams, $params[$paramName]);
unset($params[$paramName]);
break; // There can only be one
}
if ($params[$paramName] instanceof DefaultValueParam) {
$params[$paramName] = $params[$paramName]->getValue();
}
}
return $blueprint->replaceParams(array_merge($params, array_values($variadicParams)));
} | [
"protected",
"function",
"expandParams",
"(",
"Blueprint",
"$",
"blueprint",
")",
":",
"Blueprint",
"{",
"$",
"class",
"=",
"$",
"blueprint",
"->",
"getClassName",
"(",
")",
";",
"$",
"params",
"=",
"$",
"blueprint",
"->",
"getParams",
"(",
")",
";",
"$"... | Expands variadic parameters onto the end of a contructor parameters array.
@param Blueprint $blueprint The blueprint to expand parameters for.
@return Blueprint The blueprint with expanded constructor parameters. | [
"Expands",
"variadic",
"parameters",
"onto",
"the",
"end",
"of",
"a",
"contructor",
"parameters",
"array",
"."
] | ea4b166e9006babca411732c4d45ee14efa32259 | https://github.com/auraphp/Aura.Di/blob/ea4b166e9006babca411732c4d45ee14efa32259/src/Resolver/Resolver.php#L423-L443 | train |
coinbase/coinbase-php | src/ActiveRecord/AccountActiveRecord.php | AccountActiveRecord.createAddress | public function createAddress(Address $address, array $params = [])
{
$this->getClient()->createAccountAddress($this, $address, $params);
} | php | public function createAddress(Address $address, array $params = [])
{
$this->getClient()->createAccountAddress($this, $address, $params);
} | [
"public",
"function",
"createAddress",
"(",
"Address",
"$",
"address",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"createAccountAddress",
"(",
"$",
"this",
",",
"$",
"address",
",",
"$",
"param... | Issues an API request to create a new account address. | [
"Issues",
"an",
"API",
"request",
"to",
"create",
"a",
"new",
"account",
"address",
"."
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/ActiveRecord/AccountActiveRecord.php#L74-L77 | train |
coinbase/coinbase-php | src/ActiveRecord/AccountActiveRecord.php | AccountActiveRecord.createTransaction | public function createTransaction(Transaction $transaction, array $params = [])
{
$this->getClient()->createAccountTransaction($this, $transaction, $params);
} | php | public function createTransaction(Transaction $transaction, array $params = [])
{
$this->getClient()->createAccountTransaction($this, $transaction, $params);
} | [
"public",
"function",
"createTransaction",
"(",
"Transaction",
"$",
"transaction",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"createAccountTransaction",
"(",
"$",
"this",
",",
"$",
"transaction",
... | Issues an API request to create a new account transaction. | [
"Issues",
"an",
"API",
"request",
"to",
"create",
"a",
"new",
"account",
"transaction",
"."
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/ActiveRecord/AccountActiveRecord.php#L104-L107 | train |
coinbase/coinbase-php | src/ActiveRecord/AccountActiveRecord.php | AccountActiveRecord.createBuy | public function createBuy(Buy $buy, array $params = [])
{
$this->getClient()->createAccountBuy($this, $buy, $params);
} | php | public function createBuy(Buy $buy, array $params = [])
{
$this->getClient()->createAccountBuy($this, $buy, $params);
} | [
"public",
"function",
"createBuy",
"(",
"Buy",
"$",
"buy",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"createAccountBuy",
"(",
"$",
"this",
",",
"$",
"buy",
",",
"$",
"params",
")",
";",
... | Issues an API request to create a new account buy. | [
"Issues",
"an",
"API",
"request",
"to",
"create",
"a",
"new",
"account",
"buy",
"."
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/ActiveRecord/AccountActiveRecord.php#L134-L137 | train |
coinbase/coinbase-php | src/ActiveRecord/AccountActiveRecord.php | AccountActiveRecord.createSell | public function createSell(Sell $sell, array $params = [])
{
$this->getClient()->createAccountSell($this, $sell, $params);
} | php | public function createSell(Sell $sell, array $params = [])
{
$this->getClient()->createAccountSell($this, $sell, $params);
} | [
"public",
"function",
"createSell",
"(",
"Sell",
"$",
"sell",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"createAccountSell",
"(",
"$",
"this",
",",
"$",
"sell",
",",
"$",
"params",
")",
";... | Issues an API request to create a new account sell. | [
"Issues",
"an",
"API",
"request",
"to",
"create",
"a",
"new",
"account",
"sell",
"."
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/ActiveRecord/AccountActiveRecord.php#L172-L175 | train |
coinbase/coinbase-php | src/ActiveRecord/AccountActiveRecord.php | AccountActiveRecord.createDeposit | public function createDeposit(Deposit $deposit, array $params = [])
{
$this->getClient()->createAccountDeposit($this, $deposit, $params);
} | php | public function createDeposit(Deposit $deposit, array $params = [])
{
$this->getClient()->createAccountDeposit($this, $deposit, $params);
} | [
"public",
"function",
"createDeposit",
"(",
"Deposit",
"$",
"deposit",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"createAccountDeposit",
"(",
"$",
"this",
",",
"$",
"deposit",
",",
"$",
"param... | Issues an API request to create a new account deposit. | [
"Issues",
"an",
"API",
"request",
"to",
"create",
"a",
"new",
"account",
"deposit",
"."
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/ActiveRecord/AccountActiveRecord.php#L210-L213 | train |
coinbase/coinbase-php | src/ActiveRecord/AccountActiveRecord.php | AccountActiveRecord.createWithdrawal | public function createWithdrawal(Withdrawal $withdrawal, array $params = [])
{
$this->getClient()->createAccountWithdrawal($this, $withdrawal, $params);
} | php | public function createWithdrawal(Withdrawal $withdrawal, array $params = [])
{
$this->getClient()->createAccountWithdrawal($this, $withdrawal, $params);
} | [
"public",
"function",
"createWithdrawal",
"(",
"Withdrawal",
"$",
"withdrawal",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"createAccountWithdrawal",
"(",
"$",
"this",
",",
"$",
"withdrawal",
",",
... | Issues an API request to create a new account withdrawal. | [
"Issues",
"an",
"API",
"request",
"to",
"create",
"a",
"new",
"account",
"withdrawal",
"."
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/ActiveRecord/AccountActiveRecord.php#L248-L251 | train |
coinbase/coinbase-php | src/Client.php | Client.createAccountTransaction | public function createAccountTransaction(Account $account, Transaction $transaction, array $params = [])
{
$data = $this->mapper->fromTransaction($transaction);
$this->postAndMap($account->getResourcePath().'/transactions', $data + $params, 'toTransaction', $transaction);
} | php | public function createAccountTransaction(Account $account, Transaction $transaction, array $params = [])
{
$data = $this->mapper->fromTransaction($transaction);
$this->postAndMap($account->getResourcePath().'/transactions', $data + $params, 'toTransaction', $transaction);
} | [
"public",
"function",
"createAccountTransaction",
"(",
"Account",
"$",
"account",
",",
"Transaction",
"$",
"transaction",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"mapper",
"->",
"fromTransaction",
"(",
"$"... | Creates a new transaction.
Supported parameters include:
* skip_notifications (Boolean)
* fee (float)
* idem (string) | [
"Creates",
"a",
"new",
"transaction",
"."
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/Client.php#L359-L363 | train |
coinbase/coinbase-php | src/Client.php | Client.createAccountBuy | public function createAccountBuy(Account $account, Buy $buy, array $params = [])
{
$data = $this->mapper->fromBuy($buy);
$this->postAndMap($account->getResourcePath().'/buys', $data + $params, 'toBuy', $buy);
} | php | public function createAccountBuy(Account $account, Buy $buy, array $params = [])
{
$data = $this->mapper->fromBuy($buy);
$this->postAndMap($account->getResourcePath().'/buys', $data + $params, 'toBuy', $buy);
} | [
"public",
"function",
"createAccountBuy",
"(",
"Account",
"$",
"account",
",",
"Buy",
"$",
"buy",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"mapper",
"->",
"fromBuy",
"(",
"$",
"buy",
")",
";",
"$",
... | Buys some amount of bitcoin.
Supported parameters include:
* agree_btc_amount_varies (Boolean)
* commit (Boolean)
* quote (Boolean) | [
"Buys",
"some",
"amount",
"of",
"bitcoin",
"."
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/Client.php#L421-L425 | train |
coinbase/coinbase-php | src/Client.php | Client.createAccountSell | public function createAccountSell(Account $account, Sell $sell, array $params = [])
{
$data = $this->mapper->fromSell($sell);
$this->postAndMap($account->getResourcePath().'/sells', $data + $params, 'toSell', $sell);
} | php | public function createAccountSell(Account $account, Sell $sell, array $params = [])
{
$data = $this->mapper->fromSell($sell);
$this->postAndMap($account->getResourcePath().'/sells', $data + $params, 'toSell', $sell);
} | [
"public",
"function",
"createAccountSell",
"(",
"Account",
"$",
"account",
",",
"Sell",
"$",
"sell",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"mapper",
"->",
"fromSell",
"(",
"$",
"sell",
")",
";",
... | Sells some amount of bitcoin.
Supported parameters include:
* agree_btc_amount_varies (Boolean)
* commit (Boolean)
* quote (Boolean) | [
"Sells",
"some",
"amount",
"of",
"bitcoin",
"."
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/Client.php#L473-L477 | train |
coinbase/coinbase-php | src/Client.php | Client.createAccountDeposit | public function createAccountDeposit(Account $account, Deposit $deposit, array $params = [])
{
$data = $this->mapper->fromDeposit($deposit);
$this->postAndMap($account->getResourcePath().'/deposits', $data + $params, 'toDeposit', $deposit);
} | php | public function createAccountDeposit(Account $account, Deposit $deposit, array $params = [])
{
$data = $this->mapper->fromDeposit($deposit);
$this->postAndMap($account->getResourcePath().'/deposits', $data + $params, 'toDeposit', $deposit);
} | [
"public",
"function",
"createAccountDeposit",
"(",
"Account",
"$",
"account",
",",
"Deposit",
"$",
"deposit",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"mapper",
"->",
"fromDeposit",
"(",
"$",
"deposit",
... | Deposits some amount of funds.
Supported parameters include:
* commit (Boolean) | [
"Deposits",
"some",
"amount",
"of",
"funds",
"."
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/Client.php#L523-L527 | train |
coinbase/coinbase-php | src/Client.php | Client.createAccountWithdrawal | public function createAccountWithdrawal(Account $account, Withdrawal $withdrawal, array $params = [])
{
$data = $this->mapper->fromWithdrawal($withdrawal);
$this->postAndMap($account->getResourcePath().'/withdrawals', $data + $params, 'toWithdrawal', $withdrawal);
} | php | public function createAccountWithdrawal(Account $account, Withdrawal $withdrawal, array $params = [])
{
$data = $this->mapper->fromWithdrawal($withdrawal);
$this->postAndMap($account->getResourcePath().'/withdrawals', $data + $params, 'toWithdrawal', $withdrawal);
} | [
"public",
"function",
"createAccountWithdrawal",
"(",
"Account",
"$",
"account",
",",
"Withdrawal",
"$",
"withdrawal",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"mapper",
"->",
"fromWithdrawal",
"(",
"$",
... | Withdraws some amount of funds.
Supported parameters include:
* commit (Boolean) | [
"Withdraws",
"some",
"amount",
"of",
"funds",
"."
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/Client.php#L573-L577 | train |
coinbase/coinbase-php | src/Client.php | Client.refundOrder | public function refundOrder(Order $order, $currency, array $params = [])
{
$params['currency'] = $currency;
$this->postAndMap($order->getResourcePath().'/refund', $params, 'toOrder', $order);
} | php | public function refundOrder(Order $order, $currency, array $params = [])
{
$params['currency'] = $currency;
$this->postAndMap($order->getResourcePath().'/refund', $params, 'toOrder', $order);
} | [
"public",
"function",
"refundOrder",
"(",
"Order",
"$",
"order",
",",
"$",
"currency",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"params",
"[",
"'currency'",
"]",
"=",
"$",
"currency",
";",
"$",
"this",
"->",
"postAndMap",
"(",
"$",
... | Refunds an order.
Supported parameters include:
* mispayment (string)
* refund_address (string) | [
"Refunds",
"an",
"order",
"."
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/Client.php#L669-L674 | train |
coinbase/coinbase-php | src/Client.php | Client.parseNotification | public function parseNotification($webhook_body)
{
$data = json_decode($webhook_body, true);
return $this->mapper->injectNotification($data);
} | php | public function parseNotification($webhook_body)
{
$data = json_decode($webhook_body, true);
return $this->mapper->injectNotification($data);
} | [
"public",
"function",
"parseNotification",
"(",
"$",
"webhook_body",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"webhook_body",
",",
"true",
")",
";",
"return",
"$",
"this",
"->",
"mapper",
"->",
"injectNotification",
"(",
"$",
"data",
")",
";",
... | Create a Notification object from the body of a notification webhook
@return Notification | [
"Create",
"a",
"Notification",
"object",
"from",
"the",
"body",
"of",
"a",
"notification",
"webhook"
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/Client.php#L743-L747 | train |
coinbase/coinbase-php | src/Client.php | Client.verifyCallback | public function verifyCallback($body, $signature)
{
$signature_buffer = base64_decode( $signature );
return (1 == openssl_verify($body, $signature_buffer, self::getCallbackPublicKey(), OPENSSL_ALGO_SHA256));
} | php | public function verifyCallback($body, $signature)
{
$signature_buffer = base64_decode( $signature );
return (1 == openssl_verify($body, $signature_buffer, self::getCallbackPublicKey(), OPENSSL_ALGO_SHA256));
} | [
"public",
"function",
"verifyCallback",
"(",
"$",
"body",
",",
"$",
"signature",
")",
"{",
"$",
"signature_buffer",
"=",
"base64_decode",
"(",
"$",
"signature",
")",
";",
"return",
"(",
"1",
"==",
"openssl_verify",
"(",
"$",
"body",
",",
"$",
"signature_bu... | Verifies the authenticity of a merchant callback from Coinbase
@return Boolean | [
"Verifies",
"the",
"authenticity",
"of",
"a",
"merchant",
"callback",
"from",
"Coinbase"
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/Client.php#L754-L758 | train |
coinbase/coinbase-php | src/Exception/HttpException.php | HttpException.wrap | public static function wrap(RequestException $e)
{
$response = $e->getResponse();
if ($errors = self::errors($response)) {
$class = self::exceptionClass($response, $errors[0]);
$message = implode(', ', array_map('strval', $errors));
} else {
$class = self::exceptionClass($response);
$message = $e->getMessage();
}
return new $class($message, $errors, $e->getRequest(), $response, $e);
} | php | public static function wrap(RequestException $e)
{
$response = $e->getResponse();
if ($errors = self::errors($response)) {
$class = self::exceptionClass($response, $errors[0]);
$message = implode(', ', array_map('strval', $errors));
} else {
$class = self::exceptionClass($response);
$message = $e->getMessage();
}
return new $class($message, $errors, $e->getRequest(), $response, $e);
} | [
"public",
"static",
"function",
"wrap",
"(",
"RequestException",
"$",
"e",
")",
"{",
"$",
"response",
"=",
"$",
"e",
"->",
"getResponse",
"(",
")",
";",
"if",
"(",
"$",
"errors",
"=",
"self",
"::",
"errors",
"(",
"$",
"response",
")",
")",
"{",
"$"... | Wraps an API exception in the appropriate domain exception.
@param RequestException $e The API exception
@return HttpException | [
"Wraps",
"an",
"API",
"exception",
"in",
"the",
"appropriate",
"domain",
"exception",
"."
] | 9313a554f794c258af40e11f8841a93a6249fae4 | https://github.com/coinbase/coinbase-php/blob/9313a554f794c258af40e11f8841a93a6249fae4/src/Exception/HttpException.php#L25-L38 | train |
Spomky-Labs/jose | src/Object/RotatableJWKSet.php | RotatableJWKSet.rotateIfNeeded | private function rotateIfNeeded()
{
if (isset($this->interval) && $this->interval >= 0) {
$modificationTime = $this->getLastModificationTime();
if (null === $modificationTime) {
$this->regen();
} elseif (($modificationTime + $this->interval) < time()) {
$this->rotate();
}
}
} | php | private function rotateIfNeeded()
{
if (isset($this->interval) && $this->interval >= 0) {
$modificationTime = $this->getLastModificationTime();
if (null === $modificationTime) {
$this->regen();
} elseif (($modificationTime + $this->interval) < time()) {
$this->rotate();
}
}
} | [
"private",
"function",
"rotateIfNeeded",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"interval",
")",
"&&",
"$",
"this",
"->",
"interval",
">=",
"0",
")",
"{",
"$",
"modificationTime",
"=",
"$",
"this",
"->",
"getLastModificationTime",
"("... | Rotate key set if last modification time is due. | [
"Rotate",
"key",
"set",
"if",
"last",
"modification",
"time",
"is",
"due",
"."
] | d2ba9ba5a5cc66ca22edc07c2e9190ec6c7664e2 | https://github.com/Spomky-Labs/jose/blob/d2ba9ba5a5cc66ca22edc07c2e9190ec6c7664e2/src/Object/RotatableJWKSet.php#L72-L83 | train |
Spomky-Labs/jose | src/Util/RSA.php | RSA.convertIntegerToOctetString | private static function convertIntegerToOctetString($x, $xLen)
{
$x = $x->toBytes();
if (strlen($x) > $xLen) {
return false;
}
return str_pad($x, $xLen, chr(0), STR_PAD_LEFT);
} | php | private static function convertIntegerToOctetString($x, $xLen)
{
$x = $x->toBytes();
if (strlen($x) > $xLen) {
return false;
}
return str_pad($x, $xLen, chr(0), STR_PAD_LEFT);
} | [
"private",
"static",
"function",
"convertIntegerToOctetString",
"(",
"$",
"x",
",",
"$",
"xLen",
")",
"{",
"$",
"x",
"=",
"$",
"x",
"->",
"toBytes",
"(",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"x",
")",
">",
"$",
"xLen",
")",
"{",
"return",
"fa... | Integer-to-Octet-String primitive.
@param \Jose\Util\BigInteger $x
@param int $xLen
@return string | [
"Integer",
"-",
"to",
"-",
"Octet",
"-",
"String",
"primitive",
"."
] | d2ba9ba5a5cc66ca22edc07c2e9190ec6c7664e2 | https://github.com/Spomky-Labs/jose/blob/d2ba9ba5a5cc66ca22edc07c2e9190ec6c7664e2/src/Util/RSA.php#L27-L35 | train |
Spomky-Labs/jose | src/Util/RSA.php | RSA.getRSASP1 | private static function getRSASP1(RSAKey $key, BigInteger $m)
{
if ($m->compare(BigInteger::createFromDecimal(0)) < 0 || $m->compare($key->getModulus()) > 0) {
return false;
}
return self::exponentiate($key, $m);
} | php | private static function getRSASP1(RSAKey $key, BigInteger $m)
{
if ($m->compare(BigInteger::createFromDecimal(0)) < 0 || $m->compare($key->getModulus()) > 0) {
return false;
}
return self::exponentiate($key, $m);
} | [
"private",
"static",
"function",
"getRSASP1",
"(",
"RSAKey",
"$",
"key",
",",
"BigInteger",
"$",
"m",
")",
"{",
"if",
"(",
"$",
"m",
"->",
"compare",
"(",
"BigInteger",
"::",
"createFromDecimal",
"(",
"0",
")",
")",
"<",
"0",
"||",
"$",
"m",
"->",
... | RSA SP1.
@param \Jose\KeyConverter\RSAKey $key
@param \Jose\Util\BigInteger $m
@return \Jose\Util\BigInteger|false | [
"RSA",
"SP1",
"."
] | d2ba9ba5a5cc66ca22edc07c2e9190ec6c7664e2 | https://github.com/Spomky-Labs/jose/blob/d2ba9ba5a5cc66ca22edc07c2e9190ec6c7664e2/src/Util/RSA.php#L120-L127 | train |
Spomky-Labs/jose | src/KeyConverter/KeyConverter.php | KeyConverter.sanitizePEM | private static function sanitizePEM(&$pem)
{
preg_match_all('#(-.*-)#', $pem, $matches, PREG_PATTERN_ORDER);
$ciphertext = preg_replace('#-.*-|\r|\n| #', '', $pem);
$pem = $matches[0][0].PHP_EOL;
$pem .= chunk_split($ciphertext, 64, PHP_EOL);
$pem .= $matches[0][1].PHP_EOL;
} | php | private static function sanitizePEM(&$pem)
{
preg_match_all('#(-.*-)#', $pem, $matches, PREG_PATTERN_ORDER);
$ciphertext = preg_replace('#-.*-|\r|\n| #', '', $pem);
$pem = $matches[0][0].PHP_EOL;
$pem .= chunk_split($ciphertext, 64, PHP_EOL);
$pem .= $matches[0][1].PHP_EOL;
} | [
"private",
"static",
"function",
"sanitizePEM",
"(",
"&",
"$",
"pem",
")",
"{",
"preg_match_all",
"(",
"'#(-.*-)#'",
",",
"$",
"pem",
",",
"$",
"matches",
",",
"PREG_PATTERN_ORDER",
")",
";",
"$",
"ciphertext",
"=",
"preg_replace",
"(",
"'#-.*-|\\r|\\n| #'",
... | This method modify the PEM to get 64 char lines and fix bug with old OpenSSL versions.
@param string $pem | [
"This",
"method",
"modify",
"the",
"PEM",
"to",
"get",
"64",
"char",
"lines",
"and",
"fix",
"bug",
"with",
"old",
"OpenSSL",
"versions",
"."
] | d2ba9ba5a5cc66ca22edc07c2e9190ec6c7664e2 | https://github.com/Spomky-Labs/jose/blob/d2ba9ba5a5cc66ca22edc07c2e9190ec6c7664e2/src/KeyConverter/KeyConverter.php#L184-L192 | train |
Spomky-Labs/jose | src/Util/BigInteger.php | BigInteger.multiply | public function multiply(self $x)
{
$value = gmp_mul($this->value, $x->value);
return self::createFromGMPResource($value);
} | php | public function multiply(self $x)
{
$value = gmp_mul($this->value, $x->value);
return self::createFromGMPResource($value);
} | [
"public",
"function",
"multiply",
"(",
"self",
"$",
"x",
")",
"{",
"$",
"value",
"=",
"gmp_mul",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"x",
"->",
"value",
")",
";",
"return",
"self",
"::",
"createFromGMPResource",
"(",
"$",
"value",
")",
";",
... | Multiplies two BigIntegers.
@param BigInteger $x
@return BigInteger | [
"Multiplies",
"two",
"BigIntegers",
"."
] | d2ba9ba5a5cc66ca22edc07c2e9190ec6c7664e2 | https://github.com/Spomky-Labs/jose/blob/d2ba9ba5a5cc66ca22edc07c2e9190ec6c7664e2/src/Util/BigInteger.php#L160-L165 | train |
Spomky-Labs/jose | src/Object/StorableJWKSet.php | StorableJWKSet.createNewObject | protected function createNewObject()
{
$jwkset = new JWKSet();
for ($i = 0; $i < $this->nb_keys; ++$i) {
$key = $this->createJWK();
$jwkset->addKey($key);
}
return $jwkset;
} | php | protected function createNewObject()
{
$jwkset = new JWKSet();
for ($i = 0; $i < $this->nb_keys; ++$i) {
$key = $this->createJWK();
$jwkset->addKey($key);
}
return $jwkset;
} | [
"protected",
"function",
"createNewObject",
"(",
")",
"{",
"$",
"jwkset",
"=",
"new",
"JWKSet",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"nb_keys",
";",
"++",
"$",
"i",
")",
"{",
"$",
"key",
"=",
"... | This method creates the JWKSet and populate it with keys. | [
"This",
"method",
"creates",
"the",
"JWKSet",
"and",
"populate",
"it",
"with",
"keys",
"."
] | d2ba9ba5a5cc66ca22edc07c2e9190ec6c7664e2 | https://github.com/Spomky-Labs/jose/blob/d2ba9ba5a5cc66ca22edc07c2e9190ec6c7664e2/src/Object/StorableJWKSet.php#L227-L236 | train |
aacotroneo/laravel-saml2 | src/Aacotroneo/Saml2/Saml2User.php | Saml2User.parseUserAttribute | function parseUserAttribute($samlAttribute = null, $propertyName = null) {
if(empty($samlAttribute)) {
return null;
}
if(empty($propertyName)) {
return $this->getAttribute($samlAttribute);
}
return $this->{$propertyName} = $this->getAttribute($samlAttribute);
} | php | function parseUserAttribute($samlAttribute = null, $propertyName = null) {
if(empty($samlAttribute)) {
return null;
}
if(empty($propertyName)) {
return $this->getAttribute($samlAttribute);
}
return $this->{$propertyName} = $this->getAttribute($samlAttribute);
} | [
"function",
"parseUserAttribute",
"(",
"$",
"samlAttribute",
"=",
"null",
",",
"$",
"propertyName",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"samlAttribute",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"property... | Parses a SAML property and adds this property to this user or returns the value
@param string $samlAttribute
@param string $propertyName
@return array|null | [
"Parses",
"a",
"SAML",
"property",
"and",
"adds",
"this",
"property",
"to",
"this",
"user",
"or",
"returns",
"the",
"value"
] | ecb3606181499826fab155118d3aa6a2fa530750 | https://github.com/aacotroneo/laravel-saml2/blob/ecb3606181499826fab155118d3aa6a2fa530750/src/Aacotroneo/Saml2/Saml2User.php#L92-L101 | train |
aacotroneo/laravel-saml2 | src/Aacotroneo/Saml2/Saml2User.php | Saml2User.parseAttributes | function parseAttributes($attributes = array()) {
foreach($attributes as $propertyName => $samlAttribute) {
$this->parseUserAttribute($samlAttribute, $propertyName);
}
} | php | function parseAttributes($attributes = array()) {
foreach($attributes as $propertyName => $samlAttribute) {
$this->parseUserAttribute($samlAttribute, $propertyName);
}
} | [
"function",
"parseAttributes",
"(",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"propertyName",
"=>",
"$",
"samlAttribute",
")",
"{",
"$",
"this",
"->",
"parseUserAttribute",
"(",
"$",
"samlAttribute",
... | Parse the saml attributes and adds it to this user
@param array $attributes Array of properties which need to be parsed, like this ['email' => 'urn:oid:0.9.2342.19200300.100.1.3'] | [
"Parse",
"the",
"saml",
"attributes",
"and",
"adds",
"it",
"to",
"this",
"user"
] | ecb3606181499826fab155118d3aa6a2fa530750 | https://github.com/aacotroneo/laravel-saml2/blob/ecb3606181499826fab155118d3aa6a2fa530750/src/Aacotroneo/Saml2/Saml2User.php#L108-L112 | train |
aacotroneo/laravel-saml2 | src/Aacotroneo/Saml2/Saml2Auth.php | Saml2Auth.logout | function logout($returnTo = null, $nameId = null, $sessionIndex = null, $nameIdFormat = null, $stay = false, $nameIdNameQualifier = null)
{
$auth = $this->auth;
return $auth->logout($returnTo, [], $nameId, $sessionIndex, $stay, $nameIdFormat, $nameIdNameQualifier);
} | php | function logout($returnTo = null, $nameId = null, $sessionIndex = null, $nameIdFormat = null, $stay = false, $nameIdNameQualifier = null)
{
$auth = $this->auth;
return $auth->logout($returnTo, [], $nameId, $sessionIndex, $stay, $nameIdFormat, $nameIdNameQualifier);
} | [
"function",
"logout",
"(",
"$",
"returnTo",
"=",
"null",
",",
"$",
"nameId",
"=",
"null",
",",
"$",
"sessionIndex",
"=",
"null",
",",
"$",
"nameIdFormat",
"=",
"null",
",",
"$",
"stay",
"=",
"false",
",",
"$",
"nameIdNameQualifier",
"=",
"null",
")",
... | Initiate a saml2 logout flow. It will close session on all other SSO services. You should close
local session if applicable.
@param string|null $returnTo The target URL the user should be returned to after logout.
@param string|null $nameId The NameID that will be set in the LogoutRequest.
@param string|null $sessionIndex The SessionIndex (taken from the SAML Response in the SSO process).
@param string|null $nameIdFormat The NameID Format will be set in the LogoutRequest.
@param bool $stay True if we want to stay (returns the url string) False to redirect
@param string|null $nameIdNameQualifier The NameID NameQualifier will be set in the LogoutRequest.
@return string|null If $stay is True, it return a string with the SLO URL + LogoutRequest + parameters
@throws OneLogin_Saml2_Error | [
"Initiate",
"a",
"saml2",
"logout",
"flow",
".",
"It",
"will",
"close",
"session",
"on",
"all",
"other",
"SSO",
"services",
".",
"You",
"should",
"close",
"local",
"session",
"if",
"applicable",
"."
] | ecb3606181499826fab155118d3aa6a2fa530750 | https://github.com/aacotroneo/laravel-saml2/blob/ecb3606181499826fab155118d3aa6a2fa530750/src/Aacotroneo/Saml2/Saml2Auth.php#L91-L96 | train |
aacotroneo/laravel-saml2 | src/Aacotroneo/Saml2/Saml2Auth.php | Saml2Auth.getMetadata | function getMetadata()
{
$auth = $this->auth;
$settings = $auth->getSettings();
$metadata = $settings->getSPMetadata();
$errors = $settings->validateMetadata($metadata);
if (empty($errors)) {
return $metadata;
} else {
throw new InvalidArgumentException(
'Invalid SP metadata: ' . implode(', ', $errors),
OneLogin_Saml2_Error::METADATA_SP_INVALID
);
}
} | php | function getMetadata()
{
$auth = $this->auth;
$settings = $auth->getSettings();
$metadata = $settings->getSPMetadata();
$errors = $settings->validateMetadata($metadata);
if (empty($errors)) {
return $metadata;
} else {
throw new InvalidArgumentException(
'Invalid SP metadata: ' . implode(', ', $errors),
OneLogin_Saml2_Error::METADATA_SP_INVALID
);
}
} | [
"function",
"getMetadata",
"(",
")",
"{",
"$",
"auth",
"=",
"$",
"this",
"->",
"auth",
";",
"$",
"settings",
"=",
"$",
"auth",
"->",
"getSettings",
"(",
")",
";",
"$",
"metadata",
"=",
"$",
"settings",
"->",
"getSPMetadata",
"(",
")",
";",
"$",
"er... | Show metadata about the local sp. Use this to configure your saml2 IDP
@return mixed xml string representing metadata
@throws \InvalidArgumentException if metadata is not correctly set | [
"Show",
"metadata",
"about",
"the",
"local",
"sp",
".",
"Use",
"this",
"to",
"configure",
"your",
"saml2",
"IDP"
] | ecb3606181499826fab155118d3aa6a2fa530750 | https://github.com/aacotroneo/laravel-saml2/blob/ecb3606181499826fab155118d3aa6a2fa530750/src/Aacotroneo/Saml2/Saml2Auth.php#L150-L167 | train |
aacotroneo/laravel-saml2 | src/Aacotroneo/Saml2/Http/Controllers/Saml2Controller.php | Saml2Controller.acs | public function acs()
{
$errors = $this->saml2Auth->acs();
if (!empty($errors)) {
logger()->error('Saml2 error_detail', ['error' => $this->saml2Auth->getLastErrorReason()]);
session()->flash('saml2_error_detail', [$this->saml2Auth->getLastErrorReason()]);
logger()->error('Saml2 error', $errors);
session()->flash('saml2_error', $errors);
return redirect(config('saml2_settings.errorRoute'));
}
$user = $this->saml2Auth->getSaml2User();
event(new Saml2LoginEvent($user, $this->saml2Auth));
$redirectUrl = $user->getIntendedUrl();
if ($redirectUrl !== null) {
return redirect($redirectUrl);
} else {
return redirect(config('saml2_settings.loginRoute'));
}
} | php | public function acs()
{
$errors = $this->saml2Auth->acs();
if (!empty($errors)) {
logger()->error('Saml2 error_detail', ['error' => $this->saml2Auth->getLastErrorReason()]);
session()->flash('saml2_error_detail', [$this->saml2Auth->getLastErrorReason()]);
logger()->error('Saml2 error', $errors);
session()->flash('saml2_error', $errors);
return redirect(config('saml2_settings.errorRoute'));
}
$user = $this->saml2Auth->getSaml2User();
event(new Saml2LoginEvent($user, $this->saml2Auth));
$redirectUrl = $user->getIntendedUrl();
if ($redirectUrl !== null) {
return redirect($redirectUrl);
} else {
return redirect(config('saml2_settings.loginRoute'));
}
} | [
"public",
"function",
"acs",
"(",
")",
"{",
"$",
"errors",
"=",
"$",
"this",
"->",
"saml2Auth",
"->",
"acs",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"errors",
")",
")",
"{",
"logger",
"(",
")",
"->",
"error",
"(",
"'Saml2 error_detail'",
... | Process an incoming saml2 assertion request.
Fires 'Saml2LoginEvent' event if a valid user is Found | [
"Process",
"an",
"incoming",
"saml2",
"assertion",
"request",
".",
"Fires",
"Saml2LoginEvent",
"event",
"if",
"a",
"valid",
"user",
"is",
"Found"
] | ecb3606181499826fab155118d3aa6a2fa530750 | https://github.com/aacotroneo/laravel-saml2/blob/ecb3606181499826fab155118d3aa6a2fa530750/src/Aacotroneo/Saml2/Http/Controllers/Saml2Controller.php#L41-L65 | train |
aacotroneo/laravel-saml2 | src/Aacotroneo/Saml2/Http/Controllers/Saml2Controller.php | Saml2Controller.sls | public function sls()
{
$error = $this->saml2Auth->sls(config('saml2_settings.retrieveParametersFromServer'));
if (!empty($error)) {
throw new \Exception("Could not log out");
}
return redirect(config('saml2_settings.logoutRoute')); //may be set a configurable default
} | php | public function sls()
{
$error = $this->saml2Auth->sls(config('saml2_settings.retrieveParametersFromServer'));
if (!empty($error)) {
throw new \Exception("Could not log out");
}
return redirect(config('saml2_settings.logoutRoute')); //may be set a configurable default
} | [
"public",
"function",
"sls",
"(",
")",
"{",
"$",
"error",
"=",
"$",
"this",
"->",
"saml2Auth",
"->",
"sls",
"(",
"config",
"(",
"'saml2_settings.retrieveParametersFromServer'",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"error",
")",
")",
"{",
"... | Process an incoming saml2 logout request.
Fires 'Saml2LogoutEvent' event if its valid.
This means the user logged out of the SSO infrastructure, you 'should' log him out locally too. | [
"Process",
"an",
"incoming",
"saml2",
"logout",
"request",
".",
"Fires",
"Saml2LogoutEvent",
"event",
"if",
"its",
"valid",
".",
"This",
"means",
"the",
"user",
"logged",
"out",
"of",
"the",
"SSO",
"infrastructure",
"you",
"should",
"log",
"him",
"out",
"loc... | ecb3606181499826fab155118d3aa6a2fa530750 | https://github.com/aacotroneo/laravel-saml2/blob/ecb3606181499826fab155118d3aa6a2fa530750/src/Aacotroneo/Saml2/Http/Controllers/Saml2Controller.php#L72-L80 | train |
aacotroneo/laravel-saml2 | src/Aacotroneo/Saml2/Http/Controllers/Saml2Controller.php | Saml2Controller.logout | public function logout(Request $request)
{
$returnTo = $request->query('returnTo');
$sessionIndex = $request->query('sessionIndex');
$nameId = $request->query('nameId');
$this->saml2Auth->logout($returnTo, $nameId, $sessionIndex); //will actually end up in the sls endpoint
//does not return
} | php | public function logout(Request $request)
{
$returnTo = $request->query('returnTo');
$sessionIndex = $request->query('sessionIndex');
$nameId = $request->query('nameId');
$this->saml2Auth->logout($returnTo, $nameId, $sessionIndex); //will actually end up in the sls endpoint
//does not return
} | [
"public",
"function",
"logout",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"returnTo",
"=",
"$",
"request",
"->",
"query",
"(",
"'returnTo'",
")",
";",
"$",
"sessionIndex",
"=",
"$",
"request",
"->",
"query",
"(",
"'sessionIndex'",
")",
";",
"$",
"... | This initiates a logout request across all the SSO infrastructure. | [
"This",
"initiates",
"a",
"logout",
"request",
"across",
"all",
"the",
"SSO",
"infrastructure",
"."
] | ecb3606181499826fab155118d3aa6a2fa530750 | https://github.com/aacotroneo/laravel-saml2/blob/ecb3606181499826fab155118d3aa6a2fa530750/src/Aacotroneo/Saml2/Http/Controllers/Saml2Controller.php#L85-L92 | train |
johnbillion/extended-cpts | src/class-extended-cpt.php | Extended_CPT.maybe_filter | public function maybe_filter( WP_Query $wp_query ) {
if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->post_type, (array) $wp_query->query['post_type'], true ) ) {
return;
}
$vars = self::get_filter_vars( $wp_query->query, $this->args['site_filters'] );
if ( empty( $vars ) ) {
return;
}
foreach ( $vars as $key => $value ) {
if ( is_array( $value ) ) {
$query = $wp_query->get( $key );
if ( empty( $query ) ) {
$query = [];
}
$value = array_merge( $query, $value );
}
$wp_query->set( $key, $value );
}
} | php | public function maybe_filter( WP_Query $wp_query ) {
if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->post_type, (array) $wp_query->query['post_type'], true ) ) {
return;
}
$vars = self::get_filter_vars( $wp_query->query, $this->args['site_filters'] );
if ( empty( $vars ) ) {
return;
}
foreach ( $vars as $key => $value ) {
if ( is_array( $value ) ) {
$query = $wp_query->get( $key );
if ( empty( $query ) ) {
$query = [];
}
$value = array_merge( $query, $value );
}
$wp_query->set( $key, $value );
}
} | [
"public",
"function",
"maybe_filter",
"(",
"WP_Query",
"$",
"wp_query",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"wp_query",
"->",
"query",
"[",
"'post_type'",
"]",
")",
"||",
"!",
"in_array",
"(",
"$",
"this",
"->",
"post_type",
",",
"(",
"array",
")",... | Set the relevant query vars for filtering posts by our front-end filters.
@param WP_Query $wp_query The current WP_Query object. | [
"Set",
"the",
"relevant",
"query",
"vars",
"for",
"filtering",
"posts",
"by",
"our",
"front",
"-",
"end",
"filters",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt.php#L227-L250 | train |
johnbillion/extended-cpts | src/class-extended-cpt.php | Extended_CPT.maybe_sort_by_fields | public function maybe_sort_by_fields( WP_Query $wp_query ) {
if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->post_type, (array) $wp_query->query['post_type'], true ) ) {
return;
}
// If we've not specified an order:
if ( empty( $wp_query->query['orderby'] ) ) {
// Loop over our sortables to find the default sort field (if there is one):
foreach ( $this->args['site_sortables'] as $id => $col ) {
if ( is_array( $col ) && isset( $col['default'] ) ) {
// @TODO Don't set 'order' if 'orderby' is an array (WP 4.0+)
$wp_query->query['orderby'] = $id;
$wp_query->query['order'] = ( 'desc' === strtolower( $col['default'] ) ? 'desc' : 'asc' );
break;
}
}
}
$sort = self::get_sort_field_vars( $wp_query->query, $this->args['site_sortables'] );
if ( empty( $sort ) ) {
return;
}
foreach ( $sort as $key => $value ) {
$wp_query->set( $key, $value );
}
} | php | public function maybe_sort_by_fields( WP_Query $wp_query ) {
if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->post_type, (array) $wp_query->query['post_type'], true ) ) {
return;
}
// If we've not specified an order:
if ( empty( $wp_query->query['orderby'] ) ) {
// Loop over our sortables to find the default sort field (if there is one):
foreach ( $this->args['site_sortables'] as $id => $col ) {
if ( is_array( $col ) && isset( $col['default'] ) ) {
// @TODO Don't set 'order' if 'orderby' is an array (WP 4.0+)
$wp_query->query['orderby'] = $id;
$wp_query->query['order'] = ( 'desc' === strtolower( $col['default'] ) ? 'desc' : 'asc' );
break;
}
}
}
$sort = self::get_sort_field_vars( $wp_query->query, $this->args['site_sortables'] );
if ( empty( $sort ) ) {
return;
}
foreach ( $sort as $key => $value ) {
$wp_query->set( $key, $value );
}
} | [
"public",
"function",
"maybe_sort_by_fields",
"(",
"WP_Query",
"$",
"wp_query",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"wp_query",
"->",
"query",
"[",
"'post_type'",
"]",
")",
"||",
"!",
"in_array",
"(",
"$",
"this",
"->",
"post_type",
",",
"(",
"array"... | Set the relevant query vars for sorting posts by our front-end sortables.
@param WP_Query $wp_query The current WP_Query object. | [
"Set",
"the",
"relevant",
"query",
"vars",
"for",
"sorting",
"posts",
"by",
"our",
"front",
"-",
"end",
"sortables",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt.php#L257-L287 | train |
johnbillion/extended-cpts | src/class-extended-cpt.php | Extended_CPT.maybe_sort_by_taxonomy | public function maybe_sort_by_taxonomy( array $clauses, WP_Query $wp_query ) : array {
if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->post_type, (array) $wp_query->query['post_type'], true ) ) {
return $clauses;
}
$sort = self::get_sort_taxonomy_clauses( $clauses, $wp_query->query, $this->args['site_sortables'] );
if ( empty( $sort ) ) {
return $clauses;
}
return array_merge( $clauses, $sort );
} | php | public function maybe_sort_by_taxonomy( array $clauses, WP_Query $wp_query ) : array {
if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->post_type, (array) $wp_query->query['post_type'], true ) ) {
return $clauses;
}
$sort = self::get_sort_taxonomy_clauses( $clauses, $wp_query->query, $this->args['site_sortables'] );
if ( empty( $sort ) ) {
return $clauses;
}
return array_merge( $clauses, $sort );
} | [
"public",
"function",
"maybe_sort_by_taxonomy",
"(",
"array",
"$",
"clauses",
",",
"WP_Query",
"$",
"wp_query",
")",
":",
"array",
"{",
"if",
"(",
"empty",
"(",
"$",
"wp_query",
"->",
"query",
"[",
"'post_type'",
"]",
")",
"||",
"!",
"in_array",
"(",
"$"... | Filter the query's SQL clauses so we can sort posts by taxonomy terms.
@param array $clauses The current query's SQL clauses.
@param WP_Query $wp_query The current `WP_Query` object.
@return array The updated SQL clauses. | [
"Filter",
"the",
"query",
"s",
"SQL",
"clauses",
"so",
"we",
"can",
"sort",
"posts",
"by",
"taxonomy",
"terms",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt.php#L296-L310 | train |
johnbillion/extended-cpts | src/class-extended-cpt.php | Extended_CPT.get_filter_vars | public static function get_filter_vars( array $query, array $filters ) : array {
$return = [];
foreach ( $filters as $filter_key => $filter ) {
if ( ! isset( $query[ $filter_key ] ) || ( '' === $query[ $filter_key ] ) ) {
continue;
}
if ( isset( $filter['cap'] ) && ! current_user_can( $filter['cap'] ) ) {
continue;
}
if ( isset( $filter['meta_key'] ) ) {
$meta_query = [
'key' => $filter['meta_key'],
'value' => wp_unslash( $query[ $filter_key ] ),
];
} elseif ( isset( $filter['meta_search_key'] ) ) {
$meta_query = [
'key' => $filter['meta_search_key'],
'value' => wp_unslash( $query[ $filter_key ] ),
'compare' => 'LIKE',
];
} elseif ( isset( $filter['meta_exists'] ) ) {
$meta_query = [
'key' => wp_unslash( $query[ $filter_key ] ),
'compare' => 'NOT IN',
'value' => [ '', '0', 'false', 'null' ],
];
} else {
continue;
}
if ( isset( $filter['meta_query'] ) ) {
$meta_query = array_merge( $meta_query, $filter['meta_query'] );
}
if ( ! empty( $meta_query ) ) {
$return['meta_query'][] = $meta_query;
}
}
return $return;
} | php | public static function get_filter_vars( array $query, array $filters ) : array {
$return = [];
foreach ( $filters as $filter_key => $filter ) {
if ( ! isset( $query[ $filter_key ] ) || ( '' === $query[ $filter_key ] ) ) {
continue;
}
if ( isset( $filter['cap'] ) && ! current_user_can( $filter['cap'] ) ) {
continue;
}
if ( isset( $filter['meta_key'] ) ) {
$meta_query = [
'key' => $filter['meta_key'],
'value' => wp_unslash( $query[ $filter_key ] ),
];
} elseif ( isset( $filter['meta_search_key'] ) ) {
$meta_query = [
'key' => $filter['meta_search_key'],
'value' => wp_unslash( $query[ $filter_key ] ),
'compare' => 'LIKE',
];
} elseif ( isset( $filter['meta_exists'] ) ) {
$meta_query = [
'key' => wp_unslash( $query[ $filter_key ] ),
'compare' => 'NOT IN',
'value' => [ '', '0', 'false', 'null' ],
];
} else {
continue;
}
if ( isset( $filter['meta_query'] ) ) {
$meta_query = array_merge( $meta_query, $filter['meta_query'] );
}
if ( ! empty( $meta_query ) ) {
$return['meta_query'][] = $meta_query;
}
}
return $return;
} | [
"public",
"static",
"function",
"get_filter_vars",
"(",
"array",
"$",
"query",
",",
"array",
"$",
"filters",
")",
":",
"array",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"filter_key",
"=>",
"$",
"filter",
")",
... | Get the array of private query vars for the given filters, to apply to the current query in order to filter it by the
given public query vars.
@param array $query The public query vars, usually from `$wp_query->query`.
@param array $filters The filters valid for this query (usually the value of the `admin_filters` or
`site_filters` argument when registering an extended post type).
@return array The list of private query vars to apply to the query. | [
"Get",
"the",
"array",
"of",
"private",
"query",
"vars",
"for",
"the",
"given",
"filters",
"to",
"apply",
"to",
"the",
"current",
"query",
"in",
"order",
"to",
"filter",
"it",
"by",
"the",
"given",
"public",
"query",
"vars",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt.php#L321-L366 | train |
johnbillion/extended-cpts | src/class-extended-cpt.php | Extended_CPT.get_sort_field_vars | public static function get_sort_field_vars( array $vars, array $sortables ) : array {
if ( ! isset( $vars['orderby'] ) ) {
return [];
}
if ( ! is_string( $vars['orderby'] ) ) {
return [];
}
if ( ! isset( $sortables[ $vars['orderby'] ] ) ) {
return [];
}
$orderby = $sortables[ $vars['orderby'] ];
if ( ! is_array( $orderby ) ) {
return [];
}
if ( isset( $orderby['sortable'] ) && ! $orderby['sortable'] ) {
return [];
}
$return = [];
if ( isset( $orderby['meta_key'] ) ) {
$return['meta_key'] = $orderby['meta_key'];
$return['orderby'] = 'meta_value';
// @TODO meta_value_num
} elseif ( isset( $orderby['post_field'] ) ) {
$field = str_replace( 'post_', '', $orderby['post_field'] );
$return['orderby'] = $field;
}
if ( isset( $vars['order'] ) ) {
$return['order'] = $vars['order'];
}
return $return;
} | php | public static function get_sort_field_vars( array $vars, array $sortables ) : array {
if ( ! isset( $vars['orderby'] ) ) {
return [];
}
if ( ! is_string( $vars['orderby'] ) ) {
return [];
}
if ( ! isset( $sortables[ $vars['orderby'] ] ) ) {
return [];
}
$orderby = $sortables[ $vars['orderby'] ];
if ( ! is_array( $orderby ) ) {
return [];
}
if ( isset( $orderby['sortable'] ) && ! $orderby['sortable'] ) {
return [];
}
$return = [];
if ( isset( $orderby['meta_key'] ) ) {
$return['meta_key'] = $orderby['meta_key'];
$return['orderby'] = 'meta_value';
// @TODO meta_value_num
} elseif ( isset( $orderby['post_field'] ) ) {
$field = str_replace( 'post_', '', $orderby['post_field'] );
$return['orderby'] = $field;
}
if ( isset( $vars['order'] ) ) {
$return['order'] = $vars['order'];
}
return $return;
} | [
"public",
"static",
"function",
"get_sort_field_vars",
"(",
"array",
"$",
"vars",
",",
"array",
"$",
"sortables",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"vars",
"[",
"'orderby'",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
... | Get the array of private and public query vars for the given sortables, to apply to the current query in order to
sort it by the requested orderby field.
@param array $vars The public query vars, usually from `$wp_query->query`.
@param array $sortables The sortables valid for this query (usually the value of the `admin_cols` or
`site_sortables` argument when registering an extended post type.
@return array The list of private and public query vars to apply to the query. | [
"Get",
"the",
"array",
"of",
"private",
"and",
"public",
"query",
"vars",
"for",
"the",
"given",
"sortables",
"to",
"apply",
"to",
"the",
"current",
"query",
"in",
"order",
"to",
"sort",
"it",
"by",
"the",
"requested",
"orderby",
"field",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt.php#L377-L415 | train |
johnbillion/extended-cpts | src/class-extended-cpt.php | Extended_CPT.get_sort_taxonomy_clauses | public static function get_sort_taxonomy_clauses( array $clauses, array $vars, array $sortables ) : array {
global $wpdb;
if ( ! isset( $vars['orderby'] ) ) {
return [];
}
if ( ! is_string( $vars['orderby'] ) ) {
return [];
}
if ( ! isset( $sortables[ $vars['orderby'] ] ) ) {
return [];
}
$orderby = $sortables[ $vars['orderby'] ];
if ( ! is_array( $orderby ) ) {
return [];
}
if ( isset( $orderby['sortable'] ) && ! $orderby['sortable'] ) {
return [];
}
if ( ! isset( $orderby['taxonomy'] ) ) {
return [];
}
# Taxonomy term ordering courtesy of http://scribu.net/wordpress/sortable-taxonomy-columns.html
$clauses['join'] .= "
LEFT OUTER JOIN {$wpdb->term_relationships} as ext_cpts_tr
ON ( {$wpdb->posts}.ID = ext_cpts_tr.object_id )
LEFT OUTER JOIN {$wpdb->term_taxonomy} as ext_cpts_tt
ON ( ext_cpts_tr.term_taxonomy_id = ext_cpts_tt.term_taxonomy_id )
LEFT OUTER JOIN {$wpdb->terms} as ext_cpts_t
ON ( ext_cpts_tt.term_id = ext_cpts_t.term_id )
";
$clauses['where'] .= $wpdb->prepare( ' AND ( taxonomy = %s OR taxonomy IS NULL )', $orderby['taxonomy'] );
$clauses['groupby'] = 'ext_cpts_tr.object_id';
$clauses['orderby'] = 'GROUP_CONCAT( ext_cpts_t.name ORDER BY name ASC ) ';
$clauses['orderby'] .= ( isset( $vars['order'] ) && ( 'ASC' === strtoupper( $vars['order'] ) ) ) ? 'ASC' : 'DESC';
return $clauses;
} | php | public static function get_sort_taxonomy_clauses( array $clauses, array $vars, array $sortables ) : array {
global $wpdb;
if ( ! isset( $vars['orderby'] ) ) {
return [];
}
if ( ! is_string( $vars['orderby'] ) ) {
return [];
}
if ( ! isset( $sortables[ $vars['orderby'] ] ) ) {
return [];
}
$orderby = $sortables[ $vars['orderby'] ];
if ( ! is_array( $orderby ) ) {
return [];
}
if ( isset( $orderby['sortable'] ) && ! $orderby['sortable'] ) {
return [];
}
if ( ! isset( $orderby['taxonomy'] ) ) {
return [];
}
# Taxonomy term ordering courtesy of http://scribu.net/wordpress/sortable-taxonomy-columns.html
$clauses['join'] .= "
LEFT OUTER JOIN {$wpdb->term_relationships} as ext_cpts_tr
ON ( {$wpdb->posts}.ID = ext_cpts_tr.object_id )
LEFT OUTER JOIN {$wpdb->term_taxonomy} as ext_cpts_tt
ON ( ext_cpts_tr.term_taxonomy_id = ext_cpts_tt.term_taxonomy_id )
LEFT OUTER JOIN {$wpdb->terms} as ext_cpts_t
ON ( ext_cpts_tt.term_id = ext_cpts_t.term_id )
";
$clauses['where'] .= $wpdb->prepare( ' AND ( taxonomy = %s OR taxonomy IS NULL )', $orderby['taxonomy'] );
$clauses['groupby'] = 'ext_cpts_tr.object_id';
$clauses['orderby'] = 'GROUP_CONCAT( ext_cpts_t.name ORDER BY name ASC ) ';
$clauses['orderby'] .= ( isset( $vars['order'] ) && ( 'ASC' === strtoupper( $vars['order'] ) ) ) ? 'ASC' : 'DESC';
return $clauses;
} | [
"public",
"static",
"function",
"get_sort_taxonomy_clauses",
"(",
"array",
"$",
"clauses",
",",
"array",
"$",
"vars",
",",
"array",
"$",
"sortables",
")",
":",
"array",
"{",
"global",
"$",
"wpdb",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"vars",
"[",
"'... | Get the array of SQL clauses for the given sortables, to apply to the current query in order to
sort it by the requested orderby field.
@param array $clauses The query's SQL clauses.
@param array $vars The public query vars, usually from `$wp_query->query`.
@param array $sortables The sortables valid for this query (usually the value of the `admin_cols` or
`site_sortables` argument when registering an extended post type).
@return array The list of SQL clauses to apply to the query. | [
"Get",
"the",
"array",
"of",
"SQL",
"clauses",
"for",
"the",
"given",
"sortables",
"to",
"apply",
"to",
"the",
"current",
"query",
"in",
"order",
"to",
"sort",
"it",
"by",
"the",
"requested",
"orderby",
"field",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt.php#L427-L469 | train |
johnbillion/extended-cpts | src/class-extended-cpt.php | Extended_CPT.add_to_feed | public function add_to_feed( array $vars ) : array {
# If it's not a feed, we're not interested:
if ( ! isset( $vars['feed'] ) ) {
return $vars;
}
if ( ! isset( $vars['post_type'] ) ) {
$vars['post_type'] = [
'post',
$this->post_type,
];
} elseif ( is_array( $vars['post_type'] ) && ( count( $vars['post_type'] ) > 1 ) ) {
$vars['post_type'][] = $this->post_type;
}
return $vars;
} | php | public function add_to_feed( array $vars ) : array {
# If it's not a feed, we're not interested:
if ( ! isset( $vars['feed'] ) ) {
return $vars;
}
if ( ! isset( $vars['post_type'] ) ) {
$vars['post_type'] = [
'post',
$this->post_type,
];
} elseif ( is_array( $vars['post_type'] ) && ( count( $vars['post_type'] ) > 1 ) ) {
$vars['post_type'][] = $this->post_type;
}
return $vars;
} | [
"public",
"function",
"add_to_feed",
"(",
"array",
"$",
"vars",
")",
":",
"array",
"{",
"# If it's not a feed, we're not interested:",
"if",
"(",
"!",
"isset",
"(",
"$",
"vars",
"[",
"'feed'",
"]",
")",
")",
"{",
"return",
"$",
"vars",
";",
"}",
"if",
"(... | Add our post type to the feed.
@param array $vars Request parameters.
@return array Updated request parameters. | [
"Add",
"our",
"post",
"type",
"to",
"the",
"feed",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt.php#L491-L509 | train |
johnbillion/extended-cpts | src/class-extended-cpt.php | Extended_CPT.override_private_query_vars | public function override_private_query_vars( WP $wp ) : WP {
# If it's not our post type, bail out:
if ( ! isset( $wp->query_vars['post_type'] ) || ( $this->post_type !== $wp->query_vars['post_type'] ) ) {
return $wp;
}
# If it's a single post, bail out:
if ( isset( $wp->query_vars['name'] ) ) {
return $wp;
}
# Set the vars:
foreach ( $this->args['archive'] as $var => $value ) {
$wp->query_vars[ $var ] = $value;
}
return $wp;
} | php | public function override_private_query_vars( WP $wp ) : WP {
# If it's not our post type, bail out:
if ( ! isset( $wp->query_vars['post_type'] ) || ( $this->post_type !== $wp->query_vars['post_type'] ) ) {
return $wp;
}
# If it's a single post, bail out:
if ( isset( $wp->query_vars['name'] ) ) {
return $wp;
}
# Set the vars:
foreach ( $this->args['archive'] as $var => $value ) {
$wp->query_vars[ $var ] = $value;
}
return $wp;
} | [
"public",
"function",
"override_private_query_vars",
"(",
"WP",
"$",
"wp",
")",
":",
"WP",
"{",
"# If it's not our post type, bail out:",
"if",
"(",
"!",
"isset",
"(",
"$",
"wp",
"->",
"query_vars",
"[",
"'post_type'",
"]",
")",
"||",
"(",
"$",
"this",
"->",... | Add to or override our post type archive's private query vars.
@param WP $wp The WP request object.
@return WP Updated WP request object. | [
"Add",
"to",
"or",
"override",
"our",
"post",
"type",
"archive",
"s",
"private",
"query",
"vars",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt.php#L517-L536 | train |
johnbillion/extended-cpts | src/class-extended-cpt.php | Extended_CPT.registered_post_type | public function registered_post_type( string $post_type, WP_Post_Type $post_type_object ) {
if ( $post_type !== $this->post_type ) {
return;
}
$struct = str_replace( "%{$this->post_type}_slug%", $this->post_slug, $post_type_object->rewrite['permastruct'] );
$struct = str_replace( '%postname%', "%{$this->post_type}%", $struct );
add_permastruct( $this->post_type, $struct, $post_type_object->rewrite );
} | php | public function registered_post_type( string $post_type, WP_Post_Type $post_type_object ) {
if ( $post_type !== $this->post_type ) {
return;
}
$struct = str_replace( "%{$this->post_type}_slug%", $this->post_slug, $post_type_object->rewrite['permastruct'] );
$struct = str_replace( '%postname%', "%{$this->post_type}%", $struct );
add_permastruct( $this->post_type, $struct, $post_type_object->rewrite );
} | [
"public",
"function",
"registered_post_type",
"(",
"string",
"$",
"post_type",
",",
"WP_Post_Type",
"$",
"post_type_object",
")",
"{",
"if",
"(",
"$",
"post_type",
"!==",
"$",
"this",
"->",
"post_type",
")",
"{",
"return",
";",
"}",
"$",
"struct",
"=",
"st... | Action fired after a CPT is registered in order to set up the custom permalink structure for the post type.
@param string $post_type Post type name.
@param WP_Post_Type $post_type_object Post type object. | [
"Action",
"fired",
"after",
"a",
"CPT",
"is",
"registered",
"in",
"order",
"to",
"set",
"up",
"the",
"custom",
"permalink",
"structure",
"for",
"the",
"post",
"type",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt.php#L544-L551 | train |
johnbillion/extended-cpts | src/class-extended-cpt.php | Extended_CPT.post_type_link | public function post_type_link( string $post_link, WP_Post $post, bool $leavename, bool $sample ) : string {
# If it's not our post type, bail out:
if ( $this->post_type !== $post->post_type ) {
return $post_link;
}
$date = explode( ' ', mysql2date( 'Y m d H i s', $post->post_date ) );
$replacements = [
'%year%' => $date[0],
'%monthnum%' => $date[1],
'%day%' => $date[2],
'%hour%' => $date[3],
'%minute%' => $date[4],
'%second%' => $date[5],
'%post_id%' => $post->ID,
];
if ( false !== strpos( $post_link, '%author%' ) ) {
$replacements['%author%'] = get_userdata( $post->post_author )->user_nicename;
}
foreach ( get_object_taxonomies( $post ) as $tax ) {
if ( false === strpos( $post_link, "%{$tax}%" ) ) {
continue;
}
$terms = get_the_terms( $post, $tax );
if ( $terms ) {
/**
* Filter the term that gets used in the `$tax` permalink token.
* @TODO make this more betterer ^
*
* @param WP_Term $term The `$tax` term to use in the permalink.
* @param WP_Term[] $terms Array of all `$tax` terms associated with the post.
* @param WP_Post $post The post in question.
*/
$term_object = apply_filters( "post_link_{$tax}", reset( $terms ), $terms, $post );
$term = get_term( $term_object, $tax )->slug;
} else {
$term = $post->post_type;
/**
* Filter the default term name that gets used in the `$tax` permalink token.
* @TODO make this more betterer ^
*
* @param string $term The `$tax` term name to use in the permalink.
* @param WP_Post $post The post in question.
*/
$default_term_name = apply_filters( "default_{$tax}", get_option( "default_{$tax}", '' ), $post );
if ( $default_term_name ) {
$default_term = get_term( $default_term_name, $tax );
if ( ! is_wp_error( $default_term ) ) {
$term = $default_term->slug;
}
}
}
$replacements[ "%{$tax}%" ] = $term;
}
$post_link = str_replace( array_keys( $replacements ), $replacements, $post_link );
return $post_link;
} | php | public function post_type_link( string $post_link, WP_Post $post, bool $leavename, bool $sample ) : string {
# If it's not our post type, bail out:
if ( $this->post_type !== $post->post_type ) {
return $post_link;
}
$date = explode( ' ', mysql2date( 'Y m d H i s', $post->post_date ) );
$replacements = [
'%year%' => $date[0],
'%monthnum%' => $date[1],
'%day%' => $date[2],
'%hour%' => $date[3],
'%minute%' => $date[4],
'%second%' => $date[5],
'%post_id%' => $post->ID,
];
if ( false !== strpos( $post_link, '%author%' ) ) {
$replacements['%author%'] = get_userdata( $post->post_author )->user_nicename;
}
foreach ( get_object_taxonomies( $post ) as $tax ) {
if ( false === strpos( $post_link, "%{$tax}%" ) ) {
continue;
}
$terms = get_the_terms( $post, $tax );
if ( $terms ) {
/**
* Filter the term that gets used in the `$tax` permalink token.
* @TODO make this more betterer ^
*
* @param WP_Term $term The `$tax` term to use in the permalink.
* @param WP_Term[] $terms Array of all `$tax` terms associated with the post.
* @param WP_Post $post The post in question.
*/
$term_object = apply_filters( "post_link_{$tax}", reset( $terms ), $terms, $post );
$term = get_term( $term_object, $tax )->slug;
} else {
$term = $post->post_type;
/**
* Filter the default term name that gets used in the `$tax` permalink token.
* @TODO make this more betterer ^
*
* @param string $term The `$tax` term name to use in the permalink.
* @param WP_Post $post The post in question.
*/
$default_term_name = apply_filters( "default_{$tax}", get_option( "default_{$tax}", '' ), $post );
if ( $default_term_name ) {
$default_term = get_term( $default_term_name, $tax );
if ( ! is_wp_error( $default_term ) ) {
$term = $default_term->slug;
}
}
}
$replacements[ "%{$tax}%" ] = $term;
}
$post_link = str_replace( array_keys( $replacements ), $replacements, $post_link );
return $post_link;
} | [
"public",
"function",
"post_type_link",
"(",
"string",
"$",
"post_link",
",",
"WP_Post",
"$",
"post",
",",
"bool",
"$",
"leavename",
",",
"bool",
"$",
"sample",
")",
":",
"string",
"{",
"# If it's not our post type, bail out:",
"if",
"(",
"$",
"this",
"->",
... | Filter the post type permalink in order to populate its rewrite tags.
@param string $post_link The post's permalink.
@param WP_Post $post The post in question.
@param bool $leavename Whether to keep the post name.
@param bool $sample Is it a sample permalink.
@return string The post's permalink. | [
"Filter",
"the",
"post",
"type",
"permalink",
"in",
"order",
"to",
"populate",
"its",
"rewrite",
"tags",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt.php#L562-L631 | train |
johnbillion/extended-cpts | src/class-extended-cpt.php | Extended_CPT.register_post_type | public function register_post_type() {
if ( ! isset( $this->args['query_var'] ) || ( true === $this->args['query_var'] ) ) {
$query_var = $this->post_type;
} else {
$query_var = $this->args['query_var'];
}
$existing = get_post_type_object( $this->post_type );
$taxonomies = get_taxonomies( [
'query_var' => $query_var,
], 'objects' );
if ( $query_var && count( $taxonomies ) ) {
// https://core.trac.wordpress.org/ticket/35089
foreach ( $taxonomies as $tax ) {
if ( $tax->query_var === $query_var ) {
trigger_error( esc_html( sprintf(
/* translators: %s: Post type query variable name */
__( 'Post type query var "%s" clashes with a taxonomy query var of the same name', 'extended-cpts' ),
$query_var
) ), E_USER_ERROR );
}
}
}
if ( empty( $existing ) ) {
$cpt = register_post_type( $this->post_type, $this->args );
if ( is_wp_error( $cpt ) ) {
trigger_error( esc_html( $cpt->get_error_message() ), E_USER_ERROR );
}
} else {
# This allows us to call `register_extended_post_type()` on an existing post type to add custom functionality
# to the post type.
$this->extend( $existing );
}
} | php | public function register_post_type() {
if ( ! isset( $this->args['query_var'] ) || ( true === $this->args['query_var'] ) ) {
$query_var = $this->post_type;
} else {
$query_var = $this->args['query_var'];
}
$existing = get_post_type_object( $this->post_type );
$taxonomies = get_taxonomies( [
'query_var' => $query_var,
], 'objects' );
if ( $query_var && count( $taxonomies ) ) {
// https://core.trac.wordpress.org/ticket/35089
foreach ( $taxonomies as $tax ) {
if ( $tax->query_var === $query_var ) {
trigger_error( esc_html( sprintf(
/* translators: %s: Post type query variable name */
__( 'Post type query var "%s" clashes with a taxonomy query var of the same name', 'extended-cpts' ),
$query_var
) ), E_USER_ERROR );
}
}
}
if ( empty( $existing ) ) {
$cpt = register_post_type( $this->post_type, $this->args );
if ( is_wp_error( $cpt ) ) {
trigger_error( esc_html( $cpt->get_error_message() ), E_USER_ERROR );
}
} else {
# This allows us to call `register_extended_post_type()` on an existing post type to add custom functionality
# to the post type.
$this->extend( $existing );
}
} | [
"public",
"function",
"register_post_type",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"args",
"[",
"'query_var'",
"]",
")",
"||",
"(",
"true",
"===",
"$",
"this",
"->",
"args",
"[",
"'query_var'",
"]",
")",
")",
"{",
"$",
"que... | Registers our post type.
The only difference between this and regular `register_post_type()` calls is this will trigger an error of
`E_USER_ERROR` level if a `WP_Error` is returned. | [
"Registers",
"our",
"post",
"type",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt.php#L658-L699 | train |
johnbillion/extended-cpts | src/class-extended-cpt.php | Extended_CPT.extend | public function extend( WP_Post_Type $pto ) {
# Merge core with overridden labels
$this->args['labels'] = array_merge( (array) get_post_type_labels( $pto ), $this->args['labels'] );
$GLOBALS['wp_post_types'][ $pto->name ]->labels = (object) $this->args['labels'];
} | php | public function extend( WP_Post_Type $pto ) {
# Merge core with overridden labels
$this->args['labels'] = array_merge( (array) get_post_type_labels( $pto ), $this->args['labels'] );
$GLOBALS['wp_post_types'][ $pto->name ]->labels = (object) $this->args['labels'];
} | [
"public",
"function",
"extend",
"(",
"WP_Post_Type",
"$",
"pto",
")",
"{",
"# Merge core with overridden labels",
"$",
"this",
"->",
"args",
"[",
"'labels'",
"]",
"=",
"array_merge",
"(",
"(",
"array",
")",
"get_post_type_labels",
"(",
"$",
"pto",
")",
",",
... | Extends an existing post type object. Currently only handles labels.
@param WP_Post_Type $pto A post type object. | [
"Extends",
"an",
"existing",
"post",
"type",
"object",
".",
"Currently",
"only",
"handles",
"labels",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt.php#L706-L713 | train |
johnbillion/extended-cpts | src/class-extended-cpt.php | Extended_CPT.add_taxonomy | public function add_taxonomy( string $taxonomy, array $args = [], array $names = [] ) : WP_Taxonomy {
if ( taxonomy_exists( $taxonomy ) ) {
register_taxonomy_for_object_type( $taxonomy, $this->post_type );
} else {
register_extended_taxonomy( $taxonomy, $this->post_type, $args, $names );
}
return get_taxonomy( $taxonomy );
} | php | public function add_taxonomy( string $taxonomy, array $args = [], array $names = [] ) : WP_Taxonomy {
if ( taxonomy_exists( $taxonomy ) ) {
register_taxonomy_for_object_type( $taxonomy, $this->post_type );
} else {
register_extended_taxonomy( $taxonomy, $this->post_type, $args, $names );
}
return get_taxonomy( $taxonomy );
} | [
"public",
"function",
"add_taxonomy",
"(",
"string",
"$",
"taxonomy",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"names",
"=",
"[",
"]",
")",
":",
"WP_Taxonomy",
"{",
"if",
"(",
"taxonomy_exists",
"(",
"$",
"taxonomy",
")",
")",
"{"... | Helper function for registering a taxonomy and adding it to this post type.
Accepts the same parameters as `register_extended_taxonomy()`, minus the `$object_type` parameter.
Example usage:
$events = register_extended_post_type( 'event' );
$location = $events->add_taxonomy( 'location' );
@param string $taxonomy The taxonomy name.
@param array $args Optional. The taxonomy arguments.
@param array $names Optional. An associative array of the plural, singular, and slug names.
@return WP_Taxonomy Taxonomy object. | [
"Helper",
"function",
"for",
"registering",
"a",
"taxonomy",
"and",
"adding",
"it",
"to",
"this",
"post",
"type",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt.php#L730-L740 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.admin_head | public function admin_head() {
if ( self::get_current_post_type() !== $this->cpt->post_type ) {
return;
}
?>
<?php if ( isset( $this->args['admin_filters']['m'] ) && ! $this->args['admin_filters']['m'] ) { ?>
<style type="text/css">
#posts-filter select[name="m"] {
display: none;
}
</style>
<?php } ?>
<?php
} | php | public function admin_head() {
if ( self::get_current_post_type() !== $this->cpt->post_type ) {
return;
}
?>
<?php if ( isset( $this->args['admin_filters']['m'] ) && ! $this->args['admin_filters']['m'] ) { ?>
<style type="text/css">
#posts-filter select[name="m"] {
display: none;
}
</style>
<?php } ?>
<?php
} | [
"public",
"function",
"admin_head",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"get_current_post_type",
"(",
")",
"!==",
"$",
"this",
"->",
"cpt",
"->",
"post_type",
")",
"{",
"return",
";",
"}",
"?>\n\t\t<?php",
"if",
"(",
"isset",
"(",
"$",
"this",
"->"... | Add some CSS to the post listing screen. Used to hide various screen elements. | [
"Add",
"some",
"CSS",
"to",
"the",
"post",
"listing",
"screen",
".",
"Used",
"to",
"hide",
"various",
"screen",
"elements",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L86-L102 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.default_sort | public function default_sort() {
if ( self::get_current_post_type() !== $this->cpt->post_type ) {
return;
}
# If we've already ordered the screen, bail out:
if ( isset( $_GET['orderby'] ) ) {
return;
}
# Loop over our columns to find the default sort column (if there is one):
foreach ( $this->args['admin_cols'] as $id => $col ) {
if ( is_array( $col ) && isset( $col['default'] ) ) {
$_GET['orderby'] = $id;
$_GET['order'] = ( 'desc' === strtolower( $col['default'] ) ? 'desc' : 'asc' );
break;
}
}
} | php | public function default_sort() {
if ( self::get_current_post_type() !== $this->cpt->post_type ) {
return;
}
# If we've already ordered the screen, bail out:
if ( isset( $_GET['orderby'] ) ) {
return;
}
# Loop over our columns to find the default sort column (if there is one):
foreach ( $this->args['admin_cols'] as $id => $col ) {
if ( is_array( $col ) && isset( $col['default'] ) ) {
$_GET['orderby'] = $id;
$_GET['order'] = ( 'desc' === strtolower( $col['default'] ) ? 'desc' : 'asc' );
break;
}
}
} | [
"public",
"function",
"default_sort",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"get_current_post_type",
"(",
")",
"!==",
"$",
"this",
"->",
"cpt",
"->",
"post_type",
")",
"{",
"return",
";",
"}",
"# If we've already ordered the screen, bail out:",
"if",
"(",
"i... | Set the default sort field and sort order on our post type admin screen. | [
"Set",
"the",
"default",
"sort",
"field",
"and",
"sort",
"order",
"on",
"our",
"post",
"type",
"admin",
"screen",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L107-L127 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.enter_title_here | public function enter_title_here( string $title, WP_Post $post ) : string {
if ( $this->cpt->post_type !== $post->post_type ) {
return $title;
}
return $this->args['enter_title_here'];
} | php | public function enter_title_here( string $title, WP_Post $post ) : string {
if ( $this->cpt->post_type !== $post->post_type ) {
return $title;
}
return $this->args['enter_title_here'];
} | [
"public",
"function",
"enter_title_here",
"(",
"string",
"$",
"title",
",",
"WP_Post",
"$",
"post",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"cpt",
"->",
"post_type",
"!==",
"$",
"post",
"->",
"post_type",
")",
"{",
"return",
"$",
"title"... | Set the placeholder text for the title field for this post type.
@param string $title The placeholder text.
@param WP_Post $post The current post.
@return string The updated placeholder text. | [
"Set",
"the",
"placeholder",
"text",
"for",
"the",
"title",
"field",
"for",
"this",
"post",
"type",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L136-L144 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.maybe_sort_by_fields | public function maybe_sort_by_fields( WP_Query $wp_query ) {
if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->cpt->post_type, (array) $wp_query->query['post_type'], true ) ) {
return;
}
$sort = Extended_CPT::get_sort_field_vars( $wp_query->query, $this->cpt->args['admin_cols'] );
if ( empty( $sort ) ) {
return;
}
foreach ( $sort as $key => $value ) {
$wp_query->set( $key, $value );
}
} | php | public function maybe_sort_by_fields( WP_Query $wp_query ) {
if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->cpt->post_type, (array) $wp_query->query['post_type'], true ) ) {
return;
}
$sort = Extended_CPT::get_sort_field_vars( $wp_query->query, $this->cpt->args['admin_cols'] );
if ( empty( $sort ) ) {
return;
}
foreach ( $sort as $key => $value ) {
$wp_query->set( $key, $value );
}
} | [
"public",
"function",
"maybe_sort_by_fields",
"(",
"WP_Query",
"$",
"wp_query",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"wp_query",
"->",
"query",
"[",
"'post_type'",
"]",
")",
"||",
"!",
"in_array",
"(",
"$",
"this",
"->",
"cpt",
"->",
"post_type",
",",... | Set the relevant query vars for sorting posts by our admin sortables.
@param WP_Query $wp_query The current `WP_Query` object. | [
"Set",
"the",
"relevant",
"query",
"vars",
"for",
"sorting",
"posts",
"by",
"our",
"admin",
"sortables",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L377-L393 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.glance_items | public function glance_items( array $items ) : array {
$pto = get_post_type_object( $this->cpt->post_type );
if ( ! current_user_can( $pto->cap->edit_posts ) ) {
return $items;
}
if ( $pto->_builtin ) {
return $items;
}
# Get the labels and format the counts:
$count = wp_count_posts( $this->cpt->post_type );
$text = self::n( $pto->labels->singular_name, $pto->labels->name, (int) $count->publish );
$num = number_format_i18n( $count->publish );
# This is absolutely not localisable. WordPress 3.8 didn't add a new post type label.
$url = add_query_arg( [
'post_type' => $this->cpt->post_type,
], admin_url( 'edit.php' ) );
$text = '<a href="' . esc_url( $url ) . '" class="cpt-' . esc_attr( $this->cpt->post_type ) . '-count">' . esc_html( $num . ' ' . $text ) . '</a>';
# Go!
$items[] = $text;
return $items;
} | php | public function glance_items( array $items ) : array {
$pto = get_post_type_object( $this->cpt->post_type );
if ( ! current_user_can( $pto->cap->edit_posts ) ) {
return $items;
}
if ( $pto->_builtin ) {
return $items;
}
# Get the labels and format the counts:
$count = wp_count_posts( $this->cpt->post_type );
$text = self::n( $pto->labels->singular_name, $pto->labels->name, (int) $count->publish );
$num = number_format_i18n( $count->publish );
# This is absolutely not localisable. WordPress 3.8 didn't add a new post type label.
$url = add_query_arg( [
'post_type' => $this->cpt->post_type,
], admin_url( 'edit.php' ) );
$text = '<a href="' . esc_url( $url ) . '" class="cpt-' . esc_attr( $this->cpt->post_type ) . '-count">' . esc_html( $num . ' ' . $text ) . '</a>';
# Go!
$items[] = $text;
return $items;
} | [
"public",
"function",
"glance_items",
"(",
"array",
"$",
"items",
")",
":",
"array",
"{",
"$",
"pto",
"=",
"get_post_type_object",
"(",
"$",
"this",
"->",
"cpt",
"->",
"post_type",
")",
";",
"if",
"(",
"!",
"current_user_can",
"(",
"$",
"pto",
"->",
"c... | Add our post type to the 'At a Glance' widget on the WordPress 3.8+ dashboard.
@param array $items Array of items to display on the widget.
@return array Updated array of items. | [
"Add",
"our",
"post",
"type",
"to",
"the",
"At",
"a",
"Glance",
"widget",
"on",
"the",
"WordPress",
"3",
".",
"8",
"+",
"dashboard",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L424-L451 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.post_updated_messages | public function post_updated_messages( array $messages ) : array {
global $post;
$pto = get_post_type_object( $this->cpt->post_type );
$messages[ $this->cpt->post_type ] = [
1 => sprintf(
( $pto->publicly_queryable ? '%1$s updated. <a href="%2$s">View %3$s</a>' : '%1$s updated.' ),
esc_html( $this->cpt->post_singular ),
esc_url( get_permalink( $post ) ),
esc_html( $this->cpt->post_singular_low )
),
2 => 'Custom field updated.',
3 => 'Custom field deleted.',
4 => sprintf(
'%s updated.',
esc_html( $this->cpt->post_singular )
),
5 => isset( $_GET['revision'] ) ? sprintf(
'%1$s restored to revision from %2$s',
esc_html( $this->cpt->post_singular ),
wp_post_revision_title( intval( $_GET['revision'] ), false )
) : false,
6 => sprintf(
( $pto->publicly_queryable ? '%1$s published. <a href="%2$s">View %3$s</a>' : '%1$s published.' ),
esc_html( $this->cpt->post_singular ),
esc_url( get_permalink( $post ) ),
esc_html( $this->cpt->post_singular_low )
),
7 => sprintf(
'%s saved.',
esc_html( $this->cpt->post_singular )
),
8 => sprintf(
( $pto->publicly_queryable ? '%1$s submitted. <a target="_blank" href="%2$s">Preview %3$s</a>' : '%1$s submitted.' ),
esc_html( $this->cpt->post_singular ),
esc_url( add_query_arg( 'preview', 'true', get_permalink( $post ) ) ),
esc_html( $this->cpt->post_singular_low )
),
9 => sprintf(
( $pto->publicly_queryable ? '%1$s scheduled for: <strong>%2$s</strong>. <a target="_blank" href="%3$s">Preview %4$s</a>' : '%1$s scheduled for: <strong>%2$s</strong>.' ),
esc_html( $this->cpt->post_singular ),
esc_html( date_i18n( 'M j, Y @ G:i', strtotime( $post->post_date ) ) ),
esc_url( get_permalink( $post ) ),
esc_html( $this->cpt->post_singular_low )
),
10 => sprintf(
( $pto->publicly_queryable ? '%1$s draft updated. <a target="_blank" href="%2$s">Preview %3$s</a>' : '%1$s draft updated.' ),
esc_html( $this->cpt->post_singular ),
esc_url( add_query_arg( 'preview', 'true', get_permalink( $post ) ) ),
esc_html( $this->cpt->post_singular_low )
),
];
return $messages;
} | php | public function post_updated_messages( array $messages ) : array {
global $post;
$pto = get_post_type_object( $this->cpt->post_type );
$messages[ $this->cpt->post_type ] = [
1 => sprintf(
( $pto->publicly_queryable ? '%1$s updated. <a href="%2$s">View %3$s</a>' : '%1$s updated.' ),
esc_html( $this->cpt->post_singular ),
esc_url( get_permalink( $post ) ),
esc_html( $this->cpt->post_singular_low )
),
2 => 'Custom field updated.',
3 => 'Custom field deleted.',
4 => sprintf(
'%s updated.',
esc_html( $this->cpt->post_singular )
),
5 => isset( $_GET['revision'] ) ? sprintf(
'%1$s restored to revision from %2$s',
esc_html( $this->cpt->post_singular ),
wp_post_revision_title( intval( $_GET['revision'] ), false )
) : false,
6 => sprintf(
( $pto->publicly_queryable ? '%1$s published. <a href="%2$s">View %3$s</a>' : '%1$s published.' ),
esc_html( $this->cpt->post_singular ),
esc_url( get_permalink( $post ) ),
esc_html( $this->cpt->post_singular_low )
),
7 => sprintf(
'%s saved.',
esc_html( $this->cpt->post_singular )
),
8 => sprintf(
( $pto->publicly_queryable ? '%1$s submitted. <a target="_blank" href="%2$s">Preview %3$s</a>' : '%1$s submitted.' ),
esc_html( $this->cpt->post_singular ),
esc_url( add_query_arg( 'preview', 'true', get_permalink( $post ) ) ),
esc_html( $this->cpt->post_singular_low )
),
9 => sprintf(
( $pto->publicly_queryable ? '%1$s scheduled for: <strong>%2$s</strong>. <a target="_blank" href="%3$s">Preview %4$s</a>' : '%1$s scheduled for: <strong>%2$s</strong>.' ),
esc_html( $this->cpt->post_singular ),
esc_html( date_i18n( 'M j, Y @ G:i', strtotime( $post->post_date ) ) ),
esc_url( get_permalink( $post ) ),
esc_html( $this->cpt->post_singular_low )
),
10 => sprintf(
( $pto->publicly_queryable ? '%1$s draft updated. <a target="_blank" href="%2$s">Preview %3$s</a>' : '%1$s draft updated.' ),
esc_html( $this->cpt->post_singular ),
esc_url( add_query_arg( 'preview', 'true', get_permalink( $post ) ) ),
esc_html( $this->cpt->post_singular_low )
),
];
return $messages;
} | [
"public",
"function",
"post_updated_messages",
"(",
"array",
"$",
"messages",
")",
":",
"array",
"{",
"global",
"$",
"post",
";",
"$",
"pto",
"=",
"get_post_type_object",
"(",
"$",
"this",
"->",
"cpt",
"->",
"post_type",
")",
";",
"$",
"messages",
"[",
"... | Add our post type updated messages.
The messages are as follows:
1 => "Post updated. {View Post}"
2 => "Custom field updated."
3 => "Custom field deleted."
4 => "Post updated."
5 => "Post restored to revision from [date]."
6 => "Post published. {View post}"
7 => "Post saved."
8 => "Post submitted. {Preview post}"
9 => "Post scheduled for: [date]. {Preview post}"
10 => "Post draft updated. {Preview post}"
@param array $messages An associative array of post updated messages with post type as keys.
@return array Updated array of post updated messages. | [
"Add",
"our",
"post",
"type",
"updated",
"messages",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L472-L529 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.bulk_post_updated_messages | public function bulk_post_updated_messages( array $messages, array $counts ) : array {
$messages[ $this->cpt->post_type ] = [
'updated' => sprintf(
self::n( '%2$s updated.', '%1$s %3$s updated.', $counts['updated'] ),
esc_html( number_format_i18n( $counts['updated'] ) ),
esc_html( $this->cpt->post_singular ),
esc_html( $this->cpt->post_plural_low )
),
'locked' => sprintf(
self::n( '%2$s not updated, somebody is editing it.', '%1$s %3$s not updated, somebody is editing them.', $counts['locked'] ),
esc_html( number_format_i18n( $counts['locked'] ) ),
esc_html( $this->cpt->post_singular ),
esc_html( $this->cpt->post_plural_low )
),
'deleted' => sprintf(
self::n( '%2$s permanently deleted.', '%1$s %3$s permanently deleted.', $counts['deleted'] ),
esc_html( number_format_i18n( $counts['deleted'] ) ),
esc_html( $this->cpt->post_singular ),
esc_html( $this->cpt->post_plural_low )
),
'trashed' => sprintf(
self::n( '%2$s moved to the trash.', '%1$s %3$s moved to the trash.', $counts['trashed'] ),
esc_html( number_format_i18n( $counts['trashed'] ) ),
esc_html( $this->cpt->post_singular ),
esc_html( $this->cpt->post_plural_low )
),
'untrashed' => sprintf(
self::n( '%2$s restored from the trash.', '%1$s %3$s restored from the trash.', $counts['untrashed'] ),
esc_html( number_format_i18n( $counts['untrashed'] ) ),
esc_html( $this->cpt->post_singular ),
esc_html( $this->cpt->post_plural_low )
),
];
return $messages;
} | php | public function bulk_post_updated_messages( array $messages, array $counts ) : array {
$messages[ $this->cpt->post_type ] = [
'updated' => sprintf(
self::n( '%2$s updated.', '%1$s %3$s updated.', $counts['updated'] ),
esc_html( number_format_i18n( $counts['updated'] ) ),
esc_html( $this->cpt->post_singular ),
esc_html( $this->cpt->post_plural_low )
),
'locked' => sprintf(
self::n( '%2$s not updated, somebody is editing it.', '%1$s %3$s not updated, somebody is editing them.', $counts['locked'] ),
esc_html( number_format_i18n( $counts['locked'] ) ),
esc_html( $this->cpt->post_singular ),
esc_html( $this->cpt->post_plural_low )
),
'deleted' => sprintf(
self::n( '%2$s permanently deleted.', '%1$s %3$s permanently deleted.', $counts['deleted'] ),
esc_html( number_format_i18n( $counts['deleted'] ) ),
esc_html( $this->cpt->post_singular ),
esc_html( $this->cpt->post_plural_low )
),
'trashed' => sprintf(
self::n( '%2$s moved to the trash.', '%1$s %3$s moved to the trash.', $counts['trashed'] ),
esc_html( number_format_i18n( $counts['trashed'] ) ),
esc_html( $this->cpt->post_singular ),
esc_html( $this->cpt->post_plural_low )
),
'untrashed' => sprintf(
self::n( '%2$s restored from the trash.', '%1$s %3$s restored from the trash.', $counts['untrashed'] ),
esc_html( number_format_i18n( $counts['untrashed'] ) ),
esc_html( $this->cpt->post_singular ),
esc_html( $this->cpt->post_plural_low )
),
];
return $messages;
} | [
"public",
"function",
"bulk_post_updated_messages",
"(",
"array",
"$",
"messages",
",",
"array",
"$",
"counts",
")",
":",
"array",
"{",
"$",
"messages",
"[",
"$",
"this",
"->",
"cpt",
"->",
"post_type",
"]",
"=",
"[",
"'updated'",
"=>",
"sprintf",
"(",
"... | Add our bulk post type updated messages.
The messages are as follows:
- updated => "Post updated." | "[n] posts updated."
- locked => "Post not updated, somebody is editing it." | "[n] posts not updated, somebody is editing them."
- deleted => "Post permanently deleted." | "[n] posts permanently deleted."
- trashed => "Post moved to the trash." | "[n] posts moved to the trash."
- untrashed => "Post restored from the trash." | "[n] posts restored from the trash."
@param array $messages An associative array of bulk post updated messages with post type as keys.
@param array $counts An array of counts for each key in `$messages`.
@return array Updated array of bulk post updated messages. | [
"Add",
"our",
"bulk",
"post",
"type",
"updated",
"messages",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L546-L583 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.sortables | public function sortables( array $cols ) : array {
foreach ( $this->args['admin_cols'] as $id => $col ) {
if ( ! is_array( $col ) ) {
continue;
}
if ( isset( $col['sortable'] ) && ! $col['sortable'] ) {
continue;
}
if ( isset( $col['meta_key'] ) || isset( $col['taxonomy'] ) || isset( $col['post_field'] ) ) {
$cols[ $id ] = $id;
}
}
return $cols;
} | php | public function sortables( array $cols ) : array {
foreach ( $this->args['admin_cols'] as $id => $col ) {
if ( ! is_array( $col ) ) {
continue;
}
if ( isset( $col['sortable'] ) && ! $col['sortable'] ) {
continue;
}
if ( isset( $col['meta_key'] ) || isset( $col['taxonomy'] ) || isset( $col['post_field'] ) ) {
$cols[ $id ] = $id;
}
}
return $cols;
} | [
"public",
"function",
"sortables",
"(",
"array",
"$",
"cols",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"this",
"->",
"args",
"[",
"'admin_cols'",
"]",
"as",
"$",
"id",
"=>",
"$",
"col",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"col",
"... | Add our custom columns to the list of sortable columns.
@param array $cols Associative array of sortable columns
@return array Updated array of sortable columns | [
"Add",
"our",
"custom",
"columns",
"to",
"the",
"list",
"of",
"sortable",
"columns",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L591-L607 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.cols | public function cols( array $cols ) : array {
// This function gets called multiple times, so let's cache it for efficiency:
if ( isset( $this->the_cols ) ) {
return $this->the_cols;
}
$new_cols = [];
$keep = [
'cb',
'title',
];
# Add existing columns we want to keep:
foreach ( $cols as $id => $title ) {
if ( in_array( $id, $keep, true ) && ! isset( $this->args['admin_cols'][ $id ] ) ) {
$new_cols[ $id ] = $title;
}
}
# Add our custom columns:
foreach ( array_filter( $this->args['admin_cols'] ) as $id => $col ) {
if ( is_string( $col ) && isset( $cols[ $col ] ) ) {
# Existing (ie. built-in) column with id as the value
$new_cols[ $col ] = $cols[ $col ];
} elseif ( is_string( $col ) && isset( $cols[ $id ] ) ) {
# Existing (ie. built-in) column with id as the key and title as the value
$new_cols[ $id ] = esc_html( $col );
} elseif ( 'author' === $col ) {
# Automatic support for Co-Authors Plus plugin and special case for
# displaying author column when the post type doesn't support 'author'
if ( class_exists( 'coauthors_plus' ) ) {
$k = 'coauthors';
} else {
$k = 'author';
}
$new_cols[ $k ] = esc_html__( 'Author', 'extended-cpts' );
} elseif ( is_array( $col ) ) {
if ( isset( $col['cap'] ) && ! current_user_can( $col['cap'] ) ) {
continue;
}
if ( isset( $col['connection'] ) && ! function_exists( 'p2p_type' ) ) {
continue;
}
if ( ! isset( $col['title'] ) ) {
$col['title'] = $this->get_item_title( $col ) ?? $id;
}
$new_cols[ $id ] = esc_html( $col['title'] );
}
}
# Re-add any custom columns:
$custom = array_diff_key( $cols, $this->_cols );
$new_cols = array_merge( $new_cols, $custom );
$this->the_cols = $new_cols;
return $this->the_cols;
} | php | public function cols( array $cols ) : array {
// This function gets called multiple times, so let's cache it for efficiency:
if ( isset( $this->the_cols ) ) {
return $this->the_cols;
}
$new_cols = [];
$keep = [
'cb',
'title',
];
# Add existing columns we want to keep:
foreach ( $cols as $id => $title ) {
if ( in_array( $id, $keep, true ) && ! isset( $this->args['admin_cols'][ $id ] ) ) {
$new_cols[ $id ] = $title;
}
}
# Add our custom columns:
foreach ( array_filter( $this->args['admin_cols'] ) as $id => $col ) {
if ( is_string( $col ) && isset( $cols[ $col ] ) ) {
# Existing (ie. built-in) column with id as the value
$new_cols[ $col ] = $cols[ $col ];
} elseif ( is_string( $col ) && isset( $cols[ $id ] ) ) {
# Existing (ie. built-in) column with id as the key and title as the value
$new_cols[ $id ] = esc_html( $col );
} elseif ( 'author' === $col ) {
# Automatic support for Co-Authors Plus plugin and special case for
# displaying author column when the post type doesn't support 'author'
if ( class_exists( 'coauthors_plus' ) ) {
$k = 'coauthors';
} else {
$k = 'author';
}
$new_cols[ $k ] = esc_html__( 'Author', 'extended-cpts' );
} elseif ( is_array( $col ) ) {
if ( isset( $col['cap'] ) && ! current_user_can( $col['cap'] ) ) {
continue;
}
if ( isset( $col['connection'] ) && ! function_exists( 'p2p_type' ) ) {
continue;
}
if ( ! isset( $col['title'] ) ) {
$col['title'] = $this->get_item_title( $col ) ?? $id;
}
$new_cols[ $id ] = esc_html( $col['title'] );
}
}
# Re-add any custom columns:
$custom = array_diff_key( $cols, $this->_cols );
$new_cols = array_merge( $new_cols, $custom );
$this->the_cols = $new_cols;
return $this->the_cols;
} | [
"public",
"function",
"cols",
"(",
"array",
"$",
"cols",
")",
":",
"array",
"{",
"// This function gets called multiple times, so let's cache it for efficiency:",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"the_cols",
")",
")",
"{",
"return",
"$",
"this",
"->",
... | Add columns to the admin screen for this post type.
@link https://github.com/johnbillion/extended-cpts/wiki/Admin-columns
@param array $cols Associative array of columns
@return array Updated array of columns | [
"Add",
"columns",
"to",
"the",
"admin",
"screen",
"for",
"this",
"post",
"type",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L617-L675 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.col_post_meta | public function col_post_meta( string $meta_key, array $args ) {
$vals = get_post_meta( get_the_ID(), $meta_key, false );
$echo = [];
sort( $vals );
if ( isset( $args['date_format'] ) ) {
if ( true === $args['date_format'] ) {
$args['date_format'] = get_option( 'date_format' );
}
foreach ( $vals as $val ) {
$val_time = strtotime( $val );
if ( $val_time ) {
$val = $val_time;
}
if ( is_numeric( $val ) ) {
$echo[] = date_i18n( $args['date_format'], $val );
} elseif ( ! empty( $val ) ) {
$echo[] = mysql2date( $args['date_format'], $val );
}
}
} else {
foreach ( $vals as $val ) {
if ( ! empty( $val ) || ( '0' === $val ) ) {
$echo[] = $val;
}
}
}
if ( empty( $echo ) ) {
echo '—';
} else {
echo esc_html( implode( ', ', $echo ) );
}
} | php | public function col_post_meta( string $meta_key, array $args ) {
$vals = get_post_meta( get_the_ID(), $meta_key, false );
$echo = [];
sort( $vals );
if ( isset( $args['date_format'] ) ) {
if ( true === $args['date_format'] ) {
$args['date_format'] = get_option( 'date_format' );
}
foreach ( $vals as $val ) {
$val_time = strtotime( $val );
if ( $val_time ) {
$val = $val_time;
}
if ( is_numeric( $val ) ) {
$echo[] = date_i18n( $args['date_format'], $val );
} elseif ( ! empty( $val ) ) {
$echo[] = mysql2date( $args['date_format'], $val );
}
}
} else {
foreach ( $vals as $val ) {
if ( ! empty( $val ) || ( '0' === $val ) ) {
$echo[] = $val;
}
}
}
if ( empty( $echo ) ) {
echo '—';
} else {
echo esc_html( implode( ', ', $echo ) );
}
} | [
"public",
"function",
"col_post_meta",
"(",
"string",
"$",
"meta_key",
",",
"array",
"$",
"args",
")",
"{",
"$",
"vals",
"=",
"get_post_meta",
"(",
"get_the_ID",
"(",
")",
",",
"$",
"meta_key",
",",
"false",
")",
";",
"$",
"echo",
"=",
"[",
"]",
";",... | Output column data for a post meta field.
@param string $meta_key The post meta key
@param array $args Array of arguments for this field | [
"Output",
"column",
"data",
"for",
"a",
"post",
"meta",
"field",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L724-L765 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.col_taxonomy | public function col_taxonomy( string $taxonomy, array $args ) {
global $post;
$terms = get_the_terms( $post, $taxonomy );
$tax = get_taxonomy( $taxonomy );
if ( is_wp_error( $terms ) ) {
echo esc_html( $terms->get_error_message() );
return;
}
if ( empty( $terms ) ) {
printf(
'<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>',
esc_html( $tax->labels->no_terms )
);
return;
}
$out = [];
foreach ( $terms as $term ) {
if ( $args['link'] ) {
switch ( $args['link'] ) {
case 'view':
if ( $tax->public ) {
// https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1096
// @codingStandardsIgnoreStart
$out[] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( get_term_link( $term ) ),
esc_html( $term->name )
);
// @codingStandardsIgnoreEnd
} else {
$out[] = esc_html( $term->name );
}
break;
case 'edit':
if ( current_user_can( $tax->cap->edit_terms ) ) {
$out[] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( get_edit_term_link( $term, $taxonomy, $post->post_type ) ),
esc_html( $term->name )
);
} else {
$out[] = esc_html( $term->name );
}
break;
case 'list':
$link = add_query_arg( [
'post_type' => $post->post_type,
$taxonomy => $term->slug,
], admin_url( 'edit.php' ) );
$out[] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( $link ),
esc_html( $term->name )
);
break;
}
} else {
$out[] = esc_html( $term->name );
}
}
echo implode( ', ', $out ); // WPCS: XSS ok.
} | php | public function col_taxonomy( string $taxonomy, array $args ) {
global $post;
$terms = get_the_terms( $post, $taxonomy );
$tax = get_taxonomy( $taxonomy );
if ( is_wp_error( $terms ) ) {
echo esc_html( $terms->get_error_message() );
return;
}
if ( empty( $terms ) ) {
printf(
'<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>',
esc_html( $tax->labels->no_terms )
);
return;
}
$out = [];
foreach ( $terms as $term ) {
if ( $args['link'] ) {
switch ( $args['link'] ) {
case 'view':
if ( $tax->public ) {
// https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1096
// @codingStandardsIgnoreStart
$out[] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( get_term_link( $term ) ),
esc_html( $term->name )
);
// @codingStandardsIgnoreEnd
} else {
$out[] = esc_html( $term->name );
}
break;
case 'edit':
if ( current_user_can( $tax->cap->edit_terms ) ) {
$out[] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( get_edit_term_link( $term, $taxonomy, $post->post_type ) ),
esc_html( $term->name )
);
} else {
$out[] = esc_html( $term->name );
}
break;
case 'list':
$link = add_query_arg( [
'post_type' => $post->post_type,
$taxonomy => $term->slug,
], admin_url( 'edit.php' ) );
$out[] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( $link ),
esc_html( $term->name )
);
break;
}
} else {
$out[] = esc_html( $term->name );
}
}
echo implode( ', ', $out ); // WPCS: XSS ok.
} | [
"public",
"function",
"col_taxonomy",
"(",
"string",
"$",
"taxonomy",
",",
"array",
"$",
"args",
")",
"{",
"global",
"$",
"post",
";",
"$",
"terms",
"=",
"get_the_terms",
"(",
"$",
"post",
",",
"$",
"taxonomy",
")",
";",
"$",
"tax",
"=",
"get_taxonomy"... | Output column data for a taxonomy's term names.
@param string $taxonomy The taxonomy name
@param array $args Array of arguments for this field | [
"Output",
"column",
"data",
"for",
"a",
"taxonomy",
"s",
"term",
"names",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L773-L846 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.col_post_field | public function col_post_field( string $field, array $args ) {
global $post;
switch ( $field ) {
case 'post_date':
case 'post_date_gmt':
case 'post_modified':
case 'post_modified_gmt':
if ( '0000-00-00 00:00:00' !== get_post_field( $field, $post ) ) {
if ( ! isset( $args['date_format'] ) ) {
$args['date_format'] = get_option( 'date_format' );
}
echo esc_html( mysql2date( $args['date_format'], get_post_field( $field, $post ) ) );
}
break;
case 'post_status':
$status = get_post_status_object( get_post_status( $post ) );
if ( $status ) {
echo esc_html( $status->label );
}
break;
case 'post_author':
echo esc_html( get_the_author() );
break;
case 'post_title':
echo esc_html( get_the_title() );
break;
case 'post_excerpt':
echo esc_html( get_the_excerpt() );
break;
default:
echo esc_html( get_post_field( $field, $post ) );
break;
}
} | php | public function col_post_field( string $field, array $args ) {
global $post;
switch ( $field ) {
case 'post_date':
case 'post_date_gmt':
case 'post_modified':
case 'post_modified_gmt':
if ( '0000-00-00 00:00:00' !== get_post_field( $field, $post ) ) {
if ( ! isset( $args['date_format'] ) ) {
$args['date_format'] = get_option( 'date_format' );
}
echo esc_html( mysql2date( $args['date_format'], get_post_field( $field, $post ) ) );
}
break;
case 'post_status':
$status = get_post_status_object( get_post_status( $post ) );
if ( $status ) {
echo esc_html( $status->label );
}
break;
case 'post_author':
echo esc_html( get_the_author() );
break;
case 'post_title':
echo esc_html( get_the_title() );
break;
case 'post_excerpt':
echo esc_html( get_the_excerpt() );
break;
default:
echo esc_html( get_post_field( $field, $post ) );
break;
}
} | [
"public",
"function",
"col_post_field",
"(",
"string",
"$",
"field",
",",
"array",
"$",
"args",
")",
"{",
"global",
"$",
"post",
";",
"switch",
"(",
"$",
"field",
")",
"{",
"case",
"'post_date'",
":",
"case",
"'post_date_gmt'",
":",
"case",
"'post_modified... | Output column data for a post field.
@param string $field The post field
@param array $args Array of arguments for this field | [
"Output",
"column",
"data",
"for",
"a",
"post",
"field",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L854-L897 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.col_featured_image | public function col_featured_image( string $image_size, array $args ) {
if ( ! function_exists( 'has_post_thumbnail' ) ) {
return;
}
if ( isset( $args['width'] ) ) {
$width = is_numeric( $args['width'] ) ? sprintf( '%dpx', $args['width'] ) : $args['width'];
} else {
$width = 'auto';
}
if ( isset( $args['height'] ) ) {
$height = is_numeric( $args['height'] ) ? sprintf( '%dpx', $args['height'] ) : $args['height'];
} else {
$height = 'auto';
}
$image_atts = [
'style' => esc_attr( sprintf(
'width:%1$s;height:%2$s',
$width,
$height
) ),
'title' => '',
];
if ( has_post_thumbnail() ) {
the_post_thumbnail( $image_size, $image_atts );
}
} | php | public function col_featured_image( string $image_size, array $args ) {
if ( ! function_exists( 'has_post_thumbnail' ) ) {
return;
}
if ( isset( $args['width'] ) ) {
$width = is_numeric( $args['width'] ) ? sprintf( '%dpx', $args['width'] ) : $args['width'];
} else {
$width = 'auto';
}
if ( isset( $args['height'] ) ) {
$height = is_numeric( $args['height'] ) ? sprintf( '%dpx', $args['height'] ) : $args['height'];
} else {
$height = 'auto';
}
$image_atts = [
'style' => esc_attr( sprintf(
'width:%1$s;height:%2$s',
$width,
$height
) ),
'title' => '',
];
if ( has_post_thumbnail() ) {
the_post_thumbnail( $image_size, $image_atts );
}
} | [
"public",
"function",
"col_featured_image",
"(",
"string",
"$",
"image_size",
",",
"array",
"$",
"args",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'has_post_thumbnail'",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"args",
"[... | Output column data for a post's featured image.
@param string $image_size The image size
@param array $args Array of `width` and `height` attributes for the image | [
"Output",
"column",
"data",
"for",
"a",
"post",
"s",
"featured",
"image",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L905-L936 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.remove_quick_edit_action | public function remove_quick_edit_action( array $actions, WP_Post $post ) : array {
if ( $this->cpt->post_type !== $post->post_type ) {
return $actions;
}
unset( $actions['inline'], $actions['inline hide-if-no-js'] );
return $actions;
} | php | public function remove_quick_edit_action( array $actions, WP_Post $post ) : array {
if ( $this->cpt->post_type !== $post->post_type ) {
return $actions;
}
unset( $actions['inline'], $actions['inline hide-if-no-js'] );
return $actions;
} | [
"public",
"function",
"remove_quick_edit_action",
"(",
"array",
"$",
"actions",
",",
"WP_Post",
"$",
"post",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"cpt",
"->",
"post_type",
"!==",
"$",
"post",
"->",
"post_type",
")",
"{",
"return",
"$",
... | Removes the Quick Edit link from the post row actions.
@param array $actions Array of post actions
@param WP_Post $post The current post object
@return array Array of updated post actions | [
"Removes",
"the",
"Quick",
"Edit",
"link",
"from",
"the",
"post",
"row",
"actions",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L1070-L1079 | train |
johnbillion/extended-cpts | src/class-extended-cpt-admin.php | Extended_CPT_Admin.p2p_connection_exists | protected function p2p_connection_exists( string $connection ) : bool {
if ( ! isset( $this->connection_exists[ $connection ] ) ) {
$this->connection_exists[ $connection ] = p2p_connection_exists( $connection );
}
return $this->connection_exists[ $connection ];
} | php | protected function p2p_connection_exists( string $connection ) : bool {
if ( ! isset( $this->connection_exists[ $connection ] ) ) {
$this->connection_exists[ $connection ] = p2p_connection_exists( $connection );
}
return $this->connection_exists[ $connection ];
} | [
"protected",
"function",
"p2p_connection_exists",
"(",
"string",
"$",
"connection",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"connection_exists",
"[",
"$",
"connection",
"]",
")",
")",
"{",
"$",
"this",
"->",
"connection_exis... | Check if a certain Posts 2 Posts connection exists.
This is just a caching wrapper for `p2p_connection_exists()`, which performs a
database query on every call.
@param string $connection A connection type.
@return bool Whether the connection exists. | [
"Check",
"if",
"a",
"certain",
"Posts",
"2",
"Posts",
"connection",
"exists",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-cpt-admin.php#L1198-L1203 | train |
johnbillion/extended-cpts | src/class-extended-taxonomy.php | Extended_Taxonomy.register_taxonomy | public function register_taxonomy() {
if ( true === $this->args['query_var'] ) {
$query_var = $this->taxonomy;
} else {
$query_var = $this->args['query_var'];
}
$post_types = get_post_types( [
'query_var' => $query_var,
] );
if ( $query_var && count( $post_types ) ) {
trigger_error( esc_html( sprintf(
/* translators: %s: Taxonomy query variable name */
__( 'Taxonomy query var "%s" clashes with a post type query var of the same name', 'extended-cpts' ),
$query_var
) ), E_USER_ERROR );
} elseif ( in_array( $query_var, [ 'type', 'tab' ], true ) ) {
trigger_error( esc_html( sprintf(
/* translators: %s: Taxonomy query variable name */
__( 'Taxonomy query var "%s" is not allowed', 'extended-cpts' ),
$query_var
) ), E_USER_ERROR );
} else {
register_taxonomy( $this->taxonomy, $this->object_type, $this->args );
}
} | php | public function register_taxonomy() {
if ( true === $this->args['query_var'] ) {
$query_var = $this->taxonomy;
} else {
$query_var = $this->args['query_var'];
}
$post_types = get_post_types( [
'query_var' => $query_var,
] );
if ( $query_var && count( $post_types ) ) {
trigger_error( esc_html( sprintf(
/* translators: %s: Taxonomy query variable name */
__( 'Taxonomy query var "%s" clashes with a post type query var of the same name', 'extended-cpts' ),
$query_var
) ), E_USER_ERROR );
} elseif ( in_array( $query_var, [ 'type', 'tab' ], true ) ) {
trigger_error( esc_html( sprintf(
/* translators: %s: Taxonomy query variable name */
__( 'Taxonomy query var "%s" is not allowed', 'extended-cpts' ),
$query_var
) ), E_USER_ERROR );
} else {
register_taxonomy( $this->taxonomy, $this->object_type, $this->args );
}
} | [
"public",
"function",
"register_taxonomy",
"(",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"args",
"[",
"'query_var'",
"]",
")",
"{",
"$",
"query_var",
"=",
"$",
"this",
"->",
"taxonomy",
";",
"}",
"else",
"{",
"$",
"query_var",
"=",
"$",... | Registers our taxonomy.
@return null | [
"Registers",
"our",
"taxonomy",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-taxonomy.php#L187-L215 | train |
johnbillion/extended-cpts | src/class-extended-taxonomy-admin.php | Extended_Taxonomy_Admin.col_term_meta | public function col_term_meta( $meta_key, array $args, $term_id ) {
$vals = get_term_meta( $term_id, $meta_key, false );
$echo = [];
sort( $vals );
if ( isset( $args['date_format'] ) ) {
if ( true === $args['date_format'] ) {
$args['date_format'] = get_option( 'date_format' );
}
foreach ( $vals as $val ) {
if ( is_numeric( $val ) ) {
$echo[] = date( $args['date_format'], $val );
} elseif ( ! empty( $val ) ) {
$echo[] = mysql2date( $args['date_format'], $val );
}
}
} else {
foreach ( $vals as $val ) {
if ( ! empty( $val ) || ( '0' === $val ) ) {
$echo[] = $val;
}
}
}
if ( empty( $echo ) ) {
echo '—';
} else {
echo esc_html( implode( ', ', $echo ) );
}
} | php | public function col_term_meta( $meta_key, array $args, $term_id ) {
$vals = get_term_meta( $term_id, $meta_key, false );
$echo = [];
sort( $vals );
if ( isset( $args['date_format'] ) ) {
if ( true === $args['date_format'] ) {
$args['date_format'] = get_option( 'date_format' );
}
foreach ( $vals as $val ) {
if ( is_numeric( $val ) ) {
$echo[] = date( $args['date_format'], $val );
} elseif ( ! empty( $val ) ) {
$echo[] = mysql2date( $args['date_format'], $val );
}
}
} else {
foreach ( $vals as $val ) {
if ( ! empty( $val ) || ( '0' === $val ) ) {
$echo[] = $val;
}
}
}
if ( empty( $echo ) ) {
echo '—';
} else {
echo esc_html( implode( ', ', $echo ) );
}
} | [
"public",
"function",
"col_term_meta",
"(",
"$",
"meta_key",
",",
"array",
"$",
"args",
",",
"$",
"term_id",
")",
"{",
"$",
"vals",
"=",
"get_term_meta",
"(",
"$",
"term_id",
",",
"$",
"meta_key",
",",
"false",
")",
";",
"$",
"echo",
"=",
"[",
"]",
... | Output column data for a term meta field.
@param string $meta_key The term meta key
@param array $args Array of arguments for this field
@param int $term_id Term ID. | [
"Output",
"column",
"data",
"for",
"a",
"term",
"meta",
"field",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-taxonomy-admin.php#L215-L251 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.