repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
netbull/CoreBundle | ORM/Subscribers/Sluggable/SluggableSubscriber.php | SluggableSubscriber.onFlush | public function onFlush(OnFlushEventArgs $args)
{
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
$uow->computeChangeSets();
} | php | public function onFlush(OnFlushEventArgs $args)
{
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
$uow->computeChangeSets();
} | [
"public",
"function",
"onFlush",
"(",
"OnFlushEventArgs",
"$",
"args",
")",
"{",
"$",
"em",
"=",
"$",
"args",
"->",
"getEntityManager",
"(",
")",
";",
"$",
"uow",
"=",
"$",
"em",
"->",
"getUnitOfWork",
"(",
")",
";",
"$",
"uow",
"->",
"computeChangeSets",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/netbull/CoreBundle/blob/0bacc1d9e4733b6da613027400c48421e5a14645/ORM/Subscribers/Sluggable/SluggableSubscriber.php#L87-L93 |
KDF5000/EasyThink | src/ThinkPHP/Library/Think/Cache/Driver/Memcache.php | Memcache.rm | public function rm($name, $ttl = false) {
$name = $this->options['prefix'].$name;
return $ttl === false ?
$this->handler->delete($name) :
$this->handler->delete($name, $ttl);
} | php | public function rm($name, $ttl = false) {
$name = $this->options['prefix'].$name;
return $ttl === false ?
$this->handler->delete($name) :
$this->handler->delete($name, $ttl);
} | [
"public",
"function",
"rm",
"(",
"$",
"name",
",",
"$",
"ttl",
"=",
"false",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"options",
"[",
"'prefix'",
"]",
".",
"$",
"name",
";",
"return",
"$",
"ttl",
"===",
"false",
"?",
"$",
"this",
"->",
"handler",
"->",
"delete",
"(",
"$",
"name",
")",
":",
"$",
"this",
"->",
"handler",
"->",
"delete",
"(",
"$",
"name",
",",
"$",
"ttl",
")",
";",
"}"
] | 删除缓存
@access public
@param string $name 缓存变量名
@return boolean | [
"删除缓存"
] | train | https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Cache/Driver/Memcache.php#L88-L93 |
Soneritics/Database | Soneritics/Database/DatabaseRecord/PDODatabaseRecord.php | PDODatabaseRecord.createMapping | private function createMapping()
{
$columns = $this->pdoStatement->columnCount();
if ($columns > 0) {
$this->mapping = [];
for ($i = 0; $i < $columns; $i++) {
$meta = $this->pdoStatement->getColumnMeta($i);
$this->mapping[$i] = [$meta['table'], $meta['name']];
}
}
} | php | private function createMapping()
{
$columns = $this->pdoStatement->columnCount();
if ($columns > 0) {
$this->mapping = [];
for ($i = 0; $i < $columns; $i++) {
$meta = $this->pdoStatement->getColumnMeta($i);
$this->mapping[$i] = [$meta['table'], $meta['name']];
}
}
} | [
"private",
"function",
"createMapping",
"(",
")",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"pdoStatement",
"->",
"columnCount",
"(",
")",
";",
"if",
"(",
"$",
"columns",
">",
"0",
")",
"{",
"$",
"this",
"->",
"mapping",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"columns",
";",
"$",
"i",
"++",
")",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"pdoStatement",
"->",
"getColumnMeta",
"(",
"$",
"i",
")",
";",
"$",
"this",
"->",
"mapping",
"[",
"$",
"i",
"]",
"=",
"[",
"$",
"meta",
"[",
"'table'",
"]",
",",
"$",
"meta",
"[",
"'name'",
"]",
"]",
";",
"}",
"}",
"}"
] | Create the mapping to use for mapping the column names to a result array. | [
"Create",
"the",
"mapping",
"to",
"use",
"for",
"mapping",
"the",
"column",
"names",
"to",
"a",
"result",
"array",
"."
] | train | https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseRecord/PDODatabaseRecord.php#L51-L61 |
Soneritics/Database | Soneritics/Database/DatabaseRecord/PDODatabaseRecord.php | PDODatabaseRecord.all | public function all()
{
$this->reset();
$result = [];
while ($row = $this->get()) {
$result[] = $row;
}
return $result;
} | php | public function all()
{
$this->reset();
$result = [];
while ($row = $this->get()) {
$result[] = $row;
}
return $result;
} | [
"public",
"function",
"all",
"(",
")",
"{",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"this",
"->",
"get",
"(",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Return an array with all the data from the query.
@return array | [
"Return",
"an",
"array",
"with",
"all",
"the",
"data",
"from",
"the",
"query",
"."
] | train | https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseRecord/PDODatabaseRecord.php#L80-L90 |
Soneritics/Database | Soneritics/Database/DatabaseRecord/PDODatabaseRecord.php | PDODatabaseRecord.get | public function get()
{
$row = $this->pdoStatement->fetch(\PDO::FETCH_NUM);
return $row ? $this->map($row) : $row;
} | php | public function get()
{
$row = $this->pdoStatement->fetch(\PDO::FETCH_NUM);
return $row ? $this->map($row) : $row;
} | [
"public",
"function",
"get",
"(",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"pdoStatement",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_NUM",
")",
";",
"return",
"$",
"row",
"?",
"$",
"this",
"->",
"map",
"(",
"$",
"row",
")",
":",
"$",
"row",
";",
"}"
] | Fetch the next (or first) row from the results.
@return mixed | [
"Fetch",
"the",
"next",
"(",
"or",
"first",
")",
"row",
"from",
"the",
"results",
"."
] | train | https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseRecord/PDODatabaseRecord.php#L105-L109 |
maddoger/yii2-cms-user | common/models/PasswordResetRequestForm.php | PasswordResetRequestForm.sendEmail | public function sendEmail()
{
/* @var $user User */
$user = User::findOne([
'status' => User::STATUS_ACTIVE,
'email' => $this->email,
]);
if ($user) {
if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
$user->generatePasswordResetToken();
}
if ($user->save()) {
$resetUrl = $this->resetUrl;
$resetUrl['token'] = $user->password_reset_token;
return Yii::$app->mailer->compose($this->mailView, ['user' => $user, 'resetUrl' => $resetUrl])
->setTo($this->email)
->setSubject(Yii::t('maddoger/user', 'Password reset for {app}', ['app' => \Yii::$app->name]))
->send();
}
}
return false;
} | php | public function sendEmail()
{
/* @var $user User */
$user = User::findOne([
'status' => User::STATUS_ACTIVE,
'email' => $this->email,
]);
if ($user) {
if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
$user->generatePasswordResetToken();
}
if ($user->save()) {
$resetUrl = $this->resetUrl;
$resetUrl['token'] = $user->password_reset_token;
return Yii::$app->mailer->compose($this->mailView, ['user' => $user, 'resetUrl' => $resetUrl])
->setTo($this->email)
->setSubject(Yii::t('maddoger/user', 'Password reset for {app}', ['app' => \Yii::$app->name]))
->send();
}
}
return false;
} | [
"public",
"function",
"sendEmail",
"(",
")",
"{",
"/* @var $user User */",
"$",
"user",
"=",
"User",
"::",
"findOne",
"(",
"[",
"'status'",
"=>",
"User",
"::",
"STATUS_ACTIVE",
",",
"'email'",
"=>",
"$",
"this",
"->",
"email",
",",
"]",
")",
";",
"if",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"!",
"User",
"::",
"isPasswordResetTokenValid",
"(",
"$",
"user",
"->",
"password_reset_token",
")",
")",
"{",
"$",
"user",
"->",
"generatePasswordResetToken",
"(",
")",
";",
"}",
"if",
"(",
"$",
"user",
"->",
"save",
"(",
")",
")",
"{",
"$",
"resetUrl",
"=",
"$",
"this",
"->",
"resetUrl",
";",
"$",
"resetUrl",
"[",
"'token'",
"]",
"=",
"$",
"user",
"->",
"password_reset_token",
";",
"return",
"Yii",
"::",
"$",
"app",
"->",
"mailer",
"->",
"compose",
"(",
"$",
"this",
"->",
"mailView",
",",
"[",
"'user'",
"=>",
"$",
"user",
",",
"'resetUrl'",
"=>",
"$",
"resetUrl",
"]",
")",
"->",
"setTo",
"(",
"$",
"this",
"->",
"email",
")",
"->",
"setSubject",
"(",
"Yii",
"::",
"t",
"(",
"'maddoger/user'",
",",
"'Password reset for {app}'",
",",
"[",
"'app'",
"=>",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"name",
"]",
")",
")",
"->",
"send",
"(",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Sends an email with a link, for resetting the password.
@return boolean whether the email was send | [
"Sends",
"an",
"email",
"with",
"a",
"link",
"for",
"resetting",
"the",
"password",
"."
] | train | https://github.com/maddoger/yii2-cms-user/blob/6792d1d0d2c0bf01fe87729985b5659de4c1aac1/common/models/PasswordResetRequestForm.php#L65-L89 |
as3io/As3ModlrBundle | DependencyInjection/Compiler/DirectoryCompilerPass.php | DirectoryCompilerPass.createDirectory | private function createDirectory($dir)
{
if (file_exists($dir)) {
return $this;
}
if (false === @mkdir($dir, 0777, true)) {
throw new \RuntimeException(sprintf('Unable to create directory "%s"', $dir));
}
return $this;
} | php | private function createDirectory($dir)
{
if (file_exists($dir)) {
return $this;
}
if (false === @mkdir($dir, 0777, true)) {
throw new \RuntimeException(sprintf('Unable to create directory "%s"', $dir));
}
return $this;
} | [
"private",
"function",
"createDirectory",
"(",
"$",
"dir",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"dir",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"false",
"===",
"@",
"mkdir",
"(",
"$",
"dir",
",",
"0777",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to create directory \"%s\"'",
",",
"$",
"dir",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Creates a directory (if nonexistent).
@param string $dir
@return self
@throws \RuntimeException | [
"Creates",
"a",
"directory",
"(",
"if",
"nonexistent",
")",
"."
] | train | https://github.com/as3io/As3ModlrBundle/blob/7ce2abb7390c7eaf4081c5b7e00b96e7001774a4/DependencyInjection/Compiler/DirectoryCompilerPass.php#L23-L32 |
as3io/As3ModlrBundle | DependencyInjection/Compiler/DirectoryCompilerPass.php | DirectoryCompilerPass.process | public function process(ContainerBuilder $container)
{
$name = Utility::getAliasedName('dirs');
if (false === $container->hasParameter($name)) {
return;
}
foreach ($container->getParameter($name) as $dir) {
$this->createDirectory($dir);
}
} | php | public function process(ContainerBuilder $container)
{
$name = Utility::getAliasedName('dirs');
if (false === $container->hasParameter($name)) {
return;
}
foreach ($container->getParameter($name) as $dir) {
$this->createDirectory($dir);
}
} | [
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"name",
"=",
"Utility",
"::",
"getAliasedName",
"(",
"'dirs'",
")",
";",
"if",
"(",
"false",
"===",
"$",
"container",
"->",
"hasParameter",
"(",
"$",
"name",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"container",
"->",
"getParameter",
"(",
"$",
"name",
")",
"as",
"$",
"dir",
")",
"{",
"$",
"this",
"->",
"createDirectory",
"(",
"$",
"dir",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/as3io/As3ModlrBundle/blob/7ce2abb7390c7eaf4081c5b7e00b96e7001774a4/DependencyInjection/Compiler/DirectoryCompilerPass.php#L37-L46 |
theopera/framework | src/Component/Http/Header/Header.php | Header.createFromString | public static function createFromString(string $string)
{
$string = trim($string);
$parts = explode(': ', $string, 2);
return new Header($parts[0], $parts[1]);
} | php | public static function createFromString(string $string)
{
$string = trim($string);
$parts = explode(': ', $string, 2);
return new Header($parts[0], $parts[1]);
} | [
"public",
"static",
"function",
"createFromString",
"(",
"string",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"': '",
",",
"$",
"string",
",",
"2",
")",
";",
"return",
"new",
"Header",
"(",
"$",
"parts",
"[",
"0",
"]",
",",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"}"
] | @param string $string
@return Header | [
"@param",
"string",
"$string"
] | train | https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/Http/Header/Header.php#L100-L106 |
ommu/mod-banner | models/BannerClicks.php | BannerClicks.search | public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
// Custom Search
$criteria->with = array(
'banner' => array(
'alias' => 'banner',
'select' => 'publish, cat_id, title'
),
'user' => array(
'alias' => 'user',
'select' => 'displayname',
),
);
$criteria->compare('t.click_id', $this->click_id);
$criteria->compare('t.banner_id', Yii::app()->getRequest()->getParam('banner') ? Yii::app()->getRequest()->getParam('banner') : $this->banner_id);
$criteria->compare('t.user_id', Yii::app()->getRequest()->getParam('user') ? Yii::app()->getRequest()->getParam('user') : $this->user_id);
$criteria->compare('t.clicks', $this->clicks);
if($this->click_date != null && !in_array($this->click_date, array('0000-00-00 00:00:00','1970-01-01 00:00:00','0002-12-02 07:07:12','-0001-11-30 00:00:00')))
$criteria->compare('date(t.click_date)', date('Y-m-d', strtotime($this->click_date)));
$criteria->compare('t.click_ip', strtolower($this->click_ip), true);
$criteria->compare('banner.cat_id', $this->category_search);
$criteria->compare('banner.title', strtolower($this->banner_search), true);
if(Yii::app()->getRequest()->getParam('banner') && Yii::app()->getRequest()->getParam('publish'))
$criteria->compare('banner.publish', Yii::app()->getRequest()->getParam('publish'));
$criteria->compare('user.displayname', strtolower($this->user_search), true);
if(!Yii::app()->getRequest()->getParam('BannerClicks_sort'))
$criteria->order = 't.click_id DESC';
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>Yii::app()->params['grid-view'] ? Yii::app()->params['grid-view']['pageSize'] : 50,
),
));
} | php | public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
// Custom Search
$criteria->with = array(
'banner' => array(
'alias' => 'banner',
'select' => 'publish, cat_id, title'
),
'user' => array(
'alias' => 'user',
'select' => 'displayname',
),
);
$criteria->compare('t.click_id', $this->click_id);
$criteria->compare('t.banner_id', Yii::app()->getRequest()->getParam('banner') ? Yii::app()->getRequest()->getParam('banner') : $this->banner_id);
$criteria->compare('t.user_id', Yii::app()->getRequest()->getParam('user') ? Yii::app()->getRequest()->getParam('user') : $this->user_id);
$criteria->compare('t.clicks', $this->clicks);
if($this->click_date != null && !in_array($this->click_date, array('0000-00-00 00:00:00','1970-01-01 00:00:00','0002-12-02 07:07:12','-0001-11-30 00:00:00')))
$criteria->compare('date(t.click_date)', date('Y-m-d', strtotime($this->click_date)));
$criteria->compare('t.click_ip', strtolower($this->click_ip), true);
$criteria->compare('banner.cat_id', $this->category_search);
$criteria->compare('banner.title', strtolower($this->banner_search), true);
if(Yii::app()->getRequest()->getParam('banner') && Yii::app()->getRequest()->getParam('publish'))
$criteria->compare('banner.publish', Yii::app()->getRequest()->getParam('publish'));
$criteria->compare('user.displayname', strtolower($this->user_search), true);
if(!Yii::app()->getRequest()->getParam('BannerClicks_sort'))
$criteria->order = 't.click_id DESC';
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>Yii::app()->params['grid-view'] ? Yii::app()->params['grid-view']['pageSize'] : 50,
),
));
} | [
"public",
"function",
"search",
"(",
")",
"{",
"// @todo Please modify the following code to remove attributes that should not be searched.",
"$",
"criteria",
"=",
"new",
"CDbCriteria",
";",
"// Custom Search",
"$",
"criteria",
"->",
"with",
"=",
"array",
"(",
"'banner'",
"=>",
"array",
"(",
"'alias'",
"=>",
"'banner'",
",",
"'select'",
"=>",
"'publish, cat_id, title'",
")",
",",
"'user'",
"=>",
"array",
"(",
"'alias'",
"=>",
"'user'",
",",
"'select'",
"=>",
"'displayname'",
",",
")",
",",
")",
";",
"$",
"criteria",
"->",
"compare",
"(",
"'t.click_id'",
",",
"$",
"this",
"->",
"click_id",
")",
";",
"$",
"criteria",
"->",
"compare",
"(",
"'t.banner_id'",
",",
"Yii",
"::",
"app",
"(",
")",
"->",
"getRequest",
"(",
")",
"->",
"getParam",
"(",
"'banner'",
")",
"?",
"Yii",
"::",
"app",
"(",
")",
"->",
"getRequest",
"(",
")",
"->",
"getParam",
"(",
"'banner'",
")",
":",
"$",
"this",
"->",
"banner_id",
")",
";",
"$",
"criteria",
"->",
"compare",
"(",
"'t.user_id'",
",",
"Yii",
"::",
"app",
"(",
")",
"->",
"getRequest",
"(",
")",
"->",
"getParam",
"(",
"'user'",
")",
"?",
"Yii",
"::",
"app",
"(",
")",
"->",
"getRequest",
"(",
")",
"->",
"getParam",
"(",
"'user'",
")",
":",
"$",
"this",
"->",
"user_id",
")",
";",
"$",
"criteria",
"->",
"compare",
"(",
"'t.clicks'",
",",
"$",
"this",
"->",
"clicks",
")",
";",
"if",
"(",
"$",
"this",
"->",
"click_date",
"!=",
"null",
"&&",
"!",
"in_array",
"(",
"$",
"this",
"->",
"click_date",
",",
"array",
"(",
"'0000-00-00 00:00:00'",
",",
"'1970-01-01 00:00:00'",
",",
"'0002-12-02 07:07:12'",
",",
"'-0001-11-30 00:00:00'",
")",
")",
")",
"$",
"criteria",
"->",
"compare",
"(",
"'date(t.click_date)'",
",",
"date",
"(",
"'Y-m-d'",
",",
"strtotime",
"(",
"$",
"this",
"->",
"click_date",
")",
")",
")",
";",
"$",
"criteria",
"->",
"compare",
"(",
"'t.click_ip'",
",",
"strtolower",
"(",
"$",
"this",
"->",
"click_ip",
")",
",",
"true",
")",
";",
"$",
"criteria",
"->",
"compare",
"(",
"'banner.cat_id'",
",",
"$",
"this",
"->",
"category_search",
")",
";",
"$",
"criteria",
"->",
"compare",
"(",
"'banner.title'",
",",
"strtolower",
"(",
"$",
"this",
"->",
"banner_search",
")",
",",
"true",
")",
";",
"if",
"(",
"Yii",
"::",
"app",
"(",
")",
"->",
"getRequest",
"(",
")",
"->",
"getParam",
"(",
"'banner'",
")",
"&&",
"Yii",
"::",
"app",
"(",
")",
"->",
"getRequest",
"(",
")",
"->",
"getParam",
"(",
"'publish'",
")",
")",
"$",
"criteria",
"->",
"compare",
"(",
"'banner.publish'",
",",
"Yii",
"::",
"app",
"(",
")",
"->",
"getRequest",
"(",
")",
"->",
"getParam",
"(",
"'publish'",
")",
")",
";",
"$",
"criteria",
"->",
"compare",
"(",
"'user.displayname'",
",",
"strtolower",
"(",
"$",
"this",
"->",
"user_search",
")",
",",
"true",
")",
";",
"if",
"(",
"!",
"Yii",
"::",
"app",
"(",
")",
"->",
"getRequest",
"(",
")",
"->",
"getParam",
"(",
"'BannerClicks_sort'",
")",
")",
"$",
"criteria",
"->",
"order",
"=",
"'t.click_id DESC'",
";",
"return",
"new",
"CActiveDataProvider",
"(",
"$",
"this",
",",
"array",
"(",
"'criteria'",
"=>",
"$",
"criteria",
",",
"'pagination'",
"=>",
"array",
"(",
"'pageSize'",
"=>",
"Yii",
"::",
"app",
"(",
")",
"->",
"params",
"[",
"'grid-view'",
"]",
"?",
"Yii",
"::",
"app",
"(",
")",
"->",
"params",
"[",
"'grid-view'",
"]",
"[",
"'pageSize'",
"]",
":",
"50",
",",
")",
",",
")",
")",
";",
"}"
] | Retrieves a list of models based on the current search/filter conditions.
Typical usecase:
- Initialize the model fields with values from filter form.
- Execute this method to get CActiveDataProvider instance which will filter
models according to data in model fields.
- Pass data provider to CGridView, CListView or any similar widget.
@return CActiveDataProvider the data provider that can return the models
based on the search/filter conditions. | [
"Retrieves",
"a",
"list",
"of",
"models",
"based",
"on",
"the",
"current",
"search",
"/",
"filter",
"conditions",
"."
] | train | https://github.com/ommu/mod-banner/blob/eb1c9fbb25a0a6be31749d5f32816de87fed8fdf/models/BannerClicks.php#L122-L163 |
ommu/mod-banner | models/BannerClicks.php | BannerClicks.insertClick | public static function insertClick($banner_id)
{
$criteria=new CDbCriteria;
$criteria->select = 'click_id, banner_id, user_id, clicks';
$criteria->compare('banner_id', $banner_id);
if(!Yii::app()->user->isGuest)
$criteria->compare('user_id', Yii::app()->user->id);
else
$criteria->addCondition('user_id IS NULL');
$findClick = self::model()->find($criteria);
if($findClick != null)
self::model()->updateByPk($findClick->click_id, array('clicks'=>$findClick->clicks + 1, 'click_ip'=>$_SERVER['REMOTE_ADDR']));
else {
$click=new BannerClicks;
$click->banner_id = $banner_id;
$click->save();
}
} | php | public static function insertClick($banner_id)
{
$criteria=new CDbCriteria;
$criteria->select = 'click_id, banner_id, user_id, clicks';
$criteria->compare('banner_id', $banner_id);
if(!Yii::app()->user->isGuest)
$criteria->compare('user_id', Yii::app()->user->id);
else
$criteria->addCondition('user_id IS NULL');
$findClick = self::model()->find($criteria);
if($findClick != null)
self::model()->updateByPk($findClick->click_id, array('clicks'=>$findClick->clicks + 1, 'click_ip'=>$_SERVER['REMOTE_ADDR']));
else {
$click=new BannerClicks;
$click->banner_id = $banner_id;
$click->save();
}
} | [
"public",
"static",
"function",
"insertClick",
"(",
"$",
"banner_id",
")",
"{",
"$",
"criteria",
"=",
"new",
"CDbCriteria",
";",
"$",
"criteria",
"->",
"select",
"=",
"'click_id, banner_id, user_id, clicks'",
";",
"$",
"criteria",
"->",
"compare",
"(",
"'banner_id'",
",",
"$",
"banner_id",
")",
";",
"if",
"(",
"!",
"Yii",
"::",
"app",
"(",
")",
"->",
"user",
"->",
"isGuest",
")",
"$",
"criteria",
"->",
"compare",
"(",
"'user_id'",
",",
"Yii",
"::",
"app",
"(",
")",
"->",
"user",
"->",
"id",
")",
";",
"else",
"$",
"criteria",
"->",
"addCondition",
"(",
"'user_id IS NULL'",
")",
";",
"$",
"findClick",
"=",
"self",
"::",
"model",
"(",
")",
"->",
"find",
"(",
"$",
"criteria",
")",
";",
"if",
"(",
"$",
"findClick",
"!=",
"null",
")",
"self",
"::",
"model",
"(",
")",
"->",
"updateByPk",
"(",
"$",
"findClick",
"->",
"click_id",
",",
"array",
"(",
"'clicks'",
"=>",
"$",
"findClick",
"->",
"clicks",
"+",
"1",
",",
"'click_ip'",
"=>",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
")",
";",
"else",
"{",
"$",
"click",
"=",
"new",
"BannerClicks",
";",
"$",
"click",
"->",
"banner_id",
"=",
"$",
"banner_id",
";",
"$",
"click",
"->",
"save",
"(",
")",
";",
"}",
"}"
] | insertClick | [
"insertClick"
] | train | https://github.com/ommu/mod-banner/blob/eb1c9fbb25a0a6be31749d5f32816de87fed8fdf/models/BannerClicks.php#L251-L270 |
zapheus/zapheus | src/Routing/Dispatcher.php | Dispatcher.dispatch | public function dispatch($method, $uri)
{
$uri = $uri[0] !== '/' ? '/' . $uri : $uri;
if (($result = $this->match($method, $uri)) !== null)
{
list($matches, $route) = (array) $result;
$filtered = array_filter(array_keys($matches), 'is_string');
$flipped = (array) array_flip($filtered);
$values = array_intersect_key($matches, $flipped);
$factory = new RouteFactory($route);
return $factory->parameters($values)->make();
}
$error = sprintf('Route "%s %s" not found', $method, $uri);
throw new \UnexpectedValueException($error);
} | php | public function dispatch($method, $uri)
{
$uri = $uri[0] !== '/' ? '/' . $uri : $uri;
if (($result = $this->match($method, $uri)) !== null)
{
list($matches, $route) = (array) $result;
$filtered = array_filter(array_keys($matches), 'is_string');
$flipped = (array) array_flip($filtered);
$values = array_intersect_key($matches, $flipped);
$factory = new RouteFactory($route);
return $factory->parameters($values)->make();
}
$error = sprintf('Route "%s %s" not found', $method, $uri);
throw new \UnexpectedValueException($error);
} | [
"public",
"function",
"dispatch",
"(",
"$",
"method",
",",
"$",
"uri",
")",
"{",
"$",
"uri",
"=",
"$",
"uri",
"[",
"0",
"]",
"!==",
"'/'",
"?",
"'/'",
".",
"$",
"uri",
":",
"$",
"uri",
";",
"if",
"(",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"match",
"(",
"$",
"method",
",",
"$",
"uri",
")",
")",
"!==",
"null",
")",
"{",
"list",
"(",
"$",
"matches",
",",
"$",
"route",
")",
"=",
"(",
"array",
")",
"$",
"result",
";",
"$",
"filtered",
"=",
"array_filter",
"(",
"array_keys",
"(",
"$",
"matches",
")",
",",
"'is_string'",
")",
";",
"$",
"flipped",
"=",
"(",
"array",
")",
"array_flip",
"(",
"$",
"filtered",
")",
";",
"$",
"values",
"=",
"array_intersect_key",
"(",
"$",
"matches",
",",
"$",
"flipped",
")",
";",
"$",
"factory",
"=",
"new",
"RouteFactory",
"(",
"$",
"route",
")",
";",
"return",
"$",
"factory",
"->",
"parameters",
"(",
"$",
"values",
")",
"->",
"make",
"(",
")",
";",
"}",
"$",
"error",
"=",
"sprintf",
"(",
"'Route \"%s %s\" not found'",
",",
"$",
"method",
",",
"$",
"uri",
")",
";",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"$",
"error",
")",
";",
"}"
] | Dispatches against the provided HTTP method verb and URI.
@param string $method
@param string $uri
@return \Zapheus\Routing\RouteInterface
@throws \UnexpectedValueException | [
"Dispatches",
"against",
"the",
"provided",
"HTTP",
"method",
"verb",
"and",
"URI",
"."
] | train | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Dispatcher.php#L37-L59 |
zapheus/zapheus | src/Routing/Dispatcher.php | Dispatcher.match | protected function match($method, $uri)
{
$result = null;
foreach ((array) $this->router->routes() as $route)
{
$matched = preg_match($route->regex(), $uri, $matches);
if ($matched && $route->method() === $method)
{
return array($matches, $route);
}
}
return $result;
} | php | protected function match($method, $uri)
{
$result = null;
foreach ((array) $this->router->routes() as $route)
{
$matched = preg_match($route->regex(), $uri, $matches);
if ($matched && $route->method() === $method)
{
return array($matches, $route);
}
}
return $result;
} | [
"protected",
"function",
"match",
"(",
"$",
"method",
",",
"$",
"uri",
")",
"{",
"$",
"result",
"=",
"null",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"router",
"->",
"routes",
"(",
")",
"as",
"$",
"route",
")",
"{",
"$",
"matched",
"=",
"preg_match",
"(",
"$",
"route",
"->",
"regex",
"(",
")",
",",
"$",
"uri",
",",
"$",
"matches",
")",
";",
"if",
"(",
"$",
"matched",
"&&",
"$",
"route",
"->",
"method",
"(",
")",
"===",
"$",
"method",
")",
"{",
"return",
"array",
"(",
"$",
"matches",
",",
"$",
"route",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Matches the route from the parsed URI.
@param string $method
@param string $uri
@return array|null | [
"Matches",
"the",
"route",
"from",
"the",
"parsed",
"URI",
"."
] | train | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Dispatcher.php#L68-L83 |
spryker/product-measurement-unit-data-import | src/Spryker/Zed/ProductMeasurementUnitDataImport/Business/Model/ProductMeasurementSalesUnitStoreWriterStep.php | ProductMeasurementSalesUnitStoreWriterStep.getIdProductMeasurementSalesUnitByKey | protected function getIdProductMeasurementSalesUnitByKey($productMeasurementSalesUnitKey): int
{
$spyProductMeasurementSalesUnitEntity = SpyProductMeasurementSalesUnitQuery::create()
->findOneByKey($productMeasurementSalesUnitKey);
if (!$spyProductMeasurementSalesUnitEntity) {
throw new EntityNotFoundException(
sprintf('Product measurement sales unit with key "%s" was not found during import.', $productMeasurementSalesUnitKey)
);
}
return $spyProductMeasurementSalesUnitEntity->getIdProductMeasurementSalesUnit();
} | php | protected function getIdProductMeasurementSalesUnitByKey($productMeasurementSalesUnitKey): int
{
$spyProductMeasurementSalesUnitEntity = SpyProductMeasurementSalesUnitQuery::create()
->findOneByKey($productMeasurementSalesUnitKey);
if (!$spyProductMeasurementSalesUnitEntity) {
throw new EntityNotFoundException(
sprintf('Product measurement sales unit with key "%s" was not found during import.', $productMeasurementSalesUnitKey)
);
}
return $spyProductMeasurementSalesUnitEntity->getIdProductMeasurementSalesUnit();
} | [
"protected",
"function",
"getIdProductMeasurementSalesUnitByKey",
"(",
"$",
"productMeasurementSalesUnitKey",
")",
":",
"int",
"{",
"$",
"spyProductMeasurementSalesUnitEntity",
"=",
"SpyProductMeasurementSalesUnitQuery",
"::",
"create",
"(",
")",
"->",
"findOneByKey",
"(",
"$",
"productMeasurementSalesUnitKey",
")",
";",
"if",
"(",
"!",
"$",
"spyProductMeasurementSalesUnitEntity",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"sprintf",
"(",
"'Product measurement sales unit with key \"%s\" was not found during import.'",
",",
"$",
"productMeasurementSalesUnitKey",
")",
")",
";",
"}",
"return",
"$",
"spyProductMeasurementSalesUnitEntity",
"->",
"getIdProductMeasurementSalesUnit",
"(",
")",
";",
"}"
] | @param string $productMeasurementSalesUnitKey
@throws \Spryker\Zed\ProductMeasurementUnitDataImport\Business\Exception\EntityNotFoundException
@return int | [
"@param",
"string",
"$productMeasurementSalesUnitKey"
] | train | https://github.com/spryker/product-measurement-unit-data-import/blob/d9437537a9b72023c310b6d93b566671dec71a8a/src/Spryker/Zed/ProductMeasurementUnitDataImport/Business/Model/ProductMeasurementSalesUnitStoreWriterStep.php#L42-L54 |
spryker/product-measurement-unit-data-import | src/Spryker/Zed/ProductMeasurementUnitDataImport/Business/Model/ProductMeasurementSalesUnitStoreWriterStep.php | ProductMeasurementSalesUnitStoreWriterStep.saveProductMeasurementSalesUnitStore | protected function saveProductMeasurementSalesUnitStore(DataSetInterface $dataSet): void
{
SpyProductMeasurementSalesUnitStoreQuery::create()
->filterByFkProductMeasurementSalesUnit($this->getIdProductMeasurementSalesUnitByKey($dataSet[ProductMeasurementSalesUnitStoreDataSet::COLUMN_SALES_UNIT_KEY]))
->filterByFkStore($this->getIdStoreByName($dataSet[ProductMeasurementSalesUnitStoreDataSet::COLUMN_STORE_NAME]))
->findOneOrCreate()
->save();
} | php | protected function saveProductMeasurementSalesUnitStore(DataSetInterface $dataSet): void
{
SpyProductMeasurementSalesUnitStoreQuery::create()
->filterByFkProductMeasurementSalesUnit($this->getIdProductMeasurementSalesUnitByKey($dataSet[ProductMeasurementSalesUnitStoreDataSet::COLUMN_SALES_UNIT_KEY]))
->filterByFkStore($this->getIdStoreByName($dataSet[ProductMeasurementSalesUnitStoreDataSet::COLUMN_STORE_NAME]))
->findOneOrCreate()
->save();
} | [
"protected",
"function",
"saveProductMeasurementSalesUnitStore",
"(",
"DataSetInterface",
"$",
"dataSet",
")",
":",
"void",
"{",
"SpyProductMeasurementSalesUnitStoreQuery",
"::",
"create",
"(",
")",
"->",
"filterByFkProductMeasurementSalesUnit",
"(",
"$",
"this",
"->",
"getIdProductMeasurementSalesUnitByKey",
"(",
"$",
"dataSet",
"[",
"ProductMeasurementSalesUnitStoreDataSet",
"::",
"COLUMN_SALES_UNIT_KEY",
"]",
")",
")",
"->",
"filterByFkStore",
"(",
"$",
"this",
"->",
"getIdStoreByName",
"(",
"$",
"dataSet",
"[",
"ProductMeasurementSalesUnitStoreDataSet",
"::",
"COLUMN_STORE_NAME",
"]",
")",
")",
"->",
"findOneOrCreate",
"(",
")",
"->",
"save",
"(",
")",
";",
"}"
] | @param \Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface $dataSet
@return void | [
"@param",
"\\",
"Spryker",
"\\",
"Zed",
"\\",
"DataImport",
"\\",
"Business",
"\\",
"Model",
"\\",
"DataSet",
"\\",
"DataSetInterface",
"$dataSet"
] | train | https://github.com/spryker/product-measurement-unit-data-import/blob/d9437537a9b72023c310b6d93b566671dec71a8a/src/Spryker/Zed/ProductMeasurementUnitDataImport/Business/Model/ProductMeasurementSalesUnitStoreWriterStep.php#L85-L92 |
kherge-abandoned/php-service-update | src/lib/Herrera/Service/Update/UpdateServiceProvider.php | UpdateServiceProvider.register | public function register(Container $container)
{
$container['update'] = $container->many(function (
$version,
$major = true,
$pre = false
) use (
$container
){
return $container['update.manager']->update($version, $major, $pre);
});
$container['update.manager'] = $container->once(function () use (
$container
){
return new Manager($container['update.manifest']);
});
$container['update.manifest'] = $container->once(function () use (
$container
){
return Manifest::loadFile($container['update.url']);
});
} | php | public function register(Container $container)
{
$container['update'] = $container->many(function (
$version,
$major = true,
$pre = false
) use (
$container
){
return $container['update.manager']->update($version, $major, $pre);
});
$container['update.manager'] = $container->once(function () use (
$container
){
return new Manager($container['update.manifest']);
});
$container['update.manifest'] = $container->once(function () use (
$container
){
return Manifest::loadFile($container['update.url']);
});
} | [
"public",
"function",
"register",
"(",
"Container",
"$",
"container",
")",
"{",
"$",
"container",
"[",
"'update'",
"]",
"=",
"$",
"container",
"->",
"many",
"(",
"function",
"(",
"$",
"version",
",",
"$",
"major",
"=",
"true",
",",
"$",
"pre",
"=",
"false",
")",
"use",
"(",
"$",
"container",
")",
"{",
"return",
"$",
"container",
"[",
"'update.manager'",
"]",
"->",
"update",
"(",
"$",
"version",
",",
"$",
"major",
",",
"$",
"pre",
")",
";",
"}",
")",
";",
"$",
"container",
"[",
"'update.manager'",
"]",
"=",
"$",
"container",
"->",
"once",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"container",
")",
"{",
"return",
"new",
"Manager",
"(",
"$",
"container",
"[",
"'update.manifest'",
"]",
")",
";",
"}",
")",
";",
"$",
"container",
"[",
"'update.manifest'",
"]",
"=",
"$",
"container",
"->",
"once",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"container",
")",
"{",
"return",
"Manifest",
"::",
"loadFile",
"(",
"$",
"container",
"[",
"'update.url'",
"]",
")",
";",
"}",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/kherge-abandoned/php-service-update/blob/2b79d752556dac933063de3a908b254bbea8eec3/src/lib/Herrera/Service/Update/UpdateServiceProvider.php#L20-L43 |
miaoxing/wechat | src/Controller/Wechat.php | Wechat.jsConfigAction | public function jsConfigAction($req)
{
$account = wei()->wechatAccount->getCurrentAccount();
$url = $req['url'] ?: $req->getReferer();
$config = $account->getConfigData([], $url);
$this->response->setHeader('Access-Control-Allow-Origin', '*');
return $this->suc([
'config' => $config,
]);
} | php | public function jsConfigAction($req)
{
$account = wei()->wechatAccount->getCurrentAccount();
$url = $req['url'] ?: $req->getReferer();
$config = $account->getConfigData([], $url);
$this->response->setHeader('Access-Control-Allow-Origin', '*');
return $this->suc([
'config' => $config,
]);
} | [
"public",
"function",
"jsConfigAction",
"(",
"$",
"req",
")",
"{",
"$",
"account",
"=",
"wei",
"(",
")",
"->",
"wechatAccount",
"->",
"getCurrentAccount",
"(",
")",
";",
"$",
"url",
"=",
"$",
"req",
"[",
"'url'",
"]",
"?",
":",
"$",
"req",
"->",
"getReferer",
"(",
")",
";",
"$",
"config",
"=",
"$",
"account",
"->",
"getConfigData",
"(",
"[",
"]",
",",
"$",
"url",
")",
";",
"$",
"this",
"->",
"response",
"->",
"setHeader",
"(",
"'Access-Control-Allow-Origin'",
",",
"'*'",
")",
";",
"return",
"$",
"this",
"->",
"suc",
"(",
"[",
"'config'",
"=>",
"$",
"config",
",",
"]",
")",
";",
"}"
] | 获取JS-SDK配置
@param Request $req
@return array | [
"获取JS",
"-",
"SDK配置"
] | train | https://github.com/miaoxing/wechat/blob/8620f7788cd0b6b9d20d436cede1f9f2fd24925f/src/Controller/Wechat.php#L196-L207 |
miaoxing/wechat | src/Controller/Wechat.php | Wechat.runComponent | protected function runComponent(WeChatApp $app, WechatAccount $account)
{
$this->logger->info('收到第三方平台通知', $app->getAttrs());
switch ($app->getAttr('InfoType')) {
case 'component_verify_ticket':
$account->save(['verifyTicket' => $app->getAttr('ComponentVerifyTicket')]);
break;
case 'unauthorized':
$account = wei()->wechatAccount()->find(['applicationId' => $app->getAttr('AuthorizerAppid')]);
/** @var \Miaoxing\Wechat\Service\WechatAccount $account */
if ($account) {
$account->save(['authed' => false]);
} else {
$this->logger->info('取消授权但AppId不存在', $app->getAttrs());
}
break;
case 'authorized':
// 授权成功,无需处理
break;
default:
$this->logger->warning('未识别事件', $app->getAttrs());
}
// 不调用$app->run(),避免返回默认信息
return 'success';
} | php | protected function runComponent(WeChatApp $app, WechatAccount $account)
{
$this->logger->info('收到第三方平台通知', $app->getAttrs());
switch ($app->getAttr('InfoType')) {
case 'component_verify_ticket':
$account->save(['verifyTicket' => $app->getAttr('ComponentVerifyTicket')]);
break;
case 'unauthorized':
$account = wei()->wechatAccount()->find(['applicationId' => $app->getAttr('AuthorizerAppid')]);
/** @var \Miaoxing\Wechat\Service\WechatAccount $account */
if ($account) {
$account->save(['authed' => false]);
} else {
$this->logger->info('取消授权但AppId不存在', $app->getAttrs());
}
break;
case 'authorized':
// 授权成功,无需处理
break;
default:
$this->logger->warning('未识别事件', $app->getAttrs());
}
// 不调用$app->run(),避免返回默认信息
return 'success';
} | [
"protected",
"function",
"runComponent",
"(",
"WeChatApp",
"$",
"app",
",",
"WechatAccount",
"$",
"account",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'收到第三方平台通知', $app->getAttrs()",
")",
"",
"",
"",
"",
"",
"",
"",
"",
"switch",
"(",
"$",
"app",
"->",
"getAttr",
"(",
"'InfoType'",
")",
")",
"{",
"case",
"'component_verify_ticket'",
":",
"$",
"account",
"->",
"save",
"(",
"[",
"'verifyTicket'",
"=>",
"$",
"app",
"->",
"getAttr",
"(",
"'ComponentVerifyTicket'",
")",
"]",
")",
";",
"break",
";",
"case",
"'unauthorized'",
":",
"$",
"account",
"=",
"wei",
"(",
")",
"->",
"wechatAccount",
"(",
")",
"->",
"find",
"(",
"[",
"'applicationId'",
"=>",
"$",
"app",
"->",
"getAttr",
"(",
"'AuthorizerAppid'",
")",
"]",
")",
";",
"/** @var \\Miaoxing\\Wechat\\Service\\WechatAccount $account */",
"if",
"(",
"$",
"account",
")",
"{",
"$",
"account",
"->",
"save",
"(",
"[",
"'authed'",
"=>",
"false",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'取消授权但AppId不存在', $app->getAttrs",
"(",
")",
";",
"",
"",
"",
"",
"",
"",
"}",
"break",
";",
"case",
"'authorized'",
":",
"// 授权成功,无需处理",
"break",
";",
"default",
":",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"'未识别事件', $app->ge",
"t",
"t",
"trs",
"()",
");",
"",
"",
"",
"",
"}",
"// 不调用$app->run(),避免返回默认信息",
"return",
"'success'",
";",
"}"
] | 单独处理来自第三方平台的通知
@param WeChatApp $app
@param \Miaoxing\Wechat\Service\WechatAccount $account
@return string | [
"单独处理来自第三方平台的通知"
] | train | https://github.com/miaoxing/wechat/blob/8620f7788cd0b6b9d20d436cede1f9f2fd24925f/src/Controller/Wechat.php#L216-L245 |
SlabPHP/controllers | src/POSTBack.php | POSTBack.requireSubmitValue | protected function requireSubmitValue()
{
if ($this->system->input()->post('submit')) {
echo 'LOOK: ' . $this->system->input()->post('submit') . PHP_EOL;
return;
}
$this->setNotReady("No submit value present.");
} | php | protected function requireSubmitValue()
{
if ($this->system->input()->post('submit')) {
echo 'LOOK: ' . $this->system->input()->post('submit') . PHP_EOL;
return;
}
$this->setNotReady("No submit value present.");
} | [
"protected",
"function",
"requireSubmitValue",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"system",
"->",
"input",
"(",
")",
"->",
"post",
"(",
"'submit'",
")",
")",
"{",
"echo",
"'LOOK: '",
".",
"$",
"this",
"->",
"system",
"->",
"input",
"(",
")",
"->",
"post",
"(",
"'submit'",
")",
".",
"PHP_EOL",
";",
"return",
";",
"}",
"$",
"this",
"->",
"setNotReady",
"(",
"\"No submit value present.\"",
")",
";",
"}"
] | Require Submit Value | [
"Require",
"Submit",
"Value"
] | train | https://github.com/SlabPHP/controllers/blob/a1c4fded0265100a85904dd664b972a7f8687652/src/POSTBack.php#L56-L64 |
SlabPHP/controllers | src/POSTBack.php | POSTBack.resolveRedirectRoute | protected function resolveRedirectRoute()
{
if (empty($this->redirectRoute)) return;
$route = $this->system->router()->getRouteByName($this->redirectRoute);
if (empty($route))
{
$this->setNotReady("Unable to find route " . $this->redirectRoute);
return;
}
$this->redirectURL = $route->getPath($this->redirectParameters);
} | php | protected function resolveRedirectRoute()
{
if (empty($this->redirectRoute)) return;
$route = $this->system->router()->getRouteByName($this->redirectRoute);
if (empty($route))
{
$this->setNotReady("Unable to find route " . $this->redirectRoute);
return;
}
$this->redirectURL = $route->getPath($this->redirectParameters);
} | [
"protected",
"function",
"resolveRedirectRoute",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"redirectRoute",
")",
")",
"return",
";",
"$",
"route",
"=",
"$",
"this",
"->",
"system",
"->",
"router",
"(",
")",
"->",
"getRouteByName",
"(",
"$",
"this",
"->",
"redirectRoute",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"route",
")",
")",
"{",
"$",
"this",
"->",
"setNotReady",
"(",
"\"Unable to find route \"",
".",
"$",
"this",
"->",
"redirectRoute",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"redirectURL",
"=",
"$",
"route",
"->",
"getPath",
"(",
"$",
"this",
"->",
"redirectParameters",
")",
";",
"}"
] | Resolve redirect route | [
"Resolve",
"redirect",
"route"
] | train | https://github.com/SlabPHP/controllers/blob/a1c4fded0265100a85904dd664b972a7f8687652/src/POSTBack.php#L86-L99 |
intpro/scalar | src/Db/ScalarCMapper.php | ScalarCMapper.getByRef | public function getByRef(ARef $ref, $asUnitMember = false)
{
$ownerType = $ref->getType();
$owner_name = $ownerType->getName();
$rank = $ownerType->getRank();
if($rank === TypeRank::GROUP and $asUnitMember)
{
$selectionUnit = $this->tuner->getSelection($owner_name, 'group');
return $this->select($selectionUnit);
}
$owner_id = $ref->getId();
$key = $owner_name.'_'.$owner_id;
if(array_key_exists($key, $this->units))
{
return $this->units[$key];
}
$collection = new MapScalarCollection($this->factory);
$this->units[$key] = $collection;
foreach($this->tables as $type_name => $table)
{
$query = DB::table($table);
$query->where($table.'.entity_name', '=', $owner_name);
$query->where($table.'.entity_id', '=', $owner_id);
$result = Helpers::laravel_db_result_to_array($query->get(['entity_name', 'entity_id', 'name', 'value']));
$this->addResultToCollection($type_name, $ownerType, $collection, $result);
}
return $collection;
} | php | public function getByRef(ARef $ref, $asUnitMember = false)
{
$ownerType = $ref->getType();
$owner_name = $ownerType->getName();
$rank = $ownerType->getRank();
if($rank === TypeRank::GROUP and $asUnitMember)
{
$selectionUnit = $this->tuner->getSelection($owner_name, 'group');
return $this->select($selectionUnit);
}
$owner_id = $ref->getId();
$key = $owner_name.'_'.$owner_id;
if(array_key_exists($key, $this->units))
{
return $this->units[$key];
}
$collection = new MapScalarCollection($this->factory);
$this->units[$key] = $collection;
foreach($this->tables as $type_name => $table)
{
$query = DB::table($table);
$query->where($table.'.entity_name', '=', $owner_name);
$query->where($table.'.entity_id', '=', $owner_id);
$result = Helpers::laravel_db_result_to_array($query->get(['entity_name', 'entity_id', 'name', 'value']));
$this->addResultToCollection($type_name, $ownerType, $collection, $result);
}
return $collection;
} | [
"public",
"function",
"getByRef",
"(",
"ARef",
"$",
"ref",
",",
"$",
"asUnitMember",
"=",
"false",
")",
"{",
"$",
"ownerType",
"=",
"$",
"ref",
"->",
"getType",
"(",
")",
";",
"$",
"owner_name",
"=",
"$",
"ownerType",
"->",
"getName",
"(",
")",
";",
"$",
"rank",
"=",
"$",
"ownerType",
"->",
"getRank",
"(",
")",
";",
"if",
"(",
"$",
"rank",
"===",
"TypeRank",
"::",
"GROUP",
"and",
"$",
"asUnitMember",
")",
"{",
"$",
"selectionUnit",
"=",
"$",
"this",
"->",
"tuner",
"->",
"getSelection",
"(",
"$",
"owner_name",
",",
"'group'",
")",
";",
"return",
"$",
"this",
"->",
"select",
"(",
"$",
"selectionUnit",
")",
";",
"}",
"$",
"owner_id",
"=",
"$",
"ref",
"->",
"getId",
"(",
")",
";",
"$",
"key",
"=",
"$",
"owner_name",
".",
"'_'",
".",
"$",
"owner_id",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"units",
")",
")",
"{",
"return",
"$",
"this",
"->",
"units",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"collection",
"=",
"new",
"MapScalarCollection",
"(",
"$",
"this",
"->",
"factory",
")",
";",
"$",
"this",
"->",
"units",
"[",
"$",
"key",
"]",
"=",
"$",
"collection",
";",
"foreach",
"(",
"$",
"this",
"->",
"tables",
"as",
"$",
"type_name",
"=>",
"$",
"table",
")",
"{",
"$",
"query",
"=",
"DB",
"::",
"table",
"(",
"$",
"table",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"table",
".",
"'.entity_name'",
",",
"'='",
",",
"$",
"owner_name",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"table",
".",
"'.entity_id'",
",",
"'='",
",",
"$",
"owner_id",
")",
";",
"$",
"result",
"=",
"Helpers",
"::",
"laravel_db_result_to_array",
"(",
"$",
"query",
"->",
"get",
"(",
"[",
"'entity_name'",
",",
"'entity_id'",
",",
"'name'",
",",
"'value'",
"]",
")",
")",
";",
"$",
"this",
"->",
"addResultToCollection",
"(",
"$",
"type_name",
",",
"$",
"ownerType",
",",
"$",
"collection",
",",
"$",
"result",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
] | @param \Interpro\Core\Contracts\Ref\ARef $ref
@param bool $asUnitMember
@return \Interpro\Extractor\Contracts\Collections\MapCCollection | [
"@param",
"\\",
"Interpro",
"\\",
"Core",
"\\",
"Contracts",
"\\",
"Ref",
"\\",
"ARef",
"$ref",
"@param",
"bool",
"$asUnitMember"
] | train | https://github.com/intpro/scalar/blob/de2d8c6e39efc9edf479447d8b2ed265aebe0a8d/src/Db/ScalarCMapper.php#L78-L115 |
Stinger-Soft/PhpCommons | src/StingerSoft/PhpCommons/Formatter/TimeFormatter.php | TimeFormatter.prettyPrintMicroTimeInterval | public static function prettyPrintMicroTimeInterval($startTime, $endTime) {
$seconds = abs($endTime - $startTime);
return sprintf('%02d:%02d:%02d', ($seconds / 3600), ($seconds / 60 % 60), $seconds % 60);
} | php | public static function prettyPrintMicroTimeInterval($startTime, $endTime) {
$seconds = abs($endTime - $startTime);
return sprintf('%02d:%02d:%02d', ($seconds / 3600), ($seconds / 60 % 60), $seconds % 60);
} | [
"public",
"static",
"function",
"prettyPrintMicroTimeInterval",
"(",
"$",
"startTime",
",",
"$",
"endTime",
")",
"{",
"$",
"seconds",
"=",
"abs",
"(",
"$",
"endTime",
"-",
"$",
"startTime",
")",
";",
"return",
"sprintf",
"(",
"'%02d:%02d:%02d'",
",",
"(",
"$",
"seconds",
"/",
"3600",
")",
",",
"(",
"$",
"seconds",
"/",
"60",
"%",
"60",
")",
",",
"$",
"seconds",
"%",
"60",
")",
";",
"}"
] | Pretty prints an interval specfied by two timestamps
@param float $startTime
Starttime as returned by microtime(true)
@param float $endTime
Endtime as returned by microtime(true)
@param string $locale
Locale used to format the result | [
"Pretty",
"prints",
"an",
"interval",
"specfied",
"by",
"two",
"timestamps"
] | train | https://github.com/Stinger-Soft/PhpCommons/blob/e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b/src/StingerSoft/PhpCommons/Formatter/TimeFormatter.php#L53-L56 |
Stinger-Soft/PhpCommons | src/StingerSoft/PhpCommons/Formatter/TimeFormatter.php | TimeFormatter.getRelativeTimeDifference | public static function getRelativeTimeDifference($from, $to = null) {
if($from instanceof \DateTime) {
$from = $from->getTimestamp();
} else if(!is_int($from)) {
throw new \InvalidArgumentException('$from must be a \DateTime or an integer!');
}
if($to === null) {
$to = time();
} else if($to instanceof \DateTime) {
$to = $to->getTimestamp();
} else if(!is_int($to)) {
throw new \InvalidArgumentException('$to must be a \DateTime, null or an integer!');
}
$diff = (int)abs($to - $from);
$since = $diff;
$unit = self::UNIT_SECONDS;
if($diff < self::MINUTE_IN_SECONDS) {
// leave empty here, because this is the default case
} else if($diff < self::HOUR_IN_SECONDS) {
$since = max(1, round($diff / self::MINUTE_IN_SECONDS));
$unit = self::UNIT_MINUTES;
} elseif($diff < self::DAY_IN_SECONDS && $diff >= self::HOUR_IN_SECONDS) {
$since = max(1, round($diff / self::HOUR_IN_SECONDS));
$unit = self::UNIT_HOURS;
} elseif($diff < self::WEEK_IN_SECONDS && $diff >= self::DAY_IN_SECONDS) {
$since = max(1, round($diff / self::DAY_IN_SECONDS));
$unit = self::UNIT_DAYS;
} elseif($diff < 30 * self::DAY_IN_SECONDS && $diff >= self::WEEK_IN_SECONDS) {
$since = max(1, round($diff / self::WEEK_IN_SECONDS));
$unit = self::UNIT_WEEKS;
} elseif($diff < self::YEAR_IN_SECONDS && $diff >= 30 * self::DAY_IN_SECONDS) {
$since = max(1, round($diff / (30 * self::DAY_IN_SECONDS)));
$unit = self::UNIT_MONTHS;
} elseif($diff >= self::YEAR_IN_SECONDS) {
$since = max(1, round($diff / self::YEAR_IN_SECONDS));
$unit = self::UNIT_YEARS;
}
return array(
$since,
$unit
);
} | php | public static function getRelativeTimeDifference($from, $to = null) {
if($from instanceof \DateTime) {
$from = $from->getTimestamp();
} else if(!is_int($from)) {
throw new \InvalidArgumentException('$from must be a \DateTime or an integer!');
}
if($to === null) {
$to = time();
} else if($to instanceof \DateTime) {
$to = $to->getTimestamp();
} else if(!is_int($to)) {
throw new \InvalidArgumentException('$to must be a \DateTime, null or an integer!');
}
$diff = (int)abs($to - $from);
$since = $diff;
$unit = self::UNIT_SECONDS;
if($diff < self::MINUTE_IN_SECONDS) {
// leave empty here, because this is the default case
} else if($diff < self::HOUR_IN_SECONDS) {
$since = max(1, round($diff / self::MINUTE_IN_SECONDS));
$unit = self::UNIT_MINUTES;
} elseif($diff < self::DAY_IN_SECONDS && $diff >= self::HOUR_IN_SECONDS) {
$since = max(1, round($diff / self::HOUR_IN_SECONDS));
$unit = self::UNIT_HOURS;
} elseif($diff < self::WEEK_IN_SECONDS && $diff >= self::DAY_IN_SECONDS) {
$since = max(1, round($diff / self::DAY_IN_SECONDS));
$unit = self::UNIT_DAYS;
} elseif($diff < 30 * self::DAY_IN_SECONDS && $diff >= self::WEEK_IN_SECONDS) {
$since = max(1, round($diff / self::WEEK_IN_SECONDS));
$unit = self::UNIT_WEEKS;
} elseif($diff < self::YEAR_IN_SECONDS && $diff >= 30 * self::DAY_IN_SECONDS) {
$since = max(1, round($diff / (30 * self::DAY_IN_SECONDS)));
$unit = self::UNIT_MONTHS;
} elseif($diff >= self::YEAR_IN_SECONDS) {
$since = max(1, round($diff / self::YEAR_IN_SECONDS));
$unit = self::UNIT_YEARS;
}
return array(
$since,
$unit
);
} | [
"public",
"static",
"function",
"getRelativeTimeDifference",
"(",
"$",
"from",
",",
"$",
"to",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"from",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"from",
"=",
"$",
"from",
"->",
"getTimestamp",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"is_int",
"(",
"$",
"from",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'$from must be a \\DateTime or an integer!'",
")",
";",
"}",
"if",
"(",
"$",
"to",
"===",
"null",
")",
"{",
"$",
"to",
"=",
"time",
"(",
")",
";",
"}",
"else",
"if",
"(",
"$",
"to",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"to",
"=",
"$",
"to",
"->",
"getTimestamp",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"is_int",
"(",
"$",
"to",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'$to must be a \\DateTime, null or an integer!'",
")",
";",
"}",
"$",
"diff",
"=",
"(",
"int",
")",
"abs",
"(",
"$",
"to",
"-",
"$",
"from",
")",
";",
"$",
"since",
"=",
"$",
"diff",
";",
"$",
"unit",
"=",
"self",
"::",
"UNIT_SECONDS",
";",
"if",
"(",
"$",
"diff",
"<",
"self",
"::",
"MINUTE_IN_SECONDS",
")",
"{",
"// leave empty here, because this is the default case\r",
"}",
"else",
"if",
"(",
"$",
"diff",
"<",
"self",
"::",
"HOUR_IN_SECONDS",
")",
"{",
"$",
"since",
"=",
"max",
"(",
"1",
",",
"round",
"(",
"$",
"diff",
"/",
"self",
"::",
"MINUTE_IN_SECONDS",
")",
")",
";",
"$",
"unit",
"=",
"self",
"::",
"UNIT_MINUTES",
";",
"}",
"elseif",
"(",
"$",
"diff",
"<",
"self",
"::",
"DAY_IN_SECONDS",
"&&",
"$",
"diff",
">=",
"self",
"::",
"HOUR_IN_SECONDS",
")",
"{",
"$",
"since",
"=",
"max",
"(",
"1",
",",
"round",
"(",
"$",
"diff",
"/",
"self",
"::",
"HOUR_IN_SECONDS",
")",
")",
";",
"$",
"unit",
"=",
"self",
"::",
"UNIT_HOURS",
";",
"}",
"elseif",
"(",
"$",
"diff",
"<",
"self",
"::",
"WEEK_IN_SECONDS",
"&&",
"$",
"diff",
">=",
"self",
"::",
"DAY_IN_SECONDS",
")",
"{",
"$",
"since",
"=",
"max",
"(",
"1",
",",
"round",
"(",
"$",
"diff",
"/",
"self",
"::",
"DAY_IN_SECONDS",
")",
")",
";",
"$",
"unit",
"=",
"self",
"::",
"UNIT_DAYS",
";",
"}",
"elseif",
"(",
"$",
"diff",
"<",
"30",
"*",
"self",
"::",
"DAY_IN_SECONDS",
"&&",
"$",
"diff",
">=",
"self",
"::",
"WEEK_IN_SECONDS",
")",
"{",
"$",
"since",
"=",
"max",
"(",
"1",
",",
"round",
"(",
"$",
"diff",
"/",
"self",
"::",
"WEEK_IN_SECONDS",
")",
")",
";",
"$",
"unit",
"=",
"self",
"::",
"UNIT_WEEKS",
";",
"}",
"elseif",
"(",
"$",
"diff",
"<",
"self",
"::",
"YEAR_IN_SECONDS",
"&&",
"$",
"diff",
">=",
"30",
"*",
"self",
"::",
"DAY_IN_SECONDS",
")",
"{",
"$",
"since",
"=",
"max",
"(",
"1",
",",
"round",
"(",
"$",
"diff",
"/",
"(",
"30",
"*",
"self",
"::",
"DAY_IN_SECONDS",
")",
")",
")",
";",
"$",
"unit",
"=",
"self",
"::",
"UNIT_MONTHS",
";",
"}",
"elseif",
"(",
"$",
"diff",
">=",
"self",
"::",
"YEAR_IN_SECONDS",
")",
"{",
"$",
"since",
"=",
"max",
"(",
"1",
",",
"round",
"(",
"$",
"diff",
"/",
"self",
"::",
"YEAR_IN_SECONDS",
")",
")",
";",
"$",
"unit",
"=",
"self",
"::",
"UNIT_YEARS",
";",
"}",
"return",
"array",
"(",
"$",
"since",
",",
"$",
"unit",
")",
";",
"}"
] | Get the relative difference between a given start time and end time.
Depending on the amount of time passed between given from and to, the difference between the two may be
expressed in seconds, hours, days, weeks, months or years.
@param int|\DateTime $from
the start time, either as <code>DateTime</code> object or as integer expressing a unix timestamp,
used for calculating the relative difference to the given <code>to</code> parameter.
@param int|\DateTime|null $to
the end time, either as <code>DateTime</code> object, a unix timestamp or <code>null</code> used for
calculating the difference to the given <code>from</code> parameter. In case <code>null</code> is
provided, the current timestamp will be used (utilizing <code>time()</code>).
@return int[2] returns an array containing two values: first, the relative difference
between <code>from</code> and </code>to</code>, second a constant for the time unit of the relative
difference. The unit is one of the class constants: <code>UNIT_SECONDS</code>, <code>UNIT_MINUTES</code>,
<code>UNIT_HOURS</code>, <code>UNIT_DAYS</code>, <code>UNIT_WEEKS</code>, <code>UNIT_MONTHS</code> or
<code>UNIT_YEARS</code>
@throws \InvalidArgumentException in case <code>from</code> is neither an integer, nor
a <code>DateTime</code> object.
@throws \InvalidArgumentException in case <code>to</code> is neither an integer,
nor a <code>DateTime</code> object, nor <code>null</code>. | [
"Get",
"the",
"relative",
"difference",
"between",
"a",
"given",
"start",
"time",
"and",
"end",
"time",
"."
] | train | https://github.com/Stinger-Soft/PhpCommons/blob/e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b/src/StingerSoft/PhpCommons/Formatter/TimeFormatter.php#L82-L127 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/Visitor/DisableDisallowedEntitiesInWayfVisitor.php | DisableDisallowedEntitiesInWayfVisitor.visitIdentityProvider | public function visitIdentityProvider(IdentityProvider $identityProvider)
{
if (in_array($identityProvider->entityId, $this->allowedEntityIds)) {
return;
}
$identityProvider->enabledInWayf = false;
} | php | public function visitIdentityProvider(IdentityProvider $identityProvider)
{
if (in_array($identityProvider->entityId, $this->allowedEntityIds)) {
return;
}
$identityProvider->enabledInWayf = false;
} | [
"public",
"function",
"visitIdentityProvider",
"(",
"IdentityProvider",
"$",
"identityProvider",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"identityProvider",
"->",
"entityId",
",",
"$",
"this",
"->",
"allowedEntityIds",
")",
")",
"{",
"return",
";",
"}",
"$",
"identityProvider",
"->",
"enabledInWayf",
"=",
"false",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/Visitor/DisableDisallowedEntitiesInWayfVisitor.php#L32-L39 |
makinacorpus/drupal-ulink | src/EntityFinderRegistry.php | EntityFinderRegistry.get | public function get($types)
{
$ret = [];
if (!$types) {
return $ret;
}
if (!is_array($types)) {
$types = [];
}
foreach ($types as $type) {
if (isset($this->instances[$type])) {
$ret = array_merge($ret, $this->instances[$type]);
}
}
return $ret;
} | php | public function get($types)
{
$ret = [];
if (!$types) {
return $ret;
}
if (!is_array($types)) {
$types = [];
}
foreach ($types as $type) {
if (isset($this->instances[$type])) {
$ret = array_merge($ret, $this->instances[$type]);
}
}
return $ret;
} | [
"public",
"function",
"get",
"(",
"$",
"types",
")",
"{",
"$",
"ret",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"$",
"types",
")",
"{",
"return",
"$",
"ret",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"types",
")",
")",
"{",
"$",
"types",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"instances",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"ret",
"=",
"array_merge",
"(",
"$",
"ret",
",",
"$",
"this",
"->",
"instances",
"[",
"$",
"type",
"]",
")",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get all instances for type(s)
@param string|string[] $types
@return EntityFinderInterface[] | [
"Get",
"all",
"instances",
"for",
"type",
"(",
"s",
")"
] | train | https://github.com/makinacorpus/drupal-ulink/blob/4e1e54b979d72934a6fc0242aae3f12abebf41d0/src/EntityFinderRegistry.php#L29-L48 |
makinacorpus/drupal-ulink | src/EntityFinderRegistry.php | EntityFinderRegistry.all | public function all()
{
$ret = [];
foreach ($this->instances as $instances) {
$ret = array_merge($ret, $instances);
}
return $ret;
} | php | public function all()
{
$ret = [];
foreach ($this->instances as $instances) {
$ret = array_merge($ret, $instances);
}
return $ret;
} | [
"public",
"function",
"all",
"(",
")",
"{",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"instances",
"as",
"$",
"instances",
")",
"{",
"$",
"ret",
"=",
"array_merge",
"(",
"$",
"ret",
",",
"$",
"instances",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get all instances
@return EntityFinderInterface[] | [
"Get",
"all",
"instances"
] | train | https://github.com/makinacorpus/drupal-ulink/blob/4e1e54b979d72934a6fc0242aae3f12abebf41d0/src/EntityFinderRegistry.php#L55-L64 |
kduma-OSS/L5-permissions | Middleware/Permission.php | Permission.handle | public function handle($request, Closure $next, $permissions)
{
if (! empty($permissions) && $this->auth->check()) {
$permissions = explode(':', $permissions);
if ($this->permissionsHelper->can($permissions)) {
return $next($request);
}
return abort(403);
}
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('auth/login');
}
} | php | public function handle($request, Closure $next, $permissions)
{
if (! empty($permissions) && $this->auth->check()) {
$permissions = explode(':', $permissions);
if ($this->permissionsHelper->can($permissions)) {
return $next($request);
}
return abort(403);
}
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('auth/login');
}
} | [
"public",
"function",
"handle",
"(",
"$",
"request",
",",
"Closure",
"$",
"next",
",",
"$",
"permissions",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"permissions",
")",
"&&",
"$",
"this",
"->",
"auth",
"->",
"check",
"(",
")",
")",
"{",
"$",
"permissions",
"=",
"explode",
"(",
"':'",
",",
"$",
"permissions",
")",
";",
"if",
"(",
"$",
"this",
"->",
"permissionsHelper",
"->",
"can",
"(",
"$",
"permissions",
")",
")",
"{",
"return",
"$",
"next",
"(",
"$",
"request",
")",
";",
"}",
"return",
"abort",
"(",
"403",
")",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"ajax",
"(",
")",
")",
"{",
"return",
"response",
"(",
"'Unauthorized.'",
",",
"401",
")",
";",
"}",
"else",
"{",
"return",
"redirect",
"(",
")",
"->",
"guest",
"(",
"'auth/login'",
")",
";",
"}",
"}"
] | Handle an incoming request.
@param \Illuminate\Http\Request $request
@param \Closure $next
@param $permissions
@return mixed | [
"Handle",
"an",
"incoming",
"request",
"."
] | train | https://github.com/kduma-OSS/L5-permissions/blob/0e11c1dc1dc083f972cef5a52ced664b7390b054/Middleware/Permission.php#L42-L58 |
Vectrex/vxPHP | src/Http/AcceptHeaderItem.php | AcceptHeaderItem.getAttribute | public function getAttribute($name, $default = NULL) {
return isset($this->attributes[$name]) ? $this->attributes[$name] : $default;
} | php | public function getAttribute($name, $default = NULL) {
return isset($this->attributes[$name]) ? $this->attributes[$name] : $default;
} | [
"public",
"function",
"getAttribute",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"NULL",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"attributes",
"[",
"$",
"name",
"]",
":",
"$",
"default",
";",
"}"
] | Returns an attribute by its name.
@param string $name
@param mixed $default
@return mixed | [
"Returns",
"an",
"attribute",
"by",
"its",
"name",
"."
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/AcceptHeaderItem.php#L209-L213 |
pryley/castor-framework | src/Services/Validator.php | Validator.validate | public function validate( $data, array $rules = [] )
{
$this->normalizeData( $data );
$this->setRules( $rules );
foreach( $this->rules as $attribute => $rules ) {
foreach( $rules as $rule ) {
$this->validateAttribute( $rule, $attribute );
if( $this->shouldStopValidating( $attribute ))break;
}
}
return $this->errors;
} | php | public function validate( $data, array $rules = [] )
{
$this->normalizeData( $data );
$this->setRules( $rules );
foreach( $this->rules as $attribute => $rules ) {
foreach( $rules as $rule ) {
$this->validateAttribute( $rule, $attribute );
if( $this->shouldStopValidating( $attribute ))break;
}
}
return $this->errors;
} | [
"public",
"function",
"validate",
"(",
"$",
"data",
",",
"array",
"$",
"rules",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"normalizeData",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"setRules",
"(",
"$",
"rules",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"attribute",
"=>",
"$",
"rules",
")",
"{",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
")",
"{",
"$",
"this",
"->",
"validateAttribute",
"(",
"$",
"rule",
",",
"$",
"attribute",
")",
";",
"if",
"(",
"$",
"this",
"->",
"shouldStopValidating",
"(",
"$",
"attribute",
")",
")",
"break",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"errors",
";",
"}"
] | Run the validator's rules against its data.
@param mixed $data
@return array | [
"Run",
"the",
"validator",
"s",
"rules",
"against",
"its",
"data",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L72-L86 |
pryley/castor-framework | src/Services/Validator.php | Validator.addError | protected function addError( $attribute, $rule, array $parameters )
{
$message = $this->getMessage( $attribute, $rule, $parameters );
$this->errors[ $attribute ]['errors'][] = $message;
if( !isset( $this->errors[ $attribute ]['value'] )) {
$this->errors[ $attribute ]['value'] = $this->getValue( $attribute );
}
} | php | protected function addError( $attribute, $rule, array $parameters )
{
$message = $this->getMessage( $attribute, $rule, $parameters );
$this->errors[ $attribute ]['errors'][] = $message;
if( !isset( $this->errors[ $attribute ]['value'] )) {
$this->errors[ $attribute ]['value'] = $this->getValue( $attribute );
}
} | [
"protected",
"function",
"addError",
"(",
"$",
"attribute",
",",
"$",
"rule",
",",
"array",
"$",
"parameters",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"getMessage",
"(",
"$",
"attribute",
",",
"$",
"rule",
",",
"$",
"parameters",
")",
";",
"$",
"this",
"->",
"errors",
"[",
"$",
"attribute",
"]",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"$",
"message",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"attribute",
"]",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"attribute",
"]",
"[",
"'value'",
"]",
"=",
"$",
"this",
"->",
"getValue",
"(",
"$",
"attribute",
")",
";",
"}",
"}"
] | Add an error message to the validator's collection of errors.
@param string $attribute
@param string $rule
@return void | [
"Add",
"an",
"error",
"message",
"to",
"the",
"validator",
"s",
"collection",
"of",
"errors",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L96-L105 |
pryley/castor-framework | src/Services/Validator.php | Validator.addFailure | protected function addFailure( $attribute, $rule, array $parameters )
{
$this->addError( $attribute, $rule, $parameters );
$this->failedRules[ $attribute ][ $rule ] = $parameters;
} | php | protected function addFailure( $attribute, $rule, array $parameters )
{
$this->addError( $attribute, $rule, $parameters );
$this->failedRules[ $attribute ][ $rule ] = $parameters;
} | [
"protected",
"function",
"addFailure",
"(",
"$",
"attribute",
",",
"$",
"rule",
",",
"array",
"$",
"parameters",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"$",
"attribute",
",",
"$",
"rule",
",",
"$",
"parameters",
")",
";",
"$",
"this",
"->",
"failedRules",
"[",
"$",
"attribute",
"]",
"[",
"$",
"rule",
"]",
"=",
"$",
"parameters",
";",
"}"
] | Add a failed rule and error message to the collection.
@param string $attribute
@param string $rule
@return void | [
"Add",
"a",
"failed",
"rule",
"and",
"error",
"message",
"to",
"the",
"collection",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L115-L120 |
pryley/castor-framework | src/Services/Validator.php | Validator.getMessage | protected function getMessage( $attribute, $rule, array $parameters )
{
if( in_array( $rule, $this->sizeRules )) {
return $this->getSizeMessage( $attribute, $rule, $parameters );
}
$lowerRule = $this->snakeCase( $rule );
return $this->translator( $lowerRule, $rule, $attribute, $parameters );
} | php | protected function getMessage( $attribute, $rule, array $parameters )
{
if( in_array( $rule, $this->sizeRules )) {
return $this->getSizeMessage( $attribute, $rule, $parameters );
}
$lowerRule = $this->snakeCase( $rule );
return $this->translator( $lowerRule, $rule, $attribute, $parameters );
} | [
"protected",
"function",
"getMessage",
"(",
"$",
"attribute",
",",
"$",
"rule",
",",
"array",
"$",
"parameters",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"rule",
",",
"$",
"this",
"->",
"sizeRules",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getSizeMessage",
"(",
"$",
"attribute",
",",
"$",
"rule",
",",
"$",
"parameters",
")",
";",
"}",
"$",
"lowerRule",
"=",
"$",
"this",
"->",
"snakeCase",
"(",
"$",
"rule",
")",
";",
"return",
"$",
"this",
"->",
"translator",
"(",
"$",
"lowerRule",
",",
"$",
"rule",
",",
"$",
"attribute",
",",
"$",
"parameters",
")",
";",
"}"
] | Get the validation message for an attribute and rule.
@param string $attribute
@param string $rule
@return string|null | [
"Get",
"the",
"validation",
"message",
"for",
"an",
"attribute",
"and",
"rule",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L143-L152 |
pryley/castor-framework | src/Services/Validator.php | Validator.getSizeMessage | protected function getSizeMessage( $attribute, $rule, array $parameters )
{
$lowerRule = $this->snakeCase( $rule );
$type = $this->getAttributeType( $attribute );
$lowerRule .= ".{$type}";
return $this->translator( $lowerRule, $rule, $attribute, $parameters );
} | php | protected function getSizeMessage( $attribute, $rule, array $parameters )
{
$lowerRule = $this->snakeCase( $rule );
$type = $this->getAttributeType( $attribute );
$lowerRule .= ".{$type}";
return $this->translator( $lowerRule, $rule, $attribute, $parameters );
} | [
"protected",
"function",
"getSizeMessage",
"(",
"$",
"attribute",
",",
"$",
"rule",
",",
"array",
"$",
"parameters",
")",
"{",
"$",
"lowerRule",
"=",
"$",
"this",
"->",
"snakeCase",
"(",
"$",
"rule",
")",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"getAttributeType",
"(",
"$",
"attribute",
")",
";",
"$",
"lowerRule",
".=",
"\".{$type}\"",
";",
"return",
"$",
"this",
"->",
"translator",
"(",
"$",
"lowerRule",
",",
"$",
"rule",
",",
"$",
"attribute",
",",
"$",
"parameters",
")",
";",
"}"
] | Get the proper error message for an attribute and size rule.
@param string $attribute
@param string $rule
@return string|null | [
"Get",
"the",
"proper",
"error",
"message",
"for",
"an",
"attribute",
"and",
"size",
"rule",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L207-L215 |
pryley/castor-framework | src/Services/Validator.php | Validator.normalizeData | protected function normalizeData( $data )
{
// If an object was provided, get its public properties
if( is_object( $data )) {
$this->data = get_object_vars( $data );
}
else {
$this->data = $data;
}
return $this;
} | php | protected function normalizeData( $data )
{
// If an object was provided, get its public properties
if( is_object( $data )) {
$this->data = get_object_vars( $data );
}
else {
$this->data = $data;
}
return $this;
} | [
"protected",
"function",
"normalizeData",
"(",
"$",
"data",
")",
"{",
"// If an object was provided, get its public properties",
"if",
"(",
"is_object",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"get_object_vars",
"(",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Normalize the provided data to an array.
@param mixed $data
@return $this | [
"Normalize",
"the",
"provided",
"data",
"to",
"an",
"array",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L251-L262 |
pryley/castor-framework | src/Services/Validator.php | Validator.parseRule | protected function parseRule( $rule )
{
$parameters = [];
// example: {rule}:{parameters}
if( strpos( $rule, ':' ) !== false ) {
list( $rule, $parameter ) = explode( ':', $rule, 2 );
// example: {parameter1,parameter2,...}
$parameters = $this->parseParameters( $rule, $parameter );
}
$rule = ucwords( str_replace( ['-', '_'], ' ', trim( $rule )));
$rule = str_replace( ' ', '', $rule );
return [ $rule, $parameters ];
} | php | protected function parseRule( $rule )
{
$parameters = [];
// example: {rule}:{parameters}
if( strpos( $rule, ':' ) !== false ) {
list( $rule, $parameter ) = explode( ':', $rule, 2 );
// example: {parameter1,parameter2,...}
$parameters = $this->parseParameters( $rule, $parameter );
}
$rule = ucwords( str_replace( ['-', '_'], ' ', trim( $rule )));
$rule = str_replace( ' ', '', $rule );
return [ $rule, $parameters ];
} | [
"protected",
"function",
"parseRule",
"(",
"$",
"rule",
")",
"{",
"$",
"parameters",
"=",
"[",
"]",
";",
"// example: {rule}:{parameters}",
"if",
"(",
"strpos",
"(",
"$",
"rule",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"rule",
",",
"$",
"parameter",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"rule",
",",
"2",
")",
";",
"// example: {parameter1,parameter2,...}",
"$",
"parameters",
"=",
"$",
"this",
"->",
"parseParameters",
"(",
"$",
"rule",
",",
"$",
"parameter",
")",
";",
"}",
"$",
"rule",
"=",
"ucwords",
"(",
"str_replace",
"(",
"[",
"'-'",
",",
"'_'",
"]",
",",
"' '",
",",
"trim",
"(",
"$",
"rule",
")",
")",
")",
";",
"$",
"rule",
"=",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"rule",
")",
";",
"return",
"[",
"$",
"rule",
",",
"$",
"parameters",
"]",
";",
"}"
] | Extract the rule name and parameters from a rule.
@param string $rule
@return array | [
"Extract",
"the",
"rule",
"name",
"and",
"parameters",
"from",
"a",
"rule",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L288-L304 |
pryley/castor-framework | src/Services/Validator.php | Validator.setRules | protected function setRules( array $rules )
{
foreach( $rules as $key => $rule ) {
$rules[ $key ] = is_string( $rule ) ? explode( '|', $rule ) : $rule;
}
$this->rules = $rules;
return $this;
} | php | protected function setRules( array $rules )
{
foreach( $rules as $key => $rule ) {
$rules[ $key ] = is_string( $rule ) ? explode( '|', $rule ) : $rule;
}
$this->rules = $rules;
return $this;
} | [
"protected",
"function",
"setRules",
"(",
"array",
"$",
"rules",
")",
"{",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"key",
"=>",
"$",
"rule",
")",
"{",
"$",
"rules",
"[",
"$",
"key",
"]",
"=",
"is_string",
"(",
"$",
"rule",
")",
"?",
"explode",
"(",
"'|'",
",",
"$",
"rule",
")",
":",
"$",
"rule",
";",
"}",
"$",
"this",
"->",
"rules",
"=",
"$",
"rules",
";",
"return",
"$",
"this",
";",
"}"
] | Set the validation rules.
@return $this | [
"Set",
"the",
"validation",
"rules",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L363-L372 |
pryley/castor-framework | src/Services/Validator.php | Validator.shouldStopValidating | protected function shouldStopValidating( $attribute )
{
return $this->hasRule( $attribute, $this->implicitRules )
&& isset( $this->failedRules[ $attribute ] )
&& array_intersect( array_keys( $this->failedRules[ $attribute ] ), $this->implicitRules );
} | php | protected function shouldStopValidating( $attribute )
{
return $this->hasRule( $attribute, $this->implicitRules )
&& isset( $this->failedRules[ $attribute ] )
&& array_intersect( array_keys( $this->failedRules[ $attribute ] ), $this->implicitRules );
} | [
"protected",
"function",
"shouldStopValidating",
"(",
"$",
"attribute",
")",
"{",
"return",
"$",
"this",
"->",
"hasRule",
"(",
"$",
"attribute",
",",
"$",
"this",
"->",
"implicitRules",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"failedRules",
"[",
"$",
"attribute",
"]",
")",
"&&",
"array_intersect",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"failedRules",
"[",
"$",
"attribute",
"]",
")",
",",
"$",
"this",
"->",
"implicitRules",
")",
";",
"}"
] | Check if we should stop further validations on a given attribute.
@param string $attribute
@return bool | [
"Check",
"if",
"we",
"should",
"stop",
"further",
"validations",
"on",
"a",
"given",
"attribute",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L381-L386 |
pryley/castor-framework | src/Services/Validator.php | Validator.snakeCase | protected function snakeCase( $string )
{
if( !ctype_lower( $string )) {
$string = preg_replace( '/\s+/u', '', $string );
$string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string );
$string = mb_strtolower( $string, 'UTF-8' );
}
return $string;
} | php | protected function snakeCase( $string )
{
if( !ctype_lower( $string )) {
$string = preg_replace( '/\s+/u', '', $string );
$string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string );
$string = mb_strtolower( $string, 'UTF-8' );
}
return $string;
} | [
"protected",
"function",
"snakeCase",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"!",
"ctype_lower",
"(",
"$",
"string",
")",
")",
"{",
"$",
"string",
"=",
"preg_replace",
"(",
"'/\\s+/u'",
",",
"''",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"preg_replace",
"(",
"'/(.)(?=[A-Z])/u'",
",",
"'$1_'",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"mb_strtolower",
"(",
"$",
"string",
",",
"'UTF-8'",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Convert a string to snake case.
@param string $string
@return string | [
"Convert",
"a",
"string",
"to",
"snake",
"case",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L395-L404 |
pryley/castor-framework | src/Services/Validator.php | Validator.translator | protected function translator( $key, $rule, $attribute, array $parameters )
{
$strings = [];//glsr_resolve( 'Strings' )->validation();
$message = isset( $strings[$key] )
? $strings[$key]
: false;
if( !$message )return;
$message = str_replace( ':attribute', $attribute, $message );
if( method_exists( $this, $replacer = "replace{$rule}" )) {
$message = $this->$replacer( $message, $parameters );
}
return $message;
} | php | protected function translator( $key, $rule, $attribute, array $parameters )
{
$strings = [];//glsr_resolve( 'Strings' )->validation();
$message = isset( $strings[$key] )
? $strings[$key]
: false;
if( !$message )return;
$message = str_replace( ':attribute', $attribute, $message );
if( method_exists( $this, $replacer = "replace{$rule}" )) {
$message = $this->$replacer( $message, $parameters );
}
return $message;
} | [
"protected",
"function",
"translator",
"(",
"$",
"key",
",",
"$",
"rule",
",",
"$",
"attribute",
",",
"array",
"$",
"parameters",
")",
"{",
"$",
"strings",
"=",
"[",
"]",
";",
"//glsr_resolve( 'Strings' )->validation();",
"$",
"message",
"=",
"isset",
"(",
"$",
"strings",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"strings",
"[",
"$",
"key",
"]",
":",
"false",
";",
"if",
"(",
"!",
"$",
"message",
")",
"return",
";",
"$",
"message",
"=",
"str_replace",
"(",
"':attribute'",
",",
"$",
"attribute",
",",
"$",
"message",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"replacer",
"=",
"\"replace{$rule}\"",
")",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"$",
"replacer",
"(",
"$",
"message",
",",
"$",
"parameters",
")",
";",
"}",
"return",
"$",
"message",
";",
"}"
] | Returns a translated message for the attribute
@param string $key
@param string $rule
@param string $attribute
@return string|null | [
"Returns",
"a",
"translated",
"message",
"for",
"the",
"attribute"
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L415-L432 |
pryley/castor-framework | src/Services/Validator.php | Validator.validateAccepted | protected function validateAccepted( $value )
{
$acceptable = ['yes', 'on', '1', 1, true, 'true'];
return $this->validateRequired( $value ) && in_array( $value, $acceptable, true );
} | php | protected function validateAccepted( $value )
{
$acceptable = ['yes', 'on', '1', 1, true, 'true'];
return $this->validateRequired( $value ) && in_array( $value, $acceptable, true );
} | [
"protected",
"function",
"validateAccepted",
"(",
"$",
"value",
")",
"{",
"$",
"acceptable",
"=",
"[",
"'yes'",
",",
"'on'",
",",
"'1'",
",",
"1",
",",
"true",
",",
"'true'",
"]",
";",
"return",
"$",
"this",
"->",
"validateRequired",
"(",
"$",
"value",
")",
"&&",
"in_array",
"(",
"$",
"value",
",",
"$",
"acceptable",
",",
"true",
")",
";",
"}"
] | Validate that an attribute was "accepted".
This validation rule implies the attribute is "required".
@param mixed $value
@return bool | [
"Validate",
"that",
"an",
"attribute",
"was",
"accepted",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L446-L451 |
pryley/castor-framework | src/Services/Validator.php | Validator.validateAttribute | protected function validateAttribute( $rule, $attribute )
{
list( $rule, $parameters ) = $this->parseRule( $rule );
if( $rule == '' )return;
$method = "validate{$rule}";
if( !method_exists( $this, $method )) {
throw new BadMethodCallException( "Method [$method] does not exist." );
}
if( !$this->$method( $this->getValue( $attribute ), $attribute, $parameters )) {
$this->addFailure( $attribute, $rule, $parameters );
}
} | php | protected function validateAttribute( $rule, $attribute )
{
list( $rule, $parameters ) = $this->parseRule( $rule );
if( $rule == '' )return;
$method = "validate{$rule}";
if( !method_exists( $this, $method )) {
throw new BadMethodCallException( "Method [$method] does not exist." );
}
if( !$this->$method( $this->getValue( $attribute ), $attribute, $parameters )) {
$this->addFailure( $attribute, $rule, $parameters );
}
} | [
"protected",
"function",
"validateAttribute",
"(",
"$",
"rule",
",",
"$",
"attribute",
")",
"{",
"list",
"(",
"$",
"rule",
",",
"$",
"parameters",
")",
"=",
"$",
"this",
"->",
"parseRule",
"(",
"$",
"rule",
")",
";",
"if",
"(",
"$",
"rule",
"==",
"''",
")",
"return",
";",
"$",
"method",
"=",
"\"validate{$rule}\"",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"\"Method [$method] does not exist.\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"$",
"method",
"(",
"$",
"this",
"->",
"getValue",
"(",
"$",
"attribute",
")",
",",
"$",
"attribute",
",",
"$",
"parameters",
")",
")",
"{",
"$",
"this",
"->",
"addFailure",
"(",
"$",
"attribute",
",",
"$",
"rule",
",",
"$",
"parameters",
")",
";",
"}",
"}"
] | Validate a given attribute against a rule.
@param string $rule
@param string $attribute
@return void
@throws BadMethodCallException | [
"Validate",
"a",
"given",
"attribute",
"against",
"a",
"rule",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L462-L477 |
pryley/castor-framework | src/Services/Validator.php | Validator.validateMin | protected function validateMin( $value, $attribute, array $parameters )
{
$this->requireParameterCount( 1, $parameters, 'min' );
return $this->getSize( $attribute, $value ) >= $parameters[0];
} | php | protected function validateMin( $value, $attribute, array $parameters )
{
$this->requireParameterCount( 1, $parameters, 'min' );
return $this->getSize( $attribute, $value ) >= $parameters[0];
} | [
"protected",
"function",
"validateMin",
"(",
"$",
"value",
",",
"$",
"attribute",
",",
"array",
"$",
"parameters",
")",
"{",
"$",
"this",
"->",
"requireParameterCount",
"(",
"1",
",",
"$",
"parameters",
",",
"'min'",
")",
";",
"return",
"$",
"this",
"->",
"getSize",
"(",
"$",
"attribute",
",",
"$",
"value",
")",
">=",
"$",
"parameters",
"[",
"0",
"]",
";",
"}"
] | Validate the size of an attribute is greater than a minimum value.
@param mixed $value
@param string $attribute
@return bool | [
"Validate",
"the",
"size",
"of",
"an",
"attribute",
"is",
"greater",
"than",
"a",
"minimum",
"value",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L531-L536 |
pryley/castor-framework | src/Services/Validator.php | Validator.validateRequired | protected function validateRequired( $value )
{
if( is_string( $value )) {
$value = trim( $value );
}
return is_null( $value ) || empty( $value )
? false
: true;
} | php | protected function validateRequired( $value )
{
if( is_string( $value )) {
$value = trim( $value );
}
return is_null( $value ) || empty( $value )
? false
: true;
} | [
"protected",
"function",
"validateRequired",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"}",
"return",
"is_null",
"(",
"$",
"value",
")",
"||",
"empty",
"(",
"$",
"value",
")",
"?",
"false",
":",
"true",
";",
"}"
] | Validate that a required attribute exists.
@param mixed $value
@return bool | [
"Validate",
"that",
"a",
"required",
"attribute",
"exists",
"."
] | train | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Services/Validator.php#L557-L565 |
PenoaksDev/Milky-Framework | src/Milky/Http/View/Compilers/Compiler.php | Compiler.getCompiledPath | public function getCompiledPath( $path )
{
$views = Framework::fw()->buildPath( "__views" );
if ( starts_with($path, $views) )
$path = substr( $path, strlen( $views ) + 1 );
if ( !ends_with( $path, '.php' ) )
$path .= '.php';
// $path = substr( $path, 0, strrpos( $path, "." ) );
$path = $this->cachePath . DIRECTORY_SEPARATOR . $path;
@mkdir( dirname( $path ), 0755, true );
return $path;
// return $this->cachePath . '/' . str_replace( ["/", "\\"], "-", dirname( $path ) ) . '-' . basename( $path ) . '.php';
// return $this->cachePath . '/' . sha1( $path ) . '.php';
} | php | public function getCompiledPath( $path )
{
$views = Framework::fw()->buildPath( "__views" );
if ( starts_with($path, $views) )
$path = substr( $path, strlen( $views ) + 1 );
if ( !ends_with( $path, '.php' ) )
$path .= '.php';
// $path = substr( $path, 0, strrpos( $path, "." ) );
$path = $this->cachePath . DIRECTORY_SEPARATOR . $path;
@mkdir( dirname( $path ), 0755, true );
return $path;
// return $this->cachePath . '/' . str_replace( ["/", "\\"], "-", dirname( $path ) ) . '-' . basename( $path ) . '.php';
// return $this->cachePath . '/' . sha1( $path ) . '.php';
} | [
"public",
"function",
"getCompiledPath",
"(",
"$",
"path",
")",
"{",
"$",
"views",
"=",
"Framework",
"::",
"fw",
"(",
")",
"->",
"buildPath",
"(",
"\"__views\"",
")",
";",
"if",
"(",
"starts_with",
"(",
"$",
"path",
",",
"$",
"views",
")",
")",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"strlen",
"(",
"$",
"views",
")",
"+",
"1",
")",
";",
"if",
"(",
"!",
"ends_with",
"(",
"$",
"path",
",",
"'.php'",
")",
")",
"$",
"path",
".=",
"'.php'",
";",
"// $path = substr( $path, 0, strrpos( $path, \".\" ) );",
"$",
"path",
"=",
"$",
"this",
"->",
"cachePath",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"path",
";",
"@",
"mkdir",
"(",
"dirname",
"(",
"$",
"path",
")",
",",
"0755",
",",
"true",
")",
";",
"return",
"$",
"path",
";",
"// return $this->cachePath . '/' . str_replace( [\"/\", \"\\\\\"], \"-\", dirname( $path ) ) . '-' . basename( $path ) . '.php';",
"// return $this->cachePath . '/' . sha1( $path ) . '.php';",
"}"
] | Get the path to the compiled version of a view.
@param string $path
@return string | [
"Get",
"the",
"path",
"to",
"the",
"compiled",
"version",
"of",
"a",
"view",
"."
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/View/Compilers/Compiler.php#L48-L69 |
PenoaksDev/Milky-Framework | src/Milky/Http/View/Compilers/Compiler.php | Compiler.isExpired | public function isExpired( $path )
{
$compiled = $this->getCompiledPath( $path );
// If the compiled file doesn't exist we will indicate that the view is expired
// so that it can be re-compiled. Else, we will verify the last modification
// of the views is less than the modification times of the compiled views.
if ( !$this->files->exists( $compiled ) )
{
return true;
}
$lastModified = $this->files->lastModified( $path );
return $lastModified >= $this->files->lastModified( $compiled );
} | php | public function isExpired( $path )
{
$compiled = $this->getCompiledPath( $path );
// If the compiled file doesn't exist we will indicate that the view is expired
// so that it can be re-compiled. Else, we will verify the last modification
// of the views is less than the modification times of the compiled views.
if ( !$this->files->exists( $compiled ) )
{
return true;
}
$lastModified = $this->files->lastModified( $path );
return $lastModified >= $this->files->lastModified( $compiled );
} | [
"public",
"function",
"isExpired",
"(",
"$",
"path",
")",
"{",
"$",
"compiled",
"=",
"$",
"this",
"->",
"getCompiledPath",
"(",
"$",
"path",
")",
";",
"// If the compiled file doesn't exist we will indicate that the view is expired",
"// so that it can be re-compiled. Else, we will verify the last modification",
"// of the views is less than the modification times of the compiled views.",
"if",
"(",
"!",
"$",
"this",
"->",
"files",
"->",
"exists",
"(",
"$",
"compiled",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"lastModified",
"=",
"$",
"this",
"->",
"files",
"->",
"lastModified",
"(",
"$",
"path",
")",
";",
"return",
"$",
"lastModified",
">=",
"$",
"this",
"->",
"files",
"->",
"lastModified",
"(",
"$",
"compiled",
")",
";",
"}"
] | Determine if the view at the given path is expired.
@param string $path
@return bool | [
"Determine",
"if",
"the",
"view",
"at",
"the",
"given",
"path",
"is",
"expired",
"."
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/View/Compilers/Compiler.php#L77-L92 |
native5/native5-sdk-client-php | src/Native5/UI/ScriptPathResolver.php | ScriptPathResolver.resolve | public static function resolve($name)
{
$logger = $GLOBALS['logger'];
$app = $GLOBALS['app'];
$staticPath = 'public';
if ($app->getConfiguration()->isLocal()) {
$staticPath = 'views';
}
$session = $app->getSessionManager()->getActiveSession();
$category = $session->getAttribute('category');
$basePath = '/'.$staticPath.'/resources/'.$category;
$commonPath = '/'.$staticPath.'/resources/common';
$searchFolder = '.';
$isUrl = false;
if(preg_match('/.*\.js$/', $name)) {
$searchFolder = 'scripts';
} else if(preg_match('/.*\.css$/', $name)) {
$searchFolder = 'styles';
} else if(preg_match('/.*\.(?:jpg|jpeg|gif|png)$/', $name)) {
$searchFolder = 'images';
} else {
$isUrl = true;
$name = DIRECTORY_SEPARATOR.$app->getConfiguration()->getApplicationContext().DIRECTORY_SEPARATOR.$name;
}
if ($isUrl) {
return $name;
}
if (file_exists(getcwd().$basePath.'/'.$searchFolder.'/'.$name)) {
return '/'.$app->getConfiguration()->getApplicationContext().$basePath.'/'.$searchFolder.'/'.$name;
} else if (file_exists(getcwd().$commonPath.'/'.$searchFolder.'/'.$name)) {
return '/'.$app->getConfiguration()->getApplicationContext().$commonPath.'/'.$searchFolder.'/'.$name;
}
return $name;
} | php | public static function resolve($name)
{
$logger = $GLOBALS['logger'];
$app = $GLOBALS['app'];
$staticPath = 'public';
if ($app->getConfiguration()->isLocal()) {
$staticPath = 'views';
}
$session = $app->getSessionManager()->getActiveSession();
$category = $session->getAttribute('category');
$basePath = '/'.$staticPath.'/resources/'.$category;
$commonPath = '/'.$staticPath.'/resources/common';
$searchFolder = '.';
$isUrl = false;
if(preg_match('/.*\.js$/', $name)) {
$searchFolder = 'scripts';
} else if(preg_match('/.*\.css$/', $name)) {
$searchFolder = 'styles';
} else if(preg_match('/.*\.(?:jpg|jpeg|gif|png)$/', $name)) {
$searchFolder = 'images';
} else {
$isUrl = true;
$name = DIRECTORY_SEPARATOR.$app->getConfiguration()->getApplicationContext().DIRECTORY_SEPARATOR.$name;
}
if ($isUrl) {
return $name;
}
if (file_exists(getcwd().$basePath.'/'.$searchFolder.'/'.$name)) {
return '/'.$app->getConfiguration()->getApplicationContext().$basePath.'/'.$searchFolder.'/'.$name;
} else if (file_exists(getcwd().$commonPath.'/'.$searchFolder.'/'.$name)) {
return '/'.$app->getConfiguration()->getApplicationContext().$commonPath.'/'.$searchFolder.'/'.$name;
}
return $name;
} | [
"public",
"static",
"function",
"resolve",
"(",
"$",
"name",
")",
"{",
"$",
"logger",
"=",
"$",
"GLOBALS",
"[",
"'logger'",
"]",
";",
"$",
"app",
"=",
"$",
"GLOBALS",
"[",
"'app'",
"]",
";",
"$",
"staticPath",
"=",
"'public'",
";",
"if",
"(",
"$",
"app",
"->",
"getConfiguration",
"(",
")",
"->",
"isLocal",
"(",
")",
")",
"{",
"$",
"staticPath",
"=",
"'views'",
";",
"}",
"$",
"session",
"=",
"$",
"app",
"->",
"getSessionManager",
"(",
")",
"->",
"getActiveSession",
"(",
")",
";",
"$",
"category",
"=",
"$",
"session",
"->",
"getAttribute",
"(",
"'category'",
")",
";",
"$",
"basePath",
"=",
"'/'",
".",
"$",
"staticPath",
".",
"'/resources/'",
".",
"$",
"category",
";",
"$",
"commonPath",
"=",
"'/'",
".",
"$",
"staticPath",
".",
"'/resources/common'",
";",
"$",
"searchFolder",
"=",
"'.'",
";",
"$",
"isUrl",
"=",
"false",
";",
"if",
"(",
"preg_match",
"(",
"'/.*\\.js$/'",
",",
"$",
"name",
")",
")",
"{",
"$",
"searchFolder",
"=",
"'scripts'",
";",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"'/.*\\.css$/'",
",",
"$",
"name",
")",
")",
"{",
"$",
"searchFolder",
"=",
"'styles'",
";",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"'/.*\\.(?:jpg|jpeg|gif|png)$/'",
",",
"$",
"name",
")",
")",
"{",
"$",
"searchFolder",
"=",
"'images'",
";",
"}",
"else",
"{",
"$",
"isUrl",
"=",
"true",
";",
"$",
"name",
"=",
"DIRECTORY_SEPARATOR",
".",
"$",
"app",
"->",
"getConfiguration",
"(",
")",
"->",
"getApplicationContext",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
";",
"}",
"if",
"(",
"$",
"isUrl",
")",
"{",
"return",
"$",
"name",
";",
"}",
"if",
"(",
"file_exists",
"(",
"getcwd",
"(",
")",
".",
"$",
"basePath",
".",
"'/'",
".",
"$",
"searchFolder",
".",
"'/'",
".",
"$",
"name",
")",
")",
"{",
"return",
"'/'",
".",
"$",
"app",
"->",
"getConfiguration",
"(",
")",
"->",
"getApplicationContext",
"(",
")",
".",
"$",
"basePath",
".",
"'/'",
".",
"$",
"searchFolder",
".",
"'/'",
".",
"$",
"name",
";",
"}",
"else",
"if",
"(",
"file_exists",
"(",
"getcwd",
"(",
")",
".",
"$",
"commonPath",
".",
"'/'",
".",
"$",
"searchFolder",
".",
"'/'",
".",
"$",
"name",
")",
")",
"{",
"return",
"'/'",
".",
"$",
"app",
"->",
"getConfiguration",
"(",
")",
"->",
"getApplicationContext",
"(",
")",
".",
"$",
"commonPath",
".",
"'/'",
".",
"$",
"searchFolder",
".",
"'/'",
".",
"$",
"name",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | Resolve Script Path based on name.
@param mixed $name Name of the script to resolve.
@access public
@return void | [
"Resolve",
"Script",
"Path",
"based",
"on",
"name",
"."
] | train | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/UI/ScriptPathResolver.php#L55-L95 |
native5/native5-sdk-client-php | src/Native5/UI/ScriptPathResolver.php | ScriptPathResolver.secureLink | public static function secureLink($url)
{
$app = $GLOBALS['app'];
if ($app->getSubject() !== null && $app->getSubject()->isAuthenticated()) {
$separator = '&';
if(!strpos($url, '?')) {
$separator = '?';
}
$url = $url.$separator.'rand_token='.urlencode($app->getSessionManager()->getActiveSession()->get('nonce'));
}
} | php | public static function secureLink($url)
{
$app = $GLOBALS['app'];
if ($app->getSubject() !== null && $app->getSubject()->isAuthenticated()) {
$separator = '&';
if(!strpos($url, '?')) {
$separator = '?';
}
$url = $url.$separator.'rand_token='.urlencode($app->getSessionManager()->getActiveSession()->get('nonce'));
}
} | [
"public",
"static",
"function",
"secureLink",
"(",
"$",
"url",
")",
"{",
"$",
"app",
"=",
"$",
"GLOBALS",
"[",
"'app'",
"]",
";",
"if",
"(",
"$",
"app",
"->",
"getSubject",
"(",
")",
"!==",
"null",
"&&",
"$",
"app",
"->",
"getSubject",
"(",
")",
"->",
"isAuthenticated",
"(",
")",
")",
"{",
"$",
"separator",
"=",
"'&'",
";",
"if",
"(",
"!",
"strpos",
"(",
"$",
"url",
",",
"'?'",
")",
")",
"{",
"$",
"separator",
"=",
"'?'",
";",
"}",
"$",
"url",
"=",
"$",
"url",
".",
"$",
"separator",
".",
"'rand_token='",
".",
"urlencode",
"(",
"$",
"app",
"->",
"getSessionManager",
"(",
")",
"->",
"getActiveSession",
"(",
")",
"->",
"get",
"(",
"'nonce'",
")",
")",
";",
"}",
"}"
] | secureLink
@param mixed $url Append nonce to token.
@static
@access public
@return void | [
"secureLink"
] | train | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/UI/ScriptPathResolver.php#L107-L117 |
jonesiscoding/device | src/DetectDefaults.php | DetectDefaults.getDefaults | public function getDefaults()
{
return array(
'android' => false,
'browser' => self::BROWSER,
'cookies' => ( count( $_COOKIE ) > 0 ) ? true : false,
'height' => self::HEIGHT,
'hidpi' => ( array_key_exists( 'HTTP_DPR', $_SERVER ) ) ? $_SERVER[ 'HTTP_DPR' ] > 1 : false,
'ios' => false,
'low_speed' => false, // deprecated
'low_battery' => false, // deprecated
'metered' => $this->getMeteredDefault(),
'touch' => self::TOUCH,
'user-agent' => $this->getUserAgentDefault(),
'viewport' => $this->getViewportDefault(),
'width' => self::WIDTH
);
} | php | public function getDefaults()
{
return array(
'android' => false,
'browser' => self::BROWSER,
'cookies' => ( count( $_COOKIE ) > 0 ) ? true : false,
'height' => self::HEIGHT,
'hidpi' => ( array_key_exists( 'HTTP_DPR', $_SERVER ) ) ? $_SERVER[ 'HTTP_DPR' ] > 1 : false,
'ios' => false,
'low_speed' => false, // deprecated
'low_battery' => false, // deprecated
'metered' => $this->getMeteredDefault(),
'touch' => self::TOUCH,
'user-agent' => $this->getUserAgentDefault(),
'viewport' => $this->getViewportDefault(),
'width' => self::WIDTH
);
} | [
"public",
"function",
"getDefaults",
"(",
")",
"{",
"return",
"array",
"(",
"'android'",
"=>",
"false",
",",
"'browser'",
"=>",
"self",
"::",
"BROWSER",
",",
"'cookies'",
"=>",
"(",
"count",
"(",
"$",
"_COOKIE",
")",
">",
"0",
")",
"?",
"true",
":",
"false",
",",
"'height'",
"=>",
"self",
"::",
"HEIGHT",
",",
"'hidpi'",
"=>",
"(",
"array_key_exists",
"(",
"'HTTP_DPR'",
",",
"$",
"_SERVER",
")",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_DPR'",
"]",
">",
"1",
":",
"false",
",",
"'ios'",
"=>",
"false",
",",
"'low_speed'",
"=>",
"false",
",",
"// deprecated",
"'low_battery'",
"=>",
"false",
",",
"// deprecated",
"'metered'",
"=>",
"$",
"this",
"->",
"getMeteredDefault",
"(",
")",
",",
"'touch'",
"=>",
"self",
"::",
"TOUCH",
",",
"'user-agent'",
"=>",
"$",
"this",
"->",
"getUserAgentDefault",
"(",
")",
",",
"'viewport'",
"=>",
"$",
"this",
"->",
"getViewportDefault",
"(",
")",
",",
"'width'",
"=>",
"self",
"::",
"WIDTH",
")",
";",
"}"
] | These defaults come from an number of places, including client hints. The only values based on a UA string are
the Android & iOS values.
References:
* https://developers.google.com/web/updates/2015/09/automating-resource-selection-with-client-hints
* http://httpwg.org/http-extensions/client-hints.html
* https://developers.google.com/web/updates/2016/02/save-data
@return array | [
"These",
"defaults",
"come",
"from",
"an",
"number",
"of",
"places",
"including",
"client",
"hints",
".",
"The",
"only",
"values",
"based",
"on",
"a",
"UA",
"string",
"are",
"the",
"Android",
"&",
"iOS",
"values",
"."
] | train | https://github.com/jonesiscoding/device/blob/d3c66f934bcaa8e5e0424cf684c995b1c80cee29/src/DetectDefaults.php#L59-L76 |
jonesiscoding/device | src/DetectDefaults.php | DetectDefaults.getMeteredDefault | private function getMeteredDefault()
{
foreach( self::METERED_HEADERS as $header )
{
if( array_key_exists( $header, $_SERVER ) )
{
return true;
}
}
return false;
} | php | private function getMeteredDefault()
{
foreach( self::METERED_HEADERS as $header )
{
if( array_key_exists( $header, $_SERVER ) )
{
return true;
}
}
return false;
} | [
"private",
"function",
"getMeteredDefault",
"(",
")",
"{",
"foreach",
"(",
"self",
"::",
"METERED_HEADERS",
"as",
"$",
"header",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"header",
",",
"$",
"_SERVER",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Uses potential mobile headers & Google's new 'save-data' header to determine if we have a metered connection.
* Reference for 'save-data': https://developers.google.com/web/updates/2016/02/save-data
@return bool | [
"Uses",
"potential",
"mobile",
"headers",
"&",
"Google",
"s",
"new",
"save",
"-",
"data",
"header",
"to",
"determine",
"if",
"we",
"have",
"a",
"metered",
"connection",
"."
] | train | https://github.com/jonesiscoding/device/blob/d3c66f934bcaa8e5e0424cf684c995b1c80cee29/src/DetectDefaults.php#L85-L96 |
e-commit/EcommitUtilBundle | Command/CompareLocalesCommand.php | CompareLocalesCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$sourceLocale = $input->getArgument('source-locale');
$targetLocale = $input->getArgument('target-locale');
$domain = $input->getOption('domain');
//Config
$config = array();
$fs = new Filesystem();
$configFile = $this->projectDir.'/config/compare_locales.yaml';
if ($fs->exists($configFile)) {
$config = Yaml::parseFile($configFile);
}
// Extract messages
$extractedCatalogueSource = $this->translator->getCatalogue($sourceLocale);
$extractedCatalogueTarget = $this->translator->getCatalogue($targetLocale);
$allMessagesSource = $extractedCatalogueSource->all($domain);
if (null !== $domain) {
$allMessagesSource = array($domain => $allMessagesSource);
}
if (!$this->checkExtractMessages($io, $allMessagesSource, $domain, $sourceLocale)) {
return;
}
$allMessagesTarget = $extractedCatalogueTarget->all($domain);
if (null !== $domain) {
$allMessagesTarget = array($domain => $allMessagesTarget);
}
if (!$this->checkExtractMessages($io, $allMessagesTarget, $domain, $targetLocale)) {
return;
}
//Diff
$rows = array();
foreach ($allMessagesSource as $domain => $messages) {
foreach ($messages as $id => $message) {
if (empty($allMessagesTarget[$domain][$id]) && !$this->ignoreMissingMessage($targetLocale, $domain, $id, $config)) {
$rows[] = ['<error>Missing</error>', $domain, $id, $message];
}
}
}
foreach ($allMessagesTarget as $domain => $messages) {
foreach ($messages as $id => $message) {
if (empty($allMessagesSource[$domain][$id])) {
$rows[] = ['<info>Unused</info>', $domain, $id, $message];
}
}
}
if (count($rows) > 0) {
$headers = array('State', 'Domain', 'Id', 'Messsage');
$io->table($headers, $rows);
return 2;
} else {
$io->success('No error.');
}
return 0;
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$sourceLocale = $input->getArgument('source-locale');
$targetLocale = $input->getArgument('target-locale');
$domain = $input->getOption('domain');
//Config
$config = array();
$fs = new Filesystem();
$configFile = $this->projectDir.'/config/compare_locales.yaml';
if ($fs->exists($configFile)) {
$config = Yaml::parseFile($configFile);
}
// Extract messages
$extractedCatalogueSource = $this->translator->getCatalogue($sourceLocale);
$extractedCatalogueTarget = $this->translator->getCatalogue($targetLocale);
$allMessagesSource = $extractedCatalogueSource->all($domain);
if (null !== $domain) {
$allMessagesSource = array($domain => $allMessagesSource);
}
if (!$this->checkExtractMessages($io, $allMessagesSource, $domain, $sourceLocale)) {
return;
}
$allMessagesTarget = $extractedCatalogueTarget->all($domain);
if (null !== $domain) {
$allMessagesTarget = array($domain => $allMessagesTarget);
}
if (!$this->checkExtractMessages($io, $allMessagesTarget, $domain, $targetLocale)) {
return;
}
//Diff
$rows = array();
foreach ($allMessagesSource as $domain => $messages) {
foreach ($messages as $id => $message) {
if (empty($allMessagesTarget[$domain][$id]) && !$this->ignoreMissingMessage($targetLocale, $domain, $id, $config)) {
$rows[] = ['<error>Missing</error>', $domain, $id, $message];
}
}
}
foreach ($allMessagesTarget as $domain => $messages) {
foreach ($messages as $id => $message) {
if (empty($allMessagesSource[$domain][$id])) {
$rows[] = ['<info>Unused</info>', $domain, $id, $message];
}
}
}
if (count($rows) > 0) {
$headers = array('State', 'Domain', 'Id', 'Messsage');
$io->table($headers, $rows);
return 2;
} else {
$io->success('No error.');
}
return 0;
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"io",
"=",
"new",
"SymfonyStyle",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"$",
"sourceLocale",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'source-locale'",
")",
";",
"$",
"targetLocale",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'target-locale'",
")",
";",
"$",
"domain",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'domain'",
")",
";",
"//Config",
"$",
"config",
"=",
"array",
"(",
")",
";",
"$",
"fs",
"=",
"new",
"Filesystem",
"(",
")",
";",
"$",
"configFile",
"=",
"$",
"this",
"->",
"projectDir",
".",
"'/config/compare_locales.yaml'",
";",
"if",
"(",
"$",
"fs",
"->",
"exists",
"(",
"$",
"configFile",
")",
")",
"{",
"$",
"config",
"=",
"Yaml",
"::",
"parseFile",
"(",
"$",
"configFile",
")",
";",
"}",
"// Extract messages",
"$",
"extractedCatalogueSource",
"=",
"$",
"this",
"->",
"translator",
"->",
"getCatalogue",
"(",
"$",
"sourceLocale",
")",
";",
"$",
"extractedCatalogueTarget",
"=",
"$",
"this",
"->",
"translator",
"->",
"getCatalogue",
"(",
"$",
"targetLocale",
")",
";",
"$",
"allMessagesSource",
"=",
"$",
"extractedCatalogueSource",
"->",
"all",
"(",
"$",
"domain",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"domain",
")",
"{",
"$",
"allMessagesSource",
"=",
"array",
"(",
"$",
"domain",
"=>",
"$",
"allMessagesSource",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"checkExtractMessages",
"(",
"$",
"io",
",",
"$",
"allMessagesSource",
",",
"$",
"domain",
",",
"$",
"sourceLocale",
")",
")",
"{",
"return",
";",
"}",
"$",
"allMessagesTarget",
"=",
"$",
"extractedCatalogueTarget",
"->",
"all",
"(",
"$",
"domain",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"domain",
")",
"{",
"$",
"allMessagesTarget",
"=",
"array",
"(",
"$",
"domain",
"=>",
"$",
"allMessagesTarget",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"checkExtractMessages",
"(",
"$",
"io",
",",
"$",
"allMessagesTarget",
",",
"$",
"domain",
",",
"$",
"targetLocale",
")",
")",
"{",
"return",
";",
"}",
"//Diff",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"allMessagesSource",
"as",
"$",
"domain",
"=>",
"$",
"messages",
")",
"{",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"id",
"=>",
"$",
"message",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"allMessagesTarget",
"[",
"$",
"domain",
"]",
"[",
"$",
"id",
"]",
")",
"&&",
"!",
"$",
"this",
"->",
"ignoreMissingMessage",
"(",
"$",
"targetLocale",
",",
"$",
"domain",
",",
"$",
"id",
",",
"$",
"config",
")",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"[",
"'<error>Missing</error>'",
",",
"$",
"domain",
",",
"$",
"id",
",",
"$",
"message",
"]",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"allMessagesTarget",
"as",
"$",
"domain",
"=>",
"$",
"messages",
")",
"{",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"id",
"=>",
"$",
"message",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"allMessagesSource",
"[",
"$",
"domain",
"]",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"[",
"'<info>Unused</info>'",
",",
"$",
"domain",
",",
"$",
"id",
",",
"$",
"message",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"rows",
")",
">",
"0",
")",
"{",
"$",
"headers",
"=",
"array",
"(",
"'State'",
",",
"'Domain'",
",",
"'Id'",
",",
"'Messsage'",
")",
";",
"$",
"io",
"->",
"table",
"(",
"$",
"headers",
",",
"$",
"rows",
")",
";",
"return",
"2",
";",
"}",
"else",
"{",
"$",
"io",
"->",
"success",
"(",
"'No error.'",
")",
";",
"}",
"return",
"0",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/e-commit/EcommitUtilBundle/blob/2ee5ddae7709e8ad4412739cbecda28e0590da8b/Command/CompareLocalesCommand.php#L72-L133 |
e-commit/EcommitUtilBundle | Command/CompareLocalesCommand.php | CompareLocalesCommand.ignoreMissingMessage | protected function ignoreMissingMessage($locale, $domain, $messageId, $config)
{
if (!isset($config['ignore_missing_messages'])) {
return false;
}
if (!isset($config['ignore_missing_messages'][$domain])) {
return false;
}
foreach ([$locale, 'all'] as $lang) {
if (isset($config['ignore_missing_messages'][$domain][$lang]) && in_array($messageId, $config['ignore_missing_messages'][$domain][$lang])) {
return true;
}
}
return false;
} | php | protected function ignoreMissingMessage($locale, $domain, $messageId, $config)
{
if (!isset($config['ignore_missing_messages'])) {
return false;
}
if (!isset($config['ignore_missing_messages'][$domain])) {
return false;
}
foreach ([$locale, 'all'] as $lang) {
if (isset($config['ignore_missing_messages'][$domain][$lang]) && in_array($messageId, $config['ignore_missing_messages'][$domain][$lang])) {
return true;
}
}
return false;
} | [
"protected",
"function",
"ignoreMissingMessage",
"(",
"$",
"locale",
",",
"$",
"domain",
",",
"$",
"messageId",
",",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'ignore_missing_messages'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'ignore_missing_messages'",
"]",
"[",
"$",
"domain",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"[",
"$",
"locale",
",",
"'all'",
"]",
"as",
"$",
"lang",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'ignore_missing_messages'",
"]",
"[",
"$",
"domain",
"]",
"[",
"$",
"lang",
"]",
")",
"&&",
"in_array",
"(",
"$",
"messageId",
",",
"$",
"config",
"[",
"'ignore_missing_messages'",
"]",
"[",
"$",
"domain",
"]",
"[",
"$",
"lang",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | @param string $locale
@param string $domain
@param string $messageId
@param array $config
@return bool | [
"@param",
"string",
"$locale",
"@param",
"string",
"$domain",
"@param",
"string",
"$messageId",
"@param",
"array",
"$config"
] | train | https://github.com/e-commit/EcommitUtilBundle/blob/2ee5ddae7709e8ad4412739cbecda28e0590da8b/Command/CompareLocalesCommand.php#L167-L183 |
PenoaksDev/Milky-Framework | src/Milky/Account/Permissions/PermissionManager.php | PermissionManager.getPermission | public function getPermission( $namespace )
{
$node = Arr::get( $this->cachedPermissions, $namespace . '.__node' );
if ( !$node )
{
$node = new Permission( $this, basename( str_replace( ".", "/", $namespace ) ) );
Arr::set( $this->cachedPermissions, $namespace . '.__node', $node );
}
return $node;
} | php | public function getPermission( $namespace )
{
$node = Arr::get( $this->cachedPermissions, $namespace . '.__node' );
if ( !$node )
{
$node = new Permission( $this, basename( str_replace( ".", "/", $namespace ) ) );
Arr::set( $this->cachedPermissions, $namespace . '.__node', $node );
}
return $node;
} | [
"public",
"function",
"getPermission",
"(",
"$",
"namespace",
")",
"{",
"$",
"node",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"cachedPermissions",
",",
"$",
"namespace",
".",
"'.__node'",
")",
";",
"if",
"(",
"!",
"$",
"node",
")",
"{",
"$",
"node",
"=",
"new",
"Permission",
"(",
"$",
"this",
",",
"basename",
"(",
"str_replace",
"(",
"\".\"",
",",
"\"/\"",
",",
"$",
"namespace",
")",
")",
")",
";",
"Arr",
"::",
"set",
"(",
"$",
"this",
"->",
"cachedPermissions",
",",
"$",
"namespace",
".",
"'.__node'",
",",
"$",
"node",
")",
";",
"}",
"return",
"$",
"node",
";",
"}"
] | @param $namespace
@return Permission | [
"@param",
"$namespace"
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Account/Permissions/PermissionManager.php#L59-L69 |
PenoaksDev/Milky-Framework | src/Milky/Account/Permissions/PermissionManager.php | PermissionManager.policy | public function policy( Policy $policy )
{
$this->loadedPolicies[] = $policy;
// Caches the policy nodes as a nestable tree
foreach ( $policy->getNodes() as $namespace => $callable )
$this->getPermission( $namespace )->addPolicyMethod( $callable );
} | php | public function policy( Policy $policy )
{
$this->loadedPolicies[] = $policy;
// Caches the policy nodes as a nestable tree
foreach ( $policy->getNodes() as $namespace => $callable )
$this->getPermission( $namespace )->addPolicyMethod( $callable );
} | [
"public",
"function",
"policy",
"(",
"Policy",
"$",
"policy",
")",
"{",
"$",
"this",
"->",
"loadedPolicies",
"[",
"]",
"=",
"$",
"policy",
";",
"// Caches the policy nodes as a nestable tree",
"foreach",
"(",
"$",
"policy",
"->",
"getNodes",
"(",
")",
"as",
"$",
"namespace",
"=>",
"$",
"callable",
")",
"$",
"this",
"->",
"getPermission",
"(",
"$",
"namespace",
")",
"->",
"addPolicyMethod",
"(",
"$",
"callable",
")",
";",
"}"
] | Adds a new policy checker.
Policies are checked for permissions before they are checked by the general permission backend
@param Policy $policy | [
"Adds",
"a",
"new",
"policy",
"checker",
"."
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Account/Permissions/PermissionManager.php#L78-L85 |
PenoaksDev/Milky-Framework | src/Milky/Account/Permissions/PermissionManager.php | PermissionManager.checkRaw | protected function checkRaw( $namespace, PermissibleEntity $entity = null )
{
if ( $namespace == null || strlen( $namespace ) == 0 || $namespace == "everybody" || $namespace == "-1" )
$namespace = Permission::EVERYBODY;
if ( $namespace == "op" || $namespace == "0" )
$namespace = Permission::OP;
if ( $namespace == "admin" )
$namespace = Permission::ADMIN;
if ( $namespace == "banned" )
$namespace = Permission::BANNED;
if ( $namespace == "whitelisted" )
$namespace = Permission::WHITELISTED;
$namespace = static::getAlias( $namespace );
if ( !preg_match( "/[a-z0-9_.]*/", $namespace ) )
throw new PermissionException( "The permission namespace [$namespace] can only contain the characters 'a-z0-9_.'." );
$permission_defaults = PermissionDefaults::find( $namespace );
if ( $entity === null )
{
if ( !Acct::check() )
{
$result = $this->checkWalker( $namespace, [] );
if ( $result == PermissionValues::UNSET )
$result = $permission_defaults->value_default;
return $result;
}
$entity = Acct::acct();
}
$group_state = PermissionValues::UNSET;
/*
* Check group permissible state
*/
foreach ( $entity->groups() as $group )
{
$group_state = $this->checkRaw( $namespace, $group );
if ( $group_state == PermissionValues::ALWAYS || $group_state == PermissionValues::NEVER )
break;
}
/*
* Check user permissible state
*/
$user_state = $this->checkWalker( $namespace, $entity->permissions() );
if ( $group_state == PermissionValues::ALWAYS || $group_state == PermissionValues::NEVER )
{
if ( $user_state == PermissionValues::ALWAYS )
return true;
else if ( $user_state == PermissionValues::NEVER )
return false;
else
return $group_state;
}
else if ( $group_state == PermissionValues::UNSET && $user_state == PermissionValues::UNSET )
return $permission_defaults->value_default;
else if ( $user_state == PermissionValues::UNSET )
return $group_state;
else // if ( $group_state == PermissionValues::UNSET )
return $user_state;
} | php | protected function checkRaw( $namespace, PermissibleEntity $entity = null )
{
if ( $namespace == null || strlen( $namespace ) == 0 || $namespace == "everybody" || $namespace == "-1" )
$namespace = Permission::EVERYBODY;
if ( $namespace == "op" || $namespace == "0" )
$namespace = Permission::OP;
if ( $namespace == "admin" )
$namespace = Permission::ADMIN;
if ( $namespace == "banned" )
$namespace = Permission::BANNED;
if ( $namespace == "whitelisted" )
$namespace = Permission::WHITELISTED;
$namespace = static::getAlias( $namespace );
if ( !preg_match( "/[a-z0-9_.]*/", $namespace ) )
throw new PermissionException( "The permission namespace [$namespace] can only contain the characters 'a-z0-9_.'." );
$permission_defaults = PermissionDefaults::find( $namespace );
if ( $entity === null )
{
if ( !Acct::check() )
{
$result = $this->checkWalker( $namespace, [] );
if ( $result == PermissionValues::UNSET )
$result = $permission_defaults->value_default;
return $result;
}
$entity = Acct::acct();
}
$group_state = PermissionValues::UNSET;
/*
* Check group permissible state
*/
foreach ( $entity->groups() as $group )
{
$group_state = $this->checkRaw( $namespace, $group );
if ( $group_state == PermissionValues::ALWAYS || $group_state == PermissionValues::NEVER )
break;
}
/*
* Check user permissible state
*/
$user_state = $this->checkWalker( $namespace, $entity->permissions() );
if ( $group_state == PermissionValues::ALWAYS || $group_state == PermissionValues::NEVER )
{
if ( $user_state == PermissionValues::ALWAYS )
return true;
else if ( $user_state == PermissionValues::NEVER )
return false;
else
return $group_state;
}
else if ( $group_state == PermissionValues::UNSET && $user_state == PermissionValues::UNSET )
return $permission_defaults->value_default;
else if ( $user_state == PermissionValues::UNSET )
return $group_state;
else // if ( $group_state == PermissionValues::UNSET )
return $user_state;
} | [
"protected",
"function",
"checkRaw",
"(",
"$",
"namespace",
",",
"PermissibleEntity",
"$",
"entity",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"namespace",
"==",
"null",
"||",
"strlen",
"(",
"$",
"namespace",
")",
"==",
"0",
"||",
"$",
"namespace",
"==",
"\"everybody\"",
"||",
"$",
"namespace",
"==",
"\"-1\"",
")",
"$",
"namespace",
"=",
"Permission",
"::",
"EVERYBODY",
";",
"if",
"(",
"$",
"namespace",
"==",
"\"op\"",
"||",
"$",
"namespace",
"==",
"\"0\"",
")",
"$",
"namespace",
"=",
"Permission",
"::",
"OP",
";",
"if",
"(",
"$",
"namespace",
"==",
"\"admin\"",
")",
"$",
"namespace",
"=",
"Permission",
"::",
"ADMIN",
";",
"if",
"(",
"$",
"namespace",
"==",
"\"banned\"",
")",
"$",
"namespace",
"=",
"Permission",
"::",
"BANNED",
";",
"if",
"(",
"$",
"namespace",
"==",
"\"whitelisted\"",
")",
"$",
"namespace",
"=",
"Permission",
"::",
"WHITELISTED",
";",
"$",
"namespace",
"=",
"static",
"::",
"getAlias",
"(",
"$",
"namespace",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"\"/[a-z0-9_.]*/\"",
",",
"$",
"namespace",
")",
")",
"throw",
"new",
"PermissionException",
"(",
"\"The permission namespace [$namespace] can only contain the characters 'a-z0-9_.'.\"",
")",
";",
"$",
"permission_defaults",
"=",
"PermissionDefaults",
"::",
"find",
"(",
"$",
"namespace",
")",
";",
"if",
"(",
"$",
"entity",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"Acct",
"::",
"check",
"(",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"checkWalker",
"(",
"$",
"namespace",
",",
"[",
"]",
")",
";",
"if",
"(",
"$",
"result",
"==",
"PermissionValues",
"::",
"UNSET",
")",
"$",
"result",
"=",
"$",
"permission_defaults",
"->",
"value_default",
";",
"return",
"$",
"result",
";",
"}",
"$",
"entity",
"=",
"Acct",
"::",
"acct",
"(",
")",
";",
"}",
"$",
"group_state",
"=",
"PermissionValues",
"::",
"UNSET",
";",
"/*\n\t\t * Check group permissible state\n\t\t */",
"foreach",
"(",
"$",
"entity",
"->",
"groups",
"(",
")",
"as",
"$",
"group",
")",
"{",
"$",
"group_state",
"=",
"$",
"this",
"->",
"checkRaw",
"(",
"$",
"namespace",
",",
"$",
"group",
")",
";",
"if",
"(",
"$",
"group_state",
"==",
"PermissionValues",
"::",
"ALWAYS",
"||",
"$",
"group_state",
"==",
"PermissionValues",
"::",
"NEVER",
")",
"break",
";",
"}",
"/*\n\t\t * Check user permissible state\n\t\t */",
"$",
"user_state",
"=",
"$",
"this",
"->",
"checkWalker",
"(",
"$",
"namespace",
",",
"$",
"entity",
"->",
"permissions",
"(",
")",
")",
";",
"if",
"(",
"$",
"group_state",
"==",
"PermissionValues",
"::",
"ALWAYS",
"||",
"$",
"group_state",
"==",
"PermissionValues",
"::",
"NEVER",
")",
"{",
"if",
"(",
"$",
"user_state",
"==",
"PermissionValues",
"::",
"ALWAYS",
")",
"return",
"true",
";",
"else",
"if",
"(",
"$",
"user_state",
"==",
"PermissionValues",
"::",
"NEVER",
")",
"return",
"false",
";",
"else",
"return",
"$",
"group_state",
";",
"}",
"else",
"if",
"(",
"$",
"group_state",
"==",
"PermissionValues",
"::",
"UNSET",
"&&",
"$",
"user_state",
"==",
"PermissionValues",
"::",
"UNSET",
")",
"return",
"$",
"permission_defaults",
"->",
"value_default",
";",
"else",
"if",
"(",
"$",
"user_state",
"==",
"PermissionValues",
"::",
"UNSET",
")",
"return",
"$",
"group_state",
";",
"else",
"// if ( $group_state == PermissionValues::UNSET )",
"return",
"$",
"user_state",
";",
"}"
] | Checks a raw singular namespace and returns the unhindered result
@param $namespace
@param PermissibleEntity|null $entity
@return string | [
"Checks",
"a",
"raw",
"singular",
"namespace",
"and",
"returns",
"the",
"unhindered",
"result"
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Account/Permissions/PermissionManager.php#L178-L243 |
PenoaksDev/Milky-Framework | src/Milky/Account/Permissions/PermissionManager.php | PermissionManager.check | public function check( $namespaces, PermissibleModel $model = null, PermissibleEntity $entity = null )
{
// Allows for static calling
$instance = $this ?: self::i();
if ( !is_array( $namespaces ) )
$namespaces = [$namespaces];
foreach ( $namespaces as &$ns )
{
if ( !is_string( $ns ) )
throw new PermissionException( "The permission namespace must be a string." );
$ns = static::getAlias( $ns );
if ( !preg_match( "/[a-z0-9_.]*/", $ns ) )
throw new PermissionException( "The permission namespace [$ns] can only contain the characters 'a-z0-9_.'." );
}
if ( $model != null )
{
if ( $model instanceof PermissibleModel )
{
$namespaces_new = $namespaces;
foreach ( $model->getIdentifiers() as $key => $id )
$namespaces_new = str_replace( "{" . $key . "}", $id, $namespaces_new );
// Removes untouched values. Seems like a good idea, except in the cast that the user wishes to check a generic permission node.
// $namespaces_new = array_diff( $namespaces_new, array_intersect( $namespaces_new, $namespaces ) );
// Log::debug( "Amending namespaces [" . str_replace( "\n", "", var_export( $namespaces, true ) ) . "] with model [" . get_class( $model ) . "] resulting in [" . str_replace( "\n", "", var_export( $namespaces_new, true ) ) . "]" );
return $instance->check( $namespaces_new, null, $entity );
}
else
throw new PermissionException( "The 'model' must implement PermissibleModel." );
}
$current_state = PermissionValues::UNSET;
array_walk( $namespaces, function ( $ns ) use ( &$instance, &$entity, &$current_state )
{
$current_state = $instance->checkRaw( $ns, $entity );
Log::debug( "Checking permission [" . $ns . "] on entity [" . ( $entity ? get_class( $entity ) : "null" ) . "] with result [" . $current_state . "]" );
if ( $current_state == PermissionValues::ALWAYS )
return true;
if ( $current_state == PermissionValues::NEVER )
return false;
if ( $current_state == PermissionValues::UNSET || !PermissionValues::valid( $current_state ) )
throw new PermissionException( "Permission Exception!" );
} );
return $current_state == PermissionValues::YES;
} | php | public function check( $namespaces, PermissibleModel $model = null, PermissibleEntity $entity = null )
{
// Allows for static calling
$instance = $this ?: self::i();
if ( !is_array( $namespaces ) )
$namespaces = [$namespaces];
foreach ( $namespaces as &$ns )
{
if ( !is_string( $ns ) )
throw new PermissionException( "The permission namespace must be a string." );
$ns = static::getAlias( $ns );
if ( !preg_match( "/[a-z0-9_.]*/", $ns ) )
throw new PermissionException( "The permission namespace [$ns] can only contain the characters 'a-z0-9_.'." );
}
if ( $model != null )
{
if ( $model instanceof PermissibleModel )
{
$namespaces_new = $namespaces;
foreach ( $model->getIdentifiers() as $key => $id )
$namespaces_new = str_replace( "{" . $key . "}", $id, $namespaces_new );
// Removes untouched values. Seems like a good idea, except in the cast that the user wishes to check a generic permission node.
// $namespaces_new = array_diff( $namespaces_new, array_intersect( $namespaces_new, $namespaces ) );
// Log::debug( "Amending namespaces [" . str_replace( "\n", "", var_export( $namespaces, true ) ) . "] with model [" . get_class( $model ) . "] resulting in [" . str_replace( "\n", "", var_export( $namespaces_new, true ) ) . "]" );
return $instance->check( $namespaces_new, null, $entity );
}
else
throw new PermissionException( "The 'model' must implement PermissibleModel." );
}
$current_state = PermissionValues::UNSET;
array_walk( $namespaces, function ( $ns ) use ( &$instance, &$entity, &$current_state )
{
$current_state = $instance->checkRaw( $ns, $entity );
Log::debug( "Checking permission [" . $ns . "] on entity [" . ( $entity ? get_class( $entity ) : "null" ) . "] with result [" . $current_state . "]" );
if ( $current_state == PermissionValues::ALWAYS )
return true;
if ( $current_state == PermissionValues::NEVER )
return false;
if ( $current_state == PermissionValues::UNSET || !PermissionValues::valid( $current_state ) )
throw new PermissionException( "Permission Exception!" );
} );
return $current_state == PermissionValues::YES;
} | [
"public",
"function",
"check",
"(",
"$",
"namespaces",
",",
"PermissibleModel",
"$",
"model",
"=",
"null",
",",
"PermissibleEntity",
"$",
"entity",
"=",
"null",
")",
"{",
"// Allows for static calling",
"$",
"instance",
"=",
"$",
"this",
"?",
":",
"self",
"::",
"i",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"namespaces",
")",
")",
"$",
"namespaces",
"=",
"[",
"$",
"namespaces",
"]",
";",
"foreach",
"(",
"$",
"namespaces",
"as",
"&",
"$",
"ns",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"ns",
")",
")",
"throw",
"new",
"PermissionException",
"(",
"\"The permission namespace must be a string.\"",
")",
";",
"$",
"ns",
"=",
"static",
"::",
"getAlias",
"(",
"$",
"ns",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"\"/[a-z0-9_.]*/\"",
",",
"$",
"ns",
")",
")",
"throw",
"new",
"PermissionException",
"(",
"\"The permission namespace [$ns] can only contain the characters 'a-z0-9_.'.\"",
")",
";",
"}",
"if",
"(",
"$",
"model",
"!=",
"null",
")",
"{",
"if",
"(",
"$",
"model",
"instanceof",
"PermissibleModel",
")",
"{",
"$",
"namespaces_new",
"=",
"$",
"namespaces",
";",
"foreach",
"(",
"$",
"model",
"->",
"getIdentifiers",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"id",
")",
"$",
"namespaces_new",
"=",
"str_replace",
"(",
"\"{\"",
".",
"$",
"key",
".",
"\"}\"",
",",
"$",
"id",
",",
"$",
"namespaces_new",
")",
";",
"// Removes untouched values. Seems like a good idea, except in the cast that the user wishes to check a generic permission node.",
"// $namespaces_new = array_diff( $namespaces_new, array_intersect( $namespaces_new, $namespaces ) );",
"// Log::debug( \"Amending namespaces [\" . str_replace( \"\\n\", \"\", var_export( $namespaces, true ) ) . \"] with model [\" . get_class( $model ) . \"] resulting in [\" . str_replace( \"\\n\", \"\", var_export( $namespaces_new, true ) ) . \"]\" );",
"return",
"$",
"instance",
"->",
"check",
"(",
"$",
"namespaces_new",
",",
"null",
",",
"$",
"entity",
")",
";",
"}",
"else",
"throw",
"new",
"PermissionException",
"(",
"\"The 'model' must implement PermissibleModel.\"",
")",
";",
"}",
"$",
"current_state",
"=",
"PermissionValues",
"::",
"UNSET",
";",
"array_walk",
"(",
"$",
"namespaces",
",",
"function",
"(",
"$",
"ns",
")",
"use",
"(",
"&",
"$",
"instance",
",",
"&",
"$",
"entity",
",",
"&",
"$",
"current_state",
")",
"{",
"$",
"current_state",
"=",
"$",
"instance",
"->",
"checkRaw",
"(",
"$",
"ns",
",",
"$",
"entity",
")",
";",
"Log",
"::",
"debug",
"(",
"\"Checking permission [\"",
".",
"$",
"ns",
".",
"\"] on entity [\"",
".",
"(",
"$",
"entity",
"?",
"get_class",
"(",
"$",
"entity",
")",
":",
"\"null\"",
")",
".",
"\"] with result [\"",
".",
"$",
"current_state",
".",
"\"]\"",
")",
";",
"if",
"(",
"$",
"current_state",
"==",
"PermissionValues",
"::",
"ALWAYS",
")",
"return",
"true",
";",
"if",
"(",
"$",
"current_state",
"==",
"PermissionValues",
"::",
"NEVER",
")",
"return",
"false",
";",
"if",
"(",
"$",
"current_state",
"==",
"PermissionValues",
"::",
"UNSET",
"||",
"!",
"PermissionValues",
"::",
"valid",
"(",
"$",
"current_state",
")",
")",
"throw",
"new",
"PermissionException",
"(",
"\"Permission Exception!\"",
")",
";",
"}",
")",
";",
"return",
"$",
"current_state",
"==",
"PermissionValues",
"::",
"YES",
";",
"}"
] | Checks a permission for assignment and policy checks
@param string|array $namespace
@param PermissibleEntity|null $entity
@return bool | [
"Checks",
"a",
"permission",
"for",
"assignment",
"and",
"policy",
"checks"
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Account/Permissions/PermissionManager.php#L253-L308 |
danielgp/common-lib | source/DomCssAndJavascriptByDanielGPwithCDN.php | DomCssAndJavascriptByDanielGPwithCDN.setCssFileCDN | protected function setCssFileCDN($cssFileName)
{
$patternFound = null;
if (strpos(pathinfo($cssFileName)['basename'], 'font-awesome-') !== false) {
$patternFound = $this->setCssFileCDNforFontAwesome($cssFileName);
}
if (is_null($patternFound)) {
$patternFound = [false, $this->sanitizeString($cssFileName)];
}
return $patternFound;
} | php | protected function setCssFileCDN($cssFileName)
{
$patternFound = null;
if (strpos(pathinfo($cssFileName)['basename'], 'font-awesome-') !== false) {
$patternFound = $this->setCssFileCDNforFontAwesome($cssFileName);
}
if (is_null($patternFound)) {
$patternFound = [false, $this->sanitizeString($cssFileName)];
}
return $patternFound;
} | [
"protected",
"function",
"setCssFileCDN",
"(",
"$",
"cssFileName",
")",
"{",
"$",
"patternFound",
"=",
"null",
";",
"if",
"(",
"strpos",
"(",
"pathinfo",
"(",
"$",
"cssFileName",
")",
"[",
"'basename'",
"]",
",",
"'font-awesome-'",
")",
"!==",
"false",
")",
"{",
"$",
"patternFound",
"=",
"$",
"this",
"->",
"setCssFileCDNforFontAwesome",
"(",
"$",
"cssFileName",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"patternFound",
")",
")",
"{",
"$",
"patternFound",
"=",
"[",
"false",
",",
"$",
"this",
"->",
"sanitizeString",
"(",
"$",
"cssFileName",
")",
"]",
";",
"}",
"return",
"$",
"patternFound",
";",
"}"
] | Manages all known CSS that can be handled through CDNs
@param string $cssFileName
@return array|string | [
"Manages",
"all",
"known",
"CSS",
"that",
"can",
"be",
"handled",
"through",
"CDNs"
] | train | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomCssAndJavascriptByDanielGPwithCDN.php#L78-L88 |
danielgp/common-lib | source/DomCssAndJavascriptByDanielGPwithCDN.php | DomCssAndJavascriptByDanielGPwithCDN.setJavascriptFileCDN | protected function setJavascriptFileCDN($jsFileName)
{
$onlyFileName = pathinfo($jsFileName)['basename'];
$patternFound = null;
if (in_array($onlyFileName, ['jquery.placeholder.min.js', 'jquery.easing.1.3.min.js'])) {
$patternFound = $this->setJavascriptFileCDNjQueryLibs($jsFileName);
} elseif (strpos($onlyFileName, '-') !== false) {
$patternFound = $this->setJavascriptFileCDNbyPattern($jsFileName);
}
if (is_null($patternFound)) {
$patternFound = [false, $this->sanitizeString($jsFileName), ''];
}
return $patternFound;
} | php | protected function setJavascriptFileCDN($jsFileName)
{
$onlyFileName = pathinfo($jsFileName)['basename'];
$patternFound = null;
if (in_array($onlyFileName, ['jquery.placeholder.min.js', 'jquery.easing.1.3.min.js'])) {
$patternFound = $this->setJavascriptFileCDNjQueryLibs($jsFileName);
} elseif (strpos($onlyFileName, '-') !== false) {
$patternFound = $this->setJavascriptFileCDNbyPattern($jsFileName);
}
if (is_null($patternFound)) {
$patternFound = [false, $this->sanitizeString($jsFileName), ''];
}
return $patternFound;
} | [
"protected",
"function",
"setJavascriptFileCDN",
"(",
"$",
"jsFileName",
")",
"{",
"$",
"onlyFileName",
"=",
"pathinfo",
"(",
"$",
"jsFileName",
")",
"[",
"'basename'",
"]",
";",
"$",
"patternFound",
"=",
"null",
";",
"if",
"(",
"in_array",
"(",
"$",
"onlyFileName",
",",
"[",
"'jquery.placeholder.min.js'",
",",
"'jquery.easing.1.3.min.js'",
"]",
")",
")",
"{",
"$",
"patternFound",
"=",
"$",
"this",
"->",
"setJavascriptFileCDNjQueryLibs",
"(",
"$",
"jsFileName",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"onlyFileName",
",",
"'-'",
")",
"!==",
"false",
")",
"{",
"$",
"patternFound",
"=",
"$",
"this",
"->",
"setJavascriptFileCDNbyPattern",
"(",
"$",
"jsFileName",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"patternFound",
")",
")",
"{",
"$",
"patternFound",
"=",
"[",
"false",
",",
"$",
"this",
"->",
"sanitizeString",
"(",
"$",
"jsFileName",
")",
",",
"''",
"]",
";",
"}",
"return",
"$",
"patternFound",
";",
"}"
] | Manages all known Javascript that can be handled through CDNs
(if within local network makes no sense to use CDNs)
@param string $jsFileName
@return array|string | [
"Manages",
"all",
"known",
"Javascript",
"that",
"can",
"be",
"handled",
"through",
"CDNs",
"(",
"if",
"within",
"local",
"network",
"makes",
"no",
"sense",
"to",
"use",
"CDNs",
")"
] | train | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomCssAndJavascriptByDanielGPwithCDN.php#L113-L126 |
danielgp/common-lib | source/DomCssAndJavascriptByDanielGPwithCDN.php | DomCssAndJavascriptByDanielGPwithCDN.setJavascriptFileCDNforHighChartsMain | private function setJavascriptFileCDNforHighChartsMain($jsFileName, $libName)
{
$jsFN = $this->sanitizeString($jsFileName);
$jsVersionlessFN = str_replace([$libName . '-', '.js'], '', pathinfo($jsFileName)['basename'])
. ($libName === 'exporting' ? '/modules' : '');
if (strpos($jsFileName, $libName) !== false) {
return [
true,
$this->sCloundFlareUrl . 'highcharts/' . $jsVersionlessFN . '/' . $libName . '.js',
'<script>!window.Highcharts && document.write(\'<script src="' . $jsFN . '">\x3C/script>\')</script>',
];
}
return null;
} | php | private function setJavascriptFileCDNforHighChartsMain($jsFileName, $libName)
{
$jsFN = $this->sanitizeString($jsFileName);
$jsVersionlessFN = str_replace([$libName . '-', '.js'], '', pathinfo($jsFileName)['basename'])
. ($libName === 'exporting' ? '/modules' : '');
if (strpos($jsFileName, $libName) !== false) {
return [
true,
$this->sCloundFlareUrl . 'highcharts/' . $jsVersionlessFN . '/' . $libName . '.js',
'<script>!window.Highcharts && document.write(\'<script src="' . $jsFN . '">\x3C/script>\')</script>',
];
}
return null;
} | [
"private",
"function",
"setJavascriptFileCDNforHighChartsMain",
"(",
"$",
"jsFileName",
",",
"$",
"libName",
")",
"{",
"$",
"jsFN",
"=",
"$",
"this",
"->",
"sanitizeString",
"(",
"$",
"jsFileName",
")",
";",
"$",
"jsVersionlessFN",
"=",
"str_replace",
"(",
"[",
"$",
"libName",
".",
"'-'",
",",
"'.js'",
"]",
",",
"''",
",",
"pathinfo",
"(",
"$",
"jsFileName",
")",
"[",
"'basename'",
"]",
")",
".",
"(",
"$",
"libName",
"===",
"'exporting'",
"?",
"'/modules'",
":",
"''",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"jsFileName",
",",
"$",
"libName",
")",
"!==",
"false",
")",
"{",
"return",
"[",
"true",
",",
"$",
"this",
"->",
"sCloundFlareUrl",
".",
"'highcharts/'",
".",
"$",
"jsVersionlessFN",
".",
"'/'",
".",
"$",
"libName",
".",
"'.js'",
",",
"'<script>!window.Highcharts && document.write(\\'<script src=\"'",
".",
"$",
"jsFN",
".",
"'\">\\x3C/script>\\')</script>'",
",",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Returns an array with CDN call of a known Javascript library
and fall-back line that points to local cache of it
specific for HighCharts
@param string $jsFileName
@param string $libName
@return array | [
"Returns",
"an",
"array",
"with",
"CDN",
"call",
"of",
"a",
"known",
"Javascript",
"library",
"and",
"fall",
"-",
"back",
"line",
"that",
"points",
"to",
"local",
"cache",
"of",
"it",
"specific",
"for",
"HighCharts"
] | train | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomCssAndJavascriptByDanielGPwithCDN.php#L178-L191 |
danielgp/common-lib | source/DomCssAndJavascriptByDanielGPwithCDN.php | DomCssAndJavascriptByDanielGPwithCDN.setJavascriptFileCDNjQuery | private function setJavascriptFileCDNjQuery($jsFileName)
{
$jQueryPosition = strpos($jsFileName, 'jquery-');
$jQueryMajorVersion = substr($jsFileName, 7, 1);
if (($jQueryPosition !== false) && is_numeric($jQueryMajorVersion) && (substr($jsFileName, -7) == '.min.js')) {
return [
true,
$this->sCloundFlareUrl . 'jquery/' . $this->getCmpltVers($jsFileName, 'jquery-') . '/jquery.min.js',
'<script>window.jQuery || document.write(\'<script src="' . $this->sanitizeString($jsFileName)
. '">\x3C/script>\')</script>',
];
}
return null;
} | php | private function setJavascriptFileCDNjQuery($jsFileName)
{
$jQueryPosition = strpos($jsFileName, 'jquery-');
$jQueryMajorVersion = substr($jsFileName, 7, 1);
if (($jQueryPosition !== false) && is_numeric($jQueryMajorVersion) && (substr($jsFileName, -7) == '.min.js')) {
return [
true,
$this->sCloundFlareUrl . 'jquery/' . $this->getCmpltVers($jsFileName, 'jquery-') . '/jquery.min.js',
'<script>window.jQuery || document.write(\'<script src="' . $this->sanitizeString($jsFileName)
. '">\x3C/script>\')</script>',
];
}
return null;
} | [
"private",
"function",
"setJavascriptFileCDNjQuery",
"(",
"$",
"jsFileName",
")",
"{",
"$",
"jQueryPosition",
"=",
"strpos",
"(",
"$",
"jsFileName",
",",
"'jquery-'",
")",
";",
"$",
"jQueryMajorVersion",
"=",
"substr",
"(",
"$",
"jsFileName",
",",
"7",
",",
"1",
")",
";",
"if",
"(",
"(",
"$",
"jQueryPosition",
"!==",
"false",
")",
"&&",
"is_numeric",
"(",
"$",
"jQueryMajorVersion",
")",
"&&",
"(",
"substr",
"(",
"$",
"jsFileName",
",",
"-",
"7",
")",
"==",
"'.min.js'",
")",
")",
"{",
"return",
"[",
"true",
",",
"$",
"this",
"->",
"sCloundFlareUrl",
".",
"'jquery/'",
".",
"$",
"this",
"->",
"getCmpltVers",
"(",
"$",
"jsFileName",
",",
"'jquery-'",
")",
".",
"'/jquery.min.js'",
",",
"'<script>window.jQuery || document.write(\\'<script src=\"'",
".",
"$",
"this",
"->",
"sanitizeString",
"(",
"$",
"jsFileName",
")",
".",
"'\">\\x3C/script>\\')</script>'",
",",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Returns an array with CDN call of a known Javascript library
and fall-back line that points to local cache of it
specific for jQuery
@param string $jsFileName
@return array | [
"Returns",
"an",
"array",
"with",
"CDN",
"call",
"of",
"a",
"known",
"Javascript",
"library",
"and",
"fall",
"-",
"back",
"line",
"that",
"points",
"to",
"local",
"cache",
"of",
"it",
"specific",
"for",
"jQuery"
] | train | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomCssAndJavascriptByDanielGPwithCDN.php#L201-L214 |
danielgp/common-lib | source/DomCssAndJavascriptByDanielGPwithCDN.php | DomCssAndJavascriptByDanielGPwithCDN.setJavascriptFileCDNjQueryLibs | private function setJavascriptFileCDNjQueryLibs($jsFileName)
{
$sFN = $this->sanitizeString($jsFileName);
$eArray = $this->knownCloudFlareJavascript($sFN);
if (!is_null($eArray['version'])) {
return [
true,
$this->sCloundFlareUrl . $eArray['version'] . $eArray['justFile'],
'<script>' . $eArray['eVerify'] . ' || document.write(\'<script src="' . $sFN
. '">\x3C/script>\')</script>',
];
}
return null;
} | php | private function setJavascriptFileCDNjQueryLibs($jsFileName)
{
$sFN = $this->sanitizeString($jsFileName);
$eArray = $this->knownCloudFlareJavascript($sFN);
if (!is_null($eArray['version'])) {
return [
true,
$this->sCloundFlareUrl . $eArray['version'] . $eArray['justFile'],
'<script>' . $eArray['eVerify'] . ' || document.write(\'<script src="' . $sFN
. '">\x3C/script>\')</script>',
];
}
return null;
} | [
"private",
"function",
"setJavascriptFileCDNjQueryLibs",
"(",
"$",
"jsFileName",
")",
"{",
"$",
"sFN",
"=",
"$",
"this",
"->",
"sanitizeString",
"(",
"$",
"jsFileName",
")",
";",
"$",
"eArray",
"=",
"$",
"this",
"->",
"knownCloudFlareJavascript",
"(",
"$",
"sFN",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"eArray",
"[",
"'version'",
"]",
")",
")",
"{",
"return",
"[",
"true",
",",
"$",
"this",
"->",
"sCloundFlareUrl",
".",
"$",
"eArray",
"[",
"'version'",
"]",
".",
"$",
"eArray",
"[",
"'justFile'",
"]",
",",
"'<script>'",
".",
"$",
"eArray",
"[",
"'eVerify'",
"]",
".",
"' || document.write(\\'<script src=\"'",
".",
"$",
"sFN",
".",
"'\">\\x3C/script>\\')</script>'",
",",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Returns an array with CDN call of a known Javascript library
and fall-back line that points to local cache of it
specific for jQuery Libraries
@param string $jsFileName
@return array | [
"Returns",
"an",
"array",
"with",
"CDN",
"call",
"of",
"a",
"known",
"Javascript",
"library",
"and",
"fall",
"-",
"back",
"line",
"that",
"points",
"to",
"local",
"cache",
"of",
"it",
"specific",
"for",
"jQuery",
"Libraries"
] | train | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomCssAndJavascriptByDanielGPwithCDN.php#L224-L237 |
SysControllers/Admin | src/app/Http/Controllers/Admin/UsersController.php | UsersController.store | public function store(Request $request)
{
$dataProfile = $request->only('nombres', 'apellidos');
$dataUser = $request->only('email', 'password');
$this->validate($request, $this->rulesProfile);
$this->validate($request, $this->rulesUser);
$user = new User($dataUser);
$user->estado = 1;
$user->save();
$userProfile = new UserProfile($dataProfile);
$userProfile->user_id = $user->id;
$userProfile->save();
//MENSAJE
flash()->success('El registro se creó satisfactoriamente.');
//REDIRECCIONAR A PAGINA PARA VER DATOS
return redirect()->route('admin.user.index');
} | php | public function store(Request $request)
{
$dataProfile = $request->only('nombres', 'apellidos');
$dataUser = $request->only('email', 'password');
$this->validate($request, $this->rulesProfile);
$this->validate($request, $this->rulesUser);
$user = new User($dataUser);
$user->estado = 1;
$user->save();
$userProfile = new UserProfile($dataProfile);
$userProfile->user_id = $user->id;
$userProfile->save();
//MENSAJE
flash()->success('El registro se creó satisfactoriamente.');
//REDIRECCIONAR A PAGINA PARA VER DATOS
return redirect()->route('admin.user.index');
} | [
"public",
"function",
"store",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"dataProfile",
"=",
"$",
"request",
"->",
"only",
"(",
"'nombres'",
",",
"'apellidos'",
")",
";",
"$",
"dataUser",
"=",
"$",
"request",
"->",
"only",
"(",
"'email'",
",",
"'password'",
")",
";",
"$",
"this",
"->",
"validate",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"rulesProfile",
")",
";",
"$",
"this",
"->",
"validate",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"rulesUser",
")",
";",
"$",
"user",
"=",
"new",
"User",
"(",
"$",
"dataUser",
")",
";",
"$",
"user",
"->",
"estado",
"=",
"1",
";",
"$",
"user",
"->",
"save",
"(",
")",
";",
"$",
"userProfile",
"=",
"new",
"UserProfile",
"(",
"$",
"dataProfile",
")",
";",
"$",
"userProfile",
"->",
"user_id",
"=",
"$",
"user",
"->",
"id",
";",
"$",
"userProfile",
"->",
"save",
"(",
")",
";",
"//MENSAJE",
"flash",
"(",
")",
"->",
"success",
"(",
"'El registro se creó satisfactoriamente.')",
";",
"",
"//REDIRECCIONAR A PAGINA PARA VER DATOS",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'admin.user.index'",
")",
";",
"}"
] | Store a newly created resource in storage.
@param Request $request
@return Response | [
"Store",
"a",
"newly",
"created",
"resource",
"in",
"storage",
"."
] | train | https://github.com/SysControllers/Admin/blob/8f1df46aca422b87f2f522fbba610dcfa0c5f7f3/src/app/Http/Controllers/Admin/UsersController.php#L66-L87 |
SysControllers/Admin | src/app/Http/Controllers/Admin/UsersController.php | UsersController.update | public function update($id, Request $request)
{
$user = UserProfile::whereUserId($id)->first();
$rules = [
'nombre' => 'required',
'apellidos' => 'required'
];
$this->validate($request, $rules);
$user->fill($request->all());
$user->save();
//MENSAJE
flash()->success('El registro se actualizó satisfactoriamente.');
//REDIRECCIONAR A PAGINA PARA VER DATOS
return redirect()->route('admin.user.index');
} | php | public function update($id, Request $request)
{
$user = UserProfile::whereUserId($id)->first();
$rules = [
'nombre' => 'required',
'apellidos' => 'required'
];
$this->validate($request, $rules);
$user->fill($request->all());
$user->save();
//MENSAJE
flash()->success('El registro se actualizó satisfactoriamente.');
//REDIRECCIONAR A PAGINA PARA VER DATOS
return redirect()->route('admin.user.index');
} | [
"public",
"function",
"update",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"user",
"=",
"UserProfile",
"::",
"whereUserId",
"(",
"$",
"id",
")",
"->",
"first",
"(",
")",
";",
"$",
"rules",
"=",
"[",
"'nombre'",
"=>",
"'required'",
",",
"'apellidos'",
"=>",
"'required'",
"]",
";",
"$",
"this",
"->",
"validate",
"(",
"$",
"request",
",",
"$",
"rules",
")",
";",
"$",
"user",
"->",
"fill",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"$",
"user",
"->",
"save",
"(",
")",
";",
"//MENSAJE",
"flash",
"(",
")",
"->",
"success",
"(",
"'El registro se actualizó satisfactoriamente.')",
";",
"",
"//REDIRECCIONAR A PAGINA PARA VER DATOS",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'admin.user.index'",
")",
";",
"}"
] | Update the specified resource in storage.
@param int $id
@return Response | [
"Update",
"the",
"specified",
"resource",
"in",
"storage",
"."
] | train | https://github.com/SysControllers/Admin/blob/8f1df46aca422b87f2f522fbba610dcfa0c5f7f3/src/app/Http/Controllers/Admin/UsersController.php#L124-L143 |
SysControllers/Admin | src/app/Http/Controllers/Admin/UsersController.php | UsersController.updatePassword | public function updatePassword($id, Request $request)
{
$user = User::findOrFail($id);
$rules = [
'password' => 'required|confirmed',
'password_confirmation' => 'required'
];
$this->validate($request, $rules);
$user->fill($request->all());
$user->save();
//MENSAJE
flash()->success('La contraseña se modificó satisfactoriamente.');
//REDIRECCIONAR A PAGINA PARA VER DATOS
return redirect()->route('admin.user.index');
} | php | public function updatePassword($id, Request $request)
{
$user = User::findOrFail($id);
$rules = [
'password' => 'required|confirmed',
'password_confirmation' => 'required'
];
$this->validate($request, $rules);
$user->fill($request->all());
$user->save();
//MENSAJE
flash()->success('La contraseña se modificó satisfactoriamente.');
//REDIRECCIONAR A PAGINA PARA VER DATOS
return redirect()->route('admin.user.index');
} | [
"public",
"function",
"updatePassword",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"user",
"=",
"User",
"::",
"findOrFail",
"(",
"$",
"id",
")",
";",
"$",
"rules",
"=",
"[",
"'password'",
"=>",
"'required|confirmed'",
",",
"'password_confirmation'",
"=>",
"'required'",
"]",
";",
"$",
"this",
"->",
"validate",
"(",
"$",
"request",
",",
"$",
"rules",
")",
";",
"$",
"user",
"->",
"fill",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"$",
"user",
"->",
"save",
"(",
")",
";",
"//MENSAJE",
"flash",
"(",
")",
"->",
"success",
"(",
"'La contraseña se modificó satisfactoriamente.');",
"",
"",
"//REDIRECCIONAR A PAGINA PARA VER DATOS",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'admin.user.index'",
")",
";",
"}"
] | Funcion para cambiar contraseña de Perfil de usuario logeado | [
"Funcion",
"para",
"cambiar",
"contraseña",
"de",
"Perfil",
"de",
"usuario",
"logeado"
] | train | https://github.com/SysControllers/Admin/blob/8f1df46aca422b87f2f522fbba610dcfa0c5f7f3/src/app/Http/Controllers/Admin/UsersController.php#L148-L167 |
SysControllers/Admin | src/app/Http/Controllers/Admin/UsersController.php | UsersController.profileData | public function profileData()
{
$user = Auth::user();
$profile = UserProfile::whereUserId($user->id)->first();
$data = Input::all();
$rules = [
'nombre' => 'required',
'apellidos' => 'required'
];
$validator = Validator::make($data, $rules);
if($validator->passes())
{
$profile->fill($data);
$profile->save();
//REDIRECCIONAR A PAGINA PARA VER DATOS
return redirect()->route('admin.user.profile');
}
else
{
return Redirect::back()->withInput()->withErrors($validator->messages());
}
} | php | public function profileData()
{
$user = Auth::user();
$profile = UserProfile::whereUserId($user->id)->first();
$data = Input::all();
$rules = [
'nombre' => 'required',
'apellidos' => 'required'
];
$validator = Validator::make($data, $rules);
if($validator->passes())
{
$profile->fill($data);
$profile->save();
//REDIRECCIONAR A PAGINA PARA VER DATOS
return redirect()->route('admin.user.profile');
}
else
{
return Redirect::back()->withInput()->withErrors($validator->messages());
}
} | [
"public",
"function",
"profileData",
"(",
")",
"{",
"$",
"user",
"=",
"Auth",
"::",
"user",
"(",
")",
";",
"$",
"profile",
"=",
"UserProfile",
"::",
"whereUserId",
"(",
"$",
"user",
"->",
"id",
")",
"->",
"first",
"(",
")",
";",
"$",
"data",
"=",
"Input",
"::",
"all",
"(",
")",
";",
"$",
"rules",
"=",
"[",
"'nombre'",
"=>",
"'required'",
",",
"'apellidos'",
"=>",
"'required'",
"]",
";",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"$",
"data",
",",
"$",
"rules",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"passes",
"(",
")",
")",
"{",
"$",
"profile",
"->",
"fill",
"(",
"$",
"data",
")",
";",
"$",
"profile",
"->",
"save",
"(",
")",
";",
"//REDIRECCIONAR A PAGINA PARA VER DATOS",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'admin.user.profile'",
")",
";",
"}",
"else",
"{",
"return",
"Redirect",
"::",
"back",
"(",
")",
"->",
"withInput",
"(",
")",
"->",
"withErrors",
"(",
"$",
"validator",
"->",
"messages",
"(",
")",
")",
";",
"}",
"}"
] | Funcion para cambiar datos de Perfil de usuario logeado | [
"Funcion",
"para",
"cambiar",
"datos",
"de",
"Perfil",
"de",
"usuario",
"logeado"
] | train | https://github.com/SysControllers/Admin/blob/8f1df46aca422b87f2f522fbba610dcfa0c5f7f3/src/app/Http/Controllers/Admin/UsersController.php#L197-L224 |
SysControllers/Admin | src/app/Http/Controllers/Admin/UsersController.php | UsersController.profileChangePassword | public function profileChangePassword()
{
$user = Auth::user();
$data = Input::all();
$rules = [
'password' => 'required|confirmed',
'password_confirmation' => 'required'
];
$validator = Validator::make($data, $rules);
if($validator->passes())
{
$user->fill($data);
$user->save();
//REDIRECCIONAR A PAGINA PARA VER DATOS
return redirect()->route('admin.user.profile');
}
else
{
return Redirect::back()->withInput()->withErrors($validator->messages());
}
} | php | public function profileChangePassword()
{
$user = Auth::user();
$data = Input::all();
$rules = [
'password' => 'required|confirmed',
'password_confirmation' => 'required'
];
$validator = Validator::make($data, $rules);
if($validator->passes())
{
$user->fill($data);
$user->save();
//REDIRECCIONAR A PAGINA PARA VER DATOS
return redirect()->route('admin.user.profile');
}
else
{
return Redirect::back()->withInput()->withErrors($validator->messages());
}
} | [
"public",
"function",
"profileChangePassword",
"(",
")",
"{",
"$",
"user",
"=",
"Auth",
"::",
"user",
"(",
")",
";",
"$",
"data",
"=",
"Input",
"::",
"all",
"(",
")",
";",
"$",
"rules",
"=",
"[",
"'password'",
"=>",
"'required|confirmed'",
",",
"'password_confirmation'",
"=>",
"'required'",
"]",
";",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"$",
"data",
",",
"$",
"rules",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"passes",
"(",
")",
")",
"{",
"$",
"user",
"->",
"fill",
"(",
"$",
"data",
")",
";",
"$",
"user",
"->",
"save",
"(",
")",
";",
"//REDIRECCIONAR A PAGINA PARA VER DATOS",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'admin.user.profile'",
")",
";",
"}",
"else",
"{",
"return",
"Redirect",
"::",
"back",
"(",
")",
"->",
"withInput",
"(",
")",
"->",
"withErrors",
"(",
"$",
"validator",
"->",
"messages",
"(",
")",
")",
";",
"}",
"}"
] | Funcion para cambiar contraseña de Perfil de usuario logeado | [
"Funcion",
"para",
"cambiar",
"contraseña",
"de",
"Perfil",
"de",
"usuario",
"logeado"
] | train | https://github.com/SysControllers/Admin/blob/8f1df46aca422b87f2f522fbba610dcfa0c5f7f3/src/app/Http/Controllers/Admin/UsersController.php#L230-L255 |
koolkode/lexer | src/AbstractTokenSequence.php | AbstractTokenSequence.contains | public function contains($type)
{
foreach($this->tokens as $token)
{
if($token->is($type))
{
return true;
}
}
return false;
} | php | public function contains($type)
{
foreach($this->tokens as $token)
{
if($token->is($type))
{
return true;
}
}
return false;
} | [
"public",
"function",
"contains",
"(",
"$",
"type",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"tokens",
"as",
"$",
"token",
")",
"{",
"if",
"(",
"$",
"token",
"->",
"is",
"(",
"$",
"type",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if the sequence contains at least one token of the given type.
@param integer $type
@return boolean | [
"Check",
"if",
"the",
"sequence",
"contains",
"at",
"least",
"one",
"token",
"of",
"the",
"given",
"type",
"."
] | train | https://github.com/koolkode/lexer/blob/1f33fb4e95bf3b6b21c63187e503bbe612a1646c/src/AbstractTokenSequence.php#L42-L53 |
koolkode/lexer | src/AbstractTokenSequence.php | AbstractTokenSequence.containsOneOf | public function containsOneOf(array $types)
{
foreach($this->tokens as $token)
{
if($token->isOneOf($types))
{
return true;
}
}
return false;
} | php | public function containsOneOf(array $types)
{
foreach($this->tokens as $token)
{
if($token->isOneOf($types))
{
return true;
}
}
return false;
} | [
"public",
"function",
"containsOneOf",
"(",
"array",
"$",
"types",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"tokens",
"as",
"$",
"token",
")",
"{",
"if",
"(",
"$",
"token",
"->",
"isOneOf",
"(",
"$",
"types",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if the sequence contains at least one token of any of the given token types.
@param array<integer> $types
@return boolean | [
"Check",
"if",
"the",
"sequence",
"contains",
"at",
"least",
"one",
"token",
"of",
"any",
"of",
"the",
"given",
"token",
"types",
"."
] | train | https://github.com/koolkode/lexer/blob/1f33fb4e95bf3b6b21c63187e503bbe612a1646c/src/AbstractTokenSequence.php#L61-L72 |
koolkode/lexer | src/AbstractTokenSequence.php | AbstractTokenSequence.endsWith | public function endsWith($type)
{
if(empty($this->tokens))
{
return false;
}
return $this->tokens[count($this->tokens) - 1]->is($type);
} | php | public function endsWith($type)
{
if(empty($this->tokens))
{
return false;
}
return $this->tokens[count($this->tokens) - 1]->is($type);
} | [
"public",
"function",
"endsWith",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"tokens",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"tokens",
"[",
"count",
"(",
"$",
"this",
"->",
"tokens",
")",
"-",
"1",
"]",
"->",
"is",
"(",
"$",
"type",
")",
";",
"}"
] | Check if the sequence ends with a token of the given token type.
@param integer $type
@return boolean | [
"Check",
"if",
"the",
"sequence",
"ends",
"with",
"a",
"token",
"of",
"the",
"given",
"token",
"type",
"."
] | train | https://github.com/koolkode/lexer/blob/1f33fb4e95bf3b6b21c63187e503bbe612a1646c/src/AbstractTokenSequence.php#L80-L88 |
koolkode/http | src/HttpResponse.php | HttpResponse.setStatus | public function setStatus($status)
{
$status = (int)$status;
if($status < 100)
{
throw new \InvalidArgumentException(sprintf('Invalid HTTP status code: %u', $status));
}
if($status >= 600)
{
throw new \InvalidArgumentException(sprintf('Invalid HTTP status code: %u', $status));
}
$this->status = $status;
return $this;
} | php | public function setStatus($status)
{
$status = (int)$status;
if($status < 100)
{
throw new \InvalidArgumentException(sprintf('Invalid HTTP status code: %u', $status));
}
if($status >= 600)
{
throw new \InvalidArgumentException(sprintf('Invalid HTTP status code: %u', $status));
}
$this->status = $status;
return $this;
} | [
"public",
"function",
"setStatus",
"(",
"$",
"status",
")",
"{",
"$",
"status",
"=",
"(",
"int",
")",
"$",
"status",
";",
"if",
"(",
"$",
"status",
"<",
"100",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid HTTP status code: %u'",
",",
"$",
"status",
")",
")",
";",
"}",
"if",
"(",
"$",
"status",
">=",
"600",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid HTTP status code: %u'",
",",
"$",
"status",
")",
")",
";",
"}",
"$",
"this",
"->",
"status",
"=",
"$",
"status",
";",
"return",
"$",
"this",
";",
"}"
] | Set the HTTP status of this response.
@param integer $status
@return HttpResponse
@throws \InvalidArgumentException | [
"Set",
"the",
"HTTP",
"status",
"of",
"this",
"response",
"."
] | train | https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/HttpResponse.php#L82-L99 |
koolkode/http | src/HttpResponse.php | HttpResponse.removeCookie | public function removeCookie($name)
{
$cookie = new SetCookieHeader($name, '');
$cookie->setExpires(1337);
$this->addHeader($cookie);
return $this;
} | php | public function removeCookie($name)
{
$cookie = new SetCookieHeader($name, '');
$cookie->setExpires(1337);
$this->addHeader($cookie);
return $this;
} | [
"public",
"function",
"removeCookie",
"(",
"$",
"name",
")",
"{",
"$",
"cookie",
"=",
"new",
"SetCookieHeader",
"(",
"$",
"name",
",",
"''",
")",
";",
"$",
"cookie",
"->",
"setExpires",
"(",
"1337",
")",
";",
"$",
"this",
"->",
"addHeader",
"(",
"$",
"cookie",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Remove a cookie by eliminating a Set-Cookie header for this cookie replacing it with a
header that will cause the client to remove the cookie.
@param string $name Name of the cookie to be removed.
@return HttpResponse | [
"Remove",
"a",
"cookie",
"by",
"eliminating",
"a",
"Set",
"-",
"Cookie",
"header",
"for",
"this",
"cookie",
"replacing",
"it",
"with",
"a",
"header",
"that",
"will",
"cause",
"the",
"client",
"to",
"remove",
"the",
"cookie",
"."
] | train | https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/HttpResponse.php#L194-L202 |
shrink0r/monatic | src/Attempt.php | Attempt.get | public function get(callable $codeBlock = null)
{
if (!$this->result) {
$this->result = $this->run(new Success);
}
if ($this->result instanceof Success) {
return is_callable($codeBlock) ? $codeBlock($this->result) : $this->result;
}
return $this->result;
} | php | public function get(callable $codeBlock = null)
{
if (!$this->result) {
$this->result = $this->run(new Success);
}
if ($this->result instanceof Success) {
return is_callable($codeBlock) ? $codeBlock($this->result) : $this->result;
}
return $this->result;
} | [
"public",
"function",
"get",
"(",
"callable",
"$",
"codeBlock",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"result",
")",
"{",
"$",
"this",
"->",
"result",
"=",
"$",
"this",
"->",
"run",
"(",
"new",
"Success",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"result",
"instanceof",
"Success",
")",
"{",
"return",
"is_callable",
"(",
"$",
"codeBlock",
")",
"?",
"$",
"codeBlock",
"(",
"$",
"this",
"->",
"result",
")",
":",
"$",
"this",
"->",
"result",
";",
"}",
"return",
"$",
"this",
"->",
"result",
";",
"}"
] | Returns the result of the code-block execution attempt.
@param callable $codeBlock Is never executed for this type.
@return null | [
"Returns",
"the",
"result",
"of",
"the",
"code",
"-",
"block",
"execution",
"attempt",
"."
] | train | https://github.com/shrink0r/monatic/blob/f39b8b2ef68a397d31d844341487412b335fd107/src/Attempt.php#L38-L49 |
shrink0r/monatic | src/Attempt.php | Attempt.bind | public function bind(callable $codeBlock)
{
return static::unit(function ($result) use ($codeBlock) {
$result = $this->run($result);
if ($result instanceof Success) {
return $codeBlock($result);
} else {
return $result;
}
});
} | php | public function bind(callable $codeBlock)
{
return static::unit(function ($result) use ($codeBlock) {
$result = $this->run($result);
if ($result instanceof Success) {
return $codeBlock($result);
} else {
return $result;
}
});
} | [
"public",
"function",
"bind",
"(",
"callable",
"$",
"codeBlock",
")",
"{",
"return",
"static",
"::",
"unit",
"(",
"function",
"(",
"$",
"result",
")",
"use",
"(",
"$",
"codeBlock",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"run",
"(",
"$",
"result",
")",
";",
"if",
"(",
"$",
"result",
"instanceof",
"Success",
")",
"{",
"return",
"$",
"codeBlock",
"(",
"$",
"result",
")",
";",
"}",
"else",
"{",
"return",
"$",
"result",
";",
"}",
"}",
")",
";",
"}"
] | Returns a new Attempt monad that is bound to the given code-block.
@param callable $codeBlock
@return Attempt | [
"Returns",
"a",
"new",
"Attempt",
"monad",
"that",
"is",
"bound",
"to",
"the",
"given",
"code",
"-",
"block",
"."
] | train | https://github.com/shrink0r/monatic/blob/f39b8b2ef68a397d31d844341487412b335fd107/src/Attempt.php#L58-L68 |
shrink0r/monatic | src/Attempt.php | Attempt.run | protected function run(MonadInterface $prevResult, callable $next = null)
{
try {
$result = call_user_func($this->codeBlock, $prevResult);
return ($result instanceof MonadInterface) ? $result : Success::unit($result);
} catch (Exception $error) {
return Error::unit($error);
}
} | php | protected function run(MonadInterface $prevResult, callable $next = null)
{
try {
$result = call_user_func($this->codeBlock, $prevResult);
return ($result instanceof MonadInterface) ? $result : Success::unit($result);
} catch (Exception $error) {
return Error::unit($error);
}
} | [
"protected",
"function",
"run",
"(",
"MonadInterface",
"$",
"prevResult",
",",
"callable",
"$",
"next",
"=",
"null",
")",
"{",
"try",
"{",
"$",
"result",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"codeBlock",
",",
"$",
"prevResult",
")",
";",
"return",
"(",
"$",
"result",
"instanceof",
"MonadInterface",
")",
"?",
"$",
"result",
":",
"Success",
"::",
"unit",
"(",
"$",
"result",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"error",
")",
"{",
"return",
"Error",
"::",
"unit",
"(",
"$",
"error",
")",
";",
"}",
"}"
] | Runs the monad's code-block.
@param MonadInterface $prevResult
@param callable $next
@return MonadInterface Either Success or Error in case an exception occured. | [
"Runs",
"the",
"monad",
"s",
"code",
"-",
"block",
"."
] | train | https://github.com/shrink0r/monatic/blob/f39b8b2ef68a397d31d844341487412b335fd107/src/Attempt.php#L89-L97 |
ciims/ciims-modules-install | models/UserForm.php | UserForm.validateForm | public function validateForm()
{
// Validates the model
if ($this->validate())
{
// Getters and setters don't work in CFormModel? So set them manually
$this->encryptionKey = $this->getEncryptionKey();
$this->encryptedPassword = $this->getEncryptedPassword();
return true;
}
return false;
} | php | public function validateForm()
{
// Validates the model
if ($this->validate())
{
// Getters and setters don't work in CFormModel? So set them manually
$this->encryptionKey = $this->getEncryptionKey();
$this->encryptedPassword = $this->getEncryptedPassword();
return true;
}
return false;
} | [
"public",
"function",
"validateForm",
"(",
")",
"{",
"// Validates the model",
"if",
"(",
"$",
"this",
"->",
"validate",
"(",
")",
")",
"{",
"// Getters and setters don't work in CFormModel? So set them manually",
"$",
"this",
"->",
"encryptionKey",
"=",
"$",
"this",
"->",
"getEncryptionKey",
"(",
")",
";",
"$",
"this",
"->",
"encryptedPassword",
"=",
"$",
"this",
"->",
"getEncryptedPassword",
"(",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Validates the model, and provides the encrypted data stream for hashing
@return bool If the model validated or not | [
"Validates",
"the",
"model",
"and",
"provides",
"the",
"encrypted",
"data",
"stream",
"for",
"hashing"
] | train | https://github.com/ciims/ciims-modules-install/blob/54d6a93e5c42c2d98e19de38a90e27f77358e88b/models/UserForm.php#L90-L102 |
ciims/ciims-modules-install | models/UserForm.php | UserForm.save | public function save()
{
if (!$this->validateForm())
return false;
try
{
// Store some data in session temporarily
Yii::app()->session['encryptionKey'] = $this->encryptionKey;
Yii::app()->session['siteName'] = $this->siteName;
Yii::app()->session['primaryEmail'] = $this->email;
// Try to save the record into the database
$connection = new CDbConnection(Yii::app()->session['dsn']['dsn'], Yii::app()->session['dsn']['username'], Yii::app()->session['dsn']['password']);
$connection->setActive(true);
$connection->createCommand('INSERT INTO users (id, email, password, username, user_role, status, created, updated) VALUES (1, :email, :password, :username, 9, 1, UNIX_TIMESTAMP(),UNIX_TIMESTAMP())')
->bindParam(':email', $this->email)
->bindParam(':password', $this->encryptedPassword)
->bindParam(':username', $this->username)
->execute();
return true;
}
catch (CDbException $e)
{
$this->addError('password', Yii::t('Install.main','There was an error saving your details to the database.'));
return false;
}
return false;
} | php | public function save()
{
if (!$this->validateForm())
return false;
try
{
// Store some data in session temporarily
Yii::app()->session['encryptionKey'] = $this->encryptionKey;
Yii::app()->session['siteName'] = $this->siteName;
Yii::app()->session['primaryEmail'] = $this->email;
// Try to save the record into the database
$connection = new CDbConnection(Yii::app()->session['dsn']['dsn'], Yii::app()->session['dsn']['username'], Yii::app()->session['dsn']['password']);
$connection->setActive(true);
$connection->createCommand('INSERT INTO users (id, email, password, username, user_role, status, created, updated) VALUES (1, :email, :password, :username, 9, 1, UNIX_TIMESTAMP(),UNIX_TIMESTAMP())')
->bindParam(':email', $this->email)
->bindParam(':password', $this->encryptedPassword)
->bindParam(':username', $this->username)
->execute();
return true;
}
catch (CDbException $e)
{
$this->addError('password', Yii::t('Install.main','There was an error saving your details to the database.'));
return false;
}
return false;
} | [
"public",
"function",
"save",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"validateForm",
"(",
")",
")",
"return",
"false",
";",
"try",
"{",
"// Store some data in session temporarily",
"Yii",
"::",
"app",
"(",
")",
"->",
"session",
"[",
"'encryptionKey'",
"]",
"=",
"$",
"this",
"->",
"encryptionKey",
";",
"Yii",
"::",
"app",
"(",
")",
"->",
"session",
"[",
"'siteName'",
"]",
"=",
"$",
"this",
"->",
"siteName",
";",
"Yii",
"::",
"app",
"(",
")",
"->",
"session",
"[",
"'primaryEmail'",
"]",
"=",
"$",
"this",
"->",
"email",
";",
"// Try to save the record into the database",
"$",
"connection",
"=",
"new",
"CDbConnection",
"(",
"Yii",
"::",
"app",
"(",
")",
"->",
"session",
"[",
"'dsn'",
"]",
"[",
"'dsn'",
"]",
",",
"Yii",
"::",
"app",
"(",
")",
"->",
"session",
"[",
"'dsn'",
"]",
"[",
"'username'",
"]",
",",
"Yii",
"::",
"app",
"(",
")",
"->",
"session",
"[",
"'dsn'",
"]",
"[",
"'password'",
"]",
")",
";",
"$",
"connection",
"->",
"setActive",
"(",
"true",
")",
";",
"$",
"connection",
"->",
"createCommand",
"(",
"'INSERT INTO users (id, email, password, username, user_role, status, created, updated) VALUES (1, :email, :password, :username, 9, 1, UNIX_TIMESTAMP(),UNIX_TIMESTAMP())'",
")",
"->",
"bindParam",
"(",
"':email'",
",",
"$",
"this",
"->",
"email",
")",
"->",
"bindParam",
"(",
"':password'",
",",
"$",
"this",
"->",
"encryptedPassword",
")",
"->",
"bindParam",
"(",
"':username'",
",",
"$",
"this",
"->",
"username",
")",
"->",
"execute",
"(",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"CDbException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"'password'",
",",
"Yii",
"::",
"t",
"(",
"'Install.main'",
",",
"'There was an error saving your details to the database.'",
")",
")",
";",
"return",
"false",
";",
"}",
"return",
"false",
";",
"}"
] | This method will save the admin user into the database, | [
"This",
"method",
"will",
"save",
"the",
"admin",
"user",
"into",
"the",
"database"
] | train | https://github.com/ciims/ciims-modules-install/blob/54d6a93e5c42c2d98e19de38a90e27f77358e88b/models/UserForm.php#L107-L136 |
ciims/ciims-modules-install | models/UserForm.php | UserForm.checkConfigDir | public function checkConfigDir()
{
if (is_writable(dirname(__FILE__) . '/../../../config'))
return true;
$this->addError('isConfigDirWritable', Yii::t('Install.main','Configuration directory is not writable. This must be corrected before your settings can be applied.'));
return false;
} | php | public function checkConfigDir()
{
if (is_writable(dirname(__FILE__) . '/../../../config'))
return true;
$this->addError('isConfigDirWritable', Yii::t('Install.main','Configuration directory is not writable. This must be corrected before your settings can be applied.'));
return false;
} | [
"public",
"function",
"checkConfigDir",
"(",
")",
"{",
"if",
"(",
"is_writable",
"(",
"dirname",
"(",
"__FILE__",
")",
".",
"'/../../../config'",
")",
")",
"return",
"true",
";",
"$",
"this",
"->",
"addError",
"(",
"'isConfigDirWritable'",
",",
"Yii",
"::",
"t",
"(",
"'Install.main'",
",",
"'Configuration directory is not writable. This must be corrected before your settings can be applied.'",
")",
")",
";",
"return",
"false",
";",
"}"
] | Validator for checkConfigDir | [
"Validator",
"for",
"checkConfigDir"
] | train | https://github.com/ciims/ciims-modules-install/blob/54d6a93e5c42c2d98e19de38a90e27f77358e88b/models/UserForm.php#L141-L148 |
DeimosProject/Helper | src/Helper/Helpers/Send.php | Send.http_build_query_develop | protected function http_build_query_develop($data)
{
if (!is_array($data))
{
return $data;
}
foreach ($data as $key => $val)
{
if (is_array($val))
{
foreach ($val as $k => $v)
{
if (is_array($v))
{
$data = array_merge($data, $this->http_build_query_develop(["{$key}[{$k}]" => $v]));
}
else
{
$data["{$key}[{$k}]"] = $v;
}
}
unset($data[$key]);
}
}
return $data;
} | php | protected function http_build_query_develop($data)
{
if (!is_array($data))
{
return $data;
}
foreach ($data as $key => $val)
{
if (is_array($val))
{
foreach ($val as $k => $v)
{
if (is_array($v))
{
$data = array_merge($data, $this->http_build_query_develop(["{$key}[{$k}]" => $v]));
}
else
{
$data["{$key}[{$k}]"] = $v;
}
}
unset($data[$key]);
}
}
return $data;
} | [
"protected",
"function",
"http_build_query_develop",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"foreach",
"(",
"$",
"val",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"$",
"data",
"=",
"array_merge",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"http_build_query_develop",
"(",
"[",
"\"{$key}[{$k}]\"",
"=>",
"$",
"v",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"\"{$key}[{$k}]\"",
"]",
"=",
"$",
"v",
";",
"}",
"}",
"unset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | patch for CURL bug
@link https://bugs.php.net/bug.php?id=67477
@param $data
@return array | [
"patch",
"for",
"CURL",
"bug",
"@link",
"https",
":",
"//",
"bugs",
".",
"php",
".",
"net",
"/",
"bug",
".",
"php?id",
"=",
"67477"
] | train | https://github.com/DeimosProject/Helper/blob/39c67de21a87c7c6391b2f98416063f41c94e26f/src/Helper/Helpers/Send.php#L88-L115 |
DeimosProject/Helper | src/Helper/Helpers/Send.php | Send.exec | public function exec()
{
$this->build();
$data = curl_exec($this->ch);
if(curl_errno($this->ch))
{
throw new CurlError(curl_error($this->ch));
}
curl_close($this->ch);
return $data;
} | php | public function exec()
{
$this->build();
$data = curl_exec($this->ch);
if(curl_errno($this->ch))
{
throw new CurlError(curl_error($this->ch));
}
curl_close($this->ch);
return $data;
} | [
"public",
"function",
"exec",
"(",
")",
"{",
"$",
"this",
"->",
"build",
"(",
")",
";",
"$",
"data",
"=",
"curl_exec",
"(",
"$",
"this",
"->",
"ch",
")",
";",
"if",
"(",
"curl_errno",
"(",
"$",
"this",
"->",
"ch",
")",
")",
"{",
"throw",
"new",
"CurlError",
"(",
"curl_error",
"(",
"$",
"this",
"->",
"ch",
")",
")",
";",
"}",
"curl_close",
"(",
"$",
"this",
"->",
"ch",
")",
";",
"return",
"$",
"data",
";",
"}"
] | @return mixed
@throws CurlError | [
"@return",
"mixed"
] | train | https://github.com/DeimosProject/Helper/blob/39c67de21a87c7c6391b2f98416063f41c94e26f/src/Helper/Helpers/Send.php#L229-L243 |
DeimosProject/Helper | src/Helper/Helpers/Send.php | Send.httpAuth | public function httpAuth($user, $password)
{
curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($this->ch, CURLOPT_USERPWD, "$user:$password");
return $this;
} | php | public function httpAuth($user, $password)
{
curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($this->ch, CURLOPT_USERPWD, "$user:$password");
return $this;
} | [
"public",
"function",
"httpAuth",
"(",
"$",
"user",
",",
"$",
"password",
")",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"ch",
",",
"CURLOPT_HTTPAUTH",
",",
"CURLAUTH_BASIC",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"ch",
",",
"CURLOPT_USERPWD",
",",
"\"$user:$password\"",
")",
";",
"return",
"$",
"this",
";",
"}"
] | @param string $user
@param string $password
@return $this | [
"@param",
"string",
"$user",
"@param",
"string",
"$password"
] | train | https://github.com/DeimosProject/Helper/blob/39c67de21a87c7c6391b2f98416063f41c94e26f/src/Helper/Helpers/Send.php#L268-L274 |
Stinger-Soft/TwigExtensions | src/StingerSoft/TwigExtensions/PrettyPrintExtensions.php | PrettyPrintExtensions.humanizeFileSizeFilter | public function humanizeFileSizeFilter($size, $precision = 2, $si = false, $locale = 'en') {
return ByteFormatter::prettyPrintSize($size, $precision, $si, $locale);
} | php | public function humanizeFileSizeFilter($size, $precision = 2, $si = false, $locale = 'en') {
return ByteFormatter::prettyPrintSize($size, $precision, $si, $locale);
} | [
"public",
"function",
"humanizeFileSizeFilter",
"(",
"$",
"size",
",",
"$",
"precision",
"=",
"2",
",",
"$",
"si",
"=",
"false",
",",
"$",
"locale",
"=",
"'en'",
")",
"{",
"return",
"ByteFormatter",
"::",
"prettyPrintSize",
"(",
"$",
"size",
",",
"$",
"precision",
",",
"$",
"si",
",",
"$",
"locale",
")",
";",
"}"
] | Pretty prints a given memory size
@see ByteFormatter @codeCoverageIgnore
@param integer $size
The memory size in bytes
@param boolean $si
Use SI prefixes?
@param string $locale
Locale used to format the result
@return string A pretty printed memory size | [
"Pretty",
"prints",
"a",
"given",
"memory",
"size"
] | train | https://github.com/Stinger-Soft/TwigExtensions/blob/7bfce337b0dd33106e22f80b221338451a02d7c5/src/StingerSoft/TwigExtensions/PrettyPrintExtensions.php#L66-L68 |
Stinger-Soft/TwigExtensions | src/StingerSoft/TwigExtensions/PrettyPrintExtensions.php | PrettyPrintExtensions.humanizeTimeDiffFilter | public function humanizeTimeDiffFilter($from, $to = null) {
$diff = TimeFormatter::getRelativeTimeDifference($from, $to);
$since = null;
switch($diff[1]) {
case TimeFormatter::UNIT_SECONDS:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.seconds', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
case TimeFormatter::UNIT_MINUTES:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.minutes', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
case TimeFormatter::UNIT_HOURS:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.hours', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
case TimeFormatter::UNIT_DAYS:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.days', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
case TimeFormatter::UNIT_WEEKS:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.weeks', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
case TimeFormatter::UNIT_MONTHS:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.months', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
case TimeFormatter::UNIT_YEARS:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.years', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
}
return $this->translator->trans('stinger_soft.twig_extensions.pretty_print.time.diff', array(
'%time%' => $since
), 'StingerSoftTwigExtensions');
} | php | public function humanizeTimeDiffFilter($from, $to = null) {
$diff = TimeFormatter::getRelativeTimeDifference($from, $to);
$since = null;
switch($diff[1]) {
case TimeFormatter::UNIT_SECONDS:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.seconds', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
case TimeFormatter::UNIT_MINUTES:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.minutes', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
case TimeFormatter::UNIT_HOURS:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.hours', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
case TimeFormatter::UNIT_DAYS:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.days', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
case TimeFormatter::UNIT_WEEKS:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.weeks', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
case TimeFormatter::UNIT_MONTHS:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.months', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
case TimeFormatter::UNIT_YEARS:
$since = $this->translator->transChoice('stinger_soft.twig_extensions.pretty_print.time.years', $diff[0], array(
'%count%' => $diff[0]
), 'StingerSoftTwigExtensions');
break;
}
return $this->translator->trans('stinger_soft.twig_extensions.pretty_print.time.diff', array(
'%time%' => $since
), 'StingerSoftTwigExtensions');
} | [
"public",
"function",
"humanizeTimeDiffFilter",
"(",
"$",
"from",
",",
"$",
"to",
"=",
"null",
")",
"{",
"$",
"diff",
"=",
"TimeFormatter",
"::",
"getRelativeTimeDifference",
"(",
"$",
"from",
",",
"$",
"to",
")",
";",
"$",
"since",
"=",
"null",
";",
"switch",
"(",
"$",
"diff",
"[",
"1",
"]",
")",
"{",
"case",
"TimeFormatter",
"::",
"UNIT_SECONDS",
":",
"$",
"since",
"=",
"$",
"this",
"->",
"translator",
"->",
"transChoice",
"(",
"'stinger_soft.twig_extensions.pretty_print.time.seconds'",
",",
"$",
"diff",
"[",
"0",
"]",
",",
"array",
"(",
"'%count%'",
"=>",
"$",
"diff",
"[",
"0",
"]",
")",
",",
"'StingerSoftTwigExtensions'",
")",
";",
"break",
";",
"case",
"TimeFormatter",
"::",
"UNIT_MINUTES",
":",
"$",
"since",
"=",
"$",
"this",
"->",
"translator",
"->",
"transChoice",
"(",
"'stinger_soft.twig_extensions.pretty_print.time.minutes'",
",",
"$",
"diff",
"[",
"0",
"]",
",",
"array",
"(",
"'%count%'",
"=>",
"$",
"diff",
"[",
"0",
"]",
")",
",",
"'StingerSoftTwigExtensions'",
")",
";",
"break",
";",
"case",
"TimeFormatter",
"::",
"UNIT_HOURS",
":",
"$",
"since",
"=",
"$",
"this",
"->",
"translator",
"->",
"transChoice",
"(",
"'stinger_soft.twig_extensions.pretty_print.time.hours'",
",",
"$",
"diff",
"[",
"0",
"]",
",",
"array",
"(",
"'%count%'",
"=>",
"$",
"diff",
"[",
"0",
"]",
")",
",",
"'StingerSoftTwigExtensions'",
")",
";",
"break",
";",
"case",
"TimeFormatter",
"::",
"UNIT_DAYS",
":",
"$",
"since",
"=",
"$",
"this",
"->",
"translator",
"->",
"transChoice",
"(",
"'stinger_soft.twig_extensions.pretty_print.time.days'",
",",
"$",
"diff",
"[",
"0",
"]",
",",
"array",
"(",
"'%count%'",
"=>",
"$",
"diff",
"[",
"0",
"]",
")",
",",
"'StingerSoftTwigExtensions'",
")",
";",
"break",
";",
"case",
"TimeFormatter",
"::",
"UNIT_WEEKS",
":",
"$",
"since",
"=",
"$",
"this",
"->",
"translator",
"->",
"transChoice",
"(",
"'stinger_soft.twig_extensions.pretty_print.time.weeks'",
",",
"$",
"diff",
"[",
"0",
"]",
",",
"array",
"(",
"'%count%'",
"=>",
"$",
"diff",
"[",
"0",
"]",
")",
",",
"'StingerSoftTwigExtensions'",
")",
";",
"break",
";",
"case",
"TimeFormatter",
"::",
"UNIT_MONTHS",
":",
"$",
"since",
"=",
"$",
"this",
"->",
"translator",
"->",
"transChoice",
"(",
"'stinger_soft.twig_extensions.pretty_print.time.months'",
",",
"$",
"diff",
"[",
"0",
"]",
",",
"array",
"(",
"'%count%'",
"=>",
"$",
"diff",
"[",
"0",
"]",
")",
",",
"'StingerSoftTwigExtensions'",
")",
";",
"break",
";",
"case",
"TimeFormatter",
"::",
"UNIT_YEARS",
":",
"$",
"since",
"=",
"$",
"this",
"->",
"translator",
"->",
"transChoice",
"(",
"'stinger_soft.twig_extensions.pretty_print.time.years'",
",",
"$",
"diff",
"[",
"0",
"]",
",",
"array",
"(",
"'%count%'",
"=>",
"$",
"diff",
"[",
"0",
"]",
")",
",",
"'StingerSoftTwigExtensions'",
")",
";",
"break",
";",
"}",
"return",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'stinger_soft.twig_extensions.pretty_print.time.diff'",
",",
"array",
"(",
"'%time%'",
"=>",
"$",
"since",
")",
",",
"'StingerSoftTwigExtensions'",
")",
";",
"}"
] | Get the relative difference between a given start time and end time.
Depending on the amount of time passed between given from and to, the difference between the two may be
expressed in seconds, hours, days, weeks, months or years.
@see TimeFormatter
@param int|\DateTime $from
the start time, either as <code>DateTime</code> object or as integer expressing a unix timestamp,
used for calculating the relative difference to the given <code>to</code> parameter.
@param int|\DateTime|null $to
the end time, either as <code>DateTime</code> object, a unix timestamp or <code>null</code> used for
calculating the difference to the given <code>from</code> parameter. In case <code>null</code> is
provided, the current timestamp will be used (utilizing <code>time()</code>). | [
"Get",
"the",
"relative",
"difference",
"between",
"a",
"given",
"start",
"time",
"and",
"end",
"time",
"."
] | train | https://github.com/Stinger-Soft/TwigExtensions/blob/7bfce337b0dd33106e22f80b221338451a02d7c5/src/StingerSoft/TwigExtensions/PrettyPrintExtensions.php#L86-L129 |
frodosghost/AtomLoggerBundle | Connection/Request.php | Request.formatData | public function formatData()
{
$this->formatter->addData($this->data);
try {
$formatted = $this->formatter->format();
} catch (DataException $e) {
throw new FormattingException('The provided data has been incorrectly formatted.');
}
return $formatted;
} | php | public function formatData()
{
$this->formatter->addData($this->data);
try {
$formatted = $this->formatter->format();
} catch (DataException $e) {
throw new FormattingException('The provided data has been incorrectly formatted.');
}
return $formatted;
} | [
"public",
"function",
"formatData",
"(",
")",
"{",
"$",
"this",
"->",
"formatter",
"->",
"addData",
"(",
"$",
"this",
"->",
"data",
")",
";",
"try",
"{",
"$",
"formatted",
"=",
"$",
"this",
"->",
"formatter",
"->",
"format",
"(",
")",
";",
"}",
"catch",
"(",
"DataException",
"$",
"e",
")",
"{",
"throw",
"new",
"FormattingException",
"(",
"'The provided data has been incorrectly formatted.'",
")",
";",
"}",
"return",
"$",
"formatted",
";",
"}"
] | Calls the Formatter with the data passed into the Request
@return string | [
"Calls",
"the",
"Formatter",
"with",
"the",
"data",
"passed",
"into",
"the",
"Request"
] | train | https://github.com/frodosghost/AtomLoggerBundle/blob/c48823e4b3772e498b366867f27e6581f613f733/Connection/Request.php#L57-L68 |
judus/minimal-html | src/Table.php | Table.setTheadData | public function setTheadData(array $theadData): Table
{
if ($theadData) {
$this->options['thead']['value'] = $theadData;
} else {
$this->options['thead'] = null;
}
$this->theadData = $theadData;
return $this;
} | php | public function setTheadData(array $theadData): Table
{
if ($theadData) {
$this->options['thead']['value'] = $theadData;
} else {
$this->options['thead'] = null;
}
$this->theadData = $theadData;
return $this;
} | [
"public",
"function",
"setTheadData",
"(",
"array",
"$",
"theadData",
")",
":",
"Table",
"{",
"if",
"(",
"$",
"theadData",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'thead'",
"]",
"[",
"'value'",
"]",
"=",
"$",
"theadData",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"options",
"[",
"'thead'",
"]",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"theadData",
"=",
"$",
"theadData",
";",
"return",
"$",
"this",
";",
"}"
] | @param array $theadData
@return Table | [
"@param",
"array",
"$theadData"
] | train | https://github.com/judus/minimal-html/blob/0e1788b0b4b86a705e4f8cd402b4a2336b09d666/src/Table.php#L118-L129 |
judus/minimal-html | src/Table.php | Table.setTfootData | public function setTfootData(array $tfootData): Table
{
if ($tfootData) {
$this->options['tfoot']['value'] = $tfootData;
} else {
$this->options['tfoot'] = null;
}
$this->tfootData = $tfootData;
return $this;
} | php | public function setTfootData(array $tfootData): Table
{
if ($tfootData) {
$this->options['tfoot']['value'] = $tfootData;
} else {
$this->options['tfoot'] = null;
}
$this->tfootData = $tfootData;
return $this;
} | [
"public",
"function",
"setTfootData",
"(",
"array",
"$",
"tfootData",
")",
":",
"Table",
"{",
"if",
"(",
"$",
"tfootData",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'tfoot'",
"]",
"[",
"'value'",
"]",
"=",
"$",
"tfootData",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"options",
"[",
"'tfoot'",
"]",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"tfootData",
"=",
"$",
"tfootData",
";",
"return",
"$",
"this",
";",
"}"
] | @param array $tfootData
@return Table | [
"@param",
"array",
"$tfootData"
] | train | https://github.com/judus/minimal-html/blob/0e1788b0b4b86a705e4f8cd402b4a2336b09d666/src/Table.php#L148-L159 |
judus/minimal-html | src/Table.php | Table.setTableId | public function setTableId($tableId): Table
{
$this->tableId = $tableId;
$this->options['table']['id'] = $tableId;
return $this;
} | php | public function setTableId($tableId): Table
{
$this->tableId = $tableId;
$this->options['table']['id'] = $tableId;
return $this;
} | [
"public",
"function",
"setTableId",
"(",
"$",
"tableId",
")",
":",
"Table",
"{",
"$",
"this",
"->",
"tableId",
"=",
"$",
"tableId",
";",
"$",
"this",
"->",
"options",
"[",
"'table'",
"]",
"[",
"'id'",
"]",
"=",
"$",
"tableId",
";",
"return",
"$",
"this",
";",
"}"
] | @param mixed $tableId
@return Table | [
"@param",
"mixed",
"$tableId"
] | train | https://github.com/judus/minimal-html/blob/0e1788b0b4b86a705e4f8cd402b4a2336b09d666/src/Table.php#L255-L261 |
judus/minimal-html | src/Table.php | Table.setTableClass | public function setTableClass($tableClass): Table
{
$this->tableClass = $tableClass;
$this->options['table']['class'] = $tableClass;
return $this;
} | php | public function setTableClass($tableClass): Table
{
$this->tableClass = $tableClass;
$this->options['table']['class'] = $tableClass;
return $this;
} | [
"public",
"function",
"setTableClass",
"(",
"$",
"tableClass",
")",
":",
"Table",
"{",
"$",
"this",
"->",
"tableClass",
"=",
"$",
"tableClass",
";",
"$",
"this",
"->",
"options",
"[",
"'table'",
"]",
"[",
"'class'",
"]",
"=",
"$",
"tableClass",
";",
"return",
"$",
"this",
";",
"}"
] | @param mixed $tableClass
@return Table | [
"@param",
"mixed",
"$tableClass"
] | train | https://github.com/judus/minimal-html/blob/0e1788b0b4b86a705e4f8cd402b4a2336b09d666/src/Table.php#L276-L282 |
judus/minimal-html | src/Table.php | Table.setCaption | public function setCaption($caption): Table
{
$this->caption = $caption;
$this->options['caption']['value'] = $caption;
return $this;
} | php | public function setCaption($caption): Table
{
$this->caption = $caption;
$this->options['caption']['value'] = $caption;
return $this;
} | [
"public",
"function",
"setCaption",
"(",
"$",
"caption",
")",
":",
"Table",
"{",
"$",
"this",
"->",
"caption",
"=",
"$",
"caption",
";",
"$",
"this",
"->",
"options",
"[",
"'caption'",
"]",
"[",
"'value'",
"]",
"=",
"$",
"caption",
";",
"return",
"$",
"this",
";",
"}"
] | @param mixed $caption
@return Table | [
"@param",
"mixed",
"$caption"
] | train | https://github.com/judus/minimal-html/blob/0e1788b0b4b86a705e4f8cd402b4a2336b09d666/src/Table.php#L297-L303 |
judus/minimal-html | src/Table.php | Table.setThead | public function setThead(array $thead = null, $useKeyName = false): Table
{
$this->setTheadUsesValue(!$useKeyName);
$this->setShowThead(true);
!is_array($thead) || $this->setTheadData($thead);
return $this;
} | php | public function setThead(array $thead = null, $useKeyName = false): Table
{
$this->setTheadUsesValue(!$useKeyName);
$this->setShowThead(true);
!is_array($thead) || $this->setTheadData($thead);
return $this;
} | [
"public",
"function",
"setThead",
"(",
"array",
"$",
"thead",
"=",
"null",
",",
"$",
"useKeyName",
"=",
"false",
")",
":",
"Table",
"{",
"$",
"this",
"->",
"setTheadUsesValue",
"(",
"!",
"$",
"useKeyName",
")",
";",
"$",
"this",
"->",
"setShowThead",
"(",
"true",
")",
";",
"!",
"is_array",
"(",
"$",
"thead",
")",
"||",
"$",
"this",
"->",
"setTheadData",
"(",
"$",
"thead",
")",
";",
"return",
"$",
"this",
";",
"}"
] | @param array|null $thead
@param bool $useKeyName
@return Table | [
"@param",
"array|null",
"$thead"
] | train | https://github.com/judus/minimal-html/blob/0e1788b0b4b86a705e4f8cd402b4a2336b09d666/src/Table.php#L320-L328 |
judus/minimal-html | src/Table.php | Table.setTfoot | public function setTfoot(array $tfoot = null, $useKeyName = false)
{
$this->setTfootUsesValue(!$useKeyName);
$this->setShowTfoot(!is_null($tfoot));
$this->setTfootData($tfoot);
return $this;
} | php | public function setTfoot(array $tfoot = null, $useKeyName = false)
{
$this->setTfootUsesValue(!$useKeyName);
$this->setShowTfoot(!is_null($tfoot));
$this->setTfootData($tfoot);
return $this;
} | [
"public",
"function",
"setTfoot",
"(",
"array",
"$",
"tfoot",
"=",
"null",
",",
"$",
"useKeyName",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"setTfootUsesValue",
"(",
"!",
"$",
"useKeyName",
")",
";",
"$",
"this",
"->",
"setShowTfoot",
"(",
"!",
"is_null",
"(",
"$",
"tfoot",
")",
")",
";",
"$",
"this",
"->",
"setTfootData",
"(",
"$",
"tfoot",
")",
";",
"return",
"$",
"this",
";",
"}"
] | @param array|null $tfoot
@param bool $useKeyName
@return Table | [
"@param",
"array|null",
"$tfoot"
] | train | https://github.com/judus/minimal-html/blob/0e1788b0b4b86a705e4f8cd402b4a2336b09d666/src/Table.php#L345-L352 |
judus/minimal-html | src/Table.php | Table.make | public function make(array $data = null, array $options = null)
{
$data = $data ? $data : $this->getData();
$this->setData($data);
$options = $options ? $options : $this->getOptions();
$options = array_replace_recursive($this->getDefaults(), $options);
$this->setOptions($options);
if ($this->isShowRowCheckbox()) {
$this->addRowCheckbox();
}
if ($this->isShowRowIndex()) {
$this->addRowIndex();
}
if ($this->isShowColSearch()) {
$this->addColSearch();
}
$options = $this->getOptions();
$data = $this->getData();
$attributes = [];
// Attributes for wrappers
$attributes['table'] = $this->getAttributes('table', $options);
$attributes['caption'] = $this->getAttributes('caption', $options);
$attributes['colgroup'] = $this->getAttributes('colgroup', $options);
$attributes['thead'] = $this->getAttributes('thead', $options);
$attributes['tbody'] = $this->getAttributes('tbody', $options);
$attributes['tfoot'] = $this->getAttributes('tfoot', $options);
// caption
$caption = isset($options['caption']['value']) ?
$options['caption']['value'] : '';
// colgroup data
$cols = '';
if (is_array($options['colgroup']) && $this->isShowColgroup()) {
$colsData = isset($options['colgroup']['value']) ?
$options['colgroup']['value'] : array_slice($data, 0, 1);
$cols = $this->getColgroup($colsData, $options);
}
// thead data
$thead_rows = '';
if (is_array($options['thead']) && $this->isShowThead()) {
$theadData = isset($options['thead']['value']) ?
$options['thead']['value'] : array_slice($data, 0, 1);
$theadData = is_callable($theadData) ? $theadData($data) : $theadData;
$thead_rows = $this->getGrid($theadData, 'thead_tr', 'th',
$options);
}
// tfoot data
$tfoot_rows = '';
if (is_array($options['tfoot']) && $this->isShowTfoot()) {
$tfootData = isset($options['tfoot']['value']) ?
$options['tfoot']['value'] : null;
$tfootData = is_callable($tfootData) ? $tfootData($data) : $tfootData;
$tfoot_rows = $this->getGrid($tfootData, 'tfoot_tr', 'tfoot_td',
$options);
}
// tbody data
$tbody_rows = $this->getGrid($data, 'tr', 'td', $options);
// Render wrappers
$caption = empty($caption) ?
'' : sprintf($options['caption']['tag'], $attributes['caption'],
$caption);
$colgroup = empty($cols) ?
'' : sprintf($options['colgroup']['tag'], $attributes['colgroup'],
$cols);
$thead = empty($thead_rows) ?
'' : sprintf($options['thead']['tag'], $attributes['thead'],
$thead_rows);
$tbody = sprintf($options['tbody']['tag'], $attributes['tbody'],
$tbody_rows);
$tfoot = empty($tfoot_rows) ?
'' : sprintf($options['tfoot']['tag'], $attributes['tfoot'],
$tfoot_rows);
$table = $caption .$colgroup . $thead . $tbody . $tfoot;
return sprintf($options['table']['tag'], $attributes['table'], $table);
} | php | public function make(array $data = null, array $options = null)
{
$data = $data ? $data : $this->getData();
$this->setData($data);
$options = $options ? $options : $this->getOptions();
$options = array_replace_recursive($this->getDefaults(), $options);
$this->setOptions($options);
if ($this->isShowRowCheckbox()) {
$this->addRowCheckbox();
}
if ($this->isShowRowIndex()) {
$this->addRowIndex();
}
if ($this->isShowColSearch()) {
$this->addColSearch();
}
$options = $this->getOptions();
$data = $this->getData();
$attributes = [];
// Attributes for wrappers
$attributes['table'] = $this->getAttributes('table', $options);
$attributes['caption'] = $this->getAttributes('caption', $options);
$attributes['colgroup'] = $this->getAttributes('colgroup', $options);
$attributes['thead'] = $this->getAttributes('thead', $options);
$attributes['tbody'] = $this->getAttributes('tbody', $options);
$attributes['tfoot'] = $this->getAttributes('tfoot', $options);
// caption
$caption = isset($options['caption']['value']) ?
$options['caption']['value'] : '';
// colgroup data
$cols = '';
if (is_array($options['colgroup']) && $this->isShowColgroup()) {
$colsData = isset($options['colgroup']['value']) ?
$options['colgroup']['value'] : array_slice($data, 0, 1);
$cols = $this->getColgroup($colsData, $options);
}
// thead data
$thead_rows = '';
if (is_array($options['thead']) && $this->isShowThead()) {
$theadData = isset($options['thead']['value']) ?
$options['thead']['value'] : array_slice($data, 0, 1);
$theadData = is_callable($theadData) ? $theadData($data) : $theadData;
$thead_rows = $this->getGrid($theadData, 'thead_tr', 'th',
$options);
}
// tfoot data
$tfoot_rows = '';
if (is_array($options['tfoot']) && $this->isShowTfoot()) {
$tfootData = isset($options['tfoot']['value']) ?
$options['tfoot']['value'] : null;
$tfootData = is_callable($tfootData) ? $tfootData($data) : $tfootData;
$tfoot_rows = $this->getGrid($tfootData, 'tfoot_tr', 'tfoot_td',
$options);
}
// tbody data
$tbody_rows = $this->getGrid($data, 'tr', 'td', $options);
// Render wrappers
$caption = empty($caption) ?
'' : sprintf($options['caption']['tag'], $attributes['caption'],
$caption);
$colgroup = empty($cols) ?
'' : sprintf($options['colgroup']['tag'], $attributes['colgroup'],
$cols);
$thead = empty($thead_rows) ?
'' : sprintf($options['thead']['tag'], $attributes['thead'],
$thead_rows);
$tbody = sprintf($options['tbody']['tag'], $attributes['tbody'],
$tbody_rows);
$tfoot = empty($tfoot_rows) ?
'' : sprintf($options['tfoot']['tag'], $attributes['tfoot'],
$tfoot_rows);
$table = $caption .$colgroup . $thead . $tbody . $tfoot;
return sprintf($options['table']['tag'], $attributes['table'], $table);
} | [
"public",
"function",
"make",
"(",
"array",
"$",
"data",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"$",
"data",
"?",
"$",
"data",
":",
"$",
"this",
"->",
"getData",
"(",
")",
";",
"$",
"this",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"$",
"options",
"=",
"$",
"options",
"?",
"$",
"options",
":",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"$",
"options",
"=",
"array_replace_recursive",
"(",
"$",
"this",
"->",
"getDefaults",
"(",
")",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isShowRowCheckbox",
"(",
")",
")",
"{",
"$",
"this",
"->",
"addRowCheckbox",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isShowRowIndex",
"(",
")",
")",
"{",
"$",
"this",
"->",
"addRowIndex",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isShowColSearch",
"(",
")",
")",
"{",
"$",
"this",
"->",
"addColSearch",
"(",
")",
";",
"}",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"getData",
"(",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"// Attributes for wrappers",
"$",
"attributes",
"[",
"'table'",
"]",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
"'table'",
",",
"$",
"options",
")",
";",
"$",
"attributes",
"[",
"'caption'",
"]",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
"'caption'",
",",
"$",
"options",
")",
";",
"$",
"attributes",
"[",
"'colgroup'",
"]",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
"'colgroup'",
",",
"$",
"options",
")",
";",
"$",
"attributes",
"[",
"'thead'",
"]",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
"'thead'",
",",
"$",
"options",
")",
";",
"$",
"attributes",
"[",
"'tbody'",
"]",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
"'tbody'",
",",
"$",
"options",
")",
";",
"$",
"attributes",
"[",
"'tfoot'",
"]",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
"'tfoot'",
",",
"$",
"options",
")",
";",
"// caption",
"$",
"caption",
"=",
"isset",
"(",
"$",
"options",
"[",
"'caption'",
"]",
"[",
"'value'",
"]",
")",
"?",
"$",
"options",
"[",
"'caption'",
"]",
"[",
"'value'",
"]",
":",
"''",
";",
"// colgroup data",
"$",
"cols",
"=",
"''",
";",
"if",
"(",
"is_array",
"(",
"$",
"options",
"[",
"'colgroup'",
"]",
")",
"&&",
"$",
"this",
"->",
"isShowColgroup",
"(",
")",
")",
"{",
"$",
"colsData",
"=",
"isset",
"(",
"$",
"options",
"[",
"'colgroup'",
"]",
"[",
"'value'",
"]",
")",
"?",
"$",
"options",
"[",
"'colgroup'",
"]",
"[",
"'value'",
"]",
":",
"array_slice",
"(",
"$",
"data",
",",
"0",
",",
"1",
")",
";",
"$",
"cols",
"=",
"$",
"this",
"->",
"getColgroup",
"(",
"$",
"colsData",
",",
"$",
"options",
")",
";",
"}",
"// thead data",
"$",
"thead_rows",
"=",
"''",
";",
"if",
"(",
"is_array",
"(",
"$",
"options",
"[",
"'thead'",
"]",
")",
"&&",
"$",
"this",
"->",
"isShowThead",
"(",
")",
")",
"{",
"$",
"theadData",
"=",
"isset",
"(",
"$",
"options",
"[",
"'thead'",
"]",
"[",
"'value'",
"]",
")",
"?",
"$",
"options",
"[",
"'thead'",
"]",
"[",
"'value'",
"]",
":",
"array_slice",
"(",
"$",
"data",
",",
"0",
",",
"1",
")",
";",
"$",
"theadData",
"=",
"is_callable",
"(",
"$",
"theadData",
")",
"?",
"$",
"theadData",
"(",
"$",
"data",
")",
":",
"$",
"theadData",
";",
"$",
"thead_rows",
"=",
"$",
"this",
"->",
"getGrid",
"(",
"$",
"theadData",
",",
"'thead_tr'",
",",
"'th'",
",",
"$",
"options",
")",
";",
"}",
"// tfoot data",
"$",
"tfoot_rows",
"=",
"''",
";",
"if",
"(",
"is_array",
"(",
"$",
"options",
"[",
"'tfoot'",
"]",
")",
"&&",
"$",
"this",
"->",
"isShowTfoot",
"(",
")",
")",
"{",
"$",
"tfootData",
"=",
"isset",
"(",
"$",
"options",
"[",
"'tfoot'",
"]",
"[",
"'value'",
"]",
")",
"?",
"$",
"options",
"[",
"'tfoot'",
"]",
"[",
"'value'",
"]",
":",
"null",
";",
"$",
"tfootData",
"=",
"is_callable",
"(",
"$",
"tfootData",
")",
"?",
"$",
"tfootData",
"(",
"$",
"data",
")",
":",
"$",
"tfootData",
";",
"$",
"tfoot_rows",
"=",
"$",
"this",
"->",
"getGrid",
"(",
"$",
"tfootData",
",",
"'tfoot_tr'",
",",
"'tfoot_td'",
",",
"$",
"options",
")",
";",
"}",
"// tbody data",
"$",
"tbody_rows",
"=",
"$",
"this",
"->",
"getGrid",
"(",
"$",
"data",
",",
"'tr'",
",",
"'td'",
",",
"$",
"options",
")",
";",
"// Render wrappers",
"$",
"caption",
"=",
"empty",
"(",
"$",
"caption",
")",
"?",
"''",
":",
"sprintf",
"(",
"$",
"options",
"[",
"'caption'",
"]",
"[",
"'tag'",
"]",
",",
"$",
"attributes",
"[",
"'caption'",
"]",
",",
"$",
"caption",
")",
";",
"$",
"colgroup",
"=",
"empty",
"(",
"$",
"cols",
")",
"?",
"''",
":",
"sprintf",
"(",
"$",
"options",
"[",
"'colgroup'",
"]",
"[",
"'tag'",
"]",
",",
"$",
"attributes",
"[",
"'colgroup'",
"]",
",",
"$",
"cols",
")",
";",
"$",
"thead",
"=",
"empty",
"(",
"$",
"thead_rows",
")",
"?",
"''",
":",
"sprintf",
"(",
"$",
"options",
"[",
"'thead'",
"]",
"[",
"'tag'",
"]",
",",
"$",
"attributes",
"[",
"'thead'",
"]",
",",
"$",
"thead_rows",
")",
";",
"$",
"tbody",
"=",
"sprintf",
"(",
"$",
"options",
"[",
"'tbody'",
"]",
"[",
"'tag'",
"]",
",",
"$",
"attributes",
"[",
"'tbody'",
"]",
",",
"$",
"tbody_rows",
")",
";",
"$",
"tfoot",
"=",
"empty",
"(",
"$",
"tfoot_rows",
")",
"?",
"''",
":",
"sprintf",
"(",
"$",
"options",
"[",
"'tfoot'",
"]",
"[",
"'tag'",
"]",
",",
"$",
"attributes",
"[",
"'tfoot'",
"]",
",",
"$",
"tfoot_rows",
")",
";",
"$",
"table",
"=",
"$",
"caption",
".",
"$",
"colgroup",
".",
"$",
"thead",
".",
"$",
"tbody",
".",
"$",
"tfoot",
";",
"return",
"sprintf",
"(",
"$",
"options",
"[",
"'table'",
"]",
"[",
"'tag'",
"]",
",",
"$",
"attributes",
"[",
"'table'",
"]",
",",
"$",
"table",
")",
";",
"}"
] | @param array|null $data
@param array|null $options
@return string | [
"@param",
"array|null",
"$data",
"@param",
"array|null",
"$options"
] | train | https://github.com/judus/minimal-html/blob/0e1788b0b4b86a705e4f8cd402b4a2336b09d666/src/Table.php#L699-L794 |
judus/minimal-html | src/Table.php | Table.getAttributes | public function getAttributes($name, $options = null)
{
$attributes = '';
if (!is_array($options[$name])) {
return $attributes;
}
foreach ($options[$name] as $key => $value) {
if ($key !== 'tag' && $key !== 'value') {
$value = is_callable($value) ? $value($options[$name], $options) : $value;
$attributes .= !empty($value) ? ' ' . $key . '="' . $value . '"' : '';
}
}
return $attributes;
} | php | public function getAttributes($name, $options = null)
{
$attributes = '';
if (!is_array($options[$name])) {
return $attributes;
}
foreach ($options[$name] as $key => $value) {
if ($key !== 'tag' && $key !== 'value') {
$value = is_callable($value) ? $value($options[$name], $options) : $value;
$attributes .= !empty($value) ? ' ' . $key . '="' . $value . '"' : '';
}
}
return $attributes;
} | [
"public",
"function",
"getAttributes",
"(",
"$",
"name",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"attributes",
"=",
"''",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"attributes",
";",
"}",
"foreach",
"(",
"$",
"options",
"[",
"$",
"name",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"!==",
"'tag'",
"&&",
"$",
"key",
"!==",
"'value'",
")",
"{",
"$",
"value",
"=",
"is_callable",
"(",
"$",
"value",
")",
"?",
"$",
"value",
"(",
"$",
"options",
"[",
"$",
"name",
"]",
",",
"$",
"options",
")",
":",
"$",
"value",
";",
"$",
"attributes",
".=",
"!",
"empty",
"(",
"$",
"value",
")",
"?",
"' '",
".",
"$",
"key",
".",
"'=\"'",
".",
"$",
"value",
".",
"'\"'",
":",
"''",
";",
"}",
"}",
"return",
"$",
"attributes",
";",
"}"
] | @param $name
@param null $options
@return string | [
"@param",
"$name",
"@param",
"null",
"$options"
] | train | https://github.com/judus/minimal-html/blob/0e1788b0b4b86a705e4f8cd402b4a2336b09d666/src/Table.php#L803-L819 |
judus/minimal-html | src/Table.php | Table.getColgroup | public function getColgroup($data, $options = null)
{
$cols = '';
$i = 0;
foreach ($data as $rowIndex => $rowValue) {
foreach ($rowValue as $colIndex => $colValue) {
$attributes = '';
foreach ($options['col'] as $key => $value) {
if ($key !== 'tag') {
$value = is_callable($value) ? $value($colIndex,
$options) : $value;
$attributes .= !empty($value) ? ' ' . $key . '="' . $value . '"' : '';
}
}
$cols .= sprintf($options['col']['tag'], $attributes);
}
$i++;
if ($i > 0) {
break;
}
}
return $cols;
} | php | public function getColgroup($data, $options = null)
{
$cols = '';
$i = 0;
foreach ($data as $rowIndex => $rowValue) {
foreach ($rowValue as $colIndex => $colValue) {
$attributes = '';
foreach ($options['col'] as $key => $value) {
if ($key !== 'tag') {
$value = is_callable($value) ? $value($colIndex,
$options) : $value;
$attributes .= !empty($value) ? ' ' . $key . '="' . $value . '"' : '';
}
}
$cols .= sprintf($options['col']['tag'], $attributes);
}
$i++;
if ($i > 0) {
break;
}
}
return $cols;
} | [
"public",
"function",
"getColgroup",
"(",
"$",
"data",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"cols",
"=",
"''",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"rowIndex",
"=>",
"$",
"rowValue",
")",
"{",
"foreach",
"(",
"$",
"rowValue",
"as",
"$",
"colIndex",
"=>",
"$",
"colValue",
")",
"{",
"$",
"attributes",
"=",
"''",
";",
"foreach",
"(",
"$",
"options",
"[",
"'col'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"!==",
"'tag'",
")",
"{",
"$",
"value",
"=",
"is_callable",
"(",
"$",
"value",
")",
"?",
"$",
"value",
"(",
"$",
"colIndex",
",",
"$",
"options",
")",
":",
"$",
"value",
";",
"$",
"attributes",
".=",
"!",
"empty",
"(",
"$",
"value",
")",
"?",
"' '",
".",
"$",
"key",
".",
"'=\"'",
".",
"$",
"value",
".",
"'\"'",
":",
"''",
";",
"}",
"}",
"$",
"cols",
".=",
"sprintf",
"(",
"$",
"options",
"[",
"'col'",
"]",
"[",
"'tag'",
"]",
",",
"$",
"attributes",
")",
";",
"}",
"$",
"i",
"++",
";",
"if",
"(",
"$",
"i",
">",
"0",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"cols",
";",
"}"
] | @param $data
@param null $options
@return string | [
"@param",
"$data",
"@param",
"null",
"$options"
] | train | https://github.com/judus/minimal-html/blob/0e1788b0b4b86a705e4f8cd402b4a2336b09d666/src/Table.php#L827-L851 |
judus/minimal-html | src/Table.php | Table.getGrid | public function getGrid($data, $row = 'tr', $col = 'td', $options = null)
{
$rows = '';
if (!is_array($data)) {
return $rows;
}
foreach ($data as $rowIndex => $rowValue) {
// Attribute for tr
$attributes[$row] = '';
foreach ($options[$row] as $key => $value) {
if ($key !== 'tag') {
$value = is_callable($value) ?
$value($rowIndex, $rowValue, $options) : $value;
$attributes[$row] .= !empty($value) ? ' ' . $key . '="' . $value . '"' : '';
}
}
$cols = '';
$skipCols = 0;
$skipCols = $this->isShowRowIndex() ? $skipCols + 1 : $skipCols;
$skipCols = $this->isShowRowCheckbox() ? $skipCols + 1 : $skipCols;
$i = 0;
foreach ($rowValue as $colIndex => $colValue) {
// Attribute for td
$attributes[$col] = '';
foreach ($options[$col] as $key => $value) {
if ($key !== 'tag' && $key !== 'value') {
$value = is_callable($value) ?
$value($rowIndex, $colIndex, $colValue,
$options) : $value;
$attributes[$col] .= !empty($value) ? ' ' . $key . '="' . $value . '"' : '';
}
}
// Value for td
if (($row == 'thead_tr' && !$this->theadUsesValue) ||
($row == 'tfoot_tr' && !$this->tfootUsesValue)
) {
if ($rowIndex === 'search') {
$colValue = $i >= $skipCols ? $colValue : '';
} else {
$colValue = $i >= $skipCols ? $colIndex : '';
}
} else {
$colValue = isset($options[$col]['value']) && is_callable($options[$col]['value']) ?
$options[$col]['value']($rowIndex, $colIndex,
$colValue,
$options) : $colValue;
}
$cols .= sprintf($options[$col]['tag'], $attributes[$col],
$colValue);
$i++;
}
$rows .= sprintf($options[$row]['tag'], $attributes[$row], $cols);
}
return $rows;
} | php | public function getGrid($data, $row = 'tr', $col = 'td', $options = null)
{
$rows = '';
if (!is_array($data)) {
return $rows;
}
foreach ($data as $rowIndex => $rowValue) {
// Attribute for tr
$attributes[$row] = '';
foreach ($options[$row] as $key => $value) {
if ($key !== 'tag') {
$value = is_callable($value) ?
$value($rowIndex, $rowValue, $options) : $value;
$attributes[$row] .= !empty($value) ? ' ' . $key . '="' . $value . '"' : '';
}
}
$cols = '';
$skipCols = 0;
$skipCols = $this->isShowRowIndex() ? $skipCols + 1 : $skipCols;
$skipCols = $this->isShowRowCheckbox() ? $skipCols + 1 : $skipCols;
$i = 0;
foreach ($rowValue as $colIndex => $colValue) {
// Attribute for td
$attributes[$col] = '';
foreach ($options[$col] as $key => $value) {
if ($key !== 'tag' && $key !== 'value') {
$value = is_callable($value) ?
$value($rowIndex, $colIndex, $colValue,
$options) : $value;
$attributes[$col] .= !empty($value) ? ' ' . $key . '="' . $value . '"' : '';
}
}
// Value for td
if (($row == 'thead_tr' && !$this->theadUsesValue) ||
($row == 'tfoot_tr' && !$this->tfootUsesValue)
) {
if ($rowIndex === 'search') {
$colValue = $i >= $skipCols ? $colValue : '';
} else {
$colValue = $i >= $skipCols ? $colIndex : '';
}
} else {
$colValue = isset($options[$col]['value']) && is_callable($options[$col]['value']) ?
$options[$col]['value']($rowIndex, $colIndex,
$colValue,
$options) : $colValue;
}
$cols .= sprintf($options[$col]['tag'], $attributes[$col],
$colValue);
$i++;
}
$rows .= sprintf($options[$row]['tag'], $attributes[$row], $cols);
}
return $rows;
} | [
"public",
"function",
"getGrid",
"(",
"$",
"data",
",",
"$",
"row",
"=",
"'tr'",
",",
"$",
"col",
"=",
"'td'",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"rows",
"=",
"''",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"rows",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"rowIndex",
"=>",
"$",
"rowValue",
")",
"{",
"// Attribute for tr",
"$",
"attributes",
"[",
"$",
"row",
"]",
"=",
"''",
";",
"foreach",
"(",
"$",
"options",
"[",
"$",
"row",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"!==",
"'tag'",
")",
"{",
"$",
"value",
"=",
"is_callable",
"(",
"$",
"value",
")",
"?",
"$",
"value",
"(",
"$",
"rowIndex",
",",
"$",
"rowValue",
",",
"$",
"options",
")",
":",
"$",
"value",
";",
"$",
"attributes",
"[",
"$",
"row",
"]",
".=",
"!",
"empty",
"(",
"$",
"value",
")",
"?",
"' '",
".",
"$",
"key",
".",
"'=\"'",
".",
"$",
"value",
".",
"'\"'",
":",
"''",
";",
"}",
"}",
"$",
"cols",
"=",
"''",
";",
"$",
"skipCols",
"=",
"0",
";",
"$",
"skipCols",
"=",
"$",
"this",
"->",
"isShowRowIndex",
"(",
")",
"?",
"$",
"skipCols",
"+",
"1",
":",
"$",
"skipCols",
";",
"$",
"skipCols",
"=",
"$",
"this",
"->",
"isShowRowCheckbox",
"(",
")",
"?",
"$",
"skipCols",
"+",
"1",
":",
"$",
"skipCols",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"rowValue",
"as",
"$",
"colIndex",
"=>",
"$",
"colValue",
")",
"{",
"// Attribute for td",
"$",
"attributes",
"[",
"$",
"col",
"]",
"=",
"''",
";",
"foreach",
"(",
"$",
"options",
"[",
"$",
"col",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"!==",
"'tag'",
"&&",
"$",
"key",
"!==",
"'value'",
")",
"{",
"$",
"value",
"=",
"is_callable",
"(",
"$",
"value",
")",
"?",
"$",
"value",
"(",
"$",
"rowIndex",
",",
"$",
"colIndex",
",",
"$",
"colValue",
",",
"$",
"options",
")",
":",
"$",
"value",
";",
"$",
"attributes",
"[",
"$",
"col",
"]",
".=",
"!",
"empty",
"(",
"$",
"value",
")",
"?",
"' '",
".",
"$",
"key",
".",
"'=\"'",
".",
"$",
"value",
".",
"'\"'",
":",
"''",
";",
"}",
"}",
"// Value for td",
"if",
"(",
"(",
"$",
"row",
"==",
"'thead_tr'",
"&&",
"!",
"$",
"this",
"->",
"theadUsesValue",
")",
"||",
"(",
"$",
"row",
"==",
"'tfoot_tr'",
"&&",
"!",
"$",
"this",
"->",
"tfootUsesValue",
")",
")",
"{",
"if",
"(",
"$",
"rowIndex",
"===",
"'search'",
")",
"{",
"$",
"colValue",
"=",
"$",
"i",
">=",
"$",
"skipCols",
"?",
"$",
"colValue",
":",
"''",
";",
"}",
"else",
"{",
"$",
"colValue",
"=",
"$",
"i",
">=",
"$",
"skipCols",
"?",
"$",
"colIndex",
":",
"''",
";",
"}",
"}",
"else",
"{",
"$",
"colValue",
"=",
"isset",
"(",
"$",
"options",
"[",
"$",
"col",
"]",
"[",
"'value'",
"]",
")",
"&&",
"is_callable",
"(",
"$",
"options",
"[",
"$",
"col",
"]",
"[",
"'value'",
"]",
")",
"?",
"$",
"options",
"[",
"$",
"col",
"]",
"[",
"'value'",
"]",
"(",
"$",
"rowIndex",
",",
"$",
"colIndex",
",",
"$",
"colValue",
",",
"$",
"options",
")",
":",
"$",
"colValue",
";",
"}",
"$",
"cols",
".=",
"sprintf",
"(",
"$",
"options",
"[",
"$",
"col",
"]",
"[",
"'tag'",
"]",
",",
"$",
"attributes",
"[",
"$",
"col",
"]",
",",
"$",
"colValue",
")",
";",
"$",
"i",
"++",
";",
"}",
"$",
"rows",
".=",
"sprintf",
"(",
"$",
"options",
"[",
"$",
"row",
"]",
"[",
"'tag'",
"]",
",",
"$",
"attributes",
"[",
"$",
"row",
"]",
",",
"$",
"cols",
")",
";",
"}",
"return",
"$",
"rows",
";",
"}"
] | @param $data
@param string $row
@param string $col
@param null $options
@return string | [
"@param",
"$data",
"@param",
"string",
"$row",
"@param",
"string",
"$col",
"@param",
"null",
"$options"
] | train | https://github.com/judus/minimal-html/blob/0e1788b0b4b86a705e4f8cd402b4a2336b09d666/src/Table.php#L861-L932 |
freialib/fenrir.system | src/Web.php | Web.send | function send($contents, $status = 200, array $headers = null) {
$this->http_response_code($status);
if ($headers !== null) {
foreach ($headers as $header) {
$this->header($header[0], $header[1], $header[2]);
}
}
if ( ! empty($contents)) {
echo $contents;
}
} | php | function send($contents, $status = 200, array $headers = null) {
$this->http_response_code($status);
if ($headers !== null) {
foreach ($headers as $header) {
$this->header($header[0], $header[1], $header[2]);
}
}
if ( ! empty($contents)) {
echo $contents;
}
} | [
"function",
"send",
"(",
"$",
"contents",
",",
"$",
"status",
"=",
"200",
",",
"array",
"$",
"headers",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"http_response_code",
"(",
"$",
"status",
")",
";",
"if",
"(",
"$",
"headers",
"!==",
"null",
")",
"{",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"header",
")",
"{",
"$",
"this",
"->",
"header",
"(",
"$",
"header",
"[",
"0",
"]",
",",
"$",
"header",
"[",
"1",
"]",
",",
"$",
"header",
"[",
"2",
"]",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"contents",
")",
")",
"{",
"echo",
"$",
"contents",
";",
"}",
"}"
] | Sent content to the client. | [
"Sent",
"content",
"to",
"the",
"client",
"."
] | train | https://github.com/freialib/fenrir.system/blob/388d360dbc3bc6dcf85b09bb06e08a2dce8f3ec8/src/Web.php#L86-L99 |
frodosghost/AtomLoggerBundle | Controller/Controller.php | Controller.createNotFoundException | public function createNotFoundException($message = 'Not Found', \Exception $previous = null)
{
if ($this->has('atom.404.logger')) {
$log = $this->get('atom.404.logger');
$log->addRecord(400, $message, array('request' => $this->getRequest()->getUri()));
}
return new NotFoundHttpException($message, $previous);
} | php | public function createNotFoundException($message = 'Not Found', \Exception $previous = null)
{
if ($this->has('atom.404.logger')) {
$log = $this->get('atom.404.logger');
$log->addRecord(400, $message, array('request' => $this->getRequest()->getUri()));
}
return new NotFoundHttpException($message, $previous);
} | [
"public",
"function",
"createNotFoundException",
"(",
"$",
"message",
"=",
"'Not Found'",
",",
"\\",
"Exception",
"$",
"previous",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"'atom.404.logger'",
")",
")",
"{",
"$",
"log",
"=",
"$",
"this",
"->",
"get",
"(",
"'atom.404.logger'",
")",
";",
"$",
"log",
"->",
"addRecord",
"(",
"400",
",",
"$",
"message",
",",
"array",
"(",
"'request'",
"=>",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getUri",
"(",
")",
")",
")",
";",
"}",
"return",
"new",
"NotFoundHttpException",
"(",
"$",
"message",
",",
"$",
"previous",
")",
";",
"}"
] | Sends 404 to Page AtomLogger
@param string $message Error Message to be logged
@param \Exception $previous Previous message made prior to 404
@return NotFoundHttpException | [
"Sends",
"404",
"to",
"Page",
"AtomLogger"
] | train | https://github.com/frodosghost/AtomLoggerBundle/blob/c48823e4b3772e498b366867f27e6581f613f733/Controller/Controller.php#L26-L34 |
RhubarbPHP/Scaffold.RepositoryLog | src/RepositoryLog.php | RepositoryLog.writeFormattedEntry | protected function writeFormattedEntry($level, $message, $category = "", $additionalData)
{
// There are a number of occasions where this method can cause an infinite loop:
//
// 1) Writing a database entry could cause PDO log entries to be generated
// 2) If any of the following lines should through warnings or notices AND these are set to report
// through this logger.
//
// For this reason we ask the log framework to suspend logging until this method is complete.
Log::disableLogging();
$logEntryModelClassName = $this->logEntryModelClassName;
/** @var RhubarbLogEntry $logEntry */
$logEntry = new $logEntryModelClassName();
$logEntry->Level = $level;
$logEntry->LogSession = $this->uniqueIdentifier;
$logEntry->IpAddress = self::getRemoteIP();
$logEntry->Category = ($category == "") ? "CORE" : $category;
$logEntry->EntryDate = "now";
$logEntry->ExecutionTime = $this->getExecutionTime();
$logEntry->ExecutionGapTime = $this->getTimeSinceLastLog();
$logEntry->Message = $message;
$logEntry->Request = isset($_SERVER["SCRIPT_URI"]) ? $_SERVER["SCRIPT_URI"] : '';
$logEntry->Host = isset($_SERVER["SERVER_NAME"]) ? $_SERVER["SERVER_NAME"] : '';
$logEntry->ScriptName = isset($_SERVER["SCRIPT_NAME"]) ? $_SERVER["SCRIPT_NAME"] : '';
if (is_array($additionalData) || is_object($additionalData)) {
$additionalData = json_encode($additionalData, JSON_PRETTY_PRINT);
}
$logEntry->AdditionalData = $additionalData;
$logEntry->save();
Log::enableLogging();
} | php | protected function writeFormattedEntry($level, $message, $category = "", $additionalData)
{
// There are a number of occasions where this method can cause an infinite loop:
//
// 1) Writing a database entry could cause PDO log entries to be generated
// 2) If any of the following lines should through warnings or notices AND these are set to report
// through this logger.
//
// For this reason we ask the log framework to suspend logging until this method is complete.
Log::disableLogging();
$logEntryModelClassName = $this->logEntryModelClassName;
/** @var RhubarbLogEntry $logEntry */
$logEntry = new $logEntryModelClassName();
$logEntry->Level = $level;
$logEntry->LogSession = $this->uniqueIdentifier;
$logEntry->IpAddress = self::getRemoteIP();
$logEntry->Category = ($category == "") ? "CORE" : $category;
$logEntry->EntryDate = "now";
$logEntry->ExecutionTime = $this->getExecutionTime();
$logEntry->ExecutionGapTime = $this->getTimeSinceLastLog();
$logEntry->Message = $message;
$logEntry->Request = isset($_SERVER["SCRIPT_URI"]) ? $_SERVER["SCRIPT_URI"] : '';
$logEntry->Host = isset($_SERVER["SERVER_NAME"]) ? $_SERVER["SERVER_NAME"] : '';
$logEntry->ScriptName = isset($_SERVER["SCRIPT_NAME"]) ? $_SERVER["SCRIPT_NAME"] : '';
if (is_array($additionalData) || is_object($additionalData)) {
$additionalData = json_encode($additionalData, JSON_PRETTY_PRINT);
}
$logEntry->AdditionalData = $additionalData;
$logEntry->save();
Log::enableLogging();
} | [
"protected",
"function",
"writeFormattedEntry",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"category",
"=",
"\"\"",
",",
"$",
"additionalData",
")",
"{",
"// There are a number of occasions where this method can cause an infinite loop:",
"//",
"// 1) Writing a database entry could cause PDO log entries to be generated",
"// 2) If any of the following lines should through warnings or notices AND these are set to report",
"// through this logger.",
"//",
"// For this reason we ask the log framework to suspend logging until this method is complete.",
"Log",
"::",
"disableLogging",
"(",
")",
";",
"$",
"logEntryModelClassName",
"=",
"$",
"this",
"->",
"logEntryModelClassName",
";",
"/** @var RhubarbLogEntry $logEntry */",
"$",
"logEntry",
"=",
"new",
"$",
"logEntryModelClassName",
"(",
")",
";",
"$",
"logEntry",
"->",
"Level",
"=",
"$",
"level",
";",
"$",
"logEntry",
"->",
"LogSession",
"=",
"$",
"this",
"->",
"uniqueIdentifier",
";",
"$",
"logEntry",
"->",
"IpAddress",
"=",
"self",
"::",
"getRemoteIP",
"(",
")",
";",
"$",
"logEntry",
"->",
"Category",
"=",
"(",
"$",
"category",
"==",
"\"\"",
")",
"?",
"\"CORE\"",
":",
"$",
"category",
";",
"$",
"logEntry",
"->",
"EntryDate",
"=",
"\"now\"",
";",
"$",
"logEntry",
"->",
"ExecutionTime",
"=",
"$",
"this",
"->",
"getExecutionTime",
"(",
")",
";",
"$",
"logEntry",
"->",
"ExecutionGapTime",
"=",
"$",
"this",
"->",
"getTimeSinceLastLog",
"(",
")",
";",
"$",
"logEntry",
"->",
"Message",
"=",
"$",
"message",
";",
"$",
"logEntry",
"->",
"Request",
"=",
"isset",
"(",
"$",
"_SERVER",
"[",
"\"SCRIPT_URI\"",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"\"SCRIPT_URI\"",
"]",
":",
"''",
";",
"$",
"logEntry",
"->",
"Host",
"=",
"isset",
"(",
"$",
"_SERVER",
"[",
"\"SERVER_NAME\"",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"\"SERVER_NAME\"",
"]",
":",
"''",
";",
"$",
"logEntry",
"->",
"ScriptName",
"=",
"isset",
"(",
"$",
"_SERVER",
"[",
"\"SCRIPT_NAME\"",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"\"SCRIPT_NAME\"",
"]",
":",
"''",
";",
"if",
"(",
"is_array",
"(",
"$",
"additionalData",
")",
"||",
"is_object",
"(",
"$",
"additionalData",
")",
")",
"{",
"$",
"additionalData",
"=",
"json_encode",
"(",
"$",
"additionalData",
",",
"JSON_PRETTY_PRINT",
")",
";",
"}",
"$",
"logEntry",
"->",
"AdditionalData",
"=",
"$",
"additionalData",
";",
"$",
"logEntry",
"->",
"save",
"(",
")",
";",
"Log",
"::",
"enableLogging",
"(",
")",
";",
"}"
] | The logger should implement this method to perform the actual log committal.
@param int $level The log level
@param string $message The text message to log
@param string $category The category of log message
@param array $additionalData Any number of additional key value pairs which can be understood by specific
logs (e.g. an API log might understand what AuthenticationToken means)
@return mixed | [
"The",
"logger",
"should",
"implement",
"this",
"method",
"to",
"perform",
"the",
"actual",
"log",
"committal",
"."
] | train | https://github.com/RhubarbPHP/Scaffold.RepositoryLog/blob/7e54f6a1553d3baff7c2fd58c97e022ad1c2c8d3/src/RepositoryLog.php#L29-L65 |
nicodevs/laito | src/Laito/Controller.php | Controller.index | public function index($params = [])
{
// Set the filters
$params = (!empty($params))? $params : $this->app->request->input();
// Get records
$this->model->params = $params;
$result = $this->model->search($params)->get();
// Get pagination and number of records
$pagination = array_merge(
['records' => $this->model->search($params)->count()],
$this->model->pagination()
);
// Return results
return [
'success' => true,
'paging' => $pagination,
'data' => $result
];
} | php | public function index($params = [])
{
// Set the filters
$params = (!empty($params))? $params : $this->app->request->input();
// Get records
$this->model->params = $params;
$result = $this->model->search($params)->get();
// Get pagination and number of records
$pagination = array_merge(
['records' => $this->model->search($params)->count()],
$this->model->pagination()
);
// Return results
return [
'success' => true,
'paging' => $pagination,
'data' => $result
];
} | [
"public",
"function",
"index",
"(",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"// Set the filters",
"$",
"params",
"=",
"(",
"!",
"empty",
"(",
"$",
"params",
")",
")",
"?",
"$",
"params",
":",
"$",
"this",
"->",
"app",
"->",
"request",
"->",
"input",
"(",
")",
";",
"// Get records",
"$",
"this",
"->",
"model",
"->",
"params",
"=",
"$",
"params",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"model",
"->",
"search",
"(",
"$",
"params",
")",
"->",
"get",
"(",
")",
";",
"// Get pagination and number of records",
"$",
"pagination",
"=",
"array_merge",
"(",
"[",
"'records'",
"=>",
"$",
"this",
"->",
"model",
"->",
"search",
"(",
"$",
"params",
")",
"->",
"count",
"(",
")",
"]",
",",
"$",
"this",
"->",
"model",
"->",
"pagination",
"(",
")",
")",
";",
"// Return results",
"return",
"[",
"'success'",
"=>",
"true",
",",
"'paging'",
"=>",
"$",
"pagination",
",",
"'data'",
"=>",
"$",
"result",
"]",
";",
"}"
] | Display a listing of the resource
@param array $params Listing parameters
@return array Response | [
"Display",
"a",
"listing",
"of",
"the",
"resource"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Controller.php#L49-L70 |
nicodevs/laito | src/Laito/Controller.php | Controller.show | public function show($id = null)
{
// Check the ID
if (!isset($id)) {
throw new \InvalidArgumentException('Undefined ID', 400);
}
// Get record
$item = $this->model->find($id);
// Abort if the record is not found
if (!$item) {
throw new \Exception('Element not found', 404);
}
// Return response
return [
'success' => true,
'data' => $item
];
} | php | public function show($id = null)
{
// Check the ID
if (!isset($id)) {
throw new \InvalidArgumentException('Undefined ID', 400);
}
// Get record
$item = $this->model->find($id);
// Abort if the record is not found
if (!$item) {
throw new \Exception('Element not found', 404);
}
// Return response
return [
'success' => true,
'data' => $item
];
} | [
"public",
"function",
"show",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"// Check the ID",
"if",
"(",
"!",
"isset",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Undefined ID'",
",",
"400",
")",
";",
"}",
"// Get record",
"$",
"item",
"=",
"$",
"this",
"->",
"model",
"->",
"find",
"(",
"$",
"id",
")",
";",
"// Abort if the record is not found",
"if",
"(",
"!",
"$",
"item",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Element not found'",
",",
"404",
")",
";",
"}",
"// Return response",
"return",
"[",
"'success'",
"=>",
"true",
",",
"'data'",
"=>",
"$",
"item",
"]",
";",
"}"
] | Display the specified resource
@param array $id Resource ID
@return array Response | [
"Display",
"the",
"specified",
"resource"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Controller.php#L78-L98 |
nicodevs/laito | src/Laito/Controller.php | Controller.store | public function store($attributes = [])
{
// Set the attributes
$attributes = (!empty($attributes))? $attributes : $this->app->request->input();
// Create the record
$result = $this->model->create($attributes);
// Return results
return [
'success' => true,
'id' => $result['id'],
'data' => $result
];
} | php | public function store($attributes = [])
{
// Set the attributes
$attributes = (!empty($attributes))? $attributes : $this->app->request->input();
// Create the record
$result = $this->model->create($attributes);
// Return results
return [
'success' => true,
'id' => $result['id'],
'data' => $result
];
} | [
"public",
"function",
"store",
"(",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"// Set the attributes",
"$",
"attributes",
"=",
"(",
"!",
"empty",
"(",
"$",
"attributes",
")",
")",
"?",
"$",
"attributes",
":",
"$",
"this",
"->",
"app",
"->",
"request",
"->",
"input",
"(",
")",
";",
"// Create the record",
"$",
"result",
"=",
"$",
"this",
"->",
"model",
"->",
"create",
"(",
"$",
"attributes",
")",
";",
"// Return results",
"return",
"[",
"'success'",
"=>",
"true",
",",
"'id'",
"=>",
"$",
"result",
"[",
"'id'",
"]",
",",
"'data'",
"=>",
"$",
"result",
"]",
";",
"}"
] | Stores a newly created resource in storage
@param array $params Resource attributes
@return array Response | [
"Stores",
"a",
"newly",
"created",
"resource",
"in",
"storage"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Controller.php#L106-L120 |
nicodevs/laito | src/Laito/Controller.php | Controller.update | public function update($id = null, $attributes = [])
{
// Check the ID
if (!isset($id)) {
throw new \InvalidArgumentException('Undefined ID', 400);
}
// Set the attributes
$attributes = (!empty($attributes))? $attributes : $this->app->request->input();
// Update the record
$result = $this->model->update($id, $attributes);
// Return results
return [
'success' => true,
'id' => $id,
'data' => $result
];
} | php | public function update($id = null, $attributes = [])
{
// Check the ID
if (!isset($id)) {
throw new \InvalidArgumentException('Undefined ID', 400);
}
// Set the attributes
$attributes = (!empty($attributes))? $attributes : $this->app->request->input();
// Update the record
$result = $this->model->update($id, $attributes);
// Return results
return [
'success' => true,
'id' => $id,
'data' => $result
];
} | [
"public",
"function",
"update",
"(",
"$",
"id",
"=",
"null",
",",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"// Check the ID",
"if",
"(",
"!",
"isset",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Undefined ID'",
",",
"400",
")",
";",
"}",
"// Set the attributes",
"$",
"attributes",
"=",
"(",
"!",
"empty",
"(",
"$",
"attributes",
")",
")",
"?",
"$",
"attributes",
":",
"$",
"this",
"->",
"app",
"->",
"request",
"->",
"input",
"(",
")",
";",
"// Update the record",
"$",
"result",
"=",
"$",
"this",
"->",
"model",
"->",
"update",
"(",
"$",
"id",
",",
"$",
"attributes",
")",
";",
"// Return results",
"return",
"[",
"'success'",
"=>",
"true",
",",
"'id'",
"=>",
"$",
"id",
",",
"'data'",
"=>",
"$",
"result",
"]",
";",
"}"
] | Update the specified resource in storage
@param array $id Resource ID
@return array Response | [
"Update",
"the",
"specified",
"resource",
"in",
"storage"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Controller.php#L128-L147 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.