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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
22,500
|
42mate/towel
|
src/Towel/Controller/User.php
|
User.logoutAction
|
public function logoutAction()
{
if ($this->isAuthenticated()) {
$this->session()->set('user', null);
}
$this->setMessage('success', 'Bye Bye !');
return $this->redirect('/');
}
|
php
|
public function logoutAction()
{
if ($this->isAuthenticated()) {
$this->session()->set('user', null);
}
$this->setMessage('success', 'Bye Bye !');
return $this->redirect('/');
}
|
[
"public",
"function",
"logoutAction",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAuthenticated",
"(",
")",
")",
"{",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"set",
"(",
"'user'",
",",
"null",
")",
";",
"}",
"$",
"this",
"->",
"setMessage",
"(",
"'success'",
",",
"'Bye Bye !'",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"'/'",
")",
";",
"}"
] |
Handles the logout actions.
@return \Symfony\Component\HttpFoundation\RedirectResponse
|
[
"Handles",
"the",
"logout",
"actions",
"."
] |
5316c3075fc844e8a5cbae113712b26556227dff
|
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Controller/User.php#L67-L75
|
22,501
|
42mate/towel
|
src/Towel/Controller/User.php
|
User.registerAction
|
public function registerAction($request)
{
$modelUser = new ModelUser();
$data = $request->get('data');
$error = false;
if ($this->isAuthenticated()) {
$this->setMessage('error', 'You are logged in');
$error = true;
}
if (!filter_var($data['model']['email'], FILTER_VALIDATE_EMAIL)) {
$this->setMessage('error', 'That is not an Email');
$error = true;
}
if ($modelUser->findByName($data['model']['username'])) {
$this->setMessage('error', 'Your account exists');
$error = true;
}
if ($modelUser->findByEmail($data['model']['email'])) {
$this->setMessage('error', 'Your Email is already registered');
$error = true;
}
if (empty($data['model']['password'])) {
$this->setMessage('error', 'You need to select a password');
$error = true;
}
if (empty($data['model']['email'])) {
$this->setMessage('error', 'You need to select an email');
$error = true;
}
if (empty($data['model']['username'])) {
$this->setMessage('error', 'You need to select an User Name');
$error = true;
}
if (!$error) {
$modelUser->resetObject();
$modelUser->username = $data['model']['username'];
$modelUser->password = md5($data['model']['password']);
$modelUser->email = $data['model']['email'];
$modelUser->address = $data['model']['address'];
$modelUser->phone = $data['model']['phone'];
$modelUser->save();
return $this->twig()->render('user\registerAction.twig');
} else {
return $this->twig()->render('user\register.twig', array(
'data' => $data
));
}
}
|
php
|
public function registerAction($request)
{
$modelUser = new ModelUser();
$data = $request->get('data');
$error = false;
if ($this->isAuthenticated()) {
$this->setMessage('error', 'You are logged in');
$error = true;
}
if (!filter_var($data['model']['email'], FILTER_VALIDATE_EMAIL)) {
$this->setMessage('error', 'That is not an Email');
$error = true;
}
if ($modelUser->findByName($data['model']['username'])) {
$this->setMessage('error', 'Your account exists');
$error = true;
}
if ($modelUser->findByEmail($data['model']['email'])) {
$this->setMessage('error', 'Your Email is already registered');
$error = true;
}
if (empty($data['model']['password'])) {
$this->setMessage('error', 'You need to select a password');
$error = true;
}
if (empty($data['model']['email'])) {
$this->setMessage('error', 'You need to select an email');
$error = true;
}
if (empty($data['model']['username'])) {
$this->setMessage('error', 'You need to select an User Name');
$error = true;
}
if (!$error) {
$modelUser->resetObject();
$modelUser->username = $data['model']['username'];
$modelUser->password = md5($data['model']['password']);
$modelUser->email = $data['model']['email'];
$modelUser->address = $data['model']['address'];
$modelUser->phone = $data['model']['phone'];
$modelUser->save();
return $this->twig()->render('user\registerAction.twig');
} else {
return $this->twig()->render('user\register.twig', array(
'data' => $data
));
}
}
|
[
"public",
"function",
"registerAction",
"(",
"$",
"request",
")",
"{",
"$",
"modelUser",
"=",
"new",
"ModelUser",
"(",
")",
";",
"$",
"data",
"=",
"$",
"request",
"->",
"get",
"(",
"'data'",
")",
";",
"$",
"error",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"isAuthenticated",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setMessage",
"(",
"'error'",
",",
"'You are logged in'",
")",
";",
"$",
"error",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"data",
"[",
"'model'",
"]",
"[",
"'email'",
"]",
",",
"FILTER_VALIDATE_EMAIL",
")",
")",
"{",
"$",
"this",
"->",
"setMessage",
"(",
"'error'",
",",
"'That is not an Email'",
")",
";",
"$",
"error",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"modelUser",
"->",
"findByName",
"(",
"$",
"data",
"[",
"'model'",
"]",
"[",
"'username'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setMessage",
"(",
"'error'",
",",
"'Your account exists'",
")",
";",
"$",
"error",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"modelUser",
"->",
"findByEmail",
"(",
"$",
"data",
"[",
"'model'",
"]",
"[",
"'email'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setMessage",
"(",
"'error'",
",",
"'Your Email is already registered'",
")",
";",
"$",
"error",
"=",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'model'",
"]",
"[",
"'password'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setMessage",
"(",
"'error'",
",",
"'You need to select a password'",
")",
";",
"$",
"error",
"=",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'model'",
"]",
"[",
"'email'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setMessage",
"(",
"'error'",
",",
"'You need to select an email'",
")",
";",
"$",
"error",
"=",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'model'",
"]",
"[",
"'username'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setMessage",
"(",
"'error'",
",",
"'You need to select an User Name'",
")",
";",
"$",
"error",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"error",
")",
"{",
"$",
"modelUser",
"->",
"resetObject",
"(",
")",
";",
"$",
"modelUser",
"->",
"username",
"=",
"$",
"data",
"[",
"'model'",
"]",
"[",
"'username'",
"]",
";",
"$",
"modelUser",
"->",
"password",
"=",
"md5",
"(",
"$",
"data",
"[",
"'model'",
"]",
"[",
"'password'",
"]",
")",
";",
"$",
"modelUser",
"->",
"email",
"=",
"$",
"data",
"[",
"'model'",
"]",
"[",
"'email'",
"]",
";",
"$",
"modelUser",
"->",
"address",
"=",
"$",
"data",
"[",
"'model'",
"]",
"[",
"'address'",
"]",
";",
"$",
"modelUser",
"->",
"phone",
"=",
"$",
"data",
"[",
"'model'",
"]",
"[",
"'phone'",
"]",
";",
"$",
"modelUser",
"->",
"save",
"(",
")",
";",
"return",
"$",
"this",
"->",
"twig",
"(",
")",
"->",
"render",
"(",
"'user\\registerAction.twig'",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"twig",
"(",
")",
"->",
"render",
"(",
"'user\\register.twig'",
",",
"array",
"(",
"'data'",
"=>",
"$",
"data",
")",
")",
";",
"}",
"}"
] |
Shows register form.
@param $request
@return string|\Symfony\Component\HttpFoundation\RedirectResponse
|
[
"Shows",
"register",
"form",
"."
] |
5316c3075fc844e8a5cbae113712b26556227dff
|
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Controller/User.php#L94-L150
|
22,502
|
42mate/towel
|
src/Towel/Controller/User.php
|
User.recoverAction
|
public function recoverAction($request)
{
$data = $request->get('data');
$modelUser = new ModelUser;
if ($this->isAuthenticated()) {
$this->setMessage('error', 'Your are already authenticated.');
return $this->redirect('/');
}
if (!filter_var($data['model']['email'], FILTER_VALIDATE_EMAIL)) {
$this->setMessage('error', 'Thats is not an email');
return $this->redirect('/user/recover');
}
if (!$modelUser->findByEmail($data['model']['email'])) {
$this->setMessage('error', 'Your are not registered');
return $this->redirect('/user/register');
}
//Send the email
$password = $modelUser->regeneratePassword();
$to = $modelUser->email;
$subject = 'Password from Reader';
$message = 'Your new password is ' . $password;
$this->sendMail($to, $subject, $message);
return $this->twig()->render('user\recoverAction.twig');
}
|
php
|
public function recoverAction($request)
{
$data = $request->get('data');
$modelUser = new ModelUser;
if ($this->isAuthenticated()) {
$this->setMessage('error', 'Your are already authenticated.');
return $this->redirect('/');
}
if (!filter_var($data['model']['email'], FILTER_VALIDATE_EMAIL)) {
$this->setMessage('error', 'Thats is not an email');
return $this->redirect('/user/recover');
}
if (!$modelUser->findByEmail($data['model']['email'])) {
$this->setMessage('error', 'Your are not registered');
return $this->redirect('/user/register');
}
//Send the email
$password = $modelUser->regeneratePassword();
$to = $modelUser->email;
$subject = 'Password from Reader';
$message = 'Your new password is ' . $password;
$this->sendMail($to, $subject, $message);
return $this->twig()->render('user\recoverAction.twig');
}
|
[
"public",
"function",
"recoverAction",
"(",
"$",
"request",
")",
"{",
"$",
"data",
"=",
"$",
"request",
"->",
"get",
"(",
"'data'",
")",
";",
"$",
"modelUser",
"=",
"new",
"ModelUser",
";",
"if",
"(",
"$",
"this",
"->",
"isAuthenticated",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setMessage",
"(",
"'error'",
",",
"'Your are already authenticated.'",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"'/'",
")",
";",
"}",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"data",
"[",
"'model'",
"]",
"[",
"'email'",
"]",
",",
"FILTER_VALIDATE_EMAIL",
")",
")",
"{",
"$",
"this",
"->",
"setMessage",
"(",
"'error'",
",",
"'Thats is not an email'",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"'/user/recover'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"modelUser",
"->",
"findByEmail",
"(",
"$",
"data",
"[",
"'model'",
"]",
"[",
"'email'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setMessage",
"(",
"'error'",
",",
"'Your are not registered'",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"'/user/register'",
")",
";",
"}",
"//Send the email",
"$",
"password",
"=",
"$",
"modelUser",
"->",
"regeneratePassword",
"(",
")",
";",
"$",
"to",
"=",
"$",
"modelUser",
"->",
"email",
";",
"$",
"subject",
"=",
"'Password from Reader'",
";",
"$",
"message",
"=",
"'Your new password is '",
".",
"$",
"password",
";",
"$",
"this",
"->",
"sendMail",
"(",
"$",
"to",
",",
"$",
"subject",
",",
"$",
"message",
")",
";",
"return",
"$",
"this",
"->",
"twig",
"(",
")",
"->",
"render",
"(",
"'user\\recoverAction.twig'",
")",
";",
"}"
] |
Handles the recover action.
@param $request
@return string|\Symfony\Component\HttpFoundation\RedirectResponse
|
[
"Handles",
"the",
"recover",
"action",
"."
] |
5316c3075fc844e8a5cbae113712b26556227dff
|
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Controller/User.php#L169-L197
|
22,503
|
buse974/JRpc
|
src/JRpc/Json/Server/Server.php
|
Server.initializeClass
|
public function initializeClass()
{
if (!isset($this->options['services']) || !is_array($this->options['services'])) {
return;
}
if ($this->getPersistence() && $this->getCache() !== null && ($definition = $this->getCache()->getItem('jrpc-definition')) !== null && ($serviceMap = $this->getCache()->getItem('jrpc-serviceMap')) !== null) {
$this->table = $definition;
$this->serviceMap = $serviceMap;
return;
}
foreach ($this->options['services'] as $c) {
$this->setClass($c, ((isset($c['namespace'])) ? $c['namespace'] : ''));
}
if ($this->getPersistence() && $this->getCache() !== null) {
$this->getCache()->setItem('jrpc-definition', $this->table);
$this->getCache()->setItem('jrpc-serviceMap', $this->serviceMap);
}
}
|
php
|
public function initializeClass()
{
if (!isset($this->options['services']) || !is_array($this->options['services'])) {
return;
}
if ($this->getPersistence() && $this->getCache() !== null && ($definition = $this->getCache()->getItem('jrpc-definition')) !== null && ($serviceMap = $this->getCache()->getItem('jrpc-serviceMap')) !== null) {
$this->table = $definition;
$this->serviceMap = $serviceMap;
return;
}
foreach ($this->options['services'] as $c) {
$this->setClass($c, ((isset($c['namespace'])) ? $c['namespace'] : ''));
}
if ($this->getPersistence() && $this->getCache() !== null) {
$this->getCache()->setItem('jrpc-definition', $this->table);
$this->getCache()->setItem('jrpc-serviceMap', $this->serviceMap);
}
}
|
[
"public",
"function",
"initializeClass",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'services'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"options",
"[",
"'services'",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getPersistence",
"(",
")",
"&&",
"$",
"this",
"->",
"getCache",
"(",
")",
"!==",
"null",
"&&",
"(",
"$",
"definition",
"=",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"getItem",
"(",
"'jrpc-definition'",
")",
")",
"!==",
"null",
"&&",
"(",
"$",
"serviceMap",
"=",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"getItem",
"(",
"'jrpc-serviceMap'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"table",
"=",
"$",
"definition",
";",
"$",
"this",
"->",
"serviceMap",
"=",
"$",
"serviceMap",
";",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"options",
"[",
"'services'",
"]",
"as",
"$",
"c",
")",
"{",
"$",
"this",
"->",
"setClass",
"(",
"$",
"c",
",",
"(",
"(",
"isset",
"(",
"$",
"c",
"[",
"'namespace'",
"]",
")",
")",
"?",
"$",
"c",
"[",
"'namespace'",
"]",
":",
"''",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getPersistence",
"(",
")",
"&&",
"$",
"this",
"->",
"getCache",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"setItem",
"(",
"'jrpc-definition'",
",",
"$",
"this",
"->",
"table",
")",
";",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"setItem",
"(",
"'jrpc-serviceMap'",
",",
"$",
"this",
"->",
"serviceMap",
")",
";",
"}",
"}"
] |
Initialize all class.
|
[
"Initialize",
"all",
"class",
"."
] |
c6100a5984d20a1ea00c43d41d3a022f2878b17f
|
https://github.com/buse974/JRpc/blob/c6100a5984d20a1ea00c43d41d3a022f2878b17f/src/JRpc/Json/Server/Server.php#L125-L146
|
22,504
|
buse974/JRpc
|
src/JRpc/Json/Server/Server.php
|
Server.getPersistence
|
public function getPersistence()
{
if (null === $this->persistence) {
$this->persistence = (isset($this->options['persistence']) && $this->options['persistence'] == true);
}
return $this->persistence;
}
|
php
|
public function getPersistence()
{
if (null === $this->persistence) {
$this->persistence = (isset($this->options['persistence']) && $this->options['persistence'] == true);
}
return $this->persistence;
}
|
[
"public",
"function",
"getPersistence",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"persistence",
")",
"{",
"$",
"this",
"->",
"persistence",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'persistence'",
"]",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"'persistence'",
"]",
"==",
"true",
")",
";",
"}",
"return",
"$",
"this",
"->",
"persistence",
";",
"}"
] |
Check persistance.
@return bool
|
[
"Check",
"persistance",
"."
] |
c6100a5984d20a1ea00c43d41d3a022f2878b17f
|
https://github.com/buse974/JRpc/blob/c6100a5984d20a1ea00c43d41d3a022f2878b17f/src/JRpc/Json/Server/Server.php#L296-L303
|
22,505
|
buse974/JRpc
|
src/JRpc/Json/Server/Server.php
|
Server.getCache
|
public function getCache()
{
if (null === $this->cache) {
if (isset($this->options['cache']) && is_string($this->options['cache'])) {
$this->cache = $this->container->get($this->options['cache']);
}
}
return $this->cache;
}
|
php
|
public function getCache()
{
if (null === $this->cache) {
if (isset($this->options['cache']) && is_string($this->options['cache'])) {
$this->cache = $this->container->get($this->options['cache']);
}
}
return $this->cache;
}
|
[
"public",
"function",
"getCache",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"cache",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'cache'",
"]",
")",
"&&",
"is_string",
"(",
"$",
"this",
"->",
"options",
"[",
"'cache'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"cache",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"this",
"->",
"options",
"[",
"'cache'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"cache",
";",
"}"
] |
Get Storage if define in config.
@return \Zend\Cache\Storage\StorageInterface|null
|
[
"Get",
"Storage",
"if",
"define",
"in",
"config",
"."
] |
c6100a5984d20a1ea00c43d41d3a022f2878b17f
|
https://github.com/buse974/JRpc/blob/c6100a5984d20a1ea00c43d41d3a022f2878b17f/src/JRpc/Json/Server/Server.php#L310-L319
|
22,506
|
buse974/JRpc
|
src/JRpc/Json/Server/Server.php
|
Server.setEventManager
|
public function setEventManager(\Zend\EventManager\EventManagerInterface $events)
{
$this->events = $events;
$this->events->setIdentifiers([__CLASS__,get_called_class()]);
return $this;
}
|
php
|
public function setEventManager(\Zend\EventManager\EventManagerInterface $events)
{
$this->events = $events;
$this->events->setIdentifiers([__CLASS__,get_called_class()]);
return $this;
}
|
[
"public",
"function",
"setEventManager",
"(",
"\\",
"Zend",
"\\",
"EventManager",
"\\",
"EventManagerInterface",
"$",
"events",
")",
"{",
"$",
"this",
"->",
"events",
"=",
"$",
"events",
";",
"$",
"this",
"->",
"events",
"->",
"setIdentifiers",
"(",
"[",
"__CLASS__",
",",
"get_called_class",
"(",
")",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Inject an EventManager instance.
@param \Zend\EventManager\EventManagerInterface $eventManager
|
[
"Inject",
"an",
"EventManager",
"instance",
"."
] |
c6100a5984d20a1ea00c43d41d3a022f2878b17f
|
https://github.com/buse974/JRpc/blob/c6100a5984d20a1ea00c43d41d3a022f2878b17f/src/JRpc/Json/Server/Server.php#L326-L332
|
22,507
|
rhosocial/yii2-user
|
User.php
|
User.getCacheTag
|
public function getCacheTag()
{
return $this->cacheTagPrefix .
($this->isAttributeChanged($this->idAttribute) ? $this->getOldAttribute($this->idAttribute) : $this->getID());
}
|
php
|
public function getCacheTag()
{
return $this->cacheTagPrefix .
($this->isAttributeChanged($this->idAttribute) ? $this->getOldAttribute($this->idAttribute) : $this->getID());
}
|
[
"public",
"function",
"getCacheTag",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"cacheTagPrefix",
".",
"(",
"$",
"this",
"->",
"isAttributeChanged",
"(",
"$",
"this",
"->",
"idAttribute",
")",
"?",
"$",
"this",
"->",
"getOldAttribute",
"(",
"$",
"this",
"->",
"idAttribute",
")",
":",
"$",
"this",
"->",
"getID",
"(",
")",
")",
";",
"}"
] |
Get cache tag.
The cache tag ends with the user ID, but after the user ID is modified, the old ID will prevail.
@return string
|
[
"Get",
"cache",
"tag",
".",
"The",
"cache",
"tag",
"ends",
"with",
"the",
"user",
"ID",
"but",
"after",
"the",
"user",
"ID",
"is",
"modified",
"the",
"old",
"ID",
"will",
"prevail",
"."
] |
96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc
|
https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/User.php#L199-L203
|
22,508
|
zicht/z
|
src/Zicht/Tool/Configuration/ConfigurationLoader.php
|
ConfigurationLoader.fromEnv
|
public static function fromEnv($configFilename, Version $version)
{
if (null === $configFilename) {
$configFilename = getenv('ZFILE') ? getenv('ZFILE') : 'z.yml';
}
return new self(
$configFilename,
new PathDefaultFileLocator('ZPATH', array(getcwd(), getenv('HOME') . '/.config/z')),
new FileLoader(
new PathDefaultFileLocator(
'ZPLUGINPATH',
array(ZPREFIX . '/vendor/zicht/z-plugins/', getcwd())
),
$version
)
);
}
|
php
|
public static function fromEnv($configFilename, Version $version)
{
if (null === $configFilename) {
$configFilename = getenv('ZFILE') ? getenv('ZFILE') : 'z.yml';
}
return new self(
$configFilename,
new PathDefaultFileLocator('ZPATH', array(getcwd(), getenv('HOME') . '/.config/z')),
new FileLoader(
new PathDefaultFileLocator(
'ZPLUGINPATH',
array(ZPREFIX . '/vendor/zicht/z-plugins/', getcwd())
),
$version
)
);
}
|
[
"public",
"static",
"function",
"fromEnv",
"(",
"$",
"configFilename",
",",
"Version",
"$",
"version",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"configFilename",
")",
"{",
"$",
"configFilename",
"=",
"getenv",
"(",
"'ZFILE'",
")",
"?",
"getenv",
"(",
"'ZFILE'",
")",
":",
"'z.yml'",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"configFilename",
",",
"new",
"PathDefaultFileLocator",
"(",
"'ZPATH'",
",",
"array",
"(",
"getcwd",
"(",
")",
",",
"getenv",
"(",
"'HOME'",
")",
".",
"'/.config/z'",
")",
")",
",",
"new",
"FileLoader",
"(",
"new",
"PathDefaultFileLocator",
"(",
"'ZPLUGINPATH'",
",",
"array",
"(",
"ZPREFIX",
".",
"'/vendor/zicht/z-plugins/'",
",",
"getcwd",
"(",
")",
")",
")",
",",
"$",
"version",
")",
")",
";",
"}"
] |
Create the configuration loader based the current shell environment variables.
@param string $configFilename
@param Version $version
@return ConfigurationLoader
@codeCoverageIgnore
|
[
"Create",
"the",
"configuration",
"loader",
"based",
"the",
"current",
"shell",
"environment",
"variables",
"."
] |
6a1731dad20b018555a96b726a61d4bf8ec8c886
|
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Configuration/ConfigurationLoader.php#L29-L46
|
22,509
|
zicht/z
|
src/Zicht/Tool/Configuration/ConfigurationLoader.php
|
ConfigurationLoader.processConfiguration
|
public function processConfiguration()
{
Debug::enterScope('config');
Debug::enterScope('load');
try {
$zfiles = (array)$this->configLocator->locate($this->configFilename, null, false);
} catch (\InvalidArgumentException $e) {
$zfiles = array();
}
foreach ($zfiles as $file) {
Debug::enterScope($file);
$this->sourceFiles[] = $file;
$this->loader->load($file);
Debug::exitScope($file);
}
foreach ($this->loader->getPlugins() as $name => $file) {
Debug::enterScope($file);
$this->sourceFiles[] = $file;
$this->loadPlugin($name, $file);
Debug::exitScope($file);
}
Debug::exitScope('load');
Debug::enterScope('process');
$processor = new Processor();
$ret = $processor->processConfiguration(
new Configuration($this->plugins),
$this->loader->getConfigs()
);
Debug::exitScope('process');
Debug::exitScope('config');
return $ret;
}
|
php
|
public function processConfiguration()
{
Debug::enterScope('config');
Debug::enterScope('load');
try {
$zfiles = (array)$this->configLocator->locate($this->configFilename, null, false);
} catch (\InvalidArgumentException $e) {
$zfiles = array();
}
foreach ($zfiles as $file) {
Debug::enterScope($file);
$this->sourceFiles[] = $file;
$this->loader->load($file);
Debug::exitScope($file);
}
foreach ($this->loader->getPlugins() as $name => $file) {
Debug::enterScope($file);
$this->sourceFiles[] = $file;
$this->loadPlugin($name, $file);
Debug::exitScope($file);
}
Debug::exitScope('load');
Debug::enterScope('process');
$processor = new Processor();
$ret = $processor->processConfiguration(
new Configuration($this->plugins),
$this->loader->getConfigs()
);
Debug::exitScope('process');
Debug::exitScope('config');
return $ret;
}
|
[
"public",
"function",
"processConfiguration",
"(",
")",
"{",
"Debug",
"::",
"enterScope",
"(",
"'config'",
")",
";",
"Debug",
"::",
"enterScope",
"(",
"'load'",
")",
";",
"try",
"{",
"$",
"zfiles",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"configLocator",
"->",
"locate",
"(",
"$",
"this",
"->",
"configFilename",
",",
"null",
",",
"false",
")",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"zfiles",
"=",
"array",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"zfiles",
"as",
"$",
"file",
")",
"{",
"Debug",
"::",
"enterScope",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"sourceFiles",
"[",
"]",
"=",
"$",
"file",
";",
"$",
"this",
"->",
"loader",
"->",
"load",
"(",
"$",
"file",
")",
";",
"Debug",
"::",
"exitScope",
"(",
"$",
"file",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"loader",
"->",
"getPlugins",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"file",
")",
"{",
"Debug",
"::",
"enterScope",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"sourceFiles",
"[",
"]",
"=",
"$",
"file",
";",
"$",
"this",
"->",
"loadPlugin",
"(",
"$",
"name",
",",
"$",
"file",
")",
";",
"Debug",
"::",
"exitScope",
"(",
"$",
"file",
")",
";",
"}",
"Debug",
"::",
"exitScope",
"(",
"'load'",
")",
";",
"Debug",
"::",
"enterScope",
"(",
"'process'",
")",
";",
"$",
"processor",
"=",
"new",
"Processor",
"(",
")",
";",
"$",
"ret",
"=",
"$",
"processor",
"->",
"processConfiguration",
"(",
"new",
"Configuration",
"(",
"$",
"this",
"->",
"plugins",
")",
",",
"$",
"this",
"->",
"loader",
"->",
"getConfigs",
"(",
")",
")",
";",
"Debug",
"::",
"exitScope",
"(",
"'process'",
")",
";",
"Debug",
"::",
"exitScope",
"(",
"'config'",
")",
";",
"return",
"$",
"ret",
";",
"}"
] |
Processes the configuration contents
@return array
@throws \UnexpectedValueException
|
[
"Processes",
"the",
"configuration",
"contents"
] |
6a1731dad20b018555a96b726a61d4bf8ec8c886
|
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Configuration/ConfigurationLoader.php#L89-L121
|
22,510
|
zicht/z
|
src/Zicht/Tool/Configuration/ConfigurationLoader.php
|
ConfigurationLoader.loadPlugin
|
protected function loadPlugin($name, $file)
{
require_once $file;
$className = sprintf('Zicht\Tool\Plugin\%s\Plugin', ucfirst(basename($name)));
$class = new \ReflectionClass($className);
if (!$class->implementsInterface('Zicht\Tool\PluginInterface')) {
throw new \UnexpectedValueException("The class $className is not a 'Zicht\\Tool\\PluginInterface'");
}
$this->plugins[$name] = $class->newInstance();
}
|
php
|
protected function loadPlugin($name, $file)
{
require_once $file;
$className = sprintf('Zicht\Tool\Plugin\%s\Plugin', ucfirst(basename($name)));
$class = new \ReflectionClass($className);
if (!$class->implementsInterface('Zicht\Tool\PluginInterface')) {
throw new \UnexpectedValueException("The class $className is not a 'Zicht\\Tool\\PluginInterface'");
}
$this->plugins[$name] = $class->newInstance();
}
|
[
"protected",
"function",
"loadPlugin",
"(",
"$",
"name",
",",
"$",
"file",
")",
"{",
"require_once",
"$",
"file",
";",
"$",
"className",
"=",
"sprintf",
"(",
"'Zicht\\Tool\\Plugin\\%s\\Plugin'",
",",
"ucfirst",
"(",
"basename",
"(",
"$",
"name",
")",
")",
")",
";",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"if",
"(",
"!",
"$",
"class",
"->",
"implementsInterface",
"(",
"'Zicht\\Tool\\PluginInterface'",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"The class $className is not a 'Zicht\\\\Tool\\\\PluginInterface'\"",
")",
";",
"}",
"$",
"this",
"->",
"plugins",
"[",
"$",
"name",
"]",
"=",
"$",
"class",
"->",
"newInstance",
"(",
")",
";",
"}"
] |
Load the specified plugin instance.
@param string $name
@param string $file
@return void
@throws \UnexpectedValueException
|
[
"Load",
"the",
"specified",
"plugin",
"instance",
"."
] |
6a1731dad20b018555a96b726a61d4bf8ec8c886
|
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Configuration/ConfigurationLoader.php#L133-L142
|
22,511
|
Erdiko/core
|
src/Layout.php
|
Layout.getTemplateFile
|
public function getTemplateFile($filename, $data)
{
$data['getRegion'] = function($name) {
return $this->getRegion($name);
}; // This is for mustache compatibility
// Push the data into regions and then pass a pointer to this class to the layout
// $this->setRegions($data);
return parent::getTemplateFile($filename, $data); // Pass in layout object to template
}
|
php
|
public function getTemplateFile($filename, $data)
{
$data['getRegion'] = function($name) {
return $this->getRegion($name);
}; // This is for mustache compatibility
// Push the data into regions and then pass a pointer to this class to the layout
// $this->setRegions($data);
return parent::getTemplateFile($filename, $data); // Pass in layout object to template
}
|
[
"public",
"function",
"getTemplateFile",
"(",
"$",
"filename",
",",
"$",
"data",
")",
"{",
"$",
"data",
"[",
"'getRegion'",
"]",
"=",
"function",
"(",
"$",
"name",
")",
"{",
"return",
"$",
"this",
"->",
"getRegion",
"(",
"$",
"name",
")",
";",
"}",
";",
"// This is for mustache compatibility",
"// Push the data into regions and then pass a pointer to this class to the layout",
"// $this->setRegions($data);",
"return",
"parent",
"::",
"getTemplateFile",
"(",
"$",
"filename",
",",
"$",
"data",
")",
";",
"// Pass in layout object to template",
"}"
] |
Get template file
@param string $filename
@param mixed $data Typically a string, Container object or other object
@return string
@todo array merge regions with data
|
[
"Get",
"template",
"file"
] |
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
|
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Layout.php#L73-L82
|
22,512
|
Erdiko/core
|
src/Layout.php
|
Layout.getRegion
|
public function getRegion($name)
{
if(array_key_exists($name, $this->_regions)) {
$html = (is_subclass_of($this->_regions[$name], 'erdiko\core\Container')) ?
$this->_regions[$name]->toHtml() : $this->_regions[$name];
} else {
throw new \Exception("Template region '{$name}' does not exits.");
}
return $html;
}
|
php
|
public function getRegion($name)
{
if(array_key_exists($name, $this->_regions)) {
$html = (is_subclass_of($this->_regions[$name], 'erdiko\core\Container')) ?
$this->_regions[$name]->toHtml() : $this->_regions[$name];
} else {
throw new \Exception("Template region '{$name}' does not exits.");
}
return $html;
}
|
[
"public",
"function",
"getRegion",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"_regions",
")",
")",
"{",
"$",
"html",
"=",
"(",
"is_subclass_of",
"(",
"$",
"this",
"->",
"_regions",
"[",
"$",
"name",
"]",
",",
"'erdiko\\core\\Container'",
")",
")",
"?",
"$",
"this",
"->",
"_regions",
"[",
"$",
"name",
"]",
"->",
"toHtml",
"(",
")",
":",
"$",
"this",
"->",
"_regions",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Template region '{$name}' does not exits.\"",
")",
";",
"}",
"return",
"$",
"html",
";",
"}"
] |
get rendered region
@param string $name
@return mixed $content, typically a string, Container object or other object
|
[
"get",
"rendered",
"region"
] |
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
|
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Layout.php#L169-L179
|
22,513
|
juskiewicz/Geolocation
|
src/Geolocation.php
|
Geolocation.getAddresses
|
public function getAddresses(CoordinatesInterface $coordinates) : AddressCollection
{
$url = $this->coordinatesQuery($coordinates);
$json = $this->fetchUrl($url);
// convert google data to address collection
$results = [];
foreach ($json->results as $result) {
$address = AddressBuild::create($result);
$address->setCoordinates($coordinates);
$results[] = $address;
}
return new AddressCollection($results);
}
|
php
|
public function getAddresses(CoordinatesInterface $coordinates) : AddressCollection
{
$url = $this->coordinatesQuery($coordinates);
$json = $this->fetchUrl($url);
// convert google data to address collection
$results = [];
foreach ($json->results as $result) {
$address = AddressBuild::create($result);
$address->setCoordinates($coordinates);
$results[] = $address;
}
return new AddressCollection($results);
}
|
[
"public",
"function",
"getAddresses",
"(",
"CoordinatesInterface",
"$",
"coordinates",
")",
":",
"AddressCollection",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"coordinatesQuery",
"(",
"$",
"coordinates",
")",
";",
"$",
"json",
"=",
"$",
"this",
"->",
"fetchUrl",
"(",
"$",
"url",
")",
";",
"// convert google data to address collection",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"json",
"->",
"results",
"as",
"$",
"result",
")",
"{",
"$",
"address",
"=",
"AddressBuild",
"::",
"create",
"(",
"$",
"result",
")",
";",
"$",
"address",
"->",
"setCoordinates",
"(",
"$",
"coordinates",
")",
";",
"$",
"results",
"[",
"]",
"=",
"$",
"address",
";",
"}",
"return",
"new",
"AddressCollection",
"(",
"$",
"results",
")",
";",
"}"
] |
Get possible addresses using CoordinatesInterface
@param CoordinatesInterface $coordinates
@return AddressCollection
|
[
"Get",
"possible",
"addresses",
"using",
"CoordinatesInterface"
] |
5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d
|
https://github.com/juskiewicz/Geolocation/blob/5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d/src/Geolocation.php#L69-L83
|
22,514
|
juskiewicz/Geolocation
|
src/Geolocation.php
|
Geolocation.getCoordinatesByObject
|
public function getCoordinatesByObject(AddressInterface $address) : CoordinatesInterface
{
$url = $this->addressQuery($address->getFormattedAddress());
$json = $this->fetchUrl($url);
// convert google data to coordinates
$coordinates = CoordinatesBuild::create($json->results[0]);
return $coordinates;
}
|
php
|
public function getCoordinatesByObject(AddressInterface $address) : CoordinatesInterface
{
$url = $this->addressQuery($address->getFormattedAddress());
$json = $this->fetchUrl($url);
// convert google data to coordinates
$coordinates = CoordinatesBuild::create($json->results[0]);
return $coordinates;
}
|
[
"public",
"function",
"getCoordinatesByObject",
"(",
"AddressInterface",
"$",
"address",
")",
":",
"CoordinatesInterface",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"addressQuery",
"(",
"$",
"address",
"->",
"getFormattedAddress",
"(",
")",
")",
";",
"$",
"json",
"=",
"$",
"this",
"->",
"fetchUrl",
"(",
"$",
"url",
")",
";",
"// convert google data to coordinates",
"$",
"coordinates",
"=",
"CoordinatesBuild",
"::",
"create",
"(",
"$",
"json",
"->",
"results",
"[",
"0",
"]",
")",
";",
"return",
"$",
"coordinates",
";",
"}"
] |
Get coordinates using AddressInterface
@param AddressInterface $address
@return CoordinatesInterface
|
[
"Get",
"coordinates",
"using",
"AddressInterface"
] |
5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d
|
https://github.com/juskiewicz/Geolocation/blob/5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d/src/Geolocation.php#L91-L100
|
22,515
|
juskiewicz/Geolocation
|
src/Geolocation.php
|
Geolocation.getCoordinatesByString
|
public function getCoordinatesByString(string $address) : CoordinatesInterface
{
$url = $this->addressQuery($address);
$json = $this->fetchUrl($url);
// convert google data to coordinates
$coordinates = CoordinatesBuild::create($json->results[0]);
return $coordinates;
}
|
php
|
public function getCoordinatesByString(string $address) : CoordinatesInterface
{
$url = $this->addressQuery($address);
$json = $this->fetchUrl($url);
// convert google data to coordinates
$coordinates = CoordinatesBuild::create($json->results[0]);
return $coordinates;
}
|
[
"public",
"function",
"getCoordinatesByString",
"(",
"string",
"$",
"address",
")",
":",
"CoordinatesInterface",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"addressQuery",
"(",
"$",
"address",
")",
";",
"$",
"json",
"=",
"$",
"this",
"->",
"fetchUrl",
"(",
"$",
"url",
")",
";",
"// convert google data to coordinates",
"$",
"coordinates",
"=",
"CoordinatesBuild",
"::",
"create",
"(",
"$",
"json",
"->",
"results",
"[",
"0",
"]",
")",
";",
"return",
"$",
"coordinates",
";",
"}"
] |
Get coordinates using string
@param string $address
@return CoordinatesInterface
|
[
"Get",
"coordinates",
"using",
"string"
] |
5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d
|
https://github.com/juskiewicz/Geolocation/blob/5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d/src/Geolocation.php#L108-L117
|
22,516
|
juskiewicz/Geolocation
|
src/Geolocation.php
|
Geolocation.coordinatesQuery
|
private function coordinatesQuery(CoordinatesInterface $coordinates) : string
{
$url = sprintf(self::API_COORDINATES_URL_SSL, $coordinates->getLatitude(), $coordinates->getLongitude());
$url = $this->buildQuery($url, $this->apiKey, $this->locale, $this->region);
return $url;
}
|
php
|
private function coordinatesQuery(CoordinatesInterface $coordinates) : string
{
$url = sprintf(self::API_COORDINATES_URL_SSL, $coordinates->getLatitude(), $coordinates->getLongitude());
$url = $this->buildQuery($url, $this->apiKey, $this->locale, $this->region);
return $url;
}
|
[
"private",
"function",
"coordinatesQuery",
"(",
"CoordinatesInterface",
"$",
"coordinates",
")",
":",
"string",
"{",
"$",
"url",
"=",
"sprintf",
"(",
"self",
"::",
"API_COORDINATES_URL_SSL",
",",
"$",
"coordinates",
"->",
"getLatitude",
"(",
")",
",",
"$",
"coordinates",
"->",
"getLongitude",
"(",
")",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"buildQuery",
"(",
"$",
"url",
",",
"$",
"this",
"->",
"apiKey",
",",
"$",
"this",
"->",
"locale",
",",
"$",
"this",
"->",
"region",
")",
";",
"return",
"$",
"url",
";",
"}"
] |
Build coordinates query
@param CoordinatesInterface $coordinates
@return string
|
[
"Build",
"coordinates",
"query"
] |
5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d
|
https://github.com/juskiewicz/Geolocation/blob/5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d/src/Geolocation.php#L125-L131
|
22,517
|
juskiewicz/Geolocation
|
src/Geolocation.php
|
Geolocation.addressQuery
|
private function addressQuery(string $formattedAddress) : string
{
$url = sprintf(self::API_ADDRESS_URL_SSL, rawurlencode($formattedAddress));
$url = $this->buildQuery($url, $this->apiKey, $this->locale, $this->region);
return $url;
}
|
php
|
private function addressQuery(string $formattedAddress) : string
{
$url = sprintf(self::API_ADDRESS_URL_SSL, rawurlencode($formattedAddress));
$url = $this->buildQuery($url, $this->apiKey, $this->locale, $this->region);
return $url;
}
|
[
"private",
"function",
"addressQuery",
"(",
"string",
"$",
"formattedAddress",
")",
":",
"string",
"{",
"$",
"url",
"=",
"sprintf",
"(",
"self",
"::",
"API_ADDRESS_URL_SSL",
",",
"rawurlencode",
"(",
"$",
"formattedAddress",
")",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"buildQuery",
"(",
"$",
"url",
",",
"$",
"this",
"->",
"apiKey",
",",
"$",
"this",
"->",
"locale",
",",
"$",
"this",
"->",
"region",
")",
";",
"return",
"$",
"url",
";",
"}"
] |
Build address query
@param string $formattedAddress
@return string
|
[
"Build",
"address",
"query"
] |
5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d
|
https://github.com/juskiewicz/Geolocation/blob/5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d/src/Geolocation.php#L139-L145
|
22,518
|
juskiewicz/Geolocation
|
src/Geolocation.php
|
Geolocation.buildQuery
|
private function buildQuery(string $url, string $apiKey, string $locale = null, string $region = null) : string
{
if (null !== $apiKey) {
$url = sprintf('%s&key=%s', $url, $apiKey);
}
if (null !== $locale) {
$url = sprintf('%s&language=%s', $url, $locale);
}
if (null !== $region) {
$url = sprintf('%s®ion=%s', $url, $region);
}
return $url;
}
|
php
|
private function buildQuery(string $url, string $apiKey, string $locale = null, string $region = null) : string
{
if (null !== $apiKey) {
$url = sprintf('%s&key=%s', $url, $apiKey);
}
if (null !== $locale) {
$url = sprintf('%s&language=%s', $url, $locale);
}
if (null !== $region) {
$url = sprintf('%s®ion=%s', $url, $region);
}
return $url;
}
|
[
"private",
"function",
"buildQuery",
"(",
"string",
"$",
"url",
",",
"string",
"$",
"apiKey",
",",
"string",
"$",
"locale",
"=",
"null",
",",
"string",
"$",
"region",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"null",
"!==",
"$",
"apiKey",
")",
"{",
"$",
"url",
"=",
"sprintf",
"(",
"'%s&key=%s'",
",",
"$",
"url",
",",
"$",
"apiKey",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"locale",
")",
"{",
"$",
"url",
"=",
"sprintf",
"(",
"'%s&language=%s'",
",",
"$",
"url",
",",
"$",
"locale",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"region",
")",
"{",
"$",
"url",
"=",
"sprintf",
"(",
"'%s®ion=%s'",
",",
"$",
"url",
",",
"$",
"region",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] |
build query with extra params
@param string $url
@param string $locale
@param string $region
@param string $apiKey
@return string
|
[
"build",
"query",
"with",
"extra",
"params"
] |
5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d
|
https://github.com/juskiewicz/Geolocation/blob/5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d/src/Geolocation.php#L157-L170
|
22,519
|
wenbinye/PhalconX
|
src/Validation/Validation.php
|
Validation.validate
|
public function validate($model, $validators = null)
{
if (isset($validators) && is_array($validators)) {
$validation = $this->validateArray($model, $validators);
} else {
$validation = $this->validateModel($model);
}
if ($validation) {
$errors = $validation->validate($model);
if (count($errors)) {
throw new ValidationException($errors);
}
}
}
|
php
|
public function validate($model, $validators = null)
{
if (isset($validators) && is_array($validators)) {
$validation = $this->validateArray($model, $validators);
} else {
$validation = $this->validateModel($model);
}
if ($validation) {
$errors = $validation->validate($model);
if (count($errors)) {
throw new ValidationException($errors);
}
}
}
|
[
"public",
"function",
"validate",
"(",
"$",
"model",
",",
"$",
"validators",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"validators",
")",
"&&",
"is_array",
"(",
"$",
"validators",
")",
")",
"{",
"$",
"validation",
"=",
"$",
"this",
"->",
"validateArray",
"(",
"$",
"model",
",",
"$",
"validators",
")",
";",
"}",
"else",
"{",
"$",
"validation",
"=",
"$",
"this",
"->",
"validateModel",
"(",
"$",
"model",
")",
";",
"}",
"if",
"(",
"$",
"validation",
")",
"{",
"$",
"errors",
"=",
"$",
"validation",
"->",
"validate",
"(",
"$",
"model",
")",
";",
"if",
"(",
"count",
"(",
"$",
"errors",
")",
")",
"{",
"throw",
"new",
"ValidationException",
"(",
"$",
"errors",
")",
";",
"}",
"}",
"}"
] |
Validate model object
@param object|array $model
@param array $validators
@throws ValidationException
|
[
"Validate",
"model",
"object"
] |
0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1
|
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Validation/Validation.php#L66-L79
|
22,520
|
wenbinye/PhalconX
|
src/Validation/Validation.php
|
Validation.createForm
|
public function createForm($model, $formClass = null)
{
if (is_string($model)) {
return $this->createFormInternal($model, new $model, $formClass);
} else {
return $this->createFormInternal(get_class($model), $model, $formClass);
}
}
|
php
|
public function createForm($model, $formClass = null)
{
if (is_string($model)) {
return $this->createFormInternal($model, new $model, $formClass);
} else {
return $this->createFormInternal(get_class($model), $model, $formClass);
}
}
|
[
"public",
"function",
"createForm",
"(",
"$",
"model",
",",
"$",
"formClass",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"model",
")",
")",
"{",
"return",
"$",
"this",
"->",
"createFormInternal",
"(",
"$",
"model",
",",
"new",
"$",
"model",
",",
"$",
"formClass",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"createFormInternal",
"(",
"get_class",
"(",
"$",
"model",
")",
",",
"$",
"model",
",",
"$",
"formClass",
")",
";",
"}",
"}"
] |
Create form object
@param string|object $model model class or object
@param string $formClass form class, default use Phalcon\Forms\Form
@return Phalcon\Forms\Form
|
[
"Create",
"form",
"object"
] |
0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1
|
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Validation/Validation.php#L88-L95
|
22,521
|
wenbinye/PhalconX
|
src/Validation/Validation.php
|
Validation.getLabels
|
private function getLabels($annotations)
{
$it = $this->getAnnotations()->filter($annotations)
->is(Label::class)
->onProperties();
$labels = [];
foreach ($it as $annotation) {
$labels[$annotation->getPropertyName()] = $annotation->value;
}
return $labels;
}
|
php
|
private function getLabels($annotations)
{
$it = $this->getAnnotations()->filter($annotations)
->is(Label::class)
->onProperties();
$labels = [];
foreach ($it as $annotation) {
$labels[$annotation->getPropertyName()] = $annotation->value;
}
return $labels;
}
|
[
"private",
"function",
"getLabels",
"(",
"$",
"annotations",
")",
"{",
"$",
"it",
"=",
"$",
"this",
"->",
"getAnnotations",
"(",
")",
"->",
"filter",
"(",
"$",
"annotations",
")",
"->",
"is",
"(",
"Label",
"::",
"class",
")",
"->",
"onProperties",
"(",
")",
";",
"$",
"labels",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"it",
"as",
"$",
"annotation",
")",
"{",
"$",
"labels",
"[",
"$",
"annotation",
"->",
"getPropertyName",
"(",
")",
"]",
"=",
"$",
"annotation",
"->",
"value",
";",
"}",
"return",
"$",
"labels",
";",
"}"
] |
Gets property labels
@return array
|
[
"Gets",
"property",
"labels"
] |
0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1
|
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Validation/Validation.php#L131-L141
|
22,522
|
wenbinye/PhalconX
|
src/Validation/Validation.php
|
Validation.getValidators
|
private function getValidators($annotations, $class)
{
$validators = [];
$it = $this->getAnnotations()->filter($annotations)
->is(ValidatorInterface::class)
->onProperties();
foreach ($it as $annotation) {
$property = $annotation->getPropertyName();
if (!isset($validators[$property])) {
$validators[$property] = [
'required' => false,
'validators' => [],
];
}
$validators[$property]['validators'][] = $annotation->getValidator($this);
if ($annotation instanceof Required) {
$validators[$property]['required'] = true;
}
}
return $validators;
}
|
php
|
private function getValidators($annotations, $class)
{
$validators = [];
$it = $this->getAnnotations()->filter($annotations)
->is(ValidatorInterface::class)
->onProperties();
foreach ($it as $annotation) {
$property = $annotation->getPropertyName();
if (!isset($validators[$property])) {
$validators[$property] = [
'required' => false,
'validators' => [],
];
}
$validators[$property]['validators'][] = $annotation->getValidator($this);
if ($annotation instanceof Required) {
$validators[$property]['required'] = true;
}
}
return $validators;
}
|
[
"private",
"function",
"getValidators",
"(",
"$",
"annotations",
",",
"$",
"class",
")",
"{",
"$",
"validators",
"=",
"[",
"]",
";",
"$",
"it",
"=",
"$",
"this",
"->",
"getAnnotations",
"(",
")",
"->",
"filter",
"(",
"$",
"annotations",
")",
"->",
"is",
"(",
"ValidatorInterface",
"::",
"class",
")",
"->",
"onProperties",
"(",
")",
";",
"foreach",
"(",
"$",
"it",
"as",
"$",
"annotation",
")",
"{",
"$",
"property",
"=",
"$",
"annotation",
"->",
"getPropertyName",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"validators",
"[",
"$",
"property",
"]",
")",
")",
"{",
"$",
"validators",
"[",
"$",
"property",
"]",
"=",
"[",
"'required'",
"=>",
"false",
",",
"'validators'",
"=>",
"[",
"]",
",",
"]",
";",
"}",
"$",
"validators",
"[",
"$",
"property",
"]",
"[",
"'validators'",
"]",
"[",
"]",
"=",
"$",
"annotation",
"->",
"getValidator",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"annotation",
"instanceof",
"Required",
")",
"{",
"$",
"validators",
"[",
"$",
"property",
"]",
"[",
"'required'",
"]",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"validators",
";",
"}"
] |
Gets all validators
@return array
|
[
"Gets",
"all",
"validators"
] |
0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1
|
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Validation/Validation.php#L177-L197
|
22,523
|
wenbinye/PhalconX
|
src/Validation/Validation.php
|
Validation.getElements
|
private function getElements($annotations, $formClass)
{
$labels = $this->getLabels($annotations);
$reflection = new \ReflectionClass($formClass);
$defaultValues = $reflection->getDefaultProperties();
$elements = [];
$it = $this->getAnnotations()->filter($annotations)
->is(InputInterface::class)
->onProperties();
foreach ($it as $annotation) {
$property = $annotation->getPropertyName();
if (!isset($annotation->name)) {
$annotation->name = $property;
}
$elem = $annotation->getElement($this);
if ($annotation->label) {
$label = $annotation->label;
} elseif (isset($labels[$property])) {
$label = $labels[$property];
} else {
$label = str_replace('_', ' ', ucfirst($property));
}
$elem->setLabel($label);
if (isset($defaultValues[$property])) {
$elem->setDefault($defaultValues[$property]);
}
$elements[$property] = $elem;
}
return $elements;
}
|
php
|
private function getElements($annotations, $formClass)
{
$labels = $this->getLabels($annotations);
$reflection = new \ReflectionClass($formClass);
$defaultValues = $reflection->getDefaultProperties();
$elements = [];
$it = $this->getAnnotations()->filter($annotations)
->is(InputInterface::class)
->onProperties();
foreach ($it as $annotation) {
$property = $annotation->getPropertyName();
if (!isset($annotation->name)) {
$annotation->name = $property;
}
$elem = $annotation->getElement($this);
if ($annotation->label) {
$label = $annotation->label;
} elseif (isset($labels[$property])) {
$label = $labels[$property];
} else {
$label = str_replace('_', ' ', ucfirst($property));
}
$elem->setLabel($label);
if (isset($defaultValues[$property])) {
$elem->setDefault($defaultValues[$property]);
}
$elements[$property] = $elem;
}
return $elements;
}
|
[
"private",
"function",
"getElements",
"(",
"$",
"annotations",
",",
"$",
"formClass",
")",
"{",
"$",
"labels",
"=",
"$",
"this",
"->",
"getLabels",
"(",
"$",
"annotations",
")",
";",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"formClass",
")",
";",
"$",
"defaultValues",
"=",
"$",
"reflection",
"->",
"getDefaultProperties",
"(",
")",
";",
"$",
"elements",
"=",
"[",
"]",
";",
"$",
"it",
"=",
"$",
"this",
"->",
"getAnnotations",
"(",
")",
"->",
"filter",
"(",
"$",
"annotations",
")",
"->",
"is",
"(",
"InputInterface",
"::",
"class",
")",
"->",
"onProperties",
"(",
")",
";",
"foreach",
"(",
"$",
"it",
"as",
"$",
"annotation",
")",
"{",
"$",
"property",
"=",
"$",
"annotation",
"->",
"getPropertyName",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"annotation",
"->",
"name",
")",
")",
"{",
"$",
"annotation",
"->",
"name",
"=",
"$",
"property",
";",
"}",
"$",
"elem",
"=",
"$",
"annotation",
"->",
"getElement",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"annotation",
"->",
"label",
")",
"{",
"$",
"label",
"=",
"$",
"annotation",
"->",
"label",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"labels",
"[",
"$",
"property",
"]",
")",
")",
"{",
"$",
"label",
"=",
"$",
"labels",
"[",
"$",
"property",
"]",
";",
"}",
"else",
"{",
"$",
"label",
"=",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"ucfirst",
"(",
"$",
"property",
")",
")",
";",
"}",
"$",
"elem",
"->",
"setLabel",
"(",
"$",
"label",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"defaultValues",
"[",
"$",
"property",
"]",
")",
")",
"{",
"$",
"elem",
"->",
"setDefault",
"(",
"$",
"defaultValues",
"[",
"$",
"property",
"]",
")",
";",
"}",
"$",
"elements",
"[",
"$",
"property",
"]",
"=",
"$",
"elem",
";",
"}",
"return",
"$",
"elements",
";",
"}"
] |
Gets all form elements
@return array key is property, value is Phalcon\Form\Element object
|
[
"Gets",
"all",
"form",
"elements"
] |
0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1
|
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Validation/Validation.php#L204-L234
|
22,524
|
gedex/php-janrain-api
|
lib/Janrain/Api/Capture/Settings.php
|
Settings.getSingle
|
public function getSingle($key, $forClientId = null)
{
$params = array('key' => $key);
if ($forClientId) {
$params['for_client_id'] = $forClientId;
}
return $this->post('settings/get', $params);
}
|
php
|
public function getSingle($key, $forClientId = null)
{
$params = array('key' => $key);
if ($forClientId) {
$params['for_client_id'] = $forClientId;
}
return $this->post('settings/get', $params);
}
|
[
"public",
"function",
"getSingle",
"(",
"$",
"key",
",",
"$",
"forClientId",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'key'",
"=>",
"$",
"key",
")",
";",
"if",
"(",
"$",
"forClientId",
")",
"{",
"$",
"params",
"[",
"'for_client_id'",
"]",
"=",
"$",
"forClientId",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"'settings/get'",
",",
"$",
"params",
")",
";",
"}"
] |
Get the value associated with a key for a particular `client_id`. If the key
has not value for that client, then return the key's default value for the
application, or if they key has not default value, then return null.
@param string $key The key whose value you want to retrieve. To find out the
values available, use the 'settings/keys' API call first
@param string $forClientId The client identifier. If you do not enter a value
for this parameter, it defaults to the value of
the `client_id`, that is, you are getting the
value for a key in your own record.
|
[
"Get",
"the",
"value",
"associated",
"with",
"a",
"key",
"for",
"a",
"particular",
"client_id",
".",
"If",
"the",
"key",
"has",
"not",
"value",
"for",
"that",
"client",
"then",
"return",
"the",
"key",
"s",
"default",
"value",
"for",
"the",
"application",
"or",
"if",
"they",
"key",
"has",
"not",
"default",
"value",
"then",
"return",
"null",
"."
] |
6283f68454e0ad5211ac620f1d337df38cd49597
|
https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Settings.php#L23-L32
|
22,525
|
gedex/php-janrain-api
|
lib/Janrain/Api/Capture/Settings.php
|
Settings.items
|
public function items($forClientId = null)
{
$params = array();
if ($forClientId) {
$params['for_client_id'] = $forClientId;
}
return $this->post('settings/items', $params);
}
|
php
|
public function items($forClientId = null)
{
$params = array();
if ($forClientId) {
$params['for_client_id'] = $forClientId;
}
return $this->post('settings/items', $params);
}
|
[
"public",
"function",
"items",
"(",
"$",
"forClientId",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"forClientId",
")",
"{",
"$",
"params",
"[",
"'for_client_id'",
"]",
"=",
"$",
"forClientId",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"'settings/items'",
",",
"$",
"params",
")",
";",
"}"
] |
Get all settings for a particular client, including those from the application-
wide default settings. If a key is defined in both the client and application
settings, only the client-specific value is returned.
@param string $forClientId The client identifier whose settings will be
retrieved. If you do not enter a value for this
parameter, it defaults to the value of the
`client_id`
|
[
"Get",
"all",
"settings",
"for",
"a",
"particular",
"client",
"including",
"those",
"from",
"the",
"application",
"-",
"wide",
"default",
"settings",
".",
"If",
"a",
"key",
"is",
"defined",
"in",
"both",
"the",
"client",
"and",
"application",
"settings",
"only",
"the",
"client",
"-",
"specific",
"value",
"is",
"returned",
"."
] |
6283f68454e0ad5211ac620f1d337df38cd49597
|
https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Settings.php#L70-L78
|
22,526
|
gedex/php-janrain-api
|
lib/Janrain/Api/Capture/Settings.php
|
Settings.keys
|
public function keys($forClientId = null)
{
$params = array();
if ($forClientId) {
$params['for_client_id'] = $forClientId;
}
return $this->post('settings/keys', $params);
}
|
php
|
public function keys($forClientId = null)
{
$params = array();
if ($forClientId) {
$params['for_client_id'] = $forClientId;
}
return $this->post('settings/keys', $params);
}
|
[
"public",
"function",
"keys",
"(",
"$",
"forClientId",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"forClientId",
")",
"{",
"$",
"params",
"[",
"'for_client_id'",
"]",
"=",
"$",
"forClientId",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"'settings/keys'",
",",
"$",
"params",
")",
";",
"}"
] |
Get all keys for a particular client, including those from the application-
wide default settings. Returns an array of the keys.
@param string $forClientId The client identifier whose setting will be
modified. If you do not enter a value for this
parameter, it defaults to the value of the
`client_id`, that is, you are modifying the
settings for your own record
|
[
"Get",
"all",
"keys",
"for",
"a",
"particular",
"client",
"including",
"those",
"from",
"the",
"application",
"-",
"wide",
"default",
"settings",
".",
"Returns",
"an",
"array",
"of",
"the",
"keys",
"."
] |
6283f68454e0ad5211ac620f1d337df38cd49597
|
https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Settings.php#L90-L98
|
22,527
|
gedex/php-janrain-api
|
lib/Janrain/Api/Capture/Settings.php
|
Settings.set
|
public function set($key, $value, $forClientId = null)
{
$params = array('key' => $key, 'value' => $value);
if (is_array($value)) {
$params['value'] = json_encode($value);
}
if ($forClientId) {
$params['for_client_id'] = $forClientId;
}
return $this->post('settings/set', $params);
}
|
php
|
public function set($key, $value, $forClientId = null)
{
$params = array('key' => $key, 'value' => $value);
if (is_array($value)) {
$params['value'] = json_encode($value);
}
if ($forClientId) {
$params['for_client_id'] = $forClientId;
}
return $this->post('settings/set', $params);
}
|
[
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"forClientId",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'key'",
"=>",
"$",
"key",
",",
"'value'",
"=>",
"$",
"value",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"params",
"[",
"'value'",
"]",
"=",
"json_encode",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"forClientId",
")",
"{",
"$",
"params",
"[",
"'for_client_id'",
"]",
"=",
"$",
"forClientId",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"'settings/set'",
",",
"$",
"params",
")",
";",
"}"
] |
Assign a key-value pair for a particular `client_id`. If the key does not
exist, it will be created. If they key already exists, this call overwrites
the existing value.
Returns a boolean that indicates whether the key already existed. True
indicates the key has been overwritten. False indicates that a new key has
been created.
Note that you cannot use 'settings/set' to modify the application-wide
default settings.
@param string $key The key to add or modify
@param mixed $value The value to assign to the key
@param string $forClientId The client identifier whose setting will be
modified. If you do not enter a value for this
parameter, it defaults to the value of the
`client_id`, that is, you are modifying the
settings for your own record
|
[
"Assign",
"a",
"key",
"-",
"value",
"pair",
"for",
"a",
"particular",
"client_id",
".",
"If",
"the",
"key",
"does",
"not",
"exist",
"it",
"will",
"be",
"created",
".",
"If",
"they",
"key",
"already",
"exists",
"this",
"call",
"overwrites",
"the",
"existing",
"value",
"."
] |
6283f68454e0ad5211ac620f1d337df38cd49597
|
https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Settings.php#L121-L133
|
22,528
|
gedex/php-janrain-api
|
lib/Janrain/Api/Capture/Settings.php
|
Settings.setMulti
|
public function setMulti(array $items, $forClientId = null)
{
$params = array('items' => json_encode($items));
if ($forClientId) {
$params['for_client_id'] = $forClientId;
}
return $this->post('settings/set_multi', $params);
}
|
php
|
public function setMulti(array $items, $forClientId = null)
{
$params = array('items' => json_encode($items));
if ($forClientId) {
$params['for_client_id'] = $forClientId;
}
return $this->post('settings/set_multi', $params);
}
|
[
"public",
"function",
"setMulti",
"(",
"array",
"$",
"items",
",",
"$",
"forClientId",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'items'",
"=>",
"json_encode",
"(",
"$",
"items",
")",
")",
";",
"if",
"(",
"$",
"forClientId",
")",
"{",
"$",
"params",
"[",
"'for_client_id'",
"]",
"=",
"$",
"forClientId",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"'settings/set_multi'",
",",
"$",
"params",
")",
";",
"}"
] |
Assign multiple settings for a particular `client_id`. Returns a JSON
object in which each key is mapped to a boolean that indicates whether the
key already existed. True indicates that a previous key did exist and has
been overwritten. False indicates that there were no previous key and a new
key has been created. Does not modify application-wide settings.
@param array $items Array containing key-value pairs to set for the client
identifier.
@param string $forClientId The client identifier whose settings will be
modified. If you do not enter a value for this
parameter, it defaults to the value of the
`client_id`, that is, you are setting the values
for multiple keys in your own record.
|
[
"Assign",
"multiple",
"settings",
"for",
"a",
"particular",
"client_id",
".",
"Returns",
"a",
"JSON",
"object",
"in",
"which",
"each",
"key",
"is",
"mapped",
"to",
"a",
"boolean",
"that",
"indicates",
"whether",
"the",
"key",
"already",
"existed",
".",
"True",
"indicates",
"that",
"a",
"previous",
"key",
"did",
"exist",
"and",
"has",
"been",
"overwritten",
".",
"False",
"indicates",
"that",
"there",
"were",
"no",
"previous",
"key",
"and",
"a",
"new",
"key",
"has",
"been",
"created",
".",
"Does",
"not",
"modify",
"application",
"-",
"wide",
"settings",
"."
] |
6283f68454e0ad5211ac620f1d337df38cd49597
|
https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Settings.php#L151-L160
|
22,529
|
gedex/php-janrain-api
|
lib/Janrain/Api/Capture/Settings.php
|
Settings.setDefault
|
public function setDefault($key, $value)
{
$params = array('key' => $key, 'value' => $value);
if (is_array($value)) {
$params['value'] = json_encode($value);
}
return $this->post('settings/set_default', $params);
}
|
php
|
public function setDefault($key, $value)
{
$params = array('key' => $key, 'value' => $value);
if (is_array($value)) {
$params['value'] = json_encode($value);
}
return $this->post('settings/set_default', $params);
}
|
[
"public",
"function",
"setDefault",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'key'",
"=>",
"$",
"key",
",",
"'value'",
"=>",
"$",
"value",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"params",
"[",
"'value'",
"]",
"=",
"json_encode",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"'settings/set_default'",
",",
"$",
"params",
")",
";",
"}"
] |
Set the application-wide default value for a key. This will create a new
key with a default value, if the key does not yet exist in the application.
If the key does exist, the value will be overwritten.
Returns a boolean that indicates whether the key already existed. "True"
indicates the key has been overwritten. "False" indicates that a new key
has been created.
@param string $key The key to add or modifiy
@param string $value The value to assign to the key
|
[
"Set",
"the",
"application",
"-",
"wide",
"default",
"value",
"for",
"a",
"key",
".",
"This",
"will",
"create",
"a",
"new",
"key",
"with",
"a",
"default",
"value",
"if",
"the",
"key",
"does",
"not",
"yet",
"exist",
"in",
"the",
"application",
".",
"If",
"the",
"key",
"does",
"exist",
"the",
"value",
"will",
"be",
"overwritten",
"."
] |
6283f68454e0ad5211ac620f1d337df38cd49597
|
https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Settings.php#L187-L195
|
22,530
|
gedex/php-janrain-api
|
lib/Janrain/Api/Capture/Settings.php
|
Settings.delete
|
public function delete($key, $forClientId = null)
{
$params = array('key' => $key);
if ($forClientId) {
$params['for_client_id'] = $forClientId;
}
return $this->post('settings/delete', $params);
}
|
php
|
public function delete($key, $forClientId = null)
{
$params = array('key' => $key);
if ($forClientId) {
$params['for_client_id'] = $forClientId;
}
return $this->post('settings/delete', $params);
}
|
[
"public",
"function",
"delete",
"(",
"$",
"key",
",",
"$",
"forClientId",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'key'",
"=>",
"$",
"key",
")",
";",
"if",
"(",
"$",
"forClientId",
")",
"{",
"$",
"params",
"[",
"'for_client_id'",
"]",
"=",
"$",
"forClientId",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"'settings/delete'",
",",
"$",
"params",
")",
";",
"}"
] |
Delete a key from the settings for a particular client. Returns a boolean
indicating whether the key existed. This does not modify the application-
wide default value for a key.
@param string $key The key to delete from the client settings. To find out
the values available, use the 'settings/keys' API call
first.
@param string $forClientId The client identifier whose key will be deleted
If you do not enter a value for this parameter,
it defaults to the value of the `client_id`. In
this case, you will delete the key from your
own account.
|
[
"Delete",
"a",
"key",
"from",
"the",
"settings",
"for",
"a",
"particular",
"client",
".",
"Returns",
"a",
"boolean",
"indicating",
"whether",
"the",
"key",
"existed",
".",
"This",
"does",
"not",
"modify",
"the",
"application",
"-",
"wide",
"default",
"value",
"for",
"a",
"key",
"."
] |
6283f68454e0ad5211ac620f1d337df38cd49597
|
https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Settings.php#L212-L221
|
22,531
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Translation/src/backends/ts_backend.php
|
ezcTranslationTsBackend.setOptions
|
public function setOptions( $options )
{
if ( is_array( $options ) )
{
$this->options->merge( $options );
}
else if ( $options instanceof ezcTranslationTsBackendOptions )
{
$this->options = $options;
}
else
{
throw new ezcBaseValueException( "options", $options, "instance of ezcTranslationTsBackendOptions" );
}
}
|
php
|
public function setOptions( $options )
{
if ( is_array( $options ) )
{
$this->options->merge( $options );
}
else if ( $options instanceof ezcTranslationTsBackendOptions )
{
$this->options = $options;
}
else
{
throw new ezcBaseValueException( "options", $options, "instance of ezcTranslationTsBackendOptions" );
}
}
|
[
"public",
"function",
"setOptions",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"options",
"->",
"merge",
"(",
"$",
"options",
")",
";",
"}",
"else",
"if",
"(",
"$",
"options",
"instanceof",
"ezcTranslationTsBackendOptions",
")",
"{",
"$",
"this",
"->",
"options",
"=",
"$",
"options",
";",
"}",
"else",
"{",
"throw",
"new",
"ezcBaseValueException",
"(",
"\"options\"",
",",
"$",
"options",
",",
"\"instance of ezcTranslationTsBackendOptions\"",
")",
";",
"}",
"}"
] |
Set new options.
This method allows you to change the options of the translation backend.
@param ezcTranslationTsBackendOptions $options The options to set.
@throws ezcBaseSettingNotFoundException
If you tried to set a non-existent option value.
@throws ezcBaseSettingValueException
If the value is not valid for the desired option.
@throws ezcBaseValueException
If you submit neither an array nor an instance of
ezcTranslationTsBackendOptions.
|
[
"Set",
"new",
"options",
".",
"This",
"method",
"allows",
"you",
"to",
"change",
"the",
"options",
"of",
"the",
"translation",
"backend",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Translation/src/backends/ts_backend.php#L162-L176
|
22,532
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Translation/src/backends/ts_backend.php
|
ezcTranslationTsBackend.deinitWriter
|
public function deinitWriter()
{
if ( is_null( $this->dom ) )
{
throw new ezcTranslationWriterNotInitializedException();
}
$filename = $this->buildTranslationFileName( $this->writeLocale );
$this->dom->save( $filename );
}
|
php
|
public function deinitWriter()
{
if ( is_null( $this->dom ) )
{
throw new ezcTranslationWriterNotInitializedException();
}
$filename = $this->buildTranslationFileName( $this->writeLocale );
$this->dom->save( $filename );
}
|
[
"public",
"function",
"deinitWriter",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"dom",
")",
")",
"{",
"throw",
"new",
"ezcTranslationWriterNotInitializedException",
"(",
")",
";",
"}",
"$",
"filename",
"=",
"$",
"this",
"->",
"buildTranslationFileName",
"(",
"$",
"this",
"->",
"writeLocale",
")",
";",
"$",
"this",
"->",
"dom",
"->",
"save",
"(",
"$",
"filename",
")",
";",
"}"
] |
Deinitializes the writer
@return void
|
[
"Deinitializes",
"the",
"writer"
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Translation/src/backends/ts_backend.php#L524-L532
|
22,533
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Translation/src/backends/ts_backend.php
|
ezcTranslationTsBackend.next
|
public function next()
{
if ( is_null( $this->xmlParser ) )
{
throw new ezcTranslationReaderNotInitializedException();
}
$valid = $this->xmlParser->valid();
if ( $valid )
{
$newContext = array( trim( $this->xmlParser->getChildren()->name), array() );
foreach ( $this->xmlParser->getChildren()->message as $data )
{
$translationItem = $this->parseSimpleXMLMessage( $data );
if ( !is_null( $translationItem ) )
{
$newContext[1][] = $translationItem;
}
}
$this->currentContext = $newContext;
$this->xmlParser->next();
}
else
{
$this->currentContext = null;
}
}
|
php
|
public function next()
{
if ( is_null( $this->xmlParser ) )
{
throw new ezcTranslationReaderNotInitializedException();
}
$valid = $this->xmlParser->valid();
if ( $valid )
{
$newContext = array( trim( $this->xmlParser->getChildren()->name), array() );
foreach ( $this->xmlParser->getChildren()->message as $data )
{
$translationItem = $this->parseSimpleXMLMessage( $data );
if ( !is_null( $translationItem ) )
{
$newContext[1][] = $translationItem;
}
}
$this->currentContext = $newContext;
$this->xmlParser->next();
}
else
{
$this->currentContext = null;
}
}
|
[
"public",
"function",
"next",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"xmlParser",
")",
")",
"{",
"throw",
"new",
"ezcTranslationReaderNotInitializedException",
"(",
")",
";",
"}",
"$",
"valid",
"=",
"$",
"this",
"->",
"xmlParser",
"->",
"valid",
"(",
")",
";",
"if",
"(",
"$",
"valid",
")",
"{",
"$",
"newContext",
"=",
"array",
"(",
"trim",
"(",
"$",
"this",
"->",
"xmlParser",
"->",
"getChildren",
"(",
")",
"->",
"name",
")",
",",
"array",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"xmlParser",
"->",
"getChildren",
"(",
")",
"->",
"message",
"as",
"$",
"data",
")",
"{",
"$",
"translationItem",
"=",
"$",
"this",
"->",
"parseSimpleXMLMessage",
"(",
"$",
"data",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"translationItem",
")",
")",
"{",
"$",
"newContext",
"[",
"1",
"]",
"[",
"]",
"=",
"$",
"translationItem",
";",
"}",
"}",
"$",
"this",
"->",
"currentContext",
"=",
"$",
"newContext",
";",
"$",
"this",
"->",
"xmlParser",
"->",
"next",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"currentContext",
"=",
"null",
";",
"}",
"}"
] |
Advanced to the next context.
This method parses a little bit more of the XML file to be able to
return the next context. If no more contexts are available it sets the
$currentContext member variable to null, so that the valid() method can
pick this up. If there are more contexts available it reads the context
from the file and stores it into the $currentContext member variable.
This method is used for iteration as part of the Iterator interface.
@throws ezcTranslationReaderNotInitializedException when the reader is
not initialized with initReader().
@return void
|
[
"Advanced",
"to",
"the",
"next",
"context",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Translation/src/backends/ts_backend.php#L548-L577
|
22,534
|
GreenCape/joomla-cli
|
src/GreenCape/JoomlaCLI/Driver/Factory.php
|
DriverFactory.create
|
public function create($basePath)
{
$parts = explode('.', $this->loadVersion($basePath)->getShortVersion());
while (!empty($parts))
{
$version = implode('Dot', $parts);
$classname = __NAMESPACE__ . '\\Joomla' . $version . 'Driver';
if (class_exists($classname))
{
return new $classname;
}
array_pop($parts);
}
throw new \RuntimeException('No driver found');
}
|
php
|
public function create($basePath)
{
$parts = explode('.', $this->loadVersion($basePath)->getShortVersion());
while (!empty($parts))
{
$version = implode('Dot', $parts);
$classname = __NAMESPACE__ . '\\Joomla' . $version . 'Driver';
if (class_exists($classname))
{
return new $classname;
}
array_pop($parts);
}
throw new \RuntimeException('No driver found');
}
|
[
"public",
"function",
"create",
"(",
"$",
"basePath",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"this",
"->",
"loadVersion",
"(",
"$",
"basePath",
")",
"->",
"getShortVersion",
"(",
")",
")",
";",
"while",
"(",
"!",
"empty",
"(",
"$",
"parts",
")",
")",
"{",
"$",
"version",
"=",
"implode",
"(",
"'Dot'",
",",
"$",
"parts",
")",
";",
"$",
"classname",
"=",
"__NAMESPACE__",
".",
"'\\\\Joomla'",
".",
"$",
"version",
".",
"'Driver'",
";",
"if",
"(",
"class_exists",
"(",
"$",
"classname",
")",
")",
"{",
"return",
"new",
"$",
"classname",
";",
"}",
"array_pop",
"(",
"$",
"parts",
")",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'No driver found'",
")",
";",
"}"
] |
Create a version specific driver to Joomla
@param string $basePath The Joomla base path (same as JPATH_BASE within Joomla)
@return JoomlaDriver
@throws \RuntimeException
|
[
"Create",
"a",
"version",
"specific",
"driver",
"to",
"Joomla"
] |
74a6940f27b1f66c99330d4f9e2c5ac314cdd369
|
https://github.com/GreenCape/joomla-cli/blob/74a6940f27b1f66c99330d4f9e2c5ac314cdd369/src/GreenCape/JoomlaCLI/Driver/Factory.php#L52-L66
|
22,535
|
GreenCape/joomla-cli
|
src/GreenCape/JoomlaCLI/Driver/Factory.php
|
DriverFactory.loadVersion
|
private function loadVersion($basePath)
{
static $locations = array(
'/libraries/cms/version/version.php',
'/libraries/joomla/version.php',
);
define('_JEXEC', 1);
foreach ($locations as $location)
{
if (file_exists($basePath . $location))
{
$code = file_get_contents($basePath . $location);
$code = str_replace("defined('JPATH_BASE')", "defined('_JEXEC')", $code);
eval('?>' . $code);
return new \JVersion;
}
}
throw new \RuntimeException('Unable to locate version information');
}
|
php
|
private function loadVersion($basePath)
{
static $locations = array(
'/libraries/cms/version/version.php',
'/libraries/joomla/version.php',
);
define('_JEXEC', 1);
foreach ($locations as $location)
{
if (file_exists($basePath . $location))
{
$code = file_get_contents($basePath . $location);
$code = str_replace("defined('JPATH_BASE')", "defined('_JEXEC')", $code);
eval('?>' . $code);
return new \JVersion;
}
}
throw new \RuntimeException('Unable to locate version information');
}
|
[
"private",
"function",
"loadVersion",
"(",
"$",
"basePath",
")",
"{",
"static",
"$",
"locations",
"=",
"array",
"(",
"'/libraries/cms/version/version.php'",
",",
"'/libraries/joomla/version.php'",
",",
")",
";",
"define",
"(",
"'_JEXEC'",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"locations",
"as",
"$",
"location",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"basePath",
".",
"$",
"location",
")",
")",
"{",
"$",
"code",
"=",
"file_get_contents",
"(",
"$",
"basePath",
".",
"$",
"location",
")",
";",
"$",
"code",
"=",
"str_replace",
"(",
"\"defined('JPATH_BASE')\"",
",",
"\"defined('_JEXEC')\"",
",",
"$",
"code",
")",
";",
"eval",
"(",
"'?>'",
".",
"$",
"code",
")",
";",
"return",
"new",
"\\",
"JVersion",
";",
"}",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Unable to locate version information'",
")",
";",
"}"
] |
Load the Joomla version
@param string $basePath The Joomla base path (same as JPATH_BASE within Joomla)
@return \JVersion
@throws \RuntimeException
|
[
"Load",
"the",
"Joomla",
"version"
] |
74a6940f27b1f66c99330d4f9e2c5ac314cdd369
|
https://github.com/GreenCape/joomla-cli/blob/74a6940f27b1f66c99330d4f9e2c5ac314cdd369/src/GreenCape/JoomlaCLI/Driver/Factory.php#L77-L98
|
22,536
|
nblum/silverstripe-flexible-content
|
code/ContentElement.php
|
ContentElement.getSiblings
|
public function getSiblings($active = '1')
{
$stage = \Nblum\FlexibleContent\FlexibleContentVersionedDataObject::get_live_stage();
$results = \Nblum\FlexibleContent\FlexibleContentVersionedDataObject::get_by_stage(
\ContentElement::class,
$stage
, [
'Active' => $active
], [
'Sort' => 'ASC'
]);
return $results;
}
|
php
|
public function getSiblings($active = '1')
{
$stage = \Nblum\FlexibleContent\FlexibleContentVersionedDataObject::get_live_stage();
$results = \Nblum\FlexibleContent\FlexibleContentVersionedDataObject::get_by_stage(
\ContentElement::class,
$stage
, [
'Active' => $active
], [
'Sort' => 'ASC'
]);
return $results;
}
|
[
"public",
"function",
"getSiblings",
"(",
"$",
"active",
"=",
"'1'",
")",
"{",
"$",
"stage",
"=",
"\\",
"Nblum",
"\\",
"FlexibleContent",
"\\",
"FlexibleContentVersionedDataObject",
"::",
"get_live_stage",
"(",
")",
";",
"$",
"results",
"=",
"\\",
"Nblum",
"\\",
"FlexibleContent",
"\\",
"FlexibleContentVersionedDataObject",
"::",
"get_by_stage",
"(",
"\\",
"ContentElement",
"::",
"class",
",",
"$",
"stage",
",",
"[",
"'Active'",
"=>",
"$",
"active",
"]",
",",
"[",
"'Sort'",
"=>",
"'ASC'",
"]",
")",
";",
"return",
"$",
"results",
";",
"}"
] |
returns all content element of the same page
@param string $active
@return DataList
|
[
"returns",
"all",
"content",
"element",
"of",
"the",
"same",
"page"
] |
e20a06ee98b7f884965a951653d98af11eb6bc67
|
https://github.com/nblum/silverstripe-flexible-content/blob/e20a06ee98b7f884965a951653d98af11eb6bc67/code/ContentElement.php#L255-L268
|
22,537
|
neyaoz/laravel-view-control
|
src/ViewControl/ViewControlServiceProvider.php
|
ViewControlServiceProvider.bindInstancesInContainer
|
protected function bindInstancesInContainer()
{
$this->app->instance("view-control.path", $this->path());
$this->app->instance("view-control.path.base", $this->basePath());
}
|
php
|
protected function bindInstancesInContainer()
{
$this->app->instance("view-control.path", $this->path());
$this->app->instance("view-control.path.base", $this->basePath());
}
|
[
"protected",
"function",
"bindInstancesInContainer",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"instance",
"(",
"\"view-control.path\"",
",",
"$",
"this",
"->",
"path",
"(",
")",
")",
";",
"$",
"this",
"->",
"app",
"->",
"instance",
"(",
"\"view-control.path.base\"",
",",
"$",
"this",
"->",
"basePath",
"(",
")",
")",
";",
"}"
] |
Bind all of the instances in the container.
@return void
|
[
"Bind",
"all",
"of",
"the",
"instances",
"in",
"the",
"container",
"."
] |
2f49777a5cd81223cd36da2ef4385ccd036a4b1e
|
https://github.com/neyaoz/laravel-view-control/blob/2f49777a5cd81223cd36da2ef4385ccd036a4b1e/src/ViewControl/ViewControlServiceProvider.php#L42-L46
|
22,538
|
neyaoz/laravel-view-control
|
src/ViewControl/ViewControlServiceProvider.php
|
ViewControlServiceProvider.basePath
|
public function basePath($path = '')
{
return $this->getFilesystem()->dirname($this->path()) . ($path ? DIRECTORY_SEPARATOR . $path : $path);
}
|
php
|
public function basePath($path = '')
{
return $this->getFilesystem()->dirname($this->path()) . ($path ? DIRECTORY_SEPARATOR . $path : $path);
}
|
[
"public",
"function",
"basePath",
"(",
"$",
"path",
"=",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"getFilesystem",
"(",
")",
"->",
"dirname",
"(",
"$",
"this",
"->",
"path",
"(",
")",
")",
".",
"(",
"$",
"path",
"?",
"DIRECTORY_SEPARATOR",
".",
"$",
"path",
":",
"$",
"path",
")",
";",
"}"
] |
Get the base path of the plugin installation.
@param string $path
@return string
|
[
"Get",
"the",
"base",
"path",
"of",
"the",
"plugin",
"installation",
"."
] |
2f49777a5cd81223cd36da2ef4385ccd036a4b1e
|
https://github.com/neyaoz/laravel-view-control/blob/2f49777a5cd81223cd36da2ef4385ccd036a4b1e/src/ViewControl/ViewControlServiceProvider.php#L123-L126
|
22,539
|
ajant/SimpleArrayLibrary
|
src/Categories/Counters.php
|
Counters.countMaxDepth
|
public static function countMaxDepth(array $array)
{
$maxDepth = 1;
foreach ($array as $element) {
$depth = 1;
if (is_array($element)) {
$depth += self::countMaxDepth($element);
}
if ($depth > $maxDepth) $maxDepth = $depth;
}
return $maxDepth;
}
|
php
|
public static function countMaxDepth(array $array)
{
$maxDepth = 1;
foreach ($array as $element) {
$depth = 1;
if (is_array($element)) {
$depth += self::countMaxDepth($element);
}
if ($depth > $maxDepth) $maxDepth = $depth;
}
return $maxDepth;
}
|
[
"public",
"static",
"function",
"countMaxDepth",
"(",
"array",
"$",
"array",
")",
"{",
"$",
"maxDepth",
"=",
"1",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"element",
")",
"{",
"$",
"depth",
"=",
"1",
";",
"if",
"(",
"is_array",
"(",
"$",
"element",
")",
")",
"{",
"$",
"depth",
"+=",
"self",
"::",
"countMaxDepth",
"(",
"$",
"element",
")",
";",
"}",
"if",
"(",
"$",
"depth",
">",
"$",
"maxDepth",
")",
"$",
"maxDepth",
"=",
"$",
"depth",
";",
"}",
"return",
"$",
"maxDepth",
";",
"}"
] |
Counts maximum array depth recursively
@param array $array
@return int
|
[
"Counts",
"maximum",
"array",
"depth",
"recursively"
] |
374877c0f20a22a914eb3680eb1cf39e424071be
|
https://github.com/ajant/SimpleArrayLibrary/blob/374877c0f20a22a914eb3680eb1cf39e424071be/src/Categories/Counters.php#L16-L28
|
22,540
|
ajant/SimpleArrayLibrary
|
src/Categories/Counters.php
|
Counters.countMaxDepthIterative
|
public static function countMaxDepthIterative(array $array)
{
$copy = $array;
$maxDepth = 1;
foreach ($copy as $element) {
$depth = 1;
while (!empty($element)) {
if (is_array($element)) {
++$depth;
$tmp = array_shift($element);
if (is_array($tmp)) {
array_push($element, array_shift($tmp));
}
} else {
break;
}
}
if ($depth > $maxDepth) {
$maxDepth = $depth;
}
}
return $maxDepth;
}
|
php
|
public static function countMaxDepthIterative(array $array)
{
$copy = $array;
$maxDepth = 1;
foreach ($copy as $element) {
$depth = 1;
while (!empty($element)) {
if (is_array($element)) {
++$depth;
$tmp = array_shift($element);
if (is_array($tmp)) {
array_push($element, array_shift($tmp));
}
} else {
break;
}
}
if ($depth > $maxDepth) {
$maxDepth = $depth;
}
}
return $maxDepth;
}
|
[
"public",
"static",
"function",
"countMaxDepthIterative",
"(",
"array",
"$",
"array",
")",
"{",
"$",
"copy",
"=",
"$",
"array",
";",
"$",
"maxDepth",
"=",
"1",
";",
"foreach",
"(",
"$",
"copy",
"as",
"$",
"element",
")",
"{",
"$",
"depth",
"=",
"1",
";",
"while",
"(",
"!",
"empty",
"(",
"$",
"element",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"element",
")",
")",
"{",
"++",
"$",
"depth",
";",
"$",
"tmp",
"=",
"array_shift",
"(",
"$",
"element",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"tmp",
")",
")",
"{",
"array_push",
"(",
"$",
"element",
",",
"array_shift",
"(",
"$",
"tmp",
")",
")",
";",
"}",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"depth",
">",
"$",
"maxDepth",
")",
"{",
"$",
"maxDepth",
"=",
"$",
"depth",
";",
"}",
"}",
"return",
"$",
"maxDepth",
";",
"}"
] |
Counts maximum array depth iteratively
@param array $array
@return int
|
[
"Counts",
"maximum",
"array",
"depth",
"iteratively"
] |
374877c0f20a22a914eb3680eb1cf39e424071be
|
https://github.com/ajant/SimpleArrayLibrary/blob/374877c0f20a22a914eb3680eb1cf39e424071be/src/Categories/Counters.php#L37-L61
|
22,541
|
ajant/SimpleArrayLibrary
|
src/Categories/Counters.php
|
Counters.countMinDepth
|
public static function countMinDepth($potentialArray, $depth = 0)
{
// validation, must be positive int or 0
if (!self::isLogicallyCastableToInt($depth)) {
throw new InvalidArgumentException('Depth parameter must be non-negative integer');
}
if ($depth < 0) {
throw new InvalidArgumentException('Depth parameter must be non-negative integer');
}
$return = $depth;
if (is_array($potentialArray)) {
$return++;
$childrenDepths = array();
foreach ($potentialArray as $element) {
$childrenDepths[] = self::countMinDepth($element, $return);
}
$return = empty($childrenDepths) ? $return : min($childrenDepths);
}
return $return;
}
|
php
|
public static function countMinDepth($potentialArray, $depth = 0)
{
// validation, must be positive int or 0
if (!self::isLogicallyCastableToInt($depth)) {
throw new InvalidArgumentException('Depth parameter must be non-negative integer');
}
if ($depth < 0) {
throw new InvalidArgumentException('Depth parameter must be non-negative integer');
}
$return = $depth;
if (is_array($potentialArray)) {
$return++;
$childrenDepths = array();
foreach ($potentialArray as $element) {
$childrenDepths[] = self::countMinDepth($element, $return);
}
$return = empty($childrenDepths) ? $return : min($childrenDepths);
}
return $return;
}
|
[
"public",
"static",
"function",
"countMinDepth",
"(",
"$",
"potentialArray",
",",
"$",
"depth",
"=",
"0",
")",
"{",
"// validation, must be positive int or 0",
"if",
"(",
"!",
"self",
"::",
"isLogicallyCastableToInt",
"(",
"$",
"depth",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Depth parameter must be non-negative integer'",
")",
";",
"}",
"if",
"(",
"$",
"depth",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Depth parameter must be non-negative integer'",
")",
";",
"}",
"$",
"return",
"=",
"$",
"depth",
";",
"if",
"(",
"is_array",
"(",
"$",
"potentialArray",
")",
")",
"{",
"$",
"return",
"++",
";",
"$",
"childrenDepths",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"potentialArray",
"as",
"$",
"element",
")",
"{",
"$",
"childrenDepths",
"[",
"]",
"=",
"self",
"::",
"countMinDepth",
"(",
"$",
"element",
",",
"$",
"return",
")",
";",
"}",
"$",
"return",
"=",
"empty",
"(",
"$",
"childrenDepths",
")",
"?",
"$",
"return",
":",
"min",
"(",
"$",
"childrenDepths",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] |
Counts maximum array depth
@param mixed $potentialArray
@param int $depth
@return int
@throws InvalidArgumentException
|
[
"Counts",
"maximum",
"array",
"depth"
] |
374877c0f20a22a914eb3680eb1cf39e424071be
|
https://github.com/ajant/SimpleArrayLibrary/blob/374877c0f20a22a914eb3680eb1cf39e424071be/src/Categories/Counters.php#L72-L93
|
22,542
|
oroinc/OroLayoutComponent
|
HierarchyIterator.php
|
HierarchyIterator.getParent
|
public function getParent()
{
$depth = $this->iterator->getDepth();
return $depth === 0
? $this->id
: $this->iterator->getSubIterator($depth - 1)->key();
}
|
php
|
public function getParent()
{
$depth = $this->iterator->getDepth();
return $depth === 0
? $this->id
: $this->iterator->getSubIterator($depth - 1)->key();
}
|
[
"public",
"function",
"getParent",
"(",
")",
"{",
"$",
"depth",
"=",
"$",
"this",
"->",
"iterator",
"->",
"getDepth",
"(",
")",
";",
"return",
"$",
"depth",
"===",
"0",
"?",
"$",
"this",
"->",
"id",
":",
"$",
"this",
"->",
"iterator",
"->",
"getSubIterator",
"(",
"$",
"depth",
"-",
"1",
")",
"->",
"key",
"(",
")",
";",
"}"
] |
Return the parent element
@return mixed
|
[
"Return",
"the",
"parent",
"element"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/HierarchyIterator.php#L36-L43
|
22,543
|
BugBuster1701/contao-botdetection-bundle
|
src/Resources/contao/classes/Referrer/ProviderCommunication.php
|
ProviderCommunication.loadProviderFiles
|
public function loadProviderFiles()
{
//debug $this->logMessage('ProviderCommunication::loadProviderFile: START','botdetection_debug');
$lastWeek = time() - (7 * 24 * 60 * 60);
if (false === $this->allowUrlOpen)
{
$this->logMessage('ProviderCommunication::loadProviderFiles allowUrlOpen = false!', 'botdetection_debug');
return false;
}
foreach($this->referrerProvider as $source => $url)
{
if (false === file_exists($this->cachePath .'/'. strtolower($source) . '.txt') ||
$lastWeek > filemtime($this->cachePath .'/'. strtolower($source) . '.txt')
)
{
//debug $this->logMessage('ProviderCommunication::loadProviderFile: '.$source,'botdetection_debug');
$fileProvider = fopen($this->cachePath .'/'. strtolower($source) . '.txt', 'wb+');
fwrite($fileProvider, file_get_contents($url));
fclose($fileProvider);
}
}
//debug $this->logMessage('ProviderCommunication::loadProviderFile: END','botdetection_debug');
return true;
}
|
php
|
public function loadProviderFiles()
{
//debug $this->logMessage('ProviderCommunication::loadProviderFile: START','botdetection_debug');
$lastWeek = time() - (7 * 24 * 60 * 60);
if (false === $this->allowUrlOpen)
{
$this->logMessage('ProviderCommunication::loadProviderFiles allowUrlOpen = false!', 'botdetection_debug');
return false;
}
foreach($this->referrerProvider as $source => $url)
{
if (false === file_exists($this->cachePath .'/'. strtolower($source) . '.txt') ||
$lastWeek > filemtime($this->cachePath .'/'. strtolower($source) . '.txt')
)
{
//debug $this->logMessage('ProviderCommunication::loadProviderFile: '.$source,'botdetection_debug');
$fileProvider = fopen($this->cachePath .'/'. strtolower($source) . '.txt', 'wb+');
fwrite($fileProvider, file_get_contents($url));
fclose($fileProvider);
}
}
//debug $this->logMessage('ProviderCommunication::loadProviderFile: END','botdetection_debug');
return true;
}
|
[
"public",
"function",
"loadProviderFiles",
"(",
")",
"{",
"//debug $this->logMessage('ProviderCommunication::loadProviderFile: START','botdetection_debug');",
"$",
"lastWeek",
"=",
"time",
"(",
")",
"-",
"(",
"7",
"*",
"24",
"*",
"60",
"*",
"60",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"allowUrlOpen",
")",
"{",
"$",
"this",
"->",
"logMessage",
"(",
"'ProviderCommunication::loadProviderFiles allowUrlOpen = false!'",
",",
"'botdetection_debug'",
")",
";",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"referrerProvider",
"as",
"$",
"source",
"=>",
"$",
"url",
")",
"{",
"if",
"(",
"false",
"===",
"file_exists",
"(",
"$",
"this",
"->",
"cachePath",
".",
"'/'",
".",
"strtolower",
"(",
"$",
"source",
")",
".",
"'.txt'",
")",
"||",
"$",
"lastWeek",
">",
"filemtime",
"(",
"$",
"this",
"->",
"cachePath",
".",
"'/'",
".",
"strtolower",
"(",
"$",
"source",
")",
".",
"'.txt'",
")",
")",
"{",
"//debug $this->logMessage('ProviderCommunication::loadProviderFile: '.$source,'botdetection_debug');",
"$",
"fileProvider",
"=",
"fopen",
"(",
"$",
"this",
"->",
"cachePath",
".",
"'/'",
".",
"strtolower",
"(",
"$",
"source",
")",
".",
"'.txt'",
",",
"'wb+'",
")",
";",
"fwrite",
"(",
"$",
"fileProvider",
",",
"file_get_contents",
"(",
"$",
"url",
")",
")",
";",
"fclose",
"(",
"$",
"fileProvider",
")",
";",
"}",
"}",
"//debug $this->logMessage('ProviderCommunication::loadProviderFile: END','botdetection_debug');",
"return",
"true",
";",
"}"
] |
Load Referrer Provider Files if
- provider files to old
|
[
"Load",
"Referrer",
"Provider",
"Files",
"if",
"-",
"provider",
"files",
"to",
"old"
] |
50c964acc354aa9116fae0e509cd7d075bd52f55
|
https://github.com/BugBuster1701/contao-botdetection-bundle/blob/50c964acc354aa9116fae0e509cd7d075bd52f55/src/Resources/contao/classes/Referrer/ProviderCommunication.php#L98-L124
|
22,544
|
BOOKEEN/opds-parser
|
src/Business/OpdsParserBusiness.php
|
OpdsParserBusiness.parse
|
private function parse(\SimpleXMLElement $xmldata)
{
if (!isset($xmldata->title)) {
throw new OpdsParserNoTitleException();
}
if ($xmldata->getName() === 'entry') {
return $this->parseEntry($xmldata);
}
return $this->parseFeed($xmldata);
}
|
php
|
private function parse(\SimpleXMLElement $xmldata)
{
if (!isset($xmldata->title)) {
throw new OpdsParserNoTitleException();
}
if ($xmldata->getName() === 'entry') {
return $this->parseEntry($xmldata);
}
return $this->parseFeed($xmldata);
}
|
[
"private",
"function",
"parse",
"(",
"\\",
"SimpleXMLElement",
"$",
"xmldata",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"xmldata",
"->",
"title",
")",
")",
"{",
"throw",
"new",
"OpdsParserNoTitleException",
"(",
")",
";",
"}",
"if",
"(",
"$",
"xmldata",
"->",
"getName",
"(",
")",
"===",
"'entry'",
")",
"{",
"return",
"$",
"this",
"->",
"parseEntry",
"(",
"$",
"xmldata",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parseFeed",
"(",
"$",
"xmldata",
")",
";",
"}"
] |
Parse an OPDS flux.
@param \SimpleXMLElement $xmldata
@return Feed|Publication
@throws OpdsParserNoTitleException
|
[
"Parse",
"an",
"OPDS",
"flux",
"."
] |
b9ef065210e81ee63b029e37c6943c6fa8c74cef
|
https://github.com/BOOKEEN/opds-parser/blob/b9ef065210e81ee63b029e37c6943c6fa8c74cef/src/Business/OpdsParserBusiness.php#L93-L106
|
22,545
|
BOOKEEN/opds-parser
|
src/Business/OpdsParserBusiness.php
|
OpdsParserBusiness.parsePagination
|
private function parsePagination(\SimpleXMLElement $xmldata)
{
$pagination = new Pagination();
$paginated = false;
foreach ($xmldata->children('opensearch', true) as $key => $value) {
switch ($key) {
case 'totalResults':
$pagination->setNumberOfItem((int) $value);
$paginated = true;
break;
case 'itemsPerPage':
$pagination->setItemsPerPage((int) $value);
$paginated = true;
break;
}
}
return $paginated ? $pagination : null;
}
|
php
|
private function parsePagination(\SimpleXMLElement $xmldata)
{
$pagination = new Pagination();
$paginated = false;
foreach ($xmldata->children('opensearch', true) as $key => $value) {
switch ($key) {
case 'totalResults':
$pagination->setNumberOfItem((int) $value);
$paginated = true;
break;
case 'itemsPerPage':
$pagination->setItemsPerPage((int) $value);
$paginated = true;
break;
}
}
return $paginated ? $pagination : null;
}
|
[
"private",
"function",
"parsePagination",
"(",
"\\",
"SimpleXMLElement",
"$",
"xmldata",
")",
"{",
"$",
"pagination",
"=",
"new",
"Pagination",
"(",
")",
";",
"$",
"paginated",
"=",
"false",
";",
"foreach",
"(",
"$",
"xmldata",
"->",
"children",
"(",
"'opensearch'",
",",
"true",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'totalResults'",
":",
"$",
"pagination",
"->",
"setNumberOfItem",
"(",
"(",
"int",
")",
"$",
"value",
")",
";",
"$",
"paginated",
"=",
"true",
";",
"break",
";",
"case",
"'itemsPerPage'",
":",
"$",
"pagination",
"->",
"setItemsPerPage",
"(",
"(",
"int",
")",
"$",
"value",
")",
";",
"$",
"paginated",
"=",
"true",
";",
"break",
";",
"}",
"}",
"return",
"$",
"paginated",
"?",
"$",
"pagination",
":",
"null",
";",
"}"
] |
Met en forme la pagination si elle existe
@param \SimpleXMLElement $xmldata
@return Pagination|null null si elle n'existe pas
|
[
"Met",
"en",
"forme",
"la",
"pagination",
"si",
"elle",
"existe"
] |
b9ef065210e81ee63b029e37c6943c6fa8c74cef
|
https://github.com/BOOKEEN/opds-parser/blob/b9ef065210e81ee63b029e37c6943c6fa8c74cef/src/Business/OpdsParserBusiness.php#L115-L134
|
22,546
|
mridang/magazine
|
lib/magento/Archive/Abstract.php
|
Mage_Archive_Abstract._writeFile
|
protected function _writeFile($destination, $data)
{
$destination = trim($destination);
if(false === file_put_contents($destination, $data)) {
throw new Mage_Exception("Can't write to file: " . $destination);
}
return true;
}
|
php
|
protected function _writeFile($destination, $data)
{
$destination = trim($destination);
if(false === file_put_contents($destination, $data)) {
throw new Mage_Exception("Can't write to file: " . $destination);
}
return true;
}
|
[
"protected",
"function",
"_writeFile",
"(",
"$",
"destination",
",",
"$",
"data",
")",
"{",
"$",
"destination",
"=",
"trim",
"(",
"$",
"destination",
")",
";",
"if",
"(",
"false",
"===",
"file_put_contents",
"(",
"$",
"destination",
",",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"Mage_Exception",
"(",
"\"Can't write to file: \"",
".",
"$",
"destination",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Write data to file. If file can't be opened - throw exception
@param string $destination
@param string $data
@return boolean
@throws Mage_Exception
|
[
"Write",
"data",
"to",
"file",
".",
"If",
"file",
"can",
"t",
"be",
"opened",
"-",
"throw",
"exception"
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Abstract.php#L44-L51
|
22,547
|
mridang/magazine
|
lib/magento/Archive/Abstract.php
|
Mage_Archive_Abstract._readFile
|
protected function _readFile($source)
{
$data = '';
if (is_file($source) && is_readable($source)) {
$data = @file_get_contents($source);
if ($data === false) {
throw new Mage_Exception("Can't get contents from: " . $source);
}
}
return $data;
}
|
php
|
protected function _readFile($source)
{
$data = '';
if (is_file($source) && is_readable($source)) {
$data = @file_get_contents($source);
if ($data === false) {
throw new Mage_Exception("Can't get contents from: " . $source);
}
}
return $data;
}
|
[
"protected",
"function",
"_readFile",
"(",
"$",
"source",
")",
"{",
"$",
"data",
"=",
"''",
";",
"if",
"(",
"is_file",
"(",
"$",
"source",
")",
"&&",
"is_readable",
"(",
"$",
"source",
")",
")",
"{",
"$",
"data",
"=",
"@",
"file_get_contents",
"(",
"$",
"source",
")",
";",
"if",
"(",
"$",
"data",
"===",
"false",
")",
"{",
"throw",
"new",
"Mage_Exception",
"(",
"\"Can't get contents from: \"",
".",
"$",
"source",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Read data from file. If file can't be opened, throw to exception.
@param string $source
@return string
@throws Mage_Exception
|
[
"Read",
"data",
"from",
"file",
".",
"If",
"file",
"can",
"t",
"be",
"opened",
"throw",
"to",
"exception",
"."
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Abstract.php#L60-L70
|
22,548
|
mridang/magazine
|
lib/magento/Archive/Tar.php
|
Mage_Archive_Tar._initWriter
|
protected function _initWriter()
{
$this->_writer = new Mage_Archive_Helper_File($this->_destinationFilePath);
$this->_writer->open('w');
return $this;
}
|
php
|
protected function _initWriter()
{
$this->_writer = new Mage_Archive_Helper_File($this->_destinationFilePath);
$this->_writer->open('w');
return $this;
}
|
[
"protected",
"function",
"_initWriter",
"(",
")",
"{",
"$",
"this",
"->",
"_writer",
"=",
"new",
"Mage_Archive_Helper_File",
"(",
"$",
"this",
"->",
"_destinationFilePath",
")",
";",
"$",
"this",
"->",
"_writer",
"->",
"open",
"(",
"'w'",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Initialize tarball writer
@return Mage_Archive_Tar
|
[
"Initialize",
"tarball",
"writer"
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L91-L97
|
22,549
|
mridang/magazine
|
lib/magento/Archive/Tar.php
|
Mage_Archive_Tar._destroyWriter
|
protected function _destroyWriter()
{
if ($this->_writer instanceof Mage_Archive_Helper_File) {
$this->_writer->close();
$this->_writer = null;
}
return $this;
}
|
php
|
protected function _destroyWriter()
{
if ($this->_writer instanceof Mage_Archive_Helper_File) {
$this->_writer->close();
$this->_writer = null;
}
return $this;
}
|
[
"protected",
"function",
"_destroyWriter",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_writer",
"instanceof",
"Mage_Archive_Helper_File",
")",
"{",
"$",
"this",
"->",
"_writer",
"->",
"close",
"(",
")",
";",
"$",
"this",
"->",
"_writer",
"=",
"null",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Destroy tarball writer
@return Mage_Archive_Tar
|
[
"Destroy",
"tarball",
"writer"
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L119-L127
|
22,550
|
mridang/magazine
|
lib/magento/Archive/Tar.php
|
Mage_Archive_Tar._initReader
|
protected function _initReader()
{
$this->_reader = new Mage_Archive_Helper_File($this->_getCurrentFile());
$this->_reader->open('r');
return $this;
}
|
php
|
protected function _initReader()
{
$this->_reader = new Mage_Archive_Helper_File($this->_getCurrentFile());
$this->_reader->open('r');
return $this;
}
|
[
"protected",
"function",
"_initReader",
"(",
")",
"{",
"$",
"this",
"->",
"_reader",
"=",
"new",
"Mage_Archive_Helper_File",
"(",
"$",
"this",
"->",
"_getCurrentFile",
"(",
")",
")",
";",
"$",
"this",
"->",
"_reader",
"->",
"open",
"(",
"'r'",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Initialize tarball reader
@return Mage_Archive_Tar
|
[
"Initialize",
"tarball",
"reader"
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L148-L154
|
22,551
|
mridang/magazine
|
lib/magento/Archive/Tar.php
|
Mage_Archive_Tar._destroyReader
|
protected function _destroyReader()
{
if ($this->_reader instanceof Mage_Archive_Helper_File) {
$this->_reader->close();
$this->_reader = null;
}
return $this;
}
|
php
|
protected function _destroyReader()
{
if ($this->_reader instanceof Mage_Archive_Helper_File) {
$this->_reader->close();
$this->_reader = null;
}
return $this;
}
|
[
"protected",
"function",
"_destroyReader",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_reader",
"instanceof",
"Mage_Archive_Helper_File",
")",
"{",
"$",
"this",
"->",
"_reader",
"->",
"close",
"(",
")",
";",
"$",
"this",
"->",
"_reader",
"=",
"null",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Destroy tarball reader
@return Mage_Archive_Tar
|
[
"Destroy",
"tarball",
"reader"
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L161-L169
|
22,552
|
mridang/magazine
|
lib/magento/Archive/Tar.php
|
Mage_Archive_Tar._setCurrentFile
|
protected function _setCurrentFile($file)
{
$this->_currentFile = $file .((!is_link($file) && is_dir($file) && substr($file, -1) != DS) ? DS : '');
return $this;
}
|
php
|
protected function _setCurrentFile($file)
{
$this->_currentFile = $file .((!is_link($file) && is_dir($file) && substr($file, -1) != DS) ? DS : '');
return $this;
}
|
[
"protected",
"function",
"_setCurrentFile",
"(",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"_currentFile",
"=",
"$",
"file",
".",
"(",
"(",
"!",
"is_link",
"(",
"$",
"file",
")",
"&&",
"is_dir",
"(",
"$",
"file",
")",
"&&",
"substr",
"(",
"$",
"file",
",",
"-",
"1",
")",
"!=",
"DS",
")",
"?",
"DS",
":",
"''",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set file which is packing.
@param string $file
@return Mage_Archive_Tar
|
[
"Set",
"file",
"which",
"is",
"packing",
"."
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L203-L207
|
22,553
|
mridang/magazine
|
lib/magento/Archive/Tar.php
|
Mage_Archive_Tar._setCurrentPath
|
protected function _setCurrentPath($path)
{
if ($this->_skipRoot && is_dir($path)) {
$this->_currentPath = $path.(substr($path, -1)!=DS?DS:'');
} else {
$this->_currentPath = dirname($path) . DS;
}
return $this;
}
|
php
|
protected function _setCurrentPath($path)
{
if ($this->_skipRoot && is_dir($path)) {
$this->_currentPath = $path.(substr($path, -1)!=DS?DS:'');
} else {
$this->_currentPath = dirname($path) . DS;
}
return $this;
}
|
[
"protected",
"function",
"_setCurrentPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_skipRoot",
"&&",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"_currentPath",
"=",
"$",
"path",
".",
"(",
"substr",
"(",
"$",
"path",
",",
"-",
"1",
")",
"!=",
"DS",
"?",
"DS",
":",
"''",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_currentPath",
"=",
"dirname",
"(",
"$",
"path",
")",
".",
"DS",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set path to file which is packing.
@param string $path
@return Mage_Archive_Tar
|
[
"Set",
"path",
"to",
"file",
"which",
"is",
"packing",
"."
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L237-L245
|
22,554
|
mridang/magazine
|
lib/magento/Archive/Tar.php
|
Mage_Archive_Tar._packToTar
|
protected function _packToTar($skipRoot=false)
{
$file = $this->_getCurrentFile();
$header = '';
$data = '';
if (!$skipRoot) {
$header = $this->_composeHeader();
$data = $this->_readFile($file);
$data = str_pad($data, floor(((is_dir($file) ? 0 : filesize($file)) + 512 - 1) / 512) * 512, "\0");
}
$sub = '';
if (is_dir($file)) {
$treeDir = scandir($file);
if (empty($treeDir)) {
throw new Mage_Exception('Can\'t scan dir: ' . $file);
}
array_shift($treeDir); /* remove './'*/
array_shift($treeDir); /* remove '../'*/
foreach ($treeDir as $item) {
$sub .= $this->_setCurrentFile($file.$item)->_packToTar(false);
}
}
$tarData = $header . $data . $sub;
$tarData = str_pad($tarData, floor((strlen($tarData) - 1) / 1536) * 1536, "\0");
return $tarData;
}
|
php
|
protected function _packToTar($skipRoot=false)
{
$file = $this->_getCurrentFile();
$header = '';
$data = '';
if (!$skipRoot) {
$header = $this->_composeHeader();
$data = $this->_readFile($file);
$data = str_pad($data, floor(((is_dir($file) ? 0 : filesize($file)) + 512 - 1) / 512) * 512, "\0");
}
$sub = '';
if (is_dir($file)) {
$treeDir = scandir($file);
if (empty($treeDir)) {
throw new Mage_Exception('Can\'t scan dir: ' . $file);
}
array_shift($treeDir); /* remove './'*/
array_shift($treeDir); /* remove '../'*/
foreach ($treeDir as $item) {
$sub .= $this->_setCurrentFile($file.$item)->_packToTar(false);
}
}
$tarData = $header . $data . $sub;
$tarData = str_pad($tarData, floor((strlen($tarData) - 1) / 1536) * 1536, "\0");
return $tarData;
}
|
[
"protected",
"function",
"_packToTar",
"(",
"$",
"skipRoot",
"=",
"false",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"_getCurrentFile",
"(",
")",
";",
"$",
"header",
"=",
"''",
";",
"$",
"data",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"skipRoot",
")",
"{",
"$",
"header",
"=",
"$",
"this",
"->",
"_composeHeader",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"_readFile",
"(",
"$",
"file",
")",
";",
"$",
"data",
"=",
"str_pad",
"(",
"$",
"data",
",",
"floor",
"(",
"(",
"(",
"is_dir",
"(",
"$",
"file",
")",
"?",
"0",
":",
"filesize",
"(",
"$",
"file",
")",
")",
"+",
"512",
"-",
"1",
")",
"/",
"512",
")",
"*",
"512",
",",
"\"\\0\"",
")",
";",
"}",
"$",
"sub",
"=",
"''",
";",
"if",
"(",
"is_dir",
"(",
"$",
"file",
")",
")",
"{",
"$",
"treeDir",
"=",
"scandir",
"(",
"$",
"file",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"treeDir",
")",
")",
"{",
"throw",
"new",
"Mage_Exception",
"(",
"'Can\\'t scan dir: '",
".",
"$",
"file",
")",
";",
"}",
"array_shift",
"(",
"$",
"treeDir",
")",
";",
"/* remove './'*/",
"array_shift",
"(",
"$",
"treeDir",
")",
";",
"/* remove '../'*/",
"foreach",
"(",
"$",
"treeDir",
"as",
"$",
"item",
")",
"{",
"$",
"sub",
".=",
"$",
"this",
"->",
"_setCurrentFile",
"(",
"$",
"file",
".",
"$",
"item",
")",
"->",
"_packToTar",
"(",
"false",
")",
";",
"}",
"}",
"$",
"tarData",
"=",
"$",
"header",
".",
"$",
"data",
".",
"$",
"sub",
";",
"$",
"tarData",
"=",
"str_pad",
"(",
"$",
"tarData",
",",
"floor",
"(",
"(",
"strlen",
"(",
"$",
"tarData",
")",
"-",
"1",
")",
"/",
"1536",
")",
"*",
"1536",
",",
"\"\\0\"",
")",
";",
"return",
"$",
"tarData",
";",
"}"
] |
Walk through directory and add to tar file or directory.
Result is packed string on TAR format.
@deprecated after 1.7.0.0
@param boolean $skipRoot
@return string
|
[
"Walk",
"through",
"directory",
"and",
"add",
"to",
"tar",
"file",
"or",
"directory",
".",
"Result",
"is",
"packed",
"string",
"on",
"TAR",
"format",
"."
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L265-L290
|
22,555
|
mridang/magazine
|
lib/magento/Archive/Tar.php
|
Mage_Archive_Tar._createTar
|
protected function _createTar($skipRoot = false, $finalize = false)
{
if (!$skipRoot) {
$this->_packAndWriteCurrentFile();
}
$file = $this->_getCurrentFile();
if (is_dir($file)) {
$dirFiles = scandir($file);
if (false === $dirFiles) {
throw new Mage_Exception('Can\'t scan dir: ' . $file);
}
array_shift($dirFiles); /* remove './'*/
array_shift($dirFiles); /* remove '../'*/
foreach ($dirFiles as $item) {
$this->_setCurrentFile($file . $item)->_createTar();
}
}
if ($finalize) {
$this->_getWriter()->write(str_repeat("\0", self::TAR_BLOCK_SIZE * 12));
}
}
|
php
|
protected function _createTar($skipRoot = false, $finalize = false)
{
if (!$skipRoot) {
$this->_packAndWriteCurrentFile();
}
$file = $this->_getCurrentFile();
if (is_dir($file)) {
$dirFiles = scandir($file);
if (false === $dirFiles) {
throw new Mage_Exception('Can\'t scan dir: ' . $file);
}
array_shift($dirFiles); /* remove './'*/
array_shift($dirFiles); /* remove '../'*/
foreach ($dirFiles as $item) {
$this->_setCurrentFile($file . $item)->_createTar();
}
}
if ($finalize) {
$this->_getWriter()->write(str_repeat("\0", self::TAR_BLOCK_SIZE * 12));
}
}
|
[
"protected",
"function",
"_createTar",
"(",
"$",
"skipRoot",
"=",
"false",
",",
"$",
"finalize",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"skipRoot",
")",
"{",
"$",
"this",
"->",
"_packAndWriteCurrentFile",
"(",
")",
";",
"}",
"$",
"file",
"=",
"$",
"this",
"->",
"_getCurrentFile",
"(",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"file",
")",
")",
"{",
"$",
"dirFiles",
"=",
"scandir",
"(",
"$",
"file",
")",
";",
"if",
"(",
"false",
"===",
"$",
"dirFiles",
")",
"{",
"throw",
"new",
"Mage_Exception",
"(",
"'Can\\'t scan dir: '",
".",
"$",
"file",
")",
";",
"}",
"array_shift",
"(",
"$",
"dirFiles",
")",
";",
"/* remove './'*/",
"array_shift",
"(",
"$",
"dirFiles",
")",
";",
"/* remove '../'*/",
"foreach",
"(",
"$",
"dirFiles",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"_setCurrentFile",
"(",
"$",
"file",
".",
"$",
"item",
")",
"->",
"_createTar",
"(",
")",
";",
"}",
"}",
"if",
"(",
"$",
"finalize",
")",
"{",
"$",
"this",
"->",
"_getWriter",
"(",
")",
"->",
"write",
"(",
"str_repeat",
"(",
"\"\\0\"",
",",
"self",
"::",
"TAR_BLOCK_SIZE",
"*",
"12",
")",
")",
";",
"}",
"}"
] |
Recursively walk through file tree and create tarball
@param boolean $skipRoot
@param boolean $finalize
@throws Mage_Exception
|
[
"Recursively",
"walk",
"through",
"file",
"tree",
"and",
"create",
"tarball"
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L299-L325
|
22,556
|
mridang/magazine
|
lib/magento/Archive/Tar.php
|
Mage_Archive_Tar._packAndWriteCurrentFile
|
protected function _packAndWriteCurrentFile()
{
$archiveWriter = $this->_getWriter();
$archiveWriter->write($this->_composeHeader());
$currentFile = $this->_getCurrentFile();
$fileSize = 0;
if (is_file($currentFile) && !is_link($currentFile)) {
$fileReader = new Mage_Archive_Helper_File($currentFile);
$fileReader->open('r');
while (!$fileReader->eof()) {
$archiveWriter->write($fileReader->read());
}
$fileReader->close();
$fileSize = filesize($currentFile);
}
$appendZerosCount = (self::TAR_BLOCK_SIZE - $fileSize % self::TAR_BLOCK_SIZE) % self::TAR_BLOCK_SIZE;
$archiveWriter->write(str_repeat("\0", $appendZerosCount));
}
|
php
|
protected function _packAndWriteCurrentFile()
{
$archiveWriter = $this->_getWriter();
$archiveWriter->write($this->_composeHeader());
$currentFile = $this->_getCurrentFile();
$fileSize = 0;
if (is_file($currentFile) && !is_link($currentFile)) {
$fileReader = new Mage_Archive_Helper_File($currentFile);
$fileReader->open('r');
while (!$fileReader->eof()) {
$archiveWriter->write($fileReader->read());
}
$fileReader->close();
$fileSize = filesize($currentFile);
}
$appendZerosCount = (self::TAR_BLOCK_SIZE - $fileSize % self::TAR_BLOCK_SIZE) % self::TAR_BLOCK_SIZE;
$archiveWriter->write(str_repeat("\0", $appendZerosCount));
}
|
[
"protected",
"function",
"_packAndWriteCurrentFile",
"(",
")",
"{",
"$",
"archiveWriter",
"=",
"$",
"this",
"->",
"_getWriter",
"(",
")",
";",
"$",
"archiveWriter",
"->",
"write",
"(",
"$",
"this",
"->",
"_composeHeader",
"(",
")",
")",
";",
"$",
"currentFile",
"=",
"$",
"this",
"->",
"_getCurrentFile",
"(",
")",
";",
"$",
"fileSize",
"=",
"0",
";",
"if",
"(",
"is_file",
"(",
"$",
"currentFile",
")",
"&&",
"!",
"is_link",
"(",
"$",
"currentFile",
")",
")",
"{",
"$",
"fileReader",
"=",
"new",
"Mage_Archive_Helper_File",
"(",
"$",
"currentFile",
")",
";",
"$",
"fileReader",
"->",
"open",
"(",
"'r'",
")",
";",
"while",
"(",
"!",
"$",
"fileReader",
"->",
"eof",
"(",
")",
")",
"{",
"$",
"archiveWriter",
"->",
"write",
"(",
"$",
"fileReader",
"->",
"read",
"(",
")",
")",
";",
"}",
"$",
"fileReader",
"->",
"close",
"(",
")",
";",
"$",
"fileSize",
"=",
"filesize",
"(",
"$",
"currentFile",
")",
";",
"}",
"$",
"appendZerosCount",
"=",
"(",
"self",
"::",
"TAR_BLOCK_SIZE",
"-",
"$",
"fileSize",
"%",
"self",
"::",
"TAR_BLOCK_SIZE",
")",
"%",
"self",
"::",
"TAR_BLOCK_SIZE",
";",
"$",
"archiveWriter",
"->",
"write",
"(",
"str_repeat",
"(",
"\"\\0\"",
",",
"$",
"appendZerosCount",
")",
")",
";",
"}"
] |
Write current file to tarball
|
[
"Write",
"current",
"file",
"to",
"tarball"
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L330-L354
|
22,557
|
mridang/magazine
|
lib/magento/Archive/Tar.php
|
Mage_Archive_Tar._unpackCurrentTar
|
protected function _unpackCurrentTar($destination)
{
$archiveReader = $this->_getReader();
$list = array();
while (!$archiveReader->eof()) {
$header = $this->_extractFileHeader();
if (!$header) {
continue;
}
$currentFile = $destination . $header['name'];
$dirname = dirname($currentFile);
if (in_array($header['type'], array("0",chr(0), ''))) {
if(!file_exists($dirname)) {
$mkdirResult = @mkdir($dirname, 0777, true);
if (false === $mkdirResult) {
throw new Mage_Exception('Failed to create directory ' . $dirname);
}
}
$this->_extractAndWriteFile($header, $currentFile);
$list[] = $currentFile;
} elseif ($header['type'] == '5') {
if(!file_exists($dirname)) {
$mkdirResult = @mkdir($currentFile, $header['mode'], true);
if (false === $mkdirResult) {
throw new Mage_Exception('Failed to create directory ' . $currentFile);
}
}
$list[] = $currentFile . DS;
} elseif ($header['type'] == '2') {
//we do not interrupt unpack process if symlink creation failed as symlinks are not so important
@symlink($header['symlink'], $currentFile);
}
}
return $list;
}
|
php
|
protected function _unpackCurrentTar($destination)
{
$archiveReader = $this->_getReader();
$list = array();
while (!$archiveReader->eof()) {
$header = $this->_extractFileHeader();
if (!$header) {
continue;
}
$currentFile = $destination . $header['name'];
$dirname = dirname($currentFile);
if (in_array($header['type'], array("0",chr(0), ''))) {
if(!file_exists($dirname)) {
$mkdirResult = @mkdir($dirname, 0777, true);
if (false === $mkdirResult) {
throw new Mage_Exception('Failed to create directory ' . $dirname);
}
}
$this->_extractAndWriteFile($header, $currentFile);
$list[] = $currentFile;
} elseif ($header['type'] == '5') {
if(!file_exists($dirname)) {
$mkdirResult = @mkdir($currentFile, $header['mode'], true);
if (false === $mkdirResult) {
throw new Mage_Exception('Failed to create directory ' . $currentFile);
}
}
$list[] = $currentFile . DS;
} elseif ($header['type'] == '2') {
//we do not interrupt unpack process if symlink creation failed as symlinks are not so important
@symlink($header['symlink'], $currentFile);
}
}
return $list;
}
|
[
"protected",
"function",
"_unpackCurrentTar",
"(",
"$",
"destination",
")",
"{",
"$",
"archiveReader",
"=",
"$",
"this",
"->",
"_getReader",
"(",
")",
";",
"$",
"list",
"=",
"array",
"(",
")",
";",
"while",
"(",
"!",
"$",
"archiveReader",
"->",
"eof",
"(",
")",
")",
"{",
"$",
"header",
"=",
"$",
"this",
"->",
"_extractFileHeader",
"(",
")",
";",
"if",
"(",
"!",
"$",
"header",
")",
"{",
"continue",
";",
"}",
"$",
"currentFile",
"=",
"$",
"destination",
".",
"$",
"header",
"[",
"'name'",
"]",
";",
"$",
"dirname",
"=",
"dirname",
"(",
"$",
"currentFile",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"header",
"[",
"'type'",
"]",
",",
"array",
"(",
"\"0\"",
",",
"chr",
"(",
"0",
")",
",",
"''",
")",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dirname",
")",
")",
"{",
"$",
"mkdirResult",
"=",
"@",
"mkdir",
"(",
"$",
"dirname",
",",
"0777",
",",
"true",
")",
";",
"if",
"(",
"false",
"===",
"$",
"mkdirResult",
")",
"{",
"throw",
"new",
"Mage_Exception",
"(",
"'Failed to create directory '",
".",
"$",
"dirname",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_extractAndWriteFile",
"(",
"$",
"header",
",",
"$",
"currentFile",
")",
";",
"$",
"list",
"[",
"]",
"=",
"$",
"currentFile",
";",
"}",
"elseif",
"(",
"$",
"header",
"[",
"'type'",
"]",
"==",
"'5'",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dirname",
")",
")",
"{",
"$",
"mkdirResult",
"=",
"@",
"mkdir",
"(",
"$",
"currentFile",
",",
"$",
"header",
"[",
"'mode'",
"]",
",",
"true",
")",
";",
"if",
"(",
"false",
"===",
"$",
"mkdirResult",
")",
"{",
"throw",
"new",
"Mage_Exception",
"(",
"'Failed to create directory '",
".",
"$",
"currentFile",
")",
";",
"}",
"}",
"$",
"list",
"[",
"]",
"=",
"$",
"currentFile",
".",
"DS",
";",
"}",
"elseif",
"(",
"$",
"header",
"[",
"'type'",
"]",
"==",
"'2'",
")",
"{",
"//we do not interrupt unpack process if symlink creation failed as symlinks are not so important",
"@",
"symlink",
"(",
"$",
"header",
"[",
"'symlink'",
"]",
",",
"$",
"currentFile",
")",
";",
"}",
"}",
"return",
"$",
"list",
";",
"}"
] |
Read TAR string from file, and unpacked it.
Create files and directories information about discribed
in the string.
@param string $destination path to file is unpacked
@return array list of files
@throws Mage_Exception
|
[
"Read",
"TAR",
"string",
"from",
"file",
"and",
"unpacked",
"it",
".",
"Create",
"files",
"and",
"directories",
"information",
"about",
"discribed",
"in",
"the",
"string",
"."
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L425-L471
|
22,558
|
mridang/magazine
|
lib/magento/Archive/Tar.php
|
Mage_Archive_Tar._parseHeader
|
protected function _parseHeader(&$pointer)
{
$firstLine = fread($pointer, 512);
if (strlen($firstLine)<512){
return false;
}
$fmt = self::_getFormatParseHeader();
$header = unpack ($fmt, $firstLine);
$header['mode']=$header['mode']+0;
$header['uid']=octdec($header['uid']);
$header['gid']=octdec($header['gid']);
$header['size']=octdec($header['size']);
$header['mtime']=octdec($header['mtime']);
$header['checksum']=octdec($header['checksum']);
if ($header['type'] == "5") {
$header['size'] = 0;
}
$checksum = 0;
$firstLine = substr_replace($firstLine, ' ', 148, 8);
for ($i = 0; $i < 512; $i++) {
$checksum += ord(substr($firstLine, $i, 1));
}
$isUstar = 'ustar' == strtolower(substr($header['magic'], 0, 5));
$checksumOk = $header['checksum'] == $checksum;
if (isset($header['name']) && $checksumOk) {
if ($header['name'] == '././@LongLink' && $header['type'] == 'L') {
$realName = substr(fread($pointer, floor(($header['size'] + 512 - 1) / 512) * 512), 0, $header['size']);
$headerMain = $this->_parseHeader($pointer);
$headerMain['name'] = $realName;
return $headerMain;
} else {
if ($header['size']>0) {
$header['data'] = substr(fread($pointer, floor(($header['size'] + 512 - 1) / 512) * 512), 0, $header['size']);
} else {
$header['data'] = '';
}
return $header;
}
}
return false;
}
|
php
|
protected function _parseHeader(&$pointer)
{
$firstLine = fread($pointer, 512);
if (strlen($firstLine)<512){
return false;
}
$fmt = self::_getFormatParseHeader();
$header = unpack ($fmt, $firstLine);
$header['mode']=$header['mode']+0;
$header['uid']=octdec($header['uid']);
$header['gid']=octdec($header['gid']);
$header['size']=octdec($header['size']);
$header['mtime']=octdec($header['mtime']);
$header['checksum']=octdec($header['checksum']);
if ($header['type'] == "5") {
$header['size'] = 0;
}
$checksum = 0;
$firstLine = substr_replace($firstLine, ' ', 148, 8);
for ($i = 0; $i < 512; $i++) {
$checksum += ord(substr($firstLine, $i, 1));
}
$isUstar = 'ustar' == strtolower(substr($header['magic'], 0, 5));
$checksumOk = $header['checksum'] == $checksum;
if (isset($header['name']) && $checksumOk) {
if ($header['name'] == '././@LongLink' && $header['type'] == 'L') {
$realName = substr(fread($pointer, floor(($header['size'] + 512 - 1) / 512) * 512), 0, $header['size']);
$headerMain = $this->_parseHeader($pointer);
$headerMain['name'] = $realName;
return $headerMain;
} else {
if ($header['size']>0) {
$header['data'] = substr(fread($pointer, floor(($header['size'] + 512 - 1) / 512) * 512), 0, $header['size']);
} else {
$header['data'] = '';
}
return $header;
}
}
return false;
}
|
[
"protected",
"function",
"_parseHeader",
"(",
"&",
"$",
"pointer",
")",
"{",
"$",
"firstLine",
"=",
"fread",
"(",
"$",
"pointer",
",",
"512",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"firstLine",
")",
"<",
"512",
")",
"{",
"return",
"false",
";",
"}",
"$",
"fmt",
"=",
"self",
"::",
"_getFormatParseHeader",
"(",
")",
";",
"$",
"header",
"=",
"unpack",
"(",
"$",
"fmt",
",",
"$",
"firstLine",
")",
";",
"$",
"header",
"[",
"'mode'",
"]",
"=",
"$",
"header",
"[",
"'mode'",
"]",
"+",
"0",
";",
"$",
"header",
"[",
"'uid'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'uid'",
"]",
")",
";",
"$",
"header",
"[",
"'gid'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'gid'",
"]",
")",
";",
"$",
"header",
"[",
"'size'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'size'",
"]",
")",
";",
"$",
"header",
"[",
"'mtime'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'mtime'",
"]",
")",
";",
"$",
"header",
"[",
"'checksum'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'checksum'",
"]",
")",
";",
"if",
"(",
"$",
"header",
"[",
"'type'",
"]",
"==",
"\"5\"",
")",
"{",
"$",
"header",
"[",
"'size'",
"]",
"=",
"0",
";",
"}",
"$",
"checksum",
"=",
"0",
";",
"$",
"firstLine",
"=",
"substr_replace",
"(",
"$",
"firstLine",
",",
"' '",
",",
"148",
",",
"8",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"512",
";",
"$",
"i",
"++",
")",
"{",
"$",
"checksum",
"+=",
"ord",
"(",
"substr",
"(",
"$",
"firstLine",
",",
"$",
"i",
",",
"1",
")",
")",
";",
"}",
"$",
"isUstar",
"=",
"'ustar'",
"==",
"strtolower",
"(",
"substr",
"(",
"$",
"header",
"[",
"'magic'",
"]",
",",
"0",
",",
"5",
")",
")",
";",
"$",
"checksumOk",
"=",
"$",
"header",
"[",
"'checksum'",
"]",
"==",
"$",
"checksum",
";",
"if",
"(",
"isset",
"(",
"$",
"header",
"[",
"'name'",
"]",
")",
"&&",
"$",
"checksumOk",
")",
"{",
"if",
"(",
"$",
"header",
"[",
"'name'",
"]",
"==",
"'././@LongLink'",
"&&",
"$",
"header",
"[",
"'type'",
"]",
"==",
"'L'",
")",
"{",
"$",
"realName",
"=",
"substr",
"(",
"fread",
"(",
"$",
"pointer",
",",
"floor",
"(",
"(",
"$",
"header",
"[",
"'size'",
"]",
"+",
"512",
"-",
"1",
")",
"/",
"512",
")",
"*",
"512",
")",
",",
"0",
",",
"$",
"header",
"[",
"'size'",
"]",
")",
";",
"$",
"headerMain",
"=",
"$",
"this",
"->",
"_parseHeader",
"(",
"$",
"pointer",
")",
";",
"$",
"headerMain",
"[",
"'name'",
"]",
"=",
"$",
"realName",
";",
"return",
"$",
"headerMain",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"header",
"[",
"'size'",
"]",
">",
"0",
")",
"{",
"$",
"header",
"[",
"'data'",
"]",
"=",
"substr",
"(",
"fread",
"(",
"$",
"pointer",
",",
"floor",
"(",
"(",
"$",
"header",
"[",
"'size'",
"]",
"+",
"512",
"-",
"1",
")",
"/",
"512",
")",
"*",
"512",
")",
",",
"0",
",",
"$",
"header",
"[",
"'size'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"header",
"[",
"'data'",
"]",
"=",
"''",
";",
"}",
"return",
"$",
"header",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Get header from TAR string and unpacked it by format.
@deprecated after 1.7.0.0
@param resource $pointer
@return string
|
[
"Get",
"header",
"from",
"TAR",
"string",
"and",
"unpacked",
"it",
"by",
"format",
"."
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L480-L527
|
22,559
|
mridang/magazine
|
lib/magento/Archive/Tar.php
|
Mage_Archive_Tar._extractFileHeader
|
protected function _extractFileHeader()
{
$archiveReader = $this->_getReader();
$headerBlock = $archiveReader->read(self::TAR_BLOCK_SIZE);
if (strlen($headerBlock) < self::TAR_BLOCK_SIZE) {
return false;
}
$header = unpack(self::_getFormatParseHeader(), $headerBlock);
$header['mode'] = octdec($header['mode']);
$header['uid'] = octdec($header['uid']);
$header['gid'] = octdec($header['gid']);
$header['size'] = octdec($header['size']);
$header['mtime'] = octdec($header['mtime']);
$header['checksum'] = octdec($header['checksum']);
if ($header['type'] == "5") {
$header['size'] = 0;
}
$checksum = 0;
$headerBlock = substr_replace($headerBlock, ' ', 148, 8);
for ($i = 0; $i < 512; $i++) {
$checksum += ord(substr($headerBlock, $i, 1));
}
$checksumOk = $header['checksum'] == $checksum;
if (isset($header['name']) && $checksumOk) {
if (!($header['name'] == '././@LongLink' && $header['type'] == 'L')) {
$header['name'] = trim($header['name']);
return $header;
}
$realNameBlockSize = floor(($header['size'] + self::TAR_BLOCK_SIZE - 1) / self::TAR_BLOCK_SIZE)
* self::TAR_BLOCK_SIZE;
$realNameBlock = $archiveReader->read($realNameBlockSize);
$realName = substr($realNameBlock, 0, $header['size']);
$headerMain = $this->_extractFileHeader();
$headerMain['name'] = trim($realName);
return $headerMain;
}
return false;
}
|
php
|
protected function _extractFileHeader()
{
$archiveReader = $this->_getReader();
$headerBlock = $archiveReader->read(self::TAR_BLOCK_SIZE);
if (strlen($headerBlock) < self::TAR_BLOCK_SIZE) {
return false;
}
$header = unpack(self::_getFormatParseHeader(), $headerBlock);
$header['mode'] = octdec($header['mode']);
$header['uid'] = octdec($header['uid']);
$header['gid'] = octdec($header['gid']);
$header['size'] = octdec($header['size']);
$header['mtime'] = octdec($header['mtime']);
$header['checksum'] = octdec($header['checksum']);
if ($header['type'] == "5") {
$header['size'] = 0;
}
$checksum = 0;
$headerBlock = substr_replace($headerBlock, ' ', 148, 8);
for ($i = 0; $i < 512; $i++) {
$checksum += ord(substr($headerBlock, $i, 1));
}
$checksumOk = $header['checksum'] == $checksum;
if (isset($header['name']) && $checksumOk) {
if (!($header['name'] == '././@LongLink' && $header['type'] == 'L')) {
$header['name'] = trim($header['name']);
return $header;
}
$realNameBlockSize = floor(($header['size'] + self::TAR_BLOCK_SIZE - 1) / self::TAR_BLOCK_SIZE)
* self::TAR_BLOCK_SIZE;
$realNameBlock = $archiveReader->read($realNameBlockSize);
$realName = substr($realNameBlock, 0, $header['size']);
$headerMain = $this->_extractFileHeader();
$headerMain['name'] = trim($realName);
return $headerMain;
}
return false;
}
|
[
"protected",
"function",
"_extractFileHeader",
"(",
")",
"{",
"$",
"archiveReader",
"=",
"$",
"this",
"->",
"_getReader",
"(",
")",
";",
"$",
"headerBlock",
"=",
"$",
"archiveReader",
"->",
"read",
"(",
"self",
"::",
"TAR_BLOCK_SIZE",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"headerBlock",
")",
"<",
"self",
"::",
"TAR_BLOCK_SIZE",
")",
"{",
"return",
"false",
";",
"}",
"$",
"header",
"=",
"unpack",
"(",
"self",
"::",
"_getFormatParseHeader",
"(",
")",
",",
"$",
"headerBlock",
")",
";",
"$",
"header",
"[",
"'mode'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'mode'",
"]",
")",
";",
"$",
"header",
"[",
"'uid'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'uid'",
"]",
")",
";",
"$",
"header",
"[",
"'gid'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'gid'",
"]",
")",
";",
"$",
"header",
"[",
"'size'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'size'",
"]",
")",
";",
"$",
"header",
"[",
"'mtime'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'mtime'",
"]",
")",
";",
"$",
"header",
"[",
"'checksum'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'checksum'",
"]",
")",
";",
"if",
"(",
"$",
"header",
"[",
"'type'",
"]",
"==",
"\"5\"",
")",
"{",
"$",
"header",
"[",
"'size'",
"]",
"=",
"0",
";",
"}",
"$",
"checksum",
"=",
"0",
";",
"$",
"headerBlock",
"=",
"substr_replace",
"(",
"$",
"headerBlock",
",",
"' '",
",",
"148",
",",
"8",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"512",
";",
"$",
"i",
"++",
")",
"{",
"$",
"checksum",
"+=",
"ord",
"(",
"substr",
"(",
"$",
"headerBlock",
",",
"$",
"i",
",",
"1",
")",
")",
";",
"}",
"$",
"checksumOk",
"=",
"$",
"header",
"[",
"'checksum'",
"]",
"==",
"$",
"checksum",
";",
"if",
"(",
"isset",
"(",
"$",
"header",
"[",
"'name'",
"]",
")",
"&&",
"$",
"checksumOk",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"header",
"[",
"'name'",
"]",
"==",
"'././@LongLink'",
"&&",
"$",
"header",
"[",
"'type'",
"]",
"==",
"'L'",
")",
")",
"{",
"$",
"header",
"[",
"'name'",
"]",
"=",
"trim",
"(",
"$",
"header",
"[",
"'name'",
"]",
")",
";",
"return",
"$",
"header",
";",
"}",
"$",
"realNameBlockSize",
"=",
"floor",
"(",
"(",
"$",
"header",
"[",
"'size'",
"]",
"+",
"self",
"::",
"TAR_BLOCK_SIZE",
"-",
"1",
")",
"/",
"self",
"::",
"TAR_BLOCK_SIZE",
")",
"*",
"self",
"::",
"TAR_BLOCK_SIZE",
";",
"$",
"realNameBlock",
"=",
"$",
"archiveReader",
"->",
"read",
"(",
"$",
"realNameBlockSize",
")",
";",
"$",
"realName",
"=",
"substr",
"(",
"$",
"realNameBlock",
",",
"0",
",",
"$",
"header",
"[",
"'size'",
"]",
")",
";",
"$",
"headerMain",
"=",
"$",
"this",
"->",
"_extractFileHeader",
"(",
")",
";",
"$",
"headerMain",
"[",
"'name'",
"]",
"=",
"trim",
"(",
"$",
"realName",
")",
";",
"return",
"$",
"headerMain",
";",
"}",
"return",
"false",
";",
"}"
] |
Read and decode file header information from tarball
@return array|boolean
|
[
"Read",
"and",
"decode",
"file",
"header",
"information",
"from",
"tarball"
] |
5b3cfecc472c61fde6af63efe62690a30a267a04
|
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L534-L583
|
22,560
|
madkom/regex
|
src/Grepper.php
|
Grepper.grep
|
public function grep(array $subjects, int $flags = 0) : array
{
$result = preg_grep($this->pattern->getPattern() . $this->modifier, $subjects, $flags);
if (($errno = preg_last_error()) !== PREG_NO_ERROR) {
$message = array_flip(get_defined_constants(true)['pcre'])[$errno];
switch ($errno) {
case PREG_INTERNAL_ERROR:
throw new InternalException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BACKTRACK_LIMIT_ERROR:
throw new BacktrackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_RECURSION_LIMIT_ERROR:
throw new RecursionLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_ERROR:
throw new BadUtf8Exception("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_OFFSET_ERROR:
throw new BadUtf8OffsetException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_JIT_STACKLIMIT_ERROR:
throw new JitStackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
}
}
return $result;
}
|
php
|
public function grep(array $subjects, int $flags = 0) : array
{
$result = preg_grep($this->pattern->getPattern() . $this->modifier, $subjects, $flags);
if (($errno = preg_last_error()) !== PREG_NO_ERROR) {
$message = array_flip(get_defined_constants(true)['pcre'])[$errno];
switch ($errno) {
case PREG_INTERNAL_ERROR:
throw new InternalException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BACKTRACK_LIMIT_ERROR:
throw new BacktrackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_RECURSION_LIMIT_ERROR:
throw new RecursionLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_ERROR:
throw new BadUtf8Exception("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_OFFSET_ERROR:
throw new BadUtf8OffsetException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_JIT_STACKLIMIT_ERROR:
throw new JitStackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
}
}
return $result;
}
|
[
"public",
"function",
"grep",
"(",
"array",
"$",
"subjects",
",",
"int",
"$",
"flags",
"=",
"0",
")",
":",
"array",
"{",
"$",
"result",
"=",
"preg_grep",
"(",
"$",
"this",
"->",
"pattern",
"->",
"getPattern",
"(",
")",
".",
"$",
"this",
"->",
"modifier",
",",
"$",
"subjects",
",",
"$",
"flags",
")",
";",
"if",
"(",
"(",
"$",
"errno",
"=",
"preg_last_error",
"(",
")",
")",
"!==",
"PREG_NO_ERROR",
")",
"{",
"$",
"message",
"=",
"array_flip",
"(",
"get_defined_constants",
"(",
"true",
")",
"[",
"'pcre'",
"]",
")",
"[",
"$",
"errno",
"]",
";",
"switch",
"(",
"$",
"errno",
")",
"{",
"case",
"PREG_INTERNAL_ERROR",
":",
"throw",
"new",
"InternalException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_BACKTRACK_LIMIT_ERROR",
":",
"throw",
"new",
"BacktrackLimitException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_RECURSION_LIMIT_ERROR",
":",
"throw",
"new",
"RecursionLimitException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_BAD_UTF8_ERROR",
":",
"throw",
"new",
"BadUtf8Exception",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_BAD_UTF8_OFFSET_ERROR",
":",
"throw",
"new",
"BadUtf8OffsetException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_JIT_STACKLIMIT_ERROR",
":",
"throw",
"new",
"JitStackLimitException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Retrieve grepped subjects array
@param array $subjects
@param int $flags
@return array
@throws BacktrackLimitException
@throws BadUtf8Exception
@throws BadUtf8OffsetException
@throws InternalException
@throws JitStackLimitException
@throws RecursionLimitException
|
[
"Retrieve",
"grepped",
"subjects",
"array"
] |
798c1124805b130b1110ee6e8dcc9a88d8aaffa8
|
https://github.com/madkom/regex/blob/798c1124805b130b1110ee6e8dcc9a88d8aaffa8/src/Grepper.php#L56-L79
|
22,561
|
andromeda-framework/doctrine
|
src/Doctrine/Console/Commands/SchemaDropCommand.php
|
SchemaDropCommand.executeSchemaCommand
|
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output,
SchemaTool $schemaTool, array $metadata, SymfonyStyle $ui)
{
$merger = new MetadataMerger();
$metadata = $merger->merge($metadata);
return parent::executeSchemaCommand($input, $output, $schemaTool, $metadata, $ui);
}
|
php
|
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output,
SchemaTool $schemaTool, array $metadata, SymfonyStyle $ui)
{
$merger = new MetadataMerger();
$metadata = $merger->merge($metadata);
return parent::executeSchemaCommand($input, $output, $schemaTool, $metadata, $ui);
}
|
[
"protected",
"function",
"executeSchemaCommand",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"SchemaTool",
"$",
"schemaTool",
",",
"array",
"$",
"metadata",
",",
"SymfonyStyle",
"$",
"ui",
")",
"{",
"$",
"merger",
"=",
"new",
"MetadataMerger",
"(",
")",
";",
"$",
"metadata",
"=",
"$",
"merger",
"->",
"merge",
"(",
"$",
"metadata",
")",
";",
"return",
"parent",
"::",
"executeSchemaCommand",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"schemaTool",
",",
"$",
"metadata",
",",
"$",
"ui",
")",
";",
"}"
] |
Executes the Drop command.
@param InputInterface $input
@param OutputInterface $output
@param SchemaTool $schemaTool
@param ClassMetadata[] $metadata
@param SymfonyStyle $ui
@return int|NULL 0 or NULL if everything went fine, or an error code
|
[
"Executes",
"the",
"Drop",
"command",
"."
] |
46924d91c09e0b9fbe5764518cbad70e467ffad4
|
https://github.com/andromeda-framework/doctrine/blob/46924d91c09e0b9fbe5764518cbad70e467ffad4/src/Doctrine/Console/Commands/SchemaDropCommand.php#L49-L56
|
22,562
|
jaxon-php/jaxon-jquery
|
src/SelectorTrait.php
|
SelectorTrait.jQuery
|
public function jQuery(string $sSelector, string $sContext = '')
{
return $this->getResponse()->plugin('jquery')->element($sSelector, $sContext);
}
|
php
|
public function jQuery(string $sSelector, string $sContext = '')
{
return $this->getResponse()->plugin('jquery')->element($sSelector, $sContext);
}
|
[
"public",
"function",
"jQuery",
"(",
"string",
"$",
"sSelector",
",",
"string",
"$",
"sContext",
"=",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"plugin",
"(",
"'jquery'",
")",
"->",
"element",
"(",
"$",
"sSelector",
",",
"$",
"sContext",
")",
";",
"}"
] |
Create a JQuery Element with a given selector, and link it to the response attribute.
@param string $sSelector The jQuery selector
@param string $sContext A context associated to the selector
@return Jaxon\JQuery\Dom\Element
|
[
"Create",
"a",
"JQuery",
"Element",
"with",
"a",
"given",
"selector",
"and",
"link",
"it",
"to",
"the",
"response",
"attribute",
"."
] |
90766a8ea8a4124a3f110e96b316370f71762380
|
https://github.com/jaxon-php/jaxon-jquery/blob/90766a8ea8a4124a3f110e96b316370f71762380/src/SelectorTrait.php#L22-L25
|
22,563
|
aalfiann/json-class-php
|
src/JSONHelper.php
|
JSONHelper.debug_decode
|
public function debug_decode($json,$assoc=false,$depth=512,$options=0){
$test = json_decode($json,$assoc,$depth,$options);
if (!empty($test)) $json = $test;
$data = $this->errorMessage(json_last_error(),$json);
return json_encode($data,JSON_PRETTY_PRINT);
}
|
php
|
public function debug_decode($json,$assoc=false,$depth=512,$options=0){
$test = json_decode($json,$assoc,$depth,$options);
if (!empty($test)) $json = $test;
$data = $this->errorMessage(json_last_error(),$json);
return json_encode($data,JSON_PRETTY_PRINT);
}
|
[
"public",
"function",
"debug_decode",
"(",
"$",
"json",
",",
"$",
"assoc",
"=",
"false",
",",
"$",
"depth",
"=",
"512",
",",
"$",
"options",
"=",
"0",
")",
"{",
"$",
"test",
"=",
"json_decode",
"(",
"$",
"json",
",",
"$",
"assoc",
",",
"$",
"depth",
",",
"$",
"options",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"test",
")",
")",
"$",
"json",
"=",
"$",
"test",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"errorMessage",
"(",
"json_last_error",
"(",
")",
",",
"$",
"json",
")",
";",
"return",
"json_encode",
"(",
"$",
"data",
",",
"JSON_PRETTY_PRINT",
")",
";",
"}"
] |
Debugger to test json decode
@param json is the json string
@return json string
|
[
"Debugger",
"to",
"test",
"json",
"decode"
] |
524be94b162031946137ea1b729ba390d83dc41e
|
https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L42-L47
|
22,564
|
aalfiann/json-class-php
|
src/JSONHelper.php
|
JSONHelper.fixControlChar
|
public function fixControlChar($string){
//Sanitize hidden control chars
for ($i = 0; $i <= 9; ++$i) {
$string = str_replace(chr($i), "", $string);
}
for ($i = 11; $i <= 12; ++$i) {
$string = str_replace(chr($i), "", $string);
}
for ($i = 14; $i <= 31; ++$i) {
$string = str_replace(chr($i), "", $string);
}
$string = str_replace(chr(127), "", $string);
//Handle Byte Order Mark (BOM)
if (0 === strpos(bin2hex($string), 'efbbbf')) {
$string = substr($string, 3);
}
//Handle newline char
$string = preg_replace("/[\r\n]+/", "\\n", $string);
return $string;
}
|
php
|
public function fixControlChar($string){
//Sanitize hidden control chars
for ($i = 0; $i <= 9; ++$i) {
$string = str_replace(chr($i), "", $string);
}
for ($i = 11; $i <= 12; ++$i) {
$string = str_replace(chr($i), "", $string);
}
for ($i = 14; $i <= 31; ++$i) {
$string = str_replace(chr($i), "", $string);
}
$string = str_replace(chr(127), "", $string);
//Handle Byte Order Mark (BOM)
if (0 === strpos(bin2hex($string), 'efbbbf')) {
$string = substr($string, 3);
}
//Handle newline char
$string = preg_replace("/[\r\n]+/", "\\n", $string);
return $string;
}
|
[
"public",
"function",
"fixControlChar",
"(",
"$",
"string",
")",
"{",
"//Sanitize hidden control chars",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<=",
"9",
";",
"++",
"$",
"i",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"chr",
"(",
"$",
"i",
")",
",",
"\"\"",
",",
"$",
"string",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"11",
";",
"$",
"i",
"<=",
"12",
";",
"++",
"$",
"i",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"chr",
"(",
"$",
"i",
")",
",",
"\"\"",
",",
"$",
"string",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"14",
";",
"$",
"i",
"<=",
"31",
";",
"++",
"$",
"i",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"chr",
"(",
"$",
"i",
")",
",",
"\"\"",
",",
"$",
"string",
")",
";",
"}",
"$",
"string",
"=",
"str_replace",
"(",
"chr",
"(",
"127",
")",
",",
"\"\"",
",",
"$",
"string",
")",
";",
"//Handle Byte Order Mark (BOM)",
"if",
"(",
"0",
"===",
"strpos",
"(",
"bin2hex",
"(",
"$",
"string",
")",
",",
"'efbbbf'",
")",
")",
"{",
"$",
"string",
"=",
"substr",
"(",
"$",
"string",
",",
"3",
")",
";",
"}",
"//Handle newline char",
"$",
"string",
"=",
"preg_replace",
"(",
"\"/[\\r\\n]+/\"",
",",
"\"\\\\n\"",
",",
"$",
"string",
")",
";",
"return",
"$",
"string",
";",
"}"
] |
Most common fixed hidden control char in json string which made json decode fails.
@param string is the string or json string
@return string
|
[
"Most",
"common",
"fixed",
"hidden",
"control",
"char",
"in",
"json",
"string",
"which",
"made",
"json",
"decode",
"fails",
"."
] |
524be94b162031946137ea1b729ba390d83dc41e
|
https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L220-L239
|
22,565
|
aalfiann/json-class-php
|
src/JSONHelper.php
|
JSONHelper.modifyJsonStringInArray
|
public function modifyJsonStringInArray($data,$jsonfield,$setnewfield=""){
if (is_array($data)){
if (count($data) == count($data, COUNT_RECURSIVE)) {
foreach($data as $value){
if(!empty($setnewfield)){
if (is_array($jsonfield)){
for ($i=0;$i<count($jsonfield);$i++){
if (isset($data[$jsonfield[$i]])){
$data[$setnewfield[$i]] = json_decode($data[$jsonfield[$i]]);
}
}
} else {
if (isset($data[$jsonfield])){
$data[$setnewfield] = json_decode($data[$jsonfield]);
}
}
} else {
if (is_array($jsonfield)){
for ($i=0;$i<count($jsonfield);$i++){
if (isset($data[$jsonfield[$i]])){
if (is_string($data[$jsonfield[$i]])) {
$decode = json_decode($data[$jsonfield[$i]]);
if (!empty($decode)) $data[$jsonfield[$i]] = $decode;
}
}
}
} else {
if (isset($data[$jsonfield])){
$decode = json_decode($data[$jsonfield]);
if (!empty($decode)) $data[$jsonfield] = $decode;
}
}
}
}
} else {
foreach($data as $key => $value){
$data[$key] = $this->modifyJsonStringInArray($data[$key],$jsonfield,$setnewfield);
}
}
}
return $data;
}
|
php
|
public function modifyJsonStringInArray($data,$jsonfield,$setnewfield=""){
if (is_array($data)){
if (count($data) == count($data, COUNT_RECURSIVE)) {
foreach($data as $value){
if(!empty($setnewfield)){
if (is_array($jsonfield)){
for ($i=0;$i<count($jsonfield);$i++){
if (isset($data[$jsonfield[$i]])){
$data[$setnewfield[$i]] = json_decode($data[$jsonfield[$i]]);
}
}
} else {
if (isset($data[$jsonfield])){
$data[$setnewfield] = json_decode($data[$jsonfield]);
}
}
} else {
if (is_array($jsonfield)){
for ($i=0;$i<count($jsonfield);$i++){
if (isset($data[$jsonfield[$i]])){
if (is_string($data[$jsonfield[$i]])) {
$decode = json_decode($data[$jsonfield[$i]]);
if (!empty($decode)) $data[$jsonfield[$i]] = $decode;
}
}
}
} else {
if (isset($data[$jsonfield])){
$decode = json_decode($data[$jsonfield]);
if (!empty($decode)) $data[$jsonfield] = $decode;
}
}
}
}
} else {
foreach($data as $key => $value){
$data[$key] = $this->modifyJsonStringInArray($data[$key],$jsonfield,$setnewfield);
}
}
}
return $data;
}
|
[
"public",
"function",
"modifyJsonStringInArray",
"(",
"$",
"data",
",",
"$",
"jsonfield",
",",
"$",
"setnewfield",
"=",
"\"\"",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"data",
")",
"==",
"count",
"(",
"$",
"data",
",",
"COUNT_RECURSIVE",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"setnewfield",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"jsonfield",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"jsonfield",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"[",
"$",
"i",
"]",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"setnewfield",
"[",
"$",
"i",
"]",
"]",
"=",
"json_decode",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"[",
"$",
"i",
"]",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"setnewfield",
"]",
"=",
"json_decode",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"jsonfield",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"jsonfield",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"[",
"$",
"i",
"]",
"]",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"[",
"$",
"i",
"]",
"]",
")",
")",
"{",
"$",
"decode",
"=",
"json_decode",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"[",
"$",
"i",
"]",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"decode",
")",
")",
"$",
"data",
"[",
"$",
"jsonfield",
"[",
"$",
"i",
"]",
"]",
"=",
"$",
"decode",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"]",
")",
")",
"{",
"$",
"decode",
"=",
"json_decode",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"decode",
")",
")",
"$",
"data",
"[",
"$",
"jsonfield",
"]",
"=",
"$",
"decode",
";",
"}",
"}",
"}",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"modifyJsonStringInArray",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
",",
"$",
"jsonfield",
",",
"$",
"setnewfield",
")",
";",
"}",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Modify json data string in some field array to be nice json data structure
Note:
- When you put json into database, then you load it with using PDO:fetch() or PDO::fetchAll() it will be served as string inside some field array.
- So this function is make you easier to modify the json string to become nice json data structure automatically.
- This function is well tested at here >> https://3v4l.org/IWkjn
@param data is the data array
@param jsonfield is the field which is contains json string
@param setnewfield is to put the result of modified json string in new field
@return mixed array or string (if the $data is string then will return string)
|
[
"Modify",
"json",
"data",
"string",
"in",
"some",
"field",
"array",
"to",
"be",
"nice",
"json",
"data",
"structure"
] |
524be94b162031946137ea1b729ba390d83dc41e
|
https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L254-L295
|
22,566
|
aalfiann/json-class-php
|
src/JSONHelper.php
|
JSONHelper.minify
|
public function minify($json){
$tokenizer = "/\"|(\/\*)|(\*\/)|(\/\/)|\n|\r/";
$in_string = false;
$in_multiline_comment = false;
$in_singleline_comment = false;
$tmp; $tmp2; $new_str = array(); $ns = 0; $from = 0; $lc; $rc; $lastIndex = 0;
while (preg_match($tokenizer,$json,$tmp,PREG_OFFSET_CAPTURE,$lastIndex)){
$tmp = $tmp[0];
$lastIndex = $tmp[1] + strlen($tmp[0]);
$lc = substr($json,0,$lastIndex - strlen($tmp[0]));
$rc = substr($json,$lastIndex);
if (!$in_multiline_comment && !$in_singleline_comment){
$tmp2 = substr($lc,$from);
if (!$in_string){
$tmp2 = preg_replace("/(\n|\r|\s)*/","",$tmp2);
}
$new_str[] = $tmp2;
}
$from = $lastIndex;
if ($tmp[0] == "\"" && !$in_multiline_comment && !$in_singleline_comment){
preg_match("/(\\\\)*$/",$lc,$tmp2);
if (!$in_string || !$tmp2 || (strlen($tmp2[0]) % 2) == 0){ // start of string with ", or unescaped " character found to end string
$in_string = !$in_string;
}
$from--; // include " character in next catch
$rc = substr($json,$from);
} else if ($tmp[0] == "/*" && !$in_string && !$in_multiline_comment && !$in_singleline_comment){
$in_multiline_comment = true;
} else if ($tmp[0] == "*/" && !$in_string && $in_multiline_comment && !$in_singleline_comment){
$in_multiline_comment = false;
} else if ($tmp[0] == "//" && !$in_string && !$in_multiline_comment && !$in_singleline_comment){
$in_singleline_comment = true;
} else if (($tmp[0] == "\n" || $tmp[0] == "\r") && !$in_string && !$in_multiline_comment && $in_singleline_comment){
$in_singleline_comment = false;
} else if (!$in_multiline_comment && !$in_singleline_comment && !(preg_match("/\n|\r|\s/",$tmp[0]))){
$new_str[] = $tmp[0];
}
}
$new_str[] = $rc;
return implode("",$new_str);
}
|
php
|
public function minify($json){
$tokenizer = "/\"|(\/\*)|(\*\/)|(\/\/)|\n|\r/";
$in_string = false;
$in_multiline_comment = false;
$in_singleline_comment = false;
$tmp; $tmp2; $new_str = array(); $ns = 0; $from = 0; $lc; $rc; $lastIndex = 0;
while (preg_match($tokenizer,$json,$tmp,PREG_OFFSET_CAPTURE,$lastIndex)){
$tmp = $tmp[0];
$lastIndex = $tmp[1] + strlen($tmp[0]);
$lc = substr($json,0,$lastIndex - strlen($tmp[0]));
$rc = substr($json,$lastIndex);
if (!$in_multiline_comment && !$in_singleline_comment){
$tmp2 = substr($lc,$from);
if (!$in_string){
$tmp2 = preg_replace("/(\n|\r|\s)*/","",$tmp2);
}
$new_str[] = $tmp2;
}
$from = $lastIndex;
if ($tmp[0] == "\"" && !$in_multiline_comment && !$in_singleline_comment){
preg_match("/(\\\\)*$/",$lc,$tmp2);
if (!$in_string || !$tmp2 || (strlen($tmp2[0]) % 2) == 0){ // start of string with ", or unescaped " character found to end string
$in_string = !$in_string;
}
$from--; // include " character in next catch
$rc = substr($json,$from);
} else if ($tmp[0] == "/*" && !$in_string && !$in_multiline_comment && !$in_singleline_comment){
$in_multiline_comment = true;
} else if ($tmp[0] == "*/" && !$in_string && $in_multiline_comment && !$in_singleline_comment){
$in_multiline_comment = false;
} else if ($tmp[0] == "//" && !$in_string && !$in_multiline_comment && !$in_singleline_comment){
$in_singleline_comment = true;
} else if (($tmp[0] == "\n" || $tmp[0] == "\r") && !$in_string && !$in_multiline_comment && $in_singleline_comment){
$in_singleline_comment = false;
} else if (!$in_multiline_comment && !$in_singleline_comment && !(preg_match("/\n|\r|\s/",$tmp[0]))){
$new_str[] = $tmp[0];
}
}
$new_str[] = $rc;
return implode("",$new_str);
}
|
[
"public",
"function",
"minify",
"(",
"$",
"json",
")",
"{",
"$",
"tokenizer",
"=",
"\"/\\\"|(\\/\\*)|(\\*\\/)|(\\/\\/)|\\n|\\r/\"",
";",
"$",
"in_string",
"=",
"false",
";",
"$",
"in_multiline_comment",
"=",
"false",
";",
"$",
"in_singleline_comment",
"=",
"false",
";",
"$",
"tmp",
";",
"$",
"tmp2",
";",
"$",
"new_str",
"=",
"array",
"(",
")",
";",
"$",
"ns",
"=",
"0",
";",
"$",
"from",
"=",
"0",
";",
"$",
"lc",
";",
"$",
"rc",
";",
"$",
"lastIndex",
"=",
"0",
";",
"while",
"(",
"preg_match",
"(",
"$",
"tokenizer",
",",
"$",
"json",
",",
"$",
"tmp",
",",
"PREG_OFFSET_CAPTURE",
",",
"$",
"lastIndex",
")",
")",
"{",
"$",
"tmp",
"=",
"$",
"tmp",
"[",
"0",
"]",
";",
"$",
"lastIndex",
"=",
"$",
"tmp",
"[",
"1",
"]",
"+",
"strlen",
"(",
"$",
"tmp",
"[",
"0",
"]",
")",
";",
"$",
"lc",
"=",
"substr",
"(",
"$",
"json",
",",
"0",
",",
"$",
"lastIndex",
"-",
"strlen",
"(",
"$",
"tmp",
"[",
"0",
"]",
")",
")",
";",
"$",
"rc",
"=",
"substr",
"(",
"$",
"json",
",",
"$",
"lastIndex",
")",
";",
"if",
"(",
"!",
"$",
"in_multiline_comment",
"&&",
"!",
"$",
"in_singleline_comment",
")",
"{",
"$",
"tmp2",
"=",
"substr",
"(",
"$",
"lc",
",",
"$",
"from",
")",
";",
"if",
"(",
"!",
"$",
"in_string",
")",
"{",
"$",
"tmp2",
"=",
"preg_replace",
"(",
"\"/(\\n|\\r|\\s)*/\"",
",",
"\"\"",
",",
"$",
"tmp2",
")",
";",
"}",
"$",
"new_str",
"[",
"]",
"=",
"$",
"tmp2",
";",
"}",
"$",
"from",
"=",
"$",
"lastIndex",
";",
"if",
"(",
"$",
"tmp",
"[",
"0",
"]",
"==",
"\"\\\"\"",
"&&",
"!",
"$",
"in_multiline_comment",
"&&",
"!",
"$",
"in_singleline_comment",
")",
"{",
"preg_match",
"(",
"\"/(\\\\\\\\)*$/\"",
",",
"$",
"lc",
",",
"$",
"tmp2",
")",
";",
"if",
"(",
"!",
"$",
"in_string",
"||",
"!",
"$",
"tmp2",
"||",
"(",
"strlen",
"(",
"$",
"tmp2",
"[",
"0",
"]",
")",
"%",
"2",
")",
"==",
"0",
")",
"{",
"// start of string with \", or unescaped \" character found to end string",
"$",
"in_string",
"=",
"!",
"$",
"in_string",
";",
"}",
"$",
"from",
"--",
";",
"// include \" character in next catch",
"$",
"rc",
"=",
"substr",
"(",
"$",
"json",
",",
"$",
"from",
")",
";",
"}",
"else",
"if",
"(",
"$",
"tmp",
"[",
"0",
"]",
"==",
"\"/*\"",
"&&",
"!",
"$",
"in_string",
"&&",
"!",
"$",
"in_multiline_comment",
"&&",
"!",
"$",
"in_singleline_comment",
")",
"{",
"$",
"in_multiline_comment",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"tmp",
"[",
"0",
"]",
"==",
"\"*/\"",
"&&",
"!",
"$",
"in_string",
"&&",
"$",
"in_multiline_comment",
"&&",
"!",
"$",
"in_singleline_comment",
")",
"{",
"$",
"in_multiline_comment",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"$",
"tmp",
"[",
"0",
"]",
"==",
"\"//\"",
"&&",
"!",
"$",
"in_string",
"&&",
"!",
"$",
"in_multiline_comment",
"&&",
"!",
"$",
"in_singleline_comment",
")",
"{",
"$",
"in_singleline_comment",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"(",
"$",
"tmp",
"[",
"0",
"]",
"==",
"\"\\n\"",
"||",
"$",
"tmp",
"[",
"0",
"]",
"==",
"\"\\r\"",
")",
"&&",
"!",
"$",
"in_string",
"&&",
"!",
"$",
"in_multiline_comment",
"&&",
"$",
"in_singleline_comment",
")",
"{",
"$",
"in_singleline_comment",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"in_multiline_comment",
"&&",
"!",
"$",
"in_singleline_comment",
"&&",
"!",
"(",
"preg_match",
"(",
"\"/\\n|\\r|\\s/\"",
",",
"$",
"tmp",
"[",
"0",
"]",
")",
")",
")",
"{",
"$",
"new_str",
"[",
"]",
"=",
"$",
"tmp",
"[",
"0",
"]",
";",
"}",
"}",
"$",
"new_str",
"[",
"]",
"=",
"$",
"rc",
";",
"return",
"implode",
"(",
"\"\"",
",",
"$",
"new_str",
")",
";",
"}"
] |
Minify the json string
@param json is the json string
@return string
|
[
"Minify",
"the",
"json",
"string"
] |
524be94b162031946137ea1b729ba390d83dc41e
|
https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L326-L366
|
22,567
|
pvsaintpe/yii2-grid
|
widgets/GridView.php
|
GridView.renderPageSummary
|
public function renderPageSummary()
{
$content = parent::renderPageSummary();
if ($this->showCustomPageSummary) {
if (!$content) {
$content = "<tfoot></tfoot>";
}
if ($this->beforeSummary) {
foreach ($this->beforeSummary as &$row) {
if (!isset($row['options'])) {
$row['options'] = $this->pageSummaryRowOptions;
}
}
}
if ($this->afterSummary) {
foreach ($this->afterSummary as &$row) {
if (!isset($row['options'])) {
$row['options'] = $this->pageSummaryRowOptions;
}
}
}
return strtr(
$content,
[
'<tfoot>' => "<tfoot>\n" . parent::generateRows($this->beforeSummary),
'</tfoot>' => parent::generateRows($this->afterSummary) . "\n</tfoot>",
]
);
}
return $content;
}
|
php
|
public function renderPageSummary()
{
$content = parent::renderPageSummary();
if ($this->showCustomPageSummary) {
if (!$content) {
$content = "<tfoot></tfoot>";
}
if ($this->beforeSummary) {
foreach ($this->beforeSummary as &$row) {
if (!isset($row['options'])) {
$row['options'] = $this->pageSummaryRowOptions;
}
}
}
if ($this->afterSummary) {
foreach ($this->afterSummary as &$row) {
if (!isset($row['options'])) {
$row['options'] = $this->pageSummaryRowOptions;
}
}
}
return strtr(
$content,
[
'<tfoot>' => "<tfoot>\n" . parent::generateRows($this->beforeSummary),
'</tfoot>' => parent::generateRows($this->afterSummary) . "\n</tfoot>",
]
);
}
return $content;
}
|
[
"public",
"function",
"renderPageSummary",
"(",
")",
"{",
"$",
"content",
"=",
"parent",
"::",
"renderPageSummary",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"showCustomPageSummary",
")",
"{",
"if",
"(",
"!",
"$",
"content",
")",
"{",
"$",
"content",
"=",
"\"<tfoot></tfoot>\"",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"beforeSummary",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"beforeSummary",
"as",
"&",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"row",
"[",
"'options'",
"]",
"=",
"$",
"this",
"->",
"pageSummaryRowOptions",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"afterSummary",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"afterSummary",
"as",
"&",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"row",
"[",
"'options'",
"]",
"=",
"$",
"this",
"->",
"pageSummaryRowOptions",
";",
"}",
"}",
"}",
"return",
"strtr",
"(",
"$",
"content",
",",
"[",
"'<tfoot>'",
"=>",
"\"<tfoot>\\n\"",
".",
"parent",
"::",
"generateRows",
"(",
"$",
"this",
"->",
"beforeSummary",
")",
",",
"'</tfoot>'",
"=>",
"parent",
"::",
"generateRows",
"(",
"$",
"this",
"->",
"afterSummary",
")",
".",
"\"\\n</tfoot>\"",
",",
"]",
")",
";",
"}",
"return",
"$",
"content",
";",
"}"
] |
Custom renders the table page summary.
@return string the rendering result.
@throws \yii\base\InvalidConfigException
|
[
"Custom",
"renders",
"the",
"table",
"page",
"summary",
"."
] |
8c91a1737412070775dc3fbee6a89384a67ca2cf
|
https://github.com/pvsaintpe/yii2-grid/blob/8c91a1737412070775dc3fbee6a89384a67ca2cf/widgets/GridView.php#L151-L186
|
22,568
|
nicolasbeauvais/botscout-client
|
src/BotScout.php
|
BotScout.multi
|
public function multi(string $name = null, string $mail = null, string $ip = null)
{
return $this->makeRequest('multi', compact('name', 'mail', 'ip'));
}
|
php
|
public function multi(string $name = null, string $mail = null, string $ip = null)
{
return $this->makeRequest('multi', compact('name', 'mail', 'ip'));
}
|
[
"public",
"function",
"multi",
"(",
"string",
"$",
"name",
"=",
"null",
",",
"string",
"$",
"mail",
"=",
"null",
",",
"string",
"$",
"ip",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"makeRequest",
"(",
"'multi'",
",",
"compact",
"(",
"'name'",
",",
"'mail'",
",",
"'ip'",
")",
")",
";",
"}"
] |
Test matches all parameters at once.
@param string $name
@param string $mail
@param string $ip
@return BotScoutResponse
|
[
"Test",
"matches",
"all",
"parameters",
"at",
"once",
"."
] |
bcc3f607998f02d79fd150f1ffd719c414262e86
|
https://github.com/nicolasbeauvais/botscout-client/blob/bcc3f607998f02d79fd150f1ffd719c414262e86/src/BotScout.php#L34-L37
|
22,569
|
ekuiter/feature-php
|
FeaturePhp/File/LogFile.php
|
LogFile.getContent
|
public function getContent() {
$content = "";
$maxLen = 0;
foreach ($this->logs as $log)
if ($log[0]) {
$name = $log[0]->getFeature()->getName();
$maxLen = strlen($name) > $maxLen ? strlen($name) : $maxLen;
}
foreach ($this->logs as $log)
$content .= sprintf("%-{$maxLen}s | $log[1]\n", $log[0] ? $log[0]->getFeature()->getName() : "");
return new TextFileContent($content);
}
|
php
|
public function getContent() {
$content = "";
$maxLen = 0;
foreach ($this->logs as $log)
if ($log[0]) {
$name = $log[0]->getFeature()->getName();
$maxLen = strlen($name) > $maxLen ? strlen($name) : $maxLen;
}
foreach ($this->logs as $log)
$content .= sprintf("%-{$maxLen}s | $log[1]\n", $log[0] ? $log[0]->getFeature()->getName() : "");
return new TextFileContent($content);
}
|
[
"public",
"function",
"getContent",
"(",
")",
"{",
"$",
"content",
"=",
"\"\"",
";",
"$",
"maxLen",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"logs",
"as",
"$",
"log",
")",
"if",
"(",
"$",
"log",
"[",
"0",
"]",
")",
"{",
"$",
"name",
"=",
"$",
"log",
"[",
"0",
"]",
"->",
"getFeature",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"maxLen",
"=",
"strlen",
"(",
"$",
"name",
")",
">",
"$",
"maxLen",
"?",
"strlen",
"(",
"$",
"name",
")",
":",
"$",
"maxLen",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"logs",
"as",
"$",
"log",
")",
"$",
"content",
".=",
"sprintf",
"(",
"\"%-{$maxLen}s | $log[1]\\n\"",
",",
"$",
"log",
"[",
"0",
"]",
"?",
"$",
"log",
"[",
"0",
"]",
"->",
"getFeature",
"(",
")",
"->",
"getName",
"(",
")",
":",
"\"\"",
")",
";",
"return",
"new",
"TextFileContent",
"(",
"$",
"content",
")",
";",
"}"
] |
Returns the log file's content.
Tabular output is generated.
@return TextFileContent
|
[
"Returns",
"the",
"log",
"file",
"s",
"content",
".",
"Tabular",
"output",
"is",
"generated",
"."
] |
daf4a59098802fedcfd1f1a1d07847fcf2fea7bf
|
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/File/LogFile.php#L44-L58
|
22,570
|
hametuha/wpametu
|
src/WPametu/Tool/BatchProcessor.php
|
BatchProcessor.render_screen
|
public function render_screen(){
$this->register_batches();
?>
<div class="wrap">
<h2><?php $this->_e('Do Batch Actions') ?></h2>
<?php if( $this->batches ): ?>
<form id="batch-form" method="post" action="<?= admin_url('admin-ajax.php') ?>">
<input type="hidden" name="action" value="wpametu_batch">
<?php wp_nonce_field('wpametu_batch') ?>
<input type="hidden" name="page_num" id="page_num" value="1" />
<ol class="batch-container">
<?php
$counter = 0;
foreach( $this->batches as $batch_class ):
$counter++;
/** @var Batch $batch */
$batch = $batch_class::get_instance();
$option = $this->option;
if( isset($option[$batch_class]) ){
$last = $option[$batch_class];
}else{
$last = false;
}
?>
<li>
<input type="radio" id="batch-<?= $counter ?>" name="batch_class" value="<?= esc_attr(get_class($batch)) ?>" />
<label for="batch-<?= $counter ?>">
<span class="dashicons dashicons-yes"></span>
<strong><?= esc_html($batch->title) ?></strong><small>ver <?= esc_html($batch->version) ?></small>
<span class="description"><?= nl2br(esc_html($batch->description)) ?></span>
<?php if( false === $last ): ?>
<span class="executed not-yet"><?php $this->_e('Never executed') ?></span>
<?php else: ?>
<span class="executed"><?= date_i18n(get_option('date_format').' '.get_option('time_format'), $last) ?></span>
<?php endif; ?>
</label>
</li>
<?php endforeach; ?>
</ol>
<?php submit_button($this->__('Execute')) ?>
<div class="loader">
<div><span class="dashicons dashicons-update"></span></div>
</div>
</form>
<div id="batch-result">
<h3><span class="dashicons dashicons-media-code"></span> <?php $this->_e('Console') ?></h3>
<div class="console">
</div>
</div>
<?php else: ?>
<div class="error"><p><?php $this->_e('There is no classes.') ?></p></div>
<?php endif; ?>
</div>
<?php
}
|
php
|
public function render_screen(){
$this->register_batches();
?>
<div class="wrap">
<h2><?php $this->_e('Do Batch Actions') ?></h2>
<?php if( $this->batches ): ?>
<form id="batch-form" method="post" action="<?= admin_url('admin-ajax.php') ?>">
<input type="hidden" name="action" value="wpametu_batch">
<?php wp_nonce_field('wpametu_batch') ?>
<input type="hidden" name="page_num" id="page_num" value="1" />
<ol class="batch-container">
<?php
$counter = 0;
foreach( $this->batches as $batch_class ):
$counter++;
/** @var Batch $batch */
$batch = $batch_class::get_instance();
$option = $this->option;
if( isset($option[$batch_class]) ){
$last = $option[$batch_class];
}else{
$last = false;
}
?>
<li>
<input type="radio" id="batch-<?= $counter ?>" name="batch_class" value="<?= esc_attr(get_class($batch)) ?>" />
<label for="batch-<?= $counter ?>">
<span class="dashicons dashicons-yes"></span>
<strong><?= esc_html($batch->title) ?></strong><small>ver <?= esc_html($batch->version) ?></small>
<span class="description"><?= nl2br(esc_html($batch->description)) ?></span>
<?php if( false === $last ): ?>
<span class="executed not-yet"><?php $this->_e('Never executed') ?></span>
<?php else: ?>
<span class="executed"><?= date_i18n(get_option('date_format').' '.get_option('time_format'), $last) ?></span>
<?php endif; ?>
</label>
</li>
<?php endforeach; ?>
</ol>
<?php submit_button($this->__('Execute')) ?>
<div class="loader">
<div><span class="dashicons dashicons-update"></span></div>
</div>
</form>
<div id="batch-result">
<h3><span class="dashicons dashicons-media-code"></span> <?php $this->_e('Console') ?></h3>
<div class="console">
</div>
</div>
<?php else: ?>
<div class="error"><p><?php $this->_e('There is no classes.') ?></p></div>
<?php endif; ?>
</div>
<?php
}
|
[
"public",
"function",
"render_screen",
"(",
")",
"{",
"$",
"this",
"->",
"register_batches",
"(",
")",
";",
"?>\n\t\t<div class=\"wrap\">\n\t\t\t<h2><?php",
"$",
"this",
"->",
"_e",
"(",
"'Do Batch Actions'",
")",
"?></h2>\n\t\t\t<?php",
"if",
"(",
"$",
"this",
"->",
"batches",
")",
":",
"?>\n\t\t\t<form id=\"batch-form\" method=\"post\" action=\"<?=",
"admin_url",
"(",
"'admin-ajax.php'",
")",
"?>\">\n\t\t\t\t<input type=\"hidden\" name=\"action\" value=\"wpametu_batch\">\n\t\t\t\t<?php",
"wp_nonce_field",
"(",
"'wpametu_batch'",
")",
"?>\n\t\t\t\t<input type=\"hidden\" name=\"page_num\" id=\"page_num\" value=\"1\" />\n\t\t\t\t<ol class=\"batch-container\">\n\t\t\t\t<?php",
"$",
"counter",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"batches",
"as",
"$",
"batch_class",
")",
":",
"$",
"counter",
"++",
";",
"/** @var Batch $batch */",
"$",
"batch",
"=",
"$",
"batch_class",
"::",
"get_instance",
"(",
")",
";",
"$",
"option",
"=",
"$",
"this",
"->",
"option",
";",
"if",
"(",
"isset",
"(",
"$",
"option",
"[",
"$",
"batch_class",
"]",
")",
")",
"{",
"$",
"last",
"=",
"$",
"option",
"[",
"$",
"batch_class",
"]",
";",
"}",
"else",
"{",
"$",
"last",
"=",
"false",
";",
"}",
"?>\n\t\t\t\t<li>\n\t\t\t\t\t<input type=\"radio\" id=\"batch-<?=",
"$",
"counter",
"?>\" name=\"batch_class\" value=\"<?=",
"esc_attr",
"(",
"get_class",
"(",
"$",
"batch",
")",
")",
"?>\" />\n\t\t\t\t\t<label for=\"batch-<?=",
"$",
"counter",
"?>\">\n\t\t\t\t\t\t<span class=\"dashicons dashicons-yes\"></span>\n\t\t\t\t\t\t<strong><?=",
"esc_html",
"(",
"$",
"batch",
"->",
"title",
")",
"?></strong><small>ver <?=",
"esc_html",
"(",
"$",
"batch",
"->",
"version",
")",
"?></small>\n\t\t\t\t\t\t<span class=\"description\"><?=",
"nl2br",
"(",
"esc_html",
"(",
"$",
"batch",
"->",
"description",
")",
")",
"?></span>\n\t\t\t\t\t\t<?php",
"if",
"(",
"false",
"===",
"$",
"last",
")",
":",
"?>\n\t\t\t\t\t\t\t<span class=\"executed not-yet\"><?php",
"$",
"this",
"->",
"_e",
"(",
"'Never executed'",
")",
"?></span>\n\t\t\t\t\t\t<?php",
"else",
":",
"?>\n\t\t\t\t\t\t\t<span class=\"executed\"><?=",
"date_i18n",
"(",
"get_option",
"(",
"'date_format'",
")",
".",
"' '",
".",
"get_option",
"(",
"'time_format'",
")",
",",
"$",
"last",
")",
"?></span>\n\t\t\t\t\t\t<?php",
"endif",
";",
"?>\n\t\t\t\t\t</label>\n\t\t\t\t</li>\n\t\t\t\t<?php",
"endforeach",
";",
"?>\n\t\t\t\t</ol>\n\t\t\t\t<?php",
"submit_button",
"(",
"$",
"this",
"->",
"__",
"(",
"'Execute'",
")",
")",
"?>\n\t\t\t\t<div class=\"loader\">\n\t\t\t\t\t<div><span class=\"dashicons dashicons-update\"></span></div>\n\t\t\t\t</div>\n\t\t\t</form>\n\t\t\t<div id=\"batch-result\">\n\t\t\t\t<h3><span class=\"dashicons dashicons-media-code\"></span> <?php",
"$",
"this",
"->",
"_e",
"(",
"'Console'",
")",
"?></h3>\n\t\t\t\t<div class=\"console\">\n\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t\t<?php",
"else",
":",
"?>\n\t\t\t<div class=\"error\"><p><?php",
"$",
"this",
"->",
"_e",
"(",
"'There is no classes.'",
")",
"?></p></div>\n\t\t\t<?php",
"endif",
";",
"?>\n\t\t</div>\n\t\t<?php",
"}"
] |
Render Admin screen
|
[
"Render",
"Admin",
"screen"
] |
0939373800815a8396291143d2a57967340da5aa
|
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/Tool/BatchProcessor.php#L67-L122
|
22,571
|
hametuha/wpametu
|
src/WPametu/Tool/BatchProcessor.php
|
BatchProcessor.register_batches
|
protected function register_batches(){
static $batch_registered = false;
if( !$batch_registered ){
// Register Batches
/** @var AutoLoader $auto_loader */
$auto_loader = AutoLoader::get_instance();
$root = $auto_loader->namespace_root;
$namespace = $auto_loader->namespace;
if( $namespace && $root && is_dir($root.'/Batches') ){
// Scan directory and find batch children
foreach( scandir($root.'/Batches') as $file ){
if( preg_match('/\.php$/', $file) ){
$class_name = $namespace.'\\Batches\\'.str_replace('.php', '', $file);
if( class_exists($class_name) && $this->is_sub_class_of($class_name, Batch::class) ){
$this->batches[] = $class_name;
}
}
}
}
$batch_registered = true;
}
}
|
php
|
protected function register_batches(){
static $batch_registered = false;
if( !$batch_registered ){
// Register Batches
/** @var AutoLoader $auto_loader */
$auto_loader = AutoLoader::get_instance();
$root = $auto_loader->namespace_root;
$namespace = $auto_loader->namespace;
if( $namespace && $root && is_dir($root.'/Batches') ){
// Scan directory and find batch children
foreach( scandir($root.'/Batches') as $file ){
if( preg_match('/\.php$/', $file) ){
$class_name = $namespace.'\\Batches\\'.str_replace('.php', '', $file);
if( class_exists($class_name) && $this->is_sub_class_of($class_name, Batch::class) ){
$this->batches[] = $class_name;
}
}
}
}
$batch_registered = true;
}
}
|
[
"protected",
"function",
"register_batches",
"(",
")",
"{",
"static",
"$",
"batch_registered",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"batch_registered",
")",
"{",
"// Register Batches",
"/** @var AutoLoader $auto_loader */",
"$",
"auto_loader",
"=",
"AutoLoader",
"::",
"get_instance",
"(",
")",
";",
"$",
"root",
"=",
"$",
"auto_loader",
"->",
"namespace_root",
";",
"$",
"namespace",
"=",
"$",
"auto_loader",
"->",
"namespace",
";",
"if",
"(",
"$",
"namespace",
"&&",
"$",
"root",
"&&",
"is_dir",
"(",
"$",
"root",
".",
"'/Batches'",
")",
")",
"{",
"// Scan directory and find batch children",
"foreach",
"(",
"scandir",
"(",
"$",
"root",
".",
"'/Batches'",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/\\.php$/'",
",",
"$",
"file",
")",
")",
"{",
"$",
"class_name",
"=",
"$",
"namespace",
".",
"'\\\\Batches\\\\'",
".",
"str_replace",
"(",
"'.php'",
",",
"''",
",",
"$",
"file",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class_name",
")",
"&&",
"$",
"this",
"->",
"is_sub_class_of",
"(",
"$",
"class_name",
",",
"Batch",
"::",
"class",
")",
")",
"{",
"$",
"this",
"->",
"batches",
"[",
"]",
"=",
"$",
"class_name",
";",
"}",
"}",
"}",
"}",
"$",
"batch_registered",
"=",
"true",
";",
"}",
"}"
] |
Register Batch classes
|
[
"Register",
"Batch",
"classes"
] |
0939373800815a8396291143d2a57967340da5aa
|
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/Tool/BatchProcessor.php#L144-L165
|
22,572
|
OpenBuildings/monetary
|
src/OpenBuildings/Monetary/CURL.php
|
CURL.request
|
public function request(array $curl_options)
{
$curl = $this->_init($curl_options);
$response = $this->_execute($curl);
// Execute response
if ($response === FALSE)
{
$this->_handle_error($curl);
return FALSE;
}
$this->_close($curl);
return $response;
}
|
php
|
public function request(array $curl_options)
{
$curl = $this->_init($curl_options);
$response = $this->_execute($curl);
// Execute response
if ($response === FALSE)
{
$this->_handle_error($curl);
return FALSE;
}
$this->_close($curl);
return $response;
}
|
[
"public",
"function",
"request",
"(",
"array",
"$",
"curl_options",
")",
"{",
"$",
"curl",
"=",
"$",
"this",
"->",
"_init",
"(",
"$",
"curl_options",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"_execute",
"(",
"$",
"curl",
")",
";",
"// Execute response",
"if",
"(",
"$",
"response",
"===",
"FALSE",
")",
"{",
"$",
"this",
"->",
"_handle_error",
"(",
"$",
"curl",
")",
";",
"return",
"FALSE",
";",
"}",
"$",
"this",
"->",
"_close",
"(",
"$",
"curl",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Perform a cURL request
@param array $curl_options
@return string response of the request
@throws Exception_Source If the remote returns an error.
|
[
"Perform",
"a",
"cURL",
"request"
] |
f7831ab055eaba7105f3f3530506b96de7fedd29
|
https://github.com/OpenBuildings/monetary/blob/f7831ab055eaba7105f3f3530506b96de7fedd29/src/OpenBuildings/Monetary/CURL.php#L18-L34
|
22,573
|
OpenBuildings/monetary
|
src/OpenBuildings/Monetary/CURL.php
|
CURL._init
|
protected function _init(array $curl_options)
{
$options = array(
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_MAXREDIRS => 10
);
$options += $curl_options;
$curl = curl_init();
curl_setopt_array($curl, $options);
return $curl;
}
|
php
|
protected function _init(array $curl_options)
{
$options = array(
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_MAXREDIRS => 10
);
$options += $curl_options;
$curl = curl_init();
curl_setopt_array($curl, $options);
return $curl;
}
|
[
"protected",
"function",
"_init",
"(",
"array",
"$",
"curl_options",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"CURLOPT_SSL_VERIFYPEER",
"=>",
"FALSE",
",",
"CURLOPT_SSL_VERIFYHOST",
"=>",
"FALSE",
",",
"CURLOPT_RETURNTRANSFER",
"=>",
"TRUE",
",",
"CURLOPT_FOLLOWLOCATION",
"=>",
"TRUE",
",",
"CURLOPT_MAXREDIRS",
"=>",
"10",
")",
";",
"$",
"options",
"+=",
"$",
"curl_options",
";",
"$",
"curl",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt_array",
"(",
"$",
"curl",
",",
"$",
"options",
")",
";",
"return",
"$",
"curl",
";",
"}"
] |
Initializes a cURL resource and set options
@param array $curl_options
@return resource cURL resource
@codeCoverageIgnore
|
[
"Initializes",
"a",
"cURL",
"resource",
"and",
"set",
"options"
] |
f7831ab055eaba7105f3f3530506b96de7fedd29
|
https://github.com/OpenBuildings/monetary/blob/f7831ab055eaba7105f3f3530506b96de7fedd29/src/OpenBuildings/Monetary/CURL.php#L42-L59
|
22,574
|
OpenBuildings/monetary
|
src/OpenBuildings/Monetary/CURL.php
|
CURL._handle_error
|
protected function _handle_error($curl)
{
// Get the error code and message
$code = curl_errno($curl);
$error = curl_error($curl);
$this->_close($curl);
throw new Exception_Source(
'Fetching :source_name data failed: :error (:code)',
'remote',
array(
':error' => $error,
':code' => $code
)
);
}
|
php
|
protected function _handle_error($curl)
{
// Get the error code and message
$code = curl_errno($curl);
$error = curl_error($curl);
$this->_close($curl);
throw new Exception_Source(
'Fetching :source_name data failed: :error (:code)',
'remote',
array(
':error' => $error,
':code' => $code
)
);
}
|
[
"protected",
"function",
"_handle_error",
"(",
"$",
"curl",
")",
"{",
"// Get the error code and message",
"$",
"code",
"=",
"curl_errno",
"(",
"$",
"curl",
")",
";",
"$",
"error",
"=",
"curl_error",
"(",
"$",
"curl",
")",
";",
"$",
"this",
"->",
"_close",
"(",
"$",
"curl",
")",
";",
"throw",
"new",
"Exception_Source",
"(",
"'Fetching :source_name data failed: :error (:code)'",
",",
"'remote'",
",",
"array",
"(",
"':error'",
"=>",
"$",
"error",
",",
"':code'",
"=>",
"$",
"code",
")",
")",
";",
"}"
] |
Handle cURL errors
@param resource $curl cURL resource with an error
@throws Exception_Source with the error message and error code
|
[
"Handle",
"cURL",
"errors"
] |
f7831ab055eaba7105f3f3530506b96de7fedd29
|
https://github.com/OpenBuildings/monetary/blob/f7831ab055eaba7105f3f3530506b96de7fedd29/src/OpenBuildings/Monetary/CURL.php#L86-L102
|
22,575
|
sergmoro1/yii2-lookup
|
src/models/Property.php
|
Property.getValues
|
public static function getValues($name, $index = 'code') {
if($property_id = self::getId($name)) {
$a = [];
foreach(Lookup::find()
->select(['position', 'name'])
->where(['property_id' => $property_id])
->orderBy($index)->all() as $item)
$a[$item->$index] = $item->name;
return $a;
} else
return null;
}
|
php
|
public static function getValues($name, $index = 'code') {
if($property_id = self::getId($name)) {
$a = [];
foreach(Lookup::find()
->select(['position', 'name'])
->where(['property_id' => $property_id])
->orderBy($index)->all() as $item)
$a[$item->$index] = $item->name;
return $a;
} else
return null;
}
|
[
"public",
"static",
"function",
"getValues",
"(",
"$",
"name",
",",
"$",
"index",
"=",
"'code'",
")",
"{",
"if",
"(",
"$",
"property_id",
"=",
"self",
"::",
"getId",
"(",
"$",
"name",
")",
")",
"{",
"$",
"a",
"=",
"[",
"]",
";",
"foreach",
"(",
"Lookup",
"::",
"find",
"(",
")",
"->",
"select",
"(",
"[",
"'position'",
",",
"'name'",
"]",
")",
"->",
"where",
"(",
"[",
"'property_id'",
"=>",
"$",
"property_id",
"]",
")",
"->",
"orderBy",
"(",
"$",
"index",
")",
"->",
"all",
"(",
")",
"as",
"$",
"item",
")",
"$",
"a",
"[",
"$",
"item",
"->",
"$",
"index",
"]",
"=",
"$",
"item",
"->",
"name",
";",
"return",
"$",
"a",
";",
"}",
"else",
"return",
"null",
";",
"}"
] |
Get all property values as array with Code or Position as index.
@params string property name
@params string code or position
@return array
|
[
"Get",
"all",
"property",
"values",
"as",
"array",
"with",
"Code",
"or",
"Position",
"as",
"index",
"."
] |
deff08a2612b3c54d313a6c60a74fcaae1193b21
|
https://github.com/sergmoro1/yii2-lookup/blob/deff08a2612b3c54d313a6c60a74fcaae1193b21/src/models/Property.php#L45-L56
|
22,576
|
technote-space/wordpress-plugin-base
|
src/traits/cron.php
|
Cron.set_cron_event
|
private function set_cron_event() {
$interval = $this->get_interval();
if ( $interval > 0 ) {
if ( ! wp_next_scheduled( $this->get_hook_name() ) ) {
if ( $this->is_running_cron_process() ) {
return;
}
wp_schedule_single_event( time() + $interval, $this->get_hook_name() );
}
}
}
|
php
|
private function set_cron_event() {
$interval = $this->get_interval();
if ( $interval > 0 ) {
if ( ! wp_next_scheduled( $this->get_hook_name() ) ) {
if ( $this->is_running_cron_process() ) {
return;
}
wp_schedule_single_event( time() + $interval, $this->get_hook_name() );
}
}
}
|
[
"private",
"function",
"set_cron_event",
"(",
")",
"{",
"$",
"interval",
"=",
"$",
"this",
"->",
"get_interval",
"(",
")",
";",
"if",
"(",
"$",
"interval",
">",
"0",
")",
"{",
"if",
"(",
"!",
"wp_next_scheduled",
"(",
"$",
"this",
"->",
"get_hook_name",
"(",
")",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_running_cron_process",
"(",
")",
")",
"{",
"return",
";",
"}",
"wp_schedule_single_event",
"(",
"time",
"(",
")",
"+",
"$",
"interval",
",",
"$",
"this",
"->",
"get_hook_name",
"(",
")",
")",
";",
"}",
"}",
"}"
] |
set cron event
|
[
"set",
"cron",
"event"
] |
02cfcba358432a2539af07a69d9db00ff7c14eac
|
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/cron.php#L43-L53
|
22,577
|
SporkCode/Spork
|
src/Validator/AuthAdapter.php
|
AuthAdapter.isValid
|
public function isValid($value, array $context = null)
{
$context = (array) $context;
if (!array_key_exists($this->identity, $context) || empty($context[$this->identity])) {
// $this->error(self::IDENTITY_EMPTY);
return false;
}
if (!array_key_exists($this->credential, $context) || empty($context[$this->credential])) {
// $this->error(self::CREDENTIAL_EMPTY);
return false;
}
$authAdapter = $this->auth->getAdapter();
$authAdapter->setIdentity($context[$this->identity]);
$authAdapter->setCredential($context[$this->credential]);
$result = $this->authResult = $this->auth->authenticate();
if (!$result->isValid()) {
$this->error($result->getCode());
return false;
}
return true;
}
|
php
|
public function isValid($value, array $context = null)
{
$context = (array) $context;
if (!array_key_exists($this->identity, $context) || empty($context[$this->identity])) {
// $this->error(self::IDENTITY_EMPTY);
return false;
}
if (!array_key_exists($this->credential, $context) || empty($context[$this->credential])) {
// $this->error(self::CREDENTIAL_EMPTY);
return false;
}
$authAdapter = $this->auth->getAdapter();
$authAdapter->setIdentity($context[$this->identity]);
$authAdapter->setCredential($context[$this->credential]);
$result = $this->authResult = $this->auth->authenticate();
if (!$result->isValid()) {
$this->error($result->getCode());
return false;
}
return true;
}
|
[
"public",
"function",
"isValid",
"(",
"$",
"value",
",",
"array",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"context",
"=",
"(",
"array",
")",
"$",
"context",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"identity",
",",
"$",
"context",
")",
"||",
"empty",
"(",
"$",
"context",
"[",
"$",
"this",
"->",
"identity",
"]",
")",
")",
"{",
"// $this->error(self::IDENTITY_EMPTY);",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"credential",
",",
"$",
"context",
")",
"||",
"empty",
"(",
"$",
"context",
"[",
"$",
"this",
"->",
"credential",
"]",
")",
")",
"{",
"// $this->error(self::CREDENTIAL_EMPTY);",
"return",
"false",
";",
"}",
"$",
"authAdapter",
"=",
"$",
"this",
"->",
"auth",
"->",
"getAdapter",
"(",
")",
";",
"$",
"authAdapter",
"->",
"setIdentity",
"(",
"$",
"context",
"[",
"$",
"this",
"->",
"identity",
"]",
")",
";",
"$",
"authAdapter",
"->",
"setCredential",
"(",
"$",
"context",
"[",
"$",
"this",
"->",
"credential",
"]",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"authResult",
"=",
"$",
"this",
"->",
"auth",
"->",
"authenticate",
"(",
")",
";",
"if",
"(",
"!",
"$",
"result",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"$",
"result",
"->",
"getCode",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Test if authentication is valid
@see \Zend\Validator\ValidatorInterface::isValid()
@param mixed $value
@param array $context
@return boolean
|
[
"Test",
"if",
"authentication",
"is",
"valid"
] |
7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a
|
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Validator/AuthAdapter.php#L150-L176
|
22,578
|
antaresproject/notifications
|
src/Model/NotificationContents.php
|
NotificationContents.fires
|
protected function fires()
{
$className = isset($this->notification->classname) ? snake_case(class_basename($this->notification->classname)) : false;
if (! $className) {
return [];
}
$before = event('notifications:' . $className . '.render.before');
$after = event('notifications:' . $className . '.render.after');
return [
'before' => !empty($before) ? current($before) : '',
'after' => !empty($after) ? current($after) : ''
];
}
|
php
|
protected function fires()
{
$className = isset($this->notification->classname) ? snake_case(class_basename($this->notification->classname)) : false;
if (! $className) {
return [];
}
$before = event('notifications:' . $className . '.render.before');
$after = event('notifications:' . $className . '.render.after');
return [
'before' => !empty($before) ? current($before) : '',
'after' => !empty($after) ? current($after) : ''
];
}
|
[
"protected",
"function",
"fires",
"(",
")",
"{",
"$",
"className",
"=",
"isset",
"(",
"$",
"this",
"->",
"notification",
"->",
"classname",
")",
"?",
"snake_case",
"(",
"class_basename",
"(",
"$",
"this",
"->",
"notification",
"->",
"classname",
")",
")",
":",
"false",
";",
"if",
"(",
"!",
"$",
"className",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"before",
"=",
"event",
"(",
"'notifications:'",
".",
"$",
"className",
".",
"'.render.before'",
")",
";",
"$",
"after",
"=",
"event",
"(",
"'notifications:'",
".",
"$",
"className",
".",
"'.render.after'",
")",
";",
"return",
"[",
"'before'",
"=>",
"!",
"empty",
"(",
"$",
"before",
")",
"?",
"current",
"(",
"$",
"before",
")",
":",
"''",
",",
"'after'",
"=>",
"!",
"empty",
"(",
"$",
"after",
")",
"?",
"current",
"(",
"$",
"after",
")",
":",
"''",
"]",
";",
"}"
] |
fires events for notification template
@return array
|
[
"fires",
"events",
"for",
"notification",
"template"
] |
60de743477b7e9cbb51de66da5fd9461adc9dd8a
|
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Model/NotificationContents.php#L88-L103
|
22,579
|
antaresproject/notifications
|
src/Model/NotificationContents.php
|
NotificationContents.save
|
public function save(array $options = array())
{
$fired = $this->fires();
$content = count($fired)
? str_replace([$fired['before'], $fired['after']], '', $this->content)
: $this->content;
$this->setAttribute('content', $content);
$this->attributes['content'] = $content;
parent::save($options);
}
|
php
|
public function save(array $options = array())
{
$fired = $this->fires();
$content = count($fired)
? str_replace([$fired['before'], $fired['after']], '', $this->content)
: $this->content;
$this->setAttribute('content', $content);
$this->attributes['content'] = $content;
parent::save($options);
}
|
[
"public",
"function",
"save",
"(",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"fired",
"=",
"$",
"this",
"->",
"fires",
"(",
")",
";",
"$",
"content",
"=",
"count",
"(",
"$",
"fired",
")",
"?",
"str_replace",
"(",
"[",
"$",
"fired",
"[",
"'before'",
"]",
",",
"$",
"fired",
"[",
"'after'",
"]",
"]",
",",
"''",
",",
"$",
"this",
"->",
"content",
")",
":",
"$",
"this",
"->",
"content",
";",
"$",
"this",
"->",
"setAttribute",
"(",
"'content'",
",",
"$",
"content",
")",
";",
"$",
"this",
"->",
"attributes",
"[",
"'content'",
"]",
"=",
"$",
"content",
";",
"parent",
"::",
"save",
"(",
"$",
"options",
")",
";",
"}"
] |
saves notification content without data from fired events
@param array $options
|
[
"saves",
"notification",
"content",
"without",
"data",
"from",
"fired",
"events"
] |
60de743477b7e9cbb51de66da5fd9461adc9dd8a
|
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Model/NotificationContents.php#L133-L144
|
22,580
|
kenphp/ken
|
src/Utils/ArrayDot.php
|
ArrayDot.get
|
public function get($key, $defaultValue = null)
{
$keys = explode('.', $key);
$config = $this->_arr;
foreach ($keys as $value) {
if (is_array($config)) {
if (array_key_exists($value, $config)) {
$config = $config[$value];
} else {
return $defaultValue;
}
} else {
return $defaultValue;
}
}
return $config;
}
|
php
|
public function get($key, $defaultValue = null)
{
$keys = explode('.', $key);
$config = $this->_arr;
foreach ($keys as $value) {
if (is_array($config)) {
if (array_key_exists($value, $config)) {
$config = $config[$value];
} else {
return $defaultValue;
}
} else {
return $defaultValue;
}
}
return $config;
}
|
[
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"defaultValue",
"=",
"null",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"_arr",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"value",
",",
"$",
"config",
")",
")",
"{",
"$",
"config",
"=",
"$",
"config",
"[",
"$",
"value",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"defaultValue",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"defaultValue",
";",
"}",
"}",
"return",
"$",
"config",
";",
"}"
] |
Gets config value based on key.
To access a sub-array you can use a dot separated key.
For example, given this configuration array :
array(
'basePath' => 'somepath',
'params' => array(
'somekey' => 'value of key'
)
);
To access the value of 'somekey', you can call the method like this :
echo $config->get('params.somekey');
The code above will print 'value of key' which is the value of
config 'somekey' in the 'params' array.
@param string $key Dot-separated string of key
@param mixed $defaultValue Default value returned when **$key** is not found.
@return mixed Value of config
|
[
"Gets",
"config",
"value",
"based",
"on",
"key",
"."
] |
c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb
|
https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Utils/ArrayDot.php#L58-L76
|
22,581
|
kenphp/ken
|
src/Utils/ArrayDot.php
|
ArrayDot.set
|
public function set($key, $value)
{
$keys = explode('.', $key);
$config = &$this->_arr;
foreach ($keys as $val) {
$config = &$config[$val];
}
$config = $value;
}
|
php
|
public function set($key, $value)
{
$keys = explode('.', $key);
$config = &$this->_arr;
foreach ($keys as $val) {
$config = &$config[$val];
}
$config = $value;
}
|
[
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"config",
"=",
"&",
"$",
"this",
"->",
"_arr",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"val",
")",
"{",
"$",
"config",
"=",
"&",
"$",
"config",
"[",
"$",
"val",
"]",
";",
"}",
"$",
"config",
"=",
"$",
"value",
";",
"}"
] |
Sets config value based on key.
To set a sub-array configuration, you can use a dot separated key.
For example, given this configuration array :
array(
'basePath' => 'somepath',
'params' => array(
'somekey' => 'value of key'
)
);
To set the value of 'somekey' to 'another value of key', you can call the method like this :
$config->set('params.somekey','another value of key');
@param string $key Dot-separated string of key
@param mixed $value
|
[
"Sets",
"config",
"value",
"based",
"on",
"key",
"."
] |
c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb
|
https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Utils/ArrayDot.php#L98-L108
|
22,582
|
kenphp/ken
|
src/Utils/ArrayDot.php
|
ArrayDot.remove
|
public function remove($key)
{
$keys = explode('.', $key);
$cKeys = count($keys);
$config = &$this->_arr;
for ($i = 0; $i < $cKeys; ++$i) {
if ($i === ($cKeys - 1)) {
unset($config[$keys[$i]]);
} elseif (is_array($config)) {
if (array_key_exists($keys[$i], $config)) {
$config = &$config[$keys[$i]];
} else {
return;
}
}
}
}
|
php
|
public function remove($key)
{
$keys = explode('.', $key);
$cKeys = count($keys);
$config = &$this->_arr;
for ($i = 0; $i < $cKeys; ++$i) {
if ($i === ($cKeys - 1)) {
unset($config[$keys[$i]]);
} elseif (is_array($config)) {
if (array_key_exists($keys[$i], $config)) {
$config = &$config[$keys[$i]];
} else {
return;
}
}
}
}
|
[
"public",
"function",
"remove",
"(",
"$",
"key",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"cKeys",
"=",
"count",
"(",
"$",
"keys",
")",
";",
"$",
"config",
"=",
"&",
"$",
"this",
"->",
"_arr",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"cKeys",
";",
"++",
"$",
"i",
")",
"{",
"if",
"(",
"$",
"i",
"===",
"(",
"$",
"cKeys",
"-",
"1",
")",
")",
"{",
"unset",
"(",
"$",
"config",
"[",
"$",
"keys",
"[",
"$",
"i",
"]",
"]",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"keys",
"[",
"$",
"i",
"]",
",",
"$",
"config",
")",
")",
"{",
"$",
"config",
"=",
"&",
"$",
"config",
"[",
"$",
"keys",
"[",
"$",
"i",
"]",
"]",
";",
"}",
"else",
"{",
"return",
";",
"}",
"}",
"}",
"}"
] |
Removes config value based on key.
To unset a sub-array configuration, you can use a dot separated key.
For example, given this configuration array :
array(
'basePath' => 'somepath',
'params' => array(
'somekey' => 'value of key'
)
);
To unset the value of 'somekey', you can call the method like this :
$config->unset('params.somekey');
@param string $key Dot-separated string of key
|
[
"Removes",
"config",
"value",
"based",
"on",
"key",
"."
] |
c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb
|
https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Utils/ArrayDot.php#L129-L146
|
22,583
|
kenphp/ken
|
src/Utils/ArrayDot.php
|
ArrayDot.has
|
public function has($key)
{
$keys = explode('.', $key);
$cKeys = count($keys);
$config = $this->_arr;
for ($i = 0; $i < $cKeys; ++$i) {
if (is_array($config)) {
if (array_key_exists($keys[$i], $config)) {
$config = $config[$keys[$i]];
} else {
return false;
}
} else {
return false;
}
}
return true;
}
|
php
|
public function has($key)
{
$keys = explode('.', $key);
$cKeys = count($keys);
$config = $this->_arr;
for ($i = 0; $i < $cKeys; ++$i) {
if (is_array($config)) {
if (array_key_exists($keys[$i], $config)) {
$config = $config[$keys[$i]];
} else {
return false;
}
} else {
return false;
}
}
return true;
}
|
[
"public",
"function",
"has",
"(",
"$",
"key",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"cKeys",
"=",
"count",
"(",
"$",
"keys",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"_arr",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"cKeys",
";",
"++",
"$",
"i",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"keys",
"[",
"$",
"i",
"]",
",",
"$",
"config",
")",
")",
"{",
"$",
"config",
"=",
"$",
"config",
"[",
"$",
"keys",
"[",
"$",
"i",
"]",
"]",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Checks whether config has a certain key.
@param string $key Dot-separated string of key
@return bool
|
[
"Checks",
"whether",
"config",
"has",
"a",
"certain",
"key",
"."
] |
c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb
|
https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Utils/ArrayDot.php#L155-L174
|
22,584
|
nabab/bbn
|
src/bbn/file/pdf.php
|
pdf.add_fonts
|
public function add_fonts(array $fonts){
if ( !\defined('BBN_LIB_PATH') ){
die('You must define BBN_LIB_PATH!');
}
if ( !is_dir(BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/') ){
die("You don't have the mpdf/mpdf/ttfonts directory.");
}
foreach ($fonts as $f => $fs) {
// add to available fonts array
foreach ( $fs as $i => $v ){
if ( !empty($v) ){
// check if file exists in mpdf/ttfonts directory
if ( !is_file(BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/' . basename($v)) ){
\bbn\file\dir::copy($v, BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/' . basename($v));
}
$fs[$i] = basename($v);
if ( $i === 'R' ){
array_push($this->pdf->available_unifonts, $f);
}
else {
array_push($this->pdf->available_unifonts, $f.$i);
}
}
else {
unset($fs[$i]);
}
}
// add to fontdata array
$this->pdf->fontdata[$f] = $fs;
}
$this->pdf->default_available_fonts = $this->pdf->available_unifonts;
}
|
php
|
public function add_fonts(array $fonts){
if ( !\defined('BBN_LIB_PATH') ){
die('You must define BBN_LIB_PATH!');
}
if ( !is_dir(BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/') ){
die("You don't have the mpdf/mpdf/ttfonts directory.");
}
foreach ($fonts as $f => $fs) {
// add to available fonts array
foreach ( $fs as $i => $v ){
if ( !empty($v) ){
// check if file exists in mpdf/ttfonts directory
if ( !is_file(BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/' . basename($v)) ){
\bbn\file\dir::copy($v, BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/' . basename($v));
}
$fs[$i] = basename($v);
if ( $i === 'R' ){
array_push($this->pdf->available_unifonts, $f);
}
else {
array_push($this->pdf->available_unifonts, $f.$i);
}
}
else {
unset($fs[$i]);
}
}
// add to fontdata array
$this->pdf->fontdata[$f] = $fs;
}
$this->pdf->default_available_fonts = $this->pdf->available_unifonts;
}
|
[
"public",
"function",
"add_fonts",
"(",
"array",
"$",
"fonts",
")",
"{",
"if",
"(",
"!",
"\\",
"defined",
"(",
"'BBN_LIB_PATH'",
")",
")",
"{",
"die",
"(",
"'You must define BBN_LIB_PATH!'",
")",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"BBN_LIB_PATH",
".",
"'mpdf/mpdf/ttfonts/'",
")",
")",
"{",
"die",
"(",
"\"You don't have the mpdf/mpdf/ttfonts directory.\"",
")",
";",
"}",
"foreach",
"(",
"$",
"fonts",
"as",
"$",
"f",
"=>",
"$",
"fs",
")",
"{",
"// add to available fonts array",
"foreach",
"(",
"$",
"fs",
"as",
"$",
"i",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"v",
")",
")",
"{",
"// check if file exists in mpdf/ttfonts directory",
"if",
"(",
"!",
"is_file",
"(",
"BBN_LIB_PATH",
".",
"'mpdf/mpdf/ttfonts/'",
".",
"basename",
"(",
"$",
"v",
")",
")",
")",
"{",
"\\",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"copy",
"(",
"$",
"v",
",",
"BBN_LIB_PATH",
".",
"'mpdf/mpdf/ttfonts/'",
".",
"basename",
"(",
"$",
"v",
")",
")",
";",
"}",
"$",
"fs",
"[",
"$",
"i",
"]",
"=",
"basename",
"(",
"$",
"v",
")",
";",
"if",
"(",
"$",
"i",
"===",
"'R'",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"pdf",
"->",
"available_unifonts",
",",
"$",
"f",
")",
";",
"}",
"else",
"{",
"array_push",
"(",
"$",
"this",
"->",
"pdf",
"->",
"available_unifonts",
",",
"$",
"f",
".",
"$",
"i",
")",
";",
"}",
"}",
"else",
"{",
"unset",
"(",
"$",
"fs",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"// add to fontdata array",
"$",
"this",
"->",
"pdf",
"->",
"fontdata",
"[",
"$",
"f",
"]",
"=",
"$",
"fs",
";",
"}",
"$",
"this",
"->",
"pdf",
"->",
"default_available_fonts",
"=",
"$",
"this",
"->",
"pdf",
"->",
"available_unifonts",
";",
"}"
] |
Adds custom fonts
$pdf->add_fonts([
'dawningofanewday' => [
'R' => BBN_DATA_PATH.'files/DawningofaNewDay.ttf'
]
]);
@param array $fonts
|
[
"Adds",
"custom",
"fonts"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/pdf.php#L239-L270
|
22,585
|
cirrusidentity/simplesamlphp-test-utils
|
src/SanityChecker.php
|
SanityChecker.confirmAspectMockConfigured
|
static public function confirmAspectMockConfigured() {
// Ensure mocks are configured for SSP classes
$httpDouble = test::double('SimpleSAML\Utils\HTTP', [
'getAcceptLanguage' => ['some-lang']
]);
if ( ['some-lang'] !== \SimpleSAML\Utils\HTTP::getAcceptLanguage()) {
throw new \Exception("Aspect mock does not seem to be configured");
}
// You can also validate the that a method was called.
// $httpDouble->verifyInvokedOnce('getAcceptLanguage');
return $httpDouble;
}
|
php
|
static public function confirmAspectMockConfigured() {
// Ensure mocks are configured for SSP classes
$httpDouble = test::double('SimpleSAML\Utils\HTTP', [
'getAcceptLanguage' => ['some-lang']
]);
if ( ['some-lang'] !== \SimpleSAML\Utils\HTTP::getAcceptLanguage()) {
throw new \Exception("Aspect mock does not seem to be configured");
}
// You can also validate the that a method was called.
// $httpDouble->verifyInvokedOnce('getAcceptLanguage');
return $httpDouble;
}
|
[
"static",
"public",
"function",
"confirmAspectMockConfigured",
"(",
")",
"{",
"// Ensure mocks are configured for SSP classes",
"$",
"httpDouble",
"=",
"test",
"::",
"double",
"(",
"'SimpleSAML\\Utils\\HTTP'",
",",
"[",
"'getAcceptLanguage'",
"=>",
"[",
"'some-lang'",
"]",
"]",
")",
";",
"if",
"(",
"[",
"'some-lang'",
"]",
"!==",
"\\",
"SimpleSAML",
"\\",
"Utils",
"\\",
"HTTP",
"::",
"getAcceptLanguage",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Aspect mock does not seem to be configured\"",
")",
";",
"}",
"// You can also validate the that a method was called.",
"// $httpDouble->verifyInvokedOnce('getAcceptLanguage');",
"return",
"$",
"httpDouble",
";",
"}"
] |
Checks that AspectMock is configured and can override HTTP Util methods
@return \AspectMock\Proxy\ClassProxy|\AspectMock\Proxy\InstanceProxy|\AspectMock\Proxy\Verifier
@throws \Exception
|
[
"Checks",
"that",
"AspectMock",
"is",
"configured",
"and",
"can",
"override",
"HTTP",
"Util",
"methods"
] |
79150efb8bca89c180b604dc1d6194f819ebe2b2
|
https://github.com/cirrusidentity/simplesamlphp-test-utils/blob/79150efb8bca89c180b604dc1d6194f819ebe2b2/src/SanityChecker.php#L18-L30
|
22,586
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Database/src/handlers/mssql.php
|
ezcDbHandlerMssql.setupConnection
|
private function setupConnection()
{
$requiredMode = $this->options->quoteIdentifier;
if ( $requiredMode == ezcDbMssqlOptions::QUOTES_GUESS )
{
$result = parent::query( "SELECT sessionproperty('QUOTED_IDENTIFIER')" );
$rows = $result->fetchAll();
$mode = (int)$rows[0][0];
if ( $mode == 0 )
{
$this->identifierQuoteChars = array( 'start' => '[', 'end' => ']' );
}
else
{
$this->identifierQuoteChars = array( 'start' => '"', 'end' => '"' );
}
}
else if ( $requiredMode == ezcDbMssqlOptions::QUOTES_COMPLIANT )
{
parent::exec( 'SET QUOTED_IDENTIFIER ON' );
$this->identifierQuoteChars = array( 'start' => '"', 'end' => '"' );
}
else if ( $requiredMode == ezcDbMssqlOptions::QUOTES_LEGACY )
{
parent::exec( 'SET QUOTED_IDENTIFIER OFF' );
$this->identifierQuoteChars = array( 'start' => '[', 'end' => ']' );
}
}
|
php
|
private function setupConnection()
{
$requiredMode = $this->options->quoteIdentifier;
if ( $requiredMode == ezcDbMssqlOptions::QUOTES_GUESS )
{
$result = parent::query( "SELECT sessionproperty('QUOTED_IDENTIFIER')" );
$rows = $result->fetchAll();
$mode = (int)$rows[0][0];
if ( $mode == 0 )
{
$this->identifierQuoteChars = array( 'start' => '[', 'end' => ']' );
}
else
{
$this->identifierQuoteChars = array( 'start' => '"', 'end' => '"' );
}
}
else if ( $requiredMode == ezcDbMssqlOptions::QUOTES_COMPLIANT )
{
parent::exec( 'SET QUOTED_IDENTIFIER ON' );
$this->identifierQuoteChars = array( 'start' => '"', 'end' => '"' );
}
else if ( $requiredMode == ezcDbMssqlOptions::QUOTES_LEGACY )
{
parent::exec( 'SET QUOTED_IDENTIFIER OFF' );
$this->identifierQuoteChars = array( 'start' => '[', 'end' => ']' );
}
}
|
[
"private",
"function",
"setupConnection",
"(",
")",
"{",
"$",
"requiredMode",
"=",
"$",
"this",
"->",
"options",
"->",
"quoteIdentifier",
";",
"if",
"(",
"$",
"requiredMode",
"==",
"ezcDbMssqlOptions",
"::",
"QUOTES_GUESS",
")",
"{",
"$",
"result",
"=",
"parent",
"::",
"query",
"(",
"\"SELECT sessionproperty('QUOTED_IDENTIFIER')\"",
")",
";",
"$",
"rows",
"=",
"$",
"result",
"->",
"fetchAll",
"(",
")",
";",
"$",
"mode",
"=",
"(",
"int",
")",
"$",
"rows",
"[",
"0",
"]",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"mode",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"identifierQuoteChars",
"=",
"array",
"(",
"'start'",
"=>",
"'['",
",",
"'end'",
"=>",
"']'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"identifierQuoteChars",
"=",
"array",
"(",
"'start'",
"=>",
"'\"'",
",",
"'end'",
"=>",
"'\"'",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"requiredMode",
"==",
"ezcDbMssqlOptions",
"::",
"QUOTES_COMPLIANT",
")",
"{",
"parent",
"::",
"exec",
"(",
"'SET QUOTED_IDENTIFIER ON'",
")",
";",
"$",
"this",
"->",
"identifierQuoteChars",
"=",
"array",
"(",
"'start'",
"=>",
"'\"'",
",",
"'end'",
"=>",
"'\"'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"requiredMode",
"==",
"ezcDbMssqlOptions",
"::",
"QUOTES_LEGACY",
")",
"{",
"parent",
"::",
"exec",
"(",
"'SET QUOTED_IDENTIFIER OFF'",
")",
";",
"$",
"this",
"->",
"identifierQuoteChars",
"=",
"array",
"(",
"'start'",
"=>",
"'['",
",",
"'end'",
"=>",
"']'",
")",
";",
"}",
"}"
] |
Sets up opened connection according to options.
|
[
"Sets",
"up",
"opened",
"connection",
"according",
"to",
"options",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/handlers/mssql.php#L92-L119
|
22,587
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/dwoo/Dwoo/Loader.php
|
Dwoo_Loader.rebuildClassPathCache
|
protected function rebuildClassPathCache($path, $cacheFile)
{
if ($cacheFile!==false) {
$tmp = $this->classPath;
$this->classPath = array();
}
// iterates over all files/folders
$list = glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*');
if (is_array($list)) {
foreach ($list as $f) {
if (is_dir($f)) {
$this->rebuildClassPathCache($f, false);
} else {
$this->classPath[str_replace(array('function.','block.','modifier.','outputfilter.','filter.','prefilter.','postfilter.','pre.','post.','output.','shared.','helper.'), '', basename($f, '.php'))] = $f;
}
}
}
// save in file if it's the first call (not recursed)
if ($cacheFile!==false) {
if (!file_put_contents($cacheFile, serialize($this->classPath))) {
throw new Dwoo_Exception('Could not write into '.$cacheFile.', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()');
}
$this->classPath += $tmp;
}
}
|
php
|
protected function rebuildClassPathCache($path, $cacheFile)
{
if ($cacheFile!==false) {
$tmp = $this->classPath;
$this->classPath = array();
}
// iterates over all files/folders
$list = glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*');
if (is_array($list)) {
foreach ($list as $f) {
if (is_dir($f)) {
$this->rebuildClassPathCache($f, false);
} else {
$this->classPath[str_replace(array('function.','block.','modifier.','outputfilter.','filter.','prefilter.','postfilter.','pre.','post.','output.','shared.','helper.'), '', basename($f, '.php'))] = $f;
}
}
}
// save in file if it's the first call (not recursed)
if ($cacheFile!==false) {
if (!file_put_contents($cacheFile, serialize($this->classPath))) {
throw new Dwoo_Exception('Could not write into '.$cacheFile.', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()');
}
$this->classPath += $tmp;
}
}
|
[
"protected",
"function",
"rebuildClassPathCache",
"(",
"$",
"path",
",",
"$",
"cacheFile",
")",
"{",
"if",
"(",
"$",
"cacheFile",
"!==",
"false",
")",
"{",
"$",
"tmp",
"=",
"$",
"this",
"->",
"classPath",
";",
"$",
"this",
"->",
"classPath",
"=",
"array",
"(",
")",
";",
"}",
"// iterates over all files/folders",
"$",
"list",
"=",
"glob",
"(",
"rtrim",
"(",
"$",
"path",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'*'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"list",
")",
")",
"{",
"foreach",
"(",
"$",
"list",
"as",
"$",
"f",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"f",
")",
")",
"{",
"$",
"this",
"->",
"rebuildClassPathCache",
"(",
"$",
"f",
",",
"false",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"classPath",
"[",
"str_replace",
"(",
"array",
"(",
"'function.'",
",",
"'block.'",
",",
"'modifier.'",
",",
"'outputfilter.'",
",",
"'filter.'",
",",
"'prefilter.'",
",",
"'postfilter.'",
",",
"'pre.'",
",",
"'post.'",
",",
"'output.'",
",",
"'shared.'",
",",
"'helper.'",
")",
",",
"''",
",",
"basename",
"(",
"$",
"f",
",",
"'.php'",
")",
")",
"]",
"=",
"$",
"f",
";",
"}",
"}",
"}",
"// save in file if it's the first call (not recursed)",
"if",
"(",
"$",
"cacheFile",
"!==",
"false",
")",
"{",
"if",
"(",
"!",
"file_put_contents",
"(",
"$",
"cacheFile",
",",
"serialize",
"(",
"$",
"this",
"->",
"classPath",
")",
")",
")",
"{",
"throw",
"new",
"Dwoo_Exception",
"(",
"'Could not write into '",
".",
"$",
"cacheFile",
".",
"', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()'",
")",
";",
"}",
"$",
"this",
"->",
"classPath",
"+=",
"$",
"tmp",
";",
"}",
"}"
] |
rebuilds class paths, scans the given directory recursively and saves all paths in the given file
@param string $path the plugin path to scan
@param string $cacheFile the file where to store the plugin paths cache, it will be overwritten
|
[
"rebuilds",
"class",
"paths",
"scans",
"the",
"given",
"directory",
"recursively",
"and",
"saves",
"all",
"paths",
"in",
"the",
"given",
"file"
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Loader.php#L66-L92
|
22,588
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/dwoo/Dwoo/Loader.php
|
Dwoo_Loader.loadPlugin
|
public function loadPlugin($class, $forceRehash = true)
{
// a new class was added or the include failed so we rebuild the cache
if (!isset($this->classPath[$class]) || !(include $this->classPath[$class])) {
if ($forceRehash) {
$this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir . 'classpath.cache.d'.Dwoo::RELEASE_TAG.'.php');
foreach ($this->paths as $path=>$file) {
$this->rebuildClassPathCache($path, $file);
}
if (isset($this->classPath[$class])) {
include $this->classPath[$class];
} else {
throw new Dwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE);
}
} else {
throw new Dwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE);
}
}
}
|
php
|
public function loadPlugin($class, $forceRehash = true)
{
// a new class was added or the include failed so we rebuild the cache
if (!isset($this->classPath[$class]) || !(include $this->classPath[$class])) {
if ($forceRehash) {
$this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir . 'classpath.cache.d'.Dwoo::RELEASE_TAG.'.php');
foreach ($this->paths as $path=>$file) {
$this->rebuildClassPathCache($path, $file);
}
if (isset($this->classPath[$class])) {
include $this->classPath[$class];
} else {
throw new Dwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE);
}
} else {
throw new Dwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE);
}
}
}
|
[
"public",
"function",
"loadPlugin",
"(",
"$",
"class",
",",
"$",
"forceRehash",
"=",
"true",
")",
"{",
"// a new class was added or the include failed so we rebuild the cache",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"classPath",
"[",
"$",
"class",
"]",
")",
"||",
"!",
"(",
"include",
"$",
"this",
"->",
"classPath",
"[",
"$",
"class",
"]",
")",
")",
"{",
"if",
"(",
"$",
"forceRehash",
")",
"{",
"$",
"this",
"->",
"rebuildClassPathCache",
"(",
"$",
"this",
"->",
"corePluginDir",
",",
"$",
"this",
"->",
"cacheDir",
".",
"'classpath.cache.d'",
".",
"Dwoo",
"::",
"RELEASE_TAG",
".",
"'.php'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"paths",
"as",
"$",
"path",
"=>",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"rebuildClassPathCache",
"(",
"$",
"path",
",",
"$",
"file",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"classPath",
"[",
"$",
"class",
"]",
")",
")",
"{",
"include",
"$",
"this",
"->",
"classPath",
"[",
"$",
"class",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"Dwoo_Exception",
"(",
"'Plugin <em>'",
".",
"$",
"class",
".",
"'</em> can not be found, maybe you forgot to bind it if it\\'s a custom plugin ?'",
",",
"E_USER_NOTICE",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"Dwoo_Exception",
"(",
"'Plugin <em>'",
".",
"$",
"class",
".",
"'</em> can not be found, maybe you forgot to bind it if it\\'s a custom plugin ?'",
",",
"E_USER_NOTICE",
")",
";",
"}",
"}",
"}"
] |
loads a plugin file
@param string $class the plugin name, without the Dwoo_Plugin_ prefix
@param bool $forceRehash if true, the class path caches will be rebuilt if the plugin is not found, in case it has just been added, defaults to true
|
[
"loads",
"a",
"plugin",
"file"
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Loader.php#L100-L118
|
22,589
|
ekuiter/feature-php
|
FeaturePhp/File/TemplateFile.php
|
TemplateFile.render
|
public static function render($source, $rules = array(), $directory = null) {
if (!$directory)
$directory = getcwd();
return self::fromSpecification(
fphp\Specification\TemplateSpecification::fromArrayAndSettings(
array(
"source" => $source,
"rules" => $rules
), fphp\Settings::inDirectory($directory))
)->getContent()->getSummary();
}
|
php
|
public static function render($source, $rules = array(), $directory = null) {
if (!$directory)
$directory = getcwd();
return self::fromSpecification(
fphp\Specification\TemplateSpecification::fromArrayAndSettings(
array(
"source" => $source,
"rules" => $rules
), fphp\Settings::inDirectory($directory))
)->getContent()->getSummary();
}
|
[
"public",
"static",
"function",
"render",
"(",
"$",
"source",
",",
"$",
"rules",
"=",
"array",
"(",
")",
",",
"$",
"directory",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"directory",
")",
"$",
"directory",
"=",
"getcwd",
"(",
")",
";",
"return",
"self",
"::",
"fromSpecification",
"(",
"fphp",
"\\",
"Specification",
"\\",
"TemplateSpecification",
"::",
"fromArrayAndSettings",
"(",
"array",
"(",
"\"source\"",
"=>",
"$",
"source",
",",
"\"rules\"",
"=>",
"$",
"rules",
")",
",",
"fphp",
"\\",
"Settings",
"::",
"inDirectory",
"(",
"$",
"directory",
")",
")",
")",
"->",
"getContent",
"(",
")",
"->",
"getSummary",
"(",
")",
";",
"}"
] |
A quick way to directly render a template file with some replacement rules.
@param string $source
@param array[] $rules
@param string $directory
@return string
|
[
"A",
"quick",
"way",
"to",
"directly",
"render",
"a",
"template",
"file",
"with",
"some",
"replacement",
"rules",
"."
] |
daf4a59098802fedcfd1f1a1d07847fcf2fea7bf
|
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/File/TemplateFile.php#L52-L63
|
22,590
|
ekuiter/feature-php
|
FeaturePhp/File/TemplateFile.php
|
TemplateFile.getContent
|
public function getContent() {
$content = file_get_contents($this->fileSource);
foreach ($this->rules as $rule)
$content = $rule->apply($content);
return new TextFileContent($content);
}
|
php
|
public function getContent() {
$content = file_get_contents($this->fileSource);
foreach ($this->rules as $rule)
$content = $rule->apply($content);
return new TextFileContent($content);
}
|
[
"public",
"function",
"getContent",
"(",
")",
"{",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"fileSource",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"rule",
")",
"$",
"content",
"=",
"$",
"rule",
"->",
"apply",
"(",
"$",
"content",
")",
";",
"return",
"new",
"TextFileContent",
"(",
"$",
"content",
")",
";",
"}"
] |
Returns the template file's content.
The content consists of the file content with every rule applied.
@return TextFileContent
|
[
"Returns",
"the",
"template",
"file",
"s",
"content",
".",
"The",
"content",
"consists",
"of",
"the",
"file",
"content",
"with",
"every",
"rule",
"applied",
"."
] |
daf4a59098802fedcfd1f1a1d07847fcf2fea7bf
|
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/File/TemplateFile.php#L100-L105
|
22,591
|
Smile-SA/EzUICronBundle
|
Controller/CronsController.php
|
CronsController.listAction
|
public function listAction()
{
$this->performAccessChecks();
$crons = $this->cronService->getCrons();
return $this->render('SmileEzUICronBundle:cron:tab/crons/list.html.twig', [
'datas' => $crons
]);
}
|
php
|
public function listAction()
{
$this->performAccessChecks();
$crons = $this->cronService->getCrons();
return $this->render('SmileEzUICronBundle:cron:tab/crons/list.html.twig', [
'datas' => $crons
]);
}
|
[
"public",
"function",
"listAction",
"(",
")",
"{",
"$",
"this",
"->",
"performAccessChecks",
"(",
")",
";",
"$",
"crons",
"=",
"$",
"this",
"->",
"cronService",
"->",
"getCrons",
"(",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'SmileEzUICronBundle:cron:tab/crons/list.html.twig'",
",",
"[",
"'datas'",
"=>",
"$",
"crons",
"]",
")",
";",
"}"
] |
List crons definition
@return Response
|
[
"List",
"crons",
"definition"
] |
c62fc6a3ab0b39e3f911742d9affe4aade90cf66
|
https://github.com/Smile-SA/EzUICronBundle/blob/c62fc6a3ab0b39e3f911742d9affe4aade90cf66/Controller/CronsController.php#L44-L53
|
22,592
|
Smile-SA/EzUICronBundle
|
Controller/CronsController.php
|
CronsController.editAction
|
public function editAction(Request $request, $type, $alias)
{
$this->performAccessChecks();
$value = $request->get('value');
$response = new Response();
try {
$this->cronService->updateCron($alias, $type, $value);
$response->setStatusCode(
200,
$this->translator->trans('cron.edit.done', ['%type%' => $type, '%alias%' => $alias], 'smileezcron')
);
} catch (NotFoundException $e) {
$response->setStatusCode(500, $e->getMessage());
} catch (InvalidArgumentException $e) {
$response->setStatusCode(500, $e->getMessage());
}
return $response;
}
|
php
|
public function editAction(Request $request, $type, $alias)
{
$this->performAccessChecks();
$value = $request->get('value');
$response = new Response();
try {
$this->cronService->updateCron($alias, $type, $value);
$response->setStatusCode(
200,
$this->translator->trans('cron.edit.done', ['%type%' => $type, '%alias%' => $alias], 'smileezcron')
);
} catch (NotFoundException $e) {
$response->setStatusCode(500, $e->getMessage());
} catch (InvalidArgumentException $e) {
$response->setStatusCode(500, $e->getMessage());
}
return $response;
}
|
[
"public",
"function",
"editAction",
"(",
"Request",
"$",
"request",
",",
"$",
"type",
",",
"$",
"alias",
")",
"{",
"$",
"this",
"->",
"performAccessChecks",
"(",
")",
";",
"$",
"value",
"=",
"$",
"request",
"->",
"get",
"(",
"'value'",
")",
";",
"$",
"response",
"=",
"new",
"Response",
"(",
")",
";",
"try",
"{",
"$",
"this",
"->",
"cronService",
"->",
"updateCron",
"(",
"$",
"alias",
",",
"$",
"type",
",",
"$",
"value",
")",
";",
"$",
"response",
"->",
"setStatusCode",
"(",
"200",
",",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'cron.edit.done'",
",",
"[",
"'%type%'",
"=>",
"$",
"type",
",",
"'%alias%'",
"=>",
"$",
"alias",
"]",
",",
"'smileezcron'",
")",
")",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"e",
")",
"{",
"$",
"response",
"->",
"setStatusCode",
"(",
"500",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"response",
"->",
"setStatusCode",
"(",
"500",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] |
Edition cron definition
@param Request $request
@param string $type cron property identifier
@param string $alias cron alias identifier
@return Response
|
[
"Edition",
"cron",
"definition"
] |
c62fc6a3ab0b39e3f911742d9affe4aade90cf66
|
https://github.com/Smile-SA/EzUICronBundle/blob/c62fc6a3ab0b39e3f911742d9affe4aade90cf66/Controller/CronsController.php#L63-L84
|
22,593
|
codezero-be/laravel-localizer
|
src/Localizer.php
|
Localizer.detect
|
public function detect()
{
foreach ($this->detectors as $detector) {
$locales = (array) $this->getInstance($detector)->detect();
foreach ($locales as $locale) {
if ($this->isSupportedLocale($locale)) {
return $locale;
}
}
}
return false;
}
|
php
|
public function detect()
{
foreach ($this->detectors as $detector) {
$locales = (array) $this->getInstance($detector)->detect();
foreach ($locales as $locale) {
if ($this->isSupportedLocale($locale)) {
return $locale;
}
}
}
return false;
}
|
[
"public",
"function",
"detect",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"detectors",
"as",
"$",
"detector",
")",
"{",
"$",
"locales",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"getInstance",
"(",
"$",
"detector",
")",
"->",
"detect",
"(",
")",
";",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"locale",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSupportedLocale",
"(",
"$",
"locale",
")",
")",
"{",
"return",
"$",
"locale",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Detect any supported locale and return the first match.
@return string|false
|
[
"Detect",
"any",
"supported",
"locale",
"and",
"return",
"the",
"first",
"match",
"."
] |
812692796a73bd38fc205404d8ef90df5bfa0d83
|
https://github.com/codezero-be/laravel-localizer/blob/812692796a73bd38fc205404d8ef90df5bfa0d83/src/Localizer.php#L49-L62
|
22,594
|
josh-taylor/migrations-generator
|
src/Generator.php
|
Generator.tables
|
public function tables()
{
$schema = $this->db->connection()
->getDoctrineConnection()
->getSchemaManager();
$tables = $schema->listTableNames();
foreach ($tables as $table) {
$columns = $this->describer->describe($table);
yield compact('table', 'columns');
}
}
|
php
|
public function tables()
{
$schema = $this->db->connection()
->getDoctrineConnection()
->getSchemaManager();
$tables = $schema->listTableNames();
foreach ($tables as $table) {
$columns = $this->describer->describe($table);
yield compact('table', 'columns');
}
}
|
[
"public",
"function",
"tables",
"(",
")",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"db",
"->",
"connection",
"(",
")",
"->",
"getDoctrineConnection",
"(",
")",
"->",
"getSchemaManager",
"(",
")",
";",
"$",
"tables",
"=",
"$",
"schema",
"->",
"listTableNames",
"(",
")",
";",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"table",
")",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"describer",
"->",
"describe",
"(",
"$",
"table",
")",
";",
"yield",
"compact",
"(",
"'table'",
",",
"'columns'",
")",
";",
"}",
"}"
] |
Return a description for each table.
@return \Generator
|
[
"Return",
"a",
"description",
"for",
"each",
"table",
"."
] |
bb6edc78773d11491881f12265a658bf058cb218
|
https://github.com/josh-taylor/migrations-generator/blob/bb6edc78773d11491881f12265a658bf058cb218/src/Generator.php#L36-L49
|
22,595
|
inhere/php-librarys
|
src/Utils/LiteLogger.php
|
LiteLogger.flush
|
public function flush()
{
if ($this->recordSize === 0) {
return;
}
$str = '';
foreach ($this->records as $record) {
$str .= $this->recordFormat($record);
}
$this->clear();
$this->write($str);
}
|
php
|
public function flush()
{
if ($this->recordSize === 0) {
return;
}
$str = '';
foreach ($this->records as $record) {
$str .= $this->recordFormat($record);
}
$this->clear();
$this->write($str);
}
|
[
"public",
"function",
"flush",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"recordSize",
"===",
"0",
")",
"{",
"return",
";",
"}",
"$",
"str",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"records",
"as",
"$",
"record",
")",
"{",
"$",
"str",
".=",
"$",
"this",
"->",
"recordFormat",
"(",
"$",
"record",
")",
";",
"}",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"write",
"(",
"$",
"str",
")",
";",
"}"
] |
flush data to file.
@throws \Inhere\Exceptions\FileSystemException
|
[
"flush",
"data",
"to",
"file",
"."
] |
e6ca598685469794f310e3ab0e2bc19519cd0ae6
|
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Utils/LiteLogger.php#L330-L343
|
22,596
|
inhere/php-librarys
|
src/Utils/LiteLogger.php
|
LiteLogger.getLogPath
|
public function getLogPath()
{
if (!$this->basePath) {
throw new \InvalidArgumentException('The property basePath is required.');
}
return $this->getBasePath() . '/' . ($this->subFolder ? $this->subFolder . '/' : '');
}
|
php
|
public function getLogPath()
{
if (!$this->basePath) {
throw new \InvalidArgumentException('The property basePath is required.');
}
return $this->getBasePath() . '/' . ($this->subFolder ? $this->subFolder . '/' : '');
}
|
[
"public",
"function",
"getLogPath",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"basePath",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The property basePath is required.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getBasePath",
"(",
")",
".",
"'/'",
".",
"(",
"$",
"this",
"->",
"subFolder",
"?",
"$",
"this",
"->",
"subFolder",
".",
"'/'",
":",
"''",
")",
";",
"}"
] |
get log path
@return string
@throws \InvalidArgumentException
|
[
"get",
"log",
"path"
] |
e6ca598685469794f310e3ab0e2bc19519cd0ae6
|
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Utils/LiteLogger.php#L449-L456
|
22,597
|
AbuseIO/parser-ipechelon
|
src/Ipechelon.php
|
Ipechelon.saveIncident
|
private function saveIncident($report_xml)
{
if (!empty($report_xml) && $report_xml = simplexml_load_string($report_xml)) {
$this->feedName = 'default';
// If feed is known and enabled, validate data and save report
if ($this->isKnownFeed() && $this->isEnabledFeed()) {
// Create a corrected array
$report_raw = json_decode(json_encode($report_xml), true);
// Sanity check
$report = $this->applyFilters($report_raw['Source']);
if ($this->hasRequiredFields($report) === true) {
// incident has all requirements met, add!
$incident = new Incident();
$incident->source = config("{$this->configBase}.parser.name");
$incident->source_id = false;
$incident->ip = $report['IP_Address'];
$incident->domain = false;
$incident->class = config("{$this->configBase}.feeds.{$this->feedName}.class");
$incident->type = config("{$this->configBase}.feeds.{$this->feedName}.type");
$incident->timestamp = strtotime($report['TimeStamp']);
$incident->information = json_encode($report_raw);
$this->incidents[] = $incident;
}
}
}
}
|
php
|
private function saveIncident($report_xml)
{
if (!empty($report_xml) && $report_xml = simplexml_load_string($report_xml)) {
$this->feedName = 'default';
// If feed is known and enabled, validate data and save report
if ($this->isKnownFeed() && $this->isEnabledFeed()) {
// Create a corrected array
$report_raw = json_decode(json_encode($report_xml), true);
// Sanity check
$report = $this->applyFilters($report_raw['Source']);
if ($this->hasRequiredFields($report) === true) {
// incident has all requirements met, add!
$incident = new Incident();
$incident->source = config("{$this->configBase}.parser.name");
$incident->source_id = false;
$incident->ip = $report['IP_Address'];
$incident->domain = false;
$incident->class = config("{$this->configBase}.feeds.{$this->feedName}.class");
$incident->type = config("{$this->configBase}.feeds.{$this->feedName}.type");
$incident->timestamp = strtotime($report['TimeStamp']);
$incident->information = json_encode($report_raw);
$this->incidents[] = $incident;
}
}
}
}
|
[
"private",
"function",
"saveIncident",
"(",
"$",
"report_xml",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"report_xml",
")",
"&&",
"$",
"report_xml",
"=",
"simplexml_load_string",
"(",
"$",
"report_xml",
")",
")",
"{",
"$",
"this",
"->",
"feedName",
"=",
"'default'",
";",
"// If feed is known and enabled, validate data and save report",
"if",
"(",
"$",
"this",
"->",
"isKnownFeed",
"(",
")",
"&&",
"$",
"this",
"->",
"isEnabledFeed",
"(",
")",
")",
"{",
"// Create a corrected array",
"$",
"report_raw",
"=",
"json_decode",
"(",
"json_encode",
"(",
"$",
"report_xml",
")",
",",
"true",
")",
";",
"// Sanity check",
"$",
"report",
"=",
"$",
"this",
"->",
"applyFilters",
"(",
"$",
"report_raw",
"[",
"'Source'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasRequiredFields",
"(",
"$",
"report",
")",
"===",
"true",
")",
"{",
"// incident has all requirements met, add!",
"$",
"incident",
"=",
"new",
"Incident",
"(",
")",
";",
"$",
"incident",
"->",
"source",
"=",
"config",
"(",
"\"{$this->configBase}.parser.name\"",
")",
";",
"$",
"incident",
"->",
"source_id",
"=",
"false",
";",
"$",
"incident",
"->",
"ip",
"=",
"$",
"report",
"[",
"'IP_Address'",
"]",
";",
"$",
"incident",
"->",
"domain",
"=",
"false",
";",
"$",
"incident",
"->",
"class",
"=",
"config",
"(",
"\"{$this->configBase}.feeds.{$this->feedName}.class\"",
")",
";",
"$",
"incident",
"->",
"type",
"=",
"config",
"(",
"\"{$this->configBase}.feeds.{$this->feedName}.type\"",
")",
";",
"$",
"incident",
"->",
"timestamp",
"=",
"strtotime",
"(",
"$",
"report",
"[",
"'TimeStamp'",
"]",
")",
";",
"$",
"incident",
"->",
"information",
"=",
"json_encode",
"(",
"$",
"report_raw",
")",
";",
"$",
"this",
"->",
"incidents",
"[",
"]",
"=",
"$",
"incident",
";",
"}",
"}",
"}",
"}"
] |
Uses the XML to create incidents
@param string $report_xml
|
[
"Uses",
"the",
"XML",
"to",
"create",
"incidents"
] |
41154a5aa88f7762db0941edca95363fac9f6886
|
https://github.com/AbuseIO/parser-ipechelon/blob/41154a5aa88f7762db0941edca95363fac9f6886/src/Ipechelon.php#L77-L104
|
22,598
|
phpgears/dto
|
src/PayloadBehaviour.php
|
PayloadBehaviour.setPayload
|
private function setPayload(array $parameters): void
{
$this->payload = [];
foreach ($parameters as $parameter => $value) {
$this->setPayloadParameter($parameter, $value);
}
}
|
php
|
private function setPayload(array $parameters): void
{
$this->payload = [];
foreach ($parameters as $parameter => $value) {
$this->setPayloadParameter($parameter, $value);
}
}
|
[
"private",
"function",
"setPayload",
"(",
"array",
"$",
"parameters",
")",
":",
"void",
"{",
"$",
"this",
"->",
"payload",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameter",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setPayloadParameter",
"(",
"$",
"parameter",
",",
"$",
"value",
")",
";",
"}",
"}"
] |
Set payload.
@param array<string, mixed> $parameters
|
[
"Set",
"payload",
"."
] |
404b2cdea108538b55caa261c29280062dd0e3db
|
https://github.com/phpgears/dto/blob/404b2cdea108538b55caa261c29280062dd0e3db/src/PayloadBehaviour.php#L34-L41
|
22,599
|
shipmile/shipmile-api-php
|
lib/Shipmile/HttpClient/AuthHandler.php
|
AuthHandler.getAuthType
|
public function getAuthType()
{
if (isset($this->auth['username']) && isset($this->auth['password'])) {
return self::HTTP_PASSWORD;
}
if (isset($this->auth['client_id']) && isset($this->auth['client_secret'])) {
return self::URL_SECRET;
}
if (isset($this->auth['access_token'])) {
return self::URL_TOKEN;
}
return -1;
}
|
php
|
public function getAuthType()
{
if (isset($this->auth['username']) && isset($this->auth['password'])) {
return self::HTTP_PASSWORD;
}
if (isset($this->auth['client_id']) && isset($this->auth['client_secret'])) {
return self::URL_SECRET;
}
if (isset($this->auth['access_token'])) {
return self::URL_TOKEN;
}
return -1;
}
|
[
"public",
"function",
"getAuthType",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"auth",
"[",
"'username'",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"auth",
"[",
"'password'",
"]",
")",
")",
"{",
"return",
"self",
"::",
"HTTP_PASSWORD",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"auth",
"[",
"'client_id'",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"auth",
"[",
"'client_secret'",
"]",
")",
")",
"{",
"return",
"self",
"::",
"URL_SECRET",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"auth",
"[",
"'access_token'",
"]",
")",
")",
"{",
"return",
"self",
"::",
"URL_TOKEN",
";",
"}",
"return",
"-",
"1",
";",
"}"
] |
Calculating the Authentication Type
|
[
"Calculating",
"the",
"Authentication",
"Type"
] |
b8272613b3a27f0f27e8722cbee277e41e9dfe59
|
https://github.com/shipmile/shipmile-api-php/blob/b8272613b3a27f0f27e8722cbee277e41e9dfe59/lib/Shipmile/HttpClient/AuthHandler.php#L27-L43
|
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.