repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
beyoio/beyod
Parser.php
Parser.input
public function input($buffer, $connection) { $len = strlen($buffer); if ($this->max_packet_size >0 && $len >= $this->max_packet_size) { throw new \Exception($connection.' request packet size exceed max_packet_size ', Server::ERROR_LARGE_PACKET); } return $len; }
php
public function input($buffer, $connection) { $len = strlen($buffer); if ($this->max_packet_size >0 && $len >= $this->max_packet_size) { throw new \Exception($connection.' request packet size exceed max_packet_size ', Server::ERROR_LARGE_PACKET); } return $len; }
[ "public", "function", "input", "(", "$", "buffer", ",", "$", "connection", ")", "{", "$", "len", "=", "strlen", "(", "$", "buffer", ")", ";", "if", "(", "$", "this", "->", "max_packet_size", ">", "0", "&&", "$", "len", ">=", "$", "this", "->", "max_packet_size", ")", "{", "throw", "new", "\\", "Exception", "(", "$", "connection", ".", "' request packet size exceed max_packet_size '", ",", "Server", "::", "ERROR_LARGE_PACKET", ")", ";", "}", "return", "$", "len", ";", "}" ]
Determines whether the current connection has received the complete packet, zero value indicates that a complete packet is not received yet, positive value indicates that a complete packet has been received and represents the number of bytes of the packet, negative value indicates that the data is invalid or unrecognized @param string $buffer @param Connection|StreamClient $connection, for udp packet it is null @return int
[ "Determines", "whether", "the", "current", "connection", "has", "received", "the", "complete", "packet", "zero", "value", "indicates", "that", "a", "complete", "packet", "is", "not", "received", "yet", "positive", "value", "indicates", "that", "a", "complete", "packet", "has", "been", "received", "and", "represents", "the", "number", "of", "bytes", "of", "the", "packet", "negative", "value", "indicates", "that", "the", "data", "is", "invalid", "or", "unrecognized" ]
11941db9c4ae4abbca6c8e634d21873c690efc79
https://github.com/beyoio/beyod/blob/11941db9c4ae4abbca6c8e634d21873c690efc79/Parser.php#L51-L60
train
kiwi-26/line-bot-test-helper
src/WebhookEvent.php
WebhookEvent.body
public function body() { $event = []; if (!empty($this->replyToken)) { $event['replyToken'] = $this->replyToken; } $event['type'] = $this->eventType(); $event['timestamp'] = time(); $event['source'] = $this->source; $event['message'] = $this->message; $result = ['events' => [$event]]; return json_encode($result); }
php
public function body() { $event = []; if (!empty($this->replyToken)) { $event['replyToken'] = $this->replyToken; } $event['type'] = $this->eventType(); $event['timestamp'] = time(); $event['source'] = $this->source; $event['message'] = $this->message; $result = ['events' => [$event]]; return json_encode($result); }
[ "public", "function", "body", "(", ")", "{", "$", "event", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "replyToken", ")", ")", "{", "$", "event", "[", "'replyToken'", "]", "=", "$", "this", "->", "replyToken", ";", "}", "$", "event", "[", "'type'", "]", "=", "$", "this", "->", "eventType", "(", ")", ";", "$", "event", "[", "'timestamp'", "]", "=", "time", "(", ")", ";", "$", "event", "[", "'source'", "]", "=", "$", "this", "->", "source", ";", "$", "event", "[", "'message'", "]", "=", "$", "this", "->", "message", ";", "$", "result", "=", "[", "'events'", "=>", "[", "$", "event", "]", "]", ";", "return", "json_encode", "(", "$", "result", ")", ";", "}" ]
Build webhook event and return body. Original webhook request body has this signature. @return String json encoded body.
[ "Build", "webhook", "event", "and", "return", "body", ".", "Original", "webhook", "request", "body", "has", "this", "signature", "." ]
e1d6fb611e73016a5242c4b28238686926f262ba
https://github.com/kiwi-26/line-bot-test-helper/blob/e1d6fb611e73016a5242c4b28238686926f262ba/src/WebhookEvent.php#L40-L51
train
luoxiaojun1992/lb_framework
components/traits/lb/Config.php
Config.getCustomConfig
public function getCustomConfig($name = '') { $custom_config = $this->getConfigByName('custom'); return $name ? ($custom_config[$name] ?? null) : $custom_config; }
php
public function getCustomConfig($name = '') { $custom_config = $this->getConfigByName('custom'); return $name ? ($custom_config[$name] ?? null) : $custom_config; }
[ "public", "function", "getCustomConfig", "(", "$", "name", "=", "''", ")", "{", "$", "custom_config", "=", "$", "this", "->", "getConfigByName", "(", "'custom'", ")", ";", "return", "$", "name", "?", "(", "$", "custom_config", "[", "$", "name", "]", "??", "null", ")", ":", "$", "custom_config", ";", "}" ]
Get Custom Configuration @param string $name @return array|null
[ "Get", "Custom", "Configuration" ]
12a865729e7738d7d1e07371ad7203243c4571fa
https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/traits/lb/Config.php#L100-L104
train
luoxiaojun1992/lb_framework
components/traits/lb/Config.php
Config.getConfigByName
public function getConfigByName($config_name) { if ($this->isSingle()) { if (isset($this->containers['config'])) { return $this->containers['config']->get($config_name); } } return []; }
php
public function getConfigByName($config_name) { if ($this->isSingle()) { if (isset($this->containers['config'])) { return $this->containers['config']->get($config_name); } } return []; }
[ "public", "function", "getConfigByName", "(", "$", "config_name", ")", "{", "if", "(", "$", "this", "->", "isSingle", "(", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "containers", "[", "'config'", "]", ")", ")", "{", "return", "$", "this", "->", "containers", "[", "'config'", "]", "->", "get", "(", "$", "config_name", ")", ";", "}", "}", "return", "[", "]", ";", "}" ]
Get Configuration By Name @param $config_name @return array
[ "Get", "Configuration", "By", "Name" ]
12a865729e7738d7d1e07371ad7203243c4571fa
https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/traits/lb/Config.php#L215-L223
train
luoxiaojun1992/lb_framework
components/traits/lb/Config.php
Config.getUrlManagerConfig
public function getUrlManagerConfig($item) { $urlManager = $this->getConfigByName('urlManager'); if (isset($urlManager[$item])) { return $urlManager[$item]; } return false; }
php
public function getUrlManagerConfig($item) { $urlManager = $this->getConfigByName('urlManager'); if (isset($urlManager[$item])) { return $urlManager[$item]; } return false; }
[ "public", "function", "getUrlManagerConfig", "(", "$", "item", ")", "{", "$", "urlManager", "=", "$", "this", "->", "getConfigByName", "(", "'urlManager'", ")", ";", "if", "(", "isset", "(", "$", "urlManager", "[", "$", "item", "]", ")", ")", "{", "return", "$", "urlManager", "[", "$", "item", "]", ";", "}", "return", "false", ";", "}" ]
Get Url Manager Config By Item Name @param $item @return bool
[ "Get", "Url", "Manager", "Config", "By", "Item", "Name" ]
12a865729e7738d7d1e07371ad7203243c4571fa
https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/traits/lb/Config.php#L231-L238
train
luoxiaojun1992/lb_framework
components/traits/lb/Config.php
Config.getJsFiles
public function getJsFiles($controller_id, $template_id) { $js_files = []; $asset_config = $this->getConfigByName('assets'); if (isset($asset_config[$controller_id][$template_id]['js'])) { $js_files = $asset_config[$controller_id][$template_id]['js']; } return $js_files; }
php
public function getJsFiles($controller_id, $template_id) { $js_files = []; $asset_config = $this->getConfigByName('assets'); if (isset($asset_config[$controller_id][$template_id]['js'])) { $js_files = $asset_config[$controller_id][$template_id]['js']; } return $js_files; }
[ "public", "function", "getJsFiles", "(", "$", "controller_id", ",", "$", "template_id", ")", "{", "$", "js_files", "=", "[", "]", ";", "$", "asset_config", "=", "$", "this", "->", "getConfigByName", "(", "'assets'", ")", ";", "if", "(", "isset", "(", "$", "asset_config", "[", "$", "controller_id", "]", "[", "$", "template_id", "]", "[", "'js'", "]", ")", ")", "{", "$", "js_files", "=", "$", "asset_config", "[", "$", "controller_id", "]", "[", "$", "template_id", "]", "[", "'js'", "]", ";", "}", "return", "$", "js_files", ";", "}" ]
Get Js Files @param $controller_id @param $template_id @return array
[ "Get", "Js", "Files" ]
12a865729e7738d7d1e07371ad7203243c4571fa
https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/traits/lb/Config.php#L267-L275
train
luoxiaojun1992/lb_framework
components/traits/lb/Config.php
Config.getCssFiles
public function getCssFiles($controller_id, $template_id) { $css_files = []; $asset_config = $this->getConfigByName('assets'); if (isset($asset_config[$controller_id][$template_id]['css'])) { $css_files = $asset_config[$controller_id][$template_id]['css']; } return $css_files; }
php
public function getCssFiles($controller_id, $template_id) { $css_files = []; $asset_config = $this->getConfigByName('assets'); if (isset($asset_config[$controller_id][$template_id]['css'])) { $css_files = $asset_config[$controller_id][$template_id]['css']; } return $css_files; }
[ "public", "function", "getCssFiles", "(", "$", "controller_id", ",", "$", "template_id", ")", "{", "$", "css_files", "=", "[", "]", ";", "$", "asset_config", "=", "$", "this", "->", "getConfigByName", "(", "'assets'", ")", ";", "if", "(", "isset", "(", "$", "asset_config", "[", "$", "controller_id", "]", "[", "$", "template_id", "]", "[", "'css'", "]", ")", ")", "{", "$", "css_files", "=", "$", "asset_config", "[", "$", "controller_id", "]", "[", "$", "template_id", "]", "[", "'css'", "]", ";", "}", "return", "$", "css_files", ";", "}" ]
Get Css Files @param $controller_id @param $template_id @return array
[ "Get", "Css", "Files" ]
12a865729e7738d7d1e07371ad7203243c4571fa
https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/traits/lb/Config.php#L284-L292
train
Synapse-Cmf/synapse-cmf
src/Synapse/Cmf/Framework/Engine/Decorator/Component/ComponentDecorator.php
ComponentDecorator.prepare
public function prepare( $content, ThemeInterface $theme, TemplateInterface $template, ZoneInterface $zone, ComponentInterface $component ) { $this->contextStack->push( $this->contextBuilder ->setContent($content) ->setTheme($theme) ->setTemplate($template) ->setZone($zone) ->setComponent($component) ->createContext() ); return $this; }
php
public function prepare( $content, ThemeInterface $theme, TemplateInterface $template, ZoneInterface $zone, ComponentInterface $component ) { $this->contextStack->push( $this->contextBuilder ->setContent($content) ->setTheme($theme) ->setTemplate($template) ->setZone($zone) ->setComponent($component) ->createContext() ); return $this; }
[ "public", "function", "prepare", "(", "$", "content", ",", "ThemeInterface", "$", "theme", ",", "TemplateInterface", "$", "template", ",", "ZoneInterface", "$", "zone", ",", "ComponentInterface", "$", "component", ")", "{", "$", "this", "->", "contextStack", "->", "push", "(", "$", "this", "->", "contextBuilder", "->", "setContent", "(", "$", "content", ")", "->", "setTheme", "(", "$", "theme", ")", "->", "setTemplate", "(", "$", "template", ")", "->", "setZone", "(", "$", "zone", ")", "->", "setComponent", "(", "$", "component", ")", "->", "createContext", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
Prepare decorator context. @param ContentInterface|Content $content @param ThemeInterface $theme @param TemplateInterface $template @param ZoneInterface $zone @param ComponentInterface $component @return self
[ "Prepare", "decorator", "context", "." ]
d8122a4150a83d5607289724425cf35c56a5e880
https://github.com/Synapse-Cmf/synapse-cmf/blob/d8122a4150a83d5607289724425cf35c56a5e880/src/Synapse/Cmf/Framework/Engine/Decorator/Component/ComponentDecorator.php#L64-L82
train
znframework/package-hypertext
BootstrapAttributes.php
BootstrapAttributes.usePropertyOptions
protected function usePropertyOptions($selector, $content, $type) { $this->isBootstrapAttribute('on', function($return) use($type) { $this->settings['attr']['on'] = Base::suffix($return, '.bs.' . $type); }); return $this->bootstrapObjectOptions($selector === 'all' ? '[data-toggle="'.$type.'"]' : $selector, $content ?? [], $type); }
php
protected function usePropertyOptions($selector, $content, $type) { $this->isBootstrapAttribute('on', function($return) use($type) { $this->settings['attr']['on'] = Base::suffix($return, '.bs.' . $type); }); return $this->bootstrapObjectOptions($selector === 'all' ? '[data-toggle="'.$type.'"]' : $selector, $content ?? [], $type); }
[ "protected", "function", "usePropertyOptions", "(", "$", "selector", ",", "$", "content", ",", "$", "type", ")", "{", "$", "this", "->", "isBootstrapAttribute", "(", "'on'", ",", "function", "(", "$", "return", ")", "use", "(", "$", "type", ")", "{", "$", "this", "->", "settings", "[", "'attr'", "]", "[", "'on'", "]", "=", "Base", "::", "suffix", "(", "$", "return", ",", "'.bs.'", ".", "$", "type", ")", ";", "}", ")", ";", "return", "$", "this", "->", "bootstrapObjectOptions", "(", "$", "selector", "===", "'all'", "?", "'[data-toggle=\"'", ".", "$", "type", ".", "'\"]'", ":", "$", "selector", ",", "$", "content", "??", "[", "]", ",", "$", "type", ")", ";", "}" ]
Protected use property options
[ "Protected", "use", "property", "options" ]
12bbc3bd47a2fae735f638a3e01cc82c1b9c9005
https://github.com/znframework/package-hypertext/blob/12bbc3bd47a2fae735f638a3e01cc82c1b9c9005/BootstrapAttributes.php#L56-L64
train
Etenil/assegai
src/assegai/modules/mail/services/ses/utilities/complextype.class.php
CFComplexType.json
public static function json($json, $member = '', $default_key = '') { return self::option_group(json_decode($json, true), $member, $default_key); }
php
public static function json($json, $member = '', $default_key = '') { return self::option_group(json_decode($json, true), $member, $default_key); }
[ "public", "static", "function", "json", "(", "$", "json", ",", "$", "member", "=", "''", ",", "$", "default_key", "=", "''", ")", "{", "return", "self", "::", "option_group", "(", "json_decode", "(", "$", "json", ",", "true", ")", ",", "$", "member", ",", "$", "default_key", ")", ";", "}" ]
Takes a JSON object, as a string, to convert to query string keys. @param string $json (Required) A JSON object. The JSON string should use canonical rules (e.g., double quotes, quoted keys) as is required by PHP's <php:json_encode()> function. @param string $member (Optional) The name of the "member" property that AWS uses for lists in certain services. Defaults to an empty string. @param string $default_key (Optional) The default key to use when the value for `$data` is a string. Defaults to an empty string. @return array The option group parameters to merge into another method's `$opt` parameter.
[ "Takes", "a", "JSON", "object", "as", "a", "string", "to", "convert", "to", "query", "string", "keys", "." ]
d43cce1a88f1c332f60dd0a4374b17764852af9e
https://github.com/Etenil/assegai/blob/d43cce1a88f1c332f60dd0a4374b17764852af9e/src/assegai/modules/mail/services/ses/utilities/complextype.class.php#L39-L42
train
Etenil/assegai
src/assegai/modules/mail/services/ses/utilities/complextype.class.php
CFComplexType.yaml
public static function yaml($yaml, $member = '', $default_key = '') { return self::option_group(sfYaml::load($yaml), $member, $default_key); }
php
public static function yaml($yaml, $member = '', $default_key = '') { return self::option_group(sfYaml::load($yaml), $member, $default_key); }
[ "public", "static", "function", "yaml", "(", "$", "yaml", ",", "$", "member", "=", "''", ",", "$", "default_key", "=", "''", ")", "{", "return", "self", "::", "option_group", "(", "sfYaml", "::", "load", "(", "$", "yaml", ")", ",", "$", "member", ",", "$", "default_key", ")", ";", "}" ]
Takes a YAML object, as a string, to convert to query string keys. @param string $yaml (Required) A YAML object. @param string $member (Optional) The name of the "member" property that AWS uses for lists in certain services. Defaults to an empty string. @param string $default_key (Optional) The default key to use when the value for `$data` is a string. Defaults to an empty string. @return array The option group parameters to merge into another method's `$opt` parameter.
[ "Takes", "a", "YAML", "object", "as", "a", "string", "to", "convert", "to", "query", "string", "keys", "." ]
d43cce1a88f1c332f60dd0a4374b17764852af9e
https://github.com/Etenil/assegai/blob/d43cce1a88f1c332f60dd0a4374b17764852af9e/src/assegai/modules/mail/services/ses/utilities/complextype.class.php#L52-L55
train
alekitto/metadata
lib/Exception/InvalidArgumentException.php
InvalidArgumentException.create
public static function create($reason): self { $arguments = func_get_args(); switch ($reason) { case static::CLASS_DOES_NOT_EXIST: $message = sprintf('Class %s does not exist. Cannot retrieve its metadata', $arguments[1]); return new static($message); case static::VALUE_IS_NOT_AN_OBJECT: $message = sprintf('Cannot create metadata for non-objects. Got: "%s"', gettype($arguments[1])); return new static($message); case static::NOT_MERGEABLE_METADATA: $message = sprintf( 'Cannot merge metadata of class "%s" with "%s"', is_object($arguments[2]) ? get_class($arguments[2]) : $arguments[2], is_object($arguments[1]) ? get_class($arguments[1]) : $arguments[1] ); return new static($message); case static::INVALID_METADATA_CLASS: $message = sprintf( '"%s" is not a valid metadata object class', is_object($arguments[1]) ? get_class($arguments[1]) : $arguments[1] ); return new static($message); case static::INVALID_PROCESSOR_INTERFACE_CLASS: $message = sprintf( '"%s" is not a valid ProcessorInterface class', $arguments[1] ); return new static($message); } return new static(call_user_func_array('sprintf', $arguments)); }
php
public static function create($reason): self { $arguments = func_get_args(); switch ($reason) { case static::CLASS_DOES_NOT_EXIST: $message = sprintf('Class %s does not exist. Cannot retrieve its metadata', $arguments[1]); return new static($message); case static::VALUE_IS_NOT_AN_OBJECT: $message = sprintf('Cannot create metadata for non-objects. Got: "%s"', gettype($arguments[1])); return new static($message); case static::NOT_MERGEABLE_METADATA: $message = sprintf( 'Cannot merge metadata of class "%s" with "%s"', is_object($arguments[2]) ? get_class($arguments[2]) : $arguments[2], is_object($arguments[1]) ? get_class($arguments[1]) : $arguments[1] ); return new static($message); case static::INVALID_METADATA_CLASS: $message = sprintf( '"%s" is not a valid metadata object class', is_object($arguments[1]) ? get_class($arguments[1]) : $arguments[1] ); return new static($message); case static::INVALID_PROCESSOR_INTERFACE_CLASS: $message = sprintf( '"%s" is not a valid ProcessorInterface class', $arguments[1] ); return new static($message); } return new static(call_user_func_array('sprintf', $arguments)); }
[ "public", "static", "function", "create", "(", "$", "reason", ")", ":", "self", "{", "$", "arguments", "=", "func_get_args", "(", ")", ";", "switch", "(", "$", "reason", ")", "{", "case", "static", "::", "CLASS_DOES_NOT_EXIST", ":", "$", "message", "=", "sprintf", "(", "'Class %s does not exist. Cannot retrieve its metadata'", ",", "$", "arguments", "[", "1", "]", ")", ";", "return", "new", "static", "(", "$", "message", ")", ";", "case", "static", "::", "VALUE_IS_NOT_AN_OBJECT", ":", "$", "message", "=", "sprintf", "(", "'Cannot create metadata for non-objects. Got: \"%s\"'", ",", "gettype", "(", "$", "arguments", "[", "1", "]", ")", ")", ";", "return", "new", "static", "(", "$", "message", ")", ";", "case", "static", "::", "NOT_MERGEABLE_METADATA", ":", "$", "message", "=", "sprintf", "(", "'Cannot merge metadata of class \"%s\" with \"%s\"'", ",", "is_object", "(", "$", "arguments", "[", "2", "]", ")", "?", "get_class", "(", "$", "arguments", "[", "2", "]", ")", ":", "$", "arguments", "[", "2", "]", ",", "is_object", "(", "$", "arguments", "[", "1", "]", ")", "?", "get_class", "(", "$", "arguments", "[", "1", "]", ")", ":", "$", "arguments", "[", "1", "]", ")", ";", "return", "new", "static", "(", "$", "message", ")", ";", "case", "static", "::", "INVALID_METADATA_CLASS", ":", "$", "message", "=", "sprintf", "(", "'\"%s\" is not a valid metadata object class'", ",", "is_object", "(", "$", "arguments", "[", "1", "]", ")", "?", "get_class", "(", "$", "arguments", "[", "1", "]", ")", ":", "$", "arguments", "[", "1", "]", ")", ";", "return", "new", "static", "(", "$", "message", ")", ";", "case", "static", "::", "INVALID_PROCESSOR_INTERFACE_CLASS", ":", "$", "message", "=", "sprintf", "(", "'\"%s\" is not a valid ProcessorInterface class'", ",", "$", "arguments", "[", "1", "]", ")", ";", "return", "new", "static", "(", "$", "message", ")", ";", "}", "return", "new", "static", "(", "call_user_func_array", "(", "'sprintf'", ",", "$", "arguments", ")", ")", ";", "}" ]
Create a new instance of InvalidArgumentException with meaningful message. @param $reason @return self
[ "Create", "a", "new", "instance", "of", "InvalidArgumentException", "with", "meaningful", "message", "." ]
0422ac8d7fe72d5fa8cc51b6f1e173866e8afb2c
https://github.com/alekitto/metadata/blob/0422ac8d7fe72d5fa8cc51b6f1e173866e8afb2c/lib/Exception/InvalidArgumentException.php#L20-L62
train
event-bus/event-dispatcher
src/Util/Pattern/PatternFactory.php
PatternFactory.getPatternFor
public static function getPatternFor(Pattern $parent, $word) { if (self::isWildcard($word)) { return self::getWildcardPattern($parent, $word); } return new Word($word); }
php
public static function getPatternFor(Pattern $parent, $word) { if (self::isWildcard($word)) { return self::getWildcardPattern($parent, $word); } return new Word($word); }
[ "public", "static", "function", "getPatternFor", "(", "Pattern", "$", "parent", ",", "$", "word", ")", "{", "if", "(", "self", "::", "isWildcard", "(", "$", "word", ")", ")", "{", "return", "self", "::", "getWildcardPattern", "(", "$", "parent", ",", "$", "word", ")", ";", "}", "return", "new", "Word", "(", "$", "word", ")", ";", "}" ]
Builds a pattern node based on a given word and its parent. @param Pattern $parent The parent pattern object, in case a loop node will be built. @param string $word A single word from a composite pattern. @return Pattern A pattern object.
[ "Builds", "a", "pattern", "node", "based", "on", "a", "given", "word", "and", "its", "parent", "." ]
0954a9fe0084fbd096b1c32e386c21fb4754b5ff
https://github.com/event-bus/event-dispatcher/blob/0954a9fe0084fbd096b1c32e386c21fb4754b5ff/src/Util/Pattern/PatternFactory.php#L20-L27
train
as3io/modlr
src/Models/Collections/ModelCollection.php
ModelCollection.loadFromStore
protected function loadFromStore() { if (false === $this->isLoaded()) { // Loads collection from the database on iteration. $models = $this->store->loadCollection($this); $this->setModels($models); $this->loaded = true; } }
php
protected function loadFromStore() { if (false === $this->isLoaded()) { // Loads collection from the database on iteration. $models = $this->store->loadCollection($this); $this->setModels($models); $this->loaded = true; } }
[ "protected", "function", "loadFromStore", "(", ")", "{", "if", "(", "false", "===", "$", "this", "->", "isLoaded", "(", ")", ")", "{", "// Loads collection from the database on iteration.", "$", "models", "=", "$", "this", "->", "store", "->", "loadCollection", "(", "$", "this", ")", ";", "$", "this", "->", "setModels", "(", "$", "models", ")", ";", "$", "this", "->", "loaded", "=", "true", ";", "}", "}" ]
Loads this collection from the store.
[ "Loads", "this", "collection", "from", "the", "store", "." ]
7e684b88bb22a2e18397df9402075c6533084b16
https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Models/Collections/ModelCollection.php#L103-L111
train
alphacomm/alpharpc
src/AlphaRPC/Worker/WorkerCommunication.php
WorkerCommunication.setDelay
public function setDelay($delay) { if (!ctype_digit((string) $delay)) { throw new \InvalidArgumentException('Delay must be a number.'); } $this->delay = $delay; return $this; }
php
public function setDelay($delay) { if (!ctype_digit((string) $delay)) { throw new \InvalidArgumentException('Delay must be a number.'); } $this->delay = $delay; return $this; }
[ "public", "function", "setDelay", "(", "$", "delay", ")", "{", "if", "(", "!", "ctype_digit", "(", "(", "string", ")", "$", "delay", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Delay must be a number.'", ")", ";", "}", "$", "this", "->", "delay", "=", "$", "delay", ";", "return", "$", "this", ";", "}" ]
The time it takes for the handler to respond. @param int $delay @throws \InvalidArgumentException @return WorkerCommunication
[ "The", "time", "it", "takes", "for", "the", "handler", "to", "respond", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Worker/WorkerCommunication.php#L115-L123
train
alphacomm/alpharpc
src/AlphaRPC/Worker/WorkerCommunication.php
WorkerCommunication.start
public function start() { $this->workerHandlerReady = true; $this->serviceStreamReady = true; $this->sendToService(new ActionListRequest()); }
php
public function start() { $this->workerHandlerReady = true; $this->serviceStreamReady = true; $this->sendToService(new ActionListRequest()); }
[ "public", "function", "start", "(", ")", "{", "$", "this", "->", "workerHandlerReady", "=", "true", ";", "$", "this", "->", "serviceStreamReady", "=", "true", ";", "$", "this", "->", "sendToService", "(", "new", "ActionListRequest", "(", ")", ")", ";", "}" ]
Initializes the worker.
[ "Initializes", "the", "worker", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Worker/WorkerCommunication.php#L128-L133
train
alphacomm/alpharpc
src/AlphaRPC/Worker/WorkerCommunication.php
WorkerCommunication.process
public function process() { if ($this->worker->getState() == Worker::INVALID) { throw new \RuntimeException('Invalid state to process.'); } $expiry = 5000 + $this->delay; if ($this->worker->isExpired($expiry)) { $this->getLogger()->debug('Worker is expired, no longer registered to workerhandler.'); $this->worker->setState(Worker::INVALID); return; } try { $read = $write = array(); $this->getPoller()->poll($read, $write, 100); } catch (\ZMQPollException $ex) { pcntl_signal_dispatch(); return; } $this->workerHandlerStream->handle(); $this->serviceStream->handle(); $this->handleResult(); $this->heartbeat(); pcntl_signal_dispatch(); }
php
public function process() { if ($this->worker->getState() == Worker::INVALID) { throw new \RuntimeException('Invalid state to process.'); } $expiry = 5000 + $this->delay; if ($this->worker->isExpired($expiry)) { $this->getLogger()->debug('Worker is expired, no longer registered to workerhandler.'); $this->worker->setState(Worker::INVALID); return; } try { $read = $write = array(); $this->getPoller()->poll($read, $write, 100); } catch (\ZMQPollException $ex) { pcntl_signal_dispatch(); return; } $this->workerHandlerStream->handle(); $this->serviceStream->handle(); $this->handleResult(); $this->heartbeat(); pcntl_signal_dispatch(); }
[ "public", "function", "process", "(", ")", "{", "if", "(", "$", "this", "->", "worker", "->", "getState", "(", ")", "==", "Worker", "::", "INVALID", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Invalid state to process.'", ")", ";", "}", "$", "expiry", "=", "5000", "+", "$", "this", "->", "delay", ";", "if", "(", "$", "this", "->", "worker", "->", "isExpired", "(", "$", "expiry", ")", ")", "{", "$", "this", "->", "getLogger", "(", ")", "->", "debug", "(", "'Worker is expired, no longer registered to workerhandler.'", ")", ";", "$", "this", "->", "worker", "->", "setState", "(", "Worker", "::", "INVALID", ")", ";", "return", ";", "}", "try", "{", "$", "read", "=", "$", "write", "=", "array", "(", ")", ";", "$", "this", "->", "getPoller", "(", ")", "->", "poll", "(", "$", "read", ",", "$", "write", ",", "100", ")", ";", "}", "catch", "(", "\\", "ZMQPollException", "$", "ex", ")", "{", "pcntl_signal_dispatch", "(", ")", ";", "return", ";", "}", "$", "this", "->", "workerHandlerStream", "->", "handle", "(", ")", ";", "$", "this", "->", "serviceStream", "->", "handle", "(", ")", ";", "$", "this", "->", "handleResult", "(", ")", ";", "$", "this", "->", "heartbeat", "(", ")", ";", "pcntl_signal_dispatch", "(", ")", ";", "}" ]
Perform one service cycle. This method checks whether there are any new requests to be handled, either from the Worker Handler or from the Service.
[ "Perform", "one", "service", "cycle", ".", "This", "method", "checks", "whether", "there", "are", "any", "new", "requests", "to", "be", "handled", "either", "from", "the", "Worker", "Handler", "or", "from", "the", "Service", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Worker/WorkerCommunication.php#L140-L168
train
alphacomm/alpharpc
src/AlphaRPC/Worker/WorkerCommunication.php
WorkerCommunication.createWorkerHandlerStream
protected function createWorkerHandlerStream(Socket $socket) { $socket->setId('manager'); $this->getPoller()->add($socket, ZMQ::POLL_IN); $that = $this; $this->workerHandlerStream = $socket->getStream(); $this->workerHandlerStream->addListener(StreamInterface::MESSAGE, function (MessageEvent $event) use ($that) { if (null === $event->getProtocolMessage()) { $message = $event->getMessage(); $that->getLogger()->error('Non-protocol message detected in worker-handler stream: '.$message); return; } $that->onWorkerHandlerMessage($event->getProtocolMessage()); }); }
php
protected function createWorkerHandlerStream(Socket $socket) { $socket->setId('manager'); $this->getPoller()->add($socket, ZMQ::POLL_IN); $that = $this; $this->workerHandlerStream = $socket->getStream(); $this->workerHandlerStream->addListener(StreamInterface::MESSAGE, function (MessageEvent $event) use ($that) { if (null === $event->getProtocolMessage()) { $message = $event->getMessage(); $that->getLogger()->error('Non-protocol message detected in worker-handler stream: '.$message); return; } $that->onWorkerHandlerMessage($event->getProtocolMessage()); }); }
[ "protected", "function", "createWorkerHandlerStream", "(", "Socket", "$", "socket", ")", "{", "$", "socket", "->", "setId", "(", "'manager'", ")", ";", "$", "this", "->", "getPoller", "(", ")", "->", "add", "(", "$", "socket", ",", "ZMQ", "::", "POLL_IN", ")", ";", "$", "that", "=", "$", "this", ";", "$", "this", "->", "workerHandlerStream", "=", "$", "socket", "->", "getStream", "(", ")", ";", "$", "this", "->", "workerHandlerStream", "->", "addListener", "(", "StreamInterface", "::", "MESSAGE", ",", "function", "(", "MessageEvent", "$", "event", ")", "use", "(", "$", "that", ")", "{", "if", "(", "null", "===", "$", "event", "->", "getProtocolMessage", "(", ")", ")", "{", "$", "message", "=", "$", "event", "->", "getMessage", "(", ")", ";", "$", "that", "->", "getLogger", "(", ")", "->", "error", "(", "'Non-protocol message detected in worker-handler stream: '", ".", "$", "message", ")", ";", "return", ";", "}", "$", "that", "->", "onWorkerHandlerMessage", "(", "$", "event", "->", "getProtocolMessage", "(", ")", ")", ";", "}", ")", ";", "}" ]
Creates a socket to communicate with the worker handler. @param Socket $socket @return null
[ "Creates", "a", "socket", "to", "communicate", "with", "the", "worker", "handler", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Worker/WorkerCommunication.php#L177-L195
train
alphacomm/alpharpc
src/AlphaRPC/Worker/WorkerCommunication.php
WorkerCommunication.createServiceStream
protected function createServiceStream(Socket $socket) { $socket->setId('worker_service'); $this->getPoller()->add($socket, ZMQ::POLL_IN); $that = $this; $this->serviceStream = $socket->getStream(); $this->serviceStream->addListener(StreamInterface::MESSAGE, function (MessageEvent $event) use ($that) { if (null === $event->getProtocolMessage()) { $message = $event->getMessage(); $that->getLogger()->error('Non-protocol message detected in service stream: '.$message); return; } $that->onServiceMessage($event->getProtocolMessage()); }); }
php
protected function createServiceStream(Socket $socket) { $socket->setId('worker_service'); $this->getPoller()->add($socket, ZMQ::POLL_IN); $that = $this; $this->serviceStream = $socket->getStream(); $this->serviceStream->addListener(StreamInterface::MESSAGE, function (MessageEvent $event) use ($that) { if (null === $event->getProtocolMessage()) { $message = $event->getMessage(); $that->getLogger()->error('Non-protocol message detected in service stream: '.$message); return; } $that->onServiceMessage($event->getProtocolMessage()); }); }
[ "protected", "function", "createServiceStream", "(", "Socket", "$", "socket", ")", "{", "$", "socket", "->", "setId", "(", "'worker_service'", ")", ";", "$", "this", "->", "getPoller", "(", ")", "->", "add", "(", "$", "socket", ",", "ZMQ", "::", "POLL_IN", ")", ";", "$", "that", "=", "$", "this", ";", "$", "this", "->", "serviceStream", "=", "$", "socket", "->", "getStream", "(", ")", ";", "$", "this", "->", "serviceStream", "->", "addListener", "(", "StreamInterface", "::", "MESSAGE", ",", "function", "(", "MessageEvent", "$", "event", ")", "use", "(", "$", "that", ")", "{", "if", "(", "null", "===", "$", "event", "->", "getProtocolMessage", "(", ")", ")", "{", "$", "message", "=", "$", "event", "->", "getMessage", "(", ")", ";", "$", "that", "->", "getLogger", "(", ")", "->", "error", "(", "'Non-protocol message detected in service stream: '", ".", "$", "message", ")", ";", "return", ";", "}", "$", "that", "->", "onServiceMessage", "(", "$", "event", "->", "getProtocolMessage", "(", ")", ")", ";", "}", ")", ";", "}" ]
Creates a socket to communicate with the service. @param Socket $socket @return null
[ "Creates", "a", "socket", "to", "communicate", "with", "the", "service", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Worker/WorkerCommunication.php#L204-L222
train
alphacomm/alpharpc
src/AlphaRPC/Worker/WorkerCommunication.php
WorkerCommunication.onWorkerHandlerMessage
public function onWorkerHandlerMessage(MessageInterface $msg) { $this->workerHandlerReady = true; $this->worker->touch(); if ($msg instanceof Destroy) { $this->worker->setState(Worker::INVALID); return; } if ($msg instanceof ExecuteJobRequest) { $this->startJob($msg); return; } if ($msg instanceof HeartbeatResponseWorkerhandler) { $this->handleHeartbeatResponse(); return; } $this->getLogger()->error('Unknown worker-handler response: '.get_class($msg).'.'); }
php
public function onWorkerHandlerMessage(MessageInterface $msg) { $this->workerHandlerReady = true; $this->worker->touch(); if ($msg instanceof Destroy) { $this->worker->setState(Worker::INVALID); return; } if ($msg instanceof ExecuteJobRequest) { $this->startJob($msg); return; } if ($msg instanceof HeartbeatResponseWorkerhandler) { $this->handleHeartbeatResponse(); return; } $this->getLogger()->error('Unknown worker-handler response: '.get_class($msg).'.'); }
[ "public", "function", "onWorkerHandlerMessage", "(", "MessageInterface", "$", "msg", ")", "{", "$", "this", "->", "workerHandlerReady", "=", "true", ";", "$", "this", "->", "worker", "->", "touch", "(", ")", ";", "if", "(", "$", "msg", "instanceof", "Destroy", ")", "{", "$", "this", "->", "worker", "->", "setState", "(", "Worker", "::", "INVALID", ")", ";", "return", ";", "}", "if", "(", "$", "msg", "instanceof", "ExecuteJobRequest", ")", "{", "$", "this", "->", "startJob", "(", "$", "msg", ")", ";", "return", ";", "}", "if", "(", "$", "msg", "instanceof", "HeartbeatResponseWorkerhandler", ")", "{", "$", "this", "->", "handleHeartbeatResponse", "(", ")", ";", "return", ";", "}", "$", "this", "->", "getLogger", "(", ")", "->", "error", "(", "'Unknown worker-handler response: '", ".", "get_class", "(", "$", "msg", ")", ".", "'.'", ")", ";", "}" ]
Handles a Message from the Worker Handler. @param MessageInterface $msg
[ "Handles", "a", "Message", "from", "the", "Worker", "Handler", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Worker/WorkerCommunication.php#L243-L267
train
alphacomm/alpharpc
src/AlphaRPC/Worker/WorkerCommunication.php
WorkerCommunication.handleHeartbeatResponse
private function handleHeartbeatResponse() { $state = $this->worker->getState(); if (Worker::BUSY == $state) { /** * We should only reply in the following cases: * - A heartbeat is about to expire. * - We have a result. */ return; } if (Worker::RESULT_AVAILABLE == $state) { // A result is available send it to the worker handler. $this->handleResult(); return; } if (in_array($state, array(Worker::READY, Worker::RESULT, Worker::REGISTER))) { // Update the state to ready and forget about the last job. $this->worker->cleanup(); // Request a new job $this->sendToWorkerHandler(new GetJobRequest()); return; } if (Worker::SHUTDOWN != $state) { // The worker did not request a shutdown, however all other states should be handled at this point. $this->getLogger()->error('Invalid worker state: '.$this->worker->getState().'.'); } // Worker is completely shutdown, because there is no open connection to the worker handler. $this->worker->setState(Worker::INVALID); }
php
private function handleHeartbeatResponse() { $state = $this->worker->getState(); if (Worker::BUSY == $state) { /** * We should only reply in the following cases: * - A heartbeat is about to expire. * - We have a result. */ return; } if (Worker::RESULT_AVAILABLE == $state) { // A result is available send it to the worker handler. $this->handleResult(); return; } if (in_array($state, array(Worker::READY, Worker::RESULT, Worker::REGISTER))) { // Update the state to ready and forget about the last job. $this->worker->cleanup(); // Request a new job $this->sendToWorkerHandler(new GetJobRequest()); return; } if (Worker::SHUTDOWN != $state) { // The worker did not request a shutdown, however all other states should be handled at this point. $this->getLogger()->error('Invalid worker state: '.$this->worker->getState().'.'); } // Worker is completely shutdown, because there is no open connection to the worker handler. $this->worker->setState(Worker::INVALID); }
[ "private", "function", "handleHeartbeatResponse", "(", ")", "{", "$", "state", "=", "$", "this", "->", "worker", "->", "getState", "(", ")", ";", "if", "(", "Worker", "::", "BUSY", "==", "$", "state", ")", "{", "/**\n * We should only reply in the following cases:\n * - A heartbeat is about to expire.\n * - We have a result.\n */", "return", ";", "}", "if", "(", "Worker", "::", "RESULT_AVAILABLE", "==", "$", "state", ")", "{", "// A result is available send it to the worker handler.", "$", "this", "->", "handleResult", "(", ")", ";", "return", ";", "}", "if", "(", "in_array", "(", "$", "state", ",", "array", "(", "Worker", "::", "READY", ",", "Worker", "::", "RESULT", ",", "Worker", "::", "REGISTER", ")", ")", ")", "{", "// Update the state to ready and forget about the last job.", "$", "this", "->", "worker", "->", "cleanup", "(", ")", ";", "// Request a new job", "$", "this", "->", "sendToWorkerHandler", "(", "new", "GetJobRequest", "(", ")", ")", ";", "return", ";", "}", "if", "(", "Worker", "::", "SHUTDOWN", "!=", "$", "state", ")", "{", "// The worker did not request a shutdown, however all other states should be handled at this point.", "$", "this", "->", "getLogger", "(", ")", "->", "error", "(", "'Invalid worker state: '", ".", "$", "this", "->", "worker", "->", "getState", "(", ")", ".", "'.'", ")", ";", "}", "// Worker is completely shutdown, because there is no open connection to the worker handler.", "$", "this", "->", "worker", "->", "setState", "(", "Worker", "::", "INVALID", ")", ";", "}" ]
Handles the heartbeat response from the worker handler.
[ "Handles", "the", "heartbeat", "response", "from", "the", "worker", "handler", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Worker/WorkerCommunication.php#L272-L308
train
alphacomm/alpharpc
src/AlphaRPC/Worker/WorkerCommunication.php
WorkerCommunication.onServiceMessage
public function onServiceMessage(MessageInterface $msg) { $this->serviceStreamReady = true; $this->getLogger()->debug('Received Service Message of Type: '.get_class($msg)); if ($msg instanceof ActionListResponse) { $actions = $msg->getActions(); $this->getLogger()->debug('The action list is: '.implode(', ', $actions).'.'); $this->worker->setActions($actions); $reply = new Register(); $reply->setActions($actions); $this->sendToWorkerHandler($reply); unset($reply); return; } if ($msg instanceof ExecuteJobResponse) { $requestId = $msg->getRequestId(); $result = $msg->getResult(); $this->getLogger()->debug('Result for: '.$requestId.': '.$result); $this->worker->setResult($requestId, $result); return; } $this->getLogger()->error('Unknown service response: '.get_class($msg).'.'); }
php
public function onServiceMessage(MessageInterface $msg) { $this->serviceStreamReady = true; $this->getLogger()->debug('Received Service Message of Type: '.get_class($msg)); if ($msg instanceof ActionListResponse) { $actions = $msg->getActions(); $this->getLogger()->debug('The action list is: '.implode(', ', $actions).'.'); $this->worker->setActions($actions); $reply = new Register(); $reply->setActions($actions); $this->sendToWorkerHandler($reply); unset($reply); return; } if ($msg instanceof ExecuteJobResponse) { $requestId = $msg->getRequestId(); $result = $msg->getResult(); $this->getLogger()->debug('Result for: '.$requestId.': '.$result); $this->worker->setResult($requestId, $result); return; } $this->getLogger()->error('Unknown service response: '.get_class($msg).'.'); }
[ "public", "function", "onServiceMessage", "(", "MessageInterface", "$", "msg", ")", "{", "$", "this", "->", "serviceStreamReady", "=", "true", ";", "$", "this", "->", "getLogger", "(", ")", "->", "debug", "(", "'Received Service Message of Type: '", ".", "get_class", "(", "$", "msg", ")", ")", ";", "if", "(", "$", "msg", "instanceof", "ActionListResponse", ")", "{", "$", "actions", "=", "$", "msg", "->", "getActions", "(", ")", ";", "$", "this", "->", "getLogger", "(", ")", "->", "debug", "(", "'The action list is: '", ".", "implode", "(", "', '", ",", "$", "actions", ")", ".", "'.'", ")", ";", "$", "this", "->", "worker", "->", "setActions", "(", "$", "actions", ")", ";", "$", "reply", "=", "new", "Register", "(", ")", ";", "$", "reply", "->", "setActions", "(", "$", "actions", ")", ";", "$", "this", "->", "sendToWorkerHandler", "(", "$", "reply", ")", ";", "unset", "(", "$", "reply", ")", ";", "return", ";", "}", "if", "(", "$", "msg", "instanceof", "ExecuteJobResponse", ")", "{", "$", "requestId", "=", "$", "msg", "->", "getRequestId", "(", ")", ";", "$", "result", "=", "$", "msg", "->", "getResult", "(", ")", ";", "$", "this", "->", "getLogger", "(", ")", "->", "debug", "(", "'Result for: '", ".", "$", "requestId", ".", "': '", ".", "$", "result", ")", ";", "$", "this", "->", "worker", "->", "setResult", "(", "$", "requestId", ",", "$", "result", ")", ";", "return", ";", "}", "$", "this", "->", "getLogger", "(", ")", "->", "error", "(", "'Unknown service response: '", ".", "get_class", "(", "$", "msg", ")", ".", "'.'", ")", ";", "}" ]
Handles a Message from the Service Handler. @param MessageInterface $msg
[ "Handles", "a", "Message", "from", "the", "Service", "Handler", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Worker/WorkerCommunication.php#L315-L344
train
alphacomm/alpharpc
src/AlphaRPC/Worker/WorkerCommunication.php
WorkerCommunication.startJob
public function startJob(ExecuteJobRequest $request) { $this->worker->setState(Worker::BUSY); $requestId = $request->getRequestId(); $action = $request->getAction(); if (!$this->worker->hasAction($action)) { $this->getLogger()->debug('Action '.$action.' not found.'); $this->sendToWorkerHandler(new ActionNotFound($requestId, $action)); return; } $this->getLogger()->debug('Sending new request ('.$requestId.') to action '.$action); $this->serviceStream->send($request); }
php
public function startJob(ExecuteJobRequest $request) { $this->worker->setState(Worker::BUSY); $requestId = $request->getRequestId(); $action = $request->getAction(); if (!$this->worker->hasAction($action)) { $this->getLogger()->debug('Action '.$action.' not found.'); $this->sendToWorkerHandler(new ActionNotFound($requestId, $action)); return; } $this->getLogger()->debug('Sending new request ('.$requestId.') to action '.$action); $this->serviceStream->send($request); }
[ "public", "function", "startJob", "(", "ExecuteJobRequest", "$", "request", ")", "{", "$", "this", "->", "worker", "->", "setState", "(", "Worker", "::", "BUSY", ")", ";", "$", "requestId", "=", "$", "request", "->", "getRequestId", "(", ")", ";", "$", "action", "=", "$", "request", "->", "getAction", "(", ")", ";", "if", "(", "!", "$", "this", "->", "worker", "->", "hasAction", "(", "$", "action", ")", ")", "{", "$", "this", "->", "getLogger", "(", ")", "->", "debug", "(", "'Action '", ".", "$", "action", ".", "' not found.'", ")", ";", "$", "this", "->", "sendToWorkerHandler", "(", "new", "ActionNotFound", "(", "$", "requestId", ",", "$", "action", ")", ")", ";", "return", ";", "}", "$", "this", "->", "getLogger", "(", ")", "->", "debug", "(", "'Sending new request ('", ".", "$", "requestId", ".", "') to action '", ".", "$", "action", ")", ";", "$", "this", "->", "serviceStream", "->", "send", "(", "$", "request", ")", ";", "}" ]
Starts a Job. @param ExecuteJobRequest $request
[ "Starts", "a", "Job", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Worker/WorkerCommunication.php#L351-L366
train
alphacomm/alpharpc
src/AlphaRPC/Worker/WorkerCommunication.php
WorkerCommunication.heartbeat
public function heartbeat() { $state = $this->worker->getState(); if (!in_array($state, array(Worker::BUSY, Worker::READY))) { return; } // Detect manager crash. $timeout = 2500; if (!$this->worker->isExpired($timeout)) { // Worker is pretty active no heartbeat required. return; } if ($this->isWorkerHandlerReady()) { // Send a heartbeat. $this->sendToWorkerHandler(new Protocol\Heartbeat()); return; } $expiry = 5000 + $this->delay; if (!$this->worker->isExpired($expiry)) { return; } // Expired, manager already destroyed this instance. $this->worker->setState(Worker::INVALID); }
php
public function heartbeat() { $state = $this->worker->getState(); if (!in_array($state, array(Worker::BUSY, Worker::READY))) { return; } // Detect manager crash. $timeout = 2500; if (!$this->worker->isExpired($timeout)) { // Worker is pretty active no heartbeat required. return; } if ($this->isWorkerHandlerReady()) { // Send a heartbeat. $this->sendToWorkerHandler(new Protocol\Heartbeat()); return; } $expiry = 5000 + $this->delay; if (!$this->worker->isExpired($expiry)) { return; } // Expired, manager already destroyed this instance. $this->worker->setState(Worker::INVALID); }
[ "public", "function", "heartbeat", "(", ")", "{", "$", "state", "=", "$", "this", "->", "worker", "->", "getState", "(", ")", ";", "if", "(", "!", "in_array", "(", "$", "state", ",", "array", "(", "Worker", "::", "BUSY", ",", "Worker", "::", "READY", ")", ")", ")", "{", "return", ";", "}", "// Detect manager crash.", "$", "timeout", "=", "2500", ";", "if", "(", "!", "$", "this", "->", "worker", "->", "isExpired", "(", "$", "timeout", ")", ")", "{", "// Worker is pretty active no heartbeat required.", "return", ";", "}", "if", "(", "$", "this", "->", "isWorkerHandlerReady", "(", ")", ")", "{", "// Send a heartbeat.", "$", "this", "->", "sendToWorkerHandler", "(", "new", "Protocol", "\\", "Heartbeat", "(", ")", ")", ";", "return", ";", "}", "$", "expiry", "=", "5000", "+", "$", "this", "->", "delay", ";", "if", "(", "!", "$", "this", "->", "worker", "->", "isExpired", "(", "$", "expiry", ")", ")", "{", "return", ";", "}", "// Expired, manager already destroyed this instance.", "$", "this", "->", "worker", "->", "setState", "(", "Worker", "::", "INVALID", ")", ";", "}" ]
Performs a heartbeat with the Worker Handler.
[ "Performs", "a", "heartbeat", "with", "the", "Worker", "Handler", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Worker/WorkerCommunication.php#L371-L399
train
alphacomm/alpharpc
src/AlphaRPC/Worker/WorkerCommunication.php
WorkerCommunication.handleResult
public function handleResult() { // No result $result = $this->worker->getResult(); if ($result === null) { return; } // Invalid worker state, wait for a response first. if (!$this->isWorkerHandlerReady()) { return; } $this->sendToWorkerHandler(new Protocol\JobResult($this->worker->getRequestId(), $result)); $this->worker->setState(Worker::RESULT); }
php
public function handleResult() { // No result $result = $this->worker->getResult(); if ($result === null) { return; } // Invalid worker state, wait for a response first. if (!$this->isWorkerHandlerReady()) { return; } $this->sendToWorkerHandler(new Protocol\JobResult($this->worker->getRequestId(), $result)); $this->worker->setState(Worker::RESULT); }
[ "public", "function", "handleResult", "(", ")", "{", "// No result", "$", "result", "=", "$", "this", "->", "worker", "->", "getResult", "(", ")", ";", "if", "(", "$", "result", "===", "null", ")", "{", "return", ";", "}", "// Invalid worker state, wait for a response first.", "if", "(", "!", "$", "this", "->", "isWorkerHandlerReady", "(", ")", ")", "{", "return", ";", "}", "$", "this", "->", "sendToWorkerHandler", "(", "new", "Protocol", "\\", "JobResult", "(", "$", "this", "->", "worker", "->", "getRequestId", "(", ")", ",", "$", "result", ")", ")", ";", "$", "this", "->", "worker", "->", "setState", "(", "Worker", "::", "RESULT", ")", ";", "}" ]
Sends when the Service is done working, this sends the result to the Worker Handler.
[ "Sends", "when", "the", "Service", "is", "done", "working", "this", "sends", "the", "result", "to", "the", "Worker", "Handler", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Worker/WorkerCommunication.php#L404-L419
train
alphacomm/alpharpc
src/AlphaRPC/Worker/WorkerCommunication.php
WorkerCommunication.sendToWorkerHandler
public function sendToWorkerHandler(MessageInterface $msg) { if (!$this->isWorkerHandlerReady()) { $this->getLogger()->debug('WorkerHandler socket not ready to send.'); return; } $this->workerHandlerReady = false; $this->workerHandlerStream->send($msg); }
php
public function sendToWorkerHandler(MessageInterface $msg) { if (!$this->isWorkerHandlerReady()) { $this->getLogger()->debug('WorkerHandler socket not ready to send.'); return; } $this->workerHandlerReady = false; $this->workerHandlerStream->send($msg); }
[ "public", "function", "sendToWorkerHandler", "(", "MessageInterface", "$", "msg", ")", "{", "if", "(", "!", "$", "this", "->", "isWorkerHandlerReady", "(", ")", ")", "{", "$", "this", "->", "getLogger", "(", ")", "->", "debug", "(", "'WorkerHandler socket not ready to send.'", ")", ";", "return", ";", "}", "$", "this", "->", "workerHandlerReady", "=", "false", ";", "$", "this", "->", "workerHandlerStream", "->", "send", "(", "$", "msg", ")", ";", "}" ]
Send the given Message to the Worker Handler. @param MessageInterface $msg
[ "Send", "the", "given", "Message", "to", "the", "Worker", "Handler", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Worker/WorkerCommunication.php#L426-L436
train
alphacomm/alpharpc
src/AlphaRPC/Worker/WorkerCommunication.php
WorkerCommunication.sendToService
public function sendToService(MessageInterface $msg) { if (!$this->isServiceStreamReady()) { $this->getLogger()->debug('Service socket not ready to send.'); return; } $this->getLogger()->debug('Sending to service.'); $this->serviceStreamReady = false; $this->serviceStream->send($msg); }
php
public function sendToService(MessageInterface $msg) { if (!$this->isServiceStreamReady()) { $this->getLogger()->debug('Service socket not ready to send.'); return; } $this->getLogger()->debug('Sending to service.'); $this->serviceStreamReady = false; $this->serviceStream->send($msg); }
[ "public", "function", "sendToService", "(", "MessageInterface", "$", "msg", ")", "{", "if", "(", "!", "$", "this", "->", "isServiceStreamReady", "(", ")", ")", "{", "$", "this", "->", "getLogger", "(", ")", "->", "debug", "(", "'Service socket not ready to send.'", ")", ";", "return", ";", "}", "$", "this", "->", "getLogger", "(", ")", "->", "debug", "(", "'Sending to service.'", ")", ";", "$", "this", "->", "serviceStreamReady", "=", "false", ";", "$", "this", "->", "serviceStream", "->", "send", "(", "$", "msg", ")", ";", "}" ]
Send the given Message to the Service. @param MessageInterface $msg
[ "Send", "the", "given", "Message", "to", "the", "Service", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Worker/WorkerCommunication.php#L443-L454
train
plumphp/plum-excel
src/ExcelWriter.php
ExcelWriter.finish
public function finish() { $writer = $this->writer; if (!$writer) { $writer = PHPExcel_IOFactory::createWriter($this->excel, $this->format); } $writer->save($this->filename); }
php
public function finish() { $writer = $this->writer; if (!$writer) { $writer = PHPExcel_IOFactory::createWriter($this->excel, $this->format); } $writer->save($this->filename); }
[ "public", "function", "finish", "(", ")", "{", "$", "writer", "=", "$", "this", "->", "writer", ";", "if", "(", "!", "$", "writer", ")", "{", "$", "writer", "=", "PHPExcel_IOFactory", "::", "createWriter", "(", "$", "this", "->", "excel", ",", "$", "this", "->", "format", ")", ";", "}", "$", "writer", "->", "save", "(", "$", "this", "->", "filename", ")", ";", "}" ]
Finish the writer.
[ "Finish", "the", "writer", "." ]
cc1dd308901b836676e077b13f01c0c87845c5f6
https://github.com/plumphp/plum-excel/blob/cc1dd308901b836676e077b13f01c0c87845c5f6/src/ExcelWriter.php#L156-L163
train
strident/Aegis
src/Aegis/Authentication/Authenticator/DelegatingAuthenticator.php
DelegatingAuthenticator.delegateAuthenticator
private function delegateAuthenticator(TokenInterface $token) { if ( ! $authenticator = $this->resolveAuthenticator($token)) { throw new \RuntimeException(sprintf( 'No authentication authenticator found for token: "%s".', get_class($token) )); } return $authenticator; }
php
private function delegateAuthenticator(TokenInterface $token) { if ( ! $authenticator = $this->resolveAuthenticator($token)) { throw new \RuntimeException(sprintf( 'No authentication authenticator found for token: "%s".', get_class($token) )); } return $authenticator; }
[ "private", "function", "delegateAuthenticator", "(", "TokenInterface", "$", "token", ")", "{", "if", "(", "!", "$", "authenticator", "=", "$", "this", "->", "resolveAuthenticator", "(", "$", "token", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'No authentication authenticator found for token: \"%s\".'", ",", "get_class", "(", "$", "token", ")", ")", ")", ";", "}", "return", "$", "authenticator", ";", "}" ]
Delegate a authenticator for a token. @param TokenInterface $token @return DelegatingAuthenticator
[ "Delegate", "a", "authenticator", "for", "a", "token", "." ]
954bd3d24808d77271844276ae31b41f4f039bd5
https://github.com/strident/Aegis/blob/954bd3d24808d77271844276ae31b41f4f039bd5/src/Aegis/Authentication/Authenticator/DelegatingAuthenticator.php#L123-L133
train
strident/Aegis
src/Aegis/Authentication/Authenticator/DelegatingAuthenticator.php
DelegatingAuthenticator.resolveAuthenticator
private function resolveAuthenticator(TokenInterface $token) { foreach ($this->authenticators as $authenticator) { if ($authenticator->supports($token)) { return $authenticator; } } return false; }
php
private function resolveAuthenticator(TokenInterface $token) { foreach ($this->authenticators as $authenticator) { if ($authenticator->supports($token)) { return $authenticator; } } return false; }
[ "private", "function", "resolveAuthenticator", "(", "TokenInterface", "$", "token", ")", "{", "foreach", "(", "$", "this", "->", "authenticators", "as", "$", "authenticator", ")", "{", "if", "(", "$", "authenticator", "->", "supports", "(", "$", "token", ")", ")", "{", "return", "$", "authenticator", ";", "}", "}", "return", "false", ";", "}" ]
Resolve a token to its authenticator. @param TokenInterface $token @return mixed
[ "Resolve", "a", "token", "to", "its", "authenticator", "." ]
954bd3d24808d77271844276ae31b41f4f039bd5
https://github.com/strident/Aegis/blob/954bd3d24808d77271844276ae31b41f4f039bd5/src/Aegis/Authentication/Authenticator/DelegatingAuthenticator.php#L142-L151
train
tigron/skeleton-error
lib/Skeleton/Error/Handler/Basic.php
Basic.handle
public function handle() { // If this is a reqular exception, always quit, else check the type if (!($this->exception instanceof \ErrorException)) { $this->quit = true; } else { // Only quit after specific error types switch ($this->exception->getSeverity()) { case E_ERROR: case E_CORE_ERROR: case E_USER_ERROR: $this->quit = true; } } return self::get_html($this->exception); }
php
public function handle() { // If this is a reqular exception, always quit, else check the type if (!($this->exception instanceof \ErrorException)) { $this->quit = true; } else { // Only quit after specific error types switch ($this->exception->getSeverity()) { case E_ERROR: case E_CORE_ERROR: case E_USER_ERROR: $this->quit = true; } } return self::get_html($this->exception); }
[ "public", "function", "handle", "(", ")", "{", "// If this is a reqular exception, always quit, else check the type", "if", "(", "!", "(", "$", "this", "->", "exception", "instanceof", "\\", "ErrorException", ")", ")", "{", "$", "this", "->", "quit", "=", "true", ";", "}", "else", "{", "// Only quit after specific error types", "switch", "(", "$", "this", "->", "exception", "->", "getSeverity", "(", ")", ")", "{", "case", "E_ERROR", ":", "case", "E_CORE_ERROR", ":", "case", "E_USER_ERROR", ":", "$", "this", "->", "quit", "=", "true", ";", "}", "}", "return", "self", "::", "get_html", "(", "$", "this", "->", "exception", ")", ";", "}" ]
Handle an error with the most basic handler @return string
[ "Handle", "an", "error", "with", "the", "most", "basic", "handler" ]
c0671ad52a4386d95179f1c47bedfdf754ee3611
https://github.com/tigron/skeleton-error/blob/c0671ad52a4386d95179f1c47bedfdf754ee3611/lib/Skeleton/Error/Handler/Basic.php#L24-L39
train
tigron/skeleton-error
lib/Skeleton/Error/Handler/Basic.php
Basic.get_subject
public static function get_subject($exception) { $application = null; try { $application = \Skeleton\Core\Application::get(); } catch (\Exception $e) {} if ($application === null) { $hostname = 'unknown'; $name = 'unknown'; } else { $hostname = $application->hostname; $name = $application->name; } if ($exception instanceof \ErrorException) { $subject = get_class($exception) . ' (' . \Skeleton\Error\Util\Misc::translate_error_code($exception->getSeverity()) . ') on ' . $hostname . ' (' . $name . ')'; } else { $subject = get_class($exception) . ' on ' . $hostname . ' (' . $name . ')'; } return $subject; }
php
public static function get_subject($exception) { $application = null; try { $application = \Skeleton\Core\Application::get(); } catch (\Exception $e) {} if ($application === null) { $hostname = 'unknown'; $name = 'unknown'; } else { $hostname = $application->hostname; $name = $application->name; } if ($exception instanceof \ErrorException) { $subject = get_class($exception) . ' (' . \Skeleton\Error\Util\Misc::translate_error_code($exception->getSeverity()) . ') on ' . $hostname . ' (' . $name . ')'; } else { $subject = get_class($exception) . ' on ' . $hostname . ' (' . $name . ')'; } return $subject; }
[ "public", "static", "function", "get_subject", "(", "$", "exception", ")", "{", "$", "application", "=", "null", ";", "try", "{", "$", "application", "=", "\\", "Skeleton", "\\", "Core", "\\", "Application", "::", "get", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "if", "(", "$", "application", "===", "null", ")", "{", "$", "hostname", "=", "'unknown'", ";", "$", "name", "=", "'unknown'", ";", "}", "else", "{", "$", "hostname", "=", "$", "application", "->", "hostname", ";", "$", "name", "=", "$", "application", "->", "name", ";", "}", "if", "(", "$", "exception", "instanceof", "\\", "ErrorException", ")", "{", "$", "subject", "=", "get_class", "(", "$", "exception", ")", ".", "' ('", ".", "\\", "Skeleton", "\\", "Error", "\\", "Util", "\\", "Misc", "::", "translate_error_code", "(", "$", "exception", "->", "getSeverity", "(", ")", ")", ".", "') on '", ".", "$", "hostname", ".", "' ('", ".", "$", "name", ".", "')'", ";", "}", "else", "{", "$", "subject", "=", "get_class", "(", "$", "exception", ")", ".", "' on '", ".", "$", "hostname", ".", "' ('", ".", "$", "name", ".", "')'", ";", "}", "return", "$", "subject", ";", "}" ]
Produce a subject based on the error @param $exception (can be \Throwable or \Exception) @return string
[ "Produce", "a", "subject", "based", "on", "the", "error" ]
c0671ad52a4386d95179f1c47bedfdf754ee3611
https://github.com/tigron/skeleton-error/blob/c0671ad52a4386d95179f1c47bedfdf754ee3611/lib/Skeleton/Error/Handler/Basic.php#L61-L83
train
tigron/skeleton-error
lib/Skeleton/Error/Handler/Basic.php
Basic.get_html
public static function get_html($exception) { $subject = self::get_subject($exception); if ($exception instanceof \ErrorException) { $error_type = \Skeleton\Error\Util\Misc::translate_error_code($exception->getSeverity()); } else { $error_type = 'Exception'; } $error_info = ''; $error_info .= 'Error: ' . $exception->getMessage() . "\n"; $error_info .= 'Type: ' . $error_type . "\n"; $error_info .= 'File: ' . $exception->getFile() . "\n"; $error_info .= 'Line: ' . $exception->getLine() . "\n\n"; $error_info .= 'Time: ' . date('Y-m-d H:i:s') . "\n"; $html = '<html>' . ' <head>' . ' <title>' . $subject . '</title>' . ' <style type="text/css">' . ' body { font-family: sans-serif; background: #eee; } ' . ' pre { border: 1px solid #1b2582; background: #ccc; padding: 5px; }' . ' h1 { width: 100%; background: #183452; font-weight: bold; color: #fff; padding: 2px; font-size: 16px;} ' . ' h2 { font-size: 15px; } ' . ' </style>' . ' </head>' . ' <body>' . ' <h1>' . $subject . '</h1>'; $html .= '<h2>Message</h2> <pre>' . $exception->getMessage() . '</pre>'; $html .= '<h2>Info</h2> <pre>' . $error_info . '</pre>'; // Backtraces are not very useful for anything else but real exceptions if (!($exception instanceof \ErrorException)) { ob_start(); debug_print_backtrace(); $backtrace = ob_get_contents(); ob_end_clean(); $html .= '<h2>Backtrace</h2> <pre>' . $backtrace . '</pre>'; } $vartrace = [ '_GET' => isset($_GET) ? $_GET : null, '_POST' => isset($_POST) ? $_POST : null, '_COOKIE' => isset($_COOKIE) ? $_COOKIE : null, '_SESSION' => isset($_SESSION) ? $_SESSION : null, '_SERVER' => isset($_SERVER) ? $_SERVER : null ]; $html .= '<h2>Vartrace</h2> <pre> ' . print_r($vartrace, true) . '</pre>'; $html .= ' </body>' . '</html>'; return $html; }
php
public static function get_html($exception) { $subject = self::get_subject($exception); if ($exception instanceof \ErrorException) { $error_type = \Skeleton\Error\Util\Misc::translate_error_code($exception->getSeverity()); } else { $error_type = 'Exception'; } $error_info = ''; $error_info .= 'Error: ' . $exception->getMessage() . "\n"; $error_info .= 'Type: ' . $error_type . "\n"; $error_info .= 'File: ' . $exception->getFile() . "\n"; $error_info .= 'Line: ' . $exception->getLine() . "\n\n"; $error_info .= 'Time: ' . date('Y-m-d H:i:s') . "\n"; $html = '<html>' . ' <head>' . ' <title>' . $subject . '</title>' . ' <style type="text/css">' . ' body { font-family: sans-serif; background: #eee; } ' . ' pre { border: 1px solid #1b2582; background: #ccc; padding: 5px; }' . ' h1 { width: 100%; background: #183452; font-weight: bold; color: #fff; padding: 2px; font-size: 16px;} ' . ' h2 { font-size: 15px; } ' . ' </style>' . ' </head>' . ' <body>' . ' <h1>' . $subject . '</h1>'; $html .= '<h2>Message</h2> <pre>' . $exception->getMessage() . '</pre>'; $html .= '<h2>Info</h2> <pre>' . $error_info . '</pre>'; // Backtraces are not very useful for anything else but real exceptions if (!($exception instanceof \ErrorException)) { ob_start(); debug_print_backtrace(); $backtrace = ob_get_contents(); ob_end_clean(); $html .= '<h2>Backtrace</h2> <pre>' . $backtrace . '</pre>'; } $vartrace = [ '_GET' => isset($_GET) ? $_GET : null, '_POST' => isset($_POST) ? $_POST : null, '_COOKIE' => isset($_COOKIE) ? $_COOKIE : null, '_SESSION' => isset($_SESSION) ? $_SESSION : null, '_SERVER' => isset($_SERVER) ? $_SERVER : null ]; $html .= '<h2>Vartrace</h2> <pre> ' . print_r($vartrace, true) . '</pre>'; $html .= ' </body>' . '</html>'; return $html; }
[ "public", "static", "function", "get_html", "(", "$", "exception", ")", "{", "$", "subject", "=", "self", "::", "get_subject", "(", "$", "exception", ")", ";", "if", "(", "$", "exception", "instanceof", "\\", "ErrorException", ")", "{", "$", "error_type", "=", "\\", "Skeleton", "\\", "Error", "\\", "Util", "\\", "Misc", "::", "translate_error_code", "(", "$", "exception", "->", "getSeverity", "(", ")", ")", ";", "}", "else", "{", "$", "error_type", "=", "'Exception'", ";", "}", "$", "error_info", "=", "''", ";", "$", "error_info", ".=", "'Error: '", ".", "$", "exception", "->", "getMessage", "(", ")", ".", "\"\\n\"", ";", "$", "error_info", ".=", "'Type: '", ".", "$", "error_type", ".", "\"\\n\"", ";", "$", "error_info", ".=", "'File: '", ".", "$", "exception", "->", "getFile", "(", ")", ".", "\"\\n\"", ";", "$", "error_info", ".=", "'Line: '", ".", "$", "exception", "->", "getLine", "(", ")", ".", "\"\\n\\n\"", ";", "$", "error_info", ".=", "'Time: '", ".", "date", "(", "'Y-m-d H:i:s'", ")", ".", "\"\\n\"", ";", "$", "html", "=", "'<html>'", ".", "' <head>'", ".", "' <title>'", ".", "$", "subject", ".", "'</title>'", ".", "' <style type=\"text/css\">'", ".", "' body { font-family: sans-serif; background: #eee; } '", ".", "' pre { border: 1px solid #1b2582; background: #ccc; padding: 5px; }'", ".", "' h1 { width: 100%; background: #183452; font-weight: bold; color: #fff; padding: 2px; font-size: 16px;} '", ".", "' h2 { font-size: 15px; } '", ".", "' </style>'", ".", "' </head>'", ".", "' <body>'", ".", "' <h1>'", ".", "$", "subject", ".", "'</h1>'", ";", "$", "html", ".=", "'<h2>Message</h2> <pre>'", ".", "$", "exception", "->", "getMessage", "(", ")", ".", "'</pre>'", ";", "$", "html", ".=", "'<h2>Info</h2> <pre>'", ".", "$", "error_info", ".", "'</pre>'", ";", "// Backtraces are not very useful for anything else but real exceptions", "if", "(", "!", "(", "$", "exception", "instanceof", "\\", "ErrorException", ")", ")", "{", "ob_start", "(", ")", ";", "debug_print_backtrace", "(", ")", ";", "$", "backtrace", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "$", "html", ".=", "'<h2>Backtrace</h2> <pre>'", ".", "$", "backtrace", ".", "'</pre>'", ";", "}", "$", "vartrace", "=", "[", "'_GET'", "=>", "isset", "(", "$", "_GET", ")", "?", "$", "_GET", ":", "null", ",", "'_POST'", "=>", "isset", "(", "$", "_POST", ")", "?", "$", "_POST", ":", "null", ",", "'_COOKIE'", "=>", "isset", "(", "$", "_COOKIE", ")", "?", "$", "_COOKIE", ":", "null", ",", "'_SESSION'", "=>", "isset", "(", "$", "_SESSION", ")", "?", "$", "_SESSION", ":", "null", ",", "'_SERVER'", "=>", "isset", "(", "$", "_SERVER", ")", "?", "$", "_SERVER", ":", "null", "]", ";", "$", "html", ".=", "'<h2>Vartrace</h2> <pre> '", ".", "print_r", "(", "$", "vartrace", ",", "true", ")", ".", "'</pre>'", ";", "$", "html", ".=", "' </body>'", ".", "'</html>'", ";", "return", "$", "html", ";", "}" ]
Produce some HTML around the error @param $exception (can be \Throwable or \Exception) @return string
[ "Produce", "some", "HTML", "around", "the", "error" ]
c0671ad52a4386d95179f1c47bedfdf754ee3611
https://github.com/tigron/skeleton-error/blob/c0671ad52a4386d95179f1c47bedfdf754ee3611/lib/Skeleton/Error/Handler/Basic.php#L91-L150
train
harp-orm/harp
src/Repo.php
Repo.loadRelFor
public function loadRelFor(Models $models, $relName, $flags = null) { $rel = $this->getRelOrError($relName); $foreign = $rel->loadModelsIfAvailable($models, $flags); $rel->linkModels($models, $foreign, function (AbstractLink $link) { $class = get_class($link->getModel()); $class::getRepo()->addLink($link); }); return $foreign; }
php
public function loadRelFor(Models $models, $relName, $flags = null) { $rel = $this->getRelOrError($relName); $foreign = $rel->loadModelsIfAvailable($models, $flags); $rel->linkModels($models, $foreign, function (AbstractLink $link) { $class = get_class($link->getModel()); $class::getRepo()->addLink($link); }); return $foreign; }
[ "public", "function", "loadRelFor", "(", "Models", "$", "models", ",", "$", "relName", ",", "$", "flags", "=", "null", ")", "{", "$", "rel", "=", "$", "this", "->", "getRelOrError", "(", "$", "relName", ")", ";", "$", "foreign", "=", "$", "rel", "->", "loadModelsIfAvailable", "(", "$", "models", ",", "$", "flags", ")", ";", "$", "rel", "->", "linkModels", "(", "$", "models", ",", "$", "foreign", ",", "function", "(", "AbstractLink", "$", "link", ")", "{", "$", "class", "=", "get_class", "(", "$", "link", "->", "getModel", "(", ")", ")", ";", "$", "class", "::", "getRepo", "(", ")", "->", "addLink", "(", "$", "link", ")", ";", "}", ")", ";", "return", "$", "foreign", ";", "}" ]
Load models for a given relation. @param Models $models @param string $relName @return Models @throws InvalidArgumentException If $relName does not belong to repo
[ "Load", "models", "for", "a", "given", "relation", "." ]
e0751696521164c86ccd0a76d708df490efd8306
https://github.com/harp-orm/harp/blob/e0751696521164c86ccd0a76d708df490efd8306/src/Repo.php#L137-L149
train
harp-orm/harp
src/Repo.php
Repo.loadAllRelsFor
public function loadAllRelsFor(Models $models, array $rels, $flags = null) { $rels = Arr::toAssoc($rels); foreach ($rels as $relName => $childRels) { $foreign = $this->loadRelFor($models, $relName, $flags); if ($childRels) { $rel = $this->getRel($relName); $rel->getRepo()->loadAllRelsFor($foreign, $childRels, $flags); } } return $this; }
php
public function loadAllRelsFor(Models $models, array $rels, $flags = null) { $rels = Arr::toAssoc($rels); foreach ($rels as $relName => $childRels) { $foreign = $this->loadRelFor($models, $relName, $flags); if ($childRels) { $rel = $this->getRel($relName); $rel->getRepo()->loadAllRelsFor($foreign, $childRels, $flags); } } return $this; }
[ "public", "function", "loadAllRelsFor", "(", "Models", "$", "models", ",", "array", "$", "rels", ",", "$", "flags", "=", "null", ")", "{", "$", "rels", "=", "Arr", "::", "toAssoc", "(", "$", "rels", ")", ";", "foreach", "(", "$", "rels", "as", "$", "relName", "=>", "$", "childRels", ")", "{", "$", "foreign", "=", "$", "this", "->", "loadRelFor", "(", "$", "models", ",", "$", "relName", ",", "$", "flags", ")", ";", "if", "(", "$", "childRels", ")", "{", "$", "rel", "=", "$", "this", "->", "getRel", "(", "$", "relName", ")", ";", "$", "rel", "->", "getRepo", "(", ")", "->", "loadAllRelsFor", "(", "$", "foreign", ",", "$", "childRels", ",", "$", "flags", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Load all the models for the provided relations. This is the meat of the eager loading @param Models $models @param array $rels @param int $flags @return Repo $this
[ "Load", "all", "the", "models", "for", "the", "provided", "relations", ".", "This", "is", "the", "meat", "of", "the", "eager", "loading" ]
e0751696521164c86ccd0a76d708df490efd8306
https://github.com/harp-orm/harp/blob/e0751696521164c86ccd0a76d708df490efd8306/src/Repo.php#L159-L173
train
harp-orm/harp
src/Repo.php
Repo.updateModels
public function updateModels(Models $models) { foreach ($models as $model) { if ($model->isSoftDeleted()) { $this->dispatchBeforeEvent($model, Event::DELETE); } else { $this->dispatchBeforeEvent($model, Event::UPDATE); $this->dispatchBeforeEvent($model, Event::SAVE); } } $this->updateAll()->executeModels($models); foreach ($models as $model) { $model->resetOriginals(); if ($model->isSoftDeleted()) { $this->dispatchAfterEvent($model, Event::DELETE); } else { $this->dispatchAfterEvent($model, Event::UPDATE); $this->dispatchAfterEvent($model, Event::SAVE); } } return $this; }
php
public function updateModels(Models $models) { foreach ($models as $model) { if ($model->isSoftDeleted()) { $this->dispatchBeforeEvent($model, Event::DELETE); } else { $this->dispatchBeforeEvent($model, Event::UPDATE); $this->dispatchBeforeEvent($model, Event::SAVE); } } $this->updateAll()->executeModels($models); foreach ($models as $model) { $model->resetOriginals(); if ($model->isSoftDeleted()) { $this->dispatchAfterEvent($model, Event::DELETE); } else { $this->dispatchAfterEvent($model, Event::UPDATE); $this->dispatchAfterEvent($model, Event::SAVE); } } return $this; }
[ "public", "function", "updateModels", "(", "Models", "$", "models", ")", "{", "foreach", "(", "$", "models", "as", "$", "model", ")", "{", "if", "(", "$", "model", "->", "isSoftDeleted", "(", ")", ")", "{", "$", "this", "->", "dispatchBeforeEvent", "(", "$", "model", ",", "Event", "::", "DELETE", ")", ";", "}", "else", "{", "$", "this", "->", "dispatchBeforeEvent", "(", "$", "model", ",", "Event", "::", "UPDATE", ")", ";", "$", "this", "->", "dispatchBeforeEvent", "(", "$", "model", ",", "Event", "::", "SAVE", ")", ";", "}", "}", "$", "this", "->", "updateAll", "(", ")", "->", "executeModels", "(", "$", "models", ")", ";", "foreach", "(", "$", "models", "as", "$", "model", ")", "{", "$", "model", "->", "resetOriginals", "(", ")", ";", "if", "(", "$", "model", "->", "isSoftDeleted", "(", ")", ")", "{", "$", "this", "->", "dispatchAfterEvent", "(", "$", "model", ",", "Event", "::", "DELETE", ")", ";", "}", "else", "{", "$", "this", "->", "dispatchAfterEvent", "(", "$", "model", ",", "Event", "::", "UPDATE", ")", ";", "$", "this", "->", "dispatchAfterEvent", "(", "$", "model", ",", "Event", "::", "SAVE", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Call all the events associated with model updates. Perform the update itself. @param Models $models @return Repo $this
[ "Call", "all", "the", "events", "associated", "with", "model", "updates", ".", "Perform", "the", "update", "itself", "." ]
e0751696521164c86ccd0a76d708df490efd8306
https://github.com/harp-orm/harp/blob/e0751696521164c86ccd0a76d708df490efd8306/src/Repo.php#L181-L207
train
harp-orm/harp
src/Repo.php
Repo.deleteModels
public function deleteModels(Models $models) { foreach ($models as $model) { $this->dispatchBeforeEvent($model, Event::DELETE); } $this->deleteAll()->executeModels($models); foreach ($models as $model) { $this->dispatchAfterEvent($model, Event::DELETE); } return $this; }
php
public function deleteModels(Models $models) { foreach ($models as $model) { $this->dispatchBeforeEvent($model, Event::DELETE); } $this->deleteAll()->executeModels($models); foreach ($models as $model) { $this->dispatchAfterEvent($model, Event::DELETE); } return $this; }
[ "public", "function", "deleteModels", "(", "Models", "$", "models", ")", "{", "foreach", "(", "$", "models", "as", "$", "model", ")", "{", "$", "this", "->", "dispatchBeforeEvent", "(", "$", "model", ",", "Event", "::", "DELETE", ")", ";", "}", "$", "this", "->", "deleteAll", "(", ")", "->", "executeModels", "(", "$", "models", ")", ";", "foreach", "(", "$", "models", "as", "$", "model", ")", "{", "$", "this", "->", "dispatchAfterEvent", "(", "$", "model", ",", "Event", "::", "DELETE", ")", ";", "}", "return", "$", "this", ";", "}" ]
Call all the events associated with model deletion. Perform the deletion itself. @param Models $models @return Repo $this
[ "Call", "all", "the", "events", "associated", "with", "model", "deletion", ".", "Perform", "the", "deletion", "itself", "." ]
e0751696521164c86ccd0a76d708df490efd8306
https://github.com/harp-orm/harp/blob/e0751696521164c86ccd0a76d708df490efd8306/src/Repo.php#L215-L228
train
harp-orm/harp
src/Repo.php
Repo.insertModels
public function insertModels(Models $models) { foreach ($models as $model) { $this->dispatchBeforeEvent($model, Event::INSERT); $this->dispatchBeforeEvent($model, Event::SAVE); } $this->insertAll()->executeModels($models); foreach ($models as $model) { $model ->resetOriginals() ->setState(State::SAVED); $this->dispatchAfterEvent($model, Event::INSERT); $this->dispatchAfterEvent($model, Event::SAVE); } return $this; }
php
public function insertModels(Models $models) { foreach ($models as $model) { $this->dispatchBeforeEvent($model, Event::INSERT); $this->dispatchBeforeEvent($model, Event::SAVE); } $this->insertAll()->executeModels($models); foreach ($models as $model) { $model ->resetOriginals() ->setState(State::SAVED); $this->dispatchAfterEvent($model, Event::INSERT); $this->dispatchAfterEvent($model, Event::SAVE); } return $this; }
[ "public", "function", "insertModels", "(", "Models", "$", "models", ")", "{", "foreach", "(", "$", "models", "as", "$", "model", ")", "{", "$", "this", "->", "dispatchBeforeEvent", "(", "$", "model", ",", "Event", "::", "INSERT", ")", ";", "$", "this", "->", "dispatchBeforeEvent", "(", "$", "model", ",", "Event", "::", "SAVE", ")", ";", "}", "$", "this", "->", "insertAll", "(", ")", "->", "executeModels", "(", "$", "models", ")", ";", "foreach", "(", "$", "models", "as", "$", "model", ")", "{", "$", "model", "->", "resetOriginals", "(", ")", "->", "setState", "(", "State", "::", "SAVED", ")", ";", "$", "this", "->", "dispatchAfterEvent", "(", "$", "model", ",", "Event", "::", "INSERT", ")", ";", "$", "this", "->", "dispatchAfterEvent", "(", "$", "model", ",", "Event", "::", "SAVE", ")", ";", "}", "return", "$", "this", ";", "}" ]
Call all the events associated with model insertion. Perform the insertion itself. @param Models $models @return Repo $this
[ "Call", "all", "the", "events", "associated", "with", "model", "insertion", ".", "Perform", "the", "insertion", "itself", "." ]
e0751696521164c86ccd0a76d708df490efd8306
https://github.com/harp-orm/harp/blob/e0751696521164c86ccd0a76d708df490efd8306/src/Repo.php#L236-L255
train
Phpillip/phpillip
src/Console/Command/WatchCommand.php
WatchCommand.build
protected function build(OutputInterface $output) { $this->command->run($this->input, $output); $this->lastBuild = new DateTime(); }
php
protected function build(OutputInterface $output) { $this->command->run($this->input, $output); $this->lastBuild = new DateTime(); }
[ "protected", "function", "build", "(", "OutputInterface", "$", "output", ")", "{", "$", "this", "->", "command", "->", "run", "(", "$", "this", "->", "input", ",", "$", "output", ")", ";", "$", "this", "->", "lastBuild", "=", "new", "DateTime", "(", ")", ";", "}" ]
Run the build command @param OutputInterface $output
[ "Run", "the", "build", "command" ]
c37afaafb536361e7e0b564659f1cd5b80b98be9
https://github.com/Phpillip/phpillip/blob/c37afaafb536361e7e0b564659f1cd5b80b98be9/src/Console/Command/WatchCommand.php#L88-L93
train
prooph/processing
library/Processor/Process.php
Process.setUp
public static function setUp(NodeName $nodeName, array $tasks, array $config = array()) { /** @var $instance Process */ $instance = new static(); $instance->assertConfig($config); $processId = ProcessId::generate(); $taskList = TaskList::scheduleTasks(TaskListId::linkWith($nodeName, $processId), $tasks); $instance->recordThat(ProcessWasSetUp::with($processId, $taskList, $config)); return $instance; }
php
public static function setUp(NodeName $nodeName, array $tasks, array $config = array()) { /** @var $instance Process */ $instance = new static(); $instance->assertConfig($config); $processId = ProcessId::generate(); $taskList = TaskList::scheduleTasks(TaskListId::linkWith($nodeName, $processId), $tasks); $instance->recordThat(ProcessWasSetUp::with($processId, $taskList, $config)); return $instance; }
[ "public", "static", "function", "setUp", "(", "NodeName", "$", "nodeName", ",", "array", "$", "tasks", ",", "array", "$", "config", "=", "array", "(", ")", ")", "{", "/** @var $instance Process */", "$", "instance", "=", "new", "static", "(", ")", ";", "$", "instance", "->", "assertConfig", "(", "$", "config", ")", ";", "$", "processId", "=", "ProcessId", "::", "generate", "(", ")", ";", "$", "taskList", "=", "TaskList", "::", "scheduleTasks", "(", "TaskListId", "::", "linkWith", "(", "$", "nodeName", ",", "$", "processId", ")", ",", "$", "tasks", ")", ";", "$", "instance", "->", "recordThat", "(", "ProcessWasSetUp", "::", "with", "(", "$", "processId", ",", "$", "taskList", ",", "$", "config", ")", ")", ";", "return", "$", "instance", ";", "}" ]
Creates new process from given tasks and config @param NodeName $nodeName @param Task[] $tasks @param array $config @return static
[ "Creates", "new", "process", "from", "given", "tasks", "and", "config" ]
a2947bccbffeecc4ca93a15e38ab53814e3e53e5
https://github.com/prooph/processing/blob/a2947bccbffeecc4ca93a15e38ab53814e3e53e5/library/Processor/Process.php#L102-L116
train
prooph/processing
library/Processor/Process.php
Process.receiveMessage
public function receiveMessage($message, WorkflowEngine $workflowEngine) { if ($message instanceof WorkflowMessage) { if (MessageNameUtils::isProcessingCommand($message->messageName())) { $this->perform($workflowEngine, $message); return; } $this->assertTaskEntryExists($message->processTaskListPosition()); $this->recordThat(TaskEntryMarkedAsDone::at($message->processTaskListPosition())); $this->perform($workflowEngine, $message); return; } if ($message instanceof LogMessage) { $this->assertTaskEntryExists($message->processTaskListPosition()); $this->recordThat(LogMessageReceived::record($message)); if ($message->isError()) { $this->recordThat(TaskEntryMarkedAsFailed::at($message->processTaskListPosition())); } elseif ($this->isSubProcess() && $this->syncLogMessages) { //We only sync non error messages, because errors are always synced and then they would be received twice $messageForParent = $message->reconnectToProcessTask($this->parentTaskListPosition); $workflowEngine->dispatch($messageForParent); } } }
php
public function receiveMessage($message, WorkflowEngine $workflowEngine) { if ($message instanceof WorkflowMessage) { if (MessageNameUtils::isProcessingCommand($message->messageName())) { $this->perform($workflowEngine, $message); return; } $this->assertTaskEntryExists($message->processTaskListPosition()); $this->recordThat(TaskEntryMarkedAsDone::at($message->processTaskListPosition())); $this->perform($workflowEngine, $message); return; } if ($message instanceof LogMessage) { $this->assertTaskEntryExists($message->processTaskListPosition()); $this->recordThat(LogMessageReceived::record($message)); if ($message->isError()) { $this->recordThat(TaskEntryMarkedAsFailed::at($message->processTaskListPosition())); } elseif ($this->isSubProcess() && $this->syncLogMessages) { //We only sync non error messages, because errors are always synced and then they would be received twice $messageForParent = $message->reconnectToProcessTask($this->parentTaskListPosition); $workflowEngine->dispatch($messageForParent); } } }
[ "public", "function", "receiveMessage", "(", "$", "message", ",", "WorkflowEngine", "$", "workflowEngine", ")", "{", "if", "(", "$", "message", "instanceof", "WorkflowMessage", ")", "{", "if", "(", "MessageNameUtils", "::", "isProcessingCommand", "(", "$", "message", "->", "messageName", "(", ")", ")", ")", "{", "$", "this", "->", "perform", "(", "$", "workflowEngine", ",", "$", "message", ")", ";", "return", ";", "}", "$", "this", "->", "assertTaskEntryExists", "(", "$", "message", "->", "processTaskListPosition", "(", ")", ")", ";", "$", "this", "->", "recordThat", "(", "TaskEntryMarkedAsDone", "::", "at", "(", "$", "message", "->", "processTaskListPosition", "(", ")", ")", ")", ";", "$", "this", "->", "perform", "(", "$", "workflowEngine", ",", "$", "message", ")", ";", "return", ";", "}", "if", "(", "$", "message", "instanceof", "LogMessage", ")", "{", "$", "this", "->", "assertTaskEntryExists", "(", "$", "message", "->", "processTaskListPosition", "(", ")", ")", ";", "$", "this", "->", "recordThat", "(", "LogMessageReceived", "::", "record", "(", "$", "message", ")", ")", ";", "if", "(", "$", "message", "->", "isError", "(", ")", ")", "{", "$", "this", "->", "recordThat", "(", "TaskEntryMarkedAsFailed", "::", "at", "(", "$", "message", "->", "processTaskListPosition", "(", ")", ")", ")", ";", "}", "elseif", "(", "$", "this", "->", "isSubProcess", "(", ")", "&&", "$", "this", "->", "syncLogMessages", ")", "{", "//We only sync non error messages, because errors are always synced and then they would be received twice", "$", "messageForParent", "=", "$", "message", "->", "reconnectToProcessTask", "(", "$", "this", "->", "parentTaskListPosition", ")", ";", "$", "workflowEngine", "->", "dispatch", "(", "$", "messageForParent", ")", ";", "}", "}", "}" ]
A Process can start or continue with the next step after it has received a message @param WorkflowMessage|LogMessage $message @param WorkflowEngine $workflowEngine @throws \RuntimeException @return void
[ "A", "Process", "can", "start", "or", "continue", "with", "the", "next", "step", "after", "it", "has", "received", "a", "message" ]
a2947bccbffeecc4ca93a15e38ab53814e3e53e5
https://github.com/prooph/processing/blob/a2947bccbffeecc4ca93a15e38ab53814e3e53e5/library/Processor/Process.php#L168-L197
train
oliwierptak/Everon1
src/Everon/Helper/Asserts/IsEmpty.php
IsEmpty.assertIsEmpty
public function assertIsEmpty($value, $message='%s must not be empty', $exception='Asserts') { if (isset($value) === false || empty($value)) { $this->throwException($exception, $message, $value); } }
php
public function assertIsEmpty($value, $message='%s must not be empty', $exception='Asserts') { if (isset($value) === false || empty($value)) { $this->throwException($exception, $message, $value); } }
[ "public", "function", "assertIsEmpty", "(", "$", "value", ",", "$", "message", "=", "'%s must not be empty'", ",", "$", "exception", "=", "'Asserts'", ")", "{", "if", "(", "isset", "(", "$", "value", ")", "===", "false", "||", "empty", "(", "$", "value", ")", ")", "{", "$", "this", "->", "throwException", "(", "$", "exception", ",", "$", "message", ",", "$", "value", ")", ";", "}", "}" ]
Verifies that the specified condition is not empty. The assertion fails if the condition is empty. @param mixed $value @param string $message @param string $exception @throws \Everon\Exception\Asserts
[ "Verifies", "that", "the", "specified", "condition", "is", "not", "empty", ".", "The", "assertion", "fails", "if", "the", "condition", "is", "empty", "." ]
ac93793d1fa517a8394db5f00062f1925dc218a3
https://github.com/oliwierptak/Everon1/blob/ac93793d1fa517a8394db5f00062f1925dc218a3/src/Everon/Helper/Asserts/IsEmpty.php#L23-L28
train
haldayne/fox
src/Expression.php
Expression.makeCallable
private static function makeCallable($expression) { if (! array_key_exists($expression, static::$map)) { $return = "return ($expression);"; try { $lambda = create_function(static::$signature, $return); } catch (\ParseError $ex) { $lambda = false; } finally { if (false === $lambda) { throw new \LogicException(sprintf( 'Expression is not valid PHP code: given=[%s], becomes=[%s]', $expression, $return )); } else { static::$map[$expression] = $lambda; } } } return static::$map[$expression]; }
php
private static function makeCallable($expression) { if (! array_key_exists($expression, static::$map)) { $return = "return ($expression);"; try { $lambda = create_function(static::$signature, $return); } catch (\ParseError $ex) { $lambda = false; } finally { if (false === $lambda) { throw new \LogicException(sprintf( 'Expression is not valid PHP code: given=[%s], becomes=[%s]', $expression, $return )); } else { static::$map[$expression] = $lambda; } } } return static::$map[$expression]; }
[ "private", "static", "function", "makeCallable", "(", "$", "expression", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "expression", ",", "static", "::", "$", "map", ")", ")", "{", "$", "return", "=", "\"return ($expression);\"", ";", "try", "{", "$", "lambda", "=", "create_function", "(", "static", "::", "$", "signature", ",", "$", "return", ")", ";", "}", "catch", "(", "\\", "ParseError", "$", "ex", ")", "{", "$", "lambda", "=", "false", ";", "}", "finally", "{", "if", "(", "false", "===", "$", "lambda", ")", "{", "throw", "new", "\\", "LogicException", "(", "sprintf", "(", "'Expression is not valid PHP code: given=[%s], becomes=[%s]'", ",", "$", "expression", ",", "$", "return", ")", ")", ";", "}", "else", "{", "static", "::", "$", "map", "[", "$", "expression", "]", "=", "$", "lambda", ";", "}", "}", "}", "return", "static", "::", "$", "map", "[", "$", "expression", "]", ";", "}" ]
Given a string expression, turn that into an anonymous function. Cache the result, so as to keep memory impacts low. @throw \LogicException
[ "Given", "a", "string", "expression", "turn", "that", "into", "an", "anonymous", "function", ".", "Cache", "the", "result", "so", "as", "to", "keep", "memory", "impacts", "low", "." ]
f5dcc3798cca0fdbfc6f448c5cb5a174eaab60eb
https://github.com/haldayne/fox/blob/f5dcc3798cca0fdbfc6f448c5cb5a174eaab60eb/src/Expression.php#L124-L145
train
stonedz/pff2
src/modules/cookies/Cookies.php
Cookies.setCookie
public function setCookie($cookieName, $value = null, $expire = null) { if ($expire !== null) { $expire = time() + (60 * 60 * $expire); } if (setcookie($cookieName, $this->encodeCookie($value), $expire, "/")) { return true; } else { return false; } }
php
public function setCookie($cookieName, $value = null, $expire = null) { if ($expire !== null) { $expire = time() + (60 * 60 * $expire); } if (setcookie($cookieName, $this->encodeCookie($value), $expire, "/")) { return true; } else { return false; } }
[ "public", "function", "setCookie", "(", "$", "cookieName", ",", "$", "value", "=", "null", ",", "$", "expire", "=", "null", ")", "{", "if", "(", "$", "expire", "!==", "null", ")", "{", "$", "expire", "=", "time", "(", ")", "+", "(", "60", "*", "60", "*", "$", "expire", ")", ";", "}", "if", "(", "setcookie", "(", "$", "cookieName", ",", "$", "this", "->", "encodeCookie", "(", "$", "value", ")", ",", "$", "expire", ",", "\"/\"", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Sets a cookie in the user's browser @param string $cookieName @param string|null $value The value to store in the cookie @param int|null $expire how many HOURS the cookie will be valid (set to 0 for session time) @return bool
[ "Sets", "a", "cookie", "in", "the", "user", "s", "browser" ]
ec3b087d4d4732816f61ac487f0cb25511e0da88
https://github.com/stonedz/pff2/blob/ec3b087d4d4732816f61ac487f0cb25511e0da88/src/modules/cookies/Cookies.php#L41-L51
train
stonedz/pff2
src/modules/cookies/Cookies.php
Cookies.getCookie
public function getCookie($cookieName) { if (isset($_COOKIE[$cookieName])) { return $this->decodeCookie($_COOKIE[$cookieName]); } else { return false; } }
php
public function getCookie($cookieName) { if (isset($_COOKIE[$cookieName])) { return $this->decodeCookie($_COOKIE[$cookieName]); } else { return false; } }
[ "public", "function", "getCookie", "(", "$", "cookieName", ")", "{", "if", "(", "isset", "(", "$", "_COOKIE", "[", "$", "cookieName", "]", ")", ")", "{", "return", "$", "this", "->", "decodeCookie", "(", "$", "_COOKIE", "[", "$", "cookieName", "]", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Check if a cookie is set and returns its content @param string $cookieName @return bool @retrurn string
[ "Check", "if", "a", "cookie", "is", "set", "and", "returns", "its", "content" ]
ec3b087d4d4732816f61ac487f0cb25511e0da88
https://github.com/stonedz/pff2/blob/ec3b087d4d4732816f61ac487f0cb25511e0da88/src/modules/cookies/Cookies.php#L76-L82
train
mpaleo/view-tags
src/ViewTags/TagsContainer.php
TagsContainer.taggedWith
public function taggedWith($tag) { $results = []; if (isset($this->tags[$tag])) { foreach ($this->tags[$tag] as $view) { $results[] = $view; } } return $results; }
php
public function taggedWith($tag) { $results = []; if (isset($this->tags[$tag])) { foreach ($this->tags[$tag] as $view) { $results[] = $view; } } return $results; }
[ "public", "function", "taggedWith", "(", "$", "tag", ")", "{", "$", "results", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "tags", "[", "$", "tag", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "tags", "[", "$", "tag", "]", "as", "$", "view", ")", "{", "$", "results", "[", "]", "=", "$", "view", ";", "}", "}", "return", "$", "results", ";", "}" ]
Return all the views for a given tag. @param $tag @return array
[ "Return", "all", "the", "views", "for", "a", "given", "tag", "." ]
7ca3308b616738e744a0435f581bbd705e59cad6
https://github.com/mpaleo/view-tags/blob/7ca3308b616738e744a0435f581bbd705e59cad6/src/ViewTags/TagsContainer.php#L41-L55
train
newup/core
src/Templates/Renderers/TemplateRenderer.php
TemplateRenderer.registerFilters
private function registerFilters() { $filters = config('app.render_filters', []); foreach ($filters as $filter) { $filter = app($filter); if ($filter instanceof FilterContract) { $this->twigEnvironment->addFilter(new \Twig_SimpleFilter($filter->getName(), $filter->getFilter())); $this->twigStringEnvironment->addFilter(new \Twig_SimpleFilter($filter->getName(), $filter->getFilter())); } } }
php
private function registerFilters() { $filters = config('app.render_filters', []); foreach ($filters as $filter) { $filter = app($filter); if ($filter instanceof FilterContract) { $this->twigEnvironment->addFilter(new \Twig_SimpleFilter($filter->getName(), $filter->getFilter())); $this->twigStringEnvironment->addFilter(new \Twig_SimpleFilter($filter->getName(), $filter->getFilter())); } } }
[ "private", "function", "registerFilters", "(", ")", "{", "$", "filters", "=", "config", "(", "'app.render_filters'", ",", "[", "]", ")", ";", "foreach", "(", "$", "filters", "as", "$", "filter", ")", "{", "$", "filter", "=", "app", "(", "$", "filter", ")", ";", "if", "(", "$", "filter", "instanceof", "FilterContract", ")", "{", "$", "this", "->", "twigEnvironment", "->", "addFilter", "(", "new", "\\", "Twig_SimpleFilter", "(", "$", "filter", "->", "getName", "(", ")", ",", "$", "filter", "->", "getFilter", "(", ")", ")", ")", ";", "$", "this", "->", "twigStringEnvironment", "->", "addFilter", "(", "new", "\\", "Twig_SimpleFilter", "(", "$", "filter", "->", "getName", "(", ")", ",", "$", "filter", "->", "getFilter", "(", ")", ")", ")", ";", "}", "}", "}" ]
Registers the template filters.
[ "Registers", "the", "template", "filters", "." ]
54128903e7775e67d63284d958b46862c8df71f9
https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Templates/Renderers/TemplateRenderer.php#L112-L125
train
newup/core
src/Templates/Renderers/TemplateRenderer.php
TemplateRenderer.addPath
public function addPath($path) { try { $this->twigFileLoader->addPath($path); } catch (\Twig_Error_Loader $e) { throw new InvalidPathException($e->getMessage()); } }
php
public function addPath($path) { try { $this->twigFileLoader->addPath($path); } catch (\Twig_Error_Loader $e) { throw new InvalidPathException($e->getMessage()); } }
[ "public", "function", "addPath", "(", "$", "path", ")", "{", "try", "{", "$", "this", "->", "twigFileLoader", "->", "addPath", "(", "$", "path", ")", ";", "}", "catch", "(", "\\", "Twig_Error_Loader", "$", "e", ")", "{", "throw", "new", "InvalidPathException", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Adds a path to the template environment. @param $path @throws InvalidPathException
[ "Adds", "a", "path", "to", "the", "template", "environment", "." ]
54128903e7775e67d63284d958b46862c8df71f9
https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Templates/Renderers/TemplateRenderer.php#L148-L155
train
newup/core
src/Templates/Renderers/TemplateRenderer.php
TemplateRenderer.getData
public function getData() { $systemInformation = []; $systemInformation['newup_version'] = Application::VERSION; return $this->dataArray + $systemInformation + $this->collectData(); }
php
public function getData() { $systemInformation = []; $systemInformation['newup_version'] = Application::VERSION; return $this->dataArray + $systemInformation + $this->collectData(); }
[ "public", "function", "getData", "(", ")", "{", "$", "systemInformation", "=", "[", "]", ";", "$", "systemInformation", "[", "'newup_version'", "]", "=", "Application", "::", "VERSION", ";", "return", "$", "this", "->", "dataArray", "+", "$", "systemInformation", "+", "$", "this", "->", "collectData", "(", ")", ";", "}" ]
Gets the environment data. @return array
[ "Gets", "the", "environment", "data", "." ]
54128903e7775e67d63284d958b46862c8df71f9
https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Templates/Renderers/TemplateRenderer.php#L203-L209
train
newup/core
src/Templates/Renderers/TemplateRenderer.php
TemplateRenderer.render
public function render($templateName) { try { return $this->twigEnvironment->render($templateName, $this->getData()); } catch (SecurityException $e) { throw new SecurityException($e->getMessage(), $e->getCode(), $e); } catch (\Twig_Error_Runtime $e) { throw new RuntimeException($e->getMessage(), $e->getCode(), $e); } catch (\Twig_Error_Syntax $e) { throw new InvalidSyntaxException($e->getMessage(), $e->getCode(), $e); } catch (\Twig_Error_Loader $e) { if ($this->ignoreUndefinedTemplateErrors && Str::contains($e->getMessage(), 'is not defined')) { return; } throw new InvalidTemplateException($e->getMessage(), $e->getCode(), $e); } }
php
public function render($templateName) { try { return $this->twigEnvironment->render($templateName, $this->getData()); } catch (SecurityException $e) { throw new SecurityException($e->getMessage(), $e->getCode(), $e); } catch (\Twig_Error_Runtime $e) { throw new RuntimeException($e->getMessage(), $e->getCode(), $e); } catch (\Twig_Error_Syntax $e) { throw new InvalidSyntaxException($e->getMessage(), $e->getCode(), $e); } catch (\Twig_Error_Loader $e) { if ($this->ignoreUndefinedTemplateErrors && Str::contains($e->getMessage(), 'is not defined')) { return; } throw new InvalidTemplateException($e->getMessage(), $e->getCode(), $e); } }
[ "public", "function", "render", "(", "$", "templateName", ")", "{", "try", "{", "return", "$", "this", "->", "twigEnvironment", "->", "render", "(", "$", "templateName", ",", "$", "this", "->", "getData", "(", ")", ")", ";", "}", "catch", "(", "SecurityException", "$", "e", ")", "{", "throw", "new", "SecurityException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "catch", "(", "\\", "Twig_Error_Runtime", "$", "e", ")", "{", "throw", "new", "RuntimeException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "catch", "(", "\\", "Twig_Error_Syntax", "$", "e", ")", "{", "throw", "new", "InvalidSyntaxException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "catch", "(", "\\", "Twig_Error_Loader", "$", "e", ")", "{", "if", "(", "$", "this", "->", "ignoreUndefinedTemplateErrors", "&&", "Str", "::", "contains", "(", "$", "e", "->", "getMessage", "(", ")", ",", "'is not defined'", ")", ")", "{", "return", ";", "}", "throw", "new", "InvalidTemplateException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "}" ]
Renders a template by name. @param $templateName @return string @throws InvalidTemplateException @throws InvalidSyntaxException @throws RuntimeException @throws SecurityException
[ "Renders", "a", "template", "by", "name", "." ]
54128903e7775e67d63284d958b46862c8df71f9
https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Templates/Renderers/TemplateRenderer.php#L232-L251
train
newup/core
src/Templates/Renderers/TemplateRenderer.php
TemplateRenderer.renderString
public function renderString($templateString) { try { return $this->twigStringEnvironment->render($templateString, $this->getData()); } catch (SecurityException $e) { throw new SecurityException($e->getMessage(), $e->getCode(), $e); } catch (\Twig_Error_Runtime $e) { throw new RuntimeException($e->getMessage(), $e->getCode(), $e); } catch (\Twig_Error_Syntax $e) { throw new InvalidSyntaxException($e->getMessage(), $e->getCode(), $e); } catch (\Twig_Error_Loader $e) { if ($this->ignoreUndefinedTemplateErrors && Str::contains($e->getMessage(), 'is not defined')) { return; } throw new InvalidTemplateException($e->getMessage(), $e->getCode(), $e); } }
php
public function renderString($templateString) { try { return $this->twigStringEnvironment->render($templateString, $this->getData()); } catch (SecurityException $e) { throw new SecurityException($e->getMessage(), $e->getCode(), $e); } catch (\Twig_Error_Runtime $e) { throw new RuntimeException($e->getMessage(), $e->getCode(), $e); } catch (\Twig_Error_Syntax $e) { throw new InvalidSyntaxException($e->getMessage(), $e->getCode(), $e); } catch (\Twig_Error_Loader $e) { if ($this->ignoreUndefinedTemplateErrors && Str::contains($e->getMessage(), 'is not defined')) { return; } throw new InvalidTemplateException($e->getMessage(), $e->getCode(), $e); } }
[ "public", "function", "renderString", "(", "$", "templateString", ")", "{", "try", "{", "return", "$", "this", "->", "twigStringEnvironment", "->", "render", "(", "$", "templateString", ",", "$", "this", "->", "getData", "(", ")", ")", ";", "}", "catch", "(", "SecurityException", "$", "e", ")", "{", "throw", "new", "SecurityException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "catch", "(", "\\", "Twig_Error_Runtime", "$", "e", ")", "{", "throw", "new", "RuntimeException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "catch", "(", "\\", "Twig_Error_Syntax", "$", "e", ")", "{", "throw", "new", "InvalidSyntaxException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "catch", "(", "\\", "Twig_Error_Loader", "$", "e", ")", "{", "if", "(", "$", "this", "->", "ignoreUndefinedTemplateErrors", "&&", "Str", "::", "contains", "(", "$", "e", "->", "getMessage", "(", ")", ",", "'is not defined'", ")", ")", "{", "return", ";", "}", "throw", "new", "InvalidTemplateException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "}" ]
Renders a string as a template. @param $templateString @return string @throws InvalidTemplateException @throws InvalidSyntaxException @throws RuntimeException @throws SecurityException
[ "Renders", "a", "string", "as", "a", "template", "." ]
54128903e7775e67d63284d958b46862c8df71f9
https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Templates/Renderers/TemplateRenderer.php#L263-L282
train
newup/core
src/Templates/Renderers/TemplateRenderer.php
TemplateRenderer.collectData
public function collectData() { $collectedData = []; foreach ($this->dataCollectors as $collector) { $collectedData = $collectedData + $collector->collect(); } return $collectedData; }
php
public function collectData() { $collectedData = []; foreach ($this->dataCollectors as $collector) { $collectedData = $collectedData + $collector->collect(); } return $collectedData; }
[ "public", "function", "collectData", "(", ")", "{", "$", "collectedData", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "dataCollectors", "as", "$", "collector", ")", "{", "$", "collectedData", "=", "$", "collectedData", "+", "$", "collector", "->", "collect", "(", ")", ";", "}", "return", "$", "collectedData", ";", "}" ]
Collects all data from data collectors. @return array
[ "Collects", "all", "data", "from", "data", "collectors", "." ]
54128903e7775e67d63284d958b46862c8df71f9
https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Templates/Renderers/TemplateRenderer.php#L309-L318
train
tarsana/syntax
src/NumberSyntax.php
NumberSyntax.instance
public static function instance() : NumberSyntax { if (self::$instance === null) self::$instance = new NumberSyntax; return self::$instance; }
php
public static function instance() : NumberSyntax { if (self::$instance === null) self::$instance = new NumberSyntax; return self::$instance; }
[ "public", "static", "function", "instance", "(", ")", ":", "NumberSyntax", "{", "if", "(", "self", "::", "$", "instance", "===", "null", ")", "self", "::", "$", "instance", "=", "new", "NumberSyntax", ";", "return", "self", "::", "$", "instance", ";", "}" ]
Returns the NumberSyntax instance. @return Tarsana\Syntax\NumberSyntax
[ "Returns", "the", "NumberSyntax", "instance", "." ]
fd3f8a25e3be0e391c8fd486ccfcffe913ade534
https://github.com/tarsana/syntax/blob/fd3f8a25e3be0e391c8fd486ccfcffe913ade534/src/NumberSyntax.php#L20-L25
train
Etenil/assegai
src/assegai/modules/mail/services/ses/sdk.class.php
CFRuntime.set_hostname
public function set_hostname($hostname, $port_number = null) { if ($this->override_hostname) { $this->hostname = $hostname; if ($port_number) { $this->port_number = $port_number; $this->hostname .= ':' . (string) $this->port_number; } } return $this; }
php
public function set_hostname($hostname, $port_number = null) { if ($this->override_hostname) { $this->hostname = $hostname; if ($port_number) { $this->port_number = $port_number; $this->hostname .= ':' . (string) $this->port_number; } } return $this; }
[ "public", "function", "set_hostname", "(", "$", "hostname", ",", "$", "port_number", "=", "null", ")", "{", "if", "(", "$", "this", "->", "override_hostname", ")", "{", "$", "this", "->", "hostname", "=", "$", "hostname", ";", "if", "(", "$", "port_number", ")", "{", "$", "this", "->", "port_number", "=", "$", "port_number", ";", "$", "this", "->", "hostname", ".=", "':'", ".", "(", "string", ")", "$", "this", "->", "port_number", ";", "}", "}", "return", "$", "this", ";", "}" ]
Set the hostname to connect to. This is useful for alternate services that are API-compatible with AWS, but run from a different hostname. @param string $hostname (Required) The alternate hostname to use in place of the default one. Useful for mock or test applications living on different hostnames. @param integer $port_number (Optional) The alternate port number to use in place of the default one. Useful for mock or test applications living on different port numbers. @return $this A reference to the current instance.
[ "Set", "the", "hostname", "to", "connect", "to", ".", "This", "is", "useful", "for", "alternate", "services", "that", "are", "API", "-", "compatible", "with", "AWS", "but", "run", "from", "a", "different", "hostname", "." ]
d43cce1a88f1c332f60dd0a4374b17764852af9e
https://github.com/Etenil/assegai/blob/d43cce1a88f1c332f60dd0a4374b17764852af9e/src/assegai/modules/mail/services/ses/sdk.class.php#L478-L492
train
Etenil/assegai
src/assegai/modules/mail/services/ses/sdk.class.php
CFRuntime.set_cache_config
public function set_cache_config($location, $gzip = true) { // If we have an array, we're probably passing in Memcached servers and ports. if (is_array($location)) { $this->cache_class = 'CacheMC'; } else { // I would expect locations like `/tmp/cache`, `pdo.mysql://user:pass@hostname:port`, `pdo.sqlite:memory:`, and `apc`. $type = strtolower(substr($location, 0, 3)); switch ($type) { case 'apc': $this->cache_class = 'CacheAPC'; break; case 'xca': // First three letters of `xcache` $this->cache_class = 'CacheXCache'; break; case 'pdo': $this->cache_class = 'CachePDO'; $location = substr($location, 4); break; default: $this->cache_class = 'CacheFile'; break; } } // Set the remaining cache information. $this->cache_location = $location; $this->cache_compress = $gzip; return $this; }
php
public function set_cache_config($location, $gzip = true) { // If we have an array, we're probably passing in Memcached servers and ports. if (is_array($location)) { $this->cache_class = 'CacheMC'; } else { // I would expect locations like `/tmp/cache`, `pdo.mysql://user:pass@hostname:port`, `pdo.sqlite:memory:`, and `apc`. $type = strtolower(substr($location, 0, 3)); switch ($type) { case 'apc': $this->cache_class = 'CacheAPC'; break; case 'xca': // First three letters of `xcache` $this->cache_class = 'CacheXCache'; break; case 'pdo': $this->cache_class = 'CachePDO'; $location = substr($location, 4); break; default: $this->cache_class = 'CacheFile'; break; } } // Set the remaining cache information. $this->cache_location = $location; $this->cache_compress = $gzip; return $this; }
[ "public", "function", "set_cache_config", "(", "$", "location", ",", "$", "gzip", "=", "true", ")", "{", "// If we have an array, we're probably passing in Memcached servers and ports.", "if", "(", "is_array", "(", "$", "location", ")", ")", "{", "$", "this", "->", "cache_class", "=", "'CacheMC'", ";", "}", "else", "{", "// I would expect locations like `/tmp/cache`, `pdo.mysql://user:pass@hostname:port`, `pdo.sqlite:memory:`, and `apc`.", "$", "type", "=", "strtolower", "(", "substr", "(", "$", "location", ",", "0", ",", "3", ")", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "'apc'", ":", "$", "this", "->", "cache_class", "=", "'CacheAPC'", ";", "break", ";", "case", "'xca'", ":", "// First three letters of `xcache`", "$", "this", "->", "cache_class", "=", "'CacheXCache'", ";", "break", ";", "case", "'pdo'", ":", "$", "this", "->", "cache_class", "=", "'CachePDO'", ";", "$", "location", "=", "substr", "(", "$", "location", ",", "4", ")", ";", "break", ";", "default", ":", "$", "this", "->", "cache_class", "=", "'CacheFile'", ";", "break", ";", "}", "}", "// Set the remaining cache information.", "$", "this", "->", "cache_location", "=", "$", "location", ";", "$", "this", "->", "cache_compress", "=", "$", "gzip", ";", "return", "$", "this", ";", "}" ]
Set the caching configuration to use for response caching. @param string $location (Required) <p>The location to store the cache object in. This may vary by cache method.</p><ul><li>File - The local file system paths such as <code>./cache</code> (relative) or <code>/tmp/cache/</code> (absolute). The location must be server-writable.</li><li>APC - Pass in <code>apc</code> to use this lightweight cache. You must have the <a href="http://php.net/apc">APC extension</a> installed.</li><li>XCache - Pass in <code>xcache</code> to use this lightweight cache. You must have the <a href="http://xcache.lighttpd.net">XCache</a> extension installed.</li><li>Memcached - Pass in an indexed array of associative arrays. Each associative array should have a <code>host</code> and a <code>port</code> value representing a <a href="http://php.net/memcached">Memcached</a> server to connect to.</li><li>PDO - A URL-style string (e.g. <code>pdo.mysql://user:pass@localhost/cache</code>) or a standard DSN-style string (e.g. <code>pdo.sqlite:/sqlite/cache.db</code>). MUST be prefixed with <code>pdo.</code>. See <code>CachePDO</code> and <a href="http://php.net/pdo">PDO</a> for more details.</li></ul> @param boolean $gzip (Optional) Whether or not data should be gzipped before being stored. A value of `true` will compress the contents before caching them. A value of `false` will leave the contents uncompressed. Defaults to `true`. @return $this A reference to the current instance.
[ "Set", "the", "caching", "configuration", "to", "use", "for", "response", "caching", "." ]
d43cce1a88f1c332f60dd0a4374b17764852af9e
https://github.com/Etenil/assegai/blob/d43cce1a88f1c332f60dd0a4374b17764852af9e/src/assegai/modules/mail/services/ses/sdk.class.php#L562-L599
train
Etenil/assegai
src/assegai/modules/mail/services/ses/sdk.class.php
CFRuntime.batch
public function batch(CFBatchRequest &$queue = null) { if ($queue) { $this->batch_object = $queue; } elseif ($this->internal_batch_object) { $this->batch_object = &$this->internal_batch_object; } else { $this->internal_batch_object = new $this->batch_class(); $this->batch_object = &$this->internal_batch_object; } $this->use_batch_flow = true; return $this; }
php
public function batch(CFBatchRequest &$queue = null) { if ($queue) { $this->batch_object = $queue; } elseif ($this->internal_batch_object) { $this->batch_object = &$this->internal_batch_object; } else { $this->internal_batch_object = new $this->batch_class(); $this->batch_object = &$this->internal_batch_object; } $this->use_batch_flow = true; return $this; }
[ "public", "function", "batch", "(", "CFBatchRequest", "&", "$", "queue", "=", "null", ")", "{", "if", "(", "$", "queue", ")", "{", "$", "this", "->", "batch_object", "=", "$", "queue", ";", "}", "elseif", "(", "$", "this", "->", "internal_batch_object", ")", "{", "$", "this", "->", "batch_object", "=", "&", "$", "this", "->", "internal_batch_object", ";", "}", "else", "{", "$", "this", "->", "internal_batch_object", "=", "new", "$", "this", "->", "batch_class", "(", ")", ";", "$", "this", "->", "batch_object", "=", "&", "$", "this", "->", "internal_batch_object", ";", "}", "$", "this", "->", "use_batch_flow", "=", "true", ";", "return", "$", "this", ";", "}" ]
Specifies that the intended request should be queued for a later batch request. @param CFBatchRequest $queue (Optional) The <CFBatchRequest> instance to use for managing batch requests. If not available, it generates a new instance of <CFBatchRequest>. @return $this A reference to the current instance.
[ "Specifies", "that", "the", "intended", "request", "should", "be", "queued", "for", "a", "later", "batch", "request", "." ]
d43cce1a88f1c332f60dd0a4374b17764852af9e
https://github.com/Etenil/assegai/blob/d43cce1a88f1c332f60dd0a4374b17764852af9e/src/assegai/modules/mail/services/ses/sdk.class.php#L1083-L1102
train
Etenil/assegai
src/assegai/modules/mail/services/ses/sdk.class.php
CFRuntime.send
public function send($clear_after_send = true) { if ($this->use_batch_flow) { // When we send the request, disable batch flow. $this->use_batch_flow = false; // If we're not caching, simply send the request. if (!$this->use_cache_flow) { $response = $this->batch_object->send(); $parsed_data = array_map(array($this, 'parse_callback'), $response); $parsed_data = new CFArray($parsed_data); // Clear the queue if ($clear_after_send) { $this->batch_object->queue = array(); } return $parsed_data; } // Generate an identifier specific to this particular set of arguments. $cache_id = $this->key . '_' . get_class($this) . '_' . sha1(serialize($this->batch_object)); // Instantiate the appropriate caching object. $this->cache_object = new $this->cache_class($cache_id, $this->cache_location, $this->cache_expires, $this->cache_compress); if ($this->delete_cache) { $this->use_cache_flow = false; $this->delete_cache = false; return $this->cache_object->delete(); } // Invoke the cache callback function to determine whether to pull data from the cache or make a fresh request. $data_set = $this->cache_object->response_manager(array($this, 'cache_callback_batch'), array($this->batch_object)); $parsed_data = array_map(array($this, 'parse_callback'), $data_set); $parsed_data = new CFArray($parsed_data); // Clear the queue if ($clear_after_send) { $this->batch_object->queue = array(); } // End! return $parsed_data; } // Load the class $null = new CFBatchRequest(); unset($null); throw new CFBatchRequest_Exception('You must use $object->batch()->send()'); }
php
public function send($clear_after_send = true) { if ($this->use_batch_flow) { // When we send the request, disable batch flow. $this->use_batch_flow = false; // If we're not caching, simply send the request. if (!$this->use_cache_flow) { $response = $this->batch_object->send(); $parsed_data = array_map(array($this, 'parse_callback'), $response); $parsed_data = new CFArray($parsed_data); // Clear the queue if ($clear_after_send) { $this->batch_object->queue = array(); } return $parsed_data; } // Generate an identifier specific to this particular set of arguments. $cache_id = $this->key . '_' . get_class($this) . '_' . sha1(serialize($this->batch_object)); // Instantiate the appropriate caching object. $this->cache_object = new $this->cache_class($cache_id, $this->cache_location, $this->cache_expires, $this->cache_compress); if ($this->delete_cache) { $this->use_cache_flow = false; $this->delete_cache = false; return $this->cache_object->delete(); } // Invoke the cache callback function to determine whether to pull data from the cache or make a fresh request. $data_set = $this->cache_object->response_manager(array($this, 'cache_callback_batch'), array($this->batch_object)); $parsed_data = array_map(array($this, 'parse_callback'), $data_set); $parsed_data = new CFArray($parsed_data); // Clear the queue if ($clear_after_send) { $this->batch_object->queue = array(); } // End! return $parsed_data; } // Load the class $null = new CFBatchRequest(); unset($null); throw new CFBatchRequest_Exception('You must use $object->batch()->send()'); }
[ "public", "function", "send", "(", "$", "clear_after_send", "=", "true", ")", "{", "if", "(", "$", "this", "->", "use_batch_flow", ")", "{", "// When we send the request, disable batch flow.", "$", "this", "->", "use_batch_flow", "=", "false", ";", "// If we're not caching, simply send the request.", "if", "(", "!", "$", "this", "->", "use_cache_flow", ")", "{", "$", "response", "=", "$", "this", "->", "batch_object", "->", "send", "(", ")", ";", "$", "parsed_data", "=", "array_map", "(", "array", "(", "$", "this", ",", "'parse_callback'", ")", ",", "$", "response", ")", ";", "$", "parsed_data", "=", "new", "CFArray", "(", "$", "parsed_data", ")", ";", "// Clear the queue", "if", "(", "$", "clear_after_send", ")", "{", "$", "this", "->", "batch_object", "->", "queue", "=", "array", "(", ")", ";", "}", "return", "$", "parsed_data", ";", "}", "// Generate an identifier specific to this particular set of arguments.", "$", "cache_id", "=", "$", "this", "->", "key", ".", "'_'", ".", "get_class", "(", "$", "this", ")", ".", "'_'", ".", "sha1", "(", "serialize", "(", "$", "this", "->", "batch_object", ")", ")", ";", "// Instantiate the appropriate caching object.", "$", "this", "->", "cache_object", "=", "new", "$", "this", "->", "cache_class", "(", "$", "cache_id", ",", "$", "this", "->", "cache_location", ",", "$", "this", "->", "cache_expires", ",", "$", "this", "->", "cache_compress", ")", ";", "if", "(", "$", "this", "->", "delete_cache", ")", "{", "$", "this", "->", "use_cache_flow", "=", "false", ";", "$", "this", "->", "delete_cache", "=", "false", ";", "return", "$", "this", "->", "cache_object", "->", "delete", "(", ")", ";", "}", "// Invoke the cache callback function to determine whether to pull data from the cache or make a fresh request.", "$", "data_set", "=", "$", "this", "->", "cache_object", "->", "response_manager", "(", "array", "(", "$", "this", ",", "'cache_callback_batch'", ")", ",", "array", "(", "$", "this", "->", "batch_object", ")", ")", ";", "$", "parsed_data", "=", "array_map", "(", "array", "(", "$", "this", ",", "'parse_callback'", ")", ",", "$", "data_set", ")", ";", "$", "parsed_data", "=", "new", "CFArray", "(", "$", "parsed_data", ")", ";", "// Clear the queue", "if", "(", "$", "clear_after_send", ")", "{", "$", "this", "->", "batch_object", "->", "queue", "=", "array", "(", ")", ";", "}", "// End!", "return", "$", "parsed_data", ";", "}", "// Load the class", "$", "null", "=", "new", "CFBatchRequest", "(", ")", ";", "unset", "(", "$", "null", ")", ";", "throw", "new", "CFBatchRequest_Exception", "(", "'You must use $object->batch()->send()'", ")", ";", "}" ]
Executes the batch request queue by sending all queued requests. @param boolean $clear_after_send (Optional) Whether or not to clear the batch queue after sending a request. Defaults to `true`. Set this to `false` if you are caching batch responses and want to retrieve results later. @return array An array of <CFResponse> objects.
[ "Executes", "the", "batch", "request", "queue", "by", "sending", "all", "queued", "requests", "." ]
d43cce1a88f1c332f60dd0a4374b17764852af9e
https://github.com/Etenil/assegai/blob/d43cce1a88f1c332f60dd0a4374b17764852af9e/src/assegai/modules/mail/services/ses/sdk.class.php#L1110-L1166
train
Etenil/assegai
src/assegai/modules/mail/services/ses/sdk.class.php
CFRuntime.parse_callback
public function parse_callback($response, $headers = null) { // Shorten this so we have a (mostly) single code path if (isset($response->body)) { if (is_string($response->body)) { $body = $response->body; } else { return $response; } } elseif (is_string($response)) { $body = $response; } else { return $response; } // Decompress gzipped content if (isset($headers['content-encoding'])) { switch (strtolower(trim($headers['content-encoding'], "\x09\x0A\x0D\x20"))) { case 'gzip': case 'x-gzip': if (strpos($headers['_info']['url'], 'monitoring.') !== false) { // CloudWatch incorrectly uses the deflate algorithm when they say gzip. if (($uncompressed = gzuncompress($body)) !== false) { $body = $uncompressed; } elseif (($uncompressed = gzinflate($body)) !== false) { $body = $uncompressed; } break; } else { // Everyone else uses gzip correctly. $decoder = new CFGzipDecode($body); if ($decoder->parse()) { $body = $decoder->data; } break; } case 'deflate': if (strpos($headers['_info']['url'], 'monitoring.') !== false) { // CloudWatch incorrectly does nothing when they say deflate. continue; } else { // Everyone else uses deflate correctly. if (($uncompressed = gzuncompress($body)) !== false) { $body = $uncompressed; } elseif (($uncompressed = gzinflate($body)) !== false) { $body = $uncompressed; } } break; } } // Look for XML cues if ( (isset($headers['content-type']) && ($headers['content-type'] === 'text/xml' || $headers['content-type'] === 'application/xml')) || // We know it's XML (!isset($headers['content-type']) && (stripos($body, '<?xml') === 0 || strpos($body, '<Error>') === 0) || preg_match('/^<(\w*) xmlns="http(s?):\/\/(\w*).amazon(aws)?.com/im', $body)) // Sniff for XML ) { // Strip the default XML namespace to simplify XPath expressions $body = str_replace("xmlns=", "ns=", $body); // Parse the XML body $body = new $this->parser_class($body); } // Look for JSON cues elseif ( (isset($headers['content-type']) && $headers['content-type'] === 'application/json') || // We know it's JSON (!isset($headers['content-type']) && $this->util->is_json($body)) // Sniff for JSON ) { // Normalize JSON to a CFSimpleXML object $body = CFJSON::to_xml($body); } // Put the parsed data back where it goes if (isset($response->body)) { $response->body = $body; } else { $response = $body; } return $response; }
php
public function parse_callback($response, $headers = null) { // Shorten this so we have a (mostly) single code path if (isset($response->body)) { if (is_string($response->body)) { $body = $response->body; } else { return $response; } } elseif (is_string($response)) { $body = $response; } else { return $response; } // Decompress gzipped content if (isset($headers['content-encoding'])) { switch (strtolower(trim($headers['content-encoding'], "\x09\x0A\x0D\x20"))) { case 'gzip': case 'x-gzip': if (strpos($headers['_info']['url'], 'monitoring.') !== false) { // CloudWatch incorrectly uses the deflate algorithm when they say gzip. if (($uncompressed = gzuncompress($body)) !== false) { $body = $uncompressed; } elseif (($uncompressed = gzinflate($body)) !== false) { $body = $uncompressed; } break; } else { // Everyone else uses gzip correctly. $decoder = new CFGzipDecode($body); if ($decoder->parse()) { $body = $decoder->data; } break; } case 'deflate': if (strpos($headers['_info']['url'], 'monitoring.') !== false) { // CloudWatch incorrectly does nothing when they say deflate. continue; } else { // Everyone else uses deflate correctly. if (($uncompressed = gzuncompress($body)) !== false) { $body = $uncompressed; } elseif (($uncompressed = gzinflate($body)) !== false) { $body = $uncompressed; } } break; } } // Look for XML cues if ( (isset($headers['content-type']) && ($headers['content-type'] === 'text/xml' || $headers['content-type'] === 'application/xml')) || // We know it's XML (!isset($headers['content-type']) && (stripos($body, '<?xml') === 0 || strpos($body, '<Error>') === 0) || preg_match('/^<(\w*) xmlns="http(s?):\/\/(\w*).amazon(aws)?.com/im', $body)) // Sniff for XML ) { // Strip the default XML namespace to simplify XPath expressions $body = str_replace("xmlns=", "ns=", $body); // Parse the XML body $body = new $this->parser_class($body); } // Look for JSON cues elseif ( (isset($headers['content-type']) && $headers['content-type'] === 'application/json') || // We know it's JSON (!isset($headers['content-type']) && $this->util->is_json($body)) // Sniff for JSON ) { // Normalize JSON to a CFSimpleXML object $body = CFJSON::to_xml($body); } // Put the parsed data back where it goes if (isset($response->body)) { $response->body = $body; } else { $response = $body; } return $response; }
[ "public", "function", "parse_callback", "(", "$", "response", ",", "$", "headers", "=", "null", ")", "{", "// Shorten this so we have a (mostly) single code path", "if", "(", "isset", "(", "$", "response", "->", "body", ")", ")", "{", "if", "(", "is_string", "(", "$", "response", "->", "body", ")", ")", "{", "$", "body", "=", "$", "response", "->", "body", ";", "}", "else", "{", "return", "$", "response", ";", "}", "}", "elseif", "(", "is_string", "(", "$", "response", ")", ")", "{", "$", "body", "=", "$", "response", ";", "}", "else", "{", "return", "$", "response", ";", "}", "// Decompress gzipped content", "if", "(", "isset", "(", "$", "headers", "[", "'content-encoding'", "]", ")", ")", "{", "switch", "(", "strtolower", "(", "trim", "(", "$", "headers", "[", "'content-encoding'", "]", ",", "\"\\x09\\x0A\\x0D\\x20\"", ")", ")", ")", "{", "case", "'gzip'", ":", "case", "'x-gzip'", ":", "if", "(", "strpos", "(", "$", "headers", "[", "'_info'", "]", "[", "'url'", "]", ",", "'monitoring.'", ")", "!==", "false", ")", "{", "// CloudWatch incorrectly uses the deflate algorithm when they say gzip.", "if", "(", "(", "$", "uncompressed", "=", "gzuncompress", "(", "$", "body", ")", ")", "!==", "false", ")", "{", "$", "body", "=", "$", "uncompressed", ";", "}", "elseif", "(", "(", "$", "uncompressed", "=", "gzinflate", "(", "$", "body", ")", ")", "!==", "false", ")", "{", "$", "body", "=", "$", "uncompressed", ";", "}", "break", ";", "}", "else", "{", "// Everyone else uses gzip correctly.", "$", "decoder", "=", "new", "CFGzipDecode", "(", "$", "body", ")", ";", "if", "(", "$", "decoder", "->", "parse", "(", ")", ")", "{", "$", "body", "=", "$", "decoder", "->", "data", ";", "}", "break", ";", "}", "case", "'deflate'", ":", "if", "(", "strpos", "(", "$", "headers", "[", "'_info'", "]", "[", "'url'", "]", ",", "'monitoring.'", ")", "!==", "false", ")", "{", "// CloudWatch incorrectly does nothing when they say deflate.", "continue", ";", "}", "else", "{", "// Everyone else uses deflate correctly.", "if", "(", "(", "$", "uncompressed", "=", "gzuncompress", "(", "$", "body", ")", ")", "!==", "false", ")", "{", "$", "body", "=", "$", "uncompressed", ";", "}", "elseif", "(", "(", "$", "uncompressed", "=", "gzinflate", "(", "$", "body", ")", ")", "!==", "false", ")", "{", "$", "body", "=", "$", "uncompressed", ";", "}", "}", "break", ";", "}", "}", "// Look for XML cues", "if", "(", "(", "isset", "(", "$", "headers", "[", "'content-type'", "]", ")", "&&", "(", "$", "headers", "[", "'content-type'", "]", "===", "'text/xml'", "||", "$", "headers", "[", "'content-type'", "]", "===", "'application/xml'", ")", ")", "||", "// We know it's XML", "(", "!", "isset", "(", "$", "headers", "[", "'content-type'", "]", ")", "&&", "(", "stripos", "(", "$", "body", ",", "'<?xml'", ")", "===", "0", "||", "strpos", "(", "$", "body", ",", "'<Error>'", ")", "===", "0", ")", "||", "preg_match", "(", "'/^<(\\w*) xmlns=\"http(s?):\\/\\/(\\w*).amazon(aws)?.com/im'", ",", "$", "body", ")", ")", "// Sniff for XML", ")", "{", "// Strip the default XML namespace to simplify XPath expressions", "$", "body", "=", "str_replace", "(", "\"xmlns=\"", ",", "\"ns=\"", ",", "$", "body", ")", ";", "// Parse the XML body", "$", "body", "=", "new", "$", "this", "->", "parser_class", "(", "$", "body", ")", ";", "}", "// Look for JSON cues", "elseif", "(", "(", "isset", "(", "$", "headers", "[", "'content-type'", "]", ")", "&&", "$", "headers", "[", "'content-type'", "]", "===", "'application/json'", ")", "||", "// We know it's JSON", "(", "!", "isset", "(", "$", "headers", "[", "'content-type'", "]", ")", "&&", "$", "this", "->", "util", "->", "is_json", "(", "$", "body", ")", ")", "// Sniff for JSON", ")", "{", "// Normalize JSON to a CFSimpleXML object", "$", "body", "=", "CFJSON", "::", "to_xml", "(", "$", "body", ")", ";", "}", "// Put the parsed data back where it goes", "if", "(", "isset", "(", "$", "response", "->", "body", ")", ")", "{", "$", "response", "->", "body", "=", "$", "body", ";", "}", "else", "{", "$", "response", "=", "$", "body", ";", "}", "return", "$", "response", ";", "}" ]
Parses a response body into a PHP object if appropriate. @param CFResponse|string $response (Required) The <CFResponse> object to parse, or an XML string that would otherwise be a response body. @param string $content_type (Optional) The content-type to use when determining how to parse the content. @return CFResponse|string A parsed <CFResponse> object, or parsed XML.
[ "Parses", "a", "response", "body", "into", "a", "PHP", "object", "if", "appropriate", "." ]
d43cce1a88f1c332f60dd0a4374b17764852af9e
https://github.com/Etenil/assegai/blob/d43cce1a88f1c332f60dd0a4374b17764852af9e/src/assegai/modules/mail/services/ses/sdk.class.php#L1175-L1284
train
Etenil/assegai
src/assegai/modules/mail/services/ses/sdk.class.php
CFLoader.autoloader
public static function autoloader($class) { $path = dirname(__FILE__) . DIRECTORY_SEPARATOR; // Amazon SDK classes if (strstr($class, 'Amazon')) { $path .= 'services' . DIRECTORY_SEPARATOR . str_ireplace('Amazon', '', strtolower($class)) . '.class.php'; } // Utility classes elseif (strstr($class, 'CF')) { $path .= 'utilities' . DIRECTORY_SEPARATOR . str_ireplace('CF', '', strtolower($class)) . '.class.php'; } // Load CacheCore elseif (strstr($class, 'Cache')) { if (file_exists($ipath = 'lib' . DIRECTORY_SEPARATOR . 'cachecore' . DIRECTORY_SEPARATOR . 'icachecore.interface.php')) { require_once($ipath); } $path .= 'lib' . DIRECTORY_SEPARATOR . 'cachecore' . DIRECTORY_SEPARATOR . strtolower($class) . '.class.php'; } // Load RequestCore elseif (strstr($class, 'RequestCore') || strstr($class, 'ResponseCore')) { $path .= 'lib' . DIRECTORY_SEPARATOR . 'requestcore' . DIRECTORY_SEPARATOR . 'requestcore.class.php'; } // Load Symfony YAML classes elseif (strstr($class, 'sfYaml')) { $path .= 'lib' . DIRECTORY_SEPARATOR . 'yaml' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'sfYaml.php'; } // Fall back to the 'extensions' directory. elseif (defined('AWS_ENABLE_EXTENSIONS') && AWS_ENABLE_EXTENSIONS) { $path .= 'extensions' . DIRECTORY_SEPARATOR . strtolower($class) . '.class.php'; } if (file_exists($path) && !is_dir($path)) { require_once($path); } }
php
public static function autoloader($class) { $path = dirname(__FILE__) . DIRECTORY_SEPARATOR; // Amazon SDK classes if (strstr($class, 'Amazon')) { $path .= 'services' . DIRECTORY_SEPARATOR . str_ireplace('Amazon', '', strtolower($class)) . '.class.php'; } // Utility classes elseif (strstr($class, 'CF')) { $path .= 'utilities' . DIRECTORY_SEPARATOR . str_ireplace('CF', '', strtolower($class)) . '.class.php'; } // Load CacheCore elseif (strstr($class, 'Cache')) { if (file_exists($ipath = 'lib' . DIRECTORY_SEPARATOR . 'cachecore' . DIRECTORY_SEPARATOR . 'icachecore.interface.php')) { require_once($ipath); } $path .= 'lib' . DIRECTORY_SEPARATOR . 'cachecore' . DIRECTORY_SEPARATOR . strtolower($class) . '.class.php'; } // Load RequestCore elseif (strstr($class, 'RequestCore') || strstr($class, 'ResponseCore')) { $path .= 'lib' . DIRECTORY_SEPARATOR . 'requestcore' . DIRECTORY_SEPARATOR . 'requestcore.class.php'; } // Load Symfony YAML classes elseif (strstr($class, 'sfYaml')) { $path .= 'lib' . DIRECTORY_SEPARATOR . 'yaml' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'sfYaml.php'; } // Fall back to the 'extensions' directory. elseif (defined('AWS_ENABLE_EXTENSIONS') && AWS_ENABLE_EXTENSIONS) { $path .= 'extensions' . DIRECTORY_SEPARATOR . strtolower($class) . '.class.php'; } if (file_exists($path) && !is_dir($path)) { require_once($path); } }
[ "public", "static", "function", "autoloader", "(", "$", "class", ")", "{", "$", "path", "=", "dirname", "(", "__FILE__", ")", ".", "DIRECTORY_SEPARATOR", ";", "// Amazon SDK classes", "if", "(", "strstr", "(", "$", "class", ",", "'Amazon'", ")", ")", "{", "$", "path", ".=", "'services'", ".", "DIRECTORY_SEPARATOR", ".", "str_ireplace", "(", "'Amazon'", ",", "''", ",", "strtolower", "(", "$", "class", ")", ")", ".", "'.class.php'", ";", "}", "// Utility classes", "elseif", "(", "strstr", "(", "$", "class", ",", "'CF'", ")", ")", "{", "$", "path", ".=", "'utilities'", ".", "DIRECTORY_SEPARATOR", ".", "str_ireplace", "(", "'CF'", ",", "''", ",", "strtolower", "(", "$", "class", ")", ")", ".", "'.class.php'", ";", "}", "// Load CacheCore", "elseif", "(", "strstr", "(", "$", "class", ",", "'Cache'", ")", ")", "{", "if", "(", "file_exists", "(", "$", "ipath", "=", "'lib'", ".", "DIRECTORY_SEPARATOR", ".", "'cachecore'", ".", "DIRECTORY_SEPARATOR", ".", "'icachecore.interface.php'", ")", ")", "{", "require_once", "(", "$", "ipath", ")", ";", "}", "$", "path", ".=", "'lib'", ".", "DIRECTORY_SEPARATOR", ".", "'cachecore'", ".", "DIRECTORY_SEPARATOR", ".", "strtolower", "(", "$", "class", ")", ".", "'.class.php'", ";", "}", "// Load RequestCore", "elseif", "(", "strstr", "(", "$", "class", ",", "'RequestCore'", ")", "||", "strstr", "(", "$", "class", ",", "'ResponseCore'", ")", ")", "{", "$", "path", ".=", "'lib'", ".", "DIRECTORY_SEPARATOR", ".", "'requestcore'", ".", "DIRECTORY_SEPARATOR", ".", "'requestcore.class.php'", ";", "}", "// Load Symfony YAML classes", "elseif", "(", "strstr", "(", "$", "class", ",", "'sfYaml'", ")", ")", "{", "$", "path", ".=", "'lib'", ".", "DIRECTORY_SEPARATOR", ".", "'yaml'", ".", "DIRECTORY_SEPARATOR", ".", "'lib'", ".", "DIRECTORY_SEPARATOR", ".", "'sfYaml.php'", ";", "}", "// Fall back to the 'extensions' directory.", "elseif", "(", "defined", "(", "'AWS_ENABLE_EXTENSIONS'", ")", "&&", "AWS_ENABLE_EXTENSIONS", ")", "{", "$", "path", ".=", "'extensions'", ".", "DIRECTORY_SEPARATOR", ".", "strtolower", "(", "$", "class", ")", ".", "'.class.php'", ";", "}", "if", "(", "file_exists", "(", "$", "path", ")", "&&", "!", "is_dir", "(", "$", "path", ")", ")", "{", "require_once", "(", "$", "path", ")", ";", "}", "}" ]
Automatically load classes that aren't included. @param string $class (Required) The classname to load. @return void
[ "Automatically", "load", "classes", "that", "aren", "t", "included", "." ]
d43cce1a88f1c332f60dd0a4374b17764852af9e
https://github.com/Etenil/assegai/blob/d43cce1a88f1c332f60dd0a4374b17764852af9e/src/assegai/modules/mail/services/ses/sdk.class.php#L1391-L1440
train
IftekherSunny/Planet-Framework
src/Sun/Http/Response.php
Response.html
public function html($data) { if(is_array($data)) { echo $this->json($data); } else { echo $data; } if($this->app->config('session.enable')) { $this->session->create('previous_uri', $_SERVER['REQUEST_URI']); $this->session->create('planet_oldInput', null); } }
php
public function html($data) { if(is_array($data)) { echo $this->json($data); } else { echo $data; } if($this->app->config('session.enable')) { $this->session->create('previous_uri', $_SERVER['REQUEST_URI']); $this->session->create('planet_oldInput', null); } }
[ "public", "function", "html", "(", "$", "data", ")", "{", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "echo", "$", "this", "->", "json", "(", "$", "data", ")", ";", "}", "else", "{", "echo", "$", "data", ";", "}", "if", "(", "$", "this", "->", "app", "->", "config", "(", "'session.enable'", ")", ")", "{", "$", "this", "->", "session", "->", "create", "(", "'previous_uri'", ",", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", ";", "$", "this", "->", "session", "->", "create", "(", "'planet_oldInput'", ",", "null", ")", ";", "}", "}" ]
To response with html @param string $data
[ "To", "response", "with", "html" ]
530e772fb97695c1c4e1af73f81675f189474d9f
https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Http/Response.php#L39-L51
train
IftekherSunny/Planet-Framework
src/Sun/Http/Response.php
Response.json
public function json($data, $status = 200) { $this->header('Content-Type: application/json'); $this->statusCode($status); return json_encode($data); }
php
public function json($data, $status = 200) { $this->header('Content-Type: application/json'); $this->statusCode($status); return json_encode($data); }
[ "public", "function", "json", "(", "$", "data", ",", "$", "status", "=", "200", ")", "{", "$", "this", "->", "header", "(", "'Content-Type: application/json'", ")", ";", "$", "this", "->", "statusCode", "(", "$", "status", ")", ";", "return", "json_encode", "(", "$", "data", ")", ";", "}" ]
To response with json @param string $data @param int $status @return string
[ "To", "response", "with", "json" ]
530e772fb97695c1c4e1af73f81675f189474d9f
https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Http/Response.php#L61-L68
train
IftekherSunny/Planet-Framework
src/Sun/Http/Response.php
Response.download
public function download($path, $removeDownloadedFile = false) { if(!file_exists($path)) { throw new Exception("File [ $path ] not found."); } $filename = pathinfo($path, PATHINFO_BASENAME ); header("Content-Description: File Transfer"); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"$filename\""); @readfile($path); if($removeDownloadedFile) { @unlink($path); } }
php
public function download($path, $removeDownloadedFile = false) { if(!file_exists($path)) { throw new Exception("File [ $path ] not found."); } $filename = pathinfo($path, PATHINFO_BASENAME ); header("Content-Description: File Transfer"); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"$filename\""); @readfile($path); if($removeDownloadedFile) { @unlink($path); } }
[ "public", "function", "download", "(", "$", "path", ",", "$", "removeDownloadedFile", "=", "false", ")", "{", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "throw", "new", "Exception", "(", "\"File [ $path ] not found.\"", ")", ";", "}", "$", "filename", "=", "pathinfo", "(", "$", "path", ",", "PATHINFO_BASENAME", ")", ";", "header", "(", "\"Content-Description: File Transfer\"", ")", ";", "header", "(", "\"Content-Type: application/octet-stream\"", ")", ";", "header", "(", "\"Content-Disposition: attachment; filename=\\\"$filename\\\"\"", ")", ";", "@", "readfile", "(", "$", "path", ")", ";", "if", "(", "$", "removeDownloadedFile", ")", "{", "@", "unlink", "(", "$", "path", ")", ";", "}", "}" ]
Http Response to download file @param string $path @param bool $removeDownloadedFile @throws Exception
[ "Http", "Response", "to", "download", "file" ]
530e772fb97695c1c4e1af73f81675f189474d9f
https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Http/Response.php#L78-L95
train
acacha/forge-publish
src/Console/Commands/PublishDeploymentScript.php
PublishDeploymentScript.updateDeploymentScript
protected function updateDeploymentScript() { $this->info('Updating deployment script for site ' . $this->site . '...'); $this->url = $this->obtainAPIURLEndpoint('update_deployment_script_uri'); if (! File::exists($this->file)) { $this->error("File " . $this->file . " doesn't exists"); die(); } $this->http->put($this->url, [ 'form_params' => [ 'content' => file_get_contents($this->file) ], 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest', 'Authorization' => 'Bearer ' . fp_env('ACACHA_FORGE_ACCESS_TOKEN') ] ] ); }
php
protected function updateDeploymentScript() { $this->info('Updating deployment script for site ' . $this->site . '...'); $this->url = $this->obtainAPIURLEndpoint('update_deployment_script_uri'); if (! File::exists($this->file)) { $this->error("File " . $this->file . " doesn't exists"); die(); } $this->http->put($this->url, [ 'form_params' => [ 'content' => file_get_contents($this->file) ], 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest', 'Authorization' => 'Bearer ' . fp_env('ACACHA_FORGE_ACCESS_TOKEN') ] ] ); }
[ "protected", "function", "updateDeploymentScript", "(", ")", "{", "$", "this", "->", "info", "(", "'Updating deployment script for site '", ".", "$", "this", "->", "site", ".", "'...'", ")", ";", "$", "this", "->", "url", "=", "$", "this", "->", "obtainAPIURLEndpoint", "(", "'update_deployment_script_uri'", ")", ";", "if", "(", "!", "File", "::", "exists", "(", "$", "this", "->", "file", ")", ")", "{", "$", "this", "->", "error", "(", "\"File \"", ".", "$", "this", "->", "file", ".", "\" doesn't exists\"", ")", ";", "die", "(", ")", ";", "}", "$", "this", "->", "http", "->", "put", "(", "$", "this", "->", "url", ",", "[", "'form_params'", "=>", "[", "'content'", "=>", "file_get_contents", "(", "$", "this", "->", "file", ")", "]", ",", "'headers'", "=>", "[", "'X-Requested-With'", "=>", "'XMLHttpRequest'", ",", "'Authorization'", "=>", "'Bearer '", ".", "fp_env", "(", "'ACACHA_FORGE_ACCESS_TOKEN'", ")", "]", "]", ")", ";", "}" ]
Update deployment script.
[ "Update", "deployment", "script", "." ]
010779e3d2297c763b82dc3fbde992edffb3a6c6
https://github.com/acacha/forge-publish/blob/010779e3d2297c763b82dc3fbde992edffb3a6c6/src/Console/Commands/PublishDeploymentScript.php#L109-L130
train
acacha/forge-publish
src/Console/Commands/PublishDeploymentScript.php
PublishDeploymentScript.obtainAPIURLEndpoint
protected function obtainAPIURLEndpoint($type) { $uri = str_replace('{forgeserver}', $this->server, config('forge-publish.' . $type)); $uri = str_replace('{forgesite}', $this->site, $uri); return config('forge-publish.url') . $uri; }
php
protected function obtainAPIURLEndpoint($type) { $uri = str_replace('{forgeserver}', $this->server, config('forge-publish.' . $type)); $uri = str_replace('{forgesite}', $this->site, $uri); return config('forge-publish.url') . $uri; }
[ "protected", "function", "obtainAPIURLEndpoint", "(", "$", "type", ")", "{", "$", "uri", "=", "str_replace", "(", "'{forgeserver}'", ",", "$", "this", "->", "server", ",", "config", "(", "'forge-publish.'", ".", "$", "type", ")", ")", ";", "$", "uri", "=", "str_replace", "(", "'{forgesite}'", ",", "$", "this", "->", "site", ",", "$", "uri", ")", ";", "return", "config", "(", "'forge-publish.url'", ")", ".", "$", "uri", ";", "}" ]
Obtain API URL endpoint. @return string
[ "Obtain", "API", "URL", "endpoint", "." ]
010779e3d2297c763b82dc3fbde992edffb3a6c6
https://github.com/acacha/forge-publish/blob/010779e3d2297c763b82dc3fbde992edffb3a6c6/src/Console/Commands/PublishDeploymentScript.php#L137-L142
train
makinacorpus/drupal-calista
src/EventDispatcher/ViewEventSubscriber.php
ViewEventSubscriber.onTwigView
public function onTwigView(ViewEvent $event) { $view = $event->getView(); if (function_exists('drupal_add_library') && $view instanceof TwigView) { drupal_add_library('calista', 'calista_page'); /* if ($event->getView()->visualSearchIsEnabled()) { drupal_add_library('calista', 'calista_search'); } */ } }
php
public function onTwigView(ViewEvent $event) { $view = $event->getView(); if (function_exists('drupal_add_library') && $view instanceof TwigView) { drupal_add_library('calista', 'calista_page'); /* if ($event->getView()->visualSearchIsEnabled()) { drupal_add_library('calista', 'calista_search'); } */ } }
[ "public", "function", "onTwigView", "(", "ViewEvent", "$", "event", ")", "{", "$", "view", "=", "$", "event", "->", "getView", "(", ")", ";", "if", "(", "function_exists", "(", "'drupal_add_library'", ")", "&&", "$", "view", "instanceof", "TwigView", ")", "{", "drupal_add_library", "(", "'calista'", ",", "'calista_page'", ")", ";", "/*\n if ($event->getView()->visualSearchIsEnabled()) {\n drupal_add_library('calista', 'calista_search');\n }\n */", "}", "}" ]
Add JS libraries @param ViewEvent $event
[ "Add", "JS", "libraries" ]
cceb6b975fc3e80f0f83c803fc6f6a9ac5852b53
https://github.com/makinacorpus/drupal-calista/blob/cceb6b975fc3e80f0f83c803fc6f6a9ac5852b53/src/EventDispatcher/ViewEventSubscriber.php#L31-L43
train
infusephp/auth
src/Jobs/GarbageCollection.php
GarbageCollection.run
public function run() { $res1 = $this->gcPersistent(); $res2 = $this->gcUserLinks(); $res3 = $this->gcActive(); return $res1 && $res2 && $res3; }
php
public function run() { $res1 = $this->gcPersistent(); $res2 = $this->gcUserLinks(); $res3 = $this->gcActive(); return $res1 && $res2 && $res3; }
[ "public", "function", "run", "(", ")", "{", "$", "res1", "=", "$", "this", "->", "gcPersistent", "(", ")", ";", "$", "res2", "=", "$", "this", "->", "gcUserLinks", "(", ")", ";", "$", "res3", "=", "$", "this", "->", "gcActive", "(", ")", ";", "return", "$", "res1", "&&", "$", "res2", "&&", "$", "res3", ";", "}" ]
Runs the auth garbage collection. @return array
[ "Runs", "the", "auth", "garbage", "collection", "." ]
720280b4b2635572f331afe8d082e3e88cf54eb7
https://github.com/infusephp/auth/blob/720280b4b2635572f331afe8d082e3e88cf54eb7/src/Jobs/GarbageCollection.php#L33-L40
train
infusephp/auth
src/Jobs/GarbageCollection.php
GarbageCollection.gcPersistent
private function gcPersistent() { return (bool) $this->app['database']->getDefault() ->delete('PersistentSessions') ->where('created_at', U::unixToDb(time() - PersistentSession::$sessionLength), '<') ->execute(); }
php
private function gcPersistent() { return (bool) $this->app['database']->getDefault() ->delete('PersistentSessions') ->where('created_at', U::unixToDb(time() - PersistentSession::$sessionLength), '<') ->execute(); }
[ "private", "function", "gcPersistent", "(", ")", "{", "return", "(", "bool", ")", "$", "this", "->", "app", "[", "'database'", "]", "->", "getDefault", "(", ")", "->", "delete", "(", "'PersistentSessions'", ")", "->", "where", "(", "'created_at'", ",", "U", "::", "unixToDb", "(", "time", "(", ")", "-", "PersistentSession", "::", "$", "sessionLength", ")", ",", "'<'", ")", "->", "execute", "(", ")", ";", "}" ]
Clears out expired persistent sessions. @return bool
[ "Clears", "out", "expired", "persistent", "sessions", "." ]
720280b4b2635572f331afe8d082e3e88cf54eb7
https://github.com/infusephp/auth/blob/720280b4b2635572f331afe8d082e3e88cf54eb7/src/Jobs/GarbageCollection.php#L60-L66
train
infusephp/auth
src/Jobs/GarbageCollection.php
GarbageCollection.gcUserLinks
private function gcUserLinks() { return (bool) $this->app['database']->getDefault() ->delete('UserLinks') ->where('type', UserLink::FORGOT_PASSWORD) ->where('created_at', U::unixToDb(time() - UserLink::$forgotLinkTimeframe), '<') ->execute(); }
php
private function gcUserLinks() { return (bool) $this->app['database']->getDefault() ->delete('UserLinks') ->where('type', UserLink::FORGOT_PASSWORD) ->where('created_at', U::unixToDb(time() - UserLink::$forgotLinkTimeframe), '<') ->execute(); }
[ "private", "function", "gcUserLinks", "(", ")", "{", "return", "(", "bool", ")", "$", "this", "->", "app", "[", "'database'", "]", "->", "getDefault", "(", ")", "->", "delete", "(", "'UserLinks'", ")", "->", "where", "(", "'type'", ",", "UserLink", "::", "FORGOT_PASSWORD", ")", "->", "where", "(", "'created_at'", ",", "U", "::", "unixToDb", "(", "time", "(", ")", "-", "UserLink", "::", "$", "forgotLinkTimeframe", ")", ",", "'<'", ")", "->", "execute", "(", ")", ";", "}" ]
Clears out expired user links. @return bool
[ "Clears", "out", "expired", "user", "links", "." ]
720280b4b2635572f331afe8d082e3e88cf54eb7
https://github.com/infusephp/auth/blob/720280b4b2635572f331afe8d082e3e88cf54eb7/src/Jobs/GarbageCollection.php#L73-L80
train
andyburton/Sonic-Framework
src/Resource/Session.php
Session.singleton
public static function singleton ($sessionID = FALSE) { // If no instance is set if (self::$_instance === FALSE) { // Create an instance self::$_instance = new static ($sessionID); } // Return instance return self::$_instance; }
php
public static function singleton ($sessionID = FALSE) { // If no instance is set if (self::$_instance === FALSE) { // Create an instance self::$_instance = new static ($sessionID); } // Return instance return self::$_instance; }
[ "public", "static", "function", "singleton", "(", "$", "sessionID", "=", "FALSE", ")", "{", "// If no instance is set", "if", "(", "self", "::", "$", "_instance", "===", "FALSE", ")", "{", "// Create an instance", "self", "::", "$", "_instance", "=", "new", "static", "(", "$", "sessionID", ")", ";", "}", "// Return instance", "return", "self", "::", "$", "_instance", ";", "}" ]
Return a single object instance @param string $sessionID Session ID @return \Sonic\Resource\Session
[ "Return", "a", "single", "object", "instance" ]
a5999448a0abab4d542413002a780ede391e7374
https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/Session.php#L78-L96
train
x2ts/x2ts
src/db/SQLite.php
SQLite.query
public function query(string $sql, array $params = []) { X::logger()->trace("$sql with params " . $this->serializeArray($params)); try { $st = $this->pdo->prepare($sql); if ($st === false) { $e = $this->pdo->errorInfo(); throw new DataBaseException($e[2], $e[1]); } if ($st->execute($params)) { $this->_affectedRows = $st->rowCount(); $this->_lastInsertId = $this->pdo->lastInsertId(); return $st->fetchAll(PDO::FETCH_ASSOC); } $e = $st->errorInfo(); throw new DataBaseException($e[2], $e[1]); } catch (PDOException $ex) { X::logger()->trace($ex); throw new DataBaseException($ex->getMessage(), $ex->getCode()); } }
php
public function query(string $sql, array $params = []) { X::logger()->trace("$sql with params " . $this->serializeArray($params)); try { $st = $this->pdo->prepare($sql); if ($st === false) { $e = $this->pdo->errorInfo(); throw new DataBaseException($e[2], $e[1]); } if ($st->execute($params)) { $this->_affectedRows = $st->rowCount(); $this->_lastInsertId = $this->pdo->lastInsertId(); return $st->fetchAll(PDO::FETCH_ASSOC); } $e = $st->errorInfo(); throw new DataBaseException($e[2], $e[1]); } catch (PDOException $ex) { X::logger()->trace($ex); throw new DataBaseException($ex->getMessage(), $ex->getCode()); } }
[ "public", "function", "query", "(", "string", "$", "sql", ",", "array", "$", "params", "=", "[", "]", ")", "{", "X", "::", "logger", "(", ")", "->", "trace", "(", "\"$sql with params \"", ".", "$", "this", "->", "serializeArray", "(", "$", "params", ")", ")", ";", "try", "{", "$", "st", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "sql", ")", ";", "if", "(", "$", "st", "===", "false", ")", "{", "$", "e", "=", "$", "this", "->", "pdo", "->", "errorInfo", "(", ")", ";", "throw", "new", "DataBaseException", "(", "$", "e", "[", "2", "]", ",", "$", "e", "[", "1", "]", ")", ";", "}", "if", "(", "$", "st", "->", "execute", "(", "$", "params", ")", ")", "{", "$", "this", "->", "_affectedRows", "=", "$", "st", "->", "rowCount", "(", ")", ";", "$", "this", "->", "_lastInsertId", "=", "$", "this", "->", "pdo", "->", "lastInsertId", "(", ")", ";", "return", "$", "st", "->", "fetchAll", "(", "PDO", "::", "FETCH_ASSOC", ")", ";", "}", "$", "e", "=", "$", "st", "->", "errorInfo", "(", ")", ";", "throw", "new", "DataBaseException", "(", "$", "e", "[", "2", "]", ",", "$", "e", "[", "1", "]", ")", ";", "}", "catch", "(", "PDOException", "$", "ex", ")", "{", "X", "::", "logger", "(", ")", "->", "trace", "(", "$", "ex", ")", ";", "throw", "new", "DataBaseException", "(", "$", "ex", "->", "getMessage", "(", ")", ",", "$", "ex", "->", "getCode", "(", ")", ")", ";", "}", "}" ]
run sql and return the result @param string $sql @param array $params @throws DataBaseException @return array
[ "run", "sql", "and", "return", "the", "result" ]
65e43952ab940ab05696a34d31a1c3ab91545090
https://github.com/x2ts/x2ts/blob/65e43952ab940ab05696a34d31a1c3ab91545090/src/db/SQLite.php#L62-L82
train
3ev/wordpress-core
src/Tev/Author/Model/Author.php
Author.getAvatarTag
public function getAvatarTag($size = 96, $alt = null) { return get_avatar($this->getId(), $size, null, $alt ?: $this->getDisplayName()); }
php
public function getAvatarTag($size = 96, $alt = null) { return get_avatar($this->getId(), $size, null, $alt ?: $this->getDisplayName()); }
[ "public", "function", "getAvatarTag", "(", "$", "size", "=", "96", ",", "$", "alt", "=", "null", ")", "{", "return", "get_avatar", "(", "$", "this", "->", "getId", "(", ")", ",", "$", "size", ",", "null", ",", "$", "alt", "?", ":", "$", "this", "->", "getDisplayName", "(", ")", ")", ";", "}" ]
Get an image tag for this author's avatar. @param int $size Avatar size. Max 512, default 96 @param string $alt Alt text. Defaults to display name @return string
[ "Get", "an", "image", "tag", "for", "this", "author", "s", "avatar", "." ]
da674fbec5bf3d5bd2a2141680a4c141113eb6b0
https://github.com/3ev/wordpress-core/blob/da674fbec5bf3d5bd2a2141680a4c141113eb6b0/src/Tev/Author/Model/Author.php#L142-L145
train
tarsana/syntax
src/ArraySyntax.php
ArraySyntax.syntax
public function syntax(Syntax $value = null) : Syntax { if (null === $value) { return $this->syntax; } $this->syntax = $value; return $this; }
php
public function syntax(Syntax $value = null) : Syntax { if (null === $value) { return $this->syntax; } $this->syntax = $value; return $this; }
[ "public", "function", "syntax", "(", "Syntax", "$", "value", "=", "null", ")", ":", "Syntax", "{", "if", "(", "null", "===", "$", "value", ")", "{", "return", "$", "this", "->", "syntax", ";", "}", "$", "this", "->", "syntax", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Item syntax getter and setter. @param Tarsana\Syntax\Syntax $value @return Tarsana\Syntax\Syntax
[ "Item", "syntax", "getter", "and", "setter", "." ]
fd3f8a25e3be0e391c8fd486ccfcffe913ade534
https://github.com/tarsana/syntax/blob/fd3f8a25e3be0e391c8fd486ccfcffe913ade534/src/ArraySyntax.php#L49-L56
train
tarsana/syntax
src/ArraySyntax.php
ArraySyntax.separator
public function separator(string $value = null) { if (null === $value) { return $this->separator; } $this->separator = $value; return $this; }
php
public function separator(string $value = null) { if (null === $value) { return $this->separator; } $this->separator = $value; return $this; }
[ "public", "function", "separator", "(", "string", "$", "value", "=", "null", ")", "{", "if", "(", "null", "===", "$", "value", ")", "{", "return", "$", "this", "->", "separator", ";", "}", "$", "this", "->", "separator", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Separator getter and setter. @param string $value @return self|string
[ "Separator", "getter", "and", "setter", "." ]
fd3f8a25e3be0e391c8fd486ccfcffe913ade534
https://github.com/tarsana/syntax/blob/fd3f8a25e3be0e391c8fd486ccfcffe913ade534/src/ArraySyntax.php#L64-L71
train
tarsana/syntax
src/ArraySyntax.php
ArraySyntax.parse
public function parse(string $text) : array { $index = 0; $items = Text::split($text, $this->separator); $array = []; try { foreach ($items as $item) { $array[] = $this->syntax->parse($item); $index += strlen($item) + 1; } } catch (ParseException $e) { $extra = [ 'type' => 'invalid-item', 'item' => $item, 'position' => $e->position() ]; throw new ParseException($this, $text, $index + $e->position(), "Unable to parse the item '{$item}'", $extra, $e ); } return $array; }
php
public function parse(string $text) : array { $index = 0; $items = Text::split($text, $this->separator); $array = []; try { foreach ($items as $item) { $array[] = $this->syntax->parse($item); $index += strlen($item) + 1; } } catch (ParseException $e) { $extra = [ 'type' => 'invalid-item', 'item' => $item, 'position' => $e->position() ]; throw new ParseException($this, $text, $index + $e->position(), "Unable to parse the item '{$item}'", $extra, $e ); } return $array; }
[ "public", "function", "parse", "(", "string", "$", "text", ")", ":", "array", "{", "$", "index", "=", "0", ";", "$", "items", "=", "Text", "::", "split", "(", "$", "text", ",", "$", "this", "->", "separator", ")", ";", "$", "array", "=", "[", "]", ";", "try", "{", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "array", "[", "]", "=", "$", "this", "->", "syntax", "->", "parse", "(", "$", "item", ")", ";", "$", "index", "+=", "strlen", "(", "$", "item", ")", "+", "1", ";", "}", "}", "catch", "(", "ParseException", "$", "e", ")", "{", "$", "extra", "=", "[", "'type'", "=>", "'invalid-item'", ",", "'item'", "=>", "$", "item", ",", "'position'", "=>", "$", "e", "->", "position", "(", ")", "]", ";", "throw", "new", "ParseException", "(", "$", "this", ",", "$", "text", ",", "$", "index", "+", "$", "e", "->", "position", "(", ")", ",", "\"Unable to parse the item '{$item}'\"", ",", "$", "extra", ",", "$", "e", ")", ";", "}", "return", "$", "array", ";", "}" ]
Transforms a string to array based on the syntax or throws a ParseException. @param string $text the string to parse @return array @throws Tarsana\Syntax\Exceptions\ParseException
[ "Transforms", "a", "string", "to", "array", "based", "on", "the", "syntax", "or", "throws", "a", "ParseException", "." ]
fd3f8a25e3be0e391c8fd486ccfcffe913ade534
https://github.com/tarsana/syntax/blob/fd3f8a25e3be0e391c8fd486ccfcffe913ade534/src/ArraySyntax.php#L92-L114
train
tarsana/syntax
src/ArraySyntax.php
ArraySyntax.dump
public function dump($values) : string { if (! is_array($values)) throw new DumpException($this, $values, self::ERROR); $items = []; $index = 0; try { foreach ($values as $key => $value) { $index = $key; $items[] = $this->syntax->dump($value); } } catch (DumpException $e) { throw new DumpException($this, $values, "Unable to dump item at key {$index}", [], $e); } return Text::join($items, $this->separator); }
php
public function dump($values) : string { if (! is_array($values)) throw new DumpException($this, $values, self::ERROR); $items = []; $index = 0; try { foreach ($values as $key => $value) { $index = $key; $items[] = $this->syntax->dump($value); } } catch (DumpException $e) { throw new DumpException($this, $values, "Unable to dump item at key {$index}", [], $e); } return Text::join($items, $this->separator); }
[ "public", "function", "dump", "(", "$", "values", ")", ":", "string", "{", "if", "(", "!", "is_array", "(", "$", "values", ")", ")", "throw", "new", "DumpException", "(", "$", "this", ",", "$", "values", ",", "self", "::", "ERROR", ")", ";", "$", "items", "=", "[", "]", ";", "$", "index", "=", "0", ";", "try", "{", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "index", "=", "$", "key", ";", "$", "items", "[", "]", "=", "$", "this", "->", "syntax", "->", "dump", "(", "$", "value", ")", ";", "}", "}", "catch", "(", "DumpException", "$", "e", ")", "{", "throw", "new", "DumpException", "(", "$", "this", ",", "$", "values", ",", "\"Unable to dump item at key {$index}\"", ",", "[", "]", ",", "$", "e", ")", ";", "}", "return", "Text", "::", "join", "(", "$", "items", ",", "$", "this", "->", "separator", ")", ";", "}" ]
Converts the given array to a string based on the syntax or throws a DumpException. @param array $values the data to encode @return string @throws Tarsana\Syntax\Exceptions\DumpException
[ "Converts", "the", "given", "array", "to", "a", "string", "based", "on", "the", "syntax", "or", "throws", "a", "DumpException", "." ]
fd3f8a25e3be0e391c8fd486ccfcffe913ade534
https://github.com/tarsana/syntax/blob/fd3f8a25e3be0e391c8fd486ccfcffe913ade534/src/ArraySyntax.php#L125-L141
train
payapi/payapi-sdk-php
src/payapi/core/core.controller.php
controller.settings
protected function settings($key = false) { if ($this->settings == false) { return false; } if ($key == false) { return $this->settings; } if (isset($this->settings[$key])) { return $this->settings[$key]; } return false; }
php
protected function settings($key = false) { if ($this->settings == false) { return false; } if ($key == false) { return $this->settings; } if (isset($this->settings[$key])) { return $this->settings[$key]; } return false; }
[ "protected", "function", "settings", "(", "$", "key", "=", "false", ")", "{", "if", "(", "$", "this", "->", "settings", "==", "false", ")", "{", "return", "false", ";", "}", "if", "(", "$", "key", "==", "false", ")", "{", "return", "$", "this", "->", "settings", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "settings", "[", "$", "key", "]", ")", ")", "{", "return", "$", "this", "->", "settings", "[", "$", "key", "]", ";", "}", "return", "false", ";", "}" ]
-> merchantSettings
[ "-", ">", "merchantSettings" ]
6a675749c88742b261178d7977f2436d540132b4
https://github.com/payapi/payapi-sdk-php/blob/6a675749c88742b261178d7977f2436d540132b4/src/payapi/core/core.controller.php#L231-L243
train
as3io/modlr
src/Rest/RestKernel.php
RestKernel.handle
public function handle(Request $request) { try { $restRequest = new RestRequest($this->config, $request->getMethod(), $request->getUri(), $request->getContent()); $restResponse = $this->adapter->processRequest($restRequest); } catch (\Exception $e) { if (true === $this->debugEnabled()) { throw $e; } $restResponse = $this->adapter->handleException($e); } return new Response($restResponse->getContent(), $restResponse->getStatus(), $restResponse->getHeaders()); }
php
public function handle(Request $request) { try { $restRequest = new RestRequest($this->config, $request->getMethod(), $request->getUri(), $request->getContent()); $restResponse = $this->adapter->processRequest($restRequest); } catch (\Exception $e) { if (true === $this->debugEnabled()) { throw $e; } $restResponse = $this->adapter->handleException($e); } return new Response($restResponse->getContent(), $restResponse->getStatus(), $restResponse->getHeaders()); }
[ "public", "function", "handle", "(", "Request", "$", "request", ")", "{", "try", "{", "$", "restRequest", "=", "new", "RestRequest", "(", "$", "this", "->", "config", ",", "$", "request", "->", "getMethod", "(", ")", ",", "$", "request", "->", "getUri", "(", ")", ",", "$", "request", "->", "getContent", "(", ")", ")", ";", "$", "restResponse", "=", "$", "this", "->", "adapter", "->", "processRequest", "(", "$", "restRequest", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "true", "===", "$", "this", "->", "debugEnabled", "(", ")", ")", "{", "throw", "$", "e", ";", "}", "$", "restResponse", "=", "$", "this", "->", "adapter", "->", "handleException", "(", "$", "e", ")", ";", "}", "return", "new", "Response", "(", "$", "restResponse", "->", "getContent", "(", ")", ",", "$", "restResponse", "->", "getStatus", "(", ")", ",", "$", "restResponse", "->", "getHeaders", "(", ")", ")", ";", "}" ]
Processes an incoming Request object, routes it to the adapter, and returns a response. @param Request $request @return Response $response
[ "Processes", "an", "incoming", "Request", "object", "routes", "it", "to", "the", "adapter", "and", "returns", "a", "response", "." ]
7e684b88bb22a2e18397df9402075c6533084b16
https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Rest/RestKernel.php#L62-L74
train
weavephp/container-league
src/League.php
League.loadContainer
protected function loadContainer(array $config = [], $environment = null) { $this->container = new Container; $this->configureContainerInternal(); $this->configureContainer($this->container, $config, $environment); return $this->container->get('instantiator'); }
php
protected function loadContainer(array $config = [], $environment = null) { $this->container = new Container; $this->configureContainerInternal(); $this->configureContainer($this->container, $config, $environment); return $this->container->get('instantiator'); }
[ "protected", "function", "loadContainer", "(", "array", "$", "config", "=", "[", "]", ",", "$", "environment", "=", "null", ")", "{", "$", "this", "->", "container", "=", "new", "Container", ";", "$", "this", "->", "configureContainerInternal", "(", ")", ";", "$", "this", "->", "configureContainer", "(", "$", "this", "->", "container", ",", "$", "config", ",", "$", "environment", ")", ";", "return", "$", "this", "->", "container", "->", "get", "(", "'instantiator'", ")", ";", "}" ]
Setup the Dependency Injection Container @param array $config Optional config array as provided from loadConfig(). @param string $environment Optional indication of the runtime environment. @return callable A callable that can instantiate instances of classes from the DIC.
[ "Setup", "the", "Dependency", "Injection", "Container" ]
14227536569eccd8376b38429e7762a4caebe282
https://github.com/weavephp/container-league/blob/14227536569eccd8376b38429e7762a4caebe282/src/League.php#L31-L37
train
weavephp/container-league
src/League.php
League.configureContainerInternal
protected function configureContainerInternal() { $this->container->add( 'instantiator', function () { return function ($name) { return $this->container->get($name); }; } ); $this->container->add(\Weave\Middleware\Middleware::class) ->withArgument(\Weave\Middleware\MiddlewareAdaptorInterface::class) ->withArgument( function ($pipelineName) { return $this->provideMiddlewarePipeline($pipelineName); } ) ->withArgument(\Weave\Resolve\ResolveAdaptorInterface::class) ->withArgument(\Weave\Dispatch\DispatchAdaptorInterface::class) ->withArgument(\Weave\Http\RequestFactoryInterface::class) ->withArgument(\Weave\Http\ResponseFactoryInterface::class) ->withArgument(\Weave\Http\ResponseEmitterInterface::class); $this->container->add( \Weave\Resolve\ResolveAdaptorInterface::class, \Weave\Resolve\Resolve::class ) ->withArgument('instantiator'); $this->container->add( \Weave\Dispatch\DispatchAdaptorInterface::class, \Weave\Dispatch\Dispatch::class ); $this->container->add(\Weave\Middleware\Dispatch::class) ->withArgument(\Weave\Resolve\ResolveAdaptorInterface::class) ->withArgument(\Weave\Dispatch\DispatchAdaptorInterface::class); $this->container->add(\Weave\Router\Router::class) ->withArgument(\Weave\Router\RouterAdaptorInterface::class) ->withArgument( function ($router) { return $this->provideRouteConfiguration($router); } ) ->withArgument(\Weave\Resolve\ResolveAdaptorInterface::class) ->withArgument(\Weave\Dispatch\DispatchAdaptorInterface::class); }
php
protected function configureContainerInternal() { $this->container->add( 'instantiator', function () { return function ($name) { return $this->container->get($name); }; } ); $this->container->add(\Weave\Middleware\Middleware::class) ->withArgument(\Weave\Middleware\MiddlewareAdaptorInterface::class) ->withArgument( function ($pipelineName) { return $this->provideMiddlewarePipeline($pipelineName); } ) ->withArgument(\Weave\Resolve\ResolveAdaptorInterface::class) ->withArgument(\Weave\Dispatch\DispatchAdaptorInterface::class) ->withArgument(\Weave\Http\RequestFactoryInterface::class) ->withArgument(\Weave\Http\ResponseFactoryInterface::class) ->withArgument(\Weave\Http\ResponseEmitterInterface::class); $this->container->add( \Weave\Resolve\ResolveAdaptorInterface::class, \Weave\Resolve\Resolve::class ) ->withArgument('instantiator'); $this->container->add( \Weave\Dispatch\DispatchAdaptorInterface::class, \Weave\Dispatch\Dispatch::class ); $this->container->add(\Weave\Middleware\Dispatch::class) ->withArgument(\Weave\Resolve\ResolveAdaptorInterface::class) ->withArgument(\Weave\Dispatch\DispatchAdaptorInterface::class); $this->container->add(\Weave\Router\Router::class) ->withArgument(\Weave\Router\RouterAdaptorInterface::class) ->withArgument( function ($router) { return $this->provideRouteConfiguration($router); } ) ->withArgument(\Weave\Resolve\ResolveAdaptorInterface::class) ->withArgument(\Weave\Dispatch\DispatchAdaptorInterface::class); }
[ "protected", "function", "configureContainerInternal", "(", ")", "{", "$", "this", "->", "container", "->", "add", "(", "'instantiator'", ",", "function", "(", ")", "{", "return", "function", "(", "$", "name", ")", "{", "return", "$", "this", "->", "container", "->", "get", "(", "$", "name", ")", ";", "}", ";", "}", ")", ";", "$", "this", "->", "container", "->", "add", "(", "\\", "Weave", "\\", "Middleware", "\\", "Middleware", "::", "class", ")", "->", "withArgument", "(", "\\", "Weave", "\\", "Middleware", "\\", "MiddlewareAdaptorInterface", "::", "class", ")", "->", "withArgument", "(", "function", "(", "$", "pipelineName", ")", "{", "return", "$", "this", "->", "provideMiddlewarePipeline", "(", "$", "pipelineName", ")", ";", "}", ")", "->", "withArgument", "(", "\\", "Weave", "\\", "Resolve", "\\", "ResolveAdaptorInterface", "::", "class", ")", "->", "withArgument", "(", "\\", "Weave", "\\", "Dispatch", "\\", "DispatchAdaptorInterface", "::", "class", ")", "->", "withArgument", "(", "\\", "Weave", "\\", "Http", "\\", "RequestFactoryInterface", "::", "class", ")", "->", "withArgument", "(", "\\", "Weave", "\\", "Http", "\\", "ResponseFactoryInterface", "::", "class", ")", "->", "withArgument", "(", "\\", "Weave", "\\", "Http", "\\", "ResponseEmitterInterface", "::", "class", ")", ";", "$", "this", "->", "container", "->", "add", "(", "\\", "Weave", "\\", "Resolve", "\\", "ResolveAdaptorInterface", "::", "class", ",", "\\", "Weave", "\\", "Resolve", "\\", "Resolve", "::", "class", ")", "->", "withArgument", "(", "'instantiator'", ")", ";", "$", "this", "->", "container", "->", "add", "(", "\\", "Weave", "\\", "Dispatch", "\\", "DispatchAdaptorInterface", "::", "class", ",", "\\", "Weave", "\\", "Dispatch", "\\", "Dispatch", "::", "class", ")", ";", "$", "this", "->", "container", "->", "add", "(", "\\", "Weave", "\\", "Middleware", "\\", "Dispatch", "::", "class", ")", "->", "withArgument", "(", "\\", "Weave", "\\", "Resolve", "\\", "ResolveAdaptorInterface", "::", "class", ")", "->", "withArgument", "(", "\\", "Weave", "\\", "Dispatch", "\\", "DispatchAdaptorInterface", "::", "class", ")", ";", "$", "this", "->", "container", "->", "add", "(", "\\", "Weave", "\\", "Router", "\\", "Router", "::", "class", ")", "->", "withArgument", "(", "\\", "Weave", "\\", "Router", "\\", "RouterAdaptorInterface", "::", "class", ")", "->", "withArgument", "(", "function", "(", "$", "router", ")", "{", "return", "$", "this", "->", "provideRouteConfiguration", "(", "$", "router", ")", ";", "}", ")", "->", "withArgument", "(", "\\", "Weave", "\\", "Resolve", "\\", "ResolveAdaptorInterface", "::", "class", ")", "->", "withArgument", "(", "\\", "Weave", "\\", "Dispatch", "\\", "DispatchAdaptorInterface", "::", "class", ")", ";", "}" ]
Configure's the internal Weave requirements. @return null
[ "Configure", "s", "the", "internal", "Weave", "requirements", "." ]
14227536569eccd8376b38429e7762a4caebe282
https://github.com/weavephp/container-league/blob/14227536569eccd8376b38429e7762a4caebe282/src/League.php#L55-L103
train
wandersonwhcr/illuminate-romans
src/Providers/RomansProvider.php
RomansProvider.register
public function register() { $this->app->singleton(Grammar::class); $this->app->singleton(Lexer::class); $this->app->singleton(Parser::class); $this->app->singleton(IntToRomanFilter::class); $this->app->singleton(RomanToIntFilter::class); $this->app->resolving(RomanToIntFilter::class, function ($element, $app) { $element->setLexer($app->make(Lexer::class)); $element->setParser($app->make(Parser::class)); return $element; }); $this->app->alias(IntToRomanFilter::class, 'intToRoman'); $this->app->alias(RomanToIntFilter::class, 'romanToInt'); }
php
public function register() { $this->app->singleton(Grammar::class); $this->app->singleton(Lexer::class); $this->app->singleton(Parser::class); $this->app->singleton(IntToRomanFilter::class); $this->app->singleton(RomanToIntFilter::class); $this->app->resolving(RomanToIntFilter::class, function ($element, $app) { $element->setLexer($app->make(Lexer::class)); $element->setParser($app->make(Parser::class)); return $element; }); $this->app->alias(IntToRomanFilter::class, 'intToRoman'); $this->app->alias(RomanToIntFilter::class, 'romanToInt'); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "Grammar", "::", "class", ")", ";", "$", "this", "->", "app", "->", "singleton", "(", "Lexer", "::", "class", ")", ";", "$", "this", "->", "app", "->", "singleton", "(", "Parser", "::", "class", ")", ";", "$", "this", "->", "app", "->", "singleton", "(", "IntToRomanFilter", "::", "class", ")", ";", "$", "this", "->", "app", "->", "singleton", "(", "RomanToIntFilter", "::", "class", ")", ";", "$", "this", "->", "app", "->", "resolving", "(", "RomanToIntFilter", "::", "class", ",", "function", "(", "$", "element", ",", "$", "app", ")", "{", "$", "element", "->", "setLexer", "(", "$", "app", "->", "make", "(", "Lexer", "::", "class", ")", ")", ";", "$", "element", "->", "setParser", "(", "$", "app", "->", "make", "(", "Parser", "::", "class", ")", ")", ";", "return", "$", "element", ";", "}", ")", ";", "$", "this", "->", "app", "->", "alias", "(", "IntToRomanFilter", "::", "class", ",", "'intToRoman'", ")", ";", "$", "this", "->", "app", "->", "alias", "(", "RomanToIntFilter", "::", "class", ",", "'romanToInt'", ")", ";", "}" ]
Register Romans Services @return void
[ "Register", "Romans", "Services" ]
7025e39c633cb30a10eff27c7cfa756ce91026a6
https://github.com/wandersonwhcr/illuminate-romans/blob/7025e39c633cb30a10eff27c7cfa756ce91026a6/src/Providers/RomansProvider.php#L41-L60
train
mover-io/belt
lib/Text.php
Text.shellColor
static public function shellColor($color, $string, $conditional=true) { if(!$conditional) { return $string; } $color = self::shellColorCode($color); return $color.$string.self::shellColorCode('plain'); }
php
static public function shellColor($color, $string, $conditional=true) { if(!$conditional) { return $string; } $color = self::shellColorCode($color); return $color.$string.self::shellColorCode('plain'); }
[ "static", "public", "function", "shellColor", "(", "$", "color", ",", "$", "string", ",", "$", "conditional", "=", "true", ")", "{", "if", "(", "!", "$", "conditional", ")", "{", "return", "$", "string", ";", "}", "$", "color", "=", "self", "::", "shellColorCode", "(", "$", "color", ")", ";", "return", "$", "color", ".", "$", "string", ".", "self", "::", "shellColorCode", "(", "'plain'", ")", ";", "}" ]
Wraps string in bash shell color escape sequences for the provided color. @param $color string|integer If a string is provided, we lookup the colors using the $colors table in the function body below. For precise control, an integer will yield a precise color code. @param $string string The string to colorize. @param $conditional A flag parameter which may be passed in to transparently enable/disable colorization. @return The colorized string.
[ "Wraps", "string", "in", "bash", "shell", "color", "escape", "sequences", "for", "the", "provided", "color", "." ]
c966a70aa0f4eb51be55bbb86c89b1e85b773d68
https://github.com/mover-io/belt/blob/c966a70aa0f4eb51be55bbb86c89b1e85b773d68/lib/Text.php#L136-L142
train
mover-io/belt
lib/Text.php
Text.fromCamel
static public function fromCamel($str) { $str[0] = strtolower($str[0]); return preg_replace_callback('/([A-Z])/', function($char) {return "_" . strtolower($char[1]);}, $str); }
php
static public function fromCamel($str) { $str[0] = strtolower($str[0]); return preg_replace_callback('/([A-Z])/', function($char) {return "_" . strtolower($char[1]);}, $str); }
[ "static", "public", "function", "fromCamel", "(", "$", "str", ")", "{", "$", "str", "[", "0", "]", "=", "strtolower", "(", "$", "str", "[", "0", "]", ")", ";", "return", "preg_replace_callback", "(", "'/([A-Z])/'", ",", "function", "(", "$", "char", ")", "{", "return", "\"_\"", ".", "strtolower", "(", "$", "char", "[", "1", "]", ")", ";", "}", ",", "$", "str", ")", ";", "}" ]
Converts camel-case to corresponding underscores. @param $str @example helloWorld -> hello_world @return string
[ "Converts", "camel", "-", "case", "to", "corresponding", "underscores", "." ]
c966a70aa0f4eb51be55bbb86c89b1e85b773d68
https://github.com/mover-io/belt/blob/c966a70aa0f4eb51be55bbb86c89b1e85b773d68/lib/Text.php#L213-L216
train
mover-io/belt
lib/Text.php
Text.toCamel
static public function toCamel($str, $capitalise_first_char = false) { if($capitalise_first_char) { $str[0] = strtoupper($str[0]); } return preg_replace_callback('/_([a-z])/',function($char) {return strtoupper($char[1]);}, $str); }
php
static public function toCamel($str, $capitalise_first_char = false) { if($capitalise_first_char) { $str[0] = strtoupper($str[0]); } return preg_replace_callback('/_([a-z])/',function($char) {return strtoupper($char[1]);}, $str); }
[ "static", "public", "function", "toCamel", "(", "$", "str", ",", "$", "capitalise_first_char", "=", "false", ")", "{", "if", "(", "$", "capitalise_first_char", ")", "{", "$", "str", "[", "0", "]", "=", "strtoupper", "(", "$", "str", "[", "0", "]", ")", ";", "}", "return", "preg_replace_callback", "(", "'/_([a-z])/'", ",", "function", "(", "$", "char", ")", "{", "return", "strtoupper", "(", "$", "char", "[", "1", "]", ")", ";", "}", ",", "$", "str", ")", ";", "}" ]
Converts underscores to a corresponding camel-case string. @param $str @param $capitalise_first_char @example this_is_a_test -> thisIsATest @return string
[ "Converts", "underscores", "to", "a", "corresponding", "camel", "-", "case", "string", "." ]
c966a70aa0f4eb51be55bbb86c89b1e85b773d68
https://github.com/mover-io/belt/blob/c966a70aa0f4eb51be55bbb86c89b1e85b773d68/lib/Text.php#L227-L232
train
feelinc/laravel-api
src/Sule/Api/OAuth2/Repositories/FluentSession.php
FluentSession.deleteSession
public function deleteSession($clientId, $ownerType, $ownerId) { DB::table('oauth_sessions') ->where('client_id', $clientId) ->where('owner_type', $ownerType) ->where('owner_id', $ownerId) ->delete(); }
php
public function deleteSession($clientId, $ownerType, $ownerId) { DB::table('oauth_sessions') ->where('client_id', $clientId) ->where('owner_type', $ownerType) ->where('owner_id', $ownerId) ->delete(); }
[ "public", "function", "deleteSession", "(", "$", "clientId", ",", "$", "ownerType", ",", "$", "ownerId", ")", "{", "DB", "::", "table", "(", "'oauth_sessions'", ")", "->", "where", "(", "'client_id'", ",", "$", "clientId", ")", "->", "where", "(", "'owner_type'", ",", "$", "ownerType", ")", "->", "where", "(", "'owner_id'", ",", "$", "ownerId", ")", "->", "delete", "(", ")", ";", "}" ]
Delete a session Example SQL query: <code> DELETE FROM oauth_sessions WHERE client_id = :clientId AND owner_type = :type AND owner_id = :typeId </code> @param string $clientId The client ID @param string $ownerType The type of the session owner (e.g. "user") @param string $ownerId The ID of the session owner (e.g. "123") @return void
[ "Delete", "a", "session" ]
8b4abc4f1be255b441e09f5014e863a130c666d8
https://github.com/feelinc/laravel-api/blob/8b4abc4f1be255b441e09f5014e863a130c666d8/src/Sule/Api/OAuth2/Repositories/FluentSession.php#L60-L67
train
feelinc/laravel-api
src/Sule/Api/OAuth2/Repositories/FluentSession.php
FluentSession.associateRedirectUri
public function associateRedirectUri($sessionId, $redirectUri) { DB::table('oauth_session_redirects')->insert(array( 'session_id' => $sessionId, 'redirect_uri' => $redirectUri, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now() )); }
php
public function associateRedirectUri($sessionId, $redirectUri) { DB::table('oauth_session_redirects')->insert(array( 'session_id' => $sessionId, 'redirect_uri' => $redirectUri, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now() )); }
[ "public", "function", "associateRedirectUri", "(", "$", "sessionId", ",", "$", "redirectUri", ")", "{", "DB", "::", "table", "(", "'oauth_session_redirects'", ")", "->", "insert", "(", "array", "(", "'session_id'", "=>", "$", "sessionId", ",", "'redirect_uri'", "=>", "$", "redirectUri", ",", "'created_at'", "=>", "Carbon", "::", "now", "(", ")", ",", "'updated_at'", "=>", "Carbon", "::", "now", "(", ")", ")", ")", ";", "}" ]
Associate a redirect URI with a session Example SQL query: <code> INSERT INTO oauth_session_redirects (session_id, redirect_uri) VALUE (:sessionId, :redirectUri) </code> @param int $sessionId The session ID @param string $redirectUri The redirect URI @return void
[ "Associate", "a", "redirect", "URI", "with", "a", "session" ]
8b4abc4f1be255b441e09f5014e863a130c666d8
https://github.com/feelinc/laravel-api/blob/8b4abc4f1be255b441e09f5014e863a130c666d8/src/Sule/Api/OAuth2/Repositories/FluentSession.php#L82-L90
train
feelinc/laravel-api
src/Sule/Api/OAuth2/Repositories/FluentSession.php
FluentSession.associateAccessToken
public function associateAccessToken($sessionId, $accessToken, $expireTime) { return DB::table('oauth_session_access_tokens')->insertGetId(array( 'session_id' => $sessionId, 'access_token' => $accessToken, 'access_token_expires' => $expireTime, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now() )); }
php
public function associateAccessToken($sessionId, $accessToken, $expireTime) { return DB::table('oauth_session_access_tokens')->insertGetId(array( 'session_id' => $sessionId, 'access_token' => $accessToken, 'access_token_expires' => $expireTime, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now() )); }
[ "public", "function", "associateAccessToken", "(", "$", "sessionId", ",", "$", "accessToken", ",", "$", "expireTime", ")", "{", "return", "DB", "::", "table", "(", "'oauth_session_access_tokens'", ")", "->", "insertGetId", "(", "array", "(", "'session_id'", "=>", "$", "sessionId", ",", "'access_token'", "=>", "$", "accessToken", ",", "'access_token_expires'", "=>", "$", "expireTime", ",", "'created_at'", "=>", "Carbon", "::", "now", "(", ")", ",", "'updated_at'", "=>", "Carbon", "::", "now", "(", ")", ")", ")", ";", "}" ]
Associate an access token with a session Example SQL query: <code> INSERT INTO oauth_session_access_tokens (session_id, access_token, access_token_expires) VALUE (:sessionId, :accessToken, :accessTokenExpire) </code> @param int $sessionId The session ID @param string $accessToken The access token @param int $expireTime Unix timestamp of the access token expiry time @return void
[ "Associate", "an", "access", "token", "with", "a", "session" ]
8b4abc4f1be255b441e09f5014e863a130c666d8
https://github.com/feelinc/laravel-api/blob/8b4abc4f1be255b441e09f5014e863a130c666d8/src/Sule/Api/OAuth2/Repositories/FluentSession.php#L107-L116
train
feelinc/laravel-api
src/Sule/Api/OAuth2/Repositories/FluentSession.php
FluentSession.associateRefreshToken
public function associateRefreshToken($accessTokenId, $refreshToken, $expireTime, $clientId) { DB::table('oauth_session_refresh_tokens')->insert(array( 'session_access_token_id' => $accessTokenId, 'refresh_token' => $refreshToken, 'refresh_token_expires' => $expireTime, 'client_id' => $clientId, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now() )); }
php
public function associateRefreshToken($accessTokenId, $refreshToken, $expireTime, $clientId) { DB::table('oauth_session_refresh_tokens')->insert(array( 'session_access_token_id' => $accessTokenId, 'refresh_token' => $refreshToken, 'refresh_token_expires' => $expireTime, 'client_id' => $clientId, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now() )); }
[ "public", "function", "associateRefreshToken", "(", "$", "accessTokenId", ",", "$", "refreshToken", ",", "$", "expireTime", ",", "$", "clientId", ")", "{", "DB", "::", "table", "(", "'oauth_session_refresh_tokens'", ")", "->", "insert", "(", "array", "(", "'session_access_token_id'", "=>", "$", "accessTokenId", ",", "'refresh_token'", "=>", "$", "refreshToken", ",", "'refresh_token_expires'", "=>", "$", "expireTime", ",", "'client_id'", "=>", "$", "clientId", ",", "'created_at'", "=>", "Carbon", "::", "now", "(", ")", ",", "'updated_at'", "=>", "Carbon", "::", "now", "(", ")", ")", ")", ";", "}" ]
Associate a refresh token with a session Example SQL query: <code> INSERT INTO oauth_session_refresh_tokens (session_access_token_id, refresh_token, refresh_token_expires, client_id) VALUE (:accessTokenId, :refreshToken, :expireTime, :clientId) </code> @param int $accessTokenId The access token ID @param string $refreshToken The refresh token @param int $expireTime Unix timestamp of the refresh token expiry time @param string $clientId The client ID @return void
[ "Associate", "a", "refresh", "token", "with", "a", "session" ]
8b4abc4f1be255b441e09f5014e863a130c666d8
https://github.com/feelinc/laravel-api/blob/8b4abc4f1be255b441e09f5014e863a130c666d8/src/Sule/Api/OAuth2/Repositories/FluentSession.php#L134-L144
train
feelinc/laravel-api
src/Sule/Api/OAuth2/Repositories/FluentSession.php
FluentSession.associateAuthCode
public function associateAuthCode($sessionId, $authCode, $expireTime) { $id = DB::table('oauth_session_authcodes')->insertGetId(array( 'session_id' => $sessionId, 'auth_code' => $authCode, 'auth_code_expires' => $expireTime, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now() )); return $id; }
php
public function associateAuthCode($sessionId, $authCode, $expireTime) { $id = DB::table('oauth_session_authcodes')->insertGetId(array( 'session_id' => $sessionId, 'auth_code' => $authCode, 'auth_code_expires' => $expireTime, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now() )); return $id; }
[ "public", "function", "associateAuthCode", "(", "$", "sessionId", ",", "$", "authCode", ",", "$", "expireTime", ")", "{", "$", "id", "=", "DB", "::", "table", "(", "'oauth_session_authcodes'", ")", "->", "insertGetId", "(", "array", "(", "'session_id'", "=>", "$", "sessionId", ",", "'auth_code'", "=>", "$", "authCode", ",", "'auth_code_expires'", "=>", "$", "expireTime", ",", "'created_at'", "=>", "Carbon", "::", "now", "(", ")", ",", "'updated_at'", "=>", "Carbon", "::", "now", "(", ")", ")", ")", ";", "return", "$", "id", ";", "}" ]
Assocate an authorization code with a session Example SQL query: <code> INSERT INTO oauth_session_authcodes (session_id, auth_code, auth_code_expires) VALUE (:sessionId, :authCode, :authCodeExpires) </code> @param int $sessionId The session ID @param string $authCode The authorization code @param int $expireTime Unix timestamp of the access token expiry time @return int The auth code ID
[ "Assocate", "an", "authorization", "code", "with", "a", "session" ]
8b4abc4f1be255b441e09f5014e863a130c666d8
https://github.com/feelinc/laravel-api/blob/8b4abc4f1be255b441e09f5014e863a130c666d8/src/Sule/Api/OAuth2/Repositories/FluentSession.php#L161-L172
train
feelinc/laravel-api
src/Sule/Api/OAuth2/Repositories/FluentSession.php
FluentSession.validateAuthCode
public function validateAuthCode($clientId, $redirectUri, $authCode) { $result = DB::table('oauth_sessions') ->select('oauth_sessions.id as session_id', 'oauth_session_authcodes.id as authcode_id') ->join('oauth_session_authcodes', 'oauth_sessions.id', '=', 'oauth_session_authcodes.session_id') ->join('oauth_session_redirects', 'oauth_sessions.id', '=', 'oauth_session_redirects.session_id') ->where('oauth_sessions.client_id', $clientId) ->where('oauth_session_authcodes.auth_code', $authCode) ->where('oauth_session_authcodes.auth_code_expires', '>=', time()) ->where('oauth_session_redirects.redirect_uri', $redirectUri) ->first(); return (is_null($result)) ? false : (array) $result; }
php
public function validateAuthCode($clientId, $redirectUri, $authCode) { $result = DB::table('oauth_sessions') ->select('oauth_sessions.id as session_id', 'oauth_session_authcodes.id as authcode_id') ->join('oauth_session_authcodes', 'oauth_sessions.id', '=', 'oauth_session_authcodes.session_id') ->join('oauth_session_redirects', 'oauth_sessions.id', '=', 'oauth_session_redirects.session_id') ->where('oauth_sessions.client_id', $clientId) ->where('oauth_session_authcodes.auth_code', $authCode) ->where('oauth_session_authcodes.auth_code_expires', '>=', time()) ->where('oauth_session_redirects.redirect_uri', $redirectUri) ->first(); return (is_null($result)) ? false : (array) $result; }
[ "public", "function", "validateAuthCode", "(", "$", "clientId", ",", "$", "redirectUri", ",", "$", "authCode", ")", "{", "$", "result", "=", "DB", "::", "table", "(", "'oauth_sessions'", ")", "->", "select", "(", "'oauth_sessions.id as session_id'", ",", "'oauth_session_authcodes.id as authcode_id'", ")", "->", "join", "(", "'oauth_session_authcodes'", ",", "'oauth_sessions.id'", ",", "'='", ",", "'oauth_session_authcodes.session_id'", ")", "->", "join", "(", "'oauth_session_redirects'", ",", "'oauth_sessions.id'", ",", "'='", ",", "'oauth_session_redirects.session_id'", ")", "->", "where", "(", "'oauth_sessions.client_id'", ",", "$", "clientId", ")", "->", "where", "(", "'oauth_session_authcodes.auth_code'", ",", "$", "authCode", ")", "->", "where", "(", "'oauth_session_authcodes.auth_code_expires'", ",", "'>='", ",", "time", "(", ")", ")", "->", "where", "(", "'oauth_session_redirects.redirect_uri'", ",", "$", "redirectUri", ")", "->", "first", "(", ")", ";", "return", "(", "is_null", "(", "$", "result", ")", ")", "?", "false", ":", "(", "array", ")", "$", "result", ";", "}" ]
Validate an authorization code Example SQL query: <code> SELECT oauth_sessions.id AS session_id, oauth_session_authcodes.id AS authcode_id FROM oauth_sessions JOIN oauth_session_authcodes ON oauth_session_authcodes.`session_id` = oauth_sessions.id JOIN oauth_session_redirects ON oauth_session_redirects.`session_id` = oauth_sessions.id WHERE oauth_sessions.client_id = :clientId AND oauth_session_authcodes.`auth_code` = :authCode AND `oauth_session_authcodes`.`auth_code_expires` >= :time AND `oauth_session_redirects`.`redirect_uri` = :redirectUri </code> Expected response: <code> array( 'session_id' => (int) 'authcode_id' => (int) ) </code> @param string $clientId The client ID @param string $redirectUri The redirect URI @param string $authCode The authorization code @return array|bool False if invalid or array as above
[ "Validate", "an", "authorization", "code" ]
8b4abc4f1be255b441e09f5014e863a130c666d8
https://github.com/feelinc/laravel-api/blob/8b4abc4f1be255b441e09f5014e863a130c666d8/src/Sule/Api/OAuth2/Repositories/FluentSession.php#L221-L234
train
feelinc/laravel-api
src/Sule/Api/OAuth2/Repositories/FluentSession.php
FluentSession.validateAccessToken
public function validateAccessToken($accessToken) { $result = DB::table('oauth_session_access_tokens') ->select('oauth_session_access_tokens.session_id as session_id', 'oauth_sessions.client_id as client_id', 'oauth_clients.secret as client_secret', 'oauth_sessions.owner_id as owner_id', 'oauth_sessions.owner_type as owner_type') ->join('oauth_sessions', 'oauth_session_access_tokens.session_id', '=', 'oauth_sessions.id') ->join('oauth_clients', 'oauth_sessions.client_id', '=', 'oauth_clients.id') ->where('access_token', $accessToken) ->where('access_token_expires', '>=', time()) ->first(); return (is_null($result)) ? false : (array) $result; }
php
public function validateAccessToken($accessToken) { $result = DB::table('oauth_session_access_tokens') ->select('oauth_session_access_tokens.session_id as session_id', 'oauth_sessions.client_id as client_id', 'oauth_clients.secret as client_secret', 'oauth_sessions.owner_id as owner_id', 'oauth_sessions.owner_type as owner_type') ->join('oauth_sessions', 'oauth_session_access_tokens.session_id', '=', 'oauth_sessions.id') ->join('oauth_clients', 'oauth_sessions.client_id', '=', 'oauth_clients.id') ->where('access_token', $accessToken) ->where('access_token_expires', '>=', time()) ->first(); return (is_null($result)) ? false : (array) $result; }
[ "public", "function", "validateAccessToken", "(", "$", "accessToken", ")", "{", "$", "result", "=", "DB", "::", "table", "(", "'oauth_session_access_tokens'", ")", "->", "select", "(", "'oauth_session_access_tokens.session_id as session_id'", ",", "'oauth_sessions.client_id as client_id'", ",", "'oauth_clients.secret as client_secret'", ",", "'oauth_sessions.owner_id as owner_id'", ",", "'oauth_sessions.owner_type as owner_type'", ")", "->", "join", "(", "'oauth_sessions'", ",", "'oauth_session_access_tokens.session_id'", ",", "'='", ",", "'oauth_sessions.id'", ")", "->", "join", "(", "'oauth_clients'", ",", "'oauth_sessions.client_id'", ",", "'='", ",", "'oauth_clients.id'", ")", "->", "where", "(", "'access_token'", ",", "$", "accessToken", ")", "->", "where", "(", "'access_token_expires'", ",", "'>='", ",", "time", "(", ")", ")", "->", "first", "(", ")", ";", "return", "(", "is_null", "(", "$", "result", ")", ")", "?", "false", ":", "(", "array", ")", "$", "result", ";", "}" ]
Validate an access token Example SQL query: <code> SELECT session_id, oauth_sessions.`client_id`, oauth_sessions.`owner_id`, oauth_sessions.`owner_type` FROM `oauth_session_access_tokens` JOIN oauth_sessions ON oauth_sessions.`id` = session_id WHERE access_token = :accessToken AND access_token_expires >= UNIX_TIMESTAMP(NOW()) </code> Expected response: <code> array( 'session_id' => (int), 'client_id' => (string), 'owner_id' => (string), 'owner_type' => (string) ) </code> @param string $accessToken The access token @return array|bool False if invalid or an array as above
[ "Validate", "an", "access", "token" ]
8b4abc4f1be255b441e09f5014e863a130c666d8
https://github.com/feelinc/laravel-api/blob/8b4abc4f1be255b441e09f5014e863a130c666d8/src/Sule/Api/OAuth2/Repositories/FluentSession.php#L261-L276
train
feelinc/laravel-api
src/Sule/Api/OAuth2/Repositories/FluentSession.php
FluentSession.validateRefreshToken
public function validateRefreshToken($refreshToken, $clientId) { $result = DB::table('oauth_session_refresh_tokens') ->where('refresh_token', $refreshToken) ->where('client_id', $clientId) ->where('refresh_token_expires', '>=', time()) ->first(); return (is_null($result)) ? false : $result->session_access_token_id; }
php
public function validateRefreshToken($refreshToken, $clientId) { $result = DB::table('oauth_session_refresh_tokens') ->where('refresh_token', $refreshToken) ->where('client_id', $clientId) ->where('refresh_token_expires', '>=', time()) ->first(); return (is_null($result)) ? false : $result->session_access_token_id; }
[ "public", "function", "validateRefreshToken", "(", "$", "refreshToken", ",", "$", "clientId", ")", "{", "$", "result", "=", "DB", "::", "table", "(", "'oauth_session_refresh_tokens'", ")", "->", "where", "(", "'refresh_token'", ",", "$", "refreshToken", ")", "->", "where", "(", "'client_id'", ",", "$", "clientId", ")", "->", "where", "(", "'refresh_token_expires'", ",", "'>='", ",", "time", "(", ")", ")", "->", "first", "(", ")", ";", "return", "(", "is_null", "(", "$", "result", ")", ")", "?", "false", ":", "$", "result", "->", "session_access_token_id", ";", "}" ]
Validate a refresh token Example SQL query: <code> SELECT session_access_token_id FROM `oauth_session_refresh_tokens` WHERE refresh_token = :refreshToken AND refresh_token_expires >= UNIX_TIMESTAMP(NOW()) AND client_id = :clientId </code> @param string $refreshToken The access token @param string $clientId The client ID @return int|bool The ID of the access token the refresh token is linked to (or false if invalid)
[ "Validate", "a", "refresh", "token" ]
8b4abc4f1be255b441e09f5014e863a130c666d8
https://github.com/feelinc/laravel-api/blob/8b4abc4f1be255b441e09f5014e863a130c666d8/src/Sule/Api/OAuth2/Repositories/FluentSession.php#L292-L301
train
feelinc/laravel-api
src/Sule/Api/OAuth2/Repositories/FluentSession.php
FluentSession.getAccessToken
public function getAccessToken($accessTokenId) { $result = DB::table('oauth_session_access_tokens') ->where('id', $accessTokenId) ->first(); return (is_null($result)) ? false : (array) $result; }
php
public function getAccessToken($accessTokenId) { $result = DB::table('oauth_session_access_tokens') ->where('id', $accessTokenId) ->first(); return (is_null($result)) ? false : (array) $result; }
[ "public", "function", "getAccessToken", "(", "$", "accessTokenId", ")", "{", "$", "result", "=", "DB", "::", "table", "(", "'oauth_session_access_tokens'", ")", "->", "where", "(", "'id'", ",", "$", "accessTokenId", ")", "->", "first", "(", ")", ";", "return", "(", "is_null", "(", "$", "result", ")", ")", "?", "false", ":", "(", "array", ")", "$", "result", ";", "}" ]
Get an access token by ID Example SQL query: <code> SELECT * FROM `oauth_session_access_tokens` WHERE `id` = :accessTokenId </code> Expected response: <code> array( 'id' => (int), 'session_id' => (int), 'access_token' => (string), 'access_token_expires' => (int) ) </code> @param int $accessTokenId The access token ID @return array
[ "Get", "an", "access", "token", "by", "ID" ]
8b4abc4f1be255b441e09f5014e863a130c666d8
https://github.com/feelinc/laravel-api/blob/8b4abc4f1be255b441e09f5014e863a130c666d8/src/Sule/Api/OAuth2/Repositories/FluentSession.php#L326-L333
train
feelinc/laravel-api
src/Sule/Api/OAuth2/Repositories/FluentSession.php
FluentSession.associateScope
public function associateScope($accessTokenId, $scopeId) { DB::table('oauth_session_token_scopes')->insert(array( 'session_access_token_id' => $accessTokenId, 'scope_id' => $scopeId, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now() )); }
php
public function associateScope($accessTokenId, $scopeId) { DB::table('oauth_session_token_scopes')->insert(array( 'session_access_token_id' => $accessTokenId, 'scope_id' => $scopeId, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now() )); }
[ "public", "function", "associateScope", "(", "$", "accessTokenId", ",", "$", "scopeId", ")", "{", "DB", "::", "table", "(", "'oauth_session_token_scopes'", ")", "->", "insert", "(", "array", "(", "'session_access_token_id'", "=>", "$", "accessTokenId", ",", "'scope_id'", "=>", "$", "scopeId", ",", "'created_at'", "=>", "Carbon", "::", "now", "(", ")", ",", "'updated_at'", "=>", "Carbon", "::", "now", "(", ")", ")", ")", ";", "}" ]
Associate a scope with an access token Example SQL query: <code> INSERT INTO `oauth_session_token_scopes` (`session_access_token_id`, `scope_id`) VALUE (:accessTokenId, :scopeId) </code> @param int $accessTokenId The ID of the access token @param int $scopeId The ID of the scope @return void
[ "Associate", "a", "scope", "with", "an", "access", "token" ]
8b4abc4f1be255b441e09f5014e863a130c666d8
https://github.com/feelinc/laravel-api/blob/8b4abc4f1be255b441e09f5014e863a130c666d8/src/Sule/Api/OAuth2/Repositories/FluentSession.php#L348-L356
train
feelinc/laravel-api
src/Sule/Api/OAuth2/Repositories/FluentSession.php
FluentSession.getScopes
public function getScopes($accessToken) { $scopeResults = DB::table('oauth_session_token_scopes') ->select('oauth_scopes.*') ->join('oauth_session_access_tokens', 'oauth_session_token_scopes.session_access_token_id', '=', 'oauth_session_access_tokens.id') ->join('oauth_scopes', 'oauth_session_token_scopes.scope_id', '=', 'oauth_scopes.id') ->where('access_token', $accessToken) ->get(); $scopes = array(); foreach($scopeResults as $key=>$scope) { $scopes[$key] = get_object_vars($scope); } return $scopes; }
php
public function getScopes($accessToken) { $scopeResults = DB::table('oauth_session_token_scopes') ->select('oauth_scopes.*') ->join('oauth_session_access_tokens', 'oauth_session_token_scopes.session_access_token_id', '=', 'oauth_session_access_tokens.id') ->join('oauth_scopes', 'oauth_session_token_scopes.scope_id', '=', 'oauth_scopes.id') ->where('access_token', $accessToken) ->get(); $scopes = array(); foreach($scopeResults as $key=>$scope) { $scopes[$key] = get_object_vars($scope); } return $scopes; }
[ "public", "function", "getScopes", "(", "$", "accessToken", ")", "{", "$", "scopeResults", "=", "DB", "::", "table", "(", "'oauth_session_token_scopes'", ")", "->", "select", "(", "'oauth_scopes.*'", ")", "->", "join", "(", "'oauth_session_access_tokens'", ",", "'oauth_session_token_scopes.session_access_token_id'", ",", "'='", ",", "'oauth_session_access_tokens.id'", ")", "->", "join", "(", "'oauth_scopes'", ",", "'oauth_session_token_scopes.scope_id'", ",", "'='", ",", "'oauth_scopes.id'", ")", "->", "where", "(", "'access_token'", ",", "$", "accessToken", ")", "->", "get", "(", ")", ";", "$", "scopes", "=", "array", "(", ")", ";", "foreach", "(", "$", "scopeResults", "as", "$", "key", "=>", "$", "scope", ")", "{", "$", "scopes", "[", "$", "key", "]", "=", "get_object_vars", "(", "$", "scope", ")", ";", "}", "return", "$", "scopes", ";", "}" ]
Get all associated access tokens for an access token Example SQL query: <code> SELECT oauth_scopes.* FROM oauth_session_token_scopes JOIN oauth_session_access_tokens ON oauth_session_access_tokens.`id` = `oauth_session_token_scopes`.`session_access_token_id` JOIN oauth_scopes ON oauth_scopes.id = `oauth_session_token_scopes`.`scope_id` WHERE access_token = :accessToken </code> Expected response: <code> array ( array( 'key' => (string), 'name' => (string), 'description' => (string) ), ... ... ) </code> @param string $accessToken The access token @return array
[ "Get", "all", "associated", "access", "tokens", "for", "an", "access", "token" ]
8b4abc4f1be255b441e09f5014e863a130c666d8
https://github.com/feelinc/laravel-api/blob/8b4abc4f1be255b441e09f5014e863a130c666d8/src/Sule/Api/OAuth2/Repositories/FluentSession.php#L387-L405
train
feelinc/laravel-api
src/Sule/Api/OAuth2/Repositories/FluentSession.php
FluentSession.getAuthCodeScopes
public function getAuthCodeScopes($oauthSessionAuthCodeId) { $scopesResults = DB::table('oauth_session_authcode_scopes') ->where('oauth_session_authcode_id', '=', $oauthSessionAuthCodeId) ->get(); $scopes = array(); foreach($scopesResults as $key=>$scope) { $scopes[$key] = get_object_vars($scope); } return $scopes; }
php
public function getAuthCodeScopes($oauthSessionAuthCodeId) { $scopesResults = DB::table('oauth_session_authcode_scopes') ->where('oauth_session_authcode_id', '=', $oauthSessionAuthCodeId) ->get(); $scopes = array(); foreach($scopesResults as $key=>$scope) { $scopes[$key] = get_object_vars($scope); } return $scopes; }
[ "public", "function", "getAuthCodeScopes", "(", "$", "oauthSessionAuthCodeId", ")", "{", "$", "scopesResults", "=", "DB", "::", "table", "(", "'oauth_session_authcode_scopes'", ")", "->", "where", "(", "'oauth_session_authcode_id'", ",", "'='", ",", "$", "oauthSessionAuthCodeId", ")", "->", "get", "(", ")", ";", "$", "scopes", "=", "array", "(", ")", ";", "foreach", "(", "$", "scopesResults", "as", "$", "key", "=>", "$", "scope", ")", "{", "$", "scopes", "[", "$", "key", "]", "=", "get_object_vars", "(", "$", "scope", ")", ";", "}", "return", "$", "scopes", ";", "}" ]
Get the scopes associated with an auth code Example SQL query: <code> SELECT scope_id FROM `oauth_session_authcode_scopes` WHERE oauth_session_authcode_id = :authCodeId </code> Expected response: <code> array( array( 'scope_id' => (int) ), array( 'scope_id' => (int) ), ... ) </code> @param int $oauthSessionAuthCodeId The session ID @return array
[ "Get", "the", "scopes", "associated", "with", "an", "auth", "code" ]
8b4abc4f1be255b441e09f5014e863a130c666d8
https://github.com/feelinc/laravel-api/blob/8b4abc4f1be255b441e09f5014e863a130c666d8/src/Sule/Api/OAuth2/Repositories/FluentSession.php#L457-L473
train
chilimatic/chilimatic-framework
lib/file/File.php
File.append
public function append($content, $create = false) { if ($this->writeable !== true || empty($content)) return false; if (strpos($this->_option, 'a') === false) { // close open filepoint if (!empty($this->fp)) fclose($this->fp); // opens fp for writing with file lock $this->open_fp((is_bool($create) && $create === true ? 'a+' : 'a')); } if ($this->file_lock !== true && !$this->lock(LOCK_EX)) return false; // writes to file fputs($this->fp, $content, strlen($content)); // releases lock $this->lock(LOCK_UN); return true; }
php
public function append($content, $create = false) { if ($this->writeable !== true || empty($content)) return false; if (strpos($this->_option, 'a') === false) { // close open filepoint if (!empty($this->fp)) fclose($this->fp); // opens fp for writing with file lock $this->open_fp((is_bool($create) && $create === true ? 'a+' : 'a')); } if ($this->file_lock !== true && !$this->lock(LOCK_EX)) return false; // writes to file fputs($this->fp, $content, strlen($content)); // releases lock $this->lock(LOCK_UN); return true; }
[ "public", "function", "append", "(", "$", "content", ",", "$", "create", "=", "false", ")", "{", "if", "(", "$", "this", "->", "writeable", "!==", "true", "||", "empty", "(", "$", "content", ")", ")", "return", "false", ";", "if", "(", "strpos", "(", "$", "this", "->", "_option", ",", "'a'", ")", "===", "false", ")", "{", "// close open filepoint", "if", "(", "!", "empty", "(", "$", "this", "->", "fp", ")", ")", "fclose", "(", "$", "this", "->", "fp", ")", ";", "// opens fp for writing with file lock", "$", "this", "->", "open_fp", "(", "(", "is_bool", "(", "$", "create", ")", "&&", "$", "create", "===", "true", "?", "'a+'", ":", "'a'", ")", ")", ";", "}", "if", "(", "$", "this", "->", "file_lock", "!==", "true", "&&", "!", "$", "this", "->", "lock", "(", "LOCK_EX", ")", ")", "return", "false", ";", "// writes to file", "fputs", "(", "$", "this", "->", "fp", ",", "$", "content", ",", "strlen", "(", "$", "content", ")", ")", ";", "// releases lock", "$", "this", "->", "lock", "(", "LOCK_UN", ")", ";", "return", "true", ";", "}" ]
appends to a file based + create if wanted @param $content string @param $create bool @return bool
[ "appends", "to", "a", "file", "based", "+", "create", "if", "wanted" ]
8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12
https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/file/File.php#L220-L240
train
chilimatic/chilimatic-framework
lib/file/File.php
File.change_owner
public function change_owner($owner) { if (empty($owner) || !is_int($owner) || $this->owner != getmyuid()) return false; if (!empty($this->fp)) fclose($this->fp); if (chown($this->path . $this->filename, $owner)) { return $this->open($this->path . $this->filename); } return false; }
php
public function change_owner($owner) { if (empty($owner) || !is_int($owner) || $this->owner != getmyuid()) return false; if (!empty($this->fp)) fclose($this->fp); if (chown($this->path . $this->filename, $owner)) { return $this->open($this->path . $this->filename); } return false; }
[ "public", "function", "change_owner", "(", "$", "owner", ")", "{", "if", "(", "empty", "(", "$", "owner", ")", "||", "!", "is_int", "(", "$", "owner", ")", "||", "$", "this", "->", "owner", "!=", "getmyuid", "(", ")", ")", "return", "false", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "fp", ")", ")", "fclose", "(", "$", "this", "->", "fp", ")", ";", "if", "(", "chown", "(", "$", "this", "->", "path", ".", "$", "this", "->", "filename", ",", "$", "owner", ")", ")", "{", "return", "$", "this", "->", "open", "(", "$", "this", "->", "path", ".", "$", "this", "->", "filename", ")", ";", "}", "return", "false", ";", "}" ]
changes file owner @param $owner int @return bool
[ "changes", "file", "owner" ]
8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12
https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/file/File.php#L283-L295
train
chilimatic/chilimatic-framework
lib/file/File.php
File.change_group
public function change_group($group) { if (empty($group) || !is_int($group)) return false; if (chgrp($this->path . $this->filename, $group)) { return $this->open($this->path . $this->filename); } return false; }
php
public function change_group($group) { if (empty($group) || !is_int($group)) return false; if (chgrp($this->path . $this->filename, $group)) { return $this->open($this->path . $this->filename); } return false; }
[ "public", "function", "change_group", "(", "$", "group", ")", "{", "if", "(", "empty", "(", "$", "group", ")", "||", "!", "is_int", "(", "$", "group", ")", ")", "return", "false", ";", "if", "(", "chgrp", "(", "$", "this", "->", "path", ".", "$", "this", "->", "filename", ",", "$", "group", ")", ")", "{", "return", "$", "this", "->", "open", "(", "$", "this", "->", "path", ".", "$", "this", "->", "filename", ")", ";", "}", "return", "false", ";", "}" ]
changes the group @param $group int @return bool
[ "changes", "the", "group" ]
8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12
https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/file/File.php#L325-L335
train
chilimatic/chilimatic-framework
lib/file/File.php
File._extract_file_extension
private function _extract_file_extension() { if (empty($this->filename)) return false; if (!empty($this->mime_type)) { $array = explode('/', $this->mime_type); $this->file_extension = array_pop($array); } else { if (strpos($this->filename, '.') !== false) { $array = explode('/', $this->mime_type); $this->file_extension = array_pop($array); } else { $this->file_extension = 'unknown'; } } return true; }
php
private function _extract_file_extension() { if (empty($this->filename)) return false; if (!empty($this->mime_type)) { $array = explode('/', $this->mime_type); $this->file_extension = array_pop($array); } else { if (strpos($this->filename, '.') !== false) { $array = explode('/', $this->mime_type); $this->file_extension = array_pop($array); } else { $this->file_extension = 'unknown'; } } return true; }
[ "private", "function", "_extract_file_extension", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "filename", ")", ")", "return", "false", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "mime_type", ")", ")", "{", "$", "array", "=", "explode", "(", "'/'", ",", "$", "this", "->", "mime_type", ")", ";", "$", "this", "->", "file_extension", "=", "array_pop", "(", "$", "array", ")", ";", "}", "else", "{", "if", "(", "strpos", "(", "$", "this", "->", "filename", ",", "'.'", ")", "!==", "false", ")", "{", "$", "array", "=", "explode", "(", "'/'", ",", "$", "this", "->", "mime_type", ")", ";", "$", "this", "->", "file_extension", "=", "array_pop", "(", "$", "array", ")", ";", "}", "else", "{", "$", "this", "->", "file_extension", "=", "'unknown'", ";", "}", "}", "return", "true", ";", "}" ]
extracts the extension of the current file
[ "extracts", "the", "extension", "of", "the", "current", "file" ]
8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12
https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/file/File.php#L357-L375
train
chilimatic/chilimatic-framework
lib/file/File.php
File._extract_filename
private function _extract_filename() { if (empty($this->file)) return false; $tmp_array = explode('/', $this->file); $count = (int)count($tmp_array); for ($i = 0; $i < $count; $i++) { if ($i + 1 == $count) { $this->filename = (string)$tmp_array[0]; } array_shift($tmp_array); } unset($tmp_array); return true; }
php
private function _extract_filename() { if (empty($this->file)) return false; $tmp_array = explode('/', $this->file); $count = (int)count($tmp_array); for ($i = 0; $i < $count; $i++) { if ($i + 1 == $count) { $this->filename = (string)$tmp_array[0]; } array_shift($tmp_array); } unset($tmp_array); return true; }
[ "private", "function", "_extract_filename", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "file", ")", ")", "return", "false", ";", "$", "tmp_array", "=", "explode", "(", "'/'", ",", "$", "this", "->", "file", ")", ";", "$", "count", "=", "(", "int", ")", "count", "(", "$", "tmp_array", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "if", "(", "$", "i", "+", "1", "==", "$", "count", ")", "{", "$", "this", "->", "filename", "=", "(", "string", ")", "$", "tmp_array", "[", "0", "]", ";", "}", "array_shift", "(", "$", "tmp_array", ")", ";", "}", "unset", "(", "$", "tmp_array", ")", ";", "return", "true", ";", "}" ]
gets the filename of the file
[ "gets", "the", "filename", "of", "the", "file" ]
8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12
https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/file/File.php#L381-L397
train