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
listlengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
listlengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
lode/fem
|
src/routing.php
|
routing.find_custom_handler
|
private function find_custom_handler() {
// get user defined routes
$routes = $this->get_custom_routes();
if (empty($routes) || empty($routes[$this->method])) {
return false;
}
// catch the non-regex routes first
if (isset($routes[$this->method][$this->url])) {
return $routes[$this->method][$this->url];
}
// find a matching regex
$handler = false;
foreach ($routes[$this->method] as $url_regex => $possible_handler) {
if (preg_match('{^'.$url_regex.'$}', $this->url, $matches)) {
$handler = $possible_handler;
// save named subpatterns from the regex, to send them through to the handler
if (strpos($url_regex, '?<') && count($matches) > 1) {
$this->arguments = $matches;
}
break;
}
}
return $handler;
}
|
php
|
private function find_custom_handler() {
// get user defined routes
$routes = $this->get_custom_routes();
if (empty($routes) || empty($routes[$this->method])) {
return false;
}
// catch the non-regex routes first
if (isset($routes[$this->method][$this->url])) {
return $routes[$this->method][$this->url];
}
// find a matching regex
$handler = false;
foreach ($routes[$this->method] as $url_regex => $possible_handler) {
if (preg_match('{^'.$url_regex.'$}', $this->url, $matches)) {
$handler = $possible_handler;
// save named subpatterns from the regex, to send them through to the handler
if (strpos($url_regex, '?<') && count($matches) > 1) {
$this->arguments = $matches;
}
break;
}
}
return $handler;
}
|
[
"private",
"function",
"find_custom_handler",
"(",
")",
"{",
"// get user defined routes",
"$",
"routes",
"=",
"$",
"this",
"->",
"get_custom_routes",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"routes",
")",
"||",
"empty",
"(",
"$",
"routes",
"[",
"$",
"this",
"->",
"method",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"// catch the non-regex routes first",
"if",
"(",
"isset",
"(",
"$",
"routes",
"[",
"$",
"this",
"->",
"method",
"]",
"[",
"$",
"this",
"->",
"url",
"]",
")",
")",
"{",
"return",
"$",
"routes",
"[",
"$",
"this",
"->",
"method",
"]",
"[",
"$",
"this",
"->",
"url",
"]",
";",
"}",
"// find a matching regex",
"$",
"handler",
"=",
"false",
";",
"foreach",
"(",
"$",
"routes",
"[",
"$",
"this",
"->",
"method",
"]",
"as",
"$",
"url_regex",
"=>",
"$",
"possible_handler",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'{^'",
".",
"$",
"url_regex",
".",
"'$}'",
",",
"$",
"this",
"->",
"url",
",",
"$",
"matches",
")",
")",
"{",
"$",
"handler",
"=",
"$",
"possible_handler",
";",
"// save named subpatterns from the regex, to send them through to the handler",
"if",
"(",
"strpos",
"(",
"$",
"url_regex",
",",
"'?<'",
")",
"&&",
"count",
"(",
"$",
"matches",
")",
">",
"1",
")",
"{",
"$",
"this",
"->",
"arguments",
"=",
"$",
"matches",
";",
"}",
"break",
";",
"}",
"}",
"return",
"$",
"handler",
";",
"}"
] |
matches the user defined routes
@return mixed $handler see get_handler_type()
|
[
"matches",
"the",
"user",
"defined",
"routes"
] |
train
|
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/routing.php#L207-L234
|
lode/fem
|
src/routing.php
|
routing.get_handler_type
|
private function get_handler_type($handler) {
if ($handler instanceof \Closure) {
return 'function';
}
if (is_string($handler) == false) {
return false;
}
if (strpos($handler, '->')) {
return 'method';
}
if (strpos($handler, '::')) {
return 'static';
}
if ($handler && $this->find_handler_path($handler)) {
return 'file';
}
return false;
}
|
php
|
private function get_handler_type($handler) {
if ($handler instanceof \Closure) {
return 'function';
}
if (is_string($handler) == false) {
return false;
}
if (strpos($handler, '->')) {
return 'method';
}
if (strpos($handler, '::')) {
return 'static';
}
if ($handler && $this->find_handler_path($handler)) {
return 'file';
}
return false;
}
|
[
"private",
"function",
"get_handler_type",
"(",
"$",
"handler",
")",
"{",
"if",
"(",
"$",
"handler",
"instanceof",
"\\",
"Closure",
")",
"{",
"return",
"'function'",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"handler",
")",
"==",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"handler",
",",
"'->'",
")",
")",
"{",
"return",
"'method'",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"handler",
",",
"'::'",
")",
")",
"{",
"return",
"'static'",
";",
"}",
"if",
"(",
"$",
"handler",
"&&",
"$",
"this",
"->",
"find_handler_path",
"(",
"$",
"handler",
")",
")",
"{",
"return",
"'file'",
";",
"}",
"return",
"false",
";",
"}"
] |
figure out how to run the given handler
there are a few different handlers formats:
- function: an inline function directly handling the request
@note it can call handle() with a new handler of another type ..
.. this might be useful for database lookups
- method: a method in the format of 'class->method'
the class will be instantiated before invoking the method
- static: a method in the format of 'class::method'
where the method will be called statically
- file: a file path (relative to $handler_base_path)
@see $auto_instantiation: it can instantiate a class with the same name
@param mixed $handler
@return string|boolean the name of the handler from above description ..
.. or false when unknown
|
[
"figure",
"out",
"how",
"to",
"run",
"the",
"given",
"handler"
] |
train
|
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/routing.php#L258-L277
|
lode/fem
|
src/routing.php
|
routing.load_handler_as_method
|
private function load_handler_as_method($handler) {
list($class, $method) = explode('->', $handler);
$object = new $class;
$object->$method($this->url, $this->method, $this->arguments);
}
|
php
|
private function load_handler_as_method($handler) {
list($class, $method) = explode('->', $handler);
$object = new $class;
$object->$method($this->url, $this->method, $this->arguments);
}
|
[
"private",
"function",
"load_handler_as_method",
"(",
"$",
"handler",
")",
"{",
"list",
"(",
"$",
"class",
",",
"$",
"method",
")",
"=",
"explode",
"(",
"'->'",
",",
"$",
"handler",
")",
";",
"$",
"object",
"=",
"new",
"$",
"class",
";",
"$",
"object",
"->",
"$",
"method",
"(",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"method",
",",
"$",
"this",
"->",
"arguments",
")",
";",
"}"
] |
instantiated method handler
@param string $handler
@return void, the method is called on the object
|
[
"instantiated",
"method",
"handler"
] |
train
|
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/routing.php#L295-L300
|
lode/fem
|
src/routing.php
|
routing.load_handler_as_static
|
private function load_handler_as_static($handler) {
list($class, $method) = explode('::', $handler);
$class::$method($this->url, $this->method, $this->arguments);
}
|
php
|
private function load_handler_as_static($handler) {
list($class, $method) = explode('::', $handler);
$class::$method($this->url, $this->method, $this->arguments);
}
|
[
"private",
"function",
"load_handler_as_static",
"(",
"$",
"handler",
")",
"{",
"list",
"(",
"$",
"class",
",",
"$",
"method",
")",
"=",
"explode",
"(",
"'::'",
",",
"$",
"handler",
")",
";",
"$",
"class",
"::",
"$",
"method",
"(",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"method",
",",
"$",
"this",
"->",
"arguments",
")",
";",
"}"
] |
static method handler
@param string $handler
@return void, the method is called on the class
|
[
"static",
"method",
"handler"
] |
train
|
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/routing.php#L308-L312
|
lode/fem
|
src/routing.php
|
routing.load_handler_as_file
|
private function load_handler_as_file($handler) {
$path = $this->find_handler_path($handler);
require_once $path;
$class_name = str_replace('/', '\\', $handler);
if ($this->auto_instantiation && is_callable($class_name)) {
new $class_name($this->url, $this->method, $this->arguments);
}
}
|
php
|
private function load_handler_as_file($handler) {
$path = $this->find_handler_path($handler);
require_once $path;
$class_name = str_replace('/', '\\', $handler);
if ($this->auto_instantiation && is_callable($class_name)) {
new $class_name($this->url, $this->method, $this->arguments);
}
}
|
[
"private",
"function",
"load_handler_as_file",
"(",
"$",
"handler",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"find_handler_path",
"(",
"$",
"handler",
")",
";",
"require_once",
"$",
"path",
";",
"$",
"class_name",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"handler",
")",
";",
"if",
"(",
"$",
"this",
"->",
"auto_instantiation",
"&&",
"is_callable",
"(",
"$",
"class_name",
")",
")",
"{",
"new",
"$",
"class_name",
"(",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"method",
",",
"$",
"this",
"->",
"arguments",
")",
";",
"}",
"}"
] |
file reference handler
@param string $handler
@return void, the file is included
a inner class is instantiated if $this->auto_instantiation is true
|
[
"file",
"reference",
"handler"
] |
train
|
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/routing.php#L321-L329
|
yuncms/framework
|
src/admin/migrations/m180324_103503_create_admin_menu_table.php
|
m180324_103503_create_admin_menu_table.safeUp
|
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
}
$this->createTable($this->tableName, [
'id' => $this->primaryKey()->unsigned()->comment('ID'),
'name' => $this->string(128)->notNull()->comment('Name'),
'parent' => $this->integer()->unsigned()->comment('Parent'),
'route' => $this->string()->comment('Route'),
'icon' => $this->string(30)->comment('Icon'),
'visible' => $this->boolean()->defaultValue(true)->comment('Visible'),
'sort' => $this->smallInteger()->defaultValue(99)->comment('Sort'),
'data' => $this->text()->comment('Data')
], $tableOptions);
$this->addForeignKey('admin_menu_fk_1', $this->tableName, 'parent', $this->tableName, 'id', 'SET NULL', 'CASCADE');
$this->batchInsert($this->tableName, ['id', 'name', 'parent', 'route', 'icon', 'sort', 'data'], [
//一级主菜单
[1, '控制台', NULL, '/site/index', 'fa-th-large', 1, NULL],
[2, '核心设置', NULL, NULL, 'fa-cog', 2, NULL],
[3, '数据管理', NULL, NULL, 'fa-wrench', 3, NULL],
[4, '运营中心', NULL, NULL, 'fa-bar-chart-o', 4, NULL],
[5, '用户管理', NULL, NULL, 'fa-user', 5, NULL],
[6, '网站管理', NULL, NULL, 'fa-bars', 6, NULL],
[7, '财务管理', NULL, NULL, 'fa-cny', 7, NULL],
[8, '模块管理', NULL, NULL, 'fa-th', 8, NULL],
[9, '模板管理', NULL, NULL, 'fa-laptop', 9, NULL],
//核心设置子菜单
[21, '站点设置', 2, '/admin/setting/setting', 'fa-gears', 1, NULL],
[22, '管理员管理', 2, '/admin/admin/index', 'fa-user', 2, NULL],
[24, '角色管理', 2, '/admin/role/index', 'fa-group', 3, NULL],
[25, '权限管理', 2, '/admin/permission/index', 'fa-certificate', 4, NULL],
[26, '路由管理', 2, '/admin/route/index', 'fa-cloud', 5, NULL],
[27, '规则管理', 2, '/admin/rule/index', 'fa-key', 6, NULL],
[28, '菜单管理', 2, '/admin/menu/index', 'fa-wrench', 7, NULL],
[29, '附件设置', 2, '/admin/attachment/setting', 'fa-cog', 8, NULL],
[30, '执行计划', 2, '/admin/task/index', 'fa-spinner', 8, NULL],
[50, '用户管理', 5, '/admin/user/index', 'fa-user', 2, NULL],
[51, '角色管理', 5, '/admin/user-role/index', 'fa-group', 3, NULL],
[52, '权限管理', 5, '/admin/user-permission/index', 'fa-certificate', 4, NULL],
//[53, '路由管理', 5, '/admin/user-route/index', 'fa-cloud', 5, NULL],
[54, '规则管理', 5, '/admin/user-rule/index', 'fa-key', 6, NULL],
// [40, '地区管理', 3, '/area/index', 'fa-globe', 1, NULL],
//[43, '敏感词管理', 3, '/admin/ban-word/index', 'fa-exclamation-triangle', 2, NULL],
]);
//隐藏的子菜单[隐藏的子菜单不设置id字段,使用自增]//从10000开始
$this->batchInsert($this->tableName, ['id', 'name', 'parent', 'route', 'visible', 'sort'], [
[10000, '管理员查看', 22, '/admin/admin/view', 0, NULL],
]);
$this->batchInsert($this->tableName, ['name', 'parent', 'route', 'visible', 'sort'], [
['更新管理员', 22, '/admin/admin/update', 0, NULL], ['授权设置', 22, '/admin/assignment/view', 0, NULL],
['角色查看', 24, '/admin/role/view', 0, NULL], ['创建角色', 24, '/admin/role/create', 0, NULL], ['更新角色', 24, '/admin/role/update', 0, NULL],
['权限查看', 25, '/admin/permission/view', 0, NULL], ['创建权限', 25, '/admin/permission/create', 0, NULL], ['更新权限', 25, '/admin/permission/update', 0, NULL],
['路由查看', 26, '/admin/route/view', 0, NULL], ['创建路由', 26, '/admin/route/create', 0, NULL],
['规则查看', 27, '/admin/rule/view', 0, NULL], ['创建规则', 27, '/admin/rule/create', 0, NULL], ['更新规则', 27, '/admin/rule/update', 0, NULL],
['菜单查看', 28, '/admin/menu/view', 0, NULL], ['创建菜单', 28, '/admin/menu/create', 0, NULL], ['更新菜单', 28, '/admin/menu/update', 0, NULL],
//['创建地区', 40, '/area/create', 0, NULL], ['更新地区', 40, '/area/update', 0, NULL],
//['敏感词查看', 43, '/admin/ban-word/view', 0, NULL], ['创建敏感词', 43, '/admin/ban-word/create', 0, NULL], ['更新敏感词', 43, '/admin/ban-word/update', 0, NULL],
]);
$this->batchInsert($this->tableName, ['name', 'parent', 'route', 'visible', 'sort'], [
['用户设置', 50, '/admin/user/settings', 0, NULL],
['新建用户', 50, '/admin/user/create', 0, NULL],
['用户查看', 50, '/admin/user/view', 0, NULL],
['用户修改', 50, '/admin/user/update-profile', 0, NULL],
['账户详情', 50, '/admin/user/update', 0, NULL],
['权限分配', 50, '/admin/user-assignment/view', 0, NULL],
//['授权设置', 52, '/admin/user-assignment/view', 0, NULL],
['角色查看', 51, '/admin/user-role/view', 0, NULL], ['创建角色', 51, '/admin/user-role/create', 0, NULL], ['更新角色', 51, '/admin/user-role/update', 0, NULL],
['权限查看', 52, '/admin/user-permission/view', 0, NULL], ['创建权限', 52, '/admin/user-permission/create', 0, NULL], ['更新权限', 52, '/admin/user-permission/update', 0, NULL],
//['路由查看', 53, '/admin/user-route/view', 0, NULL], ['创建路由', 53, '/admin/user-route/create', 0, NULL],
['规则查看', 54, '/admin/user-rule/view', 0, NULL], ['创建规则', 54, '/admin/user-rule/create', 0, NULL], ['更新规则', 54, '/admin/user-rule/update', 0, NULL],
]);
$this->insert($this->tableName, ['name' => '附件管理', 'parent' => 8, 'route' => '/admin/attachment/index', 'icon' => 'fa-cog', 'sort' => NULL, 'data' => NULL]);
//OAuth2
$this->insert($this->tableName, ['name' => 'App管理', 'parent' => 8, 'route' => '/admin/oauth2/index', 'icon' => 'fa fa-apple', 'sort' => NULL, 'data' => NULL]);
$id = (new Query())->select(['id'])->from($this->tableName)->where(['name' => 'App管理', 'parent' => 8])->scalar($this->getDb());
$this->batchInsert($this->tableName, ['name', 'parent', 'route', 'visible', 'sort'], [
['App查看', $id, '/admin/oauth2/view', 0, NULL],
]);
}
|
php
|
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
}
$this->createTable($this->tableName, [
'id' => $this->primaryKey()->unsigned()->comment('ID'),
'name' => $this->string(128)->notNull()->comment('Name'),
'parent' => $this->integer()->unsigned()->comment('Parent'),
'route' => $this->string()->comment('Route'),
'icon' => $this->string(30)->comment('Icon'),
'visible' => $this->boolean()->defaultValue(true)->comment('Visible'),
'sort' => $this->smallInteger()->defaultValue(99)->comment('Sort'),
'data' => $this->text()->comment('Data')
], $tableOptions);
$this->addForeignKey('admin_menu_fk_1', $this->tableName, 'parent', $this->tableName, 'id', 'SET NULL', 'CASCADE');
$this->batchInsert($this->tableName, ['id', 'name', 'parent', 'route', 'icon', 'sort', 'data'], [
//一级主菜单
[1, '控制台', NULL, '/site/index', 'fa-th-large', 1, NULL],
[2, '核心设置', NULL, NULL, 'fa-cog', 2, NULL],
[3, '数据管理', NULL, NULL, 'fa-wrench', 3, NULL],
[4, '运营中心', NULL, NULL, 'fa-bar-chart-o', 4, NULL],
[5, '用户管理', NULL, NULL, 'fa-user', 5, NULL],
[6, '网站管理', NULL, NULL, 'fa-bars', 6, NULL],
[7, '财务管理', NULL, NULL, 'fa-cny', 7, NULL],
[8, '模块管理', NULL, NULL, 'fa-th', 8, NULL],
[9, '模板管理', NULL, NULL, 'fa-laptop', 9, NULL],
//核心设置子菜单
[21, '站点设置', 2, '/admin/setting/setting', 'fa-gears', 1, NULL],
[22, '管理员管理', 2, '/admin/admin/index', 'fa-user', 2, NULL],
[24, '角色管理', 2, '/admin/role/index', 'fa-group', 3, NULL],
[25, '权限管理', 2, '/admin/permission/index', 'fa-certificate', 4, NULL],
[26, '路由管理', 2, '/admin/route/index', 'fa-cloud', 5, NULL],
[27, '规则管理', 2, '/admin/rule/index', 'fa-key', 6, NULL],
[28, '菜单管理', 2, '/admin/menu/index', 'fa-wrench', 7, NULL],
[29, '附件设置', 2, '/admin/attachment/setting', 'fa-cog', 8, NULL],
[30, '执行计划', 2, '/admin/task/index', 'fa-spinner', 8, NULL],
[50, '用户管理', 5, '/admin/user/index', 'fa-user', 2, NULL],
[51, '角色管理', 5, '/admin/user-role/index', 'fa-group', 3, NULL],
[52, '权限管理', 5, '/admin/user-permission/index', 'fa-certificate', 4, NULL],
//[53, '路由管理', 5, '/admin/user-route/index', 'fa-cloud', 5, NULL],
[54, '规则管理', 5, '/admin/user-rule/index', 'fa-key', 6, NULL],
// [40, '地区管理', 3, '/area/index', 'fa-globe', 1, NULL],
//[43, '敏感词管理', 3, '/admin/ban-word/index', 'fa-exclamation-triangle', 2, NULL],
]);
//隐藏的子菜单[隐藏的子菜单不设置id字段,使用自增]//从10000开始
$this->batchInsert($this->tableName, ['id', 'name', 'parent', 'route', 'visible', 'sort'], [
[10000, '管理员查看', 22, '/admin/admin/view', 0, NULL],
]);
$this->batchInsert($this->tableName, ['name', 'parent', 'route', 'visible', 'sort'], [
['更新管理员', 22, '/admin/admin/update', 0, NULL], ['授权设置', 22, '/admin/assignment/view', 0, NULL],
['角色查看', 24, '/admin/role/view', 0, NULL], ['创建角色', 24, '/admin/role/create', 0, NULL], ['更新角色', 24, '/admin/role/update', 0, NULL],
['权限查看', 25, '/admin/permission/view', 0, NULL], ['创建权限', 25, '/admin/permission/create', 0, NULL], ['更新权限', 25, '/admin/permission/update', 0, NULL],
['路由查看', 26, '/admin/route/view', 0, NULL], ['创建路由', 26, '/admin/route/create', 0, NULL],
['规则查看', 27, '/admin/rule/view', 0, NULL], ['创建规则', 27, '/admin/rule/create', 0, NULL], ['更新规则', 27, '/admin/rule/update', 0, NULL],
['菜单查看', 28, '/admin/menu/view', 0, NULL], ['创建菜单', 28, '/admin/menu/create', 0, NULL], ['更新菜单', 28, '/admin/menu/update', 0, NULL],
//['创建地区', 40, '/area/create', 0, NULL], ['更新地区', 40, '/area/update', 0, NULL],
//['敏感词查看', 43, '/admin/ban-word/view', 0, NULL], ['创建敏感词', 43, '/admin/ban-word/create', 0, NULL], ['更新敏感词', 43, '/admin/ban-word/update', 0, NULL],
]);
$this->batchInsert($this->tableName, ['name', 'parent', 'route', 'visible', 'sort'], [
['用户设置', 50, '/admin/user/settings', 0, NULL],
['新建用户', 50, '/admin/user/create', 0, NULL],
['用户查看', 50, '/admin/user/view', 0, NULL],
['用户修改', 50, '/admin/user/update-profile', 0, NULL],
['账户详情', 50, '/admin/user/update', 0, NULL],
['权限分配', 50, '/admin/user-assignment/view', 0, NULL],
//['授权设置', 52, '/admin/user-assignment/view', 0, NULL],
['角色查看', 51, '/admin/user-role/view', 0, NULL], ['创建角色', 51, '/admin/user-role/create', 0, NULL], ['更新角色', 51, '/admin/user-role/update', 0, NULL],
['权限查看', 52, '/admin/user-permission/view', 0, NULL], ['创建权限', 52, '/admin/user-permission/create', 0, NULL], ['更新权限', 52, '/admin/user-permission/update', 0, NULL],
//['路由查看', 53, '/admin/user-route/view', 0, NULL], ['创建路由', 53, '/admin/user-route/create', 0, NULL],
['规则查看', 54, '/admin/user-rule/view', 0, NULL], ['创建规则', 54, '/admin/user-rule/create', 0, NULL], ['更新规则', 54, '/admin/user-rule/update', 0, NULL],
]);
$this->insert($this->tableName, ['name' => '附件管理', 'parent' => 8, 'route' => '/admin/attachment/index', 'icon' => 'fa-cog', 'sort' => NULL, 'data' => NULL]);
//OAuth2
$this->insert($this->tableName, ['name' => 'App管理', 'parent' => 8, 'route' => '/admin/oauth2/index', 'icon' => 'fa fa-apple', 'sort' => NULL, 'data' => NULL]);
$id = (new Query())->select(['id'])->from($this->tableName)->where(['name' => 'App管理', 'parent' => 8])->scalar($this->getDb());
$this->batchInsert($this->tableName, ['name', 'parent', 'route', 'visible', 'sort'], [
['App查看', $id, '/admin/oauth2/view', 0, NULL],
]);
}
|
[
"public",
"function",
"safeUp",
"(",
")",
"{",
"$",
"tableOptions",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"driverName",
"===",
"'mysql'",
")",
"{",
"// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci",
"$",
"tableOptions",
"=",
"'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB'",
";",
"}",
"$",
"this",
"->",
"createTable",
"(",
"$",
"this",
"->",
"tableName",
",",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"primaryKey",
"(",
")",
"->",
"unsigned",
"(",
")",
"->",
"comment",
"(",
"'ID'",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"string",
"(",
"128",
")",
"->",
"notNull",
"(",
")",
"->",
"comment",
"(",
"'Name'",
")",
",",
"'parent'",
"=>",
"$",
"this",
"->",
"integer",
"(",
")",
"->",
"unsigned",
"(",
")",
"->",
"comment",
"(",
"'Parent'",
")",
",",
"'route'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"comment",
"(",
"'Route'",
")",
",",
"'icon'",
"=>",
"$",
"this",
"->",
"string",
"(",
"30",
")",
"->",
"comment",
"(",
"'Icon'",
")",
",",
"'visible'",
"=>",
"$",
"this",
"->",
"boolean",
"(",
")",
"->",
"defaultValue",
"(",
"true",
")",
"->",
"comment",
"(",
"'Visible'",
")",
",",
"'sort'",
"=>",
"$",
"this",
"->",
"smallInteger",
"(",
")",
"->",
"defaultValue",
"(",
"99",
")",
"->",
"comment",
"(",
"'Sort'",
")",
",",
"'data'",
"=>",
"$",
"this",
"->",
"text",
"(",
")",
"->",
"comment",
"(",
"'Data'",
")",
"]",
",",
"$",
"tableOptions",
")",
";",
"$",
"this",
"->",
"addForeignKey",
"(",
"'admin_menu_fk_1'",
",",
"$",
"this",
"->",
"tableName",
",",
"'parent'",
",",
"$",
"this",
"->",
"tableName",
",",
"'id'",
",",
"'SET NULL'",
",",
"'CASCADE'",
")",
";",
"$",
"this",
"->",
"batchInsert",
"(",
"$",
"this",
"->",
"tableName",
",",
"[",
"'id'",
",",
"'name'",
",",
"'parent'",
",",
"'route'",
",",
"'icon'",
",",
"'sort'",
",",
"'data'",
"]",
",",
"[",
"//一级主菜单",
"[",
"1",
",",
"'控制台', NULL",
",",
"'/si",
"t",
"/index', 'fa-",
"t",
"-large', 1, N",
"U",
"L",
"]",
"",
"",
"",
"[",
"2",
",",
"'核心设置', NULL, ",
"N",
"LL, ",
"'",
"a-co",
"g",
", 2, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"3",
",",
"'数据管理', NULL, ",
"N",
"LL, ",
"'",
"a-wr",
"e",
"ch', 3, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"4",
",",
"'运营中心', NULL, ",
"N",
"LL, ",
"'",
"a-ba",
"r",
"chart-o', 4, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"5",
",",
"'用户管理', NULL, ",
"N",
"LL, ",
"'",
"a-us",
"e",
"', 5, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"6",
",",
"'网站管理', NULL, ",
"N",
"LL, ",
"'",
"a-ba",
"r",
"', 6, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"7",
",",
"'财务管理', NULL, ",
"N",
"LL, ",
"'",
"a-cn",
"y",
", 7, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"8",
",",
"'模块管理', NULL, ",
"N",
"LL, ",
"'",
"a-th",
"'",
" 8, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"9",
",",
"'模板管理', NULL, ",
"N",
"LL, ",
"'",
"a-la",
"p",
"op', 9, NUL",
"L",
",",
"",
"",
"",
"",
"//核心设置子菜单",
"[",
"21",
",",
"'站点设置', 2, '/a",
"d",
"i",
"n",
"setting/setting', 'fa-ge",
"a",
"s', 1, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"22",
",",
"'管理员管理', 2, '/adm",
"i",
"/",
"a",
"min/index', 'fa-user",
"'",
" 2, NULL]",
",",
"",
"",
"",
"",
"",
"[",
"24",
",",
"'角色管理', 2, '/a",
"d",
"i",
"n",
"role/index', 'fa-gr",
"o",
"p', 3, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"25",
",",
"'权限管理', 2, '/a",
"d",
"i",
"n",
"permission/index', 'fa-ce",
"r",
"ificate', 4, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"26",
",",
"'路由管理', 2, '/a",
"d",
"i",
"n",
"route/index', 'fa-cl",
"o",
"d', 5, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"27",
",",
"'规则管理', 2, '/a",
"d",
"i",
"n",
"rule/index', 'fa-ke",
"y",
", 6, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"28",
",",
"'菜单管理', 2, '/a",
"d",
"i",
"n",
"menu/index', 'fa-wr",
"e",
"ch', 7, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"29",
",",
"'附件设置', 2, '/a",
"d",
"i",
"n",
"attachment/setting', 'fa-co",
"g",
", 8, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"30",
",",
"'执行计划', 2, '/a",
"d",
"i",
"n",
"task/index', 'fa-sp",
"i",
"ner', 8, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"50",
",",
"'用户管理', 5, '/a",
"d",
"i",
"n",
"user/index', 'fa-us",
"e",
"', 2, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"51",
",",
"'角色管理', 5, '/a",
"d",
"i",
"n",
"user-role/index', 'fa-gr",
"o",
"p', 3, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"52",
",",
"'权限管理', 5, '/a",
"d",
"i",
"n",
"user-permission/index', 'fa-ce",
"r",
"ificate', 4, NUL",
"L",
",",
"",
"",
"",
"",
"//[53, '路由管理', 5, '/admin/user-route/index', 'fa-cloud', 5, NULL],",
"[",
"54",
",",
"'规则管理', 5, '/a",
"d",
"i",
"n",
"user-rule/index', 'fa-ke",
"y",
", 6, NUL",
"L",
",",
"",
"",
"",
"",
"// [40, '地区管理', 3, '/area/index', 'fa-globe', 1, NULL],",
"//[43, '敏感词管理', 3, '/admin/ban-word/index', 'fa-exclamation-triangle', 2, NULL],",
"]",
")",
";",
"//隐藏的子菜单[隐藏的子菜单不设置id字段,使用自增]//从10000开始",
"$",
"this",
"->",
"batchInsert",
"(",
"$",
"this",
"->",
"tableName",
",",
"[",
"'id'",
",",
"'name'",
",",
"'parent'",
",",
"'route'",
",",
"'visible'",
",",
"'sort'",
"]",
",",
"[",
"[",
"10000",
",",
"'管理员查看', 22, '/ad",
"m",
"n/",
"a",
"min/view', 0, NULL]",
",",
"",
"",
"",
"",
"",
"]",
")",
";",
"$",
"this",
"->",
"batchInsert",
"(",
"$",
"this",
"->",
"tableName",
",",
"[",
"'name'",
",",
"'parent'",
",",
"'route'",
",",
"'visible'",
",",
"'sort'",
"]",
",",
"[",
"[",
"'更新管理员', 22, '/ad",
"m",
"n/",
"a",
"min/update', 0, NULL]",
",",
"[",
"'",
"权设置'",
",",
" ",
"2",
", '/admin/assi",
"g",
"me",
"n",
"/view', 0, NULL],",
"",
"",
"",
"",
"",
"",
"[",
"'角色查看', 24, '/",
"a",
"mi",
"n",
"role/view', 0, NUL",
"L",
",",
" ",
"'创建角",
"色",
"'",
" ",
"24, '/admin/ro",
"l",
"/c",
"r",
"ate', 0, NULL], ['更新",
"角",
"'",
",",
"24, ",
"'",
"/",
"d",
"min/role/updat",
"e",
", ",
"0",
" NULL],",
"",
"",
"",
"",
"",
"",
"[",
"'权限查看', 25, '/",
"a",
"mi",
"n",
"permission/view', 0, NUL",
"L",
",",
" ",
"'创建权",
"限",
"'",
" ",
"25, '/admin/pe",
"r",
"is",
"s",
"on/create', 0, NULL], ['更新",
"权",
"'",
",",
"25, ",
"'",
"/",
"d",
"min/permission",
"/",
"pd",
"a",
"e', 0, NULL],",
"",
"",
"",
"",
"",
"",
"[",
"'路由查看', 26, '/",
"a",
"mi",
"n",
"route/view', 0, NUL",
"L",
",",
" ",
"'创建路",
"由",
"'",
" ",
"26, '/admin/ro",
"u",
"e/",
"c",
"eate', 0, NULL],",
"",
"",
"",
"",
"",
"",
"[",
"'规则查看', 27, '/",
"a",
"mi",
"n",
"rule/view', 0, NUL",
"L",
",",
" ",
"'创建规",
"则",
"'",
" ",
"27, '/admin/ru",
"l",
"/c",
"r",
"ate', 0, NULL], ['更新",
"规",
"'",
",",
"27, ",
"'",
"/",
"d",
"min/rule/updat",
"e",
", ",
"0",
" NULL],",
"",
"",
"",
"",
"",
"",
"[",
"'菜单查看', 28, '/",
"a",
"mi",
"n",
"menu/view', 0, NUL",
"L",
",",
" ",
"'创建菜",
"单",
"'",
" ",
"28, '/admin/me",
"n",
"/c",
"r",
"ate', 0, NULL], ['更新",
"菜",
"'",
",",
"28, ",
"'",
"/",
"d",
"min/menu/updat",
"e",
", ",
"0",
" NULL],",
"",
"",
"",
"",
"",
"",
"//['创建地区', 40, '/area/create', 0, NULL], ['更新地区', 40, '/area/update', 0, NULL],",
"//['敏感词查看', 43, '/admin/ban-word/view', 0, NULL], ['创建敏感词', 43, '/admin/ban-word/create', 0, NULL], ['更新敏感词', 43, '/admin/ban-word/update', 0, NULL],",
"]",
")",
";",
"$",
"this",
"->",
"batchInsert",
"(",
"$",
"this",
"->",
"tableName",
",",
"[",
"'name'",
",",
"'parent'",
",",
"'route'",
",",
"'visible'",
",",
"'sort'",
"]",
",",
"[",
"[",
"'用户设置', 50, '/",
"a",
"mi",
"n",
"user/settings', 0, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"'新建用户', 50, '/",
"a",
"mi",
"n",
"user/create', 0, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"'用户查看', 50, '/",
"a",
"mi",
"n",
"user/view', 0, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"'用户修改', 50, '/",
"a",
"mi",
"n",
"user/update-profile', 0, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"'账户详情', 50, '/",
"a",
"mi",
"n",
"user/update', 0, NUL",
"L",
",",
"",
"",
"",
"",
"[",
"'权限分配', 50, '/",
"a",
"mi",
"n",
"user-assignment/view', 0, NUL",
"L",
",",
"",
"",
"",
"",
"//['授权设置', 52, '/admin/user-assignment/view', 0, NULL],",
"[",
"'角色查看', 51, '/",
"a",
"mi",
"n",
"user-role/view', 0, NUL",
"L",
",",
" ",
"'创建角",
"色",
"'",
" ",
"51, '/admin/us",
"e",
"-r",
"o",
"e/create', 0, NULL], ['更新",
"角",
"'",
",",
"51, ",
"'",
"/",
"d",
"min/user-role/",
"u",
"da",
"t",
"', 0, NULL],",
"",
"",
"",
"",
"",
"",
"[",
"'权限查看', 52, '/",
"a",
"mi",
"n",
"user-permission/view', 0, NUL",
"L",
",",
" ",
"'创建权",
"限",
"'",
" ",
"52, '/admin/us",
"e",
"-p",
"e",
"mission/create', 0, NULL], ['更新",
"权",
"'",
",",
"52, ",
"'",
"/",
"d",
"min/user-permi",
"s",
"io",
"n",
"update', 0, NULL],",
"",
"",
"",
"",
"",
"",
"//['路由查看', 53, '/admin/user-route/view', 0, NULL], ['创建路由', 53, '/admin/user-route/create', 0, NULL],",
"[",
"'规则查看', 54, '/",
"a",
"mi",
"n",
"user-rule/view', 0, NUL",
"L",
",",
" ",
"'创建规",
"则",
"'",
" ",
"54, '/admin/us",
"e",
"-r",
"u",
"e/create', 0, NULL], ['更新",
"规",
"'",
",",
"54, ",
"'",
"/",
"d",
"min/user-rule/",
"u",
"da",
"t",
"', 0, NULL],",
"",
"",
"",
"",
"",
"",
"]",
")",
";",
"$",
"this",
"->",
"insert",
"(",
"$",
"this",
"->",
"tableName",
",",
"[",
"'name'",
"=>",
"'附件管理', 'paren",
"t",
" => 8, '",
"ou",
"e",
"'",
"=> '/ad",
"in",
"attachment/index', 'icon'",
" ",
"> 'fa-",
"og",
", 'sort'",
" ",
"> NULL",
" '",
"ata'",
" ",
"> NULL",
");",
"",
"",
"",
"",
"//OAuth2",
"$",
"this",
"->",
"insert",
"(",
"$",
"this",
"->",
"tableName",
",",
"[",
"'name'",
"=>",
"'App管理', 'p",
"a",
"ent' => ",
", ",
"r",
"o",
"te' => ",
"/a",
"min/oauth2/index', 'i",
"c",
"n' => ",
"fa",
"fa-apple', 's",
"o",
"t' => ",
"UL",
", 'd",
"a",
"a' => ",
"UL",
"]);",
"",
"",
"",
"$",
"id",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'id'",
"]",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"tableName",
")",
"->",
"where",
"(",
"[",
"'name'",
"=>",
"'App管理', 'p",
"a",
"ent' => ",
"])",
">",
"s",
"c",
"al",
"ar($th",
"i",
"s",
"->ge",
"tD",
"b());",
"",
"",
"",
"",
"$",
"this",
"->",
"batchInsert",
"(",
"$",
"this",
"->",
"tableName",
",",
"[",
"'name'",
",",
"'parent'",
",",
"'route'",
",",
"'visible'",
",",
"'sort'",
"]",
",",
"[",
"[",
"'App查看', $i",
"d",
" ",
"'/",
"a",
"min/oauth2/view', 0,",
" ",
"U",
"L",
"],",
"",
"",
"]",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/migrations/m180324_103503_create_admin_menu_table.php#L19-L113
|
PeekAndPoke/psi
|
src/Operation/Intermediate/EmptyIntermediateOp.php
|
EmptyIntermediateOp.apply
|
public function apply($input, $index, IntermediateContext $context)
{
$context->outUseItem = true;
$context->outCanContinue = true;
// return the input unmodified
return $input;
}
|
php
|
public function apply($input, $index, IntermediateContext $context)
{
$context->outUseItem = true;
$context->outCanContinue = true;
// return the input unmodified
return $input;
}
|
[
"public",
"function",
"apply",
"(",
"$",
"input",
",",
"$",
"index",
",",
"IntermediateContext",
"$",
"context",
")",
"{",
"$",
"context",
"->",
"outUseItem",
"=",
"true",
";",
"$",
"context",
"->",
"outCanContinue",
"=",
"true",
";",
"// return the input unmodified",
"return",
"$",
"input",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/Operation/Intermediate/EmptyIntermediateOp.php#L23-L30
|
devemio/php-readable-timer
|
src/Timer.php
|
Timer.stop
|
public function stop()
{
$time = microtime(true);
$this->time += $time - $this->start;
$this->start = $time;
return $this;
}
|
php
|
public function stop()
{
$time = microtime(true);
$this->time += $time - $this->start;
$this->start = $time;
return $this;
}
|
[
"public",
"function",
"stop",
"(",
")",
"{",
"$",
"time",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"this",
"->",
"time",
"+=",
"$",
"time",
"-",
"$",
"this",
"->",
"start",
";",
"$",
"this",
"->",
"start",
"=",
"$",
"time",
";",
"return",
"$",
"this",
";",
"}"
] |
Stop the timer.
@return $this
|
[
"Stop",
"the",
"timer",
"."
] |
train
|
https://github.com/devemio/php-readable-timer/blob/50916b630eda07999dc6676528afe59fb2105615/src/Timer.php#L60-L66
|
devemio/php-readable-timer
|
src/Timer.php
|
Timer.time
|
public function time()
{
$format = $this->format;
$format = $this->replace('u', 6, $format);
$format = $this->replace('ms', 3, $format);
return gmdate($format, $this->time);
}
|
php
|
public function time()
{
$format = $this->format;
$format = $this->replace('u', 6, $format);
$format = $this->replace('ms', 3, $format);
return gmdate($format, $this->time);
}
|
[
"public",
"function",
"time",
"(",
")",
"{",
"$",
"format",
"=",
"$",
"this",
"->",
"format",
";",
"$",
"format",
"=",
"$",
"this",
"->",
"replace",
"(",
"'u'",
",",
"6",
",",
"$",
"format",
")",
";",
"$",
"format",
"=",
"$",
"this",
"->",
"replace",
"(",
"'ms'",
",",
"3",
",",
"$",
"format",
")",
";",
"return",
"gmdate",
"(",
"$",
"format",
",",
"$",
"this",
"->",
"time",
")",
";",
"}"
] |
Return measured time.
@return string
|
[
"Return",
"measured",
"time",
"."
] |
train
|
https://github.com/devemio/php-readable-timer/blob/50916b630eda07999dc6676528afe59fb2105615/src/Timer.php#L85-L94
|
devemio/php-readable-timer
|
src/Timer.php
|
Timer.replace
|
private function replace($pattern, $precision, $format)
{
$time = round($this->time, $precision);
$value = substr(number_format($time - floor($time), $precision), 2);
return str_replace($pattern, $value, $format);
}
|
php
|
private function replace($pattern, $precision, $format)
{
$time = round($this->time, $precision);
$value = substr(number_format($time - floor($time), $precision), 2);
return str_replace($pattern, $value, $format);
}
|
[
"private",
"function",
"replace",
"(",
"$",
"pattern",
",",
"$",
"precision",
",",
"$",
"format",
")",
"{",
"$",
"time",
"=",
"round",
"(",
"$",
"this",
"->",
"time",
",",
"$",
"precision",
")",
";",
"$",
"value",
"=",
"substr",
"(",
"number_format",
"(",
"$",
"time",
"-",
"floor",
"(",
"$",
"time",
")",
",",
"$",
"precision",
")",
",",
"2",
")",
";",
"return",
"str_replace",
"(",
"$",
"pattern",
",",
"$",
"value",
",",
"$",
"format",
")",
";",
"}"
] |
Replace the date format with calculated values.
@param string $pattern
@param int $precision
@param string $format
@return string
|
[
"Replace",
"the",
"date",
"format",
"with",
"calculated",
"values",
"."
] |
train
|
https://github.com/devemio/php-readable-timer/blob/50916b630eda07999dc6676528afe59fb2105615/src/Timer.php#L104-L109
|
anime-db/app-bundle
|
src/Event/Listener/Request.php
|
Request.getLocale
|
public function getLocale(HttpRequest $request)
{
if ($this->locale) {
return $this->locale;
}
// get locale from language list
$constraint = new Locale();
foreach ($request->getLanguages() as $language) {
if (!$this->validator->validate($language, $constraint)->has(0)) {
return $language;
}
}
// get default locale
return $request->getLocale();
}
|
php
|
public function getLocale(HttpRequest $request)
{
if ($this->locale) {
return $this->locale;
}
// get locale from language list
$constraint = new Locale();
foreach ($request->getLanguages() as $language) {
if (!$this->validator->validate($language, $constraint)->has(0)) {
return $language;
}
}
// get default locale
return $request->getLocale();
}
|
[
"public",
"function",
"getLocale",
"(",
"HttpRequest",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"locale",
")",
"{",
"return",
"$",
"this",
"->",
"locale",
";",
"}",
"// get locale from language list",
"$",
"constraint",
"=",
"new",
"Locale",
"(",
")",
";",
"foreach",
"(",
"$",
"request",
"->",
"getLanguages",
"(",
")",
"as",
"$",
"language",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"validator",
"->",
"validate",
"(",
"$",
"language",
",",
"$",
"constraint",
")",
"->",
"has",
"(",
"0",
")",
")",
"{",
"return",
"$",
"language",
";",
"}",
"}",
"// get default locale",
"return",
"$",
"request",
"->",
"getLocale",
"(",
")",
";",
"}"
] |
@param HttpRequest $request
@return string
|
[
"@param",
"HttpRequest",
"$request"
] |
train
|
https://github.com/anime-db/app-bundle/blob/ca3b342081719d41ba018792a75970cbb1f1fe22/src/Event/Listener/Request.php#L99-L115
|
lmammino/e-foundation
|
src/Attribute/Model/AttributeSubjectTrait.php
|
AttributeSubjectTrait.setAttributesValues
|
public function setAttributesValues(Collection $attributesValues)
{
foreach ($attributesValues as $attributeValue) {
$this->addAttributeValue($attributeValue);
}
return $this;
}
|
php
|
public function setAttributesValues(Collection $attributesValues)
{
foreach ($attributesValues as $attributeValue) {
$this->addAttributeValue($attributeValue);
}
return $this;
}
|
[
"public",
"function",
"setAttributesValues",
"(",
"Collection",
"$",
"attributesValues",
")",
"{",
"foreach",
"(",
"$",
"attributesValues",
"as",
"$",
"attributeValue",
")",
"{",
"$",
"this",
"->",
"addAttributeValue",
"(",
"$",
"attributeValue",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set the attribute values
@param Collection $attributesValues
@return $this
|
[
"Set",
"the",
"attribute",
"values"
] |
train
|
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Attribute/Model/AttributeSubjectTrait.php#L45-L52
|
lmammino/e-foundation
|
src/Attribute/Model/AttributeSubjectTrait.php
|
AttributeSubjectTrait.addAttributeValue
|
public function addAttributeValue(AttributeValueInterface $attributeValue)
{
if (!$this->attributeValues->contains($attributeValue)) {
$attributeValue->setSubject($this);
$this->attributeValues->add($attributeValue);
}
return $this;
}
|
php
|
public function addAttributeValue(AttributeValueInterface $attributeValue)
{
if (!$this->attributeValues->contains($attributeValue)) {
$attributeValue->setSubject($this);
$this->attributeValues->add($attributeValue);
}
return $this;
}
|
[
"public",
"function",
"addAttributeValue",
"(",
"AttributeValueInterface",
"$",
"attributeValue",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"attributeValues",
"->",
"contains",
"(",
"$",
"attributeValue",
")",
")",
"{",
"$",
"attributeValue",
"->",
"setSubject",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"attributeValues",
"->",
"add",
"(",
"$",
"attributeValue",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add an attribute value
@param AttributeValueInterface $attributeValue
@return $this
|
[
"Add",
"an",
"attribute",
"value"
] |
train
|
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Attribute/Model/AttributeSubjectTrait.php#L61-L69
|
lmammino/e-foundation
|
src/Attribute/Model/AttributeSubjectTrait.php
|
AttributeSubjectTrait.removeAttributeValue
|
public function removeAttributeValue(AttributeValueInterface $attributeValue)
{
if ($this->attributeValues->contains($attributeValue)) {
$attributeValue->setSubject(null);
$this->attributeValues->removeElement($attributeValue);
}
return $this;
}
|
php
|
public function removeAttributeValue(AttributeValueInterface $attributeValue)
{
if ($this->attributeValues->contains($attributeValue)) {
$attributeValue->setSubject(null);
$this->attributeValues->removeElement($attributeValue);
}
return $this;
}
|
[
"public",
"function",
"removeAttributeValue",
"(",
"AttributeValueInterface",
"$",
"attributeValue",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"attributeValues",
"->",
"contains",
"(",
"$",
"attributeValue",
")",
")",
"{",
"$",
"attributeValue",
"->",
"setSubject",
"(",
"null",
")",
";",
"$",
"this",
"->",
"attributeValues",
"->",
"removeElement",
"(",
"$",
"attributeValue",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Remove an attribute value
@param AttributeValueInterface $attributeValue
@return $this
|
[
"Remove",
"an",
"attribute",
"value"
] |
train
|
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Attribute/Model/AttributeSubjectTrait.php#L78-L86
|
lmammino/e-foundation
|
src/Attribute/Model/AttributeSubjectTrait.php
|
AttributeSubjectTrait.hasAttributeValueByName
|
public function hasAttributeValueByName($attributeValueName)
{
/** @var AttributeValueInterface $attributeValue */
foreach ($this->attributeValues as $attributeValue) {
if ($attributeValue->getAttributeName() == $attributeValueName) {
return true;
}
}
return false;
}
|
php
|
public function hasAttributeValueByName($attributeValueName)
{
/** @var AttributeValueInterface $attributeValue */
foreach ($this->attributeValues as $attributeValue) {
if ($attributeValue->getAttributeName() == $attributeValueName) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"hasAttributeValueByName",
"(",
"$",
"attributeValueName",
")",
"{",
"/** @var AttributeValueInterface $attributeValue */",
"foreach",
"(",
"$",
"this",
"->",
"attributeValues",
"as",
"$",
"attributeValue",
")",
"{",
"if",
"(",
"$",
"attributeValue",
"->",
"getAttributeName",
"(",
")",
"==",
"$",
"attributeValueName",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check if has an attribute value that matches a given name
@param string $attributeValueName
@return boolean
|
[
"Check",
"if",
"has",
"an",
"attribute",
"value",
"that",
"matches",
"a",
"given",
"name"
] |
train
|
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Attribute/Model/AttributeSubjectTrait.php#L107-L117
|
lmammino/e-foundation
|
src/Attribute/Model/AttributeSubjectTrait.php
|
AttributeSubjectTrait.getAttributeValueByName
|
public function getAttributeValueByName($attributeValueName)
{
/** @var AttributeValueInterface $attributeValue */
foreach ($this->attributeValues as $attributeValue) {
if ($attributeValue->getAttributeName() == $attributeValueName) {
return $attributeValue;
}
}
return null;
}
|
php
|
public function getAttributeValueByName($attributeValueName)
{
/** @var AttributeValueInterface $attributeValue */
foreach ($this->attributeValues as $attributeValue) {
if ($attributeValue->getAttributeName() == $attributeValueName) {
return $attributeValue;
}
}
return null;
}
|
[
"public",
"function",
"getAttributeValueByName",
"(",
"$",
"attributeValueName",
")",
"{",
"/** @var AttributeValueInterface $attributeValue */",
"foreach",
"(",
"$",
"this",
"->",
"attributeValues",
"as",
"$",
"attributeValue",
")",
"{",
"if",
"(",
"$",
"attributeValue",
"->",
"getAttributeName",
"(",
")",
"==",
"$",
"attributeValueName",
")",
"{",
"return",
"$",
"attributeValue",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Gets an attribute value if matches a given name or null instead
@param string $attributeValueName
@return AttributeValueInterface|null
|
[
"Gets",
"an",
"attribute",
"value",
"if",
"matches",
"a",
"given",
"name",
"or",
"null",
"instead"
] |
train
|
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Attribute/Model/AttributeSubjectTrait.php#L126-L136
|
ClanCats/Core
|
src/classes/CCView.php
|
CCView.cache_path
|
public static function cache_path( $view )
{
if ( strpos( $view, '::' ) !== false )
{
list( $package, $view ) = explode( '::', $view );
}
else
{
$package = 'app';
}
return \CCStorage::path( 'views/'.$package.'/'.$view.EXT );
}
|
php
|
public static function cache_path( $view )
{
if ( strpos( $view, '::' ) !== false )
{
list( $package, $view ) = explode( '::', $view );
}
else
{
$package = 'app';
}
return \CCStorage::path( 'views/'.$package.'/'.$view.EXT );
}
|
[
"public",
"static",
"function",
"cache_path",
"(",
"$",
"view",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"view",
",",
"'::'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"package",
",",
"$",
"view",
")",
"=",
"explode",
"(",
"'::'",
",",
"$",
"view",
")",
";",
"}",
"else",
"{",
"$",
"package",
"=",
"'app'",
";",
"}",
"return",
"\\",
"CCStorage",
"::",
"path",
"(",
"'views/'",
".",
"$",
"package",
".",
"'/'",
".",
"$",
"view",
".",
"EXT",
")",
";",
"}"
] |
Get the cache path of a view
@param string $view
@return string
|
[
"Get",
"the",
"cache",
"path",
"of",
"a",
"view"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCView.php#L72-L84
|
ClanCats/Core
|
src/classes/CCView.php
|
CCView.file
|
public function file( $file = null )
{
if ( !is_null( $file ) )
{
return $this->_file = $file;
}
return $this->_file;
}
|
php
|
public function file( $file = null )
{
if ( !is_null( $file ) )
{
return $this->_file = $file;
}
return $this->_file;
}
|
[
"public",
"function",
"file",
"(",
"$",
"file",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"file",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_file",
"=",
"$",
"file",
";",
"}",
"return",
"$",
"this",
"->",
"_file",
";",
"}"
] |
set or get the current file
@param string $file
@return string
|
[
"set",
"or",
"get",
"the",
"current",
"file"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCView.php#L126-L134
|
ClanCats/Core
|
src/classes/CCView.php
|
CCView.set
|
public function set( $key, $value, $param = null )
{
if ( $param === true )
{
$value = CCStr::htmlentities( $value );
}
return CCArr::set( $key, $value, $this->_data );
}
|
php
|
public function set( $key, $value, $param = null )
{
if ( $param === true )
{
$value = CCStr::htmlentities( $value );
}
return CCArr::set( $key, $value, $this->_data );
}
|
[
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"param",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"param",
"===",
"true",
")",
"{",
"$",
"value",
"=",
"CCStr",
"::",
"htmlentities",
"(",
"$",
"value",
")",
";",
"}",
"return",
"CCArr",
"::",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"this",
"->",
"_data",
")",
";",
"}"
] |
custom setter with encode ability
@param string $key
@param mixed $value
@param mixed $param
@return void
|
[
"custom",
"setter",
"with",
"encode",
"ability"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCView.php#L144-L152
|
ClanCats/Core
|
src/classes/CCView.php
|
CCView.capture
|
public function capture( $key, $callback )
{
return $this->set( $key, CCStr::capture( $callback, $this ) );
}
|
php
|
public function capture( $key, $callback )
{
return $this->set( $key, CCStr::capture( $callback, $this ) );
}
|
[
"public",
"function",
"capture",
"(",
"$",
"key",
",",
"$",
"callback",
")",
"{",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"CCStr",
"::",
"capture",
"(",
"$",
"callback",
",",
"$",
"this",
")",
")",
";",
"}"
] |
just like set but it can
captures all output in a closure and set that.
@param string $key
@param callback $callback
@return void
|
[
"just",
"like",
"set",
"but",
"it",
"can",
"captures",
"all",
"output",
"in",
"a",
"closure",
"and",
"set",
"that",
"."
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCView.php#L162-L165
|
ClanCats/Core
|
src/classes/CCView.php
|
CCView.capture_append
|
public function capture_append( $key, $callback )
{
return $this->set( $key, $this->get( $key, '' ).CCStr::capture( $callback, $this ) );
}
|
php
|
public function capture_append( $key, $callback )
{
return $this->set( $key, $this->get( $key, '' ).CCStr::capture( $callback, $this ) );
}
|
[
"public",
"function",
"capture_append",
"(",
"$",
"key",
",",
"$",
"callback",
")",
"{",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
",",
"''",
")",
".",
"CCStr",
"::",
"capture",
"(",
"$",
"callback",
",",
"$",
"this",
")",
")",
";",
"}"
] |
just like capture but it appends
@param string $key
@param callback $callback
@return void
|
[
"just",
"like",
"capture",
"but",
"it",
"appends"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCView.php#L174-L177
|
ClanCats/Core
|
src/classes/CCView.php
|
CCView.view_path
|
protected function view_path( $view )
{
if ( isset( static::$_view_paths[$view] ) )
{
return static::$_view_paths[$view];
}
// view is empty?
if ( is_null( $view ) )
{
throw new CCException( "CCView - cannot render view without a view file." );
}
// generate the views path
$path = CCPath::get( $view, CCDIR_VIEW, EXT );
if ( !file_exists( $path ) )
{
throw new CCException( "CCView - could not find view: ".$view." at: {$path}." );
}
// does the view implement a view builder?
if ( strpos( $view, '.' ) !== false )
{
$cache = static::cache_path( $view );
// does the cache not exits or is out of date
if ( !file_exists( $cache ) || filemtime( $cache ) < filemtime( $path ) )
{
list( $view_name, $builder ) = explode( '.', $view );
$this->build_cache( $cache, $builder, $path );
}
$path = $cache;
}
return static::$_view_paths[$view] = $path;
}
|
php
|
protected function view_path( $view )
{
if ( isset( static::$_view_paths[$view] ) )
{
return static::$_view_paths[$view];
}
// view is empty?
if ( is_null( $view ) )
{
throw new CCException( "CCView - cannot render view without a view file." );
}
// generate the views path
$path = CCPath::get( $view, CCDIR_VIEW, EXT );
if ( !file_exists( $path ) )
{
throw new CCException( "CCView - could not find view: ".$view." at: {$path}." );
}
// does the view implement a view builder?
if ( strpos( $view, '.' ) !== false )
{
$cache = static::cache_path( $view );
// does the cache not exits or is out of date
if ( !file_exists( $cache ) || filemtime( $cache ) < filemtime( $path ) )
{
list( $view_name, $builder ) = explode( '.', $view );
$this->build_cache( $cache, $builder, $path );
}
$path = $cache;
}
return static::$_view_paths[$view] = $path;
}
|
[
"protected",
"function",
"view_path",
"(",
"$",
"view",
")",
"{",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"_view_paths",
"[",
"$",
"view",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"_view_paths",
"[",
"$",
"view",
"]",
";",
"}",
"// view is empty?",
"if",
"(",
"is_null",
"(",
"$",
"view",
")",
")",
"{",
"throw",
"new",
"CCException",
"(",
"\"CCView - cannot render view without a view file.\"",
")",
";",
"}",
"// generate the views path",
"$",
"path",
"=",
"CCPath",
"::",
"get",
"(",
"$",
"view",
",",
"CCDIR_VIEW",
",",
"EXT",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"CCException",
"(",
"\"CCView - could not find view: \"",
".",
"$",
"view",
".",
"\" at: {$path}.\"",
")",
";",
"}",
"// does the view implement a view builder?",
"if",
"(",
"strpos",
"(",
"$",
"view",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"cache",
"=",
"static",
"::",
"cache_path",
"(",
"$",
"view",
")",
";",
"// does the cache not exits or is out of date",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"cache",
")",
"||",
"filemtime",
"(",
"$",
"cache",
")",
"<",
"filemtime",
"(",
"$",
"path",
")",
")",
"{",
"list",
"(",
"$",
"view_name",
",",
"$",
"builder",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"view",
")",
";",
"$",
"this",
"->",
"build_cache",
"(",
"$",
"cache",
",",
"$",
"builder",
",",
"$",
"path",
")",
";",
"}",
"$",
"path",
"=",
"$",
"cache",
";",
"}",
"return",
"static",
"::",
"$",
"_view_paths",
"[",
"$",
"view",
"]",
"=",
"$",
"path",
";",
"}"
] |
Get the path to real view file
This function will also build the cache view file if needed.
@param string $path
@return string
|
[
"Get",
"the",
"path",
"to",
"real",
"view",
"file"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCView.php#L198-L235
|
ClanCats/Core
|
src/classes/CCView.php
|
CCView.build_cache
|
protected function build_cache( $path, $builder, $view_path )
{
CCFile::write( $path, CCView_Builder::compile( $builder, $view_path ) );
}
|
php
|
protected function build_cache( $path, $builder, $view_path )
{
CCFile::write( $path, CCView_Builder::compile( $builder, $view_path ) );
}
|
[
"protected",
"function",
"build_cache",
"(",
"$",
"path",
",",
"$",
"builder",
",",
"$",
"view_path",
")",
"{",
"CCFile",
"::",
"write",
"(",
"$",
"path",
",",
"CCView_Builder",
"::",
"compile",
"(",
"$",
"builder",
",",
"$",
"view_path",
")",
")",
";",
"}"
] |
Build a view cache file
@param string $path
@param string $builder
@param string
@return void
|
[
"Build",
"a",
"view",
"cache",
"file"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCView.php#L246-L249
|
ClanCats/Core
|
src/classes/CCView.php
|
CCView.render
|
public function render( $file = null )
{
if ( !is_null( $file ) )
{
$this->file( $file );
}
$path = $this->view_path( $this->file() );
// extract the view data
extract( $this->_data );
// extract globals if they exists
if ( !empty( static::$_globals ) )
{
extract( static::$_globals, EXTR_PREFIX_SAME, 'global' );
}
ob_start();
require( $path );
return ob_get_clean();
}
|
php
|
public function render( $file = null )
{
if ( !is_null( $file ) )
{
$this->file( $file );
}
$path = $this->view_path( $this->file() );
// extract the view data
extract( $this->_data );
// extract globals if they exists
if ( !empty( static::$_globals ) )
{
extract( static::$_globals, EXTR_PREFIX_SAME, 'global' );
}
ob_start();
require( $path );
return ob_get_clean();
}
|
[
"public",
"function",
"render",
"(",
"$",
"file",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"file",
"(",
"$",
"file",
")",
";",
"}",
"$",
"path",
"=",
"$",
"this",
"->",
"view_path",
"(",
"$",
"this",
"->",
"file",
"(",
")",
")",
";",
"// extract the view data",
"extract",
"(",
"$",
"this",
"->",
"_data",
")",
";",
"// extract globals if they exists",
"if",
"(",
"!",
"empty",
"(",
"static",
"::",
"$",
"_globals",
")",
")",
"{",
"extract",
"(",
"static",
"::",
"$",
"_globals",
",",
"EXTR_PREFIX_SAME",
",",
"'global'",
")",
";",
"}",
"ob_start",
"(",
")",
";",
"require",
"(",
"$",
"path",
")",
";",
"return",
"ob_get_clean",
"(",
")",
";",
"}"
] |
Render the view and return the output.
@param string $file
@return string
|
[
"Render",
"the",
"view",
"and",
"return",
"the",
"output",
"."
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCView.php#L257-L280
|
boekkooi/tactician-amqp
|
src/ExchangeLocator/InMemoryLocator.php
|
InMemoryLocator.addExchanges
|
protected function addExchanges(array $commandClassToHandlerMap)
{
foreach ($commandClassToHandlerMap as $messageClass => $handler) {
$this->addExchange($handler, $messageClass);
}
}
|
php
|
protected function addExchanges(array $commandClassToHandlerMap)
{
foreach ($commandClassToHandlerMap as $messageClass => $handler) {
$this->addExchange($handler, $messageClass);
}
}
|
[
"protected",
"function",
"addExchanges",
"(",
"array",
"$",
"commandClassToHandlerMap",
")",
"{",
"foreach",
"(",
"$",
"commandClassToHandlerMap",
"as",
"$",
"messageClass",
"=>",
"$",
"handler",
")",
"{",
"$",
"this",
"->",
"addExchange",
"(",
"$",
"handler",
",",
"$",
"messageClass",
")",
";",
"}",
"}"
] |
Allows you to add multiple exchanges at once.
The map should be an array in the format of:
[
AddTaskCommand::class => $someAMQPExchangeInstance,
CompleteTaskCommand::class => $someAMQPExchangeInstance,
]
@param array $commandClassToHandlerMap
|
[
"Allows",
"you",
"to",
"add",
"multiple",
"exchanges",
"at",
"once",
"."
] |
train
|
https://github.com/boekkooi/tactician-amqp/blob/55cbb8b9e20aab7891e6a6090b248377c599360e/src/ExchangeLocator/InMemoryLocator.php#L44-L49
|
boekkooi/tactician-amqp
|
src/ExchangeLocator/InMemoryLocator.php
|
InMemoryLocator.getExchangeForMessage
|
public function getExchangeForMessage(Message $message)
{
$class = get_class($message);
if (!isset($this->exchanges[$class])) {
throw MissingExchangeException::forMessage($message);
}
return $this->exchanges[$class];
}
|
php
|
public function getExchangeForMessage(Message $message)
{
$class = get_class($message);
if (!isset($this->exchanges[$class])) {
throw MissingExchangeException::forMessage($message);
}
return $this->exchanges[$class];
}
|
[
"public",
"function",
"getExchangeForMessage",
"(",
"Message",
"$",
"message",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"message",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"exchanges",
"[",
"$",
"class",
"]",
")",
")",
"{",
"throw",
"MissingExchangeException",
"::",
"forMessage",
"(",
"$",
"message",
")",
";",
"}",
"return",
"$",
"this",
"->",
"exchanges",
"[",
"$",
"class",
"]",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/boekkooi/tactician-amqp/blob/55cbb8b9e20aab7891e6a6090b248377c599360e/src/ExchangeLocator/InMemoryLocator.php#L54-L63
|
lmammino/e-foundation
|
src/Price/Model/AdjustableTrait.php
|
AdjustableTrait.setAdjustments
|
public function setAdjustments(Collection $adjustments)
{
$this->adjustmentsTotal = null;
$this->onAdjustmentsChange();
foreach ($adjustments as $adjustment) {
$this->addAdjustment($adjustment);
}
return $this;
}
|
php
|
public function setAdjustments(Collection $adjustments)
{
$this->adjustmentsTotal = null;
$this->onAdjustmentsChange();
foreach ($adjustments as $adjustment) {
$this->addAdjustment($adjustment);
}
return $this;
}
|
[
"public",
"function",
"setAdjustments",
"(",
"Collection",
"$",
"adjustments",
")",
"{",
"$",
"this",
"->",
"adjustmentsTotal",
"=",
"null",
";",
"$",
"this",
"->",
"onAdjustmentsChange",
"(",
")",
";",
"foreach",
"(",
"$",
"adjustments",
"as",
"$",
"adjustment",
")",
"{",
"$",
"this",
"->",
"addAdjustment",
"(",
"$",
"adjustment",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set adjustments
@param Collection $adjustments
@return $this
|
[
"Set",
"adjustments"
] |
train
|
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Price/Model/AdjustableTrait.php#L50-L59
|
lmammino/e-foundation
|
src/Price/Model/AdjustableTrait.php
|
AdjustableTrait.addAdjustment
|
public function addAdjustment(AdjustmentInterface $adjustment)
{
if (!$this->hasAdjustment($adjustment)) {
$this->adjustmentsTotal = null;
$this->onAdjustmentsChange();
$adjustment->setAdjustable($this);
$this->adjustments->add($adjustment);
}
return $this;
}
|
php
|
public function addAdjustment(AdjustmentInterface $adjustment)
{
if (!$this->hasAdjustment($adjustment)) {
$this->adjustmentsTotal = null;
$this->onAdjustmentsChange();
$adjustment->setAdjustable($this);
$this->adjustments->add($adjustment);
}
return $this;
}
|
[
"public",
"function",
"addAdjustment",
"(",
"AdjustmentInterface",
"$",
"adjustment",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasAdjustment",
"(",
"$",
"adjustment",
")",
")",
"{",
"$",
"this",
"->",
"adjustmentsTotal",
"=",
"null",
";",
"$",
"this",
"->",
"onAdjustmentsChange",
"(",
")",
";",
"$",
"adjustment",
"->",
"setAdjustable",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"adjustments",
"->",
"add",
"(",
"$",
"adjustment",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add adjustment
@param AdjustmentInterface $adjustment
@return $this
|
[
"Add",
"adjustment"
] |
train
|
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Price/Model/AdjustableTrait.php#L68-L78
|
lmammino/e-foundation
|
src/Price/Model/AdjustableTrait.php
|
AdjustableTrait.removeAdjustment
|
public function removeAdjustment(AdjustmentInterface $adjustment)
{
if ($this->hasAdjustment($adjustment)) {
$this->adjustmentsTotal = null;
$adjustment->setAdjustable(null);
$this->adjustments->removeElement($adjustment);
}
return $this;
}
|
php
|
public function removeAdjustment(AdjustmentInterface $adjustment)
{
if ($this->hasAdjustment($adjustment)) {
$this->adjustmentsTotal = null;
$adjustment->setAdjustable(null);
$this->adjustments->removeElement($adjustment);
}
return $this;
}
|
[
"public",
"function",
"removeAdjustment",
"(",
"AdjustmentInterface",
"$",
"adjustment",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasAdjustment",
"(",
"$",
"adjustment",
")",
")",
"{",
"$",
"this",
"->",
"adjustmentsTotal",
"=",
"null",
";",
"$",
"adjustment",
"->",
"setAdjustable",
"(",
"null",
")",
";",
"$",
"this",
"->",
"adjustments",
"->",
"removeElement",
"(",
"$",
"adjustment",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Removes a given adjustment
@param AdjustmentInterface $adjustment
@return $this
|
[
"Removes",
"a",
"given",
"adjustment"
] |
train
|
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Price/Model/AdjustableTrait.php#L99-L108
|
lmammino/e-foundation
|
src/Price/Model/AdjustableTrait.php
|
AdjustableTrait.removeAdjustmentByLabel
|
public function removeAdjustmentByLabel($adjustmentLabel)
{
/** @var AdjustmentInterface $adjustment */
foreach ($this->adjustments as $adjustment) {
if ($adjustmentLabel == $adjustment->getLabel()) {
$this->removeAdjustment($adjustment);
return $this;
}
}
return $this;
}
|
php
|
public function removeAdjustmentByLabel($adjustmentLabel)
{
/** @var AdjustmentInterface $adjustment */
foreach ($this->adjustments as $adjustment) {
if ($adjustmentLabel == $adjustment->getLabel()) {
$this->removeAdjustment($adjustment);
return $this;
}
}
return $this;
}
|
[
"public",
"function",
"removeAdjustmentByLabel",
"(",
"$",
"adjustmentLabel",
")",
"{",
"/** @var AdjustmentInterface $adjustment */",
"foreach",
"(",
"$",
"this",
"->",
"adjustments",
"as",
"$",
"adjustment",
")",
"{",
"if",
"(",
"$",
"adjustmentLabel",
"==",
"$",
"adjustment",
"->",
"getLabel",
"(",
")",
")",
"{",
"$",
"this",
"->",
"removeAdjustment",
"(",
"$",
"adjustment",
")",
";",
"return",
"$",
"this",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Removes an adjustment by label
@param string $adjustmentLabel
@return $this
|
[
"Removes",
"an",
"adjustment",
"by",
"label"
] |
train
|
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Price/Model/AdjustableTrait.php#L116-L127
|
lmammino/e-foundation
|
src/Price/Model/AdjustableTrait.php
|
AdjustableTrait.calculateAdjustmentsTotal
|
public function calculateAdjustmentsTotal()
{
$this->adjustmentsTotal = 0;
foreach ($this->adjustments as $adjustment) {
if (!$adjustment->isNeutral()) {
$this->adjustmentsTotal += $adjustment->getAmount();
}
}
return $this;
}
|
php
|
public function calculateAdjustmentsTotal()
{
$this->adjustmentsTotal = 0;
foreach ($this->adjustments as $adjustment) {
if (!$adjustment->isNeutral()) {
$this->adjustmentsTotal += $adjustment->getAmount();
}
}
return $this;
}
|
[
"public",
"function",
"calculateAdjustmentsTotal",
"(",
")",
"{",
"$",
"this",
"->",
"adjustmentsTotal",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"adjustments",
"as",
"$",
"adjustment",
")",
"{",
"if",
"(",
"!",
"$",
"adjustment",
"->",
"isNeutral",
"(",
")",
")",
"{",
"$",
"this",
"->",
"adjustmentsTotal",
"+=",
"$",
"adjustment",
"->",
"getAmount",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Recalculates the adjustment amount
@return $this
|
[
"Recalculates",
"the",
"adjustment",
"amount"
] |
train
|
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Price/Model/AdjustableTrait.php#L158-L169
|
askupasoftware/amarkal
|
Assets/Stylesheet.php
|
Stylesheet.register
|
public function register()
{
wp_register_style(
$this->handle,
$this->url,
$this->dependencies,
$this->version,
$this->media
);
$this->is_registered = true;
}
|
php
|
public function register()
{
wp_register_style(
$this->handle,
$this->url,
$this->dependencies,
$this->version,
$this->media
);
$this->is_registered = true;
}
|
[
"public",
"function",
"register",
"(",
")",
"{",
"wp_register_style",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"dependencies",
",",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"media",
")",
";",
"$",
"this",
"->",
"is_registered",
"=",
"true",
";",
"}"
] |
Register the stylesheet.
|
[
"Register",
"the",
"stylesheet",
"."
] |
train
|
https://github.com/askupasoftware/amarkal/blob/fe8283e2d6847ef697abec832da7ee741a85058c/Assets/Stylesheet.php#L31-L41
|
PeekAndPoke/psi
|
src/Operation/Terminal/GetFirstOperation.php
|
GetFirstOperation.apply
|
public function apply(\Iterator $set)
{
$set->rewind();
return $set->valid() ? $set->current() : $this->default;
}
|
php
|
public function apply(\Iterator $set)
{
$set->rewind();
return $set->valid() ? $set->current() : $this->default;
}
|
[
"public",
"function",
"apply",
"(",
"\\",
"Iterator",
"$",
"set",
")",
"{",
"$",
"set",
"->",
"rewind",
"(",
")",
";",
"return",
"$",
"set",
"->",
"valid",
"(",
")",
"?",
"$",
"set",
"->",
"current",
"(",
")",
":",
"$",
"this",
"->",
"default",
";",
"}"
] |
@param \Iterator $set
@return mixed
|
[
"@param",
"\\",
"Iterator",
"$set"
] |
train
|
https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/Operation/Terminal/GetFirstOperation.php#L35-L40
|
amostajo/wordpress-plugin-core
|
src/psr4/Plugin.php
|
Plugin.set_addons
|
protected function set_addons()
{
if ( $this->config->get( 'addons' ) ) {
foreach ( $this->config->get( 'addons' ) as $addon ) {
$this->addons[] = new $addon( $this );
}
}
}
|
php
|
protected function set_addons()
{
if ( $this->config->get( 'addons' ) ) {
foreach ( $this->config->get( 'addons' ) as $addon ) {
$this->addons[] = new $addon( $this );
}
}
}
|
[
"protected",
"function",
"set_addons",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'addons'",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'addons'",
")",
"as",
"$",
"addon",
")",
"{",
"$",
"this",
"->",
"addons",
"[",
"]",
"=",
"new",
"$",
"addon",
"(",
"$",
"this",
")",
";",
"}",
"}",
"}"
] |
Sets plugin addons.
@since 1.2
@return void
|
[
"Sets",
"plugin",
"addons",
".",
"@since",
"1",
".",
"2"
] |
train
|
https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Plugin.php#L181-L188
|
amostajo/wordpress-plugin-core
|
src/psr4/Plugin.php
|
Plugin.autoload_init
|
public function autoload_init()
{
$this->init();
// Addons
for ( $i = count( $this->addons ) - 1; $i >= 0; --$i ) {
$this->addons[$i]->init();
}
}
|
php
|
public function autoload_init()
{
$this->init();
// Addons
for ( $i = count( $this->addons ) - 1; $i >= 0; --$i ) {
$this->addons[$i]->init();
}
}
|
[
"public",
"function",
"autoload_init",
"(",
")",
"{",
"$",
"this",
"->",
"init",
"(",
")",
";",
"// Addons",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"this",
"->",
"addons",
")",
"-",
"1",
";",
"$",
"i",
">=",
"0",
";",
"--",
"$",
"i",
")",
"{",
"$",
"this",
"->",
"addons",
"[",
"$",
"i",
"]",
"->",
"init",
"(",
")",
";",
"}",
"}"
] |
Called by autoload to init class.
@since 1.2
@return void
|
[
"Called",
"by",
"autoload",
"to",
"init",
"class",
"."
] |
train
|
https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Plugin.php#L209-L216
|
amostajo/wordpress-plugin-core
|
src/psr4/Plugin.php
|
Plugin.autoload_on_admin
|
public function autoload_on_admin()
{
$this->on_admin();
// Addons
for ( $i = count( $this->addons ) - 1; $i >= 0; --$i ) {
$this->addons[$i]->on_admin();
}
}
|
php
|
public function autoload_on_admin()
{
$this->on_admin();
// Addons
for ( $i = count( $this->addons ) - 1; $i >= 0; --$i ) {
$this->addons[$i]->on_admin();
}
}
|
[
"public",
"function",
"autoload_on_admin",
"(",
")",
"{",
"$",
"this",
"->",
"on_admin",
"(",
")",
";",
"// Addons",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"this",
"->",
"addons",
")",
"-",
"1",
";",
"$",
"i",
">=",
"0",
";",
"--",
"$",
"i",
")",
"{",
"$",
"this",
"->",
"addons",
"[",
"$",
"i",
"]",
"->",
"on_admin",
"(",
")",
";",
"}",
"}"
] |
Called by autoload to init on admin.
@since 1.2
@return void
|
[
"Called",
"by",
"autoload",
"to",
"init",
"on",
"admin",
"."
] |
train
|
https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Plugin.php#L223-L230
|
amostajo/wordpress-plugin-core
|
src/psr4/Plugin.php
|
Plugin.add_action
|
public function add_action( $hook, $mvc_call, $priority = 10, $accepted_args = 1, $args = 1 )
{
$this->actions[] = $this->get_hook(
$hook,
$mvc_call,
$priority,
$accepted_args,
$args
);
}
|
php
|
public function add_action( $hook, $mvc_call, $priority = 10, $accepted_args = 1, $args = 1 )
{
$this->actions[] = $this->get_hook(
$hook,
$mvc_call,
$priority,
$accepted_args,
$args
);
}
|
[
"public",
"function",
"add_action",
"(",
"$",
"hook",
",",
"$",
"mvc_call",
",",
"$",
"priority",
"=",
"10",
",",
"$",
"accepted_args",
"=",
"1",
",",
"$",
"args",
"=",
"1",
")",
"{",
"$",
"this",
"->",
"actions",
"[",
"]",
"=",
"$",
"this",
"->",
"get_hook",
"(",
"$",
"hook",
",",
"$",
"mvc_call",
",",
"$",
"priority",
",",
"$",
"accepted_args",
",",
"$",
"args",
")",
";",
"}"
] |
Adds a Wordpress action hook.
@since 1.3
@param string $hook Wordpress hook name.
@param string $mvc_call Lightweight MVC call. (i.e. 'Controller@method')
@param mixed $priority Execution priority or MVC params.
@param mixed $accepted_args Accepted args or priority.
@param int $args Accepted args.
|
[
"Adds",
"a",
"Wordpress",
"action",
"hook",
".",
"@since",
"1",
".",
"3"
] |
train
|
https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Plugin.php#L262-L271
|
amostajo/wordpress-plugin-core
|
src/psr4/Plugin.php
|
Plugin.add_filter
|
public function add_filter( $hook, $mvc_call, $priority = 10, $accepted_args = 1, $args = 1 )
{
$this->filters[] = $this->get_hook(
$hook,
$mvc_call,
$priority,
$accepted_args,
$args
);
}
|
php
|
public function add_filter( $hook, $mvc_call, $priority = 10, $accepted_args = 1, $args = 1 )
{
$this->filters[] = $this->get_hook(
$hook,
$mvc_call,
$priority,
$accepted_args,
$args
);
}
|
[
"public",
"function",
"add_filter",
"(",
"$",
"hook",
",",
"$",
"mvc_call",
",",
"$",
"priority",
"=",
"10",
",",
"$",
"accepted_args",
"=",
"1",
",",
"$",
"args",
"=",
"1",
")",
"{",
"$",
"this",
"->",
"filters",
"[",
"]",
"=",
"$",
"this",
"->",
"get_hook",
"(",
"$",
"hook",
",",
"$",
"mvc_call",
",",
"$",
"priority",
",",
"$",
"accepted_args",
",",
"$",
"args",
")",
";",
"}"
] |
Adds a Wordpress filter hook.
@since 1.3
@param string $hook Wordpress hook name.
@param string $mvc_call Lightweight MVC call. (i.e. 'Controller@method')
@param mixed $priority Execution priority or MVC params.
@param mixed $accepted_args Accepted args or priority.
@param int $args Accepted args.
|
[
"Adds",
"a",
"Wordpress",
"filter",
"hook",
".",
"@since",
"1",
".",
"3"
] |
train
|
https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Plugin.php#L283-L292
|
amostajo/wordpress-plugin-core
|
src/psr4/Plugin.php
|
Plugin.add_shortcode
|
public function add_shortcode( $tag, $mvc_call, $mvc_args = null )
{
$this->shortcodes[] = [
'tag' => $tag,
'mvc' => $mvc_call,
'mvc_args' => $mvc_args,
];
}
|
php
|
public function add_shortcode( $tag, $mvc_call, $mvc_args = null )
{
$this->shortcodes[] = [
'tag' => $tag,
'mvc' => $mvc_call,
'mvc_args' => $mvc_args,
];
}
|
[
"public",
"function",
"add_shortcode",
"(",
"$",
"tag",
",",
"$",
"mvc_call",
",",
"$",
"mvc_args",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"shortcodes",
"[",
"]",
"=",
"[",
"'tag'",
"=>",
"$",
"tag",
",",
"'mvc'",
"=>",
"$",
"mvc_call",
",",
"'mvc_args'",
"=>",
"$",
"mvc_args",
",",
"]",
";",
"}"
] |
Adds a Wordpress shortcode.
@since 1.3
@param string $tag Wordpress tag name.
@param string $mvc_call Lightweight MVC call. (i.e. 'Controller@method')
|
[
"Adds",
"a",
"Wordpress",
"shortcode",
".",
"@since",
"1",
".",
"3"
] |
train
|
https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Plugin.php#L301-L308
|
amostajo/wordpress-plugin-core
|
src/psr4/Plugin.php
|
Plugin.add_hooks
|
public function add_hooks()
{
if ( function_exists( 'add_action' )
&& function_exists( 'add_filter' )
&& function_exists( 'add_shortcode' )
) {
// Actions
foreach ( $this->actions as $action ) {
add_action(
$action['hook'],
[ &$this, $this->get_mapped_mvc_call( $action['mvc'] ) ],
$action['priority'],
$action['args']
);
}
// Filters
foreach ( $this->filters as $filter ) {
add_filter(
$filter['hook'],
[ &$this, $this->get_mapped_mvc_call( $filter['mvc'], true ) ],
$filter['priority'],
$filter['args']
);
}
// Filters
foreach ( $this->shortcodes as $shortcode ) {
add_shortcode(
$shortcode['tag'],
[ &$this, $this->get_mapped_mvc_call( $shortcode['mvc'], true ) ]
);
}
// Widgets
if ( count( $this->widgets ) > 0 ) {
add_action( 'widgets_init', [ &$this, '_widgets' ], 1 );
}
}
}
|
php
|
public function add_hooks()
{
if ( function_exists( 'add_action' )
&& function_exists( 'add_filter' )
&& function_exists( 'add_shortcode' )
) {
// Actions
foreach ( $this->actions as $action ) {
add_action(
$action['hook'],
[ &$this, $this->get_mapped_mvc_call( $action['mvc'] ) ],
$action['priority'],
$action['args']
);
}
// Filters
foreach ( $this->filters as $filter ) {
add_filter(
$filter['hook'],
[ &$this, $this->get_mapped_mvc_call( $filter['mvc'], true ) ],
$filter['priority'],
$filter['args']
);
}
// Filters
foreach ( $this->shortcodes as $shortcode ) {
add_shortcode(
$shortcode['tag'],
[ &$this, $this->get_mapped_mvc_call( $shortcode['mvc'], true ) ]
);
}
// Widgets
if ( count( $this->widgets ) > 0 ) {
add_action( 'widgets_init', [ &$this, '_widgets' ], 1 );
}
}
}
|
[
"public",
"function",
"add_hooks",
"(",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'add_action'",
")",
"&&",
"function_exists",
"(",
"'add_filter'",
")",
"&&",
"function_exists",
"(",
"'add_shortcode'",
")",
")",
"{",
"// Actions",
"foreach",
"(",
"$",
"this",
"->",
"actions",
"as",
"$",
"action",
")",
"{",
"add_action",
"(",
"$",
"action",
"[",
"'hook'",
"]",
",",
"[",
"&",
"$",
"this",
",",
"$",
"this",
"->",
"get_mapped_mvc_call",
"(",
"$",
"action",
"[",
"'mvc'",
"]",
")",
"]",
",",
"$",
"action",
"[",
"'priority'",
"]",
",",
"$",
"action",
"[",
"'args'",
"]",
")",
";",
"}",
"// Filters",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"as",
"$",
"filter",
")",
"{",
"add_filter",
"(",
"$",
"filter",
"[",
"'hook'",
"]",
",",
"[",
"&",
"$",
"this",
",",
"$",
"this",
"->",
"get_mapped_mvc_call",
"(",
"$",
"filter",
"[",
"'mvc'",
"]",
",",
"true",
")",
"]",
",",
"$",
"filter",
"[",
"'priority'",
"]",
",",
"$",
"filter",
"[",
"'args'",
"]",
")",
";",
"}",
"// Filters",
"foreach",
"(",
"$",
"this",
"->",
"shortcodes",
"as",
"$",
"shortcode",
")",
"{",
"add_shortcode",
"(",
"$",
"shortcode",
"[",
"'tag'",
"]",
",",
"[",
"&",
"$",
"this",
",",
"$",
"this",
"->",
"get_mapped_mvc_call",
"(",
"$",
"shortcode",
"[",
"'mvc'",
"]",
",",
"true",
")",
"]",
")",
";",
"}",
"// Widgets",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"widgets",
")",
">",
"0",
")",
"{",
"add_action",
"(",
"'widgets_init'",
",",
"[",
"&",
"$",
"this",
",",
"'_widgets'",
"]",
",",
"1",
")",
";",
"}",
"}",
"}"
] |
Adds hooks and filters into Wordpress core.
@since 1.3
|
[
"Adds",
"hooks",
"and",
"filters",
"into",
"Wordpress",
"core",
"."
] |
train
|
https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Plugin.php#L325-L361
|
amostajo/wordpress-plugin-core
|
src/psr4/Plugin.php
|
Plugin.get_hook
|
private function get_hook( $hook, $mvc_call, $priority = 10, $accepted_args = 1, $args = 1 )
{
return [
'hook' => $hook,
'mvc' => $mvc_call,
'priority' => is_array( $priority ) ? $accepted_args : $priority,
'args' => is_array( $priority ) ? $args : $accepted_args,
'mvc_args' => is_array( $priority ) ? $priority : null,
];
}
|
php
|
private function get_hook( $hook, $mvc_call, $priority = 10, $accepted_args = 1, $args = 1 )
{
return [
'hook' => $hook,
'mvc' => $mvc_call,
'priority' => is_array( $priority ) ? $accepted_args : $priority,
'args' => is_array( $priority ) ? $args : $accepted_args,
'mvc_args' => is_array( $priority ) ? $priority : null,
];
}
|
[
"private",
"function",
"get_hook",
"(",
"$",
"hook",
",",
"$",
"mvc_call",
",",
"$",
"priority",
"=",
"10",
",",
"$",
"accepted_args",
"=",
"1",
",",
"$",
"args",
"=",
"1",
")",
"{",
"return",
"[",
"'hook'",
"=>",
"$",
"hook",
",",
"'mvc'",
"=>",
"$",
"mvc_call",
",",
"'priority'",
"=>",
"is_array",
"(",
"$",
"priority",
")",
"?",
"$",
"accepted_args",
":",
"$",
"priority",
",",
"'args'",
"=>",
"is_array",
"(",
"$",
"priority",
")",
"?",
"$",
"args",
":",
"$",
"accepted_args",
",",
"'mvc_args'",
"=>",
"is_array",
"(",
"$",
"priority",
")",
"?",
"$",
"priority",
":",
"null",
",",
"]",
";",
"}"
] |
Returns valid action filter item.
@since 1.3
@param string $hook Wordpress hook name.
@param string $mvc_call Lightweight MVC call. (i.e. 'Controller@method')
@param mixed $priority Execution priority or MVC params.
@param mixed $accepted_args Accepted args or priority.
@param int $args Accepted args.
@return array
|
[
"Returns",
"valid",
"action",
"filter",
"item",
".",
"@since",
"1",
".",
"3"
] |
train
|
https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Plugin.php#L399-L408
|
amostajo/wordpress-plugin-core
|
src/psr4/Plugin.php
|
Plugin.override_args
|
private function override_args( $mvc_call, $args )
{
// Check on actions
for ( $i = count( $this->actions ) - 1; $i >= 0; --$i ) {
if ( ! empty( $this->actions[$i]['mvc_args'] )
&& $this->actions[$i]['mvc'] === $mvc_call
) {
return $this->actions[$i]['mvc_args'];
}
}
// Check on filters
for ( $i = count( $this->filters ) - 1; $i >= 0; --$i ) {
if ( ! empty( $this->filters[$i]['mvc_args'] )
&& $this->filters[$i]['mvc'] === $mvc_call
) {
return $this->filters[$i]['mvc_args'];
}
}
// Check on shortcodes
for ( $i = count( $this->shortcodes ) - 1; $i >= 0; --$i ) {
if ( ! empty( $this->shortcodes[$i]['mvc_args'] )
&& $this->shortcodes[$i]['mvc'] === $mvc_call
) {
return $this->shortcodes[$i]['mvc_args'];
}
}
return $args;
}
|
php
|
private function override_args( $mvc_call, $args )
{
// Check on actions
for ( $i = count( $this->actions ) - 1; $i >= 0; --$i ) {
if ( ! empty( $this->actions[$i]['mvc_args'] )
&& $this->actions[$i]['mvc'] === $mvc_call
) {
return $this->actions[$i]['mvc_args'];
}
}
// Check on filters
for ( $i = count( $this->filters ) - 1; $i >= 0; --$i ) {
if ( ! empty( $this->filters[$i]['mvc_args'] )
&& $this->filters[$i]['mvc'] === $mvc_call
) {
return $this->filters[$i]['mvc_args'];
}
}
// Check on shortcodes
for ( $i = count( $this->shortcodes ) - 1; $i >= 0; --$i ) {
if ( ! empty( $this->shortcodes[$i]['mvc_args'] )
&& $this->shortcodes[$i]['mvc'] === $mvc_call
) {
return $this->shortcodes[$i]['mvc_args'];
}
}
return $args;
}
|
[
"private",
"function",
"override_args",
"(",
"$",
"mvc_call",
",",
"$",
"args",
")",
"{",
"// Check on actions",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"this",
"->",
"actions",
")",
"-",
"1",
";",
"$",
"i",
">=",
"0",
";",
"--",
"$",
"i",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"actions",
"[",
"$",
"i",
"]",
"[",
"'mvc_args'",
"]",
")",
"&&",
"$",
"this",
"->",
"actions",
"[",
"$",
"i",
"]",
"[",
"'mvc'",
"]",
"===",
"$",
"mvc_call",
")",
"{",
"return",
"$",
"this",
"->",
"actions",
"[",
"$",
"i",
"]",
"[",
"'mvc_args'",
"]",
";",
"}",
"}",
"// Check on filters",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"this",
"->",
"filters",
")",
"-",
"1",
";",
"$",
"i",
">=",
"0",
";",
"--",
"$",
"i",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"filters",
"[",
"$",
"i",
"]",
"[",
"'mvc_args'",
"]",
")",
"&&",
"$",
"this",
"->",
"filters",
"[",
"$",
"i",
"]",
"[",
"'mvc'",
"]",
"===",
"$",
"mvc_call",
")",
"{",
"return",
"$",
"this",
"->",
"filters",
"[",
"$",
"i",
"]",
"[",
"'mvc_args'",
"]",
";",
"}",
"}",
"// Check on shortcodes",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"this",
"->",
"shortcodes",
")",
"-",
"1",
";",
"$",
"i",
">=",
"0",
";",
"--",
"$",
"i",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"shortcodes",
"[",
"$",
"i",
"]",
"[",
"'mvc_args'",
"]",
")",
"&&",
"$",
"this",
"->",
"shortcodes",
"[",
"$",
"i",
"]",
"[",
"'mvc'",
"]",
"===",
"$",
"mvc_call",
")",
"{",
"return",
"$",
"this",
"->",
"shortcodes",
"[",
"$",
"i",
"]",
"[",
"'mvc_args'",
"]",
";",
"}",
"}",
"return",
"$",
"args",
";",
"}"
] |
Override mvc arguments with those defined when adding an action or filter.
@since 1.3
@param string $mvc_call Lightweight MVC call. (i.e. 'Controller@method')
@param array $args Current args for call.
@return array
|
[
"Override",
"mvc",
"arguments",
"with",
"those",
"defined",
"when",
"adding",
"an",
"action",
"or",
"filter",
".",
"@since",
"1",
".",
"3"
] |
train
|
https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Plugin.php#L419-L446
|
liugene/framework
|
src/Model.php
|
Model.buildQuery
|
protected function buildQuery()
{
// 合并数据库配置
if (!empty($this->connection)) {
if (is_array($this->connection)) {
$connection = array_merge(Config::get('database'), $this->connection);
} else {
$connection = $this->connection;
}
} else {
$connection = Config::get('database');
}
Db::import($connection)->connect();
/**
* @var Connect $con
*/
$con = Db::getQueryObject();
$queryClass = $con->getConfig('query');
/**
* @var Query $query
*/
$query = Application::get($queryClass);
// 设置当前数据表和模型名
if (!empty($this->table)) {
$query->table($this->table);
} else {
$query->table($this->name);
}
return $query;
}
|
php
|
protected function buildQuery()
{
// 合并数据库配置
if (!empty($this->connection)) {
if (is_array($this->connection)) {
$connection = array_merge(Config::get('database'), $this->connection);
} else {
$connection = $this->connection;
}
} else {
$connection = Config::get('database');
}
Db::import($connection)->connect();
/**
* @var Connect $con
*/
$con = Db::getQueryObject();
$queryClass = $con->getConfig('query');
/**
* @var Query $query
*/
$query = Application::get($queryClass);
// 设置当前数据表和模型名
if (!empty($this->table)) {
$query->table($this->table);
} else {
$query->table($this->name);
}
return $query;
}
|
[
"protected",
"function",
"buildQuery",
"(",
")",
"{",
"// 合并数据库配置",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"connection",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"connection",
")",
")",
"{",
"$",
"connection",
"=",
"array_merge",
"(",
"Config",
"::",
"get",
"(",
"'database'",
")",
",",
"$",
"this",
"->",
"connection",
")",
";",
"}",
"else",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"connection",
";",
"}",
"}",
"else",
"{",
"$",
"connection",
"=",
"Config",
"::",
"get",
"(",
"'database'",
")",
";",
"}",
"Db",
"::",
"import",
"(",
"$",
"connection",
")",
"->",
"connect",
"(",
")",
";",
"/**\n * @var Connect $con\n */",
"$",
"con",
"=",
"Db",
"::",
"getQueryObject",
"(",
")",
";",
"$",
"queryClass",
"=",
"$",
"con",
"->",
"getConfig",
"(",
"'query'",
")",
";",
"/**\n * @var Query $query\n */",
"$",
"query",
"=",
"Application",
"::",
"get",
"(",
"$",
"queryClass",
")",
";",
"// 设置当前数据表和模型名",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"table",
")",
")",
"{",
"$",
"query",
"->",
"table",
"(",
"$",
"this",
"->",
"table",
")",
";",
"}",
"else",
"{",
"$",
"query",
"->",
"table",
"(",
"$",
"this",
"->",
"name",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] |
创建模型的查询对象
@access protected
@return Query
|
[
"创建模型的查询对象"
] |
train
|
https://github.com/liugene/framework/blob/450642242442c5884d47552a588a2639923e7289/src/Model.php#L73-L109
|
liugene/framework
|
src/Model.php
|
Model.getQuery
|
public function getQuery($buildNewQuery = false)
{
if ($buildNewQuery) {
return $this->buildQuery();
} elseif (!isset(self::$links[$this->class])) {
// 创建模型查询对象
self::$links[$this->class] = $this->buildQuery();
}
return self::$links[$this->class];
}
|
php
|
public function getQuery($buildNewQuery = false)
{
if ($buildNewQuery) {
return $this->buildQuery();
} elseif (!isset(self::$links[$this->class])) {
// 创建模型查询对象
self::$links[$this->class] = $this->buildQuery();
}
return self::$links[$this->class];
}
|
[
"public",
"function",
"getQuery",
"(",
"$",
"buildNewQuery",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"buildNewQuery",
")",
"{",
"return",
"$",
"this",
"->",
"buildQuery",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"links",
"[",
"$",
"this",
"->",
"class",
"]",
")",
")",
"{",
"// 创建模型查询对象",
"self",
"::",
"$",
"links",
"[",
"$",
"this",
"->",
"class",
"]",
"=",
"$",
"this",
"->",
"buildQuery",
"(",
")",
";",
"}",
"return",
"self",
"::",
"$",
"links",
"[",
"$",
"this",
"->",
"class",
"]",
";",
"}"
] |
获取当前模型的查询对象
@access public
@param bool $buildNewQuery 创建新的查询对象
@return Query
|
[
"获取当前模型的查询对象"
] |
train
|
https://github.com/liugene/framework/blob/450642242442c5884d47552a588a2639923e7289/src/Model.php#L117-L127
|
liugene/framework
|
src/Model.php
|
Model.insert
|
public function insert(array $data)
{
if (false === $this->trigger('before_insert', $this)) {
return false;
}
if($this->dateFormat && $this->updateTime && $this->createTime){
$time = date('Y-m-d H:i:s', time());
$data[$this->updateTime] = $time;
$data[$this->createTime] = $time;
} else {
$time = time();
$data[$this->updateTime] = $time;
$data[$this->createTime] = $time;
}
$response = $this->getQuery()->insert($data);
if (false === $this->trigger('after_insert', $this)) {
return false;
}
return $response;
}
|
php
|
public function insert(array $data)
{
if (false === $this->trigger('before_insert', $this)) {
return false;
}
if($this->dateFormat && $this->updateTime && $this->createTime){
$time = date('Y-m-d H:i:s', time());
$data[$this->updateTime] = $time;
$data[$this->createTime] = $time;
} else {
$time = time();
$data[$this->updateTime] = $time;
$data[$this->createTime] = $time;
}
$response = $this->getQuery()->insert($data);
if (false === $this->trigger('after_insert', $this)) {
return false;
}
return $response;
}
|
[
"public",
"function",
"insert",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"trigger",
"(",
"'before_insert'",
",",
"$",
"this",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dateFormat",
"&&",
"$",
"this",
"->",
"updateTime",
"&&",
"$",
"this",
"->",
"createTime",
")",
"{",
"$",
"time",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
",",
"time",
"(",
")",
")",
";",
"$",
"data",
"[",
"$",
"this",
"->",
"updateTime",
"]",
"=",
"$",
"time",
";",
"$",
"data",
"[",
"$",
"this",
"->",
"createTime",
"]",
"=",
"$",
"time",
";",
"}",
"else",
"{",
"$",
"time",
"=",
"time",
"(",
")",
";",
"$",
"data",
"[",
"$",
"this",
"->",
"updateTime",
"]",
"=",
"$",
"time",
";",
"$",
"data",
"[",
"$",
"this",
"->",
"createTime",
"]",
"=",
"$",
"time",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"getQuery",
"(",
")",
"->",
"insert",
"(",
"$",
"data",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"trigger",
"(",
"'after_insert'",
",",
"$",
"this",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"response",
";",
"}"
] |
save 数据库添加操作方法 返回保存记录的ID
|
[
"save",
"数据库添加操作方法",
"返回保存记录的ID"
] |
train
|
https://github.com/liugene/framework/blob/450642242442c5884d47552a588a2639923e7289/src/Model.php#L182-L204
|
liugene/framework
|
src/Model.php
|
Model.delete
|
public function delete($data=null)
{
if (false === $this->trigger('before_delete', $this)) {
return false;
}
$response = $this->getQuery()->delete($data);
if (false === $this->trigger('after_insert', $this)) {
return false;
}
return $response;
}
|
php
|
public function delete($data=null)
{
if (false === $this->trigger('before_delete', $this)) {
return false;
}
$response = $this->getQuery()->delete($data);
if (false === $this->trigger('after_insert', $this)) {
return false;
}
return $response;
}
|
[
"public",
"function",
"delete",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"trigger",
"(",
"'before_delete'",
",",
"$",
"this",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"getQuery",
"(",
")",
"->",
"delete",
"(",
"$",
"data",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"trigger",
"(",
"'after_insert'",
",",
"$",
"this",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"response",
";",
"}"
] |
delete
|
[
"delete"
] |
train
|
https://github.com/liugene/framework/blob/450642242442c5884d47552a588a2639923e7289/src/Model.php#L226-L239
|
liugene/framework
|
src/Model.php
|
Model.event
|
public static function event($event, $callback, $override = false)
{
$class = get_called_class();
if ($override) {
self::$event[$class][$event] = [];
}
self::$event[$class][$event][] = $callback;
}
|
php
|
public static function event($event, $callback, $override = false)
{
$class = get_called_class();
if ($override) {
self::$event[$class][$event] = [];
}
self::$event[$class][$event][] = $callback;
}
|
[
"public",
"static",
"function",
"event",
"(",
"$",
"event",
",",
"$",
"callback",
",",
"$",
"override",
"=",
"false",
")",
"{",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"$",
"override",
")",
"{",
"self",
"::",
"$",
"event",
"[",
"$",
"class",
"]",
"[",
"$",
"event",
"]",
"=",
"[",
"]",
";",
"}",
"self",
"::",
"$",
"event",
"[",
"$",
"class",
"]",
"[",
"$",
"event",
"]",
"[",
"]",
"=",
"$",
"callback",
";",
"}"
] |
注册回调方法
@access public
@param string $event 事件名
@param callable $callback 回调方法
@param bool $override 是否覆盖
@return void
|
[
"注册回调方法"
] |
train
|
https://github.com/liugene/framework/blob/450642242442c5884d47552a588a2639923e7289/src/Model.php#L427-L434
|
liugene/framework
|
src/Model.php
|
Model.trigger
|
protected function trigger($event, &$params)
{
if (isset(self::$event[$this->class][$event])) {
foreach (self::$event[$this->class][$event] as $callback) {
if (is_callable($callback)) {
$result = call_user_func_array($callback, [ & $params]);
if (false === $result) {
return false;
}
}
}
}
return true;
}
|
php
|
protected function trigger($event, &$params)
{
if (isset(self::$event[$this->class][$event])) {
foreach (self::$event[$this->class][$event] as $callback) {
if (is_callable($callback)) {
$result = call_user_func_array($callback, [ & $params]);
if (false === $result) {
return false;
}
}
}
}
return true;
}
|
[
"protected",
"function",
"trigger",
"(",
"$",
"event",
",",
"&",
"$",
"params",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"event",
"[",
"$",
"this",
"->",
"class",
"]",
"[",
"$",
"event",
"]",
")",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"event",
"[",
"$",
"this",
"->",
"class",
"]",
"[",
"$",
"event",
"]",
"as",
"$",
"callback",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"result",
"=",
"call_user_func_array",
"(",
"$",
"callback",
",",
"[",
"&",
"$",
"params",
"]",
")",
";",
"if",
"(",
"false",
"===",
"$",
"result",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] |
触发事件
@access protected
@param string $event 事件名
@param mixed $params 传入参数(引用)
@return bool
|
[
"触发事件"
] |
train
|
https://github.com/liugene/framework/blob/450642242442c5884d47552a588a2639923e7289/src/Model.php#L443-L456
|
GrafiteInc/Mission-Control-Package
|
src/TrafficService.php
|
TrafficService.sendTraffic
|
public function sendTraffic($log, $format)
{
$headers = [
'token' => $this->token,
];
if (is_null($this->token)) {
throw new Exception("Missing token", 1);
}
$query = $this->getTraffic($log, $format);
$response = $this->curl::post($this->missionControlUrl, $headers, $query);
if ($response->code != 200) {
$this->error('Unable to message Mission Control, please confirm your token');
}
return true;
}
|
php
|
public function sendTraffic($log, $format)
{
$headers = [
'token' => $this->token,
];
if (is_null($this->token)) {
throw new Exception("Missing token", 1);
}
$query = $this->getTraffic($log, $format);
$response = $this->curl::post($this->missionControlUrl, $headers, $query);
if ($response->code != 200) {
$this->error('Unable to message Mission Control, please confirm your token');
}
return true;
}
|
[
"public",
"function",
"sendTraffic",
"(",
"$",
"log",
",",
"$",
"format",
")",
"{",
"$",
"headers",
"=",
"[",
"'token'",
"=>",
"$",
"this",
"->",
"token",
",",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"token",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Missing token\"",
",",
"1",
")",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"getTraffic",
"(",
"$",
"log",
",",
"$",
"format",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"curl",
"::",
"post",
"(",
"$",
"this",
"->",
"missionControlUrl",
",",
"$",
"headers",
",",
"$",
"query",
")",
";",
"if",
"(",
"$",
"response",
"->",
"code",
"!=",
"200",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'Unable to message Mission Control, please confirm your token'",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Send the exception to Mission control.
@param Exeption $exception
@return bool
|
[
"Send",
"the",
"exception",
"to",
"Mission",
"control",
"."
] |
train
|
https://github.com/GrafiteInc/Mission-Control-Package/blob/4e85f0b729329783b34e35d90abba2807899ff58/src/TrafficService.php#L35-L54
|
GrafiteInc/Mission-Control-Package
|
src/TrafficService.php
|
TrafficService.getTraffic
|
public function getTraffic($log, $format)
{
try {
return $this->service->analyze($log, $format);
} catch (Exception $e) {
$this->issueService->exception($e);
}
}
|
php
|
public function getTraffic($log, $format)
{
try {
return $this->service->analyze($log, $format);
} catch (Exception $e) {
$this->issueService->exception($e);
}
}
|
[
"public",
"function",
"getTraffic",
"(",
"$",
"log",
",",
"$",
"format",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"service",
"->",
"analyze",
"(",
"$",
"log",
",",
"$",
"format",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"issueService",
"->",
"exception",
"(",
"$",
"e",
")",
";",
"}",
"}"
] |
Collect data and set report details.
@return array
|
[
"Collect",
"data",
"and",
"set",
"report",
"details",
"."
] |
train
|
https://github.com/GrafiteInc/Mission-Control-Package/blob/4e85f0b729329783b34e35d90abba2807899ff58/src/TrafficService.php#L61-L68
|
steeffeen/FancyManiaLinks
|
FML/Controls/Label.php
|
Label.addClockFeature
|
public function addClockFeature($showSeconds = true, $showFullDate = false)
{
$clock = new Clock($this, $showSeconds, $showFullDate);
$this->addScriptFeature($clock);
return $this;
}
|
php
|
public function addClockFeature($showSeconds = true, $showFullDate = false)
{
$clock = new Clock($this, $showSeconds, $showFullDate);
$this->addScriptFeature($clock);
return $this;
}
|
[
"public",
"function",
"addClockFeature",
"(",
"$",
"showSeconds",
"=",
"true",
",",
"$",
"showFullDate",
"=",
"false",
")",
"{",
"$",
"clock",
"=",
"new",
"Clock",
"(",
"$",
"this",
",",
"$",
"showSeconds",
",",
"$",
"showFullDate",
")",
";",
"$",
"this",
"->",
"addScriptFeature",
"(",
"$",
"clock",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a dynamic Feature showing the current time
@api
@param bool $showSeconds (optional) If the seconds should be shown
@param bool $showFullDate (optional) If the date should be shown
@return static
|
[
"Add",
"a",
"dynamic",
"Feature",
"showing",
"the",
"current",
"time"
] |
train
|
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Controls/Label.php#L604-L609
|
paliari/oauth2-server-facade
|
src/Paliari/Oauth2ServerFacade/Oauth2Facade.php
|
Oauth2Facade.authorized
|
protected function authorized($client_id, $user_id)
{
if ($this->storage->getClientUser($client_id, $user_id)) {
return true;
}
if ($_POST && 'yes' === @$_POST['authorized']) {
$this->storage->setClientUser($client_id, $user_id);
return true;
}
return false;
}
|
php
|
protected function authorized($client_id, $user_id)
{
if ($this->storage->getClientUser($client_id, $user_id)) {
return true;
}
if ($_POST && 'yes' === @$_POST['authorized']) {
$this->storage->setClientUser($client_id, $user_id);
return true;
}
return false;
}
|
[
"protected",
"function",
"authorized",
"(",
"$",
"client_id",
",",
"$",
"user_id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"storage",
"->",
"getClientUser",
"(",
"$",
"client_id",
",",
"$",
"user_id",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"_POST",
"&&",
"'yes'",
"===",
"@",
"$",
"_POST",
"[",
"'authorized'",
"]",
")",
"{",
"$",
"this",
"->",
"storage",
"->",
"setClientUser",
"(",
"$",
"client_id",
",",
"$",
"user_id",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
@param string $client_id
@param string $user_id
@return bool
|
[
"@param",
"string",
"$client_id",
"@param",
"string",
"$user_id"
] |
train
|
https://github.com/paliari/oauth2-server-facade/blob/72785397ff5b2d4c9e8cf487b4215b3808bbcfdf/src/Paliari/Oauth2ServerFacade/Oauth2Facade.php#L168-L180
|
phpmob/changmin
|
src/PhpMob/CoreBundle/Form/Type/WebUserRegistrationType.php
|
WebUserRegistrationType.buildForm
|
public function buildForm(FormBuilderInterface $builder, array $options): void
{
parent::buildForm($builder, $options);
$builder->remove('enabled');
$builder->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'first_options' => ['label' => 'sylius.form.user.password.label'],
'second_options' => ['label' => 'sylius.form.user.password.confirmation'],
'invalid_message' => 'sylius.user.plainPassword.mismatch',
]);
}
|
php
|
public function buildForm(FormBuilderInterface $builder, array $options): void
{
parent::buildForm($builder, $options);
$builder->remove('enabled');
$builder->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'first_options' => ['label' => 'sylius.form.user.password.label'],
'second_options' => ['label' => 'sylius.form.user.password.confirmation'],
'invalid_message' => 'sylius.user.plainPassword.mismatch',
]);
}
|
[
"public",
"function",
"buildForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
":",
"void",
"{",
"parent",
"::",
"buildForm",
"(",
"$",
"builder",
",",
"$",
"options",
")",
";",
"$",
"builder",
"->",
"remove",
"(",
"'enabled'",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'plainPassword'",
",",
"RepeatedType",
"::",
"class",
",",
"[",
"'type'",
"=>",
"PasswordType",
"::",
"class",
",",
"'first_options'",
"=>",
"[",
"'label'",
"=>",
"'sylius.form.user.password.label'",
"]",
",",
"'second_options'",
"=>",
"[",
"'label'",
"=>",
"'sylius.form.user.password.confirmation'",
"]",
",",
"'invalid_message'",
"=>",
"'sylius.user.plainPassword.mismatch'",
",",
"]",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CoreBundle/Form/Type/WebUserRegistrationType.php#L27-L39
|
dreamfactorysoftware/df-file
|
src/Services/BaseFileService.php
|
BaseFileService.setResourceMembers
|
protected function setResourceMembers($resourcePath = null)
{
// File services need the trailing slash '/' for designating folders vs files
// It is removed by the parent method
$isFolder = (empty($resourcePath) ? false : ('/' === substr($resourcePath, -1)));
parent::setResourceMembers($resourcePath);
if (!empty($resourcePath)) {
if ($isFolder) {
$this->folderPath = $resourcePath;
} else {
$this->folderPath = dirname($resourcePath) . '/';
$this->filePath = $resourcePath;
}
}
return $this;
}
|
php
|
protected function setResourceMembers($resourcePath = null)
{
// File services need the trailing slash '/' for designating folders vs files
// It is removed by the parent method
$isFolder = (empty($resourcePath) ? false : ('/' === substr($resourcePath, -1)));
parent::setResourceMembers($resourcePath);
if (!empty($resourcePath)) {
if ($isFolder) {
$this->folderPath = $resourcePath;
} else {
$this->folderPath = dirname($resourcePath) . '/';
$this->filePath = $resourcePath;
}
}
return $this;
}
|
[
"protected",
"function",
"setResourceMembers",
"(",
"$",
"resourcePath",
"=",
"null",
")",
"{",
"// File services need the trailing slash '/' for designating folders vs files",
"// It is removed by the parent method",
"$",
"isFolder",
"=",
"(",
"empty",
"(",
"$",
"resourcePath",
")",
"?",
"false",
":",
"(",
"'/'",
"===",
"substr",
"(",
"$",
"resourcePath",
",",
"-",
"1",
")",
")",
")",
";",
"parent",
"::",
"setResourceMembers",
"(",
"$",
"resourcePath",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"resourcePath",
")",
")",
"{",
"if",
"(",
"$",
"isFolder",
")",
"{",
"$",
"this",
"->",
"folderPath",
"=",
"$",
"resourcePath",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"folderPath",
"=",
"dirname",
"(",
"$",
"resourcePath",
")",
".",
"'/'",
";",
"$",
"this",
"->",
"filePath",
"=",
"$",
"resourcePath",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Apply the commonly used REST path members to the class.
@param string $resourcePath
@return $this
|
[
"Apply",
"the",
"commonly",
"used",
"REST",
"path",
"members",
"to",
"the",
"class",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Services/BaseFileService.php#L253-L270
|
dreamfactorysoftware/df-file
|
src/Services/BaseFileService.php
|
BaseFileService.handleResource
|
protected function handleResource(array $resources)
{
// Fall through is to process just like a no-resource request
$resources = $this->getResourceHandlers();
if ((false !== $resources) && !empty($this->resource)) {
if (in_array($this->resource, $resources)) {
return $this->processRequest();
}
}
throw new NotFoundException("Resource '{$this->resource}' not found for service '{$this->name}'.");
}
|
php
|
protected function handleResource(array $resources)
{
// Fall through is to process just like a no-resource request
$resources = $this->getResourceHandlers();
if ((false !== $resources) && !empty($this->resource)) {
if (in_array($this->resource, $resources)) {
return $this->processRequest();
}
}
throw new NotFoundException("Resource '{$this->resource}' not found for service '{$this->name}'.");
}
|
[
"protected",
"function",
"handleResource",
"(",
"array",
"$",
"resources",
")",
"{",
"// Fall through is to process just like a no-resource request",
"$",
"resources",
"=",
"$",
"this",
"->",
"getResourceHandlers",
"(",
")",
";",
"if",
"(",
"(",
"false",
"!==",
"$",
"resources",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"resource",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"resource",
",",
"$",
"resources",
")",
")",
"{",
"return",
"$",
"this",
"->",
"processRequest",
"(",
")",
";",
"}",
"}",
"throw",
"new",
"NotFoundException",
"(",
"\"Resource '{$this->resource}' not found for service '{$this->name}'.\"",
")",
";",
"}"
] |
@param array $resources
@return bool|mixed
@throws BadRequestException
@throws NotFoundException
|
[
"@param",
"array",
"$resources"
] |
train
|
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Services/BaseFileService.php#L284-L295
|
dreamfactorysoftware/df-file
|
src/Services/BaseFileService.php
|
BaseFileService.doSearch
|
protected function doSearch($search)
{
$found = [];
$result = $this->driver->getFolder(
$this->container,
$this->folderPath,
$this->request->getParameterAsBool('include_files', true),
$this->request->getParameterAsBool('include_folders', true),
$this->request->getParameterAsBool('full_tree', false)
);
foreach ($result as $rs) {
if (stripos(basename($rs['path']), $search) !== false) {
$found[] = $rs;
}
}
return $found;
}
|
php
|
protected function doSearch($search)
{
$found = [];
$result = $this->driver->getFolder(
$this->container,
$this->folderPath,
$this->request->getParameterAsBool('include_files', true),
$this->request->getParameterAsBool('include_folders', true),
$this->request->getParameterAsBool('full_tree', false)
);
foreach ($result as $rs) {
if (stripos(basename($rs['path']), $search) !== false) {
$found[] = $rs;
}
}
return $found;
}
|
[
"protected",
"function",
"doSearch",
"(",
"$",
"search",
")",
"{",
"$",
"found",
"=",
"[",
"]",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"driver",
"->",
"getFolder",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"this",
"->",
"folderPath",
",",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'include_files'",
",",
"true",
")",
",",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'include_folders'",
",",
"true",
")",
",",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'full_tree'",
",",
"false",
")",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"rs",
")",
"{",
"if",
"(",
"stripos",
"(",
"basename",
"(",
"$",
"rs",
"[",
"'path'",
"]",
")",
",",
"$",
"search",
")",
"!==",
"false",
")",
"{",
"$",
"found",
"[",
"]",
"=",
"$",
"rs",
";",
"}",
"}",
"return",
"$",
"found",
";",
"}"
] |
Searches for files/folders.
@param string $search
@return array
|
[
"Searches",
"for",
"files",
"/",
"folders",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Services/BaseFileService.php#L340-L358
|
dreamfactorysoftware/df-file
|
src/Services/BaseFileService.php
|
BaseFileService.handleGET
|
protected function handleGET()
{
if (empty($this->folderPath) && empty($this->filePath) &&
$this->request->getParameterAsBool(ApiOptions::AS_ACCESS_LIST)
) {
return ResourcesWrapper::wrapResources($this->getAccessList());
}
if (empty($this->filePath)) {
//Resource is the root/container or a folder
if ($this->request->getParameterAsBool('zip')) {
$zipFileName = '';
if (empty($this->container) && empty($this->folderPath)) {
$zipFileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $this->getName() . '_' . time() . '.zip';
}
$zipFileName = $this->driver->getFolderAsZip($this->container, $this->folderPath, null, $zipFileName);
$response = new StreamedResponse();
$response->setCallback(function () use ($zipFileName){
$chunk = \Config::get('df.file_chunk_size');
FileUtilities::sendFile($zipFileName, true, $chunk);
unlink($zipFileName);
});
return $response;
} elseif ($this->request->getParameterAsBool('include_properties')) {
$result = $this->driver->getFolderProperties($this->container, $this->folderPath);
} else {
$search = $this->request->getParameter('search');
if (!empty($search)) {
$result = $this->doSearch($search);
} else {
$result = $this->driver->getFolder(
$this->container,
$this->folderPath,
$this->request->getParameterAsBool('include_files', true),
$this->request->getParameterAsBool('include_folders', true),
$this->request->getParameterAsBool('full_tree', false)
);
}
$asList = $this->request->getParameterAsBool(ApiOptions::AS_LIST);
$idField = $this->request->getParameter(ApiOptions::ID_FIELD, static::getResourceIdentifier());
$fields = $this->request->getParameter(ApiOptions::FIELDS, ApiOptions::FIELDS_ALL);
$result = ResourcesWrapper::cleanResources($result, $asList, $idField, $fields, true);
}
} else {
// Resource is a file
// Check to see if file exists
if (!$this->driver->fileExists($this->container, $this->filePath)) {
throw new NotFoundException("The specified file '" . $this->filePath . "' was not found in storage.");
}
if ($this->request->getParameterAsBool('include_properties', false)) {
// just properties of the file itself
$content = $this->request->getParameterAsBool('content', false);
$base64 = $this->request->getParameterAsBool('is_base64', true);
$result = $this->driver->getFileProperties($this->container, $this->filePath, $content, $base64);
} else {
$download = $this->request->getParameterAsBool('download', false);
// stream the file using StreamedResponse, exits processing
$response = new StreamedResponse();
$service = $this;
$response->setCallback(function () use ($service, $download){
$service->streamFile($service->filePath, $download);
});
return $response;
}
}
return $result;
}
|
php
|
protected function handleGET()
{
if (empty($this->folderPath) && empty($this->filePath) &&
$this->request->getParameterAsBool(ApiOptions::AS_ACCESS_LIST)
) {
return ResourcesWrapper::wrapResources($this->getAccessList());
}
if (empty($this->filePath)) {
//Resource is the root/container or a folder
if ($this->request->getParameterAsBool('zip')) {
$zipFileName = '';
if (empty($this->container) && empty($this->folderPath)) {
$zipFileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $this->getName() . '_' . time() . '.zip';
}
$zipFileName = $this->driver->getFolderAsZip($this->container, $this->folderPath, null, $zipFileName);
$response = new StreamedResponse();
$response->setCallback(function () use ($zipFileName){
$chunk = \Config::get('df.file_chunk_size');
FileUtilities::sendFile($zipFileName, true, $chunk);
unlink($zipFileName);
});
return $response;
} elseif ($this->request->getParameterAsBool('include_properties')) {
$result = $this->driver->getFolderProperties($this->container, $this->folderPath);
} else {
$search = $this->request->getParameter('search');
if (!empty($search)) {
$result = $this->doSearch($search);
} else {
$result = $this->driver->getFolder(
$this->container,
$this->folderPath,
$this->request->getParameterAsBool('include_files', true),
$this->request->getParameterAsBool('include_folders', true),
$this->request->getParameterAsBool('full_tree', false)
);
}
$asList = $this->request->getParameterAsBool(ApiOptions::AS_LIST);
$idField = $this->request->getParameter(ApiOptions::ID_FIELD, static::getResourceIdentifier());
$fields = $this->request->getParameter(ApiOptions::FIELDS, ApiOptions::FIELDS_ALL);
$result = ResourcesWrapper::cleanResources($result, $asList, $idField, $fields, true);
}
} else {
// Resource is a file
// Check to see if file exists
if (!$this->driver->fileExists($this->container, $this->filePath)) {
throw new NotFoundException("The specified file '" . $this->filePath . "' was not found in storage.");
}
if ($this->request->getParameterAsBool('include_properties', false)) {
// just properties of the file itself
$content = $this->request->getParameterAsBool('content', false);
$base64 = $this->request->getParameterAsBool('is_base64', true);
$result = $this->driver->getFileProperties($this->container, $this->filePath, $content, $base64);
} else {
$download = $this->request->getParameterAsBool('download', false);
// stream the file using StreamedResponse, exits processing
$response = new StreamedResponse();
$service = $this;
$response->setCallback(function () use ($service, $download){
$service->streamFile($service->filePath, $download);
});
return $response;
}
}
return $result;
}
|
[
"protected",
"function",
"handleGET",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"folderPath",
")",
"&&",
"empty",
"(",
"$",
"this",
"->",
"filePath",
")",
"&&",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"ApiOptions",
"::",
"AS_ACCESS_LIST",
")",
")",
"{",
"return",
"ResourcesWrapper",
"::",
"wrapResources",
"(",
"$",
"this",
"->",
"getAccessList",
"(",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"filePath",
")",
")",
"{",
"//Resource is the root/container or a folder",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'zip'",
")",
")",
"{",
"$",
"zipFileName",
"=",
"''",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"container",
")",
"&&",
"empty",
"(",
"$",
"this",
"->",
"folderPath",
")",
")",
"{",
"$",
"zipFileName",
"=",
"sys_get_temp_dir",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'_'",
".",
"time",
"(",
")",
".",
"'.zip'",
";",
"}",
"$",
"zipFileName",
"=",
"$",
"this",
"->",
"driver",
"->",
"getFolderAsZip",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"this",
"->",
"folderPath",
",",
"null",
",",
"$",
"zipFileName",
")",
";",
"$",
"response",
"=",
"new",
"StreamedResponse",
"(",
")",
";",
"$",
"response",
"->",
"setCallback",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"zipFileName",
")",
"{",
"$",
"chunk",
"=",
"\\",
"Config",
"::",
"get",
"(",
"'df.file_chunk_size'",
")",
";",
"FileUtilities",
"::",
"sendFile",
"(",
"$",
"zipFileName",
",",
"true",
",",
"$",
"chunk",
")",
";",
"unlink",
"(",
"$",
"zipFileName",
")",
";",
"}",
")",
";",
"return",
"$",
"response",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'include_properties'",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"driver",
"->",
"getFolderProperties",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"this",
"->",
"folderPath",
")",
";",
"}",
"else",
"{",
"$",
"search",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameter",
"(",
"'search'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"search",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"doSearch",
"(",
"$",
"search",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"driver",
"->",
"getFolder",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"this",
"->",
"folderPath",
",",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'include_files'",
",",
"true",
")",
",",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'include_folders'",
",",
"true",
")",
",",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'full_tree'",
",",
"false",
")",
")",
";",
"}",
"$",
"asList",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"ApiOptions",
"::",
"AS_LIST",
")",
";",
"$",
"idField",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameter",
"(",
"ApiOptions",
"::",
"ID_FIELD",
",",
"static",
"::",
"getResourceIdentifier",
"(",
")",
")",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameter",
"(",
"ApiOptions",
"::",
"FIELDS",
",",
"ApiOptions",
"::",
"FIELDS_ALL",
")",
";",
"$",
"result",
"=",
"ResourcesWrapper",
"::",
"cleanResources",
"(",
"$",
"result",
",",
"$",
"asList",
",",
"$",
"idField",
",",
"$",
"fields",
",",
"true",
")",
";",
"}",
"}",
"else",
"{",
"// Resource is a file",
"// Check to see if file exists",
"if",
"(",
"!",
"$",
"this",
"->",
"driver",
"->",
"fileExists",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"this",
"->",
"filePath",
")",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"\"The specified file '\"",
".",
"$",
"this",
"->",
"filePath",
".",
"\"' was not found in storage.\"",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'include_properties'",
",",
"false",
")",
")",
"{",
"// just properties of the file itself",
"$",
"content",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'content'",
",",
"false",
")",
";",
"$",
"base64",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'is_base64'",
",",
"true",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"driver",
"->",
"getFileProperties",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"this",
"->",
"filePath",
",",
"$",
"content",
",",
"$",
"base64",
")",
";",
"}",
"else",
"{",
"$",
"download",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'download'",
",",
"false",
")",
";",
"// stream the file using StreamedResponse, exits processing",
"$",
"response",
"=",
"new",
"StreamedResponse",
"(",
")",
";",
"$",
"service",
"=",
"$",
"this",
";",
"$",
"response",
"->",
"setCallback",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"service",
",",
"$",
"download",
")",
"{",
"$",
"service",
"->",
"streamFile",
"(",
"$",
"service",
"->",
"filePath",
",",
"$",
"download",
")",
";",
"}",
")",
";",
"return",
"$",
"response",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Handles GET actions.
@throws \Exception
@return \DreamFactory\Core\Utility\ServiceResponse|StreamedResponse|array
|
[
"Handles",
"GET",
"actions",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Services/BaseFileService.php#L366-L437
|
dreamfactorysoftware/df-file
|
src/Services/BaseFileService.php
|
BaseFileService.handlePOST
|
protected function handlePOST()
{
$extract = $this->request->getParameterAsBool('extract', false);
$clean = $this->request->getParameterAsBool('clean', false);
$checkExist = $this->request->getParameterAsBool('check_exist', false);
if (empty($this->filePath)) {
$fileNameHeader = str_to_utf8($this->request->getHeader('X-File-Name'));
$folderNameHeader = str_to_utf8($this->request->getHeader('X-Folder-Name'));
$fileUrl = filter_var($this->request->getParameter('url', ''), FILTER_SANITIZE_URL);
if (!empty($fileNameHeader)) {
// html5 single posting for file create
$result = $this->handleFileContent(
$this->folderPath,
$fileNameHeader,
$this->request->getContent(),
$this->request->getContentType(),
$extract,
$clean,
$checkExist
);
} elseif (!empty($folderNameHeader)) {
// html5 single posting for folder create
$fullPathName = $this->folderPath . $folderNameHeader;
$content = $this->request->getPayloadData();
$this->driver->createFolder($this->container, $fullPathName, $content);
$result = ['name' => $folderNameHeader, 'path' => $fullPathName];
} elseif (!empty($fileUrl)) {
// upload a file from a url, could be expandable zip
$tmpName = null;
$newFileName = $this->request->input('filename', '');
try {
$tmpName = FileUtilities::importUrlFileToTemp($fileUrl);
$result = $this->handleFile(
$this->folderPath,
$newFileName,
$tmpName,
'',
$extract,
$clean,
$checkExist
);
@unlink($tmpName);
} catch (\Exception $ex) {
if (!empty($tmpName)) {
@unlink($tmpName);
}
throw $ex;
}
} elseif (null !== $uploadedFiles = $this->request->getFile('files')) {
if (Arr::isAssoc($uploadedFiles)) { //Single file upload
$uploadedFiles = [$uploadedFiles];
}
$result = $this->handleFolderContentFromFiles($uploadedFiles, $extract, $clean, $checkExist);
$result = ResourcesWrapper::cleanResources($result);
} else {
// possibly xml or json post either of files or folders to create, copy or move
if (!empty($data = ResourcesWrapper::unwrapResources($this->getPayloadData()))) {
$result = $this->handleFolderContentFromData($data, $extract, $clean, $checkExist);
$result = ResourcesWrapper::cleanResources($result);
} else {
// create folder from resource path
$this->driver->createFolder($this->container, $this->folderPath);
$result = ['name' => basename($this->folderPath), 'path' => $this->folderPath];
}
}
} else {
// create the file
// possible file handling parameters
$name = basename($this->filePath);
$path = (false !== strpos($this->filePath, '/')) ? dirname($this->filePath) : '';
$files = $this->request->getFile('files');
if (empty($files)) {
// direct load from posted data as content
// or possibly xml or json post of file properties create, copy or move
$result = $this->handleFileContent(
$path,
$name,
$this->request->getContent(),
$this->request->getContentType(),
$extract,
$clean,
$checkExist
);
} else {
if (Arr::isAssoc($files)) { // Single file upload
$files = [$files];
}
if (1 < count($files)) {
throw new BadRequestException("Multiple files uploaded to a single REST resource '$name'.");
}
$file = array_get($files, 0);
if (empty($file)) {
throw new BadRequestException("No file uploaded to REST resource '$name'.");
}
$error = $file['error'];
if (UPLOAD_ERR_OK == $error) {
$result = $this->handleFile(
$path,
$name,
$file["tmp_name"],
$file['type'],
$extract,
$clean,
$checkExist
);
} else {
throw new InternalServerErrorException("Failed to upload file $name.\n$error");
}
}
}
return ResponseFactory::create($result, null, ServiceResponseInterface::HTTP_CREATED);
}
|
php
|
protected function handlePOST()
{
$extract = $this->request->getParameterAsBool('extract', false);
$clean = $this->request->getParameterAsBool('clean', false);
$checkExist = $this->request->getParameterAsBool('check_exist', false);
if (empty($this->filePath)) {
$fileNameHeader = str_to_utf8($this->request->getHeader('X-File-Name'));
$folderNameHeader = str_to_utf8($this->request->getHeader('X-Folder-Name'));
$fileUrl = filter_var($this->request->getParameter('url', ''), FILTER_SANITIZE_URL);
if (!empty($fileNameHeader)) {
// html5 single posting for file create
$result = $this->handleFileContent(
$this->folderPath,
$fileNameHeader,
$this->request->getContent(),
$this->request->getContentType(),
$extract,
$clean,
$checkExist
);
} elseif (!empty($folderNameHeader)) {
// html5 single posting for folder create
$fullPathName = $this->folderPath . $folderNameHeader;
$content = $this->request->getPayloadData();
$this->driver->createFolder($this->container, $fullPathName, $content);
$result = ['name' => $folderNameHeader, 'path' => $fullPathName];
} elseif (!empty($fileUrl)) {
// upload a file from a url, could be expandable zip
$tmpName = null;
$newFileName = $this->request->input('filename', '');
try {
$tmpName = FileUtilities::importUrlFileToTemp($fileUrl);
$result = $this->handleFile(
$this->folderPath,
$newFileName,
$tmpName,
'',
$extract,
$clean,
$checkExist
);
@unlink($tmpName);
} catch (\Exception $ex) {
if (!empty($tmpName)) {
@unlink($tmpName);
}
throw $ex;
}
} elseif (null !== $uploadedFiles = $this->request->getFile('files')) {
if (Arr::isAssoc($uploadedFiles)) { //Single file upload
$uploadedFiles = [$uploadedFiles];
}
$result = $this->handleFolderContentFromFiles($uploadedFiles, $extract, $clean, $checkExist);
$result = ResourcesWrapper::cleanResources($result);
} else {
// possibly xml or json post either of files or folders to create, copy or move
if (!empty($data = ResourcesWrapper::unwrapResources($this->getPayloadData()))) {
$result = $this->handleFolderContentFromData($data, $extract, $clean, $checkExist);
$result = ResourcesWrapper::cleanResources($result);
} else {
// create folder from resource path
$this->driver->createFolder($this->container, $this->folderPath);
$result = ['name' => basename($this->folderPath), 'path' => $this->folderPath];
}
}
} else {
// create the file
// possible file handling parameters
$name = basename($this->filePath);
$path = (false !== strpos($this->filePath, '/')) ? dirname($this->filePath) : '';
$files = $this->request->getFile('files');
if (empty($files)) {
// direct load from posted data as content
// or possibly xml or json post of file properties create, copy or move
$result = $this->handleFileContent(
$path,
$name,
$this->request->getContent(),
$this->request->getContentType(),
$extract,
$clean,
$checkExist
);
} else {
if (Arr::isAssoc($files)) { // Single file upload
$files = [$files];
}
if (1 < count($files)) {
throw new BadRequestException("Multiple files uploaded to a single REST resource '$name'.");
}
$file = array_get($files, 0);
if (empty($file)) {
throw new BadRequestException("No file uploaded to REST resource '$name'.");
}
$error = $file['error'];
if (UPLOAD_ERR_OK == $error) {
$result = $this->handleFile(
$path,
$name,
$file["tmp_name"],
$file['type'],
$extract,
$clean,
$checkExist
);
} else {
throw new InternalServerErrorException("Failed to upload file $name.\n$error");
}
}
}
return ResponseFactory::create($result, null, ServiceResponseInterface::HTTP_CREATED);
}
|
[
"protected",
"function",
"handlePOST",
"(",
")",
"{",
"$",
"extract",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'extract'",
",",
"false",
")",
";",
"$",
"clean",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'clean'",
",",
"false",
")",
";",
"$",
"checkExist",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'check_exist'",
",",
"false",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"filePath",
")",
")",
"{",
"$",
"fileNameHeader",
"=",
"str_to_utf8",
"(",
"$",
"this",
"->",
"request",
"->",
"getHeader",
"(",
"'X-File-Name'",
")",
")",
";",
"$",
"folderNameHeader",
"=",
"str_to_utf8",
"(",
"$",
"this",
"->",
"request",
"->",
"getHeader",
"(",
"'X-Folder-Name'",
")",
")",
";",
"$",
"fileUrl",
"=",
"filter_var",
"(",
"$",
"this",
"->",
"request",
"->",
"getParameter",
"(",
"'url'",
",",
"''",
")",
",",
"FILTER_SANITIZE_URL",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"fileNameHeader",
")",
")",
"{",
"// html5 single posting for file create",
"$",
"result",
"=",
"$",
"this",
"->",
"handleFileContent",
"(",
"$",
"this",
"->",
"folderPath",
",",
"$",
"fileNameHeader",
",",
"$",
"this",
"->",
"request",
"->",
"getContent",
"(",
")",
",",
"$",
"this",
"->",
"request",
"->",
"getContentType",
"(",
")",
",",
"$",
"extract",
",",
"$",
"clean",
",",
"$",
"checkExist",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"folderNameHeader",
")",
")",
"{",
"// html5 single posting for folder create",
"$",
"fullPathName",
"=",
"$",
"this",
"->",
"folderPath",
".",
"$",
"folderNameHeader",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"request",
"->",
"getPayloadData",
"(",
")",
";",
"$",
"this",
"->",
"driver",
"->",
"createFolder",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"fullPathName",
",",
"$",
"content",
")",
";",
"$",
"result",
"=",
"[",
"'name'",
"=>",
"$",
"folderNameHeader",
",",
"'path'",
"=>",
"$",
"fullPathName",
"]",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"fileUrl",
")",
")",
"{",
"// upload a file from a url, could be expandable zip",
"$",
"tmpName",
"=",
"null",
";",
"$",
"newFileName",
"=",
"$",
"this",
"->",
"request",
"->",
"input",
"(",
"'filename'",
",",
"''",
")",
";",
"try",
"{",
"$",
"tmpName",
"=",
"FileUtilities",
"::",
"importUrlFileToTemp",
"(",
"$",
"fileUrl",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"handleFile",
"(",
"$",
"this",
"->",
"folderPath",
",",
"$",
"newFileName",
",",
"$",
"tmpName",
",",
"''",
",",
"$",
"extract",
",",
"$",
"clean",
",",
"$",
"checkExist",
")",
";",
"@",
"unlink",
"(",
"$",
"tmpName",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"tmpName",
")",
")",
"{",
"@",
"unlink",
"(",
"$",
"tmpName",
")",
";",
"}",
"throw",
"$",
"ex",
";",
"}",
"}",
"elseif",
"(",
"null",
"!==",
"$",
"uploadedFiles",
"=",
"$",
"this",
"->",
"request",
"->",
"getFile",
"(",
"'files'",
")",
")",
"{",
"if",
"(",
"Arr",
"::",
"isAssoc",
"(",
"$",
"uploadedFiles",
")",
")",
"{",
"//Single file upload",
"$",
"uploadedFiles",
"=",
"[",
"$",
"uploadedFiles",
"]",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"handleFolderContentFromFiles",
"(",
"$",
"uploadedFiles",
",",
"$",
"extract",
",",
"$",
"clean",
",",
"$",
"checkExist",
")",
";",
"$",
"result",
"=",
"ResourcesWrapper",
"::",
"cleanResources",
"(",
"$",
"result",
")",
";",
"}",
"else",
"{",
"// possibly xml or json post either of files or folders to create, copy or move",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"=",
"ResourcesWrapper",
"::",
"unwrapResources",
"(",
"$",
"this",
"->",
"getPayloadData",
"(",
")",
")",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"handleFolderContentFromData",
"(",
"$",
"data",
",",
"$",
"extract",
",",
"$",
"clean",
",",
"$",
"checkExist",
")",
";",
"$",
"result",
"=",
"ResourcesWrapper",
"::",
"cleanResources",
"(",
"$",
"result",
")",
";",
"}",
"else",
"{",
"// create folder from resource path",
"$",
"this",
"->",
"driver",
"->",
"createFolder",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"this",
"->",
"folderPath",
")",
";",
"$",
"result",
"=",
"[",
"'name'",
"=>",
"basename",
"(",
"$",
"this",
"->",
"folderPath",
")",
",",
"'path'",
"=>",
"$",
"this",
"->",
"folderPath",
"]",
";",
"}",
"}",
"}",
"else",
"{",
"// create the file",
"// possible file handling parameters",
"$",
"name",
"=",
"basename",
"(",
"$",
"this",
"->",
"filePath",
")",
";",
"$",
"path",
"=",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"this",
"->",
"filePath",
",",
"'/'",
")",
")",
"?",
"dirname",
"(",
"$",
"this",
"->",
"filePath",
")",
":",
"''",
";",
"$",
"files",
"=",
"$",
"this",
"->",
"request",
"->",
"getFile",
"(",
"'files'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"files",
")",
")",
"{",
"// direct load from posted data as content",
"// or possibly xml or json post of file properties create, copy or move",
"$",
"result",
"=",
"$",
"this",
"->",
"handleFileContent",
"(",
"$",
"path",
",",
"$",
"name",
",",
"$",
"this",
"->",
"request",
"->",
"getContent",
"(",
")",
",",
"$",
"this",
"->",
"request",
"->",
"getContentType",
"(",
")",
",",
"$",
"extract",
",",
"$",
"clean",
",",
"$",
"checkExist",
")",
";",
"}",
"else",
"{",
"if",
"(",
"Arr",
"::",
"isAssoc",
"(",
"$",
"files",
")",
")",
"{",
"// Single file upload",
"$",
"files",
"=",
"[",
"$",
"files",
"]",
";",
"}",
"if",
"(",
"1",
"<",
"count",
"(",
"$",
"files",
")",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Multiple files uploaded to a single REST resource '$name'.\"",
")",
";",
"}",
"$",
"file",
"=",
"array_get",
"(",
"$",
"files",
",",
"0",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"No file uploaded to REST resource '$name'.\"",
")",
";",
"}",
"$",
"error",
"=",
"$",
"file",
"[",
"'error'",
"]",
";",
"if",
"(",
"UPLOAD_ERR_OK",
"==",
"$",
"error",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"handleFile",
"(",
"$",
"path",
",",
"$",
"name",
",",
"$",
"file",
"[",
"\"tmp_name\"",
"]",
",",
"$",
"file",
"[",
"'type'",
"]",
",",
"$",
"extract",
",",
"$",
"clean",
",",
"$",
"checkExist",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InternalServerErrorException",
"(",
"\"Failed to upload file $name.\\n$error\"",
")",
";",
"}",
"}",
"}",
"return",
"ResponseFactory",
"::",
"create",
"(",
"$",
"result",
",",
"null",
",",
"ServiceResponseInterface",
"::",
"HTTP_CREATED",
")",
";",
"}"
] |
Handles POST actions.
@return \DreamFactory\Core\Utility\ServiceResponse
@throws BadRequestException
@throws InternalServerErrorException
@throws \Exception
|
[
"Handles",
"POST",
"actions",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Services/BaseFileService.php#L447-L562
|
dreamfactorysoftware/df-file
|
src/Services/BaseFileService.php
|
BaseFileService.handlePATCH
|
protected function handlePATCH()
{
$content = $this->getPayloadData();
if (empty($this->folderPath)) {
// update container properties
$this->driver->updateContainerProperties($this->container, $content);
} else {
if (empty($this->filePath)) {
// update folder properties
$this->driver->updateFolderProperties($this->container, $this->folderPath, $content);
} else {
// update file properties?
$this->driver->updateFileProperties($this->container, $this->filePath, $content);
}
}
return ResponseFactory::create(['success' => true]);
}
|
php
|
protected function handlePATCH()
{
$content = $this->getPayloadData();
if (empty($this->folderPath)) {
// update container properties
$this->driver->updateContainerProperties($this->container, $content);
} else {
if (empty($this->filePath)) {
// update folder properties
$this->driver->updateFolderProperties($this->container, $this->folderPath, $content);
} else {
// update file properties?
$this->driver->updateFileProperties($this->container, $this->filePath, $content);
}
}
return ResponseFactory::create(['success' => true]);
}
|
[
"protected",
"function",
"handlePATCH",
"(",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"getPayloadData",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"folderPath",
")",
")",
"{",
"// update container properties",
"$",
"this",
"->",
"driver",
"->",
"updateContainerProperties",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"content",
")",
";",
"}",
"else",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"filePath",
")",
")",
"{",
"// update folder properties",
"$",
"this",
"->",
"driver",
"->",
"updateFolderProperties",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"this",
"->",
"folderPath",
",",
"$",
"content",
")",
";",
"}",
"else",
"{",
"// update file properties?",
"$",
"this",
"->",
"driver",
"->",
"updateFileProperties",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"this",
"->",
"filePath",
",",
"$",
"content",
")",
";",
"}",
"}",
"return",
"ResponseFactory",
"::",
"create",
"(",
"[",
"'success'",
"=>",
"true",
"]",
")",
";",
"}"
] |
Handles PATCH actions.
@return \DreamFactory\Core\Utility\ServiceResponse
|
[
"Handles",
"PATCH",
"actions",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Services/BaseFileService.php#L569-L586
|
dreamfactorysoftware/df-file
|
src/Services/BaseFileService.php
|
BaseFileService.handleDELETE
|
protected function handleDELETE()
{
$force = $this->request->getParameterAsBool('force', false);
$noCheck = $this->request->getParameterAsBool('no_check', false);
$contentOnly = $this->request->getParameterAsBool('content_only', false);
if (empty($this->folderPath)) {
// delete just folders and files from the container
if (!empty($content = ResourcesWrapper::unwrapResources($this->request->getPayloadData()))) {
$result = $this->deleteFolderContent($content, '', $force);
} else {
throw new BadRequestException('No resources given for delete.');
}
} else {
if (empty($this->filePath)) {
// delete directory of files and the directory itself
// multi-file or folder delete via post data
if (!empty($content = ResourcesWrapper::unwrapResources($this->request->getPayloadData()))) {
$result = $this->deleteFolderContent($content, $this->folderPath, $force);
} else {
$this->driver->deleteFolder($this->container, $this->folderPath, $force, $contentOnly);
$result = ['name' => basename($this->folderPath), 'path' => $this->folderPath];
}
} else {
// delete file from permanent storage
$this->driver->deleteFile($this->container, $this->filePath, $noCheck);
$result = ['name' => basename($this->filePath), 'path' => $this->filePath];
}
}
return ResponseFactory::create(ResourcesWrapper::cleanResources($result));
}
|
php
|
protected function handleDELETE()
{
$force = $this->request->getParameterAsBool('force', false);
$noCheck = $this->request->getParameterAsBool('no_check', false);
$contentOnly = $this->request->getParameterAsBool('content_only', false);
if (empty($this->folderPath)) {
// delete just folders and files from the container
if (!empty($content = ResourcesWrapper::unwrapResources($this->request->getPayloadData()))) {
$result = $this->deleteFolderContent($content, '', $force);
} else {
throw new BadRequestException('No resources given for delete.');
}
} else {
if (empty($this->filePath)) {
// delete directory of files and the directory itself
// multi-file or folder delete via post data
if (!empty($content = ResourcesWrapper::unwrapResources($this->request->getPayloadData()))) {
$result = $this->deleteFolderContent($content, $this->folderPath, $force);
} else {
$this->driver->deleteFolder($this->container, $this->folderPath, $force, $contentOnly);
$result = ['name' => basename($this->folderPath), 'path' => $this->folderPath];
}
} else {
// delete file from permanent storage
$this->driver->deleteFile($this->container, $this->filePath, $noCheck);
$result = ['name' => basename($this->filePath), 'path' => $this->filePath];
}
}
return ResponseFactory::create(ResourcesWrapper::cleanResources($result));
}
|
[
"protected",
"function",
"handleDELETE",
"(",
")",
"{",
"$",
"force",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'force'",
",",
"false",
")",
";",
"$",
"noCheck",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'no_check'",
",",
"false",
")",
";",
"$",
"contentOnly",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'content_only'",
",",
"false",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"folderPath",
")",
")",
"{",
"// delete just folders and files from the container",
"if",
"(",
"!",
"empty",
"(",
"$",
"content",
"=",
"ResourcesWrapper",
"::",
"unwrapResources",
"(",
"$",
"this",
"->",
"request",
"->",
"getPayloadData",
"(",
")",
")",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"deleteFolderContent",
"(",
"$",
"content",
",",
"''",
",",
"$",
"force",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"BadRequestException",
"(",
"'No resources given for delete.'",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"filePath",
")",
")",
"{",
"// delete directory of files and the directory itself",
"// multi-file or folder delete via post data",
"if",
"(",
"!",
"empty",
"(",
"$",
"content",
"=",
"ResourcesWrapper",
"::",
"unwrapResources",
"(",
"$",
"this",
"->",
"request",
"->",
"getPayloadData",
"(",
")",
")",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"deleteFolderContent",
"(",
"$",
"content",
",",
"$",
"this",
"->",
"folderPath",
",",
"$",
"force",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"driver",
"->",
"deleteFolder",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"this",
"->",
"folderPath",
",",
"$",
"force",
",",
"$",
"contentOnly",
")",
";",
"$",
"result",
"=",
"[",
"'name'",
"=>",
"basename",
"(",
"$",
"this",
"->",
"folderPath",
")",
",",
"'path'",
"=>",
"$",
"this",
"->",
"folderPath",
"]",
";",
"}",
"}",
"else",
"{",
"// delete file from permanent storage",
"$",
"this",
"->",
"driver",
"->",
"deleteFile",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"this",
"->",
"filePath",
",",
"$",
"noCheck",
")",
";",
"$",
"result",
"=",
"[",
"'name'",
"=>",
"basename",
"(",
"$",
"this",
"->",
"filePath",
")",
",",
"'path'",
"=>",
"$",
"this",
"->",
"filePath",
"]",
";",
"}",
"}",
"return",
"ResponseFactory",
"::",
"create",
"(",
"ResourcesWrapper",
"::",
"cleanResources",
"(",
"$",
"result",
")",
")",
";",
"}"
] |
Handles DELETE actions.
@return \DreamFactory\Core\Utility\ServiceResponse
@throws BadRequestException
|
[
"Handles",
"DELETE",
"actions",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Services/BaseFileService.php#L594-L625
|
dreamfactorysoftware/df-file
|
src/Services/BaseFileService.php
|
BaseFileService.handleFileContent
|
protected function handleFileContent(
$dest_path,
$dest_name,
$content,
$contentType = '',
$extract = false,
$clean = false,
$check_exist = false
){
$ext = FileUtilities::getFileExtension($dest_name);
if (empty($contentType)) {
$contentType = FileUtilities::determineContentType($ext, $content);
}
if ((FileUtilities::isZipContent($contentType) || ('zip' === $ext)) && $extract) {
// need to extract zip file and move contents to storage
$tempDir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$tmpName = $tempDir . $dest_name;
file_put_contents($tmpName, $content);
$zip = new \ZipArchive();
$code = $zip->open($tmpName);
if (true !== $code) {
unlink($tmpName);
throw new InternalServerErrorException('Error opening temporary zip file. code = ' . $code);
}
$results = $this->extractZipFile($dest_path, $zip, $clean);
unlink($tmpName);
return $results;
} else {
$fullPathName = FileUtilities::fixFolderPath($dest_path) . $dest_name;
$this->driver->writeFile($this->container, $fullPathName, $content, false, $check_exist);
return ['name' => $dest_name, 'path' => $fullPathName, 'type' => 'file'];
}
}
|
php
|
protected function handleFileContent(
$dest_path,
$dest_name,
$content,
$contentType = '',
$extract = false,
$clean = false,
$check_exist = false
){
$ext = FileUtilities::getFileExtension($dest_name);
if (empty($contentType)) {
$contentType = FileUtilities::determineContentType($ext, $content);
}
if ((FileUtilities::isZipContent($contentType) || ('zip' === $ext)) && $extract) {
// need to extract zip file and move contents to storage
$tempDir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$tmpName = $tempDir . $dest_name;
file_put_contents($tmpName, $content);
$zip = new \ZipArchive();
$code = $zip->open($tmpName);
if (true !== $code) {
unlink($tmpName);
throw new InternalServerErrorException('Error opening temporary zip file. code = ' . $code);
}
$results = $this->extractZipFile($dest_path, $zip, $clean);
unlink($tmpName);
return $results;
} else {
$fullPathName = FileUtilities::fixFolderPath($dest_path) . $dest_name;
$this->driver->writeFile($this->container, $fullPathName, $content, false, $check_exist);
return ['name' => $dest_name, 'path' => $fullPathName, 'type' => 'file'];
}
}
|
[
"protected",
"function",
"handleFileContent",
"(",
"$",
"dest_path",
",",
"$",
"dest_name",
",",
"$",
"content",
",",
"$",
"contentType",
"=",
"''",
",",
"$",
"extract",
"=",
"false",
",",
"$",
"clean",
"=",
"false",
",",
"$",
"check_exist",
"=",
"false",
")",
"{",
"$",
"ext",
"=",
"FileUtilities",
"::",
"getFileExtension",
"(",
"$",
"dest_name",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"contentType",
")",
")",
"{",
"$",
"contentType",
"=",
"FileUtilities",
"::",
"determineContentType",
"(",
"$",
"ext",
",",
"$",
"content",
")",
";",
"}",
"if",
"(",
"(",
"FileUtilities",
"::",
"isZipContent",
"(",
"$",
"contentType",
")",
"||",
"(",
"'zip'",
"===",
"$",
"ext",
")",
")",
"&&",
"$",
"extract",
")",
"{",
"// need to extract zip file and move contents to storage",
"$",
"tempDir",
"=",
"rtrim",
"(",
"sys_get_temp_dir",
"(",
")",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"$",
"tmpName",
"=",
"$",
"tempDir",
".",
"$",
"dest_name",
";",
"file_put_contents",
"(",
"$",
"tmpName",
",",
"$",
"content",
")",
";",
"$",
"zip",
"=",
"new",
"\\",
"ZipArchive",
"(",
")",
";",
"$",
"code",
"=",
"$",
"zip",
"->",
"open",
"(",
"$",
"tmpName",
")",
";",
"if",
"(",
"true",
"!==",
"$",
"code",
")",
"{",
"unlink",
"(",
"$",
"tmpName",
")",
";",
"throw",
"new",
"InternalServerErrorException",
"(",
"'Error opening temporary zip file. code = '",
".",
"$",
"code",
")",
";",
"}",
"$",
"results",
"=",
"$",
"this",
"->",
"extractZipFile",
"(",
"$",
"dest_path",
",",
"$",
"zip",
",",
"$",
"clean",
")",
";",
"unlink",
"(",
"$",
"tmpName",
")",
";",
"return",
"$",
"results",
";",
"}",
"else",
"{",
"$",
"fullPathName",
"=",
"FileUtilities",
"::",
"fixFolderPath",
"(",
"$",
"dest_path",
")",
".",
"$",
"dest_name",
";",
"$",
"this",
"->",
"driver",
"->",
"writeFile",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"fullPathName",
",",
"$",
"content",
",",
"false",
",",
"$",
"check_exist",
")",
";",
"return",
"[",
"'name'",
"=>",
"$",
"dest_name",
",",
"'path'",
"=>",
"$",
"fullPathName",
",",
"'type'",
"=>",
"'file'",
"]",
";",
"}",
"}"
] |
@param $dest_path
@param $dest_name
@param $content
@param string $contentType
@param bool $extract
@param bool $clean
@param bool $check_exist
@throws \Exception
@return array
|
[
"@param",
"$dest_path",
"@param",
"$dest_name",
"@param",
"$content",
"@param",
"string",
"$contentType",
"@param",
"bool",
"$extract",
"@param",
"bool",
"$clean",
"@param",
"bool",
"$check_exist"
] |
train
|
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Services/BaseFileService.php#L652-L688
|
dreamfactorysoftware/df-file
|
src/Services/BaseFileService.php
|
BaseFileService.handleFile
|
protected function handleFile(
$dest_path,
$dest_name,
$source_file,
$contentType = '',
$extract = false,
$clean = false,
$check_exist = false
){
$ext = FileUtilities::getFileExtension($source_file);
if (empty($contentType)) {
$contentType = FileUtilities::determineContentType($ext, '', $source_file);
}
if ((FileUtilities::isZipContent($contentType) || ('zip' === $ext)) && $extract) {
// need to extract zip file and move contents to storage
$zip = new \ZipArchive();
if (true === $zip->open($source_file)) {
return $this->extractZipFile($dest_path, $zip, $clean);
} else {
throw new InternalServerErrorException('Error opening temporary zip file.');
}
} else {
$name = (empty($dest_name) ? basename($source_file) : $dest_name);
$fullPathName = FileUtilities::fixFolderPath($dest_path) . $name;
$this->driver->moveFile($this->container, $fullPathName, $source_file, $check_exist);
return ['name' => $name, 'path' => $fullPathName, 'type' => 'file'];
}
}
|
php
|
protected function handleFile(
$dest_path,
$dest_name,
$source_file,
$contentType = '',
$extract = false,
$clean = false,
$check_exist = false
){
$ext = FileUtilities::getFileExtension($source_file);
if (empty($contentType)) {
$contentType = FileUtilities::determineContentType($ext, '', $source_file);
}
if ((FileUtilities::isZipContent($contentType) || ('zip' === $ext)) && $extract) {
// need to extract zip file and move contents to storage
$zip = new \ZipArchive();
if (true === $zip->open($source_file)) {
return $this->extractZipFile($dest_path, $zip, $clean);
} else {
throw new InternalServerErrorException('Error opening temporary zip file.');
}
} else {
$name = (empty($dest_name) ? basename($source_file) : $dest_name);
$fullPathName = FileUtilities::fixFolderPath($dest_path) . $name;
$this->driver->moveFile($this->container, $fullPathName, $source_file, $check_exist);
return ['name' => $name, 'path' => $fullPathName, 'type' => 'file'];
}
}
|
[
"protected",
"function",
"handleFile",
"(",
"$",
"dest_path",
",",
"$",
"dest_name",
",",
"$",
"source_file",
",",
"$",
"contentType",
"=",
"''",
",",
"$",
"extract",
"=",
"false",
",",
"$",
"clean",
"=",
"false",
",",
"$",
"check_exist",
"=",
"false",
")",
"{",
"$",
"ext",
"=",
"FileUtilities",
"::",
"getFileExtension",
"(",
"$",
"source_file",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"contentType",
")",
")",
"{",
"$",
"contentType",
"=",
"FileUtilities",
"::",
"determineContentType",
"(",
"$",
"ext",
",",
"''",
",",
"$",
"source_file",
")",
";",
"}",
"if",
"(",
"(",
"FileUtilities",
"::",
"isZipContent",
"(",
"$",
"contentType",
")",
"||",
"(",
"'zip'",
"===",
"$",
"ext",
")",
")",
"&&",
"$",
"extract",
")",
"{",
"// need to extract zip file and move contents to storage",
"$",
"zip",
"=",
"new",
"\\",
"ZipArchive",
"(",
")",
";",
"if",
"(",
"true",
"===",
"$",
"zip",
"->",
"open",
"(",
"$",
"source_file",
")",
")",
"{",
"return",
"$",
"this",
"->",
"extractZipFile",
"(",
"$",
"dest_path",
",",
"$",
"zip",
",",
"$",
"clean",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InternalServerErrorException",
"(",
"'Error opening temporary zip file.'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"name",
"=",
"(",
"empty",
"(",
"$",
"dest_name",
")",
"?",
"basename",
"(",
"$",
"source_file",
")",
":",
"$",
"dest_name",
")",
";",
"$",
"fullPathName",
"=",
"FileUtilities",
"::",
"fixFolderPath",
"(",
"$",
"dest_path",
")",
".",
"$",
"name",
";",
"$",
"this",
"->",
"driver",
"->",
"moveFile",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"fullPathName",
",",
"$",
"source_file",
",",
"$",
"check_exist",
")",
";",
"return",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'path'",
"=>",
"$",
"fullPathName",
",",
"'type'",
"=>",
"'file'",
"]",
";",
"}",
"}"
] |
@param $dest_path
@param $dest_name
@param $source_file
@param string $contentType
@param bool $extract
@param bool $clean
@param bool $check_exist
@throws \Exception
@return array
|
[
"@param",
"$dest_path",
"@param",
"$dest_name",
"@param",
"$source_file",
"@param",
"string",
"$contentType",
"@param",
"bool",
"$extract",
"@param",
"bool",
"$clean",
"@param",
"bool",
"$check_exist"
] |
train
|
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Services/BaseFileService.php#L702-L730
|
dreamfactorysoftware/df-file
|
src/Services/BaseFileService.php
|
BaseFileService.handleFolderContentFromFiles
|
protected function handleFolderContentFromFiles($files, $extract = false, $clean = false, $checkExist = false)
{
$out = [];
$err = [];
foreach ($files as $key => $file) {
$name = $file['name'];
$error = $file['error'];
if ($error == UPLOAD_ERR_OK) {
$tmpName = $file['tmp_name'];
// Get file's content type
$contentType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $tmpName);
if (empty($contentType)) {
// It is not safe to use content-type set by client.
// Therefore, only using content-type from client as a fallback.
$contentType = $file['type'];
}
$tmp = $this->handleFile(
$this->folderPath,
$name,
$tmpName,
$contentType,
$extract,
$clean,
$checkExist
);
$out[$key] = $tmp;
} else {
$err[] = $name;
}
}
if (!empty($err)) {
$msg = 'Failed to upload the following files to folder ' . $this->folderPath . ': ' . implode(', ', $err);
throw new InternalServerErrorException($msg);
}
return $out;
}
|
php
|
protected function handleFolderContentFromFiles($files, $extract = false, $clean = false, $checkExist = false)
{
$out = [];
$err = [];
foreach ($files as $key => $file) {
$name = $file['name'];
$error = $file['error'];
if ($error == UPLOAD_ERR_OK) {
$tmpName = $file['tmp_name'];
// Get file's content type
$contentType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $tmpName);
if (empty($contentType)) {
// It is not safe to use content-type set by client.
// Therefore, only using content-type from client as a fallback.
$contentType = $file['type'];
}
$tmp = $this->handleFile(
$this->folderPath,
$name,
$tmpName,
$contentType,
$extract,
$clean,
$checkExist
);
$out[$key] = $tmp;
} else {
$err[] = $name;
}
}
if (!empty($err)) {
$msg = 'Failed to upload the following files to folder ' . $this->folderPath . ': ' . implode(', ', $err);
throw new InternalServerErrorException($msg);
}
return $out;
}
|
[
"protected",
"function",
"handleFolderContentFromFiles",
"(",
"$",
"files",
",",
"$",
"extract",
"=",
"false",
",",
"$",
"clean",
"=",
"false",
",",
"$",
"checkExist",
"=",
"false",
")",
"{",
"$",
"out",
"=",
"[",
"]",
";",
"$",
"err",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"key",
"=>",
"$",
"file",
")",
"{",
"$",
"name",
"=",
"$",
"file",
"[",
"'name'",
"]",
";",
"$",
"error",
"=",
"$",
"file",
"[",
"'error'",
"]",
";",
"if",
"(",
"$",
"error",
"==",
"UPLOAD_ERR_OK",
")",
"{",
"$",
"tmpName",
"=",
"$",
"file",
"[",
"'tmp_name'",
"]",
";",
"// Get file's content type",
"$",
"contentType",
"=",
"finfo_file",
"(",
"finfo_open",
"(",
"FILEINFO_MIME_TYPE",
")",
",",
"$",
"tmpName",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"contentType",
")",
")",
"{",
"// It is not safe to use content-type set by client.",
"// Therefore, only using content-type from client as a fallback.",
"$",
"contentType",
"=",
"$",
"file",
"[",
"'type'",
"]",
";",
"}",
"$",
"tmp",
"=",
"$",
"this",
"->",
"handleFile",
"(",
"$",
"this",
"->",
"folderPath",
",",
"$",
"name",
",",
"$",
"tmpName",
",",
"$",
"contentType",
",",
"$",
"extract",
",",
"$",
"clean",
",",
"$",
"checkExist",
")",
";",
"$",
"out",
"[",
"$",
"key",
"]",
"=",
"$",
"tmp",
";",
"}",
"else",
"{",
"$",
"err",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"err",
")",
")",
"{",
"$",
"msg",
"=",
"'Failed to upload the following files to folder '",
".",
"$",
"this",
"->",
"folderPath",
".",
"': '",
".",
"implode",
"(",
"', '",
",",
"$",
"err",
")",
";",
"throw",
"new",
"InternalServerErrorException",
"(",
"$",
"msg",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] |
@param array $files
@param bool $extract
@param bool $clean
@param bool $checkExist
@return array
@throws \Exception
|
[
"@param",
"array",
"$files",
"@param",
"bool",
"$extract",
"@param",
"bool",
"$clean",
"@param",
"bool",
"$checkExist"
] |
train
|
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Services/BaseFileService.php#L741-L779
|
dreamfactorysoftware/df-file
|
src/Services/BaseFileService.php
|
BaseFileService.handleFolderContentFromData
|
protected function handleFolderContentFromData(
$data,
/** @noinspection PhpUnusedParameterInspection */
$extract = false,
/** @noinspection PhpUnusedParameterInspection */
$clean = false,
/** @noinspection PhpUnusedParameterInspection */
$checkExist = false
){
$out = [];
if (!empty($data) && !Arr::isAssoc($data)) {
foreach ($data as $key => $resource) {
switch (array_get($resource, 'type')) {
case 'folder':
$name = array_get($resource, 'name', '');
$srcPath = array_get($resource, 'source_path');
if (!empty($srcPath)) {
$srcContainer = array_get($resource, 'source_container', $this->container);
// copy or move
if (empty($name)) {
$name = FileUtilities::getNameFromPath($srcPath);
}
$fullPathName = $this->folderPath . $name . '/';
$out[$key] = ['name' => $name, 'path' => $fullPathName, 'type' => 'folder'];
try {
$this->driver->copyFolder($this->container, $fullPathName, $srcContainer, $srcPath,
true);
$deleteSource = array_get_bool($resource, 'delete_source');
if ($deleteSource) {
$this->driver->deleteFolder($this->container, $srcPath, true);
}
} catch (\Exception $ex) {
$out[$key]['error'] = ['message' => $ex->getMessage()];
}
} else {
$fullPathName = $this->folderPath . $name . '/';
$content = array_get($resource, 'content', '');
$isBase64 = array_get_bool($resource, 'is_base64');
if ($isBase64) {
$content = base64_decode($content);
}
$out[$key] = ['name' => $name, 'path' => $fullPathName, 'type' => 'folder'];
try {
$this->driver->createFolder($this->container, $fullPathName, $content);
} catch (\Exception $ex) {
$out[$key]['error'] = ['message' => $ex->getMessage()];
}
}
break;
case 'file':
$name = array_get($resource, 'name', '');
$srcPath = array_get($resource, 'source_path');
if (!empty($srcPath)) {
// copy or move
$srcContainer = array_get($resource, 'source_container', $this->container);
if (empty($name)) {
$name = FileUtilities::getNameFromPath($srcPath);
}
$fullPathName = $this->folderPath . $name;
$out[$key] = ['name' => $name, 'path' => $fullPathName, 'type' => 'file'];
try {
$this->driver->copyFile($this->container, $fullPathName, $srcContainer, $srcPath, true);
$deleteSource = array_get_bool($resource, 'delete_source');
if ($deleteSource) {
$this->driver->deleteFile($this->container, $srcPath);
}
} catch (\Exception $ex) {
$out[$key]['error'] = ['message' => $ex->getMessage()];
}
} elseif (isset($resource['content'])) {
$fullPathName = $this->folderPath . $name;
$out[$key] = ['name' => $name, 'path' => $fullPathName, 'type' => 'file'];
$content = array_get($resource, 'content', '');
$isBase64 = array_get_bool($resource, 'is_base64');
if ($isBase64) {
$content = base64_decode($content);
}
try {
$this->driver->writeFile($this->container, $fullPathName, $content);
} catch (\Exception $ex) {
$out[$key]['error'] = ['message' => $ex->getMessage()];
}
}
break;
}
}
}
return $out;
}
|
php
|
protected function handleFolderContentFromData(
$data,
/** @noinspection PhpUnusedParameterInspection */
$extract = false,
/** @noinspection PhpUnusedParameterInspection */
$clean = false,
/** @noinspection PhpUnusedParameterInspection */
$checkExist = false
){
$out = [];
if (!empty($data) && !Arr::isAssoc($data)) {
foreach ($data as $key => $resource) {
switch (array_get($resource, 'type')) {
case 'folder':
$name = array_get($resource, 'name', '');
$srcPath = array_get($resource, 'source_path');
if (!empty($srcPath)) {
$srcContainer = array_get($resource, 'source_container', $this->container);
// copy or move
if (empty($name)) {
$name = FileUtilities::getNameFromPath($srcPath);
}
$fullPathName = $this->folderPath . $name . '/';
$out[$key] = ['name' => $name, 'path' => $fullPathName, 'type' => 'folder'];
try {
$this->driver->copyFolder($this->container, $fullPathName, $srcContainer, $srcPath,
true);
$deleteSource = array_get_bool($resource, 'delete_source');
if ($deleteSource) {
$this->driver->deleteFolder($this->container, $srcPath, true);
}
} catch (\Exception $ex) {
$out[$key]['error'] = ['message' => $ex->getMessage()];
}
} else {
$fullPathName = $this->folderPath . $name . '/';
$content = array_get($resource, 'content', '');
$isBase64 = array_get_bool($resource, 'is_base64');
if ($isBase64) {
$content = base64_decode($content);
}
$out[$key] = ['name' => $name, 'path' => $fullPathName, 'type' => 'folder'];
try {
$this->driver->createFolder($this->container, $fullPathName, $content);
} catch (\Exception $ex) {
$out[$key]['error'] = ['message' => $ex->getMessage()];
}
}
break;
case 'file':
$name = array_get($resource, 'name', '');
$srcPath = array_get($resource, 'source_path');
if (!empty($srcPath)) {
// copy or move
$srcContainer = array_get($resource, 'source_container', $this->container);
if (empty($name)) {
$name = FileUtilities::getNameFromPath($srcPath);
}
$fullPathName = $this->folderPath . $name;
$out[$key] = ['name' => $name, 'path' => $fullPathName, 'type' => 'file'];
try {
$this->driver->copyFile($this->container, $fullPathName, $srcContainer, $srcPath, true);
$deleteSource = array_get_bool($resource, 'delete_source');
if ($deleteSource) {
$this->driver->deleteFile($this->container, $srcPath);
}
} catch (\Exception $ex) {
$out[$key]['error'] = ['message' => $ex->getMessage()];
}
} elseif (isset($resource['content'])) {
$fullPathName = $this->folderPath . $name;
$out[$key] = ['name' => $name, 'path' => $fullPathName, 'type' => 'file'];
$content = array_get($resource, 'content', '');
$isBase64 = array_get_bool($resource, 'is_base64');
if ($isBase64) {
$content = base64_decode($content);
}
try {
$this->driver->writeFile($this->container, $fullPathName, $content);
} catch (\Exception $ex) {
$out[$key]['error'] = ['message' => $ex->getMessage()];
}
}
break;
}
}
}
return $out;
}
|
[
"protected",
"function",
"handleFolderContentFromData",
"(",
"$",
"data",
",",
"/** @noinspection PhpUnusedParameterInspection */",
"$",
"extract",
"=",
"false",
",",
"/** @noinspection PhpUnusedParameterInspection */",
"$",
"clean",
"=",
"false",
",",
"/** @noinspection PhpUnusedParameterInspection */",
"$",
"checkExist",
"=",
"false",
")",
"{",
"$",
"out",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
"&&",
"!",
"Arr",
"::",
"isAssoc",
"(",
"$",
"data",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"resource",
")",
"{",
"switch",
"(",
"array_get",
"(",
"$",
"resource",
",",
"'type'",
")",
")",
"{",
"case",
"'folder'",
":",
"$",
"name",
"=",
"array_get",
"(",
"$",
"resource",
",",
"'name'",
",",
"''",
")",
";",
"$",
"srcPath",
"=",
"array_get",
"(",
"$",
"resource",
",",
"'source_path'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"srcPath",
")",
")",
"{",
"$",
"srcContainer",
"=",
"array_get",
"(",
"$",
"resource",
",",
"'source_container'",
",",
"$",
"this",
"->",
"container",
")",
";",
"// copy or move",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"FileUtilities",
"::",
"getNameFromPath",
"(",
"$",
"srcPath",
")",
";",
"}",
"$",
"fullPathName",
"=",
"$",
"this",
"->",
"folderPath",
".",
"$",
"name",
".",
"'/'",
";",
"$",
"out",
"[",
"$",
"key",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'path'",
"=>",
"$",
"fullPathName",
",",
"'type'",
"=>",
"'folder'",
"]",
";",
"try",
"{",
"$",
"this",
"->",
"driver",
"->",
"copyFolder",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"fullPathName",
",",
"$",
"srcContainer",
",",
"$",
"srcPath",
",",
"true",
")",
";",
"$",
"deleteSource",
"=",
"array_get_bool",
"(",
"$",
"resource",
",",
"'delete_source'",
")",
";",
"if",
"(",
"$",
"deleteSource",
")",
"{",
"$",
"this",
"->",
"driver",
"->",
"deleteFolder",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"srcPath",
",",
"true",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"out",
"[",
"$",
"key",
"]",
"[",
"'error'",
"]",
"=",
"[",
"'message'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"fullPathName",
"=",
"$",
"this",
"->",
"folderPath",
".",
"$",
"name",
".",
"'/'",
";",
"$",
"content",
"=",
"array_get",
"(",
"$",
"resource",
",",
"'content'",
",",
"''",
")",
";",
"$",
"isBase64",
"=",
"array_get_bool",
"(",
"$",
"resource",
",",
"'is_base64'",
")",
";",
"if",
"(",
"$",
"isBase64",
")",
"{",
"$",
"content",
"=",
"base64_decode",
"(",
"$",
"content",
")",
";",
"}",
"$",
"out",
"[",
"$",
"key",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'path'",
"=>",
"$",
"fullPathName",
",",
"'type'",
"=>",
"'folder'",
"]",
";",
"try",
"{",
"$",
"this",
"->",
"driver",
"->",
"createFolder",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"fullPathName",
",",
"$",
"content",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"out",
"[",
"$",
"key",
"]",
"[",
"'error'",
"]",
"=",
"[",
"'message'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
"]",
";",
"}",
"}",
"break",
";",
"case",
"'file'",
":",
"$",
"name",
"=",
"array_get",
"(",
"$",
"resource",
",",
"'name'",
",",
"''",
")",
";",
"$",
"srcPath",
"=",
"array_get",
"(",
"$",
"resource",
",",
"'source_path'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"srcPath",
")",
")",
"{",
"// copy or move",
"$",
"srcContainer",
"=",
"array_get",
"(",
"$",
"resource",
",",
"'source_container'",
",",
"$",
"this",
"->",
"container",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"FileUtilities",
"::",
"getNameFromPath",
"(",
"$",
"srcPath",
")",
";",
"}",
"$",
"fullPathName",
"=",
"$",
"this",
"->",
"folderPath",
".",
"$",
"name",
";",
"$",
"out",
"[",
"$",
"key",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'path'",
"=>",
"$",
"fullPathName",
",",
"'type'",
"=>",
"'file'",
"]",
";",
"try",
"{",
"$",
"this",
"->",
"driver",
"->",
"copyFile",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"fullPathName",
",",
"$",
"srcContainer",
",",
"$",
"srcPath",
",",
"true",
")",
";",
"$",
"deleteSource",
"=",
"array_get_bool",
"(",
"$",
"resource",
",",
"'delete_source'",
")",
";",
"if",
"(",
"$",
"deleteSource",
")",
"{",
"$",
"this",
"->",
"driver",
"->",
"deleteFile",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"srcPath",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"out",
"[",
"$",
"key",
"]",
"[",
"'error'",
"]",
"=",
"[",
"'message'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
"]",
";",
"}",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"resource",
"[",
"'content'",
"]",
")",
")",
"{",
"$",
"fullPathName",
"=",
"$",
"this",
"->",
"folderPath",
".",
"$",
"name",
";",
"$",
"out",
"[",
"$",
"key",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'path'",
"=>",
"$",
"fullPathName",
",",
"'type'",
"=>",
"'file'",
"]",
";",
"$",
"content",
"=",
"array_get",
"(",
"$",
"resource",
",",
"'content'",
",",
"''",
")",
";",
"$",
"isBase64",
"=",
"array_get_bool",
"(",
"$",
"resource",
",",
"'is_base64'",
")",
";",
"if",
"(",
"$",
"isBase64",
")",
"{",
"$",
"content",
"=",
"base64_decode",
"(",
"$",
"content",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"driver",
"->",
"writeFile",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"fullPathName",
",",
"$",
"content",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"out",
"[",
"$",
"key",
"]",
"[",
"'error'",
"]",
"=",
"[",
"'message'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
"]",
";",
"}",
"}",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"out",
";",
"}"
] |
@param array $data
@param bool $extract
@param bool $clean
@param bool $checkExist
@return array
|
[
"@param",
"array",
"$data",
"@param",
"bool",
"$extract",
"@param",
"bool",
"$clean",
"@param",
"bool",
"$checkExist"
] |
train
|
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Services/BaseFileService.php#L789-L878
|
dreamfactorysoftware/df-file
|
src/Services/BaseFileService.php
|
BaseFileService.deleteFolderContent
|
protected function deleteFolderContent($data, $root = '', $force = false)
{
$root = FileUtilities::fixFolderPath($root);
$out = [];
if (!empty($data)) {
foreach ($data as $key => $resource) {
$path = array_get($resource, 'path');
$name = array_get($resource, 'name');
if (!empty($path)) {
$fullPath = $path;
} else {
if (!empty($name)) {
$fullPath = $root . '/' . $name;
} else {
throw new BadRequestException('No path or name provided for resource.');
}
}
switch (array_get($resource, 'type')) {
case 'file':
$out[$key] = ['name' => $name, 'path' => $path, 'type' => 'file'];
try {
$this->driver->deleteFile($this->container, $fullPath);
} catch (\Exception $ex) {
$out[$key]['error'] = ['message' => $ex->getMessage()];
}
break;
case 'folder':
$out[$key] = ['name' => $name, 'path' => $path, 'type' => 'folder'];
try {
$this->driver->deleteFolder($this->container, $fullPath, $force);
} catch (\Exception $ex) {
$out[$key]['error'] = ['message' => $ex->getMessage()];
}
break;
}
}
}
return $out;
}
|
php
|
protected function deleteFolderContent($data, $root = '', $force = false)
{
$root = FileUtilities::fixFolderPath($root);
$out = [];
if (!empty($data)) {
foreach ($data as $key => $resource) {
$path = array_get($resource, 'path');
$name = array_get($resource, 'name');
if (!empty($path)) {
$fullPath = $path;
} else {
if (!empty($name)) {
$fullPath = $root . '/' . $name;
} else {
throw new BadRequestException('No path or name provided for resource.');
}
}
switch (array_get($resource, 'type')) {
case 'file':
$out[$key] = ['name' => $name, 'path' => $path, 'type' => 'file'];
try {
$this->driver->deleteFile($this->container, $fullPath);
} catch (\Exception $ex) {
$out[$key]['error'] = ['message' => $ex->getMessage()];
}
break;
case 'folder':
$out[$key] = ['name' => $name, 'path' => $path, 'type' => 'folder'];
try {
$this->driver->deleteFolder($this->container, $fullPath, $force);
} catch (\Exception $ex) {
$out[$key]['error'] = ['message' => $ex->getMessage()];
}
break;
}
}
}
return $out;
}
|
[
"protected",
"function",
"deleteFolderContent",
"(",
"$",
"data",
",",
"$",
"root",
"=",
"''",
",",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"root",
"=",
"FileUtilities",
"::",
"fixFolderPath",
"(",
"$",
"root",
")",
";",
"$",
"out",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"resource",
")",
"{",
"$",
"path",
"=",
"array_get",
"(",
"$",
"resource",
",",
"'path'",
")",
";",
"$",
"name",
"=",
"array_get",
"(",
"$",
"resource",
",",
"'name'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"$",
"fullPath",
"=",
"$",
"path",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"fullPath",
"=",
"$",
"root",
".",
"'/'",
".",
"$",
"name",
";",
"}",
"else",
"{",
"throw",
"new",
"BadRequestException",
"(",
"'No path or name provided for resource.'",
")",
";",
"}",
"}",
"switch",
"(",
"array_get",
"(",
"$",
"resource",
",",
"'type'",
")",
")",
"{",
"case",
"'file'",
":",
"$",
"out",
"[",
"$",
"key",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'path'",
"=>",
"$",
"path",
",",
"'type'",
"=>",
"'file'",
"]",
";",
"try",
"{",
"$",
"this",
"->",
"driver",
"->",
"deleteFile",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"fullPath",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"out",
"[",
"$",
"key",
"]",
"[",
"'error'",
"]",
"=",
"[",
"'message'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
"]",
";",
"}",
"break",
";",
"case",
"'folder'",
":",
"$",
"out",
"[",
"$",
"key",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'path'",
"=>",
"$",
"path",
",",
"'type'",
"=>",
"'folder'",
"]",
";",
"try",
"{",
"$",
"this",
"->",
"driver",
"->",
"deleteFolder",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"fullPath",
",",
"$",
"force",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"out",
"[",
"$",
"key",
"]",
"[",
"'error'",
"]",
"=",
"[",
"'message'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
"]",
";",
"}",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"out",
";",
"}"
] |
@param array $data Array of sub-folder and file paths that are relative to the root folder
@param string $root root folder from which to delete
@param bool $force
@return array
@throws \DreamFactory\Core\Exceptions\BadRequestException
|
[
"@param",
"array",
"$data",
"Array",
"of",
"sub",
"-",
"folder",
"and",
"file",
"paths",
"that",
"are",
"relative",
"to",
"the",
"root",
"folder",
"@param",
"string",
"$root",
"root",
"folder",
"from",
"which",
"to",
"delete",
"@param",
"bool",
"$force"
] |
train
|
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Services/BaseFileService.php#L888-L929
|
yuncms/framework
|
src/rest/models/UserSettingsForm.php
|
UserSettingsForm.validatePassword
|
public function validatePassword($attribute)
{
if (!$this->hasErrors()) {
if ($this->user === null || !PasswordHelper::validate($this->password, $this->user->password_hash)) {
$this->addError($attribute, Yii::t('yuncms', 'Invalid login or password'));
}
}
}
|
php
|
public function validatePassword($attribute)
{
if (!$this->hasErrors()) {
if ($this->user === null || !PasswordHelper::validate($this->password, $this->user->password_hash)) {
$this->addError($attribute, Yii::t('yuncms', 'Invalid login or password'));
}
}
}
|
[
"public",
"function",
"validatePassword",
"(",
"$",
"attribute",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasErrors",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"===",
"null",
"||",
"!",
"PasswordHelper",
"::",
"validate",
"(",
"$",
"this",
"->",
"password",
",",
"$",
"this",
"->",
"user",
"->",
"password_hash",
")",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"$",
"attribute",
",",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Invalid login or password'",
")",
")",
";",
"}",
"}",
"}"
] |
Validates the password.
This method serves as the inline validation for password.
@param string $attribute the attribute currently being validated
|
[
"Validates",
"the",
"password",
".",
"This",
"method",
"serves",
"as",
"the",
"inline",
"validation",
"for",
"password",
"."
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/models/UserSettingsForm.php#L63-L70
|
yuncms/framework
|
src/rest/models/UserSettingsForm.php
|
UserSettingsForm.save
|
public function save()
{
if ($this->validate()) {
$this->user->scenario = User::SCENARIO_PASSWORD;
$this->user->password = $this->new_password;
return $this->user->save();
}
return false;
}
|
php
|
public function save()
{
if ($this->validate()) {
$this->user->scenario = User::SCENARIO_PASSWORD;
$this->user->password = $this->new_password;
return $this->user->save();
}
return false;
}
|
[
"public",
"function",
"save",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"validate",
"(",
")",
")",
"{",
"$",
"this",
"->",
"user",
"->",
"scenario",
"=",
"User",
"::",
"SCENARIO_PASSWORD",
";",
"$",
"this",
"->",
"user",
"->",
"password",
"=",
"$",
"this",
"->",
"new_password",
";",
"return",
"$",
"this",
"->",
"user",
"->",
"save",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Saves new account settings.
@return boolean
|
[
"Saves",
"new",
"account",
"settings",
"."
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/models/UserSettingsForm.php#L88-L96
|
slashworks/control-bundle
|
src/Slashworks/BackendBundle/Helper/InstallHelper.php
|
InstallHelper.doInstall
|
public static function doInstall(&$oContainer, &$aData)
{
// init class vars
self::_init($oContainer, $aData);
// check provided database credentials
if (self::_checkDatabaseCredentials()) {
// write symfony's parameters.yml
self::_saveSystemConfig();
// insert default database dump
self::_insertDump();
// create admin user
self::_createAdminUser();
// insert control-url to settgins-db
self::_saveControlUrl();
// reset the assetic configs
self::resetAsseticConfig();
//create keys
self::createKeys();
// clears caches and dumps assets
self::clearCache();
} else {
throw new \Exception(self::$_container->get("translator")->trans("install.bad_database_credentials"));
}
}
|
php
|
public static function doInstall(&$oContainer, &$aData)
{
// init class vars
self::_init($oContainer, $aData);
// check provided database credentials
if (self::_checkDatabaseCredentials()) {
// write symfony's parameters.yml
self::_saveSystemConfig();
// insert default database dump
self::_insertDump();
// create admin user
self::_createAdminUser();
// insert control-url to settgins-db
self::_saveControlUrl();
// reset the assetic configs
self::resetAsseticConfig();
//create keys
self::createKeys();
// clears caches and dumps assets
self::clearCache();
} else {
throw new \Exception(self::$_container->get("translator")->trans("install.bad_database_credentials"));
}
}
|
[
"public",
"static",
"function",
"doInstall",
"(",
"&",
"$",
"oContainer",
",",
"&",
"$",
"aData",
")",
"{",
"// init class vars",
"self",
"::",
"_init",
"(",
"$",
"oContainer",
",",
"$",
"aData",
")",
";",
"// check provided database credentials",
"if",
"(",
"self",
"::",
"_checkDatabaseCredentials",
"(",
")",
")",
"{",
"// write symfony's parameters.yml",
"self",
"::",
"_saveSystemConfig",
"(",
")",
";",
"// insert default database dump",
"self",
"::",
"_insertDump",
"(",
")",
";",
"// create admin user",
"self",
"::",
"_createAdminUser",
"(",
")",
";",
"// insert control-url to settgins-db",
"self",
"::",
"_saveControlUrl",
"(",
")",
";",
"// reset the assetic configs",
"self",
"::",
"resetAsseticConfig",
"(",
")",
";",
"//create keys",
"self",
"::",
"createKeys",
"(",
")",
";",
"// clears caches and dumps assets",
"self",
"::",
"clearCache",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"self",
"::",
"$",
"_container",
"->",
"get",
"(",
"\"translator\"",
")",
"->",
"trans",
"(",
"\"install.bad_database_credentials\"",
")",
")",
";",
"}",
"}"
] |
@param $oContainer
@param $aData
@throws \Exception
|
[
"@param",
"$oContainer",
"@param",
"$aData"
] |
train
|
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Helper/InstallHelper.php#L45-L78
|
slashworks/control-bundle
|
src/Slashworks/BackendBundle/Helper/InstallHelper.php
|
InstallHelper.resetAsseticConfig
|
private static function resetAsseticConfig()
{
return;
/**
* dev
*/
$aYaml = Yaml::parse(file_get_contents(self::$_container->get('kernel')->getRootDir() . '/config/config_dev.yml'));
$aYaml['assetic']['use_controller'] = false;
$sNewYaml = Yaml::dump($aYaml, 5);
file_put_contents(self::$_container->get('kernel')->getRootDir() . '/config/config_dev.yml', $sNewYaml);
/**
* prod
*/
$aYaml = Yaml::parse(file_get_contents(self::$_container->get('kernel')->getRootDir() . '/config/config_prod.yml'));
$aYaml['assetic']['use_controller'] = false;
$sNewYaml = Yaml::dump($aYaml, 5);
file_put_contents(self::$_container->get('kernel')->getRootDir() . '/config/config_prod.yml', $sNewYaml);
}
|
php
|
private static function resetAsseticConfig()
{
return;
/**
* dev
*/
$aYaml = Yaml::parse(file_get_contents(self::$_container->get('kernel')->getRootDir() . '/config/config_dev.yml'));
$aYaml['assetic']['use_controller'] = false;
$sNewYaml = Yaml::dump($aYaml, 5);
file_put_contents(self::$_container->get('kernel')->getRootDir() . '/config/config_dev.yml', $sNewYaml);
/**
* prod
*/
$aYaml = Yaml::parse(file_get_contents(self::$_container->get('kernel')->getRootDir() . '/config/config_prod.yml'));
$aYaml['assetic']['use_controller'] = false;
$sNewYaml = Yaml::dump($aYaml, 5);
file_put_contents(self::$_container->get('kernel')->getRootDir() . '/config/config_prod.yml', $sNewYaml);
}
|
[
"private",
"static",
"function",
"resetAsseticConfig",
"(",
")",
"{",
"return",
";",
"/**\n * dev\n */",
"$",
"aYaml",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"self",
"::",
"$",
"_container",
"->",
"get",
"(",
"'kernel'",
")",
"->",
"getRootDir",
"(",
")",
".",
"'/config/config_dev.yml'",
")",
")",
";",
"$",
"aYaml",
"[",
"'assetic'",
"]",
"[",
"'use_controller'",
"]",
"=",
"false",
";",
"$",
"sNewYaml",
"=",
"Yaml",
"::",
"dump",
"(",
"$",
"aYaml",
",",
"5",
")",
";",
"file_put_contents",
"(",
"self",
"::",
"$",
"_container",
"->",
"get",
"(",
"'kernel'",
")",
"->",
"getRootDir",
"(",
")",
".",
"'/config/config_dev.yml'",
",",
"$",
"sNewYaml",
")",
";",
"/**\n * prod\n */",
"$",
"aYaml",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"self",
"::",
"$",
"_container",
"->",
"get",
"(",
"'kernel'",
")",
"->",
"getRootDir",
"(",
")",
".",
"'/config/config_prod.yml'",
")",
")",
";",
"$",
"aYaml",
"[",
"'assetic'",
"]",
"[",
"'use_controller'",
"]",
"=",
"false",
";",
"$",
"sNewYaml",
"=",
"Yaml",
"::",
"dump",
"(",
"$",
"aYaml",
",",
"5",
")",
";",
"file_put_contents",
"(",
"self",
"::",
"$",
"_container",
"->",
"get",
"(",
"'kernel'",
")",
"->",
"getRootDir",
"(",
")",
".",
"'/config/config_prod.yml'",
",",
"$",
"sNewYaml",
")",
";",
"}"
] |
reset assitx-config not to use controller
|
[
"reset",
"assitx",
"-",
"config",
"not",
"to",
"use",
"controller"
] |
train
|
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Helper/InstallHelper.php#L99-L120
|
slashworks/control-bundle
|
src/Slashworks/BackendBundle/Helper/InstallHelper.php
|
InstallHelper._saveControlUrl
|
private static function _saveControlUrl()
{
$oStatement = self::$_connection->prepare('INSERT INTO `system_settings` (`key` ,`value`)VALUES (:key, :value);');
$oResult = $oStatement->execute(array(
":key" => "control_url",
":value" => self::$_data['controlUrl'],
));
if ($oResult !== true) {
throw new Exception("Error while inserting control url");
}
$oStatement = self::$_connection->prepare('INSERT INTO `license` (`id`, `max_clients`, `domain`, `serial`, `valid_until`) VALUES (null, 0, :control_url , \'\', 0);');
$oResult = $oStatement->execute(array(
":control_url" => self::$_data['controlUrl'],
));
}
|
php
|
private static function _saveControlUrl()
{
$oStatement = self::$_connection->prepare('INSERT INTO `system_settings` (`key` ,`value`)VALUES (:key, :value);');
$oResult = $oStatement->execute(array(
":key" => "control_url",
":value" => self::$_data['controlUrl'],
));
if ($oResult !== true) {
throw new Exception("Error while inserting control url");
}
$oStatement = self::$_connection->prepare('INSERT INTO `license` (`id`, `max_clients`, `domain`, `serial`, `valid_until`) VALUES (null, 0, :control_url , \'\', 0);');
$oResult = $oStatement->execute(array(
":control_url" => self::$_data['controlUrl'],
));
}
|
[
"private",
"static",
"function",
"_saveControlUrl",
"(",
")",
"{",
"$",
"oStatement",
"=",
"self",
"::",
"$",
"_connection",
"->",
"prepare",
"(",
"'INSERT INTO `system_settings` (`key` ,`value`)VALUES (:key, :value);'",
")",
";",
"$",
"oResult",
"=",
"$",
"oStatement",
"->",
"execute",
"(",
"array",
"(",
"\":key\"",
"=>",
"\"control_url\"",
",",
"\":value\"",
"=>",
"self",
"::",
"$",
"_data",
"[",
"'controlUrl'",
"]",
",",
")",
")",
";",
"if",
"(",
"$",
"oResult",
"!==",
"true",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Error while inserting control url\"",
")",
";",
"}",
"$",
"oStatement",
"=",
"self",
"::",
"$",
"_connection",
"->",
"prepare",
"(",
"'INSERT INTO `license` (`id`, `max_clients`, `domain`, `serial`, `valid_until`) VALUES (null, 0, :control_url , \\'\\', 0);'",
")",
";",
"$",
"oResult",
"=",
"$",
"oStatement",
"->",
"execute",
"(",
"array",
"(",
"\":control_url\"",
"=>",
"self",
"::",
"$",
"_data",
"[",
"'controlUrl'",
"]",
",",
")",
")",
";",
"}"
] |
save control-url to database
|
[
"save",
"control",
"-",
"url",
"to",
"database"
] |
train
|
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Helper/InstallHelper.php#L184-L204
|
slashworks/control-bundle
|
src/Slashworks/BackendBundle/Helper/InstallHelper.php
|
InstallHelper._saveSystemConfig
|
private static function _saveSystemConfig()
{
$sYmlDump = array(
'parameters' => array(
'database_driver' => self::checkEmpty(self::$_data['dbDriver']),
'database_host' => self::checkEmpty(self::$_data['dbHost']),
'database_port' => self::checkEmpty(self::$_data['dbPort']),
'database_name' => self::checkEmpty(self::$_data['dbName']),
'database_user' => self::checkEmpty(self::$_data['dbUser']),
'database_password' => self::checkEmpty(self::$_data['dbPassword']),
'mailer_transport' => self::checkEmpty(self::$_data['mailerTransport']),
'mailer_host' => self::checkEmpty(self::$_data['mailerHost']),
'mailer_user' => self::checkEmpty(self::$_data['mailerUser']),
'mailer_password' => self::checkEmpty(self::$_data['mailerPassword']),
'locale' => 'de',
'secret' => md5(uniqid(null, true)),
),
);
$oDumper = new Dumper();
$sYaml = $oDumper->dump($sYmlDump, 99, 0, true, false);
$sAppPath = self::$_container->get('kernel')->getRootDir();
$sPath = $sAppPath. '/config/parameters.yml';
$sYaml = str_replace("'", '', $sYaml);
file_put_contents($sPath, $sYaml);
}
|
php
|
private static function _saveSystemConfig()
{
$sYmlDump = array(
'parameters' => array(
'database_driver' => self::checkEmpty(self::$_data['dbDriver']),
'database_host' => self::checkEmpty(self::$_data['dbHost']),
'database_port' => self::checkEmpty(self::$_data['dbPort']),
'database_name' => self::checkEmpty(self::$_data['dbName']),
'database_user' => self::checkEmpty(self::$_data['dbUser']),
'database_password' => self::checkEmpty(self::$_data['dbPassword']),
'mailer_transport' => self::checkEmpty(self::$_data['mailerTransport']),
'mailer_host' => self::checkEmpty(self::$_data['mailerHost']),
'mailer_user' => self::checkEmpty(self::$_data['mailerUser']),
'mailer_password' => self::checkEmpty(self::$_data['mailerPassword']),
'locale' => 'de',
'secret' => md5(uniqid(null, true)),
),
);
$oDumper = new Dumper();
$sYaml = $oDumper->dump($sYmlDump, 99, 0, true, false);
$sAppPath = self::$_container->get('kernel')->getRootDir();
$sPath = $sAppPath. '/config/parameters.yml';
$sYaml = str_replace("'", '', $sYaml);
file_put_contents($sPath, $sYaml);
}
|
[
"private",
"static",
"function",
"_saveSystemConfig",
"(",
")",
"{",
"$",
"sYmlDump",
"=",
"array",
"(",
"'parameters'",
"=>",
"array",
"(",
"'database_driver'",
"=>",
"self",
"::",
"checkEmpty",
"(",
"self",
"::",
"$",
"_data",
"[",
"'dbDriver'",
"]",
")",
",",
"'database_host'",
"=>",
"self",
"::",
"checkEmpty",
"(",
"self",
"::",
"$",
"_data",
"[",
"'dbHost'",
"]",
")",
",",
"'database_port'",
"=>",
"self",
"::",
"checkEmpty",
"(",
"self",
"::",
"$",
"_data",
"[",
"'dbPort'",
"]",
")",
",",
"'database_name'",
"=>",
"self",
"::",
"checkEmpty",
"(",
"self",
"::",
"$",
"_data",
"[",
"'dbName'",
"]",
")",
",",
"'database_user'",
"=>",
"self",
"::",
"checkEmpty",
"(",
"self",
"::",
"$",
"_data",
"[",
"'dbUser'",
"]",
")",
",",
"'database_password'",
"=>",
"self",
"::",
"checkEmpty",
"(",
"self",
"::",
"$",
"_data",
"[",
"'dbPassword'",
"]",
")",
",",
"'mailer_transport'",
"=>",
"self",
"::",
"checkEmpty",
"(",
"self",
"::",
"$",
"_data",
"[",
"'mailerTransport'",
"]",
")",
",",
"'mailer_host'",
"=>",
"self",
"::",
"checkEmpty",
"(",
"self",
"::",
"$",
"_data",
"[",
"'mailerHost'",
"]",
")",
",",
"'mailer_user'",
"=>",
"self",
"::",
"checkEmpty",
"(",
"self",
"::",
"$",
"_data",
"[",
"'mailerUser'",
"]",
")",
",",
"'mailer_password'",
"=>",
"self",
"::",
"checkEmpty",
"(",
"self",
"::",
"$",
"_data",
"[",
"'mailerPassword'",
"]",
")",
",",
"'locale'",
"=>",
"'de'",
",",
"'secret'",
"=>",
"md5",
"(",
"uniqid",
"(",
"null",
",",
"true",
")",
")",
",",
")",
",",
")",
";",
"$",
"oDumper",
"=",
"new",
"Dumper",
"(",
")",
";",
"$",
"sYaml",
"=",
"$",
"oDumper",
"->",
"dump",
"(",
"$",
"sYmlDump",
",",
"99",
",",
"0",
",",
"true",
",",
"false",
")",
";",
"$",
"sAppPath",
"=",
"self",
"::",
"$",
"_container",
"->",
"get",
"(",
"'kernel'",
")",
"->",
"getRootDir",
"(",
")",
";",
"$",
"sPath",
"=",
"$",
"sAppPath",
".",
"'/config/parameters.yml'",
";",
"$",
"sYaml",
"=",
"str_replace",
"(",
"\"'\"",
",",
"''",
",",
"$",
"sYaml",
")",
";",
"file_put_contents",
"(",
"$",
"sPath",
",",
"$",
"sYaml",
")",
";",
"}"
] |
save systemconfig to parameters.yml
|
[
"save",
"systemconfig",
"to",
"parameters",
".",
"yml"
] |
train
|
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Helper/InstallHelper.php#L210-L237
|
slashworks/control-bundle
|
src/Slashworks/BackendBundle/Helper/InstallHelper.php
|
InstallHelper._createAdminUser
|
private static function _createAdminUser()
{
$oUser = new User();
$factory = self::$_container->get('security.encoder_factory');
$encoder = $factory->getEncoder($oUser);
$sSalt = $oUser->getSalt();
$sPassword = $encoder->encodePassword(self::$_data['adminPassword'], $sSalt);
$oStatement = self::$_connection->prepare('INSERT INTO `user` (`id`, `username`, `password`, `salt`, `firstname`, `lastname`, `email`, `phone`, `memo`, `activated`, `last_login`, `notification_change`, `notification_error`) VALUES (null, :adminUser, :adminPassword , :adminPasswordSalt, \'admin\', \'admin\', :adminEmail, \'\', \'\', 1, \'0000-00-00 00:00:00\', 1, 1);');
$oResult = $oStatement->execute(array(
":adminUser" => self::$_data['adminUser'],
":adminPassword" => $sPassword,
":adminPasswordSalt" => $sSalt,
":adminEmail" => self::$_data['adminEmail'],
));
if ($oResult !== true) {
throw new Exception("Error while creating admin user");
}
$iUserId = self::$_connection->lastInsertId();
$oStatement = self::$_connection->prepare('INSERT INTO `user_role` (`user_id` ,`role_id`)VALUES (:user_id, :user_role_id);');
$oResult = $oStatement->execute(array(
":user_id" => $iUserId,
":user_role_id" => 6,
));
if ($oResult !== true) {
throw new Exception("Error while creating admin user");
}
}
|
php
|
private static function _createAdminUser()
{
$oUser = new User();
$factory = self::$_container->get('security.encoder_factory');
$encoder = $factory->getEncoder($oUser);
$sSalt = $oUser->getSalt();
$sPassword = $encoder->encodePassword(self::$_data['adminPassword'], $sSalt);
$oStatement = self::$_connection->prepare('INSERT INTO `user` (`id`, `username`, `password`, `salt`, `firstname`, `lastname`, `email`, `phone`, `memo`, `activated`, `last_login`, `notification_change`, `notification_error`) VALUES (null, :adminUser, :adminPassword , :adminPasswordSalt, \'admin\', \'admin\', :adminEmail, \'\', \'\', 1, \'0000-00-00 00:00:00\', 1, 1);');
$oResult = $oStatement->execute(array(
":adminUser" => self::$_data['adminUser'],
":adminPassword" => $sPassword,
":adminPasswordSalt" => $sSalt,
":adminEmail" => self::$_data['adminEmail'],
));
if ($oResult !== true) {
throw new Exception("Error while creating admin user");
}
$iUserId = self::$_connection->lastInsertId();
$oStatement = self::$_connection->prepare('INSERT INTO `user_role` (`user_id` ,`role_id`)VALUES (:user_id, :user_role_id);');
$oResult = $oStatement->execute(array(
":user_id" => $iUserId,
":user_role_id" => 6,
));
if ($oResult !== true) {
throw new Exception("Error while creating admin user");
}
}
|
[
"private",
"static",
"function",
"_createAdminUser",
"(",
")",
"{",
"$",
"oUser",
"=",
"new",
"User",
"(",
")",
";",
"$",
"factory",
"=",
"self",
"::",
"$",
"_container",
"->",
"get",
"(",
"'security.encoder_factory'",
")",
";",
"$",
"encoder",
"=",
"$",
"factory",
"->",
"getEncoder",
"(",
"$",
"oUser",
")",
";",
"$",
"sSalt",
"=",
"$",
"oUser",
"->",
"getSalt",
"(",
")",
";",
"$",
"sPassword",
"=",
"$",
"encoder",
"->",
"encodePassword",
"(",
"self",
"::",
"$",
"_data",
"[",
"'adminPassword'",
"]",
",",
"$",
"sSalt",
")",
";",
"$",
"oStatement",
"=",
"self",
"::",
"$",
"_connection",
"->",
"prepare",
"(",
"'INSERT INTO `user` (`id`, `username`, `password`, `salt`, `firstname`, `lastname`, `email`, `phone`, `memo`, `activated`, `last_login`, `notification_change`, `notification_error`) VALUES (null, :adminUser, :adminPassword , :adminPasswordSalt, \\'admin\\', \\'admin\\', :adminEmail, \\'\\', \\'\\', 1, \\'0000-00-00 00:00:00\\', 1, 1);'",
")",
";",
"$",
"oResult",
"=",
"$",
"oStatement",
"->",
"execute",
"(",
"array",
"(",
"\":adminUser\"",
"=>",
"self",
"::",
"$",
"_data",
"[",
"'adminUser'",
"]",
",",
"\":adminPassword\"",
"=>",
"$",
"sPassword",
",",
"\":adminPasswordSalt\"",
"=>",
"$",
"sSalt",
",",
"\":adminEmail\"",
"=>",
"self",
"::",
"$",
"_data",
"[",
"'adminEmail'",
"]",
",",
")",
")",
";",
"if",
"(",
"$",
"oResult",
"!==",
"true",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Error while creating admin user\"",
")",
";",
"}",
"$",
"iUserId",
"=",
"self",
"::",
"$",
"_connection",
"->",
"lastInsertId",
"(",
")",
";",
"$",
"oStatement",
"=",
"self",
"::",
"$",
"_connection",
"->",
"prepare",
"(",
"'INSERT INTO `user_role` (`user_id` ,`role_id`)VALUES (:user_id, :user_role_id);'",
")",
";",
"$",
"oResult",
"=",
"$",
"oStatement",
"->",
"execute",
"(",
"array",
"(",
"\":user_id\"",
"=>",
"$",
"iUserId",
",",
"\":user_role_id\"",
"=>",
"6",
",",
")",
")",
";",
"if",
"(",
"$",
"oResult",
"!==",
"true",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Error while creating admin user\"",
")",
";",
"}",
"}"
] |
create the admin user
|
[
"create",
"the",
"admin",
"user"
] |
train
|
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Helper/InstallHelper.php#L309-L343
|
uthando-cms/uthando-dompdf
|
src/UthandoDomPdf/Mvc/Service/ViewPdfRendererFactory.php
|
ViewPdfRendererFactory.createService
|
public function createService(ServiceLocatorInterface $serviceLocator)
{
$resolver = $serviceLocator->get('ViewResolver');
$renderer = $serviceLocator->get('ViewRenderer');
$pdfRenderer = new PdfRenderer();
$pdfRenderer->setResolver($resolver);
$pdfRenderer->setHtmlRenderer($renderer);
$pdfRenderer->setEngine($serviceLocator->get(Dompdf::class));
return $pdfRenderer;
}
|
php
|
public function createService(ServiceLocatorInterface $serviceLocator)
{
$resolver = $serviceLocator->get('ViewResolver');
$renderer = $serviceLocator->get('ViewRenderer');
$pdfRenderer = new PdfRenderer();
$pdfRenderer->setResolver($resolver);
$pdfRenderer->setHtmlRenderer($renderer);
$pdfRenderer->setEngine($serviceLocator->get(Dompdf::class));
return $pdfRenderer;
}
|
[
"public",
"function",
"createService",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"$",
"resolver",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'ViewResolver'",
")",
";",
"$",
"renderer",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'ViewRenderer'",
")",
";",
"$",
"pdfRenderer",
"=",
"new",
"PdfRenderer",
"(",
")",
";",
"$",
"pdfRenderer",
"->",
"setResolver",
"(",
"$",
"resolver",
")",
";",
"$",
"pdfRenderer",
"->",
"setHtmlRenderer",
"(",
"$",
"renderer",
")",
";",
"$",
"pdfRenderer",
"->",
"setEngine",
"(",
"$",
"serviceLocator",
"->",
"get",
"(",
"Dompdf",
"::",
"class",
")",
")",
";",
"return",
"$",
"pdfRenderer",
";",
"}"
] |
Create and return the PDF view renderer
@param ServiceLocatorInterface $serviceLocator
@return PdfRenderer
|
[
"Create",
"and",
"return",
"the",
"PDF",
"view",
"renderer"
] |
train
|
https://github.com/uthando-cms/uthando-dompdf/blob/60a750058c2db9ed167476192b20c7f544c32007/src/UthandoDomPdf/Mvc/Service/ViewPdfRendererFactory.php#L31-L42
|
windwork/wf-mailer
|
lib/adapter/Mail.php
|
Mail.send
|
public function send($to, $subject, $message, $from = '', $cc = '', $bcc = '')
{
$to = \wf\mailer\Helper::emailEncode($to);
$from = \wf\mailer\Helper::emailEncode($from);
$subject = \wf\mailer\Helper::encode($subject);
$headers = "From: {$from}\r\n";
$headers = "To: {$to}\r\n";
// 抄送
if($cc) {
$cc = \wf\mailer\Helper::emailEncode($cc);
$headers .= "Cc: {$cc}\r\n";
}
// 密送
if($bcc) {
$bcc = \wf\mailer\Helper::emailEncode($bcc);
$headers .= "Bcc: {$bcc}\r\n";
}
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "X-Mailer: Windwork\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
// 内容处理
$message = str_replace("\n\r", "\r", $message);
$message = str_replace("\r\n", "\n", $message);
$message = str_replace("\r", "\n", $message);
$message = str_replace("\n", "\r\n", $message);
$message = chunk_split(base64_encode($message));
if(!mail($to, $subject, $message, $headers)) {
throw new Exception("Mail failed: {$to} {$subject}");
}
return true;
}
|
php
|
public function send($to, $subject, $message, $from = '', $cc = '', $bcc = '')
{
$to = \wf\mailer\Helper::emailEncode($to);
$from = \wf\mailer\Helper::emailEncode($from);
$subject = \wf\mailer\Helper::encode($subject);
$headers = "From: {$from}\r\n";
$headers = "To: {$to}\r\n";
// 抄送
if($cc) {
$cc = \wf\mailer\Helper::emailEncode($cc);
$headers .= "Cc: {$cc}\r\n";
}
// 密送
if($bcc) {
$bcc = \wf\mailer\Helper::emailEncode($bcc);
$headers .= "Bcc: {$bcc}\r\n";
}
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "X-Mailer: Windwork\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
// 内容处理
$message = str_replace("\n\r", "\r", $message);
$message = str_replace("\r\n", "\n", $message);
$message = str_replace("\r", "\n", $message);
$message = str_replace("\n", "\r\n", $message);
$message = chunk_split(base64_encode($message));
if(!mail($to, $subject, $message, $headers)) {
throw new Exception("Mail failed: {$to} {$subject}");
}
return true;
}
|
[
"public",
"function",
"send",
"(",
"$",
"to",
",",
"$",
"subject",
",",
"$",
"message",
",",
"$",
"from",
"=",
"''",
",",
"$",
"cc",
"=",
"''",
",",
"$",
"bcc",
"=",
"''",
")",
"{",
"$",
"to",
"=",
"\\",
"wf",
"\\",
"mailer",
"\\",
"Helper",
"::",
"emailEncode",
"(",
"$",
"to",
")",
";",
"$",
"from",
"=",
"\\",
"wf",
"\\",
"mailer",
"\\",
"Helper",
"::",
"emailEncode",
"(",
"$",
"from",
")",
";",
"$",
"subject",
"=",
"\\",
"wf",
"\\",
"mailer",
"\\",
"Helper",
"::",
"encode",
"(",
"$",
"subject",
")",
";",
"$",
"headers",
"=",
"\"From: {$from}\\r\\n\"",
";",
"$",
"headers",
"=",
"\"To: {$to}\\r\\n\"",
";",
"// 抄送",
"if",
"(",
"$",
"cc",
")",
"{",
"$",
"cc",
"=",
"\\",
"wf",
"\\",
"mailer",
"\\",
"Helper",
"::",
"emailEncode",
"(",
"$",
"cc",
")",
";",
"$",
"headers",
".=",
"\"Cc: {$cc}\\r\\n\"",
";",
"}",
"// 密送",
"if",
"(",
"$",
"bcc",
")",
"{",
"$",
"bcc",
"=",
"\\",
"wf",
"\\",
"mailer",
"\\",
"Helper",
"::",
"emailEncode",
"(",
"$",
"bcc",
")",
";",
"$",
"headers",
".=",
"\"Bcc: {$bcc}\\r\\n\"",
";",
"}",
"$",
"headers",
".=",
"\"MIME-Version: 1.0\\r\\n\"",
";",
"$",
"headers",
".=",
"\"X-Mailer: Windwork\\r\\n\"",
";",
"$",
"headers",
".=",
"\"Content-type: text/html; charset=utf-8\\r\\n\"",
";",
"$",
"headers",
".=",
"\"Content-Transfer-Encoding: base64\\r\\n\"",
";",
"// 内容处理",
"$",
"message",
"=",
"str_replace",
"(",
"\"\\n\\r\"",
",",
"\"\\r\"",
",",
"$",
"message",
")",
";",
"$",
"message",
"=",
"str_replace",
"(",
"\"\\r\\n\"",
",",
"\"\\n\"",
",",
"$",
"message",
")",
";",
"$",
"message",
"=",
"str_replace",
"(",
"\"\\r\"",
",",
"\"\\n\"",
",",
"$",
"message",
")",
";",
"$",
"message",
"=",
"str_replace",
"(",
"\"\\n\"",
",",
"\"\\r\\n\"",
",",
"$",
"message",
")",
";",
"$",
"message",
"=",
"chunk_split",
"(",
"base64_encode",
"(",
"$",
"message",
")",
")",
";",
"if",
"(",
"!",
"mail",
"(",
"$",
"to",
",",
"$",
"subject",
",",
"$",
"message",
",",
"$",
"headers",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Mail failed: {$to} {$subject}\"",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
{@inheritDoc}
@see \wf\mailer\MailerInterface::send()
|
[
"{"
] |
train
|
https://github.com/windwork/wf-mailer/blob/71fbdb3bcb5bdc0a53fa8b4433c446828e205d22/lib/adapter/Mail.php#L35-L73
|
joseph-walker/vector
|
src/Control/Pattern.php
|
Pattern.__getType
|
protected static function __getType($param)
{
$type = is_object($param)
? get_class($param)
: gettype($param);
return $type === 'integer' ? 'int' : $type;
}
|
php
|
protected static function __getType($param)
{
$type = is_object($param)
? get_class($param)
: gettype($param);
return $type === 'integer' ? 'int' : $type;
}
|
[
"protected",
"static",
"function",
"__getType",
"(",
"$",
"param",
")",
"{",
"$",
"type",
"=",
"is_object",
"(",
"$",
"param",
")",
"?",
"get_class",
"(",
"$",
"param",
")",
":",
"gettype",
"(",
"$",
"param",
")",
";",
"return",
"$",
"type",
"===",
"'integer'",
"?",
"'int'",
":",
"$",
"type",
";",
"}"
] |
Get type OR class for params, as well as re-mapping inconsistencies
@param $param
@return string
|
[
"Get",
"type",
"OR",
"class",
"for",
"params",
"as",
"well",
"as",
"re",
"-",
"mapping",
"inconsistencies"
] |
train
|
https://github.com/joseph-walker/vector/blob/e349aa2e9e0535b1993f9fffc0476e7fd8e113fc/src/Control/Pattern.php#L27-L34
|
joseph-walker/vector
|
src/Control/Pattern.php
|
Pattern.__match
|
protected static function __match(array $patterns)
{
return function (...$args) use ($patterns) {
$parameterTypes = array_map(self::getType(), $args);
try {
$keysToValues = Arrays::zip(array_keys($patterns), array_values($patterns));
list($key, $matchingPattern) = Arrays::first(
Pattern::patternApplies($parameterTypes, $args),
$keysToValues
);
} catch (ElementNotFoundException $e) {
throw new IncompletePatternMatchException(
'Incomplete pattern match expression. (missing ' . implode(', ', $parameterTypes) . ')'
);
}
/**
* Upcoming Feature, Array DSL for matching via `x::xs` etc.
*/
// // if key is a string, manually match
// if (is_string($key)) {
//
// throw new \Exception('Array DSL not available.');
// }
list($hasExtractable, $unwrappedArgs) = self::unwrapArgs($args);
$value = $matchingPattern(...$args);
$isCallable = is_callable($value);
if ($hasExtractable && ! $isCallable) {
throw new InvalidPatternMatchException(
'Invalid pattern match expression. (one of ' . implode(', ', $parameterTypes)
. ' requires a callback to unwrap)'
);
}
/**
* Extractable requires a callback to feed args into.
*/
if ($hasExtractable && $isCallable) {
return $matchingPattern(...$args)(...$unwrappedArgs);
}
/**
* No extractable so we can just return the value directly.
*/
return $value;
};
}
|
php
|
protected static function __match(array $patterns)
{
return function (...$args) use ($patterns) {
$parameterTypes = array_map(self::getType(), $args);
try {
$keysToValues = Arrays::zip(array_keys($patterns), array_values($patterns));
list($key, $matchingPattern) = Arrays::first(
Pattern::patternApplies($parameterTypes, $args),
$keysToValues
);
} catch (ElementNotFoundException $e) {
throw new IncompletePatternMatchException(
'Incomplete pattern match expression. (missing ' . implode(', ', $parameterTypes) . ')'
);
}
/**
* Upcoming Feature, Array DSL for matching via `x::xs` etc.
*/
// // if key is a string, manually match
// if (is_string($key)) {
//
// throw new \Exception('Array DSL not available.');
// }
list($hasExtractable, $unwrappedArgs) = self::unwrapArgs($args);
$value = $matchingPattern(...$args);
$isCallable = is_callable($value);
if ($hasExtractable && ! $isCallable) {
throw new InvalidPatternMatchException(
'Invalid pattern match expression. (one of ' . implode(', ', $parameterTypes)
. ' requires a callback to unwrap)'
);
}
/**
* Extractable requires a callback to feed args into.
*/
if ($hasExtractable && $isCallable) {
return $matchingPattern(...$args)(...$unwrappedArgs);
}
/**
* No extractable so we can just return the value directly.
*/
return $value;
};
}
|
[
"protected",
"static",
"function",
"__match",
"(",
"array",
"$",
"patterns",
")",
"{",
"return",
"function",
"(",
"...",
"$",
"args",
")",
"use",
"(",
"$",
"patterns",
")",
"{",
"$",
"parameterTypes",
"=",
"array_map",
"(",
"self",
"::",
"getType",
"(",
")",
",",
"$",
"args",
")",
";",
"try",
"{",
"$",
"keysToValues",
"=",
"Arrays",
"::",
"zip",
"(",
"array_keys",
"(",
"$",
"patterns",
")",
",",
"array_values",
"(",
"$",
"patterns",
")",
")",
";",
"list",
"(",
"$",
"key",
",",
"$",
"matchingPattern",
")",
"=",
"Arrays",
"::",
"first",
"(",
"Pattern",
"::",
"patternApplies",
"(",
"$",
"parameterTypes",
",",
"$",
"args",
")",
",",
"$",
"keysToValues",
")",
";",
"}",
"catch",
"(",
"ElementNotFoundException",
"$",
"e",
")",
"{",
"throw",
"new",
"IncompletePatternMatchException",
"(",
"'Incomplete pattern match expression. (missing '",
".",
"implode",
"(",
"', '",
",",
"$",
"parameterTypes",
")",
".",
"')'",
")",
";",
"}",
"/**\n * Upcoming Feature, Array DSL for matching via `x::xs` etc.\n */",
"// // if key is a string, manually match",
"// if (is_string($key)) {",
"//",
"// throw new \\Exception('Array DSL not available.');",
"// }",
"list",
"(",
"$",
"hasExtractable",
",",
"$",
"unwrappedArgs",
")",
"=",
"self",
"::",
"unwrapArgs",
"(",
"$",
"args",
")",
";",
"$",
"value",
"=",
"$",
"matchingPattern",
"(",
"...",
"$",
"args",
")",
";",
"$",
"isCallable",
"=",
"is_callable",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"hasExtractable",
"&&",
"!",
"$",
"isCallable",
")",
"{",
"throw",
"new",
"InvalidPatternMatchException",
"(",
"'Invalid pattern match expression. (one of '",
".",
"implode",
"(",
"', '",
",",
"$",
"parameterTypes",
")",
".",
"' requires a callback to unwrap)'",
")",
";",
"}",
"/**\n * Extractable requires a callback to feed args into.\n */",
"if",
"(",
"$",
"hasExtractable",
"&&",
"$",
"isCallable",
")",
"{",
"return",
"$",
"matchingPattern",
"(",
"...",
"$",
"args",
")",
"(",
"...",
"$",
"unwrappedArgs",
")",
";",
"}",
"/**\n * No extractable so we can just return the value directly.\n */",
"return",
"$",
"value",
";",
"}",
";",
"}"
] |
Pattern Matching. Use switch-case for explicit values, this for everything else.
@param array $patterns
@return mixed
|
[
"Pattern",
"Matching",
".",
"Use",
"switch",
"-",
"case",
"for",
"explicit",
"values",
"this",
"for",
"everything",
"else",
"."
] |
train
|
https://github.com/joseph-walker/vector/blob/e349aa2e9e0535b1993f9fffc0476e7fd8e113fc/src/Control/Pattern.php#L41-L93
|
joseph-walker/vector
|
src/Control/Pattern.php
|
Pattern.unwrapArgs
|
private static function unwrapArgs(array $args) : array
{
$hasExtractable = false;
$unwrappedArgs = self::flatten(array_map(function ($arg) use (&$hasExtractable) {
if (method_exists($arg, 'extract')) {
$hasExtractable = true;
return $arg->extract();
}
return $arg;
}, $args));
return [$hasExtractable, $unwrappedArgs];
}
|
php
|
private static function unwrapArgs(array $args) : array
{
$hasExtractable = false;
$unwrappedArgs = self::flatten(array_map(function ($arg) use (&$hasExtractable) {
if (method_exists($arg, 'extract')) {
$hasExtractable = true;
return $arg->extract();
}
return $arg;
}, $args));
return [$hasExtractable, $unwrappedArgs];
}
|
[
"private",
"static",
"function",
"unwrapArgs",
"(",
"array",
"$",
"args",
")",
":",
"array",
"{",
"$",
"hasExtractable",
"=",
"false",
";",
"$",
"unwrappedArgs",
"=",
"self",
"::",
"flatten",
"(",
"array_map",
"(",
"function",
"(",
"$",
"arg",
")",
"use",
"(",
"&",
"$",
"hasExtractable",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"arg",
",",
"'extract'",
")",
")",
"{",
"$",
"hasExtractable",
"=",
"true",
";",
"return",
"$",
"arg",
"->",
"extract",
"(",
")",
";",
"}",
"return",
"$",
"arg",
";",
"}",
",",
"$",
"args",
")",
")",
";",
"return",
"[",
"$",
"hasExtractable",
",",
"$",
"unwrappedArgs",
"]",
";",
"}"
] |
Extracts args from Extractable values
@param array $args
@return array
|
[
"Extracts",
"args",
"from",
"Extractable",
"values"
] |
train
|
https://github.com/joseph-walker/vector/blob/e349aa2e9e0535b1993f9fffc0476e7fd8e113fc/src/Control/Pattern.php#L100-L114
|
maniaplanet/maniaplanet-ws-sdk
|
libraries/Maniaplanet/WebServices/Rankings.php
|
Rankings.getMultiplayerPlayer
|
function getMultiplayerPlayer($titleId, $login)
{
if(!$login)
{
throw new Exception('Invalid login');
}
return $this->execute('GET', $this->getPrefixEndpoint($titleId).'/rankings/multiplayer/player/%s/?title=%s', array($login, $titleId));
}
|
php
|
function getMultiplayerPlayer($titleId, $login)
{
if(!$login)
{
throw new Exception('Invalid login');
}
return $this->execute('GET', $this->getPrefixEndpoint($titleId).'/rankings/multiplayer/player/%s/?title=%s', array($login, $titleId));
}
|
[
"function",
"getMultiplayerPlayer",
"(",
"$",
"titleId",
",",
"$",
"login",
")",
"{",
"if",
"(",
"!",
"$",
"login",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Invalid login'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"execute",
"(",
"'GET'",
",",
"$",
"this",
"->",
"getPrefixEndpoint",
"(",
"$",
"titleId",
")",
".",
"'/rankings/multiplayer/player/%s/?title=%s'",
",",
"array",
"(",
"$",
"login",
",",
"$",
"titleId",
")",
")",
";",
"}"
] |
Get player ranking for the give title
@param string $titleId
@param string $login
@return Object
@throws Exception
|
[
"Get",
"player",
"ranking",
"for",
"the",
"give",
"title"
] |
train
|
https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/Rankings.php#L18-L25
|
webforge-labs/psc-cms
|
lib/Psc/Graph/EdgesList.php
|
EdgesList.remove
|
public function remove(Vertice $u, Vertice $v = NULL) {
if ($v == NULL) return $this->erase($u);
return $this;
}
|
php
|
public function remove(Vertice $u, Vertice $v = NULL) {
if ($v == NULL) return $this->erase($u);
return $this;
}
|
[
"public",
"function",
"remove",
"(",
"Vertice",
"$",
"u",
",",
"Vertice",
"$",
"v",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"v",
"==",
"NULL",
")",
"return",
"$",
"this",
"->",
"erase",
"(",
"$",
"u",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Entfernt die Kante von $u und $v
Ist $v nicht angegeben werden alle Kanten von $u entfernt
|
[
"Entfernt",
"die",
"Kante",
"von",
"$u",
"und",
"$v"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Graph/EdgesList.php#L30-L33
|
webforge-labs/psc-cms
|
lib/Psc/Graph/EdgesList.php
|
EdgesList.erase
|
public function erase(Vertice $u) {
if (isset($this->lists[$u->label]))
unset($this->lists[$u->label]);
return $this;
}
|
php
|
public function erase(Vertice $u) {
if (isset($this->lists[$u->label]))
unset($this->lists[$u->label]);
return $this;
}
|
[
"public",
"function",
"erase",
"(",
"Vertice",
"$",
"u",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"lists",
"[",
"$",
"u",
"->",
"label",
"]",
")",
")",
"unset",
"(",
"$",
"this",
"->",
"lists",
"[",
"$",
"u",
"->",
"label",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Löscht alle Kanten von $u
|
[
"Löscht",
"alle",
"Kanten",
"von",
"$u"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Graph/EdgesList.php#L38-L43
|
yuncms/framework
|
src/admin/widgets/ActiveField.php
|
ActiveField.fileInput
|
public function fileInput($options = [])
{
$options = array_merge([
'class' => 'filestyle',
'data' => [
'buttonText' => Yii::t('app', 'Choose file'),
//'size' => 'lg'
]
], $options);
BootstrapFileStyleAsset::register($this->form->view);
return parent::fileInput($options);
}
|
php
|
public function fileInput($options = [])
{
$options = array_merge([
'class' => 'filestyle',
'data' => [
'buttonText' => Yii::t('app', 'Choose file'),
//'size' => 'lg'
]
], $options);
BootstrapFileStyleAsset::register($this->form->view);
return parent::fileInput($options);
}
|
[
"public",
"function",
"fileInput",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"[",
"'class'",
"=>",
"'filestyle'",
",",
"'data'",
"=>",
"[",
"'buttonText'",
"=>",
"Yii",
"::",
"t",
"(",
"'app'",
",",
"'Choose file'",
")",
",",
"//'size' => 'lg'",
"]",
"]",
",",
"$",
"options",
")",
";",
"BootstrapFileStyleAsset",
"::",
"register",
"(",
"$",
"this",
"->",
"form",
"->",
"view",
")",
";",
"return",
"parent",
"::",
"fileInput",
"(",
"$",
"options",
")",
";",
"}"
] |
显示文件上传窗口
@param array $options
@return \yii\bootstrap\ActiveField|ActiveField
|
[
"显示文件上传窗口"
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/widgets/ActiveField.php#L29-L40
|
yuncms/framework
|
src/admin/widgets/ActiveField.php
|
ActiveField.dropDownList
|
public function dropDownList($items, $options = [], $generateDefault = true)
{
if ($generateDefault === true && !isset($options['prompt'])) {
$options['prompt'] = Yii::t('yuncms', 'Please select');
}
return parent::dropDownList($items, $options);
}
|
php
|
public function dropDownList($items, $options = [], $generateDefault = true)
{
if ($generateDefault === true && !isset($options['prompt'])) {
$options['prompt'] = Yii::t('yuncms', 'Please select');
}
return parent::dropDownList($items, $options);
}
|
[
"public",
"function",
"dropDownList",
"(",
"$",
"items",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"generateDefault",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"generateDefault",
"===",
"true",
"&&",
"!",
"isset",
"(",
"$",
"options",
"[",
"'prompt'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'prompt'",
"]",
"=",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Please select'",
")",
";",
"}",
"return",
"parent",
"::",
"dropDownList",
"(",
"$",
"items",
",",
"$",
"options",
")",
";",
"}"
] |
显示下拉
@param array $items
@param array $options
@param bool $generateDefault
@return \yii\bootstrap\ActiveField|ActiveField
|
[
"显示下拉"
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/widgets/ActiveField.php#L91-L97
|
afrittella/back-project
|
src/app/Http/Middleware/Role.php
|
Role.handle
|
public function handle($request, Closure $next, $role, $permission = "")
{
if (Auth::guest()) {
return redirect()->guest('login');
}
if (!$request->user()->hasRole($role)) {
abort(403);
}
if (!empty($permission) and !$request->user()->can($permission)) {
abort(403);
}
return $next($request);
}
|
php
|
public function handle($request, Closure $next, $role, $permission = "")
{
if (Auth::guest()) {
return redirect()->guest('login');
}
if (!$request->user()->hasRole($role)) {
abort(403);
}
if (!empty($permission) and !$request->user()->can($permission)) {
abort(403);
}
return $next($request);
}
|
[
"public",
"function",
"handle",
"(",
"$",
"request",
",",
"Closure",
"$",
"next",
",",
"$",
"role",
",",
"$",
"permission",
"=",
"\"\"",
")",
"{",
"if",
"(",
"Auth",
"::",
"guest",
"(",
")",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"guest",
"(",
"'login'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"request",
"->",
"user",
"(",
")",
"->",
"hasRole",
"(",
"$",
"role",
")",
")",
"{",
"abort",
"(",
"403",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"permission",
")",
"and",
"!",
"$",
"request",
"->",
"user",
"(",
")",
"->",
"can",
"(",
"$",
"permission",
")",
")",
"{",
"abort",
"(",
"403",
")",
";",
"}",
"return",
"$",
"next",
"(",
"$",
"request",
")",
";",
"}"
] |
Handle an incoming request.
@param \Illuminate\Http\Request $request
@param \Closure $next
@param $role
@param $permission
@return mixed
|
[
"Handle",
"an",
"incoming",
"request",
"."
] |
train
|
https://github.com/afrittella/back-project/blob/e1aa2e3ee03d453033f75a4b16f073c60b5f32d1/src/app/Http/Middleware/Role.php#L19-L34
|
PortaText/php-sdk
|
src/PortaText/Command/Api/ContactLists.php
|
ContactLists.withNumber
|
public function withNumber($number, $variables = null)
{
if (!is_null($variables)) {
$vars = array();
foreach ($variables as $k => $v) {
$vars[] = array('key' => $k, 'value' => $v);
}
$this->setArgument("variables", $vars);
}
return $this->setArgument("number", $number);
}
|
php
|
public function withNumber($number, $variables = null)
{
if (!is_null($variables)) {
$vars = array();
foreach ($variables as $k => $v) {
$vars[] = array('key' => $k, 'value' => $v);
}
$this->setArgument("variables", $vars);
}
return $this->setArgument("number", $number);
}
|
[
"public",
"function",
"withNumber",
"(",
"$",
"number",
",",
"$",
"variables",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"variables",
")",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"variables",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"vars",
"[",
"]",
"=",
"array",
"(",
"'key'",
"=>",
"$",
"k",
",",
"'value'",
"=>",
"$",
"v",
")",
";",
"}",
"$",
"this",
"->",
"setArgument",
"(",
"\"variables\"",
",",
"$",
"vars",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setArgument",
"(",
"\"number\"",
",",
"$",
"number",
")",
";",
"}"
] |
Add or remove this number to the contact list.
@param string $number Number.
@param array $variables variables.
@return PortaText\Command\ICommand
|
[
"Add",
"or",
"remove",
"this",
"number",
"to",
"the",
"contact",
"list",
"."
] |
train
|
https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Api/ContactLists.php#L52-L62
|
PortaText/php-sdk
|
src/PortaText/Command/Api/ContactLists.php
|
ContactLists.getEndpoint
|
protected function getEndpoint($method)
{
$endpoint = "contact_lists";
$contactListId = $this->getArgument("id");
if (!is_null($contactListId)) {
$endpoint = "contact_lists/$contactListId";
$this->delArgument("id");
}
$number = $this->getArgument("number");
if (!is_null($number)) {
$this->delArgument("number");
return "$endpoint/contacts/$number";
}
$file = $this->getArgument("file");
$saveTo = $this->getArgument("accept_file");
if (!is_null($file) || !is_null($saveTo)) {
$endpoint .= "/contacts";
}
$page = $this->getArgument("page");
$this->delArgument("page");
if (!is_null($page)) {
$endpoint .= "/contacts?page=$page";
}
return $endpoint;
}
|
php
|
protected function getEndpoint($method)
{
$endpoint = "contact_lists";
$contactListId = $this->getArgument("id");
if (!is_null($contactListId)) {
$endpoint = "contact_lists/$contactListId";
$this->delArgument("id");
}
$number = $this->getArgument("number");
if (!is_null($number)) {
$this->delArgument("number");
return "$endpoint/contacts/$number";
}
$file = $this->getArgument("file");
$saveTo = $this->getArgument("accept_file");
if (!is_null($file) || !is_null($saveTo)) {
$endpoint .= "/contacts";
}
$page = $this->getArgument("page");
$this->delArgument("page");
if (!is_null($page)) {
$endpoint .= "/contacts?page=$page";
}
return $endpoint;
}
|
[
"protected",
"function",
"getEndpoint",
"(",
"$",
"method",
")",
"{",
"$",
"endpoint",
"=",
"\"contact_lists\"",
";",
"$",
"contactListId",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"id\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"contactListId",
")",
")",
"{",
"$",
"endpoint",
"=",
"\"contact_lists/$contactListId\"",
";",
"$",
"this",
"->",
"delArgument",
"(",
"\"id\"",
")",
";",
"}",
"$",
"number",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"number\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"number",
")",
")",
"{",
"$",
"this",
"->",
"delArgument",
"(",
"\"number\"",
")",
";",
"return",
"\"$endpoint/contacts/$number\"",
";",
"}",
"$",
"file",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"file\"",
")",
";",
"$",
"saveTo",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"accept_file\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"file",
")",
"||",
"!",
"is_null",
"(",
"$",
"saveTo",
")",
")",
"{",
"$",
"endpoint",
".=",
"\"/contacts\"",
";",
"}",
"$",
"page",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"page\"",
")",
";",
"$",
"this",
"->",
"delArgument",
"(",
"\"page\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"page",
")",
")",
"{",
"$",
"endpoint",
".=",
"\"/contacts?page=$page\"",
";",
"}",
"return",
"$",
"endpoint",
";",
"}"
] |
Returns a string with the endpoint for the given command.
@param string $method Method for this command.
@return string
|
[
"Returns",
"a",
"string",
"with",
"the",
"endpoint",
"for",
"the",
"given",
"command",
"."
] |
train
|
https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Api/ContactLists.php#L119-L143
|
dandisy/laravel-generator
|
src/Utils/TableFieldsGenerator.php
|
TableFieldsGenerator.detectManyToOne
|
private function detectManyToOne($tables, $modelTable)
{
$manyToOneRelations = [];
$foreignKeys = $modelTable->foreignKeys;
foreach ($foreignKeys as $foreignKey) {
$foreignTable = $foreignKey->foreignTable;
$foreignField = $foreignKey->foreignField;
if (!isset($tables[$foreignTable])) {
continue;
}
if ($foreignField == $tables[$foreignTable]->primaryKey) {
$modelName = model_name_from_table_name($foreignTable);
$manyToOneRelations[] = GeneratorFieldRelation::parseRelation('mt1,'.$modelName);
}
}
return $manyToOneRelations;
}
|
php
|
private function detectManyToOne($tables, $modelTable)
{
$manyToOneRelations = [];
$foreignKeys = $modelTable->foreignKeys;
foreach ($foreignKeys as $foreignKey) {
$foreignTable = $foreignKey->foreignTable;
$foreignField = $foreignKey->foreignField;
if (!isset($tables[$foreignTable])) {
continue;
}
if ($foreignField == $tables[$foreignTable]->primaryKey) {
$modelName = model_name_from_table_name($foreignTable);
$manyToOneRelations[] = GeneratorFieldRelation::parseRelation('mt1,'.$modelName);
}
}
return $manyToOneRelations;
}
|
[
"private",
"function",
"detectManyToOne",
"(",
"$",
"tables",
",",
"$",
"modelTable",
")",
"{",
"$",
"manyToOneRelations",
"=",
"[",
"]",
";",
"$",
"foreignKeys",
"=",
"$",
"modelTable",
"->",
"foreignKeys",
";",
"foreach",
"(",
"$",
"foreignKeys",
"as",
"$",
"foreignKey",
")",
"{",
"$",
"foreignTable",
"=",
"$",
"foreignKey",
"->",
"foreignTable",
";",
"$",
"foreignField",
"=",
"$",
"foreignKey",
"->",
"foreignField",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"tables",
"[",
"$",
"foreignTable",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"foreignField",
"==",
"$",
"tables",
"[",
"$",
"foreignTable",
"]",
"->",
"primaryKey",
")",
"{",
"$",
"modelName",
"=",
"model_name_from_table_name",
"(",
"$",
"foreignTable",
")",
";",
"$",
"manyToOneRelations",
"[",
"]",
"=",
"GeneratorFieldRelation",
"::",
"parseRelation",
"(",
"'mt1,'",
".",
"$",
"modelName",
")",
";",
"}",
"}",
"return",
"$",
"manyToOneRelations",
";",
"}"
] |
Detect many to one relationship on model table
If foreign key of model table is primary key of foreign table.
@param GeneratorTable[] $tables
@param GeneratorTable $modelTable
@return array
|
[
"Detect",
"many",
"to",
"one",
"relationship",
"on",
"model",
"table",
"If",
"foreign",
"key",
"of",
"model",
"table",
"is",
"primary",
"key",
"of",
"foreign",
"table",
"."
] |
train
|
https://github.com/dandisy/laravel-generator/blob/742797c8483bc88b54b6302a516a9a85eeb8579b/src/Utils/TableFieldsGenerator.php#L483-L504
|
ClanCats/Core
|
src/classes/CCModel.php
|
CCModel._prepare
|
protected static function _prepare( $setting, $class )
{
$settings['defaults'] = array();
$settings['types'] = array();
// get the default's, fix them and clean them.
if ( property_exists( $class, '_defaults') )
{
foreach( static::$_defaults as $key => $value )
{
if ( is_numeric( $key ) )
{
$settings['defaults'][$value] = null;
}
else
{
if ( is_array( $value ) && !empty( $value ) )
{
$settings['types'][$key] = array_shift( $value );
$settings['defaults'][$key] = array_shift( $value );
}
else
{
$settings['defaults'][$key] = $value;
}
}
}
static::$_defaults = $settings['defaults'];
}
// add also the hidden fields properties
if ( property_exists( $class, '_hidden') )
{
$settings['hidden'] = array_flip( static::$_hidden );
}
else
{
$settings['hidden'] = array();
}
// and of course the visible ones
if ( property_exists( $class, '_visible') )
{
$settings['visible'] = array_flip( static::$_visible );
}
else
{
$settings['visible'] = array();
}
// check if the key property isset if not we generate one using
// the current class name
if ( property_exists( $class, '_name') )
{
$settings['name'] = static::$_name;
}
else
{
$settings['name'] = strtolower( str_replace( array( "\\", '_' ), '/', get_called_class() ) );
// if it starts with model remove it
if ( substr( $settings['name'], $length = strlen( 'model/' ) ) == 'model/' )
{
$settings['name'] = substr( $settings['name'], $length );
}
}
return $settings;
}
|
php
|
protected static function _prepare( $setting, $class )
{
$settings['defaults'] = array();
$settings['types'] = array();
// get the default's, fix them and clean them.
if ( property_exists( $class, '_defaults') )
{
foreach( static::$_defaults as $key => $value )
{
if ( is_numeric( $key ) )
{
$settings['defaults'][$value] = null;
}
else
{
if ( is_array( $value ) && !empty( $value ) )
{
$settings['types'][$key] = array_shift( $value );
$settings['defaults'][$key] = array_shift( $value );
}
else
{
$settings['defaults'][$key] = $value;
}
}
}
static::$_defaults = $settings['defaults'];
}
// add also the hidden fields properties
if ( property_exists( $class, '_hidden') )
{
$settings['hidden'] = array_flip( static::$_hidden );
}
else
{
$settings['hidden'] = array();
}
// and of course the visible ones
if ( property_exists( $class, '_visible') )
{
$settings['visible'] = array_flip( static::$_visible );
}
else
{
$settings['visible'] = array();
}
// check if the key property isset if not we generate one using
// the current class name
if ( property_exists( $class, '_name') )
{
$settings['name'] = static::$_name;
}
else
{
$settings['name'] = strtolower( str_replace( array( "\\", '_' ), '/', get_called_class() ) );
// if it starts with model remove it
if ( substr( $settings['name'], $length = strlen( 'model/' ) ) == 'model/' )
{
$settings['name'] = substr( $settings['name'], $length );
}
}
return $settings;
}
|
[
"protected",
"static",
"function",
"_prepare",
"(",
"$",
"setting",
",",
"$",
"class",
")",
"{",
"$",
"settings",
"[",
"'defaults'",
"]",
"=",
"array",
"(",
")",
";",
"$",
"settings",
"[",
"'types'",
"]",
"=",
"array",
"(",
")",
";",
"// get the default's, fix them and clean them.",
"if",
"(",
"property_exists",
"(",
"$",
"class",
",",
"'_defaults'",
")",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"_defaults",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"settings",
"[",
"'defaults'",
"]",
"[",
"$",
"value",
"]",
"=",
"null",
";",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"settings",
"[",
"'types'",
"]",
"[",
"$",
"key",
"]",
"=",
"array_shift",
"(",
"$",
"value",
")",
";",
"$",
"settings",
"[",
"'defaults'",
"]",
"[",
"$",
"key",
"]",
"=",
"array_shift",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"settings",
"[",
"'defaults'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"static",
"::",
"$",
"_defaults",
"=",
"$",
"settings",
"[",
"'defaults'",
"]",
";",
"}",
"// add also the hidden fields properties",
"if",
"(",
"property_exists",
"(",
"$",
"class",
",",
"'_hidden'",
")",
")",
"{",
"$",
"settings",
"[",
"'hidden'",
"]",
"=",
"array_flip",
"(",
"static",
"::",
"$",
"_hidden",
")",
";",
"}",
"else",
"{",
"$",
"settings",
"[",
"'hidden'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"// and of course the visible ones",
"if",
"(",
"property_exists",
"(",
"$",
"class",
",",
"'_visible'",
")",
")",
"{",
"$",
"settings",
"[",
"'visible'",
"]",
"=",
"array_flip",
"(",
"static",
"::",
"$",
"_visible",
")",
";",
"}",
"else",
"{",
"$",
"settings",
"[",
"'visible'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"// check if the key property isset if not we generate one using",
"// the current class name",
"if",
"(",
"property_exists",
"(",
"$",
"class",
",",
"'_name'",
")",
")",
"{",
"$",
"settings",
"[",
"'name'",
"]",
"=",
"static",
"::",
"$",
"_name",
";",
"}",
"else",
"{",
"$",
"settings",
"[",
"'name'",
"]",
"=",
"strtolower",
"(",
"str_replace",
"(",
"array",
"(",
"\"\\\\\"",
",",
"'_'",
")",
",",
"'/'",
",",
"get_called_class",
"(",
")",
")",
")",
";",
"// if it starts with model remove it",
"if",
"(",
"substr",
"(",
"$",
"settings",
"[",
"'name'",
"]",
",",
"$",
"length",
"=",
"strlen",
"(",
"'model/'",
")",
")",
"==",
"'model/'",
")",
"{",
"$",
"settings",
"[",
"'name'",
"]",
"=",
"substr",
"(",
"$",
"settings",
"[",
"'name'",
"]",
",",
"$",
"length",
")",
";",
"}",
"}",
"return",
"$",
"settings",
";",
"}"
] |
Prepare the model
@param string $settings The model properties
@param string $class The class name.
@return array
|
[
"Prepare",
"the",
"model"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCModel.php#L66-L135
|
ClanCats/Core
|
src/classes/CCModel.php
|
CCModel.assign
|
public static function assign( $data )
{
// return null if we have no data
if ( $data === null || empty( $data ) )
{
return null;
}
// do we have a collection or a single result?
if ( CCArr::is_collection( $data ) )
{
$return = array();
foreach( $data as $key => $item )
{
$return[$key] = static::create( $item );
}
return $return;
}
return static::create( $data );
}
|
php
|
public static function assign( $data )
{
// return null if we have no data
if ( $data === null || empty( $data ) )
{
return null;
}
// do we have a collection or a single result?
if ( CCArr::is_collection( $data ) )
{
$return = array();
foreach( $data as $key => $item )
{
$return[$key] = static::create( $item );
}
return $return;
}
return static::create( $data );
}
|
[
"public",
"static",
"function",
"assign",
"(",
"$",
"data",
")",
"{",
"// return null if we have no data",
"if",
"(",
"$",
"data",
"===",
"null",
"||",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"null",
";",
"}",
"// do we have a collection or a single result?",
"if",
"(",
"CCArr",
"::",
"is_collection",
"(",
"$",
"data",
")",
")",
"{",
"$",
"return",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"static",
"::",
"create",
"(",
"$",
"item",
")",
";",
"}",
"return",
"$",
"return",
";",
"}",
"return",
"static",
"::",
"create",
"(",
"$",
"data",
")",
";",
"}"
] |
Assign an model with some data
@param array $data
@return CCModel
|
[
"Assign",
"an",
"model",
"with",
"some",
"data"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCModel.php#L169-L190
|
ClanCats/Core
|
src/classes/CCModel.php
|
CCModel.__
|
public function __( $key, $params = array() )
{
$namespace = explode( "\\", get_called_class() );
$class = strtolower( 'model/'.str_replace( '_', '/', array_pop( $namespace ) ) );
$namespace = implode( "\\", $namespace );
if ( $namespace )
{
$class = $namespace.'::'.$class;
}
return __( $class.'.label.'.$key, $params );
}
|
php
|
public function __( $key, $params = array() )
{
$namespace = explode( "\\", get_called_class() );
$class = strtolower( 'model/'.str_replace( '_', '/', array_pop( $namespace ) ) );
$namespace = implode( "\\", $namespace );
if ( $namespace )
{
$class = $namespace.'::'.$class;
}
return __( $class.'.label.'.$key, $params );
}
|
[
"public",
"function",
"__",
"(",
"$",
"key",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"namespace",
"=",
"explode",
"(",
"\"\\\\\"",
",",
"get_called_class",
"(",
")",
")",
";",
"$",
"class",
"=",
"strtolower",
"(",
"'model/'",
".",
"str_replace",
"(",
"'_'",
",",
"'/'",
",",
"array_pop",
"(",
"$",
"namespace",
")",
")",
")",
";",
"$",
"namespace",
"=",
"implode",
"(",
"\"\\\\\"",
",",
"$",
"namespace",
")",
";",
"if",
"(",
"$",
"namespace",
")",
"{",
"$",
"class",
"=",
"$",
"namespace",
".",
"'::'",
".",
"$",
"class",
";",
"}",
"return",
"__",
"(",
"$",
"class",
".",
"'.label.'",
".",
"$",
"key",
",",
"$",
"params",
")",
";",
"}"
] |
Label translation helper
@param string $key
@param array $params
@return string
|
[
"Label",
"translation",
"helper"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCModel.php#L234-L248
|
ClanCats/Core
|
src/classes/CCModel.php
|
CCModel._assign
|
public function _assign( $data )
{
$data = $this->_before_assign( $data );
$types = static::_model( 'types' );
foreach( $data as $key => $value )
{
if ( array_key_exists( $key, $this->_data_store ) )
{
// do we have to to something with the data type?
if ( array_key_exists( $key, $types ) )
{
$value = $this->_type_assignment_get( $types[$key], $value );
}
$this->_data_store[$key] = $value;
}
}
return $this;
}
|
php
|
public function _assign( $data )
{
$data = $this->_before_assign( $data );
$types = static::_model( 'types' );
foreach( $data as $key => $value )
{
if ( array_key_exists( $key, $this->_data_store ) )
{
// do we have to to something with the data type?
if ( array_key_exists( $key, $types ) )
{
$value = $this->_type_assignment_get( $types[$key], $value );
}
$this->_data_store[$key] = $value;
}
}
return $this;
}
|
[
"public",
"function",
"_assign",
"(",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"_before_assign",
"(",
"$",
"data",
")",
";",
"$",
"types",
"=",
"static",
"::",
"_model",
"(",
"'types'",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"_data_store",
")",
")",
"{",
"// do we have to to something with the data type?",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"types",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"_type_assignment_get",
"(",
"$",
"types",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"_data_store",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Assign an model with some data
@param array $data
@return self
|
[
"Assign",
"an",
"model",
"with",
"some",
"data"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCModel.php#L256-L277
|
ClanCats/Core
|
src/classes/CCModel.php
|
CCModel.strict_assign
|
public function strict_assign( array $fields, array $data )
{
foreach( $fields as $field )
{
if ( isset( $data[$field] ) )
{
$this->__set( $field, $data[$field] );
}
}
}
|
php
|
public function strict_assign( array $fields, array $data )
{
foreach( $fields as $field )
{
if ( isset( $data[$field] ) )
{
$this->__set( $field, $data[$field] );
}
}
}
|
[
"public",
"function",
"strict_assign",
"(",
"array",
"$",
"fields",
",",
"array",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"this",
"->",
"__set",
"(",
"$",
"field",
",",
"$",
"data",
"[",
"$",
"field",
"]",
")",
";",
"}",
"}",
"}"
] |
Strict assign only sets some values out of an array.
This can be useful to easly set some values from post.
example:
$model->srtict_assign( array( 'name', 'description' ), CCIn::all( 'post' ) )
@param array $fields
@param array $data
@return void
|
[
"Strict",
"assign",
"only",
"sets",
"some",
"values",
"out",
"of",
"an",
"array",
".",
"This",
"can",
"be",
"useful",
"to",
"easly",
"set",
"some",
"values",
"from",
"post",
"."
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCModel.php#L290-L299
|
ClanCats/Core
|
src/classes/CCModel.php
|
CCModel._type_assignment_set
|
protected function _type_assignment_set( $type, $value )
{
switch ( $type )
{
case 'int':
case 'timestamp':
return (int) $value;
break;
case 'string':
return (string) $value;
break;
case 'bool':
return (bool) $value;
break;
// json datatype simply encode
case 'json':
return json_encode( $value );
break;
}
return $value;
}
|
php
|
protected function _type_assignment_set( $type, $value )
{
switch ( $type )
{
case 'int':
case 'timestamp':
return (int) $value;
break;
case 'string':
return (string) $value;
break;
case 'bool':
return (bool) $value;
break;
// json datatype simply encode
case 'json':
return json_encode( $value );
break;
}
return $value;
}
|
[
"protected",
"function",
"_type_assignment_set",
"(",
"$",
"type",
",",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'int'",
":",
"case",
"'timestamp'",
":",
"return",
"(",
"int",
")",
"$",
"value",
";",
"break",
";",
"case",
"'string'",
":",
"return",
"(",
"string",
")",
"$",
"value",
";",
"break",
";",
"case",
"'bool'",
":",
"return",
"(",
"bool",
")",
"$",
"value",
";",
"break",
";",
"// json datatype simply encode",
"case",
"'json'",
":",
"return",
"json_encode",
"(",
"$",
"value",
")",
";",
"break",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Assign the data type in a set operation
@param string $type
@param mixed $value
@return mixed
|
[
"Assign",
"the",
"data",
"type",
"in",
"a",
"set",
"operation"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCModel.php#L308-L332
|
ClanCats/Core
|
src/classes/CCModel.php
|
CCModel._type_assignment_get
|
protected function _type_assignment_get( $type, $value )
{
switch ( $type )
{
case 'int':
case 'timestamp':
return (int) $value;
break;
case 'string':
return (string) $value;
break;
case 'bool':
return (bool) $value;
break;
// json datatype try to decode return array on failure
case 'json':
if ( is_array( $value ) )
{
return $value;
}
if ( is_array( $value = json_decode( $value, true ) ) )
{
return $value;
}
return array();
break;
}
return $value;
}
|
php
|
protected function _type_assignment_get( $type, $value )
{
switch ( $type )
{
case 'int':
case 'timestamp':
return (int) $value;
break;
case 'string':
return (string) $value;
break;
case 'bool':
return (bool) $value;
break;
// json datatype try to decode return array on failure
case 'json':
if ( is_array( $value ) )
{
return $value;
}
if ( is_array( $value = json_decode( $value, true ) ) )
{
return $value;
}
return array();
break;
}
return $value;
}
|
[
"protected",
"function",
"_type_assignment_get",
"(",
"$",
"type",
",",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'int'",
":",
"case",
"'timestamp'",
":",
"return",
"(",
"int",
")",
"$",
"value",
";",
"break",
";",
"case",
"'string'",
":",
"return",
"(",
"string",
")",
"$",
"value",
";",
"break",
";",
"case",
"'bool'",
":",
"return",
"(",
"bool",
")",
"$",
"value",
";",
"break",
";",
"// json datatype try to decode return array on failure",
"case",
"'json'",
":",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
"=",
"json_decode",
"(",
"$",
"value",
",",
"true",
")",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"array",
"(",
")",
";",
"break",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Assign the data type in a get operation
@param string $type
@param mixed $value
@return mixed
|
[
"Assign",
"the",
"data",
"type",
"in",
"a",
"get",
"operation"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCModel.php#L341-L373
|
ClanCats/Core
|
src/classes/CCModel.php
|
CCModel.&
|
public function &__get( $key )
{
$value = null;
// check if the modifier exists
$has_modifier = method_exists( $this, '_get_modifier_'.$key );
// try getting the item
if ( array_key_exists( $key, $this->_data_store ) )
{
$value =& $this->_data_store[$key];
if ( $has_modifier )
{
$tmpvalue = $this->{'_get_modifier_'.$key}( $value ); return $tmpvalue;
}
return $value;
}
if ( $has_modifier )
{
$value = $this->{'_get_modifier_'.$key}(); return $value;
}
// when a function extists we forward the call
if ( method_exists( $this, $key ) )
{
$value = $this->__call_property( $key ); return $value;
}
throw new \InvalidArgumentException( "CCModel - Invalid or undefined model property '".$key."'." );
}
|
php
|
public function &__get( $key )
{
$value = null;
// check if the modifier exists
$has_modifier = method_exists( $this, '_get_modifier_'.$key );
// try getting the item
if ( array_key_exists( $key, $this->_data_store ) )
{
$value =& $this->_data_store[$key];
if ( $has_modifier )
{
$tmpvalue = $this->{'_get_modifier_'.$key}( $value ); return $tmpvalue;
}
return $value;
}
if ( $has_modifier )
{
$value = $this->{'_get_modifier_'.$key}(); return $value;
}
// when a function extists we forward the call
if ( method_exists( $this, $key ) )
{
$value = $this->__call_property( $key ); return $value;
}
throw new \InvalidArgumentException( "CCModel - Invalid or undefined model property '".$key."'." );
}
|
[
"public",
"function",
"&",
"__get",
"(",
"$",
"key",
")",
"{",
"$",
"value",
"=",
"null",
";",
"// check if the modifier exists",
"$",
"has_modifier",
"=",
"method_exists",
"(",
"$",
"this",
",",
"'_get_modifier_'",
".",
"$",
"key",
")",
";",
"// try getting the item",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"_data_store",
")",
")",
"{",
"$",
"value",
"=",
"&",
"$",
"this",
"->",
"_data_store",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"$",
"has_modifier",
")",
"{",
"$",
"tmpvalue",
"=",
"$",
"this",
"->",
"{",
"'_get_modifier_'",
".",
"$",
"key",
"}",
"(",
"$",
"value",
")",
";",
"return",
"$",
"tmpvalue",
";",
"}",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"has_modifier",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"{",
"'_get_modifier_'",
".",
"$",
"key",
"}",
"(",
")",
";",
"return",
"$",
"value",
";",
"}",
"// when a function extists we forward the call",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"key",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"__call_property",
"(",
"$",
"key",
")",
";",
"return",
"$",
"value",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"CCModel - Invalid or undefined model property '\"",
".",
"$",
"key",
".",
"\"'.\"",
")",
";",
"}"
] |
Get a value by key from the model data
@param string $key
@return mixed
|
[
"Get",
"a",
"value",
"by",
"key",
"from",
"the",
"model",
"data"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCModel.php#L390-L422
|
ClanCats/Core
|
src/classes/CCModel.php
|
CCModel.__isset
|
public function __isset( $key )
{
return ( array_key_exists( $key, $this->_data_store ) || method_exists( $this, '_get_modifier_'.$key ) ) ? true : false;
}
|
php
|
public function __isset( $key )
{
return ( array_key_exists( $key, $this->_data_store ) || method_exists( $this, '_get_modifier_'.$key ) ) ? true : false;
}
|
[
"public",
"function",
"__isset",
"(",
"$",
"key",
")",
"{",
"return",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"_data_store",
")",
"||",
"method_exists",
"(",
"$",
"this",
",",
"'_get_modifier_'",
".",
"$",
"key",
")",
")",
"?",
"true",
":",
"false",
";",
"}"
] |
Check if model data isset
This also checks if a get modifier function exists which will also count as ture.
@param $key
@return bool
|
[
"Check",
"if",
"model",
"data",
"isset",
"This",
"also",
"checks",
"if",
"a",
"get",
"modifier",
"function",
"exists",
"which",
"will",
"also",
"count",
"as",
"ture",
"."
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCModel.php#L456-L459
|
ClanCats/Core
|
src/classes/CCModel.php
|
CCModel.raw
|
public function raw( $key = null )
{
if ( !is_null( $key ) )
{
if ( isset( $this->_data_store[$key] ) )
{
return $this->_data_store[$key];
}
throw new \InvalidArgumentException( "CCModel - Invalid or undefined model property '".$key."'." );
}
return $this->_data_store;
}
|
php
|
public function raw( $key = null )
{
if ( !is_null( $key ) )
{
if ( isset( $this->_data_store[$key] ) )
{
return $this->_data_store[$key];
}
throw new \InvalidArgumentException( "CCModel - Invalid or undefined model property '".$key."'." );
}
return $this->_data_store;
}
|
[
"public",
"function",
"raw",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_data_store",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_data_store",
"[",
"$",
"key",
"]",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"CCModel - Invalid or undefined model property '\"",
".",
"$",
"key",
".",
"\"'.\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_data_store",
";",
"}"
] |
Returns all raw data of the object or a single property
$model->raw();
$model->raw( 'key' );
@param string $key
@return array
|
[
"Returns",
"all",
"raw",
"data",
"of",
"the",
"object",
"or",
"a",
"single",
"property"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCModel.php#L470-L483
|
ClanCats/Core
|
src/classes/CCModel.php
|
CCModel.as_array
|
public function as_array( $modifiers = true )
{
$settings = static::_model();
// get the available keys
$keys = ( $this->_data_store );
// remove the hidden ones
$keys = array_diff_key( $keys, $settings['hidden'] );
// add this moment we can simply return when
// we dont wish to execute the modifiers
if ( $modifiers === false )
{
return $keys;
}
// add the visible keys
foreach( $settings['visible'] as $key => $value )
{
$keys[$key] = null;
}
// run the modifiers
foreach( $keys as $key => $value )
{
$keys[$key] = $this->$key;
}
return $keys;
}
|
php
|
public function as_array( $modifiers = true )
{
$settings = static::_model();
// get the available keys
$keys = ( $this->_data_store );
// remove the hidden ones
$keys = array_diff_key( $keys, $settings['hidden'] );
// add this moment we can simply return when
// we dont wish to execute the modifiers
if ( $modifiers === false )
{
return $keys;
}
// add the visible keys
foreach( $settings['visible'] as $key => $value )
{
$keys[$key] = null;
}
// run the modifiers
foreach( $keys as $key => $value )
{
$keys[$key] = $this->$key;
}
return $keys;
}
|
[
"public",
"function",
"as_array",
"(",
"$",
"modifiers",
"=",
"true",
")",
"{",
"$",
"settings",
"=",
"static",
"::",
"_model",
"(",
")",
";",
"// get the available keys",
"$",
"keys",
"=",
"(",
"$",
"this",
"->",
"_data_store",
")",
";",
"// remove the hidden ones",
"$",
"keys",
"=",
"array_diff_key",
"(",
"$",
"keys",
",",
"$",
"settings",
"[",
"'hidden'",
"]",
")",
";",
"// add this moment we can simply return when ",
"// we dont wish to execute the modifiers",
"if",
"(",
"$",
"modifiers",
"===",
"false",
")",
"{",
"return",
"$",
"keys",
";",
"}",
"// add the visible keys",
"foreach",
"(",
"$",
"settings",
"[",
"'visible'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"keys",
"[",
"$",
"key",
"]",
"=",
"null",
";",
"}",
"// run the modifiers",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"keys",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"$",
"key",
";",
"}",
"return",
"$",
"keys",
";",
"}"
] |
Get the object as array
When $modifiers is true, then the data will be passed trough the modifiers
@param bool $modifiers
@return array
|
[
"Get",
"the",
"object",
"as",
"array",
"When",
"$modifiers",
"is",
"true",
"then",
"the",
"data",
"will",
"be",
"passed",
"trough",
"the",
"modifiers"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCModel.php#L506-L536
|
ClanCats/Core
|
src/classes/CCModel.php
|
CCModel.as_json
|
public function as_json( $modifiers = true, $beautify = true )
{
return CCJson::encode( $this->as_array( $modifiers ), $beautify );
}
|
php
|
public function as_json( $modifiers = true, $beautify = true )
{
return CCJson::encode( $this->as_array( $modifiers ), $beautify );
}
|
[
"public",
"function",
"as_json",
"(",
"$",
"modifiers",
"=",
"true",
",",
"$",
"beautify",
"=",
"true",
")",
"{",
"return",
"CCJson",
"::",
"encode",
"(",
"$",
"this",
"->",
"as_array",
"(",
"$",
"modifiers",
")",
",",
"$",
"beautify",
")",
";",
"}"
] |
Get the object as json
When $modifiers is true, then the data will be passed trough the modifiers
@param bool $modifiers
@param bool $beautify
@return string
|
[
"Get",
"the",
"object",
"as",
"json",
"When",
"$modifiers",
"is",
"true",
"then",
"the",
"data",
"will",
"be",
"passed",
"trough",
"the",
"modifiers"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCModel.php#L546-L549
|
spiral-modules/scaffolder
|
source/Scaffolder/Commands/RequestCommand.php
|
RequestCommand.parseField
|
private function parseField(string $field): array
{
$source = static::DEFAULT_SOURCE;
$type = static::DEFAULT_TYPE;
$origin = null;
if (strpos($field, '(') !== false) {
$source = substr($field, strpos($field, '(') + 1, -1);
$field = substr($field, 0, strpos($field, '('));
if (strpos($source, ':') !== false) {
list($source, $origin) = explode(':', $source);
}
}
if (strpos($field, ':') !== false) {
list($field, $type) = explode(':', $field);
}
return [$field, $type, $source, $origin];
}
|
php
|
private function parseField(string $field): array
{
$source = static::DEFAULT_SOURCE;
$type = static::DEFAULT_TYPE;
$origin = null;
if (strpos($field, '(') !== false) {
$source = substr($field, strpos($field, '(') + 1, -1);
$field = substr($field, 0, strpos($field, '('));
if (strpos($source, ':') !== false) {
list($source, $origin) = explode(':', $source);
}
}
if (strpos($field, ':') !== false) {
list($field, $type) = explode(':', $field);
}
return [$field, $type, $source, $origin];
}
|
[
"private",
"function",
"parseField",
"(",
"string",
"$",
"field",
")",
":",
"array",
"{",
"$",
"source",
"=",
"static",
"::",
"DEFAULT_SOURCE",
";",
"$",
"type",
"=",
"static",
"::",
"DEFAULT_TYPE",
";",
"$",
"origin",
"=",
"null",
";",
"if",
"(",
"strpos",
"(",
"$",
"field",
",",
"'('",
")",
"!==",
"false",
")",
"{",
"$",
"source",
"=",
"substr",
"(",
"$",
"field",
",",
"strpos",
"(",
"$",
"field",
",",
"'('",
")",
"+",
"1",
",",
"-",
"1",
")",
";",
"$",
"field",
"=",
"substr",
"(",
"$",
"field",
",",
"0",
",",
"strpos",
"(",
"$",
"field",
",",
"'('",
")",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"source",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"source",
",",
"$",
"origin",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"source",
")",
";",
"}",
"}",
"if",
"(",
"strpos",
"(",
"$",
"field",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"field",
",",
"$",
"type",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"field",
")",
";",
"}",
"return",
"[",
"$",
"field",
",",
"$",
"type",
",",
"$",
"source",
",",
"$",
"origin",
"]",
";",
"}"
] |
Parse field to fetch source, origin and type.
@param string $field
@return array
|
[
"Parse",
"field",
"to",
"fetch",
"source",
"origin",
"and",
"type",
"."
] |
train
|
https://github.com/spiral-modules/scaffolder/blob/9be9dd0da6e4b02232db24e797fe5c288afbbddf/source/Scaffolder/Commands/RequestCommand.php#L69-L89
|
ufocoder/yii2-SyncSocial
|
src/actions/ActionSynchronize.php
|
ActionSynchronize.initialRedirectUrl
|
protected function initialRedirectUrl() {
$defaultUrl = '/'. $this->controller->id . '/' . $this->controller->defaultAction;
if (isset($this->controller->module->id) && !$this->controller->module instanceof Application) {
$defaultUrl = '/' . $this->controller->module->id . $defaultUrl;
}
if ( empty( $this->successUrl ) ) {
$this->successUrl = $defaultUrl;
}
if ( empty( $this->failedUrl ) ) {
$this->failedUrl = $defaultUrl;
}
}
|
php
|
protected function initialRedirectUrl() {
$defaultUrl = '/'. $this->controller->id . '/' . $this->controller->defaultAction;
if (isset($this->controller->module->id) && !$this->controller->module instanceof Application) {
$defaultUrl = '/' . $this->controller->module->id . $defaultUrl;
}
if ( empty( $this->successUrl ) ) {
$this->successUrl = $defaultUrl;
}
if ( empty( $this->failedUrl ) ) {
$this->failedUrl = $defaultUrl;
}
}
|
[
"protected",
"function",
"initialRedirectUrl",
"(",
")",
"{",
"$",
"defaultUrl",
"=",
"'/'",
".",
"$",
"this",
"->",
"controller",
"->",
"id",
".",
"'/'",
".",
"$",
"this",
"->",
"controller",
"->",
"defaultAction",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"controller",
"->",
"module",
"->",
"id",
")",
"&&",
"!",
"$",
"this",
"->",
"controller",
"->",
"module",
"instanceof",
"Application",
")",
"{",
"$",
"defaultUrl",
"=",
"'/'",
".",
"$",
"this",
"->",
"controller",
"->",
"module",
"->",
"id",
".",
"$",
"defaultUrl",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"successUrl",
")",
")",
"{",
"$",
"this",
"->",
"successUrl",
"=",
"$",
"defaultUrl",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"failedUrl",
")",
")",
"{",
"$",
"this",
"->",
"failedUrl",
"=",
"$",
"defaultUrl",
";",
"}",
"}"
] |
Set default redirect url
|
[
"Set",
"default",
"redirect",
"url"
] |
train
|
https://github.com/ufocoder/yii2-SyncSocial/blob/2dbaaec2dad782c52fdd5b648a31ba7fe2a75e1b/src/actions/ActionSynchronize.php#L37-L53
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.