repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
j-d/draggy
src/Draggy/Autocode/Base/AttributeBase.php
AttributeBase.setOwnerSide
public function setOwnerSide($ownerSide) { if (!is_bool($ownerSide)) { throw new \InvalidArgumentException('The attribute ownerSide on the class Attribute has to be boolean (' . gettype($ownerSide) . ('object' === gettype($ownerSide) ? ' ' . get_class($ownerSide) : '') . ' given).'); } $this->ownerSide = $ownerSide; return $this; }
php
public function setOwnerSide($ownerSide) { if (!is_bool($ownerSide)) { throw new \InvalidArgumentException('The attribute ownerSide on the class Attribute has to be boolean (' . gettype($ownerSide) . ('object' === gettype($ownerSide) ? ' ' . get_class($ownerSide) : '') . ' given).'); } $this->ownerSide = $ownerSide; return $this; }
[ "public", "function", "setOwnerSide", "(", "$", "ownerSide", ")", "{", "if", "(", "!", "is_bool", "(", "$", "ownerSide", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The attribute ownerSide on the class Attribute has to be boolean ('", ".", "gettype", "(", "$", "ownerSide", ")", ".", "(", "'object'", "===", "gettype", "(", "$", "ownerSide", ")", "?", "' '", ".", "get_class", "(", "$", "ownerSide", ")", ":", "''", ")", ".", "' given).'", ")", ";", "}", "$", "this", "->", "ownerSide", "=", "$", "ownerSide", ";", "return", "$", "this", ";", "}" ]
Set ownerSide @param boolean $ownerSide @return Attribute @throws \InvalidArgumentException
[ "Set", "ownerSide" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Base/AttributeBase.php#L995-L1004
j-d/draggy
src/Draggy/Autocode/Base/AttributeBase.php
AttributeBase.setInverse
public function setInverse($inverse) { if (!is_bool($inverse)) { throw new \InvalidArgumentException('The attribute inverse on the class Attribute has to be boolean (' . gettype($inverse) . ('object' === gettype($inverse) ? ' ' . get_class($inverse) : '') . ' given).'); } $this->inverse = $inverse; return $this; }
php
public function setInverse($inverse) { if (!is_bool($inverse)) { throw new \InvalidArgumentException('The attribute inverse on the class Attribute has to be boolean (' . gettype($inverse) . ('object' === gettype($inverse) ? ' ' . get_class($inverse) : '') . ' given).'); } $this->inverse = $inverse; return $this; }
[ "public", "function", "setInverse", "(", "$", "inverse", ")", "{", "if", "(", "!", "is_bool", "(", "$", "inverse", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The attribute inverse on the class Attribute has to be boolean ('", ".", "gettype", "(", "$", "inverse", ")", ".", "(", "'object'", "===", "gettype", "(", "$", "inverse", ")", "?", "' '", ".", "get_class", "(", "$", "inverse", ")", ":", "''", ")", ".", "' given).'", ")", ";", "}", "$", "this", "->", "inverse", "=", "$", "inverse", ";", "return", "$", "this", ";", "}" ]
Set inverse @param boolean $inverse @return Attribute @throws \InvalidArgumentException
[ "Set", "inverse" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Base/AttributeBase.php#L1065-L1074
arndtteunissen/column-layout
Classes/Utility/EmConfigurationUtility.php
EmConfigurationUtility.getSettings
public static function getSettings() { if (self::$settings === null) { $configuration = self::parseSettings(); self::$settings = new EmConfiguration($configuration); } return self::$settings; }
php
public static function getSettings() { if (self::$settings === null) { $configuration = self::parseSettings(); self::$settings = new EmConfiguration($configuration); } return self::$settings; }
[ "public", "static", "function", "getSettings", "(", ")", "{", "if", "(", "self", "::", "$", "settings", "===", "null", ")", "{", "$", "configuration", "=", "self", "::", "parseSettings", "(", ")", ";", "self", "::", "$", "settings", "=", "new", "EmConfiguration", "(", "$", "configuration", ")", ";", "}", "return", "self", "::", "$", "settings", ";", "}" ]
Parses the extension settings. @return EmConfiguration
[ "Parses", "the", "extension", "settings", "." ]
train
https://github.com/arndtteunissen/column-layout/blob/ad737068eef3b084d4d0e3a48e6a3d8277af9560/Classes/Utility/EmConfigurationUtility.php#L28-L36
xiewulong/yii2-fileupload
oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassMapGenerator.php
ClassMapGenerator.createMap
public static function createMap($dir) { if (is_string($dir)) { $dir = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir)); } $map = array(); foreach ($dir as $file) { if (!$file->isFile()) { continue; } $path = $file->getRealPath(); if (pathinfo($path, PATHINFO_EXTENSION) !== 'php') { continue; } $classes = self::findClasses($path); foreach ($classes as $class) { $map[$class] = $path; } } return $map; }
php
public static function createMap($dir) { if (is_string($dir)) { $dir = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir)); } $map = array(); foreach ($dir as $file) { if (!$file->isFile()) { continue; } $path = $file->getRealPath(); if (pathinfo($path, PATHINFO_EXTENSION) !== 'php') { continue; } $classes = self::findClasses($path); foreach ($classes as $class) { $map[$class] = $path; } } return $map; }
[ "public", "static", "function", "createMap", "(", "$", "dir", ")", "{", "if", "(", "is_string", "(", "$", "dir", ")", ")", "{", "$", "dir", "=", "new", "\\", "RecursiveIteratorIterator", "(", "new", "\\", "RecursiveDirectoryIterator", "(", "$", "dir", ")", ")", ";", "}", "$", "map", "=", "array", "(", ")", ";", "foreach", "(", "$", "dir", "as", "$", "file", ")", "{", "if", "(", "!", "$", "file", "->", "isFile", "(", ")", ")", "{", "continue", ";", "}", "$", "path", "=", "$", "file", "->", "getRealPath", "(", ")", ";", "if", "(", "pathinfo", "(", "$", "path", ",", "PATHINFO_EXTENSION", ")", "!==", "'php'", ")", "{", "continue", ";", "}", "$", "classes", "=", "self", "::", "findClasses", "(", "$", "path", ")", ";", "foreach", "(", "$", "classes", "as", "$", "class", ")", "{", "$", "map", "[", "$", "class", "]", "=", "$", "path", ";", "}", "}", "return", "$", "map", ";", "}" ]
Iterate over all files in the given directory searching for classes @param Iterator|string $dir The directory to search in or an iterator @return array A class map array
[ "Iterate", "over", "all", "files", "in", "the", "given", "directory", "searching", "for", "classes" ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassMapGenerator.php#L46-L74
xiewulong/yii2-fileupload
oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassMapGenerator.php
ClassMapGenerator.findClasses
private static function findClasses($path) { $contents = file_get_contents($path); $tokens = token_get_all($contents); $T_TRAIT = version_compare(PHP_VERSION, '5.4', '<') ? -1 : T_TRAIT; $classes = array(); $namespace = ''; for ($i = 0, $max = count($tokens); $i < $max; $i++) { $token = $tokens[$i]; if (is_string($token)) { continue; } $class = ''; switch ($token[0]) { case T_NAMESPACE: $namespace = ''; // If there is a namespace, extract it while (($t = $tokens[++$i]) && is_array($t)) { if (in_array($t[0], array(T_STRING, T_NS_SEPARATOR))) { $namespace .= $t[1]; } } $namespace .= '\\'; break; case T_CLASS: case T_INTERFACE: case $T_TRAIT: // Find the classname while (($t = $tokens[++$i]) && is_array($t)) { if (T_STRING === $t[0]) { $class .= $t[1]; } elseif ($class !== '' && T_WHITESPACE == $t[0]) { break; } } $classes[] = ltrim($namespace.$class, '\\'); break; default: break; } } return $classes; }
php
private static function findClasses($path) { $contents = file_get_contents($path); $tokens = token_get_all($contents); $T_TRAIT = version_compare(PHP_VERSION, '5.4', '<') ? -1 : T_TRAIT; $classes = array(); $namespace = ''; for ($i = 0, $max = count($tokens); $i < $max; $i++) { $token = $tokens[$i]; if (is_string($token)) { continue; } $class = ''; switch ($token[0]) { case T_NAMESPACE: $namespace = ''; // If there is a namespace, extract it while (($t = $tokens[++$i]) && is_array($t)) { if (in_array($t[0], array(T_STRING, T_NS_SEPARATOR))) { $namespace .= $t[1]; } } $namespace .= '\\'; break; case T_CLASS: case T_INTERFACE: case $T_TRAIT: // Find the classname while (($t = $tokens[++$i]) && is_array($t)) { if (T_STRING === $t[0]) { $class .= $t[1]; } elseif ($class !== '' && T_WHITESPACE == $t[0]) { break; } } $classes[] = ltrim($namespace.$class, '\\'); break; default: break; } } return $classes; }
[ "private", "static", "function", "findClasses", "(", "$", "path", ")", "{", "$", "contents", "=", "file_get_contents", "(", "$", "path", ")", ";", "$", "tokens", "=", "token_get_all", "(", "$", "contents", ")", ";", "$", "T_TRAIT", "=", "version_compare", "(", "PHP_VERSION", ",", "'5.4'", ",", "'<'", ")", "?", "-", "1", ":", "T_TRAIT", ";", "$", "classes", "=", "array", "(", ")", ";", "$", "namespace", "=", "''", ";", "for", "(", "$", "i", "=", "0", ",", "$", "max", "=", "count", "(", "$", "tokens", ")", ";", "$", "i", "<", "$", "max", ";", "$", "i", "++", ")", "{", "$", "token", "=", "$", "tokens", "[", "$", "i", "]", ";", "if", "(", "is_string", "(", "$", "token", ")", ")", "{", "continue", ";", "}", "$", "class", "=", "''", ";", "switch", "(", "$", "token", "[", "0", "]", ")", "{", "case", "T_NAMESPACE", ":", "$", "namespace", "=", "''", ";", "// If there is a namespace, extract it", "while", "(", "(", "$", "t", "=", "$", "tokens", "[", "++", "$", "i", "]", ")", "&&", "is_array", "(", "$", "t", ")", ")", "{", "if", "(", "in_array", "(", "$", "t", "[", "0", "]", ",", "array", "(", "T_STRING", ",", "T_NS_SEPARATOR", ")", ")", ")", "{", "$", "namespace", ".=", "$", "t", "[", "1", "]", ";", "}", "}", "$", "namespace", ".=", "'\\\\'", ";", "break", ";", "case", "T_CLASS", ":", "case", "T_INTERFACE", ":", "case", "$", "T_TRAIT", ":", "// Find the classname", "while", "(", "(", "$", "t", "=", "$", "tokens", "[", "++", "$", "i", "]", ")", "&&", "is_array", "(", "$", "t", ")", ")", "{", "if", "(", "T_STRING", "===", "$", "t", "[", "0", "]", ")", "{", "$", "class", ".=", "$", "t", "[", "1", "]", ";", "}", "elseif", "(", "$", "class", "!==", "''", "&&", "T_WHITESPACE", "==", "$", "t", "[", "0", "]", ")", "{", "break", ";", "}", "}", "$", "classes", "[", "]", "=", "ltrim", "(", "$", "namespace", ".", "$", "class", ",", "'\\\\'", ")", ";", "break", ";", "default", ":", "break", ";", "}", "}", "return", "$", "classes", ";", "}" ]
Extract the classes in the given file @param string $path The file to check @return array The found classes
[ "Extract", "the", "classes", "in", "the", "given", "file" ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassMapGenerator.php#L83-L132
php-lug/lug
src/Bundle/GridBundle/Context/LocaleContext.php
LocaleContext.getLocale
public function getLocale() { $locales = $this->localeContext->getLocales(); if (($locale = reset($locales)) === false) { throw new LocaleNotFoundException(); } return $locale; }
php
public function getLocale() { $locales = $this->localeContext->getLocales(); if (($locale = reset($locales)) === false) { throw new LocaleNotFoundException(); } return $locale; }
[ "public", "function", "getLocale", "(", ")", "{", "$", "locales", "=", "$", "this", "->", "localeContext", "->", "getLocales", "(", ")", ";", "if", "(", "(", "$", "locale", "=", "reset", "(", "$", "locales", ")", ")", "===", "false", ")", "{", "throw", "new", "LocaleNotFoundException", "(", ")", ";", "}", "return", "$", "locale", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Context/LocaleContext.php#L39-L48
hametuha/wpametu
src/WPametu/UI/Field/Taxonomy.php
Taxonomy.get_options
protected function get_options(){ $terms = get_terms($this->name); if( !$terms || is_wp_error($terms) ){ return []; }else{ $result = []; foreach( $terms as $term ){ $result[$term->term_id] = $term->name; } return $result; } }
php
protected function get_options(){ $terms = get_terms($this->name); if( !$terms || is_wp_error($terms) ){ return []; }else{ $result = []; foreach( $terms as $term ){ $result[$term->term_id] = $term->name; } return $result; } }
[ "protected", "function", "get_options", "(", ")", "{", "$", "terms", "=", "get_terms", "(", "$", "this", "->", "name", ")", ";", "if", "(", "!", "$", "terms", "||", "is_wp_error", "(", "$", "terms", ")", ")", "{", "return", "[", "]", ";", "}", "else", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "terms", "as", "$", "term", ")", "{", "$", "result", "[", "$", "term", "->", "term_id", "]", "=", "$", "term", "->", "name", ";", "}", "return", "$", "result", ";", "}", "}" ]
Get terms as option @return array
[ "Get", "terms", "as", "option" ]
train
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/UI/Field/Taxonomy.php#L53-L64
antaresproject/notifications
src/Http/Form/Form.php
Form.buttons
protected function buttons($fluent, Fieldset $fieldset) { $fieldset->control('button', 'cancel') ->field(function() { return app('html')->link(handles("antares::notifications/"), trans('Cancel'), ['class' => 'btn btn--md btn--default mdl-button mdl-js-button']); }); $acl = app('antares.acl')->make('antares/notifications'); if ($acl->can('notifications-preview')) { $fieldset->control('button', 'preview') ->attributes([ 'type' => 'button', 'value' => trans('Preview'), 'class' => 'btn btn-default notification-template-preview', 'url' => handles('antares::notifications/preview/' . $fluent->id), 'data-title' => trans('antares/notifications::messages.generating_notification_preview') ]) ->value(trans('Preview')); } if ($acl->can('notifications-test') && in_array($this->fluent->type, ['email', 'sms'])) { $fieldset->control('button', 'sendtest') ->attributes([ 'type' => 'button', 'class' => 'btn btn-default send-test-notification', 'rel' => handles('antares::notifications/sendtest', ['csrf' => true]) ]) ->value(trans('Send test')); } $fieldset->control('button', 'button') ->attributes(['type' => 'submit', 'class' => 'btn btn-primary']) ->value($fluent->id ? trans('antares/foundation::label.save_changes') : trans('Save')); }
php
protected function buttons($fluent, Fieldset $fieldset) { $fieldset->control('button', 'cancel') ->field(function() { return app('html')->link(handles("antares::notifications/"), trans('Cancel'), ['class' => 'btn btn--md btn--default mdl-button mdl-js-button']); }); $acl = app('antares.acl')->make('antares/notifications'); if ($acl->can('notifications-preview')) { $fieldset->control('button', 'preview') ->attributes([ 'type' => 'button', 'value' => trans('Preview'), 'class' => 'btn btn-default notification-template-preview', 'url' => handles('antares::notifications/preview/' . $fluent->id), 'data-title' => trans('antares/notifications::messages.generating_notification_preview') ]) ->value(trans('Preview')); } if ($acl->can('notifications-test') && in_array($this->fluent->type, ['email', 'sms'])) { $fieldset->control('button', 'sendtest') ->attributes([ 'type' => 'button', 'class' => 'btn btn-default send-test-notification', 'rel' => handles('antares::notifications/sendtest', ['csrf' => true]) ]) ->value(trans('Send test')); } $fieldset->control('button', 'button') ->attributes(['type' => 'submit', 'class' => 'btn btn-primary']) ->value($fluent->id ? trans('antares/foundation::label.save_changes') : trans('Save')); }
[ "protected", "function", "buttons", "(", "$", "fluent", ",", "Fieldset", "$", "fieldset", ")", "{", "$", "fieldset", "->", "control", "(", "'button'", ",", "'cancel'", ")", "->", "field", "(", "function", "(", ")", "{", "return", "app", "(", "'html'", ")", "->", "link", "(", "handles", "(", "\"antares::notifications/\"", ")", ",", "trans", "(", "'Cancel'", ")", ",", "[", "'class'", "=>", "'btn btn--md btn--default mdl-button mdl-js-button'", "]", ")", ";", "}", ")", ";", "$", "acl", "=", "app", "(", "'antares.acl'", ")", "->", "make", "(", "'antares/notifications'", ")", ";", "if", "(", "$", "acl", "->", "can", "(", "'notifications-preview'", ")", ")", "{", "$", "fieldset", "->", "control", "(", "'button'", ",", "'preview'", ")", "->", "attributes", "(", "[", "'type'", "=>", "'button'", ",", "'value'", "=>", "trans", "(", "'Preview'", ")", ",", "'class'", "=>", "'btn btn-default notification-template-preview'", ",", "'url'", "=>", "handles", "(", "'antares::notifications/preview/'", ".", "$", "fluent", "->", "id", ")", ",", "'data-title'", "=>", "trans", "(", "'antares/notifications::messages.generating_notification_preview'", ")", "]", ")", "->", "value", "(", "trans", "(", "'Preview'", ")", ")", ";", "}", "if", "(", "$", "acl", "->", "can", "(", "'notifications-test'", ")", "&&", "in_array", "(", "$", "this", "->", "fluent", "->", "type", ",", "[", "'email'", ",", "'sms'", "]", ")", ")", "{", "$", "fieldset", "->", "control", "(", "'button'", ",", "'sendtest'", ")", "->", "attributes", "(", "[", "'type'", "=>", "'button'", ",", "'class'", "=>", "'btn btn-default send-test-notification'", ",", "'rel'", "=>", "handles", "(", "'antares::notifications/sendtest'", ",", "[", "'csrf'", "=>", "true", "]", ")", "]", ")", "->", "value", "(", "trans", "(", "'Send test'", ")", ")", ";", "}", "$", "fieldset", "->", "control", "(", "'button'", ",", "'button'", ")", "->", "attributes", "(", "[", "'type'", "=>", "'submit'", ",", "'class'", "=>", "'btn btn-primary'", "]", ")", "->", "value", "(", "$", "fluent", "->", "id", "?", "trans", "(", "'antares/foundation::label.save_changes'", ")", ":", "trans", "(", "'Save'", ")", ")", ";", "}" ]
buttons in form @param Fluent $fluent @param Fieldset $fieldset
[ "buttons", "in", "form" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Http/Form/Form.php#L160-L193
antaresproject/notifications
src/Http/Form/Form.php
Form.onCreate
public function onCreate() { $this->grid->attributes([ 'url' => handles('antares::notifications/store'), 'method' => 'POST', ]); $layout = ($this->fluent->type == 'sms') ? 'antares/notifications::admin.index.form_sms' : 'antares/notifications::admin.index.form'; $this->grid->layout($layout, $this->layoutAttributes); return $this; }
php
public function onCreate() { $this->grid->attributes([ 'url' => handles('antares::notifications/store'), 'method' => 'POST', ]); $layout = ($this->fluent->type == 'sms') ? 'antares/notifications::admin.index.form_sms' : 'antares/notifications::admin.index.form'; $this->grid->layout($layout, $this->layoutAttributes); return $this; }
[ "public", "function", "onCreate", "(", ")", "{", "$", "this", "->", "grid", "->", "attributes", "(", "[", "'url'", "=>", "handles", "(", "'antares::notifications/store'", ")", ",", "'method'", "=>", "'POST'", ",", "]", ")", ";", "$", "layout", "=", "(", "$", "this", "->", "fluent", "->", "type", "==", "'sms'", ")", "?", "'antares/notifications::admin.index.form_sms'", ":", "'antares/notifications::admin.index.form'", ";", "$", "this", "->", "grid", "->", "layout", "(", "$", "layout", ",", "$", "this", "->", "layoutAttributes", ")", ";", "return", "$", "this", ";", "}" ]
on create scenario @param String $type @return \Antares\Notifications\Http\Form\Form
[ "on", "create", "scenario" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Http/Form/Form.php#L213-L222
antaresproject/notifications
src/Http/Form/Form.php
Form.getNotificationContentData
protected function getNotificationContentData($fluent, $langId, $key = 'title') { foreach ($fluent->contents as $content) { if ($langId !== $content['lang_id']) { continue; } return array_get($content, $key); } return ''; }
php
protected function getNotificationContentData($fluent, $langId, $key = 'title') { foreach ($fluent->contents as $content) { if ($langId !== $content['lang_id']) { continue; } return array_get($content, $key); } return ''; }
[ "protected", "function", "getNotificationContentData", "(", "$", "fluent", ",", "$", "langId", ",", "$", "key", "=", "'title'", ")", "{", "foreach", "(", "$", "fluent", "->", "contents", "as", "$", "content", ")", "{", "if", "(", "$", "langId", "!==", "$", "content", "[", "'lang_id'", "]", ")", "{", "continue", ";", "}", "return", "array_get", "(", "$", "content", ",", "$", "key", ")", ";", "}", "return", "''", ";", "}" ]
Gets notification data @param Fluent $fluent @param mixed $langId @param String $key @return String
[ "Gets", "notification", "data" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Http/Form/Form.php#L232-L241
ajgarlag/AjglCsv
src/Writer/WriterAbstract.php
WriterAbstract.writeRow
public function writeRow(array $row, $inputCharset = IoInterface::CHARSET_DEFAULT) { if ($inputCharset !== $this->getFileCharset()) { $row = $this->convertRowCharset($row, $inputCharset, $this->getFileCharset()); } $this->doWrite($this->getHandler(), $row, $this->getDelimiter()); return $this; }
php
public function writeRow(array $row, $inputCharset = IoInterface::CHARSET_DEFAULT) { if ($inputCharset !== $this->getFileCharset()) { $row = $this->convertRowCharset($row, $inputCharset, $this->getFileCharset()); } $this->doWrite($this->getHandler(), $row, $this->getDelimiter()); return $this; }
[ "public", "function", "writeRow", "(", "array", "$", "row", ",", "$", "inputCharset", "=", "IoInterface", "::", "CHARSET_DEFAULT", ")", "{", "if", "(", "$", "inputCharset", "!==", "$", "this", "->", "getFileCharset", "(", ")", ")", "{", "$", "row", "=", "$", "this", "->", "convertRowCharset", "(", "$", "row", ",", "$", "inputCharset", ",", "$", "this", "->", "getFileCharset", "(", ")", ")", ";", "}", "$", "this", "->", "doWrite", "(", "$", "this", "->", "getHandler", "(", ")", ",", "$", "row", ",", "$", "this", "->", "getDelimiter", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/ajgarlag/AjglCsv/blob/28872f58b9ef864893cac6faddfcb1229c2c2047/src/Writer/WriterAbstract.php#L43-L51
ajgarlag/AjglCsv
src/Writer/WriterAbstract.php
WriterAbstract.writeRows
public function writeRows(array $rows, $inputCharset = IoInterface::CHARSET_DEFAULT) { foreach ($rows as $row) { $this->writeRow($row, $inputCharset); } return $this; }
php
public function writeRows(array $rows, $inputCharset = IoInterface::CHARSET_DEFAULT) { foreach ($rows as $row) { $this->writeRow($row, $inputCharset); } return $this; }
[ "public", "function", "writeRows", "(", "array", "$", "rows", ",", "$", "inputCharset", "=", "IoInterface", "::", "CHARSET_DEFAULT", ")", "{", "foreach", "(", "$", "rows", "as", "$", "row", ")", "{", "$", "this", "->", "writeRow", "(", "$", "row", ",", "$", "inputCharset", ")", ";", "}", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/ajgarlag/AjglCsv/blob/28872f58b9ef864893cac6faddfcb1229c2c2047/src/Writer/WriterAbstract.php#L56-L63
RhubarbPHP/Module.RestApi
src/Modelling/ApiModel.php
ApiModel.delete
public function delete() { if ($this->isNewRecord()) { throw new DeleteModelException("New models can't be deleted."); } $this->beforeDelete(); $this->raiseEvent("BeforeDelete"); $this->Deleted = true; $this->save(); $this->afterDelete(); $this->raiseEvent("AfterDelete"); }
php
public function delete() { if ($this->isNewRecord()) { throw new DeleteModelException("New models can't be deleted."); } $this->beforeDelete(); $this->raiseEvent("BeforeDelete"); $this->Deleted = true; $this->save(); $this->afterDelete(); $this->raiseEvent("AfterDelete"); }
[ "public", "function", "delete", "(", ")", "{", "if", "(", "$", "this", "->", "isNewRecord", "(", ")", ")", "{", "throw", "new", "DeleteModelException", "(", "\"New models can't be deleted.\"", ")", ";", "}", "$", "this", "->", "beforeDelete", "(", ")", ";", "$", "this", "->", "raiseEvent", "(", "\"BeforeDelete\"", ")", ";", "$", "this", "->", "Deleted", "=", "true", ";", "$", "this", "->", "save", "(", ")", ";", "$", "this", "->", "afterDelete", "(", ")", ";", "$", "this", "->", "raiseEvent", "(", "\"AfterDelete\"", ")", ";", "}" ]
Replaces the standard delete by flagging the entry deleted instead.
[ "Replaces", "the", "standard", "delete", "by", "flagging", "the", "entry", "deleted", "instead", "." ]
train
https://github.com/RhubarbPHP/Module.RestApi/blob/825d2b920caed13811971c5eb2784a94417787bd/src/Modelling/ApiModel.php#L55-L69
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package._init
protected function _init($definition=null) { if (!is_null($definition)) { $this->_packageXml = simplexml_load_string($definition); } else { $packageXmlStub = <<<END <?xml version="1.0"?> <package> <name /> <version /> <stability /> <license /> <channel /> <extends /> <summary /> <description /> <notes /> <authors /> <date /> <time /> <contents /> <compatible /> <dependencies /> </package> END; $this->_packageXml = simplexml_load_string($packageXmlStub); } return $this; }
php
protected function _init($definition=null) { if (!is_null($definition)) { $this->_packageXml = simplexml_load_string($definition); } else { $packageXmlStub = <<<END <?xml version="1.0"?> <package> <name /> <version /> <stability /> <license /> <channel /> <extends /> <summary /> <description /> <notes /> <authors /> <date /> <time /> <contents /> <compatible /> <dependencies /> </package> END; $this->_packageXml = simplexml_load_string($packageXmlStub); } return $this; }
[ "protected", "function", "_init", "(", "$", "definition", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "definition", ")", ")", "{", "$", "this", "->", "_packageXml", "=", "simplexml_load_string", "(", "$", "definition", ")", ";", "}", "else", "{", "$", "packageXmlStub", "=", " <<<END\n<?xml version=\"1.0\"?>\n<package>\n <name />\n <version />\n <stability />\n <license />\n <channel />\n <extends />\n <summary />\n <description />\n <notes />\n <authors />\n <date />\n <time />\n <contents />\n <compatible />\n <dependencies />\n</package>\nEND", ";", "$", "this", "->", "_packageXml", "=", "simplexml_load_string", "(", "$", "packageXmlStub", ")", ";", "}", "return", "$", "this", ";", "}" ]
Initializes an empty package object @param null|string $definition optional package definition xml @return Mage_Connect_Package
[ "Initializes", "an", "empty", "package", "object" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L165-L194
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package._loadFile
protected function _loadFile($filename='') { if (is_null($this->_reader)) { $this->_reader = new Mage_Connect_Package_Reader($filename); } $content = $this->_reader->load(); $this->_packageXml = simplexml_load_string($content); return $this; }
php
protected function _loadFile($filename='') { if (is_null($this->_reader)) { $this->_reader = new Mage_Connect_Package_Reader($filename); } $content = $this->_reader->load(); $this->_packageXml = simplexml_load_string($content); return $this; }
[ "protected", "function", "_loadFile", "(", "$", "filename", "=", "''", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_reader", ")", ")", "{", "$", "this", "->", "_reader", "=", "new", "Mage_Connect_Package_Reader", "(", "$", "filename", ")", ";", "}", "$", "content", "=", "$", "this", "->", "_reader", "->", "load", "(", ")", ";", "$", "this", "->", "_packageXml", "=", "simplexml_load_string", "(", "$", "content", ")", ";", "return", "$", "this", ";", "}" ]
Loads a package from specified file @param string $filename @return Mage_Connect_Package
[ "Loads", "a", "package", "from", "specified", "file" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L202-L210
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.save
public function save($path) { $this->validate(); $path = rtrim($path, "\\/") . DS; $this->_savePackage($path); return $this; }
php
public function save($path) { $this->validate(); $path = rtrim($path, "\\/") . DS; $this->_savePackage($path); return $this; }
[ "public", "function", "save", "(", "$", "path", ")", "{", "$", "this", "->", "validate", "(", ")", ";", "$", "path", "=", "rtrim", "(", "$", "path", ",", "\"\\\\/\"", ")", ".", "DS", ";", "$", "this", "->", "_savePackage", "(", "$", "path", ")", ";", "return", "$", "this", ";", "}" ]
Creates a package and saves it @param string $path @return Mage_Connect_Package
[ "Creates", "a", "package", "and", "saves", "it" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L218-L224
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package._savePackage
protected function _savePackage($path) { $fileName = $this->getReleaseFilename(); if (is_null($this->_writer)) { $this->_writer = new Mage_Connect_Package_Writer($this->getContents(), $path.$fileName); } $this->_writer ->composePackage() ->addPackageXml($this->getPackageXml()) ->archivePackage(); return $this; }
php
protected function _savePackage($path) { $fileName = $this->getReleaseFilename(); if (is_null($this->_writer)) { $this->_writer = new Mage_Connect_Package_Writer($this->getContents(), $path.$fileName); } $this->_writer ->composePackage() ->addPackageXml($this->getPackageXml()) ->archivePackage(); return $this; }
[ "protected", "function", "_savePackage", "(", "$", "path", ")", "{", "$", "fileName", "=", "$", "this", "->", "getReleaseFilename", "(", ")", ";", "if", "(", "is_null", "(", "$", "this", "->", "_writer", ")", ")", "{", "$", "this", "->", "_writer", "=", "new", "Mage_Connect_Package_Writer", "(", "$", "this", "->", "getContents", "(", ")", ",", "$", "path", ".", "$", "fileName", ")", ";", "}", "$", "this", "->", "_writer", "->", "composePackage", "(", ")", "->", "addPackageXml", "(", "$", "this", "->", "getPackageXml", "(", ")", ")", "->", "archivePackage", "(", ")", ";", "return", "$", "this", ";", "}" ]
Creates a package archive and saves it to specified path @param string $path @return Mage_Connect_Package
[ "Creates", "a", "package", "archive", "and", "saves", "it", "to", "specified", "path" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L232-L243
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.setAuthors
public function setAuthors($authors) { $this->_authors = $authors; foreach ($authors as $_author) { $this->addAuthor($_author['name'], $_author['user'], $_author['email']); } return $this; }
php
public function setAuthors($authors) { $this->_authors = $authors; foreach ($authors as $_author) { $this->addAuthor($_author['name'], $_author['user'], $_author['email']); } return $this; }
[ "public", "function", "setAuthors", "(", "$", "authors", ")", "{", "$", "this", "->", "_authors", "=", "$", "authors", ";", "foreach", "(", "$", "authors", "as", "$", "_author", ")", "{", "$", "this", "->", "addAuthor", "(", "$", "_author", "[", "'name'", "]", ",", "$", "_author", "[", "'user'", "]", ",", "$", "_author", "[", "'email'", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Puts value to <authors /> array( array('name'=>'Name1', 'user'=>'User1', 'email'=>'[email protected]'), array('name'=>'Name2', 'user'=>'User2', 'email'=>'[email protected]'), ); @param array $authors @return Mage_Connect_Package
[ "Puts", "value", "to", "<authors", "/", ">" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L326-L333
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.addAuthor
public function addAuthor($name=null, $user=null, $email=null) { $this->_authors[] = array( 'name' =>$name, 'user' =>$user, 'email'=>$email ); $author = $this->_packageXml->authors->addChild('author'); $author->addChild('name', $name); $author->addChild('user', $user); $author->addChild('email', $email); return $this; }
php
public function addAuthor($name=null, $user=null, $email=null) { $this->_authors[] = array( 'name' =>$name, 'user' =>$user, 'email'=>$email ); $author = $this->_packageXml->authors->addChild('author'); $author->addChild('name', $name); $author->addChild('user', $user); $author->addChild('email', $email); return $this; }
[ "public", "function", "addAuthor", "(", "$", "name", "=", "null", ",", "$", "user", "=", "null", ",", "$", "email", "=", "null", ")", "{", "$", "this", "->", "_authors", "[", "]", "=", "array", "(", "'name'", "=>", "$", "name", ",", "'user'", "=>", "$", "user", ",", "'email'", "=>", "$", "email", ")", ";", "$", "author", "=", "$", "this", "->", "_packageXml", "->", "authors", "->", "addChild", "(", "'author'", ")", ";", "$", "author", "->", "addChild", "(", "'name'", ",", "$", "name", ")", ";", "$", "author", "->", "addChild", "(", "'user'", ",", "$", "user", ")", ";", "$", "author", "->", "addChild", "(", "'email'", ",", "$", "email", ")", ";", "return", "$", "this", ";", "}" ]
Add author to <authors/> @param string $name @param string $user @param string $email @return Mage_Connect_Package
[ "Add", "author", "to", "<authors", "/", ">" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L343-L355
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.setLicense
public function setLicense($license, $uri=null) { $this->_packageXml->license = $license; if ($uri) { $this->_packageXml->license['uri'] = $uri; } return $this; }
php
public function setLicense($license, $uri=null) { $this->_packageXml->license = $license; if ($uri) { $this->_packageXml->license['uri'] = $uri; } return $this; }
[ "public", "function", "setLicense", "(", "$", "license", ",", "$", "uri", "=", "null", ")", "{", "$", "this", "->", "_packageXml", "->", "license", "=", "$", "license", ";", "if", "(", "$", "uri", ")", "{", "$", "this", "->", "_packageXml", "->", "license", "[", "'uri'", "]", "=", "$", "uri", ";", "}", "return", "$", "this", ";", "}" ]
Puts value to <license/>, also method can used for set attribute URI. @param string $license @param string $uri @return Mage_Connect_Package
[ "Puts", "value", "to", "<license", "/", ">", "also", "method", "can", "used", "for", "set", "attribute", "URI", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L412-L419
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package._getNode
protected function _getNode($tag, $parent, $name='') { $found = false; foreach ($parent->xpath($tag) as $_node) { if ($_node['name'] == $name) { $node = $_node; $found = true; break; } } if (!$found) { $node = $parent->addChild($tag); if ($name) { $node->addAttribute('name', $name); } } return $node; }
php
protected function _getNode($tag, $parent, $name='') { $found = false; foreach ($parent->xpath($tag) as $_node) { if ($_node['name'] == $name) { $node = $_node; $found = true; break; } } if (!$found) { $node = $parent->addChild($tag); if ($name) { $node->addAttribute('name', $name); } } return $node; }
[ "protected", "function", "_getNode", "(", "$", "tag", ",", "$", "parent", ",", "$", "name", "=", "''", ")", "{", "$", "found", "=", "false", ";", "foreach", "(", "$", "parent", "->", "xpath", "(", "$", "tag", ")", "as", "$", "_node", ")", "{", "if", "(", "$", "_node", "[", "'name'", "]", "==", "$", "name", ")", "{", "$", "node", "=", "$", "_node", ";", "$", "found", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "$", "found", ")", "{", "$", "node", "=", "$", "parent", "->", "addChild", "(", "$", "tag", ")", ";", "if", "(", "$", "name", ")", "{", "$", "node", "->", "addAttribute", "(", "'name'", ",", "$", "name", ")", ";", "}", "}", "return", "$", "node", ";", "}" ]
Retrieve SimpleXMLElement node by xpath. If it absent, create new. For comparing nodes method uses attribute "name" in each nodes. If attribute "name" is same for both nodes, nodes are same. @param string $tag @param SimpleXMLElement $parent @param string $name @return SimpleXMLElement
[ "Retrieve", "SimpleXMLElement", "node", "by", "xpath", ".", "If", "it", "absent", "create", "new", ".", "For", "comparing", "nodes", "method", "uses", "attribute", "name", "in", "each", "nodes", ".", "If", "attribute", "name", "is", "same", "for", "both", "nodes", "nodes", "are", "same", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L443-L460
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.addContent
public function addContent($path, $targetName) { $found = false; $parent = $this->_getNode('target', $this->_packageXml->contents, $targetName); $source = str_replace('\\', '/', $path); $directories = explode('/', dirname($source)); foreach ($directories as $directory) { $parent = $this->_getNode('dir', $parent, $directory); } $fileName = basename($source); if ($fileName!='') { $fileNode = $parent->addChild('file'); $fileNode->addAttribute('name', $fileName); $targetDir = $this->getTarget()->getTargetUri($targetName); $hash = md5_file($targetDir.DS.$path); $fileNode->addAttribute('hash', $hash); } return $this; }
php
public function addContent($path, $targetName) { $found = false; $parent = $this->_getNode('target', $this->_packageXml->contents, $targetName); $source = str_replace('\\', '/', $path); $directories = explode('/', dirname($source)); foreach ($directories as $directory) { $parent = $this->_getNode('dir', $parent, $directory); } $fileName = basename($source); if ($fileName!='') { $fileNode = $parent->addChild('file'); $fileNode->addAttribute('name', $fileName); $targetDir = $this->getTarget()->getTargetUri($targetName); $hash = md5_file($targetDir.DS.$path); $fileNode->addAttribute('hash', $hash); } return $this; }
[ "public", "function", "addContent", "(", "$", "path", ",", "$", "targetName", ")", "{", "$", "found", "=", "false", ";", "$", "parent", "=", "$", "this", "->", "_getNode", "(", "'target'", ",", "$", "this", "->", "_packageXml", "->", "contents", ",", "$", "targetName", ")", ";", "$", "source", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "path", ")", ";", "$", "directories", "=", "explode", "(", "'/'", ",", "dirname", "(", "$", "source", ")", ")", ";", "foreach", "(", "$", "directories", "as", "$", "directory", ")", "{", "$", "parent", "=", "$", "this", "->", "_getNode", "(", "'dir'", ",", "$", "parent", ",", "$", "directory", ")", ";", "}", "$", "fileName", "=", "basename", "(", "$", "source", ")", ";", "if", "(", "$", "fileName", "!=", "''", ")", "{", "$", "fileNode", "=", "$", "parent", "->", "addChild", "(", "'file'", ")", ";", "$", "fileNode", "->", "addAttribute", "(", "'name'", ",", "$", "fileName", ")", ";", "$", "targetDir", "=", "$", "this", "->", "getTarget", "(", ")", "->", "getTargetUri", "(", "$", "targetName", ")", ";", "$", "hash", "=", "md5_file", "(", "$", "targetDir", ".", "DS", ".", "$", "path", ")", ";", "$", "fileNode", "->", "addAttribute", "(", "'hash'", ",", "$", "hash", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add directory or file to <contents />. @param string $path Path to directory or file @param string $targetName Target name. @param string $hash MD5 hash of the file @return Mage_Connect_Package
[ "Add", "directory", "or", "file", "to", "<contents", "/", ">", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L470-L488
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.addContentDir
public function addContentDir($targetName, $path, $exclude=null, $include=null) { $targetDir = $this->getTarget()->getTargetUri($targetName); $targetDirLen = strlen($targetDir . DS); //get all subdirectories and files. $entries = @glob($targetDir. DS . $path . DS . "{,.}*", GLOB_BRACE); if (!empty($entries)) { foreach ($entries as $entry) { $filePath = substr($entry, $targetDirLen); if (!empty($include) && !preg_match($include, $filePath)) { continue; } if (!empty($exclude) && preg_match($exclude, $filePath)) { continue; } if (is_dir($entry)) { $baseName = basename($entry); if ('.'===$baseName || '..'===$baseName) { continue; } //for subdirectory call method recursively $this->addContentDir($targetName, $filePath, $exclude, $include); } elseif (is_file($entry)) { $this->addContent($filePath, $targetName); } } } return $this; }
php
public function addContentDir($targetName, $path, $exclude=null, $include=null) { $targetDir = $this->getTarget()->getTargetUri($targetName); $targetDirLen = strlen($targetDir . DS); //get all subdirectories and files. $entries = @glob($targetDir. DS . $path . DS . "{,.}*", GLOB_BRACE); if (!empty($entries)) { foreach ($entries as $entry) { $filePath = substr($entry, $targetDirLen); if (!empty($include) && !preg_match($include, $filePath)) { continue; } if (!empty($exclude) && preg_match($exclude, $filePath)) { continue; } if (is_dir($entry)) { $baseName = basename($entry); if ('.'===$baseName || '..'===$baseName) { continue; } //for subdirectory call method recursively $this->addContentDir($targetName, $filePath, $exclude, $include); } elseif (is_file($entry)) { $this->addContent($filePath, $targetName); } } } return $this; }
[ "public", "function", "addContentDir", "(", "$", "targetName", ",", "$", "path", ",", "$", "exclude", "=", "null", ",", "$", "include", "=", "null", ")", "{", "$", "targetDir", "=", "$", "this", "->", "getTarget", "(", ")", "->", "getTargetUri", "(", "$", "targetName", ")", ";", "$", "targetDirLen", "=", "strlen", "(", "$", "targetDir", ".", "DS", ")", ";", "//get all subdirectories and files.", "$", "entries", "=", "@", "glob", "(", "$", "targetDir", ".", "DS", ".", "$", "path", ".", "DS", ".", "\"{,.}*\"", ",", "GLOB_BRACE", ")", ";", "if", "(", "!", "empty", "(", "$", "entries", ")", ")", "{", "foreach", "(", "$", "entries", "as", "$", "entry", ")", "{", "$", "filePath", "=", "substr", "(", "$", "entry", ",", "$", "targetDirLen", ")", ";", "if", "(", "!", "empty", "(", "$", "include", ")", "&&", "!", "preg_match", "(", "$", "include", ",", "$", "filePath", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "empty", "(", "$", "exclude", ")", "&&", "preg_match", "(", "$", "exclude", ",", "$", "filePath", ")", ")", "{", "continue", ";", "}", "if", "(", "is_dir", "(", "$", "entry", ")", ")", "{", "$", "baseName", "=", "basename", "(", "$", "entry", ")", ";", "if", "(", "'.'", "===", "$", "baseName", "||", "'..'", "===", "$", "baseName", ")", "{", "continue", ";", "}", "//for subdirectory call method recursively", "$", "this", "->", "addContentDir", "(", "$", "targetName", ",", "$", "filePath", ",", "$", "exclude", ",", "$", "include", ")", ";", "}", "elseif", "(", "is_file", "(", "$", "entry", ")", ")", "{", "$", "this", "->", "addContent", "(", "$", "filePath", ",", "$", "targetName", ")", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Add directory recursively (with subdirectory and file). Exclude and Include can be add using Regular Expression. @param string $targetName Target name @param string $targetDir Path for target name @param string $path Path to directory @param string $exclude Exclude @param string $include Include @return Mage_Connect_Package
[ "Add", "directory", "recursively", "(", "with", "subdirectory", "and", "file", ")", ".", "Exclude", "and", "Include", "can", "be", "add", "using", "Regular", "Expression", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L501-L529
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.addCompatible
public function addCompatible($packageName, $channel, $minVersion, $maxVersion) { $package = $this->_packageXml->compatible->addChild('package'); $package->addChild('name', $packageName); $package->addChild('channel', $channel); $package->addChild('min', $minVersion); $package->addChild('max', $maxVersion); return $this; }
php
public function addCompatible($packageName, $channel, $minVersion, $maxVersion) { $package = $this->_packageXml->compatible->addChild('package'); $package->addChild('name', $packageName); $package->addChild('channel', $channel); $package->addChild('min', $minVersion); $package->addChild('max', $maxVersion); return $this; }
[ "public", "function", "addCompatible", "(", "$", "packageName", ",", "$", "channel", ",", "$", "minVersion", ",", "$", "maxVersion", ")", "{", "$", "package", "=", "$", "this", "->", "_packageXml", "->", "compatible", "->", "addChild", "(", "'package'", ")", ";", "$", "package", "->", "addChild", "(", "'name'", ",", "$", "packageName", ")", ";", "$", "package", "->", "addChild", "(", "'channel'", ",", "$", "channel", ")", ";", "$", "package", "->", "addChild", "(", "'min'", ",", "$", "minVersion", ")", ";", "$", "package", "->", "addChild", "(", "'max'", ",", "$", "maxVersion", ")", ";", "return", "$", "this", ";", "}" ]
Add value to <compatible />. @param string $packageName @param string $channel @param string $minVersion @param string $maxVersion @return Mage_Connect_Package
[ "Add", "value", "to", "<compatible", "/", ">", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L540-L548
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.setDependencyPhpVersion
public function setDependencyPhpVersion($minVersion, $maxVersion) { $parent = $this->_packageXml->dependencies; $parent = $this->_getNode('required', $parent); $parent = $this->_getNode('php', $parent); $parent->addChild('min', $minVersion); $parent->addChild('max', $maxVersion); return $this; }
php
public function setDependencyPhpVersion($minVersion, $maxVersion) { $parent = $this->_packageXml->dependencies; $parent = $this->_getNode('required', $parent); $parent = $this->_getNode('php', $parent); $parent->addChild('min', $minVersion); $parent->addChild('max', $maxVersion); return $this; }
[ "public", "function", "setDependencyPhpVersion", "(", "$", "minVersion", ",", "$", "maxVersion", ")", "{", "$", "parent", "=", "$", "this", "->", "_packageXml", "->", "dependencies", ";", "$", "parent", "=", "$", "this", "->", "_getNode", "(", "'required'", ",", "$", "parent", ")", ";", "$", "parent", "=", "$", "this", "->", "_getNode", "(", "'php'", ",", "$", "parent", ")", ";", "$", "parent", "->", "addChild", "(", "'min'", ",", "$", "minVersion", ")", ";", "$", "parent", "->", "addChild", "(", "'max'", ",", "$", "maxVersion", ")", ";", "return", "$", "this", ";", "}" ]
Set dependency from php version. @param string $minVersion @param string $maxVersion @return Mage_Connect_Package
[ "Set", "dependency", "from", "php", "version", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L557-L565
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.checkPhpVersion
public function checkPhpVersion() { $min = $this->getDependencyPhpVersionMin(); $max = $this->getDependencyPhpVersionMax(); $minOk = $min? version_compare(PHP_VERSION, $min, ">=") : true; $maxOk = $max? version_compare(PHP_VERSION, $max, "<=") : true; if(!$minOk || !$maxOk) { $err = "requires PHP version "; if($min && $max) { $err .= " >= $min and <= $max "; } elseif($min) { $err .= " >= $min "; } elseif($max) { $err .= " <= $max "; } $err .= " current is: ".PHP_VERSION; return $err; } return true; }
php
public function checkPhpVersion() { $min = $this->getDependencyPhpVersionMin(); $max = $this->getDependencyPhpVersionMax(); $minOk = $min? version_compare(PHP_VERSION, $min, ">=") : true; $maxOk = $max? version_compare(PHP_VERSION, $max, "<=") : true; if(!$minOk || !$maxOk) { $err = "requires PHP version "; if($min && $max) { $err .= " >= $min and <= $max "; } elseif($min) { $err .= " >= $min "; } elseif($max) { $err .= " <= $max "; } $err .= " current is: ".PHP_VERSION; return $err; } return true; }
[ "public", "function", "checkPhpVersion", "(", ")", "{", "$", "min", "=", "$", "this", "->", "getDependencyPhpVersionMin", "(", ")", ";", "$", "max", "=", "$", "this", "->", "getDependencyPhpVersionMax", "(", ")", ";", "$", "minOk", "=", "$", "min", "?", "version_compare", "(", "PHP_VERSION", ",", "$", "min", ",", "\">=\"", ")", ":", "true", ";", "$", "maxOk", "=", "$", "max", "?", "version_compare", "(", "PHP_VERSION", ",", "$", "max", ",", "\"<=\"", ")", ":", "true", ";", "if", "(", "!", "$", "minOk", "||", "!", "$", "maxOk", ")", "{", "$", "err", "=", "\"requires PHP version \"", ";", "if", "(", "$", "min", "&&", "$", "max", ")", "{", "$", "err", ".=", "\" >= $min and <= $max \"", ";", "}", "elseif", "(", "$", "min", ")", "{", "$", "err", ".=", "\" >= $min \"", ";", "}", "elseif", "(", "$", "max", ")", "{", "$", "err", ".=", "\" <= $max \"", ";", "}", "$", "err", ".=", "\" current is: \"", ".", "PHP_VERSION", ";", "return", "$", "err", ";", "}", "return", "true", ";", "}" ]
Check PHP version restriction @param $phpVersion PHP_VERSION by default @return true | string
[ "Check", "PHP", "version", "restriction" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L573-L594
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.checkPhpDependencies
public function checkPhpDependencies() { $errors = array(); foreach($this->getDependencyPhpExtensions() as $dep) { if(!extension_loaded($dep['name'])) { $errors[] = $dep; } } if(count($errors)) { return $errors; } return true; }
php
public function checkPhpDependencies() { $errors = array(); foreach($this->getDependencyPhpExtensions() as $dep) { if(!extension_loaded($dep['name'])) { $errors[] = $dep; } } if(count($errors)) { return $errors; } return true; }
[ "public", "function", "checkPhpDependencies", "(", ")", "{", "$", "errors", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getDependencyPhpExtensions", "(", ")", "as", "$", "dep", ")", "{", "if", "(", "!", "extension_loaded", "(", "$", "dep", "[", "'name'", "]", ")", ")", "{", "$", "errors", "[", "]", "=", "$", "dep", ";", "}", "}", "if", "(", "count", "(", "$", "errors", ")", ")", "{", "return", "$", "errors", ";", "}", "return", "true", ";", "}" ]
Check PHP extensions availability @throws Exceptiom on failure @return true | array
[ "Check", "PHP", "extensions", "availability" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L602-L615
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.setDependencyPhpExtensions
public function setDependencyPhpExtensions($extensions) { foreach($extensions as $_extension) { $this->addDependencyExtension( $_extension['name'], $_extension['min_version'], $_extension['max_version'] ); } return $this; }
php
public function setDependencyPhpExtensions($extensions) { foreach($extensions as $_extension) { $this->addDependencyExtension( $_extension['name'], $_extension['min_version'], $_extension['max_version'] ); } return $this; }
[ "public", "function", "setDependencyPhpExtensions", "(", "$", "extensions", ")", "{", "foreach", "(", "$", "extensions", "as", "$", "_extension", ")", "{", "$", "this", "->", "addDependencyExtension", "(", "$", "_extension", "[", "'name'", "]", ",", "$", "_extension", "[", "'min_version'", "]", ",", "$", "_extension", "[", "'max_version'", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set dependency from php extensions. $extension has next view: array('curl', 'mysql') @param array|string $extensions @return Mage_Connect_Package
[ "Set", "dependency", "from", "php", "extensions", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L627-L637
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.setDependencyPackages
public function setDependencyPackages($packages, $clear = false) { if($clear) { unset($this->_packageXml->dependencies->required->package); } foreach($packages as $_package) { $filesArrayCondition = isset($_package['files']) && is_array($_package['files']); $filesArray = $filesArrayCondition ? $_package['files'] : array(); $this->addDependencyPackage( $_package['name'], $_package['channel'], $_package['min_version'], $_package['max_version'], $filesArray ); } return $this; }
php
public function setDependencyPackages($packages, $clear = false) { if($clear) { unset($this->_packageXml->dependencies->required->package); } foreach($packages as $_package) { $filesArrayCondition = isset($_package['files']) && is_array($_package['files']); $filesArray = $filesArrayCondition ? $_package['files'] : array(); $this->addDependencyPackage( $_package['name'], $_package['channel'], $_package['min_version'], $_package['max_version'], $filesArray ); } return $this; }
[ "public", "function", "setDependencyPackages", "(", "$", "packages", ",", "$", "clear", "=", "false", ")", "{", "if", "(", "$", "clear", ")", "{", "unset", "(", "$", "this", "->", "_packageXml", "->", "dependencies", "->", "required", "->", "package", ")", ";", "}", "foreach", "(", "$", "packages", "as", "$", "_package", ")", "{", "$", "filesArrayCondition", "=", "isset", "(", "$", "_package", "[", "'files'", "]", ")", "&&", "is_array", "(", "$", "_package", "[", "'files'", "]", ")", ";", "$", "filesArray", "=", "$", "filesArrayCondition", "?", "$", "_package", "[", "'files'", "]", ":", "array", "(", ")", ";", "$", "this", "->", "addDependencyPackage", "(", "$", "_package", "[", "'name'", "]", ",", "$", "_package", "[", "'channel'", "]", ",", "$", "_package", "[", "'min_version'", "]", ",", "$", "_package", "[", "'max_version'", "]", ",", "$", "filesArray", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set dependency from another packages. $packages should contain: array( array('name'=>'test1', 'channel'=>'test1', 'min_version'=>'0.0.1', 'max_version'=>'0.1.0'), array('name'=>'test2', 'channel'=>'test2', 'min_version'=>'0.0.1', 'max_version'=>'0.1.0'), ) @param array $packages @param bool $clear @return Mage_Connect_Package
[ "Set", "dependency", "from", "another", "packages", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L652-L672
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.addDependencyPackage
public function addDependencyPackage($name, $channel, $minVersion, $maxVersion, $files = array()) { $parent = $this->_packageXml->dependencies; $parent = $this->_getNode('required', $parent); $parent = $parent->addChild('package'); $parent->addChild('name', $name); $parent->addChild('channel', $channel); $parent->addChild('min', $minVersion); $parent->addChild('max', $maxVersion); if(count($files)) { $parent = $parent->addChild('files'); foreach($files as $row) { if(!empty($row['target']) && !empty($row['path'])) { $node = $parent->addChild("file"); $node["target"] = $row['target']; $node["path"] = $row['path']; } } } return $this; }
php
public function addDependencyPackage($name, $channel, $minVersion, $maxVersion, $files = array()) { $parent = $this->_packageXml->dependencies; $parent = $this->_getNode('required', $parent); $parent = $parent->addChild('package'); $parent->addChild('name', $name); $parent->addChild('channel', $channel); $parent->addChild('min', $minVersion); $parent->addChild('max', $maxVersion); if(count($files)) { $parent = $parent->addChild('files'); foreach($files as $row) { if(!empty($row['target']) && !empty($row['path'])) { $node = $parent->addChild("file"); $node["target"] = $row['target']; $node["path"] = $row['path']; } } } return $this; }
[ "public", "function", "addDependencyPackage", "(", "$", "name", ",", "$", "channel", ",", "$", "minVersion", ",", "$", "maxVersion", ",", "$", "files", "=", "array", "(", ")", ")", "{", "$", "parent", "=", "$", "this", "->", "_packageXml", "->", "dependencies", ";", "$", "parent", "=", "$", "this", "->", "_getNode", "(", "'required'", ",", "$", "parent", ")", ";", "$", "parent", "=", "$", "parent", "->", "addChild", "(", "'package'", ")", ";", "$", "parent", "->", "addChild", "(", "'name'", ",", "$", "name", ")", ";", "$", "parent", "->", "addChild", "(", "'channel'", ",", "$", "channel", ")", ";", "$", "parent", "->", "addChild", "(", "'min'", ",", "$", "minVersion", ")", ";", "$", "parent", "->", "addChild", "(", "'max'", ",", "$", "maxVersion", ")", ";", "if", "(", "count", "(", "$", "files", ")", ")", "{", "$", "parent", "=", "$", "parent", "->", "addChild", "(", "'files'", ")", ";", "foreach", "(", "$", "files", "as", "$", "row", ")", "{", "if", "(", "!", "empty", "(", "$", "row", "[", "'target'", "]", ")", "&&", "!", "empty", "(", "$", "row", "[", "'path'", "]", ")", ")", "{", "$", "node", "=", "$", "parent", "->", "addChild", "(", "\"file\"", ")", ";", "$", "node", "[", "\"target\"", "]", "=", "$", "row", "[", "'target'", "]", ";", "$", "node", "[", "\"path\"", "]", "=", "$", "row", "[", "'path'", "]", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Add package to dependency packages. @param string $package @param string $channel @param string $minVersion @param string $maxVersion @return Mage_Connect_Package
[ "Add", "package", "to", "dependency", "packages", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L685-L706
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.addDependencyExtension
public function addDependencyExtension($name, $minVersion, $maxVersion) { $parent = $this->_packageXml->dependencies; $parent = $this->_getNode('required', $parent); $parent = $parent->addChild('extension'); $parent->addChild('name', $name); $parent->addChild('min', $minVersion); $parent->addChild('max', $maxVersion); return $this; }
php
public function addDependencyExtension($name, $minVersion, $maxVersion) { $parent = $this->_packageXml->dependencies; $parent = $this->_getNode('required', $parent); $parent = $parent->addChild('extension'); $parent->addChild('name', $name); $parent->addChild('min', $minVersion); $parent->addChild('max', $maxVersion); return $this; }
[ "public", "function", "addDependencyExtension", "(", "$", "name", ",", "$", "minVersion", ",", "$", "maxVersion", ")", "{", "$", "parent", "=", "$", "this", "->", "_packageXml", "->", "dependencies", ";", "$", "parent", "=", "$", "this", "->", "_getNode", "(", "'required'", ",", "$", "parent", ")", ";", "$", "parent", "=", "$", "parent", "->", "addChild", "(", "'extension'", ")", ";", "$", "parent", "->", "addChild", "(", "'name'", ",", "$", "name", ")", ";", "$", "parent", "->", "addChild", "(", "'min'", ",", "$", "minVersion", ")", ";", "$", "parent", "->", "addChild", "(", "'max'", ",", "$", "maxVersion", ")", ";", "return", "$", "this", ";", "}" ]
Add package to dependency extension. @param string $package @param string $minVersion @param string $maxVersion @return Mage_Connect_Package
[ "Add", "package", "to", "dependency", "extension", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L718-L727
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.getAuthors
public function getAuthors() { if (is_array($this->_authors)) return $this->_authors; $this->_authors = array(); if(!isset($this->_packageXml->authors->author)) { return array(); } foreach ($this->_packageXml->authors->author as $_author) { $this->_authors[] = array( 'name' => (string)$_author->name, 'user' => (string)$_author->user, 'email'=> (string)$_author->email ); } return $this->_authors; }
php
public function getAuthors() { if (is_array($this->_authors)) return $this->_authors; $this->_authors = array(); if(!isset($this->_packageXml->authors->author)) { return array(); } foreach ($this->_packageXml->authors->author as $_author) { $this->_authors[] = array( 'name' => (string)$_author->name, 'user' => (string)$_author->user, 'email'=> (string)$_author->email ); } return $this->_authors; }
[ "public", "function", "getAuthors", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "_authors", ")", ")", "return", "$", "this", "->", "_authors", ";", "$", "this", "->", "_authors", "=", "array", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_packageXml", "->", "authors", "->", "author", ")", ")", "{", "return", "array", "(", ")", ";", "}", "foreach", "(", "$", "this", "->", "_packageXml", "->", "authors", "->", "author", "as", "$", "_author", ")", "{", "$", "this", "->", "_authors", "[", "]", "=", "array", "(", "'name'", "=>", "(", "string", ")", "$", "_author", "->", "name", ",", "'user'", "=>", "(", "string", ")", "$", "_author", "->", "user", ",", "'email'", "=>", "(", "string", ")", "$", "_author", "->", "email", ")", ";", "}", "return", "$", "this", "->", "_authors", ";", "}" ]
Get list of authors in associative array. @return array
[ "Get", "list", "of", "authors", "in", "associative", "array", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L776-L791
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.getContents
public function getContents() { if (is_array($this->_contents)) return $this->_contents; $this->_contents = array(); if(!isset($this->_packageXml->contents->target)) { return $this->_contents; } foreach($this->_packageXml->contents->target as $target) { $targetUri = $this->getTarget()->getTargetUri($target['name']); $this->_getList($target, $targetUri); } return $this->_contents; }
php
public function getContents() { if (is_array($this->_contents)) return $this->_contents; $this->_contents = array(); if(!isset($this->_packageXml->contents->target)) { return $this->_contents; } foreach($this->_packageXml->contents->target as $target) { $targetUri = $this->getTarget()->getTargetUri($target['name']); $this->_getList($target, $targetUri); } return $this->_contents; }
[ "public", "function", "getContents", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "_contents", ")", ")", "return", "$", "this", "->", "_contents", ";", "$", "this", "->", "_contents", "=", "array", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_packageXml", "->", "contents", "->", "target", ")", ")", "{", "return", "$", "this", "->", "_contents", ";", "}", "foreach", "(", "$", "this", "->", "_packageXml", "->", "contents", "->", "target", "as", "$", "target", ")", "{", "$", "targetUri", "=", "$", "this", "->", "getTarget", "(", ")", "->", "getTargetUri", "(", "$", "target", "[", "'name'", "]", ")", ";", "$", "this", "->", "_getList", "(", "$", "target", ",", "$", "targetUri", ")", ";", "}", "return", "$", "this", "->", "_contents", ";", "}" ]
Create list of all files from package.xml @return array
[ "Create", "list", "of", "all", "files", "from", "package", ".", "xml" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L868-L880
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package._getList
protected function _getList($parent, $path) { if (count($parent) == 0) { $this->_contents[] = $path; } else { foreach($parent as $_content) { $this->_getList($_content, ($path ? $path . DS : '') . $_content['name']); } } }
php
protected function _getList($parent, $path) { if (count($parent) == 0) { $this->_contents[] = $path; } else { foreach($parent as $_content) { $this->_getList($_content, ($path ? $path . DS : '') . $_content['name']); } } }
[ "protected", "function", "_getList", "(", "$", "parent", ",", "$", "path", ")", "{", "if", "(", "count", "(", "$", "parent", ")", "==", "0", ")", "{", "$", "this", "->", "_contents", "[", "]", "=", "$", "path", ";", "}", "else", "{", "foreach", "(", "$", "parent", "as", "$", "_content", ")", "{", "$", "this", "->", "_getList", "(", "$", "_content", ",", "(", "$", "path", "?", "$", "path", ".", "DS", ":", "''", ")", ".", "$", "_content", "[", "'name'", "]", ")", ";", "}", "}", "}" ]
Helper for getContents(). Create recursively list. @param SimpleXMLElement $parent @param string $path
[ "Helper", "for", "getContents", "()", ".", "Create", "recursively", "list", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L888-L897
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.getHashContents
public function getHashContents() { if (is_array($this->_hashContents)) return $this->_hashContents; $this->_hashContents = array(); if(!isset($this->_packageXml->contents->target)) { return $this->_hashContents; } foreach($this->_packageXml->contents->target as $target) { $targetUri = $this->getTarget()->getTargetUri($target['name']); $this->_getHashList($target, $targetUri); } return $this->_hashContents; }
php
public function getHashContents() { if (is_array($this->_hashContents)) return $this->_hashContents; $this->_hashContents = array(); if(!isset($this->_packageXml->contents->target)) { return $this->_hashContents; } foreach($this->_packageXml->contents->target as $target) { $targetUri = $this->getTarget()->getTargetUri($target['name']); $this->_getHashList($target, $targetUri); } return $this->_hashContents; }
[ "public", "function", "getHashContents", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "_hashContents", ")", ")", "return", "$", "this", "->", "_hashContents", ";", "$", "this", "->", "_hashContents", "=", "array", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_packageXml", "->", "contents", "->", "target", ")", ")", "{", "return", "$", "this", "->", "_hashContents", ";", "}", "foreach", "(", "$", "this", "->", "_packageXml", "->", "contents", "->", "target", "as", "$", "target", ")", "{", "$", "targetUri", "=", "$", "this", "->", "getTarget", "(", ")", "->", "getTargetUri", "(", "$", "target", "[", "'name'", "]", ")", ";", "$", "this", "->", "_getHashList", "(", "$", "target", ",", "$", "targetUri", ")", ";", "}", "return", "$", "this", "->", "_hashContents", ";", "}" ]
Create list of all files from package.xml with hash @return array
[ "Create", "list", "of", "all", "files", "from", "package", ".", "xml", "with", "hash" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L904-L916
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package._getHashList
protected function _getHashList($parent, $path, $hash='') { if (count($parent) == 0) { $this->_hashContents[$path] = $hash; } else { foreach($parent as $_content) { $contentHash = ''; if (isset($_content['hash'])) { $contentHash = (string)$_content['hash']; } $this->_getHashList($_content, ($path ? $path . DS : '') . $_content['name'], $contentHash); } } }
php
protected function _getHashList($parent, $path, $hash='') { if (count($parent) == 0) { $this->_hashContents[$path] = $hash; } else { foreach($parent as $_content) { $contentHash = ''; if (isset($_content['hash'])) { $contentHash = (string)$_content['hash']; } $this->_getHashList($_content, ($path ? $path . DS : '') . $_content['name'], $contentHash); } } }
[ "protected", "function", "_getHashList", "(", "$", "parent", ",", "$", "path", ",", "$", "hash", "=", "''", ")", "{", "if", "(", "count", "(", "$", "parent", ")", "==", "0", ")", "{", "$", "this", "->", "_hashContents", "[", "$", "path", "]", "=", "$", "hash", ";", "}", "else", "{", "foreach", "(", "$", "parent", "as", "$", "_content", ")", "{", "$", "contentHash", "=", "''", ";", "if", "(", "isset", "(", "$", "_content", "[", "'hash'", "]", ")", ")", "{", "$", "contentHash", "=", "(", "string", ")", "$", "_content", "[", "'hash'", "]", ";", "}", "$", "this", "->", "_getHashList", "(", "$", "_content", ",", "(", "$", "path", "?", "$", "path", ".", "DS", ":", "''", ")", ".", "$", "_content", "[", "'name'", "]", ",", "$", "contentHash", ")", ";", "}", "}", "}" ]
Helper for getHashContents(). Create recursively list. @param SimpleXMLElement $parent @param string $path
[ "Helper", "for", "getHashContents", "()", ".", "Create", "recursively", "list", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L924-L937
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.getCompatible
public function getCompatible() { if (is_array($this->_compatible)) return $this->_compatible; $this->_compatible = array(); if(!isset($this->_packageXml->compatible->package)) { return array(); } foreach ($this->_packageXml->compatible->package as $_package) { $this->_compatible[] = array( 'name' => (string)$_package->name, 'channel' => (string)$_package->channel, 'min' => (string)$_package->min, 'max' => (string)$_package->max ); } return $this->_compatible; }
php
public function getCompatible() { if (is_array($this->_compatible)) return $this->_compatible; $this->_compatible = array(); if(!isset($this->_packageXml->compatible->package)) { return array(); } foreach ($this->_packageXml->compatible->package as $_package) { $this->_compatible[] = array( 'name' => (string)$_package->name, 'channel' => (string)$_package->channel, 'min' => (string)$_package->min, 'max' => (string)$_package->max ); } return $this->_compatible; }
[ "public", "function", "getCompatible", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "_compatible", ")", ")", "return", "$", "this", "->", "_compatible", ";", "$", "this", "->", "_compatible", "=", "array", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_packageXml", "->", "compatible", "->", "package", ")", ")", "{", "return", "array", "(", ")", ";", "}", "foreach", "(", "$", "this", "->", "_packageXml", "->", "compatible", "->", "package", "as", "$", "_package", ")", "{", "$", "this", "->", "_compatible", "[", "]", "=", "array", "(", "'name'", "=>", "(", "string", ")", "$", "_package", "->", "name", ",", "'channel'", "=>", "(", "string", ")", "$", "_package", "->", "channel", ",", "'min'", "=>", "(", "string", ")", "$", "_package", "->", "min", ",", "'max'", "=>", "(", "string", ")", "$", "_package", "->", "max", ")", ";", "}", "return", "$", "this", "->", "_compatible", ";", "}" ]
Get compatible packages. @return array
[ "Get", "compatible", "packages", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L944-L960
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.getDependencyPhpVersionMin
public function getDependencyPhpVersionMin() { if(!isset($this->_packageXml->dependencies->required->php->min)) { return false; } return (string)$this->_packageXml->dependencies->required->php->min; }
php
public function getDependencyPhpVersionMin() { if(!isset($this->_packageXml->dependencies->required->php->min)) { return false; } return (string)$this->_packageXml->dependencies->required->php->min; }
[ "public", "function", "getDependencyPhpVersionMin", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_packageXml", "->", "dependencies", "->", "required", "->", "php", "->", "min", ")", ")", "{", "return", "false", ";", "}", "return", "(", "string", ")", "$", "this", "->", "_packageXml", "->", "dependencies", "->", "required", "->", "php", "->", "min", ";", "}" ]
Getter @return string
[ "Getter" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L967-L973
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.getDependencyPhpVersionMax
public function getDependencyPhpVersionMax() { if(!isset($this->_packageXml->dependencies->required->php->max)) { return false; } return (string)$this->_packageXml->dependencies->required->php->max; }
php
public function getDependencyPhpVersionMax() { if(!isset($this->_packageXml->dependencies->required->php->max)) { return false; } return (string)$this->_packageXml->dependencies->required->php->max; }
[ "public", "function", "getDependencyPhpVersionMax", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_packageXml", "->", "dependencies", "->", "required", "->", "php", "->", "max", ")", ")", "{", "return", "false", ";", "}", "return", "(", "string", ")", "$", "this", "->", "_packageXml", "->", "dependencies", "->", "required", "->", "php", "->", "max", ";", "}" ]
Getter @return string
[ "Getter" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L980-L986
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.getDependencyPhpExtensions
public function getDependencyPhpExtensions() { if (is_array($this->_dependencyPhpExtensions)) return $this->_dependencyPhpExtensions; $this->_dependencyPhpExtensions = array(); if (!isset($this->_packageXml->dependencies->required->extension)) { return $this->_dependencyPhpExtensions; } foreach($this->_packageXml->dependencies->required->extension as $_package) { $this->_dependencyPhpExtensions[] = array( 'name' => (string)$_package->name, 'min' => (string)$_package->min, 'max' => (string)$_package->max, ); } return $this->_dependencyPhpExtensions; }
php
public function getDependencyPhpExtensions() { if (is_array($this->_dependencyPhpExtensions)) return $this->_dependencyPhpExtensions; $this->_dependencyPhpExtensions = array(); if (!isset($this->_packageXml->dependencies->required->extension)) { return $this->_dependencyPhpExtensions; } foreach($this->_packageXml->dependencies->required->extension as $_package) { $this->_dependencyPhpExtensions[] = array( 'name' => (string)$_package->name, 'min' => (string)$_package->min, 'max' => (string)$_package->max, ); } return $this->_dependencyPhpExtensions; }
[ "public", "function", "getDependencyPhpExtensions", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "_dependencyPhpExtensions", ")", ")", "return", "$", "this", "->", "_dependencyPhpExtensions", ";", "$", "this", "->", "_dependencyPhpExtensions", "=", "array", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_packageXml", "->", "dependencies", "->", "required", "->", "extension", ")", ")", "{", "return", "$", "this", "->", "_dependencyPhpExtensions", ";", "}", "foreach", "(", "$", "this", "->", "_packageXml", "->", "dependencies", "->", "required", "->", "extension", "as", "$", "_package", ")", "{", "$", "this", "->", "_dependencyPhpExtensions", "[", "]", "=", "array", "(", "'name'", "=>", "(", "string", ")", "$", "_package", "->", "name", ",", "'min'", "=>", "(", "string", ")", "$", "_package", "->", "min", ",", "'max'", "=>", "(", "string", ")", "$", "_package", "->", "max", ",", ")", ";", "}", "return", "$", "this", "->", "_dependencyPhpExtensions", ";", "}" ]
Get list of php extensions. @return array
[ "Get", "list", "of", "php", "extensions", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L993-L1008
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.getDependencyPackages
public function getDependencyPackages() { $this->_dependencyPackages = array(); if (!isset($this->_packageXml->dependencies->required->package)) { return $this->_dependencyPackages; } foreach($this->_packageXml->dependencies->required->package as $_package) { $add = array( 'name' => (string)$_package->name, 'channel' => (string)$_package->channel, 'min' => (string)$_package->min, 'max' => (string)$_package->max, ); if(isset($_package->files)) { $add['files'] = array(); foreach($_package->files as $node) { if(isset($node->file)) { $add['files'][] = array('target' => (string) $node->file['target'], 'path'=> (string) $node->file['path']); } } } $this->_dependencyPackages[] = $add; } return $this->_dependencyPackages; }
php
public function getDependencyPackages() { $this->_dependencyPackages = array(); if (!isset($this->_packageXml->dependencies->required->package)) { return $this->_dependencyPackages; } foreach($this->_packageXml->dependencies->required->package as $_package) { $add = array( 'name' => (string)$_package->name, 'channel' => (string)$_package->channel, 'min' => (string)$_package->min, 'max' => (string)$_package->max, ); if(isset($_package->files)) { $add['files'] = array(); foreach($_package->files as $node) { if(isset($node->file)) { $add['files'][] = array('target' => (string) $node->file['target'], 'path'=> (string) $node->file['path']); } } } $this->_dependencyPackages[] = $add; } return $this->_dependencyPackages; }
[ "public", "function", "getDependencyPackages", "(", ")", "{", "$", "this", "->", "_dependencyPackages", "=", "array", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_packageXml", "->", "dependencies", "->", "required", "->", "package", ")", ")", "{", "return", "$", "this", "->", "_dependencyPackages", ";", "}", "foreach", "(", "$", "this", "->", "_packageXml", "->", "dependencies", "->", "required", "->", "package", "as", "$", "_package", ")", "{", "$", "add", "=", "array", "(", "'name'", "=>", "(", "string", ")", "$", "_package", "->", "name", ",", "'channel'", "=>", "(", "string", ")", "$", "_package", "->", "channel", ",", "'min'", "=>", "(", "string", ")", "$", "_package", "->", "min", ",", "'max'", "=>", "(", "string", ")", "$", "_package", "->", "max", ",", ")", ";", "if", "(", "isset", "(", "$", "_package", "->", "files", ")", ")", "{", "$", "add", "[", "'files'", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "_package", "->", "files", "as", "$", "node", ")", "{", "if", "(", "isset", "(", "$", "node", "->", "file", ")", ")", "{", "$", "add", "[", "'files'", "]", "[", "]", "=", "array", "(", "'target'", "=>", "(", "string", ")", "$", "node", "->", "file", "[", "'target'", "]", ",", "'path'", "=>", "(", "string", ")", "$", "node", "->", "file", "[", "'path'", "]", ")", ";", "}", "}", "}", "$", "this", "->", "_dependencyPackages", "[", "]", "=", "$", "add", ";", "}", "return", "$", "this", "->", "_dependencyPackages", ";", "}" ]
Get list of dependency packages. @return array
[ "Get", "list", "of", "dependency", "packages", "." ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L1015-L1040
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.validate
public function validate() { $v = $this->validator(); /** * Validation map * * Format: * * 'key' => array( * 'method' => this class method name to call, string, required * 'method_args' => optional args for 'method' call, array, optional * 'v_method' => validator method to call, string, required * 'error' => custom error string when validation fails, optional * if not set, error string fprmatted as "Invalid '$key' specified" * 'v_error_method' => validator method - when called returned error string * prepared by validator, optional, * if not set => see 'error' * 'optional' => optional value, if it's empty validation result ignored * */ $validateMap = array( 'name' => array('method' => 'getName', 'v_method' => 'validatePackageName', 'error'=>"Invalid package name, allowed: [a-zA-Z0-9_-] chars"), 'version' => array('method' => 'getVersion', 'v_method' => 'validateVersion', 'error'=>"Invalid version, should be like: x.x.x"), 'stability' => array('method' => 'getStability', 'v_method' => 'validateStability', 'error'=>"Invalid stability"), 'date' => array('method' => 'getDate', 'v_method' => 'validateDate', 'error'=>"Invalid date, should be YYYY-DD-MM"), 'license_uri' => array('method' => 'getLicenseUri', 'v_method' => 'validateLicenseUrl', 'error'=>"Invalid license URL"), 'channel' => array('method' => 'getChannel', 'v_method' => 'validateChannelNameOrUri', 'error'=>"Invalid channel URL"), 'authors' => array('method' => 'getAuthors', 'v_method' => 'validateAuthors', 'v_error_method' => 'getErrors'), 'php_min' => array('method' => 'getDependencyPhpVersionMin', 'v_method' => 'validateVersion', 'error' => 'PHP minimum version invalid', 'optional' => true ), 'php_max' => array('method' => 'getDependencyPhpVersionMax', 'v_method' => 'validateVersion', 'error' => 'PHP maximum version invalid', 'optional' => true ), 'compatible' => array('method' => 'getCompatible', 'v_method' => 'validateCompatible', 'v_error_method' => 'getErrors'), 'content' => array('method' => 'getContents', 'v_method' => 'validateContents', 'v_args' => array('config' => $this->getConfig()), 'v_error_method' => 'getErrors'), ); $errors = array(); /** * Iterate validation map */ foreach($validateMap as $name=>$data) { /** * Check mandatory rules fields */ if(!isset($data['method'], $data['v_method'])) { throw new Mage_Exception("Invalid rules specified!"); } $method = $data['method']; $validatorMethod = $data['v_method']; /** * If $optional === false, value is mandatory */ $optional = isset($data['optional']) ? (bool) $data['optional'] : false; /** * Check for method availability, package */ if(!method_exists($this, $method)) { throw new Mage_Exception("Invalid method specified for Package : $method"); } /** * Check for method availability, validator */ if(!method_exists($v, $validatorMethod)) { throw new Mage_Exception("Invalid method specified for Validator : $validatorMethod"); } /** * If $data['error'] => get error string from $data['error'] * Else concatenate "Invalid '{$name}' specified" */ $errorString = isset($data['error']) ? $data['error'] : "Invalid '{$name}' specified"; /** * Additional method args check * array() by default */ $methodArgs = isset($data['method_args']) ? $data['method_args'] : array(); /** * Call package method */ $out = @call_user_func_array(array($this, $method), $methodArgs); /** * Skip if result is empty and value is optional */ if(empty($out) && $optional) { continue; } /** * Additional validator arguments, merged with array($out) */ $validatorArgs = isset($data['v_args']) ? array_merge(array($out), $data['v_args']) : array($out); /** * Get validation result */ $result = call_user_func_array(array($v, $validatorMethod), $validatorArgs); /** * Skip if validation success */ if($result) { continue; } /** * From where to get error string? * If validator callback method specified, call it to get errors array * Else get it from $errorString - local error string */ $validatorFetchErrorsMethod = isset($data['v_error_method']) ? $data['v_error_method'] : false; if (false !== $validatorFetchErrorsMethod) { $errorString = call_user_func_array(array($v, $validatorFetchErrorsMethod), array()); } /** * If errors is array => merge * Else append */ if(is_array($errorString)) { $errors = array_merge($errors, $errorString); } else { $errors[] = $errorString; } } /** * Set local errors */ $this->setErrors($errors); /** * Return true if there's no errors :) */ return ! $this->hasErrors(); }
php
public function validate() { $v = $this->validator(); /** * Validation map * * Format: * * 'key' => array( * 'method' => this class method name to call, string, required * 'method_args' => optional args for 'method' call, array, optional * 'v_method' => validator method to call, string, required * 'error' => custom error string when validation fails, optional * if not set, error string fprmatted as "Invalid '$key' specified" * 'v_error_method' => validator method - when called returned error string * prepared by validator, optional, * if not set => see 'error' * 'optional' => optional value, if it's empty validation result ignored * */ $validateMap = array( 'name' => array('method' => 'getName', 'v_method' => 'validatePackageName', 'error'=>"Invalid package name, allowed: [a-zA-Z0-9_-] chars"), 'version' => array('method' => 'getVersion', 'v_method' => 'validateVersion', 'error'=>"Invalid version, should be like: x.x.x"), 'stability' => array('method' => 'getStability', 'v_method' => 'validateStability', 'error'=>"Invalid stability"), 'date' => array('method' => 'getDate', 'v_method' => 'validateDate', 'error'=>"Invalid date, should be YYYY-DD-MM"), 'license_uri' => array('method' => 'getLicenseUri', 'v_method' => 'validateLicenseUrl', 'error'=>"Invalid license URL"), 'channel' => array('method' => 'getChannel', 'v_method' => 'validateChannelNameOrUri', 'error'=>"Invalid channel URL"), 'authors' => array('method' => 'getAuthors', 'v_method' => 'validateAuthors', 'v_error_method' => 'getErrors'), 'php_min' => array('method' => 'getDependencyPhpVersionMin', 'v_method' => 'validateVersion', 'error' => 'PHP minimum version invalid', 'optional' => true ), 'php_max' => array('method' => 'getDependencyPhpVersionMax', 'v_method' => 'validateVersion', 'error' => 'PHP maximum version invalid', 'optional' => true ), 'compatible' => array('method' => 'getCompatible', 'v_method' => 'validateCompatible', 'v_error_method' => 'getErrors'), 'content' => array('method' => 'getContents', 'v_method' => 'validateContents', 'v_args' => array('config' => $this->getConfig()), 'v_error_method' => 'getErrors'), ); $errors = array(); /** * Iterate validation map */ foreach($validateMap as $name=>$data) { /** * Check mandatory rules fields */ if(!isset($data['method'], $data['v_method'])) { throw new Mage_Exception("Invalid rules specified!"); } $method = $data['method']; $validatorMethod = $data['v_method']; /** * If $optional === false, value is mandatory */ $optional = isset($data['optional']) ? (bool) $data['optional'] : false; /** * Check for method availability, package */ if(!method_exists($this, $method)) { throw new Mage_Exception("Invalid method specified for Package : $method"); } /** * Check for method availability, validator */ if(!method_exists($v, $validatorMethod)) { throw new Mage_Exception("Invalid method specified for Validator : $validatorMethod"); } /** * If $data['error'] => get error string from $data['error'] * Else concatenate "Invalid '{$name}' specified" */ $errorString = isset($data['error']) ? $data['error'] : "Invalid '{$name}' specified"; /** * Additional method args check * array() by default */ $methodArgs = isset($data['method_args']) ? $data['method_args'] : array(); /** * Call package method */ $out = @call_user_func_array(array($this, $method), $methodArgs); /** * Skip if result is empty and value is optional */ if(empty($out) && $optional) { continue; } /** * Additional validator arguments, merged with array($out) */ $validatorArgs = isset($data['v_args']) ? array_merge(array($out), $data['v_args']) : array($out); /** * Get validation result */ $result = call_user_func_array(array($v, $validatorMethod), $validatorArgs); /** * Skip if validation success */ if($result) { continue; } /** * From where to get error string? * If validator callback method specified, call it to get errors array * Else get it from $errorString - local error string */ $validatorFetchErrorsMethod = isset($data['v_error_method']) ? $data['v_error_method'] : false; if (false !== $validatorFetchErrorsMethod) { $errorString = call_user_func_array(array($v, $validatorFetchErrorsMethod), array()); } /** * If errors is array => merge * Else append */ if(is_array($errorString)) { $errors = array_merge($errors, $errorString); } else { $errors[] = $errorString; } } /** * Set local errors */ $this->setErrors($errors); /** * Return true if there's no errors :) */ return ! $this->hasErrors(); }
[ "public", "function", "validate", "(", ")", "{", "$", "v", "=", "$", "this", "->", "validator", "(", ")", ";", "/**\n * Validation map\n *\n * Format:\n *\n * 'key' => array(\n * 'method' => this class method name to call, string, required\n * 'method_args' => optional args for 'method' call, array, optional\n * 'v_method' => validator method to call, string, required\n * 'error' => custom error string when validation fails, optional\n * if not set, error string fprmatted as \"Invalid '$key' specified\"\n * 'v_error_method' => validator method - when called returned error string\n * prepared by validator, optional,\n * if not set => see 'error'\n * 'optional' => optional value, if it's empty validation result ignored\n *\n */", "$", "validateMap", "=", "array", "(", "'name'", "=>", "array", "(", "'method'", "=>", "'getName'", ",", "'v_method'", "=>", "'validatePackageName'", ",", "'error'", "=>", "\"Invalid package name, allowed: [a-zA-Z0-9_-] chars\"", ")", ",", "'version'", "=>", "array", "(", "'method'", "=>", "'getVersion'", ",", "'v_method'", "=>", "'validateVersion'", ",", "'error'", "=>", "\"Invalid version, should be like: x.x.x\"", ")", ",", "'stability'", "=>", "array", "(", "'method'", "=>", "'getStability'", ",", "'v_method'", "=>", "'validateStability'", ",", "'error'", "=>", "\"Invalid stability\"", ")", ",", "'date'", "=>", "array", "(", "'method'", "=>", "'getDate'", ",", "'v_method'", "=>", "'validateDate'", ",", "'error'", "=>", "\"Invalid date, should be YYYY-DD-MM\"", ")", ",", "'license_uri'", "=>", "array", "(", "'method'", "=>", "'getLicenseUri'", ",", "'v_method'", "=>", "'validateLicenseUrl'", ",", "'error'", "=>", "\"Invalid license URL\"", ")", ",", "'channel'", "=>", "array", "(", "'method'", "=>", "'getChannel'", ",", "'v_method'", "=>", "'validateChannelNameOrUri'", ",", "'error'", "=>", "\"Invalid channel URL\"", ")", ",", "'authors'", "=>", "array", "(", "'method'", "=>", "'getAuthors'", ",", "'v_method'", "=>", "'validateAuthors'", ",", "'v_error_method'", "=>", "'getErrors'", ")", ",", "'php_min'", "=>", "array", "(", "'method'", "=>", "'getDependencyPhpVersionMin'", ",", "'v_method'", "=>", "'validateVersion'", ",", "'error'", "=>", "'PHP minimum version invalid'", ",", "'optional'", "=>", "true", ")", ",", "'php_max'", "=>", "array", "(", "'method'", "=>", "'getDependencyPhpVersionMax'", ",", "'v_method'", "=>", "'validateVersion'", ",", "'error'", "=>", "'PHP maximum version invalid'", ",", "'optional'", "=>", "true", ")", ",", "'compatible'", "=>", "array", "(", "'method'", "=>", "'getCompatible'", ",", "'v_method'", "=>", "'validateCompatible'", ",", "'v_error_method'", "=>", "'getErrors'", ")", ",", "'content'", "=>", "array", "(", "'method'", "=>", "'getContents'", ",", "'v_method'", "=>", "'validateContents'", ",", "'v_args'", "=>", "array", "(", "'config'", "=>", "$", "this", "->", "getConfig", "(", ")", ")", ",", "'v_error_method'", "=>", "'getErrors'", ")", ",", ")", ";", "$", "errors", "=", "array", "(", ")", ";", "/**\n * Iterate validation map\n */", "foreach", "(", "$", "validateMap", "as", "$", "name", "=>", "$", "data", ")", "{", "/**\n * Check mandatory rules fields\n */", "if", "(", "!", "isset", "(", "$", "data", "[", "'method'", "]", ",", "$", "data", "[", "'v_method'", "]", ")", ")", "{", "throw", "new", "Mage_Exception", "(", "\"Invalid rules specified!\"", ")", ";", "}", "$", "method", "=", "$", "data", "[", "'method'", "]", ";", "$", "validatorMethod", "=", "$", "data", "[", "'v_method'", "]", ";", "/**\n * If $optional === false, value is mandatory\n */", "$", "optional", "=", "isset", "(", "$", "data", "[", "'optional'", "]", ")", "?", "(", "bool", ")", "$", "data", "[", "'optional'", "]", ":", "false", ";", "/**\n * Check for method availability, package\n */", "if", "(", "!", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "{", "throw", "new", "Mage_Exception", "(", "\"Invalid method specified for Package : $method\"", ")", ";", "}", "/**\n * Check for method availability, validator\n */", "if", "(", "!", "method_exists", "(", "$", "v", ",", "$", "validatorMethod", ")", ")", "{", "throw", "new", "Mage_Exception", "(", "\"Invalid method specified for Validator : $validatorMethod\"", ")", ";", "}", "/**\n * If $data['error'] => get error string from $data['error']\n * Else concatenate \"Invalid '{$name}' specified\"\n */", "$", "errorString", "=", "isset", "(", "$", "data", "[", "'error'", "]", ")", "?", "$", "data", "[", "'error'", "]", ":", "\"Invalid '{$name}' specified\"", ";", "/**\n * Additional method args check\n * array() by default\n */", "$", "methodArgs", "=", "isset", "(", "$", "data", "[", "'method_args'", "]", ")", "?", "$", "data", "[", "'method_args'", "]", ":", "array", "(", ")", ";", "/**\n * Call package method\n */", "$", "out", "=", "@", "call_user_func_array", "(", "array", "(", "$", "this", ",", "$", "method", ")", ",", "$", "methodArgs", ")", ";", "/**\n * Skip if result is empty and value is optional\n */", "if", "(", "empty", "(", "$", "out", ")", "&&", "$", "optional", ")", "{", "continue", ";", "}", "/**\n * Additional validator arguments, merged with array($out)\n */", "$", "validatorArgs", "=", "isset", "(", "$", "data", "[", "'v_args'", "]", ")", "?", "array_merge", "(", "array", "(", "$", "out", ")", ",", "$", "data", "[", "'v_args'", "]", ")", ":", "array", "(", "$", "out", ")", ";", "/**\n * Get validation result\n */", "$", "result", "=", "call_user_func_array", "(", "array", "(", "$", "v", ",", "$", "validatorMethod", ")", ",", "$", "validatorArgs", ")", ";", "/**\n * Skip if validation success\n */", "if", "(", "$", "result", ")", "{", "continue", ";", "}", "/**\n * From where to get error string?\n * If validator callback method specified, call it to get errors array\n * Else get it from $errorString - local error string\n */", "$", "validatorFetchErrorsMethod", "=", "isset", "(", "$", "data", "[", "'v_error_method'", "]", ")", "?", "$", "data", "[", "'v_error_method'", "]", ":", "false", ";", "if", "(", "false", "!==", "$", "validatorFetchErrorsMethod", ")", "{", "$", "errorString", "=", "call_user_func_array", "(", "array", "(", "$", "v", ",", "$", "validatorFetchErrorsMethod", ")", ",", "array", "(", ")", ")", ";", "}", "/**\n * If errors is array => merge\n * Else append\n */", "if", "(", "is_array", "(", "$", "errorString", ")", ")", "{", "$", "errors", "=", "array_merge", "(", "$", "errors", ",", "$", "errorString", ")", ";", "}", "else", "{", "$", "errors", "[", "]", "=", "$", "errorString", ";", "}", "}", "/**\n * Set local errors\n */", "$", "this", "->", "setErrors", "(", "$", "errors", ")", ";", "/**\n * Return true if there's no errors :)\n */", "return", "!", "$", "this", "->", "hasErrors", "(", ")", ";", "}" ]
Validate package. Errors can be retreived by calling getErrors(); @return bool
[ "Validate", "package", ".", "Errors", "can", "be", "retreived", "by", "calling", "getErrors", "()", ";" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L1107-L1271
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.importDataV1x
public function importDataV1x(array $data) { $this->_packageXml = null; $this->_init(); // Import simple data if (isset($data['name'])) { $this->setName($data['name']); } if (isset($data['summary'])) { $this->setSummary($data['summary']); } if (isset($data['description'])) { $this->setDescription($data['description']); } if (isset($data['channel'])) { $this->setChannel($this->convertChannelFromV1x($data['channel'])); } if (isset($data['license'])) { if (is_array($data['license'])) { $this->setLicense($data['license']['_content'], $data['license']['attribs']['uri']); } else { $this->setLicense($data['license']); } } if (isset($data['version'])) { $this->setVersion($data['version']['release']); } if (isset($data['stability'])) { $this->setStability($data['stability']['release']); } if (isset($data['notes'])) { $this->setNotes($data['notes']); } if (isset($data['date'])) { $this->setDate($data['date']); } if (isset($data['time'])) { $this->setTime($data['time']); } // Import authors $authors = array(); $authorRoles = array('lead', 'developer', 'contributor', 'helper'); foreach ($authorRoles as $authorRole) { if (isset($data[$authorRole])) { $authorList = $data[$authorRole]; if (!is_array($authorList) || isset($authorList['name'])) { $authorList = array($authorList); } foreach ($authorList as $authorRawData) { $author = array(); $author['name'] = $authorRawData['name']; $author['user'] = $authorRawData['user']; $author['email'] = $authorRawData['email']; array_push($authors, $author); } } } $this->setAuthors($authors); // Import dependencies $packages = array(); $extensions = array(); if (isset($data['dependencies']) && is_array($data['dependencies'])) { $dependencySections = array('required', 'optional'); $elementTypes = array('package', 'extension'); foreach ($dependencySections as $dependencySection) { if (isset($data['dependencies'][$dependencySection])) { // Handle required PHP version if ($dependencySection == 'required' && isset($data['dependencies']['required']['php'])) { $this->setDependencyPhpVersion($data['dependencies']['required']['php']['min'], $data['dependencies']['required']['php']['max']); } // Handle extensions if (isset($data['dependencies'][$dependencySection]['extension'])) { $extensionList = $data['dependencies'][$dependencySection]['extension']; if (!is_array($extensionList) || isset($extensionList['name'])) { $extensionList = array($extensionList); } foreach ($extensionList as $extensionRawData) { $extension = array(); $extension['name'] = $extensionRawData['name']; $extension['min_version'] = isset($extensionRawData['min']) ? $extensionRawData['min'] : null; $extension['max_version'] = isset($extensionRawData['max']) ? $extensionRawData['max'] : null; array_push($extensions, $extension); } } // Handle packages if (isset($data['dependencies'][$dependencySection]['package'])) { $packageList = $data['dependencies'][$dependencySection]['package']; if (!is_array($packageList) || isset($packageList['name'])) { $packageList = array($packageList); } foreach ($packageList as $packageRawData) { $package = array(); $package['name'] = $packageRawData['name']; $package['channel'] = $this->convertChannelFromV1x($packageRawData['channel']); $package['min_version'] = isset($packageRawData['min']) ? $packageRawData['min'] : null; $package['max_version'] = isset($packageRawData['max']) ? $packageRawData['max'] : null; array_push($packages, $package); } } } } } $this->setDependencyPackages($packages); $this->setDependencyPhpExtensions($extensions); // Import contents if (isset($data['contents']) && is_array($data['contents']) && is_array($data['contents']['dir'])) { // Handle files $root = $data['contents']['dir']; if (isset($data['contents']['dir']['file'])) { $fileList = $data['contents']['dir']['file']; if (!is_array($fileList) || isset($fileList['attribs'])) { $fileList = array($fileList); } foreach ($fileList as $fileRawData) { $targetName = $fileRawData['attribs']['role']; $parentTargetNode = $this->_getNode('target', $this->_packageXml->contents, $targetName); $filePath = $fileRawData['attribs']['name']; $filePathParts = explode('/', $filePath); $fileName = array_pop($filePathParts); $parentDirNode = null; if (!empty($filePathParts)) { $parentDirNode = $parentTargetNode; foreach ($filePathParts as $directoryName) { $parentDirNode = $this->_getNode('dir', $parentDirNode, $directoryName); } } else { $parentDirNode = $this->_getNode('dir', $parentTargetNode, '.'); } $fileNode = $parentDirNode->addChild('file'); $fileNode->addAttribute('name', $fileName); $fileNode->addAttribute('hash', $fileRawData['attribs']['md5sum']); } } } return $this; }
php
public function importDataV1x(array $data) { $this->_packageXml = null; $this->_init(); // Import simple data if (isset($data['name'])) { $this->setName($data['name']); } if (isset($data['summary'])) { $this->setSummary($data['summary']); } if (isset($data['description'])) { $this->setDescription($data['description']); } if (isset($data['channel'])) { $this->setChannel($this->convertChannelFromV1x($data['channel'])); } if (isset($data['license'])) { if (is_array($data['license'])) { $this->setLicense($data['license']['_content'], $data['license']['attribs']['uri']); } else { $this->setLicense($data['license']); } } if (isset($data['version'])) { $this->setVersion($data['version']['release']); } if (isset($data['stability'])) { $this->setStability($data['stability']['release']); } if (isset($data['notes'])) { $this->setNotes($data['notes']); } if (isset($data['date'])) { $this->setDate($data['date']); } if (isset($data['time'])) { $this->setTime($data['time']); } // Import authors $authors = array(); $authorRoles = array('lead', 'developer', 'contributor', 'helper'); foreach ($authorRoles as $authorRole) { if (isset($data[$authorRole])) { $authorList = $data[$authorRole]; if (!is_array($authorList) || isset($authorList['name'])) { $authorList = array($authorList); } foreach ($authorList as $authorRawData) { $author = array(); $author['name'] = $authorRawData['name']; $author['user'] = $authorRawData['user']; $author['email'] = $authorRawData['email']; array_push($authors, $author); } } } $this->setAuthors($authors); // Import dependencies $packages = array(); $extensions = array(); if (isset($data['dependencies']) && is_array($data['dependencies'])) { $dependencySections = array('required', 'optional'); $elementTypes = array('package', 'extension'); foreach ($dependencySections as $dependencySection) { if (isset($data['dependencies'][$dependencySection])) { // Handle required PHP version if ($dependencySection == 'required' && isset($data['dependencies']['required']['php'])) { $this->setDependencyPhpVersion($data['dependencies']['required']['php']['min'], $data['dependencies']['required']['php']['max']); } // Handle extensions if (isset($data['dependencies'][$dependencySection]['extension'])) { $extensionList = $data['dependencies'][$dependencySection]['extension']; if (!is_array($extensionList) || isset($extensionList['name'])) { $extensionList = array($extensionList); } foreach ($extensionList as $extensionRawData) { $extension = array(); $extension['name'] = $extensionRawData['name']; $extension['min_version'] = isset($extensionRawData['min']) ? $extensionRawData['min'] : null; $extension['max_version'] = isset($extensionRawData['max']) ? $extensionRawData['max'] : null; array_push($extensions, $extension); } } // Handle packages if (isset($data['dependencies'][$dependencySection]['package'])) { $packageList = $data['dependencies'][$dependencySection]['package']; if (!is_array($packageList) || isset($packageList['name'])) { $packageList = array($packageList); } foreach ($packageList as $packageRawData) { $package = array(); $package['name'] = $packageRawData['name']; $package['channel'] = $this->convertChannelFromV1x($packageRawData['channel']); $package['min_version'] = isset($packageRawData['min']) ? $packageRawData['min'] : null; $package['max_version'] = isset($packageRawData['max']) ? $packageRawData['max'] : null; array_push($packages, $package); } } } } } $this->setDependencyPackages($packages); $this->setDependencyPhpExtensions($extensions); // Import contents if (isset($data['contents']) && is_array($data['contents']) && is_array($data['contents']['dir'])) { // Handle files $root = $data['contents']['dir']; if (isset($data['contents']['dir']['file'])) { $fileList = $data['contents']['dir']['file']; if (!is_array($fileList) || isset($fileList['attribs'])) { $fileList = array($fileList); } foreach ($fileList as $fileRawData) { $targetName = $fileRawData['attribs']['role']; $parentTargetNode = $this->_getNode('target', $this->_packageXml->contents, $targetName); $filePath = $fileRawData['attribs']['name']; $filePathParts = explode('/', $filePath); $fileName = array_pop($filePathParts); $parentDirNode = null; if (!empty($filePathParts)) { $parentDirNode = $parentTargetNode; foreach ($filePathParts as $directoryName) { $parentDirNode = $this->_getNode('dir', $parentDirNode, $directoryName); } } else { $parentDirNode = $this->_getNode('dir', $parentTargetNode, '.'); } $fileNode = $parentDirNode->addChild('file'); $fileNode->addAttribute('name', $fileName); $fileNode->addAttribute('hash', $fileRawData['attribs']['md5sum']); } } } return $this; }
[ "public", "function", "importDataV1x", "(", "array", "$", "data", ")", "{", "$", "this", "->", "_packageXml", "=", "null", ";", "$", "this", "->", "_init", "(", ")", ";", "// Import simple data", "if", "(", "isset", "(", "$", "data", "[", "'name'", "]", ")", ")", "{", "$", "this", "->", "setName", "(", "$", "data", "[", "'name'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'summary'", "]", ")", ")", "{", "$", "this", "->", "setSummary", "(", "$", "data", "[", "'summary'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'description'", "]", ")", ")", "{", "$", "this", "->", "setDescription", "(", "$", "data", "[", "'description'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'channel'", "]", ")", ")", "{", "$", "this", "->", "setChannel", "(", "$", "this", "->", "convertChannelFromV1x", "(", "$", "data", "[", "'channel'", "]", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'license'", "]", ")", ")", "{", "if", "(", "is_array", "(", "$", "data", "[", "'license'", "]", ")", ")", "{", "$", "this", "->", "setLicense", "(", "$", "data", "[", "'license'", "]", "[", "'_content'", "]", ",", "$", "data", "[", "'license'", "]", "[", "'attribs'", "]", "[", "'uri'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "setLicense", "(", "$", "data", "[", "'license'", "]", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "data", "[", "'version'", "]", ")", ")", "{", "$", "this", "->", "setVersion", "(", "$", "data", "[", "'version'", "]", "[", "'release'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'stability'", "]", ")", ")", "{", "$", "this", "->", "setStability", "(", "$", "data", "[", "'stability'", "]", "[", "'release'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'notes'", "]", ")", ")", "{", "$", "this", "->", "setNotes", "(", "$", "data", "[", "'notes'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'date'", "]", ")", ")", "{", "$", "this", "->", "setDate", "(", "$", "data", "[", "'date'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'time'", "]", ")", ")", "{", "$", "this", "->", "setTime", "(", "$", "data", "[", "'time'", "]", ")", ";", "}", "// Import authors", "$", "authors", "=", "array", "(", ")", ";", "$", "authorRoles", "=", "array", "(", "'lead'", ",", "'developer'", ",", "'contributor'", ",", "'helper'", ")", ";", "foreach", "(", "$", "authorRoles", "as", "$", "authorRole", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "$", "authorRole", "]", ")", ")", "{", "$", "authorList", "=", "$", "data", "[", "$", "authorRole", "]", ";", "if", "(", "!", "is_array", "(", "$", "authorList", ")", "||", "isset", "(", "$", "authorList", "[", "'name'", "]", ")", ")", "{", "$", "authorList", "=", "array", "(", "$", "authorList", ")", ";", "}", "foreach", "(", "$", "authorList", "as", "$", "authorRawData", ")", "{", "$", "author", "=", "array", "(", ")", ";", "$", "author", "[", "'name'", "]", "=", "$", "authorRawData", "[", "'name'", "]", ";", "$", "author", "[", "'user'", "]", "=", "$", "authorRawData", "[", "'user'", "]", ";", "$", "author", "[", "'email'", "]", "=", "$", "authorRawData", "[", "'email'", "]", ";", "array_push", "(", "$", "authors", ",", "$", "author", ")", ";", "}", "}", "}", "$", "this", "->", "setAuthors", "(", "$", "authors", ")", ";", "// Import dependencies", "$", "packages", "=", "array", "(", ")", ";", "$", "extensions", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "'dependencies'", "]", ")", "&&", "is_array", "(", "$", "data", "[", "'dependencies'", "]", ")", ")", "{", "$", "dependencySections", "=", "array", "(", "'required'", ",", "'optional'", ")", ";", "$", "elementTypes", "=", "array", "(", "'package'", ",", "'extension'", ")", ";", "foreach", "(", "$", "dependencySections", "as", "$", "dependencySection", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "'dependencies'", "]", "[", "$", "dependencySection", "]", ")", ")", "{", "// Handle required PHP version", "if", "(", "$", "dependencySection", "==", "'required'", "&&", "isset", "(", "$", "data", "[", "'dependencies'", "]", "[", "'required'", "]", "[", "'php'", "]", ")", ")", "{", "$", "this", "->", "setDependencyPhpVersion", "(", "$", "data", "[", "'dependencies'", "]", "[", "'required'", "]", "[", "'php'", "]", "[", "'min'", "]", ",", "$", "data", "[", "'dependencies'", "]", "[", "'required'", "]", "[", "'php'", "]", "[", "'max'", "]", ")", ";", "}", "// Handle extensions", "if", "(", "isset", "(", "$", "data", "[", "'dependencies'", "]", "[", "$", "dependencySection", "]", "[", "'extension'", "]", ")", ")", "{", "$", "extensionList", "=", "$", "data", "[", "'dependencies'", "]", "[", "$", "dependencySection", "]", "[", "'extension'", "]", ";", "if", "(", "!", "is_array", "(", "$", "extensionList", ")", "||", "isset", "(", "$", "extensionList", "[", "'name'", "]", ")", ")", "{", "$", "extensionList", "=", "array", "(", "$", "extensionList", ")", ";", "}", "foreach", "(", "$", "extensionList", "as", "$", "extensionRawData", ")", "{", "$", "extension", "=", "array", "(", ")", ";", "$", "extension", "[", "'name'", "]", "=", "$", "extensionRawData", "[", "'name'", "]", ";", "$", "extension", "[", "'min_version'", "]", "=", "isset", "(", "$", "extensionRawData", "[", "'min'", "]", ")", "?", "$", "extensionRawData", "[", "'min'", "]", ":", "null", ";", "$", "extension", "[", "'max_version'", "]", "=", "isset", "(", "$", "extensionRawData", "[", "'max'", "]", ")", "?", "$", "extensionRawData", "[", "'max'", "]", ":", "null", ";", "array_push", "(", "$", "extensions", ",", "$", "extension", ")", ";", "}", "}", "// Handle packages", "if", "(", "isset", "(", "$", "data", "[", "'dependencies'", "]", "[", "$", "dependencySection", "]", "[", "'package'", "]", ")", ")", "{", "$", "packageList", "=", "$", "data", "[", "'dependencies'", "]", "[", "$", "dependencySection", "]", "[", "'package'", "]", ";", "if", "(", "!", "is_array", "(", "$", "packageList", ")", "||", "isset", "(", "$", "packageList", "[", "'name'", "]", ")", ")", "{", "$", "packageList", "=", "array", "(", "$", "packageList", ")", ";", "}", "foreach", "(", "$", "packageList", "as", "$", "packageRawData", ")", "{", "$", "package", "=", "array", "(", ")", ";", "$", "package", "[", "'name'", "]", "=", "$", "packageRawData", "[", "'name'", "]", ";", "$", "package", "[", "'channel'", "]", "=", "$", "this", "->", "convertChannelFromV1x", "(", "$", "packageRawData", "[", "'channel'", "]", ")", ";", "$", "package", "[", "'min_version'", "]", "=", "isset", "(", "$", "packageRawData", "[", "'min'", "]", ")", "?", "$", "packageRawData", "[", "'min'", "]", ":", "null", ";", "$", "package", "[", "'max_version'", "]", "=", "isset", "(", "$", "packageRawData", "[", "'max'", "]", ")", "?", "$", "packageRawData", "[", "'max'", "]", ":", "null", ";", "array_push", "(", "$", "packages", ",", "$", "package", ")", ";", "}", "}", "}", "}", "}", "$", "this", "->", "setDependencyPackages", "(", "$", "packages", ")", ";", "$", "this", "->", "setDependencyPhpExtensions", "(", "$", "extensions", ")", ";", "// Import contents", "if", "(", "isset", "(", "$", "data", "[", "'contents'", "]", ")", "&&", "is_array", "(", "$", "data", "[", "'contents'", "]", ")", "&&", "is_array", "(", "$", "data", "[", "'contents'", "]", "[", "'dir'", "]", ")", ")", "{", "// Handle files", "$", "root", "=", "$", "data", "[", "'contents'", "]", "[", "'dir'", "]", ";", "if", "(", "isset", "(", "$", "data", "[", "'contents'", "]", "[", "'dir'", "]", "[", "'file'", "]", ")", ")", "{", "$", "fileList", "=", "$", "data", "[", "'contents'", "]", "[", "'dir'", "]", "[", "'file'", "]", ";", "if", "(", "!", "is_array", "(", "$", "fileList", ")", "||", "isset", "(", "$", "fileList", "[", "'attribs'", "]", ")", ")", "{", "$", "fileList", "=", "array", "(", "$", "fileList", ")", ";", "}", "foreach", "(", "$", "fileList", "as", "$", "fileRawData", ")", "{", "$", "targetName", "=", "$", "fileRawData", "[", "'attribs'", "]", "[", "'role'", "]", ";", "$", "parentTargetNode", "=", "$", "this", "->", "_getNode", "(", "'target'", ",", "$", "this", "->", "_packageXml", "->", "contents", ",", "$", "targetName", ")", ";", "$", "filePath", "=", "$", "fileRawData", "[", "'attribs'", "]", "[", "'name'", "]", ";", "$", "filePathParts", "=", "explode", "(", "'/'", ",", "$", "filePath", ")", ";", "$", "fileName", "=", "array_pop", "(", "$", "filePathParts", ")", ";", "$", "parentDirNode", "=", "null", ";", "if", "(", "!", "empty", "(", "$", "filePathParts", ")", ")", "{", "$", "parentDirNode", "=", "$", "parentTargetNode", ";", "foreach", "(", "$", "filePathParts", "as", "$", "directoryName", ")", "{", "$", "parentDirNode", "=", "$", "this", "->", "_getNode", "(", "'dir'", ",", "$", "parentDirNode", ",", "$", "directoryName", ")", ";", "}", "}", "else", "{", "$", "parentDirNode", "=", "$", "this", "->", "_getNode", "(", "'dir'", ",", "$", "parentTargetNode", ",", "'.'", ")", ";", "}", "$", "fileNode", "=", "$", "parentDirNode", "->", "addChild", "(", "'file'", ")", ";", "$", "fileNode", "->", "addAttribute", "(", "'name'", ",", "$", "fileName", ")", ";", "$", "fileNode", "->", "addAttribute", "(", "'hash'", ",", "$", "fileRawData", "[", "'attribs'", "]", "[", "'md5sum'", "]", ")", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Import package information from previous version of Magento Connect Manager @param array $data @return Mage_Connect_Package
[ "Import", "package", "information", "from", "previous", "version", "of", "Magento", "Connect", "Manager" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L1340-L1479
mridang/magazine
lib/magento/Package.php
Mage_Connect_Package.convertChannelFromV1x
public function convertChannelFromV1x($channel) { $channelMap = array( 'connect.magentocommerce.com/community' => 'community', 'connect.magentocommerce.com/core' => 'community' ); if (!empty($channel) && isset($channelMap[$channel])) { $channel = $channelMap[$channel]; } return $channel; }
php
public function convertChannelFromV1x($channel) { $channelMap = array( 'connect.magentocommerce.com/community' => 'community', 'connect.magentocommerce.com/core' => 'community' ); if (!empty($channel) && isset($channelMap[$channel])) { $channel = $channelMap[$channel]; } return $channel; }
[ "public", "function", "convertChannelFromV1x", "(", "$", "channel", ")", "{", "$", "channelMap", "=", "array", "(", "'connect.magentocommerce.com/community'", "=>", "'community'", ",", "'connect.magentocommerce.com/core'", "=>", "'community'", ")", ";", "if", "(", "!", "empty", "(", "$", "channel", ")", "&&", "isset", "(", "$", "channelMap", "[", "$", "channel", "]", ")", ")", "{", "$", "channel", "=", "$", "channelMap", "[", "$", "channel", "]", ";", "}", "return", "$", "channel", ";", "}" ]
Convert package channel in order for it to be compatible with current version of Magento Connect Manager @param string $channel @return string
[ "Convert", "package", "channel", "in", "order", "for", "it", "to", "be", "compatible", "with", "current", "version", "of", "Magento", "Connect", "Manager" ]
train
https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Package.php#L1488-L1498
timiTao/behat-symfony-container
src/Factory/ContainerFactory.php
ContainerFactory.createContainer
private function createContainer(array $files) { $containerBuilder = new Container(); $loader = $this->createLoader($containerBuilder); foreach ($files as $file) { $loader->load($file); } return $containerBuilder; }
php
private function createContainer(array $files) { $containerBuilder = new Container(); $loader = $this->createLoader($containerBuilder); foreach ($files as $file) { $loader->load($file); } return $containerBuilder; }
[ "private", "function", "createContainer", "(", "array", "$", "files", ")", "{", "$", "containerBuilder", "=", "new", "Container", "(", ")", ";", "$", "loader", "=", "$", "this", "->", "createLoader", "(", "$", "containerBuilder", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "loader", "->", "load", "(", "$", "file", ")", ";", "}", "return", "$", "containerBuilder", ";", "}" ]
@param array $files @return Container
[ "@param", "array", "$files" ]
train
https://github.com/timiTao/behat-symfony-container/blob/f6b87583300d2e2a19b35bc66fb741a133684f7e/src/Factory/ContainerFactory.php#L52-L61
php-lug/lug
src/Bundle/GridBundle/Handler/GridHandler.php
GridHandler.handle
public function handle(GridInterface $grid, FormInterface $form = null, FormInterface $batchForm = null) { $valid = $form !== null && $form->isValid(); $view = $this->handler->handle( $grid, $valid ? $form->get('filters')->getData() : [], $valid ? $form->get('sorting')->getData() : [], $valid ? ['page' => $form->get('page')->getData(), 'limit' => $form->get('limit')->getData()] : [] ); if ($form !== null) { $view->setForm($form->createView()); } if ($batchForm !== null) { $view->setBatchForm($batchForm->createView()); } return $view; }
php
public function handle(GridInterface $grid, FormInterface $form = null, FormInterface $batchForm = null) { $valid = $form !== null && $form->isValid(); $view = $this->handler->handle( $grid, $valid ? $form->get('filters')->getData() : [], $valid ? $form->get('sorting')->getData() : [], $valid ? ['page' => $form->get('page')->getData(), 'limit' => $form->get('limit')->getData()] : [] ); if ($form !== null) { $view->setForm($form->createView()); } if ($batchForm !== null) { $view->setBatchForm($batchForm->createView()); } return $view; }
[ "public", "function", "handle", "(", "GridInterface", "$", "grid", ",", "FormInterface", "$", "form", "=", "null", ",", "FormInterface", "$", "batchForm", "=", "null", ")", "{", "$", "valid", "=", "$", "form", "!==", "null", "&&", "$", "form", "->", "isValid", "(", ")", ";", "$", "view", "=", "$", "this", "->", "handler", "->", "handle", "(", "$", "grid", ",", "$", "valid", "?", "$", "form", "->", "get", "(", "'filters'", ")", "->", "getData", "(", ")", ":", "[", "]", ",", "$", "valid", "?", "$", "form", "->", "get", "(", "'sorting'", ")", "->", "getData", "(", ")", ":", "[", "]", ",", "$", "valid", "?", "[", "'page'", "=>", "$", "form", "->", "get", "(", "'page'", ")", "->", "getData", "(", ")", ",", "'limit'", "=>", "$", "form", "->", "get", "(", "'limit'", ")", "->", "getData", "(", ")", "]", ":", "[", "]", ")", ";", "if", "(", "$", "form", "!==", "null", ")", "{", "$", "view", "->", "setForm", "(", "$", "form", "->", "createView", "(", ")", ")", ";", "}", "if", "(", "$", "batchForm", "!==", "null", ")", "{", "$", "view", "->", "setBatchForm", "(", "$", "batchForm", "->", "createView", "(", ")", ")", ";", "}", "return", "$", "view", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Handler/GridHandler.php#L39-L59
expectation-php/expect
src/config/ConfigurableConfiguration.php
ConfigurableConfiguration.merge
public function merge(Configuration $config) { $matcherRegistrars = array_merge( $this->matcherRegistrars, $config->getMatcherRegistrars() ); $reporter = $config->getResultReporter(); if ($reporter === null) { $reporter = $this->resultReporter; } return new RuntimeConfiguration($matcherRegistrars, $reporter); }
php
public function merge(Configuration $config) { $matcherRegistrars = array_merge( $this->matcherRegistrars, $config->getMatcherRegistrars() ); $reporter = $config->getResultReporter(); if ($reporter === null) { $reporter = $this->resultReporter; } return new RuntimeConfiguration($matcherRegistrars, $reporter); }
[ "public", "function", "merge", "(", "Configuration", "$", "config", ")", "{", "$", "matcherRegistrars", "=", "array_merge", "(", "$", "this", "->", "matcherRegistrars", ",", "$", "config", "->", "getMatcherRegistrars", "(", ")", ")", ";", "$", "reporter", "=", "$", "config", "->", "getResultReporter", "(", ")", ";", "if", "(", "$", "reporter", "===", "null", ")", "{", "$", "reporter", "=", "$", "this", "->", "resultReporter", ";", "}", "return", "new", "RuntimeConfiguration", "(", "$", "matcherRegistrars", ",", "$", "reporter", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/expectation-php/expect/blob/1a32c5af37f3dc8dabe4e8eedeeb21aea16ce139/src/config/ConfigurableConfiguration.php#L52-L66
protophp/session
src/SessionManager.php
SessionManager.getUniqueKey
private function getUniqueKey(): string { do { try { $isDuplicate = null; $key = random_bytes($this->getOpt(self::OPT_SESSION_KEY_LENGTH)); // Ask for duplicate key from storage $this->emit('duplicate-check', [$key, &$isDuplicate]); } catch (\Exception $e) { throw new SessionException($e->getMessage(), SessionException::ERR_RANDOM_BYTES); } } while (isset($this->SESSION[$key]) || $isDuplicate === true); return $key; }
php
private function getUniqueKey(): string { do { try { $isDuplicate = null; $key = random_bytes($this->getOpt(self::OPT_SESSION_KEY_LENGTH)); // Ask for duplicate key from storage $this->emit('duplicate-check', [$key, &$isDuplicate]); } catch (\Exception $e) { throw new SessionException($e->getMessage(), SessionException::ERR_RANDOM_BYTES); } } while (isset($this->SESSION[$key]) || $isDuplicate === true); return $key; }
[ "private", "function", "getUniqueKey", "(", ")", ":", "string", "{", "do", "{", "try", "{", "$", "isDuplicate", "=", "null", ";", "$", "key", "=", "random_bytes", "(", "$", "this", "->", "getOpt", "(", "self", "::", "OPT_SESSION_KEY_LENGTH", ")", ")", ";", "// Ask for duplicate key from storage", "$", "this", "->", "emit", "(", "'duplicate-check'", ",", "[", "$", "key", ",", "&", "$", "isDuplicate", "]", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "SessionException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "SessionException", "::", "ERR_RANDOM_BYTES", ")", ";", "}", "}", "while", "(", "isset", "(", "$", "this", "->", "SESSION", "[", "$", "key", "]", ")", "||", "$", "isDuplicate", "===", "true", ")", ";", "return", "$", "key", ";", "}" ]
Generate unique key @return string @throws SessionException
[ "Generate", "unique", "key" ]
train
https://github.com/protophp/session/blob/bd90c882628a556727b5bc02d63005a59afa4c3a/src/SessionManager.php#L68-L84
php-lug/lug
src/Component/Grid/DataSource/Doctrine/ORM/ExpressionBuilder.php
ExpressionBuilder.between
public function between($value, $x, $y) { return $this->expr->between($value, $x, $y); }
php
public function between($value, $x, $y) { return $this->expr->between($value, $x, $y); }
[ "public", "function", "between", "(", "$", "value", ",", "$", "x", ",", "$", "y", ")", "{", "return", "$", "this", "->", "expr", "->", "between", "(", "$", "value", ",", "$", "x", ",", "$", "y", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/DataSource/Doctrine/ORM/ExpressionBuilder.php#L174-L177
php-lug/lug
src/Component/Grid/DataSource/Doctrine/ORM/ExpressionBuilder.php
ExpressionBuilder.notBetween
public function notBetween($value, $x, $y) { return $this->expr->not($this->between($value, $x, $y)); }
php
public function notBetween($value, $x, $y) { return $this->expr->not($this->between($value, $x, $y)); }
[ "public", "function", "notBetween", "(", "$", "value", ",", "$", "x", ",", "$", "y", ")", "{", "return", "$", "this", "->", "expr", "->", "not", "(", "$", "this", "->", "between", "(", "$", "value", ",", "$", "x", ",", "$", "y", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/DataSource/Doctrine/ORM/ExpressionBuilder.php#L182-L185
php-lug/lug
src/Component/Grid/Column/Type/TwigType.php
TwigType.render
public function render($data, array $options) { return $this->renderTemplate($this->getValue($data, $options), $options); }
php
public function render($data, array $options) { return $this->renderTemplate($this->getValue($data, $options), $options); }
[ "public", "function", "render", "(", "$", "data", ",", "array", "$", "options", ")", "{", "return", "$", "this", "->", "renderTemplate", "(", "$", "this", "->", "getValue", "(", "$", "data", ",", "$", "options", ")", ",", "$", "options", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Column/Type/TwigType.php#L41-L44
php-lug/lug
src/Component/Grid/Column/Type/TwigType.php
TwigType.renderTemplate
protected function renderTemplate($data, array $options) { return $this->twig->render( $options['template'], array_merge($options['context'], ['column' => $options['column'], 'data' => $data]) ); }
php
protected function renderTemplate($data, array $options) { return $this->twig->render( $options['template'], array_merge($options['context'], ['column' => $options['column'], 'data' => $data]) ); }
[ "protected", "function", "renderTemplate", "(", "$", "data", ",", "array", "$", "options", ")", "{", "return", "$", "this", "->", "twig", "->", "render", "(", "$", "options", "[", "'template'", "]", ",", "array_merge", "(", "$", "options", "[", "'context'", "]", ",", "[", "'column'", "=>", "$", "options", "[", "'column'", "]", ",", "'data'", "=>", "$", "data", "]", ")", ")", ";", "}" ]
@param mixed $data @param mixed[] $options @return string
[ "@param", "mixed", "$data", "@param", "mixed", "[]", "$options" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Column/Type/TwigType.php#L74-L80
traderinteractive/util-http-php
src/Util/Http.php
Http.parseHeaders
public static function parseHeaders(string $rawHeaders) : array { if (empty(trim($rawHeaders))) { throw new InvalidArgumentException('$rawHeaders cannot be whitespace'); } $headers = []; $rawHeaders = preg_replace("/\r\n[\t ]+/", ' ', trim($rawHeaders)); $fields = explode("\r\n", $rawHeaders); foreach ($fields as $field) { $match = null; if (preg_match('/([^:]+): (.+)/m', $field, $match)) { $key = $match[1]; // convert 'some-header' to 'Some-Header' $key = strtolower(trim($key)); $key = ucwords(preg_replace('/[\s-]/', ' ', $key)); $key = strtr($key, ' ', '-'); $value = trim($match[2]); if (!array_key_exists($key, $headers)) { $headers[$key] = $value; continue; } if (!is_array($headers[$key])) { $headers[$key] = [$headers[$key]]; } $headers[$key][] = $value; continue; } if (preg_match('#([A-Za-z]+) +([^ ]+) +HTTP/([\d.]+)#', $field, $match)) { $headers = self::addRequestDataToHeaders($match, $headers); continue; } if (preg_match('#HTTP/([\d.]+) +(\d{3}) +(.*)#', $field, $match)) { $headers = self::addResponseDataToHeaders($match, $headers); continue; } throw new Exception("Unsupported header format: {$field}"); } return $headers; }
php
public static function parseHeaders(string $rawHeaders) : array { if (empty(trim($rawHeaders))) { throw new InvalidArgumentException('$rawHeaders cannot be whitespace'); } $headers = []; $rawHeaders = preg_replace("/\r\n[\t ]+/", ' ', trim($rawHeaders)); $fields = explode("\r\n", $rawHeaders); foreach ($fields as $field) { $match = null; if (preg_match('/([^:]+): (.+)/m', $field, $match)) { $key = $match[1]; // convert 'some-header' to 'Some-Header' $key = strtolower(trim($key)); $key = ucwords(preg_replace('/[\s-]/', ' ', $key)); $key = strtr($key, ' ', '-'); $value = trim($match[2]); if (!array_key_exists($key, $headers)) { $headers[$key] = $value; continue; } if (!is_array($headers[$key])) { $headers[$key] = [$headers[$key]]; } $headers[$key][] = $value; continue; } if (preg_match('#([A-Za-z]+) +([^ ]+) +HTTP/([\d.]+)#', $field, $match)) { $headers = self::addRequestDataToHeaders($match, $headers); continue; } if (preg_match('#HTTP/([\d.]+) +(\d{3}) +(.*)#', $field, $match)) { $headers = self::addResponseDataToHeaders($match, $headers); continue; } throw new Exception("Unsupported header format: {$field}"); } return $headers; }
[ "public", "static", "function", "parseHeaders", "(", "string", "$", "rawHeaders", ")", ":", "array", "{", "if", "(", "empty", "(", "trim", "(", "$", "rawHeaders", ")", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'$rawHeaders cannot be whitespace'", ")", ";", "}", "$", "headers", "=", "[", "]", ";", "$", "rawHeaders", "=", "preg_replace", "(", "\"/\\r\\n[\\t ]+/\"", ",", "' '", ",", "trim", "(", "$", "rawHeaders", ")", ")", ";", "$", "fields", "=", "explode", "(", "\"\\r\\n\"", ",", "$", "rawHeaders", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "$", "match", "=", "null", ";", "if", "(", "preg_match", "(", "'/([^:]+): (.+)/m'", ",", "$", "field", ",", "$", "match", ")", ")", "{", "$", "key", "=", "$", "match", "[", "1", "]", ";", "// convert 'some-header' to 'Some-Header'", "$", "key", "=", "strtolower", "(", "trim", "(", "$", "key", ")", ")", ";", "$", "key", "=", "ucwords", "(", "preg_replace", "(", "'/[\\s-]/'", ",", "' '", ",", "$", "key", ")", ")", ";", "$", "key", "=", "strtr", "(", "$", "key", ",", "' '", ",", "'-'", ")", ";", "$", "value", "=", "trim", "(", "$", "match", "[", "2", "]", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "headers", ")", ")", "{", "$", "headers", "[", "$", "key", "]", "=", "$", "value", ";", "continue", ";", "}", "if", "(", "!", "is_array", "(", "$", "headers", "[", "$", "key", "]", ")", ")", "{", "$", "headers", "[", "$", "key", "]", "=", "[", "$", "headers", "[", "$", "key", "]", "]", ";", "}", "$", "headers", "[", "$", "key", "]", "[", "]", "=", "$", "value", ";", "continue", ";", "}", "if", "(", "preg_match", "(", "'#([A-Za-z]+) +([^ ]+) +HTTP/([\\d.]+)#'", ",", "$", "field", ",", "$", "match", ")", ")", "{", "$", "headers", "=", "self", "::", "addRequestDataToHeaders", "(", "$", "match", ",", "$", "headers", ")", ";", "continue", ";", "}", "if", "(", "preg_match", "(", "'#HTTP/([\\d.]+) +(\\d{3}) +(.*)#'", ",", "$", "field", ",", "$", "match", ")", ")", "{", "$", "headers", "=", "self", "::", "addResponseDataToHeaders", "(", "$", "match", ",", "$", "headers", ")", ";", "continue", ";", "}", "throw", "new", "Exception", "(", "\"Unsupported header format: {$field}\"", ")", ";", "}", "return", "$", "headers", ";", "}" ]
Parses HTTP headers into an associative array. Example: <code> $headers = "HTTP/1.1 200 OK\r\n". "content-type: text/html; charset=UTF-8\r\n". "Server: Funky/1.0\r\n". "Set-Cookie: foo=bar\r\n". "Set-Cookie: baz=quux\r\n". "Folds: are\r\n\treformatted\r\n"; print_r(\TraderInteractive\HttpUtil::parseHeaders($headers)); </code> The above example will output: <pre> Array ( [Response Code] => 200 [Response Status] => OK [Content-Type] => text/html; charset=UTF-8 [Server] => Funky/1.0 [Set-Cookie] => Array ( [0] => foo=bar [1] => baz=quux ) [Folds] => are reformatted ) </pre> @param string $rawHeaders string containing HTTP headers @return array the parsed headers @throws Exception Thrown if unable to parse the headers
[ "Parses", "HTTP", "headers", "into", "an", "associative", "array", "." ]
train
https://github.com/traderinteractive/util-http-php/blob/d3bba26fbd9ec5a3227c4580717019bf16a58c67/src/Util/Http.php#L49-L96
traderinteractive/util-http-php
src/Util/Http.php
Http.buildQueryString
public static function buildQueryString(array $parameters) : string { $queryStrings = []; foreach ($parameters as $parameterName => $parameterValue) { $parameterName = rawurlencode($parameterName); if (is_array($parameterValue)) { foreach ($parameterValue as $eachValue) { $eachValue = rawurlencode($eachValue); $queryStrings[] = "{$parameterName}={$eachValue}"; } } elseif ($parameterValue === false) { $queryStrings[] = "{$parameterName}=false"; } elseif ($parameterValue === true) { $queryStrings[] = "{$parameterName}=true"; } else { $parameterValue = rawurlencode($parameterValue); $queryStrings[] = "{$parameterName}={$parameterValue}"; } } return implode('&', $queryStrings); }
php
public static function buildQueryString(array $parameters) : string { $queryStrings = []; foreach ($parameters as $parameterName => $parameterValue) { $parameterName = rawurlencode($parameterName); if (is_array($parameterValue)) { foreach ($parameterValue as $eachValue) { $eachValue = rawurlencode($eachValue); $queryStrings[] = "{$parameterName}={$eachValue}"; } } elseif ($parameterValue === false) { $queryStrings[] = "{$parameterName}=false"; } elseif ($parameterValue === true) { $queryStrings[] = "{$parameterName}=true"; } else { $parameterValue = rawurlencode($parameterValue); $queryStrings[] = "{$parameterName}={$parameterValue}"; } } return implode('&', $queryStrings); }
[ "public", "static", "function", "buildQueryString", "(", "array", "$", "parameters", ")", ":", "string", "{", "$", "queryStrings", "=", "[", "]", ";", "foreach", "(", "$", "parameters", "as", "$", "parameterName", "=>", "$", "parameterValue", ")", "{", "$", "parameterName", "=", "rawurlencode", "(", "$", "parameterName", ")", ";", "if", "(", "is_array", "(", "$", "parameterValue", ")", ")", "{", "foreach", "(", "$", "parameterValue", "as", "$", "eachValue", ")", "{", "$", "eachValue", "=", "rawurlencode", "(", "$", "eachValue", ")", ";", "$", "queryStrings", "[", "]", "=", "\"{$parameterName}={$eachValue}\"", ";", "}", "}", "elseif", "(", "$", "parameterValue", "===", "false", ")", "{", "$", "queryStrings", "[", "]", "=", "\"{$parameterName}=false\"", ";", "}", "elseif", "(", "$", "parameterValue", "===", "true", ")", "{", "$", "queryStrings", "[", "]", "=", "\"{$parameterName}=true\"", ";", "}", "else", "{", "$", "parameterValue", "=", "rawurlencode", "(", "$", "parameterValue", ")", ";", "$", "queryStrings", "[", "]", "=", "\"{$parameterName}={$parameterValue}\"", ";", "}", "}", "return", "implode", "(", "'&'", ",", "$", "queryStrings", ")", ";", "}" ]
Generate URL-encoded query string Example: <code> $parameters = [ 'param1' => ['value', 'another value'], 'param2' => 'a value', 'param3' => false, ]; $queryString = \TraderInteractive\HttpUtil::buildQueryString($parameters); echo $queryString </code> Output: <pre> param1=value&param1=another+value&param2=a+value&param3=false </pre> @param array $parameters An associative array containing parameter key/value(s) @return string the built query string
[ "Generate", "URL", "-", "encoded", "query", "string" ]
train
https://github.com/traderinteractive/util-http-php/blob/d3bba26fbd9ec5a3227c4580717019bf16a58c67/src/Util/Http.php#L137-L159
traderinteractive/util-http-php
src/Util/Http.php
Http.getQueryParams
public static function getQueryParams(string $url, array $collapsedParams = []) : array { $queryString = parse_url($url, PHP_URL_QUERY); if (!is_string($queryString)) { return []; } $collapsedParams = array_flip($collapsedParams); $result = []; foreach (explode('&', $queryString) as $arg) { $name = $arg; $value = ''; $nameAndValue = explode('=', $arg); if (isset($nameAndValue[1])) { list($name, $value) = $nameAndValue; } $name = rawurldecode($name); $value = rawurldecode($value); $collapsed = isset($collapsedParams[$name]); if (!array_key_exists($name, $result)) { if ($collapsed) { $result[$name] = $value; continue; } $result[$name] = []; } if ($collapsed) { throw new Exception("Parameter '{$name}' had more than one value but in \$collapsedParams"); } $result[$name][] = $value; } return $result; }
php
public static function getQueryParams(string $url, array $collapsedParams = []) : array { $queryString = parse_url($url, PHP_URL_QUERY); if (!is_string($queryString)) { return []; } $collapsedParams = array_flip($collapsedParams); $result = []; foreach (explode('&', $queryString) as $arg) { $name = $arg; $value = ''; $nameAndValue = explode('=', $arg); if (isset($nameAndValue[1])) { list($name, $value) = $nameAndValue; } $name = rawurldecode($name); $value = rawurldecode($value); $collapsed = isset($collapsedParams[$name]); if (!array_key_exists($name, $result)) { if ($collapsed) { $result[$name] = $value; continue; } $result[$name] = []; } if ($collapsed) { throw new Exception("Parameter '{$name}' had more than one value but in \$collapsedParams"); } $result[$name][] = $value; } return $result; }
[ "public", "static", "function", "getQueryParams", "(", "string", "$", "url", ",", "array", "$", "collapsedParams", "=", "[", "]", ")", ":", "array", "{", "$", "queryString", "=", "parse_url", "(", "$", "url", ",", "PHP_URL_QUERY", ")", ";", "if", "(", "!", "is_string", "(", "$", "queryString", ")", ")", "{", "return", "[", "]", ";", "}", "$", "collapsedParams", "=", "array_flip", "(", "$", "collapsedParams", ")", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "explode", "(", "'&'", ",", "$", "queryString", ")", "as", "$", "arg", ")", "{", "$", "name", "=", "$", "arg", ";", "$", "value", "=", "''", ";", "$", "nameAndValue", "=", "explode", "(", "'='", ",", "$", "arg", ")", ";", "if", "(", "isset", "(", "$", "nameAndValue", "[", "1", "]", ")", ")", "{", "list", "(", "$", "name", ",", "$", "value", ")", "=", "$", "nameAndValue", ";", "}", "$", "name", "=", "rawurldecode", "(", "$", "name", ")", ";", "$", "value", "=", "rawurldecode", "(", "$", "value", ")", ";", "$", "collapsed", "=", "isset", "(", "$", "collapsedParams", "[", "$", "name", "]", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "name", ",", "$", "result", ")", ")", "{", "if", "(", "$", "collapsed", ")", "{", "$", "result", "[", "$", "name", "]", "=", "$", "value", ";", "continue", ";", "}", "$", "result", "[", "$", "name", "]", "=", "[", "]", ";", "}", "if", "(", "$", "collapsed", ")", "{", "throw", "new", "Exception", "(", "\"Parameter '{$name}' had more than one value but in \\$collapsedParams\"", ")", ";", "}", "$", "result", "[", "$", "name", "]", "[", "]", "=", "$", "value", ";", "}", "return", "$", "result", ";", "}" ]
Get an array of all url parameters. @param string $url The url to parse such as http://foo.com/bar/?id=boo&another=wee&another=boo @param array $collapsedParams Parameters to collapse. ex. 'id' => ['boo'] to just 'id' => 'boo'. Exception thrown if more than 1 value @return array such as ['id' => ['boo'], 'another' => ['wee', 'boo']] @throws Exception if more than one value in a $collapsedParams param
[ "Get", "an", "array", "of", "all", "url", "parameters", "." ]
train
https://github.com/traderinteractive/util-http-php/blob/d3bba26fbd9ec5a3227c4580717019bf16a58c67/src/Util/Http.php#L172-L211
traderinteractive/util-http-php
src/Util/Http.php
Http.getQueryParamsCollapsed
public static function getQueryParamsCollapsed(string $url, array $expectedArrayParams = []) : array { $queryString = parse_url($url, PHP_URL_QUERY); if (!is_string($queryString)) { return []; } $result = []; foreach (explode('&', $queryString) as $arg) { $name = $arg; $value = ''; $nameAndValue = explode('=', $arg); if (isset($nameAndValue[1])) { list($name, $value) = $nameAndValue; } $name = rawurldecode($name); $value = rawurldecode($value); if (!array_key_exists($name, $result)) { $result[$name] = $value; continue; } if (!in_array($name, $expectedArrayParams)) { throw new Exception("Parameter '{$name}' is not expected to be an array, but array given"); } if (!is_array($result[$name])) { $result[$name] = [$result[$name]]; } $result[$name][] = $value; } return $result; }
php
public static function getQueryParamsCollapsed(string $url, array $expectedArrayParams = []) : array { $queryString = parse_url($url, PHP_URL_QUERY); if (!is_string($queryString)) { return []; } $result = []; foreach (explode('&', $queryString) as $arg) { $name = $arg; $value = ''; $nameAndValue = explode('=', $arg); if (isset($nameAndValue[1])) { list($name, $value) = $nameAndValue; } $name = rawurldecode($name); $value = rawurldecode($value); if (!array_key_exists($name, $result)) { $result[$name] = $value; continue; } if (!in_array($name, $expectedArrayParams)) { throw new Exception("Parameter '{$name}' is not expected to be an array, but array given"); } if (!is_array($result[$name])) { $result[$name] = [$result[$name]]; } $result[$name][] = $value; } return $result; }
[ "public", "static", "function", "getQueryParamsCollapsed", "(", "string", "$", "url", ",", "array", "$", "expectedArrayParams", "=", "[", "]", ")", ":", "array", "{", "$", "queryString", "=", "parse_url", "(", "$", "url", ",", "PHP_URL_QUERY", ")", ";", "if", "(", "!", "is_string", "(", "$", "queryString", ")", ")", "{", "return", "[", "]", ";", "}", "$", "result", "=", "[", "]", ";", "foreach", "(", "explode", "(", "'&'", ",", "$", "queryString", ")", "as", "$", "arg", ")", "{", "$", "name", "=", "$", "arg", ";", "$", "value", "=", "''", ";", "$", "nameAndValue", "=", "explode", "(", "'='", ",", "$", "arg", ")", ";", "if", "(", "isset", "(", "$", "nameAndValue", "[", "1", "]", ")", ")", "{", "list", "(", "$", "name", ",", "$", "value", ")", "=", "$", "nameAndValue", ";", "}", "$", "name", "=", "rawurldecode", "(", "$", "name", ")", ";", "$", "value", "=", "rawurldecode", "(", "$", "value", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "name", ",", "$", "result", ")", ")", "{", "$", "result", "[", "$", "name", "]", "=", "$", "value", ";", "continue", ";", "}", "if", "(", "!", "in_array", "(", "$", "name", ",", "$", "expectedArrayParams", ")", ")", "{", "throw", "new", "Exception", "(", "\"Parameter '{$name}' is not expected to be an array, but array given\"", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "result", "[", "$", "name", "]", ")", ")", "{", "$", "result", "[", "$", "name", "]", "=", "[", "$", "result", "[", "$", "name", "]", "]", ";", "}", "$", "result", "[", "$", "name", "]", "[", "]", "=", "$", "value", ";", "}", "return", "$", "result", ";", "}" ]
Get an array of all url parameters. @param string $url The url to parse such as http://foo.com/bar/?single=boo&multi=wee&multi=boo @param array $expectedArrayParams List of parameter names which are not collapsed. @return array such as ['single' => 'boo', 'multi' => ['wee', 'boo']] if 'multi' is given in $expectedArrayParams @throws Exception if a parameter is given as array but not included in the expected array argument
[ "Get", "an", "array", "of", "all", "url", "parameters", "." ]
train
https://github.com/traderinteractive/util-http-php/blob/d3bba26fbd9ec5a3227c4580717019bf16a58c67/src/Util/Http.php#L223-L259
siad007/versioncontrol_hg
src/Factory.php
Factory.getInstance
public static function getInstance($command, $options = []) { $commandClassName = sprintf( '\\Siad007\\VersionControl\\HG\\Command\\%sCommand', ucfirst($command) ); if (!class_exists($commandClassName)) { throw new \InvalidArgumentException( "Command $commandClassName not supported." ); } return new $commandClassName($options); }
php
public static function getInstance($command, $options = []) { $commandClassName = sprintf( '\\Siad007\\VersionControl\\HG\\Command\\%sCommand', ucfirst($command) ); if (!class_exists($commandClassName)) { throw new \InvalidArgumentException( "Command $commandClassName not supported." ); } return new $commandClassName($options); }
[ "public", "static", "function", "getInstance", "(", "$", "command", ",", "$", "options", "=", "[", "]", ")", "{", "$", "commandClassName", "=", "sprintf", "(", "'\\\\Siad007\\\\VersionControl\\\\HG\\\\Command\\\\%sCommand'", ",", "ucfirst", "(", "$", "command", ")", ")", ";", "if", "(", "!", "class_exists", "(", "$", "commandClassName", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Command $commandClassName not supported.\"", ")", ";", "}", "return", "new", "$", "commandClassName", "(", "$", "options", ")", ";", "}" ]
Factory method. @param string $command @param array $options @return Command\AbstractCommand @throws \InvalidArgumentException
[ "Factory", "method", "." ]
train
https://github.com/siad007/versioncontrol_hg/blob/e02ec9f1e88efae48f0e3296f65b1d99718b27cd/src/Factory.php#L84-L98
mikelgoig/nova-spotify-auth-tool
src/SpotifyAuthToolServiceProvider.php
SpotifyAuthToolServiceProvider.boot
public function boot() { if ($this->app->runningInConsole()) { $this->publishes([ __DIR__.'/../database/migrations/2018_11_15_000000_create_spotify_table.php' => database_path('migrations/2018_11_15_000000_create_spotify_table.php'), ], 'migrations'); } $this->loadViewsFrom(__DIR__.'/../resources/views', 'nova-spotify-auth-tool'); $this->app->booted(function () { $this->routes(); }); Nova::serving(function (ServingNova $event) { // }); }
php
public function boot() { if ($this->app->runningInConsole()) { $this->publishes([ __DIR__.'/../database/migrations/2018_11_15_000000_create_spotify_table.php' => database_path('migrations/2018_11_15_000000_create_spotify_table.php'), ], 'migrations'); } $this->loadViewsFrom(__DIR__.'/../resources/views', 'nova-spotify-auth-tool'); $this->app->booted(function () { $this->routes(); }); Nova::serving(function (ServingNova $event) { // }); }
[ "public", "function", "boot", "(", ")", "{", "if", "(", "$", "this", "->", "app", "->", "runningInConsole", "(", ")", ")", "{", "$", "this", "->", "publishes", "(", "[", "__DIR__", ".", "'/../database/migrations/2018_11_15_000000_create_spotify_table.php'", "=>", "database_path", "(", "'migrations/2018_11_15_000000_create_spotify_table.php'", ")", ",", "]", ",", "'migrations'", ")", ";", "}", "$", "this", "->", "loadViewsFrom", "(", "__DIR__", ".", "'/../resources/views'", ",", "'nova-spotify-auth-tool'", ")", ";", "$", "this", "->", "app", "->", "booted", "(", "function", "(", ")", "{", "$", "this", "->", "routes", "(", ")", ";", "}", ")", ";", "Nova", "::", "serving", "(", "function", "(", "ServingNova", "$", "event", ")", "{", "//", "}", ")", ";", "}" ]
Bootstrap any application services. @return void
[ "Bootstrap", "any", "application", "services", "." ]
train
https://github.com/mikelgoig/nova-spotify-auth-tool/blob/a5351c386206c45f77fe6ae833cdac51f2a030f4/src/SpotifyAuthToolServiceProvider.php#L18-L35
mikelgoig/nova-spotify-auth-tool
src/SpotifyAuthToolServiceProvider.php
SpotifyAuthToolServiceProvider.routes
protected function routes() { if ($this->app->routesAreCached()) { return; } Route::middleware(['nova', Authorize::class]) ->prefix('nova-vendor/nova-spotify-auth-tool') ->group(__DIR__.'/../routes/web.php'); Route::middleware(['nova', Authorize::class]) ->prefix('nova-vendor/nova-spotify-auth-tool') ->group(__DIR__.'/../routes/api.php'); }
php
protected function routes() { if ($this->app->routesAreCached()) { return; } Route::middleware(['nova', Authorize::class]) ->prefix('nova-vendor/nova-spotify-auth-tool') ->group(__DIR__.'/../routes/web.php'); Route::middleware(['nova', Authorize::class]) ->prefix('nova-vendor/nova-spotify-auth-tool') ->group(__DIR__.'/../routes/api.php'); }
[ "protected", "function", "routes", "(", ")", "{", "if", "(", "$", "this", "->", "app", "->", "routesAreCached", "(", ")", ")", "{", "return", ";", "}", "Route", "::", "middleware", "(", "[", "'nova'", ",", "Authorize", "::", "class", "]", ")", "->", "prefix", "(", "'nova-vendor/nova-spotify-auth-tool'", ")", "->", "group", "(", "__DIR__", ".", "'/../routes/web.php'", ")", ";", "Route", "::", "middleware", "(", "[", "'nova'", ",", "Authorize", "::", "class", "]", ")", "->", "prefix", "(", "'nova-vendor/nova-spotify-auth-tool'", ")", "->", "group", "(", "__DIR__", ".", "'/../routes/api.php'", ")", ";", "}" ]
Register the tool's routes. @return void
[ "Register", "the", "tool", "s", "routes", "." ]
train
https://github.com/mikelgoig/nova-spotify-auth-tool/blob/a5351c386206c45f77fe6ae833cdac51f2a030f4/src/SpotifyAuthToolServiceProvider.php#L42-L55
hametuha/wpametu
src/WPametu/UI/Admin/EditMetaBox.php
EditMetaBox.add_meta_boxes
public function add_meta_boxes($post_type, $post){ if( $this->is_valid_post_type($post_type) && $this->has_cap() ){ if( empty($this->name) || empty($this->label) ){ $message = sprintf($this->__('<code>%s</code> has invalid name or label.'), get_called_class()); add_action('admin_notices', function() use ($message) { printf('<div class="error"><p>%s</p></div>', $message); }); }else{ add_meta_box($this->name, $this->label, [$this, 'render'], $post_type, $this->context, $this->priority); } } }
php
public function add_meta_boxes($post_type, $post){ if( $this->is_valid_post_type($post_type) && $this->has_cap() ){ if( empty($this->name) || empty($this->label) ){ $message = sprintf($this->__('<code>%s</code> has invalid name or label.'), get_called_class()); add_action('admin_notices', function() use ($message) { printf('<div class="error"><p>%s</p></div>', $message); }); }else{ add_meta_box($this->name, $this->label, [$this, 'render'], $post_type, $this->context, $this->priority); } } }
[ "public", "function", "add_meta_boxes", "(", "$", "post_type", ",", "$", "post", ")", "{", "if", "(", "$", "this", "->", "is_valid_post_type", "(", "$", "post_type", ")", "&&", "$", "this", "->", "has_cap", "(", ")", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "name", ")", "||", "empty", "(", "$", "this", "->", "label", ")", ")", "{", "$", "message", "=", "sprintf", "(", "$", "this", "->", "__", "(", "'<code>%s</code> has invalid name or label.'", ")", ",", "get_called_class", "(", ")", ")", ";", "add_action", "(", "'admin_notices'", ",", "function", "(", ")", "use", "(", "$", "message", ")", "{", "printf", "(", "'<div class=\"error\"><p>%s</p></div>'", ",", "$", "message", ")", ";", "}", ")", ";", "}", "else", "{", "add_meta_box", "(", "$", "this", "->", "name", ",", "$", "this", "->", "label", ",", "[", "$", "this", ",", "'render'", "]", ",", "$", "post_type", ",", "$", "this", "->", "context", ",", "$", "this", "->", "priority", ")", ";", "}", "}", "}" ]
Register meta box @param string $post_type @param \WP_Post $post
[ "Register", "meta", "box" ]
train
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/UI/Admin/EditMetaBox.php#L38-L49
FriendsOfApi/phraseapp
src/Model/Key/KeyCreated.php
KeyCreated.createFromArray
public static function createFromArray(array $data) { $self = new self(); if (isset($data['id'])) { $self->setId($data['id']); } if (isset($data['name'])) { $self->setName($data['name']); } if (isset($data['description'])) { $self->setDescription($data['description']); } if (isset($data['name_hash'])) { $self->setNameHash($data['name_hash']); } if (isset($data['plural'])) { $self->setPlural($data['plural']); } if (isset($data['name_plural'])) { $self->setNamePlural($data['name_plural']); } if (isset($data['created_at'])) { $self->setCreatedAt($data['created_at']); } if (isset($data['updated_at'])) { $self->setUpdatedAt($data['updated_at']); } if (isset($data['data_type'])) { $self->setDataType($data['data_type']); } if (isset($data['tags'])) { $self->setTags($data['tags']); } return $self; }
php
public static function createFromArray(array $data) { $self = new self(); if (isset($data['id'])) { $self->setId($data['id']); } if (isset($data['name'])) { $self->setName($data['name']); } if (isset($data['description'])) { $self->setDescription($data['description']); } if (isset($data['name_hash'])) { $self->setNameHash($data['name_hash']); } if (isset($data['plural'])) { $self->setPlural($data['plural']); } if (isset($data['name_plural'])) { $self->setNamePlural($data['name_plural']); } if (isset($data['created_at'])) { $self->setCreatedAt($data['created_at']); } if (isset($data['updated_at'])) { $self->setUpdatedAt($data['updated_at']); } if (isset($data['data_type'])) { $self->setDataType($data['data_type']); } if (isset($data['tags'])) { $self->setTags($data['tags']); } return $self; }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "data", ")", "{", "$", "self", "=", "new", "self", "(", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "'id'", "]", ")", ")", "{", "$", "self", "->", "setId", "(", "$", "data", "[", "'id'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'name'", "]", ")", ")", "{", "$", "self", "->", "setName", "(", "$", "data", "[", "'name'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'description'", "]", ")", ")", "{", "$", "self", "->", "setDescription", "(", "$", "data", "[", "'description'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'name_hash'", "]", ")", ")", "{", "$", "self", "->", "setNameHash", "(", "$", "data", "[", "'name_hash'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'plural'", "]", ")", ")", "{", "$", "self", "->", "setPlural", "(", "$", "data", "[", "'plural'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'name_plural'", "]", ")", ")", "{", "$", "self", "->", "setNamePlural", "(", "$", "data", "[", "'name_plural'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'created_at'", "]", ")", ")", "{", "$", "self", "->", "setCreatedAt", "(", "$", "data", "[", "'created_at'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'updated_at'", "]", ")", ")", "{", "$", "self", "->", "setUpdatedAt", "(", "$", "data", "[", "'updated_at'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'data_type'", "]", ")", ")", "{", "$", "self", "->", "setDataType", "(", "$", "data", "[", "'data_type'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'tags'", "]", ")", ")", "{", "$", "self", "->", "setTags", "(", "$", "data", "[", "'tags'", "]", ")", ";", "}", "return", "$", "self", ";", "}" ]
@param array $data @return KeyCreated
[ "@param", "array", "$data" ]
train
https://github.com/FriendsOfApi/phraseapp/blob/1553bf857eb0858f9a7eb905b085864d24f80886/src/Model/Key/KeyCreated.php#L74-L110
old-town/workflow-designer-server
src/Factory/WorkflowDescriptorApiRendererFactory.php
WorkflowDescriptorApiRendererFactory.createService
public function createService(ServiceLocatorInterface $serviceLocator) { /** @var ApiProblemRenderer $apiProblemRenderer */ $apiProblemRenderer = $serviceLocator->get(ApiProblemRenderer::class); $renderer = new WorkflowDescriptorApiRenderer($apiProblemRenderer); return $renderer; }
php
public function createService(ServiceLocatorInterface $serviceLocator) { /** @var ApiProblemRenderer $apiProblemRenderer */ $apiProblemRenderer = $serviceLocator->get(ApiProblemRenderer::class); $renderer = new WorkflowDescriptorApiRenderer($apiProblemRenderer); return $renderer; }
[ "public", "function", "createService", "(", "ServiceLocatorInterface", "$", "serviceLocator", ")", "{", "/** @var ApiProblemRenderer $apiProblemRenderer */", "$", "apiProblemRenderer", "=", "$", "serviceLocator", "->", "get", "(", "ApiProblemRenderer", "::", "class", ")", ";", "$", "renderer", "=", "new", "WorkflowDescriptorApiRenderer", "(", "$", "apiProblemRenderer", ")", ";", "return", "$", "renderer", ";", "}" ]
{@inheritDoc} @return WorkflowDescriptorApiRenderer @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
[ "{", "@inheritDoc", "}", "@return", "WorkflowDescriptorApiRenderer" ]
train
https://github.com/old-town/workflow-designer-server/blob/6389c5a515861cc8e0b769f1ca7be12c6b78c611/src/Factory/WorkflowDescriptorApiRendererFactory.php#L26-L34
php-lug/lug
src/Bundle/GridBundle/Action/Type/LinkSecureType.php
LinkSecureType.render
public function render($data, array $options) { $action = $options['action']; return $this->formFactory->create(CsrfProtectionType::class, null, [ 'method' => strtoupper($options['method']), 'action' => parent::render($data, $options), 'label' => $action->getLabel(), 'translation_domain' => $action->getOption('trans_domain'), ])->createView(); }
php
public function render($data, array $options) { $action = $options['action']; return $this->formFactory->create(CsrfProtectionType::class, null, [ 'method' => strtoupper($options['method']), 'action' => parent::render($data, $options), 'label' => $action->getLabel(), 'translation_domain' => $action->getOption('trans_domain'), ])->createView(); }
[ "public", "function", "render", "(", "$", "data", ",", "array", "$", "options", ")", "{", "$", "action", "=", "$", "options", "[", "'action'", "]", ";", "return", "$", "this", "->", "formFactory", "->", "create", "(", "CsrfProtectionType", "::", "class", ",", "null", ",", "[", "'method'", "=>", "strtoupper", "(", "$", "options", "[", "'method'", "]", ")", ",", "'action'", "=>", "parent", "::", "render", "(", "$", "data", ",", "$", "options", ")", ",", "'label'", "=>", "$", "action", "->", "getLabel", "(", ")", ",", "'translation_domain'", "=>", "$", "action", "->", "getOption", "(", "'trans_domain'", ")", ",", "]", ")", "->", "createView", "(", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Action/Type/LinkSecureType.php#L49-L59
php-lug/lug
src/Bundle/GridBundle/Action/Type/LinkSecureType.php
LinkSecureType.configureOptions
public function configureOptions(OptionsResolver $resolver) { parent::configureOptions($resolver); $resolver ->setDefault('method', Request::METHOD_GET) ->setAllowedTypes('method', 'string'); }
php
public function configureOptions(OptionsResolver $resolver) { parent::configureOptions($resolver); $resolver ->setDefault('method', Request::METHOD_GET) ->setAllowedTypes('method', 'string'); }
[ "public", "function", "configureOptions", "(", "OptionsResolver", "$", "resolver", ")", "{", "parent", "::", "configureOptions", "(", "$", "resolver", ")", ";", "$", "resolver", "->", "setDefault", "(", "'method'", ",", "Request", "::", "METHOD_GET", ")", "->", "setAllowedTypes", "(", "'method'", ",", "'string'", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Action/Type/LinkSecureType.php#L64-L71
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php
ezcBase.autoload
public static function autoload( $className ) { Eresus_Kernel::log(__METHOD__, LOG_DEBUG, '(%s)', $className); ezcBase::setPackageDir(); // Check whether the classname is already in the cached autoloadArray. if ( array_key_exists( $className, ezcBase::$autoloadArray ) ) { // Is it registered as 'unloadable'? if ( ezcBase::$autoloadArray[$className] == false ) { return false; } ezcBase::loadFile( ezcBase::$autoloadArray[$className] ); return true; } // Check whether the classname is already in the cached autoloadArray // for external repositories. if ( array_key_exists( $className, ezcBase::$externalAutoloadArray ) ) { // Is it registered as 'unloadable'? if ( ezcBase::$externalAutoloadArray[$className] == false ) { return false; } ezcBase::loadExternalFile( ezcBase::$externalAutoloadArray[$className] ); return true; } // Not cached, so load the autoload from the package. // Matches the first and optionally the second 'word' from the classname. $fileNames = array(); if ( preg_match( "/^([a-z0-9]*)([A-Z][a-z0-9]*)?([A-Z][a-z0-9]*)?/", $className, $matches ) !== false ) { $autoloadFile = ""; // Try to match with both names, if available. switch ( sizeof( $matches ) ) { case 4: // check for x_y_autoload.php $autoloadFile = strtolower( "{$matches[2]}_{$matches[3]}_autoload.php" ); $fileNames[] = $autoloadFile; if ( ezcBase::requireFile( $autoloadFile, $className, $matches[1] ) ) { return true; } // break intentionally missing. case 3: // check for x_autoload.php $autoloadFile = strtolower( "{$matches[2]}_autoload.php" ); $fileNames[] = $autoloadFile; if ( ezcBase::requireFile( $autoloadFile, $className, $matches[1] ) ) { return true; } // break intentionally missing. case 2: // check for autoload.php $autoloadFile = 'autoload.php'; $fileNames[] = $autoloadFile; if ( ezcBase::requireFile( $autoloadFile, $className, $matches[1] ) ) { return true; } break; } // Maybe there is another autoload available. // Register this classname as false. ezcBase::$autoloadArray[$className] = false; } $path = ezcBase::$packageDir . 'autoload/'; $realPath = realpath( $path ); if ( $realPath == '' ) { // Can not be tested, because if this happens, then the autoload // environment has not been set-up correctly. trigger_error( "Couldn't find autoload directory '$path'", E_USER_ERROR ); } $dirs = self::getRepositoryDirectories(); if ( ezcBase::$options && ezcBase::$options->debug ) { throw new ezcBaseAutoloadException( $className, $fileNames, $dirs ); } return false; }
php
public static function autoload( $className ) { Eresus_Kernel::log(__METHOD__, LOG_DEBUG, '(%s)', $className); ezcBase::setPackageDir(); // Check whether the classname is already in the cached autoloadArray. if ( array_key_exists( $className, ezcBase::$autoloadArray ) ) { // Is it registered as 'unloadable'? if ( ezcBase::$autoloadArray[$className] == false ) { return false; } ezcBase::loadFile( ezcBase::$autoloadArray[$className] ); return true; } // Check whether the classname is already in the cached autoloadArray // for external repositories. if ( array_key_exists( $className, ezcBase::$externalAutoloadArray ) ) { // Is it registered as 'unloadable'? if ( ezcBase::$externalAutoloadArray[$className] == false ) { return false; } ezcBase::loadExternalFile( ezcBase::$externalAutoloadArray[$className] ); return true; } // Not cached, so load the autoload from the package. // Matches the first and optionally the second 'word' from the classname. $fileNames = array(); if ( preg_match( "/^([a-z0-9]*)([A-Z][a-z0-9]*)?([A-Z][a-z0-9]*)?/", $className, $matches ) !== false ) { $autoloadFile = ""; // Try to match with both names, if available. switch ( sizeof( $matches ) ) { case 4: // check for x_y_autoload.php $autoloadFile = strtolower( "{$matches[2]}_{$matches[3]}_autoload.php" ); $fileNames[] = $autoloadFile; if ( ezcBase::requireFile( $autoloadFile, $className, $matches[1] ) ) { return true; } // break intentionally missing. case 3: // check for x_autoload.php $autoloadFile = strtolower( "{$matches[2]}_autoload.php" ); $fileNames[] = $autoloadFile; if ( ezcBase::requireFile( $autoloadFile, $className, $matches[1] ) ) { return true; } // break intentionally missing. case 2: // check for autoload.php $autoloadFile = 'autoload.php'; $fileNames[] = $autoloadFile; if ( ezcBase::requireFile( $autoloadFile, $className, $matches[1] ) ) { return true; } break; } // Maybe there is another autoload available. // Register this classname as false. ezcBase::$autoloadArray[$className] = false; } $path = ezcBase::$packageDir . 'autoload/'; $realPath = realpath( $path ); if ( $realPath == '' ) { // Can not be tested, because if this happens, then the autoload // environment has not been set-up correctly. trigger_error( "Couldn't find autoload directory '$path'", E_USER_ERROR ); } $dirs = self::getRepositoryDirectories(); if ( ezcBase::$options && ezcBase::$options->debug ) { throw new ezcBaseAutoloadException( $className, $fileNames, $dirs ); } return false; }
[ "public", "static", "function", "autoload", "(", "$", "className", ")", "{", "Eresus_Kernel", "::", "log", "(", "__METHOD__", ",", "LOG_DEBUG", ",", "'(%s)'", ",", "$", "className", ")", ";", "ezcBase", "::", "setPackageDir", "(", ")", ";", "// Check whether the classname is already in the cached autoloadArray.", "if", "(", "array_key_exists", "(", "$", "className", ",", "ezcBase", "::", "$", "autoloadArray", ")", ")", "{", "// Is it registered as 'unloadable'?", "if", "(", "ezcBase", "::", "$", "autoloadArray", "[", "$", "className", "]", "==", "false", ")", "{", "return", "false", ";", "}", "ezcBase", "::", "loadFile", "(", "ezcBase", "::", "$", "autoloadArray", "[", "$", "className", "]", ")", ";", "return", "true", ";", "}", "// Check whether the classname is already in the cached autoloadArray", "// for external repositories.", "if", "(", "array_key_exists", "(", "$", "className", ",", "ezcBase", "::", "$", "externalAutoloadArray", ")", ")", "{", "// Is it registered as 'unloadable'?", "if", "(", "ezcBase", "::", "$", "externalAutoloadArray", "[", "$", "className", "]", "==", "false", ")", "{", "return", "false", ";", "}", "ezcBase", "::", "loadExternalFile", "(", "ezcBase", "::", "$", "externalAutoloadArray", "[", "$", "className", "]", ")", ";", "return", "true", ";", "}", "// Not cached, so load the autoload from the package.", "// Matches the first and optionally the second 'word' from the classname.", "$", "fileNames", "=", "array", "(", ")", ";", "if", "(", "preg_match", "(", "\"/^([a-z0-9]*)([A-Z][a-z0-9]*)?([A-Z][a-z0-9]*)?/\"", ",", "$", "className", ",", "$", "matches", ")", "!==", "false", ")", "{", "$", "autoloadFile", "=", "\"\"", ";", "// Try to match with both names, if available.", "switch", "(", "sizeof", "(", "$", "matches", ")", ")", "{", "case", "4", ":", "// check for x_y_autoload.php", "$", "autoloadFile", "=", "strtolower", "(", "\"{$matches[2]}_{$matches[3]}_autoload.php\"", ")", ";", "$", "fileNames", "[", "]", "=", "$", "autoloadFile", ";", "if", "(", "ezcBase", "::", "requireFile", "(", "$", "autoloadFile", ",", "$", "className", ",", "$", "matches", "[", "1", "]", ")", ")", "{", "return", "true", ";", "}", "// break intentionally missing.", "case", "3", ":", "// check for x_autoload.php", "$", "autoloadFile", "=", "strtolower", "(", "\"{$matches[2]}_autoload.php\"", ")", ";", "$", "fileNames", "[", "]", "=", "$", "autoloadFile", ";", "if", "(", "ezcBase", "::", "requireFile", "(", "$", "autoloadFile", ",", "$", "className", ",", "$", "matches", "[", "1", "]", ")", ")", "{", "return", "true", ";", "}", "// break intentionally missing.", "case", "2", ":", "// check for autoload.php", "$", "autoloadFile", "=", "'autoload.php'", ";", "$", "fileNames", "[", "]", "=", "$", "autoloadFile", ";", "if", "(", "ezcBase", "::", "requireFile", "(", "$", "autoloadFile", ",", "$", "className", ",", "$", "matches", "[", "1", "]", ")", ")", "{", "return", "true", ";", "}", "break", ";", "}", "// Maybe there is another autoload available.", "// Register this classname as false.", "ezcBase", "::", "$", "autoloadArray", "[", "$", "className", "]", "=", "false", ";", "}", "$", "path", "=", "ezcBase", "::", "$", "packageDir", ".", "'autoload/'", ";", "$", "realPath", "=", "realpath", "(", "$", "path", ")", ";", "if", "(", "$", "realPath", "==", "''", ")", "{", "// Can not be tested, because if this happens, then the autoload", "// environment has not been set-up correctly.", "trigger_error", "(", "\"Couldn't find autoload directory '$path'\"", ",", "E_USER_ERROR", ")", ";", "}", "$", "dirs", "=", "self", "::", "getRepositoryDirectories", "(", ")", ";", "if", "(", "ezcBase", "::", "$", "options", "&&", "ezcBase", "::", "$", "options", "->", "debug", ")", "{", "throw", "new", "ezcBaseAutoloadException", "(", "$", "className", ",", "$", "fileNames", ",", "$", "dirs", ")", ";", "}", "return", "false", ";", "}" ]
Tries to autoload the given className. If the className could be found this method returns true, otherwise false. This class caches the requested class names (including the ones who failed to load). @param string $className The name of the class that should be loaded. @return bool
[ "Tries", "to", "autoload", "the", "given", "className", ".", "If", "the", "className", "could", "be", "found", "this", "method", "returns", "true", "otherwise", "false", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php#L123-L217
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php
ezcBase.setPackageDir
protected static function setPackageDir() { if ( ezcBase::$packageDir !== null ) { return; } // Get the path to the components. $baseDir = dirname( __FILE__ ); switch ( ezcBase::$libraryMode ) { case "custom": ezcBase::$packageDir = self::$currentWorkingDirectory . '/'; break; case "devel": case "tarball": ezcBase::$packageDir = $baseDir. "/../../"; break; case "pear"; ezcBase::$packageDir = $baseDir. "/../"; break; } }
php
protected static function setPackageDir() { if ( ezcBase::$packageDir !== null ) { return; } // Get the path to the components. $baseDir = dirname( __FILE__ ); switch ( ezcBase::$libraryMode ) { case "custom": ezcBase::$packageDir = self::$currentWorkingDirectory . '/'; break; case "devel": case "tarball": ezcBase::$packageDir = $baseDir. "/../../"; break; case "pear"; ezcBase::$packageDir = $baseDir. "/../"; break; } }
[ "protected", "static", "function", "setPackageDir", "(", ")", "{", "if", "(", "ezcBase", "::", "$", "packageDir", "!==", "null", ")", "{", "return", ";", "}", "// Get the path to the components.", "$", "baseDir", "=", "dirname", "(", "__FILE__", ")", ";", "switch", "(", "ezcBase", "::", "$", "libraryMode", ")", "{", "case", "\"custom\"", ":", "ezcBase", "::", "$", "packageDir", "=", "self", "::", "$", "currentWorkingDirectory", ".", "'/'", ";", "break", ";", "case", "\"devel\"", ":", "case", "\"tarball\"", ":", "ezcBase", "::", "$", "packageDir", "=", "$", "baseDir", ".", "\"/../../\"", ";", "break", ";", "case", "\"pear\"", ";", "ezcBase", "::", "$", "packageDir", "=", "$", "baseDir", ".", "\"/../\"", ";", "break", ";", "}", "}" ]
Figures out the base path of the eZ Components installation. It stores the path that it finds in a static member variable. The path depends on the installation method of the eZ Components. The SVN version has a different path than the PEAR installed version.
[ "Figures", "out", "the", "base", "path", "of", "the", "eZ", "Components", "installation", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php#L237-L260
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php
ezcBase.requireFile
protected static function requireFile( $fileName, $className, $prefix ) { $autoloadDir = ezcBase::$packageDir . "autoload/"; // We need the full path to the fileName. The method file_exists() doesn't // automatically check the (php.ini) library paths. Therefore: // file_exists( "ezc/autoload/$fileName" ) doesn't work. if ( $prefix === 'ezc' && file_exists( "$autoloadDir$fileName" ) ) { $array = require( "$autoloadDir$fileName" ); if ( is_array( $array) && array_key_exists( $className, $array ) ) { // Add the array to the cache, and include the requested file. ezcBase::$autoloadArray = array_merge( ezcBase::$autoloadArray, $array ); if ( ezcBase::$options !== null && ezcBase::$options->preload && !preg_match( '/Exception$/', $className ) ) { foreach ( $array as $loadClassName => $file ) { if ( $loadClassName !== 'ezcBase' && !class_exists( $loadClassName, false ) && !interface_exists( $loadClassName, false ) && !preg_match( '/Exception$/', $loadClassName ) /*&& !class_exists( $loadClassName, false ) && !interface_exists( $loadClassName, false )*/ ) { ezcBase::loadFile( ezcBase::$autoloadArray[$loadClassName] ); } } } else { ezcBase::loadFile( ezcBase::$autoloadArray[$className] ); } return true; } } // It is not in components autoload/ dir. // try to search in additional dirs. foreach ( ezcBase::$repositoryDirs as $repositoryPrefix => $extraDir ) { if ( gettype( $repositoryPrefix ) === 'string' && $repositoryPrefix !== $prefix ) { continue; } if ( file_exists( $extraDir['autoloadDirPath'] . '/' . $fileName ) ) { $array = array(); $originalArray = require( $extraDir['autoloadDirPath'] . '/' . $fileName ); // Building paths. // Resulting path to class definition file consists of: // path to extra directory with autoload file + // basePath provided for current extra directory + // path to class definition file stored in autoload file. foreach ( $originalArray as $class => $classPath ) { $array[$class] = $extraDir['basePath'] . '/' . $classPath; } if ( is_array( $array ) && array_key_exists( $className, $array ) ) { // Add the array to the cache, and include the requested file. ezcBase::$externalAutoloadArray = array_merge( ezcBase::$externalAutoloadArray, $array ); ezcBase::loadExternalFile( ezcBase::$externalAutoloadArray[$className] ); return true; } } } // Nothing found :-(. return false; }
php
protected static function requireFile( $fileName, $className, $prefix ) { $autoloadDir = ezcBase::$packageDir . "autoload/"; // We need the full path to the fileName. The method file_exists() doesn't // automatically check the (php.ini) library paths. Therefore: // file_exists( "ezc/autoload/$fileName" ) doesn't work. if ( $prefix === 'ezc' && file_exists( "$autoloadDir$fileName" ) ) { $array = require( "$autoloadDir$fileName" ); if ( is_array( $array) && array_key_exists( $className, $array ) ) { // Add the array to the cache, and include the requested file. ezcBase::$autoloadArray = array_merge( ezcBase::$autoloadArray, $array ); if ( ezcBase::$options !== null && ezcBase::$options->preload && !preg_match( '/Exception$/', $className ) ) { foreach ( $array as $loadClassName => $file ) { if ( $loadClassName !== 'ezcBase' && !class_exists( $loadClassName, false ) && !interface_exists( $loadClassName, false ) && !preg_match( '/Exception$/', $loadClassName ) /*&& !class_exists( $loadClassName, false ) && !interface_exists( $loadClassName, false )*/ ) { ezcBase::loadFile( ezcBase::$autoloadArray[$loadClassName] ); } } } else { ezcBase::loadFile( ezcBase::$autoloadArray[$className] ); } return true; } } // It is not in components autoload/ dir. // try to search in additional dirs. foreach ( ezcBase::$repositoryDirs as $repositoryPrefix => $extraDir ) { if ( gettype( $repositoryPrefix ) === 'string' && $repositoryPrefix !== $prefix ) { continue; } if ( file_exists( $extraDir['autoloadDirPath'] . '/' . $fileName ) ) { $array = array(); $originalArray = require( $extraDir['autoloadDirPath'] . '/' . $fileName ); // Building paths. // Resulting path to class definition file consists of: // path to extra directory with autoload file + // basePath provided for current extra directory + // path to class definition file stored in autoload file. foreach ( $originalArray as $class => $classPath ) { $array[$class] = $extraDir['basePath'] . '/' . $classPath; } if ( is_array( $array ) && array_key_exists( $className, $array ) ) { // Add the array to the cache, and include the requested file. ezcBase::$externalAutoloadArray = array_merge( ezcBase::$externalAutoloadArray, $array ); ezcBase::loadExternalFile( ezcBase::$externalAutoloadArray[$className] ); return true; } } } // Nothing found :-(. return false; }
[ "protected", "static", "function", "requireFile", "(", "$", "fileName", ",", "$", "className", ",", "$", "prefix", ")", "{", "$", "autoloadDir", "=", "ezcBase", "::", "$", "packageDir", ".", "\"autoload/\"", ";", "// We need the full path to the fileName. The method file_exists() doesn't", "// automatically check the (php.ini) library paths. Therefore:", "// file_exists( \"ezc/autoload/$fileName\" ) doesn't work.", "if", "(", "$", "prefix", "===", "'ezc'", "&&", "file_exists", "(", "\"$autoloadDir$fileName\"", ")", ")", "{", "$", "array", "=", "require", "(", "\"$autoloadDir$fileName\"", ")", ";", "if", "(", "is_array", "(", "$", "array", ")", "&&", "array_key_exists", "(", "$", "className", ",", "$", "array", ")", ")", "{", "// Add the array to the cache, and include the requested file.", "ezcBase", "::", "$", "autoloadArray", "=", "array_merge", "(", "ezcBase", "::", "$", "autoloadArray", ",", "$", "array", ")", ";", "if", "(", "ezcBase", "::", "$", "options", "!==", "null", "&&", "ezcBase", "::", "$", "options", "->", "preload", "&&", "!", "preg_match", "(", "'/Exception$/'", ",", "$", "className", ")", ")", "{", "foreach", "(", "$", "array", "as", "$", "loadClassName", "=>", "$", "file", ")", "{", "if", "(", "$", "loadClassName", "!==", "'ezcBase'", "&&", "!", "class_exists", "(", "$", "loadClassName", ",", "false", ")", "&&", "!", "interface_exists", "(", "$", "loadClassName", ",", "false", ")", "&&", "!", "preg_match", "(", "'/Exception$/'", ",", "$", "loadClassName", ")", "/*&& !class_exists( $loadClassName, false ) && !interface_exists( $loadClassName, false )*/", ")", "{", "ezcBase", "::", "loadFile", "(", "ezcBase", "::", "$", "autoloadArray", "[", "$", "loadClassName", "]", ")", ";", "}", "}", "}", "else", "{", "ezcBase", "::", "loadFile", "(", "ezcBase", "::", "$", "autoloadArray", "[", "$", "className", "]", ")", ";", "}", "return", "true", ";", "}", "}", "// It is not in components autoload/ dir.", "// try to search in additional dirs.", "foreach", "(", "ezcBase", "::", "$", "repositoryDirs", "as", "$", "repositoryPrefix", "=>", "$", "extraDir", ")", "{", "if", "(", "gettype", "(", "$", "repositoryPrefix", ")", "===", "'string'", "&&", "$", "repositoryPrefix", "!==", "$", "prefix", ")", "{", "continue", ";", "}", "if", "(", "file_exists", "(", "$", "extraDir", "[", "'autoloadDirPath'", "]", ".", "'/'", ".", "$", "fileName", ")", ")", "{", "$", "array", "=", "array", "(", ")", ";", "$", "originalArray", "=", "require", "(", "$", "extraDir", "[", "'autoloadDirPath'", "]", ".", "'/'", ".", "$", "fileName", ")", ";", "// Building paths.", "// Resulting path to class definition file consists of:", "// path to extra directory with autoload file +", "// basePath provided for current extra directory +", "// path to class definition file stored in autoload file.", "foreach", "(", "$", "originalArray", "as", "$", "class", "=>", "$", "classPath", ")", "{", "$", "array", "[", "$", "class", "]", "=", "$", "extraDir", "[", "'basePath'", "]", ".", "'/'", ".", "$", "classPath", ";", "}", "if", "(", "is_array", "(", "$", "array", ")", "&&", "array_key_exists", "(", "$", "className", ",", "$", "array", ")", ")", "{", "// Add the array to the cache, and include the requested file.", "ezcBase", "::", "$", "externalAutoloadArray", "=", "array_merge", "(", "ezcBase", "::", "$", "externalAutoloadArray", ",", "$", "array", ")", ";", "ezcBase", "::", "loadExternalFile", "(", "ezcBase", "::", "$", "externalAutoloadArray", "[", "$", "className", "]", ")", ";", "return", "true", ";", "}", "}", "}", "// Nothing found :-(.", "return", "false", ";", "}" ]
Tries to load the autoload array and, if loaded correctly, includes the class. @param string $fileName Name of the autoload file. @param string $className Name of the class that should be autoloaded. @param string $prefix The prefix of the class repository. @return bool True is returned when the file is correctly loaded. Otherwise false is returned.
[ "Tries", "to", "load", "the", "autoload", "array", "and", "if", "loaded", "correctly", "includes", "the", "class", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php#L272-L341
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php
ezcBase.loadFile
protected static function loadFile( $file ) { switch ( ezcBase::$libraryMode ) { case "devel": case "tarball": list( $first, $second ) = explode( '/', $file, 2 ); $file = $first . "/src/" . $second; break; case "custom": list( $first, $second ) = explode( '/', $file, 2 ); // Add the "src/" after the package name. if ( $first == 'Base' || $first == 'UnitTest' ) { list( $first, $second ) = explode( '/', $file, 2 ); $file = $first . "/src/" . $second; } else { list( $first, $second, $third ) = explode( '/', $file, 3 ); $file = $first . '/' . $second . "/src/" . $third; } break; case "pear": /* do nothing, it's already correct */ break; } if ( file_exists( ezcBase::$packageDir . $file ) ) { require( ezcBase::$packageDir . $file ); } else { // Can not be tested, because if this happens, then one of the // components has a broken autoload file. throw new ezcBaseFileNotFoundException( ezcBase::$packageDir.$file ); } }
php
protected static function loadFile( $file ) { switch ( ezcBase::$libraryMode ) { case "devel": case "tarball": list( $first, $second ) = explode( '/', $file, 2 ); $file = $first . "/src/" . $second; break; case "custom": list( $first, $second ) = explode( '/', $file, 2 ); // Add the "src/" after the package name. if ( $first == 'Base' || $first == 'UnitTest' ) { list( $first, $second ) = explode( '/', $file, 2 ); $file = $first . "/src/" . $second; } else { list( $first, $second, $third ) = explode( '/', $file, 3 ); $file = $first . '/' . $second . "/src/" . $third; } break; case "pear": /* do nothing, it's already correct */ break; } if ( file_exists( ezcBase::$packageDir . $file ) ) { require( ezcBase::$packageDir . $file ); } else { // Can not be tested, because if this happens, then one of the // components has a broken autoload file. throw new ezcBaseFileNotFoundException( ezcBase::$packageDir.$file ); } }
[ "protected", "static", "function", "loadFile", "(", "$", "file", ")", "{", "switch", "(", "ezcBase", "::", "$", "libraryMode", ")", "{", "case", "\"devel\"", ":", "case", "\"tarball\"", ":", "list", "(", "$", "first", ",", "$", "second", ")", "=", "explode", "(", "'/'", ",", "$", "file", ",", "2", ")", ";", "$", "file", "=", "$", "first", ".", "\"/src/\"", ".", "$", "second", ";", "break", ";", "case", "\"custom\"", ":", "list", "(", "$", "first", ",", "$", "second", ")", "=", "explode", "(", "'/'", ",", "$", "file", ",", "2", ")", ";", "// Add the \"src/\" after the package name.", "if", "(", "$", "first", "==", "'Base'", "||", "$", "first", "==", "'UnitTest'", ")", "{", "list", "(", "$", "first", ",", "$", "second", ")", "=", "explode", "(", "'/'", ",", "$", "file", ",", "2", ")", ";", "$", "file", "=", "$", "first", ".", "\"/src/\"", ".", "$", "second", ";", "}", "else", "{", "list", "(", "$", "first", ",", "$", "second", ",", "$", "third", ")", "=", "explode", "(", "'/'", ",", "$", "file", ",", "3", ")", ";", "$", "file", "=", "$", "first", ".", "'/'", ".", "$", "second", ".", "\"/src/\"", ".", "$", "third", ";", "}", "break", ";", "case", "\"pear\"", ":", "/* do nothing, it's already correct */", "break", ";", "}", "if", "(", "file_exists", "(", "ezcBase", "::", "$", "packageDir", ".", "$", "file", ")", ")", "{", "require", "(", "ezcBase", "::", "$", "packageDir", ".", "$", "file", ")", ";", "}", "else", "{", "// Can not be tested, because if this happens, then one of the", "// components has a broken autoload file.", "throw", "new", "ezcBaseFileNotFoundException", "(", "ezcBase", "::", "$", "packageDir", ".", "$", "file", ")", ";", "}", "}" ]
Loads, require(), the given file name. If we are in development mode, "/src/" is inserted into the path. @param string $file The name of the file that should be loaded.
[ "Loads", "require", "()", "the", "given", "file", "name", ".", "If", "we", "are", "in", "development", "mode", "/", "src", "/", "is", "inserted", "into", "the", "path", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php#L349-L389
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php
ezcBase.checkDependency
public static function checkDependency( $component, $type, $value ) { switch ( $type ) { case self::DEP_PHP_EXTENSION: if ( extension_loaded( $value ) ) { return; } else { // Can not be tested as it would abort the PHP script. die( "\nThe {$component} component depends on the default PHP extension '{$value}', which is not loaded.\n" ); } break; case self::DEP_PHP_VERSION: $phpVersion = phpversion(); if ( version_compare( $phpVersion, $value, '>=' ) ) { return; } else { // Can not be tested as it would abort the PHP script. die( "\nThe {$component} component depends on the PHP version '{$value}', but the current version is '{$phpVersion}'.\n" ); } break; } }
php
public static function checkDependency( $component, $type, $value ) { switch ( $type ) { case self::DEP_PHP_EXTENSION: if ( extension_loaded( $value ) ) { return; } else { // Can not be tested as it would abort the PHP script. die( "\nThe {$component} component depends on the default PHP extension '{$value}', which is not loaded.\n" ); } break; case self::DEP_PHP_VERSION: $phpVersion = phpversion(); if ( version_compare( $phpVersion, $value, '>=' ) ) { return; } else { // Can not be tested as it would abort the PHP script. die( "\nThe {$component} component depends on the PHP version '{$value}', but the current version is '{$phpVersion}'.\n" ); } break; } }
[ "public", "static", "function", "checkDependency", "(", "$", "component", ",", "$", "type", ",", "$", "value", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "self", "::", "DEP_PHP_EXTENSION", ":", "if", "(", "extension_loaded", "(", "$", "value", ")", ")", "{", "return", ";", "}", "else", "{", "// Can not be tested as it would abort the PHP script.", "die", "(", "\"\\nThe {$component} component depends on the default PHP extension '{$value}', which is not loaded.\\n\"", ")", ";", "}", "break", ";", "case", "self", "::", "DEP_PHP_VERSION", ":", "$", "phpVersion", "=", "phpversion", "(", ")", ";", "if", "(", "version_compare", "(", "$", "phpVersion", ",", "$", "value", ",", "'>='", ")", ")", "{", "return", ";", "}", "else", "{", "// Can not be tested as it would abort the PHP script.", "die", "(", "\"\\nThe {$component} component depends on the PHP version '{$value}', but the current version is '{$phpVersion}'.\\n\"", ")", ";", "}", "break", ";", "}", "}" ]
Checks for dependencies on PHP versions or extensions The function as called by the $component component checks for the $type dependency. The dependency $type is compared against the $value. The function aborts the script if the dependency is not matched. @param string $component @param int $type @param mixed $value
[ "Checks", "for", "dependencies", "on", "PHP", "versions", "or", "extensions" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php#L419-L448
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php
ezcBase.getRepositoryDirectories
public static function getRepositoryDirectories() { $autoloadDirs = array(); ezcBase::setPackageDir(); $repositoryDir = self::$currentWorkingDirectory ? self::$currentWorkingDirectory : ( realpath( dirname( __FILE__ ) . '/../../' ) ); $autoloadDirs['ezc'] = new ezcBaseRepositoryDirectory( ezcBaseRepositoryDirectory::TYPE_INTERNAL, $repositoryDir, $repositoryDir . "/autoload" ); foreach ( ezcBase::$repositoryDirs as $extraDirKey => $extraDirArray ) { $repositoryDirectory = new ezcBaseRepositoryDirectory( ezcBaseRepositoryDirectory::TYPE_EXTERNAL, realpath( $extraDirArray['basePath'] ), realpath( $extraDirArray['autoloadDirPath'] ) ); $autoloadDirs[$extraDirKey] = $repositoryDirectory; } return $autoloadDirs; }
php
public static function getRepositoryDirectories() { $autoloadDirs = array(); ezcBase::setPackageDir(); $repositoryDir = self::$currentWorkingDirectory ? self::$currentWorkingDirectory : ( realpath( dirname( __FILE__ ) . '/../../' ) ); $autoloadDirs['ezc'] = new ezcBaseRepositoryDirectory( ezcBaseRepositoryDirectory::TYPE_INTERNAL, $repositoryDir, $repositoryDir . "/autoload" ); foreach ( ezcBase::$repositoryDirs as $extraDirKey => $extraDirArray ) { $repositoryDirectory = new ezcBaseRepositoryDirectory( ezcBaseRepositoryDirectory::TYPE_EXTERNAL, realpath( $extraDirArray['basePath'] ), realpath( $extraDirArray['autoloadDirPath'] ) ); $autoloadDirs[$extraDirKey] = $repositoryDirectory; } return $autoloadDirs; }
[ "public", "static", "function", "getRepositoryDirectories", "(", ")", "{", "$", "autoloadDirs", "=", "array", "(", ")", ";", "ezcBase", "::", "setPackageDir", "(", ")", ";", "$", "repositoryDir", "=", "self", "::", "$", "currentWorkingDirectory", "?", "self", "::", "$", "currentWorkingDirectory", ":", "(", "realpath", "(", "dirname", "(", "__FILE__", ")", ".", "'/../../'", ")", ")", ";", "$", "autoloadDirs", "[", "'ezc'", "]", "=", "new", "ezcBaseRepositoryDirectory", "(", "ezcBaseRepositoryDirectory", "::", "TYPE_INTERNAL", ",", "$", "repositoryDir", ",", "$", "repositoryDir", ".", "\"/autoload\"", ")", ";", "foreach", "(", "ezcBase", "::", "$", "repositoryDirs", "as", "$", "extraDirKey", "=>", "$", "extraDirArray", ")", "{", "$", "repositoryDirectory", "=", "new", "ezcBaseRepositoryDirectory", "(", "ezcBaseRepositoryDirectory", "::", "TYPE_EXTERNAL", ",", "realpath", "(", "$", "extraDirArray", "[", "'basePath'", "]", ")", ",", "realpath", "(", "$", "extraDirArray", "[", "'autoloadDirPath'", "]", ")", ")", ";", "$", "autoloadDirs", "[", "$", "extraDirKey", "]", "=", "$", "repositoryDirectory", ";", "}", "return", "$", "autoloadDirs", ";", "}" ]
Return the list of directories that contain class repositories. The path to the eZ components directory is always included in the result array. Each element in the returned array has the format of: packageDirectory => ezcBaseRepositoryDirectory @return array(string=>ezcBaseRepositoryDirectory)
[ "Return", "the", "list", "of", "directories", "that", "contain", "class", "repositories", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php#L459-L473
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php
ezcBase.addClassRepository
public static function addClassRepository( $basePath, $autoloadDirPath = null, $prefix = null ) { // check if base path exists if ( !is_dir( $basePath ) ) { throw new ezcBaseFileNotFoundException( $basePath, 'base directory' ); } // calculate autoload path if it wasn't given if ( is_null( $autoloadDirPath ) ) { $autoloadDirPath = $basePath . '/autoload'; } // check if autoload dir exists if ( !is_dir( $autoloadDirPath ) ) { throw new ezcBaseFileNotFoundException( $autoloadDirPath, 'autoload directory' ); } // add info to $repositoryDirs if ( $prefix === null ) { $array = array( 'basePath' => $basePath, 'autoloadDirPath' => $autoloadDirPath ); // add info to the list of extra dirs ezcBase::$repositoryDirs[] = $array; } else { if ( array_key_exists( $prefix, ezcBase::$repositoryDirs ) ) { throw new ezcBaseDoubleClassRepositoryPrefixException( $prefix, $basePath, $autoloadDirPath ); } // add info to the list of extra dirs, and use the prefix to identify the new repository. ezcBase::$repositoryDirs[$prefix] = array( 'basePath' => $basePath, 'autoloadDirPath' => $autoloadDirPath ); } }
php
public static function addClassRepository( $basePath, $autoloadDirPath = null, $prefix = null ) { // check if base path exists if ( !is_dir( $basePath ) ) { throw new ezcBaseFileNotFoundException( $basePath, 'base directory' ); } // calculate autoload path if it wasn't given if ( is_null( $autoloadDirPath ) ) { $autoloadDirPath = $basePath . '/autoload'; } // check if autoload dir exists if ( !is_dir( $autoloadDirPath ) ) { throw new ezcBaseFileNotFoundException( $autoloadDirPath, 'autoload directory' ); } // add info to $repositoryDirs if ( $prefix === null ) { $array = array( 'basePath' => $basePath, 'autoloadDirPath' => $autoloadDirPath ); // add info to the list of extra dirs ezcBase::$repositoryDirs[] = $array; } else { if ( array_key_exists( $prefix, ezcBase::$repositoryDirs ) ) { throw new ezcBaseDoubleClassRepositoryPrefixException( $prefix, $basePath, $autoloadDirPath ); } // add info to the list of extra dirs, and use the prefix to identify the new repository. ezcBase::$repositoryDirs[$prefix] = array( 'basePath' => $basePath, 'autoloadDirPath' => $autoloadDirPath ); } }
[ "public", "static", "function", "addClassRepository", "(", "$", "basePath", ",", "$", "autoloadDirPath", "=", "null", ",", "$", "prefix", "=", "null", ")", "{", "// check if base path exists", "if", "(", "!", "is_dir", "(", "$", "basePath", ")", ")", "{", "throw", "new", "ezcBaseFileNotFoundException", "(", "$", "basePath", ",", "'base directory'", ")", ";", "}", "// calculate autoload path if it wasn't given", "if", "(", "is_null", "(", "$", "autoloadDirPath", ")", ")", "{", "$", "autoloadDirPath", "=", "$", "basePath", ".", "'/autoload'", ";", "}", "// check if autoload dir exists", "if", "(", "!", "is_dir", "(", "$", "autoloadDirPath", ")", ")", "{", "throw", "new", "ezcBaseFileNotFoundException", "(", "$", "autoloadDirPath", ",", "'autoload directory'", ")", ";", "}", "// add info to $repositoryDirs", "if", "(", "$", "prefix", "===", "null", ")", "{", "$", "array", "=", "array", "(", "'basePath'", "=>", "$", "basePath", ",", "'autoloadDirPath'", "=>", "$", "autoloadDirPath", ")", ";", "// add info to the list of extra dirs", "ezcBase", "::", "$", "repositoryDirs", "[", "]", "=", "$", "array", ";", "}", "else", "{", "if", "(", "array_key_exists", "(", "$", "prefix", ",", "ezcBase", "::", "$", "repositoryDirs", ")", ")", "{", "throw", "new", "ezcBaseDoubleClassRepositoryPrefixException", "(", "$", "prefix", ",", "$", "basePath", ",", "$", "autoloadDirPath", ")", ";", "}", "// add info to the list of extra dirs, and use the prefix to identify the new repository.", "ezcBase", "::", "$", "repositoryDirs", "[", "$", "prefix", "]", "=", "array", "(", "'basePath'", "=>", "$", "basePath", ",", "'autoloadDirPath'", "=>", "$", "autoloadDirPath", ")", ";", "}", "}" ]
Adds an additional class repository. Used for adding class repositoryies outside the eZ components to be loaded by the autoload system. This function takes two arguments: $basePath is the base path for the whole class repository and $autoloadDirPath the path where autoload files for this repository are found. The paths in the autoload files are relative to the package directory as specified by the $basePath argument. I.e. class definition file will be searched at location $basePath + path to the class definition file as stored in the autoload file. addClassRepository() should be called somewhere in code before external classes are used. Example: Take the following facts: <ul> <li>there is a class repository stored in the directory "./repos"</li> <li>autoload files for that repository are stored in "./repos/autoloads"</li> <li>there are two components in this repository: "Me" and "You"</li> <li>the "Me" component has the classes "erMyClass1" and "erMyClass2"</li> <li>the "You" component has the classes "erYourClass1" and "erYourClass2"</li> </ul> In this case you would need to create the following files in "./repos/autoloads". Please note that the part before _autoload.php in the filename is the first part of the <b>classname</b>, not considering the all lower-case letter prefix. "my_autoload.php": <code> <?php return array ( 'erMyClass1' => 'Me/myclass1.php', 'erMyClass2' => 'Me/myclass2.php', ); ?> </code> "your_autoload.php": <code> <?php return array ( 'erYourClass1' => 'You/yourclass1.php', 'erYourClass2' => 'You/yourclass2.php', ); ?> </code> The directory structure for the external repository is then: <code> ./repos/autoloads/my_autoload.php ./repos/autoloads/you_autoload.php ./repos/Me/myclass1.php ./repos/Me/myclass2.php ./repos/You/yourclass1.php ./repos/You/yourclass2.php </code> To use this repository with the autoload mechanism you have to use the following code: <code> <?php ezcBase::addClassRepository( './repos', './repos/autoloads' ); $myVar = new erMyClass2(); ?> </code> @throws ezcBaseFileNotFoundException if $autoloadDirPath or $basePath do not exist. @param string $basePath @param string $autoloadDirPath @param string $prefix
[ "Adds", "an", "additional", "class", "repository", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php#L551-L589
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php
ezcBase.getInstallationPath
public static function getInstallationPath() { self::setPackageDir(); $path = realpath( self::$packageDir ); if ( substr( $path, -1 ) !== DIRECTORY_SEPARATOR ) { $path .= DIRECTORY_SEPARATOR; } return $path; }
php
public static function getInstallationPath() { self::setPackageDir(); $path = realpath( self::$packageDir ); if ( substr( $path, -1 ) !== DIRECTORY_SEPARATOR ) { $path .= DIRECTORY_SEPARATOR; } return $path; }
[ "public", "static", "function", "getInstallationPath", "(", ")", "{", "self", "::", "setPackageDir", "(", ")", ";", "$", "path", "=", "realpath", "(", "self", "::", "$", "packageDir", ")", ";", "if", "(", "substr", "(", "$", "path", ",", "-", "1", ")", "!==", "DIRECTORY_SEPARATOR", ")", "{", "$", "path", ".=", "DIRECTORY_SEPARATOR", ";", "}", "return", "$", "path", ";", "}" ]
Returns the base path of the eZ Components installation This method returns the base path, including a trailing directory separator. @return string
[ "Returns", "the", "base", "path", "of", "the", "eZ", "Components", "installation" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php#L599-L609
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php
ezcBase.setRunMode
public static function setRunMode( $runMode ) { if ( !in_array( $runMode, array( ezcBase::MODE_PRODUCTION, ezcBase::MODE_DEVELOPMENT ) ) ) { throw new ezcBaseValueException( 'runMode', $runMode, 'ezcBase::MODE_PRODUCTION or ezcBase::MODE_DEVELOPMENT' ); } self::$runMode = $runMode; }
php
public static function setRunMode( $runMode ) { if ( !in_array( $runMode, array( ezcBase::MODE_PRODUCTION, ezcBase::MODE_DEVELOPMENT ) ) ) { throw new ezcBaseValueException( 'runMode', $runMode, 'ezcBase::MODE_PRODUCTION or ezcBase::MODE_DEVELOPMENT' ); } self::$runMode = $runMode; }
[ "public", "static", "function", "setRunMode", "(", "$", "runMode", ")", "{", "if", "(", "!", "in_array", "(", "$", "runMode", ",", "array", "(", "ezcBase", "::", "MODE_PRODUCTION", ",", "ezcBase", "::", "MODE_DEVELOPMENT", ")", ")", ")", "{", "throw", "new", "ezcBaseValueException", "(", "'runMode'", ",", "$", "runMode", ",", "'ezcBase::MODE_PRODUCTION or ezcBase::MODE_DEVELOPMENT'", ")", ";", "}", "self", "::", "$", "runMode", "=", "$", "runMode", ";", "}" ]
Sets the development mode to the one specified. @param int $runMode
[ "Sets", "the", "development", "mode", "to", "the", "one", "specified", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Base/src/base.php#L616-L624
xiewulong/yii2-fileupload
oss/libs/symfony/yaml/Symfony/Component/Yaml/Inline.php
Inline.parse
public static function parse($value, $exceptionOnInvalidType = false, $objectSupport = false) { self::$exceptionOnInvalidType = $exceptionOnInvalidType; self::$objectSupport = $objectSupport; $value = trim($value); if (0 == strlen($value)) { return ''; } if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding('ASCII'); } $i = 0; switch ($value[0]) { case '[': $result = self::parseSequence($value, $i); ++$i; break; case '{': $result = self::parseMapping($value, $i); ++$i; break; default: $result = self::parseScalar($value, null, array('"', "'"), $i); } // some comments are allowed at the end if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) { throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i))); } if (isset($mbEncoding)) { mb_internal_encoding($mbEncoding); } return $result; }
php
public static function parse($value, $exceptionOnInvalidType = false, $objectSupport = false) { self::$exceptionOnInvalidType = $exceptionOnInvalidType; self::$objectSupport = $objectSupport; $value = trim($value); if (0 == strlen($value)) { return ''; } if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding('ASCII'); } $i = 0; switch ($value[0]) { case '[': $result = self::parseSequence($value, $i); ++$i; break; case '{': $result = self::parseMapping($value, $i); ++$i; break; default: $result = self::parseScalar($value, null, array('"', "'"), $i); } // some comments are allowed at the end if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) { throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i))); } if (isset($mbEncoding)) { mb_internal_encoding($mbEncoding); } return $result; }
[ "public", "static", "function", "parse", "(", "$", "value", ",", "$", "exceptionOnInvalidType", "=", "false", ",", "$", "objectSupport", "=", "false", ")", "{", "self", "::", "$", "exceptionOnInvalidType", "=", "$", "exceptionOnInvalidType", ";", "self", "::", "$", "objectSupport", "=", "$", "objectSupport", ";", "$", "value", "=", "trim", "(", "$", "value", ")", ";", "if", "(", "0", "==", "strlen", "(", "$", "value", ")", ")", "{", "return", "''", ";", "}", "if", "(", "function_exists", "(", "'mb_internal_encoding'", ")", "&&", "(", "(", "int", ")", "ini_get", "(", "'mbstring.func_overload'", ")", ")", "&", "2", ")", "{", "$", "mbEncoding", "=", "mb_internal_encoding", "(", ")", ";", "mb_internal_encoding", "(", "'ASCII'", ")", ";", "}", "$", "i", "=", "0", ";", "switch", "(", "$", "value", "[", "0", "]", ")", "{", "case", "'['", ":", "$", "result", "=", "self", "::", "parseSequence", "(", "$", "value", ",", "$", "i", ")", ";", "++", "$", "i", ";", "break", ";", "case", "'{'", ":", "$", "result", "=", "self", "::", "parseMapping", "(", "$", "value", ",", "$", "i", ")", ";", "++", "$", "i", ";", "break", ";", "default", ":", "$", "result", "=", "self", "::", "parseScalar", "(", "$", "value", ",", "null", ",", "array", "(", "'\"'", ",", "\"'\"", ")", ",", "$", "i", ")", ";", "}", "// some comments are allowed at the end", "if", "(", "preg_replace", "(", "'/\\s+#.*$/A'", ",", "''", ",", "substr", "(", "$", "value", ",", "$", "i", ")", ")", ")", "{", "throw", "new", "ParseException", "(", "sprintf", "(", "'Unexpected characters near \"%s\".'", ",", "substr", "(", "$", "value", ",", "$", "i", ")", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "mbEncoding", ")", ")", "{", "mb_internal_encoding", "(", "$", "mbEncoding", ")", ";", "}", "return", "$", "result", ";", "}" ]
Converts a YAML string to a PHP array. @param string $value A YAML string @param Boolean $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise @param Boolean $objectSupport true if object support is enabled, false otherwise @return array A PHP array representing the YAML string @throws ParseException
[ "Converts", "a", "YAML", "string", "to", "a", "PHP", "array", "." ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/yaml/Symfony/Component/Yaml/Inline.php#L39-L79
xiewulong/yii2-fileupload
oss/libs/symfony/yaml/Symfony/Component/Yaml/Inline.php
Inline.dump
public static function dump($value, $exceptionOnInvalidType = false, $objectSupport = false) { switch (true) { case is_resource($value): if ($exceptionOnInvalidType) { throw new DumpException(sprintf('Unable to dump PHP resources in a YAML file ("%s").', get_resource_type($value))); } return 'null'; case is_object($value): if ($objectSupport) { return '!!php/object:'.serialize($value); } if ($exceptionOnInvalidType) { throw new DumpException('Object support when dumping a YAML file has been disabled.'); } return 'null'; case is_array($value): return self::dumpArray($value, $exceptionOnInvalidType, $objectSupport); case null === $value: return 'null'; case true === $value: return 'true'; case false === $value: return 'false'; case ctype_digit($value): return is_string($value) ? "'$value'" : (int) $value; case is_numeric($value): $locale = setlocale(LC_NUMERIC, 0); if (false !== $locale) { setlocale(LC_NUMERIC, 'C'); } $repr = is_string($value) ? "'$value'" : (is_infinite($value) ? str_ireplace('INF', '.Inf', strval($value)) : strval($value)); if (false !== $locale) { setlocale(LC_NUMERIC, $locale); } return $repr; case Escaper::requiresDoubleQuoting($value): return Escaper::escapeWithDoubleQuotes($value); case Escaper::requiresSingleQuoting($value): return Escaper::escapeWithSingleQuotes($value); case '' == $value: return "''"; case preg_match(self::getTimestampRegex(), $value): case in_array(strtolower($value), array('null', '~', 'true', 'false')): return "'$value'"; default: return $value; } }
php
public static function dump($value, $exceptionOnInvalidType = false, $objectSupport = false) { switch (true) { case is_resource($value): if ($exceptionOnInvalidType) { throw new DumpException(sprintf('Unable to dump PHP resources in a YAML file ("%s").', get_resource_type($value))); } return 'null'; case is_object($value): if ($objectSupport) { return '!!php/object:'.serialize($value); } if ($exceptionOnInvalidType) { throw new DumpException('Object support when dumping a YAML file has been disabled.'); } return 'null'; case is_array($value): return self::dumpArray($value, $exceptionOnInvalidType, $objectSupport); case null === $value: return 'null'; case true === $value: return 'true'; case false === $value: return 'false'; case ctype_digit($value): return is_string($value) ? "'$value'" : (int) $value; case is_numeric($value): $locale = setlocale(LC_NUMERIC, 0); if (false !== $locale) { setlocale(LC_NUMERIC, 'C'); } $repr = is_string($value) ? "'$value'" : (is_infinite($value) ? str_ireplace('INF', '.Inf', strval($value)) : strval($value)); if (false !== $locale) { setlocale(LC_NUMERIC, $locale); } return $repr; case Escaper::requiresDoubleQuoting($value): return Escaper::escapeWithDoubleQuotes($value); case Escaper::requiresSingleQuoting($value): return Escaper::escapeWithSingleQuotes($value); case '' == $value: return "''"; case preg_match(self::getTimestampRegex(), $value): case in_array(strtolower($value), array('null', '~', 'true', 'false')): return "'$value'"; default: return $value; } }
[ "public", "static", "function", "dump", "(", "$", "value", ",", "$", "exceptionOnInvalidType", "=", "false", ",", "$", "objectSupport", "=", "false", ")", "{", "switch", "(", "true", ")", "{", "case", "is_resource", "(", "$", "value", ")", ":", "if", "(", "$", "exceptionOnInvalidType", ")", "{", "throw", "new", "DumpException", "(", "sprintf", "(", "'Unable to dump PHP resources in a YAML file (\"%s\").'", ",", "get_resource_type", "(", "$", "value", ")", ")", ")", ";", "}", "return", "'null'", ";", "case", "is_object", "(", "$", "value", ")", ":", "if", "(", "$", "objectSupport", ")", "{", "return", "'!!php/object:'", ".", "serialize", "(", "$", "value", ")", ";", "}", "if", "(", "$", "exceptionOnInvalidType", ")", "{", "throw", "new", "DumpException", "(", "'Object support when dumping a YAML file has been disabled.'", ")", ";", "}", "return", "'null'", ";", "case", "is_array", "(", "$", "value", ")", ":", "return", "self", "::", "dumpArray", "(", "$", "value", ",", "$", "exceptionOnInvalidType", ",", "$", "objectSupport", ")", ";", "case", "null", "===", "$", "value", ":", "return", "'null'", ";", "case", "true", "===", "$", "value", ":", "return", "'true'", ";", "case", "false", "===", "$", "value", ":", "return", "'false'", ";", "case", "ctype_digit", "(", "$", "value", ")", ":", "return", "is_string", "(", "$", "value", ")", "?", "\"'$value'\"", ":", "(", "int", ")", "$", "value", ";", "case", "is_numeric", "(", "$", "value", ")", ":", "$", "locale", "=", "setlocale", "(", "LC_NUMERIC", ",", "0", ")", ";", "if", "(", "false", "!==", "$", "locale", ")", "{", "setlocale", "(", "LC_NUMERIC", ",", "'C'", ")", ";", "}", "$", "repr", "=", "is_string", "(", "$", "value", ")", "?", "\"'$value'\"", ":", "(", "is_infinite", "(", "$", "value", ")", "?", "str_ireplace", "(", "'INF'", ",", "'.Inf'", ",", "strval", "(", "$", "value", ")", ")", ":", "strval", "(", "$", "value", ")", ")", ";", "if", "(", "false", "!==", "$", "locale", ")", "{", "setlocale", "(", "LC_NUMERIC", ",", "$", "locale", ")", ";", "}", "return", "$", "repr", ";", "case", "Escaper", "::", "requiresDoubleQuoting", "(", "$", "value", ")", ":", "return", "Escaper", "::", "escapeWithDoubleQuotes", "(", "$", "value", ")", ";", "case", "Escaper", "::", "requiresSingleQuoting", "(", "$", "value", ")", ":", "return", "Escaper", "::", "escapeWithSingleQuotes", "(", "$", "value", ")", ";", "case", "''", "==", "$", "value", ":", "return", "\"''\"", ";", "case", "preg_match", "(", "self", "::", "getTimestampRegex", "(", ")", ",", "$", "value", ")", ":", "case", "in_array", "(", "strtolower", "(", "$", "value", ")", ",", "array", "(", "'null'", ",", "'~'", ",", "'true'", ",", "'false'", ")", ")", ":", "return", "\"'$value'\"", ";", "default", ":", "return", "$", "value", ";", "}", "}" ]
Dumps a given PHP variable to a YAML string. @param mixed $value The PHP variable to convert @param Boolean $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise @param Boolean $objectSupport true if object support is enabled, false otherwise @return string The YAML string representing the PHP array @throws DumpException When trying to dump PHP resource
[ "Dumps", "a", "given", "PHP", "variable", "to", "a", "YAML", "string", "." ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/yaml/Symfony/Component/Yaml/Inline.php#L92-L145
xiewulong/yii2-fileupload
oss/libs/symfony/yaml/Symfony/Component/Yaml/Inline.php
Inline.dumpArray
private static function dumpArray($value, $exceptionOnInvalidType, $objectSupport) { // array $keys = array_keys($value); if ((1 == count($keys) && '0' == $keys[0]) || (count($keys) > 1 && array_reduce($keys, function ($v, $w) { return (integer) $v + $w; }, 0) == count($keys) * (count($keys) - 1) / 2) ) { $output = array(); foreach ($value as $val) { $output[] = self::dump($val, $exceptionOnInvalidType, $objectSupport); } return sprintf('[%s]', implode(', ', $output)); } // mapping $output = array(); foreach ($value as $key => $val) { $output[] = sprintf('%s: %s', self::dump($key, $exceptionOnInvalidType, $objectSupport), self::dump($val, $exceptionOnInvalidType, $objectSupport)); } return sprintf('{ %s }', implode(', ', $output)); }
php
private static function dumpArray($value, $exceptionOnInvalidType, $objectSupport) { // array $keys = array_keys($value); if ((1 == count($keys) && '0' == $keys[0]) || (count($keys) > 1 && array_reduce($keys, function ($v, $w) { return (integer) $v + $w; }, 0) == count($keys) * (count($keys) - 1) / 2) ) { $output = array(); foreach ($value as $val) { $output[] = self::dump($val, $exceptionOnInvalidType, $objectSupport); } return sprintf('[%s]', implode(', ', $output)); } // mapping $output = array(); foreach ($value as $key => $val) { $output[] = sprintf('%s: %s', self::dump($key, $exceptionOnInvalidType, $objectSupport), self::dump($val, $exceptionOnInvalidType, $objectSupport)); } return sprintf('{ %s }', implode(', ', $output)); }
[ "private", "static", "function", "dumpArray", "(", "$", "value", ",", "$", "exceptionOnInvalidType", ",", "$", "objectSupport", ")", "{", "// array", "$", "keys", "=", "array_keys", "(", "$", "value", ")", ";", "if", "(", "(", "1", "==", "count", "(", "$", "keys", ")", "&&", "'0'", "==", "$", "keys", "[", "0", "]", ")", "||", "(", "count", "(", "$", "keys", ")", ">", "1", "&&", "array_reduce", "(", "$", "keys", ",", "function", "(", "$", "v", ",", "$", "w", ")", "{", "return", "(", "integer", ")", "$", "v", "+", "$", "w", ";", "}", ",", "0", ")", "==", "count", "(", "$", "keys", ")", "*", "(", "count", "(", "$", "keys", ")", "-", "1", ")", "/", "2", ")", ")", "{", "$", "output", "=", "array", "(", ")", ";", "foreach", "(", "$", "value", "as", "$", "val", ")", "{", "$", "output", "[", "]", "=", "self", "::", "dump", "(", "$", "val", ",", "$", "exceptionOnInvalidType", ",", "$", "objectSupport", ")", ";", "}", "return", "sprintf", "(", "'[%s]'", ",", "implode", "(", "', '", ",", "$", "output", ")", ")", ";", "}", "// mapping", "$", "output", "=", "array", "(", ")", ";", "foreach", "(", "$", "value", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "output", "[", "]", "=", "sprintf", "(", "'%s: %s'", ",", "self", "::", "dump", "(", "$", "key", ",", "$", "exceptionOnInvalidType", ",", "$", "objectSupport", ")", ",", "self", "::", "dump", "(", "$", "val", ",", "$", "exceptionOnInvalidType", ",", "$", "objectSupport", ")", ")", ";", "}", "return", "sprintf", "(", "'{ %s }'", ",", "implode", "(", "', '", ",", "$", "output", ")", ")", ";", "}" ]
Dumps a PHP array to a YAML string. @param array $value The PHP array to dump @param Boolean $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise @param Boolean $objectSupport true if object support is enabled, false otherwise @return string The YAML string representing the PHP array
[ "Dumps", "a", "PHP", "array", "to", "a", "YAML", "string", "." ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/yaml/Symfony/Component/Yaml/Inline.php#L156-L178
xiewulong/yii2-fileupload
oss/libs/symfony/yaml/Symfony/Component/Yaml/Inline.php
Inline.parseScalar
public static function parseScalar($scalar, $delimiters = null, $stringDelimiters = array('"', "'"), &$i = 0, $evaluate = true) { if (in_array($scalar[$i], $stringDelimiters)) { // quoted scalar $output = self::parseQuotedScalar($scalar, $i); if (null !== $delimiters) { $tmp = ltrim(substr($scalar, $i), ' '); if (!in_array($tmp[0], $delimiters)) { throw new ParseException(sprintf('Unexpected characters (%s).', substr($scalar, $i))); } } } else { // "normal" string if (!$delimiters) { $output = substr($scalar, $i); $i += strlen($output); // remove comments if (false !== $strpos = strpos($output, ' #')) { $output = rtrim(substr($output, 0, $strpos)); } } elseif (preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) { $output = $match[1]; $i += strlen($output); } else { throw new ParseException(sprintf('Malformed inline YAML string (%s).', $scalar)); } $output = $evaluate ? self::evaluateScalar($output) : $output; } return $output; }
php
public static function parseScalar($scalar, $delimiters = null, $stringDelimiters = array('"', "'"), &$i = 0, $evaluate = true) { if (in_array($scalar[$i], $stringDelimiters)) { // quoted scalar $output = self::parseQuotedScalar($scalar, $i); if (null !== $delimiters) { $tmp = ltrim(substr($scalar, $i), ' '); if (!in_array($tmp[0], $delimiters)) { throw new ParseException(sprintf('Unexpected characters (%s).', substr($scalar, $i))); } } } else { // "normal" string if (!$delimiters) { $output = substr($scalar, $i); $i += strlen($output); // remove comments if (false !== $strpos = strpos($output, ' #')) { $output = rtrim(substr($output, 0, $strpos)); } } elseif (preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) { $output = $match[1]; $i += strlen($output); } else { throw new ParseException(sprintf('Malformed inline YAML string (%s).', $scalar)); } $output = $evaluate ? self::evaluateScalar($output) : $output; } return $output; }
[ "public", "static", "function", "parseScalar", "(", "$", "scalar", ",", "$", "delimiters", "=", "null", ",", "$", "stringDelimiters", "=", "array", "(", "'\"'", ",", "\"'\"", ")", ",", "&", "$", "i", "=", "0", ",", "$", "evaluate", "=", "true", ")", "{", "if", "(", "in_array", "(", "$", "scalar", "[", "$", "i", "]", ",", "$", "stringDelimiters", ")", ")", "{", "// quoted scalar", "$", "output", "=", "self", "::", "parseQuotedScalar", "(", "$", "scalar", ",", "$", "i", ")", ";", "if", "(", "null", "!==", "$", "delimiters", ")", "{", "$", "tmp", "=", "ltrim", "(", "substr", "(", "$", "scalar", ",", "$", "i", ")", ",", "' '", ")", ";", "if", "(", "!", "in_array", "(", "$", "tmp", "[", "0", "]", ",", "$", "delimiters", ")", ")", "{", "throw", "new", "ParseException", "(", "sprintf", "(", "'Unexpected characters (%s).'", ",", "substr", "(", "$", "scalar", ",", "$", "i", ")", ")", ")", ";", "}", "}", "}", "else", "{", "// \"normal\" string", "if", "(", "!", "$", "delimiters", ")", "{", "$", "output", "=", "substr", "(", "$", "scalar", ",", "$", "i", ")", ";", "$", "i", "+=", "strlen", "(", "$", "output", ")", ";", "// remove comments", "if", "(", "false", "!==", "$", "strpos", "=", "strpos", "(", "$", "output", ",", "' #'", ")", ")", "{", "$", "output", "=", "rtrim", "(", "substr", "(", "$", "output", ",", "0", ",", "$", "strpos", ")", ")", ";", "}", "}", "elseif", "(", "preg_match", "(", "'/^(.+?)('", ".", "implode", "(", "'|'", ",", "$", "delimiters", ")", ".", "')/'", ",", "substr", "(", "$", "scalar", ",", "$", "i", ")", ",", "$", "match", ")", ")", "{", "$", "output", "=", "$", "match", "[", "1", "]", ";", "$", "i", "+=", "strlen", "(", "$", "output", ")", ";", "}", "else", "{", "throw", "new", "ParseException", "(", "sprintf", "(", "'Malformed inline YAML string (%s).'", ",", "$", "scalar", ")", ")", ";", "}", "$", "output", "=", "$", "evaluate", "?", "self", "::", "evaluateScalar", "(", "$", "output", ")", ":", "$", "output", ";", "}", "return", "$", "output", ";", "}" ]
Parses a scalar to a YAML string. @param scalar $scalar @param string $delimiters @param array $stringDelimiters @param integer &$i @param Boolean $evaluate @return string A YAML string @throws ParseException When malformed inline YAML string is parsed
[ "Parses", "a", "scalar", "to", "a", "YAML", "string", "." ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/yaml/Symfony/Component/Yaml/Inline.php#L193-L226
getuisdk/getui-php-sdk
src/IGeTui.php
IGeTui.pushMessageToSingle
public function pushMessageToSingle($message, $target, $requestId = null) { if ($requestId === null || trim($requestId) === '') { $requestId = uniqid('', true); } $params = $this->getSingleMessagePostData($message, $target, $requestId); return $this->httpPostJSON($this->host, $params); }
php
public function pushMessageToSingle($message, $target, $requestId = null) { if ($requestId === null || trim($requestId) === '') { $requestId = uniqid('', true); } $params = $this->getSingleMessagePostData($message, $target, $requestId); return $this->httpPostJSON($this->host, $params); }
[ "public", "function", "pushMessageToSingle", "(", "$", "message", ",", "$", "target", ",", "$", "requestId", "=", "null", ")", "{", "if", "(", "$", "requestId", "===", "null", "||", "trim", "(", "$", "requestId", ")", "===", "''", ")", "{", "$", "requestId", "=", "uniqid", "(", "''", ",", "true", ")", ";", "}", "$", "params", "=", "$", "this", "->", "getSingleMessagePostData", "(", "$", "message", ",", "$", "target", ",", "$", "requestId", ")", ";", "return", "$", "this", "->", "httpPostJSON", "(", "$", "this", "->", "host", ",", "$", "params", ")", ";", "}" ]
指定用户推送消息 @param IGtMessage $message @param IGtTarget $target @param string $requestId @return Array {result:successed_offline,taskId:xxx} || {result:successed_online,taskId:xxx} || {result:error} @throws RequestException @throws \InvalidArgumentException @throws \UnexpectedValueException *
[ "指定用户推送消息" ]
train
https://github.com/getuisdk/getui-php-sdk/blob/e91773b099bcbfd7492a44086b373d1c9fee37e2/src/IGeTui.php#L182-L189
getuisdk/getui-php-sdk
src/IGeTui.php
IGeTui.cancelContentId
public function cancelContentId($contentId) { $params = array(); $params['action'] = 'cancleContentIdAction'; $params['appkey'] = $this->appkey; $params['contentId'] = $contentId; $rep = $this->httpPostJSON($this->host, $params); return (string)$rep['result'] === 'ok'; }
php
public function cancelContentId($contentId) { $params = array(); $params['action'] = 'cancleContentIdAction'; $params['appkey'] = $this->appkey; $params['contentId'] = $contentId; $rep = $this->httpPostJSON($this->host, $params); return (string)$rep['result'] === 'ok'; }
[ "public", "function", "cancelContentId", "(", "$", "contentId", ")", "{", "$", "params", "=", "array", "(", ")", ";", "$", "params", "[", "'action'", "]", "=", "'cancleContentIdAction'", ";", "$", "params", "[", "'appkey'", "]", "=", "$", "this", "->", "appkey", ";", "$", "params", "[", "'contentId'", "]", "=", "$", "contentId", ";", "$", "rep", "=", "$", "this", "->", "httpPostJSON", "(", "$", "this", "->", "host", ",", "$", "params", ")", ";", "return", "(", "string", ")", "$", "rep", "[", "'result'", "]", "===", "'ok'", ";", "}" ]
取消消息 @param String $contentId contentId @return boolean @throws RequestException @throws \UnexpectedValueException @throws \InvalidArgumentException *
[ "取消消息" ]
train
https://github.com/getuisdk/getui-php-sdk/blob/e91773b099bcbfd7492a44086b373d1c9fee37e2/src/IGeTui.php#L244-L252
getuisdk/getui-php-sdk
src/IGeTui.php
IGeTui.pushMessageToList
public function pushMessageToList($contentId, $targetList) { $params = array(); $params['action'] = 'pushMessageToListAction'; $params['appkey'] = $this->appkey; $params['contentId'] = $contentId; $needDetails = GTConfig::isPushListNeedDetails(); $params['needDetails'] = $needDetails; $async = GTConfig::isPushListAsync(); $params['async'] = $async; if ($async && (!$needDetails)) { $limit = GTConfig::getAsyncListLimit(); } else { $limit = GTConfig::getSyncListLimit(); } if (count($targetList) > $limit) { throw new \InvalidArgumentException('target size:' . count($targetList) . ' beyond the limit:' . $limit); } $clientIdList = array(); $aliasList = array(); $appId = null; foreach ($targetList as $target) { $targetCid = $target->getClientId(); $targetAlias = $target->getAlias(); if ($targetCid !== null) { $clientIdList[] = $targetCid; } elseif ($targetAlias !== null) { $aliasList[] = $targetAlias; } if ($appId === null) { $appId = $target->getAppId(); } } $params['appId'] = $appId; $params['clientIdList'] = $clientIdList; $params['aliasList'] = $aliasList; $params['type'] = 2; return $this->httpPostJSON($this->host, $params, true); }
php
public function pushMessageToList($contentId, $targetList) { $params = array(); $params['action'] = 'pushMessageToListAction'; $params['appkey'] = $this->appkey; $params['contentId'] = $contentId; $needDetails = GTConfig::isPushListNeedDetails(); $params['needDetails'] = $needDetails; $async = GTConfig::isPushListAsync(); $params['async'] = $async; if ($async && (!$needDetails)) { $limit = GTConfig::getAsyncListLimit(); } else { $limit = GTConfig::getSyncListLimit(); } if (count($targetList) > $limit) { throw new \InvalidArgumentException('target size:' . count($targetList) . ' beyond the limit:' . $limit); } $clientIdList = array(); $aliasList = array(); $appId = null; foreach ($targetList as $target) { $targetCid = $target->getClientId(); $targetAlias = $target->getAlias(); if ($targetCid !== null) { $clientIdList[] = $targetCid; } elseif ($targetAlias !== null) { $aliasList[] = $targetAlias; } if ($appId === null) { $appId = $target->getAppId(); } } $params['appId'] = $appId; $params['clientIdList'] = $clientIdList; $params['aliasList'] = $aliasList; $params['type'] = 2; return $this->httpPostJSON($this->host, $params, true); }
[ "public", "function", "pushMessageToList", "(", "$", "contentId", ",", "$", "targetList", ")", "{", "$", "params", "=", "array", "(", ")", ";", "$", "params", "[", "'action'", "]", "=", "'pushMessageToListAction'", ";", "$", "params", "[", "'appkey'", "]", "=", "$", "this", "->", "appkey", ";", "$", "params", "[", "'contentId'", "]", "=", "$", "contentId", ";", "$", "needDetails", "=", "GTConfig", "::", "isPushListNeedDetails", "(", ")", ";", "$", "params", "[", "'needDetails'", "]", "=", "$", "needDetails", ";", "$", "async", "=", "GTConfig", "::", "isPushListAsync", "(", ")", ";", "$", "params", "[", "'async'", "]", "=", "$", "async", ";", "if", "(", "$", "async", "&&", "(", "!", "$", "needDetails", ")", ")", "{", "$", "limit", "=", "GTConfig", "::", "getAsyncListLimit", "(", ")", ";", "}", "else", "{", "$", "limit", "=", "GTConfig", "::", "getSyncListLimit", "(", ")", ";", "}", "if", "(", "count", "(", "$", "targetList", ")", ">", "$", "limit", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'target size:'", ".", "count", "(", "$", "targetList", ")", ".", "' beyond the limit:'", ".", "$", "limit", ")", ";", "}", "$", "clientIdList", "=", "array", "(", ")", ";", "$", "aliasList", "=", "array", "(", ")", ";", "$", "appId", "=", "null", ";", "foreach", "(", "$", "targetList", "as", "$", "target", ")", "{", "$", "targetCid", "=", "$", "target", "->", "getClientId", "(", ")", ";", "$", "targetAlias", "=", "$", "target", "->", "getAlias", "(", ")", ";", "if", "(", "$", "targetCid", "!==", "null", ")", "{", "$", "clientIdList", "[", "]", "=", "$", "targetCid", ";", "}", "elseif", "(", "$", "targetAlias", "!==", "null", ")", "{", "$", "aliasList", "[", "]", "=", "$", "targetAlias", ";", "}", "if", "(", "$", "appId", "===", "null", ")", "{", "$", "appId", "=", "$", "target", "->", "getAppId", "(", ")", ";", "}", "}", "$", "params", "[", "'appId'", "]", "=", "$", "appId", ";", "$", "params", "[", "'clientIdList'", "]", "=", "$", "clientIdList", ";", "$", "params", "[", "'aliasList'", "]", "=", "$", "aliasList", ";", "$", "params", "[", "'type'", "]", "=", "2", ";", "return", "$", "this", "->", "httpPostJSON", "(", "$", "this", "->", "host", ",", "$", "params", ",", "true", ")", ";", "}" ]
批量推送信息 @param String $contentId @param Array <IGtTarget> targetList @return Array {result:successed_offline,taskId:xxx} || {result:successed_online,taskId:xxx} || {result:error} @throws \Exception *
[ "批量推送信息" ]
train
https://github.com/getuisdk/getui-php-sdk/blob/e91773b099bcbfd7492a44086b373d1c9fee37e2/src/IGeTui.php#L261-L300
getuisdk/getui-php-sdk
src/IGeTui.php
IGeTui.pushAPNMessageToList
public function pushAPNMessageToList($appId, $contentId, $deviceTokenList) { $params = array(); $params['action'] = 'apnPushToListAction'; $params['appkey'] = $this->appkey; $params['appId'] = $appId; $params['contentId'] = $contentId; $params['DTL'] = $deviceTokenList; $needDetails = GTConfig::isPushListNeedDetails(); $params['needDetails'] = $needDetails; return $this->httpPostJSON($this->host, $params); }
php
public function pushAPNMessageToList($appId, $contentId, $deviceTokenList) { $params = array(); $params['action'] = 'apnPushToListAction'; $params['appkey'] = $this->appkey; $params['appId'] = $appId; $params['contentId'] = $contentId; $params['DTL'] = $deviceTokenList; $needDetails = GTConfig::isPushListNeedDetails(); $params['needDetails'] = $needDetails; return $this->httpPostJSON($this->host, $params); }
[ "public", "function", "pushAPNMessageToList", "(", "$", "appId", ",", "$", "contentId", ",", "$", "deviceTokenList", ")", "{", "$", "params", "=", "array", "(", ")", ";", "$", "params", "[", "'action'", "]", "=", "'apnPushToListAction'", ";", "$", "params", "[", "'appkey'", "]", "=", "$", "this", "->", "appkey", ";", "$", "params", "[", "'appId'", "]", "=", "$", "appId", ";", "$", "params", "[", "'contentId'", "]", "=", "$", "contentId", ";", "$", "params", "[", "'DTL'", "]", "=", "$", "deviceTokenList", ";", "$", "needDetails", "=", "GTConfig", "::", "isPushListNeedDetails", "(", ")", ";", "$", "params", "[", "'needDetails'", "]", "=", "$", "needDetails", ";", "return", "$", "this", "->", "httpPostJSON", "(", "$", "this", "->", "host", ",", "$", "params", ")", ";", "}" ]
根据deviceTokenList群推 @param $appId @param $contentId @param $deviceTokenList @return mixed @throws RequestException @throws \UnexpectedValueException @throws \InvalidArgumentException
[ "根据deviceTokenList群推" ]
train
https://github.com/getuisdk/getui-php-sdk/blob/e91773b099bcbfd7492a44086b373d1c9fee37e2/src/IGeTui.php#L465-L476
getuisdk/getui-php-sdk
src/IGeTui.php
IGeTui.getAPNContentId
public function getAPNContentId($appId, $message) { $params = array(); $params['action'] = 'apnGetContentIdAction'; $params['appkey'] = $this->appkey; $params['appId'] = $appId; $params['PI'] = base64_encode($message->getData()->getPushInfo()->serializeToString()); $rep = $this->httpPostJSON($this->host, $params); if ($rep['result'] === 'ok') { return $rep['contentId']; } else { throw new \UnexpectedValueException('host:[' . $this->host . '] 获取contentId失败:' . $rep); } }
php
public function getAPNContentId($appId, $message) { $params = array(); $params['action'] = 'apnGetContentIdAction'; $params['appkey'] = $this->appkey; $params['appId'] = $appId; $params['PI'] = base64_encode($message->getData()->getPushInfo()->serializeToString()); $rep = $this->httpPostJSON($this->host, $params); if ($rep['result'] === 'ok') { return $rep['contentId']; } else { throw new \UnexpectedValueException('host:[' . $this->host . '] 获取contentId失败:' . $rep); } }
[ "public", "function", "getAPNContentId", "(", "$", "appId", ",", "$", "message", ")", "{", "$", "params", "=", "array", "(", ")", ";", "$", "params", "[", "'action'", "]", "=", "'apnGetContentIdAction'", ";", "$", "params", "[", "'appkey'", "]", "=", "$", "this", "->", "appkey", ";", "$", "params", "[", "'appId'", "]", "=", "$", "appId", ";", "$", "params", "[", "'PI'", "]", "=", "base64_encode", "(", "$", "message", "->", "getData", "(", ")", "->", "getPushInfo", "(", ")", "->", "serializeToString", "(", ")", ")", ";", "$", "rep", "=", "$", "this", "->", "httpPostJSON", "(", "$", "this", "->", "host", ",", "$", "params", ")", ";", "if", "(", "$", "rep", "[", "'result'", "]", "===", "'ok'", ")", "{", "return", "$", "rep", "[", "'contentId'", "]", ";", "}", "else", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "'host:['", ".", "$", "this", "->", "host", ".", "'] 获取contentId失败:' . $rep)", "\r", "", "", "", "", "}", "}" ]
获取apn contentId @param $appId @param $message @return string @throws \Exception
[ "获取apn", "contentId" ]
train
https://github.com/getuisdk/getui-php-sdk/blob/e91773b099bcbfd7492a44086b373d1c9fee37e2/src/IGeTui.php#L485-L498
flowcode/AmulenUserBundle
src/Flowcode/UserBundle/Controller/SecurityController.php
SecurityController.forgotCheckAction
public function forgotCheckAction(Request $request) { $error = null; $last_email = null; $userService = $this->get("flowcode.user"); $user = $userService->loadUserByUsername($request->get("_username")); if ($user) { $userService->resetPasssword($user); } else { $error = array( "messageKey" => "security.login.unknown_user", "messageData" => array(), ); } return array( "error" => $error, "last_email" => $last_email, ); }
php
public function forgotCheckAction(Request $request) { $error = null; $last_email = null; $userService = $this->get("flowcode.user"); $user = $userService->loadUserByUsername($request->get("_username")); if ($user) { $userService->resetPasssword($user); } else { $error = array( "messageKey" => "security.login.unknown_user", "messageData" => array(), ); } return array( "error" => $error, "last_email" => $last_email, ); }
[ "public", "function", "forgotCheckAction", "(", "Request", "$", "request", ")", "{", "$", "error", "=", "null", ";", "$", "last_email", "=", "null", ";", "$", "userService", "=", "$", "this", "->", "get", "(", "\"flowcode.user\"", ")", ";", "$", "user", "=", "$", "userService", "->", "loadUserByUsername", "(", "$", "request", "->", "get", "(", "\"_username\"", ")", ")", ";", "if", "(", "$", "user", ")", "{", "$", "userService", "->", "resetPasssword", "(", "$", "user", ")", ";", "}", "else", "{", "$", "error", "=", "array", "(", "\"messageKey\"", "=>", "\"security.login.unknown_user\"", ",", "\"messageData\"", "=>", "array", "(", ")", ",", ")", ";", "}", "return", "array", "(", "\"error\"", "=>", "$", "error", ",", "\"last_email\"", "=>", "$", "last_email", ",", ")", ";", "}" ]
Forget check. @Route("/forgot_check", name="amulen_forgot_check") @Method("POST") @Template("FlowcodeUserBundle:Security:forgot.html.twig")
[ "Forget", "check", "." ]
train
https://github.com/flowcode/AmulenUserBundle/blob/00055834d9f094e63dcd8d66e2fedb822fcddee0/src/Flowcode/UserBundle/Controller/SecurityController.php#L90-L112
flowcode/AmulenUserBundle
src/Flowcode/UserBundle/Controller/SecurityController.php
SecurityController.registerAction
public function registerAction(Request $request) { $user = new User(); $form = $this->createRegisterForm($user); return array( 'form' => $form->createView(), ); }
php
public function registerAction(Request $request) { $user = new User(); $form = $this->createRegisterForm($user); return array( 'form' => $form->createView(), ); }
[ "public", "function", "registerAction", "(", "Request", "$", "request", ")", "{", "$", "user", "=", "new", "User", "(", ")", ";", "$", "form", "=", "$", "this", "->", "createRegisterForm", "(", "$", "user", ")", ";", "return", "array", "(", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", ")", ";", "}" ]
Register new user. @Route("/register", name="amulen_user_register") @Method("GET") @Template()
[ "Register", "new", "user", "." ]
train
https://github.com/flowcode/AmulenUserBundle/blob/00055834d9f094e63dcd8d66e2fedb822fcddee0/src/Flowcode/UserBundle/Controller/SecurityController.php#L121-L129
flowcode/AmulenUserBundle
src/Flowcode/UserBundle/Controller/SecurityController.php
SecurityController.createRegisterForm
private function createRegisterForm(User $user) { $form = $this->createForm(new UserRegisterType(), $user, array( 'action' => $this->generateUrl('amulen_user_register_do'), 'method' => 'POST', )); $form->add('submit', 'submit', array('label' => 'Register')); return $form; }
php
private function createRegisterForm(User $user) { $form = $this->createForm(new UserRegisterType(), $user, array( 'action' => $this->generateUrl('amulen_user_register_do'), 'method' => 'POST', )); $form->add('submit', 'submit', array('label' => 'Register')); return $form; }
[ "private", "function", "createRegisterForm", "(", "User", "$", "user", ")", "{", "$", "form", "=", "$", "this", "->", "createForm", "(", "new", "UserRegisterType", "(", ")", ",", "$", "user", ",", "array", "(", "'action'", "=>", "$", "this", "->", "generateUrl", "(", "'amulen_user_register_do'", ")", ",", "'method'", "=>", "'POST'", ",", ")", ")", ";", "$", "form", "->", "add", "(", "'submit'", ",", "'submit'", ",", "array", "(", "'label'", "=>", "'Register'", ")", ")", ";", "return", "$", "form", ";", "}" ]
Creates a form to edit a User entity. @param User $entity The entity @return \Symfony\Component\Form\Form The form
[ "Creates", "a", "form", "to", "edit", "a", "User", "entity", "." ]
train
https://github.com/flowcode/AmulenUserBundle/blob/00055834d9f094e63dcd8d66e2fedb822fcddee0/src/Flowcode/UserBundle/Controller/SecurityController.php#L138-L148
flowcode/AmulenUserBundle
src/Flowcode/UserBundle/Controller/SecurityController.php
SecurityController.doRegisterAction
public function doRegisterAction(Request $request) { $user = new User(); $form = $this->createRegisterForm($user); $form->handleRequest($request); if ($form->isValid()) { // FIXME: This have to be in the service. $user->setStatus(User::STATUS_ACTIVE); $userManager = $this->container->get('flowcode.user'); $userManager->create($user); // //FIXME: firewall name in security.yml // $firewall = 'public'; // $token = $userManager->getAuthToken($user, $user->getPlainPassword(), $firewall); // // Fire the login event // // Logging the user in above the way we do it doesn't do this automatically // $event = new InteractiveLoginEvent($request, $token); // $userManager->loginUser($event); return $this->redirect($this->generateUrl('homepage')); } return array( 'form' => $form->createView(), ); }
php
public function doRegisterAction(Request $request) { $user = new User(); $form = $this->createRegisterForm($user); $form->handleRequest($request); if ($form->isValid()) { // FIXME: This have to be in the service. $user->setStatus(User::STATUS_ACTIVE); $userManager = $this->container->get('flowcode.user'); $userManager->create($user); // //FIXME: firewall name in security.yml // $firewall = 'public'; // $token = $userManager->getAuthToken($user, $user->getPlainPassword(), $firewall); // // Fire the login event // // Logging the user in above the way we do it doesn't do this automatically // $event = new InteractiveLoginEvent($request, $token); // $userManager->loginUser($event); return $this->redirect($this->generateUrl('homepage')); } return array( 'form' => $form->createView(), ); }
[ "public", "function", "doRegisterAction", "(", "Request", "$", "request", ")", "{", "$", "user", "=", "new", "User", "(", ")", ";", "$", "form", "=", "$", "this", "->", "createRegisterForm", "(", "$", "user", ")", ";", "$", "form", "->", "handleRequest", "(", "$", "request", ")", ";", "if", "(", "$", "form", "->", "isValid", "(", ")", ")", "{", "// FIXME: This have to be in the service.", "$", "user", "->", "setStatus", "(", "User", "::", "STATUS_ACTIVE", ")", ";", "$", "userManager", "=", "$", "this", "->", "container", "->", "get", "(", "'flowcode.user'", ")", ";", "$", "userManager", "->", "create", "(", "$", "user", ")", ";", "// //FIXME: firewall name in security.yml", "// $firewall = 'public';", "// $token = $userManager->getAuthToken($user, $user->getPlainPassword(), $firewall);", "// // Fire the login event", "// // Logging the user in above the way we do it doesn't do this automatically", "// $event = new InteractiveLoginEvent($request, $token);", "// $userManager->loginUser($event);", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "generateUrl", "(", "'homepage'", ")", ")", ";", "}", "return", "array", "(", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", ")", ";", "}" ]
Edits an existing User entity. @Route("/register", name="amulen_user_register_do") @Method("POST") @Template("FlowcodeUserBundle:Security:register.html.twig")
[ "Edits", "an", "existing", "User", "entity", "." ]
train
https://github.com/flowcode/AmulenUserBundle/blob/00055834d9f094e63dcd8d66e2fedb822fcddee0/src/Flowcode/UserBundle/Controller/SecurityController.php#L157-L186
Laralum/Events
src/Policies/EventPolicy.php
EventPolicy.view
public function view($user, Event $event) { if ($event->creator->id == $user->id) { return true; } return User::findOrFail($user->id)->hasPermission('laralum::events.view'); }
php
public function view($user, Event $event) { if ($event->creator->id == $user->id) { return true; } return User::findOrFail($user->id)->hasPermission('laralum::events.view'); }
[ "public", "function", "view", "(", "$", "user", ",", "Event", "$", "event", ")", "{", "if", "(", "$", "event", "->", "creator", "->", "id", "==", "$", "user", "->", "id", ")", "{", "return", "true", ";", "}", "return", "User", "::", "findOrFail", "(", "$", "user", "->", "id", ")", "->", "hasPermission", "(", "'laralum::events.view'", ")", ";", "}" ]
Determine if the current user can view events. @param mixed $user @return bool
[ "Determine", "if", "the", "current", "user", "can", "view", "events", "." ]
train
https://github.com/Laralum/Events/blob/9dc36468f4253e7d040863a115ea94cded0e6aa5/src/Policies/EventPolicy.php#L57-L64
Laralum/Events
src/Policies/EventPolicy.php
EventPolicy.publicDelete
public function publicDelete($user, Event $event) { if ($event->creator->id == $user->id) { return User::findOrFail($user->id)->hasPermission('laralum::events.delete-public'); } return false; }
php
public function publicDelete($user, Event $event) { if ($event->creator->id == $user->id) { return User::findOrFail($user->id)->hasPermission('laralum::events.delete-public'); } return false; }
[ "public", "function", "publicDelete", "(", "$", "user", ",", "Event", "$", "event", ")", "{", "if", "(", "$", "event", "->", "creator", "->", "id", "==", "$", "user", "->", "id", ")", "{", "return", "User", "::", "findOrFail", "(", "$", "user", "->", "id", ")", "->", "hasPermission", "(", "'laralum::events.delete-public'", ")", ";", "}", "return", "false", ";", "}" ]
Determine if the current user can delete events on public views. @param mixed $user @return bool
[ "Determine", "if", "the", "current", "user", "can", "delete", "events", "on", "public", "views", "." ]
train
https://github.com/Laralum/Events/blob/9dc36468f4253e7d040863a115ea94cded0e6aa5/src/Policies/EventPolicy.php#L185-L192
42mate/towel
src/Towel/Controller/BaseController.php
BaseController.routeError
public function routeError(\Exception $e) { if ($e instanceof NotFoundHttpException) { $responseContent = $this->twig()->render('Default\404.twig'); $response = new Response($responseContent, 404); } else { $responseContent = $this->twig()->render('Default\500.twig', array('error' => $e->getMessage())); $response = new Response($responseContent, 500); } return $response; }
php
public function routeError(\Exception $e) { if ($e instanceof NotFoundHttpException) { $responseContent = $this->twig()->render('Default\404.twig'); $response = new Response($responseContent, 404); } else { $responseContent = $this->twig()->render('Default\500.twig', array('error' => $e->getMessage())); $response = new Response($responseContent, 500); } return $response; }
[ "public", "function", "routeError", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "$", "e", "instanceof", "NotFoundHttpException", ")", "{", "$", "responseContent", "=", "$", "this", "->", "twig", "(", ")", "->", "render", "(", "'Default\\404.twig'", ")", ";", "$", "response", "=", "new", "Response", "(", "$", "responseContent", ",", "404", ")", ";", "}", "else", "{", "$", "responseContent", "=", "$", "this", "->", "twig", "(", ")", "->", "render", "(", "'Default\\500.twig'", ",", "array", "(", "'error'", "=>", "$", "e", "->", "getMessage", "(", ")", ")", ")", ";", "$", "response", "=", "new", "Response", "(", "$", "responseContent", ",", "500", ")", ";", "}", "return", "$", "response", ";", "}" ]
404 and 500 error page for non debug mode @param \Exception $e @return Response
[ "404", "and", "500", "error", "page", "for", "non", "debug", "mode" ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Controller/BaseController.php#L34-L45
42mate/towel
src/Towel/Controller/BaseController.php
BaseController.setMessage
public function setMessage($type, $content) { $message = new \stdClass; $message->mt = $type; $message->content = $content; $messages = $this->session()->get('messages', array()); $messages[] = $message; $this->session()->set('messages', $messages); }
php
public function setMessage($type, $content) { $message = new \stdClass; $message->mt = $type; $message->content = $content; $messages = $this->session()->get('messages', array()); $messages[] = $message; $this->session()->set('messages', $messages); }
[ "public", "function", "setMessage", "(", "$", "type", ",", "$", "content", ")", "{", "$", "message", "=", "new", "\\", "stdClass", ";", "$", "message", "->", "mt", "=", "$", "type", ";", "$", "message", "->", "content", "=", "$", "content", ";", "$", "messages", "=", "$", "this", "->", "session", "(", ")", "->", "get", "(", "'messages'", ",", "array", "(", ")", ")", ";", "$", "messages", "[", "]", "=", "$", "message", ";", "$", "this", "->", "session", "(", ")", "->", "set", "(", "'messages'", ",", "$", "messages", ")", ";", "}" ]
Sets a user message to present after reload or redirect. @param $type @param $content
[ "Sets", "a", "user", "message", "to", "present", "after", "reload", "or", "redirect", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Controller/BaseController.php#L83-L91
42mate/towel
src/Towel/Controller/BaseController.php
BaseController.hasErrorMessages
public function hasErrorMessages() { $messages = $this->getMessages(); foreach ($messages as $message) { if ($message->mt == 'error') { return true; } } return false; }
php
public function hasErrorMessages() { $messages = $this->getMessages(); foreach ($messages as $message) { if ($message->mt == 'error') { return true; } } return false; }
[ "public", "function", "hasErrorMessages", "(", ")", "{", "$", "messages", "=", "$", "this", "->", "getMessages", "(", ")", ";", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "if", "(", "$", "message", "->", "mt", "==", "'error'", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks into the message bag if there is some error message. Type == error
[ "Checks", "into", "the", "message", "bag", "if", "there", "is", "some", "error", "message", ".", "Type", "==", "error" ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Controller/BaseController.php#L97-L105
42mate/towel
src/Towel/Controller/BaseController.php
BaseController.attachFiles
public function attachFiles($id, $table, $files) { foreach ($files as $file) { if (!empty($file)) { $this->attachFile($id, $table, $file); } } }
php
public function attachFiles($id, $table, $files) { foreach ($files as $file) { if (!empty($file)) { $this->attachFile($id, $table, $file); } } }
[ "public", "function", "attachFiles", "(", "$", "id", ",", "$", "table", ",", "$", "files", ")", "{", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "if", "(", "!", "empty", "(", "$", "file", ")", ")", "{", "$", "this", "->", "attachFile", "(", "$", "id", ",", "$", "table", ",", "$", "file", ")", ";", "}", "}", "}" ]
It will attach the array of files to the entity. @param $id @param $table @param $files
[ "It", "will", "attach", "the", "array", "of", "files", "to", "the", "entity", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Controller/BaseController.php#L124-L131
42mate/towel
src/Towel/Controller/BaseController.php
BaseController.attachFile
public function attachFile($id, $table, \Symfony\Component\HttpFoundation\File\UploadedFile $file) { $newFileName = md5(microtime() . '.' . strtolower($file->getClientOriginalExtension())); $relativePath = $table . '/' . date('Y/m/d'); $relativeFilePath = $relativePath . '/' . $newFileName; $dstPath = APP_UPLOADS_DIR . '/' . $relativePath; $file->move($dstPath, $newFileName); $pic = new \Towel\Model\Pic(); $pic->object_id = $id; $pic->object_type = $table; $pic->pic = $relativeFilePath; $pic->created = time(); $pic->save(); }
php
public function attachFile($id, $table, \Symfony\Component\HttpFoundation\File\UploadedFile $file) { $newFileName = md5(microtime() . '.' . strtolower($file->getClientOriginalExtension())); $relativePath = $table . '/' . date('Y/m/d'); $relativeFilePath = $relativePath . '/' . $newFileName; $dstPath = APP_UPLOADS_DIR . '/' . $relativePath; $file->move($dstPath, $newFileName); $pic = new \Towel\Model\Pic(); $pic->object_id = $id; $pic->object_type = $table; $pic->pic = $relativeFilePath; $pic->created = time(); $pic->save(); }
[ "public", "function", "attachFile", "(", "$", "id", ",", "$", "table", ",", "\\", "Symfony", "\\", "Component", "\\", "HttpFoundation", "\\", "File", "\\", "UploadedFile", "$", "file", ")", "{", "$", "newFileName", "=", "md5", "(", "microtime", "(", ")", ".", "'.'", ".", "strtolower", "(", "$", "file", "->", "getClientOriginalExtension", "(", ")", ")", ")", ";", "$", "relativePath", "=", "$", "table", ".", "'/'", ".", "date", "(", "'Y/m/d'", ")", ";", "$", "relativeFilePath", "=", "$", "relativePath", ".", "'/'", ".", "$", "newFileName", ";", "$", "dstPath", "=", "APP_UPLOADS_DIR", ".", "'/'", ".", "$", "relativePath", ";", "$", "file", "->", "move", "(", "$", "dstPath", ",", "$", "newFileName", ")", ";", "$", "pic", "=", "new", "\\", "Towel", "\\", "Model", "\\", "Pic", "(", ")", ";", "$", "pic", "->", "object_id", "=", "$", "id", ";", "$", "pic", "->", "object_type", "=", "$", "table", ";", "$", "pic", "->", "pic", "=", "$", "relativeFilePath", ";", "$", "pic", "->", "created", "=", "time", "(", ")", ";", "$", "pic", "->", "save", "(", ")", ";", "}" ]
It will attach the file. @param $id @param $table @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
[ "It", "will", "attach", "the", "file", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Controller/BaseController.php#L140-L154
nullcall/geo-api
src/MapAPI.php
GoogleAPI.setDirectionCo
public function setDirectionCo($gpsArray){ $this->directionLat1 = $gpsArray[0]['lat']; $this->directionLat2 = $gpsArray[1]['lat']; $this->directionLong1 = $gpsArray[0]['long']; $this->directionLong2 = $gpsArray[1]['long']; }
php
public function setDirectionCo($gpsArray){ $this->directionLat1 = $gpsArray[0]['lat']; $this->directionLat2 = $gpsArray[1]['lat']; $this->directionLong1 = $gpsArray[0]['long']; $this->directionLong2 = $gpsArray[1]['long']; }
[ "public", "function", "setDirectionCo", "(", "$", "gpsArray", ")", "{", "$", "this", "->", "directionLat1", "=", "$", "gpsArray", "[", "0", "]", "[", "'lat'", "]", ";", "$", "this", "->", "directionLat2", "=", "$", "gpsArray", "[", "1", "]", "[", "'lat'", "]", ";", "$", "this", "->", "directionLong1", "=", "$", "gpsArray", "[", "0", "]", "[", "'long'", "]", ";", "$", "this", "->", "directionLong2", "=", "$", "gpsArray", "[", "1", "]", "[", "'long'", "]", ";", "}" ]
/ Set the coordinates from direction ///
[ "/", "Set", "the", "coordinates", "from", "direction", "///" ]
train
https://github.com/nullcall/geo-api/blob/c8b5c12f2aa32d6965d941509f9572c95995f45c/src/MapAPI.php#L33-L38
nullcall/geo-api
src/MapAPI.php
GoogleAPI.getDirection
public function getDirection() { //difference in longitudinal coordinates $dLon = deg2rad($this->directionLong2) - deg2rad($this->directionLong1); //difference in the phi of latitudinal coordinates $dPhi = log(tan(deg2rad($this->directionLat2) / 2 + pi() / 4) / tan(deg2rad($this->directionLat1) / 2 + pi() / 4)); //we need to recalculate $dLon if it is greater than pi if(abs($dLon) > pi()) { if($dLon > 0) { $dLon = (2 * pi() - $dLon) * -1; } else { $dLon = 2 * pi() + $dLon; } } //return the angle, normalized $this->bearingAngle = (rad2deg(atan2($dLon, $dPhi)) + 360) % 360; return $this->getCompassDirection(); }
php
public function getDirection() { //difference in longitudinal coordinates $dLon = deg2rad($this->directionLong2) - deg2rad($this->directionLong1); //difference in the phi of latitudinal coordinates $dPhi = log(tan(deg2rad($this->directionLat2) / 2 + pi() / 4) / tan(deg2rad($this->directionLat1) / 2 + pi() / 4)); //we need to recalculate $dLon if it is greater than pi if(abs($dLon) > pi()) { if($dLon > 0) { $dLon = (2 * pi() - $dLon) * -1; } else { $dLon = 2 * pi() + $dLon; } } //return the angle, normalized $this->bearingAngle = (rad2deg(atan2($dLon, $dPhi)) + 360) % 360; return $this->getCompassDirection(); }
[ "public", "function", "getDirection", "(", ")", "{", "//difference in longitudinal coordinates", "$", "dLon", "=", "deg2rad", "(", "$", "this", "->", "directionLong2", ")", "-", "deg2rad", "(", "$", "this", "->", "directionLong1", ")", ";", "//difference in the phi of latitudinal coordinates", "$", "dPhi", "=", "log", "(", "tan", "(", "deg2rad", "(", "$", "this", "->", "directionLat2", ")", "/", "2", "+", "pi", "(", ")", "/", "4", ")", "/", "tan", "(", "deg2rad", "(", "$", "this", "->", "directionLat1", ")", "/", "2", "+", "pi", "(", ")", "/", "4", ")", ")", ";", "//we need to recalculate $dLon if it is greater than pi", "if", "(", "abs", "(", "$", "dLon", ")", ">", "pi", "(", ")", ")", "{", "if", "(", "$", "dLon", ">", "0", ")", "{", "$", "dLon", "=", "(", "2", "*", "pi", "(", ")", "-", "$", "dLon", ")", "*", "-", "1", ";", "}", "else", "{", "$", "dLon", "=", "2", "*", "pi", "(", ")", "+", "$", "dLon", ";", "}", "}", "//return the angle, normalized", "$", "this", "->", "bearingAngle", "=", "(", "rad2deg", "(", "atan2", "(", "$", "dLon", ",", "$", "dPhi", ")", ")", "+", "360", ")", "%", "360", ";", "return", "$", "this", "->", "getCompassDirection", "(", ")", ";", "}" ]
// Fetch Direction from given lat long ///////////
[ "//", "Fetch", "Direction", "from", "given", "lat", "long", "///////////" ]
train
https://github.com/nullcall/geo-api/blob/c8b5c12f2aa32d6965d941509f9572c95995f45c/src/MapAPI.php#L41-L58
nullcall/geo-api
src/MapAPI.php
GoogleAPI.calDistance
public function calDistance(){ $num = 0; foreach ($this->coordinatesArray as $key => $row) { $this->distLat[] = $row['lat']; $this->distLong[] =$row['long']; } //// Get the Leangth of passed array ////// $num = sizeof($this->coordinatesArray) - 1; // Fixed the Undefined offset error : offset = sizeofArray - 1 for($i=0;$i<$num;$i++){ if($this->distLat[$i+1] != '' and $this->distLong[$i+1] != '') { $distance[]=$this->distance($this->distLat[$i],$this->distLong[$i],$this->distLat[$i+1],$this->distLong[$i+1],$this->unit); } } return round(array_sum($distance)); }
php
public function calDistance(){ $num = 0; foreach ($this->coordinatesArray as $key => $row) { $this->distLat[] = $row['lat']; $this->distLong[] =$row['long']; } //// Get the Leangth of passed array ////// $num = sizeof($this->coordinatesArray) - 1; // Fixed the Undefined offset error : offset = sizeofArray - 1 for($i=0;$i<$num;$i++){ if($this->distLat[$i+1] != '' and $this->distLong[$i+1] != '') { $distance[]=$this->distance($this->distLat[$i],$this->distLong[$i],$this->distLat[$i+1],$this->distLong[$i+1],$this->unit); } } return round(array_sum($distance)); }
[ "public", "function", "calDistance", "(", ")", "{", "$", "num", "=", "0", ";", "foreach", "(", "$", "this", "->", "coordinatesArray", "as", "$", "key", "=>", "$", "row", ")", "{", "$", "this", "->", "distLat", "[", "]", "=", "$", "row", "[", "'lat'", "]", ";", "$", "this", "->", "distLong", "[", "]", "=", "$", "row", "[", "'long'", "]", ";", "}", "//// Get the Leangth of passed array //////", "$", "num", "=", "sizeof", "(", "$", "this", "->", "coordinatesArray", ")", "-", "1", ";", "// Fixed the Undefined offset error : offset = sizeofArray - 1", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "num", ";", "$", "i", "++", ")", "{", "if", "(", "$", "this", "->", "distLat", "[", "$", "i", "+", "1", "]", "!=", "''", "and", "$", "this", "->", "distLong", "[", "$", "i", "+", "1", "]", "!=", "''", ")", "{", "$", "distance", "[", "]", "=", "$", "this", "->", "distance", "(", "$", "this", "->", "distLat", "[", "$", "i", "]", ",", "$", "this", "->", "distLong", "[", "$", "i", "]", ",", "$", "this", "->", "distLat", "[", "$", "i", "+", "1", "]", ",", "$", "this", "->", "distLong", "[", "$", "i", "+", "1", "]", ",", "$", "this", "->", "unit", ")", ";", "}", "}", "return", "round", "(", "array_sum", "(", "$", "distance", ")", ")", ";", "}" ]
return the (int) distance
[ "return", "the", "(", "int", ")", "distance" ]
train
https://github.com/nullcall/geo-api/blob/c8b5c12f2aa32d6965d941509f9572c95995f45c/src/MapAPI.php#L114-L128
nullcall/geo-api
src/MapAPI.php
GoogleAPI.addFetch
public function addFetch(){ $url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=$this->latitude,$this->longitude&sensor=false"; $curlData=file_get_contents($url); $address = json_decode($curlData); $a=$address->results[0]; return explode(",",$a->formatted_address); }
php
public function addFetch(){ $url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=$this->latitude,$this->longitude&sensor=false"; $curlData=file_get_contents($url); $address = json_decode($curlData); $a=$address->results[0]; return explode(",",$a->formatted_address); }
[ "public", "function", "addFetch", "(", ")", "{", "$", "url", "=", "\"http://maps.googleapis.com/maps/api/geocode/json?latlng=$this->latitude,$this->longitude&sensor=false\"", ";", "$", "curlData", "=", "file_get_contents", "(", "$", "url", ")", ";", "$", "address", "=", "json_decode", "(", "$", "curlData", ")", ";", "$", "a", "=", "$", "address", "->", "results", "[", "0", "]", ";", "return", "explode", "(", "\",\"", ",", "$", "a", "->", "formatted_address", ")", ";", "}" ]
// Fetch Address from given coordinates //////////
[ "//", "Fetch", "Address", "from", "given", "coordinates", "//////////" ]
train
https://github.com/nullcall/geo-api/blob/c8b5c12f2aa32d6965d941509f9572c95995f45c/src/MapAPI.php#L146-L152
dappur/dappurware
app/src/Dappurware/Cookies.php
Cookies.setResponseCookie
public function setResponseCookie($response, $name, $value = null, $expiration = 0) { $expiration = 1; if ($expiration == 0) { $expiration = 30; } if (is_numeric($expiration)) { $expiration = $expiration; } $response = FigResponseCookies::set( $response, SetCookie::create($name) ->withExpires(Carbon::parse()->timestamp + 60*60*24*$expiration) ->withValue($value) ); return $response; }
php
public function setResponseCookie($response, $name, $value = null, $expiration = 0) { $expiration = 1; if ($expiration == 0) { $expiration = 30; } if (is_numeric($expiration)) { $expiration = $expiration; } $response = FigResponseCookies::set( $response, SetCookie::create($name) ->withExpires(Carbon::parse()->timestamp + 60*60*24*$expiration) ->withValue($value) ); return $response; }
[ "public", "function", "setResponseCookie", "(", "$", "response", ",", "$", "name", ",", "$", "value", "=", "null", ",", "$", "expiration", "=", "0", ")", "{", "$", "expiration", "=", "1", ";", "if", "(", "$", "expiration", "==", "0", ")", "{", "$", "expiration", "=", "30", ";", "}", "if", "(", "is_numeric", "(", "$", "expiration", ")", ")", "{", "$", "expiration", "=", "$", "expiration", ";", "}", "$", "response", "=", "FigResponseCookies", "::", "set", "(", "$", "response", ",", "SetCookie", "::", "create", "(", "$", "name", ")", "->", "withExpires", "(", "Carbon", "::", "parse", "(", ")", "->", "timestamp", "+", "60", "*", "60", "*", "24", "*", "$", "expiration", ")", "->", "withValue", "(", "$", "value", ")", ")", ";", "return", "$", "response", ";", "}" ]
Set New Response Cookie
[ "Set", "New", "Response", "Cookie" ]
train
https://github.com/dappur/dappurware/blob/453ca999047693a1f009618820f8497a287f6a05/app/src/Dappurware/Cookies.php#L22-L40
dappur/dappurware
app/src/Dappurware/Cookies.php
Cookies.modifyResponseCookie
public function modifyResponseCookie($response, $name, $value = null, $expiration = 0) { $expiration = 1; if ($expiration == 0) { $expiration = 30; //Expire After 30 Days } if (is_numeric($expiration)) { $expiration = $expiration; } $modify = function (SetCookie $setCookie) { $value = $setCookie->getValue(); // ... inspect current $value and determine if $value should // change or if it can stay the same. in all cases, a cookie // should be returned from this callback... return $setCookie ->withValue($value) ->withExpires($expiration) ; }; $response = FigResponseCookies::modify($response, $name, $modify); return $response; }
php
public function modifyResponseCookie($response, $name, $value = null, $expiration = 0) { $expiration = 1; if ($expiration == 0) { $expiration = 30; //Expire After 30 Days } if (is_numeric($expiration)) { $expiration = $expiration; } $modify = function (SetCookie $setCookie) { $value = $setCookie->getValue(); // ... inspect current $value and determine if $value should // change or if it can stay the same. in all cases, a cookie // should be returned from this callback... return $setCookie ->withValue($value) ->withExpires($expiration) ; }; $response = FigResponseCookies::modify($response, $name, $modify); return $response; }
[ "public", "function", "modifyResponseCookie", "(", "$", "response", ",", "$", "name", ",", "$", "value", "=", "null", ",", "$", "expiration", "=", "0", ")", "{", "$", "expiration", "=", "1", ";", "if", "(", "$", "expiration", "==", "0", ")", "{", "$", "expiration", "=", "30", ";", "//Expire After 30 Days", "}", "if", "(", "is_numeric", "(", "$", "expiration", ")", ")", "{", "$", "expiration", "=", "$", "expiration", ";", "}", "$", "modify", "=", "function", "(", "SetCookie", "$", "setCookie", ")", "{", "$", "value", "=", "$", "setCookie", "->", "getValue", "(", ")", ";", "// ... inspect current $value and determine if $value should", "// change or if it can stay the same. in all cases, a cookie", "// should be returned from this callback...", "return", "$", "setCookie", "->", "withValue", "(", "$", "value", ")", "->", "withExpires", "(", "$", "expiration", ")", ";", "}", ";", "$", "response", "=", "FigResponseCookies", "::", "modify", "(", "$", "response", ",", "$", "name", ",", "$", "modify", ")", ";", "return", "$", "response", ";", "}" ]
Modify Response Cookie
[ "Modify", "Response", "Cookie" ]
train
https://github.com/dappur/dappurware/blob/453ca999047693a1f009618820f8497a287f6a05/app/src/Dappurware/Cookies.php#L43-L69
dappur/dappurware
app/src/Dappurware/Cookies.php
Cookies.setRequestCookie
public function setRequestCookie($request, $name, $value = null) { if (empty($name)) { return false; } $request = FigRequestCookies::set($request, Cookie::create($name, $value)); return $request; }
php
public function setRequestCookie($request, $name, $value = null) { if (empty($name)) { return false; } $request = FigRequestCookies::set($request, Cookie::create($name, $value)); return $request; }
[ "public", "function", "setRequestCookie", "(", "$", "request", ",", "$", "name", ",", "$", "value", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "return", "false", ";", "}", "$", "request", "=", "FigRequestCookies", "::", "set", "(", "$", "request", ",", "Cookie", "::", "create", "(", "$", "name", ",", "$", "value", ")", ")", ";", "return", "$", "request", ";", "}" ]
Set New Request Cookie
[ "Set", "New", "Request", "Cookie" ]
train
https://github.com/dappur/dappurware/blob/453ca999047693a1f009618820f8497a287f6a05/app/src/Dappurware/Cookies.php#L86-L95