id
int32 0
241k
| 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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
25,700
|
Retentio/Boomgo
|
src/Boomgo/Formatter/Underscore2CamelFormatter.php
|
Underscore2CamelFormatter.camelize
|
private function camelize($string, $lower = true)
{
$words = explode('_', strtolower($string));
$camelized = '';
foreach ($words as $word) {
if (strpos($word, '_') === false) {
$camelized .= ucfirst(trim($word));
}
}
return ($lower) ? lcfirst($camelized) : $camelized;
}
|
php
|
private function camelize($string, $lower = true)
{
$words = explode('_', strtolower($string));
$camelized = '';
foreach ($words as $word) {
if (strpos($word, '_') === false) {
$camelized .= ucfirst(trim($word));
}
}
return ($lower) ? lcfirst($camelized) : $camelized;
}
|
[
"private",
"function",
"camelize",
"(",
"$",
"string",
",",
"$",
"lower",
"=",
"true",
")",
"{",
"$",
"words",
"=",
"explode",
"(",
"'_'",
",",
"strtolower",
"(",
"$",
"string",
")",
")",
";",
"$",
"camelized",
"=",
"''",
";",
"foreach",
"(",
"$",
"words",
"as",
"$",
"word",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"word",
",",
"'_'",
")",
"===",
"false",
")",
"{",
"$",
"camelized",
".=",
"ucfirst",
"(",
"trim",
"(",
"$",
"word",
")",
")",
";",
"}",
"}",
"return",
"(",
"$",
"lower",
")",
"?",
"lcfirst",
"(",
"$",
"camelized",
")",
":",
"$",
"camelized",
";",
"}"
] |
Convert underscored string to lower|upper camelCase
@param string $string An underscored string
@param bool $lower
@return string
@example my_great_key -> myGreatKey|MyGreatKey
|
[
"Convert",
"underscored",
"string",
"to",
"lower|upper",
"camelCase"
] |
95cc53777425dd76cd0034046fa4f9e72c04d73a
|
https://github.com/Retentio/Boomgo/blob/95cc53777425dd76cd0034046fa4f9e72c04d73a/src/Boomgo/Formatter/Underscore2CamelFormatter.php#L92-L105
|
25,701
|
ekyna/Resource
|
ResourceComponent.php
|
ResourceComponent.getConfigurationFactory
|
public function getConfigurationFactory()
{
if (null === $this->configurationFactory) {
$this->configurationFactory = new Configuration\ConfigurationFactory();
}
return $this->configurationFactory;
}
|
php
|
public function getConfigurationFactory()
{
if (null === $this->configurationFactory) {
$this->configurationFactory = new Configuration\ConfigurationFactory();
}
return $this->configurationFactory;
}
|
[
"public",
"function",
"getConfigurationFactory",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"configurationFactory",
")",
"{",
"$",
"this",
"->",
"configurationFactory",
"=",
"new",
"Configuration",
"\\",
"ConfigurationFactory",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"configurationFactory",
";",
"}"
] |
Returns the configuration factory.
@return Configuration\ConfigurationFactory
|
[
"Returns",
"the",
"configuration",
"factory",
"."
] |
96ee3d28e02bd9513705408e3bb7f88a76e52f56
|
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/ResourceComponent.php#L151-L158
|
25,702
|
ekyna/Resource
|
ResourceComponent.php
|
ResourceComponent.getConfigurationRegistry
|
public function getConfigurationRegistry()
{
if (null === $this->configurationRegistry) {
$this->configurationRegistry = new Configuration\ConfigurationRegistry();
}
return $this->configurationRegistry;
}
|
php
|
public function getConfigurationRegistry()
{
if (null === $this->configurationRegistry) {
$this->configurationRegistry = new Configuration\ConfigurationRegistry();
}
return $this->configurationRegistry;
}
|
[
"public",
"function",
"getConfigurationRegistry",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"configurationRegistry",
")",
"{",
"$",
"this",
"->",
"configurationRegistry",
"=",
"new",
"Configuration",
"\\",
"ConfigurationRegistry",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"configurationRegistry",
";",
"}"
] |
Returns the configuration registry.
@return Configuration\ConfigurationRegistry
|
[
"Returns",
"the",
"configuration",
"registry",
"."
] |
96ee3d28e02bd9513705408e3bb7f88a76e52f56
|
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/ResourceComponent.php#L165-L172
|
25,703
|
ekyna/Resource
|
ResourceComponent.php
|
ResourceComponent.getEventDispatcher
|
public function getEventDispatcher()
{
if (null === $this->eventDispatcher) {
$this->eventDispatcher = new Dispatcher\ResourceEventDispatcher();
$this->eventDispatcher->setConfigurationRegistry($this->getConfigurationRegistry());
$this->eventDispatcher->setEventQueue($this->getEventQueue());
}
return $this->eventDispatcher;
}
|
php
|
public function getEventDispatcher()
{
if (null === $this->eventDispatcher) {
$this->eventDispatcher = new Dispatcher\ResourceEventDispatcher();
$this->eventDispatcher->setConfigurationRegistry($this->getConfigurationRegistry());
$this->eventDispatcher->setEventQueue($this->getEventQueue());
}
return $this->eventDispatcher;
}
|
[
"public",
"function",
"getEventDispatcher",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"eventDispatcher",
")",
"{",
"$",
"this",
"->",
"eventDispatcher",
"=",
"new",
"Dispatcher",
"\\",
"ResourceEventDispatcher",
"(",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"setConfigurationRegistry",
"(",
"$",
"this",
"->",
"getConfigurationRegistry",
"(",
")",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"setEventQueue",
"(",
"$",
"this",
"->",
"getEventQueue",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"eventDispatcher",
";",
"}"
] |
Returns the event dispatcher.
@return Dispatcher\ResourceEventDispatcher
|
[
"Returns",
"the",
"event",
"dispatcher",
"."
] |
96ee3d28e02bd9513705408e3bb7f88a76e52f56
|
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/ResourceComponent.php#L179-L188
|
25,704
|
ekyna/Resource
|
ResourceComponent.php
|
ResourceComponent.getLocaleProvider
|
public function getLocaleProvider()
{
if (null === $this->localeProvider) {
$this->localeProvider = new Locale\LocaleProvider('fr', 'en', ['fr', 'en']);
}
return $this->localeProvider;
}
|
php
|
public function getLocaleProvider()
{
if (null === $this->localeProvider) {
$this->localeProvider = new Locale\LocaleProvider('fr', 'en', ['fr', 'en']);
}
return $this->localeProvider;
}
|
[
"public",
"function",
"getLocaleProvider",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"localeProvider",
")",
"{",
"$",
"this",
"->",
"localeProvider",
"=",
"new",
"Locale",
"\\",
"LocaleProvider",
"(",
"'fr'",
",",
"'en'",
",",
"[",
"'fr'",
",",
"'en'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"localeProvider",
";",
"}"
] |
Returns the locale provider.
@return Locale\LocaleProviderInterface
|
[
"Returns",
"the",
"locale",
"provider",
"."
] |
96ee3d28e02bd9513705408e3bb7f88a76e52f56
|
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/ResourceComponent.php#L195-L202
|
25,705
|
ekyna/Resource
|
ResourceComponent.php
|
ResourceComponent.getEventQueue
|
public function getEventQueue()
{
if (null === $this->eventQueue) {
$this->eventQueue = new Event\EventQueue(
$this->getConfigurationRegistry(),
$this->getEventDispatcher()
);
}
return $this->eventQueue;
}
|
php
|
public function getEventQueue()
{
if (null === $this->eventQueue) {
$this->eventQueue = new Event\EventQueue(
$this->getConfigurationRegistry(),
$this->getEventDispatcher()
);
}
return $this->eventQueue;
}
|
[
"public",
"function",
"getEventQueue",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"eventQueue",
")",
"{",
"$",
"this",
"->",
"eventQueue",
"=",
"new",
"Event",
"\\",
"EventQueue",
"(",
"$",
"this",
"->",
"getConfigurationRegistry",
"(",
")",
",",
"$",
"this",
"->",
"getEventDispatcher",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"eventQueue",
";",
"}"
] |
Returns the event queue.
@return Event\EventQueue
|
[
"Returns",
"the",
"event",
"queue",
"."
] |
96ee3d28e02bd9513705408e3bb7f88a76e52f56
|
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/ResourceComponent.php#L209-L219
|
25,706
|
ekyna/Resource
|
ResourceComponent.php
|
ResourceComponent.getPersistenceEventQueue
|
public function getPersistenceEventQueue()
{
if (null === $this->persistenceEventQueue) {
$this->persistenceEventQueue = new Persistence\PersistenceEventQueue(
$this->getConfigurationRegistry(),
$this->getEventDispatcher()
);
}
return $this->persistenceEventQueue;
}
|
php
|
public function getPersistenceEventQueue()
{
if (null === $this->persistenceEventQueue) {
$this->persistenceEventQueue = new Persistence\PersistenceEventQueue(
$this->getConfigurationRegistry(),
$this->getEventDispatcher()
);
}
return $this->persistenceEventQueue;
}
|
[
"public",
"function",
"getPersistenceEventQueue",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"persistenceEventQueue",
")",
"{",
"$",
"this",
"->",
"persistenceEventQueue",
"=",
"new",
"Persistence",
"\\",
"PersistenceEventQueue",
"(",
"$",
"this",
"->",
"getConfigurationRegistry",
"(",
")",
",",
"$",
"this",
"->",
"getEventDispatcher",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"persistenceEventQueue",
";",
"}"
] |
Returns the persistence event queue.
@return Persistence\PersistenceEventQueue
|
[
"Returns",
"the",
"persistence",
"event",
"queue",
"."
] |
96ee3d28e02bd9513705408e3bb7f88a76e52f56
|
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/ResourceComponent.php#L226-L236
|
25,707
|
ekyna/Resource
|
ResourceComponent.php
|
ResourceComponent.getPersistenceHelper
|
public function getPersistenceHelper()
{
if (null === $this->persistenceHelper) {
$this->persistenceHelper = new Doctrine\ORM\PersistenceHelper(
$this->em,
$this->getPersistenceEventQueue()
);
}
return $this->persistenceHelper;
}
|
php
|
public function getPersistenceHelper()
{
if (null === $this->persistenceHelper) {
$this->persistenceHelper = new Doctrine\ORM\PersistenceHelper(
$this->em,
$this->getPersistenceEventQueue()
);
}
return $this->persistenceHelper;
}
|
[
"public",
"function",
"getPersistenceHelper",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"persistenceHelper",
")",
"{",
"$",
"this",
"->",
"persistenceHelper",
"=",
"new",
"Doctrine",
"\\",
"ORM",
"\\",
"PersistenceHelper",
"(",
"$",
"this",
"->",
"em",
",",
"$",
"this",
"->",
"getPersistenceEventQueue",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"persistenceHelper",
";",
"}"
] |
Returns the persistence helper.
@return Persistence\PersistenceHelperInterface
|
[
"Returns",
"the",
"persistence",
"helper",
"."
] |
96ee3d28e02bd9513705408e3bb7f88a76e52f56
|
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/ResourceComponent.php#L243-L253
|
25,708
|
niels-nijens/protocol-stream
|
src/Wrapper/StreamWrapper.php
|
StreamWrapper.getStreamByPathScheme
|
private function getStreamByPathScheme($path)
{
$scheme = parse_url($path, PHP_URL_SCHEME);
return $this->streamManager->getStream($scheme);
}
|
php
|
private function getStreamByPathScheme($path)
{
$scheme = parse_url($path, PHP_URL_SCHEME);
return $this->streamManager->getStream($scheme);
}
|
[
"private",
"function",
"getStreamByPathScheme",
"(",
"$",
"path",
")",
"{",
"$",
"scheme",
"=",
"parse_url",
"(",
"$",
"path",
",",
"PHP_URL_SCHEME",
")",
";",
"return",
"$",
"this",
"->",
"streamManager",
"->",
"getStream",
"(",
"$",
"scheme",
")",
";",
"}"
] |
Returns the stream instance by the uri scheme in path.
@param string $path
@return StreamInterface
|
[
"Returns",
"the",
"stream",
"instance",
"by",
"the",
"uri",
"scheme",
"in",
"path",
"."
] |
c45b8d282bbb83f2a3d17adeb1d66500c14a868c
|
https://github.com/niels-nijens/protocol-stream/blob/c45b8d282bbb83f2a3d17adeb1d66500c14a868c/src/Wrapper/StreamWrapper.php#L288-L293
|
25,709
|
niels-nijens/protocol-stream
|
src/Wrapper/StreamWrapper.php
|
StreamWrapper.isStreamWritable
|
private function isStreamWritable($path)
{
$stream = $this->getStreamByPathScheme($path);
if ($stream instanceof StreamInterface) {
return $stream->isWritable();
}
return false;
}
|
php
|
private function isStreamWritable($path)
{
$stream = $this->getStreamByPathScheme($path);
if ($stream instanceof StreamInterface) {
return $stream->isWritable();
}
return false;
}
|
[
"private",
"function",
"isStreamWritable",
"(",
"$",
"path",
")",
"{",
"$",
"stream",
"=",
"$",
"this",
"->",
"getStreamByPathScheme",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"stream",
"instanceof",
"StreamInterface",
")",
"{",
"return",
"$",
"stream",
"->",
"isWritable",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns true if the stream for the path is writable.
@param string $path
@return bool
|
[
"Returns",
"true",
"if",
"the",
"stream",
"for",
"the",
"path",
"is",
"writable",
"."
] |
c45b8d282bbb83f2a3d17adeb1d66500c14a868c
|
https://github.com/niels-nijens/protocol-stream/blob/c45b8d282bbb83f2a3d17adeb1d66500c14a868c/src/Wrapper/StreamWrapper.php#L302-L310
|
25,710
|
OpencontentCoop/ocembed
|
classes/ocembed.php
|
OCEmbed.maybe_make_link
|
function maybe_make_link( $url )
{
if ( array_key_exists( $url, $this->links ) )
{
if ( is_array( $this->links[$url] ) )
{
$output = $this->links[$url][0];
}
else
{
$output = $this->links[$url];
}
}
else
{
$output = $url;
}
return $output;
}
|
php
|
function maybe_make_link( $url )
{
if ( array_key_exists( $url, $this->links ) )
{
if ( is_array( $this->links[$url] ) )
{
$output = $this->links[$url][0];
}
else
{
$output = $this->links[$url];
}
}
else
{
$output = $url;
}
return $output;
}
|
[
"function",
"maybe_make_link",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"url",
",",
"$",
"this",
"->",
"links",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"links",
"[",
"$",
"url",
"]",
")",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"links",
"[",
"$",
"url",
"]",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"links",
"[",
"$",
"url",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"output",
"=",
"$",
"url",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
Conditionally makes a hyperlink based on an internal class variable.
@param string $url URL to potentially be linked.
@return string Linked URL or the original URL.
|
[
"Conditionally",
"makes",
"a",
"hyperlink",
"based",
"on",
"an",
"internal",
"class",
"variable",
"."
] |
e8c990a9bcc284c2f48ac5688ee6e66ee6dd8043
|
https://github.com/OpencontentCoop/ocembed/blob/e8c990a9bcc284c2f48ac5688ee6e66ee6dd8043/classes/ocembed.php#L227-L245
|
25,711
|
Kris-Kuiper/sFire-Framework
|
src/MVC/ViewModel.php
|
ViewModel.getVariable
|
public function getVariable($variable) {
if(true === isset($this -> variables[$variable])) {
return $this -> variables[$variable];
}
}
|
php
|
public function getVariable($variable) {
if(true === isset($this -> variables[$variable])) {
return $this -> variables[$variable];
}
}
|
[
"public",
"function",
"getVariable",
"(",
"$",
"variable",
")",
"{",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"variables",
"[",
"$",
"variable",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"variables",
"[",
"$",
"variable",
"]",
";",
"}",
"}"
] |
Getter for returning variables by key
@param mixed $variable
@return mixed
|
[
"Getter",
"for",
"returning",
"variables",
"by",
"key"
] |
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
|
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/MVC/ViewModel.php#L111-L116
|
25,712
|
shgysk8zer0/core_api
|
traits/file_resources.php
|
File_Resources.fsockopen
|
final protected function fsockopen(
$hostname,
$port = -1,
&$errno = 0,
&$errstr = '',
$timeout = null
)
{
$this->fhandle = fsockopen($hostname, $port, $errno, $errstr, $timeout);
return $this;
}
|
php
|
final protected function fsockopen(
$hostname,
$port = -1,
&$errno = 0,
&$errstr = '',
$timeout = null
)
{
$this->fhandle = fsockopen($hostname, $port, $errno, $errstr, $timeout);
return $this;
}
|
[
"final",
"protected",
"function",
"fsockopen",
"(",
"$",
"hostname",
",",
"$",
"port",
"=",
"-",
"1",
",",
"&",
"$",
"errno",
"=",
"0",
",",
"&",
"$",
"errstr",
"=",
"''",
",",
"$",
"timeout",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"fhandle",
"=",
"fsockopen",
"(",
"$",
"hostname",
",",
"$",
"port",
",",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"timeout",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Open Internet or Unix domain socket connection
@param string $hostname [description]
@param int $port Port number
@param int $errno Holds system level error number
@param string $errstr The error message as a string
@param float $timeout The connection timeout, in seconds
@return self
@see https://php.net/manual/en/function.fpassthru.php
@todo Test this
|
[
"Open",
"Internet",
"or",
"Unix",
"domain",
"socket",
"connection"
] |
9e9b8baf761af874b95256ad2462e55fbb2b2e58
|
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/file_resources.php#L77-L87
|
25,713
|
shgysk8zer0/core_api
|
traits/file_resources.php
|
File_Resources.fwrite
|
final protected function fwrite($string, $length = null)
{
return is_int($length)
? fwrite($this->fhandle, $string, $length)
: fwrite($this->fhandle, $string);
}
|
php
|
final protected function fwrite($string, $length = null)
{
return is_int($length)
? fwrite($this->fhandle, $string, $length)
: fwrite($this->fhandle, $string);
}
|
[
"final",
"protected",
"function",
"fwrite",
"(",
"$",
"string",
",",
"$",
"length",
"=",
"null",
")",
"{",
"return",
"is_int",
"(",
"$",
"length",
")",
"?",
"fwrite",
"(",
"$",
"this",
"->",
"fhandle",
",",
"$",
"string",
",",
"$",
"length",
")",
":",
"fwrite",
"(",
"$",
"this",
"->",
"fhandle",
",",
"$",
"string",
")",
";",
"}"
] |
Binary-safe file write
@param string $string The string that is to be written.
@param int $length Stop after $length bytes have been written
@return self
@see https://php.net/manual/en/function.fwrite.php
|
[
"Binary",
"-",
"safe",
"file",
"write"
] |
9e9b8baf761af874b95256ad2462e55fbb2b2e58
|
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/file_resources.php#L125-L130
|
25,714
|
shgysk8zer0/core_api
|
traits/file_resources.php
|
File_Resources.fread
|
final protected function fread($length = null)
{
if (! is_int($length)) {
$length = $this->fstat('size');
}
return fread($this->fhandle, $length);
}
|
php
|
final protected function fread($length = null)
{
if (! is_int($length)) {
$length = $this->fstat('size');
}
return fread($this->fhandle, $length);
}
|
[
"final",
"protected",
"function",
"fread",
"(",
"$",
"length",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"length",
")",
")",
"{",
"$",
"length",
"=",
"$",
"this",
"->",
"fstat",
"(",
"'size'",
")",
";",
"}",
"return",
"fread",
"(",
"$",
"this",
"->",
"fhandle",
",",
"$",
"length",
")",
";",
"}"
] |
Binary-safe file read
@param int $length Up to $length number of bytes read.
@return string The read string or FALSE on failure.
@see https://php.net/manual/en/function.fread.php
|
[
"Binary",
"-",
"safe",
"file",
"read"
] |
9e9b8baf761af874b95256ad2462e55fbb2b2e58
|
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/file_resources.php#L159-L165
|
25,715
|
shgysk8zer0/core_api
|
traits/file_resources.php
|
File_Resources.fgetcsv
|
final protected function fgetcsv(
$length = 0,
$delimiter = ',',
$enclosure = '"',
$escape = '\\'
)
{
return fgetcsv($this->fhandle, $length, $delimiter, $enclosure, $escape);
}
|
php
|
final protected function fgetcsv(
$length = 0,
$delimiter = ',',
$enclosure = '"',
$escape = '\\'
)
{
return fgetcsv($this->fhandle, $length, $delimiter, $enclosure, $escape);
}
|
[
"final",
"protected",
"function",
"fgetcsv",
"(",
"$",
"length",
"=",
"0",
",",
"$",
"delimiter",
"=",
"','",
",",
"$",
"enclosure",
"=",
"'\"'",
",",
"$",
"escape",
"=",
"'\\\\'",
")",
"{",
"return",
"fgetcsv",
"(",
"$",
"this",
"->",
"fhandle",
",",
"$",
"length",
",",
"$",
"delimiter",
",",
"$",
"enclosure",
",",
"$",
"escape",
")",
";",
"}"
] |
Gets line from file pointer and parse for CSV fields
@param int $length Maximum line length (0 is unlimited)
@param string $delimiter Sets the field delimiter (1 character only)
@param string $enclosure Sets the field enclosure (1 character only)
@param string $escape Sets the escape character (1 character only)
@return array An indexed array containing the fields read.
@see https://php.net/manual/en/function.fgetcsv.php
|
[
"Gets",
"line",
"from",
"file",
"pointer",
"and",
"parse",
"for",
"CSV",
"fields"
] |
9e9b8baf761af874b95256ad2462e55fbb2b2e58
|
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/file_resources.php#L228-L236
|
25,716
|
shgysk8zer0/core_api
|
traits/file_resources.php
|
File_Resources.fputcsv
|
final protected function fputcsv(
array $fields,
$delimiter = ',',
$enclosure = '"',
$escape_char = '\\'
)
{
return fputcsv(
$this->fhandle,
$fields,
$delimiter,
$enclosure,
$escape_char
);
}
|
php
|
final protected function fputcsv(
array $fields,
$delimiter = ',',
$enclosure = '"',
$escape_char = '\\'
)
{
return fputcsv(
$this->fhandle,
$fields,
$delimiter,
$enclosure,
$escape_char
);
}
|
[
"final",
"protected",
"function",
"fputcsv",
"(",
"array",
"$",
"fields",
",",
"$",
"delimiter",
"=",
"','",
",",
"$",
"enclosure",
"=",
"'\"'",
",",
"$",
"escape_char",
"=",
"'\\\\'",
")",
"{",
"return",
"fputcsv",
"(",
"$",
"this",
"->",
"fhandle",
",",
"$",
"fields",
",",
"$",
"delimiter",
",",
"$",
"enclosure",
",",
"$",
"escape_char",
")",
";",
"}"
] |
Format line as CSV and write to file pointer
@param array $fields An array of values.
@param string $delimiter Sets the field delimiter (1 character only)
@param string $enclosure Sets the field enclosure (1 character only)
@param string $escape_char Sets the escape character (1 character only)
@return int Length of the written string or FALSE on failure.
@see https://php.net/manual/en/function.fputcsv.php
|
[
"Format",
"line",
"as",
"CSV",
"and",
"write",
"to",
"file",
"pointer"
] |
9e9b8baf761af874b95256ad2462e55fbb2b2e58
|
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/file_resources.php#L248-L262
|
25,717
|
shgysk8zer0/core_api
|
traits/file_resources.php
|
File_Resources.fscanf
|
final protected function fscanf($format, array &$params = array())
{
if (empty($params)) {
return fscanf($this->fhandle, $format);
}
array_shift($params, $this->fhandle, $format);
$results = call_user_func_array('fscanf', $params);
array_splice($params, 2);
return $results;
}
|
php
|
final protected function fscanf($format, array &$params = array())
{
if (empty($params)) {
return fscanf($this->fhandle, $format);
}
array_shift($params, $this->fhandle, $format);
$results = call_user_func_array('fscanf', $params);
array_splice($params, 2);
return $results;
}
|
[
"final",
"protected",
"function",
"fscanf",
"(",
"$",
"format",
",",
"array",
"&",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"return",
"fscanf",
"(",
"$",
"this",
"->",
"fhandle",
",",
"$",
"format",
")",
";",
"}",
"array_shift",
"(",
"$",
"params",
",",
"$",
"this",
"->",
"fhandle",
",",
"$",
"format",
")",
";",
"$",
"results",
"=",
"call_user_func_array",
"(",
"'fscanf'",
",",
"$",
"params",
")",
";",
"array_splice",
"(",
"$",
"params",
",",
"2",
")",
";",
"return",
"$",
"results",
";",
"}"
] |
Parses input from a file according to a format
@param string $format [description]
@param array $params [description]
@return mixed
@see https://php.net/manual/en/function.fscanf.php
@todo Test and make work with additional params beyond $format
|
[
"Parses",
"input",
"from",
"a",
"file",
"according",
"to",
"a",
"format"
] |
9e9b8baf761af874b95256ad2462e55fbb2b2e58
|
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/file_resources.php#L329-L338
|
25,718
|
theopera/framework
|
src/Component/WebApplication/Router.php
|
Router.fallBackRoute
|
private function fallBackRoute(RequestInterface $request) : Route
{
$parts = explode('/', $request->getPathInfo());
if (count($parts) == 2 && empty($parts[1])) {
return $this->getDefaultRoute($request);
}
$actionName = 'index';
$controllerName = ucfirst($parts[1]);
if (count($parts) > 2) {
$actionName = $parts[2];
}
$endPoint = new RouteEndpoint(
$this->context->getControllerNamespace(),
$controllerName,
$actionName,
$request->getMethod());
return new Route('/' . $parts[1] . '/' . $actionName, $endPoint);
}
|
php
|
private function fallBackRoute(RequestInterface $request) : Route
{
$parts = explode('/', $request->getPathInfo());
if (count($parts) == 2 && empty($parts[1])) {
return $this->getDefaultRoute($request);
}
$actionName = 'index';
$controllerName = ucfirst($parts[1]);
if (count($parts) > 2) {
$actionName = $parts[2];
}
$endPoint = new RouteEndpoint(
$this->context->getControllerNamespace(),
$controllerName,
$actionName,
$request->getMethod());
return new Route('/' . $parts[1] . '/' . $actionName, $endPoint);
}
|
[
"private",
"function",
"fallBackRoute",
"(",
"RequestInterface",
"$",
"request",
")",
":",
"Route",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"request",
"->",
"getPathInfo",
"(",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"==",
"2",
"&&",
"empty",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getDefaultRoute",
"(",
"$",
"request",
")",
";",
"}",
"$",
"actionName",
"=",
"'index'",
";",
"$",
"controllerName",
"=",
"ucfirst",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
">",
"2",
")",
"{",
"$",
"actionName",
"=",
"$",
"parts",
"[",
"2",
"]",
";",
"}",
"$",
"endPoint",
"=",
"new",
"RouteEndpoint",
"(",
"$",
"this",
"->",
"context",
"->",
"getControllerNamespace",
"(",
")",
",",
"$",
"controllerName",
",",
"$",
"actionName",
",",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
";",
"return",
"new",
"Route",
"(",
"'/'",
".",
"$",
"parts",
"[",
"1",
"]",
".",
"'/'",
".",
"$",
"actionName",
",",
"$",
"endPoint",
")",
";",
"}"
] |
If we cannot match a Route with the RouteCollection
we will try to find a Controller & Action that matches the uri
@param RequestInterface $request
@return Route
|
[
"If",
"we",
"cannot",
"match",
"a",
"Route",
"with",
"the",
"RouteCollection",
"we",
"will",
"try",
"to",
"find",
"a",
"Controller",
"&",
"Action",
"that",
"matches",
"the",
"uri"
] |
fa6165d3891a310faa580c81dee49a63c150c711
|
https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/WebApplication/Router.php#L97-L118
|
25,719
|
arikaim/container
|
Container.php
|
Container.add
|
public function add($id, $service, $replace = false)
{
if ($this->has($id) == true && $replace == false) {
throw new ServiceExistsException($id);
}
$this->services[$id] = $service;
}
|
php
|
public function add($id, $service, $replace = false)
{
if ($this->has($id) == true && $replace == false) {
throw new ServiceExistsException($id);
}
$this->services[$id] = $service;
}
|
[
"public",
"function",
"add",
"(",
"$",
"id",
",",
"$",
"service",
",",
"$",
"replace",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"id",
")",
"==",
"true",
"&&",
"$",
"replace",
"==",
"false",
")",
"{",
"throw",
"new",
"ServiceExistsException",
"(",
"$",
"id",
")",
";",
"}",
"$",
"this",
"->",
"services",
"[",
"$",
"id",
"]",
"=",
"$",
"service",
";",
"}"
] |
Add service to container
@param string $id Service id
@param mixed $service Service value
@param boolean $replace Replace service if exists
@throws ServiceExistsException If replace is false and service exists in container
@return void
|
[
"Add",
"service",
"to",
"container"
] |
aa0e7b62e9a0fd58839610857e466fe4838f72f5
|
https://github.com/arikaim/container/blob/aa0e7b62e9a0fd58839610857e466fe4838f72f5/Container.php#L78-L84
|
25,720
|
sndsgd/http
|
src/http/Response.php
|
Response.setStatus
|
public function setStatus(int $code): Response
{
# `Status::getText` will throw an exception for invalid status codes
$this->statusText = Status::getText($code);
$this->statusCode = $code;
return $this;
}
|
php
|
public function setStatus(int $code): Response
{
# `Status::getText` will throw an exception for invalid status codes
$this->statusText = Status::getText($code);
$this->statusCode = $code;
return $this;
}
|
[
"public",
"function",
"setStatus",
"(",
"int",
"$",
"code",
")",
":",
"Response",
"{",
"# `Status::getText` will throw an exception for invalid status codes",
"$",
"this",
"->",
"statusText",
"=",
"Status",
"::",
"getText",
"(",
"$",
"code",
")",
";",
"$",
"this",
"->",
"statusCode",
"=",
"$",
"code",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the status code and text
@see \sndsgd\http\Code
@param integer $code The http status code
@return \sndsgd\http\Response
|
[
"Set",
"the",
"status",
"code",
"and",
"text"
] |
e7f82010a66c6d3241a24ea82baf4593130c723b
|
https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/Response.php#L54-L60
|
25,721
|
sndsgd/http
|
src/http/Response.php
|
Response.addHeader
|
public function addHeader(string $key, string $value): Response
{
$this->headers->add($key, $value);
return $this;
}
|
php
|
public function addHeader(string $key, string $value): Response
{
$this->headers->add($key, $value);
return $this;
}
|
[
"public",
"function",
"addHeader",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"value",
")",
":",
"Response",
"{",
"$",
"this",
"->",
"headers",
"->",
"add",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a header
Allows for adding multiple headers with the same key
@param string $key
@param string $value
@return \sndsgd\http\Response
|
[
"Add",
"a",
"header",
"Allows",
"for",
"adding",
"multiple",
"headers",
"with",
"the",
"same",
"key"
] |
e7f82010a66c6d3241a24ea82baf4593130c723b
|
https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/Response.php#L97-L101
|
25,722
|
praxigento/mobi_mod_downline
|
Ui/DataProvider/Grid/Account/Query.php
|
Query.getQueryItems
|
protected function getQueryItems()
{
/* this is primary query builder, not extender */
$result = parent::getQueryItems();
/* define tables aliases for internal usage (in this method) */
$asDwnl = self::AS_DWNL;
$asAcc = self::AS_ACCOUNT;
/* LEFT JOIN prxgt_dwnl_customer */
$tbl = $this->resource->getTableName(EDownline::ENTITY_NAME);
$as = $asDwnl;
$cols = [
self::A_MLM_ID => EDownline::A_MLM_ID
];
$cond = $as . '.' . EDownline::A_CUSTOMER_REF . '=' . $asAcc . '.' . EAccount::A_CUST_ID;
$result->joinLeft([$as => $tbl], $cond, $cols);
/* return result */
return $result;
}
|
php
|
protected function getQueryItems()
{
/* this is primary query builder, not extender */
$result = parent::getQueryItems();
/* define tables aliases for internal usage (in this method) */
$asDwnl = self::AS_DWNL;
$asAcc = self::AS_ACCOUNT;
/* LEFT JOIN prxgt_dwnl_customer */
$tbl = $this->resource->getTableName(EDownline::ENTITY_NAME);
$as = $asDwnl;
$cols = [
self::A_MLM_ID => EDownline::A_MLM_ID
];
$cond = $as . '.' . EDownline::A_CUSTOMER_REF . '=' . $asAcc . '.' . EAccount::A_CUST_ID;
$result->joinLeft([$as => $tbl], $cond, $cols);
/* return result */
return $result;
}
|
[
"protected",
"function",
"getQueryItems",
"(",
")",
"{",
"/* this is primary query builder, not extender */",
"$",
"result",
"=",
"parent",
"::",
"getQueryItems",
"(",
")",
";",
"/* define tables aliases for internal usage (in this method) */",
"$",
"asDwnl",
"=",
"self",
"::",
"AS_DWNL",
";",
"$",
"asAcc",
"=",
"self",
"::",
"AS_ACCOUNT",
";",
"/* LEFT JOIN prxgt_dwnl_customer */",
"$",
"tbl",
"=",
"$",
"this",
"->",
"resource",
"->",
"getTableName",
"(",
"EDownline",
"::",
"ENTITY_NAME",
")",
";",
"$",
"as",
"=",
"$",
"asDwnl",
";",
"$",
"cols",
"=",
"[",
"self",
"::",
"A_MLM_ID",
"=>",
"EDownline",
"::",
"A_MLM_ID",
"]",
";",
"$",
"cond",
"=",
"$",
"as",
".",
"'.'",
".",
"EDownline",
"::",
"A_CUSTOMER_REF",
".",
"'='",
".",
"$",
"asAcc",
".",
"'.'",
".",
"EAccount",
"::",
"A_CUST_ID",
";",
"$",
"result",
"->",
"joinLeft",
"(",
"[",
"$",
"as",
"=>",
"$",
"tbl",
"]",
",",
"$",
"cond",
",",
"$",
"cols",
")",
";",
"/* return result */",
"return",
"$",
"result",
";",
"}"
] |
SELECT
...
FROM
`prxgt_acc_account` AS `paa`
LEFT JOIN `prxgt_acc_type_asset` AS `pata` ON
pata.id = paa.asset_type_id
LEFT JOIN `customer_entity` AS `ce` ON
ce.entity_id = paa.customer_id
LEFT JOIN `prxgt_dwnl_customer` AS `dwnl` ON
dwnl.customer_ref = paa.customer_id
|
[
"SELECT",
"...",
"FROM",
"prxgt_acc_account",
"AS",
"paa",
"LEFT",
"JOIN",
"prxgt_acc_type_asset",
"AS",
"pata",
"ON",
"pata",
".",
"id",
"=",
"paa",
".",
"asset_type_id",
"LEFT",
"JOIN",
"customer_entity",
"AS",
"ce",
"ON",
"ce",
".",
"entity_id",
"=",
"paa",
".",
"customer_id",
"LEFT",
"JOIN",
"prxgt_dwnl_customer",
"AS",
"dwnl",
"ON",
"dwnl",
".",
"customer_ref",
"=",
"paa",
".",
"customer_id"
] |
0f3c276dfff1aa029f9fd205ccfc56f207a2e75b
|
https://github.com/praxigento/mobi_mod_downline/blob/0f3c276dfff1aa029f9fd205ccfc56f207a2e75b/Ui/DataProvider/Grid/Account/Query.php#L54-L74
|
25,723
|
t-kanstantsin/fileupload
|
src/model/ExternalFile.php
|
ExternalFile.generateId
|
protected function generateId(): int
{
if ($this->getId() !== null) {
return $this->getId();
}
$maxIdLength = \mb_strlen((string) PHP_INT_MAX) - 1;
// try generate unique id for file
$id = mb_substr(crc32($this->getModelId()), $maxIdLength - self::ID_PATH_HASH_LENGTH)
. mb_substr(crc32($this->getActualPath()), self::ID_PATH_HASH_LENGTH);
return (int) $id;
}
|
php
|
protected function generateId(): int
{
if ($this->getId() !== null) {
return $this->getId();
}
$maxIdLength = \mb_strlen((string) PHP_INT_MAX) - 1;
// try generate unique id for file
$id = mb_substr(crc32($this->getModelId()), $maxIdLength - self::ID_PATH_HASH_LENGTH)
. mb_substr(crc32($this->getActualPath()), self::ID_PATH_HASH_LENGTH);
return (int) $id;
}
|
[
"protected",
"function",
"generateId",
"(",
")",
":",
"int",
"{",
"if",
"(",
"$",
"this",
"->",
"getId",
"(",
")",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"}",
"$",
"maxIdLength",
"=",
"\\",
"mb_strlen",
"(",
"(",
"string",
")",
"PHP_INT_MAX",
")",
"-",
"1",
";",
"// try generate unique id for file",
"$",
"id",
"=",
"mb_substr",
"(",
"crc32",
"(",
"$",
"this",
"->",
"getModelId",
"(",
")",
")",
",",
"$",
"maxIdLength",
"-",
"self",
"::",
"ID_PATH_HASH_LENGTH",
")",
".",
"mb_substr",
"(",
"crc32",
"(",
"$",
"this",
"->",
"getActualPath",
"(",
")",
")",
",",
"self",
"::",
"ID_PATH_HASH_LENGTH",
")",
";",
"return",
"(",
"int",
")",
"$",
"id",
";",
"}"
] |
Returns existed id or generate unique id based on model id and file path.
@return int
|
[
"Returns",
"existed",
"id",
"or",
"generate",
"unique",
"id",
"based",
"on",
"model",
"id",
"and",
"file",
"path",
"."
] |
d6317a9b9b36d992f09affe3900ef7d7ddfd855f
|
https://github.com/t-kanstantsin/fileupload/blob/d6317a9b9b36d992f09affe3900ef7d7ddfd855f/src/model/ExternalFile.php#L347-L360
|
25,724
|
prolic/HumusMvc
|
src/HumusMvc/Db/Service/MultiDbManagerFactory.php
|
MultiDbManagerFactory.setDefaultMetadataCache
|
protected function setDefaultMetadataCache($cache, ServiceLocatorInterface $serviceLocator)
{
$metadataCache = null;
if (is_string($cache)) {
if ($serviceLocator->has($cache)) {
$metadataCache = $serviceLocator->get($cache);
}
} else if ($cache instanceof Zend_Cache_Core) {
$metadataCache = $cache;
}
if ($metadataCache instanceof Zend_Cache_Core) {
Zend_Db_Table::setDefaultMetadataCache($metadataCache);
}
}
|
php
|
protected function setDefaultMetadataCache($cache, ServiceLocatorInterface $serviceLocator)
{
$metadataCache = null;
if (is_string($cache)) {
if ($serviceLocator->has($cache)) {
$metadataCache = $serviceLocator->get($cache);
}
} else if ($cache instanceof Zend_Cache_Core) {
$metadataCache = $cache;
}
if ($metadataCache instanceof Zend_Cache_Core) {
Zend_Db_Table::setDefaultMetadataCache($metadataCache);
}
}
|
[
"protected",
"function",
"setDefaultMetadataCache",
"(",
"$",
"cache",
",",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"$",
"metadataCache",
"=",
"null",
";",
"if",
"(",
"is_string",
"(",
"$",
"cache",
")",
")",
"{",
"if",
"(",
"$",
"serviceLocator",
"->",
"has",
"(",
"$",
"cache",
")",
")",
"{",
"$",
"metadataCache",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"$",
"cache",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"cache",
"instanceof",
"Zend_Cache_Core",
")",
"{",
"$",
"metadataCache",
"=",
"$",
"cache",
";",
"}",
"if",
"(",
"$",
"metadataCache",
"instanceof",
"Zend_Cache_Core",
")",
"{",
"Zend_Db_Table",
"::",
"setDefaultMetadataCache",
"(",
"$",
"metadataCache",
")",
";",
"}",
"}"
] |
Set the default metadata cache
@param string|Zend_Cache_Core $cache
@return void
|
[
"Set",
"the",
"default",
"metadata",
"cache"
] |
09e8c6422d84b57745cc643047e10761be2a21a7
|
https://github.com/prolic/HumusMvc/blob/09e8c6422d84b57745cc643047e10761be2a21a7/src/HumusMvc/Db/Service/MultiDbManagerFactory.php#L81-L97
|
25,725
|
romm/configuration_object
|
Classes/Service/AbstractService.php
|
AbstractService.checkUnknownOptions
|
protected function checkUnknownOptions(array $options)
{
$unsupportedOptions = array_diff_key($options, $this->supportedOptions);
if ([] !== ($unsupportedOptions)) {
throw new InvalidServiceOptionsException(
'Unsupported validation option(s) found: ' . implode(', ', array_keys($unsupportedOptions)),
1456397655
);
}
}
|
php
|
protected function checkUnknownOptions(array $options)
{
$unsupportedOptions = array_diff_key($options, $this->supportedOptions);
if ([] !== ($unsupportedOptions)) {
throw new InvalidServiceOptionsException(
'Unsupported validation option(s) found: ' . implode(', ', array_keys($unsupportedOptions)),
1456397655
);
}
}
|
[
"protected",
"function",
"checkUnknownOptions",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"unsupportedOptions",
"=",
"array_diff_key",
"(",
"$",
"options",
",",
"$",
"this",
"->",
"supportedOptions",
")",
";",
"if",
"(",
"[",
"]",
"!==",
"(",
"$",
"unsupportedOptions",
")",
")",
"{",
"throw",
"new",
"InvalidServiceOptionsException",
"(",
"'Unsupported validation option(s) found: '",
".",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"unsupportedOptions",
")",
")",
",",
"1456397655",
")",
";",
"}",
"}"
] |
Checks if an unknown option exists in the given options array.
@param array $options
@throws InvalidServiceOptionsException
|
[
"Checks",
"if",
"an",
"unknown",
"option",
"exists",
"in",
"the",
"given",
"options",
"array",
"."
] |
d3a40903386c2e0766bd8279337fe6da45cf5ce3
|
https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/AbstractService.php#L85-L95
|
25,726
|
romm/configuration_object
|
Classes/Service/AbstractService.php
|
AbstractService.checkRequiredOptions
|
protected function checkRequiredOptions(array $options)
{
array_walk(
$this->supportedOptions,
function ($supportedOptionData, $supportedOptionName, $options) {
if (isset($supportedOptionData[1])
&& true === $supportedOptionData[1]
&& empty($supportedOptionData[0])
&& !array_key_exists($supportedOptionName, $options)
) {
throw new InvalidServiceOptionsException(
'Required validation option not set: ' . $supportedOptionName,
1456397839
);
}
},
$options
);
}
|
php
|
protected function checkRequiredOptions(array $options)
{
array_walk(
$this->supportedOptions,
function ($supportedOptionData, $supportedOptionName, $options) {
if (isset($supportedOptionData[1])
&& true === $supportedOptionData[1]
&& empty($supportedOptionData[0])
&& !array_key_exists($supportedOptionName, $options)
) {
throw new InvalidServiceOptionsException(
'Required validation option not set: ' . $supportedOptionName,
1456397839
);
}
},
$options
);
}
|
[
"protected",
"function",
"checkRequiredOptions",
"(",
"array",
"$",
"options",
")",
"{",
"array_walk",
"(",
"$",
"this",
"->",
"supportedOptions",
",",
"function",
"(",
"$",
"supportedOptionData",
",",
"$",
"supportedOptionName",
",",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"supportedOptionData",
"[",
"1",
"]",
")",
"&&",
"true",
"===",
"$",
"supportedOptionData",
"[",
"1",
"]",
"&&",
"empty",
"(",
"$",
"supportedOptionData",
"[",
"0",
"]",
")",
"&&",
"!",
"array_key_exists",
"(",
"$",
"supportedOptionName",
",",
"$",
"options",
")",
")",
"{",
"throw",
"new",
"InvalidServiceOptionsException",
"(",
"'Required validation option not set: '",
".",
"$",
"supportedOptionName",
",",
"1456397839",
")",
";",
"}",
"}",
",",
"$",
"options",
")",
";",
"}"
] |
Will check if the required options are correctly filled.
@param array $options
@throws InvalidServiceOptionsException
|
[
"Will",
"check",
"if",
"the",
"required",
"options",
"are",
"correctly",
"filled",
"."
] |
d3a40903386c2e0766bd8279337fe6da45cf5ce3
|
https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/AbstractService.php#L103-L121
|
25,727
|
romm/configuration_object
|
Classes/Service/AbstractService.php
|
AbstractService.fillOptionsWithValues
|
protected function fillOptionsWithValues(array $options)
{
return array_merge(
array_map(
function ($value) {
if (false === is_array($value)) {
throw new InvalidTypeException(
'Supported options of a service must be an array with a value as first entry, and a flag to tell if the option is required in the second entry.',
1459249834
);
}
return $value[0];
},
$this->supportedOptions
),
$options
);
}
|
php
|
protected function fillOptionsWithValues(array $options)
{
return array_merge(
array_map(
function ($value) {
if (false === is_array($value)) {
throw new InvalidTypeException(
'Supported options of a service must be an array with a value as first entry, and a flag to tell if the option is required in the second entry.',
1459249834
);
}
return $value[0];
},
$this->supportedOptions
),
$options
);
}
|
[
"protected",
"function",
"fillOptionsWithValues",
"(",
"array",
"$",
"options",
")",
"{",
"return",
"array_merge",
"(",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"InvalidTypeException",
"(",
"'Supported options of a service must be an array with a value as first entry, and a flag to tell if the option is required in the second entry.'",
",",
"1459249834",
")",
";",
"}",
"return",
"$",
"value",
"[",
"0",
"]",
";",
"}",
",",
"$",
"this",
"->",
"supportedOptions",
")",
",",
"$",
"options",
")",
";",
"}"
] |
Will fill the options of this service with the given values.
@param array $options
@return array
@throws InvalidTypeException
|
[
"Will",
"fill",
"the",
"options",
"of",
"this",
"service",
"with",
"the",
"given",
"values",
"."
] |
d3a40903386c2e0766bd8279337fe6da45cf5ce3
|
https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/AbstractService.php#L130-L148
|
25,728
|
romm/configuration_object
|
Classes/Service/AbstractService.php
|
AbstractService.delay
|
protected function delay($priority, callable $callback)
{
if (false === MathUtility::canBeInterpretedAsInteger($priority)) {
throw new InvalidTypeException(
'The priority must be an integer, ' . gettype($priority) . ' was given.',
1457014282
);
}
if (false === isset(static::$delayedCallbacks[$priority])) {
static::$delayedCallbacks[$priority] = [];
}
static::$delayedCallbacks[$priority][] = $callback;
}
|
php
|
protected function delay($priority, callable $callback)
{
if (false === MathUtility::canBeInterpretedAsInteger($priority)) {
throw new InvalidTypeException(
'The priority must be an integer, ' . gettype($priority) . ' was given.',
1457014282
);
}
if (false === isset(static::$delayedCallbacks[$priority])) {
static::$delayedCallbacks[$priority] = [];
}
static::$delayedCallbacks[$priority][] = $callback;
}
|
[
"protected",
"function",
"delay",
"(",
"$",
"priority",
",",
"callable",
"$",
"callback",
")",
"{",
"if",
"(",
"false",
"===",
"MathUtility",
"::",
"canBeInterpretedAsInteger",
"(",
"$",
"priority",
")",
")",
"{",
"throw",
"new",
"InvalidTypeException",
"(",
"'The priority must be an integer, '",
".",
"gettype",
"(",
"$",
"priority",
")",
".",
"' was given.'",
",",
"1457014282",
")",
";",
"}",
"if",
"(",
"false",
"===",
"isset",
"(",
"static",
"::",
"$",
"delayedCallbacks",
"[",
"$",
"priority",
"]",
")",
")",
"{",
"static",
"::",
"$",
"delayedCallbacks",
"[",
"$",
"priority",
"]",
"=",
"[",
"]",
";",
"}",
"static",
"::",
"$",
"delayedCallbacks",
"[",
"$",
"priority",
"]",
"[",
"]",
"=",
"$",
"callback",
";",
"}"
] |
Use this function to delay a certain part of the script during an event
dispatch. This allows to run parts of the script in a sorted way, based
on a priority value.
The higher the priority is, the faster the script will run.
Please note that the usage of this function is not needed in every event.
@param int $priority Priority: the higher it is, the faster the script will run.
@param callable $callback Function which will be called later.
@throws InvalidTypeException
|
[
"Use",
"this",
"function",
"to",
"delay",
"a",
"certain",
"part",
"of",
"the",
"script",
"during",
"an",
"event",
"dispatch",
".",
"This",
"allows",
"to",
"run",
"parts",
"of",
"the",
"script",
"in",
"a",
"sorted",
"way",
"based",
"on",
"a",
"priority",
"value",
"."
] |
d3a40903386c2e0766bd8279337fe6da45cf5ce3
|
https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/AbstractService.php#L171-L184
|
25,729
|
romm/configuration_object
|
Classes/Service/AbstractService.php
|
AbstractService.runDelayedCallbacks
|
public function runDelayedCallbacks(AbstractServiceDTO $dto)
{
krsort(static::$delayedCallbacks);
foreach (static::$delayedCallbacks as $callbacks) {
foreach ($callbacks as $callback) {
$callback($dto);
}
}
static::$delayedCallbacks = [];
}
|
php
|
public function runDelayedCallbacks(AbstractServiceDTO $dto)
{
krsort(static::$delayedCallbacks);
foreach (static::$delayedCallbacks as $callbacks) {
foreach ($callbacks as $callback) {
$callback($dto);
}
}
static::$delayedCallbacks = [];
}
|
[
"public",
"function",
"runDelayedCallbacks",
"(",
"AbstractServiceDTO",
"$",
"dto",
")",
"{",
"krsort",
"(",
"static",
"::",
"$",
"delayedCallbacks",
")",
";",
"foreach",
"(",
"static",
"::",
"$",
"delayedCallbacks",
"as",
"$",
"callbacks",
")",
"{",
"foreach",
"(",
"$",
"callbacks",
"as",
"$",
"callback",
")",
"{",
"$",
"callback",
"(",
"$",
"dto",
")",
";",
"}",
"}",
"static",
"::",
"$",
"delayedCallbacks",
"=",
"[",
"]",
";",
"}"
] |
Will run every delayed callback which was registered during an event.
@see \Romm\ConfigurationObject\Service\AbstractService::delay()
@param AbstractServiceDTO $dto The data transfer object sent to the services.
@internal This function is reserved for internal usage only, you should not use it in third party applications!
|
[
"Will",
"run",
"every",
"delayed",
"callback",
"which",
"was",
"registered",
"during",
"an",
"event",
"."
] |
d3a40903386c2e0766bd8279337fe6da45cf5ce3
|
https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/AbstractService.php#L194-L205
|
25,730
|
ARCANESOFT/Blog
|
src/Http/Requests/Admin/Posts/CreatePostRequest.php
|
CreatePostRequest.sanitize
|
protected function sanitize()
{
return [
'slug' => Str::slug($this->get($this->has('slug') ? 'slug' : 'title', '')),
'seo_title' => $this->get(empty($this->get('seo_title')) ? 'title' : 'seo_title'),
];
}
|
php
|
protected function sanitize()
{
return [
'slug' => Str::slug($this->get($this->has('slug') ? 'slug' : 'title', '')),
'seo_title' => $this->get(empty($this->get('seo_title')) ? 'title' : 'seo_title'),
];
}
|
[
"protected",
"function",
"sanitize",
"(",
")",
"{",
"return",
"[",
"'slug'",
"=>",
"Str",
"::",
"slug",
"(",
"$",
"this",
"->",
"get",
"(",
"$",
"this",
"->",
"has",
"(",
"'slug'",
")",
"?",
"'slug'",
":",
"'title'",
",",
"''",
")",
")",
",",
"'seo_title'",
"=>",
"$",
"this",
"->",
"get",
"(",
"empty",
"(",
"$",
"this",
"->",
"get",
"(",
"'seo_title'",
")",
")",
"?",
"'title'",
":",
"'seo_title'",
")",
",",
"]",
";",
"}"
] |
Sanitize the inputs.
@return array
|
[
"Sanitize",
"the",
"inputs",
"."
] |
2078fdfdcbccda161c02899b9e1f344f011b2859
|
https://github.com/ARCANESOFT/Blog/blob/2078fdfdcbccda161c02899b9e1f344f011b2859/src/Http/Requests/Admin/Posts/CreatePostRequest.php#L45-L51
|
25,731
|
lasallecms/lasallecms-l5-usermanagement-pkg
|
src/Validation/ForbiddenTLD.php
|
ForbiddenTLD.validateForbiddenTLD
|
public function validateForbiddenTLD($email, $specifiedTLDs = array()) {
$forbiddenTLDs = $this->getTheForbiddenTLDs($specifiedTLDs);
// if no TLD's specified in the parameters; and, no TLD's specified in the config,
// then deem the validation as kosher
if (empty($forbiddenTLDs)) return true;
// initialize var
$validation = true;
foreach ($forbiddenTLDs as $forbiddenTLD)
{
$lengthOfForbiddenTLD = $this->lengthForbiddenTLD($forbiddenTLD);
$lastCharactersOfEmail = $this->lastCharactersOfEmail($email, $lengthOfForbiddenTLD);
// validate
if ($this->compareEmailWithForbiddenTLD($lastCharactersOfEmail, $forbiddenTLD) )
{
$validation = false;
}
}
return $validation;
}
|
php
|
public function validateForbiddenTLD($email, $specifiedTLDs = array()) {
$forbiddenTLDs = $this->getTheForbiddenTLDs($specifiedTLDs);
// if no TLD's specified in the parameters; and, no TLD's specified in the config,
// then deem the validation as kosher
if (empty($forbiddenTLDs)) return true;
// initialize var
$validation = true;
foreach ($forbiddenTLDs as $forbiddenTLD)
{
$lengthOfForbiddenTLD = $this->lengthForbiddenTLD($forbiddenTLD);
$lastCharactersOfEmail = $this->lastCharactersOfEmail($email, $lengthOfForbiddenTLD);
// validate
if ($this->compareEmailWithForbiddenTLD($lastCharactersOfEmail, $forbiddenTLD) )
{
$validation = false;
}
}
return $validation;
}
|
[
"public",
"function",
"validateForbiddenTLD",
"(",
"$",
"email",
",",
"$",
"specifiedTLDs",
"=",
"array",
"(",
")",
")",
"{",
"$",
"forbiddenTLDs",
"=",
"$",
"this",
"->",
"getTheForbiddenTLDs",
"(",
"$",
"specifiedTLDs",
")",
";",
"// if no TLD's specified in the parameters; and, no TLD's specified in the config,",
"// then deem the validation as kosher",
"if",
"(",
"empty",
"(",
"$",
"forbiddenTLDs",
")",
")",
"return",
"true",
";",
"// initialize var",
"$",
"validation",
"=",
"true",
";",
"foreach",
"(",
"$",
"forbiddenTLDs",
"as",
"$",
"forbiddenTLD",
")",
"{",
"$",
"lengthOfForbiddenTLD",
"=",
"$",
"this",
"->",
"lengthForbiddenTLD",
"(",
"$",
"forbiddenTLD",
")",
";",
"$",
"lastCharactersOfEmail",
"=",
"$",
"this",
"->",
"lastCharactersOfEmail",
"(",
"$",
"email",
",",
"$",
"lengthOfForbiddenTLD",
")",
";",
"// validate",
"if",
"(",
"$",
"this",
"->",
"compareEmailWithForbiddenTLD",
"(",
"$",
"lastCharactersOfEmail",
",",
"$",
"forbiddenTLD",
")",
")",
"{",
"$",
"validation",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"validation",
";",
"}"
] |
Validate Top Level Domains
@param string $email
@param array $specifiedTLDs So unit test can specify its own array of forbidden TLDs
@return bool
|
[
"Validate",
"Top",
"Level",
"Domains"
] |
b5203d596e18e2566e7fdcd3f13868bb44a94c1d
|
https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Validation/ForbiddenTLD.php#L53-L77
|
25,732
|
palmtreephp/nameconverter
|
SnakeCaseToCamelCaseNameConverter.php
|
SnakeCaseToCamelCaseNameConverter.denormalize
|
public function denormalize($input)
{
$lcPropertyName = lcfirst($input);
$snakeCasedName = '';
$len = strlen($lcPropertyName);
for ($i = 0; $i < $len; ++$i) {
if (ctype_upper($lcPropertyName[$i])) {
$snakeCasedName .= '_' . strtolower($lcPropertyName[$i]);
} else {
$snakeCasedName .= strtolower($lcPropertyName[$i]);
}
}
return $snakeCasedName;
}
|
php
|
public function denormalize($input)
{
$lcPropertyName = lcfirst($input);
$snakeCasedName = '';
$len = strlen($lcPropertyName);
for ($i = 0; $i < $len; ++$i) {
if (ctype_upper($lcPropertyName[$i])) {
$snakeCasedName .= '_' . strtolower($lcPropertyName[$i]);
} else {
$snakeCasedName .= strtolower($lcPropertyName[$i]);
}
}
return $snakeCasedName;
}
|
[
"public",
"function",
"denormalize",
"(",
"$",
"input",
")",
"{",
"$",
"lcPropertyName",
"=",
"lcfirst",
"(",
"$",
"input",
")",
";",
"$",
"snakeCasedName",
"=",
"''",
";",
"$",
"len",
"=",
"strlen",
"(",
"$",
"lcPropertyName",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"++",
"$",
"i",
")",
"{",
"if",
"(",
"ctype_upper",
"(",
"$",
"lcPropertyName",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"snakeCasedName",
".=",
"'_'",
".",
"strtolower",
"(",
"$",
"lcPropertyName",
"[",
"$",
"i",
"]",
")",
";",
"}",
"else",
"{",
"$",
"snakeCasedName",
".=",
"strtolower",
"(",
"$",
"lcPropertyName",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"return",
"$",
"snakeCasedName",
";",
"}"
] |
Converts a string like 'myInput' to 'my_input'
@param $input
@return string
|
[
"Converts",
"a",
"string",
"like",
"myInput",
"to",
"my_input"
] |
ccec2ac6134cd8941ea9a83fa0a8588615443c9b
|
https://github.com/palmtreephp/nameconverter/blob/ccec2ac6134cd8941ea9a83fa0a8588615443c9b/SnakeCaseToCamelCaseNameConverter.php#L41-L56
|
25,733
|
modulusphp/utility
|
RouteQuery.php
|
RouteQuery.persist
|
public function persist($eloquent, $field, $value, $name)
{
return $this->handle($eloquent, $field, $value, $name);
}
|
php
|
public function persist($eloquent, $field, $value, $name)
{
return $this->handle($eloquent, $field, $value, $name);
}
|
[
"public",
"function",
"persist",
"(",
"$",
"eloquent",
",",
"$",
"field",
",",
"$",
"value",
",",
"$",
"name",
")",
"{",
"return",
"$",
"this",
"->",
"handle",
"(",
"$",
"eloquent",
",",
"$",
"field",
",",
"$",
"value",
",",
"$",
"name",
")",
";",
"}"
] |
Persist route query
@param mixed $eloquent
@param mixed $field
@param mixed $value
@return mixed
|
[
"Persist",
"route",
"query"
] |
c1e127539b13d3ec8381e41c64b881e0701807f5
|
https://github.com/modulusphp/utility/blob/c1e127539b13d3ec8381e41c64b881e0701807f5/RouteQuery.php#L15-L18
|
25,734
|
rollerworks-graveyard/metadata
|
src/CacheableMetadataFactory.php
|
CacheableMetadataFactory.freshOrNull
|
private function freshOrNull(ClassMetadata $classMetadata = null)
{
if (null === $classMetadata) {
return;
}
return $this->freshnessValidator->isFresh($classMetadata) ? $classMetadata : null;
}
|
php
|
private function freshOrNull(ClassMetadata $classMetadata = null)
{
if (null === $classMetadata) {
return;
}
return $this->freshnessValidator->isFresh($classMetadata) ? $classMetadata : null;
}
|
[
"private",
"function",
"freshOrNull",
"(",
"ClassMetadata",
"$",
"classMetadata",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"classMetadata",
")",
"{",
"return",
";",
"}",
"return",
"$",
"this",
"->",
"freshnessValidator",
"->",
"isFresh",
"(",
"$",
"classMetadata",
")",
"?",
"$",
"classMetadata",
":",
"null",
";",
"}"
] |
Internal method for handling refreshing of metadata.
@param ClassMetadata|null $classMetadata
@return ClassMetadata|null
|
[
"Internal",
"method",
"for",
"handling",
"refreshing",
"of",
"metadata",
"."
] |
5b07f564aad87709ca0d0b3e140e4dc4edf9d375
|
https://github.com/rollerworks-graveyard/metadata/blob/5b07f564aad87709ca0d0b3e140e4dc4edf9d375/src/CacheableMetadataFactory.php#L133-L140
|
25,735
|
danielgp/common-lib
|
source/CommonLibLocale.php
|
CommonLibLocale.handleLocalizationCommon
|
private function handleLocalizationCommon()
{
$this->handleLanguageIntoSession();
$localizationFile = $this->getCommonLocaleFolder() . '/locale/'
. $this->tCmnSession->get('lang') . '/LC_MESSAGES/'
. $this->commonLibFlags['localization_domain'] . '.mo';
$translations = new \Gettext\Translations();
$translations->addFromMoFile($localizationFile);
$this->tCmnLb = new \Gettext\Translator();
$this->tCmnLb->loadTranslations($translations);
}
|
php
|
private function handleLocalizationCommon()
{
$this->handleLanguageIntoSession();
$localizationFile = $this->getCommonLocaleFolder() . '/locale/'
. $this->tCmnSession->get('lang') . '/LC_MESSAGES/'
. $this->commonLibFlags['localization_domain'] . '.mo';
$translations = new \Gettext\Translations();
$translations->addFromMoFile($localizationFile);
$this->tCmnLb = new \Gettext\Translator();
$this->tCmnLb->loadTranslations($translations);
}
|
[
"private",
"function",
"handleLocalizationCommon",
"(",
")",
"{",
"$",
"this",
"->",
"handleLanguageIntoSession",
"(",
")",
";",
"$",
"localizationFile",
"=",
"$",
"this",
"->",
"getCommonLocaleFolder",
"(",
")",
".",
"'/locale/'",
".",
"$",
"this",
"->",
"tCmnSession",
"->",
"get",
"(",
"'lang'",
")",
".",
"'/LC_MESSAGES/'",
".",
"$",
"this",
"->",
"commonLibFlags",
"[",
"'localization_domain'",
"]",
".",
"'.mo'",
";",
"$",
"translations",
"=",
"new",
"\\",
"Gettext",
"\\",
"Translations",
"(",
")",
";",
"$",
"translations",
"->",
"addFromMoFile",
"(",
"$",
"localizationFile",
")",
";",
"$",
"this",
"->",
"tCmnLb",
"=",
"new",
"\\",
"Gettext",
"\\",
"Translator",
"(",
")",
";",
"$",
"this",
"->",
"tCmnLb",
"->",
"loadTranslations",
"(",
"$",
"translations",
")",
";",
"}"
] |
Takes care of instantiation of localization libraries
used within current module for multi-languages support
|
[
"Takes",
"care",
"of",
"instantiation",
"of",
"localization",
"libraries",
"used",
"within",
"current",
"module",
"for",
"multi",
"-",
"languages",
"support"
] |
627b99b4408414c7cd21a6c8016f6468dc9216b2
|
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonLibLocale.php#L106-L116
|
25,736
|
danielgp/common-lib
|
source/CommonLibLocale.php
|
CommonLibLocale.setDividedResult
|
public function setDividedResult($fAbove, $fBelow, $mArguments = null)
{
if (($fAbove == 0) || ($fBelow == 0)) { // prevent infinite result AND division by 0
return 0;
}
$numberToFormat = ($fAbove / $fBelow);
if (is_numeric($mArguments)) {
$frMinMax = [
'MinFractionDigits' => $mArguments,
'MaxFractionDigits' => $mArguments,
];
return $this->setNumberFormat($numberToFormat, $frMinMax);
}
return $this->setNumberFormat(round($numberToFormat, $mArguments));
}
|
php
|
public function setDividedResult($fAbove, $fBelow, $mArguments = null)
{
if (($fAbove == 0) || ($fBelow == 0)) { // prevent infinite result AND division by 0
return 0;
}
$numberToFormat = ($fAbove / $fBelow);
if (is_numeric($mArguments)) {
$frMinMax = [
'MinFractionDigits' => $mArguments,
'MaxFractionDigits' => $mArguments,
];
return $this->setNumberFormat($numberToFormat, $frMinMax);
}
return $this->setNumberFormat(round($numberToFormat, $mArguments));
}
|
[
"public",
"function",
"setDividedResult",
"(",
"$",
"fAbove",
",",
"$",
"fBelow",
",",
"$",
"mArguments",
"=",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"fAbove",
"==",
"0",
")",
"||",
"(",
"$",
"fBelow",
"==",
"0",
")",
")",
"{",
"// prevent infinite result AND division by 0",
"return",
"0",
";",
"}",
"$",
"numberToFormat",
"=",
"(",
"$",
"fAbove",
"/",
"$",
"fBelow",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"mArguments",
")",
")",
"{",
"$",
"frMinMax",
"=",
"[",
"'MinFractionDigits'",
"=>",
"$",
"mArguments",
",",
"'MaxFractionDigits'",
"=>",
"$",
"mArguments",
",",
"]",
";",
"return",
"$",
"this",
"->",
"setNumberFormat",
"(",
"$",
"numberToFormat",
",",
"$",
"frMinMax",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setNumberFormat",
"(",
"round",
"(",
"$",
"numberToFormat",
",",
"$",
"mArguments",
")",
")",
";",
"}"
] |
Returns proper result from a mathematical division in order to avoid
Zero division error or Infinite results
@param float $fAbove
@param float $fBelow
@param mixed $mArguments
@return string
|
[
"Returns",
"proper",
"result",
"from",
"a",
"mathematical",
"division",
"in",
"order",
"to",
"avoid",
"Zero",
"division",
"error",
"or",
"Infinite",
"results"
] |
627b99b4408414c7cd21a6c8016f6468dc9216b2
|
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonLibLocale.php#L173-L187
|
25,737
|
tw88/sso
|
src/Server.php
|
Server.startBrokerSession
|
public function startBrokerSession()
{
if (isset($this->brokerId)) {
return;
}
$sid = $this->getBrokerSessionID();
if ($sid === false) {
return $this->fail("Broker didn't send a session key", 400);
}
$linkedId = $this->cache->get($sid);
if (!$linkedId) {
return $this->fail("The broker session id isn't attached to a user session", 403);
}
if (session_status() === PHP_SESSION_ACTIVE) {
if ($linkedId !== session_id()) {
throw new \Exception("Session has already started", 400);
}
return;
}
session_id($linkedId);
session_start();
$this->brokerId = $this->validateBrokerSessionId($sid);
}
|
php
|
public function startBrokerSession()
{
if (isset($this->brokerId)) {
return;
}
$sid = $this->getBrokerSessionID();
if ($sid === false) {
return $this->fail("Broker didn't send a session key", 400);
}
$linkedId = $this->cache->get($sid);
if (!$linkedId) {
return $this->fail("The broker session id isn't attached to a user session", 403);
}
if (session_status() === PHP_SESSION_ACTIVE) {
if ($linkedId !== session_id()) {
throw new \Exception("Session has already started", 400);
}
return;
}
session_id($linkedId);
session_start();
$this->brokerId = $this->validateBrokerSessionId($sid);
}
|
[
"public",
"function",
"startBrokerSession",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"brokerId",
")",
")",
"{",
"return",
";",
"}",
"$",
"sid",
"=",
"$",
"this",
"->",
"getBrokerSessionID",
"(",
")",
";",
"if",
"(",
"$",
"sid",
"===",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"fail",
"(",
"\"Broker didn't send a session key\"",
",",
"400",
")",
";",
"}",
"$",
"linkedId",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"sid",
")",
";",
"if",
"(",
"!",
"$",
"linkedId",
")",
"{",
"return",
"$",
"this",
"->",
"fail",
"(",
"\"The broker session id isn't attached to a user session\"",
",",
"403",
")",
";",
"}",
"if",
"(",
"session_status",
"(",
")",
"===",
"PHP_SESSION_ACTIVE",
")",
"{",
"if",
"(",
"$",
"linkedId",
"!==",
"session_id",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Session has already started\"",
",",
"400",
")",
";",
"}",
"return",
";",
"}",
"session_id",
"(",
"$",
"linkedId",
")",
";",
"session_start",
"(",
")",
";",
"$",
"this",
"->",
"brokerId",
"=",
"$",
"this",
"->",
"validateBrokerSessionId",
"(",
"$",
"sid",
")",
";",
"}"
] |
Start the session for broker requests to the SSO server
|
[
"Start",
"the",
"session",
"for",
"broker",
"requests",
"to",
"the",
"SSO",
"server"
] |
746323f3087af5a06769f7c207ab4ed5124a14bb
|
https://github.com/tw88/sso/blob/746323f3087af5a06769f7c207ab4ed5124a14bb/src/Server.php#L68-L97
|
25,738
|
tw88/sso
|
src/Server.php
|
Server.generateSessionId
|
protected function generateSessionId($brokerId, $token)
{
$broker = $this->getBrokerInfo($brokerId);
if (!isset($broker)) {
return null;
}
return "SSO-{$brokerId}-{$token}-" . hash('sha256', 'session' . $token . $broker['secret']);
}
|
php
|
protected function generateSessionId($brokerId, $token)
{
$broker = $this->getBrokerInfo($brokerId);
if (!isset($broker)) {
return null;
}
return "SSO-{$brokerId}-{$token}-" . hash('sha256', 'session' . $token . $broker['secret']);
}
|
[
"protected",
"function",
"generateSessionId",
"(",
"$",
"brokerId",
",",
"$",
"token",
")",
"{",
"$",
"broker",
"=",
"$",
"this",
"->",
"getBrokerInfo",
"(",
"$",
"brokerId",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"broker",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"\"SSO-{$brokerId}-{$token}-\"",
".",
"hash",
"(",
"'sha256'",
",",
"'session'",
".",
"$",
"token",
".",
"$",
"broker",
"[",
"'secret'",
"]",
")",
";",
"}"
] |
Generate session id from session token
@param string $brokerId
@param string $token
@return string
|
[
"Generate",
"session",
"id",
"from",
"session",
"token"
] |
746323f3087af5a06769f7c207ab4ed5124a14bb
|
https://github.com/tw88/sso/blob/746323f3087af5a06769f7c207ab4ed5124a14bb/src/Server.php#L164-L173
|
25,739
|
tw88/sso
|
src/Server.php
|
Server.detectReturnType
|
protected function detectReturnType()
{
if (isset($_GET['cookie'])) {
$this->returnType = 'none';
return;
} elseif (!empty($_GET['return_url'])) {
$this->returnType = 'redirect';
} elseif (!empty($_GET['callback'])) {
$this->returnType = 'jsonp';
} elseif (strpos($_SERVER['HTTP_ACCEPT'], 'image/') !== false) {
$this->returnType = 'image';
} elseif (strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) {
$this->returnType = 'json';
}
}
|
php
|
protected function detectReturnType()
{
if (isset($_GET['cookie'])) {
$this->returnType = 'none';
return;
} elseif (!empty($_GET['return_url'])) {
$this->returnType = 'redirect';
} elseif (!empty($_GET['callback'])) {
$this->returnType = 'jsonp';
} elseif (strpos($_SERVER['HTTP_ACCEPT'], 'image/') !== false) {
$this->returnType = 'image';
} elseif (strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) {
$this->returnType = 'json';
}
}
|
[
"protected",
"function",
"detectReturnType",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'cookie'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"returnType",
"=",
"'none'",
";",
"return",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"_GET",
"[",
"'return_url'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"returnType",
"=",
"'redirect'",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"_GET",
"[",
"'callback'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"returnType",
"=",
"'jsonp'",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
",",
"'image/'",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"returnType",
"=",
"'image'",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
",",
"'application/json'",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"returnType",
"=",
"'json'",
";",
"}",
"}"
] |
Detect the type for the HTTP response.
Should only be done for an `attach` request.
|
[
"Detect",
"the",
"type",
"for",
"the",
"HTTP",
"response",
".",
"Should",
"only",
"be",
"done",
"for",
"an",
"attach",
"request",
"."
] |
746323f3087af5a06769f7c207ab4ed5124a14bb
|
https://github.com/tw88/sso/blob/746323f3087af5a06769f7c207ab4ed5124a14bb/src/Server.php#L198-L212
|
25,740
|
tw88/sso
|
src/Server.php
|
Server.attach
|
public function attach()
{
$this->detectReturnType();
if (empty($_REQUEST['broker'])) {
return $this->fail("No broker specified", 400);
}
if (empty($_REQUEST['token'])) {
return $this->fail("No token specified", 400);
}
if (!$this->returnType) {
return $this->fail("No return url specified", 400);
}
$checksum = $this->generateAttachChecksum($_REQUEST['broker'], $_REQUEST['token']);
if (empty($_REQUEST['checksum']) || $checksum != $_REQUEST['checksum']) {
return $this->fail("Invalid checksum", 400);
}
$this->startUserSession();
$sid = $this->generateSessionId($_REQUEST['broker'], $_REQUEST['token']);
$this->cache->set($sid, $this->getSessionData('id'));
$this->outputAttachSuccess();
}
|
php
|
public function attach()
{
$this->detectReturnType();
if (empty($_REQUEST['broker'])) {
return $this->fail("No broker specified", 400);
}
if (empty($_REQUEST['token'])) {
return $this->fail("No token specified", 400);
}
if (!$this->returnType) {
return $this->fail("No return url specified", 400);
}
$checksum = $this->generateAttachChecksum($_REQUEST['broker'], $_REQUEST['token']);
if (empty($_REQUEST['checksum']) || $checksum != $_REQUEST['checksum']) {
return $this->fail("Invalid checksum", 400);
}
$this->startUserSession();
$sid = $this->generateSessionId($_REQUEST['broker'], $_REQUEST['token']);
$this->cache->set($sid, $this->getSessionData('id'));
$this->outputAttachSuccess();
}
|
[
"public",
"function",
"attach",
"(",
")",
"{",
"$",
"this",
"->",
"detectReturnType",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"_REQUEST",
"[",
"'broker'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"fail",
"(",
"\"No broker specified\"",
",",
"400",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"_REQUEST",
"[",
"'token'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"fail",
"(",
"\"No token specified\"",
",",
"400",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"returnType",
")",
"{",
"return",
"$",
"this",
"->",
"fail",
"(",
"\"No return url specified\"",
",",
"400",
")",
";",
"}",
"$",
"checksum",
"=",
"$",
"this",
"->",
"generateAttachChecksum",
"(",
"$",
"_REQUEST",
"[",
"'broker'",
"]",
",",
"$",
"_REQUEST",
"[",
"'token'",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"_REQUEST",
"[",
"'checksum'",
"]",
")",
"||",
"$",
"checksum",
"!=",
"$",
"_REQUEST",
"[",
"'checksum'",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"fail",
"(",
"\"Invalid checksum\"",
",",
"400",
")",
";",
"}",
"$",
"this",
"->",
"startUserSession",
"(",
")",
";",
"$",
"sid",
"=",
"$",
"this",
"->",
"generateSessionId",
"(",
"$",
"_REQUEST",
"[",
"'broker'",
"]",
",",
"$",
"_REQUEST",
"[",
"'token'",
"]",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"$",
"sid",
",",
"$",
"this",
"->",
"getSessionData",
"(",
"'id'",
")",
")",
";",
"$",
"this",
"->",
"outputAttachSuccess",
"(",
")",
";",
"}"
] |
Attach a user session to a broker session
|
[
"Attach",
"a",
"user",
"session",
"to",
"a",
"broker",
"session"
] |
746323f3087af5a06769f7c207ab4ed5124a14bb
|
https://github.com/tw88/sso/blob/746323f3087af5a06769f7c207ab4ed5124a14bb/src/Server.php#L217-L244
|
25,741
|
tw88/sso
|
src/Server.php
|
Server.outputAttachSuccess
|
protected function outputAttachSuccess()
{
if ($this->returnType === 'image') {
$this->outputImage();
}
if ($this->returnType === 'json' || $this->returnType === 'none') {
header('Content-type: application/json; charset=UTF-8');
echo json_encode(['success' => 'attached']);
}
if ($this->returnType === 'jsonp') {
$data = json_encode(['success' => 'attached']);
echo $_REQUEST['callback'] . "($data, 200);";
}
if ($this->returnType === 'redirect') {
$url = $_REQUEST['return_url'];
header("Location: $url", true, 307);
echo "You're being redirected to <a href='{$url}'>$url</a>";
}
}
|
php
|
protected function outputAttachSuccess()
{
if ($this->returnType === 'image') {
$this->outputImage();
}
if ($this->returnType === 'json' || $this->returnType === 'none') {
header('Content-type: application/json; charset=UTF-8');
echo json_encode(['success' => 'attached']);
}
if ($this->returnType === 'jsonp') {
$data = json_encode(['success' => 'attached']);
echo $_REQUEST['callback'] . "($data, 200);";
}
if ($this->returnType === 'redirect') {
$url = $_REQUEST['return_url'];
header("Location: $url", true, 307);
echo "You're being redirected to <a href='{$url}'>$url</a>";
}
}
|
[
"protected",
"function",
"outputAttachSuccess",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"returnType",
"===",
"'image'",
")",
"{",
"$",
"this",
"->",
"outputImage",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"returnType",
"===",
"'json'",
"||",
"$",
"this",
"->",
"returnType",
"===",
"'none'",
")",
"{",
"header",
"(",
"'Content-type: application/json; charset=UTF-8'",
")",
";",
"echo",
"json_encode",
"(",
"[",
"'success'",
"=>",
"'attached'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"returnType",
"===",
"'jsonp'",
")",
"{",
"$",
"data",
"=",
"json_encode",
"(",
"[",
"'success'",
"=>",
"'attached'",
"]",
")",
";",
"echo",
"$",
"_REQUEST",
"[",
"'callback'",
"]",
".",
"\"($data, 200);\"",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"returnType",
"===",
"'redirect'",
")",
"{",
"$",
"url",
"=",
"$",
"_REQUEST",
"[",
"'return_url'",
"]",
";",
"header",
"(",
"\"Location: $url\"",
",",
"true",
",",
"307",
")",
";",
"echo",
"\"You're being redirected to <a href='{$url}'>$url</a>\"",
";",
"}",
"}"
] |
Output on a successful attach
|
[
"Output",
"on",
"a",
"successful",
"attach"
] |
746323f3087af5a06769f7c207ab4ed5124a14bb
|
https://github.com/tw88/sso/blob/746323f3087af5a06769f7c207ab4ed5124a14bb/src/Server.php#L249-L270
|
25,742
|
tw88/sso
|
src/Server.php
|
Server.getSessionData
|
protected function getSessionData($key)
{
if ($key === 'id') {
return session_id();
}
return isset($_SESSION[$key]) ? $_SESSION[$key] : null;
}
|
php
|
protected function getSessionData($key)
{
if ($key === 'id') {
return session_id();
}
return isset($_SESSION[$key]) ? $_SESSION[$key] : null;
}
|
[
"protected",
"function",
"getSessionData",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"'id'",
")",
"{",
"return",
"session_id",
"(",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] |
Get session data
@param type $key
|
[
"Get",
"session",
"data"
] |
746323f3087af5a06769f7c207ab4ed5124a14bb
|
https://github.com/tw88/sso/blob/746323f3087af5a06769f7c207ab4ed5124a14bb/src/Server.php#L363-L370
|
25,743
|
tw88/sso
|
src/Server.php
|
Server.fail
|
protected function fail($message, $http_status = 500)
{
if (!empty($this->options['fail_exception'])) {
throw new Exception($message, $http_status);
}
if ($http_status === 500) {
trigger_error($message, E_USER_WARNING);
}
if ($this->returnType === 'jsonp') {
echo $_REQUEST['callback'] . "(" . json_encode(['error' => $message]) . ", $http_status);";
exit();
}
if ($this->returnType === 'redirect') {
$url = $_REQUEST['return_url'] . '?sso_error=' . $message;
header("Location: $url", true, 307);
echo "You're being redirected to <a href='{$url}'>$url</a>";
exit();
}
http_response_code($http_status);
header('Content-type: application/json; charset=UTF-8');
echo json_encode(['error' => $message]);
exit();
}
|
php
|
protected function fail($message, $http_status = 500)
{
if (!empty($this->options['fail_exception'])) {
throw new Exception($message, $http_status);
}
if ($http_status === 500) {
trigger_error($message, E_USER_WARNING);
}
if ($this->returnType === 'jsonp') {
echo $_REQUEST['callback'] . "(" . json_encode(['error' => $message]) . ", $http_status);";
exit();
}
if ($this->returnType === 'redirect') {
$url = $_REQUEST['return_url'] . '?sso_error=' . $message;
header("Location: $url", true, 307);
echo "You're being redirected to <a href='{$url}'>$url</a>";
exit();
}
http_response_code($http_status);
header('Content-type: application/json; charset=UTF-8');
echo json_encode(['error' => $message]);
exit();
}
|
[
"protected",
"function",
"fail",
"(",
"$",
"message",
",",
"$",
"http_status",
"=",
"500",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"options",
"[",
"'fail_exception'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"message",
",",
"$",
"http_status",
")",
";",
"}",
"if",
"(",
"$",
"http_status",
"===",
"500",
")",
"{",
"trigger_error",
"(",
"$",
"message",
",",
"E_USER_WARNING",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"returnType",
"===",
"'jsonp'",
")",
"{",
"echo",
"$",
"_REQUEST",
"[",
"'callback'",
"]",
".",
"\"(\"",
".",
"json_encode",
"(",
"[",
"'error'",
"=>",
"$",
"message",
"]",
")",
".",
"\", $http_status);\"",
";",
"exit",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"returnType",
"===",
"'redirect'",
")",
"{",
"$",
"url",
"=",
"$",
"_REQUEST",
"[",
"'return_url'",
"]",
".",
"'?sso_error='",
".",
"$",
"message",
";",
"header",
"(",
"\"Location: $url\"",
",",
"true",
",",
"307",
")",
";",
"echo",
"\"You're being redirected to <a href='{$url}'>$url</a>\"",
";",
"exit",
"(",
")",
";",
"}",
"http_response_code",
"(",
"$",
"http_status",
")",
";",
"header",
"(",
"'Content-type: application/json; charset=UTF-8'",
")",
";",
"echo",
"json_encode",
"(",
"[",
"'error'",
"=>",
"$",
"message",
"]",
")",
";",
"exit",
"(",
")",
";",
"}"
] |
An error occured.
@param string $message
@param int $http_status
|
[
"An",
"error",
"occured",
"."
] |
746323f3087af5a06769f7c207ab4ed5124a14bb
|
https://github.com/tw88/sso/blob/746323f3087af5a06769f7c207ab4ed5124a14bb/src/Server.php#L379-L406
|
25,744
|
itsmikej/Filter
|
src/Filter.php
|
Filter.uInt
|
public static function uInt(&$value, $options = ['max'=>null, 'min'=>null, 'default'=>null])
{
$value = (int)$value;
self::processUNum($value, $options);
return $value;
}
|
php
|
public static function uInt(&$value, $options = ['max'=>null, 'min'=>null, 'default'=>null])
{
$value = (int)$value;
self::processUNum($value, $options);
return $value;
}
|
[
"public",
"static",
"function",
"uInt",
"(",
"&",
"$",
"value",
",",
"$",
"options",
"=",
"[",
"'max'",
"=>",
"null",
",",
"'min'",
"=>",
"null",
",",
"'default'",
"=>",
"null",
"]",
")",
"{",
"$",
"value",
"=",
"(",
"int",
")",
"$",
"value",
";",
"self",
"::",
"processUNum",
"(",
"$",
"value",
",",
"$",
"options",
")",
";",
"return",
"$",
"value",
";",
"}"
] |
filter positive int
@param $value
@param array $options
@return int
|
[
"filter",
"positive",
"int"
] |
77132fd7c2e12d353323273220af841e39b77193
|
https://github.com/itsmikej/Filter/blob/77132fd7c2e12d353323273220af841e39b77193/src/Filter.php#L97-L102
|
25,745
|
itsmikej/Filter
|
src/Filter.php
|
Filter.ufloat
|
public static function ufloat(&$value, $options = ['max'=>null, 'min'=>null, 'default'=>null])
{
$value = (float)$value;
self::processUNum($value, $options);
return $value;
}
|
php
|
public static function ufloat(&$value, $options = ['max'=>null, 'min'=>null, 'default'=>null])
{
$value = (float)$value;
self::processUNum($value, $options);
return $value;
}
|
[
"public",
"static",
"function",
"ufloat",
"(",
"&",
"$",
"value",
",",
"$",
"options",
"=",
"[",
"'max'",
"=>",
"null",
",",
"'min'",
"=>",
"null",
",",
"'default'",
"=>",
"null",
"]",
")",
"{",
"$",
"value",
"=",
"(",
"float",
")",
"$",
"value",
";",
"self",
"::",
"processUNum",
"(",
"$",
"value",
",",
"$",
"options",
")",
";",
"return",
"$",
"value",
";",
"}"
] |
filter positive float
@param $value
@param array $options
@return float
|
[
"filter",
"positive",
"float"
] |
77132fd7c2e12d353323273220af841e39b77193
|
https://github.com/itsmikej/Filter/blob/77132fd7c2e12d353323273220af841e39b77193/src/Filter.php#L123-L128
|
25,746
|
itsmikej/Filter
|
src/Filter.php
|
Filter.processUNum
|
protected static function processUNum(&$value, $options)
{
if (!isset($options['min']) || empty($options['min']) || $options['min'] < 0) {
$options['min'] = 0;
}
self::processNum($value, $options);
}
|
php
|
protected static function processUNum(&$value, $options)
{
if (!isset($options['min']) || empty($options['min']) || $options['min'] < 0) {
$options['min'] = 0;
}
self::processNum($value, $options);
}
|
[
"protected",
"static",
"function",
"processUNum",
"(",
"&",
"$",
"value",
",",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'min'",
"]",
")",
"||",
"empty",
"(",
"$",
"options",
"[",
"'min'",
"]",
")",
"||",
"$",
"options",
"[",
"'min'",
"]",
"<",
"0",
")",
"{",
"$",
"options",
"[",
"'min'",
"]",
"=",
"0",
";",
"}",
"self",
"::",
"processNum",
"(",
"$",
"value",
",",
"$",
"options",
")",
";",
"}"
] |
process positive number
@param $value
@param $options
|
[
"process",
"positive",
"number"
] |
77132fd7c2e12d353323273220af841e39b77193
|
https://github.com/itsmikej/Filter/blob/77132fd7c2e12d353323273220af841e39b77193/src/Filter.php#L318-L324
|
25,747
|
stubbles/stubbles-reflect
|
src/main/php/annotation/AnnotationCache.php
|
AnnotationCache.start
|
public static function start(callable $readCache, callable $storeCache)
{
self::$annotations = $readCache();
if (!is_array(self::$annotations)) {
self::flush();
throw new \RuntimeException('Cached annotation data is not an array');
}
self::$unserialized = [];
self::$cacheChanged = false;
self::$storeCache = $storeCache;
register_shutdown_function([__CLASS__, '__shutdown']);
}
|
php
|
public static function start(callable $readCache, callable $storeCache)
{
self::$annotations = $readCache();
if (!is_array(self::$annotations)) {
self::flush();
throw new \RuntimeException('Cached annotation data is not an array');
}
self::$unserialized = [];
self::$cacheChanged = false;
self::$storeCache = $storeCache;
register_shutdown_function([__CLASS__, '__shutdown']);
}
|
[
"public",
"static",
"function",
"start",
"(",
"callable",
"$",
"readCache",
",",
"callable",
"$",
"storeCache",
")",
"{",
"self",
"::",
"$",
"annotations",
"=",
"$",
"readCache",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"self",
"::",
"$",
"annotations",
")",
")",
"{",
"self",
"::",
"flush",
"(",
")",
";",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cached annotation data is not an array'",
")",
";",
"}",
"self",
"::",
"$",
"unserialized",
"=",
"[",
"]",
";",
"self",
"::",
"$",
"cacheChanged",
"=",
"false",
";",
"self",
"::",
"$",
"storeCache",
"=",
"$",
"storeCache",
";",
"register_shutdown_function",
"(",
"[",
"__CLASS__",
",",
"'__shutdown'",
"]",
")",
";",
"}"
] |
start annotation cache with given cache storage logic
Calling this method will also flush the cache. If this method is never
called the annotation cache will not be persistent but only last as long
as the current request is running.
The $readCache closure must return the stored annotation data. If no such
data is present it must return null. In case the stored annotation data
can't be unserialized into an array a \RuntimeException will be thrown.
The $storeCache closure must store passed annotation data. It doesn't
need to take care about serialization, as it already receives a
serialized representation.
A possible implementation for the file cache would look like this:
<code>
AnnotationCache::start(
function() use($cacheFile)
{
if (file_exists($cacheFile)) {
return unserialize(file_get_contents($cacheFile));
}
return [];
},
function(array $annotationData) use($cacheFile)
{
file_put_contents($cacheFile, serialize($annotationData));
}
);
</code>
@param callable $readCache function which can return cached annotation data
@param callable $storeCache function which takes cached annotation data and stores it
@throws \RuntimeException
@since 3.0.0
|
[
"start",
"annotation",
"cache",
"with",
"given",
"cache",
"storage",
"logic"
] |
ab48f9b8692293ef0d276b52619625dbb8869c97
|
https://github.com/stubbles/stubbles-reflect/blob/ab48f9b8692293ef0d276b52619625dbb8869c97/src/main/php/annotation/AnnotationCache.php#L83-L95
|
25,748
|
stubbles/stubbles-reflect
|
src/main/php/annotation/AnnotationCache.php
|
AnnotationCache.startFromFileCache
|
public static function startFromFileCache(string $cacheFile)
{
self::start(
function() use($cacheFile)
{
if (file_exists($cacheFile)) {
return unserialize(file_get_contents($cacheFile));
}
return [];
},
function(array $annotationData) use($cacheFile)
{
file_put_contents($cacheFile, serialize($annotationData));
}
);
}
|
php
|
public static function startFromFileCache(string $cacheFile)
{
self::start(
function() use($cacheFile)
{
if (file_exists($cacheFile)) {
return unserialize(file_get_contents($cacheFile));
}
return [];
},
function(array $annotationData) use($cacheFile)
{
file_put_contents($cacheFile, serialize($annotationData));
}
);
}
|
[
"public",
"static",
"function",
"startFromFileCache",
"(",
"string",
"$",
"cacheFile",
")",
"{",
"self",
"::",
"start",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"cacheFile",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"cacheFile",
")",
")",
"{",
"return",
"unserialize",
"(",
"file_get_contents",
"(",
"$",
"cacheFile",
")",
")",
";",
"}",
"return",
"[",
"]",
";",
"}",
",",
"function",
"(",
"array",
"$",
"annotationData",
")",
"use",
"(",
"$",
"cacheFile",
")",
"{",
"file_put_contents",
"(",
"$",
"cacheFile",
",",
"serialize",
"(",
"$",
"annotationData",
")",
")",
";",
"}",
")",
";",
"}"
] |
starts annotation cache with given cache file
@param string $cacheFile path to file wherein cached annotation data is stored
@since 3.0.0
|
[
"starts",
"annotation",
"cache",
"with",
"given",
"cache",
"file"
] |
ab48f9b8692293ef0d276b52619625dbb8869c97
|
https://github.com/stubbles/stubbles-reflect/blob/ab48f9b8692293ef0d276b52619625dbb8869c97/src/main/php/annotation/AnnotationCache.php#L103-L119
|
25,749
|
stubbles/stubbles-reflect
|
src/main/php/annotation/AnnotationCache.php
|
AnnotationCache.put
|
public static function put(Annotations $annotations)
{
self::$annotations[$annotations->target()] = serialize($annotations);
self::$unserialized[$annotations->target()] = $annotations;
self::$cacheChanged = true;
}
|
php
|
public static function put(Annotations $annotations)
{
self::$annotations[$annotations->target()] = serialize($annotations);
self::$unserialized[$annotations->target()] = $annotations;
self::$cacheChanged = true;
}
|
[
"public",
"static",
"function",
"put",
"(",
"Annotations",
"$",
"annotations",
")",
"{",
"self",
"::",
"$",
"annotations",
"[",
"$",
"annotations",
"->",
"target",
"(",
")",
"]",
"=",
"serialize",
"(",
"$",
"annotations",
")",
";",
"self",
"::",
"$",
"unserialized",
"[",
"$",
"annotations",
"->",
"target",
"(",
")",
"]",
"=",
"$",
"annotations",
";",
"self",
"::",
"$",
"cacheChanged",
"=",
"true",
";",
"}"
] |
store annotations in the cache
@param \stubbles\reflect\annotation\Annotations $annotations
|
[
"store",
"annotations",
"in",
"the",
"cache"
] |
ab48f9b8692293ef0d276b52619625dbb8869c97
|
https://github.com/stubbles/stubbles-reflect/blob/ab48f9b8692293ef0d276b52619625dbb8869c97/src/main/php/annotation/AnnotationCache.php#L157-L162
|
25,750
|
stubbles/stubbles-reflect
|
src/main/php/annotation/AnnotationCache.php
|
AnnotationCache.get
|
public static function get(string $target)
{
if (!self::has($target)) {
return null;
}
if (!isset(self::$unserialized[$target])) {
self::$unserialized[$target] = unserialize(self::$annotations[$target]);
}
return self::$unserialized[$target];
}
|
php
|
public static function get(string $target)
{
if (!self::has($target)) {
return null;
}
if (!isset(self::$unserialized[$target])) {
self::$unserialized[$target] = unserialize(self::$annotations[$target]);
}
return self::$unserialized[$target];
}
|
[
"public",
"static",
"function",
"get",
"(",
"string",
"$",
"target",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"has",
"(",
"$",
"target",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"unserialized",
"[",
"$",
"target",
"]",
")",
")",
"{",
"self",
"::",
"$",
"unserialized",
"[",
"$",
"target",
"]",
"=",
"unserialize",
"(",
"self",
"::",
"$",
"annotations",
"[",
"$",
"target",
"]",
")",
";",
"}",
"return",
"self",
"::",
"$",
"unserialized",
"[",
"$",
"target",
"]",
";",
"}"
] |
returns list of all annotations for given target
@param string $target
@return \stubbles\reflect\annotation\Annotations
|
[
"returns",
"list",
"of",
"all",
"annotations",
"for",
"given",
"target"
] |
ab48f9b8692293ef0d276b52619625dbb8869c97
|
https://github.com/stubbles/stubbles-reflect/blob/ab48f9b8692293ef0d276b52619625dbb8869c97/src/main/php/annotation/AnnotationCache.php#L181-L192
|
25,751
|
JoeBengalen/Config
|
src/Config.php
|
Config.load
|
public function load($file)
{
if (!is_string($file) || !file_exists($file)) {
throw new InvalidArgumentException('File must be a valid file.');
}
$data = include $file;
if (!is_array($data)) {
throw new RuntimeException('File did not return an array.');
}
return $this->set($data);
}
|
php
|
public function load($file)
{
if (!is_string($file) || !file_exists($file)) {
throw new InvalidArgumentException('File must be a valid file.');
}
$data = include $file;
if (!is_array($data)) {
throw new RuntimeException('File did not return an array.');
}
return $this->set($data);
}
|
[
"public",
"function",
"load",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"file",
")",
"||",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'File must be a valid file.'",
")",
";",
"}",
"$",
"data",
"=",
"include",
"$",
"file",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'File did not return an array.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"data",
")",
";",
"}"
] |
Load a configuration file.
@param string $file Path to php file which returns an array.
@return self.
@throws \InvalidArgumentException If $file is not a valid file.
@throws \RunTimeException If $file does not return an array.
|
[
"Load",
"a",
"configuration",
"file",
"."
] |
1a13f3153374224aad52da4669bd69655f037546
|
https://github.com/JoeBengalen/Config/blob/1a13f3153374224aad52da4669bd69655f037546/src/Config.php#L33-L46
|
25,752
|
hiqdev/minii-widgets
|
src/FragmentCache.php
|
FragmentCache.updateDynamicContent
|
protected function updateDynamicContent($content, $placeholders)
{
foreach ($placeholders as $name => $statements) {
$placeholders[$name] = $this->getView()->evaluateDynamicContent($statements);
}
return strtr($content, $placeholders);
}
|
php
|
protected function updateDynamicContent($content, $placeholders)
{
foreach ($placeholders as $name => $statements) {
$placeholders[$name] = $this->getView()->evaluateDynamicContent($statements);
}
return strtr($content, $placeholders);
}
|
[
"protected",
"function",
"updateDynamicContent",
"(",
"$",
"content",
",",
"$",
"placeholders",
")",
"{",
"foreach",
"(",
"$",
"placeholders",
"as",
"$",
"name",
"=>",
"$",
"statements",
")",
"{",
"$",
"placeholders",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"getView",
"(",
")",
"->",
"evaluateDynamicContent",
"(",
"$",
"statements",
")",
";",
"}",
"return",
"strtr",
"(",
"$",
"content",
",",
"$",
"placeholders",
")",
";",
"}"
] |
Replaces placeholders in content by results of evaluated dynamic statements.
@param string $content
@param array $placeholders
@return string final content
|
[
"Replaces",
"placeholders",
"in",
"content",
"by",
"results",
"of",
"evaluated",
"dynamic",
"statements",
"."
] |
b8bc54a3645e9e45c228e3ec81b11ff4775385c3
|
https://github.com/hiqdev/minii-widgets/blob/b8bc54a3645e9e45c228e3ec81b11ff4775385c3/src/FragmentCache.php#L167-L174
|
25,753
|
comodojo/foundation
|
src/Comodojo/Foundation/Validation/DataFilter.php
|
DataFilter.filterInteger
|
public static function filterInteger($int, $min=~PHP_INT_MAX, $max=PHP_INT_MAX, $default=0) {
return filter_var($int, FILTER_VALIDATE_INT, array(
'options' => array(
'default' => $default,
'min_range' => $min,
'max_range' => $max
)
));
}
|
php
|
public static function filterInteger($int, $min=~PHP_INT_MAX, $max=PHP_INT_MAX, $default=0) {
return filter_var($int, FILTER_VALIDATE_INT, array(
'options' => array(
'default' => $default,
'min_range' => $min,
'max_range' => $max
)
));
}
|
[
"public",
"static",
"function",
"filterInteger",
"(",
"$",
"int",
",",
"$",
"min",
"=",
"~",
"PHP_INT_MAX",
",",
"$",
"max",
"=",
"PHP_INT_MAX",
",",
"$",
"default",
"=",
"0",
")",
"{",
"return",
"filter_var",
"(",
"$",
"int",
",",
"FILTER_VALIDATE_INT",
",",
"array",
"(",
"'options'",
"=>",
"array",
"(",
"'default'",
"=>",
"$",
"default",
",",
"'min_range'",
"=>",
"$",
"min",
",",
"'max_range'",
"=>",
"$",
"max",
")",
")",
")",
";",
"}"
] |
Filter an integer.
This method is a shortcut to filter_var using FILTER_VALIDATE_INT
@param int $int Int to filter
@param int $min Min value (default to ~PHP_INT_MAX)
@param int $max Max value (default to PHP_INT_MAX)
@param int $default Default value
@return int
|
[
"Filter",
"an",
"integer",
"."
] |
21ed690e81763ed9e1ef7721a7eb4fcc0fcefc1a
|
https://github.com/comodojo/foundation/blob/21ed690e81763ed9e1ef7721a7eb4fcc0fcefc1a/src/Comodojo/Foundation/Validation/DataFilter.php#L32-L42
|
25,754
|
KDF5000/EasyThink
|
src/ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_config.php
|
Smarty_Internal_Config.buildCompiledFilepath
|
public function buildCompiledFilepath()
{
$_compile_id = isset($this->smarty->compile_id) ? preg_replace('![^\w\|]+!', '_', $this->smarty->compile_id) : null;
$_flag = (int) $this->smarty->config_read_hidden + (int) $this->smarty->config_booleanize * 2
+ (int) $this->smarty->config_overwrite * 4;
$_filepath = sha1($this->source->name . $_flag);
// if use_sub_dirs, break file into directories
if ($this->smarty->use_sub_dirs) {
$_filepath = substr($_filepath, 0, 2) . DS
. substr($_filepath, 2, 2) . DS
. substr($_filepath, 4, 2) . DS
. $_filepath;
}
$_compile_dir_sep = $this->smarty->use_sub_dirs ? DS : '^';
if (isset($_compile_id)) {
$_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
}
$_compile_dir = $this->smarty->getCompileDir();
return $_compile_dir . $_filepath . '.' . basename($this->source->name) . '.config' . '.php';
}
|
php
|
public function buildCompiledFilepath()
{
$_compile_id = isset($this->smarty->compile_id) ? preg_replace('![^\w\|]+!', '_', $this->smarty->compile_id) : null;
$_flag = (int) $this->smarty->config_read_hidden + (int) $this->smarty->config_booleanize * 2
+ (int) $this->smarty->config_overwrite * 4;
$_filepath = sha1($this->source->name . $_flag);
// if use_sub_dirs, break file into directories
if ($this->smarty->use_sub_dirs) {
$_filepath = substr($_filepath, 0, 2) . DS
. substr($_filepath, 2, 2) . DS
. substr($_filepath, 4, 2) . DS
. $_filepath;
}
$_compile_dir_sep = $this->smarty->use_sub_dirs ? DS : '^';
if (isset($_compile_id)) {
$_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
}
$_compile_dir = $this->smarty->getCompileDir();
return $_compile_dir . $_filepath . '.' . basename($this->source->name) . '.config' . '.php';
}
|
[
"public",
"function",
"buildCompiledFilepath",
"(",
")",
"{",
"$",
"_compile_id",
"=",
"isset",
"(",
"$",
"this",
"->",
"smarty",
"->",
"compile_id",
")",
"?",
"preg_replace",
"(",
"'![^\\w\\|]+!'",
",",
"'_'",
",",
"$",
"this",
"->",
"smarty",
"->",
"compile_id",
")",
":",
"null",
";",
"$",
"_flag",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"smarty",
"->",
"config_read_hidden",
"+",
"(",
"int",
")",
"$",
"this",
"->",
"smarty",
"->",
"config_booleanize",
"*",
"2",
"+",
"(",
"int",
")",
"$",
"this",
"->",
"smarty",
"->",
"config_overwrite",
"*",
"4",
";",
"$",
"_filepath",
"=",
"sha1",
"(",
"$",
"this",
"->",
"source",
"->",
"name",
".",
"$",
"_flag",
")",
";",
"// if use_sub_dirs, break file into directories",
"if",
"(",
"$",
"this",
"->",
"smarty",
"->",
"use_sub_dirs",
")",
"{",
"$",
"_filepath",
"=",
"substr",
"(",
"$",
"_filepath",
",",
"0",
",",
"2",
")",
".",
"DS",
".",
"substr",
"(",
"$",
"_filepath",
",",
"2",
",",
"2",
")",
".",
"DS",
".",
"substr",
"(",
"$",
"_filepath",
",",
"4",
",",
"2",
")",
".",
"DS",
".",
"$",
"_filepath",
";",
"}",
"$",
"_compile_dir_sep",
"=",
"$",
"this",
"->",
"smarty",
"->",
"use_sub_dirs",
"?",
"DS",
":",
"'^'",
";",
"if",
"(",
"isset",
"(",
"$",
"_compile_id",
")",
")",
"{",
"$",
"_filepath",
"=",
"$",
"_compile_id",
".",
"$",
"_compile_dir_sep",
".",
"$",
"_filepath",
";",
"}",
"$",
"_compile_dir",
"=",
"$",
"this",
"->",
"smarty",
"->",
"getCompileDir",
"(",
")",
";",
"return",
"$",
"_compile_dir",
".",
"$",
"_filepath",
".",
"'.'",
".",
"basename",
"(",
"$",
"this",
"->",
"source",
"->",
"name",
")",
".",
"'.config'",
".",
"'.php'",
";",
"}"
] |
Get file path.
@return string
|
[
"Get",
"file",
"path",
"."
] |
86efc9c8a0d504e01e2fea55868227fdc8928841
|
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_config.php#L102-L121
|
25,755
|
Finesse/QueryScribe
|
src/QueryBricks/WhereTrait.php
|
WhereTrait.whereNot
|
public function whereNot(\Closure $callback, string $appendRule = 'AND'): self
{
$groupQuery = $this->resolveCriteriaGroupClosure($callback);
$this->where[] = new CriteriaCriterion($groupQuery->where, true, $appendRule);
return $this;
}
|
php
|
public function whereNot(\Closure $callback, string $appendRule = 'AND'): self
{
$groupQuery = $this->resolveCriteriaGroupClosure($callback);
$this->where[] = new CriteriaCriterion($groupQuery->where, true, $appendRule);
return $this;
}
|
[
"public",
"function",
"whereNot",
"(",
"\\",
"Closure",
"$",
"callback",
",",
"string",
"$",
"appendRule",
"=",
"'AND'",
")",
":",
"self",
"{",
"$",
"groupQuery",
"=",
"$",
"this",
"->",
"resolveCriteriaGroupClosure",
"(",
"$",
"callback",
")",
";",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"new",
"CriteriaCriterion",
"(",
"$",
"groupQuery",
"->",
"where",
",",
"true",
",",
"$",
"appendRule",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a group of criteria wrapped by NOT.
@param \Closure $callback Makes a group of criteria
@param string $appendRule How the criterion should be appended to the others (SQL boolean operator name)
@return $this
@throws InvalidReturnValueException
|
[
"Adds",
"a",
"group",
"of",
"criteria",
"wrapped",
"by",
"NOT",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/WhereTrait.php#L77-L82
|
25,756
|
Finesse/QueryScribe
|
src/QueryBricks/WhereTrait.php
|
WhereTrait.whereRaw
|
public function whereRaw(string $query, array $bindings = [], string $appendRule = 'AND'): self
{
$this->where[] = new RawCriterion(new Raw($query, $bindings), $appendRule);
return $this;
}
|
php
|
public function whereRaw(string $query, array $bindings = [], string $appendRule = 'AND'): self
{
$this->where[] = new RawCriterion(new Raw($query, $bindings), $appendRule);
return $this;
}
|
[
"public",
"function",
"whereRaw",
"(",
"string",
"$",
"query",
",",
"array",
"$",
"bindings",
"=",
"[",
"]",
",",
"string",
"$",
"appendRule",
"=",
"'AND'",
")",
":",
"self",
"{",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"new",
"RawCriterion",
"(",
"new",
"Raw",
"(",
"$",
"query",
",",
"$",
"bindings",
")",
",",
"$",
"appendRule",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a raw SQL criterion to the WHERE section.
@param string $query SQL statement
@param array $bindings Values to bind to the statement
@param string $appendRule How the criterion should be appended to the others (SQL boolean operator name)
@return $this
|
[
"Adds",
"a",
"raw",
"SQL",
"criterion",
"to",
"the",
"WHERE",
"section",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/WhereTrait.php#L104-L108
|
25,757
|
Finesse/QueryScribe
|
src/QueryBricks/WhereTrait.php
|
WhereTrait.whereBetween
|
public function whereBetween($column, $min, $max, bool $not = false, string $appendRule = 'AND'): self
{
$column = $this->checkStringValue('Argument $column', $column);
$min = $this->checkScalarOrNullValue('The left between value', $min);
$max = $this->checkScalarOrNullValue('The right between value', $max);
$this->where[] = new BetweenCriterion($column, $min, $max, $not, $appendRule);
return $this;
}
|
php
|
public function whereBetween($column, $min, $max, bool $not = false, string $appendRule = 'AND'): self
{
$column = $this->checkStringValue('Argument $column', $column);
$min = $this->checkScalarOrNullValue('The left between value', $min);
$max = $this->checkScalarOrNullValue('The right between value', $max);
$this->where[] = new BetweenCriterion($column, $min, $max, $not, $appendRule);
return $this;
}
|
[
"public",
"function",
"whereBetween",
"(",
"$",
"column",
",",
"$",
"min",
",",
"$",
"max",
",",
"bool",
"$",
"not",
"=",
"false",
",",
"string",
"$",
"appendRule",
"=",
"'AND'",
")",
":",
"self",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"checkStringValue",
"(",
"'Argument $column'",
",",
"$",
"column",
")",
";",
"$",
"min",
"=",
"$",
"this",
"->",
"checkScalarOrNullValue",
"(",
"'The left between value'",
",",
"$",
"min",
")",
";",
"$",
"max",
"=",
"$",
"this",
"->",
"checkScalarOrNullValue",
"(",
"'The right between value'",
",",
"$",
"max",
")",
";",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"new",
"BetweenCriterion",
"(",
"$",
"column",
",",
"$",
"min",
",",
"$",
"max",
",",
"$",
"not",
",",
"$",
"appendRule",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a BETWEEN criterion to the WHERE section.
@param string|\Closure|Query|StatementInterface $column Target column
@param mixed|\Closure|Query|StatementInterface $min Left value
@param mixed|\Closure|Query|StatementInterface $max Right value
@param bool $not Whether the rule should be NOT BETWEEN
@param string $appendRule How the criterion should be appended to the others (SQL boolean operator name)
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"Adds",
"a",
"BETWEEN",
"criterion",
"to",
"the",
"WHERE",
"section",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/WhereTrait.php#L135-L143
|
25,758
|
Finesse/QueryScribe
|
src/QueryBricks/WhereTrait.php
|
WhereTrait.orWhereBetween
|
public function orWhereBetween($column, $min, $max): self
{
return $this->whereBetween($column, $min, $max, false, 'OR');
}
|
php
|
public function orWhereBetween($column, $min, $max): self
{
return $this->whereBetween($column, $min, $max, false, 'OR');
}
|
[
"public",
"function",
"orWhereBetween",
"(",
"$",
"column",
",",
"$",
"min",
",",
"$",
"max",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"whereBetween",
"(",
"$",
"column",
",",
"$",
"min",
",",
"$",
"max",
",",
"false",
",",
"'OR'",
")",
";",
"}"
] |
Adds a BETWEEN criterion to the WHERE section with the OR append rule. See the readme for more info about append
rules.
@param string|\Closure|Query|StatementInterface $column Target column
@param mixed|\Closure|Query|StatementInterface $min Left value
@param mixed|\Closure|Query|StatementInterface $max Right value
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"Adds",
"a",
"BETWEEN",
"criterion",
"to",
"the",
"WHERE",
"section",
"with",
"the",
"OR",
"append",
"rule",
".",
"See",
"the",
"readme",
"for",
"more",
"info",
"about",
"append",
"rules",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/WhereTrait.php#L156-L159
|
25,759
|
Finesse/QueryScribe
|
src/QueryBricks/WhereTrait.php
|
WhereTrait.whereNotBetween
|
public function whereNotBetween($column, $min, $max): self
{
return $this->whereBetween($column, $min, $max, true);
}
|
php
|
public function whereNotBetween($column, $min, $max): self
{
return $this->whereBetween($column, $min, $max, true);
}
|
[
"public",
"function",
"whereNotBetween",
"(",
"$",
"column",
",",
"$",
"min",
",",
"$",
"max",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"whereBetween",
"(",
"$",
"column",
",",
"$",
"min",
",",
"$",
"max",
",",
"true",
")",
";",
"}"
] |
Adds a NOT BETWEEN criterion to the WHERE section.
@param string|\Closure|Query|StatementInterface $column Target column
@param mixed|\Closure|Query|StatementInterface $min Left value
@param mixed|\Closure|Query|StatementInterface $max Right value
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"Adds",
"a",
"NOT",
"BETWEEN",
"criterion",
"to",
"the",
"WHERE",
"section",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/WhereTrait.php#L171-L174
|
25,760
|
Finesse/QueryScribe
|
src/QueryBricks/WhereTrait.php
|
WhereTrait.orWhereNotBetween
|
public function orWhereNotBetween($column, $min, $max): self
{
return $this->whereBetween($column, $min, $max, true, 'OR');
}
|
php
|
public function orWhereNotBetween($column, $min, $max): self
{
return $this->whereBetween($column, $min, $max, true, 'OR');
}
|
[
"public",
"function",
"orWhereNotBetween",
"(",
"$",
"column",
",",
"$",
"min",
",",
"$",
"max",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"whereBetween",
"(",
"$",
"column",
",",
"$",
"min",
",",
"$",
"max",
",",
"true",
",",
"'OR'",
")",
";",
"}"
] |
Adds a NOT BETWEEN criterion to the WHERE section with the OR append rule. See the readme for more info about
append rules.
@param string|\Closure|Query|StatementInterface $column Target column
@param mixed|\Closure|Query|StatementInterface $min Left value
@param mixed|\Closure|Query|StatementInterface $max Right value
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"Adds",
"a",
"NOT",
"BETWEEN",
"criterion",
"to",
"the",
"WHERE",
"section",
"with",
"the",
"OR",
"append",
"rule",
".",
"See",
"the",
"readme",
"for",
"more",
"info",
"about",
"append",
"rules",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/WhereTrait.php#L187-L190
|
25,761
|
Finesse/QueryScribe
|
src/QueryBricks/WhereTrait.php
|
WhereTrait.whereIn
|
public function whereIn($column, $values, bool $not = false, string $appendRule = 'AND'): self
{
$column = $this->checkStringValue('Argument $column', $column);
if (
!is_array($values) &&
!($values instanceof \Closure) &&
!($values instanceof Query) &&
!($values instanceof StatementInterface)
) {
return $this->handleException(InvalidArgumentException::create(
'The IN value',
$values,
['array', \Closure::class, Query::class, StatementInterface::class, 'null']
));
}
if (is_array($values)) {
foreach ($values as $index => &$value) {
$value = $this->checkScalarOrNullValue('Argument $values['.$index.']', $value);
}
} elseif ($values instanceof \Closure) {
$values = $this->resolveSubQueryClosure($values);
}
$this->where[] = new InCriterion($column, $values, $not, $appendRule);
return $this;
}
|
php
|
public function whereIn($column, $values, bool $not = false, string $appendRule = 'AND'): self
{
$column = $this->checkStringValue('Argument $column', $column);
if (
!is_array($values) &&
!($values instanceof \Closure) &&
!($values instanceof Query) &&
!($values instanceof StatementInterface)
) {
return $this->handleException(InvalidArgumentException::create(
'The IN value',
$values,
['array', \Closure::class, Query::class, StatementInterface::class, 'null']
));
}
if (is_array($values)) {
foreach ($values as $index => &$value) {
$value = $this->checkScalarOrNullValue('Argument $values['.$index.']', $value);
}
} elseif ($values instanceof \Closure) {
$values = $this->resolveSubQueryClosure($values);
}
$this->where[] = new InCriterion($column, $values, $not, $appendRule);
return $this;
}
|
[
"public",
"function",
"whereIn",
"(",
"$",
"column",
",",
"$",
"values",
",",
"bool",
"$",
"not",
"=",
"false",
",",
"string",
"$",
"appendRule",
"=",
"'AND'",
")",
":",
"self",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"checkStringValue",
"(",
"'Argument $column'",
",",
"$",
"column",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"values",
")",
"&&",
"!",
"(",
"$",
"values",
"instanceof",
"\\",
"Closure",
")",
"&&",
"!",
"(",
"$",
"values",
"instanceof",
"Query",
")",
"&&",
"!",
"(",
"$",
"values",
"instanceof",
"StatementInterface",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidArgumentException",
"::",
"create",
"(",
"'The IN value'",
",",
"$",
"values",
",",
"[",
"'array'",
",",
"\\",
"Closure",
"::",
"class",
",",
"Query",
"::",
"class",
",",
"StatementInterface",
"::",
"class",
",",
"'null'",
"]",
")",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"index",
"=>",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"checkScalarOrNullValue",
"(",
"'Argument $values['",
".",
"$",
"index",
".",
"']'",
",",
"$",
"value",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"values",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"resolveSubQueryClosure",
"(",
"$",
"values",
")",
";",
"}",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"new",
"InCriterion",
"(",
"$",
"column",
",",
"$",
"values",
",",
"$",
"not",
",",
"$",
"appendRule",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a IN criterion to the WHERE section.
@param string|\Closure|Query|StatementInterface $column Target column
@param mixed[]|\Closure[]|Query[]|StatementInterface[]|\Closure|Query|StatementInterface Haystack values
@param bool $not Whether the rule should be NOT IN
@param string $appendRule How the criterion should be appended to the others (SQL boolean operator name)
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"Adds",
"a",
"IN",
"criterion",
"to",
"the",
"WHERE",
"section",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/WhereTrait.php#L203-L230
|
25,762
|
Finesse/QueryScribe
|
src/QueryBricks/WhereTrait.php
|
WhereTrait.whereNull
|
public function whereNull($column, bool $not = false, string $appendRule = 'AND'): self
{
$column = $this->checkStringValue('Argument $column', $column);
$this->where[] = new NullCriterion($column, !$not, $appendRule);
return $this;
}
|
php
|
public function whereNull($column, bool $not = false, string $appendRule = 'AND'): self
{
$column = $this->checkStringValue('Argument $column', $column);
$this->where[] = new NullCriterion($column, !$not, $appendRule);
return $this;
}
|
[
"public",
"function",
"whereNull",
"(",
"$",
"column",
",",
"bool",
"$",
"not",
"=",
"false",
",",
"string",
"$",
"appendRule",
"=",
"'AND'",
")",
":",
"self",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"checkStringValue",
"(",
"'Argument $column'",
",",
"$",
"column",
")",
";",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"new",
"NullCriterion",
"(",
"$",
"column",
",",
"!",
"$",
"not",
",",
"$",
"appendRule",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a IS NULL criterion to the WHERE section.
@param string|\Closure|Query|StatementInterface $column Target column
@param bool $not Whether the rule should be NOT NULL
@param string $appendRule How the criterion should be appended to the others (SQL boolean operator name)
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"Adds",
"a",
"IS",
"NULL",
"criterion",
"to",
"the",
"WHERE",
"section",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/WhereTrait.php#L286-L292
|
25,763
|
Finesse/QueryScribe
|
src/QueryBricks/WhereTrait.php
|
WhereTrait.orWhereColumn
|
public function orWhereColumn(...$arguments): self
{
$this->where[] = $this->whereArgumentsToCriterion($arguments, 'OR', true);
return $this;
}
|
php
|
public function orWhereColumn(...$arguments): self
{
$this->where[] = $this->whereArgumentsToCriterion($arguments, 'OR', true);
return $this;
}
|
[
"public",
"function",
"orWhereColumn",
"(",
"...",
"$",
"arguments",
")",
":",
"self",
"{",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"$",
"this",
"->",
"whereArgumentsToCriterion",
"(",
"$",
"arguments",
",",
"'OR'",
",",
"true",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
The same as `whereColumn` but the result criterion is appended to the "where" group with the OR append rule.
@see whereColumn
@param string|\Closure|Query|StatementInterface|array[] $column Target column 1
@param string|\Closure|Query|StatementInterface $rule Rule or target column 2
@param string|\Closure|Query|StatementInterface|null $column Target column 2 or nothing
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"The",
"same",
"as",
"whereColumn",
"but",
"the",
"result",
"criterion",
"is",
"appended",
"to",
"the",
"where",
"group",
"with",
"the",
"OR",
"append",
"rule",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/WhereTrait.php#L364-L368
|
25,764
|
Finesse/QueryScribe
|
src/QueryBricks/WhereTrait.php
|
WhereTrait.whereExists
|
public function whereExists($subQuery, bool $not = false, string $appendRule = 'AND'): self
{
$subQuery = $this->checkSubQueryValue('Argument $subQuery', $subQuery);
$this->where[] = new ExistsCriterion($subQuery, $not, $appendRule);
return $this;
}
|
php
|
public function whereExists($subQuery, bool $not = false, string $appendRule = 'AND'): self
{
$subQuery = $this->checkSubQueryValue('Argument $subQuery', $subQuery);
$this->where[] = new ExistsCriterion($subQuery, $not, $appendRule);
return $this;
}
|
[
"public",
"function",
"whereExists",
"(",
"$",
"subQuery",
",",
"bool",
"$",
"not",
"=",
"false",
",",
"string",
"$",
"appendRule",
"=",
"'AND'",
")",
":",
"self",
"{",
"$",
"subQuery",
"=",
"$",
"this",
"->",
"checkSubQueryValue",
"(",
"'Argument $subQuery'",
",",
"$",
"subQuery",
")",
";",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"new",
"ExistsCriterion",
"(",
"$",
"subQuery",
",",
"$",
"not",
",",
"$",
"appendRule",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a EXISTS criterion to the WHERE section.
@param $subQuery \Closure|Query|StatementInterface Query to place inside the EXISTS clause. If closure, it
should create the query.
@param bool $not Whether the rule should be NOT EXISTS
@param string $appendRule How the criterion should be appended to the others (SQL boolean operator name)
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"Adds",
"a",
"EXISTS",
"criterion",
"to",
"the",
"WHERE",
"section",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/WhereTrait.php#L381-L387
|
25,765
|
Finesse/QueryScribe
|
src/QueryBricks/WhereTrait.php
|
WhereTrait.whereArgumentsToCriterion
|
protected function whereArgumentsToCriterion(
array $arguments,
string $appendRule = 'AND',
bool $valueIsColumn = false
): Criterion {
switch ($argumentsCount = count($arguments)) {
case 0:
return $this->handleException(new InvalidArgumentException('Too few arguments'));
case 1:
$argument = $arguments[0];
if ($argument instanceof \Closure) {
$groupQuery = $this->resolveCriteriaGroupClosure($argument);
return new CriteriaCriterion($groupQuery->where, false, $appendRule);
}
if (is_array($argument)) {
$criteria = [];
foreach ($argument as $criterionData) {
$criteria[] = $this->whereArgumentsToCriterion($criterionData, 'AND', $valueIsColumn);
}
return new CriteriaCriterion($criteria, false, $appendRule);
}
if ($argument instanceof StatementInterface) {
return new RawCriterion($argument, $appendRule);
}
return $this->handleException(InvalidArgumentException::create(
'The argument',
$argument,
['Closure', 'array', StatementInterface::class]
));
case 2:
case 3:
if ($argumentsCount === 2) {
list($column, $value) = $arguments;
$rule = '=';
} else {
list($column, $rule, $value) = $arguments;
if (!is_string($rule)) {
return $this->handleException(InvalidArgumentException::create('Argument $rule', $rule, ['string']));
}
}
if ($valueIsColumn) {
$column1 = $this->checkStringValue('Argument $column1', $column);
$column2 = $this->checkStringValue('Argument $column2', $value);
return new ColumnsCriterion($column1, $rule, $column2, $appendRule);
} else {
$column = $this->checkStringValue('Argument $column', $column);
$value = $this->checkScalarOrNullValue('Argument $value', $value);
return new ValueCriterion($column, $rule, $value, $appendRule);
}
default:
return $this->handleException(new InvalidArgumentException('Too many arguments'));
}
}
|
php
|
protected function whereArgumentsToCriterion(
array $arguments,
string $appendRule = 'AND',
bool $valueIsColumn = false
): Criterion {
switch ($argumentsCount = count($arguments)) {
case 0:
return $this->handleException(new InvalidArgumentException('Too few arguments'));
case 1:
$argument = $arguments[0];
if ($argument instanceof \Closure) {
$groupQuery = $this->resolveCriteriaGroupClosure($argument);
return new CriteriaCriterion($groupQuery->where, false, $appendRule);
}
if (is_array($argument)) {
$criteria = [];
foreach ($argument as $criterionData) {
$criteria[] = $this->whereArgumentsToCriterion($criterionData, 'AND', $valueIsColumn);
}
return new CriteriaCriterion($criteria, false, $appendRule);
}
if ($argument instanceof StatementInterface) {
return new RawCriterion($argument, $appendRule);
}
return $this->handleException(InvalidArgumentException::create(
'The argument',
$argument,
['Closure', 'array', StatementInterface::class]
));
case 2:
case 3:
if ($argumentsCount === 2) {
list($column, $value) = $arguments;
$rule = '=';
} else {
list($column, $rule, $value) = $arguments;
if (!is_string($rule)) {
return $this->handleException(InvalidArgumentException::create('Argument $rule', $rule, ['string']));
}
}
if ($valueIsColumn) {
$column1 = $this->checkStringValue('Argument $column1', $column);
$column2 = $this->checkStringValue('Argument $column2', $value);
return new ColumnsCriterion($column1, $rule, $column2, $appendRule);
} else {
$column = $this->checkStringValue('Argument $column', $column);
$value = $this->checkScalarOrNullValue('Argument $value', $value);
return new ValueCriterion($column, $rule, $value, $appendRule);
}
default:
return $this->handleException(new InvalidArgumentException('Too many arguments'));
}
}
|
[
"protected",
"function",
"whereArgumentsToCriterion",
"(",
"array",
"$",
"arguments",
",",
"string",
"$",
"appendRule",
"=",
"'AND'",
",",
"bool",
"$",
"valueIsColumn",
"=",
"false",
")",
":",
"Criterion",
"{",
"switch",
"(",
"$",
"argumentsCount",
"=",
"count",
"(",
"$",
"arguments",
")",
")",
"{",
"case",
"0",
":",
"return",
"$",
"this",
"->",
"handleException",
"(",
"new",
"InvalidArgumentException",
"(",
"'Too few arguments'",
")",
")",
";",
"case",
"1",
":",
"$",
"argument",
"=",
"$",
"arguments",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"argument",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"groupQuery",
"=",
"$",
"this",
"->",
"resolveCriteriaGroupClosure",
"(",
"$",
"argument",
")",
";",
"return",
"new",
"CriteriaCriterion",
"(",
"$",
"groupQuery",
"->",
"where",
",",
"false",
",",
"$",
"appendRule",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"argument",
")",
")",
"{",
"$",
"criteria",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"argument",
"as",
"$",
"criterionData",
")",
"{",
"$",
"criteria",
"[",
"]",
"=",
"$",
"this",
"->",
"whereArgumentsToCriterion",
"(",
"$",
"criterionData",
",",
"'AND'",
",",
"$",
"valueIsColumn",
")",
";",
"}",
"return",
"new",
"CriteriaCriterion",
"(",
"$",
"criteria",
",",
"false",
",",
"$",
"appendRule",
")",
";",
"}",
"if",
"(",
"$",
"argument",
"instanceof",
"StatementInterface",
")",
"{",
"return",
"new",
"RawCriterion",
"(",
"$",
"argument",
",",
"$",
"appendRule",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidArgumentException",
"::",
"create",
"(",
"'The argument'",
",",
"$",
"argument",
",",
"[",
"'Closure'",
",",
"'array'",
",",
"StatementInterface",
"::",
"class",
"]",
")",
")",
";",
"case",
"2",
":",
"case",
"3",
":",
"if",
"(",
"$",
"argumentsCount",
"===",
"2",
")",
"{",
"list",
"(",
"$",
"column",
",",
"$",
"value",
")",
"=",
"$",
"arguments",
";",
"$",
"rule",
"=",
"'='",
";",
"}",
"else",
"{",
"list",
"(",
"$",
"column",
",",
"$",
"rule",
",",
"$",
"value",
")",
"=",
"$",
"arguments",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"rule",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidArgumentException",
"::",
"create",
"(",
"'Argument $rule'",
",",
"$",
"rule",
",",
"[",
"'string'",
"]",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"valueIsColumn",
")",
"{",
"$",
"column1",
"=",
"$",
"this",
"->",
"checkStringValue",
"(",
"'Argument $column1'",
",",
"$",
"column",
")",
";",
"$",
"column2",
"=",
"$",
"this",
"->",
"checkStringValue",
"(",
"'Argument $column2'",
",",
"$",
"value",
")",
";",
"return",
"new",
"ColumnsCriterion",
"(",
"$",
"column1",
",",
"$",
"rule",
",",
"$",
"column2",
",",
"$",
"appendRule",
")",
";",
"}",
"else",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"checkStringValue",
"(",
"'Argument $column'",
",",
"$",
"column",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"checkScalarOrNullValue",
"(",
"'Argument $value'",
",",
"$",
"value",
")",
";",
"return",
"new",
"ValueCriterion",
"(",
"$",
"column",
",",
"$",
"rule",
",",
"$",
"value",
",",
"$",
"appendRule",
")",
";",
"}",
"default",
":",
"return",
"$",
"this",
"->",
"handleException",
"(",
"new",
"InvalidArgumentException",
"(",
"'Too many arguments'",
")",
")",
";",
"}",
"}"
] |
Converts `where` method arguments to a criterion object
@see where
@see whereColumn
@param array $arguments The original method arguments
@param string $appendRule How the criterion should be appended to the others (SQL boolean operator name)
@param bool $valueIsColumn Treat the second or the third argument as a column name
@return Criterion
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"Converts",
"where",
"method",
"arguments",
"to",
"a",
"criterion",
"object"
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/WhereTrait.php#L445-L502
|
25,766
|
libreworks/caridea-acl
|
src/Rule.php
|
Rule.match
|
public function match(Subject $subject, string $verb): bool
{
return $this->subject->getType() == $subject->getType() &&
$this->subject->getId() === $subject->getId() &&
($this->verbs === null || in_array($verb, $this->verbs, true));
}
|
php
|
public function match(Subject $subject, string $verb): bool
{
return $this->subject->getType() == $subject->getType() &&
$this->subject->getId() === $subject->getId() &&
($this->verbs === null || in_array($verb, $this->verbs, true));
}
|
[
"public",
"function",
"match",
"(",
"Subject",
"$",
"subject",
",",
"string",
"$",
"verb",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"subject",
"->",
"getType",
"(",
")",
"==",
"$",
"subject",
"->",
"getType",
"(",
")",
"&&",
"$",
"this",
"->",
"subject",
"->",
"getId",
"(",
")",
"===",
"$",
"subject",
"->",
"getId",
"(",
")",
"&&",
"(",
"$",
"this",
"->",
"verbs",
"===",
"null",
"||",
"in_array",
"(",
"$",
"verb",
",",
"$",
"this",
"->",
"verbs",
",",
"true",
")",
")",
";",
"}"
] |
Gets whether this Rule matches the `Subject` and verb provided.
@param \Caridea\Acl\Subject $subject The subject to check
@param string $verb The verb to check
@return bool Whether this Rule matches the arguments provided
|
[
"Gets",
"whether",
"this",
"Rule",
"matches",
"the",
"Subject",
"and",
"verb",
"provided",
"."
] |
64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916
|
https://github.com/libreworks/caridea-acl/blob/64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916/src/Rule.php#L75-L80
|
25,767
|
libreworks/caridea-acl
|
src/Rule.php
|
Rule.allow
|
public static function allow(Subject $subject, array $verbs = null): Rule
{
return new self($subject, true, $verbs);
}
|
php
|
public static function allow(Subject $subject, array $verbs = null): Rule
{
return new self($subject, true, $verbs);
}
|
[
"public",
"static",
"function",
"allow",
"(",
"Subject",
"$",
"subject",
",",
"array",
"$",
"verbs",
"=",
"null",
")",
":",
"Rule",
"{",
"return",
"new",
"self",
"(",
"$",
"subject",
",",
"true",
",",
"$",
"verbs",
")",
";",
"}"
] |
Creates an allowing Rule.
@param \Caridea\Acl\Subject $subject The subject to allow access
@param array<string>|null $verbs Optional list of allowed verbs.
Empty or `null` means *all*.
@return Rule The allowing Rule
|
[
"Creates",
"an",
"allowing",
"Rule",
"."
] |
64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916
|
https://github.com/libreworks/caridea-acl/blob/64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916/src/Rule.php#L90-L93
|
25,768
|
libreworks/caridea-acl
|
src/Rule.php
|
Rule.deny
|
public static function deny(Subject $subject, array $verbs = null): Rule
{
return new self($subject, false, $verbs);
}
|
php
|
public static function deny(Subject $subject, array $verbs = null): Rule
{
return new self($subject, false, $verbs);
}
|
[
"public",
"static",
"function",
"deny",
"(",
"Subject",
"$",
"subject",
",",
"array",
"$",
"verbs",
"=",
"null",
")",
":",
"Rule",
"{",
"return",
"new",
"self",
"(",
"$",
"subject",
",",
"false",
",",
"$",
"verbs",
")",
";",
"}"
] |
Creates an denying Rule.
@param \Caridea\Acl\Subject $subject The subject to allow access
@param array<string>|null $verbs Optional list of denied verbs.
Empty or `null` means *all*.
@return Rule The denying Rule
|
[
"Creates",
"an",
"denying",
"Rule",
"."
] |
64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916
|
https://github.com/libreworks/caridea-acl/blob/64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916/src/Rule.php#L103-L106
|
25,769
|
gplcart/cli
|
controllers/commands/Page.php
|
Page.cmdGetPage
|
public function cmdGetPage()
{
$result = $this->getListPage();
$this->outputFormat($result);
$this->outputFormatTablePage($result);
$this->output();
}
|
php
|
public function cmdGetPage()
{
$result = $this->getListPage();
$this->outputFormat($result);
$this->outputFormatTablePage($result);
$this->output();
}
|
[
"public",
"function",
"cmdGetPage",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListPage",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTablePage",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] |
Callback for "page-get" command
|
[
"Callback",
"for",
"page",
"-",
"get",
"command"
] |
e57dba53e291a225b4bff0c0d9b23d685dd1c125
|
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L40-L46
|
25,770
|
gplcart/cli
|
controllers/commands/Page.php
|
Page.cmdDeletePage
|
public function cmdDeletePage()
{
$id = $this->getParam(0);
$all = $this->getParam('all');
$blog = $this->getParam('blog');
if (empty($id) && empty($all) && empty($blog)) {
$this->errorAndExit($this->text('Invalid command'));
}
if (isset($id) && (empty($id) || !is_numeric($id))) {
$this->errorAndExit($this->text('Invalid argument'));
}
$options = null;
if (isset($id)) {
if ($this->getParam('store')) {
$options = array('store_id' => $id);
} else if ($this->getParam('category')) {
$options = array('category_id' => $id);
} else if ($this->getParam('user')) {
$options = array('user_id' => $id);
}
} else if ($blog) {
$options = array('blog_post' => true);
} else if ($all) {
$options = array();
}
if (isset($options)) {
$deleted = $count = 0;
foreach ($this->page->getList($options) as $item) {
$count++;
$deleted += (int) $this->page->delete($item['page_id']);
}
$result = $count && $count == $deleted;
} else {
$result = $this->page->delete($id);
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
}
|
php
|
public function cmdDeletePage()
{
$id = $this->getParam(0);
$all = $this->getParam('all');
$blog = $this->getParam('blog');
if (empty($id) && empty($all) && empty($blog)) {
$this->errorAndExit($this->text('Invalid command'));
}
if (isset($id) && (empty($id) || !is_numeric($id))) {
$this->errorAndExit($this->text('Invalid argument'));
}
$options = null;
if (isset($id)) {
if ($this->getParam('store')) {
$options = array('store_id' => $id);
} else if ($this->getParam('category')) {
$options = array('category_id' => $id);
} else if ($this->getParam('user')) {
$options = array('user_id' => $id);
}
} else if ($blog) {
$options = array('blog_post' => true);
} else if ($all) {
$options = array();
}
if (isset($options)) {
$deleted = $count = 0;
foreach ($this->page->getList($options) as $item) {
$count++;
$deleted += (int) $this->page->delete($item['page_id']);
}
$result = $count && $count == $deleted;
} else {
$result = $this->page->delete($id);
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
}
|
[
"public",
"function",
"cmdDeletePage",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
";",
"$",
"all",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'all'",
")",
";",
"$",
"blog",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'blog'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
"&&",
"empty",
"(",
"$",
"all",
")",
"&&",
"empty",
"(",
"$",
"blog",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"id",
")",
"&&",
"(",
"empty",
"(",
"$",
"id",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"id",
")",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"options",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"id",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getParam",
"(",
"'store'",
")",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'store_id'",
"=>",
"$",
"id",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"getParam",
"(",
"'category'",
")",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'category_id'",
"=>",
"$",
"id",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"getParam",
"(",
"'user'",
")",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'user_id'",
"=>",
"$",
"id",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"blog",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'blog_post'",
"=>",
"true",
")",
";",
"}",
"else",
"if",
"(",
"$",
"all",
")",
"{",
"$",
"options",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
")",
")",
"{",
"$",
"deleted",
"=",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"page",
"->",
"getList",
"(",
"$",
"options",
")",
"as",
"$",
"item",
")",
"{",
"$",
"count",
"++",
";",
"$",
"deleted",
"+=",
"(",
"int",
")",
"$",
"this",
"->",
"page",
"->",
"delete",
"(",
"$",
"item",
"[",
"'page_id'",
"]",
")",
";",
"}",
"$",
"result",
"=",
"$",
"count",
"&&",
"$",
"count",
"==",
"$",
"deleted",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"page",
"->",
"delete",
"(",
"$",
"id",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] |
Callback for "page-delete" command
|
[
"Callback",
"for",
"page",
"-",
"delete",
"command"
] |
e57dba53e291a225b4bff0c0d9b23d685dd1c125
|
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L51-L102
|
25,771
|
gplcart/cli
|
controllers/commands/Page.php
|
Page.cmdUpdatePage
|
public function cmdUpdatePage()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('page');
$this->updatePage($params[0]);
$this->output();
}
|
php
|
public function cmdUpdatePage()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('page');
$this->updatePage($params[0]);
$this->output();
}
|
[
"public",
"function",
"cmdUpdatePage",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'page'",
")",
";",
"$",
"this",
"->",
"updatePage",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] |
Callback for "page-update" command
|
[
"Callback",
"for",
"page",
"-",
"update",
"command"
] |
e57dba53e291a225b4bff0c0d9b23d685dd1c125
|
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L121-L139
|
25,772
|
gplcart/cli
|
controllers/commands/Page.php
|
Page.addPage
|
protected function addPage()
{
if (!$this->isError()) {
$id = $this->page->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
}
|
php
|
protected function addPage()
{
if (!$this->isError()) {
$id = $this->page->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
}
|
[
"protected",
"function",
"addPage",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"page",
"->",
"add",
"(",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"line",
"(",
"$",
"id",
")",
";",
"}",
"}"
] |
Add a new page
|
[
"Add",
"a",
"new",
"page"
] |
e57dba53e291a225b4bff0c0d9b23d685dd1c125
|
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L212-L221
|
25,773
|
gplcart/cli
|
controllers/commands/Page.php
|
Page.submitAddPage
|
protected function submitAddPage()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('page');
$this->addPage();
}
|
php
|
protected function submitAddPage()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('page');
$this->addPage();
}
|
[
"protected",
"function",
"submitAddPage",
"(",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"this",
"->",
"getParam",
"(",
")",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'page'",
")",
";",
"$",
"this",
"->",
"addPage",
"(",
")",
";",
"}"
] |
Add a new page at once
|
[
"Add",
"a",
"new",
"page",
"at",
"once"
] |
e57dba53e291a225b4bff0c0d9b23d685dd1c125
|
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L237-L242
|
25,774
|
gplcart/cli
|
controllers/commands/Page.php
|
Page.wizardAddPage
|
protected function wizardAddPage()
{
// Required
$this->validatePrompt('title', $this->text('Title'), 'page');
$this->validatePrompt('description', $this->text('Description'), 'page');
$this->validatePrompt('store_id', $this->text('Store ID'), 'page');
// Optional
$this->validatePrompt('user_id', $this->text('User ID'), 'page', 0);
$this->validatePrompt('meta_title', $this->text('Meta title'), 'page', '');
$this->validatePrompt('meta_description', $this->text('Meta description'), 'page', '');
$this->validatePrompt('category_id', $this->text('Category ID'), 'page', 0);
$this->validatePrompt('blog_post', $this->text('Blog post'), 'page', 0);
$this->validatePrompt('status', $this->text('Status'), 'page', 0);
$this->validateComponent('page');
$this->addPage();
}
|
php
|
protected function wizardAddPage()
{
// Required
$this->validatePrompt('title', $this->text('Title'), 'page');
$this->validatePrompt('description', $this->text('Description'), 'page');
$this->validatePrompt('store_id', $this->text('Store ID'), 'page');
// Optional
$this->validatePrompt('user_id', $this->text('User ID'), 'page', 0);
$this->validatePrompt('meta_title', $this->text('Meta title'), 'page', '');
$this->validatePrompt('meta_description', $this->text('Meta description'), 'page', '');
$this->validatePrompt('category_id', $this->text('Category ID'), 'page', 0);
$this->validatePrompt('blog_post', $this->text('Blog post'), 'page', 0);
$this->validatePrompt('status', $this->text('Status'), 'page', 0);
$this->validateComponent('page');
$this->addPage();
}
|
[
"protected",
"function",
"wizardAddPage",
"(",
")",
"{",
"// Required",
"$",
"this",
"->",
"validatePrompt",
"(",
"'title'",
",",
"$",
"this",
"->",
"text",
"(",
"'Title'",
")",
",",
"'page'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'description'",
",",
"$",
"this",
"->",
"text",
"(",
"'Description'",
")",
",",
"'page'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'store_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'Store ID'",
")",
",",
"'page'",
")",
";",
"// Optional",
"$",
"this",
"->",
"validatePrompt",
"(",
"'user_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'User ID'",
")",
",",
"'page'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'meta_title'",
",",
"$",
"this",
"->",
"text",
"(",
"'Meta title'",
")",
",",
"'page'",
",",
"''",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'meta_description'",
",",
"$",
"this",
"->",
"text",
"(",
"'Meta description'",
")",
",",
"'page'",
",",
"''",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'category_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'Category ID'",
")",
",",
"'page'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'blog_post'",
",",
"$",
"this",
"->",
"text",
"(",
"'Blog post'",
")",
",",
"'page'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'status'",
",",
"$",
"this",
"->",
"text",
"(",
"'Status'",
")",
",",
"'page'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'page'",
")",
";",
"$",
"this",
"->",
"addPage",
"(",
")",
";",
"}"
] |
Add a new page step by step
|
[
"Add",
"a",
"new",
"page",
"step",
"by",
"step"
] |
e57dba53e291a225b4bff0c0d9b23d685dd1c125
|
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L247-L264
|
25,775
|
eclipxe13/engineworks-progress-status
|
src/EngineWorks/ProgressStatus/Status.php
|
Status.make
|
public static function make($total = 0, $message = '', $value = 0, $startTime = null, $current = null)
{
$now = time();
return new self($current ? : $now, $startTime ? : $now, $value, $total, $message);
}
|
php
|
public static function make($total = 0, $message = '', $value = 0, $startTime = null, $current = null)
{
$now = time();
return new self($current ? : $now, $startTime ? : $now, $value, $total, $message);
}
|
[
"public",
"static",
"function",
"make",
"(",
"$",
"total",
"=",
"0",
",",
"$",
"message",
"=",
"''",
",",
"$",
"value",
"=",
"0",
",",
"$",
"startTime",
"=",
"null",
",",
"$",
"current",
"=",
"null",
")",
"{",
"$",
"now",
"=",
"time",
"(",
")",
";",
"return",
"new",
"self",
"(",
"$",
"current",
"?",
":",
"$",
"now",
",",
"$",
"startTime",
"?",
":",
"$",
"now",
",",
"$",
"value",
",",
"$",
"total",
",",
"$",
"message",
")",
";",
"}"
] |
Helper function to create a new object
@param int $total
@param string $message
@param int $value
@param int|null $startTime if null then uses the value of time()
@param int|null $current if null then uses the value of time()
@return Status
|
[
"Helper",
"function",
"to",
"create",
"a",
"new",
"object"
] |
2eda8e17ba10ff93ca206ffa8039c38acac17bcd
|
https://github.com/eclipxe13/engineworks-progress-status/blob/2eda8e17ba10ff93ca206ffa8039c38acac17bcd/src/EngineWorks/ProgressStatus/Status.php#L49-L53
|
25,776
|
Wedeto/Auth
|
src/ACL/ACL.php
|
ACL.registerClass
|
public function registerClass(string $class, string $name)
{
if (isset($this->classes[$name]))
throw new Exception("Cannot register the same name twice");
if (!is_a($class, ACLModel::class, true))
throw new TypeError("Class must be subclass of ACLModel");
$this->classes[$name] = $class;
$this->classes_names[$class] = $name;
return $this;
}
|
php
|
public function registerClass(string $class, string $name)
{
if (isset($this->classes[$name]))
throw new Exception("Cannot register the same name twice");
if (!is_a($class, ACLModel::class, true))
throw new TypeError("Class must be subclass of ACLModel");
$this->classes[$name] = $class;
$this->classes_names[$class] = $name;
return $this;
}
|
[
"public",
"function",
"registerClass",
"(",
"string",
"$",
"class",
",",
"string",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"classes",
"[",
"$",
"name",
"]",
")",
")",
"throw",
"new",
"Exception",
"(",
"\"Cannot register the same name twice\"",
")",
";",
"if",
"(",
"!",
"is_a",
"(",
"$",
"class",
",",
"ACLModel",
"::",
"class",
",",
"true",
")",
")",
"throw",
"new",
"TypeError",
"(",
"\"Class must be subclass of ACLModel\"",
")",
";",
"$",
"this",
"->",
"classes",
"[",
"$",
"name",
"]",
"=",
"$",
"class",
";",
"$",
"this",
"->",
"classes_names",
"[",
"$",
"class",
"]",
"=",
"$",
"name",
";",
"return",
"$",
"this",
";",
"}"
] |
Register the name of the object class to be used in ACL entity naming.
@param string $class The name of the class
@param string $name The name of the ACL objects
@return $this Provides fluent interface
|
[
"Register",
"the",
"name",
"of",
"the",
"object",
"class",
"to",
"be",
"used",
"in",
"ACL",
"entity",
"naming",
"."
] |
d53777d860a9e67154b84b425e29da5d4dcd28e0
|
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACL.php#L92-L102
|
25,777
|
Wedeto/Auth
|
src/ACL/ACL.php
|
ACL.loadByACLID
|
public function loadByACLID($id)
{
$parts = explode("#", $id);
if (count($parts) !== 2)
throw new Exception("Invalid DAO ID: {$id}");
if (!isset($this->classes[$parts[0]]))
throw new Exception("Invalid DAO type: {$parts[0]}");
$classname = $this->classes[$parts[0]];
$pkey_values = explode("-", $parts[1]);
$db = DB::getInstance();
$dao = $db->getDAO($classname);
return call_user_func(array($dao, "get"), $pkey_values);
}
|
php
|
public function loadByACLID($id)
{
$parts = explode("#", $id);
if (count($parts) !== 2)
throw new Exception("Invalid DAO ID: {$id}");
if (!isset($this->classes[$parts[0]]))
throw new Exception("Invalid DAO type: {$parts[0]}");
$classname = $this->classes[$parts[0]];
$pkey_values = explode("-", $parts[1]);
$db = DB::getInstance();
$dao = $db->getDAO($classname);
return call_user_func(array($dao, "get"), $pkey_values);
}
|
[
"public",
"function",
"loadByACLID",
"(",
"$",
"id",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"\"#\"",
",",
"$",
"id",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"!==",
"2",
")",
"throw",
"new",
"Exception",
"(",
"\"Invalid DAO ID: {$id}\"",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"classes",
"[",
"$",
"parts",
"[",
"0",
"]",
"]",
")",
")",
"throw",
"new",
"Exception",
"(",
"\"Invalid DAO type: {$parts[0]}\"",
")",
";",
"$",
"classname",
"=",
"$",
"this",
"->",
"classes",
"[",
"$",
"parts",
"[",
"0",
"]",
"]",
";",
"$",
"pkey_values",
"=",
"explode",
"(",
"\"-\"",
",",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"$",
"db",
"=",
"DB",
"::",
"getInstance",
"(",
")",
";",
"$",
"dao",
"=",
"$",
"db",
"->",
"getDAO",
"(",
"$",
"classname",
")",
";",
"return",
"call_user_func",
"(",
"array",
"(",
"$",
"dao",
",",
"\"get\"",
")",
",",
"$",
"pkey_values",
")",
";",
"}"
] |
This method will load a new instance to be used in ACL inheritance
|
[
"This",
"method",
"will",
"load",
"a",
"new",
"instance",
"to",
"be",
"used",
"in",
"ACL",
"inheritance"
] |
d53777d860a9e67154b84b425e29da5d4dcd28e0
|
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACL.php#L165-L181
|
25,778
|
Wedeto/Auth
|
src/ACL/ACL.php
|
ACL.getInstance
|
public function getInstance(string $class, $element_id)
{
if (!is_a($class, Hierarchy::class, true))
throw new TypeError("Not a subclass of Hierarchy: $class");
if (is_object($element_id) && get_class($element_id) === $class)
return $element_id;
if (!is_scalar($element_id))
throw new TypeError("Element-ID must be a scalar");
if (!$this->hasInstance($class, $element_id))
{
$root = $class::getRootName();
if ($element_id === $root)
$this->hierarchy[$class][$root] = new $class($this, $root);
else
throw new Exception("Element-ID '{$element_id}' is unknown for {$class}");
}
return $this->hierarchy[$class][$element_id];
}
|
php
|
public function getInstance(string $class, $element_id)
{
if (!is_a($class, Hierarchy::class, true))
throw new TypeError("Not a subclass of Hierarchy: $class");
if (is_object($element_id) && get_class($element_id) === $class)
return $element_id;
if (!is_scalar($element_id))
throw new TypeError("Element-ID must be a scalar");
if (!$this->hasInstance($class, $element_id))
{
$root = $class::getRootName();
if ($element_id === $root)
$this->hierarchy[$class][$root] = new $class($this, $root);
else
throw new Exception("Element-ID '{$element_id}' is unknown for {$class}");
}
return $this->hierarchy[$class][$element_id];
}
|
[
"public",
"function",
"getInstance",
"(",
"string",
"$",
"class",
",",
"$",
"element_id",
")",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"class",
",",
"Hierarchy",
"::",
"class",
",",
"true",
")",
")",
"throw",
"new",
"TypeError",
"(",
"\"Not a subclass of Hierarchy: $class\"",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"element_id",
")",
"&&",
"get_class",
"(",
"$",
"element_id",
")",
"===",
"$",
"class",
")",
"return",
"$",
"element_id",
";",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"element_id",
")",
")",
"throw",
"new",
"TypeError",
"(",
"\"Element-ID must be a scalar\"",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"hasInstance",
"(",
"$",
"class",
",",
"$",
"element_id",
")",
")",
"{",
"$",
"root",
"=",
"$",
"class",
"::",
"getRootName",
"(",
")",
";",
"if",
"(",
"$",
"element_id",
"===",
"$",
"root",
")",
"$",
"this",
"->",
"hierarchy",
"[",
"$",
"class",
"]",
"[",
"$",
"root",
"]",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
",",
"$",
"root",
")",
";",
"else",
"throw",
"new",
"Exception",
"(",
"\"Element-ID '{$element_id}' is unknown for {$class}\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"hierarchy",
"[",
"$",
"class",
"]",
"[",
"$",
"element_id",
"]",
";",
"}"
] |
Get an hierarchy element by specifying its ID
|
[
"Get",
"an",
"hierarchy",
"element",
"by",
"specifying",
"its",
"ID"
] |
d53777d860a9e67154b84b425e29da5d4dcd28e0
|
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACL.php#L186-L207
|
25,779
|
Wedeto/Auth
|
src/ACL/ACL.php
|
ACL.getRoot
|
public function getRoot(string $class)
{
if (!is_a($class, Hierarchy::class, true))
throw new TypeError("Not a subclass of Hierarchy: $class");
$root = $class::getRootName();
return $this->getInstance($class, $root);
}
|
php
|
public function getRoot(string $class)
{
if (!is_a($class, Hierarchy::class, true))
throw new TypeError("Not a subclass of Hierarchy: $class");
$root = $class::getRootName();
return $this->getInstance($class, $root);
}
|
[
"public",
"function",
"getRoot",
"(",
"string",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"class",
",",
"Hierarchy",
"::",
"class",
",",
"true",
")",
")",
"throw",
"new",
"TypeError",
"(",
"\"Not a subclass of Hierarchy: $class\"",
")",
";",
"$",
"root",
"=",
"$",
"class",
"::",
"getRootName",
"(",
")",
";",
"return",
"$",
"this",
"->",
"getInstance",
"(",
"$",
"class",
",",
"$",
"root",
")",
";",
"}"
] |
Return the root element for a certain hierarchy
@param string $class The class name
@return Hierarchy The root element of the hierarchy
@throws Wedeto\Auth\ACL\Exception When an invalid class is passed
|
[
"Return",
"the",
"root",
"element",
"for",
"a",
"certain",
"hierarchy"
] |
d53777d860a9e67154b84b425e29da5d4dcd28e0
|
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACL.php#L216-L223
|
25,780
|
Wedeto/Auth
|
src/ACL/ACL.php
|
ACL.createEntity
|
public function createEntity(string $entity_id, array $parents)
{
$entity = new Entity($this, $entity_id, $parents);
return $entity;
}
|
php
|
public function createEntity(string $entity_id, array $parents)
{
$entity = new Entity($this, $entity_id, $parents);
return $entity;
}
|
[
"public",
"function",
"createEntity",
"(",
"string",
"$",
"entity_id",
",",
"array",
"$",
"parents",
")",
"{",
"$",
"entity",
"=",
"new",
"Entity",
"(",
"$",
"this",
",",
"$",
"entity_id",
",",
"$",
"parents",
")",
";",
"return",
"$",
"entity",
";",
"}"
] |
Create a new entity and store it.
@param string $entity_id The ID of the entity
@param array $parents The parents of the entity
@throws Exception When the entity_id has already been created for this class
|
[
"Create",
"a",
"new",
"entity",
"and",
"store",
"it",
"."
] |
d53777d860a9e67154b84b425e29da5d4dcd28e0
|
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACL.php#L231-L235
|
25,781
|
Wedeto/Auth
|
src/ACL/ACL.php
|
ACL.setInstance
|
public function setInstance(Hierarchy $element)
{
$class = get_class($element);
$this->hierarchy[$class][$element->getID()] = $element;
return $this;
}
|
php
|
public function setInstance(Hierarchy $element)
{
$class = get_class($element);
$this->hierarchy[$class][$element->getID()] = $element;
return $this;
}
|
[
"public",
"function",
"setInstance",
"(",
"Hierarchy",
"$",
"element",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"element",
")",
";",
"$",
"this",
"->",
"hierarchy",
"[",
"$",
"class",
"]",
"[",
"$",
"element",
"->",
"getID",
"(",
")",
"]",
"=",
"$",
"element",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the instance of a specific ID.
@param scalar $id The ID to set the instance for
@return $this Provides fluent interface
|
[
"Set",
"the",
"instance",
"of",
"a",
"specific",
"ID",
"."
] |
d53777d860a9e67154b84b425e29da5d4dcd28e0
|
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACL.php#L273-L278
|
25,782
|
itkg/core
|
src/Itkg/Core/Command/DatabaseUpdate/Template/Loader.php
|
Loader.load
|
public function load($file, array $data = array())
{
$this->queries = array();
$this->data = $data;
include $file;
return $this;
}
|
php
|
public function load($file, array $data = array())
{
$this->queries = array();
$this->data = $data;
include $file;
return $this;
}
|
[
"public",
"function",
"load",
"(",
"$",
"file",
",",
"array",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"queries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
";",
"include",
"$",
"file",
";",
"return",
"$",
"this",
";",
"}"
] |
Load script file
@param $file
@return $this
|
[
"Load",
"script",
"file"
] |
e5e4efb05feb4d23b0df41f2b21fd095103e593b
|
https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Command/DatabaseUpdate/Template/Loader.php#L49-L57
|
25,783
|
beMang/phpgone
|
core/Core/BackController.php
|
BackController.execute
|
public function execute()
{
if (method_exists($this, 'setUp')) {
call_user_func_array([$this, 'setUp'], [$this->request]);
}
call_user_func_array([$this, $this->action], [$this->request]);
}
|
php
|
public function execute()
{
if (method_exists($this, 'setUp')) {
call_user_func_array([$this, 'setUp'], [$this->request]);
}
call_user_func_array([$this, $this->action], [$this->request]);
}
|
[
"public",
"function",
"execute",
"(",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'setUp'",
")",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"'setUp'",
"]",
",",
"[",
"$",
"this",
"->",
"request",
"]",
")",
";",
"}",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"$",
"this",
"->",
"action",
"]",
",",
"[",
"$",
"this",
"->",
"request",
"]",
")",
";",
"}"
] |
Execute la bonne fonction enfante en fonction de l'action
@return void
|
[
"Execute",
"la",
"bonne",
"fonction",
"enfante",
"en",
"fonction",
"de",
"l",
"action"
] |
6da468283880b7f5b28dc3735f8f13c97382710b
|
https://github.com/beMang/phpgone/blob/6da468283880b7f5b28dc3735f8f13c97382710b/core/Core/BackController.php#L34-L40
|
25,784
|
Rudloff/php-dicollecte-lexicon
|
classes/Lexicon.php
|
Lexicon.getBy
|
private function getBy($search, $column)
{
$search = mb_strtolower($search, mb_detect_encoding($search));
$this->procBuilder->setArguments(['-e', "\t$search\t"]);
$process = $this->procBuilder->getProcess();
$process->run();
$csv = Csv\Reader::createFromString($process->getOutput());
$csv->setDelimiter($this->delimiter);
$results = [];
foreach ($csv->fetchAssoc(['id', 'inflection', 'lemma', 'tags']) as $row) {
if ($row[$column] == $search) {
$results[] = new Inflection($row['id'], $row['inflection'], $row['lemma'], explode(' ', $row['tags']));
}
}
return $results;
}
|
php
|
private function getBy($search, $column)
{
$search = mb_strtolower($search, mb_detect_encoding($search));
$this->procBuilder->setArguments(['-e', "\t$search\t"]);
$process = $this->procBuilder->getProcess();
$process->run();
$csv = Csv\Reader::createFromString($process->getOutput());
$csv->setDelimiter($this->delimiter);
$results = [];
foreach ($csv->fetchAssoc(['id', 'inflection', 'lemma', 'tags']) as $row) {
if ($row[$column] == $search) {
$results[] = new Inflection($row['id'], $row['inflection'], $row['lemma'], explode(' ', $row['tags']));
}
}
return $results;
}
|
[
"private",
"function",
"getBy",
"(",
"$",
"search",
",",
"$",
"column",
")",
"{",
"$",
"search",
"=",
"mb_strtolower",
"(",
"$",
"search",
",",
"mb_detect_encoding",
"(",
"$",
"search",
")",
")",
";",
"$",
"this",
"->",
"procBuilder",
"->",
"setArguments",
"(",
"[",
"'-e'",
",",
"\"\\t$search\\t\"",
"]",
")",
";",
"$",
"process",
"=",
"$",
"this",
"->",
"procBuilder",
"->",
"getProcess",
"(",
")",
";",
"$",
"process",
"->",
"run",
"(",
")",
";",
"$",
"csv",
"=",
"Csv",
"\\",
"Reader",
"::",
"createFromString",
"(",
"$",
"process",
"->",
"getOutput",
"(",
")",
")",
";",
"$",
"csv",
"->",
"setDelimiter",
"(",
"$",
"this",
"->",
"delimiter",
")",
";",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"csv",
"->",
"fetchAssoc",
"(",
"[",
"'id'",
",",
"'inflection'",
",",
"'lemma'",
",",
"'tags'",
"]",
")",
"as",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"row",
"[",
"$",
"column",
"]",
"==",
"$",
"search",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"new",
"Inflection",
"(",
"$",
"row",
"[",
"'id'",
"]",
",",
"$",
"row",
"[",
"'inflection'",
"]",
",",
"$",
"row",
"[",
"'lemma'",
"]",
",",
"explode",
"(",
"' '",
",",
"$",
"row",
"[",
"'tags'",
"]",
")",
")",
";",
"}",
"}",
"return",
"$",
"results",
";",
"}"
] |
Get inflections by searching in a specific column.
@param string $search String to search
@param string $column Column name
@return Inflection[] Search results
|
[
"Get",
"inflections",
"by",
"searching",
"in",
"a",
"specific",
"column",
"."
] |
d868c1ef8d844edfdd012a7ef051cf9a2ca69f9e
|
https://github.com/Rudloff/php-dicollecte-lexicon/blob/d868c1ef8d844edfdd012a7ef051cf9a2ca69f9e/classes/Lexicon.php#L57-L73
|
25,785
|
ScaraMVC/Framework
|
src/Scara/Http/Groups/Groupable.php
|
Groupable.finalize
|
public function finalize()
{
$gen = new UrlGenerator();
if (!empty($this->redirect)) {
$gen->redirect($this->redirect);
}
}
|
php
|
public function finalize()
{
$gen = new UrlGenerator();
if (!empty($this->redirect)) {
$gen->redirect($this->redirect);
}
}
|
[
"public",
"function",
"finalize",
"(",
")",
"{",
"$",
"gen",
"=",
"new",
"UrlGenerator",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"redirect",
")",
")",
"{",
"$",
"gen",
"->",
"redirect",
"(",
"$",
"this",
"->",
"redirect",
")",
";",
"}",
"}"
] |
Finalize groups that implement the Groupable trait.
@return void
|
[
"Finalize",
"groups",
"that",
"implement",
"the",
"Groupable",
"trait",
"."
] |
199b08b45fadf5dae14ac4732af03b36e15bbef2
|
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Http/Groups/Groupable.php#L24-L30
|
25,786
|
congraphcms/core
|
Helpers/StringHelper.php
|
StringHelper.createSlug
|
public static function createSlug($string)
{
// remove all accent characters
$string = self::remove_accents($string);
// lowercase
$string = strtolower($string);
// replace all characters except letters and numbers to dashes
$slug = preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
// deep replace double dashes
while(strpos('--', $slug))
{
$slug = str_replace('--', '-', $slug);
}
// trim dashes at start and end
$slug = trim($slug, '-');
return $slug;
}
|
php
|
public static function createSlug($string)
{
// remove all accent characters
$string = self::remove_accents($string);
// lowercase
$string = strtolower($string);
// replace all characters except letters and numbers to dashes
$slug = preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
// deep replace double dashes
while(strpos('--', $slug))
{
$slug = str_replace('--', '-', $slug);
}
// trim dashes at start and end
$slug = trim($slug, '-');
return $slug;
}
|
[
"public",
"static",
"function",
"createSlug",
"(",
"$",
"string",
")",
"{",
"// remove all accent characters",
"$",
"string",
"=",
"self",
"::",
"remove_accents",
"(",
"$",
"string",
")",
";",
"// lowercase",
"$",
"string",
"=",
"strtolower",
"(",
"$",
"string",
")",
";",
"// replace all characters except letters and numbers to dashes",
"$",
"slug",
"=",
"preg_replace",
"(",
"'/[^A-Za-z0-9-]+/'",
",",
"'-'",
",",
"$",
"string",
")",
";",
"// deep replace double dashes",
"while",
"(",
"strpos",
"(",
"'--'",
",",
"$",
"slug",
")",
")",
"{",
"$",
"slug",
"=",
"str_replace",
"(",
"'--'",
",",
"'-'",
",",
"$",
"slug",
")",
";",
"}",
"// trim dashes at start and end",
"$",
"slug",
"=",
"trim",
"(",
"$",
"slug",
",",
"'-'",
")",
";",
"return",
"$",
"slug",
";",
"}"
] |
Creates slug from any string
@param string $string
@return string
|
[
"Creates",
"slug",
"from",
"any",
"string"
] |
d017d3951b446fb2ac93b8fcee120549bb125b17
|
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Helpers/StringHelper.php#L38-L59
|
25,787
|
vainproject/vain-site
|
src/Site/Http/Requests/PageFormRequest.php
|
PageFormRequest.rules
|
public function rules()
{
$attributes = [
'title' => 'required',
'text' => 'required',
];
$rules = $this->buildLocalizedRules($attributes);
return array_merge($rules, [
'id' => 'exists:site_pages,id',
'slug' => 'required|alpha_dash|unique:site_pages,slug,'.$this->route('sites'),
'published_at' => 'date',
'concealed_at' => 'date',
]);
}
|
php
|
public function rules()
{
$attributes = [
'title' => 'required',
'text' => 'required',
];
$rules = $this->buildLocalizedRules($attributes);
return array_merge($rules, [
'id' => 'exists:site_pages,id',
'slug' => 'required|alpha_dash|unique:site_pages,slug,'.$this->route('sites'),
'published_at' => 'date',
'concealed_at' => 'date',
]);
}
|
[
"public",
"function",
"rules",
"(",
")",
"{",
"$",
"attributes",
"=",
"[",
"'title'",
"=>",
"'required'",
",",
"'text'",
"=>",
"'required'",
",",
"]",
";",
"$",
"rules",
"=",
"$",
"this",
"->",
"buildLocalizedRules",
"(",
"$",
"attributes",
")",
";",
"return",
"array_merge",
"(",
"$",
"rules",
",",
"[",
"'id'",
"=>",
"'exists:site_pages,id'",
",",
"'slug'",
"=>",
"'required|alpha_dash|unique:site_pages,slug,'",
".",
"$",
"this",
"->",
"route",
"(",
"'sites'",
")",
",",
"'published_at'",
"=>",
"'date'",
",",
"'concealed_at'",
"=>",
"'date'",
",",
"]",
")",
";",
"}"
] |
validation that has to pass.
@return array
|
[
"validation",
"that",
"has",
"to",
"pass",
"."
] |
d5560df68264f7ac1692c3dcfebc40500148dd56
|
https://github.com/vainproject/vain-site/blob/d5560df68264f7ac1692c3dcfebc40500148dd56/src/Site/Http/Requests/PageFormRequest.php#L16-L31
|
25,788
|
vainproject/vain-site
|
src/Site/Http/Requests/PageFormRequest.php
|
PageFormRequest.buildLocalizedRules
|
protected function buildLocalizedRules($attributes)
{
$rules = [];
$locales = config('app.locales');
foreach ($locales as $locale => $name) {
foreach ($attributes as $attribute => $rule) {
$rules[$attribute.'_'.$locale] = $rule;
}
}
return $rules;
}
|
php
|
protected function buildLocalizedRules($attributes)
{
$rules = [];
$locales = config('app.locales');
foreach ($locales as $locale => $name) {
foreach ($attributes as $attribute => $rule) {
$rules[$attribute.'_'.$locale] = $rule;
}
}
return $rules;
}
|
[
"protected",
"function",
"buildLocalizedRules",
"(",
"$",
"attributes",
")",
"{",
"$",
"rules",
"=",
"[",
"]",
";",
"$",
"locales",
"=",
"config",
"(",
"'app.locales'",
")",
";",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"locale",
"=>",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"rule",
")",
"{",
"$",
"rules",
"[",
"$",
"attribute",
".",
"'_'",
".",
"$",
"locale",
"]",
"=",
"$",
"rule",
";",
"}",
"}",
"return",
"$",
"rules",
";",
"}"
] |
builds localized suffixed rules for validation.
@param $attributes
@return array
|
[
"builds",
"localized",
"suffixed",
"rules",
"for",
"validation",
"."
] |
d5560df68264f7ac1692c3dcfebc40500148dd56
|
https://github.com/vainproject/vain-site/blob/d5560df68264f7ac1692c3dcfebc40500148dd56/src/Site/Http/Requests/PageFormRequest.php#L48-L60
|
25,789
|
nochso/ORM2
|
src/Model.php
|
Model.getPrimaryKeyValue
|
public function getPrimaryKeyValue()
{
$primaryKey = $this->getPrimaryKey();
if (isset($this->$primaryKey)) {
return $this->$primaryKey;
} else {
return null;
}
}
|
php
|
public function getPrimaryKeyValue()
{
$primaryKey = $this->getPrimaryKey();
if (isset($this->$primaryKey)) {
return $this->$primaryKey;
} else {
return null;
}
}
|
[
"public",
"function",
"getPrimaryKeyValue",
"(",
")",
"{",
"$",
"primaryKey",
"=",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"$",
"primaryKey",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"primaryKey",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Returns the value of the primary key
@return null
|
[
"Returns",
"the",
"value",
"of",
"the",
"primary",
"key"
] |
89f9a5c61ad5f575fbdd52990171b52d54f8bfbc
|
https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/Model.php#L105-L113
|
25,790
|
nochso/ORM2
|
src/Model.php
|
Model.toAssoc
|
public function toAssoc()
{
$params = [];
foreach (Extract::getObjectVars($this) as $key => $value) {
if (!$value instanceof Relation) {
$params[$key] = $value;
}
}
if ($this->getPrimaryKeyValue() === null) {
unset($params[$this->getPrimaryKey()]);
}
return $params;
}
|
php
|
public function toAssoc()
{
$params = [];
foreach (Extract::getObjectVars($this) as $key => $value) {
if (!$value instanceof Relation) {
$params[$key] = $value;
}
}
if ($this->getPrimaryKeyValue() === null) {
unset($params[$this->getPrimaryKey()]);
}
return $params;
}
|
[
"public",
"function",
"toAssoc",
"(",
")",
"{",
"$",
"params",
"=",
"[",
"]",
";",
"foreach",
"(",
"Extract",
"::",
"getObjectVars",
"(",
"$",
"this",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"value",
"instanceof",
"Relation",
")",
"{",
"$",
"params",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"getPrimaryKeyValue",
"(",
")",
"===",
"null",
")",
"{",
"unset",
"(",
"$",
"params",
"[",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
"]",
")",
";",
"}",
"return",
"$",
"params",
";",
"}"
] |
Returns an associative array from this object excluding private variables and Relation objects
@return array
|
[
"Returns",
"an",
"associative",
"array",
"from",
"this",
"object",
"excluding",
"private",
"variables",
"and",
"Relation",
"objects"
] |
89f9a5c61ad5f575fbdd52990171b52d54f8bfbc
|
https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/Model.php#L268-L280
|
25,791
|
nochso/ORM2
|
src/Model.php
|
Model.hydrate
|
public function hydrate($data, $removePrimaryKey = false)
{
foreach ($data as $key => $value) {
if (property_exists($this, $key)) {
$this->$key = $value;
} else {
$this->extra[$key] = $value;
}
}
if ($removePrimaryKey) {
$key = $this->getPrimaryKey();
$this->$key = null;
}
return $this;
}
|
php
|
public function hydrate($data, $removePrimaryKey = false)
{
foreach ($data as $key => $value) {
if (property_exists($this, $key)) {
$this->$key = $value;
} else {
$this->extra[$key] = $value;
}
}
if ($removePrimaryKey) {
$key = $this->getPrimaryKey();
$this->$key = null;
}
return $this;
}
|
[
"public",
"function",
"hydrate",
"(",
"$",
"data",
",",
"$",
"removePrimaryKey",
"=",
"false",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"extra",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"if",
"(",
"$",
"removePrimaryKey",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"this",
"->",
"$",
"key",
"=",
"null",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the properties of this object using an associative array,
where key is the property name and value is the property value.
Properties that do not exist in the current context are ignored.
@param array $data Associative array
@param bool $removePrimaryKey Optional: If true, the primary key of the
model will be unset. This is useful for hydrating a new object
and the source ($_POST) erroneously supplies a primary key.
Default: false
@return static
|
[
"Sets",
"the",
"properties",
"of",
"this",
"object",
"using",
"an",
"associative",
"array",
"where",
"key",
"is",
"the",
"property",
"name",
"and",
"value",
"is",
"the",
"property",
"value",
"."
] |
89f9a5c61ad5f575fbdd52990171b52d54f8bfbc
|
https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/Model.php#L296-L310
|
25,792
|
nochso/ORM2
|
src/Model.php
|
Model.limit
|
public function limit($limit, $offset = null)
{
$this->queryBuilder->setLimit($limit, $offset);
return $this;
}
|
php
|
public function limit($limit, $offset = null)
{
$this->queryBuilder->setLimit($limit, $offset);
return $this;
}
|
[
"public",
"function",
"limit",
"(",
"$",
"limit",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"queryBuilder",
"->",
"setLimit",
"(",
"$",
"limit",
",",
"$",
"offset",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Limit the amount of maximum rows returned
@param int $limit
@param int $offset
@return static
|
[
"Limit",
"the",
"amount",
"of",
"maximum",
"rows",
"returned"
] |
89f9a5c61ad5f575fbdd52990171b52d54f8bfbc
|
https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/Model.php#L503-L507
|
25,793
|
Wedeto/Auth
|
src/ACL/DBRuleLoader.php
|
DBRuleLoader.loadRules
|
public function loadRules(string $entity_id)
{
$records = ACLRule::get(["entity_id" => $entity_id]);
$rules = array();
foreach ($records as $record)
{
$rule = new Rule($record->entity_id, $record->role_id, $record->action, $record->policy);
$rule->setRecord($record);
$rules[] = $rule;
}
return $rules;
}
|
php
|
public function loadRules(string $entity_id)
{
$records = ACLRule::get(["entity_id" => $entity_id]);
$rules = array();
foreach ($records as $record)
{
$rule = new Rule($record->entity_id, $record->role_id, $record->action, $record->policy);
$rule->setRecord($record);
$rules[] = $rule;
}
return $rules;
}
|
[
"public",
"function",
"loadRules",
"(",
"string",
"$",
"entity_id",
")",
"{",
"$",
"records",
"=",
"ACLRule",
"::",
"get",
"(",
"[",
"\"entity_id\"",
"=>",
"$",
"entity_id",
"]",
")",
";",
"$",
"rules",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"$",
"rule",
"=",
"new",
"Rule",
"(",
"$",
"record",
"->",
"entity_id",
",",
"$",
"record",
"->",
"role_id",
",",
"$",
"record",
"->",
"action",
",",
"$",
"record",
"->",
"policy",
")",
";",
"$",
"rule",
"->",
"setRecord",
"(",
"$",
"record",
")",
";",
"$",
"rules",
"[",
"]",
"=",
"$",
"rule",
";",
"}",
"return",
"$",
"rules",
";",
"}"
] |
Loads the rules for the specified entity from the database.
|
[
"Loads",
"the",
"rules",
"for",
"the",
"specified",
"entity",
"from",
"the",
"database",
"."
] |
d53777d860a9e67154b84b425e29da5d4dcd28e0
|
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/DBRuleLoader.php#L38-L50
|
25,794
|
randomhost/image
|
src/php/Text/Generic.php
|
Generic.setTextFont
|
public function setTextFont($path)
{
if (!is_file($path) || !is_readable($path)) {
throw new \InvalidArgumentException(
'Unable to load font file at ' . $path
);
}
$this->textFontPath = realpath($path);
return $this;
}
|
php
|
public function setTextFont($path)
{
if (!is_file($path) || !is_readable($path)) {
throw new \InvalidArgumentException(
'Unable to load font file at ' . $path
);
}
$this->textFontPath = realpath($path);
return $this;
}
|
[
"public",
"function",
"setTextFont",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"path",
")",
"||",
"!",
"is_readable",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unable to load font file at '",
".",
"$",
"path",
")",
";",
"}",
"$",
"this",
"->",
"textFontPath",
"=",
"realpath",
"(",
"$",
"path",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the path to the font file used for rendering text overlays onto the
image.
@param string $path File system path to TTF font file to be used.
@return $this
@throws \InvalidArgumentException Thrown if the font file could not be loaded.
|
[
"Sets",
"the",
"path",
"to",
"the",
"font",
"file",
"used",
"for",
"rendering",
"text",
"overlays",
"onto",
"the",
"image",
"."
] |
bd669ba6b50fd2bbbe50c4ef06235b111a8a30b0
|
https://github.com/randomhost/image/blob/bd669ba6b50fd2bbbe50c4ef06235b111a8a30b0/src/php/Text/Generic.php#L121-L132
|
25,795
|
bearframework/localization-addon
|
classes/Localization.php
|
Localization.addDictionary
|
public function addDictionary(string $locale, $callbackOrArray): \BearFramework\Localization
{
if (!isset($this->dictionaries[$locale])) {
$this->dictionaries[$locale] = [];
}
$this->dictionaries[$locale][] = $callbackOrArray;
return $this;
}
|
php
|
public function addDictionary(string $locale, $callbackOrArray): \BearFramework\Localization
{
if (!isset($this->dictionaries[$locale])) {
$this->dictionaries[$locale] = [];
}
$this->dictionaries[$locale][] = $callbackOrArray;
return $this;
}
|
[
"public",
"function",
"addDictionary",
"(",
"string",
"$",
"locale",
",",
"$",
"callbackOrArray",
")",
":",
"\\",
"BearFramework",
"\\",
"Localization",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"dictionaries",
"[",
"$",
"locale",
"]",
")",
")",
"{",
"$",
"this",
"->",
"dictionaries",
"[",
"$",
"locale",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"dictionaries",
"[",
"$",
"locale",
"]",
"[",
"]",
"=",
"$",
"callbackOrArray",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a new dictionary.
@param string $locale A locale code.
@param type $callbackOrArray An array containing dictionary data (in key=>value format) or a callback that returns such array.
@return \BearFramework\Localization Returns a instance to itself.
|
[
"Adds",
"a",
"new",
"dictionary",
"."
] |
7feb1b85bf5b808a1883f98bbfb40c4eb83bb139
|
https://github.com/bearframework/localization-addon/blob/7feb1b85bf5b808a1883f98bbfb40c4eb83bb139/classes/Localization.php#L86-L93
|
25,796
|
bearframework/localization-addon
|
classes/Localization.php
|
Localization.getText
|
public function getText(string $id): ?string
{
$getText = function(string $id, string $locale) {
if (isset($this->defaultLocales[$locale]) && $this->defaultLocales[$locale] === 0) {
$app = App::get();
$context = $app->contexts->get(__FILE__);
$this->defaultLocales[$locale] = 1;
$filename = $context->dir . '/locales/' . $locale . '.php';
if (is_file($filename)) {
$data = include $filename;
if (is_array($data)) {
$this->addDictionary($locale, $data);
}
}
}
if (isset($this->dictionaries[$locale])) {
foreach ($this->dictionaries[$locale] as $i => $dictionary) {
if (is_callable($dictionary)) {
$dictionary = call_user_func($dictionary);
$this->dictionaries[$locale][$i] = $dictionary;
}
if (is_array($dictionary)) {
foreach ($dictionary as $_id => $text) {
if ($id === $_id) {
return (string) $text;
}
}
}
}
}
return null;
};
$text = $getText($id, $this->locale);
if ($text === null || !isset($text[0])) {
$text = $getText($id, $this->backupLocale);
}
return $text;
}
|
php
|
public function getText(string $id): ?string
{
$getText = function(string $id, string $locale) {
if (isset($this->defaultLocales[$locale]) && $this->defaultLocales[$locale] === 0) {
$app = App::get();
$context = $app->contexts->get(__FILE__);
$this->defaultLocales[$locale] = 1;
$filename = $context->dir . '/locales/' . $locale . '.php';
if (is_file($filename)) {
$data = include $filename;
if (is_array($data)) {
$this->addDictionary($locale, $data);
}
}
}
if (isset($this->dictionaries[$locale])) {
foreach ($this->dictionaries[$locale] as $i => $dictionary) {
if (is_callable($dictionary)) {
$dictionary = call_user_func($dictionary);
$this->dictionaries[$locale][$i] = $dictionary;
}
if (is_array($dictionary)) {
foreach ($dictionary as $_id => $text) {
if ($id === $_id) {
return (string) $text;
}
}
}
}
}
return null;
};
$text = $getText($id, $this->locale);
if ($text === null || !isset($text[0])) {
$text = $getText($id, $this->backupLocale);
}
return $text;
}
|
[
"public",
"function",
"getText",
"(",
"string",
"$",
"id",
")",
":",
"?",
"string",
"{",
"$",
"getText",
"=",
"function",
"(",
"string",
"$",
"id",
",",
"string",
"$",
"locale",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"defaultLocales",
"[",
"$",
"locale",
"]",
")",
"&&",
"$",
"this",
"->",
"defaultLocales",
"[",
"$",
"locale",
"]",
"===",
"0",
")",
"{",
"$",
"app",
"=",
"App",
"::",
"get",
"(",
")",
";",
"$",
"context",
"=",
"$",
"app",
"->",
"contexts",
"->",
"get",
"(",
"__FILE__",
")",
";",
"$",
"this",
"->",
"defaultLocales",
"[",
"$",
"locale",
"]",
"=",
"1",
";",
"$",
"filename",
"=",
"$",
"context",
"->",
"dir",
".",
"'/locales/'",
".",
"$",
"locale",
".",
"'.php'",
";",
"if",
"(",
"is_file",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"data",
"=",
"include",
"$",
"filename",
";",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"addDictionary",
"(",
"$",
"locale",
",",
"$",
"data",
")",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dictionaries",
"[",
"$",
"locale",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"dictionaries",
"[",
"$",
"locale",
"]",
"as",
"$",
"i",
"=>",
"$",
"dictionary",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"dictionary",
")",
")",
"{",
"$",
"dictionary",
"=",
"call_user_func",
"(",
"$",
"dictionary",
")",
";",
"$",
"this",
"->",
"dictionaries",
"[",
"$",
"locale",
"]",
"[",
"$",
"i",
"]",
"=",
"$",
"dictionary",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"dictionary",
")",
")",
"{",
"foreach",
"(",
"$",
"dictionary",
"as",
"$",
"_id",
"=>",
"$",
"text",
")",
"{",
"if",
"(",
"$",
"id",
"===",
"$",
"_id",
")",
"{",
"return",
"(",
"string",
")",
"$",
"text",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"null",
";",
"}",
";",
"$",
"text",
"=",
"$",
"getText",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"locale",
")",
";",
"if",
"(",
"$",
"text",
"===",
"null",
"||",
"!",
"isset",
"(",
"$",
"text",
"[",
"0",
"]",
")",
")",
"{",
"$",
"text",
"=",
"$",
"getText",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"backupLocale",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
] |
Returns a text from the dictionary for the current locale.
@param string $id The ID of the text.
@return string A text from the dictionary for the current locale. Returns null if no text is found.
|
[
"Returns",
"a",
"text",
"from",
"the",
"dictionary",
"for",
"the",
"current",
"locale",
"."
] |
7feb1b85bf5b808a1883f98bbfb40c4eb83bb139
|
https://github.com/bearframework/localization-addon/blob/7feb1b85bf5b808a1883f98bbfb40c4eb83bb139/classes/Localization.php#L100-L137
|
25,797
|
wb-crowdfusion/crowdfusion
|
system/core/classes/libraries/database/AbstractMySQLDataSource.php
|
AbstractMySQLDataSource.getNewConnection
|
protected function getNewConnection($connections)
{
$connection = $this->ApplicationContext->object($this->DatabaseServiceName);
$connection->setConnectionInfo($connections);
return $connection;
}
|
php
|
protected function getNewConnection($connections)
{
$connection = $this->ApplicationContext->object($this->DatabaseServiceName);
$connection->setConnectionInfo($connections);
return $connection;
}
|
[
"protected",
"function",
"getNewConnection",
"(",
"$",
"connections",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"ApplicationContext",
"->",
"object",
"(",
"$",
"this",
"->",
"DatabaseServiceName",
")",
";",
"$",
"connection",
"->",
"setConnectionInfo",
"(",
"$",
"connections",
")",
";",
"return",
"$",
"connection",
";",
"}"
] |
Gets a new connection using the connection info given
@param array $connectionInfo An array of connection info
@return DatabaseInterface
|
[
"Gets",
"a",
"new",
"connection",
"using",
"the",
"connection",
"info",
"given"
] |
8cad7988f046a6fefbed07d026cb4ae6706c1217
|
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/AbstractMySQLDataSource.php#L52-L57
|
25,798
|
LpFactory/NestedSetRoutingBundle
|
Configuration/AbstractPageRouteConfiguration.php
|
AbstractPageRouteConfiguration.isMatching
|
public function isMatching($url)
{
if ($this->getRegex() === null) {
return true;
}
if (preg_match($this->getRegex(), $url)) {
return true;
}
return false;
}
|
php
|
public function isMatching($url)
{
if ($this->getRegex() === null) {
return true;
}
if (preg_match($this->getRegex(), $url)) {
return true;
}
return false;
}
|
[
"public",
"function",
"isMatching",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getRegex",
"(",
")",
"===",
"null",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"preg_match",
"(",
"$",
"this",
"->",
"getRegex",
"(",
")",
",",
"$",
"url",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Check if route configuration matches url
@param string $url
@return null|string
|
[
"Check",
"if",
"route",
"configuration",
"matches",
"url"
] |
dc07227a6764e657b7b321827a18127ec18ba214
|
https://github.com/LpFactory/NestedSetRoutingBundle/blob/dc07227a6764e657b7b321827a18127ec18ba214/Configuration/AbstractPageRouteConfiguration.php#L29-L40
|
25,799
|
LpFactory/NestedSetRoutingBundle
|
Configuration/AbstractPageRouteConfiguration.php
|
AbstractPageRouteConfiguration.extractPathInfo
|
public function extractPathInfo($pathInfo)
{
if ($this->getRegex() === null) {
return $pathInfo;
}
preg_match($this->getRegex(), $pathInfo, $matches);
if (isset($matches[1])) {
return $matches[1];
} else {
// Empty then root node ("/" or "/edit)
return "/";
}
}
|
php
|
public function extractPathInfo($pathInfo)
{
if ($this->getRegex() === null) {
return $pathInfo;
}
preg_match($this->getRegex(), $pathInfo, $matches);
if (isset($matches[1])) {
return $matches[1];
} else {
// Empty then root node ("/" or "/edit)
return "/";
}
}
|
[
"public",
"function",
"extractPathInfo",
"(",
"$",
"pathInfo",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getRegex",
"(",
")",
"===",
"null",
")",
"{",
"return",
"$",
"pathInfo",
";",
"}",
"preg_match",
"(",
"$",
"this",
"->",
"getRegex",
"(",
")",
",",
"$",
"pathInfo",
",",
"$",
"matches",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"// Empty then root node (\"/\" or \"/edit)",
"return",
"\"/\"",
";",
"}",
"}"
] |
Extract page pathinfo
Call isMatching before to be sure regex matches
@param $pathInfo
@return string
|
[
"Extract",
"page",
"pathinfo",
"Call",
"isMatching",
"before",
"to",
"be",
"sure",
"regex",
"matches"
] |
dc07227a6764e657b7b321827a18127ec18ba214
|
https://github.com/LpFactory/NestedSetRoutingBundle/blob/dc07227a6764e657b7b321827a18127ec18ba214/Configuration/AbstractPageRouteConfiguration.php#L50-L64
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.