id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
30,800 | BKWLD/decoy | classes/Models/Base.php | Base.makeDeleteAction | protected function makeDeleteAction($data)
{
extract($data);
// Check if this model can be deleted. This mirrors code found in the table
// partial for generating the edit link on the title
if (!(app('decoy.user')->can('destroy', $controller)
|| ($many_to_many && app('decoy.user')->can('update', $parent_controller)))) {
return;
}
// If soft deleted, show a disabled icon
if (method_exists($this, 'trashed') && $this->trashed()) {
return '<span class="glyphicon glyphicon-trash"></span>';
}
// Make the label
$label = $many_to_many ?
__('decoy::base.action.remove') :
$with_trashed ?
__('decoy::base.action.soft_delete') :
__('decoy::base.action.delete') ;
// Return markup
return sprintf('<a class="%s js-tooltip" data-placement="left" title="%s">
<span class="glyphicon glyphicon-%s"></span>
</a>',
$many_to_many ? 'remove-now' : 'delete-now',
$label,
$many_to_many ? 'remove' : 'trash'
);
} | php | protected function makeDeleteAction($data)
{
extract($data);
// Check if this model can be deleted. This mirrors code found in the table
// partial for generating the edit link on the title
if (!(app('decoy.user')->can('destroy', $controller)
|| ($many_to_many && app('decoy.user')->can('update', $parent_controller)))) {
return;
}
// If soft deleted, show a disabled icon
if (method_exists($this, 'trashed') && $this->trashed()) {
return '<span class="glyphicon glyphicon-trash"></span>';
}
// Make the label
$label = $many_to_many ?
__('decoy::base.action.remove') :
$with_trashed ?
__('decoy::base.action.soft_delete') :
__('decoy::base.action.delete') ;
// Return markup
return sprintf('<a class="%s js-tooltip" data-placement="left" title="%s">
<span class="glyphicon glyphicon-%s"></span>
</a>',
$many_to_many ? 'remove-now' : 'delete-now',
$label,
$many_to_many ? 'remove' : 'trash'
);
} | [
"protected",
"function",
"makeDeleteAction",
"(",
"$",
"data",
")",
"{",
"extract",
"(",
"$",
"data",
")",
";",
"// Check if this model can be deleted. This mirrors code found in the table",
"// partial for generating the edit link on the title",
"if",
"(",
"!",
"(",
"app",
"(",
"'decoy.user'",
")",
"->",
"can",
"(",
"'destroy'",
",",
"$",
"controller",
")",
"||",
"(",
"$",
"many_to_many",
"&&",
"app",
"(",
"'decoy.user'",
")",
"->",
"can",
"(",
"'update'",
",",
"$",
"parent_controller",
")",
")",
")",
")",
"{",
"return",
";",
"}",
"// If soft deleted, show a disabled icon",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'trashed'",
")",
"&&",
"$",
"this",
"->",
"trashed",
"(",
")",
")",
"{",
"return",
"'<span class=\"glyphicon glyphicon-trash\"></span>'",
";",
"}",
"// Make the label",
"$",
"label",
"=",
"$",
"many_to_many",
"?",
"__",
"(",
"'decoy::base.action.remove'",
")",
":",
"$",
"with_trashed",
"?",
"__",
"(",
"'decoy::base.action.soft_delete'",
")",
":",
"__",
"(",
"'decoy::base.action.delete'",
")",
";",
"// Return markup",
"return",
"sprintf",
"(",
"'<a class=\"%s js-tooltip\" data-placement=\"left\" title=\"%s\">\n <span class=\"glyphicon glyphicon-%s\"></span>\n </a>'",
",",
"$",
"many_to_many",
"?",
"'remove-now'",
":",
"'delete-now'",
",",
"$",
"label",
",",
"$",
"many_to_many",
"?",
"'remove'",
":",
"'trash'",
")",
";",
"}"
] | Make the delete action
@param array $data The data passed to a listing view
@return string | [
"Make",
"the",
"delete",
"action"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L525-L556 |
30,801 | BKWLD/decoy | classes/Models/Base.php | Base.scopePositioned | public function scopePositioned($query)
{
$query->orderBy($this->getTable().'.position', 'asc');
if ($this->usesTimestamps()) {
$query->orderBy($this->getTable().'.created_at', 'desc');
}
return $query;
} | php | public function scopePositioned($query)
{
$query->orderBy($this->getTable().'.position', 'asc');
if ($this->usesTimestamps()) {
$query->orderBy($this->getTable().'.created_at', 'desc');
}
return $query;
} | [
"public",
"function",
"scopePositioned",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"orderBy",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"'.position'",
",",
"'asc'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"usesTimestamps",
"(",
")",
")",
"{",
"$",
"query",
"->",
"orderBy",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"'.created_at'",
",",
"'desc'",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Order a table that has a position value
@param Illuminate\Database\Query\Builder $query
@return Illuminate\Database\Query\Builder | [
"Order",
"a",
"table",
"that",
"has",
"a",
"position",
"value"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L666-L673 |
30,802 | BKWLD/decoy | classes/Models/Base.php | Base.scopeRandomize | public function scopeRandomize($query, $seed = false)
{
if ($seed === true) {
$seed = Session::getId();
}
if ($seed) {
return $query->orderBy(DB::raw('RAND("'.$seed.'")'));
}
return $query->orderBy(DB::raw('RAND()'));
} | php | public function scopeRandomize($query, $seed = false)
{
if ($seed === true) {
$seed = Session::getId();
}
if ($seed) {
return $query->orderBy(DB::raw('RAND("'.$seed.'")'));
}
return $query->orderBy(DB::raw('RAND()'));
} | [
"public",
"function",
"scopeRandomize",
"(",
"$",
"query",
",",
"$",
"seed",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"seed",
"===",
"true",
")",
"{",
"$",
"seed",
"=",
"Session",
"::",
"getId",
"(",
")",
";",
"}",
"if",
"(",
"$",
"seed",
")",
"{",
"return",
"$",
"query",
"->",
"orderBy",
"(",
"DB",
"::",
"raw",
"(",
"'RAND(\"'",
".",
"$",
"seed",
".",
"'\")'",
")",
")",
";",
"}",
"return",
"$",
"query",
"->",
"orderBy",
"(",
"DB",
"::",
"raw",
"(",
"'RAND()'",
")",
")",
";",
"}"
] | Randomize the results in the DB. This shouldn't be used for large datasets
cause it's not very performant
@param Illuminate\Database\Query\Builder $query
@param mixed $seed Providing a seed keeps the order the same on subsequent queries
@return Illuminate\Database\Query\Builder | [
"Randomize",
"the",
"results",
"in",
"the",
"DB",
".",
"This",
"shouldn",
"t",
"be",
"used",
"for",
"large",
"datasets",
"cause",
"it",
"s",
"not",
"very",
"performant"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L694-L705 |
30,803 | BKWLD/decoy | classes/Models/Base.php | Base.scopeOtherLocalizations | public function scopeOtherLocalizations($query)
{
return $query->where('locale_group', $this->locale_group)
->where($this->getKeyName(), '!=', $this->getKey());
} | php | public function scopeOtherLocalizations($query)
{
return $query->where('locale_group', $this->locale_group)
->where($this->getKeyName(), '!=', $this->getKey());
} | [
"public",
"function",
"scopeOtherLocalizations",
"(",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"'locale_group'",
",",
"$",
"this",
"->",
"locale_group",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"getKeyName",
"(",
")",
",",
"'!='",
",",
"$",
"this",
"->",
"getKey",
"(",
")",
")",
";",
"}"
] | Get localized siblings of this model
@param Illuminate\Database\Query\Builder $query
@return Illuminate\Database\Query\Builder | [
"Get",
"localized",
"siblings",
"of",
"this",
"model"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L725-L729 |
30,804 | BKWLD/decoy | classes/Models/Base.php | Base.findBySlugOrFail | public static function findBySlugOrFail($slug, array $columns = ['*'])
{
// Model not found, throw exception
if (!$item = static::findBySlug($slug)) {
throw (new ModelNotFoundException)->setModel(get_called_class());
}
// Return the model if visible
$item->enforceVisibility();
return $item;
} | php | public static function findBySlugOrFail($slug, array $columns = ['*'])
{
// Model not found, throw exception
if (!$item = static::findBySlug($slug)) {
throw (new ModelNotFoundException)->setModel(get_called_class());
}
// Return the model if visible
$item->enforceVisibility();
return $item;
} | [
"public",
"static",
"function",
"findBySlugOrFail",
"(",
"$",
"slug",
",",
"array",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"// Model not found, throw exception",
"if",
"(",
"!",
"$",
"item",
"=",
"static",
"::",
"findBySlug",
"(",
"$",
"slug",
")",
")",
"{",
"throw",
"(",
"new",
"ModelNotFoundException",
")",
"->",
"setModel",
"(",
"get_called_class",
"(",
")",
")",
";",
"}",
"// Return the model if visible",
"$",
"item",
"->",
"enforceVisibility",
"(",
")",
";",
"return",
"$",
"item",
";",
"}"
] | Find by the slug and fail if missing. Invokes methods from the
Sluggable trait.
@param string $string
@param array $columns
@return Illuminate\Database\Eloquent\Model
@throws Illuminate\Database\Eloquent\ModelNotFoundException | [
"Find",
"by",
"the",
"slug",
"and",
"fail",
"if",
"missing",
".",
"Invokes",
"methods",
"from",
"the",
"Sluggable",
"trait",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L741-L752 |
30,805 | BKWLD/decoy | classes/Models/Base.php | Base.fireDecoyEvent | public function fireDecoyEvent($event, $args = null)
{
$event = "decoy::model.{$event}: ".get_class($this);
return Event::fire($event, $args);
} | php | public function fireDecoyEvent($event, $args = null)
{
$event = "decoy::model.{$event}: ".get_class($this);
return Event::fire($event, $args);
} | [
"public",
"function",
"fireDecoyEvent",
"(",
"$",
"event",
",",
"$",
"args",
"=",
"null",
")",
"{",
"$",
"event",
"=",
"\"decoy::model.{$event}: \"",
".",
"get_class",
"(",
"$",
"this",
")",
";",
"return",
"Event",
"::",
"fire",
"(",
"$",
"event",
",",
"$",
"args",
")",
";",
"}"
] | Fire an Decoy model event.
@param $string event The name of this event
@param $array args An array of params that will be passed to the handler
@return object | [
"Fire",
"an",
"Decoy",
"model",
"event",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L779-L784 |
30,806 | BKWLD/decoy | classes/Models/Base.php | Base.titleAttributes | public function titleAttributes()
{
// Convert to an array so I can test for the presence of values. As an
// object, it would throw exceptions
$row = $this->getAttributes();
// Name before title to cover the case of people with job titles
if (isset($row['name'])) {
return ['name'];
}
// Search full names if people-type fields
if (isset($row['first_name']) && isset($row['last_name'])) {
return ['first_name', 'last_name'];
}
// Standard location for the title
if (isset($row['title'])) {
return ['title'];
}
// Default to no searchable attributes
return [];
} | php | public function titleAttributes()
{
// Convert to an array so I can test for the presence of values. As an
// object, it would throw exceptions
$row = $this->getAttributes();
// Name before title to cover the case of people with job titles
if (isset($row['name'])) {
return ['name'];
}
// Search full names if people-type fields
if (isset($row['first_name']) && isset($row['last_name'])) {
return ['first_name', 'last_name'];
}
// Standard location for the title
if (isset($row['title'])) {
return ['title'];
}
// Default to no searchable attributes
return [];
} | [
"public",
"function",
"titleAttributes",
"(",
")",
"{",
"// Convert to an array so I can test for the presence of values. As an",
"// object, it would throw exceptions",
"$",
"row",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
")",
";",
"// Name before title to cover the case of people with job titles",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'name'",
"]",
")",
")",
"{",
"return",
"[",
"'name'",
"]",
";",
"}",
"// Search full names if people-type fields",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'first_name'",
"]",
")",
"&&",
"isset",
"(",
"$",
"row",
"[",
"'last_name'",
"]",
")",
")",
"{",
"return",
"[",
"'first_name'",
",",
"'last_name'",
"]",
";",
"}",
"// Standard location for the title",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'title'",
"]",
")",
")",
"{",
"return",
"[",
"'title'",
"]",
";",
"}",
"// Default to no searchable attributes",
"return",
"[",
"]",
";",
"}"
] | Deduce the source for the title of the model
@return array | [
"Deduce",
"the",
"source",
"for",
"the",
"title",
"of",
"the",
"model"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L791-L814 |
30,807 | BKWLD/decoy | classes/Input/Sidebar.php | Sidebar.render | public function render()
{
// Massage the response from base controller subclassings of sidebar
$items = array_map(function ($item) {
// If a listing instance, apply defaults common to all sidebar instances
if (is_a($item, 'Bkwld\Decoy\Fields\Listing')) {
return $item->layout('sidebar')->parent($this->parent)->__toString();
}
// Anything else will be converted to a string in the next step
return $item;
}, array_merge($this->items, $this->ending_items));
// Combine all listing items into a single string and return
return array_reduce($items, function ($carry, $item) {
return $carry.$item;
}, '');
} | php | public function render()
{
// Massage the response from base controller subclassings of sidebar
$items = array_map(function ($item) {
// If a listing instance, apply defaults common to all sidebar instances
if (is_a($item, 'Bkwld\Decoy\Fields\Listing')) {
return $item->layout('sidebar')->parent($this->parent)->__toString();
}
// Anything else will be converted to a string in the next step
return $item;
}, array_merge($this->items, $this->ending_items));
// Combine all listing items into a single string and return
return array_reduce($items, function ($carry, $item) {
return $carry.$item;
}, '');
} | [
"public",
"function",
"render",
"(",
")",
"{",
"// Massage the response from base controller subclassings of sidebar",
"$",
"items",
"=",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"// If a listing instance, apply defaults common to all sidebar instances",
"if",
"(",
"is_a",
"(",
"$",
"item",
",",
"'Bkwld\\Decoy\\Fields\\Listing'",
")",
")",
"{",
"return",
"$",
"item",
"->",
"layout",
"(",
"'sidebar'",
")",
"->",
"parent",
"(",
"$",
"this",
"->",
"parent",
")",
"->",
"__toString",
"(",
")",
";",
"}",
"// Anything else will be converted to a string in the next step",
"return",
"$",
"item",
";",
"}",
",",
"array_merge",
"(",
"$",
"this",
"->",
"items",
",",
"$",
"this",
"->",
"ending_items",
")",
")",
";",
"// Combine all listing items into a single string and return",
"return",
"array_reduce",
"(",
"$",
"items",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"item",
")",
"{",
"return",
"$",
"carry",
".",
"$",
"item",
";",
"}",
",",
"''",
")",
";",
"}"
] | Render an array of listing objects to an HTML string
@return string HTML | [
"Render",
"an",
"array",
"of",
"listing",
"objects",
"to",
"an",
"HTML",
"string"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Sidebar.php#L85-L103 |
30,808 | BKWLD/decoy | classes/Fields/Former/MethodDispatcher.php | MethodDispatcher.getClassFromMethod | protected function getClassFromMethod($method)
{
// Look for a studly class
$class = Str::singular(Str::studly($method));
foreach ($this->repositories as $repository) {
if (class_exists($repository.$class)) {
return $repository.$class;
}
}
// Resume normal functioning
return parent::getClassFromMethod($method);
} | php | protected function getClassFromMethod($method)
{
// Look for a studly class
$class = Str::singular(Str::studly($method));
foreach ($this->repositories as $repository) {
if (class_exists($repository.$class)) {
return $repository.$class;
}
}
// Resume normal functioning
return parent::getClassFromMethod($method);
} | [
"protected",
"function",
"getClassFromMethod",
"(",
"$",
"method",
")",
"{",
"// Look for a studly class",
"$",
"class",
"=",
"Str",
"::",
"singular",
"(",
"Str",
"::",
"studly",
"(",
"$",
"method",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"repositories",
"as",
"$",
"repository",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"repository",
".",
"$",
"class",
")",
")",
"{",
"return",
"$",
"repository",
".",
"$",
"class",
";",
"}",
"}",
"// Resume normal functioning",
"return",
"parent",
"::",
"getClassFromMethod",
"(",
"$",
"method",
")",
";",
"}"
] | Override the parent so that study class names are respected on
case sensitive file systems.
@param string $method The field created
@return string The correct class | [
"Override",
"the",
"parent",
"so",
"that",
"study",
"class",
"names",
"are",
"respected",
"on",
"case",
"sensitive",
"file",
"systems",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Former/MethodDispatcher.php#L20-L33 |
30,809 | BKWLD/decoy | classes/Fields/Datetime.php | Datetime.value | public function value($value)
{
// Set the value using parent, so that if there is already one specified
// from populate or POST
parent::value($value);
// Set the value of the subfields
$this->date->value($value);
$this->time->value($value);
// Chainable
return $this;
} | php | public function value($value)
{
// Set the value using parent, so that if there is already one specified
// from populate or POST
parent::value($value);
// Set the value of the subfields
$this->date->value($value);
$this->time->value($value);
// Chainable
return $this;
} | [
"public",
"function",
"value",
"(",
"$",
"value",
")",
"{",
"// Set the value using parent, so that if there is already one specified",
"// from populate or POST",
"parent",
"::",
"value",
"(",
"$",
"value",
")",
";",
"// Set the value of the subfields",
"$",
"this",
"->",
"date",
"->",
"value",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"time",
"->",
"value",
"(",
"$",
"value",
")",
";",
"// Chainable",
"return",
"$",
"this",
";",
"}"
] | Massage inputted string values into dates
@param string $value A new value
@return $this | [
"Massage",
"inputted",
"string",
"values",
"into",
"dates"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Datetime.php#L67-L79 |
30,810 | BKWLD/decoy | classes/Models/Traits/Encodable.php | Encodable.encoding | public function encoding($attribute = 'video')
{
$encodings = $this->encodings;
if (!is_a($encodings, Collection::class)) {
$encodings = Encoding::hydrate($encodings);
}
return $encodings->first(function ($i, $encoding) use ($attribute) {
return data_get($encoding, 'encodable_attribute') == $attribute;
});
} | php | public function encoding($attribute = 'video')
{
$encodings = $this->encodings;
if (!is_a($encodings, Collection::class)) {
$encodings = Encoding::hydrate($encodings);
}
return $encodings->first(function ($i, $encoding) use ($attribute) {
return data_get($encoding, 'encodable_attribute') == $attribute;
});
} | [
"public",
"function",
"encoding",
"(",
"$",
"attribute",
"=",
"'video'",
")",
"{",
"$",
"encodings",
"=",
"$",
"this",
"->",
"encodings",
";",
"if",
"(",
"!",
"is_a",
"(",
"$",
"encodings",
",",
"Collection",
"::",
"class",
")",
")",
"{",
"$",
"encodings",
"=",
"Encoding",
"::",
"hydrate",
"(",
"$",
"encodings",
")",
";",
"}",
"return",
"$",
"encodings",
"->",
"first",
"(",
"function",
"(",
"$",
"i",
",",
"$",
"encoding",
")",
"use",
"(",
"$",
"attribute",
")",
"{",
"return",
"data_get",
"(",
"$",
"encoding",
",",
"'encodable_attribute'",
")",
"==",
"$",
"attribute",
";",
"}",
")",
";",
"}"
] | Find the encoding for a given database field
@param string $attribute
@return Encoding|false | [
"Find",
"the",
"encoding",
"for",
"a",
"given",
"database",
"field"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Encodable.php#L52-L62 |
30,811 | BKWLD/decoy | classes/Models/Traits/Encodable.php | Encodable.getDirtyEncodableAttributes | public function getDirtyEncodableAttributes()
{
if (empty($this->encodable_attributes)) {
return [];
}
return array_filter($this->encodable_attributes, function ($attribute) {
// The file has changed
if ($this->isDirty($attribute)) {
return true;
}
// The encoding preset is changing
return $this->hasDirtyPreset($attribute);
});
} | php | public function getDirtyEncodableAttributes()
{
if (empty($this->encodable_attributes)) {
return [];
}
return array_filter($this->encodable_attributes, function ($attribute) {
// The file has changed
if ($this->isDirty($attribute)) {
return true;
}
// The encoding preset is changing
return $this->hasDirtyPreset($attribute);
});
} | [
"public",
"function",
"getDirtyEncodableAttributes",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"encodable_attributes",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"array_filter",
"(",
"$",
"this",
"->",
"encodable_attributes",
",",
"function",
"(",
"$",
"attribute",
")",
"{",
"// The file has changed",
"if",
"(",
"$",
"this",
"->",
"isDirty",
"(",
"$",
"attribute",
")",
")",
"{",
"return",
"true",
";",
"}",
"// The encoding preset is changing",
"return",
"$",
"this",
"->",
"hasDirtyPreset",
"(",
"$",
"attribute",
")",
";",
"}",
")",
";",
"}"
] | Get all the attributes on a model who support video encodes and are dirty.
An encode is considered dirty if a file is uploaded, replaced, marked for
deletion OR if it's preset has changed.
@return array | [
"Get",
"all",
"the",
"attributes",
"on",
"a",
"model",
"who",
"support",
"video",
"encodes",
"and",
"are",
"dirty",
".",
"An",
"encode",
"is",
"considered",
"dirty",
"if",
"a",
"file",
"is",
"uploaded",
"replaced",
"marked",
"for",
"deletion",
"OR",
"if",
"it",
"s",
"preset",
"has",
"changed",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Encodable.php#L71-L87 |
30,812 | BKWLD/decoy | classes/Models/Traits/Encodable.php | Encodable.hasDirtyPreset | public function hasDirtyPreset($attribute)
{
// Require a previous encoding instance
return ($encoding = $this->encoding($attribute))
// Make sure the input actually contains a preset. It won't in cases like
// the AJAX PUT during listing drag and drop sorting or visibility toggle
&& ($preset_key = $this->encodingPresetInputKey($attribute))
&& request()->exists($preset_key)
// Check if the preset has changed
&& request($preset_key) != $encoding->preset;
} | php | public function hasDirtyPreset($attribute)
{
// Require a previous encoding instance
return ($encoding = $this->encoding($attribute))
// Make sure the input actually contains a preset. It won't in cases like
// the AJAX PUT during listing drag and drop sorting or visibility toggle
&& ($preset_key = $this->encodingPresetInputKey($attribute))
&& request()->exists($preset_key)
// Check if the preset has changed
&& request($preset_key) != $encoding->preset;
} | [
"public",
"function",
"hasDirtyPreset",
"(",
"$",
"attribute",
")",
"{",
"// Require a previous encoding instance",
"return",
"(",
"$",
"encoding",
"=",
"$",
"this",
"->",
"encoding",
"(",
"$",
"attribute",
")",
")",
"// Make sure the input actually contains a preset. It won't in cases like",
"// the AJAX PUT during listing drag and drop sorting or visibility toggle",
"&&",
"(",
"$",
"preset_key",
"=",
"$",
"this",
"->",
"encodingPresetInputKey",
"(",
"$",
"attribute",
")",
")",
"&&",
"request",
"(",
")",
"->",
"exists",
"(",
"$",
"preset_key",
")",
"// Check if the preset has changed",
"&&",
"request",
"(",
"$",
"preset_key",
")",
"!=",
"$",
"encoding",
"->",
"preset",
";",
"}"
] | Check if the preset choice is dirty
@param string $attribute
@return boolean | [
"Check",
"if",
"the",
"preset",
"choice",
"is",
"dirty"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Encodable.php#L95-L108 |
30,813 | BKWLD/decoy | classes/Models/Traits/Encodable.php | Encodable.adminColEncodeStatus | public function adminColEncodeStatus()
{
if (!$encode = $this->encoding()) {
return '<span class="label">Pending</span>';
}
switch ($encode->status) {
case 'pending':
return '<span class="label">'.ucfirst($encode->status).'</span>';
case 'error':
case 'cancelled':
return '<span class="label label-important">'.ucfirst($encode->status).'</span>';
case 'queued':
case 'processing':
return '<span class="label label-info">'.ucfirst($encode->status).'</span>';
case 'complete':
return '<span class="label label-success">'.ucfirst($encode->status).'</span>';
}
} | php | public function adminColEncodeStatus()
{
if (!$encode = $this->encoding()) {
return '<span class="label">Pending</span>';
}
switch ($encode->status) {
case 'pending':
return '<span class="label">'.ucfirst($encode->status).'</span>';
case 'error':
case 'cancelled':
return '<span class="label label-important">'.ucfirst($encode->status).'</span>';
case 'queued':
case 'processing':
return '<span class="label label-info">'.ucfirst($encode->status).'</span>';
case 'complete':
return '<span class="label label-success">'.ucfirst($encode->status).'</span>';
}
} | [
"public",
"function",
"adminColEncodeStatus",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"encode",
"=",
"$",
"this",
"->",
"encoding",
"(",
")",
")",
"{",
"return",
"'<span class=\"label\">Pending</span>'",
";",
"}",
"switch",
"(",
"$",
"encode",
"->",
"status",
")",
"{",
"case",
"'pending'",
":",
"return",
"'<span class=\"label\">'",
".",
"ucfirst",
"(",
"$",
"encode",
"->",
"status",
")",
".",
"'</span>'",
";",
"case",
"'error'",
":",
"case",
"'cancelled'",
":",
"return",
"'<span class=\"label label-important\">'",
".",
"ucfirst",
"(",
"$",
"encode",
"->",
"status",
")",
".",
"'</span>'",
";",
"case",
"'queued'",
":",
"case",
"'processing'",
":",
"return",
"'<span class=\"label label-info\">'",
".",
"ucfirst",
"(",
"$",
"encode",
"->",
"status",
")",
".",
"'</span>'",
";",
"case",
"'complete'",
":",
"return",
"'<span class=\"label label-success\">'",
".",
"ucfirst",
"(",
"$",
"encode",
"->",
"status",
")",
".",
"'</span>'",
";",
"}",
"}"
] | A utitliy function to create status badges for Decoy listings
@return string HTML | [
"A",
"utitliy",
"function",
"to",
"create",
"status",
"badges",
"for",
"Decoy",
"listings"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Encodable.php#L140-L160 |
30,814 | BKWLD/decoy | classes/Models/Traits/Encodable.php | Encodable.encode | public function encode($attribute, $preset)
{
$encoding = new Encoding([
'encodable_attribute' => $attribute,
'preset' => $preset,
]);
$this->encodings()->save($encoding);
return $encoding;
} | php | public function encode($attribute, $preset)
{
$encoding = new Encoding([
'encodable_attribute' => $attribute,
'preset' => $preset,
]);
$this->encodings()->save($encoding);
return $encoding;
} | [
"public",
"function",
"encode",
"(",
"$",
"attribute",
",",
"$",
"preset",
")",
"{",
"$",
"encoding",
"=",
"new",
"Encoding",
"(",
"[",
"'encodable_attribute'",
"=>",
"$",
"attribute",
",",
"'preset'",
"=>",
"$",
"preset",
",",
"]",
")",
";",
"$",
"this",
"->",
"encodings",
"(",
")",
"->",
"save",
"(",
"$",
"encoding",
")",
";",
"return",
"$",
"encoding",
";",
"}"
] | Delete any existing encoding for the attribute and then encode from the
source. The deleting happens automatically onCreating.
@param string $attribute The attribute on the model to use as source
@param string $preset The output config key
@return Encoding The new output instance | [
"Delete",
"any",
"existing",
"encoding",
"for",
"the",
"attribute",
"and",
"then",
"encode",
"from",
"the",
"source",
".",
"The",
"deleting",
"happens",
"automatically",
"onCreating",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Encodable.php#L208-L218 |
30,815 | BKWLD/decoy | classes/Fields/BelongsTo.php | BelongsTo.wrapAndRender | public function wrapAndRender()
{
// Apend the edit button
$this->appendEditButton();
// Add control group attributes
$this->addGroupClass('belongs-to');
$this->group->setAttribute('data-js-view', 'belongs-to');
if ($this->route) {
$this->group->setAttribute('data-controller-route', $this->route);
}
// Continue doing normal wrapping
return parent::wrapAndRender();
} | php | public function wrapAndRender()
{
// Apend the edit button
$this->appendEditButton();
// Add control group attributes
$this->addGroupClass('belongs-to');
$this->group->setAttribute('data-js-view', 'belongs-to');
if ($this->route) {
$this->group->setAttribute('data-controller-route', $this->route);
}
// Continue doing normal wrapping
return parent::wrapAndRender();
} | [
"public",
"function",
"wrapAndRender",
"(",
")",
"{",
"// Apend the edit button",
"$",
"this",
"->",
"appendEditButton",
"(",
")",
";",
"// Add control group attributes",
"$",
"this",
"->",
"addGroupClass",
"(",
"'belongs-to'",
")",
";",
"$",
"this",
"->",
"group",
"->",
"setAttribute",
"(",
"'data-js-view'",
",",
"'belongs-to'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"route",
")",
"{",
"$",
"this",
"->",
"group",
"->",
"setAttribute",
"(",
"'data-controller-route'",
",",
"$",
"this",
"->",
"route",
")",
";",
"}",
"// Continue doing normal wrapping",
"return",
"parent",
"::",
"wrapAndRender",
"(",
")",
";",
"}"
] | Prints out the field, wrapped in its group. This is the opportunity
to tack additional stuff onto the control group
@return string | [
"Prints",
"out",
"the",
"field",
"wrapped",
"in",
"its",
"group",
".",
"This",
"is",
"the",
"opportunity",
"to",
"tack",
"additional",
"stuff",
"onto",
"the",
"control",
"group"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/BelongsTo.php#L128-L142 |
30,816 | BKWLD/decoy | classes/Fields/BelongsTo.php | BelongsTo.parentModel | public function parentModel()
{
if ($this->value
&& ($relation = $this->guessRelation())
&& ($model = $this->getModel())
&& method_exists($model, $relation)) {
return $model->$relation;
}
} | php | public function parentModel()
{
if ($this->value
&& ($relation = $this->guessRelation())
&& ($model = $this->getModel())
&& method_exists($model, $relation)) {
return $model->$relation;
}
} | [
"public",
"function",
"parentModel",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"value",
"&&",
"(",
"$",
"relation",
"=",
"$",
"this",
"->",
"guessRelation",
"(",
")",
")",
"&&",
"(",
"$",
"model",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
")",
"&&",
"method_exists",
"(",
"$",
"model",
",",
"$",
"relation",
")",
")",
"{",
"return",
"$",
"model",
"->",
"$",
"relation",
";",
"}",
"}"
] | Get the parent record of the form instance
@return Illuminate\Database\Eloquent\Model | [
"Get",
"the",
"parent",
"record",
"of",
"the",
"form",
"instance"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/BelongsTo.php#L197-L205 |
30,817 | BKWLD/decoy | classes/Fields/BelongsTo.php | BelongsTo.guessRelation | protected function guessRelation()
{
if ($this->relation) {
return $this->relation;
}
return Str::camel(str_replace('_id', '', $this->name));
} | php | protected function guessRelation()
{
if ($this->relation) {
return $this->relation;
}
return Str::camel(str_replace('_id', '', $this->name));
} | [
"protected",
"function",
"guessRelation",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"relation",
")",
"{",
"return",
"$",
"this",
"->",
"relation",
";",
"}",
"return",
"Str",
"::",
"camel",
"(",
"str_replace",
"(",
"'_id'",
",",
"''",
",",
"$",
"this",
"->",
"name",
")",
")",
";",
"}"
] | Guess at the relationship name by removing id from the name and camel casing
@return string | [
"Guess",
"at",
"the",
"relationship",
"name",
"by",
"removing",
"id",
"from",
"the",
"name",
"and",
"camel",
"casing"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/BelongsTo.php#L212-L219 |
30,818 | BKWLD/decoy | classes/Input/NestedModels.php | NestedModels.relateTo | public function relateTo($model)
{
// Vars
$relation_attributes = [];
$input = Decoy::filteredInput();
// Loop through the input, looking for relationships
foreach ($input as $name => $data) {
if (!$relation = $this->makeRelation($model, $name, $data)) {
continue;
}
$relation_attributes[] = $name;
// Write child data when the model is saved. Because of how the saved
// listener works, we need to explicitly make sure the saved model is
// the one whose data we're parsing.
$model::saved(function ($saved_model) use ($model, $relation, $name, $data) {
if ($model != $saved_model) {
return;
}
$this->writeOnSaved($relation, $name, $data);
});
}
// Returning all input without the related attribtues
return array_except($input, $relation_attributes);
} | php | public function relateTo($model)
{
// Vars
$relation_attributes = [];
$input = Decoy::filteredInput();
// Loop through the input, looking for relationships
foreach ($input as $name => $data) {
if (!$relation = $this->makeRelation($model, $name, $data)) {
continue;
}
$relation_attributes[] = $name;
// Write child data when the model is saved. Because of how the saved
// listener works, we need to explicitly make sure the saved model is
// the one whose data we're parsing.
$model::saved(function ($saved_model) use ($model, $relation, $name, $data) {
if ($model != $saved_model) {
return;
}
$this->writeOnSaved($relation, $name, $data);
});
}
// Returning all input without the related attribtues
return array_except($input, $relation_attributes);
} | [
"public",
"function",
"relateTo",
"(",
"$",
"model",
")",
"{",
"// Vars",
"$",
"relation_attributes",
"=",
"[",
"]",
";",
"$",
"input",
"=",
"Decoy",
"::",
"filteredInput",
"(",
")",
";",
"// Loop through the input, looking for relationships",
"foreach",
"(",
"$",
"input",
"as",
"$",
"name",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"$",
"relation",
"=",
"$",
"this",
"->",
"makeRelation",
"(",
"$",
"model",
",",
"$",
"name",
",",
"$",
"data",
")",
")",
"{",
"continue",
";",
"}",
"$",
"relation_attributes",
"[",
"]",
"=",
"$",
"name",
";",
"// Write child data when the model is saved. Because of how the saved",
"// listener works, we need to explicitly make sure the saved model is",
"// the one whose data we're parsing.",
"$",
"model",
"::",
"saved",
"(",
"function",
"(",
"$",
"saved_model",
")",
"use",
"(",
"$",
"model",
",",
"$",
"relation",
",",
"$",
"name",
",",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"model",
"!=",
"$",
"saved_model",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"writeOnSaved",
"(",
"$",
"relation",
",",
"$",
"name",
",",
"$",
"data",
")",
";",
"}",
")",
";",
"}",
"// Returning all input without the related attribtues",
"return",
"array_except",
"(",
"$",
"input",
",",
"$",
"relation_attributes",
")",
";",
"}"
] | Check the input for related models data. Remove it from the input if it
exists. And then listen for the model to be saved and write the related
models.
@param Eloquent\Model $model
@return array The input with attributes that were relations removed | [
"Check",
"the",
"input",
"for",
"related",
"models",
"data",
".",
"Remove",
"it",
"from",
"the",
"input",
"if",
"it",
"exists",
".",
"And",
"then",
"listen",
"for",
"the",
"model",
"to",
"be",
"saved",
"and",
"write",
"the",
"related",
"models",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/NestedModels.php#L29-L55 |
30,819 | BKWLD/decoy | classes/Input/NestedModels.php | NestedModels.makeRelation | protected function makeRelation($model, $name, $data)
{
// The data must be an array and must contain arrays
if (!is_array($data)
|| empty($data)
|| count(array_filter($data, function ($child) {
return !is_array($child);
}))) {
return false;
}
// The input name should be a function defined on the model.
if (!method_exists($model, $name)) {
return false;
}
// Check if the running the function actually returns a relationship
$relation = $model->$name();
if (!is_a($relation, Relation::class)) {
return false;
}
// Return the relationship object
return $relation;
} | php | protected function makeRelation($model, $name, $data)
{
// The data must be an array and must contain arrays
if (!is_array($data)
|| empty($data)
|| count(array_filter($data, function ($child) {
return !is_array($child);
}))) {
return false;
}
// The input name should be a function defined on the model.
if (!method_exists($model, $name)) {
return false;
}
// Check if the running the function actually returns a relationship
$relation = $model->$name();
if (!is_a($relation, Relation::class)) {
return false;
}
// Return the relationship object
return $relation;
} | [
"protected",
"function",
"makeRelation",
"(",
"$",
"model",
",",
"$",
"name",
",",
"$",
"data",
")",
"{",
"// The data must be an array and must contain arrays",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
"||",
"empty",
"(",
"$",
"data",
")",
"||",
"count",
"(",
"array_filter",
"(",
"$",
"data",
",",
"function",
"(",
"$",
"child",
")",
"{",
"return",
"!",
"is_array",
"(",
"$",
"child",
")",
";",
"}",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"// The input name should be a function defined on the model.",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"model",
",",
"$",
"name",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Check if the running the function actually returns a relationship",
"$",
"relation",
"=",
"$",
"model",
"->",
"$",
"name",
"(",
")",
";",
"if",
"(",
"!",
"is_a",
"(",
"$",
"relation",
",",
"Relation",
"::",
"class",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Return the relationship object",
"return",
"$",
"relation",
";",
"}"
] | Check if the input is a relation and, if it is, return the relationship
object
@param Model $model
@param string $name The input name, like from <input name="$name">, which
is also the naem of the relationship function.
@param mixed $data
@return false|Relation | [
"Check",
"if",
"the",
"input",
"is",
"a",
"relation",
"and",
"if",
"it",
"is",
"return",
"the",
"relationship",
"object"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/NestedModels.php#L67-L91 |
30,820 | BKWLD/decoy | classes/Input/NestedModels.php | NestedModels.storeChild | protected function storeChild($relation, $input, $prefix)
{
$child = $relation->getRelated()->newInstance();
$child->fill($input);
$rules = $this->getRules($relation, $input);
(new ModelValidator)->validateAndPrefixErrors($prefix, $child, $rules);
$relation->save($child);
} | php | protected function storeChild($relation, $input, $prefix)
{
$child = $relation->getRelated()->newInstance();
$child->fill($input);
$rules = $this->getRules($relation, $input);
(new ModelValidator)->validateAndPrefixErrors($prefix, $child, $rules);
$relation->save($child);
} | [
"protected",
"function",
"storeChild",
"(",
"$",
"relation",
",",
"$",
"input",
",",
"$",
"prefix",
")",
"{",
"$",
"child",
"=",
"$",
"relation",
"->",
"getRelated",
"(",
")",
"->",
"newInstance",
"(",
")",
";",
"$",
"child",
"->",
"fill",
"(",
"$",
"input",
")",
";",
"$",
"rules",
"=",
"$",
"this",
"->",
"getRules",
"(",
"$",
"relation",
",",
"$",
"input",
")",
";",
"(",
"new",
"ModelValidator",
")",
"->",
"validateAndPrefixErrors",
"(",
"$",
"prefix",
",",
"$",
"child",
",",
"$",
"rules",
")",
";",
"$",
"relation",
"->",
"save",
"(",
"$",
"child",
")",
";",
"}"
] | Create a new child record
@param Relation $relation
@param array $input The data for the nested model
@param string $prefix The input name prefix, for validation
@return void | [
"Create",
"a",
"new",
"child",
"record"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/NestedModels.php#L124-L131 |
30,821 | BKWLD/decoy | classes/Input/NestedModels.php | NestedModels.updateChild | protected function updateChild($relation, $id, $input, $prefix)
{
$child = $relation->getRelated()->findOrFail($id);
$child->fill($input);
$rules = $this->getRules($relation, $input);
(new ModelValidator)->validateAndPrefixErrors($prefix, $child, $rules);
$child->save();
} | php | protected function updateChild($relation, $id, $input, $prefix)
{
$child = $relation->getRelated()->findOrFail($id);
$child->fill($input);
$rules = $this->getRules($relation, $input);
(new ModelValidator)->validateAndPrefixErrors($prefix, $child, $rules);
$child->save();
} | [
"protected",
"function",
"updateChild",
"(",
"$",
"relation",
",",
"$",
"id",
",",
"$",
"input",
",",
"$",
"prefix",
")",
"{",
"$",
"child",
"=",
"$",
"relation",
"->",
"getRelated",
"(",
")",
"->",
"findOrFail",
"(",
"$",
"id",
")",
";",
"$",
"child",
"->",
"fill",
"(",
"$",
"input",
")",
";",
"$",
"rules",
"=",
"$",
"this",
"->",
"getRules",
"(",
"$",
"relation",
",",
"$",
"input",
")",
";",
"(",
"new",
"ModelValidator",
")",
"->",
"validateAndPrefixErrors",
"(",
"$",
"prefix",
",",
"$",
"child",
",",
"$",
"rules",
")",
";",
"$",
"child",
"->",
"save",
"(",
")",
";",
"}"
] | Update an existing child record
@param Relation $relation
@param integer $id
@param array $input The data for the nested model
@param string $prefix The input name prefix, for validation
@return void | [
"Update",
"an",
"existing",
"child",
"record"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/NestedModels.php#L142-L149 |
30,822 | BKWLD/decoy | classes/Input/NestedModels.php | NestedModels.getRules | public function getRules($relation, $input)
{
$child = $relation->getRelated();
// If nested is not an Image, don't do anything special. This will result
// in the default validation behavior which gets the rules off of the child.
if (!is_a($child, Image::class)) {
return;
}
// Check for image rules on the parent
$parent = $relation->getParent();
$rules_key = 'images.' . ($input['name'] ?: 'default');
if (!array_key_exists($rules_key, $parent::$rules)) {
return;
}
// Return the parent rules concatenated on the default rules for an Image
// (those are essentially hardcoded here but I don't expect them to change)
return [
'file' => 'image|' . $parent::$rules[$rules_key],
];
} | php | public function getRules($relation, $input)
{
$child = $relation->getRelated();
// If nested is not an Image, don't do anything special. This will result
// in the default validation behavior which gets the rules off of the child.
if (!is_a($child, Image::class)) {
return;
}
// Check for image rules on the parent
$parent = $relation->getParent();
$rules_key = 'images.' . ($input['name'] ?: 'default');
if (!array_key_exists($rules_key, $parent::$rules)) {
return;
}
// Return the parent rules concatenated on the default rules for an Image
// (those are essentially hardcoded here but I don't expect them to change)
return [
'file' => 'image|' . $parent::$rules[$rules_key],
];
} | [
"public",
"function",
"getRules",
"(",
"$",
"relation",
",",
"$",
"input",
")",
"{",
"$",
"child",
"=",
"$",
"relation",
"->",
"getRelated",
"(",
")",
";",
"// If nested is not an Image, don't do anything special. This will result",
"// in the default validation behavior which gets the rules off of the child.",
"if",
"(",
"!",
"is_a",
"(",
"$",
"child",
",",
"Image",
"::",
"class",
")",
")",
"{",
"return",
";",
"}",
"// Check for image rules on the parent",
"$",
"parent",
"=",
"$",
"relation",
"->",
"getParent",
"(",
")",
";",
"$",
"rules_key",
"=",
"'images.'",
".",
"(",
"$",
"input",
"[",
"'name'",
"]",
"?",
":",
"'default'",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"rules_key",
",",
"$",
"parent",
"::",
"$",
"rules",
")",
")",
"{",
"return",
";",
"}",
"// Return the parent rules concatenated on the default rules for an Image",
"// (those are essentially hardcoded here but I don't expect them to change)",
"return",
"[",
"'file'",
"=>",
"'image|'",
".",
"$",
"parent",
"::",
"$",
"rules",
"[",
"$",
"rules_key",
"]",
",",
"]",
";",
"}"
] | Get the validation rules. They are generally on the child except for
in the special case of Images
@param Relation $relation
@param array $input The data for the nested model
@return array | [
"Get",
"the",
"validation",
"rules",
".",
"They",
"are",
"generally",
"on",
"the",
"child",
"except",
"for",
"in",
"the",
"special",
"case",
"of",
"Images"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/NestedModels.php#L159-L181 |
30,823 | BKWLD/decoy | classes/Fields/ManyToManyChecklist.php | ManyToManyChecklist.getRelations | public function getRelations()
{
$class = ucfirst('App\\'.ucfirst(Str::singular($this->name)));
$query = call_user_func([$class, 'ordered']);
if ($this->scope) {
call_user_func($this->scope, $query);
}
return $query->get();
} | php | public function getRelations()
{
$class = ucfirst('App\\'.ucfirst(Str::singular($this->name)));
$query = call_user_func([$class, 'ordered']);
if ($this->scope) {
call_user_func($this->scope, $query);
}
return $query->get();
} | [
"public",
"function",
"getRelations",
"(",
")",
"{",
"$",
"class",
"=",
"ucfirst",
"(",
"'App\\\\'",
".",
"ucfirst",
"(",
"Str",
"::",
"singular",
"(",
"$",
"this",
"->",
"name",
")",
")",
")",
";",
"$",
"query",
"=",
"call_user_func",
"(",
"[",
"$",
"class",
",",
"'ordered'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"scope",
")",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"scope",
",",
"$",
"query",
")",
";",
"}",
"return",
"$",
"query",
"->",
"get",
"(",
")",
";",
"}"
] | Get all the options in the related table. Each will become a checkbox.
@return Illuminate\Database\Eloquent\Collection | [
"Get",
"all",
"the",
"options",
"in",
"the",
"related",
"table",
".",
"Each",
"will",
"become",
"a",
"checkbox",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/ManyToManyChecklist.php#L104-L114 |
30,824 | BKWLD/decoy | classes/Fields/ManyToManyChecklist.php | ManyToManyChecklist.generateBox | protected function generateBox($row)
{
return [
'name' => $this->boxName(),
'value' => $row->getKey(),
'checked' => ($children = $this->children())
&& $children->contains($row->getKey()),
// Former is giving these a class of "form-control" which isn't correct
'class' => false,
// Add the model instance so the decorator can use it
'model' => $row,
];
} | php | protected function generateBox($row)
{
return [
'name' => $this->boxName(),
'value' => $row->getKey(),
'checked' => ($children = $this->children())
&& $children->contains($row->getKey()),
// Former is giving these a class of "form-control" which isn't correct
'class' => false,
// Add the model instance so the decorator can use it
'model' => $row,
];
} | [
"protected",
"function",
"generateBox",
"(",
"$",
"row",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"boxName",
"(",
")",
",",
"'value'",
"=>",
"$",
"row",
"->",
"getKey",
"(",
")",
",",
"'checked'",
"=>",
"(",
"$",
"children",
"=",
"$",
"this",
"->",
"children",
"(",
")",
")",
"&&",
"$",
"children",
"->",
"contains",
"(",
"$",
"row",
"->",
"getKey",
"(",
")",
")",
",",
"// Former is giving these a class of \"form-control\" which isn't correct",
"'class'",
"=>",
"false",
",",
"// Add the model instance so the decorator can use it",
"'model'",
"=>",
"$",
"row",
",",
"]",
";",
"}"
] | Take a model instance and generate a checkbox for it
@param Illuminate\Database\Eloquent\Model $row
@return array Configuration that is used by Former for a checkbox | [
"Take",
"a",
"model",
"instance",
"and",
"generate",
"a",
"checkbox",
"for",
"it"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/ManyToManyChecklist.php#L133-L147 |
30,825 | BKWLD/decoy | classes/Fields/ManyToManyChecklist.php | ManyToManyChecklist.generateBoxLabel | protected function generateBoxLabel($row)
{
// Generate the title
$html = '<span class="title">'.$row->getAdminTitleHtmlAttribute().'</span>';
// Add link to edit
$url = '/'.Config::get('decoy.core.dir').'/'.Str::snake($this->name, '-')
.'/'.$row->getKey().'/edit';
if (app('decoy.user')->can('update', $url)) {
$html .= '<a href="'.$url.'"><span class="glyphicon glyphicon-pencil edit"></span></a>';
}
// The str_replace fixes Former's auto conversion of underscores into spaces.
$html = str_replace('_', '_', $html);
return $html;
} | php | protected function generateBoxLabel($row)
{
// Generate the title
$html = '<span class="title">'.$row->getAdminTitleHtmlAttribute().'</span>';
// Add link to edit
$url = '/'.Config::get('decoy.core.dir').'/'.Str::snake($this->name, '-')
.'/'.$row->getKey().'/edit';
if (app('decoy.user')->can('update', $url)) {
$html .= '<a href="'.$url.'"><span class="glyphicon glyphicon-pencil edit"></span></a>';
}
// The str_replace fixes Former's auto conversion of underscores into spaces.
$html = str_replace('_', '_', $html);
return $html;
} | [
"protected",
"function",
"generateBoxLabel",
"(",
"$",
"row",
")",
"{",
"// Generate the title",
"$",
"html",
"=",
"'<span class=\"title\">'",
".",
"$",
"row",
"->",
"getAdminTitleHtmlAttribute",
"(",
")",
".",
"'</span>'",
";",
"// Add link to edit",
"$",
"url",
"=",
"'/'",
".",
"Config",
"::",
"get",
"(",
"'decoy.core.dir'",
")",
".",
"'/'",
".",
"Str",
"::",
"snake",
"(",
"$",
"this",
"->",
"name",
",",
"'-'",
")",
".",
"'/'",
".",
"$",
"row",
"->",
"getKey",
"(",
")",
".",
"'/edit'",
";",
"if",
"(",
"app",
"(",
"'decoy.user'",
")",
"->",
"can",
"(",
"'update'",
",",
"$",
"url",
")",
")",
"{",
"$",
"html",
".=",
"'<a href=\"'",
".",
"$",
"url",
".",
"'\"><span class=\"glyphicon glyphicon-pencil edit\"></span></a>'",
";",
"}",
"// The str_replace fixes Former's auto conversion of underscores into spaces.",
"$",
"html",
"=",
"str_replace",
"(",
"'_'",
",",
"'_'",
",",
"$",
"html",
")",
";",
"return",
"$",
"html",
";",
"}"
] | Create the HTML label for a checkbox
@param Illuminate\Database\Eloquent\Model $row
@return string HTML | [
"Create",
"the",
"HTML",
"label",
"for",
"a",
"checkbox"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/ManyToManyChecklist.php#L155-L171 |
30,826 | BKWLD/decoy | classes/Fields/ManyToManyChecklist.php | ManyToManyChecklist.children | protected function children()
{
if (($item = $this->getModel()) && method_exists($item, $this->name)) {
return $item->{$this->name};
}
} | php | protected function children()
{
if (($item = $this->getModel()) && method_exists($item, $this->name)) {
return $item->{$this->name};
}
} | [
"protected",
"function",
"children",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"item",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
")",
"&&",
"method_exists",
"(",
"$",
"item",
",",
"$",
"this",
"->",
"name",
")",
")",
"{",
"return",
"$",
"item",
"->",
"{",
"$",
"this",
"->",
"name",
"}",
";",
"}",
"}"
] | Get a collection of all the children that are already associated with the parent
@return Illuminate\Database\Eloquent\Collection | [
"Get",
"a",
"collection",
"of",
"all",
"the",
"children",
"that",
"are",
"already",
"associated",
"with",
"the",
"parent"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/ManyToManyChecklist.php#L178-L183 |
30,827 | BKWLD/decoy | classes/Fields/ManyToManyChecklist.php | ManyToManyChecklist.createCheckable | protected function createCheckable($item, $fallbackValue = 1)
{
// Get the model reference out of the item and remove it before it's
// rendered. Otherwise it gets created as a data atrribute
$model = $item['attributes']['model'];
unset($item['attributes']['model']);
// Render the checkbox as per normal
$html = parent::createCheckable($item, $fallbackValue);
// Mutate a checkable using user defined
if ($this->decorator) {
$html = call_user_func($this->decorator, $html, $model);
}
// Return html
return $html;
} | php | protected function createCheckable($item, $fallbackValue = 1)
{
// Get the model reference out of the item and remove it before it's
// rendered. Otherwise it gets created as a data atrribute
$model = $item['attributes']['model'];
unset($item['attributes']['model']);
// Render the checkbox as per normal
$html = parent::createCheckable($item, $fallbackValue);
// Mutate a checkable using user defined
if ($this->decorator) {
$html = call_user_func($this->decorator, $html, $model);
}
// Return html
return $html;
} | [
"protected",
"function",
"createCheckable",
"(",
"$",
"item",
",",
"$",
"fallbackValue",
"=",
"1",
")",
"{",
"// Get the model reference out of the item and remove it before it's",
"// rendered. Otherwise it gets created as a data atrribute",
"$",
"model",
"=",
"$",
"item",
"[",
"'attributes'",
"]",
"[",
"'model'",
"]",
";",
"unset",
"(",
"$",
"item",
"[",
"'attributes'",
"]",
"[",
"'model'",
"]",
")",
";",
"// Render the checkbox as per normal",
"$",
"html",
"=",
"parent",
"::",
"createCheckable",
"(",
"$",
"item",
",",
"$",
"fallbackValue",
")",
";",
"// Mutate a checkable using user defined",
"if",
"(",
"$",
"this",
"->",
"decorator",
")",
"{",
"$",
"html",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"decorator",
",",
"$",
"html",
",",
"$",
"model",
")",
";",
"}",
"// Return html",
"return",
"$",
"html",
";",
"}"
] | Renders a checkable. This overrides the Former subclass so we can decorate
each individual `.checkbox`div.
@param string|array $item A checkable item
@param integer $fallbackValue A fallback value if none is set
@return string | [
"Renders",
"a",
"checkable",
".",
"This",
"overrides",
"the",
"Former",
"subclass",
"so",
"we",
"can",
"decorate",
"each",
"individual",
".",
"checkbox",
"div",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/ManyToManyChecklist.php#L194-L211 |
30,828 | BKWLD/decoy | classes/Observers/ValidateExistingFiles.php | ValidateExistingFiles.onValidating | public function onValidating($event, $payload)
{
// Destructure payload
list($model, $validation) = $payload;
// Only act on locally hosted files
if (config('upchuck.disk.driver') != 'local') {
return;
}
// Get all the file related rules
// https://regex101.com/r/oP4kD2/1
$rules = array_filter($validation->getRules(), function ($rules) {
foreach ($rules as $rule) {
if (preg_match('#^(image|file|video|mimes|dimensions)#', $rule)) {
return true;
}
}
});
// For each of the file rules, if the input has a value, make a file
// instance for it if it's a local path.
$data = $validation->getData();
foreach (array_keys($rules) as $attribute) {
$value = array_get($data, $attribute);
// Skip if the attribute isn't in the input. It may not be for
// images or other nested models. Their validation should get
// triggered later through NestedModels behavior.
if (!array_has($data, $attribute)) {
continue;
// Skip if a file was uploaded for this attribtue
} else if (is_a($value, File::class)) {
continue;
// If the value is empty, because the user is deleting the file
// instance, set it to an empty string instead of the default
// (null). Null requires `nullable` validation rules to be set
// and I don't want to require that.
} else if (!$value) {
array_set($data, $attribute, '');
// Create the file instance and clear the data instance
} else {
array_set($data, $attribute, $this->makeFileFromPath($value));
}
}
// Replace the files and data with the updated set. `setData()` expects
// the data to contain files in it. But `getData()` strips out the
// files. Thus, they need to be merged back in before being set.
$validation->setData(array_merge($data));
} | php | public function onValidating($event, $payload)
{
// Destructure payload
list($model, $validation) = $payload;
// Only act on locally hosted files
if (config('upchuck.disk.driver') != 'local') {
return;
}
// Get all the file related rules
// https://regex101.com/r/oP4kD2/1
$rules = array_filter($validation->getRules(), function ($rules) {
foreach ($rules as $rule) {
if (preg_match('#^(image|file|video|mimes|dimensions)#', $rule)) {
return true;
}
}
});
// For each of the file rules, if the input has a value, make a file
// instance for it if it's a local path.
$data = $validation->getData();
foreach (array_keys($rules) as $attribute) {
$value = array_get($data, $attribute);
// Skip if the attribute isn't in the input. It may not be for
// images or other nested models. Their validation should get
// triggered later through NestedModels behavior.
if (!array_has($data, $attribute)) {
continue;
// Skip if a file was uploaded for this attribtue
} else if (is_a($value, File::class)) {
continue;
// If the value is empty, because the user is deleting the file
// instance, set it to an empty string instead of the default
// (null). Null requires `nullable` validation rules to be set
// and I don't want to require that.
} else if (!$value) {
array_set($data, $attribute, '');
// Create the file instance and clear the data instance
} else {
array_set($data, $attribute, $this->makeFileFromPath($value));
}
}
// Replace the files and data with the updated set. `setData()` expects
// the data to contain files in it. But `getData()` strips out the
// files. Thus, they need to be merged back in before being set.
$validation->setData(array_merge($data));
} | [
"public",
"function",
"onValidating",
"(",
"$",
"event",
",",
"$",
"payload",
")",
"{",
"// Destructure payload",
"list",
"(",
"$",
"model",
",",
"$",
"validation",
")",
"=",
"$",
"payload",
";",
"// Only act on locally hosted files",
"if",
"(",
"config",
"(",
"'upchuck.disk.driver'",
")",
"!=",
"'local'",
")",
"{",
"return",
";",
"}",
"// Get all the file related rules",
"// https://regex101.com/r/oP4kD2/1",
"$",
"rules",
"=",
"array_filter",
"(",
"$",
"validation",
"->",
"getRules",
"(",
")",
",",
"function",
"(",
"$",
"rules",
")",
"{",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'#^(image|file|video|mimes|dimensions)#'",
",",
"$",
"rule",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
")",
";",
"// For each of the file rules, if the input has a value, make a file",
"// instance for it if it's a local path.",
"$",
"data",
"=",
"$",
"validation",
"->",
"getData",
"(",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"rules",
")",
"as",
"$",
"attribute",
")",
"{",
"$",
"value",
"=",
"array_get",
"(",
"$",
"data",
",",
"$",
"attribute",
")",
";",
"// Skip if the attribute isn't in the input. It may not be for",
"// images or other nested models. Their validation should get",
"// triggered later through NestedModels behavior.",
"if",
"(",
"!",
"array_has",
"(",
"$",
"data",
",",
"$",
"attribute",
")",
")",
"{",
"continue",
";",
"// Skip if a file was uploaded for this attribtue",
"}",
"else",
"if",
"(",
"is_a",
"(",
"$",
"value",
",",
"File",
"::",
"class",
")",
")",
"{",
"continue",
";",
"// If the value is empty, because the user is deleting the file",
"// instance, set it to an empty string instead of the default",
"// (null). Null requires `nullable` validation rules to be set",
"// and I don't want to require that.",
"}",
"else",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"array_set",
"(",
"$",
"data",
",",
"$",
"attribute",
",",
"''",
")",
";",
"// Create the file instance and clear the data instance",
"}",
"else",
"{",
"array_set",
"(",
"$",
"data",
",",
"$",
"attribute",
",",
"$",
"this",
"->",
"makeFileFromPath",
"(",
"$",
"value",
")",
")",
";",
"}",
"}",
"// Replace the files and data with the updated set. `setData()` expects",
"// the data to contain files in it. But `getData()` strips out the",
"// files. Thus, they need to be merged back in before being set.",
"$",
"validation",
"->",
"setData",
"(",
"array_merge",
"(",
"$",
"data",
")",
")",
";",
"}"
] | Massage validation handling
@param string $event
@param array $payload Contains:
- Bkwld\Decoy\Models\Base
- Illuminate\Validation\Validator
@return void | [
"Massage",
"validation",
"handling"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/ValidateExistingFiles.php#L25-L78 |
30,829 | BKWLD/decoy | classes/Observers/ValidateExistingFiles.php | ValidateExistingFiles.makeFileFromPath | public function makeFileFromPath($path)
{
$upchuck_path = app('upchuck')->path($path);
$absolute_path = config('upchuck.disk.path').'/'.$upchuck_path;
return new UploadedFile(
$absolute_path, basename($absolute_path),
null, null, // Default mime and error
true); // Enable test mode so local file will be pass as uploaded
} | php | public function makeFileFromPath($path)
{
$upchuck_path = app('upchuck')->path($path);
$absolute_path = config('upchuck.disk.path').'/'.$upchuck_path;
return new UploadedFile(
$absolute_path, basename($absolute_path),
null, null, // Default mime and error
true); // Enable test mode so local file will be pass as uploaded
} | [
"public",
"function",
"makeFileFromPath",
"(",
"$",
"path",
")",
"{",
"$",
"upchuck_path",
"=",
"app",
"(",
"'upchuck'",
")",
"->",
"path",
"(",
"$",
"path",
")",
";",
"$",
"absolute_path",
"=",
"config",
"(",
"'upchuck.disk.path'",
")",
".",
"'/'",
".",
"$",
"upchuck_path",
";",
"return",
"new",
"UploadedFile",
"(",
"$",
"absolute_path",
",",
"basename",
"(",
"$",
"absolute_path",
")",
",",
"null",
",",
"null",
",",
"// Default mime and error",
"true",
")",
";",
"// Enable test mode so local file will be pass as uploaded",
"}"
] | Make an UploadedFile instance using Upchuck from the string input value
@param string $path
@return UploadedFile | [
"Make",
"an",
"UploadedFile",
"instance",
"using",
"Upchuck",
"from",
"the",
"string",
"input",
"value"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/ValidateExistingFiles.php#L86-L94 |
30,830 | BKWLD/decoy | classes/Models/Worker.php | Worker.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
if ($this->option('worker')) {
return $this->worker();
}
if ($this->option('cron')) {
return $this->cron();
}
if ($this->option('heartbeat')) {
return $this->heartbeat();
}
return parent::execute($input, $output);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
if ($this->option('worker')) {
return $this->worker();
}
if ($this->option('cron')) {
return $this->cron();
}
if ($this->option('heartbeat')) {
return $this->heartbeat();
}
return parent::execute($input, $output);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"option",
"(",
"'worker'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"worker",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"option",
"(",
"'cron'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"cron",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"option",
"(",
"'heartbeat'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"heartbeat",
"(",
")",
";",
"}",
"return",
"parent",
"::",
"execute",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"}"
] | Tap into the Laravel method that invokes the fire command to check for and
act on options | [
"Tap",
"into",
"the",
"Laravel",
"method",
"that",
"invokes",
"the",
"fire",
"command",
"to",
"check",
"for",
"and",
"act",
"on",
"options"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L63-L78 |
30,831 | BKWLD/decoy | classes/Models/Worker.php | Worker.heartbeat | protected function heartbeat()
{
// Update the heartbeat
$last = Cache::get($this->HEARTBEAT_CRON_KEY);
if (empty($last->interval)) {
$interval = 'calculating';
} else {
$interval = time() - $last->time;
}
Cache::forever($this->HEARTBEAT_CRON_KEY, (object) [
'time' => time(),
'interval' => $interval,
]);
// The worker has died
if (!$this->isRunning()) {
// Log an error that the worker stopped
$this->addLogging();
$this->error('The '.$this->name.' worker has stopped');
// Do work (since the worker has stopped)
$this->fire();
// The worker appears to be fine
} else {
$this->info('The '.$this->name.' worker is running');
}
} | php | protected function heartbeat()
{
// Update the heartbeat
$last = Cache::get($this->HEARTBEAT_CRON_KEY);
if (empty($last->interval)) {
$interval = 'calculating';
} else {
$interval = time() - $last->time;
}
Cache::forever($this->HEARTBEAT_CRON_KEY, (object) [
'time' => time(),
'interval' => $interval,
]);
// The worker has died
if (!$this->isRunning()) {
// Log an error that the worker stopped
$this->addLogging();
$this->error('The '.$this->name.' worker has stopped');
// Do work (since the worker has stopped)
$this->fire();
// The worker appears to be fine
} else {
$this->info('The '.$this->name.' worker is running');
}
} | [
"protected",
"function",
"heartbeat",
"(",
")",
"{",
"// Update the heartbeat",
"$",
"last",
"=",
"Cache",
"::",
"get",
"(",
"$",
"this",
"->",
"HEARTBEAT_CRON_KEY",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"last",
"->",
"interval",
")",
")",
"{",
"$",
"interval",
"=",
"'calculating'",
";",
"}",
"else",
"{",
"$",
"interval",
"=",
"time",
"(",
")",
"-",
"$",
"last",
"->",
"time",
";",
"}",
"Cache",
"::",
"forever",
"(",
"$",
"this",
"->",
"HEARTBEAT_CRON_KEY",
",",
"(",
"object",
")",
"[",
"'time'",
"=>",
"time",
"(",
")",
",",
"'interval'",
"=>",
"$",
"interval",
",",
"]",
")",
";",
"// The worker has died",
"if",
"(",
"!",
"$",
"this",
"->",
"isRunning",
"(",
")",
")",
"{",
"// Log an error that the worker stopped",
"$",
"this",
"->",
"addLogging",
"(",
")",
";",
"$",
"this",
"->",
"error",
"(",
"'The '",
".",
"$",
"this",
"->",
"name",
".",
"' worker has stopped'",
")",
";",
"// Do work (since the worker has stopped)",
"$",
"this",
"->",
"fire",
"(",
")",
";",
"// The worker appears to be fine",
"}",
"else",
"{",
"$",
"this",
"->",
"info",
"(",
"'The '",
".",
"$",
"this",
"->",
"name",
".",
"' worker is running'",
")",
";",
"}",
"}"
] | This heartbeat function is called by cron to verify that the worker is still running | [
"This",
"heartbeat",
"function",
"is",
"called",
"by",
"cron",
"to",
"verify",
"that",
"the",
"worker",
"is",
"still",
"running"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L124-L153 |
30,832 | BKWLD/decoy | classes/Models/Worker.php | Worker.log | public function log($level, $message, $context = [])
{
// This will be empty when output messages are triggered by the command
// when it's NOT called by a worker option
if (empty($this->logger)) {
return;
}
// Call the logger's level specific methods
$method = 'add'.ucfirst($level);
$this->logger->$method($message, $context);
} | php | public function log($level, $message, $context = [])
{
// This will be empty when output messages are triggered by the command
// when it's NOT called by a worker option
if (empty($this->logger)) {
return;
}
// Call the logger's level specific methods
$method = 'add'.ucfirst($level);
$this->logger->$method($message, $context);
} | [
"public",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"// This will be empty when output messages are triggered by the command",
"// when it's NOT called by a worker option",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"logger",
")",
")",
"{",
"return",
";",
"}",
"// Call the logger's level specific methods",
"$",
"method",
"=",
"'add'",
".",
"ucfirst",
"(",
"$",
"level",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"$",
"method",
"(",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Write Command output types to the log
@param $level
@param $message
@param array $context | [
"Write",
"Command",
"output",
"types",
"to",
"the",
"log"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L188-L199 |
30,833 | BKWLD/decoy | classes/Models/Worker.php | Worker.all | public static function all()
{
$output = array();
$namespaced = Command::allCustom();
foreach ($namespaced as $namespace => $commands) {
foreach ($commands as $title => $command) {
if (is_a($command, 'Bkwld\Decoy\Models\Worker')) {
$output[] = $command;
}
}
}
return $output;
} | php | public static function all()
{
$output = array();
$namespaced = Command::allCustom();
foreach ($namespaced as $namespace => $commands) {
foreach ($commands as $title => $command) {
if (is_a($command, 'Bkwld\Decoy\Models\Worker')) {
$output[] = $command;
}
}
}
return $output;
} | [
"public",
"static",
"function",
"all",
"(",
")",
"{",
"$",
"output",
"=",
"array",
"(",
")",
";",
"$",
"namespaced",
"=",
"Command",
"::",
"allCustom",
"(",
")",
";",
"foreach",
"(",
"$",
"namespaced",
"as",
"$",
"namespace",
"=>",
"$",
"commands",
")",
"{",
"foreach",
"(",
"$",
"commands",
"as",
"$",
"title",
"=>",
"$",
"command",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"command",
",",
"'Bkwld\\Decoy\\Models\\Worker'",
")",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"command",
";",
"}",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] | Get all the tasks that have workers | [
"Get",
"all",
"the",
"tasks",
"that",
"have",
"workers"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L227-L240 |
30,834 | BKWLD/decoy | classes/Models/Worker.php | Worker.lastHeartbeatCheck | public function lastHeartbeatCheck()
{
$check = Cache::get($this->HEARTBEAT_CRON_KEY);
if (empty($check)) {
return 'never';
}
return date(Library\Utils\Constants::COMMON_DATETIME.' T', $check->time);
} | php | public function lastHeartbeatCheck()
{
$check = Cache::get($this->HEARTBEAT_CRON_KEY);
if (empty($check)) {
return 'never';
}
return date(Library\Utils\Constants::COMMON_DATETIME.' T', $check->time);
} | [
"public",
"function",
"lastHeartbeatCheck",
"(",
")",
"{",
"$",
"check",
"=",
"Cache",
"::",
"get",
"(",
"$",
"this",
"->",
"HEARTBEAT_CRON_KEY",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"check",
")",
")",
"{",
"return",
"'never'",
";",
"}",
"return",
"date",
"(",
"Library",
"\\",
"Utils",
"\\",
"Constants",
"::",
"COMMON_DATETIME",
".",
"' T'",
",",
"$",
"check",
"->",
"time",
")",
";",
"}"
] | Last time the heartbeat was checked | [
"Last",
"time",
"the",
"heartbeat",
"was",
"checked"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L253-L261 |
30,835 | BKWLD/decoy | classes/Models/Worker.php | Worker.lastHeartbeat | public function lastHeartbeat()
{
$check = Cache::get($this->HEARTBEAT_WORKER_KEY);
if (empty($check)) {
return 'never';
}
return date(Library\Utils\Constants::COMMON_DATETIME.' T', $check);
} | php | public function lastHeartbeat()
{
$check = Cache::get($this->HEARTBEAT_WORKER_KEY);
if (empty($check)) {
return 'never';
}
return date(Library\Utils\Constants::COMMON_DATETIME.' T', $check);
} | [
"public",
"function",
"lastHeartbeat",
"(",
")",
"{",
"$",
"check",
"=",
"Cache",
"::",
"get",
"(",
"$",
"this",
"->",
"HEARTBEAT_WORKER_KEY",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"check",
")",
")",
"{",
"return",
"'never'",
";",
"}",
"return",
"date",
"(",
"Library",
"\\",
"Utils",
"\\",
"Constants",
"::",
"COMMON_DATETIME",
".",
"' T'",
",",
"$",
"check",
")",
";",
"}"
] | The last time the worker ran | [
"The",
"last",
"time",
"the",
"worker",
"ran"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L266-L274 |
30,836 | BKWLD/decoy | classes/Models/Worker.php | Worker.currentInterval | public function currentInterval($format = null)
{
// Relative time formatting
$abbreviated = [
'pluraling' => false,
'spacing' => false,
'labels' => ['now', 's', 'm', 'h', 'd', 'm', 'y'],
];
// Figure stuff out
if ($this->isRunning()) {
$interval = $this->WORKER_SLEEP_SECS;
} else {
$check = Cache::get($this->HEARTBEAT_CRON_KEY);
if (empty($check)) {
$interval = 'uncertain';
} else {
$interval = $check->interval;
}
}
// Format it
if (!is_numeric($interval)) {
return $interval;
}
switch ($format) {
case 'raw':
return $interval;
case 'abbreviated':
return Library\Utils\Text::timeElapsed(time() - $interval, $abbreviated);
default:
return Library\Utils\Text::timeElapsed(time() - $interval);
}
} | php | public function currentInterval($format = null)
{
// Relative time formatting
$abbreviated = [
'pluraling' => false,
'spacing' => false,
'labels' => ['now', 's', 'm', 'h', 'd', 'm', 'y'],
];
// Figure stuff out
if ($this->isRunning()) {
$interval = $this->WORKER_SLEEP_SECS;
} else {
$check = Cache::get($this->HEARTBEAT_CRON_KEY);
if (empty($check)) {
$interval = 'uncertain';
} else {
$interval = $check->interval;
}
}
// Format it
if (!is_numeric($interval)) {
return $interval;
}
switch ($format) {
case 'raw':
return $interval;
case 'abbreviated':
return Library\Utils\Text::timeElapsed(time() - $interval, $abbreviated);
default:
return Library\Utils\Text::timeElapsed(time() - $interval);
}
} | [
"public",
"function",
"currentInterval",
"(",
"$",
"format",
"=",
"null",
")",
"{",
"// Relative time formatting",
"$",
"abbreviated",
"=",
"[",
"'pluraling'",
"=>",
"false",
",",
"'spacing'",
"=>",
"false",
",",
"'labels'",
"=>",
"[",
"'now'",
",",
"'s'",
",",
"'m'",
",",
"'h'",
",",
"'d'",
",",
"'m'",
",",
"'y'",
"]",
",",
"]",
";",
"// Figure stuff out",
"if",
"(",
"$",
"this",
"->",
"isRunning",
"(",
")",
")",
"{",
"$",
"interval",
"=",
"$",
"this",
"->",
"WORKER_SLEEP_SECS",
";",
"}",
"else",
"{",
"$",
"check",
"=",
"Cache",
"::",
"get",
"(",
"$",
"this",
"->",
"HEARTBEAT_CRON_KEY",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"check",
")",
")",
"{",
"$",
"interval",
"=",
"'uncertain'",
";",
"}",
"else",
"{",
"$",
"interval",
"=",
"$",
"check",
"->",
"interval",
";",
"}",
"}",
"// Format it",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"interval",
")",
")",
"{",
"return",
"$",
"interval",
";",
"}",
"switch",
"(",
"$",
"format",
")",
"{",
"case",
"'raw'",
":",
"return",
"$",
"interval",
";",
"case",
"'abbreviated'",
":",
"return",
"Library",
"\\",
"Utils",
"\\",
"Text",
"::",
"timeElapsed",
"(",
"time",
"(",
")",
"-",
"$",
"interval",
",",
"$",
"abbreviated",
")",
";",
"default",
":",
"return",
"Library",
"\\",
"Utils",
"\\",
"Text",
"::",
"timeElapsed",
"(",
"time",
"(",
")",
"-",
"$",
"interval",
")",
";",
"}",
"}"
] | The current interval that heartbeats are running at | [
"The",
"current",
"interval",
"that",
"heartbeats",
"are",
"running",
"at"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L279-L315 |
30,837 | BKWLD/decoy | classes/Layout/Nav.php | Nav.generate | public function generate()
{
// Get the navigation pages from the config
$pages = Config::get('decoy.site.nav');
if (is_callable($pages)) {
$pages = call_user_func($pages);
}
// Loop through the list of pages and massage
$massaged = [];
foreach ($pages as $key => $val) {
// If val is an array, make a drop down menu
if (is_array($val)) {
// Create a new page instance that represents the dropdown menu
$page = ['active' => false];
$page = array_merge($page, $this->makeIcon($key));
$page['children'] = [];
// Loop through children (we only support one level deep) and
// add each as a child
foreach ($val as $child_key => $child_val) {
$page['children'][] = $this->makePage($child_key, $child_val);
}
// See if any of the children are active and set the pulldown to active
foreach ($page['children'] as $child) {
if (!empty($child->active)) {
$page['active'] = true;
break;
}
}
// Add the pulldown to the list of pages
$massaged[] = (object) $page;
// The page is a simple (non pulldown) link
} else {
$massaged[] = $this->makePage($key, $val);
}
}
// Pass along the navigation data
return $massaged;
} | php | public function generate()
{
// Get the navigation pages from the config
$pages = Config::get('decoy.site.nav');
if (is_callable($pages)) {
$pages = call_user_func($pages);
}
// Loop through the list of pages and massage
$massaged = [];
foreach ($pages as $key => $val) {
// If val is an array, make a drop down menu
if (is_array($val)) {
// Create a new page instance that represents the dropdown menu
$page = ['active' => false];
$page = array_merge($page, $this->makeIcon($key));
$page['children'] = [];
// Loop through children (we only support one level deep) and
// add each as a child
foreach ($val as $child_key => $child_val) {
$page['children'][] = $this->makePage($child_key, $child_val);
}
// See if any of the children are active and set the pulldown to active
foreach ($page['children'] as $child) {
if (!empty($child->active)) {
$page['active'] = true;
break;
}
}
// Add the pulldown to the list of pages
$massaged[] = (object) $page;
// The page is a simple (non pulldown) link
} else {
$massaged[] = $this->makePage($key, $val);
}
}
// Pass along the navigation data
return $massaged;
} | [
"public",
"function",
"generate",
"(",
")",
"{",
"// Get the navigation pages from the config",
"$",
"pages",
"=",
"Config",
"::",
"get",
"(",
"'decoy.site.nav'",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"pages",
")",
")",
"{",
"$",
"pages",
"=",
"call_user_func",
"(",
"$",
"pages",
")",
";",
"}",
"// Loop through the list of pages and massage",
"$",
"massaged",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"pages",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"// If val is an array, make a drop down menu",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"// Create a new page instance that represents the dropdown menu",
"$",
"page",
"=",
"[",
"'active'",
"=>",
"false",
"]",
";",
"$",
"page",
"=",
"array_merge",
"(",
"$",
"page",
",",
"$",
"this",
"->",
"makeIcon",
"(",
"$",
"key",
")",
")",
";",
"$",
"page",
"[",
"'children'",
"]",
"=",
"[",
"]",
";",
"// Loop through children (we only support one level deep) and",
"// add each as a child",
"foreach",
"(",
"$",
"val",
"as",
"$",
"child_key",
"=>",
"$",
"child_val",
")",
"{",
"$",
"page",
"[",
"'children'",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"makePage",
"(",
"$",
"child_key",
",",
"$",
"child_val",
")",
";",
"}",
"// See if any of the children are active and set the pulldown to active",
"foreach",
"(",
"$",
"page",
"[",
"'children'",
"]",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"child",
"->",
"active",
")",
")",
"{",
"$",
"page",
"[",
"'active'",
"]",
"=",
"true",
";",
"break",
";",
"}",
"}",
"// Add the pulldown to the list of pages",
"$",
"massaged",
"[",
"]",
"=",
"(",
"object",
")",
"$",
"page",
";",
"// The page is a simple (non pulldown) link",
"}",
"else",
"{",
"$",
"massaged",
"[",
"]",
"=",
"$",
"this",
"->",
"makePage",
"(",
"$",
"key",
",",
"$",
"val",
")",
";",
"}",
"}",
"// Pass along the navigation data",
"return",
"$",
"massaged",
";",
"}"
] | Generate the nav config
@return array | [
"Generate",
"the",
"nav",
"config"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Layout/Nav.php#L18-L63 |
30,838 | BKWLD/decoy | classes/Layout/Nav.php | Nav.makeIcon | protected function makeIcon($label_and_icon)
{
$parts = explode(',', $label_and_icon);
if (count($parts) == 2) {
return ['label' => $parts[0], 'icon' => $parts[1]];
}
return ['label' => $parts[0], 'icon' => 'default'];
} | php | protected function makeIcon($label_and_icon)
{
$parts = explode(',', $label_and_icon);
if (count($parts) == 2) {
return ['label' => $parts[0], 'icon' => $parts[1]];
}
return ['label' => $parts[0], 'icon' => 'default'];
} | [
"protected",
"function",
"makeIcon",
"(",
"$",
"label_and_icon",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"','",
",",
"$",
"label_and_icon",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"==",
"2",
")",
"{",
"return",
"[",
"'label'",
"=>",
"$",
"parts",
"[",
"0",
"]",
",",
"'icon'",
"=>",
"$",
"parts",
"[",
"1",
"]",
"]",
";",
"}",
"return",
"[",
"'label'",
"=>",
"$",
"parts",
"[",
"0",
"]",
",",
"'icon'",
"=>",
"'default'",
"]",
";",
"}"
] | Break the icon out of the label, returning an arary of label and icon | [
"Break",
"the",
"icon",
"out",
"of",
"the",
"label",
"returning",
"an",
"arary",
"of",
"label",
"and",
"icon"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Layout/Nav.php#L68-L76 |
30,839 | BKWLD/decoy | classes/Layout/Nav.php | Nav.makePage | protected function makePage($key, $val)
{
// Check if it's a divider
if ($val === '-') {
return (object) ['divider' => true];
}
// Create a new page
$page = ['url' => $val, 'divider' => false];
$page = array_merge($page, $this->makeIcon($key));
// Check if this item is the currently selected one
$page['active'] = false;
if (strpos(URL::current(), parse_url($page['url'], PHP_URL_PATH))) {
$page['active'] = true;
}
// Return the new page
return (object) $page;
} | php | protected function makePage($key, $val)
{
// Check if it's a divider
if ($val === '-') {
return (object) ['divider' => true];
}
// Create a new page
$page = ['url' => $val, 'divider' => false];
$page = array_merge($page, $this->makeIcon($key));
// Check if this item is the currently selected one
$page['active'] = false;
if (strpos(URL::current(), parse_url($page['url'], PHP_URL_PATH))) {
$page['active'] = true;
}
// Return the new page
return (object) $page;
} | [
"protected",
"function",
"makePage",
"(",
"$",
"key",
",",
"$",
"val",
")",
"{",
"// Check if it's a divider",
"if",
"(",
"$",
"val",
"===",
"'-'",
")",
"{",
"return",
"(",
"object",
")",
"[",
"'divider'",
"=>",
"true",
"]",
";",
"}",
"// Create a new page",
"$",
"page",
"=",
"[",
"'url'",
"=>",
"$",
"val",
",",
"'divider'",
"=>",
"false",
"]",
";",
"$",
"page",
"=",
"array_merge",
"(",
"$",
"page",
",",
"$",
"this",
"->",
"makeIcon",
"(",
"$",
"key",
")",
")",
";",
"// Check if this item is the currently selected one",
"$",
"page",
"[",
"'active'",
"]",
"=",
"false",
";",
"if",
"(",
"strpos",
"(",
"URL",
"::",
"current",
"(",
")",
",",
"parse_url",
"(",
"$",
"page",
"[",
"'url'",
"]",
",",
"PHP_URL_PATH",
")",
")",
")",
"{",
"$",
"page",
"[",
"'active'",
"]",
"=",
"true",
";",
"}",
"// Return the new page",
"return",
"(",
"object",
")",
"$",
"page",
";",
"}"
] | Make a page object
@return object | [
"Make",
"a",
"page",
"object"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Layout/Nav.php#L83-L102 |
30,840 | BKWLD/decoy | classes/Controllers/Commands.php | Commands.execute | public function execute($command_name)
{
// Find it
if (!($command = Command::find($command_name))) {
App::abort(404);
}
// Run it, ignoring all output
set_time_limit(self::MAX_EXECUTION_TIME);
ob_start();
Artisan::call($command->getName());
ob_end_clean();
// Return response
return Response::json('ok');
} | php | public function execute($command_name)
{
// Find it
if (!($command = Command::find($command_name))) {
App::abort(404);
}
// Run it, ignoring all output
set_time_limit(self::MAX_EXECUTION_TIME);
ob_start();
Artisan::call($command->getName());
ob_end_clean();
// Return response
return Response::json('ok');
} | [
"public",
"function",
"execute",
"(",
"$",
"command_name",
")",
"{",
"// Find it",
"if",
"(",
"!",
"(",
"$",
"command",
"=",
"Command",
"::",
"find",
"(",
"$",
"command_name",
")",
")",
")",
"{",
"App",
"::",
"abort",
"(",
"404",
")",
";",
"}",
"// Run it, ignoring all output",
"set_time_limit",
"(",
"self",
"::",
"MAX_EXECUTION_TIME",
")",
";",
"ob_start",
"(",
")",
";",
"Artisan",
"::",
"call",
"(",
"$",
"command",
"->",
"getName",
"(",
")",
")",
";",
"ob_end_clean",
"(",
")",
";",
"// Return response",
"return",
"Response",
"::",
"json",
"(",
"'ok'",
")",
";",
"}"
] | Run one of the commands, designed to be called via AJAX
@return Response | [
"Run",
"one",
"of",
"the",
"commands",
"designed",
"to",
"be",
"called",
"via",
"AJAX"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Commands.php#L49-L64 |
30,841 | BKWLD/decoy | classes/Routing/Wildcard.php | Wildcard.detectAndExecute | public function detectAndExecute()
{
// Get the controller
if (!($controller = $this->detectController())) {
return false;
}
// Get the action
$action = $this->detectAction();
if (!$action || !method_exists($controller, $action)) {
return false;
}
// Get the id
$id = $this->detectId();
// Tell other classes what was found
$event = Event::fire('wildcard.detection', [
$controller, $action, $id
]);
// Instantiate controller
$controller = new $controller();
if ($parent = $this->detectParent()) {
list($parent_slug, $parent_id) = $parent;
$parent_model = 'App\\'.Str::singular(Str::studly($parent_slug));
$controller->parent($parent_model::findOrFail($parent_id));
}
// Execute the request
$params = $id ? [$id] : [];
return $controller->callAction($action, $params);
} | php | public function detectAndExecute()
{
// Get the controller
if (!($controller = $this->detectController())) {
return false;
}
// Get the action
$action = $this->detectAction();
if (!$action || !method_exists($controller, $action)) {
return false;
}
// Get the id
$id = $this->detectId();
// Tell other classes what was found
$event = Event::fire('wildcard.detection', [
$controller, $action, $id
]);
// Instantiate controller
$controller = new $controller();
if ($parent = $this->detectParent()) {
list($parent_slug, $parent_id) = $parent;
$parent_model = 'App\\'.Str::singular(Str::studly($parent_slug));
$controller->parent($parent_model::findOrFail($parent_id));
}
// Execute the request
$params = $id ? [$id] : [];
return $controller->callAction($action, $params);
} | [
"public",
"function",
"detectAndExecute",
"(",
")",
"{",
"// Get the controller",
"if",
"(",
"!",
"(",
"$",
"controller",
"=",
"$",
"this",
"->",
"detectController",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Get the action",
"$",
"action",
"=",
"$",
"this",
"->",
"detectAction",
"(",
")",
";",
"if",
"(",
"!",
"$",
"action",
"||",
"!",
"method_exists",
"(",
"$",
"controller",
",",
"$",
"action",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Get the id",
"$",
"id",
"=",
"$",
"this",
"->",
"detectId",
"(",
")",
";",
"// Tell other classes what was found",
"$",
"event",
"=",
"Event",
"::",
"fire",
"(",
"'wildcard.detection'",
",",
"[",
"$",
"controller",
",",
"$",
"action",
",",
"$",
"id",
"]",
")",
";",
"// Instantiate controller",
"$",
"controller",
"=",
"new",
"$",
"controller",
"(",
")",
";",
"if",
"(",
"$",
"parent",
"=",
"$",
"this",
"->",
"detectParent",
"(",
")",
")",
"{",
"list",
"(",
"$",
"parent_slug",
",",
"$",
"parent_id",
")",
"=",
"$",
"parent",
";",
"$",
"parent_model",
"=",
"'App\\\\'",
".",
"Str",
"::",
"singular",
"(",
"Str",
"::",
"studly",
"(",
"$",
"parent_slug",
")",
")",
";",
"$",
"controller",
"->",
"parent",
"(",
"$",
"parent_model",
"::",
"findOrFail",
"(",
"$",
"parent_id",
")",
")",
";",
"}",
"// Execute the request",
"$",
"params",
"=",
"$",
"id",
"?",
"[",
"$",
"id",
"]",
":",
"[",
"]",
";",
"return",
"$",
"controller",
"->",
"callAction",
"(",
"$",
"action",
",",
"$",
"params",
")",
";",
"}"
] | Detect the controller for a given route and then execute the action
that is specified in the route. | [
"Detect",
"the",
"controller",
"for",
"a",
"given",
"route",
"and",
"then",
"execute",
"the",
"action",
"that",
"is",
"specified",
"in",
"the",
"route",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Wildcard.php#L48-L80 |
30,842 | BKWLD/decoy | classes/Routing/Wildcard.php | Wildcard.detectController | public function detectController($class_name = null)
{
// Setup the two schemes
if (!$class_name) {
$class_name = $this->detectControllerClass();
}
$app = 'App\\Http\\Controllers\\'
. ucfirst(Str::studly($this->dir))
. '\\'.$class_name;
$decoy = 'Bkwld\Decoy\Controllers\\'.$class_name;
// Find the right one
if (class_exists($app)) {
return $app;
} elseif (class_exists($decoy)) {
return $decoy;
}
return false;
} | php | public function detectController($class_name = null)
{
// Setup the two schemes
if (!$class_name) {
$class_name = $this->detectControllerClass();
}
$app = 'App\\Http\\Controllers\\'
. ucfirst(Str::studly($this->dir))
. '\\'.$class_name;
$decoy = 'Bkwld\Decoy\Controllers\\'.$class_name;
// Find the right one
if (class_exists($app)) {
return $app;
} elseif (class_exists($decoy)) {
return $decoy;
}
return false;
} | [
"public",
"function",
"detectController",
"(",
"$",
"class_name",
"=",
"null",
")",
"{",
"// Setup the two schemes",
"if",
"(",
"!",
"$",
"class_name",
")",
"{",
"$",
"class_name",
"=",
"$",
"this",
"->",
"detectControllerClass",
"(",
")",
";",
"}",
"$",
"app",
"=",
"'App\\\\Http\\\\Controllers\\\\'",
".",
"ucfirst",
"(",
"Str",
"::",
"studly",
"(",
"$",
"this",
"->",
"dir",
")",
")",
".",
"'\\\\'",
".",
"$",
"class_name",
";",
"$",
"decoy",
"=",
"'Bkwld\\Decoy\\Controllers\\\\'",
".",
"$",
"class_name",
";",
"// Find the right one",
"if",
"(",
"class_exists",
"(",
"$",
"app",
")",
")",
"{",
"return",
"$",
"app",
";",
"}",
"elseif",
"(",
"class_exists",
"(",
"$",
"decoy",
")",
")",
"{",
"return",
"$",
"decoy",
";",
"}",
"return",
"false",
";",
"}"
] | Get the full namespaced controller
@return string i.e. App\Http\Controllers\Admin\People or
Bkwld\Decoy\Controllers\Admins | [
"Get",
"the",
"full",
"namespaced",
"controller"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Wildcard.php#L88-L108 |
30,843 | BKWLD/decoy | classes/Routing/Wildcard.php | Wildcard.detectControllerClass | public function detectControllerClass($name = null)
{
// The path must begin with the config dir
if (!preg_match('#^'.$this->dir.'#i', $this->path, $matches)) {
return false;
}
// Find the controller from the end of the path
if (!$name) {
$name = $this->detectControllerName();
}
// Form the namespaced controller
return Str::studly($name);
} | php | public function detectControllerClass($name = null)
{
// The path must begin with the config dir
if (!preg_match('#^'.$this->dir.'#i', $this->path, $matches)) {
return false;
}
// Find the controller from the end of the path
if (!$name) {
$name = $this->detectControllerName();
}
// Form the namespaced controller
return Str::studly($name);
} | [
"public",
"function",
"detectControllerClass",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"// The path must begin with the config dir",
"if",
"(",
"!",
"preg_match",
"(",
"'#^'",
".",
"$",
"this",
"->",
"dir",
".",
"'#i'",
",",
"$",
"this",
"->",
"path",
",",
"$",
"matches",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Find the controller from the end of the path",
"if",
"(",
"!",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"detectControllerName",
"(",
")",
";",
"}",
"// Form the namespaced controller",
"return",
"Str",
"::",
"studly",
"(",
"$",
"name",
")",
";",
"}"
] | Detect the controller for a path. Which is the last non-action
string in the path
@return string The controller class, i.e. Articles | [
"Detect",
"the",
"controller",
"for",
"a",
"path",
".",
"Which",
"is",
"the",
"last",
"non",
"-",
"action",
"string",
"in",
"the",
"path"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Wildcard.php#L116-L130 |
30,844 | BKWLD/decoy | classes/Routing/Wildcard.php | Wildcard.detectControllerName | public function detectControllerName()
{
$pattern = '#/'.$this->controllerNameRegex().'#i';
if (!preg_match($pattern, $this->path, $matches)) {
return false;
}
return $matches[1];
} | php | public function detectControllerName()
{
$pattern = '#/'.$this->controllerNameRegex().'#i';
if (!preg_match($pattern, $this->path, $matches)) {
return false;
}
return $matches[1];
} | [
"public",
"function",
"detectControllerName",
"(",
")",
"{",
"$",
"pattern",
"=",
"'#/'",
".",
"$",
"this",
"->",
"controllerNameRegex",
"(",
")",
".",
"'#i'",
";",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"this",
"->",
"path",
",",
"$",
"matches",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}"
] | Get just the controller's short name from the path
@return mixed false if not found, otherwise a string like "news" or "slides" | [
"Get",
"just",
"the",
"controller",
"s",
"short",
"name",
"from",
"the",
"path"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Wildcard.php#L136-L144 |
30,845 | BKWLD/decoy | classes/Routing/Wildcard.php | Wildcard.detectAction | public function detectAction()
{
// If the path ends in one of the special actions, use that as the action
// as long as the verb is a GET
if (preg_match('#[a-z-]+$#i', $this->path, $matches)) {
$action = $matches[0];
// If posting to the create/edit route, treat as a 'post' route rather than
// a 'create/edit' one. This is a shorthand so the create forms can
// post to themselves
if ($action == 'create' && $this->verb == 'POST') {
return 'store';
} elseif ($action == 'edit' && $this->verb == 'POST') {
return 'update';
}
// ... otherwise, use the route explicitly
elseif (in_array($action, $this->actions)) {
return $action;
}
}
// If the path ends in a number, the verb defines what it is
if (preg_match('#\d+$#', $this->path)) {
switch ($this->verb) {
case 'PUT':
case 'POST':
return 'update';
case 'DELETE':
return 'destroy';
default:
return false;
}
}
// Else, it must end with the controller name
switch ($this->verb) {
case 'POST':
return 'store';
case 'GET':
return 'index';
}
// Must have been an erorr if we got here
return false;
} | php | public function detectAction()
{
// If the path ends in one of the special actions, use that as the action
// as long as the verb is a GET
if (preg_match('#[a-z-]+$#i', $this->path, $matches)) {
$action = $matches[0];
// If posting to the create/edit route, treat as a 'post' route rather than
// a 'create/edit' one. This is a shorthand so the create forms can
// post to themselves
if ($action == 'create' && $this->verb == 'POST') {
return 'store';
} elseif ($action == 'edit' && $this->verb == 'POST') {
return 'update';
}
// ... otherwise, use the route explicitly
elseif (in_array($action, $this->actions)) {
return $action;
}
}
// If the path ends in a number, the verb defines what it is
if (preg_match('#\d+$#', $this->path)) {
switch ($this->verb) {
case 'PUT':
case 'POST':
return 'update';
case 'DELETE':
return 'destroy';
default:
return false;
}
}
// Else, it must end with the controller name
switch ($this->verb) {
case 'POST':
return 'store';
case 'GET':
return 'index';
}
// Must have been an erorr if we got here
return false;
} | [
"public",
"function",
"detectAction",
"(",
")",
"{",
"// If the path ends in one of the special actions, use that as the action",
"// as long as the verb is a GET",
"if",
"(",
"preg_match",
"(",
"'#[a-z-]+$#i'",
",",
"$",
"this",
"->",
"path",
",",
"$",
"matches",
")",
")",
"{",
"$",
"action",
"=",
"$",
"matches",
"[",
"0",
"]",
";",
"// If posting to the create/edit route, treat as a 'post' route rather than",
"// a 'create/edit' one. This is a shorthand so the create forms can",
"// post to themselves",
"if",
"(",
"$",
"action",
"==",
"'create'",
"&&",
"$",
"this",
"->",
"verb",
"==",
"'POST'",
")",
"{",
"return",
"'store'",
";",
"}",
"elseif",
"(",
"$",
"action",
"==",
"'edit'",
"&&",
"$",
"this",
"->",
"verb",
"==",
"'POST'",
")",
"{",
"return",
"'update'",
";",
"}",
"// ... otherwise, use the route explicitly",
"elseif",
"(",
"in_array",
"(",
"$",
"action",
",",
"$",
"this",
"->",
"actions",
")",
")",
"{",
"return",
"$",
"action",
";",
"}",
"}",
"// If the path ends in a number, the verb defines what it is",
"if",
"(",
"preg_match",
"(",
"'#\\d+$#'",
",",
"$",
"this",
"->",
"path",
")",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"verb",
")",
"{",
"case",
"'PUT'",
":",
"case",
"'POST'",
":",
"return",
"'update'",
";",
"case",
"'DELETE'",
":",
"return",
"'destroy'",
";",
"default",
":",
"return",
"false",
";",
"}",
"}",
"// Else, it must end with the controller name",
"switch",
"(",
"$",
"this",
"->",
"verb",
")",
"{",
"case",
"'POST'",
":",
"return",
"'store'",
";",
"case",
"'GET'",
":",
"return",
"'index'",
";",
"}",
"// Must have been an erorr if we got here",
"return",
"false",
";",
"}"
] | Detect the action for a path
@return string 'create', 'update', 'edit', .... | [
"Detect",
"the",
"action",
"for",
"a",
"path"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Wildcard.php#L159-L208 |
30,846 | BKWLD/decoy | classes/Routing/Wildcard.php | Wildcard.detectId | public function detectId()
{
// If there is an id, it will be the last number
if (preg_match('#\d+$#', $this->path, $matches)) {
return $matches[0];
}
// .. or the route will be an action preceeded by an id
$pattern = '#(\d+)/('.implode('|', $this->actions).')$#i';
if (preg_match($pattern, $this->path, $matches)) {
return $matches[1];
}
// There's no id
return false;
} | php | public function detectId()
{
// If there is an id, it will be the last number
if (preg_match('#\d+$#', $this->path, $matches)) {
return $matches[0];
}
// .. or the route will be an action preceeded by an id
$pattern = '#(\d+)/('.implode('|', $this->actions).')$#i';
if (preg_match($pattern, $this->path, $matches)) {
return $matches[1];
}
// There's no id
return false;
} | [
"public",
"function",
"detectId",
"(",
")",
"{",
"// If there is an id, it will be the last number",
"if",
"(",
"preg_match",
"(",
"'#\\d+$#'",
",",
"$",
"this",
"->",
"path",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
"// .. or the route will be an action preceeded by an id",
"$",
"pattern",
"=",
"'#(\\d+)/('",
".",
"implode",
"(",
"'|'",
",",
"$",
"this",
"->",
"actions",
")",
".",
"')$#i'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"this",
"->",
"path",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"// There's no id",
"return",
"false",
";",
"}"
] | Detect the id for the path
@return integer An id number for a DB record | [
"Detect",
"the",
"id",
"for",
"the",
"path"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Wildcard.php#L214-L229 |
30,847 | BKWLD/decoy | classes/Routing/Wildcard.php | Wildcard.detectParent | public function detectParent()
{
// Look for a string, then a number (the parent id), followed by a non-action
// string, then possiby a number and/or an action string and then the end
$pattern = '#([a-z-]+)/(\d+)/(?!'.implode('|', $this->actions).')[a-z-]+(?:/\d+)?(/('.implode('|', $this->actions).'))?$#i';
if (preg_match($pattern, $this->path, $matches)) {
return [$matches[1], $matches[2]];
}
return false;
} | php | public function detectParent()
{
// Look for a string, then a number (the parent id), followed by a non-action
// string, then possiby a number and/or an action string and then the end
$pattern = '#([a-z-]+)/(\d+)/(?!'.implode('|', $this->actions).')[a-z-]+(?:/\d+)?(/('.implode('|', $this->actions).'))?$#i';
if (preg_match($pattern, $this->path, $matches)) {
return [$matches[1], $matches[2]];
}
return false;
} | [
"public",
"function",
"detectParent",
"(",
")",
"{",
"// Look for a string, then a number (the parent id), followed by a non-action",
"// string, then possiby a number and/or an action string and then the end",
"$",
"pattern",
"=",
"'#([a-z-]+)/(\\d+)/(?!'",
".",
"implode",
"(",
"'|'",
",",
"$",
"this",
"->",
"actions",
")",
".",
"')[a-z-]+(?:/\\d+)?(/('",
".",
"implode",
"(",
"'|'",
",",
"$",
"this",
"->",
"actions",
")",
".",
"'))?$#i'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"this",
"->",
"path",
",",
"$",
"matches",
")",
")",
"{",
"return",
"[",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"matches",
"[",
"2",
"]",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Detect the parent id of the path
@return mixed False or an array containing:
- The slug of the parent controller
- The id of the parent record | [
"Detect",
"the",
"parent",
"id",
"of",
"the",
"path"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Wildcard.php#L238-L248 |
30,848 | BKWLD/decoy | classes/Routing/Wildcard.php | Wildcard.getAllClasses | public function getAllClasses()
{
// Get all slugs that lead with a slash
$pattern = '#(?:/([a-z-]+))#i';
// If no matches, return an empty array. Matches will be at first index;
preg_match_all($pattern, $this->path, $matches);
if (count($matches) <= 1) {
return [];
}
$matches = $matches[1];
// Remove actions from the matches list (like "edit")
if (in_array($matches[count($matches) - 1], $this->actions)) {
array_pop($matches);
}
// Convert all the matches to their classes
return array_map(function ($name) {
return $this->detectController($this->detectControllerClass($name));
}, $matches);
} | php | public function getAllClasses()
{
// Get all slugs that lead with a slash
$pattern = '#(?:/([a-z-]+))#i';
// If no matches, return an empty array. Matches will be at first index;
preg_match_all($pattern, $this->path, $matches);
if (count($matches) <= 1) {
return [];
}
$matches = $matches[1];
// Remove actions from the matches list (like "edit")
if (in_array($matches[count($matches) - 1], $this->actions)) {
array_pop($matches);
}
// Convert all the matches to their classes
return array_map(function ($name) {
return $this->detectController($this->detectControllerClass($name));
}, $matches);
} | [
"public",
"function",
"getAllClasses",
"(",
")",
"{",
"// Get all slugs that lead with a slash",
"$",
"pattern",
"=",
"'#(?:/([a-z-]+))#i'",
";",
"// If no matches, return an empty array. Matches will be at first index;",
"preg_match_all",
"(",
"$",
"pattern",
",",
"$",
"this",
"->",
"path",
",",
"$",
"matches",
")",
";",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
"<=",
"1",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"matches",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"// Remove actions from the matches list (like \"edit\")",
"if",
"(",
"in_array",
"(",
"$",
"matches",
"[",
"count",
"(",
"$",
"matches",
")",
"-",
"1",
"]",
",",
"$",
"this",
"->",
"actions",
")",
")",
"{",
"array_pop",
"(",
"$",
"matches",
")",
";",
"}",
"// Convert all the matches to their classes",
"return",
"array_map",
"(",
"function",
"(",
"$",
"name",
")",
"{",
"return",
"$",
"this",
"->",
"detectController",
"(",
"$",
"this",
"->",
"detectControllerClass",
"(",
"$",
"name",
")",
")",
";",
"}",
",",
"$",
"matches",
")",
";",
"}"
] | Return an array of all classes represented in the URL | [
"Return",
"an",
"array",
"of",
"all",
"classes",
"represented",
"in",
"the",
"URL"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Wildcard.php#L253-L274 |
30,849 | BKWLD/decoy | classes/Models/Traits/Loggable.php | Loggable.showTrashedVersion | private static function showTrashedVersion(Builder $builder)
{
if (($change = static::lookupRequestedChange())
&& static::builderMatchesChange($change, $builder)) {
$builder->withoutGlobalScope(SoftDeletingScope::class);
}
} | php | private static function showTrashedVersion(Builder $builder)
{
if (($change = static::lookupRequestedChange())
&& static::builderMatchesChange($change, $builder)) {
$builder->withoutGlobalScope(SoftDeletingScope::class);
}
} | [
"private",
"static",
"function",
"showTrashedVersion",
"(",
"Builder",
"$",
"builder",
")",
"{",
"if",
"(",
"(",
"$",
"change",
"=",
"static",
"::",
"lookupRequestedChange",
"(",
")",
")",
"&&",
"static",
"::",
"builderMatchesChange",
"(",
"$",
"change",
",",
"$",
"builder",
")",
")",
"{",
"$",
"builder",
"->",
"withoutGlobalScope",
"(",
"SoftDeletingScope",
"::",
"class",
")",
";",
"}",
"}"
] | Show trashed models for matching change
@param Builder $builder
@return void | [
"Show",
"trashed",
"models",
"for",
"matching",
"change"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Loggable.php#L84-L90 |
30,850 | BKWLD/decoy | classes/Models/Traits/Loggable.php | Loggable.lookupRequestedChange | private static function lookupRequestedChange()
{
// Only run if the query param is present
if (!$change_id = request(Change::QUERY_KEY)) {
return;
}
// Don't execute for classes that result in recusirve queries when the
// Change model gets built below
$class = get_called_class();
if (in_array($class, [Change::class, Admin::class, Image::class])) {
return;
}
// Check whether the referenced Change is for this class
$change = Change::find($change_id);
if ($class == $change->model) {
return $change;
}
} | php | private static function lookupRequestedChange()
{
// Only run if the query param is present
if (!$change_id = request(Change::QUERY_KEY)) {
return;
}
// Don't execute for classes that result in recusirve queries when the
// Change model gets built below
$class = get_called_class();
if (in_array($class, [Change::class, Admin::class, Image::class])) {
return;
}
// Check whether the referenced Change is for this class
$change = Change::find($change_id);
if ($class == $change->model) {
return $change;
}
} | [
"private",
"static",
"function",
"lookupRequestedChange",
"(",
")",
"{",
"// Only run if the query param is present",
"if",
"(",
"!",
"$",
"change_id",
"=",
"request",
"(",
"Change",
"::",
"QUERY_KEY",
")",
")",
"{",
"return",
";",
"}",
"// Don't execute for classes that result in recusirve queries when the",
"// Change model gets built below",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"class",
",",
"[",
"Change",
"::",
"class",
",",
"Admin",
"::",
"class",
",",
"Image",
"::",
"class",
"]",
")",
")",
"{",
"return",
";",
"}",
"// Check whether the referenced Change is for this class",
"$",
"change",
"=",
"Change",
"::",
"find",
"(",
"$",
"change_id",
")",
";",
"if",
"(",
"$",
"class",
"==",
"$",
"change",
"->",
"model",
")",
"{",
"return",
"$",
"change",
";",
"}",
"}"
] | Get a Change record mentioned in the query, if appropriate
@return Change|void | [
"Get",
"a",
"Change",
"record",
"mentioned",
"in",
"the",
"query",
"if",
"appropriate"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Loggable.php#L97-L116 |
30,851 | BKWLD/decoy | classes/Models/Traits/Loggable.php | Loggable.builderMatchesChange | private static function builderMatchesChange(Change $change, Builder $builder)
{
$class = $change->model;
$route_key_name = (new $class)->getRouteKeyName();
return collect($builder->getQuery()->wheres)
->contains(function($where) use ($change, $route_key_name) {
// If the builder is keyed to a simple "id" in the route, return
// whether the Change matches it.
if ($route_key_name == 'id') {
return $where['column'] == $route_key_name
&& $where['operator'] == '='
&& $where['value'] == $change->key;
// Otherwise compare against model logged by the change. The
// scope needs to be removed to prevent recursion.
} else {
$value = $change->changedModel()
->withoutGlobalScope(static::$LOGGABLE_SCOPE)
->first()
->$route_key_name;
return $where['column'] == $route_key_name
&& $where['operator'] == '='
&& $where['value'] == $value;
}
});
} | php | private static function builderMatchesChange(Change $change, Builder $builder)
{
$class = $change->model;
$route_key_name = (new $class)->getRouteKeyName();
return collect($builder->getQuery()->wheres)
->contains(function($where) use ($change, $route_key_name) {
// If the builder is keyed to a simple "id" in the route, return
// whether the Change matches it.
if ($route_key_name == 'id') {
return $where['column'] == $route_key_name
&& $where['operator'] == '='
&& $where['value'] == $change->key;
// Otherwise compare against model logged by the change. The
// scope needs to be removed to prevent recursion.
} else {
$value = $change->changedModel()
->withoutGlobalScope(static::$LOGGABLE_SCOPE)
->first()
->$route_key_name;
return $where['column'] == $route_key_name
&& $where['operator'] == '='
&& $where['value'] == $value;
}
});
} | [
"private",
"static",
"function",
"builderMatchesChange",
"(",
"Change",
"$",
"change",
",",
"Builder",
"$",
"builder",
")",
"{",
"$",
"class",
"=",
"$",
"change",
"->",
"model",
";",
"$",
"route_key_name",
"=",
"(",
"new",
"$",
"class",
")",
"->",
"getRouteKeyName",
"(",
")",
";",
"return",
"collect",
"(",
"$",
"builder",
"->",
"getQuery",
"(",
")",
"->",
"wheres",
")",
"->",
"contains",
"(",
"function",
"(",
"$",
"where",
")",
"use",
"(",
"$",
"change",
",",
"$",
"route_key_name",
")",
"{",
"// If the builder is keyed to a simple \"id\" in the route, return",
"// whether the Change matches it.",
"if",
"(",
"$",
"route_key_name",
"==",
"'id'",
")",
"{",
"return",
"$",
"where",
"[",
"'column'",
"]",
"==",
"$",
"route_key_name",
"&&",
"$",
"where",
"[",
"'operator'",
"]",
"==",
"'='",
"&&",
"$",
"where",
"[",
"'value'",
"]",
"==",
"$",
"change",
"->",
"key",
";",
"// Otherwise compare against model logged by the change. The",
"// scope needs to be removed to prevent recursion.",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"change",
"->",
"changedModel",
"(",
")",
"->",
"withoutGlobalScope",
"(",
"static",
"::",
"$",
"LOGGABLE_SCOPE",
")",
"->",
"first",
"(",
")",
"->",
"$",
"route_key_name",
";",
"return",
"$",
"where",
"[",
"'column'",
"]",
"==",
"$",
"route_key_name",
"&&",
"$",
"where",
"[",
"'operator'",
"]",
"==",
"'='",
"&&",
"$",
"where",
"[",
"'value'",
"]",
"==",
"$",
"value",
";",
"}",
"}",
")",
";",
"}"
] | Does the Change referenced in the GET query match the conditions already
applied in the query builder?
@param Change $change
@param Builder $builder
@return boolean | [
"Does",
"the",
"Change",
"referenced",
"in",
"the",
"GET",
"query",
"match",
"the",
"conditions",
"already",
"applied",
"in",
"the",
"query",
"builder?"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Loggable.php#L126-L152 |
30,852 | BKWLD/decoy | classes/Models/Traits/Loggable.php | Loggable.replaceAttributesWithChange | private function replaceAttributesWithChange()
{
if (($change = static::lookupRequestedChange())
&& $change->key == $this->getKey()) {
$this->attributes = array_merge(
$this->attributes,
$this->attributesAtChange($change)
);
}
} | php | private function replaceAttributesWithChange()
{
if (($change = static::lookupRequestedChange())
&& $change->key == $this->getKey()) {
$this->attributes = array_merge(
$this->attributes,
$this->attributesAtChange($change)
);
}
} | [
"private",
"function",
"replaceAttributesWithChange",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"change",
"=",
"static",
"::",
"lookupRequestedChange",
"(",
")",
")",
"&&",
"$",
"change",
"->",
"key",
"==",
"$",
"this",
"->",
"getKey",
"(",
")",
")",
"{",
"$",
"this",
"->",
"attributes",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"attributes",
",",
"$",
"this",
"->",
"attributesAtChange",
"(",
"$",
"change",
")",
")",
";",
"}",
"}"
] | Replace all the attributes with those from the specified Change specified
in the reqeust query.
@return void | [
"Replace",
"all",
"the",
"attributes",
"with",
"those",
"from",
"the",
"specified",
"Change",
"specified",
"in",
"the",
"reqeust",
"query",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Loggable.php#L160-L169 |
30,853 | BKWLD/decoy | classes/Models/Traits/Loggable.php | Loggable.attributesAtChange | private function attributesAtChange(Change $change)
{
return $this->previousChanges($change)
->reduce(function($attributes, $change) {
return array_merge($attributes, $change->changed);
}, []);
} | php | private function attributesAtChange(Change $change)
{
return $this->previousChanges($change)
->reduce(function($attributes, $change) {
return array_merge($attributes, $change->changed);
}, []);
} | [
"private",
"function",
"attributesAtChange",
"(",
"Change",
"$",
"change",
")",
"{",
"return",
"$",
"this",
"->",
"previousChanges",
"(",
"$",
"change",
")",
"->",
"reduce",
"(",
"function",
"(",
"$",
"attributes",
",",
"$",
"change",
")",
"{",
"return",
"array_merge",
"(",
"$",
"attributes",
",",
"$",
"change",
"->",
"changed",
")",
";",
"}",
",",
"[",
"]",
")",
";",
"}"
] | Get the attributes of the model at a given Change
@param Change $change
@return array | [
"Get",
"the",
"attributes",
"of",
"the",
"model",
"at",
"a",
"given",
"Change"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Loggable.php#L177-L183 |
30,854 | BKWLD/decoy | classes/Models/Traits/Loggable.php | Loggable.previousChanges | private function previousChanges(Change $change)
{
return $this->changes()
->where('changes.id', '<=', $change->id)
->orderBy('changes.id', 'asc')
->get();
} | php | private function previousChanges(Change $change)
{
return $this->changes()
->where('changes.id', '<=', $change->id)
->orderBy('changes.id', 'asc')
->get();
} | [
"private",
"function",
"previousChanges",
"(",
"Change",
"$",
"change",
")",
"{",
"return",
"$",
"this",
"->",
"changes",
"(",
")",
"->",
"where",
"(",
"'changes.id'",
",",
"'<='",
",",
"$",
"change",
"->",
"id",
")",
"->",
"orderBy",
"(",
"'changes.id'",
",",
"'asc'",
")",
"->",
"get",
"(",
")",
";",
"}"
] | Get the list of pervious changes of this model, storing it to reduce
future lookups
@param Change $change
@return Collection | [
"Get",
"the",
"list",
"of",
"pervious",
"changes",
"of",
"this",
"model",
"storing",
"it",
"to",
"reduce",
"future",
"lookups"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Loggable.php#L192-L199 |
30,855 | BKWLD/decoy | classes/Input/EncodingProviders/EncodingProvider.php | EncodingProvider.mergeConfigWithDefaults | protected function mergeConfigWithDefaults($preset)
{
// Get the preset settings
if (!$settings = Config::get('decoy.encode.presets.'.$preset.'.settings')) {
throw new Exception('Encoding preset not found: '.$preset);
}
// If the settings are an assoc array, then there is only one output and it
// needs to be wrapped in an array
if (!is_numeric(array_keys($settings)[0])) {
$settings = ['mp4' => $settings];
}
// Merge defaults with each output in the settings
return array_map(function ($output) {
return array_merge($this->defaults, $output);
}, $settings);
} | php | protected function mergeConfigWithDefaults($preset)
{
// Get the preset settings
if (!$settings = Config::get('decoy.encode.presets.'.$preset.'.settings')) {
throw new Exception('Encoding preset not found: '.$preset);
}
// If the settings are an assoc array, then there is only one output and it
// needs to be wrapped in an array
if (!is_numeric(array_keys($settings)[0])) {
$settings = ['mp4' => $settings];
}
// Merge defaults with each output in the settings
return array_map(function ($output) {
return array_merge($this->defaults, $output);
}, $settings);
} | [
"protected",
"function",
"mergeConfigWithDefaults",
"(",
"$",
"preset",
")",
"{",
"// Get the preset settings",
"if",
"(",
"!",
"$",
"settings",
"=",
"Config",
"::",
"get",
"(",
"'decoy.encode.presets.'",
".",
"$",
"preset",
".",
"'.settings'",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Encoding preset not found: '",
".",
"$",
"preset",
")",
";",
"}",
"// If the settings are an assoc array, then there is only one output and it",
"// needs to be wrapped in an array",
"if",
"(",
"!",
"is_numeric",
"(",
"array_keys",
"(",
"$",
"settings",
")",
"[",
"0",
"]",
")",
")",
"{",
"$",
"settings",
"=",
"[",
"'mp4'",
"=>",
"$",
"settings",
"]",
";",
"}",
"// Merge defaults with each output in the settings",
"return",
"array_map",
"(",
"function",
"(",
"$",
"output",
")",
"{",
"return",
"array_merge",
"(",
"$",
"this",
"->",
"defaults",
",",
"$",
"output",
")",
";",
"}",
",",
"$",
"settings",
")",
";",
"}"
] | Update the default configwith the user config
@param string $preset
@return array
@throws Exception | [
"Update",
"the",
"default",
"configwith",
"the",
"user",
"config"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/EncodingProviders/EncodingProvider.php#L77-L94 |
30,856 | BKWLD/decoy | classes/Fields/Image.php | Image.applyRules | protected function applyRules()
{
// Check if there are rules for this field
$rules_key = 'images.' . ($this->name ?: 'default');
if (!$rules = Former::getRules($rules_key)) {
return;
}
// If there already is an image, drop the forced requirement
if ($this->hasImage() && array_key_exists('required', $rules)) {
unset($rules['required']);
$this->addClass('required'); // So the icon shows up
}
// Apply rules using Former's LiveValidation
$live = new LiveValidation($this);
$live->apply($rules);
} | php | protected function applyRules()
{
// Check if there are rules for this field
$rules_key = 'images.' . ($this->name ?: 'default');
if (!$rules = Former::getRules($rules_key)) {
return;
}
// If there already is an image, drop the forced requirement
if ($this->hasImage() && array_key_exists('required', $rules)) {
unset($rules['required']);
$this->addClass('required'); // So the icon shows up
}
// Apply rules using Former's LiveValidation
$live = new LiveValidation($this);
$live->apply($rules);
} | [
"protected",
"function",
"applyRules",
"(",
")",
"{",
"// Check if there are rules for this field",
"$",
"rules_key",
"=",
"'images.'",
".",
"(",
"$",
"this",
"->",
"name",
"?",
":",
"'default'",
")",
";",
"if",
"(",
"!",
"$",
"rules",
"=",
"Former",
"::",
"getRules",
"(",
"$",
"rules_key",
")",
")",
"{",
"return",
";",
"}",
"// If there already is an image, drop the forced requirement",
"if",
"(",
"$",
"this",
"->",
"hasImage",
"(",
")",
"&&",
"array_key_exists",
"(",
"'required'",
",",
"$",
"rules",
")",
")",
"{",
"unset",
"(",
"$",
"rules",
"[",
"'required'",
"]",
")",
";",
"$",
"this",
"->",
"addClass",
"(",
"'required'",
")",
";",
"// So the icon shows up",
"}",
"// Apply rules using Former's LiveValidation",
"$",
"live",
"=",
"new",
"LiveValidation",
"(",
"$",
"this",
")",
";",
"$",
"live",
"->",
"apply",
"(",
"$",
"rules",
")",
";",
"}"
] | Apply validation rules
@return void | [
"Apply",
"validation",
"rules"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Image.php#L84-L101 |
30,857 | BKWLD/decoy | classes/Fields/Image.php | Image.showErrors | public function showErrors()
{
$key = sprintf('images.%s.file', $this->inputId());
if (session('errors') && ($error = session('errors')->first($key))) {
$this->help($error);
$this->group->addClass('has-error');
}
} | php | public function showErrors()
{
$key = sprintf('images.%s.file', $this->inputId());
if (session('errors') && ($error = session('errors')->first($key))) {
$this->help($error);
$this->group->addClass('has-error');
}
} | [
"public",
"function",
"showErrors",
"(",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"'images.%s.file'",
",",
"$",
"this",
"->",
"inputId",
"(",
")",
")",
";",
"if",
"(",
"session",
"(",
"'errors'",
")",
"&&",
"(",
"$",
"error",
"=",
"session",
"(",
"'errors'",
")",
"->",
"first",
"(",
"$",
"key",
")",
")",
")",
"{",
"$",
"this",
"->",
"help",
"(",
"$",
"error",
")",
";",
"$",
"this",
"->",
"group",
"->",
"addClass",
"(",
"'has-error'",
")",
";",
"}",
"}"
] | Show errors that will have been stored on the `file` proeperty
@return void | [
"Show",
"errors",
"that",
"will",
"have",
"been",
"stored",
"on",
"the",
"file",
"proeperty"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Image.php#L108-L115 |
30,858 | BKWLD/decoy | classes/Fields/Image.php | Image.wrapAndRender | public function wrapAndRender()
{
// Get additional UI first so it can modify the normal form-group UI.
$html = $this->renderEditor();
// Add the aspect ratio choice
$this->group->dataAspectRatio($this->ratio ?: false);
// Set errors
$this->showErrors();
// Inform whether there is an existing image to preview
if ($this->hasImage()) {
$this->group->addClass('has-image');
}
// Add extra markup
return $this->appendToGroup(parent::wrapAndRender(), $html);
} | php | public function wrapAndRender()
{
// Get additional UI first so it can modify the normal form-group UI.
$html = $this->renderEditor();
// Add the aspect ratio choice
$this->group->dataAspectRatio($this->ratio ?: false);
// Set errors
$this->showErrors();
// Inform whether there is an existing image to preview
if ($this->hasImage()) {
$this->group->addClass('has-image');
}
// Add extra markup
return $this->appendToGroup(parent::wrapAndRender(), $html);
} | [
"public",
"function",
"wrapAndRender",
"(",
")",
"{",
"// Get additional UI first so it can modify the normal form-group UI.",
"$",
"html",
"=",
"$",
"this",
"->",
"renderEditor",
"(",
")",
";",
"// Add the aspect ratio choice",
"$",
"this",
"->",
"group",
"->",
"dataAspectRatio",
"(",
"$",
"this",
"->",
"ratio",
"?",
":",
"false",
")",
";",
"// Set errors",
"$",
"this",
"->",
"showErrors",
"(",
")",
";",
"// Inform whether there is an existing image to preview",
"if",
"(",
"$",
"this",
"->",
"hasImage",
"(",
")",
")",
"{",
"$",
"this",
"->",
"group",
"->",
"addClass",
"(",
"'has-image'",
")",
";",
"}",
"// Add extra markup",
"return",
"$",
"this",
"->",
"appendToGroup",
"(",
"parent",
"::",
"wrapAndRender",
"(",
")",
",",
"$",
"html",
")",
";",
"}"
] | Prints out the field, wrapped in its group. Additional review UI is tacked
on here.
@return string | [
"Prints",
"out",
"the",
"field",
"wrapped",
"in",
"its",
"group",
".",
"Additional",
"review",
"UI",
"is",
"tacked",
"on",
"here",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Image.php#L135-L153 |
30,859 | BKWLD/decoy | classes/Fields/Image.php | Image.createHidden | protected function createHidden($name, $value = null)
{
$field = Former::hidden($this->inputName($name))->class('input-'.$name);
if ($value) {
if (!is_scalar($value)) {
$value = json_encode($value);
}
$field->forceValue($value);
}
return $field->render();
} | php | protected function createHidden($name, $value = null)
{
$field = Former::hidden($this->inputName($name))->class('input-'.$name);
if ($value) {
if (!is_scalar($value)) {
$value = json_encode($value);
}
$field->forceValue($value);
}
return $field->render();
} | [
"protected",
"function",
"createHidden",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"field",
"=",
"Former",
"::",
"hidden",
"(",
"$",
"this",
"->",
"inputName",
"(",
"$",
"name",
")",
")",
"->",
"class",
"(",
"'input-'",
".",
"$",
"name",
")",
";",
"if",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"json_encode",
"(",
"$",
"value",
")",
";",
"}",
"$",
"field",
"->",
"forceValue",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"field",
"->",
"render",
"(",
")",
";",
"}"
] | Make a hidden field
@param string $name
@param string $value
@return string | [
"Make",
"a",
"hidden",
"field"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Image.php#L234-L245 |
30,860 | BKWLD/decoy | classes/Fields/Image.php | Image.inputId | protected function inputId()
{
// If we're editing an already existing image, return it's Image id
if (($image = $this->image()) && $image->id) {
return $image->id;
}
// Otherwise, use the name of the field, which should be unique compared
// to other image fields on the page.
if (!$this->input_id) {
$this->input_id = '_'.preg_replace('#[^\w]#', '', $this->name);
}
return $this->input_id;
} | php | protected function inputId()
{
// If we're editing an already existing image, return it's Image id
if (($image = $this->image()) && $image->id) {
return $image->id;
}
// Otherwise, use the name of the field, which should be unique compared
// to other image fields on the page.
if (!$this->input_id) {
$this->input_id = '_'.preg_replace('#[^\w]#', '', $this->name);
}
return $this->input_id;
} | [
"protected",
"function",
"inputId",
"(",
")",
"{",
"// If we're editing an already existing image, return it's Image id",
"if",
"(",
"(",
"$",
"image",
"=",
"$",
"this",
"->",
"image",
"(",
")",
")",
"&&",
"$",
"image",
"->",
"id",
")",
"{",
"return",
"$",
"image",
"->",
"id",
";",
"}",
"// Otherwise, use the name of the field, which should be unique compared",
"// to other image fields on the page.",
"if",
"(",
"!",
"$",
"this",
"->",
"input_id",
")",
"{",
"$",
"this",
"->",
"input_id",
"=",
"'_'",
".",
"preg_replace",
"(",
"'#[^\\w]#'",
",",
"''",
",",
"$",
"this",
"->",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"input_id",
";",
"}"
] | Get the id to use in all inputs for this Image
@return string Either a model id or an arbitrary number prefixed by _ | [
"Get",
"the",
"id",
"to",
"use",
"in",
"all",
"inputs",
"for",
"this",
"Image"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Image.php#L263-L277 |
30,861 | BKWLD/decoy | classes/Fields/Image.php | Image.forElement | public function forElement(Element $el)
{
// Add help
$this->model($el)->blockhelp($el->help);
// Populate the image array with the image instance. This will create an
// Image instance from the default value if it doesn't exist.
$pop = app('former.populator')->all();
$pop['images'][$this->inputId()] = $el->img();
app('former.populator')->replace($pop);
// Support chaining
return $this;
} | php | public function forElement(Element $el)
{
// Add help
$this->model($el)->blockhelp($el->help);
// Populate the image array with the image instance. This will create an
// Image instance from the default value if it doesn't exist.
$pop = app('former.populator')->all();
$pop['images'][$this->inputId()] = $el->img();
app('former.populator')->replace($pop);
// Support chaining
return $this;
} | [
"public",
"function",
"forElement",
"(",
"Element",
"$",
"el",
")",
"{",
"// Add help",
"$",
"this",
"->",
"model",
"(",
"$",
"el",
")",
"->",
"blockhelp",
"(",
"$",
"el",
"->",
"help",
")",
";",
"// Populate the image array with the image instance. This will create an",
"// Image instance from the default value if it doesn't exist.",
"$",
"pop",
"=",
"app",
"(",
"'former.populator'",
")",
"->",
"all",
"(",
")",
";",
"$",
"pop",
"[",
"'images'",
"]",
"[",
"$",
"this",
"->",
"inputId",
"(",
")",
"]",
"=",
"$",
"el",
"->",
"img",
"(",
")",
";",
"app",
"(",
"'former.populator'",
")",
"->",
"replace",
"(",
"$",
"pop",
")",
";",
"// Support chaining",
"return",
"$",
"this",
";",
"}"
] | Logic for rendering an Image field for editing Element images
@param Element $element
@return $this | [
"Logic",
"for",
"rendering",
"an",
"Image",
"field",
"for",
"editing",
"Element",
"images"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Image.php#L325-L338 |
30,862 | bovigo/callmap | src/main/php/CallMap.php | CallMap.hasResultFor | public function hasResultFor(string $method, int $invocationCount): bool
{
if (!array_key_exists($method, $this->callMap)) {
return false;
}
if ($this->callMap[$method] instanceof InvocationResults) {
return $this->callMap[$method]->hasResultForInvocation($invocationCount - 1);
}
return true;
} | php | public function hasResultFor(string $method, int $invocationCount): bool
{
if (!array_key_exists($method, $this->callMap)) {
return false;
}
if ($this->callMap[$method] instanceof InvocationResults) {
return $this->callMap[$method]->hasResultForInvocation($invocationCount - 1);
}
return true;
} | [
"public",
"function",
"hasResultFor",
"(",
"string",
"$",
"method",
",",
"int",
"$",
"invocationCount",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"callMap",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"callMap",
"[",
"$",
"method",
"]",
"instanceof",
"InvocationResults",
")",
"{",
"return",
"$",
"this",
"->",
"callMap",
"[",
"$",
"method",
"]",
"->",
"hasResultForInvocation",
"(",
"$",
"invocationCount",
"-",
"1",
")",
";",
"}",
"return",
"true",
";",
"}"
] | checks whether callmap has a result for the invocation of method
@param string $method name of invoked method
@param int $invocationCount denotes which nth invocation of the method this is
@return bool | [
"checks",
"whether",
"callmap",
"has",
"a",
"result",
"for",
"the",
"invocation",
"of",
"method"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/CallMap.php#L41-L52 |
30,863 | bovigo/callmap | src/main/php/CallMap.php | CallMap.resultFor | public function resultFor(string $method, array $arguments, int $invocationCount)
{
if (!isset($this->callMap[$method])) {
return null;
}
if ($this->callMap[$method] instanceof InvocationResults) {
$result = $this->callMap[$method]->resultForInvocation($invocationCount - 1);
} else {
$result = $this->callMap[$method];
}
if (is_callable($result)) {
return $result(...$arguments);
}
return $result;
} | php | public function resultFor(string $method, array $arguments, int $invocationCount)
{
if (!isset($this->callMap[$method])) {
return null;
}
if ($this->callMap[$method] instanceof InvocationResults) {
$result = $this->callMap[$method]->resultForInvocation($invocationCount - 1);
} else {
$result = $this->callMap[$method];
}
if (is_callable($result)) {
return $result(...$arguments);
}
return $result;
} | [
"public",
"function",
"resultFor",
"(",
"string",
"$",
"method",
",",
"array",
"$",
"arguments",
",",
"int",
"$",
"invocationCount",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"callMap",
"[",
"$",
"method",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"callMap",
"[",
"$",
"method",
"]",
"instanceof",
"InvocationResults",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"callMap",
"[",
"$",
"method",
"]",
"->",
"resultForInvocation",
"(",
"$",
"invocationCount",
"-",
"1",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"callMap",
"[",
"$",
"method",
"]",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"result",
")",
")",
"{",
"return",
"$",
"result",
"(",
"...",
"$",
"arguments",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | returns the result for the method invocation done with given arguments
@param string $method name of invoked method
@param mixed[] $arguments arguments passed for the method call
@param int $invocationCount denotes which nth invocation of the method this is
@return mixed
@throws \Exception | [
"returns",
"the",
"result",
"for",
"the",
"method",
"invocation",
"done",
"with",
"given",
"arguments"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/CallMap.php#L63-L80 |
30,864 | bovigo/callmap | src/main/php/NewCallable.php | NewCallable.callMapClass | private static function callMapClass(string $function): \ReflectionClass
{
if (!isset(self::$functions[$function])) {
self::$functions[$function] = self::forkCallMapClass(
new \ReflectionFunction($function)
);
}
return self::$functions[$function];
} | php | private static function callMapClass(string $function): \ReflectionClass
{
if (!isset(self::$functions[$function])) {
self::$functions[$function] = self::forkCallMapClass(
new \ReflectionFunction($function)
);
}
return self::$functions[$function];
} | [
"private",
"static",
"function",
"callMapClass",
"(",
"string",
"$",
"function",
")",
":",
"\\",
"ReflectionClass",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"functions",
"[",
"$",
"function",
"]",
")",
")",
"{",
"self",
"::",
"$",
"functions",
"[",
"$",
"function",
"]",
"=",
"self",
"::",
"forkCallMapClass",
"(",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"function",
")",
")",
";",
"}",
"return",
"self",
"::",
"$",
"functions",
"[",
"$",
"function",
"]",
";",
"}"
] | returns the proxy class for given function
@param string $function
@return \ReflectionClass | [
"returns",
"the",
"proxy",
"class",
"for",
"given",
"function"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/NewCallable.php#L64-L73 |
30,865 | bovigo/callmap | src/main/php/NewCallable.php | NewCallable.forkCallMapClass | private static function forkCallMapClass(\ReflectionFunction $function): \ReflectionClass
{
try {
$compile = self::$compile;
$compile(self::createProxyCode($function));
} catch (\ParseError $pe) {
throw new ProxyCreationFailure(
'Failure while creating callable CallMap instance of '
. $function->getName() . '(): ' . $pe->getMessage(),
$pe
);
}
return new \ReflectionClass($function->getName() . 'CallMapProxy');
} | php | private static function forkCallMapClass(\ReflectionFunction $function): \ReflectionClass
{
try {
$compile = self::$compile;
$compile(self::createProxyCode($function));
} catch (\ParseError $pe) {
throw new ProxyCreationFailure(
'Failure while creating callable CallMap instance of '
. $function->getName() . '(): ' . $pe->getMessage(),
$pe
);
}
return new \ReflectionClass($function->getName() . 'CallMapProxy');
} | [
"private",
"static",
"function",
"forkCallMapClass",
"(",
"\\",
"ReflectionFunction",
"$",
"function",
")",
":",
"\\",
"ReflectionClass",
"{",
"try",
"{",
"$",
"compile",
"=",
"self",
"::",
"$",
"compile",
";",
"$",
"compile",
"(",
"self",
"::",
"createProxyCode",
"(",
"$",
"function",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"ParseError",
"$",
"pe",
")",
"{",
"throw",
"new",
"ProxyCreationFailure",
"(",
"'Failure while creating callable CallMap instance of '",
".",
"$",
"function",
"->",
"getName",
"(",
")",
".",
"'(): '",
".",
"$",
"pe",
"->",
"getMessage",
"(",
")",
",",
"$",
"pe",
")",
";",
"}",
"return",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"function",
"->",
"getName",
"(",
")",
".",
"'CallMapProxy'",
")",
";",
"}"
] | creates a new class from the given function which uses the CallMap trait
@param \ReflectionFunction $function
@return \ReflectionClass
@throws ProxyCreationFailure | [
"creates",
"a",
"new",
"class",
"from",
"the",
"given",
"function",
"which",
"uses",
"the",
"CallMap",
"trait"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/NewCallable.php#L90-L104 |
30,866 | gocom/rah_flat | src/Rah/Flat.php | Rah_Flat.import | public function import()
{
$skin = \Txp::get('\Textpattern\Skin\Skin');
$skin->setNames(array_keys((array)$skin->getUploaded()))->import(true, true);
} | php | public function import()
{
$skin = \Txp::get('\Textpattern\Skin\Skin');
$skin->setNames(array_keys((array)$skin->getUploaded()))->import(true, true);
} | [
"public",
"function",
"import",
"(",
")",
"{",
"$",
"skin",
"=",
"\\",
"Txp",
"::",
"get",
"(",
"'\\Textpattern\\Skin\\Skin'",
")",
";",
"$",
"skin",
"->",
"setNames",
"(",
"array_keys",
"(",
"(",
"array",
")",
"$",
"skin",
"->",
"getUploaded",
"(",
")",
")",
")",
"->",
"import",
"(",
"true",
",",
"true",
")",
";",
"}"
] | Imports themes.
@return void | [
"Imports",
"themes",
"."
] | 2af2f68ffa1d65151302032a4bbab0bf4f6503d0 | https://github.com/gocom/rah_flat/blob/2af2f68ffa1d65151302032a4bbab0bf4f6503d0/src/Rah/Flat.php#L49-L53 |
30,867 | bovigo/callmap | src/main/php/Verification.php | Verification.wasCalledAtLeastOnce | public function wasCalledAtLeastOnce(): bool
{
if (count($this->invocations) < 1) {
throw new CallAmountViolation(sprintf(
'%s was expected to be called at least once,'
. ' but was never called.',
$this->invocations->name()
));
}
return true;
} | php | public function wasCalledAtLeastOnce(): bool
{
if (count($this->invocations) < 1) {
throw new CallAmountViolation(sprintf(
'%s was expected to be called at least once,'
. ' but was never called.',
$this->invocations->name()
));
}
return true;
} | [
"public",
"function",
"wasCalledAtLeastOnce",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"invocations",
")",
"<",
"1",
")",
"{",
"throw",
"new",
"CallAmountViolation",
"(",
"sprintf",
"(",
"'%s was expected to be called at least once,'",
".",
"' but was never called.'",
",",
"$",
"this",
"->",
"invocations",
"->",
"name",
"(",
")",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | verifies that the method on the class was called at least once
@api
@return bool
@throws \bovigo\callmap\CallAmountViolation | [
"verifies",
"that",
"the",
"method",
"on",
"the",
"class",
"was",
"called",
"at",
"least",
"once"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/Verification.php#L63-L74 |
30,868 | bovigo/callmap | src/main/php/Verification.php | Verification.wasCalledOnce | public function wasCalledOnce(): bool
{
$callsReceived = count($this->invocations);
if (1 !== $callsReceived) {
throw new CallAmountViolation(sprintf(
'%s was expected to be called once, but actually %s.',
$this->invocations->name(),
1 < $callsReceived ?
'called ' . $callsReceived . ' time(s)' :
'never called'
));
}
return true;
} | php | public function wasCalledOnce(): bool
{
$callsReceived = count($this->invocations);
if (1 !== $callsReceived) {
throw new CallAmountViolation(sprintf(
'%s was expected to be called once, but actually %s.',
$this->invocations->name(),
1 < $callsReceived ?
'called ' . $callsReceived . ' time(s)' :
'never called'
));
}
return true;
} | [
"public",
"function",
"wasCalledOnce",
"(",
")",
":",
"bool",
"{",
"$",
"callsReceived",
"=",
"count",
"(",
"$",
"this",
"->",
"invocations",
")",
";",
"if",
"(",
"1",
"!==",
"$",
"callsReceived",
")",
"{",
"throw",
"new",
"CallAmountViolation",
"(",
"sprintf",
"(",
"'%s was expected to be called once, but actually %s.'",
",",
"$",
"this",
"->",
"invocations",
"->",
"name",
"(",
")",
",",
"1",
"<",
"$",
"callsReceived",
"?",
"'called '",
".",
"$",
"callsReceived",
".",
"' time(s)'",
":",
"'never called'",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | verifies that the method on the class was called exactly once
@api
@return bool
@throws \bovigo\callmap\CallAmountViolation | [
"verifies",
"that",
"the",
"method",
"on",
"the",
"class",
"was",
"called",
"exactly",
"once"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/Verification.php#L106-L121 |
30,869 | bovigo/callmap | src/main/php/Verification.php | Verification.wasNeverCalled | public function wasNeverCalled(): bool
{
if (count($this->invocations) > 0) {
throw new CallAmountViolation(sprintf(
'%s was not expected to be called,'
. ' but actually called %d time(s).',
$this->invocations->name(),
count($this->invocations)
));
}
return true;
} | php | public function wasNeverCalled(): bool
{
if (count($this->invocations) > 0) {
throw new CallAmountViolation(sprintf(
'%s was not expected to be called,'
. ' but actually called %d time(s).',
$this->invocations->name(),
count($this->invocations)
));
}
return true;
} | [
"public",
"function",
"wasNeverCalled",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"invocations",
")",
">",
"0",
")",
"{",
"throw",
"new",
"CallAmountViolation",
"(",
"sprintf",
"(",
"'%s was not expected to be called,'",
".",
"' but actually called %d time(s).'",
",",
"$",
"this",
"->",
"invocations",
"->",
"name",
"(",
")",
",",
"count",
"(",
"$",
"this",
"->",
"invocations",
")",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | verifies that the method on the class was never called
@api
@return bool
@throws \bovigo\callmap\CallAmountViolation | [
"verifies",
"that",
"the",
"method",
"on",
"the",
"class",
"was",
"never",
"called"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/Verification.php#L153-L165 |
30,870 | bovigo/callmap | src/main/php/Verification.php | Verification.receivedNothing | public function receivedNothing(int $invocation = 1): bool
{
$received = $this->invocations->argumentsOf($invocation);
if (count($received) === 0) {
return true;
}
throw new ArgumentMismatch(sprintf(
'Argument count for invocation #%d of %s is too'
. ' high: received %d argument(s), expected no arguments.',
$invocation,
$this->invocations->name(),
count($received)
));
} | php | public function receivedNothing(int $invocation = 1): bool
{
$received = $this->invocations->argumentsOf($invocation);
if (count($received) === 0) {
return true;
}
throw new ArgumentMismatch(sprintf(
'Argument count for invocation #%d of %s is too'
. ' high: received %d argument(s), expected no arguments.',
$invocation,
$this->invocations->name(),
count($received)
));
} | [
"public",
"function",
"receivedNothing",
"(",
"int",
"$",
"invocation",
"=",
"1",
")",
":",
"bool",
"{",
"$",
"received",
"=",
"$",
"this",
"->",
"invocations",
"->",
"argumentsOf",
"(",
"$",
"invocation",
")",
";",
"if",
"(",
"count",
"(",
"$",
"received",
")",
"===",
"0",
")",
"{",
"return",
"true",
";",
"}",
"throw",
"new",
"ArgumentMismatch",
"(",
"sprintf",
"(",
"'Argument count for invocation #%d of %s is too'",
".",
"' high: received %d argument(s), expected no arguments.'",
",",
"$",
"invocation",
",",
"$",
"this",
"->",
"invocations",
"->",
"name",
"(",
")",
",",
"count",
"(",
"$",
"received",
")",
")",
")",
";",
"}"
] | verifies that the method received nothing on the given invocation
@api
@param int $invocation optional nth invocation to check, defaults to 1 aka first invocation
@return bool
@throws \bovigo\callmap\ArgumentMismatch | [
"verifies",
"that",
"the",
"method",
"received",
"nothing",
"on",
"the",
"given",
"invocation"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/Verification.php#L175-L189 |
30,871 | bovigo/callmap | src/main/php/Verification.php | Verification.verifyArgs | private function verifyArgs(int $invocation, array $expected): bool
{
$received = $this->invocations->argumentsOf($invocation);
if (count($received) < count($expected)) {
throw new ArgumentMismatch(sprintf(
'Argument count for invocation #%d of %s is too'
. ' low: received %d argument(s), expected %d argument(s).',
$invocation,
$this->invocations->name(),
count($received),
count($expected)
));
}
foreach ($expected as $atPosition => $constraint) {
$this->evaluate(
$constraint,
$received[$atPosition] ?? null,
sprintf(
'Parameter %sat position %d for invocation #%d of %s'
. ' does not match expected value.',
$this->invocations->argumentName($atPosition, ' '),
$atPosition,
$invocation,
$this->invocations->name()
)
);
}
return true;
} | php | private function verifyArgs(int $invocation, array $expected): bool
{
$received = $this->invocations->argumentsOf($invocation);
if (count($received) < count($expected)) {
throw new ArgumentMismatch(sprintf(
'Argument count for invocation #%d of %s is too'
. ' low: received %d argument(s), expected %d argument(s).',
$invocation,
$this->invocations->name(),
count($received),
count($expected)
));
}
foreach ($expected as $atPosition => $constraint) {
$this->evaluate(
$constraint,
$received[$atPosition] ?? null,
sprintf(
'Parameter %sat position %d for invocation #%d of %s'
. ' does not match expected value.',
$this->invocations->argumentName($atPosition, ' '),
$atPosition,
$invocation,
$this->invocations->name()
)
);
}
return true;
} | [
"private",
"function",
"verifyArgs",
"(",
"int",
"$",
"invocation",
",",
"array",
"$",
"expected",
")",
":",
"bool",
"{",
"$",
"received",
"=",
"$",
"this",
"->",
"invocations",
"->",
"argumentsOf",
"(",
"$",
"invocation",
")",
";",
"if",
"(",
"count",
"(",
"$",
"received",
")",
"<",
"count",
"(",
"$",
"expected",
")",
")",
"{",
"throw",
"new",
"ArgumentMismatch",
"(",
"sprintf",
"(",
"'Argument count for invocation #%d of %s is too'",
".",
"' low: received %d argument(s), expected %d argument(s).'",
",",
"$",
"invocation",
",",
"$",
"this",
"->",
"invocations",
"->",
"name",
"(",
")",
",",
"count",
"(",
"$",
"received",
")",
",",
"count",
"(",
"$",
"expected",
")",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"expected",
"as",
"$",
"atPosition",
"=>",
"$",
"constraint",
")",
"{",
"$",
"this",
"->",
"evaluate",
"(",
"$",
"constraint",
",",
"$",
"received",
"[",
"$",
"atPosition",
"]",
"??",
"null",
",",
"sprintf",
"(",
"'Parameter %sat position %d for invocation #%d of %s'",
".",
"' does not match expected value.'",
",",
"$",
"this",
"->",
"invocations",
"->",
"argumentName",
"(",
"$",
"atPosition",
",",
"' '",
")",
",",
"$",
"atPosition",
",",
"$",
"invocation",
",",
"$",
"this",
"->",
"invocations",
"->",
"name",
"(",
")",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | verifies arguments of given invocation with the expected constraints
If a constraint is not an instance of PHPUnit\Framework\Constraint\Constraint it
will automatically use PHPUnit\Framework\Constraint\IsEqual.
@param int $invocation number of invocation to check
@param array $expected constraints which describe expected parameters
@return bool
@throws \bovigo\callmap\ArgumentMismatch | [
"verifies",
"arguments",
"of",
"given",
"invocation",
"with",
"the",
"expected",
"constraints"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/Verification.php#L233-L263 |
30,872 | bovigo/callmap | src/main/php/Verification.php | Verification.evaluate | private function evaluate($constraint, $received, string $description): bool
{
if (function_exists('bovigo\assert\assertThat')) {
return \bovigo\assert\assertThat(
$received,
$this->predicateFor($constraint),
$description
);
}
if (class_exists('\PHPUnit\Framework\Constraint\IsEqual')) {
return $this->evaluateWithPhpUnit($constraint, $received, $description);
}
if (class_exists('\unittest\TestCase')) {
return $this->evaluateWithXpFrameworkCore($constraint, $received, $description);
}
throw new \RuntimeException('Neither bovigo/assert, PHPUnit nor xp-framework/unittest found, can not perform argument verification');
} | php | private function evaluate($constraint, $received, string $description): bool
{
if (function_exists('bovigo\assert\assertThat')) {
return \bovigo\assert\assertThat(
$received,
$this->predicateFor($constraint),
$description
);
}
if (class_exists('\PHPUnit\Framework\Constraint\IsEqual')) {
return $this->evaluateWithPhpUnit($constraint, $received, $description);
}
if (class_exists('\unittest\TestCase')) {
return $this->evaluateWithXpFrameworkCore($constraint, $received, $description);
}
throw new \RuntimeException('Neither bovigo/assert, PHPUnit nor xp-framework/unittest found, can not perform argument verification');
} | [
"private",
"function",
"evaluate",
"(",
"$",
"constraint",
",",
"$",
"received",
",",
"string",
"$",
"description",
")",
":",
"bool",
"{",
"if",
"(",
"function_exists",
"(",
"'bovigo\\assert\\assertThat'",
")",
")",
"{",
"return",
"\\",
"bovigo",
"\\",
"assert",
"\\",
"assertThat",
"(",
"$",
"received",
",",
"$",
"this",
"->",
"predicateFor",
"(",
"$",
"constraint",
")",
",",
"$",
"description",
")",
";",
"}",
"if",
"(",
"class_exists",
"(",
"'\\PHPUnit\\Framework\\Constraint\\IsEqual'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"evaluateWithPhpUnit",
"(",
"$",
"constraint",
",",
"$",
"received",
",",
"$",
"description",
")",
";",
"}",
"if",
"(",
"class_exists",
"(",
"'\\unittest\\TestCase'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"evaluateWithXpFrameworkCore",
"(",
"$",
"constraint",
",",
"$",
"received",
",",
"$",
"description",
")",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Neither bovigo/assert, PHPUnit nor xp-framework/unittest found, can not perform argument verification'",
")",
";",
"}"
] | evaluates given constraint given received argument
@param mixed|\bovigo\assert\predicate\Predicate|\PHPUnit\Framework\Constraint\Constraint $constraint constraint for argument
@param mixed $received actually received argument
@param string $description description for invocation in case of error
@return bool
@throws \RuntimeException in case neither bovigo/assert, PHPUnit not xp-framework/unittest is present | [
"evaluates",
"given",
"constraint",
"given",
"received",
"argument"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/Verification.php#L274-L293 |
30,873 | bovigo/callmap | src/main/php/Verification.php | Verification.predicateFor | private function predicateFor($constraint): \bovigo\assert\predicate\Predicate
{
if ($constraint instanceof \PHPUnit\Framework\Constraint\Constraint) {
return new \bovigo\assert\phpunit\ConstraintAdapter($constraint);
}
if ($constraint instanceof \bovigo\assert\predicate\Predicate) {
return $constraint;
}
return \bovigo\assert\predicate\equals($constraint);
} | php | private function predicateFor($constraint): \bovigo\assert\predicate\Predicate
{
if ($constraint instanceof \PHPUnit\Framework\Constraint\Constraint) {
return new \bovigo\assert\phpunit\ConstraintAdapter($constraint);
}
if ($constraint instanceof \bovigo\assert\predicate\Predicate) {
return $constraint;
}
return \bovigo\assert\predicate\equals($constraint);
} | [
"private",
"function",
"predicateFor",
"(",
"$",
"constraint",
")",
":",
"\\",
"bovigo",
"\\",
"assert",
"\\",
"predicate",
"\\",
"Predicate",
"{",
"if",
"(",
"$",
"constraint",
"instanceof",
"\\",
"PHPUnit",
"\\",
"Framework",
"\\",
"Constraint",
"\\",
"Constraint",
")",
"{",
"return",
"new",
"\\",
"bovigo",
"\\",
"assert",
"\\",
"phpunit",
"\\",
"ConstraintAdapter",
"(",
"$",
"constraint",
")",
";",
"}",
"if",
"(",
"$",
"constraint",
"instanceof",
"\\",
"bovigo",
"\\",
"assert",
"\\",
"predicate",
"\\",
"Predicate",
")",
"{",
"return",
"$",
"constraint",
";",
"}",
"return",
"\\",
"bovigo",
"\\",
"assert",
"\\",
"predicate",
"\\",
"equals",
"(",
"$",
"constraint",
")",
";",
"}"
] | creates precicate for given constraint
@param mixed|\bovigo\assert\predicate\Predicate|\PHPUnit\Framework\Constraint\Constraint $constraint
@return \bovigo\assert\predicate\Predicate | [
"creates",
"precicate",
"for",
"given",
"constraint"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/Verification.php#L301-L312 |
30,874 | bovigo/callmap | src/main/php/Verification.php | Verification.evaluateWithPhpUnit | protected function evaluateWithPhpUnit($constraint, $received, string $description): bool
{
if ($constraint instanceof \PHPUnit\Framework\Constraint\Constraint) {
return $constraint->evaluate($received, $description);
}
return (new \PHPUnit\Framework\Constraint\IsEqual($constraint))
->evaluate($received, $description);
} | php | protected function evaluateWithPhpUnit($constraint, $received, string $description): bool
{
if ($constraint instanceof \PHPUnit\Framework\Constraint\Constraint) {
return $constraint->evaluate($received, $description);
}
return (new \PHPUnit\Framework\Constraint\IsEqual($constraint))
->evaluate($received, $description);
} | [
"protected",
"function",
"evaluateWithPhpUnit",
"(",
"$",
"constraint",
",",
"$",
"received",
",",
"string",
"$",
"description",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"constraint",
"instanceof",
"\\",
"PHPUnit",
"\\",
"Framework",
"\\",
"Constraint",
"\\",
"Constraint",
")",
"{",
"return",
"$",
"constraint",
"->",
"evaluate",
"(",
"$",
"received",
",",
"$",
"description",
")",
";",
"}",
"return",
"(",
"new",
"\\",
"PHPUnit",
"\\",
"Framework",
"\\",
"Constraint",
"\\",
"IsEqual",
"(",
"$",
"constraint",
")",
")",
"->",
"evaluate",
"(",
"$",
"received",
",",
"$",
"description",
")",
";",
"}"
] | evaluates given constraint using PHPUnit
If given constraint is not a instance of \PHPUnit\Framework\Constraint\Constraint it
will be wrapped with \PHPUnit\Framework\Constraint\IsEqual.
@param mixed|\PHPUnit\Framework\Constraint\Constraint $constraint constraint for argument
@param mixed $received actually received argument
@param string $description description for invocation in case of error
@return bool | [
"evaluates",
"given",
"constraint",
"using",
"PHPUnit"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/Verification.php#L325-L333 |
30,875 | dshanske/parse-this | includes/class-parse-this-mf2.php | Parse_This_MF2.is_type | public static function is_type( $mf, $type ) {
return is_array( $mf ) && ! empty( $mf['type'] ) && is_array( $mf['type'] ) && in_array( $type, $mf['type'], true );
} | php | public static function is_type( $mf, $type ) {
return is_array( $mf ) && ! empty( $mf['type'] ) && is_array( $mf['type'] ) && in_array( $type, $mf['type'], true );
} | [
"public",
"static",
"function",
"is_type",
"(",
"$",
"mf",
",",
"$",
"type",
")",
"{",
"return",
"is_array",
"(",
"$",
"mf",
")",
"&&",
"!",
"empty",
"(",
"$",
"mf",
"[",
"'type'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"mf",
"[",
"'type'",
"]",
")",
"&&",
"in_array",
"(",
"$",
"type",
",",
"$",
"mf",
"[",
"'type'",
"]",
",",
"true",
")",
";",
"}"
] | is this what type
@param array $mf Parsed Microformats Array
@param string $type Type
@return bool | [
"is",
"this",
"what",
"type"
] | 722154e91fe47bca185256bd6388324de7bea012 | https://github.com/dshanske/parse-this/blob/722154e91fe47bca185256bd6388324de7bea012/includes/class-parse-this-mf2.php#L18-L20 |
30,876 | dshanske/parse-this | includes/class-parse-this-mf2.php | Parse_This_MF2.get_prop | public static function get_prop( array $mf, $propname, $fallback = null ) {
return self::get_plaintext( $mf, $propname, $fallback );
} | php | public static function get_prop( array $mf, $propname, $fallback = null ) {
return self::get_plaintext( $mf, $propname, $fallback );
} | [
"public",
"static",
"function",
"get_prop",
"(",
"array",
"$",
"mf",
",",
"$",
"propname",
",",
"$",
"fallback",
"=",
"null",
")",
"{",
"return",
"self",
"::",
"get_plaintext",
"(",
"$",
"mf",
",",
"$",
"propname",
",",
"$",
"fallback",
")",
";",
"}"
] | shortcut for getPlaintext.
@deprecated use getPlaintext from now on
@param array $mf
@param $propname
@param null|string $fallback
@return mixed|null | [
"shortcut",
"for",
"getPlaintext",
"."
] | 722154e91fe47bca185256bd6388324de7bea012 | https://github.com/dshanske/parse-this/blob/722154e91fe47bca185256bd6388324de7bea012/includes/class-parse-this-mf2.php#L117-L119 |
30,877 | dshanske/parse-this | includes/class-parse-this-mf2.php | Parse_This_MF2.get_prop_array | public static function get_prop_array( array $mf, $properties, $args = null ) {
if ( ! self::is_microformat( $mf ) ) {
return array();
}
$data = array();
foreach ( $properties as $p ) {
if ( array_key_exists( $p, $mf['properties'] ) ) {
foreach ( $mf['properties'][ $p ] as $v ) {
if ( self::is_microformat( $v ) ) {
$data[ $p ] = self::parse_item( $v, $mf, $args );
} else {
if ( isset( $data[ $p ] ) ) {
$data[ $p ][] = $v;
} else {
$data[ $p ] = array( $v );
}
}
}
}
}
return $data;
} | php | public static function get_prop_array( array $mf, $properties, $args = null ) {
if ( ! self::is_microformat( $mf ) ) {
return array();
}
$data = array();
foreach ( $properties as $p ) {
if ( array_key_exists( $p, $mf['properties'] ) ) {
foreach ( $mf['properties'][ $p ] as $v ) {
if ( self::is_microformat( $v ) ) {
$data[ $p ] = self::parse_item( $v, $mf, $args );
} else {
if ( isset( $data[ $p ] ) ) {
$data[ $p ][] = $v;
} else {
$data[ $p ] = array( $v );
}
}
}
}
}
return $data;
} | [
"public",
"static",
"function",
"get_prop_array",
"(",
"array",
"$",
"mf",
",",
"$",
"properties",
",",
"$",
"args",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"is_microformat",
"(",
"$",
"mf",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"p",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"p",
",",
"$",
"mf",
"[",
"'properties'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"mf",
"[",
"'properties'",
"]",
"[",
"$",
"p",
"]",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"self",
"::",
"is_microformat",
"(",
"$",
"v",
")",
")",
"{",
"$",
"data",
"[",
"$",
"p",
"]",
"=",
"self",
"::",
"parse_item",
"(",
"$",
"v",
",",
"$",
"mf",
",",
"$",
"args",
")",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"p",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"p",
"]",
"[",
"]",
"=",
"$",
"v",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"p",
"]",
"=",
"array",
"(",
"$",
"v",
")",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Return an array of properties, and may contain plaintext content
@param array $mf
@param array $properties
@return null|array | [
"Return",
"an",
"array",
"of",
"properties",
"and",
"may",
"contain",
"plaintext",
"content"
] | 722154e91fe47bca185256bd6388324de7bea012 | https://github.com/dshanske/parse-this/blob/722154e91fe47bca185256bd6388324de7bea012/includes/class-parse-this-mf2.php#L173-L195 |
30,878 | dshanske/parse-this | includes/class-parse-this-mf2.php | Parse_This_MF2.get_datetime_property | public static function get_datetime_property( $name, array $mf, $ensurevalid = false, $fallback = null ) {
$compliment = 'published' === $name ? 'updated' : 'published';
if ( self::has_prop( $mf, $name ) ) {
$return = self::get_prop( $mf, $name ); } elseif ( self::has_prop( $mf, $compliment ) ) {
$return = self::get_prop( $mf, $compliment );
} else {
return $fallback; }
if ( ! $ensurevalid ) {
return $return; } else {
try {
$date = new DateTime( $return );
return $date->format( DATE_W3C );
} catch ( Exception $e ) {
return $fallback;
}
}
} | php | public static function get_datetime_property( $name, array $mf, $ensurevalid = false, $fallback = null ) {
$compliment = 'published' === $name ? 'updated' : 'published';
if ( self::has_prop( $mf, $name ) ) {
$return = self::get_prop( $mf, $name ); } elseif ( self::has_prop( $mf, $compliment ) ) {
$return = self::get_prop( $mf, $compliment );
} else {
return $fallback; }
if ( ! $ensurevalid ) {
return $return; } else {
try {
$date = new DateTime( $return );
return $date->format( DATE_W3C );
} catch ( Exception $e ) {
return $fallback;
}
}
} | [
"public",
"static",
"function",
"get_datetime_property",
"(",
"$",
"name",
",",
"array",
"$",
"mf",
",",
"$",
"ensurevalid",
"=",
"false",
",",
"$",
"fallback",
"=",
"null",
")",
"{",
"$",
"compliment",
"=",
"'published'",
"===",
"$",
"name",
"?",
"'updated'",
":",
"'published'",
";",
"if",
"(",
"self",
"::",
"has_prop",
"(",
"$",
"mf",
",",
"$",
"name",
")",
")",
"{",
"$",
"return",
"=",
"self",
"::",
"get_prop",
"(",
"$",
"mf",
",",
"$",
"name",
")",
";",
"}",
"elseif",
"(",
"self",
"::",
"has_prop",
"(",
"$",
"mf",
",",
"$",
"compliment",
")",
")",
"{",
"$",
"return",
"=",
"self",
"::",
"get_prop",
"(",
"$",
"mf",
",",
"$",
"compliment",
")",
";",
"}",
"else",
"{",
"return",
"$",
"fallback",
";",
"}",
"if",
"(",
"!",
"$",
"ensurevalid",
")",
"{",
"return",
"$",
"return",
";",
"}",
"else",
"{",
"try",
"{",
"$",
"date",
"=",
"new",
"DateTime",
"(",
"$",
"return",
")",
";",
"return",
"$",
"date",
"->",
"format",
"(",
"DATE_W3C",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"fallback",
";",
"}",
"}",
"}"
] | Gets the DateTime properties including published or updated, depending on params.
@param $name string updated or published
@param array $mf
@param bool $ensurevalid
@param null|string $fallback
@return mixed|null | [
"Gets",
"the",
"DateTime",
"properties",
"including",
"published",
"or",
"updated",
"depending",
"on",
"params",
"."
] | 722154e91fe47bca185256bd6388324de7bea012 | https://github.com/dshanske/parse-this/blob/722154e91fe47bca185256bd6388324de7bea012/includes/class-parse-this-mf2.php#L282-L298 |
30,879 | dshanske/parse-this | includes/class-parse-this-mf2.php | Parse_This_MF2.parse_url | public static function parse_url( $url ) {
$r = wp_parse_url( $url );
$r['pathname'] = empty( $r['path'] ) ? '/' : $r['path'];
return $r;
} | php | public static function parse_url( $url ) {
$r = wp_parse_url( $url );
$r['pathname'] = empty( $r['path'] ) ? '/' : $r['path'];
return $r;
} | [
"public",
"static",
"function",
"parse_url",
"(",
"$",
"url",
")",
"{",
"$",
"r",
"=",
"wp_parse_url",
"(",
"$",
"url",
")",
";",
"$",
"r",
"[",
"'pathname'",
"]",
"=",
"empty",
"(",
"$",
"r",
"[",
"'path'",
"]",
")",
"?",
"'/'",
":",
"$",
"r",
"[",
"'path'",
"]",
";",
"return",
"$",
"r",
";",
"}"
] | Returns array per parse_url standard with pathname key added.
@param $url
@return mixed
@link http://php.net/manual/en/function.parse-url.php | [
"Returns",
"array",
"per",
"parse_url",
"standard",
"with",
"pathname",
"key",
"added",
"."
] | 722154e91fe47bca185256bd6388324de7bea012 | https://github.com/dshanske/parse-this/blob/722154e91fe47bca185256bd6388324de7bea012/includes/class-parse-this-mf2.php#L380-L384 |
30,880 | dshanske/parse-this | includes/class-parse-this-mf2.php | Parse_This_MF2.normalize_feed | public static function normalize_feed( $input ) {
$hcard = array();
foreach ( $input['items'] as $key => $item ) {
if ( self::is_type( $item, 'h-card' ) ) {
$hcard = $item;
unset( $input['items'][ $key ] );
break;
}
}
if ( 1 === count( $input['items'] ) ) {
if ( self::has_prop( $input['items'][0], 'author' ) ) {
$input['items'][0]['properties']['author'] = array( $hcard );
}
return $input;
}
return array(
'items' => array(
array(
'type' => array( 'h-feed' ),
'properties' => array(
'author' => array( $hcard ),
),
'children' => $input['items'],
),
),
);
} | php | public static function normalize_feed( $input ) {
$hcard = array();
foreach ( $input['items'] as $key => $item ) {
if ( self::is_type( $item, 'h-card' ) ) {
$hcard = $item;
unset( $input['items'][ $key ] );
break;
}
}
if ( 1 === count( $input['items'] ) ) {
if ( self::has_prop( $input['items'][0], 'author' ) ) {
$input['items'][0]['properties']['author'] = array( $hcard );
}
return $input;
}
return array(
'items' => array(
array(
'type' => array( 'h-feed' ),
'properties' => array(
'author' => array( $hcard ),
),
'children' => $input['items'],
),
),
);
} | [
"public",
"static",
"function",
"normalize_feed",
"(",
"$",
"input",
")",
"{",
"$",
"hcard",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"input",
"[",
"'items'",
"]",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"self",
"::",
"is_type",
"(",
"$",
"item",
",",
"'h-card'",
")",
")",
"{",
"$",
"hcard",
"=",
"$",
"item",
";",
"unset",
"(",
"$",
"input",
"[",
"'items'",
"]",
"[",
"$",
"key",
"]",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"1",
"===",
"count",
"(",
"$",
"input",
"[",
"'items'",
"]",
")",
")",
"{",
"if",
"(",
"self",
"::",
"has_prop",
"(",
"$",
"input",
"[",
"'items'",
"]",
"[",
"0",
"]",
",",
"'author'",
")",
")",
"{",
"$",
"input",
"[",
"'items'",
"]",
"[",
"0",
"]",
"[",
"'properties'",
"]",
"[",
"'author'",
"]",
"=",
"array",
"(",
"$",
"hcard",
")",
";",
"}",
"return",
"$",
"input",
";",
"}",
"return",
"array",
"(",
"'items'",
"=>",
"array",
"(",
"array",
"(",
"'type'",
"=>",
"array",
"(",
"'h-feed'",
")",
",",
"'properties'",
"=>",
"array",
"(",
"'author'",
"=>",
"array",
"(",
"$",
"hcard",
")",
",",
")",
",",
"'children'",
"=>",
"$",
"input",
"[",
"'items'",
"]",
",",
")",
",",
")",
",",
")",
";",
"}"
] | Tries to normalize a set of items into a feed | [
"Tries",
"to",
"normalize",
"a",
"set",
"of",
"items",
"into",
"a",
"feed"
] | 722154e91fe47bca185256bd6388324de7bea012 | https://github.com/dshanske/parse-this/blob/722154e91fe47bca185256bd6388324de7bea012/includes/class-parse-this-mf2.php#L610-L636 |
30,881 | GrahamCampbell/Laravel-TestBench-Core | src/HelperTrait.php | HelperTrait.assertInArray | public static function assertInArray($needle, array $haystack, string $msg = '')
{
if ($msg === '') {
$msg = "Expected the array to contain the element '$needle'.";
}
static::assertTrue(in_array($needle, $haystack, true), $msg);
} | php | public static function assertInArray($needle, array $haystack, string $msg = '')
{
if ($msg === '') {
$msg = "Expected the array to contain the element '$needle'.";
}
static::assertTrue(in_array($needle, $haystack, true), $msg);
} | [
"public",
"static",
"function",
"assertInArray",
"(",
"$",
"needle",
",",
"array",
"$",
"haystack",
",",
"string",
"$",
"msg",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"msg",
"===",
"''",
")",
"{",
"$",
"msg",
"=",
"\"Expected the array to contain the element '$needle'.\"",
";",
"}",
"static",
"::",
"assertTrue",
"(",
"in_array",
"(",
"$",
"needle",
",",
"$",
"haystack",
",",
"true",
")",
",",
"$",
"msg",
")",
";",
"}"
] | Assert that the element exists in the array.
@param mixed $needle
@param array $haystack
@param string $msg
@return void | [
"Assert",
"that",
"the",
"element",
"exists",
"in",
"the",
"array",
"."
] | 138218735a65f4532d6c4242a44ffa6c591bca09 | https://github.com/GrahamCampbell/Laravel-TestBench-Core/blob/138218735a65f4532d6c4242a44ffa6c591bca09/src/HelperTrait.php#L35-L42 |
30,882 | GrahamCampbell/Laravel-TestBench-Core | src/HelperTrait.php | HelperTrait.assertMethodExists | public static function assertMethodExists(string $method, string $class, string $msg = '')
{
if ($msg === '') {
$msg = "Expected the class '$class' to have method '$method'.";
}
static::assertTrue(method_exists($class, $method), $msg);
} | php | public static function assertMethodExists(string $method, string $class, string $msg = '')
{
if ($msg === '') {
$msg = "Expected the class '$class' to have method '$method'.";
}
static::assertTrue(method_exists($class, $method), $msg);
} | [
"public",
"static",
"function",
"assertMethodExists",
"(",
"string",
"$",
"method",
",",
"string",
"$",
"class",
",",
"string",
"$",
"msg",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"msg",
"===",
"''",
")",
"{",
"$",
"msg",
"=",
"\"Expected the class '$class' to have method '$method'.\"",
";",
"}",
"static",
"::",
"assertTrue",
"(",
"method_exists",
"(",
"$",
"class",
",",
"$",
"method",
")",
",",
"$",
"msg",
")",
";",
"}"
] | Assert that the specified method exists on the class.
@param string $method
@param string $class
@param string $msg
@return void | [
"Assert",
"that",
"the",
"specified",
"method",
"exists",
"on",
"the",
"class",
"."
] | 138218735a65f4532d6c4242a44ffa6c591bca09 | https://github.com/GrahamCampbell/Laravel-TestBench-Core/blob/138218735a65f4532d6c4242a44ffa6c591bca09/src/HelperTrait.php#L53-L60 |
30,883 | GrahamCampbell/Laravel-TestBench-Core | src/HelperTrait.php | HelperTrait.assertInJson | public static function assertInJson(string $needle, array $haystack, string $msg = '')
{
if ($msg === '') {
$msg = "Expected the array to contain the element '$needle'.";
}
$array = json_decode($needle, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new InvalidArgumentException("Invalid json provided: '$needle'.");
}
static::assertArraySubset($haystack, $array, false, $msg);
} | php | public static function assertInJson(string $needle, array $haystack, string $msg = '')
{
if ($msg === '') {
$msg = "Expected the array to contain the element '$needle'.";
}
$array = json_decode($needle, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new InvalidArgumentException("Invalid json provided: '$needle'.");
}
static::assertArraySubset($haystack, $array, false, $msg);
} | [
"public",
"static",
"function",
"assertInJson",
"(",
"string",
"$",
"needle",
",",
"array",
"$",
"haystack",
",",
"string",
"$",
"msg",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"msg",
"===",
"''",
")",
"{",
"$",
"msg",
"=",
"\"Expected the array to contain the element '$needle'.\"",
";",
"}",
"$",
"array",
"=",
"json_decode",
"(",
"$",
"needle",
",",
"true",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"!==",
"JSON_ERROR_NONE",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Invalid json provided: '$needle'.\"",
")",
";",
"}",
"static",
"::",
"assertArraySubset",
"(",
"$",
"haystack",
",",
"$",
"array",
",",
"false",
",",
"$",
"msg",
")",
";",
"}"
] | Assert that the element exists in the json.
@param string $needle
@param array $haystack
@param string $msg
@throws \InvalidArgumentException
@return void | [
"Assert",
"that",
"the",
"element",
"exists",
"in",
"the",
"json",
"."
] | 138218735a65f4532d6c4242a44ffa6c591bca09 | https://github.com/GrahamCampbell/Laravel-TestBench-Core/blob/138218735a65f4532d6c4242a44ffa6c591bca09/src/HelperTrait.php#L73-L86 |
30,884 | QuickenLoans/mcp-cache | src/Item/Item.php | Item.data | public function data(TimePoint $now = null)
{
if ($now && $this->isExpired($now)) {
return null;
}
return $this->data;
} | php | public function data(TimePoint $now = null)
{
if ($now && $this->isExpired($now)) {
return null;
}
return $this->data;
} | [
"public",
"function",
"data",
"(",
"TimePoint",
"$",
"now",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"now",
"&&",
"$",
"this",
"->",
"isExpired",
"(",
"$",
"now",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"data",
";",
"}"
] | If provided, the data will be checked for expiration.
@param TimePoint|null $now
@return mixed | [
"If",
"provided",
"the",
"data",
"will",
"be",
"checked",
"for",
"expiration",
"."
] | 2dba32705f85452cb9099e35e0241a6c7a98b717 | https://github.com/QuickenLoans/mcp-cache/blob/2dba32705f85452cb9099e35e0241a6c7a98b717/src/Item/Item.php#L67-L74 |
30,885 | GrahamCampbell/Laravel-TestBench-Core | src/MockeryTrait.php | MockeryTrait.tearDownMockery | public function tearDownMockery()
{
if (class_exists(Mockery::class, false)) {
$container = Mockery::getContainer();
if ($container) {
$this->addToAssertionCount($container->mockery_getExpectationCount());
}
Mockery::close();
}
} | php | public function tearDownMockery()
{
if (class_exists(Mockery::class, false)) {
$container = Mockery::getContainer();
if ($container) {
$this->addToAssertionCount($container->mockery_getExpectationCount());
}
Mockery::close();
}
} | [
"public",
"function",
"tearDownMockery",
"(",
")",
"{",
"if",
"(",
"class_exists",
"(",
"Mockery",
"::",
"class",
",",
"false",
")",
")",
"{",
"$",
"container",
"=",
"Mockery",
"::",
"getContainer",
"(",
")",
";",
"if",
"(",
"$",
"container",
")",
"{",
"$",
"this",
"->",
"addToAssertionCount",
"(",
"$",
"container",
"->",
"mockery_getExpectationCount",
"(",
")",
")",
";",
"}",
"Mockery",
"::",
"close",
"(",
")",
";",
"}",
"}"
] | Tear down mockery.
@after
@return void | [
"Tear",
"down",
"mockery",
"."
] | 138218735a65f4532d6c4242a44ffa6c591bca09 | https://github.com/GrahamCampbell/Laravel-TestBench-Core/blob/138218735a65f4532d6c4242a44ffa6c591bca09/src/MockeryTrait.php#L32-L43 |
30,886 | dshanske/parse-this | includes/class-parse-this-api.php | Parse_This_API.debug | public static function debug() {
?>
<div class="wrap">
<h2> <?php esc_html_e( 'Parse This Debugger', 'indieweb-post-kinds' ); ?> </h2>
<p> <?php esc_html_e( 'Test the Parse Tools Debugger. You can report sites to the developer for possibly improvement in future', 'parse-this' ); ?>
</p>
<a href="https://github.com/dshanske/parse-this/issues"><?php esc_html_e( 'Open an Issue', 'parse-this' ); ?></a>
<p>
<?php
if ( is_plugin_active( 'parse-this/parse-this.php' ) ) {
esc_html_e( 'You are using the plugin version of Parse This as opposed to a version built into any plugin', 'parse-this' );
}
?>
<hr />
<form method="get" action="<?php echo esc_url( rest_url( '/parse-this/1.0/parse/' ) ); ?> ">
<p><label for="url"><?php esc_html_e( 'URL', 'indieweb-post-kinds' ); ?></label><input type="url" class="widefat" name="url" id="url" /></p>
<p><label for="mf2"><?php esc_html_e( 'MF2', 'indieweb-post-kinds' ); ?></label><input type="checkbox" name="mf2" id="mf2" /></p>
<p><label for="discovery"><?php esc_html_e( 'Feed Discovery', 'indieweb-post-kinds' ); ?></label><input type="checkbox" name="discovery" id="discovery" /></p>
<p><label for"return"><?php esc_html_e( 'Return Type', 'indieweb-post-kinds' ); ?></label>
<select name="return">
<option value="single"><?php esc_html_e( 'Single', 'indieweb-post-kinds' ); ?></option>
<option value="feed"><?php esc_html_e( 'Feed', 'indieweb-post-kinds' ); ?></option>
</select>
</p>
<p><label for="follow"><?php esc_html_e( 'Follow Author Links', 'indieweb-post-kinds' ); ?></label><input type="checkbox" name="follow" id="follow" /></p>
<?php wp_nonce_field( 'wp_rest' ); ?>
<?php submit_button( __( 'Parse', 'indieweb-post-kinds' ) ); ?>
</form>
</div>
<?php
} | php | public static function debug() {
?>
<div class="wrap">
<h2> <?php esc_html_e( 'Parse This Debugger', 'indieweb-post-kinds' ); ?> </h2>
<p> <?php esc_html_e( 'Test the Parse Tools Debugger. You can report sites to the developer for possibly improvement in future', 'parse-this' ); ?>
</p>
<a href="https://github.com/dshanske/parse-this/issues"><?php esc_html_e( 'Open an Issue', 'parse-this' ); ?></a>
<p>
<?php
if ( is_plugin_active( 'parse-this/parse-this.php' ) ) {
esc_html_e( 'You are using the plugin version of Parse This as opposed to a version built into any plugin', 'parse-this' );
}
?>
<hr />
<form method="get" action="<?php echo esc_url( rest_url( '/parse-this/1.0/parse/' ) ); ?> ">
<p><label for="url"><?php esc_html_e( 'URL', 'indieweb-post-kinds' ); ?></label><input type="url" class="widefat" name="url" id="url" /></p>
<p><label for="mf2"><?php esc_html_e( 'MF2', 'indieweb-post-kinds' ); ?></label><input type="checkbox" name="mf2" id="mf2" /></p>
<p><label for="discovery"><?php esc_html_e( 'Feed Discovery', 'indieweb-post-kinds' ); ?></label><input type="checkbox" name="discovery" id="discovery" /></p>
<p><label for"return"><?php esc_html_e( 'Return Type', 'indieweb-post-kinds' ); ?></label>
<select name="return">
<option value="single"><?php esc_html_e( 'Single', 'indieweb-post-kinds' ); ?></option>
<option value="feed"><?php esc_html_e( 'Feed', 'indieweb-post-kinds' ); ?></option>
</select>
</p>
<p><label for="follow"><?php esc_html_e( 'Follow Author Links', 'indieweb-post-kinds' ); ?></label><input type="checkbox" name="follow" id="follow" /></p>
<?php wp_nonce_field( 'wp_rest' ); ?>
<?php submit_button( __( 'Parse', 'indieweb-post-kinds' ) ); ?>
</form>
</div>
<?php
} | [
"public",
"static",
"function",
"debug",
"(",
")",
"{",
"?>\n\t\t\t\t<div class=\"wrap\">\n\t\t\t\t\t\t<h2> <?php",
"esc_html_e",
"(",
"'Parse This Debugger'",
",",
"'indieweb-post-kinds'",
")",
";",
"?> </h2>\n\t\t\t\t\t\t<p> <?php",
"esc_html_e",
"(",
"'Test the Parse Tools Debugger. You can report sites to the developer for possibly improvement in future'",
",",
"'parse-this'",
")",
";",
"?>\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t<a href=\"https://github.com/dshanske/parse-this/issues\"><?php",
"esc_html_e",
"(",
"'Open an Issue'",
",",
"'parse-this'",
")",
";",
"?></a>\n\t\t\t\t\t\t\t<p> \n\t\t\t\t\t\t\t<?php",
"if",
"(",
"is_plugin_active",
"(",
"'parse-this/parse-this.php'",
")",
")",
"{",
"esc_html_e",
"(",
"'You are using the plugin version of Parse This as opposed to a version built into any plugin'",
",",
"'parse-this'",
")",
";",
"}",
"?>\n\t\t\t\t\t\t<hr />\n\t\t\t<form method=\"get\" action=\"<?php",
"echo",
"esc_url",
"(",
"rest_url",
"(",
"'/parse-this/1.0/parse/'",
")",
")",
";",
"?> \">\n\t\t\t<p><label for=\"url\"><?php",
"esc_html_e",
"(",
"'URL'",
",",
"'indieweb-post-kinds'",
")",
";",
"?></label><input type=\"url\" class=\"widefat\" name=\"url\" id=\"url\" /></p>\n\t\t\t<p><label for=\"mf2\"><?php",
"esc_html_e",
"(",
"'MF2'",
",",
"'indieweb-post-kinds'",
")",
";",
"?></label><input type=\"checkbox\" name=\"mf2\" id=\"mf2\" /></p>\n\t\t\t<p><label for=\"discovery\"><?php",
"esc_html_e",
"(",
"'Feed Discovery'",
",",
"'indieweb-post-kinds'",
")",
";",
"?></label><input type=\"checkbox\" name=\"discovery\" id=\"discovery\" /></p>\n\t\t\t<p><label for\"return\"><?php",
"esc_html_e",
"(",
"'Return Type'",
",",
"'indieweb-post-kinds'",
")",
";",
"?></label>\n\t\t\t\t<select name=\"return\">\n\t\t\t\t\t<option value=\"single\"><?php",
"esc_html_e",
"(",
"'Single'",
",",
"'indieweb-post-kinds'",
")",
";",
"?></option>\n\t\t\t\t\t<option value=\"feed\"><?php",
"esc_html_e",
"(",
"'Feed'",
",",
"'indieweb-post-kinds'",
")",
";",
"?></option>\n\t\t\t\t</select>\n\t\t\t</p>\n\t\t\t<p><label for=\"follow\"><?php",
"esc_html_e",
"(",
"'Follow Author Links'",
",",
"'indieweb-post-kinds'",
")",
";",
"?></label><input type=\"checkbox\" name=\"follow\" id=\"follow\" /></p>\n\t\t\t<?php",
"wp_nonce_field",
"(",
"'wp_rest'",
")",
";",
"?>\n\t\t\t<?php",
"submit_button",
"(",
"__",
"(",
"'Parse'",
",",
"'indieweb-post-kinds'",
")",
")",
";",
"?>\n\t\t\t\t\t\t</form>\n\t\t\t\t</div>\n\t\t\t\t<?php",
"}"
] | Generate Debug Tool
@access public | [
"Generate",
"Debug",
"Tool"
] | 722154e91fe47bca185256bd6388324de7bea012 | https://github.com/dshanske/parse-this/blob/722154e91fe47bca185256bd6388324de7bea012/includes/class-parse-this-api.php#L40-L70 |
30,887 | bovigo/callmap | src/main/php/Invocations.php | Invocations.argumentName | public function argumentName(int $argumentPosition, string $suffix = ''): ?string
{
if (isset($this->paramNames[$argumentPosition])) {
return '$' . $this->paramNames[$argumentPosition] . $suffix;
}
return null;
} | php | public function argumentName(int $argumentPosition, string $suffix = ''): ?string
{
if (isset($this->paramNames[$argumentPosition])) {
return '$' . $this->paramNames[$argumentPosition] . $suffix;
}
return null;
} | [
"public",
"function",
"argumentName",
"(",
"int",
"$",
"argumentPosition",
",",
"string",
"$",
"suffix",
"=",
"''",
")",
":",
"?",
"string",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"paramNames",
"[",
"$",
"argumentPosition",
"]",
")",
")",
"{",
"return",
"'$'",
".",
"$",
"this",
"->",
"paramNames",
"[",
"$",
"argumentPosition",
"]",
".",
"$",
"suffix",
";",
"}",
"return",
"null",
";",
"}"
] | returns name of argument at requested position
Returns null if there is no argument at requested position or the name
of that argument is unknown.
@param int $argumentPosition
@param string $suffix optional string to append after argument name
@return string|null | [
"returns",
"name",
"of",
"argument",
"at",
"requested",
"position"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/Invocations.php#L85-L92 |
30,888 | bovigo/callmap | src/main/php/Invocations.php | Invocations.argumentsOf | public function argumentsOf(int $invocation = 1): array
{
if (isset($this->callHistory[$invocation - 1])) {
return $this->callHistory[$invocation - 1];
}
$totalInvocations = $this->count();
throw new MissingInvocation(sprintf(
'Missing invocation #%d for %s, was %s.',
$invocation,
$this->name,
($totalInvocations === 0 ?
'never called' :
('only called ' . ($totalInvocations === 1 ?
'once' : $totalInvocations . ' times')
)
)
));
} | php | public function argumentsOf(int $invocation = 1): array
{
if (isset($this->callHistory[$invocation - 1])) {
return $this->callHistory[$invocation - 1];
}
$totalInvocations = $this->count();
throw new MissingInvocation(sprintf(
'Missing invocation #%d for %s, was %s.',
$invocation,
$this->name,
($totalInvocations === 0 ?
'never called' :
('only called ' . ($totalInvocations === 1 ?
'once' : $totalInvocations . ' times')
)
)
));
} | [
"public",
"function",
"argumentsOf",
"(",
"int",
"$",
"invocation",
"=",
"1",
")",
":",
"array",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"callHistory",
"[",
"$",
"invocation",
"-",
"1",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"callHistory",
"[",
"$",
"invocation",
"-",
"1",
"]",
";",
"}",
"$",
"totalInvocations",
"=",
"$",
"this",
"->",
"count",
"(",
")",
";",
"throw",
"new",
"MissingInvocation",
"(",
"sprintf",
"(",
"'Missing invocation #%d for %s, was %s.'",
",",
"$",
"invocation",
",",
"$",
"this",
"->",
"name",
",",
"(",
"$",
"totalInvocations",
"===",
"0",
"?",
"'never called'",
":",
"(",
"'only called '",
".",
"(",
"$",
"totalInvocations",
"===",
"1",
"?",
"'once'",
":",
"$",
"totalInvocations",
".",
"' times'",
")",
")",
")",
")",
")",
";",
"}"
] | returns the arguments received for a specific invocation
@param int $invocation nth invocation to check, defaults to 1 aka first invocation
@return mixed[]
@throws \bovigo\callmap\MissingInvocation in case no such invocation was received | [
"returns",
"the",
"arguments",
"received",
"for",
"a",
"specific",
"invocation"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/Invocations.php#L101-L119 |
30,889 | QuickenLoans/mcp-logger | src/Message/MessageFactory.php | MessageFactory.setDefaultProperty | public function setDefaultProperty(string $name, $value): void
{
$this->validateProperty($name, $value);
$this->logProperties[$name] = $value;
} | php | public function setDefaultProperty(string $name, $value): void
{
$this->validateProperty($name, $value);
$this->logProperties[$name] = $value;
} | [
"public",
"function",
"setDefaultProperty",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
":",
"void",
"{",
"$",
"this",
"->",
"validateProperty",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"logProperties",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}"
] | Set a property that will be attached to all log messages.
@param string $name
@param mixed $value
@return void | [
"Set",
"a",
"property",
"that",
"will",
"be",
"attached",
"to",
"all",
"log",
"messages",
"."
] | ec0960fc32de1a4c583b2447b99d0ef8c801f1ae | https://github.com/QuickenLoans/mcp-logger/blob/ec0960fc32de1a4c583b2447b99d0ef8c801f1ae/src/Message/MessageFactory.php#L118-L123 |
30,890 | QuickenLoans/mcp-logger | src/Message/MessageFactory.php | MessageFactory.buildMessage | public function buildMessage($level, string $message, array $context = []): MessageInterface
{
$level = $this->validateSeverity($level);
$data = [
MessageInterface::CONTEXT => []
];
// Append message defaults to this payload
$data = $this->consume($data, $this->logProperties);
// Append message context to this payload
$data = $this->consume($data, $context);
return new Message($level, $message, $data);
} | php | public function buildMessage($level, string $message, array $context = []): MessageInterface
{
$level = $this->validateSeverity($level);
$data = [
MessageInterface::CONTEXT => []
];
// Append message defaults to this payload
$data = $this->consume($data, $this->logProperties);
// Append message context to this payload
$data = $this->consume($data, $context);
return new Message($level, $message, $data);
} | [
"public",
"function",
"buildMessage",
"(",
"$",
"level",
",",
"string",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
":",
"MessageInterface",
"{",
"$",
"level",
"=",
"$",
"this",
"->",
"validateSeverity",
"(",
"$",
"level",
")",
";",
"$",
"data",
"=",
"[",
"MessageInterface",
"::",
"CONTEXT",
"=>",
"[",
"]",
"]",
";",
"// Append message defaults to this payload",
"$",
"data",
"=",
"$",
"this",
"->",
"consume",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"logProperties",
")",
";",
"// Append message context to this payload",
"$",
"data",
"=",
"$",
"this",
"->",
"consume",
"(",
"$",
"data",
",",
"$",
"context",
")",
";",
"return",
"new",
"Message",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"data",
")",
";",
"}"
] | Sanitize and instantiate a Message
@param mixed $level
@param string $message
@param array $context
@return Message | [
"Sanitize",
"and",
"instantiate",
"a",
"Message"
] | ec0960fc32de1a4c583b2447b99d0ef8c801f1ae | https://github.com/QuickenLoans/mcp-logger/blob/ec0960fc32de1a4c583b2447b99d0ef8c801f1ae/src/Message/MessageFactory.php#L163-L177 |
30,891 | QuickenLoans/mcp-logger | src/Message/MessageFactory.php | MessageFactory.consume | private function consume(array $data, array $context)
{
foreach ($context as $property => $value) {
$sanitized = $this->validateValue($value);
if ($sanitized === null) {
continue;
}
if (in_array($property, [MessageInterface::SERVER_IP, MessageInterface::USER_IP], true)) {
try {
$ip = new IP($value);
$value = $ip->getShortAddress();
} catch (InvalidIpAddressException $e) {
$value = '0.0.0.0';
}
}
if (in_array($property, $this->knownProperties, true)) {
$data[$property] = $sanitized;
} else {
$data[MessageInterface::CONTEXT][$property] = $sanitized;
}
}
return $data;
} | php | private function consume(array $data, array $context)
{
foreach ($context as $property => $value) {
$sanitized = $this->validateValue($value);
if ($sanitized === null) {
continue;
}
if (in_array($property, [MessageInterface::SERVER_IP, MessageInterface::USER_IP], true)) {
try {
$ip = new IP($value);
$value = $ip->getShortAddress();
} catch (InvalidIpAddressException $e) {
$value = '0.0.0.0';
}
}
if (in_array($property, $this->knownProperties, true)) {
$data[$property] = $sanitized;
} else {
$data[MessageInterface::CONTEXT][$property] = $sanitized;
}
}
return $data;
} | [
"private",
"function",
"consume",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"context",
")",
"{",
"foreach",
"(",
"$",
"context",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"$",
"sanitized",
"=",
"$",
"this",
"->",
"validateValue",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"sanitized",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"property",
",",
"[",
"MessageInterface",
"::",
"SERVER_IP",
",",
"MessageInterface",
"::",
"USER_IP",
"]",
",",
"true",
")",
")",
"{",
"try",
"{",
"$",
"ip",
"=",
"new",
"IP",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"$",
"ip",
"->",
"getShortAddress",
"(",
")",
";",
"}",
"catch",
"(",
"InvalidIpAddressException",
"$",
"e",
")",
"{",
"$",
"value",
"=",
"'0.0.0.0'",
";",
"}",
"}",
"if",
"(",
"in_array",
"(",
"$",
"property",
",",
"$",
"this",
"->",
"knownProperties",
",",
"true",
")",
")",
"{",
"$",
"data",
"[",
"$",
"property",
"]",
"=",
"$",
"sanitized",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"MessageInterface",
"::",
"CONTEXT",
"]",
"[",
"$",
"property",
"]",
"=",
"$",
"sanitized",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Parse the provided context data and add it to the message payload
@param mixed[] $data
@param mixed[] $context
@return mixed[] | [
"Parse",
"the",
"provided",
"context",
"data",
"and",
"add",
"it",
"to",
"the",
"message",
"payload"
] | ec0960fc32de1a4c583b2447b99d0ef8c801f1ae | https://github.com/QuickenLoans/mcp-logger/blob/ec0960fc32de1a4c583b2447b99d0ef8c801f1ae/src/Message/MessageFactory.php#L187-L213 |
30,892 | QuickenLoans/mcp-logger | src/Transformer/QLLogSeverityTransformer.php | QLLogSeverityTransformer.convertLogLevelFromPSRToQL | private function convertLogLevelFromPSRToQL($severity)
{
// Equal mappings
if ($severity === LogLevel::DEBUG) {
return 'debug';
} elseif ($severity === LogLevel::INFO) {
return 'info';
} elseif ($severity === LogLevel::WARNING) {
return 'warn';
} elseif ($severity === LogLevel::ERROR) {
return 'error';
}
// Duplicate mappings
if ($severity === LogLevel::NOTICE) {
return 'info';
} elseif ($severity === LogLevel::CRITICAL) {
return 'fatal';
} elseif ($severity === LogLevel::ALERT) {
return 'fatal';
} elseif ($severity === LogLevel::EMERGENCY) {
return 'fatal';
}
// Default to error
return 'error';
} | php | private function convertLogLevelFromPSRToQL($severity)
{
// Equal mappings
if ($severity === LogLevel::DEBUG) {
return 'debug';
} elseif ($severity === LogLevel::INFO) {
return 'info';
} elseif ($severity === LogLevel::WARNING) {
return 'warn';
} elseif ($severity === LogLevel::ERROR) {
return 'error';
}
// Duplicate mappings
if ($severity === LogLevel::NOTICE) {
return 'info';
} elseif ($severity === LogLevel::CRITICAL) {
return 'fatal';
} elseif ($severity === LogLevel::ALERT) {
return 'fatal';
} elseif ($severity === LogLevel::EMERGENCY) {
return 'fatal';
}
// Default to error
return 'error';
} | [
"private",
"function",
"convertLogLevelFromPSRToQL",
"(",
"$",
"severity",
")",
"{",
"// Equal mappings",
"if",
"(",
"$",
"severity",
"===",
"LogLevel",
"::",
"DEBUG",
")",
"{",
"return",
"'debug'",
";",
"}",
"elseif",
"(",
"$",
"severity",
"===",
"LogLevel",
"::",
"INFO",
")",
"{",
"return",
"'info'",
";",
"}",
"elseif",
"(",
"$",
"severity",
"===",
"LogLevel",
"::",
"WARNING",
")",
"{",
"return",
"'warn'",
";",
"}",
"elseif",
"(",
"$",
"severity",
"===",
"LogLevel",
"::",
"ERROR",
")",
"{",
"return",
"'error'",
";",
"}",
"// Duplicate mappings",
"if",
"(",
"$",
"severity",
"===",
"LogLevel",
"::",
"NOTICE",
")",
"{",
"return",
"'info'",
";",
"}",
"elseif",
"(",
"$",
"severity",
"===",
"LogLevel",
"::",
"CRITICAL",
")",
"{",
"return",
"'fatal'",
";",
"}",
"elseif",
"(",
"$",
"severity",
"===",
"LogLevel",
"::",
"ALERT",
")",
"{",
"return",
"'fatal'",
";",
"}",
"elseif",
"(",
"$",
"severity",
"===",
"LogLevel",
"::",
"EMERGENCY",
")",
"{",
"return",
"'fatal'",
";",
"}",
"// Default to error",
"return",
"'error'",
";",
"}"
] | Translate a PRS-3 log level to QL log level
Not used:
- 'audit'
@param string $severity
@return string | [
"Translate",
"a",
"PRS",
"-",
"3",
"log",
"level",
"to",
"QL",
"log",
"level"
] | ec0960fc32de1a4c583b2447b99d0ef8c801f1ae | https://github.com/QuickenLoans/mcp-logger/blob/ec0960fc32de1a4c583b2447b99d0ef8c801f1ae/src/Transformer/QLLogSeverityTransformer.php#L41-L73 |
30,893 | bovigo/callmap | src/main/php/ClassProxyMethodHandler.php | ClassProxyMethodHandler.returns | public function returns(array $callMap): ClassProxy
{
foreach (array_keys($callMap) as $method) {
if (!isset($this->_allowedMethods[$method]) || isset($this->_voidMethods[$method])) {
throw new \InvalidArgumentException(
$this->canNot('map', $method)
);
}
}
$this->callMap = new CallMap($callMap);
return $this;
} | php | public function returns(array $callMap): ClassProxy
{
foreach (array_keys($callMap) as $method) {
if (!isset($this->_allowedMethods[$method]) || isset($this->_voidMethods[$method])) {
throw new \InvalidArgumentException(
$this->canNot('map', $method)
);
}
}
$this->callMap = new CallMap($callMap);
return $this;
} | [
"public",
"function",
"returns",
"(",
"array",
"$",
"callMap",
")",
":",
"ClassProxy",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"callMap",
")",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_allowedMethods",
"[",
"$",
"method",
"]",
")",
"||",
"isset",
"(",
"$",
"this",
"->",
"_voidMethods",
"[",
"$",
"method",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"$",
"this",
"->",
"canNot",
"(",
"'map'",
",",
"$",
"method",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"callMap",
"=",
"new",
"CallMap",
"(",
"$",
"callMap",
")",
";",
"return",
"$",
"this",
";",
"}"
] | sets the call map with return values
@api
@since 3.2.0
@param array $callMap
@return ClassProxy
@throws \InvalidArgumentException in case any of the mapped methods does not exist or is not applicable | [
"sets",
"the",
"call",
"map",
"with",
"return",
"values"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/ClassProxyMethodHandler.php#L56-L68 |
30,894 | bovigo/callmap | src/main/php/ClassProxyMethodHandler.php | ClassProxyMethodHandler.handleMethodCall | protected function handleMethodCall(string $method, array $arguments, bool $shouldReturnSelf)
{
$invocation = $this->invocations($method)->recordCall($arguments);
if (null !== $this->callMap && $this->callMap->hasResultFor($method, $invocation)) {
return $this->callMap->resultFor($method, $arguments, $invocation);
}
if ($this->parentCallsAllowed && is_callable(['parent', $method])) {
// is_callable() returns true even for abstract methods
$refMethod = new \ReflectionMethod(get_parent_class(), $method);
if (!$refMethod->isAbstract()) {
return parent::$method(...$arguments);
}
}
if ($shouldReturnSelf) {
return $this;
}
return null;
} | php | protected function handleMethodCall(string $method, array $arguments, bool $shouldReturnSelf)
{
$invocation = $this->invocations($method)->recordCall($arguments);
if (null !== $this->callMap && $this->callMap->hasResultFor($method, $invocation)) {
return $this->callMap->resultFor($method, $arguments, $invocation);
}
if ($this->parentCallsAllowed && is_callable(['parent', $method])) {
// is_callable() returns true even for abstract methods
$refMethod = new \ReflectionMethod(get_parent_class(), $method);
if (!$refMethod->isAbstract()) {
return parent::$method(...$arguments);
}
}
if ($shouldReturnSelf) {
return $this;
}
return null;
} | [
"protected",
"function",
"handleMethodCall",
"(",
"string",
"$",
"method",
",",
"array",
"$",
"arguments",
",",
"bool",
"$",
"shouldReturnSelf",
")",
"{",
"$",
"invocation",
"=",
"$",
"this",
"->",
"invocations",
"(",
"$",
"method",
")",
"->",
"recordCall",
"(",
"$",
"arguments",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"callMap",
"&&",
"$",
"this",
"->",
"callMap",
"->",
"hasResultFor",
"(",
"$",
"method",
",",
"$",
"invocation",
")",
")",
"{",
"return",
"$",
"this",
"->",
"callMap",
"->",
"resultFor",
"(",
"$",
"method",
",",
"$",
"arguments",
",",
"$",
"invocation",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"parentCallsAllowed",
"&&",
"is_callable",
"(",
"[",
"'parent'",
",",
"$",
"method",
"]",
")",
")",
"{",
"// is_callable() returns true even for abstract methods",
"$",
"refMethod",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"get_parent_class",
"(",
")",
",",
"$",
"method",
")",
";",
"if",
"(",
"!",
"$",
"refMethod",
"->",
"isAbstract",
"(",
")",
")",
"{",
"return",
"parent",
"::",
"$",
"method",
"(",
"...",
"$",
"arguments",
")",
";",
"}",
"}",
"if",
"(",
"$",
"shouldReturnSelf",
")",
"{",
"return",
"$",
"this",
";",
"}",
"return",
"null",
";",
"}"
] | handles actual method calls
@param string $method actually called method
@param mixed[] $arguments list of given arguments for methods
@param bool $shouldReturnSelf whether the return value should be the instance itself
@return mixed
@throws \Exception | [
"handles",
"actual",
"method",
"calls"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/ClassProxyMethodHandler.php#L79-L99 |
30,895 | bovigo/callmap | src/main/php/ClassProxyMethodHandler.php | ClassProxyMethodHandler.invocations | public function invocations(string $method): Invocations
{
if (empty($method)) {
throw new \InvalidArgumentException(
'Please provide a method name to retrieve invocations for.'
);
}
if (!isset($this->_allowedMethods[$method])) {
throw new \InvalidArgumentException(
$this->canNot('retrieve invocations for', $method)
);
}
if (!isset($this->invocations[$method])) {
$this->invocations[$method] = new Invocations(
$this->completeNameOf($method),
$this->_methodParams[$method]
);
}
return $this->invocations[$method];
} | php | public function invocations(string $method): Invocations
{
if (empty($method)) {
throw new \InvalidArgumentException(
'Please provide a method name to retrieve invocations for.'
);
}
if (!isset($this->_allowedMethods[$method])) {
throw new \InvalidArgumentException(
$this->canNot('retrieve invocations for', $method)
);
}
if (!isset($this->invocations[$method])) {
$this->invocations[$method] = new Invocations(
$this->completeNameOf($method),
$this->_methodParams[$method]
);
}
return $this->invocations[$method];
} | [
"public",
"function",
"invocations",
"(",
"string",
"$",
"method",
")",
":",
"Invocations",
"{",
"if",
"(",
"empty",
"(",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Please provide a method name to retrieve invocations for.'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_allowedMethods",
"[",
"$",
"method",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"$",
"this",
"->",
"canNot",
"(",
"'retrieve invocations for'",
",",
"$",
"method",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"invocations",
"[",
"$",
"method",
"]",
")",
")",
"{",
"$",
"this",
"->",
"invocations",
"[",
"$",
"method",
"]",
"=",
"new",
"Invocations",
"(",
"$",
"this",
"->",
"completeNameOf",
"(",
"$",
"method",
")",
",",
"$",
"this",
"->",
"_methodParams",
"[",
"$",
"method",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"invocations",
"[",
"$",
"method",
"]",
";",
"}"
] | returns recorded invocations for given method
@param string $method
@return Invocations
@throws \InvalidArgumentException in case the method does not exist or is not applicable
@since 3.1.0 | [
"returns",
"recorded",
"invocations",
"for",
"given",
"method"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/ClassProxyMethodHandler.php#L109-L131 |
30,896 | bovigo/callmap | src/main/php/ClassProxyMethodHandler.php | ClassProxyMethodHandler.canNot | private function canNot(string $message, string $invalidMethod): string
{
if (isset($this->_voidMethods[$invalidMethod])) {
$reason = 'is declared as returning void.';
} elseif (method_exists($this, $invalidMethod)) {
$reason = 'is not applicable for mapping.';
} else {
$reason = 'does not exist. Probably a typo?';
}
return sprintf(
'Trying to %s method %s, but it %s',
$message,
$this->completeNameOf($invalidMethod),
$reason
);
} | php | private function canNot(string $message, string $invalidMethod): string
{
if (isset($this->_voidMethods[$invalidMethod])) {
$reason = 'is declared as returning void.';
} elseif (method_exists($this, $invalidMethod)) {
$reason = 'is not applicable for mapping.';
} else {
$reason = 'does not exist. Probably a typo?';
}
return sprintf(
'Trying to %s method %s, but it %s',
$message,
$this->completeNameOf($invalidMethod),
$reason
);
} | [
"private",
"function",
"canNot",
"(",
"string",
"$",
"message",
",",
"string",
"$",
"invalidMethod",
")",
":",
"string",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_voidMethods",
"[",
"$",
"invalidMethod",
"]",
")",
")",
"{",
"$",
"reason",
"=",
"'is declared as returning void.'",
";",
"}",
"elseif",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"invalidMethod",
")",
")",
"{",
"$",
"reason",
"=",
"'is not applicable for mapping.'",
";",
"}",
"else",
"{",
"$",
"reason",
"=",
"'does not exist. Probably a typo?'",
";",
"}",
"return",
"sprintf",
"(",
"'Trying to %s method %s, but it %s'",
",",
"$",
"message",
",",
"$",
"this",
"->",
"completeNameOf",
"(",
"$",
"invalidMethod",
")",
",",
"$",
"reason",
")",
";",
"}"
] | creates complete error message that invalid method can not be used
@param string $message
@param string $invalidMethod | [
"creates",
"complete",
"error",
"message",
"that",
"invalid",
"method",
"can",
"not",
"be",
"used"
] | 0dbf2c234469bf18f4cc06d31962b6141923754b | https://github.com/bovigo/callmap/blob/0dbf2c234469bf18f4cc06d31962b6141923754b/src/main/php/ClassProxyMethodHandler.php#L154-L170 |
30,897 | dshanske/parse-this | includes/class-mf2-post.php | MF2_Post.get_mf2meta | private function get_mf2meta() {
$meta = get_post_meta( $this->uid );
if ( ! $meta ) {
return array();
}
if ( isset( $meta['response'] ) ) {
$response = maybe_unserialize( $meta['response'] );
// Retrieve from the old response array and store in new location.
if ( ! empty( $response ) ) {
$new = array();
// Convert to new format and update.
if ( ! empty( $response['title'] ) ) {
$new['name'] = $response['title'];
}
if ( ! empty( $response['url'] ) ) {
$new['url'] = $response['url'];
}
if ( ! empty( $response['content'] ) ) {
$new['content'] = $response['content'];
}
if ( ! empty( $response['published'] ) ) {
$new['published'] = $response['published'];
}
if ( ! empty( $response['author'] ) ) {
$new['card'] = array();
$new['card']['name'] = $response['author'];
if ( ! empty( $response['icon'] ) ) {
$new['card']['photo'] = $response['icon'];
}
}
$new = array_unique( $new );
$new['card'] = array_unique( $new['card'] );
if ( isset( $new ) ) {
update_post_meta( $this->uid, 'mf2_cite', $new );
delete_post_meta( $this->uid, 'response' );
$meta['cite'] = $new;
}
}
}
foreach ( $meta as $key => $value ) {
if ( ! self::str_prefix( $key, 'mf2_' ) ) {
unset( $meta[ $key ] );
} else {
unset( $meta[ $key ] );
$key = str_replace( 'mf2_', '', $key );
// Do not save microput prefixed instructions
if ( self::str_prefix( $key, 'mp-' ) ) {
continue;
}
$value = array_map( 'maybe_unserialize', $value );
if ( 1 === count( $value ) ) {
$value = array_shift( $value );
}
if ( is_string( $value ) ) {
$meta[ $key ] = array( $value );
} else {
$meta[ $key ] = $value;
}
}
}
return array_filter( $meta );
} | php | private function get_mf2meta() {
$meta = get_post_meta( $this->uid );
if ( ! $meta ) {
return array();
}
if ( isset( $meta['response'] ) ) {
$response = maybe_unserialize( $meta['response'] );
// Retrieve from the old response array and store in new location.
if ( ! empty( $response ) ) {
$new = array();
// Convert to new format and update.
if ( ! empty( $response['title'] ) ) {
$new['name'] = $response['title'];
}
if ( ! empty( $response['url'] ) ) {
$new['url'] = $response['url'];
}
if ( ! empty( $response['content'] ) ) {
$new['content'] = $response['content'];
}
if ( ! empty( $response['published'] ) ) {
$new['published'] = $response['published'];
}
if ( ! empty( $response['author'] ) ) {
$new['card'] = array();
$new['card']['name'] = $response['author'];
if ( ! empty( $response['icon'] ) ) {
$new['card']['photo'] = $response['icon'];
}
}
$new = array_unique( $new );
$new['card'] = array_unique( $new['card'] );
if ( isset( $new ) ) {
update_post_meta( $this->uid, 'mf2_cite', $new );
delete_post_meta( $this->uid, 'response' );
$meta['cite'] = $new;
}
}
}
foreach ( $meta as $key => $value ) {
if ( ! self::str_prefix( $key, 'mf2_' ) ) {
unset( $meta[ $key ] );
} else {
unset( $meta[ $key ] );
$key = str_replace( 'mf2_', '', $key );
// Do not save microput prefixed instructions
if ( self::str_prefix( $key, 'mp-' ) ) {
continue;
}
$value = array_map( 'maybe_unserialize', $value );
if ( 1 === count( $value ) ) {
$value = array_shift( $value );
}
if ( is_string( $value ) ) {
$meta[ $key ] = array( $value );
} else {
$meta[ $key ] = $value;
}
}
}
return array_filter( $meta );
} | [
"private",
"function",
"get_mf2meta",
"(",
")",
"{",
"$",
"meta",
"=",
"get_post_meta",
"(",
"$",
"this",
"->",
"uid",
")",
";",
"if",
"(",
"!",
"$",
"meta",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"meta",
"[",
"'response'",
"]",
")",
")",
"{",
"$",
"response",
"=",
"maybe_unserialize",
"(",
"$",
"meta",
"[",
"'response'",
"]",
")",
";",
"// Retrieve from the old response array and store in new location.",
"if",
"(",
"!",
"empty",
"(",
"$",
"response",
")",
")",
"{",
"$",
"new",
"=",
"array",
"(",
")",
";",
"// Convert to new format and update.",
"if",
"(",
"!",
"empty",
"(",
"$",
"response",
"[",
"'title'",
"]",
")",
")",
"{",
"$",
"new",
"[",
"'name'",
"]",
"=",
"$",
"response",
"[",
"'title'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"response",
"[",
"'url'",
"]",
")",
")",
"{",
"$",
"new",
"[",
"'url'",
"]",
"=",
"$",
"response",
"[",
"'url'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"response",
"[",
"'content'",
"]",
")",
")",
"{",
"$",
"new",
"[",
"'content'",
"]",
"=",
"$",
"response",
"[",
"'content'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"response",
"[",
"'published'",
"]",
")",
")",
"{",
"$",
"new",
"[",
"'published'",
"]",
"=",
"$",
"response",
"[",
"'published'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"response",
"[",
"'author'",
"]",
")",
")",
"{",
"$",
"new",
"[",
"'card'",
"]",
"=",
"array",
"(",
")",
";",
"$",
"new",
"[",
"'card'",
"]",
"[",
"'name'",
"]",
"=",
"$",
"response",
"[",
"'author'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"response",
"[",
"'icon'",
"]",
")",
")",
"{",
"$",
"new",
"[",
"'card'",
"]",
"[",
"'photo'",
"]",
"=",
"$",
"response",
"[",
"'icon'",
"]",
";",
"}",
"}",
"$",
"new",
"=",
"array_unique",
"(",
"$",
"new",
")",
";",
"$",
"new",
"[",
"'card'",
"]",
"=",
"array_unique",
"(",
"$",
"new",
"[",
"'card'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"new",
")",
")",
"{",
"update_post_meta",
"(",
"$",
"this",
"->",
"uid",
",",
"'mf2_cite'",
",",
"$",
"new",
")",
";",
"delete_post_meta",
"(",
"$",
"this",
"->",
"uid",
",",
"'response'",
")",
";",
"$",
"meta",
"[",
"'cite'",
"]",
"=",
"$",
"new",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"meta",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"str_prefix",
"(",
"$",
"key",
",",
"'mf2_'",
")",
")",
"{",
"unset",
"(",
"$",
"meta",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"meta",
"[",
"$",
"key",
"]",
")",
";",
"$",
"key",
"=",
"str_replace",
"(",
"'mf2_'",
",",
"''",
",",
"$",
"key",
")",
";",
"// Do not save microput prefixed instructions",
"if",
"(",
"self",
"::",
"str_prefix",
"(",
"$",
"key",
",",
"'mp-'",
")",
")",
"{",
"continue",
";",
"}",
"$",
"value",
"=",
"array_map",
"(",
"'maybe_unserialize'",
",",
"$",
"value",
")",
";",
"if",
"(",
"1",
"===",
"count",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"array_shift",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"meta",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"meta",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"array_filter",
"(",
"$",
"meta",
")",
";",
"}"
] | Sets an array with only the mf2 prefixed meta. | [
"Sets",
"an",
"array",
"with",
"only",
"the",
"mf2",
"prefixed",
"meta",
"."
] | 722154e91fe47bca185256bd6388324de7bea012 | https://github.com/dshanske/parse-this/blob/722154e91fe47bca185256bd6388324de7bea012/includes/class-mf2-post.php#L221-L282 |
30,898 | dshanske/parse-this | includes/class-mf2-post.php | MF2_Post.fetch | public function fetch( $property ) {
// If the property is not set then exit
if ( ! $property || ! $this->has_key( $property ) ) {
return false;
}
$return = $this->get( $property );
if ( wp_is_numeric_array( $return ) ) {
$return = array_shift( $return );
}
// If it is in fact a string it is the pre 2.7.0 format and should be updated
if ( is_string( $return ) ) {
if ( $this->has_key( 'cite' ) ) {
$cite = array_filter( $this->get( 'cite' ) );
$cite['url'] = $return;
$this->set( $property, $cite );
$this->delete( 'cite' );
return $cite;
} else {
return array( 'url' => $return );
}
}
if ( is_array( $return ) ) {
return mf2_to_jf2( $return );
}
return false;
} | php | public function fetch( $property ) {
// If the property is not set then exit
if ( ! $property || ! $this->has_key( $property ) ) {
return false;
}
$return = $this->get( $property );
if ( wp_is_numeric_array( $return ) ) {
$return = array_shift( $return );
}
// If it is in fact a string it is the pre 2.7.0 format and should be updated
if ( is_string( $return ) ) {
if ( $this->has_key( 'cite' ) ) {
$cite = array_filter( $this->get( 'cite' ) );
$cite['url'] = $return;
$this->set( $property, $cite );
$this->delete( 'cite' );
return $cite;
} else {
return array( 'url' => $return );
}
}
if ( is_array( $return ) ) {
return mf2_to_jf2( $return );
}
return false;
} | [
"public",
"function",
"fetch",
"(",
"$",
"property",
")",
"{",
"// If the property is not set then exit",
"if",
"(",
"!",
"$",
"property",
"||",
"!",
"$",
"this",
"->",
"has_key",
"(",
"$",
"property",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"return",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"property",
")",
";",
"if",
"(",
"wp_is_numeric_array",
"(",
"$",
"return",
")",
")",
"{",
"$",
"return",
"=",
"array_shift",
"(",
"$",
"return",
")",
";",
"}",
"// If it is in fact a string it is the pre 2.7.0 format and should be updated",
"if",
"(",
"is_string",
"(",
"$",
"return",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has_key",
"(",
"'cite'",
")",
")",
"{",
"$",
"cite",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"get",
"(",
"'cite'",
")",
")",
";",
"$",
"cite",
"[",
"'url'",
"]",
"=",
"$",
"return",
";",
"$",
"this",
"->",
"set",
"(",
"$",
"property",
",",
"$",
"cite",
")",
";",
"$",
"this",
"->",
"delete",
"(",
"'cite'",
")",
";",
"return",
"$",
"cite",
";",
"}",
"else",
"{",
"return",
"array",
"(",
"'url'",
"=>",
"$",
"return",
")",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"return",
")",
")",
"{",
"return",
"mf2_to_jf2",
"(",
"$",
"return",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Also will update old posts with new settings | [
"Also",
"will",
"update",
"old",
"posts",
"with",
"new",
"settings"
] | 722154e91fe47bca185256bd6388324de7bea012 | https://github.com/dshanske/parse-this/blob/722154e91fe47bca185256bd6388324de7bea012/includes/class-mf2-post.php#L487-L513 |
30,899 | GrahamCampbell/Laravel-TestBench-Core | src/LaravelTrait.php | LaravelTrait.assertIsInjectable | public function assertIsInjectable(string $name)
{
$injectable = true;
$message = "The class '$name' couldn't be automatically injected.";
try {
$class = $this->makeInjectableClass($name);
$this->assertInstanceOf($name, $class->getInjectedObject());
} catch (Exception $e) {
$injectable = false;
if ($msg = $e->getMessage()) {
$message .= " $msg";
}
}
$this->assertTrue($injectable, $message);
} | php | public function assertIsInjectable(string $name)
{
$injectable = true;
$message = "The class '$name' couldn't be automatically injected.";
try {
$class = $this->makeInjectableClass($name);
$this->assertInstanceOf($name, $class->getInjectedObject());
} catch (Exception $e) {
$injectable = false;
if ($msg = $e->getMessage()) {
$message .= " $msg";
}
}
$this->assertTrue($injectable, $message);
} | [
"public",
"function",
"assertIsInjectable",
"(",
"string",
"$",
"name",
")",
"{",
"$",
"injectable",
"=",
"true",
";",
"$",
"message",
"=",
"\"The class '$name' couldn't be automatically injected.\"",
";",
"try",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"makeInjectableClass",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"assertInstanceOf",
"(",
"$",
"name",
",",
"$",
"class",
"->",
"getInjectedObject",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"injectable",
"=",
"false",
";",
"if",
"(",
"$",
"msg",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
"{",
"$",
"message",
".=",
"\" $msg\"",
";",
"}",
"}",
"$",
"this",
"->",
"assertTrue",
"(",
"$",
"injectable",
",",
"$",
"message",
")",
";",
"}"
] | Assert that a class can be automatically injected.
@param string $name
@return void | [
"Assert",
"that",
"a",
"class",
"can",
"be",
"automatically",
"injected",
"."
] | 138218735a65f4532d6c4242a44ffa6c591bca09 | https://github.com/GrahamCampbell/Laravel-TestBench-Core/blob/138218735a65f4532d6c4242a44ffa6c591bca09/src/LaravelTrait.php#L32-L49 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.