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
|
---|---|---|---|---|---|---|---|---|---|---|---|
21,000 |
gpupo/common-schema
|
src/ORM/Entity/Trading/Order/Shipping/Shipping.php
|
Shipping.removeInvoice
|
public function removeInvoice(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Invoice\Invoice $invoice)
{
return $this->invoices->removeElement($invoice);
}
|
php
|
public function removeInvoice(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Invoice\Invoice $invoice)
{
return $this->invoices->removeElement($invoice);
}
|
[
"public",
"function",
"removeInvoice",
"(",
"\\",
"Gpupo",
"\\",
"CommonSchema",
"\\",
"ORM",
"\\",
"Entity",
"\\",
"Trading",
"\\",
"Order",
"\\",
"Shipping",
"\\",
"Invoice",
"\\",
"Invoice",
"$",
"invoice",
")",
"{",
"return",
"$",
"this",
"->",
"invoices",
"->",
"removeElement",
"(",
"$",
"invoice",
")",
";",
"}"
] |
Remove invoice.
@param \Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Invoice\Invoice $invoice
@return bool TRUE if this collection contained the specified element, FALSE otherwise
|
[
"Remove",
"invoice",
"."
] |
a762d2eb3063b7317c72c69cbb463b1f95b86b0a
|
https://github.com/gpupo/common-schema/blob/a762d2eb3063b7317c72c69cbb463b1f95b86b0a/src/ORM/Entity/Trading/Order/Shipping/Shipping.php#L795-L798
|
21,001 |
gpupo/common-schema
|
src/ORM/Entity/Trading/Order/Shipping/Shipping.php
|
Shipping.addPayment
|
public function addPayment(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Payment\Payment $payment)
{
$this->payments[] = $payment;
return $this;
}
|
php
|
public function addPayment(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Payment\Payment $payment)
{
$this->payments[] = $payment;
return $this;
}
|
[
"public",
"function",
"addPayment",
"(",
"\\",
"Gpupo",
"\\",
"CommonSchema",
"\\",
"ORM",
"\\",
"Entity",
"\\",
"Trading",
"\\",
"Order",
"\\",
"Shipping",
"\\",
"Payment",
"\\",
"Payment",
"$",
"payment",
")",
"{",
"$",
"this",
"->",
"payments",
"[",
"]",
"=",
"$",
"payment",
";",
"return",
"$",
"this",
";",
"}"
] |
Add payment.
@param \Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Payment\Payment $payment
@return Shipping
|
[
"Add",
"payment",
"."
] |
a762d2eb3063b7317c72c69cbb463b1f95b86b0a
|
https://github.com/gpupo/common-schema/blob/a762d2eb3063b7317c72c69cbb463b1f95b86b0a/src/ORM/Entity/Trading/Order/Shipping/Shipping.php#L889-L894
|
21,002 |
gpupo/common-schema
|
src/ORM/Entity/Trading/Order/Shipping/Shipping.php
|
Shipping.addConciliation
|
public function addConciliation(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Conciliation\Conciliation $conciliation)
{
$this->conciliations[] = $conciliation;
return $this;
}
|
php
|
public function addConciliation(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Conciliation\Conciliation $conciliation)
{
$this->conciliations[] = $conciliation;
return $this;
}
|
[
"public",
"function",
"addConciliation",
"(",
"\\",
"Gpupo",
"\\",
"CommonSchema",
"\\",
"ORM",
"\\",
"Entity",
"\\",
"Trading",
"\\",
"Order",
"\\",
"Shipping",
"\\",
"Conciliation",
"\\",
"Conciliation",
"$",
"conciliation",
")",
"{",
"$",
"this",
"->",
"conciliations",
"[",
"]",
"=",
"$",
"conciliation",
";",
"return",
"$",
"this",
";",
"}"
] |
Add conciliation.
@param \Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Conciliation\Conciliation $conciliation
@return Shipping
|
[
"Add",
"conciliation",
"."
] |
a762d2eb3063b7317c72c69cbb463b1f95b86b0a
|
https://github.com/gpupo/common-schema/blob/a762d2eb3063b7317c72c69cbb463b1f95b86b0a/src/ORM/Entity/Trading/Order/Shipping/Shipping.php#L925-L930
|
21,003 |
gpupo/common-schema
|
src/ORM/Entity/Trading/Order/Shipping/Shipping.php
|
Shipping.removeConciliation
|
public function removeConciliation(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Conciliation\Conciliation $conciliation)
{
return $this->conciliations->removeElement($conciliation);
}
|
php
|
public function removeConciliation(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Conciliation\Conciliation $conciliation)
{
return $this->conciliations->removeElement($conciliation);
}
|
[
"public",
"function",
"removeConciliation",
"(",
"\\",
"Gpupo",
"\\",
"CommonSchema",
"\\",
"ORM",
"\\",
"Entity",
"\\",
"Trading",
"\\",
"Order",
"\\",
"Shipping",
"\\",
"Conciliation",
"\\",
"Conciliation",
"$",
"conciliation",
")",
"{",
"return",
"$",
"this",
"->",
"conciliations",
"->",
"removeElement",
"(",
"$",
"conciliation",
")",
";",
"}"
] |
Remove conciliation.
@param \Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Conciliation\Conciliation $conciliation
@return bool TRUE if this collection contained the specified element, FALSE otherwise
|
[
"Remove",
"conciliation",
"."
] |
a762d2eb3063b7317c72c69cbb463b1f95b86b0a
|
https://github.com/gpupo/common-schema/blob/a762d2eb3063b7317c72c69cbb463b1f95b86b0a/src/ORM/Entity/Trading/Order/Shipping/Shipping.php#L939-L942
|
21,004 |
CupOfTea696/WordPress-Composer
|
src/ComposerConfigurator.php
|
ComposerConfigurator.configure
|
public function configure(Composer $composer, IOInterface $io)
{
$this->composer = $composer;
$this->jsonFile = null;
$this->io = $io;
$publicDirectorySet = $this->isPublicDirectorySet();
$wordPressInstallDirectorySet = $this->isWordPressInstallDirectorySet();
$reposConfigured = $this->areReposConfigured();
$sortingConfigured = $this->isSortingConfigured();
if ($publicDirectorySet && $wordPressInstallDirectorySet && $reposConfigured && $sortingConfigured) {
return;
}
if (! $publicDirectorySet) {
$this->setPublicDirectory();
}
if (! $wordPressInstallDirectorySet) {
$this->setWordPressInstallDirectory();
}
if (! $reposConfigured) {
$this->configureRepos();
}
if (! $sortingConfigured) {
$this->configureSorting();
}
$this->sortProperties();
$this->saveJson();
}
|
php
|
public function configure(Composer $composer, IOInterface $io)
{
$this->composer = $composer;
$this->jsonFile = null;
$this->io = $io;
$publicDirectorySet = $this->isPublicDirectorySet();
$wordPressInstallDirectorySet = $this->isWordPressInstallDirectorySet();
$reposConfigured = $this->areReposConfigured();
$sortingConfigured = $this->isSortingConfigured();
if ($publicDirectorySet && $wordPressInstallDirectorySet && $reposConfigured && $sortingConfigured) {
return;
}
if (! $publicDirectorySet) {
$this->setPublicDirectory();
}
if (! $wordPressInstallDirectorySet) {
$this->setWordPressInstallDirectory();
}
if (! $reposConfigured) {
$this->configureRepos();
}
if (! $sortingConfigured) {
$this->configureSorting();
}
$this->sortProperties();
$this->saveJson();
}
|
[
"public",
"function",
"configure",
"(",
"Composer",
"$",
"composer",
",",
"IOInterface",
"$",
"io",
")",
"{",
"$",
"this",
"->",
"composer",
"=",
"$",
"composer",
";",
"$",
"this",
"->",
"jsonFile",
"=",
"null",
";",
"$",
"this",
"->",
"io",
"=",
"$",
"io",
";",
"$",
"publicDirectorySet",
"=",
"$",
"this",
"->",
"isPublicDirectorySet",
"(",
")",
";",
"$",
"wordPressInstallDirectorySet",
"=",
"$",
"this",
"->",
"isWordPressInstallDirectorySet",
"(",
")",
";",
"$",
"reposConfigured",
"=",
"$",
"this",
"->",
"areReposConfigured",
"(",
")",
";",
"$",
"sortingConfigured",
"=",
"$",
"this",
"->",
"isSortingConfigured",
"(",
")",
";",
"if",
"(",
"$",
"publicDirectorySet",
"&&",
"$",
"wordPressInstallDirectorySet",
"&&",
"$",
"reposConfigured",
"&&",
"$",
"sortingConfigured",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"publicDirectorySet",
")",
"{",
"$",
"this",
"->",
"setPublicDirectory",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"wordPressInstallDirectorySet",
")",
"{",
"$",
"this",
"->",
"setWordPressInstallDirectory",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"reposConfigured",
")",
"{",
"$",
"this",
"->",
"configureRepos",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"sortingConfigured",
")",
"{",
"$",
"this",
"->",
"configureSorting",
"(",
")",
";",
"}",
"$",
"this",
"->",
"sortProperties",
"(",
")",
";",
"$",
"this",
"->",
"saveJson",
"(",
")",
";",
"}"
] |
Configure the composer.json file.
@return void
|
[
"Configure",
"the",
"composer",
".",
"json",
"file",
"."
] |
8c0abc10f82b8ce1db5354f6a041c7587ad3fb90
|
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/ComposerConfigurator.php#L113-L146
|
21,005 |
CupOfTea696/WordPress-Composer
|
src/ComposerConfigurator.php
|
ComposerConfigurator.setPublicDirectory
|
protected function setPublicDirectory()
{
if (! $this->json) {
$this->readJson();
}
$this->json['extra']['public-dir'] = $this->plugin->getPublicDirectory();
}
|
php
|
protected function setPublicDirectory()
{
if (! $this->json) {
$this->readJson();
}
$this->json['extra']['public-dir'] = $this->plugin->getPublicDirectory();
}
|
[
"protected",
"function",
"setPublicDirectory",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"json",
")",
"{",
"$",
"this",
"->",
"readJson",
"(",
")",
";",
"}",
"$",
"this",
"->",
"json",
"[",
"'extra'",
"]",
"[",
"'public-dir'",
"]",
"=",
"$",
"this",
"->",
"plugin",
"->",
"getPublicDirectory",
"(",
")",
";",
"}"
] |
Set the public directory in the composer.json.
@return void
|
[
"Set",
"the",
"public",
"directory",
"in",
"the",
"composer",
".",
"json",
"."
] |
8c0abc10f82b8ce1db5354f6a041c7587ad3fb90
|
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/ComposerConfigurator.php#L167-L174
|
21,006 |
CupOfTea696/WordPress-Composer
|
src/ComposerConfigurator.php
|
ComposerConfigurator.setWordPressInstallDirectory
|
protected function setWordPressInstallDirectory()
{
if (! $this->json) {
$this->readJson();
}
$this->json['extra']['wordpress-install-dir'] = $this->plugin->getPublicDirectory() . '/wp';
}
|
php
|
protected function setWordPressInstallDirectory()
{
if (! $this->json) {
$this->readJson();
}
$this->json['extra']['wordpress-install-dir'] = $this->plugin->getPublicDirectory() . '/wp';
}
|
[
"protected",
"function",
"setWordPressInstallDirectory",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"json",
")",
"{",
"$",
"this",
"->",
"readJson",
"(",
")",
";",
"}",
"$",
"this",
"->",
"json",
"[",
"'extra'",
"]",
"[",
"'wordpress-install-dir'",
"]",
"=",
"$",
"this",
"->",
"plugin",
"->",
"getPublicDirectory",
"(",
")",
".",
"'/wp'",
";",
"}"
] |
Set the WordPress installation directory in the composer.json.
@return void
|
[
"Set",
"the",
"WordPress",
"installation",
"directory",
"in",
"the",
"composer",
".",
"json",
"."
] |
8c0abc10f82b8ce1db5354f6a041c7587ad3fb90
|
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/ComposerConfigurator.php#L209-L216
|
21,007 |
CupOfTea696/WordPress-Composer
|
src/ComposerConfigurator.php
|
ComposerConfigurator.areReposConfigured
|
protected function areReposConfigured()
{
if (! $this->json) {
$this->readJson();
}
return ! empty($this->json['repositories']) && $this->pregGrepRecursive('/^http(s|\?)?:\/\/wpackagist\.org\/?$/', $this->json['repositories']);
}
|
php
|
protected function areReposConfigured()
{
if (! $this->json) {
$this->readJson();
}
return ! empty($this->json['repositories']) && $this->pregGrepRecursive('/^http(s|\?)?:\/\/wpackagist\.org\/?$/', $this->json['repositories']);
}
|
[
"protected",
"function",
"areReposConfigured",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"json",
")",
"{",
"$",
"this",
"->",
"readJson",
"(",
")",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"json",
"[",
"'repositories'",
"]",
")",
"&&",
"$",
"this",
"->",
"pregGrepRecursive",
"(",
"'/^http(s|\\?)?:\\/\\/wpackagist\\.org\\/?$/'",
",",
"$",
"this",
"->",
"json",
"[",
"'repositories'",
"]",
")",
";",
"}"
] |
Check if the additional repositories for using WordPress with composer are set.
@return bool
|
[
"Check",
"if",
"the",
"additional",
"repositories",
"for",
"using",
"WordPress",
"with",
"composer",
"are",
"set",
"."
] |
8c0abc10f82b8ce1db5354f6a041c7587ad3fb90
|
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/ComposerConfigurator.php#L223-L230
|
21,008 |
CupOfTea696/WordPress-Composer
|
src/ComposerConfigurator.php
|
ComposerConfigurator.configureRepos
|
protected function configureRepos()
{
if (! $this->json) {
$this->readJson();
}
$public = $this->plugin->getPublicDirectory();
$plugins_path = $public . '/plugins/{$name}/';
$themes_path = $public . '/themes/{$name}/';
$this->json['repositories'][] = [
'type' => 'composer',
'url' => 'https://wpackagist.org',
];
$extra = $this->json['extra'];
if (isset($extra['installer-paths'])) {
foreach ($extra['installer-paths'] as $path => &$names) {
if ($path != $plugins_path && ($key = array_search('type:wordpress-plugin', $names)) !== false ||
$path != $themes_path && ($key = array_search('type:wordpress-theme', $names)) !== false
) {
unset($names[$key]);
if (! count($names)) {
unset($extra['installer-paths'][$path]);
}
}
}
}
$extra['installer-paths'][$plugins_path][] = 'type:wordpress-plugin';
$extra['installer-paths'][$themes_path][] = 'type:wordpress-theme';
$this->json['extra'] = $extra;
}
|
php
|
protected function configureRepos()
{
if (! $this->json) {
$this->readJson();
}
$public = $this->plugin->getPublicDirectory();
$plugins_path = $public . '/plugins/{$name}/';
$themes_path = $public . '/themes/{$name}/';
$this->json['repositories'][] = [
'type' => 'composer',
'url' => 'https://wpackagist.org',
];
$extra = $this->json['extra'];
if (isset($extra['installer-paths'])) {
foreach ($extra['installer-paths'] as $path => &$names) {
if ($path != $plugins_path && ($key = array_search('type:wordpress-plugin', $names)) !== false ||
$path != $themes_path && ($key = array_search('type:wordpress-theme', $names)) !== false
) {
unset($names[$key]);
if (! count($names)) {
unset($extra['installer-paths'][$path]);
}
}
}
}
$extra['installer-paths'][$plugins_path][] = 'type:wordpress-plugin';
$extra['installer-paths'][$themes_path][] = 'type:wordpress-theme';
$this->json['extra'] = $extra;
}
|
[
"protected",
"function",
"configureRepos",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"json",
")",
"{",
"$",
"this",
"->",
"readJson",
"(",
")",
";",
"}",
"$",
"public",
"=",
"$",
"this",
"->",
"plugin",
"->",
"getPublicDirectory",
"(",
")",
";",
"$",
"plugins_path",
"=",
"$",
"public",
".",
"'/plugins/{$name}/'",
";",
"$",
"themes_path",
"=",
"$",
"public",
".",
"'/themes/{$name}/'",
";",
"$",
"this",
"->",
"json",
"[",
"'repositories'",
"]",
"[",
"]",
"=",
"[",
"'type'",
"=>",
"'composer'",
",",
"'url'",
"=>",
"'https://wpackagist.org'",
",",
"]",
";",
"$",
"extra",
"=",
"$",
"this",
"->",
"json",
"[",
"'extra'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"extra",
"[",
"'installer-paths'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"extra",
"[",
"'installer-paths'",
"]",
"as",
"$",
"path",
"=>",
"&",
"$",
"names",
")",
"{",
"if",
"(",
"$",
"path",
"!=",
"$",
"plugins_path",
"&&",
"(",
"$",
"key",
"=",
"array_search",
"(",
"'type:wordpress-plugin'",
",",
"$",
"names",
")",
")",
"!==",
"false",
"||",
"$",
"path",
"!=",
"$",
"themes_path",
"&&",
"(",
"$",
"key",
"=",
"array_search",
"(",
"'type:wordpress-theme'",
",",
"$",
"names",
")",
")",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"names",
"[",
"$",
"key",
"]",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"names",
")",
")",
"{",
"unset",
"(",
"$",
"extra",
"[",
"'installer-paths'",
"]",
"[",
"$",
"path",
"]",
")",
";",
"}",
"}",
"}",
"}",
"$",
"extra",
"[",
"'installer-paths'",
"]",
"[",
"$",
"plugins_path",
"]",
"[",
"]",
"=",
"'type:wordpress-plugin'",
";",
"$",
"extra",
"[",
"'installer-paths'",
"]",
"[",
"$",
"themes_path",
"]",
"[",
"]",
"=",
"'type:wordpress-theme'",
";",
"$",
"this",
"->",
"json",
"[",
"'extra'",
"]",
"=",
"$",
"extra",
";",
"}"
] |
Configure additional repositories for using WordPress with composer,
and set the installation directories for WordPress packages.
@return void
|
[
"Configure",
"additional",
"repositories",
"for",
"using",
"WordPress",
"with",
"composer",
"and",
"set",
"the",
"installation",
"directories",
"for",
"WordPress",
"packages",
"."
] |
8c0abc10f82b8ce1db5354f6a041c7587ad3fb90
|
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/ComposerConfigurator.php#L238-L273
|
21,009 |
CupOfTea696/WordPress-Composer
|
src/ComposerConfigurator.php
|
ComposerConfigurator.isSortingConfigured
|
protected function isSortingConfigured()
{
if (! $this->json) {
$this->readJson();
}
return ! empty($this->json['config']) && ! empty($this->json['config']['sort-packages']);
}
|
php
|
protected function isSortingConfigured()
{
if (! $this->json) {
$this->readJson();
}
return ! empty($this->json['config']) && ! empty($this->json['config']['sort-packages']);
}
|
[
"protected",
"function",
"isSortingConfigured",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"json",
")",
"{",
"$",
"this",
"->",
"readJson",
"(",
")",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"json",
"[",
"'config'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"json",
"[",
"'config'",
"]",
"[",
"'sort-packages'",
"]",
")",
";",
"}"
] |
Check if autmatic sorting of linked packages is enabled.
@return bool
|
[
"Check",
"if",
"autmatic",
"sorting",
"of",
"linked",
"packages",
"is",
"enabled",
"."
] |
8c0abc10f82b8ce1db5354f6a041c7587ad3fb90
|
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/ComposerConfigurator.php#L280-L287
|
21,010 |
CupOfTea696/WordPress-Composer
|
src/ComposerConfigurator.php
|
ComposerConfigurator.sortProperties
|
protected function sortProperties()
{
if (! $this->json) {
$this->readJson();
}
$this->json = $this->sortByArray($this->json, $this->composerOrder);
if (isset($this->json['autoload'])) {
$this->json['autoload'] = $this->sortByArray($this->json['autoload'], $this->autoloadOrder);
}
if (isset($this->json['autoload-dev'])) {
$this->json['autoload-dev'] = $this->sortByArray($this->json['autoload-dev'], $this->autoloadOrder);
}
foreach (['support', 'require', 'require-dev', 'conflict', 'replace', 'provide', 'suggest'] as $property) {
if (isset($this->json[$property])) {
ksort($this->json[$property]);
}
}
}
|
php
|
protected function sortProperties()
{
if (! $this->json) {
$this->readJson();
}
$this->json = $this->sortByArray($this->json, $this->composerOrder);
if (isset($this->json['autoload'])) {
$this->json['autoload'] = $this->sortByArray($this->json['autoload'], $this->autoloadOrder);
}
if (isset($this->json['autoload-dev'])) {
$this->json['autoload-dev'] = $this->sortByArray($this->json['autoload-dev'], $this->autoloadOrder);
}
foreach (['support', 'require', 'require-dev', 'conflict', 'replace', 'provide', 'suggest'] as $property) {
if (isset($this->json[$property])) {
ksort($this->json[$property]);
}
}
}
|
[
"protected",
"function",
"sortProperties",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"json",
")",
"{",
"$",
"this",
"->",
"readJson",
"(",
")",
";",
"}",
"$",
"this",
"->",
"json",
"=",
"$",
"this",
"->",
"sortByArray",
"(",
"$",
"this",
"->",
"json",
",",
"$",
"this",
"->",
"composerOrder",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"json",
"[",
"'autoload'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"json",
"[",
"'autoload'",
"]",
"=",
"$",
"this",
"->",
"sortByArray",
"(",
"$",
"this",
"->",
"json",
"[",
"'autoload'",
"]",
",",
"$",
"this",
"->",
"autoloadOrder",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"json",
"[",
"'autoload-dev'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"json",
"[",
"'autoload-dev'",
"]",
"=",
"$",
"this",
"->",
"sortByArray",
"(",
"$",
"this",
"->",
"json",
"[",
"'autoload-dev'",
"]",
",",
"$",
"this",
"->",
"autoloadOrder",
")",
";",
"}",
"foreach",
"(",
"[",
"'support'",
",",
"'require'",
",",
"'require-dev'",
",",
"'conflict'",
",",
"'replace'",
",",
"'provide'",
",",
"'suggest'",
"]",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"json",
"[",
"$",
"property",
"]",
")",
")",
"{",
"ksort",
"(",
"$",
"this",
"->",
"json",
"[",
"$",
"property",
"]",
")",
";",
"}",
"}",
"}"
] |
Sort the composer.json properties.
@return void
|
[
"Sort",
"the",
"composer",
".",
"json",
"properties",
"."
] |
8c0abc10f82b8ce1db5354f6a041c7587ad3fb90
|
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/ComposerConfigurator.php#L308-L329
|
21,011 |
CupOfTea696/WordPress-Composer
|
src/ComposerConfigurator.php
|
ComposerConfigurator.getJsonFile
|
protected function getJsonFile()
{
if (! $this->jsonFile) {
$this->jsonFile = new JsonFile('composer.json', null, $this->io);
}
return $this->jsonFile;
}
|
php
|
protected function getJsonFile()
{
if (! $this->jsonFile) {
$this->jsonFile = new JsonFile('composer.json', null, $this->io);
}
return $this->jsonFile;
}
|
[
"protected",
"function",
"getJsonFile",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"jsonFile",
")",
"{",
"$",
"this",
"->",
"jsonFile",
"=",
"new",
"JsonFile",
"(",
"'composer.json'",
",",
"null",
",",
"$",
"this",
"->",
"io",
")",
";",
"}",
"return",
"$",
"this",
"->",
"jsonFile",
";",
"}"
] |
Get the JsonFile.
@return \Composer\Json\JsonFile
|
[
"Get",
"the",
"JsonFile",
"."
] |
8c0abc10f82b8ce1db5354f6a041c7587ad3fb90
|
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/ComposerConfigurator.php#L336-L343
|
21,012 |
CupOfTea696/WordPress-Composer
|
src/ComposerConfigurator.php
|
ComposerConfigurator.pregGrepRecursive
|
protected function pregGrepRecursive($pattern, $haystack)
{
$matches = [];
foreach ($haystack as $key => $item) {
if (is_array($item)) {
$sub_matches = $this->pregGrepRecursive($pattern, $item);
if ($sub_matches) {
$matches[$key] = $sub_matches;
}
} elseif (preg_match($pattern, $item)) {
$matches[$key] = $item;
}
}
return $matches;
}
|
php
|
protected function pregGrepRecursive($pattern, $haystack)
{
$matches = [];
foreach ($haystack as $key => $item) {
if (is_array($item)) {
$sub_matches = $this->pregGrepRecursive($pattern, $item);
if ($sub_matches) {
$matches[$key] = $sub_matches;
}
} elseif (preg_match($pattern, $item)) {
$matches[$key] = $item;
}
}
return $matches;
}
|
[
"protected",
"function",
"pregGrepRecursive",
"(",
"$",
"pattern",
",",
"$",
"haystack",
")",
"{",
"$",
"matches",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"haystack",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"item",
")",
")",
"{",
"$",
"sub_matches",
"=",
"$",
"this",
"->",
"pregGrepRecursive",
"(",
"$",
"pattern",
",",
"$",
"item",
")",
";",
"if",
"(",
"$",
"sub_matches",
")",
"{",
"$",
"matches",
"[",
"$",
"key",
"]",
"=",
"$",
"sub_matches",
";",
"}",
"}",
"elseif",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"item",
")",
")",
"{",
"$",
"matches",
"[",
"$",
"key",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"return",
"$",
"matches",
";",
"}"
] |
Recursive version of preg_grep.
@param string $pattern
@param array $haystack
@return array
|
[
"Recursive",
"version",
"of",
"preg_grep",
"."
] |
8c0abc10f82b8ce1db5354f6a041c7587ad3fb90
|
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/ComposerConfigurator.php#L372-L389
|
21,013 |
CupOfTea696/WordPress-Composer
|
src/ComposerConfigurator.php
|
ComposerConfigurator.sortByArray
|
protected function sortByArray($array, $order)
{
$keys = array_keys($array);
return array_merge(
array_flip(
array_intersect($order, $keys) +
array_diff($keys, $order)
),
$array
);
}
|
php
|
protected function sortByArray($array, $order)
{
$keys = array_keys($array);
return array_merge(
array_flip(
array_intersect($order, $keys) +
array_diff($keys, $order)
),
$array
);
}
|
[
"protected",
"function",
"sortByArray",
"(",
"$",
"array",
",",
"$",
"order",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"array",
")",
";",
"return",
"array_merge",
"(",
"array_flip",
"(",
"array_intersect",
"(",
"$",
"order",
",",
"$",
"keys",
")",
"+",
"array_diff",
"(",
"$",
"keys",
",",
"$",
"order",
")",
")",
",",
"$",
"array",
")",
";",
"}"
] |
Sort an array by its keys, using a given array as the sort order.
@param array $array
@param array $order
@return array
|
[
"Sort",
"an",
"array",
"by",
"its",
"keys",
"using",
"a",
"given",
"array",
"as",
"the",
"sort",
"order",
"."
] |
8c0abc10f82b8ce1db5354f6a041c7587ad3fb90
|
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/ComposerConfigurator.php#L398-L409
|
21,014 |
odiaseo/pagebuilder
|
src/PageBuilder/Model/SiteThemeModel.php
|
SiteThemeModel.getActiveSiteTheme
|
public function getActiveSiteTheme($siteId)
{
$qb = $this->getEntityManager()->createQueryBuilder();
/** @var $query \Doctrine\ORM\Query */
$query = $qb->select('e, t')
->from($this->_entity, 'e')
->innerJoin('e.themeId', 't')
->where('e.siteId = :id')
->andWhere('e.isActive = 1')
->setMaxResults(1)
->setParameter('id', $siteId)
->getQuery();
/** @var $result \PageBuilder\Entity\Join\SiteTheme */
$result = $query->getOneOrNullResult(AbstractQuery::HYDRATE_OBJECT);
if ($result) {
return $result->getThemeId();
} else {
return $result;
}
}
|
php
|
public function getActiveSiteTheme($siteId)
{
$qb = $this->getEntityManager()->createQueryBuilder();
/** @var $query \Doctrine\ORM\Query */
$query = $qb->select('e, t')
->from($this->_entity, 'e')
->innerJoin('e.themeId', 't')
->where('e.siteId = :id')
->andWhere('e.isActive = 1')
->setMaxResults(1)
->setParameter('id', $siteId)
->getQuery();
/** @var $result \PageBuilder\Entity\Join\SiteTheme */
$result = $query->getOneOrNullResult(AbstractQuery::HYDRATE_OBJECT);
if ($result) {
return $result->getThemeId();
} else {
return $result;
}
}
|
[
"public",
"function",
"getActiveSiteTheme",
"(",
"$",
"siteId",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"createQueryBuilder",
"(",
")",
";",
"/** @var $query \\Doctrine\\ORM\\Query */",
"$",
"query",
"=",
"$",
"qb",
"->",
"select",
"(",
"'e, t'",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"_entity",
",",
"'e'",
")",
"->",
"innerJoin",
"(",
"'e.themeId'",
",",
"'t'",
")",
"->",
"where",
"(",
"'e.siteId = :id'",
")",
"->",
"andWhere",
"(",
"'e.isActive = 1'",
")",
"->",
"setMaxResults",
"(",
"1",
")",
"->",
"setParameter",
"(",
"'id'",
",",
"$",
"siteId",
")",
"->",
"getQuery",
"(",
")",
";",
"/** @var $result \\PageBuilder\\Entity\\Join\\SiteTheme */",
"$",
"result",
"=",
"$",
"query",
"->",
"getOneOrNullResult",
"(",
"AbstractQuery",
"::",
"HYDRATE_OBJECT",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"return",
"$",
"result",
"->",
"getThemeId",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"result",
";",
"}",
"}"
] |
Get Active Site Theme
@param $siteId
@return \PageBuilder\Entity\Join\SiteTheme
|
[
"Get",
"Active",
"Site",
"Theme"
] |
88ef7cccf305368561307efe4ca07fac8e5774f3
|
https://github.com/odiaseo/pagebuilder/blob/88ef7cccf305368561307efe4ca07fac8e5774f3/src/PageBuilder/Model/SiteThemeModel.php#L16-L37
|
21,015 |
heidelpay/PhpDoc
|
src/phpDocumentor/Configuration/ServiceProvider.php
|
ServiceProvider.register
|
public function register(Application $app)
{
$this->addMerger($app);
$app->extend(
'console',
function (ConsoleApplication $console) {
$console->getDefinition()->addOption(
new InputOption(
'config',
'c',
InputOption::VALUE_OPTIONAL,
'Location of a custom configuration file'
)
);
return $console;
}
);
$app['config.path.template'] = __DIR__ . '/Resources/phpdoc.tpl.xml';
$app['config.path.user'] = getcwd()
. ((file_exists(getcwd() . '/phpdoc.xml')) ? '/phpdoc.xml' : '/phpdoc.dist.xml');
$app['config.class'] = 'phpDocumentor\Configuration';
$app['config'] = $app->share(
function ($app) {
$loader = new Loader($app['serializer'], $app['config.merger']);
return $loader->load($app['config.path.template'], $app['config.path.user'], $app['config.class']);
}
);
}
|
php
|
public function register(Application $app)
{
$this->addMerger($app);
$app->extend(
'console',
function (ConsoleApplication $console) {
$console->getDefinition()->addOption(
new InputOption(
'config',
'c',
InputOption::VALUE_OPTIONAL,
'Location of a custom configuration file'
)
);
return $console;
}
);
$app['config.path.template'] = __DIR__ . '/Resources/phpdoc.tpl.xml';
$app['config.path.user'] = getcwd()
. ((file_exists(getcwd() . '/phpdoc.xml')) ? '/phpdoc.xml' : '/phpdoc.dist.xml');
$app['config.class'] = 'phpDocumentor\Configuration';
$app['config'] = $app->share(
function ($app) {
$loader = new Loader($app['serializer'], $app['config.merger']);
return $loader->load($app['config.path.template'], $app['config.path.user'], $app['config.class']);
}
);
}
|
[
"public",
"function",
"register",
"(",
"Application",
"$",
"app",
")",
"{",
"$",
"this",
"->",
"addMerger",
"(",
"$",
"app",
")",
";",
"$",
"app",
"->",
"extend",
"(",
"'console'",
",",
"function",
"(",
"ConsoleApplication",
"$",
"console",
")",
"{",
"$",
"console",
"->",
"getDefinition",
"(",
")",
"->",
"addOption",
"(",
"new",
"InputOption",
"(",
"'config'",
",",
"'c'",
",",
"InputOption",
"::",
"VALUE_OPTIONAL",
",",
"'Location of a custom configuration file'",
")",
")",
";",
"return",
"$",
"console",
";",
"}",
")",
";",
"$",
"app",
"[",
"'config.path.template'",
"]",
"=",
"__DIR__",
".",
"'/Resources/phpdoc.tpl.xml'",
";",
"$",
"app",
"[",
"'config.path.user'",
"]",
"=",
"getcwd",
"(",
")",
".",
"(",
"(",
"file_exists",
"(",
"getcwd",
"(",
")",
".",
"'/phpdoc.xml'",
")",
")",
"?",
"'/phpdoc.xml'",
":",
"'/phpdoc.dist.xml'",
")",
";",
"$",
"app",
"[",
"'config.class'",
"]",
"=",
"'phpDocumentor\\Configuration'",
";",
"$",
"app",
"[",
"'config'",
"]",
"=",
"$",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"loader",
"=",
"new",
"Loader",
"(",
"$",
"app",
"[",
"'serializer'",
"]",
",",
"$",
"app",
"[",
"'config.merger'",
"]",
")",
";",
"return",
"$",
"loader",
"->",
"load",
"(",
"$",
"app",
"[",
"'config.path.template'",
"]",
",",
"$",
"app",
"[",
"'config.path.user'",
"]",
",",
"$",
"app",
"[",
"'config.class'",
"]",
")",
";",
"}",
")",
";",
"}"
] |
Adds the Configuration object to the DIC.
phpDocumentor first loads the template config file (/data/phpdoc.tpl.xml)
and then the phpdoc.dist.xml, or the phpdoc.xml if it exists but not both,
from the current working directory.
The user config file (either phpdoc.dist.xml or phpdoc.xml) is merged
with the template file.
@param Application $app An Application instance
|
[
"Adds",
"the",
"Configuration",
"object",
"to",
"the",
"DIC",
"."
] |
5ac9e842cbd4cbb70900533b240c131f3515ee02
|
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Configuration/ServiceProvider.php#L53-L85
|
21,016 |
heidelpay/PhpDoc
|
src/phpDocumentor/Configuration/ServiceProvider.php
|
ServiceProvider.addMerger
|
private function addMerger(Application $container)
{
$this->addMergerAnnotations($container);
$container['config.merger'] = $container->share(
function () {
return new Merger(new AnnotationReader());
}
);
}
|
php
|
private function addMerger(Application $container)
{
$this->addMergerAnnotations($container);
$container['config.merger'] = $container->share(
function () {
return new Merger(new AnnotationReader());
}
);
}
|
[
"private",
"function",
"addMerger",
"(",
"Application",
"$",
"container",
")",
"{",
"$",
"this",
"->",
"addMergerAnnotations",
"(",
"$",
"container",
")",
";",
"$",
"container",
"[",
"'config.merger'",
"]",
"=",
"$",
"container",
"->",
"share",
"(",
"function",
"(",
")",
"{",
"return",
"new",
"Merger",
"(",
"new",
"AnnotationReader",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] |
Initializes and adds the configuration merger object as the 'config.merger' service to the container.
@param Application $container
@return void
|
[
"Initializes",
"and",
"adds",
"the",
"configuration",
"merger",
"object",
"as",
"the",
"config",
".",
"merger",
"service",
"to",
"the",
"container",
"."
] |
5ac9e842cbd4cbb70900533b240c131f3515ee02
|
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Configuration/ServiceProvider.php#L94-L103
|
21,017 |
heidelpay/PhpDoc
|
src/phpDocumentor/Configuration/ServiceProvider.php
|
ServiceProvider.addMergerAnnotations
|
private function addMergerAnnotations(Application $container)
{
if (!isset($container['serializer.annotations'])) {
throw new \RuntimeException(
'The configuration service provider depends on the JmsSerializer Service Provider but the '
. '"serializer.annotations" key could not be found in the container.'
);
}
$annotations = $container['serializer.annotations'];
$annotations[] = array(
'namespace' => 'phpDocumentor\Configuration\Merger\Annotation',
'path' => __DIR__ . '/../../'
);
$container['serializer.annotations'] = $annotations;
}
|
php
|
private function addMergerAnnotations(Application $container)
{
if (!isset($container['serializer.annotations'])) {
throw new \RuntimeException(
'The configuration service provider depends on the JmsSerializer Service Provider but the '
. '"serializer.annotations" key could not be found in the container.'
);
}
$annotations = $container['serializer.annotations'];
$annotations[] = array(
'namespace' => 'phpDocumentor\Configuration\Merger\Annotation',
'path' => __DIR__ . '/../../'
);
$container['serializer.annotations'] = $annotations;
}
|
[
"private",
"function",
"addMergerAnnotations",
"(",
"Application",
"$",
"container",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"container",
"[",
"'serializer.annotations'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'The configuration service provider depends on the JmsSerializer Service Provider but the '",
".",
"'\"serializer.annotations\" key could not be found in the container.'",
")",
";",
"}",
"$",
"annotations",
"=",
"$",
"container",
"[",
"'serializer.annotations'",
"]",
";",
"$",
"annotations",
"[",
"]",
"=",
"array",
"(",
"'namespace'",
"=>",
"'phpDocumentor\\Configuration\\Merger\\Annotation'",
",",
"'path'",
"=>",
"__DIR__",
".",
"'/../../'",
")",
";",
"$",
"container",
"[",
"'serializer.annotations'",
"]",
"=",
"$",
"annotations",
";",
"}"
] |
Adds the annotations for the Merger component to the Serializer.
@param Application $container
@throws \RuntimeException if the annotation handler for Jms Serializer is not added to the container as
'serializer.annotations' service.
@return void
|
[
"Adds",
"the",
"annotations",
"for",
"the",
"Merger",
"component",
"to",
"the",
"Serializer",
"."
] |
5ac9e842cbd4cbb70900533b240c131f3515ee02
|
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Configuration/ServiceProvider.php#L115-L130
|
21,018 |
NuclearCMS/Hierarchy
|
src/Builders/Writer.php
|
Writer.write
|
public function write($path, $contents)
{
if ( ! FileKeeper::exists($dir = $this->getBasePath()))
{
FileKeeper::directory($dir);
}
FileKeeper::write($path, $contents);
}
|
php
|
public function write($path, $contents)
{
if ( ! FileKeeper::exists($dir = $this->getBasePath()))
{
FileKeeper::directory($dir);
}
FileKeeper::write($path, $contents);
}
|
[
"public",
"function",
"write",
"(",
"$",
"path",
",",
"$",
"contents",
")",
"{",
"if",
"(",
"!",
"FileKeeper",
"::",
"exists",
"(",
"$",
"dir",
"=",
"$",
"this",
"->",
"getBasePath",
"(",
")",
")",
")",
"{",
"FileKeeper",
"::",
"directory",
"(",
"$",
"dir",
")",
";",
"}",
"FileKeeper",
"::",
"write",
"(",
"$",
"path",
",",
"$",
"contents",
")",
";",
"}"
] |
Writes a file, also creates base directory
@param $path
@param $contents
|
[
"Writes",
"a",
"file",
"also",
"creates",
"base",
"directory"
] |
535171c5e2db72265313fd2110aec8456e46f459
|
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/Writer.php#L16-L24
|
21,019 |
bradcornford/Alerter
|
src/Cornford/Alerter/Alert.php
|
Alert.create
|
public static function create($type, $content)
{
if (empty($type)) {
throw new AlertTypeException('Unable to create message with invalid type.');
}
if (empty($content)) {
throw new AlertContentException('Unable to create message with invalid content.');
}
return new self($type, $content);
}
|
php
|
public static function create($type, $content)
{
if (empty($type)) {
throw new AlertTypeException('Unable to create message with invalid type.');
}
if (empty($content)) {
throw new AlertContentException('Unable to create message with invalid content.');
}
return new self($type, $content);
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"type",
",",
"$",
"content",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"AlertTypeException",
"(",
"'Unable to create message with invalid type.'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"content",
")",
")",
"{",
"throw",
"new",
"AlertContentException",
"(",
"'Unable to create message with invalid content.'",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"type",
",",
"$",
"content",
")",
";",
"}"
] |
Create a new alerter instance.
@param string $type
@param string $content
@return self
@throws \Cornford\Alerter\Exceptions\AlertContentException
@throws \Cornford\Alerter\Exceptions\AlertTypeException
|
[
"Create",
"a",
"new",
"alerter",
"instance",
"."
] |
6533fe7afb9d1bae553385d3e687a24bda6a1333
|
https://github.com/bradcornford/Alerter/blob/6533fe7afb9d1bae553385d3e687a24bda6a1333/src/Cornford/Alerter/Alert.php#L75-L86
|
21,020 |
bradcornford/Alerter
|
src/Cornford/Alerter/Alert.php
|
Alert.display
|
public function display($viewPath = null, $view = null)
{
if (!$viewPath) {
$viewPath = $this->viewPath;
}
if (!$view) {
$view = $this->view;
}
return (new AlertDisplay($this, $viewPath, $view))->display();
}
|
php
|
public function display($viewPath = null, $view = null)
{
if (!$viewPath) {
$viewPath = $this->viewPath;
}
if (!$view) {
$view = $this->view;
}
return (new AlertDisplay($this, $viewPath, $view))->display();
}
|
[
"public",
"function",
"display",
"(",
"$",
"viewPath",
"=",
"null",
",",
"$",
"view",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"viewPath",
")",
"{",
"$",
"viewPath",
"=",
"$",
"this",
"->",
"viewPath",
";",
"}",
"if",
"(",
"!",
"$",
"view",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
";",
"}",
"return",
"(",
"new",
"AlertDisplay",
"(",
"$",
"this",
",",
"$",
"viewPath",
",",
"$",
"view",
")",
")",
"->",
"display",
"(",
")",
";",
"}"
] |
Return a string of alert display HTML for a set display view.
@param string $view
@param string $viewPath
@return string
|
[
"Return",
"a",
"string",
"of",
"alert",
"display",
"HTML",
"for",
"a",
"set",
"display",
"view",
"."
] |
6533fe7afb9d1bae553385d3e687a24bda6a1333
|
https://github.com/bradcornford/Alerter/blob/6533fe7afb9d1bae553385d3e687a24bda6a1333/src/Cornford/Alerter/Alert.php#L162-L173
|
21,021 |
oroinc/OroLayoutComponent
|
RawLayoutBuilder.php
|
RawLayoutBuilder.validateBlockType
|
protected function validateBlockType($blockType)
{
if (!$blockType) {
throw new Exception\InvalidArgumentException('The block type name must not be empty.');
}
if (!$blockType instanceof BlockTypeInterface) {
if (!is_string($blockType)) {
throw new Exception\UnexpectedTypeException($blockType, 'string or BlockTypeInterface', 'blockType');
}
if (!preg_match('/^[a-z][a-z0-9_]*$/iD', $blockType)) {
throw new Exception\InvalidArgumentException(
sprintf(
'The "%s" string cannot be used as the name of the block type '
. 'because it contains illegal characters. '
. 'The valid block type name should start with a letter and only contain '
. 'letters, numbers and underscores ("_").',
$blockType
)
);
}
}
}
|
php
|
protected function validateBlockType($blockType)
{
if (!$blockType) {
throw new Exception\InvalidArgumentException('The block type name must not be empty.');
}
if (!$blockType instanceof BlockTypeInterface) {
if (!is_string($blockType)) {
throw new Exception\UnexpectedTypeException($blockType, 'string or BlockTypeInterface', 'blockType');
}
if (!preg_match('/^[a-z][a-z0-9_]*$/iD', $blockType)) {
throw new Exception\InvalidArgumentException(
sprintf(
'The "%s" string cannot be used as the name of the block type '
. 'because it contains illegal characters. '
. 'The valid block type name should start with a letter and only contain '
. 'letters, numbers and underscores ("_").',
$blockType
)
);
}
}
}
|
[
"protected",
"function",
"validateBlockType",
"(",
"$",
"blockType",
")",
"{",
"if",
"(",
"!",
"$",
"blockType",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"'The block type name must not be empty.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"blockType",
"instanceof",
"BlockTypeInterface",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"blockType",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"UnexpectedTypeException",
"(",
"$",
"blockType",
",",
"'string or BlockTypeInterface'",
",",
"'blockType'",
")",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"'/^[a-z][a-z0-9_]*$/iD'",
",",
"$",
"blockType",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The \"%s\" string cannot be used as the name of the block type '",
".",
"'because it contains illegal characters. '",
".",
"'The valid block type name should start with a letter and only contain '",
".",
"'letters, numbers and underscores (\"_\").'",
",",
"$",
"blockType",
")",
")",
";",
"}",
"}",
"}"
] |
Checks if the given value can be used as the block type name
@param string|BlockTypeInterface $blockType The block type
@throws Exception\InvalidArgumentException if the block type name is not valid
|
[
"Checks",
"if",
"the",
"given",
"value",
"can",
"be",
"used",
"as",
"the",
"block",
"type",
"name"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/RawLayoutBuilder.php#L501-L522
|
21,022 |
inhere/php-librarys
|
src/Utils/UUID.php
|
UUID.makeBin
|
protected static function makeBin($str, $len)
{
if ($str instanceof self) {
return $str->bytes;
}
if (\strlen($str) === $len) {
return $str;
}
$str = (string)preg_replace([
// strip URN scheme and namespace
'/^urn:uuid:/is',
// strip non-hex characters
'/[^a-f0-9]/is',
], '', $str);
if (\strlen($str) !== ($len * 2)) {
return null;
}
return pack('H*', $str);
}
|
php
|
protected static function makeBin($str, $len)
{
if ($str instanceof self) {
return $str->bytes;
}
if (\strlen($str) === $len) {
return $str;
}
$str = (string)preg_replace([
// strip URN scheme and namespace
'/^urn:uuid:/is',
// strip non-hex characters
'/[^a-f0-9]/is',
], '', $str);
if (\strlen($str) !== ($len * 2)) {
return null;
}
return pack('H*', $str);
}
|
[
"protected",
"static",
"function",
"makeBin",
"(",
"$",
"str",
",",
"$",
"len",
")",
"{",
"if",
"(",
"$",
"str",
"instanceof",
"self",
")",
"{",
"return",
"$",
"str",
"->",
"bytes",
";",
"}",
"if",
"(",
"\\",
"strlen",
"(",
"$",
"str",
")",
"===",
"$",
"len",
")",
"{",
"return",
"$",
"str",
";",
"}",
"$",
"str",
"=",
"(",
"string",
")",
"preg_replace",
"(",
"[",
"// strip URN scheme and namespace",
"'/^urn:uuid:/is'",
",",
"// strip non-hex characters",
"'/[^a-f0-9]/is'",
",",
"]",
",",
"''",
",",
"$",
"str",
")",
";",
"if",
"(",
"\\",
"strlen",
"(",
"$",
"str",
")",
"!==",
"(",
"$",
"len",
"*",
"2",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"pack",
"(",
"'H*'",
",",
"$",
"str",
")",
";",
"}"
] |
Insure that an input string is either binary or hexadecimal.
Returns binary representation, or false on failure.
@param string $str
@param integer $len
@return string|null
|
[
"Insure",
"that",
"an",
"input",
"string",
"is",
"either",
"binary",
"or",
"hexadecimal",
".",
"Returns",
"binary",
"representation",
"or",
"false",
"on",
"failure",
"."
] |
e6ca598685469794f310e3ab0e2bc19519cd0ae6
|
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Utils/UUID.php#L248-L269
|
21,023 |
nathan-fiscaletti/extended-arrays
|
src/ExtendedArrays/Traits/BaseArray.php
|
BaseArray.offsetGet
|
public function offsetGet($offset)
{
return isset($this->_args[$offset])
? (
(is_array($this->_args[$offset]))
? new AssociativeArray($this->_args[$offset])
: $this->_args[$offset]
) : null;
}
|
php
|
public function offsetGet($offset)
{
return isset($this->_args[$offset])
? (
(is_array($this->_args[$offset]))
? new AssociativeArray($this->_args[$offset])
: $this->_args[$offset]
) : null;
}
|
[
"public",
"function",
"offsetGet",
"(",
"$",
"offset",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"_args",
"[",
"$",
"offset",
"]",
")",
"?",
"(",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_args",
"[",
"$",
"offset",
"]",
")",
")",
"?",
"new",
"AssociativeArray",
"(",
"$",
"this",
"->",
"_args",
"[",
"$",
"offset",
"]",
")",
":",
"$",
"this",
"->",
"_args",
"[",
"$",
"offset",
"]",
")",
":",
"null",
";",
"}"
] |
Retrieve a value based on an offset in the array.
@param mixed $offset
@return mixed
|
[
"Retrieve",
"a",
"value",
"based",
"on",
"an",
"offset",
"in",
"the",
"array",
"."
] |
a641856115131f76417521d3e4aa2d951158050a
|
https://github.com/nathan-fiscaletti/extended-arrays/blob/a641856115131f76417521d3e4aa2d951158050a/src/ExtendedArrays/Traits/BaseArray.php#L48-L56
|
21,024 |
Erdiko/core
|
src/Cache.php
|
Cache.getCacheObject
|
public static function getCacheObject($cacheConfig = 'default')
{
//Check if the caller requests an new object
if (empty(static::$instance[$cacheConfig])) {
$config = Helper::getConfig('application', $cacheConfig);
//Check if the object already be created
if (isset($config["cache"][$cacheConfig])) {
static::$instance[$cacheConfig] = new $config["cache"][$cacheConfig]['class'];
} else {
throw new \Exception("There is no cache config defined ({$cacheConfig})");
}
}
return static::$instance[$cacheConfig];
}
|
php
|
public static function getCacheObject($cacheConfig = 'default')
{
//Check if the caller requests an new object
if (empty(static::$instance[$cacheConfig])) {
$config = Helper::getConfig('application', $cacheConfig);
//Check if the object already be created
if (isset($config["cache"][$cacheConfig])) {
static::$instance[$cacheConfig] = new $config["cache"][$cacheConfig]['class'];
} else {
throw new \Exception("There is no cache config defined ({$cacheConfig})");
}
}
return static::$instance[$cacheConfig];
}
|
[
"public",
"static",
"function",
"getCacheObject",
"(",
"$",
"cacheConfig",
"=",
"'default'",
")",
"{",
"//Check if the caller requests an new object",
"if",
"(",
"empty",
"(",
"static",
"::",
"$",
"instance",
"[",
"$",
"cacheConfig",
"]",
")",
")",
"{",
"$",
"config",
"=",
"Helper",
"::",
"getConfig",
"(",
"'application'",
",",
"$",
"cacheConfig",
")",
";",
"//Check if the object already be created",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"\"cache\"",
"]",
"[",
"$",
"cacheConfig",
"]",
")",
")",
"{",
"static",
"::",
"$",
"instance",
"[",
"$",
"cacheConfig",
"]",
"=",
"new",
"$",
"config",
"[",
"\"cache\"",
"]",
"[",
"$",
"cacheConfig",
"]",
"[",
"'class'",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"There is no cache config defined ({$cacheConfig})\"",
")",
";",
"}",
"}",
"return",
"static",
"::",
"$",
"instance",
"[",
"$",
"cacheConfig",
"]",
";",
"}"
] |
Get the cache instance
@param string $cacheConfig
@return object
|
[
"Get",
"the",
"cache",
"instance"
] |
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
|
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Cache.php#L24-L40
|
21,025 |
madkom/regex
|
src/Replacer.php
|
Replacer.replace
|
public function replace(string $subject, string $replacement, int $limit = -1, int &$count = null) : string
{
$result = preg_replace($this->pattern->getPattern() . $this->modifier, $replacement, $subject, $limit, $count);
if (($errno = preg_last_error()) !== PREG_NO_ERROR) {
$message = array_flip(get_defined_constants(true)['pcre'])[$errno];
switch ($errno) {
case PREG_INTERNAL_ERROR:
throw new InternalException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BACKTRACK_LIMIT_ERROR:
throw new BacktrackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_RECURSION_LIMIT_ERROR:
throw new RecursionLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_ERROR:
throw new BadUtf8Exception("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_OFFSET_ERROR:
throw new BadUtf8OffsetException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_JIT_STACKLIMIT_ERROR:
throw new JitStackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
}
}
return $result;
}
|
php
|
public function replace(string $subject, string $replacement, int $limit = -1, int &$count = null) : string
{
$result = preg_replace($this->pattern->getPattern() . $this->modifier, $replacement, $subject, $limit, $count);
if (($errno = preg_last_error()) !== PREG_NO_ERROR) {
$message = array_flip(get_defined_constants(true)['pcre'])[$errno];
switch ($errno) {
case PREG_INTERNAL_ERROR:
throw new InternalException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BACKTRACK_LIMIT_ERROR:
throw new BacktrackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_RECURSION_LIMIT_ERROR:
throw new RecursionLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_ERROR:
throw new BadUtf8Exception("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_OFFSET_ERROR:
throw new BadUtf8OffsetException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_JIT_STACKLIMIT_ERROR:
throw new JitStackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
}
}
return $result;
}
|
[
"public",
"function",
"replace",
"(",
"string",
"$",
"subject",
",",
"string",
"$",
"replacement",
",",
"int",
"$",
"limit",
"=",
"-",
"1",
",",
"int",
"&",
"$",
"count",
"=",
"null",
")",
":",
"string",
"{",
"$",
"result",
"=",
"preg_replace",
"(",
"$",
"this",
"->",
"pattern",
"->",
"getPattern",
"(",
")",
".",
"$",
"this",
"->",
"modifier",
",",
"$",
"replacement",
",",
"$",
"subject",
",",
"$",
"limit",
",",
"$",
"count",
")",
";",
"if",
"(",
"(",
"$",
"errno",
"=",
"preg_last_error",
"(",
")",
")",
"!==",
"PREG_NO_ERROR",
")",
"{",
"$",
"message",
"=",
"array_flip",
"(",
"get_defined_constants",
"(",
"true",
")",
"[",
"'pcre'",
"]",
")",
"[",
"$",
"errno",
"]",
";",
"switch",
"(",
"$",
"errno",
")",
"{",
"case",
"PREG_INTERNAL_ERROR",
":",
"throw",
"new",
"InternalException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_BACKTRACK_LIMIT_ERROR",
":",
"throw",
"new",
"BacktrackLimitException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_RECURSION_LIMIT_ERROR",
":",
"throw",
"new",
"RecursionLimitException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_BAD_UTF8_ERROR",
":",
"throw",
"new",
"BadUtf8Exception",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_BAD_UTF8_OFFSET_ERROR",
":",
"throw",
"new",
"BadUtf8OffsetException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_JIT_STACKLIMIT_ERROR",
":",
"throw",
"new",
"JitStackLimitException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Retrieve replaced subject with replacement
@param string $subject
@param string $replacement
@param int $limit
@param int|null $count
@return string
@throws BacktrackLimitException
@throws BadUtf8Exception
@throws BadUtf8OffsetException
@throws InternalException
@throws JitStackLimitException
@throws RecursionLimitException
|
[
"Retrieve",
"replaced",
"subject",
"with",
"replacement"
] |
798c1124805b130b1110ee6e8dcc9a88d8aaffa8
|
https://github.com/madkom/regex/blob/798c1124805b130b1110ee6e8dcc9a88d8aaffa8/src/Replacer.php#L58-L81
|
21,026 |
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Base/src/metadata/pear.php
|
ezcBaseMetaDataPearReader.getRequiredPhpVersion
|
public function getRequiredPhpVersion()
{
@$packageInfo = $this->registry->packageInfo( 'ezcomponents', null, 'components.ez.no' );
if ( array_key_exists( 'required', $packageInfo['dependencies'] ) )
{
return $packageInfo['dependencies']['required']['php']['min'];
}
return $packageInfo['dependencies']['php']['min'];
}
|
php
|
public function getRequiredPhpVersion()
{
@$packageInfo = $this->registry->packageInfo( 'ezcomponents', null, 'components.ez.no' );
if ( array_key_exists( 'required', $packageInfo['dependencies'] ) )
{
return $packageInfo['dependencies']['required']['php']['min'];
}
return $packageInfo['dependencies']['php']['min'];
}
|
[
"public",
"function",
"getRequiredPhpVersion",
"(",
")",
"{",
"@",
"$",
"packageInfo",
"=",
"$",
"this",
"->",
"registry",
"->",
"packageInfo",
"(",
"'ezcomponents'",
",",
"null",
",",
"'components.ez.no'",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'required'",
",",
"$",
"packageInfo",
"[",
"'dependencies'",
"]",
")",
")",
"{",
"return",
"$",
"packageInfo",
"[",
"'dependencies'",
"]",
"[",
"'required'",
"]",
"[",
"'php'",
"]",
"[",
"'min'",
"]",
";",
"}",
"return",
"$",
"packageInfo",
"[",
"'dependencies'",
"]",
"[",
"'php'",
"]",
"[",
"'min'",
"]",
";",
"}"
] |
Returns a PHP version string that describes the required PHP version for
this installed eZ Components bundle.
@return string
|
[
"Returns",
"a",
"PHP",
"version",
"string",
"that",
"describes",
"the",
"required",
"PHP",
"version",
"for",
"this",
"installed",
"eZ",
"Components",
"bundle",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Base/src/metadata/pear.php#L61-L69
|
21,027 |
trunda/SmfMenu
|
src/Smf/Menu/Control/MenuControl.php
|
MenuControl.getRoot
|
public function getRoot()
{
if ($this->root === null) {
$this->root = $this->menuFactory->createItem($this->getName());
}
return $this->root;
}
|
php
|
public function getRoot()
{
if ($this->root === null) {
$this->root = $this->menuFactory->createItem($this->getName());
}
return $this->root;
}
|
[
"public",
"function",
"getRoot",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"root",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"root",
"=",
"$",
"this",
"->",
"menuFactory",
"->",
"createItem",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"root",
";",
"}"
] |
Returns root item
@return \Knp\Menu\ItemInterface
|
[
"Returns",
"root",
"item"
] |
739e74fb664c1f018b4a74142bd28d20c004bac6
|
https://github.com/trunda/SmfMenu/blob/739e74fb664c1f018b4a74142bd28d20c004bac6/src/Smf/Menu/Control/MenuControl.php#L53-L59
|
21,028 |
99designs/ergo-http
|
src/ResponseSender.php
|
ResponseSender.send
|
public function send()
{
$response = $this->_response;
header($response->getStatus()->__toString());
foreach ($response->getHeaders() as $headerField)
header($headerField);
if ($response->hasBody()) echo $response->getBody();
}
|
php
|
public function send()
{
$response = $this->_response;
header($response->getStatus()->__toString());
foreach ($response->getHeaders() as $headerField)
header($headerField);
if ($response->hasBody()) echo $response->getBody();
}
|
[
"public",
"function",
"send",
"(",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"_response",
";",
"header",
"(",
"$",
"response",
"->",
"getStatus",
"(",
")",
"->",
"__toString",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"response",
"->",
"getHeaders",
"(",
")",
"as",
"$",
"headerField",
")",
"header",
"(",
"$",
"headerField",
")",
";",
"if",
"(",
"$",
"response",
"->",
"hasBody",
"(",
")",
")",
"echo",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"}"
] |
Sends the headers and body.
|
[
"Sends",
"the",
"headers",
"and",
"body",
"."
] |
979b789f2e011a1cb70a00161e6b7bcd0d2e9c71
|
https://github.com/99designs/ergo-http/blob/979b789f2e011a1cb70a00161e6b7bcd0d2e9c71/src/ResponseSender.php#L24-L33
|
21,029 |
webservices-nl/common
|
src/Common/Endpoint/Uri.php
|
Uri.filterPort
|
private function filterPort($scheme, $host, $port)
{
if (null !== $port) {
$port = (int) $port;
if (1 > $port || 65535 < $port) {
throw new \InvalidArgumentException(sprintf('Invalid port: %d. Must be between 1 and 65535', $port));
}
}
return self::isStandardPort($port, (string) $scheme, (string) $host) ? null : $port;
}
|
php
|
private function filterPort($scheme, $host, $port)
{
if (null !== $port) {
$port = (int) $port;
if (1 > $port || 65535 < $port) {
throw new \InvalidArgumentException(sprintf('Invalid port: %d. Must be between 1 and 65535', $port));
}
}
return self::isStandardPort($port, (string) $scheme, (string) $host) ? null : $port;
}
|
[
"private",
"function",
"filterPort",
"(",
"$",
"scheme",
",",
"$",
"host",
",",
"$",
"port",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"port",
")",
"{",
"$",
"port",
"=",
"(",
"int",
")",
"$",
"port",
";",
"if",
"(",
"1",
">",
"$",
"port",
"||",
"65535",
"<",
"$",
"port",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid port: %d. Must be between 1 and 65535'",
",",
"$",
"port",
")",
")",
";",
"}",
"}",
"return",
"self",
"::",
"isStandardPort",
"(",
"$",
"port",
",",
"(",
"string",
")",
"$",
"scheme",
",",
"(",
"string",
")",
"$",
"host",
")",
"?",
"null",
":",
"$",
"port",
";",
"}"
] |
Filter port before setting it.
@param string $scheme
@param string $host
@param int $port
@return int|null
@throws \InvalidArgumentException if the port is invalid.
|
[
"Filter",
"port",
"before",
"setting",
"it",
"."
] |
f867fb5969636b185b26442446bb021743a6515e
|
https://github.com/webservices-nl/common/blob/f867fb5969636b185b26442446bb021743a6515e/src/Common/Endpoint/Uri.php#L151-L161
|
21,030 |
webservices-nl/common
|
src/Common/Endpoint/Uri.php
|
Uri.isStandardPort
|
private static function isStandardPort($port, $scheme = null, $host = null)
{
if ($host === null || $scheme === null) {
return false;
}
return array_key_exists($scheme, static::$schemes) && $port === static::$schemes[$scheme];
}
|
php
|
private static function isStandardPort($port, $scheme = null, $host = null)
{
if ($host === null || $scheme === null) {
return false;
}
return array_key_exists($scheme, static::$schemes) && $port === static::$schemes[$scheme];
}
|
[
"private",
"static",
"function",
"isStandardPort",
"(",
"$",
"port",
",",
"$",
"scheme",
"=",
"null",
",",
"$",
"host",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"host",
"===",
"null",
"||",
"$",
"scheme",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"return",
"array_key_exists",
"(",
"$",
"scheme",
",",
"static",
"::",
"$",
"schemes",
")",
"&&",
"$",
"port",
"===",
"static",
"::",
"$",
"schemes",
"[",
"$",
"scheme",
"]",
";",
"}"
] |
Is a given port standard for the current scheme?
@param int $port
@param string $scheme
@param string $host
@return bool
|
[
"Is",
"a",
"given",
"port",
"standard",
"for",
"the",
"current",
"scheme?"
] |
f867fb5969636b185b26442446bb021743a6515e
|
https://github.com/webservices-nl/common/blob/f867fb5969636b185b26442446bb021743a6515e/src/Common/Endpoint/Uri.php#L172-L179
|
21,031 |
webservices-nl/common
|
src/Common/Endpoint/Uri.php
|
Uri.withPath
|
public function withPath($path)
{
if (!is_string($path)) {
throw new \InvalidArgumentException('Invalid path provided; must be a string');
}
$path = $this->filterPath($path);
$new = clone $this;
$new->path = $path;
return $new;
}
|
php
|
public function withPath($path)
{
if (!is_string($path)) {
throw new \InvalidArgumentException('Invalid path provided; must be a string');
}
$path = $this->filterPath($path);
$new = clone $this;
$new->path = $path;
return $new;
}
|
[
"public",
"function",
"withPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid path provided; must be a string'",
")",
";",
"}",
"$",
"path",
"=",
"$",
"this",
"->",
"filterPath",
"(",
"$",
"path",
")",
";",
"$",
"new",
"=",
"clone",
"$",
"this",
";",
"$",
"new",
"->",
"path",
"=",
"$",
"path",
";",
"return",
"$",
"new",
";",
"}"
] |
Returns instance with given path.
@param string $path
@throws \InvalidArgumentException
@return UriInterface
|
[
"Returns",
"instance",
"with",
"given",
"path",
"."
] |
f867fb5969636b185b26442446bb021743a6515e
|
https://github.com/webservices-nl/common/blob/f867fb5969636b185b26442446bb021743a6515e/src/Common/Endpoint/Uri.php#L515-L526
|
21,032 |
mothership-ec/composer
|
src/Composer/Plugin/PluginManager.php
|
PluginManager.loadRepository
|
public function loadRepository(RepositoryInterface $repo)
{
foreach ($repo->getPackages() as $package) { /** @var PackageInterface $package */
if ($package instanceof AliasPackage) {
continue;
}
if ('composer-plugin' === $package->getType()) {
$requiresComposer = null;
foreach ($package->getRequires() as $link) { /** @var Link $link */
if ('composer-plugin-api' === $link->getTarget()) {
$requiresComposer = $link->getConstraint();
break;
}
}
if (!$requiresComposer) {
throw new \RuntimeException("Plugin ".$package->getName()." is missing a require statement for a version of the composer-plugin-api package.");
}
$currentPluginApiVersion = $this->getPluginApiVersion();
$currentPluginApiConstraint = new VersionConstraint('==', $this->versionParser->normalize($currentPluginApiVersion));
if (!$requiresComposer->matches($currentPluginApiConstraint)) {
$this->io->writeError('<warning>The "' . $package->getName() . '" plugin was skipped because it requires a Plugin API version ("' . $requiresComposer->getPrettyString() . '") that does not match your Composer installation ("' . $currentPluginApiVersion . '"). You may need to run composer update with the "--no-plugins" option.</warning>');
continue;
}
$this->registerPackage($package);
// Backward compatibility
} elseif ('composer-installer' === $package->getType()) {
$this->registerPackage($package);
}
}
}
|
php
|
public function loadRepository(RepositoryInterface $repo)
{
foreach ($repo->getPackages() as $package) { /** @var PackageInterface $package */
if ($package instanceof AliasPackage) {
continue;
}
if ('composer-plugin' === $package->getType()) {
$requiresComposer = null;
foreach ($package->getRequires() as $link) { /** @var Link $link */
if ('composer-plugin-api' === $link->getTarget()) {
$requiresComposer = $link->getConstraint();
break;
}
}
if (!$requiresComposer) {
throw new \RuntimeException("Plugin ".$package->getName()." is missing a require statement for a version of the composer-plugin-api package.");
}
$currentPluginApiVersion = $this->getPluginApiVersion();
$currentPluginApiConstraint = new VersionConstraint('==', $this->versionParser->normalize($currentPluginApiVersion));
if (!$requiresComposer->matches($currentPluginApiConstraint)) {
$this->io->writeError('<warning>The "' . $package->getName() . '" plugin was skipped because it requires a Plugin API version ("' . $requiresComposer->getPrettyString() . '") that does not match your Composer installation ("' . $currentPluginApiVersion . '"). You may need to run composer update with the "--no-plugins" option.</warning>');
continue;
}
$this->registerPackage($package);
// Backward compatibility
} elseif ('composer-installer' === $package->getType()) {
$this->registerPackage($package);
}
}
}
|
[
"public",
"function",
"loadRepository",
"(",
"RepositoryInterface",
"$",
"repo",
")",
"{",
"foreach",
"(",
"$",
"repo",
"->",
"getPackages",
"(",
")",
"as",
"$",
"package",
")",
"{",
"/** @var PackageInterface $package */",
"if",
"(",
"$",
"package",
"instanceof",
"AliasPackage",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"'composer-plugin'",
"===",
"$",
"package",
"->",
"getType",
"(",
")",
")",
"{",
"$",
"requiresComposer",
"=",
"null",
";",
"foreach",
"(",
"$",
"package",
"->",
"getRequires",
"(",
")",
"as",
"$",
"link",
")",
"{",
"/** @var Link $link */",
"if",
"(",
"'composer-plugin-api'",
"===",
"$",
"link",
"->",
"getTarget",
"(",
")",
")",
"{",
"$",
"requiresComposer",
"=",
"$",
"link",
"->",
"getConstraint",
"(",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"requiresComposer",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Plugin \"",
".",
"$",
"package",
"->",
"getName",
"(",
")",
".",
"\" is missing a require statement for a version of the composer-plugin-api package.\"",
")",
";",
"}",
"$",
"currentPluginApiVersion",
"=",
"$",
"this",
"->",
"getPluginApiVersion",
"(",
")",
";",
"$",
"currentPluginApiConstraint",
"=",
"new",
"VersionConstraint",
"(",
"'=='",
",",
"$",
"this",
"->",
"versionParser",
"->",
"normalize",
"(",
"$",
"currentPluginApiVersion",
")",
")",
";",
"if",
"(",
"!",
"$",
"requiresComposer",
"->",
"matches",
"(",
"$",
"currentPluginApiConstraint",
")",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"'<warning>The \"'",
".",
"$",
"package",
"->",
"getName",
"(",
")",
".",
"'\" plugin was skipped because it requires a Plugin API version (\"'",
".",
"$",
"requiresComposer",
"->",
"getPrettyString",
"(",
")",
".",
"'\") that does not match your Composer installation (\"'",
".",
"$",
"currentPluginApiVersion",
".",
"'\"). You may need to run composer update with the \"--no-plugins\" option.</warning>'",
")",
";",
"continue",
";",
"}",
"$",
"this",
"->",
"registerPackage",
"(",
"$",
"package",
")",
";",
"// Backward compatibility",
"}",
"elseif",
"(",
"'composer-installer'",
"===",
"$",
"package",
"->",
"getType",
"(",
")",
")",
"{",
"$",
"this",
"->",
"registerPackage",
"(",
"$",
"package",
")",
";",
"}",
"}",
"}"
] |
Load all plugins and installers from a repository
Note that plugins in the specified repository that rely on events that
have fired prior to loading will be missed. This means you likely want to
call this method as early as possible.
@param RepositoryInterface $repo Repository to scan for plugins to install
@throws \RuntimeException
|
[
"Load",
"all",
"plugins",
"and",
"installers",
"from",
"a",
"repository"
] |
fa6ad031a939d8d33b211e428fdbdd28cfce238c
|
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Plugin/PluginManager.php#L114-L148
|
21,033 |
mothership-ec/composer
|
src/Composer/Plugin/PluginManager.php
|
PluginManager.lookupInstalledPackage
|
protected function lookupInstalledPackage(Pool $pool, Link $link)
{
$packages = $pool->whatProvides($link->getTarget(), $link->getConstraint());
return (!empty($packages)) ? $packages[0] : null;
}
|
php
|
protected function lookupInstalledPackage(Pool $pool, Link $link)
{
$packages = $pool->whatProvides($link->getTarget(), $link->getConstraint());
return (!empty($packages)) ? $packages[0] : null;
}
|
[
"protected",
"function",
"lookupInstalledPackage",
"(",
"Pool",
"$",
"pool",
",",
"Link",
"$",
"link",
")",
"{",
"$",
"packages",
"=",
"$",
"pool",
"->",
"whatProvides",
"(",
"$",
"link",
"->",
"getTarget",
"(",
")",
",",
"$",
"link",
"->",
"getConstraint",
"(",
")",
")",
";",
"return",
"(",
"!",
"empty",
"(",
"$",
"packages",
")",
")",
"?",
"$",
"packages",
"[",
"0",
"]",
":",
"null",
";",
"}"
] |
Resolves a package link to a package in the installed pool
Since dependencies are already installed this should always find one.
@param Pool $pool Pool of installed packages only
@param Link $link Package link to look up
@return PackageInterface|null The found package
|
[
"Resolves",
"a",
"package",
"link",
"to",
"a",
"package",
"in",
"the",
"installed",
"pool"
] |
fa6ad031a939d8d33b211e428fdbdd28cfce238c
|
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Plugin/PluginManager.php#L187-L192
|
21,034 |
zhouyl/mellivora
|
Mellivora/Database/Query/Builder.php
|
Builder.prepareValueAndOperator
|
protected function prepareValueAndOperator($value, $operator, $useDefault = false)
{
if ($useDefault) {
return [$operator, '='];
}
if ($this->invalidOperatorAndValue($operator, $value)) {
throw new InvalidArgumentException('Illegal operator and value combination.');
}
return [$value, $operator];
}
|
php
|
protected function prepareValueAndOperator($value, $operator, $useDefault = false)
{
if ($useDefault) {
return [$operator, '='];
}
if ($this->invalidOperatorAndValue($operator, $value)) {
throw new InvalidArgumentException('Illegal operator and value combination.');
}
return [$value, $operator];
}
|
[
"protected",
"function",
"prepareValueAndOperator",
"(",
"$",
"value",
",",
"$",
"operator",
",",
"$",
"useDefault",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"useDefault",
")",
"{",
"return",
"[",
"$",
"operator",
",",
"'='",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"invalidOperatorAndValue",
"(",
"$",
"operator",
",",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Illegal operator and value combination.'",
")",
";",
"}",
"return",
"[",
"$",
"value",
",",
"$",
"operator",
"]",
";",
"}"
] |
Prepare the value and operator for a where clause.
@param string $value
@param string $operator
@param bool $useDefault
@throws \InvalidArgumentException
@return array
|
[
"Prepare",
"the",
"value",
"and",
"operator",
"for",
"a",
"where",
"clause",
"."
] |
79f844c5c9c25ffbe18d142062e9bc3df00b36a1
|
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Builder.php#L632-L642
|
21,035 |
zhouyl/mellivora
|
Mellivora/Database/Query/Builder.php
|
Builder.runPaginationCountQuery
|
protected function runPaginationCountQuery($columns = ['*'])
{
return $this->cloneWithout(['columns', 'orders', 'limit', 'offset'])
->cloneWithoutBindings(['select', 'order'])
->setAggregate('count', $this->withoutSelectAliases($columns))
->get()->all();
}
|
php
|
protected function runPaginationCountQuery($columns = ['*'])
{
return $this->cloneWithout(['columns', 'orders', 'limit', 'offset'])
->cloneWithoutBindings(['select', 'order'])
->setAggregate('count', $this->withoutSelectAliases($columns))
->get()->all();
}
|
[
"protected",
"function",
"runPaginationCountQuery",
"(",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"cloneWithout",
"(",
"[",
"'columns'",
",",
"'orders'",
",",
"'limit'",
",",
"'offset'",
"]",
")",
"->",
"cloneWithoutBindings",
"(",
"[",
"'select'",
",",
"'order'",
"]",
")",
"->",
"setAggregate",
"(",
"'count'",
",",
"$",
"this",
"->",
"withoutSelectAliases",
"(",
"$",
"columns",
")",
")",
"->",
"get",
"(",
")",
"->",
"all",
"(",
")",
";",
"}"
] |
Run a pagiantion count query.
@param array $columns
@return array
|
[
"Run",
"a",
"pagiantion",
"count",
"query",
"."
] |
79f844c5c9c25ffbe18d142062e9bc3df00b36a1
|
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Builder.php#L1922-L1928
|
21,036 |
surebert/surebert-framework
|
src/sb/Ebook/Epub/OPF.php
|
OPF.setAuthor
|
public function setAuthor($author, $sort_key = '')
{
$this->creator = $this->metadata->appendChild($this->createElement('dc:creator'));
$this->creator->setAttribute('opf:role', "aut");
$txt = $this->createTextNode($author);
$this->creator->appendChild($txt);
if ($sort_key) {
$this->creator->setAttribute('opf:file-as', $sort_key);
}
}
|
php
|
public function setAuthor($author, $sort_key = '')
{
$this->creator = $this->metadata->appendChild($this->createElement('dc:creator'));
$this->creator->setAttribute('opf:role', "aut");
$txt = $this->createTextNode($author);
$this->creator->appendChild($txt);
if ($sort_key) {
$this->creator->setAttribute('opf:file-as', $sort_key);
}
}
|
[
"public",
"function",
"setAuthor",
"(",
"$",
"author",
",",
"$",
"sort_key",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"creator",
"=",
"$",
"this",
"->",
"metadata",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'dc:creator'",
")",
")",
";",
"$",
"this",
"->",
"creator",
"->",
"setAttribute",
"(",
"'opf:role'",
",",
"\"aut\"",
")",
";",
"$",
"txt",
"=",
"$",
"this",
"->",
"createTextNode",
"(",
"$",
"author",
")",
";",
"$",
"this",
"->",
"creator",
"->",
"appendChild",
"(",
"$",
"txt",
")",
";",
"if",
"(",
"$",
"sort_key",
")",
"{",
"$",
"this",
"->",
"creator",
"->",
"setAttribute",
"(",
"'opf:file-as'",
",",
"$",
"sort_key",
")",
";",
"}",
"}"
] |
Book author or creator, optional.
.
@param string $author Used for the dc:creator metadata parameter in the
OPF file
@param string $sort_key is basically how the name is to be sorted, usually
it's "Lastname, First names" where the $author is the straight
"Firstnames Lastname"
|
[
"Book",
"author",
"or",
"creator",
"optional",
".",
"."
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Ebook/Epub/OPF.php#L182-L191
|
21,037 |
thecodingmachine/interop.silex.di
|
src/Mouf/Interop/Silex/Application.php
|
Application.offsetGet
|
public function offsetGet($id)
{
if ($this->rootContainer) {
try {
return $this->rootContainer->get($id);
} catch (NotFoundException $ex) {
// Fallback to pimple if offsetGet fails.
return $this->pimpleContainer[$id];
}
} else {
return $this->pimpleContainer[$id];
}
}
|
php
|
public function offsetGet($id)
{
if ($this->rootContainer) {
try {
return $this->rootContainer->get($id);
} catch (NotFoundException $ex) {
// Fallback to pimple if offsetGet fails.
return $this->pimpleContainer[$id];
}
} else {
return $this->pimpleContainer[$id];
}
}
|
[
"public",
"function",
"offsetGet",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"rootContainer",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"rootContainer",
"->",
"get",
"(",
"$",
"id",
")",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"ex",
")",
"{",
"// Fallback to pimple if offsetGet fails.",
"return",
"$",
"this",
"->",
"pimpleContainer",
"[",
"$",
"id",
"]",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"pimpleContainer",
"[",
"$",
"id",
"]",
";",
"}",
"}"
] |
Gets a parameter or an object, first from the root container, then from Pimple if nothing is found in root container.
It is expected that the root container will be a composite container with Pimple being part of it, therefore,
the fallback to Pimple is just here by security.
@param string $id The unique identifier for the parameter or object
@return mixed The value of the parameter or an object
@throws PimpleNotFoundException if the identifier is not defined
|
[
"Gets",
"a",
"parameter",
"or",
"an",
"object",
"first",
"from",
"the",
"root",
"container",
"then",
"from",
"Pimple",
"if",
"nothing",
"is",
"found",
"in",
"root",
"container",
".",
"It",
"is",
"expected",
"that",
"the",
"root",
"container",
"will",
"be",
"a",
"composite",
"container",
"with",
"Pimple",
"being",
"part",
"of",
"it",
"therefore",
"the",
"fallback",
"to",
"Pimple",
"is",
"just",
"here",
"by",
"security",
"."
] |
14f7682bf9db3f4aab50d6f1c216df405b8aaa6d
|
https://github.com/thecodingmachine/interop.silex.di/blob/14f7682bf9db3f4aab50d6f1c216df405b8aaa6d/src/Mouf/Interop/Silex/Application.php#L66-L78
|
21,038 |
thecodingmachine/interop.silex.di
|
src/Mouf/Interop/Silex/Application.php
|
Application.offsetExists
|
public function offsetExists($id)
{
if ($this->rootContainer) {
try {
return $this->rootContainer->has($id);
} catch (NotFoundException $ex) {
// Fallback to pimple if offsetExists fails.
return $this->pimpleContainer->offsetExists($id);
}
} else {
return $this->pimpleContainer->offsetExists($id);
}
}
|
php
|
public function offsetExists($id)
{
if ($this->rootContainer) {
try {
return $this->rootContainer->has($id);
} catch (NotFoundException $ex) {
// Fallback to pimple if offsetExists fails.
return $this->pimpleContainer->offsetExists($id);
}
} else {
return $this->pimpleContainer->offsetExists($id);
}
}
|
[
"public",
"function",
"offsetExists",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"rootContainer",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"rootContainer",
"->",
"has",
"(",
"$",
"id",
")",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"ex",
")",
"{",
"// Fallback to pimple if offsetExists fails.",
"return",
"$",
"this",
"->",
"pimpleContainer",
"->",
"offsetExists",
"(",
"$",
"id",
")",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"pimpleContainer",
"->",
"offsetExists",
"(",
"$",
"id",
")",
";",
"}",
"}"
] |
Check existence of a parameter or an object, first in the root container, then in Pimple if nothing is found in root container.
It is expected that the root container will be a composite container with Pimple being part of it, therefore,
the fallback to Pimple is just here by security.
@param string $id The unique identifier for the parameter or object
@return Boolean
|
[
"Check",
"existence",
"of",
"a",
"parameter",
"or",
"an",
"object",
"first",
"in",
"the",
"root",
"container",
"then",
"in",
"Pimple",
"if",
"nothing",
"is",
"found",
"in",
"root",
"container",
".",
"It",
"is",
"expected",
"that",
"the",
"root",
"container",
"will",
"be",
"a",
"composite",
"container",
"with",
"Pimple",
"being",
"part",
"of",
"it",
"therefore",
"the",
"fallback",
"to",
"Pimple",
"is",
"just",
"here",
"by",
"security",
"."
] |
14f7682bf9db3f4aab50d6f1c216df405b8aaa6d
|
https://github.com/thecodingmachine/interop.silex.di/blob/14f7682bf9db3f4aab50d6f1c216df405b8aaa6d/src/Mouf/Interop/Silex/Application.php#L100-L112
|
21,039 |
SporkCode/Spork
|
src/View/Helper/GoogleAnalytic.php
|
GoogleAnalytic.createService
|
public function createService(ServiceLocatorInterface $viewHelperManager)
{
$serviceLocator = $viewHelperManager->getServiceLocator();
$config = $serviceLocator->has('config') ? $serviceLocator->get('config') : array();
if (isset($config['google_analytics'])) {
$this->config($config['google_analytics']);
}
return $this;
}
|
php
|
public function createService(ServiceLocatorInterface $viewHelperManager)
{
$serviceLocator = $viewHelperManager->getServiceLocator();
$config = $serviceLocator->has('config') ? $serviceLocator->get('config') : array();
if (isset($config['google_analytics'])) {
$this->config($config['google_analytics']);
}
return $this;
}
|
[
"public",
"function",
"createService",
"(",
"ServiceLocatorInterface",
"$",
"viewHelperManager",
")",
"{",
"$",
"serviceLocator",
"=",
"$",
"viewHelperManager",
"->",
"getServiceLocator",
"(",
")",
";",
"$",
"config",
"=",
"$",
"serviceLocator",
"->",
"has",
"(",
"'config'",
")",
"?",
"$",
"serviceLocator",
"->",
"get",
"(",
"'config'",
")",
":",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'google_analytics'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"(",
"$",
"config",
"[",
"'google_analytics'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Create and configure helper instance
@see \Zend\ServiceManager\FactoryInterface::createService()
@param ServiceLocatorInterface $viewHelperManager
@return \Spork\View\Helper\GoogleAnalytic
|
[
"Create",
"and",
"configure",
"helper",
"instance"
] |
7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a
|
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/View/Helper/GoogleAnalytic.php#L45-L54
|
21,040 |
SporkCode/Spork
|
src/View/Helper/GoogleAnalytic.php
|
GoogleAnalytic.initialize
|
public function initialize()
{
if (true == $this->initialized) {
return;
}
$this->initialized = true;
if (null !== $this->trackingId) {
$trackerId = $this->trackingId;
$inlineScript = $this->getView()->plugin('inlineScript');
$inlineScript->appendScript(<<<HDOC
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '$trackerId', 'auto');
ga('send', 'pageview');
HDOC
);
}
}
|
php
|
public function initialize()
{
if (true == $this->initialized) {
return;
}
$this->initialized = true;
if (null !== $this->trackingId) {
$trackerId = $this->trackingId;
$inlineScript = $this->getView()->plugin('inlineScript');
$inlineScript->appendScript(<<<HDOC
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '$trackerId', 'auto');
ga('send', 'pageview');
HDOC
);
}
}
|
[
"public",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"true",
"==",
"$",
"this",
"->",
"initialized",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"initialized",
"=",
"true",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"trackingId",
")",
"{",
"$",
"trackerId",
"=",
"$",
"this",
"->",
"trackingId",
";",
"$",
"inlineScript",
"=",
"$",
"this",
"->",
"getView",
"(",
")",
"->",
"plugin",
"(",
"'inlineScript'",
")",
";",
"$",
"inlineScript",
"->",
"appendScript",
"(",
"<<<HDOC\n(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\nm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\nga('create', '$trackerId', 'auto');\nga('send', 'pageview');\nHDOC",
")",
";",
"}",
"}"
] |
Inject Google Analytics tracker code into InlineScript helper. This
should only be called once after the helper is completely configured.
|
[
"Inject",
"Google",
"Analytics",
"tracker",
"code",
"into",
"InlineScript",
"helper",
".",
"This",
"should",
"only",
"be",
"called",
"once",
"after",
"the",
"helper",
"is",
"completely",
"configured",
"."
] |
7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a
|
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/View/Helper/GoogleAnalytic.php#L95-L115
|
21,041 |
dave-redfern/somnambulist-value-objects
|
src/Types/DateTime/Traits/Factory.php
|
Factory.create
|
public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null,
$second = null, TimeZone $tz = null)
{
[$nowYear, $nowMonth, $nowDay, $nowHour, $nowMin, $nowSec] = explode('-', date('Y-n-j-G-i-s', time()));
$year = $year ?? $nowYear;
$month = $month ?? $nowMonth;
$day = $day ?? $nowDay;
$hour = $hour ?? $nowHour;
$minute = $minute ?? $nowMin;
$second = $second ?? $nowSec;
$tz = $tz ?? TimeZone::create();
return static::createFromFormat(
'Y-n-j G:i:s',
sprintf('%s-%s-%s %s:%02s:%02s', $year, $month, $day, $hour, $minute, $second),
$tz->toNative()
);
}
|
php
|
public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null,
$second = null, TimeZone $tz = null)
{
[$nowYear, $nowMonth, $nowDay, $nowHour, $nowMin, $nowSec] = explode('-', date('Y-n-j-G-i-s', time()));
$year = $year ?? $nowYear;
$month = $month ?? $nowMonth;
$day = $day ?? $nowDay;
$hour = $hour ?? $nowHour;
$minute = $minute ?? $nowMin;
$second = $second ?? $nowSec;
$tz = $tz ?? TimeZone::create();
return static::createFromFormat(
'Y-n-j G:i:s',
sprintf('%s-%s-%s %s:%02s:%02s', $year, $month, $day, $hour, $minute, $second),
$tz->toNative()
);
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"year",
"=",
"null",
",",
"$",
"month",
"=",
"null",
",",
"$",
"day",
"=",
"null",
",",
"$",
"hour",
"=",
"null",
",",
"$",
"minute",
"=",
"null",
",",
"$",
"second",
"=",
"null",
",",
"TimeZone",
"$",
"tz",
"=",
"null",
")",
"{",
"[",
"$",
"nowYear",
",",
"$",
"nowMonth",
",",
"$",
"nowDay",
",",
"$",
"nowHour",
",",
"$",
"nowMin",
",",
"$",
"nowSec",
"]",
"=",
"explode",
"(",
"'-'",
",",
"date",
"(",
"'Y-n-j-G-i-s'",
",",
"time",
"(",
")",
")",
")",
";",
"$",
"year",
"=",
"$",
"year",
"??",
"$",
"nowYear",
";",
"$",
"month",
"=",
"$",
"month",
"??",
"$",
"nowMonth",
";",
"$",
"day",
"=",
"$",
"day",
"??",
"$",
"nowDay",
";",
"$",
"hour",
"=",
"$",
"hour",
"??",
"$",
"nowHour",
";",
"$",
"minute",
"=",
"$",
"minute",
"??",
"$",
"nowMin",
";",
"$",
"second",
"=",
"$",
"second",
"??",
"$",
"nowSec",
";",
"$",
"tz",
"=",
"$",
"tz",
"??",
"TimeZone",
"::",
"create",
"(",
")",
";",
"return",
"static",
"::",
"createFromFormat",
"(",
"'Y-n-j G:i:s'",
",",
"sprintf",
"(",
"'%s-%s-%s %s:%02s:%02s'",
",",
"$",
"year",
",",
"$",
"month",
",",
"$",
"day",
",",
"$",
"hour",
",",
"$",
"minute",
",",
"$",
"second",
")",
",",
"$",
"tz",
"->",
"toNative",
"(",
")",
")",
";",
"}"
] |
Create a DateTime instance
Based on Carbon::create with the following differences:
* if you require an hour, you must specify minutes and seconds as 0 (zero)
* TimeZone should be specified using the value object
@param null|int $year
@param null|int $month
@param null|int $day
@param null|int $hour
@param null|int $minute
@param null|int $second
@param null|TimeZone $tz
@return bool|DateTime
|
[
"Create",
"a",
"DateTime",
"instance"
] |
dbae7fea7140b36e105ed3f5e21a42316ea3061f
|
https://github.com/dave-redfern/somnambulist-value-objects/blob/dbae7fea7140b36e105ed3f5e21a42316ea3061f/src/Types/DateTime/Traits/Factory.php#L74-L92
|
21,042 |
GrupaZero/api
|
src/Gzero/Api/Transformer/AbstractTransformer.php
|
AbstractTransformer.entityToArray
|
protected function entityToArray($class, $object)
{
if (is_object($object) && get_class($object) == $class) {
$object = $object->toArray();
}
return $object;
}
|
php
|
protected function entityToArray($class, $object)
{
if (is_object($object) && get_class($object) == $class) {
$object = $object->toArray();
}
return $object;
}
|
[
"protected",
"function",
"entityToArray",
"(",
"$",
"class",
",",
"$",
"object",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"object",
")",
"&&",
"get_class",
"(",
"$",
"object",
")",
"==",
"$",
"class",
")",
"{",
"$",
"object",
"=",
"$",
"object",
"->",
"toArray",
"(",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] |
Return entity transformed to array
@param string $class Entity class
@param mixed $object Entity object or array
@return array
|
[
"Return",
"entity",
"transformed",
"to",
"array"
] |
fc544bb6057274e9d5e7b617346c3f854ea5effd
|
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Transformer/AbstractTransformer.php#L27-L33
|
21,043 |
surebert/surebert-framework
|
src/sb/Event.php
|
Event.getArg
|
public function getArg($key='')
{
if(isset($this->args[$key])){
return $this->args[$key];
} else {
return null;
}
}
|
php
|
public function getArg($key='')
{
if(isset($this->args[$key])){
return $this->args[$key];
} else {
return null;
}
}
|
[
"public",
"function",
"getArg",
"(",
"$",
"key",
"=",
"''",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"args",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"args",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Gets the event _args value for a specific key if passed
@param string $key the specific key to fetch
@return mixed Whatever value the key holds or the full array if no key is specified
|
[
"Gets",
"the",
"event",
"_args",
"value",
"for",
"a",
"specific",
"key",
"if",
"passed"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Event.php#L108-L116
|
21,044 |
Daursu/xero
|
src/Daursu/Xero/lib/XeroOAuth.php
|
XeroOAuth.parseResponse
|
function parseResponse($response, $format) {
if (isset ( $format )) {
switch ($format) {
case "pdf" :
$theResponse = $response;
break;
case "json" :
$theResponse = json_decode ( $response, true );
break;
default :
$theResponse = simplexml_load_string ( $response );
break;
}
}
return $theResponse;
}
|
php
|
function parseResponse($response, $format) {
if (isset ( $format )) {
switch ($format) {
case "pdf" :
$theResponse = $response;
break;
case "json" :
$theResponse = json_decode ( $response, true );
break;
default :
$theResponse = simplexml_load_string ( $response );
break;
}
}
return $theResponse;
}
|
[
"function",
"parseResponse",
"(",
"$",
"response",
",",
"$",
"format",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"format",
")",
")",
"{",
"switch",
"(",
"$",
"format",
")",
"{",
"case",
"\"pdf\"",
":",
"$",
"theResponse",
"=",
"$",
"response",
";",
"break",
";",
"case",
"\"json\"",
":",
"$",
"theResponse",
"=",
"json_decode",
"(",
"$",
"response",
",",
"true",
")",
";",
"break",
";",
"default",
":",
"$",
"theResponse",
"=",
"simplexml_load_string",
"(",
"$",
"response",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"theResponse",
";",
"}"
] |
Convert the response into usable data
@param string $response
the raw response from the API
@param string $format
the format of the response
@return string the concatenation of the host, API version and API method
|
[
"Convert",
"the",
"response",
"into",
"usable",
"data"
] |
f6ac2b0cd3123f9667fd07927bee6725d34df4a6
|
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/lib/XeroOAuth.php#L488-L503
|
21,045 |
ganlvtech/php-simple-cas-proxy
|
src/PhpCasProxy.php
|
PhpCasProxy.filterService
|
protected function filterService()
{
if (empty($_GET['service'])) {
return false;
}
if (is_null($this->service_filter)) {
return true;
}
return (true == call_user_func($this->service_filter, $_GET['service']));
}
|
php
|
protected function filterService()
{
if (empty($_GET['service'])) {
return false;
}
if (is_null($this->service_filter)) {
return true;
}
return (true == call_user_func($this->service_filter, $_GET['service']));
}
|
[
"protected",
"function",
"filterService",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"_GET",
"[",
"'service'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"service_filter",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"(",
"true",
"==",
"call_user_func",
"(",
"$",
"this",
"->",
"service_filter",
",",
"$",
"_GET",
"[",
"'service'",
"]",
")",
")",
";",
"}"
] |
Validate if the proxied service is authenticated
@return bool
|
[
"Validate",
"if",
"the",
"proxied",
"service",
"is",
"authenticated"
] |
eda8628b424db83d4b243bc2fa9d47cde0faba39
|
https://github.com/ganlvtech/php-simple-cas-proxy/blob/eda8628b424db83d4b243bc2fa9d47cde0faba39/src/PhpCasProxy.php#L76-L85
|
21,046 |
ganlvtech/php-simple-cas-proxy
|
src/PhpCasProxy.php
|
PhpCasProxy.login
|
public function login($service, $gateway = false)
{
$query = array(
'service' => $this->my_service . '?' . http_build_query(array(
'service' => $service,
)),
);
if ($gateway) {
$query['gateway'] = $gateway;
}
self::http_redirect($this->server['login_url'] . '?' . http_build_query($query));
// never reach
return true;
}
|
php
|
public function login($service, $gateway = false)
{
$query = array(
'service' => $this->my_service . '?' . http_build_query(array(
'service' => $service,
)),
);
if ($gateway) {
$query['gateway'] = $gateway;
}
self::http_redirect($this->server['login_url'] . '?' . http_build_query($query));
// never reach
return true;
}
|
[
"public",
"function",
"login",
"(",
"$",
"service",
",",
"$",
"gateway",
"=",
"false",
")",
"{",
"$",
"query",
"=",
"array",
"(",
"'service'",
"=>",
"$",
"this",
"->",
"my_service",
".",
"'?'",
".",
"http_build_query",
"(",
"array",
"(",
"'service'",
"=>",
"$",
"service",
",",
")",
")",
",",
")",
";",
"if",
"(",
"$",
"gateway",
")",
"{",
"$",
"query",
"[",
"'gateway'",
"]",
"=",
"$",
"gateway",
";",
"}",
"self",
"::",
"http_redirect",
"(",
"$",
"this",
"->",
"server",
"[",
"'login_url'",
"]",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"query",
")",
")",
";",
"// never reach",
"return",
"true",
";",
"}"
] |
From proxied service to CAS server
@param string $service
@param string|bool $gateway
@return bool always true, but never reach.
|
[
"From",
"proxied",
"service",
"to",
"CAS",
"server"
] |
eda8628b424db83d4b243bc2fa9d47cde0faba39
|
https://github.com/ganlvtech/php-simple-cas-proxy/blob/eda8628b424db83d4b243bc2fa9d47cde0faba39/src/PhpCasProxy.php#L143-L156
|
21,047 |
ganlvtech/php-simple-cas-proxy
|
src/PhpCasProxy.php
|
PhpCasProxy.back
|
public function back($service, $ticket = '')
{
$parts = parse_url($service);
if (isset($parts['query'])) {
parse_str($parts['query'], $query);
} else {
$query = array();
}
if (!empty($ticket)) {
$query['ticket'] = $ticket;
}
$parts['query'] = http_build_query($query);
self::http_redirect(self::build_url($parts));
// never reach
return true;
}
|
php
|
public function back($service, $ticket = '')
{
$parts = parse_url($service);
if (isset($parts['query'])) {
parse_str($parts['query'], $query);
} else {
$query = array();
}
if (!empty($ticket)) {
$query['ticket'] = $ticket;
}
$parts['query'] = http_build_query($query);
self::http_redirect(self::build_url($parts));
// never reach
return true;
}
|
[
"public",
"function",
"back",
"(",
"$",
"service",
",",
"$",
"ticket",
"=",
"''",
")",
"{",
"$",
"parts",
"=",
"parse_url",
"(",
"$",
"service",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'query'",
"]",
")",
")",
"{",
"parse_str",
"(",
"$",
"parts",
"[",
"'query'",
"]",
",",
"$",
"query",
")",
";",
"}",
"else",
"{",
"$",
"query",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"ticket",
")",
")",
"{",
"$",
"query",
"[",
"'ticket'",
"]",
"=",
"$",
"ticket",
";",
"}",
"$",
"parts",
"[",
"'query'",
"]",
"=",
"http_build_query",
"(",
"$",
"query",
")",
";",
"self",
"::",
"http_redirect",
"(",
"self",
"::",
"build_url",
"(",
"$",
"parts",
")",
")",
";",
"// never reach",
"return",
"true",
";",
"}"
] |
From CAS server back to proxied service
@param string $service proxied service
@param string $ticket
@return bool always true, but never reach.
|
[
"From",
"CAS",
"server",
"back",
"to",
"proxied",
"service"
] |
eda8628b424db83d4b243bc2fa9d47cde0faba39
|
https://github.com/ganlvtech/php-simple-cas-proxy/blob/eda8628b424db83d4b243bc2fa9d47cde0faba39/src/PhpCasProxy.php#L166-L181
|
21,048 |
ganlvtech/php-simple-cas-proxy
|
src/PhpCasProxy.php
|
PhpCasProxy.serviceValidate
|
public function serviceValidate($service, $ticket, $timeout = 10)
{
header('Content-Type: text/xml; charset=UTF-8');
exit(self::file_get_contents($this->server['service_validate_url'] . '?' . http_build_query(array(
'service' => $this->my_service . '?' . http_build_query(array(
'service' => $service,
)),
'ticket' => $ticket,
)), $timeout));
// never reach
return true;
}
|
php
|
public function serviceValidate($service, $ticket, $timeout = 10)
{
header('Content-Type: text/xml; charset=UTF-8');
exit(self::file_get_contents($this->server['service_validate_url'] . '?' . http_build_query(array(
'service' => $this->my_service . '?' . http_build_query(array(
'service' => $service,
)),
'ticket' => $ticket,
)), $timeout));
// never reach
return true;
}
|
[
"public",
"function",
"serviceValidate",
"(",
"$",
"service",
",",
"$",
"ticket",
",",
"$",
"timeout",
"=",
"10",
")",
"{",
"header",
"(",
"'Content-Type: text/xml; charset=UTF-8'",
")",
";",
"exit",
"(",
"self",
"::",
"file_get_contents",
"(",
"$",
"this",
"->",
"server",
"[",
"'service_validate_url'",
"]",
".",
"'?'",
".",
"http_build_query",
"(",
"array",
"(",
"'service'",
"=>",
"$",
"this",
"->",
"my_service",
".",
"'?'",
".",
"http_build_query",
"(",
"array",
"(",
"'service'",
"=>",
"$",
"service",
",",
")",
")",
",",
"'ticket'",
"=>",
"$",
"ticket",
",",
")",
")",
",",
"$",
"timeout",
")",
")",
";",
"// never reach",
"return",
"true",
";",
"}"
] |
Pass service validate http response
@param string $service proxied service
@param string $ticket CAS ticket
@param int $timeout
@return bool always true, but never reach.
|
[
"Pass",
"service",
"validate",
"http",
"response"
] |
eda8628b424db83d4b243bc2fa9d47cde0faba39
|
https://github.com/ganlvtech/php-simple-cas-proxy/blob/eda8628b424db83d4b243bc2fa9d47cde0faba39/src/PhpCasProxy.php#L192-L203
|
21,049 |
SporkCode/Spork
|
src/Mvc/Listener/Limit/LimitStrategy.php
|
LimitStrategy.detach
|
public function detach(EventManagerInterface $events)
{
foreach ($this->listeners as $listener) {
$events->detach($listener);
}
}
|
php
|
public function detach(EventManagerInterface $events)
{
foreach ($this->listeners as $listener) {
$events->detach($listener);
}
}
|
[
"public",
"function",
"detach",
"(",
"EventManagerInterface",
"$",
"events",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"listeners",
"as",
"$",
"listener",
")",
"{",
"$",
"events",
"->",
"detach",
"(",
"$",
"listener",
")",
";",
"}",
"}"
] |
Detach event listeners
@param EventManagerInterface $events
@see \Zend\EventManager\ListenerAggregateInterface::detach()
|
[
"Detach",
"event",
"listeners"
] |
7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a
|
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L118-L123
|
21,050 |
SporkCode/Spork
|
src/Mvc/Listener/Limit/LimitStrategy.php
|
LimitStrategy.getActionPlugins
|
public function getActionPlugins()
{
if (null === $this->actionPlugins) {
$this->setActionPlugins(new Action\PluginManager());
}
return $this->actionPlugins;
}
|
php
|
public function getActionPlugins()
{
if (null === $this->actionPlugins) {
$this->setActionPlugins(new Action\PluginManager());
}
return $this->actionPlugins;
}
|
[
"public",
"function",
"getActionPlugins",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"actionPlugins",
")",
"{",
"$",
"this",
"->",
"setActionPlugins",
"(",
"new",
"Action",
"\\",
"PluginManager",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"actionPlugins",
";",
"}"
] |
Get action plugin manager
@return \Zend\ServiceManager\AbstractPluginManager
|
[
"Get",
"action",
"plugin",
"manager"
] |
7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a
|
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L153-L159
|
21,051 |
SporkCode/Spork
|
src/Mvc/Listener/Limit/LimitStrategy.php
|
LimitStrategy.setLimit
|
public function setLimit($limit)
{
if (is_array($limit)) {
$spec = $limit;
if (!isset($spec['name'])) {
throw new \Exception("Cannot create Limit: Name missing from configuration.");
}
$name = $spec['name'];
$limit = isset($spec['limit']) ? $spec['limit'] : null;
$interval = isset($spec['interval']) ? $spec['interval'] : null;
$actions = isset($spec['actions']) ? $spec['actions'] : array();
$limit = new Limit($name, $limit, $interval);
foreach ($actions as $action) {
if (is_string($action)) {
$action = $this->getActionPlugins()->get($action);
} elseif (is_array($action)) {
if (!isset($action['name'])) {
throw new \Exception('Cannot create Action: Name missing from configuration.');
}
$action = $this->getActionPlugins()->get($action['name'], $action);
}
if (!$action instanceof Action\ActionInterface) {
throw new \Exception("Action must be instance of Spork\Mvc\Listener\Limit\Action\ActionInterface");
}
$limit->addAction($action);
}
}
if (!$limit instanceof Limit) {
throw new \Exception("Limit must be instance of Spork\Mvc\Listener\Limit\Limit");
}
$this->limits[$limit->getName()] = $limit;
}
|
php
|
public function setLimit($limit)
{
if (is_array($limit)) {
$spec = $limit;
if (!isset($spec['name'])) {
throw new \Exception("Cannot create Limit: Name missing from configuration.");
}
$name = $spec['name'];
$limit = isset($spec['limit']) ? $spec['limit'] : null;
$interval = isset($spec['interval']) ? $spec['interval'] : null;
$actions = isset($spec['actions']) ? $spec['actions'] : array();
$limit = new Limit($name, $limit, $interval);
foreach ($actions as $action) {
if (is_string($action)) {
$action = $this->getActionPlugins()->get($action);
} elseif (is_array($action)) {
if (!isset($action['name'])) {
throw new \Exception('Cannot create Action: Name missing from configuration.');
}
$action = $this->getActionPlugins()->get($action['name'], $action);
}
if (!$action instanceof Action\ActionInterface) {
throw new \Exception("Action must be instance of Spork\Mvc\Listener\Limit\Action\ActionInterface");
}
$limit->addAction($action);
}
}
if (!$limit instanceof Limit) {
throw new \Exception("Limit must be instance of Spork\Mvc\Listener\Limit\Limit");
}
$this->limits[$limit->getName()] = $limit;
}
|
[
"public",
"function",
"setLimit",
"(",
"$",
"limit",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"limit",
")",
")",
"{",
"$",
"spec",
"=",
"$",
"limit",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"spec",
"[",
"'name'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Cannot create Limit: Name missing from configuration.\"",
")",
";",
"}",
"$",
"name",
"=",
"$",
"spec",
"[",
"'name'",
"]",
";",
"$",
"limit",
"=",
"isset",
"(",
"$",
"spec",
"[",
"'limit'",
"]",
")",
"?",
"$",
"spec",
"[",
"'limit'",
"]",
":",
"null",
";",
"$",
"interval",
"=",
"isset",
"(",
"$",
"spec",
"[",
"'interval'",
"]",
")",
"?",
"$",
"spec",
"[",
"'interval'",
"]",
":",
"null",
";",
"$",
"actions",
"=",
"isset",
"(",
"$",
"spec",
"[",
"'actions'",
"]",
")",
"?",
"$",
"spec",
"[",
"'actions'",
"]",
":",
"array",
"(",
")",
";",
"$",
"limit",
"=",
"new",
"Limit",
"(",
"$",
"name",
",",
"$",
"limit",
",",
"$",
"interval",
")",
";",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"action",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"action",
")",
")",
"{",
"$",
"action",
"=",
"$",
"this",
"->",
"getActionPlugins",
"(",
")",
"->",
"get",
"(",
"$",
"action",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"action",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"action",
"[",
"'name'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Cannot create Action: Name missing from configuration.'",
")",
";",
"}",
"$",
"action",
"=",
"$",
"this",
"->",
"getActionPlugins",
"(",
")",
"->",
"get",
"(",
"$",
"action",
"[",
"'name'",
"]",
",",
"$",
"action",
")",
";",
"}",
"if",
"(",
"!",
"$",
"action",
"instanceof",
"Action",
"\\",
"ActionInterface",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Action must be instance of Spork\\Mvc\\Listener\\Limit\\Action\\ActionInterface\"",
")",
";",
"}",
"$",
"limit",
"->",
"addAction",
"(",
"$",
"action",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"limit",
"instanceof",
"Limit",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Limit must be instance of Spork\\Mvc\\Listener\\Limit\\Limit\"",
")",
";",
"}",
"$",
"this",
"->",
"limits",
"[",
"$",
"limit",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"limit",
";",
"}"
] |
Set a limit
@param Limit|array $limit
@throws \Exception
|
[
"Set",
"a",
"limit"
] |
7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a
|
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L200-L237
|
21,052 |
SporkCode/Spork
|
src/Mvc/Listener/Limit/LimitStrategy.php
|
LimitStrategy.setStorage
|
public function setStorage($storage)
{
if (is_string($storage)) {
$storage = $this->getStoragePlugins()->get($storage);
} elseif (is_array($storage)) {
if (!isset($storage['name'])) {
throw new \Exception('Invalid Storage configuration: Name required.');
}
$storage = $this->getStoragePlugins()->get($storage['name'], $storage);
}
if (!$storage instanceof Storage\StorageInterface) {
throw new \Exception('Storage must be instance of Spork\Mvc\Listener\Limit\Storage\StorageInterface');
}
$this->storage = $storage;
return $this;
}
|
php
|
public function setStorage($storage)
{
if (is_string($storage)) {
$storage = $this->getStoragePlugins()->get($storage);
} elseif (is_array($storage)) {
if (!isset($storage['name'])) {
throw new \Exception('Invalid Storage configuration: Name required.');
}
$storage = $this->getStoragePlugins()->get($storage['name'], $storage);
}
if (!$storage instanceof Storage\StorageInterface) {
throw new \Exception('Storage must be instance of Spork\Mvc\Listener\Limit\Storage\StorageInterface');
}
$this->storage = $storage;
return $this;
}
|
[
"public",
"function",
"setStorage",
"(",
"$",
"storage",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"storage",
")",
")",
"{",
"$",
"storage",
"=",
"$",
"this",
"->",
"getStoragePlugins",
"(",
")",
"->",
"get",
"(",
"$",
"storage",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"storage",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"storage",
"[",
"'name'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Invalid Storage configuration: Name required.'",
")",
";",
"}",
"$",
"storage",
"=",
"$",
"this",
"->",
"getStoragePlugins",
"(",
")",
"->",
"get",
"(",
"$",
"storage",
"[",
"'name'",
"]",
",",
"$",
"storage",
")",
";",
"}",
"if",
"(",
"!",
"$",
"storage",
"instanceof",
"Storage",
"\\",
"StorageInterface",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Storage must be instance of Spork\\Mvc\\Listener\\Limit\\Storage\\StorageInterface'",
")",
";",
"}",
"$",
"this",
"->",
"storage",
"=",
"$",
"storage",
";",
"return",
"$",
"this",
";",
"}"
] |
Set storage instance
@param StorageInterface|string|array $storage
@return \Spork\Mvc\Listener\Limit\LimitStrategy
@throws \Exception on invalid type
|
[
"Set",
"storage",
"instance"
] |
7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a
|
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L278-L295
|
21,053 |
SporkCode/Spork
|
src/Mvc/Listener/Limit/LimitStrategy.php
|
LimitStrategy.getStoragePlugins
|
public function getStoragePlugins()
{
if (null === $this->storagePlugins) {
$this->setStoragePlugins(new Storage\PluginManager());
}
return $this->storagePlugins;
}
|
php
|
public function getStoragePlugins()
{
if (null === $this->storagePlugins) {
$this->setStoragePlugins(new Storage\PluginManager());
}
return $this->storagePlugins;
}
|
[
"public",
"function",
"getStoragePlugins",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"storagePlugins",
")",
"{",
"$",
"this",
"->",
"setStoragePlugins",
"(",
"new",
"Storage",
"\\",
"PluginManager",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"storagePlugins",
";",
"}"
] |
Get storage plugin manager
@return \Zend\ServiceManager\AbstractPluginManager
|
[
"Get",
"storage",
"plugin",
"manager"
] |
7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a
|
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L302-L308
|
21,054 |
SporkCode/Spork
|
src/Mvc/Listener/Limit/LimitStrategy.php
|
LimitStrategy.initialize
|
public function initialize(MvcEvent $event)
{
$appConfig = $event->getApplication()->getServiceManager()->get('config');
if (array_key_exists(self::CONFIG_KEY, $appConfig)) {
$this->configure($appConfig[self::CONFIG_KEY]);
}
$event->getApplication()
->getServiceManager()
->get('controllerPluginManager')
->setService($this->pluginName, $this);
}
|
php
|
public function initialize(MvcEvent $event)
{
$appConfig = $event->getApplication()->getServiceManager()->get('config');
if (array_key_exists(self::CONFIG_KEY, $appConfig)) {
$this->configure($appConfig[self::CONFIG_KEY]);
}
$event->getApplication()
->getServiceManager()
->get('controllerPluginManager')
->setService($this->pluginName, $this);
}
|
[
"public",
"function",
"initialize",
"(",
"MvcEvent",
"$",
"event",
")",
"{",
"$",
"appConfig",
"=",
"$",
"event",
"->",
"getApplication",
"(",
")",
"->",
"getServiceManager",
"(",
")",
"->",
"get",
"(",
"'config'",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"self",
"::",
"CONFIG_KEY",
",",
"$",
"appConfig",
")",
")",
"{",
"$",
"this",
"->",
"configure",
"(",
"$",
"appConfig",
"[",
"self",
"::",
"CONFIG_KEY",
"]",
")",
";",
"}",
"$",
"event",
"->",
"getApplication",
"(",
")",
"->",
"getServiceManager",
"(",
")",
"->",
"get",
"(",
"'controllerPluginManager'",
")",
"->",
"setService",
"(",
"$",
"this",
"->",
"pluginName",
",",
"$",
"this",
")",
";",
"}"
] |
Configure instance and inject it into controller plugin manager
@param MvcEvent $event
|
[
"Configure",
"instance",
"and",
"inject",
"it",
"into",
"controller",
"plugin",
"manager"
] |
7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a
|
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L337-L348
|
21,055 |
SporkCode/Spork
|
src/Mvc/Listener/Limit/LimitStrategy.php
|
LimitStrategy.check
|
public function check(MvcEvent $event)
{
foreach ($this->limits as $limit) {
if ($this->storage->check($this->remoteAddress->getIpAddress(), $limit)) {
foreach ($limit->getActions() as $action) {
$action($event);
}
}
}
}
|
php
|
public function check(MvcEvent $event)
{
foreach ($this->limits as $limit) {
if ($this->storage->check($this->remoteAddress->getIpAddress(), $limit)) {
foreach ($limit->getActions() as $action) {
$action($event);
}
}
}
}
|
[
"public",
"function",
"check",
"(",
"MvcEvent",
"$",
"event",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"limits",
"as",
"$",
"limit",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"storage",
"->",
"check",
"(",
"$",
"this",
"->",
"remoteAddress",
"->",
"getIpAddress",
"(",
")",
",",
"$",
"limit",
")",
")",
"{",
"foreach",
"(",
"$",
"limit",
"->",
"getActions",
"(",
")",
"as",
"$",
"action",
")",
"{",
"$",
"action",
"(",
"$",
"event",
")",
";",
"}",
"}",
"}",
"}"
] |
Test limits and take actions if they have been exceeded
@param MvcEvent $event
|
[
"Test",
"limits",
"and",
"take",
"actions",
"if",
"they",
"have",
"been",
"exceeded"
] |
7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a
|
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L355-L364
|
21,056 |
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php
|
ezcMailMboxTransport.findFirstMessage
|
private function findFirstMessage()
{
$data = fgets( $this->fh );
fseek( $this->fh, 0 );
if ( substr( $data, 0, 18 ) === 'From MAILER-DAEMON' )
{
return $this->findNextMessage();
}
else
{
return 0;
}
}
|
php
|
private function findFirstMessage()
{
$data = fgets( $this->fh );
fseek( $this->fh, 0 );
if ( substr( $data, 0, 18 ) === 'From MAILER-DAEMON' )
{
return $this->findNextMessage();
}
else
{
return 0;
}
}
|
[
"private",
"function",
"findFirstMessage",
"(",
")",
"{",
"$",
"data",
"=",
"fgets",
"(",
"$",
"this",
"->",
"fh",
")",
";",
"fseek",
"(",
"$",
"this",
"->",
"fh",
",",
"0",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"18",
")",
"===",
"'From MAILER-DAEMON'",
")",
"{",
"return",
"$",
"this",
"->",
"findNextMessage",
"(",
")",
";",
"}",
"else",
"{",
"return",
"0",
";",
"}",
"}"
] |
Finds the position of the first message while skipping a possible header.
Mbox files can contain a header which does not describe an email
message. This method skips over this optional header by checking for a
specific From MAILER-DAEMON header.
@return int
|
[
"Finds",
"the",
"position",
"of",
"the",
"first",
"message",
"while",
"skipping",
"a",
"possible",
"header",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php#L63-L75
|
21,057 |
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php
|
ezcMailMboxTransport.findNextMessage
|
private function findNextMessage()
{
do
{
$data = fgets( $this->fh );
} while ( !feof( $this->fh ) && substr( $data, 0, 5 ) !== "From " );
if ( feof( $this->fh ) )
{
return false;
}
return ftell( $this->fh );
}
|
php
|
private function findNextMessage()
{
do
{
$data = fgets( $this->fh );
} while ( !feof( $this->fh ) && substr( $data, 0, 5 ) !== "From " );
if ( feof( $this->fh ) )
{
return false;
}
return ftell( $this->fh );
}
|
[
"private",
"function",
"findNextMessage",
"(",
")",
"{",
"do",
"{",
"$",
"data",
"=",
"fgets",
"(",
"$",
"this",
"->",
"fh",
")",
";",
"}",
"while",
"(",
"!",
"feof",
"(",
"$",
"this",
"->",
"fh",
")",
"&&",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"5",
")",
"!==",
"\"From \"",
")",
";",
"if",
"(",
"feof",
"(",
"$",
"this",
"->",
"fh",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"ftell",
"(",
"$",
"this",
"->",
"fh",
")",
";",
"}"
] |
Reads through the Mbox file and stops at the next message.
Messages in Mbox files are separated with lines starting with "From "
and this function reads to the next "From " marker. It then returns the
current posistion in the file. If EOF is detected during reading the
function returns false instead.
@return int
|
[
"Reads",
"through",
"the",
"Mbox",
"file",
"and",
"stops",
"at",
"the",
"next",
"message",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php#L87-L99
|
21,058 |
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php
|
ezcMailMboxTransport.listMessages
|
public function listMessages()
{
$messages = array();
fseek( $this->fh, 0 );
// Skip the first mail as this is the mbox header
$position = $this->findFirstMessage();
if ( $position === false )
{
return $messages;
}
// Continue reading through the rest of the mbox
do
{
$position = $this->findNextMessage();
if ( $position !== false )
{
$messages[] = $position;
}
} while ( $position !== false );
return $messages;
}
|
php
|
public function listMessages()
{
$messages = array();
fseek( $this->fh, 0 );
// Skip the first mail as this is the mbox header
$position = $this->findFirstMessage();
if ( $position === false )
{
return $messages;
}
// Continue reading through the rest of the mbox
do
{
$position = $this->findNextMessage();
if ( $position !== false )
{
$messages[] = $position;
}
} while ( $position !== false );
return $messages;
}
|
[
"public",
"function",
"listMessages",
"(",
")",
"{",
"$",
"messages",
"=",
"array",
"(",
")",
";",
"fseek",
"(",
"$",
"this",
"->",
"fh",
",",
"0",
")",
";",
"// Skip the first mail as this is the mbox header",
"$",
"position",
"=",
"$",
"this",
"->",
"findFirstMessage",
"(",
")",
";",
"if",
"(",
"$",
"position",
"===",
"false",
")",
"{",
"return",
"$",
"messages",
";",
"}",
"// Continue reading through the rest of the mbox",
"do",
"{",
"$",
"position",
"=",
"$",
"this",
"->",
"findNextMessage",
"(",
")",
";",
"if",
"(",
"$",
"position",
"!==",
"false",
")",
"{",
"$",
"messages",
"[",
"]",
"=",
"$",
"position",
";",
"}",
"}",
"while",
"(",
"$",
"position",
"!==",
"false",
")",
";",
"return",
"$",
"messages",
";",
"}"
] |
This function reads through the whole mbox and returns starting positions of the messages.
@return array(int=>int)
|
[
"This",
"function",
"reads",
"through",
"the",
"whole",
"mbox",
"and",
"returns",
"starting",
"positions",
"of",
"the",
"messages",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php#L106-L127
|
21,059 |
glynnforrest/active-doctrine
|
src/ActiveDoctrine/Selector/AbstractSelector.php
|
AbstractSelector.getParams
|
public function getParams()
{
//exit early if no types are set
if (empty($this->types)) {
return $this->params;
}
$params = [];
$num_params = count($this->params);
for ($i = 0; $i < $num_params; $i++) {
$value = $this->params[$i];
$column = $this->param_columns[$i];
if (isset($this->types[$column])) {
$params[] = $this->connection->convertToDatabaseValue($value, $this->types[$column]);
continue;
}
$params[] = $value;
}
return $params;
}
|
php
|
public function getParams()
{
//exit early if no types are set
if (empty($this->types)) {
return $this->params;
}
$params = [];
$num_params = count($this->params);
for ($i = 0; $i < $num_params; $i++) {
$value = $this->params[$i];
$column = $this->param_columns[$i];
if (isset($this->types[$column])) {
$params[] = $this->connection->convertToDatabaseValue($value, $this->types[$column]);
continue;
}
$params[] = $value;
}
return $params;
}
|
[
"public",
"function",
"getParams",
"(",
")",
"{",
"//exit early if no types are set",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"types",
")",
")",
"{",
"return",
"$",
"this",
"->",
"params",
";",
"}",
"$",
"params",
"=",
"[",
"]",
";",
"$",
"num_params",
"=",
"count",
"(",
"$",
"this",
"->",
"params",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"num_params",
";",
"$",
"i",
"++",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"params",
"[",
"$",
"i",
"]",
";",
"$",
"column",
"=",
"$",
"this",
"->",
"param_columns",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"types",
"[",
"$",
"column",
"]",
")",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"$",
"this",
"->",
"connection",
"->",
"convertToDatabaseValue",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"types",
"[",
"$",
"column",
"]",
")",
";",
"continue",
";",
"}",
"$",
"params",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"params",
";",
"}"
] |
Get the parameters to be used in the prepared query, converted
to the correct database type.
@return array The parameters
|
[
"Get",
"the",
"parameters",
"to",
"be",
"used",
"in",
"the",
"prepared",
"query",
"converted",
"to",
"the",
"correct",
"database",
"type",
"."
] |
fcf8c434c7df4704966107bf9a95c005a0b37168
|
https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L107-L128
|
21,060 |
glynnforrest/active-doctrine
|
src/ActiveDoctrine/Selector/AbstractSelector.php
|
AbstractSelector.execute
|
public function execute()
{
$stmt = $this->connection->prepare($this->getSQL());
$stmt->execute($this->getParams());
return $this->counting ? (int) $stmt->fetchColumn() : $stmt->fetchAll();
}
|
php
|
public function execute()
{
$stmt = $this->connection->prepare($this->getSQL());
$stmt->execute($this->getParams());
return $this->counting ? (int) $stmt->fetchColumn() : $stmt->fetchAll();
}
|
[
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"connection",
"->",
"prepare",
"(",
"$",
"this",
"->",
"getSQL",
"(",
")",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"$",
"this",
"->",
"getParams",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"counting",
"?",
"(",
"int",
")",
"$",
"stmt",
"->",
"fetchColumn",
"(",
")",
":",
"$",
"stmt",
"->",
"fetchAll",
"(",
")",
";",
"}"
] |
Prepare and execute the current SQL query, returning an array
of the results.
@return array The results
|
[
"Prepare",
"and",
"execute",
"the",
"current",
"SQL",
"query",
"returning",
"an",
"array",
"of",
"the",
"results",
"."
] |
fcf8c434c7df4704966107bf9a95c005a0b37168
|
https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L146-L152
|
21,061 |
glynnforrest/active-doctrine
|
src/ActiveDoctrine/Selector/AbstractSelector.php
|
AbstractSelector.fromConnection
|
public static function fromConnection(Connection $connection, $table, array $types = [])
{
$name = $connection->getDriver()->getName();
switch ($name) {
case 'pdo_mysql':
return new MysqlSelector($connection, $table, $types);
case 'pdo_sqlite':
return new SqliteSelector($connection, $table, $types);
default:
throw new DBALException("Unsupported database type: $name");
}
}
|
php
|
public static function fromConnection(Connection $connection, $table, array $types = [])
{
$name = $connection->getDriver()->getName();
switch ($name) {
case 'pdo_mysql':
return new MysqlSelector($connection, $table, $types);
case 'pdo_sqlite':
return new SqliteSelector($connection, $table, $types);
default:
throw new DBALException("Unsupported database type: $name");
}
}
|
[
"public",
"static",
"function",
"fromConnection",
"(",
"Connection",
"$",
"connection",
",",
"$",
"table",
",",
"array",
"$",
"types",
"=",
"[",
"]",
")",
"{",
"$",
"name",
"=",
"$",
"connection",
"->",
"getDriver",
"(",
")",
"->",
"getName",
"(",
")",
";",
"switch",
"(",
"$",
"name",
")",
"{",
"case",
"'pdo_mysql'",
":",
"return",
"new",
"MysqlSelector",
"(",
"$",
"connection",
",",
"$",
"table",
",",
"$",
"types",
")",
";",
"case",
"'pdo_sqlite'",
":",
"return",
"new",
"SqliteSelector",
"(",
"$",
"connection",
",",
"$",
"table",
",",
"$",
"types",
")",
";",
"default",
":",
"throw",
"new",
"DBALException",
"(",
"\"Unsupported database type: $name\"",
")",
";",
"}",
"}"
] |
Get a vendor-specific selector based on a connection instance.
@param Connection $connection A connection instance
@param string $table The table to select from
@return AbstractSelector A selector instance
@throws DBALException
|
[
"Get",
"a",
"vendor",
"-",
"specific",
"selector",
"based",
"on",
"a",
"connection",
"instance",
"."
] |
fcf8c434c7df4704966107bf9a95c005a0b37168
|
https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L162-L173
|
21,062 |
glynnforrest/active-doctrine
|
src/ActiveDoctrine/Selector/AbstractSelector.php
|
AbstractSelector.addParam
|
protected function addParam($column, $value)
{
if (is_array($value)) {
$this->params = array_merge($this->params, $value);
$this->param_columns = array_merge($this->param_columns, array_fill(0, count($value), $column));
return;
}
$this->params[] = $value;
$this->param_columns[] = $column;
}
|
php
|
protected function addParam($column, $value)
{
if (is_array($value)) {
$this->params = array_merge($this->params, $value);
$this->param_columns = array_merge($this->param_columns, array_fill(0, count($value), $column));
return;
}
$this->params[] = $value;
$this->param_columns[] = $column;
}
|
[
"protected",
"function",
"addParam",
"(",
"$",
"column",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"params",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"params",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"param_columns",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"param_columns",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"value",
")",
",",
"$",
"column",
")",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"params",
"[",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"param_columns",
"[",
"]",
"=",
"$",
"column",
";",
"}"
] |
Add a param to be executed in the query. To ensure the order of
parameters, this should be called during the buildSQL method.
@param string $column
@param mixed $value
|
[
"Add",
"a",
"param",
"to",
"be",
"executed",
"in",
"the",
"query",
".",
"To",
"ensure",
"the",
"order",
"of",
"parameters",
"this",
"should",
"be",
"called",
"during",
"the",
"buildSQL",
"method",
"."
] |
fcf8c434c7df4704966107bf9a95c005a0b37168
|
https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L182-L191
|
21,063 |
glynnforrest/active-doctrine
|
src/ActiveDoctrine/Selector/AbstractSelector.php
|
AbstractSelector.where
|
public function where($column, $expression = null, $value = null)
{
return $this->doWhere(self::AND_WHERE, $column, $expression, $value);
}
|
php
|
public function where($column, $expression = null, $value = null)
{
return $this->doWhere(self::AND_WHERE, $column, $expression, $value);
}
|
[
"public",
"function",
"where",
"(",
"$",
"column",
",",
"$",
"expression",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"doWhere",
"(",
"self",
"::",
"AND_WHERE",
",",
"$",
"column",
",",
"$",
"expression",
",",
"$",
"value",
")",
";",
"}"
] |
Add a 'where' clause to the query.
@param string $column The column name
@param string $expression The comparison, e.g. '=' or '<'
@param string $value The value
|
[
"Add",
"a",
"where",
"clause",
"to",
"the",
"query",
"."
] |
fcf8c434c7df4704966107bf9a95c005a0b37168
|
https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L225-L228
|
21,064 |
glynnforrest/active-doctrine
|
src/ActiveDoctrine/Selector/AbstractSelector.php
|
AbstractSelector.andWhereIn
|
public function andWhereIn($column, array $values)
{
$this->where[] = [self::AND_WHERE_IN, $column, $values];
return $this;
}
|
php
|
public function andWhereIn($column, array $values)
{
$this->where[] = [self::AND_WHERE_IN, $column, $values];
return $this;
}
|
[
"public",
"function",
"andWhereIn",
"(",
"$",
"column",
",",
"array",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"[",
"self",
"::",
"AND_WHERE_IN",
",",
"$",
"column",
",",
"$",
"values",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Add an 'and where in' clause to the query.
@param string $column The column name
@param array $values A list of values to query with
|
[
"Add",
"an",
"and",
"where",
"in",
"clause",
"to",
"the",
"query",
"."
] |
fcf8c434c7df4704966107bf9a95c005a0b37168
|
https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L273-L278
|
21,065 |
glynnforrest/active-doctrine
|
src/ActiveDoctrine/Selector/AbstractSelector.php
|
AbstractSelector.orWhereIn
|
public function orWhereIn($column, array $values)
{
$this->where[] = [self::OR_WHERE_IN, $column, $values];
return $this;
}
|
php
|
public function orWhereIn($column, array $values)
{
$this->where[] = [self::OR_WHERE_IN, $column, $values];
return $this;
}
|
[
"public",
"function",
"orWhereIn",
"(",
"$",
"column",
",",
"array",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"[",
"self",
"::",
"OR_WHERE_IN",
",",
"$",
"column",
",",
"$",
"values",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Add an 'or where in' clause to the query.
@param string $column The column name
@param array $values A list of values to query with
|
[
"Add",
"an",
"or",
"where",
"in",
"clause",
"to",
"the",
"query",
"."
] |
fcf8c434c7df4704966107bf9a95c005a0b37168
|
https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L286-L291
|
21,066 |
superjimpupcake/Pupcake
|
src/Pupcake/Pupcake.php
|
Pupcake.on
|
public function on($event_name, $handler_callback)
{
$event = null;
if (!isset($this->event_queue[$event_name])) {
$event = new Event($event_name);
$this->event_queue[$event_name] = $event;
}
$event = $this->event_queue[$event_name];
$event->setHandlerCallback($handler_callback);
}
|
php
|
public function on($event_name, $handler_callback)
{
$event = null;
if (!isset($this->event_queue[$event_name])) {
$event = new Event($event_name);
$this->event_queue[$event_name] = $event;
}
$event = $this->event_queue[$event_name];
$event->setHandlerCallback($handler_callback);
}
|
[
"public",
"function",
"on",
"(",
"$",
"event_name",
",",
"$",
"handler_callback",
")",
"{",
"$",
"event",
"=",
"null",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"event_queue",
"[",
"$",
"event_name",
"]",
")",
")",
"{",
"$",
"event",
"=",
"new",
"Event",
"(",
"$",
"event_name",
")",
";",
"$",
"this",
"->",
"event_queue",
"[",
"$",
"event_name",
"]",
"=",
"$",
"event",
";",
"}",
"$",
"event",
"=",
"$",
"this",
"->",
"event_queue",
"[",
"$",
"event_name",
"]",
";",
"$",
"event",
"->",
"setHandlerCallback",
"(",
"$",
"handler_callback",
")",
";",
"}"
] |
add a callback to the event, one event, one handler callback
the handler callback is swappable, so later handler callback can override previous handler callback
|
[
"add",
"a",
"callback",
"to",
"the",
"event",
"one",
"event",
"one",
"handler",
"callback",
"the",
"handler",
"callback",
"is",
"swappable",
"so",
"later",
"handler",
"callback",
"can",
"override",
"previous",
"handler",
"callback"
] |
2f962818646e4e1d65f5d008eeb953cb41ebb3e0
|
https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Pupcake.php#L48-L58
|
21,067 |
superjimpupcake/Pupcake
|
src/Pupcake/Pupcake.php
|
Pupcake.trigger
|
public function trigger($event_name, $default_handler_callback = "", $event_properties = array())
{
$event = null;
if (isset($this->event_queue[$event_name])) { //if the event already exists, use the handler callback for the event instead of the default handler callback
$event = $this->event_queue[$event_name];
$event->setProperties($event_properties);
$handler_callback = $event->getHandlerCallback();
if (is_callable($handler_callback)) {
$result = call_user_func_array($handler_callback, array($event));
$event->setHandlerCallbackReturnValue($result);
}
}
else{ //event does not exist yet, use the default handler callback
$event = new Event($event_name);
$event->setProperties($event_properties);
if (is_callable($default_handler_callback)) {
$event->setHandlerCallback($default_handler_callback);
$result = call_user_func_array($default_handler_callback, array($event));
$event->setHandlerCallbackReturnValue($result);
$this->event_queue[$event_name] = $event;
}
}
$result = $event->getHandlerCallbackReturnValue();
return $result;
}
|
php
|
public function trigger($event_name, $default_handler_callback = "", $event_properties = array())
{
$event = null;
if (isset($this->event_queue[$event_name])) { //if the event already exists, use the handler callback for the event instead of the default handler callback
$event = $this->event_queue[$event_name];
$event->setProperties($event_properties);
$handler_callback = $event->getHandlerCallback();
if (is_callable($handler_callback)) {
$result = call_user_func_array($handler_callback, array($event));
$event->setHandlerCallbackReturnValue($result);
}
}
else{ //event does not exist yet, use the default handler callback
$event = new Event($event_name);
$event->setProperties($event_properties);
if (is_callable($default_handler_callback)) {
$event->setHandlerCallback($default_handler_callback);
$result = call_user_func_array($default_handler_callback, array($event));
$event->setHandlerCallbackReturnValue($result);
$this->event_queue[$event_name] = $event;
}
}
$result = $event->getHandlerCallbackReturnValue();
return $result;
}
|
[
"public",
"function",
"trigger",
"(",
"$",
"event_name",
",",
"$",
"default_handler_callback",
"=",
"\"\"",
",",
"$",
"event_properties",
"=",
"array",
"(",
")",
")",
"{",
"$",
"event",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"event_queue",
"[",
"$",
"event_name",
"]",
")",
")",
"{",
"//if the event already exists, use the handler callback for the event instead of the default handler callback",
"$",
"event",
"=",
"$",
"this",
"->",
"event_queue",
"[",
"$",
"event_name",
"]",
";",
"$",
"event",
"->",
"setProperties",
"(",
"$",
"event_properties",
")",
";",
"$",
"handler_callback",
"=",
"$",
"event",
"->",
"getHandlerCallback",
"(",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"handler_callback",
")",
")",
"{",
"$",
"result",
"=",
"call_user_func_array",
"(",
"$",
"handler_callback",
",",
"array",
"(",
"$",
"event",
")",
")",
";",
"$",
"event",
"->",
"setHandlerCallbackReturnValue",
"(",
"$",
"result",
")",
";",
"}",
"}",
"else",
"{",
"//event does not exist yet, use the default handler callback",
"$",
"event",
"=",
"new",
"Event",
"(",
"$",
"event_name",
")",
";",
"$",
"event",
"->",
"setProperties",
"(",
"$",
"event_properties",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"default_handler_callback",
")",
")",
"{",
"$",
"event",
"->",
"setHandlerCallback",
"(",
"$",
"default_handler_callback",
")",
";",
"$",
"result",
"=",
"call_user_func_array",
"(",
"$",
"default_handler_callback",
",",
"array",
"(",
"$",
"event",
")",
")",
";",
"$",
"event",
"->",
"setHandlerCallbackReturnValue",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"event_queue",
"[",
"$",
"event_name",
"]",
"=",
"$",
"event",
";",
"}",
"}",
"$",
"result",
"=",
"$",
"event",
"->",
"getHandlerCallbackReturnValue",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
trigger an event with a default handler callback
|
[
"trigger",
"an",
"event",
"with",
"a",
"default",
"handler",
"callback"
] |
2f962818646e4e1d65f5d008eeb953cb41ebb3e0
|
https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Pupcake.php#L71-L98
|
21,068 |
superjimpupcake/Pupcake
|
src/Pupcake/Pupcake.php
|
Pupcake.usePlugin
|
public function usePlugin($plugin_name, $config = array())
{
if (!isset($this->plugins[$plugin_name])) {
$plugin_name = str_replace(".", "\\", $plugin_name);
//allow plugin name to use . sign
$plugin_class_name = $plugin_name."\Main";
$this->plugins[$plugin_name] = new $plugin_class_name();
$this->plugins[$plugin_name]->setAppInstance($this);
$this->plugins[$plugin_name]->load($config);
}
return $this->plugins[$plugin_name];
}
|
php
|
public function usePlugin($plugin_name, $config = array())
{
if (!isset($this->plugins[$plugin_name])) {
$plugin_name = str_replace(".", "\\", $plugin_name);
//allow plugin name to use . sign
$plugin_class_name = $plugin_name."\Main";
$this->plugins[$plugin_name] = new $plugin_class_name();
$this->plugins[$plugin_name]->setAppInstance($this);
$this->plugins[$plugin_name]->load($config);
}
return $this->plugins[$plugin_name];
}
|
[
"public",
"function",
"usePlugin",
"(",
"$",
"plugin_name",
",",
"$",
"config",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"plugins",
"[",
"$",
"plugin_name",
"]",
")",
")",
"{",
"$",
"plugin_name",
"=",
"str_replace",
"(",
"\".\"",
",",
"\"\\\\\"",
",",
"$",
"plugin_name",
")",
";",
"//allow plugin name to use . sign",
"$",
"plugin_class_name",
"=",
"$",
"plugin_name",
".",
"\"\\Main\"",
";",
"$",
"this",
"->",
"plugins",
"[",
"$",
"plugin_name",
"]",
"=",
"new",
"$",
"plugin_class_name",
"(",
")",
";",
"$",
"this",
"->",
"plugins",
"[",
"$",
"plugin_name",
"]",
"->",
"setAppInstance",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"plugins",
"[",
"$",
"plugin_name",
"]",
"->",
"load",
"(",
"$",
"config",
")",
";",
"}",
"return",
"$",
"this",
"->",
"plugins",
"[",
"$",
"plugin_name",
"]",
";",
"}"
] |
tell the sytem to use a plugin
|
[
"tell",
"the",
"sytem",
"to",
"use",
"a",
"plugin"
] |
2f962818646e4e1d65f5d008eeb953cb41ebb3e0
|
https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Pupcake.php#L103-L114
|
21,069 |
superjimpupcake/Pupcake
|
src/Pupcake/Pupcake.php
|
Pupcake.loadAllPlugins
|
public function loadAllPlugins()
{
if (count($this->plugins) > 0) {
foreach ($this->plugins as $plugin_name => $plugin) {
$event_helpers = $plugin->getEventHelperCallbacks();
if (count($event_helpers) > 0) {
foreach ($event_helpers as $event_name => $callback) {
if (!isset($this->events_helpers[$event_name])) {
$this->events_helpers[$event_name] = array();
}
$this->events_helpers[$event_name][] = $plugin; //add the plugin object to the map
}
}
}
//register all event helpers
if (count($this->events_helpers) > 0) {
foreach ($this->events_helpers as $event_name => $plugin_objs) {
if (count($plugin_objs) > 0) {
$this->plugin_loading = true;
$this->on($event_name, function($event) use ($plugin_objs) {
return call_user_func_array(array($event, "register"), $plugin_objs)->start();
});
$this->plugin_loading = false;
}
}
}
}
}
|
php
|
public function loadAllPlugins()
{
if (count($this->plugins) > 0) {
foreach ($this->plugins as $plugin_name => $plugin) {
$event_helpers = $plugin->getEventHelperCallbacks();
if (count($event_helpers) > 0) {
foreach ($event_helpers as $event_name => $callback) {
if (!isset($this->events_helpers[$event_name])) {
$this->events_helpers[$event_name] = array();
}
$this->events_helpers[$event_name][] = $plugin; //add the plugin object to the map
}
}
}
//register all event helpers
if (count($this->events_helpers) > 0) {
foreach ($this->events_helpers as $event_name => $plugin_objs) {
if (count($plugin_objs) > 0) {
$this->plugin_loading = true;
$this->on($event_name, function($event) use ($plugin_objs) {
return call_user_func_array(array($event, "register"), $plugin_objs)->start();
});
$this->plugin_loading = false;
}
}
}
}
}
|
[
"public",
"function",
"loadAllPlugins",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"plugins",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"plugins",
"as",
"$",
"plugin_name",
"=>",
"$",
"plugin",
")",
"{",
"$",
"event_helpers",
"=",
"$",
"plugin",
"->",
"getEventHelperCallbacks",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"event_helpers",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"event_helpers",
"as",
"$",
"event_name",
"=>",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"events_helpers",
"[",
"$",
"event_name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"events_helpers",
"[",
"$",
"event_name",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"events_helpers",
"[",
"$",
"event_name",
"]",
"[",
"]",
"=",
"$",
"plugin",
";",
"//add the plugin object to the map",
"}",
"}",
"}",
"//register all event helpers",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"events_helpers",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"events_helpers",
"as",
"$",
"event_name",
"=>",
"$",
"plugin_objs",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"plugin_objs",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"plugin_loading",
"=",
"true",
";",
"$",
"this",
"->",
"on",
"(",
"$",
"event_name",
",",
"function",
"(",
"$",
"event",
")",
"use",
"(",
"$",
"plugin_objs",
")",
"{",
"return",
"call_user_func_array",
"(",
"array",
"(",
"$",
"event",
",",
"\"register\"",
")",
",",
"$",
"plugin_objs",
")",
"->",
"start",
"(",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"plugin_loading",
"=",
"false",
";",
"}",
"}",
"}",
"}",
"}"
] |
load all plugins
|
[
"load",
"all",
"plugins"
] |
2f962818646e4e1d65f5d008eeb953cb41ebb3e0
|
https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Pupcake.php#L119-L147
|
21,070 |
antaresproject/notifications
|
src/Repository/Repository.php
|
Repository.findByLocale
|
public function findByLocale($id, $locale)
{
return $this->model->with(['type', 'contents' => function($query) {
$query->with('lang');
}])->where('id', $id)->first();
}
|
php
|
public function findByLocale($id, $locale)
{
return $this->model->with(['type', 'contents' => function($query) {
$query->with('lang');
}])->where('id', $id)->first();
}
|
[
"public",
"function",
"findByLocale",
"(",
"$",
"id",
",",
"$",
"locale",
")",
"{",
"return",
"$",
"this",
"->",
"model",
"->",
"with",
"(",
"[",
"'type'",
",",
"'contents'",
"=>",
"function",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"with",
"(",
"'lang'",
")",
";",
"}",
"]",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"id",
")",
"->",
"first",
"(",
")",
";",
"}"
] |
find model by locale
@param mixed $id
@param String $locale
@return Model
|
[
"find",
"model",
"by",
"locale"
] |
60de743477b7e9cbb51de66da5fd9461adc9dd8a
|
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/Repository.php#L64-L69
|
21,071 |
antaresproject/notifications
|
src/Repository/Repository.php
|
Repository.store
|
public function store(array $data)
{
DB::transaction(function() use($data) {
$model = $this->storeNotificationInstance($data);
foreach ($data['title'] as $langId => $content) {
$model->contents()->save($model->contents()->getModel()->newInstance([
'notification_id' => $model->id,
'lang_id' => $langId,
'title' => $content,
'content' => $data['content'][$langId],
'subject' => $data['subject'][$langId]
]));
}
});
}
|
php
|
public function store(array $data)
{
DB::transaction(function() use($data) {
$model = $this->storeNotificationInstance($data);
foreach ($data['title'] as $langId => $content) {
$model->contents()->save($model->contents()->getModel()->newInstance([
'notification_id' => $model->id,
'lang_id' => $langId,
'title' => $content,
'content' => $data['content'][$langId],
'subject' => $data['subject'][$langId]
]));
}
});
}
|
[
"public",
"function",
"store",
"(",
"array",
"$",
"data",
")",
"{",
"DB",
"::",
"transaction",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"data",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"storeNotificationInstance",
"(",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"data",
"[",
"'title'",
"]",
"as",
"$",
"langId",
"=>",
"$",
"content",
")",
"{",
"$",
"model",
"->",
"contents",
"(",
")",
"->",
"save",
"(",
"$",
"model",
"->",
"contents",
"(",
")",
"->",
"getModel",
"(",
")",
"->",
"newInstance",
"(",
"[",
"'notification_id'",
"=>",
"$",
"model",
"->",
"id",
",",
"'lang_id'",
"=>",
"$",
"langId",
",",
"'title'",
"=>",
"$",
"content",
",",
"'content'",
"=>",
"$",
"data",
"[",
"'content'",
"]",
"[",
"$",
"langId",
"]",
",",
"'subject'",
"=>",
"$",
"data",
"[",
"'subject'",
"]",
"[",
"$",
"langId",
"]",
"]",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] |
stores new notification
@param array $data
|
[
"stores",
"new",
"notification"
] |
60de743477b7e9cbb51de66da5fd9461adc9dd8a
|
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/Repository.php#L118-L132
|
21,072 |
antaresproject/notifications
|
src/Repository/Repository.php
|
Repository.storeNotificationInstance
|
protected function storeNotificationInstance(array $data)
{
is_null($typeId = array_get($data, 'type_id')) ? $typeId = app(NotificationTypes::class)->where('name', array_get($data, 'type'))->first()->id : null;
$model = $this->model->getModel()->newInstance([
'category_id' => array_get($data, 'category'),
'type_id' => $typeId,
'active' => array_get($data, 'active', 1),
'severity_id' => NotificationSeverity::medium()->first()->id,
'event' => config('antares/notifications::default.custom_event')
]);
$model->save();
return $model;
}
|
php
|
protected function storeNotificationInstance(array $data)
{
is_null($typeId = array_get($data, 'type_id')) ? $typeId = app(NotificationTypes::class)->where('name', array_get($data, 'type'))->first()->id : null;
$model = $this->model->getModel()->newInstance([
'category_id' => array_get($data, 'category'),
'type_id' => $typeId,
'active' => array_get($data, 'active', 1),
'severity_id' => NotificationSeverity::medium()->first()->id,
'event' => config('antares/notifications::default.custom_event')
]);
$model->save();
return $model;
}
|
[
"protected",
"function",
"storeNotificationInstance",
"(",
"array",
"$",
"data",
")",
"{",
"is_null",
"(",
"$",
"typeId",
"=",
"array_get",
"(",
"$",
"data",
",",
"'type_id'",
")",
")",
"?",
"$",
"typeId",
"=",
"app",
"(",
"NotificationTypes",
"::",
"class",
")",
"->",
"where",
"(",
"'name'",
",",
"array_get",
"(",
"$",
"data",
",",
"'type'",
")",
")",
"->",
"first",
"(",
")",
"->",
"id",
":",
"null",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"model",
"->",
"getModel",
"(",
")",
"->",
"newInstance",
"(",
"[",
"'category_id'",
"=>",
"array_get",
"(",
"$",
"data",
",",
"'category'",
")",
",",
"'type_id'",
"=>",
"$",
"typeId",
",",
"'active'",
"=>",
"array_get",
"(",
"$",
"data",
",",
"'active'",
",",
"1",
")",
",",
"'severity_id'",
"=>",
"NotificationSeverity",
"::",
"medium",
"(",
")",
"->",
"first",
"(",
")",
"->",
"id",
",",
"'event'",
"=>",
"config",
"(",
"'antares/notifications::default.custom_event'",
")",
"]",
")",
";",
"$",
"model",
"->",
"save",
"(",
")",
";",
"return",
"$",
"model",
";",
"}"
] |
Stores notification instance details
@param array $data
@return Model
|
[
"Stores",
"notification",
"instance",
"details"
] |
60de743477b7e9cbb51de66da5fd9461adc9dd8a
|
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/Repository.php#L140-L153
|
21,073 |
antaresproject/notifications
|
src/Repository/Repository.php
|
Repository.sync
|
public function sync(array $data, array $areas = [])
{
DB::beginTransaction();
try {
$templates = array_get($data, 'templates', []);
$model = $this->storeNotificationInstance($data);
$langs = array_get($data, 'languages', []);
foreach ($langs as $lang) {
$this->processSingle($data, $lang, $model);
}
} catch (Exception $e) {
DB::rollback();
throw $e;
}
DB::commit();
return true;
}
|
php
|
public function sync(array $data, array $areas = [])
{
DB::beginTransaction();
try {
$templates = array_get($data, 'templates', []);
$model = $this->storeNotificationInstance($data);
$langs = array_get($data, 'languages', []);
foreach ($langs as $lang) {
$this->processSingle($data, $lang, $model);
}
} catch (Exception $e) {
DB::rollback();
throw $e;
}
DB::commit();
return true;
}
|
[
"public",
"function",
"sync",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"areas",
"=",
"[",
"]",
")",
"{",
"DB",
"::",
"beginTransaction",
"(",
")",
";",
"try",
"{",
"$",
"templates",
"=",
"array_get",
"(",
"$",
"data",
",",
"'templates'",
",",
"[",
"]",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"storeNotificationInstance",
"(",
"$",
"data",
")",
";",
"$",
"langs",
"=",
"array_get",
"(",
"$",
"data",
",",
"'languages'",
",",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"langs",
"as",
"$",
"lang",
")",
"{",
"$",
"this",
"->",
"processSingle",
"(",
"$",
"data",
",",
"$",
"lang",
",",
"$",
"model",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"DB",
"::",
"rollback",
"(",
")",
";",
"throw",
"$",
"e",
";",
"}",
"DB",
"::",
"commit",
"(",
")",
";",
"return",
"true",
";",
"}"
] |
Stores system notifications
@param array $data
@param array $areas
@throws Exception
|
[
"Stores",
"system",
"notifications"
] |
60de743477b7e9cbb51de66da5fd9461adc9dd8a
|
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/Repository.php#L162-L178
|
21,074 |
antaresproject/notifications
|
src/Repository/Repository.php
|
Repository.processSingle
|
protected function processSingle(array $data, $lang, $model)
{
is_null($view = array_get($data, 'templates.' . $lang->code)) ? $view = array_get($data, 'templates.' . $lang->code) : null;
$content = '';
if (is_null($view)) {
$content = app($data['classname'])->render();
} else {
$path = view($view)->getPath();
if (!file_exists($path)) {
throw new Exception(trans('antares/notifications::messages.notification_view_not_exists', ['path' => $path]));
}
$content = file_get_contents($path);
}
return $model->contents()->save($model->contents()->getModel()->newInstance([
'notification_id' => $model->id,
'lang_id' => $lang->id,
'title' => array_get($data, 'title'),
'subject' => array_get($data, 'subject'),
'content' => $content
]));
}
|
php
|
protected function processSingle(array $data, $lang, $model)
{
is_null($view = array_get($data, 'templates.' . $lang->code)) ? $view = array_get($data, 'templates.' . $lang->code) : null;
$content = '';
if (is_null($view)) {
$content = app($data['classname'])->render();
} else {
$path = view($view)->getPath();
if (!file_exists($path)) {
throw new Exception(trans('antares/notifications::messages.notification_view_not_exists', ['path' => $path]));
}
$content = file_get_contents($path);
}
return $model->contents()->save($model->contents()->getModel()->newInstance([
'notification_id' => $model->id,
'lang_id' => $lang->id,
'title' => array_get($data, 'title'),
'subject' => array_get($data, 'subject'),
'content' => $content
]));
}
|
[
"protected",
"function",
"processSingle",
"(",
"array",
"$",
"data",
",",
"$",
"lang",
",",
"$",
"model",
")",
"{",
"is_null",
"(",
"$",
"view",
"=",
"array_get",
"(",
"$",
"data",
",",
"'templates.'",
".",
"$",
"lang",
"->",
"code",
")",
")",
"?",
"$",
"view",
"=",
"array_get",
"(",
"$",
"data",
",",
"'templates.'",
".",
"$",
"lang",
"->",
"code",
")",
":",
"null",
";",
"$",
"content",
"=",
"''",
";",
"if",
"(",
"is_null",
"(",
"$",
"view",
")",
")",
"{",
"$",
"content",
"=",
"app",
"(",
"$",
"data",
"[",
"'classname'",
"]",
")",
"->",
"render",
"(",
")",
";",
"}",
"else",
"{",
"$",
"path",
"=",
"view",
"(",
"$",
"view",
")",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"trans",
"(",
"'antares/notifications::messages.notification_view_not_exists'",
",",
"[",
"'path'",
"=>",
"$",
"path",
"]",
")",
")",
";",
"}",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"}",
"return",
"$",
"model",
"->",
"contents",
"(",
")",
"->",
"save",
"(",
"$",
"model",
"->",
"contents",
"(",
")",
"->",
"getModel",
"(",
")",
"->",
"newInstance",
"(",
"[",
"'notification_id'",
"=>",
"$",
"model",
"->",
"id",
",",
"'lang_id'",
"=>",
"$",
"lang",
"->",
"id",
",",
"'title'",
"=>",
"array_get",
"(",
"$",
"data",
",",
"'title'",
")",
",",
"'subject'",
"=>",
"array_get",
"(",
"$",
"data",
",",
"'subject'",
")",
",",
"'content'",
"=>",
"$",
"content",
"]",
")",
")",
";",
"}"
] |
Process signle notification
@param array $data
@param \Antares\Translations\Models\Languages $lang
@param Notifications $model
@return boolean
@throws Exception
|
[
"Process",
"signle",
"notification"
] |
60de743477b7e9cbb51de66da5fd9461adc9dd8a
|
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/Repository.php#L189-L210
|
21,075 |
antaresproject/notifications
|
src/Repository/Repository.php
|
Repository.getNotificationContents
|
public function getNotificationContents($type = null)
{
return NotificationContents::select(['title', 'id'])
->whereHas('lang', function($query) {
$query->where('code', locale());
})
->whereHas('notification', function($query) use($type) {
if (is_null($type)) {
$query->whereHas('type', function($subquery) {
$subquery->whereIn('name', ['sms', 'email']);
});
} elseif (is_numeric($type)) {
$query->where('type_id', $type);
} elseif (is_string($type)) {
$query->whereHas('type', function($subquery) use($type) {
$subquery->where('name', $type);
});
}
})->get();
}
|
php
|
public function getNotificationContents($type = null)
{
return NotificationContents::select(['title', 'id'])
->whereHas('lang', function($query) {
$query->where('code', locale());
})
->whereHas('notification', function($query) use($type) {
if (is_null($type)) {
$query->whereHas('type', function($subquery) {
$subquery->whereIn('name', ['sms', 'email']);
});
} elseif (is_numeric($type)) {
$query->where('type_id', $type);
} elseif (is_string($type)) {
$query->whereHas('type', function($subquery) use($type) {
$subquery->where('name', $type);
});
}
})->get();
}
|
[
"public",
"function",
"getNotificationContents",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"return",
"NotificationContents",
"::",
"select",
"(",
"[",
"'title'",
",",
"'id'",
"]",
")",
"->",
"whereHas",
"(",
"'lang'",
",",
"function",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'code'",
",",
"locale",
"(",
")",
")",
";",
"}",
")",
"->",
"whereHas",
"(",
"'notification'",
",",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"type",
")",
")",
"{",
"$",
"query",
"->",
"whereHas",
"(",
"'type'",
",",
"function",
"(",
"$",
"subquery",
")",
"{",
"$",
"subquery",
"->",
"whereIn",
"(",
"'name'",
",",
"[",
"'sms'",
",",
"'email'",
"]",
")",
";",
"}",
")",
";",
"}",
"elseif",
"(",
"is_numeric",
"(",
"$",
"type",
")",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'type_id'",
",",
"$",
"type",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"$",
"query",
"->",
"whereHas",
"(",
"'type'",
",",
"function",
"(",
"$",
"subquery",
")",
"use",
"(",
"$",
"type",
")",
"{",
"$",
"subquery",
"->",
"where",
"(",
"'name'",
",",
"$",
"type",
")",
";",
"}",
")",
";",
"}",
"}",
")",
"->",
"get",
"(",
")",
";",
"}"
] |
Gets notification contents
@param String $type
@return \Antares\Support\Collection
|
[
"Gets",
"notification",
"contents"
] |
60de743477b7e9cbb51de66da5fd9461adc9dd8a
|
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/Repository.php#L228-L247
|
21,076 |
shabbyrobe/amiss
|
src/MapperTrait.php
|
MapperTrait.mapObjectsToRows
|
public function mapObjectsToRows($objects, $meta=null, $context=null)
{
if (!$objects) { return []; }
if (!$meta instanceof Meta) {
$meta = $this->getMeta($meta ?: get_class(current($objects)));
}
$out = [];
foreach ($objects as $key => $object) {
$out[$key] = $this->mapObjectToRow($object, $meta, $context);
}
return $out;
}
|
php
|
public function mapObjectsToRows($objects, $meta=null, $context=null)
{
if (!$objects) { return []; }
if (!$meta instanceof Meta) {
$meta = $this->getMeta($meta ?: get_class(current($objects)));
}
$out = [];
foreach ($objects as $key => $object) {
$out[$key] = $this->mapObjectToRow($object, $meta, $context);
}
return $out;
}
|
[
"public",
"function",
"mapObjectsToRows",
"(",
"$",
"objects",
",",
"$",
"meta",
"=",
"null",
",",
"$",
"context",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"objects",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"meta",
"instanceof",
"Meta",
")",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"getMeta",
"(",
"$",
"meta",
"?",
":",
"get_class",
"(",
"current",
"(",
"$",
"objects",
")",
")",
")",
";",
"}",
"$",
"out",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"objects",
"as",
"$",
"key",
"=>",
"$",
"object",
")",
"{",
"$",
"out",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"mapObjectToRow",
"(",
"$",
"object",
",",
"$",
"meta",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] |
Get row values from a list of objects
This will almost always have the exact same body. This is provided for
convenience, commented out below the definition.
@param $meta Amiss\Meta or string used to call getMeta()
|
[
"Get",
"row",
"values",
"from",
"a",
"list",
"of",
"objects"
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/MapperTrait.php#L86-L99
|
21,077 |
shabbyrobe/amiss
|
src/MapperTrait.php
|
MapperTrait.createObject
|
public function createObject($meta, $mapped, $args=null)
{
if (!$meta instanceof Meta) {
$meta = $this->getMeta($meta);
}
$object = null;
$args = $args ? array_values($args) : [];
$argc = $args ? count($args) : 0;
if ($meta->constructorArgs) {
$actualArgs = [];
foreach ($meta->constructorArgs as $argInfo) {
$type = $argInfo[0];
$id = isset($argInfo[1]) ? $argInfo[1] : null;
switch ($type) {
case 'property':
$actualArgs[] = isset($mapped->{$id}) ? $mapped->{$id} : null;
unset($mapped->{$id});
break;
case 'arg':
if ($id >= $argc) {
throw new Exception("Class {$meta->class} requires argument at index $id - please use Select->\$args");
}
$actualArgs[] = $args[$id];
break;
case 'all': $actualArgs[] = $mapped; break;
// NO! leaky abstraction.
// case 'meta': $actualArgs[] = $meta; break;
default:
throw new Exception("Invalid constructor argument type {$type}");
}
}
$args = $actualArgs;
}
if ($meta->constructor == '__construct') {
if ($args) {
$rc = new \ReflectionClass($meta->class);
$object = $rc->newInstanceArgs($args);
}
else {
$cname = $meta->class;
$object = new $cname;
}
}
else {
$rc = new \ReflectionClass($meta->class);
$method = $rc->getMethod($meta->constructor);
$object = $method->invokeArgs(null, $args ?: []);
}
if (!$object instanceof $meta->class) {
throw new Exception(
"Constructor {$meta->constructor} did not return instance of {$meta->class}"
);
}
return $object;
}
|
php
|
public function createObject($meta, $mapped, $args=null)
{
if (!$meta instanceof Meta) {
$meta = $this->getMeta($meta);
}
$object = null;
$args = $args ? array_values($args) : [];
$argc = $args ? count($args) : 0;
if ($meta->constructorArgs) {
$actualArgs = [];
foreach ($meta->constructorArgs as $argInfo) {
$type = $argInfo[0];
$id = isset($argInfo[1]) ? $argInfo[1] : null;
switch ($type) {
case 'property':
$actualArgs[] = isset($mapped->{$id}) ? $mapped->{$id} : null;
unset($mapped->{$id});
break;
case 'arg':
if ($id >= $argc) {
throw new Exception("Class {$meta->class} requires argument at index $id - please use Select->\$args");
}
$actualArgs[] = $args[$id];
break;
case 'all': $actualArgs[] = $mapped; break;
// NO! leaky abstraction.
// case 'meta': $actualArgs[] = $meta; break;
default:
throw new Exception("Invalid constructor argument type {$type}");
}
}
$args = $actualArgs;
}
if ($meta->constructor == '__construct') {
if ($args) {
$rc = new \ReflectionClass($meta->class);
$object = $rc->newInstanceArgs($args);
}
else {
$cname = $meta->class;
$object = new $cname;
}
}
else {
$rc = new \ReflectionClass($meta->class);
$method = $rc->getMethod($meta->constructor);
$object = $method->invokeArgs(null, $args ?: []);
}
if (!$object instanceof $meta->class) {
throw new Exception(
"Constructor {$meta->constructor} did not return instance of {$meta->class}"
);
}
return $object;
}
|
[
"public",
"function",
"createObject",
"(",
"$",
"meta",
",",
"$",
"mapped",
",",
"$",
"args",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"meta",
"instanceof",
"Meta",
")",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"getMeta",
"(",
"$",
"meta",
")",
";",
"}",
"$",
"object",
"=",
"null",
";",
"$",
"args",
"=",
"$",
"args",
"?",
"array_values",
"(",
"$",
"args",
")",
":",
"[",
"]",
";",
"$",
"argc",
"=",
"$",
"args",
"?",
"count",
"(",
"$",
"args",
")",
":",
"0",
";",
"if",
"(",
"$",
"meta",
"->",
"constructorArgs",
")",
"{",
"$",
"actualArgs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"meta",
"->",
"constructorArgs",
"as",
"$",
"argInfo",
")",
"{",
"$",
"type",
"=",
"$",
"argInfo",
"[",
"0",
"]",
";",
"$",
"id",
"=",
"isset",
"(",
"$",
"argInfo",
"[",
"1",
"]",
")",
"?",
"$",
"argInfo",
"[",
"1",
"]",
":",
"null",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'property'",
":",
"$",
"actualArgs",
"[",
"]",
"=",
"isset",
"(",
"$",
"mapped",
"->",
"{",
"$",
"id",
"}",
")",
"?",
"$",
"mapped",
"->",
"{",
"$",
"id",
"}",
":",
"null",
";",
"unset",
"(",
"$",
"mapped",
"->",
"{",
"$",
"id",
"}",
")",
";",
"break",
";",
"case",
"'arg'",
":",
"if",
"(",
"$",
"id",
">=",
"$",
"argc",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Class {$meta->class} requires argument at index $id - please use Select->\\$args\"",
")",
";",
"}",
"$",
"actualArgs",
"[",
"]",
"=",
"$",
"args",
"[",
"$",
"id",
"]",
";",
"break",
";",
"case",
"'all'",
":",
"$",
"actualArgs",
"[",
"]",
"=",
"$",
"mapped",
";",
"break",
";",
"// NO! leaky abstraction.",
"// case 'meta': $actualArgs[] = $meta; break;",
"default",
":",
"throw",
"new",
"Exception",
"(",
"\"Invalid constructor argument type {$type}\"",
")",
";",
"}",
"}",
"$",
"args",
"=",
"$",
"actualArgs",
";",
"}",
"if",
"(",
"$",
"meta",
"->",
"constructor",
"==",
"'__construct'",
")",
"{",
"if",
"(",
"$",
"args",
")",
"{",
"$",
"rc",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"meta",
"->",
"class",
")",
";",
"$",
"object",
"=",
"$",
"rc",
"->",
"newInstanceArgs",
"(",
"$",
"args",
")",
";",
"}",
"else",
"{",
"$",
"cname",
"=",
"$",
"meta",
"->",
"class",
";",
"$",
"object",
"=",
"new",
"$",
"cname",
";",
"}",
"}",
"else",
"{",
"$",
"rc",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"meta",
"->",
"class",
")",
";",
"$",
"method",
"=",
"$",
"rc",
"->",
"getMethod",
"(",
"$",
"meta",
"->",
"constructor",
")",
";",
"$",
"object",
"=",
"$",
"method",
"->",
"invokeArgs",
"(",
"null",
",",
"$",
"args",
"?",
":",
"[",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"object",
"instanceof",
"$",
"meta",
"->",
"class",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Constructor {$meta->constructor} did not return instance of {$meta->class}\"",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] |
The row is made available to this function, but this is so it can be
used to construct the object, not to populate it. Feel free to ignore it,
it will be passed to populateObject as well.
@param $meta \Amiss\Meta The metadata to use to create the object
@param array $mapped Input values after mapping to property names and type handling
@param array $args Class constructor arguments
@return void
|
[
"The",
"row",
"is",
"made",
"available",
"to",
"this",
"function",
"but",
"this",
"is",
"so",
"it",
"can",
"be",
"used",
"to",
"construct",
"the",
"object",
"not",
"to",
"populate",
"it",
".",
"Feel",
"free",
"to",
"ignore",
"it",
"it",
"will",
"be",
"passed",
"to",
"populateObject",
"as",
"well",
"."
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/MapperTrait.php#L111-L175
|
21,078 |
shabbyrobe/amiss
|
src/MapperTrait.php
|
MapperTrait.populateObject
|
public function populateObject($object, \stdClass $mapped, $meta=null)
{
if (!$meta instanceof Meta) {
$meta = $this->getMeta($meta ?: get_class($object));
if (!$meta) {
throw new \InvalidArgumentException();
}
}
$properties = $meta->getProperties();
foreach ($mapped as $prop=>$value) {
if (!isset($properties[$prop])) {
throw new \UnexpectedValueException("Property $prop does not exist on class {$meta->class}");
}
$property = $properties[$prop];
if (!isset($property['setter'])) {
$object->{$prop} = $value;
}
else {
// false setter means read only
if ($property['setter'] !== false) {
call_user_func(array($object, $property['setter']), $value);
}
}
}
}
|
php
|
public function populateObject($object, \stdClass $mapped, $meta=null)
{
if (!$meta instanceof Meta) {
$meta = $this->getMeta($meta ?: get_class($object));
if (!$meta) {
throw new \InvalidArgumentException();
}
}
$properties = $meta->getProperties();
foreach ($mapped as $prop=>$value) {
if (!isset($properties[$prop])) {
throw new \UnexpectedValueException("Property $prop does not exist on class {$meta->class}");
}
$property = $properties[$prop];
if (!isset($property['setter'])) {
$object->{$prop} = $value;
}
else {
// false setter means read only
if ($property['setter'] !== false) {
call_user_func(array($object, $property['setter']), $value);
}
}
}
}
|
[
"public",
"function",
"populateObject",
"(",
"$",
"object",
",",
"\\",
"stdClass",
"$",
"mapped",
",",
"$",
"meta",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"meta",
"instanceof",
"Meta",
")",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"getMeta",
"(",
"$",
"meta",
"?",
":",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"if",
"(",
"!",
"$",
"meta",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"}",
"$",
"properties",
"=",
"$",
"meta",
"->",
"getProperties",
"(",
")",
";",
"foreach",
"(",
"$",
"mapped",
"as",
"$",
"prop",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"properties",
"[",
"$",
"prop",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"Property $prop does not exist on class {$meta->class}\"",
")",
";",
"}",
"$",
"property",
"=",
"$",
"properties",
"[",
"$",
"prop",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"property",
"[",
"'setter'",
"]",
")",
")",
"{",
"$",
"object",
"->",
"{",
"$",
"prop",
"}",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"// false setter means read only",
"if",
"(",
"$",
"property",
"[",
"'setter'",
"]",
"!==",
"false",
")",
"{",
"call_user_func",
"(",
"array",
"(",
"$",
"object",
",",
"$",
"property",
"[",
"'setter'",
"]",
")",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"}"
] |
Populate an object with row values
@param $meta Amiss\Meta|string
@param object $object
@param array $mapped Input after mapping to property names and type handling
@return void
|
[
"Populate",
"an",
"object",
"with",
"row",
"values"
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/MapperTrait.php#L185-L210
|
21,079 |
tttptd/laravel-responder
|
src/Http/ErrorResponseBuilder.php
|
ErrorResponseBuilder.addData
|
public function addData(array $data):ErrorResponseBuilder
{
$this->data = array_merge($this->data, $data);
return $this;
}
|
php
|
public function addData(array $data):ErrorResponseBuilder
{
$this->data = array_merge($this->data, $data);
return $this;
}
|
[
"public",
"function",
"addData",
"(",
"array",
"$",
"data",
")",
":",
"ErrorResponseBuilder",
"{",
"$",
"this",
"->",
"data",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"data",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add additonal data appended to the error object.
@param array $data
@return self
|
[
"Add",
"additonal",
"data",
"appended",
"to",
"the",
"error",
"object",
"."
] |
0e4a32701f0de755c1f1af458045829e1bd6caf6
|
https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Http/ErrorResponseBuilder.php#L78-L83
|
21,080 |
tttptd/laravel-responder
|
src/Http/ErrorResponseBuilder.php
|
ErrorResponseBuilder.setError
|
public function setError($errorCode = null, $message = null):ErrorResponseBuilder
{
$this->errorCode = $errorCode;
if (is_array($message)) {
$this->parameters = $message;
} else {
$this->message = $message;
}
return $this;
}
|
php
|
public function setError($errorCode = null, $message = null):ErrorResponseBuilder
{
$this->errorCode = $errorCode;
if (is_array($message)) {
$this->parameters = $message;
} else {
$this->message = $message;
}
return $this;
}
|
[
"public",
"function",
"setError",
"(",
"$",
"errorCode",
"=",
"null",
",",
"$",
"message",
"=",
"null",
")",
":",
"ErrorResponseBuilder",
"{",
"$",
"this",
"->",
"errorCode",
"=",
"$",
"errorCode",
";",
"if",
"(",
"is_array",
"(",
"$",
"message",
")",
")",
"{",
"$",
"this",
"->",
"parameters",
"=",
"$",
"message",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"message",
"=",
"$",
"message",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set the error code and optionally an error message.
@param mixed|null $errorCode
@param string|array|null $message
@return self
|
[
"Set",
"the",
"error",
"code",
"and",
"optionally",
"an",
"error",
"message",
"."
] |
0e4a32701f0de755c1f1af458045829e1bd6caf6
|
https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Http/ErrorResponseBuilder.php#L92-L103
|
21,081 |
tttptd/laravel-responder
|
src/Http/ErrorResponseBuilder.php
|
ErrorResponseBuilder.setStatus
|
public function setStatus(int $statusCode):ResponseBuilder
{
if ($statusCode < 400 || $statusCode >= 600) {
throw new InvalidArgumentException("{$statusCode} is not a valid error HTTP status code.");
}
return parent::setStatus($statusCode);
}
|
php
|
public function setStatus(int $statusCode):ResponseBuilder
{
if ($statusCode < 400 || $statusCode >= 600) {
throw new InvalidArgumentException("{$statusCode} is not a valid error HTTP status code.");
}
return parent::setStatus($statusCode);
}
|
[
"public",
"function",
"setStatus",
"(",
"int",
"$",
"statusCode",
")",
":",
"ResponseBuilder",
"{",
"if",
"(",
"$",
"statusCode",
"<",
"400",
"||",
"$",
"statusCode",
">=",
"600",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"{$statusCode} is not a valid error HTTP status code.\"",
")",
";",
"}",
"return",
"parent",
"::",
"setStatus",
"(",
"$",
"statusCode",
")",
";",
"}"
] |
Set the HTTP status code for the response.
@param int $statusCode
@return self
@throws \InvalidArgumentException
|
[
"Set",
"the",
"HTTP",
"status",
"code",
"for",
"the",
"response",
"."
] |
0e4a32701f0de755c1f1af458045829e1bd6caf6
|
https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Http/ErrorResponseBuilder.php#L112-L118
|
21,082 |
tttptd/laravel-responder
|
src/Http/ErrorResponseBuilder.php
|
ErrorResponseBuilder.buildErrorData
|
protected function buildErrorData()
{
if (is_null($this->errorCode)) {
return null;
}
$data = [
'code' => $this->errorCode,
'message' => $this->message ?: $this->resolveMessage()
];
return array_merge($data, $this->data);
}
|
php
|
protected function buildErrorData()
{
if (is_null($this->errorCode)) {
return null;
}
$data = [
'code' => $this->errorCode,
'message' => $this->message ?: $this->resolveMessage()
];
return array_merge($data, $this->data);
}
|
[
"protected",
"function",
"buildErrorData",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"errorCode",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"data",
"=",
"[",
"'code'",
"=>",
"$",
"this",
"->",
"errorCode",
",",
"'message'",
"=>",
"$",
"this",
"->",
"message",
"?",
":",
"$",
"this",
"->",
"resolveMessage",
"(",
")",
"]",
";",
"return",
"array_merge",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"data",
")",
";",
"}"
] |
Build the error object of the serialized response data.
@return array|null
|
[
"Build",
"the",
"error",
"object",
"of",
"the",
"serialized",
"response",
"data",
"."
] |
0e4a32701f0de755c1f1af458045829e1bd6caf6
|
https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Http/ErrorResponseBuilder.php#L147-L159
|
21,083 |
tttptd/laravel-responder
|
src/Http/ErrorResponseBuilder.php
|
ErrorResponseBuilder.resolveMessage
|
protected function resolveMessage()
{
if (! $this->translator->has($code = "errors.$this->errorCode")) {
return null;
}
return $this->translator->trans($code, $this->parameters);
}
|
php
|
protected function resolveMessage()
{
if (! $this->translator->has($code = "errors.$this->errorCode")) {
return null;
}
return $this->translator->trans($code, $this->parameters);
}
|
[
"protected",
"function",
"resolveMessage",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"translator",
"->",
"has",
"(",
"$",
"code",
"=",
"\"errors.$this->errorCode\"",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"$",
"code",
",",
"$",
"this",
"->",
"parameters",
")",
";",
"}"
] |
Resolve an error message from the translator.
@return string|null
|
[
"Resolve",
"an",
"error",
"message",
"from",
"the",
"translator",
"."
] |
0e4a32701f0de755c1f1af458045829e1bd6caf6
|
https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Http/ErrorResponseBuilder.php#L166-L173
|
21,084 |
caffeinated/beverage
|
src/Traits/BindIlluminate.php
|
BindIlluminate.ensureIlluminateBase
|
public function ensureIlluminateBase(Container $app = null)
{
if (! $app->bound('events')) {
$app->singleton('events', $this->illuminateClasses['events']);
$app['events']->fire('booting');
}
if (! $app->bound('files')) {
$app->bindIf('files', $this->illuminateClasses['files']);
}
}
|
php
|
public function ensureIlluminateBase(Container $app = null)
{
if (! $app->bound('events')) {
$app->singleton('events', $this->illuminateClasses['events']);
$app['events']->fire('booting');
}
if (! $app->bound('files')) {
$app->bindIf('files', $this->illuminateClasses['files']);
}
}
|
[
"public",
"function",
"ensureIlluminateBase",
"(",
"Container",
"$",
"app",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"app",
"->",
"bound",
"(",
"'events'",
")",
")",
"{",
"$",
"app",
"->",
"singleton",
"(",
"'events'",
",",
"$",
"this",
"->",
"illuminateClasses",
"[",
"'events'",
"]",
")",
";",
"$",
"app",
"[",
"'events'",
"]",
"->",
"fire",
"(",
"'booting'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"app",
"->",
"bound",
"(",
"'files'",
")",
")",
"{",
"$",
"app",
"->",
"bindIf",
"(",
"'files'",
",",
"$",
"this",
"->",
"illuminateClasses",
"[",
"'files'",
"]",
")",
";",
"}",
"}"
] |
Ensure the base event and file bindings are present. Required for binding anything else.
@param Container $app
@return void
|
[
"Ensure",
"the",
"base",
"event",
"and",
"file",
"bindings",
"are",
"present",
".",
"Required",
"for",
"binding",
"anything",
"else",
"."
] |
c7d612a1d3bc1baddc97fec60ab17224550efaf3
|
https://github.com/caffeinated/beverage/blob/c7d612a1d3bc1baddc97fec60ab17224550efaf3/src/Traits/BindIlluminate.php#L68-L78
|
21,085 |
caffeinated/beverage
|
src/Traits/BindIlluminate.php
|
BindIlluminate.bindIlluminateCore
|
public function bindIlluminateCore(Container $app = null)
{
if (! $app) {
$app = new Container();
}
$this->ensureIlluminateBase($app);
// Core classes
$app->bindIf('url', $this->illuminateClasses[ 'url' ]);
// Session and request
$app->bindIf('session.manager', function ($app) {
return new SessionManager($app);
});
$app->bindIf('session', function ($app) {
return $app['session.manager']->driver('array');
}, true);
$app->bindIf('request', function ($app) {
$request = Request::createFromGlobals();
if (method_exists($request, 'setSessionStore')) {
$request->setSessionStore($app['session']);
} else {
$request->setSession($app['session']);
}
return $request;
}, true);
// Config
$app->bindIf('path.config', function ($app) {
return $this->illuminateConfigPath;
}, true);
$app->bindIf('config', function ($app) {
$config = new Repository;
$this->loadIlluminateConfig($app, $config);
return $config;
}, true);
// Localization
$app->bindIf('translation.loader', function ($app) {
return new FileLoader($app['files'], 'src/config');
});
$app->bindIf('translator', function ($app) {
$loader = new FileLoader($app['files'], 'lang');
return new Translator($loader, 'en');
});
return $app;
}
|
php
|
public function bindIlluminateCore(Container $app = null)
{
if (! $app) {
$app = new Container();
}
$this->ensureIlluminateBase($app);
// Core classes
$app->bindIf('url', $this->illuminateClasses[ 'url' ]);
// Session and request
$app->bindIf('session.manager', function ($app) {
return new SessionManager($app);
});
$app->bindIf('session', function ($app) {
return $app['session.manager']->driver('array');
}, true);
$app->bindIf('request', function ($app) {
$request = Request::createFromGlobals();
if (method_exists($request, 'setSessionStore')) {
$request->setSessionStore($app['session']);
} else {
$request->setSession($app['session']);
}
return $request;
}, true);
// Config
$app->bindIf('path.config', function ($app) {
return $this->illuminateConfigPath;
}, true);
$app->bindIf('config', function ($app) {
$config = new Repository;
$this->loadIlluminateConfig($app, $config);
return $config;
}, true);
// Localization
$app->bindIf('translation.loader', function ($app) {
return new FileLoader($app['files'], 'src/config');
});
$app->bindIf('translator', function ($app) {
$loader = new FileLoader($app['files'], 'lang');
return new Translator($loader, 'en');
});
return $app;
}
|
[
"public",
"function",
"bindIlluminateCore",
"(",
"Container",
"$",
"app",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"app",
")",
"{",
"$",
"app",
"=",
"new",
"Container",
"(",
")",
";",
"}",
"$",
"this",
"->",
"ensureIlluminateBase",
"(",
"$",
"app",
")",
";",
"// Core classes",
"$",
"app",
"->",
"bindIf",
"(",
"'url'",
",",
"$",
"this",
"->",
"illuminateClasses",
"[",
"'url'",
"]",
")",
";",
"// Session and request",
"$",
"app",
"->",
"bindIf",
"(",
"'session.manager'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"SessionManager",
"(",
"$",
"app",
")",
";",
"}",
")",
";",
"$",
"app",
"->",
"bindIf",
"(",
"'session'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"[",
"'session.manager'",
"]",
"->",
"driver",
"(",
"'array'",
")",
";",
"}",
",",
"true",
")",
";",
"$",
"app",
"->",
"bindIf",
"(",
"'request'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"request",
"=",
"Request",
"::",
"createFromGlobals",
"(",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"request",
",",
"'setSessionStore'",
")",
")",
"{",
"$",
"request",
"->",
"setSessionStore",
"(",
"$",
"app",
"[",
"'session'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"request",
"->",
"setSession",
"(",
"$",
"app",
"[",
"'session'",
"]",
")",
";",
"}",
"return",
"$",
"request",
";",
"}",
",",
"true",
")",
";",
"// Config",
"$",
"app",
"->",
"bindIf",
"(",
"'path.config'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"this",
"->",
"illuminateConfigPath",
";",
"}",
",",
"true",
")",
";",
"$",
"app",
"->",
"bindIf",
"(",
"'config'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"config",
"=",
"new",
"Repository",
";",
"$",
"this",
"->",
"loadIlluminateConfig",
"(",
"$",
"app",
",",
"$",
"config",
")",
";",
"return",
"$",
"config",
";",
"}",
",",
"true",
")",
";",
"// Localization",
"$",
"app",
"->",
"bindIf",
"(",
"'translation.loader'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"FileLoader",
"(",
"$",
"app",
"[",
"'files'",
"]",
",",
"'src/config'",
")",
";",
"}",
")",
";",
"$",
"app",
"->",
"bindIf",
"(",
"'translator'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"loader",
"=",
"new",
"FileLoader",
"(",
"$",
"app",
"[",
"'files'",
"]",
",",
"'lang'",
")",
";",
"return",
"new",
"Translator",
"(",
"$",
"loader",
",",
"'en'",
")",
";",
"}",
")",
";",
"return",
"$",
"app",
";",
"}"
] |
Bind the core classes to the Container
@param Container $app
@return Container
|
[
"Bind",
"the",
"core",
"classes",
"to",
"the",
"Container"
] |
c7d612a1d3bc1baddc97fec60ab17224550efaf3
|
https://github.com/caffeinated/beverage/blob/c7d612a1d3bc1baddc97fec60ab17224550efaf3/src/Traits/BindIlluminate.php#L86-L142
|
21,086 |
caffeinated/beverage
|
src/Traits/BindIlluminate.php
|
BindIlluminate.loadIlluminateConfig
|
protected function loadIlluminateConfig(Container $app, Repository $config)
{
foreach ($this->getIlluminateConfig($app) as $key => $path) {
$config->set($key, require $path);
}
}
|
php
|
protected function loadIlluminateConfig(Container $app, Repository $config)
{
foreach ($this->getIlluminateConfig($app) as $key => $path) {
$config->set($key, require $path);
}
}
|
[
"protected",
"function",
"loadIlluminateConfig",
"(",
"Container",
"$",
"app",
",",
"Repository",
"$",
"config",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getIlluminateConfig",
"(",
"$",
"app",
")",
"as",
"$",
"key",
"=>",
"$",
"path",
")",
"{",
"$",
"config",
"->",
"set",
"(",
"$",
"key",
",",
"require",
"$",
"path",
")",
";",
"}",
"}"
] |
Load the configuration items from all config files.
@param Container $app
@param Repository $config
@return void
|
[
"Load",
"the",
"configuration",
"items",
"from",
"all",
"config",
"files",
"."
] |
c7d612a1d3bc1baddc97fec60ab17224550efaf3
|
https://github.com/caffeinated/beverage/blob/c7d612a1d3bc1baddc97fec60ab17224550efaf3/src/Traits/BindIlluminate.php#L204-L209
|
21,087 |
caffeinated/beverage
|
src/Traits/BindIlluminate.php
|
BindIlluminate.getIlluminateConfig
|
protected function getIlluminateConfig(Container $app)
{
$files = array();
foreach (Finder::create()->files()->name('*.php')->in($app['path.config']) as $file) {
$files[basename($file->getRealPath(), '.php')] = $file->getRealPath();
}
return $files;
}
|
php
|
protected function getIlluminateConfig(Container $app)
{
$files = array();
foreach (Finder::create()->files()->name('*.php')->in($app['path.config']) as $file) {
$files[basename($file->getRealPath(), '.php')] = $file->getRealPath();
}
return $files;
}
|
[
"protected",
"function",
"getIlluminateConfig",
"(",
"Container",
"$",
"app",
")",
"{",
"$",
"files",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"Finder",
"::",
"create",
"(",
")",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"'*.php'",
")",
"->",
"in",
"(",
"$",
"app",
"[",
"'path.config'",
"]",
")",
"as",
"$",
"file",
")",
"{",
"$",
"files",
"[",
"basename",
"(",
"$",
"file",
"->",
"getRealPath",
"(",
")",
",",
"'.php'",
")",
"]",
"=",
"$",
"file",
"->",
"getRealPath",
"(",
")",
";",
"}",
"return",
"$",
"files",
";",
"}"
] |
Get all configuration files from the application.
@param Container $app
@return array
|
[
"Get",
"all",
"configuration",
"files",
"from",
"the",
"application",
"."
] |
c7d612a1d3bc1baddc97fec60ab17224550efaf3
|
https://github.com/caffeinated/beverage/blob/c7d612a1d3bc1baddc97fec60ab17224550efaf3/src/Traits/BindIlluminate.php#L217-L226
|
21,088 |
neat-php/database
|
classes/Table.php
|
Table.findOne
|
public function findOne($conditions, string $orderBy = null): Result
{
$query = $this->query()
->where($conditions)
->limit(1);
if ($orderBy) {
$query->orderBy($orderBy);
}
return $query->query();
}
|
php
|
public function findOne($conditions, string $orderBy = null): Result
{
$query = $this->query()
->where($conditions)
->limit(1);
if ($orderBy) {
$query->orderBy($orderBy);
}
return $query->query();
}
|
[
"public",
"function",
"findOne",
"(",
"$",
"conditions",
",",
"string",
"$",
"orderBy",
"=",
"null",
")",
":",
"Result",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"query",
"(",
")",
"->",
"where",
"(",
"$",
"conditions",
")",
"->",
"limit",
"(",
"1",
")",
";",
"if",
"(",
"$",
"orderBy",
")",
"{",
"$",
"query",
"->",
"orderBy",
"(",
"$",
"orderBy",
")",
";",
"}",
"return",
"$",
"query",
"->",
"query",
"(",
")",
";",
"}"
] |
Builds the query for the given conditions and executes it
Will return an result with 1 or 0 rows
@param array|string $conditions
@param string|null $orderBy
@return Result
|
[
"Builds",
"the",
"query",
"for",
"the",
"given",
"conditions",
"and",
"executes",
"it",
"Will",
"return",
"an",
"result",
"with",
"1",
"or",
"0",
"rows"
] |
7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff
|
https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Table.php#L77-L88
|
21,089 |
neat-php/database
|
classes/Table.php
|
Table.validateIdentifier
|
public function validateIdentifier($id)
{
$printed = print_r($id, true);
if (count($this->keys) > 1 && !is_array($id)) {
throw new \RuntimeException("Entity $this->name has a composed key, finding by id requires an array, given: $printed");
}
if (count($this->keys) !== count($id)) {
$keys = print_r($this->keys, true);
throw new \RuntimeException("Entity $this->name requires the following keys: $keys, given: $printed");
}
}
|
php
|
public function validateIdentifier($id)
{
$printed = print_r($id, true);
if (count($this->keys) > 1 && !is_array($id)) {
throw new \RuntimeException("Entity $this->name has a composed key, finding by id requires an array, given: $printed");
}
if (count($this->keys) !== count($id)) {
$keys = print_r($this->keys, true);
throw new \RuntimeException("Entity $this->name requires the following keys: $keys, given: $printed");
}
}
|
[
"public",
"function",
"validateIdentifier",
"(",
"$",
"id",
")",
"{",
"$",
"printed",
"=",
"print_r",
"(",
"$",
"id",
",",
"true",
")",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"keys",
")",
">",
"1",
"&&",
"!",
"is_array",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Entity $this->name has a composed key, finding by id requires an array, given: $printed\"",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"keys",
")",
"!==",
"count",
"(",
"$",
"id",
")",
")",
"{",
"$",
"keys",
"=",
"print_r",
"(",
"$",
"this",
"->",
"keys",
",",
"true",
")",
";",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Entity $this->name requires the following keys: $keys, given: $printed\"",
")",
";",
"}",
"}"
] |
Validates the identifier to prevent unexpected behaviour
@param int|string|array $id
|
[
"Validates",
"the",
"identifier",
"to",
"prevent",
"unexpected",
"behaviour"
] |
7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff
|
https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Table.php#L148-L158
|
21,090 |
neat-php/database
|
classes/Table.php
|
Table.where
|
public function where($id)
{
$this->validateIdentifier($id);
if (!is_array($id)) {
$key = reset($this->keys);
return [$key => $id];
} else {
return $id;
}
}
|
php
|
public function where($id)
{
$this->validateIdentifier($id);
if (!is_array($id)) {
$key = reset($this->keys);
return [$key => $id];
} else {
return $id;
}
}
|
[
"public",
"function",
"where",
"(",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"validateIdentifier",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"id",
")",
")",
"{",
"$",
"key",
"=",
"reset",
"(",
"$",
"this",
"->",
"keys",
")",
";",
"return",
"[",
"$",
"key",
"=>",
"$",
"id",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"id",
";",
"}",
"}"
] |
Creates the where condition for the identifier
@param int|string|array $id
@return array
|
[
"Creates",
"the",
"where",
"condition",
"for",
"the",
"identifier"
] |
7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff
|
https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Table.php#L166-L176
|
21,091 |
webdevvie/pheanstalk-task-queue-bundle
|
Command/WorkerCommand.php
|
WorkerCommand.handleRunningProcess
|
private function handleRunningProcess(
Process $process,
&$runningCommand,
&$failed,
&$hasReceivedSignal,
&$exitCode,
&$exitCodeText
) {
if ($process->isRunning()) {
if ($hasReceivedSignal) {
return;
}
//force it to shut down now!
if ($this->shutdownNow) {
$this->output->write("[RECEIVED SIGNAL] Shutting down now!");
$process->stop(0);
$hasReceivedSignal = true;
$this->keepWorking = false;
$runningCommand = false;
}
if ((!$this->keepWorking || $this->shutdownGracefully)) {
//we need to keep this running until we are finished...
$this->output->write("[RECEIVED SIGNAL] will shutdown after finishing task");
$hasReceivedSignal = true;
}
} else {
$runningCommand = false;
$exitCode = $process->getExitCode();
$exitCodeText = $process->getExitCode();
if ($exitCode != 0) {
$failed = true;
}
}
}
|
php
|
private function handleRunningProcess(
Process $process,
&$runningCommand,
&$failed,
&$hasReceivedSignal,
&$exitCode,
&$exitCodeText
) {
if ($process->isRunning()) {
if ($hasReceivedSignal) {
return;
}
//force it to shut down now!
if ($this->shutdownNow) {
$this->output->write("[RECEIVED SIGNAL] Shutting down now!");
$process->stop(0);
$hasReceivedSignal = true;
$this->keepWorking = false;
$runningCommand = false;
}
if ((!$this->keepWorking || $this->shutdownGracefully)) {
//we need to keep this running until we are finished...
$this->output->write("[RECEIVED SIGNAL] will shutdown after finishing task");
$hasReceivedSignal = true;
}
} else {
$runningCommand = false;
$exitCode = $process->getExitCode();
$exitCodeText = $process->getExitCode();
if ($exitCode != 0) {
$failed = true;
}
}
}
|
[
"private",
"function",
"handleRunningProcess",
"(",
"Process",
"$",
"process",
",",
"&",
"$",
"runningCommand",
",",
"&",
"$",
"failed",
",",
"&",
"$",
"hasReceivedSignal",
",",
"&",
"$",
"exitCode",
",",
"&",
"$",
"exitCodeText",
")",
"{",
"if",
"(",
"$",
"process",
"->",
"isRunning",
"(",
")",
")",
"{",
"if",
"(",
"$",
"hasReceivedSignal",
")",
"{",
"return",
";",
"}",
"//force it to shut down now!",
"if",
"(",
"$",
"this",
"->",
"shutdownNow",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"write",
"(",
"\"[RECEIVED SIGNAL] Shutting down now!\"",
")",
";",
"$",
"process",
"->",
"stop",
"(",
"0",
")",
";",
"$",
"hasReceivedSignal",
"=",
"true",
";",
"$",
"this",
"->",
"keepWorking",
"=",
"false",
";",
"$",
"runningCommand",
"=",
"false",
";",
"}",
"if",
"(",
"(",
"!",
"$",
"this",
"->",
"keepWorking",
"||",
"$",
"this",
"->",
"shutdownGracefully",
")",
")",
"{",
"//we need to keep this running until we are finished...",
"$",
"this",
"->",
"output",
"->",
"write",
"(",
"\"[RECEIVED SIGNAL] will shutdown after finishing task\"",
")",
";",
"$",
"hasReceivedSignal",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"$",
"runningCommand",
"=",
"false",
";",
"$",
"exitCode",
"=",
"$",
"process",
"->",
"getExitCode",
"(",
")",
";",
"$",
"exitCodeText",
"=",
"$",
"process",
"->",
"getExitCode",
"(",
")",
";",
"if",
"(",
"$",
"exitCode",
"!=",
"0",
")",
"{",
"$",
"failed",
"=",
"true",
";",
"}",
"}",
"}"
] |
Handles any running process waiting for signals..
@param Process $process
@param boolean &$runningCommand
@param boolean &$failed
@param boolean &$hasReceivedSignal
@param integer &$exitCode
@param string &$exitCodeText
@return void
|
[
"Handles",
"any",
"running",
"process",
"waiting",
"for",
"signals",
".."
] |
db5e63a8f844e345dc2e69ce8e94b32d851020eb
|
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Command/WorkerCommand.php#L175-L208
|
21,092 |
glynnforrest/active-doctrine
|
src/ActiveDoctrine/Fixture/FixtureLoader.php
|
FixtureLoader.addFixture
|
public function addFixture(FixtureInterface $fixture)
{
$this->dropTables = array_merge($this->dropTables, (array) $fixture->getTables());
$this->fixtures[] = $fixture;
}
|
php
|
public function addFixture(FixtureInterface $fixture)
{
$this->dropTables = array_merge($this->dropTables, (array) $fixture->getTables());
$this->fixtures[] = $fixture;
}
|
[
"public",
"function",
"addFixture",
"(",
"FixtureInterface",
"$",
"fixture",
")",
"{",
"$",
"this",
"->",
"dropTables",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"dropTables",
",",
"(",
"array",
")",
"$",
"fixture",
"->",
"getTables",
"(",
")",
")",
";",
"$",
"this",
"->",
"fixtures",
"[",
"]",
"=",
"$",
"fixture",
";",
"}"
] |
Add a fixture to be loaded into the database.
@param FixtureInterface $fixture
|
[
"Add",
"a",
"fixture",
"to",
"be",
"loaded",
"into",
"the",
"database",
"."
] |
fcf8c434c7df4704966107bf9a95c005a0b37168
|
https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Fixture/FixtureLoader.php#L22-L26
|
21,093 |
glynnforrest/active-doctrine
|
src/ActiveDoctrine/Fixture/FixtureLoader.php
|
FixtureLoader.run
|
public function run(Connection $connection, $append = false)
{
if (!$append) {
//in the future, resolve key constraints here
foreach (array_unique($this->dropTables) as $table) {
$connection->delete($table, [1 => 1], [\PDO::PARAM_INT]);
}
}
foreach ($this->getSortedFixtures() as $fixture) {
$this->runFixture($connection, $fixture);
}
}
|
php
|
public function run(Connection $connection, $append = false)
{
if (!$append) {
//in the future, resolve key constraints here
foreach (array_unique($this->dropTables) as $table) {
$connection->delete($table, [1 => 1], [\PDO::PARAM_INT]);
}
}
foreach ($this->getSortedFixtures() as $fixture) {
$this->runFixture($connection, $fixture);
}
}
|
[
"public",
"function",
"run",
"(",
"Connection",
"$",
"connection",
",",
"$",
"append",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"append",
")",
"{",
"//in the future, resolve key constraints here",
"foreach",
"(",
"array_unique",
"(",
"$",
"this",
"->",
"dropTables",
")",
"as",
"$",
"table",
")",
"{",
"$",
"connection",
"->",
"delete",
"(",
"$",
"table",
",",
"[",
"1",
"=>",
"1",
"]",
",",
"[",
"\\",
"PDO",
"::",
"PARAM_INT",
"]",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"getSortedFixtures",
"(",
")",
"as",
"$",
"fixture",
")",
"{",
"$",
"this",
"->",
"runFixture",
"(",
"$",
"connection",
",",
"$",
"fixture",
")",
";",
"}",
"}"
] |
Run all fixtures.
@param Connection $connection
@param bool $append Don't empty tables before loading
|
[
"Run",
"all",
"fixtures",
"."
] |
fcf8c434c7df4704966107bf9a95c005a0b37168
|
https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Fixture/FixtureLoader.php#L34-L46
|
21,094 |
neat-php/database
|
classes/FetchedResult.php
|
FetchedResult.each
|
public function each(callable $closure)
{
$results = [];
foreach ($this->rows as $row) {
$results[] = $closure(...array_values($row));
}
return $results;
}
|
php
|
public function each(callable $closure)
{
$results = [];
foreach ($this->rows as $row) {
$results[] = $closure(...array_values($row));
}
return $results;
}
|
[
"public",
"function",
"each",
"(",
"callable",
"$",
"closure",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"$",
"closure",
"(",
"...",
"array_values",
"(",
"$",
"row",
")",
")",
";",
"}",
"return",
"$",
"results",
";",
"}"
] |
Call a closure for each row
@param callable $closure
@return array
|
[
"Call",
"a",
"closure",
"for",
"each",
"row"
] |
7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff
|
https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/FetchedResult.php#L39-L47
|
21,095 |
neat-php/database
|
classes/FetchedResult.php
|
FetchedResult.row
|
public function row()
{
if (isset($this->rows[$this->cursor])) {
return $this->rows[$this->cursor++];
}
return false;
}
|
php
|
public function row()
{
if (isset($this->rows[$this->cursor])) {
return $this->rows[$this->cursor++];
}
return false;
}
|
[
"public",
"function",
"row",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"rows",
"[",
"$",
"this",
"->",
"cursor",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"rows",
"[",
"$",
"this",
"->",
"cursor",
"++",
"]",
";",
"}",
"return",
"false",
";",
"}"
] |
Get a single row as array
Moves the cursor to the next row
@return array|false
|
[
"Get",
"a",
"single",
"row",
"as",
"array"
] |
7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff
|
https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/FetchedResult.php#L68-L75
|
21,096 |
RhubarbPHP/Module.RestApi
|
src/Resources/CollectionRestResource.php
|
CollectionRestResource.containsResourceIdentifier
|
public function containsResourceIdentifier($resourceIdentifier)
{
// This will be very slow however the base implementation can do nothing else.
// Inheritors of this class should override this if they can do this faster!
$items = $this->getItems(0, false);
foreach ($items[0] as $item) {
if ($item->_id = $resourceIdentifier) {
return true;
}
}
return false;
}
|
php
|
public function containsResourceIdentifier($resourceIdentifier)
{
// This will be very slow however the base implementation can do nothing else.
// Inheritors of this class should override this if they can do this faster!
$items = $this->getItems(0, false);
foreach ($items[0] as $item) {
if ($item->_id = $resourceIdentifier) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"containsResourceIdentifier",
"(",
"$",
"resourceIdentifier",
")",
"{",
"// This will be very slow however the base implementation can do nothing else.",
"// Inheritors of this class should override this if they can do this faster!",
"$",
"items",
"=",
"$",
"this",
"->",
"getItems",
"(",
"0",
",",
"false",
")",
";",
"foreach",
"(",
"$",
"items",
"[",
"0",
"]",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"_id",
"=",
"$",
"resourceIdentifier",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Test to see if the given resource identifier exists in the collection of resources.
@param $resourceIdentifier
@return True if it exists, false if it does not.
|
[
"Test",
"to",
"see",
"if",
"the",
"given",
"resource",
"identifier",
"exists",
"in",
"the",
"collection",
"of",
"resources",
"."
] |
825d2b920caed13811971c5eb2784a94417787bd
|
https://github.com/RhubarbPHP/Module.RestApi/blob/825d2b920caed13811971c5eb2784a94417787bd/src/Resources/CollectionRestResource.php#L64-L77
|
21,097 |
RhubarbPHP/Module.RestApi
|
src/Resources/CollectionRestResource.php
|
CollectionRestResource.createCollectionResourceForItems
|
protected function createCollectionResourceForItems($items, $from, $to, $count)
{
$resource = parent::get();
$resource->items = $items;
$resource->count = $count;
$resource->range = new \stdClass();
$resource->range->from = $from;
$resource->range->to = $to;
return $resource;
}
|
php
|
protected function createCollectionResourceForItems($items, $from, $to, $count)
{
$resource = parent::get();
$resource->items = $items;
$resource->count = $count;
$resource->range = new \stdClass();
$resource->range->from = $from;
$resource->range->to = $to;
return $resource;
}
|
[
"protected",
"function",
"createCollectionResourceForItems",
"(",
"$",
"items",
",",
"$",
"from",
",",
"$",
"to",
",",
"$",
"count",
")",
"{",
"$",
"resource",
"=",
"parent",
"::",
"get",
"(",
")",
";",
"$",
"resource",
"->",
"items",
"=",
"$",
"items",
";",
"$",
"resource",
"->",
"count",
"=",
"$",
"count",
";",
"$",
"resource",
"->",
"range",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"resource",
"->",
"range",
"->",
"from",
"=",
"$",
"from",
";",
"$",
"resource",
"->",
"range",
"->",
"to",
"=",
"$",
"to",
";",
"return",
"$",
"resource",
";",
"}"
] |
Creates a valid collection response from a list of objects.
@param Collection|\stdClass[] $items
@param int $from
@param int $to
@param int $count
@return \stdClass
|
[
"Creates",
"a",
"valid",
"collection",
"response",
"from",
"a",
"list",
"of",
"objects",
"."
] |
825d2b920caed13811971c5eb2784a94417787bd
|
https://github.com/RhubarbPHP/Module.RestApi/blob/825d2b920caed13811971c5eb2784a94417787bd/src/Resources/CollectionRestResource.php#L151-L161
|
21,098 |
mikebarlow/html-helper
|
src/Attributes.php
|
Attributes.attr
|
public function attr(array $attributes)
{
$result = '';
foreach ($attributes as $attribute => $value) {
$result .= ' '.(is_int($attribute) ? $value : $attribute.'="'.str_replace('"', '"', $value).'"');
}
return $result;
}
|
php
|
public function attr(array $attributes)
{
$result = '';
foreach ($attributes as $attribute => $value) {
$result .= ' '.(is_int($attribute) ? $value : $attribute.'="'.str_replace('"', '"', $value).'"');
}
return $result;
}
|
[
"public",
"function",
"attr",
"(",
"array",
"$",
"attributes",
")",
"{",
"$",
"result",
"=",
"''",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"$",
"result",
".=",
"' '",
".",
"(",
"is_int",
"(",
"$",
"attribute",
")",
"?",
"$",
"value",
":",
"$",
"attribute",
".",
"'=\"'",
".",
"str_replace",
"(",
"'\"'",
",",
"'"'",
",",
"$",
"value",
")",
".",
"'\"'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Render the attributes
@param array $attributes
@return string
|
[
"Render",
"the",
"attributes"
] |
d9d9dc3e92ba3ecd75f3a2e5a5bc2d23f38b5f65
|
https://github.com/mikebarlow/html-helper/blob/d9d9dc3e92ba3ecd75f3a2e5a5bc2d23f38b5f65/src/Attributes.php#L13-L22
|
21,099 |
mikebarlow/html-helper
|
src/Attributes.php
|
Attributes.mergeAttr
|
public function mergeAttr()
{
$arrays = func_get_args();
$result = array();
foreach ($arrays as $array) {
$result = $this->mergeRecursive($result, $array);
}
return $result;
}
|
php
|
public function mergeAttr()
{
$arrays = func_get_args();
$result = array();
foreach ($arrays as $array) {
$result = $this->mergeRecursive($result, $array);
}
return $result;
}
|
[
"public",
"function",
"mergeAttr",
"(",
")",
"{",
"$",
"arrays",
"=",
"func_get_args",
"(",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"arrays",
"as",
"$",
"array",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"mergeRecursive",
"(",
"$",
"result",
",",
"$",
"array",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
It will merge multiple attributes arrays without erase values
@return array
|
[
"It",
"will",
"merge",
"multiple",
"attributes",
"arrays",
"without",
"erase",
"values"
] |
d9d9dc3e92ba3ecd75f3a2e5a5bc2d23f38b5f65
|
https://github.com/mikebarlow/html-helper/blob/d9d9dc3e92ba3ecd75f3a2e5a5bc2d23f38b5f65/src/Attributes.php#L29-L39
|
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.