id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
12,700 | AlcyZ/Alcys-ORM | src/Core/Db/Factory/DbFactory.php | DbFactory.builder | public function builder(StatementInterface $statement)
{
if($statement instanceof Insert)
{
return new InsertBuilder($statement);
}
/** @var ExpressionBuilderFactoryInterface $factory */
$factory = $this->expression('BuilderFactory');
if($statement instanceof Select)
{
return new SelectBuilder($statement, $factory);
}
elseif($statement instanceof Update)
{
return new UpdateBuilder($statement, $factory);
}
else
{
/** @var Delete $statement */
return new DeleteBuilder($statement, $factory);
}
} | php | public function builder(StatementInterface $statement)
{
if($statement instanceof Insert)
{
return new InsertBuilder($statement);
}
/** @var ExpressionBuilderFactoryInterface $factory */
$factory = $this->expression('BuilderFactory');
if($statement instanceof Select)
{
return new SelectBuilder($statement, $factory);
}
elseif($statement instanceof Update)
{
return new UpdateBuilder($statement, $factory);
}
else
{
/** @var Delete $statement */
return new DeleteBuilder($statement, $factory);
}
} | [
"public",
"function",
"builder",
"(",
"StatementInterface",
"$",
"statement",
")",
"{",
"if",
"(",
"$",
"statement",
"instanceof",
"Insert",
")",
"{",
"return",
"new",
"InsertBuilder",
"(",
"$",
"statement",
")",
";",
"}",
"/** @var ExpressionBuilderFactoryInterface $factory */",
"$",
"factory",
"=",
"$",
"this",
"->",
"expression",
"(",
"'BuilderFactory'",
")",
";",
"if",
"(",
"$",
"statement",
"instanceof",
"Select",
")",
"{",
"return",
"new",
"SelectBuilder",
"(",
"$",
"statement",
",",
"$",
"factory",
")",
";",
"}",
"elseif",
"(",
"$",
"statement",
"instanceof",
"Update",
")",
"{",
"return",
"new",
"UpdateBuilder",
"(",
"$",
"statement",
",",
"$",
"factory",
")",
";",
"}",
"else",
"{",
"/** @var Delete $statement */",
"return",
"new",
"DeleteBuilder",
"(",
"$",
"statement",
",",
"$",
"factory",
")",
";",
"}",
"}"
] | Create an instance of a query builder.
Different between the several statement types and return the correct query builder for the passed statement.
@param StatementInterface $statement The statement value object, from which should the a query build.
@return DeleteBuilder|InsertBuilder|SelectBuilder|UpdateBuilder An instance of QueryBuilder,
switched by the passed argument. | [
"Create",
"an",
"instance",
"of",
"a",
"query",
"builder",
".",
"Different",
"between",
"the",
"several",
"statement",
"types",
"and",
"return",
"the",
"correct",
"query",
"builder",
"for",
"the",
"passed",
"statement",
"."
] | dd30946ad35ab06cba2167cf6dfa02b733614720 | https://github.com/AlcyZ/Alcys-ORM/blob/dd30946ad35ab06cba2167cf6dfa02b733614720/src/Core/Db/Factory/DbFactory.php#L107-L129 |
12,701 | AlcyZ/Alcys-ORM | src/Core/Db/Factory/DbFactory.php | DbFactory._invokeCreateMethod | private function _invokeCreateMethod($type, $name, array $arguments)
{
$createMethodName = '_create' . $type . $name;
if(method_exists($this, $createMethodName))
{
return $this->$createMethodName($arguments);
}
throw new \Exception('no creation method for the ' . strtolower($type) . ' class ' . $name . ' found!');
} | php | private function _invokeCreateMethod($type, $name, array $arguments)
{
$createMethodName = '_create' . $type . $name;
if(method_exists($this, $createMethodName))
{
return $this->$createMethodName($arguments);
}
throw new \Exception('no creation method for the ' . strtolower($type) . ' class ' . $name . ' found!');
} | [
"private",
"function",
"_invokeCreateMethod",
"(",
"$",
"type",
",",
"$",
"name",
",",
"array",
"$",
"arguments",
")",
"{",
"$",
"createMethodName",
"=",
"'_create'",
".",
"$",
"type",
".",
"$",
"name",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"createMethodName",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"createMethodName",
"(",
"$",
"arguments",
")",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"'no creation method for the '",
".",
"strtolower",
"(",
"$",
"type",
")",
".",
"' class '",
".",
"$",
"name",
".",
"' found!'",
")",
";",
"}"
] | Invoke the expected private create method.
@param string $type The type, like 'statement' or 'queryBuilder' of the instance that should create.
@param string $name The specific name of the class that will instantiating.
@param array $arguments Arguments that should passed to the constructor of the created object.
@return mixed
@throws \Exception | [
"Invoke",
"the",
"expected",
"private",
"create",
"method",
"."
] | dd30946ad35ab06cba2167cf6dfa02b733614720 | https://github.com/AlcyZ/Alcys-ORM/blob/dd30946ad35ab06cba2167cf6dfa02b733614720/src/Core/Db/Factory/DbFactory.php#L210-L218 |
12,702 | AlcyZ/Alcys-ORM | src/Core/Db/Factory/DbFactory.php | DbFactory._createReferencesColumn | private function _createReferencesColumn(array $args)
{
$this->_checkSecondArgument($args);
$table = (isset($args[2])) ? $args[2] : null;
$alias = (isset($args[3])) ? $args[3] : null;
return new Column($args[1], $table, $alias);
} | php | private function _createReferencesColumn(array $args)
{
$this->_checkSecondArgument($args);
$table = (isset($args[2])) ? $args[2] : null;
$alias = (isset($args[3])) ? $args[3] : null;
return new Column($args[1], $table, $alias);
} | [
"private",
"function",
"_createReferencesColumn",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"_checkSecondArgument",
"(",
"$",
"args",
")",
";",
"$",
"table",
"=",
"(",
"isset",
"(",
"$",
"args",
"[",
"2",
"]",
")",
")",
"?",
"$",
"args",
"[",
"2",
"]",
":",
"null",
";",
"$",
"alias",
"=",
"(",
"isset",
"(",
"$",
"args",
"[",
"3",
"]",
")",
")",
"?",
"$",
"args",
"[",
"3",
"]",
":",
"null",
";",
"return",
"new",
"Column",
"(",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"table",
",",
"$",
"alias",
")",
";",
"}"
] | Create an instance of a column references.
@param array $args The arguments that are passed from the clients executed method. Bundled in an array.
@return Column The validated column object, that can easily parsed to a string with casting (string).
@throws \Exception | [
"Create",
"an",
"instance",
"of",
"a",
"column",
"references",
"."
] | dd30946ad35ab06cba2167cf6dfa02b733614720 | https://github.com/AlcyZ/Alcys-ORM/blob/dd30946ad35ab06cba2167cf6dfa02b733614720/src/Core/Db/Factory/DbFactory.php#L306-L313 |
12,703 | AlcyZ/Alcys-ORM | src/Core/Db/Factory/DbFactory.php | DbFactory._createReferencesSqlFunction | private function _createReferencesSqlFunction(array $args)
{
$this->_checkSecondArgument($args);
if(isset($args[2]) && !is_array($args[2]))
{
throw new \Exception('sql function references argument have to be an array or null!');
}
$argArray = (isset($args[2])) ? $args[2] : array();
return new SqlFunction($args[1], $argArray);
} | php | private function _createReferencesSqlFunction(array $args)
{
$this->_checkSecondArgument($args);
if(isset($args[2]) && !is_array($args[2]))
{
throw new \Exception('sql function references argument have to be an array or null!');
}
$argArray = (isset($args[2])) ? $args[2] : array();
return new SqlFunction($args[1], $argArray);
} | [
"private",
"function",
"_createReferencesSqlFunction",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"_checkSecondArgument",
"(",
"$",
"args",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"2",
"]",
")",
"&&",
"!",
"is_array",
"(",
"$",
"args",
"[",
"2",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'sql function references argument have to be an array or null!'",
")",
";",
"}",
"$",
"argArray",
"=",
"(",
"isset",
"(",
"$",
"args",
"[",
"2",
"]",
")",
")",
"?",
"$",
"args",
"[",
"2",
"]",
":",
"array",
"(",
")",
";",
"return",
"new",
"SqlFunction",
"(",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"argArray",
")",
";",
"}"
] | Create an instance of a sql function references object.
@param array $args The arguments that are passed from the clients executed method. Bundled in an array.
@return SqlFunction The validated sql function object, that can easily parsed to a string with casting (string).
@throws \Exception | [
"Create",
"an",
"instance",
"of",
"a",
"sql",
"function",
"references",
"object",
"."
] | dd30946ad35ab06cba2167cf6dfa02b733614720 | https://github.com/AlcyZ/Alcys-ORM/blob/dd30946ad35ab06cba2167cf6dfa02b733614720/src/Core/Db/Factory/DbFactory.php#L341-L351 |
12,704 | AlcyZ/Alcys-ORM | src/Core/Db/Factory/DbFactory.php | DbFactory._createReferencesTable | private function _createReferencesTable(array $args)
{
$this->_checkSecondArgument($args);
$alias = (isset($args[2])) ? $args[2] : null;
return new Table($args[1], $alias);
} | php | private function _createReferencesTable(array $args)
{
$this->_checkSecondArgument($args);
$alias = (isset($args[2])) ? $args[2] : null;
return new Table($args[1], $alias);
} | [
"private",
"function",
"_createReferencesTable",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"_checkSecondArgument",
"(",
"$",
"args",
")",
";",
"$",
"alias",
"=",
"(",
"isset",
"(",
"$",
"args",
"[",
"2",
"]",
")",
")",
"?",
"$",
"args",
"[",
"2",
"]",
":",
"null",
";",
"return",
"new",
"Table",
"(",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"alias",
")",
";",
"}"
] | Create an instance of a table references object.
@param array $args The arguments that are passed from the clients executed method. Bundled in an array.
@return Table The validated table object, that can easily parsed to a string with casting (string).
@throws \Exception | [
"Create",
"an",
"instance",
"of",
"a",
"table",
"references",
"object",
"."
] | dd30946ad35ab06cba2167cf6dfa02b733614720 | https://github.com/AlcyZ/Alcys-ORM/blob/dd30946ad35ab06cba2167cf6dfa02b733614720/src/Core/Db/Factory/DbFactory.php#L362-L368 |
12,705 | laravelflare/media | src/Media/Http/Controllers/MediaAdminController.php | MediaAdminController.postCreate | public function postCreate(MediaCreateRequest $request)
{
$media = Media::create($request->all());
return redirect($this->admin->currentUrl('view/'.$media->id))->with('notifications_below_header', [['type' => 'success', 'icon' => 'check-circle', 'title' => 'Success!', 'message' => 'Your Media was successfully added.', 'dismissable' => false]]);
} | php | public function postCreate(MediaCreateRequest $request)
{
$media = Media::create($request->all());
return redirect($this->admin->currentUrl('view/'.$media->id))->with('notifications_below_header', [['type' => 'success', 'icon' => 'check-circle', 'title' => 'Success!', 'message' => 'Your Media was successfully added.', 'dismissable' => false]]);
} | [
"public",
"function",
"postCreate",
"(",
"MediaCreateRequest",
"$",
"request",
")",
"{",
"$",
"media",
"=",
"Media",
"::",
"create",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"return",
"redirect",
"(",
"$",
"this",
"->",
"admin",
"->",
"currentUrl",
"(",
"'view/'",
".",
"$",
"media",
"->",
"id",
")",
")",
"->",
"with",
"(",
"'notifications_below_header'",
",",
"[",
"[",
"'type'",
"=>",
"'success'",
",",
"'icon'",
"=>",
"'check-circle'",
",",
"'title'",
"=>",
"'Success!'",
",",
"'message'",
"=>",
"'Your Media was successfully added.'",
",",
"'dismissable'",
"=>",
"false",
"]",
"]",
")",
";",
"}"
] | Processes a new Media Request.
@return \Illuminate\Http\RedirectResponse | [
"Processes",
"a",
"new",
"Media",
"Request",
"."
] | 380a9d3f7c2fc370c2cbd34a77ced87675fc8491 | https://github.com/laravelflare/media/blob/380a9d3f7c2fc370c2cbd34a77ced87675fc8491/src/Media/Http/Controllers/MediaAdminController.php#L68-L73 |
12,706 | laravelflare/media | src/Media/Http/Controllers/MediaAdminController.php | MediaAdminController.postUpload | public function postUpload(Request $request)
{
if (!$request->file('file')) {
return [];
}
$filename = time().'-'.$request->file('file')->getClientOriginalName();
$request->file('file')->move('uploads/media', $filename);
foreach (\Config::get('flare-config.media.resize') as $sizeArray) {
$newfilename = $sizeArray[0].'-'.(array_key_exists(1, $sizeArray) ? $sizeArray[1] : $sizeArray[0]).'-'.$filename;
Image::make('uploads/media/'.$filename)->fit($sizeArray[0], (array_key_exists(1, $sizeArray) ? $sizeArray[1] : $sizeArray[0]))->save('uploads/media/'.$newfilename);
}
$media = Media::create([
'name' => $request->file('file')->getClientOriginalName(),
'path' => $filename,
'extension' => $request->file('file')->getClientOriginalExtension(),
'mimetype' => $request->file('file')->getClientMimeType(),
'size' => $request->file('file')->getClientSize(),
]);
$file = new \stdClass();
$file->name = $media->name;
$file->url = url('uploads/media/'.$media->path);
$file->thumbnailUrl = url('uploads/media/100-100-'.$media->path);
$file->type = $media->mimetype;
$file->size = $media->size;
$object = new \stdClass();
$object->files = [$file];
return json_encode($object);
} | php | public function postUpload(Request $request)
{
if (!$request->file('file')) {
return [];
}
$filename = time().'-'.$request->file('file')->getClientOriginalName();
$request->file('file')->move('uploads/media', $filename);
foreach (\Config::get('flare-config.media.resize') as $sizeArray) {
$newfilename = $sizeArray[0].'-'.(array_key_exists(1, $sizeArray) ? $sizeArray[1] : $sizeArray[0]).'-'.$filename;
Image::make('uploads/media/'.$filename)->fit($sizeArray[0], (array_key_exists(1, $sizeArray) ? $sizeArray[1] : $sizeArray[0]))->save('uploads/media/'.$newfilename);
}
$media = Media::create([
'name' => $request->file('file')->getClientOriginalName(),
'path' => $filename,
'extension' => $request->file('file')->getClientOriginalExtension(),
'mimetype' => $request->file('file')->getClientMimeType(),
'size' => $request->file('file')->getClientSize(),
]);
$file = new \stdClass();
$file->name = $media->name;
$file->url = url('uploads/media/'.$media->path);
$file->thumbnailUrl = url('uploads/media/100-100-'.$media->path);
$file->type = $media->mimetype;
$file->size = $media->size;
$object = new \stdClass();
$object->files = [$file];
return json_encode($object);
} | [
"public",
"function",
"postUpload",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"$",
"request",
"->",
"file",
"(",
"'file'",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"filename",
"=",
"time",
"(",
")",
".",
"'-'",
".",
"$",
"request",
"->",
"file",
"(",
"'file'",
")",
"->",
"getClientOriginalName",
"(",
")",
";",
"$",
"request",
"->",
"file",
"(",
"'file'",
")",
"->",
"move",
"(",
"'uploads/media'",
",",
"$",
"filename",
")",
";",
"foreach",
"(",
"\\",
"Config",
"::",
"get",
"(",
"'flare-config.media.resize'",
")",
"as",
"$",
"sizeArray",
")",
"{",
"$",
"newfilename",
"=",
"$",
"sizeArray",
"[",
"0",
"]",
".",
"'-'",
".",
"(",
"array_key_exists",
"(",
"1",
",",
"$",
"sizeArray",
")",
"?",
"$",
"sizeArray",
"[",
"1",
"]",
":",
"$",
"sizeArray",
"[",
"0",
"]",
")",
".",
"'-'",
".",
"$",
"filename",
";",
"Image",
"::",
"make",
"(",
"'uploads/media/'",
".",
"$",
"filename",
")",
"->",
"fit",
"(",
"$",
"sizeArray",
"[",
"0",
"]",
",",
"(",
"array_key_exists",
"(",
"1",
",",
"$",
"sizeArray",
")",
"?",
"$",
"sizeArray",
"[",
"1",
"]",
":",
"$",
"sizeArray",
"[",
"0",
"]",
")",
")",
"->",
"save",
"(",
"'uploads/media/'",
".",
"$",
"newfilename",
")",
";",
"}",
"$",
"media",
"=",
"Media",
"::",
"create",
"(",
"[",
"'name'",
"=>",
"$",
"request",
"->",
"file",
"(",
"'file'",
")",
"->",
"getClientOriginalName",
"(",
")",
",",
"'path'",
"=>",
"$",
"filename",
",",
"'extension'",
"=>",
"$",
"request",
"->",
"file",
"(",
"'file'",
")",
"->",
"getClientOriginalExtension",
"(",
")",
",",
"'mimetype'",
"=>",
"$",
"request",
"->",
"file",
"(",
"'file'",
")",
"->",
"getClientMimeType",
"(",
")",
",",
"'size'",
"=>",
"$",
"request",
"->",
"file",
"(",
"'file'",
")",
"->",
"getClientSize",
"(",
")",
",",
"]",
")",
";",
"$",
"file",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"file",
"->",
"name",
"=",
"$",
"media",
"->",
"name",
";",
"$",
"file",
"->",
"url",
"=",
"url",
"(",
"'uploads/media/'",
".",
"$",
"media",
"->",
"path",
")",
";",
"$",
"file",
"->",
"thumbnailUrl",
"=",
"url",
"(",
"'uploads/media/100-100-'",
".",
"$",
"media",
"->",
"path",
")",
";",
"$",
"file",
"->",
"type",
"=",
"$",
"media",
"->",
"mimetype",
";",
"$",
"file",
"->",
"size",
"=",
"$",
"media",
"->",
"size",
";",
"$",
"object",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"object",
"->",
"files",
"=",
"[",
"$",
"file",
"]",
";",
"return",
"json_encode",
"(",
"$",
"object",
")",
";",
"}"
] | Process a File Upload from the Jquery File Uploader.
@param Request $request
@return string | [
"Process",
"a",
"File",
"Upload",
"from",
"the",
"Jquery",
"File",
"Uploader",
"."
] | 380a9d3f7c2fc370c2cbd34a77ced87675fc8491 | https://github.com/laravelflare/media/blob/380a9d3f7c2fc370c2cbd34a77ced87675fc8491/src/Media/Http/Controllers/MediaAdminController.php#L92-L125 |
12,707 | laravelflare/media | src/Media/Http/Controllers/MediaAdminController.php | MediaAdminController.postDelete | public function postDelete($mediaId)
{
$media = Media::findOrFail($mediaId);
$media->delete();
return redirect($this->admin->currentUrl())->with('notifications_below_header', [['type' => 'success', 'icon' => 'check-circle', 'title' => 'Success!', 'message' => 'The Media was successfully deleted.', 'dismissable' => false]]);
} | php | public function postDelete($mediaId)
{
$media = Media::findOrFail($mediaId);
$media->delete();
return redirect($this->admin->currentUrl())->with('notifications_below_header', [['type' => 'success', 'icon' => 'check-circle', 'title' => 'Success!', 'message' => 'The Media was successfully deleted.', 'dismissable' => false]]);
} | [
"public",
"function",
"postDelete",
"(",
"$",
"mediaId",
")",
"{",
"$",
"media",
"=",
"Media",
"::",
"findOrFail",
"(",
"$",
"mediaId",
")",
";",
"$",
"media",
"->",
"delete",
"(",
")",
";",
"return",
"redirect",
"(",
"$",
"this",
"->",
"admin",
"->",
"currentUrl",
"(",
")",
")",
"->",
"with",
"(",
"'notifications_below_header'",
",",
"[",
"[",
"'type'",
"=>",
"'success'",
",",
"'icon'",
"=>",
"'check-circle'",
",",
"'title'",
"=>",
"'Success!'",
",",
"'message'",
"=>",
"'The Media was successfully deleted.'",
",",
"'dismissable'",
"=>",
"false",
"]",
"]",
")",
";",
"}"
] | Process Delete Media Request.
@param int $mediaId
@return \Illuminate\Http\RedirectResponse | [
"Process",
"Delete",
"Media",
"Request",
"."
] | 380a9d3f7c2fc370c2cbd34a77ced87675fc8491 | https://github.com/laravelflare/media/blob/380a9d3f7c2fc370c2cbd34a77ced87675fc8491/src/Media/Http/Controllers/MediaAdminController.php#L146-L152 |
12,708 | canis-io/yii2-canis-lib | lib/db/behaviors/Blame.php | Blame.getFields | public function getFields()
{
$ownerClass = get_class($this->owner);
$ownerTable = $ownerClass::tableName();
if (!isset(self::$_fields[$ownerTable])) {
self::$_fields[$ownerTable] = [];
$_f = ['deletedField', 'deletedByField', 'createdField', 'createdByField', 'modifiedField', 'modifiedByField'];
$schema = $ownerClass::getTableSchema();
foreach ($_f as $field) {
if (isset($schema->columns[$this->{$field}])) {
self::$_fields[$ownerTable][$field] = $this->{$field};
}
}
}
return self::$_fields[$ownerTable];
} | php | public function getFields()
{
$ownerClass = get_class($this->owner);
$ownerTable = $ownerClass::tableName();
if (!isset(self::$_fields[$ownerTable])) {
self::$_fields[$ownerTable] = [];
$_f = ['deletedField', 'deletedByField', 'createdField', 'createdByField', 'modifiedField', 'modifiedByField'];
$schema = $ownerClass::getTableSchema();
foreach ($_f as $field) {
if (isset($schema->columns[$this->{$field}])) {
self::$_fields[$ownerTable][$field] = $this->{$field};
}
}
}
return self::$_fields[$ownerTable];
} | [
"public",
"function",
"getFields",
"(",
")",
"{",
"$",
"ownerClass",
"=",
"get_class",
"(",
"$",
"this",
"->",
"owner",
")",
";",
"$",
"ownerTable",
"=",
"$",
"ownerClass",
"::",
"tableName",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_fields",
"[",
"$",
"ownerTable",
"]",
")",
")",
"{",
"self",
"::",
"$",
"_fields",
"[",
"$",
"ownerTable",
"]",
"=",
"[",
"]",
";",
"$",
"_f",
"=",
"[",
"'deletedField'",
",",
"'deletedByField'",
",",
"'createdField'",
",",
"'createdByField'",
",",
"'modifiedField'",
",",
"'modifiedByField'",
"]",
";",
"$",
"schema",
"=",
"$",
"ownerClass",
"::",
"getTableSchema",
"(",
")",
";",
"foreach",
"(",
"$",
"_f",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"schema",
"->",
"columns",
"[",
"$",
"this",
"->",
"{",
"$",
"field",
"}",
"]",
")",
")",
"{",
"self",
"::",
"$",
"_fields",
"[",
"$",
"ownerTable",
"]",
"[",
"$",
"field",
"]",
"=",
"$",
"this",
"->",
"{",
"$",
"field",
"}",
";",
"}",
"}",
"}",
"return",
"self",
"::",
"$",
"_fields",
"[",
"$",
"ownerTable",
"]",
";",
"}"
] | Get fields.
@return [[@doctodo return_type:getFields]] [[@doctodo return_description:getFields]] | [
"Get",
"fields",
"."
] | 97d533521f65b084dc805c5f312c364b469142d2 | https://github.com/canis-io/yii2-canis-lib/blob/97d533521f65b084dc805c5f312c364b469142d2/lib/db/behaviors/Blame.php#L77-L93 |
12,709 | webriq/core | module/Core/src/Grid/Core/Model/Package/Model.php | Model.getPaginator | public function getPaginator( $where = null, $order = null )
{
return $this->getMapper()
->getPaginator( $where, $order );
} | php | public function getPaginator( $where = null, $order = null )
{
return $this->getMapper()
->getPaginator( $where, $order );
} | [
"public",
"function",
"getPaginator",
"(",
"$",
"where",
"=",
"null",
",",
"$",
"order",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getMapper",
"(",
")",
"->",
"getPaginator",
"(",
"$",
"where",
",",
"$",
"order",
")",
";",
"}"
] | Find package element by name
@param string|null $where
@param bool|null $order
@return \Zend\Paginator\Paginator | [
"Find",
"package",
"element",
"by",
"name"
] | cfeb6e8a4732561c2215ec94e736c07f9b8bc990 | https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Core/src/Grid/Core/Model/Package/Model.php#L69-L73 |
12,710 | webriq/core | module/Core/src/Grid/Core/Model/Package/Model.php | Model.loadJsonData | protected static function loadJsonData( $file )
{
if ( ! is_file( $file ) )
{
return null;
}
return Json::decode(
@ file_get_contents( $file ),
Json::TYPE_ARRAY
);
} | php | protected static function loadJsonData( $file )
{
if ( ! is_file( $file ) )
{
return null;
}
return Json::decode(
@ file_get_contents( $file ),
Json::TYPE_ARRAY
);
} | [
"protected",
"static",
"function",
"loadJsonData",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"Json",
"::",
"decode",
"(",
"@",
"file_get_contents",
"(",
"$",
"file",
")",
",",
"Json",
"::",
"TYPE_ARRAY",
")",
";",
"}"
] | Load json data
@param string $file
@return mixed|null | [
"Load",
"json",
"data"
] | cfeb6e8a4732561c2215ec94e736c07f9b8bc990 | https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Core/src/Grid/Core/Model/Package/Model.php#L114-L125 |
12,711 | webriq/core | module/Core/src/Grid/Core/Model/Package/Model.php | Model.loadPackageData | protected static function loadPackageData()
{
if ( ! is_file( static::PACKAGE_FILE ) )
{
return null;
}
if ( null === static::$packageData )
{
static::$packageData = static::loadJsonData( static::PACKAGE_FILE );
}
return static::$packageData;
} | php | protected static function loadPackageData()
{
if ( ! is_file( static::PACKAGE_FILE ) )
{
return null;
}
if ( null === static::$packageData )
{
static::$packageData = static::loadJsonData( static::PACKAGE_FILE );
}
return static::$packageData;
} | [
"protected",
"static",
"function",
"loadPackageData",
"(",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"static",
"::",
"PACKAGE_FILE",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"null",
"===",
"static",
"::",
"$",
"packageData",
")",
"{",
"static",
"::",
"$",
"packageData",
"=",
"static",
"::",
"loadJsonData",
"(",
"static",
"::",
"PACKAGE_FILE",
")",
";",
"}",
"return",
"static",
"::",
"$",
"packageData",
";",
"}"
] | Load package data
@return mixed | [
"Load",
"package",
"data"
] | cfeb6e8a4732561c2215ec94e736c07f9b8bc990 | https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Core/src/Grid/Core/Model/Package/Model.php#L132-L145 |
12,712 | webriq/core | module/Core/src/Grid/Core/Model/Package/Model.php | Model.savePackageData | protected static function savePackageData( $data )
{
if ( ! is_file( static::PACKAGE_FILE ) )
{
return false;
}
if ( is_file( static::PACKAGE_FILE_BACKUP ) )
{
@ unlink( static::PACKAGE_FILE_BACKUP );
}
@ copy( static::PACKAGE_FILE, static::PACKAGE_FILE_BACKUP );
$result = static::saveJsonData( static::PACKAGE_FILE, $data );
if ( $result )
{
static::$packageData = $data;
}
else if ( is_file( static::PACKAGE_FILE_BACKUP ) )
{
@ unlink( static::PACKAGE_FILE );
@ copy( static::PACKAGE_FILE_BACKUP, static::PACKAGE_FILE );
}
return $result;
} | php | protected static function savePackageData( $data )
{
if ( ! is_file( static::PACKAGE_FILE ) )
{
return false;
}
if ( is_file( static::PACKAGE_FILE_BACKUP ) )
{
@ unlink( static::PACKAGE_FILE_BACKUP );
}
@ copy( static::PACKAGE_FILE, static::PACKAGE_FILE_BACKUP );
$result = static::saveJsonData( static::PACKAGE_FILE, $data );
if ( $result )
{
static::$packageData = $data;
}
else if ( is_file( static::PACKAGE_FILE_BACKUP ) )
{
@ unlink( static::PACKAGE_FILE );
@ copy( static::PACKAGE_FILE_BACKUP, static::PACKAGE_FILE );
}
return $result;
} | [
"protected",
"static",
"function",
"savePackageData",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"static",
"::",
"PACKAGE_FILE",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_file",
"(",
"static",
"::",
"PACKAGE_FILE_BACKUP",
")",
")",
"{",
"@",
"unlink",
"(",
"static",
"::",
"PACKAGE_FILE_BACKUP",
")",
";",
"}",
"@",
"copy",
"(",
"static",
"::",
"PACKAGE_FILE",
",",
"static",
"::",
"PACKAGE_FILE_BACKUP",
")",
";",
"$",
"result",
"=",
"static",
"::",
"saveJsonData",
"(",
"static",
"::",
"PACKAGE_FILE",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"static",
"::",
"$",
"packageData",
"=",
"$",
"data",
";",
"}",
"else",
"if",
"(",
"is_file",
"(",
"static",
"::",
"PACKAGE_FILE_BACKUP",
")",
")",
"{",
"@",
"unlink",
"(",
"static",
"::",
"PACKAGE_FILE",
")",
";",
"@",
"copy",
"(",
"static",
"::",
"PACKAGE_FILE_BACKUP",
",",
"static",
"::",
"PACKAGE_FILE",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Save package data
@param mixed $data
@return bool|int | [
"Save",
"package",
"data"
] | cfeb6e8a4732561c2215ec94e736c07f9b8bc990 | https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Core/src/Grid/Core/Model/Package/Model.php#L167-L194 |
12,713 | webriq/core | module/Core/src/Grid/Core/Model/Package/Model.php | Model.mergeJsonData | protected static function mergeJsonData( $file, $data )
{
return static::saveJsonData( $file, ArrayUtils::merge(
(array) static::loadJsonData( $file ),
$data
) );
} | php | protected static function mergeJsonData( $file, $data )
{
return static::saveJsonData( $file, ArrayUtils::merge(
(array) static::loadJsonData( $file ),
$data
) );
} | [
"protected",
"static",
"function",
"mergeJsonData",
"(",
"$",
"file",
",",
"$",
"data",
")",
"{",
"return",
"static",
"::",
"saveJsonData",
"(",
"$",
"file",
",",
"ArrayUtils",
"::",
"merge",
"(",
"(",
"array",
")",
"static",
"::",
"loadJsonData",
"(",
"$",
"file",
")",
",",
"$",
"data",
")",
")",
";",
"}"
] | Merge json data
@param mixed $data
@return bool|int | [
"Merge",
"json",
"data"
] | cfeb6e8a4732561c2215ec94e736c07f9b8bc990 | https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Core/src/Grid/Core/Model/Package/Model.php#L202-L208 |
12,714 | cityware/city-components | src/Filesystem.php | Filesystem.makePathRelative | public function makePathRelative($endPath, $startPath)
{
// Normalize separators on Windows
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
$endPath = strtr($endPath, '\\', '/');
$startPath = strtr($startPath, '\\', '/');
}
// Split the paths into arrays
$startPathArr = explode('/', trim($startPath, '/'));
$endPathArr = explode('/', trim($endPath, '/'));
// Find for which directory the common path stops
$index = 0;
while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) {
$index++;
}
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
$depth = count($startPathArr) - $index;
// Repeated "../" for each level need to reach the common path
$traverser = str_repeat('../', $depth);
$endPathRemainder = implode('/', array_slice($endPathArr, $index));
// Construct $endPath from traversing to the common path, then to the remaining $endPath
$relativePath = $traverser.(strlen($endPathRemainder) > 0 ? $endPathRemainder.'/' : '');
return (strlen($relativePath) === 0) ? './' : $relativePath;
} | php | public function makePathRelative($endPath, $startPath)
{
// Normalize separators on Windows
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
$endPath = strtr($endPath, '\\', '/');
$startPath = strtr($startPath, '\\', '/');
}
// Split the paths into arrays
$startPathArr = explode('/', trim($startPath, '/'));
$endPathArr = explode('/', trim($endPath, '/'));
// Find for which directory the common path stops
$index = 0;
while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) {
$index++;
}
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
$depth = count($startPathArr) - $index;
// Repeated "../" for each level need to reach the common path
$traverser = str_repeat('../', $depth);
$endPathRemainder = implode('/', array_slice($endPathArr, $index));
// Construct $endPath from traversing to the common path, then to the remaining $endPath
$relativePath = $traverser.(strlen($endPathRemainder) > 0 ? $endPathRemainder.'/' : '');
return (strlen($relativePath) === 0) ? './' : $relativePath;
} | [
"public",
"function",
"makePathRelative",
"(",
"$",
"endPath",
",",
"$",
"startPath",
")",
"{",
"// Normalize separators on Windows",
"if",
"(",
"defined",
"(",
"'PHP_WINDOWS_VERSION_MAJOR'",
")",
")",
"{",
"$",
"endPath",
"=",
"strtr",
"(",
"$",
"endPath",
",",
"'\\\\'",
",",
"'/'",
")",
";",
"$",
"startPath",
"=",
"strtr",
"(",
"$",
"startPath",
",",
"'\\\\'",
",",
"'/'",
")",
";",
"}",
"// Split the paths into arrays",
"$",
"startPathArr",
"=",
"explode",
"(",
"'/'",
",",
"trim",
"(",
"$",
"startPath",
",",
"'/'",
")",
")",
";",
"$",
"endPathArr",
"=",
"explode",
"(",
"'/'",
",",
"trim",
"(",
"$",
"endPath",
",",
"'/'",
")",
")",
";",
"// Find for which directory the common path stops",
"$",
"index",
"=",
"0",
";",
"while",
"(",
"isset",
"(",
"$",
"startPathArr",
"[",
"$",
"index",
"]",
")",
"&&",
"isset",
"(",
"$",
"endPathArr",
"[",
"$",
"index",
"]",
")",
"&&",
"$",
"startPathArr",
"[",
"$",
"index",
"]",
"===",
"$",
"endPathArr",
"[",
"$",
"index",
"]",
")",
"{",
"$",
"index",
"++",
";",
"}",
"// Determine how deep the start path is relative to the common path (ie, \"web/bundles\" = 2 levels)",
"$",
"depth",
"=",
"count",
"(",
"$",
"startPathArr",
")",
"-",
"$",
"index",
";",
"// Repeated \"../\" for each level need to reach the common path",
"$",
"traverser",
"=",
"str_repeat",
"(",
"'../'",
",",
"$",
"depth",
")",
";",
"$",
"endPathRemainder",
"=",
"implode",
"(",
"'/'",
",",
"array_slice",
"(",
"$",
"endPathArr",
",",
"$",
"index",
")",
")",
";",
"// Construct $endPath from traversing to the common path, then to the remaining $endPath",
"$",
"relativePath",
"=",
"$",
"traverser",
".",
"(",
"strlen",
"(",
"$",
"endPathRemainder",
")",
">",
"0",
"?",
"$",
"endPathRemainder",
".",
"'/'",
":",
"''",
")",
";",
"return",
"(",
"strlen",
"(",
"$",
"relativePath",
")",
"===",
"0",
")",
"?",
"'./'",
":",
"$",
"relativePath",
";",
"}"
] | Given an existing path, convert it to a path relative to a given starting path
@param string $endPath Absolute path of target
@param string $startPath Absolute path where traversal begins
@return string Path of target relative to starting path | [
"Given",
"an",
"existing",
"path",
"convert",
"it",
"to",
"a",
"path",
"relative",
"to",
"a",
"given",
"starting",
"path"
] | 103211a4896f7e9ecdccec2ee9bf26239d52faa0 | https://github.com/cityware/city-components/blob/103211a4896f7e9ecdccec2ee9bf26239d52faa0/src/Filesystem.php#L295-L325 |
12,715 | cityware/city-components | src/Filesystem.php | Filesystem.mirror | public function mirror($originDir, $targetDir, \Traversable $iterator = null, $options = array())
{
$targetDir = rtrim($targetDir, '/\\');
$originDir = rtrim($originDir, '/\\');
// Iterate in destination folder to remove obsolete entries
if ($this->exists($targetDir) && isset($options['delete']) && $options['delete']) {
$deleteIterator = $iterator;
if (null === $deleteIterator) {
$flags = \FilesystemIterator::SKIP_DOTS;
$deleteIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($targetDir, $flags), \RecursiveIteratorIterator::CHILD_FIRST);
}
foreach ($deleteIterator as $file) {
$origin = str_replace($targetDir, $originDir, $file->getPathname());
if (!$this->exists($origin)) {
$this->remove($file);
}
}
}
$copyOnWindows = false;
if (isset($options['copy_on_windows']) && !function_exists('symlink')) {
$copyOnWindows = $options['copy_on_windows'];
}
if (null === $iterator) {
$flags = $copyOnWindows ? \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS : \FilesystemIterator::SKIP_DOTS;
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir, $flags), \RecursiveIteratorIterator::SELF_FIRST);
}
foreach ($iterator as $file) {
$target = str_replace($originDir, $targetDir, $file->getPathname());
if ($copyOnWindows) {
if (is_link($file) || is_file($file)) {
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
} elseif (is_dir($file)) {
$this->mkdir($target);
} else {
throw new \RuntimeException(sprintf('Unable to guess "%s" file type.', $file), 0, null);
}
} else {
if (is_link($file)) {
$this->symlink($file->getLinkTarget(), $target);
} elseif (is_dir($file)) {
$this->mkdir($target);
} elseif (is_file($file)) {
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
} else {
throw new \RuntimeException(sprintf('Unable to guess "%s" file type.', $file), 0, null);
}
}
}
} | php | public function mirror($originDir, $targetDir, \Traversable $iterator = null, $options = array())
{
$targetDir = rtrim($targetDir, '/\\');
$originDir = rtrim($originDir, '/\\');
// Iterate in destination folder to remove obsolete entries
if ($this->exists($targetDir) && isset($options['delete']) && $options['delete']) {
$deleteIterator = $iterator;
if (null === $deleteIterator) {
$flags = \FilesystemIterator::SKIP_DOTS;
$deleteIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($targetDir, $flags), \RecursiveIteratorIterator::CHILD_FIRST);
}
foreach ($deleteIterator as $file) {
$origin = str_replace($targetDir, $originDir, $file->getPathname());
if (!$this->exists($origin)) {
$this->remove($file);
}
}
}
$copyOnWindows = false;
if (isset($options['copy_on_windows']) && !function_exists('symlink')) {
$copyOnWindows = $options['copy_on_windows'];
}
if (null === $iterator) {
$flags = $copyOnWindows ? \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS : \FilesystemIterator::SKIP_DOTS;
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir, $flags), \RecursiveIteratorIterator::SELF_FIRST);
}
foreach ($iterator as $file) {
$target = str_replace($originDir, $targetDir, $file->getPathname());
if ($copyOnWindows) {
if (is_link($file) || is_file($file)) {
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
} elseif (is_dir($file)) {
$this->mkdir($target);
} else {
throw new \RuntimeException(sprintf('Unable to guess "%s" file type.', $file), 0, null);
}
} else {
if (is_link($file)) {
$this->symlink($file->getLinkTarget(), $target);
} elseif (is_dir($file)) {
$this->mkdir($target);
} elseif (is_file($file)) {
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
} else {
throw new \RuntimeException(sprintf('Unable to guess "%s" file type.', $file), 0, null);
}
}
}
} | [
"public",
"function",
"mirror",
"(",
"$",
"originDir",
",",
"$",
"targetDir",
",",
"\\",
"Traversable",
"$",
"iterator",
"=",
"null",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"targetDir",
"=",
"rtrim",
"(",
"$",
"targetDir",
",",
"'/\\\\'",
")",
";",
"$",
"originDir",
"=",
"rtrim",
"(",
"$",
"originDir",
",",
"'/\\\\'",
")",
";",
"// Iterate in destination folder to remove obsolete entries",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"targetDir",
")",
"&&",
"isset",
"(",
"$",
"options",
"[",
"'delete'",
"]",
")",
"&&",
"$",
"options",
"[",
"'delete'",
"]",
")",
"{",
"$",
"deleteIterator",
"=",
"$",
"iterator",
";",
"if",
"(",
"null",
"===",
"$",
"deleteIterator",
")",
"{",
"$",
"flags",
"=",
"\\",
"FilesystemIterator",
"::",
"SKIP_DOTS",
";",
"$",
"deleteIterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"targetDir",
",",
"$",
"flags",
")",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"CHILD_FIRST",
")",
";",
"}",
"foreach",
"(",
"$",
"deleteIterator",
"as",
"$",
"file",
")",
"{",
"$",
"origin",
"=",
"str_replace",
"(",
"$",
"targetDir",
",",
"$",
"originDir",
",",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"exists",
"(",
"$",
"origin",
")",
")",
"{",
"$",
"this",
"->",
"remove",
"(",
"$",
"file",
")",
";",
"}",
"}",
"}",
"$",
"copyOnWindows",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'copy_on_windows'",
"]",
")",
"&&",
"!",
"function_exists",
"(",
"'symlink'",
")",
")",
"{",
"$",
"copyOnWindows",
"=",
"$",
"options",
"[",
"'copy_on_windows'",
"]",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"iterator",
")",
"{",
"$",
"flags",
"=",
"$",
"copyOnWindows",
"?",
"\\",
"FilesystemIterator",
"::",
"SKIP_DOTS",
"|",
"\\",
"FilesystemIterator",
"::",
"FOLLOW_SYMLINKS",
":",
"\\",
"FilesystemIterator",
"::",
"SKIP_DOTS",
";",
"$",
"iterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"originDir",
",",
"$",
"flags",
")",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"SELF_FIRST",
")",
";",
"}",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"file",
")",
"{",
"$",
"target",
"=",
"str_replace",
"(",
"$",
"originDir",
",",
"$",
"targetDir",
",",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"if",
"(",
"$",
"copyOnWindows",
")",
"{",
"if",
"(",
"is_link",
"(",
"$",
"file",
")",
"||",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"copy",
"(",
"$",
"file",
",",
"$",
"target",
",",
"isset",
"(",
"$",
"options",
"[",
"'override'",
"]",
")",
"?",
"$",
"options",
"[",
"'override'",
"]",
":",
"false",
")",
";",
"}",
"elseif",
"(",
"is_dir",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"mkdir",
"(",
"$",
"target",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to guess \"%s\" file type.'",
",",
"$",
"file",
")",
",",
"0",
",",
"null",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"is_link",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"symlink",
"(",
"$",
"file",
"->",
"getLinkTarget",
"(",
")",
",",
"$",
"target",
")",
";",
"}",
"elseif",
"(",
"is_dir",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"mkdir",
"(",
"$",
"target",
")",
";",
"}",
"elseif",
"(",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"copy",
"(",
"$",
"file",
",",
"$",
"target",
",",
"isset",
"(",
"$",
"options",
"[",
"'override'",
"]",
")",
"?",
"$",
"options",
"[",
"'override'",
"]",
":",
"false",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to guess \"%s\" file type.'",
",",
"$",
"file",
")",
",",
"0",
",",
"null",
")",
";",
"}",
"}",
"}",
"}"
] | Mirrors a directory to another.
@param string $originDir The origin directory
@param string $targetDir The target directory
@param \Traversable $iterator A Traversable instance
@param array $options An array of boolean options
Valid options are:
- $options['override'] Whether to override an existing file on copy or not (see copy())
- $options['copy_on_windows'] Whether to copy files instead of links on Windows (see symlink())
- $options['delete'] Whether to delete files that are not in the source directory (defaults to false)
@throws \RuntimeException When file type is unknown | [
"Mirrors",
"a",
"directory",
"to",
"another",
"."
] | 103211a4896f7e9ecdccec2ee9bf26239d52faa0 | https://github.com/cityware/city-components/blob/103211a4896f7e9ecdccec2ee9bf26239d52faa0/src/Filesystem.php#L341-L394 |
12,716 | osflab/view | Helper/Bootstrap/Button.php | Button.submitForm | public function submitForm(string $formId = '', string $targetId = '', bool $preventDefault = true)
{
static $attached = false;
if ($attached) {
Checkers::notice('This button is already attached to a form.');
return $this;
}
$this->id = 'btnf' . self::$idCount++;
Component::getVueJs()->registerSubmitLink($this->id, $formId, VueJs::EVENT_CLIC, $targetId, $preventDefault);
return $this;
} | php | public function submitForm(string $formId = '', string $targetId = '', bool $preventDefault = true)
{
static $attached = false;
if ($attached) {
Checkers::notice('This button is already attached to a form.');
return $this;
}
$this->id = 'btnf' . self::$idCount++;
Component::getVueJs()->registerSubmitLink($this->id, $formId, VueJs::EVENT_CLIC, $targetId, $preventDefault);
return $this;
} | [
"public",
"function",
"submitForm",
"(",
"string",
"$",
"formId",
"=",
"''",
",",
"string",
"$",
"targetId",
"=",
"''",
",",
"bool",
"$",
"preventDefault",
"=",
"true",
")",
"{",
"static",
"$",
"attached",
"=",
"false",
";",
"if",
"(",
"$",
"attached",
")",
"{",
"Checkers",
"::",
"notice",
"(",
"'This button is already attached to a form.'",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"id",
"=",
"'btnf'",
".",
"self",
"::",
"$",
"idCount",
"++",
";",
"Component",
"::",
"getVueJs",
"(",
")",
"->",
"registerSubmitLink",
"(",
"$",
"this",
"->",
"id",
",",
"$",
"formId",
",",
"VueJs",
"::",
"EVENT_CLIC",
",",
"$",
"targetId",
",",
"$",
"preventDefault",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set submit action
@staticvar boolean $attached
@param string $formId (without #)
@param string $targetId (without #)
@param bool $preventDefault
@return $this | [
"Set",
"submit",
"action"
] | e06601013e8ec86dc2055e000e58dffd963c78e2 | https://github.com/osflab/view/blob/e06601013e8ec86dc2055e000e58dffd963c78e2/Helper/Bootstrap/Button.php#L155-L166 |
12,717 | razielsd/webdriverlib | WebDriver/WebDriver/Touch.php | WebDriver_Touch.swipe | public function swipe($xSpeed, $ySpeed)
{
$this->webDriver->getDriver()->curl(
$this->webDriver->getDriver()->factoryCommand(
'touch/flick',
WebDriver_Command::METHOD_POST,
[
'xspeed' => (int) $xSpeed,
'yspeed' => (int) $ySpeed,
]
)
);
return $this;
} | php | public function swipe($xSpeed, $ySpeed)
{
$this->webDriver->getDriver()->curl(
$this->webDriver->getDriver()->factoryCommand(
'touch/flick',
WebDriver_Command::METHOD_POST,
[
'xspeed' => (int) $xSpeed,
'yspeed' => (int) $ySpeed,
]
)
);
return $this;
} | [
"public",
"function",
"swipe",
"(",
"$",
"xSpeed",
",",
"$",
"ySpeed",
")",
"{",
"$",
"this",
"->",
"webDriver",
"->",
"getDriver",
"(",
")",
"->",
"curl",
"(",
"$",
"this",
"->",
"webDriver",
"->",
"getDriver",
"(",
")",
"->",
"factoryCommand",
"(",
"'touch/flick'",
",",
"WebDriver_Command",
"::",
"METHOD_POST",
",",
"[",
"'xspeed'",
"=>",
"(",
"int",
")",
"$",
"xSpeed",
",",
"'yspeed'",
"=>",
"(",
"int",
")",
"$",
"ySpeed",
",",
"]",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Performs swipe on screen.
@param int $xSpeed
@param int $ySpeed
@return $this | [
"Performs",
"swipe",
"on",
"screen",
"."
] | e498afc36a8cdeab5b6ca95016420557baf32f36 | https://github.com/razielsd/webdriverlib/blob/e498afc36a8cdeab5b6ca95016420557baf32f36/WebDriver/WebDriver/Touch.php#L25-L38 |
12,718 | razielsd/webdriverlib | WebDriver/WebDriver/Touch.php | WebDriver_Touch.down | public function down($x, $y)
{
$this->webDriver->getDriver()->curl(
$this->webDriver->getDriver()->factoryCommand(
'touch/down',
WebDriver_Command::METHOD_POST,
[
'x' => (int) $x,
'y' => (int) $y,
]
)
);
return $this;
} | php | public function down($x, $y)
{
$this->webDriver->getDriver()->curl(
$this->webDriver->getDriver()->factoryCommand(
'touch/down',
WebDriver_Command::METHOD_POST,
[
'x' => (int) $x,
'y' => (int) $y,
]
)
);
return $this;
} | [
"public",
"function",
"down",
"(",
"$",
"x",
",",
"$",
"y",
")",
"{",
"$",
"this",
"->",
"webDriver",
"->",
"getDriver",
"(",
")",
"->",
"curl",
"(",
"$",
"this",
"->",
"webDriver",
"->",
"getDriver",
"(",
")",
"->",
"factoryCommand",
"(",
"'touch/down'",
",",
"WebDriver_Command",
"::",
"METHOD_POST",
",",
"[",
"'x'",
"=>",
"(",
"int",
")",
"$",
"x",
",",
"'y'",
"=>",
"(",
"int",
")",
"$",
"y",
",",
"]",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Performs touch on screen.
@param int $x
@param int $y
@return $this | [
"Performs",
"touch",
"on",
"screen",
"."
] | e498afc36a8cdeab5b6ca95016420557baf32f36 | https://github.com/razielsd/webdriverlib/blob/e498afc36a8cdeab5b6ca95016420557baf32f36/WebDriver/WebDriver/Touch.php#L48-L61 |
12,719 | Stratadox/HydrationMapping | src/Property/UnmappableProperty.php | UnmappableProperty.addAlternativeTypeInformation | public static function addAlternativeTypeInformation(
string $type,
UnmappableInput $exception
): UnmappableInput {
return new self(sprintf(
'%s It could not be mapped to %s either.',
$exception->getMessage(),
$type
), 0, $exception);
} | php | public static function addAlternativeTypeInformation(
string $type,
UnmappableInput $exception
): UnmappableInput {
return new self(sprintf(
'%s It could not be mapped to %s either.',
$exception->getMessage(),
$type
), 0, $exception);
} | [
"public",
"static",
"function",
"addAlternativeTypeInformation",
"(",
"string",
"$",
"type",
",",
"UnmappableInput",
"$",
"exception",
")",
":",
"UnmappableInput",
"{",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'%s It could not be mapped to %s either.'",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"$",
"type",
")",
",",
"0",
",",
"$",
"exception",
")",
";",
"}"
] | Add the alternative type information to the original exception.
@param string $type The alternative type.
@param UnmappableInput $exception The original exception.
@return UnmappableInput The exception to throw. | [
"Add",
"the",
"alternative",
"type",
"information",
"to",
"the",
"original",
"exception",
"."
] | b145deaaf76ab8c8060f0cba1a8c6f73da375982 | https://github.com/Stratadox/HydrationMapping/blob/b145deaaf76ab8c8060f0cba1a8c6f73da375982/src/Property/UnmappableProperty.php#L88-L97 |
12,720 | Stratadox/HydrationMapping | src/Property/UnmappableProperty.php | UnmappableProperty.inputData | private static function inputData(
MapsProperty $mapped,
string $type,
$input,
string $message = ''
): Throwable {
if (is_scalar($input)) {
return new self(trim(sprintf(
'Cannot assign `%s` to property `%s`: ' .
'it is not clean for conversion to %s. %s',
$input, $mapped->name(), $type, $message
)));
}
return new self(trim(sprintf(
'Cannot assign the %s to property `%s`: ' .
'it is not clean for conversion to %s. %s',
gettype($input), $mapped->name(), $type, $message
)));
} | php | private static function inputData(
MapsProperty $mapped,
string $type,
$input,
string $message = ''
): Throwable {
if (is_scalar($input)) {
return new self(trim(sprintf(
'Cannot assign `%s` to property `%s`: ' .
'it is not clean for conversion to %s. %s',
$input, $mapped->name(), $type, $message
)));
}
return new self(trim(sprintf(
'Cannot assign the %s to property `%s`: ' .
'it is not clean for conversion to %s. %s',
gettype($input), $mapped->name(), $type, $message
)));
} | [
"private",
"static",
"function",
"inputData",
"(",
"MapsProperty",
"$",
"mapped",
",",
"string",
"$",
"type",
",",
"$",
"input",
",",
"string",
"$",
"message",
"=",
"''",
")",
":",
"Throwable",
"{",
"if",
"(",
"is_scalar",
"(",
"$",
"input",
")",
")",
"{",
"return",
"new",
"self",
"(",
"trim",
"(",
"sprintf",
"(",
"'Cannot assign `%s` to property `%s`: '",
".",
"'it is not clean for conversion to %s. %s'",
",",
"$",
"input",
",",
"$",
"mapped",
"->",
"name",
"(",
")",
",",
"$",
"type",
",",
"$",
"message",
")",
")",
")",
";",
"}",
"return",
"new",
"self",
"(",
"trim",
"(",
"sprintf",
"(",
"'Cannot assign the %s to property `%s`: '",
".",
"'it is not clean for conversion to %s. %s'",
",",
"gettype",
"(",
"$",
"input",
")",
",",
"$",
"mapped",
"->",
"name",
"(",
")",
",",
"$",
"type",
",",
"$",
"message",
")",
")",
")",
";",
"}"
] | Notifies the client code when the input is not mappable.
@param MapsProperty $mapped The mapping that failed.
@param string $type The type of data that was expected.
@param mixed $input The input that could not be mapped.
@param string $message Optional extra message.
@return Throwable The exception to throw. | [
"Notifies",
"the",
"client",
"code",
"when",
"the",
"input",
"is",
"not",
"mappable",
"."
] | b145deaaf76ab8c8060f0cba1a8c6f73da375982 | https://github.com/Stratadox/HydrationMapping/blob/b145deaaf76ab8c8060f0cba1a8c6f73da375982/src/Property/UnmappableProperty.php#L108-L126 |
12,721 | webservices-nl/utils | src/FileSignatureUtils.php | FileSignatureUtils.hasSignature | public static function hasSignature($string, $signature)
{
if (ctype_xdigit($signature) === false) {
throw new \InvalidArgumentException(sprintf('Invalid HEX signature provided: %s', $signature));
}
$signatureChars = str_split($signature, 2);
$hexChars = array_map(
function ($val) {
return strtoupper(bin2hex($val));
},
str_split(substr($string, 0, count($signatureChars)))
);
return $hexChars === $signatureChars;
} | php | public static function hasSignature($string, $signature)
{
if (ctype_xdigit($signature) === false) {
throw new \InvalidArgumentException(sprintf('Invalid HEX signature provided: %s', $signature));
}
$signatureChars = str_split($signature, 2);
$hexChars = array_map(
function ($val) {
return strtoupper(bin2hex($val));
},
str_split(substr($string, 0, count($signatureChars)))
);
return $hexChars === $signatureChars;
} | [
"public",
"static",
"function",
"hasSignature",
"(",
"$",
"string",
",",
"$",
"signature",
")",
"{",
"if",
"(",
"ctype_xdigit",
"(",
"$",
"signature",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid HEX signature provided: %s'",
",",
"$",
"signature",
")",
")",
";",
"}",
"$",
"signatureChars",
"=",
"str_split",
"(",
"$",
"signature",
",",
"2",
")",
";",
"$",
"hexChars",
"=",
"array_map",
"(",
"function",
"(",
"$",
"val",
")",
"{",
"return",
"strtoupper",
"(",
"bin2hex",
"(",
"$",
"val",
")",
")",
";",
"}",
",",
"str_split",
"(",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"count",
"(",
"$",
"signatureChars",
")",
")",
")",
")",
";",
"return",
"$",
"hexChars",
"===",
"$",
"signatureChars",
";",
"}"
] | Determine whether the given string contains one of the registered signatures
@param string $string the string data to check
@param string $signature the hex signature
@throws \InvalidArgumentException
@return bool | [
"Determine",
"whether",
"the",
"given",
"string",
"contains",
"one",
"of",
"the",
"registered",
"signatures"
] | 052f41ff725808b19d529e640f890ce7c863e100 | https://github.com/webservices-nl/utils/blob/052f41ff725808b19d529e640f890ce7c863e100/src/FileSignatureUtils.php#L27-L41 |
12,722 | zepi/turbo-base | Zepi/Web/UserInterface/src/Renderer/Table.php | Table.prepareTable | public function prepareTable(WebRequest $request, TableAbstract $table, $paginationUrl, $numberOfEntries = 10)
{
// If the table has no pagination we do not limit the number of entries
// which will be displayed
if (!$table->hasPagination()) {
$numberOfEntries = false;
}
// Generate the data request
$dataRequest = $this->generateDataRequest($request, $table, $numberOfEntries);
// Get the data
$data = $table->getData($dataRequest);
if (!is_array($data)) {
$data = array();
}
$preparedTable = new PreparedTable($table, $table->getColumns());
$preparedTable->setOptions($table->getOptions());
// Add the table head
$preparedTable->setHead($this->renderHead($table, $dataRequest));
// Render the body and add it to the rendered table
$body = new Body();
foreach ($data as $object) {
$body->addRow($this->renderRow($table, $body, $object));
}
$preparedTable->setBody($body);
// Add the table foot
$preparedTable->setFoot($this->renderFoot($table));
// Create the token
$token = uniqid('dt');
$preparedTable->setToken($token);
$request->setSessionData('dt-class-' . $token, get_class($table));
$request->setSessionData('dt-time-' . $token, time());
$request->setSessionData('dt-options-' . $token, json_encode($table->getOptions()));
return $preparedTable;
} | php | public function prepareTable(WebRequest $request, TableAbstract $table, $paginationUrl, $numberOfEntries = 10)
{
// If the table has no pagination we do not limit the number of entries
// which will be displayed
if (!$table->hasPagination()) {
$numberOfEntries = false;
}
// Generate the data request
$dataRequest = $this->generateDataRequest($request, $table, $numberOfEntries);
// Get the data
$data = $table->getData($dataRequest);
if (!is_array($data)) {
$data = array();
}
$preparedTable = new PreparedTable($table, $table->getColumns());
$preparedTable->setOptions($table->getOptions());
// Add the table head
$preparedTable->setHead($this->renderHead($table, $dataRequest));
// Render the body and add it to the rendered table
$body = new Body();
foreach ($data as $object) {
$body->addRow($this->renderRow($table, $body, $object));
}
$preparedTable->setBody($body);
// Add the table foot
$preparedTable->setFoot($this->renderFoot($table));
// Create the token
$token = uniqid('dt');
$preparedTable->setToken($token);
$request->setSessionData('dt-class-' . $token, get_class($table));
$request->setSessionData('dt-time-' . $token, time());
$request->setSessionData('dt-options-' . $token, json_encode($table->getOptions()));
return $preparedTable;
} | [
"public",
"function",
"prepareTable",
"(",
"WebRequest",
"$",
"request",
",",
"TableAbstract",
"$",
"table",
",",
"$",
"paginationUrl",
",",
"$",
"numberOfEntries",
"=",
"10",
")",
"{",
"// If the table has no pagination we do not limit the number of entries ",
"// which will be displayed",
"if",
"(",
"!",
"$",
"table",
"->",
"hasPagination",
"(",
")",
")",
"{",
"$",
"numberOfEntries",
"=",
"false",
";",
"}",
"// Generate the data request",
"$",
"dataRequest",
"=",
"$",
"this",
"->",
"generateDataRequest",
"(",
"$",
"request",
",",
"$",
"table",
",",
"$",
"numberOfEntries",
")",
";",
"// Get the data",
"$",
"data",
"=",
"$",
"table",
"->",
"getData",
"(",
"$",
"dataRequest",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"}",
"$",
"preparedTable",
"=",
"new",
"PreparedTable",
"(",
"$",
"table",
",",
"$",
"table",
"->",
"getColumns",
"(",
")",
")",
";",
"$",
"preparedTable",
"->",
"setOptions",
"(",
"$",
"table",
"->",
"getOptions",
"(",
")",
")",
";",
"// Add the table head",
"$",
"preparedTable",
"->",
"setHead",
"(",
"$",
"this",
"->",
"renderHead",
"(",
"$",
"table",
",",
"$",
"dataRequest",
")",
")",
";",
"// Render the body and add it to the rendered table",
"$",
"body",
"=",
"new",
"Body",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"object",
")",
"{",
"$",
"body",
"->",
"addRow",
"(",
"$",
"this",
"->",
"renderRow",
"(",
"$",
"table",
",",
"$",
"body",
",",
"$",
"object",
")",
")",
";",
"}",
"$",
"preparedTable",
"->",
"setBody",
"(",
"$",
"body",
")",
";",
"// Add the table foot",
"$",
"preparedTable",
"->",
"setFoot",
"(",
"$",
"this",
"->",
"renderFoot",
"(",
"$",
"table",
")",
")",
";",
"// Create the token",
"$",
"token",
"=",
"uniqid",
"(",
"'dt'",
")",
";",
"$",
"preparedTable",
"->",
"setToken",
"(",
"$",
"token",
")",
";",
"$",
"request",
"->",
"setSessionData",
"(",
"'dt-class-'",
".",
"$",
"token",
",",
"get_class",
"(",
"$",
"table",
")",
")",
";",
"$",
"request",
"->",
"setSessionData",
"(",
"'dt-time-'",
".",
"$",
"token",
",",
"time",
"(",
")",
")",
";",
"$",
"request",
"->",
"setSessionData",
"(",
"'dt-options-'",
".",
"$",
"token",
",",
"json_encode",
"(",
"$",
"table",
"->",
"getOptions",
"(",
")",
")",
")",
";",
"return",
"$",
"preparedTable",
";",
"}"
] | Renders the whole table
@access public
@param \Zepi\Turbo\Request\WebRequest $request
@param \Zepi\Web\UserInterface\Table\TableAbstract $table
@param string $paginationUrl
@param integer $numberOfEntries
@return \Zepi\Web\UserInterface\Table\PreparedTable | [
"Renders",
"the",
"whole",
"table"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/UserInterface/src/Renderer/Table.php#L84-L125 |
12,723 | zepi/turbo-base | Zepi/Web/UserInterface/src/Renderer/Table.php | Table.generateDataRequest | protected function generateDataRequest(WebRequest $request, TableAbstract $table, $numberOfEntries)
{
$sortBy = 'name';
$sortByDirection = 'ASC';
// If the session has a data request object for the table, load it and refresh the data.
$savedDataRequestKey = get_class($table) . '.DataRequest.Saved';
$dataRequest = false;
if ($table->shouldSaveDataRequest() && $request->getSessionData($savedDataRequestKey) !== false) {
$dataRequest = unserialize($request->getSessionData($savedDataRequestKey));
}
// Check if the data request is valid
if ($dataRequest === false) {
$dataRequest = new DataRequest(1, $numberOfEntries, $sortBy, $sortByDirection);
}
// Save the data request to the session if needed
if ($table->shouldSaveDataRequest()) {
$request->setSessionData($savedDataRequestKey, serialize($dataRequest));
}
return $dataRequest;
} | php | protected function generateDataRequest(WebRequest $request, TableAbstract $table, $numberOfEntries)
{
$sortBy = 'name';
$sortByDirection = 'ASC';
// If the session has a data request object for the table, load it and refresh the data.
$savedDataRequestKey = get_class($table) . '.DataRequest.Saved';
$dataRequest = false;
if ($table->shouldSaveDataRequest() && $request->getSessionData($savedDataRequestKey) !== false) {
$dataRequest = unserialize($request->getSessionData($savedDataRequestKey));
}
// Check if the data request is valid
if ($dataRequest === false) {
$dataRequest = new DataRequest(1, $numberOfEntries, $sortBy, $sortByDirection);
}
// Save the data request to the session if needed
if ($table->shouldSaveDataRequest()) {
$request->setSessionData($savedDataRequestKey, serialize($dataRequest));
}
return $dataRequest;
} | [
"protected",
"function",
"generateDataRequest",
"(",
"WebRequest",
"$",
"request",
",",
"TableAbstract",
"$",
"table",
",",
"$",
"numberOfEntries",
")",
"{",
"$",
"sortBy",
"=",
"'name'",
";",
"$",
"sortByDirection",
"=",
"'ASC'",
";",
"// If the session has a data request object for the table, load it and refresh the data.",
"$",
"savedDataRequestKey",
"=",
"get_class",
"(",
"$",
"table",
")",
".",
"'.DataRequest.Saved'",
";",
"$",
"dataRequest",
"=",
"false",
";",
"if",
"(",
"$",
"table",
"->",
"shouldSaveDataRequest",
"(",
")",
"&&",
"$",
"request",
"->",
"getSessionData",
"(",
"$",
"savedDataRequestKey",
")",
"!==",
"false",
")",
"{",
"$",
"dataRequest",
"=",
"unserialize",
"(",
"$",
"request",
"->",
"getSessionData",
"(",
"$",
"savedDataRequestKey",
")",
")",
";",
"}",
"// Check if the data request is valid",
"if",
"(",
"$",
"dataRequest",
"===",
"false",
")",
"{",
"$",
"dataRequest",
"=",
"new",
"DataRequest",
"(",
"1",
",",
"$",
"numberOfEntries",
",",
"$",
"sortBy",
",",
"$",
"sortByDirection",
")",
";",
"}",
"// Save the data request to the session if needed",
"if",
"(",
"$",
"table",
"->",
"shouldSaveDataRequest",
"(",
")",
")",
"{",
"$",
"request",
"->",
"setSessionData",
"(",
"$",
"savedDataRequestKey",
",",
"serialize",
"(",
"$",
"dataRequest",
")",
")",
";",
"}",
"return",
"$",
"dataRequest",
";",
"}"
] | Generates a DataRequest object
@access protected
@param \Zepi\Turbo\Request\WebRequest $request
@param \Zepi\Web\UserInterface\Table\TableAbstract $table
@param false|integer $numberOfEntries
@return \Zepi\Web\UserInterface\Table\DataRequest | [
"Generates",
"a",
"DataRequest",
"object"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/UserInterface/src/Renderer/Table.php#L136-L159 |
12,724 | zepi/turbo-base | Zepi/Web/UserInterface/src/Renderer/Table.php | Table.renderHead | protected function renderHead(TableAbstract $table, DataRequest $dataRequest)
{
$head = new Head();
// Add the name row
$row = new Row($head);
foreach ($table->getColumns() as $column) {
$cell = new Cell($column, $row, $column->getName());
$row->addCell($cell);
}
$head->addRow($row);
return $head;
} | php | protected function renderHead(TableAbstract $table, DataRequest $dataRequest)
{
$head = new Head();
// Add the name row
$row = new Row($head);
foreach ($table->getColumns() as $column) {
$cell = new Cell($column, $row, $column->getName());
$row->addCell($cell);
}
$head->addRow($row);
return $head;
} | [
"protected",
"function",
"renderHead",
"(",
"TableAbstract",
"$",
"table",
",",
"DataRequest",
"$",
"dataRequest",
")",
"{",
"$",
"head",
"=",
"new",
"Head",
"(",
")",
";",
"// Add the name row",
"$",
"row",
"=",
"new",
"Row",
"(",
"$",
"head",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"cell",
"=",
"new",
"Cell",
"(",
"$",
"column",
",",
"$",
"row",
",",
"$",
"column",
"->",
"getName",
"(",
")",
")",
";",
"$",
"row",
"->",
"addCell",
"(",
"$",
"cell",
")",
";",
"}",
"$",
"head",
"->",
"addRow",
"(",
"$",
"row",
")",
";",
"return",
"$",
"head",
";",
"}"
] | Generates the object structure for the head
@access protected
@param \Zepi\Web\UserInterface\Table\TableAbstract $table
@param \Zepi\DataSource\Core\Entity\DataRequest $dataRequest
@return \Zepi\Web\UserInterface\Table\Head | [
"Generates",
"the",
"object",
"structure",
"for",
"the",
"head"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/UserInterface/src/Renderer/Table.php#L169-L184 |
12,725 | zepi/turbo-base | Zepi/Web/UserInterface/src/Renderer/Table.php | Table.renderRow | protected function renderRow(TableAbstract $table, Body $body, $object)
{
$row = new Row($body);
foreach ($table->getColumns() as $column) {
$value = $table->getDataForRow($column->getKey(), $object);
$cell = new Cell($column, $row, $value);
$row->addCell($cell);
}
return $row;
} | php | protected function renderRow(TableAbstract $table, Body $body, $object)
{
$row = new Row($body);
foreach ($table->getColumns() as $column) {
$value = $table->getDataForRow($column->getKey(), $object);
$cell = new Cell($column, $row, $value);
$row->addCell($cell);
}
return $row;
} | [
"protected",
"function",
"renderRow",
"(",
"TableAbstract",
"$",
"table",
",",
"Body",
"$",
"body",
",",
"$",
"object",
")",
"{",
"$",
"row",
"=",
"new",
"Row",
"(",
"$",
"body",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"value",
"=",
"$",
"table",
"->",
"getDataForRow",
"(",
"$",
"column",
"->",
"getKey",
"(",
")",
",",
"$",
"object",
")",
";",
"$",
"cell",
"=",
"new",
"Cell",
"(",
"$",
"column",
",",
"$",
"row",
",",
"$",
"value",
")",
";",
"$",
"row",
"->",
"addCell",
"(",
"$",
"cell",
")",
";",
"}",
"return",
"$",
"row",
";",
"}"
] | Renders the table row with the given row data
@access protected
@param \Zepi\Web\UserInterface\Table\TableAbstract $table
@param \Zepi\Web\UserInterface\Table\Body $body
@param mixed $object
@return \Zepi\Web\UserInterface\Table\Row | [
"Renders",
"the",
"table",
"row",
"with",
"the",
"given",
"row",
"data"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/UserInterface/src/Renderer/Table.php#L195-L207 |
12,726 | mszewcz/php-light-framework | src/Filesystem/Directory.php | Directory.exists | public static function exists(string $dir = ''): bool
{
$dir = static::normalizePath($dir);
return static::verifyPath($dir) && \file_exists($dir) && \is_dir($dir);
} | php | public static function exists(string $dir = ''): bool
{
$dir = static::normalizePath($dir);
return static::verifyPath($dir) && \file_exists($dir) && \is_dir($dir);
} | [
"public",
"static",
"function",
"exists",
"(",
"string",
"$",
"dir",
"=",
"''",
")",
":",
"bool",
"{",
"$",
"dir",
"=",
"static",
"::",
"normalizePath",
"(",
"$",
"dir",
")",
";",
"return",
"static",
"::",
"verifyPath",
"(",
"$",
"dir",
")",
"&&",
"\\",
"file_exists",
"(",
"$",
"dir",
")",
"&&",
"\\",
"is_dir",
"(",
"$",
"dir",
")",
";",
"}"
] | Checks whether directory exists.
@param string $dir
@return bool | [
"Checks",
"whether",
"directory",
"exists",
"."
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Filesystem/Directory.php#L27-L31 |
12,727 | mszewcz/php-light-framework | src/Filesystem/Directory.php | Directory.isLink | public static function isLink(string $dir = ''): bool
{
$dir = static::normalizePath($dir);
return static::exists($dir) && \is_link($dir);
} | php | public static function isLink(string $dir = ''): bool
{
$dir = static::normalizePath($dir);
return static::exists($dir) && \is_link($dir);
} | [
"public",
"static",
"function",
"isLink",
"(",
"string",
"$",
"dir",
"=",
"''",
")",
":",
"bool",
"{",
"$",
"dir",
"=",
"static",
"::",
"normalizePath",
"(",
"$",
"dir",
")",
";",
"return",
"static",
"::",
"exists",
"(",
"$",
"dir",
")",
"&&",
"\\",
"is_link",
"(",
"$",
"dir",
")",
";",
"}"
] | Checks whether directory is a link
@param string $dir
@return bool | [
"Checks",
"whether",
"directory",
"is",
"a",
"link"
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Filesystem/Directory.php#L39-L43 |
12,728 | mszewcz/php-light-framework | src/Filesystem/Directory.php | Directory.remove | public static function remove(string $dir = '', bool $emptyOnly = false): bool
{
$ret = true;
$dir = static::normalizePath($dir);
if (static::exists($dir)) {
if ($handle = @\opendir($dir)) {
while (false !== ($item = @\readdir($handle))) {
if ($item !== '.' && $item !== '..') {
$item = $dir.DIRECTORY_SEPARATOR.$item;
\is_dir($item) ? static::remove($item) : @\unlink($item);
}
}
@\closedir($handle);
}
if ($emptyOnly === false) {
@\rmdir($dir);
}
return true;
}
return $ret;
} | php | public static function remove(string $dir = '', bool $emptyOnly = false): bool
{
$ret = true;
$dir = static::normalizePath($dir);
if (static::exists($dir)) {
if ($handle = @\opendir($dir)) {
while (false !== ($item = @\readdir($handle))) {
if ($item !== '.' && $item !== '..') {
$item = $dir.DIRECTORY_SEPARATOR.$item;
\is_dir($item) ? static::remove($item) : @\unlink($item);
}
}
@\closedir($handle);
}
if ($emptyOnly === false) {
@\rmdir($dir);
}
return true;
}
return $ret;
} | [
"public",
"static",
"function",
"remove",
"(",
"string",
"$",
"dir",
"=",
"''",
",",
"bool",
"$",
"emptyOnly",
"=",
"false",
")",
":",
"bool",
"{",
"$",
"ret",
"=",
"true",
";",
"$",
"dir",
"=",
"static",
"::",
"normalizePath",
"(",
"$",
"dir",
")",
";",
"if",
"(",
"static",
"::",
"exists",
"(",
"$",
"dir",
")",
")",
"{",
"if",
"(",
"$",
"handle",
"=",
"@",
"\\",
"opendir",
"(",
"$",
"dir",
")",
")",
"{",
"while",
"(",
"false",
"!==",
"(",
"$",
"item",
"=",
"@",
"\\",
"readdir",
"(",
"$",
"handle",
")",
")",
")",
"{",
"if",
"(",
"$",
"item",
"!==",
"'.'",
"&&",
"$",
"item",
"!==",
"'..'",
")",
"{",
"$",
"item",
"=",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"item",
";",
"\\",
"is_dir",
"(",
"$",
"item",
")",
"?",
"static",
"::",
"remove",
"(",
"$",
"item",
")",
":",
"@",
"\\",
"unlink",
"(",
"$",
"item",
")",
";",
"}",
"}",
"@",
"\\",
"closedir",
"(",
"$",
"handle",
")",
";",
"}",
"if",
"(",
"$",
"emptyOnly",
"===",
"false",
")",
"{",
"@",
"\\",
"rmdir",
"(",
"$",
"dir",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Removes a directory with all subdirectories, files and symbolic links inside.
@param string $dir
@param bool $emptyOnly
@return bool | [
"Removes",
"a",
"directory",
"with",
"all",
"subdirectories",
"files",
"and",
"symbolic",
"links",
"inside",
"."
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Filesystem/Directory.php#L108-L129 |
12,729 | phplegends/http | src/UploadedFile.php | UploadedFile.moveToDirectory | public function moveToDirectory($directory)
{
$targetPath = rtrim($directory, '/') . '/' . $this->getClientFilename();
return $this->moveTo($targetPath);
} | php | public function moveToDirectory($directory)
{
$targetPath = rtrim($directory, '/') . '/' . $this->getClientFilename();
return $this->moveTo($targetPath);
} | [
"public",
"function",
"moveToDirectory",
"(",
"$",
"directory",
")",
"{",
"$",
"targetPath",
"=",
"rtrim",
"(",
"$",
"directory",
",",
"'/'",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"getClientFilename",
"(",
")",
";",
"return",
"$",
"this",
"->",
"moveTo",
"(",
"$",
"targetPath",
")",
";",
"}"
] | Move file from directory, keeping the cliente file name
@param string $directory | [
"Move",
"file",
"from",
"directory",
"keeping",
"the",
"cliente",
"file",
"name"
] | a172792b71d12c88a05ac15faacc3a8ab110fb25 | https://github.com/phplegends/http/blob/a172792b71d12c88a05ac15faacc3a8ab110fb25/src/UploadedFile.php#L170-L175 |
12,730 | phplegends/http | src/UploadedFile.php | UploadedFile.getErrorMessage | public function getErrorMessage()
{
if (array_key_exists($this->error, $this->errorMessages)) {
return $this->errorMessages[$this->error];
}
return 'Unknow error';
} | php | public function getErrorMessage()
{
if (array_key_exists($this->error, $this->errorMessages)) {
return $this->errorMessages[$this->error];
}
return 'Unknow error';
} | [
"public",
"function",
"getErrorMessage",
"(",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"this",
"->",
"error",
",",
"$",
"this",
"->",
"errorMessages",
")",
")",
"{",
"return",
"$",
"this",
"->",
"errorMessages",
"[",
"$",
"this",
"->",
"error",
"]",
";",
"}",
"return",
"'Unknow error'",
";",
"}"
] | Gets the value of errorMessages.
@return mixed | [
"Gets",
"the",
"value",
"of",
"errorMessages",
"."
] | a172792b71d12c88a05ac15faacc3a8ab110fb25 | https://github.com/phplegends/http/blob/a172792b71d12c88a05ac15faacc3a8ab110fb25/src/UploadedFile.php#L239-L247 |
12,731 | SyberIsle/pipeline | src/Pipeline/Simple.php | Simple.pipe | public function pipe($stage)
{
$pipeline = clone $this;
$this->handleStage($pipeline->stages, $stage);
return $pipeline;
} | php | public function pipe($stage)
{
$pipeline = clone $this;
$this->handleStage($pipeline->stages, $stage);
return $pipeline;
} | [
"public",
"function",
"pipe",
"(",
"$",
"stage",
")",
"{",
"$",
"pipeline",
"=",
"clone",
"$",
"this",
";",
"$",
"this",
"->",
"handleStage",
"(",
"$",
"pipeline",
"->",
"stages",
",",
"$",
"stage",
")",
";",
"return",
"$",
"pipeline",
";",
"}"
] | Create a new pipeline with an appended stage.
@param Pipeline|Stage|callable $stage
@return static | [
"Create",
"a",
"new",
"pipeline",
"with",
"an",
"appended",
"stage",
"."
] | b34b02665a00a220aa56e3fd4e86290f8d07dac8 | https://github.com/SyberIsle/pipeline/blob/b34b02665a00a220aa56e3fd4e86290f8d07dac8/src/Pipeline/Simple.php#L45-L51 |
12,732 | SyberIsle/pipeline | src/Pipeline/Simple.php | Simple.handleStage | protected function handleStage(&$stages, $stage)
{
if ($stage instanceof Pipeline) {
$stages = array_merge($stages, $stage->stages());
} else {
$stages[] = is_callable($stage) ? new Callback($stage) : $stage;
}
} | php | protected function handleStage(&$stages, $stage)
{
if ($stage instanceof Pipeline) {
$stages = array_merge($stages, $stage->stages());
} else {
$stages[] = is_callable($stage) ? new Callback($stage) : $stage;
}
} | [
"protected",
"function",
"handleStage",
"(",
"&",
"$",
"stages",
",",
"$",
"stage",
")",
"{",
"if",
"(",
"$",
"stage",
"instanceof",
"Pipeline",
")",
"{",
"$",
"stages",
"=",
"array_merge",
"(",
"$",
"stages",
",",
"$",
"stage",
"->",
"stages",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"stages",
"[",
"]",
"=",
"is_callable",
"(",
"$",
"stage",
")",
"?",
"new",
"Callback",
"(",
"$",
"stage",
")",
":",
"$",
"stage",
";",
"}",
"}"
] | Handles merging or converting the stage to a callback
@param array $stages
@param Pipeline|Stage|callable $stage | [
"Handles",
"merging",
"or",
"converting",
"the",
"stage",
"to",
"a",
"callback"
] | b34b02665a00a220aa56e3fd4e86290f8d07dac8 | https://github.com/SyberIsle/pipeline/blob/b34b02665a00a220aa56e3fd4e86290f8d07dac8/src/Pipeline/Simple.php#L81-L88 |
12,733 | monolyth-php/frontal | src/Controller.php | Controller.run | public function run()
{
$request = ServerRequestFactory::fromGlobals();
$this->pipeline->build()
->pipe(new Stage(function (ResponseInterface $response = null) {
$emitter = new SapiEmitter;
if (is_null($response)) {
throw new Exception(404);
}
return $emitter->emit($response);
}))
->process($request);
} | php | public function run()
{
$request = ServerRequestFactory::fromGlobals();
$this->pipeline->build()
->pipe(new Stage(function (ResponseInterface $response = null) {
$emitter = new SapiEmitter;
if (is_null($response)) {
throw new Exception(404);
}
return $emitter->emit($response);
}))
->process($request);
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"request",
"=",
"ServerRequestFactory",
"::",
"fromGlobals",
"(",
")",
";",
"$",
"this",
"->",
"pipeline",
"->",
"build",
"(",
")",
"->",
"pipe",
"(",
"new",
"Stage",
"(",
"function",
"(",
"ResponseInterface",
"$",
"response",
"=",
"null",
")",
"{",
"$",
"emitter",
"=",
"new",
"SapiEmitter",
";",
"if",
"(",
"is_null",
"(",
"$",
"response",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"404",
")",
";",
"}",
"return",
"$",
"emitter",
"->",
"emit",
"(",
"$",
"response",
")",
";",
"}",
")",
")",
"->",
"process",
"(",
"$",
"request",
")",
";",
"}"
] | Run the HTTP kernel controller. This processes your pipeline and emits
the resulting response.
@throws Error|Exception If any error or exception gets thrown during
processing, your front controller should handle that gracefully (or not
so gracefully if you're still developing). | [
"Run",
"the",
"HTTP",
"kernel",
"controller",
".",
"This",
"processes",
"your",
"pipeline",
"and",
"emits",
"the",
"resulting",
"response",
"."
] | 5577a71e31d140594cba658942b12779af90f780 | https://github.com/monolyth-php/frontal/blob/5577a71e31d140594cba658942b12779af90f780/src/Controller.php#L64-L76 |
12,734 | stk2k/decoy | src/AutogeneratedFile.php | AutogeneratedFile.export | public function export(string $path) : File
{
$target_dir = new File($path);
if (!$target_dir->exists()){
throw new DecoyException('Export target directory not exists:' . $path);
}
if (!$target_dir->canWrite()){
throw new DecoyException('Export target directory not writable:' . $path);
}
$file = new File($this->autogenerated_file->getName(), $target_dir);
$parent_dir = $file->getParent();
try{
$parent_dir->makeDirectory();
}
catch(MakeDirectoryException $e){
throw new DecoyException('Making parent directory failed:' . $parent_dir, $e);
}
try{
$file->putContents($this->autogenerated_file->getContent());
}
catch(FileOutputException $e){
throw new DecoyException('Writing output file failed:' . $file);
}
return $file;
} | php | public function export(string $path) : File
{
$target_dir = new File($path);
if (!$target_dir->exists()){
throw new DecoyException('Export target directory not exists:' . $path);
}
if (!$target_dir->canWrite()){
throw new DecoyException('Export target directory not writable:' . $path);
}
$file = new File($this->autogenerated_file->getName(), $target_dir);
$parent_dir = $file->getParent();
try{
$parent_dir->makeDirectory();
}
catch(MakeDirectoryException $e){
throw new DecoyException('Making parent directory failed:' . $parent_dir, $e);
}
try{
$file->putContents($this->autogenerated_file->getContent());
}
catch(FileOutputException $e){
throw new DecoyException('Writing output file failed:' . $file);
}
return $file;
} | [
"public",
"function",
"export",
"(",
"string",
"$",
"path",
")",
":",
"File",
"{",
"$",
"target_dir",
"=",
"new",
"File",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"$",
"target_dir",
"->",
"exists",
"(",
")",
")",
"{",
"throw",
"new",
"DecoyException",
"(",
"'Export target directory not exists:'",
".",
"$",
"path",
")",
";",
"}",
"if",
"(",
"!",
"$",
"target_dir",
"->",
"canWrite",
"(",
")",
")",
"{",
"throw",
"new",
"DecoyException",
"(",
"'Export target directory not writable:'",
".",
"$",
"path",
")",
";",
"}",
"$",
"file",
"=",
"new",
"File",
"(",
"$",
"this",
"->",
"autogenerated_file",
"->",
"getName",
"(",
")",
",",
"$",
"target_dir",
")",
";",
"$",
"parent_dir",
"=",
"$",
"file",
"->",
"getParent",
"(",
")",
";",
"try",
"{",
"$",
"parent_dir",
"->",
"makeDirectory",
"(",
")",
";",
"}",
"catch",
"(",
"MakeDirectoryException",
"$",
"e",
")",
"{",
"throw",
"new",
"DecoyException",
"(",
"'Making parent directory failed:'",
".",
"$",
"parent_dir",
",",
"$",
"e",
")",
";",
"}",
"try",
"{",
"$",
"file",
"->",
"putContents",
"(",
"$",
"this",
"->",
"autogenerated_file",
"->",
"getContent",
"(",
")",
")",
";",
"}",
"catch",
"(",
"FileOutputException",
"$",
"e",
")",
"{",
"throw",
"new",
"DecoyException",
"(",
"'Writing output file failed:'",
".",
"$",
"file",
")",
";",
"}",
"return",
"$",
"file",
";",
"}"
] | Export to local file
@param string $path
@return File
@throws DecoyException | [
"Export",
"to",
"local",
"file"
] | 743653d78b3a67e5e4fba8e4297eb3ffe64e4899 | https://github.com/stk2k/decoy/blob/743653d78b3a67e5e4fba8e4297eb3ffe64e4899/src/AutogeneratedFile.php#L34-L63 |
12,735 | tlumx/tlumx-servicecontainer | src/ServiceContainer.php | ServiceContainer.get | public function get($id)
{
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
if (!isset($this->keys[$id])) {
throw new NotFoundException(sprintf(
'The service "%s" is not found',
$id
));
}
if (isset($this->values[$id])) {
return $this->values[$id];
}
if (! $this->keys[$id]) {
if (isset($this->factories[$id])) {
return $this->createFromFactory($this->factories[$id]);
} else {
return $this->createFromDefinition($this->definition[$id]);
}
}
if (isset($this->factories[$id])) {
$service = $this->createFromFactory($this->factories[$id]);
unset($this->factories[$id]);
} else {
$service = $this->createFromDefinition($this->definition[$id]);
unset($this->definition[$id]);
}
$this->values[$id] = $service;
$this->immutable[$id] = true;
return $service;
} | php | public function get($id)
{
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
if (!isset($this->keys[$id])) {
throw new NotFoundException(sprintf(
'The service "%s" is not found',
$id
));
}
if (isset($this->values[$id])) {
return $this->values[$id];
}
if (! $this->keys[$id]) {
if (isset($this->factories[$id])) {
return $this->createFromFactory($this->factories[$id]);
} else {
return $this->createFromDefinition($this->definition[$id]);
}
}
if (isset($this->factories[$id])) {
$service = $this->createFromFactory($this->factories[$id]);
unset($this->factories[$id]);
} else {
$service = $this->createFromDefinition($this->definition[$id]);
unset($this->definition[$id]);
}
$this->values[$id] = $service;
$this->immutable[$id] = true;
return $service;
} | [
"public",
"function",
"get",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"aliases",
"[",
"$",
"id",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"keys",
"[",
"$",
"id",
"]",
")",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"sprintf",
"(",
"'The service \"%s\" is not found'",
",",
"$",
"id",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"id",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"values",
"[",
"$",
"id",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"keys",
"[",
"$",
"id",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"factories",
"[",
"$",
"id",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"createFromFactory",
"(",
"$",
"this",
"->",
"factories",
"[",
"$",
"id",
"]",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"createFromDefinition",
"(",
"$",
"this",
"->",
"definition",
"[",
"$",
"id",
"]",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"factories",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"service",
"=",
"$",
"this",
"->",
"createFromFactory",
"(",
"$",
"this",
"->",
"factories",
"[",
"$",
"id",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"factories",
"[",
"$",
"id",
"]",
")",
";",
"}",
"else",
"{",
"$",
"service",
"=",
"$",
"this",
"->",
"createFromDefinition",
"(",
"$",
"this",
"->",
"definition",
"[",
"$",
"id",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"definition",
"[",
"$",
"id",
"]",
")",
";",
"}",
"$",
"this",
"->",
"values",
"[",
"$",
"id",
"]",
"=",
"$",
"service",
";",
"$",
"this",
"->",
"immutable",
"[",
"$",
"id",
"]",
"=",
"true",
";",
"return",
"$",
"service",
";",
"}"
] | Get entry of the container by its identifier.
@param string $id Identifier of the service.
@return mixed Entry of the container.
@throws NotFoundException If service not exist in container. | [
"Get",
"entry",
"of",
"the",
"container",
"by",
"its",
"identifier",
"."
] | 3aef3e6b790092f5c3e232410abd91727930f720 | https://github.com/tlumx/tlumx-servicecontainer/blob/3aef3e6b790092f5c3e232410abd91727930f720/src/ServiceContainer.php#L74-L110 |
12,736 | tlumx/tlumx-servicecontainer | src/ServiceContainer.php | ServiceContainer.setAlias | public function setAlias($alias, $service)
{
if ($alias == $service) {
throw new ContainerException('Alias and service names can not be equals');
}
$this->aliases[$alias] = $service;
} | php | public function setAlias($alias, $service)
{
if ($alias == $service) {
throw new ContainerException('Alias and service names can not be equals');
}
$this->aliases[$alias] = $service;
} | [
"public",
"function",
"setAlias",
"(",
"$",
"alias",
",",
"$",
"service",
")",
"{",
"if",
"(",
"$",
"alias",
"==",
"$",
"service",
")",
"{",
"throw",
"new",
"ContainerException",
"(",
"'Alias and service names can not be equals'",
")",
";",
"}",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
"=",
"$",
"service",
";",
"}"
] | Set entry alias in the container
@param string $alias Identifier for entry alias.
@param string $service Identifier of the service for which the alias is define.
@throws ContainerException Error while service name and aliad are equals. | [
"Set",
"entry",
"alias",
"in",
"the",
"container"
] | 3aef3e6b790092f5c3e232410abd91727930f720 | https://github.com/tlumx/tlumx-servicecontainer/blob/3aef3e6b790092f5c3e232410abd91727930f720/src/ServiceContainer.php#L144-L151 |
12,737 | tlumx/tlumx-servicecontainer | src/ServiceContainer.php | ServiceContainer.getServiceIdFromAlias | public function getServiceIdFromAlias($alias, $default = null)
{
if (isset($this->aliases[$alias])) {
return $this->aliases[$alias];
}
return $default;
} | php | public function getServiceIdFromAlias($alias, $default = null)
{
if (isset($this->aliases[$alias])) {
return $this->aliases[$alias];
}
return $default;
} | [
"public",
"function",
"getServiceIdFromAlias",
"(",
"$",
"alias",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Retrive service identifier for alias or default value, if alias is not
define.
@param string $alias Alias identifier.
@param mixed $default Default value, if alias not registred.
@return string|mixed Service identifier or default value. | [
"Retrive",
"service",
"identifier",
"for",
"alias",
"or",
"default",
"value",
"if",
"alias",
"is",
"not",
"define",
"."
] | 3aef3e6b790092f5c3e232410abd91727930f720 | https://github.com/tlumx/tlumx-servicecontainer/blob/3aef3e6b790092f5c3e232410abd91727930f720/src/ServiceContainer.php#L194-L201 |
12,738 | tlumx/tlumx-servicecontainer | src/ServiceContainer.php | ServiceContainer.has | public function has($id)
{
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
return isset($this->keys[$id]);
} | php | public function has($id)
{
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
return isset($this->keys[$id]);
} | [
"public",
"function",
"has",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"aliases",
"[",
"$",
"id",
"]",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"keys",
"[",
"$",
"id",
"]",
")",
";",
"}"
] | Returns true if the container can return an entry for the given
identifier and returns false otherwise.
@param string $id Identifier of the service.
@return bool True - if the container can return an entry for the given
identifier, false - otherwise. | [
"Returns",
"true",
"if",
"the",
"container",
"can",
"return",
"an",
"entry",
"for",
"the",
"given",
"identifier",
"and",
"returns",
"false",
"otherwise",
"."
] | 3aef3e6b790092f5c3e232410abd91727930f720 | https://github.com/tlumx/tlumx-servicecontainer/blob/3aef3e6b790092f5c3e232410abd91727930f720/src/ServiceContainer.php#L211-L218 |
12,739 | tlumx/tlumx-servicecontainer | src/ServiceContainer.php | ServiceContainer.remove | public function remove($id)
{
if (isset($this->aliases[$id])) {
$aliasId = $id;
$id = $this->aliases[$id];
unset($this->aliases[$aliasId]);
}
unset($this->keys[$id]);
unset($this->values[$id]);
unset($this->immutable[$id]);
unset($this->factories[$id]);
unset($this->definition[$id]);
} | php | public function remove($id)
{
if (isset($this->aliases[$id])) {
$aliasId = $id;
$id = $this->aliases[$id];
unset($this->aliases[$aliasId]);
}
unset($this->keys[$id]);
unset($this->values[$id]);
unset($this->immutable[$id]);
unset($this->factories[$id]);
unset($this->definition[$id]);
} | [
"public",
"function",
"remove",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"aliasId",
"=",
"$",
"id",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"aliases",
"[",
"$",
"id",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"aliasId",
"]",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"keys",
"[",
"$",
"id",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"id",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"immutable",
"[",
"$",
"id",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"factories",
"[",
"$",
"id",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"definition",
"[",
"$",
"id",
"]",
")",
";",
"}"
] | Remove an entry of the container by its identifier.
@param string $id Identifier of the service. | [
"Remove",
"an",
"entry",
"of",
"the",
"container",
"by",
"its",
"identifier",
"."
] | 3aef3e6b790092f5c3e232410abd91727930f720 | https://github.com/tlumx/tlumx-servicecontainer/blob/3aef3e6b790092f5c3e232410abd91727930f720/src/ServiceContainer.php#L225-L238 |
12,740 | tlumx/tlumx-servicecontainer | src/ServiceContainer.php | ServiceContainer.registerDefinition | public function registerDefinition($id, array $definition, $isShared = true)
{
if (isset($this->immutable[$id])) {
throw new ContainerException(sprintf(
'A service by the name "%s" already exists and cannot be overridden',
$id
));
}
$this->definition[$id] = $definition;
$this->keys[$id] = boolval($isShared);
if (isset($this->aliases[$id])) {
unset($this->aliases[$id]);
}
} | php | public function registerDefinition($id, array $definition, $isShared = true)
{
if (isset($this->immutable[$id])) {
throw new ContainerException(sprintf(
'A service by the name "%s" already exists and cannot be overridden',
$id
));
}
$this->definition[$id] = $definition;
$this->keys[$id] = boolval($isShared);
if (isset($this->aliases[$id])) {
unset($this->aliases[$id]);
}
} | [
"public",
"function",
"registerDefinition",
"(",
"$",
"id",
",",
"array",
"$",
"definition",
",",
"$",
"isShared",
"=",
"true",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"immutable",
"[",
"$",
"id",
"]",
")",
")",
"{",
"throw",
"new",
"ContainerException",
"(",
"sprintf",
"(",
"'A service by the name \"%s\" already exists and cannot be overridden'",
",",
"$",
"id",
")",
")",
";",
"}",
"$",
"this",
"->",
"definition",
"[",
"$",
"id",
"]",
"=",
"$",
"definition",
";",
"$",
"this",
"->",
"keys",
"[",
"$",
"id",
"]",
"=",
"boolval",
"(",
"$",
"isShared",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"id",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"id",
"]",
")",
";",
"}",
"}"
] | Register array of definition, which will be used to create the service.
@param string $id Identifier of the service.
@param array $definition Array of service definition.
@param bool $isShared Indicating whether or not the service is shared.
@throws ContainerException Error while service already exists and cannot
be overridden. | [
"Register",
"array",
"of",
"definition",
"which",
"will",
"be",
"used",
"to",
"create",
"the",
"service",
"."
] | 3aef3e6b790092f5c3e232410abd91727930f720 | https://github.com/tlumx/tlumx-servicecontainer/blob/3aef3e6b790092f5c3e232410abd91727930f720/src/ServiceContainer.php#L280-L295 |
12,741 | tlumx/tlumx-servicecontainer | src/ServiceContainer.php | ServiceContainer.createFromFactory | protected function createFromFactory($factory)
{
try {
if (is_string($factory) && class_exists($factory)) {
$factory = new $factory();
}
if (is_callable($factory)) {
$service = $factory($this);
} else {
throw new ContainerException(
'Service could not be created: "There were incorrectly '
. 'transmitted data when registering the service".'
);
}
} catch (ContainerException $e) {
throw $e;
} catch (\Throwable $e) {
throw new ContainerException(
'Service could not be created: "Service factory may be '
. 'callable or string (that can be resolving to an '
. 'invokable class or to a FactoryInterface instance).'
);
}
return $service;
} | php | protected function createFromFactory($factory)
{
try {
if (is_string($factory) && class_exists($factory)) {
$factory = new $factory();
}
if (is_callable($factory)) {
$service = $factory($this);
} else {
throw new ContainerException(
'Service could not be created: "There were incorrectly '
. 'transmitted data when registering the service".'
);
}
} catch (ContainerException $e) {
throw $e;
} catch (\Throwable $e) {
throw new ContainerException(
'Service could not be created: "Service factory may be '
. 'callable or string (that can be resolving to an '
. 'invokable class or to a FactoryInterface instance).'
);
}
return $service;
} | [
"protected",
"function",
"createFromFactory",
"(",
"$",
"factory",
")",
"{",
"try",
"{",
"if",
"(",
"is_string",
"(",
"$",
"factory",
")",
"&&",
"class_exists",
"(",
"$",
"factory",
")",
")",
"{",
"$",
"factory",
"=",
"new",
"$",
"factory",
"(",
")",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"factory",
")",
")",
"{",
"$",
"service",
"=",
"$",
"factory",
"(",
"$",
"this",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"ContainerException",
"(",
"'Service could not be created: \"There were incorrectly '",
".",
"'transmitted data when registering the service\".'",
")",
";",
"}",
"}",
"catch",
"(",
"ContainerException",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"throw",
"new",
"ContainerException",
"(",
"'Service could not be created: \"Service factory may be '",
".",
"'callable or string (that can be resolving to an '",
".",
"'invokable class or to a FactoryInterface instance).'",
")",
";",
"}",
"return",
"$",
"service",
";",
"}"
] | Create a new instance of service from factory.
@param string|callable $factory The service factory.
@return mixed New service.
@throws ContainerException Error while service could not be created. | [
"Create",
"a",
"new",
"instance",
"of",
"service",
"from",
"factory",
"."
] | 3aef3e6b790092f5c3e232410abd91727930f720 | https://github.com/tlumx/tlumx-servicecontainer/blob/3aef3e6b790092f5c3e232410abd91727930f720/src/ServiceContainer.php#L304-L330 |
12,742 | tlumx/tlumx-servicecontainer | src/ServiceContainer.php | ServiceContainer.createFromDefinition | protected function createFromDefinition(array $definition)
{
if (!isset($definition['class'])) {
throw new ContainerException(
'Service could not be created from definition:'
. ' option "class" is not exists in definition array.'
);
}
$className = $definition['class'];
if (!class_exists($className)) {
throw new ContainerException(sprintf(
'Service could not be created from definition:'
. ' Class "%s" is not exists.',
$className
));
}
$reflection = new \ReflectionClass($className);
if (!$reflection->isInstantiable()) {
throw new ContainerException(sprintf(
'Service could not be created from definition:'
. ' Unable to create instance of class "%s".',
$className
));
}
if (null !== ($constructor = $reflection->getConstructor())) {
if (!isset($definition['args'])) {
throw new ContainerException(
'Service could not be created from definition:'
. ' option "args" is not exists in definition array.'
);
}
$params = $this->resolveArgs($constructor->getParameters(), $definition['args']);
$service = $reflection->newInstanceArgs($params);
} else {
// we don't have a constructor
$service = $reflection->newInstance();
}
if (!isset($definition['calls'])) {
return $service;
}
$calls = isset($definition['calls']) ? $definition['calls'] : [];
foreach ($calls as $method => $args) {
if (!is_callable([$service, $method])) {
throw new ContainerException(sprintf(
'Service could not be created from definition:'
. ' can not call method "%s" from class: "%s"',
$method,
$className
));
}
$method = new \ReflectionMethod($service, $method);
$params = $method->getParameters();
$arguments = is_array($args)
? $this->resolveArgs($params, $args)
: [];
$method->invokeArgs($service, $arguments);
}
return $service;
} | php | protected function createFromDefinition(array $definition)
{
if (!isset($definition['class'])) {
throw new ContainerException(
'Service could not be created from definition:'
. ' option "class" is not exists in definition array.'
);
}
$className = $definition['class'];
if (!class_exists($className)) {
throw new ContainerException(sprintf(
'Service could not be created from definition:'
. ' Class "%s" is not exists.',
$className
));
}
$reflection = new \ReflectionClass($className);
if (!$reflection->isInstantiable()) {
throw new ContainerException(sprintf(
'Service could not be created from definition:'
. ' Unable to create instance of class "%s".',
$className
));
}
if (null !== ($constructor = $reflection->getConstructor())) {
if (!isset($definition['args'])) {
throw new ContainerException(
'Service could not be created from definition:'
. ' option "args" is not exists in definition array.'
);
}
$params = $this->resolveArgs($constructor->getParameters(), $definition['args']);
$service = $reflection->newInstanceArgs($params);
} else {
// we don't have a constructor
$service = $reflection->newInstance();
}
if (!isset($definition['calls'])) {
return $service;
}
$calls = isset($definition['calls']) ? $definition['calls'] : [];
foreach ($calls as $method => $args) {
if (!is_callable([$service, $method])) {
throw new ContainerException(sprintf(
'Service could not be created from definition:'
. ' can not call method "%s" from class: "%s"',
$method,
$className
));
}
$method = new \ReflectionMethod($service, $method);
$params = $method->getParameters();
$arguments = is_array($args)
? $this->resolveArgs($params, $args)
: [];
$method->invokeArgs($service, $arguments);
}
return $service;
} | [
"protected",
"function",
"createFromDefinition",
"(",
"array",
"$",
"definition",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"definition",
"[",
"'class'",
"]",
")",
")",
"{",
"throw",
"new",
"ContainerException",
"(",
"'Service could not be created from definition:'",
".",
"' option \"class\" is not exists in definition array.'",
")",
";",
"}",
"$",
"className",
"=",
"$",
"definition",
"[",
"'class'",
"]",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"ContainerException",
"(",
"sprintf",
"(",
"'Service could not be created from definition:'",
".",
"' Class \"%s\" is not exists.'",
",",
"$",
"className",
")",
")",
";",
"}",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"if",
"(",
"!",
"$",
"reflection",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"throw",
"new",
"ContainerException",
"(",
"sprintf",
"(",
"'Service could not be created from definition:'",
".",
"' Unable to create instance of class \"%s\".'",
",",
"$",
"className",
")",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"(",
"$",
"constructor",
"=",
"$",
"reflection",
"->",
"getConstructor",
"(",
")",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"definition",
"[",
"'args'",
"]",
")",
")",
"{",
"throw",
"new",
"ContainerException",
"(",
"'Service could not be created from definition:'",
".",
"' option \"args\" is not exists in definition array.'",
")",
";",
"}",
"$",
"params",
"=",
"$",
"this",
"->",
"resolveArgs",
"(",
"$",
"constructor",
"->",
"getParameters",
"(",
")",
",",
"$",
"definition",
"[",
"'args'",
"]",
")",
";",
"$",
"service",
"=",
"$",
"reflection",
"->",
"newInstanceArgs",
"(",
"$",
"params",
")",
";",
"}",
"else",
"{",
"// we don't have a constructor",
"$",
"service",
"=",
"$",
"reflection",
"->",
"newInstance",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"definition",
"[",
"'calls'",
"]",
")",
")",
"{",
"return",
"$",
"service",
";",
"}",
"$",
"calls",
"=",
"isset",
"(",
"$",
"definition",
"[",
"'calls'",
"]",
")",
"?",
"$",
"definition",
"[",
"'calls'",
"]",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"calls",
"as",
"$",
"method",
"=>",
"$",
"args",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"[",
"$",
"service",
",",
"$",
"method",
"]",
")",
")",
"{",
"throw",
"new",
"ContainerException",
"(",
"sprintf",
"(",
"'Service could not be created from definition:'",
".",
"' can not call method \"%s\" from class: \"%s\"'",
",",
"$",
"method",
",",
"$",
"className",
")",
")",
";",
"}",
"$",
"method",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"service",
",",
"$",
"method",
")",
";",
"$",
"params",
"=",
"$",
"method",
"->",
"getParameters",
"(",
")",
";",
"$",
"arguments",
"=",
"is_array",
"(",
"$",
"args",
")",
"?",
"$",
"this",
"->",
"resolveArgs",
"(",
"$",
"params",
",",
"$",
"args",
")",
":",
"[",
"]",
";",
"$",
"method",
"->",
"invokeArgs",
"(",
"$",
"service",
",",
"$",
"arguments",
")",
";",
"}",
"return",
"$",
"service",
";",
"}"
] | Create a new instance of service from array definition.
@param array $definition Servise definition.
@return mixed New service.
@throws ContainerException Error while service could not be created. | [
"Create",
"a",
"new",
"instance",
"of",
"service",
"from",
"array",
"definition",
"."
] | 3aef3e6b790092f5c3e232410abd91727930f720 | https://github.com/tlumx/tlumx-servicecontainer/blob/3aef3e6b790092f5c3e232410abd91727930f720/src/ServiceContainer.php#L339-L405 |
12,743 | tmquang6805/phalex | library/Phalex/Mvc/Application.php | Application.getCacheInstance | private function getCacheInstance(array $config)
{
if (!isset($config['enable']) || !$config['enable']) {
return null;
}
$className = $config['adapter'];
if (!class_exists($className)) {
$errMsg = sprintf('Adapter "%s" is not supported for caching', $config['adapter']);
throw new Exception\RuntimeException($errMsg);
}
return new $className($config['options']);
} | php | private function getCacheInstance(array $config)
{
if (!isset($config['enable']) || !$config['enable']) {
return null;
}
$className = $config['adapter'];
if (!class_exists($className)) {
$errMsg = sprintf('Adapter "%s" is not supported for caching', $config['adapter']);
throw new Exception\RuntimeException($errMsg);
}
return new $className($config['options']);
} | [
"private",
"function",
"getCacheInstance",
"(",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'enable'",
"]",
")",
"||",
"!",
"$",
"config",
"[",
"'enable'",
"]",
")",
"{",
"return",
"null",
";",
"}",
"$",
"className",
"=",
"$",
"config",
"[",
"'adapter'",
"]",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"$",
"errMsg",
"=",
"sprintf",
"(",
"'Adapter \"%s\" is not supported for caching'",
",",
"$",
"config",
"[",
"'adapter'",
"]",
")",
";",
"throw",
"new",
"Exception",
"\\",
"RuntimeException",
"(",
"$",
"errMsg",
")",
";",
"}",
"return",
"new",
"$",
"className",
"(",
"$",
"config",
"[",
"'options'",
"]",
")",
";",
"}"
] | Get cache instance for config or module
@param array $config
@return null|object
@throws Exception\RuntimeException | [
"Get",
"cache",
"instance",
"for",
"config",
"or",
"module"
] | 6452b4e695b456838d9d553d96f2b114e1c110b4 | https://github.com/tmquang6805/phalex/blob/6452b4e695b456838d9d553d96f2b114e1c110b4/library/Phalex/Mvc/Application.php#L53-L65 |
12,744 | tmquang6805/phalex | library/Phalex/Mvc/Application.php | Application.initPhalconApplication | protected function initPhalconApplication()
{
$diFactory = $this->diManager->getDI();
$moduleHandler = $diFactory->get('moduleHandler');
// Register autoloader
(new Autoloader($diFactory))->register();
// Register services and routers
$this->diManager->initInvokableServices()
->initFactoriedServices()
->initRouterDi();
// Init listeners
(new Listener($diFactory))
->listenApplicationEvents(new Listener\Application())
->listenDispatchEvents(new Listener\Dispatch());
// Register modules
$application = new PhalconApplication($diFactory);
$application->setEventsManager($diFactory['eventsManager']);
$application->registerModules($moduleHandler->getRegisteredModules());
return $application;
} | php | protected function initPhalconApplication()
{
$diFactory = $this->diManager->getDI();
$moduleHandler = $diFactory->get('moduleHandler');
// Register autoloader
(new Autoloader($diFactory))->register();
// Register services and routers
$this->diManager->initInvokableServices()
->initFactoriedServices()
->initRouterDi();
// Init listeners
(new Listener($diFactory))
->listenApplicationEvents(new Listener\Application())
->listenDispatchEvents(new Listener\Dispatch());
// Register modules
$application = new PhalconApplication($diFactory);
$application->setEventsManager($diFactory['eventsManager']);
$application->registerModules($moduleHandler->getRegisteredModules());
return $application;
} | [
"protected",
"function",
"initPhalconApplication",
"(",
")",
"{",
"$",
"diFactory",
"=",
"$",
"this",
"->",
"diManager",
"->",
"getDI",
"(",
")",
";",
"$",
"moduleHandler",
"=",
"$",
"diFactory",
"->",
"get",
"(",
"'moduleHandler'",
")",
";",
"// Register autoloader",
"(",
"new",
"Autoloader",
"(",
"$",
"diFactory",
")",
")",
"->",
"register",
"(",
")",
";",
"// Register services and routers",
"$",
"this",
"->",
"diManager",
"->",
"initInvokableServices",
"(",
")",
"->",
"initFactoriedServices",
"(",
")",
"->",
"initRouterDi",
"(",
")",
";",
"// Init listeners",
"(",
"new",
"Listener",
"(",
"$",
"diFactory",
")",
")",
"->",
"listenApplicationEvents",
"(",
"new",
"Listener",
"\\",
"Application",
"(",
")",
")",
"->",
"listenDispatchEvents",
"(",
"new",
"Listener",
"\\",
"Dispatch",
"(",
")",
")",
";",
"// Register modules",
"$",
"application",
"=",
"new",
"PhalconApplication",
"(",
"$",
"diFactory",
")",
";",
"$",
"application",
"->",
"setEventsManager",
"(",
"$",
"diFactory",
"[",
"'eventsManager'",
"]",
")",
";",
"$",
"application",
"->",
"registerModules",
"(",
"$",
"moduleHandler",
"->",
"getRegisteredModules",
"(",
")",
")",
";",
"return",
"$",
"application",
";",
"}"
] | Initialize phalcon application
@return PhalconApplication | [
"Initialize",
"phalcon",
"application"
] | 6452b4e695b456838d9d553d96f2b114e1c110b4 | https://github.com/tmquang6805/phalex/blob/6452b4e695b456838d9d553d96f2b114e1c110b4/library/Phalex/Mvc/Application.php#L76-L100 |
12,745 | transfer-framework/bridge-bundle | DependencyInjection/BridgeExtension.php | BridgeExtension.generateServices | private function generateServices(array $services, ContainerBuilder $container)
{
foreach ($services as $serviceName => $service) {
$serviceId = 'bridge.'.$serviceName;
$serviceDefinition = $this->createComponentDefinition($serviceName, $service['class'], $service['options']);
$serviceDefinition->addMethodCall('setEventDispatcher', array(new Reference('bridge.event_dispatcher')));
$serviceDefinition->addMethodCall('setRegistry', array(new Reference('bridge.registry')));
$this->generateGroups($service['groups'], $serviceId, $serviceDefinition, $container);
$container->setDefinition($serviceId, $serviceDefinition);
$container
->getDefinition('bridge.registry')
->addMethodCall('addService', array(new Reference($serviceId)));
}
} | php | private function generateServices(array $services, ContainerBuilder $container)
{
foreach ($services as $serviceName => $service) {
$serviceId = 'bridge.'.$serviceName;
$serviceDefinition = $this->createComponentDefinition($serviceName, $service['class'], $service['options']);
$serviceDefinition->addMethodCall('setEventDispatcher', array(new Reference('bridge.event_dispatcher')));
$serviceDefinition->addMethodCall('setRegistry', array(new Reference('bridge.registry')));
$this->generateGroups($service['groups'], $serviceId, $serviceDefinition, $container);
$container->setDefinition($serviceId, $serviceDefinition);
$container
->getDefinition('bridge.registry')
->addMethodCall('addService', array(new Reference($serviceId)));
}
} | [
"private",
"function",
"generateServices",
"(",
"array",
"$",
"services",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"foreach",
"(",
"$",
"services",
"as",
"$",
"serviceName",
"=>",
"$",
"service",
")",
"{",
"$",
"serviceId",
"=",
"'bridge.'",
".",
"$",
"serviceName",
";",
"$",
"serviceDefinition",
"=",
"$",
"this",
"->",
"createComponentDefinition",
"(",
"$",
"serviceName",
",",
"$",
"service",
"[",
"'class'",
"]",
",",
"$",
"service",
"[",
"'options'",
"]",
")",
";",
"$",
"serviceDefinition",
"->",
"addMethodCall",
"(",
"'setEventDispatcher'",
",",
"array",
"(",
"new",
"Reference",
"(",
"'bridge.event_dispatcher'",
")",
")",
")",
";",
"$",
"serviceDefinition",
"->",
"addMethodCall",
"(",
"'setRegistry'",
",",
"array",
"(",
"new",
"Reference",
"(",
"'bridge.registry'",
")",
")",
")",
";",
"$",
"this",
"->",
"generateGroups",
"(",
"$",
"service",
"[",
"'groups'",
"]",
",",
"$",
"serviceId",
",",
"$",
"serviceDefinition",
",",
"$",
"container",
")",
";",
"$",
"container",
"->",
"setDefinition",
"(",
"$",
"serviceId",
",",
"$",
"serviceDefinition",
")",
";",
"$",
"container",
"->",
"getDefinition",
"(",
"'bridge.registry'",
")",
"->",
"addMethodCall",
"(",
"'addService'",
",",
"array",
"(",
"new",
"Reference",
"(",
"$",
"serviceId",
")",
")",
")",
";",
"}",
"}"
] | Generates service definitions for services.
@param array $services Services
@param ContainerBuilder $container Container builder | [
"Generates",
"service",
"definitions",
"for",
"services",
"."
] | 258d0152aa80a7d48b2fa0e30b3810db1b1b913e | https://github.com/transfer-framework/bridge-bundle/blob/258d0152aa80a7d48b2fa0e30b3810db1b1b913e/DependencyInjection/BridgeExtension.php#L50-L67 |
12,746 | transfer-framework/bridge-bundle | DependencyInjection/BridgeExtension.php | BridgeExtension.generateGroups | private function generateGroups(array $groups, $parentId, Definition $parent, ContainerBuilder $container)
{
foreach ($groups as $groupName => $group) {
$groupId = $parentId.'.'.$groupName;
$groupDefinition = $this->createComponentDefinition($groupName, $group['class'], $group['options']);
$groupDefinition->addMethodCall('setService', array(new Reference($parentId)));
$this->generateActions($group['actions'], $groupId, $groupDefinition, $container);
$container->setDefinition($groupId, $groupDefinition);
$parent->addMethodCall('addGroup', array(new Reference($groupId)));
}
} | php | private function generateGroups(array $groups, $parentId, Definition $parent, ContainerBuilder $container)
{
foreach ($groups as $groupName => $group) {
$groupId = $parentId.'.'.$groupName;
$groupDefinition = $this->createComponentDefinition($groupName, $group['class'], $group['options']);
$groupDefinition->addMethodCall('setService', array(new Reference($parentId)));
$this->generateActions($group['actions'], $groupId, $groupDefinition, $container);
$container->setDefinition($groupId, $groupDefinition);
$parent->addMethodCall('addGroup', array(new Reference($groupId)));
}
} | [
"private",
"function",
"generateGroups",
"(",
"array",
"$",
"groups",
",",
"$",
"parentId",
",",
"Definition",
"$",
"parent",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"groupName",
"=>",
"$",
"group",
")",
"{",
"$",
"groupId",
"=",
"$",
"parentId",
".",
"'.'",
".",
"$",
"groupName",
";",
"$",
"groupDefinition",
"=",
"$",
"this",
"->",
"createComponentDefinition",
"(",
"$",
"groupName",
",",
"$",
"group",
"[",
"'class'",
"]",
",",
"$",
"group",
"[",
"'options'",
"]",
")",
";",
"$",
"groupDefinition",
"->",
"addMethodCall",
"(",
"'setService'",
",",
"array",
"(",
"new",
"Reference",
"(",
"$",
"parentId",
")",
")",
")",
";",
"$",
"this",
"->",
"generateActions",
"(",
"$",
"group",
"[",
"'actions'",
"]",
",",
"$",
"groupId",
",",
"$",
"groupDefinition",
",",
"$",
"container",
")",
";",
"$",
"container",
"->",
"setDefinition",
"(",
"$",
"groupId",
",",
"$",
"groupDefinition",
")",
";",
"$",
"parent",
"->",
"addMethodCall",
"(",
"'addGroup'",
",",
"array",
"(",
"new",
"Reference",
"(",
"$",
"groupId",
")",
")",
")",
";",
"}",
"}"
] | Generates services definitions for groups associated to a service.
@param array $groups Groups
@param string $parentId Parent component ID
@param Definition $parent Parent service definition
@param ContainerBuilder $container Container builder | [
"Generates",
"services",
"definitions",
"for",
"groups",
"associated",
"to",
"a",
"service",
"."
] | 258d0152aa80a7d48b2fa0e30b3810db1b1b913e | https://github.com/transfer-framework/bridge-bundle/blob/258d0152aa80a7d48b2fa0e30b3810db1b1b913e/DependencyInjection/BridgeExtension.php#L77-L91 |
12,747 | transfer-framework/bridge-bundle | DependencyInjection/BridgeExtension.php | BridgeExtension.generateActions | private function generateActions(array $actions, $parentId, Definition $parent, ContainerBuilder $container)
{
foreach ($actions as $actionName => $action) {
$actionId = $parentId.'.'.$actionName;
$actionDefinition = $this->createComponentDefinition($actionName, $action['class'], $action['options']);
$actionDefinition->addMethodCall('setGroup', array(new Reference($parentId)));
$container->setDefinition($actionId, $actionDefinition);
$parent->addMethodCall('addAction', array(new Reference($actionId)));
}
} | php | private function generateActions(array $actions, $parentId, Definition $parent, ContainerBuilder $container)
{
foreach ($actions as $actionName => $action) {
$actionId = $parentId.'.'.$actionName;
$actionDefinition = $this->createComponentDefinition($actionName, $action['class'], $action['options']);
$actionDefinition->addMethodCall('setGroup', array(new Reference($parentId)));
$container->setDefinition($actionId, $actionDefinition);
$parent->addMethodCall('addAction', array(new Reference($actionId)));
}
} | [
"private",
"function",
"generateActions",
"(",
"array",
"$",
"actions",
",",
"$",
"parentId",
",",
"Definition",
"$",
"parent",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"actionName",
"=>",
"$",
"action",
")",
"{",
"$",
"actionId",
"=",
"$",
"parentId",
".",
"'.'",
".",
"$",
"actionName",
";",
"$",
"actionDefinition",
"=",
"$",
"this",
"->",
"createComponentDefinition",
"(",
"$",
"actionName",
",",
"$",
"action",
"[",
"'class'",
"]",
",",
"$",
"action",
"[",
"'options'",
"]",
")",
";",
"$",
"actionDefinition",
"->",
"addMethodCall",
"(",
"'setGroup'",
",",
"array",
"(",
"new",
"Reference",
"(",
"$",
"parentId",
")",
")",
")",
";",
"$",
"container",
"->",
"setDefinition",
"(",
"$",
"actionId",
",",
"$",
"actionDefinition",
")",
";",
"$",
"parent",
"->",
"addMethodCall",
"(",
"'addAction'",
",",
"array",
"(",
"new",
"Reference",
"(",
"$",
"actionId",
")",
")",
")",
";",
"}",
"}"
] | Generates service definitions for actions associated to service groups.
@param array $actions Actions
@param string $parentId Parent component ID
@param Definition $parent Parent definition
@param ContainerBuilder $container Container builder | [
"Generates",
"service",
"definitions",
"for",
"actions",
"associated",
"to",
"service",
"groups",
"."
] | 258d0152aa80a7d48b2fa0e30b3810db1b1b913e | https://github.com/transfer-framework/bridge-bundle/blob/258d0152aa80a7d48b2fa0e30b3810db1b1b913e/DependencyInjection/BridgeExtension.php#L101-L113 |
12,748 | bkdotcom/Toolbox | src/Session.php | Session.destroy | public static function destroy()
{
if (\session_status() !== PHP_SESSION_ACTIVE) {
return false;
}
foreach (\array_keys($_SESSION) as $key) {
unset($_SESSION[$key]);
}
self::$cfgStatic['id'] = null;
$success = \session_destroy();
if (!$success) {
return false;
}
/*
Clear cookie so new session not automatically started on next page load
If strict mode is enabled... this isn't exactly necessary... a new id will be used..
however, we may not want to start a new session
*/
\setcookie(
self::$cfgStatic['name'],
'',
\time()-60*60*24,
self::$cfgStatic['cookiePath'],
self::$cfgStatic['cookieDomain'],
self::$cfgStatic['cookieSecure'],
self::$cfgStatic['cookieHttponly']
);
return $success;
} | php | public static function destroy()
{
if (\session_status() !== PHP_SESSION_ACTIVE) {
return false;
}
foreach (\array_keys($_SESSION) as $key) {
unset($_SESSION[$key]);
}
self::$cfgStatic['id'] = null;
$success = \session_destroy();
if (!$success) {
return false;
}
/*
Clear cookie so new session not automatically started on next page load
If strict mode is enabled... this isn't exactly necessary... a new id will be used..
however, we may not want to start a new session
*/
\setcookie(
self::$cfgStatic['name'],
'',
\time()-60*60*24,
self::$cfgStatic['cookiePath'],
self::$cfgStatic['cookieDomain'],
self::$cfgStatic['cookieSecure'],
self::$cfgStatic['cookieHttponly']
);
return $success;
} | [
"public",
"static",
"function",
"destroy",
"(",
")",
"{",
"if",
"(",
"\\",
"session_status",
"(",
")",
"!==",
"PHP_SESSION_ACTIVE",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"\\",
"array_keys",
"(",
"$",
"_SESSION",
")",
"as",
"$",
"key",
")",
"{",
"unset",
"(",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
")",
";",
"}",
"self",
"::",
"$",
"cfgStatic",
"[",
"'id'",
"]",
"=",
"null",
";",
"$",
"success",
"=",
"\\",
"session_destroy",
"(",
")",
";",
"if",
"(",
"!",
"$",
"success",
")",
"{",
"return",
"false",
";",
"}",
"/*\n Clear cookie so new session not automatically started on next page load\n If strict mode is enabled... this isn't exactly necessary... a new id will be used..\n however, we may not want to start a new session\n */",
"\\",
"setcookie",
"(",
"self",
"::",
"$",
"cfgStatic",
"[",
"'name'",
"]",
",",
"''",
",",
"\\",
"time",
"(",
")",
"-",
"60",
"*",
"60",
"*",
"24",
",",
"self",
"::",
"$",
"cfgStatic",
"[",
"'cookiePath'",
"]",
",",
"self",
"::",
"$",
"cfgStatic",
"[",
"'cookieDomain'",
"]",
",",
"self",
"::",
"$",
"cfgStatic",
"[",
"'cookieSecure'",
"]",
",",
"self",
"::",
"$",
"cfgStatic",
"[",
"'cookieHttponly'",
"]",
")",
";",
"return",
"$",
"success",
";",
"}"
] | Destroys all data registered to session
Removes session cookie
@return boolean | [
"Destroys",
"all",
"data",
"registered",
"to",
"session",
"Removes",
"session",
"cookie"
] | 2f9d34fd57bd8382baee4c29aac13a6710e3a994 | https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/Session.php#L143-L171 |
12,749 | bkdotcom/Toolbox | src/Session.php | Session.gc | public static function gc()
{
if (\version_compare(PHP_VERSION, '7.0.0', '>=')) {
return \session_gc();
}
/*
Polyfill for PHP < 7
*/
$initial = array(
'status' => \session_status(),
'probability' => \ini_get('session.gc_probability'),
'divisor' => \ini_get('session.gc_divisor'),
);
if ($initial['status'] === PHP_SESSION_DISABLED) {
return false;
}
if ($initial['status'] === PHP_SESSION_ACTIVE) {
// garbage collection is performed on session_start..
// close our open session... and restart it
\session_write_close();
}
\ini_set('session.gc_probability', 1);
\ini_set('session.gc_divisor', 1);
\session_start();
\ini_set('session.gc_probability', $initial['probability']);
\ini_set('session.gc_divisor', $initial['divisor']);
if ($initial['status'] === PHP_SESSION_NONE) {
if (self::$status['requestId']) {
\session_write_close();
} else {
\session_destroy();
}
}
return true;
} | php | public static function gc()
{
if (\version_compare(PHP_VERSION, '7.0.0', '>=')) {
return \session_gc();
}
/*
Polyfill for PHP < 7
*/
$initial = array(
'status' => \session_status(),
'probability' => \ini_get('session.gc_probability'),
'divisor' => \ini_get('session.gc_divisor'),
);
if ($initial['status'] === PHP_SESSION_DISABLED) {
return false;
}
if ($initial['status'] === PHP_SESSION_ACTIVE) {
// garbage collection is performed on session_start..
// close our open session... and restart it
\session_write_close();
}
\ini_set('session.gc_probability', 1);
\ini_set('session.gc_divisor', 1);
\session_start();
\ini_set('session.gc_probability', $initial['probability']);
\ini_set('session.gc_divisor', $initial['divisor']);
if ($initial['status'] === PHP_SESSION_NONE) {
if (self::$status['requestId']) {
\session_write_close();
} else {
\session_destroy();
}
}
return true;
} | [
"public",
"static",
"function",
"gc",
"(",
")",
"{",
"if",
"(",
"\\",
"version_compare",
"(",
"PHP_VERSION",
",",
"'7.0.0'",
",",
"'>='",
")",
")",
"{",
"return",
"\\",
"session_gc",
"(",
")",
";",
"}",
"/*\n Polyfill for PHP < 7\n */",
"$",
"initial",
"=",
"array",
"(",
"'status'",
"=>",
"\\",
"session_status",
"(",
")",
",",
"'probability'",
"=>",
"\\",
"ini_get",
"(",
"'session.gc_probability'",
")",
",",
"'divisor'",
"=>",
"\\",
"ini_get",
"(",
"'session.gc_divisor'",
")",
",",
")",
";",
"if",
"(",
"$",
"initial",
"[",
"'status'",
"]",
"===",
"PHP_SESSION_DISABLED",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"initial",
"[",
"'status'",
"]",
"===",
"PHP_SESSION_ACTIVE",
")",
"{",
"// garbage collection is performed on session_start..",
"// close our open session... and restart it",
"\\",
"session_write_close",
"(",
")",
";",
"}",
"\\",
"ini_set",
"(",
"'session.gc_probability'",
",",
"1",
")",
";",
"\\",
"ini_set",
"(",
"'session.gc_divisor'",
",",
"1",
")",
";",
"\\",
"session_start",
"(",
")",
";",
"\\",
"ini_set",
"(",
"'session.gc_probability'",
",",
"$",
"initial",
"[",
"'probability'",
"]",
")",
";",
"\\",
"ini_set",
"(",
"'session.gc_divisor'",
",",
"$",
"initial",
"[",
"'divisor'",
"]",
")",
";",
"if",
"(",
"$",
"initial",
"[",
"'status'",
"]",
"===",
"PHP_SESSION_NONE",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"status",
"[",
"'requestId'",
"]",
")",
"{",
"\\",
"session_write_close",
"(",
")",
";",
"}",
"else",
"{",
"\\",
"session_destroy",
"(",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Perform session data garbage collection
@return integer number of deleted sessions | [
"Perform",
"session",
"data",
"garbage",
"collection"
] | 2f9d34fd57bd8382baee4c29aac13a6710e3a994 | https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/Session.php#L178-L212 |
12,750 | bkdotcom/Toolbox | src/Session.php | Session.& | public static function &get($key)
{
self::startIf();
if (isset($_SESSION[$key])) {
return $_SESSION[$key];
} else {
$val = null;
return $val;
}
} | php | public static function &get($key)
{
self::startIf();
if (isset($_SESSION[$key])) {
return $_SESSION[$key];
} else {
$val = null;
return $val;
}
} | [
"public",
"static",
"function",
"&",
"get",
"(",
"$",
"key",
")",
"{",
"self",
"::",
"startIf",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"$",
"val",
"=",
"null",
";",
"return",
"$",
"val",
";",
"}",
"}"
] | Get session value
Essentially just a wrapper for
start session (if not started)
$_SESSION[$key]
@param string $key session key
@return mixed The key's value, or the default value | [
"Get",
"session",
"value"
] | 2f9d34fd57bd8382baee4c29aac13a6710e3a994 | https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/Session.php#L225-L234 |
12,751 | bkdotcom/Toolbox | src/Session.php | Session.regenerateId | public static function regenerateId($delOldSession = false)
{
$success = false;
if (self::$status['regenerated']) {
// already regenerated... no sense in doing it again
return false;
}
if (empty(self::$status['requestId'])) {
// no session id was passed... there's no need to regenerate!
return false;
}
if (\session_status() === PHP_SESSION_NONE) {
// there's currently not a session
self::$cfgStatic['regenOnStart'] = true;
}
if (\session_status() === PHP_SESSION_ACTIVE) {
$success = \session_regenerate_id($delOldSession);
self::$cfgStatic['regenOnStart'] = false;
self::$status['regenerated'] = true;
}
if ($success) {
\bdk\Debug::_info('new session_id', \session_id());
}
return $success;
} | php | public static function regenerateId($delOldSession = false)
{
$success = false;
if (self::$status['regenerated']) {
// already regenerated... no sense in doing it again
return false;
}
if (empty(self::$status['requestId'])) {
// no session id was passed... there's no need to regenerate!
return false;
}
if (\session_status() === PHP_SESSION_NONE) {
// there's currently not a session
self::$cfgStatic['regenOnStart'] = true;
}
if (\session_status() === PHP_SESSION_ACTIVE) {
$success = \session_regenerate_id($delOldSession);
self::$cfgStatic['regenOnStart'] = false;
self::$status['regenerated'] = true;
}
if ($success) {
\bdk\Debug::_info('new session_id', \session_id());
}
return $success;
} | [
"public",
"static",
"function",
"regenerateId",
"(",
"$",
"delOldSession",
"=",
"false",
")",
"{",
"$",
"success",
"=",
"false",
";",
"if",
"(",
"self",
"::",
"$",
"status",
"[",
"'regenerated'",
"]",
")",
"{",
"// already regenerated... no sense in doing it again",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"status",
"[",
"'requestId'",
"]",
")",
")",
"{",
"// no session id was passed... there's no need to regenerate!",
"return",
"false",
";",
"}",
"if",
"(",
"\\",
"session_status",
"(",
")",
"===",
"PHP_SESSION_NONE",
")",
"{",
"// there's currently not a session",
"self",
"::",
"$",
"cfgStatic",
"[",
"'regenOnStart'",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"\\",
"session_status",
"(",
")",
"===",
"PHP_SESSION_ACTIVE",
")",
"{",
"$",
"success",
"=",
"\\",
"session_regenerate_id",
"(",
"$",
"delOldSession",
")",
";",
"self",
"::",
"$",
"cfgStatic",
"[",
"'regenOnStart'",
"]",
"=",
"false",
";",
"self",
"::",
"$",
"status",
"[",
"'regenerated'",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"success",
")",
"{",
"\\",
"bdk",
"\\",
"Debug",
"::",
"_info",
"(",
"'new session_id'",
",",
"\\",
"session_id",
"(",
")",
")",
";",
"}",
"return",
"$",
"success",
";",
"}"
] | Assign new session id
@param boolean $delOldSession invalidate existing id?
@return boolean | [
"Assign",
"new",
"session",
"id"
] | 2f9d34fd57bd8382baee4c29aac13a6710e3a994 | https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/Session.php#L275-L299 |
12,752 | bkdotcom/Toolbox | src/Session.php | Session.start | public static function start()
{
/*
session_id() will continue to return id even after session_write_close()
*/
if (\session_status() === PHP_SESSION_ACTIVE) {
return true;
}
if (\headers_sent()) {
return false;
}
self::setCfg(array()); // makes sure all default's determined and set
$success = \session_start();
\bdk\Debug::_info('started', \session_id());
if (self::$cfgStatic['regenOnStart']) {
self::regenerateId();
}
return $success;
} | php | public static function start()
{
/*
session_id() will continue to return id even after session_write_close()
*/
if (\session_status() === PHP_SESSION_ACTIVE) {
return true;
}
if (\headers_sent()) {
return false;
}
self::setCfg(array()); // makes sure all default's determined and set
$success = \session_start();
\bdk\Debug::_info('started', \session_id());
if (self::$cfgStatic['regenOnStart']) {
self::regenerateId();
}
return $success;
} | [
"public",
"static",
"function",
"start",
"(",
")",
"{",
"/*\n session_id() will continue to return id even after session_write_close()\n */",
"if",
"(",
"\\",
"session_status",
"(",
")",
"===",
"PHP_SESSION_ACTIVE",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"\\",
"headers_sent",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"self",
"::",
"setCfg",
"(",
"array",
"(",
")",
")",
";",
"// makes sure all default's determined and set",
"$",
"success",
"=",
"\\",
"session_start",
"(",
")",
";",
"\\",
"bdk",
"\\",
"Debug",
"::",
"_info",
"(",
"'started'",
",",
"\\",
"session_id",
"(",
")",
")",
";",
"if",
"(",
"self",
"::",
"$",
"cfgStatic",
"[",
"'regenOnStart'",
"]",
")",
"{",
"self",
"::",
"regenerateId",
"(",
")",
";",
"}",
"return",
"$",
"success",
";",
"}"
] | Start session if it's not already started
@return boolean | [
"Start",
"session",
"if",
"it",
"s",
"not",
"already",
"started"
] | 2f9d34fd57bd8382baee4c29aac13a6710e3a994 | https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/Session.php#L346-L364 |
12,753 | bkdotcom/Toolbox | src/Session.php | Session.cfgApply | private static function cfgApply()
{
$iniMap = array(
'gcMaxlifetime' => 'session.gc_maxlifetime',
'gcProbability' => 'session.gc_probability',
'gcDivisor' => 'session.gc_divisor',
'savePath' => 'session.save_path',
'useCookies' => 'session.use_cookies',
'useOnlyCookies'=> 'session.use_only_cookies',
);
foreach ($iniMap as $cfgKey => $iniKey) {
\ini_set($iniKey, self::$cfgStatic[$cfgKey]);
}
\session_set_cookie_params(
self::$cfgStatic['cookieLifetime'],
self::$cfgStatic['cookiePath'],
self::$cfgStatic['cookieDomain'],
self::$cfgStatic['cookieSecure'],
self::$cfgStatic['cookieHttponly'] // php >= 5.2.0
);
if (\ini_get('session.save_handler') == 'files' && !\is_dir(self::$cfgStatic['savePath'])) {
\bdk\Debug::_warn('savePath doesn\'t exist -> creating');
\mkdir(self::$cfgStatic['savePath'], 0700, true);
}
\session_cache_expire(self::$cfgStatic['cacheExpire']);
\session_cache_limiter(self::$cfgStatic['cacheLimiter']);
if (self::$cfgStatic['name'] != \session_name()) {
\session_name(self::$cfgStatic['name']);
}
if (self::$cfgStatic['id']) {
\bdk\Debug::_log('setting useStrictMode to false (session_id passed)');
\ini_set('session.use_strict_mode', false);
\session_id(self::$cfgStatic['id']);
} else {
\ini_set('session.use_strict_mode', self::$cfgStatic['useStrictMode']);
}
} | php | private static function cfgApply()
{
$iniMap = array(
'gcMaxlifetime' => 'session.gc_maxlifetime',
'gcProbability' => 'session.gc_probability',
'gcDivisor' => 'session.gc_divisor',
'savePath' => 'session.save_path',
'useCookies' => 'session.use_cookies',
'useOnlyCookies'=> 'session.use_only_cookies',
);
foreach ($iniMap as $cfgKey => $iniKey) {
\ini_set($iniKey, self::$cfgStatic[$cfgKey]);
}
\session_set_cookie_params(
self::$cfgStatic['cookieLifetime'],
self::$cfgStatic['cookiePath'],
self::$cfgStatic['cookieDomain'],
self::$cfgStatic['cookieSecure'],
self::$cfgStatic['cookieHttponly'] // php >= 5.2.0
);
if (\ini_get('session.save_handler') == 'files' && !\is_dir(self::$cfgStatic['savePath'])) {
\bdk\Debug::_warn('savePath doesn\'t exist -> creating');
\mkdir(self::$cfgStatic['savePath'], 0700, true);
}
\session_cache_expire(self::$cfgStatic['cacheExpire']);
\session_cache_limiter(self::$cfgStatic['cacheLimiter']);
if (self::$cfgStatic['name'] != \session_name()) {
\session_name(self::$cfgStatic['name']);
}
if (self::$cfgStatic['id']) {
\bdk\Debug::_log('setting useStrictMode to false (session_id passed)');
\ini_set('session.use_strict_mode', false);
\session_id(self::$cfgStatic['id']);
} else {
\ini_set('session.use_strict_mode', self::$cfgStatic['useStrictMode']);
}
} | [
"private",
"static",
"function",
"cfgApply",
"(",
")",
"{",
"$",
"iniMap",
"=",
"array",
"(",
"'gcMaxlifetime'",
"=>",
"'session.gc_maxlifetime'",
",",
"'gcProbability'",
"=>",
"'session.gc_probability'",
",",
"'gcDivisor'",
"=>",
"'session.gc_divisor'",
",",
"'savePath'",
"=>",
"'session.save_path'",
",",
"'useCookies'",
"=>",
"'session.use_cookies'",
",",
"'useOnlyCookies'",
"=>",
"'session.use_only_cookies'",
",",
")",
";",
"foreach",
"(",
"$",
"iniMap",
"as",
"$",
"cfgKey",
"=>",
"$",
"iniKey",
")",
"{",
"\\",
"ini_set",
"(",
"$",
"iniKey",
",",
"self",
"::",
"$",
"cfgStatic",
"[",
"$",
"cfgKey",
"]",
")",
";",
"}",
"\\",
"session_set_cookie_params",
"(",
"self",
"::",
"$",
"cfgStatic",
"[",
"'cookieLifetime'",
"]",
",",
"self",
"::",
"$",
"cfgStatic",
"[",
"'cookiePath'",
"]",
",",
"self",
"::",
"$",
"cfgStatic",
"[",
"'cookieDomain'",
"]",
",",
"self",
"::",
"$",
"cfgStatic",
"[",
"'cookieSecure'",
"]",
",",
"self",
"::",
"$",
"cfgStatic",
"[",
"'cookieHttponly'",
"]",
"// php >= 5.2.0",
")",
";",
"if",
"(",
"\\",
"ini_get",
"(",
"'session.save_handler'",
")",
"==",
"'files'",
"&&",
"!",
"\\",
"is_dir",
"(",
"self",
"::",
"$",
"cfgStatic",
"[",
"'savePath'",
"]",
")",
")",
"{",
"\\",
"bdk",
"\\",
"Debug",
"::",
"_warn",
"(",
"'savePath doesn\\'t exist -> creating'",
")",
";",
"\\",
"mkdir",
"(",
"self",
"::",
"$",
"cfgStatic",
"[",
"'savePath'",
"]",
",",
"0700",
",",
"true",
")",
";",
"}",
"\\",
"session_cache_expire",
"(",
"self",
"::",
"$",
"cfgStatic",
"[",
"'cacheExpire'",
"]",
")",
";",
"\\",
"session_cache_limiter",
"(",
"self",
"::",
"$",
"cfgStatic",
"[",
"'cacheLimiter'",
"]",
")",
";",
"if",
"(",
"self",
"::",
"$",
"cfgStatic",
"[",
"'name'",
"]",
"!=",
"\\",
"session_name",
"(",
")",
")",
"{",
"\\",
"session_name",
"(",
"self",
"::",
"$",
"cfgStatic",
"[",
"'name'",
"]",
")",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"cfgStatic",
"[",
"'id'",
"]",
")",
"{",
"\\",
"bdk",
"\\",
"Debug",
"::",
"_log",
"(",
"'setting useStrictMode to false (session_id passed)'",
")",
";",
"\\",
"ini_set",
"(",
"'session.use_strict_mode'",
",",
"false",
")",
";",
"\\",
"session_id",
"(",
"self",
"::",
"$",
"cfgStatic",
"[",
"'id'",
"]",
")",
";",
"}",
"else",
"{",
"\\",
"ini_set",
"(",
"'session.use_strict_mode'",
",",
"self",
"::",
"$",
"cfgStatic",
"[",
"'useStrictMode'",
"]",
")",
";",
"}",
"}"
] | Apply configuration settings
@return void | [
"Apply",
"configuration",
"settings"
] | 2f9d34fd57bd8382baee4c29aac13a6710e3a994 | https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/Session.php#L385-L421 |
12,754 | bkdotcom/Toolbox | src/Session.php | Session.cfgGetDefaults | private static function cfgGetDefaults()
{
if (self::$status['cfgInitialized']) {
return array();
}
$defaults = array(
'cacheExpire' => \session_cache_expire(), // int (minutes) session_cache_expire()
// only applies when cacheLimiter != 'nocache'
'cacheLimiter' => \session_cache_limiter(), // session_cache_limiter()
// public | private_no_expire | private | nocache
'gcMaxlifetime' => (int) \ini_get('session.gc_maxlifetime'),
'gcProbability' => (int) \ini_get('session.gc_probability'),
'gcDivisor' => (int) \ini_get('session.gc_divisor'),
'savePath' => (string) \ini_get('session.save_path'),
'name' => empty(self::$cfgExplicitlySet['name'])
? self::cfgGetDefaultName()
: null, // meh, who cares
);
if (empty($defaults['savePath']) && \ini_get('session.save_handler') == 'files') {
$defaults['savePath'] = \sys_get_temp_dir();
}
self::$status['cfgInitialized'] = true;
return \array_diff_key($defaults, self::$cfgExplicitlySet);
} | php | private static function cfgGetDefaults()
{
if (self::$status['cfgInitialized']) {
return array();
}
$defaults = array(
'cacheExpire' => \session_cache_expire(), // int (minutes) session_cache_expire()
// only applies when cacheLimiter != 'nocache'
'cacheLimiter' => \session_cache_limiter(), // session_cache_limiter()
// public | private_no_expire | private | nocache
'gcMaxlifetime' => (int) \ini_get('session.gc_maxlifetime'),
'gcProbability' => (int) \ini_get('session.gc_probability'),
'gcDivisor' => (int) \ini_get('session.gc_divisor'),
'savePath' => (string) \ini_get('session.save_path'),
'name' => empty(self::$cfgExplicitlySet['name'])
? self::cfgGetDefaultName()
: null, // meh, who cares
);
if (empty($defaults['savePath']) && \ini_get('session.save_handler') == 'files') {
$defaults['savePath'] = \sys_get_temp_dir();
}
self::$status['cfgInitialized'] = true;
return \array_diff_key($defaults, self::$cfgExplicitlySet);
} | [
"private",
"static",
"function",
"cfgGetDefaults",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"status",
"[",
"'cfgInitialized'",
"]",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"defaults",
"=",
"array",
"(",
"'cacheExpire'",
"=>",
"\\",
"session_cache_expire",
"(",
")",
",",
"// int (minutes) session_cache_expire()",
"// only applies when cacheLimiter != 'nocache'",
"'cacheLimiter'",
"=>",
"\\",
"session_cache_limiter",
"(",
")",
",",
"// session_cache_limiter()",
"// public | private_no_expire | private | nocache",
"'gcMaxlifetime'",
"=>",
"(",
"int",
")",
"\\",
"ini_get",
"(",
"'session.gc_maxlifetime'",
")",
",",
"'gcProbability'",
"=>",
"(",
"int",
")",
"\\",
"ini_get",
"(",
"'session.gc_probability'",
")",
",",
"'gcDivisor'",
"=>",
"(",
"int",
")",
"\\",
"ini_get",
"(",
"'session.gc_divisor'",
")",
",",
"'savePath'",
"=>",
"(",
"string",
")",
"\\",
"ini_get",
"(",
"'session.save_path'",
")",
",",
"'name'",
"=>",
"empty",
"(",
"self",
"::",
"$",
"cfgExplicitlySet",
"[",
"'name'",
"]",
")",
"?",
"self",
"::",
"cfgGetDefaultName",
"(",
")",
":",
"null",
",",
"// meh, who cares",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"defaults",
"[",
"'savePath'",
"]",
")",
"&&",
"\\",
"ini_get",
"(",
"'session.save_handler'",
")",
"==",
"'files'",
")",
"{",
"$",
"defaults",
"[",
"'savePath'",
"]",
"=",
"\\",
"sys_get_temp_dir",
"(",
")",
";",
"}",
"self",
"::",
"$",
"status",
"[",
"'cfgInitialized'",
"]",
"=",
"true",
";",
"return",
"\\",
"array_diff_key",
"(",
"$",
"defaults",
",",
"self",
"::",
"$",
"cfgExplicitlySet",
")",
";",
"}"
] | Get default config values
@return array | [
"Get",
"default",
"config",
"values"
] | 2f9d34fd57bd8382baee4c29aac13a6710e3a994 | https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/Session.php#L428-L451 |
12,755 | bkdotcom/Toolbox | src/Session.php | Session.cfgGetDefaultName | private static function cfgGetDefaultName()
{
$nameDefault = null;
$sessionNamePref = array('SESSIONID', \session_name());
foreach ($sessionNamePref as $nameTest) {
$useCookies = isset(self::$cfgExplicitlySet['useCookies'])
? self::$cfgExplicitlySet['useCookies']
: self::$cfgStatic['useCookies'];
if ($useCookies && !empty($_COOKIE[$nameTest])) {
$nameDefault = $nameTest;
self::$status['requestId'] = $_COOKIE[$nameTest];
break;
}
$useOnlyCookies = isset(self::$cfgExplicitlySet['useOnlyCookies'])
? self::$cfgExplicitlySet['useOnlyCookies']
: self::$cfgStatic['useOnlyCookies'];
if (!$useOnlyCookies && !empty($_GET[$nameTest])) {
$nameDefault = $nameTest;
self::$status['requestId'] = $_GET[$nameTest];
break;
}
}
if (!$nameDefault) {
$nameDefault = $sessionNamePref[0];
}
return $nameDefault;
} | php | private static function cfgGetDefaultName()
{
$nameDefault = null;
$sessionNamePref = array('SESSIONID', \session_name());
foreach ($sessionNamePref as $nameTest) {
$useCookies = isset(self::$cfgExplicitlySet['useCookies'])
? self::$cfgExplicitlySet['useCookies']
: self::$cfgStatic['useCookies'];
if ($useCookies && !empty($_COOKIE[$nameTest])) {
$nameDefault = $nameTest;
self::$status['requestId'] = $_COOKIE[$nameTest];
break;
}
$useOnlyCookies = isset(self::$cfgExplicitlySet['useOnlyCookies'])
? self::$cfgExplicitlySet['useOnlyCookies']
: self::$cfgStatic['useOnlyCookies'];
if (!$useOnlyCookies && !empty($_GET[$nameTest])) {
$nameDefault = $nameTest;
self::$status['requestId'] = $_GET[$nameTest];
break;
}
}
if (!$nameDefault) {
$nameDefault = $sessionNamePref[0];
}
return $nameDefault;
} | [
"private",
"static",
"function",
"cfgGetDefaultName",
"(",
")",
"{",
"$",
"nameDefault",
"=",
"null",
";",
"$",
"sessionNamePref",
"=",
"array",
"(",
"'SESSIONID'",
",",
"\\",
"session_name",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"sessionNamePref",
"as",
"$",
"nameTest",
")",
"{",
"$",
"useCookies",
"=",
"isset",
"(",
"self",
"::",
"$",
"cfgExplicitlySet",
"[",
"'useCookies'",
"]",
")",
"?",
"self",
"::",
"$",
"cfgExplicitlySet",
"[",
"'useCookies'",
"]",
":",
"self",
"::",
"$",
"cfgStatic",
"[",
"'useCookies'",
"]",
";",
"if",
"(",
"$",
"useCookies",
"&&",
"!",
"empty",
"(",
"$",
"_COOKIE",
"[",
"$",
"nameTest",
"]",
")",
")",
"{",
"$",
"nameDefault",
"=",
"$",
"nameTest",
";",
"self",
"::",
"$",
"status",
"[",
"'requestId'",
"]",
"=",
"$",
"_COOKIE",
"[",
"$",
"nameTest",
"]",
";",
"break",
";",
"}",
"$",
"useOnlyCookies",
"=",
"isset",
"(",
"self",
"::",
"$",
"cfgExplicitlySet",
"[",
"'useOnlyCookies'",
"]",
")",
"?",
"self",
"::",
"$",
"cfgExplicitlySet",
"[",
"'useOnlyCookies'",
"]",
":",
"self",
"::",
"$",
"cfgStatic",
"[",
"'useOnlyCookies'",
"]",
";",
"if",
"(",
"!",
"$",
"useOnlyCookies",
"&&",
"!",
"empty",
"(",
"$",
"_GET",
"[",
"$",
"nameTest",
"]",
")",
")",
"{",
"$",
"nameDefault",
"=",
"$",
"nameTest",
";",
"self",
"::",
"$",
"status",
"[",
"'requestId'",
"]",
"=",
"$",
"_GET",
"[",
"$",
"nameTest",
"]",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"nameDefault",
")",
"{",
"$",
"nameDefault",
"=",
"$",
"sessionNamePref",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"nameDefault",
";",
"}"
] | Determine session name
depending on useCookies and useOnlyCookies options:
if "PHPSESSID" param passed as COOKIE/GET then "PHPSESSID" will be used
Otherwise, SESSIONID will be used (ie preference is SESSIONID)
@return string | [
"Determine",
"session",
"name"
] | 2f9d34fd57bd8382baee4c29aac13a6710e3a994 | https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/Session.php#L462-L488 |
12,756 | weavephp/http-zenddiactoros | src/ResponseEmitter.php | ResponseEmitter.emit | public function emit(Response $response)
{
$emitter = new \Zend\Diactoros\Response\SapiEmitter();
$emitter->emit($response);
} | php | public function emit(Response $response)
{
$emitter = new \Zend\Diactoros\Response\SapiEmitter();
$emitter->emit($response);
} | [
"public",
"function",
"emit",
"(",
"Response",
"$",
"response",
")",
"{",
"$",
"emitter",
"=",
"new",
"\\",
"Zend",
"\\",
"Diactoros",
"\\",
"Response",
"\\",
"SapiEmitter",
"(",
")",
";",
"$",
"emitter",
"->",
"emit",
"(",
"$",
"response",
")",
";",
"}"
] | Output to the client the contents of the provided PSR7 Response object.
@param Response $response The response object to emit to the client.
@return null | [
"Output",
"to",
"the",
"client",
"the",
"contents",
"of",
"the",
"provided",
"PSR7",
"Response",
"object",
"."
] | cecf7c2dd5f1a6a015ed6eec4b46bf656a1ab59b | https://github.com/weavephp/http-zenddiactoros/blob/cecf7c2dd5f1a6a015ed6eec4b46bf656a1ab59b/src/ResponseEmitter.php#L22-L26 |
12,757 | movicon/movicon-db | src/db/DbTable.php | DbTable.select | public static function select($db, $tableName, $colNames, $id)
{
$cols = array_map(
function ($colName) {
return Db::quote($colName);
},
$colNames
);
$sql = "select " . implode($cols, ", ") .
" from " . Db::quote($tableName) . " where id = ?";
return $db->query($sql, [$id]);
} | php | public static function select($db, $tableName, $colNames, $id)
{
$cols = array_map(
function ($colName) {
return Db::quote($colName);
},
$colNames
);
$sql = "select " . implode($cols, ", ") .
" from " . Db::quote($tableName) . " where id = ?";
return $db->query($sql, [$id]);
} | [
"public",
"static",
"function",
"select",
"(",
"$",
"db",
",",
"$",
"tableName",
",",
"$",
"colNames",
",",
"$",
"id",
")",
"{",
"$",
"cols",
"=",
"array_map",
"(",
"function",
"(",
"$",
"colName",
")",
"{",
"return",
"Db",
"::",
"quote",
"(",
"$",
"colName",
")",
";",
"}",
",",
"$",
"colNames",
")",
";",
"$",
"sql",
"=",
"\"select \"",
".",
"implode",
"(",
"$",
"cols",
",",
"\", \"",
")",
".",
"\" from \"",
".",
"Db",
"::",
"quote",
"(",
"$",
"tableName",
")",
".",
"\" where id = ?\"",
";",
"return",
"$",
"db",
"->",
"query",
"(",
"$",
"sql",
",",
"[",
"$",
"id",
"]",
")",
";",
"}"
] | Selects a record from a table.
For example:
list(
$username,
$password
) = DbTable::select($db, "user", ["username", "password"], 1);
@param DbConnector $db Database connection
@param string $tableName Table name
@param string[] $colNames Column names
@param string $id Record ID
@return mixed[] | [
"Selects",
"a",
"record",
"from",
"a",
"table",
"."
] | 505023932d6cd82462bb0e89b9057175c4b14e38 | https://github.com/movicon/movicon-db/blob/505023932d6cd82462bb0e89b9057175c4b14e38/src/db/DbTable.php#L29-L41 |
12,758 | Puzzlout/FrameworkMvcLegacy | src/Core/FileManager/ArrayFilterFileSearch.php | ArrayFilterFileSearch.Init | public static function Init(\Puzzlout\Framework\Core\Application $app) {
$instance = new ArrayFilterFileSearch();
$instance->FileList = array();
$instance->ContextApp = $app;
return $instance;
} | php | public static function Init(\Puzzlout\Framework\Core\Application $app) {
$instance = new ArrayFilterFileSearch();
$instance->FileList = array();
$instance->ContextApp = $app;
return $instance;
} | [
"public",
"static",
"function",
"Init",
"(",
"\\",
"Puzzlout",
"\\",
"Framework",
"\\",
"Core",
"\\",
"Application",
"$",
"app",
")",
"{",
"$",
"instance",
"=",
"new",
"ArrayFilterFileSearch",
"(",
")",
";",
"$",
"instance",
"->",
"FileList",
"=",
"array",
"(",
")",
";",
"$",
"instance",
"->",
"ContextApp",
"=",
"$",
"app",
";",
"return",
"$",
"instance",
";",
"}"
] | Builds the instance of class
@return \Puzzlout\Framework\Core\DirectoryManager\ArrayFilterDirectorySearch | [
"Builds",
"the",
"instance",
"of",
"class"
] | 14e0fc5b16978cbd209f552ee9c649f66a0dfc6e | https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/Core/FileManager/ArrayFilterFileSearch.php#L23-L28 |
12,759 | Puzzlout/FrameworkMvcLegacy | src/Core/FileManager/ArrayFilterFileSearch.php | ArrayFilterFileSearch.AddFileToResult | private function AddFileToResult($directory, $file) {
if (array_key_exists($directory, $this->FileList)) {
array_push($this->FileList[$directory], $file);
return;
}
//array_push($this->FileList, $directory);
$this->FileList[$directory] = [$file];
} | php | private function AddFileToResult($directory, $file) {
if (array_key_exists($directory, $this->FileList)) {
array_push($this->FileList[$directory], $file);
return;
}
//array_push($this->FileList, $directory);
$this->FileList[$directory] = [$file];
} | [
"private",
"function",
"AddFileToResult",
"(",
"$",
"directory",
",",
"$",
"file",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"directory",
",",
"$",
"this",
"->",
"FileList",
")",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"FileList",
"[",
"$",
"directory",
"]",
",",
"$",
"file",
")",
";",
"return",
";",
"}",
"//array_push($this->FileList, $directory);",
"$",
"this",
"->",
"FileList",
"[",
"$",
"directory",
"]",
"=",
"[",
"$",
"file",
"]",
";",
"}"
] | Add a file to the result list in the proper subarray using the directory.
@param string $directory The directory where resides the file
@param string $file The file name | [
"Add",
"a",
"file",
"to",
"the",
"result",
"list",
"in",
"the",
"proper",
"subarray",
"using",
"the",
"directory",
"."
] | 14e0fc5b16978cbd209f552ee9c649f66a0dfc6e | https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/Core/FileManager/ArrayFilterFileSearch.php#L65-L72 |
12,760 | webriq/core | module/Paragraph/src/Grid/Paragraph/Controller/DashboardController.php | DashboardController.editAction | public function editAction()
{
$params = $this->params();
$request = $this->getRequest();
$service = $this->getServiceLocator();
$cid = $params->fromQuery( 'contentId' );
$pid = $params->fromRoute( 'paragraphId' );
$locale = $service->get( 'AdminLocale' )->getCurrent();
$model = $service->get( 'Grid\Paragraph\Model\Dashboard\Model' );
$permission = $service->get( 'Grid\User\Model\Permissions\Model' );
$dashboard = $model->setLocale( $locale )->find( $pid );
$customize = $permission->isAllowed( 'paragraph.customize', 'edit' );
if ( empty( $dashboard ) )
{
$this->getResponse()
->setStatusCode( 404 );
return;
}
$paragraph = $dashboard->paragraph;
if ( ! $paragraph->isEditable() )
{
$this->getResponse()
->setStatusCode( 403 );
return;
}
if ( $cid && $paragraph instanceof ContentDependentAwareInterface )
{
$content = $service->get( 'Grid\Paragraph\Model\Paragraph\Model' )
->setLocale( $locale )
->find( $cid );
if ( $content instanceof AbstractRoot )
{
$paragraph->setDependentContent( $content );
}
}
$form = $dashboard->getForm( $service->get( 'Form' ), $customize );
$view = new ViewModel( array(
'form' => $form,
'success' => null,
) );
if ( $request->isPost() )
{
$form->setData( $request->getPost() );
$view->setVariable( 'success',
$form->isValid() && $dashboard->save() );
}
return $view->setTerminal( true );
} | php | public function editAction()
{
$params = $this->params();
$request = $this->getRequest();
$service = $this->getServiceLocator();
$cid = $params->fromQuery( 'contentId' );
$pid = $params->fromRoute( 'paragraphId' );
$locale = $service->get( 'AdminLocale' )->getCurrent();
$model = $service->get( 'Grid\Paragraph\Model\Dashboard\Model' );
$permission = $service->get( 'Grid\User\Model\Permissions\Model' );
$dashboard = $model->setLocale( $locale )->find( $pid );
$customize = $permission->isAllowed( 'paragraph.customize', 'edit' );
if ( empty( $dashboard ) )
{
$this->getResponse()
->setStatusCode( 404 );
return;
}
$paragraph = $dashboard->paragraph;
if ( ! $paragraph->isEditable() )
{
$this->getResponse()
->setStatusCode( 403 );
return;
}
if ( $cid && $paragraph instanceof ContentDependentAwareInterface )
{
$content = $service->get( 'Grid\Paragraph\Model\Paragraph\Model' )
->setLocale( $locale )
->find( $cid );
if ( $content instanceof AbstractRoot )
{
$paragraph->setDependentContent( $content );
}
}
$form = $dashboard->getForm( $service->get( 'Form' ), $customize );
$view = new ViewModel( array(
'form' => $form,
'success' => null,
) );
if ( $request->isPost() )
{
$form->setData( $request->getPost() );
$view->setVariable( 'success',
$form->isValid() && $dashboard->save() );
}
return $view->setTerminal( true );
} | [
"public",
"function",
"editAction",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"params",
"(",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"service",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
";",
"$",
"cid",
"=",
"$",
"params",
"->",
"fromQuery",
"(",
"'contentId'",
")",
";",
"$",
"pid",
"=",
"$",
"params",
"->",
"fromRoute",
"(",
"'paragraphId'",
")",
";",
"$",
"locale",
"=",
"$",
"service",
"->",
"get",
"(",
"'AdminLocale'",
")",
"->",
"getCurrent",
"(",
")",
";",
"$",
"model",
"=",
"$",
"service",
"->",
"get",
"(",
"'Grid\\Paragraph\\Model\\Dashboard\\Model'",
")",
";",
"$",
"permission",
"=",
"$",
"service",
"->",
"get",
"(",
"'Grid\\User\\Model\\Permissions\\Model'",
")",
";",
"$",
"dashboard",
"=",
"$",
"model",
"->",
"setLocale",
"(",
"$",
"locale",
")",
"->",
"find",
"(",
"$",
"pid",
")",
";",
"$",
"customize",
"=",
"$",
"permission",
"->",
"isAllowed",
"(",
"'paragraph.customize'",
",",
"'edit'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"dashboard",
")",
")",
"{",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"setStatusCode",
"(",
"404",
")",
";",
"return",
";",
"}",
"$",
"paragraph",
"=",
"$",
"dashboard",
"->",
"paragraph",
";",
"if",
"(",
"!",
"$",
"paragraph",
"->",
"isEditable",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"setStatusCode",
"(",
"403",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"cid",
"&&",
"$",
"paragraph",
"instanceof",
"ContentDependentAwareInterface",
")",
"{",
"$",
"content",
"=",
"$",
"service",
"->",
"get",
"(",
"'Grid\\Paragraph\\Model\\Paragraph\\Model'",
")",
"->",
"setLocale",
"(",
"$",
"locale",
")",
"->",
"find",
"(",
"$",
"cid",
")",
";",
"if",
"(",
"$",
"content",
"instanceof",
"AbstractRoot",
")",
"{",
"$",
"paragraph",
"->",
"setDependentContent",
"(",
"$",
"content",
")",
";",
"}",
"}",
"$",
"form",
"=",
"$",
"dashboard",
"->",
"getForm",
"(",
"$",
"service",
"->",
"get",
"(",
"'Form'",
")",
",",
"$",
"customize",
")",
";",
"$",
"view",
"=",
"new",
"ViewModel",
"(",
"array",
"(",
"'form'",
"=>",
"$",
"form",
",",
"'success'",
"=>",
"null",
",",
")",
")",
";",
"if",
"(",
"$",
"request",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"form",
"->",
"setData",
"(",
"$",
"request",
"->",
"getPost",
"(",
")",
")",
";",
"$",
"view",
"->",
"setVariable",
"(",
"'success'",
",",
"$",
"form",
"->",
"isValid",
"(",
")",
"&&",
"$",
"dashboard",
"->",
"save",
"(",
")",
")",
";",
"}",
"return",
"$",
"view",
"->",
"setTerminal",
"(",
"true",
")",
";",
"}"
] | Edit-paragraph action | [
"Edit",
"-",
"paragraph",
"action"
] | cfeb6e8a4732561c2215ec94e736c07f9b8bc990 | https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Paragraph/src/Grid/Paragraph/Controller/DashboardController.php#L21-L78 |
12,761 | Silvestra/Silvestra | src/Silvestra/Component/Media/Image/Resizer/ImageResizerHelper.php | ImageResizerHelper.getBoxSize | public function getBoxSize(array $imageSize, array $size)
{
list($width, $height) = $size;
if ((null == $width) && (null == $height)) {
return $imageSize;
}
list($imageWidth, $imageHeight) = $imageSize;
if ((null !== $width) && (null == $height)) {
$height = ceil($width * ($imageHeight / $imageWidth));
if ($height > $imageHeight) {
$height = $imageHeight;
}
return array($width, $height);
}
if ((null === $width) && (null != $height)) {
$width = ceil($height * ($imageWidth / $imageHeight));
if ($width > $imageWidth) {
$width = $imageWidth;
}
return array($width, $height);
}
return $size;
} | php | public function getBoxSize(array $imageSize, array $size)
{
list($width, $height) = $size;
if ((null == $width) && (null == $height)) {
return $imageSize;
}
list($imageWidth, $imageHeight) = $imageSize;
if ((null !== $width) && (null == $height)) {
$height = ceil($width * ($imageHeight / $imageWidth));
if ($height > $imageHeight) {
$height = $imageHeight;
}
return array($width, $height);
}
if ((null === $width) && (null != $height)) {
$width = ceil($height * ($imageWidth / $imageHeight));
if ($width > $imageWidth) {
$width = $imageWidth;
}
return array($width, $height);
}
return $size;
} | [
"public",
"function",
"getBoxSize",
"(",
"array",
"$",
"imageSize",
",",
"array",
"$",
"size",
")",
"{",
"list",
"(",
"$",
"width",
",",
"$",
"height",
")",
"=",
"$",
"size",
";",
"if",
"(",
"(",
"null",
"==",
"$",
"width",
")",
"&&",
"(",
"null",
"==",
"$",
"height",
")",
")",
"{",
"return",
"$",
"imageSize",
";",
"}",
"list",
"(",
"$",
"imageWidth",
",",
"$",
"imageHeight",
")",
"=",
"$",
"imageSize",
";",
"if",
"(",
"(",
"null",
"!==",
"$",
"width",
")",
"&&",
"(",
"null",
"==",
"$",
"height",
")",
")",
"{",
"$",
"height",
"=",
"ceil",
"(",
"$",
"width",
"*",
"(",
"$",
"imageHeight",
"/",
"$",
"imageWidth",
")",
")",
";",
"if",
"(",
"$",
"height",
">",
"$",
"imageHeight",
")",
"{",
"$",
"height",
"=",
"$",
"imageHeight",
";",
"}",
"return",
"array",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"}",
"if",
"(",
"(",
"null",
"===",
"$",
"width",
")",
"&&",
"(",
"null",
"!=",
"$",
"height",
")",
")",
"{",
"$",
"width",
"=",
"ceil",
"(",
"$",
"height",
"*",
"(",
"$",
"imageWidth",
"/",
"$",
"imageHeight",
")",
")",
";",
"if",
"(",
"$",
"width",
">",
"$",
"imageWidth",
")",
"{",
"$",
"width",
"=",
"$",
"imageWidth",
";",
"}",
"return",
"array",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"}",
"return",
"$",
"size",
";",
"}"
] | Get box size.
@param array $imageSize
@param array $size
@return array | [
"Get",
"box",
"size",
"."
] | b7367601b01495ae3c492b42042f804dee13ab06 | https://github.com/Silvestra/Silvestra/blob/b7367601b01495ae3c492b42042f804dee13ab06/src/Silvestra/Component/Media/Image/Resizer/ImageResizerHelper.php#L29-L60 |
12,762 | Silvestra/Silvestra | src/Silvestra/Component/Media/Image/Resizer/ImageResizerHelper.php | ImageResizerHelper.getImageSizeInBox | public function getImageSizeInBox(array $imageSize, array $boxSize)
{
list($imageWidth, $imageHeight) = $imageSize;
list($boxWidth, $boxHeight) = $boxSize;
if (($imageWidth <= $boxWidth) && ($imageHeight <= $boxHeight)) {
return $imageSize;
}
$resizeRatio = min($boxWidth / $imageWidth, $boxHeight / $imageHeight);
$imageWidth = ceil($imageWidth * $resizeRatio);
if ($imageWidth > $boxWidth) {
$imageWidth = $boxWidth;
}
$imageHeight = ceil($imageHeight * $resizeRatio);
if ($imageHeight > $boxHeight) {
$imageHeight = $boxHeight;
}
return array($imageWidth, $imageHeight);
} | php | public function getImageSizeInBox(array $imageSize, array $boxSize)
{
list($imageWidth, $imageHeight) = $imageSize;
list($boxWidth, $boxHeight) = $boxSize;
if (($imageWidth <= $boxWidth) && ($imageHeight <= $boxHeight)) {
return $imageSize;
}
$resizeRatio = min($boxWidth / $imageWidth, $boxHeight / $imageHeight);
$imageWidth = ceil($imageWidth * $resizeRatio);
if ($imageWidth > $boxWidth) {
$imageWidth = $boxWidth;
}
$imageHeight = ceil($imageHeight * $resizeRatio);
if ($imageHeight > $boxHeight) {
$imageHeight = $boxHeight;
}
return array($imageWidth, $imageHeight);
} | [
"public",
"function",
"getImageSizeInBox",
"(",
"array",
"$",
"imageSize",
",",
"array",
"$",
"boxSize",
")",
"{",
"list",
"(",
"$",
"imageWidth",
",",
"$",
"imageHeight",
")",
"=",
"$",
"imageSize",
";",
"list",
"(",
"$",
"boxWidth",
",",
"$",
"boxHeight",
")",
"=",
"$",
"boxSize",
";",
"if",
"(",
"(",
"$",
"imageWidth",
"<=",
"$",
"boxWidth",
")",
"&&",
"(",
"$",
"imageHeight",
"<=",
"$",
"boxHeight",
")",
")",
"{",
"return",
"$",
"imageSize",
";",
"}",
"$",
"resizeRatio",
"=",
"min",
"(",
"$",
"boxWidth",
"/",
"$",
"imageWidth",
",",
"$",
"boxHeight",
"/",
"$",
"imageHeight",
")",
";",
"$",
"imageWidth",
"=",
"ceil",
"(",
"$",
"imageWidth",
"*",
"$",
"resizeRatio",
")",
";",
"if",
"(",
"$",
"imageWidth",
">",
"$",
"boxWidth",
")",
"{",
"$",
"imageWidth",
"=",
"$",
"boxWidth",
";",
"}",
"$",
"imageHeight",
"=",
"ceil",
"(",
"$",
"imageHeight",
"*",
"$",
"resizeRatio",
")",
";",
"if",
"(",
"$",
"imageHeight",
">",
"$",
"boxHeight",
")",
"{",
"$",
"imageHeight",
"=",
"$",
"boxHeight",
";",
"}",
"return",
"array",
"(",
"$",
"imageWidth",
",",
"$",
"imageHeight",
")",
";",
"}"
] | Get image size in box.
@param array $imageSize
@param array $boxSize
@return array | [
"Get",
"image",
"size",
"in",
"box",
"."
] | b7367601b01495ae3c492b42042f804dee13ab06 | https://github.com/Silvestra/Silvestra/blob/b7367601b01495ae3c492b42042f804dee13ab06/src/Silvestra/Component/Media/Image/Resizer/ImageResizerHelper.php#L70-L94 |
12,763 | skeeks-cms/cms-module-money | src/Money.php | Money.subtract | public function subtract(Money $other)
{
$other = $other->convertToCurrency($this->currency);
$this->assertSameCurrency($this, $other);
$value = $this->amount - $other->getAmount();
$this->assertIsFloat($value);
return $this->newMoney($value);
} | php | public function subtract(Money $other)
{
$other = $other->convertToCurrency($this->currency);
$this->assertSameCurrency($this, $other);
$value = $this->amount - $other->getAmount();
$this->assertIsFloat($value);
return $this->newMoney($value);
} | [
"public",
"function",
"subtract",
"(",
"Money",
"$",
"other",
")",
"{",
"$",
"other",
"=",
"$",
"other",
"->",
"convertToCurrency",
"(",
"$",
"this",
"->",
"currency",
")",
";",
"$",
"this",
"->",
"assertSameCurrency",
"(",
"$",
"this",
",",
"$",
"other",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"amount",
"-",
"$",
"other",
"->",
"getAmount",
"(",
")",
";",
"$",
"this",
"->",
"assertIsFloat",
"(",
"$",
"value",
")",
";",
"return",
"$",
"this",
"->",
"newMoney",
"(",
"$",
"value",
")",
";",
"}"
] | Returns a new Money object that represents the monetary value
of the difference of this Money object and another.
@param Money $other
@return Money
@throws CurrencyMismatchException
@throws OverflowException | [
"Returns",
"a",
"new",
"Money",
"object",
"that",
"represents",
"the",
"monetary",
"value",
"of",
"the",
"difference",
"of",
"this",
"Money",
"object",
"and",
"another",
"."
] | b2ce7a9d51014e4f5d340ddc69a0636d94f7618a | https://github.com/skeeks-cms/cms-module-money/blob/b2ce7a9d51014e4f5d340ddc69a0636d94f7618a/src/Money.php#L186-L196 |
12,764 | skeeks-cms/cms-module-money | src/Money.php | Money.multiply | public function multiply($factor, $roundingMode = PHP_ROUND_HALF_UP)
{
if (!in_array($roundingMode, self::$roundingModes)) {
throw new InvalidArgumentException(
'$roundingMode ' . \Yii::t('skeeks/money', 'must be a valid rounding mode') . ' (PHP_ROUND_*)'
);
}
return $this->newMoney(
$this->castToFloat(
round($factor * $this->amount, 0, $roundingMode)
)
);
} | php | public function multiply($factor, $roundingMode = PHP_ROUND_HALF_UP)
{
if (!in_array($roundingMode, self::$roundingModes)) {
throw new InvalidArgumentException(
'$roundingMode ' . \Yii::t('skeeks/money', 'must be a valid rounding mode') . ' (PHP_ROUND_*)'
);
}
return $this->newMoney(
$this->castToFloat(
round($factor * $this->amount, 0, $roundingMode)
)
);
} | [
"public",
"function",
"multiply",
"(",
"$",
"factor",
",",
"$",
"roundingMode",
"=",
"PHP_ROUND_HALF_UP",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"roundingMode",
",",
"self",
"::",
"$",
"roundingModes",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$roundingMode '",
".",
"\\",
"Yii",
"::",
"t",
"(",
"'skeeks/money'",
",",
"'must be a valid rounding mode'",
")",
".",
"' (PHP_ROUND_*)'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"newMoney",
"(",
"$",
"this",
"->",
"castToFloat",
"(",
"round",
"(",
"$",
"factor",
"*",
"$",
"this",
"->",
"amount",
",",
"0",
",",
"$",
"roundingMode",
")",
")",
")",
";",
"}"
] | Returns a new Money object that represents the monetary value
of this Money object multiplied by a given factor.
@param float $factor
@param integer $roundingMode
@return Money
@throws InvalidArgumentException | [
"Returns",
"a",
"new",
"Money",
"object",
"that",
"represents",
"the",
"monetary",
"value",
"of",
"this",
"Money",
"object",
"multiplied",
"by",
"a",
"given",
"factor",
"."
] | b2ce7a9d51014e4f5d340ddc69a0636d94f7618a | https://github.com/skeeks-cms/cms-module-money/blob/b2ce7a9d51014e4f5d340ddc69a0636d94f7618a/src/Money.php#L218-L231 |
12,765 | skeeks-cms/cms-module-money | src/Money.php | Money.allocateToTargets | public function allocateToTargets($n)
{
if (is_int($n)) {
$n = (float)$n;
}
if (!is_float($n)) {
throw new InvalidArgumentException('$n ' . \Yii::t('skeeks/money', 'must be an integer'));
}
$low = $this->newMoney(floatval($this->amount / $n));
$high = $this->newMoney($low->getAmount() + 1);
$remainder = $this->amount % $n;
$result = array();
for ($i = 0; $i < $remainder; $i++) {
$result[] = $high;
}
for ($i = $remainder; $i < $n; $i++) {
$result[] = $low;
}
return $result;
} | php | public function allocateToTargets($n)
{
if (is_int($n)) {
$n = (float)$n;
}
if (!is_float($n)) {
throw new InvalidArgumentException('$n ' . \Yii::t('skeeks/money', 'must be an integer'));
}
$low = $this->newMoney(floatval($this->amount / $n));
$high = $this->newMoney($low->getAmount() + 1);
$remainder = $this->amount % $n;
$result = array();
for ($i = 0; $i < $remainder; $i++) {
$result[] = $high;
}
for ($i = $remainder; $i < $n; $i++) {
$result[] = $low;
}
return $result;
} | [
"public",
"function",
"allocateToTargets",
"(",
"$",
"n",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"n",
")",
")",
"{",
"$",
"n",
"=",
"(",
"float",
")",
"$",
"n",
";",
"}",
"if",
"(",
"!",
"is_float",
"(",
"$",
"n",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$n '",
".",
"\\",
"Yii",
"::",
"t",
"(",
"'skeeks/money'",
",",
"'must be an integer'",
")",
")",
";",
"}",
"$",
"low",
"=",
"$",
"this",
"->",
"newMoney",
"(",
"floatval",
"(",
"$",
"this",
"->",
"amount",
"/",
"$",
"n",
")",
")",
";",
"$",
"high",
"=",
"$",
"this",
"->",
"newMoney",
"(",
"$",
"low",
"->",
"getAmount",
"(",
")",
"+",
"1",
")",
";",
"$",
"remainder",
"=",
"$",
"this",
"->",
"amount",
"%",
"$",
"n",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"remainder",
";",
"$",
"i",
"++",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"high",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"$",
"remainder",
";",
"$",
"i",
"<",
"$",
"n",
";",
"$",
"i",
"++",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"low",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Allocate the monetary value represented by this Money object
among N targets.
@param integer|float $n
@return Money[]
@throws InvalidArgumentException | [
"Allocate",
"the",
"monetary",
"value",
"represented",
"by",
"this",
"Money",
"object",
"among",
"N",
"targets",
"."
] | b2ce7a9d51014e4f5d340ddc69a0636d94f7618a | https://github.com/skeeks-cms/cms-module-money/blob/b2ce7a9d51014e4f5d340ddc69a0636d94f7618a/src/Money.php#L241-L265 |
12,766 | skeeks-cms/cms-module-money | src/Money.php | Money.allocateByRatios | public function allocateByRatios(array $ratios)
{
/** @var Money[] $result */
$result = array();
$total = array_sum($ratios);
$remainder = $this->amount;
for ($i = 0; $i < count($ratios); $i++) {
$amount = $this->castToFloat($this->amount * $ratios[$i] / $total);
$result[] = $this->newMoney($amount);
$remainder -= $amount;
}
for ($i = 0; $i < $remainder; $i++) {
$result[$i] = $this->newMoney($result[$i]->getAmount() + 1);
}
return $result;
} | php | public function allocateByRatios(array $ratios)
{
/** @var Money[] $result */
$result = array();
$total = array_sum($ratios);
$remainder = $this->amount;
for ($i = 0; $i < count($ratios); $i++) {
$amount = $this->castToFloat($this->amount * $ratios[$i] / $total);
$result[] = $this->newMoney($amount);
$remainder -= $amount;
}
for ($i = 0; $i < $remainder; $i++) {
$result[$i] = $this->newMoney($result[$i]->getAmount() + 1);
}
return $result;
} | [
"public",
"function",
"allocateByRatios",
"(",
"array",
"$",
"ratios",
")",
"{",
"/** @var Money[] $result */",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"total",
"=",
"array_sum",
"(",
"$",
"ratios",
")",
";",
"$",
"remainder",
"=",
"$",
"this",
"->",
"amount",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"ratios",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"amount",
"=",
"$",
"this",
"->",
"castToFloat",
"(",
"$",
"this",
"->",
"amount",
"*",
"$",
"ratios",
"[",
"$",
"i",
"]",
"/",
"$",
"total",
")",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"this",
"->",
"newMoney",
"(",
"$",
"amount",
")",
";",
"$",
"remainder",
"-=",
"$",
"amount",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"remainder",
";",
"$",
"i",
"++",
")",
"{",
"$",
"result",
"[",
"$",
"i",
"]",
"=",
"$",
"this",
"->",
"newMoney",
"(",
"$",
"result",
"[",
"$",
"i",
"]",
"->",
"getAmount",
"(",
")",
"+",
"1",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Allocate the monetary value represented by this Money object
using a list of ratios.
@param array $ratios
@return Money[] | [
"Allocate",
"the",
"monetary",
"value",
"represented",
"by",
"this",
"Money",
"object",
"using",
"a",
"list",
"of",
"ratios",
"."
] | b2ce7a9d51014e4f5d340ddc69a0636d94f7618a | https://github.com/skeeks-cms/cms-module-money/blob/b2ce7a9d51014e4f5d340ddc69a0636d94f7618a/src/Money.php#L274-L292 |
12,767 | skeeks-cms/cms-module-money | src/Money.php | Money.compareTo | public function compareTo(Money $other)
{
$other = $other->convertToCurrency($this->currency);
$this->assertSameCurrency($this, $other);
if ($this->amount == $other->getAmount()) {
return 0;
}
return $this->amount < $other->getAmount() ? -1 : 1;
} | php | public function compareTo(Money $other)
{
$other = $other->convertToCurrency($this->currency);
$this->assertSameCurrency($this, $other);
if ($this->amount == $other->getAmount()) {
return 0;
}
return $this->amount < $other->getAmount() ? -1 : 1;
} | [
"public",
"function",
"compareTo",
"(",
"Money",
"$",
"other",
")",
"{",
"$",
"other",
"=",
"$",
"other",
"->",
"convertToCurrency",
"(",
"$",
"this",
"->",
"currency",
")",
";",
"$",
"this",
"->",
"assertSameCurrency",
"(",
"$",
"this",
",",
"$",
"other",
")",
";",
"if",
"(",
"$",
"this",
"->",
"amount",
"==",
"$",
"other",
"->",
"getAmount",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"this",
"->",
"amount",
"<",
"$",
"other",
"->",
"getAmount",
"(",
")",
"?",
"-",
"1",
":",
"1",
";",
"}"
] | Compares this Money object to another.
Returns an integer less than, equal to, or greater than zero
if the value of this Money object is considered to be respectively
less than, equal to, or greater than the other Money object.
@param Money $other
@return integer -1|0|1
@throws CurrencyMismatchException | [
"Compares",
"this",
"Money",
"object",
"to",
"another",
"."
] | b2ce7a9d51014e4f5d340ddc69a0636d94f7618a | https://github.com/skeeks-cms/cms-module-money/blob/b2ce7a9d51014e4f5d340ddc69a0636d94f7618a/src/Money.php#L332-L342 |
12,768 | rseyferth/activerecord | lib/Validation/Validators.php | Validator.validate | public function validate($field, $model)
{
return $this->_validate($this->getValue($model, $field), $field, $model);
} | php | public function validate($field, $model)
{
return $this->_validate($this->getValue($model, $field), $field, $model);
} | [
"public",
"function",
"validate",
"(",
"$",
"field",
",",
"$",
"model",
")",
"{",
"return",
"$",
"this",
"->",
"_validate",
"(",
"$",
"this",
"->",
"getValue",
"(",
"$",
"model",
",",
"$",
"field",
")",
",",
"$",
"field",
",",
"$",
"model",
")",
";",
"}"
] | Validate given field and model against this Validator
@param string The fieldname to look for in the model
@param array|Model An associative array or a ActiveRecord Model instance
@return string|true When validation succeeds true, otherwise the error-key for the validation error. | [
"Validate",
"given",
"field",
"and",
"model",
"against",
"this",
"Validator"
] | 0e7b1cbddd6f967c3a09adf38753babd5f698e39 | https://github.com/rseyferth/activerecord/blob/0e7b1cbddd6f967c3a09adf38753babd5f698e39/lib/Validation/Validators.php#L24-L29 |
12,769 | veridu/idos-sdk-php | src/idOS/Section/AbstractSection.php | AbstractSection.getEndpointClassName | protected function getEndpointClassName(string $name) : string {
$className = sprintf(
'%s\\%s',
str_replace('Section', 'Endpoint', get_class($this)),
ucfirst($name)
);
if (! class_exists($className)) {
throw new \RuntimeException(
sprintf(
'Invalid endpoint name "%s" (%s)',
$name,
$className
)
);
}
return $className;
} | php | protected function getEndpointClassName(string $name) : string {
$className = sprintf(
'%s\\%s',
str_replace('Section', 'Endpoint', get_class($this)),
ucfirst($name)
);
if (! class_exists($className)) {
throw new \RuntimeException(
sprintf(
'Invalid endpoint name "%s" (%s)',
$name,
$className
)
);
}
return $className;
} | [
"protected",
"function",
"getEndpointClassName",
"(",
"string",
"$",
"name",
")",
":",
"string",
"{",
"$",
"className",
"=",
"sprintf",
"(",
"'%s\\\\%s'",
",",
"str_replace",
"(",
"'Section'",
",",
"'Endpoint'",
",",
"get_class",
"(",
"$",
"this",
")",
")",
",",
"ucfirst",
"(",
"$",
"name",
")",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Invalid endpoint name \"%s\" (%s)'",
",",
"$",
"name",
",",
"$",
"className",
")",
")",
";",
"}",
"return",
"$",
"className",
";",
"}"
] | Return the Endpoint Class Name.
@param string $name
@return string $className | [
"Return",
"the",
"Endpoint",
"Class",
"Name",
"."
] | e56757bed10404756f2f0485a4b7f55794192008 | https://github.com/veridu/idos-sdk-php/blob/e56757bed10404756f2f0485a4b7f55794192008/src/idOS/Section/AbstractSection.php#L44-L62 |
12,770 | veridu/idos-sdk-php | src/idOS/Section/AbstractSection.php | AbstractSection.createEndpoint | protected function createEndpoint(string $name, array $args) : EndpointInterface {
$className = $this->getEndpointClassName($name);
// aditional parameters
$args[] = $this->authentication;
$args[] = $this->client;
$args[] = $this->throwsExceptions;
$args[] = $this->baseUrl;
return new $className(...$args);
} | php | protected function createEndpoint(string $name, array $args) : EndpointInterface {
$className = $this->getEndpointClassName($name);
// aditional parameters
$args[] = $this->authentication;
$args[] = $this->client;
$args[] = $this->throwsExceptions;
$args[] = $this->baseUrl;
return new $className(...$args);
} | [
"protected",
"function",
"createEndpoint",
"(",
"string",
"$",
"name",
",",
"array",
"$",
"args",
")",
":",
"EndpointInterface",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"getEndpointClassName",
"(",
"$",
"name",
")",
";",
"// aditional parameters",
"$",
"args",
"[",
"]",
"=",
"$",
"this",
"->",
"authentication",
";",
"$",
"args",
"[",
"]",
"=",
"$",
"this",
"->",
"client",
";",
"$",
"args",
"[",
"]",
"=",
"$",
"this",
"->",
"throwsExceptions",
";",
"$",
"args",
"[",
"]",
"=",
"$",
"this",
"->",
"baseUrl",
";",
"return",
"new",
"$",
"className",
"(",
"...",
"$",
"args",
")",
";",
"}"
] | Return an endpoint instance properly initialized.
@param string $name
@param array $args
@return \idOS\Endpoint\EndpointInterface | [
"Return",
"an",
"endpoint",
"instance",
"properly",
"initialized",
"."
] | e56757bed10404756f2f0485a4b7f55794192008 | https://github.com/veridu/idos-sdk-php/blob/e56757bed10404756f2f0485a4b7f55794192008/src/idOS/Section/AbstractSection.php#L72-L82 |
12,771 | veridu/idos-sdk-php | src/idOS/Section/AbstractSection.php | AbstractSection.getSectionClassName | protected function getSectionClassName(string $name) : string {
$className = sprintf(
'%s\\%s',
get_class($this),
ucfirst($name)
);
if (! class_exists($className)) {
throw new \RuntimeException(
sprintf(
'Invalid section name "%s" (%s)',
$name,
$className
)
);
}
return $className;
} | php | protected function getSectionClassName(string $name) : string {
$className = sprintf(
'%s\\%s',
get_class($this),
ucfirst($name)
);
if (! class_exists($className)) {
throw new \RuntimeException(
sprintf(
'Invalid section name "%s" (%s)',
$name,
$className
)
);
}
return $className;
} | [
"protected",
"function",
"getSectionClassName",
"(",
"string",
"$",
"name",
")",
":",
"string",
"{",
"$",
"className",
"=",
"sprintf",
"(",
"'%s\\\\%s'",
",",
"get_class",
"(",
"$",
"this",
")",
",",
"ucfirst",
"(",
"$",
"name",
")",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Invalid section name \"%s\" (%s)'",
",",
"$",
"name",
",",
"$",
"className",
")",
")",
";",
"}",
"return",
"$",
"className",
";",
"}"
] | Returns the Section Class Name.
@param string $name
@return string $className | [
"Returns",
"the",
"Section",
"Class",
"Name",
"."
] | e56757bed10404756f2f0485a4b7f55794192008 | https://github.com/veridu/idos-sdk-php/blob/e56757bed10404756f2f0485a4b7f55794192008/src/idOS/Section/AbstractSection.php#L91-L109 |
12,772 | veridu/idos-sdk-php | src/idOS/Section/AbstractSection.php | AbstractSection.createSection | protected function createSection(string $name, array $args) : SectionInterface {
$className = $this->getSectionClassName($name);
// aditional parameters
$args[] = $this->authentication;
$args[] = $this->client;
$args[] = $this->throwsExceptions;
$args[] = $this->baseUrl;
return new $className(...$args);
} | php | protected function createSection(string $name, array $args) : SectionInterface {
$className = $this->getSectionClassName($name);
// aditional parameters
$args[] = $this->authentication;
$args[] = $this->client;
$args[] = $this->throwsExceptions;
$args[] = $this->baseUrl;
return new $className(...$args);
} | [
"protected",
"function",
"createSection",
"(",
"string",
"$",
"name",
",",
"array",
"$",
"args",
")",
":",
"SectionInterface",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"getSectionClassName",
"(",
"$",
"name",
")",
";",
"// aditional parameters",
"$",
"args",
"[",
"]",
"=",
"$",
"this",
"->",
"authentication",
";",
"$",
"args",
"[",
"]",
"=",
"$",
"this",
"->",
"client",
";",
"$",
"args",
"[",
"]",
"=",
"$",
"this",
"->",
"throwsExceptions",
";",
"$",
"args",
"[",
"]",
"=",
"$",
"this",
"->",
"baseUrl",
";",
"return",
"new",
"$",
"className",
"(",
"...",
"$",
"args",
")",
";",
"}"
] | Return a section instance properly initialized.
@param string $name
@param array $args
@return \idOS\Section\SectionInterface | [
"Return",
"a",
"section",
"instance",
"properly",
"initialized",
"."
] | e56757bed10404756f2f0485a4b7f55794192008 | https://github.com/veridu/idos-sdk-php/blob/e56757bed10404756f2f0485a4b7f55794192008/src/idOS/Section/AbstractSection.php#L119-L129 |
12,773 | dmeikle/pesedget | src/Gossamer/Pesedget/Utils/ConfigManager.php | ConfigManager.getConfiguration | public function getConfiguration($filename) {
$cacheManager = new CacheManager();
$configuration = $cacheManager->retrieveFromCache('/' . $filename);
if (!is_array($configuration)) {
return null;
}
$config = new Config($configuration);
$cacheManager = null;
return $config;
} | php | public function getConfiguration($filename) {
$cacheManager = new CacheManager();
$configuration = $cacheManager->retrieveFromCache('/' . $filename);
if (!is_array($configuration)) {
return null;
}
$config = new Config($configuration);
$cacheManager = null;
return $config;
} | [
"public",
"function",
"getConfiguration",
"(",
"$",
"filename",
")",
"{",
"$",
"cacheManager",
"=",
"new",
"CacheManager",
"(",
")",
";",
"$",
"configuration",
"=",
"$",
"cacheManager",
"->",
"retrieveFromCache",
"(",
"'/'",
".",
"$",
"filename",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"configuration",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"config",
"=",
"new",
"Config",
"(",
"$",
"configuration",
")",
";",
"$",
"cacheManager",
"=",
"null",
";",
"return",
"$",
"config",
";",
"}"
] | getConfiguration - loads the configuration
@param string filename
@param Config loaded config | [
"getConfiguration",
"-",
"loads",
"the",
"configuration"
] | bcfca25569d1f47c073f08906a710ed895f77b4d | https://github.com/dmeikle/pesedget/blob/bcfca25569d1f47c073f08906a710ed895f77b4d/src/Gossamer/Pesedget/Utils/ConfigManager.php#L57-L68 |
12,774 | dmeikle/pesedget | src/Gossamer/Pesedget/Utils/ConfigManager.php | ConfigManager.saveConfiguration | public function saveConfiguration($filename, Config $config) {
$this->workingPath = $this->parseFilepath($filename);
$cacheManager = new CacheManager();
$cacheManager->saveToCache('/' . $filename, $config->toDetailsArray());
} | php | public function saveConfiguration($filename, Config $config) {
$this->workingPath = $this->parseFilepath($filename);
$cacheManager = new CacheManager();
$cacheManager->saveToCache('/' . $filename, $config->toDetailsArray());
} | [
"public",
"function",
"saveConfiguration",
"(",
"$",
"filename",
",",
"Config",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"workingPath",
"=",
"$",
"this",
"->",
"parseFilepath",
"(",
"$",
"filename",
")",
";",
"$",
"cacheManager",
"=",
"new",
"CacheManager",
"(",
")",
";",
"$",
"cacheManager",
"->",
"saveToCache",
"(",
"'/'",
".",
"$",
"filename",
",",
"$",
"config",
"->",
"toDetailsArray",
"(",
")",
")",
";",
"}"
] | saveConfiguration - serializes a configuration
@param string filename
@param Config config | [
"saveConfiguration",
"-",
"serializes",
"a",
"configuration"
] | bcfca25569d1f47c073f08906a710ed895f77b4d | https://github.com/dmeikle/pesedget/blob/bcfca25569d1f47c073f08906a710ed895f77b4d/src/Gossamer/Pesedget/Utils/ConfigManager.php#L76-L81 |
12,775 | gubler/collection | src/Arr.php | Arr.random | public static function random($array, $number = null)
{
$requested = \is_null($number) ? 1 : $number;
$count = \count($array);
if ($requested > $count) {
throw new InvalidArgumentException(
"You requested {$requested} items, but there are only {$count} items available."
);
}
if (\is_null($number)) {
return $array[array_rand($array)];
}
if ((int) $number === 0) {
return [];
}
$keys = array_rand($array, $number);
$results = [];
foreach ((array) $keys as $key) {
$results[] = $array[$key];
}
return $results;
} | php | public static function random($array, $number = null)
{
$requested = \is_null($number) ? 1 : $number;
$count = \count($array);
if ($requested > $count) {
throw new InvalidArgumentException(
"You requested {$requested} items, but there are only {$count} items available."
);
}
if (\is_null($number)) {
return $array[array_rand($array)];
}
if ((int) $number === 0) {
return [];
}
$keys = array_rand($array, $number);
$results = [];
foreach ((array) $keys as $key) {
$results[] = $array[$key];
}
return $results;
} | [
"public",
"static",
"function",
"random",
"(",
"$",
"array",
",",
"$",
"number",
"=",
"null",
")",
"{",
"$",
"requested",
"=",
"\\",
"is_null",
"(",
"$",
"number",
")",
"?",
"1",
":",
"$",
"number",
";",
"$",
"count",
"=",
"\\",
"count",
"(",
"$",
"array",
")",
";",
"if",
"(",
"$",
"requested",
">",
"$",
"count",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"You requested {$requested} items, but there are only {$count} items available.\"",
")",
";",
"}",
"if",
"(",
"\\",
"is_null",
"(",
"$",
"number",
")",
")",
"{",
"return",
"$",
"array",
"[",
"array_rand",
"(",
"$",
"array",
")",
"]",
";",
"}",
"if",
"(",
"(",
"int",
")",
"$",
"number",
"===",
"0",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"keys",
"=",
"array_rand",
"(",
"$",
"array",
",",
"$",
"number",
")",
";",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"$",
"array",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"results",
";",
"}"
] | Get one or a specified number of random values from an array.
@param array $array
@param int|null $number
@return mixed
@throws \InvalidArgumentException | [
"Get",
"one",
"or",
"a",
"specified",
"number",
"of",
"random",
"values",
"from",
"an",
"array",
"."
] | 8af2e0478f78b0fe0fbac7437f3f94f01de307b8 | https://github.com/gubler/collection/blob/8af2e0478f78b0fe0fbac7437f3f94f01de307b8/src/Arr.php#L473-L502 |
12,776 | spiral/validation | src/Checker/Traits/NotEmptyTrait.php | NotEmptyTrait.notEmpty | public function notEmpty($value, bool $asString = true): bool
{
if ($asString && is_string($value) && strlen(trim($value)) == 0) {
return false;
}
return !empty($value);
} | php | public function notEmpty($value, bool $asString = true): bool
{
if ($asString && is_string($value) && strlen(trim($value)) == 0) {
return false;
}
return !empty($value);
} | [
"public",
"function",
"notEmpty",
"(",
"$",
"value",
",",
"bool",
"$",
"asString",
"=",
"true",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"asString",
"&&",
"is_string",
"(",
"$",
"value",
")",
"&&",
"strlen",
"(",
"trim",
"(",
"$",
"value",
")",
")",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"value",
")",
";",
"}"
] | Value should not be empty.
@param mixed $value
@param bool $asString Cut spaces and make sure it's not empty when value is string.
@return bool | [
"Value",
"should",
"not",
"be",
"empty",
"."
] | aa8977dfe93904acfcce354e000d7d384579e2e3 | https://github.com/spiral/validation/blob/aa8977dfe93904acfcce354e000d7d384579e2e3/src/Checker/Traits/NotEmptyTrait.php#L25-L32 |
12,777 | rafflesargentina/l5-resource-controller | src/Traits/WorksWithFileUploads.php | WorksWithFileUploads.uploadFiles | public function uploadFiles(Request $request, Model $model, $relativePath = null)
{
if (!$relativePath) {
$relativePath = $this->getDefaultRelativePath();
}
$fileBag = $request->files;
foreach ($fileBag->all() as $paramName => $uploadedFiles) {
$attributes = $model->getAttributes();
if (array_key_exists($paramName, $attributes)) {
$this->handleNonMultipleFileUploads($model, $paramName, $uploadedFiles, $relativePath);
} else {
$this->handleMultipleFileUploads($request, $model, $paramName, $uploadedFiles, $relativePath);
}
}
return $request;
} | php | public function uploadFiles(Request $request, Model $model, $relativePath = null)
{
if (!$relativePath) {
$relativePath = $this->getDefaultRelativePath();
}
$fileBag = $request->files;
foreach ($fileBag->all() as $paramName => $uploadedFiles) {
$attributes = $model->getAttributes();
if (array_key_exists($paramName, $attributes)) {
$this->handleNonMultipleFileUploads($model, $paramName, $uploadedFiles, $relativePath);
} else {
$this->handleMultipleFileUploads($request, $model, $paramName, $uploadedFiles, $relativePath);
}
}
return $request;
} | [
"public",
"function",
"uploadFiles",
"(",
"Request",
"$",
"request",
",",
"Model",
"$",
"model",
",",
"$",
"relativePath",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"relativePath",
")",
"{",
"$",
"relativePath",
"=",
"$",
"this",
"->",
"getDefaultRelativePath",
"(",
")",
";",
"}",
"$",
"fileBag",
"=",
"$",
"request",
"->",
"files",
";",
"foreach",
"(",
"$",
"fileBag",
"->",
"all",
"(",
")",
"as",
"$",
"paramName",
"=>",
"$",
"uploadedFiles",
")",
"{",
"$",
"attributes",
"=",
"$",
"model",
"->",
"getAttributes",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"paramName",
",",
"$",
"attributes",
")",
")",
"{",
"$",
"this",
"->",
"handleNonMultipleFileUploads",
"(",
"$",
"model",
",",
"$",
"paramName",
",",
"$",
"uploadedFiles",
",",
"$",
"relativePath",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"handleMultipleFileUploads",
"(",
"$",
"request",
",",
"$",
"model",
",",
"$",
"paramName",
",",
"$",
"uploadedFiles",
",",
"$",
"relativePath",
")",
";",
"}",
"}",
"return",
"$",
"request",
";",
"}"
] | Upload request files and update or create relations handling array type request data.
@param Request $request The Request object.
@param Model $model The eloquent model.
@param string|null $relativePath The file uploads relative path.
@return Request | [
"Upload",
"request",
"files",
"and",
"update",
"or",
"create",
"relations",
"handling",
"array",
"type",
"request",
"data",
"."
] | 5ee5de4803a26d0592dd6f5db77aec40c1a56c09 | https://github.com/rafflesargentina/l5-resource-controller/blob/5ee5de4803a26d0592dd6f5db77aec40c1a56c09/src/Traits/WorksWithFileUploads.php#L26-L43 |
12,778 | rafflesargentina/l5-resource-controller | src/Traits/WorksWithFileUploads.php | WorksWithFileUploads.getFilename | protected function getFilename(UploadedFile $uploadedFile)
{
$extension = $uploadedFile->guessExtension();
$filename = str_random().'.'.$extension;
return $filename;
} | php | protected function getFilename(UploadedFile $uploadedFile)
{
$extension = $uploadedFile->guessExtension();
$filename = str_random().'.'.$extension;
return $filename;
} | [
"protected",
"function",
"getFilename",
"(",
"UploadedFile",
"$",
"uploadedFile",
")",
"{",
"$",
"extension",
"=",
"$",
"uploadedFile",
"->",
"guessExtension",
"(",
")",
";",
"$",
"filename",
"=",
"str_random",
"(",
")",
".",
"'.'",
".",
"$",
"extension",
";",
"return",
"$",
"filename",
";",
"}"
] | Get the name of the file.
@param UploadedFile $uploadedFile The UploadedFile object.
@return string | [
"Get",
"the",
"name",
"of",
"the",
"file",
"."
] | 5ee5de4803a26d0592dd6f5db77aec40c1a56c09 | https://github.com/rafflesargentina/l5-resource-controller/blob/5ee5de4803a26d0592dd6f5db77aec40c1a56c09/src/Traits/WorksWithFileUploads.php#L52-L58 |
12,779 | rafflesargentina/l5-resource-controller | src/Traits/WorksWithFileUploads.php | WorksWithFileUploads.handleMultipleFileUploads | protected function handleMultipleFileUploads(Request $request, Model $model, $paramName, $uploadedFiles, $relativePath)
{
$this->_checkFileRelationExists($model, $paramName);
$data = $request->attributes->all();
$fileBag = $request->files;
foreach ($uploadedFiles as $index => $uploadedFile) {
if (!$uploadedFile->isValid()) {
throw new UploadException($uploadedFile->getError());
}
$filename = $this->getFilename($uploadedFile);
$storagePath = $this->getStoragePath($relativePath);
$this->moveUploadedFile($uploadedFile, $filename, $storagePath);
$location = $relativePath.$filename;
if (count($fileBag->get($paramName)) > 1) {
$data[$paramName][$index] = [$this->getLocationColumn() => $location];
} else {
$data[$paramName][$this->getLocationColumn()] = $location;
}
$request->merge($data);
}
} | php | protected function handleMultipleFileUploads(Request $request, Model $model, $paramName, $uploadedFiles, $relativePath)
{
$this->_checkFileRelationExists($model, $paramName);
$data = $request->attributes->all();
$fileBag = $request->files;
foreach ($uploadedFiles as $index => $uploadedFile) {
if (!$uploadedFile->isValid()) {
throw new UploadException($uploadedFile->getError());
}
$filename = $this->getFilename($uploadedFile);
$storagePath = $this->getStoragePath($relativePath);
$this->moveUploadedFile($uploadedFile, $filename, $storagePath);
$location = $relativePath.$filename;
if (count($fileBag->get($paramName)) > 1) {
$data[$paramName][$index] = [$this->getLocationColumn() => $location];
} else {
$data[$paramName][$this->getLocationColumn()] = $location;
}
$request->merge($data);
}
} | [
"protected",
"function",
"handleMultipleFileUploads",
"(",
"Request",
"$",
"request",
",",
"Model",
"$",
"model",
",",
"$",
"paramName",
",",
"$",
"uploadedFiles",
",",
"$",
"relativePath",
")",
"{",
"$",
"this",
"->",
"_checkFileRelationExists",
"(",
"$",
"model",
",",
"$",
"paramName",
")",
";",
"$",
"data",
"=",
"$",
"request",
"->",
"attributes",
"->",
"all",
"(",
")",
";",
"$",
"fileBag",
"=",
"$",
"request",
"->",
"files",
";",
"foreach",
"(",
"$",
"uploadedFiles",
"as",
"$",
"index",
"=>",
"$",
"uploadedFile",
")",
"{",
"if",
"(",
"!",
"$",
"uploadedFile",
"->",
"isValid",
"(",
")",
")",
"{",
"throw",
"new",
"UploadException",
"(",
"$",
"uploadedFile",
"->",
"getError",
"(",
")",
")",
";",
"}",
"$",
"filename",
"=",
"$",
"this",
"->",
"getFilename",
"(",
"$",
"uploadedFile",
")",
";",
"$",
"storagePath",
"=",
"$",
"this",
"->",
"getStoragePath",
"(",
"$",
"relativePath",
")",
";",
"$",
"this",
"->",
"moveUploadedFile",
"(",
"$",
"uploadedFile",
",",
"$",
"filename",
",",
"$",
"storagePath",
")",
";",
"$",
"location",
"=",
"$",
"relativePath",
".",
"$",
"filename",
";",
"if",
"(",
"count",
"(",
"$",
"fileBag",
"->",
"get",
"(",
"$",
"paramName",
")",
")",
">",
"1",
")",
"{",
"$",
"data",
"[",
"$",
"paramName",
"]",
"[",
"$",
"index",
"]",
"=",
"[",
"$",
"this",
"->",
"getLocationColumn",
"(",
")",
"=>",
"$",
"location",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"paramName",
"]",
"[",
"$",
"this",
"->",
"getLocationColumn",
"(",
")",
"]",
"=",
"$",
"location",
";",
"}",
"$",
"request",
"->",
"merge",
"(",
"$",
"data",
")",
";",
"}",
"}"
] | Handle multiple file uploads.
@param Request $request The Request object.
@param Model $model The eloquent model.
@param string $paramName The name of the file param.
@param array $uploadedFiles An array of UploadedFile objects.
@param string $relativePath The file uploads relative path.
@return void | [
"Handle",
"multiple",
"file",
"uploads",
"."
] | 5ee5de4803a26d0592dd6f5db77aec40c1a56c09 | https://github.com/rafflesargentina/l5-resource-controller/blob/5ee5de4803a26d0592dd6f5db77aec40c1a56c09/src/Traits/WorksWithFileUploads.php#L117-L142 |
12,780 | rafflesargentina/l5-resource-controller | src/Traits/WorksWithFileUploads.php | WorksWithFileUploads.handleNonMultipleFileUploads | protected function handleNonMultipleFileUploads(Model $model, $paramName, $uploadedFile, $relativePath)
{
if (!$uploadedFile->isValid()) {
throw new UploadException($uploadedFile->getError());
}
$filename = $this->getFilename($uploadedFile);
$destination = $this->getStoragePath($relativePath);
$this->moveUploadedFile($uploadedFile, $filename, $destination);
$location = $relativePath.$filename;
$model->{$paramName} = $location;
$model->save();
} | php | protected function handleNonMultipleFileUploads(Model $model, $paramName, $uploadedFile, $relativePath)
{
if (!$uploadedFile->isValid()) {
throw new UploadException($uploadedFile->getError());
}
$filename = $this->getFilename($uploadedFile);
$destination = $this->getStoragePath($relativePath);
$this->moveUploadedFile($uploadedFile, $filename, $destination);
$location = $relativePath.$filename;
$model->{$paramName} = $location;
$model->save();
} | [
"protected",
"function",
"handleNonMultipleFileUploads",
"(",
"Model",
"$",
"model",
",",
"$",
"paramName",
",",
"$",
"uploadedFile",
",",
"$",
"relativePath",
")",
"{",
"if",
"(",
"!",
"$",
"uploadedFile",
"->",
"isValid",
"(",
")",
")",
"{",
"throw",
"new",
"UploadException",
"(",
"$",
"uploadedFile",
"->",
"getError",
"(",
")",
")",
";",
"}",
"$",
"filename",
"=",
"$",
"this",
"->",
"getFilename",
"(",
"$",
"uploadedFile",
")",
";",
"$",
"destination",
"=",
"$",
"this",
"->",
"getStoragePath",
"(",
"$",
"relativePath",
")",
";",
"$",
"this",
"->",
"moveUploadedFile",
"(",
"$",
"uploadedFile",
",",
"$",
"filename",
",",
"$",
"destination",
")",
";",
"$",
"location",
"=",
"$",
"relativePath",
".",
"$",
"filename",
";",
"$",
"model",
"->",
"{",
"$",
"paramName",
"}",
"=",
"$",
"location",
";",
"$",
"model",
"->",
"save",
"(",
")",
";",
"}"
] | Handle non-multiple file uploads.
@param Model $model The eloquent model.
@param string $paramName The name of the file param.
@param UploadedFile $uploadedFile The UploadedFile object.
@param string $relativePath The file uploads relative path.
@return void | [
"Handle",
"non",
"-",
"multiple",
"file",
"uploads",
"."
] | 5ee5de4803a26d0592dd6f5db77aec40c1a56c09 | https://github.com/rafflesargentina/l5-resource-controller/blob/5ee5de4803a26d0592dd6f5db77aec40c1a56c09/src/Traits/WorksWithFileUploads.php#L154-L168 |
12,781 | rafflesargentina/l5-resource-controller | src/Traits/WorksWithFileUploads.php | WorksWithFileUploads._checkFileRelationExists | private function _checkFileRelationExists(Model $model, $relationName)
{
if ((!method_exists($model, $relationName) && !$model->{$relationName}() instanceof Relation)) {
if (Lang::has('resource-controller.filerelationinexistent')) {
$message = trans('resource-controller.filerelationinexistent', ['relationName' => $relationName]);
} else {
$message = "Request file '{$relationName}' is not named after an existent relation.";
}
throw new UploadException($message);
}
} | php | private function _checkFileRelationExists(Model $model, $relationName)
{
if ((!method_exists($model, $relationName) && !$model->{$relationName}() instanceof Relation)) {
if (Lang::has('resource-controller.filerelationinexistent')) {
$message = trans('resource-controller.filerelationinexistent', ['relationName' => $relationName]);
} else {
$message = "Request file '{$relationName}' is not named after an existent relation.";
}
throw new UploadException($message);
}
} | [
"private",
"function",
"_checkFileRelationExists",
"(",
"Model",
"$",
"model",
",",
"$",
"relationName",
")",
"{",
"if",
"(",
"(",
"!",
"method_exists",
"(",
"$",
"model",
",",
"$",
"relationName",
")",
"&&",
"!",
"$",
"model",
"->",
"{",
"$",
"relationName",
"}",
"(",
")",
"instanceof",
"Relation",
")",
")",
"{",
"if",
"(",
"Lang",
"::",
"has",
"(",
"'resource-controller.filerelationinexistent'",
")",
")",
"{",
"$",
"message",
"=",
"trans",
"(",
"'resource-controller.filerelationinexistent'",
",",
"[",
"'relationName'",
"=>",
"$",
"relationName",
"]",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"\"Request file '{$relationName}' is not named after an existent relation.\"",
";",
"}",
"throw",
"new",
"UploadException",
"(",
"$",
"message",
")",
";",
"}",
"}"
] | Throw an exception if request file is not named after an existent relation.
@param Model $model The eloquent model.
@param string $relationName The eloquent relation name.
@throws UploadException
@return void | [
"Throw",
"an",
"exception",
"if",
"request",
"file",
"is",
"not",
"named",
"after",
"an",
"existent",
"relation",
"."
] | 5ee5de4803a26d0592dd6f5db77aec40c1a56c09 | https://github.com/rafflesargentina/l5-resource-controller/blob/5ee5de4803a26d0592dd6f5db77aec40c1a56c09/src/Traits/WorksWithFileUploads.php#L180-L190 |
12,782 | droid-php/droid-mysql | src/Model/MasterInfo.php | MasterInfo.execute | public function execute()
{
if (!is_string($this->master_hostname)
|| empty($this->master_hostname)
) {
throw new UnexpectedValueException(
'Cannot execute CHANGE MASTER without a valid master hostname.'
);
}
if (!is_string($this->replication_username)
|| empty($this->replication_username)
) {
throw new UnexpectedValueException(
'Cannot execute CHANGE MASTER without a valid replication username.'
);
}
if (!is_string($this->replication_password)
|| empty($this->replication_password)
) {
throw new UnexpectedValueException(
'Cannot execute CHANGE MASTER without a valid replication password.'
);
}
if (!is_string($this->recorded_log_file_name)) {
throw new UnexpectedValueException(
'Cannot execute CHANGE MASTER without a valid log file name (empty is acceptable).'
);
}
if (!is_int($this->recorded_log_pos)) {
throw new UnexpectedValueException(
'Cannot execute CHANGE MASTER without a valid log file position.'
);
}
if ($this->recorded_log_file_name == self::EMPTY_LOG_FILENAME
&& $this->recorded_log_pos != self::EMPTY_LOG_POSITION
) {
throw new UnexpectedValueException(
sprintf(
'The value of the log position must be equal to %d when the log file name is given as "%s".',
self::EMPTY_LOG_POSITION,
self::EMPTY_LOG_FILENAME
)
);
}
if ($this->recorded_log_file_name != self::EMPTY_LOG_FILENAME
&& $this->recorded_log_pos <= self::EMPTY_LOG_POSITION
) {
throw new UnexpectedValueException(
sprintf(
'The value of the log position must be greater than %d when the log file name is given something other than "%s".',
self::EMPTY_LOG_POSITION,
self::EMPTY_LOG_FILENAME
)
);
}
$statement = implode(
', ',
array(
'CHANGE MASTER TO MASTER_HOST=:master_hostname',
'MASTER_USER=:replication_username',
'MASTER_PASSWORD=:replication_password',
'MASTER_LOG_FILE=:recorded_log_file_name',
'MASTER_LOG_POS=:recorded_log_pos',
)
) . ';';
$params = array(
':master_hostname' => $this->master_hostname,
':replication_username' => $this->replication_username,
':replication_password' => $this->replication_password,
':recorded_log_file_name' => $this->recorded_log_file_name,
':recorded_log_pos' => array(
$this->recorded_log_pos, $this->client->typeInt()
),
);
return $this->client->execute($statement, $params);
} | php | public function execute()
{
if (!is_string($this->master_hostname)
|| empty($this->master_hostname)
) {
throw new UnexpectedValueException(
'Cannot execute CHANGE MASTER without a valid master hostname.'
);
}
if (!is_string($this->replication_username)
|| empty($this->replication_username)
) {
throw new UnexpectedValueException(
'Cannot execute CHANGE MASTER without a valid replication username.'
);
}
if (!is_string($this->replication_password)
|| empty($this->replication_password)
) {
throw new UnexpectedValueException(
'Cannot execute CHANGE MASTER without a valid replication password.'
);
}
if (!is_string($this->recorded_log_file_name)) {
throw new UnexpectedValueException(
'Cannot execute CHANGE MASTER without a valid log file name (empty is acceptable).'
);
}
if (!is_int($this->recorded_log_pos)) {
throw new UnexpectedValueException(
'Cannot execute CHANGE MASTER without a valid log file position.'
);
}
if ($this->recorded_log_file_name == self::EMPTY_LOG_FILENAME
&& $this->recorded_log_pos != self::EMPTY_LOG_POSITION
) {
throw new UnexpectedValueException(
sprintf(
'The value of the log position must be equal to %d when the log file name is given as "%s".',
self::EMPTY_LOG_POSITION,
self::EMPTY_LOG_FILENAME
)
);
}
if ($this->recorded_log_file_name != self::EMPTY_LOG_FILENAME
&& $this->recorded_log_pos <= self::EMPTY_LOG_POSITION
) {
throw new UnexpectedValueException(
sprintf(
'The value of the log position must be greater than %d when the log file name is given something other than "%s".',
self::EMPTY_LOG_POSITION,
self::EMPTY_LOG_FILENAME
)
);
}
$statement = implode(
', ',
array(
'CHANGE MASTER TO MASTER_HOST=:master_hostname',
'MASTER_USER=:replication_username',
'MASTER_PASSWORD=:replication_password',
'MASTER_LOG_FILE=:recorded_log_file_name',
'MASTER_LOG_POS=:recorded_log_pos',
)
) . ';';
$params = array(
':master_hostname' => $this->master_hostname,
':replication_username' => $this->replication_username,
':replication_password' => $this->replication_password,
':recorded_log_file_name' => $this->recorded_log_file_name,
':recorded_log_pos' => array(
$this->recorded_log_pos, $this->client->typeInt()
),
);
return $this->client->execute($statement, $params);
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"this",
"->",
"master_hostname",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"master_hostname",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"'Cannot execute CHANGE MASTER without a valid master hostname.'",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"this",
"->",
"replication_username",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"replication_username",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"'Cannot execute CHANGE MASTER without a valid replication username.'",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"this",
"->",
"replication_password",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"replication_password",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"'Cannot execute CHANGE MASTER without a valid replication password.'",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"this",
"->",
"recorded_log_file_name",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"'Cannot execute CHANGE MASTER without a valid log file name (empty is acceptable).'",
")",
";",
"}",
"if",
"(",
"!",
"is_int",
"(",
"$",
"this",
"->",
"recorded_log_pos",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"'Cannot execute CHANGE MASTER without a valid log file position.'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"recorded_log_file_name",
"==",
"self",
"::",
"EMPTY_LOG_FILENAME",
"&&",
"$",
"this",
"->",
"recorded_log_pos",
"!=",
"self",
"::",
"EMPTY_LOG_POSITION",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'The value of the log position must be equal to %d when the log file name is given as \"%s\".'",
",",
"self",
"::",
"EMPTY_LOG_POSITION",
",",
"self",
"::",
"EMPTY_LOG_FILENAME",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"recorded_log_file_name",
"!=",
"self",
"::",
"EMPTY_LOG_FILENAME",
"&&",
"$",
"this",
"->",
"recorded_log_pos",
"<=",
"self",
"::",
"EMPTY_LOG_POSITION",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'The value of the log position must be greater than %d when the log file name is given something other than \"%s\".'",
",",
"self",
"::",
"EMPTY_LOG_POSITION",
",",
"self",
"::",
"EMPTY_LOG_FILENAME",
")",
")",
";",
"}",
"$",
"statement",
"=",
"implode",
"(",
"', '",
",",
"array",
"(",
"'CHANGE MASTER TO MASTER_HOST=:master_hostname'",
",",
"'MASTER_USER=:replication_username'",
",",
"'MASTER_PASSWORD=:replication_password'",
",",
"'MASTER_LOG_FILE=:recorded_log_file_name'",
",",
"'MASTER_LOG_POS=:recorded_log_pos'",
",",
")",
")",
".",
"';'",
";",
"$",
"params",
"=",
"array",
"(",
"':master_hostname'",
"=>",
"$",
"this",
"->",
"master_hostname",
",",
"':replication_username'",
"=>",
"$",
"this",
"->",
"replication_username",
",",
"':replication_password'",
"=>",
"$",
"this",
"->",
"replication_password",
",",
"':recorded_log_file_name'",
"=>",
"$",
"this",
"->",
"recorded_log_file_name",
",",
"':recorded_log_pos'",
"=>",
"array",
"(",
"$",
"this",
"->",
"recorded_log_pos",
",",
"$",
"this",
"->",
"client",
"->",
"typeInt",
"(",
")",
")",
",",
")",
";",
"return",
"$",
"this",
"->",
"client",
"->",
"execute",
"(",
"$",
"statement",
",",
"$",
"params",
")",
";",
"}"
] | Execute the CHANGE MASTER MySQL query.
@throws \UnexpectedValueException | [
"Execute",
"the",
"CHANGE",
"MASTER",
"MySQL",
"query",
"."
] | d363ec067495073469a25b48b97d460b6fba938a | https://github.com/droid-php/droid-mysql/blob/d363ec067495073469a25b48b97d460b6fba938a/src/Model/MasterInfo.php#L62-L139 |
12,783 | samurai-fw/samurai | src/Samurai/Component/Routing/Rule/Rule.php | Rule.toActionCaller | public function toActionCaller()
{
$actionCaller = new ActionCaller();
$action = $this->getAction();
if ($action instanceof Closure)
{
$actionCaller->byClosure($action);
}
else if (is_callable($action))
{
$actionCaller->byCallable($action);
}
else
{
}
return $actionCaller;
} | php | public function toActionCaller()
{
$actionCaller = new ActionCaller();
$action = $this->getAction();
if ($action instanceof Closure)
{
$actionCaller->byClosure($action);
}
else if (is_callable($action))
{
$actionCaller->byCallable($action);
}
else
{
}
return $actionCaller;
} | [
"public",
"function",
"toActionCaller",
"(",
")",
"{",
"$",
"actionCaller",
"=",
"new",
"ActionCaller",
"(",
")",
";",
"$",
"action",
"=",
"$",
"this",
"->",
"getAction",
"(",
")",
";",
"if",
"(",
"$",
"action",
"instanceof",
"Closure",
")",
"{",
"$",
"actionCaller",
"->",
"byClosure",
"(",
"$",
"action",
")",
";",
"}",
"else",
"if",
"(",
"is_callable",
"(",
"$",
"action",
")",
")",
"{",
"$",
"actionCaller",
"->",
"byCallable",
"(",
"$",
"action",
")",
";",
"}",
"else",
"{",
"}",
"return",
"$",
"actionCaller",
";",
"}"
] | rule convert to action caller
@param string $path
@param string $method
@return ActionCaller | [
"rule",
"convert",
"to",
"action",
"caller"
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Routing/Rule/Rule.php#L307-L325 |
12,784 | b01/interception | src/InterceptionException.php | InterceptionException.getMessageByCode | public function getMessageByCode( $code, array $data = NULL, $customMessage = NULL )
{
// Use custom message when set.
if ( !empty($customMessage) && \strlen($customMessage) > 0 )
{
return \vsprintf($customMessage, $data );
}
// When no entry for code found, return a generic error message.
if ( !\array_key_exists($code, $this->messages) )
{
return $this->messages[ self::GENERIC ];
}
// Parse variables in the error message when present.
if ( \is_array($data) )
{
return \vsprintf( $this->messages[$code], $data );
}
return $this->messages[ $code ];
} | php | public function getMessageByCode( $code, array $data = NULL, $customMessage = NULL )
{
// Use custom message when set.
if ( !empty($customMessage) && \strlen($customMessage) > 0 )
{
return \vsprintf($customMessage, $data );
}
// When no entry for code found, return a generic error message.
if ( !\array_key_exists($code, $this->messages) )
{
return $this->messages[ self::GENERIC ];
}
// Parse variables in the error message when present.
if ( \is_array($data) )
{
return \vsprintf( $this->messages[$code], $data );
}
return $this->messages[ $code ];
} | [
"public",
"function",
"getMessageByCode",
"(",
"$",
"code",
",",
"array",
"$",
"data",
"=",
"NULL",
",",
"$",
"customMessage",
"=",
"NULL",
")",
"{",
"// Use custom message when set.",
"if",
"(",
"!",
"empty",
"(",
"$",
"customMessage",
")",
"&&",
"\\",
"strlen",
"(",
"$",
"customMessage",
")",
">",
"0",
")",
"{",
"return",
"\\",
"vsprintf",
"(",
"$",
"customMessage",
",",
"$",
"data",
")",
";",
"}",
"// When no entry for code found, return a generic error message.",
"if",
"(",
"!",
"\\",
"array_key_exists",
"(",
"$",
"code",
",",
"$",
"this",
"->",
"messages",
")",
")",
"{",
"return",
"$",
"this",
"->",
"messages",
"[",
"self",
"::",
"GENERIC",
"]",
";",
"}",
"// Parse variables in the error message when present.",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"\\",
"vsprintf",
"(",
"$",
"this",
"->",
"messages",
"[",
"$",
"code",
"]",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"this",
"->",
"messages",
"[",
"$",
"code",
"]",
";",
"}"
] | Returns a textual error message for an error code
@param integer $code error code or another error object for code reuse
@param array $data additional data to insert into message, processed by vsprintf()
@param string $customMessage Override the built-in message with your own.
@return string error message | [
"Returns",
"a",
"textual",
"error",
"message",
"for",
"an",
"error",
"code"
] | fe508529a49d97d5f24fa835cdbb6e4a67137be3 | https://github.com/b01/interception/blob/fe508529a49d97d5f24fa835cdbb6e4a67137be3/src/InterceptionException.php#L56-L77 |
12,785 | PytoCryto/PytoFlashMessage | src/FlashMessage.php | FlashMessage.resetMessageTypes | protected function resetMessageTypes()
{
foreach (array_keys($this->config('types')) as $type) {
$_SESSION[$this->alias][$type] = [];
}
} | php | protected function resetMessageTypes()
{
foreach (array_keys($this->config('types')) as $type) {
$_SESSION[$this->alias][$type] = [];
}
} | [
"protected",
"function",
"resetMessageTypes",
"(",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"config",
"(",
"'types'",
")",
")",
"as",
"$",
"type",
")",
"{",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"alias",
"]",
"[",
"$",
"type",
"]",
"=",
"[",
"]",
";",
"}",
"}"
] | Clear all the messages but keep an empty array in the session
@return void | [
"Clear",
"all",
"the",
"messages",
"but",
"keep",
"an",
"empty",
"array",
"in",
"the",
"session"
] | c35d9883b6b464f1bdef2db737540fb91c00a28a | https://github.com/PytoCryto/PytoFlashMessage/blob/c35d9883b6b464f1bdef2db737540fb91c00a28a/src/FlashMessage.php#L103-L108 |
12,786 | PytoCryto/PytoFlashMessage | src/FlashMessage.php | FlashMessage.success | public function success($message, $dismissable = true, $title = null)
{
return $this->make($message, $title, $dismissable, __FUNCTION__);
} | php | public function success($message, $dismissable = true, $title = null)
{
return $this->make($message, $title, $dismissable, __FUNCTION__);
} | [
"public",
"function",
"success",
"(",
"$",
"message",
",",
"$",
"dismissable",
"=",
"true",
",",
"$",
"title",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"make",
"(",
"$",
"message",
",",
"$",
"title",
",",
"$",
"dismissable",
",",
"__FUNCTION__",
")",
";",
"}"
] | Flash a success message
@param string $message
@param bool $dismissable
@param string|null $title
@return $this | [
"Flash",
"a",
"success",
"message"
] | c35d9883b6b464f1bdef2db737540fb91c00a28a | https://github.com/PytoCryto/PytoFlashMessage/blob/c35d9883b6b464f1bdef2db737540fb91c00a28a/src/FlashMessage.php#L118-L121 |
12,787 | PytoCryto/PytoFlashMessage | src/FlashMessage.php | FlashMessage.getTitle | protected function getTitle($type)
{
return array_key_exists($type, $this->config('titles'))
? $this->config('titles')[$type]
: null;
} | php | protected function getTitle($type)
{
return array_key_exists($type, $this->config('titles'))
? $this->config('titles')[$type]
: null;
} | [
"protected",
"function",
"getTitle",
"(",
"$",
"type",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"config",
"(",
"'titles'",
")",
")",
"?",
"$",
"this",
"->",
"config",
"(",
"'titles'",
")",
"[",
"$",
"type",
"]",
":",
"null",
";",
"}"
] | Get the message title for the given type
@param string $type
@return string|null | [
"Get",
"the",
"message",
"title",
"for",
"the",
"given",
"type"
] | c35d9883b6b464f1bdef2db737540fb91c00a28a | https://github.com/PytoCryto/PytoFlashMessage/blob/c35d9883b6b464f1bdef2db737540fb91c00a28a/src/FlashMessage.php#L179-L184 |
12,788 | PytoCryto/PytoFlashMessage | src/FlashMessage.php | FlashMessage.make | protected function make($message, $title, $dismissable, $type)
{
if (! $this->isValidType($type)) {
return false;
}
if (is_null($title) && $this->config('withTitles') === true) {
$title = $this->getTitle($type);
}
$message = str_replace(
'{counter}',
count(@$_SESSION[$this->alias][$type]) + 1,
$message
);
$this->addMessageToSession($message, $title, $dismissable, $type);
return $this;
} | php | protected function make($message, $title, $dismissable, $type)
{
if (! $this->isValidType($type)) {
return false;
}
if (is_null($title) && $this->config('withTitles') === true) {
$title = $this->getTitle($type);
}
$message = str_replace(
'{counter}',
count(@$_SESSION[$this->alias][$type]) + 1,
$message
);
$this->addMessageToSession($message, $title, $dismissable, $type);
return $this;
} | [
"protected",
"function",
"make",
"(",
"$",
"message",
",",
"$",
"title",
",",
"$",
"dismissable",
",",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValidType",
"(",
"$",
"type",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"title",
")",
"&&",
"$",
"this",
"->",
"config",
"(",
"'withTitles'",
")",
"===",
"true",
")",
"{",
"$",
"title",
"=",
"$",
"this",
"->",
"getTitle",
"(",
"$",
"type",
")",
";",
"}",
"$",
"message",
"=",
"str_replace",
"(",
"'{counter}'",
",",
"count",
"(",
"@",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"alias",
"]",
"[",
"$",
"type",
"]",
")",
"+",
"1",
",",
"$",
"message",
")",
";",
"$",
"this",
"->",
"addMessageToSession",
"(",
"$",
"message",
",",
"$",
"title",
",",
"$",
"dismissable",
",",
"$",
"type",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Create the message and store it in the session
@param string $message
@param string|null $title
@param bool $dismissable
@param string $type
@return bool|$this | [
"Create",
"the",
"message",
"and",
"store",
"it",
"in",
"the",
"session"
] | c35d9883b6b464f1bdef2db737540fb91c00a28a | https://github.com/PytoCryto/PytoFlashMessage/blob/c35d9883b6b464f1bdef2db737540fb91c00a28a/src/FlashMessage.php#L195-L214 |
12,789 | PytoCryto/PytoFlashMessage | src/FlashMessage.php | FlashMessage.addMessageToSession | protected function addMessageToSession($message, $title, $dismissable, $type)
{
$_SESSION[$this->alias][$type][] = compact('message', 'title', 'dismissable', 'type');
return $this;
} | php | protected function addMessageToSession($message, $title, $dismissable, $type)
{
$_SESSION[$this->alias][$type][] = compact('message', 'title', 'dismissable', 'type');
return $this;
} | [
"protected",
"function",
"addMessageToSession",
"(",
"$",
"message",
",",
"$",
"title",
",",
"$",
"dismissable",
",",
"$",
"type",
")",
"{",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"alias",
"]",
"[",
"$",
"type",
"]",
"[",
"]",
"=",
"compact",
"(",
"'message'",
",",
"'title'",
",",
"'dismissable'",
",",
"'type'",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Push the message to the session
@param string $message
@param string|null $title
@param bool $dismissable
@param string $type
@return $this | [
"Push",
"the",
"message",
"to",
"the",
"session"
] | c35d9883b6b464f1bdef2db737540fb91c00a28a | https://github.com/PytoCryto/PytoFlashMessage/blob/c35d9883b6b464f1bdef2db737540fb91c00a28a/src/FlashMessage.php#L225-L230 |
12,790 | PytoCryto/PytoFlashMessage | src/FlashMessage.php | FlashMessage.config | public function config($key, $default = null)
{
// if an array is passed as the key, we will assume you want to set an array of values
if (is_array($key)) {
return $this->config = array_merge($this->config, $key);
}
return array_key_exists($key, $this->config)
? $this->config[$key]
: $default;
} | php | public function config($key, $default = null)
{
// if an array is passed as the key, we will assume you want to set an array of values
if (is_array($key)) {
return $this->config = array_merge($this->config, $key);
}
return array_key_exists($key, $this->config)
? $this->config[$key]
: $default;
} | [
"public",
"function",
"config",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"// if an array is passed as the key, we will assume you want to set an array of values",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"config",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"key",
")",
";",
"}",
"return",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"config",
")",
"?",
"$",
"this",
"->",
"config",
"[",
"$",
"key",
"]",
":",
"$",
"default",
";",
"}"
] | Get or set configuration values
@param string|array $key
@param mixed|null $default
@return mixed | [
"Get",
"or",
"set",
"configuration",
"values"
] | c35d9883b6b464f1bdef2db737540fb91c00a28a | https://github.com/PytoCryto/PytoFlashMessage/blob/c35d9883b6b464f1bdef2db737540fb91c00a28a/src/FlashMessage.php#L239-L249 |
12,791 | PytoCryto/PytoFlashMessage | src/FlashMessage.php | FlashMessage.hasMessages | public function hasMessages($type)
{
return isset($_SESSION[$alias = $this->alias][$type]) && count($_SESSION[$alias][$type]) > 0;
} | php | public function hasMessages($type)
{
return isset($_SESSION[$alias = $this->alias][$type]) && count($_SESSION[$alias][$type]) > 0;
} | [
"public",
"function",
"hasMessages",
"(",
"$",
"type",
")",
"{",
"return",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"alias",
"=",
"$",
"this",
"->",
"alias",
"]",
"[",
"$",
"type",
"]",
")",
"&&",
"count",
"(",
"$",
"_SESSION",
"[",
"$",
"alias",
"]",
"[",
"$",
"type",
"]",
")",
">",
"0",
";",
"}"
] | Indicate whether there is messages stored on the given type
@param string $type
@return bool | [
"Indicate",
"whether",
"there",
"is",
"messages",
"stored",
"on",
"the",
"given",
"type"
] | c35d9883b6b464f1bdef2db737540fb91c00a28a | https://github.com/PytoCryto/PytoFlashMessage/blob/c35d9883b6b464f1bdef2db737540fb91c00a28a/src/FlashMessage.php#L257-L260 |
12,792 | PytoCryto/PytoFlashMessage | src/FlashMessage.php | FlashMessage.getMessages | public function getMessages($type)
{
return $this->hasMessages($type)
? $_SESSION[$this->alias][$type]
: null;
} | php | public function getMessages($type)
{
return $this->hasMessages($type)
? $_SESSION[$this->alias][$type]
: null;
} | [
"public",
"function",
"getMessages",
"(",
"$",
"type",
")",
"{",
"return",
"$",
"this",
"->",
"hasMessages",
"(",
"$",
"type",
")",
"?",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"alias",
"]",
"[",
"$",
"type",
"]",
":",
"null",
";",
"}"
] | Get messages from the given type
@param string $type
@return mixed | [
"Get",
"messages",
"from",
"the",
"given",
"type"
] | c35d9883b6b464f1bdef2db737540fb91c00a28a | https://github.com/PytoCryto/PytoFlashMessage/blob/c35d9883b6b464f1bdef2db737540fb91c00a28a/src/FlashMessage.php#L289-L294 |
12,793 | PytoCryto/PytoFlashMessage | src/FlashMessage.php | FlashMessage.display | public function display($types = null, $return = false)
{
$html = null;
$types = $types ?: array_keys($this->config('types'));
foreach ((array)$types as $type) {
if (! $this->isValidType($type) || ($messages = $this->getMessages($type)) === null) {
continue;
}
foreach ($messages as $message) {
$html .= $this->formatMessage($message, $type);
}
$this->clear($type);
}
$html = sprintf($this->config('container'), $html);
if ($return) {
return $html;
}
echo $html;
} | php | public function display($types = null, $return = false)
{
$html = null;
$types = $types ?: array_keys($this->config('types'));
foreach ((array)$types as $type) {
if (! $this->isValidType($type) || ($messages = $this->getMessages($type)) === null) {
continue;
}
foreach ($messages as $message) {
$html .= $this->formatMessage($message, $type);
}
$this->clear($type);
}
$html = sprintf($this->config('container'), $html);
if ($return) {
return $html;
}
echo $html;
} | [
"public",
"function",
"display",
"(",
"$",
"types",
"=",
"null",
",",
"$",
"return",
"=",
"false",
")",
"{",
"$",
"html",
"=",
"null",
";",
"$",
"types",
"=",
"$",
"types",
"?",
":",
"array_keys",
"(",
"$",
"this",
"->",
"config",
"(",
"'types'",
")",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValidType",
"(",
"$",
"type",
")",
"||",
"(",
"$",
"messages",
"=",
"$",
"this",
"->",
"getMessages",
"(",
"$",
"type",
")",
")",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"message",
")",
"{",
"$",
"html",
".=",
"$",
"this",
"->",
"formatMessage",
"(",
"$",
"message",
",",
"$",
"type",
")",
";",
"}",
"$",
"this",
"->",
"clear",
"(",
"$",
"type",
")",
";",
"}",
"$",
"html",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"config",
"(",
"'container'",
")",
",",
"$",
"html",
")",
";",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"$",
"html",
";",
"}",
"echo",
"$",
"html",
";",
"}"
] | Display the messages
@param string|array|null $types
@param bool $return
@return string | [
"Display",
"the",
"messages"
] | c35d9883b6b464f1bdef2db737540fb91c00a28a | https://github.com/PytoCryto/PytoFlashMessage/blob/c35d9883b6b464f1bdef2db737540fb91c00a28a/src/FlashMessage.php#L303-L327 |
12,794 | PytoCryto/PytoFlashMessage | src/FlashMessage.php | FlashMessage.formatMessage | protected function formatMessage(array $data, $type)
{
$shouldBeSticky = $this->config('sticky') === true || $data['dismissable'] !== true;
$templateData = [
'{message.baseClass}' => $this->config('baseClass'),
'{message.class}' => $this->config('types')[$type],
'{message.fadeClass}' => $this->config('fadeOut') ? 'fade in' : null,
'{message.contents}' => $data['message'],
'{message.title}' => null,
'{button}' => $shouldBeSticky ? null : $this->config('button')
];
if ($data['dismissable'] === true) {
$templateData['{message.class}'] .= ' ' . $this->config('dismissableClass');
}
if (! is_null($title = $data['title'])) {
$templateData['{message.title}'] = sprintf($this->config('title'), $title);
}
return str_replace(
array_keys($templateData), array_values($templateData), $this->config('wrapper')
);
} | php | protected function formatMessage(array $data, $type)
{
$shouldBeSticky = $this->config('sticky') === true || $data['dismissable'] !== true;
$templateData = [
'{message.baseClass}' => $this->config('baseClass'),
'{message.class}' => $this->config('types')[$type],
'{message.fadeClass}' => $this->config('fadeOut') ? 'fade in' : null,
'{message.contents}' => $data['message'],
'{message.title}' => null,
'{button}' => $shouldBeSticky ? null : $this->config('button')
];
if ($data['dismissable'] === true) {
$templateData['{message.class}'] .= ' ' . $this->config('dismissableClass');
}
if (! is_null($title = $data['title'])) {
$templateData['{message.title}'] = sprintf($this->config('title'), $title);
}
return str_replace(
array_keys($templateData), array_values($templateData), $this->config('wrapper')
);
} | [
"protected",
"function",
"formatMessage",
"(",
"array",
"$",
"data",
",",
"$",
"type",
")",
"{",
"$",
"shouldBeSticky",
"=",
"$",
"this",
"->",
"config",
"(",
"'sticky'",
")",
"===",
"true",
"||",
"$",
"data",
"[",
"'dismissable'",
"]",
"!==",
"true",
";",
"$",
"templateData",
"=",
"[",
"'{message.baseClass}'",
"=>",
"$",
"this",
"->",
"config",
"(",
"'baseClass'",
")",
",",
"'{message.class}'",
"=>",
"$",
"this",
"->",
"config",
"(",
"'types'",
")",
"[",
"$",
"type",
"]",
",",
"'{message.fadeClass}'",
"=>",
"$",
"this",
"->",
"config",
"(",
"'fadeOut'",
")",
"?",
"'fade in'",
":",
"null",
",",
"'{message.contents}'",
"=>",
"$",
"data",
"[",
"'message'",
"]",
",",
"'{message.title}'",
"=>",
"null",
",",
"'{button}'",
"=>",
"$",
"shouldBeSticky",
"?",
"null",
":",
"$",
"this",
"->",
"config",
"(",
"'button'",
")",
"]",
";",
"if",
"(",
"$",
"data",
"[",
"'dismissable'",
"]",
"===",
"true",
")",
"{",
"$",
"templateData",
"[",
"'{message.class}'",
"]",
".=",
"' '",
".",
"$",
"this",
"->",
"config",
"(",
"'dismissableClass'",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"title",
"=",
"$",
"data",
"[",
"'title'",
"]",
")",
")",
"{",
"$",
"templateData",
"[",
"'{message.title}'",
"]",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"config",
"(",
"'title'",
")",
",",
"$",
"title",
")",
";",
"}",
"return",
"str_replace",
"(",
"array_keys",
"(",
"$",
"templateData",
")",
",",
"array_values",
"(",
"$",
"templateData",
")",
",",
"$",
"this",
"->",
"config",
"(",
"'wrapper'",
")",
")",
";",
"}"
] | Format the given data
@param array $data
@param string $type
@return string | [
"Format",
"the",
"given",
"data"
] | c35d9883b6b464f1bdef2db737540fb91c00a28a | https://github.com/PytoCryto/PytoFlashMessage/blob/c35d9883b6b464f1bdef2db737540fb91c00a28a/src/FlashMessage.php#L336-L360 |
12,795 | tux-rampage/rampage-php | library/rampage/core/UserConfig.php | UserConfig.getDomain | protected function getDomain()
{
if ($this->domain !== null) {
return $this->domain;
}
if (PHP_SAPI == 'cli') {
$this->domain = '__CLI__';
return $this->domain;
}
$this->domain = isset($_SERVER['SERVER_NAME'])? $_SERVER['SERVER_NAME'] : 'default';
return $this->domain;
} | php | protected function getDomain()
{
if ($this->domain !== null) {
return $this->domain;
}
if (PHP_SAPI == 'cli') {
$this->domain = '__CLI__';
return $this->domain;
}
$this->domain = isset($_SERVER['SERVER_NAME'])? $_SERVER['SERVER_NAME'] : 'default';
return $this->domain;
} | [
"protected",
"function",
"getDomain",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"domain",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"domain",
";",
"}",
"if",
"(",
"PHP_SAPI",
"==",
"'cli'",
")",
"{",
"$",
"this",
"->",
"domain",
"=",
"'__CLI__'",
";",
"return",
"$",
"this",
"->",
"domain",
";",
"}",
"$",
"this",
"->",
"domain",
"=",
"isset",
"(",
"$",
"_SERVER",
"[",
"'SERVER_NAME'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'SERVER_NAME'",
"]",
":",
"'default'",
";",
"return",
"$",
"this",
"->",
"domain",
";",
"}"
] | Current domain for retrieving values
@return string | [
"Current",
"domain",
"for",
"retrieving",
"values"
] | 1c679b04a6d477e2f8fdb86135e1d9f0c128b1cf | https://github.com/tux-rampage/rampage-php/blob/1c679b04a6d477e2f8fdb86135e1d9f0c128b1cf/library/rampage/core/UserConfig.php#L83-L96 |
12,796 | tux-rampage/rampage-php | library/rampage/core/UserConfig.php | UserConfig.getConfigValue | public function getConfigValue($name, $default = null, $domain = null)
{
if ($domain === null) {
$domain = $this->getDomain();
} else if ($domain === false) {
$domain = '__default__';
}
$domain = strtolower($domain);
if (isset($this->values[$domain]) && array_key_exists($name, $this->values[$domain])) {
return $this->values[$domain][$name];
}
// already tried to fetch this property without success
if (isset($this->undefined[$domain][$name])) {
return $default;
}
// Find the matching node
$xpathName = $this->xpathQuote($name);
if ($domain == '__default__') {
$node = $this->getNode("./property[@name = $xpathName and not(@domain)]");
} else {
$xpathDomain = $this->xpathQuote($domain);
$node = $this->getNode("./property[@name = $xpathName and @domain = $xpathDomain]");
if (!$node instanceof xml\SimpleXmlElement) {
$node = $this->getNode("./property[@name = $xpathName and not(@domain)]");
}
}
// node was not found?
if (!$node instanceof xml\SimpleXmlElement) {
$this->undefined[$domain][$name] = true;
return $default;
}
// extract the node value by type
$type = (string)$node['type'];
switch ($type) {
case 'array':
case 'instance':
$value = $node->toPhpValue($type);
break;
case '':
$type = 'string';
// break intentionally omitted
default:
$value = $node->toValue($type, 'value');
break;
}
$this->values[$domain][$name] = $value;
return $value;
} | php | public function getConfigValue($name, $default = null, $domain = null)
{
if ($domain === null) {
$domain = $this->getDomain();
} else if ($domain === false) {
$domain = '__default__';
}
$domain = strtolower($domain);
if (isset($this->values[$domain]) && array_key_exists($name, $this->values[$domain])) {
return $this->values[$domain][$name];
}
// already tried to fetch this property without success
if (isset($this->undefined[$domain][$name])) {
return $default;
}
// Find the matching node
$xpathName = $this->xpathQuote($name);
if ($domain == '__default__') {
$node = $this->getNode("./property[@name = $xpathName and not(@domain)]");
} else {
$xpathDomain = $this->xpathQuote($domain);
$node = $this->getNode("./property[@name = $xpathName and @domain = $xpathDomain]");
if (!$node instanceof xml\SimpleXmlElement) {
$node = $this->getNode("./property[@name = $xpathName and not(@domain)]");
}
}
// node was not found?
if (!$node instanceof xml\SimpleXmlElement) {
$this->undefined[$domain][$name] = true;
return $default;
}
// extract the node value by type
$type = (string)$node['type'];
switch ($type) {
case 'array':
case 'instance':
$value = $node->toPhpValue($type);
break;
case '':
$type = 'string';
// break intentionally omitted
default:
$value = $node->toValue($type, 'value');
break;
}
$this->values[$domain][$name] = $value;
return $value;
} | [
"public",
"function",
"getConfigValue",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"null",
",",
"$",
"domain",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"domain",
"===",
"null",
")",
"{",
"$",
"domain",
"=",
"$",
"this",
"->",
"getDomain",
"(",
")",
";",
"}",
"else",
"if",
"(",
"$",
"domain",
"===",
"false",
")",
"{",
"$",
"domain",
"=",
"'__default__'",
";",
"}",
"$",
"domain",
"=",
"strtolower",
"(",
"$",
"domain",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"domain",
"]",
")",
"&&",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"values",
"[",
"$",
"domain",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"values",
"[",
"$",
"domain",
"]",
"[",
"$",
"name",
"]",
";",
"}",
"// already tried to fetch this property without success",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"undefined",
"[",
"$",
"domain",
"]",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"// Find the matching node",
"$",
"xpathName",
"=",
"$",
"this",
"->",
"xpathQuote",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"domain",
"==",
"'__default__'",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"getNode",
"(",
"\"./property[@name = $xpathName and not(@domain)]\"",
")",
";",
"}",
"else",
"{",
"$",
"xpathDomain",
"=",
"$",
"this",
"->",
"xpathQuote",
"(",
"$",
"domain",
")",
";",
"$",
"node",
"=",
"$",
"this",
"->",
"getNode",
"(",
"\"./property[@name = $xpathName and @domain = $xpathDomain]\"",
")",
";",
"if",
"(",
"!",
"$",
"node",
"instanceof",
"xml",
"\\",
"SimpleXmlElement",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"getNode",
"(",
"\"./property[@name = $xpathName and not(@domain)]\"",
")",
";",
"}",
"}",
"// node was not found?",
"if",
"(",
"!",
"$",
"node",
"instanceof",
"xml",
"\\",
"SimpleXmlElement",
")",
"{",
"$",
"this",
"->",
"undefined",
"[",
"$",
"domain",
"]",
"[",
"$",
"name",
"]",
"=",
"true",
";",
"return",
"$",
"default",
";",
"}",
"// extract the node value by type",
"$",
"type",
"=",
"(",
"string",
")",
"$",
"node",
"[",
"'type'",
"]",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'array'",
":",
"case",
"'instance'",
":",
"$",
"value",
"=",
"$",
"node",
"->",
"toPhpValue",
"(",
"$",
"type",
")",
";",
"break",
";",
"case",
"''",
":",
"$",
"type",
"=",
"'string'",
";",
"// break intentionally omitted",
"default",
":",
"$",
"value",
"=",
"$",
"node",
"->",
"toValue",
"(",
"$",
"type",
",",
"'value'",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"values",
"[",
"$",
"domain",
"]",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"value",
";",
"}"
] | Get a property name
@param string $name
@return mixed | [
"Get",
"a",
"property",
"name"
] | 1c679b04a6d477e2f8fdb86135e1d9f0c128b1cf | https://github.com/tux-rampage/rampage-php/blob/1c679b04a6d477e2f8fdb86135e1d9f0c128b1cf/library/rampage/core/UserConfig.php#L104-L161 |
12,797 | tux-rampage/rampage-php | library/rampage/core/UserConfig.php | UserConfig.processConfigVariables | protected function processConfigVariables($value, $prefix = null)
{
if ($prefix && !preg_match('~^[a-z0-9._-]*$~i', $prefix)) {
throw new exception\InvalidArgumentException('Invalid config var prefix: ' . $prefix);
}
if ($prefix) {
// dots should be literal in regex
$prefix = strtr($prefix, '.', '\\.');
}
$config = $this;
$value = preg_replace_callback("~{{({$prefix}[a-z0-9._-]+)}}~i", function($match) use ($config) {
return (string)$config->getConfigValue($match[1], '');
}, $value);
return $value;
} | php | protected function processConfigVariables($value, $prefix = null)
{
if ($prefix && !preg_match('~^[a-z0-9._-]*$~i', $prefix)) {
throw new exception\InvalidArgumentException('Invalid config var prefix: ' . $prefix);
}
if ($prefix) {
// dots should be literal in regex
$prefix = strtr($prefix, '.', '\\.');
}
$config = $this;
$value = preg_replace_callback("~{{({$prefix}[a-z0-9._-]+)}}~i", function($match) use ($config) {
return (string)$config->getConfigValue($match[1], '');
}, $value);
return $value;
} | [
"protected",
"function",
"processConfigVariables",
"(",
"$",
"value",
",",
"$",
"prefix",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"prefix",
"&&",
"!",
"preg_match",
"(",
"'~^[a-z0-9._-]*$~i'",
",",
"$",
"prefix",
")",
")",
"{",
"throw",
"new",
"exception",
"\\",
"InvalidArgumentException",
"(",
"'Invalid config var prefix: '",
".",
"$",
"prefix",
")",
";",
"}",
"if",
"(",
"$",
"prefix",
")",
"{",
"// dots should be literal in regex",
"$",
"prefix",
"=",
"strtr",
"(",
"$",
"prefix",
",",
"'.'",
",",
"'\\\\.'",
")",
";",
"}",
"$",
"config",
"=",
"$",
"this",
";",
"$",
"value",
"=",
"preg_replace_callback",
"(",
"\"~{{({$prefix}[a-z0-9._-]+)}}~i\"",
",",
"function",
"(",
"$",
"match",
")",
"use",
"(",
"$",
"config",
")",
"{",
"return",
"(",
"string",
")",
"$",
"config",
"->",
"getConfigValue",
"(",
"$",
"match",
"[",
"1",
"]",
",",
"''",
")",
";",
"}",
",",
"$",
"value",
")",
";",
"return",
"$",
"value",
";",
"}"
] | Replace placeholders with config values
@param string $value
@param string $prefix | [
"Replace",
"placeholders",
"with",
"config",
"values"
] | 1c679b04a6d477e2f8fdb86135e1d9f0c128b1cf | https://github.com/tux-rampage/rampage-php/blob/1c679b04a6d477e2f8fdb86135e1d9f0c128b1cf/library/rampage/core/UserConfig.php#L169-L186 |
12,798 | phlexible/phlexible | src/Phlexible/Component/Formatter/AgeFormatter.php | AgeFormatter.formatDate | public static function formatDate($firstDate, $secondDate = null, $returnAsArray = false)
{
if ($firstDate instanceof \DateTime) {
$firstTimestamp = $firstDate->format('U');
} elseif (is_int($firstDate)) {
$firstTimestamp = strtotime($firstDate);
} else {
$firstTimestamp = strtotime($firstDate);
}
$secondTimestamp = null;
if ($secondDate instanceof \DateTime) {
$secondTimestamp = $secondDate->format('U');
} elseif (is_int($secondDate)) {
$secondTimestamp = strtotime($secondDate);
} else {
$secondTimestamp = strtotime($secondDate);
}
return self::formatTimestamp($firstTimestamp, $secondTimestamp, $returnAsArray);
} | php | public static function formatDate($firstDate, $secondDate = null, $returnAsArray = false)
{
if ($firstDate instanceof \DateTime) {
$firstTimestamp = $firstDate->format('U');
} elseif (is_int($firstDate)) {
$firstTimestamp = strtotime($firstDate);
} else {
$firstTimestamp = strtotime($firstDate);
}
$secondTimestamp = null;
if ($secondDate instanceof \DateTime) {
$secondTimestamp = $secondDate->format('U');
} elseif (is_int($secondDate)) {
$secondTimestamp = strtotime($secondDate);
} else {
$secondTimestamp = strtotime($secondDate);
}
return self::formatTimestamp($firstTimestamp, $secondTimestamp, $returnAsArray);
} | [
"public",
"static",
"function",
"formatDate",
"(",
"$",
"firstDate",
",",
"$",
"secondDate",
"=",
"null",
",",
"$",
"returnAsArray",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"firstDate",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"firstTimestamp",
"=",
"$",
"firstDate",
"->",
"format",
"(",
"'U'",
")",
";",
"}",
"elseif",
"(",
"is_int",
"(",
"$",
"firstDate",
")",
")",
"{",
"$",
"firstTimestamp",
"=",
"strtotime",
"(",
"$",
"firstDate",
")",
";",
"}",
"else",
"{",
"$",
"firstTimestamp",
"=",
"strtotime",
"(",
"$",
"firstDate",
")",
";",
"}",
"$",
"secondTimestamp",
"=",
"null",
";",
"if",
"(",
"$",
"secondDate",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"secondTimestamp",
"=",
"$",
"secondDate",
"->",
"format",
"(",
"'U'",
")",
";",
"}",
"elseif",
"(",
"is_int",
"(",
"$",
"secondDate",
")",
")",
"{",
"$",
"secondTimestamp",
"=",
"strtotime",
"(",
"$",
"secondDate",
")",
";",
"}",
"else",
"{",
"$",
"secondTimestamp",
"=",
"strtotime",
"(",
"$",
"secondDate",
")",
";",
"}",
"return",
"self",
"::",
"formatTimestamp",
"(",
"$",
"firstTimestamp",
",",
"$",
"secondTimestamp",
",",
"$",
"returnAsArray",
")",
";",
"}"
] | Format the difference of 2 dates in a human readable form
If the second date is omitted, the current time will be used.
@param string $firstDate
@param string $secondDate
@param bool $returnAsArray
@return string|array | [
"Format",
"the",
"difference",
"of",
"2",
"dates",
"in",
"a",
"human",
"readable",
"form",
"If",
"the",
"second",
"date",
"is",
"omitted",
"the",
"current",
"time",
"will",
"be",
"used",
"."
] | 132f24924c9bb0dbb6c1ea84db0a463f97fa3893 | https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Component/Formatter/AgeFormatter.php#L31-L51 |
12,799 | phlexible/phlexible | src/Phlexible/Component/Formatter/AgeFormatter.php | AgeFormatter.formatTimestamp | public static function formatTimestamp($firstTimestamp, $secondTimestamp = null, $returnAsArray = false)
{
if ($secondTimestamp === null) {
$secondTimestamp = time();
}
$startDiff = $diff = abs($firstTimestamp - $secondTimestamp);
$suffixes = array(
array('single' => 'second', 'multi' => 'seconds', 'div' => 60, 'cap' => 60),
array('single' => 'minute', 'multi' => 'minutes', 'div' => 3600, 'cap' => 60),
array('single' => 'hour', 'multi' => 'hours', 'div' => 86400, 'cap' => 24),
array('single' => 'day', 'multi' => 'days', 'div' => 604800, 'cap' => 7),
array('single' => 'week', 'multi' => 'weeks', 'div' => 2629743.83, 'cap' => 4),
array('single' => 'month', 'multi' => 'months', 'div' => 31556925, 'cap' => 12),
array('single' => 'year', 'multi' => 'years', 'div' => 0, 'cap' => 0),
);
foreach ($suffixes as $suffixRow) {
$single = $suffixRow['single'];
$multi = $suffixRow['multi'];
$div = $suffixRow['div'];
$cap = $suffixRow['cap'];
if (!$cap) {
break;
}
if ($diff < $cap) {
if ($returnAsArray) {
return array($diff, ($diff === 1 ? $single : $multi));
}
return $diff.' '.($diff === 1 ? $single : $multi);
}
$diff = (int) round($startDiff / $div);
}
if ($returnAsArray) {
return array($diff, ($diff === 1 ? $single : $multi));
}
return $diff.' '.($diff === 1 ? $single : $multi);
} | php | public static function formatTimestamp($firstTimestamp, $secondTimestamp = null, $returnAsArray = false)
{
if ($secondTimestamp === null) {
$secondTimestamp = time();
}
$startDiff = $diff = abs($firstTimestamp - $secondTimestamp);
$suffixes = array(
array('single' => 'second', 'multi' => 'seconds', 'div' => 60, 'cap' => 60),
array('single' => 'minute', 'multi' => 'minutes', 'div' => 3600, 'cap' => 60),
array('single' => 'hour', 'multi' => 'hours', 'div' => 86400, 'cap' => 24),
array('single' => 'day', 'multi' => 'days', 'div' => 604800, 'cap' => 7),
array('single' => 'week', 'multi' => 'weeks', 'div' => 2629743.83, 'cap' => 4),
array('single' => 'month', 'multi' => 'months', 'div' => 31556925, 'cap' => 12),
array('single' => 'year', 'multi' => 'years', 'div' => 0, 'cap' => 0),
);
foreach ($suffixes as $suffixRow) {
$single = $suffixRow['single'];
$multi = $suffixRow['multi'];
$div = $suffixRow['div'];
$cap = $suffixRow['cap'];
if (!$cap) {
break;
}
if ($diff < $cap) {
if ($returnAsArray) {
return array($diff, ($diff === 1 ? $single : $multi));
}
return $diff.' '.($diff === 1 ? $single : $multi);
}
$diff = (int) round($startDiff / $div);
}
if ($returnAsArray) {
return array($diff, ($diff === 1 ? $single : $multi));
}
return $diff.' '.($diff === 1 ? $single : $multi);
} | [
"public",
"static",
"function",
"formatTimestamp",
"(",
"$",
"firstTimestamp",
",",
"$",
"secondTimestamp",
"=",
"null",
",",
"$",
"returnAsArray",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"secondTimestamp",
"===",
"null",
")",
"{",
"$",
"secondTimestamp",
"=",
"time",
"(",
")",
";",
"}",
"$",
"startDiff",
"=",
"$",
"diff",
"=",
"abs",
"(",
"$",
"firstTimestamp",
"-",
"$",
"secondTimestamp",
")",
";",
"$",
"suffixes",
"=",
"array",
"(",
"array",
"(",
"'single'",
"=>",
"'second'",
",",
"'multi'",
"=>",
"'seconds'",
",",
"'div'",
"=>",
"60",
",",
"'cap'",
"=>",
"60",
")",
",",
"array",
"(",
"'single'",
"=>",
"'minute'",
",",
"'multi'",
"=>",
"'minutes'",
",",
"'div'",
"=>",
"3600",
",",
"'cap'",
"=>",
"60",
")",
",",
"array",
"(",
"'single'",
"=>",
"'hour'",
",",
"'multi'",
"=>",
"'hours'",
",",
"'div'",
"=>",
"86400",
",",
"'cap'",
"=>",
"24",
")",
",",
"array",
"(",
"'single'",
"=>",
"'day'",
",",
"'multi'",
"=>",
"'days'",
",",
"'div'",
"=>",
"604800",
",",
"'cap'",
"=>",
"7",
")",
",",
"array",
"(",
"'single'",
"=>",
"'week'",
",",
"'multi'",
"=>",
"'weeks'",
",",
"'div'",
"=>",
"2629743.83",
",",
"'cap'",
"=>",
"4",
")",
",",
"array",
"(",
"'single'",
"=>",
"'month'",
",",
"'multi'",
"=>",
"'months'",
",",
"'div'",
"=>",
"31556925",
",",
"'cap'",
"=>",
"12",
")",
",",
"array",
"(",
"'single'",
"=>",
"'year'",
",",
"'multi'",
"=>",
"'years'",
",",
"'div'",
"=>",
"0",
",",
"'cap'",
"=>",
"0",
")",
",",
")",
";",
"foreach",
"(",
"$",
"suffixes",
"as",
"$",
"suffixRow",
")",
"{",
"$",
"single",
"=",
"$",
"suffixRow",
"[",
"'single'",
"]",
";",
"$",
"multi",
"=",
"$",
"suffixRow",
"[",
"'multi'",
"]",
";",
"$",
"div",
"=",
"$",
"suffixRow",
"[",
"'div'",
"]",
";",
"$",
"cap",
"=",
"$",
"suffixRow",
"[",
"'cap'",
"]",
";",
"if",
"(",
"!",
"$",
"cap",
")",
"{",
"break",
";",
"}",
"if",
"(",
"$",
"diff",
"<",
"$",
"cap",
")",
"{",
"if",
"(",
"$",
"returnAsArray",
")",
"{",
"return",
"array",
"(",
"$",
"diff",
",",
"(",
"$",
"diff",
"===",
"1",
"?",
"$",
"single",
":",
"$",
"multi",
")",
")",
";",
"}",
"return",
"$",
"diff",
".",
"' '",
".",
"(",
"$",
"diff",
"===",
"1",
"?",
"$",
"single",
":",
"$",
"multi",
")",
";",
"}",
"$",
"diff",
"=",
"(",
"int",
")",
"round",
"(",
"$",
"startDiff",
"/",
"$",
"div",
")",
";",
"}",
"if",
"(",
"$",
"returnAsArray",
")",
"{",
"return",
"array",
"(",
"$",
"diff",
",",
"(",
"$",
"diff",
"===",
"1",
"?",
"$",
"single",
":",
"$",
"multi",
")",
")",
";",
"}",
"return",
"$",
"diff",
".",
"' '",
".",
"(",
"$",
"diff",
"===",
"1",
"?",
"$",
"single",
":",
"$",
"multi",
")",
";",
"}"
] | Format the difference of 2 unix timestamps in a human readable form
If the second date is omitted, the current time will be used.
@param string $firstTimestamp
@param string $secondTimestamp
@param bool $returnAsArray
@return string|array | [
"Format",
"the",
"difference",
"of",
"2",
"unix",
"timestamps",
"in",
"a",
"human",
"readable",
"form",
"If",
"the",
"second",
"date",
"is",
"omitted",
"the",
"current",
"time",
"will",
"be",
"used",
"."
] | 132f24924c9bb0dbb6c1ea84db0a463f97fa3893 | https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Component/Formatter/AgeFormatter.php#L63-L107 |
Subsets and Splits