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
StydeNet/html
src/Access/BasicAccessHandler.php
BasicAccessHandler.checkRole
protected function checkRole($allowed) { if (!is_array($allowed)) { $allowed = explode('|', $allowed); } return in_array($this->getCurrentRole(), $allowed); }
php
protected function checkRole($allowed) { if (!is_array($allowed)) { $allowed = explode('|', $allowed); } return in_array($this->getCurrentRole(), $allowed); }
[ "protected", "function", "checkRole", "(", "$", "allowed", ")", "{", "if", "(", "!", "is_array", "(", "$", "allowed", ")", ")", "{", "$", "allowed", "=", "explode", "(", "'|'", ",", "$", "allowed", ")", ";", "}", "return", "in_array", "(", "$", "th...
Check if a user has at least one of the allowed roles. @param $allowed @return bool
[ "Check", "if", "a", "user", "has", "at", "least", "one", "of", "the", "allowed", "roles", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Access/BasicAccessHandler.php#L111-L118
train
StydeNet/html
src/Alert/Message.php
Message.details
public function details($details, $parameters = array()) { $this->message['details'] = $this->container->translate($details, $parameters); return $this; }
php
public function details($details, $parameters = array()) { $this->message['details'] = $this->container->translate($details, $parameters); return $this; }
[ "public", "function", "details", "(", "$", "details", ",", "$", "parameters", "=", "array", "(", ")", ")", "{", "$", "this", "->", "message", "[", "'details'", "]", "=", "$", "this", "->", "container", "->", "translate", "(", "$", "details", ",", "$"...
Add details to the alert message @param $details @return \Styde\Html\Alert\Message $this
[ "Add", "details", "to", "the", "alert", "message" ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Alert/Message.php#L67-L71
train
StydeNet/html
src/Alert/Message.php
Message.view
public function view($template, $data = array()) { return $this->html($this->container->view($template, $data)); }
php
public function view($template, $data = array()) { return $this->html($this->container->view($template, $data)); }
[ "public", "function", "view", "(", "$", "template", ",", "$", "data", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "html", "(", "$", "this", "->", "container", "->", "view", "(", "$", "template", ",", "$", "data", ")", ")", ";",...
Add an additional view partial to the alert message. @param string $template @param array $data @return \Styde\Html\Alert\Message $this
[ "Add", "an", "additional", "view", "partial", "to", "the", "alert", "message", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Alert/Message.php#L112-L115
train
StydeNet/html
src/HtmlBuilder.php
HtmlBuilder.classes
public function classes($classes) { if (! is_array($classes)) { $classes = func_get_args(); } $html = ''; foreach ($classes as $name => $bool) { if (is_int($name)) { $name = $bool; $bool = true; } if ($bool) { $html .= $name.' '; } } if (!empty($html)) { return ' class="'.trim($html).'"'; } return ''; }
php
public function classes($classes) { if (! is_array($classes)) { $classes = func_get_args(); } $html = ''; foreach ($classes as $name => $bool) { if (is_int($name)) { $name = $bool; $bool = true; } if ($bool) { $html .= $name.' '; } } if (!empty($html)) { return ' class="'.trim($html).'"'; } return ''; }
[ "public", "function", "classes", "(", "$", "classes", ")", "{", "if", "(", "!", "is_array", "(", "$", "classes", ")", ")", "{", "$", "classes", "=", "func_get_args", "(", ")", ";", "}", "$", "html", "=", "''", ";", "foreach", "(", "$", "classes", ...
Builds an HTML class attribute dynamically. This method is similar to the ng-class attribute of AngularJS You can specify one or more CSS classes as a key and a condition as a value. If the condition is true the class(es) will be used, otherwise they will be skipped. You can also set the static class(es) (those which we'll always be used) as a value. Example: {!! Html::classes(['home' => true, 'main', 'dont-use-this' => false]) !!} Returns: class="home main". Notice that this function returns an empty space before the class attribute. So you have to do this: <p{!! classes(..) !!}> and not this: <p {{!! classes(..) !!}> If no classes are evaluated as TRUE then this function will return an empty string. @param array|mixed $classes @return string
[ "Builds", "an", "HTML", "class", "attribute", "dynamically", ".", "This", "method", "is", "similar", "to", "the", "ng", "-", "class", "attribute", "of", "AngularJS" ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/HtmlBuilder.php#L38-L62
train
StydeNet/html
src/Theme.php
Theme.render
public function render($custom, $data = array(), $template = null) { if ($custom != null) { return $this->view->make($custom, $data)->render(); } $template = $this->theme.'/'.$template; if ($this->view->exists($this->custom . '/' . $template)) { return $this->view->make($this->custom . '/' . $template, $data)->render(); } return $this->view->make('styde.html::'.$template, $data)->render(); }
php
public function render($custom, $data = array(), $template = null) { if ($custom != null) { return $this->view->make($custom, $data)->render(); } $template = $this->theme.'/'.$template; if ($this->view->exists($this->custom . '/' . $template)) { return $this->view->make($this->custom . '/' . $template, $data)->render(); } return $this->view->make('styde.html::'.$template, $data)->render(); }
[ "public", "function", "render", "(", "$", "custom", ",", "$", "data", "=", "array", "(", ")", ",", "$", "template", "=", "null", ")", "{", "if", "(", "$", "custom", "!=", "null", ")", "{", "return", "$", "this", "->", "view", "->", "make", "(", ...
Renders a custom template or one of the default templates. The default template could be published (into resources/views/themes/) or be located inside the components directory (vendor/styde/html/themes/) @param string $custom @param array $data @param null $template @return string
[ "Renders", "a", "custom", "template", "or", "one", "of", "the", "default", "templates", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Theme.php#L75-L88
train
StydeNet/html
src/FieldBuilder.php
FieldBuilder.url
public function url($name, $value = null, array $attributes = array(), array $extra = array()) { return $this->build('url', $name, $value, $attributes, $extra); }
php
public function url($name, $value = null, array $attributes = array(), array $extra = array()) { return $this->build('url', $name, $value, $attributes, $extra); }
[ "public", "function", "url", "(", "$", "name", ",", "$", "value", "=", "null", ",", "array", "$", "attributes", "=", "array", "(", ")", ",", "array", "$", "extra", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "build", "(", "'url...
Create a URL input field. @param string $name @param string $value @param array $attributes @param array $extra @return string
[ "Create", "a", "URL", "input", "field", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FieldBuilder.php#L233-L236
train
StydeNet/html
src/FieldBuilder.php
FieldBuilder.file
public function file($name, array $attributes = array(), array $extra = array()) { return $this->build('file', $name, null, $attributes, $extra); }
php
public function file($name, array $attributes = array(), array $extra = array()) { return $this->build('file', $name, null, $attributes, $extra); }
[ "public", "function", "file", "(", "$", "name", ",", "array", "$", "attributes", "=", "array", "(", ")", ",", "array", "$", "extra", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "build", "(", "'file'", ",", "$", "name", ",", "nu...
Create a file input field. @param string $name @param array $attributes @param array $extra @return string
[ "Create", "a", "file", "input", "field", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FieldBuilder.php#L247-L250
train
StydeNet/html
src/FieldBuilder.php
FieldBuilder.radios
public function radios($name, $options = array(), $selected = null, array $attributes = array(), array $extra = array()) { return $this->build('radios', $name, $selected, $attributes, $extra, $options); }
php
public function radios($name, $options = array(), $selected = null, array $attributes = array(), array $extra = array()) { return $this->build('radios', $name, $selected, $attributes, $extra, $options); }
[ "public", "function", "radios", "(", "$", "name", ",", "$", "options", "=", "array", "(", ")", ",", "$", "selected", "=", "null", ",", "array", "$", "attributes", "=", "array", "(", ")", ",", "array", "$", "extra", "=", "array", "(", ")", ")", "{...
Create a radios field. @param string $name @param array $options @param string $selected @param array $attributes @param array $extra @return string
[ "Create", "a", "radios", "field", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FieldBuilder.php#L278-L281
train
StydeNet/html
src/FieldBuilder.php
FieldBuilder.selectMultiple
public function selectMultiple($name, $options = array(), $selected = null, array $attributes = array(), array $extra = array()) { $attributes[] = 'multiple'; return $this->doBuild('select', $name, $selected, $attributes, $extra, $options); }
php
public function selectMultiple($name, $options = array(), $selected = null, array $attributes = array(), array $extra = array()) { $attributes[] = 'multiple'; return $this->doBuild('select', $name, $selected, $attributes, $extra, $options); }
[ "public", "function", "selectMultiple", "(", "$", "name", ",", "$", "options", "=", "array", "(", ")", ",", "$", "selected", "=", "null", ",", "array", "$", "attributes", "=", "array", "(", ")", ",", "array", "$", "extra", "=", "array", "(", ")", "...
Create a multiple select field @param $name @param array $options @param array $selected @param array $attributes @param array $extra @return string
[ "Create", "a", "multiple", "select", "field" ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FieldBuilder.php#L319-L323
train
StydeNet/html
src/FieldBuilder.php
FieldBuilder.getOptionsList
protected function getOptionsList($name, $options) { if (empty($options)) { $options = $this->getOptionsFromModel($name); } return $options; }
php
protected function getOptionsList($name, $options) { if (empty($options)) { $options = $this->getOptionsFromModel($name); } return $options; }
[ "protected", "function", "getOptionsList", "(", "$", "name", ",", "$", "options", ")", "{", "if", "(", "empty", "(", "$", "options", ")", ")", "{", "$", "options", "=", "$", "this", "->", "getOptionsFromModel", "(", "$", "name", ")", ";", "}", "retur...
Get the option list for the select box or the group of radios @param string $name @param array $options @return array
[ "Get", "the", "option", "list", "for", "the", "select", "box", "or", "the", "group", "of", "radios" ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FieldBuilder.php#L366-L373
train
StydeNet/html
src/FieldBuilder.php
FieldBuilder.getOptionsFromModel
protected function getOptionsFromModel($name) { $model = $this->form->getModel(); if (is_null($model)) { return array(); } $method = 'get'.Str::studly($name).'Options'; if (method_exists($model, $method)) { return $model->$method(); } return array(); }
php
protected function getOptionsFromModel($name) { $model = $this->form->getModel(); if (is_null($model)) { return array(); } $method = 'get'.Str::studly($name).'Options'; if (method_exists($model, $method)) { return $model->$method(); } return array(); }
[ "protected", "function", "getOptionsFromModel", "(", "$", "name", ")", "{", "$", "model", "=", "$", "this", "->", "form", "->", "getModel", "(", ")", ";", "if", "(", "is_null", "(", "$", "model", ")", ")", "{", "return", "array", "(", ")", ";", "}"...
Attempt to get the option list from the model The model needs to be set and have a method with the following convention: attribute -> get[Attribute]Options, i.e.: user_id -> getUserIdOptions() Otherwise it will return an empty array @param $name @return mixed
[ "Attempt", "to", "get", "the", "option", "list", "from", "the", "model" ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FieldBuilder.php#L389-L404
train
StydeNet/html
src/FieldBuilder.php
FieldBuilder.addEmptyOption
protected function addEmptyOption($name, array $options, array &$attributes) { if (empty($options)) { return []; } // Don't add an empty option if the select is "multiple" if (isset($attributes['multiple']) || in_array('multiple', $attributes)) { return $options; } if (isset($attributes['empty'])) { $text = $attributes['empty']; unset($attributes['empty']); } else { $text = $this->getEmptyOption($name); } if ($text === false) { return $options; } return ['' => $text] + $options; }
php
protected function addEmptyOption($name, array $options, array &$attributes) { if (empty($options)) { return []; } // Don't add an empty option if the select is "multiple" if (isset($attributes['multiple']) || in_array('multiple', $attributes)) { return $options; } if (isset($attributes['empty'])) { $text = $attributes['empty']; unset($attributes['empty']); } else { $text = $this->getEmptyOption($name); } if ($text === false) { return $options; } return ['' => $text] + $options; }
[ "protected", "function", "addEmptyOption", "(", "$", "name", ",", "array", "$", "options", ",", "array", "&", "$", "attributes", ")", "{", "if", "(", "empty", "(", "$", "options", ")", ")", "{", "return", "[", "]", ";", "}", "// Don't add an empty option...
Adds an empty option for select inputs if the option list is not empty. You can pass the empty option's text as the "empty" key in the attribute's array. Or you can set this as a lang's key (see the getEmptyOption method below). @param $name @param array $options @param array $attributes @return array
[ "Adds", "an", "empty", "option", "for", "select", "inputs", "if", "the", "option", "list", "is", "not", "empty", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FieldBuilder.php#L419-L442
train
StydeNet/html
src/FieldBuilder.php
FieldBuilder.getHtmlName
protected function getHtmlName($name) { if (strpos($name, '.')) { $segments = explode('.', $name); return array_shift($segments).'['.implode('][', $segments).']'; } return $name; }
php
protected function getHtmlName($name) { if (strpos($name, '.')) { $segments = explode('.', $name); return array_shift($segments).'['.implode('][', $segments).']'; } return $name; }
[ "protected", "function", "getHtmlName", "(", "$", "name", ")", "{", "if", "(", "strpos", "(", "$", "name", ",", "'.'", ")", ")", "{", "$", "segments", "=", "explode", "(", "'.'", ",", "$", "name", ")", ";", "return", "array_shift", "(", "$", "segme...
Get the HTML name for the input control. You can use dots to specify arrays: product.category.name will be converted to: product[category][name] @param string $name @return string
[ "Get", "the", "HTML", "name", "for", "the", "input", "control", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FieldBuilder.php#L513-L521
train
StydeNet/html
src/FieldBuilder.php
FieldBuilder.getDefaultClasses
protected function getDefaultClasses($type) { if (isset($this->cssClasses[$type])) { return $this->cssClasses[$type]; } if (isset($this->cssClasses['default'])) { return $this->cssClasses['default']; } return ''; }
php
protected function getDefaultClasses($type) { if (isset($this->cssClasses[$type])) { return $this->cssClasses[$type]; } if (isset($this->cssClasses['default'])) { return $this->cssClasses['default']; } return ''; }
[ "protected", "function", "getDefaultClasses", "(", "$", "type", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "cssClasses", "[", "$", "type", "]", ")", ")", "{", "return", "$", "this", "->", "cssClasses", "[", "$", "type", "]", ";", "}", "i...
Get the default HTML classes for a particular type. If the type is not defined it will use the 'default' key in the cssClasses array, otherwise it will return an empty string. @param string $type @return string
[ "Get", "the", "default", "HTML", "classes", "for", "a", "particular", "type", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FieldBuilder.php#L589-L600
train
StydeNet/html
src/FieldBuilder.php
FieldBuilder.getClasses
protected function getClasses($type, array $attributes = [], $errors = null) { $classes = $this->getDefaultClasses($type); if (isset($attributes['class'])) { $classes .= ' '.$attributes['class']; } if ( ! empty($errors)) { $classes .= ' '.(isset($this->cssClasses['error']) ? $this->cssClasses['error'] : 'error'); } return trim($classes); }
php
protected function getClasses($type, array $attributes = [], $errors = null) { $classes = $this->getDefaultClasses($type); if (isset($attributes['class'])) { $classes .= ' '.$attributes['class']; } if ( ! empty($errors)) { $classes .= ' '.(isset($this->cssClasses['error']) ? $this->cssClasses['error'] : 'error'); } return trim($classes); }
[ "protected", "function", "getClasses", "(", "$", "type", ",", "array", "$", "attributes", "=", "[", "]", ",", "$", "errors", "=", "null", ")", "{", "$", "classes", "=", "$", "this", "->", "getDefaultClasses", "(", "$", "type", ")", ";", "if", "(", ...
Get the HTML classes for a particular field. It concatenates the default CSS classes plus the custom classes (passed as the class key in the $attributes array). And it will also add an extra class if the control has any errors. @param string $type @param array $attributes @param string|null $errors @return string
[ "Get", "the", "HTML", "classes", "for", "a", "particular", "field", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FieldBuilder.php#L615-L628
train
StydeNet/html
src/FieldBuilder.php
FieldBuilder.replaceAttributes
protected function replaceAttributes(array $attributes) { foreach ($this->abbreviations as $abbreviation => $attribute) { if (isset($attributes[$abbreviation])) { $attributes[$attribute] = $attributes[$abbreviation]; unset($attributes[$abbreviation]); } } return $attributes; }
php
protected function replaceAttributes(array $attributes) { foreach ($this->abbreviations as $abbreviation => $attribute) { if (isset($attributes[$abbreviation])) { $attributes[$attribute] = $attributes[$abbreviation]; unset($attributes[$abbreviation]); } } return $attributes; }
[ "protected", "function", "replaceAttributes", "(", "array", "$", "attributes", ")", "{", "foreach", "(", "$", "this", "->", "abbreviations", "as", "$", "abbreviation", "=>", "$", "attribute", ")", "{", "if", "(", "isset", "(", "$", "attributes", "[", "$", ...
Search for abbreviations and replace them with the right attributes @param array $attributes @return array
[ "Search", "for", "abbreviations", "and", "replace", "them", "with", "the", "right", "attributes" ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FieldBuilder.php#L681-L691
train
StydeNet/html
src/FieldBuilder.php
FieldBuilder.doBuild
protected function doBuild($type, $name, $value = null, array $attributes = array(), array $extra = array(), $options = null) { $attributes = $this->replaceAttributes($attributes); if (!$this->checkAccess($attributes)) { return ''; } $required = $this->getRequired($attributes); $label = $this->getLabel($name, $attributes); $htmlName = $this->getHtmlName($name); $id = $this->getHtmlId($name, $attributes); $errors = $this->getControlErrors($name); $hasErrors = !empty($errors); $customTemplate = $this->getCustomTemplate($attributes); $attributes = $this->getHtmlAttributes($type, $attributes, $errors, $id); $input = $this->buildControl($type, $name, $value, $attributes, $options, $htmlName, $hasErrors); return $this->theme->render( $customTemplate, array_merge($extra, compact('htmlName', 'id', 'label', 'input', 'errors', 'hasErrors', 'required')), 'fields.'.$this->getDefaultTemplate($type) ); }
php
protected function doBuild($type, $name, $value = null, array $attributes = array(), array $extra = array(), $options = null) { $attributes = $this->replaceAttributes($attributes); if (!$this->checkAccess($attributes)) { return ''; } $required = $this->getRequired($attributes); $label = $this->getLabel($name, $attributes); $htmlName = $this->getHtmlName($name); $id = $this->getHtmlId($name, $attributes); $errors = $this->getControlErrors($name); $hasErrors = !empty($errors); $customTemplate = $this->getCustomTemplate($attributes); $attributes = $this->getHtmlAttributes($type, $attributes, $errors, $id); $input = $this->buildControl($type, $name, $value, $attributes, $options, $htmlName, $hasErrors); return $this->theme->render( $customTemplate, array_merge($extra, compact('htmlName', 'id', 'label', 'input', 'errors', 'hasErrors', 'required')), 'fields.'.$this->getDefaultTemplate($type) ); }
[ "protected", "function", "doBuild", "(", "$", "type", ",", "$", "name", ",", "$", "value", "=", "null", ",", "array", "$", "attributes", "=", "array", "(", ")", ",", "array", "$", "extra", "=", "array", "(", ")", ",", "$", "options", "=", "null", ...
Build and render a field @param string $type @param string $name @param mixed $value @param array $attributes @param array $extra @param array|null $options @return string
[ "Build", "and", "render", "a", "field" ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FieldBuilder.php#L730-L755
train
StydeNet/html
src/Alert/Container.php
Container.translate
public function translate($text, $parameters = array()) { if (!is_null($this->lang)) { return $this->lang->get($text, $parameters); } return $text; }
php
public function translate($text, $parameters = array()) { if (!is_null($this->lang)) { return $this->lang->get($text, $parameters); } return $text; }
[ "public", "function", "translate", "(", "$", "text", ",", "$", "parameters", "=", "array", "(", ")", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "lang", ")", ")", "{", "return", "$", "this", "->", "lang", "->", "get", "(", "$", ...
Attempts to translate texts if the translator component is set and the lang key is found, otherwise returns the original text. @param $text @param array $parameters @return string
[ "Attempts", "to", "translate", "texts", "if", "the", "translator", "component", "is", "set", "and", "the", "lang", "key", "is", "found", "otherwise", "returns", "the", "original", "text", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Alert/Container.php#L110-L117
train
StydeNet/html
src/Alert/Container.php
Container.render
public function render($custom = null) { $messages = $this->toArray(); if ( ! empty ($messages)) { $this->clearMessages(); return $this->theme->render( $custom, ['messages' => $this->withDefaults($messages)], 'alert' ); } return ''; }
php
public function render($custom = null) { $messages = $this->toArray(); if ( ! empty ($messages)) { $this->clearMessages(); return $this->theme->render( $custom, ['messages' => $this->withDefaults($messages)], 'alert' ); } return ''; }
[ "public", "function", "render", "(", "$", "custom", "=", "null", ")", "{", "$", "messages", "=", "$", "this", "->", "toArray", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "messages", ")", ")", "{", "$", "this", "->", "clearMessages", "(", "...
Clear and render the alert messages of this and the previous requests. @param string|null $custom @return string
[ "Clear", "and", "render", "the", "alert", "messages", "of", "this", "and", "the", "previous", "requests", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Alert/Container.php#L176-L190
train
StydeNet/html
src/Alert/Container.php
Container.withDefaults
protected function withDefaults($messages) { $defaults = array( 'details' => '', 'html' => '', 'list' => [], 'buttons' => [], ); foreach ($messages as &$message) { $message = array_merge($defaults, $message); } return $messages; }
php
protected function withDefaults($messages) { $defaults = array( 'details' => '', 'html' => '', 'list' => [], 'buttons' => [], ); foreach ($messages as &$message) { $message = array_merge($defaults, $message); } return $messages; }
[ "protected", "function", "withDefaults", "(", "$", "messages", ")", "{", "$", "defaults", "=", "array", "(", "'details'", "=>", "''", ",", "'html'", "=>", "''", ",", "'list'", "=>", "[", "]", ",", "'buttons'", "=>", "[", "]", ",", ")", ";", "foreach"...
Add the optional defaults for each alert message so you don't have to use isset in the template nor persist empty values through the handler. @param $messages @return array
[ "Add", "the", "optional", "defaults", "for", "each", "alert", "message", "so", "you", "don", "t", "have", "to", "use", "isset", "in", "the", "template", "nor", "persist", "empty", "values", "through", "the", "handler", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Alert/Container.php#L199-L213
train
StydeNet/html
src/Menu/MenuGenerator.php
MenuGenerator.make
public function make($items, $classes = null) { if (is_string($items)) { $items = $this->config->get($items); } $menu = new Menu($this->url, $this->theme, $items); if (!is_null($this->lang)) { $menu->setLang($this->lang); } if (!is_null($this->accessHandler)) { $menu->setAccessHandler($this->accessHandler); } if ($classes != null) { $menu->setClass($classes); } if ($this->activeUrlResolver != null) { $menu->setActiveUrlResolver($this->activeUrlResolver); } return $menu; }
php
public function make($items, $classes = null) { if (is_string($items)) { $items = $this->config->get($items); } $menu = new Menu($this->url, $this->theme, $items); if (!is_null($this->lang)) { $menu->setLang($this->lang); } if (!is_null($this->accessHandler)) { $menu->setAccessHandler($this->accessHandler); } if ($classes != null) { $menu->setClass($classes); } if ($this->activeUrlResolver != null) { $menu->setActiveUrlResolver($this->activeUrlResolver); } return $menu; }
[ "public", "function", "make", "(", "$", "items", ",", "$", "classes", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "items", ")", ")", "{", "$", "items", "=", "$", "this", "->", "config", "->", "get", "(", "$", "items", ")", ";", "}"...
Makes a new menu. As the first argument you can send an array of items or reference a configuration key where you can store the items array. @param array|string $items array of items or a config file key @param string|null $classes main CSS classes for the menu @return \Styde\Html\Menu\Menu
[ "Makes", "a", "new", "menu", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Menu/MenuGenerator.php#L97-L122
train
StydeNet/html
src/HtmlServiceProvider.php
HtmlServiceProvider.getTheme
protected function getTheme() { if ($this->theme == null) { $this->theme = new Theme($this->app['view'], $this->options['theme'], $this->options['custom']); } return $this->theme; }
php
protected function getTheme() { if ($this->theme == null) { $this->theme = new Theme($this->app['view'], $this->options['theme'], $this->options['custom']); } return $this->theme; }
[ "protected", "function", "getTheme", "(", ")", "{", "if", "(", "$", "this", "->", "theme", "==", "null", ")", "{", "$", "this", "->", "theme", "=", "new", "Theme", "(", "$", "this", "->", "app", "[", "'view'", "]", ",", "$", "this", "->", "option...
Instantiate and return the Theme object Only one theme is necessary, and the theme object will be used internally by the other classes of this component. So we don't need to add it to the IoC container. @return \Styde\Html\Theme
[ "Instantiate", "and", "return", "the", "Theme", "object" ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/HtmlServiceProvider.php#L107-L114
train
StydeNet/html
src/HtmlServiceProvider.php
HtmlServiceProvider.registerAccessHandler
protected function registerAccessHandler() { $this->app->singleton('access', function ($app) { $guard = $app['config']->get('html.guard', null); $handler = new BasicAccessHandler($app['auth']->guard($guard)); $gate = $app->make(Gate::class); if ($gate) { $handler->setGate($gate); } return $handler; }); $this->app->alias('access', AccessHandler::class); }
php
protected function registerAccessHandler() { $this->app->singleton('access', function ($app) { $guard = $app['config']->get('html.guard', null); $handler = new BasicAccessHandler($app['auth']->guard($guard)); $gate = $app->make(Gate::class); if ($gate) { $handler->setGate($gate); } return $handler; }); $this->app->alias('access', AccessHandler::class); }
[ "protected", "function", "registerAccessHandler", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "'access'", ",", "function", "(", "$", "app", ")", "{", "$", "guard", "=", "$", "app", "[", "'config'", "]", "->", "get", "(", "'html.gua...
Register the AccessHandler implementation into the IoC Container. This package provides a BasicAccessHandler. @return \Styde\Html\Access\AccessHandler
[ "Register", "the", "AccessHandler", "implementation", "into", "the", "IoC", "Container", ".", "This", "package", "provides", "a", "BasicAccessHandler", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/HtmlServiceProvider.php#L122-L137
train
StydeNet/html
src/HtmlServiceProvider.php
HtmlServiceProvider.registerFormBuilder
protected function registerFormBuilder() { $this->app->singleton('form', function ($app) { $this->loadConfigurationOptions(); $form = new FormBuilder( $app['html'], $app['url'], $app['session.store']->token(), $this->getTheme() ); $form->novalidate( $app['config']->get('html.novalidate', false) ); return $form->setSessionStore($app['session.store']); }); }
php
protected function registerFormBuilder() { $this->app->singleton('form', function ($app) { $this->loadConfigurationOptions(); $form = new FormBuilder( $app['html'], $app['url'], $app['session.store']->token(), $this->getTheme() ); $form->novalidate( $app['config']->get('html.novalidate', false) ); return $form->setSessionStore($app['session.store']); }); }
[ "protected", "function", "registerFormBuilder", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "'form'", ",", "function", "(", "$", "app", ")", "{", "$", "this", "->", "loadConfigurationOptions", "(", ")", ";", "$", "form", "=", "new", ...
Register the Form Builder instance.
[ "Register", "the", "Form", "Builder", "instance", "." ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/HtmlServiceProvider.php#L142-L160
train
StydeNet/html
src/HtmlServiceProvider.php
HtmlServiceProvider.registerFieldBuilder
protected function registerFieldBuilder() { $this->app->bind('field', function ($app) { $this->loadConfigurationOptions(); $fieldBuilder = new FieldBuilder( $app['form'], $this->theme, $app['translator'] ); if ($this->options['control_access']) { $fieldBuilder->setAccessHandler($app[AccessHandler::class]); } $fieldBuilder->setAbbreviations($this->options['abbreviations']); if (isset ($this->options['theme_values']['field_classes'])) { $fieldBuilder->setCssClasses( $this->options['theme_values']['field_classes'] ); } if (isset ($this->options['theme_values']['field_templates'])) { $fieldBuilder->setTemplates( $this->options['theme_values']['field_templates'] ); } $fieldBuilder->setSessionStore($app['session.store']); return $fieldBuilder; }); }
php
protected function registerFieldBuilder() { $this->app->bind('field', function ($app) { $this->loadConfigurationOptions(); $fieldBuilder = new FieldBuilder( $app['form'], $this->theme, $app['translator'] ); if ($this->options['control_access']) { $fieldBuilder->setAccessHandler($app[AccessHandler::class]); } $fieldBuilder->setAbbreviations($this->options['abbreviations']); if (isset ($this->options['theme_values']['field_classes'])) { $fieldBuilder->setCssClasses( $this->options['theme_values']['field_classes'] ); } if (isset ($this->options['theme_values']['field_templates'])) { $fieldBuilder->setTemplates( $this->options['theme_values']['field_templates'] ); } $fieldBuilder->setSessionStore($app['session.store']); return $fieldBuilder; }); }
[ "protected", "function", "registerFieldBuilder", "(", ")", "{", "$", "this", "->", "app", "->", "bind", "(", "'field'", ",", "function", "(", "$", "app", ")", "{", "$", "this", "->", "loadConfigurationOptions", "(", ")", ";", "$", "fieldBuilder", "=", "n...
Register the Field Builder instance
[ "Register", "the", "Field", "Builder", "instance" ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/HtmlServiceProvider.php#L175-L209
train
StydeNet/html
src/HtmlServiceProvider.php
HtmlServiceProvider.registerAlertContainer
protected function registerAlertContainer() { $this->app->singleton('alert', function ($app) { $this->loadConfigurationOptions(); $alert = new Alert( $this->getAlertHandler(), $this->getTheme() ); if ($this->options['translate_texts']) { $alert->setLang($app['translator']); } return $alert; }); $this->app->alias('alert', Alert::class); }
php
protected function registerAlertContainer() { $this->app->singleton('alert', function ($app) { $this->loadConfigurationOptions(); $alert = new Alert( $this->getAlertHandler(), $this->getTheme() ); if ($this->options['translate_texts']) { $alert->setLang($app['translator']); } return $alert; }); $this->app->alias('alert', Alert::class); }
[ "protected", "function", "registerAlertContainer", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "'alert'", ",", "function", "(", "$", "app", ")", "{", "$", "this", "->", "loadConfigurationOptions", "(", ")", ";", "$", "alert", "=", "n...
Register the Alert Container instance
[ "Register", "the", "Alert", "Container", "instance" ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/HtmlServiceProvider.php#L230-L248
train
StydeNet/html
src/HtmlServiceProvider.php
HtmlServiceProvider.registerMenuGenerator
protected function registerMenuGenerator() { $this->app->bind('menu', function ($app) { $this->loadConfigurationOptions(); $menu = new MenuGenerator( $app['url'], $app['config'], $this->getTheme() ); if ($this->options['control_access']) { $menu->setAccessHandler($app[AccessHandler::class]); } if ($this->options['translate_texts']) { $menu->setLang($app['translator']); } return $menu; }); }
php
protected function registerMenuGenerator() { $this->app->bind('menu', function ($app) { $this->loadConfigurationOptions(); $menu = new MenuGenerator( $app['url'], $app['config'], $this->getTheme() ); if ($this->options['control_access']) { $menu->setAccessHandler($app[AccessHandler::class]); } if ($this->options['translate_texts']) { $menu->setLang($app['translator']); } return $menu; }); }
[ "protected", "function", "registerMenuGenerator", "(", ")", "{", "$", "this", "->", "app", "->", "bind", "(", "'menu'", ",", "function", "(", "$", "app", ")", "{", "$", "this", "->", "loadConfigurationOptions", "(", ")", ";", "$", "menu", "=", "new", "...
Register the Menu Generator instance
[ "Register", "the", "Menu", "Generator", "instance" ]
b93eda3606edf049dc579c6b9c903cbcf0605d71
https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/HtmlServiceProvider.php#L263-L285
train
Gregwar/Formidable
Factory.php
Factory.getParser
public function getParser($content, $offset = 0) { $parserClass = $this->parserClass; return $this->inject(new $parserClass($content, $this, $offset)); }
php
public function getParser($content, $offset = 0) { $parserClass = $this->parserClass; return $this->inject(new $parserClass($content, $this, $offset)); }
[ "public", "function", "getParser", "(", "$", "content", ",", "$", "offset", "=", "0", ")", "{", "$", "parserClass", "=", "$", "this", "->", "parserClass", ";", "return", "$", "this", "->", "inject", "(", "new", "$", "parserClass", "(", "$", "content", ...
Get a parser
[ "Get", "a", "parser" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Factory.php#L78-L83
train
Gregwar/Formidable
Factory.php
Factory.getField
public function getField($name) { if (isset($this->typeClasses[$name])) { return $this->inject(new $this->typeClasses[$name]); } else { throw new ParserException('Unknown field type: '.$name); } }
php
public function getField($name) { if (isset($this->typeClasses[$name])) { return $this->inject(new $this->typeClasses[$name]); } else { throw new ParserException('Unknown field type: '.$name); } }
[ "public", "function", "getField", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "typeClasses", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "inject", "(", "new", "$", "this", "->", "typeClasses", "[",...
Get a field of a given type
[ "Get", "a", "field", "of", "a", "given", "type" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Factory.php#L88-L95
train
Gregwar/Formidable
Factory.php
Factory.getForm
public function getForm($pathOrContent, array $vars = array(), $cache = false) { $formClass = $this->formClass; return $this->inject(new $formClass($pathOrContent, $vars, $cache, $this)); }
php
public function getForm($pathOrContent, array $vars = array(), $cache = false) { $formClass = $this->formClass; return $this->inject(new $formClass($pathOrContent, $vars, $cache, $this)); }
[ "public", "function", "getForm", "(", "$", "pathOrContent", ",", "array", "$", "vars", "=", "array", "(", ")", ",", "$", "cache", "=", "false", ")", "{", "$", "formClass", "=", "$", "this", "->", "formClass", ";", "return", "$", "this", "->", "inject...
Get a form in this factory
[ "Get", "a", "form", "in", "this", "factory" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Factory.php#L108-L112
train
Gregwar/Formidable
Fields/Field.php
Field.push
public function push($name, $value = null) { switch ($name) { case 'name': $this->setName($value); break; case 'type': break; case 'value': $this->setValue($value, true); break; case 'required': $this->required = true; break; case 'pattern': case 'regex': $this->regex = $value; $this->attributes['pattern'] = $value; break; case 'minlength': $this->minlength = $value; $this->attributes['minlength'] = $value; break; case 'maxlength': $this->maxlength = $value; $this->attributes['maxlength'] = $value; break; case 'mapping': $this->mapping = $value; break; case 'prettyname': $this->prettyname = $value; break; case 'readonly': $this->readonly = true; $this->attributes['readonly'] = 'readonly'; break; default: if (preg_match('#^([a-z0-9_-]+)$#mUsi', $name)) { if (null !== $value) { $this->setAttribute($name, $value); } else { $this->setAttribute($name, $name); } } } }
php
public function push($name, $value = null) { switch ($name) { case 'name': $this->setName($value); break; case 'type': break; case 'value': $this->setValue($value, true); break; case 'required': $this->required = true; break; case 'pattern': case 'regex': $this->regex = $value; $this->attributes['pattern'] = $value; break; case 'minlength': $this->minlength = $value; $this->attributes['minlength'] = $value; break; case 'maxlength': $this->maxlength = $value; $this->attributes['maxlength'] = $value; break; case 'mapping': $this->mapping = $value; break; case 'prettyname': $this->prettyname = $value; break; case 'readonly': $this->readonly = true; $this->attributes['readonly'] = 'readonly'; break; default: if (preg_match('#^([a-z0-9_-]+)$#mUsi', $name)) { if (null !== $value) { $this->setAttribute($name, $value); } else { $this->setAttribute($name, $name); } } } }
[ "public", "function", "push", "(", "$", "name", ",", "$", "value", "=", "null", ")", "{", "switch", "(", "$", "name", ")", "{", "case", "'name'", ":", "$", "this", "->", "setName", "(", "$", "value", ")", ";", "break", ";", "case", "'type'", ":",...
Function called by the dispatcher
[ "Function", "called", "by", "the", "dispatcher" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Fields/Field.php#L125-L171
train
Gregwar/Formidable
Form.php
Form.pushLanguage
protected function pushLanguage() { $language = $this->factory->getLanguage(); if ($language && $this->parserData) { $fields = $this->parserData->getFields(); foreach ($fields as &$field) { $field->setLanguage($this->factory->getLanguage()); } } }
php
protected function pushLanguage() { $language = $this->factory->getLanguage(); if ($language && $this->parserData) { $fields = $this->parserData->getFields(); foreach ($fields as &$field) { $field->setLanguage($this->factory->getLanguage()); } } }
[ "protected", "function", "pushLanguage", "(", ")", "{", "$", "language", "=", "$", "this", "->", "factory", "->", "getLanguage", "(", ")", ";", "if", "(", "$", "language", "&&", "$", "this", "->", "parserData", ")", "{", "$", "fields", "=", "$", "thi...
Push the language to all the fields
[ "Push", "the", "language", "to", "all", "the", "fields" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L120-L130
train
Gregwar/Formidable
Form.php
Form.getContent
public function getContent() { if ($this->content === null) { if (is_array($this->variables)) { extract($this->variables); } else { if ($this->variables !== null) { throw new \InvalidArgumentException('$variables argument should be null or an array'); } } ob_start(); include($this->path); $this->content = ob_get_clean(); } return $this->content; }
php
public function getContent() { if ($this->content === null) { if (is_array($this->variables)) { extract($this->variables); } else { if ($this->variables !== null) { throw new \InvalidArgumentException('$variables argument should be null or an array'); } } ob_start(); include($this->path); $this->content = ob_get_clean(); } return $this->content; }
[ "public", "function", "getContent", "(", ")", "{", "if", "(", "$", "this", "->", "content", "===", "null", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "variables", ")", ")", "{", "extract", "(", "$", "this", "->", "variables", ")", ";"...
Get the form contents
[ "Get", "the", "form", "contents" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L135-L152
train
Gregwar/Formidable
Form.php
Form.parse
protected function parse() { $formidable = $this; $generate = function() use ($formidable) { // Parses the contents $parser = $formidable->getFactory()->getParser($formidable->getContent()); $formidable->isCached = false; return $parser; }; if ($this->cache) { $formInfos = array( 'path' => $this->path, 'content' => $this->content ); $cacheFile = sha1(serialize($formInfos)); $conditions = array(); if ($this->path !== null) { $conditions['younger-than'] = $this->path; } $cacheData = $this->cache->getOrCreate($cacheFile, $conditions, function($cacheFile) use ($generate) { $parserData = $generate(); file_put_contents($cacheFile, serialize($parserData)); }); $this->originalParserData = unserialize($cacheData); } else { $this->originalParserData = $generate(); } $this->reset(); }
php
protected function parse() { $formidable = $this; $generate = function() use ($formidable) { // Parses the contents $parser = $formidable->getFactory()->getParser($formidable->getContent()); $formidable->isCached = false; return $parser; }; if ($this->cache) { $formInfos = array( 'path' => $this->path, 'content' => $this->content ); $cacheFile = sha1(serialize($formInfos)); $conditions = array(); if ($this->path !== null) { $conditions['younger-than'] = $this->path; } $cacheData = $this->cache->getOrCreate($cacheFile, $conditions, function($cacheFile) use ($generate) { $parserData = $generate(); file_put_contents($cacheFile, serialize($parserData)); }); $this->originalParserData = unserialize($cacheData); } else { $this->originalParserData = $generate(); } $this->reset(); }
[ "protected", "function", "parse", "(", ")", "{", "$", "formidable", "=", "$", "this", ";", "$", "generate", "=", "function", "(", ")", "use", "(", "$", "formidable", ")", "{", "// Parses the contents", "$", "parser", "=", "$", "formidable", "->", "getFac...
Parses the form contents to build objects
[ "Parses", "the", "form", "contents", "to", "build", "objects" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L157-L191
train
Gregwar/Formidable
Form.php
Form.getValues
public function getValues() { $values = array(); foreach ($this->getFields() as $field) { $name = $field->getBaseName(); $index = $field->getIndex(); if ($index === null) { $values[$name] = $field->getValue(); } else { if (!isset($values[$name])) { $values[$name] = array(); } if ($index) { $value = &$values[$name]; foreach ($index as $part) { if (!isset($value[$part])) { $value[$part] = array(); } $value = &$value[$part]; } $value = $field->getValue(); } else { $values[$name][] = $field->getValue(); } } } return $values; }
php
public function getValues() { $values = array(); foreach ($this->getFields() as $field) { $name = $field->getBaseName(); $index = $field->getIndex(); if ($index === null) { $values[$name] = $field->getValue(); } else { if (!isset($values[$name])) { $values[$name] = array(); } if ($index) { $value = &$values[$name]; foreach ($index as $part) { if (!isset($value[$part])) { $value[$part] = array(); } $value = &$value[$part]; } $value = $field->getValue(); } else { $values[$name][] = $field->getValue(); } } } return $values; }
[ "public", "function", "getValues", "(", ")", "{", "$", "values", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getFields", "(", ")", "as", "$", "field", ")", "{", "$", "name", "=", "$", "field", "->", "getBaseName", "(", ")", "...
Get all the values
[ "Get", "all", "the", "values" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L205-L236
train
Gregwar/Formidable
Form.php
Form.setValues
public function setValues($values, array $files = array()) { foreach ($this->getFields() as $name => $field) { $name = $field->getBaseName(); $index = $field->getIndex(); if ($index === null) { if ($present = isset($values[$name])) { $value =& $values[$name]; } } else { if ($index) { $present = true; $tmp = &$values[$name]; foreach ($index as $part) { if (isset($tmp[$part])) { $tmp = &$tmp[$part]; } else { $present = false; } } if ($present) { $value = $tmp; } } else { if ($present = isset($values[$name]) && is_array($values[$name])) { $value = in_array($field->getValue(), $values[$name]); } } } if ($field instanceof Fields\Multiple) { if (!$present) { $value = array(); } $field->setValues($value, (isset($files[$name])?$files[$name]:array())); } else { if ($present) { $field->setValue($value, $files); } else { if ($field instanceof Fields\FileField && isset($files[$name])) { $field->setValue($files[$name]); } else { $field->setValue(''); } } } } }
php
public function setValues($values, array $files = array()) { foreach ($this->getFields() as $name => $field) { $name = $field->getBaseName(); $index = $field->getIndex(); if ($index === null) { if ($present = isset($values[$name])) { $value =& $values[$name]; } } else { if ($index) { $present = true; $tmp = &$values[$name]; foreach ($index as $part) { if (isset($tmp[$part])) { $tmp = &$tmp[$part]; } else { $present = false; } } if ($present) { $value = $tmp; } } else { if ($present = isset($values[$name]) && is_array($values[$name])) { $value = in_array($field->getValue(), $values[$name]); } } } if ($field instanceof Fields\Multiple) { if (!$present) { $value = array(); } $field->setValues($value, (isset($files[$name])?$files[$name]:array())); } else { if ($present) { $field->setValue($value, $files); } else { if ($field instanceof Fields\FileField && isset($files[$name])) { $field->setValue($files[$name]); } else { $field->setValue(''); } } } } }
[ "public", "function", "setValues", "(", "$", "values", ",", "array", "$", "files", "=", "array", "(", ")", ")", "{", "foreach", "(", "$", "this", "->", "getFields", "(", ")", "as", "$", "name", "=>", "$", "field", ")", "{", "$", "name", "=", "$",...
Define the values
[ "Define", "the", "values" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L241-L290
train
Gregwar/Formidable
Form.php
Form.setData
public function setData($entity) { if ($this->accessor == null) { $this->accessor = new PropertyAccessor; } foreach ($this->getFields() as $field) { if (is_object($field)) { if (($mapping = $field->getMappingName()) && !$field->readOnly()) { if (is_array($entity)) { if (isset($entity[$mapping])) { $field->setValue($entity[$mapping], 1); } } else { $value = $this->accessor->getValue($entity, $mapping); $field->setValue($value, 1); } } } } }
php
public function setData($entity) { if ($this->accessor == null) { $this->accessor = new PropertyAccessor; } foreach ($this->getFields() as $field) { if (is_object($field)) { if (($mapping = $field->getMappingName()) && !$field->readOnly()) { if (is_array($entity)) { if (isset($entity[$mapping])) { $field->setValue($entity[$mapping], 1); } } else { $value = $this->accessor->getValue($entity, $mapping); $field->setValue($value, 1); } } } } }
[ "public", "function", "setData", "(", "$", "entity", ")", "{", "if", "(", "$", "this", "->", "accessor", "==", "null", ")", "{", "$", "this", "->", "accessor", "=", "new", "PropertyAccessor", ";", "}", "foreach", "(", "$", "this", "->", "getFields", ...
Define the values using mapping
[ "Define", "the", "values", "using", "mapping" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L295-L315
train
Gregwar/Formidable
Form.php
Form.addConstraint
public function addConstraint($name, $closure = null) { if ($name instanceof \Closure) { $closure = $name; $name = null; } if ($name == null) { $this->constraints[] = $closure; } else { $this->getField($name)->addConstraint($closure); } }
php
public function addConstraint($name, $closure = null) { if ($name instanceof \Closure) { $closure = $name; $name = null; } if ($name == null) { $this->constraints[] = $closure; } else { $this->getField($name)->addConstraint($closure); } }
[ "public", "function", "addConstraint", "(", "$", "name", ",", "$", "closure", "=", "null", ")", "{", "if", "(", "$", "name", "instanceof", "\\", "Closure", ")", "{", "$", "closure", "=", "$", "name", ";", "$", "name", "=", "null", ";", "}", "if", ...
Add a constraint on a field
[ "Add", "a", "constraint", "on", "a", "field" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L344-L356
train
Gregwar/Formidable
Form.php
Form.setAttribute
public function setAttribute($name, $attribute, $value) { $this->getField($name)->setAttribute($attribute, $value); }
php
public function setAttribute($name, $attribute, $value) { $this->getField($name)->setAttribute($attribute, $value); }
[ "public", "function", "setAttribute", "(", "$", "name", ",", "$", "attribute", ",", "$", "value", ")", "{", "$", "this", "->", "getField", "(", "$", "name", ")", "->", "setAttribute", "(", "$", "attribute", ",", "$", "value", ")", ";", "}" ]
Defines an attribute value
[ "Defines", "an", "attribute", "value" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L361-L364
train
Gregwar/Formidable
Form.php
Form.getJs
public function getJs() { $html = '<script type="text/javascript">'; $js = file_get_contents(__DIR__.'/Js/formidable.js'); $html .= str_replace("\n", '', str_replace('{remove}', $this->factory->getLanguage()->translate('remove'), $js)); $html .= '</script>'; return $html; }
php
public function getJs() { $html = '<script type="text/javascript">'; $js = file_get_contents(__DIR__.'/Js/formidable.js'); $html .= str_replace("\n", '', str_replace('{remove}', $this->factory->getLanguage()->translate('remove'), $js)); $html .= '</script>'; return $html; }
[ "public", "function", "getJs", "(", ")", "{", "$", "html", "=", "'<script type=\"text/javascript\">'", ";", "$", "js", "=", "file_get_contents", "(", "__DIR__", ".", "'/Js/formidable.js'", ")", ";", "$", "html", ".=", "str_replace", "(", "\"\\n\"", ",", "''", ...
Get the JavaScript code to embed
[ "Get", "the", "JavaScript", "code", "to", "embed" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L406-L414
train
Gregwar/Formidable
Form.php
Form.getHtml
public function getHtml() { $html = ''; if ($this->parserData->needJs()) { $html .= $this->getJs(); } $k = 0; foreach ($this->parserData->getData() as $data) { if ($data instanceof Fields\FileField) { $data->getHtml(true); } $html .= (string)$data; } if ($html[strlen($html)-1] != "\n") { $html .= "\n"; } return $html; }
php
public function getHtml() { $html = ''; if ($this->parserData->needJs()) { $html .= $this->getJs(); } $k = 0; foreach ($this->parserData->getData() as $data) { if ($data instanceof Fields\FileField) { $data->getHtml(true); } $html .= (string)$data; } if ($html[strlen($html)-1] != "\n") { $html .= "\n"; } return $html; }
[ "public", "function", "getHtml", "(", ")", "{", "$", "html", "=", "''", ";", "if", "(", "$", "this", "->", "parserData", "->", "needJs", "(", ")", ")", "{", "$", "html", ".=", "$", "this", "->", "getJs", "(", ")", ";", "}", "$", "k", "=", "0"...
Convert to HTML
[ "Convert", "to", "HTML" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L419-L440
train
Gregwar/Formidable
Form.php
Form.getData
public function getData($entity = array()) { if ($this->accessor == null) { $this->accessor = new PropertyAccessor; } foreach ($this->getFields() as $name => $field) { if ($mapping = $field->getMappingName()) { if (is_array($entity)) { $entity[$mapping] = $field->getMappingValue(); } else { $this->accessor->setValue($entity, $mapping, $field->getMappingValue()); } } } return $entity; }
php
public function getData($entity = array()) { if ($this->accessor == null) { $this->accessor = new PropertyAccessor; } foreach ($this->getFields() as $name => $field) { if ($mapping = $field->getMappingName()) { if (is_array($entity)) { $entity[$mapping] = $field->getMappingValue(); } else { $this->accessor->setValue($entity, $mapping, $field->getMappingValue()); } } } return $entity; }
[ "public", "function", "getData", "(", "$", "entity", "=", "array", "(", ")", ")", "{", "if", "(", "$", "this", "->", "accessor", "==", "null", ")", "{", "$", "this", "->", "accessor", "=", "new", "PropertyAccessor", ";", "}", "foreach", "(", "$", "...
Gets the data using mapping
[ "Gets", "the", "data", "using", "mapping" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L488-L505
train
Gregwar/Formidable
Form.php
Form.getPostIndicator
public function getPostIndicator() { foreach ($this->parserData->getData() as $entry) { if ($entry instanceof PostIndicator) { return $entry; } } return null; }
php
public function getPostIndicator() { foreach ($this->parserData->getData() as $entry) { if ($entry instanceof PostIndicator) { return $entry; } } return null; }
[ "public", "function", "getPostIndicator", "(", ")", "{", "foreach", "(", "$", "this", "->", "parserData", "->", "getData", "(", ")", "as", "$", "entry", ")", "{", "if", "(", "$", "entry", "instanceof", "PostIndicator", ")", "{", "return", "$", "entry", ...
Get the CSRF manager
[ "Get", "the", "CSRF", "manager" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L526-L535
train
Gregwar/Formidable
Form.php
Form.posted
public function posted($method = 'post') { $postIndicator = $this->getPostIndicator(); if ($postIndicator->posted($method)) { if ($method == 'post') { $this->setValues($_POST, $_FILES); } else if ($method == 'get') { $this->setValues($_GET); } return true; } return false; }
php
public function posted($method = 'post') { $postIndicator = $this->getPostIndicator(); if ($postIndicator->posted($method)) { if ($method == 'post') { $this->setValues($_POST, $_FILES); } else if ($method == 'get') { $this->setValues($_GET); } return true; } return false; }
[ "public", "function", "posted", "(", "$", "method", "=", "'post'", ")", "{", "$", "postIndicator", "=", "$", "this", "->", "getPostIndicator", "(", ")", ";", "if", "(", "$", "postIndicator", "->", "posted", "(", "$", "method", ")", ")", "{", "if", "(...
Check if the form was posted
[ "Check", "if", "the", "form", "was", "posted" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L548-L562
train
Gregwar/Formidable
Form.php
Form.handle
public function handle($callback = null, $errorsCallback = null) { if ($this->posted()) { $errors = $this->check(); if (!$errors) { if (null !== $callback) { $callback($this->getData()); } } else { if (null !== $errorsCallback) { $errorsCallback($errors); } return $errors; } } return array(); }
php
public function handle($callback = null, $errorsCallback = null) { if ($this->posted()) { $errors = $this->check(); if (!$errors) { if (null !== $callback) { $callback($this->getData()); } } else { if (null !== $errorsCallback) { $errorsCallback($errors); } return $errors; } } return array(); }
[ "public", "function", "handle", "(", "$", "callback", "=", "null", ",", "$", "errorsCallback", "=", "null", ")", "{", "if", "(", "$", "this", "->", "posted", "(", ")", ")", "{", "$", "errors", "=", "$", "this", "->", "check", "(", ")", ";", "if",...
Check a form, helper function
[ "Check", "a", "form", "helper", "function" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Form.php#L567-L585
train
Gregwar/Formidable
PostIndicator.php
PostIndicator.generateToken
protected function generateToken() { if ($this->token === null) { $secret = array( 'install' => __DIR__, 'name' => $this->name, ); if (isset($_SESSION)) { $key = sha1(__DIR__ . '/' . 'formidable_secret'); if (isset($_SESSION[$key])) { $secret['csrf'] = $_SESSION[$key]; } else { $csrf = sha1(uniqid(mt_rand(), true).'|'.gettimeofday(true)); $_SESSION[$key] = $csrf; $secret['csrf'] = $csrf; } } $this->token = sha1(serialize($secret)); } }
php
protected function generateToken() { if ($this->token === null) { $secret = array( 'install' => __DIR__, 'name' => $this->name, ); if (isset($_SESSION)) { $key = sha1(__DIR__ . '/' . 'formidable_secret'); if (isset($_SESSION[$key])) { $secret['csrf'] = $_SESSION[$key]; } else { $csrf = sha1(uniqid(mt_rand(), true).'|'.gettimeofday(true)); $_SESSION[$key] = $csrf; $secret['csrf'] = $csrf; } } $this->token = sha1(serialize($secret)); } }
[ "protected", "function", "generateToken", "(", ")", "{", "if", "(", "$", "this", "->", "token", "===", "null", ")", "{", "$", "secret", "=", "array", "(", "'install'", "=>", "__DIR__", ",", "'name'", "=>", "$", "this", "->", "name", ",", ")", ";", ...
Generate the token or get it from the session
[ "Generate", "the", "token", "or", "get", "it", "from", "the", "session" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/PostIndicator.php#L44-L66
train
Gregwar/Formidable
PostIndicator.php
PostIndicator.posted
public function posted($method = 'post') { $origin = ($method == 'post' ? $_POST : $_GET); return (isset($origin) && isset($origin[self::$fieldName]) && $this->getToken() && $this->getToken() == $origin[self::$fieldName]); }
php
public function posted($method = 'post') { $origin = ($method == 'post' ? $_POST : $_GET); return (isset($origin) && isset($origin[self::$fieldName]) && $this->getToken() && $this->getToken() == $origin[self::$fieldName]); }
[ "public", "function", "posted", "(", "$", "method", "=", "'post'", ")", "{", "$", "origin", "=", "(", "$", "method", "==", "'post'", "?", "$", "_POST", ":", "$", "_GET", ")", ";", "return", "(", "isset", "(", "$", "origin", ")", "&&", "isset", "(...
Tell if the given form was posted
[ "Tell", "if", "the", "given", "form", "was", "posted" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/PostIndicator.php#L79-L83
train
Gregwar/Formidable
Parser.php
Parser.findPlaceholders
protected function findPlaceholders() { $data = array(); foreach ($this->data as $part) { if (is_string($part)) { while (preg_match('#^(.+){{([^}]+)}}(.+)$#Usi', $part, $match)) { $data[] = $match[1]; $placeholder = new Placeholder($match[2]); $data[] = $placeholder; $this->placeholders[$placeholder->getName()] = $placeholder; $part = $match[3]; } $data[] = $part; } else { $data[] = $part; } } $this->data = $data; }
php
protected function findPlaceholders() { $data = array(); foreach ($this->data as $part) { if (is_string($part)) { while (preg_match('#^(.+){{([^}]+)}}(.+)$#Usi', $part, $match)) { $data[] = $match[1]; $placeholder = new Placeholder($match[2]); $data[] = $placeholder; $this->placeholders[$placeholder->getName()] = $placeholder; $part = $match[3]; } $data[] = $part; } else { $data[] = $part; } } $this->data = $data; }
[ "protected", "function", "findPlaceholders", "(", ")", "{", "$", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "data", "as", "$", "part", ")", "{", "if", "(", "is_string", "(", "$", "part", ")", ")", "{", "while", "(", "...
Parsing second pass, finding placeholders in strings
[ "Parsing", "second", "pass", "finding", "placeholders", "in", "strings" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Parser.php#L217-L237
train
Gregwar/Formidable
ParserData.php
ParserData.getField
public function getField($name) { if (isset($this->fields[$name])) { return $this->fields[$name]; } else { throw new \InvalidArgumentException('Field with name '.$name.' not found'); } }
php
public function getField($name) { if (isset($this->fields[$name])) { return $this->fields[$name]; } else { throw new \InvalidArgumentException('Field with name '.$name.' not found'); } }
[ "public", "function", "getField", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "fields", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "fields", "[", "$", "name", "]", ";", "}", "else", "{", "thro...
Gets a field
[ "Gets", "a", "field" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/ParserData.php#L96-L103
train
Gregwar/Formidable
Error.php
Error.getMessage
public function getMessage() { $message = $this->message; if (is_array($message)) { $message = $this->language->translateArray($message); } return $message; }
php
public function getMessage() { $message = $this->message; if (is_array($message)) { $message = $this->language->translateArray($message); } return $message; }
[ "public", "function", "getMessage", "(", ")", "{", "$", "message", "=", "$", "this", "->", "message", ";", "if", "(", "is_array", "(", "$", "message", ")", ")", "{", "$", "message", "=", "$", "this", "->", "language", "->", "translateArray", "(", "$"...
Gets the message
[ "Gets", "the", "message" ]
3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1
https://github.com/Gregwar/Formidable/blob/3025618a3e4c0e29da697fa8d1e9c6b32e6fbfd1/Error.php#L35-L44
train
salesforce-marketingcloud/FuelSDK-PHP
src/ET_Client.php
ET_Client.CreateWSDL
function CreateWSDL($wsdlLoc) { try{ $getNewWSDL = true; $remoteTS = $this->GetLastModifiedDate($wsdlLoc); if (file_exists($this->xmlLoc)){ $localTS = filemtime($this->xmlLoc); if ($remoteTS <= $localTS) { $getNewWSDL = false; } } if ($getNewWSDL){ $newWSDL = file_get_contents($wsdlLoc); file_put_contents($this->xmlLoc, $newWSDL); } } catch (Exception $e) { throw new Exception('Unable to store local copy of WSDL file:'.$e->getMessage()."\n"); } }
php
function CreateWSDL($wsdlLoc) { try{ $getNewWSDL = true; $remoteTS = $this->GetLastModifiedDate($wsdlLoc); if (file_exists($this->xmlLoc)){ $localTS = filemtime($this->xmlLoc); if ($remoteTS <= $localTS) { $getNewWSDL = false; } } if ($getNewWSDL){ $newWSDL = file_get_contents($wsdlLoc); file_put_contents($this->xmlLoc, $newWSDL); } } catch (Exception $e) { throw new Exception('Unable to store local copy of WSDL file:'.$e->getMessage()."\n"); } }
[ "function", "CreateWSDL", "(", "$", "wsdlLoc", ")", "{", "try", "{", "$", "getNewWSDL", "=", "true", ";", "$", "remoteTS", "=", "$", "this", "->", "GetLastModifiedDate", "(", "$", "wsdlLoc", ")", ";", "if", "(", "file_exists", "(", "$", "this", "->", ...
Create the WSDL file at specified location. @param string location or path of the WSDL file to be created. @return void
[ "Create", "the", "WSDL", "file", "at", "specified", "location", "." ]
8018468706fd796bd63d18f0af3ea8b1de088988
https://github.com/salesforce-marketingcloud/FuelSDK-PHP/blob/8018468706fd796bd63d18f0af3ea8b1de088988/src/ET_Client.php#L311-L333
train
salesforce-marketingcloud/FuelSDK-PHP
src/ET_Client.php
ET_Client.GetLastModifiedDate
function GetLastModifiedDate($remotepath) { $curl = curl_init($remotepath); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, ET_Util::shouldVerifySslPeer($this->sslVerifyPeer)); curl_setopt($curl, CURLOPT_NOBODY, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FILETIME, true); if (!empty($this->proxyHost)) { curl_setopt($curl, CURLOPT_PROXY, $this->proxyHost); } if (!empty($this->proxyPort)) { curl_setopt($curl, CURLOPT_PROXYPORT, $this->proxyPort); } if (!empty($this->proxyUserName) && !empty($this->proxyPassword)) { curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_PROXYUSERPWD, $this->proxyUserName.':'.$this->proxyPassword); } $result = curl_exec($curl); if ($result === false) { throw new Exception(curl_error($curl)); } return curl_getinfo($curl, CURLINFO_FILETIME); }
php
function GetLastModifiedDate($remotepath) { $curl = curl_init($remotepath); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, ET_Util::shouldVerifySslPeer($this->sslVerifyPeer)); curl_setopt($curl, CURLOPT_NOBODY, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FILETIME, true); if (!empty($this->proxyHost)) { curl_setopt($curl, CURLOPT_PROXY, $this->proxyHost); } if (!empty($this->proxyPort)) { curl_setopt($curl, CURLOPT_PROXYPORT, $this->proxyPort); } if (!empty($this->proxyUserName) && !empty($this->proxyPassword)) { curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_PROXYUSERPWD, $this->proxyUserName.':'.$this->proxyPassword); } $result = curl_exec($curl); if ($result === false) { throw new Exception(curl_error($curl)); } return curl_getinfo($curl, CURLINFO_FILETIME); }
[ "function", "GetLastModifiedDate", "(", "$", "remotepath", ")", "{", "$", "curl", "=", "curl_init", "(", "$", "remotepath", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_SSL_VERIFYPEER", ",", "ET_Util", "::", "shouldVerifySslPeer", "(", "$", "this",...
Returns last modified date of the URL @param [type] $remotepath @return string Last modified date
[ "Returns", "last", "modified", "date", "of", "the", "URL" ]
8018468706fd796bd63d18f0af3ea8b1de088988
https://github.com/salesforce-marketingcloud/FuelSDK-PHP/blob/8018468706fd796bd63d18f0af3ea8b1de088988/src/ET_Client.php#L341-L367
train
salesforce-marketingcloud/FuelSDK-PHP
src/ET_Client.php
ET_Client.__doRequest
function __doRequest($request, $location, $saction, $version, $one_way = 0) { $doc = new DOMDocument(); $doc->loadXML($request); $objWSSE = new WSSESoap($doc); $objWSSE->addUserToken("*", "*", FALSE); $this->addOAuth($doc, $this->getInternalAuthToken($this->tenantKey)); $content = $objWSSE->saveXML(); $content_length = strlen($content); if ($this->debugSOAP){ error_log ('FuelSDK SOAP Request: '); error_log (str_replace($this->getInternalAuthToken($this->tenantKey),"REMOVED",$content)); } $headers = array("Content-Type: text/xml","SOAPAction: ".$saction, "User-Agent: ".ET_Util::getSDKVersion()); $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $location); curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt ($ch, CURLOPT_POSTFIELDS, $content); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, ET_Util::shouldVerifySslPeer($this->sslVerifyPeer)); curl_setopt($ch, CURLOPT_USERAGENT, ET_Util::getSDKVersion()); if (!empty($this->proxyHost)) { curl_setopt($ch, CURLOPT_PROXY, $this->proxyHost); } if (!empty($this->proxyPort)) { curl_setopt($ch, CURLOPT_PROXYPORT, $this->proxyPort); } if (!empty($this->proxyUserName) && !empty($this->proxyPassword)) { curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->proxyUserName.':'.$this->proxyPassword); } $output = curl_exec($ch); $this->lastHTTPCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $output; }
php
function __doRequest($request, $location, $saction, $version, $one_way = 0) { $doc = new DOMDocument(); $doc->loadXML($request); $objWSSE = new WSSESoap($doc); $objWSSE->addUserToken("*", "*", FALSE); $this->addOAuth($doc, $this->getInternalAuthToken($this->tenantKey)); $content = $objWSSE->saveXML(); $content_length = strlen($content); if ($this->debugSOAP){ error_log ('FuelSDK SOAP Request: '); error_log (str_replace($this->getInternalAuthToken($this->tenantKey),"REMOVED",$content)); } $headers = array("Content-Type: text/xml","SOAPAction: ".$saction, "User-Agent: ".ET_Util::getSDKVersion()); $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $location); curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt ($ch, CURLOPT_POSTFIELDS, $content); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, ET_Util::shouldVerifySslPeer($this->sslVerifyPeer)); curl_setopt($ch, CURLOPT_USERAGENT, ET_Util::getSDKVersion()); if (!empty($this->proxyHost)) { curl_setopt($ch, CURLOPT_PROXY, $this->proxyHost); } if (!empty($this->proxyPort)) { curl_setopt($ch, CURLOPT_PROXYPORT, $this->proxyPort); } if (!empty($this->proxyUserName) && !empty($this->proxyPassword)) { curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->proxyUserName.':'.$this->proxyPassword); } $output = curl_exec($ch); $this->lastHTTPCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $output; }
[ "function", "__doRequest", "(", "$", "request", ",", "$", "location", ",", "$", "saction", ",", "$", "version", ",", "$", "one_way", "=", "0", ")", "{", "$", "doc", "=", "new", "DOMDocument", "(", ")", ";", "$", "doc", "->", "loadXML", "(", "$", ...
Perfoms an soap request. @param string $request Soap request xml @param string $location Url as string @param string $saction Soap action name @param string $version Future use @param integer $one_way Future use @return string Soap web service request result
[ "Perfoms", "an", "soap", "request", "." ]
8018468706fd796bd63d18f0af3ea8b1de088988
https://github.com/salesforce-marketingcloud/FuelSDK-PHP/blob/8018468706fd796bd63d18f0af3ea8b1de088988/src/ET_Client.php#L378-L419
train
salesforce-marketingcloud/FuelSDK-PHP
src/ET_Client.php
ET_Client.addOAuth
public function addOAuth( $doc, $token) { $soapDoc = $doc; $envelope = $doc->documentElement; $soapNS = $envelope->namespaceURI; $soapPFX = $envelope->prefix; $SOAPXPath = new DOMXPath($doc); $SOAPXPath->registerNamespace('wssoap', $soapNS); $SOAPXPath->registerNamespace('wswsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'); $headers = $SOAPXPath->query('//wssoap:Envelope/wssoap:Header'); $header = $headers->item(0); if (! $header) { $header = $soapDoc->createElementNS($soapNS, $soapPFX.':Header'); $envelope->insertBefore($header, $envelope->firstChild); } $authnode = $soapDoc->createElementNS('http://exacttarget.com', 'oAuth'); $header->appendChild($authnode); $oauthtoken = $soapDoc->createElementNS(null,'oAuthToken',$token); $authnode->appendChild($oauthtoken); }
php
public function addOAuth( $doc, $token) { $soapDoc = $doc; $envelope = $doc->documentElement; $soapNS = $envelope->namespaceURI; $soapPFX = $envelope->prefix; $SOAPXPath = new DOMXPath($doc); $SOAPXPath->registerNamespace('wssoap', $soapNS); $SOAPXPath->registerNamespace('wswsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'); $headers = $SOAPXPath->query('//wssoap:Envelope/wssoap:Header'); $header = $headers->item(0); if (! $header) { $header = $soapDoc->createElementNS($soapNS, $soapPFX.':Header'); $envelope->insertBefore($header, $envelope->firstChild); } $authnode = $soapDoc->createElementNS('http://exacttarget.com', 'oAuth'); $header->appendChild($authnode); $oauthtoken = $soapDoc->createElementNS(null,'oAuthToken',$token); $authnode->appendChild($oauthtoken); }
[ "public", "function", "addOAuth", "(", "$", "doc", ",", "$", "token", ")", "{", "$", "soapDoc", "=", "$", "doc", ";", "$", "envelope", "=", "$", "doc", "->", "documentElement", ";", "$", "soapNS", "=", "$", "envelope", "->", "namespaceURI", ";", "$",...
Add OAuth token to the header of the soap request @param string $doc Soap request as xml string @param string $token OAuth token @return void
[ "Add", "OAuth", "token", "to", "the", "header", "of", "the", "soap", "request" ]
8018468706fd796bd63d18f0af3ea8b1de088988
https://github.com/salesforce-marketingcloud/FuelSDK-PHP/blob/8018468706fd796bd63d18f0af3ea8b1de088988/src/ET_Client.php#L427-L449
train
salesforce-marketingcloud/FuelSDK-PHP
src/ET_Client.php
ET_Client.getAuthToken
public function getAuthToken($tenantKey = null) { $tenantKey = $tenantKey == null ? $this->tenantKey : $tenantKey; if ($this->tenantTokens[$tenantKey] == null) { $this->tenantTokens[$tenantKey] = array(); } return isset($this->tenantTokens[$tenantKey]['authToken']) ? $this->tenantTokens[$tenantKey]['authToken'] : null; }
php
public function getAuthToken($tenantKey = null) { $tenantKey = $tenantKey == null ? $this->tenantKey : $tenantKey; if ($this->tenantTokens[$tenantKey] == null) { $this->tenantTokens[$tenantKey] = array(); } return isset($this->tenantTokens[$tenantKey]['authToken']) ? $this->tenantTokens[$tenantKey]['authToken'] : null; }
[ "public", "function", "getAuthToken", "(", "$", "tenantKey", "=", "null", ")", "{", "$", "tenantKey", "=", "$", "tenantKey", "==", "null", "?", "$", "this", "->", "tenantKey", ":", "$", "tenantKey", ";", "if", "(", "$", "this", "->", "tenantTokens", "[...
Get the authentication token. @return string
[ "Get", "the", "authentication", "token", "." ]
8018468706fd796bd63d18f0af3ea8b1de088988
https://github.com/salesforce-marketingcloud/FuelSDK-PHP/blob/8018468706fd796bd63d18f0af3ea8b1de088988/src/ET_Client.php#L455-L464
train
salesforce-marketingcloud/FuelSDK-PHP
src/ET_Client.php
ET_Client.getInternalAuthToken
function getInternalAuthToken($tenantKey) { $tenantKey = $tenantKey == null ? $this->tenantKey : $tenantKey; if ($this->tenantTokens[$tenantKey] == null) { $this->tenantTokens[$tenantKey] = array(); } return isset($this->tenantTokens[$tenantKey]['internalAuthToken']) ? $this->tenantTokens[$tenantKey]['internalAuthToken'] : null; }
php
function getInternalAuthToken($tenantKey) { $tenantKey = $tenantKey == null ? $this->tenantKey : $tenantKey; if ($this->tenantTokens[$tenantKey] == null) { $this->tenantTokens[$tenantKey] = array(); } return isset($this->tenantTokens[$tenantKey]['internalAuthToken']) ? $this->tenantTokens[$tenantKey]['internalAuthToken'] : null; }
[ "function", "getInternalAuthToken", "(", "$", "tenantKey", ")", "{", "$", "tenantKey", "=", "$", "tenantKey", "==", "null", "?", "$", "this", "->", "tenantKey", ":", "$", "tenantKey", ";", "if", "(", "$", "this", "->", "tenantTokens", "[", "$", "tenantKe...
Get the internal authentication token. @param string $tenantKey @return string Internal authenication token
[ "Get", "the", "internal", "authentication", "token", "." ]
8018468706fd796bd63d18f0af3ea8b1de088988
https://github.com/salesforce-marketingcloud/FuelSDK-PHP/blob/8018468706fd796bd63d18f0af3ea8b1de088988/src/ET_Client.php#L502-L511
train
salesforce-marketingcloud/FuelSDK-PHP
src/ET_DataExtension.php
ET_DataExtension.patch
public function patch() { $this->props["Fields"] = array("Field"=>array()); foreach ($this->columns as $column){ array_push($this->props['Fields']['Field'], $column); } $response = parent::patch(); unset($this->props["Fields"]); return $response; }
php
public function patch() { $this->props["Fields"] = array("Field"=>array()); foreach ($this->columns as $column){ array_push($this->props['Fields']['Field'], $column); } $response = parent::patch(); unset($this->props["Fields"]); return $response; }
[ "public", "function", "patch", "(", ")", "{", "$", "this", "->", "props", "[", "\"Fields\"", "]", "=", "array", "(", "\"Field\"", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "column", ")", "{", "array...
Patch this instance. @return ET_Patch Object of type ET_Patch which contains http status code, response, etc from the PATCH SOAP service
[ "Patch", "this", "instance", "." ]
8018468706fd796bd63d18f0af3ea8b1de088988
https://github.com/salesforce-marketingcloud/FuelSDK-PHP/blob/8018468706fd796bd63d18f0af3ea8b1de088988/src/ET_DataExtension.php#L64-L73
train
salesforce-marketingcloud/FuelSDK-PHP
src/ET_TriggeredSend.php
ET_TriggeredSend.Send
public function Send() { $tscall = array("TriggeredSendDefinition" => $this->props , "Subscribers" => $this->subscribers); $response = new ET_Post($this->authStub, "TriggeredSend", $tscall); return $response; }
php
public function Send() { $tscall = array("TriggeredSendDefinition" => $this->props , "Subscribers" => $this->subscribers); $response = new ET_Post($this->authStub, "TriggeredSend", $tscall); return $response; }
[ "public", "function", "Send", "(", ")", "{", "$", "tscall", "=", "array", "(", "\"TriggeredSendDefinition\"", "=>", "$", "this", "->", "props", ",", "\"Subscribers\"", "=>", "$", "this", "->", "subscribers", ")", ";", "$", "response", "=", "new", "ET_Post"...
Send this instance. @return ET_Post Object of type ET_Post which contains http status code, response, etc from the POST SOAP service
[ "Send", "this", "instance", "." ]
8018468706fd796bd63d18f0af3ea8b1de088988
https://github.com/salesforce-marketingcloud/FuelSDK-PHP/blob/8018468706fd796bd63d18f0af3ea8b1de088988/src/ET_TriggeredSend.php#L35-L40
train
salesforce-marketingcloud/FuelSDK-PHP
src/ET_Import.php
ET_Import.status
function status() { $this->filter = array('Property' => 'TaskResultID','SimpleOperator' => 'equals','Value' => $this->lastTaskID); $response = new ET_Get($this->authStub, 'ImportResultsSummary', array('ImportDefinitionCustomerKey','TaskResultID','ImportStatus','StartDate','EndDate','DestinationID','NumberSuccessful','NumberDuplicated','NumberErrors','TotalRows','ImportType'), $this->filter); $this->lastRequestID = $response->request_id; return $response; }
php
function status() { $this->filter = array('Property' => 'TaskResultID','SimpleOperator' => 'equals','Value' => $this->lastTaskID); $response = new ET_Get($this->authStub, 'ImportResultsSummary', array('ImportDefinitionCustomerKey','TaskResultID','ImportStatus','StartDate','EndDate','DestinationID','NumberSuccessful','NumberDuplicated','NumberErrors','TotalRows','ImportType'), $this->filter); $this->lastRequestID = $response->request_id; return $response; }
[ "function", "status", "(", ")", "{", "$", "this", "->", "filter", "=", "array", "(", "'Property'", "=>", "'TaskResultID'", ",", "'SimpleOperator'", "=>", "'equals'", ",", "'Value'", "=>", "$", "this", "->", "lastTaskID", ")", ";", "$", "response", "=", "...
This method is used to get Property Definition for a subscriber @return ET_Get Object of type ET_Get which contains http status code, response, etc from the GET SOAP service
[ "This", "method", "is", "used", "to", "get", "Property", "Definition", "for", "a", "subscriber" ]
8018468706fd796bd63d18f0af3ea8b1de088988
https://github.com/salesforce-marketingcloud/FuelSDK-PHP/blob/8018468706fd796bd63d18f0af3ea8b1de088988/src/ET_Import.php#L62-L68
train
yiisoft/yii2-gii
src/CodeFile.php
CodeFile.preview
public function preview() { if (($pos = strrpos($this->path, '.')) !== false) { $type = substr($this->path, $pos + 1); } else { $type = 'unknown'; } if ($type === 'php') { return highlight_string($this->content, true); } elseif (!in_array($type, ['jpg', 'gif', 'png', 'exe'])) { return nl2br(Html::encode($this->content)); } return false; }
php
public function preview() { if (($pos = strrpos($this->path, '.')) !== false) { $type = substr($this->path, $pos + 1); } else { $type = 'unknown'; } if ($type === 'php') { return highlight_string($this->content, true); } elseif (!in_array($type, ['jpg', 'gif', 'png', 'exe'])) { return nl2br(Html::encode($this->content)); } return false; }
[ "public", "function", "preview", "(", ")", "{", "if", "(", "(", "$", "pos", "=", "strrpos", "(", "$", "this", "->", "path", ",", "'.'", ")", ")", "!==", "false", ")", "{", "$", "type", "=", "substr", "(", "$", "this", "->", "path", ",", "$", ...
Returns preview or false if it cannot be rendered @return bool|string
[ "Returns", "preview", "or", "false", "if", "it", "cannot", "be", "rendered" ]
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/CodeFile.php#L142-L157
train
yiisoft/yii2-gii
src/CodeFile.php
CodeFile.diff
public function diff() { $type = strtolower($this->getType()); if (in_array($type, ['jpg', 'gif', 'png', 'exe'])) { return false; } elseif ($this->operation === self::OP_OVERWRITE) { return $this->renderDiff(file($this->path), $this->content); } return ''; }
php
public function diff() { $type = strtolower($this->getType()); if (in_array($type, ['jpg', 'gif', 'png', 'exe'])) { return false; } elseif ($this->operation === self::OP_OVERWRITE) { return $this->renderDiff(file($this->path), $this->content); } return ''; }
[ "public", "function", "diff", "(", ")", "{", "$", "type", "=", "strtolower", "(", "$", "this", "->", "getType", "(", ")", ")", ";", "if", "(", "in_array", "(", "$", "type", ",", "[", "'jpg'", ",", "'gif'", ",", "'png'", ",", "'exe'", "]", ")", ...
Returns diff or false if it cannot be calculated @return bool|string
[ "Returns", "diff", "or", "false", "if", "it", "cannot", "be", "calculated" ]
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/CodeFile.php#L164-L174
train
yiisoft/yii2-gii
src/CodeFile.php
CodeFile.renderDiff
private function renderDiff($lines1, $lines2) { if (!is_array($lines1)) { $lines1 = explode("\n", $lines1); } if (!is_array($lines2)) { $lines2 = explode("\n", $lines2); } foreach ($lines1 as $i => $line) { $lines1[$i] = rtrim($line, "\r\n"); } foreach ($lines2 as $i => $line) { $lines2[$i] = rtrim($line, "\r\n"); } $renderer = new DiffRendererHtmlInline(); $diff = new \Diff($lines1, $lines2); return $diff->render($renderer); }
php
private function renderDiff($lines1, $lines2) { if (!is_array($lines1)) { $lines1 = explode("\n", $lines1); } if (!is_array($lines2)) { $lines2 = explode("\n", $lines2); } foreach ($lines1 as $i => $line) { $lines1[$i] = rtrim($line, "\r\n"); } foreach ($lines2 as $i => $line) { $lines2[$i] = rtrim($line, "\r\n"); } $renderer = new DiffRendererHtmlInline(); $diff = new \Diff($lines1, $lines2); return $diff->render($renderer); }
[ "private", "function", "renderDiff", "(", "$", "lines1", ",", "$", "lines2", ")", "{", "if", "(", "!", "is_array", "(", "$", "lines1", ")", ")", "{", "$", "lines1", "=", "explode", "(", "\"\\n\"", ",", "$", "lines1", ")", ";", "}", "if", "(", "!"...
Renders diff between two sets of lines @param mixed $lines1 @param mixed $lines2 @return string
[ "Renders", "diff", "between", "two", "sets", "of", "lines" ]
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/CodeFile.php#L183-L202
train
yiisoft/yii2-gii
src/Generator.php
Generator.loadStickyAttributes
public function loadStickyAttributes() { $stickyAttributes = $this->stickyAttributes(); $path = $this->getStickyDataFile(); if (is_file($path)) { $result = json_decode(file_get_contents($path), true); if (is_array($result)) { foreach ($stickyAttributes as $name) { if (isset($result[$name])) { $this->$name = $result[$name]; } } } } }
php
public function loadStickyAttributes() { $stickyAttributes = $this->stickyAttributes(); $path = $this->getStickyDataFile(); if (is_file($path)) { $result = json_decode(file_get_contents($path), true); if (is_array($result)) { foreach ($stickyAttributes as $name) { if (isset($result[$name])) { $this->$name = $result[$name]; } } } } }
[ "public", "function", "loadStickyAttributes", "(", ")", "{", "$", "stickyAttributes", "=", "$", "this", "->", "stickyAttributes", "(", ")", ";", "$", "path", "=", "$", "this", "->", "getStickyDataFile", "(", ")", ";", "if", "(", "is_file", "(", "$", "pat...
Loads sticky attributes from an internal file and populates them into the generator. @internal
[ "Loads", "sticky", "attributes", "from", "an", "internal", "file", "and", "populates", "them", "into", "the", "generator", "." ]
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/Generator.php#L217-L231
train
yiisoft/yii2-gii
src/Generator.php
Generator.saveStickyAttributes
public function saveStickyAttributes() { $stickyAttributes = $this->stickyAttributes(); $stickyAttributes[] = 'template'; $values = []; foreach ($stickyAttributes as $name) { $values[$name] = $this->$name; } $path = $this->getStickyDataFile(); @mkdir(dirname($path), 0755, true); file_put_contents($path, json_encode($values)); }
php
public function saveStickyAttributes() { $stickyAttributes = $this->stickyAttributes(); $stickyAttributes[] = 'template'; $values = []; foreach ($stickyAttributes as $name) { $values[$name] = $this->$name; } $path = $this->getStickyDataFile(); @mkdir(dirname($path), 0755, true); file_put_contents($path, json_encode($values)); }
[ "public", "function", "saveStickyAttributes", "(", ")", "{", "$", "stickyAttributes", "=", "$", "this", "->", "stickyAttributes", "(", ")", ";", "$", "stickyAttributes", "[", "]", "=", "'template'", ";", "$", "values", "=", "[", "]", ";", "foreach", "(", ...
Saves sticky attributes into an internal file. @internal
[ "Saves", "sticky", "attributes", "into", "an", "internal", "file", "." ]
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/Generator.php#L237-L248
train
yiisoft/yii2-gii
src/Generator.php
Generator.validateClass
public function validateClass($attribute, $params) { $class = $this->$attribute; try { if (class_exists($class)) { if (isset($params['extends'])) { if (ltrim($class, '\\') !== ltrim($params['extends'], '\\') && !is_subclass_of($class, $params['extends'])) { $this->addError($attribute, "'$class' must extend from {$params['extends']} or its child class."); } } } else { $this->addError($attribute, "Class '$class' does not exist or has syntax error."); } } catch (\Exception $e) { $this->addError($attribute, "Class '$class' does not exist or has syntax error."); } }
php
public function validateClass($attribute, $params) { $class = $this->$attribute; try { if (class_exists($class)) { if (isset($params['extends'])) { if (ltrim($class, '\\') !== ltrim($params['extends'], '\\') && !is_subclass_of($class, $params['extends'])) { $this->addError($attribute, "'$class' must extend from {$params['extends']} or its child class."); } } } else { $this->addError($attribute, "Class '$class' does not exist or has syntax error."); } } catch (\Exception $e) { $this->addError($attribute, "Class '$class' does not exist or has syntax error."); } }
[ "public", "function", "validateClass", "(", "$", "attribute", ",", "$", "params", ")", "{", "$", "class", "=", "$", "this", "->", "$", "attribute", ";", "try", "{", "if", "(", "class_exists", "(", "$", "class", ")", ")", "{", "if", "(", "isset", "(...
An inline validator that checks if the attribute value refers to an existing class name. If the `extends` option is specified, it will also check if the class is a child class of the class represented by the `extends` option. @param string $attribute the attribute being validated @param array $params the validation options
[ "An", "inline", "validator", "that", "checks", "if", "the", "attribute", "value", "refers", "to", "an", "existing", "class", "name", ".", "If", "the", "extends", "option", "is", "specified", "it", "will", "also", "check", "if", "the", "class", "is", "a", ...
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/Generator.php#L347-L363
train
yiisoft/yii2-gii
src/Generator.php
Generator.validateNewClass
public function validateNewClass($attribute, $params) { $class = ltrim($this->$attribute, '\\'); if (($pos = strrpos($class, '\\')) === false) { $this->addError($attribute, "The class name must contain fully qualified namespace name."); } else { $ns = substr($class, 0, $pos); $path = Yii::getAlias('@' . str_replace('\\', '/', $ns), false); if ($path === false) { $this->addError($attribute, "The class namespace is invalid: $ns"); } elseif (!is_dir($path)) { $this->addError($attribute, "Please make sure the directory containing this class exists: $path"); } } }
php
public function validateNewClass($attribute, $params) { $class = ltrim($this->$attribute, '\\'); if (($pos = strrpos($class, '\\')) === false) { $this->addError($attribute, "The class name must contain fully qualified namespace name."); } else { $ns = substr($class, 0, $pos); $path = Yii::getAlias('@' . str_replace('\\', '/', $ns), false); if ($path === false) { $this->addError($attribute, "The class namespace is invalid: $ns"); } elseif (!is_dir($path)) { $this->addError($attribute, "Please make sure the directory containing this class exists: $path"); } } }
[ "public", "function", "validateNewClass", "(", "$", "attribute", ",", "$", "params", ")", "{", "$", "class", "=", "ltrim", "(", "$", "this", "->", "$", "attribute", ",", "'\\\\'", ")", ";", "if", "(", "(", "$", "pos", "=", "strrpos", "(", "$", "cla...
An inline validator that checks if the attribute value refers to a valid namespaced class name. The validator will check if the directory containing the new class file exist or not. @param string $attribute the attribute being validated @param array $params the validation options
[ "An", "inline", "validator", "that", "checks", "if", "the", "attribute", "value", "refers", "to", "a", "valid", "namespaced", "class", "name", ".", "The", "validator", "will", "check", "if", "the", "directory", "containing", "the", "new", "class", "file", "e...
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/Generator.php#L371-L385
train
yiisoft/yii2-gii
src/Generator.php
Generator.generateString
public function generateString($string = '', $placeholders = []) { $string = addslashes($string); if ($this->enableI18N) { // If there are placeholders, use them if (!empty($placeholders)) { $ph = ', ' . VarDumper::export($placeholders); } else { $ph = ''; } $str = "Yii::t('" . $this->messageCategory . "', '" . $string . "'" . $ph . ")"; } else { // No I18N, replace placeholders by real words, if any if (!empty($placeholders)) { $phKeys = array_map(function($word) { return '{' . $word . '}'; }, array_keys($placeholders)); $phValues = array_values($placeholders); $str = "'" . str_replace($phKeys, $phValues, $string) . "'"; } else { // No placeholders, just the given string $str = "'" . $string . "'"; } } return $str; }
php
public function generateString($string = '', $placeholders = []) { $string = addslashes($string); if ($this->enableI18N) { // If there are placeholders, use them if (!empty($placeholders)) { $ph = ', ' . VarDumper::export($placeholders); } else { $ph = ''; } $str = "Yii::t('" . $this->messageCategory . "', '" . $string . "'" . $ph . ")"; } else { // No I18N, replace placeholders by real words, if any if (!empty($placeholders)) { $phKeys = array_map(function($word) { return '{' . $word . '}'; }, array_keys($placeholders)); $phValues = array_values($placeholders); $str = "'" . str_replace($phKeys, $phValues, $string) . "'"; } else { // No placeholders, just the given string $str = "'" . $string . "'"; } } return $str; }
[ "public", "function", "generateString", "(", "$", "string", "=", "''", ",", "$", "placeholders", "=", "[", "]", ")", "{", "$", "string", "=", "addslashes", "(", "$", "string", ")", ";", "if", "(", "$", "this", "->", "enableI18N", ")", "{", "// If the...
Generates a string depending on enableI18N property @param string $string the text be generated @param array $placeholders the placeholders to use by `Yii::t()` @return string
[ "Generates", "a", "string", "depending", "on", "enableI18N", "property" ]
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/Generator.php#L495-L520
train
yiisoft/yii2-gii
src/generators/model/Generator.php
Generator.generateProperties
protected function generateProperties($table) { $properties = []; foreach ($table->columns as $column) { $columnPhpType = $column->phpType; if ($columnPhpType === 'integer') { $type = 'int'; } elseif ($columnPhpType === 'boolean') { $type = 'bool'; } else { $type = $columnPhpType; } $properties[$column->name] = [ 'type' => $type, 'name' => $column->name, 'comment' => $column->comment, ]; } return $properties; }
php
protected function generateProperties($table) { $properties = []; foreach ($table->columns as $column) { $columnPhpType = $column->phpType; if ($columnPhpType === 'integer') { $type = 'int'; } elseif ($columnPhpType === 'boolean') { $type = 'bool'; } else { $type = $columnPhpType; } $properties[$column->name] = [ 'type' => $type, 'name' => $column->name, 'comment' => $column->comment, ]; } return $properties; }
[ "protected", "function", "generateProperties", "(", "$", "table", ")", "{", "$", "properties", "=", "[", "]", ";", "foreach", "(", "$", "table", "->", "columns", "as", "$", "column", ")", "{", "$", "columnPhpType", "=", "$", "column", "->", "phpType", ...
Generates the properties for the specified table. @param \yii\db\TableSchema $table the table schema @return array the generated properties (property => type) @since 2.0.6
[ "Generates", "the", "properties", "for", "the", "specified", "table", "." ]
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/generators/model/Generator.php#L261-L281
train
yiisoft/yii2-gii
src/generators/model/Generator.php
Generator.generateRelationLink
protected function generateRelationLink($refs) { $pairs = []; foreach ($refs as $a => $b) { $pairs[] = "'$a' => '$b'"; } return '[' . implode(', ', $pairs) . ']'; }
php
protected function generateRelationLink($refs) { $pairs = []; foreach ($refs as $a => $b) { $pairs[] = "'$a' => '$b'"; } return '[' . implode(', ', $pairs) . ']'; }
[ "protected", "function", "generateRelationLink", "(", "$", "refs", ")", "{", "$", "pairs", "=", "[", "]", ";", "foreach", "(", "$", "refs", "as", "$", "a", "=>", "$", "b", ")", "{", "$", "pairs", "[", "]", "=", "\"'$a' => '$b'\"", ";", "}", "return...
Generates the link parameter to be used in generating the relation declaration. @param array $refs reference constraint @return string the generated link parameter.
[ "Generates", "the", "link", "parameter", "to", "be", "used", "in", "generating", "the", "relation", "declaration", "." ]
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/generators/model/Generator.php#L635-L643
train
yiisoft/yii2-gii
src/generators/model/Generator.php
Generator.checkJunctionTable
protected function checkJunctionTable($table) { if (count($table->foreignKeys) < 2) { return false; } $uniqueKeys = [$table->primaryKey]; try { $uniqueKeys = array_merge($uniqueKeys, $this->getDbConnection()->getSchema()->findUniqueIndexes($table)); } catch (NotSupportedException $e) { // ignore } $result = []; // find all foreign key pairs that have all columns in an unique constraint $foreignKeys = array_values($table->foreignKeys); $foreignKeysCount = count($foreignKeys); for ($i = 0; $i < $foreignKeysCount; $i++) { $firstColumns = $foreignKeys[$i]; unset($firstColumns[0]); for ($j = $i + 1; $j < $foreignKeysCount; $j++) { $secondColumns = $foreignKeys[$j]; unset($secondColumns[0]); $fks = array_merge(array_keys($firstColumns), array_keys($secondColumns)); foreach ($uniqueKeys as $uniqueKey) { if (count(array_diff(array_merge($uniqueKey, $fks), array_intersect($uniqueKey, $fks))) === 0) { // save the foreign key pair $result[] = [$foreignKeys[$i], $foreignKeys[$j]]; break; } } } } return empty($result) ? false : $result; }
php
protected function checkJunctionTable($table) { if (count($table->foreignKeys) < 2) { return false; } $uniqueKeys = [$table->primaryKey]; try { $uniqueKeys = array_merge($uniqueKeys, $this->getDbConnection()->getSchema()->findUniqueIndexes($table)); } catch (NotSupportedException $e) { // ignore } $result = []; // find all foreign key pairs that have all columns in an unique constraint $foreignKeys = array_values($table->foreignKeys); $foreignKeysCount = count($foreignKeys); for ($i = 0; $i < $foreignKeysCount; $i++) { $firstColumns = $foreignKeys[$i]; unset($firstColumns[0]); for ($j = $i + 1; $j < $foreignKeysCount; $j++) { $secondColumns = $foreignKeys[$j]; unset($secondColumns[0]); $fks = array_merge(array_keys($firstColumns), array_keys($secondColumns)); foreach ($uniqueKeys as $uniqueKey) { if (count(array_diff(array_merge($uniqueKey, $fks), array_intersect($uniqueKey, $fks))) === 0) { // save the foreign key pair $result[] = [$foreignKeys[$i], $foreignKeys[$j]]; break; } } } } return empty($result) ? false : $result; }
[ "protected", "function", "checkJunctionTable", "(", "$", "table", ")", "{", "if", "(", "count", "(", "$", "table", "->", "foreignKeys", ")", "<", "2", ")", "{", "return", "false", ";", "}", "$", "uniqueKeys", "=", "[", "$", "table", "->", "primaryKey",...
Checks if the given table is a junction table, that is it has at least one pair of unique foreign keys. @param \yii\db\TableSchema the table being checked @return array|bool all unique foreign key pairs if the table is a junction table, or false if the table is not a junction table.
[ "Checks", "if", "the", "given", "table", "is", "a", "junction", "table", "that", "is", "it", "has", "at", "least", "one", "pair", "of", "unique", "foreign", "keys", "." ]
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/generators/model/Generator.php#L651-L686
train
yiisoft/yii2-gii
src/generators/model/Generator.php
Generator.generateQueryClassName
protected function generateQueryClassName($modelClassName) { $queryClassName = $this->queryClass; if (empty($queryClassName) || strpos($this->tableName, '*') !== false) { $queryClassName = $modelClassName . 'Query'; } return $queryClassName; }
php
protected function generateQueryClassName($modelClassName) { $queryClassName = $this->queryClass; if (empty($queryClassName) || strpos($this->tableName, '*') !== false) { $queryClassName = $modelClassName . 'Query'; } return $queryClassName; }
[ "protected", "function", "generateQueryClassName", "(", "$", "modelClassName", ")", "{", "$", "queryClassName", "=", "$", "this", "->", "queryClass", ";", "if", "(", "empty", "(", "$", "queryClassName", ")", "||", "strpos", "(", "$", "this", "->", "tableName...
Generates a query class name from the specified model class name. @param string $modelClassName model class name @return string generated class name
[ "Generates", "a", "query", "class", "name", "from", "the", "specified", "model", "class", "name", "." ]
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/generators/model/Generator.php#L927-L934
train
yiisoft/yii2-gii
src/controllers/DefaultController.php
DefaultController.loadGenerator
protected function loadGenerator($id) { if (isset($this->module->generators[$id])) { $this->generator = $this->module->generators[$id]; $this->generator->loadStickyAttributes(); $this->generator->load(Yii::$app->request->post()); return $this->generator; } throw new NotFoundHttpException("Code generator not found: $id"); }
php
protected function loadGenerator($id) { if (isset($this->module->generators[$id])) { $this->generator = $this->module->generators[$id]; $this->generator->loadStickyAttributes(); $this->generator->load(Yii::$app->request->post()); return $this->generator; } throw new NotFoundHttpException("Code generator not found: $id"); }
[ "protected", "function", "loadGenerator", "(", "$", "id", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "module", "->", "generators", "[", "$", "id", "]", ")", ")", "{", "$", "this", "->", "generator", "=", "$", "this", "->", "module", "->"...
Loads the generator with the specified ID. @param string $id the ID of the generator to be loaded. @return \yii\gii\Generator the loaded generator @throws NotFoundHttpException
[ "Loads", "the", "generator", "with", "the", "specified", "ID", "." ]
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/controllers/DefaultController.php#L132-L142
train
yiisoft/yii2-gii
src/generators/crud/Generator.php
Generator.generateActiveSearchField
public function generateActiveSearchField($attribute) { $tableSchema = $this->getTableSchema(); if ($tableSchema === false) { return "\$form->field(\$model, '$attribute')"; } $column = $tableSchema->columns[$attribute]; if ($column->phpType === 'boolean') { return "\$form->field(\$model, '$attribute')->checkbox()"; } return "\$form->field(\$model, '$attribute')"; }
php
public function generateActiveSearchField($attribute) { $tableSchema = $this->getTableSchema(); if ($tableSchema === false) { return "\$form->field(\$model, '$attribute')"; } $column = $tableSchema->columns[$attribute]; if ($column->phpType === 'boolean') { return "\$form->field(\$model, '$attribute')->checkbox()"; } return "\$form->field(\$model, '$attribute')"; }
[ "public", "function", "generateActiveSearchField", "(", "$", "attribute", ")", "{", "$", "tableSchema", "=", "$", "this", "->", "getTableSchema", "(", ")", ";", "if", "(", "$", "tableSchema", "===", "false", ")", "{", "return", "\"\\$form->field(\\$model, '$attr...
Generates code for active search field @param string $attribute @return string
[ "Generates", "code", "for", "active", "search", "field" ]
eff1dc599f577420d569bdc67d8cc689148e9818
https://github.com/yiisoft/yii2-gii/blob/eff1dc599f577420d569bdc67d8cc689148e9818/src/generators/crud/Generator.php#L286-L299
train
rainlab/blog-plugin
models/Post.php
Post.filterFields
public function filterFields($fields, $context = null) { if (!isset($fields->published, $fields->published_at)) { return; } $user = BackendAuth::getUser(); if (!$user->hasAnyAccess(['rainlab.blog.access_publish'])) { $fields->published->hidden = true; $fields->published_at->hidden = true; } else { $fields->published->hidden = false; $fields->published_at->hidden = false; } }
php
public function filterFields($fields, $context = null) { if (!isset($fields->published, $fields->published_at)) { return; } $user = BackendAuth::getUser(); if (!$user->hasAnyAccess(['rainlab.blog.access_publish'])) { $fields->published->hidden = true; $fields->published_at->hidden = true; } else { $fields->published->hidden = false; $fields->published_at->hidden = false; } }
[ "public", "function", "filterFields", "(", "$", "fields", ",", "$", "context", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "fields", "->", "published", ",", "$", "fields", "->", "published_at", ")", ")", "{", "return", ";", "}", "$", ...
Limit visibility of the published-button @param $fields @param null $context @return void
[ "Limit", "visibility", "of", "the", "published", "-", "button" ]
22ffcbd5a076f621298ae6489f00264dd47ca66e
https://github.com/rainlab/blog-plugin/blob/22ffcbd5a076f621298ae6489f00264dd47ca66e/models/Post.php#L109-L125
train
rainlab/blog-plugin
models/Post.php
Post.setUrl
public function setUrl($pageName, $controller) { $params = [ 'id' => $this->id, 'slug' => $this->slug ]; $params['category'] = $this->categories->count() ? $this->categories->first()->slug : null; // Expose published year, month and day as URL parameters. if ($this->published) { $params['year'] = $this->published_at->format('Y'); $params['month'] = $this->published_at->format('m'); $params['day'] = $this->published_at->format('d'); } return $this->url = $controller->pageUrl($pageName, $params); }
php
public function setUrl($pageName, $controller) { $params = [ 'id' => $this->id, 'slug' => $this->slug ]; $params['category'] = $this->categories->count() ? $this->categories->first()->slug : null; // Expose published year, month and day as URL parameters. if ($this->published) { $params['year'] = $this->published_at->format('Y'); $params['month'] = $this->published_at->format('m'); $params['day'] = $this->published_at->format('d'); } return $this->url = $controller->pageUrl($pageName, $params); }
[ "public", "function", "setUrl", "(", "$", "pageName", ",", "$", "controller", ")", "{", "$", "params", "=", "[", "'id'", "=>", "$", "this", "->", "id", ",", "'slug'", "=>", "$", "this", "->", "slug", "]", ";", "$", "params", "[", "'category'", "]",...
Sets the "url" attribute with a URL to this object. @param string $pageName @param Cms\Classes\Controller $controller
[ "Sets", "the", "url", "attribute", "with", "a", "URL", "to", "this", "object", "." ]
22ffcbd5a076f621298ae6489f00264dd47ca66e
https://github.com/rainlab/blog-plugin/blob/22ffcbd5a076f621298ae6489f00264dd47ca66e/models/Post.php#L146-L163
train
rainlab/blog-plugin
models/Post.php
Post.scopeFilterCategories
public function scopeFilterCategories($query, $categories) { return $query->whereHas('categories', function($q) use ($categories) { $q->whereIn('id', $categories); }); }
php
public function scopeFilterCategories($query, $categories) { return $query->whereHas('categories', function($q) use ($categories) { $q->whereIn('id', $categories); }); }
[ "public", "function", "scopeFilterCategories", "(", "$", "query", ",", "$", "categories", ")", "{", "return", "$", "query", "->", "whereHas", "(", "'categories'", ",", "function", "(", "$", "q", ")", "use", "(", "$", "categories", ")", "{", "$", "q", "...
Allows filtering for specifc categories. @param Illuminate\Query\Builder $query QueryBuilder @param array $categories List of category ids @return Illuminate\Query\Builder QueryBuilder
[ "Allows", "filtering", "for", "specifc", "categories", "." ]
22ffcbd5a076f621298ae6489f00264dd47ca66e
https://github.com/rainlab/blog-plugin/blob/22ffcbd5a076f621298ae6489f00264dd47ca66e/models/Post.php#L327-L332
train
rainlab/blog-plugin
models/Post.php
Post.scopeApplySibling
public function scopeApplySibling($query, $options = []) { if (!is_array($options)) { $options = ['direction' => $options]; } extract(array_merge([ 'direction' => 'next', 'attribute' => 'published_at' ], $options)); $isPrevious = in_array($direction, ['previous', -1]); $directionOrder = $isPrevious ? 'asc' : 'desc'; $directionOperator = $isPrevious ? '>' : '<'; $query->where('id', '<>', $this->id); if (!is_null($this->$attribute)) { $query->where($attribute, $directionOperator, $this->$attribute); } return $query->orderBy($attribute, $directionOrder); }
php
public function scopeApplySibling($query, $options = []) { if (!is_array($options)) { $options = ['direction' => $options]; } extract(array_merge([ 'direction' => 'next', 'attribute' => 'published_at' ], $options)); $isPrevious = in_array($direction, ['previous', -1]); $directionOrder = $isPrevious ? 'asc' : 'desc'; $directionOperator = $isPrevious ? '>' : '<'; $query->where('id', '<>', $this->id); if (!is_null($this->$attribute)) { $query->where($attribute, $directionOperator, $this->$attribute); } return $query->orderBy($attribute, $directionOrder); }
[ "public", "function", "scopeApplySibling", "(", "$", "query", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "is_array", "(", "$", "options", ")", ")", "{", "$", "options", "=", "[", "'direction'", "=>", "$", "options", "]", ";", "}"...
Apply a constraint to the query to find the nearest sibling // Get the next post Post::applySibling()->first(); // Get the previous post Post::applySibling(-1)->first(); // Get the previous post, ordered by the ID attribute instead Post::applySibling(['direction' => -1, 'attribute' => 'id'])->first(); @param $query @param array $options @return
[ "Apply", "a", "constraint", "to", "the", "query", "to", "find", "the", "nearest", "sibling" ]
22ffcbd5a076f621298ae6489f00264dd47ca66e
https://github.com/rainlab/blog-plugin/blob/22ffcbd5a076f621298ae6489f00264dd47ca66e/models/Post.php#L397-L419
train
rainlab/blog-plugin
models/Post.php
Post.getPostPageUrl
protected static function getPostPageUrl($pageCode, $category, $theme) { $page = CmsPage::loadCached($theme, $pageCode); if (!$page) { return; } $properties = $page->getComponentProperties('blogPost'); if (!isset($properties['slug'])) { return; } /* * Extract the routing parameter name from the category filter * eg: {{ :someRouteParam }} */ if (!preg_match('/^\{\{([^\}]+)\}\}$/', $properties['slug'], $matches)) { return; } $paramName = substr(trim($matches[1]), 1); $params = [ $paramName => $category->slug, 'year' => $category->published_at->format('Y'), 'month' => $category->published_at->format('m'), 'day' => $category->published_at->format('d') ]; $url = CmsPage::url($page->getBaseFileName(), $params); return $url; }
php
protected static function getPostPageUrl($pageCode, $category, $theme) { $page = CmsPage::loadCached($theme, $pageCode); if (!$page) { return; } $properties = $page->getComponentProperties('blogPost'); if (!isset($properties['slug'])) { return; } /* * Extract the routing parameter name from the category filter * eg: {{ :someRouteParam }} */ if (!preg_match('/^\{\{([^\}]+)\}\}$/', $properties['slug'], $matches)) { return; } $paramName = substr(trim($matches[1]), 1); $params = [ $paramName => $category->slug, 'year' => $category->published_at->format('Y'), 'month' => $category->published_at->format('m'), 'day' => $category->published_at->format('d') ]; $url = CmsPage::url($page->getBaseFileName(), $params); return $url; }
[ "protected", "static", "function", "getPostPageUrl", "(", "$", "pageCode", ",", "$", "category", ",", "$", "theme", ")", "{", "$", "page", "=", "CmsPage", "::", "loadCached", "(", "$", "theme", ",", "$", "pageCode", ")", ";", "if", "(", "!", "$", "pa...
Returns URL of a post page. @param $pageCode @param $category @param $theme
[ "Returns", "URL", "of", "a", "post", "page", "." ]
22ffcbd5a076f621298ae6489f00264dd47ca66e
https://github.com/rainlab/blog-plugin/blob/22ffcbd5a076f621298ae6489f00264dd47ca66e/models/Post.php#L641-L671
train
rainlab/blog-plugin
models/Category.php
Category.setUrl
public function setUrl($pageName, $controller) { $params = [ 'id' => $this->id, 'slug' => $this->slug ]; return $this->url = $controller->pageUrl($pageName, $params, false); }
php
public function setUrl($pageName, $controller) { $params = [ 'id' => $this->id, 'slug' => $this->slug ]; return $this->url = $controller->pageUrl($pageName, $params, false); }
[ "public", "function", "setUrl", "(", "$", "pageName", ",", "$", "controller", ")", "{", "$", "params", "=", "[", "'id'", "=>", "$", "this", "->", "id", ",", "'slug'", "=>", "$", "this", "->", "slug", "]", ";", "return", "$", "this", "->", "url", ...
Sets the "url" attribute with a URL to this object @param string $pageName @param Cms\Classes\Controller $controller
[ "Sets", "the", "url", "attribute", "with", "a", "URL", "to", "this", "object" ]
22ffcbd5a076f621298ae6489f00264dd47ca66e
https://github.com/rainlab/blog-plugin/blob/22ffcbd5a076f621298ae6489f00264dd47ca66e/models/Category.php#L86-L94
train
rainlab/blog-plugin
models/Category.php
Category.getCategoryPageUrl
protected static function getCategoryPageUrl($pageCode, $category, $theme) { $page = CmsPage::loadCached($theme, $pageCode); if (!$page) { return; } $properties = $page->getComponentProperties('blogPosts'); if (!isset($properties['categoryFilter'])) { return; } /* * Extract the routing parameter name from the category filter * eg: {{ :someRouteParam }} */ if (!preg_match('/^\{\{([^\}]+)\}\}$/', $properties['categoryFilter'], $matches)) { return; } $paramName = substr(trim($matches[1]), 1); $url = CmsPage::url($page->getBaseFileName(), [$paramName => $category->slug]); return $url; }
php
protected static function getCategoryPageUrl($pageCode, $category, $theme) { $page = CmsPage::loadCached($theme, $pageCode); if (!$page) { return; } $properties = $page->getComponentProperties('blogPosts'); if (!isset($properties['categoryFilter'])) { return; } /* * Extract the routing parameter name from the category filter * eg: {{ :someRouteParam }} */ if (!preg_match('/^\{\{([^\}]+)\}\}$/', $properties['categoryFilter'], $matches)) { return; } $paramName = substr(trim($matches[1]), 1); $url = CmsPage::url($page->getBaseFileName(), [$paramName => $category->slug]); return $url; }
[ "protected", "static", "function", "getCategoryPageUrl", "(", "$", "pageCode", ",", "$", "category", ",", "$", "theme", ")", "{", "$", "page", "=", "CmsPage", "::", "loadCached", "(", "$", "theme", ",", "$", "pageCode", ")", ";", "if", "(", "!", "$", ...
Returns URL of a category page. @param $pageCode @param $category @param $theme
[ "Returns", "URL", "of", "a", "category", "page", "." ]
22ffcbd5a076f621298ae6489f00264dd47ca66e
https://github.com/rainlab/blog-plugin/blob/22ffcbd5a076f621298ae6489f00264dd47ca66e/models/Category.php#L282-L306
train
rainlab/blog-plugin
Plugin.php
Plugin.register
public function register() { /* * Register the image tag processing callback */ TagProcessor::instance()->registerCallback(function($input, $preview) { if (!$preview) { return $input; } return preg_replace('|\<img src="image" alt="([0-9]+)"([^>]*)\/>|m', '<span class="image-placeholder" data-index="$1"> <span class="upload-dropzone"> <span class="label">Click or drop an image...</span> <span class="indicator"></span> </span> </span>', $input); }); }
php
public function register() { /* * Register the image tag processing callback */ TagProcessor::instance()->registerCallback(function($input, $preview) { if (!$preview) { return $input; } return preg_replace('|\<img src="image" alt="([0-9]+)"([^>]*)\/>|m', '<span class="image-placeholder" data-index="$1"> <span class="upload-dropzone"> <span class="label">Click or drop an image...</span> <span class="indicator"></span> </span> </span>', $input); }); }
[ "public", "function", "register", "(", ")", "{", "/*\n * Register the image tag processing callback\n */", "TagProcessor", "::", "instance", "(", ")", "->", "registerCallback", "(", "function", "(", "$", "input", ",", "$", "preview", ")", "{", "if", ...
Register method, called when the plugin is first registered.
[ "Register", "method", "called", "when", "the", "plugin", "is", "first", "registered", "." ]
22ffcbd5a076f621298ae6489f00264dd47ca66e
https://github.com/rainlab/blog-plugin/blob/22ffcbd5a076f621298ae6489f00264dd47ca66e/Plugin.php#L118-L137
train
rainlab/blog-plugin
formwidgets/MLBlogMarkdown.php
MLBlogMarkdown.getSaveValue
public function getSaveValue($value) { $localeData = $this->getLocaleSaveData(); /* * Set the translated values to the model */ if ($this->model->methodExists('setAttributeTranslated')) { foreach ($localeData as $locale => $value) { $this->model->setAttributeTranslated('content', $value, $locale); $this->model->setAttributeTranslated( 'content_html', Post::formatHtml($value), $locale ); } } return array_get($localeData, $this->defaultLocale->code, $value); }
php
public function getSaveValue($value) { $localeData = $this->getLocaleSaveData(); /* * Set the translated values to the model */ if ($this->model->methodExists('setAttributeTranslated')) { foreach ($localeData as $locale => $value) { $this->model->setAttributeTranslated('content', $value, $locale); $this->model->setAttributeTranslated( 'content_html', Post::formatHtml($value), $locale ); } } return array_get($localeData, $this->defaultLocale->code, $value); }
[ "public", "function", "getSaveValue", "(", "$", "value", ")", "{", "$", "localeData", "=", "$", "this", "->", "getLocaleSaveData", "(", ")", ";", "/*\n * Set the translated values to the model\n */", "if", "(", "$", "this", "->", "model", "->", "me...
Returns an array of translated values for this field @param $value @return array
[ "Returns", "an", "array", "of", "translated", "values", "for", "this", "field" ]
22ffcbd5a076f621298ae6489f00264dd47ca66e
https://github.com/rainlab/blog-plugin/blob/22ffcbd5a076f621298ae6489f00264dd47ca66e/formwidgets/MLBlogMarkdown.php#L65-L85
train
Bogdaan/viber-bot-php
src/Api/Response.php
Response.create
public static function create(\GuzzleHttp\Psr7\Response $response) { // - validate body $data = json_decode($response->getBody(), true, 512, JSON_BIGINT_AS_STRING); if (empty($data)) { throw new ApiException('Invalid response body'); } // - validate internal data if (isset($data['status'])) { if ($data['status'] != 0) { throw new ApiException('Remote error: ' . (isset($data['status_message']) ? $data['status_message'] : '-'), $data['status']); } $item = new self(); $item->data = $data; return $item; } throw new ApiException('Invalid response json'); }
php
public static function create(\GuzzleHttp\Psr7\Response $response) { // - validate body $data = json_decode($response->getBody(), true, 512, JSON_BIGINT_AS_STRING); if (empty($data)) { throw new ApiException('Invalid response body'); } // - validate internal data if (isset($data['status'])) { if ($data['status'] != 0) { throw new ApiException('Remote error: ' . (isset($data['status_message']) ? $data['status_message'] : '-'), $data['status']); } $item = new self(); $item->data = $data; return $item; } throw new ApiException('Invalid response json'); }
[ "public", "static", "function", "create", "(", "\\", "GuzzleHttp", "\\", "Psr7", "\\", "Response", "$", "response", ")", "{", "// - validate body", "$", "data", "=", "json_decode", "(", "$", "response", "->", "getBody", "(", ")", ",", "true", ",", "512", ...
Create api response from http-response @param \GuzzleHttp\Psr7\Response $response network response @return \Viber\Api\Response @throws \Viber\Api\Exception\ApiException
[ "Create", "api", "response", "from", "http", "-", "response" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Api/Response.php#L28-L47
train
Bogdaan/viber-bot-php
src/Api/Message/Factory.php
Factory.makeFromApi
public static function makeFromApi(array $data) { if (isset($data['type'])) { switch ($data['type']) { case Type::TEXT: return new Text($data); case Type::URL: return new Url($data); case Type::PICTURE: return new Picture($data); case Type::CONTACT: return new Contact($data); case Type::VIDEO: return new Video($data); case Type::FILE: return new File($data); case Type::STICKER: return new Sticker($data); case Type::LOCATION: return new Location($data); } } throw new ApiException('Unknow message data'); }
php
public static function makeFromApi(array $data) { if (isset($data['type'])) { switch ($data['type']) { case Type::TEXT: return new Text($data); case Type::URL: return new Url($data); case Type::PICTURE: return new Picture($data); case Type::CONTACT: return new Contact($data); case Type::VIDEO: return new Video($data); case Type::FILE: return new File($data); case Type::STICKER: return new Sticker($data); case Type::LOCATION: return new Location($data); } } throw new ApiException('Unknow message data'); }
[ "public", "static", "function", "makeFromApi", "(", "array", "$", "data", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "'type'", "]", ")", ")", "{", "switch", "(", "$", "data", "[", "'type'", "]", ")", "{", "case", "Type", "::", "TEXT", "...
Make certain message from api-request array @param array $data api request data @return \Viber\Api\Message
[ "Make", "certain", "message", "from", "api", "-", "request", "array" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Api/Message/Factory.php#L20-L43
train
Bogdaan/viber-bot-php
src/Bot.php
Bot.on
public function on(\Closure $checker, \Closure $handler) { $this->managers[] = new Manager($checker, $handler); return $this; }
php
public function on(\Closure $checker, \Closure $handler) { $this->managers[] = new Manager($checker, $handler); return $this; }
[ "public", "function", "on", "(", "\\", "Closure", "$", "checker", ",", "\\", "Closure", "$", "handler", ")", "{", "$", "this", "->", "managers", "[", "]", "=", "new", "Manager", "(", "$", "checker", ",", "$", "handler", ")", ";", "return", "$", "th...
Register event handler callback @param \Closure $checker checker function @param \Closure $handler handler function @return \Viber\Bot
[ "Register", "event", "handler", "callback" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Bot.php#L72-L77
train
Bogdaan/viber-bot-php
src/Bot.php
Bot.onText
public function onText($regexp, \Closure $handler) { $this->managers[] = new Manager(function (Event $event) use ($regexp) { return ( $event instanceof \Viber\Api\Event\Message && $event->getMessage() instanceof \Viber\Api\Message\Text && preg_match($regexp, $event->getMessage()->getText()) ); }, $handler); return $this; }
php
public function onText($regexp, \Closure $handler) { $this->managers[] = new Manager(function (Event $event) use ($regexp) { return ( $event instanceof \Viber\Api\Event\Message && $event->getMessage() instanceof \Viber\Api\Message\Text && preg_match($regexp, $event->getMessage()->getText()) ); }, $handler); return $this; }
[ "public", "function", "onText", "(", "$", "regexp", ",", "\\", "Closure", "$", "handler", ")", "{", "$", "this", "->", "managers", "[", "]", "=", "new", "Manager", "(", "function", "(", "Event", "$", "event", ")", "use", "(", "$", "regexp", ")", "{...
Register text message handler by PCRE @param string $regexp valid regular expression @param Closure $handler event handler @return \Viber\Bot
[ "Register", "text", "message", "handler", "by", "PCRE" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Bot.php#L86-L97
train
Bogdaan/viber-bot-php
src/Bot.php
Bot.onSubscribe
public function onSubscribe(\Closure $handler) { $this->managers[] = new Manager(function (Event $event) { return ($event instanceof \Viber\Api\Event\Subscribed); }, $handler); return $this; }
php
public function onSubscribe(\Closure $handler) { $this->managers[] = new Manager(function (Event $event) { return ($event instanceof \Viber\Api\Event\Subscribed); }, $handler); return $this; }
[ "public", "function", "onSubscribe", "(", "\\", "Closure", "$", "handler", ")", "{", "$", "this", "->", "managers", "[", "]", "=", "new", "Manager", "(", "function", "(", "Event", "$", "event", ")", "{", "return", "(", "$", "event", "instanceof", "\\",...
Register subscrive event handler @param Closure $handler valid function @return \Viber\Bot
[ "Register", "subscrive", "event", "handler" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Bot.php#L105-L112
train
Bogdaan/viber-bot-php
src/Bot.php
Bot.onConversation
public function onConversation(\Closure $handler) { $this->managers[] = new Manager(function (Event $event) { return ($event instanceof \Viber\Api\Event\Conversation); }, $handler); return $this; }
php
public function onConversation(\Closure $handler) { $this->managers[] = new Manager(function (Event $event) { return ($event instanceof \Viber\Api\Event\Conversation); }, $handler); return $this; }
[ "public", "function", "onConversation", "(", "\\", "Closure", "$", "handler", ")", "{", "$", "this", "->", "managers", "[", "]", "=", "new", "Manager", "(", "function", "(", "Event", "$", "event", ")", "{", "return", "(", "$", "event", "instanceof", "\...
Register conversation event handler @param Closure $handler valid function @return \Viber\Bot
[ "Register", "conversation", "event", "handler" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Bot.php#L120-L127
train
Bogdaan/viber-bot-php
src/Bot.php
Bot.onPicture
public function onPicture(\Closure $handler) { $this->managers[] = new Manager(function (Event $event) { return ( $event instanceof \Viber\Api\Event\Message && $event->getMessage() instanceof \Viber\Api\Message\Picture ); }, $handler); return $this; }
php
public function onPicture(\Closure $handler) { $this->managers[] = new Manager(function (Event $event) { return ( $event instanceof \Viber\Api\Event\Message && $event->getMessage() instanceof \Viber\Api\Message\Picture ); }, $handler); return $this; }
[ "public", "function", "onPicture", "(", "\\", "Closure", "$", "handler", ")", "{", "$", "this", "->", "managers", "[", "]", "=", "new", "Manager", "(", "function", "(", "Event", "$", "event", ")", "{", "return", "(", "$", "event", "instanceof", "\\", ...
Register picture message handler @param Closure $handler event handler @return \Viber\Bot
[ "Register", "picture", "message", "handler" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Bot.php#L135-L145
train
Bogdaan/viber-bot-php
src/Bot.php
Bot.getSignHeaderValue
public function getSignHeaderValue() { $signature = ''; if (isset($_SERVER['HTTP_X_VIBER_CONTENT_SIGNATURE'])) { $signature = $_SERVER['HTTP_X_VIBER_CONTENT_SIGNATURE']; } elseif (isset($_GET['sig'])) { $signature = $_GET['sig']; } if (empty($signature)) { throw new \RuntimeException('Signature header not found', 1); } return $signature; }
php
public function getSignHeaderValue() { $signature = ''; if (isset($_SERVER['HTTP_X_VIBER_CONTENT_SIGNATURE'])) { $signature = $_SERVER['HTTP_X_VIBER_CONTENT_SIGNATURE']; } elseif (isset($_GET['sig'])) { $signature = $_GET['sig']; } if (empty($signature)) { throw new \RuntimeException('Signature header not found', 1); } return $signature; }
[ "public", "function", "getSignHeaderValue", "(", ")", "{", "$", "signature", "=", "''", ";", "if", "(", "isset", "(", "$", "_SERVER", "[", "'HTTP_X_VIBER_CONTENT_SIGNATURE'", "]", ")", ")", "{", "$", "signature", "=", "$", "_SERVER", "[", "'HTTP_X_VIBER_CONT...
Get signature header @throws \RuntimeException @return string
[ "Get", "signature", "header" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Bot.php#L153-L166
train
Bogdaan/viber-bot-php
src/Bot.php
Bot.run
public function run($event = null) { if (null === $event) { // check body $eventBody = $this->getInputBody(); if (!Signature::isValid( $this->getSignHeaderValue(), $eventBody, $this->getClient()->getToken() )) { throw new \RuntimeException('Invalid signature header', 2); } // check json $eventBody = json_decode($eventBody, true); if (json_last_error() || empty($eventBody) || !is_array($eventBody)) { throw new \RuntimeException('Invalid json request', 3); } // make event from json $event = Factory::makeFromApi($eventBody); } elseif (!$event instanceof Event) { throw new \RuntimeException('Event must be instance of \Viber\Api\Event', 4); } // main bot loop foreach ($this->managers as $manager) { if ($manager->isMatch($event)) { $returnValue = $manager->runHandler($event); if ($returnValue && $returnValue instanceof Entity) { // reply with entity $this->outputEntity($returnValue); } break; } } return $this; }
php
public function run($event = null) { if (null === $event) { // check body $eventBody = $this->getInputBody(); if (!Signature::isValid( $this->getSignHeaderValue(), $eventBody, $this->getClient()->getToken() )) { throw new \RuntimeException('Invalid signature header', 2); } // check json $eventBody = json_decode($eventBody, true); if (json_last_error() || empty($eventBody) || !is_array($eventBody)) { throw new \RuntimeException('Invalid json request', 3); } // make event from json $event = Factory::makeFromApi($eventBody); } elseif (!$event instanceof Event) { throw new \RuntimeException('Event must be instance of \Viber\Api\Event', 4); } // main bot loop foreach ($this->managers as $manager) { if ($manager->isMatch($event)) { $returnValue = $manager->runHandler($event); if ($returnValue && $returnValue instanceof Entity) { // reply with entity $this->outputEntity($returnValue); } break; } } return $this; }
[ "public", "function", "run", "(", "$", "event", "=", "null", ")", "{", "if", "(", "null", "===", "$", "event", ")", "{", "// check body", "$", "eventBody", "=", "$", "this", "->", "getInputBody", "(", ")", ";", "if", "(", "!", "Signature", "::", "i...
Start bot process @throws \RuntimeException @param \Viber\Api\Event $event start bot with some event @return \Viber\Bot
[ "Start", "bot", "process" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Bot.php#L197-L232
train
Bogdaan/viber-bot-php
src/Api/Signature.php
Signature.isValid
public static function isValid($sign, $messageBody, $token) { return hash_equals($sign, self::make($messageBody, $token)); }
php
public static function isValid($sign, $messageBody, $token) { return hash_equals($sign, self::make($messageBody, $token)); }
[ "public", "static", "function", "isValid", "(", "$", "sign", ",", "$", "messageBody", ",", "$", "token", ")", "{", "return", "hash_equals", "(", "$", "sign", ",", "self", "::", "make", "(", "$", "messageBody", ",", "$", "token", ")", ")", ";", "}" ]
Is message signatore valid? @param string $sign from request headers @param string $messageBody from request body @param string $token bot access token @return boolean valid or not
[ "Is", "message", "signatore", "valid?" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Api/Signature.php#L32-L35
train
Bogdaan/viber-bot-php
src/Client.php
Client.call
public function call($method, $data) { try { $response = $this->http->request('POST', $method, [ 'headers' => [ 'X-Viber-Auth-Token' => $this->token ], 'json' => $data ]); return \Viber\Api\Response::create($response); } catch (\RuntimeException $e) { throw new ApiException($e->getMessage(), $e->getCode(), $e); } }
php
public function call($method, $data) { try { $response = $this->http->request('POST', $method, [ 'headers' => [ 'X-Viber-Auth-Token' => $this->token ], 'json' => $data ]); return \Viber\Api\Response::create($response); } catch (\RuntimeException $e) { throw new ApiException($e->getMessage(), $e->getCode(), $e); } }
[ "public", "function", "call", "(", "$", "method", ",", "$", "data", ")", "{", "try", "{", "$", "response", "=", "$", "this", "->", "http", "->", "request", "(", "'POST'", ",", "$", "method", ",", "[", "'headers'", "=>", "[", "'X-Viber-Auth-Token'", "...
Call api method @throws \Viber\Api\Exception\ApiException @param string $method method name @param mixed $data method data @return \Viber\Api\Response
[ "Call", "api", "method" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Client.php#L80-L93
train
Bogdaan/viber-bot-php
src/Client.php
Client.setWebhook
public function setWebhook($url, $eventTypes = null) { if (null === $eventTypes) { $eventTypes = [Type::SUBSCRIBED, Type::CONVERSATION, Type::MESSAGE]; } if (empty($url) || !preg_match('|^https://.*|s', $url)) { throw new ApiException('Invalid webhook url: ' . $url); } return $this->call('set_webhook', [ 'url' => $url, 'event_types' => $eventTypes, ]); }
php
public function setWebhook($url, $eventTypes = null) { if (null === $eventTypes) { $eventTypes = [Type::SUBSCRIBED, Type::CONVERSATION, Type::MESSAGE]; } if (empty($url) || !preg_match('|^https://.*|s', $url)) { throw new ApiException('Invalid webhook url: ' . $url); } return $this->call('set_webhook', [ 'url' => $url, 'event_types' => $eventTypes, ]); }
[ "public", "function", "setWebhook", "(", "$", "url", ",", "$", "eventTypes", "=", "null", ")", "{", "if", "(", "null", "===", "$", "eventTypes", ")", "{", "$", "eventTypes", "=", "[", "Type", "::", "SUBSCRIBED", ",", "Type", "::", "CONVERSATION", ",", ...
Set webhook url. For security reasons only URLs with valid and * official SSL certificate from a trusted CA will be allowed. @see \Viber\Api\Event\Type @throws \Viber\Api\Exception\ApiException @param string $url webhook url @param array|null $eventTypes subscribe to certain events @return \Viber\Api\Response
[ "Set", "webhook", "url", "." ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Client.php#L107-L120
train
Bogdaan/viber-bot-php
src/Api/Entity.php
Entity.toApiArray
public function toApiArray() { $entity = $this->toArray(); foreach ($entity as $name => &$value) { if (null === $value) { unset($entity[$name]); } elseif ($value instanceof Entity) { $value = $value->toArray(); } } return $entity; }
php
public function toApiArray() { $entity = $this->toArray(); foreach ($entity as $name => &$value) { if (null === $value) { unset($entity[$name]); } elseif ($value instanceof Entity) { $value = $value->toArray(); } } return $entity; }
[ "public", "function", "toApiArray", "(", ")", "{", "$", "entity", "=", "$", "this", "->", "toArray", "(", ")", ";", "foreach", "(", "$", "entity", "as", "$", "name", "=>", "&", "$", "value", ")", "{", "if", "(", "null", "===", "$", "value", ")", ...
Build multi-level array for api call`s, filter or upgrade properties @return array
[ "Build", "multi", "-", "level", "array", "for", "api", "call", "s", "filter", "or", "upgrade", "properties" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Api/Entity.php#L66-L77
train
Bogdaan/viber-bot-php
src/Api/Event/Factory.php
Factory.makeFromApi
public static function makeFromApi(array $data) { if (isset($data['event'])) { switch ($data['event']) { case Type::MESSAGE: return new Message($data); case Type::SUBSCRIBED: return new Subscribed($data); case Type::CONVERSATION: return new Conversation($data); case Type::UNSUBSCRIBED: return new Unsubscribed($data); case Type::DELIVERED: return new Delivered($data); case Type::SEEN: return new Seen($data); case Type::FAILED: return new Failed($data); case Type::WEBHOOK: return new Webhook($data); } } throw new ApiException('Unknow event data'); }
php
public static function makeFromApi(array $data) { if (isset($data['event'])) { switch ($data['event']) { case Type::MESSAGE: return new Message($data); case Type::SUBSCRIBED: return new Subscribed($data); case Type::CONVERSATION: return new Conversation($data); case Type::UNSUBSCRIBED: return new Unsubscribed($data); case Type::DELIVERED: return new Delivered($data); case Type::SEEN: return new Seen($data); case Type::FAILED: return new Failed($data); case Type::WEBHOOK: return new Webhook($data); } } throw new ApiException('Unknow event data'); }
[ "public", "static", "function", "makeFromApi", "(", "array", "$", "data", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "'event'", "]", ")", ")", "{", "switch", "(", "$", "data", "[", "'event'", "]", ")", "{", "case", "Type", "::", "MESSAGE"...
Make some event from api-request array @param array $data api request data @return \Viber\Api\Event
[ "Make", "some", "event", "from", "api", "-", "request", "array" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Api/Event/Factory.php#L20-L43
train
Bogdaan/viber-bot-php
src/Api/Message/CarouselContent.php
CarouselContent.getButtonsApiArray
protected function getButtonsApiArray() { $buttons = []; foreach ($this->getButtons() as $i) { $buttons[] = $i->toApiArray(); } return $buttons; }
php
protected function getButtonsApiArray() { $buttons = []; foreach ($this->getButtons() as $i) { $buttons[] = $i->toApiArray(); } return $buttons; }
[ "protected", "function", "getButtonsApiArray", "(", ")", "{", "$", "buttons", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getButtons", "(", ")", "as", "$", "i", ")", "{", "$", "buttons", "[", "]", "=", "$", "i", "->", "toApiArray", "(",...
Build buttons api array @return array
[ "Build", "buttons", "api", "array" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Api/Message/CarouselContent.php#L174-L182
train
Bogdaan/viber-bot-php
src/Bot/Manager.php
Manager.isMatch
public function isMatch(Event $event) { if (is_callable($this->checker)) { return call_user_func($this->checker, $event); } return false; }
php
public function isMatch(Event $event) { if (is_callable($this->checker)) { return call_user_func($this->checker, $event); } return false; }
[ "public", "function", "isMatch", "(", "Event", "$", "event", ")", "{", "if", "(", "is_callable", "(", "$", "this", "->", "checker", ")", ")", "{", "return", "call_user_func", "(", "$", "this", "->", "checker", ",", "$", "event", ")", ";", "}", "retur...
While event checker match current event? @param \Viber\Api\Event $event @return boolean
[ "While", "event", "checker", "match", "current", "event?" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Bot/Manager.php#L66-L72
train
Bogdaan/viber-bot-php
src/Bot/Manager.php
Manager.runHandler
public function runHandler(Event $event) { if (is_callable($this->handler)) { return call_user_func($this->handler, $event); } return false; }
php
public function runHandler(Event $event) { if (is_callable($this->handler)) { return call_user_func($this->handler, $event); } return false; }
[ "public", "function", "runHandler", "(", "Event", "$", "event", ")", "{", "if", "(", "is_callable", "(", "$", "this", "->", "handler", ")", ")", "{", "return", "call_user_func", "(", "$", "this", "->", "handler", ",", "$", "event", ")", ";", "}", "re...
Process event with handler function @param \Viber\Api\Event $event @return mixed event handler result
[ "Process", "event", "with", "handler", "function" ]
993b75b6bdc78d9fa45d554014408db223d1ed6a
https://github.com/Bogdaan/viber-bot-php/blob/993b75b6bdc78d9fa45d554014408db223d1ed6a/src/Bot/Manager.php#L80-L86
train
bradcornford/Googlmapper
src/Cornford/Googlmapper/Mapper.php
Mapper.render
public function render($item = -1) { if (!$this->isEnabled()) { return; } return $this->view->make('googlmapper::mapper') ->withView($this->view) ->withOptions($this->generateRenderOptions($item)) ->withItems($item > -1 ? [$item => $this->getItem($item)] : $this->getItems()) ->render(); }
php
public function render($item = -1) { if (!$this->isEnabled()) { return; } return $this->view->make('googlmapper::mapper') ->withView($this->view) ->withOptions($this->generateRenderOptions($item)) ->withItems($item > -1 ? [$item => $this->getItem($item)] : $this->getItems()) ->render(); }
[ "public", "function", "render", "(", "$", "item", "=", "-", "1", ")", "{", "if", "(", "!", "$", "this", "->", "isEnabled", "(", ")", ")", "{", "return", ";", "}", "return", "$", "this", "->", "view", "->", "make", "(", "'googlmapper::mapper'", ")",...
Renders and returns Google Map code. @param integer $item @return string
[ "Renders", "and", "returns", "Google", "Map", "code", "." ]
785e8c11b13abd4247acce55b4394307575ff622
https://github.com/bradcornford/Googlmapper/blob/785e8c11b13abd4247acce55b4394307575ff622/src/Cornford/Googlmapper/Mapper.php#L34-L45
train