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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
15,100
|
acasademont/wurfl
|
WURFL/Configuration/InMemoryConfig.php
|
WURFL_Configuration_InMemoryConfig.matchMode
|
public function matchMode($mode)
{
if (!self::validMatchMode($mode)) {
throw new WURFL_WURFLException('Invalid Match Mode: '.$mode);
}
$this->matchMode = $mode;
return $this;
}
|
php
|
public function matchMode($mode)
{
if (!self::validMatchMode($mode)) {
throw new WURFL_WURFLException('Invalid Match Mode: '.$mode);
}
$this->matchMode = $mode;
return $this;
}
|
[
"public",
"function",
"matchMode",
"(",
"$",
"mode",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"validMatchMode",
"(",
"$",
"mode",
")",
")",
"{",
"throw",
"new",
"WURFL_WURFLException",
"(",
"'Invalid Match Mode: '",
".",
"$",
"mode",
")",
";",
"}",
"$",
"this",
"->",
"matchMode",
"=",
"$",
"mode",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the API match mode
@param string $mode
@return WURFL_Configuration_InMemoryConfig
|
[
"Sets",
"the",
"API",
"match",
"mode"
] |
0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/Configuration/InMemoryConfig.php#L110-L117
|
15,101
|
avto-dev/app-version-laravel
|
src/AppVersionManager.php
|
AppVersionManager.buildStored
|
protected function buildStored()
{
return $this->files->exists($file_path = $this->config['build_metadata_path'])
? $this->files->get($file_path, $this->use_locking)
: null;
}
|
php
|
protected function buildStored()
{
return $this->files->exists($file_path = $this->config['build_metadata_path'])
? $this->files->get($file_path, $this->use_locking)
: null;
}
|
[
"protected",
"function",
"buildStored",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"files",
"->",
"exists",
"(",
"$",
"file_path",
"=",
"$",
"this",
"->",
"config",
"[",
"'build_metadata_path'",
"]",
")",
"?",
"$",
"this",
"->",
"files",
"->",
"get",
"(",
"$",
"file_path",
",",
"$",
"this",
"->",
"use_locking",
")",
":",
"null",
";",
"}"
] |
Get build value from metadata file.
@return null|string
|
[
"Get",
"build",
"value",
"from",
"metadata",
"file",
"."
] |
5cbf9df5981cadd2d5148c49c834cc17fb903c3f
|
https://github.com/avto-dev/app-version-laravel/blob/5cbf9df5981cadd2d5148c49c834cc17fb903c3f/src/AppVersionManager.php#L169-L174
|
15,102
|
avto-dev/app-version-laravel
|
src/AppVersionManager.php
|
AppVersionManager.forgetFormatted
|
protected function forgetFormatted()
{
if ($this->files->exists($compiled_path = $this->config['compiled_path'])) {
return $this->files->delete($compiled_path);
}
return false;
}
|
php
|
protected function forgetFormatted()
{
if ($this->files->exists($compiled_path = $this->config['compiled_path'])) {
return $this->files->delete($compiled_path);
}
return false;
}
|
[
"protected",
"function",
"forgetFormatted",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"files",
"->",
"exists",
"(",
"$",
"compiled_path",
"=",
"$",
"this",
"->",
"config",
"[",
"'compiled_path'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"files",
"->",
"delete",
"(",
"$",
"compiled_path",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Forget stored formatted value.
@return bool
|
[
"Forget",
"stored",
"formatted",
"value",
"."
] |
5cbf9df5981cadd2d5148c49c834cc17fb903c3f
|
https://github.com/avto-dev/app-version-laravel/blob/5cbf9df5981cadd2d5148c49c834cc17fb903c3f/src/AppVersionManager.php#L181-L188
|
15,103
|
jan-dolata/crude-crud
|
src/Engine/Traits/WithPermissionTrait.php
|
WithPermissionTrait._checkPermission
|
private function _checkPermission($name, $attribute)
{
if ($name == 'store') {
return $this->permissionStore($attribute);
}
if ($name == 'update') {
return $this->permissionUpdate($attribute);
}
if ($name == 'delete') {
return $this->permissionDelete($attribute);
}
if ($name == 'order') {
return $this->permissionOrder($attribute);
}
if ($name == 'export') {
return $this->permissionExport($attribute);
}
return $this->permissionView($attribute);
}
|
php
|
private function _checkPermission($name, $attribute)
{
if ($name == 'store') {
return $this->permissionStore($attribute);
}
if ($name == 'update') {
return $this->permissionUpdate($attribute);
}
if ($name == 'delete') {
return $this->permissionDelete($attribute);
}
if ($name == 'order') {
return $this->permissionOrder($attribute);
}
if ($name == 'export') {
return $this->permissionExport($attribute);
}
return $this->permissionView($attribute);
}
|
[
"private",
"function",
"_checkPermission",
"(",
"$",
"name",
",",
"$",
"attribute",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"'store'",
")",
"{",
"return",
"$",
"this",
"->",
"permissionStore",
"(",
"$",
"attribute",
")",
";",
"}",
"if",
"(",
"$",
"name",
"==",
"'update'",
")",
"{",
"return",
"$",
"this",
"->",
"permissionUpdate",
"(",
"$",
"attribute",
")",
";",
"}",
"if",
"(",
"$",
"name",
"==",
"'delete'",
")",
"{",
"return",
"$",
"this",
"->",
"permissionDelete",
"(",
"$",
"attribute",
")",
";",
"}",
"if",
"(",
"$",
"name",
"==",
"'order'",
")",
"{",
"return",
"$",
"this",
"->",
"permissionOrder",
"(",
"$",
"attribute",
")",
";",
"}",
"if",
"(",
"$",
"name",
"==",
"'export'",
")",
"{",
"return",
"$",
"this",
"->",
"permissionExport",
"(",
"$",
"attribute",
")",
";",
"}",
"return",
"$",
"this",
"->",
"permissionView",
"(",
"$",
"attribute",
")",
";",
"}"
] |
Check permission by name
@param string $name
@param mixed $attribute
@return boolean
|
[
"Check",
"permission",
"by",
"name"
] |
9129ea08278835cf5cecfd46a90369226ae6bdd7
|
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/WithPermissionTrait.php#L59-L82
|
15,104
|
jan-dolata/crude-crud
|
src/Engine/Traits/WithPermissionTrait.php
|
WithPermissionTrait._checkOption
|
private function _checkOption($name)
{
if ($name == 'list')
return true;
$names = [
'store' => 'add',
'update' => 'edit',
'delete' => 'delete',
'order' => 'order',
'export' => 'export'
];
return $this->crudeSetup->haveOption($names[$name]);
}
|
php
|
private function _checkOption($name)
{
if ($name == 'list')
return true;
$names = [
'store' => 'add',
'update' => 'edit',
'delete' => 'delete',
'order' => 'order',
'export' => 'export'
];
return $this->crudeSetup->haveOption($names[$name]);
}
|
[
"private",
"function",
"_checkOption",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"'list'",
")",
"return",
"true",
";",
"$",
"names",
"=",
"[",
"'store'",
"=>",
"'add'",
",",
"'update'",
"=>",
"'edit'",
",",
"'delete'",
"=>",
"'delete'",
",",
"'order'",
"=>",
"'order'",
",",
"'export'",
"=>",
"'export'",
"]",
";",
"return",
"$",
"this",
"->",
"crudeSetup",
"->",
"haveOption",
"(",
"$",
"names",
"[",
"$",
"name",
"]",
")",
";",
"}"
] |
Check option by name
@param string $name
@return boolean
|
[
"Check",
"option",
"by",
"name"
] |
9129ea08278835cf5cecfd46a90369226ae6bdd7
|
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/WithPermissionTrait.php#L89-L103
|
15,105
|
phramework/validate
|
src/BaseValidator.php
|
BaseValidator.validateCommon
|
protected function validateCommon($value, $validateResult)
{
//While current status of validation is true,
//keep validating against common keywords
//validate against enum using validateEnum
if ($validateResult->status === true && $this->enum) {
$validateResult = $this->validateEnum($value, $validateResult->value);
if ($validateResult->status !== true) {
//failed to validate against enum
return $validateResult;
}
}
//validate against not
if ($validateResult->status === true && $this->not) {
$validateResult = $this->validateNot($value, $validateResult->value);
if ($validateResult->status !== true) {
//failed to validate against not
return $validateResult;
}
}
return $this->runValidateCallback($validateResult);
}
|
php
|
protected function validateCommon($value, $validateResult)
{
//While current status of validation is true,
//keep validating against common keywords
//validate against enum using validateEnum
if ($validateResult->status === true && $this->enum) {
$validateResult = $this->validateEnum($value, $validateResult->value);
if ($validateResult->status !== true) {
//failed to validate against enum
return $validateResult;
}
}
//validate against not
if ($validateResult->status === true && $this->not) {
$validateResult = $this->validateNot($value, $validateResult->value);
if ($validateResult->status !== true) {
//failed to validate against not
return $validateResult;
}
}
return $this->runValidateCallback($validateResult);
}
|
[
"protected",
"function",
"validateCommon",
"(",
"$",
"value",
",",
"$",
"validateResult",
")",
"{",
"//While current status of validation is true,",
"//keep validating against common keywords",
"//validate against enum using validateEnum",
"if",
"(",
"$",
"validateResult",
"->",
"status",
"===",
"true",
"&&",
"$",
"this",
"->",
"enum",
")",
"{",
"$",
"validateResult",
"=",
"$",
"this",
"->",
"validateEnum",
"(",
"$",
"value",
",",
"$",
"validateResult",
"->",
"value",
")",
";",
"if",
"(",
"$",
"validateResult",
"->",
"status",
"!==",
"true",
")",
"{",
"//failed to validate against enum",
"return",
"$",
"validateResult",
";",
"}",
"}",
"//validate against not",
"if",
"(",
"$",
"validateResult",
"->",
"status",
"===",
"true",
"&&",
"$",
"this",
"->",
"not",
")",
"{",
"$",
"validateResult",
"=",
"$",
"this",
"->",
"validateNot",
"(",
"$",
"value",
",",
"$",
"validateResult",
"->",
"value",
")",
";",
"if",
"(",
"$",
"validateResult",
"->",
"status",
"!==",
"true",
")",
"{",
"//failed to validate against not",
"return",
"$",
"validateResult",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"runValidateCallback",
"(",
"$",
"validateResult",
")",
";",
"}"
] |
Common helper method to validate against all common keywords
@uses validateEnum
@param mixed $value Value to validate
@param ValidateResult $validateResult Current ValidateResult status
@return ValidateResult
|
[
"Common",
"helper",
"method",
"to",
"validate",
"against",
"all",
"common",
"keywords"
] |
22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc
|
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/BaseValidator.php#L77-L103
|
15,106
|
phramework/validate
|
src/BaseValidator.php
|
BaseValidator.validateEnum
|
protected function validateEnum($value, $parsedValue)
{
$return = new ValidateResult($parsedValue, false);
//Check if $this->enum is set and it's not null since its optional
if ($this->enum !== null) {
if (is_object($value)) {
throw new \Exception('Objects are not supported');
}
//Search current $value in enum
foreach ($this->enum as $v) {
if (is_object($v)) {
throw new \Exception('Objects are not supported');
}
if ($value == $v) {
if ($this->validateType && ($valueType = gettype($value)) !== ($vType = gettype($v))) {
continue;
}
//Success value is found
//Overwrite $return's value (get correct object type)
$return->value = $v;
//Set status to true
$return->status = true;
return $return;
} elseif (is_array($value)
&& is_array($v)
&& ArrayValidator::equals($value, $v)
) {
//Type is same (arrays)
//Success value is found
//Overwrite $return's value (get correct object type)
$return->value = $v;
//Set status to true
$return->status = true;
return $return;
}
}
$return->status = false;
//Error
$return->errorObject = new IncorrectParametersException([[
'type' => static::getType(),
'failure' => 'enum'
]]);
}
return $return;
}
|
php
|
protected function validateEnum($value, $parsedValue)
{
$return = new ValidateResult($parsedValue, false);
//Check if $this->enum is set and it's not null since its optional
if ($this->enum !== null) {
if (is_object($value)) {
throw new \Exception('Objects are not supported');
}
//Search current $value in enum
foreach ($this->enum as $v) {
if (is_object($v)) {
throw new \Exception('Objects are not supported');
}
if ($value == $v) {
if ($this->validateType && ($valueType = gettype($value)) !== ($vType = gettype($v))) {
continue;
}
//Success value is found
//Overwrite $return's value (get correct object type)
$return->value = $v;
//Set status to true
$return->status = true;
return $return;
} elseif (is_array($value)
&& is_array($v)
&& ArrayValidator::equals($value, $v)
) {
//Type is same (arrays)
//Success value is found
//Overwrite $return's value (get correct object type)
$return->value = $v;
//Set status to true
$return->status = true;
return $return;
}
}
$return->status = false;
//Error
$return->errorObject = new IncorrectParametersException([[
'type' => static::getType(),
'failure' => 'enum'
]]);
}
return $return;
}
|
[
"protected",
"function",
"validateEnum",
"(",
"$",
"value",
",",
"$",
"parsedValue",
")",
"{",
"$",
"return",
"=",
"new",
"ValidateResult",
"(",
"$",
"parsedValue",
",",
"false",
")",
";",
"//Check if $this->enum is set and it's not null since its optional",
"if",
"(",
"$",
"this",
"->",
"enum",
"!==",
"null",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Objects are not supported'",
")",
";",
"}",
"//Search current $value in enum",
"foreach",
"(",
"$",
"this",
"->",
"enum",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"v",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Objects are not supported'",
")",
";",
"}",
"if",
"(",
"$",
"value",
"==",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"validateType",
"&&",
"(",
"$",
"valueType",
"=",
"gettype",
"(",
"$",
"value",
")",
")",
"!==",
"(",
"$",
"vType",
"=",
"gettype",
"(",
"$",
"v",
")",
")",
")",
"{",
"continue",
";",
"}",
"//Success value is found",
"//Overwrite $return's value (get correct object type)",
"$",
"return",
"->",
"value",
"=",
"$",
"v",
";",
"//Set status to true",
"$",
"return",
"->",
"status",
"=",
"true",
";",
"return",
"$",
"return",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"is_array",
"(",
"$",
"v",
")",
"&&",
"ArrayValidator",
"::",
"equals",
"(",
"$",
"value",
",",
"$",
"v",
")",
")",
"{",
"//Type is same (arrays)",
"//Success value is found",
"//Overwrite $return's value (get correct object type)",
"$",
"return",
"->",
"value",
"=",
"$",
"v",
";",
"//Set status to true",
"$",
"return",
"->",
"status",
"=",
"true",
";",
"return",
"$",
"return",
";",
"}",
"}",
"$",
"return",
"->",
"status",
"=",
"false",
";",
"//Error",
"$",
"return",
"->",
"errorObject",
"=",
"new",
"IncorrectParametersException",
"(",
"[",
"[",
"'type'",
"=>",
"static",
"::",
"getType",
"(",
")",
",",
"'failure'",
"=>",
"'enum'",
"]",
"]",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] |
Common helper method to validate against "enum" keyword
@see 5.5.1. enum http://json-schema.org/latest/json-schema-validation.html#anchor75
@param mixed $value Value to validate
@param mixed $value Parsed value from previous validators
@return ValidateResult
@todo provide support for objects and arrays
|
[
"Common",
"helper",
"method",
"to",
"validate",
"against",
"enum",
"keyword"
] |
22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc
|
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/BaseValidator.php#L133-L189
|
15,107
|
phramework/validate
|
src/BaseValidator.php
|
BaseValidator.validateNot
|
protected function validateNot($value, $parsedValue)
{
$return = new ValidateResult($parsedValue, true);
//Check if $this->not is set and it's not null since its optional
if ($this->not && $this->not !== null) {
if (!is_subclass_of(
$this->not,
BaseValidator::class,
true
)) {
throw new \Exception(sprintf(
'Property "not" MUST extend "%s"',
BaseValidator::class
));
}
$validateNot = $this->not->validate($value);
if ($validateNot->status === true) {
//Error
$return->status = false;
$return->errorObject = new IncorrectParametersException([[
'type' => static::getType(),
'failure' => 'not'
]]);
return $return;
}
}
return $return;
}
|
php
|
protected function validateNot($value, $parsedValue)
{
$return = new ValidateResult($parsedValue, true);
//Check if $this->not is set and it's not null since its optional
if ($this->not && $this->not !== null) {
if (!is_subclass_of(
$this->not,
BaseValidator::class,
true
)) {
throw new \Exception(sprintf(
'Property "not" MUST extend "%s"',
BaseValidator::class
));
}
$validateNot = $this->not->validate($value);
if ($validateNot->status === true) {
//Error
$return->status = false;
$return->errorObject = new IncorrectParametersException([[
'type' => static::getType(),
'failure' => 'not'
]]);
return $return;
}
}
return $return;
}
|
[
"protected",
"function",
"validateNot",
"(",
"$",
"value",
",",
"$",
"parsedValue",
")",
"{",
"$",
"return",
"=",
"new",
"ValidateResult",
"(",
"$",
"parsedValue",
",",
"true",
")",
";",
"//Check if $this->not is set and it's not null since its optional",
"if",
"(",
"$",
"this",
"->",
"not",
"&&",
"$",
"this",
"->",
"not",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"is_subclass_of",
"(",
"$",
"this",
"->",
"not",
",",
"BaseValidator",
"::",
"class",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Property \"not\" MUST extend \"%s\"'",
",",
"BaseValidator",
"::",
"class",
")",
")",
";",
"}",
"$",
"validateNot",
"=",
"$",
"this",
"->",
"not",
"->",
"validate",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"validateNot",
"->",
"status",
"===",
"true",
")",
"{",
"//Error",
"$",
"return",
"->",
"status",
"=",
"false",
";",
"$",
"return",
"->",
"errorObject",
"=",
"new",
"IncorrectParametersException",
"(",
"[",
"[",
"'type'",
"=>",
"static",
"::",
"getType",
"(",
")",
",",
"'failure'",
"=>",
"'not'",
"]",
"]",
")",
";",
"return",
"$",
"return",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] |
Common helper method to validate against "not" keyword
@param mixed $value Value to validate
@param mixed $value Parsed value from previous validators
@return ValidateResult
@throws \Exception
|
[
"Common",
"helper",
"method",
"to",
"validate",
"against",
"not",
"keyword"
] |
22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc
|
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/BaseValidator.php#L198-L231
|
15,108
|
phramework/validate
|
src/BaseValidator.php
|
BaseValidator.registerValidator
|
public static function registerValidator($type, $className)
{
if (!is_string($type)) {
throw new \Exception('"type" MUST be string');
}
if (!is_string($className)) {
throw new \Exception('"className" MUST be string');
}
if (!is_subclass_of(
$className,
BaseValidator::class,
true
)) {
throw new \Exception(sprintf(
'"className" MUST extend "%s"',
BaseValidator::class
));
}
self::$validatorRegistry[$type] = $className;
}
|
php
|
public static function registerValidator($type, $className)
{
if (!is_string($type)) {
throw new \Exception('"type" MUST be string');
}
if (!is_string($className)) {
throw new \Exception('"className" MUST be string');
}
if (!is_subclass_of(
$className,
BaseValidator::class,
true
)) {
throw new \Exception(sprintf(
'"className" MUST extend "%s"',
BaseValidator::class
));
}
self::$validatorRegistry[$type] = $className;
}
|
[
"public",
"static",
"function",
"registerValidator",
"(",
"$",
"type",
",",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'\"type\" MUST be string'",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'\"className\" MUST be string'",
")",
";",
"}",
"if",
"(",
"!",
"is_subclass_of",
"(",
"$",
"className",
",",
"BaseValidator",
"::",
"class",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'\"className\" MUST extend \"%s\"'",
",",
"BaseValidator",
"::",
"class",
")",
")",
";",
"}",
"self",
"::",
"$",
"validatorRegistry",
"[",
"$",
"type",
"]",
"=",
"$",
"className",
";",
"}"
] |
Register a custom validator for a type
@param string $type Type's name, `x-` SHOULD be used for custom types
@param string $className Validator's full classname.
All validators MUST extend `BaseValidator` class
@example
```php
BaseValidator::registerValidator('x-address', 'My\APP\AddressValidator');
```
@throws \Exception
|
[
"Register",
"a",
"custom",
"validator",
"for",
"a",
"type"
] |
22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc
|
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/BaseValidator.php#L504-L526
|
15,109
|
phramework/validate
|
src/BaseValidator.php
|
BaseValidator.createFromObjectForAdditional
|
protected static function createFromObjectForAdditional($object)
{
$indexProperty = null;
$class = null;
if (property_exists($object, 'anyOf')) {
$indexProperty = 'anyOf';
$class = AnyOf::class;
} elseif (property_exists($object, 'allOf')) {
$indexProperty = 'allOf';
$class = AllOf::class;
} elseif (property_exists($object, 'oneOf')) {
$indexProperty = 'oneOf';
$class = OneOf::class;
} else {
return null;
}
//Parse index property's object as validator
foreach ($object->{$indexProperty} as &$property) {
$property = BaseValidator::createFromObject($property);
}
$validator = new $class($object->{$indexProperty});
return $validator;
}
|
php
|
protected static function createFromObjectForAdditional($object)
{
$indexProperty = null;
$class = null;
if (property_exists($object, 'anyOf')) {
$indexProperty = 'anyOf';
$class = AnyOf::class;
} elseif (property_exists($object, 'allOf')) {
$indexProperty = 'allOf';
$class = AllOf::class;
} elseif (property_exists($object, 'oneOf')) {
$indexProperty = 'oneOf';
$class = OneOf::class;
} else {
return null;
}
//Parse index property's object as validator
foreach ($object->{$indexProperty} as &$property) {
$property = BaseValidator::createFromObject($property);
}
$validator = new $class($object->{$indexProperty});
return $validator;
}
|
[
"protected",
"static",
"function",
"createFromObjectForAdditional",
"(",
"$",
"object",
")",
"{",
"$",
"indexProperty",
"=",
"null",
";",
"$",
"class",
"=",
"null",
";",
"if",
"(",
"property_exists",
"(",
"$",
"object",
",",
"'anyOf'",
")",
")",
"{",
"$",
"indexProperty",
"=",
"'anyOf'",
";",
"$",
"class",
"=",
"AnyOf",
"::",
"class",
";",
"}",
"elseif",
"(",
"property_exists",
"(",
"$",
"object",
",",
"'allOf'",
")",
")",
"{",
"$",
"indexProperty",
"=",
"'allOf'",
";",
"$",
"class",
"=",
"AllOf",
"::",
"class",
";",
"}",
"elseif",
"(",
"property_exists",
"(",
"$",
"object",
",",
"'oneOf'",
")",
")",
"{",
"$",
"indexProperty",
"=",
"'oneOf'",
";",
"$",
"class",
"=",
"OneOf",
"::",
"class",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"//Parse index property's object as validator",
"foreach",
"(",
"$",
"object",
"->",
"{",
"$",
"indexProperty",
"}",
"as",
"&",
"$",
"property",
")",
"{",
"$",
"property",
"=",
"BaseValidator",
"::",
"createFromObject",
"(",
"$",
"property",
")",
";",
"}",
"$",
"validator",
"=",
"new",
"$",
"class",
"(",
"$",
"object",
"->",
"{",
"$",
"indexProperty",
"}",
")",
";",
"return",
"$",
"validator",
";",
"}"
] |
Helper method.
Used to create anyOf, allOf and oneOf validators from objects
@param object $object Validation object
@return AnyOf|AllOf|OneOf|null
|
[
"Helper",
"method",
".",
"Used",
"to",
"create",
"anyOf",
"allOf",
"and",
"oneOf",
"validators",
"from",
"objects"
] |
22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc
|
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/BaseValidator.php#L534-L560
|
15,110
|
phramework/validate
|
src/BaseValidator.php
|
BaseValidator.createFromObject
|
public static function createFromObject($object)
{
$isFromBase = (static::class === self::class);
if (!is_object($object)) {
throw new \Exception('Expecting an object');
}
//Test type if it's set
if (property_exists($object, 'type') && !empty($object->type)) {
if (array_key_exists($object->type, self::$validatorRegistry)) {
if (is_object($object->type) || is_array($object->type) || $object->type === null) {
throw new \Exception('Expecting string for type');
}
$className = self::$validatorRegistry[$object->type];
$validator = new $className();
/*} elseif (class_exists(__NAMESPACE__ . '\\' . $object->type)) {
//if already loaded
$className = __NAMESPACE__ . '\\' . $object->type;
$validator = new $className();
} elseif (class_exists(__NAMESPACE__ . '\\' . $object->type . 'Validator')) {
//if already loaded
$className = __NAMESPACE__ . '\\' . $object->type . 'Validator';
$validator = new $className();*/
} else {
$className = $object->type . 'Validator';
try {
//prevent fatal error
new \ReflectionClass($className);
//attempt to create class
$validator = new $className();
} catch (\Exception $e) {
//Wont catch the fatal error
throw new \Exception(sprintf(
'Incorrect type "%s" from "%s"',
$object->type,
static::class
));
}
}
} elseif (($validator = static::createFromObjectForAdditional($object)) !== null) {
return $validator;
} elseif (!$isFromBase
|| (isset($object->type) && !empty($object->type) && $object->type == static::$type)
) {
$validator = new static();
} else {
throw new \Exception(sprintf(
'Type is required when creating from "%s"',
self::class
));
}
//For each Validator's attribute
foreach (array_merge(
$validator::getTypeAttributes(),
$validator::$commonAttributes
) as $attribute) {
//Check if provided object contains this attribute
if (property_exists($object, $attribute)) {
if ($attribute == 'properties') {
//get properties as array
$properties = $object->{$attribute};
$createdProperties = new \stdClass();
foreach ($properties as $key => $property) {
//TODO remove
//if (!is_object($property)) {
// throw new \Exception(sprintf(
// 'Expected object for property value "%s"',
// $key
// ));
//}
$createdProperties->{$key} =
BaseValidator::createFromObject($property);
}
//push to class
$validator->{$attribute} = $createdProperties;
} elseif ($attribute == 'items' || $attribute == 'not') {
$validator->{$attribute} = BaseValidator::createFromObject(
$object->{$attribute}
);
} else {
//Use attributes value in Validator object
$validator->{$attribute} = $object->{$attribute};
}
}
}
return $validator;
}
|
php
|
public static function createFromObject($object)
{
$isFromBase = (static::class === self::class);
if (!is_object($object)) {
throw new \Exception('Expecting an object');
}
//Test type if it's set
if (property_exists($object, 'type') && !empty($object->type)) {
if (array_key_exists($object->type, self::$validatorRegistry)) {
if (is_object($object->type) || is_array($object->type) || $object->type === null) {
throw new \Exception('Expecting string for type');
}
$className = self::$validatorRegistry[$object->type];
$validator = new $className();
/*} elseif (class_exists(__NAMESPACE__ . '\\' . $object->type)) {
//if already loaded
$className = __NAMESPACE__ . '\\' . $object->type;
$validator = new $className();
} elseif (class_exists(__NAMESPACE__ . '\\' . $object->type . 'Validator')) {
//if already loaded
$className = __NAMESPACE__ . '\\' . $object->type . 'Validator';
$validator = new $className();*/
} else {
$className = $object->type . 'Validator';
try {
//prevent fatal error
new \ReflectionClass($className);
//attempt to create class
$validator = new $className();
} catch (\Exception $e) {
//Wont catch the fatal error
throw new \Exception(sprintf(
'Incorrect type "%s" from "%s"',
$object->type,
static::class
));
}
}
} elseif (($validator = static::createFromObjectForAdditional($object)) !== null) {
return $validator;
} elseif (!$isFromBase
|| (isset($object->type) && !empty($object->type) && $object->type == static::$type)
) {
$validator = new static();
} else {
throw new \Exception(sprintf(
'Type is required when creating from "%s"',
self::class
));
}
//For each Validator's attribute
foreach (array_merge(
$validator::getTypeAttributes(),
$validator::$commonAttributes
) as $attribute) {
//Check if provided object contains this attribute
if (property_exists($object, $attribute)) {
if ($attribute == 'properties') {
//get properties as array
$properties = $object->{$attribute};
$createdProperties = new \stdClass();
foreach ($properties as $key => $property) {
//TODO remove
//if (!is_object($property)) {
// throw new \Exception(sprintf(
// 'Expected object for property value "%s"',
// $key
// ));
//}
$createdProperties->{$key} =
BaseValidator::createFromObject($property);
}
//push to class
$validator->{$attribute} = $createdProperties;
} elseif ($attribute == 'items' || $attribute == 'not') {
$validator->{$attribute} = BaseValidator::createFromObject(
$object->{$attribute}
);
} else {
//Use attributes value in Validator object
$validator->{$attribute} = $object->{$attribute};
}
}
}
return $validator;
}
|
[
"public",
"static",
"function",
"createFromObject",
"(",
"$",
"object",
")",
"{",
"$",
"isFromBase",
"=",
"(",
"static",
"::",
"class",
"===",
"self",
"::",
"class",
")",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Expecting an object'",
")",
";",
"}",
"//Test type if it's set",
"if",
"(",
"property_exists",
"(",
"$",
"object",
",",
"'type'",
")",
"&&",
"!",
"empty",
"(",
"$",
"object",
"->",
"type",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"object",
"->",
"type",
",",
"self",
"::",
"$",
"validatorRegistry",
")",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"object",
"->",
"type",
")",
"||",
"is_array",
"(",
"$",
"object",
"->",
"type",
")",
"||",
"$",
"object",
"->",
"type",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Expecting string for type'",
")",
";",
"}",
"$",
"className",
"=",
"self",
"::",
"$",
"validatorRegistry",
"[",
"$",
"object",
"->",
"type",
"]",
";",
"$",
"validator",
"=",
"new",
"$",
"className",
"(",
")",
";",
"/*} elseif (class_exists(__NAMESPACE__ . '\\\\' . $object->type)) {\n //if already loaded\n $className = __NAMESPACE__ . '\\\\' . $object->type;\n $validator = new $className();\n } elseif (class_exists(__NAMESPACE__ . '\\\\' . $object->type . 'Validator')) {\n //if already loaded\n $className = __NAMESPACE__ . '\\\\' . $object->type . 'Validator';\n $validator = new $className();*/",
"}",
"else",
"{",
"$",
"className",
"=",
"$",
"object",
"->",
"type",
".",
"'Validator'",
";",
"try",
"{",
"//prevent fatal error",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"//attempt to create class",
"$",
"validator",
"=",
"new",
"$",
"className",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"//Wont catch the fatal error",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Incorrect type \"%s\" from \"%s\"'",
",",
"$",
"object",
"->",
"type",
",",
"static",
"::",
"class",
")",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"(",
"$",
"validator",
"=",
"static",
"::",
"createFromObjectForAdditional",
"(",
"$",
"object",
")",
")",
"!==",
"null",
")",
"{",
"return",
"$",
"validator",
";",
"}",
"elseif",
"(",
"!",
"$",
"isFromBase",
"||",
"(",
"isset",
"(",
"$",
"object",
"->",
"type",
")",
"&&",
"!",
"empty",
"(",
"$",
"object",
"->",
"type",
")",
"&&",
"$",
"object",
"->",
"type",
"==",
"static",
"::",
"$",
"type",
")",
")",
"{",
"$",
"validator",
"=",
"new",
"static",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Type is required when creating from \"%s\"'",
",",
"self",
"::",
"class",
")",
")",
";",
"}",
"//For each Validator's attribute",
"foreach",
"(",
"array_merge",
"(",
"$",
"validator",
"::",
"getTypeAttributes",
"(",
")",
",",
"$",
"validator",
"::",
"$",
"commonAttributes",
")",
"as",
"$",
"attribute",
")",
"{",
"//Check if provided object contains this attribute",
"if",
"(",
"property_exists",
"(",
"$",
"object",
",",
"$",
"attribute",
")",
")",
"{",
"if",
"(",
"$",
"attribute",
"==",
"'properties'",
")",
"{",
"//get properties as array",
"$",
"properties",
"=",
"$",
"object",
"->",
"{",
"$",
"attribute",
"}",
";",
"$",
"createdProperties",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"key",
"=>",
"$",
"property",
")",
"{",
"//TODO remove",
"//if (!is_object($property)) {",
"// throw new \\Exception(sprintf(",
"// 'Expected object for property value \"%s\"',",
"// $key",
"// ));",
"//}",
"$",
"createdProperties",
"->",
"{",
"$",
"key",
"}",
"=",
"BaseValidator",
"::",
"createFromObject",
"(",
"$",
"property",
")",
";",
"}",
"//push to class",
"$",
"validator",
"->",
"{",
"$",
"attribute",
"}",
"=",
"$",
"createdProperties",
";",
"}",
"elseif",
"(",
"$",
"attribute",
"==",
"'items'",
"||",
"$",
"attribute",
"==",
"'not'",
")",
"{",
"$",
"validator",
"->",
"{",
"$",
"attribute",
"}",
"=",
"BaseValidator",
"::",
"createFromObject",
"(",
"$",
"object",
"->",
"{",
"$",
"attribute",
"}",
")",
";",
"}",
"else",
"{",
"//Use attributes value in Validator object",
"$",
"validator",
"->",
"{",
"$",
"attribute",
"}",
"=",
"$",
"object",
"->",
"{",
"$",
"attribute",
"}",
";",
"}",
"}",
"}",
"return",
"$",
"validator",
";",
"}"
] |
Create validator from validation object
@param object $object Validation object
@return BaseValidator
@todo cleanup class loading
@throws \Exception When validator class cannot be found for object's type
|
[
"Create",
"validator",
"from",
"validation",
"object"
] |
22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc
|
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/BaseValidator.php#L569-L662
|
15,111
|
phramework/validate
|
src/BaseValidator.php
|
BaseValidator.createFromJSON
|
public static function createFromJSON($json)
{
$object = json_decode($json);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \Exception(
'JSON parse had errors - ' . json_last_error_msg()
);
}
return static::createFromObject($object);
}
|
php
|
public static function createFromJSON($json)
{
$object = json_decode($json);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \Exception(
'JSON parse had errors - ' . json_last_error_msg()
);
}
return static::createFromObject($object);
}
|
[
"public",
"static",
"function",
"createFromJSON",
"(",
"$",
"json",
")",
"{",
"$",
"object",
"=",
"json_decode",
"(",
"$",
"json",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"!==",
"JSON_ERROR_NONE",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'JSON parse had errors - '",
".",
"json_last_error_msg",
"(",
")",
")",
";",
"}",
"return",
"static",
"::",
"createFromObject",
"(",
"$",
"object",
")",
";",
"}"
] |
Create validator from validation object encoded as json object
@param string $json Validation json encoded object
@return BaseValidator
@throws \Exception when JSON sting is not well formed
|
[
"Create",
"validator",
"from",
"validation",
"object",
"encoded",
"as",
"json",
"object"
] |
22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc
|
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/BaseValidator.php#L681-L692
|
15,112
|
phramework/validate
|
src/BaseValidator.php
|
BaseValidator.toJSON
|
public function toJSON($JSON_PRETTY_PRINT = false)
{
$object = $this->toObject();
/*foreach ($object as $key => &$attribute) {
//Check if any of attributes is an instance of BaseValidator
if (is_object($attribute) && is_a($attribute, BaseValidator::class)) {
$attribute = $attribute->toObject();
}
}*/
return json_encode(
$object,
($JSON_PRETTY_PRINT ? JSON_PRETTY_PRINT : 0)
);
}
|
php
|
public function toJSON($JSON_PRETTY_PRINT = false)
{
$object = $this->toObject();
/*foreach ($object as $key => &$attribute) {
//Check if any of attributes is an instance of BaseValidator
if (is_object($attribute) && is_a($attribute, BaseValidator::class)) {
$attribute = $attribute->toObject();
}
}*/
return json_encode(
$object,
($JSON_PRETTY_PRINT ? JSON_PRETTY_PRINT : 0)
);
}
|
[
"public",
"function",
"toJSON",
"(",
"$",
"JSON_PRETTY_PRINT",
"=",
"false",
")",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"toObject",
"(",
")",
";",
"/*foreach ($object as $key => &$attribute) {\n //Check if any of attributes is an instance of BaseValidator\n if (is_object($attribute) && is_a($attribute, BaseValidator::class)) {\n $attribute = $attribute->toObject();\n }\n }*/",
"return",
"json_encode",
"(",
"$",
"object",
",",
"(",
"$",
"JSON_PRETTY_PRINT",
"?",
"JSON_PRETTY_PRINT",
":",
"0",
")",
")",
";",
"}"
] |
Export validator to json encoded string
@param boolean $JSON_PRETTY_PRINT *[Optional]*
@return string
|
[
"Export",
"validator",
"to",
"json",
"encoded",
"string"
] |
22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc
|
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/BaseValidator.php#L699-L714
|
15,113
|
phramework/validate
|
src/BaseValidator.php
|
BaseValidator.toObject
|
public function toObject()
{
$object = $this->toArray();
//fix type to object
if (isset($object['properties'])) {
$object['properties'] = (object)$object['properties'];
}
foreach (['anyOf', 'allOf', 'oneOf', 'not'] as $property) {
//fix type to object
if (isset($object[$property])) {
foreach ($object[$property] as &$propertyItem) {
$propertyItem = (object)$propertyItem;
}
}
}
return (object)$object;
}
|
php
|
public function toObject()
{
$object = $this->toArray();
//fix type to object
if (isset($object['properties'])) {
$object['properties'] = (object)$object['properties'];
}
foreach (['anyOf', 'allOf', 'oneOf', 'not'] as $property) {
//fix type to object
if (isset($object[$property])) {
foreach ($object[$property] as &$propertyItem) {
$propertyItem = (object)$propertyItem;
}
}
}
return (object)$object;
}
|
[
"public",
"function",
"toObject",
"(",
")",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"toArray",
"(",
")",
";",
"//fix type to object",
"if",
"(",
"isset",
"(",
"$",
"object",
"[",
"'properties'",
"]",
")",
")",
"{",
"$",
"object",
"[",
"'properties'",
"]",
"=",
"(",
"object",
")",
"$",
"object",
"[",
"'properties'",
"]",
";",
"}",
"foreach",
"(",
"[",
"'anyOf'",
",",
"'allOf'",
",",
"'oneOf'",
",",
"'not'",
"]",
"as",
"$",
"property",
")",
"{",
"//fix type to object",
"if",
"(",
"isset",
"(",
"$",
"object",
"[",
"$",
"property",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"object",
"[",
"$",
"property",
"]",
"as",
"&",
"$",
"propertyItem",
")",
"{",
"$",
"propertyItem",
"=",
"(",
"object",
")",
"$",
"propertyItem",
";",
"}",
"}",
"}",
"return",
"(",
"object",
")",
"$",
"object",
";",
"}"
] |
Export validator to object
@return object
|
[
"Export",
"validator",
"to",
"object"
] |
22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc
|
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/BaseValidator.php#L720-L739
|
15,114
|
phramework/validate
|
src/BaseValidator.php
|
BaseValidator.toArray
|
public function toArray()
{
$object = [];
if (static::$type) {
$object['type'] = static::$type;
}
$attributes = array_merge(
static::getTypeAttributes(),
static::$commonAttributes
);
foreach ($attributes as $attribute) {
$value = $this->{$attribute};
if ($value !== null) {
$toCopy = $value;
//Clone object to prevent original object to be changed
if (is_object($value)) {
$toCopy = clone $value;
}
$object[$attribute] = $toCopy;
}
if (static::$type == 'object' && $attribute == 'properties') {
foreach ($object[$attribute] as $key => $property) {
if ($property instanceof BaseValidator) {
$object[$attribute]->{$key} = $property->toArray();
}
}
//fix type to array
$object[$attribute] = (array)$object[$attribute];
} elseif (in_array($attribute, ['allOf', 'anyOf', 'oneOf'])) {
if (isset($object[$attribute]) && $object[$attribute] !== null) {
foreach ($object[$attribute] as $key => $property) {
if ($property instanceof BaseValidator) {
$object[$attribute][$key] = $property->toArray();
}
}
}
} elseif (in_array($attribute, ['items', 'not'])) {
if (isset($object[$attribute])
&& $object[$attribute]
&& $object[$attribute] instanceof BaseValidator
) {
$object[$attribute] = $object[$attribute]->toArray();
}
}
}
return $object;
}
|
php
|
public function toArray()
{
$object = [];
if (static::$type) {
$object['type'] = static::$type;
}
$attributes = array_merge(
static::getTypeAttributes(),
static::$commonAttributes
);
foreach ($attributes as $attribute) {
$value = $this->{$attribute};
if ($value !== null) {
$toCopy = $value;
//Clone object to prevent original object to be changed
if (is_object($value)) {
$toCopy = clone $value;
}
$object[$attribute] = $toCopy;
}
if (static::$type == 'object' && $attribute == 'properties') {
foreach ($object[$attribute] as $key => $property) {
if ($property instanceof BaseValidator) {
$object[$attribute]->{$key} = $property->toArray();
}
}
//fix type to array
$object[$attribute] = (array)$object[$attribute];
} elseif (in_array($attribute, ['allOf', 'anyOf', 'oneOf'])) {
if (isset($object[$attribute]) && $object[$attribute] !== null) {
foreach ($object[$attribute] as $key => $property) {
if ($property instanceof BaseValidator) {
$object[$attribute][$key] = $property->toArray();
}
}
}
} elseif (in_array($attribute, ['items', 'not'])) {
if (isset($object[$attribute])
&& $object[$attribute]
&& $object[$attribute] instanceof BaseValidator
) {
$object[$attribute] = $object[$attribute]->toArray();
}
}
}
return $object;
}
|
[
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"object",
"=",
"[",
"]",
";",
"if",
"(",
"static",
"::",
"$",
"type",
")",
"{",
"$",
"object",
"[",
"'type'",
"]",
"=",
"static",
"::",
"$",
"type",
";",
"}",
"$",
"attributes",
"=",
"array_merge",
"(",
"static",
"::",
"getTypeAttributes",
"(",
")",
",",
"static",
"::",
"$",
"commonAttributes",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"{",
"$",
"attribute",
"}",
";",
"if",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"$",
"toCopy",
"=",
"$",
"value",
";",
"//Clone object to prevent original object to be changed",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"toCopy",
"=",
"clone",
"$",
"value",
";",
"}",
"$",
"object",
"[",
"$",
"attribute",
"]",
"=",
"$",
"toCopy",
";",
"}",
"if",
"(",
"static",
"::",
"$",
"type",
"==",
"'object'",
"&&",
"$",
"attribute",
"==",
"'properties'",
")",
"{",
"foreach",
"(",
"$",
"object",
"[",
"$",
"attribute",
"]",
"as",
"$",
"key",
"=>",
"$",
"property",
")",
"{",
"if",
"(",
"$",
"property",
"instanceof",
"BaseValidator",
")",
"{",
"$",
"object",
"[",
"$",
"attribute",
"]",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"property",
"->",
"toArray",
"(",
")",
";",
"}",
"}",
"//fix type to array",
"$",
"object",
"[",
"$",
"attribute",
"]",
"=",
"(",
"array",
")",
"$",
"object",
"[",
"$",
"attribute",
"]",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"attribute",
",",
"[",
"'allOf'",
",",
"'anyOf'",
",",
"'oneOf'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"object",
"[",
"$",
"attribute",
"]",
")",
"&&",
"$",
"object",
"[",
"$",
"attribute",
"]",
"!==",
"null",
")",
"{",
"foreach",
"(",
"$",
"object",
"[",
"$",
"attribute",
"]",
"as",
"$",
"key",
"=>",
"$",
"property",
")",
"{",
"if",
"(",
"$",
"property",
"instanceof",
"BaseValidator",
")",
"{",
"$",
"object",
"[",
"$",
"attribute",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"property",
"->",
"toArray",
"(",
")",
";",
"}",
"}",
"}",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"attribute",
",",
"[",
"'items'",
",",
"'not'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"object",
"[",
"$",
"attribute",
"]",
")",
"&&",
"$",
"object",
"[",
"$",
"attribute",
"]",
"&&",
"$",
"object",
"[",
"$",
"attribute",
"]",
"instanceof",
"BaseValidator",
")",
"{",
"$",
"object",
"[",
"$",
"attribute",
"]",
"=",
"$",
"object",
"[",
"$",
"attribute",
"]",
"->",
"toArray",
"(",
")",
";",
"}",
"}",
"}",
"return",
"$",
"object",
";",
"}"
] |
Export validator to array
@return array
|
[
"Export",
"validator",
"to",
"array"
] |
22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc
|
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/BaseValidator.php#L745-L799
|
15,115
|
tjbp/laravel-verify-emails
|
src/Auth/VerifyEmails/VerifyEmailBroker.php
|
VerifyEmailBroker.sendVerificationLink
|
public function sendVerificationLink(CanVerifyEmailContract $user, Closure $callback = null)
{
// Once we have the verify token, we are ready to send the message out to this
// user with a link to verify their email. We will then redirect back to
// the current URI having nothing set in the session to indicate errors.
$token = $this->tokens->create($user);
$this->emailVerificationLink($user, $token, $callback);
return VerifyEmailBrokerContract::VERIFY_LINK_SENT;
}
|
php
|
public function sendVerificationLink(CanVerifyEmailContract $user, Closure $callback = null)
{
// Once we have the verify token, we are ready to send the message out to this
// user with a link to verify their email. We will then redirect back to
// the current URI having nothing set in the session to indicate errors.
$token = $this->tokens->create($user);
$this->emailVerificationLink($user, $token, $callback);
return VerifyEmailBrokerContract::VERIFY_LINK_SENT;
}
|
[
"public",
"function",
"sendVerificationLink",
"(",
"CanVerifyEmailContract",
"$",
"user",
",",
"Closure",
"$",
"callback",
"=",
"null",
")",
"{",
"// Once we have the verify token, we are ready to send the message out to this",
"// user with a link to verify their email. We will then redirect back to",
"// the current URI having nothing set in the session to indicate errors.",
"$",
"token",
"=",
"$",
"this",
"->",
"tokens",
"->",
"create",
"(",
"$",
"user",
")",
";",
"$",
"this",
"->",
"emailVerificationLink",
"(",
"$",
"user",
",",
"$",
"token",
",",
"$",
"callback",
")",
";",
"return",
"VerifyEmailBrokerContract",
"::",
"VERIFY_LINK_SENT",
";",
"}"
] |
Send an email verification link to a user.
@param \LaravelVerifyEmails\Contracts\Auth\CanVerifyEmail $user
@param \Closure|null $callback
@return string
|
[
"Send",
"an",
"email",
"verification",
"link",
"to",
"a",
"user",
"."
] |
1e2ac10a696c10f2fdf0d7de6c3388d549bc07c6
|
https://github.com/tjbp/laravel-verify-emails/blob/1e2ac10a696c10f2fdf0d7de6c3388d549bc07c6/src/Auth/VerifyEmails/VerifyEmailBroker.php#L55-L65
|
15,116
|
tjbp/laravel-verify-emails
|
src/Auth/VerifyEmails/VerifyEmailBroker.php
|
VerifyEmailBroker.verify
|
public function verify(CanVerifyEmailContract $user, $token)
{
// If the responses from the validate method is not a user instance, we will
// assume that it is a redirect and simply return it from this method and
// the user is properly redirected having an error message on the post.
$user = $this->validateVerification($user, $token);
if (! $user instanceof CanVerifyEmailContract) {
return $user;
}
$this->tokens->delete($token);
$user->setVerified(true);
$user->save();
return VerifyEmailBrokerContract::EMAIL_VERIFIED;
}
|
php
|
public function verify(CanVerifyEmailContract $user, $token)
{
// If the responses from the validate method is not a user instance, we will
// assume that it is a redirect and simply return it from this method and
// the user is properly redirected having an error message on the post.
$user = $this->validateVerification($user, $token);
if (! $user instanceof CanVerifyEmailContract) {
return $user;
}
$this->tokens->delete($token);
$user->setVerified(true);
$user->save();
return VerifyEmailBrokerContract::EMAIL_VERIFIED;
}
|
[
"public",
"function",
"verify",
"(",
"CanVerifyEmailContract",
"$",
"user",
",",
"$",
"token",
")",
"{",
"// If the responses from the validate method is not a user instance, we will",
"// assume that it is a redirect and simply return it from this method and",
"// the user is properly redirected having an error message on the post.",
"$",
"user",
"=",
"$",
"this",
"->",
"validateVerification",
"(",
"$",
"user",
",",
"$",
"token",
")",
";",
"if",
"(",
"!",
"$",
"user",
"instanceof",
"CanVerifyEmailContract",
")",
"{",
"return",
"$",
"user",
";",
"}",
"$",
"this",
"->",
"tokens",
"->",
"delete",
"(",
"$",
"token",
")",
";",
"$",
"user",
"->",
"setVerified",
"(",
"true",
")",
";",
"$",
"user",
"->",
"save",
"(",
")",
";",
"return",
"VerifyEmailBrokerContract",
"::",
"EMAIL_VERIFIED",
";",
"}"
] |
Verify the email address for the given token.
@param \LaravelVerifyEmails\Contracts\Auth\CanVerifyEmail $user
@param string $token
@return mixed
|
[
"Verify",
"the",
"email",
"address",
"for",
"the",
"given",
"token",
"."
] |
1e2ac10a696c10f2fdf0d7de6c3388d549bc07c6
|
https://github.com/tjbp/laravel-verify-emails/blob/1e2ac10a696c10f2fdf0d7de6c3388d549bc07c6/src/Auth/VerifyEmails/VerifyEmailBroker.php#L98-L116
|
15,117
|
tjbp/laravel-verify-emails
|
src/Auth/VerifyEmails/VerifyEmailBroker.php
|
VerifyEmailBroker.validateVerification
|
protected function validateVerification(CanVerifyEmailContract $user, $token)
{
if (! $this->tokens->exists($user, $token)) {
return VerifyEmailBrokerContract::INVALID_TOKEN;
}
return $user;
}
|
php
|
protected function validateVerification(CanVerifyEmailContract $user, $token)
{
if (! $this->tokens->exists($user, $token)) {
return VerifyEmailBrokerContract::INVALID_TOKEN;
}
return $user;
}
|
[
"protected",
"function",
"validateVerification",
"(",
"CanVerifyEmailContract",
"$",
"user",
",",
"$",
"token",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"tokens",
"->",
"exists",
"(",
"$",
"user",
",",
"$",
"token",
")",
")",
"{",
"return",
"VerifyEmailBrokerContract",
"::",
"INVALID_TOKEN",
";",
"}",
"return",
"$",
"user",
";",
"}"
] |
Validate a verification for the given credentials.
@param \LaravelVerifyEmails\Contracts\Auth\CanVerifyEmail $user
@param string $token
@return \LaravelVerifyEmails\Contracts\Auth\CanVerifyEmail
|
[
"Validate",
"a",
"verification",
"for",
"the",
"given",
"credentials",
"."
] |
1e2ac10a696c10f2fdf0d7de6c3388d549bc07c6
|
https://github.com/tjbp/laravel-verify-emails/blob/1e2ac10a696c10f2fdf0d7de6c3388d549bc07c6/src/Auth/VerifyEmails/VerifyEmailBroker.php#L125-L132
|
15,118
|
aindong/pluggables
|
src/Aindong/Pluggables/Console/PluggableMigrateRefreshCommand.php
|
PluggableMigrateRefreshCommand.runSeeder
|
protected function runSeeder($module = null, $database = null)
{
$this->call('pluggables:seed', [
'pluggable' => $this->argument('pluggable'),
'--database' => $database,
]);
}
|
php
|
protected function runSeeder($module = null, $database = null)
{
$this->call('pluggables:seed', [
'pluggable' => $this->argument('pluggable'),
'--database' => $database,
]);
}
|
[
"protected",
"function",
"runSeeder",
"(",
"$",
"module",
"=",
"null",
",",
"$",
"database",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"call",
"(",
"'pluggables:seed'",
",",
"[",
"'pluggable'",
"=>",
"$",
"this",
"->",
"argument",
"(",
"'pluggable'",
")",
",",
"'--database'",
"=>",
"$",
"database",
",",
"]",
")",
";",
"}"
] |
Run the module seeder command.
@param string $database
@return void
|
[
"Run",
"the",
"module",
"seeder",
"command",
"."
] |
bf8bab46fb65268043fb4b98db21f8e0338b5e96
|
https://github.com/aindong/pluggables/blob/bf8bab46fb65268043fb4b98db21f8e0338b5e96/src/Aindong/Pluggables/Console/PluggableMigrateRefreshCommand.php#L87-L93
|
15,119
|
hrevert/HtUserRegistration
|
src/Controller/UserRegistrationController.php
|
UserRegistrationController.verifyEmailAction
|
public function verifyEmailAction()
{
$userId = $this->params()->fromRoute('userId', null);
$token = $this->params()->fromRoute('token', null);
if ($userId === null || $token === null) {
return $this->notFoundAction();
}
$user = $this->getUserMapper()->findById($userId);
if (!$user) {
return $this->notFoundAction();
}
if ($this->userRegistrationService->verifyEmail($user, $token)) {
// email verified
return $this->redirectToPostVerificationRoute();
}
// email not verified, probably invalid token
$vm = new ViewModel();
$vm->setTemplate('ht-user-registration/user-registration/verify-email-error.phtml');
return $vm;
}
|
php
|
public function verifyEmailAction()
{
$userId = $this->params()->fromRoute('userId', null);
$token = $this->params()->fromRoute('token', null);
if ($userId === null || $token === null) {
return $this->notFoundAction();
}
$user = $this->getUserMapper()->findById($userId);
if (!$user) {
return $this->notFoundAction();
}
if ($this->userRegistrationService->verifyEmail($user, $token)) {
// email verified
return $this->redirectToPostVerificationRoute();
}
// email not verified, probably invalid token
$vm = new ViewModel();
$vm->setTemplate('ht-user-registration/user-registration/verify-email-error.phtml');
return $vm;
}
|
[
"public",
"function",
"verifyEmailAction",
"(",
")",
"{",
"$",
"userId",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'userId'",
",",
"null",
")",
";",
"$",
"token",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'token'",
",",
"null",
")",
";",
"if",
"(",
"$",
"userId",
"===",
"null",
"||",
"$",
"token",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"notFoundAction",
"(",
")",
";",
"}",
"$",
"user",
"=",
"$",
"this",
"->",
"getUserMapper",
"(",
")",
"->",
"findById",
"(",
"$",
"userId",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"return",
"$",
"this",
"->",
"notFoundAction",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"userRegistrationService",
"->",
"verifyEmail",
"(",
"$",
"user",
",",
"$",
"token",
")",
")",
"{",
"// email verified",
"return",
"$",
"this",
"->",
"redirectToPostVerificationRoute",
"(",
")",
";",
"}",
"// email not verified, probably invalid token",
"$",
"vm",
"=",
"new",
"ViewModel",
"(",
")",
";",
"$",
"vm",
"->",
"setTemplate",
"(",
"'ht-user-registration/user-registration/verify-email-error.phtml'",
")",
";",
"return",
"$",
"vm",
";",
"}"
] |
Verifies user`s email address and redirects to login route
|
[
"Verifies",
"user",
"s",
"email",
"address",
"and",
"redirects",
"to",
"login",
"route"
] |
6b4a0cc364153757290ab5eed9ffafe1228f3bd6
|
https://github.com/hrevert/HtUserRegistration/blob/6b4a0cc364153757290ab5eed9ffafe1228f3bd6/src/Controller/UserRegistrationController.php#L44-L70
|
15,120
|
hrevert/HtUserRegistration
|
src/Controller/UserRegistrationController.php
|
UserRegistrationController.setPasswordAction
|
public function setPasswordAction()
{
$userId = $this->params()->fromRoute('userId', null);
$token = $this->params()->fromRoute('token', null);
if ($userId === null || $token === null) {
return $this->notFoundAction();
}
$user = $this->getUserMapper()->findById($userId);
if (!$user) {
return $this->notFoundAction();
}
$record = $this->getUserRegistrationMapper()->findByUser($user);
if (!$record || !$this->userRegistrationService->isTokenValid($user, $token, $record)) {
// Invalid Token, Lets surprise the attacker
return $this->notFoundAction();
}
if ($record->isResponded()) {
// old link, password is already set by the user
return $this->redirectToPostVerificationRoute();
}
$form = $this->getServiceLocator()->get('HtUserRegistration\SetPasswordForm');
if ($this->getRequest()->isPost()) {
$form->setData($this->getRequest()->getPost());
if ($form->isValid()) {
$this->userRegistrationService->setPassword($form->getData(), $record);
return $this->redirectToPostVerificationRoute();
}
}
return array(
'user' => $user,
'form' => $form
);
}
|
php
|
public function setPasswordAction()
{
$userId = $this->params()->fromRoute('userId', null);
$token = $this->params()->fromRoute('token', null);
if ($userId === null || $token === null) {
return $this->notFoundAction();
}
$user = $this->getUserMapper()->findById($userId);
if (!$user) {
return $this->notFoundAction();
}
$record = $this->getUserRegistrationMapper()->findByUser($user);
if (!$record || !$this->userRegistrationService->isTokenValid($user, $token, $record)) {
// Invalid Token, Lets surprise the attacker
return $this->notFoundAction();
}
if ($record->isResponded()) {
// old link, password is already set by the user
return $this->redirectToPostVerificationRoute();
}
$form = $this->getServiceLocator()->get('HtUserRegistration\SetPasswordForm');
if ($this->getRequest()->isPost()) {
$form->setData($this->getRequest()->getPost());
if ($form->isValid()) {
$this->userRegistrationService->setPassword($form->getData(), $record);
return $this->redirectToPostVerificationRoute();
}
}
return array(
'user' => $user,
'form' => $form
);
}
|
[
"public",
"function",
"setPasswordAction",
"(",
")",
"{",
"$",
"userId",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'userId'",
",",
"null",
")",
";",
"$",
"token",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'token'",
",",
"null",
")",
";",
"if",
"(",
"$",
"userId",
"===",
"null",
"||",
"$",
"token",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"notFoundAction",
"(",
")",
";",
"}",
"$",
"user",
"=",
"$",
"this",
"->",
"getUserMapper",
"(",
")",
"->",
"findById",
"(",
"$",
"userId",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"return",
"$",
"this",
"->",
"notFoundAction",
"(",
")",
";",
"}",
"$",
"record",
"=",
"$",
"this",
"->",
"getUserRegistrationMapper",
"(",
")",
"->",
"findByUser",
"(",
"$",
"user",
")",
";",
"if",
"(",
"!",
"$",
"record",
"||",
"!",
"$",
"this",
"->",
"userRegistrationService",
"->",
"isTokenValid",
"(",
"$",
"user",
",",
"$",
"token",
",",
"$",
"record",
")",
")",
"{",
"// Invalid Token, Lets surprise the attacker",
"return",
"$",
"this",
"->",
"notFoundAction",
"(",
")",
";",
"}",
"if",
"(",
"$",
"record",
"->",
"isResponded",
"(",
")",
")",
"{",
"// old link, password is already set by the user",
"return",
"$",
"this",
"->",
"redirectToPostVerificationRoute",
"(",
")",
";",
"}",
"$",
"form",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'HtUserRegistration\\SetPasswordForm'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"form",
"->",
"setData",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getPost",
"(",
")",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"userRegistrationService",
"->",
"setPassword",
"(",
"$",
"form",
"->",
"getData",
"(",
")",
",",
"$",
"record",
")",
";",
"return",
"$",
"this",
"->",
"redirectToPostVerificationRoute",
"(",
")",
";",
"}",
"}",
"return",
"array",
"(",
"'user'",
"=>",
"$",
"user",
",",
"'form'",
"=>",
"$",
"form",
")",
";",
"}"
] |
Allows users to set their account password
|
[
"Allows",
"users",
"to",
"set",
"their",
"account",
"password"
] |
6b4a0cc364153757290ab5eed9ffafe1228f3bd6
|
https://github.com/hrevert/HtUserRegistration/blob/6b4a0cc364153757290ab5eed9ffafe1228f3bd6/src/Controller/UserRegistrationController.php#L75-L117
|
15,121
|
blast-project/CoreBundle
|
src/DependencyInjection/BlastCoreExtension.php
|
BlastCoreExtension.buildLoader
|
public function buildLoader(ContainerBuilder $container)
{
return new YamlFileLoader($container, new FileLocator($this->dir . $this->prefix));
}
|
php
|
public function buildLoader(ContainerBuilder $container)
{
return new YamlFileLoader($container, new FileLocator($this->dir . $this->prefix));
}
|
[
"public",
"function",
"buildLoader",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"return",
"new",
"YamlFileLoader",
"(",
"$",
"container",
",",
"new",
"FileLocator",
"(",
"$",
"this",
"->",
"dir",
".",
"$",
"this",
"->",
"prefix",
")",
")",
";",
"}"
] |
the buildLoader returns the required FileLoader.
@param ContainerBuilder $container
@return FileLoader
|
[
"the",
"buildLoader",
"returns",
"the",
"required",
"FileLoader",
"."
] |
7a0832758ca14e5bc5d65515532c1220df3930ae
|
https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/DependencyInjection/BlastCoreExtension.php#L70-L73
|
15,122
|
baleen/cli
|
src/CommandBus/Repository/CreateHandler.php
|
CreateHandler.writeClass
|
protected function writeClass(ClassGenerator $class, Filesystem $filesystem, $destinationDir)
{
$className = $class->getName();
$file = new FileGenerator([
'fileName' => $className.'.php',
'classes' => [$class],
]);
$contents = $file->generate();
$relativePath = $destinationDir.DIRECTORY_SEPARATOR.$file->getFilename();
if ($filesystem->has($relativePath)) {
throw new CliException(sprintf(
'Could not generate migration. File already exists: %s',
$relativePath
));
}
$result = $filesystem->write($relativePath, $contents);
return $result ? $relativePath : false;
}
|
php
|
protected function writeClass(ClassGenerator $class, Filesystem $filesystem, $destinationDir)
{
$className = $class->getName();
$file = new FileGenerator([
'fileName' => $className.'.php',
'classes' => [$class],
]);
$contents = $file->generate();
$relativePath = $destinationDir.DIRECTORY_SEPARATOR.$file->getFilename();
if ($filesystem->has($relativePath)) {
throw new CliException(sprintf(
'Could not generate migration. File already exists: %s',
$relativePath
));
}
$result = $filesystem->write($relativePath, $contents);
return $result ? $relativePath : false;
}
|
[
"protected",
"function",
"writeClass",
"(",
"ClassGenerator",
"$",
"class",
",",
"Filesystem",
"$",
"filesystem",
",",
"$",
"destinationDir",
")",
"{",
"$",
"className",
"=",
"$",
"class",
"->",
"getName",
"(",
")",
";",
"$",
"file",
"=",
"new",
"FileGenerator",
"(",
"[",
"'fileName'",
"=>",
"$",
"className",
".",
"'.php'",
",",
"'classes'",
"=>",
"[",
"$",
"class",
"]",
",",
"]",
")",
";",
"$",
"contents",
"=",
"$",
"file",
"->",
"generate",
"(",
")",
";",
"$",
"relativePath",
"=",
"$",
"destinationDir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
"->",
"getFilename",
"(",
")",
";",
"if",
"(",
"$",
"filesystem",
"->",
"has",
"(",
"$",
"relativePath",
")",
")",
"{",
"throw",
"new",
"CliException",
"(",
"sprintf",
"(",
"'Could not generate migration. File already exists: %s'",
",",
"$",
"relativePath",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"filesystem",
"->",
"write",
"(",
"$",
"relativePath",
",",
"$",
"contents",
")",
";",
"return",
"$",
"result",
"?",
"$",
"relativePath",
":",
"false",
";",
"}"
] |
Function writeClass.
@param ClassGenerator $class
@param Filesystem $filesystem
@param $destinationDir
@return string|false
@throws CliException
|
[
"Function",
"writeClass",
"."
] |
2ecbc7179c5800c9075fd93204ef25da375536ed
|
https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/CommandBus/Repository/CreateHandler.php#L160-L180
|
15,123
|
Srokap/code_review
|
classes/CodeReview/PhpFileParser.php
|
PhpFileParser.validateFileContents
|
protected function validateFileContents() {
if (!$this->fileName) {
throw new \LogicException("Missing file's path. Looks like severe internal error.");
}
$this->validateFilePath($this->fileName);
if (!$this->sha1hash) {
throw new \LogicException("Missing file's SHA1 hash. Looks like severe internal error.");
}
if ($this->sha1hash !== sha1_file($this->fileName)) {
throw new IOException("The file on disk has changed and this " . get_class($this) . " class instance is no longer valid for use. Please create fresh instance.");
}
return true;
}
|
php
|
protected function validateFileContents() {
if (!$this->fileName) {
throw new \LogicException("Missing file's path. Looks like severe internal error.");
}
$this->validateFilePath($this->fileName);
if (!$this->sha1hash) {
throw new \LogicException("Missing file's SHA1 hash. Looks like severe internal error.");
}
if ($this->sha1hash !== sha1_file($this->fileName)) {
throw new IOException("The file on disk has changed and this " . get_class($this) . " class instance is no longer valid for use. Please create fresh instance.");
}
return true;
}
|
[
"protected",
"function",
"validateFileContents",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"fileName",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"\"Missing file's path. Looks like severe internal error.\"",
")",
";",
"}",
"$",
"this",
"->",
"validateFilePath",
"(",
"$",
"this",
"->",
"fileName",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"sha1hash",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"\"Missing file's SHA1 hash. Looks like severe internal error.\"",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"sha1hash",
"!==",
"sha1_file",
"(",
"$",
"this",
"->",
"fileName",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"The file on disk has changed and this \"",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"\" class instance is no longer valid for use. Please create fresh instance.\"",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Uses SHA1 hash to determine if file contents has changed since analysis.
@return bool
@throws \CodeReview\IOException
@throws LogicException
|
[
"Uses",
"SHA1",
"hash",
"to",
"determine",
"if",
"file",
"contents",
"has",
"changed",
"since",
"analysis",
"."
] |
c79c619f99279cf15713b118ae19b0ef017db362
|
https://github.com/Srokap/code_review/blob/c79c619f99279cf15713b118ae19b0ef017db362/classes/CodeReview/PhpFileParser.php#L74-L86
|
15,124
|
Srokap/code_review
|
classes/CodeReview/PhpFileParser.php
|
PhpFileParser.validateFilePath
|
protected function validateFilePath($fileName) {
if (!file_exists($fileName)) {
throw new IOException("File $fileName does not exists");
}
if (!is_file($fileName)) {
throw new IOException("$fileName must be a file");
}
if (!is_readable($fileName)) {
throw new IOException("File $fileName is not readable");
}
return true;
}
|
php
|
protected function validateFilePath($fileName) {
if (!file_exists($fileName)) {
throw new IOException("File $fileName does not exists");
}
if (!is_file($fileName)) {
throw new IOException("$fileName must be a file");
}
if (!is_readable($fileName)) {
throw new IOException("File $fileName is not readable");
}
return true;
}
|
[
"protected",
"function",
"validateFilePath",
"(",
"$",
"fileName",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fileName",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"File $fileName does not exists\"",
")",
";",
"}",
"if",
"(",
"!",
"is_file",
"(",
"$",
"fileName",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"$fileName must be a file\"",
")",
";",
"}",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"fileName",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"File $fileName is not readable\"",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Checks if file exists and is readable.
@param $fileName
@return bool
@throws \CodeReview\IOException
|
[
"Checks",
"if",
"file",
"exists",
"and",
"is",
"readable",
"."
] |
c79c619f99279cf15713b118ae19b0ef017db362
|
https://github.com/Srokap/code_review/blob/c79c619f99279cf15713b118ae19b0ef017db362/classes/CodeReview/PhpFileParser.php#L95-L106
|
15,125
|
Srokap/code_review
|
classes/CodeReview/PhpFileParser.php
|
PhpFileParser.computeNestingParentTokens
|
private function computeNestingParentTokens($debug = false) {
$nesting = 0;
$parents = array();
$lastParent = null;
foreach ($this->tokens as $key => $token) {
if (is_array($token)) {
//add info about parent to array
$parent = $parents ? $parents[count($parents)-1] : null;
$this->tokens[$key][3] = $parent;
$this->tokens[$key][4] = $nesting;
//is current token possible parent in current level?
if ($this->isEqualToAnyToken(array(T_CLASS, T_INTERFACE, T_FUNCTION), $key)) {
$lastParent = $key + 2;
} elseif ($this->isEqualToAnyToken(array(T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES), $key)) {
$nesting++;
array_push($parents, '');//just a placeholder
if ($debug) {
echo "$nesting\{\$\n";
}
}
} else {
if ($token == '{') {
$nesting++;
if ($debug) {
echo "$nesting{\n";
}
array_push($parents, $lastParent);
} elseif ($token == '}') {
if ($debug) {
echo "$nesting}\n";
}
$nesting--;
array_pop($parents);
}
}
}
}
|
php
|
private function computeNestingParentTokens($debug = false) {
$nesting = 0;
$parents = array();
$lastParent = null;
foreach ($this->tokens as $key => $token) {
if (is_array($token)) {
//add info about parent to array
$parent = $parents ? $parents[count($parents)-1] : null;
$this->tokens[$key][3] = $parent;
$this->tokens[$key][4] = $nesting;
//is current token possible parent in current level?
if ($this->isEqualToAnyToken(array(T_CLASS, T_INTERFACE, T_FUNCTION), $key)) {
$lastParent = $key + 2;
} elseif ($this->isEqualToAnyToken(array(T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES), $key)) {
$nesting++;
array_push($parents, '');//just a placeholder
if ($debug) {
echo "$nesting\{\$\n";
}
}
} else {
if ($token == '{') {
$nesting++;
if ($debug) {
echo "$nesting{\n";
}
array_push($parents, $lastParent);
} elseif ($token == '}') {
if ($debug) {
echo "$nesting}\n";
}
$nesting--;
array_pop($parents);
}
}
}
}
|
[
"private",
"function",
"computeNestingParentTokens",
"(",
"$",
"debug",
"=",
"false",
")",
"{",
"$",
"nesting",
"=",
"0",
";",
"$",
"parents",
"=",
"array",
"(",
")",
";",
"$",
"lastParent",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"tokens",
"as",
"$",
"key",
"=>",
"$",
"token",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"token",
")",
")",
"{",
"//add info about parent to array",
"$",
"parent",
"=",
"$",
"parents",
"?",
"$",
"parents",
"[",
"count",
"(",
"$",
"parents",
")",
"-",
"1",
"]",
":",
"null",
";",
"$",
"this",
"->",
"tokens",
"[",
"$",
"key",
"]",
"[",
"3",
"]",
"=",
"$",
"parent",
";",
"$",
"this",
"->",
"tokens",
"[",
"$",
"key",
"]",
"[",
"4",
"]",
"=",
"$",
"nesting",
";",
"//is current token possible parent in current level?",
"if",
"(",
"$",
"this",
"->",
"isEqualToAnyToken",
"(",
"array",
"(",
"T_CLASS",
",",
"T_INTERFACE",
",",
"T_FUNCTION",
")",
",",
"$",
"key",
")",
")",
"{",
"$",
"lastParent",
"=",
"$",
"key",
"+",
"2",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isEqualToAnyToken",
"(",
"array",
"(",
"T_CURLY_OPEN",
",",
"T_DOLLAR_OPEN_CURLY_BRACES",
")",
",",
"$",
"key",
")",
")",
"{",
"$",
"nesting",
"++",
";",
"array_push",
"(",
"$",
"parents",
",",
"''",
")",
";",
"//just a placeholder",
"if",
"(",
"$",
"debug",
")",
"{",
"echo",
"\"$nesting\\{\\$\\n\"",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"token",
"==",
"'{'",
")",
"{",
"$",
"nesting",
"++",
";",
"if",
"(",
"$",
"debug",
")",
"{",
"echo",
"\"$nesting{\\n\"",
";",
"}",
"array_push",
"(",
"$",
"parents",
",",
"$",
"lastParent",
")",
";",
"}",
"elseif",
"(",
"$",
"token",
"==",
"'}'",
")",
"{",
"if",
"(",
"$",
"debug",
")",
"{",
"echo",
"\"$nesting}\\n\"",
";",
"}",
"$",
"nesting",
"--",
";",
"array_pop",
"(",
"$",
"parents",
")",
";",
"}",
"}",
"}",
"}"
] |
Compute parents of the tokens to easily determine containing methods and classes.
@param bool $debug
|
[
"Compute",
"parents",
"of",
"the",
"tokens",
"to",
"easily",
"determine",
"containing",
"methods",
"and",
"classes",
"."
] |
c79c619f99279cf15713b118ae19b0ef017db362
|
https://github.com/Srokap/code_review/blob/c79c619f99279cf15713b118ae19b0ef017db362/classes/CodeReview/PhpFileParser.php#L113-L150
|
15,126
|
shawnsandy/ui-pages
|
src/Classes/Pages.php
|
Pages.getView
|
public function getView($name, $data = [])
{
$view = 'missing-page';
if (view()->exists('page::' . $name)) {
$view = $name;
}
return view('page::' . $view, $data);
}
|
php
|
public function getView($name, $data = [])
{
$view = 'missing-page';
if (view()->exists('page::' . $name)) {
$view = $name;
}
return view('page::' . $view, $data);
}
|
[
"public",
"function",
"getView",
"(",
"$",
"name",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"view",
"=",
"'missing-page'",
";",
"if",
"(",
"view",
"(",
")",
"->",
"exists",
"(",
"'page::'",
".",
"$",
"name",
")",
")",
"{",
"$",
"view",
"=",
"$",
"name",
";",
"}",
"return",
"view",
"(",
"'page::'",
".",
"$",
"view",
",",
"$",
"data",
")",
";",
"}"
] |
Search and Load the view or fallbacks to specific view
@param string $name The name of the view
@param array $data View data
@return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
[
"Search",
"and",
"Load",
"the",
"view",
"or",
"fallbacks",
"to",
"specific",
"view"
] |
11584c12fa3e2b9a5c513f4ec9e2eaf78c206ca8
|
https://github.com/shawnsandy/ui-pages/blob/11584c12fa3e2b9a5c513f4ec9e2eaf78c206ca8/src/Classes/Pages.php#L20-L29
|
15,127
|
vsilva472/phpcpf
|
src/CPF.php
|
CPF.validate
|
public function validate($cpf)
{
$raw_cpf = $cpf;
$cpf = $this->clean($cpf);
$has_mask = preg_match("/^[0-9]{3}\.[0-9]{3}\.[0-9]{3}\-[0-9]{2}$/", $raw_cpf);
if (!$has_mask && !is_numeric($raw_cpf)) {
return false;
}
if (!$this->isLengthValid($cpf)) {
return false;
}
elseif ($this->isDummyValue($cpf)) {
return false;
}
return $this->validateDigits($cpf);
}
|
php
|
public function validate($cpf)
{
$raw_cpf = $cpf;
$cpf = $this->clean($cpf);
$has_mask = preg_match("/^[0-9]{3}\.[0-9]{3}\.[0-9]{3}\-[0-9]{2}$/", $raw_cpf);
if (!$has_mask && !is_numeric($raw_cpf)) {
return false;
}
if (!$this->isLengthValid($cpf)) {
return false;
}
elseif ($this->isDummyValue($cpf)) {
return false;
}
return $this->validateDigits($cpf);
}
|
[
"public",
"function",
"validate",
"(",
"$",
"cpf",
")",
"{",
"$",
"raw_cpf",
"=",
"$",
"cpf",
";",
"$",
"cpf",
"=",
"$",
"this",
"->",
"clean",
"(",
"$",
"cpf",
")",
";",
"$",
"has_mask",
"=",
"preg_match",
"(",
"\"/^[0-9]{3}\\.[0-9]{3}\\.[0-9]{3}\\-[0-9]{2}$/\"",
",",
"$",
"raw_cpf",
")",
";",
"if",
"(",
"!",
"$",
"has_mask",
"&&",
"!",
"is_numeric",
"(",
"$",
"raw_cpf",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isLengthValid",
"(",
"$",
"cpf",
")",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isDummyValue",
"(",
"$",
"cpf",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"validateDigits",
"(",
"$",
"cpf",
")",
";",
"}"
] |
Validate a given Brazilian CPF number
@param $cpf
@return bool
|
[
"Validate",
"a",
"given",
"Brazilian",
"CPF",
"number"
] |
3c37fc1af43de31ed93acc5a9538f349e361af43
|
https://github.com/vsilva472/phpcpf/blob/3c37fc1af43de31ed93acc5a9538f349e361af43/src/CPF.php#L26-L45
|
15,128
|
vsilva472/phpcpf
|
src/CPF.php
|
CPF.isDummyValue
|
public function isDummyValue($cpf)
{
return (
$cpf == '00000000000' ||
$cpf == '11111111111' ||
$cpf == '22222222222' ||
$cpf == '33333333333' ||
$cpf == '44444444444' ||
$cpf == '55555555555' ||
$cpf == '66666666666' ||
$cpf == '77777777777' ||
$cpf == '88888888888' ||
$cpf == '99999999999'
);
}
|
php
|
public function isDummyValue($cpf)
{
return (
$cpf == '00000000000' ||
$cpf == '11111111111' ||
$cpf == '22222222222' ||
$cpf == '33333333333' ||
$cpf == '44444444444' ||
$cpf == '55555555555' ||
$cpf == '66666666666' ||
$cpf == '77777777777' ||
$cpf == '88888888888' ||
$cpf == '99999999999'
);
}
|
[
"public",
"function",
"isDummyValue",
"(",
"$",
"cpf",
")",
"{",
"return",
"(",
"$",
"cpf",
"==",
"'00000000000'",
"||",
"$",
"cpf",
"==",
"'11111111111'",
"||",
"$",
"cpf",
"==",
"'22222222222'",
"||",
"$",
"cpf",
"==",
"'33333333333'",
"||",
"$",
"cpf",
"==",
"'44444444444'",
"||",
"$",
"cpf",
"==",
"'55555555555'",
"||",
"$",
"cpf",
"==",
"'66666666666'",
"||",
"$",
"cpf",
"==",
"'77777777777'",
"||",
"$",
"cpf",
"==",
"'88888888888'",
"||",
"$",
"cpf",
"==",
"'99999999999'",
")",
";",
"}"
] |
Check if a given CPF value is a dummy sequence
@param $cpf
@return bool
|
[
"Check",
"if",
"a",
"given",
"CPF",
"value",
"is",
"a",
"dummy",
"sequence"
] |
3c37fc1af43de31ed93acc5a9538f349e361af43
|
https://github.com/vsilva472/phpcpf/blob/3c37fc1af43de31ed93acc5a9538f349e361af43/src/CPF.php#L76-L90
|
15,129
|
FrenchFrogs/framework
|
src/Form/Form/Element.php
|
Element.addElement
|
public function addElement(\FrenchFrogs\Form\Element\Element $element, FrenchFrogs\Renderer\Renderer $renderer = null)
{
// Join element to the form
$element->setForm($this);
$this->elements[$element->getName()] = $element;
return $this;
}
|
php
|
public function addElement(\FrenchFrogs\Form\Element\Element $element, FrenchFrogs\Renderer\Renderer $renderer = null)
{
// Join element to the form
$element->setForm($this);
$this->elements[$element->getName()] = $element;
return $this;
}
|
[
"public",
"function",
"addElement",
"(",
"\\",
"FrenchFrogs",
"\\",
"Form",
"\\",
"Element",
"\\",
"Element",
"$",
"element",
",",
"FrenchFrogs",
"\\",
"Renderer",
"\\",
"Renderer",
"$",
"renderer",
"=",
"null",
")",
"{",
"// Join element to the form",
"$",
"element",
"->",
"setForm",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"elements",
"[",
"$",
"element",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"element",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a single element to the elements container
@param \FrenchFrogs\Form\Element\Element $element
@return $this
|
[
"Add",
"a",
"single",
"element",
"to",
"the",
"elements",
"container"
] |
a4838c698a5600437e87dac6d35ba8ebe32c4395
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Form/Element.php#L32-L40
|
15,130
|
FrenchFrogs/framework
|
src/Form/Form/Element.php
|
Element.addDateRange
|
public function addDateRange($name, $label = '', $from = '', $to = '', $is_mandatory = true)
{
$e = new \FrenchFrogs\Form\Element\DateRange($name, $label, $from, $to);
$this->addElement($e);
if ($is_mandatory) {
$e->addRule('required');
} else {
$e->addFilter('nullable');
}
return $e;
}
|
php
|
public function addDateRange($name, $label = '', $from = '', $to = '', $is_mandatory = true)
{
$e = new \FrenchFrogs\Form\Element\DateRange($name, $label, $from, $to);
$this->addElement($e);
if ($is_mandatory) {
$e->addRule('required');
} else {
$e->addFilter('nullable');
}
return $e;
}
|
[
"public",
"function",
"addDateRange",
"(",
"$",
"name",
",",
"$",
"label",
"=",
"''",
",",
"$",
"from",
"=",
"''",
",",
"$",
"to",
"=",
"''",
",",
"$",
"is_mandatory",
"=",
"true",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"FrenchFrogs",
"\\",
"Form",
"\\",
"Element",
"\\",
"DateRange",
"(",
"$",
"name",
",",
"$",
"label",
",",
"$",
"from",
",",
"$",
"to",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"$",
"e",
")",
";",
"if",
"(",
"$",
"is_mandatory",
")",
"{",
"$",
"e",
"->",
"addRule",
"(",
"'required'",
")",
";",
"}",
"else",
"{",
"$",
"e",
"->",
"addFilter",
"(",
"'nullable'",
")",
";",
"}",
"return",
"$",
"e",
";",
"}"
] |
Add 2 input for a date range element
@param $name
@param string $label
@param string $from
@param string $to
@param bool $is_mandatory
@return FrenchFrogs\Form\Element\DateRange
|
[
"Add",
"2",
"input",
"for",
"a",
"date",
"range",
"element"
] |
a4838c698a5600437e87dac6d35ba8ebe32c4395
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Form/Element.php#L259-L271
|
15,131
|
FrenchFrogs/framework
|
src/Form/Form/Element.php
|
Element.addTextarea
|
public function addTextarea($name, $label = '', $is_mandatory = true )
{
$e = new \FrenchFrogs\Form\Element\Textarea($name, $label);
$this->addElement($e);
if ($is_mandatory) {
$e->addRule('required');
} else {
$e->addFilter('nullable');
}
return $e;
}
|
php
|
public function addTextarea($name, $label = '', $is_mandatory = true )
{
$e = new \FrenchFrogs\Form\Element\Textarea($name, $label);
$this->addElement($e);
if ($is_mandatory) {
$e->addRule('required');
} else {
$e->addFilter('nullable');
}
return $e;
}
|
[
"public",
"function",
"addTextarea",
"(",
"$",
"name",
",",
"$",
"label",
"=",
"''",
",",
"$",
"is_mandatory",
"=",
"true",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"FrenchFrogs",
"\\",
"Form",
"\\",
"Element",
"\\",
"Textarea",
"(",
"$",
"name",
",",
"$",
"label",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"$",
"e",
")",
";",
"if",
"(",
"$",
"is_mandatory",
")",
"{",
"$",
"e",
"->",
"addRule",
"(",
"'required'",
")",
";",
"}",
"else",
"{",
"$",
"e",
"->",
"addFilter",
"(",
"'nullable'",
")",
";",
"}",
"return",
"$",
"e",
";",
"}"
] |
Add textarea element
@param $name
@param string $label
@param array $attr
@return \FrenchFrogs\Form\Element\Textarea
|
[
"Add",
"textarea",
"element"
] |
a4838c698a5600437e87dac6d35ba8ebe32c4395
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Form/Element.php#L326-L338
|
15,132
|
FrenchFrogs/framework
|
src/Form/Form/Element.php
|
Element.addSubmit
|
public function addSubmit($name, $attr = [])
{
$e = new \FrenchFrogs\Form\Element\Submit($name, $attr);
$e->setValue($name);
$e->setOptionAsPrimary();
$this->addAction($e);
return $e;
}
|
php
|
public function addSubmit($name, $attr = [])
{
$e = new \FrenchFrogs\Form\Element\Submit($name, $attr);
$e->setValue($name);
$e->setOptionAsPrimary();
$this->addAction($e);
return $e;
}
|
[
"public",
"function",
"addSubmit",
"(",
"$",
"name",
",",
"$",
"attr",
"=",
"[",
"]",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"FrenchFrogs",
"\\",
"Form",
"\\",
"Element",
"\\",
"Submit",
"(",
"$",
"name",
",",
"$",
"attr",
")",
";",
"$",
"e",
"->",
"setValue",
"(",
"$",
"name",
")",
";",
"$",
"e",
"->",
"setOptionAsPrimary",
"(",
")",
";",
"$",
"this",
"->",
"addAction",
"(",
"$",
"e",
")",
";",
"return",
"$",
"e",
";",
"}"
] |
Add action button
@param $name
@param array $attr
@return \FrenchFrogs\Form\Element\Submit
|
[
"Add",
"action",
"button"
] |
a4838c698a5600437e87dac6d35ba8ebe32c4395
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Form/Element.php#L347-L354
|
15,133
|
FrenchFrogs/framework
|
src/Form/Form/Element.php
|
Element.addCheckbox
|
public function addCheckbox($name, $label = '', $multi = [], $attr = [] )
{
$e = new \FrenchFrogs\Form\Element\Checkbox($name, $label, $multi, $attr);
$this->addElement($e);
return $e;
}
|
php
|
public function addCheckbox($name, $label = '', $multi = [], $attr = [] )
{
$e = new \FrenchFrogs\Form\Element\Checkbox($name, $label, $multi, $attr);
$this->addElement($e);
return $e;
}
|
[
"public",
"function",
"addCheckbox",
"(",
"$",
"name",
",",
"$",
"label",
"=",
"''",
",",
"$",
"multi",
"=",
"[",
"]",
",",
"$",
"attr",
"=",
"[",
"]",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"FrenchFrogs",
"\\",
"Form",
"\\",
"Element",
"\\",
"Checkbox",
"(",
"$",
"name",
",",
"$",
"label",
",",
"$",
"multi",
",",
"$",
"attr",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"$",
"e",
")",
";",
"return",
"$",
"e",
";",
"}"
] |
Add input checkbox element
@param $name
@param string $label
@param array $attr
@return \FrenchFrogs\Form\Element\Checkbox
|
[
"Add",
"input",
"checkbox",
"element"
] |
a4838c698a5600437e87dac6d35ba8ebe32c4395
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Form/Element.php#L365-L370
|
15,134
|
FrenchFrogs/framework
|
src/Form/Form/Element.php
|
Element.addBoolean
|
public function addBoolean($name, $label = '', $attr = [] )
{
$e = new \FrenchFrogs\Form\Element\Boolean($name, $label, $attr);
$this->addElement($e);
return $e;
}
|
php
|
public function addBoolean($name, $label = '', $attr = [] )
{
$e = new \FrenchFrogs\Form\Element\Boolean($name, $label, $attr);
$this->addElement($e);
return $e;
}
|
[
"public",
"function",
"addBoolean",
"(",
"$",
"name",
",",
"$",
"label",
"=",
"''",
",",
"$",
"attr",
"=",
"[",
"]",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"FrenchFrogs",
"\\",
"Form",
"\\",
"Element",
"\\",
"Boolean",
"(",
"$",
"name",
",",
"$",
"label",
",",
"$",
"attr",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"$",
"e",
")",
";",
"return",
"$",
"e",
";",
"}"
] |
Add Boolean Element
@param $name
@param string $label
@param array $attr
@return \FrenchFrogs\Form\Element\Boolean
|
[
"Add",
"Boolean",
"Element"
] |
a4838c698a5600437e87dac6d35ba8ebe32c4395
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Form/Element.php#L381-L386
|
15,135
|
FrenchFrogs/framework
|
src/Form/Form/Element.php
|
Element.addButton
|
public function addButton($name, $label, $attr = [] )
{
$e = new \FrenchFrogs\Form\Element\Button($name, $label, $attr);
$this->addElement($e);
return $e;
}
|
php
|
public function addButton($name, $label, $attr = [] )
{
$e = new \FrenchFrogs\Form\Element\Button($name, $label, $attr);
$this->addElement($e);
return $e;
}
|
[
"public",
"function",
"addButton",
"(",
"$",
"name",
",",
"$",
"label",
",",
"$",
"attr",
"=",
"[",
"]",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"FrenchFrogs",
"\\",
"Form",
"\\",
"Element",
"\\",
"Button",
"(",
"$",
"name",
",",
"$",
"label",
",",
"$",
"attr",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"$",
"e",
")",
";",
"return",
"$",
"e",
";",
"}"
] |
Add button element
@param $label
@param array $attr
@return \FrenchFrogs\Form\Element\Button
|
[
"Add",
"button",
"element"
] |
a4838c698a5600437e87dac6d35ba8ebe32c4395
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Form/Element.php#L560-L565
|
15,136
|
FrenchFrogs/framework
|
src/Form/Form/Element.php
|
Element.addTitle
|
public function addTitle($name, $attr = [])
{
$e = new \FrenchFrogs\Form\Element\Title($name, $attr);
$this->addElement($e);
return $e;
}
|
php
|
public function addTitle($name, $attr = [])
{
$e = new \FrenchFrogs\Form\Element\Title($name, $attr);
$this->addElement($e);
return $e;
}
|
[
"public",
"function",
"addTitle",
"(",
"$",
"name",
",",
"$",
"attr",
"=",
"[",
"]",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"FrenchFrogs",
"\\",
"Form",
"\\",
"Element",
"\\",
"Title",
"(",
"$",
"name",
",",
"$",
"attr",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"$",
"e",
")",
";",
"return",
"$",
"e",
";",
"}"
] |
Add a Title element
@param $name
@param array $attr
@return \FrenchFrogs\Form\Element\Title
|
[
"Add",
"a",
"Title",
"element"
] |
a4838c698a5600437e87dac6d35ba8ebe32c4395
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Form/Element.php#L590-L595
|
15,137
|
FrenchFrogs/framework
|
src/Form/Form/Element.php
|
Element.addContent
|
public function addContent($label, $value = '', $fullwidth = true)
{
$e = new \FrenchFrogs\Form\Element\Content($label, $value, $fullwidth);
$this->addElement($e);
return $e;
}
|
php
|
public function addContent($label, $value = '', $fullwidth = true)
{
$e = new \FrenchFrogs\Form\Element\Content($label, $value, $fullwidth);
$this->addElement($e);
return $e;
}
|
[
"public",
"function",
"addContent",
"(",
"$",
"label",
",",
"$",
"value",
"=",
"''",
",",
"$",
"fullwidth",
"=",
"true",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"FrenchFrogs",
"\\",
"Form",
"\\",
"Element",
"\\",
"Content",
"(",
"$",
"label",
",",
"$",
"value",
",",
"$",
"fullwidth",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"$",
"e",
")",
";",
"return",
"$",
"e",
";",
"}"
] |
Add format content
@param $label
@param string $content
@param array $attr
@return \FrenchFrogs\Form\Element\Content
|
[
"Add",
"format",
"content"
] |
a4838c698a5600437e87dac6d35ba8ebe32c4395
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Form/Element.php#L606-L611
|
15,138
|
FrenchFrogs/framework
|
src/Form/Form/Element.php
|
Element.addSelect
|
public function addSelect($name, $label, $multi = [], $is_mandatory = true)
{
$e = new \FrenchFrogs\Form\Element\Select($name, $label, $multi);
$this->addElement($e);
if ($is_mandatory) {
$e->addRule('required');
} else {
$e->addFilter('nullable');
}
return $e;
}
|
php
|
public function addSelect($name, $label, $multi = [], $is_mandatory = true)
{
$e = new \FrenchFrogs\Form\Element\Select($name, $label, $multi);
$this->addElement($e);
if ($is_mandatory) {
$e->addRule('required');
} else {
$e->addFilter('nullable');
}
return $e;
}
|
[
"public",
"function",
"addSelect",
"(",
"$",
"name",
",",
"$",
"label",
",",
"$",
"multi",
"=",
"[",
"]",
",",
"$",
"is_mandatory",
"=",
"true",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"FrenchFrogs",
"\\",
"Form",
"\\",
"Element",
"\\",
"Select",
"(",
"$",
"name",
",",
"$",
"label",
",",
"$",
"multi",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"$",
"e",
")",
";",
"if",
"(",
"$",
"is_mandatory",
")",
"{",
"$",
"e",
"->",
"addRule",
"(",
"'required'",
")",
";",
"}",
"else",
"{",
"$",
"e",
"->",
"addFilter",
"(",
"'nullable'",
")",
";",
"}",
"return",
"$",
"e",
";",
"}"
] |
Add select element
@param $name
@param $label
@param array $multi
@param array $attr
@return \FrenchFrogs\Form\Element\Select
|
[
"Add",
"select",
"element"
] |
a4838c698a5600437e87dac6d35ba8ebe32c4395
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Form/Element.php#L671-L683
|
15,139
|
FrenchFrogs/framework
|
src/Form/Form/Element.php
|
Element.addDataList
|
public function addDataList($name, $label, $options = [], $is_mandatory = true)
{
$e = new \FrenchFrogs\Form\Element\DataList($name, $label, $options);
$this->addElement($e);
if ($is_mandatory) {
$e->addRule('required');
} else {
$e->addFilter('nullable');
}
return $e;
}
|
php
|
public function addDataList($name, $label, $options = [], $is_mandatory = true)
{
$e = new \FrenchFrogs\Form\Element\DataList($name, $label, $options);
$this->addElement($e);
if ($is_mandatory) {
$e->addRule('required');
} else {
$e->addFilter('nullable');
}
return $e;
}
|
[
"public",
"function",
"addDataList",
"(",
"$",
"name",
",",
"$",
"label",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"is_mandatory",
"=",
"true",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"FrenchFrogs",
"\\",
"Form",
"\\",
"Element",
"\\",
"DataList",
"(",
"$",
"name",
",",
"$",
"label",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"$",
"e",
")",
";",
"if",
"(",
"$",
"is_mandatory",
")",
"{",
"$",
"e",
"->",
"addRule",
"(",
"'required'",
")",
";",
"}",
"else",
"{",
"$",
"e",
"->",
"addFilter",
"(",
"'nullable'",
")",
";",
"}",
"return",
"$",
"e",
";",
"}"
] |
Add list element
@param $name
@param $label
@param array $options
@param bool|true $is_mandatory
@return FrenchFrogs\Form\Element\DataList
|
[
"Add",
"list",
"element"
] |
a4838c698a5600437e87dac6d35ba8ebe32c4395
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Form/Element.php#L694-L706
|
15,140
|
FrenchFrogs/framework
|
src/Form/Form/Element.php
|
Element.addFile
|
public function addFile($name, $label = '', $is_mandatory = true)
{
$e = new \FrenchFrogs\Form\Element\File($name, $label);
$this->addElement($e);
if ($is_mandatory) {
$e->addRule('required');
} else {
$e->addFilter('nullable');
}
return $e;
}
|
php
|
public function addFile($name, $label = '', $is_mandatory = true)
{
$e = new \FrenchFrogs\Form\Element\File($name, $label);
$this->addElement($e);
if ($is_mandatory) {
$e->addRule('required');
} else {
$e->addFilter('nullable');
}
return $e;
}
|
[
"public",
"function",
"addFile",
"(",
"$",
"name",
",",
"$",
"label",
"=",
"''",
",",
"$",
"is_mandatory",
"=",
"true",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"FrenchFrogs",
"\\",
"Form",
"\\",
"Element",
"\\",
"File",
"(",
"$",
"name",
",",
"$",
"label",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"$",
"e",
")",
";",
"if",
"(",
"$",
"is_mandatory",
")",
"{",
"$",
"e",
"->",
"addRule",
"(",
"'required'",
")",
";",
"}",
"else",
"{",
"$",
"e",
"->",
"addFilter",
"(",
"'nullable'",
")",
";",
"}",
"return",
"$",
"e",
";",
"}"
] |
Add file element
@param $name
@param string $label
@param array $attr
@return \FrenchFrogs\Form\Element\File
|
[
"Add",
"file",
"element"
] |
a4838c698a5600437e87dac6d35ba8ebe32c4395
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Form/Form/Element.php#L717-L729
|
15,141
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Formatter.php
|
Formatter.getArgbHexString
|
public function getArgbHexString(Color $color)
{
$alpha = dechex(255 * $color->alpha);
return '#' . $alpha . $color->hex;
}
|
php
|
public function getArgbHexString(Color $color)
{
$alpha = dechex(255 * $color->alpha);
return '#' . $alpha . $color->hex;
}
|
[
"public",
"function",
"getArgbHexString",
"(",
"Color",
"$",
"color",
")",
"{",
"$",
"alpha",
"=",
"dechex",
"(",
"255",
"*",
"$",
"color",
"->",
"alpha",
")",
";",
"return",
"'#'",
".",
"$",
"alpha",
".",
"$",
"color",
"->",
"hex",
";",
"}"
] |
Given a Color object, returns a formatted argb hex string
@param object $color Color object
@return string
|
[
"Given",
"a",
"Color",
"object",
"returns",
"a",
"formatted",
"argb",
"hex",
"string"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Formatter.php#L34-L38
|
15,142
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Formatter.php
|
Formatter.getRgbaHexString
|
public function getRgbaHexString(Color $color)
{
$alpha = dechex(255 * $color->alpha);
return '#' . $color->hex . $alpha;
}
|
php
|
public function getRgbaHexString(Color $color)
{
$alpha = dechex(255 * $color->alpha);
return '#' . $color->hex . $alpha;
}
|
[
"public",
"function",
"getRgbaHexString",
"(",
"Color",
"$",
"color",
")",
"{",
"$",
"alpha",
"=",
"dechex",
"(",
"255",
"*",
"$",
"color",
"->",
"alpha",
")",
";",
"return",
"'#'",
".",
"$",
"color",
"->",
"hex",
".",
"$",
"alpha",
";",
"}"
] |
Given a Color object, returns a formatted rgba hex string
@param object $color Color object
@return string
|
[
"Given",
"a",
"Color",
"object",
"returns",
"a",
"formatted",
"rgba",
"hex",
"string"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Formatter.php#L46-L50
|
15,143
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Formatter.php
|
Formatter.getRgbaString
|
public function getRgbaString(Color $color)
{
return 'rgba('. $color->red . ', ' . $color->green . ', ' . $color->blue . ', ' . $color->alpha . ')';
}
|
php
|
public function getRgbaString(Color $color)
{
return 'rgba('. $color->red . ', ' . $color->green . ', ' . $color->blue . ', ' . $color->alpha . ')';
}
|
[
"public",
"function",
"getRgbaString",
"(",
"Color",
"$",
"color",
")",
"{",
"return",
"'rgba('",
".",
"$",
"color",
"->",
"red",
".",
"', '",
".",
"$",
"color",
"->",
"green",
".",
"', '",
".",
"$",
"color",
"->",
"blue",
".",
"', '",
".",
"$",
"color",
"->",
"alpha",
".",
"')'",
";",
"}"
] |
Given a Color object, returns a formatted rgba string
@param object $color Color object
@return string
|
[
"Given",
"a",
"Color",
"object",
"returns",
"a",
"formatted",
"rgba",
"string"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Formatter.php#L69-L72
|
15,144
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Formatter.php
|
Formatter.getHslString
|
public function getHslString(Color $color)
{
return 'hsl('. round($color->hue) . ', ' . round($color->saturation * 100) . '%, ' . round($color->lightness * 100) . '%)';
}
|
php
|
public function getHslString(Color $color)
{
return 'hsl('. round($color->hue) . ', ' . round($color->saturation * 100) . '%, ' . round($color->lightness * 100) . '%)';
}
|
[
"public",
"function",
"getHslString",
"(",
"Color",
"$",
"color",
")",
"{",
"return",
"'hsl('",
".",
"round",
"(",
"$",
"color",
"->",
"hue",
")",
".",
"', '",
".",
"round",
"(",
"$",
"color",
"->",
"saturation",
"*",
"100",
")",
".",
"'%, '",
".",
"round",
"(",
"$",
"color",
"->",
"lightness",
"*",
"100",
")",
".",
"'%)'",
";",
"}"
] |
Given a Color object, returns a formatted hsl string
@param object $color Color object
@return string
|
[
"Given",
"a",
"Color",
"object",
"returns",
"a",
"formatted",
"hsl",
"string"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Formatter.php#L80-L83
|
15,145
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Formatter.php
|
Formatter.getHslaString
|
public function getHslaString(Color $color)
{
return 'hsla('. round($color->hue) . ', ' . round($color->saturation * 100) . '%, ' . round($color->lightness * 100) . '%, ' . $color->alpha . ')';
}
|
php
|
public function getHslaString(Color $color)
{
return 'hsla('. round($color->hue) . ', ' . round($color->saturation * 100) . '%, ' . round($color->lightness * 100) . '%, ' . $color->alpha . ')';
}
|
[
"public",
"function",
"getHslaString",
"(",
"Color",
"$",
"color",
")",
"{",
"return",
"'hsla('",
".",
"round",
"(",
"$",
"color",
"->",
"hue",
")",
".",
"', '",
".",
"round",
"(",
"$",
"color",
"->",
"saturation",
"*",
"100",
")",
".",
"'%, '",
".",
"round",
"(",
"$",
"color",
"->",
"lightness",
"*",
"100",
")",
".",
"'%, '",
".",
"$",
"color",
"->",
"alpha",
".",
"')'",
";",
"}"
] |
Given a Color object, returns a formatted hsla string
@param object $color Color object
@return string
|
[
"Given",
"a",
"Color",
"object",
"returns",
"a",
"formatted",
"hsla",
"string"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Formatter.php#L91-L94
|
15,146
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Formatter.php
|
Formatter.load
|
public function load(Color $color, $value)
{
$value = strtolower(trim($value));
$format = $this->guess($value);
if (is_callable(__CLASS__ . '::' . $format)) {
$this->$format($color, $value);
}
return $color;
}
|
php
|
public function load(Color $color, $value)
{
$value = strtolower(trim($value));
$format = $this->guess($value);
if (is_callable(__CLASS__ . '::' . $format)) {
$this->$format($color, $value);
}
return $color;
}
|
[
"public",
"function",
"load",
"(",
"Color",
"$",
"color",
",",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"value",
")",
")",
";",
"$",
"format",
"=",
"$",
"this",
"->",
"guess",
"(",
"$",
"value",
")",
";",
"if",
"(",
"is_callable",
"(",
"__CLASS__",
".",
"'::'",
".",
"$",
"format",
")",
")",
"{",
"$",
"this",
"->",
"$",
"format",
"(",
"$",
"color",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"color",
";",
"}"
] |
Pass a var in subject param and this method
will attempt to parse it into a color object
and return it
@param object $color Color object
@param mixed $subject
@return object Color object
|
[
"Pass",
"a",
"var",
"in",
"subject",
"param",
"and",
"this",
"method",
"will",
"attempt",
"to",
"parse",
"it",
"into",
"a",
"color",
"object",
"and",
"return",
"it"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Formatter.php#L105-L116
|
15,147
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Formatter.php
|
Formatter.guess
|
private function guess($value)
{
if (is_string($value)) {
$len = strlen($value);
if (strpos($value, ' ') === false && strpos($value, ',') === false) {
if (substr($value, 0, 1) === '#' && ($len === 7 || $len === 4)) {
return 'loadHexString';
} elseif ($len === 6 || $len === 3) {
return 'loadHexString';
}
} elseif (substr($value, 0, 3) === 'rgb') {
return 'loadRgbString';
} elseif (substr($value, 0, 4) === 'rgba') {
return 'loadRgbString';
} elseif (substr($value, 0, 3) === 'hsl') {
return 'loadHslString';
} elseif (substr($value, 0, 4) === 'hsla') {
return 'loadHslString';
}
}
//Bad Input
return false;
}
|
php
|
private function guess($value)
{
if (is_string($value)) {
$len = strlen($value);
if (strpos($value, ' ') === false && strpos($value, ',') === false) {
if (substr($value, 0, 1) === '#' && ($len === 7 || $len === 4)) {
return 'loadHexString';
} elseif ($len === 6 || $len === 3) {
return 'loadHexString';
}
} elseif (substr($value, 0, 3) === 'rgb') {
return 'loadRgbString';
} elseif (substr($value, 0, 4) === 'rgba') {
return 'loadRgbString';
} elseif (substr($value, 0, 3) === 'hsl') {
return 'loadHslString';
} elseif (substr($value, 0, 4) === 'hsla') {
return 'loadHslString';
}
}
//Bad Input
return false;
}
|
[
"private",
"function",
"guess",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"len",
"=",
"strlen",
"(",
"$",
"value",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"value",
",",
"' '",
")",
"===",
"false",
"&&",
"strpos",
"(",
"$",
"value",
",",
"','",
")",
"===",
"false",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"1",
")",
"===",
"'#'",
"&&",
"(",
"$",
"len",
"===",
"7",
"||",
"$",
"len",
"===",
"4",
")",
")",
"{",
"return",
"'loadHexString'",
";",
"}",
"elseif",
"(",
"$",
"len",
"===",
"6",
"||",
"$",
"len",
"===",
"3",
")",
"{",
"return",
"'loadHexString'",
";",
"}",
"}",
"elseif",
"(",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"3",
")",
"===",
"'rgb'",
")",
"{",
"return",
"'loadRgbString'",
";",
"}",
"elseif",
"(",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"4",
")",
"===",
"'rgba'",
")",
"{",
"return",
"'loadRgbString'",
";",
"}",
"elseif",
"(",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"3",
")",
"===",
"'hsl'",
")",
"{",
"return",
"'loadHslString'",
";",
"}",
"elseif",
"(",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"4",
")",
"===",
"'hsla'",
")",
"{",
"return",
"'loadHslString'",
";",
"}",
"}",
"//Bad Input",
"return",
"false",
";",
"}"
] |
Given a subject tries to discover the format,
then return the appropriate method name
@param mixed
@return string|boolean string if found, boolean false if not found
|
[
"Given",
"a",
"subject",
"tries",
"to",
"discover",
"the",
"format",
"then",
"return",
"the",
"appropriate",
"method",
"name"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Formatter.php#L125-L150
|
15,148
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Formatter.php
|
Formatter.loadHexString
|
public function loadHexString(Color $color, $subject)
{
$subject = trim($subject);
$subject = str_replace(array('#', ';', ' '), '', $subject);
if (strlen($subject) !== 3 && strlen($subject) !== 6) {
//Bad Input
return false;
} elseif (strlen($subject) === 3) {
$subject = $subject[0] . $subject[0] .
$subject[1] . $subject[1] .
$subject[2] . $subject[2] ;
}
$color->hex = $subject;
return $color;
}
|
php
|
public function loadHexString(Color $color, $subject)
{
$subject = trim($subject);
$subject = str_replace(array('#', ';', ' '), '', $subject);
if (strlen($subject) !== 3 && strlen($subject) !== 6) {
//Bad Input
return false;
} elseif (strlen($subject) === 3) {
$subject = $subject[0] . $subject[0] .
$subject[1] . $subject[1] .
$subject[2] . $subject[2] ;
}
$color->hex = $subject;
return $color;
}
|
[
"public",
"function",
"loadHexString",
"(",
"Color",
"$",
"color",
",",
"$",
"subject",
")",
"{",
"$",
"subject",
"=",
"trim",
"(",
"$",
"subject",
")",
";",
"$",
"subject",
"=",
"str_replace",
"(",
"array",
"(",
"'#'",
",",
"';'",
",",
"' '",
")",
",",
"''",
",",
"$",
"subject",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"subject",
")",
"!==",
"3",
"&&",
"strlen",
"(",
"$",
"subject",
")",
"!==",
"6",
")",
"{",
"//Bad Input",
"return",
"false",
";",
"}",
"elseif",
"(",
"strlen",
"(",
"$",
"subject",
")",
"===",
"3",
")",
"{",
"$",
"subject",
"=",
"$",
"subject",
"[",
"0",
"]",
".",
"$",
"subject",
"[",
"0",
"]",
".",
"$",
"subject",
"[",
"1",
"]",
".",
"$",
"subject",
"[",
"1",
"]",
".",
"$",
"subject",
"[",
"2",
"]",
".",
"$",
"subject",
"[",
"2",
"]",
";",
"}",
"$",
"color",
"->",
"hex",
"=",
"$",
"subject",
";",
"return",
"$",
"color",
";",
"}"
] |
Loads a color object from a hex string
@param object $color Color object
@param mixed
@return object Color object
|
[
"Loads",
"a",
"color",
"object",
"from",
"a",
"hex",
"string"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Formatter.php#L159-L177
|
15,149
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Formatter.php
|
Formatter.loadRgbString
|
public function loadRgbString(Color $color, $subject)
{
$subject = trim($subject);
$subject = str_replace(array('rgba', 'rgb', '(', ')', ';', ' '), '', $subject);
$rgbnum = explode(',', $subject);
if (count($rgbnum) !== 3 && count($rgbnum) !== 4) {
return false;
}
foreach ($rgbnum as &$val) {
$val = floatval(trim($val));
}
$rgb = array(
'red' => $rgbnum[0],
'green' => $rgbnum[1],
'blue' => $rgbnum[2]
);
if (isset($rgbnum[3])) {
$rgb['alpha'] = $rgbnum[3];
}
$color->bulkUpdate($rgb);
return $color;
}
|
php
|
public function loadRgbString(Color $color, $subject)
{
$subject = trim($subject);
$subject = str_replace(array('rgba', 'rgb', '(', ')', ';', ' '), '', $subject);
$rgbnum = explode(',', $subject);
if (count($rgbnum) !== 3 && count($rgbnum) !== 4) {
return false;
}
foreach ($rgbnum as &$val) {
$val = floatval(trim($val));
}
$rgb = array(
'red' => $rgbnum[0],
'green' => $rgbnum[1],
'blue' => $rgbnum[2]
);
if (isset($rgbnum[3])) {
$rgb['alpha'] = $rgbnum[3];
}
$color->bulkUpdate($rgb);
return $color;
}
|
[
"public",
"function",
"loadRgbString",
"(",
"Color",
"$",
"color",
",",
"$",
"subject",
")",
"{",
"$",
"subject",
"=",
"trim",
"(",
"$",
"subject",
")",
";",
"$",
"subject",
"=",
"str_replace",
"(",
"array",
"(",
"'rgba'",
",",
"'rgb'",
",",
"'('",
",",
"')'",
",",
"';'",
",",
"' '",
")",
",",
"''",
",",
"$",
"subject",
")",
";",
"$",
"rgbnum",
"=",
"explode",
"(",
"','",
",",
"$",
"subject",
")",
";",
"if",
"(",
"count",
"(",
"$",
"rgbnum",
")",
"!==",
"3",
"&&",
"count",
"(",
"$",
"rgbnum",
")",
"!==",
"4",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"rgbnum",
"as",
"&",
"$",
"val",
")",
"{",
"$",
"val",
"=",
"floatval",
"(",
"trim",
"(",
"$",
"val",
")",
")",
";",
"}",
"$",
"rgb",
"=",
"array",
"(",
"'red'",
"=>",
"$",
"rgbnum",
"[",
"0",
"]",
",",
"'green'",
"=>",
"$",
"rgbnum",
"[",
"1",
"]",
",",
"'blue'",
"=>",
"$",
"rgbnum",
"[",
"2",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"rgbnum",
"[",
"3",
"]",
")",
")",
"{",
"$",
"rgb",
"[",
"'alpha'",
"]",
"=",
"$",
"rgbnum",
"[",
"3",
"]",
";",
"}",
"$",
"color",
"->",
"bulkUpdate",
"(",
"$",
"rgb",
")",
";",
"return",
"$",
"color",
";",
"}"
] |
Loads a color object from an rgb or rgba string
@param object $color Color object
@param mixed
@return object Color object
|
[
"Loads",
"a",
"color",
"object",
"from",
"an",
"rgb",
"or",
"rgba",
"string"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Formatter.php#L186-L215
|
15,150
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Formatter.php
|
Formatter.loadHslString
|
public function loadHslString(Color $color, $subject)
{
$subject = trim($subject);
$subject = str_replace(array('hsla', 'hsl', '(', ')', ';', ' '), '', $subject);
$hslnum = explode(',', $subject);
if (count($hslnum) !== 3 && count($hslnum) !== 4) {
return false;
}
foreach ($hslnum as &$val) {
$val = floatval(trim($val));
}
$hsl = array(
'hue' => $hslnum[0],
'saturation' => $hslnum[1],
'lightness' => $hslnum[2]
);
if (isset($hslnum[3])) {
$hsl['alpha'] = $hslnum[3];
}
$color->bulkUpdate($hsl);
return $color;
}
|
php
|
public function loadHslString(Color $color, $subject)
{
$subject = trim($subject);
$subject = str_replace(array('hsla', 'hsl', '(', ')', ';', ' '), '', $subject);
$hslnum = explode(',', $subject);
if (count($hslnum) !== 3 && count($hslnum) !== 4) {
return false;
}
foreach ($hslnum as &$val) {
$val = floatval(trim($val));
}
$hsl = array(
'hue' => $hslnum[0],
'saturation' => $hslnum[1],
'lightness' => $hslnum[2]
);
if (isset($hslnum[3])) {
$hsl['alpha'] = $hslnum[3];
}
$color->bulkUpdate($hsl);
return $color;
}
|
[
"public",
"function",
"loadHslString",
"(",
"Color",
"$",
"color",
",",
"$",
"subject",
")",
"{",
"$",
"subject",
"=",
"trim",
"(",
"$",
"subject",
")",
";",
"$",
"subject",
"=",
"str_replace",
"(",
"array",
"(",
"'hsla'",
",",
"'hsl'",
",",
"'('",
",",
"')'",
",",
"';'",
",",
"' '",
")",
",",
"''",
",",
"$",
"subject",
")",
";",
"$",
"hslnum",
"=",
"explode",
"(",
"','",
",",
"$",
"subject",
")",
";",
"if",
"(",
"count",
"(",
"$",
"hslnum",
")",
"!==",
"3",
"&&",
"count",
"(",
"$",
"hslnum",
")",
"!==",
"4",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"hslnum",
"as",
"&",
"$",
"val",
")",
"{",
"$",
"val",
"=",
"floatval",
"(",
"trim",
"(",
"$",
"val",
")",
")",
";",
"}",
"$",
"hsl",
"=",
"array",
"(",
"'hue'",
"=>",
"$",
"hslnum",
"[",
"0",
"]",
",",
"'saturation'",
"=>",
"$",
"hslnum",
"[",
"1",
"]",
",",
"'lightness'",
"=>",
"$",
"hslnum",
"[",
"2",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"hslnum",
"[",
"3",
"]",
")",
")",
"{",
"$",
"hsl",
"[",
"'alpha'",
"]",
"=",
"$",
"hslnum",
"[",
"3",
"]",
";",
"}",
"$",
"color",
"->",
"bulkUpdate",
"(",
"$",
"hsl",
")",
";",
"return",
"$",
"color",
";",
"}"
] |
Loads a color object from a hsl or hsla string
@param object $color Color object
@param mixed
@return object Color object
|
[
"Loads",
"a",
"color",
"object",
"from",
"a",
"hsl",
"or",
"hsla",
"string"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Formatter.php#L224-L253
|
15,151
|
opis/storages
|
cache/Database.php
|
Database.has
|
public function has($key)
{
try {
$ttlColumn = $this->columns['ttl'];
return (bool) $this->db->from($this->table)
->where($this->columns['key'])->eq($this->prefix . $key)
->andWhere(function ($group) use ($ttlColumn) {
$group->where($ttlColumn)->eq(0)
->orWhere($ttlColumn)->gt(time());
})
->count();
} catch (PDOException $e) {
return false;
}
}
|
php
|
public function has($key)
{
try {
$ttlColumn = $this->columns['ttl'];
return (bool) $this->db->from($this->table)
->where($this->columns['key'])->eq($this->prefix . $key)
->andWhere(function ($group) use ($ttlColumn) {
$group->where($ttlColumn)->eq(0)
->orWhere($ttlColumn)->gt(time());
})
->count();
} catch (PDOException $e) {
return false;
}
}
|
[
"public",
"function",
"has",
"(",
"$",
"key",
")",
"{",
"try",
"{",
"$",
"ttlColumn",
"=",
"$",
"this",
"->",
"columns",
"[",
"'ttl'",
"]",
";",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"db",
"->",
"from",
"(",
"$",
"this",
"->",
"table",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"columns",
"[",
"'key'",
"]",
")",
"->",
"eq",
"(",
"$",
"this",
"->",
"prefix",
".",
"$",
"key",
")",
"->",
"andWhere",
"(",
"function",
"(",
"$",
"group",
")",
"use",
"(",
"$",
"ttlColumn",
")",
"{",
"$",
"group",
"->",
"where",
"(",
"$",
"ttlColumn",
")",
"->",
"eq",
"(",
"0",
")",
"->",
"orWhere",
"(",
"$",
"ttlColumn",
")",
"->",
"gt",
"(",
"time",
"(",
")",
")",
";",
"}",
")",
"->",
"count",
"(",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] |
Returns TRUE if the cache key exists and FALSE if not.
@param string $key Cache key
@return boolean
|
[
"Returns",
"TRUE",
"if",
"the",
"cache",
"key",
"exists",
"and",
"FALSE",
"if",
"not",
"."
] |
548dd631239c7cd75c04d17878b677e646540fde
|
https://github.com/opis/storages/blob/548dd631239c7cd75c04d17878b677e646540fde/cache/Database.php#L137-L152
|
15,152
|
opis/storages
|
cache/Database.php
|
Database.delete
|
public function delete($key)
{
try {
return (bool) $this->db->from($this->table)
->where($this->columns['key'])->eq($this->prefix . $key)
->delete();
} catch (PDOException $e) {
return false;
}
}
|
php
|
public function delete($key)
{
try {
return (bool) $this->db->from($this->table)
->where($this->columns['key'])->eq($this->prefix . $key)
->delete();
} catch (PDOException $e) {
return false;
}
}
|
[
"public",
"function",
"delete",
"(",
"$",
"key",
")",
"{",
"try",
"{",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"db",
"->",
"from",
"(",
"$",
"this",
"->",
"table",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"columns",
"[",
"'key'",
"]",
")",
"->",
"eq",
"(",
"$",
"this",
"->",
"prefix",
".",
"$",
"key",
")",
"->",
"delete",
"(",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] |
Delete a variable from the cache.
@param string $key Cache key
@return boolean
|
[
"Delete",
"a",
"variable",
"from",
"the",
"cache",
"."
] |
548dd631239c7cd75c04d17878b677e646540fde
|
https://github.com/opis/storages/blob/548dd631239c7cd75c04d17878b677e646540fde/cache/Database.php#L161-L170
|
15,153
|
opis/storages
|
cache/Database.php
|
Database.clear
|
public function clear()
{
try {
$this->db->from($this->table)->delete();
} catch (PDOException $e) {
return false;
}
return true;
}
|
php
|
public function clear()
{
try {
$this->db->from($this->table)->delete();
} catch (PDOException $e) {
return false;
}
return true;
}
|
[
"public",
"function",
"clear",
"(",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"db",
"->",
"from",
"(",
"$",
"this",
"->",
"table",
")",
"->",
"delete",
"(",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Clears the user cache.
@return boolean
|
[
"Clears",
"the",
"user",
"cache",
"."
] |
548dd631239c7cd75c04d17878b677e646540fde
|
https://github.com/opis/storages/blob/548dd631239c7cd75c04d17878b677e646540fde/cache/Database.php#L177-L186
|
15,154
|
Nayjest/Tree
|
src/ParentNodeTrait.php
|
ParentNodeTrait.children
|
public function children()
{
if ($this->collection === null) {
$this->initializeCollection($this->defaultChildren());
}
return $this->collection;
}
|
php
|
public function children()
{
if ($this->collection === null) {
$this->initializeCollection($this->defaultChildren());
}
return $this->collection;
}
|
[
"public",
"function",
"children",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"collection",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"initializeCollection",
"(",
"$",
"this",
"->",
"defaultChildren",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"collection",
";",
"}"
] |
Returns collection of child nodes.
@return \Nayjest\Collection\CollectionInterface|ChildNodeInterface[]
|
[
"Returns",
"collection",
"of",
"child",
"nodes",
"."
] |
e73da75f939e207b1c25065e9466c28300e7113c
|
https://github.com/Nayjest/Tree/blob/e73da75f939e207b1c25065e9466c28300e7113c/src/ParentNodeTrait.php#L56-L63
|
15,155
|
Nayjest/Tree
|
src/ParentNodeTrait.php
|
ParentNodeTrait.getChildrenRecursive
|
public function getChildrenRecursive()
{
$res = new ObjectCollection();
foreach ($this->children() as $child) {
$res->add($child);
if ($child instanceof ParentNodeInterface) {
$res->addMany($child->getChildrenRecursive());
}
}
return $res;
}
|
php
|
public function getChildrenRecursive()
{
$res = new ObjectCollection();
foreach ($this->children() as $child) {
$res->add($child);
if ($child instanceof ParentNodeInterface) {
$res->addMany($child->getChildrenRecursive());
}
}
return $res;
}
|
[
"public",
"function",
"getChildrenRecursive",
"(",
")",
"{",
"$",
"res",
"=",
"new",
"ObjectCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"children",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"res",
"->",
"add",
"(",
"$",
"child",
")",
";",
"if",
"(",
"$",
"child",
"instanceof",
"ParentNodeInterface",
")",
"{",
"$",
"res",
"->",
"addMany",
"(",
"$",
"child",
"->",
"getChildrenRecursive",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"res",
";",
"}"
] |
Returns collection containing all descendant nodes.
@return CollectionInterface|ObjectCollection|ChildNodeInterface[]
|
[
"Returns",
"collection",
"containing",
"all",
"descendant",
"nodes",
"."
] |
e73da75f939e207b1c25065e9466c28300e7113c
|
https://github.com/Nayjest/Tree/blob/e73da75f939e207b1c25065e9466c28300e7113c/src/ParentNodeTrait.php#L80-L91
|
15,156
|
acasademont/wurfl
|
WURFL/WURFLUtils.php
|
WURFL_WURFLUtils.isXhtmlRequester
|
public static function isXhtmlRequester($request)
{
if (!isset($request["accept"])) {
return false;
}
$accept = $request["accept"];
if (isset($accept)) {
if ((strpos($accept, WURFL_Constants::ACCEPT_HEADER_VND_WAP_XHTML_XML) !== 0)
|| (strpos($accept, WURFL_Constants::ACCEPT_HEADER_XHTML_XML) !== 0)
|| (strpos($accept, WURFL_Constants::ACCEPT_HEADER_TEXT_HTML) !== 0)) {
return true;
}
}
return false;
}
|
php
|
public static function isXhtmlRequester($request)
{
if (!isset($request["accept"])) {
return false;
}
$accept = $request["accept"];
if (isset($accept)) {
if ((strpos($accept, WURFL_Constants::ACCEPT_HEADER_VND_WAP_XHTML_XML) !== 0)
|| (strpos($accept, WURFL_Constants::ACCEPT_HEADER_XHTML_XML) !== 0)
|| (strpos($accept, WURFL_Constants::ACCEPT_HEADER_TEXT_HTML) !== 0)) {
return true;
}
}
return false;
}
|
[
"public",
"static",
"function",
"isXhtmlRequester",
"(",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"request",
"[",
"\"accept\"",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"accept",
"=",
"$",
"request",
"[",
"\"accept\"",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"accept",
")",
")",
"{",
"if",
"(",
"(",
"strpos",
"(",
"$",
"accept",
",",
"WURFL_Constants",
"::",
"ACCEPT_HEADER_VND_WAP_XHTML_XML",
")",
"!==",
"0",
")",
"||",
"(",
"strpos",
"(",
"$",
"accept",
",",
"WURFL_Constants",
"::",
"ACCEPT_HEADER_XHTML_XML",
")",
"!==",
"0",
")",
"||",
"(",
"strpos",
"(",
"$",
"accept",
",",
"WURFL_Constants",
"::",
"ACCEPT_HEADER_TEXT_HTML",
")",
"!==",
"0",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks if the requester device is xhtml enabled
@param array $request HTTP Request array (normally $_SERVER)
@return bool
|
[
"Checks",
"if",
"the",
"requester",
"device",
"is",
"xhtml",
"enabled"
] |
0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/WURFLUtils.php#L90-L106
|
15,157
|
activecollab/databasestructure
|
src/Builder/AssociationsBuilder.php
|
AssociationsBuilder.prepareHasOneConstraintStatement
|
public function prepareHasOneConstraintStatement(TypeInterface $type, HasOneAssociation $association)
{
$result = [];
$result[] = 'ALTER TABLE ' . $this->getConnection()->escapeTableName($type->getName());
$result[] = ' ADD CONSTRAINT ' . $this->getConnection()->escapeFieldName($association->getConstraintName());
$result[] = ' FOREIGN KEY (' . $this->getConnection()->escapeFieldName($association->getFieldName()) . ') REFERENCES ' . $this->getConnection()->escapeTableName($association->getTargetTypeName()) . '(`id`)';
if ($association->isRequired()) {
$result[] = ' ON UPDATE CASCADE ON DELETE CASCADE;';
} else {
$result[] = ' ON UPDATE SET NULL ON DELETE SET NULL;';
}
return implode("\n", $result);
}
|
php
|
public function prepareHasOneConstraintStatement(TypeInterface $type, HasOneAssociation $association)
{
$result = [];
$result[] = 'ALTER TABLE ' . $this->getConnection()->escapeTableName($type->getName());
$result[] = ' ADD CONSTRAINT ' . $this->getConnection()->escapeFieldName($association->getConstraintName());
$result[] = ' FOREIGN KEY (' . $this->getConnection()->escapeFieldName($association->getFieldName()) . ') REFERENCES ' . $this->getConnection()->escapeTableName($association->getTargetTypeName()) . '(`id`)';
if ($association->isRequired()) {
$result[] = ' ON UPDATE CASCADE ON DELETE CASCADE;';
} else {
$result[] = ' ON UPDATE SET NULL ON DELETE SET NULL;';
}
return implode("\n", $result);
}
|
[
"public",
"function",
"prepareHasOneConstraintStatement",
"(",
"TypeInterface",
"$",
"type",
",",
"HasOneAssociation",
"$",
"association",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"result",
"[",
"]",
"=",
"'ALTER TABLE '",
".",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"escapeTableName",
"(",
"$",
"type",
"->",
"getName",
"(",
")",
")",
";",
"$",
"result",
"[",
"]",
"=",
"' ADD CONSTRAINT '",
".",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"escapeFieldName",
"(",
"$",
"association",
"->",
"getConstraintName",
"(",
")",
")",
";",
"$",
"result",
"[",
"]",
"=",
"' FOREIGN KEY ('",
".",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"escapeFieldName",
"(",
"$",
"association",
"->",
"getFieldName",
"(",
")",
")",
".",
"') REFERENCES '",
".",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"escapeTableName",
"(",
"$",
"association",
"->",
"getTargetTypeName",
"(",
")",
")",
".",
"'(`id`)'",
";",
"if",
"(",
"$",
"association",
"->",
"isRequired",
"(",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"' ON UPDATE CASCADE ON DELETE CASCADE;'",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"]",
"=",
"' ON UPDATE SET NULL ON DELETE SET NULL;'",
";",
"}",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"result",
")",
";",
"}"
] |
Prepare has one constraint statement.
@param TypeInterface $type
@param HasOneAssociation $association
@return string
|
[
"Prepare",
"has",
"one",
"constraint",
"statement",
"."
] |
4b2353c4422186bcfce63b3212da3e70e63eb5df
|
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/AssociationsBuilder.php#L145-L160
|
15,158
|
activecollab/databasestructure
|
src/Builder/AssociationsBuilder.php
|
AssociationsBuilder.prepareHasAndBelongsToManyConstraintStatement
|
public function prepareHasAndBelongsToManyConstraintStatement($type_name, $connection_table, $constraint_name, $field_name)
{
$result = [];
$result[] = 'ALTER TABLE ' . $this->getConnection()->escapeTableName($connection_table);
$result[] = ' ADD CONSTRAINT ' . $this->getConnection()->escapeFieldName($constraint_name);
$result[] = ' FOREIGN KEY (' . $field_name . ') REFERENCES ' . $this->getConnection()->escapeTableName($type_name) . '(`id`)';
$result[] = ' ON UPDATE CASCADE ON DELETE CASCADE;';
return implode("\n", $result);
}
|
php
|
public function prepareHasAndBelongsToManyConstraintStatement($type_name, $connection_table, $constraint_name, $field_name)
{
$result = [];
$result[] = 'ALTER TABLE ' . $this->getConnection()->escapeTableName($connection_table);
$result[] = ' ADD CONSTRAINT ' . $this->getConnection()->escapeFieldName($constraint_name);
$result[] = ' FOREIGN KEY (' . $field_name . ') REFERENCES ' . $this->getConnection()->escapeTableName($type_name) . '(`id`)';
$result[] = ' ON UPDATE CASCADE ON DELETE CASCADE;';
return implode("\n", $result);
}
|
[
"public",
"function",
"prepareHasAndBelongsToManyConstraintStatement",
"(",
"$",
"type_name",
",",
"$",
"connection_table",
",",
"$",
"constraint_name",
",",
"$",
"field_name",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"result",
"[",
"]",
"=",
"'ALTER TABLE '",
".",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"escapeTableName",
"(",
"$",
"connection_table",
")",
";",
"$",
"result",
"[",
"]",
"=",
"' ADD CONSTRAINT '",
".",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"escapeFieldName",
"(",
"$",
"constraint_name",
")",
";",
"$",
"result",
"[",
"]",
"=",
"' FOREIGN KEY ('",
".",
"$",
"field_name",
".",
"') REFERENCES '",
".",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"escapeTableName",
"(",
"$",
"type_name",
")",
".",
"'(`id`)'",
";",
"$",
"result",
"[",
"]",
"=",
"' ON UPDATE CASCADE ON DELETE CASCADE;'",
";",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"result",
")",
";",
"}"
] |
Prepare has and belongs to many constraint statement.
@param string $type_name
@param string $connection_table
@param string $constraint_name
@param string $field_name
@return string
|
[
"Prepare",
"has",
"and",
"belongs",
"to",
"many",
"constraint",
"statement",
"."
] |
4b2353c4422186bcfce63b3212da3e70e63eb5df
|
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/AssociationsBuilder.php#L171-L181
|
15,159
|
seeren/http
|
src/Stream/Stream.php
|
Stream.setReadableWritable
|
private final function setReadableWritable(string $mode)
{
if (self::MODE_R === $mode) {
$this->meta["readable"] = true;
$this->meta["writable"] = false;
} else if (self::MODE_W === $mode
|| self::MODE_A === $mode
|| self::MODE_C === $mode
|| self::MODE_X === $mode) {
$this->meta["readable"] = false;
$this->meta["writable"] = true;
} else if (self::MODE_R_MORE === $mode
|| self::MODE_W_MORE === $mode
|| self::MODE_A_MORE === $mode
|| self::MODE_C_MORE === $mode
|| self::MODE_X_MORE === $mode) {
$this->meta["readable"] = true;
$this->meta["writable"] = true;
}
}
|
php
|
private final function setReadableWritable(string $mode)
{
if (self::MODE_R === $mode) {
$this->meta["readable"] = true;
$this->meta["writable"] = false;
} else if (self::MODE_W === $mode
|| self::MODE_A === $mode
|| self::MODE_C === $mode
|| self::MODE_X === $mode) {
$this->meta["readable"] = false;
$this->meta["writable"] = true;
} else if (self::MODE_R_MORE === $mode
|| self::MODE_W_MORE === $mode
|| self::MODE_A_MORE === $mode
|| self::MODE_C_MORE === $mode
|| self::MODE_X_MORE === $mode) {
$this->meta["readable"] = true;
$this->meta["writable"] = true;
}
}
|
[
"private",
"final",
"function",
"setReadableWritable",
"(",
"string",
"$",
"mode",
")",
"{",
"if",
"(",
"self",
"::",
"MODE_R",
"===",
"$",
"mode",
")",
"{",
"$",
"this",
"->",
"meta",
"[",
"\"readable\"",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"meta",
"[",
"\"writable\"",
"]",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"self",
"::",
"MODE_W",
"===",
"$",
"mode",
"||",
"self",
"::",
"MODE_A",
"===",
"$",
"mode",
"||",
"self",
"::",
"MODE_C",
"===",
"$",
"mode",
"||",
"self",
"::",
"MODE_X",
"===",
"$",
"mode",
")",
"{",
"$",
"this",
"->",
"meta",
"[",
"\"readable\"",
"]",
"=",
"false",
";",
"$",
"this",
"->",
"meta",
"[",
"\"writable\"",
"]",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"self",
"::",
"MODE_R_MORE",
"===",
"$",
"mode",
"||",
"self",
"::",
"MODE_W_MORE",
"===",
"$",
"mode",
"||",
"self",
"::",
"MODE_A_MORE",
"===",
"$",
"mode",
"||",
"self",
"::",
"MODE_C_MORE",
"===",
"$",
"mode",
"||",
"self",
"::",
"MODE_X_MORE",
"===",
"$",
"mode",
")",
"{",
"$",
"this",
"->",
"meta",
"[",
"\"readable\"",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"meta",
"[",
"\"writable\"",
"]",
"=",
"true",
";",
"}",
"}"
] |
Set stream readable and writable status
@param string $mode ressource mode
@return null
|
[
"Set",
"stream",
"readable",
"and",
"writable",
"status"
] |
b5e692e085c41fe25714d17ee90ba78eaf1923c4
|
https://github.com/seeren/http/blob/b5e692e085c41fe25714d17ee90ba78eaf1923c4/src/Stream/Stream.php#L76-L95
|
15,160
|
seeren/http
|
src/Stream/Stream.php
|
Stream.getMetadata
|
public final function getMetadata($key = null)
{
return isset($key)
? (array_key_exists($key, $this->meta) ? $this->meta[$key] : null)
: $this->meta;
}
|
php
|
public final function getMetadata($key = null)
{
return isset($key)
? (array_key_exists($key, $this->meta) ? $this->meta[$key] : null)
: $this->meta;
}
|
[
"public",
"final",
"function",
"getMetadata",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"return",
"isset",
"(",
"$",
"key",
")",
"?",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"meta",
")",
"?",
"$",
"this",
"->",
"meta",
"[",
"$",
"key",
"]",
":",
"null",
")",
":",
"$",
"this",
"->",
"meta",
";",
"}"
] |
Get stream metadata
@param string $key metadata key
@return array|mixed|null meta or value for key or null
|
[
"Get",
"stream",
"metadata"
] |
b5e692e085c41fe25714d17ee90ba78eaf1923c4
|
https://github.com/seeren/http/blob/b5e692e085c41fe25714d17ee90ba78eaf1923c4/src/Stream/Stream.php#L301-L306
|
15,161
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Toolkit.php
|
Toolkit.sync
|
public function sync(Color $firstcolor, Color $secondcolor)
{
foreach ($this->colorprops as $name) {
$firstcolor->$name = $secondcolor->$name;
}
return $firstcolor;
}
|
php
|
public function sync(Color $firstcolor, Color $secondcolor)
{
foreach ($this->colorprops as $name) {
$firstcolor->$name = $secondcolor->$name;
}
return $firstcolor;
}
|
[
"public",
"function",
"sync",
"(",
"Color",
"$",
"firstcolor",
",",
"Color",
"$",
"secondcolor",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"colorprops",
"as",
"$",
"name",
")",
"{",
"$",
"firstcolor",
"->",
"$",
"name",
"=",
"$",
"secondcolor",
"->",
"$",
"name",
";",
"}",
"return",
"$",
"firstcolor",
";",
"}"
] |
Sync first color with second color
The first color will receive all property values from the second color
@param object $firstcolor first Color object to receive the values
@param object $secondcolor second Color object to give the values
@return object self
|
[
"Sync",
"first",
"color",
"with",
"second",
"color"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Toolkit.php#L56-L63
|
15,162
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Toolkit.php
|
Toolkit.getCssGradient
|
public function getCssGradient(Color $color, $amount = null)
{
// Get gradient colors
if (self::isLight($color)) {
$lightColor = $color->hex;
$darkColor = self::darken($color->copy(), $amount)->hex;
} else {
$lightColor = self::lighten($color->copy(), $amount)->hex;
$darkColor = $color->hex;
}
/* fallback/image non-cover color */
$css = "background-color: #" . $color->hex . ";";
/* IE Browsers */
$css .= "filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#" . $lightColor . "', endColorstr='#" . $darkColor . "');";
/* Safari 4+, Chrome 1-9 */
$css .= "background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#" . $lightColor . "), to(#" . $darkColor . "));";
/* Safari 5.1+, Mobile Safari, Chrome 10+ */
$css .= "background-image: -webkit-linear-gradient(top, #" . $lightColor . ", #" . $darkColor . ");";
/* Firefox 3.6+ */
$css .= "background-image: -moz-linear-gradient(top, #" . $lightColor . ", #" . $darkColor . ");";
/* IE 10+ */
$css .= "background-image: -ms-linear-gradient(top, #" . $lightColor . ", #" . $darkColor . ");";
/* Opera 11.10+ */
$css .= "background-image: -o-linear-gradient(top, #" . $lightColor . ", #" . $darkColor . ");";
// Return our CSS
return $css;
}
|
php
|
public function getCssGradient(Color $color, $amount = null)
{
// Get gradient colors
if (self::isLight($color)) {
$lightColor = $color->hex;
$darkColor = self::darken($color->copy(), $amount)->hex;
} else {
$lightColor = self::lighten($color->copy(), $amount)->hex;
$darkColor = $color->hex;
}
/* fallback/image non-cover color */
$css = "background-color: #" . $color->hex . ";";
/* IE Browsers */
$css .= "filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#" . $lightColor . "', endColorstr='#" . $darkColor . "');";
/* Safari 4+, Chrome 1-9 */
$css .= "background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#" . $lightColor . "), to(#" . $darkColor . "));";
/* Safari 5.1+, Mobile Safari, Chrome 10+ */
$css .= "background-image: -webkit-linear-gradient(top, #" . $lightColor . ", #" . $darkColor . ");";
/* Firefox 3.6+ */
$css .= "background-image: -moz-linear-gradient(top, #" . $lightColor . ", #" . $darkColor . ");";
/* IE 10+ */
$css .= "background-image: -ms-linear-gradient(top, #" . $lightColor . ", #" . $darkColor . ");";
/* Opera 11.10+ */
$css .= "background-image: -o-linear-gradient(top, #" . $lightColor . ", #" . $darkColor . ");";
// Return our CSS
return $css;
}
|
[
"public",
"function",
"getCssGradient",
"(",
"Color",
"$",
"color",
",",
"$",
"amount",
"=",
"null",
")",
"{",
"// Get gradient colors",
"if",
"(",
"self",
"::",
"isLight",
"(",
"$",
"color",
")",
")",
"{",
"$",
"lightColor",
"=",
"$",
"color",
"->",
"hex",
";",
"$",
"darkColor",
"=",
"self",
"::",
"darken",
"(",
"$",
"color",
"->",
"copy",
"(",
")",
",",
"$",
"amount",
")",
"->",
"hex",
";",
"}",
"else",
"{",
"$",
"lightColor",
"=",
"self",
"::",
"lighten",
"(",
"$",
"color",
"->",
"copy",
"(",
")",
",",
"$",
"amount",
")",
"->",
"hex",
";",
"$",
"darkColor",
"=",
"$",
"color",
"->",
"hex",
";",
"}",
"/* fallback/image non-cover color */",
"$",
"css",
"=",
"\"background-color: #\"",
".",
"$",
"color",
"->",
"hex",
".",
"\";\"",
";",
"/* IE Browsers */",
"$",
"css",
".=",
"\"filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#\"",
".",
"$",
"lightColor",
".",
"\"', endColorstr='#\"",
".",
"$",
"darkColor",
".",
"\"');\"",
";",
"/* Safari 4+, Chrome 1-9 */",
"$",
"css",
".=",
"\"background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#\"",
".",
"$",
"lightColor",
".",
"\"), to(#\"",
".",
"$",
"darkColor",
".",
"\"));\"",
";",
"/* Safari 5.1+, Mobile Safari, Chrome 10+ */",
"$",
"css",
".=",
"\"background-image: -webkit-linear-gradient(top, #\"",
".",
"$",
"lightColor",
".",
"\", #\"",
".",
"$",
"darkColor",
".",
"\");\"",
";",
"/* Firefox 3.6+ */",
"$",
"css",
".=",
"\"background-image: -moz-linear-gradient(top, #\"",
".",
"$",
"lightColor",
".",
"\", #\"",
".",
"$",
"darkColor",
".",
"\");\"",
";",
"/* IE 10+ */",
"$",
"css",
".=",
"\"background-image: -ms-linear-gradient(top, #\"",
".",
"$",
"lightColor",
".",
"\", #\"",
".",
"$",
"darkColor",
".",
"\");\"",
";",
"/* Opera 11.10+ */",
"$",
"css",
".=",
"\"background-image: -o-linear-gradient(top, #\"",
".",
"$",
"lightColor",
".",
"\", #\"",
".",
"$",
"darkColor",
".",
"\");\"",
";",
"// Return our CSS",
"return",
"$",
"css",
";",
"}"
] |
Returns the cross browser CSS3 gradient
@param object $color Color object
@param integer $amount Optional: percentage amount to light/darken the gradient
@return string CSS3 gradient for chrome, safari, firefox, opera and IE10 with fallbacks
|
[
"Returns",
"the",
"cross",
"browser",
"CSS3",
"gradient"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Toolkit.php#L120-L154
|
15,163
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Toolkit.php
|
Toolkit.darken
|
public function darken(Color $color, $amount = null)
{
$current = $color->lightness;
$amount = ($amount === null) ? self::DEFAULT_ADJUST : $amount ;
$amount = intval($amount) / 100;
$new = $current - $amount;
$new = ($new < 0) ? 0 : $new;
$new = ($new > 1) ? 1 : $new;
$color->lightness = floatval($new);
return $color;
}
|
php
|
public function darken(Color $color, $amount = null)
{
$current = $color->lightness;
$amount = ($amount === null) ? self::DEFAULT_ADJUST : $amount ;
$amount = intval($amount) / 100;
$new = $current - $amount;
$new = ($new < 0) ? 0 : $new;
$new = ($new > 1) ? 1 : $new;
$color->lightness = floatval($new);
return $color;
}
|
[
"public",
"function",
"darken",
"(",
"Color",
"$",
"color",
",",
"$",
"amount",
"=",
"null",
")",
"{",
"$",
"current",
"=",
"$",
"color",
"->",
"lightness",
";",
"$",
"amount",
"=",
"(",
"$",
"amount",
"===",
"null",
")",
"?",
"self",
"::",
"DEFAULT_ADJUST",
":",
"$",
"amount",
";",
"$",
"amount",
"=",
"intval",
"(",
"$",
"amount",
")",
"/",
"100",
";",
"$",
"new",
"=",
"$",
"current",
"-",
"$",
"amount",
";",
"$",
"new",
"=",
"(",
"$",
"new",
"<",
"0",
")",
"?",
"0",
":",
"$",
"new",
";",
"$",
"new",
"=",
"(",
"$",
"new",
">",
"1",
")",
"?",
"1",
":",
"$",
"new",
";",
"$",
"color",
"->",
"lightness",
"=",
"floatval",
"(",
"$",
"new",
")",
";",
"return",
"$",
"color",
";",
"}"
] |
Darkens color by a percentage a given Color object
@param object $color Color object
@param integer
@return object Color
|
[
"Darkens",
"color",
"by",
"a",
"percentage",
"a",
"given",
"Color",
"object"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Toolkit.php#L163-L180
|
15,164
|
syhol/mrcolor
|
src/SyHolloway/MrColor/Extension/Toolkit.php
|
Toolkit.merge
|
public function merge(Color $color1, Color $color2, $percentage = 50)
{
return new Color(array(
'red' => $this->getMergedColorPart('red', $color1, $color2, $percentage),
'green' => $this->getMergedColorPart('green', $color1, $color2, $percentage),
'blue' => $this->getMergedColorPart('blue', $color1, $color2, $percentage)
));
}
|
php
|
public function merge(Color $color1, Color $color2, $percentage = 50)
{
return new Color(array(
'red' => $this->getMergedColorPart('red', $color1, $color2, $percentage),
'green' => $this->getMergedColorPart('green', $color1, $color2, $percentage),
'blue' => $this->getMergedColorPart('blue', $color1, $color2, $percentage)
));
}
|
[
"public",
"function",
"merge",
"(",
"Color",
"$",
"color1",
",",
"Color",
"$",
"color2",
",",
"$",
"percentage",
"=",
"50",
")",
"{",
"return",
"new",
"Color",
"(",
"array",
"(",
"'red'",
"=>",
"$",
"this",
"->",
"getMergedColorPart",
"(",
"'red'",
",",
"$",
"color1",
",",
"$",
"color2",
",",
"$",
"percentage",
")",
",",
"'green'",
"=>",
"$",
"this",
"->",
"getMergedColorPart",
"(",
"'green'",
",",
"$",
"color1",
",",
"$",
"color2",
",",
"$",
"percentage",
")",
",",
"'blue'",
"=>",
"$",
"this",
"->",
"getMergedColorPart",
"(",
"'blue'",
",",
"$",
"color1",
",",
"$",
"color2",
",",
"$",
"percentage",
")",
")",
")",
";",
"}"
] |
Merges the current color with a second color with an optional percentage
@param object $color1 Color object
@param object $color2 Color object
@param integer $percentage
@return object Color
|
[
"Merges",
"the",
"current",
"color",
"with",
"a",
"second",
"color",
"with",
"an",
"optional",
"percentage"
] |
b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d
|
https://github.com/syhol/mrcolor/blob/b0cfef8fa3dc52940ff6cb78d19a4fac9e02ef4d/src/SyHolloway/MrColor/Extension/Toolkit.php#L216-L223
|
15,165
|
dynamic/silverstripe-geocoder
|
src/AddressDataExtension.php
|
AddressDataExtension.getMapStyleJSON
|
public static function getMapStyleJSON()
{
$folders = [
'client/dist/js/',
'client/dist/javascript/',
'dist/js/',
'dist/javascript/',
'src/javascript/thirdparty',
'js/',
'javascript/',
];
$file = 'mapStyle.json';
foreach ($folders as $folder) {
if ($style = ThemeResourceLoader::inst()->findThemedResource(
"{$folder}{$file}",
SSViewer::get_themes()
)) {
return $style;
}
}
return false;
}
|
php
|
public static function getMapStyleJSON()
{
$folders = [
'client/dist/js/',
'client/dist/javascript/',
'dist/js/',
'dist/javascript/',
'src/javascript/thirdparty',
'js/',
'javascript/',
];
$file = 'mapStyle.json';
foreach ($folders as $folder) {
if ($style = ThemeResourceLoader::inst()->findThemedResource(
"{$folder}{$file}",
SSViewer::get_themes()
)) {
return $style;
}
}
return false;
}
|
[
"public",
"static",
"function",
"getMapStyleJSON",
"(",
")",
"{",
"$",
"folders",
"=",
"[",
"'client/dist/js/'",
",",
"'client/dist/javascript/'",
",",
"'dist/js/'",
",",
"'dist/javascript/'",
",",
"'src/javascript/thirdparty'",
",",
"'js/'",
",",
"'javascript/'",
",",
"]",
";",
"$",
"file",
"=",
"'mapStyle.json'",
";",
"foreach",
"(",
"$",
"folders",
"as",
"$",
"folder",
")",
"{",
"if",
"(",
"$",
"style",
"=",
"ThemeResourceLoader",
"::",
"inst",
"(",
")",
"->",
"findThemedResource",
"(",
"\"{$folder}{$file}\"",
",",
"SSViewer",
"::",
"get_themes",
"(",
")",
")",
")",
"{",
"return",
"$",
"style",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Gets the style of the map
@return string|null
|
[
"Gets",
"the",
"style",
"of",
"the",
"map"
] |
234ec4caa8f73f7a6432a098548f8d55c7894251
|
https://github.com/dynamic/silverstripe-geocoder/blob/234ec4caa8f73f7a6432a098548f8d55c7894251/src/AddressDataExtension.php#L134-L157
|
15,166
|
dynamic/silverstripe-geocoder
|
src/AddressDataExtension.php
|
AddressDataExtension.getIconImage
|
public static function getIconImage($svg = true)
{
$folders = [
'client/dist/img/',
'client/dist/images/',
'dist/img/',
'dist/images/',
'img/',
'images/',
];
$extensions = [
'png',
'jpg',
'jpeg',
'gif',
];
if ($svg === true) {
array_unshift($extensions, 'svg');
}
$file = 'mapIcon';
foreach ($folders as $folder) {
foreach ($extensions as $extension) {
if ($icon = ThemeResourceLoader::inst()->findThemedResource(
"{$folder}{$file}.{$extension}",
SSViewer::get_themes()
)) {
return ModuleResourceLoader::resourceURL($icon);
}
}
}
return false;
}
|
php
|
public static function getIconImage($svg = true)
{
$folders = [
'client/dist/img/',
'client/dist/images/',
'dist/img/',
'dist/images/',
'img/',
'images/',
];
$extensions = [
'png',
'jpg',
'jpeg',
'gif',
];
if ($svg === true) {
array_unshift($extensions, 'svg');
}
$file = 'mapIcon';
foreach ($folders as $folder) {
foreach ($extensions as $extension) {
if ($icon = ThemeResourceLoader::inst()->findThemedResource(
"{$folder}{$file}.{$extension}",
SSViewer::get_themes()
)) {
return ModuleResourceLoader::resourceURL($icon);
}
}
}
return false;
}
|
[
"public",
"static",
"function",
"getIconImage",
"(",
"$",
"svg",
"=",
"true",
")",
"{",
"$",
"folders",
"=",
"[",
"'client/dist/img/'",
",",
"'client/dist/images/'",
",",
"'dist/img/'",
",",
"'dist/images/'",
",",
"'img/'",
",",
"'images/'",
",",
"]",
";",
"$",
"extensions",
"=",
"[",
"'png'",
",",
"'jpg'",
",",
"'jpeg'",
",",
"'gif'",
",",
"]",
";",
"if",
"(",
"$",
"svg",
"===",
"true",
")",
"{",
"array_unshift",
"(",
"$",
"extensions",
",",
"'svg'",
")",
";",
"}",
"$",
"file",
"=",
"'mapIcon'",
";",
"foreach",
"(",
"$",
"folders",
"as",
"$",
"folder",
")",
"{",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"extension",
")",
"{",
"if",
"(",
"$",
"icon",
"=",
"ThemeResourceLoader",
"::",
"inst",
"(",
")",
"->",
"findThemedResource",
"(",
"\"{$folder}{$file}.{$extension}\"",
",",
"SSViewer",
"::",
"get_themes",
"(",
")",
")",
")",
"{",
"return",
"ModuleResourceLoader",
"::",
"resourceURL",
"(",
"$",
"icon",
")",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Gets the maker icon image
@var boolean $svg if svgs should be included
@return null|string
|
[
"Gets",
"the",
"maker",
"icon",
"image"
] |
234ec4caa8f73f7a6432a098548f8d55c7894251
|
https://github.com/dynamic/silverstripe-geocoder/blob/234ec4caa8f73f7a6432a098548f8d55c7894251/src/AddressDataExtension.php#L164-L200
|
15,167
|
dynamic/silverstripe-geocoder
|
src/AddressDataExtension.php
|
AddressDataExtension.isAddressChanged
|
public function isAddressChanged($level = 1)
{
$fields = ['Address', 'Address2', 'City', 'State', 'PostalCode', 'Country'];
$changed = $this->owner->getChangedFields(false, $level);
foreach ($fields as $field) {
if (array_key_exists($field, $changed)) {
return true;
}
}
return false;
}
|
php
|
public function isAddressChanged($level = 1)
{
$fields = ['Address', 'Address2', 'City', 'State', 'PostalCode', 'Country'];
$changed = $this->owner->getChangedFields(false, $level);
foreach ($fields as $field) {
if (array_key_exists($field, $changed)) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"isAddressChanged",
"(",
"$",
"level",
"=",
"1",
")",
"{",
"$",
"fields",
"=",
"[",
"'Address'",
",",
"'Address2'",
",",
"'City'",
",",
"'State'",
",",
"'PostalCode'",
",",
"'Country'",
"]",
";",
"$",
"changed",
"=",
"$",
"this",
"->",
"owner",
"->",
"getChangedFields",
"(",
"false",
",",
"$",
"level",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"changed",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Returns TRUE if any of the address fields have changed.
@param int $level
@return bool
|
[
"Returns",
"TRUE",
"if",
"any",
"of",
"the",
"address",
"fields",
"have",
"changed",
"."
] |
234ec4caa8f73f7a6432a098548f8d55c7894251
|
https://github.com/dynamic/silverstripe-geocoder/blob/234ec4caa8f73f7a6432a098548f8d55c7894251/src/AddressDataExtension.php#L236-L247
|
15,168
|
dragosprotung/stc-core
|
src/Workout/Dumper/TCX.php
|
TCX.writeTracks
|
private function writeTracks(\XMLWriter $xmlWriter, Workout $workout)
{
$xmlWriter->startElement('Activities');
foreach ($workout->tracks() as $track) {
$xmlWriter->startElement('Activity');
$xmlWriter->writeAttribute('Sport', ucfirst($track->sport()));
// Use the start date time as the ID. This could be anything.
$xmlWriter->writeElement('Id', $this->formatDateTime($track->startDateTime()));
$xmlWriter->startElement('Lap');
$xmlWriter->writeAttribute('StartTime', $this->formatDateTime($track->startDateTime()));
$xmlWriter->writeElement('TotalTimeSeconds', (string)$track->duration()->totalSeconds());
$xmlWriter->writeElement('DistanceMeters', (string)$track->length());
$this->writeLapHeartRateDate($xmlWriter, $track);
$xmlWriter->startElement('Track');
$this->writeTrackPoints($xmlWriter, $track->trackPoints());
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
|
php
|
private function writeTracks(\XMLWriter $xmlWriter, Workout $workout)
{
$xmlWriter->startElement('Activities');
foreach ($workout->tracks() as $track) {
$xmlWriter->startElement('Activity');
$xmlWriter->writeAttribute('Sport', ucfirst($track->sport()));
// Use the start date time as the ID. This could be anything.
$xmlWriter->writeElement('Id', $this->formatDateTime($track->startDateTime()));
$xmlWriter->startElement('Lap');
$xmlWriter->writeAttribute('StartTime', $this->formatDateTime($track->startDateTime()));
$xmlWriter->writeElement('TotalTimeSeconds', (string)$track->duration()->totalSeconds());
$xmlWriter->writeElement('DistanceMeters', (string)$track->length());
$this->writeLapHeartRateDate($xmlWriter, $track);
$xmlWriter->startElement('Track');
$this->writeTrackPoints($xmlWriter, $track->trackPoints());
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
|
[
"private",
"function",
"writeTracks",
"(",
"\\",
"XMLWriter",
"$",
"xmlWriter",
",",
"Workout",
"$",
"workout",
")",
"{",
"$",
"xmlWriter",
"->",
"startElement",
"(",
"'Activities'",
")",
";",
"foreach",
"(",
"$",
"workout",
"->",
"tracks",
"(",
")",
"as",
"$",
"track",
")",
"{",
"$",
"xmlWriter",
"->",
"startElement",
"(",
"'Activity'",
")",
";",
"$",
"xmlWriter",
"->",
"writeAttribute",
"(",
"'Sport'",
",",
"ucfirst",
"(",
"$",
"track",
"->",
"sport",
"(",
")",
")",
")",
";",
"// Use the start date time as the ID. This could be anything.",
"$",
"xmlWriter",
"->",
"writeElement",
"(",
"'Id'",
",",
"$",
"this",
"->",
"formatDateTime",
"(",
"$",
"track",
"->",
"startDateTime",
"(",
")",
")",
")",
";",
"$",
"xmlWriter",
"->",
"startElement",
"(",
"'Lap'",
")",
";",
"$",
"xmlWriter",
"->",
"writeAttribute",
"(",
"'StartTime'",
",",
"$",
"this",
"->",
"formatDateTime",
"(",
"$",
"track",
"->",
"startDateTime",
"(",
")",
")",
")",
";",
"$",
"xmlWriter",
"->",
"writeElement",
"(",
"'TotalTimeSeconds'",
",",
"(",
"string",
")",
"$",
"track",
"->",
"duration",
"(",
")",
"->",
"totalSeconds",
"(",
")",
")",
";",
"$",
"xmlWriter",
"->",
"writeElement",
"(",
"'DistanceMeters'",
",",
"(",
"string",
")",
"$",
"track",
"->",
"length",
"(",
")",
")",
";",
"$",
"this",
"->",
"writeLapHeartRateDate",
"(",
"$",
"xmlWriter",
",",
"$",
"track",
")",
";",
"$",
"xmlWriter",
"->",
"startElement",
"(",
"'Track'",
")",
";",
"$",
"this",
"->",
"writeTrackPoints",
"(",
"$",
"xmlWriter",
",",
"$",
"track",
"->",
"trackPoints",
"(",
")",
")",
";",
"$",
"xmlWriter",
"->",
"endElement",
"(",
")",
";",
"$",
"xmlWriter",
"->",
"endElement",
"(",
")",
";",
"$",
"xmlWriter",
"->",
"endElement",
"(",
")",
";",
"}",
"$",
"xmlWriter",
"->",
"endElement",
"(",
")",
";",
"}"
] |
Write the tracks to the TCX.
@param \XMLWriter $xmlWriter The XML writer.
@param Workout $workout The workout.
|
[
"Write",
"the",
"tracks",
"to",
"the",
"TCX",
"."
] |
9783e3414294f4ee555a1d538d2807269deeb9e7
|
https://github.com/dragosprotung/stc-core/blob/9783e3414294f4ee555a1d538d2807269deeb9e7/src/Workout/Dumper/TCX.php#L52-L78
|
15,169
|
dragosprotung/stc-core
|
src/Workout/Dumper/TCX.php
|
TCX.writeTrackPoints
|
private function writeTrackPoints(\XMLWriter $xmlWriter, array $trackPoints)
{
$previousTrackPoint = null;
foreach ($trackPoints as $trackPoint) {
$xmlWriter->startElement('Trackpoint');
// Time of position
$dateTime = clone $trackPoint->dateTime();
$dateTime->setTimezone(new \DateTimeZone('UTC'));
$xmlWriter->writeElement('Time', $this->formatDateTime($dateTime));
// Position.
$xmlWriter->startElement('Position');
$xmlWriter->writeElement('LatitudeDegrees', (string)$trackPoint->latitude());
$xmlWriter->writeElement('LongitudeDegrees', (string)$trackPoint->longitude());
$xmlWriter->endElement();
// Elevation.
$xmlWriter->writeElement('AltitudeMeters', (string)$trackPoint->elevation());
// Distance.
if ($previousTrackPoint !== null) {
$xmlWriter->writeElement('DistanceMeters', (string)$trackPoint->distanceFromPoint($previousTrackPoint));
} else {
$xmlWriter->writeElement('DistanceMeters', '0');
}
// Extensions.
$this->writeExtensions($xmlWriter, $trackPoint->extensions());
$xmlWriter->endElement();
$previousTrackPoint = $trackPoint;
}
}
|
php
|
private function writeTrackPoints(\XMLWriter $xmlWriter, array $trackPoints)
{
$previousTrackPoint = null;
foreach ($trackPoints as $trackPoint) {
$xmlWriter->startElement('Trackpoint');
// Time of position
$dateTime = clone $trackPoint->dateTime();
$dateTime->setTimezone(new \DateTimeZone('UTC'));
$xmlWriter->writeElement('Time', $this->formatDateTime($dateTime));
// Position.
$xmlWriter->startElement('Position');
$xmlWriter->writeElement('LatitudeDegrees', (string)$trackPoint->latitude());
$xmlWriter->writeElement('LongitudeDegrees', (string)$trackPoint->longitude());
$xmlWriter->endElement();
// Elevation.
$xmlWriter->writeElement('AltitudeMeters', (string)$trackPoint->elevation());
// Distance.
if ($previousTrackPoint !== null) {
$xmlWriter->writeElement('DistanceMeters', (string)$trackPoint->distanceFromPoint($previousTrackPoint));
} else {
$xmlWriter->writeElement('DistanceMeters', '0');
}
// Extensions.
$this->writeExtensions($xmlWriter, $trackPoint->extensions());
$xmlWriter->endElement();
$previousTrackPoint = $trackPoint;
}
}
|
[
"private",
"function",
"writeTrackPoints",
"(",
"\\",
"XMLWriter",
"$",
"xmlWriter",
",",
"array",
"$",
"trackPoints",
")",
"{",
"$",
"previousTrackPoint",
"=",
"null",
";",
"foreach",
"(",
"$",
"trackPoints",
"as",
"$",
"trackPoint",
")",
"{",
"$",
"xmlWriter",
"->",
"startElement",
"(",
"'Trackpoint'",
")",
";",
"// Time of position",
"$",
"dateTime",
"=",
"clone",
"$",
"trackPoint",
"->",
"dateTime",
"(",
")",
";",
"$",
"dateTime",
"->",
"setTimezone",
"(",
"new",
"\\",
"DateTimeZone",
"(",
"'UTC'",
")",
")",
";",
"$",
"xmlWriter",
"->",
"writeElement",
"(",
"'Time'",
",",
"$",
"this",
"->",
"formatDateTime",
"(",
"$",
"dateTime",
")",
")",
";",
"// Position.",
"$",
"xmlWriter",
"->",
"startElement",
"(",
"'Position'",
")",
";",
"$",
"xmlWriter",
"->",
"writeElement",
"(",
"'LatitudeDegrees'",
",",
"(",
"string",
")",
"$",
"trackPoint",
"->",
"latitude",
"(",
")",
")",
";",
"$",
"xmlWriter",
"->",
"writeElement",
"(",
"'LongitudeDegrees'",
",",
"(",
"string",
")",
"$",
"trackPoint",
"->",
"longitude",
"(",
")",
")",
";",
"$",
"xmlWriter",
"->",
"endElement",
"(",
")",
";",
"// Elevation.",
"$",
"xmlWriter",
"->",
"writeElement",
"(",
"'AltitudeMeters'",
",",
"(",
"string",
")",
"$",
"trackPoint",
"->",
"elevation",
"(",
")",
")",
";",
"// Distance.",
"if",
"(",
"$",
"previousTrackPoint",
"!==",
"null",
")",
"{",
"$",
"xmlWriter",
"->",
"writeElement",
"(",
"'DistanceMeters'",
",",
"(",
"string",
")",
"$",
"trackPoint",
"->",
"distanceFromPoint",
"(",
"$",
"previousTrackPoint",
")",
")",
";",
"}",
"else",
"{",
"$",
"xmlWriter",
"->",
"writeElement",
"(",
"'DistanceMeters'",
",",
"'0'",
")",
";",
"}",
"// Extensions.",
"$",
"this",
"->",
"writeExtensions",
"(",
"$",
"xmlWriter",
",",
"$",
"trackPoint",
"->",
"extensions",
"(",
")",
")",
";",
"$",
"xmlWriter",
"->",
"endElement",
"(",
")",
";",
"$",
"previousTrackPoint",
"=",
"$",
"trackPoint",
";",
"}",
"}"
] |
Write the track points to the TCX.
@param \XMLWriter $xmlWriter The XML writer.
@param TrackPoint[] $trackPoints The track points to write.
|
[
"Write",
"the",
"track",
"points",
"to",
"the",
"TCX",
"."
] |
9783e3414294f4ee555a1d538d2807269deeb9e7
|
https://github.com/dragosprotung/stc-core/blob/9783e3414294f4ee555a1d538d2807269deeb9e7/src/Workout/Dumper/TCX.php#L86-L120
|
15,170
|
dragosprotung/stc-core
|
src/Workout/Dumper/TCX.php
|
TCX.writeLapHeartRateDate
|
protected function writeLapHeartRateDate(\XMLWriter $xmlWriter, Track $track)
{
$averageHeartRate = array();
$maxHearRate = null;
foreach ($track->trackPoints() as $trackPoint) {
if ($trackPoint->hasExtension(HR::ID()) === true) {
$pointHearRate = $trackPoint->extension(HR::ID())->value();
$maxHearRate = max($maxHearRate, $pointHearRate);
$averageHeartRate[] = $pointHearRate;
}
}
if ($averageHeartRate !== array()) {
$xmlWriter->startElement('AverageHeartRateBpm');
$xmlWriter->writeAttributeNS('xsi', 'type', null, 'HeartRateInBeatsPerMinute_t');
$hearRateValue = array_sum($averageHeartRate) / count($averageHeartRate);
$xmlWriter->writeElement('Value', (string)$hearRateValue);
$xmlWriter->endElement();
}
if ($maxHearRate !== null) {
$xmlWriter->startElement('MaximumHeartRateBpm');
$xmlWriter->writeAttributeNS('xsi', 'type', null, 'HeartRateInBeatsPerMinute_t');
$xmlWriter->writeElement('Value', (string)$maxHearRate);
$xmlWriter->endElement();
}
}
|
php
|
protected function writeLapHeartRateDate(\XMLWriter $xmlWriter, Track $track)
{
$averageHeartRate = array();
$maxHearRate = null;
foreach ($track->trackPoints() as $trackPoint) {
if ($trackPoint->hasExtension(HR::ID()) === true) {
$pointHearRate = $trackPoint->extension(HR::ID())->value();
$maxHearRate = max($maxHearRate, $pointHearRate);
$averageHeartRate[] = $pointHearRate;
}
}
if ($averageHeartRate !== array()) {
$xmlWriter->startElement('AverageHeartRateBpm');
$xmlWriter->writeAttributeNS('xsi', 'type', null, 'HeartRateInBeatsPerMinute_t');
$hearRateValue = array_sum($averageHeartRate) / count($averageHeartRate);
$xmlWriter->writeElement('Value', (string)$hearRateValue);
$xmlWriter->endElement();
}
if ($maxHearRate !== null) {
$xmlWriter->startElement('MaximumHeartRateBpm');
$xmlWriter->writeAttributeNS('xsi', 'type', null, 'HeartRateInBeatsPerMinute_t');
$xmlWriter->writeElement('Value', (string)$maxHearRate);
$xmlWriter->endElement();
}
}
|
[
"protected",
"function",
"writeLapHeartRateDate",
"(",
"\\",
"XMLWriter",
"$",
"xmlWriter",
",",
"Track",
"$",
"track",
")",
"{",
"$",
"averageHeartRate",
"=",
"array",
"(",
")",
";",
"$",
"maxHearRate",
"=",
"null",
";",
"foreach",
"(",
"$",
"track",
"->",
"trackPoints",
"(",
")",
"as",
"$",
"trackPoint",
")",
"{",
"if",
"(",
"$",
"trackPoint",
"->",
"hasExtension",
"(",
"HR",
"::",
"ID",
"(",
")",
")",
"===",
"true",
")",
"{",
"$",
"pointHearRate",
"=",
"$",
"trackPoint",
"->",
"extension",
"(",
"HR",
"::",
"ID",
"(",
")",
")",
"->",
"value",
"(",
")",
";",
"$",
"maxHearRate",
"=",
"max",
"(",
"$",
"maxHearRate",
",",
"$",
"pointHearRate",
")",
";",
"$",
"averageHeartRate",
"[",
"]",
"=",
"$",
"pointHearRate",
";",
"}",
"}",
"if",
"(",
"$",
"averageHeartRate",
"!==",
"array",
"(",
")",
")",
"{",
"$",
"xmlWriter",
"->",
"startElement",
"(",
"'AverageHeartRateBpm'",
")",
";",
"$",
"xmlWriter",
"->",
"writeAttributeNS",
"(",
"'xsi'",
",",
"'type'",
",",
"null",
",",
"'HeartRateInBeatsPerMinute_t'",
")",
";",
"$",
"hearRateValue",
"=",
"array_sum",
"(",
"$",
"averageHeartRate",
")",
"/",
"count",
"(",
"$",
"averageHeartRate",
")",
";",
"$",
"xmlWriter",
"->",
"writeElement",
"(",
"'Value'",
",",
"(",
"string",
")",
"$",
"hearRateValue",
")",
";",
"$",
"xmlWriter",
"->",
"endElement",
"(",
")",
";",
"}",
"if",
"(",
"$",
"maxHearRate",
"!==",
"null",
")",
"{",
"$",
"xmlWriter",
"->",
"startElement",
"(",
"'MaximumHeartRateBpm'",
")",
";",
"$",
"xmlWriter",
"->",
"writeAttributeNS",
"(",
"'xsi'",
",",
"'type'",
",",
"null",
",",
"'HeartRateInBeatsPerMinute_t'",
")",
";",
"$",
"xmlWriter",
"->",
"writeElement",
"(",
"'Value'",
",",
"(",
"string",
")",
"$",
"maxHearRate",
")",
";",
"$",
"xmlWriter",
"->",
"endElement",
"(",
")",
";",
"}",
"}"
] |
Write the heart rate data for a lap.
@param \XMLWriter $xmlWriter The XML writer.
@param Track $track The track to write.
|
[
"Write",
"the",
"heart",
"rate",
"data",
"for",
"a",
"lap",
"."
] |
9783e3414294f4ee555a1d538d2807269deeb9e7
|
https://github.com/dragosprotung/stc-core/blob/9783e3414294f4ee555a1d538d2807269deeb9e7/src/Workout/Dumper/TCX.php#L128-L155
|
15,171
|
dragosprotung/stc-core
|
src/Workout/Dumper/TCX.php
|
TCX.writeExtensions
|
protected function writeExtensions(\XMLWriter $xmlWriter, array $extensions)
{
foreach ($extensions as $extension) {
switch ($extension::ID()) {
case HR::ID():
$xmlWriter->startElement('HeartRateBpm');
$xmlWriter->writeElement('Value', (string)$extension->value());
$xmlWriter->endElement();
break;
}
}
}
|
php
|
protected function writeExtensions(\XMLWriter $xmlWriter, array $extensions)
{
foreach ($extensions as $extension) {
switch ($extension::ID()) {
case HR::ID():
$xmlWriter->startElement('HeartRateBpm');
$xmlWriter->writeElement('Value', (string)$extension->value());
$xmlWriter->endElement();
break;
}
}
}
|
[
"protected",
"function",
"writeExtensions",
"(",
"\\",
"XMLWriter",
"$",
"xmlWriter",
",",
"array",
"$",
"extensions",
")",
"{",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"extension",
")",
"{",
"switch",
"(",
"$",
"extension",
"::",
"ID",
"(",
")",
")",
"{",
"case",
"HR",
"::",
"ID",
"(",
")",
":",
"$",
"xmlWriter",
"->",
"startElement",
"(",
"'HeartRateBpm'",
")",
";",
"$",
"xmlWriter",
"->",
"writeElement",
"(",
"'Value'",
",",
"(",
"string",
")",
"$",
"extension",
"->",
"value",
"(",
")",
")",
";",
"$",
"xmlWriter",
"->",
"endElement",
"(",
")",
";",
"break",
";",
"}",
"}",
"}"
] |
Write the extensions into the TCX.
@param \XMLWriter $xmlWriter The XMLWriter.
@param ExtensionInterface[] $extensions The extensions to write.
|
[
"Write",
"the",
"extensions",
"into",
"the",
"TCX",
"."
] |
9783e3414294f4ee555a1d538d2807269deeb9e7
|
https://github.com/dragosprotung/stc-core/blob/9783e3414294f4ee555a1d538d2807269deeb9e7/src/Workout/Dumper/TCX.php#L163-L174
|
15,172
|
e0ipso/drupal-unit-autoload
|
src/TokenResolver.php
|
TokenResolver.cleanToken
|
protected function cleanToken() {
if ($token_name = $this->getToken()) {
// Remove the token and arguments and return the path.
$path = substr($this->path, strlen($token_name));
return preg_replace('/<.*>/', '', $path);
}
$message = sprintf('No token could be found in "%s". Available tokens are: %s.', $this->path, implode(', ', array_keys($this->supportedTokens)));
throw new ClassLoaderException($message);
}
|
php
|
protected function cleanToken() {
if ($token_name = $this->getToken()) {
// Remove the token and arguments and return the path.
$path = substr($this->path, strlen($token_name));
return preg_replace('/<.*>/', '', $path);
}
$message = sprintf('No token could be found in "%s". Available tokens are: %s.', $this->path, implode(', ', array_keys($this->supportedTokens)));
throw new ClassLoaderException($message);
}
|
[
"protected",
"function",
"cleanToken",
"(",
")",
"{",
"if",
"(",
"$",
"token_name",
"=",
"$",
"this",
"->",
"getToken",
"(",
")",
")",
"{",
"// Remove the token and arguments and return the path.",
"$",
"path",
"=",
"substr",
"(",
"$",
"this",
"->",
"path",
",",
"strlen",
"(",
"$",
"token_name",
")",
")",
";",
"return",
"preg_replace",
"(",
"'/<.*>/'",
",",
"''",
",",
"$",
"path",
")",
";",
"}",
"$",
"message",
"=",
"sprintf",
"(",
"'No token could be found in \"%s\". Available tokens are: %s.'",
",",
"$",
"this",
"->",
"path",
",",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"this",
"->",
"supportedTokens",
")",
")",
")",
";",
"throw",
"new",
"ClassLoaderException",
"(",
"$",
"message",
")",
";",
"}"
] |
Removes the token from the tokenized path.
@throws ClassLoaderException
If no token can be found.
@return string
The cleaned path.
|
[
"Removes",
"the",
"token",
"from",
"the",
"tokenized",
"path",
"."
] |
7ce147b269c7333eca31e2cd04b736d6274b9cbf
|
https://github.com/e0ipso/drupal-unit-autoload/blob/7ce147b269c7333eca31e2cd04b736d6274b9cbf/src/TokenResolver.php#L91-L99
|
15,173
|
e0ipso/drupal-unit-autoload
|
src/TokenResolver.php
|
TokenResolver.getToken
|
protected function getToken() {
// Iterate over the supported tokens to find the token in the tokenized
// path.
foreach (array_keys($this->supportedTokens) as $token_name) {
if (strpos($this->path, $token_name) !== FALSE) {
return $token_name;
}
}
return NULL;
}
|
php
|
protected function getToken() {
// Iterate over the supported tokens to find the token in the tokenized
// path.
foreach (array_keys($this->supportedTokens) as $token_name) {
if (strpos($this->path, $token_name) !== FALSE) {
return $token_name;
}
}
return NULL;
}
|
[
"protected",
"function",
"getToken",
"(",
")",
"{",
"// Iterate over the supported tokens to find the token in the tokenized",
"// path.",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"supportedTokens",
")",
"as",
"$",
"token_name",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"path",
",",
"$",
"token_name",
")",
"!==",
"FALSE",
")",
"{",
"return",
"$",
"token_name",
";",
"}",
"}",
"return",
"NULL",
";",
"}"
] |
Checks if the current tokenized path contains a known token.
@return string
The token found. NULL otherwise.
|
[
"Checks",
"if",
"the",
"current",
"tokenized",
"path",
"contains",
"a",
"known",
"token",
"."
] |
7ce147b269c7333eca31e2cd04b736d6274b9cbf
|
https://github.com/e0ipso/drupal-unit-autoload/blob/7ce147b269c7333eca31e2cd04b736d6274b9cbf/src/TokenResolver.php#L107-L116
|
15,174
|
e0ipso/drupal-unit-autoload
|
src/TokenResolver.php
|
TokenResolver.parseArguments
|
protected function parseArguments() {
$token_name = $this->getToken();
$delimiter = '/';
$matches = array();
if (preg_match($delimiter . preg_quote($token_name) . '<(.+)>.*' . $delimiter, $this->path, $matches)) {
// Some arguments were found.
return explode(',', $matches[1]);
}
return array();
}
|
php
|
protected function parseArguments() {
$token_name = $this->getToken();
$delimiter = '/';
$matches = array();
if (preg_match($delimiter . preg_quote($token_name) . '<(.+)>.*' . $delimiter, $this->path, $matches)) {
// Some arguments were found.
return explode(',', $matches[1]);
}
return array();
}
|
[
"protected",
"function",
"parseArguments",
"(",
")",
"{",
"$",
"token_name",
"=",
"$",
"this",
"->",
"getToken",
"(",
")",
";",
"$",
"delimiter",
"=",
"'/'",
";",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"$",
"delimiter",
".",
"preg_quote",
"(",
"$",
"token_name",
")",
".",
"'<(.+)>.*'",
".",
"$",
"delimiter",
",",
"$",
"this",
"->",
"path",
",",
"$",
"matches",
")",
")",
"{",
"// Some arguments were found.",
"return",
"explode",
"(",
"','",
",",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
] |
Gets the arguments in the token.
@return string[]
A numeric array containing the token arguments.
|
[
"Gets",
"the",
"arguments",
"in",
"the",
"token",
"."
] |
7ce147b269c7333eca31e2cd04b736d6274b9cbf
|
https://github.com/e0ipso/drupal-unit-autoload/blob/7ce147b269c7333eca31e2cd04b736d6274b9cbf/src/TokenResolver.php#L135-L144
|
15,175
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/Route.php
|
Route.arrayFrom
|
private function arrayFrom($requestMethod): array
{
if (is_string($requestMethod)) {
return [$requestMethod];
}
if (null === $requestMethod) {
return [Http::GET, Http::HEAD, Http::POST, Http::PUT, Http::DELETE];
}
if (is_array($requestMethod)) {
return $requestMethod;
}
throw new \InvalidArgumentException(
'Given request method must be null, a string or an array, but received '
. typeOf($requestMethod)
);
}
|
php
|
private function arrayFrom($requestMethod): array
{
if (is_string($requestMethod)) {
return [$requestMethod];
}
if (null === $requestMethod) {
return [Http::GET, Http::HEAD, Http::POST, Http::PUT, Http::DELETE];
}
if (is_array($requestMethod)) {
return $requestMethod;
}
throw new \InvalidArgumentException(
'Given request method must be null, a string or an array, but received '
. typeOf($requestMethod)
);
}
|
[
"private",
"function",
"arrayFrom",
"(",
"$",
"requestMethod",
")",
":",
"array",
"{",
"if",
"(",
"is_string",
"(",
"$",
"requestMethod",
")",
")",
"{",
"return",
"[",
"$",
"requestMethod",
"]",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"requestMethod",
")",
"{",
"return",
"[",
"Http",
"::",
"GET",
",",
"Http",
"::",
"HEAD",
",",
"Http",
"::",
"POST",
",",
"Http",
"::",
"PUT",
",",
"Http",
"::",
"DELETE",
"]",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"requestMethod",
")",
")",
"{",
"return",
"$",
"requestMethod",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Given request method must be null, a string or an array, but received '",
".",
"typeOf",
"(",
"$",
"requestMethod",
")",
")",
";",
"}"
] |
turns given value into a list
@param string|string[] $requestMethod
@return string[]
@throws \InvalidArgumentException
|
[
"turns",
"given",
"value",
"into",
"a",
"list"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/Route.php#L135-L153
|
15,176
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/Route.php
|
Route.matches
|
public function matches(CalledUri $calledUri): bool
{
if (!$this->matchesPath($calledUri)) {
return false;
}
if (in_array($calledUri->method(), $this->allowedRequestMethods)) {
return true;
}
if (in_array(Http::GET, $this->allowedRequestMethods)) {
return $calledUri->methodEquals(Http::HEAD);
}
return false;
}
|
php
|
public function matches(CalledUri $calledUri): bool
{
if (!$this->matchesPath($calledUri)) {
return false;
}
if (in_array($calledUri->method(), $this->allowedRequestMethods)) {
return true;
}
if (in_array(Http::GET, $this->allowedRequestMethods)) {
return $calledUri->methodEquals(Http::HEAD);
}
return false;
}
|
[
"public",
"function",
"matches",
"(",
"CalledUri",
"$",
"calledUri",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"matchesPath",
"(",
"$",
"calledUri",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"calledUri",
"->",
"method",
"(",
")",
",",
"$",
"this",
"->",
"allowedRequestMethods",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"in_array",
"(",
"Http",
"::",
"GET",
",",
"$",
"this",
"->",
"allowedRequestMethods",
")",
")",
"{",
"return",
"$",
"calledUri",
"->",
"methodEquals",
"(",
"Http",
"::",
"HEAD",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
checks if this route is applicable for given request
@param \stubbles\webapp\CalledUri $calledUri current request uri
@return bool
|
[
"checks",
"if",
"this",
"route",
"is",
"applicable",
"for",
"given",
"request"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/Route.php#L171-L186
|
15,177
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/Route.php
|
Route.preIntercept
|
public function preIntercept($preInterceptor): ConfigurableRoute
{
if (!is_callable($preInterceptor) && !($preInterceptor instanceof PreInterceptor) && !class_exists((string) $preInterceptor)) {
throw new \InvalidArgumentException(
'Given pre interceptor must be a callable, an instance of '
. PreInterceptor::class
. ' or a class name of an existing pre interceptor class'
);
}
$this->preInterceptors[] = $preInterceptor;
return $this;
}
|
php
|
public function preIntercept($preInterceptor): ConfigurableRoute
{
if (!is_callable($preInterceptor) && !($preInterceptor instanceof PreInterceptor) && !class_exists((string) $preInterceptor)) {
throw new \InvalidArgumentException(
'Given pre interceptor must be a callable, an instance of '
. PreInterceptor::class
. ' or a class name of an existing pre interceptor class'
);
}
$this->preInterceptors[] = $preInterceptor;
return $this;
}
|
[
"public",
"function",
"preIntercept",
"(",
"$",
"preInterceptor",
")",
":",
"ConfigurableRoute",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"preInterceptor",
")",
"&&",
"!",
"(",
"$",
"preInterceptor",
"instanceof",
"PreInterceptor",
")",
"&&",
"!",
"class_exists",
"(",
"(",
"string",
")",
"$",
"preInterceptor",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Given pre interceptor must be a callable, an instance of '",
".",
"PreInterceptor",
"::",
"class",
".",
"' or a class name of an existing pre interceptor class'",
")",
";",
"}",
"$",
"this",
"->",
"preInterceptors",
"[",
"]",
"=",
"$",
"preInterceptor",
";",
"return",
"$",
"this",
";",
"}"
] |
add a pre interceptor for this route
@param string|callable|\stubbles\webapp\interceptor\PreInterceptor $preInterceptor
@return \stubbles\webapp\routing\Route
@throws \InvalidArgumentException
|
[
"add",
"a",
"pre",
"interceptor",
"for",
"this",
"route"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/Route.php#L226-L238
|
15,178
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/Route.php
|
Route.postIntercept
|
public function postIntercept($postInterceptor): ConfigurableRoute
{
if (!is_callable($postInterceptor) && !($postInterceptor instanceof PostInterceptor) && !class_exists((string) $postInterceptor)) {
throw new \InvalidArgumentException(
'Given pre interceptor must be a callable, an instance of '
. PostInterceptor::class
. ' or a class name of an existing post interceptor class'
);
}
$this->postInterceptors[] = $postInterceptor;
return $this;
}
|
php
|
public function postIntercept($postInterceptor): ConfigurableRoute
{
if (!is_callable($postInterceptor) && !($postInterceptor instanceof PostInterceptor) && !class_exists((string) $postInterceptor)) {
throw new \InvalidArgumentException(
'Given pre interceptor must be a callable, an instance of '
. PostInterceptor::class
. ' or a class name of an existing post interceptor class'
);
}
$this->postInterceptors[] = $postInterceptor;
return $this;
}
|
[
"public",
"function",
"postIntercept",
"(",
"$",
"postInterceptor",
")",
":",
"ConfigurableRoute",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"postInterceptor",
")",
"&&",
"!",
"(",
"$",
"postInterceptor",
"instanceof",
"PostInterceptor",
")",
"&&",
"!",
"class_exists",
"(",
"(",
"string",
")",
"$",
"postInterceptor",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Given pre interceptor must be a callable, an instance of '",
".",
"PostInterceptor",
"::",
"class",
".",
"' or a class name of an existing post interceptor class'",
")",
";",
"}",
"$",
"this",
"->",
"postInterceptors",
"[",
"]",
"=",
"$",
"postInterceptor",
";",
"return",
"$",
"this",
";",
"}"
] |
add a post interceptor for this route
@param string|callable|\stubbles\webapp\interceptor\PostInterceptor $postInterceptor
@return \stubbles\webapp\routing\Route
@throws \InvalidArgumentException
|
[
"add",
"a",
"post",
"interceptor",
"for",
"this",
"route"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/Route.php#L257-L269
|
15,179
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/Route.php
|
Route.requiresHttps
|
public function requiresHttps(): bool
{
if ($this->requiresHttps) {
return true;
}
$this->requiresHttps = $this->routingAnnotations()->requiresHttps();
return $this->requiresHttps;
}
|
php
|
public function requiresHttps(): bool
{
if ($this->requiresHttps) {
return true;
}
$this->requiresHttps = $this->routingAnnotations()->requiresHttps();
return $this->requiresHttps;
}
|
[
"public",
"function",
"requiresHttps",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"requiresHttps",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"requiresHttps",
"=",
"$",
"this",
"->",
"routingAnnotations",
"(",
")",
"->",
"requiresHttps",
"(",
")",
";",
"return",
"$",
"this",
"->",
"requiresHttps",
";",
"}"
] |
whether route is only available via https
@return bool
|
[
"whether",
"route",
"is",
"only",
"available",
"via",
"https"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/Route.php#L297-L305
|
15,180
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/Route.php
|
Route.authConstraint
|
public function authConstraint(): AuthConstraint
{
if (null === $this->authConstraint) {
$this->authConstraint = new AuthConstraint($this->routingAnnotations());
}
return $this->authConstraint;
}
|
php
|
public function authConstraint(): AuthConstraint
{
if (null === $this->authConstraint) {
$this->authConstraint = new AuthConstraint($this->routingAnnotations());
}
return $this->authConstraint;
}
|
[
"public",
"function",
"authConstraint",
"(",
")",
":",
"AuthConstraint",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"authConstraint",
")",
"{",
"$",
"this",
"->",
"authConstraint",
"=",
"new",
"AuthConstraint",
"(",
"$",
"this",
"->",
"routingAnnotations",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"authConstraint",
";",
"}"
] |
returns auth constraint for this route
@return \stubbles\webapp\auth\AuthConstraint
|
[
"returns",
"auth",
"constraint",
"for",
"this",
"route"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/Route.php#L363-L370
|
15,181
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/Route.php
|
Route.supportsMimeType
|
public function supportsMimeType(string $mimeType, string $class = null): ConfigurableRoute
{
if (null === $class && !SupportedMimeTypes::provideDefaultClassFor($mimeType)) {
throw new \InvalidArgumentException(
'No default class known for mime type ' . $mimeType
. ', please provide a class'
);
}
$this->mimeTypes[] = $mimeType;
if (null !== $class) {
$this->mimeTypeClasses[$mimeType] = $class;
}
return $this;
}
|
php
|
public function supportsMimeType(string $mimeType, string $class = null): ConfigurableRoute
{
if (null === $class && !SupportedMimeTypes::provideDefaultClassFor($mimeType)) {
throw new \InvalidArgumentException(
'No default class known for mime type ' . $mimeType
. ', please provide a class'
);
}
$this->mimeTypes[] = $mimeType;
if (null !== $class) {
$this->mimeTypeClasses[$mimeType] = $class;
}
return $this;
}
|
[
"public",
"function",
"supportsMimeType",
"(",
"string",
"$",
"mimeType",
",",
"string",
"$",
"class",
"=",
"null",
")",
":",
"ConfigurableRoute",
"{",
"if",
"(",
"null",
"===",
"$",
"class",
"&&",
"!",
"SupportedMimeTypes",
"::",
"provideDefaultClassFor",
"(",
"$",
"mimeType",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'No default class known for mime type '",
".",
"$",
"mimeType",
".",
"', please provide a class'",
")",
";",
"}",
"$",
"this",
"->",
"mimeTypes",
"[",
"]",
"=",
"$",
"mimeType",
";",
"if",
"(",
"null",
"!==",
"$",
"class",
")",
"{",
"$",
"this",
"->",
"mimeTypeClasses",
"[",
"$",
"mimeType",
"]",
"=",
"$",
"class",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
add a mime type which this route supports
@param string $mimeType
@param string $class optional special class to be used for given mime type on this route
@return \stubbles\webapp\routing\Route
@throws \InvalidArgumentException
|
[
"add",
"a",
"mime",
"type",
"which",
"this",
"route",
"supports"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/Route.php#L380-L395
|
15,182
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/Route.php
|
Route.supportedMimeTypes
|
public function supportedMimeTypes(
array $globalMimeTypes = [],
array $globalClasses = []
): SupportedMimeTypes {
if ($this->disableContentNegotation || $this->routingAnnotations()->isContentNegotiationDisabled()) {
return SupportedMimeTypes::createWithDisabledContentNegotation();
}
return new SupportedMimeTypes(
array_merge(
$this->routingAnnotations()->mimeTypes(),
$this->mimeTypes,
$globalMimeTypes
),
array_merge(
$globalClasses,
$this->routingAnnotations()->mimeTypeClasses(),
$this->mimeTypeClasses
)
);
}
|
php
|
public function supportedMimeTypes(
array $globalMimeTypes = [],
array $globalClasses = []
): SupportedMimeTypes {
if ($this->disableContentNegotation || $this->routingAnnotations()->isContentNegotiationDisabled()) {
return SupportedMimeTypes::createWithDisabledContentNegotation();
}
return new SupportedMimeTypes(
array_merge(
$this->routingAnnotations()->mimeTypes(),
$this->mimeTypes,
$globalMimeTypes
),
array_merge(
$globalClasses,
$this->routingAnnotations()->mimeTypeClasses(),
$this->mimeTypeClasses
)
);
}
|
[
"public",
"function",
"supportedMimeTypes",
"(",
"array",
"$",
"globalMimeTypes",
"=",
"[",
"]",
",",
"array",
"$",
"globalClasses",
"=",
"[",
"]",
")",
":",
"SupportedMimeTypes",
"{",
"if",
"(",
"$",
"this",
"->",
"disableContentNegotation",
"||",
"$",
"this",
"->",
"routingAnnotations",
"(",
")",
"->",
"isContentNegotiationDisabled",
"(",
")",
")",
"{",
"return",
"SupportedMimeTypes",
"::",
"createWithDisabledContentNegotation",
"(",
")",
";",
"}",
"return",
"new",
"SupportedMimeTypes",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"routingAnnotations",
"(",
")",
"->",
"mimeTypes",
"(",
")",
",",
"$",
"this",
"->",
"mimeTypes",
",",
"$",
"globalMimeTypes",
")",
",",
"array_merge",
"(",
"$",
"globalClasses",
",",
"$",
"this",
"->",
"routingAnnotations",
"(",
")",
"->",
"mimeTypeClasses",
"(",
")",
",",
"$",
"this",
"->",
"mimeTypeClasses",
")",
")",
";",
"}"
] |
returns list of mime types supported by this route
@param string[] $globalMimeTypes optional list of globally supported mime types
@param string[] $globalClasses optional list of globally defined mime type classes
@return \stubbles\webapp\routing\SupportedMimeTypes
|
[
"returns",
"list",
"of",
"mime",
"types",
"supported",
"by",
"this",
"route"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/Route.php#L404-L425
|
15,183
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/Route.php
|
Route.routingAnnotations
|
private function routingAnnotations(): RoutingAnnotations
{
if (null === $this->routingAnnotations) {
$this->routingAnnotations = new RoutingAnnotations($this->target);
}
return $this->routingAnnotations;
}
|
php
|
private function routingAnnotations(): RoutingAnnotations
{
if (null === $this->routingAnnotations) {
$this->routingAnnotations = new RoutingAnnotations($this->target);
}
return $this->routingAnnotations;
}
|
[
"private",
"function",
"routingAnnotations",
"(",
")",
":",
"RoutingAnnotations",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"routingAnnotations",
")",
"{",
"$",
"this",
"->",
"routingAnnotations",
"=",
"new",
"RoutingAnnotations",
"(",
"$",
"this",
"->",
"target",
")",
";",
"}",
"return",
"$",
"this",
"->",
"routingAnnotations",
";",
"}"
] |
returns list of callback annotations
@return \stubbles\webapp\routing\RoutingAnnotations
|
[
"returns",
"list",
"of",
"callback",
"annotations"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/Route.php#L444-L451
|
15,184
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/Route.php
|
Route.asResource
|
public function asResource(HttpUri $uri, array $globalMimeTypes = []): Resource
{
$routeUri = $uri->withPath($this->normalizePath());
return new Resource(
$this->resourceName(),
$this->allowedRequestMethods,
$this->requiresHttps() ? $routeUri->toHttps() : $routeUri,
$this->supportedMimeTypes($globalMimeTypes)->asArray(),
$this->routingAnnotations(),
$this->authConstraint()
);
}
|
php
|
public function asResource(HttpUri $uri, array $globalMimeTypes = []): Resource
{
$routeUri = $uri->withPath($this->normalizePath());
return new Resource(
$this->resourceName(),
$this->allowedRequestMethods,
$this->requiresHttps() ? $routeUri->toHttps() : $routeUri,
$this->supportedMimeTypes($globalMimeTypes)->asArray(),
$this->routingAnnotations(),
$this->authConstraint()
);
}
|
[
"public",
"function",
"asResource",
"(",
"HttpUri",
"$",
"uri",
",",
"array",
"$",
"globalMimeTypes",
"=",
"[",
"]",
")",
":",
"Resource",
"{",
"$",
"routeUri",
"=",
"$",
"uri",
"->",
"withPath",
"(",
"$",
"this",
"->",
"normalizePath",
"(",
")",
")",
";",
"return",
"new",
"Resource",
"(",
"$",
"this",
"->",
"resourceName",
"(",
")",
",",
"$",
"this",
"->",
"allowedRequestMethods",
",",
"$",
"this",
"->",
"requiresHttps",
"(",
")",
"?",
"$",
"routeUri",
"->",
"toHttps",
"(",
")",
":",
"$",
"routeUri",
",",
"$",
"this",
"->",
"supportedMimeTypes",
"(",
"$",
"globalMimeTypes",
")",
"->",
"asArray",
"(",
")",
",",
"$",
"this",
"->",
"routingAnnotations",
"(",
")",
",",
"$",
"this",
"->",
"authConstraint",
"(",
")",
")",
";",
"}"
] |
returns route as resource
@param \stubbles\peer\http\HttpUri $uri
@param string[] $globalMimeTypes list of globally supported mime types
@return \stubbles\webapp\routing\api\Resource
@since 6.1.0
|
[
"returns",
"route",
"as",
"resource"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/Route.php#L488-L499
|
15,185
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/Route.php
|
Route.normalizePath
|
private function normalizePath(): string
{
$path = $this->path;
if (substr($path, -1) === '$') {
$path = substr($path, 0, strlen($path) - 1);
}
if (substr($path, -1) === '?') {
$path = substr($path, 0, strlen($path) - 1);
}
return $path;
}
|
php
|
private function normalizePath(): string
{
$path = $this->path;
if (substr($path, -1) === '$') {
$path = substr($path, 0, strlen($path) - 1);
}
if (substr($path, -1) === '?') {
$path = substr($path, 0, strlen($path) - 1);
}
return $path;
}
|
[
"private",
"function",
"normalizePath",
"(",
")",
":",
"string",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"path",
";",
"if",
"(",
"substr",
"(",
"$",
"path",
",",
"-",
"1",
")",
"===",
"'$'",
")",
"{",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"strlen",
"(",
"$",
"path",
")",
"-",
"1",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"path",
",",
"-",
"1",
")",
"===",
"'?'",
")",
"{",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"strlen",
"(",
"$",
"path",
")",
"-",
"1",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] |
normalizes path for better understanding
@return string
|
[
"normalizes",
"path",
"for",
"better",
"understanding"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/Route.php#L506-L518
|
15,186
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/Route.php
|
Route.resourceName
|
private function resourceName()
{
if ($this->routingAnnotations()->hasName()) {
return $this->routingAnnotations()->name();
}
if (is_string($this->target) && class_exists($this->target)) {
return substr(
$this->target,
strrpos($this->target, '\\') + 1
);
} elseif (!is_callable($this->target) && is_object($this->target)) {
return substr(
get_class($this->target),
strrpos(get_class($this->target), '\\') + 1
);
}
return null;
}
|
php
|
private function resourceName()
{
if ($this->routingAnnotations()->hasName()) {
return $this->routingAnnotations()->name();
}
if (is_string($this->target) && class_exists($this->target)) {
return substr(
$this->target,
strrpos($this->target, '\\') + 1
);
} elseif (!is_callable($this->target) && is_object($this->target)) {
return substr(
get_class($this->target),
strrpos(get_class($this->target), '\\') + 1
);
}
return null;
}
|
[
"private",
"function",
"resourceName",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"routingAnnotations",
"(",
")",
"->",
"hasName",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"routingAnnotations",
"(",
")",
"->",
"name",
"(",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"target",
")",
"&&",
"class_exists",
"(",
"$",
"this",
"->",
"target",
")",
")",
"{",
"return",
"substr",
"(",
"$",
"this",
"->",
"target",
",",
"strrpos",
"(",
"$",
"this",
"->",
"target",
",",
"'\\\\'",
")",
"+",
"1",
")",
";",
"}",
"elseif",
"(",
"!",
"is_callable",
"(",
"$",
"this",
"->",
"target",
")",
"&&",
"is_object",
"(",
"$",
"this",
"->",
"target",
")",
")",
"{",
"return",
"substr",
"(",
"get_class",
"(",
"$",
"this",
"->",
"target",
")",
",",
"strrpos",
"(",
"get_class",
"(",
"$",
"this",
"->",
"target",
")",
",",
"'\\\\'",
")",
"+",
"1",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
returns useful name for resource
@return string|null
|
[
"returns",
"useful",
"name",
"for",
"resource"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/Route.php#L525-L544
|
15,187
|
danmichaelo/quitesimplexmlelement
|
src/Danmichaelo/QuiteSimpleXMLElement/SimpleXMLElementWrapper.php
|
SimpleXMLElementWrapper.registerXPathNamespace
|
public function registerXPathNamespace($prefix, $uri)
{
$this->el->registerXPathNamespace($prefix, $uri);
$this->namespaces[$prefix] = $uri;
}
|
php
|
public function registerXPathNamespace($prefix, $uri)
{
$this->el->registerXPathNamespace($prefix, $uri);
$this->namespaces[$prefix] = $uri;
}
|
[
"public",
"function",
"registerXPathNamespace",
"(",
"$",
"prefix",
",",
"$",
"uri",
")",
"{",
"$",
"this",
"->",
"el",
"->",
"registerXPathNamespace",
"(",
"$",
"prefix",
",",
"$",
"uri",
")",
";",
"$",
"this",
"->",
"namespaces",
"[",
"$",
"prefix",
"]",
"=",
"$",
"uri",
";",
"}"
] |
Register a new xpath namespace.
@param string $prefix
@param string $uri
|
[
"Register",
"a",
"new",
"xpath",
"namespace",
"."
] |
566261ac5a789d63fda4ffc328501213772c1b27
|
https://github.com/danmichaelo/quitesimplexmlelement/blob/566261ac5a789d63fda4ffc328501213772c1b27/src/Danmichaelo/QuiteSimpleXMLElement/SimpleXMLElementWrapper.php#L146-L150
|
15,188
|
danmichaelo/quitesimplexmlelement
|
src/Danmichaelo/QuiteSimpleXMLElement/SimpleXMLElementWrapper.php
|
SimpleXMLElementWrapper.registerXPathNamespaces
|
public function registerXPathNamespaces($namespaces)
{
// Convenience method to add multiple namespaces at once
foreach ($namespaces as $prefix => $uri) {
$this->registerXPathNamespace($prefix, $uri);
}
}
|
php
|
public function registerXPathNamespaces($namespaces)
{
// Convenience method to add multiple namespaces at once
foreach ($namespaces as $prefix => $uri) {
$this->registerXPathNamespace($prefix, $uri);
}
}
|
[
"public",
"function",
"registerXPathNamespaces",
"(",
"$",
"namespaces",
")",
"{",
"// Convenience method to add multiple namespaces at once",
"foreach",
"(",
"$",
"namespaces",
"as",
"$",
"prefix",
"=>",
"$",
"uri",
")",
"{",
"$",
"this",
"->",
"registerXPathNamespace",
"(",
"$",
"prefix",
",",
"$",
"uri",
")",
";",
"}",
"}"
] |
Register an array of new xpath namespaces.
@param array $namespaces
|
[
"Register",
"an",
"array",
"of",
"new",
"xpath",
"namespaces",
"."
] |
566261ac5a789d63fda4ffc328501213772c1b27
|
https://github.com/danmichaelo/quitesimplexmlelement/blob/566261ac5a789d63fda4ffc328501213772c1b27/src/Danmichaelo/QuiteSimpleXMLElement/SimpleXMLElementWrapper.php#L157-L163
|
15,189
|
danmichaelo/quitesimplexmlelement
|
src/Danmichaelo/QuiteSimpleXMLElement/SimpleXMLElementWrapper.php
|
SimpleXMLElementWrapper.children
|
public function children($ns = null)
{
$ch = is_null($ns)
? $this->el->children()
: $this->el->children($this->namespaces[$ns]);
$o = [];
foreach ($ch as $c) {
$o[] = new static($c, $this);
}
return $o;
}
|
php
|
public function children($ns = null)
{
$ch = is_null($ns)
? $this->el->children()
: $this->el->children($this->namespaces[$ns]);
$o = [];
foreach ($ch as $c) {
$o[] = new static($c, $this);
}
return $o;
}
|
[
"public",
"function",
"children",
"(",
"$",
"ns",
"=",
"null",
")",
"{",
"$",
"ch",
"=",
"is_null",
"(",
"$",
"ns",
")",
"?",
"$",
"this",
"->",
"el",
"->",
"children",
"(",
")",
":",
"$",
"this",
"->",
"el",
"->",
"children",
"(",
"$",
"this",
"->",
"namespaces",
"[",
"$",
"ns",
"]",
")",
";",
"$",
"o",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"ch",
"as",
"$",
"c",
")",
"{",
"$",
"o",
"[",
"]",
"=",
"new",
"static",
"(",
"$",
"c",
",",
"$",
"this",
")",
";",
"}",
"return",
"$",
"o",
";",
"}"
] |
Returns child elements.
Note: By default, only children without namespace will be returned! You can
specify a namespace prefix to get children with that namespace prefix.
If you want all child elements, namespaced or not, use
`$record->all('child::*')` instead.
@param string $ns
@return QuiteSimpleXMLElement[]
|
[
"Returns",
"child",
"elements",
"."
] |
566261ac5a789d63fda4ffc328501213772c1b27
|
https://github.com/danmichaelo/quitesimplexmlelement/blob/566261ac5a789d63fda4ffc328501213772c1b27/src/Danmichaelo/QuiteSimpleXMLElement/SimpleXMLElementWrapper.php#L196-L208
|
15,190
|
danmichaelo/quitesimplexmlelement
|
src/Danmichaelo/QuiteSimpleXMLElement/SimpleXMLElementWrapper.php
|
SimpleXMLElementWrapper.attributes
|
public function attributes($ns = null, $is_prefix = false)
{
return $this->el->attributes($ns, $is_prefix);
}
|
php
|
public function attributes($ns = null, $is_prefix = false)
{
return $this->el->attributes($ns, $is_prefix);
}
|
[
"public",
"function",
"attributes",
"(",
"$",
"ns",
"=",
"null",
",",
"$",
"is_prefix",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"el",
"->",
"attributes",
"(",
"$",
"ns",
",",
"$",
"is_prefix",
")",
";",
"}"
] |
Returns and element's attributes.
@param string $ns
@param bool $is_prefix
@return SimpleXMLElement a `SimpleXMLElement` object that can be
iterated over to loop through the attributes on the tag.
|
[
"Returns",
"and",
"element",
"s",
"attributes",
"."
] |
566261ac5a789d63fda4ffc328501213772c1b27
|
https://github.com/danmichaelo/quitesimplexmlelement/blob/566261ac5a789d63fda4ffc328501213772c1b27/src/Danmichaelo/QuiteSimpleXMLElement/SimpleXMLElementWrapper.php#L235-L238
|
15,191
|
phramework/jsonapi
|
src/Controller/DELETE.php
|
DELETE.handleDELETE
|
protected static function handleDELETE(
$parameters,
$method,
$headers,
$id,
$modelClass,
$primaryDataParameters = [],
$validationCallbacks = [],
$viewCallback = null
) {
if ($viewCallback !== null && !is_callable($viewCallback)) {
throw new ServerException('View callback is not callable!');
}
//Fetch data, in order to check if resource exists (and/or is accessible)
$resource = $modelClass::getById(
$id,
null, //fields
...$primaryDataParameters
);
//Check if resource exists
static::exists($resource);
//Call validation callbacks if set
foreach ($validationCallbacks as $callback) {
call_user_func(
$callback,
$id,
$resource
);
}
$delete = $modelClass::delete($id, $primaryDataParameters);
if (!$delete) {
throw new RequestException(
'Unable to delete record'
);
}
if ($viewCallback !== null) {
return call_user_func(
$viewCallback,
$id
);
}
\Phramework\JSONAPI\Viewers\JSONAPI::header();
\Phramework\Models\Response::noContent();
return true;
}
|
php
|
protected static function handleDELETE(
$parameters,
$method,
$headers,
$id,
$modelClass,
$primaryDataParameters = [],
$validationCallbacks = [],
$viewCallback = null
) {
if ($viewCallback !== null && !is_callable($viewCallback)) {
throw new ServerException('View callback is not callable!');
}
//Fetch data, in order to check if resource exists (and/or is accessible)
$resource = $modelClass::getById(
$id,
null, //fields
...$primaryDataParameters
);
//Check if resource exists
static::exists($resource);
//Call validation callbacks if set
foreach ($validationCallbacks as $callback) {
call_user_func(
$callback,
$id,
$resource
);
}
$delete = $modelClass::delete($id, $primaryDataParameters);
if (!$delete) {
throw new RequestException(
'Unable to delete record'
);
}
if ($viewCallback !== null) {
return call_user_func(
$viewCallback,
$id
);
}
\Phramework\JSONAPI\Viewers\JSONAPI::header();
\Phramework\Models\Response::noContent();
return true;
}
|
[
"protected",
"static",
"function",
"handleDELETE",
"(",
"$",
"parameters",
",",
"$",
"method",
",",
"$",
"headers",
",",
"$",
"id",
",",
"$",
"modelClass",
",",
"$",
"primaryDataParameters",
"=",
"[",
"]",
",",
"$",
"validationCallbacks",
"=",
"[",
"]",
",",
"$",
"viewCallback",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"viewCallback",
"!==",
"null",
"&&",
"!",
"is_callable",
"(",
"$",
"viewCallback",
")",
")",
"{",
"throw",
"new",
"ServerException",
"(",
"'View callback is not callable!'",
")",
";",
"}",
"//Fetch data, in order to check if resource exists (and/or is accessible)",
"$",
"resource",
"=",
"$",
"modelClass",
"::",
"getById",
"(",
"$",
"id",
",",
"null",
",",
"//fields",
"...",
"$",
"primaryDataParameters",
")",
";",
"//Check if resource exists",
"static",
"::",
"exists",
"(",
"$",
"resource",
")",
";",
"//Call validation callbacks if set",
"foreach",
"(",
"$",
"validationCallbacks",
"as",
"$",
"callback",
")",
"{",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"id",
",",
"$",
"resource",
")",
";",
"}",
"$",
"delete",
"=",
"$",
"modelClass",
"::",
"delete",
"(",
"$",
"id",
",",
"$",
"primaryDataParameters",
")",
";",
"if",
"(",
"!",
"$",
"delete",
")",
"{",
"throw",
"new",
"RequestException",
"(",
"'Unable to delete record'",
")",
";",
"}",
"if",
"(",
"$",
"viewCallback",
"!==",
"null",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"viewCallback",
",",
"$",
"id",
")",
";",
"}",
"\\",
"Phramework",
"\\",
"JSONAPI",
"\\",
"Viewers",
"\\",
"JSONAPI",
"::",
"header",
"(",
")",
";",
"\\",
"Phramework",
"\\",
"Models",
"\\",
"Response",
"::",
"noContent",
"(",
")",
";",
"return",
"true",
";",
"}"
] |
Handle DELETE method
On success will respond with 204 No Content
@param object $parameters Request parameters
@param string $method Request method
@param array $headers Request headers
@param integer|string $id Requested resource's id
@param string $modelClass Resource's primary model
to be used
@param array $primaryDataParameters [Optional] Array with any
additional arguments that the primary data is requiring
@throws \Phramework\Exceptions\NotFound If resource not found
@throws \Phramework\Exceptions\RequestException If unable to delete
@uses model's `getById` method to fetch resource
@uses $modelClass::delete method to
delete resources
@return bool
|
[
"Handle",
"DELETE",
"method",
"On",
"success",
"will",
"respond",
"with",
"204",
"No",
"Content"
] |
af20882a8b6f6e5be9c8e09e5b87f6c23a4b0726
|
https://github.com/phramework/jsonapi/blob/af20882a8b6f6e5be9c8e09e5b87f6c23a4b0726/src/Controller/DELETE.php#L49-L102
|
15,192
|
fuelphp/display
|
src/Parser/Mustache.php
|
Mustache.setupMustache
|
public function setupMustache()
{
$mustacheLoader = new MustacheLoader($this->viewManager);
$config = ['loader' => $mustacheLoader];
if ($this->viewManager->cachePath)
{
$config['cache'] = $this->viewManager->cachePath.'mustache/';
}
$this->mustache = new Mustache_Engine($config);
}
|
php
|
public function setupMustache()
{
$mustacheLoader = new MustacheLoader($this->viewManager);
$config = ['loader' => $mustacheLoader];
if ($this->viewManager->cachePath)
{
$config['cache'] = $this->viewManager->cachePath.'mustache/';
}
$this->mustache = new Mustache_Engine($config);
}
|
[
"public",
"function",
"setupMustache",
"(",
")",
"{",
"$",
"mustacheLoader",
"=",
"new",
"MustacheLoader",
"(",
"$",
"this",
"->",
"viewManager",
")",
";",
"$",
"config",
"=",
"[",
"'loader'",
"=>",
"$",
"mustacheLoader",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"viewManager",
"->",
"cachePath",
")",
"{",
"$",
"config",
"[",
"'cache'",
"]",
"=",
"$",
"this",
"->",
"viewManager",
"->",
"cachePath",
".",
"'mustache/'",
";",
"}",
"$",
"this",
"->",
"mustache",
"=",
"new",
"Mustache_Engine",
"(",
"$",
"config",
")",
";",
"}"
] |
Sets up Mustache_Engine
|
[
"Sets",
"up",
"Mustache_Engine"
] |
d9a3eddbf80f0fd81beb40d9f4507600ac6611a4
|
https://github.com/fuelphp/display/blob/d9a3eddbf80f0fd81beb40d9f4507600ac6611a4/src/Parser/Mustache.php#L51-L62
|
15,193
|
activecollab/databasestructure
|
src/Builder/BaseManagerDirBuilder.php
|
BaseManagerDirBuilder.preBuild
|
public function preBuild()
{
$build_path = $this->getBuildPath();
if ($build_path) {
if (is_dir($build_path)) {
$build_path = rtrim($build_path, DIRECTORY_SEPARATOR);
if (!is_dir("$build_path/Manager/Base")) {
$old_umask = umask(0);
$dir_created = mkdir("$build_path/Manager/Base");
umask($old_umask);
if ($dir_created) {
$this->triggerEvent('on_dir_created', ["$build_path/Manager/Base"]);
} else {
throw new RuntimeException("Failed to create '$build_path/Manager/Base' directory");
}
}
} else {
throw new InvalidArgumentException("Directory '$build_path' not found");
}
}
}
|
php
|
public function preBuild()
{
$build_path = $this->getBuildPath();
if ($build_path) {
if (is_dir($build_path)) {
$build_path = rtrim($build_path, DIRECTORY_SEPARATOR);
if (!is_dir("$build_path/Manager/Base")) {
$old_umask = umask(0);
$dir_created = mkdir("$build_path/Manager/Base");
umask($old_umask);
if ($dir_created) {
$this->triggerEvent('on_dir_created', ["$build_path/Manager/Base"]);
} else {
throw new RuntimeException("Failed to create '$build_path/Manager/Base' directory");
}
}
} else {
throw new InvalidArgumentException("Directory '$build_path' not found");
}
}
}
|
[
"public",
"function",
"preBuild",
"(",
")",
"{",
"$",
"build_path",
"=",
"$",
"this",
"->",
"getBuildPath",
"(",
")",
";",
"if",
"(",
"$",
"build_path",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"build_path",
")",
")",
"{",
"$",
"build_path",
"=",
"rtrim",
"(",
"$",
"build_path",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"\"$build_path/Manager/Base\"",
")",
")",
"{",
"$",
"old_umask",
"=",
"umask",
"(",
"0",
")",
";",
"$",
"dir_created",
"=",
"mkdir",
"(",
"\"$build_path/Manager/Base\"",
")",
";",
"umask",
"(",
"$",
"old_umask",
")",
";",
"if",
"(",
"$",
"dir_created",
")",
"{",
"$",
"this",
"->",
"triggerEvent",
"(",
"'on_dir_created'",
",",
"[",
"\"$build_path/Manager/Base\"",
"]",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Failed to create '$build_path/Manager/Base' directory\"",
")",
";",
"}",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Directory '$build_path' not found\"",
")",
";",
"}",
"}",
"}"
] |
Execute prior to type build.
|
[
"Execute",
"prior",
"to",
"type",
"build",
"."
] |
4b2353c4422186bcfce63b3212da3e70e63eb5df
|
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/BaseManagerDirBuilder.php#L22-L45
|
15,194
|
stubbles/stubbles-webapp-core
|
src/main/php/response/Headers.php
|
Headers.add
|
public function add(string $name, $value): self
{
$this->headers[$name] = $value;
return $this;
}
|
php
|
public function add(string $name, $value): self
{
$this->headers[$name] = $value;
return $this;
}
|
[
"public",
"function",
"add",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] |
adds header with given name
@param string $name
@param mixed $value
@return \stubbles\webapp\response\Headers
|
[
"adds",
"header",
"with",
"given",
"name"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/response/Headers.php#L34-L38
|
15,195
|
stubbles/stubbles-webapp-core
|
src/main/php/response/Headers.php
|
Headers.location
|
public function location($uri): self
{
return $this->add(
'Location',
(($uri instanceof HttpUri) ? ($uri->asStringWithNonDefaultPort()) : ($uri))
);
}
|
php
|
public function location($uri): self
{
return $this->add(
'Location',
(($uri instanceof HttpUri) ? ($uri->asStringWithNonDefaultPort()) : ($uri))
);
}
|
[
"public",
"function",
"location",
"(",
"$",
"uri",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"add",
"(",
"'Location'",
",",
"(",
"(",
"$",
"uri",
"instanceof",
"HttpUri",
")",
"?",
"(",
"$",
"uri",
"->",
"asStringWithNonDefaultPort",
"(",
")",
")",
":",
"(",
"$",
"uri",
")",
")",
")",
";",
"}"
] |
adds location header with given uri
@param string|\stubbles\peer\http\HttpUri $uri
@return \stubbles\webapp\response\Headers
|
[
"adds",
"location",
"header",
"with",
"given",
"uri"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/response/Headers.php#L59-L65
|
15,196
|
stubbles/stubbles-webapp-core
|
src/main/php/response/Headers.php
|
Headers.acceptable
|
public function acceptable(array $supportedMimeTypes): self
{
if (count($supportedMimeTypes) > 0) {
$this->add('X-Acceptable', join(', ', $supportedMimeTypes));
}
return $this;
}
|
php
|
public function acceptable(array $supportedMimeTypes): self
{
if (count($supportedMimeTypes) > 0) {
$this->add('X-Acceptable', join(', ', $supportedMimeTypes));
}
return $this;
}
|
[
"public",
"function",
"acceptable",
"(",
"array",
"$",
"supportedMimeTypes",
")",
":",
"self",
"{",
"if",
"(",
"count",
"(",
"$",
"supportedMimeTypes",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"'X-Acceptable'",
",",
"join",
"(",
"', '",
",",
"$",
"supportedMimeTypes",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
adds non-standard acceptable header with list of supported mime types
@param string[] $supportedMimeTypes
@return \stubbles\webapp\response\Headers
|
[
"adds",
"non",
"-",
"standard",
"acceptable",
"header",
"with",
"list",
"of",
"supported",
"mime",
"types"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/response/Headers.php#L84-L91
|
15,197
|
stubbles/stubbles-webapp-core
|
src/main/php/response/Headers.php
|
Headers.cacheControl
|
public function cacheControl(): CacheControl
{
$cacheControl = new CacheControl();
$this->add(CacheControl::HEADER_NAME, $cacheControl);
return $cacheControl;
}
|
php
|
public function cacheControl(): CacheControl
{
$cacheControl = new CacheControl();
$this->add(CacheControl::HEADER_NAME, $cacheControl);
return $cacheControl;
}
|
[
"public",
"function",
"cacheControl",
"(",
")",
":",
"CacheControl",
"{",
"$",
"cacheControl",
"=",
"new",
"CacheControl",
"(",
")",
";",
"$",
"this",
"->",
"add",
"(",
"CacheControl",
"::",
"HEADER_NAME",
",",
"$",
"cacheControl",
")",
";",
"return",
"$",
"cacheControl",
";",
"}"
] |
enables the Cache-Control header
If no specific directives are enabled the value will be
<code>Cache-Control: private</code>
by default.
@return \stubbles\webapp\response\CacheControl
@see http://tools.ietf.org/html/rfc7234#section-5.2
@since 5.1.0
|
[
"enables",
"the",
"Cache",
"-",
"Control",
"header"
] |
7705f129011a81d5cc3c76b4b150fab3dadac6a3
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/response/Headers.php#L115-L120
|
15,198
|
czim/laravel-pxlcms
|
src/Generator/Writer/Model/Steps/StubReplaceAccessorsAndMutators.php
|
StubReplaceAccessorsAndMutators.collectNormalBelongsToRelationAccessors
|
protected function collectNormalBelongsToRelationAccessors()
{
$accessors = [];
foreach ($this->data['relationships']['normal'] as $name => $relationship) {
if ($relationship['type'] != Generator::RELATIONSHIP_BELONGS_TO) continue;
if ( ! empty($relationship['key']) && snake_case($name) !== $relationship['key']) continue;
$attributeName = snake_case($name);
$content = $this->tab(2) . "return \$this->getBelongsToRelationAttributeValue('{$name}');\n";
$accessors[ $name ] = [
'attribute' => $attributeName,
'content' => $content,
];
}
return $accessors;
}
|
php
|
protected function collectNormalBelongsToRelationAccessors()
{
$accessors = [];
foreach ($this->data['relationships']['normal'] as $name => $relationship) {
if ($relationship['type'] != Generator::RELATIONSHIP_BELONGS_TO) continue;
if ( ! empty($relationship['key']) && snake_case($name) !== $relationship['key']) continue;
$attributeName = snake_case($name);
$content = $this->tab(2) . "return \$this->getBelongsToRelationAttributeValue('{$name}');\n";
$accessors[ $name ] = [
'attribute' => $attributeName,
'content' => $content,
];
}
return $accessors;
}
|
[
"protected",
"function",
"collectNormalBelongsToRelationAccessors",
"(",
")",
"{",
"$",
"accessors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"[",
"'relationships'",
"]",
"[",
"'normal'",
"]",
"as",
"$",
"name",
"=>",
"$",
"relationship",
")",
"{",
"if",
"(",
"$",
"relationship",
"[",
"'type'",
"]",
"!=",
"Generator",
"::",
"RELATIONSHIP_BELONGS_TO",
")",
"continue",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"relationship",
"[",
"'key'",
"]",
")",
"&&",
"snake_case",
"(",
"$",
"name",
")",
"!==",
"$",
"relationship",
"[",
"'key'",
"]",
")",
"continue",
";",
"$",
"attributeName",
"=",
"snake_case",
"(",
"$",
"name",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"tab",
"(",
"2",
")",
".",
"\"return \\$this->getBelongsToRelationAttributeValue('{$name}');\\n\"",
";",
"$",
"accessors",
"[",
"$",
"name",
"]",
"=",
"[",
"'attribute'",
"=>",
"$",
"attributeName",
",",
"'content'",
"=>",
"$",
"content",
",",
"]",
";",
"}",
"return",
"$",
"accessors",
";",
"}"
] |
For belongs-to relationships that share foreign key & relation name
@return array name => array with properties
|
[
"For",
"belongs",
"-",
"to",
"relationships",
"that",
"share",
"foreign",
"key",
"&",
"relation",
"name"
] |
910297d2a3f2db86dde51b0e10fe5aad45f1aa1a
|
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Generator/Writer/Model/Steps/StubReplaceAccessorsAndMutators.php#L75-L94
|
15,199
|
acasademont/wurfl
|
WURFL/WURFLService.php
|
WURFL_WURFLService.getDeviceForRequest
|
public function getDeviceForRequest(WURFL_Request_GenericRequest $request)
{
$deviceId = $this->deviceIdForRequest($request);
return $this->getWrappedDevice($deviceId, $request);
}
|
php
|
public function getDeviceForRequest(WURFL_Request_GenericRequest $request)
{
$deviceId = $this->deviceIdForRequest($request);
return $this->getWrappedDevice($deviceId, $request);
}
|
[
"public",
"function",
"getDeviceForRequest",
"(",
"WURFL_Request_GenericRequest",
"$",
"request",
")",
"{",
"$",
"deviceId",
"=",
"$",
"this",
"->",
"deviceIdForRequest",
"(",
"$",
"request",
")",
";",
"return",
"$",
"this",
"->",
"getWrappedDevice",
"(",
"$",
"deviceId",
",",
"$",
"request",
")",
";",
"}"
] |
Returns the Device for the given WURFL_Request_GenericRequest
@param WURFL_Request_GenericRequest $request
@return WURFL_CustomDevice
|
[
"Returns",
"the",
"Device",
"for",
"the",
"given",
"WURFL_Request_GenericRequest"
] |
0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/WURFLService.php#L62-L66
|
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.