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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
221,000
|
aimeos/aimeos-laravel
|
src/Aimeos/Shop/Base/Support.php
|
Support.checkUserGroup
|
public function checkUserGroup( \Illuminate\Foundation\Auth\User $user, $groupcodes )
{
$groups = ( is_array( $groupcodes ) ? implode( ',', $groupcodes ) : $groupcodes );
if( isset( $this->cache[$user->id][$groups] ) ) {
return $this->cache[$user->id][$groups];
}
$this->cache[$user->id][$groups] = false;
$context = $this->context->get( false );
try {
$site = \Aimeos\MShop::create( $context, 'locale/site' )->getItem( $user->siteid )->getCode();
} catch( \Exception $e ) {
$site = ( Route::current() ? Route::input( 'site', Input::get( 'site', 'default' ) ) : 'default' );
}
$context->setLocale( $this->locale->getBackend( $context, $site ) );
foreach( array_reverse( $context->getLocale()->getSitePath() ) as $siteid )
{
if( (string) $user->siteid === (string) $siteid ) {
$this->cache[$user->id][$groups] = $this->checkGroups( $context, $user->id, $groupcodes );
}
}
return $this->cache[$user->id][$groups];
}
|
php
|
public function checkUserGroup( \Illuminate\Foundation\Auth\User $user, $groupcodes )
{
$groups = ( is_array( $groupcodes ) ? implode( ',', $groupcodes ) : $groupcodes );
if( isset( $this->cache[$user->id][$groups] ) ) {
return $this->cache[$user->id][$groups];
}
$this->cache[$user->id][$groups] = false;
$context = $this->context->get( false );
try {
$site = \Aimeos\MShop::create( $context, 'locale/site' )->getItem( $user->siteid )->getCode();
} catch( \Exception $e ) {
$site = ( Route::current() ? Route::input( 'site', Input::get( 'site', 'default' ) ) : 'default' );
}
$context->setLocale( $this->locale->getBackend( $context, $site ) );
foreach( array_reverse( $context->getLocale()->getSitePath() ) as $siteid )
{
if( (string) $user->siteid === (string) $siteid ) {
$this->cache[$user->id][$groups] = $this->checkGroups( $context, $user->id, $groupcodes );
}
}
return $this->cache[$user->id][$groups];
}
|
[
"public",
"function",
"checkUserGroup",
"(",
"\\",
"Illuminate",
"\\",
"Foundation",
"\\",
"Auth",
"\\",
"User",
"$",
"user",
",",
"$",
"groupcodes",
")",
"{",
"$",
"groups",
"=",
"(",
"is_array",
"(",
"$",
"groupcodes",
")",
"?",
"implode",
"(",
"','",
",",
"$",
"groupcodes",
")",
":",
"$",
"groupcodes",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"user",
"->",
"id",
"]",
"[",
"$",
"groups",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"cache",
"[",
"$",
"user",
"->",
"id",
"]",
"[",
"$",
"groups",
"]",
";",
"}",
"$",
"this",
"->",
"cache",
"[",
"$",
"user",
"->",
"id",
"]",
"[",
"$",
"groups",
"]",
"=",
"false",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"context",
"->",
"get",
"(",
"false",
")",
";",
"try",
"{",
"$",
"site",
"=",
"\\",
"Aimeos",
"\\",
"MShop",
"::",
"create",
"(",
"$",
"context",
",",
"'locale/site'",
")",
"->",
"getItem",
"(",
"$",
"user",
"->",
"siteid",
")",
"->",
"getCode",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"site",
"=",
"(",
"Route",
"::",
"current",
"(",
")",
"?",
"Route",
"::",
"input",
"(",
"'site'",
",",
"Input",
"::",
"get",
"(",
"'site'",
",",
"'default'",
")",
")",
":",
"'default'",
")",
";",
"}",
"$",
"context",
"->",
"setLocale",
"(",
"$",
"this",
"->",
"locale",
"->",
"getBackend",
"(",
"$",
"context",
",",
"$",
"site",
")",
")",
";",
"foreach",
"(",
"array_reverse",
"(",
"$",
"context",
"->",
"getLocale",
"(",
")",
"->",
"getSitePath",
"(",
")",
")",
"as",
"$",
"siteid",
")",
"{",
"if",
"(",
"(",
"string",
")",
"$",
"user",
"->",
"siteid",
"===",
"(",
"string",
")",
"$",
"siteid",
")",
"{",
"$",
"this",
"->",
"cache",
"[",
"$",
"user",
"->",
"id",
"]",
"[",
"$",
"groups",
"]",
"=",
"$",
"this",
"->",
"checkGroups",
"(",
"$",
"context",
",",
"$",
"user",
"->",
"id",
",",
"$",
"groupcodes",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"cache",
"[",
"$",
"user",
"->",
"id",
"]",
"[",
"$",
"groups",
"]",
";",
"}"
] |
Checks if the user is in the specified group and associatied to the site
@param \Illuminate\Foundation\Auth\User $user Authenticated user
@param string|array $groupcodes Unique user/customer group codes that are allowed
@return boolean True if user is part of the group, false if not
|
[
"Checks",
"if",
"the",
"user",
"is",
"in",
"the",
"specified",
"group",
"and",
"associatied",
"to",
"the",
"site"
] |
d407e5ca95433fa3e900df8dbc9ab1ea74df1afe
|
https://github.com/aimeos/aimeos-laravel/blob/d407e5ca95433fa3e900df8dbc9ab1ea74df1afe/src/Aimeos/Shop/Base/Support.php#L61-L88
|
221,001
|
aimeos/aimeos-laravel
|
src/Aimeos/Shop/Base/Support.php
|
Support.checkGroup
|
public function checkGroup( $userid, $groupcodes )
{
$groups = ( is_array( $groupcodes ) ? implode( ',', $groupcodes ) : $groupcodes );
if( isset( $this->cache[$userid][$groups] ) ) {
return $this->cache[$userid][$groups];
}
$site = ( Route::current() ? Route::input( 'site', Input::get( 'site', 'default' ) ) : 'default' );
$context = $this->context->get( false );
$context->setLocale( $this->locale->getBackend( $context, $site ) );
return $this->cache[$userid][$groups] = $this->checkGroups( $context, $userid, $groupcodes );
}
|
php
|
public function checkGroup( $userid, $groupcodes )
{
$groups = ( is_array( $groupcodes ) ? implode( ',', $groupcodes ) : $groupcodes );
if( isset( $this->cache[$userid][$groups] ) ) {
return $this->cache[$userid][$groups];
}
$site = ( Route::current() ? Route::input( 'site', Input::get( 'site', 'default' ) ) : 'default' );
$context = $this->context->get( false );
$context->setLocale( $this->locale->getBackend( $context, $site ) );
return $this->cache[$userid][$groups] = $this->checkGroups( $context, $userid, $groupcodes );
}
|
[
"public",
"function",
"checkGroup",
"(",
"$",
"userid",
",",
"$",
"groupcodes",
")",
"{",
"$",
"groups",
"=",
"(",
"is_array",
"(",
"$",
"groupcodes",
")",
"?",
"implode",
"(",
"','",
",",
"$",
"groupcodes",
")",
":",
"$",
"groupcodes",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"userid",
"]",
"[",
"$",
"groups",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"cache",
"[",
"$",
"userid",
"]",
"[",
"$",
"groups",
"]",
";",
"}",
"$",
"site",
"=",
"(",
"Route",
"::",
"current",
"(",
")",
"?",
"Route",
"::",
"input",
"(",
"'site'",
",",
"Input",
"::",
"get",
"(",
"'site'",
",",
"'default'",
")",
")",
":",
"'default'",
")",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"context",
"->",
"get",
"(",
"false",
")",
";",
"$",
"context",
"->",
"setLocale",
"(",
"$",
"this",
"->",
"locale",
"->",
"getBackend",
"(",
"$",
"context",
",",
"$",
"site",
")",
")",
";",
"return",
"$",
"this",
"->",
"cache",
"[",
"$",
"userid",
"]",
"[",
"$",
"groups",
"]",
"=",
"$",
"this",
"->",
"checkGroups",
"(",
"$",
"context",
",",
"$",
"userid",
",",
"$",
"groupcodes",
")",
";",
"}"
] |
Checks if the user with the given ID is in the specified group
@param string $userid Unique user ID
@param string|array $groupcodes Unique user/customer group codes that are allowed
@return boolean True if user is part of the group, false if not
@deprecated Use checkUserGroup() instead
|
[
"Checks",
"if",
"the",
"user",
"with",
"the",
"given",
"ID",
"is",
"in",
"the",
"specified",
"group"
] |
d407e5ca95433fa3e900df8dbc9ab1ea74df1afe
|
https://github.com/aimeos/aimeos-laravel/blob/d407e5ca95433fa3e900df8dbc9ab1ea74df1afe/src/Aimeos/Shop/Base/Support.php#L99-L113
|
221,002
|
aimeos/aimeos-laravel
|
src/Aimeos/Shop/Base/Support.php
|
Support.getGroups
|
public function getGroups( \Aimeos\MShop\Context\Item\Iface $context )
{
$list = array();
$manager = \Aimeos\MShop::create( $context, 'customer/group' );
$search = $manager->createSearch();
$search->setConditions( $search->compare( '==', 'customer.group.id', $context->getGroupIds() ) );
foreach( $manager->searchItems( $search ) as $item ) {
$list[] = $item->getCode();
}
return $list;
}
|
php
|
public function getGroups( \Aimeos\MShop\Context\Item\Iface $context )
{
$list = array();
$manager = \Aimeos\MShop::create( $context, 'customer/group' );
$search = $manager->createSearch();
$search->setConditions( $search->compare( '==', 'customer.group.id', $context->getGroupIds() ) );
foreach( $manager->searchItems( $search ) as $item ) {
$list[] = $item->getCode();
}
return $list;
}
|
[
"public",
"function",
"getGroups",
"(",
"\\",
"Aimeos",
"\\",
"MShop",
"\\",
"Context",
"\\",
"Item",
"\\",
"Iface",
"$",
"context",
")",
"{",
"$",
"list",
"=",
"array",
"(",
")",
";",
"$",
"manager",
"=",
"\\",
"Aimeos",
"\\",
"MShop",
"::",
"create",
"(",
"$",
"context",
",",
"'customer/group'",
")",
";",
"$",
"search",
"=",
"$",
"manager",
"->",
"createSearch",
"(",
")",
";",
"$",
"search",
"->",
"setConditions",
"(",
"$",
"search",
"->",
"compare",
"(",
"'=='",
",",
"'customer.group.id'",
",",
"$",
"context",
"->",
"getGroupIds",
"(",
")",
")",
")",
";",
"foreach",
"(",
"$",
"manager",
"->",
"searchItems",
"(",
"$",
"search",
")",
"as",
"$",
"item",
")",
"{",
"$",
"list",
"[",
"]",
"=",
"$",
"item",
"->",
"getCode",
"(",
")",
";",
"}",
"return",
"$",
"list",
";",
"}"
] |
Returns the available group codes
@param \Aimeos\MShop\Context\Item\Iface $context Context item
@return string[] List of group codes
|
[
"Returns",
"the",
"available",
"group",
"codes"
] |
d407e5ca95433fa3e900df8dbc9ab1ea74df1afe
|
https://github.com/aimeos/aimeos-laravel/blob/d407e5ca95433fa3e900df8dbc9ab1ea74df1afe/src/Aimeos/Shop/Base/Support.php#L122-L135
|
221,003
|
aimeos/aimeos-laravel
|
src/Aimeos/Shop/Base/Support.php
|
Support.checkGroups
|
protected function checkGroups( \Aimeos\MShop\Context\Item\Iface $context, $userid, $groupcodes )
{
$manager = \Aimeos\MShop::create( $context, 'customer/group' );
$search = $manager->createSearch();
$search->setConditions( $search->compare( '==', 'customer.group.code', (array) $groupcodes ) );
$groupItems = $manager->searchItems( $search );
$manager = \Aimeos\MShop::create( $context, 'customer/lists' );
$search = $manager->createSearch();
$expr = array(
$search->compare( '==', 'customer.lists.parentid', $userid ),
$search->compare( '==', 'customer.lists.refid', array_keys( $groupItems ) ),
$search->compare( '==', 'customer.lists.domain', 'customer/group' ),
);
$search->setConditions( $search->combine( '&&', $expr ) );
$search->setSlice( 0, 1 );
return (bool) count( $manager->searchItems( $search ) );
}
|
php
|
protected function checkGroups( \Aimeos\MShop\Context\Item\Iface $context, $userid, $groupcodes )
{
$manager = \Aimeos\MShop::create( $context, 'customer/group' );
$search = $manager->createSearch();
$search->setConditions( $search->compare( '==', 'customer.group.code', (array) $groupcodes ) );
$groupItems = $manager->searchItems( $search );
$manager = \Aimeos\MShop::create( $context, 'customer/lists' );
$search = $manager->createSearch();
$expr = array(
$search->compare( '==', 'customer.lists.parentid', $userid ),
$search->compare( '==', 'customer.lists.refid', array_keys( $groupItems ) ),
$search->compare( '==', 'customer.lists.domain', 'customer/group' ),
);
$search->setConditions( $search->combine( '&&', $expr ) );
$search->setSlice( 0, 1 );
return (bool) count( $manager->searchItems( $search ) );
}
|
[
"protected",
"function",
"checkGroups",
"(",
"\\",
"Aimeos",
"\\",
"MShop",
"\\",
"Context",
"\\",
"Item",
"\\",
"Iface",
"$",
"context",
",",
"$",
"userid",
",",
"$",
"groupcodes",
")",
"{",
"$",
"manager",
"=",
"\\",
"Aimeos",
"\\",
"MShop",
"::",
"create",
"(",
"$",
"context",
",",
"'customer/group'",
")",
";",
"$",
"search",
"=",
"$",
"manager",
"->",
"createSearch",
"(",
")",
";",
"$",
"search",
"->",
"setConditions",
"(",
"$",
"search",
"->",
"compare",
"(",
"'=='",
",",
"'customer.group.code'",
",",
"(",
"array",
")",
"$",
"groupcodes",
")",
")",
";",
"$",
"groupItems",
"=",
"$",
"manager",
"->",
"searchItems",
"(",
"$",
"search",
")",
";",
"$",
"manager",
"=",
"\\",
"Aimeos",
"\\",
"MShop",
"::",
"create",
"(",
"$",
"context",
",",
"'customer/lists'",
")",
";",
"$",
"search",
"=",
"$",
"manager",
"->",
"createSearch",
"(",
")",
";",
"$",
"expr",
"=",
"array",
"(",
"$",
"search",
"->",
"compare",
"(",
"'=='",
",",
"'customer.lists.parentid'",
",",
"$",
"userid",
")",
",",
"$",
"search",
"->",
"compare",
"(",
"'=='",
",",
"'customer.lists.refid'",
",",
"array_keys",
"(",
"$",
"groupItems",
")",
")",
",",
"$",
"search",
"->",
"compare",
"(",
"'=='",
",",
"'customer.lists.domain'",
",",
"'customer/group'",
")",
",",
")",
";",
"$",
"search",
"->",
"setConditions",
"(",
"$",
"search",
"->",
"combine",
"(",
"'&&'",
",",
"$",
"expr",
")",
")",
";",
"$",
"search",
"->",
"setSlice",
"(",
"0",
",",
"1",
")",
";",
"return",
"(",
"bool",
")",
"count",
"(",
"$",
"manager",
"->",
"searchItems",
"(",
"$",
"search",
")",
")",
";",
"}"
] |
Checks if one of the groups is associated to the given user ID
@param \Aimeos\MShop\Context\Item\Iface $context Context item
@param string $userid ID of the logged in user
@param string[] $groupcodes List of group codes to check against
@return boolean True if the user is in one of the groups, false if not
|
[
"Checks",
"if",
"one",
"of",
"the",
"groups",
"is",
"associated",
"to",
"the",
"given",
"user",
"ID"
] |
d407e5ca95433fa3e900df8dbc9ab1ea74df1afe
|
https://github.com/aimeos/aimeos-laravel/blob/d407e5ca95433fa3e900df8dbc9ab1ea74df1afe/src/Aimeos/Shop/Base/Support.php#L146-L167
|
221,004
|
deployphp/deployer
|
src/Deployer.php
|
Deployer.init
|
public function init()
{
$this->addConsoleCommands();
$this->getConsole()->add(new WorkerCommand($this));
$this->getConsole()->add($this['init_command']);
$this->getConsole()->add(new SshCommand($this));
$this->getConsole()->add(new RunCommand($this));
$this->getConsole()->add(new DebugCommand($this));
$this->getConsole()->add(new AutocompleteCommand());
$this->getConsole()->afterRun([$this, 'collectAnonymousStats']);
}
|
php
|
public function init()
{
$this->addConsoleCommands();
$this->getConsole()->add(new WorkerCommand($this));
$this->getConsole()->add($this['init_command']);
$this->getConsole()->add(new SshCommand($this));
$this->getConsole()->add(new RunCommand($this));
$this->getConsole()->add(new DebugCommand($this));
$this->getConsole()->add(new AutocompleteCommand());
$this->getConsole()->afterRun([$this, 'collectAnonymousStats']);
}
|
[
"public",
"function",
"init",
"(",
")",
"{",
"$",
"this",
"->",
"addConsoleCommands",
"(",
")",
";",
"$",
"this",
"->",
"getConsole",
"(",
")",
"->",
"add",
"(",
"new",
"WorkerCommand",
"(",
"$",
"this",
")",
")",
";",
"$",
"this",
"->",
"getConsole",
"(",
")",
"->",
"add",
"(",
"$",
"this",
"[",
"'init_command'",
"]",
")",
";",
"$",
"this",
"->",
"getConsole",
"(",
")",
"->",
"add",
"(",
"new",
"SshCommand",
"(",
"$",
"this",
")",
")",
";",
"$",
"this",
"->",
"getConsole",
"(",
")",
"->",
"add",
"(",
"new",
"RunCommand",
"(",
"$",
"this",
")",
")",
";",
"$",
"this",
"->",
"getConsole",
"(",
")",
"->",
"add",
"(",
"new",
"DebugCommand",
"(",
"$",
"this",
")",
")",
";",
"$",
"this",
"->",
"getConsole",
"(",
")",
"->",
"add",
"(",
"new",
"AutocompleteCommand",
"(",
")",
")",
";",
"$",
"this",
"->",
"getConsole",
"(",
")",
"->",
"afterRun",
"(",
"[",
"$",
"this",
",",
"'collectAnonymousStats'",
"]",
")",
";",
"}"
] |
Init console application
|
[
"Init",
"console",
"application"
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Deployer.php#L221-L231
|
221,005
|
deployphp/deployer
|
src/Deployer.php
|
Deployer.addConsoleCommands
|
public function addConsoleCommands()
{
$this->getConsole()->addUserArgumentsAndOptions();
foreach ($this->tasks as $name => $task) {
if ($task->isPrivate()) {
continue;
}
$this->getConsole()->add(new TaskCommand($name, $task->getDescription(), $this));
}
}
|
php
|
public function addConsoleCommands()
{
$this->getConsole()->addUserArgumentsAndOptions();
foreach ($this->tasks as $name => $task) {
if ($task->isPrivate()) {
continue;
}
$this->getConsole()->add(new TaskCommand($name, $task->getDescription(), $this));
}
}
|
[
"public",
"function",
"addConsoleCommands",
"(",
")",
"{",
"$",
"this",
"->",
"getConsole",
"(",
")",
"->",
"addUserArgumentsAndOptions",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"tasks",
"as",
"$",
"name",
"=>",
"$",
"task",
")",
"{",
"if",
"(",
"$",
"task",
"->",
"isPrivate",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"getConsole",
"(",
")",
"->",
"add",
"(",
"new",
"TaskCommand",
"(",
"$",
"name",
",",
"$",
"task",
"->",
"getDescription",
"(",
")",
",",
"$",
"this",
")",
")",
";",
"}",
"}"
] |
Transform tasks to console commands.
|
[
"Transform",
"tasks",
"to",
"console",
"commands",
"."
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Deployer.php#L236-L247
|
221,006
|
deployphp/deployer
|
src/Deployer.php
|
Deployer.collectAnonymousStats
|
public function collectAnonymousStats(CommandEvent $commandEvent)
{
if ($this->config->has('allow_anonymous_stats') && $this->config['allow_anonymous_stats'] === false) {
return;
}
$stats = [
'status' => 'success',
'command_name' => $commandEvent->getCommand()->getName(),
'project_hash' => empty($this->config['repository']) ? null : sha1($this->config['repository']),
'hosts_count' => $this->hosts->count(),
'deployer_version' => $this->getConsole()->getVersion(),
'deployer_phar' => $this->getConsole()->isPharArchive(),
'php_version' => phpversion(),
'extension_pcntl' => extension_loaded('pcntl'),
'extension_curl' => extension_loaded('curl'),
'os' => defined('PHP_OS_FAMILY') ? PHP_OS_FAMILY : (stristr(PHP_OS, 'DAR') ? 'OSX' : (stristr(PHP_OS, 'WIN') ? 'WIN' : (stristr(PHP_OS, 'LINUX') ? 'LINUX' : PHP_OS))),
'exception' => null,
];
if ($commandEvent->getException() !== null) {
$stats['status'] = 'error';
$stats['exception'] = get_class($commandEvent->getException());
}
if ($stats['command_name'] === 'init') {
$stats['allow_anonymous_stats'] = $GLOBALS['allow_anonymous_stats'] ?? false;
}
if (in_array($stats['command_name'], ['worker', 'list', 'help'], true)) {
return;
}
Reporter::report($stats);
}
|
php
|
public function collectAnonymousStats(CommandEvent $commandEvent)
{
if ($this->config->has('allow_anonymous_stats') && $this->config['allow_anonymous_stats'] === false) {
return;
}
$stats = [
'status' => 'success',
'command_name' => $commandEvent->getCommand()->getName(),
'project_hash' => empty($this->config['repository']) ? null : sha1($this->config['repository']),
'hosts_count' => $this->hosts->count(),
'deployer_version' => $this->getConsole()->getVersion(),
'deployer_phar' => $this->getConsole()->isPharArchive(),
'php_version' => phpversion(),
'extension_pcntl' => extension_loaded('pcntl'),
'extension_curl' => extension_loaded('curl'),
'os' => defined('PHP_OS_FAMILY') ? PHP_OS_FAMILY : (stristr(PHP_OS, 'DAR') ? 'OSX' : (stristr(PHP_OS, 'WIN') ? 'WIN' : (stristr(PHP_OS, 'LINUX') ? 'LINUX' : PHP_OS))),
'exception' => null,
];
if ($commandEvent->getException() !== null) {
$stats['status'] = 'error';
$stats['exception'] = get_class($commandEvent->getException());
}
if ($stats['command_name'] === 'init') {
$stats['allow_anonymous_stats'] = $GLOBALS['allow_anonymous_stats'] ?? false;
}
if (in_array($stats['command_name'], ['worker', 'list', 'help'], true)) {
return;
}
Reporter::report($stats);
}
|
[
"public",
"function",
"collectAnonymousStats",
"(",
"CommandEvent",
"$",
"commandEvent",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"has",
"(",
"'allow_anonymous_stats'",
")",
"&&",
"$",
"this",
"->",
"config",
"[",
"'allow_anonymous_stats'",
"]",
"===",
"false",
")",
"{",
"return",
";",
"}",
"$",
"stats",
"=",
"[",
"'status'",
"=>",
"'success'",
",",
"'command_name'",
"=>",
"$",
"commandEvent",
"->",
"getCommand",
"(",
")",
"->",
"getName",
"(",
")",
",",
"'project_hash'",
"=>",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"'repository'",
"]",
")",
"?",
"null",
":",
"sha1",
"(",
"$",
"this",
"->",
"config",
"[",
"'repository'",
"]",
")",
",",
"'hosts_count'",
"=>",
"$",
"this",
"->",
"hosts",
"->",
"count",
"(",
")",
",",
"'deployer_version'",
"=>",
"$",
"this",
"->",
"getConsole",
"(",
")",
"->",
"getVersion",
"(",
")",
",",
"'deployer_phar'",
"=>",
"$",
"this",
"->",
"getConsole",
"(",
")",
"->",
"isPharArchive",
"(",
")",
",",
"'php_version'",
"=>",
"phpversion",
"(",
")",
",",
"'extension_pcntl'",
"=>",
"extension_loaded",
"(",
"'pcntl'",
")",
",",
"'extension_curl'",
"=>",
"extension_loaded",
"(",
"'curl'",
")",
",",
"'os'",
"=>",
"defined",
"(",
"'PHP_OS_FAMILY'",
")",
"?",
"PHP_OS_FAMILY",
":",
"(",
"stristr",
"(",
"PHP_OS",
",",
"'DAR'",
")",
"?",
"'OSX'",
":",
"(",
"stristr",
"(",
"PHP_OS",
",",
"'WIN'",
")",
"?",
"'WIN'",
":",
"(",
"stristr",
"(",
"PHP_OS",
",",
"'LINUX'",
")",
"?",
"'LINUX'",
":",
"PHP_OS",
")",
")",
")",
",",
"'exception'",
"=>",
"null",
",",
"]",
";",
"if",
"(",
"$",
"commandEvent",
"->",
"getException",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"stats",
"[",
"'status'",
"]",
"=",
"'error'",
";",
"$",
"stats",
"[",
"'exception'",
"]",
"=",
"get_class",
"(",
"$",
"commandEvent",
"->",
"getException",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"stats",
"[",
"'command_name'",
"]",
"===",
"'init'",
")",
"{",
"$",
"stats",
"[",
"'allow_anonymous_stats'",
"]",
"=",
"$",
"GLOBALS",
"[",
"'allow_anonymous_stats'",
"]",
"??",
"false",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"stats",
"[",
"'command_name'",
"]",
",",
"[",
"'worker'",
",",
"'list'",
",",
"'help'",
"]",
",",
"true",
")",
")",
"{",
"return",
";",
"}",
"Reporter",
"::",
"report",
"(",
"$",
"stats",
")",
";",
"}"
] |
Collect anonymous stats about Deployer usage for improving developer experience.
If you are not comfortable with this, you will always be able to disable this
by setting `allow_anonymous_stats` to false in your deploy.php file.
@param CommandEvent $commandEvent
@codeCoverageIgnore
|
[
"Collect",
"anonymous",
"stats",
"about",
"Deployer",
"usage",
"for",
"improving",
"developer",
"experience",
".",
"If",
"you",
"are",
"not",
"comfortable",
"with",
"this",
"you",
"will",
"always",
"be",
"able",
"to",
"disable",
"this",
"by",
"setting",
"allow_anonymous_stats",
"to",
"false",
"in",
"your",
"deploy",
".",
"php",
"file",
"."
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Deployer.php#L342-L376
|
221,007
|
deployphp/deployer
|
src/Configuration/ConfigurationAccessor.php
|
ConfigurationAccessor.set
|
public function set(string $name, $value)
{
$this->config->set($name, $value);
return $this;
}
|
php
|
public function set(string $name, $value)
{
$this->config->set($name, $value);
return $this;
}
|
[
"public",
"function",
"set",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"config",
"->",
"set",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set configuration option
@param mixed $value
@return static
|
[
"Set",
"configuration",
"option"
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Configuration/ConfigurationAccessor.php#L47-L51
|
221,008
|
deployphp/deployer
|
src/Configuration/ConfigurationAccessor.php
|
ConfigurationAccessor.add
|
public function add(string $name, array $value)
{
$this->config->add($name, $value);
return $this;
}
|
php
|
public function add(string $name, array $value)
{
$this->config->add($name, $value);
return $this;
}
|
[
"public",
"function",
"add",
"(",
"string",
"$",
"name",
",",
"array",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"config",
"->",
"add",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add configuration option
@param mixed[] $value
@return static
|
[
"Add",
"configuration",
"option"
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Configuration/ConfigurationAccessor.php#L59-L63
|
221,009
|
deployphp/deployer
|
src/Console/InitCommand.php
|
InitCommand.createInitializer
|
private function createInitializer()
{
$initializer = new Initializer();
$initializer->addTemplate('Common', new CommonTemplate());
$initializer->addTemplate('Laravel', new LaravelTemplate());
$initializer->addTemplate('Symfony', new SymfonyTemplate());
$initializer->addTemplate('Yii', new YiiTemplate());
$initializer->addTemplate('Yii2 Basic App', new Yii2BasicAppTemplate());
$initializer->addTemplate('Yii2 Advanced App', new Yii2AdvancedAppTemplate());
$initializer->addTemplate('Zend Framework', new ZendTemplate());
$initializer->addTemplate('CakePHP', new CakeTemplate());
$initializer->addTemplate('CodeIgniter', new CodeIgniterTemplate());
$initializer->addTemplate('Drupal', new DrupalTemplate());
$initializer->addTemplate('TYPO3', new Typo3Template());
return $initializer;
}
|
php
|
private function createInitializer()
{
$initializer = new Initializer();
$initializer->addTemplate('Common', new CommonTemplate());
$initializer->addTemplate('Laravel', new LaravelTemplate());
$initializer->addTemplate('Symfony', new SymfonyTemplate());
$initializer->addTemplate('Yii', new YiiTemplate());
$initializer->addTemplate('Yii2 Basic App', new Yii2BasicAppTemplate());
$initializer->addTemplate('Yii2 Advanced App', new Yii2AdvancedAppTemplate());
$initializer->addTemplate('Zend Framework', new ZendTemplate());
$initializer->addTemplate('CakePHP', new CakeTemplate());
$initializer->addTemplate('CodeIgniter', new CodeIgniterTemplate());
$initializer->addTemplate('Drupal', new DrupalTemplate());
$initializer->addTemplate('TYPO3', new Typo3Template());
return $initializer;
}
|
[
"private",
"function",
"createInitializer",
"(",
")",
"{",
"$",
"initializer",
"=",
"new",
"Initializer",
"(",
")",
";",
"$",
"initializer",
"->",
"addTemplate",
"(",
"'Common'",
",",
"new",
"CommonTemplate",
"(",
")",
")",
";",
"$",
"initializer",
"->",
"addTemplate",
"(",
"'Laravel'",
",",
"new",
"LaravelTemplate",
"(",
")",
")",
";",
"$",
"initializer",
"->",
"addTemplate",
"(",
"'Symfony'",
",",
"new",
"SymfonyTemplate",
"(",
")",
")",
";",
"$",
"initializer",
"->",
"addTemplate",
"(",
"'Yii'",
",",
"new",
"YiiTemplate",
"(",
")",
")",
";",
"$",
"initializer",
"->",
"addTemplate",
"(",
"'Yii2 Basic App'",
",",
"new",
"Yii2BasicAppTemplate",
"(",
")",
")",
";",
"$",
"initializer",
"->",
"addTemplate",
"(",
"'Yii2 Advanced App'",
",",
"new",
"Yii2AdvancedAppTemplate",
"(",
")",
")",
";",
"$",
"initializer",
"->",
"addTemplate",
"(",
"'Zend Framework'",
",",
"new",
"ZendTemplate",
"(",
")",
")",
";",
"$",
"initializer",
"->",
"addTemplate",
"(",
"'CakePHP'",
",",
"new",
"CakeTemplate",
"(",
")",
")",
";",
"$",
"initializer",
"->",
"addTemplate",
"(",
"'CodeIgniter'",
",",
"new",
"CodeIgniterTemplate",
"(",
")",
")",
";",
"$",
"initializer",
"->",
"addTemplate",
"(",
"'Drupal'",
",",
"new",
"DrupalTemplate",
"(",
")",
")",
";",
"$",
"initializer",
"->",
"addTemplate",
"(",
"'TYPO3'",
",",
"new",
"Typo3Template",
"(",
")",
")",
";",
"return",
"$",
"initializer",
";",
"}"
] |
Create a initializer system
@return Initializer
|
[
"Create",
"a",
"initializer",
"system"
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Console/InitCommand.php#L158-L175
|
221,010
|
deployphp/deployer
|
src/Support/Unix.php
|
Unix.parseHomeDir
|
public static function parseHomeDir(string $path): string
{
if (isset($_SERVER['HOME'])) {
$path = str_replace('~', $_SERVER['HOME'], $path);
} elseif (isset($_SERVER['HOMEDRIVE'], $_SERVER['HOMEPATH'])) {
$path = str_replace('~', $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'], $path);
}
return $path;
}
|
php
|
public static function parseHomeDir(string $path): string
{
if (isset($_SERVER['HOME'])) {
$path = str_replace('~', $_SERVER['HOME'], $path);
} elseif (isset($_SERVER['HOMEDRIVE'], $_SERVER['HOMEPATH'])) {
$path = str_replace('~', $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'], $path);
}
return $path;
}
|
[
"public",
"static",
"function",
"parseHomeDir",
"(",
"string",
"$",
"path",
")",
":",
"string",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HOME'",
"]",
")",
")",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"'~'",
",",
"$",
"_SERVER",
"[",
"'HOME'",
"]",
",",
"$",
"path",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HOMEDRIVE'",
"]",
",",
"$",
"_SERVER",
"[",
"'HOMEPATH'",
"]",
")",
")",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"'~'",
",",
"$",
"_SERVER",
"[",
"'HOMEDRIVE'",
"]",
".",
"$",
"_SERVER",
"[",
"'HOMEPATH'",
"]",
",",
"$",
"path",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] |
Parse "~" symbol from path.
@param string $path
@return string
|
[
"Parse",
"~",
"symbol",
"from",
"path",
"."
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Support/Unix.php#L18-L27
|
221,011
|
deployphp/deployer
|
src/Initializer/Initializer.php
|
Initializer.initialize
|
public function initialize($template, $directory, $file = 'deploy.php', $params = [])
{
if (!isset($this->templates[$template])) {
throw TemplateNotFoundException::create($template, array_keys($this->templates));
}
$this->checkDirectoryBeforeInitialize($directory);
$this->checkFileBeforeInitialize($directory, $file);
$filePath = $directory . '/' . $file;
$this->templates[$template]->initialize($filePath, $params);
return $filePath;
}
|
php
|
public function initialize($template, $directory, $file = 'deploy.php', $params = [])
{
if (!isset($this->templates[$template])) {
throw TemplateNotFoundException::create($template, array_keys($this->templates));
}
$this->checkDirectoryBeforeInitialize($directory);
$this->checkFileBeforeInitialize($directory, $file);
$filePath = $directory . '/' . $file;
$this->templates[$template]->initialize($filePath, $params);
return $filePath;
}
|
[
"public",
"function",
"initialize",
"(",
"$",
"template",
",",
"$",
"directory",
",",
"$",
"file",
"=",
"'deploy.php'",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"templates",
"[",
"$",
"template",
"]",
")",
")",
"{",
"throw",
"TemplateNotFoundException",
"::",
"create",
"(",
"$",
"template",
",",
"array_keys",
"(",
"$",
"this",
"->",
"templates",
")",
")",
";",
"}",
"$",
"this",
"->",
"checkDirectoryBeforeInitialize",
"(",
"$",
"directory",
")",
";",
"$",
"this",
"->",
"checkFileBeforeInitialize",
"(",
"$",
"directory",
",",
"$",
"file",
")",
";",
"$",
"filePath",
"=",
"$",
"directory",
".",
"'/'",
".",
"$",
"file",
";",
"$",
"this",
"->",
"templates",
"[",
"$",
"template",
"]",
"->",
"initialize",
"(",
"$",
"filePath",
",",
"$",
"params",
")",
";",
"return",
"$",
"filePath",
";",
"}"
] |
Initialize deployer in project
@param string $template
@param string $directory
@param string $file
@param array $params
@return string The configuration file path
@throws TemplateNotFoundException
|
[
"Initialize",
"deployer",
"in",
"project"
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Initializer/Initializer.php#L62-L76
|
221,012
|
deployphp/deployer
|
src/Initializer/Initializer.php
|
Initializer.checkDirectoryBeforeInitialize
|
private function checkDirectoryBeforeInitialize($directory)
{
if (!file_exists($directory)) {
set_error_handler(function ($errCode, $errStr) use ($directory) {
$parts = explode(':', $errStr, 2);
$errorMessage = isset($parts[1]) ? trim($parts[1]) : 'Undefined';
throw new IOException(sprintf(
'Could not create directory "%s". %s',
$directory,
$errorMessage
), $errCode);
});
mkdir($directory, 0775);
restore_error_handler();
} elseif (!is_dir($directory)) {
throw new IOException(sprintf(
'Can not create directory. The path "%s" already exist.',
$directory
));
} elseif (!is_writable($directory)) {
throw new IOException(sprintf(
'The directory "%s" is not writable.',
$directory
));
}
}
|
php
|
private function checkDirectoryBeforeInitialize($directory)
{
if (!file_exists($directory)) {
set_error_handler(function ($errCode, $errStr) use ($directory) {
$parts = explode(':', $errStr, 2);
$errorMessage = isset($parts[1]) ? trim($parts[1]) : 'Undefined';
throw new IOException(sprintf(
'Could not create directory "%s". %s',
$directory,
$errorMessage
), $errCode);
});
mkdir($directory, 0775);
restore_error_handler();
} elseif (!is_dir($directory)) {
throw new IOException(sprintf(
'Can not create directory. The path "%s" already exist.',
$directory
));
} elseif (!is_writable($directory)) {
throw new IOException(sprintf(
'The directory "%s" is not writable.',
$directory
));
}
}
|
[
"private",
"function",
"checkDirectoryBeforeInitialize",
"(",
"$",
"directory",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"directory",
")",
")",
"{",
"set_error_handler",
"(",
"function",
"(",
"$",
"errCode",
",",
"$",
"errStr",
")",
"use",
"(",
"$",
"directory",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"':'",
",",
"$",
"errStr",
",",
"2",
")",
";",
"$",
"errorMessage",
"=",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
"?",
"trim",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
":",
"'Undefined'",
";",
"throw",
"new",
"IOException",
"(",
"sprintf",
"(",
"'Could not create directory \"%s\". %s'",
",",
"$",
"directory",
",",
"$",
"errorMessage",
")",
",",
"$",
"errCode",
")",
";",
"}",
")",
";",
"mkdir",
"(",
"$",
"directory",
",",
"0775",
")",
";",
"restore_error_handler",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"sprintf",
"(",
"'Can not create directory. The path \"%s\" already exist.'",
",",
"$",
"directory",
")",
")",
";",
"}",
"elseif",
"(",
"!",
"is_writable",
"(",
"$",
"directory",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"sprintf",
"(",
"'The directory \"%s\" is not writable.'",
",",
"$",
"directory",
")",
")",
";",
"}",
"}"
] |
Check the directory before initialize
@param string $directory
@throws IOException
|
[
"Check",
"the",
"directory",
"before",
"initialize"
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Initializer/Initializer.php#L85-L113
|
221,013
|
deployphp/deployer
|
src/Initializer/Initializer.php
|
Initializer.checkFileBeforeInitialize
|
private function checkFileBeforeInitialize($directory, $file)
{
$filePath = $directory . '/' . $file;
if (file_exists($filePath)) {
throw new IOException(sprintf(
'The file "%s" already exist.',
$filePath
));
}
touch($filePath);
}
|
php
|
private function checkFileBeforeInitialize($directory, $file)
{
$filePath = $directory . '/' . $file;
if (file_exists($filePath)) {
throw new IOException(sprintf(
'The file "%s" already exist.',
$filePath
));
}
touch($filePath);
}
|
[
"private",
"function",
"checkFileBeforeInitialize",
"(",
"$",
"directory",
",",
"$",
"file",
")",
"{",
"$",
"filePath",
"=",
"$",
"directory",
".",
"'/'",
".",
"$",
"file",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filePath",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"sprintf",
"(",
"'The file \"%s\" already exist.'",
",",
"$",
"filePath",
")",
")",
";",
"}",
"touch",
"(",
"$",
"filePath",
")",
";",
"}"
] |
Check the file before initialize
@param string $directory
@param string $file
@throws IOException
|
[
"Check",
"the",
"file",
"before",
"initialize"
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Initializer/Initializer.php#L123-L135
|
221,014
|
deployphp/deployer
|
src/Ssh/Arguments.php
|
Arguments.generateControlPath
|
private function generateControlPath(Host $host)
{
$port = empty($host->getPort()) ? '' : ':' . $host->getPort();
$connectionData = "$host$port";
$tryLongestPossible = 0;
$controlPath = '';
do {
switch ($tryLongestPossible) {
case 1:
$controlPath = "~/.ssh/deployer_%C";
break;
case 2:
$controlPath = "~/deployer_$connectionData";
break;
case 3:
$controlPath = "~/deployer_%C";
break;
case 4:
$controlPath = "~/mux_%C";
break;
case 5:
throw new Exception("The multiplexing control path is too long. Control path is: $controlPath");
default:
$controlPath = "~/.ssh/deployer_$connectionData";
}
$tryLongestPossible++;
} while (strlen($controlPath) > 104); // Unix socket max length
return $controlPath;
}
|
php
|
private function generateControlPath(Host $host)
{
$port = empty($host->getPort()) ? '' : ':' . $host->getPort();
$connectionData = "$host$port";
$tryLongestPossible = 0;
$controlPath = '';
do {
switch ($tryLongestPossible) {
case 1:
$controlPath = "~/.ssh/deployer_%C";
break;
case 2:
$controlPath = "~/deployer_$connectionData";
break;
case 3:
$controlPath = "~/deployer_%C";
break;
case 4:
$controlPath = "~/mux_%C";
break;
case 5:
throw new Exception("The multiplexing control path is too long. Control path is: $controlPath");
default:
$controlPath = "~/.ssh/deployer_$connectionData";
}
$tryLongestPossible++;
} while (strlen($controlPath) > 104); // Unix socket max length
return $controlPath;
}
|
[
"private",
"function",
"generateControlPath",
"(",
"Host",
"$",
"host",
")",
"{",
"$",
"port",
"=",
"empty",
"(",
"$",
"host",
"->",
"getPort",
"(",
")",
")",
"?",
"''",
":",
"':'",
".",
"$",
"host",
"->",
"getPort",
"(",
")",
";",
"$",
"connectionData",
"=",
"\"$host$port\"",
";",
"$",
"tryLongestPossible",
"=",
"0",
";",
"$",
"controlPath",
"=",
"''",
";",
"do",
"{",
"switch",
"(",
"$",
"tryLongestPossible",
")",
"{",
"case",
"1",
":",
"$",
"controlPath",
"=",
"\"~/.ssh/deployer_%C\"",
";",
"break",
";",
"case",
"2",
":",
"$",
"controlPath",
"=",
"\"~/deployer_$connectionData\"",
";",
"break",
";",
"case",
"3",
":",
"$",
"controlPath",
"=",
"\"~/deployer_%C\"",
";",
"break",
";",
"case",
"4",
":",
"$",
"controlPath",
"=",
"\"~/mux_%C\"",
";",
"break",
";",
"case",
"5",
":",
"throw",
"new",
"Exception",
"(",
"\"The multiplexing control path is too long. Control path is: $controlPath\"",
")",
";",
"default",
":",
"$",
"controlPath",
"=",
"\"~/.ssh/deployer_$connectionData\"",
";",
"}",
"$",
"tryLongestPossible",
"++",
";",
"}",
"while",
"(",
"strlen",
"(",
"$",
"controlPath",
")",
">",
"104",
")",
";",
"// Unix socket max length",
"return",
"$",
"controlPath",
";",
"}"
] |
Return SSH multiplexing control path
When ControlPath is longer than 104 chars we can get:
SSH Error: unix_listener: too long for Unix domain socket
So try to get as descriptive path as possible.
%C is for creating hash out of connection attributes.
@param Host $host
@return string ControlPath
@throws Exception
|
[
"Return",
"SSH",
"multiplexing",
"control",
"path"
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Ssh/Arguments.php#L128-L157
|
221,015
|
deployphp/deployer
|
src/Task/ScriptManager.php
|
ScriptManager.getTasks
|
public function getTasks($name, array $hosts = [], $hooksEnabled = true)
{
$collect = function ($name) use (&$collect, $hosts, $hooksEnabled) {
$task = $this->tasks->get($name);
if (!$task->shouldBePerformed(...array_values($hosts))) {
return [];
}
$relatedTasks = [];
if ($hooksEnabled) {
$relatedTasks = array_merge(array_map($collect, $task->getBefore()), $relatedTasks);
}
if ($task instanceof GroupTask) {
$relatedTasks = array_merge($relatedTasks, array_map($collect, $task->getGroup()));
} else {
$relatedTasks = array_merge($relatedTasks, [$task->getName()]);
}
if ($hooksEnabled) {
$relatedTasks = array_merge($relatedTasks, array_map($collect, $task->getAfter()));
}
return $relatedTasks;
};
$script = $collect($name);
$tasks = array_flatten($script);
// Convert names to real tasks
return array_map([$this->tasks, 'get'], $tasks);
}
|
php
|
public function getTasks($name, array $hosts = [], $hooksEnabled = true)
{
$collect = function ($name) use (&$collect, $hosts, $hooksEnabled) {
$task = $this->tasks->get($name);
if (!$task->shouldBePerformed(...array_values($hosts))) {
return [];
}
$relatedTasks = [];
if ($hooksEnabled) {
$relatedTasks = array_merge(array_map($collect, $task->getBefore()), $relatedTasks);
}
if ($task instanceof GroupTask) {
$relatedTasks = array_merge($relatedTasks, array_map($collect, $task->getGroup()));
} else {
$relatedTasks = array_merge($relatedTasks, [$task->getName()]);
}
if ($hooksEnabled) {
$relatedTasks = array_merge($relatedTasks, array_map($collect, $task->getAfter()));
}
return $relatedTasks;
};
$script = $collect($name);
$tasks = array_flatten($script);
// Convert names to real tasks
return array_map([$this->tasks, 'get'], $tasks);
}
|
[
"public",
"function",
"getTasks",
"(",
"$",
"name",
",",
"array",
"$",
"hosts",
"=",
"[",
"]",
",",
"$",
"hooksEnabled",
"=",
"true",
")",
"{",
"$",
"collect",
"=",
"function",
"(",
"$",
"name",
")",
"use",
"(",
"&",
"$",
"collect",
",",
"$",
"hosts",
",",
"$",
"hooksEnabled",
")",
"{",
"$",
"task",
"=",
"$",
"this",
"->",
"tasks",
"->",
"get",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"task",
"->",
"shouldBePerformed",
"(",
"...",
"array_values",
"(",
"$",
"hosts",
")",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"relatedTasks",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"hooksEnabled",
")",
"{",
"$",
"relatedTasks",
"=",
"array_merge",
"(",
"array_map",
"(",
"$",
"collect",
",",
"$",
"task",
"->",
"getBefore",
"(",
")",
")",
",",
"$",
"relatedTasks",
")",
";",
"}",
"if",
"(",
"$",
"task",
"instanceof",
"GroupTask",
")",
"{",
"$",
"relatedTasks",
"=",
"array_merge",
"(",
"$",
"relatedTasks",
",",
"array_map",
"(",
"$",
"collect",
",",
"$",
"task",
"->",
"getGroup",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"relatedTasks",
"=",
"array_merge",
"(",
"$",
"relatedTasks",
",",
"[",
"$",
"task",
"->",
"getName",
"(",
")",
"]",
")",
";",
"}",
"if",
"(",
"$",
"hooksEnabled",
")",
"{",
"$",
"relatedTasks",
"=",
"array_merge",
"(",
"$",
"relatedTasks",
",",
"array_map",
"(",
"$",
"collect",
",",
"$",
"task",
"->",
"getAfter",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"relatedTasks",
";",
"}",
";",
"$",
"script",
"=",
"$",
"collect",
"(",
"$",
"name",
")",
";",
"$",
"tasks",
"=",
"array_flatten",
"(",
"$",
"script",
")",
";",
"// Convert names to real tasks",
"return",
"array_map",
"(",
"[",
"$",
"this",
"->",
"tasks",
",",
"'get'",
"]",
",",
"$",
"tasks",
")",
";",
"}"
] |
Return tasks to run
@param string $name
@param Host[] $hosts
@param bool $hooksEnabled
@return Task[]
|
[
"Return",
"tasks",
"to",
"run"
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Task/ScriptManager.php#L36-L69
|
221,016
|
deployphp/deployer
|
src/Utility/Rsync.php
|
Rsync.call
|
public function call($hostname, $source, $destination, array $config = [])
{
$defaults = [
'timeout' => null,
'options' => [],
];
$config = array_merge($defaults, $config);
$escapedSource = escapeshellarg($source);
$escapedDestination = escapeshellarg($destination);
$rsync = "rsync -azP " . implode(' ', $config['options']) . " $escapedSource $escapedDestination";
$this->pop->command($hostname, $rsync);
$process = new Process($rsync);
$process
->setTimeout($config['timeout'])
->mustRun($this->pop->callback($hostname));
}
|
php
|
public function call($hostname, $source, $destination, array $config = [])
{
$defaults = [
'timeout' => null,
'options' => [],
];
$config = array_merge($defaults, $config);
$escapedSource = escapeshellarg($source);
$escapedDestination = escapeshellarg($destination);
$rsync = "rsync -azP " . implode(' ', $config['options']) . " $escapedSource $escapedDestination";
$this->pop->command($hostname, $rsync);
$process = new Process($rsync);
$process
->setTimeout($config['timeout'])
->mustRun($this->pop->callback($hostname));
}
|
[
"public",
"function",
"call",
"(",
"$",
"hostname",
",",
"$",
"source",
",",
"$",
"destination",
",",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'timeout'",
"=>",
"null",
",",
"'options'",
"=>",
"[",
"]",
",",
"]",
";",
"$",
"config",
"=",
"array_merge",
"(",
"$",
"defaults",
",",
"$",
"config",
")",
";",
"$",
"escapedSource",
"=",
"escapeshellarg",
"(",
"$",
"source",
")",
";",
"$",
"escapedDestination",
"=",
"escapeshellarg",
"(",
"$",
"destination",
")",
";",
"$",
"rsync",
"=",
"\"rsync -azP \"",
".",
"implode",
"(",
"' '",
",",
"$",
"config",
"[",
"'options'",
"]",
")",
".",
"\" $escapedSource $escapedDestination\"",
";",
"$",
"this",
"->",
"pop",
"->",
"command",
"(",
"$",
"hostname",
",",
"$",
"rsync",
")",
";",
"$",
"process",
"=",
"new",
"Process",
"(",
"$",
"rsync",
")",
";",
"$",
"process",
"->",
"setTimeout",
"(",
"$",
"config",
"[",
"'timeout'",
"]",
")",
"->",
"mustRun",
"(",
"$",
"this",
"->",
"pop",
"->",
"callback",
"(",
"$",
"hostname",
")",
")",
";",
"}"
] |
Start rsync process
@param $hostname
@param $source
@param $destination
@param array $config
|
[
"Start",
"rsync",
"process"
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Utility/Rsync.php#L32-L50
|
221,017
|
deployphp/deployer
|
src/Console/DebugCommand.php
|
DebugCommand.createTreeFromTaskName
|
private function createTreeFromTaskName($taskName, $postfix = '', $isLast = false)
{
$task = $this->tasks->get($taskName);
if ($task->getBefore()) {
$beforePostfix = sprintf(' [before:%s]', $task->getName());
foreach ($task->getBefore() as $beforeTask) {
$this->createTreeFromTaskName($beforeTask, $beforePostfix);
}
}
if ($task instanceof GroupTask) {
$isLast = $isLast && empty($task->getAfter());
$this->addTaskToTree($task->getName() . $postfix, $isLast);
if (!$isLast) {
$this->openGroupDepths[] = $this->depth;
}
$this->depth++;
$taskGroup = $task->getGroup();
foreach ($taskGroup as $subtask) {
$isLastSubtask = $subtask === end($taskGroup);
$this->createTreeFromTaskName($subtask, '', $isLastSubtask);
}
if (!$isLast) {
array_pop($this->openGroupDepths);
}
$this->depth--;
} else {
$this->addTaskToTree($task->getName() . $postfix, $isLast);
}
if ($task->getAfter()) {
$afterPostfix = sprintf(' [after:%s]', $task->getName());
foreach ($task->getAfter() as $afterTask) {
$this->createTreeFromTaskName($afterTask, $afterPostfix);
}
}
}
|
php
|
private function createTreeFromTaskName($taskName, $postfix = '', $isLast = false)
{
$task = $this->tasks->get($taskName);
if ($task->getBefore()) {
$beforePostfix = sprintf(' [before:%s]', $task->getName());
foreach ($task->getBefore() as $beforeTask) {
$this->createTreeFromTaskName($beforeTask, $beforePostfix);
}
}
if ($task instanceof GroupTask) {
$isLast = $isLast && empty($task->getAfter());
$this->addTaskToTree($task->getName() . $postfix, $isLast);
if (!$isLast) {
$this->openGroupDepths[] = $this->depth;
}
$this->depth++;
$taskGroup = $task->getGroup();
foreach ($taskGroup as $subtask) {
$isLastSubtask = $subtask === end($taskGroup);
$this->createTreeFromTaskName($subtask, '', $isLastSubtask);
}
if (!$isLast) {
array_pop($this->openGroupDepths);
}
$this->depth--;
} else {
$this->addTaskToTree($task->getName() . $postfix, $isLast);
}
if ($task->getAfter()) {
$afterPostfix = sprintf(' [after:%s]', $task->getName());
foreach ($task->getAfter() as $afterTask) {
$this->createTreeFromTaskName($afterTask, $afterPostfix);
}
}
}
|
[
"private",
"function",
"createTreeFromTaskName",
"(",
"$",
"taskName",
",",
"$",
"postfix",
"=",
"''",
",",
"$",
"isLast",
"=",
"false",
")",
"{",
"$",
"task",
"=",
"$",
"this",
"->",
"tasks",
"->",
"get",
"(",
"$",
"taskName",
")",
";",
"if",
"(",
"$",
"task",
"->",
"getBefore",
"(",
")",
")",
"{",
"$",
"beforePostfix",
"=",
"sprintf",
"(",
"' [before:%s]'",
",",
"$",
"task",
"->",
"getName",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"task",
"->",
"getBefore",
"(",
")",
"as",
"$",
"beforeTask",
")",
"{",
"$",
"this",
"->",
"createTreeFromTaskName",
"(",
"$",
"beforeTask",
",",
"$",
"beforePostfix",
")",
";",
"}",
"}",
"if",
"(",
"$",
"task",
"instanceof",
"GroupTask",
")",
"{",
"$",
"isLast",
"=",
"$",
"isLast",
"&&",
"empty",
"(",
"$",
"task",
"->",
"getAfter",
"(",
")",
")",
";",
"$",
"this",
"->",
"addTaskToTree",
"(",
"$",
"task",
"->",
"getName",
"(",
")",
".",
"$",
"postfix",
",",
"$",
"isLast",
")",
";",
"if",
"(",
"!",
"$",
"isLast",
")",
"{",
"$",
"this",
"->",
"openGroupDepths",
"[",
"]",
"=",
"$",
"this",
"->",
"depth",
";",
"}",
"$",
"this",
"->",
"depth",
"++",
";",
"$",
"taskGroup",
"=",
"$",
"task",
"->",
"getGroup",
"(",
")",
";",
"foreach",
"(",
"$",
"taskGroup",
"as",
"$",
"subtask",
")",
"{",
"$",
"isLastSubtask",
"=",
"$",
"subtask",
"===",
"end",
"(",
"$",
"taskGroup",
")",
";",
"$",
"this",
"->",
"createTreeFromTaskName",
"(",
"$",
"subtask",
",",
"''",
",",
"$",
"isLastSubtask",
")",
";",
"}",
"if",
"(",
"!",
"$",
"isLast",
")",
"{",
"array_pop",
"(",
"$",
"this",
"->",
"openGroupDepths",
")",
";",
"}",
"$",
"this",
"->",
"depth",
"--",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addTaskToTree",
"(",
"$",
"task",
"->",
"getName",
"(",
")",
".",
"$",
"postfix",
",",
"$",
"isLast",
")",
";",
"}",
"if",
"(",
"$",
"task",
"->",
"getAfter",
"(",
")",
")",
"{",
"$",
"afterPostfix",
"=",
"sprintf",
"(",
"' [after:%s]'",
",",
"$",
"task",
"->",
"getName",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"task",
"->",
"getAfter",
"(",
")",
"as",
"$",
"afterTask",
")",
"{",
"$",
"this",
"->",
"createTreeFromTaskName",
"(",
"$",
"afterTask",
",",
"$",
"afterPostfix",
")",
";",
"}",
"}",
"}"
] |
Create a tree from the given taskname
@param string $taskName
@param string $postfix
@param bool $isLast
@return void
|
[
"Create",
"a",
"tree",
"from",
"the",
"given",
"taskname"
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Console/DebugCommand.php#L107-L152
|
221,018
|
deployphp/deployer
|
src/Executor/ParallelExecutor.php
|
ParallelExecutor.runTask
|
private function runTask(array $hosts, Task $task): int
{
$processes = [];
foreach ($hosts as $host) {
if ($task->shouldBePerformed($host)) {
$processes[$host->getHostname()] = $this->getProcess($host, $task);
if ($task->isOnce()) {
$task->setHasRun();
}
}
}
$callback = function (string $type, string $host, string $output) {
$output = rtrim($output);
if (strlen($output) !== 0) {
$this->output->writeln($output);
}
};
$this->startProcesses($processes);
while ($this->areRunning($processes)) {
$this->gatherOutput($processes, $callback);
usleep(1000);
}
$this->gatherOutput($processes, $callback);
return $this->gatherExitCodes($processes);
}
|
php
|
private function runTask(array $hosts, Task $task): int
{
$processes = [];
foreach ($hosts as $host) {
if ($task->shouldBePerformed($host)) {
$processes[$host->getHostname()] = $this->getProcess($host, $task);
if ($task->isOnce()) {
$task->setHasRun();
}
}
}
$callback = function (string $type, string $host, string $output) {
$output = rtrim($output);
if (strlen($output) !== 0) {
$this->output->writeln($output);
}
};
$this->startProcesses($processes);
while ($this->areRunning($processes)) {
$this->gatherOutput($processes, $callback);
usleep(1000);
}
$this->gatherOutput($processes, $callback);
return $this->gatherExitCodes($processes);
}
|
[
"private",
"function",
"runTask",
"(",
"array",
"$",
"hosts",
",",
"Task",
"$",
"task",
")",
":",
"int",
"{",
"$",
"processes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"hosts",
"as",
"$",
"host",
")",
"{",
"if",
"(",
"$",
"task",
"->",
"shouldBePerformed",
"(",
"$",
"host",
")",
")",
"{",
"$",
"processes",
"[",
"$",
"host",
"->",
"getHostname",
"(",
")",
"]",
"=",
"$",
"this",
"->",
"getProcess",
"(",
"$",
"host",
",",
"$",
"task",
")",
";",
"if",
"(",
"$",
"task",
"->",
"isOnce",
"(",
")",
")",
"{",
"$",
"task",
"->",
"setHasRun",
"(",
")",
";",
"}",
"}",
"}",
"$",
"callback",
"=",
"function",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"host",
",",
"string",
"$",
"output",
")",
"{",
"$",
"output",
"=",
"rtrim",
"(",
"$",
"output",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"output",
")",
"!==",
"0",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"$",
"output",
")",
";",
"}",
"}",
";",
"$",
"this",
"->",
"startProcesses",
"(",
"$",
"processes",
")",
";",
"while",
"(",
"$",
"this",
"->",
"areRunning",
"(",
"$",
"processes",
")",
")",
"{",
"$",
"this",
"->",
"gatherOutput",
"(",
"$",
"processes",
",",
"$",
"callback",
")",
";",
"usleep",
"(",
"1000",
")",
";",
"}",
"$",
"this",
"->",
"gatherOutput",
"(",
"$",
"processes",
",",
"$",
"callback",
")",
";",
"return",
"$",
"this",
"->",
"gatherExitCodes",
"(",
"$",
"processes",
")",
";",
"}"
] |
Run task on hosts.
@param Host[] $hosts
|
[
"Run",
"task",
"on",
"hosts",
"."
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Executor/ParallelExecutor.php#L123-L152
|
221,019
|
deployphp/deployer
|
src/Executor/ParallelExecutor.php
|
ParallelExecutor.getProcess
|
protected function getProcess(Host $host, Task $task): Process
{
$dep = PHP_BINARY.' '.DEPLOYER_BIN;
$options = $this->generateOptions();
$arguments = $this->generateArguments();
$hostname = $host->getHostname();
$taskName = $task->getName();
$configFile = $host->get('host_config_storage');
$value = $this->input->getOption('file');
$file = $value ? "--file='$value'" : '';
if ($this->output->isDecorated()) {
$options .= ' --ansi';
}
$command = "$dep $file worker $arguments $options --hostname $hostname --task $taskName --config-file $configFile";
$process = new Process($command);
if (!defined('DEPLOYER_PARALLEL_PTY')) {
$process->setPty(true);
}
return $process;
}
|
php
|
protected function getProcess(Host $host, Task $task): Process
{
$dep = PHP_BINARY.' '.DEPLOYER_BIN;
$options = $this->generateOptions();
$arguments = $this->generateArguments();
$hostname = $host->getHostname();
$taskName = $task->getName();
$configFile = $host->get('host_config_storage');
$value = $this->input->getOption('file');
$file = $value ? "--file='$value'" : '';
if ($this->output->isDecorated()) {
$options .= ' --ansi';
}
$command = "$dep $file worker $arguments $options --hostname $hostname --task $taskName --config-file $configFile";
$process = new Process($command);
if (!defined('DEPLOYER_PARALLEL_PTY')) {
$process->setPty(true);
}
return $process;
}
|
[
"protected",
"function",
"getProcess",
"(",
"Host",
"$",
"host",
",",
"Task",
"$",
"task",
")",
":",
"Process",
"{",
"$",
"dep",
"=",
"PHP_BINARY",
".",
"' '",
".",
"DEPLOYER_BIN",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"generateOptions",
"(",
")",
";",
"$",
"arguments",
"=",
"$",
"this",
"->",
"generateArguments",
"(",
")",
";",
"$",
"hostname",
"=",
"$",
"host",
"->",
"getHostname",
"(",
")",
";",
"$",
"taskName",
"=",
"$",
"task",
"->",
"getName",
"(",
")",
";",
"$",
"configFile",
"=",
"$",
"host",
"->",
"get",
"(",
"'host_config_storage'",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"input",
"->",
"getOption",
"(",
"'file'",
")",
";",
"$",
"file",
"=",
"$",
"value",
"?",
"\"--file='$value'\"",
":",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"output",
"->",
"isDecorated",
"(",
")",
")",
"{",
"$",
"options",
".=",
"' --ansi'",
";",
"}",
"$",
"command",
"=",
"\"$dep $file worker $arguments $options --hostname $hostname --task $taskName --config-file $configFile\"",
";",
"$",
"process",
"=",
"new",
"Process",
"(",
"$",
"command",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"'DEPLOYER_PARALLEL_PTY'",
")",
")",
"{",
"$",
"process",
"->",
"setPty",
"(",
"true",
")",
";",
"}",
"return",
"$",
"process",
";",
"}"
] |
Get process for task on host.
|
[
"Get",
"process",
"for",
"task",
"on",
"host",
"."
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Executor/ParallelExecutor.php#L157-L180
|
221,020
|
deployphp/deployer
|
src/Executor/ParallelExecutor.php
|
ParallelExecutor.areRunning
|
protected function areRunning(array $processes): bool
{
foreach ($processes as $process) {
if ($process->isRunning()) {
return true;
}
}
return false;
}
|
php
|
protected function areRunning(array $processes): bool
{
foreach ($processes as $process) {
if ($process->isRunning()) {
return true;
}
}
return false;
}
|
[
"protected",
"function",
"areRunning",
"(",
"array",
"$",
"processes",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"processes",
"as",
"$",
"process",
")",
"{",
"if",
"(",
"$",
"process",
"->",
"isRunning",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Determine if any of the processes are running.
@param Process[] $processes
|
[
"Determine",
"if",
"any",
"of",
"the",
"processes",
"are",
"running",
"."
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Executor/ParallelExecutor.php#L201-L210
|
221,021
|
deployphp/deployer
|
src/Executor/ParallelExecutor.php
|
ParallelExecutor.generateOptions
|
private function generateOptions(): string
{
/** @var string[] $inputs */
$inputs = [
(string) (new VerbosityString($this->output)),
];
$userDefinition = $this->console->getUserDefinition();
// Get user arguments
foreach ($userDefinition->getArguments() as $argument) {
$inputs[] = Argument::toString($this->input, $argument);
}
// Get user options
foreach ($userDefinition->getOptions() as $option) {
$inputs[] = Option::toString($this->input, $option);
}
return implode(' ', array_filter($inputs, static function (string $item): bool {
return $item !== '';
}));
}
|
php
|
private function generateOptions(): string
{
/** @var string[] $inputs */
$inputs = [
(string) (new VerbosityString($this->output)),
];
$userDefinition = $this->console->getUserDefinition();
// Get user arguments
foreach ($userDefinition->getArguments() as $argument) {
$inputs[] = Argument::toString($this->input, $argument);
}
// Get user options
foreach ($userDefinition->getOptions() as $option) {
$inputs[] = Option::toString($this->input, $option);
}
return implode(' ', array_filter($inputs, static function (string $item): bool {
return $item !== '';
}));
}
|
[
"private",
"function",
"generateOptions",
"(",
")",
":",
"string",
"{",
"/** @var string[] $inputs */",
"$",
"inputs",
"=",
"[",
"(",
"string",
")",
"(",
"new",
"VerbosityString",
"(",
"$",
"this",
"->",
"output",
")",
")",
",",
"]",
";",
"$",
"userDefinition",
"=",
"$",
"this",
"->",
"console",
"->",
"getUserDefinition",
"(",
")",
";",
"// Get user arguments",
"foreach",
"(",
"$",
"userDefinition",
"->",
"getArguments",
"(",
")",
"as",
"$",
"argument",
")",
"{",
"$",
"inputs",
"[",
"]",
"=",
"Argument",
"::",
"toString",
"(",
"$",
"this",
"->",
"input",
",",
"$",
"argument",
")",
";",
"}",
"// Get user options",
"foreach",
"(",
"$",
"userDefinition",
"->",
"getOptions",
"(",
")",
"as",
"$",
"option",
")",
"{",
"$",
"inputs",
"[",
"]",
"=",
"Option",
"::",
"toString",
"(",
"$",
"this",
"->",
"input",
",",
"$",
"option",
")",
";",
"}",
"return",
"implode",
"(",
"' '",
",",
"array_filter",
"(",
"$",
"inputs",
",",
"static",
"function",
"(",
"string",
"$",
"item",
")",
":",
"bool",
"{",
"return",
"$",
"item",
"!==",
"''",
";",
"}",
")",
")",
";",
"}"
] |
Generate options and arguments string.
|
[
"Generate",
"options",
"and",
"arguments",
"string",
"."
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Executor/ParallelExecutor.php#L253-L274
|
221,022
|
deployphp/deployer
|
src/Initializer/Exception/TemplateNotFoundException.php
|
TemplateNotFoundException.create
|
public static function create($template, array $availableTemplates, $code = 0, \Exception $prev = null)
{
return new static(sprintf(
'Not found template with name "%s". Available templates: "%s"',
$template,
implode('", "', $availableTemplates)
), $code, $prev);
}
|
php
|
public static function create($template, array $availableTemplates, $code = 0, \Exception $prev = null)
{
return new static(sprintf(
'Not found template with name "%s". Available templates: "%s"',
$template,
implode('", "', $availableTemplates)
), $code, $prev);
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"template",
",",
"array",
"$",
"availableTemplates",
",",
"$",
"code",
"=",
"0",
",",
"\\",
"Exception",
"$",
"prev",
"=",
"null",
")",
"{",
"return",
"new",
"static",
"(",
"sprintf",
"(",
"'Not found template with name \"%s\". Available templates: \"%s\"'",
",",
"$",
"template",
",",
"implode",
"(",
"'\", \"'",
",",
"$",
"availableTemplates",
")",
")",
",",
"$",
"code",
",",
"$",
"prev",
")",
";",
"}"
] |
Create a new exception via template name
@param string $template
@param array $availableTemplates
@param int $code
@param \Exception $prev
@return TemplateNotFoundException
|
[
"Create",
"a",
"new",
"exception",
"via",
"template",
"name"
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Initializer/Exception/TemplateNotFoundException.php#L27-L34
|
221,023
|
deployphp/deployer
|
src/Console/Application.php
|
Application.addUserArgumentsAndOptions
|
public function addUserArgumentsAndOptions()
{
$this->getDefinition()->addArguments($this->getUserDefinition()->getArguments());
$this->getDefinition()->addOptions($this->getUserDefinition()->getOptions());
}
|
php
|
public function addUserArgumentsAndOptions()
{
$this->getDefinition()->addArguments($this->getUserDefinition()->getArguments());
$this->getDefinition()->addOptions($this->getUserDefinition()->getOptions());
}
|
[
"public",
"function",
"addUserArgumentsAndOptions",
"(",
")",
"{",
"$",
"this",
"->",
"getDefinition",
"(",
")",
"->",
"addArguments",
"(",
"$",
"this",
"->",
"getUserDefinition",
"(",
")",
"->",
"getArguments",
"(",
")",
")",
";",
"$",
"this",
"->",
"getDefinition",
"(",
")",
"->",
"addOptions",
"(",
"$",
"this",
"->",
"getUserDefinition",
"(",
")",
"->",
"getOptions",
"(",
")",
")",
";",
"}"
] |
Add user definition arguments and options to definition.
|
[
"Add",
"user",
"definition",
"arguments",
"and",
"options",
"to",
"definition",
"."
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Console/Application.php#L106-L110
|
221,024
|
deployphp/deployer
|
src/Task/Task.php
|
Task.shouldBePerformed
|
public function shouldBePerformed(...$hosts)
{
// don't allow to run again it the task has been marked to run only once
if ($this->once && $this->hasRun) {
return false;
}
foreach ($hosts as $host) {
$onHost = empty($this->on['hosts']) || in_array($host->getHostname(), $this->on['hosts'], true);
$onRole = empty($this->on['roles']);
foreach ((array) $host->get('roles', []) as $role) {
if (in_array($role, $this->on['roles'], true)) {
$onRole = true;
}
}
$onStage = empty($this->on['stages']);
if ($host->has('stage')) {
if (in_array($host->get('stage'), $this->on['stages'], true)) {
$onStage = true;
}
}
if ($onHost && $onRole && $onStage) {
return true;
}
}
return empty($hosts);
}
|
php
|
public function shouldBePerformed(...$hosts)
{
// don't allow to run again it the task has been marked to run only once
if ($this->once && $this->hasRun) {
return false;
}
foreach ($hosts as $host) {
$onHost = empty($this->on['hosts']) || in_array($host->getHostname(), $this->on['hosts'], true);
$onRole = empty($this->on['roles']);
foreach ((array) $host->get('roles', []) as $role) {
if (in_array($role, $this->on['roles'], true)) {
$onRole = true;
}
}
$onStage = empty($this->on['stages']);
if ($host->has('stage')) {
if (in_array($host->get('stage'), $this->on['stages'], true)) {
$onStage = true;
}
}
if ($onHost && $onRole && $onStage) {
return true;
}
}
return empty($hosts);
}
|
[
"public",
"function",
"shouldBePerformed",
"(",
"...",
"$",
"hosts",
")",
"{",
"// don't allow to run again it the task has been marked to run only once",
"if",
"(",
"$",
"this",
"->",
"once",
"&&",
"$",
"this",
"->",
"hasRun",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"hosts",
"as",
"$",
"host",
")",
"{",
"$",
"onHost",
"=",
"empty",
"(",
"$",
"this",
"->",
"on",
"[",
"'hosts'",
"]",
")",
"||",
"in_array",
"(",
"$",
"host",
"->",
"getHostname",
"(",
")",
",",
"$",
"this",
"->",
"on",
"[",
"'hosts'",
"]",
",",
"true",
")",
";",
"$",
"onRole",
"=",
"empty",
"(",
"$",
"this",
"->",
"on",
"[",
"'roles'",
"]",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"host",
"->",
"get",
"(",
"'roles'",
",",
"[",
"]",
")",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"role",
",",
"$",
"this",
"->",
"on",
"[",
"'roles'",
"]",
",",
"true",
")",
")",
"{",
"$",
"onRole",
"=",
"true",
";",
"}",
"}",
"$",
"onStage",
"=",
"empty",
"(",
"$",
"this",
"->",
"on",
"[",
"'stages'",
"]",
")",
";",
"if",
"(",
"$",
"host",
"->",
"has",
"(",
"'stage'",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"host",
"->",
"get",
"(",
"'stage'",
")",
",",
"$",
"this",
"->",
"on",
"[",
"'stages'",
"]",
",",
"true",
")",
")",
"{",
"$",
"onStage",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"onHost",
"&&",
"$",
"onRole",
"&&",
"$",
"onStage",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"empty",
"(",
"$",
"hosts",
")",
";",
"}"
] |
Checks what task should be performed on one of hosts.
@param Host[] $hosts
@return bool
|
[
"Checks",
"what",
"task",
"should",
"be",
"performed",
"on",
"one",
"of",
"hosts",
"."
] |
eec02040d23d5bde05c9be843d17f961b9374102
|
https://github.com/deployphp/deployer/blob/eec02040d23d5bde05c9be843d17f961b9374102/src/Task/Task.php#L211-L241
|
221,025
|
tenancy/multi-tenant
|
src/Commands/RecreateCommand.php
|
RecreateCommand.tenantDatabaseExists
|
protected function tenantDatabaseExists(Website $website) : bool
{
try {
$this->connection->set($website);
$schema = $this->connection->get()->getSchemaBuilder();
if ($schema->hasTable($this->table)) {
return true;
}
} catch (\Exception $e) {
// Suppress exception
}
return false;
}
|
php
|
protected function tenantDatabaseExists(Website $website) : bool
{
try {
$this->connection->set($website);
$schema = $this->connection->get()->getSchemaBuilder();
if ($schema->hasTable($this->table)) {
return true;
}
} catch (\Exception $e) {
// Suppress exception
}
return false;
}
|
[
"protected",
"function",
"tenantDatabaseExists",
"(",
"Website",
"$",
"website",
")",
":",
"bool",
"{",
"try",
"{",
"$",
"this",
"->",
"connection",
"->",
"set",
"(",
"$",
"website",
")",
";",
"$",
"schema",
"=",
"$",
"this",
"->",
"connection",
"->",
"get",
"(",
")",
"->",
"getSchemaBuilder",
"(",
")",
";",
"if",
"(",
"$",
"schema",
"->",
"hasTable",
"(",
"$",
"this",
"->",
"table",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// Suppress exception",
"}",
"return",
"false",
";",
"}"
] |
Checks if tenant database exists.
@param Website $website
@return bool
|
[
"Checks",
"if",
"tenant",
"database",
"exists",
"."
] |
5628006169368a33caf97b9d6788283c832a8a82
|
https://github.com/tenancy/multi-tenant/blob/5628006169368a33caf97b9d6788283c832a8a82/src/Commands/RecreateCommand.php#L82-L97
|
221,026
|
tenancy/multi-tenant
|
src/Generators/Filesystem/DirectoryGenerator.php
|
DirectoryGenerator.created
|
public function created(Events\Created $event): bool
{
if (config('tenancy.website.auto-create-tenant-directory')) {
$stat = $this->filesystem()->makeDirectory($event->website->uuid);
if ($stat) {
$this->emitEvent(
new DirectoryCreated($event->website, $this->filesystem())
);
}
return $stat;
}
return true;
}
|
php
|
public function created(Events\Created $event): bool
{
if (config('tenancy.website.auto-create-tenant-directory')) {
$stat = $this->filesystem()->makeDirectory($event->website->uuid);
if ($stat) {
$this->emitEvent(
new DirectoryCreated($event->website, $this->filesystem())
);
}
return $stat;
}
return true;
}
|
[
"public",
"function",
"created",
"(",
"Events",
"\\",
"Created",
"$",
"event",
")",
":",
"bool",
"{",
"if",
"(",
"config",
"(",
"'tenancy.website.auto-create-tenant-directory'",
")",
")",
"{",
"$",
"stat",
"=",
"$",
"this",
"->",
"filesystem",
"(",
")",
"->",
"makeDirectory",
"(",
"$",
"event",
"->",
"website",
"->",
"uuid",
")",
";",
"if",
"(",
"$",
"stat",
")",
"{",
"$",
"this",
"->",
"emitEvent",
"(",
"new",
"DirectoryCreated",
"(",
"$",
"event",
"->",
"website",
",",
"$",
"this",
"->",
"filesystem",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"stat",
";",
"}",
"return",
"true",
";",
"}"
] |
Mutates the service based on a website being enabled.
@param Events\Created $event
@return bool
|
[
"Mutates",
"the",
"service",
"based",
"on",
"a",
"website",
"being",
"enabled",
"."
] |
5628006169368a33caf97b9d6788283c832a8a82
|
https://github.com/tenancy/multi-tenant/blob/5628006169368a33caf97b9d6788283c832a8a82/src/Generators/Filesystem/DirectoryGenerator.php#L54-L69
|
221,027
|
tenancy/multi-tenant
|
src/Generators/Filesystem/DirectoryGenerator.php
|
DirectoryGenerator.deleted
|
public function deleted(Events\Deleted $event): bool
{
if (config('tenancy.website.auto-delete-tenant-directory')) {
$stat = $this->filesystem()->deleteDirectory($event->website->uuid);
if ($stat) {
$this->emitEvent(
new DirectoryDeleted($event->website, $this->filesystem())
);
}
return $stat;
}
return true;
}
|
php
|
public function deleted(Events\Deleted $event): bool
{
if (config('tenancy.website.auto-delete-tenant-directory')) {
$stat = $this->filesystem()->deleteDirectory($event->website->uuid);
if ($stat) {
$this->emitEvent(
new DirectoryDeleted($event->website, $this->filesystem())
);
}
return $stat;
}
return true;
}
|
[
"public",
"function",
"deleted",
"(",
"Events",
"\\",
"Deleted",
"$",
"event",
")",
":",
"bool",
"{",
"if",
"(",
"config",
"(",
"'tenancy.website.auto-delete-tenant-directory'",
")",
")",
"{",
"$",
"stat",
"=",
"$",
"this",
"->",
"filesystem",
"(",
")",
"->",
"deleteDirectory",
"(",
"$",
"event",
"->",
"website",
"->",
"uuid",
")",
";",
"if",
"(",
"$",
"stat",
")",
"{",
"$",
"this",
"->",
"emitEvent",
"(",
"new",
"DirectoryDeleted",
"(",
"$",
"event",
"->",
"website",
",",
"$",
"this",
"->",
"filesystem",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"stat",
";",
"}",
"return",
"true",
";",
"}"
] |
Acts on this service whenever a website is disabled.
@param Events\Deleted $event
@return bool
|
[
"Acts",
"on",
"this",
"service",
"whenever",
"a",
"website",
"is",
"disabled",
"."
] |
5628006169368a33caf97b9d6788283c832a8a82
|
https://github.com/tenancy/multi-tenant/blob/5628006169368a33caf97b9d6788283c832a8a82/src/Generators/Filesystem/DirectoryGenerator.php#L103-L118
|
221,028
|
tenancy/multi-tenant
|
src/Environment.php
|
Environment.hostname
|
public function hostname(Hostname $hostname = null): ?Hostname
{
if ($hostname !== null) {
$this->app->instance(CurrentHostname::class, $hostname);
$this->emitEvent(new Events\Hostnames\Switched($hostname));
return $hostname;
}
return $this->app->make(CurrentHostname::class);
}
|
php
|
public function hostname(Hostname $hostname = null): ?Hostname
{
if ($hostname !== null) {
$this->app->instance(CurrentHostname::class, $hostname);
$this->emitEvent(new Events\Hostnames\Switched($hostname));
return $hostname;
}
return $this->app->make(CurrentHostname::class);
}
|
[
"public",
"function",
"hostname",
"(",
"Hostname",
"$",
"hostname",
"=",
"null",
")",
":",
"?",
"Hostname",
"{",
"if",
"(",
"$",
"hostname",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"instance",
"(",
"CurrentHostname",
"::",
"class",
",",
"$",
"hostname",
")",
";",
"$",
"this",
"->",
"emitEvent",
"(",
"new",
"Events",
"\\",
"Hostnames",
"\\",
"Switched",
"(",
"$",
"hostname",
")",
")",
";",
"return",
"$",
"hostname",
";",
"}",
"return",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"CurrentHostname",
"::",
"class",
")",
";",
"}"
] |
Get or set the current hostname.
@param Hostname|null $hostname
@return Hostname|null
|
[
"Get",
"or",
"set",
"the",
"current",
"hostname",
"."
] |
5628006169368a33caf97b9d6788283c832a8a82
|
https://github.com/tenancy/multi-tenant/blob/5628006169368a33caf97b9d6788283c832a8a82/src/Environment.php#L94-L105
|
221,029
|
tenancy/multi-tenant
|
src/Environment.php
|
Environment.tenant
|
public function tenant(Website $website = null): ?Website
{
if ($website !== null) {
$this->app->instance(Tenant::class, $website);
$this->emitEvent(new Events\Websites\Switched($website));
return $website;
}
return $this->app->make(Tenant::class);
}
|
php
|
public function tenant(Website $website = null): ?Website
{
if ($website !== null) {
$this->app->instance(Tenant::class, $website);
$this->emitEvent(new Events\Websites\Switched($website));
return $website;
}
return $this->app->make(Tenant::class);
}
|
[
"public",
"function",
"tenant",
"(",
"Website",
"$",
"website",
"=",
"null",
")",
":",
"?",
"Website",
"{",
"if",
"(",
"$",
"website",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"instance",
"(",
"Tenant",
"::",
"class",
",",
"$",
"website",
")",
";",
"$",
"this",
"->",
"emitEvent",
"(",
"new",
"Events",
"\\",
"Websites",
"\\",
"Switched",
"(",
"$",
"website",
")",
")",
";",
"return",
"$",
"website",
";",
"}",
"return",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Tenant",
"::",
"class",
")",
";",
"}"
] |
Get or set current tenant.
@param Website|null $website
@return Tenant|null
|
[
"Get",
"or",
"set",
"current",
"tenant",
"."
] |
5628006169368a33caf97b9d6788283c832a8a82
|
https://github.com/tenancy/multi-tenant/blob/5628006169368a33caf97b9d6788283c832a8a82/src/Environment.php#L120-L131
|
221,030
|
tenancy/multi-tenant
|
src/Abstracts/AbstractTenantDirectoryListener.php
|
AbstractTenantDirectoryListener.proxy
|
public function proxy(WebsiteEvent $event)
{
if ($event->website) {
$this->directory($event->website);
} elseif ($this->requiresWebsite) {
return;
}
if ($this->requiresPath && !$this->exists()) {
return;
}
$result = $this->load($event);
// Possible after processing.
return $result;
}
|
php
|
public function proxy(WebsiteEvent $event)
{
if ($event->website) {
$this->directory($event->website);
} elseif ($this->requiresWebsite) {
return;
}
if ($this->requiresPath && !$this->exists()) {
return;
}
$result = $this->load($event);
// Possible after processing.
return $result;
}
|
[
"public",
"function",
"proxy",
"(",
"WebsiteEvent",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"event",
"->",
"website",
")",
"{",
"$",
"this",
"->",
"directory",
"(",
"$",
"event",
"->",
"website",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"requiresWebsite",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"requiresPath",
"&&",
"!",
"$",
"this",
"->",
"exists",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"load",
"(",
"$",
"event",
")",
";",
"// Possible after processing.",
"return",
"$",
"result",
";",
"}"
] |
Proxies fired events to configure the handler.
@param WebsiteEvent $event
|
[
"Proxies",
"fired",
"events",
"to",
"configure",
"the",
"handler",
"."
] |
5628006169368a33caf97b9d6788283c832a8a82
|
https://github.com/tenancy/multi-tenant/blob/5628006169368a33caf97b9d6788283c832a8a82/src/Abstracts/AbstractTenantDirectoryListener.php#L84-L101
|
221,031
|
tenancy/multi-tenant
|
src/Database/Connection.php
|
Connection.exists
|
public function exists(string $connection = null): bool
{
$connection = $connection ?? $this->tenantName();
return Arr::has($this->db->getConnections(), $connection);
}
|
php
|
public function exists(string $connection = null): bool
{
$connection = $connection ?? $this->tenantName();
return Arr::has($this->db->getConnections(), $connection);
}
|
[
"public",
"function",
"exists",
"(",
"string",
"$",
"connection",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"connection",
"=",
"$",
"connection",
"??",
"$",
"this",
"->",
"tenantName",
"(",
")",
";",
"return",
"Arr",
"::",
"has",
"(",
"$",
"this",
"->",
"db",
"->",
"getConnections",
"(",
")",
",",
"$",
"connection",
")",
";",
"}"
] |
Checks whether a connection has been set up.
@param string|null $connection
@return bool
|
[
"Checks",
"whether",
"a",
"connection",
"has",
"been",
"set",
"up",
"."
] |
5628006169368a33caf97b9d6788283c832a8a82
|
https://github.com/tenancy/multi-tenant/blob/5628006169368a33caf97b9d6788283c832a8a82/src/Database/Connection.php#L127-L132
|
221,032
|
tenancy/multi-tenant
|
src/Database/Connection.php
|
Connection.system
|
public function system($for = null): \Illuminate\Database\Connection
{
$website = $this->convertWebsiteOrHostnameToWebsite($for);
return $this->db->connection(
$website && $website->managed_by_database_connection ?
$website->managed_by_database_connection :
$this->systemName()
);
}
|
php
|
public function system($for = null): \Illuminate\Database\Connection
{
$website = $this->convertWebsiteOrHostnameToWebsite($for);
return $this->db->connection(
$website && $website->managed_by_database_connection ?
$website->managed_by_database_connection :
$this->systemName()
);
}
|
[
"public",
"function",
"system",
"(",
"$",
"for",
"=",
"null",
")",
":",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Connection",
"{",
"$",
"website",
"=",
"$",
"this",
"->",
"convertWebsiteOrHostnameToWebsite",
"(",
"$",
"for",
")",
";",
"return",
"$",
"this",
"->",
"db",
"->",
"connection",
"(",
"$",
"website",
"&&",
"$",
"website",
"->",
"managed_by_database_connection",
"?",
"$",
"website",
"->",
"managed_by_database_connection",
":",
"$",
"this",
"->",
"systemName",
"(",
")",
")",
";",
"}"
] |
Gets the system connection.
@param Hostname|Website|null $for The hostname or website for which to retrieve a system connection.
@return \Illuminate\Database\Connection
|
[
"Gets",
"the",
"system",
"connection",
"."
] |
5628006169368a33caf97b9d6788283c832a8a82
|
https://github.com/tenancy/multi-tenant/blob/5628006169368a33caf97b9d6788283c832a8a82/src/Database/Connection.php#L197-L206
|
221,033
|
tenancy/multi-tenant
|
src/Database/Connection.php
|
Connection.purge
|
public function purge($connection = null)
{
$connection = $connection ?? $this->tenantName();
$this->db->purge(
$connection
);
$this->config->set(
sprintf('database.connections.%s', $connection),
[]
);
}
|
php
|
public function purge($connection = null)
{
$connection = $connection ?? $this->tenantName();
$this->db->purge(
$connection
);
$this->config->set(
sprintf('database.connections.%s', $connection),
[]
);
}
|
[
"public",
"function",
"purge",
"(",
"$",
"connection",
"=",
"null",
")",
"{",
"$",
"connection",
"=",
"$",
"connection",
"??",
"$",
"this",
"->",
"tenantName",
"(",
")",
";",
"$",
"this",
"->",
"db",
"->",
"purge",
"(",
"$",
"connection",
")",
";",
"$",
"this",
"->",
"config",
"->",
"set",
"(",
"sprintf",
"(",
"'database.connections.%s'",
",",
"$",
"connection",
")",
",",
"[",
"]",
")",
";",
"}"
] |
Purges the current tenant connection.
@param null $connection
|
[
"Purges",
"the",
"current",
"tenant",
"connection",
"."
] |
5628006169368a33caf97b9d6788283c832a8a82
|
https://github.com/tenancy/multi-tenant/blob/5628006169368a33caf97b9d6788283c832a8a82/src/Database/Connection.php#L228-L240
|
221,034
|
tenancy/multi-tenant
|
src/Website/Directory.php
|
Directory.copy
|
public function copy($from, $to)
{
return $this->filesystem->copy(
$this->path($from),
$this->path($to)
);
}
|
php
|
public function copy($from, $to)
{
return $this->filesystem->copy(
$this->path($from),
$this->path($to)
);
}
|
[
"public",
"function",
"copy",
"(",
"$",
"from",
",",
"$",
"to",
")",
"{",
"return",
"$",
"this",
"->",
"filesystem",
"->",
"copy",
"(",
"$",
"this",
"->",
"path",
"(",
"$",
"from",
")",
",",
"$",
"this",
"->",
"path",
"(",
"$",
"to",
")",
")",
";",
"}"
] |
Copy a file to a new location.
@param string $from
@param string $to
@return bool
|
[
"Copy",
"a",
"file",
"to",
"a",
"new",
"location",
"."
] |
5628006169368a33caf97b9d6788283c832a8a82
|
https://github.com/tenancy/multi-tenant/blob/5628006169368a33caf97b9d6788283c832a8a82/src/Website/Directory.php#L217-L223
|
221,035
|
Sylius/Sylius
|
src/Sylius/Bundle/CoreBundle/Routing/Matcher/Dumper/PhpMatcherDumper.php
|
PhpMatcherDumper.generateMatchMethod
|
private function generateMatchMethod(bool $supportsRedirections): string
{
// Group hosts by same-suffix, re-order when possible
$matchHost = false;
$routes = new StaticPrefixCollection();
foreach ($this->getRoutes()->all() as $name => $route) {
if ($host = $route->getHost()) {
$matchHost = true;
$host = '/' . strtr(strrev($host), '}.{', '(/)');
}
$routes->addRoute($host ?: '/(.*)', [$name, $route]);
}
$routes = $matchHost ? $routes->populateCollection(new RouteCollection()) : $this->getRoutes();
$code = rtrim($this->compileRoutes($routes, $matchHost), "\n");
$fetchHost = $matchHost ? " \$host = strtolower(\$context->getHost());\n" : '';
$code = <<<EOF
{
\$allow = \$allowSchemes = array();
\$pathinfo = rawurldecode(\$rawPathinfo);
\$context = \$this->context;
\$requestMethod = \$canonicalMethod = \$context->getMethod();
{$fetchHost}
if ('HEAD' === \$requestMethod) {
\$canonicalMethod = 'GET';
}
$code
EOF;
if ($supportsRedirections) {
return <<<'EOF'
public function match($pathinfo)
{
$allow = $allowSchemes = array();
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $ret;
}
if ($allow) {
throw new MethodNotAllowedException(array_keys($allow));
}
if (!in_array($this->context->getMethod(), array('HEAD', 'GET'), true)) {
// no-op
} elseif ($allowSchemes) {
redirect_scheme:
$scheme = $this->context->getScheme();
$this->context->setScheme(key($allowSchemes));
try {
if ($ret = $this->doMatch($pathinfo)) {
return $this->redirect($pathinfo, $ret['_route'], $this->context->getScheme()) + $ret;
}
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' !== $pathinfo) {
$pathinfo = '/' !== $pathinfo[-1] ? $pathinfo.'/' : substr($pathinfo, 0, -1);
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $this->redirect($pathinfo, $ret['_route']) + $ret;
}
if ($allowSchemes) {
goto redirect_scheme;
}
}
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
EOF
. $code . "\n return null;\n }";
}
return " public function match(\$rawPathinfo)\n" . $code . "\n throw \$allow ? new MethodNotAllowedException(array_keys(\$allow)) : new ResourceNotFoundException();\n }";
}
|
php
|
private function generateMatchMethod(bool $supportsRedirections): string
{
// Group hosts by same-suffix, re-order when possible
$matchHost = false;
$routes = new StaticPrefixCollection();
foreach ($this->getRoutes()->all() as $name => $route) {
if ($host = $route->getHost()) {
$matchHost = true;
$host = '/' . strtr(strrev($host), '}.{', '(/)');
}
$routes->addRoute($host ?: '/(.*)', [$name, $route]);
}
$routes = $matchHost ? $routes->populateCollection(new RouteCollection()) : $this->getRoutes();
$code = rtrim($this->compileRoutes($routes, $matchHost), "\n");
$fetchHost = $matchHost ? " \$host = strtolower(\$context->getHost());\n" : '';
$code = <<<EOF
{
\$allow = \$allowSchemes = array();
\$pathinfo = rawurldecode(\$rawPathinfo);
\$context = \$this->context;
\$requestMethod = \$canonicalMethod = \$context->getMethod();
{$fetchHost}
if ('HEAD' === \$requestMethod) {
\$canonicalMethod = 'GET';
}
$code
EOF;
if ($supportsRedirections) {
return <<<'EOF'
public function match($pathinfo)
{
$allow = $allowSchemes = array();
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $ret;
}
if ($allow) {
throw new MethodNotAllowedException(array_keys($allow));
}
if (!in_array($this->context->getMethod(), array('HEAD', 'GET'), true)) {
// no-op
} elseif ($allowSchemes) {
redirect_scheme:
$scheme = $this->context->getScheme();
$this->context->setScheme(key($allowSchemes));
try {
if ($ret = $this->doMatch($pathinfo)) {
return $this->redirect($pathinfo, $ret['_route'], $this->context->getScheme()) + $ret;
}
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' !== $pathinfo) {
$pathinfo = '/' !== $pathinfo[-1] ? $pathinfo.'/' : substr($pathinfo, 0, -1);
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $this->redirect($pathinfo, $ret['_route']) + $ret;
}
if ($allowSchemes) {
goto redirect_scheme;
}
}
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
EOF
. $code . "\n return null;\n }";
}
return " public function match(\$rawPathinfo)\n" . $code . "\n throw \$allow ? new MethodNotAllowedException(array_keys(\$allow)) : new ResourceNotFoundException();\n }";
}
|
[
"private",
"function",
"generateMatchMethod",
"(",
"bool",
"$",
"supportsRedirections",
")",
":",
"string",
"{",
"// Group hosts by same-suffix, re-order when possible",
"$",
"matchHost",
"=",
"false",
";",
"$",
"routes",
"=",
"new",
"StaticPrefixCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getRoutes",
"(",
")",
"->",
"all",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"host",
"=",
"$",
"route",
"->",
"getHost",
"(",
")",
")",
"{",
"$",
"matchHost",
"=",
"true",
";",
"$",
"host",
"=",
"'/'",
".",
"strtr",
"(",
"strrev",
"(",
"$",
"host",
")",
",",
"'}.{'",
",",
"'(/)'",
")",
";",
"}",
"$",
"routes",
"->",
"addRoute",
"(",
"$",
"host",
"?",
":",
"'/(.*)'",
",",
"[",
"$",
"name",
",",
"$",
"route",
"]",
")",
";",
"}",
"$",
"routes",
"=",
"$",
"matchHost",
"?",
"$",
"routes",
"->",
"populateCollection",
"(",
"new",
"RouteCollection",
"(",
")",
")",
":",
"$",
"this",
"->",
"getRoutes",
"(",
")",
";",
"$",
"code",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"compileRoutes",
"(",
"$",
"routes",
",",
"$",
"matchHost",
")",
",",
"\"\\n\"",
")",
";",
"$",
"fetchHost",
"=",
"$",
"matchHost",
"?",
"\" \\$host = strtolower(\\$context->getHost());\\n\"",
":",
"''",
";",
"$",
"code",
"=",
" <<<EOF\n {\n \\$allow = \\$allowSchemes = array();\n \\$pathinfo = rawurldecode(\\$rawPathinfo);\n \\$context = \\$this->context;\n \\$requestMethod = \\$canonicalMethod = \\$context->getMethod();\n{$fetchHost}\n if ('HEAD' === \\$requestMethod) {\n \\$canonicalMethod = 'GET';\n }\n\n$code\n\nEOF",
";",
"if",
"(",
"$",
"supportsRedirections",
")",
"{",
"return",
" <<<'EOF'\n public function match($pathinfo)\n {\n $allow = $allowSchemes = array();\n if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {\n return $ret;\n }\n if ($allow) {\n throw new MethodNotAllowedException(array_keys($allow));\n }\n if (!in_array($this->context->getMethod(), array('HEAD', 'GET'), true)) {\n // no-op\n } elseif ($allowSchemes) {\n redirect_scheme:\n $scheme = $this->context->getScheme();\n $this->context->setScheme(key($allowSchemes));\n try {\n if ($ret = $this->doMatch($pathinfo)) {\n return $this->redirect($pathinfo, $ret['_route'], $this->context->getScheme()) + $ret;\n }\n } finally {\n $this->context->setScheme($scheme);\n }\n } elseif ('/' !== $pathinfo) {\n $pathinfo = '/' !== $pathinfo[-1] ? $pathinfo.'/' : substr($pathinfo, 0, -1);\n if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {\n return $this->redirect($pathinfo, $ret['_route']) + $ret;\n }\n if ($allowSchemes) {\n goto redirect_scheme;\n }\n }\n\n throw new ResourceNotFoundException();\n }\n\n private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array\n\nEOF",
".",
"$",
"code",
".",
"\"\\n return null;\\n }\"",
";",
"}",
"return",
"\" public function match(\\$rawPathinfo)\\n\"",
".",
"$",
"code",
".",
"\"\\n throw \\$allow ? new MethodNotAllowedException(array_keys(\\$allow)) : new ResourceNotFoundException();\\n }\"",
";",
"}"
] |
Generates the code for the match method implementing UrlMatcherInterface.
|
[
"Generates",
"the",
"code",
"for",
"the",
"match",
"method",
"implementing",
"UrlMatcherInterface",
"."
] |
8b26d4188fa81bb488612f59d2418b9472be1c79
|
https://github.com/Sylius/Sylius/blob/8b26d4188fa81bb488612f59d2418b9472be1c79/src/Sylius/Bundle/CoreBundle/Routing/Matcher/Dumper/PhpMatcherDumper.php#L93-L170
|
221,036
|
Sylius/Sylius
|
src/Sylius/Bundle/CoreBundle/Routing/Matcher/Dumper/PhpMatcherDumper.php
|
PhpMatcherDumper.compileRoutes
|
private function compileRoutes(RouteCollection $routes, bool $matchHost): string
{
[$staticRoutes, $dynamicRoutes] = $this->groupStaticRoutes($routes);
$code = $this->compileStaticRoutes($staticRoutes, $matchHost);
$chunkLimit = \count($dynamicRoutes);
while (true) {
try {
$this->signalingException = new \RuntimeException('preg_match(): Compilation failed: regular expression is too large');
$code .= $this->compileDynamicRoutes($dynamicRoutes, $matchHost, $chunkLimit);
break;
} catch (\Exception $e) {
if (1 < $chunkLimit && $this->signalingException === $e) {
$chunkLimit = 1 + ($chunkLimit >> 1);
continue;
}
throw $e;
}
}
// used to display the Welcome Page in apps that don't define a homepage
$code .= " if ('/' === \$pathinfo && !\$allow && !\$allowSchemes) {\n";
$code .= " throw new Symfony\Component\Routing\Exception\NoConfigurationException();\n";
$code .= " }\n";
return $code;
}
|
php
|
private function compileRoutes(RouteCollection $routes, bool $matchHost): string
{
[$staticRoutes, $dynamicRoutes] = $this->groupStaticRoutes($routes);
$code = $this->compileStaticRoutes($staticRoutes, $matchHost);
$chunkLimit = \count($dynamicRoutes);
while (true) {
try {
$this->signalingException = new \RuntimeException('preg_match(): Compilation failed: regular expression is too large');
$code .= $this->compileDynamicRoutes($dynamicRoutes, $matchHost, $chunkLimit);
break;
} catch (\Exception $e) {
if (1 < $chunkLimit && $this->signalingException === $e) {
$chunkLimit = 1 + ($chunkLimit >> 1);
continue;
}
throw $e;
}
}
// used to display the Welcome Page in apps that don't define a homepage
$code .= " if ('/' === \$pathinfo && !\$allow && !\$allowSchemes) {\n";
$code .= " throw new Symfony\Component\Routing\Exception\NoConfigurationException();\n";
$code .= " }\n";
return $code;
}
|
[
"private",
"function",
"compileRoutes",
"(",
"RouteCollection",
"$",
"routes",
",",
"bool",
"$",
"matchHost",
")",
":",
"string",
"{",
"[",
"$",
"staticRoutes",
",",
"$",
"dynamicRoutes",
"]",
"=",
"$",
"this",
"->",
"groupStaticRoutes",
"(",
"$",
"routes",
")",
";",
"$",
"code",
"=",
"$",
"this",
"->",
"compileStaticRoutes",
"(",
"$",
"staticRoutes",
",",
"$",
"matchHost",
")",
";",
"$",
"chunkLimit",
"=",
"\\",
"count",
"(",
"$",
"dynamicRoutes",
")",
";",
"while",
"(",
"true",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"signalingException",
"=",
"new",
"\\",
"RuntimeException",
"(",
"'preg_match(): Compilation failed: regular expression is too large'",
")",
";",
"$",
"code",
".=",
"$",
"this",
"->",
"compileDynamicRoutes",
"(",
"$",
"dynamicRoutes",
",",
"$",
"matchHost",
",",
"$",
"chunkLimit",
")",
";",
"break",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"1",
"<",
"$",
"chunkLimit",
"&&",
"$",
"this",
"->",
"signalingException",
"===",
"$",
"e",
")",
"{",
"$",
"chunkLimit",
"=",
"1",
"+",
"(",
"$",
"chunkLimit",
">>",
"1",
")",
";",
"continue",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"}",
"// used to display the Welcome Page in apps that don't define a homepage",
"$",
"code",
".=",
"\" if ('/' === \\$pathinfo && !\\$allow && !\\$allowSchemes) {\\n\"",
";",
"$",
"code",
".=",
"\" throw new Symfony\\Component\\Routing\\Exception\\NoConfigurationException();\\n\"",
";",
"$",
"code",
".=",
"\" }\\n\"",
";",
"return",
"$",
"code",
";",
"}"
] |
Generates PHP code to match a RouteCollection with all its routes.
|
[
"Generates",
"PHP",
"code",
"to",
"match",
"a",
"RouteCollection",
"with",
"all",
"its",
"routes",
"."
] |
8b26d4188fa81bb488612f59d2418b9472be1c79
|
https://github.com/Sylius/Sylius/blob/8b26d4188fa81bb488612f59d2418b9472be1c79/src/Sylius/Bundle/CoreBundle/Routing/Matcher/Dumper/PhpMatcherDumper.php#L175-L205
|
221,037
|
Sylius/Sylius
|
src/Sylius/Bundle/CoreBundle/Routing/Matcher/Dumper/PhpMatcherDumper.php
|
PhpMatcherDumper.compileSwitchDefault
|
private function compileSwitchDefault(bool $hasVars, bool $matchHost): string
{
if ($hasVars) {
$code = <<<EOF
foreach (\$vars as \$i => \$v) {
if (isset(\$matches[1 + \$i])) {
\$ret[\$v] = \$matches[1 + \$i];
}
}
EOF;
} elseif ($matchHost) {
$code = <<<EOF
if (\$requiredHost) {
if ('#' !== \$requiredHost[0] ? \$requiredHost !== \$host : !preg_match(\$requiredHost, \$host, \$hostMatches)) {
break;
}
if ('#' === \$requiredHost[0] && \$hostMatches) {
\$hostMatches['_route'] = \$ret['_route'];
\$ret = \$this->mergeDefaults(\$hostMatches, \$ret);
}
}
EOF;
} else {
$code = '';
}
$code .= <<<EOF
\$hasRequiredScheme = !\$requiredSchemes || isset(\$requiredSchemes[\$context->getScheme()]);
if (\$requiredMethods && !isset(\$requiredMethods[\$canonicalMethod]) && !isset(\$requiredMethods[\$requestMethod])) {
if (\$hasRequiredScheme) {
\$allow += \$requiredMethods;
}
break;
}
if (!\$hasRequiredScheme) {
\$allowSchemes += \$requiredSchemes;
break;
}
return \$ret;
EOF;
return $code;
}
|
php
|
private function compileSwitchDefault(bool $hasVars, bool $matchHost): string
{
if ($hasVars) {
$code = <<<EOF
foreach (\$vars as \$i => \$v) {
if (isset(\$matches[1 + \$i])) {
\$ret[\$v] = \$matches[1 + \$i];
}
}
EOF;
} elseif ($matchHost) {
$code = <<<EOF
if (\$requiredHost) {
if ('#' !== \$requiredHost[0] ? \$requiredHost !== \$host : !preg_match(\$requiredHost, \$host, \$hostMatches)) {
break;
}
if ('#' === \$requiredHost[0] && \$hostMatches) {
\$hostMatches['_route'] = \$ret['_route'];
\$ret = \$this->mergeDefaults(\$hostMatches, \$ret);
}
}
EOF;
} else {
$code = '';
}
$code .= <<<EOF
\$hasRequiredScheme = !\$requiredSchemes || isset(\$requiredSchemes[\$context->getScheme()]);
if (\$requiredMethods && !isset(\$requiredMethods[\$canonicalMethod]) && !isset(\$requiredMethods[\$requestMethod])) {
if (\$hasRequiredScheme) {
\$allow += \$requiredMethods;
}
break;
}
if (!\$hasRequiredScheme) {
\$allowSchemes += \$requiredSchemes;
break;
}
return \$ret;
EOF;
return $code;
}
|
[
"private",
"function",
"compileSwitchDefault",
"(",
"bool",
"$",
"hasVars",
",",
"bool",
"$",
"matchHost",
")",
":",
"string",
"{",
"if",
"(",
"$",
"hasVars",
")",
"{",
"$",
"code",
"=",
" <<<EOF\n\n foreach (\\$vars as \\$i => \\$v) {\n if (isset(\\$matches[1 + \\$i])) {\n \\$ret[\\$v] = \\$matches[1 + \\$i];\n }\n }\n\nEOF",
";",
"}",
"elseif",
"(",
"$",
"matchHost",
")",
"{",
"$",
"code",
"=",
" <<<EOF\n\n if (\\$requiredHost) {\n if ('#' !== \\$requiredHost[0] ? \\$requiredHost !== \\$host : !preg_match(\\$requiredHost, \\$host, \\$hostMatches)) {\n break;\n }\n if ('#' === \\$requiredHost[0] && \\$hostMatches) {\n \\$hostMatches['_route'] = \\$ret['_route'];\n \\$ret = \\$this->mergeDefaults(\\$hostMatches, \\$ret);\n }\n }\n\nEOF",
";",
"}",
"else",
"{",
"$",
"code",
"=",
"''",
";",
"}",
"$",
"code",
".=",
" <<<EOF\n\n \\$hasRequiredScheme = !\\$requiredSchemes || isset(\\$requiredSchemes[\\$context->getScheme()]);\n if (\\$requiredMethods && !isset(\\$requiredMethods[\\$canonicalMethod]) && !isset(\\$requiredMethods[\\$requestMethod])) {\n if (\\$hasRequiredScheme) {\n \\$allow += \\$requiredMethods;\n }\n break;\n }\n if (!\\$hasRequiredScheme) {\n \\$allowSchemes += \\$requiredSchemes;\n break;\n }\n\n return \\$ret;\n\nEOF",
";",
"return",
"$",
"code",
";",
"}"
] |
A simple helper to compiles the switch's "default" for both static and dynamic routes.
|
[
"A",
"simple",
"helper",
"to",
"compiles",
"the",
"switch",
"s",
"default",
"for",
"both",
"static",
"and",
"dynamic",
"routes",
"."
] |
8b26d4188fa81bb488612f59d2418b9472be1c79
|
https://github.com/Sylius/Sylius/blob/8b26d4188fa81bb488612f59d2418b9472be1c79/src/Sylius/Bundle/CoreBundle/Routing/Matcher/Dumper/PhpMatcherDumper.php#L542-L591
|
221,038
|
leighmacdonald/php_rbac
|
src/RBAC/Permission.php
|
Permission.create
|
public static function create($name, $description = "", $permission_id = null)
{
$perm = new self();
$perm->name = $name;
$perm->description = $description;
$perm->permission_id = $permission_id;
return $perm;
}
|
php
|
public static function create($name, $description = "", $permission_id = null)
{
$perm = new self();
$perm->name = $name;
$perm->description = $description;
$perm->permission_id = $permission_id;
return $perm;
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"name",
",",
"$",
"description",
"=",
"\"\"",
",",
"$",
"permission_id",
"=",
"null",
")",
"{",
"$",
"perm",
"=",
"new",
"self",
"(",
")",
";",
"$",
"perm",
"->",
"name",
"=",
"$",
"name",
";",
"$",
"perm",
"->",
"description",
"=",
"$",
"description",
";",
"$",
"perm",
"->",
"permission_id",
"=",
"$",
"permission_id",
";",
"return",
"$",
"perm",
";",
"}"
] |
Configure and return a new Permission instance ready to be saved to the backend data store
@param string $name Name if the permission, this is treated as a key and must be unique
@param string $description Optional description.
@param null|int $permission_id Optional permission ID
@return Permission
|
[
"Configure",
"and",
"return",
"a",
"new",
"Permission",
"instance",
"ready",
"to",
"be",
"saved",
"to",
"the",
"backend",
"data",
"store"
] |
8855d6bbfa29e0a5d89f2911d552bc2ab394cf52
|
https://github.com/leighmacdonald/php_rbac/blob/8855d6bbfa29e0a5d89f2911d552bc2ab394cf52/src/RBAC/Permission.php#L47-L54
|
221,039
|
ARCANEDEV/LaravelTracker
|
src/Trackers/QueryTracker.php
|
QueryTracker.track
|
public function track(array $queries)
{
if (count($queries) == 0)
return null;
$data = [
'query' => $this->prepareQuery($queries),
'arguments' => $this->prepareArguments($queries),
];
return $this->getModel()
->newQuery()
->firstOrCreate(Arr::only($data, ['query']), $data)
->getKey();
}
|
php
|
public function track(array $queries)
{
if (count($queries) == 0)
return null;
$data = [
'query' => $this->prepareQuery($queries),
'arguments' => $this->prepareArguments($queries),
];
return $this->getModel()
->newQuery()
->firstOrCreate(Arr::only($data, ['query']), $data)
->getKey();
}
|
[
"public",
"function",
"track",
"(",
"array",
"$",
"queries",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"queries",
")",
"==",
"0",
")",
"return",
"null",
";",
"$",
"data",
"=",
"[",
"'query'",
"=>",
"$",
"this",
"->",
"prepareQuery",
"(",
"$",
"queries",
")",
",",
"'arguments'",
"=>",
"$",
"this",
"->",
"prepareArguments",
"(",
"$",
"queries",
")",
",",
"]",
";",
"return",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"newQuery",
"(",
")",
"->",
"firstOrCreate",
"(",
"Arr",
"::",
"only",
"(",
"$",
"data",
",",
"[",
"'query'",
"]",
")",
",",
"$",
"data",
")",
"->",
"getKey",
"(",
")",
";",
"}"
] |
Track the query.
@param array $queries
@return int|null
|
[
"Track",
"the",
"query",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/QueryTracker.php#L42-L56
|
221,040
|
leighmacdonald/php_rbac
|
src/RBAC/Subject/Subject.php
|
Subject.hasPermission
|
public function hasPermission($permission)
{
if ($permission instanceof Permission) {
$permission = $permission->name;
}
return $this->getRoleSet()->has_permission($permission);
}
|
php
|
public function hasPermission($permission)
{
if ($permission instanceof Permission) {
$permission = $permission->name;
}
return $this->getRoleSet()->has_permission($permission);
}
|
[
"public",
"function",
"hasPermission",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"$",
"permission",
"instanceof",
"Permission",
")",
"{",
"$",
"permission",
"=",
"$",
"permission",
"->",
"name",
";",
"}",
"return",
"$",
"this",
"->",
"getRoleSet",
"(",
")",
"->",
"has_permission",
"(",
"$",
"permission",
")",
";",
"}"
] |
Check if a user has access to the permission requested
@param string|Permission $permission name of the permission or Permission instance
@return bool
|
[
"Check",
"if",
"a",
"user",
"has",
"access",
"to",
"the",
"permission",
"requested"
] |
8855d6bbfa29e0a5d89f2911d552bc2ab394cf52
|
https://github.com/leighmacdonald/php_rbac/blob/8855d6bbfa29e0a5d89f2911d552bc2ab394cf52/src/RBAC/Subject/Subject.php#L79-L85
|
221,041
|
ARCANEDEV/LaravelTracker
|
src/Detectors/GeoIpDetector.php
|
GeoIpDetector.search
|
public function search($ipAddress)
{
try {
if ($location = $this->geoIp->location($ipAddress)) {
return $this->transform($location);
}
}
catch (\Exception $e) {
// do nothing
}
return null;
}
|
php
|
public function search($ipAddress)
{
try {
if ($location = $this->geoIp->location($ipAddress)) {
return $this->transform($location);
}
}
catch (\Exception $e) {
// do nothing
}
return null;
}
|
[
"public",
"function",
"search",
"(",
"$",
"ipAddress",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"location",
"=",
"$",
"this",
"->",
"geoIp",
"->",
"location",
"(",
"$",
"ipAddress",
")",
")",
"{",
"return",
"$",
"this",
"->",
"transform",
"(",
"$",
"location",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// do nothing",
"}",
"return",
"null",
";",
"}"
] |
Get the geoip data.
@param string $ipAddress
@return array|null
|
[
"Get",
"the",
"geoip",
"data",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Detectors/GeoIpDetector.php#L51-L63
|
221,042
|
ARCANEDEV/LaravelTracker
|
src/Detectors/GeoIpDetector.php
|
GeoIpDetector.transform
|
private function transform($location)
{
return [
'iso_code' => $location->iso_code,
'country' => $location->country,
'city' => $location->city,
'state' => $location->state,
'state_code' => $location->state_code,
'postal_code' => $location->postal_code,
'latitude' => $location->latitude,
'longitude' => $location->longitude,
'timezone' => $location->timezone,
'continent' => $location->continent,
'currency' => $location->currency,
];
}
|
php
|
private function transform($location)
{
return [
'iso_code' => $location->iso_code,
'country' => $location->country,
'city' => $location->city,
'state' => $location->state,
'state_code' => $location->state_code,
'postal_code' => $location->postal_code,
'latitude' => $location->latitude,
'longitude' => $location->longitude,
'timezone' => $location->timezone,
'continent' => $location->continent,
'currency' => $location->currency,
];
}
|
[
"private",
"function",
"transform",
"(",
"$",
"location",
")",
"{",
"return",
"[",
"'iso_code'",
"=>",
"$",
"location",
"->",
"iso_code",
",",
"'country'",
"=>",
"$",
"location",
"->",
"country",
",",
"'city'",
"=>",
"$",
"location",
"->",
"city",
",",
"'state'",
"=>",
"$",
"location",
"->",
"state",
",",
"'state_code'",
"=>",
"$",
"location",
"->",
"state_code",
",",
"'postal_code'",
"=>",
"$",
"location",
"->",
"postal_code",
",",
"'latitude'",
"=>",
"$",
"location",
"->",
"latitude",
",",
"'longitude'",
"=>",
"$",
"location",
"->",
"longitude",
",",
"'timezone'",
"=>",
"$",
"location",
"->",
"timezone",
",",
"'continent'",
"=>",
"$",
"location",
"->",
"continent",
",",
"'currency'",
"=>",
"$",
"location",
"->",
"currency",
",",
"]",
";",
"}"
] |
Render the data.
@param \Arcanedev\GeoIP\Location $location
@return array
|
[
"Render",
"the",
"data",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Detectors/GeoIpDetector.php#L77-L92
|
221,043
|
ARCANEDEV/LaravelTracker
|
src/LaravelTrackerServiceProvider.php
|
LaravelTrackerServiceProvider.registerDetectors
|
private function registerDetectors()
{
$this->singleton(Contracts\Detectors\CrawlerDetector::class, function (AppContract $app) {
/** @var \Illuminate\Http\Request $request */
$request = $app['request'];
return new Detectors\CrawlerDetector(
new \Jaybizzle\CrawlerDetect\CrawlerDetect(
$request->headers->all(),
$request->server('HTTP_USER_AGENT')
)
);
});
$this->singleton(Contracts\Detectors\DeviceDetector::class, Detectors\DeviceDetector::class);
$this->singleton(Contracts\Detectors\GeoIpDetector::class, Detectors\GeoIpDetector::class);
$this->singleton(Contracts\Detectors\LanguageDetector::class, Detectors\LanguageDetector::class);
}
|
php
|
private function registerDetectors()
{
$this->singleton(Contracts\Detectors\CrawlerDetector::class, function (AppContract $app) {
/** @var \Illuminate\Http\Request $request */
$request = $app['request'];
return new Detectors\CrawlerDetector(
new \Jaybizzle\CrawlerDetect\CrawlerDetect(
$request->headers->all(),
$request->server('HTTP_USER_AGENT')
)
);
});
$this->singleton(Contracts\Detectors\DeviceDetector::class, Detectors\DeviceDetector::class);
$this->singleton(Contracts\Detectors\GeoIpDetector::class, Detectors\GeoIpDetector::class);
$this->singleton(Contracts\Detectors\LanguageDetector::class, Detectors\LanguageDetector::class);
}
|
[
"private",
"function",
"registerDetectors",
"(",
")",
"{",
"$",
"this",
"->",
"singleton",
"(",
"Contracts",
"\\",
"Detectors",
"\\",
"CrawlerDetector",
"::",
"class",
",",
"function",
"(",
"AppContract",
"$",
"app",
")",
"{",
"/** @var \\Illuminate\\Http\\Request $request */",
"$",
"request",
"=",
"$",
"app",
"[",
"'request'",
"]",
";",
"return",
"new",
"Detectors",
"\\",
"CrawlerDetector",
"(",
"new",
"\\",
"Jaybizzle",
"\\",
"CrawlerDetect",
"\\",
"CrawlerDetect",
"(",
"$",
"request",
"->",
"headers",
"->",
"all",
"(",
")",
",",
"$",
"request",
"->",
"server",
"(",
"'HTTP_USER_AGENT'",
")",
")",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"singleton",
"(",
"Contracts",
"\\",
"Detectors",
"\\",
"DeviceDetector",
"::",
"class",
",",
"Detectors",
"\\",
"DeviceDetector",
"::",
"class",
")",
";",
"$",
"this",
"->",
"singleton",
"(",
"Contracts",
"\\",
"Detectors",
"\\",
"GeoIpDetector",
"::",
"class",
",",
"Detectors",
"\\",
"GeoIpDetector",
"::",
"class",
")",
";",
"$",
"this",
"->",
"singleton",
"(",
"Contracts",
"\\",
"Detectors",
"\\",
"LanguageDetector",
"::",
"class",
",",
"Detectors",
"\\",
"LanguageDetector",
"::",
"class",
")",
";",
"}"
] |
Register the detectors.
|
[
"Register",
"the",
"detectors",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/LaravelTrackerServiceProvider.php#L97-L114
|
221,044
|
ARCANEDEV/LaravelTracker
|
src/LaravelTrackerServiceProvider.php
|
LaravelTrackerServiceProvider.registerParsers
|
private function registerParsers()
{
$this->singleton(Contracts\Parsers\RefererParser::class, function () {
return new Parsers\RefererParser(
new \Snowplow\RefererParser\Parser
);
});
$this->singleton(Contracts\Parsers\UserAgentParser::class, function (AppContract $app) {
return new Parsers\UserAgentParser(
\UAParser\Parser::create(), $app->make('path.base')
);
});
}
|
php
|
private function registerParsers()
{
$this->singleton(Contracts\Parsers\RefererParser::class, function () {
return new Parsers\RefererParser(
new \Snowplow\RefererParser\Parser
);
});
$this->singleton(Contracts\Parsers\UserAgentParser::class, function (AppContract $app) {
return new Parsers\UserAgentParser(
\UAParser\Parser::create(), $app->make('path.base')
);
});
}
|
[
"private",
"function",
"registerParsers",
"(",
")",
"{",
"$",
"this",
"->",
"singleton",
"(",
"Contracts",
"\\",
"Parsers",
"\\",
"RefererParser",
"::",
"class",
",",
"function",
"(",
")",
"{",
"return",
"new",
"Parsers",
"\\",
"RefererParser",
"(",
"new",
"\\",
"Snowplow",
"\\",
"RefererParser",
"\\",
"Parser",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"singleton",
"(",
"Contracts",
"\\",
"Parsers",
"\\",
"UserAgentParser",
"::",
"class",
",",
"function",
"(",
"AppContract",
"$",
"app",
")",
"{",
"return",
"new",
"Parsers",
"\\",
"UserAgentParser",
"(",
"\\",
"UAParser",
"\\",
"Parser",
"::",
"create",
"(",
")",
",",
"$",
"app",
"->",
"make",
"(",
"'path.base'",
")",
")",
";",
"}",
")",
";",
"}"
] |
Register the parsers.
|
[
"Register",
"the",
"parsers",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/LaravelTrackerServiceProvider.php#L119-L132
|
221,045
|
leighmacdonald/php_rbac
|
src/RBAC/Role/RoleSet.php
|
RoleSet.addRole
|
public function addRole(Role $role)
{
if (!in_array($role, $this->roles)) {
$this->roles[] = $role;
return true;
}
return false;
}
|
php
|
public function addRole(Role $role)
{
if (!in_array($role, $this->roles)) {
$this->roles[] = $role;
return true;
}
return false;
}
|
[
"public",
"function",
"addRole",
"(",
"Role",
"$",
"role",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"role",
",",
"$",
"this",
"->",
"roles",
")",
")",
"{",
"$",
"this",
"->",
"roles",
"[",
"]",
"=",
"$",
"role",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Add a new role to the role set
@param Role $role
@return bool
|
[
"Add",
"a",
"new",
"role",
"to",
"the",
"role",
"set"
] |
8855d6bbfa29e0a5d89f2911d552bc2ab394cf52
|
https://github.com/leighmacdonald/php_rbac/blob/8855d6bbfa29e0a5d89f2911d552bc2ab394cf52/src/RBAC/Role/RoleSet.php#L40-L47
|
221,046
|
leighmacdonald/php_rbac
|
src/RBAC/Role/RoleSet.php
|
RoleSet.getPermissions
|
public function getPermissions()
{
$permissions = [];
foreach ($this->roles as $role) {
$permissions = array_merge($permissions, $role->getPermissions());
}
return array_unique($permissions);
}
|
php
|
public function getPermissions()
{
$permissions = [];
foreach ($this->roles as $role) {
$permissions = array_merge($permissions, $role->getPermissions());
}
return array_unique($permissions);
}
|
[
"public",
"function",
"getPermissions",
"(",
")",
"{",
"$",
"permissions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"roles",
"as",
"$",
"role",
")",
"{",
"$",
"permissions",
"=",
"array_merge",
"(",
"$",
"permissions",
",",
"$",
"role",
"->",
"getPermissions",
"(",
")",
")",
";",
"}",
"return",
"array_unique",
"(",
"$",
"permissions",
")",
";",
"}"
] |
Fetch a complete set of unique permissions assigned to the users roles
@return Permission[]
|
[
"Fetch",
"a",
"complete",
"set",
"of",
"unique",
"permissions",
"assigned",
"to",
"the",
"users",
"roles"
] |
8855d6bbfa29e0a5d89f2911d552bc2ab394cf52
|
https://github.com/leighmacdonald/php_rbac/blob/8855d6bbfa29e0a5d89f2911d552bc2ab394cf52/src/RBAC/Role/RoleSet.php#L79-L86
|
221,047
|
ARCANEDEV/LaravelTracker
|
src/Exceptions/ExceptionFactory.php
|
ExceptionFactory.make
|
public static function make($errorCode, $errorMessage)
{
$exception = Arr::get(self::$supported, $errorCode, Errors\Error::class);
return new $exception($errorMessage, $errorCode);
}
|
php
|
public static function make($errorCode, $errorMessage)
{
$exception = Arr::get(self::$supported, $errorCode, Errors\Error::class);
return new $exception($errorMessage, $errorCode);
}
|
[
"public",
"static",
"function",
"make",
"(",
"$",
"errorCode",
",",
"$",
"errorMessage",
")",
"{",
"$",
"exception",
"=",
"Arr",
"::",
"get",
"(",
"self",
"::",
"$",
"supported",
",",
"$",
"errorCode",
",",
"Errors",
"\\",
"Error",
"::",
"class",
")",
";",
"return",
"new",
"$",
"exception",
"(",
"$",
"errorMessage",
",",
"$",
"errorCode",
")",
";",
"}"
] |
Make exception.
@param int $errorCode
@param string $errorMessage
@return mixed
|
[
"Make",
"exception",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Exceptions/ExceptionFactory.php#L54-L59
|
221,048
|
ARCANEDEV/LaravelTracker
|
src/Trackers/CookieTracker.php
|
CookieTracker.track
|
public function track($cookie)
{
if ( ! $cookie) {
$this->cookie()->queue(
$this->cookie()->make($this->getConfig('cookie.name'), $cookie = (string) Uuid::uuid4())
);
}
return $this->getModel()
->newQuery()
->firstOrCreate(['uuid' => $cookie])
->getKey();
}
|
php
|
public function track($cookie)
{
if ( ! $cookie) {
$this->cookie()->queue(
$this->cookie()->make($this->getConfig('cookie.name'), $cookie = (string) Uuid::uuid4())
);
}
return $this->getModel()
->newQuery()
->firstOrCreate(['uuid' => $cookie])
->getKey();
}
|
[
"public",
"function",
"track",
"(",
"$",
"cookie",
")",
"{",
"if",
"(",
"!",
"$",
"cookie",
")",
"{",
"$",
"this",
"->",
"cookie",
"(",
")",
"->",
"queue",
"(",
"$",
"this",
"->",
"cookie",
"(",
")",
"->",
"make",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'cookie.name'",
")",
",",
"$",
"cookie",
"=",
"(",
"string",
")",
"Uuid",
"::",
"uuid4",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"newQuery",
"(",
")",
"->",
"firstOrCreate",
"(",
"[",
"'uuid'",
"=>",
"$",
"cookie",
"]",
")",
"->",
"getKey",
"(",
")",
";",
"}"
] |
Track the cookie.
@param mixed $cookie
@return int
|
[
"Track",
"the",
"cookie",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/CookieTracker.php#L43-L55
|
221,049
|
ARCANEDEV/LaravelTracker
|
src/Trackers/GeoIpTracker.php
|
GeoIpTracker.track
|
public function track($ipAddress)
{
if ($data = $this->getGeoIpDetector()->search($ipAddress)) {
return $this->getModel()
->newQuery()
->firstOrCreate(Arr::only($data, ['latitude', 'longitude']), $data)
->getKey();
}
return null;
}
|
php
|
public function track($ipAddress)
{
if ($data = $this->getGeoIpDetector()->search($ipAddress)) {
return $this->getModel()
->newQuery()
->firstOrCreate(Arr::only($data, ['latitude', 'longitude']), $data)
->getKey();
}
return null;
}
|
[
"public",
"function",
"track",
"(",
"$",
"ipAddress",
")",
"{",
"if",
"(",
"$",
"data",
"=",
"$",
"this",
"->",
"getGeoIpDetector",
"(",
")",
"->",
"search",
"(",
"$",
"ipAddress",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"newQuery",
"(",
")",
"->",
"firstOrCreate",
"(",
"Arr",
"::",
"only",
"(",
"$",
"data",
",",
"[",
"'latitude'",
",",
"'longitude'",
"]",
")",
",",
"$",
"data",
")",
"->",
"getKey",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Track the ip address.
@param string $ipAddress
@return int|null
|
[
"Track",
"the",
"ip",
"address",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/GeoIpTracker.php#L51-L61
|
221,050
|
ARCANEDEV/LaravelTracker
|
src/Parsers/UserAgentParser.php
|
UserAgentParser.getOperatingSystemVersion
|
public function getOperatingSystemVersion()
{
$os = $this->getOperatingSystem();
return $this->prepareVersion([$os->major, $os->minor, $os->patch]);
}
|
php
|
public function getOperatingSystemVersion()
{
$os = $this->getOperatingSystem();
return $this->prepareVersion([$os->major, $os->minor, $os->patch]);
}
|
[
"public",
"function",
"getOperatingSystemVersion",
"(",
")",
"{",
"$",
"os",
"=",
"$",
"this",
"->",
"getOperatingSystem",
"(",
")",
";",
"return",
"$",
"this",
"->",
"prepareVersion",
"(",
"[",
"$",
"os",
"->",
"major",
",",
"$",
"os",
"->",
"minor",
",",
"$",
"os",
"->",
"patch",
"]",
")",
";",
"}"
] |
Get the OS version.
@return string
|
[
"Get",
"the",
"OS",
"version",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Parsers/UserAgentParser.php#L56-L61
|
221,051
|
ARCANEDEV/LaravelTracker
|
src/Parsers/UserAgentParser.php
|
UserAgentParser.getUserAgentVersion
|
public function getUserAgentVersion()
{
$ua = $this->getUserAgent();
return $this->prepareVersion([$ua->major, $ua->minor, $ua->patch]);
}
|
php
|
public function getUserAgentVersion()
{
$ua = $this->getUserAgent();
return $this->prepareVersion([$ua->major, $ua->minor, $ua->patch]);
}
|
[
"public",
"function",
"getUserAgentVersion",
"(",
")",
"{",
"$",
"ua",
"=",
"$",
"this",
"->",
"getUserAgent",
"(",
")",
";",
"return",
"$",
"this",
"->",
"prepareVersion",
"(",
"[",
"$",
"ua",
"->",
"major",
",",
"$",
"ua",
"->",
"minor",
",",
"$",
"ua",
"->",
"patch",
"]",
")",
";",
"}"
] |
Get the user agent version.
@return string
|
[
"Get",
"the",
"user",
"agent",
"version",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Parsers/UserAgentParser.php#L93-L98
|
221,052
|
ARCANEDEV/LaravelTracker
|
src/Trackers/DeviceTracker.php
|
DeviceTracker.getCurrentDeviceProperties
|
private function getCurrentDeviceProperties()
{
if ($properties = $this->getDeviceDetector()->detect()) {
$parser = $this->getUserAgentParser();
$properties['platform'] = $parser->getOperatingSystemFamily();
$properties['platform_version'] = $parser->getOperatingSystemVersion();
}
return $properties;
}
|
php
|
private function getCurrentDeviceProperties()
{
if ($properties = $this->getDeviceDetector()->detect()) {
$parser = $this->getUserAgentParser();
$properties['platform'] = $parser->getOperatingSystemFamily();
$properties['platform_version'] = $parser->getOperatingSystemVersion();
}
return $properties;
}
|
[
"private",
"function",
"getCurrentDeviceProperties",
"(",
")",
"{",
"if",
"(",
"$",
"properties",
"=",
"$",
"this",
"->",
"getDeviceDetector",
"(",
")",
"->",
"detect",
"(",
")",
")",
"{",
"$",
"parser",
"=",
"$",
"this",
"->",
"getUserAgentParser",
"(",
")",
";",
"$",
"properties",
"[",
"'platform'",
"]",
"=",
"$",
"parser",
"->",
"getOperatingSystemFamily",
"(",
")",
";",
"$",
"properties",
"[",
"'platform_version'",
"]",
"=",
"$",
"parser",
"->",
"getOperatingSystemVersion",
"(",
")",
";",
"}",
"return",
"$",
"properties",
";",
"}"
] |
Get the current device properties.
@return array
|
[
"Get",
"the",
"current",
"device",
"properties",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/DeviceTracker.php#L75-L85
|
221,053
|
ARCANEDEV/LaravelTracker
|
src/Trackers/VisitorTracker.php
|
VisitorTracker.checkData
|
public function checkData(array $currentData, array $newData)
{
return ($currentData && $newData && $currentData !== $newData)
? $this->updateData($newData)
: $newData;
}
|
php
|
public function checkData(array $currentData, array $newData)
{
return ($currentData && $newData && $currentData !== $newData)
? $this->updateData($newData)
: $newData;
}
|
[
"public",
"function",
"checkData",
"(",
"array",
"$",
"currentData",
",",
"array",
"$",
"newData",
")",
"{",
"return",
"(",
"$",
"currentData",
"&&",
"$",
"newData",
"&&",
"$",
"currentData",
"!==",
"$",
"newData",
")",
"?",
"$",
"this",
"->",
"updateData",
"(",
"$",
"newData",
")",
":",
"$",
"newData",
";",
"}"
] |
Check the visitor data.
@param array $currentData
@param array $newData
@return array
|
[
"Check",
"the",
"visitor",
"data",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/VisitorTracker.php#L111-L116
|
221,054
|
ARCANEDEV/LaravelTracker
|
src/Trackers/VisitorTracker.php
|
VisitorTracker.getVisitorData
|
private function getVisitorData($column = null)
{
$data = $this->session()->get($this->getSessionKey());
return is_null($column) ? $data : Arr::get($data, $column, null);
}
|
php
|
private function getVisitorData($column = null)
{
$data = $this->session()->get($this->getSessionKey());
return is_null($column) ? $data : Arr::get($data, $column, null);
}
|
[
"private",
"function",
"getVisitorData",
"(",
"$",
"column",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"getSessionKey",
"(",
")",
")",
";",
"return",
"is_null",
"(",
"$",
"column",
")",
"?",
"$",
"data",
":",
"Arr",
"::",
"get",
"(",
"$",
"data",
",",
"$",
"column",
",",
"null",
")",
";",
"}"
] |
Get the visitor data.
@param string|null $column
@return mixed
|
[
"Get",
"the",
"visitor",
"data",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/VisitorTracker.php#L144-L149
|
221,055
|
ARCANEDEV/LaravelTracker
|
src/Trackers/VisitorTracker.php
|
VisitorTracker.checkIfUserChanged
|
private function checkIfUserChanged(array $data)
{
$model = $this->getModel()->newQuery()->find($this->getVisitorData('id'));
if (
! is_null($model) &&
! is_null($model->user_id) &&
! is_null($data['user_id']) &&
$data['user_id'] !== $model->user_id
) {
$newVisitor = $this->regenerateSystemVisitor($data);
$model = $this->findByUuid($newVisitor['uuid']);
$model->update(Arr::except($data, ['id', 'uuid']));
}
}
|
php
|
private function checkIfUserChanged(array $data)
{
$model = $this->getModel()->newQuery()->find($this->getVisitorData('id'));
if (
! is_null($model) &&
! is_null($model->user_id) &&
! is_null($data['user_id']) &&
$data['user_id'] !== $model->user_id
) {
$newVisitor = $this->regenerateSystemVisitor($data);
$model = $this->findByUuid($newVisitor['uuid']);
$model->update(Arr::except($data, ['id', 'uuid']));
}
}
|
[
"private",
"function",
"checkIfUserChanged",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"newQuery",
"(",
")",
"->",
"find",
"(",
"$",
"this",
"->",
"getVisitorData",
"(",
"'id'",
")",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"model",
")",
"&&",
"!",
"is_null",
"(",
"$",
"model",
"->",
"user_id",
")",
"&&",
"!",
"is_null",
"(",
"$",
"data",
"[",
"'user_id'",
"]",
")",
"&&",
"$",
"data",
"[",
"'user_id'",
"]",
"!==",
"$",
"model",
"->",
"user_id",
")",
"{",
"$",
"newVisitor",
"=",
"$",
"this",
"->",
"regenerateSystemVisitor",
"(",
"$",
"data",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"findByUuid",
"(",
"$",
"newVisitor",
"[",
"'uuid'",
"]",
")",
";",
"$",
"model",
"->",
"update",
"(",
"Arr",
"::",
"except",
"(",
"$",
"data",
",",
"[",
"'id'",
",",
"'uuid'",
"]",
")",
")",
";",
"}",
"}"
] |
Check if user changed.
@param array $data
|
[
"Check",
"if",
"user",
"changed",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/VisitorTracker.php#L156-L170
|
221,056
|
ARCANEDEV/LaravelTracker
|
src/Trackers/VisitorTracker.php
|
VisitorTracker.regenerateSystemVisitor
|
private function regenerateSystemVisitor($data = null)
{
$data = $data ?: $this->getVisitorData();
if ($data) {
$this->resetVisitorUuid($data);
$this->createVisitorIfIsUnknown();
}
return $this->visitorInfo;
}
|
php
|
private function regenerateSystemVisitor($data = null)
{
$data = $data ?: $this->getVisitorData();
if ($data) {
$this->resetVisitorUuid($data);
$this->createVisitorIfIsUnknown();
}
return $this->visitorInfo;
}
|
[
"private",
"function",
"regenerateSystemVisitor",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"$",
"data",
"?",
":",
"$",
"this",
"->",
"getVisitorData",
"(",
")",
";",
"if",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"resetVisitorUuid",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"createVisitorIfIsUnknown",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"visitorInfo",
";",
"}"
] |
Regenerate visitor data for the system.
@param array|null $data
@return array
|
[
"Regenerate",
"visitor",
"data",
"for",
"the",
"system",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/VisitorTracker.php#L179-L189
|
221,057
|
ARCANEDEV/LaravelTracker
|
src/Trackers/VisitorTracker.php
|
VisitorTracker.resetVisitorUuid
|
private function resetVisitorUuid($data = null)
{
$this->visitorInfo['uuid'] = null;
$data = $data ?: $this->visitorInfo;
unset($data['uuid']);
$this->putSessionData($data);
$this->checkVisitorUuid();
return $data;
}
|
php
|
private function resetVisitorUuid($data = null)
{
$this->visitorInfo['uuid'] = null;
$data = $data ?: $this->visitorInfo;
unset($data['uuid']);
$this->putSessionData($data);
$this->checkVisitorUuid();
return $data;
}
|
[
"private",
"function",
"resetVisitorUuid",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"visitorInfo",
"[",
"'uuid'",
"]",
"=",
"null",
";",
"$",
"data",
"=",
"$",
"data",
"?",
":",
"$",
"this",
"->",
"visitorInfo",
";",
"unset",
"(",
"$",
"data",
"[",
"'uuid'",
"]",
")",
";",
"$",
"this",
"->",
"putSessionData",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"checkVisitorUuid",
"(",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
Reset the visitor uuid.
@param array|null $data
@return array|null
|
[
"Reset",
"the",
"visitor",
"uuid",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/VisitorTracker.php#L198-L210
|
221,058
|
ARCANEDEV/LaravelTracker
|
src/Trackers/VisitorTracker.php
|
VisitorTracker.checkVisitorUuid
|
private function checkVisitorUuid()
{
if ( ! isset($this->visitorInfo['uuid']) || ! $this->visitorInfo['uuid'])
$this->visitorInfo['uuid'] = $this->getVisitorIdFromSystem();
}
|
php
|
private function checkVisitorUuid()
{
if ( ! isset($this->visitorInfo['uuid']) || ! $this->visitorInfo['uuid'])
$this->visitorInfo['uuid'] = $this->getVisitorIdFromSystem();
}
|
[
"private",
"function",
"checkVisitorUuid",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"visitorInfo",
"[",
"'uuid'",
"]",
")",
"||",
"!",
"$",
"this",
"->",
"visitorInfo",
"[",
"'uuid'",
"]",
")",
"$",
"this",
"->",
"visitorInfo",
"[",
"'uuid'",
"]",
"=",
"$",
"this",
"->",
"getVisitorIdFromSystem",
"(",
")",
";",
"}"
] |
Check the visitor uuid.
|
[
"Check",
"the",
"visitor",
"uuid",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/VisitorTracker.php#L227-L231
|
221,059
|
ARCANEDEV/LaravelTracker
|
src/Trackers/VisitorTracker.php
|
VisitorTracker.createVisitorIfIsUnknown
|
private function createVisitorIfIsUnknown()
{
$model = $this->getModel();
/** @var \Arcanedev\LaravelTracker\Models\Visitor $visitor */
if ($this->isVisitorKnown()) {
$visitor = $model->newQuery()->find($id = $this->getVisitorData($model->getKeyName()));
$visitor->updated_at = Carbon::now();
$visitor->save();
$this->setVisitorId($id);
return true;
}
$visitor = $model->newQuery()
->firstOrCreate(Arr::only($this->visitorInfo, ['uuid']), $this->visitorInfo);
$this->setVisitorId($visitor->getKey());
$this->putSessionData($this->visitorInfo);
return false;
}
|
php
|
private function createVisitorIfIsUnknown()
{
$model = $this->getModel();
/** @var \Arcanedev\LaravelTracker\Models\Visitor $visitor */
if ($this->isVisitorKnown()) {
$visitor = $model->newQuery()->find($id = $this->getVisitorData($model->getKeyName()));
$visitor->updated_at = Carbon::now();
$visitor->save();
$this->setVisitorId($id);
return true;
}
$visitor = $model->newQuery()
->firstOrCreate(Arr::only($this->visitorInfo, ['uuid']), $this->visitorInfo);
$this->setVisitorId($visitor->getKey());
$this->putSessionData($this->visitorInfo);
return false;
}
|
[
"private",
"function",
"createVisitorIfIsUnknown",
"(",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
";",
"/** @var \\Arcanedev\\LaravelTracker\\Models\\Visitor $visitor */",
"if",
"(",
"$",
"this",
"->",
"isVisitorKnown",
"(",
")",
")",
"{",
"$",
"visitor",
"=",
"$",
"model",
"->",
"newQuery",
"(",
")",
"->",
"find",
"(",
"$",
"id",
"=",
"$",
"this",
"->",
"getVisitorData",
"(",
"$",
"model",
"->",
"getKeyName",
"(",
")",
")",
")",
";",
"$",
"visitor",
"->",
"updated_at",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"$",
"visitor",
"->",
"save",
"(",
")",
";",
"$",
"this",
"->",
"setVisitorId",
"(",
"$",
"id",
")",
";",
"return",
"true",
";",
"}",
"$",
"visitor",
"=",
"$",
"model",
"->",
"newQuery",
"(",
")",
"->",
"firstOrCreate",
"(",
"Arr",
"::",
"only",
"(",
"$",
"this",
"->",
"visitorInfo",
",",
"[",
"'uuid'",
"]",
")",
",",
"$",
"this",
"->",
"visitorInfo",
")",
";",
"$",
"this",
"->",
"setVisitorId",
"(",
"$",
"visitor",
"->",
"getKey",
"(",
")",
")",
";",
"$",
"this",
"->",
"putSessionData",
"(",
"$",
"this",
"->",
"visitorInfo",
")",
";",
"return",
"false",
";",
"}"
] |
Create a new visitor if is unknown.
@return bool
|
[
"Create",
"a",
"new",
"visitor",
"if",
"is",
"unknown",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/VisitorTracker.php#L248-L270
|
221,060
|
ARCANEDEV/LaravelTracker
|
src/Trackers/VisitorTracker.php
|
VisitorTracker.isVisitorKnown
|
private function isVisitorKnown()
{
if ( ! $this->session()->has($this->getSessionKey()))
return false;
if ($this->getVisitorData('uuid') != $this->getVisitorIdFromSystem())
return false;
if ( ! $this->findByUuid($this->getVisitorData('uuid')))
return false;
return true;
}
|
php
|
private function isVisitorKnown()
{
if ( ! $this->session()->has($this->getSessionKey()))
return false;
if ($this->getVisitorData('uuid') != $this->getVisitorIdFromSystem())
return false;
if ( ! $this->findByUuid($this->getVisitorData('uuid')))
return false;
return true;
}
|
[
"private",
"function",
"isVisitorKnown",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"has",
"(",
"$",
"this",
"->",
"getSessionKey",
"(",
")",
")",
")",
"return",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"getVisitorData",
"(",
"'uuid'",
")",
"!=",
"$",
"this",
"->",
"getVisitorIdFromSystem",
"(",
")",
")",
"return",
"false",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"findByUuid",
"(",
"$",
"this",
"->",
"getVisitorData",
"(",
"'uuid'",
")",
")",
")",
"return",
"false",
";",
"return",
"true",
";",
"}"
] |
Check if the visitor is known.
@return bool
|
[
"Check",
"if",
"the",
"visitor",
"is",
"known",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/VisitorTracker.php#L277-L289
|
221,061
|
ARCANEDEV/LaravelTracker
|
src/Trackers/VisitorTracker.php
|
VisitorTracker.generateVisitor
|
private function generateVisitor(array $visitorInfo)
{
$this->visitorInfo = $visitorInfo;
if ( ! $this->checkVisitorDataIsReliable())
$this->regenerateSystemVisitor();
$this->checkVisitorUuid();
}
|
php
|
private function generateVisitor(array $visitorInfo)
{
$this->visitorInfo = $visitorInfo;
if ( ! $this->checkVisitorDataIsReliable())
$this->regenerateSystemVisitor();
$this->checkVisitorUuid();
}
|
[
"private",
"function",
"generateVisitor",
"(",
"array",
"$",
"visitorInfo",
")",
"{",
"$",
"this",
"->",
"visitorInfo",
"=",
"$",
"visitorInfo",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"checkVisitorDataIsReliable",
"(",
")",
")",
"$",
"this",
"->",
"regenerateSystemVisitor",
"(",
")",
";",
"$",
"this",
"->",
"checkVisitorUuid",
"(",
")",
";",
"}"
] |
Generate visitor data.
@param array $visitorInfo
|
[
"Generate",
"visitor",
"data",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/VisitorTracker.php#L308-L316
|
221,062
|
ARCANEDEV/LaravelTracker
|
src/Trackers/VisitorTracker.php
|
VisitorTracker.checkVisitorDataIsReliable
|
private function checkVisitorDataIsReliable()
{
$data = $this->getVisitorData();
foreach (['user_id', 'client_ip', 'user_agent'] as $key) {
if ($this->checkDataIsUnreliable($data, $key)) return false;
}
return true;
}
|
php
|
private function checkVisitorDataIsReliable()
{
$data = $this->getVisitorData();
foreach (['user_id', 'client_ip', 'user_agent'] as $key) {
if ($this->checkDataIsUnreliable($data, $key)) return false;
}
return true;
}
|
[
"private",
"function",
"checkVisitorDataIsReliable",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getVisitorData",
"(",
")",
";",
"foreach",
"(",
"[",
"'user_id'",
",",
"'client_ip'",
",",
"'user_agent'",
"]",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"checkDataIsUnreliable",
"(",
"$",
"data",
",",
"$",
"key",
")",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Check if the visitor data is reliable.
@return bool
|
[
"Check",
"if",
"the",
"visitor",
"data",
"is",
"reliable",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/VisitorTracker.php#L323-L332
|
221,063
|
ARCANEDEV/LaravelTracker
|
src/Trackers/VisitorTracker.php
|
VisitorTracker.checkDataIsUnreliable
|
private function checkDataIsUnreliable($data, $key)
{
return isset($data[$key]) && ($data[$key] !== $this->visitorInfo[$key]);
}
|
php
|
private function checkDataIsUnreliable($data, $key)
{
return isset($data[$key]) && ($data[$key] !== $this->visitorInfo[$key]);
}
|
[
"private",
"function",
"checkDataIsUnreliable",
"(",
"$",
"data",
",",
"$",
"key",
")",
"{",
"return",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
"&&",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
"!==",
"$",
"this",
"->",
"visitorInfo",
"[",
"$",
"key",
"]",
")",
";",
"}"
] |
Check the data is unreliable.
@param array|null $data
@param string $key
@return bool
|
[
"Check",
"the",
"data",
"is",
"unreliable",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/VisitorTracker.php#L342-L345
|
221,064
|
ARCANEDEV/LaravelTracker
|
src/Trackers/VisitorTracker.php
|
VisitorTracker.ensureVisitorDataIsComplete
|
private function ensureVisitorDataIsComplete()
{
$visitorData = $this->getVisitorData();
$completed = true;
foreach ($this->visitorInfo as $key => $value) {
if ($visitorData[$key] !== $value) {
/** @var \Arcanedev\LaravelTracker\Models\Visitor $model */
if ( ! isset($model))
$model = $this->getModel()->find($this->getVisitorId());
$model->setAttribute($key, $value);
$model->save();
$completed = false;
}
}
if ( ! $completed)
$this->putSessionData($this->visitorInfo);
}
|
php
|
private function ensureVisitorDataIsComplete()
{
$visitorData = $this->getVisitorData();
$completed = true;
foreach ($this->visitorInfo as $key => $value) {
if ($visitorData[$key] !== $value) {
/** @var \Arcanedev\LaravelTracker\Models\Visitor $model */
if ( ! isset($model))
$model = $this->getModel()->find($this->getVisitorId());
$model->setAttribute($key, $value);
$model->save();
$completed = false;
}
}
if ( ! $completed)
$this->putSessionData($this->visitorInfo);
}
|
[
"private",
"function",
"ensureVisitorDataIsComplete",
"(",
")",
"{",
"$",
"visitorData",
"=",
"$",
"this",
"->",
"getVisitorData",
"(",
")",
";",
"$",
"completed",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"visitorInfo",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"visitorData",
"[",
"$",
"key",
"]",
"!==",
"$",
"value",
")",
"{",
"/** @var \\Arcanedev\\LaravelTracker\\Models\\Visitor $model */",
"if",
"(",
"!",
"isset",
"(",
"$",
"model",
")",
")",
"$",
"model",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"find",
"(",
"$",
"this",
"->",
"getVisitorId",
"(",
")",
")",
";",
"$",
"model",
"->",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"$",
"model",
"->",
"save",
"(",
")",
";",
"$",
"completed",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"completed",
")",
"$",
"this",
"->",
"putSessionData",
"(",
"$",
"this",
"->",
"visitorInfo",
")",
";",
"}"
] |
Ensure that the visitor data is complete.
|
[
"Ensure",
"that",
"the",
"visitor",
"data",
"is",
"complete",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/VisitorTracker.php#L350-L370
|
221,065
|
ARCANEDEV/LaravelTracker
|
src/Trackers/RefererTracker.php
|
RefererTracker.track
|
public function track($refererUrl, $pageUrl)
{
$firstParsed = $this->getRefererParser()->parseUrl($refererUrl);
if ($firstParsed) {
$attributes = [
'url' => $firstParsed['url'],
'host' => $firstParsed['host'],
'domain_id' => $this->trackDomain($firstParsed['domain']),
'medium' => null,
'source' => null,
'search_terms_hash' => null,
];
$secondParsed = $this->getRefererParser()->parse($firstParsed['url'], $pageUrl);
if ($secondParsed->isKnown()) {
$attributes['medium'] = $secondParsed->getMedium();
$attributes['source'] = $secondParsed->getSource();
$attributes['search_terms_hash'] = sha1($secondParsed->getSearchTerm());
}
/** @var \Arcanedev\LaravelTracker\Models\Referer $referer */
$referer = $this->getModel()->newQuery()->firstOrCreate(
Arr::only($attributes, ['url', 'search_terms_hash']),
$attributes
);
if ($secondParsed->isKnown()) {
$this->trackRefererSearchTerms($referer, $secondParsed->getSearchTerm());
}
return $referer->id;
}
return null;
}
|
php
|
public function track($refererUrl, $pageUrl)
{
$firstParsed = $this->getRefererParser()->parseUrl($refererUrl);
if ($firstParsed) {
$attributes = [
'url' => $firstParsed['url'],
'host' => $firstParsed['host'],
'domain_id' => $this->trackDomain($firstParsed['domain']),
'medium' => null,
'source' => null,
'search_terms_hash' => null,
];
$secondParsed = $this->getRefererParser()->parse($firstParsed['url'], $pageUrl);
if ($secondParsed->isKnown()) {
$attributes['medium'] = $secondParsed->getMedium();
$attributes['source'] = $secondParsed->getSource();
$attributes['search_terms_hash'] = sha1($secondParsed->getSearchTerm());
}
/** @var \Arcanedev\LaravelTracker\Models\Referer $referer */
$referer = $this->getModel()->newQuery()->firstOrCreate(
Arr::only($attributes, ['url', 'search_terms_hash']),
$attributes
);
if ($secondParsed->isKnown()) {
$this->trackRefererSearchTerms($referer, $secondParsed->getSearchTerm());
}
return $referer->id;
}
return null;
}
|
[
"public",
"function",
"track",
"(",
"$",
"refererUrl",
",",
"$",
"pageUrl",
")",
"{",
"$",
"firstParsed",
"=",
"$",
"this",
"->",
"getRefererParser",
"(",
")",
"->",
"parseUrl",
"(",
"$",
"refererUrl",
")",
";",
"if",
"(",
"$",
"firstParsed",
")",
"{",
"$",
"attributes",
"=",
"[",
"'url'",
"=>",
"$",
"firstParsed",
"[",
"'url'",
"]",
",",
"'host'",
"=>",
"$",
"firstParsed",
"[",
"'host'",
"]",
",",
"'domain_id'",
"=>",
"$",
"this",
"->",
"trackDomain",
"(",
"$",
"firstParsed",
"[",
"'domain'",
"]",
")",
",",
"'medium'",
"=>",
"null",
",",
"'source'",
"=>",
"null",
",",
"'search_terms_hash'",
"=>",
"null",
",",
"]",
";",
"$",
"secondParsed",
"=",
"$",
"this",
"->",
"getRefererParser",
"(",
")",
"->",
"parse",
"(",
"$",
"firstParsed",
"[",
"'url'",
"]",
",",
"$",
"pageUrl",
")",
";",
"if",
"(",
"$",
"secondParsed",
"->",
"isKnown",
"(",
")",
")",
"{",
"$",
"attributes",
"[",
"'medium'",
"]",
"=",
"$",
"secondParsed",
"->",
"getMedium",
"(",
")",
";",
"$",
"attributes",
"[",
"'source'",
"]",
"=",
"$",
"secondParsed",
"->",
"getSource",
"(",
")",
";",
"$",
"attributes",
"[",
"'search_terms_hash'",
"]",
"=",
"sha1",
"(",
"$",
"secondParsed",
"->",
"getSearchTerm",
"(",
")",
")",
";",
"}",
"/** @var \\Arcanedev\\LaravelTracker\\Models\\Referer $referer */",
"$",
"referer",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"newQuery",
"(",
")",
"->",
"firstOrCreate",
"(",
"Arr",
"::",
"only",
"(",
"$",
"attributes",
",",
"[",
"'url'",
",",
"'search_terms_hash'",
"]",
")",
",",
"$",
"attributes",
")",
";",
"if",
"(",
"$",
"secondParsed",
"->",
"isKnown",
"(",
")",
")",
"{",
"$",
"this",
"->",
"trackRefererSearchTerms",
"(",
"$",
"referer",
",",
"$",
"secondParsed",
"->",
"getSearchTerm",
"(",
")",
")",
";",
"}",
"return",
"$",
"referer",
"->",
"id",
";",
"}",
"return",
"null",
";",
"}"
] |
Track the referer and return the id.
@param string $refererUrl
@param string $pageUrl
@return int|null
|
[
"Track",
"the",
"referer",
"and",
"return",
"the",
"id",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/RefererTracker.php#L52-L88
|
221,066
|
ARCANEDEV/LaravelTracker
|
src/Trackers/RefererTracker.php
|
RefererTracker.trackDomain
|
private function trackDomain($name)
{
return $this->makeModel(BindingManager::MODEL_DOMAIN)
->newQuery()
->firstOrCreate(compact('name'))
->getKey();
}
|
php
|
private function trackDomain($name)
{
return $this->makeModel(BindingManager::MODEL_DOMAIN)
->newQuery()
->firstOrCreate(compact('name'))
->getKey();
}
|
[
"private",
"function",
"trackDomain",
"(",
"$",
"name",
")",
"{",
"return",
"$",
"this",
"->",
"makeModel",
"(",
"BindingManager",
"::",
"MODEL_DOMAIN",
")",
"->",
"newQuery",
"(",
")",
"->",
"firstOrCreate",
"(",
"compact",
"(",
"'name'",
")",
")",
"->",
"getKey",
"(",
")",
";",
"}"
] |
Track the domain and get the id.
@param string $name
@return int
|
[
"Track",
"the",
"domain",
"and",
"get",
"the",
"id",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/RefererTracker.php#L97-L103
|
221,067
|
ARCANEDEV/LaravelTracker
|
src/Trackers/RefererTracker.php
|
RefererTracker.trackRefererSearchTerms
|
private function trackRefererSearchTerms($referer, $searchTerms)
{
$terms = [];
foreach (explode(' ', $searchTerms) as $term) {
$terms[] = $this->makeModel(BindingManager::MODEL_REFERER_SEARCH_TERM)->fill([
'search_term' => $term,
]);
}
if (count($terms) > 0)
$referer->searchTerms()->saveMany($terms);
}
|
php
|
private function trackRefererSearchTerms($referer, $searchTerms)
{
$terms = [];
foreach (explode(' ', $searchTerms) as $term) {
$terms[] = $this->makeModel(BindingManager::MODEL_REFERER_SEARCH_TERM)->fill([
'search_term' => $term,
]);
}
if (count($terms) > 0)
$referer->searchTerms()->saveMany($terms);
}
|
[
"private",
"function",
"trackRefererSearchTerms",
"(",
"$",
"referer",
",",
"$",
"searchTerms",
")",
"{",
"$",
"terms",
"=",
"[",
"]",
";",
"foreach",
"(",
"explode",
"(",
"' '",
",",
"$",
"searchTerms",
")",
"as",
"$",
"term",
")",
"{",
"$",
"terms",
"[",
"]",
"=",
"$",
"this",
"->",
"makeModel",
"(",
"BindingManager",
"::",
"MODEL_REFERER_SEARCH_TERM",
")",
"->",
"fill",
"(",
"[",
"'search_term'",
"=>",
"$",
"term",
",",
"]",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"terms",
")",
">",
"0",
")",
"$",
"referer",
"->",
"searchTerms",
"(",
")",
"->",
"saveMany",
"(",
"$",
"terms",
")",
";",
"}"
] |
Store the referer's search terms.
@param \Arcanedev\LaravelTracker\Contracts\Models\Referer $referer
@param string $searchTerms
|
[
"Store",
"the",
"referer",
"s",
"search",
"terms",
"."
] |
9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6
|
https://github.com/ARCANEDEV/LaravelTracker/blob/9bd728dd89ea7e10ea8b92efa2af9ab9d99dcab6/src/Trackers/RefererTracker.php#L111-L124
|
221,068
|
particle-php/Filter
|
src/Value/Container.php
|
Container.traverse
|
protected function traverse($key, $returnValue = true)
{
$value = $this->values;
foreach (explode('.', $key) as $part) {
if (!array_key_exists($part, $value)) {
return false;
}
$value = $value[$part];
}
return $returnValue ? $value : true;
}
|
php
|
protected function traverse($key, $returnValue = true)
{
$value = $this->values;
foreach (explode('.', $key) as $part) {
if (!array_key_exists($part, $value)) {
return false;
}
$value = $value[$part];
}
return $returnValue ? $value : true;
}
|
[
"protected",
"function",
"traverse",
"(",
"$",
"key",
",",
"$",
"returnValue",
"=",
"true",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"values",
";",
"foreach",
"(",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"part",
",",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"value",
"=",
"$",
"value",
"[",
"$",
"part",
"]",
";",
"}",
"return",
"$",
"returnValue",
"?",
"$",
"value",
":",
"true",
";",
"}"
] |
Traverses the key using dot notation. Based on the second parameter, it will return the value or if it was set.
@param string $key
@param bool $returnValue
@return mixed
|
[
"Traverses",
"the",
"key",
"using",
"dot",
"notation",
".",
"Based",
"on",
"the",
"second",
"parameter",
"it",
"will",
"return",
"the",
"value",
"or",
"if",
"it",
"was",
"set",
"."
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/Value/Container.php#L100-L110
|
221,069
|
particle-php/Filter
|
src/Value/Container.php
|
Container.setTraverse
|
protected function setTraverse($key, $value)
{
$parts = explode('.', $key);
$ref = &$this->values;
foreach ($parts as $i => $part) {
$ref = &$ref[$part];
}
$ref = $value;
return $this;
}
|
php
|
protected function setTraverse($key, $value)
{
$parts = explode('.', $key);
$ref = &$this->values;
foreach ($parts as $i => $part) {
$ref = &$ref[$part];
}
$ref = $value;
return $this;
}
|
[
"protected",
"function",
"setTraverse",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"ref",
"=",
"&",
"$",
"this",
"->",
"values",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"i",
"=>",
"$",
"part",
")",
"{",
"$",
"ref",
"=",
"&",
"$",
"ref",
"[",
"$",
"part",
"]",
";",
"}",
"$",
"ref",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] |
Uses dot-notation to set a value.
@param string $key
@param mixed $value
@return $this
|
[
"Uses",
"dot",
"-",
"notation",
"to",
"set",
"a",
"value",
"."
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/Value/Container.php#L119-L130
|
221,070
|
particle-php/Filter
|
src/FilterResource.php
|
FilterResource.cut
|
public function cut($start, $length = null)
{
return $this->addRule(new FilterRule\Cut($start, $length));
}
|
php
|
public function cut($start, $length = null)
{
return $this->addRule(new FilterRule\Cut($start, $length));
}
|
[
"public",
"function",
"cut",
"(",
"$",
"start",
",",
"$",
"length",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"addRule",
"(",
"new",
"FilterRule",
"\\",
"Cut",
"(",
"$",
"start",
",",
"$",
"length",
")",
")",
";",
"}"
] |
Results rule that returns the cut value
@param int $start
@param int|null $length
@return $this
|
[
"Results",
"rule",
"that",
"returns",
"the",
"cut",
"value"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/FilterResource.php#L87-L90
|
221,071
|
particle-php/Filter
|
src/FilterResource.php
|
FilterResource.decodeJSON
|
public function decodeJSON($assoc = true, $depth = 512, $options = 0)
{
return $this->addRule(new FilterRule\DecodeJSON($assoc, $depth, $options));
}
|
php
|
public function decodeJSON($assoc = true, $depth = 512, $options = 0)
{
return $this->addRule(new FilterRule\DecodeJSON($assoc, $depth, $options));
}
|
[
"public",
"function",
"decodeJSON",
"(",
"$",
"assoc",
"=",
"true",
",",
"$",
"depth",
"=",
"512",
",",
"$",
"options",
"=",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"addRule",
"(",
"new",
"FilterRule",
"\\",
"DecodeJSON",
"(",
"$",
"assoc",
",",
"$",
"depth",
",",
"$",
"options",
")",
")",
";",
"}"
] |
Returns rule that decodes JSON code of a given value
@param bool $assoc When `true`, decoded objects will be converted into associative arrays (the default value is
set to `true` because both Filter and Validator can't deal with objects)
@param int $depth Decode recursion dept
@param int $options Bitmask of JSON decode options
@see http://php.net/manual/en/function.json-decode.php More information about the parameters
@return $this
|
[
"Returns",
"rule",
"that",
"decodes",
"JSON",
"code",
"of",
"a",
"given",
"value"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/FilterResource.php#L102-L105
|
221,072
|
particle-php/Filter
|
src/FilterResource.php
|
FilterResource.encode
|
public function encode($toEncodingFormat = null, $fromEncodingFormat = null)
{
return $this->addRule(new FilterRule\Encode($toEncodingFormat, $fromEncodingFormat));
}
|
php
|
public function encode($toEncodingFormat = null, $fromEncodingFormat = null)
{
return $this->addRule(new FilterRule\Encode($toEncodingFormat, $fromEncodingFormat));
}
|
[
"public",
"function",
"encode",
"(",
"$",
"toEncodingFormat",
"=",
"null",
",",
"$",
"fromEncodingFormat",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"addRule",
"(",
"new",
"FilterRule",
"\\",
"Encode",
"(",
"$",
"toEncodingFormat",
",",
"$",
"fromEncodingFormat",
")",
")",
";",
"}"
] |
Returns rule that returns an value in a specific encoding format
@param string|null $toEncodingFormat
@param string|null $fromEncodingFormat
@return $this
|
[
"Returns",
"rule",
"that",
"returns",
"an",
"value",
"in",
"a",
"specific",
"encoding",
"format"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/FilterResource.php#L136-L139
|
221,073
|
particle-php/Filter
|
src/FilterResource.php
|
FilterResource.numberFormat
|
public function numberFormat($decimals, $decimalPoint, $thousandSeparator)
{
return $this->addRule(new FilterRule\NumberFormat($decimals, $decimalPoint, $thousandSeparator));
}
|
php
|
public function numberFormat($decimals, $decimalPoint, $thousandSeparator)
{
return $this->addRule(new FilterRule\NumberFormat($decimals, $decimalPoint, $thousandSeparator));
}
|
[
"public",
"function",
"numberFormat",
"(",
"$",
"decimals",
",",
"$",
"decimalPoint",
",",
"$",
"thousandSeparator",
")",
"{",
"return",
"$",
"this",
"->",
"addRule",
"(",
"new",
"FilterRule",
"\\",
"NumberFormat",
"(",
"$",
"decimals",
",",
"$",
"decimalPoint",
",",
"$",
"thousandSeparator",
")",
")",
";",
"}"
] |
Returns rule that formats numbers
@param int $decimals
@param string $decimalPoint
@param string $thousandSeparator
@return $this
|
[
"Returns",
"rule",
"that",
"formats",
"numbers"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/FilterResource.php#L189-L192
|
221,074
|
particle-php/Filter
|
src/FilterRule/Upper.php
|
Upper.filter
|
public function filter($value)
{
if ($this->encodingFormat !== null) {
return mb_strtoupper($value, $this->encodingFormat);
}
return mb_strtoupper($value);
}
|
php
|
public function filter($value)
{
if ($this->encodingFormat !== null) {
return mb_strtoupper($value, $this->encodingFormat);
}
return mb_strtoupper($value);
}
|
[
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"encodingFormat",
"!==",
"null",
")",
"{",
"return",
"mb_strtoupper",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"encodingFormat",
")",
";",
"}",
"return",
"mb_strtoupper",
"(",
"$",
"value",
")",
";",
"}"
] |
Uppercase the given value
@param mixed $value
@return string
|
[
"Uppercase",
"the",
"given",
"value"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/FilterRule/Upper.php#L26-L33
|
221,075
|
particle-php/Filter
|
src/Filter.php
|
Filter.addFilterRule
|
public function addFilterRule(FilterRule $rule, $key = null)
{
$this->getChain($key)->addRule($rule, $this->encodingFormat);
}
|
php
|
public function addFilterRule(FilterRule $rule, $key = null)
{
$this->getChain($key)->addRule($rule, $this->encodingFormat);
}
|
[
"public",
"function",
"addFilterRule",
"(",
"FilterRule",
"$",
"rule",
",",
"$",
"key",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"getChain",
"(",
"$",
"key",
")",
"->",
"addRule",
"(",
"$",
"rule",
",",
"$",
"this",
"->",
"encodingFormat",
")",
";",
"}"
] |
Set a filter rule on a chain
@param FilterRule $rule
@param null|string $key
|
[
"Set",
"a",
"filter",
"rule",
"on",
"a",
"chain"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/Filter.php#L99-L102
|
221,076
|
particle-php/Filter
|
src/Filter.php
|
Filter.filter
|
public function filter(array $data)
{
$data = $this->filterArrayWithGlobalChain($data);
$this->data = new Container($data);
$this->filterChains();
return $this->data->getArrayCopy();
}
|
php
|
public function filter(array $data)
{
$data = $this->filterArrayWithGlobalChain($data);
$this->data = new Container($data);
$this->filterChains();
return $this->data->getArrayCopy();
}
|
[
"public",
"function",
"filter",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"filterArrayWithGlobalChain",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"data",
"=",
"new",
"Container",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"filterChains",
"(",
")",
";",
"return",
"$",
"this",
"->",
"data",
"->",
"getArrayCopy",
"(",
")",
";",
"}"
] |
Filter the provided data
@param array $data
@return array
|
[
"Filter",
"the",
"provided",
"data"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/Filter.php#L110-L119
|
221,077
|
particle-php/Filter
|
src/Filter.php
|
Filter.filterArrayWithGlobalChain
|
protected function filterArrayWithGlobalChain(array $data)
{
if ($this->globalChain === null) {
return $data;
}
foreach ($data as $key => $value) {
$data = $this->filterValueWithGlobalChain($value, $key, $data);
}
return array_filter($data);
}
|
php
|
protected function filterArrayWithGlobalChain(array $data)
{
if ($this->globalChain === null) {
return $data;
}
foreach ($data as $key => $value) {
$data = $this->filterValueWithGlobalChain($value, $key, $data);
}
return array_filter($data);
}
|
[
"protected",
"function",
"filterArrayWithGlobalChain",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"globalChain",
"===",
"null",
")",
"{",
"return",
"$",
"data",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"filterValueWithGlobalChain",
"(",
"$",
"value",
",",
"$",
"key",
",",
"$",
"data",
")",
";",
"}",
"return",
"array_filter",
"(",
"$",
"data",
")",
";",
"}"
] |
Filter all set fields with a global chain, recursively
@param array $data
@return array
|
[
"Filter",
"all",
"set",
"fields",
"with",
"a",
"global",
"chain",
"recursively"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/Filter.php#L127-L138
|
221,078
|
particle-php/Filter
|
src/Filter.php
|
Filter.filterValueWithGlobalChain
|
protected function filterValueWithGlobalChain($value, $key, $data)
{
if (is_array($value)) {
$data[$key] = $this->filterArrayWithGlobalChain($value);
return $data;
}
$filterResult = $this->globalChain->filter(true, $value, $data);
if ($filterResult->isNotEmpty()) {
$data[$key] = $filterResult->getFilteredValue();
} else {
unset($data[$key]);
}
return $data;
}
|
php
|
protected function filterValueWithGlobalChain($value, $key, $data)
{
if (is_array($value)) {
$data[$key] = $this->filterArrayWithGlobalChain($value);
return $data;
}
$filterResult = $this->globalChain->filter(true, $value, $data);
if ($filterResult->isNotEmpty()) {
$data[$key] = $filterResult->getFilteredValue();
} else {
unset($data[$key]);
}
return $data;
}
|
[
"protected",
"function",
"filterValueWithGlobalChain",
"(",
"$",
"value",
",",
"$",
"key",
",",
"$",
"data",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"filterArrayWithGlobalChain",
"(",
"$",
"value",
")",
";",
"return",
"$",
"data",
";",
"}",
"$",
"filterResult",
"=",
"$",
"this",
"->",
"globalChain",
"->",
"filter",
"(",
"true",
",",
"$",
"value",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"filterResult",
"->",
"isNotEmpty",
"(",
")",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"filterResult",
"->",
"getFilteredValue",
"(",
")",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Filters a value with the global chain
@param mixed $value
@param string $key
@param array $data
@return array
|
[
"Filters",
"a",
"value",
"with",
"the",
"global",
"chain"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/Filter.php#L148-L162
|
221,079
|
particle-php/Filter
|
src/Filter.php
|
Filter.getFilterResult
|
protected function getFilterResult($key, Chain $chain)
{
if ($this->data->has($key)) {
return $chain->filter(true, $this->data->get($key), $this->data->getArrayCopy());
}
return $chain->filter(false, null, $this->data->getArrayCopy());
}
|
php
|
protected function getFilterResult($key, Chain $chain)
{
if ($this->data->has($key)) {
return $chain->filter(true, $this->data->get($key), $this->data->getArrayCopy());
}
return $chain->filter(false, null, $this->data->getArrayCopy());
}
|
[
"protected",
"function",
"getFilterResult",
"(",
"$",
"key",
",",
"Chain",
"$",
"chain",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"data",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"chain",
"->",
"filter",
"(",
"true",
",",
"$",
"this",
"->",
"data",
"->",
"get",
"(",
"$",
"key",
")",
",",
"$",
"this",
"->",
"data",
"->",
"getArrayCopy",
"(",
")",
")",
";",
"}",
"return",
"$",
"chain",
"->",
"filter",
"(",
"false",
",",
"null",
",",
"$",
"this",
"->",
"data",
"->",
"getArrayCopy",
"(",
")",
")",
";",
"}"
] |
Get the filter result from a chain
@param string $key
@param Chain $chain
@return FilterResult
|
[
"Get",
"the",
"filter",
"result",
"from",
"a",
"chain"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/Filter.php#L171-L178
|
221,080
|
particle-php/Filter
|
src/Filter.php
|
Filter.filterChains
|
protected function filterChains()
{
foreach ($this->chains as $key => $chain) {
$filterResult = $this->getFilterResult($key, $chain);
if ($filterResult->isNotEmpty()) {
$this->data->set(
$key,
$filterResult->getFilteredValue()
);
} else {
$this->data->remove($key);
}
}
}
|
php
|
protected function filterChains()
{
foreach ($this->chains as $key => $chain) {
$filterResult = $this->getFilterResult($key, $chain);
if ($filterResult->isNotEmpty()) {
$this->data->set(
$key,
$filterResult->getFilteredValue()
);
} else {
$this->data->remove($key);
}
}
}
|
[
"protected",
"function",
"filterChains",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"chains",
"as",
"$",
"key",
"=>",
"$",
"chain",
")",
"{",
"$",
"filterResult",
"=",
"$",
"this",
"->",
"getFilterResult",
"(",
"$",
"key",
",",
"$",
"chain",
")",
";",
"if",
"(",
"$",
"filterResult",
"->",
"isNotEmpty",
"(",
")",
")",
"{",
"$",
"this",
"->",
"data",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"filterResult",
"->",
"getFilteredValue",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"data",
"->",
"remove",
"(",
"$",
"key",
")",
";",
"}",
"}",
"}"
] |
Filter all chains set
|
[
"Filter",
"all",
"chains",
"set"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/Filter.php#L183-L196
|
221,081
|
particle-php/Filter
|
src/Filter.php
|
Filter.getChain
|
protected function getChain($key)
{
// If no key, set global chain
if ($key === null) {
return $this->getGlobalChain();
}
// Return chain for key
if (isset($this->chains[$key])) {
return $this->chains[$key];
}
return $this->chains[$key] = $this->buildChain();
}
|
php
|
protected function getChain($key)
{
// If no key, set global chain
if ($key === null) {
return $this->getGlobalChain();
}
// Return chain for key
if (isset($this->chains[$key])) {
return $this->chains[$key];
}
return $this->chains[$key] = $this->buildChain();
}
|
[
"protected",
"function",
"getChain",
"(",
"$",
"key",
")",
"{",
"// If no key, set global chain",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getGlobalChain",
"(",
")",
";",
"}",
"// Return chain for key",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"chains",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"chains",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"chains",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"buildChain",
"(",
")",
";",
"}"
] |
Get a filter rule chain for a key
@param null|string $key
@return Chain
|
[
"Get",
"a",
"filter",
"rule",
"chain",
"for",
"a",
"key"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/Filter.php#L204-L216
|
221,082
|
particle-php/Filter
|
src/Filter.php
|
Filter.getGlobalChain
|
protected function getGlobalChain()
{
if ($this->globalChain === null) {
$this->globalChain = $this->buildChain();
}
return $this->globalChain;
}
|
php
|
protected function getGlobalChain()
{
if ($this->globalChain === null) {
$this->globalChain = $this->buildChain();
}
return $this->globalChain;
}
|
[
"protected",
"function",
"getGlobalChain",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"globalChain",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"globalChain",
"=",
"$",
"this",
"->",
"buildChain",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"globalChain",
";",
"}"
] |
Get the global chain for all values
@return Chain
|
[
"Get",
"the",
"global",
"chain",
"for",
"all",
"values"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/Filter.php#L223-L229
|
221,083
|
particle-php/Filter
|
src/Chain.php
|
Chain.filter
|
public function filter($isSet, $value = null, $filterData = null)
{
/** @var FilterRule $rule */
foreach ($this->rules as $rule) {
$rule->setFilterData($filterData);
if ($isSet || $rule->allowedNotSet()) {
$value = $rule->filter($value);
$isSet = $rule->isNotEmpty();
}
}
return new FilterResult($isSet, $value);
}
|
php
|
public function filter($isSet, $value = null, $filterData = null)
{
/** @var FilterRule $rule */
foreach ($this->rules as $rule) {
$rule->setFilterData($filterData);
if ($isSet || $rule->allowedNotSet()) {
$value = $rule->filter($value);
$isSet = $rule->isNotEmpty();
}
}
return new FilterResult($isSet, $value);
}
|
[
"public",
"function",
"filter",
"(",
"$",
"isSet",
",",
"$",
"value",
"=",
"null",
",",
"$",
"filterData",
"=",
"null",
")",
"{",
"/** @var FilterRule $rule */",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"rule",
")",
"{",
"$",
"rule",
"->",
"setFilterData",
"(",
"$",
"filterData",
")",
";",
"if",
"(",
"$",
"isSet",
"||",
"$",
"rule",
"->",
"allowedNotSet",
"(",
")",
")",
"{",
"$",
"value",
"=",
"$",
"rule",
"->",
"filter",
"(",
"$",
"value",
")",
";",
"$",
"isSet",
"=",
"$",
"rule",
"->",
"isNotEmpty",
"(",
")",
";",
"}",
"}",
"return",
"new",
"FilterResult",
"(",
"$",
"isSet",
",",
"$",
"value",
")",
";",
"}"
] |
Execute all filters in the chain
@param bool $isSet
@param mixed $value
@param array|null $filterData
@return FilterResult
@throws ExpectFilterResultException
|
[
"Execute",
"all",
"filters",
"in",
"the",
"chain"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/Chain.php#L34-L47
|
221,084
|
Mastercard/sdk-core-php
|
MasterCard/Core/Exception/ApiException.php
|
ApiException.describe
|
function describe() {
return get_class($this) . ": \""
. $this->getMessage() . "\" (http_status: "
. $this->getHttpStatus() . ", reason_code: "
. $this->getReasonCode() . ", source: "
. $this->getSource() . ")";
}
|
php
|
function describe() {
return get_class($this) . ": \""
. $this->getMessage() . "\" (http_status: "
. $this->getHttpStatus() . ", reason_code: "
. $this->getReasonCode() . ", source: "
. $this->getSource() . ")";
}
|
[
"function",
"describe",
"(",
")",
"{",
"return",
"get_class",
"(",
"$",
"this",
")",
".",
"\": \\\"\"",
".",
"$",
"this",
"->",
"getMessage",
"(",
")",
".",
"\"\\\" (http_status: \"",
".",
"$",
"this",
"->",
"getHttpStatus",
"(",
")",
".",
"\", reason_code: \"",
".",
"$",
"this",
"->",
"getReasonCode",
"(",
")",
".",
"\", source: \"",
".",
"$",
"this",
"->",
"getSource",
"(",
")",
".",
"\")\"",
";",
"}"
] |
Returns a description of the error.
@return string Description of the error.
|
[
"Returns",
"a",
"description",
"of",
"the",
"error",
"."
] |
4785426d649771aedd15bd498708e7995c78df8c
|
https://github.com/Mastercard/sdk-core-php/blob/4785426d649771aedd15bd498708e7995c78df8c/MasterCard/Core/Exception/ApiException.php#L135-L141
|
221,085
|
valorin/deploy
|
src/Command/Deploy.php
|
Deploy.push
|
protected function push()
{
// Check if push is enabled
if (!Config::get('vdeploy::config.push')) {
return true;
}
passthru('git push', $code);
if ($code) {
$this->error("FAILED: git push");
return false;
}
passthru('git push --tags', $code);
if ($code) {
$this->error("Failed: git push --tags");
return false;
}
return true;
}
|
php
|
protected function push()
{
// Check if push is enabled
if (!Config::get('vdeploy::config.push')) {
return true;
}
passthru('git push', $code);
if ($code) {
$this->error("FAILED: git push");
return false;
}
passthru('git push --tags', $code);
if ($code) {
$this->error("Failed: git push --tags");
return false;
}
return true;
}
|
[
"protected",
"function",
"push",
"(",
")",
"{",
"// Check if push is enabled",
"if",
"(",
"!",
"Config",
"::",
"get",
"(",
"'vdeploy::config.push'",
")",
")",
"{",
"return",
"true",
";",
"}",
"passthru",
"(",
"'git push'",
",",
"$",
"code",
")",
";",
"if",
"(",
"$",
"code",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"FAILED: git push\"",
")",
";",
"return",
"false",
";",
"}",
"passthru",
"(",
"'git push --tags'",
",",
"$",
"code",
")",
";",
"if",
"(",
"$",
"code",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Failed: git push --tags\"",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Runs the push, if requested
@return boolean
|
[
"Runs",
"the",
"push",
"if",
"requested"
] |
f1a2a0c9d4fdfd91250f6f3af616d0c964c2aa00
|
https://github.com/valorin/deploy/blob/f1a2a0c9d4fdfd91250f6f3af616d0c964c2aa00/src/Command/Deploy.php#L91-L111
|
221,086
|
valorin/deploy
|
src/Command/Deploy.php
|
Deploy.production
|
protected function production()
{
// Check if push is enabled
if (!Config::get('vdeploy::config.production.enabled')) {
return true;
}
// Check for production
$remote = $this->argument('remote');
if ($remote != Config::get('vdeploy::config.production.name')) {
return true;
}
// Check if we need to tag
$rawTag = trim(`git describe --tags --match 'v[0-9]*'`);
$tag = trim(`git describe --tags --match 'v[0-9]*' --abbrev=0`);
if ($rawTag == $tag) {
return true;
}
// Extract parts
$parts = preg_split("#[.-]#", substr($tag, 1));
$preRelease = null;
$preIncrement = 1;
if (count($parts) == 3) {
list($major, $minor, $patch) = $parts;
} elseif (count($parts) == 4) {
list($major, $minor, $patch, $preRelease) = $parts;
} elseif (count($parts) == 5) {
list($major, $minor, $patch, $preRelease, $preIncrement) = $parts;
} else {
$this->error("Unknown tag format: {$tag}");
return false;
}
// Check if we've been told what type of release to do
$newTag = $this->incrementTag($tag, $major, $minor, $patch, $preRelease, $preIncrement);
if (!$newTag) {
return false;
}
// Add tag
$this->info("Tagging deployed version as: {$newTag}.");
passthru("git tag {$newTag}", $code);
if ($code) {
$this->error("FAILED: git tag {$newTag}");
return false;
}
return true;
}
|
php
|
protected function production()
{
// Check if push is enabled
if (!Config::get('vdeploy::config.production.enabled')) {
return true;
}
// Check for production
$remote = $this->argument('remote');
if ($remote != Config::get('vdeploy::config.production.name')) {
return true;
}
// Check if we need to tag
$rawTag = trim(`git describe --tags --match 'v[0-9]*'`);
$tag = trim(`git describe --tags --match 'v[0-9]*' --abbrev=0`);
if ($rawTag == $tag) {
return true;
}
// Extract parts
$parts = preg_split("#[.-]#", substr($tag, 1));
$preRelease = null;
$preIncrement = 1;
if (count($parts) == 3) {
list($major, $minor, $patch) = $parts;
} elseif (count($parts) == 4) {
list($major, $minor, $patch, $preRelease) = $parts;
} elseif (count($parts) == 5) {
list($major, $minor, $patch, $preRelease, $preIncrement) = $parts;
} else {
$this->error("Unknown tag format: {$tag}");
return false;
}
// Check if we've been told what type of release to do
$newTag = $this->incrementTag($tag, $major, $minor, $patch, $preRelease, $preIncrement);
if (!$newTag) {
return false;
}
// Add tag
$this->info("Tagging deployed version as: {$newTag}.");
passthru("git tag {$newTag}", $code);
if ($code) {
$this->error("FAILED: git tag {$newTag}");
return false;
}
return true;
}
|
[
"protected",
"function",
"production",
"(",
")",
"{",
"// Check if push is enabled",
"if",
"(",
"!",
"Config",
"::",
"get",
"(",
"'vdeploy::config.production.enabled'",
")",
")",
"{",
"return",
"true",
";",
"}",
"// Check for production",
"$",
"remote",
"=",
"$",
"this",
"->",
"argument",
"(",
"'remote'",
")",
";",
"if",
"(",
"$",
"remote",
"!=",
"Config",
"::",
"get",
"(",
"'vdeploy::config.production.name'",
")",
")",
"{",
"return",
"true",
";",
"}",
"// Check if we need to tag",
"$",
"rawTag",
"=",
"trim",
"(",
"`git describe --tags --match 'v[0-9]*'`);\n $tag = trim(`git describe --tags --match 'v[0-9]*' --abbrev=0`",
")",
";",
"if",
"(",
"$",
"rawTag",
"==",
"$",
"tag",
")",
"{",
"return",
"true",
";",
"}",
"// Extract parts",
"$",
"parts",
"=",
"preg_split",
"(",
"\"#[.-]#\"",
",",
"substr",
"(",
"$",
"tag",
",",
"1",
")",
")",
";",
"$",
"preRelease",
"=",
"null",
";",
"$",
"preIncrement",
"=",
"1",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"==",
"3",
")",
"{",
"list",
"(",
"$",
"major",
",",
"$",
"minor",
",",
"$",
"patch",
")",
"=",
"$",
"parts",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"parts",
")",
"==",
"4",
")",
"{",
"list",
"(",
"$",
"major",
",",
"$",
"minor",
",",
"$",
"patch",
",",
"$",
"preRelease",
")",
"=",
"$",
"parts",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"parts",
")",
"==",
"5",
")",
"{",
"list",
"(",
"$",
"major",
",",
"$",
"minor",
",",
"$",
"patch",
",",
"$",
"preRelease",
",",
"$",
"preIncrement",
")",
"=",
"$",
"parts",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Unknown tag format: {$tag}\"",
")",
";",
"return",
"false",
";",
"}",
"// Check if we've been told what type of release to do",
"$",
"newTag",
"=",
"$",
"this",
"->",
"incrementTag",
"(",
"$",
"tag",
",",
"$",
"major",
",",
"$",
"minor",
",",
"$",
"patch",
",",
"$",
"preRelease",
",",
"$",
"preIncrement",
")",
";",
"if",
"(",
"!",
"$",
"newTag",
")",
"{",
"return",
"false",
";",
"}",
"// Add tag",
"$",
"this",
"->",
"info",
"(",
"\"Tagging deployed version as: {$newTag}.\"",
")",
";",
"passthru",
"(",
"\"git tag {$newTag}\"",
",",
"$",
"code",
")",
";",
"if",
"(",
"$",
"code",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"FAILED: git tag {$newTag}\"",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Runs the production code, if requested
@return boolean
|
[
"Runs",
"the",
"production",
"code",
"if",
"requested"
] |
f1a2a0c9d4fdfd91250f6f3af616d0c964c2aa00
|
https://github.com/valorin/deploy/blob/f1a2a0c9d4fdfd91250f6f3af616d0c964c2aa00/src/Command/Deploy.php#L118-L171
|
221,087
|
valorin/deploy
|
src/Command/Deploy.php
|
Deploy.incrementTag
|
protected function incrementTag($current, $major, $minor, $patch, $preRelease, $preIncrement)
{
// Current version
$this->line('');
$this->info("The current release version is: {$current}.");
// Simple options
$tag['major'] = 'v'.($major+1).'.0.0';
$tag['minor'] = "v{$major}.".($minor+1).'.0';
$tag['patch'] = "v{$major}.{$minor}.".($patch+1);
// Next RC versions
$majorPlus = $major + 1;
$minorPlus = $minor + 1;
$tag['rcmajor'] = "v{$majorPlus}.0.0-rc";
$tag['rcminor'] = "v{$major}.{$minorPlus}.0-rc";
// Increment RC version
if ($preRelease) {
$extra = ((($preIncrement + 1) > 1) ? '.'.($preIncrement + 1) : '');
$tag['rc'] = "v{$major}.{$minor}.{$patch}-rc{$extra}";
}
// Check if user provided the release
$release = $this->argument("release");
// If release not specified, ask the user
if (!$release) {
$this->line('');
$release = array_search($this->choice("Please select the next release version:", $tag), $tag);
}
// Check valid release
if (!isset($tag[$release])) {
$this->error("Unknown release type: {$release}");
return false;
}
return $tag[$release];
}
|
php
|
protected function incrementTag($current, $major, $minor, $patch, $preRelease, $preIncrement)
{
// Current version
$this->line('');
$this->info("The current release version is: {$current}.");
// Simple options
$tag['major'] = 'v'.($major+1).'.0.0';
$tag['minor'] = "v{$major}.".($minor+1).'.0';
$tag['patch'] = "v{$major}.{$minor}.".($patch+1);
// Next RC versions
$majorPlus = $major + 1;
$minorPlus = $minor + 1;
$tag['rcmajor'] = "v{$majorPlus}.0.0-rc";
$tag['rcminor'] = "v{$major}.{$minorPlus}.0-rc";
// Increment RC version
if ($preRelease) {
$extra = ((($preIncrement + 1) > 1) ? '.'.($preIncrement + 1) : '');
$tag['rc'] = "v{$major}.{$minor}.{$patch}-rc{$extra}";
}
// Check if user provided the release
$release = $this->argument("release");
// If release not specified, ask the user
if (!$release) {
$this->line('');
$release = array_search($this->choice("Please select the next release version:", $tag), $tag);
}
// Check valid release
if (!isset($tag[$release])) {
$this->error("Unknown release type: {$release}");
return false;
}
return $tag[$release];
}
|
[
"protected",
"function",
"incrementTag",
"(",
"$",
"current",
",",
"$",
"major",
",",
"$",
"minor",
",",
"$",
"patch",
",",
"$",
"preRelease",
",",
"$",
"preIncrement",
")",
"{",
"// Current version",
"$",
"this",
"->",
"line",
"(",
"''",
")",
";",
"$",
"this",
"->",
"info",
"(",
"\"The current release version is: {$current}.\"",
")",
";",
"// Simple options",
"$",
"tag",
"[",
"'major'",
"]",
"=",
"'v'",
".",
"(",
"$",
"major",
"+",
"1",
")",
".",
"'.0.0'",
";",
"$",
"tag",
"[",
"'minor'",
"]",
"=",
"\"v{$major}.\"",
".",
"(",
"$",
"minor",
"+",
"1",
")",
".",
"'.0'",
";",
"$",
"tag",
"[",
"'patch'",
"]",
"=",
"\"v{$major}.{$minor}.\"",
".",
"(",
"$",
"patch",
"+",
"1",
")",
";",
"// Next RC versions",
"$",
"majorPlus",
"=",
"$",
"major",
"+",
"1",
";",
"$",
"minorPlus",
"=",
"$",
"minor",
"+",
"1",
";",
"$",
"tag",
"[",
"'rcmajor'",
"]",
"=",
"\"v{$majorPlus}.0.0-rc\"",
";",
"$",
"tag",
"[",
"'rcminor'",
"]",
"=",
"\"v{$major}.{$minorPlus}.0-rc\"",
";",
"// Increment RC version",
"if",
"(",
"$",
"preRelease",
")",
"{",
"$",
"extra",
"=",
"(",
"(",
"(",
"$",
"preIncrement",
"+",
"1",
")",
">",
"1",
")",
"?",
"'.'",
".",
"(",
"$",
"preIncrement",
"+",
"1",
")",
":",
"''",
")",
";",
"$",
"tag",
"[",
"'rc'",
"]",
"=",
"\"v{$major}.{$minor}.{$patch}-rc{$extra}\"",
";",
"}",
"// Check if user provided the release",
"$",
"release",
"=",
"$",
"this",
"->",
"argument",
"(",
"\"release\"",
")",
";",
"// If release not specified, ask the user",
"if",
"(",
"!",
"$",
"release",
")",
"{",
"$",
"this",
"->",
"line",
"(",
"''",
")",
";",
"$",
"release",
"=",
"array_search",
"(",
"$",
"this",
"->",
"choice",
"(",
"\"Please select the next release version:\"",
",",
"$",
"tag",
")",
",",
"$",
"tag",
")",
";",
"}",
"// Check valid release",
"if",
"(",
"!",
"isset",
"(",
"$",
"tag",
"[",
"$",
"release",
"]",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Unknown release type: {$release}\"",
")",
";",
"return",
"false",
";",
"}",
"return",
"$",
"tag",
"[",
"$",
"release",
"]",
";",
"}"
] |
Increments the tag, based on argument or user input
@param string $current
@param integer $major
@param integer $minor
@param integer $patch
@param sting $preRelease
@param integer $preIncrement
@return string
|
[
"Increments",
"the",
"tag",
"based",
"on",
"argument",
"or",
"user",
"input"
] |
f1a2a0c9d4fdfd91250f6f3af616d0c964c2aa00
|
https://github.com/valorin/deploy/blob/f1a2a0c9d4fdfd91250f6f3af616d0c964c2aa00/src/Command/Deploy.php#L184-L223
|
221,088
|
valorin/deploy
|
src/Command/Deploy.php
|
Deploy.runCommands
|
protected function runCommands()
{
// Load Remote directory
$remote = $this->argument('remote');
$directory = Config::get('remote.connections.'.$remote.'.root');
// Define commands
$commands = array_merge(['cd '.$directory], Config::get('vdeploy::config.commands'));
$commands = array_filter($commands);
// Parse tags in command
if (!$this->parseTags($commands)) {
return false;
}
// Run Commands
SSH::into($remote)->run($commands);
return true;
}
|
php
|
protected function runCommands()
{
// Load Remote directory
$remote = $this->argument('remote');
$directory = Config::get('remote.connections.'.$remote.'.root');
// Define commands
$commands = array_merge(['cd '.$directory], Config::get('vdeploy::config.commands'));
$commands = array_filter($commands);
// Parse tags in command
if (!$this->parseTags($commands)) {
return false;
}
// Run Commands
SSH::into($remote)->run($commands);
return true;
}
|
[
"protected",
"function",
"runCommands",
"(",
")",
"{",
"// Load Remote directory",
"$",
"remote",
"=",
"$",
"this",
"->",
"argument",
"(",
"'remote'",
")",
";",
"$",
"directory",
"=",
"Config",
"::",
"get",
"(",
"'remote.connections.'",
".",
"$",
"remote",
".",
"'.root'",
")",
";",
"// Define commands",
"$",
"commands",
"=",
"array_merge",
"(",
"[",
"'cd '",
".",
"$",
"directory",
"]",
",",
"Config",
"::",
"get",
"(",
"'vdeploy::config.commands'",
")",
")",
";",
"$",
"commands",
"=",
"array_filter",
"(",
"$",
"commands",
")",
";",
"// Parse tags in command",
"if",
"(",
"!",
"$",
"this",
"->",
"parseTags",
"(",
"$",
"commands",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Run Commands",
"SSH",
"::",
"into",
"(",
"$",
"remote",
")",
"->",
"run",
"(",
"$",
"commands",
")",
";",
"return",
"true",
";",
"}"
] |
Runs the SSH commands on the remote
@return boolean
|
[
"Runs",
"the",
"SSH",
"commands",
"on",
"the",
"remote"
] |
f1a2a0c9d4fdfd91250f6f3af616d0c964c2aa00
|
https://github.com/valorin/deploy/blob/f1a2a0c9d4fdfd91250f6f3af616d0c964c2aa00/src/Command/Deploy.php#L230-L249
|
221,089
|
valorin/deploy
|
src/Command/Deploy.php
|
Deploy.parseTags
|
protected function parseTags(&$command)
{
// Recurse?
if (is_array($command)) {
foreach ($command as &$cmd) {
if (!$this->parseTags($cmd)) {
return false;
}
}
return true;
}
// Look for tags
while (preg_match(self::REGEX_TAG, $command, $matches)) {
// Attempt to load tag
try {
$value = $this->userOption($matches[2]);
// if tag doesn't exist
} catch (\InvalidArgumentException $exception) {
// Default value provided?
if (isset($matches[3])) {
$value = $matches[3];
} else {
// Else, throw error
$this->error("ERROR: You need to specifiy the --".self::TAG_PREFIX.$matches[2]." argument!");
return false;
}
}
// Replace
$command = str_replace($matches[0], $value, $command);
}
return true;
}
|
php
|
protected function parseTags(&$command)
{
// Recurse?
if (is_array($command)) {
foreach ($command as &$cmd) {
if (!$this->parseTags($cmd)) {
return false;
}
}
return true;
}
// Look for tags
while (preg_match(self::REGEX_TAG, $command, $matches)) {
// Attempt to load tag
try {
$value = $this->userOption($matches[2]);
// if tag doesn't exist
} catch (\InvalidArgumentException $exception) {
// Default value provided?
if (isset($matches[3])) {
$value = $matches[3];
} else {
// Else, throw error
$this->error("ERROR: You need to specifiy the --".self::TAG_PREFIX.$matches[2]." argument!");
return false;
}
}
// Replace
$command = str_replace($matches[0], $value, $command);
}
return true;
}
|
[
"protected",
"function",
"parseTags",
"(",
"&",
"$",
"command",
")",
"{",
"// Recurse?",
"if",
"(",
"is_array",
"(",
"$",
"command",
")",
")",
"{",
"foreach",
"(",
"$",
"command",
"as",
"&",
"$",
"cmd",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"parseTags",
"(",
"$",
"cmd",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"// Look for tags",
"while",
"(",
"preg_match",
"(",
"self",
"::",
"REGEX_TAG",
",",
"$",
"command",
",",
"$",
"matches",
")",
")",
"{",
"// Attempt to load tag",
"try",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"userOption",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
";",
"// if tag doesn't exist",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"exception",
")",
"{",
"// Default value provided?",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"3",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"}",
"else",
"{",
"// Else, throw error",
"$",
"this",
"->",
"error",
"(",
"\"ERROR: You need to specifiy the --\"",
".",
"self",
"::",
"TAG_PREFIX",
".",
"$",
"matches",
"[",
"2",
"]",
".",
"\" argument!\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"// Replace",
"$",
"command",
"=",
"str_replace",
"(",
"$",
"matches",
"[",
"0",
"]",
",",
"$",
"value",
",",
"$",
"command",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Parses the user tags in the commands array
@param string|string[] $command
@return boolean
|
[
"Parses",
"the",
"user",
"tags",
"in",
"the",
"commands",
"array"
] |
f1a2a0c9d4fdfd91250f6f3af616d0c964c2aa00
|
https://github.com/valorin/deploy/blob/f1a2a0c9d4fdfd91250f6f3af616d0c964c2aa00/src/Command/Deploy.php#L257-L296
|
221,090
|
particle-php/Filter
|
src/FilterRule/Slug.php
|
Slug.filter
|
public function filter($value)
{
if (empty($value) && isset($this->filterData[$this->fieldToSlugFrom])) {
$value = $this->filterData[$this->fieldToSlugFrom];
}
if (is_null($value)) {
return $this->setEmpty();
}
$value = transliterator_transliterate($this->transliterator, $value);
$value = iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", $value);
$value = preg_replace('/[^\w\d]+/', '-', $value);
$value = trim($value, '-');
return strtolower($value);
}
|
php
|
public function filter($value)
{
if (empty($value) && isset($this->filterData[$this->fieldToSlugFrom])) {
$value = $this->filterData[$this->fieldToSlugFrom];
}
if (is_null($value)) {
return $this->setEmpty();
}
$value = transliterator_transliterate($this->transliterator, $value);
$value = iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", $value);
$value = preg_replace('/[^\w\d]+/', '-', $value);
$value = trim($value, '-');
return strtolower($value);
}
|
[
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"filterData",
"[",
"$",
"this",
"->",
"fieldToSlugFrom",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"filterData",
"[",
"$",
"this",
"->",
"fieldToSlugFrom",
"]",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"setEmpty",
"(",
")",
";",
"}",
"$",
"value",
"=",
"transliterator_transliterate",
"(",
"$",
"this",
"->",
"transliterator",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"iconv",
"(",
"\"UTF-8\"",
",",
"\"ASCII//TRANSLIT//IGNORE\"",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"preg_replace",
"(",
"'/[^\\w\\d]+/'",
",",
"'-'",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
",",
"'-'",
")",
";",
"return",
"strtolower",
"(",
"$",
"value",
")",
";",
"}"
] |
Slug the value of either the actual field of the given one.
@param mixed $value
@return string
|
[
"Slug",
"the",
"value",
"of",
"either",
"the",
"actual",
"field",
"of",
"the",
"given",
"one",
"."
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/FilterRule/Slug.php#L51-L66
|
221,091
|
particle-php/Filter
|
src/FilterRule/Cut.php
|
Cut.filter
|
public function filter($value)
{
if ($this->encodingFormat !== null) {
return mb_substr($value, $this->start, $this->length, $this->encodingFormat);
}
return mb_substr($value, $this->start, $this->length);
}
|
php
|
public function filter($value)
{
if ($this->encodingFormat !== null) {
return mb_substr($value, $this->start, $this->length, $this->encodingFormat);
}
return mb_substr($value, $this->start, $this->length);
}
|
[
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"encodingFormat",
"!==",
"null",
")",
"{",
"return",
"mb_substr",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"start",
",",
"$",
"this",
"->",
"length",
",",
"$",
"this",
"->",
"encodingFormat",
")",
";",
"}",
"return",
"mb_substr",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"start",
",",
"$",
"this",
"->",
"length",
")",
";",
"}"
] |
Cuts the given value
@param mixed $value
@return string
|
[
"Cuts",
"the",
"given",
"value"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/FilterRule/Cut.php#L46-L53
|
221,092
|
particle-php/Filter
|
src/FilterRule/Each.php
|
Each.filter
|
public function filter($values)
{
if (is_array($values)) {
foreach ($values as $key => $value) {
$values[$key] = $this->filterValue($value);
}
}
return $values;
}
|
php
|
public function filter($values)
{
if (is_array($values)) {
foreach ($values as $key => $value) {
$values[$key] = $this->filterValue($value);
}
}
return $values;
}
|
[
"public",
"function",
"filter",
"(",
"$",
"values",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"values",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"filterValue",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"values",
";",
"}"
] |
When provided with an array, the callback filter will be executed for every value
@param mixed $values
@return array
|
[
"When",
"provided",
"with",
"an",
"array",
"the",
"callback",
"filter",
"will",
"be",
"executed",
"for",
"every",
"value"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/FilterRule/Each.php#L40-L49
|
221,093
|
particle-php/Filter
|
src/FilterRule/Each.php
|
Each.filterValue
|
protected function filterValue($value)
{
$filter = new Filter();
call_user_func($this->callable, $filter);
return $filter->filter($value);
}
|
php
|
protected function filterValue($value)
{
$filter = new Filter();
call_user_func($this->callable, $filter);
return $filter->filter($value);
}
|
[
"protected",
"function",
"filterValue",
"(",
"$",
"value",
")",
"{",
"$",
"filter",
"=",
"new",
"Filter",
"(",
")",
";",
"call_user_func",
"(",
"$",
"this",
"->",
"callable",
",",
"$",
"filter",
")",
";",
"return",
"$",
"filter",
"->",
"filter",
"(",
"$",
"value",
")",
";",
"}"
] |
Filter a given value with a new filter instance in a callable
@param $value
@return array
|
[
"Filter",
"a",
"given",
"value",
"with",
"a",
"new",
"filter",
"instance",
"in",
"a",
"callable"
] |
49ba23accb1eb0342438e49258a54ed4e3f3335e
|
https://github.com/particle-php/Filter/blob/49ba23accb1eb0342438e49258a54ed4e3f3335e/src/FilterRule/Each.php#L57-L64
|
221,094
|
Mastercard/sdk-core-php
|
MasterCard/Core/ApiController.php
|
ApiController.getUrl
|
public function getUrl($operationConfig, $operationMetadata, &$inputMap) {
$queryParams = array();
$action = $operationConfig->getAction();
$resourcePath = $operationConfig->getResourcePath();
$queryList = $operationConfig->getQueryParams();
$resolvedHostUrl = $operationMetadata->getHost();
//arizzini: we need to validate the host
$this->validateHost($resolvedHostUrl);
$url = "%s";
//arizzini: we need to apply the environment variable.
if (strpos($resourcePath, "#env") !== FALSE) {
$environment = "";
if (!empty($operationMetadata->getContext())) {
$environment = $operationMetadata->getContext();
}
$resourcePath = str_replace("#env", $environment, $resourcePath);
$resourcePath = str_replace("//", "/", $resourcePath);
}
$tmpUrl = Util::getReplacedPath($this->removeForwardSlashFromTail($resolvedHostUrl).$this->removeForwardSlashFromTail($resourcePath), $inputMap);
array_push($queryParams, $tmpUrl);
switch ($action) {
case "read":
case "delete":
case "list":
case "query":
foreach ($inputMap as $key => $value) {
if(!is_array($value)) {
$url = $this->appendToQueryString($url, "%s=%s");
array_push($queryParams, Util::urlEncode(strval($key)));
array_push($queryParams, Util::urlEncode(strval($value)));
}
}
break;
default:
break;
}
// we need to remove any queryParameters specified in the inputMap and
// add them as quertParameters
switch ($action) {
case "create":
case "update":
$queryMap = Util::subMap($inputMap, $queryList);
foreach ($queryMap as $key => $value) {
if(!is_array($value)) {
$url = $this->appendToQueryString($url, "%s=%s");
array_push($queryParams, Util::urlEncode(strval($key)));
array_push($queryParams, Util::urlEncode(strval($value)));
}
}
break;
default:
break;
}
if ($operationMetadata->isJsonNative() == false) {
$url = $this->appendToQueryString($url, "Format=JSON");
}
$url = vsprintf($url, $queryParams);
return $url;
}
|
php
|
public function getUrl($operationConfig, $operationMetadata, &$inputMap) {
$queryParams = array();
$action = $operationConfig->getAction();
$resourcePath = $operationConfig->getResourcePath();
$queryList = $operationConfig->getQueryParams();
$resolvedHostUrl = $operationMetadata->getHost();
//arizzini: we need to validate the host
$this->validateHost($resolvedHostUrl);
$url = "%s";
//arizzini: we need to apply the environment variable.
if (strpos($resourcePath, "#env") !== FALSE) {
$environment = "";
if (!empty($operationMetadata->getContext())) {
$environment = $operationMetadata->getContext();
}
$resourcePath = str_replace("#env", $environment, $resourcePath);
$resourcePath = str_replace("//", "/", $resourcePath);
}
$tmpUrl = Util::getReplacedPath($this->removeForwardSlashFromTail($resolvedHostUrl).$this->removeForwardSlashFromTail($resourcePath), $inputMap);
array_push($queryParams, $tmpUrl);
switch ($action) {
case "read":
case "delete":
case "list":
case "query":
foreach ($inputMap as $key => $value) {
if(!is_array($value)) {
$url = $this->appendToQueryString($url, "%s=%s");
array_push($queryParams, Util::urlEncode(strval($key)));
array_push($queryParams, Util::urlEncode(strval($value)));
}
}
break;
default:
break;
}
// we need to remove any queryParameters specified in the inputMap and
// add them as quertParameters
switch ($action) {
case "create":
case "update":
$queryMap = Util::subMap($inputMap, $queryList);
foreach ($queryMap as $key => $value) {
if(!is_array($value)) {
$url = $this->appendToQueryString($url, "%s=%s");
array_push($queryParams, Util::urlEncode(strval($key)));
array_push($queryParams, Util::urlEncode(strval($value)));
}
}
break;
default:
break;
}
if ($operationMetadata->isJsonNative() == false) {
$url = $this->appendToQueryString($url, "Format=JSON");
}
$url = vsprintf($url, $queryParams);
return $url;
}
|
[
"public",
"function",
"getUrl",
"(",
"$",
"operationConfig",
",",
"$",
"operationMetadata",
",",
"&",
"$",
"inputMap",
")",
"{",
"$",
"queryParams",
"=",
"array",
"(",
")",
";",
"$",
"action",
"=",
"$",
"operationConfig",
"->",
"getAction",
"(",
")",
";",
"$",
"resourcePath",
"=",
"$",
"operationConfig",
"->",
"getResourcePath",
"(",
")",
";",
"$",
"queryList",
"=",
"$",
"operationConfig",
"->",
"getQueryParams",
"(",
")",
";",
"$",
"resolvedHostUrl",
"=",
"$",
"operationMetadata",
"->",
"getHost",
"(",
")",
";",
"//arizzini: we need to validate the host",
"$",
"this",
"->",
"validateHost",
"(",
"$",
"resolvedHostUrl",
")",
";",
"$",
"url",
"=",
"\"%s\"",
";",
"//arizzini: we need to apply the environment variable.",
"if",
"(",
"strpos",
"(",
"$",
"resourcePath",
",",
"\"#env\"",
")",
"!==",
"FALSE",
")",
"{",
"$",
"environment",
"=",
"\"\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"operationMetadata",
"->",
"getContext",
"(",
")",
")",
")",
"{",
"$",
"environment",
"=",
"$",
"operationMetadata",
"->",
"getContext",
"(",
")",
";",
"}",
"$",
"resourcePath",
"=",
"str_replace",
"(",
"\"#env\"",
",",
"$",
"environment",
",",
"$",
"resourcePath",
")",
";",
"$",
"resourcePath",
"=",
"str_replace",
"(",
"\"//\"",
",",
"\"/\"",
",",
"$",
"resourcePath",
")",
";",
"}",
"$",
"tmpUrl",
"=",
"Util",
"::",
"getReplacedPath",
"(",
"$",
"this",
"->",
"removeForwardSlashFromTail",
"(",
"$",
"resolvedHostUrl",
")",
".",
"$",
"this",
"->",
"removeForwardSlashFromTail",
"(",
"$",
"resourcePath",
")",
",",
"$",
"inputMap",
")",
";",
"array_push",
"(",
"$",
"queryParams",
",",
"$",
"tmpUrl",
")",
";",
"switch",
"(",
"$",
"action",
")",
"{",
"case",
"\"read\"",
":",
"case",
"\"delete\"",
":",
"case",
"\"list\"",
":",
"case",
"\"query\"",
":",
"foreach",
"(",
"$",
"inputMap",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"appendToQueryString",
"(",
"$",
"url",
",",
"\"%s=%s\"",
")",
";",
"array_push",
"(",
"$",
"queryParams",
",",
"Util",
"::",
"urlEncode",
"(",
"strval",
"(",
"$",
"key",
")",
")",
")",
";",
"array_push",
"(",
"$",
"queryParams",
",",
"Util",
"::",
"urlEncode",
"(",
"strval",
"(",
"$",
"value",
")",
")",
")",
";",
"}",
"}",
"break",
";",
"default",
":",
"break",
";",
"}",
"// we need to remove any queryParameters specified in the inputMap and ",
"// add them as quertParameters",
"switch",
"(",
"$",
"action",
")",
"{",
"case",
"\"create\"",
":",
"case",
"\"update\"",
":",
"$",
"queryMap",
"=",
"Util",
"::",
"subMap",
"(",
"$",
"inputMap",
",",
"$",
"queryList",
")",
";",
"foreach",
"(",
"$",
"queryMap",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"appendToQueryString",
"(",
"$",
"url",
",",
"\"%s=%s\"",
")",
";",
"array_push",
"(",
"$",
"queryParams",
",",
"Util",
"::",
"urlEncode",
"(",
"strval",
"(",
"$",
"key",
")",
")",
")",
";",
"array_push",
"(",
"$",
"queryParams",
",",
"Util",
"::",
"urlEncode",
"(",
"strval",
"(",
"$",
"value",
")",
")",
")",
";",
"}",
"}",
"break",
";",
"default",
":",
"break",
";",
"}",
"if",
"(",
"$",
"operationMetadata",
"->",
"isJsonNative",
"(",
")",
"==",
"false",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"appendToQueryString",
"(",
"$",
"url",
",",
"\"Format=JSON\"",
")",
";",
"}",
"$",
"url",
"=",
"vsprintf",
"(",
"$",
"url",
",",
"$",
"queryParams",
")",
";",
"return",
"$",
"url",
";",
"}"
] |
This method generated the URL
@param type $operationConfig
@param type $operationMetadata
@param type $inputMap
@return type
|
[
"This",
"method",
"generated",
"the",
"URL"
] |
4785426d649771aedd15bd498708e7995c78df8c
|
https://github.com/Mastercard/sdk-core-php/blob/4785426d649771aedd15bd498708e7995c78df8c/MasterCard/Core/ApiController.php#L115-L184
|
221,095
|
Mastercard/sdk-core-php
|
MasterCard/Core/ApiController.php
|
ApiController.getRequest
|
public function getRequest($operationConfig, $operationMetadata, &$inputMap) {
$action = $operationConfig->getAction();
$resourcePath = $operationConfig->getResourcePath();
$headerList = $operationConfig->getHeaderParams();
$queryList = $operationConfig->getQueryParams();
//arizzini: store seperately the header paramters
$headerMap = Util::subMap($inputMap, $headerList);
$url = $this->getUrl($operationConfig, $operationMetadata, $inputMap);
// echo "-------------------------------------\n";
// echo "-------------------------------------\n";
// echo "url: $url \n";
// echo "-------------------------------------\n";
// echo "-------------------------------------\n";
$contentType = "application/json; charset=utf-8";
if (!empty($operationMetadata->getContentTypeOverride())) {
$contentType = $operationMetadata->getContentTypeOverride()."; charset=utf-8";
}
$request = null;
$requestBody = null;
if (!empty($inputMap)) {
$requestBody = json_encode($inputMap);
} else {
$requestBody = "{}";
}
switch ($action) {
case "create":
$request = new Request("POST", $url, [], $requestBody);
$request = $request->withHeader("Content-Type", $contentType);
break;
case "delete":
$request = new Request("DELETE", $url);
break;
case "update":
$request = new Request("PUT", $url, [], $requestBody);
$request = $request->withHeader("Content-Type", $contentType);
break;
case "read":
case "list":
case "query":
$request = new Request("GET", $url);
break;
}
$request = $request->withHeader("Accept", $contentType);
$request = $request->withHeader("User-Agent", Constants::getCoreVersion() ."/". $operationMetadata->getApiVersion());
foreach ($headerMap as $key => $value) {
$request = $request->withHeader($key, $value);
}
$request = ApiConfig::getAuthentication()->signRequest($url, $request);
return $request;
}
|
php
|
public function getRequest($operationConfig, $operationMetadata, &$inputMap) {
$action = $operationConfig->getAction();
$resourcePath = $operationConfig->getResourcePath();
$headerList = $operationConfig->getHeaderParams();
$queryList = $operationConfig->getQueryParams();
//arizzini: store seperately the header paramters
$headerMap = Util::subMap($inputMap, $headerList);
$url = $this->getUrl($operationConfig, $operationMetadata, $inputMap);
// echo "-------------------------------------\n";
// echo "-------------------------------------\n";
// echo "url: $url \n";
// echo "-------------------------------------\n";
// echo "-------------------------------------\n";
$contentType = "application/json; charset=utf-8";
if (!empty($operationMetadata->getContentTypeOverride())) {
$contentType = $operationMetadata->getContentTypeOverride()."; charset=utf-8";
}
$request = null;
$requestBody = null;
if (!empty($inputMap)) {
$requestBody = json_encode($inputMap);
} else {
$requestBody = "{}";
}
switch ($action) {
case "create":
$request = new Request("POST", $url, [], $requestBody);
$request = $request->withHeader("Content-Type", $contentType);
break;
case "delete":
$request = new Request("DELETE", $url);
break;
case "update":
$request = new Request("PUT", $url, [], $requestBody);
$request = $request->withHeader("Content-Type", $contentType);
break;
case "read":
case "list":
case "query":
$request = new Request("GET", $url);
break;
}
$request = $request->withHeader("Accept", $contentType);
$request = $request->withHeader("User-Agent", Constants::getCoreVersion() ."/". $operationMetadata->getApiVersion());
foreach ($headerMap as $key => $value) {
$request = $request->withHeader($key, $value);
}
$request = ApiConfig::getAuthentication()->signRequest($url, $request);
return $request;
}
|
[
"public",
"function",
"getRequest",
"(",
"$",
"operationConfig",
",",
"$",
"operationMetadata",
",",
"&",
"$",
"inputMap",
")",
"{",
"$",
"action",
"=",
"$",
"operationConfig",
"->",
"getAction",
"(",
")",
";",
"$",
"resourcePath",
"=",
"$",
"operationConfig",
"->",
"getResourcePath",
"(",
")",
";",
"$",
"headerList",
"=",
"$",
"operationConfig",
"->",
"getHeaderParams",
"(",
")",
";",
"$",
"queryList",
"=",
"$",
"operationConfig",
"->",
"getQueryParams",
"(",
")",
";",
"//arizzini: store seperately the header paramters",
"$",
"headerMap",
"=",
"Util",
"::",
"subMap",
"(",
"$",
"inputMap",
",",
"$",
"headerList",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"getUrl",
"(",
"$",
"operationConfig",
",",
"$",
"operationMetadata",
",",
"$",
"inputMap",
")",
";",
"// echo \"-------------------------------------\\n\";",
"// echo \"-------------------------------------\\n\";",
"// echo \"url: $url \\n\";",
"// echo \"-------------------------------------\\n\";",
"// echo \"-------------------------------------\\n\";",
"$",
"contentType",
"=",
"\"application/json; charset=utf-8\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"operationMetadata",
"->",
"getContentTypeOverride",
"(",
")",
")",
")",
"{",
"$",
"contentType",
"=",
"$",
"operationMetadata",
"->",
"getContentTypeOverride",
"(",
")",
".",
"\"; charset=utf-8\"",
";",
"}",
"$",
"request",
"=",
"null",
";",
"$",
"requestBody",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"inputMap",
")",
")",
"{",
"$",
"requestBody",
"=",
"json_encode",
"(",
"$",
"inputMap",
")",
";",
"}",
"else",
"{",
"$",
"requestBody",
"=",
"\"{}\"",
";",
"}",
"switch",
"(",
"$",
"action",
")",
"{",
"case",
"\"create\"",
":",
"$",
"request",
"=",
"new",
"Request",
"(",
"\"POST\"",
",",
"$",
"url",
",",
"[",
"]",
",",
"$",
"requestBody",
")",
";",
"$",
"request",
"=",
"$",
"request",
"->",
"withHeader",
"(",
"\"Content-Type\"",
",",
"$",
"contentType",
")",
";",
"break",
";",
"case",
"\"delete\"",
":",
"$",
"request",
"=",
"new",
"Request",
"(",
"\"DELETE\"",
",",
"$",
"url",
")",
";",
"break",
";",
"case",
"\"update\"",
":",
"$",
"request",
"=",
"new",
"Request",
"(",
"\"PUT\"",
",",
"$",
"url",
",",
"[",
"]",
",",
"$",
"requestBody",
")",
";",
"$",
"request",
"=",
"$",
"request",
"->",
"withHeader",
"(",
"\"Content-Type\"",
",",
"$",
"contentType",
")",
";",
"break",
";",
"case",
"\"read\"",
":",
"case",
"\"list\"",
":",
"case",
"\"query\"",
":",
"$",
"request",
"=",
"new",
"Request",
"(",
"\"GET\"",
",",
"$",
"url",
")",
";",
"break",
";",
"}",
"$",
"request",
"=",
"$",
"request",
"->",
"withHeader",
"(",
"\"Accept\"",
",",
"$",
"contentType",
")",
";",
"$",
"request",
"=",
"$",
"request",
"->",
"withHeader",
"(",
"\"User-Agent\"",
",",
"Constants",
"::",
"getCoreVersion",
"(",
")",
".",
"\"/\"",
".",
"$",
"operationMetadata",
"->",
"getApiVersion",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"headerMap",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"request",
"=",
"$",
"request",
"->",
"withHeader",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"$",
"request",
"=",
"ApiConfig",
"::",
"getAuthentication",
"(",
")",
"->",
"signRequest",
"(",
"$",
"url",
",",
"$",
"request",
")",
";",
"return",
"$",
"request",
";",
"}"
] |
This is the function that returns a Request object
@param type $operationConfig
@param type $operationMetadata
@param type $inputMap
@return type
|
[
"This",
"is",
"the",
"function",
"that",
"returns",
"a",
"Request",
"object"
] |
4785426d649771aedd15bd498708e7995c78df8c
|
https://github.com/Mastercard/sdk-core-php/blob/4785426d649771aedd15bd498708e7995c78df8c/MasterCard/Core/ApiController.php#L206-L266
|
221,096
|
Mastercard/sdk-core-php
|
MasterCard/Core/ApiController.php
|
ApiController.execute
|
public function execute($operationConfig, $operationMetadata, $inputMap) {
$request = $this->getRequest($operationConfig, $operationMetadata, $inputMap);
try {
$response = $this->client->send($request, array_merge(ApiConfig::getProxy(), ApiConfig::getTimeout()));
$statusCode = $response->getStatusCode();
$responseContent = $response->getBody()->getContents();
if ($statusCode < self::HTTP_AMBIGUOUS) {
if (ApiConfig::isDebug()) {
$this->logger->debug("---------------------");
$this->logger->debug(">>request(".$request->getMethod().") ". $request->getUri()->__toString() );
$this->logger->debug(">>headers: ", $request->getHeaders());
$this->logger->debug(">>body: ". $request->getBody());
$this->logger->debug("<<statusCode: ". $statusCode);
$this->logger->debug("<<headers: ", $response->getHeaders());
$this->logger->debug("<<body: ". $responseContent);
$this->logger->debug("---------------------");
}
if (strlen($responseContent) > 0) {
return json_decode($responseContent, true);
} else {
return array();
}
} else {
$this->handleException($response, $request);
}
} catch (RequestException $ex) {
if ($ex->hasResponse()) {
$this->handleException($ex->getResponse(), $request);
} else {
throw new ApiException($ex->getMessage());
}
}
}
|
php
|
public function execute($operationConfig, $operationMetadata, $inputMap) {
$request = $this->getRequest($operationConfig, $operationMetadata, $inputMap);
try {
$response = $this->client->send($request, array_merge(ApiConfig::getProxy(), ApiConfig::getTimeout()));
$statusCode = $response->getStatusCode();
$responseContent = $response->getBody()->getContents();
if ($statusCode < self::HTTP_AMBIGUOUS) {
if (ApiConfig::isDebug()) {
$this->logger->debug("---------------------");
$this->logger->debug(">>request(".$request->getMethod().") ". $request->getUri()->__toString() );
$this->logger->debug(">>headers: ", $request->getHeaders());
$this->logger->debug(">>body: ". $request->getBody());
$this->logger->debug("<<statusCode: ". $statusCode);
$this->logger->debug("<<headers: ", $response->getHeaders());
$this->logger->debug("<<body: ". $responseContent);
$this->logger->debug("---------------------");
}
if (strlen($responseContent) > 0) {
return json_decode($responseContent, true);
} else {
return array();
}
} else {
$this->handleException($response, $request);
}
} catch (RequestException $ex) {
if ($ex->hasResponse()) {
$this->handleException($ex->getResponse(), $request);
} else {
throw new ApiException($ex->getMessage());
}
}
}
|
[
"public",
"function",
"execute",
"(",
"$",
"operationConfig",
",",
"$",
"operationMetadata",
",",
"$",
"inputMap",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
"$",
"operationConfig",
",",
"$",
"operationMetadata",
",",
"$",
"inputMap",
")",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"send",
"(",
"$",
"request",
",",
"array_merge",
"(",
"ApiConfig",
"::",
"getProxy",
"(",
")",
",",
"ApiConfig",
"::",
"getTimeout",
"(",
")",
")",
")",
";",
"$",
"statusCode",
"=",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"$",
"responseContent",
"=",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
";",
"if",
"(",
"$",
"statusCode",
"<",
"self",
"::",
"HTTP_AMBIGUOUS",
")",
"{",
"if",
"(",
"ApiConfig",
"::",
"isDebug",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"---------------------\"",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\">>request(\"",
".",
"$",
"request",
"->",
"getMethod",
"(",
")",
".",
"\") \"",
".",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"__toString",
"(",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\">>headers: \"",
",",
"$",
"request",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\">>body: \"",
".",
"$",
"request",
"->",
"getBody",
"(",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"<<statusCode: \"",
".",
"$",
"statusCode",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"<<headers: \"",
",",
"$",
"response",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"<<body: \"",
".",
"$",
"responseContent",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"---------------------\"",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"responseContent",
")",
">",
"0",
")",
"{",
"return",
"json_decode",
"(",
"$",
"responseContent",
",",
"true",
")",
";",
"}",
"else",
"{",
"return",
"array",
"(",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"handleException",
"(",
"$",
"response",
",",
"$",
"request",
")",
";",
"}",
"}",
"catch",
"(",
"RequestException",
"$",
"ex",
")",
"{",
"if",
"(",
"$",
"ex",
"->",
"hasResponse",
"(",
")",
")",
"{",
"$",
"this",
"->",
"handleException",
"(",
"$",
"ex",
"->",
"getResponse",
"(",
")",
",",
"$",
"request",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"ApiException",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}"
] |
This function executes the request
@param type $operationConfig
@param type $operationMetadata
@param type $inputMap
@return type
@throws SystemException
|
[
"This",
"function",
"executes",
"the",
"request"
] |
4785426d649771aedd15bd498708e7995c78df8c
|
https://github.com/Mastercard/sdk-core-php/blob/4785426d649771aedd15bd498708e7995c78df8c/MasterCard/Core/ApiController.php#L276-L313
|
221,097
|
christiaan/InlineStyle
|
InlineStyle/InlineStyle.php
|
InlineStyle.loadDomDocument
|
public function loadDomDocument(\DOMDocument $domDocument)
{
$this->_dom = $domDocument;
foreach ($this->_getNodesForCssSelector('[style]') as $node) {
$node->setAttribute(
'inlinestyle-original-style',
$node->getAttribute('style')
);
}
}
|
php
|
public function loadDomDocument(\DOMDocument $domDocument)
{
$this->_dom = $domDocument;
foreach ($this->_getNodesForCssSelector('[style]') as $node) {
$node->setAttribute(
'inlinestyle-original-style',
$node->getAttribute('style')
);
}
}
|
[
"public",
"function",
"loadDomDocument",
"(",
"\\",
"DOMDocument",
"$",
"domDocument",
")",
"{",
"$",
"this",
"->",
"_dom",
"=",
"$",
"domDocument",
";",
"foreach",
"(",
"$",
"this",
"->",
"_getNodesForCssSelector",
"(",
"'[style]'",
")",
"as",
"$",
"node",
")",
"{",
"$",
"node",
"->",
"setAttribute",
"(",
"'inlinestyle-original-style'",
",",
"$",
"node",
"->",
"getAttribute",
"(",
"'style'",
")",
")",
";",
"}",
"}"
] |
Load the HTML as a DOMDocument directly
@param \DOMDocument $domDocument
|
[
"Load",
"the",
"HTML",
"as",
"a",
"DOMDocument",
"directly"
] |
9c408760465f4e3ef2b5fb08cb6995e3233afa98
|
https://github.com/christiaan/InlineStyle/blob/9c408760465f4e3ef2b5fb08cb6995e3233afa98/InlineStyle/InlineStyle.php#L92-L101
|
221,098
|
christiaan/InlineStyle
|
InlineStyle/InlineStyle.php
|
InlineStyle.applyStylesheet
|
public function applyStylesheet($stylesheet)
{
$stylesheet = (array) $stylesheet;
foreach($stylesheet as $ss) {
$parsed = $this->parseStylesheet($ss);
$parsed = $this->sortSelectorsOnSpecificity($parsed);
foreach($parsed as $arr) {
list($selector, $style) = $arr;
$this->applyRule($selector, $style);
}
}
return $this;
}
|
php
|
public function applyStylesheet($stylesheet)
{
$stylesheet = (array) $stylesheet;
foreach($stylesheet as $ss) {
$parsed = $this->parseStylesheet($ss);
$parsed = $this->sortSelectorsOnSpecificity($parsed);
foreach($parsed as $arr) {
list($selector, $style) = $arr;
$this->applyRule($selector, $style);
}
}
return $this;
}
|
[
"public",
"function",
"applyStylesheet",
"(",
"$",
"stylesheet",
")",
"{",
"$",
"stylesheet",
"=",
"(",
"array",
")",
"$",
"stylesheet",
";",
"foreach",
"(",
"$",
"stylesheet",
"as",
"$",
"ss",
")",
"{",
"$",
"parsed",
"=",
"$",
"this",
"->",
"parseStylesheet",
"(",
"$",
"ss",
")",
";",
"$",
"parsed",
"=",
"$",
"this",
"->",
"sortSelectorsOnSpecificity",
"(",
"$",
"parsed",
")",
";",
"foreach",
"(",
"$",
"parsed",
"as",
"$",
"arr",
")",
"{",
"list",
"(",
"$",
"selector",
",",
"$",
"style",
")",
"=",
"$",
"arr",
";",
"$",
"this",
"->",
"applyRule",
"(",
"$",
"selector",
",",
"$",
"style",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Applies one or more stylesheets to the current document
@param string|string[] $stylesheet
@return InlineStyle self
|
[
"Applies",
"one",
"or",
"more",
"stylesheets",
"to",
"the",
"current",
"document"
] |
9c408760465f4e3ef2b5fb08cb6995e3233afa98
|
https://github.com/christiaan/InlineStyle/blob/9c408760465f4e3ef2b5fb08cb6995e3233afa98/InlineStyle/InlineStyle.php#L109-L122
|
221,099
|
christiaan/InlineStyle
|
InlineStyle/InlineStyle.php
|
InlineStyle.applyRule
|
public function applyRule($selector, $style)
{
if($selector) {
$nodes = $this->_getNodesForCssSelector($selector);
$style = $this->_styleToArray($style);
foreach($nodes as $node) {
$current = $node->hasAttribute("style") ?
$this->_styleToArray($node->getAttribute("style")) :
array();
$current = $this->_mergeStyles($current, $style);
$node->setAttribute("style", $this->_arrayToStyle($current));
}
}
return $this;
}
|
php
|
public function applyRule($selector, $style)
{
if($selector) {
$nodes = $this->_getNodesForCssSelector($selector);
$style = $this->_styleToArray($style);
foreach($nodes as $node) {
$current = $node->hasAttribute("style") ?
$this->_styleToArray($node->getAttribute("style")) :
array();
$current = $this->_mergeStyles($current, $style);
$node->setAttribute("style", $this->_arrayToStyle($current));
}
}
return $this;
}
|
[
"public",
"function",
"applyRule",
"(",
"$",
"selector",
",",
"$",
"style",
")",
"{",
"if",
"(",
"$",
"selector",
")",
"{",
"$",
"nodes",
"=",
"$",
"this",
"->",
"_getNodesForCssSelector",
"(",
"$",
"selector",
")",
";",
"$",
"style",
"=",
"$",
"this",
"->",
"_styleToArray",
"(",
"$",
"style",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"current",
"=",
"$",
"node",
"->",
"hasAttribute",
"(",
"\"style\"",
")",
"?",
"$",
"this",
"->",
"_styleToArray",
"(",
"$",
"node",
"->",
"getAttribute",
"(",
"\"style\"",
")",
")",
":",
"array",
"(",
")",
";",
"$",
"current",
"=",
"$",
"this",
"->",
"_mergeStyles",
"(",
"$",
"current",
",",
"$",
"style",
")",
";",
"$",
"node",
"->",
"setAttribute",
"(",
"\"style\"",
",",
"$",
"this",
"->",
"_arrayToStyle",
"(",
"$",
"current",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Applies a style rule on the document
@param string $selector
@param string $style
@return InlineStyle self
|
[
"Applies",
"a",
"style",
"rule",
"on",
"the",
"document"
] |
9c408760465f4e3ef2b5fb08cb6995e3233afa98
|
https://github.com/christiaan/InlineStyle/blob/9c408760465f4e3ef2b5fb08cb6995e3233afa98/InlineStyle/InlineStyle.php#L153-L171
|
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.