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
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
vukbgit/PHPCraft.Subject | src/Traits/Template.php | Template.renderTemplate | protected function renderTemplate($path = false)
{
if(!$this->templateEngine) {
throw new \Exception('template engine not injected');
}
if(!$path) {
$path = sprintf('%s/%s/%s', AREA, $this->name, $this->action);
}
$this->setCommonTemplateParameters();
$html = $this->templateEngine->render($path, $this->templateParameters);
$this->httpStream->write($html);
return $html;
} | php | protected function renderTemplate($path = false)
{
if(!$this->templateEngine) {
throw new \Exception('template engine not injected');
}
if(!$path) {
$path = sprintf('%s/%s/%s', AREA, $this->name, $this->action);
}
$this->setCommonTemplateParameters();
$html = $this->templateEngine->render($path, $this->templateParameters);
$this->httpStream->write($html);
return $html;
} | [
"protected",
"function",
"renderTemplate",
"(",
"$",
"path",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"templateEngine",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'template engine not injected'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"sprintf",
"(",
"'%s/%s/%s'",
",",
"AREA",
",",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"action",
")",
";",
"}",
"$",
"this",
"->",
"setCommonTemplateParameters",
"(",
")",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"templateEngine",
"->",
"render",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"templateParameters",
")",
";",
"$",
"this",
"->",
"httpStream",
"->",
"write",
"(",
"$",
"html",
")",
";",
"return",
"$",
"html",
";",
"}"
] | Renders template and writes output to HTTP stream
@param string $path;
@return string HTML content | [
"Renders",
"template",
"and",
"writes",
"output",
"to",
"HTTP",
"stream"
] | a43ad7868098ff1e7bda6819547ea64f9a853732 | https://github.com/vukbgit/PHPCraft.Subject/blob/a43ad7868098ff1e7bda6819547ea64f9a853732/src/Traits/Template.php#L125-L137 | train |
inc2734/wp-page-speed-optimization | src/App/Controller/LazyLoad.php | LazyLoad._async_attachment_images | public function _async_attachment_images( $atts, $attachment, $size ) {
if ( ! $this->_is_async_attachment_images() ) {
return $atts;
}
$atts['data-src'] = $atts['src'];
$atts['src'] = wp_get_attachment_image_url( $attachment->ID, 'wppso-minimum-thumbnail' );
if ( isset( $atts['srcset'] ) ) {
$atts['data-srcset'] = $atts['srcset'];
$atts['srcset'] = null;
}
$atts['decoding'] = 'async';
return $atts;
} | php | public function _async_attachment_images( $atts, $attachment, $size ) {
if ( ! $this->_is_async_attachment_images() ) {
return $atts;
}
$atts['data-src'] = $atts['src'];
$atts['src'] = wp_get_attachment_image_url( $attachment->ID, 'wppso-minimum-thumbnail' );
if ( isset( $atts['srcset'] ) ) {
$atts['data-srcset'] = $atts['srcset'];
$atts['srcset'] = null;
}
$atts['decoding'] = 'async';
return $atts;
} | [
"public",
"function",
"_async_attachment_images",
"(",
"$",
"atts",
",",
"$",
"attachment",
",",
"$",
"size",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_is_async_attachment_images",
"(",
")",
")",
"{",
"return",
"$",
"atts",
";",
"}",
"$",
"atts",
"[",
"'data-src'",
"]",
"=",
"$",
"atts",
"[",
"'src'",
"]",
";",
"$",
"atts",
"[",
"'src'",
"]",
"=",
"wp_get_attachment_image_url",
"(",
"$",
"attachment",
"->",
"ID",
",",
"'wppso-minimum-thumbnail'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"atts",
"[",
"'srcset'",
"]",
")",
")",
"{",
"$",
"atts",
"[",
"'data-srcset'",
"]",
"=",
"$",
"atts",
"[",
"'srcset'",
"]",
";",
"$",
"atts",
"[",
"'srcset'",
"]",
"=",
"null",
";",
"}",
"$",
"atts",
"[",
"'decoding'",
"]",
"=",
"'async'",
";",
"return",
"$",
"atts",
";",
"}"
] | Aync loading of attachment images
@param array $atts
@param WP_Post $attachment
@param string|array $size
@return array | [
"Aync",
"loading",
"of",
"attachment",
"images"
] | 219963582b592eef4bde6cdd4ed1cf0dc71a6114 | https://github.com/inc2734/wp-page-speed-optimization/blob/219963582b592eef4bde6cdd4ed1cf0dc71a6114/src/App/Controller/LazyLoad.php#L91-L106 | train |
inc2734/wp-page-speed-optimization | src/App/Controller/LazyLoad.php | LazyLoad._async_content_images | public function _async_content_images( $content ) {
if ( ! $this->_is_async_content_images() ) {
return $content;
}
if ( ! preg_match_all( '/<img [^>]+>/', $content, $matches ) ) {
return $content;
}
$selected_images = [];
foreach ( $matches[0] as $image ) {
if ( false === strpos( $image, ' decoding=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $reg ) ) {
$selected_images[ $reg[1] ][] = $image;
}
}
foreach ( $selected_images as $image_id => $images ) {
foreach ( $images as $image ) {
$new_image = $this->_add_decoding_to_content_image( $image );
$new_image = $this->_add_data_src_to_content_image( $new_image, $image_id );
$new_image = $this->_add_data_srcset_to_content_image( $new_image, $image_id );
$content = str_replace( $image, $new_image, $content );
}
}
return $content;
} | php | public function _async_content_images( $content ) {
if ( ! $this->_is_async_content_images() ) {
return $content;
}
if ( ! preg_match_all( '/<img [^>]+>/', $content, $matches ) ) {
return $content;
}
$selected_images = [];
foreach ( $matches[0] as $image ) {
if ( false === strpos( $image, ' decoding=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $reg ) ) {
$selected_images[ $reg[1] ][] = $image;
}
}
foreach ( $selected_images as $image_id => $images ) {
foreach ( $images as $image ) {
$new_image = $this->_add_decoding_to_content_image( $image );
$new_image = $this->_add_data_src_to_content_image( $new_image, $image_id );
$new_image = $this->_add_data_srcset_to_content_image( $new_image, $image_id );
$content = str_replace( $image, $new_image, $content );
}
}
return $content;
} | [
"public",
"function",
"_async_content_images",
"(",
"$",
"content",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_is_async_content_images",
"(",
")",
")",
"{",
"return",
"$",
"content",
";",
"}",
"if",
"(",
"!",
"preg_match_all",
"(",
"'/<img [^>]+>/'",
",",
"$",
"content",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"content",
";",
"}",
"$",
"selected_images",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"image",
")",
"{",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"image",
",",
"' decoding='",
")",
"&&",
"preg_match",
"(",
"'/wp-image-([0-9]+)/i'",
",",
"$",
"image",
",",
"$",
"reg",
")",
")",
"{",
"$",
"selected_images",
"[",
"$",
"reg",
"[",
"1",
"]",
"]",
"[",
"]",
"=",
"$",
"image",
";",
"}",
"}",
"foreach",
"(",
"$",
"selected_images",
"as",
"$",
"image_id",
"=>",
"$",
"images",
")",
"{",
"foreach",
"(",
"$",
"images",
"as",
"$",
"image",
")",
"{",
"$",
"new_image",
"=",
"$",
"this",
"->",
"_add_decoding_to_content_image",
"(",
"$",
"image",
")",
";",
"$",
"new_image",
"=",
"$",
"this",
"->",
"_add_data_src_to_content_image",
"(",
"$",
"new_image",
",",
"$",
"image_id",
")",
";",
"$",
"new_image",
"=",
"$",
"this",
"->",
"_add_data_srcset_to_content_image",
"(",
"$",
"new_image",
",",
"$",
"image_id",
")",
";",
"$",
"content",
"=",
"str_replace",
"(",
"$",
"image",
",",
"$",
"new_image",
",",
"$",
"content",
")",
";",
"}",
"}",
"return",
"$",
"content",
";",
"}"
] | Aync loading of content images
@param string $content
@return string | [
"Aync",
"loading",
"of",
"content",
"images"
] | 219963582b592eef4bde6cdd4ed1cf0dc71a6114 | https://github.com/inc2734/wp-page-speed-optimization/blob/219963582b592eef4bde6cdd4ed1cf0dc71a6114/src/App/Controller/LazyLoad.php#L114-L141 | train |
inc2734/wp-page-speed-optimization | src/App/Controller/LazyLoad.php | LazyLoad._add_data_src_to_content_image | protected function _add_data_src_to_content_image( $image, $image_id ) {
return preg_replace_callback(
'@(<img decoding="async"[^>]*?) src="([^"]+?)"([^>]*?>)@m',
function( $matches ) use ( $image_id ) {
return sprintf(
'%s src="%s" data-src="%s" %s',
$matches[1],
wp_get_attachment_image_url( $image_id, 'wppso-minimum-thumbnail' ),
$matches[2],
$matches[3]
);
},
$image
);
} | php | protected function _add_data_src_to_content_image( $image, $image_id ) {
return preg_replace_callback(
'@(<img decoding="async"[^>]*?) src="([^"]+?)"([^>]*?>)@m',
function( $matches ) use ( $image_id ) {
return sprintf(
'%s src="%s" data-src="%s" %s',
$matches[1],
wp_get_attachment_image_url( $image_id, 'wppso-minimum-thumbnail' ),
$matches[2],
$matches[3]
);
},
$image
);
} | [
"protected",
"function",
"_add_data_src_to_content_image",
"(",
"$",
"image",
",",
"$",
"image_id",
")",
"{",
"return",
"preg_replace_callback",
"(",
"'@(<img decoding=\"async\"[^>]*?) src=\"([^\"]+?)\"([^>]*?>)@m'",
",",
"function",
"(",
"$",
"matches",
")",
"use",
"(",
"$",
"image_id",
")",
"{",
"return",
"sprintf",
"(",
"'%s src=\"%s\" data-src=\"%s\" %s'",
",",
"$",
"matches",
"[",
"1",
"]",
",",
"wp_get_attachment_image_url",
"(",
"$",
"image_id",
",",
"'wppso-minimum-thumbnail'",
")",
",",
"$",
"matches",
"[",
"2",
"]",
",",
"$",
"matches",
"[",
"3",
"]",
")",
";",
"}",
",",
"$",
"image",
")",
";",
"}"
] | Add data-src to content image
@param string $image
@param int $image_id
@return string | [
"Add",
"data",
"-",
"src",
"to",
"content",
"image"
] | 219963582b592eef4bde6cdd4ed1cf0dc71a6114 | https://github.com/inc2734/wp-page-speed-optimization/blob/219963582b592eef4bde6cdd4ed1cf0dc71a6114/src/App/Controller/LazyLoad.php#L160-L174 | train |
inc2734/wp-page-speed-optimization | src/App/Controller/LazyLoad.php | LazyLoad._add_data_srcset_to_content_image | protected function _add_data_srcset_to_content_image( $image, $image_id ) {
return preg_replace_callback(
'@(<img decoding="async"[^>]*?)srcset="([^"]+?)"([^>]*?>)@m',
function( $matches ) use ( $image_id ) {
return sprintf(
'%s srcset="" data-srcset="%s" %s',
$matches[1],
$matches[2],
$matches[3]
);
},
$image
);
} | php | protected function _add_data_srcset_to_content_image( $image, $image_id ) {
return preg_replace_callback(
'@(<img decoding="async"[^>]*?)srcset="([^"]+?)"([^>]*?>)@m',
function( $matches ) use ( $image_id ) {
return sprintf(
'%s srcset="" data-srcset="%s" %s',
$matches[1],
$matches[2],
$matches[3]
);
},
$image
);
} | [
"protected",
"function",
"_add_data_srcset_to_content_image",
"(",
"$",
"image",
",",
"$",
"image_id",
")",
"{",
"return",
"preg_replace_callback",
"(",
"'@(<img decoding=\"async\"[^>]*?)srcset=\"([^\"]+?)\"([^>]*?>)@m'",
",",
"function",
"(",
"$",
"matches",
")",
"use",
"(",
"$",
"image_id",
")",
"{",
"return",
"sprintf",
"(",
"'%s srcset=\"\" data-srcset=\"%s\" %s'",
",",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"matches",
"[",
"2",
"]",
",",
"$",
"matches",
"[",
"3",
"]",
")",
";",
"}",
",",
"$",
"image",
")",
";",
"}"
] | Add data-srcset to content image
@param string $image
@param int $image_id
@return string | [
"Add",
"data",
"-",
"srcset",
"to",
"content",
"image"
] | 219963582b592eef4bde6cdd4ed1cf0dc71a6114 | https://github.com/inc2734/wp-page-speed-optimization/blob/219963582b592eef4bde6cdd4ed1cf0dc71a6114/src/App/Controller/LazyLoad.php#L183-L196 | train |
Wedeto/HTTP | src/Forms/Binder.php | Binder.createFormForModel | public function createFormForModel(string $classname, DAO $dao)
{
if (!is_a($classname, Model::class, true))
throw new \InvalidArgumentException("Not a valid Model class provided");
$form = new Form($classname);
$refl = new ReflectionClass($classname);
$fields = $this->getAnnotatedFields($refl, []);
$columns = $dao->getColumns();
foreach ($columns as $name => $coldef)
{
if (isset($fields[$name]))
continue;
// Ignore serial columns
if ($coldef->getSerial())
continue;
$validator = function ($value) use ($classname, $coldef)
{
return $classname::validate($coldef, $value);
};
$type = new Validator(Type::VALIDATE_CUSTOM, ['custom' => $validator]);
$field = new FormField($name, $type, 'text', null);
$fields[$name] = $field;
}
foreach ($fields as $name => $field)
$form->add($field);
$this->addFormValidators($refl, [], $form);
return $form;
} | php | public function createFormForModel(string $classname, DAO $dao)
{
if (!is_a($classname, Model::class, true))
throw new \InvalidArgumentException("Not a valid Model class provided");
$form = new Form($classname);
$refl = new ReflectionClass($classname);
$fields = $this->getAnnotatedFields($refl, []);
$columns = $dao->getColumns();
foreach ($columns as $name => $coldef)
{
if (isset($fields[$name]))
continue;
// Ignore serial columns
if ($coldef->getSerial())
continue;
$validator = function ($value) use ($classname, $coldef)
{
return $classname::validate($coldef, $value);
};
$type = new Validator(Type::VALIDATE_CUSTOM, ['custom' => $validator]);
$field = new FormField($name, $type, 'text', null);
$fields[$name] = $field;
}
foreach ($fields as $name => $field)
$form->add($field);
$this->addFormValidators($refl, [], $form);
return $form;
} | [
"public",
"function",
"createFormForModel",
"(",
"string",
"$",
"classname",
",",
"DAO",
"$",
"dao",
")",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"classname",
",",
"Model",
"::",
"class",
",",
"true",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Not a valid Model class provided\"",
")",
";",
"$",
"form",
"=",
"new",
"Form",
"(",
"$",
"classname",
")",
";",
"$",
"refl",
"=",
"new",
"ReflectionClass",
"(",
"$",
"classname",
")",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"getAnnotatedFields",
"(",
"$",
"refl",
",",
"[",
"]",
")",
";",
"$",
"columns",
"=",
"$",
"dao",
"->",
"getColumns",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"name",
"=>",
"$",
"coldef",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"fields",
"[",
"$",
"name",
"]",
")",
")",
"continue",
";",
"// Ignore serial columns",
"if",
"(",
"$",
"coldef",
"->",
"getSerial",
"(",
")",
")",
"continue",
";",
"$",
"validator",
"=",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"classname",
",",
"$",
"coldef",
")",
"{",
"return",
"$",
"classname",
"::",
"validate",
"(",
"$",
"coldef",
",",
"$",
"value",
")",
";",
"}",
";",
"$",
"type",
"=",
"new",
"Validator",
"(",
"Type",
"::",
"VALIDATE_CUSTOM",
",",
"[",
"'custom'",
"=>",
"$",
"validator",
"]",
")",
";",
"$",
"field",
"=",
"new",
"FormField",
"(",
"$",
"name",
",",
"$",
"type",
",",
"'text'",
",",
"null",
")",
";",
"$",
"fields",
"[",
"$",
"name",
"]",
"=",
"$",
"field",
";",
"}",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"name",
"=>",
"$",
"field",
")",
"$",
"form",
"->",
"add",
"(",
"$",
"field",
")",
";",
"$",
"this",
"->",
"addFormValidators",
"(",
"$",
"refl",
",",
"[",
"]",
",",
"$",
"form",
")",
";",
"return",
"$",
"form",
";",
"}"
] | Create a form based on a database model
@param string $classname The name of the Model class
@param DAO $dao The DAO that provides more information about the class | [
"Create",
"a",
"form",
"based",
"on",
"a",
"database",
"model"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Forms/Binder.php#L56-L91 | train |
Wedeto/HTTP | src/Forms/Binder.php | Binder.createFormForObject | public function createFormForObject(string $formclass)
{
if (!is_a($formclass, BaseForm::class, true))
throw new \InvalidArgumentException("Not a valid BaseForm class provided");
$form = new Form($formclass);
$refl = new \ReflectionClass($formclass);
$field_validators = $formclass::listFieldValidators();
$fields = $this->getAnnotatedFields($refl, $field_validators);
foreach ($fields as $name => $field)
$form->add($field);
$this->addFormValidators($refl, [$formclass, 'listFormValidators'](), $form);
return $form;
} | php | public function createFormForObject(string $formclass)
{
if (!is_a($formclass, BaseForm::class, true))
throw new \InvalidArgumentException("Not a valid BaseForm class provided");
$form = new Form($formclass);
$refl = new \ReflectionClass($formclass);
$field_validators = $formclass::listFieldValidators();
$fields = $this->getAnnotatedFields($refl, $field_validators);
foreach ($fields as $name => $field)
$form->add($field);
$this->addFormValidators($refl, [$formclass, 'listFormValidators'](), $form);
return $form;
} | [
"public",
"function",
"createFormForObject",
"(",
"string",
"$",
"formclass",
")",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"formclass",
",",
"BaseForm",
"::",
"class",
",",
"true",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Not a valid BaseForm class provided\"",
")",
";",
"$",
"form",
"=",
"new",
"Form",
"(",
"$",
"formclass",
")",
";",
"$",
"refl",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"formclass",
")",
";",
"$",
"field_validators",
"=",
"$",
"formclass",
"::",
"listFieldValidators",
"(",
")",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"getAnnotatedFields",
"(",
"$",
"refl",
",",
"$",
"field_validators",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"name",
"=>",
"$",
"field",
")",
"$",
"form",
"->",
"add",
"(",
"$",
"field",
")",
";",
"$",
"this",
"->",
"addFormValidators",
"(",
"$",
"refl",
",",
"[",
"$",
"formclass",
",",
"'listFormValidators'",
"]",
"(",
")",
",",
"$",
"form",
")",
";",
"return",
"$",
"form",
";",
"}"
] | Create a form using reflection on a POPO.
The class is inspected for public properties. All properties that have
annotations in doc comments are used in the form, unless they have an
ignore annotation.
Supported annations are @var to provide the type. When @var is array,
you need to specify the type of the elements in @element.
You can specify more validators for the field by adding @validator annotations.
Each annotation must be a Fully Qualified Class Name of a class can be be instantiated
using Wedeto\DI. A default constructor will suffice for this.
If you need more complex validators, you can also override the static listFieldValidators
method to return an array with field names as key and arrays of validators as value.
The class doc comment is used to assign validators to the form as a whole, using the
@validator annotation. The same rules for field validators apply. You can provide more
complex validators by overriding the static listFormValidators method.
@param string $formclass The class to build a form from
@return FormData The constructed form
@see Wedeto\Util\Validator | [
"Create",
"a",
"form",
"using",
"reflection",
"on",
"a",
"POPO",
"."
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Forms/Binder.php#L119-L134 | train |
Wedeto/HTTP | src/Forms/Binder.php | Binder.addFormValidators | protected function addFormValidators(ReflectionClass $refl, array $additional_validators, Form $form)
{
$classdoc = $refl->getDocComment();
if (!empty($classdoc))
{
$classdoc = new DocComment($classdoc);
foreach ($classdoc->getAnnotations('validator') as $validator)
{
if (!is_a($validator, Validator::class, true))
throw new BinderException("Invalid validator class: $validator");
$validator = DI::getInjector()->getInstance($validator);
$form->addFormValidator($validator);
}
}
foreach ($additional_validators as $validator)
$form->addFormValidator($validator);
return $form;
} | php | protected function addFormValidators(ReflectionClass $refl, array $additional_validators, Form $form)
{
$classdoc = $refl->getDocComment();
if (!empty($classdoc))
{
$classdoc = new DocComment($classdoc);
foreach ($classdoc->getAnnotations('validator') as $validator)
{
if (!is_a($validator, Validator::class, true))
throw new BinderException("Invalid validator class: $validator");
$validator = DI::getInjector()->getInstance($validator);
$form->addFormValidator($validator);
}
}
foreach ($additional_validators as $validator)
$form->addFormValidator($validator);
return $form;
} | [
"protected",
"function",
"addFormValidators",
"(",
"ReflectionClass",
"$",
"refl",
",",
"array",
"$",
"additional_validators",
",",
"Form",
"$",
"form",
")",
"{",
"$",
"classdoc",
"=",
"$",
"refl",
"->",
"getDocComment",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"classdoc",
")",
")",
"{",
"$",
"classdoc",
"=",
"new",
"DocComment",
"(",
"$",
"classdoc",
")",
";",
"foreach",
"(",
"$",
"classdoc",
"->",
"getAnnotations",
"(",
"'validator'",
")",
"as",
"$",
"validator",
")",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"validator",
",",
"Validator",
"::",
"class",
",",
"true",
")",
")",
"throw",
"new",
"BinderException",
"(",
"\"Invalid validator class: $validator\"",
")",
";",
"$",
"validator",
"=",
"DI",
"::",
"getInjector",
"(",
")",
"->",
"getInstance",
"(",
"$",
"validator",
")",
";",
"$",
"form",
"->",
"addFormValidator",
"(",
"$",
"validator",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"additional_validators",
"as",
"$",
"validator",
")",
"$",
"form",
"->",
"addFormValidator",
"(",
"$",
"validator",
")",
";",
"return",
"$",
"form",
";",
"}"
] | Add validators for the whole form
@param ReflectionClass The reflection class to get validators from
@param array $additional_validators Validators to add
@param Form $form The form to add the validators to | [
"Add",
"validators",
"for",
"the",
"whole",
"form"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Forms/Binder.php#L143-L162 | train |
Wedeto/HTTP | src/Forms/Binder.php | Binder.getAnnotatedFields | protected function getAnnotatedFields(ReflectionClass $class, array $field_validators)
{
$properties = $class->getProperties(ReflectionProperty::IS_PUBLIC);
$fields = [];
foreach ($properties as $prop)
{
$name = $prop->getName();
$comment = $prop->getDocComment();
if ($comment === false)
continue;
$annotations = new DocComment($comment);
if (!empty($annotations->getAnnotations("ignore")))
continue;
$var = $annotations->getAnnotationTokens("var");
if (count($var) === 0 || empty($var[0]))
throw new BinderException("No type defined for $prop");
$base_tp = reset($var);
$element_tp = $base_tp === "array" ? $annotations->getAnnotationTokens("element") : [];
$element_tp = reset($element_tp);
$search_type = $element_tp ?: $base_tp;
$const_name = Type::class . '::' . strtoupper($search_type);
$transformer = null;
if (defined($const_name))
{
$type = new Type(constant($const_name), ['unstrict' => true]);
}
else
{
$type = new Validator(Type::OBJECT, ['instanceof' => $search_type]);
$transformer = TransformStore::getInstance()->getTransformer($search_type);
}
$fieldname = !empty($element_tp) ? $name . '[]' : $name;
$field = new FormField($fieldname, $type, 'text', '');
if ($transformer)
$field->setTransformer($transformer);
foreach ($annotations->getAnnotations('validator') as $valtype)
{
$instance = $this->getValidatorInstance($valtype);
$field->addValidator($instance);
}
$additional = $field_validators[$name] ?? [];
foreach ($additional as $validator)
$field->addValidator($validator);
$error_override = $annotations->getAnnotation('error', true);
if (!empty($error_override))
$field->setFixedError(['msg' => $error_override]);
$fields[$name] = $field;
}
return $fields;
} | php | protected function getAnnotatedFields(ReflectionClass $class, array $field_validators)
{
$properties = $class->getProperties(ReflectionProperty::IS_PUBLIC);
$fields = [];
foreach ($properties as $prop)
{
$name = $prop->getName();
$comment = $prop->getDocComment();
if ($comment === false)
continue;
$annotations = new DocComment($comment);
if (!empty($annotations->getAnnotations("ignore")))
continue;
$var = $annotations->getAnnotationTokens("var");
if (count($var) === 0 || empty($var[0]))
throw new BinderException("No type defined for $prop");
$base_tp = reset($var);
$element_tp = $base_tp === "array" ? $annotations->getAnnotationTokens("element") : [];
$element_tp = reset($element_tp);
$search_type = $element_tp ?: $base_tp;
$const_name = Type::class . '::' . strtoupper($search_type);
$transformer = null;
if (defined($const_name))
{
$type = new Type(constant($const_name), ['unstrict' => true]);
}
else
{
$type = new Validator(Type::OBJECT, ['instanceof' => $search_type]);
$transformer = TransformStore::getInstance()->getTransformer($search_type);
}
$fieldname = !empty($element_tp) ? $name . '[]' : $name;
$field = new FormField($fieldname, $type, 'text', '');
if ($transformer)
$field->setTransformer($transformer);
foreach ($annotations->getAnnotations('validator') as $valtype)
{
$instance = $this->getValidatorInstance($valtype);
$field->addValidator($instance);
}
$additional = $field_validators[$name] ?? [];
foreach ($additional as $validator)
$field->addValidator($validator);
$error_override = $annotations->getAnnotation('error', true);
if (!empty($error_override))
$field->setFixedError(['msg' => $error_override]);
$fields[$name] = $field;
}
return $fields;
} | [
"protected",
"function",
"getAnnotatedFields",
"(",
"ReflectionClass",
"$",
"class",
",",
"array",
"$",
"field_validators",
")",
"{",
"$",
"properties",
"=",
"$",
"class",
"->",
"getProperties",
"(",
"ReflectionProperty",
"::",
"IS_PUBLIC",
")",
";",
"$",
"fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"prop",
")",
"{",
"$",
"name",
"=",
"$",
"prop",
"->",
"getName",
"(",
")",
";",
"$",
"comment",
"=",
"$",
"prop",
"->",
"getDocComment",
"(",
")",
";",
"if",
"(",
"$",
"comment",
"===",
"false",
")",
"continue",
";",
"$",
"annotations",
"=",
"new",
"DocComment",
"(",
"$",
"comment",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"annotations",
"->",
"getAnnotations",
"(",
"\"ignore\"",
")",
")",
")",
"continue",
";",
"$",
"var",
"=",
"$",
"annotations",
"->",
"getAnnotationTokens",
"(",
"\"var\"",
")",
";",
"if",
"(",
"count",
"(",
"$",
"var",
")",
"===",
"0",
"||",
"empty",
"(",
"$",
"var",
"[",
"0",
"]",
")",
")",
"throw",
"new",
"BinderException",
"(",
"\"No type defined for $prop\"",
")",
";",
"$",
"base_tp",
"=",
"reset",
"(",
"$",
"var",
")",
";",
"$",
"element_tp",
"=",
"$",
"base_tp",
"===",
"\"array\"",
"?",
"$",
"annotations",
"->",
"getAnnotationTokens",
"(",
"\"element\"",
")",
":",
"[",
"]",
";",
"$",
"element_tp",
"=",
"reset",
"(",
"$",
"element_tp",
")",
";",
"$",
"search_type",
"=",
"$",
"element_tp",
"?",
":",
"$",
"base_tp",
";",
"$",
"const_name",
"=",
"Type",
"::",
"class",
".",
"'::'",
".",
"strtoupper",
"(",
"$",
"search_type",
")",
";",
"$",
"transformer",
"=",
"null",
";",
"if",
"(",
"defined",
"(",
"$",
"const_name",
")",
")",
"{",
"$",
"type",
"=",
"new",
"Type",
"(",
"constant",
"(",
"$",
"const_name",
")",
",",
"[",
"'unstrict'",
"=>",
"true",
"]",
")",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"new",
"Validator",
"(",
"Type",
"::",
"OBJECT",
",",
"[",
"'instanceof'",
"=>",
"$",
"search_type",
"]",
")",
";",
"$",
"transformer",
"=",
"TransformStore",
"::",
"getInstance",
"(",
")",
"->",
"getTransformer",
"(",
"$",
"search_type",
")",
";",
"}",
"$",
"fieldname",
"=",
"!",
"empty",
"(",
"$",
"element_tp",
")",
"?",
"$",
"name",
".",
"'[]'",
":",
"$",
"name",
";",
"$",
"field",
"=",
"new",
"FormField",
"(",
"$",
"fieldname",
",",
"$",
"type",
",",
"'text'",
",",
"''",
")",
";",
"if",
"(",
"$",
"transformer",
")",
"$",
"field",
"->",
"setTransformer",
"(",
"$",
"transformer",
")",
";",
"foreach",
"(",
"$",
"annotations",
"->",
"getAnnotations",
"(",
"'validator'",
")",
"as",
"$",
"valtype",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"getValidatorInstance",
"(",
"$",
"valtype",
")",
";",
"$",
"field",
"->",
"addValidator",
"(",
"$",
"instance",
")",
";",
"}",
"$",
"additional",
"=",
"$",
"field_validators",
"[",
"$",
"name",
"]",
"??",
"[",
"]",
";",
"foreach",
"(",
"$",
"additional",
"as",
"$",
"validator",
")",
"$",
"field",
"->",
"addValidator",
"(",
"$",
"validator",
")",
";",
"$",
"error_override",
"=",
"$",
"annotations",
"->",
"getAnnotation",
"(",
"'error'",
",",
"true",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"error_override",
")",
")",
"$",
"field",
"->",
"setFixedError",
"(",
"[",
"'msg'",
"=>",
"$",
"error_override",
"]",
")",
";",
"$",
"fields",
"[",
"$",
"name",
"]",
"=",
"$",
"field",
";",
"}",
"return",
"$",
"fields",
";",
"}"
] | Iterate over all properties and add their values to the form
@param ReflectionClass $class The class to extract properties from
@param array $field_validator Additional validators | [
"Iterate",
"over",
"all",
"properties",
"and",
"add",
"their",
"values",
"to",
"the",
"form"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Forms/Binder.php#L170-L230 | train |
Wedeto/HTTP | src/Forms/Binder.php | Binder.bindValue | protected function bindValue(FormElement $element, ReflectionClass $refl, $instance)
{
$name = $element->getName(true);
if (substr($name, 0, 1) === "_")
return;
$value = $element->getValue();
$method_name = "set" . strtoupper(substr($name, 0, 1)) . substr($name, 1);
if ($refl->hasMethod($method_name))
{
$setter = $refl->getMethod($method_name);
$params = $setter->getParameters();
if (count($params) !== 1)
throw new BinderException("Setter $method_name should take exactly one argument");
$setter->invoke($instance, $value);
}
elseif ($refl->isSubclassOf(Model::class))
{
// Model provides a setField method that should be able to set all parameters
$instance->setField($name, $element->getValue());
}
else
{
// No known accessors, the property should be settable directly
if (!$refl->hasProperty($name))
throw new BinderException("There is no attribute $name on class {$refl->getName()}");
$property = $refl->getProperty($name);
if (!$property->isPublic() || $property->isStatic())
throw new BinderException("Property $name should be public and non-static");
$property->setValue($instance, $value);
}
} | php | protected function bindValue(FormElement $element, ReflectionClass $refl, $instance)
{
$name = $element->getName(true);
if (substr($name, 0, 1) === "_")
return;
$value = $element->getValue();
$method_name = "set" . strtoupper(substr($name, 0, 1)) . substr($name, 1);
if ($refl->hasMethod($method_name))
{
$setter = $refl->getMethod($method_name);
$params = $setter->getParameters();
if (count($params) !== 1)
throw new BinderException("Setter $method_name should take exactly one argument");
$setter->invoke($instance, $value);
}
elseif ($refl->isSubclassOf(Model::class))
{
// Model provides a setField method that should be able to set all parameters
$instance->setField($name, $element->getValue());
}
else
{
// No known accessors, the property should be settable directly
if (!$refl->hasProperty($name))
throw new BinderException("There is no attribute $name on class {$refl->getName()}");
$property = $refl->getProperty($name);
if (!$property->isPublic() || $property->isStatic())
throw new BinderException("Property $name should be public and non-static");
$property->setValue($instance, $value);
}
} | [
"protected",
"function",
"bindValue",
"(",
"FormElement",
"$",
"element",
",",
"ReflectionClass",
"$",
"refl",
",",
"$",
"instance",
")",
"{",
"$",
"name",
"=",
"$",
"element",
"->",
"getName",
"(",
"true",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"1",
")",
"===",
"\"_\"",
")",
"return",
";",
"$",
"value",
"=",
"$",
"element",
"->",
"getValue",
"(",
")",
";",
"$",
"method_name",
"=",
"\"set\"",
".",
"strtoupper",
"(",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"1",
")",
")",
".",
"substr",
"(",
"$",
"name",
",",
"1",
")",
";",
"if",
"(",
"$",
"refl",
"->",
"hasMethod",
"(",
"$",
"method_name",
")",
")",
"{",
"$",
"setter",
"=",
"$",
"refl",
"->",
"getMethod",
"(",
"$",
"method_name",
")",
";",
"$",
"params",
"=",
"$",
"setter",
"->",
"getParameters",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"params",
")",
"!==",
"1",
")",
"throw",
"new",
"BinderException",
"(",
"\"Setter $method_name should take exactly one argument\"",
")",
";",
"$",
"setter",
"->",
"invoke",
"(",
"$",
"instance",
",",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"$",
"refl",
"->",
"isSubclassOf",
"(",
"Model",
"::",
"class",
")",
")",
"{",
"// Model provides a setField method that should be able to set all parameters",
"$",
"instance",
"->",
"setField",
"(",
"$",
"name",
",",
"$",
"element",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"else",
"{",
"// No known accessors, the property should be settable directly",
"if",
"(",
"!",
"$",
"refl",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"throw",
"new",
"BinderException",
"(",
"\"There is no attribute $name on class {$refl->getName()}\"",
")",
";",
"$",
"property",
"=",
"$",
"refl",
"->",
"getProperty",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"property",
"->",
"isPublic",
"(",
")",
"||",
"$",
"property",
"->",
"isStatic",
"(",
")",
")",
"throw",
"new",
"BinderException",
"(",
"\"Property $name should be public and non-static\"",
")",
";",
"$",
"property",
"->",
"setValue",
"(",
"$",
"instance",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Set a value from a form to an instance of a class
@param FormElement $element The element containing the value
@param ReflectionClass $refl The ReflectionClass of the object being set
@param object $instance The object being set | [
"Set",
"a",
"value",
"from",
"a",
"form",
"to",
"an",
"instance",
"of",
"a",
"class"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Forms/Binder.php#L393-L427 | train |
PatrolServer/patrolsdk-php | lib/HttpClient.php | HttpClient.buildUrl | private function buildUrl($path) {
$key = $this->patrol->getApiKey();
$secret = $this->patrol->getApiSecret();
$base = $this->patrol->apiBase;
$url = $base . '/' . $path . '?key=' . $key . '&secret=' . $secret;
if ($this->method === "get" && !is_null($this->payload)) {
$query = http_build_query($this->payload);
$url .= '&' . $query;
}
if (count($this->scopes)) {
$scopes = implode(',', $this->scopes);
if ($scopes) {
$url .= '&scope=' . $scopes;
}
}
$this->url = $url;
} | php | private function buildUrl($path) {
$key = $this->patrol->getApiKey();
$secret = $this->patrol->getApiSecret();
$base = $this->patrol->apiBase;
$url = $base . '/' . $path . '?key=' . $key . '&secret=' . $secret;
if ($this->method === "get" && !is_null($this->payload)) {
$query = http_build_query($this->payload);
$url .= '&' . $query;
}
if (count($this->scopes)) {
$scopes = implode(',', $this->scopes);
if ($scopes) {
$url .= '&scope=' . $scopes;
}
}
$this->url = $url;
} | [
"private",
"function",
"buildUrl",
"(",
"$",
"path",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"patrol",
"->",
"getApiKey",
"(",
")",
";",
"$",
"secret",
"=",
"$",
"this",
"->",
"patrol",
"->",
"getApiSecret",
"(",
")",
";",
"$",
"base",
"=",
"$",
"this",
"->",
"patrol",
"->",
"apiBase",
";",
"$",
"url",
"=",
"$",
"base",
".",
"'/'",
".",
"$",
"path",
".",
"'?key='",
".",
"$",
"key",
".",
"'&secret='",
".",
"$",
"secret",
";",
"if",
"(",
"$",
"this",
"->",
"method",
"===",
"\"get\"",
"&&",
"!",
"is_null",
"(",
"$",
"this",
"->",
"payload",
")",
")",
"{",
"$",
"query",
"=",
"http_build_query",
"(",
"$",
"this",
"->",
"payload",
")",
";",
"$",
"url",
".=",
"'&'",
".",
"$",
"query",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"scopes",
")",
")",
"{",
"$",
"scopes",
"=",
"implode",
"(",
"','",
",",
"$",
"this",
"->",
"scopes",
")",
";",
"if",
"(",
"$",
"scopes",
")",
"{",
"$",
"url",
".=",
"'&scope='",
".",
"$",
"scopes",
";",
"}",
"}",
"$",
"this",
"->",
"url",
"=",
"$",
"url",
";",
"}"
] | Takes a path and builds the URL with the given key and secret
@param string $path | [
"Takes",
"a",
"path",
"and",
"builds",
"the",
"URL",
"with",
"the",
"given",
"key",
"and",
"secret"
] | 2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2 | https://github.com/PatrolServer/patrolsdk-php/blob/2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2/lib/HttpClient.php#L44-L65 | train |
MinyFramework/Miny-Core | src/Utils/StringUtils.php | StringUtils.compare | public static function compare($known, $user)
{
if (strlen($known) !== strlen($user)) {
return false;
}
$result = 0;
$knownLength = strlen($known);
for ($i = 0; $i < $knownLength; $i++) {
$result |= ord($known[$i]) ^ ord($user[$i]);
}
return $result == 0;
} | php | public static function compare($known, $user)
{
if (strlen($known) !== strlen($user)) {
return false;
}
$result = 0;
$knownLength = strlen($known);
for ($i = 0; $i < $knownLength; $i++) {
$result |= ord($known[$i]) ^ ord($user[$i]);
}
return $result == 0;
} | [
"public",
"static",
"function",
"compare",
"(",
"$",
"known",
",",
"$",
"user",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"known",
")",
"!==",
"strlen",
"(",
"$",
"user",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"result",
"=",
"0",
";",
"$",
"knownLength",
"=",
"strlen",
"(",
"$",
"known",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"knownLength",
";",
"$",
"i",
"++",
")",
"{",
"$",
"result",
"|=",
"ord",
"(",
"$",
"known",
"[",
"$",
"i",
"]",
")",
"^",
"ord",
"(",
"$",
"user",
"[",
"$",
"i",
"]",
")",
";",
"}",
"return",
"$",
"result",
"==",
"0",
";",
"}"
] | Compares two strings securely.
@link http://blog.astrumfutura.com/2010/10/nanosecond-scale-remote-timing-attacks-on-php-applications-time-to-take-them-seriously/ Implementation source
@param string $known
@param string $user
@return boolean | [
"Compares",
"two",
"strings",
"securely",
"."
] | a1bfe801a44a49cf01f16411cb4663473e9c827c | https://github.com/MinyFramework/Miny-Core/blob/a1bfe801a44a49cf01f16411cb4663473e9c827c/src/Utils/StringUtils.php#L30-L42 | train |
ammarfaizi2/icetea-framework | src/System/Crayner.php | Crayner._run | public function _run()
{
if (defined("NOT_FOUND")) {
(new Controller())->load->error(404);
}
if (Configer::manualRoute()) {
$router = Router::getInstance($this->segments);
Configer::loadRoutes();
try {
if ($action = $router->run()) {
if (is_array($action)) {
$class = "App\\Controllers\\{$action['controller']}";
if (class_exists($class) and $class = new $class() and is_callable(array($class, $action['method']))) {
$class->{$action['method']}();
} else {
(new Controller())->load->error(404);
}
} else {
(new Controller())->load->error(404);
}
} else {
(new Controller())->load->error(404);
}
} catch (MethodNotAllowedHttpException $e) {
print "MethodNotAllowedHttpException : ".$e->getMessage();
}
die;
}
if (Configer::automaticRoute()) {
$this->firstSegment = empty($this->firstSegment) ? Configer::defaultRoute() : $this->firstSegment;
$this->secondSegment = empty($this->secondSegment) ? Configer::defaultMethod() : $this->secondSegment;
$class = "App\\Controllers\\{$this->firstSegment}";
if (class_exists($class) and $class = new $class() and is_callable(array($class, $this->secondSegment))) {
$class->{$this->secondSegment}();
} else {
(new Controller())->load->error(404);
}
}
} | php | public function _run()
{
if (defined("NOT_FOUND")) {
(new Controller())->load->error(404);
}
if (Configer::manualRoute()) {
$router = Router::getInstance($this->segments);
Configer::loadRoutes();
try {
if ($action = $router->run()) {
if (is_array($action)) {
$class = "App\\Controllers\\{$action['controller']}";
if (class_exists($class) and $class = new $class() and is_callable(array($class, $action['method']))) {
$class->{$action['method']}();
} else {
(new Controller())->load->error(404);
}
} else {
(new Controller())->load->error(404);
}
} else {
(new Controller())->load->error(404);
}
} catch (MethodNotAllowedHttpException $e) {
print "MethodNotAllowedHttpException : ".$e->getMessage();
}
die;
}
if (Configer::automaticRoute()) {
$this->firstSegment = empty($this->firstSegment) ? Configer::defaultRoute() : $this->firstSegment;
$this->secondSegment = empty($this->secondSegment) ? Configer::defaultMethod() : $this->secondSegment;
$class = "App\\Controllers\\{$this->firstSegment}";
if (class_exists($class) and $class = new $class() and is_callable(array($class, $this->secondSegment))) {
$class->{$this->secondSegment}();
} else {
(new Controller())->load->error(404);
}
}
} | [
"public",
"function",
"_run",
"(",
")",
"{",
"if",
"(",
"defined",
"(",
"\"NOT_FOUND\"",
")",
")",
"{",
"(",
"new",
"Controller",
"(",
")",
")",
"->",
"load",
"->",
"error",
"(",
"404",
")",
";",
"}",
"if",
"(",
"Configer",
"::",
"manualRoute",
"(",
")",
")",
"{",
"$",
"router",
"=",
"Router",
"::",
"getInstance",
"(",
"$",
"this",
"->",
"segments",
")",
";",
"Configer",
"::",
"loadRoutes",
"(",
")",
";",
"try",
"{",
"if",
"(",
"$",
"action",
"=",
"$",
"router",
"->",
"run",
"(",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"action",
")",
")",
"{",
"$",
"class",
"=",
"\"App\\\\Controllers\\\\{$action['controller']}\"",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
"and",
"$",
"class",
"=",
"new",
"$",
"class",
"(",
")",
"and",
"is_callable",
"(",
"array",
"(",
"$",
"class",
",",
"$",
"action",
"[",
"'method'",
"]",
")",
")",
")",
"{",
"$",
"class",
"->",
"{",
"$",
"action",
"[",
"'method'",
"]",
"}",
"(",
")",
";",
"}",
"else",
"{",
"(",
"new",
"Controller",
"(",
")",
")",
"->",
"load",
"->",
"error",
"(",
"404",
")",
";",
"}",
"}",
"else",
"{",
"(",
"new",
"Controller",
"(",
")",
")",
"->",
"load",
"->",
"error",
"(",
"404",
")",
";",
"}",
"}",
"else",
"{",
"(",
"new",
"Controller",
"(",
")",
")",
"->",
"load",
"->",
"error",
"(",
"404",
")",
";",
"}",
"}",
"catch",
"(",
"MethodNotAllowedHttpException",
"$",
"e",
")",
"{",
"print",
"\"MethodNotAllowedHttpException : \"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"die",
";",
"}",
"if",
"(",
"Configer",
"::",
"automaticRoute",
"(",
")",
")",
"{",
"$",
"this",
"->",
"firstSegment",
"=",
"empty",
"(",
"$",
"this",
"->",
"firstSegment",
")",
"?",
"Configer",
"::",
"defaultRoute",
"(",
")",
":",
"$",
"this",
"->",
"firstSegment",
";",
"$",
"this",
"->",
"secondSegment",
"=",
"empty",
"(",
"$",
"this",
"->",
"secondSegment",
")",
"?",
"Configer",
"::",
"defaultMethod",
"(",
")",
":",
"$",
"this",
"->",
"secondSegment",
";",
"$",
"class",
"=",
"\"App\\\\Controllers\\\\{$this->firstSegment}\"",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
"and",
"$",
"class",
"=",
"new",
"$",
"class",
"(",
")",
"and",
"is_callable",
"(",
"array",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"secondSegment",
")",
")",
")",
"{",
"$",
"class",
"->",
"{",
"$",
"this",
"->",
"secondSegment",
"}",
"(",
")",
";",
"}",
"else",
"{",
"(",
"new",
"Controller",
"(",
")",
")",
"->",
"load",
"->",
"error",
"(",
"404",
")",
";",
"}",
"}",
"}"
] | Here we go... | [
"Here",
"we",
"go",
"..."
] | dedd832846c3e69b429b18b8612fae50881af180 | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner.php#L71-L109 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Domain/Action/DynamicActionTrait.php | DynamicActionTrait.setIfDefined | protected function setIfDefined($object, $field)
{
$propertyAccessor = $this->getPropertyAccessor();
if (!$this->_has($field)) {
return $propertyAccessor->isReadable($object, $field) ?
$propertyAccessor->getValue($object, $field) :
null
;
}
$propertyAccessor->setValue(
$object,
$field,
$value = $this->_get($field)
);
return $value;
} | php | protected function setIfDefined($object, $field)
{
$propertyAccessor = $this->getPropertyAccessor();
if (!$this->_has($field)) {
return $propertyAccessor->isReadable($object, $field) ?
$propertyAccessor->getValue($object, $field) :
null
;
}
$propertyAccessor->setValue(
$object,
$field,
$value = $this->_get($field)
);
return $value;
} | [
"protected",
"function",
"setIfDefined",
"(",
"$",
"object",
",",
"$",
"field",
")",
"{",
"$",
"propertyAccessor",
"=",
"$",
"this",
"->",
"getPropertyAccessor",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_has",
"(",
"$",
"field",
")",
")",
"{",
"return",
"$",
"propertyAccessor",
"->",
"isReadable",
"(",
"$",
"object",
",",
"$",
"field",
")",
"?",
"$",
"propertyAccessor",
"->",
"getValue",
"(",
"$",
"object",
",",
"$",
"field",
")",
":",
"null",
";",
"}",
"$",
"propertyAccessor",
"->",
"setValue",
"(",
"$",
"object",
",",
"$",
"field",
",",
"$",
"value",
"=",
"$",
"this",
"->",
"_get",
"(",
"$",
"field",
")",
")",
";",
"return",
"$",
"value",
";",
"}"
] | Define given field on given object, if accessible
@param mixed $object
@param string $field
@return mixed|null | [
"Define",
"given",
"field",
"on",
"given",
"object",
"if",
"accessible"
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Domain/Action/DynamicActionTrait.php#L125-L142 | train |
Danack/Jig | src/Jig/Converter/ParsedTemplate.php | ParsedTemplate.addLocalVariable | public function addLocalVariable($localVariable)
{
$varName = $localVariable;
if (strpos($varName, '$') === 0) {
$varName = substr($localVariable, 1);
}
if (in_array($varName, $this->localVariables) === false) {
$this->localVariables[] = $varName;
}
} | php | public function addLocalVariable($localVariable)
{
$varName = $localVariable;
if (strpos($varName, '$') === 0) {
$varName = substr($localVariable, 1);
}
if (in_array($varName, $this->localVariables) === false) {
$this->localVariables[] = $varName;
}
} | [
"public",
"function",
"addLocalVariable",
"(",
"$",
"localVariable",
")",
"{",
"$",
"varName",
"=",
"$",
"localVariable",
";",
"if",
"(",
"strpos",
"(",
"$",
"varName",
",",
"'$'",
")",
"===",
"0",
")",
"{",
"$",
"varName",
"=",
"substr",
"(",
"$",
"localVariable",
",",
"1",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"varName",
",",
"$",
"this",
"->",
"localVariables",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"localVariables",
"[",
"]",
"=",
"$",
"varName",
";",
"}",
"}"
] | Add a local variable so that any usage of it doesn't
trigger trying to fetch it from the ViewModel
@param $localVariable | [
"Add",
"a",
"local",
"variable",
"so",
"that",
"any",
"usage",
"of",
"it",
"doesn",
"t",
"trigger",
"trying",
"to",
"fetch",
"it",
"from",
"the",
"ViewModel"
] | b11106bc7d634add9873bf246eda1dadb059ed7a | https://github.com/Danack/Jig/blob/b11106bc7d634add9873bf246eda1dadb059ed7a/src/Jig/Converter/ParsedTemplate.php#L198-L209 | train |
Danack/Jig | src/Jig/Converter/ParsedTemplate.php | ParsedTemplate.getNamespace | public static function getNamespace($namespaceClass)
{
if (is_object($namespaceClass) === true) {
$namespaceClass = get_class($namespaceClass);
}
$lastSlashPosition = mb_strrpos($namespaceClass, '\\');
if ($lastSlashPosition !== false) {
return mb_substr($namespaceClass, 0, $lastSlashPosition);
}
return "";
} | php | public static function getNamespace($namespaceClass)
{
if (is_object($namespaceClass) === true) {
$namespaceClass = get_class($namespaceClass);
}
$lastSlashPosition = mb_strrpos($namespaceClass, '\\');
if ($lastSlashPosition !== false) {
return mb_substr($namespaceClass, 0, $lastSlashPosition);
}
return "";
} | [
"public",
"static",
"function",
"getNamespace",
"(",
"$",
"namespaceClass",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"namespaceClass",
")",
"===",
"true",
")",
"{",
"$",
"namespaceClass",
"=",
"get_class",
"(",
"$",
"namespaceClass",
")",
";",
"}",
"$",
"lastSlashPosition",
"=",
"mb_strrpos",
"(",
"$",
"namespaceClass",
",",
"'\\\\'",
")",
";",
"if",
"(",
"$",
"lastSlashPosition",
"!==",
"false",
")",
"{",
"return",
"mb_substr",
"(",
"$",
"namespaceClass",
",",
"0",
",",
"$",
"lastSlashPosition",
")",
";",
"}",
"return",
"\"\"",
";",
"}"
] | Get the name space part of a fully namespaced class. Returns empty string
if the class had no namespace part.
@param $namespaceClass
@return string | [
"Get",
"the",
"name",
"space",
"part",
"of",
"a",
"fully",
"namespaced",
"class",
".",
"Returns",
"empty",
"string",
"if",
"the",
"class",
"had",
"no",
"namespace",
"part",
"."
] | b11106bc7d634add9873bf246eda1dadb059ed7a | https://github.com/Danack/Jig/blob/b11106bc7d634add9873bf246eda1dadb059ed7a/src/Jig/Converter/ParsedTemplate.php#L562-L575 | train |
Danack/Jig | src/Jig/Converter/ParsedTemplate.php | ParsedTemplate.getClassName | public static function getClassName($namespaceClass)
{
$lastSlashPosition = mb_strrpos($namespaceClass, '\\');
if ($lastSlashPosition !== false) {
return mb_substr($namespaceClass, $lastSlashPosition + 1);
}
return $namespaceClass;
} | php | public static function getClassName($namespaceClass)
{
$lastSlashPosition = mb_strrpos($namespaceClass, '\\');
if ($lastSlashPosition !== false) {
return mb_substr($namespaceClass, $lastSlashPosition + 1);
}
return $namespaceClass;
} | [
"public",
"static",
"function",
"getClassName",
"(",
"$",
"namespaceClass",
")",
"{",
"$",
"lastSlashPosition",
"=",
"mb_strrpos",
"(",
"$",
"namespaceClass",
",",
"'\\\\'",
")",
";",
"if",
"(",
"$",
"lastSlashPosition",
"!==",
"false",
")",
"{",
"return",
"mb_substr",
"(",
"$",
"namespaceClass",
",",
"$",
"lastSlashPosition",
"+",
"1",
")",
";",
"}",
"return",
"$",
"namespaceClass",
";",
"}"
] | Get the class part of a fully namespaced class name
@param $namespaceClass
@return string | [
"Get",
"the",
"class",
"part",
"of",
"a",
"fully",
"namespaced",
"class",
"name"
] | b11106bc7d634add9873bf246eda1dadb059ed7a | https://github.com/Danack/Jig/blob/b11106bc7d634add9873bf246eda1dadb059ed7a/src/Jig/Converter/ParsedTemplate.php#L591-L600 | train |
Danack/Jig | src/Jig/Converter/ParsedTemplate.php | ParsedTemplate.ensureDirectoryExists | public function ensureDirectoryExists($outputFilename)
{
$directoryName = dirname($outputFilename);
@mkdir($directoryName, 0755, true);
//TODO - double-check umask
if (file_exists($directoryName) === false) {
throw new JigException("Directory $directoryName does not exist and could not be created");
}
} | php | public function ensureDirectoryExists($outputFilename)
{
$directoryName = dirname($outputFilename);
@mkdir($directoryName, 0755, true);
//TODO - double-check umask
if (file_exists($directoryName) === false) {
throw new JigException("Directory $directoryName does not exist and could not be created");
}
} | [
"public",
"function",
"ensureDirectoryExists",
"(",
"$",
"outputFilename",
")",
"{",
"$",
"directoryName",
"=",
"dirname",
"(",
"$",
"outputFilename",
")",
";",
"@",
"mkdir",
"(",
"$",
"directoryName",
",",
"0755",
",",
"true",
")",
";",
"//TODO - double-check umask",
"if",
"(",
"file_exists",
"(",
"$",
"directoryName",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"JigException",
"(",
"\"Directory $directoryName does not exist and could not be created\"",
")",
";",
"}",
"}"
] | ensureDirectoryExists by creating it with 0755 permissions and throwing
an exception if it does not exst after that mkdir call.
@param $outputFilename
@throws JigException | [
"ensureDirectoryExists",
"by",
"creating",
"it",
"with",
"0755",
"permissions",
"and",
"throwing",
"an",
"exception",
"if",
"it",
"does",
"not",
"exst",
"after",
"that",
"mkdir",
"call",
"."
] | b11106bc7d634add9873bf246eda1dadb059ed7a | https://github.com/Danack/Jig/blob/b11106bc7d634add9873bf246eda1dadb059ed7a/src/Jig/Converter/ParsedTemplate.php#L608-L618 | train |
wb-crowdfusion/crowdfusion | system/core/classes/mvc/filters/SlugsFilterer.php | SlugsFilterer.create | public function create()
{
$slug = $this->getParameter('value');
$allowSlashes = StringUtils::strToBool($this->getParameter('allowSlashes'));
return SlugUtils::createSlug($slug,$allowSlashes);
} | php | public function create()
{
$slug = $this->getParameter('value');
$allowSlashes = StringUtils::strToBool($this->getParameter('allowSlashes'));
return SlugUtils::createSlug($slug,$allowSlashes);
} | [
"public",
"function",
"create",
"(",
")",
"{",
"$",
"slug",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
";",
"$",
"allowSlashes",
"=",
"StringUtils",
"::",
"strToBool",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'allowSlashes'",
")",
")",
";",
"return",
"SlugUtils",
"::",
"createSlug",
"(",
"$",
"slug",
",",
"$",
"allowSlashes",
")",
";",
"}"
] | Returns a slug for the specified parameter
Expected Parameters:
value string The string to turn into a slug
@return string | [
"Returns",
"a",
"slug",
"for",
"the",
"specified",
"parameter"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/SlugsFilterer.php#L42-L48 | train |
PenoaksDev/Milky-Framework | src/Milky/Mail/MailerServiceResolver.php | MailerServiceResolver.mailer | public function mailer()
{
if ( is_null( $this->mailerInstance ) )
{
// Once we have create the mailer instance, we will set a container instance
// on the mailer. This allows us to resolve mailer classes via containers
// for maximum testability on said classes instead of passing Closures.
$mailer = new Mailer( ViewFactory::i(), $this->swiftMailer() );
if ( $queue = UniversalBuilder::resolve( 'queue.connection' ) )
$mailer->setQueue( $queue );
// If a "from" address is set, we will set it on the mailer so that all mail
// messages sent by the applications will utilize the same "from" address
// on each one, which makes the developer's life a lot more convenient.
$from = Config::get( 'mail.from' );
if ( is_array( $from ) && isset( $from['address'] ) )
$mailer->alwaysFrom( $from['address'], $from['name'] );
$to = Config::get( 'mail.to' );
if ( is_array( $to ) && isset( $to['address'] ) )
$mailer->alwaysTo( $to['address'], $to['name'] );
$this->mailerInstance = $mailer;
}
return $this->mailerInstance;
} | php | public function mailer()
{
if ( is_null( $this->mailerInstance ) )
{
// Once we have create the mailer instance, we will set a container instance
// on the mailer. This allows us to resolve mailer classes via containers
// for maximum testability on said classes instead of passing Closures.
$mailer = new Mailer( ViewFactory::i(), $this->swiftMailer() );
if ( $queue = UniversalBuilder::resolve( 'queue.connection' ) )
$mailer->setQueue( $queue );
// If a "from" address is set, we will set it on the mailer so that all mail
// messages sent by the applications will utilize the same "from" address
// on each one, which makes the developer's life a lot more convenient.
$from = Config::get( 'mail.from' );
if ( is_array( $from ) && isset( $from['address'] ) )
$mailer->alwaysFrom( $from['address'], $from['name'] );
$to = Config::get( 'mail.to' );
if ( is_array( $to ) && isset( $to['address'] ) )
$mailer->alwaysTo( $to['address'], $to['name'] );
$this->mailerInstance = $mailer;
}
return $this->mailerInstance;
} | [
"public",
"function",
"mailer",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"mailerInstance",
")",
")",
"{",
"// Once we have create the mailer instance, we will set a container instance",
"// on the mailer. This allows us to resolve mailer classes via containers",
"// for maximum testability on said classes instead of passing Closures.",
"$",
"mailer",
"=",
"new",
"Mailer",
"(",
"ViewFactory",
"::",
"i",
"(",
")",
",",
"$",
"this",
"->",
"swiftMailer",
"(",
")",
")",
";",
"if",
"(",
"$",
"queue",
"=",
"UniversalBuilder",
"::",
"resolve",
"(",
"'queue.connection'",
")",
")",
"$",
"mailer",
"->",
"setQueue",
"(",
"$",
"queue",
")",
";",
"// If a \"from\" address is set, we will set it on the mailer so that all mail",
"// messages sent by the applications will utilize the same \"from\" address",
"// on each one, which makes the developer's life a lot more convenient.",
"$",
"from",
"=",
"Config",
"::",
"get",
"(",
"'mail.from'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"from",
")",
"&&",
"isset",
"(",
"$",
"from",
"[",
"'address'",
"]",
")",
")",
"$",
"mailer",
"->",
"alwaysFrom",
"(",
"$",
"from",
"[",
"'address'",
"]",
",",
"$",
"from",
"[",
"'name'",
"]",
")",
";",
"$",
"to",
"=",
"Config",
"::",
"get",
"(",
"'mail.to'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"to",
")",
"&&",
"isset",
"(",
"$",
"to",
"[",
"'address'",
"]",
")",
")",
"$",
"mailer",
"->",
"alwaysTo",
"(",
"$",
"to",
"[",
"'address'",
"]",
",",
"$",
"to",
"[",
"'name'",
"]",
")",
";",
"$",
"this",
"->",
"mailerInstance",
"=",
"$",
"mailer",
";",
"}",
"return",
"$",
"this",
"->",
"mailerInstance",
";",
"}"
] | mailer.mailer | [
"mailer",
".",
"mailer"
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Mail/MailerServiceResolver.php#L30-L59 | train |
dms-org/common.structure | src/Table/Form/Builder/TableCellClassDefiner.php | TableCellClassDefiner.withDataCell | public function withDataCell(string $tableDataCellClassName) : TableColumnFieldDefiner
{
if (!is_subclass_of($tableDataCellClassName, TableDataCell::class, true)) {
throw InvalidArgumentException::format(
'Invalid class supplied to %s: expecting subclass of %s, %s given',
__METHOD__, TableDataCell::class, $tableDataCellClassName
);
}
return new TableColumnFieldDefiner($this->fieldBuilder, $tableDataCellClassName);
} | php | public function withDataCell(string $tableDataCellClassName) : TableColumnFieldDefiner
{
if (!is_subclass_of($tableDataCellClassName, TableDataCell::class, true)) {
throw InvalidArgumentException::format(
'Invalid class supplied to %s: expecting subclass of %s, %s given',
__METHOD__, TableDataCell::class, $tableDataCellClassName
);
}
return new TableColumnFieldDefiner($this->fieldBuilder, $tableDataCellClassName);
} | [
"public",
"function",
"withDataCell",
"(",
"string",
"$",
"tableDataCellClassName",
")",
":",
"TableColumnFieldDefiner",
"{",
"if",
"(",
"!",
"is_subclass_of",
"(",
"$",
"tableDataCellClassName",
",",
"TableDataCell",
"::",
"class",
",",
"true",
")",
")",
"{",
"throw",
"InvalidArgumentException",
"::",
"format",
"(",
"'Invalid class supplied to %s: expecting subclass of %s, %s given'",
",",
"__METHOD__",
",",
"TableDataCell",
"::",
"class",
",",
"$",
"tableDataCellClassName",
")",
";",
"}",
"return",
"new",
"TableColumnFieldDefiner",
"(",
"$",
"this",
"->",
"fieldBuilder",
",",
"$",
"tableDataCellClassName",
")",
";",
"}"
] | Defines the cell class for the table.
@see TableDataCell
@param string $tableDataCellClassName
@return TableColumnFieldDefiner
@throws InvalidArgumentException | [
"Defines",
"the",
"cell",
"class",
"for",
"the",
"table",
"."
] | 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Table/Form/Builder/TableCellClassDefiner.php#L41-L51 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/caching/interfaces/SystemCache.php | SystemCache.put | public function put($key, $value, $duration, $localOnly = false)
{
return parent::put($key, $value, $this->cacheExpiration);
} | php | public function put($key, $value, $duration, $localOnly = false)
{
return parent::put($key, $value, $this->cacheExpiration);
} | [
"public",
"function",
"put",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"duration",
",",
"$",
"localOnly",
"=",
"false",
")",
"{",
"return",
"parent",
"::",
"put",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"this",
"->",
"cacheExpiration",
")",
";",
"}"
] | Writes the cache value to all of our cache stores
@param string $key The cache key to store
@param string $value The value of the cache item
@return boolean True | [
"Writes",
"the",
"cache",
"value",
"to",
"all",
"of",
"our",
"cache",
"stores"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/interfaces/SystemCache.php#L87-L90 | train |
ingro/Rest | src/Ingruz/Rest/Models/RestModel.php | RestModel.boot | public static function boot()
{
parent::boot();
self::saving(function($model)
{
return $model->beforeSave();
});
self::saved(function($model)
{
return $model->afterSave();
});
self::deleting(function($model)
{
return $model->beforeDelete();
});
self::deleted(function($model)
{
return $model->afterDelete();
});
} | php | public static function boot()
{
parent::boot();
self::saving(function($model)
{
return $model->beforeSave();
});
self::saved(function($model)
{
return $model->afterSave();
});
self::deleting(function($model)
{
return $model->beforeDelete();
});
self::deleted(function($model)
{
return $model->afterDelete();
});
} | [
"public",
"static",
"function",
"boot",
"(",
")",
"{",
"parent",
"::",
"boot",
"(",
")",
";",
"self",
"::",
"saving",
"(",
"function",
"(",
"$",
"model",
")",
"{",
"return",
"$",
"model",
"->",
"beforeSave",
"(",
")",
";",
"}",
")",
";",
"self",
"::",
"saved",
"(",
"function",
"(",
"$",
"model",
")",
"{",
"return",
"$",
"model",
"->",
"afterSave",
"(",
")",
";",
"}",
")",
";",
"self",
"::",
"deleting",
"(",
"function",
"(",
"$",
"model",
")",
"{",
"return",
"$",
"model",
"->",
"beforeDelete",
"(",
")",
";",
"}",
")",
";",
"self",
"::",
"deleted",
"(",
"function",
"(",
"$",
"model",
")",
"{",
"return",
"$",
"model",
"->",
"afterDelete",
"(",
")",
";",
"}",
")",
";",
"}"
] | Setup the model events | [
"Setup",
"the",
"model",
"events"
] | 922bed071b8ea41feb067d97a3e283f944a86cb8 | https://github.com/ingro/Rest/blob/922bed071b8ea41feb067d97a3e283f944a86cb8/src/Ingruz/Rest/Models/RestModel.php#L90-L113 | train |
ingro/Rest | src/Ingruz/Rest/Models/RestModel.php | RestModel.save | public function save(array $options = array(), $force = false)
{
if ( $force || $this->validate() )
{
return $this->performSave($options);
} else
{
return false;
}
} | php | public function save(array $options = array(), $force = false)
{
if ( $force || $this->validate() )
{
return $this->performSave($options);
} else
{
return false;
}
} | [
"public",
"function",
"save",
"(",
"array",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"force",
"||",
"$",
"this",
"->",
"validate",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"performSave",
"(",
"$",
"options",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Persist the model to the DB if it's valid
@param array $options
@param boolean $force
@return boolean | [
"Persist",
"the",
"model",
"to",
"the",
"DB",
"if",
"it",
"s",
"valid"
] | 922bed071b8ea41feb067d97a3e283f944a86cb8 | https://github.com/ingro/Rest/blob/922bed071b8ea41feb067d97a3e283f944a86cb8/src/Ingruz/Rest/Models/RestModel.php#L142-L151 | train |
ingro/Rest | src/Ingruz/Rest/Models/RestModel.php | RestModel.performSave | protected function performSave(array $options) {
$this->purgeAttributes();
$this->saved = true;
return parent::save($options);
} | php | protected function performSave(array $options) {
$this->purgeAttributes();
$this->saved = true;
return parent::save($options);
} | [
"protected",
"function",
"performSave",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"purgeAttributes",
"(",
")",
";",
"$",
"this",
"->",
"saved",
"=",
"true",
";",
"return",
"parent",
"::",
"save",
"(",
"$",
"options",
")",
";",
"}"
] | Save the model on the database
@param array $options
@return boolean | [
"Save",
"the",
"model",
"on",
"the",
"database"
] | 922bed071b8ea41feb067d97a3e283f944a86cb8 | https://github.com/ingro/Rest/blob/922bed071b8ea41feb067d97a3e283f944a86cb8/src/Ingruz/Rest/Models/RestModel.php#L233-L240 | train |
ingro/Rest | src/Ingruz/Rest/Models/RestModel.php | RestModel.validate | protected function validate()
{
$rules = $this->mergeRules();
if ( empty($rules) ) return true;
$data = $this->attributes;
$validator = Validator::make($data, $rules);
$success = $validator->passes();
if ( $success )
{
if ( $this->validationErrors->count() > 0 )
{
$this->validationErrors = new MessageBag;
}
} else
{
$this->validationErrors = $validator->messages();
throw new ValidationErrorException($validator->messages());
}
$this->valid = true;
return $success;
} | php | protected function validate()
{
$rules = $this->mergeRules();
if ( empty($rules) ) return true;
$data = $this->attributes;
$validator = Validator::make($data, $rules);
$success = $validator->passes();
if ( $success )
{
if ( $this->validationErrors->count() > 0 )
{
$this->validationErrors = new MessageBag;
}
} else
{
$this->validationErrors = $validator->messages();
throw new ValidationErrorException($validator->messages());
}
$this->valid = true;
return $success;
} | [
"protected",
"function",
"validate",
"(",
")",
"{",
"$",
"rules",
"=",
"$",
"this",
"->",
"mergeRules",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"rules",
")",
")",
"return",
"true",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"attributes",
";",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"$",
"data",
",",
"$",
"rules",
")",
";",
"$",
"success",
"=",
"$",
"validator",
"->",
"passes",
"(",
")",
";",
"if",
"(",
"$",
"success",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"validationErrors",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"validationErrors",
"=",
"new",
"MessageBag",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"validationErrors",
"=",
"$",
"validator",
"->",
"messages",
"(",
")",
";",
"throw",
"new",
"ValidationErrorException",
"(",
"$",
"validator",
"->",
"messages",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"valid",
"=",
"true",
";",
"return",
"$",
"success",
";",
"}"
] | Validate the model by the defined rules
@throws \Ingruz\Rest\Exceptions\ValidationErrorException
@return boolean | [
"Validate",
"the",
"model",
"by",
"the",
"defined",
"rules"
] | 922bed071b8ea41feb067d97a3e283f944a86cb8 | https://github.com/ingro/Rest/blob/922bed071b8ea41feb067d97a3e283f944a86cb8/src/Ingruz/Rest/Models/RestModel.php#L248-L274 | train |
ingro/Rest | src/Ingruz/Rest/Models/RestModel.php | RestModel.mergeRules | private function mergeRules()
{
$rules = static::$rules;
$output = array();
if (empty ($rules))
{
return $output;
}
if ($this->exists)
{
$merged = (isset($rules['update'])) ? array_merge_recursive($rules['save'], $rules['update']) : $rules['save'];
} else
{
$merged = (isset($rules['create'])) ? array_merge_recursive($rules['save'], $rules['create']) : $rules['save'];
}
foreach ($merged as $field => $rules)
{
if (is_array($rules))
{
$output[$field] = implode("|", $rules);
} else
{
$output[$field] = $rules;
}
}
return $output;
} | php | private function mergeRules()
{
$rules = static::$rules;
$output = array();
if (empty ($rules))
{
return $output;
}
if ($this->exists)
{
$merged = (isset($rules['update'])) ? array_merge_recursive($rules['save'], $rules['update']) : $rules['save'];
} else
{
$merged = (isset($rules['create'])) ? array_merge_recursive($rules['save'], $rules['create']) : $rules['save'];
}
foreach ($merged as $field => $rules)
{
if (is_array($rules))
{
$output[$field] = implode("|", $rules);
} else
{
$output[$field] = $rules;
}
}
return $output;
} | [
"private",
"function",
"mergeRules",
"(",
")",
"{",
"$",
"rules",
"=",
"static",
"::",
"$",
"rules",
";",
"$",
"output",
"=",
"array",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"rules",
")",
")",
"{",
"return",
"$",
"output",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"exists",
")",
"{",
"$",
"merged",
"=",
"(",
"isset",
"(",
"$",
"rules",
"[",
"'update'",
"]",
")",
")",
"?",
"array_merge_recursive",
"(",
"$",
"rules",
"[",
"'save'",
"]",
",",
"$",
"rules",
"[",
"'update'",
"]",
")",
":",
"$",
"rules",
"[",
"'save'",
"]",
";",
"}",
"else",
"{",
"$",
"merged",
"=",
"(",
"isset",
"(",
"$",
"rules",
"[",
"'create'",
"]",
")",
")",
"?",
"array_merge_recursive",
"(",
"$",
"rules",
"[",
"'save'",
"]",
",",
"$",
"rules",
"[",
"'create'",
"]",
")",
":",
"$",
"rules",
"[",
"'save'",
"]",
";",
"}",
"foreach",
"(",
"$",
"merged",
"as",
"$",
"field",
"=>",
"$",
"rules",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"rules",
")",
")",
"{",
"$",
"output",
"[",
"$",
"field",
"]",
"=",
"implode",
"(",
"\"|\"",
",",
"$",
"rules",
")",
";",
"}",
"else",
"{",
"$",
"output",
"[",
"$",
"field",
"]",
"=",
"$",
"rules",
";",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] | Return a single array with the rules for the action required
@return array | [
"Return",
"a",
"single",
"array",
"with",
"the",
"rules",
"for",
"the",
"action",
"required"
] | 922bed071b8ea41feb067d97a3e283f944a86cb8 | https://github.com/ingro/Rest/blob/922bed071b8ea41feb067d97a3e283f944a86cb8/src/Ingruz/Rest/Models/RestModel.php#L323-L353 | train |
ingro/Rest | src/Ingruz/Rest/Models/RestModel.php | RestModel.purgeAttributes | protected function purgeAttributes()
{
$attributes = $this->getPurgeAttributes();
if ( ! empty($attributes) )
{
foreach ( $attributes as $attribute )
{
unset($this->attributes[$attribute]);
}
}
} | php | protected function purgeAttributes()
{
$attributes = $this->getPurgeAttributes();
if ( ! empty($attributes) )
{
foreach ( $attributes as $attribute )
{
unset($this->attributes[$attribute]);
}
}
} | [
"protected",
"function",
"purgeAttributes",
"(",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"getPurgeAttributes",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"$",
"attribute",
"]",
")",
";",
"}",
"}",
"}"
] | Purge the attributes that are not a field on the database table to prevent error during the save | [
"Purge",
"the",
"attributes",
"that",
"are",
"not",
"a",
"field",
"on",
"the",
"database",
"table",
"to",
"prevent",
"error",
"during",
"the",
"save"
] | 922bed071b8ea41feb067d97a3e283f944a86cb8 | https://github.com/ingro/Rest/blob/922bed071b8ea41feb067d97a3e283f944a86cb8/src/Ingruz/Rest/Models/RestModel.php#L358-L369 | train |
gplcart/backup | models/Backup.php | Backup.getList | public function getList(array $data = array())
{
$sql = 'SELECT b.*, u.name AS user_name';
if (!empty($data['count'])) {
$sql = 'SELECT COUNT(b.backup_id)';
}
$sql .= ' FROM backup b
LEFT JOIN user u ON(b.user_id = u.user_id)
WHERE b.backup_id > 0';
$where = array();
if (isset($data['user_id'])) {
$sql .= ' AND b.user_id = ?';
$where[] = $data['user_id'];
}
if (isset($data['id'])) {
$sql .= ' AND b.id = ?';
$where[] = $data['id'];
}
if (isset($data['version'])) {
$sql .= ' AND b.version = ?';
$where[] = $data['version'];
}
if (isset($data['name'])) {
$sql .= ' AND b.name LIKE ?';
$where[] = "%{$data['name']}%";
}
$allowed_order = array('asc', 'desc');
$allowed_sort = array('name', 'user_id', 'version',
'id', 'backup_id', 'type', 'created');
if (isset($data['sort'])
&& in_array($data['sort'], $allowed_sort)
&& isset($data['order'])
&& in_array($data['order'], $allowed_order)
) {
$sql .= " ORDER BY b.{$data['sort']} {$data['order']}";
} else {
$sql .= ' ORDER BY b.created DESC';
}
if (!empty($data['limit'])) {
$sql .= ' LIMIT ' . implode(',', array_map('intval', $data['limit']));
}
if (!empty($data['count'])) {
return (int) $this->db->fetchColumn($sql, $where);
}
$results = $this->db->fetchAll($sql, $where, array('index' => 'backup_id'));
$this->hook->attach('module.backup.list', $results, $this);
return $results;
} | php | public function getList(array $data = array())
{
$sql = 'SELECT b.*, u.name AS user_name';
if (!empty($data['count'])) {
$sql = 'SELECT COUNT(b.backup_id)';
}
$sql .= ' FROM backup b
LEFT JOIN user u ON(b.user_id = u.user_id)
WHERE b.backup_id > 0';
$where = array();
if (isset($data['user_id'])) {
$sql .= ' AND b.user_id = ?';
$where[] = $data['user_id'];
}
if (isset($data['id'])) {
$sql .= ' AND b.id = ?';
$where[] = $data['id'];
}
if (isset($data['version'])) {
$sql .= ' AND b.version = ?';
$where[] = $data['version'];
}
if (isset($data['name'])) {
$sql .= ' AND b.name LIKE ?';
$where[] = "%{$data['name']}%";
}
$allowed_order = array('asc', 'desc');
$allowed_sort = array('name', 'user_id', 'version',
'id', 'backup_id', 'type', 'created');
if (isset($data['sort'])
&& in_array($data['sort'], $allowed_sort)
&& isset($data['order'])
&& in_array($data['order'], $allowed_order)
) {
$sql .= " ORDER BY b.{$data['sort']} {$data['order']}";
} else {
$sql .= ' ORDER BY b.created DESC';
}
if (!empty($data['limit'])) {
$sql .= ' LIMIT ' . implode(',', array_map('intval', $data['limit']));
}
if (!empty($data['count'])) {
return (int) $this->db->fetchColumn($sql, $where);
}
$results = $this->db->fetchAll($sql, $where, array('index' => 'backup_id'));
$this->hook->attach('module.backup.list', $results, $this);
return $results;
} | [
"public",
"function",
"getList",
"(",
"array",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"$",
"sql",
"=",
"'SELECT b.*, u.name AS user_name'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'count'",
"]",
")",
")",
"{",
"$",
"sql",
"=",
"'SELECT COUNT(b.backup_id)'",
";",
"}",
"$",
"sql",
".=",
"' FROM backup b\n LEFT JOIN user u ON(b.user_id = u.user_id)\n WHERE b.backup_id > 0'",
";",
"$",
"where",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'user_id'",
"]",
")",
")",
"{",
"$",
"sql",
".=",
"' AND b.user_id = ?'",
";",
"$",
"where",
"[",
"]",
"=",
"$",
"data",
"[",
"'user_id'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"sql",
".=",
"' AND b.id = ?'",
";",
"$",
"where",
"[",
"]",
"=",
"$",
"data",
"[",
"'id'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'version'",
"]",
")",
")",
"{",
"$",
"sql",
".=",
"' AND b.version = ?'",
";",
"$",
"where",
"[",
"]",
"=",
"$",
"data",
"[",
"'version'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"sql",
".=",
"' AND b.name LIKE ?'",
";",
"$",
"where",
"[",
"]",
"=",
"\"%{$data['name']}%\"",
";",
"}",
"$",
"allowed_order",
"=",
"array",
"(",
"'asc'",
",",
"'desc'",
")",
";",
"$",
"allowed_sort",
"=",
"array",
"(",
"'name'",
",",
"'user_id'",
",",
"'version'",
",",
"'id'",
",",
"'backup_id'",
",",
"'type'",
",",
"'created'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'sort'",
"]",
")",
"&&",
"in_array",
"(",
"$",
"data",
"[",
"'sort'",
"]",
",",
"$",
"allowed_sort",
")",
"&&",
"isset",
"(",
"$",
"data",
"[",
"'order'",
"]",
")",
"&&",
"in_array",
"(",
"$",
"data",
"[",
"'order'",
"]",
",",
"$",
"allowed_order",
")",
")",
"{",
"$",
"sql",
".=",
"\" ORDER BY b.{$data['sort']} {$data['order']}\"",
";",
"}",
"else",
"{",
"$",
"sql",
".=",
"' ORDER BY b.created DESC'",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'limit'",
"]",
")",
")",
"{",
"$",
"sql",
".=",
"' LIMIT '",
".",
"implode",
"(",
"','",
",",
"array_map",
"(",
"'intval'",
",",
"$",
"data",
"[",
"'limit'",
"]",
")",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'count'",
"]",
")",
")",
"{",
"return",
"(",
"int",
")",
"$",
"this",
"->",
"db",
"->",
"fetchColumn",
"(",
"$",
"sql",
",",
"$",
"where",
")",
";",
"}",
"$",
"results",
"=",
"$",
"this",
"->",
"db",
"->",
"fetchAll",
"(",
"$",
"sql",
",",
"$",
"where",
",",
"array",
"(",
"'index'",
"=>",
"'backup_id'",
")",
")",
";",
"$",
"this",
"->",
"hook",
"->",
"attach",
"(",
"'module.backup.list'",
",",
"$",
"results",
",",
"$",
"this",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Returns an array of backups or counts them
@param array $data
@return array|integer | [
"Returns",
"an",
"array",
"of",
"backups",
"or",
"counts",
"them"
] | 5838e2f47f0bb8c2e18b6697e20bec5682b71393 | https://github.com/gplcart/backup/blob/5838e2f47f0bb8c2e18b6697e20bec5682b71393/models/Backup.php#L69-L128 | train |
gplcart/backup | models/Backup.php | Backup.add | public function add(array $data)
{
$result = null;
$this->hook->attach('module.backup.add.before', $data, $result, $this);
if (isset($result)) {
return $result;
}
$version = null;
if (isset($data['version'])) {
$version = $data['version'];
}
if ($this->exists($data['id'], $version)) {
return false;
}
if (empty($data['user_id'])) {
$data['user_id'] = $this->user->getId();
}
$data['created'] = GC_TIME;
$result = $this->db->insert('backup', $data);
$this->hook->attach('module.backup.add.after', $data, $result, $this);
return $result;
} | php | public function add(array $data)
{
$result = null;
$this->hook->attach('module.backup.add.before', $data, $result, $this);
if (isset($result)) {
return $result;
}
$version = null;
if (isset($data['version'])) {
$version = $data['version'];
}
if ($this->exists($data['id'], $version)) {
return false;
}
if (empty($data['user_id'])) {
$data['user_id'] = $this->user->getId();
}
$data['created'] = GC_TIME;
$result = $this->db->insert('backup', $data);
$this->hook->attach('module.backup.add.after', $data, $result, $this);
return $result;
} | [
"public",
"function",
"add",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"this",
"->",
"hook",
"->",
"attach",
"(",
"'module.backup.add.before'",
",",
"$",
"data",
",",
"$",
"result",
",",
"$",
"this",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"version",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'version'",
"]",
")",
")",
"{",
"$",
"version",
"=",
"$",
"data",
"[",
"'version'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"data",
"[",
"'id'",
"]",
",",
"$",
"version",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'user_id'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'user_id'",
"]",
"=",
"$",
"this",
"->",
"user",
"->",
"getId",
"(",
")",
";",
"}",
"$",
"data",
"[",
"'created'",
"]",
"=",
"GC_TIME",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"db",
"->",
"insert",
"(",
"'backup'",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"hook",
"->",
"attach",
"(",
"'module.backup.add.after'",
",",
"$",
"data",
",",
"$",
"result",
",",
"$",
"this",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Adds a backup to the database
@param array $data
@return boolean|integer | [
"Adds",
"a",
"backup",
"to",
"the",
"database"
] | 5838e2f47f0bb8c2e18b6697e20bec5682b71393 | https://github.com/gplcart/backup/blob/5838e2f47f0bb8c2e18b6697e20bec5682b71393/models/Backup.php#L135-L162 | train |
gplcart/backup | models/Backup.php | Backup.delete | public function delete($id)
{
$result = null;
$this->hook->attach('module.backup.delete.before', $id, $this);
if (isset($result)) {
return $result;
}
$result = $this->deleteZip($id);
if ($result) {
$this->db->delete('backup', array('backup_id' => $id));
}
$this->hook->attach('module.backup.delete.after', $id, $result, $this);
return (bool) $result;
} | php | public function delete($id)
{
$result = null;
$this->hook->attach('module.backup.delete.before', $id, $this);
if (isset($result)) {
return $result;
}
$result = $this->deleteZip($id);
if ($result) {
$this->db->delete('backup', array('backup_id' => $id));
}
$this->hook->attach('module.backup.delete.after', $id, $result, $this);
return (bool) $result;
} | [
"public",
"function",
"delete",
"(",
"$",
"id",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"this",
"->",
"hook",
"->",
"attach",
"(",
"'module.backup.delete.before'",
",",
"$",
"id",
",",
"$",
"this",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"deleteZip",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"delete",
"(",
"'backup'",
",",
"array",
"(",
"'backup_id'",
"=>",
"$",
"id",
")",
")",
";",
"}",
"$",
"this",
"->",
"hook",
"->",
"attach",
"(",
"'module.backup.delete.after'",
",",
"$",
"id",
",",
"$",
"result",
",",
"$",
"this",
")",
";",
"return",
"(",
"bool",
")",
"$",
"result",
";",
"}"
] | Deletes a backup from disk and database
@param integer $id
@return boolean | [
"Deletes",
"a",
"backup",
"from",
"disk",
"and",
"database"
] | 5838e2f47f0bb8c2e18b6697e20bec5682b71393 | https://github.com/gplcart/backup/blob/5838e2f47f0bb8c2e18b6697e20bec5682b71393/models/Backup.php#L180-L197 | train |
gplcart/backup | models/Backup.php | Backup.deleteZip | protected function deleteZip($backup_id)
{
$backup = $this->get($backup_id);
if (empty($backup['path'])) {
return false;
}
$file = gplcart_file_absolute($backup['path']);
return file_exists($file) && unlink($file);
} | php | protected function deleteZip($backup_id)
{
$backup = $this->get($backup_id);
if (empty($backup['path'])) {
return false;
}
$file = gplcart_file_absolute($backup['path']);
return file_exists($file) && unlink($file);
} | [
"protected",
"function",
"deleteZip",
"(",
"$",
"backup_id",
")",
"{",
"$",
"backup",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"backup_id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"backup",
"[",
"'path'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"file",
"=",
"gplcart_file_absolute",
"(",
"$",
"backup",
"[",
"'path'",
"]",
")",
";",
"return",
"file_exists",
"(",
"$",
"file",
")",
"&&",
"unlink",
"(",
"$",
"file",
")",
";",
"}"
] | Deletes a backup ZIP archive
@param integer $backup_id
@return boolean | [
"Deletes",
"a",
"backup",
"ZIP",
"archive"
] | 5838e2f47f0bb8c2e18b6697e20bec5682b71393 | https://github.com/gplcart/backup/blob/5838e2f47f0bb8c2e18b6697e20bec5682b71393/models/Backup.php#L204-L214 | train |
gplcart/backup | models/Backup.php | Backup.exists | public function exists($id, $version = null)
{
$list = $this->getList(array('id' => $id, 'version' => $version));
return !empty($list);
} | php | public function exists($id, $version = null)
{
$list = $this->getList(array('id' => $id, 'version' => $version));
return !empty($list);
} | [
"public",
"function",
"exists",
"(",
"$",
"id",
",",
"$",
"version",
"=",
"null",
")",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"getList",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'version'",
"=>",
"$",
"version",
")",
")",
";",
"return",
"!",
"empty",
"(",
"$",
"list",
")",
";",
"}"
] | Whether a backup already exists
@param string $id
@param null|string $version
@return bool | [
"Whether",
"a",
"backup",
"already",
"exists"
] | 5838e2f47f0bb8c2e18b6697e20bec5682b71393 | https://github.com/gplcart/backup/blob/5838e2f47f0bb8c2e18b6697e20bec5682b71393/models/Backup.php#L244-L248 | train |
gplcart/backup | models/Backup.php | Backup.callHandler | protected function callHandler($handler_id, $method, array $arguments)
{
try {
$handlers = $this->getHandlers();
return Handler::call($handlers, $handler_id, $method, $arguments);
} catch (Exception $ex) {
return $ex->getMessage();
}
} | php | protected function callHandler($handler_id, $method, array $arguments)
{
try {
$handlers = $this->getHandlers();
return Handler::call($handlers, $handler_id, $method, $arguments);
} catch (Exception $ex) {
return $ex->getMessage();
}
} | [
"protected",
"function",
"callHandler",
"(",
"$",
"handler_id",
",",
"$",
"method",
",",
"array",
"$",
"arguments",
")",
"{",
"try",
"{",
"$",
"handlers",
"=",
"$",
"this",
"->",
"getHandlers",
"(",
")",
";",
"return",
"Handler",
"::",
"call",
"(",
"$",
"handlers",
",",
"$",
"handler_id",
",",
"$",
"method",
",",
"$",
"arguments",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"return",
"$",
"ex",
"->",
"getMessage",
"(",
")",
";",
"}",
"}"
] | Cal a handler
@param string $handler_id
@param string $method
@param array $arguments
@return mixed | [
"Cal",
"a",
"handler"
] | 5838e2f47f0bb8c2e18b6697e20bec5682b71393 | https://github.com/gplcart/backup/blob/5838e2f47f0bb8c2e18b6697e20bec5682b71393/models/Backup.php#L285-L293 | train |
Talesoft/tale-framework | src/Tale/Debug/Snapshot.php | Snapshot.diff | public function diff( Snapshot $other ) {
return new self(
$this->_time - $other->getTime(),
$this->_memoryUsage - $other->getMemoryUsage(),
$this->_realMemoryUsage - $other->getRealMemoryUsage(),
( $this->_memoryUsagePeak + $other->getMemoryUsagePeak() ) / 2,
( $this->_realMemoryUsagePeak + $other->getRealMemoryUsagePeak() ) / 2
);
} | php | public function diff( Snapshot $other ) {
return new self(
$this->_time - $other->getTime(),
$this->_memoryUsage - $other->getMemoryUsage(),
$this->_realMemoryUsage - $other->getRealMemoryUsage(),
( $this->_memoryUsagePeak + $other->getMemoryUsagePeak() ) / 2,
( $this->_realMemoryUsagePeak + $other->getRealMemoryUsagePeak() ) / 2
);
} | [
"public",
"function",
"diff",
"(",
"Snapshot",
"$",
"other",
")",
"{",
"return",
"new",
"self",
"(",
"$",
"this",
"->",
"_time",
"-",
"$",
"other",
"->",
"getTime",
"(",
")",
",",
"$",
"this",
"->",
"_memoryUsage",
"-",
"$",
"other",
"->",
"getMemoryUsage",
"(",
")",
",",
"$",
"this",
"->",
"_realMemoryUsage",
"-",
"$",
"other",
"->",
"getRealMemoryUsage",
"(",
")",
",",
"(",
"$",
"this",
"->",
"_memoryUsagePeak",
"+",
"$",
"other",
"->",
"getMemoryUsagePeak",
"(",
")",
")",
"/",
"2",
",",
"(",
"$",
"this",
"->",
"_realMemoryUsagePeak",
"+",
"$",
"other",
"->",
"getRealMemoryUsagePeak",
"(",
")",
")",
"/",
"2",
")",
";",
"}"
] | Subtracts a snapshot from another one.
The result will be a snapshot describing the execution metrics between the two snapshots
e.g. execution-time between two snapshots, memory-consumption from one snapshot to another etc.
@param Snapshot $other
@return Snapshot | [
"Subtracts",
"a",
"snapshot",
"from",
"another",
"one",
"."
] | 739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49 | https://github.com/Talesoft/tale-framework/blob/739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49/src/Tale/Debug/Snapshot.php#L148-L157 | train |
Talesoft/tale-framework | src/Tale/Debug/Snapshot.php | Snapshot.create | public static function create() {
return new self(
microtime( true ),
memory_get_usage( false ),
memory_get_usage( true ),
memory_get_peak_usage( false ),
memory_get_peak_usage( true )
);
} | php | public static function create() {
return new self(
microtime( true ),
memory_get_usage( false ),
memory_get_usage( true ),
memory_get_peak_usage( false ),
memory_get_peak_usage( true )
);
} | [
"public",
"static",
"function",
"create",
"(",
")",
"{",
"return",
"new",
"self",
"(",
"microtime",
"(",
"true",
")",
",",
"memory_get_usage",
"(",
"false",
")",
",",
"memory_get_usage",
"(",
"true",
")",
",",
"memory_get_peak_usage",
"(",
"false",
")",
",",
"memory_get_peak_usage",
"(",
"true",
")",
")",
";",
"}"
] | Creates a new snapshot based on current PHP environment metrics
Basically, this fills a new instance of a snapshot with:
microtime( true )
memory_get_usage( false )
memory_get_usage( true )
memory_get_peak_usage( false )
and
memory_get_peak_usage( true )
@return Snapshot | [
"Creates",
"a",
"new",
"snapshot",
"based",
"on",
"current",
"PHP",
"environment",
"metrics"
] | 739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49 | https://github.com/Talesoft/tale-framework/blob/739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49/src/Tale/Debug/Snapshot.php#L172-L181 | train |
agentmedia/phine-core | src/Core/Logic/Logging/Logger.php | Logger.ReportSiteAction | function ReportSiteAction(Site $site, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Site(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logSite = new LogSite();
$logSite->SetLogItem($logItem);
$logSite->SetSite($site);
$logSite->Save();
}
} | php | function ReportSiteAction(Site $site, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Site(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logSite = new LogSite();
$logSite->SetLogItem($logItem);
$logSite->SetSite($site);
$logSite->Save();
}
} | [
"function",
"ReportSiteAction",
"(",
"Site",
"$",
"site",
",",
"Enums",
"\\",
"Action",
"$",
"action",
")",
"{",
"$",
"logItem",
"=",
"$",
"this",
"->",
"CreateLogItem",
"(",
"Enums",
"\\",
"ObjectType",
"::",
"Site",
"(",
")",
",",
"$",
"action",
")",
";",
"if",
"(",
"!",
"$",
"action",
"->",
"Equals",
"(",
"Enums",
"\\",
"Action",
"::",
"Delete",
"(",
")",
")",
")",
"{",
"$",
"logSite",
"=",
"new",
"LogSite",
"(",
")",
";",
"$",
"logSite",
"->",
"SetLogItem",
"(",
"$",
"logItem",
")",
";",
"$",
"logSite",
"->",
"SetSite",
"(",
"$",
"site",
")",
";",
"$",
"logSite",
"->",
"Save",
"(",
")",
";",
"}",
"}"
] | Reports a site action to the log
@param Site $site The site being manipulated
@param Enums\Action $action The operation executed on the site | [
"Reports",
"a",
"site",
"action",
"to",
"the",
"log"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Logging/Logger.php#L52-L62 | train |
agentmedia/phine-core | src/Core/Logic/Logging/Logger.php | Logger.ReportPageAction | function ReportPageAction(Page $page, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Page(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logPage = new LogPage();
$logPage->SetLogItem($logItem);
$logPage->SetPage($page);
$logPage->Save();
}
else
{
$this->ReportSiteAction($page->GetSite(), Enums\Action::ChildDelete());
}
} | php | function ReportPageAction(Page $page, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Page(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logPage = new LogPage();
$logPage->SetLogItem($logItem);
$logPage->SetPage($page);
$logPage->Save();
}
else
{
$this->ReportSiteAction($page->GetSite(), Enums\Action::ChildDelete());
}
} | [
"function",
"ReportPageAction",
"(",
"Page",
"$",
"page",
",",
"Enums",
"\\",
"Action",
"$",
"action",
")",
"{",
"$",
"logItem",
"=",
"$",
"this",
"->",
"CreateLogItem",
"(",
"Enums",
"\\",
"ObjectType",
"::",
"Page",
"(",
")",
",",
"$",
"action",
")",
";",
"if",
"(",
"!",
"$",
"action",
"->",
"Equals",
"(",
"Enums",
"\\",
"Action",
"::",
"Delete",
"(",
")",
")",
")",
"{",
"$",
"logPage",
"=",
"new",
"LogPage",
"(",
")",
";",
"$",
"logPage",
"->",
"SetLogItem",
"(",
"$",
"logItem",
")",
";",
"$",
"logPage",
"->",
"SetPage",
"(",
"$",
"page",
")",
";",
"$",
"logPage",
"->",
"Save",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"ReportSiteAction",
"(",
"$",
"page",
"->",
"GetSite",
"(",
")",
",",
"Enums",
"\\",
"Action",
"::",
"ChildDelete",
"(",
")",
")",
";",
"}",
"}"
] | Reports a page action with dependencies to the log
@param Page $page The page being manipulated
@param Enums\Action $action The operation executed on the page | [
"Reports",
"a",
"page",
"action",
"with",
"dependencies",
"to",
"the",
"log"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Logging/Logger.php#L70-L84 | train |
agentmedia/phine-core | src/Core/Logic/Logging/Logger.php | Logger.ReportAreaAction | function ReportAreaAction(Area $area, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Area(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logArea = new LogArea();
$logArea->SetLogItem($logItem);
$logArea->SetArea($area);
$logArea->Save();
}
else
{
$this->ReportLayoutAction($area->GetLayout(), Enums\Action::ChildDelete());
}
} | php | function ReportAreaAction(Area $area, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Area(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logArea = new LogArea();
$logArea->SetLogItem($logItem);
$logArea->SetArea($area);
$logArea->Save();
}
else
{
$this->ReportLayoutAction($area->GetLayout(), Enums\Action::ChildDelete());
}
} | [
"function",
"ReportAreaAction",
"(",
"Area",
"$",
"area",
",",
"Enums",
"\\",
"Action",
"$",
"action",
")",
"{",
"$",
"logItem",
"=",
"$",
"this",
"->",
"CreateLogItem",
"(",
"Enums",
"\\",
"ObjectType",
"::",
"Area",
"(",
")",
",",
"$",
"action",
")",
";",
"if",
"(",
"!",
"$",
"action",
"->",
"Equals",
"(",
"Enums",
"\\",
"Action",
"::",
"Delete",
"(",
")",
")",
")",
"{",
"$",
"logArea",
"=",
"new",
"LogArea",
"(",
")",
";",
"$",
"logArea",
"->",
"SetLogItem",
"(",
"$",
"logItem",
")",
";",
"$",
"logArea",
"->",
"SetArea",
"(",
"$",
"area",
")",
";",
"$",
"logArea",
"->",
"Save",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"ReportLayoutAction",
"(",
"$",
"area",
"->",
"GetLayout",
"(",
")",
",",
"Enums",
"\\",
"Action",
"::",
"ChildDelete",
"(",
")",
")",
";",
"}",
"}"
] | Reports an area action with dependencies to the log
@param Area $area The area being manipulated
@param Enums\Action $action The operation executed on the area | [
"Reports",
"an",
"area",
"action",
"with",
"dependencies",
"to",
"the",
"log"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Logging/Logger.php#L91-L105 | train |
agentmedia/phine-core | src/Core/Logic/Logging/Logger.php | Logger.ReportLayoutAction | function ReportLayoutAction(Layout $layout, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Layout(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logLayout = new LogLayout();
$logLayout->SetLogItem($logItem);
$logLayout->SetLayout($layout);
$logLayout->Save();
}
else
{
//pages are deleted in cascade
$pages = Page::Schema()->FetchByLayout(false, $layout);
foreach ($pages as $page)
{
$this->ReportPageAction($page, Enums\Action::Delete());
}
}
} | php | function ReportLayoutAction(Layout $layout, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Layout(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logLayout = new LogLayout();
$logLayout->SetLogItem($logItem);
$logLayout->SetLayout($layout);
$logLayout->Save();
}
else
{
//pages are deleted in cascade
$pages = Page::Schema()->FetchByLayout(false, $layout);
foreach ($pages as $page)
{
$this->ReportPageAction($page, Enums\Action::Delete());
}
}
} | [
"function",
"ReportLayoutAction",
"(",
"Layout",
"$",
"layout",
",",
"Enums",
"\\",
"Action",
"$",
"action",
")",
"{",
"$",
"logItem",
"=",
"$",
"this",
"->",
"CreateLogItem",
"(",
"Enums",
"\\",
"ObjectType",
"::",
"Layout",
"(",
")",
",",
"$",
"action",
")",
";",
"if",
"(",
"!",
"$",
"action",
"->",
"Equals",
"(",
"Enums",
"\\",
"Action",
"::",
"Delete",
"(",
")",
")",
")",
"{",
"$",
"logLayout",
"=",
"new",
"LogLayout",
"(",
")",
";",
"$",
"logLayout",
"->",
"SetLogItem",
"(",
"$",
"logItem",
")",
";",
"$",
"logLayout",
"->",
"SetLayout",
"(",
"$",
"layout",
")",
";",
"$",
"logLayout",
"->",
"Save",
"(",
")",
";",
"}",
"else",
"{",
"//pages are deleted in cascade",
"$",
"pages",
"=",
"Page",
"::",
"Schema",
"(",
")",
"->",
"FetchByLayout",
"(",
"false",
",",
"$",
"layout",
")",
";",
"foreach",
"(",
"$",
"pages",
"as",
"$",
"page",
")",
"{",
"$",
"this",
"->",
"ReportPageAction",
"(",
"$",
"page",
",",
"Enums",
"\\",
"Action",
"::",
"Delete",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Reports a layout action with dependencies to the log
@param Layout $layout The layout being manipulated
@param Enums\Action $action The operation executed on the layout | [
"Reports",
"a",
"layout",
"action",
"with",
"dependencies",
"to",
"the",
"log"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Logging/Logger.php#L113-L132 | train |
agentmedia/phine-core | src/Core/Logic/Logging/Logger.php | Logger.ReportContainerAction | function ReportContainerAction(Container $container, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Container(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logContainer = new LogContainer();
$logContainer->SetContainer($container);
$logContainer->SetLogItem($logItem);
$logContainer->Save();
}
} | php | function ReportContainerAction(Container $container, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Container(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logContainer = new LogContainer();
$logContainer->SetContainer($container);
$logContainer->SetLogItem($logItem);
$logContainer->Save();
}
} | [
"function",
"ReportContainerAction",
"(",
"Container",
"$",
"container",
",",
"Enums",
"\\",
"Action",
"$",
"action",
")",
"{",
"$",
"logItem",
"=",
"$",
"this",
"->",
"CreateLogItem",
"(",
"Enums",
"\\",
"ObjectType",
"::",
"Container",
"(",
")",
",",
"$",
"action",
")",
";",
"if",
"(",
"!",
"$",
"action",
"->",
"Equals",
"(",
"Enums",
"\\",
"Action",
"::",
"Delete",
"(",
")",
")",
")",
"{",
"$",
"logContainer",
"=",
"new",
"LogContainer",
"(",
")",
";",
"$",
"logContainer",
"->",
"SetContainer",
"(",
"$",
"container",
")",
";",
"$",
"logContainer",
"->",
"SetLogItem",
"(",
"$",
"logItem",
")",
";",
"$",
"logContainer",
"->",
"Save",
"(",
")",
";",
"}",
"}"
] | Reports a container action with dependencies to the log
@param Container $container The container being manipulated
@param Enums\Action $action The operation executed on the container | [
"Reports",
"a",
"container",
"action",
"with",
"dependencies",
"to",
"the",
"log"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Logging/Logger.php#L139-L150 | train |
agentmedia/phine-core | src/Core/Logic/Logging/Logger.php | Logger.ReportContentAction | function ReportContentAction(Content $content, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Content(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logContent = new LogContent();
$logContent->SetLogItem($logItem);
$logContent->SetContent($content);
$logContent->Save();
}
else
{
if ($content->GetContainerContent())
{
$this->ReportContainerAction($content->GetContainerContent()->GetContainer(), Enums\Action::ChildDelete());
}
else if ($content->GetPageContent())
{
$this->ReportPageAction($content->GetPageContent()->GetPage(), Enums\Action::ChildDelete());
}
else if ($content->GetLayoutContent())
{
$this->ReportAreaAction($content->GetLayoutContent()->GetArea(), Enums\Action::ChildDelete());
}
}
} | php | function ReportContentAction(Content $content, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Content(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logContent = new LogContent();
$logContent->SetLogItem($logItem);
$logContent->SetContent($content);
$logContent->Save();
}
else
{
if ($content->GetContainerContent())
{
$this->ReportContainerAction($content->GetContainerContent()->GetContainer(), Enums\Action::ChildDelete());
}
else if ($content->GetPageContent())
{
$this->ReportPageAction($content->GetPageContent()->GetPage(), Enums\Action::ChildDelete());
}
else if ($content->GetLayoutContent())
{
$this->ReportAreaAction($content->GetLayoutContent()->GetArea(), Enums\Action::ChildDelete());
}
}
} | [
"function",
"ReportContentAction",
"(",
"Content",
"$",
"content",
",",
"Enums",
"\\",
"Action",
"$",
"action",
")",
"{",
"$",
"logItem",
"=",
"$",
"this",
"->",
"CreateLogItem",
"(",
"Enums",
"\\",
"ObjectType",
"::",
"Content",
"(",
")",
",",
"$",
"action",
")",
";",
"if",
"(",
"!",
"$",
"action",
"->",
"Equals",
"(",
"Enums",
"\\",
"Action",
"::",
"Delete",
"(",
")",
")",
")",
"{",
"$",
"logContent",
"=",
"new",
"LogContent",
"(",
")",
";",
"$",
"logContent",
"->",
"SetLogItem",
"(",
"$",
"logItem",
")",
";",
"$",
"logContent",
"->",
"SetContent",
"(",
"$",
"content",
")",
";",
"$",
"logContent",
"->",
"Save",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"content",
"->",
"GetContainerContent",
"(",
")",
")",
"{",
"$",
"this",
"->",
"ReportContainerAction",
"(",
"$",
"content",
"->",
"GetContainerContent",
"(",
")",
"->",
"GetContainer",
"(",
")",
",",
"Enums",
"\\",
"Action",
"::",
"ChildDelete",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"content",
"->",
"GetPageContent",
"(",
")",
")",
"{",
"$",
"this",
"->",
"ReportPageAction",
"(",
"$",
"content",
"->",
"GetPageContent",
"(",
")",
"->",
"GetPage",
"(",
")",
",",
"Enums",
"\\",
"Action",
"::",
"ChildDelete",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"content",
"->",
"GetLayoutContent",
"(",
")",
")",
"{",
"$",
"this",
"->",
"ReportAreaAction",
"(",
"$",
"content",
"->",
"GetLayoutContent",
"(",
")",
"->",
"GetArea",
"(",
")",
",",
"Enums",
"\\",
"Action",
"::",
"ChildDelete",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Reports a content action with dependencies to the log
@param Content $content The content being manipulated
@param Enums\Action $action The operation executed on the content | [
"Reports",
"a",
"content",
"action",
"with",
"dependencies",
"to",
"the",
"log"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Logging/Logger.php#L157-L182 | train |
agentmedia/phine-core | src/Core/Logic/Logging/Logger.php | Logger.ReportMemberAction | function ReportMemberAction(Member $member, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Member(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logMember = new LogMember();
$logMember->SetLogItem($logItem);
$logMember->SetMember($member);
$logMember->Save();
}
} | php | function ReportMemberAction(Member $member, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Member(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logMember = new LogMember();
$logMember->SetLogItem($logItem);
$logMember->SetMember($member);
$logMember->Save();
}
} | [
"function",
"ReportMemberAction",
"(",
"Member",
"$",
"member",
",",
"Enums",
"\\",
"Action",
"$",
"action",
")",
"{",
"$",
"logItem",
"=",
"$",
"this",
"->",
"CreateLogItem",
"(",
"Enums",
"\\",
"ObjectType",
"::",
"Member",
"(",
")",
",",
"$",
"action",
")",
";",
"if",
"(",
"!",
"$",
"action",
"->",
"Equals",
"(",
"Enums",
"\\",
"Action",
"::",
"Delete",
"(",
")",
")",
")",
"{",
"$",
"logMember",
"=",
"new",
"LogMember",
"(",
")",
";",
"$",
"logMember",
"->",
"SetLogItem",
"(",
"$",
"logItem",
")",
";",
"$",
"logMember",
"->",
"SetMember",
"(",
"$",
"member",
")",
";",
"$",
"logMember",
"->",
"Save",
"(",
")",
";",
"}",
"}"
] | Reports a member action to the log
@param Member $member The member being manipulated
@param Enums\Action $action The operation executed on the member | [
"Reports",
"a",
"member",
"action",
"to",
"the",
"log"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Logging/Logger.php#L189-L199 | train |
agentmedia/phine-core | src/Core/Logic/Logging/Logger.php | Logger.ReportMemberGroupAction | function ReportMemberGroupAction(Membergroup $memberGroup, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::MemberGroup(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logMemberGroup = new LogMembergroup();
$logMemberGroup->SetLogItem($logItem);
$logMemberGroup->SetMemberGroup($memberGroup);
$logMemberGroup->Save();
}
} | php | function ReportMemberGroupAction(Membergroup $memberGroup, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::MemberGroup(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logMemberGroup = new LogMembergroup();
$logMemberGroup->SetLogItem($logItem);
$logMemberGroup->SetMemberGroup($memberGroup);
$logMemberGroup->Save();
}
} | [
"function",
"ReportMemberGroupAction",
"(",
"Membergroup",
"$",
"memberGroup",
",",
"Enums",
"\\",
"Action",
"$",
"action",
")",
"{",
"$",
"logItem",
"=",
"$",
"this",
"->",
"CreateLogItem",
"(",
"Enums",
"\\",
"ObjectType",
"::",
"MemberGroup",
"(",
")",
",",
"$",
"action",
")",
";",
"if",
"(",
"!",
"$",
"action",
"->",
"Equals",
"(",
"Enums",
"\\",
"Action",
"::",
"Delete",
"(",
")",
")",
")",
"{",
"$",
"logMemberGroup",
"=",
"new",
"LogMembergroup",
"(",
")",
";",
"$",
"logMemberGroup",
"->",
"SetLogItem",
"(",
"$",
"logItem",
")",
";",
"$",
"logMemberGroup",
"->",
"SetMemberGroup",
"(",
"$",
"memberGroup",
")",
";",
"$",
"logMemberGroup",
"->",
"Save",
"(",
")",
";",
"}",
"}"
] | Reports a member group action to the log
@param Membergroup $memberGroup The member group being manipulated
@param Enums\Action $action The operation executed on the member group | [
"Reports",
"a",
"member",
"group",
"action",
"to",
"the",
"log"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Logging/Logger.php#L206-L216 | train |
agentmedia/phine-core | src/Core/Logic/Logging/Logger.php | Logger.ReportUserAction | function ReportUserAction(User $user, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::User(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logUser = new LogUser();
$logUser->SetLogItem($logItem);
$logUser->SetUser($user);
$logUser->Save();
}
} | php | function ReportUserAction(User $user, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::User(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logUser = new LogUser();
$logUser->SetLogItem($logItem);
$logUser->SetUser($user);
$logUser->Save();
}
} | [
"function",
"ReportUserAction",
"(",
"User",
"$",
"user",
",",
"Enums",
"\\",
"Action",
"$",
"action",
")",
"{",
"$",
"logItem",
"=",
"$",
"this",
"->",
"CreateLogItem",
"(",
"Enums",
"\\",
"ObjectType",
"::",
"User",
"(",
")",
",",
"$",
"action",
")",
";",
"if",
"(",
"!",
"$",
"action",
"->",
"Equals",
"(",
"Enums",
"\\",
"Action",
"::",
"Delete",
"(",
")",
")",
")",
"{",
"$",
"logUser",
"=",
"new",
"LogUser",
"(",
")",
";",
"$",
"logUser",
"->",
"SetLogItem",
"(",
"$",
"logItem",
")",
";",
"$",
"logUser",
"->",
"SetUser",
"(",
"$",
"user",
")",
";",
"$",
"logUser",
"->",
"Save",
"(",
")",
";",
"}",
"}"
] | Reports a user action to the log
@param User $user The user being manipulated
@param Enums\Action $action The operation executed on the user | [
"Reports",
"a",
"user",
"action",
"to",
"the",
"log"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Logging/Logger.php#L222-L232 | train |
agentmedia/phine-core | src/Core/Logic/Logging/Logger.php | Logger.ReportUserGroupAction | function ReportUserGroupAction(Usergroup $userGroup, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::UserGroup(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logUserGroup = new LogUsergroup();
$logUserGroup->SetLogItem($logItem);
$logUserGroup->SetUserGroup($userGroup);
$logUserGroup->Save();
}
} | php | function ReportUserGroupAction(Usergroup $userGroup, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::UserGroup(), $action);
if (!$action->Equals(Enums\Action::Delete()))
{
$logUserGroup = new LogUsergroup();
$logUserGroup->SetLogItem($logItem);
$logUserGroup->SetUserGroup($userGroup);
$logUserGroup->Save();
}
} | [
"function",
"ReportUserGroupAction",
"(",
"Usergroup",
"$",
"userGroup",
",",
"Enums",
"\\",
"Action",
"$",
"action",
")",
"{",
"$",
"logItem",
"=",
"$",
"this",
"->",
"CreateLogItem",
"(",
"Enums",
"\\",
"ObjectType",
"::",
"UserGroup",
"(",
")",
",",
"$",
"action",
")",
";",
"if",
"(",
"!",
"$",
"action",
"->",
"Equals",
"(",
"Enums",
"\\",
"Action",
"::",
"Delete",
"(",
")",
")",
")",
"{",
"$",
"logUserGroup",
"=",
"new",
"LogUsergroup",
"(",
")",
";",
"$",
"logUserGroup",
"->",
"SetLogItem",
"(",
"$",
"logItem",
")",
";",
"$",
"logUserGroup",
"->",
"SetUserGroup",
"(",
"$",
"userGroup",
")",
";",
"$",
"logUserGroup",
"->",
"Save",
"(",
")",
";",
"}",
"}"
] | Reports a user group action to the log
@param Usergroup $userGroup The user group being manipulated
@param Enums\Action $action The operation executed on the user group | [
"Reports",
"a",
"user",
"group",
"action",
"to",
"the",
"log"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Logging/Logger.php#L239-L249 | train |
agentmedia/phine-core | src/Core/Logic/Logging/Logger.php | Logger.ReportTemplateAction | function ReportTemplateAction($moduleType, $template, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Template(), $action);
$logTemplate = new LogTemplate;
$logTemplate->SetLogItem($logItem);
$logTemplate->SetModuleType($moduleType);
$logTemplate->SetTemplate($template);
$logTemplate->Save();
} | php | function ReportTemplateAction($moduleType, $template, Enums\Action $action)
{
$logItem = $this->CreateLogItem(Enums\ObjectType::Template(), $action);
$logTemplate = new LogTemplate;
$logTemplate->SetLogItem($logItem);
$logTemplate->SetModuleType($moduleType);
$logTemplate->SetTemplate($template);
$logTemplate->Save();
} | [
"function",
"ReportTemplateAction",
"(",
"$",
"moduleType",
",",
"$",
"template",
",",
"Enums",
"\\",
"Action",
"$",
"action",
")",
"{",
"$",
"logItem",
"=",
"$",
"this",
"->",
"CreateLogItem",
"(",
"Enums",
"\\",
"ObjectType",
"::",
"Template",
"(",
")",
",",
"$",
"action",
")",
";",
"$",
"logTemplate",
"=",
"new",
"LogTemplate",
";",
"$",
"logTemplate",
"->",
"SetLogItem",
"(",
"$",
"logItem",
")",
";",
"$",
"logTemplate",
"->",
"SetModuleType",
"(",
"$",
"moduleType",
")",
";",
"$",
"logTemplate",
"->",
"SetTemplate",
"(",
"$",
"template",
")",
";",
"$",
"logTemplate",
"->",
"Save",
"(",
")",
";",
"}"
] | Reports an action on a module template
@param string $moduleType The module type the template belongs to
@param string $template The template file name
@param Enums\Action $action The action | [
"Reports",
"an",
"action",
"on",
"a",
"module",
"template"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Logging/Logger.php#L257-L265 | train |
agentmedia/phine-core | src/Core/Logic/Logging/Logger.php | Logger.CreateLogItem | private function CreateLogItem(Enums\ObjectType $objType, Enums\Action $action)
{
$this->DeleteOldLogItems();
$item = new LogItem();
$item->SetChanged(Date::Now());
$item->SetAction((string)$action);
$item->SetObjectType((string)$objType);
$item->SetUser($this->user);
$item->Save();
return $item;
} | php | private function CreateLogItem(Enums\ObjectType $objType, Enums\Action $action)
{
$this->DeleteOldLogItems();
$item = new LogItem();
$item->SetChanged(Date::Now());
$item->SetAction((string)$action);
$item->SetObjectType((string)$objType);
$item->SetUser($this->user);
$item->Save();
return $item;
} | [
"private",
"function",
"CreateLogItem",
"(",
"Enums",
"\\",
"ObjectType",
"$",
"objType",
",",
"Enums",
"\\",
"Action",
"$",
"action",
")",
"{",
"$",
"this",
"->",
"DeleteOldLogItems",
"(",
")",
";",
"$",
"item",
"=",
"new",
"LogItem",
"(",
")",
";",
"$",
"item",
"->",
"SetChanged",
"(",
"Date",
"::",
"Now",
"(",
")",
")",
";",
"$",
"item",
"->",
"SetAction",
"(",
"(",
"string",
")",
"$",
"action",
")",
";",
"$",
"item",
"->",
"SetObjectType",
"(",
"(",
"string",
")",
"$",
"objType",
")",
";",
"$",
"item",
"->",
"SetUser",
"(",
"$",
"this",
"->",
"user",
")",
";",
"$",
"item",
"->",
"Save",
"(",
")",
";",
"return",
"$",
"item",
";",
"}"
] | Creates a log item
@param Enums\ObjectType $objType The type of object being manipulated
@param Enums\Action $action The operation executed on the object
@return LogItem Returns a log item, freshly saved to the database | [
"Creates",
"a",
"log",
"item"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Logging/Logger.php#L273-L283 | train |
agentmedia/phine-core | src/Core/Logic/Logging/Logger.php | Logger.DeleteOldLogItems | private function DeleteOldLogItems()
{
$days = SettingsProxy::Singleton()->Settings()->GetLogLifetime();
$deleteBefore = Date::Now();
$deleteBefore->AddDays(-$days);
$tblLogItem = LogItem::Schema()->Table();
$sql = Access::SqlBuilder();
$where = $sql->LT($tblLogItem->Field('Changed'), $sql->Value($deleteBefore));
LogItem::Schema()->Delete($where);
} | php | private function DeleteOldLogItems()
{
$days = SettingsProxy::Singleton()->Settings()->GetLogLifetime();
$deleteBefore = Date::Now();
$deleteBefore->AddDays(-$days);
$tblLogItem = LogItem::Schema()->Table();
$sql = Access::SqlBuilder();
$where = $sql->LT($tblLogItem->Field('Changed'), $sql->Value($deleteBefore));
LogItem::Schema()->Delete($where);
} | [
"private",
"function",
"DeleteOldLogItems",
"(",
")",
"{",
"$",
"days",
"=",
"SettingsProxy",
"::",
"Singleton",
"(",
")",
"->",
"Settings",
"(",
")",
"->",
"GetLogLifetime",
"(",
")",
";",
"$",
"deleteBefore",
"=",
"Date",
"::",
"Now",
"(",
")",
";",
"$",
"deleteBefore",
"->",
"AddDays",
"(",
"-",
"$",
"days",
")",
";",
"$",
"tblLogItem",
"=",
"LogItem",
"::",
"Schema",
"(",
")",
"->",
"Table",
"(",
")",
";",
"$",
"sql",
"=",
"Access",
"::",
"SqlBuilder",
"(",
")",
";",
"$",
"where",
"=",
"$",
"sql",
"->",
"LT",
"(",
"$",
"tblLogItem",
"->",
"Field",
"(",
"'Changed'",
")",
",",
"$",
"sql",
"->",
"Value",
"(",
"$",
"deleteBefore",
")",
")",
";",
"LogItem",
"::",
"Schema",
"(",
")",
"->",
"Delete",
"(",
"$",
"where",
")",
";",
"}"
] | Deletes log items older then the given amount of days
@param int $days The days | [
"Deletes",
"log",
"items",
"older",
"then",
"the",
"given",
"amount",
"of",
"days"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Logging/Logger.php#L289-L298 | train |
Hnto/nuki | src/Handlers/Core/Assist.php | Assist.classNameShort | public static function classNameShort($class) {
$className = self::className($class);
$position = strrpos($className, '\\');
$name = substr($className, $position + 1);
return $name;
} | php | public static function classNameShort($class) {
$className = self::className($class);
$position = strrpos($className, '\\');
$name = substr($className, $position + 1);
return $name;
} | [
"public",
"static",
"function",
"classNameShort",
"(",
"$",
"class",
")",
"{",
"$",
"className",
"=",
"self",
"::",
"className",
"(",
"$",
"class",
")",
";",
"$",
"position",
"=",
"strrpos",
"(",
"$",
"className",
",",
"'\\\\'",
")",
";",
"$",
"name",
"=",
"substr",
"(",
"$",
"className",
",",
"$",
"position",
"+",
"1",
")",
";",
"return",
"$",
"name",
";",
"}"
] | Returns only the class name
@param object $class
@return string | [
"Returns",
"only",
"the",
"class",
"name"
] | c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c | https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Core/Assist.php#L45-L52 | train |
Hnto/nuki | src/Handlers/Core/Assist.php | Assist.classHasMethod | public static function classHasMethod($method, $class) {
$methods = self::classMethods($class);
if (!in_array($method, $methods)) {
return false;
}
return true;
} | php | public static function classHasMethod($method, $class) {
$methods = self::classMethods($class);
if (!in_array($method, $methods)) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"classHasMethod",
"(",
"$",
"method",
",",
"$",
"class",
")",
"{",
"$",
"methods",
"=",
"self",
"::",
"classMethods",
"(",
"$",
"class",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"method",
",",
"$",
"methods",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Check if class has method
@param string $method
@param object|string $class
@return boolean | [
"Check",
"if",
"class",
"has",
"method"
] | c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c | https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Core/Assist.php#L61-L69 | train |
Hnto/nuki | src/Handlers/Core/Assist.php | Assist.hash | public static function hash($data, $file = false) {
$hasher = new \Nuki\Handlers\Security\Hasher(self::getAppAlgorithm(), self::getAppKey());
return $hasher->hash($data, $file);
} | php | public static function hash($data, $file = false) {
$hasher = new \Nuki\Handlers\Security\Hasher(self::getAppAlgorithm(), self::getAppKey());
return $hasher->hash($data, $file);
} | [
"public",
"static",
"function",
"hash",
"(",
"$",
"data",
",",
"$",
"file",
"=",
"false",
")",
"{",
"$",
"hasher",
"=",
"new",
"\\",
"Nuki",
"\\",
"Handlers",
"\\",
"Security",
"\\",
"Hasher",
"(",
"self",
"::",
"getAppAlgorithm",
"(",
")",
",",
"self",
"::",
"getAppKey",
"(",
")",
")",
";",
"return",
"$",
"hasher",
"->",
"hash",
"(",
"$",
"data",
",",
"$",
"file",
")",
";",
"}"
] | Hash by data or filename
@param $data
@param bool $file
@return bool|string
@throws \Nuki\Exceptions\Base | [
"Hash",
"by",
"data",
"or",
"filename"
] | c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c | https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Core/Assist.php#L184-L188 | train |
Hnto/nuki | src/Handlers/Core/Assist.php | Assist.encrypt | public static function encrypt($data) : Encrypted {
$crypter = new Crypter();
return $crypter->encrypt($data, self::getAppKey());
} | php | public static function encrypt($data) : Encrypted {
$crypter = new Crypter();
return $crypter->encrypt($data, self::getAppKey());
} | [
"public",
"static",
"function",
"encrypt",
"(",
"$",
"data",
")",
":",
"Encrypted",
"{",
"$",
"crypter",
"=",
"new",
"Crypter",
"(",
")",
";",
"return",
"$",
"crypter",
"->",
"encrypt",
"(",
"$",
"data",
",",
"self",
"::",
"getAppKey",
"(",
")",
")",
";",
"}"
] | Encrypt data and return an encrypter object
@param $data
@return Encrypted
@throws \Nuki\Exceptions\Base | [
"Encrypt",
"data",
"and",
"return",
"an",
"encrypter",
"object"
] | c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c | https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Core/Assist.php#L218-L222 | train |
Hnto/nuki | src/Handlers/Core/Assist.php | Assist.decrypt | public static function decrypt($data) : string {
$crypter = new Crypter();
return $crypter->decrypt($data, self::getAppKey());
} | php | public static function decrypt($data) : string {
$crypter = new Crypter();
return $crypter->decrypt($data, self::getAppKey());
} | [
"public",
"static",
"function",
"decrypt",
"(",
"$",
"data",
")",
":",
"string",
"{",
"$",
"crypter",
"=",
"new",
"Crypter",
"(",
")",
";",
"return",
"$",
"crypter",
"->",
"decrypt",
"(",
"$",
"data",
",",
"self",
"::",
"getAppKey",
"(",
")",
")",
";",
"}"
] | Decrypt data and return the decrypted value
@param $data
@return string
@throws \Nuki\Exceptions\Base | [
"Decrypt",
"data",
"and",
"return",
"the",
"decrypted",
"value"
] | c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c | https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Core/Assist.php#L233-L237 | train |
Hnto/nuki | src/Handlers/Core/Assist.php | Assist.loadCoreView | public static function loadCoreView(string $name) {
$base = __DIR__ . '/../../Views/';
if (!file_exists($base . $name . '.view')) {
throw new \Nuki\Exceptions\Base('The view file "' . $name . '" does not exist.');
}
return file_get_contents($base . $name . '.view');
} | php | public static function loadCoreView(string $name) {
$base = __DIR__ . '/../../Views/';
if (!file_exists($base . $name . '.view')) {
throw new \Nuki\Exceptions\Base('The view file "' . $name . '" does not exist.');
}
return file_get_contents($base . $name . '.view');
} | [
"public",
"static",
"function",
"loadCoreView",
"(",
"string",
"$",
"name",
")",
"{",
"$",
"base",
"=",
"__DIR__",
".",
"'/../../Views/'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"base",
".",
"$",
"name",
".",
"'.view'",
")",
")",
"{",
"throw",
"new",
"\\",
"Nuki",
"\\",
"Exceptions",
"\\",
"Base",
"(",
"'The view file \"'",
".",
"$",
"name",
".",
"'\" does not exist.'",
")",
";",
"}",
"return",
"file_get_contents",
"(",
"$",
"base",
".",
"$",
"name",
".",
"'.view'",
")",
";",
"}"
] | Load the contents of a core view file
@param string $name
@return string
@throws \Nuki\Exceptions\Base | [
"Load",
"the",
"contents",
"of",
"a",
"core",
"view",
"file"
] | c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c | https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Core/Assist.php#L270-L277 | train |
reshadman/php-bijective-shortener | src/BijectiveShortener.php | BijectiveShortener.makeFromInteger | public static function makeFromInteger($integer)
{
if ($integer == 0) return static::$chars[0];
$number = abs($integer);
if ($integer < 0)
throw new \InvalidArgumentException("Can not encode for negative integers");
$string = '';
$base = strlen(static::$chars);
while ($number > 0) {
$string .= static::$chars[$number % $base];
$number = (int) ($number / $base);
}
return strrev($string);
} | php | public static function makeFromInteger($integer)
{
if ($integer == 0) return static::$chars[0];
$number = abs($integer);
if ($integer < 0)
throw new \InvalidArgumentException("Can not encode for negative integers");
$string = '';
$base = strlen(static::$chars);
while ($number > 0) {
$string .= static::$chars[$number % $base];
$number = (int) ($number / $base);
}
return strrev($string);
} | [
"public",
"static",
"function",
"makeFromInteger",
"(",
"$",
"integer",
")",
"{",
"if",
"(",
"$",
"integer",
"==",
"0",
")",
"return",
"static",
"::",
"$",
"chars",
"[",
"0",
"]",
";",
"$",
"number",
"=",
"abs",
"(",
"$",
"integer",
")",
";",
"if",
"(",
"$",
"integer",
"<",
"0",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Can not encode for negative integers\"",
")",
";",
"$",
"string",
"=",
"''",
";",
"$",
"base",
"=",
"strlen",
"(",
"static",
"::",
"$",
"chars",
")",
";",
"while",
"(",
"$",
"number",
">",
"0",
")",
"{",
"$",
"string",
".=",
"static",
"::",
"$",
"chars",
"[",
"$",
"number",
"%",
"$",
"base",
"]",
";",
"$",
"number",
"=",
"(",
"int",
")",
"(",
"$",
"number",
"/",
"$",
"base",
")",
";",
"}",
"return",
"strrev",
"(",
"$",
"string",
")",
";",
"}"
] | Make a unique string from an Integer
@param $integer
@return string | [
"Make",
"a",
"unique",
"string",
"from",
"an",
"Integer"
] | 76c80defd945ca6890303fc7387ceac593b03019 | https://github.com/reshadman/php-bijective-shortener/blob/76c80defd945ca6890303fc7387ceac593b03019/src/BijectiveShortener.php#L18-L38 | train |
reshadman/php-bijective-shortener | src/BijectiveShortener.php | BijectiveShortener.decodeToInteger | public static function decodeToInteger($string)
{
$stringLength = strlen($string);
$baseLength = strlen(static::$chars);
$id = 0;
for($i = 0; $i < $stringLength; $i++){
$pos = strpos(static::$chars, $string[$i]);
$id = ($id * $baseLength) + $pos;
}
return $id;
} | php | public static function decodeToInteger($string)
{
$stringLength = strlen($string);
$baseLength = strlen(static::$chars);
$id = 0;
for($i = 0; $i < $stringLength; $i++){
$pos = strpos(static::$chars, $string[$i]);
$id = ($id * $baseLength) + $pos;
}
return $id;
} | [
"public",
"static",
"function",
"decodeToInteger",
"(",
"$",
"string",
")",
"{",
"$",
"stringLength",
"=",
"strlen",
"(",
"$",
"string",
")",
";",
"$",
"baseLength",
"=",
"strlen",
"(",
"static",
"::",
"$",
"chars",
")",
";",
"$",
"id",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"stringLength",
";",
"$",
"i",
"++",
")",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"static",
"::",
"$",
"chars",
",",
"$",
"string",
"[",
"$",
"i",
"]",
")",
";",
"$",
"id",
"=",
"(",
"$",
"id",
"*",
"$",
"baseLength",
")",
"+",
"$",
"pos",
";",
"}",
"return",
"$",
"id",
";",
"}"
] | Decode the encoded string to Integer
@param $string
@return mixed | [
"Decode",
"the",
"encoded",
"string",
"to",
"Integer"
] | 76c80defd945ca6890303fc7387ceac593b03019 | https://github.com/reshadman/php-bijective-shortener/blob/76c80defd945ca6890303fc7387ceac593b03019/src/BijectiveShortener.php#L56-L73 | train |
wb-crowdfusion/crowdfusion | system/core/classes/systemdb/cmsnavigation/CMSNavItemService.php | CMSNavItemService.getMenu | public function getMenu(DTO $dto=null)
{
if (!$menu = $this->SystemCache->get('cms-menu')) {
$menu = array();
if ($dto === null)
$dto = new DTO();
$dto->setOrderBy('SortOrder', 'ASC');
$dto->setParameter('FlattenChildren', false);
$dto->setParameter('Enabled', true);
$menu = $this->dao->findAll($dto)->getResults();
if (count($menu) < 1)
throw new Exception('No menu items exist on the root level.');
$this->SystemCache->put('cms-menu', $menu, 0);
}
return $menu;
} | php | public function getMenu(DTO $dto=null)
{
if (!$menu = $this->SystemCache->get('cms-menu')) {
$menu = array();
if ($dto === null)
$dto = new DTO();
$dto->setOrderBy('SortOrder', 'ASC');
$dto->setParameter('FlattenChildren', false);
$dto->setParameter('Enabled', true);
$menu = $this->dao->findAll($dto)->getResults();
if (count($menu) < 1)
throw new Exception('No menu items exist on the root level.');
$this->SystemCache->put('cms-menu', $menu, 0);
}
return $menu;
} | [
"public",
"function",
"getMenu",
"(",
"DTO",
"$",
"dto",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"menu",
"=",
"$",
"this",
"->",
"SystemCache",
"->",
"get",
"(",
"'cms-menu'",
")",
")",
"{",
"$",
"menu",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"dto",
"===",
"null",
")",
"$",
"dto",
"=",
"new",
"DTO",
"(",
")",
";",
"$",
"dto",
"->",
"setOrderBy",
"(",
"'SortOrder'",
",",
"'ASC'",
")",
";",
"$",
"dto",
"->",
"setParameter",
"(",
"'FlattenChildren'",
",",
"false",
")",
";",
"$",
"dto",
"->",
"setParameter",
"(",
"'Enabled'",
",",
"true",
")",
";",
"$",
"menu",
"=",
"$",
"this",
"->",
"dao",
"->",
"findAll",
"(",
"$",
"dto",
")",
"->",
"getResults",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"menu",
")",
"<",
"1",
")",
"throw",
"new",
"Exception",
"(",
"'No menu items exist on the root level.'",
")",
";",
"$",
"this",
"->",
"SystemCache",
"->",
"put",
"(",
"'cms-menu'",
",",
"$",
"menu",
",",
"0",
")",
";",
"}",
"return",
"$",
"menu",
";",
"}"
] | Returns an array that represents the CMS Navigation menu
@param DTO $dto DTO to pass through to our DAO's findAll()
@return array An array representing the cms nav menu | [
"Returns",
"an",
"array",
"that",
"represents",
"the",
"CMS",
"Navigation",
"menu"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/cmsnavigation/CMSNavItemService.php#L61-L82 | train |
TuumPHP/Web | src/Psr7/Respond.php | Respond.asError | public function asError($status = self::INTERNAL_ERROR)
{
if ($this->error_views) {
$stream = $this->error_views->getStream($status);
} else {
$stream = null;
}
return Response::error($status, $this->data, $stream);
} | php | public function asError($status = self::INTERNAL_ERROR)
{
if ($this->error_views) {
$stream = $this->error_views->getStream($status);
} else {
$stream = null;
}
return Response::error($status, $this->data, $stream);
} | [
"public",
"function",
"asError",
"(",
"$",
"status",
"=",
"self",
"::",
"INTERNAL_ERROR",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"error_views",
")",
"{",
"$",
"stream",
"=",
"$",
"this",
"->",
"error_views",
"->",
"getStream",
"(",
"$",
"status",
")",
";",
"}",
"else",
"{",
"$",
"stream",
"=",
"null",
";",
"}",
"return",
"Response",
"::",
"error",
"(",
"$",
"status",
",",
"$",
"this",
"->",
"data",
",",
"$",
"stream",
")",
";",
"}"
] | return a response with error number.
@param int|string $status
@return Response | [
"return",
"a",
"response",
"with",
"error",
"number",
"."
] | 8f296b6358aa93226ce08d6cc54a309f5b0a9820 | https://github.com/TuumPHP/Web/blob/8f296b6358aa93226ce08d6cc54a309f5b0a9820/src/Psr7/Respond.php#L131-L139 | train |
linpax/microphp-framework | src/mvc/controllers/RichController.php | RichController.switchContentType | protected function switchContentType($data)
{
switch ($this->format) {
case 'application/json':
$data = json_encode(is_object($data) ? (array)$data : $data);
break;
case 'application/xml':
$data = is_object($data) ? (string)$data : $data;
break;
default:
$data = (string)$data;
}
return $data;
} | php | protected function switchContentType($data)
{
switch ($this->format) {
case 'application/json':
$data = json_encode(is_object($data) ? (array)$data : $data);
break;
case 'application/xml':
$data = is_object($data) ? (string)$data : $data;
break;
default:
$data = (string)$data;
}
return $data;
} | [
"protected",
"function",
"switchContentType",
"(",
"$",
"data",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"format",
")",
"{",
"case",
"'application/json'",
":",
"$",
"data",
"=",
"json_encode",
"(",
"is_object",
"(",
"$",
"data",
")",
"?",
"(",
"array",
")",
"$",
"data",
":",
"$",
"data",
")",
";",
"break",
";",
"case",
"'application/xml'",
":",
"$",
"data",
"=",
"is_object",
"(",
"$",
"data",
")",
"?",
"(",
"string",
")",
"$",
"data",
":",
"$",
"data",
";",
"break",
";",
"default",
":",
"$",
"data",
"=",
"(",
"string",
")",
"$",
"data",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Switch content type
@access protected
@param null|string $data Any content
@return string | [
"Switch",
"content",
"type"
] | 11f3370f3f64c516cce9b84ecd8276c6e9ae8df9 | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/mvc/controllers/RichController.php#L129-L145 | train |
lasallecms/lasallecms-l5-lasallecmsadmin-pkg | src/FormProcessing/Users/ExtraUserValidation.php | ExtraUserValidation.extraValidation | public function extraValidation($data, $performPhoneValidation=true) {
$this->messages = new MessageBag;
// is the cell number where text messages will be sent ok?
if (
(!$this->userRepository->validatePhoneNumber($data['phone_number']))
&& ($performPhoneValidation)
)
{
// Prepare the response array, and then return to the edit form with error messages
// first, add the error message to the message bag
$this->messages->add('phone_number', 'There is a problem with your phone number. Please re-enter it.');
return $this->baseFormProcessing->prepareResponseArray('validation_failed', 500, $data, $this->messages);
}
// does the password contain the word "password"?
if (!$this->userRepository->validatePasswordNotUseWordPassword($data['password'])) {
// Prepare the response array, and then return to the edit form with error messages
// first, add the error message to the message bag
$this->messages->add('password', 'Please do not use the word \'password\' in your password. This is *really* b-a-d for security.');
return $this->baseFormProcessing->prepareResponseArray('validation_failed', 500, $data, $this->messages);
}
// does the password contain the user's name?
if (!$this->userRepository->validatePasswordNotUseUsername($data['name'], $data['password'])) {
// Prepare the response array, and then return to the edit form with error messages
// first, add the error message to the message bag
$this->messages->add('password', 'Please do not use your name in the password. This is *really* b-a-d for security.');
return $this->baseFormProcessing->prepareResponseArray('validation_failed', 500, $data, $this->messages);
}
// Extra validation is ok
// Prepare the response array, and then return to the command
return $this->baseFormProcessing->prepareResponseArray('extra_validation_successful', 200, $data);
} | php | public function extraValidation($data, $performPhoneValidation=true) {
$this->messages = new MessageBag;
// is the cell number where text messages will be sent ok?
if (
(!$this->userRepository->validatePhoneNumber($data['phone_number']))
&& ($performPhoneValidation)
)
{
// Prepare the response array, and then return to the edit form with error messages
// first, add the error message to the message bag
$this->messages->add('phone_number', 'There is a problem with your phone number. Please re-enter it.');
return $this->baseFormProcessing->prepareResponseArray('validation_failed', 500, $data, $this->messages);
}
// does the password contain the word "password"?
if (!$this->userRepository->validatePasswordNotUseWordPassword($data['password'])) {
// Prepare the response array, and then return to the edit form with error messages
// first, add the error message to the message bag
$this->messages->add('password', 'Please do not use the word \'password\' in your password. This is *really* b-a-d for security.');
return $this->baseFormProcessing->prepareResponseArray('validation_failed', 500, $data, $this->messages);
}
// does the password contain the user's name?
if (!$this->userRepository->validatePasswordNotUseUsername($data['name'], $data['password'])) {
// Prepare the response array, and then return to the edit form with error messages
// first, add the error message to the message bag
$this->messages->add('password', 'Please do not use your name in the password. This is *really* b-a-d for security.');
return $this->baseFormProcessing->prepareResponseArray('validation_failed', 500, $data, $this->messages);
}
// Extra validation is ok
// Prepare the response array, and then return to the command
return $this->baseFormProcessing->prepareResponseArray('extra_validation_successful', 200, $data);
} | [
"public",
"function",
"extraValidation",
"(",
"$",
"data",
",",
"$",
"performPhoneValidation",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"messages",
"=",
"new",
"MessageBag",
";",
"// is the cell number where text messages will be sent ok?",
"if",
"(",
"(",
"!",
"$",
"this",
"->",
"userRepository",
"->",
"validatePhoneNumber",
"(",
"$",
"data",
"[",
"'phone_number'",
"]",
")",
")",
"&&",
"(",
"$",
"performPhoneValidation",
")",
")",
"{",
"// Prepare the response array, and then return to the edit form with error messages",
"// first, add the error message to the message bag",
"$",
"this",
"->",
"messages",
"->",
"add",
"(",
"'phone_number'",
",",
"'There is a problem with your phone number. Please re-enter it.'",
")",
";",
"return",
"$",
"this",
"->",
"baseFormProcessing",
"->",
"prepareResponseArray",
"(",
"'validation_failed'",
",",
"500",
",",
"$",
"data",
",",
"$",
"this",
"->",
"messages",
")",
";",
"}",
"// does the password contain the word \"password\"?",
"if",
"(",
"!",
"$",
"this",
"->",
"userRepository",
"->",
"validatePasswordNotUseWordPassword",
"(",
"$",
"data",
"[",
"'password'",
"]",
")",
")",
"{",
"// Prepare the response array, and then return to the edit form with error messages",
"// first, add the error message to the message bag",
"$",
"this",
"->",
"messages",
"->",
"add",
"(",
"'password'",
",",
"'Please do not use the word \\'password\\' in your password. This is *really* b-a-d for security.'",
")",
";",
"return",
"$",
"this",
"->",
"baseFormProcessing",
"->",
"prepareResponseArray",
"(",
"'validation_failed'",
",",
"500",
",",
"$",
"data",
",",
"$",
"this",
"->",
"messages",
")",
";",
"}",
"// does the password contain the user's name?",
"if",
"(",
"!",
"$",
"this",
"->",
"userRepository",
"->",
"validatePasswordNotUseUsername",
"(",
"$",
"data",
"[",
"'name'",
"]",
",",
"$",
"data",
"[",
"'password'",
"]",
")",
")",
"{",
"// Prepare the response array, and then return to the edit form with error messages",
"// first, add the error message to the message bag",
"$",
"this",
"->",
"messages",
"->",
"add",
"(",
"'password'",
",",
"'Please do not use your name in the password. This is *really* b-a-d for security.'",
")",
";",
"return",
"$",
"this",
"->",
"baseFormProcessing",
"->",
"prepareResponseArray",
"(",
"'validation_failed'",
",",
"500",
",",
"$",
"data",
",",
"$",
"this",
"->",
"messages",
")",
";",
"}",
"// Extra validation is ok",
"// Prepare the response array, and then return to the command",
"return",
"$",
"this",
"->",
"baseFormProcessing",
"->",
"prepareResponseArray",
"(",
"'extra_validation_successful'",
",",
"200",
",",
"$",
"data",
")",
";",
"}"
] | Perform extra validation
@param array $data
@param bool $performPhoneValidation
@return array | [
"Perform",
"extra",
"validation"
] | 5a4b3375e449273a98e84a566bcf60fd2172cb2d | https://github.com/lasallecms/lasallecms-l5-lasallecmsadmin-pkg/blob/5a4b3375e449273a98e84a566bcf60fd2172cb2d/src/FormProcessing/Users/ExtraUserValidation.php#L85-L131 | train |
Wedeto/DB | src/Query/CustomSQL.php | CustomSQL.toSQL | public function toSQL(Parameters $params, bool $inner_clause)
{
if ($inner_clause)
return '(' . $this->getSQL() . ')';
return $this->getSQL();
} | php | public function toSQL(Parameters $params, bool $inner_clause)
{
if ($inner_clause)
return '(' . $this->getSQL() . ')';
return $this->getSQL();
} | [
"public",
"function",
"toSQL",
"(",
"Parameters",
"$",
"params",
",",
"bool",
"$",
"inner_clause",
")",
"{",
"if",
"(",
"$",
"inner_clause",
")",
"return",
"'('",
".",
"$",
"this",
"->",
"getSQL",
"(",
")",
".",
"')'",
";",
"return",
"$",
"this",
"->",
"getSQL",
"(",
")",
";",
"}"
] | Add a custom SQL string to the query
@param Parameters $params The query parameters: tables and placeholder values
@return string The generated SQL | [
"Add",
"a",
"custom",
"SQL",
"string",
"to",
"the",
"query"
] | 715f8f2e3ae6b53c511c40b620921cb9c87e6f62 | https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Query/CustomSQL.php#L47-L52 | train |
CraryPrimitiveMan/php-resque | src/Resque.php | Resque.redis | public static function redis()
{
// Detect when the PID of the current process has changed (from a fork, etc)
// and force a reconnect to redis.
$pid = getmypid();
if (self::$pid !== $pid) {
self::$redis = null;
self::$pid = $pid;
}
if(!is_null(self::$redis)) {
return self::$redis;
}
$server = self::$redisServer;
if (empty($server)) {
$server = 'localhost:6379';
}
if(is_array($server)) {
self::$redis = new RedisCluster($server);
} else {
if (strpos($server, 'unix:') === false) {
list($host, $port) = explode(':', $server);
} else {
// $server is 'unix:/tmp/redis.sock'
$host = $server;
$port = null;
}
self::$redis = new Redis($host, $port);
if (!empty(self::$redisPassword)) {
self::$redis->auth(self::$redisPassword);
}
}
self::$redis->select(self::$redisDatabase);
return self::$redis;
} | php | public static function redis()
{
// Detect when the PID of the current process has changed (from a fork, etc)
// and force a reconnect to redis.
$pid = getmypid();
if (self::$pid !== $pid) {
self::$redis = null;
self::$pid = $pid;
}
if(!is_null(self::$redis)) {
return self::$redis;
}
$server = self::$redisServer;
if (empty($server)) {
$server = 'localhost:6379';
}
if(is_array($server)) {
self::$redis = new RedisCluster($server);
} else {
if (strpos($server, 'unix:') === false) {
list($host, $port) = explode(':', $server);
} else {
// $server is 'unix:/tmp/redis.sock'
$host = $server;
$port = null;
}
self::$redis = new Redis($host, $port);
if (!empty(self::$redisPassword)) {
self::$redis->auth(self::$redisPassword);
}
}
self::$redis->select(self::$redisDatabase);
return self::$redis;
} | [
"public",
"static",
"function",
"redis",
"(",
")",
"{",
"// Detect when the PID of the current process has changed (from a fork, etc)",
"// and force a reconnect to redis.",
"$",
"pid",
"=",
"getmypid",
"(",
")",
";",
"if",
"(",
"self",
"::",
"$",
"pid",
"!==",
"$",
"pid",
")",
"{",
"self",
"::",
"$",
"redis",
"=",
"null",
";",
"self",
"::",
"$",
"pid",
"=",
"$",
"pid",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"self",
"::",
"$",
"redis",
")",
")",
"{",
"return",
"self",
"::",
"$",
"redis",
";",
"}",
"$",
"server",
"=",
"self",
"::",
"$",
"redisServer",
";",
"if",
"(",
"empty",
"(",
"$",
"server",
")",
")",
"{",
"$",
"server",
"=",
"'localhost:6379'",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"server",
")",
")",
"{",
"self",
"::",
"$",
"redis",
"=",
"new",
"RedisCluster",
"(",
"$",
"server",
")",
";",
"}",
"else",
"{",
"if",
"(",
"strpos",
"(",
"$",
"server",
",",
"'unix:'",
")",
"===",
"false",
")",
"{",
"list",
"(",
"$",
"host",
",",
"$",
"port",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"server",
")",
";",
"}",
"else",
"{",
"// $server is 'unix:/tmp/redis.sock'",
"$",
"host",
"=",
"$",
"server",
";",
"$",
"port",
"=",
"null",
";",
"}",
"self",
"::",
"$",
"redis",
"=",
"new",
"Redis",
"(",
"$",
"host",
",",
"$",
"port",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"self",
"::",
"$",
"redisPassword",
")",
")",
"{",
"self",
"::",
"$",
"redis",
"->",
"auth",
"(",
"self",
"::",
"$",
"redisPassword",
")",
";",
"}",
"}",
"self",
"::",
"$",
"redis",
"->",
"select",
"(",
"self",
"::",
"$",
"redisDatabase",
")",
";",
"return",
"self",
"::",
"$",
"redis",
";",
"}"
] | Return an instance of the Redis class instantiated for Resque.
@return Redis Instance of Redis. | [
"Return",
"an",
"instance",
"of",
"the",
"Redis",
"class",
"instantiated",
"for",
"Resque",
"."
] | eff3beba81b7f5e8d6fddb8d24c8dcde6553e209 | https://github.com/CraryPrimitiveMan/php-resque/blob/eff3beba81b7f5e8d6fddb8d24c8dcde6553e209/src/Resque.php#L67-L104 | train |
ZendExperts/phpids | lib/IDS/Converter.php | IDS_Converter.runAll | public static function runAll($value)
{
foreach (get_class_methods(__CLASS__) as $method) {
if (strpos($method, 'run') === 0) {
continue;
}
$value = self::$method($value);
}
return $value;
} | php | public static function runAll($value)
{
foreach (get_class_methods(__CLASS__) as $method) {
if (strpos($method, 'run') === 0) {
continue;
}
$value = self::$method($value);
}
return $value;
} | [
"public",
"static",
"function",
"runAll",
"(",
"$",
"value",
")",
"{",
"foreach",
"(",
"get_class_methods",
"(",
"__CLASS__",
")",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"method",
",",
"'run'",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"$",
"value",
"=",
"self",
"::",
"$",
"method",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Runs all converter functions
Note that if you make use of IDS_Converter::runAll(), existing class
methods will be executed in the same order as they are implemented in the
class tree!
@param string $value the value to convert
@static
@return string | [
"Runs",
"all",
"converter",
"functions"
] | f30df04eea47b94d056e2ae9ec8fea1c626f1c03 | https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Converter.php#L65-L76 | train |
Finesse/QueryScribe | src/QueryBricks/InsertTrait.php | InsertTrait.addInsert | public function addInsert(array $rows): self
{
if (!empty($rows) && !is_array(reset($rows))) {
$rows = [$rows];
}
foreach ($rows as $index => $row) {
if (!is_array($row)) {
return $this->handleException(InvalidArgumentException::create(
'Argument $rows['.$index.']',
$row,
['array']
));
}
$filteredRow = [];
foreach ($row as $column => $value) {
if (!is_string($column)) {
return $this->handleException(InvalidArgumentException::create(
'The argument $rows['.$index.'] indexes',
$column,
['string']
));
}
$value = $this->checkScalarOrNullValue('Argument $rows['.$index.']['.$column.']', $value);
$filteredRow[$column] = $value;
}
$this->insert[] = $filteredRow;
}
return $this;
} | php | public function addInsert(array $rows): self
{
if (!empty($rows) && !is_array(reset($rows))) {
$rows = [$rows];
}
foreach ($rows as $index => $row) {
if (!is_array($row)) {
return $this->handleException(InvalidArgumentException::create(
'Argument $rows['.$index.']',
$row,
['array']
));
}
$filteredRow = [];
foreach ($row as $column => $value) {
if (!is_string($column)) {
return $this->handleException(InvalidArgumentException::create(
'The argument $rows['.$index.'] indexes',
$column,
['string']
));
}
$value = $this->checkScalarOrNullValue('Argument $rows['.$index.']['.$column.']', $value);
$filteredRow[$column] = $value;
}
$this->insert[] = $filteredRow;
}
return $this;
} | [
"public",
"function",
"addInsert",
"(",
"array",
"$",
"rows",
")",
":",
"self",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"rows",
")",
"&&",
"!",
"is_array",
"(",
"reset",
"(",
"$",
"rows",
")",
")",
")",
"{",
"$",
"rows",
"=",
"[",
"$",
"rows",
"]",
";",
"}",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"index",
"=>",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"row",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidArgumentException",
"::",
"create",
"(",
"'Argument $rows['",
".",
"$",
"index",
".",
"']'",
",",
"$",
"row",
",",
"[",
"'array'",
"]",
")",
")",
";",
"}",
"$",
"filteredRow",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"column",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidArgumentException",
"::",
"create",
"(",
"'The argument $rows['",
".",
"$",
"index",
".",
"'] indexes'",
",",
"$",
"column",
",",
"[",
"'string'",
"]",
")",
")",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"checkScalarOrNullValue",
"(",
"'Argument $rows['",
".",
"$",
"index",
".",
"']['",
".",
"$",
"column",
".",
"']'",
",",
"$",
"value",
")",
";",
"$",
"filteredRow",
"[",
"$",
"column",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"this",
"->",
"insert",
"[",
"]",
"=",
"$",
"filteredRow",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds a row to insert to the table.
Warning, calling this method removes a given insert from select.
@param mixed[][]|\Closure[][]|Query[][]|StatementInterface[][]|mixed[]|\Closure[]|Query[]|StatementInterface[] $rows
A row or an array of rows. Each row is an associative array where indexes are column names and values are
cell values. Rows indexes must be strings.
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Adds",
"a",
"row",
"to",
"insert",
"to",
"the",
"table",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/InsertTrait.php#L36-L70 | train |
Finesse/QueryScribe | src/QueryBricks/InsertTrait.php | InsertTrait.addInsertFromSelect | public function addInsertFromSelect($columns, $selectQuery = null): self
{
if ($selectQuery === null) {
$selectQuery = $columns;
$columns = null;
}
if ($columns !== null) {
if (!is_array($columns)) {
return $this->handleException(InvalidArgumentException::create(
'Argument $columns',
$columns,
['array', 'null']
));
}
foreach ($columns as $index => $column) {
if (!is_string($column)) {
return $this->handleException(InvalidArgumentException::create(
'Argument $columns['.$index.']',
$column,
['string']
));
}
}
}
$selectQuery = $this->checkSubQueryValue('Argument $selectQuery', $selectQuery);
$this->insert[] = new InsertFromSelect($columns, $selectQuery);
return $this;
} | php | public function addInsertFromSelect($columns, $selectQuery = null): self
{
if ($selectQuery === null) {
$selectQuery = $columns;
$columns = null;
}
if ($columns !== null) {
if (!is_array($columns)) {
return $this->handleException(InvalidArgumentException::create(
'Argument $columns',
$columns,
['array', 'null']
));
}
foreach ($columns as $index => $column) {
if (!is_string($column)) {
return $this->handleException(InvalidArgumentException::create(
'Argument $columns['.$index.']',
$column,
['string']
));
}
}
}
$selectQuery = $this->checkSubQueryValue('Argument $selectQuery', $selectQuery);
$this->insert[] = new InsertFromSelect($columns, $selectQuery);
return $this;
} | [
"public",
"function",
"addInsertFromSelect",
"(",
"$",
"columns",
",",
"$",
"selectQuery",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"$",
"selectQuery",
"===",
"null",
")",
"{",
"$",
"selectQuery",
"=",
"$",
"columns",
";",
"$",
"columns",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"columns",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"columns",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidArgumentException",
"::",
"create",
"(",
"'Argument $columns'",
",",
"$",
"columns",
",",
"[",
"'array'",
",",
"'null'",
"]",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"index",
"=>",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"column",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidArgumentException",
"::",
"create",
"(",
"'Argument $columns['",
".",
"$",
"index",
".",
"']'",
",",
"$",
"column",
",",
"[",
"'string'",
"]",
")",
")",
";",
"}",
"}",
"}",
"$",
"selectQuery",
"=",
"$",
"this",
"->",
"checkSubQueryValue",
"(",
"'Argument $selectQuery'",
",",
"$",
"selectQuery",
")",
";",
"$",
"this",
"->",
"insert",
"[",
"]",
"=",
"new",
"InsertFromSelect",
"(",
"$",
"columns",
",",
"$",
"selectQuery",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds an instruction that the query should insert values to the table from the select query.
Warning, calling this method removes all the rows set by the `insert` method.
@param string[]|\Closure|self|StatementInterface $columns The list of the columns to which the selected values
should be inserted. You may omit this argument and pass the $selectQuery argument instead.
@param \Closure|self|StatementInterface|null $selectQuery
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Adds",
"an",
"instruction",
"that",
"the",
"query",
"should",
"insert",
"values",
"to",
"the",
"table",
"from",
"the",
"select",
"query",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/InsertTrait.php#L84-L114 | train |
phpffcms/ffcms-core | src/Arch/Model.php | Model.validate | final public function validate(): bool
{
// validate csrf token if required
if ($this->_tokenRequired && !$this->_tokenOk) {
App::$Session->getFlashBag()->add('warning', __('Hack attention: security token is wrong!'));
return false;
}
// get all rules as array from method rules()
$rules = $this->rules();
// get default values of attributes
$defaultAttr = $this->getAllProperties();
// start validation: on this step class attribute values will be changed to input data if it valid
$success = $this->runValidate($rules);
// get not-passed validation fields as array
$badAttributes = $this->getBadAttributes();
// prevent warnings
if (Any::isArray($badAttributes) && count($badAttributes) > 0) {
foreach ($badAttributes as $attr) {
if (Str::contains('.', $attr)) { // sounds like dot-separated array attr
$attrName = strstr($attr, '.', true); // get attr name
$attrArray = trim(strstr($attr, '.'), '.'); // get dot-based array path
$defaultValue = new DotData($defaultAttr); // load default attr
$dotData = new DotData($this->{$attrName}); // load local attr variable
$dotData->set($attrArray, $defaultValue->get($attr)); // set to local prop. variable default value
$this->{$attrName} = $dotData->export(); // export to model
} else {
$this->{$attr} = $defaultAttr[$attr]; // just set ;)
}
// add message about wrong attribute to session holder, later display it
$attrLabel = $attr;
if ($this->getLabel($attr) !== null) {
$attrLabel = $this->getLabel($attr);
}
App::$Session->getFlashBag()->add('warning', __('Field "%field%" is incorrect', ['field' => $attrLabel]));
}
}
return $success;
} | php | final public function validate(): bool
{
// validate csrf token if required
if ($this->_tokenRequired && !$this->_tokenOk) {
App::$Session->getFlashBag()->add('warning', __('Hack attention: security token is wrong!'));
return false;
}
// get all rules as array from method rules()
$rules = $this->rules();
// get default values of attributes
$defaultAttr = $this->getAllProperties();
// start validation: on this step class attribute values will be changed to input data if it valid
$success = $this->runValidate($rules);
// get not-passed validation fields as array
$badAttributes = $this->getBadAttributes();
// prevent warnings
if (Any::isArray($badAttributes) && count($badAttributes) > 0) {
foreach ($badAttributes as $attr) {
if (Str::contains('.', $attr)) { // sounds like dot-separated array attr
$attrName = strstr($attr, '.', true); // get attr name
$attrArray = trim(strstr($attr, '.'), '.'); // get dot-based array path
$defaultValue = new DotData($defaultAttr); // load default attr
$dotData = new DotData($this->{$attrName}); // load local attr variable
$dotData->set($attrArray, $defaultValue->get($attr)); // set to local prop. variable default value
$this->{$attrName} = $dotData->export(); // export to model
} else {
$this->{$attr} = $defaultAttr[$attr]; // just set ;)
}
// add message about wrong attribute to session holder, later display it
$attrLabel = $attr;
if ($this->getLabel($attr) !== null) {
$attrLabel = $this->getLabel($attr);
}
App::$Session->getFlashBag()->add('warning', __('Field "%field%" is incorrect', ['field' => $attrLabel]));
}
}
return $success;
} | [
"final",
"public",
"function",
"validate",
"(",
")",
":",
"bool",
"{",
"// validate csrf token if required",
"if",
"(",
"$",
"this",
"->",
"_tokenRequired",
"&&",
"!",
"$",
"this",
"->",
"_tokenOk",
")",
"{",
"App",
"::",
"$",
"Session",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'warning'",
",",
"__",
"(",
"'Hack attention: security token is wrong!'",
")",
")",
";",
"return",
"false",
";",
"}",
"// get all rules as array from method rules()",
"$",
"rules",
"=",
"$",
"this",
"->",
"rules",
"(",
")",
";",
"// get default values of attributes",
"$",
"defaultAttr",
"=",
"$",
"this",
"->",
"getAllProperties",
"(",
")",
";",
"// start validation: on this step class attribute values will be changed to input data if it valid",
"$",
"success",
"=",
"$",
"this",
"->",
"runValidate",
"(",
"$",
"rules",
")",
";",
"// get not-passed validation fields as array",
"$",
"badAttributes",
"=",
"$",
"this",
"->",
"getBadAttributes",
"(",
")",
";",
"// prevent warnings",
"if",
"(",
"Any",
"::",
"isArray",
"(",
"$",
"badAttributes",
")",
"&&",
"count",
"(",
"$",
"badAttributes",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"badAttributes",
"as",
"$",
"attr",
")",
"{",
"if",
"(",
"Str",
"::",
"contains",
"(",
"'.'",
",",
"$",
"attr",
")",
")",
"{",
"// sounds like dot-separated array attr",
"$",
"attrName",
"=",
"strstr",
"(",
"$",
"attr",
",",
"'.'",
",",
"true",
")",
";",
"// get attr name",
"$",
"attrArray",
"=",
"trim",
"(",
"strstr",
"(",
"$",
"attr",
",",
"'.'",
")",
",",
"'.'",
")",
";",
"// get dot-based array path",
"$",
"defaultValue",
"=",
"new",
"DotData",
"(",
"$",
"defaultAttr",
")",
";",
"// load default attr",
"$",
"dotData",
"=",
"new",
"DotData",
"(",
"$",
"this",
"->",
"{",
"$",
"attrName",
"}",
")",
";",
"// load local attr variable",
"$",
"dotData",
"->",
"set",
"(",
"$",
"attrArray",
",",
"$",
"defaultValue",
"->",
"get",
"(",
"$",
"attr",
")",
")",
";",
"// set to local prop. variable default value",
"$",
"this",
"->",
"{",
"$",
"attrName",
"}",
"=",
"$",
"dotData",
"->",
"export",
"(",
")",
";",
"// export to model",
"}",
"else",
"{",
"$",
"this",
"->",
"{",
"$",
"attr",
"}",
"=",
"$",
"defaultAttr",
"[",
"$",
"attr",
"]",
";",
"// just set ;)",
"}",
"// add message about wrong attribute to session holder, later display it",
"$",
"attrLabel",
"=",
"$",
"attr",
";",
"if",
"(",
"$",
"this",
"->",
"getLabel",
"(",
"$",
"attr",
")",
"!==",
"null",
")",
"{",
"$",
"attrLabel",
"=",
"$",
"this",
"->",
"getLabel",
"(",
"$",
"attr",
")",
";",
"}",
"App",
"::",
"$",
"Session",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'warning'",
",",
"__",
"(",
"'Field \"%field%\" is incorrect'",
",",
"[",
"'field'",
"=>",
"$",
"attrLabel",
"]",
")",
")",
";",
"}",
"}",
"return",
"$",
"success",
";",
"}"
] | Validate defined rules in app
@return bool
@throws SyntaxException | [
"Validate",
"defined",
"rules",
"in",
"app"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Arch/Model.php#L89-L133 | train |
phpffcms/ffcms-core | src/Arch/Model.php | Model.getAllProperties | public function getAllProperties(): ?array
{
$properties = null;
// list all properties here, array_walk sucks on performance!
foreach ($this as $property => $value) {
if (Str::startsWith('_', $property)) {
continue;
}
$properties[$property] = $value;
}
return $properties;
} | php | public function getAllProperties(): ?array
{
$properties = null;
// list all properties here, array_walk sucks on performance!
foreach ($this as $property => $value) {
if (Str::startsWith('_', $property)) {
continue;
}
$properties[$property] = $value;
}
return $properties;
} | [
"public",
"function",
"getAllProperties",
"(",
")",
":",
"?",
"array",
"{",
"$",
"properties",
"=",
"null",
";",
"// list all properties here, array_walk sucks on performance!",
"foreach",
"(",
"$",
"this",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"Str",
"::",
"startsWith",
"(",
"'_'",
",",
"$",
"property",
")",
")",
"{",
"continue",
";",
"}",
"$",
"properties",
"[",
"$",
"property",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"properties",
";",
"}"
] | Get all properties for current model in key=>value array
@return array|null | [
"Get",
"all",
"properties",
"for",
"current",
"model",
"in",
"key",
"=",
">",
"value",
"array"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Arch/Model.php#L139-L151 | train |
phpffcms/ffcms-core | src/Arch/Model.php | Model.clearProperties | public function clearProperties(): void
{
foreach ($this as $property => $value) {
if (!Str::startsWith('_', $property)) {
$this->{$property} = null;
}
}
} | php | public function clearProperties(): void
{
foreach ($this as $property => $value) {
if (!Str::startsWith('_', $property)) {
$this->{$property} = null;
}
}
} | [
"public",
"function",
"clearProperties",
"(",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"Str",
"::",
"startsWith",
"(",
"'_'",
",",
"$",
"property",
")",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"property",
"}",
"=",
"null",
";",
"}",
"}",
"}"
] | Cleanup all public model properties
@return void | [
"Cleanup",
"all",
"public",
"model",
"properties"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Arch/Model.php#L157-L164 | train |
phpffcms/ffcms-core | src/Arch/Model.php | Model.getValidationRule | final public function getValidationRule($field): array
{
$rules = $this->rules();
$response = [];
foreach ($rules as $rule) {
if (Any::isArray($rule[0])) { // 2 or more rules [['field1', 'field2'], 'filter', 'filter_argv']
foreach ($rule[0] as $tfield) {
if ($tfield == $field) {
$response[$rule[1]] = $rule[2];
} // ['min_length' => 1, 'required' => null]
}
} else { // 1 rule ['field1', 'filter', 'filter_argv']
if ($rule[0] === $field) {
$response[$rule[1]] = $rule[2];
}
}
}
return $response;
} | php | final public function getValidationRule($field): array
{
$rules = $this->rules();
$response = [];
foreach ($rules as $rule) {
if (Any::isArray($rule[0])) { // 2 or more rules [['field1', 'field2'], 'filter', 'filter_argv']
foreach ($rule[0] as $tfield) {
if ($tfield == $field) {
$response[$rule[1]] = $rule[2];
} // ['min_length' => 1, 'required' => null]
}
} else { // 1 rule ['field1', 'filter', 'filter_argv']
if ($rule[0] === $field) {
$response[$rule[1]] = $rule[2];
}
}
}
return $response;
} | [
"final",
"public",
"function",
"getValidationRule",
"(",
"$",
"field",
")",
":",
"array",
"{",
"$",
"rules",
"=",
"$",
"this",
"->",
"rules",
"(",
")",
";",
"$",
"response",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
")",
"{",
"if",
"(",
"Any",
"::",
"isArray",
"(",
"$",
"rule",
"[",
"0",
"]",
")",
")",
"{",
"// 2 or more rules [['field1', 'field2'], 'filter', 'filter_argv']",
"foreach",
"(",
"$",
"rule",
"[",
"0",
"]",
"as",
"$",
"tfield",
")",
"{",
"if",
"(",
"$",
"tfield",
"==",
"$",
"field",
")",
"{",
"$",
"response",
"[",
"$",
"rule",
"[",
"1",
"]",
"]",
"=",
"$",
"rule",
"[",
"2",
"]",
";",
"}",
"// ['min_length' => 1, 'required' => null]",
"}",
"}",
"else",
"{",
"// 1 rule ['field1', 'filter', 'filter_argv']",
"if",
"(",
"$",
"rule",
"[",
"0",
"]",
"===",
"$",
"field",
")",
"{",
"$",
"response",
"[",
"$",
"rule",
"[",
"1",
"]",
"]",
"=",
"$",
"rule",
"[",
"2",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"response",
";",
"}"
] | Get validation rules for field
@param string $field
@return array | [
"Get",
"validation",
"rules",
"for",
"field"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Arch/Model.php#L171-L191 | train |
romm/configuration_object | Classes/Service/ServiceFactory.php | ServiceFactory.attach | public function attach($serviceClassName, array $options = [])
{
if (true === isset($this->service[$serviceClassName])) {
throw new DuplicateEntryException(
'The service "' . $serviceClassName . '" was already attached to the service factory.',
1456418859
);
}
$this->currentService = $serviceClassName;
$this->service[$serviceClassName] = [
'className' => $serviceClassName,
'options' => $options
];
return $this;
} | php | public function attach($serviceClassName, array $options = [])
{
if (true === isset($this->service[$serviceClassName])) {
throw new DuplicateEntryException(
'The service "' . $serviceClassName . '" was already attached to the service factory.',
1456418859
);
}
$this->currentService = $serviceClassName;
$this->service[$serviceClassName] = [
'className' => $serviceClassName,
'options' => $options
];
return $this;
} | [
"public",
"function",
"attach",
"(",
"$",
"serviceClassName",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"service",
"[",
"$",
"serviceClassName",
"]",
")",
")",
"{",
"throw",
"new",
"DuplicateEntryException",
"(",
"'The service \"'",
".",
"$",
"serviceClassName",
".",
"'\" was already attached to the service factory.'",
",",
"1456418859",
")",
";",
"}",
"$",
"this",
"->",
"currentService",
"=",
"$",
"serviceClassName",
";",
"$",
"this",
"->",
"service",
"[",
"$",
"serviceClassName",
"]",
"=",
"[",
"'className'",
"=>",
"$",
"serviceClassName",
",",
"'options'",
"=>",
"$",
"options",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Will attach a service to this factory.
It will also reset the current service value to the given service,
allowing the usage of the function `setOption` with this service.
@param string $serviceClassName The class name of the service which will be attached.
@param array $options Array of options which will be sent to the service.
@return $this
@throws DuplicateEntryException | [
"Will",
"attach",
"a",
"service",
"to",
"this",
"factory",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/ServiceFactory.php#L107-L123 | train |
romm/configuration_object | Classes/Service/ServiceFactory.php | ServiceFactory.get | public function get($serviceClassName)
{
if (false === $this->hasBeenInitialized) {
throw new InitializationNotSetException(
'You can get a service instance only when the service factory has been initialized.',
1456419587
);
}
if (false === $this->has($serviceClassName)) {
throw new EntryNotFoundException(
'The service "' . $serviceClassName . '" was not found in this service factory. Attach it before trying to get it!',
1456419653
);
}
return $this->serviceInstances[$serviceClassName];
} | php | public function get($serviceClassName)
{
if (false === $this->hasBeenInitialized) {
throw new InitializationNotSetException(
'You can get a service instance only when the service factory has been initialized.',
1456419587
);
}
if (false === $this->has($serviceClassName)) {
throw new EntryNotFoundException(
'The service "' . $serviceClassName . '" was not found in this service factory. Attach it before trying to get it!',
1456419653
);
}
return $this->serviceInstances[$serviceClassName];
} | [
"public",
"function",
"get",
"(",
"$",
"serviceClassName",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"hasBeenInitialized",
")",
"{",
"throw",
"new",
"InitializationNotSetException",
"(",
"'You can get a service instance only when the service factory has been initialized.'",
",",
"1456419587",
")",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"has",
"(",
"$",
"serviceClassName",
")",
")",
"{",
"throw",
"new",
"EntryNotFoundException",
"(",
"'The service \"'",
".",
"$",
"serviceClassName",
".",
"'\" was not found in this service factory. Attach it before trying to get it!'",
",",
"1456419653",
")",
";",
"}",
"return",
"$",
"this",
"->",
"serviceInstances",
"[",
"$",
"serviceClassName",
"]",
";",
"}"
] | Returns the wanted service, if it was previously registered.
@param string $serviceClassName The class name of the wanted service.
@return AbstractService
@throws InitializationNotSetException
@throws EntryNotFoundException | [
"Returns",
"the",
"wanted",
"service",
"if",
"it",
"was",
"previously",
"registered",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/ServiceFactory.php#L144-L161 | train |
romm/configuration_object | Classes/Service/ServiceFactory.php | ServiceFactory.with | public function with($serviceClassName)
{
if (false === $this->has($serviceClassName)) {
throw new Exception(
'You cannot use the function "' . __FUNCTION__ . '" on a service which was not added to the factory (service used: "' . $serviceClassName . '").',
1459425398
);
}
$this->currentService = $serviceClassName;
return $this;
} | php | public function with($serviceClassName)
{
if (false === $this->has($serviceClassName)) {
throw new Exception(
'You cannot use the function "' . __FUNCTION__ . '" on a service which was not added to the factory (service used: "' . $serviceClassName . '").',
1459425398
);
}
$this->currentService = $serviceClassName;
return $this;
} | [
"public",
"function",
"with",
"(",
"$",
"serviceClassName",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"has",
"(",
"$",
"serviceClassName",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'You cannot use the function \"'",
".",
"__FUNCTION__",
".",
"'\" on a service which was not added to the factory (service used: \"'",
".",
"$",
"serviceClassName",
".",
"'\").'",
",",
"1459425398",
")",
";",
"}",
"$",
"this",
"->",
"currentService",
"=",
"$",
"serviceClassName",
";",
"return",
"$",
"this",
";",
"}"
] | Resets the current service value to the given service, allowing the usage
of the function `setOption` with this service.
@param string $serviceClassName The class name of the service which will be saved as "current service".
@return $this
@throws Exception | [
"Resets",
"the",
"current",
"service",
"value",
"to",
"the",
"given",
"service",
"allowing",
"the",
"usage",
"of",
"the",
"function",
"setOption",
"with",
"this",
"service",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/ServiceFactory.php#L171-L183 | train |
romm/configuration_object | Classes/Service/ServiceFactory.php | ServiceFactory.getOption | public function getOption($optionName)
{
return (isset($this->service[$this->currentService]['options'][$optionName]))
? $this->service[$this->currentService]['options'][$optionName]
: null;
} | php | public function getOption($optionName)
{
return (isset($this->service[$this->currentService]['options'][$optionName]))
? $this->service[$this->currentService]['options'][$optionName]
: null;
} | [
"public",
"function",
"getOption",
"(",
"$",
"optionName",
")",
"{",
"return",
"(",
"isset",
"(",
"$",
"this",
"->",
"service",
"[",
"$",
"this",
"->",
"currentService",
"]",
"[",
"'options'",
"]",
"[",
"$",
"optionName",
"]",
")",
")",
"?",
"$",
"this",
"->",
"service",
"[",
"$",
"this",
"->",
"currentService",
"]",
"[",
"'options'",
"]",
"[",
"$",
"optionName",
"]",
":",
"null",
";",
"}"
] | Returns an option for the current service. If the option is not found,
`null` is returned.
@param string $optionName
@return mixed | [
"Returns",
"an",
"option",
"for",
"the",
"current",
"service",
".",
"If",
"the",
"option",
"is",
"not",
"found",
"null",
"is",
"returned",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/ServiceFactory.php#L215-L220 | train |
romm/configuration_object | Classes/Service/ServiceFactory.php | ServiceFactory.initialize | public function initialize()
{
if (true === $this->hasBeenInitialized) {
return;
}
$this->hasBeenInitialized = true;
foreach ($this->service as $service) {
list($serviceClassName, $serviceOptions) = $this->manageServiceData($service);
$this->serviceInstances[$serviceClassName] = $this->getServiceInstance($serviceClassName, $serviceOptions);
}
} | php | public function initialize()
{
if (true === $this->hasBeenInitialized) {
return;
}
$this->hasBeenInitialized = true;
foreach ($this->service as $service) {
list($serviceClassName, $serviceOptions) = $this->manageServiceData($service);
$this->serviceInstances[$serviceClassName] = $this->getServiceInstance($serviceClassName, $serviceOptions);
}
} | [
"public",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"hasBeenInitialized",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"hasBeenInitialized",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"service",
"as",
"$",
"service",
")",
"{",
"list",
"(",
"$",
"serviceClassName",
",",
"$",
"serviceOptions",
")",
"=",
"$",
"this",
"->",
"manageServiceData",
"(",
"$",
"service",
")",
";",
"$",
"this",
"->",
"serviceInstances",
"[",
"$",
"serviceClassName",
"]",
"=",
"$",
"this",
"->",
"getServiceInstance",
"(",
"$",
"serviceClassName",
",",
"$",
"serviceOptions",
")",
";",
"}",
"}"
] | Initializes every single service which was added in this instance.
@throws WrongInheritanceException
@internal This function is reserved for internal usage only, you should not use it in third party applications! | [
"Initializes",
"every",
"single",
"service",
"which",
"was",
"added",
"in",
"this",
"instance",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/ServiceFactory.php#L228-L241 | train |
romm/configuration_object | Classes/Service/ServiceFactory.php | ServiceFactory.runServicesFromEvent | public function runServicesFromEvent($serviceEvent, $eventMethodName, AbstractServiceDTO $dto)
{
if (false === $this->hasBeenInitialized) {
return;
}
$this->checkServiceEvent($serviceEvent);
$this->checkServiceEventMethodName($serviceEvent, $eventMethodName);
$serviceInstances = $this->getServicesFromEvent($serviceEvent);
if (count($serviceInstances) > 0) {
foreach ($serviceInstances as $serviceInstance) {
$serviceInstance->$eventMethodName($dto);
}
$serviceInstances[0]->runDelayedCallbacks($dto);
}
} | php | public function runServicesFromEvent($serviceEvent, $eventMethodName, AbstractServiceDTO $dto)
{
if (false === $this->hasBeenInitialized) {
return;
}
$this->checkServiceEvent($serviceEvent);
$this->checkServiceEventMethodName($serviceEvent, $eventMethodName);
$serviceInstances = $this->getServicesFromEvent($serviceEvent);
if (count($serviceInstances) > 0) {
foreach ($serviceInstances as $serviceInstance) {
$serviceInstance->$eventMethodName($dto);
}
$serviceInstances[0]->runDelayedCallbacks($dto);
}
} | [
"public",
"function",
"runServicesFromEvent",
"(",
"$",
"serviceEvent",
",",
"$",
"eventMethodName",
",",
"AbstractServiceDTO",
"$",
"dto",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"hasBeenInitialized",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"checkServiceEvent",
"(",
"$",
"serviceEvent",
")",
";",
"$",
"this",
"->",
"checkServiceEventMethodName",
"(",
"$",
"serviceEvent",
",",
"$",
"eventMethodName",
")",
";",
"$",
"serviceInstances",
"=",
"$",
"this",
"->",
"getServicesFromEvent",
"(",
"$",
"serviceEvent",
")",
";",
"if",
"(",
"count",
"(",
"$",
"serviceInstances",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"serviceInstances",
"as",
"$",
"serviceInstance",
")",
"{",
"$",
"serviceInstance",
"->",
"$",
"eventMethodName",
"(",
"$",
"dto",
")",
";",
"}",
"$",
"serviceInstances",
"[",
"0",
"]",
"->",
"runDelayedCallbacks",
"(",
"$",
"dto",
")",
";",
"}",
"}"
] | Will loop on each registered service in this factory, and check if they
use the requested event. If they do, the event is dispatched.
@param string $serviceEvent The class name of the service event.
@param string $eventMethodName Name of the method called in the service.
@param AbstractServiceDTO $dto The data transfer object sent to the services.
@throws Exception
@throws InvalidTypeException
@throws WrongInheritanceException
@internal This function is reserved for internal usage only, you should not use it in third party applications! | [
"Will",
"loop",
"on",
"each",
"registered",
"service",
"in",
"this",
"factory",
"and",
"check",
"if",
"they",
"use",
"the",
"requested",
"event",
".",
"If",
"they",
"do",
"the",
"event",
"is",
"dispatched",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/ServiceFactory.php#L287-L305 | train |
romm/configuration_object | Classes/Service/ServiceFactory.php | ServiceFactory.checkServiceEvent | protected function checkServiceEvent($serviceEvent)
{
if (false === isset(self::$servicesChecked[$serviceEvent])) {
self::$servicesChecked[$serviceEvent] = [];
if (false === in_array(ServiceEventInterface::class, class_implements($serviceEvent))) {
throw new WrongInheritanceException(
'Trying to run services with a wrong event: "' . $serviceEvent . '". Service events must extend "' . ServiceEventInterface::class . '".',
1456409155
);
}
}
} | php | protected function checkServiceEvent($serviceEvent)
{
if (false === isset(self::$servicesChecked[$serviceEvent])) {
self::$servicesChecked[$serviceEvent] = [];
if (false === in_array(ServiceEventInterface::class, class_implements($serviceEvent))) {
throw new WrongInheritanceException(
'Trying to run services with a wrong event: "' . $serviceEvent . '". Service events must extend "' . ServiceEventInterface::class . '".',
1456409155
);
}
}
} | [
"protected",
"function",
"checkServiceEvent",
"(",
"$",
"serviceEvent",
")",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"self",
"::",
"$",
"servicesChecked",
"[",
"$",
"serviceEvent",
"]",
")",
")",
"{",
"self",
"::",
"$",
"servicesChecked",
"[",
"$",
"serviceEvent",
"]",
"=",
"[",
"]",
";",
"if",
"(",
"false",
"===",
"in_array",
"(",
"ServiceEventInterface",
"::",
"class",
",",
"class_implements",
"(",
"$",
"serviceEvent",
")",
")",
")",
"{",
"throw",
"new",
"WrongInheritanceException",
"(",
"'Trying to run services with a wrong event: \"'",
".",
"$",
"serviceEvent",
".",
"'\". Service events must extend \"'",
".",
"ServiceEventInterface",
"::",
"class",
".",
"'\".'",
",",
"1456409155",
")",
";",
"}",
"}",
"}"
] | Will check if the class of the service event is correct and implements
the correct interface.
@param string $serviceEvent The class name of the service event.
@throws WrongInheritanceException | [
"Will",
"check",
"if",
"the",
"class",
"of",
"the",
"service",
"event",
"is",
"correct",
"and",
"implements",
"the",
"correct",
"interface",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/ServiceFactory.php#L314-L326 | train |
romm/configuration_object | Classes/Service/ServiceFactory.php | ServiceFactory.checkServiceEventMethodName | protected function checkServiceEventMethodName($serviceEvent, $eventMethodName)
{
if (false === in_array($eventMethodName, self::$servicesChecked[$serviceEvent])) {
$eventClassReflection = ReflectionService::get()->getClassReflection($serviceEvent);
self::$servicesChecked[$serviceEvent][] = $eventMethodName;
if (false === $eventClassReflection->hasMethod($eventMethodName)) {
throw new MethodNotFoundException(
'The service event "' . $serviceEvent . '" does not have a method called "' . $eventMethodName . '".',
1456509926
);
}
}
} | php | protected function checkServiceEventMethodName($serviceEvent, $eventMethodName)
{
if (false === in_array($eventMethodName, self::$servicesChecked[$serviceEvent])) {
$eventClassReflection = ReflectionService::get()->getClassReflection($serviceEvent);
self::$servicesChecked[$serviceEvent][] = $eventMethodName;
if (false === $eventClassReflection->hasMethod($eventMethodName)) {
throw new MethodNotFoundException(
'The service event "' . $serviceEvent . '" does not have a method called "' . $eventMethodName . '".',
1456509926
);
}
}
} | [
"protected",
"function",
"checkServiceEventMethodName",
"(",
"$",
"serviceEvent",
",",
"$",
"eventMethodName",
")",
"{",
"if",
"(",
"false",
"===",
"in_array",
"(",
"$",
"eventMethodName",
",",
"self",
"::",
"$",
"servicesChecked",
"[",
"$",
"serviceEvent",
"]",
")",
")",
"{",
"$",
"eventClassReflection",
"=",
"ReflectionService",
"::",
"get",
"(",
")",
"->",
"getClassReflection",
"(",
"$",
"serviceEvent",
")",
";",
"self",
"::",
"$",
"servicesChecked",
"[",
"$",
"serviceEvent",
"]",
"[",
"]",
"=",
"$",
"eventMethodName",
";",
"if",
"(",
"false",
"===",
"$",
"eventClassReflection",
"->",
"hasMethod",
"(",
"$",
"eventMethodName",
")",
")",
"{",
"throw",
"new",
"MethodNotFoundException",
"(",
"'The service event \"'",
".",
"$",
"serviceEvent",
".",
"'\" does not have a method called \"'",
".",
"$",
"eventMethodName",
".",
"'\".'",
",",
"1456509926",
")",
";",
"}",
"}",
"}"
] | Will check if the given method exists in the service event.
@param string $serviceEvent The class name of the service event.
@param string $eventMethodName Name of the method called in the service.
@throws MethodNotFoundException | [
"Will",
"check",
"if",
"the",
"given",
"method",
"exists",
"in",
"the",
"service",
"event",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/ServiceFactory.php#L335-L348 | train |
romm/configuration_object | Classes/Service/ServiceFactory.php | ServiceFactory.getServicesFromEvent | protected function getServicesFromEvent($serviceEvent)
{
if (false === isset($this->servicesEvents[$serviceEvent])) {
$servicesInstances = [];
foreach ($this->serviceInstances as $serviceInstance) {
if ($serviceInstance instanceof $serviceEvent) {
$servicesInstances[] = $serviceInstance;
}
}
$this->servicesEvents[$serviceEvent] = $servicesInstances;
}
return $this->servicesEvents[$serviceEvent];
} | php | protected function getServicesFromEvent($serviceEvent)
{
if (false === isset($this->servicesEvents[$serviceEvent])) {
$servicesInstances = [];
foreach ($this->serviceInstances as $serviceInstance) {
if ($serviceInstance instanceof $serviceEvent) {
$servicesInstances[] = $serviceInstance;
}
}
$this->servicesEvents[$serviceEvent] = $servicesInstances;
}
return $this->servicesEvents[$serviceEvent];
} | [
"protected",
"function",
"getServicesFromEvent",
"(",
"$",
"serviceEvent",
")",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"this",
"->",
"servicesEvents",
"[",
"$",
"serviceEvent",
"]",
")",
")",
"{",
"$",
"servicesInstances",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"serviceInstances",
"as",
"$",
"serviceInstance",
")",
"{",
"if",
"(",
"$",
"serviceInstance",
"instanceof",
"$",
"serviceEvent",
")",
"{",
"$",
"servicesInstances",
"[",
"]",
"=",
"$",
"serviceInstance",
";",
"}",
"}",
"$",
"this",
"->",
"servicesEvents",
"[",
"$",
"serviceEvent",
"]",
"=",
"$",
"servicesInstances",
";",
"}",
"return",
"$",
"this",
"->",
"servicesEvents",
"[",
"$",
"serviceEvent",
"]",
";",
"}"
] | Will loop trough all the services instance and get the ones which use the
given event.
@param string $serviceEvent The class name of the service event.
@return AbstractService[] | [
"Will",
"loop",
"trough",
"all",
"the",
"services",
"instance",
"and",
"get",
"the",
"ones",
"which",
"use",
"the",
"given",
"event",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Service/ServiceFactory.php#L357-L371 | train |
niridoy/LaraveIinstaller | src/Helpers/DatabaseManager.php | DatabaseManager.migrate | private function migrate($outputLog)
{
try{
DB::connection()->getPdo();
DB::unprepared(file_get_contents('core/database.sql'));
}
catch(Exception $e){
return $this->response($e->getMessage());
}
return $this->seed($outputLog);
} | php | private function migrate($outputLog)
{
try{
DB::connection()->getPdo();
DB::unprepared(file_get_contents('core/database.sql'));
}
catch(Exception $e){
return $this->response($e->getMessage());
}
return $this->seed($outputLog);
} | [
"private",
"function",
"migrate",
"(",
"$",
"outputLog",
")",
"{",
"try",
"{",
"DB",
"::",
"connection",
"(",
")",
"->",
"getPdo",
"(",
")",
";",
"DB",
"::",
"unprepared",
"(",
"file_get_contents",
"(",
"'core/database.sql'",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"seed",
"(",
"$",
"outputLog",
")",
";",
"}"
] | Run the migration and call the seeder.
@param collection $outputLog
@return collection | [
"Run",
"the",
"migration",
"and",
"call",
"the",
"seeder",
"."
] | 8339cf45bf393be57fb4e6c63179a6865028f076 | https://github.com/niridoy/LaraveIinstaller/blob/8339cf45bf393be57fb4e6c63179a6865028f076/src/Helpers/DatabaseManager.php#L34-L47 | train |
niridoy/LaraveIinstaller | src/Helpers/DatabaseManager.php | DatabaseManager.sqlite | private function sqlite($outputLog)
{
if(DB::connection() instanceof SQLiteConnection) {
$database = DB::connection()->getDatabaseName();
if(!file_exists($database)) {
touch($database);
DB::reconnect(Config::get('database.default'));
}
$outputLog->write('Using SqlLite database: ' . $database, 1);
}
} | php | private function sqlite($outputLog)
{
if(DB::connection() instanceof SQLiteConnection) {
$database = DB::connection()->getDatabaseName();
if(!file_exists($database)) {
touch($database);
DB::reconnect(Config::get('database.default'));
}
$outputLog->write('Using SqlLite database: ' . $database, 1);
}
} | [
"private",
"function",
"sqlite",
"(",
"$",
"outputLog",
")",
"{",
"if",
"(",
"DB",
"::",
"connection",
"(",
")",
"instanceof",
"SQLiteConnection",
")",
"{",
"$",
"database",
"=",
"DB",
"::",
"connection",
"(",
")",
"->",
"getDatabaseName",
"(",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"database",
")",
")",
"{",
"touch",
"(",
"$",
"database",
")",
";",
"DB",
"::",
"reconnect",
"(",
"Config",
"::",
"get",
"(",
"'database.default'",
")",
")",
";",
"}",
"$",
"outputLog",
"->",
"write",
"(",
"'Using SqlLite database: '",
".",
"$",
"database",
",",
"1",
")",
";",
"}",
"}"
] | check database type. If SQLite, then create the database file.
@param collection $outputLog | [
"check",
"database",
"type",
".",
"If",
"SQLite",
"then",
"create",
"the",
"database",
"file",
"."
] | 8339cf45bf393be57fb4e6c63179a6865028f076 | https://github.com/niridoy/LaraveIinstaller/blob/8339cf45bf393be57fb4e6c63179a6865028f076/src/Helpers/DatabaseManager.php#L91-L101 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/storagefacility/StorageFacilityFactory.php | StorageFacilityFactory.build | public function build(StorageFacilityInfo $sfInfo)
{
$storageFacility = $this->ApplicationContext->object($sfInfo->ObjectRef);
return $storageFacility;
} | php | public function build(StorageFacilityInfo $sfInfo)
{
$storageFacility = $this->ApplicationContext->object($sfInfo->ObjectRef);
return $storageFacility;
} | [
"public",
"function",
"build",
"(",
"StorageFacilityInfo",
"$",
"sfInfo",
")",
"{",
"$",
"storageFacility",
"=",
"$",
"this",
"->",
"ApplicationContext",
"->",
"object",
"(",
"$",
"sfInfo",
"->",
"ObjectRef",
")",
";",
"return",
"$",
"storageFacility",
";",
"}"
] | Get a storage facility prototype instance from the application context | [
"Get",
"a",
"storage",
"facility",
"prototype",
"instance",
"from",
"the",
"application",
"context"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/storagefacility/StorageFacilityFactory.php#L46-L50 | train |
Triun/Diff | src/Diff.php | Diff.compareFiles | public static function compareFiles($file1, $file2, $compareCharacters = false)
{
return self::compare(
file_get_contents($file1),
file_get_contents($file2),
$compareCharacters
);
} | php | public static function compareFiles($file1, $file2, $compareCharacters = false)
{
return self::compare(
file_get_contents($file1),
file_get_contents($file2),
$compareCharacters
);
} | [
"public",
"static",
"function",
"compareFiles",
"(",
"$",
"file1",
",",
"$",
"file2",
",",
"$",
"compareCharacters",
"=",
"false",
")",
"{",
"return",
"self",
"::",
"compare",
"(",
"file_get_contents",
"(",
"$",
"file1",
")",
",",
"file_get_contents",
"(",
"$",
"file2",
")",
",",
"$",
"compareCharacters",
")",
";",
"}"
] | Returns the diff for two files.
@param string $file1 the path to the first file
@param string $file2 the path to the second file
@param bool $compareCharacters true to compare characters, and false to compare lines; this optional parameter
defaults to false.
@return array | [
"Returns",
"the",
"diff",
"for",
"two",
"files",
"."
] | b5cc865b4a924bc461215f150846c3e0f7008e11 | https://github.com/Triun/Diff/blob/b5cc865b4a924bc461215f150846c3e0f7008e11/src/Diff.php#L100-L107 | train |
Triun/Diff | src/Diff.php | Diff.toString | public static function toString($diff, $separator = "\n")
{
// initialise the string
$string = '';
// loop over the lines in the diff
foreach ($diff as $line) {
// extend the string with the line
switch ($line[1]) {
case self::UNMODIFIED:
$string .= ' ' . $line[0];
break;
case self::DELETED:
$string .= '- ' . $line[0];
break;
case self::INSERTED:
$string .= '+ ' . $line[0];
break;
default:
throw new Exception('Undefined type ('.$line[1].').');
}
// extend the string with the separator
$string .= $separator;
}
return $string;
} | php | public static function toString($diff, $separator = "\n")
{
// initialise the string
$string = '';
// loop over the lines in the diff
foreach ($diff as $line) {
// extend the string with the line
switch ($line[1]) {
case self::UNMODIFIED:
$string .= ' ' . $line[0];
break;
case self::DELETED:
$string .= '- ' . $line[0];
break;
case self::INSERTED:
$string .= '+ ' . $line[0];
break;
default:
throw new Exception('Undefined type ('.$line[1].').');
}
// extend the string with the separator
$string .= $separator;
}
return $string;
} | [
"public",
"static",
"function",
"toString",
"(",
"$",
"diff",
",",
"$",
"separator",
"=",
"\"\\n\"",
")",
"{",
"// initialise the string",
"$",
"string",
"=",
"''",
";",
"// loop over the lines in the diff",
"foreach",
"(",
"$",
"diff",
"as",
"$",
"line",
")",
"{",
"// extend the string with the line",
"switch",
"(",
"$",
"line",
"[",
"1",
"]",
")",
"{",
"case",
"self",
"::",
"UNMODIFIED",
":",
"$",
"string",
".=",
"' '",
".",
"$",
"line",
"[",
"0",
"]",
";",
"break",
";",
"case",
"self",
"::",
"DELETED",
":",
"$",
"string",
".=",
"'- '",
".",
"$",
"line",
"[",
"0",
"]",
";",
"break",
";",
"case",
"self",
"::",
"INSERTED",
":",
"$",
"string",
".=",
"'+ '",
".",
"$",
"line",
"[",
"0",
"]",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Exception",
"(",
"'Undefined type ('",
".",
"$",
"line",
"[",
"1",
"]",
".",
"').'",
")",
";",
"}",
"// extend the string with the separator",
"$",
"string",
".=",
"$",
"separator",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Returns a diff as a string, where unmodified lines are prefixed by ' ', deletions are prefixed by '- ', and
insertions are prefixed by '+ '.
@param array $diff the diff array
@param string $separator the separator between lines; this optional parameter defaults to "\n"
@return string string | [
"Returns",
"a",
"diff",
"as",
"a",
"string",
"where",
"unmodified",
"lines",
"are",
"prefixed",
"by",
"deletions",
"are",
"prefixed",
"by",
"-",
"and",
"insertions",
"are",
"prefixed",
"by",
"+",
"."
] | b5cc865b4a924bc461215f150846c3e0f7008e11 | https://github.com/Triun/Diff/blob/b5cc865b4a924bc461215f150846c3e0f7008e11/src/Diff.php#L200-L227 | train |
Triun/Diff | src/Diff.php | Diff.toTable | public static function toTable($diff, $indentation = '', $separator = '<br />')
{
// initialise the HTML
$html = $indentation . "<table class=\"diff\">\n";
// loop over the lines in the diff
$index = 0;
while ($index < count($diff)) {
// determine the line type
switch ($diff[$index][1]) {
// display the content on the left and right
case self::UNMODIFIED:
$leftCell =
self::getCellContent(
$diff,
$indentation,
$separator,
$index,
self::UNMODIFIED
);
$rightCell = $leftCell;
break;
// display the deleted on the left and inserted content on the right
case self::DELETED:
$leftCell =
self::getCellContent(
$diff,
$indentation,
$separator,
$index,
self::DELETED
);
$rightCell =
self::getCellContent(
$diff,
$indentation,
$separator,
$index,
self::INSERTED
);
break;
// display the inserted content on the right
case self::INSERTED:
$leftCell = '';
$rightCell =
self::getCellContent(
$diff,
$indentation,
$separator,
$index,
self::INSERTED
);
break;
default:
throw new Exception('Undefined type ('.$diff[$index][1].').');
}
// extend the HTML with the new row
$html .=
$indentation
. " <tr>\n"
. $indentation
. ' <td class="diff'
. ($leftCell == $rightCell
? 'Unmodified'
: ($leftCell == '' ? 'Blank' : 'Deleted'))
. '">'
. $leftCell
. "</td>\n"
. $indentation
. ' <td class="diff'
. ($leftCell == $rightCell
? 'Unmodified'
: ($rightCell == '' ? 'Blank' : 'Inserted'))
. '">'
. $rightCell
. "</td>\n"
. $indentation
. " </tr>\n";
}
return $html . $indentation . "</table>\n";
} | php | public static function toTable($diff, $indentation = '', $separator = '<br />')
{
// initialise the HTML
$html = $indentation . "<table class=\"diff\">\n";
// loop over the lines in the diff
$index = 0;
while ($index < count($diff)) {
// determine the line type
switch ($diff[$index][1]) {
// display the content on the left and right
case self::UNMODIFIED:
$leftCell =
self::getCellContent(
$diff,
$indentation,
$separator,
$index,
self::UNMODIFIED
);
$rightCell = $leftCell;
break;
// display the deleted on the left and inserted content on the right
case self::DELETED:
$leftCell =
self::getCellContent(
$diff,
$indentation,
$separator,
$index,
self::DELETED
);
$rightCell =
self::getCellContent(
$diff,
$indentation,
$separator,
$index,
self::INSERTED
);
break;
// display the inserted content on the right
case self::INSERTED:
$leftCell = '';
$rightCell =
self::getCellContent(
$diff,
$indentation,
$separator,
$index,
self::INSERTED
);
break;
default:
throw new Exception('Undefined type ('.$diff[$index][1].').');
}
// extend the HTML with the new row
$html .=
$indentation
. " <tr>\n"
. $indentation
. ' <td class="diff'
. ($leftCell == $rightCell
? 'Unmodified'
: ($leftCell == '' ? 'Blank' : 'Deleted'))
. '">'
. $leftCell
. "</td>\n"
. $indentation
. ' <td class="diff'
. ($leftCell == $rightCell
? 'Unmodified'
: ($rightCell == '' ? 'Blank' : 'Inserted'))
. '">'
. $rightCell
. "</td>\n"
. $indentation
. " </tr>\n";
}
return $html . $indentation . "</table>\n";
} | [
"public",
"static",
"function",
"toTable",
"(",
"$",
"diff",
",",
"$",
"indentation",
"=",
"''",
",",
"$",
"separator",
"=",
"'<br />'",
")",
"{",
"// initialise the HTML",
"$",
"html",
"=",
"$",
"indentation",
".",
"\"<table class=\\\"diff\\\">\\n\"",
";",
"// loop over the lines in the diff",
"$",
"index",
"=",
"0",
";",
"while",
"(",
"$",
"index",
"<",
"count",
"(",
"$",
"diff",
")",
")",
"{",
"// determine the line type",
"switch",
"(",
"$",
"diff",
"[",
"$",
"index",
"]",
"[",
"1",
"]",
")",
"{",
"// display the content on the left and right",
"case",
"self",
"::",
"UNMODIFIED",
":",
"$",
"leftCell",
"=",
"self",
"::",
"getCellContent",
"(",
"$",
"diff",
",",
"$",
"indentation",
",",
"$",
"separator",
",",
"$",
"index",
",",
"self",
"::",
"UNMODIFIED",
")",
";",
"$",
"rightCell",
"=",
"$",
"leftCell",
";",
"break",
";",
"// display the deleted on the left and inserted content on the right",
"case",
"self",
"::",
"DELETED",
":",
"$",
"leftCell",
"=",
"self",
"::",
"getCellContent",
"(",
"$",
"diff",
",",
"$",
"indentation",
",",
"$",
"separator",
",",
"$",
"index",
",",
"self",
"::",
"DELETED",
")",
";",
"$",
"rightCell",
"=",
"self",
"::",
"getCellContent",
"(",
"$",
"diff",
",",
"$",
"indentation",
",",
"$",
"separator",
",",
"$",
"index",
",",
"self",
"::",
"INSERTED",
")",
";",
"break",
";",
"// display the inserted content on the right",
"case",
"self",
"::",
"INSERTED",
":",
"$",
"leftCell",
"=",
"''",
";",
"$",
"rightCell",
"=",
"self",
"::",
"getCellContent",
"(",
"$",
"diff",
",",
"$",
"indentation",
",",
"$",
"separator",
",",
"$",
"index",
",",
"self",
"::",
"INSERTED",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Exception",
"(",
"'Undefined type ('",
".",
"$",
"diff",
"[",
"$",
"index",
"]",
"[",
"1",
"]",
".",
"').'",
")",
";",
"}",
"// extend the HTML with the new row",
"$",
"html",
".=",
"$",
"indentation",
".",
"\" <tr>\\n\"",
".",
"$",
"indentation",
".",
"' <td class=\"diff'",
".",
"(",
"$",
"leftCell",
"==",
"$",
"rightCell",
"?",
"'Unmodified'",
":",
"(",
"$",
"leftCell",
"==",
"''",
"?",
"'Blank'",
":",
"'Deleted'",
")",
")",
".",
"'\">'",
".",
"$",
"leftCell",
".",
"\"</td>\\n\"",
".",
"$",
"indentation",
".",
"' <td class=\"diff'",
".",
"(",
"$",
"leftCell",
"==",
"$",
"rightCell",
"?",
"'Unmodified'",
":",
"(",
"$",
"rightCell",
"==",
"''",
"?",
"'Blank'",
":",
"'Inserted'",
")",
")",
".",
"'\">'",
".",
"$",
"rightCell",
".",
"\"</td>\\n\"",
".",
"$",
"indentation",
".",
"\" </tr>\\n\"",
";",
"}",
"return",
"$",
"html",
".",
"$",
"indentation",
".",
"\"</table>\\n\"",
";",
"}"
] | Returns a diff as an HTML table.
@param array $diff the diff array
@param string $indentation indentation to add to every line of the generated HTML; this optional parameter
defaults to ''
@param string $separator the separator between lines; this optional parameter defaults to '<br />'
@return string return the HTML
@throws Exception | [
"Returns",
"a",
"diff",
"as",
"an",
"HTML",
"table",
"."
] | b5cc865b4a924bc461215f150846c3e0f7008e11 | https://github.com/Triun/Diff/blob/b5cc865b4a924bc461215f150846c3e0f7008e11/src/Diff.php#L283-L368 | train |
joegreen88/zf1-component-validate | src/Zend/Validate/Barcode/Issn.php | Zend_Validate_Barcode_Issn.checkChars | public function checkChars($value)
{
if (strlen($value) != 8) {
if (strpos($value, 'X') !== false) {
return false;
}
}
return parent::checkChars($value);
} | php | public function checkChars($value)
{
if (strlen($value) != 8) {
if (strpos($value, 'X') !== false) {
return false;
}
}
return parent::checkChars($value);
} | [
"public",
"function",
"checkChars",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"value",
")",
"!=",
"8",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"value",
",",
"'X'",
")",
"!==",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"parent",
"::",
"checkChars",
"(",
"$",
"value",
")",
";",
"}"
] | Allows X on length of 8 chars
@param string $value The barcode to check for allowed characters
@return boolean | [
"Allows",
"X",
"on",
"length",
"of",
"8",
"chars"
] | 88d9ea016f73d48ff0ba7d06ecbbf28951fd279e | https://github.com/joegreen88/zf1-component-validate/blob/88d9ea016f73d48ff0ba7d06ecbbf28951fd279e/src/Zend/Validate/Barcode/Issn.php#L59-L68 | train |
DoSomething/mb-toolbox | src/MB_MailChimp.php | MB_MailChimp.submitSubscribe | public function submitSubscribe($listID, $composedItem = [])
{
$results = $this->mailChimp->call("lists/subscribe",
[
'id' => $listID,
'email' => [
'email' => $composedItem['email']['email']
],
'merge_vars' => $composedItem['merge_vars'],
'double_optin' => false,
'update_existing' => true,
'replace_interests' => false,
'send_welcome' => false,
]);
// Trap errors
if (isset($results['error'])) {
throw new Exception('Call to lists/subscribe returned error response: ' . $results['name'] . ': ' . $results['error']);
} elseif ($results == 0) {
throw new Exception('Hmmm: No results returned from Mailchimp lists/subscribe submission.');
}
$this->statHat->ezCount('MB_Toolbox: MB_MailChimp: submitSubscribe', 1);
return $results;
} | php | public function submitSubscribe($listID, $composedItem = [])
{
$results = $this->mailChimp->call("lists/subscribe",
[
'id' => $listID,
'email' => [
'email' => $composedItem['email']['email']
],
'merge_vars' => $composedItem['merge_vars'],
'double_optin' => false,
'update_existing' => true,
'replace_interests' => false,
'send_welcome' => false,
]);
// Trap errors
if (isset($results['error'])) {
throw new Exception('Call to lists/subscribe returned error response: ' . $results['name'] . ': ' . $results['error']);
} elseif ($results == 0) {
throw new Exception('Hmmm: No results returned from Mailchimp lists/subscribe submission.');
}
$this->statHat->ezCount('MB_Toolbox: MB_MailChimp: submitSubscribe', 1);
return $results;
} | [
"public",
"function",
"submitSubscribe",
"(",
"$",
"listID",
",",
"$",
"composedItem",
"=",
"[",
"]",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"mailChimp",
"->",
"call",
"(",
"\"lists/subscribe\"",
",",
"[",
"'id'",
"=>",
"$",
"listID",
",",
"'email'",
"=>",
"[",
"'email'",
"=>",
"$",
"composedItem",
"[",
"'email'",
"]",
"[",
"'email'",
"]",
"]",
",",
"'merge_vars'",
"=>",
"$",
"composedItem",
"[",
"'merge_vars'",
"]",
",",
"'double_optin'",
"=>",
"false",
",",
"'update_existing'",
"=>",
"true",
",",
"'replace_interests'",
"=>",
"false",
",",
"'send_welcome'",
"=>",
"false",
",",
"]",
")",
";",
"// Trap errors",
"if",
"(",
"isset",
"(",
"$",
"results",
"[",
"'error'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Call to lists/subscribe returned error response: '",
".",
"$",
"results",
"[",
"'name'",
"]",
".",
"': '",
".",
"$",
"results",
"[",
"'error'",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"results",
"==",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Hmmm: No results returned from Mailchimp lists/subscribe submission.'",
")",
";",
"}",
"$",
"this",
"->",
"statHat",
"->",
"ezCount",
"(",
"'MB_Toolbox: MB_MailChimp: submitSubscribe'",
",",
"1",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Make single signup submission to MailChimp. Typically used for resubscribes.
@param string $listID
A unique ID that defines what MailChimp list the batch should be added to
@param array $composedItem
The the details of an email address to be submitted to MailChimp
@return array
A list of the RabbitMQ queue entry IDs that have been successfully
submitted to MailChimp. | [
"Make",
"single",
"signup",
"submission",
"to",
"MailChimp",
".",
"Typically",
"used",
"for",
"resubscribes",
"."
] | ceec5fc594bae137d1ab1f447344800343b62ac6 | https://github.com/DoSomething/mb-toolbox/blob/ceec5fc594bae137d1ab1f447344800343b62ac6/src/MB_MailChimp.php#L104-L130 | train |
DoSomething/mb-toolbox | src/MB_MailChimp.php | MB_MailChimp.composeSubscriberSubmission | public function composeSubscriberSubmission($newSubscribers = [])
{
$composedSubscriberList = [];
foreach ($newSubscribers as $newSubscriberCount => $newSubscriber) {
if (isset($newSubscriber['birthdate']) && is_int($newSubscriber['birthdate'])) {
$newSubscriber['birthdate_timestamp'] = $newSubscriber['birthdate'];
}
if (isset($newSubscriber['mobile']) && strlen($newSubscriber['mobile']) < 8) {
unset($newSubscriber['mobile']);
}
// support different merge_vars for US vs UK
if (isset($newSubscriber['application_id']) && $newSubscriber['application_id'] == 'UK') {
$mergeVars = [
'FNAME' => isset($newSubscriber['fname']) ? $newSubscriber['fname'] : '',
'LNAME' => isset($newSubscriber['lname']) ? $newSubscriber['lname'] : '',
'MERGE3' => isset($newSubscriber['birthdate_timestamp']) ? date('d/m/Y',
$newSubscriber['birthdate_timestamp']) : '',
];
} // Don't add Canadian users to MailChimp
elseif (isset($newSubscriber['application_id']) && $newSubscriber['application_id'] == 'CA') {
$this->channel->basic_ack($newSubscriber['mb_delivery_tag']);
break;
} else {
$mergeVars = [
'UID' => isset($newSubscriber['uid']) ? $newSubscriber['uid'] : '',
'FNAME' => isset($newSubscriber['fname']) ? $newSubscriber['fname'] : '',
'MERGE3' => (isset($newSubscriber['fname']) && isset($newSubscriber['lname'])) ?
$newSubscriber['fname'] . $newSubscriber['lname'] : '',
'BDAY' => isset($newSubscriber['birthdate_timestamp']) ?
date('m/d', $newSubscriber['birthdate_timestamp']) : '',
'BDAYFULL' => isset($newSubscriber['birthdate_timestamp']) ?
date('m/d/Y', $newSubscriber['birthdate_timestamp']) : '',
'MOBILE' => isset($newSubscriber['mobile']) ? $newSubscriber['mobile'] : '',
];
}
// Assign source interest group. Only support on main DoSomething Members List
// @todo: Support "id" as a variable. Perhaps a config setting keyed on countries / global.
if (isset($newSubscriber['source']) &&
isset($newSubscriber['user_country']) &&
strtoupper($newSubscriber['user_country']) == 'US')
{
$mergeVars['groupings'] = [
0 => [
'id' => 10657, // DoSomething Memebers -> Import Source
'groups' => [
$newSubscriber['source']
]
],
];
}
$composedSubscriberList[$newSubscriberCount] = [
'email' => [
'email' => $newSubscriber['email']
],
'merge_vars' => $mergeVars
];
}
return $composedSubscriberList;
} | php | public function composeSubscriberSubmission($newSubscribers = [])
{
$composedSubscriberList = [];
foreach ($newSubscribers as $newSubscriberCount => $newSubscriber) {
if (isset($newSubscriber['birthdate']) && is_int($newSubscriber['birthdate'])) {
$newSubscriber['birthdate_timestamp'] = $newSubscriber['birthdate'];
}
if (isset($newSubscriber['mobile']) && strlen($newSubscriber['mobile']) < 8) {
unset($newSubscriber['mobile']);
}
// support different merge_vars for US vs UK
if (isset($newSubscriber['application_id']) && $newSubscriber['application_id'] == 'UK') {
$mergeVars = [
'FNAME' => isset($newSubscriber['fname']) ? $newSubscriber['fname'] : '',
'LNAME' => isset($newSubscriber['lname']) ? $newSubscriber['lname'] : '',
'MERGE3' => isset($newSubscriber['birthdate_timestamp']) ? date('d/m/Y',
$newSubscriber['birthdate_timestamp']) : '',
];
} // Don't add Canadian users to MailChimp
elseif (isset($newSubscriber['application_id']) && $newSubscriber['application_id'] == 'CA') {
$this->channel->basic_ack($newSubscriber['mb_delivery_tag']);
break;
} else {
$mergeVars = [
'UID' => isset($newSubscriber['uid']) ? $newSubscriber['uid'] : '',
'FNAME' => isset($newSubscriber['fname']) ? $newSubscriber['fname'] : '',
'MERGE3' => (isset($newSubscriber['fname']) && isset($newSubscriber['lname'])) ?
$newSubscriber['fname'] . $newSubscriber['lname'] : '',
'BDAY' => isset($newSubscriber['birthdate_timestamp']) ?
date('m/d', $newSubscriber['birthdate_timestamp']) : '',
'BDAYFULL' => isset($newSubscriber['birthdate_timestamp']) ?
date('m/d/Y', $newSubscriber['birthdate_timestamp']) : '',
'MOBILE' => isset($newSubscriber['mobile']) ? $newSubscriber['mobile'] : '',
];
}
// Assign source interest group. Only support on main DoSomething Members List
// @todo: Support "id" as a variable. Perhaps a config setting keyed on countries / global.
if (isset($newSubscriber['source']) &&
isset($newSubscriber['user_country']) &&
strtoupper($newSubscriber['user_country']) == 'US')
{
$mergeVars['groupings'] = [
0 => [
'id' => 10657, // DoSomething Memebers -> Import Source
'groups' => [
$newSubscriber['source']
]
],
];
}
$composedSubscriberList[$newSubscriberCount] = [
'email' => [
'email' => $newSubscriber['email']
],
'merge_vars' => $mergeVars
];
}
return $composedSubscriberList;
} | [
"public",
"function",
"composeSubscriberSubmission",
"(",
"$",
"newSubscribers",
"=",
"[",
"]",
")",
"{",
"$",
"composedSubscriberList",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"newSubscribers",
"as",
"$",
"newSubscriberCount",
"=>",
"$",
"newSubscriber",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'birthdate'",
"]",
")",
"&&",
"is_int",
"(",
"$",
"newSubscriber",
"[",
"'birthdate'",
"]",
")",
")",
"{",
"$",
"newSubscriber",
"[",
"'birthdate_timestamp'",
"]",
"=",
"$",
"newSubscriber",
"[",
"'birthdate'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'mobile'",
"]",
")",
"&&",
"strlen",
"(",
"$",
"newSubscriber",
"[",
"'mobile'",
"]",
")",
"<",
"8",
")",
"{",
"unset",
"(",
"$",
"newSubscriber",
"[",
"'mobile'",
"]",
")",
";",
"}",
"// support different merge_vars for US vs UK",
"if",
"(",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'application_id'",
"]",
")",
"&&",
"$",
"newSubscriber",
"[",
"'application_id'",
"]",
"==",
"'UK'",
")",
"{",
"$",
"mergeVars",
"=",
"[",
"'FNAME'",
"=>",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'fname'",
"]",
")",
"?",
"$",
"newSubscriber",
"[",
"'fname'",
"]",
":",
"''",
",",
"'LNAME'",
"=>",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'lname'",
"]",
")",
"?",
"$",
"newSubscriber",
"[",
"'lname'",
"]",
":",
"''",
",",
"'MERGE3'",
"=>",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'birthdate_timestamp'",
"]",
")",
"?",
"date",
"(",
"'d/m/Y'",
",",
"$",
"newSubscriber",
"[",
"'birthdate_timestamp'",
"]",
")",
":",
"''",
",",
"]",
";",
"}",
"// Don't add Canadian users to MailChimp",
"elseif",
"(",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'application_id'",
"]",
")",
"&&",
"$",
"newSubscriber",
"[",
"'application_id'",
"]",
"==",
"'CA'",
")",
"{",
"$",
"this",
"->",
"channel",
"->",
"basic_ack",
"(",
"$",
"newSubscriber",
"[",
"'mb_delivery_tag'",
"]",
")",
";",
"break",
";",
"}",
"else",
"{",
"$",
"mergeVars",
"=",
"[",
"'UID'",
"=>",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'uid'",
"]",
")",
"?",
"$",
"newSubscriber",
"[",
"'uid'",
"]",
":",
"''",
",",
"'FNAME'",
"=>",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'fname'",
"]",
")",
"?",
"$",
"newSubscriber",
"[",
"'fname'",
"]",
":",
"''",
",",
"'MERGE3'",
"=>",
"(",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'fname'",
"]",
")",
"&&",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'lname'",
"]",
")",
")",
"?",
"$",
"newSubscriber",
"[",
"'fname'",
"]",
".",
"$",
"newSubscriber",
"[",
"'lname'",
"]",
":",
"''",
",",
"'BDAY'",
"=>",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'birthdate_timestamp'",
"]",
")",
"?",
"date",
"(",
"'m/d'",
",",
"$",
"newSubscriber",
"[",
"'birthdate_timestamp'",
"]",
")",
":",
"''",
",",
"'BDAYFULL'",
"=>",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'birthdate_timestamp'",
"]",
")",
"?",
"date",
"(",
"'m/d/Y'",
",",
"$",
"newSubscriber",
"[",
"'birthdate_timestamp'",
"]",
")",
":",
"''",
",",
"'MOBILE'",
"=>",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'mobile'",
"]",
")",
"?",
"$",
"newSubscriber",
"[",
"'mobile'",
"]",
":",
"''",
",",
"]",
";",
"}",
"// Assign source interest group. Only support on main DoSomething Members List",
"// @todo: Support \"id\" as a variable. Perhaps a config setting keyed on countries / global.",
"if",
"(",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'source'",
"]",
")",
"&&",
"isset",
"(",
"$",
"newSubscriber",
"[",
"'user_country'",
"]",
")",
"&&",
"strtoupper",
"(",
"$",
"newSubscriber",
"[",
"'user_country'",
"]",
")",
"==",
"'US'",
")",
"{",
"$",
"mergeVars",
"[",
"'groupings'",
"]",
"=",
"[",
"0",
"=>",
"[",
"'id'",
"=>",
"10657",
",",
"// DoSomething Memebers -> Import Source",
"'groups'",
"=>",
"[",
"$",
"newSubscriber",
"[",
"'source'",
"]",
"]",
"]",
",",
"]",
";",
"}",
"$",
"composedSubscriberList",
"[",
"$",
"newSubscriberCount",
"]",
"=",
"[",
"'email'",
"=>",
"[",
"'email'",
"=>",
"$",
"newSubscriber",
"[",
"'email'",
"]",
"]",
",",
"'merge_vars'",
"=>",
"$",
"mergeVars",
"]",
";",
"}",
"return",
"$",
"composedSubscriberList",
";",
"}"
] | Format email list to meet MailChimp API requirements for batchSubscribe
@param array $newSubscribers
The list of email address to be formatted
@return array
Array of email addresses formatted to meet MailChimp API requirements. | [
"Format",
"email",
"list",
"to",
"meet",
"MailChimp",
"API",
"requirements",
"for",
"batchSubscribe"
] | ceec5fc594bae137d1ab1f447344800343b62ac6 | https://github.com/DoSomething/mb-toolbox/blob/ceec5fc594bae137d1ab1f447344800343b62ac6/src/MB_MailChimp.php#L141-L204 | train |
DoSomething/mb-toolbox | src/MB_MailChimp.php | MB_MailChimp.memberInfo | public function memberInfo($email, $listID)
{
$mailchimpStatus = $this->mailChimp->call("/lists/member-info", [
'id' => $listID,
'emails' => [
0 => [
'email' => $email
]
]
]);
return $mailchimpStatus;
} | php | public function memberInfo($email, $listID)
{
$mailchimpStatus = $this->mailChimp->call("/lists/member-info", [
'id' => $listID,
'emails' => [
0 => [
'email' => $email
]
]
]);
return $mailchimpStatus;
} | [
"public",
"function",
"memberInfo",
"(",
"$",
"email",
",",
"$",
"listID",
")",
"{",
"$",
"mailchimpStatus",
"=",
"$",
"this",
"->",
"mailChimp",
"->",
"call",
"(",
"\"/lists/member-info\"",
",",
"[",
"'id'",
"=>",
"$",
"listID",
",",
"'emails'",
"=>",
"[",
"0",
"=>",
"[",
"'email'",
"=>",
"$",
"email",
"]",
"]",
"]",
")",
";",
"return",
"$",
"mailchimpStatus",
";",
"}"
] | Gather account information froma specific list
Reference: http://apidocs.mailchimp.com/api/2.0/lists/member-info.php
@param string email
Target email address to lookup
@param string $listID
The list to lookup the email address on. | [
"Gather",
"account",
"information",
"froma",
"specific",
"list"
] | ceec5fc594bae137d1ab1f447344800343b62ac6 | https://github.com/DoSomething/mb-toolbox/blob/ceec5fc594bae137d1ab1f447344800343b62ac6/src/MB_MailChimp.php#L216-L229 | train |
TuumPHP/Web | src/Stack/RouterStack.php | RouterStack.match | private function match($request)
{
$route = $this->router->match(
$request->getUri()->getPath(),
$request->getMethod()
);
if (!$route) {
// not matched. dispatch the next middleware.
return $this->next ? $this->next->__invoke($request) : null;
}
return $this->dispatch($request, $route);
} | php | private function match($request)
{
$route = $this->router->match(
$request->getUri()->getPath(),
$request->getMethod()
);
if (!$route) {
// not matched. dispatch the next middleware.
return $this->next ? $this->next->__invoke($request) : null;
}
return $this->dispatch($request, $route);
} | [
"private",
"function",
"match",
"(",
"$",
"request",
")",
"{",
"$",
"route",
"=",
"$",
"this",
"->",
"router",
"->",
"match",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
",",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"route",
")",
"{",
"// not matched. dispatch the next middleware.",
"return",
"$",
"this",
"->",
"next",
"?",
"$",
"this",
"->",
"next",
"->",
"__invoke",
"(",
"$",
"request",
")",
":",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"dispatch",
"(",
"$",
"request",
",",
"$",
"route",
")",
";",
"}"
] | matches the route!
@param Request $request
@return null|Response | [
"matches",
"the",
"route!"
] | 8f296b6358aa93226ce08d6cc54a309f5b0a9820 | https://github.com/TuumPHP/Web/blob/8f296b6358aa93226ce08d6cc54a309f5b0a9820/src/Stack/RouterStack.php#L98-L109 | train |
TuumPHP/Web | src/Stack/RouterStack.php | RouterStack.dispatch | private function dispatch($request, $route)
{
if ($route->matched()) {
$request = $request->withPathToMatch($route->matched(), $route->trailing());
}
// dispatch the route!
return $this->dispatcher->withRoute($route)->__invoke($request);
} | php | private function dispatch($request, $route)
{
if ($route->matched()) {
$request = $request->withPathToMatch($route->matched(), $route->trailing());
}
// dispatch the route!
return $this->dispatcher->withRoute($route)->__invoke($request);
} | [
"private",
"function",
"dispatch",
"(",
"$",
"request",
",",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"route",
"->",
"matched",
"(",
")",
")",
"{",
"$",
"request",
"=",
"$",
"request",
"->",
"withPathToMatch",
"(",
"$",
"route",
"->",
"matched",
"(",
")",
",",
"$",
"route",
"->",
"trailing",
"(",
")",
")",
";",
"}",
"// dispatch the route!",
"return",
"$",
"this",
"->",
"dispatcher",
"->",
"withRoute",
"(",
"$",
"route",
")",
"->",
"__invoke",
"(",
"$",
"request",
")",
";",
"}"
] | execute the dispatcher and filters using blank new web application.
@param Request $request
@param Route $route
@return mixed | [
"execute",
"the",
"dispatcher",
"and",
"filters",
"using",
"blank",
"new",
"web",
"application",
"."
] | 8f296b6358aa93226ce08d6cc54a309f5b0a9820 | https://github.com/TuumPHP/Web/blob/8f296b6358aa93226ce08d6cc54a309f5b0a9820/src/Stack/RouterStack.php#L118-L125 | train |
agentmedia/phine-core | src/Core/Logic/InsertVariables/Reader.php | Reader.ParseToken | public function ParseToken($text, $startPos, &$endPos)
{
$endPos = $startPos + strlen(self::Start);
$tokenString = $this->ExtractTokenString($text, $startPos, $endPos);
if (!$tokenString)
{
return null;
}
$nextStop = 0;
$type = $this->ParseType($tokenString, $nextStop);
if (!$type)
{
return null;
}
$typeParams = $this->ParseParams($tokenString, $nextStop);
if ($typeParams === false)
{
return null;
}
$property = $this->ParseProperty($tokenString, $nextStop);
if (!$property)
{
return null;
}
$propParams = $this->ParseParams($tokenString, $nextStop);
if ($propParams === false)
{
return null;
}
$filters = $this->ParseFilters($tokenString, $nextStop);
if ($filters === false)
{
return null;
}
return new Token($type, $typeParams, $property, $propParams, $filters);
} | php | public function ParseToken($text, $startPos, &$endPos)
{
$endPos = $startPos + strlen(self::Start);
$tokenString = $this->ExtractTokenString($text, $startPos, $endPos);
if (!$tokenString)
{
return null;
}
$nextStop = 0;
$type = $this->ParseType($tokenString, $nextStop);
if (!$type)
{
return null;
}
$typeParams = $this->ParseParams($tokenString, $nextStop);
if ($typeParams === false)
{
return null;
}
$property = $this->ParseProperty($tokenString, $nextStop);
if (!$property)
{
return null;
}
$propParams = $this->ParseParams($tokenString, $nextStop);
if ($propParams === false)
{
return null;
}
$filters = $this->ParseFilters($tokenString, $nextStop);
if ($filters === false)
{
return null;
}
return new Token($type, $typeParams, $property, $propParams, $filters);
} | [
"public",
"function",
"ParseToken",
"(",
"$",
"text",
",",
"$",
"startPos",
",",
"&",
"$",
"endPos",
")",
"{",
"$",
"endPos",
"=",
"$",
"startPos",
"+",
"strlen",
"(",
"self",
"::",
"Start",
")",
";",
"$",
"tokenString",
"=",
"$",
"this",
"->",
"ExtractTokenString",
"(",
"$",
"text",
",",
"$",
"startPos",
",",
"$",
"endPos",
")",
";",
"if",
"(",
"!",
"$",
"tokenString",
")",
"{",
"return",
"null",
";",
"}",
"$",
"nextStop",
"=",
"0",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"ParseType",
"(",
"$",
"tokenString",
",",
"$",
"nextStop",
")",
";",
"if",
"(",
"!",
"$",
"type",
")",
"{",
"return",
"null",
";",
"}",
"$",
"typeParams",
"=",
"$",
"this",
"->",
"ParseParams",
"(",
"$",
"tokenString",
",",
"$",
"nextStop",
")",
";",
"if",
"(",
"$",
"typeParams",
"===",
"false",
")",
"{",
"return",
"null",
";",
"}",
"$",
"property",
"=",
"$",
"this",
"->",
"ParseProperty",
"(",
"$",
"tokenString",
",",
"$",
"nextStop",
")",
";",
"if",
"(",
"!",
"$",
"property",
")",
"{",
"return",
"null",
";",
"}",
"$",
"propParams",
"=",
"$",
"this",
"->",
"ParseParams",
"(",
"$",
"tokenString",
",",
"$",
"nextStop",
")",
";",
"if",
"(",
"$",
"propParams",
"===",
"false",
")",
"{",
"return",
"null",
";",
"}",
"$",
"filters",
"=",
"$",
"this",
"->",
"ParseFilters",
"(",
"$",
"tokenString",
",",
"$",
"nextStop",
")",
";",
"if",
"(",
"$",
"filters",
"===",
"false",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"Token",
"(",
"$",
"type",
",",
"$",
"typeParams",
",",
"$",
"property",
",",
"$",
"propParams",
",",
"$",
"filters",
")",
";",
"}"
] | Tries to parse a token beginning on the start marker
@param string $text The text
@param int $startPos The start position of the token
@param int& $endPos The end position of the token or the next position
@return Token Returns the parsed token or null if parsing failed | [
"Tries",
"to",
"parse",
"a",
"token",
"beginning",
"on",
"the",
"start",
"marker"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/InsertVariables/Reader.php#L34-L74 | train |
agentmedia/phine-core | src/Core/Logic/InsertVariables/Reader.php | Reader.ParseFilters | private function ParseFilters($tokenString, $nextStop)
{
$filters = array();
if ($nextStop === false)
{
return $filters;
}
$trimString = trim(substr($tokenString, $nextStop));
if ($trimString == '')
{
return $filters;
}
if (!Str::StartsWith(self::FilterSeparator, $trimString))
{
return false;
}
$filtersStart = strpos($tokenString, self::FilterSeparator, $nextStop) + strlen(self::FilterSeparator);
$filterNames = explode(self::FilterSeparator, substr($tokenString, $filtersStart));
foreach ($filterNames as $filterName)
{
$filter = trim($filterName);
if (!ctype_alnum($filter))
{
return false;
}
$filters[] = $filter;
}
return $filters;
} | php | private function ParseFilters($tokenString, $nextStop)
{
$filters = array();
if ($nextStop === false)
{
return $filters;
}
$trimString = trim(substr($tokenString, $nextStop));
if ($trimString == '')
{
return $filters;
}
if (!Str::StartsWith(self::FilterSeparator, $trimString))
{
return false;
}
$filtersStart = strpos($tokenString, self::FilterSeparator, $nextStop) + strlen(self::FilterSeparator);
$filterNames = explode(self::FilterSeparator, substr($tokenString, $filtersStart));
foreach ($filterNames as $filterName)
{
$filter = trim($filterName);
if (!ctype_alnum($filter))
{
return false;
}
$filters[] = $filter;
}
return $filters;
} | [
"private",
"function",
"ParseFilters",
"(",
"$",
"tokenString",
",",
"$",
"nextStop",
")",
"{",
"$",
"filters",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"nextStop",
"===",
"false",
")",
"{",
"return",
"$",
"filters",
";",
"}",
"$",
"trimString",
"=",
"trim",
"(",
"substr",
"(",
"$",
"tokenString",
",",
"$",
"nextStop",
")",
")",
";",
"if",
"(",
"$",
"trimString",
"==",
"''",
")",
"{",
"return",
"$",
"filters",
";",
"}",
"if",
"(",
"!",
"Str",
"::",
"StartsWith",
"(",
"self",
"::",
"FilterSeparator",
",",
"$",
"trimString",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"filtersStart",
"=",
"strpos",
"(",
"$",
"tokenString",
",",
"self",
"::",
"FilterSeparator",
",",
"$",
"nextStop",
")",
"+",
"strlen",
"(",
"self",
"::",
"FilterSeparator",
")",
";",
"$",
"filterNames",
"=",
"explode",
"(",
"self",
"::",
"FilterSeparator",
",",
"substr",
"(",
"$",
"tokenString",
",",
"$",
"filtersStart",
")",
")",
";",
"foreach",
"(",
"$",
"filterNames",
"as",
"$",
"filterName",
")",
"{",
"$",
"filter",
"=",
"trim",
"(",
"$",
"filterName",
")",
";",
"if",
"(",
"!",
"ctype_alnum",
"(",
"$",
"filter",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"filters",
"[",
"]",
"=",
"$",
"filter",
";",
"}",
"return",
"$",
"filters",
";",
"}"
] | Parses the filters
@return string[] Returns the filter | [
"Parses",
"the",
"filters"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/InsertVariables/Reader.php#L133-L161 | train |
agentmedia/phine-core | src/Core/Modules/Backend/UsergroupList.php | UsergroupList.RemovalObject | protected function RemovalObject()
{
$id = Request::PostData('delete');
return $id ? Usergroup::Schema()->ByID($id) : null;
} | php | protected function RemovalObject()
{
$id = Request::PostData('delete');
return $id ? Usergroup::Schema()->ByID($id) : null;
} | [
"protected",
"function",
"RemovalObject",
"(",
")",
"{",
"$",
"id",
"=",
"Request",
"::",
"PostData",
"(",
"'delete'",
")",
";",
"return",
"$",
"id",
"?",
"Usergroup",
"::",
"Schema",
"(",
")",
"->",
"ByID",
"(",
"$",
"id",
")",
":",
"null",
";",
"}"
] | The user group required for deleting
@return Usergroup | [
"The",
"user",
"group",
"required",
"for",
"deleting"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/UsergroupList.php#L40-L44 | train |
agentmedia/phine-core | src/Core/Modules/Backend/UsergroupList.php | UsergroupList.CanEdit | protected function CanEdit(Usergroup $group)
{
return self::Guard()->Allow(BackendAction::Edit(), $group)
&& self::Guard()->Allow(BackendAction::UseIt(), new UsergroupForm());
} | php | protected function CanEdit(Usergroup $group)
{
return self::Guard()->Allow(BackendAction::Edit(), $group)
&& self::Guard()->Allow(BackendAction::UseIt(), new UsergroupForm());
} | [
"protected",
"function",
"CanEdit",
"(",
"Usergroup",
"$",
"group",
")",
"{",
"return",
"self",
"::",
"Guard",
"(",
")",
"->",
"Allow",
"(",
"BackendAction",
"::",
"Edit",
"(",
")",
",",
"$",
"group",
")",
"&&",
"self",
"::",
"Guard",
"(",
")",
"->",
"Allow",
"(",
"BackendAction",
"::",
"UseIt",
"(",
")",
",",
"new",
"UsergroupForm",
"(",
")",
")",
";",
"}"
] | True if group can be edited
@param Usergroup $group
@return bool | [
"True",
"if",
"group",
"can",
"be",
"edited"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/UsergroupList.php#L56-L60 | train |
agentmedia/phine-core | src/Core/Modules/Backend/UsergroupList.php | UsergroupList.ModuleLockFormUrl | protected function ModuleLockFormUrl(Usergroup $group)
{
$args = array('usergroup' => $group->GetID());
return BackendRouter::ModuleUrl(new ModuleLockForm(), $args);
} | php | protected function ModuleLockFormUrl(Usergroup $group)
{
$args = array('usergroup' => $group->GetID());
return BackendRouter::ModuleUrl(new ModuleLockForm(), $args);
} | [
"protected",
"function",
"ModuleLockFormUrl",
"(",
"Usergroup",
"$",
"group",
")",
"{",
"$",
"args",
"=",
"array",
"(",
"'usergroup'",
"=>",
"$",
"group",
"->",
"GetID",
"(",
")",
")",
";",
"return",
"BackendRouter",
"::",
"ModuleUrl",
"(",
"new",
"ModuleLockForm",
"(",
")",
",",
"$",
"args",
")",
";",
"}"
] | Gets the url for the module lock
@param Usergroup $group
@return string | [
"Gets",
"the",
"url",
"for",
"the",
"module",
"lock"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/UsergroupList.php#L118-L122 | train |
cmsgears/module-community | frontend/controllers/GroupController.php | GroupController.behaviors | public function behaviors() {
return [
'rbac' => [
'class' => Yii::$app->cmgCore->getRbacFilterClass(),
'actions' => [
'index' => [ 'permission' => CoreGlobal::PERM_USER ],
'update' => [ 'permission' => CoreGlobal::PERM_USER ]
]
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'index' => [ 'get' ],
'update' => [ 'get', 'post' ]
]
]
];
} | php | public function behaviors() {
return [
'rbac' => [
'class' => Yii::$app->cmgCore->getRbacFilterClass(),
'actions' => [
'index' => [ 'permission' => CoreGlobal::PERM_USER ],
'update' => [ 'permission' => CoreGlobal::PERM_USER ]
]
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'index' => [ 'get' ],
'update' => [ 'get', 'post' ]
]
]
];
} | [
"public",
"function",
"behaviors",
"(",
")",
"{",
"return",
"[",
"'rbac'",
"=>",
"[",
"'class'",
"=>",
"Yii",
"::",
"$",
"app",
"->",
"cmgCore",
"->",
"getRbacFilterClass",
"(",
")",
",",
"'actions'",
"=>",
"[",
"'index'",
"=>",
"[",
"'permission'",
"=>",
"CoreGlobal",
"::",
"PERM_USER",
"]",
",",
"'update'",
"=>",
"[",
"'permission'",
"=>",
"CoreGlobal",
"::",
"PERM_USER",
"]",
"]",
"]",
",",
"'verbs'",
"=>",
"[",
"'class'",
"=>",
"VerbFilter",
"::",
"className",
"(",
")",
",",
"'actions'",
"=>",
"[",
"'index'",
"=>",
"[",
"'get'",
"]",
",",
"'update'",
"=>",
"[",
"'get'",
",",
"'post'",
"]",
"]",
"]",
"]",
";",
"}"
] | yii\base\Component | [
"yii",
"\\",
"base",
"\\",
"Component"
] | 0ca9cf0aa0cee395a4788bd6085f291e10728555 | https://github.com/cmsgears/module-community/blob/0ca9cf0aa0cee395a4788bd6085f291e10728555/frontend/controllers/GroupController.php#L39-L57 | train |
Scoilnet/PhpSDK | scoilnetsdk/OAuth2/OAuthClient.php | OAuthClient.getVariable | public function getVariable($name, $default = NULL) {
return isset($this->conf[$name]) ? $this->conf[$name] : $default;
} | php | public function getVariable($name, $default = NULL) {
return isset($this->conf[$name]) ? $this->conf[$name] : $default;
} | [
"public",
"function",
"getVariable",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"NULL",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"conf",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"conf",
"[",
"$",
"name",
"]",
":",
"$",
"default",
";",
"}"
] | Returns a persistent variable.
To avoid problems, always use lower case for persistent variable names.
@param $name
The name of the variable to return.
@param $default
The default value to use if this variable has never been set.
@return
The value of the variable. | [
"Returns",
"a",
"persistent",
"variable",
"."
] | c2d033b020015b3c9c8a741bff857e7d599f18c0 | https://github.com/Scoilnet/PhpSDK/blob/c2d033b020015b3c9c8a741bff857e7d599f18c0/scoilnetsdk/OAuth2/OAuthClient.php#L43-L45 | train |
Scoilnet/PhpSDK | scoilnetsdk/OAuth2/OAuthClient.php | OAuthClient.getAccessTokenFromAuthorizationCode | private function getAccessTokenFromAuthorizationCode($code) {
if ($this->getVariable('access_token_uri') && $this->getVariable('client_id') && $this->getVariable('client_secret')) {
return json_decode($this->makeRequest(
$this->getVariable('access_token_uri'),
'POST',
array(
'grant_type' => 'authorization_code',
'client_id' => $this->getVariable('client_id'),
'client_secret' => $this->getVariable('client_secret'),
'code' => $code,
'redirect_uri' => $this->getCurrentUri(),
)
), TRUE);
}
return NULL;
} | php | private function getAccessTokenFromAuthorizationCode($code) {
if ($this->getVariable('access_token_uri') && $this->getVariable('client_id') && $this->getVariable('client_secret')) {
return json_decode($this->makeRequest(
$this->getVariable('access_token_uri'),
'POST',
array(
'grant_type' => 'authorization_code',
'client_id' => $this->getVariable('client_id'),
'client_secret' => $this->getVariable('client_secret'),
'code' => $code,
'redirect_uri' => $this->getCurrentUri(),
)
), TRUE);
}
return NULL;
} | [
"private",
"function",
"getAccessTokenFromAuthorizationCode",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getVariable",
"(",
"'access_token_uri'",
")",
"&&",
"$",
"this",
"->",
"getVariable",
"(",
"'client_id'",
")",
"&&",
"$",
"this",
"->",
"getVariable",
"(",
"'client_secret'",
")",
")",
"{",
"return",
"json_decode",
"(",
"$",
"this",
"->",
"makeRequest",
"(",
"$",
"this",
"->",
"getVariable",
"(",
"'access_token_uri'",
")",
",",
"'POST'",
",",
"array",
"(",
"'grant_type'",
"=>",
"'authorization_code'",
",",
"'client_id'",
"=>",
"$",
"this",
"->",
"getVariable",
"(",
"'client_id'",
")",
",",
"'client_secret'",
"=>",
"$",
"this",
"->",
"getVariable",
"(",
"'client_secret'",
")",
",",
"'code'",
"=>",
"$",
"code",
",",
"'redirect_uri'",
"=>",
"$",
"this",
"->",
"getCurrentUri",
"(",
")",
",",
")",
")",
",",
"TRUE",
")",
";",
"}",
"return",
"NULL",
";",
"}"
] | Get access token from OAuth2.0 token endpoint with authorization code.
This function will only be activated if both access token URI, client
identifier and client secret are setup correctly.
@param $code
Authorization code issued by authorization server's authorization
endpoint.
@return
A valid OAuth2.0 JSON decoded access token in associative array, and
NULL if not enough parameters or JSON decode failed. | [
"Get",
"access",
"token",
"from",
"OAuth2",
".",
"0",
"token",
"endpoint",
"with",
"authorization",
"code",
"."
] | c2d033b020015b3c9c8a741bff857e7d599f18c0 | https://github.com/Scoilnet/PhpSDK/blob/c2d033b020015b3c9c8a741bff857e7d599f18c0/scoilnetsdk/OAuth2/OAuthClient.php#L360-L375 | train |
Scoilnet/PhpSDK | scoilnetsdk/OAuth2/OAuthClient.php | OAuthClient.makeRequest | protected function makeRequest($path, $method = 'GET', $params = array(), $ch = NULL) {
if (!$ch)
$ch = curl_init();
$opts = self::$CURL_OPTS;
if ($params) {
switch ($method) {
case 'GET':
$path .= '?' . http_build_query($params, NULL, '&');
break;
// Method override as we always do a POST.
default:
if ($this->getVariable('file_upload_support')) {
$opts[CURLOPT_POSTFIELDS] = $params;
}
else {
$opts[CURLOPT_POSTFIELDS] = http_build_query($params, NULL, '&');
}
}
}
$opts[CURLOPT_URL] = $path;
// Disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
// for 2 seconds if the server does not support this header.
if (isset($opts[CURLOPT_HTTPHEADER])) {
$existing_headers = $opts[CURLOPT_HTTPHEADER];
$existing_headers[] = 'Expect:';
$opts[CURLOPT_HTTPHEADER] = $existing_headers;
}
else {
$opts[CURLOPT_HTTPHEADER] = array('Expect:');
}
curl_setopt_array($ch, $opts);
//Paul: Ignore certs for the moment
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
//curl_setopt($ch, CURLOPT_CAINFO, "/path/to/cacert.pem");
$result = curl_exec($ch);
if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
error_log('Invalid or no certificate authority found, using bundled information');
curl_setopt($ch, CURLOPT_CAINFO,
dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
$result = curl_exec($ch);
}
if ($result === FALSE) {
$e = new OAuth2Exception(array(
'code' => curl_errno($ch),
'message' => curl_error($ch),
));
curl_close($ch);
throw $e;
}
curl_close($ch);
// Split the HTTP response into header and body.
list($headers, $body) = explode("\r\n\r\n", $result);
$headers = explode("\r\n", $headers);
// We catch HTTP/1.1 4xx or HTTP/1.1 5xx error response.
if (strpos($headers[0], 'HTTP/1.1 4') !== FALSE || strpos($headers[0], 'HTTP/1.1 5') !== FALSE) {
$result = array(
'code' => 0,
'message' => '',
);
if (preg_match('/^HTTP\/1.1 ([0-9]{3,3}) (.*)$/', $headers[0], $matches)) {
$result['code'] = $matches[1];
$result['message'] = $matches[2];
}
// In case retrun with WWW-Authenticate replace the description.
foreach ($headers as $header) {
if (preg_match("/^WWW-Authenticate:.*error='(.*)'/", $header, $matches)) {
$result['error'] = $matches[1];
}
}
return json_encode($result);
}
return $body;
} | php | protected function makeRequest($path, $method = 'GET', $params = array(), $ch = NULL) {
if (!$ch)
$ch = curl_init();
$opts = self::$CURL_OPTS;
if ($params) {
switch ($method) {
case 'GET':
$path .= '?' . http_build_query($params, NULL, '&');
break;
// Method override as we always do a POST.
default:
if ($this->getVariable('file_upload_support')) {
$opts[CURLOPT_POSTFIELDS] = $params;
}
else {
$opts[CURLOPT_POSTFIELDS] = http_build_query($params, NULL, '&');
}
}
}
$opts[CURLOPT_URL] = $path;
// Disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
// for 2 seconds if the server does not support this header.
if (isset($opts[CURLOPT_HTTPHEADER])) {
$existing_headers = $opts[CURLOPT_HTTPHEADER];
$existing_headers[] = 'Expect:';
$opts[CURLOPT_HTTPHEADER] = $existing_headers;
}
else {
$opts[CURLOPT_HTTPHEADER] = array('Expect:');
}
curl_setopt_array($ch, $opts);
//Paul: Ignore certs for the moment
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
//curl_setopt($ch, CURLOPT_CAINFO, "/path/to/cacert.pem");
$result = curl_exec($ch);
if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
error_log('Invalid or no certificate authority found, using bundled information');
curl_setopt($ch, CURLOPT_CAINFO,
dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
$result = curl_exec($ch);
}
if ($result === FALSE) {
$e = new OAuth2Exception(array(
'code' => curl_errno($ch),
'message' => curl_error($ch),
));
curl_close($ch);
throw $e;
}
curl_close($ch);
// Split the HTTP response into header and body.
list($headers, $body) = explode("\r\n\r\n", $result);
$headers = explode("\r\n", $headers);
// We catch HTTP/1.1 4xx or HTTP/1.1 5xx error response.
if (strpos($headers[0], 'HTTP/1.1 4') !== FALSE || strpos($headers[0], 'HTTP/1.1 5') !== FALSE) {
$result = array(
'code' => 0,
'message' => '',
);
if (preg_match('/^HTTP\/1.1 ([0-9]{3,3}) (.*)$/', $headers[0], $matches)) {
$result['code'] = $matches[1];
$result['message'] = $matches[2];
}
// In case retrun with WWW-Authenticate replace the description.
foreach ($headers as $header) {
if (preg_match("/^WWW-Authenticate:.*error='(.*)'/", $header, $matches)) {
$result['error'] = $matches[1];
}
}
return json_encode($result);
}
return $body;
} | [
"protected",
"function",
"makeRequest",
"(",
"$",
"path",
",",
"$",
"method",
"=",
"'GET'",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"ch",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"$",
"ch",
")",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"$",
"opts",
"=",
"self",
"::",
"$",
"CURL_OPTS",
";",
"if",
"(",
"$",
"params",
")",
"{",
"switch",
"(",
"$",
"method",
")",
"{",
"case",
"'GET'",
":",
"$",
"path",
".=",
"'?'",
".",
"http_build_query",
"(",
"$",
"params",
",",
"NULL",
",",
"'&'",
")",
";",
"break",
";",
"// Method override as we always do a POST.\r",
"default",
":",
"if",
"(",
"$",
"this",
"->",
"getVariable",
"(",
"'file_upload_support'",
")",
")",
"{",
"$",
"opts",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"$",
"params",
";",
"}",
"else",
"{",
"$",
"opts",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"http_build_query",
"(",
"$",
"params",
",",
"NULL",
",",
"'&'",
")",
";",
"}",
"}",
"}",
"$",
"opts",
"[",
"CURLOPT_URL",
"]",
"=",
"$",
"path",
";",
"// Disable the 'Expect: 100-continue' behaviour. This causes CURL to wait\r",
"// for 2 seconds if the server does not support this header.\r",
"if",
"(",
"isset",
"(",
"$",
"opts",
"[",
"CURLOPT_HTTPHEADER",
"]",
")",
")",
"{",
"$",
"existing_headers",
"=",
"$",
"opts",
"[",
"CURLOPT_HTTPHEADER",
"]",
";",
"$",
"existing_headers",
"[",
"]",
"=",
"'Expect:'",
";",
"$",
"opts",
"[",
"CURLOPT_HTTPHEADER",
"]",
"=",
"$",
"existing_headers",
";",
"}",
"else",
"{",
"$",
"opts",
"[",
"CURLOPT_HTTPHEADER",
"]",
"=",
"array",
"(",
"'Expect:'",
")",
";",
"}",
"curl_setopt_array",
"(",
"$",
"ch",
",",
"$",
"opts",
")",
";",
"//Paul: Ignore certs for the moment\r",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_SSL_VERIFYHOST",
",",
"0",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_SSL_VERIFYPEER",
",",
"0",
")",
";",
"//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);\r",
"//curl_setopt($ch, CURLOPT_CAINFO, \"/path/to/cacert.pem\");\r",
"$",
"result",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"if",
"(",
"curl_errno",
"(",
"$",
"ch",
")",
"==",
"60",
")",
"{",
"// CURLE_SSL_CACERT\r",
"error_log",
"(",
"'Invalid or no certificate authority found, using bundled information'",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_CAINFO",
",",
"dirname",
"(",
"__FILE__",
")",
".",
"'/fb_ca_chain_bundle.crt'",
")",
";",
"$",
"result",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"}",
"if",
"(",
"$",
"result",
"===",
"FALSE",
")",
"{",
"$",
"e",
"=",
"new",
"OAuth2Exception",
"(",
"array",
"(",
"'code'",
"=>",
"curl_errno",
"(",
"$",
"ch",
")",
",",
"'message'",
"=>",
"curl_error",
"(",
"$",
"ch",
")",
",",
")",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"throw",
"$",
"e",
";",
"}",
"curl_close",
"(",
"$",
"ch",
")",
";",
"// Split the HTTP response into header and body.\r",
"list",
"(",
"$",
"headers",
",",
"$",
"body",
")",
"=",
"explode",
"(",
"\"\\r\\n\\r\\n\"",
",",
"$",
"result",
")",
";",
"$",
"headers",
"=",
"explode",
"(",
"\"\\r\\n\"",
",",
"$",
"headers",
")",
";",
"// We catch HTTP/1.1 4xx or HTTP/1.1 5xx error response.\r",
"if",
"(",
"strpos",
"(",
"$",
"headers",
"[",
"0",
"]",
",",
"'HTTP/1.1 4'",
")",
"!==",
"FALSE",
"||",
"strpos",
"(",
"$",
"headers",
"[",
"0",
"]",
",",
"'HTTP/1.1 5'",
")",
"!==",
"FALSE",
")",
"{",
"$",
"result",
"=",
"array",
"(",
"'code'",
"=>",
"0",
",",
"'message'",
"=>",
"''",
",",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/^HTTP\\/1.1 ([0-9]{3,3}) (.*)$/'",
",",
"$",
"headers",
"[",
"0",
"]",
",",
"$",
"matches",
")",
")",
"{",
"$",
"result",
"[",
"'code'",
"]",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"result",
"[",
"'message'",
"]",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"}",
"// In case retrun with WWW-Authenticate replace the description.\r",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"header",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"/^WWW-Authenticate:.*error='(.*)'/\"",
",",
"$",
"header",
",",
"$",
"matches",
")",
")",
"{",
"$",
"result",
"[",
"'error'",
"]",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"}",
"return",
"json_encode",
"(",
"$",
"result",
")",
";",
"}",
"return",
"$",
"body",
";",
"}"
] | Makes an HTTP request.
This method can be overriden by subclasses if developers want to do
fancier things or use something other than cURL to make the request.
@param $path
The target path, relative to base_path/service_uri or an absolute URI.
@param $method
(optional) The HTTP method (default 'GET').
@param $params
(optional The GET/POST parameters.
@param $ch
(optional) An initialized curl handle
@return
The JSON decoded response object. | [
"Makes",
"an",
"HTTP",
"request",
"."
] | c2d033b020015b3c9c8a741bff857e7d599f18c0 | https://github.com/Scoilnet/PhpSDK/blob/c2d033b020015b3c9c8a741bff857e7d599f18c0/scoilnetsdk/OAuth2/OAuthClient.php#L455-L543 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.