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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
themosis/framework | src/Forms/Form.php | Form.setTheme | public function setTheme(string $theme): FieldTypeInterface
{
$this->options['theme'] = $theme;
// Update all attached fields with the given theme.
foreach ($this->repository->all() as $field) {
/** @var FieldTypeInterface $field */
$field->setTheme($theme);
}
// Update all attached groups with the given theme.
foreach ($this->repository()->getGroups() as $group) {
/** @var SectionInterface $group */
$group->setTheme($theme);
}
return $this;
} | php | public function setTheme(string $theme): FieldTypeInterface
{
$this->options['theme'] = $theme;
// Update all attached fields with the given theme.
foreach ($this->repository->all() as $field) {
/** @var FieldTypeInterface $field */
$field->setTheme($theme);
}
// Update all attached groups with the given theme.
foreach ($this->repository()->getGroups() as $group) {
/** @var SectionInterface $group */
$group->setTheme($theme);
}
return $this;
} | [
"public",
"function",
"setTheme",
"(",
"string",
"$",
"theme",
")",
":",
"FieldTypeInterface",
"{",
"$",
"this",
"->",
"options",
"[",
"'theme'",
"]",
"=",
"$",
"theme",
";",
"// Update all attached fields with the given theme.",
"foreach",
"(",
"$",
"this",
"->",
"repository",
"->",
"all",
"(",
")",
"as",
"$",
"field",
")",
"{",
"/** @var FieldTypeInterface $field */",
"$",
"field",
"->",
"setTheme",
"(",
"$",
"theme",
")",
";",
"}",
"// Update all attached groups with the given theme.",
"foreach",
"(",
"$",
"this",
"->",
"repository",
"(",
")",
"->",
"getGroups",
"(",
")",
"as",
"$",
"group",
")",
"{",
"/** @var SectionInterface $group */",
"$",
"group",
"->",
"setTheme",
"(",
"$",
"theme",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the form and attached fields theme.
@param string $theme
@return FieldTypeInterface | [
"Set",
"the",
"form",
"and",
"attached",
"fields",
"theme",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Form.php#L254-L271 | train |
themosis/framework | src/Forms/Form.php | Form.handleRequest | public function handleRequest(Request $request): FormInterface
{
$fields = $this->repository->all();
$this->validator = $this->validation->make(
$request->all(),
$this->getFormRules($fields),
$this->getFormMessages($fields),
$this->getFormPlaceholders($fields)
);
$data = $this->validator->valid();
// Attach the errors message bag to each field.
// Set each field value.
// Update the DTO instance with form data if defined.
array_walk($fields, function ($field) use ($data) {
/** @var $field BaseType */
$field->setErrorMessageBag($this->errors());
// Set the field value. Each field has its own data transformer so when we
// call the field getValue() method later on, we're sure to fetch a correct
// formatted value.
$field->setValue(Arr::get($data, $field->getName()));
// DTO
if (! is_null($this->dataClass) && is_object($this->dataClass) && $field->getOption('mapped')) {
$this->dataMapper->mapFromFieldToObject($field, $this->dataClass);
}
// By default, if the form is not valid, we keep populating fields values.
// In the case of a valid form, by default, values are flushed except if
// the "flush" option for the form has been set to true.
if ($this->validator->fails()) {
if ($field->error()) {
// Add invalid CSS classes.
$field->addAttribute('class', 'is-invalid');
} else {
// Add valid CSS classes and validate the field.
$field->addAttribute('class', 'is-valid');
}
} else {
// Validation is successful, we can flush fields value at output.
if ($this->getOption('flush', false)) {
$field['flush'] = true;
}
}
});
return $this;
} | php | public function handleRequest(Request $request): FormInterface
{
$fields = $this->repository->all();
$this->validator = $this->validation->make(
$request->all(),
$this->getFormRules($fields),
$this->getFormMessages($fields),
$this->getFormPlaceholders($fields)
);
$data = $this->validator->valid();
// Attach the errors message bag to each field.
// Set each field value.
// Update the DTO instance with form data if defined.
array_walk($fields, function ($field) use ($data) {
/** @var $field BaseType */
$field->setErrorMessageBag($this->errors());
// Set the field value. Each field has its own data transformer so when we
// call the field getValue() method later on, we're sure to fetch a correct
// formatted value.
$field->setValue(Arr::get($data, $field->getName()));
// DTO
if (! is_null($this->dataClass) && is_object($this->dataClass) && $field->getOption('mapped')) {
$this->dataMapper->mapFromFieldToObject($field, $this->dataClass);
}
// By default, if the form is not valid, we keep populating fields values.
// In the case of a valid form, by default, values are flushed except if
// the "flush" option for the form has been set to true.
if ($this->validator->fails()) {
if ($field->error()) {
// Add invalid CSS classes.
$field->addAttribute('class', 'is-invalid');
} else {
// Add valid CSS classes and validate the field.
$field->addAttribute('class', 'is-valid');
}
} else {
// Validation is successful, we can flush fields value at output.
if ($this->getOption('flush', false)) {
$field['flush'] = true;
}
}
});
return $this;
} | [
"public",
"function",
"handleRequest",
"(",
"Request",
"$",
"request",
")",
":",
"FormInterface",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"repository",
"->",
"all",
"(",
")",
";",
"$",
"this",
"->",
"validator",
"=",
"$",
"this",
"->",
"validation",
"->",
"make",
"(",
"$",
"request",
"->",
"all",
"(",
")",
",",
"$",
"this",
"->",
"getFormRules",
"(",
"$",
"fields",
")",
",",
"$",
"this",
"->",
"getFormMessages",
"(",
"$",
"fields",
")",
",",
"$",
"this",
"->",
"getFormPlaceholders",
"(",
"$",
"fields",
")",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"validator",
"->",
"valid",
"(",
")",
";",
"// Attach the errors message bag to each field.",
"// Set each field value.",
"// Update the DTO instance with form data if defined.",
"array_walk",
"(",
"$",
"fields",
",",
"function",
"(",
"$",
"field",
")",
"use",
"(",
"$",
"data",
")",
"{",
"/** @var $field BaseType */",
"$",
"field",
"->",
"setErrorMessageBag",
"(",
"$",
"this",
"->",
"errors",
"(",
")",
")",
";",
"// Set the field value. Each field has its own data transformer so when we",
"// call the field getValue() method later on, we're sure to fetch a correct",
"// formatted value.",
"$",
"field",
"->",
"setValue",
"(",
"Arr",
"::",
"get",
"(",
"$",
"data",
",",
"$",
"field",
"->",
"getName",
"(",
")",
")",
")",
";",
"// DTO",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"dataClass",
")",
"&&",
"is_object",
"(",
"$",
"this",
"->",
"dataClass",
")",
"&&",
"$",
"field",
"->",
"getOption",
"(",
"'mapped'",
")",
")",
"{",
"$",
"this",
"->",
"dataMapper",
"->",
"mapFromFieldToObject",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"dataClass",
")",
";",
"}",
"// By default, if the form is not valid, we keep populating fields values.",
"// In the case of a valid form, by default, values are flushed except if",
"// the \"flush\" option for the form has been set to true.",
"if",
"(",
"$",
"this",
"->",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"error",
"(",
")",
")",
"{",
"// Add invalid CSS classes.",
"$",
"field",
"->",
"addAttribute",
"(",
"'class'",
",",
"'is-invalid'",
")",
";",
"}",
"else",
"{",
"// Add valid CSS classes and validate the field.",
"$",
"field",
"->",
"addAttribute",
"(",
"'class'",
",",
"'is-valid'",
")",
";",
"}",
"}",
"else",
"{",
"// Validation is successful, we can flush fields value at output.",
"if",
"(",
"$",
"this",
"->",
"getOption",
"(",
"'flush'",
",",
"false",
")",
")",
"{",
"$",
"field",
"[",
"'flush'",
"]",
"=",
"true",
";",
"}",
"}",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Handle current request and start form data validation.
@param Request $request
@throws \Illuminate\Validation\ValidationException
@return $this | [
"Handle",
"current",
"request",
"and",
"start",
"form",
"data",
"validation",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Form.php#L282-L332 | train |
themosis/framework | src/Forms/Form.php | Form.getFormRules | protected function getFormRules(array $fields)
{
$rules = [];
foreach ($fields as $field) {
/** @var FieldTypeInterface $field */
$rules[$field->getName()] = $field->getOption('rules');
}
return $rules;
} | php | protected function getFormRules(array $fields)
{
$rules = [];
foreach ($fields as $field) {
/** @var FieldTypeInterface $field */
$rules[$field->getName()] = $field->getOption('rules');
}
return $rules;
} | [
"protected",
"function",
"getFormRules",
"(",
"array",
"$",
"fields",
")",
"{",
"$",
"rules",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"/** @var FieldTypeInterface $field */",
"$",
"rules",
"[",
"$",
"field",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"field",
"->",
"getOption",
"(",
"'rules'",
")",
";",
"}",
"return",
"$",
"rules",
";",
"}"
] | Get the list of form rules.
@param array $fields The form fields instances.
@return array | [
"Get",
"the",
"list",
"of",
"form",
"rules",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Form.php#L341-L351 | train |
themosis/framework | src/Forms/Form.php | Form.getFormMessages | protected function getFormMessages(array $fields)
{
// Each message is defined by field and its own rules.
// In our case, we need to prepend the field name (attribute)
// using a "dot" notation. Ex.: email.required
$messages = [];
foreach ($fields as $field) {
/** @var FieldTypeInterface $field */
foreach ($field->getOption('messages') as $attr => $message) {
$messages[$field->getName().'.'.$attr] = $message;
}
}
return $messages;
} | php | protected function getFormMessages(array $fields)
{
// Each message is defined by field and its own rules.
// In our case, we need to prepend the field name (attribute)
// using a "dot" notation. Ex.: email.required
$messages = [];
foreach ($fields as $field) {
/** @var FieldTypeInterface $field */
foreach ($field->getOption('messages') as $attr => $message) {
$messages[$field->getName().'.'.$attr] = $message;
}
}
return $messages;
} | [
"protected",
"function",
"getFormMessages",
"(",
"array",
"$",
"fields",
")",
"{",
"// Each message is defined by field and its own rules.",
"// In our case, we need to prepend the field name (attribute)",
"// using a \"dot\" notation. Ex.: email.required",
"$",
"messages",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"/** @var FieldTypeInterface $field */",
"foreach",
"(",
"$",
"field",
"->",
"getOption",
"(",
"'messages'",
")",
"as",
"$",
"attr",
"=>",
"$",
"message",
")",
"{",
"$",
"messages",
"[",
"$",
"field",
"->",
"getName",
"(",
")",
".",
"'.'",
".",
"$",
"attr",
"]",
"=",
"$",
"message",
";",
"}",
"}",
"return",
"$",
"messages",
";",
"}"
] | Get the list of form fields messages.
@param array $fields The form fields instances.
@return array | [
"Get",
"the",
"list",
"of",
"form",
"fields",
"messages",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Form.php#L360-L375 | train |
themosis/framework | src/Forms/Form.php | Form.error | public function error(string $name = '', bool $first = false)
{
$errors = $this->errors();
if (empty($name)) {
// Return all errors messages by default if the
// name argument is not specified.
return $errors->all();
}
$field = $this->repository->getFieldByName($name);
if ($first) {
return $errors->first($field->getName());
}
return $errors->get($field->getName());
} | php | public function error(string $name = '', bool $first = false)
{
$errors = $this->errors();
if (empty($name)) {
// Return all errors messages by default if the
// name argument is not specified.
return $errors->all();
}
$field = $this->repository->getFieldByName($name);
if ($first) {
return $errors->first($field->getName());
}
return $errors->get($field->getName());
} | [
"public",
"function",
"error",
"(",
"string",
"$",
"name",
"=",
"''",
",",
"bool",
"$",
"first",
"=",
"false",
")",
"{",
"$",
"errors",
"=",
"$",
"this",
"->",
"errors",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"// Return all errors messages by default if the",
"// name argument is not specified.",
"return",
"$",
"errors",
"->",
"all",
"(",
")",
";",
"}",
"$",
"field",
"=",
"$",
"this",
"->",
"repository",
"->",
"getFieldByName",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"first",
")",
"{",
"return",
"$",
"errors",
"->",
"first",
"(",
"$",
"field",
"->",
"getName",
"(",
")",
")",
";",
"}",
"return",
"$",
"errors",
"->",
"get",
"(",
"$",
"field",
"->",
"getName",
"(",
")",
")",
";",
"}"
] | Return error messages for a specific field.
By setting the second parameter to true, a user
can fetch the first error message only on the
mentioned field.
@param string $name
@param bool $first
@return string|array | [
"Return",
"error",
"messages",
"for",
"a",
"specific",
"field",
".",
"By",
"setting",
"the",
"second",
"parameter",
"to",
"true",
"a",
"user",
"can",
"fetch",
"the",
"first",
"error",
"message",
"only",
"on",
"the",
"mentioned",
"field",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Form.php#L445-L462 | train |
themosis/framework | src/Forms/Form.php | Form.render | public function render(): string
{
$view = $this->viewer->make($this->getView(), $this->getFormData());
// Indicates that the form has been rendered at least once.
// Then return its content.
$this->rendered = true;
return $view->render();
} | php | public function render(): string
{
$view = $this->viewer->make($this->getView(), $this->getFormData());
// Indicates that the form has been rendered at least once.
// Then return its content.
$this->rendered = true;
return $view->render();
} | [
"public",
"function",
"render",
"(",
")",
":",
"string",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"viewer",
"->",
"make",
"(",
"$",
"this",
"->",
"getView",
"(",
")",
",",
"$",
"this",
"->",
"getFormData",
"(",
")",
")",
";",
"// Indicates that the form has been rendered at least once.",
"// Then return its content.",
"$",
"this",
"->",
"rendered",
"=",
"true",
";",
"return",
"$",
"view",
"->",
"render",
"(",
")",
";",
"}"
] | Render a form and returns its HTML structure.
@return string | [
"Render",
"a",
"form",
"and",
"returns",
"its",
"HTML",
"structure",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Form.php#L469-L478 | train |
themosis/framework | src/Forms/Form.php | Form.setGroupView | public function setGroupView(string $view, string $group = 'default'): FormInterface
{
// Verify that the form has the mentioned group.
// If not, throw an error.
if (! $this->repository()->hasGroup($group)) {
throw new DomainException('You cannot change the view of an undefined form group.');
}
$this->repository()->getGroup($group)->setView($view);
return $this;
} | php | public function setGroupView(string $view, string $group = 'default'): FormInterface
{
// Verify that the form has the mentioned group.
// If not, throw an error.
if (! $this->repository()->hasGroup($group)) {
throw new DomainException('You cannot change the view of an undefined form group.');
}
$this->repository()->getGroup($group)->setView($view);
return $this;
} | [
"public",
"function",
"setGroupView",
"(",
"string",
"$",
"view",
",",
"string",
"$",
"group",
"=",
"'default'",
")",
":",
"FormInterface",
"{",
"// Verify that the form has the mentioned group.",
"// If not, throw an error.",
"if",
"(",
"!",
"$",
"this",
"->",
"repository",
"(",
")",
"->",
"hasGroup",
"(",
"$",
"group",
")",
")",
"{",
"throw",
"new",
"DomainException",
"(",
"'You cannot change the view of an undefined form group.'",
")",
";",
"}",
"$",
"this",
"->",
"repository",
"(",
")",
"->",
"getGroup",
"(",
"$",
"group",
")",
"->",
"setView",
"(",
"$",
"view",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set form group view file.
@param string $view
@param string $group
@return FormInterface | [
"Set",
"form",
"group",
"view",
"file",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Form.php#L503-L514 | train |
themosis/framework | src/Forms/Form.php | Form.getView | public function getView(bool $prefixed = true): string
{
if ($prefixed) {
return $this->buildViewPath($this->getTheme(), $this->view);
}
return $this->view;
} | php | public function getView(bool $prefixed = true): string
{
if ($prefixed) {
return $this->buildViewPath($this->getTheme(), $this->view);
}
return $this->view;
} | [
"public",
"function",
"getView",
"(",
"bool",
"$",
"prefixed",
"=",
"true",
")",
":",
"string",
"{",
"if",
"(",
"$",
"prefixed",
")",
"{",
"return",
"$",
"this",
"->",
"buildViewPath",
"(",
"$",
"this",
"->",
"getTheme",
"(",
")",
",",
"$",
"this",
"->",
"view",
")",
";",
"}",
"return",
"$",
"this",
"->",
"view",
";",
"}"
] | Return the view path instance used by the form.
@param bool $prefixed
@return string | [
"Return",
"the",
"view",
"path",
"instance",
"used",
"by",
"the",
"form",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Form.php#L551-L558 | train |
themosis/framework | src/Forms/Form.php | Form.validateOptions | protected function validateOptions(array $options)
{
$validated = [];
foreach ($options as $name => $option) {
if (! in_array($name, $this->getAllowedOptions())) {
throw new DomainException('The "'.$name.'" option is not allowed on the provided form.');
}
$validated[$name] = $option;
}
return $validated;
} | php | protected function validateOptions(array $options)
{
$validated = [];
foreach ($options as $name => $option) {
if (! in_array($name, $this->getAllowedOptions())) {
throw new DomainException('The "'.$name.'" option is not allowed on the provided form.');
}
$validated[$name] = $option;
}
return $validated;
} | [
"protected",
"function",
"validateOptions",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"validated",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"name",
"=>",
"$",
"option",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"getAllowedOptions",
"(",
")",
")",
")",
"{",
"throw",
"new",
"DomainException",
"(",
"'The \"'",
".",
"$",
"name",
".",
"'\" option is not allowed on the provided form.'",
")",
";",
"}",
"$",
"validated",
"[",
"$",
"name",
"]",
"=",
"$",
"option",
";",
"}",
"return",
"$",
"validated",
";",
"}"
] | Validate form options.
@param array $options
@return array | [
"Validate",
"form",
"options",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Form.php#L587-L600 | train |
themosis/framework | src/Forms/Form.php | Form.parseOptions | protected function parseOptions(array $options)
{
// Make sure to keep defined default attributes on the form.
$options['attributes'] = array_merge($this->getAttributes(), $options['attributes']);
// Define nonce default values if "method" attribute is set to "post".
if (isset($options['attributes']['method']) && 'post' === strtolower($options['attributes']['method'])) {
$options['nonce'] = $options['nonce'] ?? '_themosisnonce';
$options['nonce_action'] = $options['nonce_action'] ?? 'form';
$options['referer'] = $options['referer'] ?? true;
}
// Make sure a default theme is always defined. User cannot defined an
// empty string for the form theme.
if (! isset($this->options['theme'])) {
$this->setTheme('themosis');
}
return $options;
} | php | protected function parseOptions(array $options)
{
// Make sure to keep defined default attributes on the form.
$options['attributes'] = array_merge($this->getAttributes(), $options['attributes']);
// Define nonce default values if "method" attribute is set to "post".
if (isset($options['attributes']['method']) && 'post' === strtolower($options['attributes']['method'])) {
$options['nonce'] = $options['nonce'] ?? '_themosisnonce';
$options['nonce_action'] = $options['nonce_action'] ?? 'form';
$options['referer'] = $options['referer'] ?? true;
}
// Make sure a default theme is always defined. User cannot defined an
// empty string for the form theme.
if (! isset($this->options['theme'])) {
$this->setTheme('themosis');
}
return $options;
} | [
"protected",
"function",
"parseOptions",
"(",
"array",
"$",
"options",
")",
"{",
"// Make sure to keep defined default attributes on the form.",
"$",
"options",
"[",
"'attributes'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getAttributes",
"(",
")",
",",
"$",
"options",
"[",
"'attributes'",
"]",
")",
";",
"// Define nonce default values if \"method\" attribute is set to \"post\".",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'attributes'",
"]",
"[",
"'method'",
"]",
")",
"&&",
"'post'",
"===",
"strtolower",
"(",
"$",
"options",
"[",
"'attributes'",
"]",
"[",
"'method'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'nonce'",
"]",
"=",
"$",
"options",
"[",
"'nonce'",
"]",
"??",
"'_themosisnonce'",
";",
"$",
"options",
"[",
"'nonce_action'",
"]",
"=",
"$",
"options",
"[",
"'nonce_action'",
"]",
"??",
"'form'",
";",
"$",
"options",
"[",
"'referer'",
"]",
"=",
"$",
"options",
"[",
"'referer'",
"]",
"??",
"true",
";",
"}",
"// Make sure a default theme is always defined. User cannot defined an",
"// empty string for the form theme.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'theme'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setTheme",
"(",
"'themosis'",
")",
";",
"}",
"return",
"$",
"options",
";",
"}"
] | Parse form options and add some default parameters.
@param array $options
@return array | [
"Parse",
"form",
"options",
"and",
"add",
"some",
"default",
"parameters",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Form.php#L628-L647 | train |
themosis/framework | src/Forms/Form.php | Form.addAttribute | public function addAttribute(string $name, string $value, $overwrite = false): FieldTypeInterface
{
if (isset($this->options['attributes'][$name]) && ! $overwrite) {
$this->options['attributes'][$name] .= ' '.$value;
} else {
$this->options['attributes'][$name] = $value;
}
return $this;
} | php | public function addAttribute(string $name, string $value, $overwrite = false): FieldTypeInterface
{
if (isset($this->options['attributes'][$name]) && ! $overwrite) {
$this->options['attributes'][$name] .= ' '.$value;
} else {
$this->options['attributes'][$name] = $value;
}
return $this;
} | [
"public",
"function",
"addAttribute",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"value",
",",
"$",
"overwrite",
"=",
"false",
")",
":",
"FieldTypeInterface",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'attributes'",
"]",
"[",
"$",
"name",
"]",
")",
"&&",
"!",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'attributes'",
"]",
"[",
"$",
"name",
"]",
".=",
"' '",
".",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"options",
"[",
"'attributes'",
"]",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add an attribute to the field.
@param string $name
@param string $value
@param bool $overwrite
@return FieldTypeInterface | [
"Add",
"an",
"attribute",
"to",
"the",
"field",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Form.php#L747-L756 | train |
themosis/framework | src/Forms/FormBuilder.php | FormBuilder.validateOptions | protected function validateOptions(array $options, FieldTypeInterface $field)
{
$parsed = [];
foreach ($options as $key => $value) {
if (! in_array($key, $field->getAllowedOptions(), true)) {
throw new \DomainException('The "'.$key.'" option is not allowed on the provided field.');
}
$parsed[$key] = $value;
}
return $parsed;
} | php | protected function validateOptions(array $options, FieldTypeInterface $field)
{
$parsed = [];
foreach ($options as $key => $value) {
if (! in_array($key, $field->getAllowedOptions(), true)) {
throw new \DomainException('The "'.$key.'" option is not allowed on the provided field.');
}
$parsed[$key] = $value;
}
return $parsed;
} | [
"protected",
"function",
"validateOptions",
"(",
"array",
"$",
"options",
",",
"FieldTypeInterface",
"$",
"field",
")",
"{",
"$",
"parsed",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"field",
"->",
"getAllowedOptions",
"(",
")",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"'The \"'",
".",
"$",
"key",
".",
"'\" option is not allowed on the provided field.'",
")",
";",
"}",
"$",
"parsed",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"parsed",
";",
"}"
] | Validate the "options" used by a field instance.
@param array $options
@return array | [
"Validate",
"the",
"options",
"used",
"by",
"a",
"field",
"instance",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/FormBuilder.php#L47-L60 | train |
themosis/framework | src/Forms/FormBuilder.php | FormBuilder.add | public function add(FieldTypeInterface $field): FormBuilderInterface
{
/** @var BaseType $field */
$opts = $this->validateOptions(array_merge([
'errors' => $this->form->getOption('errors'),
'theme' => $this->form->getOption('theme')
], $field->getOptions()), $field);
$field->setLocale($this->form->getLocale());
$field->setOptions($opts);
$field->setForm($this->form);
$field->setViewFactory($this->form->getViewer());
$field->setResourceTransformerFactory($this->form->getResourceTransformerFactory());
// DTO
if (! is_null($this->dataClass) && is_object($this->dataClass) && $field->getOption('mapped')) {
$this->dataMapperManager->mapFromObjectToField($this->dataClass, $field);
}
// Check if section instance already exists on the form.
// If not, create a new section instance.
if ($this->form->repository()->hasGroup($field->getOption('group'))) {
// The section/group instance is already registered, just fetch it.
$section = $this->form->repository()->getGroup($field->getOption('group'));
} else {
// No defined group. Let's create an instance so we can attach
// the field to it right after.
$section = new Section($field->getOption('group'));
}
// Setup group/section default view.
$section->setTheme($this->form->getTheme());
$section->setView('form.group');
// Add the field first to section instance.
// Then pass both objects to the repository.
$section->addItem($field);
$this->form->repository()->addField($field, $section);
return $this;
} | php | public function add(FieldTypeInterface $field): FormBuilderInterface
{
/** @var BaseType $field */
$opts = $this->validateOptions(array_merge([
'errors' => $this->form->getOption('errors'),
'theme' => $this->form->getOption('theme')
], $field->getOptions()), $field);
$field->setLocale($this->form->getLocale());
$field->setOptions($opts);
$field->setForm($this->form);
$field->setViewFactory($this->form->getViewer());
$field->setResourceTransformerFactory($this->form->getResourceTransformerFactory());
// DTO
if (! is_null($this->dataClass) && is_object($this->dataClass) && $field->getOption('mapped')) {
$this->dataMapperManager->mapFromObjectToField($this->dataClass, $field);
}
// Check if section instance already exists on the form.
// If not, create a new section instance.
if ($this->form->repository()->hasGroup($field->getOption('group'))) {
// The section/group instance is already registered, just fetch it.
$section = $this->form->repository()->getGroup($field->getOption('group'));
} else {
// No defined group. Let's create an instance so we can attach
// the field to it right after.
$section = new Section($field->getOption('group'));
}
// Setup group/section default view.
$section->setTheme($this->form->getTheme());
$section->setView('form.group');
// Add the field first to section instance.
// Then pass both objects to the repository.
$section->addItem($field);
$this->form->repository()->addField($field, $section);
return $this;
} | [
"public",
"function",
"add",
"(",
"FieldTypeInterface",
"$",
"field",
")",
":",
"FormBuilderInterface",
"{",
"/** @var BaseType $field */",
"$",
"opts",
"=",
"$",
"this",
"->",
"validateOptions",
"(",
"array_merge",
"(",
"[",
"'errors'",
"=>",
"$",
"this",
"->",
"form",
"->",
"getOption",
"(",
"'errors'",
")",
",",
"'theme'",
"=>",
"$",
"this",
"->",
"form",
"->",
"getOption",
"(",
"'theme'",
")",
"]",
",",
"$",
"field",
"->",
"getOptions",
"(",
")",
")",
",",
"$",
"field",
")",
";",
"$",
"field",
"->",
"setLocale",
"(",
"$",
"this",
"->",
"form",
"->",
"getLocale",
"(",
")",
")",
";",
"$",
"field",
"->",
"setOptions",
"(",
"$",
"opts",
")",
";",
"$",
"field",
"->",
"setForm",
"(",
"$",
"this",
"->",
"form",
")",
";",
"$",
"field",
"->",
"setViewFactory",
"(",
"$",
"this",
"->",
"form",
"->",
"getViewer",
"(",
")",
")",
";",
"$",
"field",
"->",
"setResourceTransformerFactory",
"(",
"$",
"this",
"->",
"form",
"->",
"getResourceTransformerFactory",
"(",
")",
")",
";",
"// DTO",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"dataClass",
")",
"&&",
"is_object",
"(",
"$",
"this",
"->",
"dataClass",
")",
"&&",
"$",
"field",
"->",
"getOption",
"(",
"'mapped'",
")",
")",
"{",
"$",
"this",
"->",
"dataMapperManager",
"->",
"mapFromObjectToField",
"(",
"$",
"this",
"->",
"dataClass",
",",
"$",
"field",
")",
";",
"}",
"// Check if section instance already exists on the form.",
"// If not, create a new section instance.",
"if",
"(",
"$",
"this",
"->",
"form",
"->",
"repository",
"(",
")",
"->",
"hasGroup",
"(",
"$",
"field",
"->",
"getOption",
"(",
"'group'",
")",
")",
")",
"{",
"// The section/group instance is already registered, just fetch it.",
"$",
"section",
"=",
"$",
"this",
"->",
"form",
"->",
"repository",
"(",
")",
"->",
"getGroup",
"(",
"$",
"field",
"->",
"getOption",
"(",
"'group'",
")",
")",
";",
"}",
"else",
"{",
"// No defined group. Let's create an instance so we can attach",
"// the field to it right after.",
"$",
"section",
"=",
"new",
"Section",
"(",
"$",
"field",
"->",
"getOption",
"(",
"'group'",
")",
")",
";",
"}",
"// Setup group/section default view.",
"$",
"section",
"->",
"setTheme",
"(",
"$",
"this",
"->",
"form",
"->",
"getTheme",
"(",
")",
")",
";",
"$",
"section",
"->",
"setView",
"(",
"'form.group'",
")",
";",
"// Add the field first to section instance.",
"// Then pass both objects to the repository.",
"$",
"section",
"->",
"addItem",
"(",
"$",
"field",
")",
";",
"$",
"this",
"->",
"form",
"->",
"repository",
"(",
")",
"->",
"addField",
"(",
"$",
"field",
",",
"$",
"section",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add a field to the current form instance.
@param FieldTypeInterface $field
@return FormBuilderInterface | [
"Add",
"a",
"field",
"to",
"the",
"current",
"form",
"instance",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/FormBuilder.php#L69-L108 | train |
themosis/framework | src/Core/Bootstrap/SetRequestForConsole.php | SetRequestForConsole.bootstrap | public function bootstrap(Application $app)
{
$uri = $app->make('config')->get('app.url', 'http://localhost');
$components = parse_url($uri);
$server = $_SERVER;
if (isset($components['path'])) {
$server = array_merge($server, [
'SCRIPT_FILENAME' => $components['path'],
'SCRIPT_NAME' => $components['path']
]);
}
$app->instance('request', Request::create(
$uri,
'GET',
[],
[],
[],
$server
));
} | php | public function bootstrap(Application $app)
{
$uri = $app->make('config')->get('app.url', 'http://localhost');
$components = parse_url($uri);
$server = $_SERVER;
if (isset($components['path'])) {
$server = array_merge($server, [
'SCRIPT_FILENAME' => $components['path'],
'SCRIPT_NAME' => $components['path']
]);
}
$app->instance('request', Request::create(
$uri,
'GET',
[],
[],
[],
$server
));
} | [
"public",
"function",
"bootstrap",
"(",
"Application",
"$",
"app",
")",
"{",
"$",
"uri",
"=",
"$",
"app",
"->",
"make",
"(",
"'config'",
")",
"->",
"get",
"(",
"'app.url'",
",",
"'http://localhost'",
")",
";",
"$",
"components",
"=",
"parse_url",
"(",
"$",
"uri",
")",
";",
"$",
"server",
"=",
"$",
"_SERVER",
";",
"if",
"(",
"isset",
"(",
"$",
"components",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"server",
"=",
"array_merge",
"(",
"$",
"server",
",",
"[",
"'SCRIPT_FILENAME'",
"=>",
"$",
"components",
"[",
"'path'",
"]",
",",
"'SCRIPT_NAME'",
"=>",
"$",
"components",
"[",
"'path'",
"]",
"]",
")",
";",
"}",
"$",
"app",
"->",
"instance",
"(",
"'request'",
",",
"Request",
"::",
"create",
"(",
"$",
"uri",
",",
"'GET'",
",",
"[",
"]",
",",
"[",
"]",
",",
"[",
"]",
",",
"$",
"server",
")",
")",
";",
"}"
] | Setup the request for console application.
@param Application $app | [
"Setup",
"the",
"request",
"for",
"console",
"application",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Bootstrap/SetRequestForConsole.php#L15-L38 | train |
themosis/framework | src/User/UserServiceProvider.php | UserServiceProvider.registerUserField | protected function registerUserField()
{
$this->app->bind('themosis.user.field', function ($app) {
$viewFactory = $app['view'];
$viewFactory->addLocation(__DIR__.'/views');
return new UserField(
new FieldsRepository(),
$app['action'],
$viewFactory,
$app['validator']
);
});
} | php | protected function registerUserField()
{
$this->app->bind('themosis.user.field', function ($app) {
$viewFactory = $app['view'];
$viewFactory->addLocation(__DIR__.'/views');
return new UserField(
new FieldsRepository(),
$app['action'],
$viewFactory,
$app['validator']
);
});
} | [
"protected",
"function",
"registerUserField",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'themosis.user.field'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"viewFactory",
"=",
"$",
"app",
"[",
"'view'",
"]",
";",
"$",
"viewFactory",
"->",
"addLocation",
"(",
"__DIR__",
".",
"'/views'",
")",
";",
"return",
"new",
"UserField",
"(",
"new",
"FieldsRepository",
"(",
")",
",",
"$",
"app",
"[",
"'action'",
"]",
",",
"$",
"viewFactory",
",",
"$",
"app",
"[",
"'validator'",
"]",
")",
";",
"}",
")",
";",
"}"
] | Register the user field. | [
"Register",
"the",
"user",
"field",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/User/UserServiceProvider.php#L29-L42 | train |
themosis/framework | src/Core/Console/ModelMakeCommand.php | ModelMakeCommand.createController | protected function createController()
{
$controller = Str::studly(class_basename($this->argument('name')));
$modelName = $this->qualifyClass($this->getNameInput());
$this->call('make:controller', [
'name' => "{$controller}Controller",
'--model' => $this->option('resource') ? $modelName : null
]);
} | php | protected function createController()
{
$controller = Str::studly(class_basename($this->argument('name')));
$modelName = $this->qualifyClass($this->getNameInput());
$this->call('make:controller', [
'name' => "{$controller}Controller",
'--model' => $this->option('resource') ? $modelName : null
]);
} | [
"protected",
"function",
"createController",
"(",
")",
"{",
"$",
"controller",
"=",
"Str",
"::",
"studly",
"(",
"class_basename",
"(",
"$",
"this",
"->",
"argument",
"(",
"'name'",
")",
")",
")",
";",
"$",
"modelName",
"=",
"$",
"this",
"->",
"qualifyClass",
"(",
"$",
"this",
"->",
"getNameInput",
"(",
")",
")",
";",
"$",
"this",
"->",
"call",
"(",
"'make:controller'",
",",
"[",
"'name'",
"=>",
"\"{$controller}Controller\"",
",",
"'--model'",
"=>",
"$",
"this",
"->",
"option",
"(",
"'resource'",
")",
"?",
"$",
"modelName",
":",
"null",
"]",
")",
";",
"}"
] | Create a controller for the model. | [
"Create",
"a",
"controller",
"for",
"the",
"model",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/ModelMakeCommand.php#L88-L97 | train |
themosis/framework | src/Core/Theme/ImageSize.php | ImageSize.parse | protected function parse(array $sizes)
{
$images = [];
foreach ($sizes as $slug => $properties) {
list($width, $height, $crop, $label) = $this->parseProperties($properties, $slug);
$images[$slug] = [
'width' => $width,
'height' => $height,
'crop' => $crop,
'label' => $label
];
}
return $images;
} | php | protected function parse(array $sizes)
{
$images = [];
foreach ($sizes as $slug => $properties) {
list($width, $height, $crop, $label) = $this->parseProperties($properties, $slug);
$images[$slug] = [
'width' => $width,
'height' => $height,
'crop' => $crop,
'label' => $label
];
}
return $images;
} | [
"protected",
"function",
"parse",
"(",
"array",
"$",
"sizes",
")",
"{",
"$",
"images",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sizes",
"as",
"$",
"slug",
"=>",
"$",
"properties",
")",
"{",
"list",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"crop",
",",
"$",
"label",
")",
"=",
"$",
"this",
"->",
"parseProperties",
"(",
"$",
"properties",
",",
"$",
"slug",
")",
";",
"$",
"images",
"[",
"$",
"slug",
"]",
"=",
"[",
"'width'",
"=>",
"$",
"width",
",",
"'height'",
"=>",
"$",
"height",
",",
"'crop'",
"=>",
"$",
"crop",
",",
"'label'",
"=>",
"$",
"label",
"]",
";",
"}",
"return",
"$",
"images",
";",
"}"
] | Parse the images sizes.
@param array $sizes
@return array | [
"Parse",
"the",
"images",
"sizes",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Theme/ImageSize.php#L34-L50 | train |
themosis/framework | src/Core/Theme/ImageSize.php | ImageSize.parseProperties | protected function parseProperties(array $properties, string $slug)
{
switch (count($properties)) {
case 1:
// Square with defaults.
return [$properties[0], $properties[0], false, false];
break;
case 2:
// Custom size with defaults.
return [$properties[0], $properties[1], false, false];
break;
case 3:
// Custom size with custom crop option.
return [$properties[0], $properties[1], $properties[2], false];
break;
case 4:
default:
// All properties with custom label.
$label = (is_bool($properties[3]) && true === $properties[3]) ? $this->label($slug) : $properties[3];
return [$properties[0], $properties[1], $properties[2], $label];
}
} | php | protected function parseProperties(array $properties, string $slug)
{
switch (count($properties)) {
case 1:
// Square with defaults.
return [$properties[0], $properties[0], false, false];
break;
case 2:
// Custom size with defaults.
return [$properties[0], $properties[1], false, false];
break;
case 3:
// Custom size with custom crop option.
return [$properties[0], $properties[1], $properties[2], false];
break;
case 4:
default:
// All properties with custom label.
$label = (is_bool($properties[3]) && true === $properties[3]) ? $this->label($slug) : $properties[3];
return [$properties[0], $properties[1], $properties[2], $label];
}
} | [
"protected",
"function",
"parseProperties",
"(",
"array",
"$",
"properties",
",",
"string",
"$",
"slug",
")",
"{",
"switch",
"(",
"count",
"(",
"$",
"properties",
")",
")",
"{",
"case",
"1",
":",
"// Square with defaults.",
"return",
"[",
"$",
"properties",
"[",
"0",
"]",
",",
"$",
"properties",
"[",
"0",
"]",
",",
"false",
",",
"false",
"]",
";",
"break",
";",
"case",
"2",
":",
"// Custom size with defaults.",
"return",
"[",
"$",
"properties",
"[",
"0",
"]",
",",
"$",
"properties",
"[",
"1",
"]",
",",
"false",
",",
"false",
"]",
";",
"break",
";",
"case",
"3",
":",
"// Custom size with custom crop option.",
"return",
"[",
"$",
"properties",
"[",
"0",
"]",
",",
"$",
"properties",
"[",
"1",
"]",
",",
"$",
"properties",
"[",
"2",
"]",
",",
"false",
"]",
";",
"break",
";",
"case",
"4",
":",
"default",
":",
"// All properties with custom label.",
"$",
"label",
"=",
"(",
"is_bool",
"(",
"$",
"properties",
"[",
"3",
"]",
")",
"&&",
"true",
"===",
"$",
"properties",
"[",
"3",
"]",
")",
"?",
"$",
"this",
"->",
"label",
"(",
"$",
"slug",
")",
":",
"$",
"properties",
"[",
"3",
"]",
";",
"return",
"[",
"$",
"properties",
"[",
"0",
"]",
",",
"$",
"properties",
"[",
"1",
"]",
",",
"$",
"properties",
"[",
"2",
"]",
",",
"$",
"label",
"]",
";",
"}",
"}"
] | Parse image properties.
@param array $properties
@param string $slug
@return array | [
"Parse",
"image",
"properties",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Theme/ImageSize.php#L60-L82 | train |
themosis/framework | src/Core/Theme/ImageSize.php | ImageSize.addToDropDown | public function addToDropDown(array $options)
{
foreach ($this->sizes as $slug => $props) {
if ($props['label'] && ! isset($options[$slug])) {
$options[$slug] = $props['label'];
}
}
return $options;
} | php | public function addToDropDown(array $options)
{
foreach ($this->sizes as $slug => $props) {
if ($props['label'] && ! isset($options[$slug])) {
$options[$slug] = $props['label'];
}
}
return $options;
} | [
"public",
"function",
"addToDropDown",
"(",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"sizes",
"as",
"$",
"slug",
"=>",
"$",
"props",
")",
"{",
"if",
"(",
"$",
"props",
"[",
"'label'",
"]",
"&&",
"!",
"isset",
"(",
"$",
"options",
"[",
"$",
"slug",
"]",
")",
")",
"{",
"$",
"options",
"[",
"$",
"slug",
"]",
"=",
"$",
"props",
"[",
"'label'",
"]",
";",
"}",
"}",
"return",
"$",
"options",
";",
"}"
] | Filter media size drop down options. Add user custom image sizes.
@param array $options
@return array | [
"Filter",
"media",
"size",
"drop",
"down",
"options",
".",
"Add",
"user",
"custom",
"image",
"sizes",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Theme/ImageSize.php#L133-L142 | train |
themosis/framework | src/Core/Console/RouteCacheCommand.php | RouteCacheCommand.getFreshApplicationRoutes | protected function getFreshApplicationRoutes()
{
return tap($this->getFreshApplication()['router']->getRoutes(), function ($routes) {
/** @var RouteCollection $routes */
$routes->refreshNameLookups();
$routes->refreshActionLookups();
});
} | php | protected function getFreshApplicationRoutes()
{
return tap($this->getFreshApplication()['router']->getRoutes(), function ($routes) {
/** @var RouteCollection $routes */
$routes->refreshNameLookups();
$routes->refreshActionLookups();
});
} | [
"protected",
"function",
"getFreshApplicationRoutes",
"(",
")",
"{",
"return",
"tap",
"(",
"$",
"this",
"->",
"getFreshApplication",
"(",
")",
"[",
"'router'",
"]",
"->",
"getRoutes",
"(",
")",
",",
"function",
"(",
"$",
"routes",
")",
"{",
"/** @var RouteCollection $routes */",
"$",
"routes",
"->",
"refreshNameLookups",
"(",
")",
";",
"$",
"routes",
"->",
"refreshActionLookups",
"(",
")",
";",
"}",
")",
";",
"}"
] | Boot a fresh copy of the application and retrieve its routes.
@return RouteCollection | [
"Boot",
"a",
"fresh",
"copy",
"of",
"the",
"application",
"and",
"retrieve",
"its",
"routes",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/RouteCacheCommand.php#L72-L79 | train |
themosis/framework | src/Core/Console/RouteCacheCommand.php | RouteCacheCommand.getFreshApplication | protected function getFreshApplication()
{
return tap(require $this->laravel->bootstrapPath('app.php'), function ($app) {
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
});
} | php | protected function getFreshApplication()
{
return tap(require $this->laravel->bootstrapPath('app.php'), function ($app) {
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
});
} | [
"protected",
"function",
"getFreshApplication",
"(",
")",
"{",
"return",
"tap",
"(",
"require",
"$",
"this",
"->",
"laravel",
"->",
"bootstrapPath",
"(",
"'app.php'",
")",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"app",
"->",
"make",
"(",
"\\",
"Illuminate",
"\\",
"Contracts",
"\\",
"Console",
"\\",
"Kernel",
"::",
"class",
")",
"->",
"bootstrap",
"(",
")",
";",
"}",
")",
";",
"}"
] | Return a fresh application instance.
@return Application | [
"Return",
"a",
"fresh",
"application",
"instance",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/RouteCacheCommand.php#L86-L91 | train |
themosis/framework | src/Forms/Resources/Transformers/MediaFieldTransformer.php | MediaFieldTransformer.getOptions | protected function getOptions(FieldTypeInterface $field)
{
$options = parent::getOptions($field);
$attachedFile = get_attached_file($field->getValue());
$options['media'] = [
'name' => wp_basename($attachedFile),
'thumbnail' => wp_get_attachment_image_src($field->getValue(), 'thumbnail', true)[0],
'filesize' => round(filesize($attachedFile) / 1024).' KB'
];
return $options;
} | php | protected function getOptions(FieldTypeInterface $field)
{
$options = parent::getOptions($field);
$attachedFile = get_attached_file($field->getValue());
$options['media'] = [
'name' => wp_basename($attachedFile),
'thumbnail' => wp_get_attachment_image_src($field->getValue(), 'thumbnail', true)[0],
'filesize' => round(filesize($attachedFile) / 1024).' KB'
];
return $options;
} | [
"protected",
"function",
"getOptions",
"(",
"FieldTypeInterface",
"$",
"field",
")",
"{",
"$",
"options",
"=",
"parent",
"::",
"getOptions",
"(",
"$",
"field",
")",
";",
"$",
"attachedFile",
"=",
"get_attached_file",
"(",
"$",
"field",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"options",
"[",
"'media'",
"]",
"=",
"[",
"'name'",
"=>",
"wp_basename",
"(",
"$",
"attachedFile",
")",
",",
"'thumbnail'",
"=>",
"wp_get_attachment_image_src",
"(",
"$",
"field",
"->",
"getValue",
"(",
")",
",",
"'thumbnail'",
",",
"true",
")",
"[",
"0",
"]",
",",
"'filesize'",
"=>",
"round",
"(",
"filesize",
"(",
"$",
"attachedFile",
")",
"/",
"1024",
")",
".",
"' KB'",
"]",
";",
"return",
"$",
"options",
";",
"}"
] | Return media field options.
@param FieldTypeInterface $field
@return array | [
"Return",
"media",
"field",
"options",
"."
] | 9931cdda709b94cc712495acf93211b6fa9d23a7 | https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Resources/Transformers/MediaFieldTransformer.php#L16-L29 | train |
luyadev/luya | core/helpers/Url.php | Url.toInternal | public static function toInternal(array $routeParams, $scheme = false)
{
if ($scheme) {
return Yii::$app->getUrlManager()->internalCreateAbsoluteUrl($routeParams);
}
return Yii::$app->getUrlManager()->internalCreateUrl($routeParams);
} | php | public static function toInternal(array $routeParams, $scheme = false)
{
if ($scheme) {
return Yii::$app->getUrlManager()->internalCreateAbsoluteUrl($routeParams);
}
return Yii::$app->getUrlManager()->internalCreateUrl($routeParams);
} | [
"public",
"static",
"function",
"toInternal",
"(",
"array",
"$",
"routeParams",
",",
"$",
"scheme",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"scheme",
")",
"{",
"return",
"Yii",
"::",
"$",
"app",
"->",
"getUrlManager",
"(",
")",
"->",
"internalCreateAbsoluteUrl",
"(",
"$",
"routeParams",
")",
";",
"}",
"return",
"Yii",
"::",
"$",
"app",
"->",
"getUrlManager",
"(",
")",
"->",
"internalCreateUrl",
"(",
"$",
"routeParams",
")",
";",
"}"
] | This helper method will not concern any context informations
@param array $routeParams Example array to route `['/module/controller/action']`.
@param boolean $scheme Whether to return the absolute url or not
@return string The created url. | [
"This",
"helper",
"method",
"will",
"not",
"concern",
"any",
"context",
"informations"
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/helpers/Url.php#L47-L54 | train |
luyadev/luya | core/helpers/Url.php | Url.toAjax | public static function toAjax($route, array $params = [])
{
$routeParams = ['/'.$route];
foreach ($params as $key => $value) {
$routeParams[$key] = $value;
}
return static::toInternal($routeParams, true);
} | php | public static function toAjax($route, array $params = [])
{
$routeParams = ['/'.$route];
foreach ($params as $key => $value) {
$routeParams[$key] = $value;
}
return static::toInternal($routeParams, true);
} | [
"public",
"static",
"function",
"toAjax",
"(",
"$",
"route",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"routeParams",
"=",
"[",
"'/'",
".",
"$",
"route",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"routeParams",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"static",
"::",
"toInternal",
"(",
"$",
"routeParams",
",",
"true",
")",
";",
"}"
] | Create a link to use when point to an ajax script.
@param string $route The base routing path defined in yii. module/controller/action
@param array $params Optional array containing get parameters with key value pairing
@return string The ajax url link. | [
"Create",
"a",
"link",
"to",
"use",
"when",
"point",
"to",
"an",
"ajax",
"script",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/helpers/Url.php#L63-L71 | train |
luyadev/luya | core/behaviors/HtmlEncodeBehavior.php | HtmlEncodeBehavior.afterFind | public function afterFind($event)
{
foreach ($this->attributes as $attribute) {
$this->owner->{$attribute} = $this->htmlEncode($this->owner->{$attribute});
}
} | php | public function afterFind($event)
{
foreach ($this->attributes as $attribute) {
$this->owner->{$attribute} = $this->htmlEncode($this->owner->{$attribute});
}
} | [
"public",
"function",
"afterFind",
"(",
"$",
"event",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"$",
"this",
"->",
"owner",
"->",
"{",
"$",
"attribute",
"}",
"=",
"$",
"this",
"->",
"htmlEncode",
"(",
"$",
"this",
"->",
"owner",
"->",
"{",
"$",
"attribute",
"}",
")",
";",
"}",
"}"
] | Event will be triggered after find.
@param \yii\base\Event $event The after find event. | [
"Event",
"will",
"be",
"triggered",
"after",
"find",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/behaviors/HtmlEncodeBehavior.php#L51-L56 | train |
luyadev/luya | core/web/jsonld/DurationValue.php | DurationValue.timeToIso8601Duration | protected function timeToIso8601Duration($time)
{
$units = array(
"Y" => 365*24*3600,
"D" => 24*3600,
"H" => 3600,
"M" => 60,
"S" => 1,
);
$str = "P";
$istime = false;
foreach ($units as $unitName => &$unit) {
$quot = intval($time / $unit);
$time -= $quot * $unit;
$unit = $quot;
if ($unit > 0) {
if (!$istime && in_array($unitName, array("H", "M", "S"))) { // There may be a better way to do this
$str .= "T";
$istime = true;
}
$str .= strval($unit) . $unitName;
}
}
return $str;
} | php | protected function timeToIso8601Duration($time)
{
$units = array(
"Y" => 365*24*3600,
"D" => 24*3600,
"H" => 3600,
"M" => 60,
"S" => 1,
);
$str = "P";
$istime = false;
foreach ($units as $unitName => &$unit) {
$quot = intval($time / $unit);
$time -= $quot * $unit;
$unit = $quot;
if ($unit > 0) {
if (!$istime && in_array($unitName, array("H", "M", "S"))) { // There may be a better way to do this
$str .= "T";
$istime = true;
}
$str .= strval($unit) . $unitName;
}
}
return $str;
} | [
"protected",
"function",
"timeToIso8601Duration",
"(",
"$",
"time",
")",
"{",
"$",
"units",
"=",
"array",
"(",
"\"Y\"",
"=>",
"365",
"*",
"24",
"*",
"3600",
",",
"\"D\"",
"=>",
"24",
"*",
"3600",
",",
"\"H\"",
"=>",
"3600",
",",
"\"M\"",
"=>",
"60",
",",
"\"S\"",
"=>",
"1",
",",
")",
";",
"$",
"str",
"=",
"\"P\"",
";",
"$",
"istime",
"=",
"false",
";",
"foreach",
"(",
"$",
"units",
"as",
"$",
"unitName",
"=>",
"&",
"$",
"unit",
")",
"{",
"$",
"quot",
"=",
"intval",
"(",
"$",
"time",
"/",
"$",
"unit",
")",
";",
"$",
"time",
"-=",
"$",
"quot",
"*",
"$",
"unit",
";",
"$",
"unit",
"=",
"$",
"quot",
";",
"if",
"(",
"$",
"unit",
">",
"0",
")",
"{",
"if",
"(",
"!",
"$",
"istime",
"&&",
"in_array",
"(",
"$",
"unitName",
",",
"array",
"(",
"\"H\"",
",",
"\"M\"",
",",
"\"S\"",
")",
")",
")",
"{",
"// There may be a better way to do this",
"$",
"str",
".=",
"\"T\"",
";",
"$",
"istime",
"=",
"true",
";",
"}",
"$",
"str",
".=",
"strval",
"(",
"$",
"unit",
")",
".",
"$",
"unitName",
";",
"}",
"}",
"return",
"$",
"str",
";",
"}"
] | Convert time to iso date.
@see https://stackoverflow.com/a/13301472/4611030
@param integer $time
@return string | [
"Convert",
"time",
"to",
"iso",
"date",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/jsonld/DurationValue.php#L58-L85 | train |
luyadev/luya | core/traits/RegistryTrait.php | RegistryTrait.has | public static function has($name)
{
return (self::find()->where([self::getNameAttribute() => $name])->one()) ? true : false;
} | php | public static function has($name)
{
return (self::find()->where([self::getNameAttribute() => $name])->one()) ? true : false;
} | [
"public",
"static",
"function",
"has",
"(",
"$",
"name",
")",
"{",
"return",
"(",
"self",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"self",
"::",
"getNameAttribute",
"(",
")",
"=>",
"$",
"name",
"]",
")",
"->",
"one",
"(",
")",
")",
"?",
"true",
":",
"false",
";",
"}"
] | Check whether a config value exists or not
@param string $name
@return boolean | [
"Check",
"whether",
"a",
"config",
"value",
"exists",
"or",
"not"
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/traits/RegistryTrait.php#L41-L44 | train |
luyadev/luya | core/traits/RegistryTrait.php | RegistryTrait.get | public static function get($name, $defaultValue = null)
{
$model = self::find()->where([self::getNameAttribute() => $name])->asArray()->one();
if ($model) {
return $model[self::getValueAttribute()];
}
return $defaultValue;
} | php | public static function get($name, $defaultValue = null)
{
$model = self::find()->where([self::getNameAttribute() => $name])->asArray()->one();
if ($model) {
return $model[self::getValueAttribute()];
}
return $defaultValue;
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"name",
",",
"$",
"defaultValue",
"=",
"null",
")",
"{",
"$",
"model",
"=",
"self",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"self",
"::",
"getNameAttribute",
"(",
")",
"=>",
"$",
"name",
"]",
")",
"->",
"asArray",
"(",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"$",
"model",
")",
"{",
"return",
"$",
"model",
"[",
"self",
"::",
"getValueAttribute",
"(",
")",
"]",
";",
"}",
"return",
"$",
"defaultValue",
";",
"}"
] | Get the value of a config value
@param string $name
@return string|null | [
"Get",
"the",
"value",
"of",
"a",
"config",
"value"
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/traits/RegistryTrait.php#L52-L61 | train |
luyadev/luya | core/traits/RegistryTrait.php | RegistryTrait.remove | public static function remove($name)
{
$model = self::find()->where([self::getNameAttribute() => $name])->one();
if ($model) {
return (bool) $model->delete();
}
return false;
} | php | public static function remove($name)
{
$model = self::find()->where([self::getNameAttribute() => $name])->one();
if ($model) {
return (bool) $model->delete();
}
return false;
} | [
"public",
"static",
"function",
"remove",
"(",
"$",
"name",
")",
"{",
"$",
"model",
"=",
"self",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"self",
"::",
"getNameAttribute",
"(",
")",
"=>",
"$",
"name",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"$",
"model",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"model",
"->",
"delete",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Remove an existing config value
@param string $name
@return bool | [
"Remove",
"an",
"existing",
"config",
"value"
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/traits/RegistryTrait.php#L92-L101 | train |
luyadev/luya | core/web/filters/ResponseCache.php | ResponseCache.callActionCallable | private function callActionCallable($action, $result)
{
if (isset($this->actionsCallable[$action]) && is_callable($this->actionsCallable[$action])) {
call_user_func($this->actionsCallable[$action], $result);
}
} | php | private function callActionCallable($action, $result)
{
if (isset($this->actionsCallable[$action]) && is_callable($this->actionsCallable[$action])) {
call_user_func($this->actionsCallable[$action], $result);
}
} | [
"private",
"function",
"callActionCallable",
"(",
"$",
"action",
",",
"$",
"result",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"actionsCallable",
"[",
"$",
"action",
"]",
")",
"&&",
"is_callable",
"(",
"$",
"this",
"->",
"actionsCallable",
"[",
"$",
"action",
"]",
")",
")",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"actionsCallable",
"[",
"$",
"action",
"]",
",",
"$",
"result",
")",
";",
"}",
"}"
] | call the action callable if available.
@param string $action The action ID name
@param string $result The cahed or not cached action response, this is a string as its after the action filters. | [
"call",
"the",
"action",
"callable",
"if",
"available",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/filters/ResponseCache.php#L62-L67 | train |
luyadev/luya | core/web/jsonld/TextValue.php | TextValue.truncate | public function truncate($length)
{
$this->_text = StringHelper::truncate($this->_text, $length);
return $this;
} | php | public function truncate($length)
{
$this->_text = StringHelper::truncate($this->_text, $length);
return $this;
} | [
"public",
"function",
"truncate",
"(",
"$",
"length",
")",
"{",
"$",
"this",
"->",
"_text",
"=",
"StringHelper",
"::",
"truncate",
"(",
"$",
"this",
"->",
"_text",
",",
"$",
"length",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Truncate the string for a given lenth.
@param integer $length
@return \luya\web\jsonld\TextValue | [
"Truncate",
"the",
"string",
"for",
"a",
"given",
"lenth",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/jsonld/TextValue.php#L36-L41 | train |
luyadev/luya | core/web/Controller.php | Controller.getViewPath | public function getViewPath()
{
if ($this->module instanceof Module) {
if ($this->module->useAppViewPath) {
return '@app/views/' . $this->module->id . '/' . $this->id;
} elseif (is_array($this->module->viewMap)) {
$currentAction = $this->id . '/' . ($this->action ? $this->action->id : $this->defaultAction);
foreach ($this->module->viewMap as $action => $viewPath) {
// Special case for map all views of controller
if ($action === '*') {
return $viewPath . '/' . $this->id;
} elseif (fnmatch($action, $currentAction)) {
return $viewPath;
}
}
}
}
return parent::getViewPath();
} | php | public function getViewPath()
{
if ($this->module instanceof Module) {
if ($this->module->useAppViewPath) {
return '@app/views/' . $this->module->id . '/' . $this->id;
} elseif (is_array($this->module->viewMap)) {
$currentAction = $this->id . '/' . ($this->action ? $this->action->id : $this->defaultAction);
foreach ($this->module->viewMap as $action => $viewPath) {
// Special case for map all views of controller
if ($action === '*') {
return $viewPath . '/' . $this->id;
} elseif (fnmatch($action, $currentAction)) {
return $viewPath;
}
}
}
}
return parent::getViewPath();
} | [
"public",
"function",
"getViewPath",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"module",
"instanceof",
"Module",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"module",
"->",
"useAppViewPath",
")",
"{",
"return",
"'@app/views/'",
".",
"$",
"this",
"->",
"module",
"->",
"id",
".",
"'/'",
".",
"$",
"this",
"->",
"id",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"this",
"->",
"module",
"->",
"viewMap",
")",
")",
"{",
"$",
"currentAction",
"=",
"$",
"this",
"->",
"id",
".",
"'/'",
".",
"(",
"$",
"this",
"->",
"action",
"?",
"$",
"this",
"->",
"action",
"->",
"id",
":",
"$",
"this",
"->",
"defaultAction",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"module",
"->",
"viewMap",
"as",
"$",
"action",
"=>",
"$",
"viewPath",
")",
"{",
"// Special case for map all views of controller",
"if",
"(",
"$",
"action",
"===",
"'*'",
")",
"{",
"return",
"$",
"viewPath",
".",
"'/'",
".",
"$",
"this",
"->",
"id",
";",
"}",
"elseif",
"(",
"fnmatch",
"(",
"$",
"action",
",",
"$",
"currentAction",
")",
")",
"{",
"return",
"$",
"viewPath",
";",
"}",
"}",
"}",
"}",
"return",
"parent",
"::",
"getViewPath",
"(",
")",
";",
"}"
] | Override the default Yii controller getViewPath method. To define the template folders in where
the templates are located. Why? Basically some modules needs to put theyr templates inside of the client
repository.
@return string | [
"Override",
"the",
"default",
"Yii",
"controller",
"getViewPath",
"method",
".",
"To",
"define",
"the",
"template",
"folders",
"in",
"where",
"the",
"templates",
"are",
"located",
".",
"Why?",
"Basically",
"some",
"modules",
"needs",
"to",
"put",
"theyr",
"templates",
"inside",
"of",
"the",
"client",
"repository",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/Controller.php#L32-L52 | train |
luyadev/luya | core/web/Controller.php | Controller.render | public function render($view, $params = [])
{
if (!empty($this->module->context) && empty($this->layout)) {
return $this->renderPartial($view, $params);
}
return parent::render($view, $params);
} | php | public function render($view, $params = [])
{
if (!empty($this->module->context) && empty($this->layout)) {
return $this->renderPartial($view, $params);
}
return parent::render($view, $params);
} | [
"public",
"function",
"render",
"(",
"$",
"view",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"module",
"->",
"context",
")",
"&&",
"empty",
"(",
"$",
"this",
"->",
"layout",
")",
")",
"{",
"return",
"$",
"this",
"->",
"renderPartial",
"(",
"$",
"view",
",",
"$",
"params",
")",
";",
"}",
"return",
"parent",
"::",
"render",
"(",
"$",
"view",
",",
"$",
"params",
")",
";",
"}"
] | If we are acting in the module context and the layout is empty we only should renderPartial the content.
@param string $view The name of the view file (e.g. index)
@param array $params The params to assign into the value for key is the variable and value the content.
@return string | [
"If",
"we",
"are",
"acting",
"in",
"the",
"module",
"context",
"and",
"the",
"layout",
"is",
"empty",
"we",
"only",
"should",
"renderPartial",
"the",
"content",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/Controller.php#L62-L69 | train |
luyadev/luya | core/web/Bootstrap.php | Bootstrap.beforeRun | public function beforeRun($app)
{
foreach ($app->tags as $name => $config) {
TagParser::inject($name, $config);
}
foreach ($this->getModules() as $id => $module) {
foreach ($module->urlRules as $key => $rule) {
if (is_string($key)) {
$this->_urlRules[$key] = $rule;
} else {
$this->_urlRules[] = $rule;
}
}
// get all api rules (since 1.0.10)
foreach ($module->apiRules as $endpoint => $rule) {
$this->_apiRules[$endpoint] = $rule;
}
/**
* 'api-admin-user' => 'admin\apis\UserController',
* 'api-cms-navcontainer' => 'admin\apis\NavContainerController'
*/
foreach ($module->apis as $alias => $class) {
$this->_apis[$alias] = ['class' => $class, 'module' => $module];
}
foreach ($module->tags as $name => $config) {
TagParser::inject($name, $config);
}
}
} | php | public function beforeRun($app)
{
foreach ($app->tags as $name => $config) {
TagParser::inject($name, $config);
}
foreach ($this->getModules() as $id => $module) {
foreach ($module->urlRules as $key => $rule) {
if (is_string($key)) {
$this->_urlRules[$key] = $rule;
} else {
$this->_urlRules[] = $rule;
}
}
// get all api rules (since 1.0.10)
foreach ($module->apiRules as $endpoint => $rule) {
$this->_apiRules[$endpoint] = $rule;
}
/**
* 'api-admin-user' => 'admin\apis\UserController',
* 'api-cms-navcontainer' => 'admin\apis\NavContainerController'
*/
foreach ($module->apis as $alias => $class) {
$this->_apis[$alias] = ['class' => $class, 'module' => $module];
}
foreach ($module->tags as $name => $config) {
TagParser::inject($name, $config);
}
}
} | [
"public",
"function",
"beforeRun",
"(",
"$",
"app",
")",
"{",
"foreach",
"(",
"$",
"app",
"->",
"tags",
"as",
"$",
"name",
"=>",
"$",
"config",
")",
"{",
"TagParser",
"::",
"inject",
"(",
"$",
"name",
",",
"$",
"config",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"getModules",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"module",
")",
"{",
"foreach",
"(",
"$",
"module",
"->",
"urlRules",
"as",
"$",
"key",
"=>",
"$",
"rule",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"_urlRules",
"[",
"$",
"key",
"]",
"=",
"$",
"rule",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_urlRules",
"[",
"]",
"=",
"$",
"rule",
";",
"}",
"}",
"// get all api rules (since 1.0.10)",
"foreach",
"(",
"$",
"module",
"->",
"apiRules",
"as",
"$",
"endpoint",
"=>",
"$",
"rule",
")",
"{",
"$",
"this",
"->",
"_apiRules",
"[",
"$",
"endpoint",
"]",
"=",
"$",
"rule",
";",
"}",
"/**\n * 'api-admin-user' => 'admin\\apis\\UserController',\n * 'api-cms-navcontainer' => 'admin\\apis\\NavContainerController'\n */",
"foreach",
"(",
"$",
"module",
"->",
"apis",
"as",
"$",
"alias",
"=>",
"$",
"class",
")",
"{",
"$",
"this",
"->",
"_apis",
"[",
"$",
"alias",
"]",
"=",
"[",
"'class'",
"=>",
"$",
"class",
",",
"'module'",
"=>",
"$",
"module",
"]",
";",
"}",
"foreach",
"(",
"$",
"module",
"->",
"tags",
"as",
"$",
"name",
"=>",
"$",
"config",
")",
"{",
"TagParser",
"::",
"inject",
"(",
"$",
"name",
",",
"$",
"config",
")",
";",
"}",
"}",
"}"
] | Before bootstrap run process.
@see \luya\base\BaseBootstrap::beforeRun() | [
"Before",
"bootstrap",
"run",
"process",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/Bootstrap.php#L35-L67 | train |
luyadev/luya | core/web/Bootstrap.php | Bootstrap.run | public function run($app)
{
if (!$app->request->getIsConsoleRequest()) {
if ($this->hasModule('admin') && $app->request->isAdmin) {
// When admin context, change csrf token, this will not terminate the frontend csrf token:
// @see https://github.com/luyadev/luya/issues/1778
$app->request->csrfParam = '_csrf_admin';
foreach ($this->getModules() as $id => $module) {
if ($module instanceof AdminModuleInterface) {
$this->_adminAssets = ArrayHelper::merge($module->getAdminAssets(), $this->_adminAssets);
if ($module->getMenu()) {
$this->_adminMenus[$module->id] = $module->getMenu();
}
$this->_jsTranslations[$id] = $module->getJsTranslationMessages();
}
}
$app->getModule('admin')->assets = $this->_adminAssets;
$app->getModule('admin')->controllerMap = $this->_apis;
$app->getModule('admin')->moduleMenus = $this->_adminMenus;
$app->getModule('admin')->setJsTranslations($this->_jsTranslations);
// calculate api defintions
if ($app->getModule('admin')->hasProperty('apiDefintions')) { // ensure backwards compatibility
$app->getModule('admin')->apiDefintions = $this->generateApiRuleDefintions($this->_apis, $this->_apiRules);
}
// as the admin module needs to listen for $apiDefintions we have to get the urlRules from the admin and merge with the existing rules:
// in admin context, admin url rules have always precedence over frontend rules.
$this->_urlRules = array_merge($app->getModule('admin')->urlRules, $this->_urlRules);
}
}
$app->getUrlManager()->addRules($this->_urlRules);
} | php | public function run($app)
{
if (!$app->request->getIsConsoleRequest()) {
if ($this->hasModule('admin') && $app->request->isAdmin) {
// When admin context, change csrf token, this will not terminate the frontend csrf token:
// @see https://github.com/luyadev/luya/issues/1778
$app->request->csrfParam = '_csrf_admin';
foreach ($this->getModules() as $id => $module) {
if ($module instanceof AdminModuleInterface) {
$this->_adminAssets = ArrayHelper::merge($module->getAdminAssets(), $this->_adminAssets);
if ($module->getMenu()) {
$this->_adminMenus[$module->id] = $module->getMenu();
}
$this->_jsTranslations[$id] = $module->getJsTranslationMessages();
}
}
$app->getModule('admin')->assets = $this->_adminAssets;
$app->getModule('admin')->controllerMap = $this->_apis;
$app->getModule('admin')->moduleMenus = $this->_adminMenus;
$app->getModule('admin')->setJsTranslations($this->_jsTranslations);
// calculate api defintions
if ($app->getModule('admin')->hasProperty('apiDefintions')) { // ensure backwards compatibility
$app->getModule('admin')->apiDefintions = $this->generateApiRuleDefintions($this->_apis, $this->_apiRules);
}
// as the admin module needs to listen for $apiDefintions we have to get the urlRules from the admin and merge with the existing rules:
// in admin context, admin url rules have always precedence over frontend rules.
$this->_urlRules = array_merge($app->getModule('admin')->urlRules, $this->_urlRules);
}
}
$app->getUrlManager()->addRules($this->_urlRules);
} | [
"public",
"function",
"run",
"(",
"$",
"app",
")",
"{",
"if",
"(",
"!",
"$",
"app",
"->",
"request",
"->",
"getIsConsoleRequest",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasModule",
"(",
"'admin'",
")",
"&&",
"$",
"app",
"->",
"request",
"->",
"isAdmin",
")",
"{",
"// When admin context, change csrf token, this will not terminate the frontend csrf token:",
"// @see https://github.com/luyadev/luya/issues/1778",
"$",
"app",
"->",
"request",
"->",
"csrfParam",
"=",
"'_csrf_admin'",
";",
"foreach",
"(",
"$",
"this",
"->",
"getModules",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"module",
")",
"{",
"if",
"(",
"$",
"module",
"instanceof",
"AdminModuleInterface",
")",
"{",
"$",
"this",
"->",
"_adminAssets",
"=",
"ArrayHelper",
"::",
"merge",
"(",
"$",
"module",
"->",
"getAdminAssets",
"(",
")",
",",
"$",
"this",
"->",
"_adminAssets",
")",
";",
"if",
"(",
"$",
"module",
"->",
"getMenu",
"(",
")",
")",
"{",
"$",
"this",
"->",
"_adminMenus",
"[",
"$",
"module",
"->",
"id",
"]",
"=",
"$",
"module",
"->",
"getMenu",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_jsTranslations",
"[",
"$",
"id",
"]",
"=",
"$",
"module",
"->",
"getJsTranslationMessages",
"(",
")",
";",
"}",
"}",
"$",
"app",
"->",
"getModule",
"(",
"'admin'",
")",
"->",
"assets",
"=",
"$",
"this",
"->",
"_adminAssets",
";",
"$",
"app",
"->",
"getModule",
"(",
"'admin'",
")",
"->",
"controllerMap",
"=",
"$",
"this",
"->",
"_apis",
";",
"$",
"app",
"->",
"getModule",
"(",
"'admin'",
")",
"->",
"moduleMenus",
"=",
"$",
"this",
"->",
"_adminMenus",
";",
"$",
"app",
"->",
"getModule",
"(",
"'admin'",
")",
"->",
"setJsTranslations",
"(",
"$",
"this",
"->",
"_jsTranslations",
")",
";",
"// calculate api defintions",
"if",
"(",
"$",
"app",
"->",
"getModule",
"(",
"'admin'",
")",
"->",
"hasProperty",
"(",
"'apiDefintions'",
")",
")",
"{",
"// ensure backwards compatibility",
"$",
"app",
"->",
"getModule",
"(",
"'admin'",
")",
"->",
"apiDefintions",
"=",
"$",
"this",
"->",
"generateApiRuleDefintions",
"(",
"$",
"this",
"->",
"_apis",
",",
"$",
"this",
"->",
"_apiRules",
")",
";",
"}",
"// as the admin module needs to listen for $apiDefintions we have to get the urlRules from the admin and merge with the existing rules:",
"// in admin context, admin url rules have always precedence over frontend rules.",
"$",
"this",
"->",
"_urlRules",
"=",
"array_merge",
"(",
"$",
"app",
"->",
"getModule",
"(",
"'admin'",
")",
"->",
"urlRules",
",",
"$",
"this",
"->",
"_urlRules",
")",
";",
"}",
"}",
"$",
"app",
"->",
"getUrlManager",
"(",
")",
"->",
"addRules",
"(",
"$",
"this",
"->",
"_urlRules",
")",
";",
"}"
] | Invokes the bootstraping process.
@see \luya\base\BaseBootstrap::run() | [
"Invokes",
"the",
"bootstraping",
"process",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/Bootstrap.php#L103-L137 | train |
luyadev/luya | core/web/jsonld/Rating.php | Rating.getRatingValue | public function getRatingValue()
{
if ($this->_ratingValue === null) {
return null;
}
$range = new RangeValue($this->_ratingValue);
$range->ensureRange($this->_worstRating ?: 0, $this->_bestRating ?: 5);
return $this->_ratingValue = $range->getValue();
} | php | public function getRatingValue()
{
if ($this->_ratingValue === null) {
return null;
}
$range = new RangeValue($this->_ratingValue);
$range->ensureRange($this->_worstRating ?: 0, $this->_bestRating ?: 5);
return $this->_ratingValue = $range->getValue();
} | [
"public",
"function",
"getRatingValue",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ratingValue",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"range",
"=",
"new",
"RangeValue",
"(",
"$",
"this",
"->",
"_ratingValue",
")",
";",
"$",
"range",
"->",
"ensureRange",
"(",
"$",
"this",
"->",
"_worstRating",
"?",
":",
"0",
",",
"$",
"this",
"->",
"_bestRating",
"?",
":",
"5",
")",
";",
"return",
"$",
"this",
"->",
"_ratingValue",
"=",
"$",
"range",
"->",
"getValue",
"(",
")",
";",
"}"
] | Get Rating Value.
@return integer | [
"Get",
"Rating",
"Value",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/jsonld/Rating.php#L125-L135 | train |
luyadev/luya | core/web/filters/RobotsFilter.php | RobotsFilter.setRenderTime | protected function setRenderTime($time)
{
$merge = Yii::$app->session->get(self::ROBOTS_FILTER_SESSION_IDENTIFIER, []);
Yii::$app->session->set(self::ROBOTS_FILTER_SESSION_IDENTIFIER, array_merge([$this->getSessionKeyByOwner() => $time], $merge));
} | php | protected function setRenderTime($time)
{
$merge = Yii::$app->session->get(self::ROBOTS_FILTER_SESSION_IDENTIFIER, []);
Yii::$app->session->set(self::ROBOTS_FILTER_SESSION_IDENTIFIER, array_merge([$this->getSessionKeyByOwner() => $time], $merge));
} | [
"protected",
"function",
"setRenderTime",
"(",
"$",
"time",
")",
"{",
"$",
"merge",
"=",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"get",
"(",
"self",
"::",
"ROBOTS_FILTER_SESSION_IDENTIFIER",
",",
"[",
"]",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"set",
"(",
"self",
"::",
"ROBOTS_FILTER_SESSION_IDENTIFIER",
",",
"array_merge",
"(",
"[",
"$",
"this",
"->",
"getSessionKeyByOwner",
"(",
")",
"=>",
"$",
"time",
"]",
",",
"$",
"merge",
")",
")",
";",
"}"
] | Render Time Setter.
@param integer $time Set the last action timestamp. | [
"Render",
"Time",
"Setter",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/filters/RobotsFilter.php#L80-L84 | train |
luyadev/luya | core/web/filters/RobotsFilter.php | RobotsFilter.getSessionKeyByOwner | protected function getSessionKeyByOwner()
{
if ($this->sessionKey) {
return $this->sessionKey;
}
if ($this->owner instanceof Controller) {
return $this->owner->module->id;
}
return 'generic';
} | php | protected function getSessionKeyByOwner()
{
if ($this->sessionKey) {
return $this->sessionKey;
}
if ($this->owner instanceof Controller) {
return $this->owner->module->id;
}
return 'generic';
} | [
"protected",
"function",
"getSessionKeyByOwner",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"sessionKey",
")",
"{",
"return",
"$",
"this",
"->",
"sessionKey",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"owner",
"instanceof",
"Controller",
")",
"{",
"return",
"$",
"this",
"->",
"owner",
"->",
"module",
"->",
"id",
";",
"}",
"return",
"'generic'",
";",
"}"
] | Get a specific key for the current robots filter session array.
This ensures that when multiple forms are on the same page, only the robot check is handeld for the given module name.
@return string
@since 1.0.17 | [
"Get",
"a",
"specific",
"key",
"for",
"the",
"current",
"robots",
"filter",
"session",
"array",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/filters/RobotsFilter.php#L94-L105 | train |
luyadev/luya | core/helpers/StringHelper.php | StringHelper.typeCast | public static function typeCast($string)
{
if (is_numeric($string)) {
return static::typeCastNumeric($string);
} elseif (is_array($string)) {
return ArrayHelper::typeCast($string);
}
return $string;
} | php | public static function typeCast($string)
{
if (is_numeric($string)) {
return static::typeCastNumeric($string);
} elseif (is_array($string)) {
return ArrayHelper::typeCast($string);
}
return $string;
} | [
"public",
"static",
"function",
"typeCast",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"string",
")",
")",
"{",
"return",
"static",
"::",
"typeCastNumeric",
"(",
"$",
"string",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"string",
")",
")",
"{",
"return",
"ArrayHelper",
"::",
"typeCast",
"(",
"$",
"string",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | TypeCast a string to its specific types.
Arrays will passed to to the {{luya\helpers\ArrayHelper::typeCast()}} class.
@param mixed $string The input string to type cast. Arrays will be passted to {{luya\helpers\ArrayHelper::typeCast()}}.
@return mixed The new type casted value, if the input is an array the output is the typecasted array. | [
"TypeCast",
"a",
"string",
"to",
"its",
"specific",
"types",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/helpers/StringHelper.php#L32-L41 | train |
luyadev/luya | core/helpers/StringHelper.php | StringHelper.typeCastNumeric | public static function typeCastNumeric($value)
{
if (!self::isFloat($value)) {
return $value;
}
if (intval($value) == $value) {
return (int) $value;
}
return (float) $value;
} | php | public static function typeCastNumeric($value)
{
if (!self::isFloat($value)) {
return $value;
}
if (intval($value) == $value) {
return (int) $value;
}
return (float) $value;
} | [
"public",
"static",
"function",
"typeCastNumeric",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"isFloat",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"intval",
"(",
"$",
"value",
")",
"==",
"$",
"value",
")",
"{",
"return",
"(",
"int",
")",
"$",
"value",
";",
"}",
"return",
"(",
"float",
")",
"$",
"value",
";",
"}"
] | TypeCast a numeric value to float or integer.
If the given value is not a numeric or float value it will be returned as it is. In order to find out whether its float
or not use {{luya\helpers\StringHelper::isFloat()}}.
@param mixed $value The given value to parse.
@return mixed Returns the original value if not numeric or integer, float casted value. | [
"TypeCast",
"a",
"numeric",
"value",
"to",
"float",
"or",
"integer",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/helpers/StringHelper.php#L72-L83 | train |
luyadev/luya | core/helpers/StringHelper.php | StringHelper.contains | public static function contains($needle, $haystack, $strict = false)
{
$needles = (array) $needle;
$state = false;
foreach ($needles as $item) {
$state = (strpos($haystack, $item) !== false);
if ($strict && !$state) {
return false;
}
if (!$strict && $state) {
return true;
}
}
return $state;
} | php | public static function contains($needle, $haystack, $strict = false)
{
$needles = (array) $needle;
$state = false;
foreach ($needles as $item) {
$state = (strpos($haystack, $item) !== false);
if ($strict && !$state) {
return false;
}
if (!$strict && $state) {
return true;
}
}
return $state;
} | [
"public",
"static",
"function",
"contains",
"(",
"$",
"needle",
",",
"$",
"haystack",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"$",
"needles",
"=",
"(",
"array",
")",
"$",
"needle",
";",
"$",
"state",
"=",
"false",
";",
"foreach",
"(",
"$",
"needles",
"as",
"$",
"item",
")",
"{",
"$",
"state",
"=",
"(",
"strpos",
"(",
"$",
"haystack",
",",
"$",
"item",
")",
"!==",
"false",
")",
";",
"if",
"(",
"$",
"strict",
"&&",
"!",
"$",
"state",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"strict",
"&&",
"$",
"state",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"$",
"state",
";",
"}"
] | Check whether a char or word exists in a string or not.
This method is case sensitive. The need can be an array with multiple chars or words who
are going to look up in the haystack string.
If an array of needle words is provided the $strict parameter defines whether all need keys must be found
in the string to get the `true` response or if just one of the keys are found the response is already `true`.
@param string|array $needle The char or word to find in the $haystack. Can be an array to multi find words or char in the string.
@param string $haystack The haystack where the $needle string should be looked up.
@param boolean $strict If an array of needles is provided the $strict parameter defines whether all keys must be found ($strict = true) or just one result must be found ($strict = false).
@return boolean If an array of values is provided the response may change depending on $findAll. | [
"Check",
"whether",
"a",
"char",
"or",
"word",
"exists",
"in",
"a",
"string",
"or",
"not",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/helpers/StringHelper.php#L135-L154 | train |
luyadev/luya | core/helpers/StringHelper.php | StringHelper.minify | public static function minify($content, array $options = [])
{
$min = preg_replace(['/[\n\r]/', '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s', ], ['', '>', '<', '\\1'], trim($content));
$min = str_replace(['> <'], ['><'], $min);
if (ArrayHelper::getValue($options, 'comments', false)) {
$min = preg_replace('/<!--(.*)-->/Uis', '', $min);
}
return $min;
} | php | public static function minify($content, array $options = [])
{
$min = preg_replace(['/[\n\r]/', '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s', ], ['', '>', '<', '\\1'], trim($content));
$min = str_replace(['> <'], ['><'], $min);
if (ArrayHelper::getValue($options, 'comments', false)) {
$min = preg_replace('/<!--(.*)-->/Uis', '', $min);
}
return $min;
} | [
"public",
"static",
"function",
"minify",
"(",
"$",
"content",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"min",
"=",
"preg_replace",
"(",
"[",
"'/[\\n\\r]/'",
",",
"'/\\>[^\\S ]+/s'",
",",
"'/[^\\S ]+\\</s'",
",",
"'/(\\s)+/s'",
",",
"]",
",",
"[",
"''",
",",
"'>'",
",",
"'<'",
",",
"'\\\\1'",
"]",
",",
"trim",
"(",
"$",
"content",
")",
")",
";",
"$",
"min",
"=",
"str_replace",
"(",
"[",
"'> <'",
"]",
",",
"[",
"'><'",
"]",
",",
"$",
"min",
")",
";",
"if",
"(",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"options",
",",
"'comments'",
",",
"false",
")",
")",
"{",
"$",
"min",
"=",
"preg_replace",
"(",
"'/<!--(.*)-->/Uis'",
",",
"''",
",",
"$",
"min",
")",
";",
"}",
"return",
"$",
"min",
";",
"}"
] | "Minify" html content.
+ remove space
+ remove tabs
+ remove newlines
+ remove html comments
@param string $content The content to minify.
@param array $options Optional arguments to provide for minification:
- comments: boolean, where html comments should be removed or not. defaults to false
@return mixed Returns the minified content.
@since 1.0.7 | [
"Minify",
"html",
"content",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/helpers/StringHelper.php#L170-L180 | train |
luyadev/luya | core/helpers/StringHelper.php | StringHelper.highlightWord | public static function highlightWord($content, $word, $markup = '<b>%s</b>')
{
$word = (array) $word;
$content = strip_tags($content);
$latest = null;
foreach ($word as $needle) {
preg_match_all("/".preg_quote($needle, '/')."+/i", $content, $matches);
if (is_array($matches[0]) && count($matches[0]) >= 1) {
foreach ($matches[0] as $match) {
// ensure if a word is found twice we don't replace again.
if ($latest === $match) {
continue;
}
$content = str_replace($match, sprintf($markup, $match), $content);
$latest = $match;
}
}
}
return $content;
} | php | public static function highlightWord($content, $word, $markup = '<b>%s</b>')
{
$word = (array) $word;
$content = strip_tags($content);
$latest = null;
foreach ($word as $needle) {
preg_match_all("/".preg_quote($needle, '/')."+/i", $content, $matches);
if (is_array($matches[0]) && count($matches[0]) >= 1) {
foreach ($matches[0] as $match) {
// ensure if a word is found twice we don't replace again.
if ($latest === $match) {
continue;
}
$content = str_replace($match, sprintf($markup, $match), $content);
$latest = $match;
}
}
}
return $content;
} | [
"public",
"static",
"function",
"highlightWord",
"(",
"$",
"content",
",",
"$",
"word",
",",
"$",
"markup",
"=",
"'<b>%s</b>'",
")",
"{",
"$",
"word",
"=",
"(",
"array",
")",
"$",
"word",
";",
"$",
"content",
"=",
"strip_tags",
"(",
"$",
"content",
")",
";",
"$",
"latest",
"=",
"null",
";",
"foreach",
"(",
"$",
"word",
"as",
"$",
"needle",
")",
"{",
"preg_match_all",
"(",
"\"/\"",
".",
"preg_quote",
"(",
"$",
"needle",
",",
"'/'",
")",
".",
"\"+/i\"",
",",
"$",
"content",
",",
"$",
"matches",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
"&&",
"count",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
">=",
"1",
")",
"{",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"match",
")",
"{",
"// ensure if a word is found twice we don't replace again.",
"if",
"(",
"$",
"latest",
"===",
"$",
"match",
")",
"{",
"continue",
";",
"}",
"$",
"content",
"=",
"str_replace",
"(",
"$",
"match",
",",
"sprintf",
"(",
"$",
"markup",
",",
"$",
"match",
")",
",",
"$",
"content",
")",
";",
"$",
"latest",
"=",
"$",
"match",
";",
"}",
"}",
"}",
"return",
"$",
"content",
";",
"}"
] | Highlight a word within a content.
Since version 1.0.14 an array of words to highlight is possible.
> This function IS NOT case sensitive!
@param string $content The content to find the word.
@param string $word The word to find within the content.
@param string $markup The markup used wrap the word to highlight.
@since 1.0.12 | [
"Highlight",
"a",
"word",
"within",
"a",
"content",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/helpers/StringHelper.php#L239-L259 | train |
luyadev/luya | core/helpers/StringHelper.php | StringHelper.mb_str_split | public static function mb_str_split($string, $length = 1)
{
$array = [];
$stringLength = mb_strlen($string, 'UTF-8');
for ($i = 0; $i < $stringLength; $i += $length) {
$array[] = mb_substr($string, $i, $length, 'UTF-8');
}
return $array;
} | php | public static function mb_str_split($string, $length = 1)
{
$array = [];
$stringLength = mb_strlen($string, 'UTF-8');
for ($i = 0; $i < $stringLength; $i += $length) {
$array[] = mb_substr($string, $i, $length, 'UTF-8');
}
return $array;
} | [
"public",
"static",
"function",
"mb_str_split",
"(",
"$",
"string",
",",
"$",
"length",
"=",
"1",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"$",
"stringLength",
"=",
"mb_strlen",
"(",
"$",
"string",
",",
"'UTF-8'",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"stringLength",
";",
"$",
"i",
"+=",
"$",
"length",
")",
"{",
"$",
"array",
"[",
"]",
"=",
"mb_substr",
"(",
"$",
"string",
",",
"$",
"i",
",",
"$",
"length",
",",
"'UTF-8'",
")",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Multibyte-safe str_split funciton.
@param string $string The string to split into an array
@param integer $length The length of the chars to cut.
@since 1.0.12 | [
"Multibyte",
"-",
"safe",
"str_split",
"funciton",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/helpers/StringHelper.php#L268-L278 | train |
luyadev/luya | core/web/jsonld/EventTrait.php | EventTrait.setAttendee | public function setAttendee($attendee)
{
ObjectHelper::isInstanceOf($attendee, [Organization::class, PersonInterface::class]);
$this->_attendee = $attendee;
return $this;
} | php | public function setAttendee($attendee)
{
ObjectHelper::isInstanceOf($attendee, [Organization::class, PersonInterface::class]);
$this->_attendee = $attendee;
return $this;
} | [
"public",
"function",
"setAttendee",
"(",
"$",
"attendee",
")",
"{",
"ObjectHelper",
"::",
"isInstanceOf",
"(",
"$",
"attendee",
",",
"[",
"Organization",
"::",
"class",
",",
"PersonInterface",
"::",
"class",
"]",
")",
";",
"$",
"this",
"->",
"_attendee",
"=",
"$",
"attendee",
";",
"return",
"$",
"this",
";",
"}"
] | A person or organization attending the event. Supersedes attendees.
@param Organization|Person $attendee
@return static | [
"A",
"person",
"or",
"organization",
"attending",
"the",
"event",
".",
"Supersedes",
"attendees",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/jsonld/EventTrait.php#L79-L85 | train |
luyadev/luya | core/web/jsonld/EventTrait.php | EventTrait.setComposer | public function setComposer($composer)
{
ObjectHelper::isInstanceOf($author, [Organization::class, PersonInterface::class]);
$this->_composer = $composer;
return $this;
} | php | public function setComposer($composer)
{
ObjectHelper::isInstanceOf($author, [Organization::class, PersonInterface::class]);
$this->_composer = $composer;
return $this;
} | [
"public",
"function",
"setComposer",
"(",
"$",
"composer",
")",
"{",
"ObjectHelper",
"::",
"isInstanceOf",
"(",
"$",
"author",
",",
"[",
"Organization",
"::",
"class",
",",
"PersonInterface",
"::",
"class",
"]",
")",
";",
"$",
"this",
"->",
"_composer",
"=",
"$",
"composer",
";",
"return",
"$",
"this",
";",
"}"
] | The person or organization who wrote a composition, or who is the composer of a work performed at some event.
@param Organization|Person $composer
@return static | [
"The",
"person",
"or",
"organization",
"who",
"wrote",
"a",
"composition",
"or",
"who",
"is",
"the",
"composer",
"of",
"a",
"work",
"performed",
"at",
"some",
"event",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/jsonld/EventTrait.php#L103-L109 | train |
luyadev/luya | core/web/jsonld/EventTrait.php | EventTrait.setContributor | public function setContributor($contributor)
{
ObjectHelper::isInstanceOf($contributor, [Organization::class, PersonInterface::class]);
$this->_contributor = $contributor;
return $this;
} | php | public function setContributor($contributor)
{
ObjectHelper::isInstanceOf($contributor, [Organization::class, PersonInterface::class]);
$this->_contributor = $contributor;
return $this;
} | [
"public",
"function",
"setContributor",
"(",
"$",
"contributor",
")",
"{",
"ObjectHelper",
"::",
"isInstanceOf",
"(",
"$",
"contributor",
",",
"[",
"Organization",
"::",
"class",
",",
"PersonInterface",
"::",
"class",
"]",
")",
";",
"$",
"this",
"->",
"_contributor",
"=",
"$",
"contributor",
";",
"return",
"$",
"this",
";",
"}"
] | A secondary contributor to the CreativeWork or Event.
@param Organization|Person $contributor
@return static | [
"A",
"secondary",
"contributor",
"to",
"the",
"CreativeWork",
"or",
"Event",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/jsonld/EventTrait.php#L127-L133 | train |
luyadev/luya | core/web/jsonld/EventTrait.php | EventTrait.setOrganizer | public function setOrganizer($organizer)
{
ObjectHelper::isInstanceOf($organizer, [Organization::class, PersonInterface::class]);
$this->_organizer = $organizer;
return $this;
} | php | public function setOrganizer($organizer)
{
ObjectHelper::isInstanceOf($organizer, [Organization::class, PersonInterface::class]);
$this->_organizer = $organizer;
return $this;
} | [
"public",
"function",
"setOrganizer",
"(",
"$",
"organizer",
")",
"{",
"ObjectHelper",
"::",
"isInstanceOf",
"(",
"$",
"organizer",
",",
"[",
"Organization",
"::",
"class",
",",
"PersonInterface",
"::",
"class",
"]",
")",
";",
"$",
"this",
"->",
"_organizer",
"=",
"$",
"organizer",
";",
"return",
"$",
"this",
";",
"}"
] | An organizer of an Event.
@param Organization|Person $organizer
@return static | [
"An",
"organizer",
"of",
"an",
"Event",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/jsonld/EventTrait.php#L354-L360 | train |
luyadev/luya | core/web/jsonld/EventTrait.php | EventTrait.setTranslator | public function setTranslator($translator)
{
ObjectHelper::isInstanceOf($translator, [Organization::class, PersonInterface::class]);
$this->_translator = $translator;
return $this;
} | php | public function setTranslator($translator)
{
ObjectHelper::isInstanceOf($translator, [Organization::class, PersonInterface::class]);
$this->_translator = $translator;
return $this;
} | [
"public",
"function",
"setTranslator",
"(",
"$",
"translator",
")",
"{",
"ObjectHelper",
"::",
"isInstanceOf",
"(",
"$",
"translator",
",",
"[",
"Organization",
"::",
"class",
",",
"PersonInterface",
"::",
"class",
"]",
")",
";",
"$",
"this",
"->",
"_translator",
"=",
"$",
"translator",
";",
"return",
"$",
"this",
";",
"}"
] | Organization or person who adapts a creative work to different languages, regional differences
and technical requirements of a target market, or that translates during some event.
@param Organization|Person $translator
@return static | [
"Organization",
"or",
"person",
"who",
"adapts",
"a",
"creative",
"work",
"to",
"different",
"languages",
"regional",
"differences",
"and",
"technical",
"requirements",
"of",
"a",
"target",
"market",
"or",
"that",
"translates",
"during",
"some",
"event",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/jsonld/EventTrait.php#L569-L575 | train |
luyadev/luya | core/console/Bootstrap.php | Bootstrap.run | public function run($app)
{
foreach ($app->getApplicationModules() as $id => $module) {
$folder = $module->basePath . DIRECTORY_SEPARATOR . 'commands';
if (file_exists($folder) && is_dir($folder)) {
foreach (FileHelper::findFiles($folder) as $file) {
$module->controllerNamespace = $module->namespace . '\commands';
$className = '\\'.$module->getNamespace().'\\commands\\' . pathinfo($file, PATHINFO_FILENAME);
$command = str_replace('-controller', '', $module->id . '/' . Inflector::camel2id(pathinfo($file, PATHINFO_FILENAME)));
Yii::$app->controllerMap[$command] = ['class' => $className];
}
}
}
} | php | public function run($app)
{
foreach ($app->getApplicationModules() as $id => $module) {
$folder = $module->basePath . DIRECTORY_SEPARATOR . 'commands';
if (file_exists($folder) && is_dir($folder)) {
foreach (FileHelper::findFiles($folder) as $file) {
$module->controllerNamespace = $module->namespace . '\commands';
$className = '\\'.$module->getNamespace().'\\commands\\' . pathinfo($file, PATHINFO_FILENAME);
$command = str_replace('-controller', '', $module->id . '/' . Inflector::camel2id(pathinfo($file, PATHINFO_FILENAME)));
Yii::$app->controllerMap[$command] = ['class' => $className];
}
}
}
} | [
"public",
"function",
"run",
"(",
"$",
"app",
")",
"{",
"foreach",
"(",
"$",
"app",
"->",
"getApplicationModules",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"module",
")",
"{",
"$",
"folder",
"=",
"$",
"module",
"->",
"basePath",
".",
"DIRECTORY_SEPARATOR",
".",
"'commands'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"folder",
")",
"&&",
"is_dir",
"(",
"$",
"folder",
")",
")",
"{",
"foreach",
"(",
"FileHelper",
"::",
"findFiles",
"(",
"$",
"folder",
")",
"as",
"$",
"file",
")",
"{",
"$",
"module",
"->",
"controllerNamespace",
"=",
"$",
"module",
"->",
"namespace",
".",
"'\\commands'",
";",
"$",
"className",
"=",
"'\\\\'",
".",
"$",
"module",
"->",
"getNamespace",
"(",
")",
".",
"'\\\\commands\\\\'",
".",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_FILENAME",
")",
";",
"$",
"command",
"=",
"str_replace",
"(",
"'-controller'",
",",
"''",
",",
"$",
"module",
"->",
"id",
".",
"'/'",
".",
"Inflector",
"::",
"camel2id",
"(",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_FILENAME",
")",
")",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"controllerMap",
"[",
"$",
"command",
"]",
"=",
"[",
"'class'",
"=>",
"$",
"className",
"]",
";",
"}",
"}",
"}",
"}"
] | The run method must be implemented by defintion.
@see \luya\base\BaseBootstrap::run() | [
"The",
"run",
"method",
"must",
"be",
"implemented",
"by",
"defintion",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/console/Bootstrap.php#L36-L52 | train |
luyadev/luya | dev/BaseDevCommand.php | BaseDevCommand.actionConfigInfo | public function actionConfigInfo()
{
$this->outputInfo("dev config file: " . Yii::getAlias($this->configFile));
$config = $this->readConfig();
if (!$config) {
return $this->outputError("Unable to open config file.");
}
foreach ($config as $key => $value) {
$this->output("{$key} => ".VarDumper::dumpAsString($value));
}
} | php | public function actionConfigInfo()
{
$this->outputInfo("dev config file: " . Yii::getAlias($this->configFile));
$config = $this->readConfig();
if (!$config) {
return $this->outputError("Unable to open config file.");
}
foreach ($config as $key => $value) {
$this->output("{$key} => ".VarDumper::dumpAsString($value));
}
} | [
"public",
"function",
"actionConfigInfo",
"(",
")",
"{",
"$",
"this",
"->",
"outputInfo",
"(",
"\"dev config file: \"",
".",
"Yii",
"::",
"getAlias",
"(",
"$",
"this",
"->",
"configFile",
")",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"readConfig",
"(",
")",
";",
"if",
"(",
"!",
"$",
"config",
")",
"{",
"return",
"$",
"this",
"->",
"outputError",
"(",
"\"Unable to open config file.\"",
")",
";",
"}",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"output",
"(",
"\"{$key} => \"",
".",
"VarDumper",
"::",
"dumpAsString",
"(",
"$",
"value",
")",
")",
";",
"}",
"}"
] | Display config data and location.
@return boolean|void | [
"Display",
"config",
"data",
"and",
"location",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/dev/BaseDevCommand.php#L31-L44 | train |
luyadev/luya | dev/BaseDevCommand.php | BaseDevCommand.readConfig | protected function readConfig()
{
$data = FileHelper::getFileContent($this->configFile);
if ($data) {
return Json::decode($data);
}
return false;
} | php | protected function readConfig()
{
$data = FileHelper::getFileContent($this->configFile);
if ($data) {
return Json::decode($data);
}
return false;
} | [
"protected",
"function",
"readConfig",
"(",
")",
"{",
"$",
"data",
"=",
"FileHelper",
"::",
"getFileContent",
"(",
"$",
"this",
"->",
"configFile",
")",
";",
"if",
"(",
"$",
"data",
")",
"{",
"return",
"Json",
"::",
"decode",
"(",
"$",
"data",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Read entire config and return as array.
@return array|boolean | [
"Read",
"entire",
"config",
"and",
"return",
"as",
"array",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/dev/BaseDevCommand.php#L51-L60 | train |
luyadev/luya | dev/BaseDevCommand.php | BaseDevCommand.getConfig | protected function getConfig($key, $defaultValue = null)
{
$config = $this->readConfig();
return isset($config[$key]) ? $config[$key] : $defaultValue;
} | php | protected function getConfig($key, $defaultValue = null)
{
$config = $this->readConfig();
return isset($config[$key]) ? $config[$key] : $defaultValue;
} | [
"protected",
"function",
"getConfig",
"(",
"$",
"key",
",",
"$",
"defaultValue",
"=",
"null",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"readConfig",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"config",
"[",
"$",
"key",
"]",
":",
"$",
"defaultValue",
";",
"}"
] | Get a specific value for a given key.
@param string $key
@param mixed $defaultValue The value used when nothing is given
@return boolean | [
"Get",
"a",
"specific",
"value",
"for",
"a",
"given",
"key",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/dev/BaseDevCommand.php#L69-L74 | train |
luyadev/luya | dev/BaseDevCommand.php | BaseDevCommand.saveConfig | protected function saveConfig($key, $value)
{
$content = $this->readConfig();
if (!$content) {
$content = [];
}
$content[$key] = $value;
$save = FileHelper::writeFile($this->configFile, Json::encode($content));
if (!$save) {
return $this->outputError("Unable to find config file " . $this->configFile. ". Please create and provide Permissions.");
}
return $value;
} | php | protected function saveConfig($key, $value)
{
$content = $this->readConfig();
if (!$content) {
$content = [];
}
$content[$key] = $value;
$save = FileHelper::writeFile($this->configFile, Json::encode($content));
if (!$save) {
return $this->outputError("Unable to find config file " . $this->configFile. ". Please create and provide Permissions.");
}
return $value;
} | [
"protected",
"function",
"saveConfig",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"readConfig",
"(",
")",
";",
"if",
"(",
"!",
"$",
"content",
")",
"{",
"$",
"content",
"=",
"[",
"]",
";",
"}",
"$",
"content",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"$",
"save",
"=",
"FileHelper",
"::",
"writeFile",
"(",
"$",
"this",
"->",
"configFile",
",",
"Json",
"::",
"encode",
"(",
"$",
"content",
")",
")",
";",
"if",
"(",
"!",
"$",
"save",
")",
"{",
"return",
"$",
"this",
"->",
"outputError",
"(",
"\"Unable to find config file \"",
".",
"$",
"this",
"->",
"configFile",
".",
"\". Please create and provide Permissions.\"",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Save a value in the config for a given key.
@param string $key
@param mixed $value
@return mixed | [
"Save",
"a",
"value",
"in",
"the",
"config",
"for",
"a",
"given",
"key",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/dev/BaseDevCommand.php#L83-L100 | train |
luyadev/luya | core/web/View.php | View.init | public function init()
{
// call parent initializer
parent::init();
// auto register csrf tags if enabled
if ($this->autoRegisterCsrf && Yii::$app->request->enableCsrfValidation) {
$this->registerCsrfMetaTags();
}
} | php | public function init()
{
// call parent initializer
parent::init();
// auto register csrf tags if enabled
if ($this->autoRegisterCsrf && Yii::$app->request->enableCsrfValidation) {
$this->registerCsrfMetaTags();
}
} | [
"public",
"function",
"init",
"(",
")",
"{",
"// call parent initializer",
"parent",
"::",
"init",
"(",
")",
";",
"// auto register csrf tags if enabled",
"if",
"(",
"$",
"this",
"->",
"autoRegisterCsrf",
"&&",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"enableCsrfValidation",
")",
"{",
"$",
"this",
"->",
"registerCsrfMetaTags",
"(",
")",
";",
"}",
"}"
] | Init view object. Implements auto register csrf meta tokens.
@see \yii\base\View::init() | [
"Init",
"view",
"object",
".",
"Implements",
"auto",
"register",
"csrf",
"meta",
"tokens",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/View.php#L32-L40 | train |
luyadev/luya | core/web/View.php | View.getAssetUrl | public function getAssetUrl($assetName)
{
$assetName = ltrim($assetName, '\\');
if (!isset($this->assetBundles[$assetName])) {
throw new Exception("The AssetBundle '$assetName' is not registered.");
}
return $this->assetBundles[$assetName]->baseUrl;
} | php | public function getAssetUrl($assetName)
{
$assetName = ltrim($assetName, '\\');
if (!isset($this->assetBundles[$assetName])) {
throw new Exception("The AssetBundle '$assetName' is not registered.");
}
return $this->assetBundles[$assetName]->baseUrl;
} | [
"public",
"function",
"getAssetUrl",
"(",
"$",
"assetName",
")",
"{",
"$",
"assetName",
"=",
"ltrim",
"(",
"$",
"assetName",
",",
"'\\\\'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"assetBundles",
"[",
"$",
"assetName",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"The AssetBundle '$assetName' is not registered.\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"assetBundles",
"[",
"$",
"assetName",
"]",
"->",
"baseUrl",
";",
"}"
] | Get the url source for an asset.
When registering an asset `\app\assets\ResoucesAsset::register($this)` the $assetName
is `app\assets\ResourcesAsset`.
@param string $assetName The class name of the asset bundle (without the leading backslash)
@return string The internal base path to the asset file.
@throws Exception | [
"Get",
"the",
"url",
"source",
"for",
"an",
"asset",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/View.php#L52-L61 | train |
luyadev/luya | core/web/EmailLink.php | EmailLink.setEmail | public function setEmail($email)
{
$validator = new EmailValidator();
if ($validator->validate($email)) {
$this->_email = $email;
} else {
$this->_email = false;
}
} | php | public function setEmail($email)
{
$validator = new EmailValidator();
if ($validator->validate($email)) {
$this->_email = $email;
} else {
$this->_email = false;
}
} | [
"public",
"function",
"setEmail",
"(",
"$",
"email",
")",
"{",
"$",
"validator",
"=",
"new",
"EmailValidator",
"(",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"validate",
"(",
"$",
"email",
")",
")",
"{",
"$",
"this",
"->",
"_email",
"=",
"$",
"email",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_email",
"=",
"false",
";",
"}",
"}"
] | Setter method for e-mail.
If no valid email is provided, not value is set.
@param string $email The e-mail which should be used for the mailto link. | [
"Setter",
"method",
"for",
"e",
"-",
"mail",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/EmailLink.php#L39-L47 | train |
luyadev/luya | core/console/commands/HealthController.php | HealthController.actionIndex | public function actionIndex()
{
$error = false;
@chdir(Yii::getAlias('@app'));
$this->output('The directory the health commands is applying to: ' . Yii::getAlias('@app'));
foreach ($this->folders as $folder => $writable) {
$mode = ($writable) ? 0777 : 0775;
if (!file_exists($folder)) {
if (FileHelper::createDirectory($folder, $mode)) {
$this->outputSuccess("$folder: successfully created directory");
} else {
$error = true;
$this->outputError("$folder: unable to create directory");
}
} else {
$this->outputInfo("$folder: directory exists already");
}
if ($writable && !is_writable($folder)) {
$this->outputInfo("$folder: is not writeable, try to set mode '$mode'.");
@chmod($folder, $mode);
}
if ($writable) {
if (!is_writable($folder)) {
$error = true;
$this->outputError("$folder: is not writable, please change permissions.");
}
}
}
foreach ($this->files as $file) {
if (file_exists($file)) {
$this->outputInfo("$file: file exists.");
} else {
$error = true;
$this->outputError("$file: file does not exists!");
}
}
return $error ? $this->outputError('Health check found errors!') : $this->outputSuccess('O.K.');
} | php | public function actionIndex()
{
$error = false;
@chdir(Yii::getAlias('@app'));
$this->output('The directory the health commands is applying to: ' . Yii::getAlias('@app'));
foreach ($this->folders as $folder => $writable) {
$mode = ($writable) ? 0777 : 0775;
if (!file_exists($folder)) {
if (FileHelper::createDirectory($folder, $mode)) {
$this->outputSuccess("$folder: successfully created directory");
} else {
$error = true;
$this->outputError("$folder: unable to create directory");
}
} else {
$this->outputInfo("$folder: directory exists already");
}
if ($writable && !is_writable($folder)) {
$this->outputInfo("$folder: is not writeable, try to set mode '$mode'.");
@chmod($folder, $mode);
}
if ($writable) {
if (!is_writable($folder)) {
$error = true;
$this->outputError("$folder: is not writable, please change permissions.");
}
}
}
foreach ($this->files as $file) {
if (file_exists($file)) {
$this->outputInfo("$file: file exists.");
} else {
$error = true;
$this->outputError("$file: file does not exists!");
}
}
return $error ? $this->outputError('Health check found errors!') : $this->outputSuccess('O.K.');
} | [
"public",
"function",
"actionIndex",
"(",
")",
"{",
"$",
"error",
"=",
"false",
";",
"@",
"chdir",
"(",
"Yii",
"::",
"getAlias",
"(",
"'@app'",
")",
")",
";",
"$",
"this",
"->",
"output",
"(",
"'The directory the health commands is applying to: '",
".",
"Yii",
"::",
"getAlias",
"(",
"'@app'",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"folders",
"as",
"$",
"folder",
"=>",
"$",
"writable",
")",
"{",
"$",
"mode",
"=",
"(",
"$",
"writable",
")",
"?",
"0777",
":",
"0775",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"folder",
")",
")",
"{",
"if",
"(",
"FileHelper",
"::",
"createDirectory",
"(",
"$",
"folder",
",",
"$",
"mode",
")",
")",
"{",
"$",
"this",
"->",
"outputSuccess",
"(",
"\"$folder: successfully created directory\"",
")",
";",
"}",
"else",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"this",
"->",
"outputError",
"(",
"\"$folder: unable to create directory\"",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"outputInfo",
"(",
"\"$folder: directory exists already\"",
")",
";",
"}",
"if",
"(",
"$",
"writable",
"&&",
"!",
"is_writable",
"(",
"$",
"folder",
")",
")",
"{",
"$",
"this",
"->",
"outputInfo",
"(",
"\"$folder: is not writeable, try to set mode '$mode'.\"",
")",
";",
"@",
"chmod",
"(",
"$",
"folder",
",",
"$",
"mode",
")",
";",
"}",
"if",
"(",
"$",
"writable",
")",
"{",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"folder",
")",
")",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"this",
"->",
"outputError",
"(",
"\"$folder: is not writable, please change permissions.\"",
")",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"outputInfo",
"(",
"\"$file: file exists.\"",
")",
";",
"}",
"else",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"this",
"->",
"outputError",
"(",
"\"$file: file does not exists!\"",
")",
";",
"}",
"}",
"return",
"$",
"error",
"?",
"$",
"this",
"->",
"outputError",
"(",
"'Health check found errors!'",
")",
":",
"$",
"this",
"->",
"outputSuccess",
"(",
"'O.K.'",
")",
";",
"}"
] | Create all required directories an check whether they are writeable or not.
@return string The action output. | [
"Create",
"all",
"required",
"directories",
"an",
"check",
"whether",
"they",
"are",
"writeable",
"or",
"not",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/console/commands/HealthController.php#L40-L84 | train |
luyadev/luya | core/web/JsonLd.php | JsonLd.addGraph | public static function addGraph($data)
{
self::registerView();
if (is_scalar($data)) {
throw new Exception("Data must be either an array or an object of type luya\web\jsonld\BaseThing.");
}
Yii::$app->view->params['@context'] = 'https://schema.org';
Yii::$app->view->params['@graph'][] = $data;
return $data;
} | php | public static function addGraph($data)
{
self::registerView();
if (is_scalar($data)) {
throw new Exception("Data must be either an array or an object of type luya\web\jsonld\BaseThing.");
}
Yii::$app->view->params['@context'] = 'https://schema.org';
Yii::$app->view->params['@graph'][] = $data;
return $data;
} | [
"public",
"static",
"function",
"addGraph",
"(",
"$",
"data",
")",
"{",
"self",
"::",
"registerView",
"(",
")",
";",
"if",
"(",
"is_scalar",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Data must be either an array or an object of type luya\\web\\jsonld\\BaseThing.\"",
")",
";",
"}",
"Yii",
"::",
"$",
"app",
"->",
"view",
"->",
"params",
"[",
"'@context'",
"]",
"=",
"'https://schema.org'",
";",
"Yii",
"::",
"$",
"app",
"->",
"view",
"->",
"params",
"[",
"'@graph'",
"]",
"[",
"]",
"=",
"$",
"data",
";",
"return",
"$",
"data",
";",
"}"
] | Register graph data.
@param \luya\web\jsonld\BaseThing|array $data Can be either an array or an object based on {{luya\web\jsonld\BaseThing}} which contains the Arrayable Inteface.
@return array|object | [
"Register",
"graph",
"data",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/JsonLd.php#L299-L311 | train |
luyadev/luya | core/web/JsonLd.php | JsonLd.registerView | protected static function registerView()
{
if (self::$_view === null) {
Yii::$app->view->on(View::EVENT_BEGIN_BODY, function ($event) {
echo '<script type="application/ld+json">' . Json::encode($event->sender->params) . '</script>';
});
self::$_view = true;
}
} | php | protected static function registerView()
{
if (self::$_view === null) {
Yii::$app->view->on(View::EVENT_BEGIN_BODY, function ($event) {
echo '<script type="application/ld+json">' . Json::encode($event->sender->params) . '</script>';
});
self::$_view = true;
}
} | [
"protected",
"static",
"function",
"registerView",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_view",
"===",
"null",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"view",
"->",
"on",
"(",
"View",
"::",
"EVENT_BEGIN_BODY",
",",
"function",
"(",
"$",
"event",
")",
"{",
"echo",
"'<script type=\"application/ld+json\">'",
".",
"Json",
"::",
"encode",
"(",
"$",
"event",
"->",
"sender",
"->",
"params",
")",
".",
"'</script>'",
";",
"}",
")",
";",
"self",
"::",
"$",
"_view",
"=",
"true",
";",
"}",
"}"
] | Register the view file an observe the event which then reads the data from @graph params key. | [
"Register",
"the",
"view",
"file",
"an",
"observe",
"the",
"event",
"which",
"then",
"reads",
"the",
"data",
"from"
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/JsonLd.php#L329-L338 | train |
luyadev/luya | core/validators/FloatValidator.php | FloatValidator.validateAttribute | public function validateAttribute($model, $attribute)
{
$value = $model->$attribute;
if (!is_numeric($value) && !is_float($value)) {
return $model->addError($attribute, Yii::t('luya', $this->message, ['attribute' => $model->getAttributeLabel($attribute)]));
}
} | php | public function validateAttribute($model, $attribute)
{
$value = $model->$attribute;
if (!is_numeric($value) && !is_float($value)) {
return $model->addError($attribute, Yii::t('luya', $this->message, ['attribute' => $model->getAttributeLabel($attribute)]));
}
} | [
"public",
"function",
"validateAttribute",
"(",
"$",
"model",
",",
"$",
"attribute",
")",
"{",
"$",
"value",
"=",
"$",
"model",
"->",
"$",
"attribute",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"value",
")",
"&&",
"!",
"is_float",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"model",
"->",
"addError",
"(",
"$",
"attribute",
",",
"Yii",
"::",
"t",
"(",
"'luya'",
",",
"$",
"this",
"->",
"message",
",",
"[",
"'attribute'",
"=>",
"$",
"model",
"->",
"getAttributeLabel",
"(",
"$",
"attribute",
")",
"]",
")",
")",
";",
"}",
"}"
] | Validate the value if is_numeric or if not is_float.
@see \yii\validators\Validator::validateAttribute() | [
"Validate",
"the",
"value",
"if",
"is_numeric",
"or",
"if",
"not",
"is_float",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/validators/FloatValidator.php#L46-L52 | train |
luyadev/luya | core/tag/tags/TelTag.php | TelTag.parse | public function parse($value, $sub)
{
return Html::a(empty($sub) ? $value : $sub, 'tel:' . $this->ensureNumber($value));
} | php | public function parse($value, $sub)
{
return Html::a(empty($sub) ? $value : $sub, 'tel:' . $this->ensureNumber($value));
} | [
"public",
"function",
"parse",
"(",
"$",
"value",
",",
"$",
"sub",
")",
"{",
"return",
"Html",
"::",
"a",
"(",
"empty",
"(",
"$",
"sub",
")",
"?",
"$",
"value",
":",
"$",
"sub",
",",
"'tel:'",
".",
"$",
"this",
"->",
"ensureNumber",
"(",
"$",
"value",
")",
")",
";",
"}"
] | Generate the Tel Tag.
@param string $value The Brackets value `[]`.
@param string $sub The optional Parentheses value `()`
@see \luya\tag\TagInterface::parse()
@return string The parser tag. | [
"Generate",
"the",
"Tel",
"Tag",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/tag/tags/TelTag.php#L50-L53 | train |
luyadev/luya | core/web/WebsiteLink.php | WebsiteLink.setHref | public function setHref($href)
{
if (StringHelper::startsWith($href, '//')) {
$this->_href = Url::base(true) . str_replace('//', '/', $href);
} else {
$this->_href = Url::ensureHttp($href);
}
} | php | public function setHref($href)
{
if (StringHelper::startsWith($href, '//')) {
$this->_href = Url::base(true) . str_replace('//', '/', $href);
} else {
$this->_href = Url::ensureHttp($href);
}
} | [
"public",
"function",
"setHref",
"(",
"$",
"href",
")",
"{",
"if",
"(",
"StringHelper",
"::",
"startsWith",
"(",
"$",
"href",
",",
"'//'",
")",
")",
"{",
"$",
"this",
"->",
"_href",
"=",
"Url",
"::",
"base",
"(",
"true",
")",
".",
"str_replace",
"(",
"'//'",
",",
"'/'",
",",
"$",
"href",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_href",
"=",
"Url",
"::",
"ensureHttp",
"(",
"$",
"href",
")",
";",
"}",
"}"
] | Set the href value for an external link resource.
@param string $href The external link href value, the http protcol will be ensured. | [
"Set",
"the",
"href",
"value",
"for",
"an",
"external",
"link",
"resource",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/WebsiteLink.php#L47-L54 | train |
luyadev/luya | core/helpers/Json.php | Json.isJson | public static function isJson($value)
{
if (!is_scalar($value)) {
return false;
}
$firstChar = substr($value, 0, 1);
if ($firstChar !== '{' && $firstChar !== '[') {
return false;
}
$json_check = json_decode($value);
return json_last_error() === JSON_ERROR_NONE;
} | php | public static function isJson($value)
{
if (!is_scalar($value)) {
return false;
}
$firstChar = substr($value, 0, 1);
if ($firstChar !== '{' && $firstChar !== '[') {
return false;
}
$json_check = json_decode($value);
return json_last_error() === JSON_ERROR_NONE;
} | [
"public",
"static",
"function",
"isJson",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"firstChar",
"=",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"1",
")",
";",
"if",
"(",
"$",
"firstChar",
"!==",
"'{'",
"&&",
"$",
"firstChar",
"!==",
"'['",
")",
"{",
"return",
"false",
";",
"}",
"$",
"json_check",
"=",
"json_decode",
"(",
"$",
"value",
")",
";",
"return",
"json_last_error",
"(",
")",
"===",
"JSON_ERROR_NONE",
";",
"}"
] | Checks if a string is a json or not.
Example values which return true:
```php
Json::isJson('{"123":"456"}');
Json::isJson('{"123":456}');
Json::isJson('[{"123":"456"}]');
Json::isJson('[{"123":"456"}]');
```
@param mixed $value The value to test if its a json or not.
@return boolean Whether the string is a json or not. | [
"Checks",
"if",
"a",
"string",
"is",
"a",
"json",
"or",
"not",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/helpers/Json.php#L34-L50 | train |
luyadev/luya | dev/RepoController.php | RepoController.actionUpdate | public function actionUpdate()
{
foreach ($this->repos as $repo) {
$this->rebaseRepo($repo, $this->getFilesystemRepoPath($repo));
}
foreach ($this->getConfig(self::CONFIG_VAR_CUSTOMCLONES, []) as $repo => $path) {
$this->rebaseRepo($repo, $path);
}
} | php | public function actionUpdate()
{
foreach ($this->repos as $repo) {
$this->rebaseRepo($repo, $this->getFilesystemRepoPath($repo));
}
foreach ($this->getConfig(self::CONFIG_VAR_CUSTOMCLONES, []) as $repo => $path) {
$this->rebaseRepo($repo, $path);
}
} | [
"public",
"function",
"actionUpdate",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"repos",
"as",
"$",
"repo",
")",
"{",
"$",
"this",
"->",
"rebaseRepo",
"(",
"$",
"repo",
",",
"$",
"this",
"->",
"getFilesystemRepoPath",
"(",
"$",
"repo",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"self",
"::",
"CONFIG_VAR_CUSTOMCLONES",
",",
"[",
"]",
")",
"as",
"$",
"repo",
"=>",
"$",
"path",
")",
"{",
"$",
"this",
"->",
"rebaseRepo",
"(",
"$",
"repo",
",",
"$",
"path",
")",
";",
"}",
"}"
] | Update all repos to master branch from upstream. | [
"Update",
"all",
"repos",
"to",
"master",
"branch",
"from",
"upstream",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/dev/RepoController.php#L157-L166 | train |
luyadev/luya | dev/RepoController.php | RepoController.actionRemove | public function actionRemove($repo)
{
FileHelper::removeDirectory($this->getFilesystemRepoPath($repo));
$clones = $this->getConfig(self::CONFIG_VAR_CUSTOMCLONES, []);
if (isset($clones[$repo])) {
unset($clones[$repo]);
$this->saveConfig(self::CONFIG_VAR_CUSTOMCLONES, $clones);
}
return $this->outputSuccess("Removed repo {$repo}.");
} | php | public function actionRemove($repo)
{
FileHelper::removeDirectory($this->getFilesystemRepoPath($repo));
$clones = $this->getConfig(self::CONFIG_VAR_CUSTOMCLONES, []);
if (isset($clones[$repo])) {
unset($clones[$repo]);
$this->saveConfig(self::CONFIG_VAR_CUSTOMCLONES, $clones);
}
return $this->outputSuccess("Removed repo {$repo}.");
} | [
"public",
"function",
"actionRemove",
"(",
"$",
"repo",
")",
"{",
"FileHelper",
"::",
"removeDirectory",
"(",
"$",
"this",
"->",
"getFilesystemRepoPath",
"(",
"$",
"repo",
")",
")",
";",
"$",
"clones",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"self",
"::",
"CONFIG_VAR_CUSTOMCLONES",
",",
"[",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"clones",
"[",
"$",
"repo",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"clones",
"[",
"$",
"repo",
"]",
")",
";",
"$",
"this",
"->",
"saveConfig",
"(",
"self",
"::",
"CONFIG_VAR_CUSTOMCLONES",
",",
"$",
"clones",
")",
";",
"}",
"return",
"$",
"this",
"->",
"outputSuccess",
"(",
"\"Removed repo {$repo}.\"",
")",
";",
"}"
] | Remove a given repo from filesystem.
@param string $repo The repo name like `luya-module-cms` without vendor. | [
"Remove",
"a",
"given",
"repo",
"from",
"filesystem",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/dev/RepoController.php#L233-L243 | train |
luyadev/luya | core/Hook.php | Hook.on | public static function on($name, $value, $prepend = false)
{
$object = new HookEvent(['handler' => $value]);
if ($prepend) {
array_unshift(static::$_hooks[$name], $object);
} else {
static::$_hooks[$name][] = $object;
}
} | php | public static function on($name, $value, $prepend = false)
{
$object = new HookEvent(['handler' => $value]);
if ($prepend) {
array_unshift(static::$_hooks[$name], $object);
} else {
static::$_hooks[$name][] = $object;
}
} | [
"public",
"static",
"function",
"on",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"prepend",
"=",
"false",
")",
"{",
"$",
"object",
"=",
"new",
"HookEvent",
"(",
"[",
"'handler'",
"=>",
"$",
"value",
"]",
")",
";",
"if",
"(",
"$",
"prepend",
")",
"{",
"array_unshift",
"(",
"static",
"::",
"$",
"_hooks",
"[",
"$",
"name",
"]",
",",
"$",
"object",
")",
";",
"}",
"else",
"{",
"static",
"::",
"$",
"_hooks",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"$",
"object",
";",
"}",
"}"
] | Register a hook listener.
Define the name of the type of listener.
@param string $name The name of the hook.
@param callable|array $value An array with `[$object, 'method']` or a callable function `function($hook) {}`.
@param boolean $prepend Whether to prepend the item to the start or as by default to the end of the stack. | [
"Register",
"a",
"hook",
"listener",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/Hook.php#L58-L67 | train |
luyadev/luya | core/Hook.php | Hook.string | public static function string($name)
{
$buffer = [];
foreach (self::trigger($name) as $hook) {
$buffer[] = $hook->output;
}
return implode("", $buffer);
} | php | public static function string($name)
{
$buffer = [];
foreach (self::trigger($name) as $hook) {
$buffer[] = $hook->output;
}
return implode("", $buffer);
} | [
"public",
"static",
"function",
"string",
"(",
"$",
"name",
")",
"{",
"$",
"buffer",
"=",
"[",
"]",
";",
"foreach",
"(",
"self",
"::",
"trigger",
"(",
"$",
"name",
")",
"as",
"$",
"hook",
")",
"{",
"$",
"buffer",
"[",
"]",
"=",
"$",
"hook",
"->",
"output",
";",
"}",
"return",
"implode",
"(",
"\"\"",
",",
"$",
"buffer",
")",
";",
"}"
] | Get the string output of the hooks.
@param string $name The name of the hook to trigger.
@return string | [
"Get",
"the",
"string",
"output",
"of",
"the",
"hooks",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/Hook.php#L113-L121 | train |
luyadev/luya | core/Hook.php | Hook.iterate | public static function iterate($name)
{
$buffer = [];
foreach (self::trigger($name) as $hook) {
$buffer = array_merge($buffer, $hook->getIterations());
}
return $buffer;
} | php | public static function iterate($name)
{
$buffer = [];
foreach (self::trigger($name) as $hook) {
$buffer = array_merge($buffer, $hook->getIterations());
}
return $buffer;
} | [
"public",
"static",
"function",
"iterate",
"(",
"$",
"name",
")",
"{",
"$",
"buffer",
"=",
"[",
"]",
";",
"foreach",
"(",
"self",
"::",
"trigger",
"(",
"$",
"name",
")",
"as",
"$",
"hook",
")",
"{",
"$",
"buffer",
"=",
"array_merge",
"(",
"$",
"buffer",
",",
"$",
"hook",
"->",
"getIterations",
"(",
")",
")",
";",
"}",
"return",
"$",
"buffer",
";",
"}"
] | Get the array output of iteration hooks.
@param string $name The name of the hook to trigger.
@return array | [
"Get",
"the",
"array",
"output",
"of",
"iteration",
"hooks",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/Hook.php#L129-L137 | train |
luyadev/luya | core/tag/tags/LinkTag.php | LinkTag.parse | public function parse($value, $sub)
{
if (substr($value, 0, 2) == '//') {
$value = StringHelper::replaceFirst('//', Url::base(true) . '/', $value);
$external = false;
} else {
$external = true;
}
$value = Url::ensureHttp($value);
$label = empty($sub) ? $value : $sub;
return Html::a($label, $value, ['class' => $external ? 'link-external' : 'link-internal', 'target' => $external ? '_blank' : null]);
} | php | public function parse($value, $sub)
{
if (substr($value, 0, 2) == '//') {
$value = StringHelper::replaceFirst('//', Url::base(true) . '/', $value);
$external = false;
} else {
$external = true;
}
$value = Url::ensureHttp($value);
$label = empty($sub) ? $value : $sub;
return Html::a($label, $value, ['class' => $external ? 'link-external' : 'link-internal', 'target' => $external ? '_blank' : null]);
} | [
"public",
"function",
"parse",
"(",
"$",
"value",
",",
"$",
"sub",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"2",
")",
"==",
"'//'",
")",
"{",
"$",
"value",
"=",
"StringHelper",
"::",
"replaceFirst",
"(",
"'//'",
",",
"Url",
"::",
"base",
"(",
"true",
")",
".",
"'/'",
",",
"$",
"value",
")",
";",
"$",
"external",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"external",
"=",
"true",
";",
"}",
"$",
"value",
"=",
"Url",
"::",
"ensureHttp",
"(",
"$",
"value",
")",
";",
"$",
"label",
"=",
"empty",
"(",
"$",
"sub",
")",
"?",
"$",
"value",
":",
"$",
"sub",
";",
"return",
"Html",
"::",
"a",
"(",
"$",
"label",
",",
"$",
"value",
",",
"[",
"'class'",
"=>",
"$",
"external",
"?",
"'link-external'",
":",
"'link-internal'",
",",
"'target'",
"=>",
"$",
"external",
"?",
"'_blank'",
":",
"null",
"]",
")",
";",
"}"
] | Generate the Link Tag.
@param string $value The Brackets value `[]`.
@param string $sub The optional Parentheses value `()`
@see \luya\tag\TagInterface::parse()
@return string The parser tag. | [
"Generate",
"the",
"Link",
"Tag",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/tag/tags/LinkTag.php#L53-L66 | train |
luyadev/luya | core/console/commands/ModuleController.php | ModuleController.renderReadme | public function renderReadme($folders, $name, $ns)
{
return $this->view->render('@luya/console/commands/views/module/readme.php', [
'folders' => $folders,
'name' => $name,
'humanName' => $this->humanizeName($name),
'ns' => $ns,
'luyaText' => $this->getGeneratorText('module/create'),
]);
} | php | public function renderReadme($folders, $name, $ns)
{
return $this->view->render('@luya/console/commands/views/module/readme.php', [
'folders' => $folders,
'name' => $name,
'humanName' => $this->humanizeName($name),
'ns' => $ns,
'luyaText' => $this->getGeneratorText('module/create'),
]);
} | [
"public",
"function",
"renderReadme",
"(",
"$",
"folders",
",",
"$",
"name",
",",
"$",
"ns",
")",
"{",
"return",
"$",
"this",
"->",
"view",
"->",
"render",
"(",
"'@luya/console/commands/views/module/readme.php'",
",",
"[",
"'folders'",
"=>",
"$",
"folders",
",",
"'name'",
"=>",
"$",
"name",
",",
"'humanName'",
"=>",
"$",
"this",
"->",
"humanizeName",
"(",
"$",
"name",
")",
",",
"'ns'",
"=>",
"$",
"ns",
",",
"'luyaText'",
"=>",
"$",
"this",
"->",
"getGeneratorText",
"(",
"'module/create'",
")",
",",
"]",
")",
";",
"}"
] | Render the readme template.
@param array $folders
@param string $name
@param string $ns
@return string | [
"Render",
"the",
"readme",
"template",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/console/commands/ModuleController.php#L41-L50 | train |
luyadev/luya | core/web/Composition.php | Composition.isHostAllowed | public function isHostAllowed($allowedHosts)
{
$currentHost = $this->request->hostName;
$rules = (array) $allowedHosts;
foreach ($rules as $allowedHost) {
if (StringHelper::matchWildcard($allowedHost, $currentHost)) {
return true;
}
}
return false;
} | php | public function isHostAllowed($allowedHosts)
{
$currentHost = $this->request->hostName;
$rules = (array) $allowedHosts;
foreach ($rules as $allowedHost) {
if (StringHelper::matchWildcard($allowedHost, $currentHost)) {
return true;
}
}
return false;
} | [
"public",
"function",
"isHostAllowed",
"(",
"$",
"allowedHosts",
")",
"{",
"$",
"currentHost",
"=",
"$",
"this",
"->",
"request",
"->",
"hostName",
";",
"$",
"rules",
"=",
"(",
"array",
")",
"$",
"allowedHosts",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"allowedHost",
")",
"{",
"if",
"(",
"StringHelper",
"::",
"matchWildcard",
"(",
"$",
"allowedHost",
",",
"$",
"currentHost",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if the current request name against the allowedHosts list.
@return boolean Whether the current hostName is allowed or not.
@since 1.0.5 | [
"Checks",
"if",
"the",
"current",
"request",
"name",
"against",
"the",
"allowedHosts",
"list",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/Composition.php#L178-L191 | train |
luyadev/luya | core/web/Composition.php | Composition.getKeys | public function getKeys()
{
if ($this->_keys === null) {
$this->_keys = $this->getResolvedPathInfo($this->request)->resolvedValues;
}
return $this->_keys;
} | php | public function getKeys()
{
if ($this->_keys === null) {
$this->_keys = $this->getResolvedPathInfo($this->request)->resolvedValues;
}
return $this->_keys;
} | [
"public",
"function",
"getKeys",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_keys",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_keys",
"=",
"$",
"this",
"->",
"getResolvedPathInfo",
"(",
"$",
"this",
"->",
"request",
")",
"->",
"resolvedValues",
";",
"}",
"return",
"$",
"this",
"->",
"_keys",
";",
"}"
] | Resolves the current key and value objects based on the current pathInto and pattern from Request component.
@return array An array with key values like `['langShortCode' => 'en']`.
@since 1.0.5 | [
"Resolves",
"the",
"current",
"key",
"and",
"value",
"objects",
"based",
"on",
"the",
"current",
"pathInto",
"and",
"pattern",
"from",
"Request",
"component",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/Composition.php#L201-L208 | train |
luyadev/luya | core/web/Composition.php | Composition.getKey | public function getKey($key, $defaultValue = false)
{
$this->getKeys();
return isset($this->_keys[$key]) ? $this->_keys[$key] : $defaultValue;
} | php | public function getKey($key, $defaultValue = false)
{
$this->getKeys();
return isset($this->_keys[$key]) ? $this->_keys[$key] : $defaultValue;
} | [
"public",
"function",
"getKey",
"(",
"$",
"key",
",",
"$",
"defaultValue",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"getKeys",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"_keys",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"_keys",
"[",
"$",
"key",
"]",
":",
"$",
"defaultValue",
";",
"}"
] | Get value from the composition array for the provided key, if the key does not existing the default value
will be return. The standard value of the defaultValue is false, so if nothing defined and the could not
be found, the return value is `false`.
@param string $key The key to find in the composition array e.g. langShortCode
@param string $defaultValue The default value if they could not be found
@return string|bool | [
"Get",
"value",
"from",
"the",
"composition",
"array",
"for",
"the",
"provided",
"key",
"if",
"the",
"key",
"does",
"not",
"existing",
"the",
"default",
"value",
"will",
"be",
"return",
".",
"The",
"standard",
"value",
"of",
"the",
"defaultValue",
"is",
"false",
"so",
"if",
"nothing",
"defined",
"and",
"the",
"could",
"not",
"be",
"found",
"the",
"return",
"value",
"is",
"false",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/Composition.php#L242-L247 | train |
luyadev/luya | core/web/Composition.php | Composition.createRouteEnsure | public function createRouteEnsure(array $overrideKeys = [])
{
if (isset($overrideKeys['langShortCode'])) {
$langShortCode = $overrideKeys['langShortCode'];
} else {
$langShortCode = $this->langShortCode;
}
return $this->hidden || (!$this->hidden && $langShortCode == $this->defaultLangShortCode && $this->hideDefaultPrefixOnly) ? '' : $this->createRoute($overrideKeys);
} | php | public function createRouteEnsure(array $overrideKeys = [])
{
if (isset($overrideKeys['langShortCode'])) {
$langShortCode = $overrideKeys['langShortCode'];
} else {
$langShortCode = $this->langShortCode;
}
return $this->hidden || (!$this->hidden && $langShortCode == $this->defaultLangShortCode && $this->hideDefaultPrefixOnly) ? '' : $this->createRoute($overrideKeys);
} | [
"public",
"function",
"createRouteEnsure",
"(",
"array",
"$",
"overrideKeys",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"overrideKeys",
"[",
"'langShortCode'",
"]",
")",
")",
"{",
"$",
"langShortCode",
"=",
"$",
"overrideKeys",
"[",
"'langShortCode'",
"]",
";",
"}",
"else",
"{",
"$",
"langShortCode",
"=",
"$",
"this",
"->",
"langShortCode",
";",
"}",
"return",
"$",
"this",
"->",
"hidden",
"||",
"(",
"!",
"$",
"this",
"->",
"hidden",
"&&",
"$",
"langShortCode",
"==",
"$",
"this",
"->",
"defaultLangShortCode",
"&&",
"$",
"this",
"->",
"hideDefaultPrefixOnly",
")",
"?",
"''",
":",
"$",
"this",
"->",
"createRoute",
"(",
"$",
"overrideKeys",
")",
";",
"}"
] | Create a route but ensures if composition is hidden anyhow.
@param array $overrideKeys
@return string | [
"Create",
"a",
"route",
"but",
"ensures",
"if",
"composition",
"is",
"hidden",
"anyhow",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/Composition.php#L268-L276 | train |
luyadev/luya | core/base/Boot.php | Boot.getIsCli | public function getIsCli()
{
if ($this->_isCli === null) {
$this->_isCli = $this->getSapiName() === 'cli';
}
return $this->_isCli;
} | php | public function getIsCli()
{
if ($this->_isCli === null) {
$this->_isCli = $this->getSapiName() === 'cli';
}
return $this->_isCli;
} | [
"public",
"function",
"getIsCli",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_isCli",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_isCli",
"=",
"$",
"this",
"->",
"getSapiName",
"(",
")",
"===",
"'cli'",
";",
"}",
"return",
"$",
"this",
"->",
"_isCli",
";",
"}"
] | Getter method whether current request is cli or not.
If not set via setIsCli() the value is determined trough php_sapi_name();
@return boolean Whether current request is console env or not.
@since 1.0.12 | [
"Getter",
"method",
"whether",
"current",
"request",
"is",
"cli",
"or",
"not",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/base/Boot.php#L98-L105 | train |
luyadev/luya | core/base/Boot.php | Boot.getConfigArray | public function getConfigArray()
{
if ($this->_configArray === null) {
if (!file_exists($this->configFile)) {
if (!$this->getIsCli()) {
throw new Exception("Unable to load the config file '".$this->configFile."'.");
}
$config = ['id' => 'consoleapp', 'basePath' => dirname(__DIR__)];
} else {
$config = require $this->configFile;
}
if (!is_array($config)) {
throw new Exception("config file '".$this->configFile."' found but no array returning.");
}
// preset the values from the defaultConfigArray
if (!empty($this->prependConfigArray())) {
$config = ArrayHelper::merge($config, $this->prependConfigArray());
}
$this->_configArray = $config;
}
return $this->_configArray;
} | php | public function getConfigArray()
{
if ($this->_configArray === null) {
if (!file_exists($this->configFile)) {
if (!$this->getIsCli()) {
throw new Exception("Unable to load the config file '".$this->configFile."'.");
}
$config = ['id' => 'consoleapp', 'basePath' => dirname(__DIR__)];
} else {
$config = require $this->configFile;
}
if (!is_array($config)) {
throw new Exception("config file '".$this->configFile."' found but no array returning.");
}
// preset the values from the defaultConfigArray
if (!empty($this->prependConfigArray())) {
$config = ArrayHelper::merge($config, $this->prependConfigArray());
}
$this->_configArray = $config;
}
return $this->_configArray;
} | [
"public",
"function",
"getConfigArray",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_configArray",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"configFile",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getIsCli",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Unable to load the config file '\"",
".",
"$",
"this",
"->",
"configFile",
".",
"\"'.\"",
")",
";",
"}",
"$",
"config",
"=",
"[",
"'id'",
"=>",
"'consoleapp'",
",",
"'basePath'",
"=>",
"dirname",
"(",
"__DIR__",
")",
"]",
";",
"}",
"else",
"{",
"$",
"config",
"=",
"require",
"$",
"this",
"->",
"configFile",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"config file '\"",
".",
"$",
"this",
"->",
"configFile",
".",
"\"' found but no array returning.\"",
")",
";",
"}",
"// preset the values from the defaultConfigArray",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"prependConfigArray",
"(",
")",
")",
")",
"{",
"$",
"config",
"=",
"ArrayHelper",
"::",
"merge",
"(",
"$",
"config",
",",
"$",
"this",
"->",
"prependConfigArray",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"_configArray",
"=",
"$",
"config",
";",
"}",
"return",
"$",
"this",
"->",
"_configArray",
";",
"}"
] | Get the config array from the configFile path with the predefined values.
@throws \luya\Exception Throws exception if the config file does not exists.
@return array The array which will be injected into the Application Constructor. | [
"Get",
"the",
"config",
"array",
"from",
"the",
"configFile",
"path",
"with",
"the",
"predefined",
"values",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/base/Boot.php#L169-L195 | train |
luyadev/luya | core/base/Boot.php | Boot.applicationConsole | public function applicationConsole()
{
$this->setIsCli(true);
$config = $this->getConfigArray();
$config['defaultRoute'] = 'help';
if (isset($config['components'])) {
if (isset($config['components']['composition'])) {
unset($config['components']['composition']);
}
}
$this->includeYii();
$baseUrl = null;
if (isset($config['consoleBaseUrl'])) {
$baseUrl = $config['consoleBaseUrl'];
} elseif (isset($config['consoleHostInfo'])) {
$baseUrl = '/';
}
$mergedConfig = ArrayHelper::merge($config, [
'bootstrap' => ['luya\console\Bootstrap'],
'components' => [
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'baseUrl' => $baseUrl,
'hostInfo' => isset($config['consoleHostInfo']) ? $config['consoleHostInfo'] : null,
],
],
]);
$this->app = new ConsoleApplication($mergedConfig);
if (!$this->mockOnly) {
exit($this->app->run());
}
} | php | public function applicationConsole()
{
$this->setIsCli(true);
$config = $this->getConfigArray();
$config['defaultRoute'] = 'help';
if (isset($config['components'])) {
if (isset($config['components']['composition'])) {
unset($config['components']['composition']);
}
}
$this->includeYii();
$baseUrl = null;
if (isset($config['consoleBaseUrl'])) {
$baseUrl = $config['consoleBaseUrl'];
} elseif (isset($config['consoleHostInfo'])) {
$baseUrl = '/';
}
$mergedConfig = ArrayHelper::merge($config, [
'bootstrap' => ['luya\console\Bootstrap'],
'components' => [
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'baseUrl' => $baseUrl,
'hostInfo' => isset($config['consoleHostInfo']) ? $config['consoleHostInfo'] : null,
],
],
]);
$this->app = new ConsoleApplication($mergedConfig);
if (!$this->mockOnly) {
exit($this->app->run());
}
} | [
"public",
"function",
"applicationConsole",
"(",
")",
"{",
"$",
"this",
"->",
"setIsCli",
"(",
"true",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfigArray",
"(",
")",
";",
"$",
"config",
"[",
"'defaultRoute'",
"]",
"=",
"'help'",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'components'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'components'",
"]",
"[",
"'composition'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"config",
"[",
"'components'",
"]",
"[",
"'composition'",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"includeYii",
"(",
")",
";",
"$",
"baseUrl",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'consoleBaseUrl'",
"]",
")",
")",
"{",
"$",
"baseUrl",
"=",
"$",
"config",
"[",
"'consoleBaseUrl'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"config",
"[",
"'consoleHostInfo'",
"]",
")",
")",
"{",
"$",
"baseUrl",
"=",
"'/'",
";",
"}",
"$",
"mergedConfig",
"=",
"ArrayHelper",
"::",
"merge",
"(",
"$",
"config",
",",
"[",
"'bootstrap'",
"=>",
"[",
"'luya\\console\\Bootstrap'",
"]",
",",
"'components'",
"=>",
"[",
"'urlManager'",
"=>",
"[",
"'class'",
"=>",
"'yii\\web\\UrlManager'",
",",
"'enablePrettyUrl'",
"=>",
"true",
",",
"'showScriptName'",
"=>",
"false",
",",
"'baseUrl'",
"=>",
"$",
"baseUrl",
",",
"'hostInfo'",
"=>",
"isset",
"(",
"$",
"config",
"[",
"'consoleHostInfo'",
"]",
")",
"?",
"$",
"config",
"[",
"'consoleHostInfo'",
"]",
":",
"null",
",",
"]",
",",
"]",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"=",
"new",
"ConsoleApplication",
"(",
"$",
"mergedConfig",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"mockOnly",
")",
"{",
"exit",
"(",
"$",
"this",
"->",
"app",
"->",
"run",
"(",
")",
")",
";",
"}",
"}"
] | Run Cli-Application based on the provided config file.
@return string|integer | [
"Run",
"Cli",
"-",
"Application",
"based",
"on",
"the",
"provided",
"config",
"file",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/base/Boot.php#L216-L252 | train |
luyadev/luya | core/base/Boot.php | Boot.applicationWeb | public function applicationWeb()
{
$config = $this->getConfigArray();
$this->includeYii();
$mergedConfig = ArrayHelper::merge($config, ['bootstrap' => ['luya\web\Bootstrap']]);
$this->app = new WebApplication($mergedConfig);
if (!$this->mockOnly) {
return $this->app->run();
}
} | php | public function applicationWeb()
{
$config = $this->getConfigArray();
$this->includeYii();
$mergedConfig = ArrayHelper::merge($config, ['bootstrap' => ['luya\web\Bootstrap']]);
$this->app = new WebApplication($mergedConfig);
if (!$this->mockOnly) {
return $this->app->run();
}
} | [
"public",
"function",
"applicationWeb",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfigArray",
"(",
")",
";",
"$",
"this",
"->",
"includeYii",
"(",
")",
";",
"$",
"mergedConfig",
"=",
"ArrayHelper",
"::",
"merge",
"(",
"$",
"config",
",",
"[",
"'bootstrap'",
"=>",
"[",
"'luya\\web\\Bootstrap'",
"]",
"]",
")",
";",
"$",
"this",
"->",
"app",
"=",
"new",
"WebApplication",
"(",
"$",
"mergedConfig",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"mockOnly",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"run",
"(",
")",
";",
"}",
"}"
] | Run Web-Application based on the provided config file.
@return string Returns the Yii Application run() method if mock is disabled. Otherwise returns void | [
"Run",
"Web",
"-",
"Application",
"based",
"on",
"the",
"provided",
"config",
"file",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/base/Boot.php#L259-L268 | train |
luyadev/luya | core/base/Boot.php | Boot.includeYii | private function includeYii()
{
if (file_exists($this->_baseYiiFile)) {
defined('LUYA_YII_VENDOR') ?: define('LUYA_YII_VENDOR', dirname($this->_baseYiiFile));
$baseYiiFolder = LUYA_YII_VENDOR . DIRECTORY_SEPARATOR;
$luyaYiiFile = $this->getCoreBasePath() . DIRECTORY_SEPARATOR . 'Yii.php';
if (file_exists($luyaYiiFile)) {
require_once($baseYiiFolder . 'BaseYii.php');
require_once($luyaYiiFile);
} else {
require_once($baseYiiFolder . 'Yii.php');
}
Yii::setAlias('@luya', $this->getCoreBasePath());
return true;
}
throw new Exception("YiiBase file does not exits '".$this->_baseYiiFile."'.");
} | php | private function includeYii()
{
if (file_exists($this->_baseYiiFile)) {
defined('LUYA_YII_VENDOR') ?: define('LUYA_YII_VENDOR', dirname($this->_baseYiiFile));
$baseYiiFolder = LUYA_YII_VENDOR . DIRECTORY_SEPARATOR;
$luyaYiiFile = $this->getCoreBasePath() . DIRECTORY_SEPARATOR . 'Yii.php';
if (file_exists($luyaYiiFile)) {
require_once($baseYiiFolder . 'BaseYii.php');
require_once($luyaYiiFile);
} else {
require_once($baseYiiFolder . 'Yii.php');
}
Yii::setAlias('@luya', $this->getCoreBasePath());
return true;
}
throw new Exception("YiiBase file does not exits '".$this->_baseYiiFile."'.");
} | [
"private",
"function",
"includeYii",
"(",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"_baseYiiFile",
")",
")",
"{",
"defined",
"(",
"'LUYA_YII_VENDOR'",
")",
"?",
":",
"define",
"(",
"'LUYA_YII_VENDOR'",
",",
"dirname",
"(",
"$",
"this",
"->",
"_baseYiiFile",
")",
")",
";",
"$",
"baseYiiFolder",
"=",
"LUYA_YII_VENDOR",
".",
"DIRECTORY_SEPARATOR",
";",
"$",
"luyaYiiFile",
"=",
"$",
"this",
"->",
"getCoreBasePath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'Yii.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"luyaYiiFile",
")",
")",
"{",
"require_once",
"(",
"$",
"baseYiiFolder",
".",
"'BaseYii.php'",
")",
";",
"require_once",
"(",
"$",
"luyaYiiFile",
")",
";",
"}",
"else",
"{",
"require_once",
"(",
"$",
"baseYiiFolder",
".",
"'Yii.php'",
")",
";",
"}",
"Yii",
"::",
"setAlias",
"(",
"'@luya'",
",",
"$",
"this",
"->",
"getCoreBasePath",
"(",
")",
")",
";",
"return",
"true",
";",
"}",
"throw",
"new",
"Exception",
"(",
"\"YiiBase file does not exits '\"",
".",
"$",
"this",
"->",
"_baseYiiFile",
".",
"\"'.\"",
")",
";",
"}"
] | Helper method to check whether the provided Yii Base file exists, if yes include and
return the file.
@return bool Return value based on require_once command.
@throws Exception Throws Exception if the YiiBase file does not exists. | [
"Helper",
"method",
"to",
"check",
"whether",
"the",
"provided",
"Yii",
"Base",
"file",
"exists",
"if",
"yes",
"include",
"and",
"return",
"the",
"file",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/base/Boot.php#L288-L309 | train |
luyadev/luya | core/base/Widget.php | Widget.getViewPath | public function getViewPath()
{
if (!$this->useAppViewPath) {
return parent::getViewPath();
}
// get reflection
$class = new ReflectionClass($this);
// get path with alias
return '@app/views/widgets/' . Inflector::camel2id($class->getShortName());
} | php | public function getViewPath()
{
if (!$this->useAppViewPath) {
return parent::getViewPath();
}
// get reflection
$class = new ReflectionClass($this);
// get path with alias
return '@app/views/widgets/' . Inflector::camel2id($class->getShortName());
} | [
"public",
"function",
"getViewPath",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"useAppViewPath",
")",
"{",
"return",
"parent",
"::",
"getViewPath",
"(",
")",
";",
"}",
"// get reflection",
"$",
"class",
"=",
"new",
"ReflectionClass",
"(",
"$",
"this",
")",
";",
"// get path with alias",
"return",
"'@app/views/widgets/'",
".",
"Inflector",
"::",
"camel2id",
"(",
"$",
"class",
"->",
"getShortName",
"(",
")",
")",
";",
"}"
] | Find view paths in application folder.
@inheritDoc
@see \yii\base\Widget::getViewPath()
@return string | [
"Find",
"view",
"paths",
"in",
"application",
"folder",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/base/Widget.php#L33-L43 | train |
luyadev/luya | core/traits/NextPrevModel.php | NextPrevModel.getPrev | public function getPrev()
{
return self::find()->where(['<', 'id', $this->id])->orderBy(['id' => SORT_DESC])->limit(1)->one();
} | php | public function getPrev()
{
return self::find()->where(['<', 'id', $this->id])->orderBy(['id' => SORT_DESC])->limit(1)->one();
} | [
"public",
"function",
"getPrev",
"(",
")",
"{",
"return",
"self",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'<'",
",",
"'id'",
",",
"$",
"this",
"->",
"id",
"]",
")",
"->",
"orderBy",
"(",
"[",
"'id'",
"=>",
"SORT_DESC",
"]",
")",
"->",
"limit",
"(",
"1",
")",
"->",
"one",
"(",
")",
";",
"}"
] | Get the previous record of a current id
@return ActiveQuery | [
"Get",
"the",
"previous",
"record",
"of",
"a",
"current",
"id"
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/traits/NextPrevModel.php#L31-L34 | train |
luyadev/luya | core/traits/ApplicationTrait.php | ApplicationTrait.init | public function init()
{
parent::init();
// add trace info
Yii::trace('initialize LUYA Application', __METHOD__);
$this->setLocale($this->language);
} | php | public function init()
{
parent::init();
// add trace info
Yii::trace('initialize LUYA Application', __METHOD__);
$this->setLocale($this->language);
} | [
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"// add trace info",
"Yii",
"::",
"trace",
"(",
"'initialize LUYA Application'",
",",
"__METHOD__",
")",
";",
"$",
"this",
"->",
"setLocale",
"(",
"$",
"this",
"->",
"language",
")",
";",
"}"
] | Add trace info to luya application trait | [
"Add",
"trace",
"info",
"to",
"luya",
"application",
"trait"
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/traits/ApplicationTrait.php#L96-L104 | train |
luyadev/luya | core/traits/ApplicationTrait.php | ApplicationTrait.getPackageInstaller | public function getPackageInstaller()
{
$file = Yii::getAlias('@vendor/luyadev/installer.php');
$data = is_file($file) ? include $file : [];
return new PackageInstaller($data);
} | php | public function getPackageInstaller()
{
$file = Yii::getAlias('@vendor/luyadev/installer.php');
$data = is_file($file) ? include $file : [];
return new PackageInstaller($data);
} | [
"public",
"function",
"getPackageInstaller",
"(",
")",
"{",
"$",
"file",
"=",
"Yii",
"::",
"getAlias",
"(",
"'@vendor/luyadev/installer.php'",
")",
";",
"$",
"data",
"=",
"is_file",
"(",
"$",
"file",
")",
"?",
"include",
"$",
"file",
":",
"[",
"]",
";",
"return",
"new",
"PackageInstaller",
"(",
"$",
"data",
")",
";",
"}"
] | Get the package Installer
@return \luya\base\PackageInstaller | [
"Get",
"the",
"package",
"Installer"
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/traits/ApplicationTrait.php#L156-L163 | train |
luyadev/luya | core/traits/ApplicationTrait.php | ApplicationTrait.getApplicationModules | public function getApplicationModules()
{
$modules = [];
foreach ($this->getModules() as $id => $obj) {
if ($obj instanceof Module) {
$modules[$id] = $obj;
}
}
return $modules;
} | php | public function getApplicationModules()
{
$modules = [];
foreach ($this->getModules() as $id => $obj) {
if ($obj instanceof Module) {
$modules[$id] = $obj;
}
}
return $modules;
} | [
"public",
"function",
"getApplicationModules",
"(",
")",
"{",
"$",
"modules",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getModules",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"obj",
")",
"{",
"if",
"(",
"$",
"obj",
"instanceof",
"Module",
")",
"{",
"$",
"modules",
"[",
"$",
"id",
"]",
"=",
"$",
"obj",
";",
"}",
"}",
"return",
"$",
"modules",
";",
"}"
] | Get an array with all modules which are an instance of the `luya\base\Module`.
@return \luya\base\Module | [
"Get",
"an",
"array",
"with",
"all",
"modules",
"which",
"are",
"an",
"instance",
"of",
"the",
"luya",
"\\",
"base",
"\\",
"Module",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/traits/ApplicationTrait.php#L211-L222 | train |
luyadev/luya | core/traits/ApplicationTrait.php | ApplicationTrait.getFrontendModules | public function getFrontendModules()
{
$modules = [];
foreach ($this->getModules() as $id => $obj) {
if ($obj instanceof Module && !$obj instanceof AdminModuleInterface && !$obj instanceof CoreModuleInterface) {
$modules[$id] = $obj;
}
}
return $modules;
} | php | public function getFrontendModules()
{
$modules = [];
foreach ($this->getModules() as $id => $obj) {
if ($obj instanceof Module && !$obj instanceof AdminModuleInterface && !$obj instanceof CoreModuleInterface) {
$modules[$id] = $obj;
}
}
return $modules;
} | [
"public",
"function",
"getFrontendModules",
"(",
")",
"{",
"$",
"modules",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getModules",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"obj",
")",
"{",
"if",
"(",
"$",
"obj",
"instanceof",
"Module",
"&&",
"!",
"$",
"obj",
"instanceof",
"AdminModuleInterface",
"&&",
"!",
"$",
"obj",
"instanceof",
"CoreModuleInterface",
")",
"{",
"$",
"modules",
"[",
"$",
"id",
"]",
"=",
"$",
"obj",
";",
"}",
"}",
"return",
"$",
"modules",
";",
"}"
] | Return a list with all registered frontend modules except 'luya' and 'cms'. This is needed in the module block.
@return \luya\base\Module | [
"Return",
"a",
"list",
"with",
"all",
"registered",
"frontend",
"modules",
"except",
"luya",
"and",
"cms",
".",
"This",
"is",
"needed",
"in",
"the",
"module",
"block",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/traits/ApplicationTrait.php#L229-L240 | train |
luyadev/luya | core/traits/ApplicationTrait.php | ApplicationTrait.getAdminModules | public function getAdminModules()
{
$modules = [];
foreach ($this->getModules() as $id => $obj) {
if ($obj instanceof Module && $obj instanceof AdminModuleInterface) {
$modules[$id] = $obj;
}
}
return $modules;
} | php | public function getAdminModules()
{
$modules = [];
foreach ($this->getModules() as $id => $obj) {
if ($obj instanceof Module && $obj instanceof AdminModuleInterface) {
$modules[$id] = $obj;
}
}
return $modules;
} | [
"public",
"function",
"getAdminModules",
"(",
")",
"{",
"$",
"modules",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getModules",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"obj",
")",
"{",
"if",
"(",
"$",
"obj",
"instanceof",
"Module",
"&&",
"$",
"obj",
"instanceof",
"AdminModuleInterface",
")",
"{",
"$",
"modules",
"[",
"$",
"id",
"]",
"=",
"$",
"obj",
";",
"}",
"}",
"return",
"$",
"modules",
";",
"}"
] | Return all Admin Module Interface implementing modules.
@return \luya\base\AdminModuleInterface | [
"Return",
"all",
"Admin",
"Module",
"Interface",
"implementing",
"modules",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/traits/ApplicationTrait.php#L247-L258 | train |
luyadev/luya | core/web/Element.php | Element.init | public function init()
{
$path = Yii::getAlias($this->configFile);
if (file_exists($path)) {
$config = (include($path));
foreach ($config as $name => $closure) {
if (is_array($closure)) {
$this->addElement($name, $closure[0], $closure[1]);
} else {
$this->addElement($name, $closure);
}
}
}
} | php | public function init()
{
$path = Yii::getAlias($this->configFile);
if (file_exists($path)) {
$config = (include($path));
foreach ($config as $name => $closure) {
if (is_array($closure)) {
$this->addElement($name, $closure[0], $closure[1]);
} else {
$this->addElement($name, $closure);
}
}
}
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"path",
"=",
"Yii",
"::",
"getAlias",
"(",
"$",
"this",
"->",
"configFile",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"config",
"=",
"(",
"include",
"(",
"$",
"path",
")",
")",
";",
"foreach",
"(",
"$",
"config",
"as",
"$",
"name",
"=>",
"$",
"closure",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"closure",
")",
")",
"{",
"$",
"this",
"->",
"addElement",
"(",
"$",
"name",
",",
"$",
"closure",
"[",
"0",
"]",
",",
"$",
"closure",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addElement",
"(",
"$",
"name",
",",
"$",
"closure",
")",
";",
"}",
"}",
"}",
"}"
] | Yii intializer, is loading the default elements.php if existing. | [
"Yii",
"intializer",
"is",
"loading",
"the",
"default",
"elements",
".",
"php",
"if",
"existing",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/Element.php#L96-L109 | train |
luyadev/luya | core/web/Element.php | Element.addElement | public function addElement($name, $closure, $mockedArgs = [])
{
$this->_elements[$name] = $closure;
$this->mockArgs($name, $mockedArgs);
} | php | public function addElement($name, $closure, $mockedArgs = [])
{
$this->_elements[$name] = $closure;
$this->mockArgs($name, $mockedArgs);
} | [
"public",
"function",
"addElement",
"(",
"$",
"name",
",",
"$",
"closure",
",",
"$",
"mockedArgs",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"_elements",
"[",
"$",
"name",
"]",
"=",
"$",
"closure",
";",
"$",
"this",
"->",
"mockArgs",
"(",
"$",
"name",
",",
"$",
"mockedArgs",
")",
";",
"}"
] | Add an element with a closure to the elements array.
@param string $name The identifier of the element where the close is binde to.
@param callable $closure The closure function to registered, for example:
```php
function() {
return 'foobar';
}
```
@param array $mockedArgs An array with key value pairing for the argument in order to render them for the styleguide. | [
"Add",
"an",
"element",
"with",
"a",
"closure",
"to",
"the",
"elements",
"array",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/Element.php#L142-L147 | train |
luyadev/luya | core/web/Element.php | Element.getElement | public function getElement($name, array $params = [])
{
if (!array_key_exists($name, $this->_elements)) {
throw new Exception("The requested element '$name' does not exist in the list. You may register the element first with `addElement(name, closure)`.");
}
return call_user_func_array($this->_elements[$name], $params);
} | php | public function getElement($name, array $params = [])
{
if (!array_key_exists($name, $this->_elements)) {
throw new Exception("The requested element '$name' does not exist in the list. You may register the element first with `addElement(name, closure)`.");
}
return call_user_func_array($this->_elements[$name], $params);
} | [
"public",
"function",
"getElement",
"(",
"$",
"name",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"_elements",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"The requested element '$name' does not exist in the list. You may register the element first with `addElement(name, closure)`.\"",
")",
";",
"}",
"return",
"call_user_func_array",
"(",
"$",
"this",
"->",
"_elements",
"[",
"$",
"name",
"]",
",",
"$",
"params",
")",
";",
"}"
] | Renders the closure for the given name and returns the content.
@param string $name The name of the elemente to execute.
@param array $params The params to pass to the closure methode.
@return mixed The return value of the executed closure function.
@throws Exception | [
"Renders",
"the",
"closure",
"for",
"the",
"given",
"name",
"and",
"returns",
"the",
"content",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/Element.php#L188-L195 | train |
luyadev/luya | core/web/Element.php | Element.getMockedArgValue | public function getMockedArgValue($elementName, $argName)
{
if (isset($this->_mockedArguments[$elementName]) && isset($this->_mockedArguments[$elementName][$argName])) {
$response = $this->_mockedArguments[$elementName][$argName];
if (is_callable($response)) {
$response = call_user_func($response);
}
return $response;
}
return false;
} | php | public function getMockedArgValue($elementName, $argName)
{
if (isset($this->_mockedArguments[$elementName]) && isset($this->_mockedArguments[$elementName][$argName])) {
$response = $this->_mockedArguments[$elementName][$argName];
if (is_callable($response)) {
$response = call_user_func($response);
}
return $response;
}
return false;
} | [
"public",
"function",
"getMockedArgValue",
"(",
"$",
"elementName",
",",
"$",
"argName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_mockedArguments",
"[",
"$",
"elementName",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"_mockedArguments",
"[",
"$",
"elementName",
"]",
"[",
"$",
"argName",
"]",
")",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"_mockedArguments",
"[",
"$",
"elementName",
"]",
"[",
"$",
"argName",
"]",
";",
"if",
"(",
"is_callable",
"(",
"$",
"response",
")",
")",
"{",
"$",
"response",
"=",
"call_user_func",
"(",
"$",
"response",
")",
";",
"}",
"return",
"$",
"response",
";",
"}",
"return",
"false",
";",
"}"
] | Find the mocked value for an element argument.
@param string $elementName The name of the element.
@param string $argName The name of the argument.
@return mixed|boolean Whether the mocked argument value exists returns the value otherwise false. | [
"Find",
"the",
"mocked",
"value",
"for",
"an",
"element",
"argument",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/Element.php#L232-L243 | train |
luyadev/luya | core/web/Element.php | Element.render | public function render($file, array $args = [])
{
$view = new View();
$view->autoRegisterCsrf = false;
return $view->renderPhpFile(rtrim($this->getFolder(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . FileHelper::ensureExtension($file, 'php'), $args);
} | php | public function render($file, array $args = [])
{
$view = new View();
$view->autoRegisterCsrf = false;
return $view->renderPhpFile(rtrim($this->getFolder(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . FileHelper::ensureExtension($file, 'php'), $args);
} | [
"public",
"function",
"render",
"(",
"$",
"file",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"view",
"=",
"new",
"View",
"(",
")",
";",
"$",
"view",
"->",
"autoRegisterCsrf",
"=",
"false",
";",
"return",
"$",
"view",
"->",
"renderPhpFile",
"(",
"rtrim",
"(",
"$",
"this",
"->",
"getFolder",
"(",
")",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"FileHelper",
"::",
"ensureExtension",
"(",
"$",
"file",
",",
"'php'",
")",
",",
"$",
"args",
")",
";",
"}"
] | Method to render twig files with theyr specific arguments, can be used inside the element closure depending
on where the closure was registered. Otherwhise the use of the element variable must be provided.
@param string $file The name of the file to render.
@param array $args The parameters to pass in the render file.
@return string The render value of the view file. | [
"Method",
"to",
"render",
"twig",
"files",
"with",
"theyr",
"specific",
"arguments",
"can",
"be",
"used",
"inside",
"the",
"element",
"closure",
"depending",
"on",
"where",
"the",
"closure",
"was",
"registered",
".",
"Otherwhise",
"the",
"use",
"of",
"the",
"element",
"variable",
"must",
"be",
"provided",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/Element.php#L254-L259 | train |
luyadev/luya | core/web/jsonld/BaseThing.php | BaseThing.resolveGetterMethods | public function resolveGetterMethods()
{
$resolved = [];
$methods = get_class_methods($this);
if (!$methods) {
return [];
}
foreach ($methods as $method) {
if (StringHelper::startsWith($method, 'get', true)) {
$resolved[] = lcfirst(StringHelper::replaceFirst('get', '', $method));
}
}
asort($resolved);
return $resolved;
} | php | public function resolveGetterMethods()
{
$resolved = [];
$methods = get_class_methods($this);
if (!$methods) {
return [];
}
foreach ($methods as $method) {
if (StringHelper::startsWith($method, 'get', true)) {
$resolved[] = lcfirst(StringHelper::replaceFirst('get', '', $method));
}
}
asort($resolved);
return $resolved;
} | [
"public",
"function",
"resolveGetterMethods",
"(",
")",
"{",
"$",
"resolved",
"=",
"[",
"]",
";",
"$",
"methods",
"=",
"get_class_methods",
"(",
"$",
"this",
")",
";",
"if",
"(",
"!",
"$",
"methods",
")",
"{",
"return",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"StringHelper",
"::",
"startsWith",
"(",
"$",
"method",
",",
"'get'",
",",
"true",
")",
")",
"{",
"$",
"resolved",
"[",
"]",
"=",
"lcfirst",
"(",
"StringHelper",
"::",
"replaceFirst",
"(",
"'get'",
",",
"''",
",",
"$",
"method",
")",
")",
";",
"}",
"}",
"asort",
"(",
"$",
"resolved",
")",
";",
"return",
"$",
"resolved",
";",
"}"
] | Find all getter methods.
@return array | [
"Find",
"all",
"getter",
"methods",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/jsonld/BaseThing.php#L39-L57 | train |
luyadev/luya | core/web/jsonld/BaseThing.php | BaseThing.removeEmptyValues | private function removeEmptyValues(array $haystack)
{
foreach ($haystack as $key => $value) {
if (is_array($value)) {
$haystack[$key] = $this->removeEmptyValues($value);
}
// remove empty values value value is NULL or an empty string ''
if ($value === null || $value == '') {
unset($haystack[$key]);
}
}
return $haystack;
} | php | private function removeEmptyValues(array $haystack)
{
foreach ($haystack as $key => $value) {
if (is_array($value)) {
$haystack[$key] = $this->removeEmptyValues($value);
}
// remove empty values value value is NULL or an empty string ''
if ($value === null || $value == '') {
unset($haystack[$key]);
}
}
return $haystack;
} | [
"private",
"function",
"removeEmptyValues",
"(",
"array",
"$",
"haystack",
")",
"{",
"foreach",
"(",
"$",
"haystack",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"haystack",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"removeEmptyValues",
"(",
"$",
"value",
")",
";",
"}",
"// remove empty values value value is NULL or an empty string ''",
"if",
"(",
"$",
"value",
"===",
"null",
"||",
"$",
"value",
"==",
"''",
")",
"{",
"unset",
"(",
"$",
"haystack",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"haystack",
";",
"}"
] | Cleanup array from null values.
@param array $haystack
@return array | [
"Cleanup",
"array",
"from",
"null",
"values",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/web/jsonld/BaseThing.php#L87-L100 | train |
luyadev/luya | core/behaviors/TimestampBehavior.php | TimestampBehavior.beforeInsert | public function beforeInsert($event)
{
foreach ($this->insert as $field) {
$event->sender->$field = time();
}
} | php | public function beforeInsert($event)
{
foreach ($this->insert as $field) {
$event->sender->$field = time();
}
} | [
"public",
"function",
"beforeInsert",
"(",
"$",
"event",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"insert",
"as",
"$",
"field",
")",
"{",
"$",
"event",
"->",
"sender",
"->",
"$",
"field",
"=",
"time",
"(",
")",
";",
"}",
"}"
] | Insert the timestamp for all provided fields.
@param \yii\base\Event $event Event object from Active Record. | [
"Insert",
"the",
"timestamp",
"for",
"all",
"provided",
"fields",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/behaviors/TimestampBehavior.php#L54-L59 | train |
luyadev/luya | core/behaviors/TimestampBehavior.php | TimestampBehavior.beforeUpdate | public function beforeUpdate($event)
{
foreach ($this->update as $field) {
$event->sender->$field = time();
}
} | php | public function beforeUpdate($event)
{
foreach ($this->update as $field) {
$event->sender->$field = time();
}
} | [
"public",
"function",
"beforeUpdate",
"(",
"$",
"event",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"update",
"as",
"$",
"field",
")",
"{",
"$",
"event",
"->",
"sender",
"->",
"$",
"field",
"=",
"time",
"(",
")",
";",
"}",
"}"
] | Update the timestamp for all provided fields.
@param \yii\base\Event $event Event object from Active Record. | [
"Update",
"the",
"timestamp",
"for",
"all",
"provided",
"fields",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/behaviors/TimestampBehavior.php#L66-L71 | train |
luyadev/luya | core/helpers/ImportHelper.php | ImportHelper.csv | public static function csv($filename, array $options = [])
{
$filename = Yii::getAlias($filename);
// check if a given file name is provided or a csv based on the content
if (FileHelper::getFileInfo($filename)->extension) {
$resource = fopen($filename, 'r');
} else {
$resource = fopen('php://memory', 'rw');
fwrite($resource, $filename);
rewind($resource);
}
$data = [];
while (($row = fgetcsv($resource, 0, ArrayHelper::getValue($options, 'delimiter', ','), ArrayHelper::getValue($options, 'enclosure', '"'))) !== false) {
$data[] = $row;
}
fclose($resource);
// check whether only an amount of fields should be parsed into the final array
$fields = ArrayHelper::getValue($options, 'fields', false);
if ($fields && is_array($fields)) {
$filteredData = [];
foreach ($fields as $fieldColumn) {
if (!is_numeric($fieldColumn)) {
$fieldColumn = array_search($fieldColumn, $data[0]);
}
foreach ($data as $key => $rowValue) {
if (array_key_exists($fieldColumn, $rowValue)) {
$filteredData[$key][] = $rowValue[$fieldColumn];
}
}
}
$data = $filteredData;
unset($filteredData);
}
// if the option to remove a header is provide. remove the first key and reset and array keys
if (ArrayHelper::getValue($options, 'removeHeader', false)) {
unset($data[0]);
$data = array_values($data);
}
return $data;
} | php | public static function csv($filename, array $options = [])
{
$filename = Yii::getAlias($filename);
// check if a given file name is provided or a csv based on the content
if (FileHelper::getFileInfo($filename)->extension) {
$resource = fopen($filename, 'r');
} else {
$resource = fopen('php://memory', 'rw');
fwrite($resource, $filename);
rewind($resource);
}
$data = [];
while (($row = fgetcsv($resource, 0, ArrayHelper::getValue($options, 'delimiter', ','), ArrayHelper::getValue($options, 'enclosure', '"'))) !== false) {
$data[] = $row;
}
fclose($resource);
// check whether only an amount of fields should be parsed into the final array
$fields = ArrayHelper::getValue($options, 'fields', false);
if ($fields && is_array($fields)) {
$filteredData = [];
foreach ($fields as $fieldColumn) {
if (!is_numeric($fieldColumn)) {
$fieldColumn = array_search($fieldColumn, $data[0]);
}
foreach ($data as $key => $rowValue) {
if (array_key_exists($fieldColumn, $rowValue)) {
$filteredData[$key][] = $rowValue[$fieldColumn];
}
}
}
$data = $filteredData;
unset($filteredData);
}
// if the option to remove a header is provide. remove the first key and reset and array keys
if (ArrayHelper::getValue($options, 'removeHeader', false)) {
unset($data[0]);
$data = array_values($data);
}
return $data;
} | [
"public",
"static",
"function",
"csv",
"(",
"$",
"filename",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"filename",
"=",
"Yii",
"::",
"getAlias",
"(",
"$",
"filename",
")",
";",
"// check if a given file name is provided or a csv based on the content",
"if",
"(",
"FileHelper",
"::",
"getFileInfo",
"(",
"$",
"filename",
")",
"->",
"extension",
")",
"{",
"$",
"resource",
"=",
"fopen",
"(",
"$",
"filename",
",",
"'r'",
")",
";",
"}",
"else",
"{",
"$",
"resource",
"=",
"fopen",
"(",
"'php://memory'",
",",
"'rw'",
")",
";",
"fwrite",
"(",
"$",
"resource",
",",
"$",
"filename",
")",
";",
"rewind",
"(",
"$",
"resource",
")",
";",
"}",
"$",
"data",
"=",
"[",
"]",
";",
"while",
"(",
"(",
"$",
"row",
"=",
"fgetcsv",
"(",
"$",
"resource",
",",
"0",
",",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"options",
",",
"'delimiter'",
",",
"','",
")",
",",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"options",
",",
"'enclosure'",
",",
"'\"'",
")",
")",
")",
"!==",
"false",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"fclose",
"(",
"$",
"resource",
")",
";",
"// check whether only an amount of fields should be parsed into the final array",
"$",
"fields",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"options",
",",
"'fields'",
",",
"false",
")",
";",
"if",
"(",
"$",
"fields",
"&&",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"filteredData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"fieldColumn",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"fieldColumn",
")",
")",
"{",
"$",
"fieldColumn",
"=",
"array_search",
"(",
"$",
"fieldColumn",
",",
"$",
"data",
"[",
"0",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"rowValue",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"fieldColumn",
",",
"$",
"rowValue",
")",
")",
"{",
"$",
"filteredData",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"rowValue",
"[",
"$",
"fieldColumn",
"]",
";",
"}",
"}",
"}",
"$",
"data",
"=",
"$",
"filteredData",
";",
"unset",
"(",
"$",
"filteredData",
")",
";",
"}",
"// if the option to remove a header is provide. remove the first key and reset and array keys",
"if",
"(",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"options",
",",
"'removeHeader'",
",",
"false",
")",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"0",
"]",
")",
";",
"$",
"data",
"=",
"array_values",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Import a CSV from a string or filename and return array.
The filename can be either a resource from fopen() or a string containing the csv data. Filenames will be wrapped trough {{Yii::getAlias()}} method.
@param string $filename Can be either a filename which is parsed by {{luya\helpers\FileHelper::getFileContent()}} or a string with the contained csv data.
@param array $options Provide options to the csv
+ removeHeader: boolean, Whether the import csv contains a header in the first row to skip or not. Default value is false.
+ delimiter: string, The delimiter which is used to explode the columns. Default value is `,`.
+ enclosure: string, The encloser which is used betweend the columns. Default value is `"`.
+ fields: array, An array with fielnames (based on the array header if any, or position) which should be parsed into the final export.
```php
'fields' => ['firstname', 'lastname'] // will only parse those fields based on table header (row 0)
'fields' => [0,1,3] // will only parse fields by those positions if no table header is present. Positions starts at 0
```
@return Returns an array with the csv data. | [
"Import",
"a",
"CSV",
"from",
"a",
"string",
"or",
"filename",
"and",
"return",
"array",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/helpers/ImportHelper.php#L32-L76 | train |
luyadev/luya | core/base/BaseBootstrap.php | BaseBootstrap.extractModules | public function extractModules($app)
{
if ($this->_modules === null) {
foreach ($app->getModules() as $id => $obj) {
// create module object
$moduleObject = Yii::$app->getModule($id);
// see if the module is a luya base module, otherwise ignore
if ($moduleObject instanceof \luya\base\Module) {
$this->_modules[$id] = $moduleObject;
}
}
// when no luya modules are registered an empty array will be returned.
if ($this->_modules === null) {
$this->_modules = [];
}
}
} | php | public function extractModules($app)
{
if ($this->_modules === null) {
foreach ($app->getModules() as $id => $obj) {
// create module object
$moduleObject = Yii::$app->getModule($id);
// see if the module is a luya base module, otherwise ignore
if ($moduleObject instanceof \luya\base\Module) {
$this->_modules[$id] = $moduleObject;
}
}
// when no luya modules are registered an empty array will be returned.
if ($this->_modules === null) {
$this->_modules = [];
}
}
} | [
"public",
"function",
"extractModules",
"(",
"$",
"app",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_modules",
"===",
"null",
")",
"{",
"foreach",
"(",
"$",
"app",
"->",
"getModules",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"obj",
")",
"{",
"// create module object",
"$",
"moduleObject",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getModule",
"(",
"$",
"id",
")",
";",
"// see if the module is a luya base module, otherwise ignore",
"if",
"(",
"$",
"moduleObject",
"instanceof",
"\\",
"luya",
"\\",
"base",
"\\",
"Module",
")",
"{",
"$",
"this",
"->",
"_modules",
"[",
"$",
"id",
"]",
"=",
"$",
"moduleObject",
";",
"}",
"}",
"// when no luya modules are registered an empty array will be returned.",
"if",
"(",
"$",
"this",
"->",
"_modules",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_modules",
"=",
"[",
"]",
";",
"}",
"}",
"}"
] | Extract and load all modules from the Application-Object.
@param object $app Luya Application `luya\base\Application`. | [
"Extract",
"and",
"load",
"all",
"modules",
"from",
"the",
"Application",
"-",
"Object",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/base/BaseBootstrap.php#L55-L71 | train |
luyadev/luya | core/console/commands/ImportController.php | ImportController.addToDirectory | protected function addToDirectory($path, $folderName, $ns, $module)
{
if (file_exists($path)) {
$this->_dirs[$folderName][] = [
'ns' => $ns,
'module' => $module,
'folderPath' => $path.DIRECTORY_SEPARATOR,
'files' => $this->scanDirectoryFiles($path, $ns, $module),
];
}
} | php | protected function addToDirectory($path, $folderName, $ns, $module)
{
if (file_exists($path)) {
$this->_dirs[$folderName][] = [
'ns' => $ns,
'module' => $module,
'folderPath' => $path.DIRECTORY_SEPARATOR,
'files' => $this->scanDirectoryFiles($path, $ns, $module),
];
}
} | [
"protected",
"function",
"addToDirectory",
"(",
"$",
"path",
",",
"$",
"folderName",
",",
"$",
"ns",
",",
"$",
"module",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"_dirs",
"[",
"$",
"folderName",
"]",
"[",
"]",
"=",
"[",
"'ns'",
"=>",
"$",
"ns",
",",
"'module'",
"=>",
"$",
"module",
",",
"'folderPath'",
"=>",
"$",
"path",
".",
"DIRECTORY_SEPARATOR",
",",
"'files'",
"=>",
"$",
"this",
"->",
"scanDirectoryFiles",
"(",
"$",
"path",
",",
"$",
"ns",
",",
"$",
"module",
")",
",",
"]",
";",
"}",
"}"
] | Add a given directory to the list of folders.
@param string $path
@param string $folderName
@param string $ns
@param string $module The name/id of the module. | [
"Add",
"a",
"given",
"directory",
"to",
"the",
"list",
"of",
"folders",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/console/commands/ImportController.php#L62-L72 | train |
luyadev/luya | core/console/commands/ImportController.php | ImportController.scanDirectoryFiles | protected function scanDirectoryFiles($path, $ns, $module)
{
$files = [];
foreach (scandir($path) as $file) {
if (substr($file, 0, 1) !== '.') {
$files[] = [
'file' => $file,
'module' => $module,
'ns' => $ns.'\\'.pathinfo($file, PATHINFO_FILENAME),
];
}
}
return $files;
} | php | protected function scanDirectoryFiles($path, $ns, $module)
{
$files = [];
foreach (scandir($path) as $file) {
if (substr($file, 0, 1) !== '.') {
$files[] = [
'file' => $file,
'module' => $module,
'ns' => $ns.'\\'.pathinfo($file, PATHINFO_FILENAME),
];
}
}
return $files;
} | [
"protected",
"function",
"scanDirectoryFiles",
"(",
"$",
"path",
",",
"$",
"ns",
",",
"$",
"module",
")",
"{",
"$",
"files",
"=",
"[",
"]",
";",
"foreach",
"(",
"scandir",
"(",
"$",
"path",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"file",
",",
"0",
",",
"1",
")",
"!==",
"'.'",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"[",
"'file'",
"=>",
"$",
"file",
",",
"'module'",
"=>",
"$",
"module",
",",
"'ns'",
"=>",
"$",
"ns",
".",
"'\\\\'",
".",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_FILENAME",
")",
",",
"]",
";",
"}",
"}",
"return",
"$",
"files",
";",
"}"
] | Scan a given directory path and return an array with namespace, module and file.
@param string $path
@param string $ns
@param string $module The name/id of the module.
@return array | [
"Scan",
"a",
"given",
"directory",
"path",
"and",
"return",
"an",
"array",
"with",
"namespace",
"module",
"and",
"file",
"."
] | 5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e | https://github.com/luyadev/luya/blob/5b1779ecc68d0374477f2dd7605de4a7d9dd5b5e/core/console/commands/ImportController.php#L82-L96 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.