id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
226,500
kevinkhill/FontAwesomePHP
src/FontAwesomeList.php
FontAwesomeList.addItem
private function addItem($icon, $liVal) { if ($icon === null) { $this->lines[] = array($this->icon, $liVal); } else { $this->lines[] = array($icon, $liVal); } return $this; }
php
private function addItem($icon, $liVal) { if ($icon === null) { $this->lines[] = array($this->icon, $liVal); } else { $this->lines[] = array($icon, $liVal); } return $this; }
[ "private", "function", "addItem", "(", "$", "icon", ",", "$", "liVal", ")", "{", "if", "(", "$", "icon", "===", "null", ")", "{", "$", "this", "->", "lines", "[", "]", "=", "array", "(", "$", "this", "->", "icon", ",", "$", "liVal", ")", ";", "}", "else", "{", "$", "this", "->", "lines", "[", "]", "=", "array", "(", "$", "icon", ",", "$", "liVal", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add an item to the list @param string $icon Icon to assign the list item @param string $liVal Value of the list item @return self
[ "Add", "an", "item", "to", "the", "list" ]
e7d12d7422b23a5c3a09715d9ca3e24ff811c073
https://github.com/kevinkhill/FontAwesomePHP/blob/e7d12d7422b23a5c3a09715d9ca3e24ff811c073/src/FontAwesomeList.php#L125-L134
226,501
kevinkhill/FontAwesomePHP
src/FontAwesomeList.php
FontAwesomeList.addItems
private function addItems(array $lineArray) { foreach ($lineArray as $icon => $liVal) { $icon = is_string($icon) ? $icon : null; $this->addItem($icon, $liVal); } return $this; }
php
private function addItems(array $lineArray) { foreach ($lineArray as $icon => $liVal) { $icon = is_string($icon) ? $icon : null; $this->addItem($icon, $liVal); } return $this; }
[ "private", "function", "addItems", "(", "array", "$", "lineArray", ")", "{", "foreach", "(", "$", "lineArray", "as", "$", "icon", "=>", "$", "liVal", ")", "{", "$", "icon", "=", "is_string", "(", "$", "icon", ")", "?", "$", "icon", ":", "null", ";", "$", "this", "->", "addItem", "(", "$", "icon", ",", "$", "liVal", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add multiple items to list @param array $lineArray Array of lines to add to list @return self @throws \Khill\FontAwesome\Exceptions\IncompleteListException
[ "Add", "multiple", "items", "to", "list" ]
e7d12d7422b23a5c3a09715d9ca3e24ff811c073
https://github.com/kevinkhill/FontAwesomePHP/blob/e7d12d7422b23a5c3a09715d9ca3e24ff811c073/src/FontAwesomeList.php#L143-L152
226,502
phergie/phergie-irc-bot-react
src/PluginProcessor/LoopInjector.php
LoopInjector.process
public function process(PluginInterface $plugin, Bot $bot) { $client = $bot->getClient(); if ($plugin instanceof LoopAwareInterface && $client instanceof LoopAccessorInterface) { $plugin->setLoop($client->getLoop()); } }
php
public function process(PluginInterface $plugin, Bot $bot) { $client = $bot->getClient(); if ($plugin instanceof LoopAwareInterface && $client instanceof LoopAccessorInterface) { $plugin->setLoop($client->getLoop()); } }
[ "public", "function", "process", "(", "PluginInterface", "$", "plugin", ",", "Bot", "$", "bot", ")", "{", "$", "client", "=", "$", "bot", "->", "getClient", "(", ")", ";", "if", "(", "$", "plugin", "instanceof", "LoopAwareInterface", "&&", "$", "client", "instanceof", "LoopAccessorInterface", ")", "{", "$", "plugin", "->", "setLoop", "(", "$", "client", "->", "getLoop", "(", ")", ")", ";", "}", "}" ]
Injects the event loop of the bot's client into the plugin if it implements \Phergie\Irc\Bot\React\LoopInterface. @param \Phergie\Irc\Bot\React\PluginInterface $plugin Loaded plugin @param \Phergie\Irc\Bot\React\Bot $bot Bot that loaded the plugin
[ "Injects", "the", "event", "loop", "of", "the", "bot", "s", "client", "into", "the", "plugin", "if", "it", "implements", "\\", "Phergie", "\\", "Irc", "\\", "Bot", "\\", "React", "\\", "LoopInterface", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/PluginProcessor/LoopInjector.php#L34-L41
226,503
jasny/db-mysql
src/Jasny/MySQL/DB.php
DB.conn
public static function conn() { // Auto connect using Jasny's Config class if (!isset(self::$connection)) { if (!class_exists('Jasny\Config') || !isset(\Jasny\Config::i()->db)) throw new DB_Exception("Unable to create DB connection: not configured"); new static(\Jasny\Config::i()->db); } return self::$connection; }
php
public static function conn() { // Auto connect using Jasny's Config class if (!isset(self::$connection)) { if (!class_exists('Jasny\Config') || !isset(\Jasny\Config::i()->db)) throw new DB_Exception("Unable to create DB connection: not configured"); new static(\Jasny\Config::i()->db); } return self::$connection; }
[ "public", "static", "function", "conn", "(", ")", "{", "// Auto connect using Jasny's Config class", "if", "(", "!", "isset", "(", "self", "::", "$", "connection", ")", ")", "{", "if", "(", "!", "class_exists", "(", "'Jasny\\Config'", ")", "||", "!", "isset", "(", "\\", "Jasny", "\\", "Config", "::", "i", "(", ")", "->", "db", ")", ")", "throw", "new", "DB_Exception", "(", "\"Unable to create DB connection: not configured\"", ")", ";", "new", "static", "(", "\\", "Jasny", "\\", "Config", "::", "i", "(", ")", "->", "db", ")", ";", "}", "return", "self", "::", "$", "connection", ";", "}" ]
Get the DB connection. @return DB
[ "Get", "the", "DB", "connection", "." ]
da03c9eaec386bd8f30919d0b33be4e91eec5c8c
https://github.com/jasny/db-mysql/blob/da03c9eaec386bd8f30919d0b33be4e91eec5c8c/src/Jasny/MySQL/DB.php#L49-L58
226,504
jasny/db-mysql
src/Jasny/MySQL/DB.php
DB.fetchColumn
public function fetchColumn($query) { if (func_num_args() > 1) $query = call_user_func_array(array(get_class(), 'bind'), func_get_args()); $result = $query instanceof \mysqli_result ? $query : $this->query($query); $values = array(); while (list($value) = $result->fetch_row()) { $values[] = $value; } return $values; }
php
public function fetchColumn($query) { if (func_num_args() > 1) $query = call_user_func_array(array(get_class(), 'bind'), func_get_args()); $result = $query instanceof \mysqli_result ? $query : $this->query($query); $values = array(); while (list($value) = $result->fetch_row()) { $values[] = $value; } return $values; }
[ "public", "function", "fetchColumn", "(", "$", "query", ")", "{", "if", "(", "func_num_args", "(", ")", ">", "1", ")", "$", "query", "=", "call_user_func_array", "(", "array", "(", "get_class", "(", ")", ",", "'bind'", ")", ",", "func_get_args", "(", ")", ")", ";", "$", "result", "=", "$", "query", "instanceof", "\\", "mysqli_result", "?", "$", "query", ":", "$", "this", "->", "query", "(", "$", "query", ")", ";", "$", "values", "=", "array", "(", ")", ";", "while", "(", "list", "(", "$", "value", ")", "=", "$", "result", "->", "fetch_row", "(", ")", ")", "{", "$", "values", "[", "]", "=", "$", "value", ";", "}", "return", "$", "values", ";", "}" ]
Query and fetch a single column from all result rows. @example DB::conn()->fetchColumn("SELECT name FROM mytable"); @example DB::conn()->fetchColumn("SELECT name FROM mytable WHERE group=?", $group); @param string|\mysqli_result $query SQL Query or DB result @param string $field The field position or name to fetch @return array
[ "Query", "and", "fetch", "a", "single", "column", "from", "all", "result", "rows", "." ]
da03c9eaec386bd8f30919d0b33be4e91eec5c8c
https://github.com/jasny/db-mysql/blob/da03c9eaec386bd8f30919d0b33be4e91eec5c8c/src/Jasny/MySQL/DB.php#L186-L198
226,505
jasny/db-mysql
src/Jasny/MySQL/DB.php
DB.fetchValue
public function fetchValue($query) { if (func_num_args() > 1) $query = call_user_func_array(array(get_class(), 'bind'), func_get_args()); $result = $query instanceof \mysqli_result ? $query : $this->query($query); list($value) = $result->fetch_row(); return $value; }
php
public function fetchValue($query) { if (func_num_args() > 1) $query = call_user_func_array(array(get_class(), 'bind'), func_get_args()); $result = $query instanceof \mysqli_result ? $query : $this->query($query); list($value) = $result->fetch_row(); return $value; }
[ "public", "function", "fetchValue", "(", "$", "query", ")", "{", "if", "(", "func_num_args", "(", ")", ">", "1", ")", "$", "query", "=", "call_user_func_array", "(", "array", "(", "get_class", "(", ")", ",", "'bind'", ")", ",", "func_get_args", "(", ")", ")", ";", "$", "result", "=", "$", "query", "instanceof", "\\", "mysqli_result", "?", "$", "query", ":", "$", "this", "->", "query", "(", "$", "query", ")", ";", "list", "(", "$", "value", ")", "=", "$", "result", "->", "fetch_row", "(", ")", ";", "return", "$", "value", ";", "}" ]
Query and fetch a single value. @example DB::conn()->fetchValue("SELECT SUM(foo) FROM mytable"); @example DB::conn()->fetchValue("SELECT name FROM mytable WHERE id=?", $id); @param string|\mysqli_result $query SQL Query or DB result @param string $field The field position or name to fetch @return array
[ "Query", "and", "fetch", "a", "single", "value", "." ]
da03c9eaec386bd8f30919d0b33be4e91eec5c8c
https://github.com/jasny/db-mysql/blob/da03c9eaec386bd8f30919d0b33be4e91eec5c8c/src/Jasny/MySQL/DB.php#L233-L241
226,506
jasny/db-mysql
src/Jasny/MySQL/DB.php
DB.save
public function save($table, array $values = array(), $update = true) { if (!is_array(reset($values))) $values = array($values); // Make sure that $values is a set of rows $fields = array(); $query_values = array(); $query_update = array(); foreach (array_keys(reset($values)) as $key) { $field = static::backquote($key); $fields[$key] = $field; $query_update[$key] = "$field=VALUES($field)"; } foreach ($values as &$row) { $vals = array(); foreach (array_keys($fields) as $key) { $vals[$key] = static::quote($row[$key], 'DEFAULT'); } $query_values[] = '(' . join(', ', $vals) . ')'; } $query = "INSERT" . ($update ? '' : " IGNORE") . " INTO `" . str_replace('`', '', $table) . "` (" . join(', ', $fields) . ") VALUES " . join(', ', $query_values) . ($update ? " ON DUPLICATE KEY UPDATE " . join(', ', $query_update) : ''); $this->query($query); return $this->insert_id; }
php
public function save($table, array $values = array(), $update = true) { if (!is_array(reset($values))) $values = array($values); // Make sure that $values is a set of rows $fields = array(); $query_values = array(); $query_update = array(); foreach (array_keys(reset($values)) as $key) { $field = static::backquote($key); $fields[$key] = $field; $query_update[$key] = "$field=VALUES($field)"; } foreach ($values as &$row) { $vals = array(); foreach (array_keys($fields) as $key) { $vals[$key] = static::quote($row[$key], 'DEFAULT'); } $query_values[] = '(' . join(', ', $vals) . ')'; } $query = "INSERT" . ($update ? '' : " IGNORE") . " INTO `" . str_replace('`', '', $table) . "` (" . join(', ', $fields) . ") VALUES " . join(', ', $query_values) . ($update ? " ON DUPLICATE KEY UPDATE " . join(', ', $query_update) : ''); $this->query($query); return $this->insert_id; }
[ "public", "function", "save", "(", "$", "table", ",", "array", "$", "values", "=", "array", "(", ")", ",", "$", "update", "=", "true", ")", "{", "if", "(", "!", "is_array", "(", "reset", "(", "$", "values", ")", ")", ")", "$", "values", "=", "array", "(", "$", "values", ")", ";", "// Make sure that $values is a set of rows", "$", "fields", "=", "array", "(", ")", ";", "$", "query_values", "=", "array", "(", ")", ";", "$", "query_update", "=", "array", "(", ")", ";", "foreach", "(", "array_keys", "(", "reset", "(", "$", "values", ")", ")", "as", "$", "key", ")", "{", "$", "field", "=", "static", "::", "backquote", "(", "$", "key", ")", ";", "$", "fields", "[", "$", "key", "]", "=", "$", "field", ";", "$", "query_update", "[", "$", "key", "]", "=", "\"$field=VALUES($field)\"", ";", "}", "foreach", "(", "$", "values", "as", "&", "$", "row", ")", "{", "$", "vals", "=", "array", "(", ")", ";", "foreach", "(", "array_keys", "(", "$", "fields", ")", "as", "$", "key", ")", "{", "$", "vals", "[", "$", "key", "]", "=", "static", "::", "quote", "(", "$", "row", "[", "$", "key", "]", ",", "'DEFAULT'", ")", ";", "}", "$", "query_values", "[", "]", "=", "'('", ".", "join", "(", "', '", ",", "$", "vals", ")", ".", "')'", ";", "}", "$", "query", "=", "\"INSERT\"", ".", "(", "$", "update", "?", "''", ":", "\" IGNORE\"", ")", ".", "\" INTO `\"", ".", "str_replace", "(", "'`'", ",", "''", ",", "$", "table", ")", ".", "\"` (\"", ".", "join", "(", "', '", ",", "$", "fields", ")", ".", "\") VALUES \"", ".", "join", "(", "', '", ",", "$", "query_values", ")", ".", "(", "$", "update", "?", "\" ON DUPLICATE KEY UPDATE \"", ".", "join", "(", "', '", ",", "$", "query_update", ")", ":", "''", ")", ";", "$", "this", "->", "query", "(", "$", "query", ")", ";", "return", "$", "this", "->", "insert_id", ";", "}" ]
Insert or update a record. All rows should have the same keys in the same order. @example $db->save('mytable', $row) @example $db->save('mytable', array($row1, $row2, $row3)) @example $db->save('mytable', array($row1, $row2, $row3), DB::SKIP_EXISTING) @param string $table @param array $values One or multiple rows of values @param boolean $update Update on duplicate key @return int Last insert ID
[ "Insert", "or", "update", "a", "record", ".", "All", "rows", "should", "have", "the", "same", "keys", "in", "the", "same", "order", "." ]
da03c9eaec386bd8f30919d0b33be4e91eec5c8c
https://github.com/jasny/db-mysql/blob/da03c9eaec386bd8f30919d0b33be4e91eec5c8c/src/Jasny/MySQL/DB.php#L257-L284
226,507
jasny/db-mysql
src/Jasny/MySQL/DB.php
DB.quote
public static function quote($value, $empty = 'NULL') { if (is_array($value)) return '(' . join(', ', array_map(array(get_class(), 'quote'), $value)) . ')'; if (is_null($value)) return $empty; if (is_bool($value)) return $value ? 'TRUE' : 'FALSE'; if (is_int($value) || is_float($value)) return (string)$value; return '"' . strtr((string)$value, array('\\' => '\\\\', "\0" => '\\0', "\r" => '\\r', "\n" => '\\n', '"' => '\\"')) . '"'; }
php
public static function quote($value, $empty = 'NULL') { if (is_array($value)) return '(' . join(', ', array_map(array(get_class(), 'quote'), $value)) . ')'; if (is_null($value)) return $empty; if (is_bool($value)) return $value ? 'TRUE' : 'FALSE'; if (is_int($value) || is_float($value)) return (string)$value; return '"' . strtr((string)$value, array('\\' => '\\\\', "\0" => '\\0', "\r" => '\\r', "\n" => '\\n', '"' => '\\"')) . '"'; }
[ "public", "static", "function", "quote", "(", "$", "value", ",", "$", "empty", "=", "'NULL'", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "return", "'('", ".", "join", "(", "', '", ",", "array_map", "(", "array", "(", "get_class", "(", ")", ",", "'quote'", ")", ",", "$", "value", ")", ")", ".", "')'", ";", "if", "(", "is_null", "(", "$", "value", ")", ")", "return", "$", "empty", ";", "if", "(", "is_bool", "(", "$", "value", ")", ")", "return", "$", "value", "?", "'TRUE'", ":", "'FALSE'", ";", "if", "(", "is_int", "(", "$", "value", ")", "||", "is_float", "(", "$", "value", ")", ")", "return", "(", "string", ")", "$", "value", ";", "return", "'\"'", ".", "strtr", "(", "(", "string", ")", "$", "value", ",", "array", "(", "'\\\\'", "=>", "'\\\\\\\\'", ",", "\"\\0\"", "=>", "'\\\\0'", ",", "\"\\r\"", "=>", "'\\\\r'", ",", "\"\\n\"", "=>", "'\\\\n'", ",", "'\"'", "=>", "'\\\\\"'", ")", ")", ".", "'\"'", ";", "}" ]
Quote a value so it can be savely used in a query. @param mixed $value @param string $empty Return $empty if $value is null @return string
[ "Quote", "a", "value", "so", "it", "can", "be", "savely", "used", "in", "a", "query", "." ]
da03c9eaec386bd8f30919d0b33be4e91eec5c8c
https://github.com/jasny/db-mysql/blob/da03c9eaec386bd8f30919d0b33be4e91eec5c8c/src/Jasny/MySQL/DB.php#L294-L302
226,508
gigaai/framework
src/Core/Config.php
Config.loadFromFile
private function loadFromFile($path) { if ( ! is_file($path)) { return; } $config = require_once $path; if (is_array($config)) { $this->config = $config; } }
php
private function loadFromFile($path) { if ( ! is_file($path)) { return; } $config = require_once $path; if (is_array($config)) { $this->config = $config; } }
[ "private", "function", "loadFromFile", "(", "$", "path", ")", "{", "if", "(", "!", "is_file", "(", "$", "path", ")", ")", "{", "return", ";", "}", "$", "config", "=", "require_once", "$", "path", ";", "if", "(", "is_array", "(", "$", "config", ")", ")", "{", "$", "this", "->", "config", "=", "$", "config", ";", "}", "}" ]
Load configuration from file. The file should returns an array of settings. @param String $path File path @return $this|void
[ "Load", "configuration", "from", "file", ".", "The", "file", "should", "returns", "an", "array", "of", "settings", "." ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Core/Config.php#L74-L85
226,509
gigaai/framework
src/Http/Http.php
Http.post
public static function post($url, $data = [], $method = 'POST') { $ch = curl_init(); if ( ! empty($data)) { $data = http_build_query($data); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output $result = curl_exec($ch); curl_close($ch); if (false !== $result) { $result = json_decode($result); } else { throw new \Exception('Error during making request'); } return $result; }
php
public static function post($url, $data = [], $method = 'POST') { $ch = curl_init(); if ( ! empty($data)) { $data = http_build_query($data); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output $result = curl_exec($ch); curl_close($ch); if (false !== $result) { $result = json_decode($result); } else { throw new \Exception('Error during making request'); } return $result; }
[ "public", "static", "function", "post", "(", "$", "url", ",", "$", "data", "=", "[", "]", ",", "$", "method", "=", "'POST'", ")", "{", "$", "ch", "=", "curl_init", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "data", ")", ")", "{", "$", "data", "=", "http_build_query", "(", "$", "data", ")", ";", "}", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_URL", ",", "$", "url", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_CUSTOMREQUEST", ",", "$", "method", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYPEER", ",", "false", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYHOST", ",", "2", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POST", ",", "true", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POSTFIELDS", ",", "$", "data", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_RETURNTRANSFER", ",", "true", ")", ";", "//to suppress the curl output", "$", "result", "=", "curl_exec", "(", "$", "ch", ")", ";", "curl_close", "(", "$", "ch", ")", ";", "if", "(", "false", "!==", "$", "result", ")", "{", "$", "result", "=", "json_decode", "(", "$", "result", ")", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "'Error during making request'", ")", ";", "}", "return", "$", "result", ";", "}" ]
Make a POST request to the end point @param String $url Url End point @param array $data Data to be send @return Mixed
[ "Make", "a", "POST", "request", "to", "the", "end", "point" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Http/Http.php#L20-L48
226,510
thelia-modules/Atos
Model/Map/AtosCurrencyTableMap.php
AtosCurrencyTableMap.doDelete
public static function doDelete($values, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(AtosCurrencyTableMap::DATABASE_NAME); } if ($values instanceof Criteria) { // rename for clarity $criteria = $values; } elseif ($values instanceof \Atos\Model\AtosCurrency) { // it's a model object // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it's a primary key, or an array of pks $criteria = new Criteria(AtosCurrencyTableMap::DATABASE_NAME); $criteria->add(AtosCurrencyTableMap::CODE, (array) $values, Criteria::IN); } $query = AtosCurrencyQuery::create()->mergeWith($criteria); if ($values instanceof Criteria) { AtosCurrencyTableMap::clearInstancePool(); } elseif (!is_object($values)) { // it's a primary key, or an array of pks foreach ((array) $values as $singleval) { AtosCurrencyTableMap::removeInstanceFromPool($singleval); } } return $query->delete($con); }
php
public static function doDelete($values, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(AtosCurrencyTableMap::DATABASE_NAME); } if ($values instanceof Criteria) { // rename for clarity $criteria = $values; } elseif ($values instanceof \Atos\Model\AtosCurrency) { // it's a model object // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it's a primary key, or an array of pks $criteria = new Criteria(AtosCurrencyTableMap::DATABASE_NAME); $criteria->add(AtosCurrencyTableMap::CODE, (array) $values, Criteria::IN); } $query = AtosCurrencyQuery::create()->mergeWith($criteria); if ($values instanceof Criteria) { AtosCurrencyTableMap::clearInstancePool(); } elseif (!is_object($values)) { // it's a primary key, or an array of pks foreach ((array) $values as $singleval) { AtosCurrencyTableMap::removeInstanceFromPool($singleval); } } return $query->delete($con); }
[ "public", "static", "function", "doDelete", "(", "$", "values", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "if", "(", "null", "===", "$", "con", ")", "{", "$", "con", "=", "Propel", "::", "getServiceContainer", "(", ")", "->", "getWriteConnection", "(", "AtosCurrencyTableMap", "::", "DATABASE_NAME", ")", ";", "}", "if", "(", "$", "values", "instanceof", "Criteria", ")", "{", "// rename for clarity", "$", "criteria", "=", "$", "values", ";", "}", "elseif", "(", "$", "values", "instanceof", "\\", "Atos", "\\", "Model", "\\", "AtosCurrency", ")", "{", "// it's a model object", "// create criteria based on pk values", "$", "criteria", "=", "$", "values", "->", "buildPkeyCriteria", "(", ")", ";", "}", "else", "{", "// it's a primary key, or an array of pks", "$", "criteria", "=", "new", "Criteria", "(", "AtosCurrencyTableMap", "::", "DATABASE_NAME", ")", ";", "$", "criteria", "->", "add", "(", "AtosCurrencyTableMap", "::", "CODE", ",", "(", "array", ")", "$", "values", ",", "Criteria", "::", "IN", ")", ";", "}", "$", "query", "=", "AtosCurrencyQuery", "::", "create", "(", ")", "->", "mergeWith", "(", "$", "criteria", ")", ";", "if", "(", "$", "values", "instanceof", "Criteria", ")", "{", "AtosCurrencyTableMap", "::", "clearInstancePool", "(", ")", ";", "}", "elseif", "(", "!", "is_object", "(", "$", "values", ")", ")", "{", "// it's a primary key, or an array of pks", "foreach", "(", "(", "array", ")", "$", "values", "as", "$", "singleval", ")", "{", "AtosCurrencyTableMap", "::", "removeInstanceFromPool", "(", "$", "singleval", ")", ";", "}", "}", "return", "$", "query", "->", "delete", "(", "$", "con", ")", ";", "}" ]
Performs a DELETE on the database, given a AtosCurrency or Criteria object OR a primary key value. @param mixed $values Criteria or AtosCurrency object or primary key or array of primary keys which is used to create the DELETE statement @param ConnectionInterface $con the connection to use @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows if supported by native driver or if emulated using Propel. @throws PropelException Any exceptions caught during processing will be rethrown wrapped into a PropelException.
[ "Performs", "a", "DELETE", "on", "the", "database", "given", "a", "AtosCurrency", "or", "Criteria", "object", "OR", "a", "primary", "key", "value", "." ]
1084b7728bf8f914001e8515f88e2e5c007cc487
https://github.com/thelia-modules/Atos/blob/1084b7728bf8f914001e8515f88e2e5c007cc487/Model/Map/AtosCurrencyTableMap.php#L331-L357
226,511
botman/driver-hangouts
src/HangoutsDriver.php
HangoutsDriver.loadMessages
protected function loadMessages() { $message = $this->event->get('message'); $text = $message['text']; if ($this->config->get('strip_annotations') === true && isset($message['annotations'])) { $start = $message['annotations'][0]['startIndex']; $length = $message['annotations'][0]['length']; $text = substr($text, $start + $length + 1); } $this->messages = [new IncomingMessage($text, $message['sender']['name'], $message['name'], $this->event->toArray())]; }
php
protected function loadMessages() { $message = $this->event->get('message'); $text = $message['text']; if ($this->config->get('strip_annotations') === true && isset($message['annotations'])) { $start = $message['annotations'][0]['startIndex']; $length = $message['annotations'][0]['length']; $text = substr($text, $start + $length + 1); } $this->messages = [new IncomingMessage($text, $message['sender']['name'], $message['name'], $this->event->toArray())]; }
[ "protected", "function", "loadMessages", "(", ")", "{", "$", "message", "=", "$", "this", "->", "event", "->", "get", "(", "'message'", ")", ";", "$", "text", "=", "$", "message", "[", "'text'", "]", ";", "if", "(", "$", "this", "->", "config", "->", "get", "(", "'strip_annotations'", ")", "===", "true", "&&", "isset", "(", "$", "message", "[", "'annotations'", "]", ")", ")", "{", "$", "start", "=", "$", "message", "[", "'annotations'", "]", "[", "0", "]", "[", "'startIndex'", "]", ";", "$", "length", "=", "$", "message", "[", "'annotations'", "]", "[", "0", "]", "[", "'length'", "]", ";", "$", "text", "=", "substr", "(", "$", "text", ",", "$", "start", "+", "$", "length", "+", "1", ")", ";", "}", "$", "this", "->", "messages", "=", "[", "new", "IncomingMessage", "(", "$", "text", ",", "$", "message", "[", "'sender'", "]", "[", "'name'", "]", ",", "$", "message", "[", "'name'", "]", ",", "$", "this", "->", "event", "->", "toArray", "(", ")", ")", "]", ";", "}" ]
Load the messages from the incoming payload.
[ "Load", "the", "messages", "from", "the", "incoming", "payload", "." ]
2e88f1a1589d4d09e5626652a42fef843eef5600
https://github.com/botman/driver-hangouts/blob/2e88f1a1589d4d09e5626652a42fef843eef5600/src/HangoutsDriver.php#L80-L93
226,512
thelia-modules/Atos
Model/Base/AtosCurrencyQuery.php
AtosCurrencyQuery.create
public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof \Atos\Model\AtosCurrencyQuery) { return $criteria; } $query = new \Atos\Model\AtosCurrencyQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
php
public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof \Atos\Model\AtosCurrencyQuery) { return $criteria; } $query = new \Atos\Model\AtosCurrencyQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
[ "public", "static", "function", "create", "(", "$", "modelAlias", "=", "null", ",", "$", "criteria", "=", "null", ")", "{", "if", "(", "$", "criteria", "instanceof", "\\", "Atos", "\\", "Model", "\\", "AtosCurrencyQuery", ")", "{", "return", "$", "criteria", ";", "}", "$", "query", "=", "new", "\\", "Atos", "\\", "Model", "\\", "AtosCurrencyQuery", "(", ")", ";", "if", "(", "null", "!==", "$", "modelAlias", ")", "{", "$", "query", "->", "setModelAlias", "(", "$", "modelAlias", ")", ";", "}", "if", "(", "$", "criteria", "instanceof", "Criteria", ")", "{", "$", "query", "->", "mergeWith", "(", "$", "criteria", ")", ";", "}", "return", "$", "query", ";", "}" ]
Returns a new ChildAtosCurrencyQuery object. @param string $modelAlias The alias of a model in the query @param Criteria $criteria Optional Criteria to build the query from @return ChildAtosCurrencyQuery
[ "Returns", "a", "new", "ChildAtosCurrencyQuery", "object", "." ]
1084b7728bf8f914001e8515f88e2e5c007cc487
https://github.com/thelia-modules/Atos/blob/1084b7728bf8f914001e8515f88e2e5c007cc487/Model/Base/AtosCurrencyQuery.php#L68-L82
226,513
thelia-modules/Atos
Model/Base/AtosCurrencyQuery.php
AtosCurrencyQuery.filterByAtosCode
public function filterByAtosCode($atosCode = null, $comparison = null) { if (is_array($atosCode)) { $useMinMax = false; if (isset($atosCode['min'])) { $this->addUsingAlias(AtosCurrencyTableMap::ATOS_CODE, $atosCode['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($atosCode['max'])) { $this->addUsingAlias(AtosCurrencyTableMap::ATOS_CODE, $atosCode['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { return $this; } if (null === $comparison) { $comparison = Criteria::IN; } } return $this->addUsingAlias(AtosCurrencyTableMap::ATOS_CODE, $atosCode, $comparison); }
php
public function filterByAtosCode($atosCode = null, $comparison = null) { if (is_array($atosCode)) { $useMinMax = false; if (isset($atosCode['min'])) { $this->addUsingAlias(AtosCurrencyTableMap::ATOS_CODE, $atosCode['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($atosCode['max'])) { $this->addUsingAlias(AtosCurrencyTableMap::ATOS_CODE, $atosCode['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { return $this; } if (null === $comparison) { $comparison = Criteria::IN; } } return $this->addUsingAlias(AtosCurrencyTableMap::ATOS_CODE, $atosCode, $comparison); }
[ "public", "function", "filterByAtosCode", "(", "$", "atosCode", "=", "null", ",", "$", "comparison", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "atosCode", ")", ")", "{", "$", "useMinMax", "=", "false", ";", "if", "(", "isset", "(", "$", "atosCode", "[", "'min'", "]", ")", ")", "{", "$", "this", "->", "addUsingAlias", "(", "AtosCurrencyTableMap", "::", "ATOS_CODE", ",", "$", "atosCode", "[", "'min'", "]", ",", "Criteria", "::", "GREATER_EQUAL", ")", ";", "$", "useMinMax", "=", "true", ";", "}", "if", "(", "isset", "(", "$", "atosCode", "[", "'max'", "]", ")", ")", "{", "$", "this", "->", "addUsingAlias", "(", "AtosCurrencyTableMap", "::", "ATOS_CODE", ",", "$", "atosCode", "[", "'max'", "]", ",", "Criteria", "::", "LESS_EQUAL", ")", ";", "$", "useMinMax", "=", "true", ";", "}", "if", "(", "$", "useMinMax", ")", "{", "return", "$", "this", ";", "}", "if", "(", "null", "===", "$", "comparison", ")", "{", "$", "comparison", "=", "Criteria", "::", "IN", ";", "}", "}", "return", "$", "this", "->", "addUsingAlias", "(", "AtosCurrencyTableMap", "::", "ATOS_CODE", ",", "$", "atosCode", ",", "$", "comparison", ")", ";", "}" ]
Filter the query on the atos_code column Example usage: <code> $query->filterByAtosCode(1234); // WHERE atos_code = 1234 $query->filterByAtosCode(array(12, 34)); // WHERE atos_code IN (12, 34) $query->filterByAtosCode(array('min' => 12)); // WHERE atos_code > 12 </code> @param mixed $atosCode The value to use as filter. Use scalar values for equality. Use array values for in_array() equivalent. Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL @return ChildAtosCurrencyQuery The current query, for fluid interface
[ "Filter", "the", "query", "on", "the", "atos_code", "column" ]
1084b7728bf8f914001e8515f88e2e5c007cc487
https://github.com/thelia-modules/Atos/blob/1084b7728bf8f914001e8515f88e2e5c007cc487/Model/Base/AtosCurrencyQuery.php#L265-L286
226,514
thelia-modules/Atos
Model/Base/AtosCurrencyQuery.php
AtosCurrencyQuery.filterByDecimals
public function filterByDecimals($decimals = null, $comparison = null) { if (is_array($decimals)) { $useMinMax = false; if (isset($decimals['min'])) { $this->addUsingAlias(AtosCurrencyTableMap::DECIMALS, $decimals['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($decimals['max'])) { $this->addUsingAlias(AtosCurrencyTableMap::DECIMALS, $decimals['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { return $this; } if (null === $comparison) { $comparison = Criteria::IN; } } return $this->addUsingAlias(AtosCurrencyTableMap::DECIMALS, $decimals, $comparison); }
php
public function filterByDecimals($decimals = null, $comparison = null) { if (is_array($decimals)) { $useMinMax = false; if (isset($decimals['min'])) { $this->addUsingAlias(AtosCurrencyTableMap::DECIMALS, $decimals['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($decimals['max'])) { $this->addUsingAlias(AtosCurrencyTableMap::DECIMALS, $decimals['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { return $this; } if (null === $comparison) { $comparison = Criteria::IN; } } return $this->addUsingAlias(AtosCurrencyTableMap::DECIMALS, $decimals, $comparison); }
[ "public", "function", "filterByDecimals", "(", "$", "decimals", "=", "null", ",", "$", "comparison", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "decimals", ")", ")", "{", "$", "useMinMax", "=", "false", ";", "if", "(", "isset", "(", "$", "decimals", "[", "'min'", "]", ")", ")", "{", "$", "this", "->", "addUsingAlias", "(", "AtosCurrencyTableMap", "::", "DECIMALS", ",", "$", "decimals", "[", "'min'", "]", ",", "Criteria", "::", "GREATER_EQUAL", ")", ";", "$", "useMinMax", "=", "true", ";", "}", "if", "(", "isset", "(", "$", "decimals", "[", "'max'", "]", ")", ")", "{", "$", "this", "->", "addUsingAlias", "(", "AtosCurrencyTableMap", "::", "DECIMALS", ",", "$", "decimals", "[", "'max'", "]", ",", "Criteria", "::", "LESS_EQUAL", ")", ";", "$", "useMinMax", "=", "true", ";", "}", "if", "(", "$", "useMinMax", ")", "{", "return", "$", "this", ";", "}", "if", "(", "null", "===", "$", "comparison", ")", "{", "$", "comparison", "=", "Criteria", "::", "IN", ";", "}", "}", "return", "$", "this", "->", "addUsingAlias", "(", "AtosCurrencyTableMap", "::", "DECIMALS", ",", "$", "decimals", ",", "$", "comparison", ")", ";", "}" ]
Filter the query on the decimals column Example usage: <code> $query->filterByDecimals(1234); // WHERE decimals = 1234 $query->filterByDecimals(array(12, 34)); // WHERE decimals IN (12, 34) $query->filterByDecimals(array('min' => 12)); // WHERE decimals > 12 </code> @param mixed $decimals The value to use as filter. Use scalar values for equality. Use array values for in_array() equivalent. Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL @return ChildAtosCurrencyQuery The current query, for fluid interface
[ "Filter", "the", "query", "on", "the", "decimals", "column" ]
1084b7728bf8f914001e8515f88e2e5c007cc487
https://github.com/thelia-modules/Atos/blob/1084b7728bf8f914001e8515f88e2e5c007cc487/Model/Base/AtosCurrencyQuery.php#L306-L327
226,515
phergie/phergie-irc-bot-react
src/Bot.php
Bot.setLogger
public function setLogger(LoggerInterface $logger) { $this->logger = $logger; $this->getClient()->setLogger($logger); }
php
public function setLogger(LoggerInterface $logger) { $this->logger = $logger; $this->getClient()->setLogger($logger); }
[ "public", "function", "setLogger", "(", "LoggerInterface", "$", "logger", ")", "{", "$", "this", "->", "logger", "=", "$", "logger", ";", "$", "this", "->", "getClient", "(", ")", "->", "setLogger", "(", "$", "logger", ")", ";", "}" ]
Sets the logger in use by the bot. @param \Psr\Log\LoggerInterface $logger
[ "Sets", "the", "logger", "in", "use", "by", "the", "bot", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L137-L141
226,516
phergie/phergie-irc-bot-react
src/Bot.php
Bot.getLogger
public function getLogger() { if (!$this->logger) { $this->logger = $this->getClient()->getLogger(); } return $this->logger; }
php
public function getLogger() { if (!$this->logger) { $this->logger = $this->getClient()->getLogger(); } return $this->logger; }
[ "public", "function", "getLogger", "(", ")", "{", "if", "(", "!", "$", "this", "->", "logger", ")", "{", "$", "this", "->", "logger", "=", "$", "this", "->", "getClient", "(", ")", "->", "getLogger", "(", ")", ";", "}", "return", "$", "this", "->", "logger", ";", "}" ]
Returns the logger in use by the bot. @return \Psr\Log\LoggerInterface
[ "Returns", "the", "logger", "in", "use", "by", "the", "bot", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L148-L154
226,517
phergie/phergie-irc-bot-react
src/Bot.php
Bot.run
public function run($autorun = true) { $this->setDependencyOverrides($this->config); $this->getPlugins($this->config); $connections = $this->getConnections($this->config); $this->getClient()->run($connections, $autorun); }
php
public function run($autorun = true) { $this->setDependencyOverrides($this->config); $this->getPlugins($this->config); $connections = $this->getConnections($this->config); $this->getClient()->run($connections, $autorun); }
[ "public", "function", "run", "(", "$", "autorun", "=", "true", ")", "{", "$", "this", "->", "setDependencyOverrides", "(", "$", "this", "->", "config", ")", ";", "$", "this", "->", "getPlugins", "(", "$", "this", "->", "config", ")", ";", "$", "connections", "=", "$", "this", "->", "getConnections", "(", "$", "this", "->", "config", ")", ";", "$", "this", "->", "getClient", "(", ")", "->", "run", "(", "$", "connections", ",", "$", "autorun", ")", ";", "}" ]
Initiates an event loop for the bot in which it will connect to servers and monitor those connections for events to forward to plugins. @param bool $autorun @throws \RuntimeException if configuration is inconsistent with expected structure
[ "Initiates", "an", "event", "loop", "for", "the", "bot", "in", "which", "it", "will", "connect", "to", "servers", "and", "monitor", "those", "connections", "for", "events", "to", "forward", "to", "plugins", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L234-L240
226,518
phergie/phergie-irc-bot-react
src/Bot.php
Bot.setDependencyOverrides
protected function setDependencyOverrides(array $config) { if (isset($config['client'])) { $this->setClient($config['client']); } if (isset($config['logger'])) { $this->setLogger($config['logger']); } if (isset($config['parser'])) { $this->setParser($config['parser']); } if (isset($config['converter'])) { $this->setConverter($config['converter']); } if (isset($config['eventQueueFactory'])) { $this->setEventQueueFactory($config['eventQueueFactory']); } }
php
protected function setDependencyOverrides(array $config) { if (isset($config['client'])) { $this->setClient($config['client']); } if (isset($config['logger'])) { $this->setLogger($config['logger']); } if (isset($config['parser'])) { $this->setParser($config['parser']); } if (isset($config['converter'])) { $this->setConverter($config['converter']); } if (isset($config['eventQueueFactory'])) { $this->setEventQueueFactory($config['eventQueueFactory']); } }
[ "protected", "function", "setDependencyOverrides", "(", "array", "$", "config", ")", "{", "if", "(", "isset", "(", "$", "config", "[", "'client'", "]", ")", ")", "{", "$", "this", "->", "setClient", "(", "$", "config", "[", "'client'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'logger'", "]", ")", ")", "{", "$", "this", "->", "setLogger", "(", "$", "config", "[", "'logger'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'parser'", "]", ")", ")", "{", "$", "this", "->", "setParser", "(", "$", "config", "[", "'parser'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'converter'", "]", ")", ")", "{", "$", "this", "->", "setConverter", "(", "$", "config", "[", "'converter'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'eventQueueFactory'", "]", ")", ")", "{", "$", "this", "->", "setEventQueueFactory", "(", "$", "config", "[", "'eventQueueFactory'", "]", ")", ";", "}", "}" ]
Sets dependencies from configuration. @param array $config
[ "Sets", "dependencies", "from", "configuration", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L247-L268
226,519
phergie/phergie-irc-bot-react
src/Bot.php
Bot.getConnections
protected function getConnections(array $config) { if (!isset($config['connections'])) { throw new \RuntimeException('Configuration must contain a "connections" key'); } if (!is_array($config['connections']) || !$config['connections']) { throw new \RuntimeException('Configuration "connections" key must reference a non-empty array'); } $connections = array_filter( $config['connections'], function ($connection) { return $connection instanceof ConnectionInterface; } ); if (count($connections) != count($config['connections'])) { throw new \RuntimeException( 'All configuration "connections" array values must implement \Phergie\Irc\ConnectionInterface' ); } return $connections; }
php
protected function getConnections(array $config) { if (!isset($config['connections'])) { throw new \RuntimeException('Configuration must contain a "connections" key'); } if (!is_array($config['connections']) || !$config['connections']) { throw new \RuntimeException('Configuration "connections" key must reference a non-empty array'); } $connections = array_filter( $config['connections'], function ($connection) { return $connection instanceof ConnectionInterface; } ); if (count($connections) != count($config['connections'])) { throw new \RuntimeException( 'All configuration "connections" array values must implement \Phergie\Irc\ConnectionInterface' ); } return $connections; }
[ "protected", "function", "getConnections", "(", "array", "$", "config", ")", "{", "if", "(", "!", "isset", "(", "$", "config", "[", "'connections'", "]", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Configuration must contain a \"connections\" key'", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "config", "[", "'connections'", "]", ")", "||", "!", "$", "config", "[", "'connections'", "]", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Configuration \"connections\" key must reference a non-empty array'", ")", ";", "}", "$", "connections", "=", "array_filter", "(", "$", "config", "[", "'connections'", "]", ",", "function", "(", "$", "connection", ")", "{", "return", "$", "connection", "instanceof", "ConnectionInterface", ";", "}", ")", ";", "if", "(", "count", "(", "$", "connections", ")", "!=", "count", "(", "$", "config", "[", "'connections'", "]", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'All configuration \"connections\" array values must implement \\Phergie\\Irc\\ConnectionInterface'", ")", ";", "}", "return", "$", "connections", ";", "}" ]
Extracts connections from configuration. @param array $config Associative array keyed by setting name @return \Phergie\Irc\ConnectionInterface[]
[ "Extracts", "connections", "from", "configuration", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L276-L299
226,520
phergie/phergie-irc-bot-react
src/Bot.php
Bot.getPlugins
protected function getPlugins(array $config) { if (!isset($config['plugins'])) { throw new \RuntimeException('Configuration must contain a "plugins" key'); } if (!is_array($config['plugins'])) { throw new \RuntimeException('Configuration "plugins" key must reference an array'); } $plugins = array_filter( $config['plugins'], function ($plugin) { return $plugin instanceof PluginInterface; } ); if (count($plugins) != count($config['plugins'])) { throw new \RuntimeException( 'All configuration "plugins" array values must implement \Phergie\Irc\Bot\React\PluginInterface' ); } $this->registerPluginSubscribers($plugins); $processors = $this->getPluginProcessors($config); $this->processPlugins($plugins, $processors); return $plugins; }
php
protected function getPlugins(array $config) { if (!isset($config['plugins'])) { throw new \RuntimeException('Configuration must contain a "plugins" key'); } if (!is_array($config['plugins'])) { throw new \RuntimeException('Configuration "plugins" key must reference an array'); } $plugins = array_filter( $config['plugins'], function ($plugin) { return $plugin instanceof PluginInterface; } ); if (count($plugins) != count($config['plugins'])) { throw new \RuntimeException( 'All configuration "plugins" array values must implement \Phergie\Irc\Bot\React\PluginInterface' ); } $this->registerPluginSubscribers($plugins); $processors = $this->getPluginProcessors($config); $this->processPlugins($plugins, $processors); return $plugins; }
[ "protected", "function", "getPlugins", "(", "array", "$", "config", ")", "{", "if", "(", "!", "isset", "(", "$", "config", "[", "'plugins'", "]", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Configuration must contain a \"plugins\" key'", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "config", "[", "'plugins'", "]", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Configuration \"plugins\" key must reference an array'", ")", ";", "}", "$", "plugins", "=", "array_filter", "(", "$", "config", "[", "'plugins'", "]", ",", "function", "(", "$", "plugin", ")", "{", "return", "$", "plugin", "instanceof", "PluginInterface", ";", "}", ")", ";", "if", "(", "count", "(", "$", "plugins", ")", "!=", "count", "(", "$", "config", "[", "'plugins'", "]", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'All configuration \"plugins\" array values must implement \\Phergie\\Irc\\Bot\\React\\PluginInterface'", ")", ";", "}", "$", "this", "->", "registerPluginSubscribers", "(", "$", "plugins", ")", ";", "$", "processors", "=", "$", "this", "->", "getPluginProcessors", "(", "$", "config", ")", ";", "$", "this", "->", "processPlugins", "(", "$", "plugins", ",", "$", "processors", ")", ";", "return", "$", "plugins", ";", "}" ]
Extracts plugins from configuration. @param array $config Associative array keyed by setting name @throws \RuntimeException if any plugin event callback is invalid @return \Phergie\Irc\Bot\React\PluginInterface[]
[ "Extracts", "plugins", "from", "configuration", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L308-L336
226,521
phergie/phergie-irc-bot-react
src/Bot.php
Bot.processPlugins
protected function processPlugins(array $plugins, array $processors, \SplObjectStorage $processedPlugins = null) { // Initialise store of already-processed plugins, to prevent container-based endless recursion if ($processedPlugins === null) { $processedPlugins = new \SplObjectStorage; } foreach ($plugins as $plugin) { if ($processedPlugins->contains($plugin)) { continue; } $processedPlugins->attach($plugin); foreach ($processors as $processor) { $processor->process($plugin, $this); } if ($plugin instanceof PluginContainerInterface) { $this->processPlugins($plugin->getPlugins(), $processors, $processedPlugins); } } }
php
protected function processPlugins(array $plugins, array $processors, \SplObjectStorage $processedPlugins = null) { // Initialise store of already-processed plugins, to prevent container-based endless recursion if ($processedPlugins === null) { $processedPlugins = new \SplObjectStorage; } foreach ($plugins as $plugin) { if ($processedPlugins->contains($plugin)) { continue; } $processedPlugins->attach($plugin); foreach ($processors as $processor) { $processor->process($plugin, $this); } if ($plugin instanceof PluginContainerInterface) { $this->processPlugins($plugin->getPlugins(), $processors, $processedPlugins); } } }
[ "protected", "function", "processPlugins", "(", "array", "$", "plugins", ",", "array", "$", "processors", ",", "\\", "SplObjectStorage", "$", "processedPlugins", "=", "null", ")", "{", "// Initialise store of already-processed plugins, to prevent container-based endless recursion", "if", "(", "$", "processedPlugins", "===", "null", ")", "{", "$", "processedPlugins", "=", "new", "\\", "SplObjectStorage", ";", "}", "foreach", "(", "$", "plugins", "as", "$", "plugin", ")", "{", "if", "(", "$", "processedPlugins", "->", "contains", "(", "$", "plugin", ")", ")", "{", "continue", ";", "}", "$", "processedPlugins", "->", "attach", "(", "$", "plugin", ")", ";", "foreach", "(", "$", "processors", "as", "$", "processor", ")", "{", "$", "processor", "->", "process", "(", "$", "plugin", ",", "$", "this", ")", ";", "}", "if", "(", "$", "plugin", "instanceof", "PluginContainerInterface", ")", "{", "$", "this", "->", "processPlugins", "(", "$", "plugin", "->", "getPlugins", "(", ")", ",", "$", "processors", ",", "$", "processedPlugins", ")", ";", "}", "}", "}" ]
Processes a list of plugins for use. @param \Phergie\Irc\Bot\React\PluginInterface[] @param \Phergie\Irc\Bot\React\PluginProcessor\PluginProcessorInterface[] @param \SplObjectStorage $processedPlugins
[ "Processes", "a", "list", "of", "plugins", "for", "use", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L345-L363
226,522
phergie/phergie-irc-bot-react
src/Bot.php
Bot.getPluginProcessors
protected function getPluginProcessors(array $config) { $processors = isset($config['pluginProcessors']) ? $config['pluginProcessors'] : $this->getDefaultPluginProcessors(); if (!is_array($processors)) { throw new \RuntimeException('Configuration "pluginProcessors" key must reference an array'); } if (!empty($processors)) { $invalid = array_filter( $processors, function ($processor) { return !$processor instanceof PluginProcessorInterface; } ); if (!empty($invalid)) { throw new \RuntimeException( 'All configuration "pluginProcessors" array values must implement' . ' \Phergie\Irc\Bot\React\PluginProcessor\PluginProcessorInterface' ); } } return $processors; }
php
protected function getPluginProcessors(array $config) { $processors = isset($config['pluginProcessors']) ? $config['pluginProcessors'] : $this->getDefaultPluginProcessors(); if (!is_array($processors)) { throw new \RuntimeException('Configuration "pluginProcessors" key must reference an array'); } if (!empty($processors)) { $invalid = array_filter( $processors, function ($processor) { return !$processor instanceof PluginProcessorInterface; } ); if (!empty($invalid)) { throw new \RuntimeException( 'All configuration "pluginProcessors" array values must implement' . ' \Phergie\Irc\Bot\React\PluginProcessor\PluginProcessorInterface' ); } } return $processors; }
[ "protected", "function", "getPluginProcessors", "(", "array", "$", "config", ")", "{", "$", "processors", "=", "isset", "(", "$", "config", "[", "'pluginProcessors'", "]", ")", "?", "$", "config", "[", "'pluginProcessors'", "]", ":", "$", "this", "->", "getDefaultPluginProcessors", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "processors", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Configuration \"pluginProcessors\" key must reference an array'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "processors", ")", ")", "{", "$", "invalid", "=", "array_filter", "(", "$", "processors", ",", "function", "(", "$", "processor", ")", "{", "return", "!", "$", "processor", "instanceof", "PluginProcessorInterface", ";", "}", ")", ";", "if", "(", "!", "empty", "(", "$", "invalid", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'All configuration \"pluginProcessors\" array values must implement'", ".", "' \\Phergie\\Irc\\Bot\\React\\PluginProcessor\\PluginProcessorInterface'", ")", ";", "}", "}", "return", "$", "processors", ";", "}" ]
Returns a list of processors for plugins. @param array $config Associative array keyed by setting name
[ "Returns", "a", "list", "of", "processors", "for", "plugins", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L370-L396
226,523
phergie/phergie-irc-bot-react
src/Bot.php
Bot.validatePluginEvents
protected function validatePluginEvents(PluginInterface $plugin) { $events = $plugin->getSubscribedEvents(); if (!is_array($events)) { throw new \RuntimeException( 'Plugin of class ' . get_class($plugin) . ' has getSubscribedEvents() implementation' . ' that does not return an array' ); } foreach ($events as $event => $callback) { if (!is_string($event) || !is_callable([ $plugin, $callback ]) && !is_callable($callback)) { throw new \RuntimeException( 'Plugin of class ' . get_class($plugin) . ' returns non-string event name or invalid callback' . ' for event "' . $event . '"' ); } } }
php
protected function validatePluginEvents(PluginInterface $plugin) { $events = $plugin->getSubscribedEvents(); if (!is_array($events)) { throw new \RuntimeException( 'Plugin of class ' . get_class($plugin) . ' has getSubscribedEvents() implementation' . ' that does not return an array' ); } foreach ($events as $event => $callback) { if (!is_string($event) || !is_callable([ $plugin, $callback ]) && !is_callable($callback)) { throw new \RuntimeException( 'Plugin of class ' . get_class($plugin) . ' returns non-string event name or invalid callback' . ' for event "' . $event . '"' ); } } }
[ "protected", "function", "validatePluginEvents", "(", "PluginInterface", "$", "plugin", ")", "{", "$", "events", "=", "$", "plugin", "->", "getSubscribedEvents", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "events", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Plugin of class '", ".", "get_class", "(", "$", "plugin", ")", ".", "' has getSubscribedEvents() implementation'", ".", "' that does not return an array'", ")", ";", "}", "foreach", "(", "$", "events", "as", "$", "event", "=>", "$", "callback", ")", "{", "if", "(", "!", "is_string", "(", "$", "event", ")", "||", "!", "is_callable", "(", "[", "$", "plugin", ",", "$", "callback", "]", ")", "&&", "!", "is_callable", "(", "$", "callback", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Plugin of class '", ".", "get_class", "(", "$", "plugin", ")", ".", "' returns non-string event name or invalid callback'", ".", "' for event \"'", ".", "$", "event", ".", "'\"'", ")", ";", "}", "}", "}" ]
Validates a plugin's event callbacks. @param \Phergie\Irc\Bot\React\PluginInterface $plugin @throws \RuntimeException if any event callback is invalid
[ "Validates", "a", "plugin", "s", "event", "callbacks", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L423-L444
226,524
phergie/phergie-irc-bot-react
src/Bot.php
Bot.registerClientSubscribers
protected function registerClientSubscribers(ClientInterface $client) { $client->on('irc.received', function ($message, $write, $connection) { $this->processClientEvent('irc.received', $message, $connection, $write); }); $client->on('irc.sent', function ($message, $write, $connection) { $parsed = $this->getParser()->parse($message); if (!$parsed) { return; } $this->processClientEvent('irc.sent', $parsed, $connection, $write); }); $client->on('irc.tick', function ($write, $connection) { $this->processOutgoingEvents($connection, $write); }); }
php
protected function registerClientSubscribers(ClientInterface $client) { $client->on('irc.received', function ($message, $write, $connection) { $this->processClientEvent('irc.received', $message, $connection, $write); }); $client->on('irc.sent', function ($message, $write, $connection) { $parsed = $this->getParser()->parse($message); if (!$parsed) { return; } $this->processClientEvent('irc.sent', $parsed, $connection, $write); }); $client->on('irc.tick', function ($write, $connection) { $this->processOutgoingEvents($connection, $write); }); }
[ "protected", "function", "registerClientSubscribers", "(", "ClientInterface", "$", "client", ")", "{", "$", "client", "->", "on", "(", "'irc.received'", ",", "function", "(", "$", "message", ",", "$", "write", ",", "$", "connection", ")", "{", "$", "this", "->", "processClientEvent", "(", "'irc.received'", ",", "$", "message", ",", "$", "connection", ",", "$", "write", ")", ";", "}", ")", ";", "$", "client", "->", "on", "(", "'irc.sent'", ",", "function", "(", "$", "message", ",", "$", "write", ",", "$", "connection", ")", "{", "$", "parsed", "=", "$", "this", "->", "getParser", "(", ")", "->", "parse", "(", "$", "message", ")", ";", "if", "(", "!", "$", "parsed", ")", "{", "return", ";", "}", "$", "this", "->", "processClientEvent", "(", "'irc.sent'", ",", "$", "parsed", ",", "$", "connection", ",", "$", "write", ")", ";", "}", ")", ";", "$", "client", "->", "on", "(", "'irc.tick'", ",", "function", "(", "$", "write", ",", "$", "connection", ")", "{", "$", "this", "->", "processOutgoingEvents", "(", "$", "connection", ",", "$", "write", ")", ";", "}", ")", ";", "}" ]
Configures the client to emit events for specific types of messages. @param \Phergie\Irc\Client\React\ClientInterface $client Client for which to configure events
[ "Configures", "the", "client", "to", "emit", "events", "for", "specific", "types", "of", "messages", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L452-L469
226,525
phergie/phergie-irc-bot-react
src/Bot.php
Bot.processClientEvent
public function processClientEvent($event, array $message, ConnectionInterface $connection, WriteStream $write) { $converter = $this->getConverter(); $converted = $converter->convert($message); $converted->setConnection($connection); $client = $this->getClient(); $queue = $this->getEventQueueFactory()->getEventQueue($connection); $params = [ $converted, $queue ]; $subtype = $this->getEventSubtype($converted); $client->emit($event . '.each', $params); $client->emit($event . '.' . $subtype, $params); $this->processOutgoingEvents($connection, $write); }
php
public function processClientEvent($event, array $message, ConnectionInterface $connection, WriteStream $write) { $converter = $this->getConverter(); $converted = $converter->convert($message); $converted->setConnection($connection); $client = $this->getClient(); $queue = $this->getEventQueueFactory()->getEventQueue($connection); $params = [ $converted, $queue ]; $subtype = $this->getEventSubtype($converted); $client->emit($event . '.each', $params); $client->emit($event . '.' . $subtype, $params); $this->processOutgoingEvents($connection, $write); }
[ "public", "function", "processClientEvent", "(", "$", "event", ",", "array", "$", "message", ",", "ConnectionInterface", "$", "connection", ",", "WriteStream", "$", "write", ")", "{", "$", "converter", "=", "$", "this", "->", "getConverter", "(", ")", ";", "$", "converted", "=", "$", "converter", "->", "convert", "(", "$", "message", ")", ";", "$", "converted", "->", "setConnection", "(", "$", "connection", ")", ";", "$", "client", "=", "$", "this", "->", "getClient", "(", ")", ";", "$", "queue", "=", "$", "this", "->", "getEventQueueFactory", "(", ")", "->", "getEventQueue", "(", "$", "connection", ")", ";", "$", "params", "=", "[", "$", "converted", ",", "$", "queue", "]", ";", "$", "subtype", "=", "$", "this", "->", "getEventSubtype", "(", "$", "converted", ")", ";", "$", "client", "->", "emit", "(", "$", "event", ".", "'.each'", ",", "$", "params", ")", ";", "$", "client", "->", "emit", "(", "$", "event", ".", "'.'", ".", "$", "subtype", ",", "$", "params", ")", ";", "$", "this", "->", "processOutgoingEvents", "(", "$", "connection", ",", "$", "write", ")", ";", "}" ]
Callback to process client events. Not intended to be called from outside this class. @param string $event Received client event @param array $message Parsed message @param \Phergie\Irc\ConnectionInterface $connection Connection on which the event occurred @param \Phergie\Irc\Client\React\WriteStream $write Stream used to send commands to the server
[ "Callback", "to", "process", "client", "events", ".", "Not", "intended", "to", "be", "called", "from", "outside", "this", "class", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L482-L496
226,526
phergie/phergie-irc-bot-react
src/Bot.php
Bot.processOutgoingEvents
public function processOutgoingEvents(ConnectionInterface $connection, WriteStream $write) { $client = $this->getClient(); $queue = $this->getEventQueueFactory()->getEventQueue($connection); $client->emit('irc.sending.all', [ $queue ]); while ($extracted = $queue->extract()) { $extracted->setConnection($connection); $params = [ $extracted, $queue ]; $subtype = $this->getEventSubtype($extracted); $client->emit('irc.sending.each', $params); $client->emit('irc.sending.' . $subtype, $params); if ($extracted instanceof CtcpEvent) { $method = 'ctcp' . $extracted->getCtcpCommand(); if ($extracted->getCommand() === 'NOTICE') { $method .= 'Response'; } } else { $method = 'irc' . $extracted->getCommand(); } call_user_func_array( [ $write, $method ], $extracted->getParams() ); } }
php
public function processOutgoingEvents(ConnectionInterface $connection, WriteStream $write) { $client = $this->getClient(); $queue = $this->getEventQueueFactory()->getEventQueue($connection); $client->emit('irc.sending.all', [ $queue ]); while ($extracted = $queue->extract()) { $extracted->setConnection($connection); $params = [ $extracted, $queue ]; $subtype = $this->getEventSubtype($extracted); $client->emit('irc.sending.each', $params); $client->emit('irc.sending.' . $subtype, $params); if ($extracted instanceof CtcpEvent) { $method = 'ctcp' . $extracted->getCtcpCommand(); if ($extracted->getCommand() === 'NOTICE') { $method .= 'Response'; } } else { $method = 'irc' . $extracted->getCommand(); } call_user_func_array( [ $write, $method ], $extracted->getParams() ); } }
[ "public", "function", "processOutgoingEvents", "(", "ConnectionInterface", "$", "connection", ",", "WriteStream", "$", "write", ")", "{", "$", "client", "=", "$", "this", "->", "getClient", "(", ")", ";", "$", "queue", "=", "$", "this", "->", "getEventQueueFactory", "(", ")", "->", "getEventQueue", "(", "$", "connection", ")", ";", "$", "client", "->", "emit", "(", "'irc.sending.all'", ",", "[", "$", "queue", "]", ")", ";", "while", "(", "$", "extracted", "=", "$", "queue", "->", "extract", "(", ")", ")", "{", "$", "extracted", "->", "setConnection", "(", "$", "connection", ")", ";", "$", "params", "=", "[", "$", "extracted", ",", "$", "queue", "]", ";", "$", "subtype", "=", "$", "this", "->", "getEventSubtype", "(", "$", "extracted", ")", ";", "$", "client", "->", "emit", "(", "'irc.sending.each'", ",", "$", "params", ")", ";", "$", "client", "->", "emit", "(", "'irc.sending.'", ".", "$", "subtype", ",", "$", "params", ")", ";", "if", "(", "$", "extracted", "instanceof", "CtcpEvent", ")", "{", "$", "method", "=", "'ctcp'", ".", "$", "extracted", "->", "getCtcpCommand", "(", ")", ";", "if", "(", "$", "extracted", "->", "getCommand", "(", ")", "===", "'NOTICE'", ")", "{", "$", "method", ".=", "'Response'", ";", "}", "}", "else", "{", "$", "method", "=", "'irc'", ".", "$", "extracted", "->", "getCommand", "(", ")", ";", "}", "call_user_func_array", "(", "[", "$", "write", ",", "$", "method", "]", ",", "$", "extracted", "->", "getParams", "(", ")", ")", ";", "}", "}" ]
Callback to process any queued outgoing events. Not intended to be called from outside thie class. @param \Phergie\Irc\ConnectionInterface $connection Connection on which the event occurred @param \Phergie\Irc\Client\React\WriteStream $write Stream used to send commands to the server
[ "Callback", "to", "process", "any", "queued", "outgoing", "events", ".", "Not", "intended", "to", "be", "called", "from", "outside", "thie", "class", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L507-L533
226,527
phergie/phergie-irc-bot-react
src/Bot.php
Bot.getEventSubtype
protected function getEventSubtype(EventInterface $event) { $subevent = ''; if ($event instanceof CtcpEvent) { $subevent = 'ctcp.' . strtolower($event->getCtcpCommand()); } elseif ($event instanceof UserEvent) { $subevent = strtolower($event->getCommand()); } elseif ($event instanceof ServerEvent) { $subevent = strtolower($event->getCode()); } return $subevent; }
php
protected function getEventSubtype(EventInterface $event) { $subevent = ''; if ($event instanceof CtcpEvent) { $subevent = 'ctcp.' . strtolower($event->getCtcpCommand()); } elseif ($event instanceof UserEvent) { $subevent = strtolower($event->getCommand()); } elseif ($event instanceof ServerEvent) { $subevent = strtolower($event->getCode()); } return $subevent; }
[ "protected", "function", "getEventSubtype", "(", "EventInterface", "$", "event", ")", "{", "$", "subevent", "=", "''", ";", "if", "(", "$", "event", "instanceof", "CtcpEvent", ")", "{", "$", "subevent", "=", "'ctcp.'", ".", "strtolower", "(", "$", "event", "->", "getCtcpCommand", "(", ")", ")", ";", "}", "elseif", "(", "$", "event", "instanceof", "UserEvent", ")", "{", "$", "subevent", "=", "strtolower", "(", "$", "event", "->", "getCommand", "(", ")", ")", ";", "}", "elseif", "(", "$", "event", "instanceof", "ServerEvent", ")", "{", "$", "subevent", "=", "strtolower", "(", "$", "event", "->", "getCode", "(", ")", ")", ";", "}", "return", "$", "subevent", ";", "}" ]
Returns an event subtype corresponding to a given event object, used to generate event names when emitting events. @param \Phergie\Irc\Event\EventInterface $event @return string
[ "Returns", "an", "event", "subtype", "corresponding", "to", "a", "given", "event", "object", "used", "to", "generate", "event", "names", "when", "emitting", "events", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L542-L553
226,528
phergie/phergie-irc-bot-react
src/Bot.php
Bot.registerPluginSubscribers
protected function registerPluginSubscribers(array $plugins) { $client = $this->getClient(); foreach ($plugins as $plugin) { $this->validatePluginEvents($plugin); $callbacks = $plugin->getSubscribedEvents(); foreach ($callbacks as $event => $callback) { $pluginCallback = [ $plugin, $callback ]; if (is_callable($pluginCallback)) { $callback = $pluginCallback; } $client->on($event, $callback); } } }
php
protected function registerPluginSubscribers(array $plugins) { $client = $this->getClient(); foreach ($plugins as $plugin) { $this->validatePluginEvents($plugin); $callbacks = $plugin->getSubscribedEvents(); foreach ($callbacks as $event => $callback) { $pluginCallback = [ $plugin, $callback ]; if (is_callable($pluginCallback)) { $callback = $pluginCallback; } $client->on($event, $callback); } } }
[ "protected", "function", "registerPluginSubscribers", "(", "array", "$", "plugins", ")", "{", "$", "client", "=", "$", "this", "->", "getClient", "(", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", ")", "{", "$", "this", "->", "validatePluginEvents", "(", "$", "plugin", ")", ";", "$", "callbacks", "=", "$", "plugin", "->", "getSubscribedEvents", "(", ")", ";", "foreach", "(", "$", "callbacks", "as", "$", "event", "=>", "$", "callback", ")", "{", "$", "pluginCallback", "=", "[", "$", "plugin", ",", "$", "callback", "]", ";", "if", "(", "is_callable", "(", "$", "pluginCallback", ")", ")", "{", "$", "callback", "=", "$", "pluginCallback", ";", "}", "$", "client", "->", "on", "(", "$", "event", ",", "$", "callback", ")", ";", "}", "}", "}" ]
Registers event callbacks from plugins. @param \Phergie\Irc\Bot\React\PluginInterface[] $plugins Plugins from which to get callbacks
[ "Registers", "event", "callbacks", "from", "plugins", "." ]
17745ef6b846513258af3dbd86e5612d3deb19b7
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/Bot.php#L561-L575
226,529
gigaai/framework
src/Storage/Eloquent/HasMeta.php
HasMeta.getMeta
public function getMeta($key = null, $default = null) { if ($key === null) { return $this->meta; } return isset($this->meta[$key]) ? $this->meta[$key] : $default; }
php
public function getMeta($key = null, $default = null) { if ($key === null) { return $this->meta; } return isset($this->meta[$key]) ? $this->meta[$key] : $default; }
[ "public", "function", "getMeta", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "key", "===", "null", ")", "{", "return", "$", "this", "->", "meta", ";", "}", "return", "isset", "(", "$", "this", "->", "meta", "[", "$", "key", "]", ")", "?", "$", "this", "->", "meta", "[", "$", "key", "]", ":", "$", "default", ";", "}" ]
Get Meta Data @param String $key Meta Key @param Mixed $default Default value @return mixed
[ "Get", "Meta", "Data" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Storage/Eloquent/HasMeta.php#L32-L39
226,530
snowplow-archive/symfony2-paypal-ipn
src/Orderly/PayPalIpnBundle/Document/IpnOrderItems.php
IpnOrderItems.setUpdatedAtValue
public function setUpdatedAtValue(\DateTime $updatedAt = null) { if($updatedAt==null && $this->updatedAt == null){ $this->updatedAt = new \DateTime(); }else if($updatedAt instanceof \DateTime){ $this->updatedAt = $updatedAt; }else{ $this->updatedAt = new \DateTime(); } }
php
public function setUpdatedAtValue(\DateTime $updatedAt = null) { if($updatedAt==null && $this->updatedAt == null){ $this->updatedAt = new \DateTime(); }else if($updatedAt instanceof \DateTime){ $this->updatedAt = $updatedAt; }else{ $this->updatedAt = new \DateTime(); } }
[ "public", "function", "setUpdatedAtValue", "(", "\\", "DateTime", "$", "updatedAt", "=", "null", ")", "{", "if", "(", "$", "updatedAt", "==", "null", "&&", "$", "this", "->", "updatedAt", "==", "null", ")", "{", "$", "this", "->", "updatedAt", "=", "new", "\\", "DateTime", "(", ")", ";", "}", "else", "if", "(", "$", "updatedAt", "instanceof", "\\", "DateTime", ")", "{", "$", "this", "->", "updatedAt", "=", "$", "updatedAt", ";", "}", "else", "{", "$", "this", "->", "updatedAt", "=", "new", "\\", "DateTime", "(", ")", ";", "}", "}" ]
PrePersist and PreUpdate UpdatedAt-Value @MongoDB\PreUpdate @MongoDB\PrePersist
[ "PrePersist", "and", "PreUpdate", "UpdatedAt", "-", "Value" ]
e46d947cda5a11743ff1e215846e7d06ac939d42
https://github.com/snowplow-archive/symfony2-paypal-ipn/blob/e46d947cda5a11743ff1e215846e7d06ac939d42/src/Orderly/PayPalIpnBundle/Document/IpnOrderItems.php#L775-L784
226,531
loco/swizzle
src/ModelCollection.php
ModelCollection.has
public function has($key) { return isset($this->data[$key]) || array_key_exists($key, $this->data); }
php
public function has($key) { return isset($this->data[$key]) || array_key_exists($key, $this->data); }
[ "public", "function", "has", "(", "$", "key", ")", "{", "return", "isset", "(", "$", "this", "->", "data", "[", "$", "key", "]", ")", "||", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "data", ")", ";", "}" ]
Test if key was found in original JSON, even if empty @param string $key @return bool
[ "Test", "if", "key", "was", "found", "in", "original", "JSON", "even", "if", "empty" ]
539db44bc2341f3da403582052b770686c86a516
https://github.com/loco/swizzle/blob/539db44bc2341f3da403582052b770686c86a516/src/ModelCollection.php#L72-L75
226,532
gigaai/framework
src/Broadcast/Channel.php
Channel.create
public function create($name) { $response = giga_facebook_post('me/custom_labels', compact('name')); if (isset($response->error)) { $message = isset($response->error->error_user_msg) ? $response->error->error_user_msg : $response->message; throw new \Exception($message); } if (isset($response->id)) { return $response->id; } }
php
public function create($name) { $response = giga_facebook_post('me/custom_labels', compact('name')); if (isset($response->error)) { $message = isset($response->error->error_user_msg) ? $response->error->error_user_msg : $response->message; throw new \Exception($message); } if (isset($response->id)) { return $response->id; } }
[ "public", "function", "create", "(", "$", "name", ")", "{", "$", "response", "=", "giga_facebook_post", "(", "'me/custom_labels'", ",", "compact", "(", "'name'", ")", ")", ";", "if", "(", "isset", "(", "$", "response", "->", "error", ")", ")", "{", "$", "message", "=", "isset", "(", "$", "response", "->", "error", "->", "error_user_msg", ")", "?", "$", "response", "->", "error", "->", "error_user_msg", ":", "$", "response", "->", "message", ";", "throw", "new", "\\", "Exception", "(", "$", "message", ")", ";", "}", "if", "(", "isset", "(", "$", "response", "->", "id", ")", ")", "{", "return", "$", "response", "->", "id", ";", "}", "}" ]
Create new Facebook Label @param String $name @return Label ID
[ "Create", "new", "Facebook", "Label" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Broadcast/Channel.php#L13-L25
226,533
gigaai/framework
src/Broadcast/Channel.php
Channel.addLead
public function addLead($labelId, $leadId) { $response = giga_facebook_post($labelId . '/label', [ 'user' => $leadId ]); return isset($response->success); }
php
public function addLead($labelId, $leadId) { $response = giga_facebook_post($labelId . '/label', [ 'user' => $leadId ]); return isset($response->success); }
[ "public", "function", "addLead", "(", "$", "labelId", ",", "$", "leadId", ")", "{", "$", "response", "=", "giga_facebook_post", "(", "$", "labelId", ".", "'/label'", ",", "[", "'user'", "=>", "$", "leadId", "]", ")", ";", "return", "isset", "(", "$", "response", "->", "success", ")", ";", "}" ]
Add lead to Facebook label @return bool
[ "Add", "lead", "to", "Facebook", "label" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Broadcast/Channel.php#L32-L39
226,534
gigaai/framework
src/Broadcast/Channel.php
Channel.addLeads
public function addLeads($labelId, array $leadIds) { $batch = []; foreach ($leadIds as $user) { $batch[] = [ 'method' => 'POST', 'relative_url' => $labelId . '/label', 'body' => http_build_query(compact('user')) ]; } $batch = json_encode($batch); return giga_facebook_post('', compact('batch')); }
php
public function addLeads($labelId, array $leadIds) { $batch = []; foreach ($leadIds as $user) { $batch[] = [ 'method' => 'POST', 'relative_url' => $labelId . '/label', 'body' => http_build_query(compact('user')) ]; } $batch = json_encode($batch); return giga_facebook_post('', compact('batch')); }
[ "public", "function", "addLeads", "(", "$", "labelId", ",", "array", "$", "leadIds", ")", "{", "$", "batch", "=", "[", "]", ";", "foreach", "(", "$", "leadIds", "as", "$", "user", ")", "{", "$", "batch", "[", "]", "=", "[", "'method'", "=>", "'POST'", ",", "'relative_url'", "=>", "$", "labelId", ".", "'/label'", ",", "'body'", "=>", "http_build_query", "(", "compact", "(", "'user'", ")", ")", "]", ";", "}", "$", "batch", "=", "json_encode", "(", "$", "batch", ")", ";", "return", "giga_facebook_post", "(", "''", ",", "compact", "(", "'batch'", ")", ")", ";", "}" ]
Add many leads to Facebook Label
[ "Add", "many", "leads", "to", "Facebook", "Label" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Broadcast/Channel.php#L44-L59
226,535
gigaai/framework
src/Broadcast/Channel.php
Channel.removeLead
public function removeLead($labelId, $leadId) { $response = giga_facebook_delete($labelId . '/label', [ 'user' => $leadId ]); return isset($response->success); }
php
public function removeLead($labelId, $leadId) { $response = giga_facebook_delete($labelId . '/label', [ 'user' => $leadId ]); return isset($response->success); }
[ "public", "function", "removeLead", "(", "$", "labelId", ",", "$", "leadId", ")", "{", "$", "response", "=", "giga_facebook_delete", "(", "$", "labelId", ".", "'/label'", ",", "[", "'user'", "=>", "$", "leadId", "]", ")", ";", "return", "isset", "(", "$", "response", "->", "success", ")", ";", "}" ]
Remove lead from FB label @return bool
[ "Remove", "lead", "from", "FB", "label" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Broadcast/Channel.php#L66-L73
226,536
gigaai/framework
src/Broadcast/Channel.php
Channel.ofLead
public function ofLead($leadId) { $response = giga_facebook_get($leadId . '/custom_labels'); if (!isset($response->data) || !is_array($response->data)) { return false; } $channels = $response->data; $channelIds = []; foreach ($channels as $channel) { $channelIds[] = $channel->id; } return $channelIds; }
php
public function ofLead($leadId) { $response = giga_facebook_get($leadId . '/custom_labels'); if (!isset($response->data) || !is_array($response->data)) { return false; } $channels = $response->data; $channelIds = []; foreach ($channels as $channel) { $channelIds[] = $channel->id; } return $channelIds; }
[ "public", "function", "ofLead", "(", "$", "leadId", ")", "{", "$", "response", "=", "giga_facebook_get", "(", "$", "leadId", ".", "'/custom_labels'", ")", ";", "if", "(", "!", "isset", "(", "$", "response", "->", "data", ")", "||", "!", "is_array", "(", "$", "response", "->", "data", ")", ")", "{", "return", "false", ";", "}", "$", "channels", "=", "$", "response", "->", "data", ";", "$", "channelIds", "=", "[", "]", ";", "foreach", "(", "$", "channels", "as", "$", "channel", ")", "{", "$", "channelIds", "[", "]", "=", "$", "channel", "->", "id", ";", "}", "return", "$", "channelIds", ";", "}" ]
Get all labels of lead @return mixed
[ "Get", "all", "labels", "of", "lead" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Broadcast/Channel.php#L96-L112
226,537
gigaai/framework
src/Broadcast/Channel.php
Channel.all
public function all() { $response = giga_facebook_get('/me/custom_labels?fields=name'); $channels = []; foreach ($response->data as $channel) { $channels[$channel->id] = $channel->name; } return $channels; // [id => name] }
php
public function all() { $response = giga_facebook_get('/me/custom_labels?fields=name'); $channels = []; foreach ($response->data as $channel) { $channels[$channel->id] = $channel->name; } return $channels; // [id => name] }
[ "public", "function", "all", "(", ")", "{", "$", "response", "=", "giga_facebook_get", "(", "'/me/custom_labels?fields=name'", ")", ";", "$", "channels", "=", "[", "]", ";", "foreach", "(", "$", "response", "->", "data", "as", "$", "channel", ")", "{", "$", "channels", "[", "$", "channel", "->", "id", "]", "=", "$", "channel", "->", "name", ";", "}", "return", "$", "channels", ";", "// [id => name]", "}" ]
Get all label of a page @return array
[ "Get", "all", "label", "of", "a", "page" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Broadcast/Channel.php#L131-L141
226,538
pug-php/js-phpize
src/JsPhpize/Lexer/Lexer.php
Lexer.unexpected
public function unexpected($token, $className = '\\JsPhpize\\Lexer\\Exception') { return new $className('Unexpected ' . $token->type . rtrim(' ' . ($token->value ?: '')) . $this->exceptionInfos(), 8); }
php
public function unexpected($token, $className = '\\JsPhpize\\Lexer\\Exception') { return new $className('Unexpected ' . $token->type . rtrim(' ' . ($token->value ?: '')) . $this->exceptionInfos(), 8); }
[ "public", "function", "unexpected", "(", "$", "token", ",", "$", "className", "=", "'\\\\JsPhpize\\\\Lexer\\\\Exception'", ")", "{", "return", "new", "$", "className", "(", "'Unexpected '", ".", "$", "token", "->", "type", ".", "rtrim", "(", "' '", ".", "(", "$", "token", "->", "value", "?", ":", "''", ")", ")", ".", "$", "this", "->", "exceptionInfos", "(", ")", ",", "8", ")", ";", "}" ]
Return a unexpected exception for a given token. @param $token @return Exception
[ "Return", "a", "unexpected", "exception", "for", "a", "given", "token", "." ]
c41102da1be243ba9439b90af8b7032016585537
https://github.com/pug-php/js-phpize/blob/c41102da1be243ba9439b90af8b7032016585537/src/JsPhpize/Lexer/Lexer.php#L109-L112
226,539
loco/swizzle
src/Result/BaseResponse.php
BaseResponse.getApiPaths
public function getApiPaths() { $paths = []; if ($apis = $this->get('apis')) { foreach ($apis as $api) { if (isset($api['path'])) { $paths[] = $api['path']; } } } return $paths; }
php
public function getApiPaths() { $paths = []; if ($apis = $this->get('apis')) { foreach ($apis as $api) { if (isset($api['path'])) { $paths[] = $api['path']; } } } return $paths; }
[ "public", "function", "getApiPaths", "(", ")", "{", "$", "paths", "=", "[", "]", ";", "if", "(", "$", "apis", "=", "$", "this", "->", "get", "(", "'apis'", ")", ")", "{", "foreach", "(", "$", "apis", "as", "$", "api", ")", "{", "if", "(", "isset", "(", "$", "api", "[", "'path'", "]", ")", ")", "{", "$", "paths", "[", "]", "=", "$", "api", "[", "'path'", "]", ";", "}", "}", "}", "return", "$", "paths", ";", "}" ]
Get all path strings in objects under apis @return array
[ "Get", "all", "path", "strings", "in", "objects", "under", "apis" ]
539db44bc2341f3da403582052b770686c86a516
https://github.com/loco/swizzle/blob/539db44bc2341f3da403582052b770686c86a516/src/Result/BaseResponse.php#L71-L82
226,540
gigaai/framework
src/Conversation/Nlp.php
Nlp.filter
public function filter($filter) { preg_match_all("/(#\w+)/", $filter, $entityNames); preg_match_all("/(:\w+)/", $filter, $positions); $entityName = is_array($entityNames[0]) && isset($entityNames[0][0]) ? ltrim($entityNames[0][0], '#') : null; $position = is_array($positions[0]) && isset($positions[0][0]) ? $positions[0][0] : null; $i = 0; $filtered = []; foreach ($this->entities as $name => $entity) { if ($i === 0 && ($entityName === $name || $entityName === null) && ($position === ':first' || $position === ':highest' || $position === null)) { $filtered[] = $entity; } if ($position === ':any' && ($entityName === $name || $entityName === null)) { $filtered[] = $entity; } if ($i + 1 === $this->entities->count() && ($entityName === $name || $entityName === null) && ($position === ':last' || $position === ':lowest')) { $filtered[] = $entity; } $i++; } $this->filtered = $filtered; return $this; }
php
public function filter($filter) { preg_match_all("/(#\w+)/", $filter, $entityNames); preg_match_all("/(:\w+)/", $filter, $positions); $entityName = is_array($entityNames[0]) && isset($entityNames[0][0]) ? ltrim($entityNames[0][0], '#') : null; $position = is_array($positions[0]) && isset($positions[0][0]) ? $positions[0][0] : null; $i = 0; $filtered = []; foreach ($this->entities as $name => $entity) { if ($i === 0 && ($entityName === $name || $entityName === null) && ($position === ':first' || $position === ':highest' || $position === null)) { $filtered[] = $entity; } if ($position === ':any' && ($entityName === $name || $entityName === null)) { $filtered[] = $entity; } if ($i + 1 === $this->entities->count() && ($entityName === $name || $entityName === null) && ($position === ':last' || $position === ':lowest')) { $filtered[] = $entity; } $i++; } $this->filtered = $filtered; return $this; }
[ "public", "function", "filter", "(", "$", "filter", ")", "{", "preg_match_all", "(", "\"/(#\\w+)/\"", ",", "$", "filter", ",", "$", "entityNames", ")", ";", "preg_match_all", "(", "\"/(:\\w+)/\"", ",", "$", "filter", ",", "$", "positions", ")", ";", "$", "entityName", "=", "is_array", "(", "$", "entityNames", "[", "0", "]", ")", "&&", "isset", "(", "$", "entityNames", "[", "0", "]", "[", "0", "]", ")", "?", "ltrim", "(", "$", "entityNames", "[", "0", "]", "[", "0", "]", ",", "'#'", ")", ":", "null", ";", "$", "position", "=", "is_array", "(", "$", "positions", "[", "0", "]", ")", "&&", "isset", "(", "$", "positions", "[", "0", "]", "[", "0", "]", ")", "?", "$", "positions", "[", "0", "]", "[", "0", "]", ":", "null", ";", "$", "i", "=", "0", ";", "$", "filtered", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "entities", "as", "$", "name", "=>", "$", "entity", ")", "{", "if", "(", "$", "i", "===", "0", "&&", "(", "$", "entityName", "===", "$", "name", "||", "$", "entityName", "===", "null", ")", "&&", "(", "$", "position", "===", "':first'", "||", "$", "position", "===", "':highest'", "||", "$", "position", "===", "null", ")", ")", "{", "$", "filtered", "[", "]", "=", "$", "entity", ";", "}", "if", "(", "$", "position", "===", "':any'", "&&", "(", "$", "entityName", "===", "$", "name", "||", "$", "entityName", "===", "null", ")", ")", "{", "$", "filtered", "[", "]", "=", "$", "entity", ";", "}", "if", "(", "$", "i", "+", "1", "===", "$", "this", "->", "entities", "->", "count", "(", ")", "&&", "(", "$", "entityName", "===", "$", "name", "||", "$", "entityName", "===", "null", ")", "&&", "(", "$", "position", "===", "':last'", "||", "$", "position", "===", "':lowest'", ")", ")", "{", "$", "filtered", "[", "]", "=", "$", "entity", ";", "}", "$", "i", "++", ";", "}", "$", "this", "->", "filtered", "=", "$", "filtered", ";", "return", "$", "this", ";", "}" ]
Get entities by their name or position @param null $filter @return Nlp
[ "Get", "entities", "by", "their", "name", "or", "position" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Conversation/Nlp.php#L52-L83
226,541
gigaai/framework
src/Conversation/Nlp.php
Nlp.get
public function get($field) { if (!is_null($this->filtered) && ! is_null($this->filtered[0])) { return isset($this->filtered[0][0][$field]) ? $this->filtered[0][0][$field] : null; } // Todo: Get values of entities }
php
public function get($field) { if (!is_null($this->filtered) && ! is_null($this->filtered[0])) { return isset($this->filtered[0][0][$field]) ? $this->filtered[0][0][$field] : null; } // Todo: Get values of entities }
[ "public", "function", "get", "(", "$", "field", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "filtered", ")", "&&", "!", "is_null", "(", "$", "this", "->", "filtered", "[", "0", "]", ")", ")", "{", "return", "isset", "(", "$", "this", "->", "filtered", "[", "0", "]", "[", "0", "]", "[", "$", "field", "]", ")", "?", "$", "this", "->", "filtered", "[", "0", "]", "[", "0", "]", "[", "$", "field", "]", ":", "null", ";", "}", "// Todo: Get values of entities", "}" ]
Get a fields value @param $field @return mixed
[ "Get", "a", "fields", "value" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Conversation/Nlp.php#L139-L146
226,542
snowplow-archive/symfony2-paypal-ipn
src/Orderly/PayPalIpnBundle/Pdt.php
Pdt.getPdt
public function getPdt($transactionID) { $this->transactionID = $transactionID; // Now we need to ask PayPal to tell us if it sent this notification $pdtResponse = $this->_postData($this->pdtURL, array('cmd' => '_notify-synch', 'tx' => $transactionID, 'at' => $this->pdtToken)); if ($pdtResponse === FALSE) { // Bail out if we have an error. return FALSE; } // Phew! We have a valid PDT transaction, log it. $this->_logTransaction('PDT', 'SUCCESS', 'Parsing complete', $pdtResponse); return $pdtResponse; }
php
public function getPdt($transactionID) { $this->transactionID = $transactionID; // Now we need to ask PayPal to tell us if it sent this notification $pdtResponse = $this->_postData($this->pdtURL, array('cmd' => '_notify-synch', 'tx' => $transactionID, 'at' => $this->pdtToken)); if ($pdtResponse === FALSE) { // Bail out if we have an error. return FALSE; } // Phew! We have a valid PDT transaction, log it. $this->_logTransaction('PDT', 'SUCCESS', 'Parsing complete', $pdtResponse); return $pdtResponse; }
[ "public", "function", "getPdt", "(", "$", "transactionID", ")", "{", "$", "this", "->", "transactionID", "=", "$", "transactionID", ";", "// Now we need to ask PayPal to tell us if it sent this notification", "$", "pdtResponse", "=", "$", "this", "->", "_postData", "(", "$", "this", "->", "pdtURL", ",", "array", "(", "'cmd'", "=>", "'_notify-synch'", ",", "'tx'", "=>", "$", "transactionID", ",", "'at'", "=>", "$", "this", "->", "pdtToken", ")", ")", ";", "if", "(", "$", "pdtResponse", "===", "FALSE", ")", "{", "// Bail out if we have an error.", "return", "FALSE", ";", "}", "// Phew! We have a valid PDT transaction, log it.", "$", "this", "->", "_logTransaction", "(", "'PDT'", ",", "'SUCCESS'", ",", "'Parsing complete'", ",", "$", "pdtResponse", ")", ";", "return", "$", "pdtResponse", ";", "}" ]
The key functionality in this library. Gets the data from Paypal with a transaction id obtained from an IPN call. @param string $transactionID Transaction Id returned from an IPN call. @return array
[ "The", "key", "functionality", "in", "this", "library", ".", "Gets", "the", "data", "from", "Paypal", "with", "a", "transaction", "id", "obtained", "from", "an", "IPN", "call", "." ]
e46d947cda5a11743ff1e215846e7d06ac939d42
https://github.com/snowplow-archive/symfony2-paypal-ipn/blob/e46d947cda5a11743ff1e215846e7d06ac939d42/src/Orderly/PayPalIpnBundle/Pdt.php#L58-L71
226,543
snowplow-archive/symfony2-paypal-ipn
src/Orderly/PayPalIpnBundle/Pdt.php
Pdt._postData
function _postData($url, $postData) { if ($this->mockResponse !== null) { return $this->mockResponse; } // Put the postData into a string $postString = ''; foreach ($postData as $field => $value) { $postString .= $field . '=' . urlencode(stripslashes($value)) . '&'; // Trailing & at end of post string is forgivable } $curl = \curl_init(); \curl_setopt($curl, CURLOPT_URL, $url); \curl_setopt($curl, CURLOPT_POST, 1); \curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); \curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); if (!empty($this->proxyUrl)) { \curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); \curl_setopt($curl, CURLOPT_PROXY, $this->proxyUrl); } \curl_setopt($curl, CURLOPT_POSTFIELDS, $postString); $response = \curl_exec($curl); // Log and return if we have an error if (\curl_error($curl)) { $this->_logTransaction("PDT", "ERROR", "curl error number " . \curl_errno($curl) . ": " . \curl_error($curl) . " connecting to " . $url); return FALSE; } \curl_close($curl); if (preg_match("/(SUCCESS|FAIL)/", $response, $matches)) { $response_array = explode("\n", $response); if ($response_array[0] === "SUCCESS") { // Get rid of SUCCESS array_shift($response_array); // Get rid of null line array_pop($response_array); $final_response = array(); foreach ($response_array as $value) { $temp = explode("=", $value); $final_response[urldecode($temp[0])] = urldecode($temp[1]); } return $final_response; } else { $this->_logTransaction('PDT', 'ERROR', 'PayPal rejected the PDT call as invalid - potentially call was spoofed or was not checked within 30s', $response); } } else { $this->_logTransaction('PDT', 'ERROR', 'PayPal did not respond properly to the PDT call', $response); } return FALSE; }
php
function _postData($url, $postData) { if ($this->mockResponse !== null) { return $this->mockResponse; } // Put the postData into a string $postString = ''; foreach ($postData as $field => $value) { $postString .= $field . '=' . urlencode(stripslashes($value)) . '&'; // Trailing & at end of post string is forgivable } $curl = \curl_init(); \curl_setopt($curl, CURLOPT_URL, $url); \curl_setopt($curl, CURLOPT_POST, 1); \curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); \curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); if (!empty($this->proxyUrl)) { \curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); \curl_setopt($curl, CURLOPT_PROXY, $this->proxyUrl); } \curl_setopt($curl, CURLOPT_POSTFIELDS, $postString); $response = \curl_exec($curl); // Log and return if we have an error if (\curl_error($curl)) { $this->_logTransaction("PDT", "ERROR", "curl error number " . \curl_errno($curl) . ": " . \curl_error($curl) . " connecting to " . $url); return FALSE; } \curl_close($curl); if (preg_match("/(SUCCESS|FAIL)/", $response, $matches)) { $response_array = explode("\n", $response); if ($response_array[0] === "SUCCESS") { // Get rid of SUCCESS array_shift($response_array); // Get rid of null line array_pop($response_array); $final_response = array(); foreach ($response_array as $value) { $temp = explode("=", $value); $final_response[urldecode($temp[0])] = urldecode($temp[1]); } return $final_response; } else { $this->_logTransaction('PDT', 'ERROR', 'PayPal rejected the PDT call as invalid - potentially call was spoofed or was not checked within 30s', $response); } } else { $this->_logTransaction('PDT', 'ERROR', 'PayPal did not respond properly to the PDT call', $response); } return FALSE; }
[ "function", "_postData", "(", "$", "url", ",", "$", "postData", ")", "{", "if", "(", "$", "this", "->", "mockResponse", "!==", "null", ")", "{", "return", "$", "this", "->", "mockResponse", ";", "}", "// Put the postData into a string", "$", "postString", "=", "''", ";", "foreach", "(", "$", "postData", "as", "$", "field", "=>", "$", "value", ")", "{", "$", "postString", ".=", "$", "field", ".", "'='", ".", "urlencode", "(", "stripslashes", "(", "$", "value", ")", ")", ".", "'&'", ";", "// Trailing & at end of post string is forgivable", "}", "$", "curl", "=", "\\", "curl_init", "(", ")", ";", "\\", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_URL", ",", "$", "url", ")", ";", "\\", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_POST", ",", "1", ")", ";", "\\", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_RETURNTRANSFER", ",", "1", ")", ";", "\\", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_SSL_VERIFYHOST", ",", "2", ")", ";", "\\", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_SSL_VERIFYPEER", ",", "FALSE", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "proxyUrl", ")", ")", "{", "\\", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_PROXYTYPE", ",", "CURLPROXY_HTTP", ")", ";", "\\", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_PROXY", ",", "$", "this", "->", "proxyUrl", ")", ";", "}", "\\", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_POSTFIELDS", ",", "$", "postString", ")", ";", "$", "response", "=", "\\", "curl_exec", "(", "$", "curl", ")", ";", "// Log and return if we have an error", "if", "(", "\\", "curl_error", "(", "$", "curl", ")", ")", "{", "$", "this", "->", "_logTransaction", "(", "\"PDT\"", ",", "\"ERROR\"", ",", "\"curl error number \"", ".", "\\", "curl_errno", "(", "$", "curl", ")", ".", "\": \"", ".", "\\", "curl_error", "(", "$", "curl", ")", ".", "\" connecting to \"", ".", "$", "url", ")", ";", "return", "FALSE", ";", "}", "\\", "curl_close", "(", "$", "curl", ")", ";", "if", "(", "preg_match", "(", "\"/(SUCCESS|FAIL)/\"", ",", "$", "response", ",", "$", "matches", ")", ")", "{", "$", "response_array", "=", "explode", "(", "\"\\n\"", ",", "$", "response", ")", ";", "if", "(", "$", "response_array", "[", "0", "]", "===", "\"SUCCESS\"", ")", "{", "// Get rid of SUCCESS", "array_shift", "(", "$", "response_array", ")", ";", "// Get rid of null line", "array_pop", "(", "$", "response_array", ")", ";", "$", "final_response", "=", "array", "(", ")", ";", "foreach", "(", "$", "response_array", "as", "$", "value", ")", "{", "$", "temp", "=", "explode", "(", "\"=\"", ",", "$", "value", ")", ";", "$", "final_response", "[", "urldecode", "(", "$", "temp", "[", "0", "]", ")", "]", "=", "urldecode", "(", "$", "temp", "[", "1", "]", ")", ";", "}", "return", "$", "final_response", ";", "}", "else", "{", "$", "this", "->", "_logTransaction", "(", "'PDT'", ",", "'ERROR'", ",", "'PayPal rejected the PDT call as invalid - potentially call was spoofed or was not checked within 30s'", ",", "$", "response", ")", ";", "}", "}", "else", "{", "$", "this", "->", "_logTransaction", "(", "'PDT'", ",", "'ERROR'", ",", "'PayPal did not respond properly to the PDT call'", ",", "$", "response", ")", ";", "}", "return", "FALSE", ";", "}" ]
Sending data to PayPal PDT service @param string $url @param array $postData @return string
[ "Sending", "data", "to", "PayPal", "PDT", "service" ]
e46d947cda5a11743ff1e215846e7d06ac939d42
https://github.com/snowplow-archive/symfony2-paypal-ipn/blob/e46d947cda5a11743ff1e215846e7d06ac939d42/src/Orderly/PayPalIpnBundle/Pdt.php#L81-L142
226,544
johannesschobel/dingoquerymapper
src/JohannesSchobel/DingoQueryMapper/Parser/DingoQueryMapper.php
DingoQueryMapper.createFromCollection
public function createFromCollection(Collection $collection) { $this->operator = new CollectionOperator($collection, $this->request); $this->prepare(); return $this; }
php
public function createFromCollection(Collection $collection) { $this->operator = new CollectionOperator($collection, $this->request); $this->prepare(); return $this; }
[ "public", "function", "createFromCollection", "(", "Collection", "$", "collection", ")", "{", "$", "this", "->", "operator", "=", "new", "CollectionOperator", "(", "$", "collection", ",", "$", "this", "->", "request", ")", ";", "$", "this", "->", "prepare", "(", ")", ";", "return", "$", "this", ";", "}" ]
Create the result based on a collection @param Collection $collection @return $this
[ "Create", "the", "result", "based", "on", "a", "collection" ]
0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e
https://github.com/johannesschobel/dingoquerymapper/blob/0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e/src/JohannesSchobel/DingoQueryMapper/Parser/DingoQueryMapper.php#L54-L60
226,545
johannesschobel/dingoquerymapper
src/JohannesSchobel/DingoQueryMapper/Parser/DingoQueryMapper.php
DingoQueryMapper.filter
private function filter() { if ($this->allowsFilter()) { if ($this->hasFilters()) { $tmp = []; foreach ($this->filters as $filter) { // check, if it is a "forbidden" query parameter if ($this->isExcludedParameter($filter['key'])) { continue; } $tmp[] = $filter; } $this->filters = $tmp; return $this->operator->filter($this->filters); } } }
php
private function filter() { if ($this->allowsFilter()) { if ($this->hasFilters()) { $tmp = []; foreach ($this->filters as $filter) { // check, if it is a "forbidden" query parameter if ($this->isExcludedParameter($filter['key'])) { continue; } $tmp[] = $filter; } $this->filters = $tmp; return $this->operator->filter($this->filters); } } }
[ "private", "function", "filter", "(", ")", "{", "if", "(", "$", "this", "->", "allowsFilter", "(", ")", ")", "{", "if", "(", "$", "this", "->", "hasFilters", "(", ")", ")", "{", "$", "tmp", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "filters", "as", "$", "filter", ")", "{", "// check, if it is a \"forbidden\" query parameter", "if", "(", "$", "this", "->", "isExcludedParameter", "(", "$", "filter", "[", "'key'", "]", ")", ")", "{", "continue", ";", "}", "$", "tmp", "[", "]", "=", "$", "filter", ";", "}", "$", "this", "->", "filters", "=", "$", "tmp", ";", "return", "$", "this", "->", "operator", "->", "filter", "(", "$", "this", "->", "filters", ")", ";", "}", "}", "}" ]
Filter the result. Operator implements actual logic. @return mixed
[ "Filter", "the", "result", ".", "Operator", "implements", "actual", "logic", "." ]
0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e
https://github.com/johannesschobel/dingoquerymapper/blob/0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e/src/JohannesSchobel/DingoQueryMapper/Parser/DingoQueryMapper.php#L83-L101
226,546
johannesschobel/dingoquerymapper
src/JohannesSchobel/DingoQueryMapper/Parser/DingoQueryMapper.php
DingoQueryMapper.prepareConstant
private function prepareConstant($parameter) { if (!$this->uriParser->hasQueryParameter($parameter)) { return; } $callback = [$this, $this->setterMethodName($parameter)]; $callbackParameter = $this->uriParser->queryParameter($parameter); call_user_func($callback, $callbackParameter['value']); }
php
private function prepareConstant($parameter) { if (!$this->uriParser->hasQueryParameter($parameter)) { return; } $callback = [$this, $this->setterMethodName($parameter)]; $callbackParameter = $this->uriParser->queryParameter($parameter); call_user_func($callback, $callbackParameter['value']); }
[ "private", "function", "prepareConstant", "(", "$", "parameter", ")", "{", "if", "(", "!", "$", "this", "->", "uriParser", "->", "hasQueryParameter", "(", "$", "parameter", ")", ")", "{", "return", ";", "}", "$", "callback", "=", "[", "$", "this", ",", "$", "this", "->", "setterMethodName", "(", "$", "parameter", ")", "]", ";", "$", "callbackParameter", "=", "$", "this", "->", "uriParser", "->", "queryParameter", "(", "$", "parameter", ")", ";", "call_user_func", "(", "$", "callback", ",", "$", "callbackParameter", "[", "'value'", "]", ")", ";", "}" ]
Calls respective setXXX Method for the predefined parameters @param $parameter
[ "Calls", "respective", "setXXX", "Method", "for", "the", "predefined", "parameters" ]
0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e
https://github.com/johannesschobel/dingoquerymapper/blob/0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e/src/JohannesSchobel/DingoQueryMapper/Parser/DingoQueryMapper.php#L138-L148
226,547
netgen/NetgenEzFormsBundle
bundle/Form/DataMapper.php
DataMapper.shouldSkipForEmptyUpdate
protected function shouldSkipForEmptyUpdate(FormInterface $form, $value, $fieldDefinitionIdentifier) { return $value === null && ( $form->getRoot()->has("ezforms_skip_empty_update_{$fieldDefinitionIdentifier}") && $form->getRoot()->get("ezforms_skip_empty_update_{$fieldDefinitionIdentifier}")->getData() === 'yes' ) ; }
php
protected function shouldSkipForEmptyUpdate(FormInterface $form, $value, $fieldDefinitionIdentifier) { return $value === null && ( $form->getRoot()->has("ezforms_skip_empty_update_{$fieldDefinitionIdentifier}") && $form->getRoot()->get("ezforms_skip_empty_update_{$fieldDefinitionIdentifier}")->getData() === 'yes' ) ; }
[ "protected", "function", "shouldSkipForEmptyUpdate", "(", "FormInterface", "$", "form", ",", "$", "value", ",", "$", "fieldDefinitionIdentifier", ")", "{", "return", "$", "value", "===", "null", "&&", "(", "$", "form", "->", "getRoot", "(", ")", "->", "has", "(", "\"ezforms_skip_empty_update_{$fieldDefinitionIdentifier}\"", ")", "&&", "$", "form", "->", "getRoot", "(", ")", "->", "get", "(", "\"ezforms_skip_empty_update_{$fieldDefinitionIdentifier}\"", ")", "->", "getData", "(", ")", "===", "'yes'", ")", ";", "}" ]
Returns if the update should be skipped for empty value. @param \Symfony\Component\Form\FormInterface $form @param mixed $value @param string $fieldDefinitionIdentifier @return bool
[ "Returns", "if", "the", "update", "should", "be", "skipped", "for", "empty", "value", "." ]
c4d2355e14a41353ac40eafc386f203b3d94ea9e
https://github.com/netgen/NetgenEzFormsBundle/blob/c4d2355e14a41353ac40eafc386f203b3d94ea9e/bundle/Form/DataMapper.php#L164-L173
226,548
gigaai/framework
src/Shortcodes/PostGeneric.php
PostGeneric.parse_query_args
private function parse_query_args( $atts ) { // If is json. Parse it! if ( ! is_array( $atts['query_args'] ) ) { $arr = @json_decode( $atts['query_args'], true ); if ( is_array( $arr ) ) { $atts['query_args'] = $arr; } } $query_args = $atts['query_args']; if ( is_numeric( $atts['limit'] ) && $atts['limit'] <= 6 && $atts['limit'] > 0 && ! isset( $query_args['posts_per_page'] ) ) { $query_args['posts_per_page'] = $atts['limit']; } foreach ( $atts as $key => $value ) { if ( in_array( $key, $this->keys ) ) { $query_args[ $key ] = $value; } } return $query_args; }
php
private function parse_query_args( $atts ) { // If is json. Parse it! if ( ! is_array( $atts['query_args'] ) ) { $arr = @json_decode( $atts['query_args'], true ); if ( is_array( $arr ) ) { $atts['query_args'] = $arr; } } $query_args = $atts['query_args']; if ( is_numeric( $atts['limit'] ) && $atts['limit'] <= 6 && $atts['limit'] > 0 && ! isset( $query_args['posts_per_page'] ) ) { $query_args['posts_per_page'] = $atts['limit']; } foreach ( $atts as $key => $value ) { if ( in_array( $key, $this->keys ) ) { $query_args[ $key ] = $value; } } return $query_args; }
[ "private", "function", "parse_query_args", "(", "$", "atts", ")", "{", "// If is json. Parse it!", "if", "(", "!", "is_array", "(", "$", "atts", "[", "'query_args'", "]", ")", ")", "{", "$", "arr", "=", "@", "json_decode", "(", "$", "atts", "[", "'query_args'", "]", ",", "true", ")", ";", "if", "(", "is_array", "(", "$", "arr", ")", ")", "{", "$", "atts", "[", "'query_args'", "]", "=", "$", "arr", ";", "}", "}", "$", "query_args", "=", "$", "atts", "[", "'query_args'", "]", ";", "if", "(", "is_numeric", "(", "$", "atts", "[", "'limit'", "]", ")", "&&", "$", "atts", "[", "'limit'", "]", "<=", "6", "&&", "$", "atts", "[", "'limit'", "]", ">", "0", "&&", "!", "isset", "(", "$", "query_args", "[", "'posts_per_page'", "]", ")", ")", "{", "$", "query_args", "[", "'posts_per_page'", "]", "=", "$", "atts", "[", "'limit'", "]", ";", "}", "foreach", "(", "$", "atts", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "$", "this", "->", "keys", ")", ")", "{", "$", "query_args", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "query_args", ";", "}" ]
Parse simple query args. @param $atts @return array|mixed|object
[ "Parse", "simple", "query", "args", "." ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Shortcodes/PostGeneric.php#L139-L163
226,549
egeriis/laravel-jsonapi
src/EchoIt/JsonApi/Response.php
Response.toJsonResponse
public function toJsonResponse($bodyKey = 'data', $options = 0) { return new JsonResponse(array_merge( [ $bodyKey => $this->body ], array_filter($this->responseData) ), $this->httpStatusCode, ['Content-Type' => 'application/vnd.api+json'], $options); }
php
public function toJsonResponse($bodyKey = 'data', $options = 0) { return new JsonResponse(array_merge( [ $bodyKey => $this->body ], array_filter($this->responseData) ), $this->httpStatusCode, ['Content-Type' => 'application/vnd.api+json'], $options); }
[ "public", "function", "toJsonResponse", "(", "$", "bodyKey", "=", "'data'", ",", "$", "options", "=", "0", ")", "{", "return", "new", "JsonResponse", "(", "array_merge", "(", "[", "$", "bodyKey", "=>", "$", "this", "->", "body", "]", ",", "array_filter", "(", "$", "this", "->", "responseData", ")", ")", ",", "$", "this", "->", "httpStatusCode", ",", "[", "'Content-Type'", "=>", "'application/vnd.api+json'", "]", ",", "$", "options", ")", ";", "}" ]
Returns a JsonResponse with the set parameters and body. @param string $bodyKey The key on which to set the main response. @return \Illuminate\Http\JsonResponse
[ "Returns", "a", "JsonResponse", "with", "the", "set", "parameters", "and", "body", "." ]
6d58e14cba26c0624d38f75273cff86fd4678289
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Response.php#L66-L72
226,550
Gameye/gameye-sdk-php
src/sdk/GameyeSelector.php
GameyeSelector.selectMatchList
public static function selectMatchList( $matchState ) { $matchState = (object) $matchState; $matchList = []; foreach ($matchState->match as $matchKey => $matchItem) { $matchList[$matchKey] = $matchItem; } return $matchList; }
php
public static function selectMatchList( $matchState ) { $matchState = (object) $matchState; $matchList = []; foreach ($matchState->match as $matchKey => $matchItem) { $matchList[$matchKey] = $matchItem; } return $matchList; }
[ "public", "static", "function", "selectMatchList", "(", "$", "matchState", ")", "{", "$", "matchState", "=", "(", "object", ")", "$", "matchState", ";", "$", "matchList", "=", "[", "]", ";", "foreach", "(", "$", "matchState", "->", "match", "as", "$", "matchKey", "=>", "$", "matchItem", ")", "{", "$", "matchList", "[", "$", "matchKey", "]", "=", "$", "matchItem", ";", "}", "return", "$", "matchList", ";", "}" ]
Select a list of active matches. @param object $matchState @return array
[ "Select", "a", "list", "of", "active", "matches", "." ]
71ed33f411e58eb4ef23cb8317825a0d3113c5f0
https://github.com/Gameye/gameye-sdk-php/blob/71ed33f411e58eb4ef23cb8317825a0d3113c5f0/src/sdk/GameyeSelector.php#L23-L34
226,551
Gameye/gameye-sdk-php
src/sdk/GameyeSelector.php
GameyeSelector.selectMatchListForGame
public static function selectMatchListForGame( $matchState, $gameKey ) { $matchState = (object) $matchState; $gameKey = (string) $gameKey; $matchList = []; foreach ($matchState->match as $matchKey => $matchItem) { if ($matchItem->gameKey != $gameKey) { continue; } $matchList[$matchKey] = $matchItem; } return $matchList; }
php
public static function selectMatchListForGame( $matchState, $gameKey ) { $matchState = (object) $matchState; $gameKey = (string) $gameKey; $matchList = []; foreach ($matchState->match as $matchKey => $matchItem) { if ($matchItem->gameKey != $gameKey) { continue; } $matchList[$matchKey] = $matchItem; } return $matchList; }
[ "public", "static", "function", "selectMatchListForGame", "(", "$", "matchState", ",", "$", "gameKey", ")", "{", "$", "matchState", "=", "(", "object", ")", "$", "matchState", ";", "$", "gameKey", "=", "(", "string", ")", "$", "gameKey", ";", "$", "matchList", "=", "[", "]", ";", "foreach", "(", "$", "matchState", "->", "match", "as", "$", "matchKey", "=>", "$", "matchItem", ")", "{", "if", "(", "$", "matchItem", "->", "gameKey", "!=", "$", "gameKey", ")", "{", "continue", ";", "}", "$", "matchList", "[", "$", "matchKey", "]", "=", "$", "matchItem", ";", "}", "return", "$", "matchList", ";", "}" ]
Select a list of active matches for a game. @param object $matchState @param string $gameKey @return array
[ "Select", "a", "list", "of", "active", "matches", "for", "a", "game", "." ]
71ed33f411e58eb4ef23cb8317825a0d3113c5f0
https://github.com/Gameye/gameye-sdk-php/blob/71ed33f411e58eb4ef23cb8317825a0d3113c5f0/src/sdk/GameyeSelector.php#L44-L61
226,552
Gameye/gameye-sdk-php
src/sdk/GameyeSelector.php
GameyeSelector.selectMatchItem
public static function selectMatchItem( $matchState, $matchKey ) { $matchState = (object) $matchState; $matchKey = (string) $matchKey; $matchItem = $matchState->match->$matchKey; return $matchItem; }
php
public static function selectMatchItem( $matchState, $matchKey ) { $matchState = (object) $matchState; $matchKey = (string) $matchKey; $matchItem = $matchState->match->$matchKey; return $matchItem; }
[ "public", "static", "function", "selectMatchItem", "(", "$", "matchState", ",", "$", "matchKey", ")", "{", "$", "matchState", "=", "(", "object", ")", "$", "matchState", ";", "$", "matchKey", "=", "(", "string", ")", "$", "matchKey", ";", "$", "matchItem", "=", "$", "matchState", "->", "match", "->", "$", "matchKey", ";", "return", "$", "matchItem", ";", "}" ]
Get details about a single match from a match-state as returned by the gameye api. @param object $matchState @param string $matchKey @return object
[ "Get", "details", "about", "a", "single", "match", "from", "a", "match", "-", "state", "as", "returned", "by", "the", "gameye", "api", "." ]
71ed33f411e58eb4ef23cb8317825a0d3113c5f0
https://github.com/Gameye/gameye-sdk-php/blob/71ed33f411e58eb4ef23cb8317825a0d3113c5f0/src/sdk/GameyeSelector.php#L72-L82
226,553
Gameye/gameye-sdk-php
src/sdk/GameyeSelector.php
GameyeSelector.selectLocationListForGame
public static function selectLocationListForGame( $gameState, $gameKey ) { $gameState = (object) $gameState; $gameKey = (string) $gameKey; $locationList = []; foreach ($gameState->game->$gameKey->location as $locationKey => $hasLocation) { if (!$hasLocation) { continue; } $locationItem = $gameState->location->$locationKey; $locationList[$locationKey] = $locationItem; } return $locationList; }
php
public static function selectLocationListForGame( $gameState, $gameKey ) { $gameState = (object) $gameState; $gameKey = (string) $gameKey; $locationList = []; foreach ($gameState->game->$gameKey->location as $locationKey => $hasLocation) { if (!$hasLocation) { continue; } $locationItem = $gameState->location->$locationKey; $locationList[$locationKey] = $locationItem; } return $locationList; }
[ "public", "static", "function", "selectLocationListForGame", "(", "$", "gameState", ",", "$", "gameKey", ")", "{", "$", "gameState", "=", "(", "object", ")", "$", "gameState", ";", "$", "gameKey", "=", "(", "string", ")", "$", "gameKey", ";", "$", "locationList", "=", "[", "]", ";", "foreach", "(", "$", "gameState", "->", "game", "->", "$", "gameKey", "->", "location", "as", "$", "locationKey", "=>", "$", "hasLocation", ")", "{", "if", "(", "!", "$", "hasLocation", ")", "{", "continue", ";", "}", "$", "locationItem", "=", "$", "gameState", "->", "location", "->", "$", "locationKey", ";", "$", "locationList", "[", "$", "locationKey", "]", "=", "$", "locationItem", ";", "}", "return", "$", "locationList", ";", "}" ]
Selects all locations for a given game. @param object $gameState @param string $gameKey @return array
[ "Selects", "all", "locations", "for", "a", "given", "game", "." ]
71ed33f411e58eb4ef23cb8317825a0d3113c5f0
https://github.com/Gameye/gameye-sdk-php/blob/71ed33f411e58eb4ef23cb8317825a0d3113c5f0/src/sdk/GameyeSelector.php#L96-L114
226,554
Gameye/gameye-sdk-php
src/sdk/GameyeSelector.php
GameyeSelector.selectTemplateList
public static function selectTemplateList( $templateState ) { $templateState = (object) $templateState; $templateList = []; foreach ($templateState->template as $templateKey => $templateItem) { $templateList[$templateKey] = $templateItem; } return $templateList; }
php
public static function selectTemplateList( $templateState ) { $templateState = (object) $templateState; $templateList = []; foreach ($templateState->template as $templateKey => $templateItem) { $templateList[$templateKey] = $templateItem; } return $templateList; }
[ "public", "static", "function", "selectTemplateList", "(", "$", "templateState", ")", "{", "$", "templateState", "=", "(", "object", ")", "$", "templateState", ";", "$", "templateList", "=", "[", "]", ";", "foreach", "(", "$", "templateState", "->", "template", "as", "$", "templateKey", "=>", "$", "templateItem", ")", "{", "$", "templateList", "[", "$", "templateKey", "]", "=", "$", "templateItem", ";", "}", "return", "$", "templateList", ";", "}" ]
Select a list of templates. @param object $templateState @return array
[ "Select", "a", "list", "of", "templates", "." ]
71ed33f411e58eb4ef23cb8317825a0d3113c5f0
https://github.com/Gameye/gameye-sdk-php/blob/71ed33f411e58eb4ef23cb8317825a0d3113c5f0/src/sdk/GameyeSelector.php#L127-L138
226,555
Gameye/gameye-sdk-php
src/sdk/GameyeSelector.php
GameyeSelector.selectTemplateItem
public static function selectTemplateItem( $templateState, $templateKey ) { $templateState = (object) $templateState; $templateKey = (string) $templateKey; $templateItem = $templateState->template->$templateKey; return $templateItem; }
php
public static function selectTemplateItem( $templateState, $templateKey ) { $templateState = (object) $templateState; $templateKey = (string) $templateKey; $templateItem = $templateState->template->$templateKey; return $templateItem; }
[ "public", "static", "function", "selectTemplateItem", "(", "$", "templateState", ",", "$", "templateKey", ")", "{", "$", "templateState", "=", "(", "object", ")", "$", "templateState", ";", "$", "templateKey", "=", "(", "string", ")", "$", "templateKey", ";", "$", "templateItem", "=", "$", "templateState", "->", "template", "->", "$", "templateKey", ";", "return", "$", "templateItem", ";", "}" ]
Get details about a single template from a template-state as returned by the gameye api. @param object $templateState @param string $templateKey @return object
[ "Get", "details", "about", "a", "single", "template", "from", "a", "template", "-", "state", "as", "returned", "by", "the", "gameye", "api", "." ]
71ed33f411e58eb4ef23cb8317825a0d3113c5f0
https://github.com/Gameye/gameye-sdk-php/blob/71ed33f411e58eb4ef23cb8317825a0d3113c5f0/src/sdk/GameyeSelector.php#L149-L159
226,556
Gameye/gameye-sdk-php
src/sdk/GameyeSelector.php
GameyeSelector.selectTeamList
public static function selectTeamList( $statisticState ) { $statisticState = (object) $statisticState; $teamList = []; foreach ($statisticState->team as $teamKey => $teamItem) { $teamList[$teamKey] = $teamItem; } return $teamList; }
php
public static function selectTeamList( $statisticState ) { $statisticState = (object) $statisticState; $teamList = []; foreach ($statisticState->team as $teamKey => $teamItem) { $teamList[$teamKey] = $teamItem; } return $teamList; }
[ "public", "static", "function", "selectTeamList", "(", "$", "statisticState", ")", "{", "$", "statisticState", "=", "(", "object", ")", "$", "statisticState", ";", "$", "teamList", "=", "[", "]", ";", "foreach", "(", "$", "statisticState", "->", "team", "as", "$", "teamKey", "=>", "$", "teamItem", ")", "{", "$", "teamList", "[", "$", "teamKey", "]", "=", "$", "teamItem", ";", "}", "return", "$", "teamList", ";", "}" ]
Get a list of all teams in the statistic-state. @param object $statisticState @return array
[ "Get", "a", "list", "of", "all", "teams", "in", "the", "statistic", "-", "state", "." ]
71ed33f411e58eb4ef23cb8317825a0d3113c5f0
https://github.com/Gameye/gameye-sdk-php/blob/71ed33f411e58eb4ef23cb8317825a0d3113c5f0/src/sdk/GameyeSelector.php#L172-L183
226,557
Gameye/gameye-sdk-php
src/sdk/GameyeSelector.php
GameyeSelector.selectTeamItem
public static function selectTeamItem( $statisticState, $teamKey ) { $statisticState = (object) $statisticState; $teamKey = (string) $teamKey; $teamItem = $statisticState->team->$teamKey; return $teamItem; }
php
public static function selectTeamItem( $statisticState, $teamKey ) { $statisticState = (object) $statisticState; $teamKey = (string) $teamKey; $teamItem = $statisticState->team->$teamKey; return $teamItem; }
[ "public", "static", "function", "selectTeamItem", "(", "$", "statisticState", ",", "$", "teamKey", ")", "{", "$", "statisticState", "=", "(", "object", ")", "$", "statisticState", ";", "$", "teamKey", "=", "(", "string", ")", "$", "teamKey", ";", "$", "teamItem", "=", "$", "statisticState", "->", "team", "->", "$", "teamKey", ";", "return", "$", "teamItem", ";", "}" ]
Get a single team from the statistic-state. @param object $statisticState @param string $teamKey name of the team @return object
[ "Get", "a", "single", "team", "from", "the", "statistic", "-", "state", "." ]
71ed33f411e58eb4ef23cb8317825a0d3113c5f0
https://github.com/Gameye/gameye-sdk-php/blob/71ed33f411e58eb4ef23cb8317825a0d3113c5f0/src/sdk/GameyeSelector.php#L193-L203
226,558
Gameye/gameye-sdk-php
src/sdk/GameyeSelector.php
GameyeSelector.selectPlayerList
public static function selectPlayerList( $statisticState ) { $statisticState = (object) $statisticState; $playerList = []; foreach ($statisticState->player as $playerKey => $playerItem) { $playerList[$playerKey] = $playerItem; } return $playerList; }
php
public static function selectPlayerList( $statisticState ) { $statisticState = (object) $statisticState; $playerList = []; foreach ($statisticState->player as $playerKey => $playerItem) { $playerList[$playerKey] = $playerItem; } return $playerList; }
[ "public", "static", "function", "selectPlayerList", "(", "$", "statisticState", ")", "{", "$", "statisticState", "=", "(", "object", ")", "$", "statisticState", ";", "$", "playerList", "=", "[", "]", ";", "foreach", "(", "$", "statisticState", "->", "player", "as", "$", "playerKey", "=>", "$", "playerItem", ")", "{", "$", "playerList", "[", "$", "playerKey", "]", "=", "$", "playerItem", ";", "}", "return", "$", "playerList", ";", "}" ]
List all players in the match. @param object $statisticState @return array
[ "List", "all", "players", "in", "the", "match", "." ]
71ed33f411e58eb4ef23cb8317825a0d3113c5f0
https://github.com/Gameye/gameye-sdk-php/blob/71ed33f411e58eb4ef23cb8317825a0d3113c5f0/src/sdk/GameyeSelector.php#L216-L227
226,559
Gameye/gameye-sdk-php
src/sdk/GameyeSelector.php
GameyeSelector.selectPlayerListForTeam
public static function selectPlayerListForTeam( $statisticState, $teamKey ) { $statisticState = (object) $statisticState; $playerList = []; foreach ($statisticState->team->$teamKey->player as $playerKey => $playerEnabled) { $playerItem = $statisticState->player->$playerKey; $playerList[$playerKey] = $playerItem; } return $playerList; }
php
public static function selectPlayerListForTeam( $statisticState, $teamKey ) { $statisticState = (object) $statisticState; $playerList = []; foreach ($statisticState->team->$teamKey->player as $playerKey => $playerEnabled) { $playerItem = $statisticState->player->$playerKey; $playerList[$playerKey] = $playerItem; } return $playerList; }
[ "public", "static", "function", "selectPlayerListForTeam", "(", "$", "statisticState", ",", "$", "teamKey", ")", "{", "$", "statisticState", "=", "(", "object", ")", "$", "statisticState", ";", "$", "playerList", "=", "[", "]", ";", "foreach", "(", "$", "statisticState", "->", "team", "->", "$", "teamKey", "->", "player", "as", "$", "playerKey", "=>", "$", "playerEnabled", ")", "{", "$", "playerItem", "=", "$", "statisticState", "->", "player", "->", "$", "playerKey", ";", "$", "playerList", "[", "$", "playerKey", "]", "=", "$", "playerItem", ";", "}", "return", "$", "playerList", ";", "}" ]
Get a list if all players in a team. @param object $statisticState @param string $teamKey name of the team @return array
[ "Get", "a", "list", "if", "all", "players", "in", "a", "team", "." ]
71ed33f411e58eb4ef23cb8317825a0d3113c5f0
https://github.com/Gameye/gameye-sdk-php/blob/71ed33f411e58eb4ef23cb8317825a0d3113c5f0/src/sdk/GameyeSelector.php#L237-L250
226,560
Gameye/gameye-sdk-php
src/sdk/GameyeSelector.php
GameyeSelector.selectPlayerItem
public static function selectPlayerItem( $statisticState, $playerKey ) { $statisticState = (object) $statisticState; $playerKey = (string) $playerKey; $playerItem = $statisticState->player->$playerKey; return $playerItem; }
php
public static function selectPlayerItem( $statisticState, $playerKey ) { $statisticState = (object) $statisticState; $playerKey = (string) $playerKey; $playerItem = $statisticState->player->$playerKey; return $playerItem; }
[ "public", "static", "function", "selectPlayerItem", "(", "$", "statisticState", ",", "$", "playerKey", ")", "{", "$", "statisticState", "=", "(", "object", ")", "$", "statisticState", ";", "$", "playerKey", "=", "(", "string", ")", "$", "playerKey", ";", "$", "playerItem", "=", "$", "statisticState", "->", "player", "->", "$", "playerKey", ";", "return", "$", "playerItem", ";", "}" ]
Get a single player in the match. @param object $statisticState @return object
[ "Get", "a", "single", "player", "in", "the", "match", "." ]
71ed33f411e58eb4ef23cb8317825a0d3113c5f0
https://github.com/Gameye/gameye-sdk-php/blob/71ed33f411e58eb4ef23cb8317825a0d3113c5f0/src/sdk/GameyeSelector.php#L259-L269
226,561
gigaai/framework
src/Shortcodes/Lead.php
Lead.output
public function output() { // By default, the shortcode takes the current lead as the input $lead = Conversation::get('lead'); // If id provided, the shortcode will find the lead with the id. if (isset($this->attributes['id'])) { $id = $this->attributes['id']; $lead = LeadModel::whereUserId($id)->first(); } // Loop through attributes and get or set data foreach ($this->attributes as $key => $value) { if ($key === 'id') { continue; } // Note that if $value isn't provided, it will get data. return $lead->data($key, $value); } }
php
public function output() { // By default, the shortcode takes the current lead as the input $lead = Conversation::get('lead'); // If id provided, the shortcode will find the lead with the id. if (isset($this->attributes['id'])) { $id = $this->attributes['id']; $lead = LeadModel::whereUserId($id)->first(); } // Loop through attributes and get or set data foreach ($this->attributes as $key => $value) { if ($key === 'id') { continue; } // Note that if $value isn't provided, it will get data. return $lead->data($key, $value); } }
[ "public", "function", "output", "(", ")", "{", "// By default, the shortcode takes the current lead as the input", "$", "lead", "=", "Conversation", "::", "get", "(", "'lead'", ")", ";", "// If id provided, the shortcode will find the lead with the id.", "if", "(", "isset", "(", "$", "this", "->", "attributes", "[", "'id'", "]", ")", ")", "{", "$", "id", "=", "$", "this", "->", "attributes", "[", "'id'", "]", ";", "$", "lead", "=", "LeadModel", "::", "whereUserId", "(", "$", "id", ")", "->", "first", "(", ")", ";", "}", "// Loop through attributes and get or set data", "foreach", "(", "$", "this", "->", "attributes", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "===", "'id'", ")", "{", "continue", ";", "}", "// Note that if $value isn't provided, it will get data.", "return", "$", "lead", "->", "data", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}" ]
Define the shortcode's output @return mixed
[ "Define", "the", "shortcode", "s", "output" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Shortcodes/Lead.php#L40-L60
226,562
gigaai/framework
src/Drivers/Facebook.php
Facebook.verifyToken
private function verifyToken() { $received = Request::getReceivedData(); if (is_array($received) && isset($received['hub_verify_token']) && strtolower($received['hub_verify_token']) == 'gigaai' ) { echo $received['hub_challenge']; exit; } }
php
private function verifyToken() { $received = Request::getReceivedData(); if (is_array($received) && isset($received['hub_verify_token']) && strtolower($received['hub_verify_token']) == 'gigaai' ) { echo $received['hub_challenge']; exit; } }
[ "private", "function", "verifyToken", "(", ")", "{", "$", "received", "=", "Request", "::", "getReceivedData", "(", ")", ";", "if", "(", "is_array", "(", "$", "received", ")", "&&", "isset", "(", "$", "received", "[", "'hub_verify_token'", "]", ")", "&&", "strtolower", "(", "$", "received", "[", "'hub_verify_token'", "]", ")", "==", "'gigaai'", ")", "{", "echo", "$", "received", "[", "'hub_challenge'", "]", ";", "exit", ";", "}", "}" ]
Verify token from Facebook @return void
[ "Verify", "token", "from", "Facebook" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Drivers/Facebook.php#L24-L35
226,563
gigaai/framework
src/Drivers/Facebook.php
Facebook.getUser
public function getUser($lead_id) { $end_point = $this->getResource() . "{$lead_id}?access_token=" . $this->getAccessToken(); $data = giga_remote_get($end_point); return (array) $data; }
php
public function getUser($lead_id) { $end_point = $this->getResource() . "{$lead_id}?access_token=" . $this->getAccessToken(); $data = giga_remote_get($end_point); return (array) $data; }
[ "public", "function", "getUser", "(", "$", "lead_id", ")", "{", "$", "end_point", "=", "$", "this", "->", "getResource", "(", ")", ".", "\"{$lead_id}?access_token=\"", ".", "$", "this", "->", "getAccessToken", "(", ")", ";", "$", "data", "=", "giga_remote_get", "(", "$", "end_point", ")", ";", "return", "(", "array", ")", "$", "data", ";", "}" ]
Get user data @param String $lead_id @return Array
[ "Get", "user", "data" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Drivers/Facebook.php#L146-L153
226,564
gigaai/framework
src/Drivers/Facebook.php
Facebook.sendSubscribeRequest
public function sendSubscribeRequest($attributes) { $token = isset($attributes['access_token']) ? $attributes['access_token'] : $this->getAccessToken(); $page_id = $attributes['page_id']; $end_point = $this->getResource() . '/' . $page_id . '/subscribed_apps?access_token=' . $token; return giga_remote_post($end_point, [ 'subscribed_fields' => $attributes['subscribed_fields'] ]); }
php
public function sendSubscribeRequest($attributes) { $token = isset($attributes['access_token']) ? $attributes['access_token'] : $this->getAccessToken(); $page_id = $attributes['page_id']; $end_point = $this->getResource() . '/' . $page_id . '/subscribed_apps?access_token=' . $token; return giga_remote_post($end_point, [ 'subscribed_fields' => $attributes['subscribed_fields'] ]); }
[ "public", "function", "sendSubscribeRequest", "(", "$", "attributes", ")", "{", "$", "token", "=", "isset", "(", "$", "attributes", "[", "'access_token'", "]", ")", "?", "$", "attributes", "[", "'access_token'", "]", ":", "$", "this", "->", "getAccessToken", "(", ")", ";", "$", "page_id", "=", "$", "attributes", "[", "'page_id'", "]", ";", "$", "end_point", "=", "$", "this", "->", "getResource", "(", ")", ".", "'/'", ".", "$", "page_id", ".", "'/subscribed_apps?access_token='", ".", "$", "token", ";", "return", "giga_remote_post", "(", "$", "end_point", ",", "[", "'subscribed_fields'", "=>", "$", "attributes", "[", "'subscribed_fields'", "]", "]", ")", ";", "}" ]
Send subscribe request to FB @return json response
[ "Send", "subscribe", "request", "to", "FB" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Drivers/Facebook.php#L160-L170
226,565
gigaai/framework
src/Drivers/Telegram.php
Telegram.formatIncomingRequest
public function formatIncomingRequest($telegram) { if ( ! empty($telegram) && is_array($telegram)) { $sender_id = null; $time = null; if (isset($telegram['callback_query'])) { $message = $telegram['callback_query']; $sender_id = $telegram['callback_query']['from']['id']; $time = $telegram['callback_query']['message']['date']; } else if (isset($telegram['message'])) { $sender_id = $telegram['message']['from']['id']; $time = $telegram['message']['date']; } else { return $telegram; } $facebook = [ 'object' => 'page', 'entry' => [ [ 'id' => rand(), 'time' => $time, 'messaging' => [ [ 'sender' => [ 'id' => $sender_id, ], 'recipient' => [ 'id' => rand() ], 'timestamp' => $time, ] ] ] ] ]; if ( ! empty($telegram['message']['text'])) { $facebook['entry'][0]['messaging'][0]['message'] = [ 'text' => $telegram['message']['text'] ]; } if ( ! empty($telegram['callback_query']['data'])) { $facebook['entry'][0]['messaging'][0]['postback'] = [ 'payload' => $telegram['callback_query']['data'] ]; } return $facebook; } return $telegram; }
php
public function formatIncomingRequest($telegram) { if ( ! empty($telegram) && is_array($telegram)) { $sender_id = null; $time = null; if (isset($telegram['callback_query'])) { $message = $telegram['callback_query']; $sender_id = $telegram['callback_query']['from']['id']; $time = $telegram['callback_query']['message']['date']; } else if (isset($telegram['message'])) { $sender_id = $telegram['message']['from']['id']; $time = $telegram['message']['date']; } else { return $telegram; } $facebook = [ 'object' => 'page', 'entry' => [ [ 'id' => rand(), 'time' => $time, 'messaging' => [ [ 'sender' => [ 'id' => $sender_id, ], 'recipient' => [ 'id' => rand() ], 'timestamp' => $time, ] ] ] ] ]; if ( ! empty($telegram['message']['text'])) { $facebook['entry'][0]['messaging'][0]['message'] = [ 'text' => $telegram['message']['text'] ]; } if ( ! empty($telegram['callback_query']['data'])) { $facebook['entry'][0]['messaging'][0]['postback'] = [ 'payload' => $telegram['callback_query']['data'] ]; } return $facebook; } return $telegram; }
[ "public", "function", "formatIncomingRequest", "(", "$", "telegram", ")", "{", "if", "(", "!", "empty", "(", "$", "telegram", ")", "&&", "is_array", "(", "$", "telegram", ")", ")", "{", "$", "sender_id", "=", "null", ";", "$", "time", "=", "null", ";", "if", "(", "isset", "(", "$", "telegram", "[", "'callback_query'", "]", ")", ")", "{", "$", "message", "=", "$", "telegram", "[", "'callback_query'", "]", ";", "$", "sender_id", "=", "$", "telegram", "[", "'callback_query'", "]", "[", "'from'", "]", "[", "'id'", "]", ";", "$", "time", "=", "$", "telegram", "[", "'callback_query'", "]", "[", "'message'", "]", "[", "'date'", "]", ";", "}", "else", "if", "(", "isset", "(", "$", "telegram", "[", "'message'", "]", ")", ")", "{", "$", "sender_id", "=", "$", "telegram", "[", "'message'", "]", "[", "'from'", "]", "[", "'id'", "]", ";", "$", "time", "=", "$", "telegram", "[", "'message'", "]", "[", "'date'", "]", ";", "}", "else", "{", "return", "$", "telegram", ";", "}", "$", "facebook", "=", "[", "'object'", "=>", "'page'", ",", "'entry'", "=>", "[", "[", "'id'", "=>", "rand", "(", ")", ",", "'time'", "=>", "$", "time", ",", "'messaging'", "=>", "[", "[", "'sender'", "=>", "[", "'id'", "=>", "$", "sender_id", ",", "]", ",", "'recipient'", "=>", "[", "'id'", "=>", "rand", "(", ")", "]", ",", "'timestamp'", "=>", "$", "time", ",", "]", "]", "]", "]", "]", ";", "if", "(", "!", "empty", "(", "$", "telegram", "[", "'message'", "]", "[", "'text'", "]", ")", ")", "{", "$", "facebook", "[", "'entry'", "]", "[", "0", "]", "[", "'messaging'", "]", "[", "0", "]", "[", "'message'", "]", "=", "[", "'text'", "=>", "$", "telegram", "[", "'message'", "]", "[", "'text'", "]", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "telegram", "[", "'callback_query'", "]", "[", "'data'", "]", ")", ")", "{", "$", "facebook", "[", "'entry'", "]", "[", "0", "]", "[", "'messaging'", "]", "[", "0", "]", "[", "'postback'", "]", "=", "[", "'payload'", "=>", "$", "telegram", "[", "'callback_query'", "]", "[", "'data'", "]", "]", ";", "}", "return", "$", "facebook", ";", "}", "return", "$", "telegram", ";", "}" ]
Convert Telegram to Facebook request @see https://core.telegram.org/bots/api @see https://developers.facebook.com/docs/messenger-platform/webhook-reference#format
[ "Convert", "Telegram", "to", "Facebook", "request" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Drivers/Telegram.php#L45-L99
226,566
gigaai/framework
src/Drivers/Telegram.php
Telegram.sendMessage
public function sendMessage($body) { $action = 'sendMessage'; $telegram = [ 'chat_id' => $body['recipient']['id'] ]; $message = $body['message']; // Send Text if (isset($message['text'])) { $telegram['text'] = $message['text']; } // Sending Attachment if (isset($message['attachment']['type'])) { // Send Audio, Video, Image, File $convert = [ 'image' => 'photo', 'audio' => 'audio', 'video' => 'video', 'file' => 'document' ]; foreach ($convert as $facebook_template => $telegram_template) { if ($message['attachment']['type'] === $facebook_template) { $telegram[$telegram_template] = $message['attachment']['payload']['url']; $action = 'send' . ucfirst($telegram_template); return $this->callMethod($action, $telegram); } } // Sending Button, Generic, List if ($message['attachment']['type'] === 'template' && isset($message['attachment']['payload'])): // Facebook Button will be converted to InlineKeyboard if ($message['attachment']['payload']['template_type'] === 'button') { return $this->sendButtons($message['attachment']['payload']); } // Facebook Generic will be converted to Image + Text + Button if ($message['attachment']['payload']['template_type'] === 'generic') { return $this->sendGeneric($message['attachment']['payload']); } endif; } // Facebook Quick Replies will be converted to ReplyKeyboardMarkup if ( ! empty($message['quick_replies'])) { $telegram['reply_markup'] = [ 'keyboard' => [], 'one_time_keyboard' => true, ]; foreach ($message['quick_replies'] as $reply) { if ($reply['content_type'] === 'text') { $telegram['reply_markup']['keyboard'][] = [ [ 'text' => $reply['title'] ] ]; } if ($reply['content_type'] === 'location') { $telegram['reply_markup']['keyboard'][] = [ [ 'text' => 'Send Location', 'request_location' => true ] ]; } } } // We have to json encode the reply_markup if (isset($telegram['reply_markup'])) { $telegram['reply_markup'] = json_encode($telegram['reply_markup']); } // Facebook Quick Replies will convert to InlineKeyboard return giga_remote_post($this->getResource($action), $telegram); }
php
public function sendMessage($body) { $action = 'sendMessage'; $telegram = [ 'chat_id' => $body['recipient']['id'] ]; $message = $body['message']; // Send Text if (isset($message['text'])) { $telegram['text'] = $message['text']; } // Sending Attachment if (isset($message['attachment']['type'])) { // Send Audio, Video, Image, File $convert = [ 'image' => 'photo', 'audio' => 'audio', 'video' => 'video', 'file' => 'document' ]; foreach ($convert as $facebook_template => $telegram_template) { if ($message['attachment']['type'] === $facebook_template) { $telegram[$telegram_template] = $message['attachment']['payload']['url']; $action = 'send' . ucfirst($telegram_template); return $this->callMethod($action, $telegram); } } // Sending Button, Generic, List if ($message['attachment']['type'] === 'template' && isset($message['attachment']['payload'])): // Facebook Button will be converted to InlineKeyboard if ($message['attachment']['payload']['template_type'] === 'button') { return $this->sendButtons($message['attachment']['payload']); } // Facebook Generic will be converted to Image + Text + Button if ($message['attachment']['payload']['template_type'] === 'generic') { return $this->sendGeneric($message['attachment']['payload']); } endif; } // Facebook Quick Replies will be converted to ReplyKeyboardMarkup if ( ! empty($message['quick_replies'])) { $telegram['reply_markup'] = [ 'keyboard' => [], 'one_time_keyboard' => true, ]; foreach ($message['quick_replies'] as $reply) { if ($reply['content_type'] === 'text') { $telegram['reply_markup']['keyboard'][] = [ [ 'text' => $reply['title'] ] ]; } if ($reply['content_type'] === 'location') { $telegram['reply_markup']['keyboard'][] = [ [ 'text' => 'Send Location', 'request_location' => true ] ]; } } } // We have to json encode the reply_markup if (isset($telegram['reply_markup'])) { $telegram['reply_markup'] = json_encode($telegram['reply_markup']); } // Facebook Quick Replies will convert to InlineKeyboard return giga_remote_post($this->getResource($action), $telegram); }
[ "public", "function", "sendMessage", "(", "$", "body", ")", "{", "$", "action", "=", "'sendMessage'", ";", "$", "telegram", "=", "[", "'chat_id'", "=>", "$", "body", "[", "'recipient'", "]", "[", "'id'", "]", "]", ";", "$", "message", "=", "$", "body", "[", "'message'", "]", ";", "// Send Text", "if", "(", "isset", "(", "$", "message", "[", "'text'", "]", ")", ")", "{", "$", "telegram", "[", "'text'", "]", "=", "$", "message", "[", "'text'", "]", ";", "}", "// Sending Attachment", "if", "(", "isset", "(", "$", "message", "[", "'attachment'", "]", "[", "'type'", "]", ")", ")", "{", "// Send Audio, Video, Image, File", "$", "convert", "=", "[", "'image'", "=>", "'photo'", ",", "'audio'", "=>", "'audio'", ",", "'video'", "=>", "'video'", ",", "'file'", "=>", "'document'", "]", ";", "foreach", "(", "$", "convert", "as", "$", "facebook_template", "=>", "$", "telegram_template", ")", "{", "if", "(", "$", "message", "[", "'attachment'", "]", "[", "'type'", "]", "===", "$", "facebook_template", ")", "{", "$", "telegram", "[", "$", "telegram_template", "]", "=", "$", "message", "[", "'attachment'", "]", "[", "'payload'", "]", "[", "'url'", "]", ";", "$", "action", "=", "'send'", ".", "ucfirst", "(", "$", "telegram_template", ")", ";", "return", "$", "this", "->", "callMethod", "(", "$", "action", ",", "$", "telegram", ")", ";", "}", "}", "// Sending Button, Generic, List", "if", "(", "$", "message", "[", "'attachment'", "]", "[", "'type'", "]", "===", "'template'", "&&", "isset", "(", "$", "message", "[", "'attachment'", "]", "[", "'payload'", "]", ")", ")", ":", "// Facebook Button will be converted to InlineKeyboard", "if", "(", "$", "message", "[", "'attachment'", "]", "[", "'payload'", "]", "[", "'template_type'", "]", "===", "'button'", ")", "{", "return", "$", "this", "->", "sendButtons", "(", "$", "message", "[", "'attachment'", "]", "[", "'payload'", "]", ")", ";", "}", "// Facebook Generic will be converted to Image + Text + Button", "if", "(", "$", "message", "[", "'attachment'", "]", "[", "'payload'", "]", "[", "'template_type'", "]", "===", "'generic'", ")", "{", "return", "$", "this", "->", "sendGeneric", "(", "$", "message", "[", "'attachment'", "]", "[", "'payload'", "]", ")", ";", "}", "endif", ";", "}", "// Facebook Quick Replies will be converted to ReplyKeyboardMarkup", "if", "(", "!", "empty", "(", "$", "message", "[", "'quick_replies'", "]", ")", ")", "{", "$", "telegram", "[", "'reply_markup'", "]", "=", "[", "'keyboard'", "=>", "[", "]", ",", "'one_time_keyboard'", "=>", "true", ",", "]", ";", "foreach", "(", "$", "message", "[", "'quick_replies'", "]", "as", "$", "reply", ")", "{", "if", "(", "$", "reply", "[", "'content_type'", "]", "===", "'text'", ")", "{", "$", "telegram", "[", "'reply_markup'", "]", "[", "'keyboard'", "]", "[", "]", "=", "[", "[", "'text'", "=>", "$", "reply", "[", "'title'", "]", "]", "]", ";", "}", "if", "(", "$", "reply", "[", "'content_type'", "]", "===", "'location'", ")", "{", "$", "telegram", "[", "'reply_markup'", "]", "[", "'keyboard'", "]", "[", "]", "=", "[", "[", "'text'", "=>", "'Send Location'", ",", "'request_location'", "=>", "true", "]", "]", ";", "}", "}", "}", "// We have to json encode the reply_markup", "if", "(", "isset", "(", "$", "telegram", "[", "'reply_markup'", "]", ")", ")", "{", "$", "telegram", "[", "'reply_markup'", "]", "=", "json_encode", "(", "$", "telegram", "[", "'reply_markup'", "]", ")", ";", "}", "// Facebook Quick Replies will convert to InlineKeyboard", "return", "giga_remote_post", "(", "$", "this", "->", "getResource", "(", "$", "action", ")", ",", "$", "telegram", ")", ";", "}" ]
Convert Facebook request back to Telegram request @param $body Body as Facebook format
[ "Convert", "Facebook", "request", "back", "to", "Telegram", "request" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Drivers/Telegram.php#L106-L192
226,567
gigaai/framework
src/Drivers/Telegram.php
Telegram.callMethod
private function callMethod($method, $params) { $params['chat_id'] = Conversation::get('lead_id'); return giga_remote_post($this->getResource($method), $params); }
php
private function callMethod($method, $params) { $params['chat_id'] = Conversation::get('lead_id'); return giga_remote_post($this->getResource($method), $params); }
[ "private", "function", "callMethod", "(", "$", "method", ",", "$", "params", ")", "{", "$", "params", "[", "'chat_id'", "]", "=", "Conversation", "::", "get", "(", "'lead_id'", ")", ";", "return", "giga_remote_post", "(", "$", "this", "->", "getResource", "(", "$", "method", ")", ",", "$", "params", ")", ";", "}" ]
Call Telegram method via HTTP @see https://core.telegram.org/bots/api#available-methods
[ "Call", "Telegram", "method", "via", "HTTP" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Drivers/Telegram.php#L199-L204
226,568
gigaai/framework
src/Drivers/Telegram.php
Telegram.sendGeneric
private function sendGeneric($payload) { foreach ($payload['elements'] as $element) { $generic = []; if (isset($element['image_url'])) { $generic['photo'] = $element['image_url']; $generic['caption'] = $element['title']; $keyboard = $this->convertToInlineKeyboard($element['buttons']); $generic['reply_markup'] = $keyboard['reply_markup']; $this->callMethod('sendPhoto', $generic); } else { $this->sendButtons([ 'text' => $element['title'], 'buttons' => $generic['buttons'] ]); } } }
php
private function sendGeneric($payload) { foreach ($payload['elements'] as $element) { $generic = []; if (isset($element['image_url'])) { $generic['photo'] = $element['image_url']; $generic['caption'] = $element['title']; $keyboard = $this->convertToInlineKeyboard($element['buttons']); $generic['reply_markup'] = $keyboard['reply_markup']; $this->callMethod('sendPhoto', $generic); } else { $this->sendButtons([ 'text' => $element['title'], 'buttons' => $generic['buttons'] ]); } } }
[ "private", "function", "sendGeneric", "(", "$", "payload", ")", "{", "foreach", "(", "$", "payload", "[", "'elements'", "]", "as", "$", "element", ")", "{", "$", "generic", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "element", "[", "'image_url'", "]", ")", ")", "{", "$", "generic", "[", "'photo'", "]", "=", "$", "element", "[", "'image_url'", "]", ";", "$", "generic", "[", "'caption'", "]", "=", "$", "element", "[", "'title'", "]", ";", "$", "keyboard", "=", "$", "this", "->", "convertToInlineKeyboard", "(", "$", "element", "[", "'buttons'", "]", ")", ";", "$", "generic", "[", "'reply_markup'", "]", "=", "$", "keyboard", "[", "'reply_markup'", "]", ";", "$", "this", "->", "callMethod", "(", "'sendPhoto'", ",", "$", "generic", ")", ";", "}", "else", "{", "$", "this", "->", "sendButtons", "(", "[", "'text'", "=>", "$", "element", "[", "'title'", "]", ",", "'buttons'", "=>", "$", "generic", "[", "'buttons'", "]", "]", ")", ";", "}", "}", "}" ]
Convert Generic to Photo with Caption + Buttons @param Array $payload @return Json
[ "Convert", "Generic", "to", "Photo", "with", "Caption", "+", "Buttons" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Drivers/Telegram.php#L251-L270
226,569
gigaai/framework
src/Drivers/Telegram.php
Telegram.sendTyping
public function sendTyping() { $lead_id = Conversation::get('lead_id'); $body = [ 'chat_id' => $lead_id, 'action' => 'typing' ]; giga_remote_post($this->getResource('sendChatAction'), $body); }
php
public function sendTyping() { $lead_id = Conversation::get('lead_id'); $body = [ 'chat_id' => $lead_id, 'action' => 'typing' ]; giga_remote_post($this->getResource('sendChatAction'), $body); }
[ "public", "function", "sendTyping", "(", ")", "{", "$", "lead_id", "=", "Conversation", "::", "get", "(", "'lead_id'", ")", ";", "$", "body", "=", "[", "'chat_id'", "=>", "$", "lead_id", ",", "'action'", "=>", "'typing'", "]", ";", "giga_remote_post", "(", "$", "this", "->", "getResource", "(", "'sendChatAction'", ")", ",", "$", "body", ")", ";", "}" ]
Send typing indicator
[ "Send", "typing", "indicator" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Drivers/Telegram.php#L275-L285
226,570
gigaai/framework
src/Drivers/Telegram.php
Telegram.getUser
public function getUser($lead_id) { // Because the received data already contains user info so we don't need to make any request $raw = Conversation::get('request_raw'); if (isset($raw['callback_query'])) { $raw = $raw['callback_query']; $user = $raw['from']; } else { $user = $raw['message']['from']; } return [ 'user_id' => $lead_id, 'first_name' => $user['first_name'], 'last_name' => $user['last_name'], 'source' => 'telegram:' . Conversation::get('page_id'), 'locale' => str_replace('-', '_', $user['language_code']) ]; }
php
public function getUser($lead_id) { // Because the received data already contains user info so we don't need to make any request $raw = Conversation::get('request_raw'); if (isset($raw['callback_query'])) { $raw = $raw['callback_query']; $user = $raw['from']; } else { $user = $raw['message']['from']; } return [ 'user_id' => $lead_id, 'first_name' => $user['first_name'], 'last_name' => $user['last_name'], 'source' => 'telegram:' . Conversation::get('page_id'), 'locale' => str_replace('-', '_', $user['language_code']) ]; }
[ "public", "function", "getUser", "(", "$", "lead_id", ")", "{", "// Because the received data already contains user info so we don't need to make any request", "$", "raw", "=", "Conversation", "::", "get", "(", "'request_raw'", ")", ";", "if", "(", "isset", "(", "$", "raw", "[", "'callback_query'", "]", ")", ")", "{", "$", "raw", "=", "$", "raw", "[", "'callback_query'", "]", ";", "$", "user", "=", "$", "raw", "[", "'from'", "]", ";", "}", "else", "{", "$", "user", "=", "$", "raw", "[", "'message'", "]", "[", "'from'", "]", ";", "}", "return", "[", "'user_id'", "=>", "$", "lead_id", ",", "'first_name'", "=>", "$", "user", "[", "'first_name'", "]", ",", "'last_name'", "=>", "$", "user", "[", "'last_name'", "]", ",", "'source'", "=>", "'telegram:'", ".", "Conversation", "::", "get", "(", "'page_id'", ")", ",", "'locale'", "=>", "str_replace", "(", "'-'", ",", "'_'", ",", "$", "user", "[", "'language_code'", "]", ")", "]", ";", "}" ]
Method to get current user @return Array format as Facebook
[ "Method", "to", "get", "current", "user" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Drivers/Telegram.php#L292-L312
226,571
gigaai/framework
src/Core/Model.php
Model.addNode
public function addNode($pattern, $answers = null, $attributes = []) { // Multiple nodes. If user like to use $patterns => $answers method if (is_array($pattern) && is_null($answers)) { $this->addNodes($pattern, $attributes); return null; } $type_pattern = $this->getNodeTypeAndPattern($pattern); list($type, $pattern) = $type_pattern; if (!is_string($pattern) && is_callable($pattern)) { $this->persistNode( [['type' => 'callback', 'content' => $answers]], $type, $pattern, $attributes ); return $this; } if (is_string($answers)) { $answers = trim($answers); } $answers = (array)$answers; $answers = $this->parse($answers); // Persist to DB $this->persistNode($answers, $type, $pattern, $attributes); return $this; }
php
public function addNode($pattern, $answers = null, $attributes = []) { // Multiple nodes. If user like to use $patterns => $answers method if (is_array($pattern) && is_null($answers)) { $this->addNodes($pattern, $attributes); return null; } $type_pattern = $this->getNodeTypeAndPattern($pattern); list($type, $pattern) = $type_pattern; if (!is_string($pattern) && is_callable($pattern)) { $this->persistNode( [['type' => 'callback', 'content' => $answers]], $type, $pattern, $attributes ); return $this; } if (is_string($answers)) { $answers = trim($answers); } $answers = (array)$answers; $answers = $this->parse($answers); // Persist to DB $this->persistNode($answers, $type, $pattern, $attributes); return $this; }
[ "public", "function", "addNode", "(", "$", "pattern", ",", "$", "answers", "=", "null", ",", "$", "attributes", "=", "[", "]", ")", "{", "// Multiple nodes. If user like to use $patterns => $answers method", "if", "(", "is_array", "(", "$", "pattern", ")", "&&", "is_null", "(", "$", "answers", ")", ")", "{", "$", "this", "->", "addNodes", "(", "$", "pattern", ",", "$", "attributes", ")", ";", "return", "null", ";", "}", "$", "type_pattern", "=", "$", "this", "->", "getNodeTypeAndPattern", "(", "$", "pattern", ")", ";", "list", "(", "$", "type", ",", "$", "pattern", ")", "=", "$", "type_pattern", ";", "if", "(", "!", "is_string", "(", "$", "pattern", ")", "&&", "is_callable", "(", "$", "pattern", ")", ")", "{", "$", "this", "->", "persistNode", "(", "[", "[", "'type'", "=>", "'callback'", ",", "'content'", "=>", "$", "answers", "]", "]", ",", "$", "type", ",", "$", "pattern", ",", "$", "attributes", ")", ";", "return", "$", "this", ";", "}", "if", "(", "is_string", "(", "$", "answers", ")", ")", "{", "$", "answers", "=", "trim", "(", "$", "answers", ")", ";", "}", "$", "answers", "=", "(", "array", ")", "$", "answers", ";", "$", "answers", "=", "$", "this", "->", "parse", "(", "$", "answers", ")", ";", "// Persist to DB", "$", "this", "->", "persistNode", "(", "$", "answers", ",", "$", "type", ",", "$", "pattern", ",", "$", "attributes", ")", ";", "return", "$", "this", ";", "}" ]
Add Node to the Database @param $pattern @param null $answers @param array $attributes @return $this|null
[ "Add", "Node", "to", "the", "Database" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Core/Model.php#L77-L111
226,572
gigaai/framework
src/Core/Model.php
Model.getNodeTypeAndPattern
private function getNodeTypeAndPattern($pattern) { $node_type = 'text'; // If user set payload, default, welcome message. foreach (['payload', 'default', 'attachment'] as $type) { if (strpos($pattern, $type . ':') !== false) { $node_type = $type; $pattern = str_replace($node_type . ':', '', $pattern); } } if (!empty($pattern) && $pattern[0] == '@') { $node_type = 'intended'; $pattern = str_replace('@', '', $pattern); } return [$node_type, $pattern]; }
php
private function getNodeTypeAndPattern($pattern) { $node_type = 'text'; // If user set payload, default, welcome message. foreach (['payload', 'default', 'attachment'] as $type) { if (strpos($pattern, $type . ':') !== false) { $node_type = $type; $pattern = str_replace($node_type . ':', '', $pattern); } } if (!empty($pattern) && $pattern[0] == '@') { $node_type = 'intended'; $pattern = str_replace('@', '', $pattern); } return [$node_type, $pattern]; }
[ "private", "function", "getNodeTypeAndPattern", "(", "$", "pattern", ")", "{", "$", "node_type", "=", "'text'", ";", "// If user set payload, default, welcome message.", "foreach", "(", "[", "'payload'", ",", "'default'", ",", "'attachment'", "]", "as", "$", "type", ")", "{", "if", "(", "strpos", "(", "$", "pattern", ",", "$", "type", ".", "':'", ")", "!==", "false", ")", "{", "$", "node_type", "=", "$", "type", ";", "$", "pattern", "=", "str_replace", "(", "$", "node_type", ".", "':'", ",", "''", ",", "$", "pattern", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "pattern", ")", "&&", "$", "pattern", "[", "0", "]", "==", "'@'", ")", "{", "$", "node_type", "=", "'intended'", ";", "$", "pattern", "=", "str_replace", "(", "'@'", ",", "''", ",", "$", "pattern", ")", ";", "}", "return", "[", "$", "node_type", ",", "$", "pattern", "]", ";", "}" ]
Get Node type and Pattern @param $pattern @return array
[ "Get", "Node", "type", "and", "Pattern" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Core/Model.php#L120-L138
226,573
gigaai/framework
src/Core/Model.php
Model.addNodes
public function addNodes($nodes, $attributes = []) { foreach ($nodes as $pattern => $answers) { $this->addNode($pattern, $answers, $attributes); } }
php
public function addNodes($nodes, $attributes = []) { foreach ($nodes as $pattern => $answers) { $this->addNode($pattern, $answers, $attributes); } }
[ "public", "function", "addNodes", "(", "$", "nodes", ",", "$", "attributes", "=", "[", "]", ")", "{", "foreach", "(", "$", "nodes", "as", "$", "pattern", "=>", "$", "answers", ")", "{", "$", "this", "->", "addNode", "(", "$", "pattern", ",", "$", "answers", ",", "$", "attributes", ")", ";", "}", "}" ]
Add Multiple Nodes @param $nodes
[ "Add", "Multiple", "Nodes" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Core/Model.php#L145-L150
226,574
gigaai/framework
src/Core/Model.php
Model.persistNode
public function persistNode(array $answers, $node_type, $pattern = null, $attributes = []) { foreach ($answers as $index => $answer) { if (isset($answer['type']) && isset($answer['content']) && is_callable($answer['content'])) { $answer['content'] = is_string($answer['content']) ? $answer['content'] : $this->serializer->serialize($answer['content']); } $answers[$index] = $answer; } $this->current_node = Storage::addNode($answers, $node_type, $pattern, $attributes); return $this->current_node; }
php
public function persistNode(array $answers, $node_type, $pattern = null, $attributes = []) { foreach ($answers as $index => $answer) { if (isset($answer['type']) && isset($answer['content']) && is_callable($answer['content'])) { $answer['content'] = is_string($answer['content']) ? $answer['content'] : $this->serializer->serialize($answer['content']); } $answers[$index] = $answer; } $this->current_node = Storage::addNode($answers, $node_type, $pattern, $attributes); return $this->current_node; }
[ "public", "function", "persistNode", "(", "array", "$", "answers", ",", "$", "node_type", ",", "$", "pattern", "=", "null", ",", "$", "attributes", "=", "[", "]", ")", "{", "foreach", "(", "$", "answers", "as", "$", "index", "=>", "$", "answer", ")", "{", "if", "(", "isset", "(", "$", "answer", "[", "'type'", "]", ")", "&&", "isset", "(", "$", "answer", "[", "'content'", "]", ")", "&&", "is_callable", "(", "$", "answer", "[", "'content'", "]", ")", ")", "{", "$", "answer", "[", "'content'", "]", "=", "is_string", "(", "$", "answer", "[", "'content'", "]", ")", "?", "$", "answer", "[", "'content'", "]", ":", "$", "this", "->", "serializer", "->", "serialize", "(", "$", "answer", "[", "'content'", "]", ")", ";", "}", "$", "answers", "[", "$", "index", "]", "=", "$", "answer", ";", "}", "$", "this", "->", "current_node", "=", "Storage", "::", "addNode", "(", "$", "answers", ",", "$", "node_type", ",", "$", "pattern", ",", "$", "attributes", ")", ";", "return", "$", "this", "->", "current_node", ";", "}" ]
Add answer to node @param Mixed $answers Message @param String $node_type Node Type @param null $pattern Question @return Node
[ "Add", "answer", "to", "node" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Core/Model.php#L161-L173
226,575
gigaai/framework
src/Core/Model.php
Model.parse
public function parse($answers) { // Iterate through answers and parse it if possible // Also, move quick replies to the last answer $parsed = []; $previous_index = 0; if ($this->isSingularResponse($answers)) { $answers = [$answers]; } foreach ($answers as $index => $answer) { // If the answer is a Closure if (!is_string($answer) && is_callable($answer)) { $answer = [ 'type' => 'callback', 'content' => $answer, ]; } if (isset($answer['content']) && isset($answer['quick_replies'])) { $answer['content'] = (array)$answer['content']; $answer['content']['quick_replies'] = $answer['quick_replies']; unset($answer['quick_replies']); } // Cast attachment key to other messages if (($index === 'attachment' || isset($answer['attachment']))) { $answer = $this->parseAttachmentMessage($index, $answer); } // Parse answer when possible. // Iterate through supported message type and return if answer is supported if ($this->isParsable($answer) && $index !== 'quick_replies') { if (isset($answer['type'])) { $parser = $this->typeClasses[$answer['type']]; $parsedAnswer = $parser::load($answer['content'], [ 'skip_detection' => true ]); if ($parsedAnswer !== false) { $answer = $parsedAnswer; } } else { foreach ($this->typeClasses as $type => $parser) { // If not supported, it will return false, otherwise, return parsed data $parsedAnswer = $parser::load($answer); if ($parsedAnswer !== false) { $answer = $parsedAnswer; break; } } } } if ($index === 'quick_replies') { $parsed[$previous_index] = (array)$parsed[$previous_index]; $parsed[$previous_index]['content']['quick_replies'] = $answer; } $parsed[$index] = $answer; $previous_index = $index; } unset($parsed['quick_replies']); return $parsed; }
php
public function parse($answers) { // Iterate through answers and parse it if possible // Also, move quick replies to the last answer $parsed = []; $previous_index = 0; if ($this->isSingularResponse($answers)) { $answers = [$answers]; } foreach ($answers as $index => $answer) { // If the answer is a Closure if (!is_string($answer) && is_callable($answer)) { $answer = [ 'type' => 'callback', 'content' => $answer, ]; } if (isset($answer['content']) && isset($answer['quick_replies'])) { $answer['content'] = (array)$answer['content']; $answer['content']['quick_replies'] = $answer['quick_replies']; unset($answer['quick_replies']); } // Cast attachment key to other messages if (($index === 'attachment' || isset($answer['attachment']))) { $answer = $this->parseAttachmentMessage($index, $answer); } // Parse answer when possible. // Iterate through supported message type and return if answer is supported if ($this->isParsable($answer) && $index !== 'quick_replies') { if (isset($answer['type'])) { $parser = $this->typeClasses[$answer['type']]; $parsedAnswer = $parser::load($answer['content'], [ 'skip_detection' => true ]); if ($parsedAnswer !== false) { $answer = $parsedAnswer; } } else { foreach ($this->typeClasses as $type => $parser) { // If not supported, it will return false, otherwise, return parsed data $parsedAnswer = $parser::load($answer); if ($parsedAnswer !== false) { $answer = $parsedAnswer; break; } } } } if ($index === 'quick_replies') { $parsed[$previous_index] = (array)$parsed[$previous_index]; $parsed[$previous_index]['content']['quick_replies'] = $answer; } $parsed[$index] = $answer; $previous_index = $index; } unset($parsed['quick_replies']); return $parsed; }
[ "public", "function", "parse", "(", "$", "answers", ")", "{", "// Iterate through answers and parse it if possible", "// Also, move quick replies to the last answer", "$", "parsed", "=", "[", "]", ";", "$", "previous_index", "=", "0", ";", "if", "(", "$", "this", "->", "isSingularResponse", "(", "$", "answers", ")", ")", "{", "$", "answers", "=", "[", "$", "answers", "]", ";", "}", "foreach", "(", "$", "answers", "as", "$", "index", "=>", "$", "answer", ")", "{", "// If the answer is a Closure", "if", "(", "!", "is_string", "(", "$", "answer", ")", "&&", "is_callable", "(", "$", "answer", ")", ")", "{", "$", "answer", "=", "[", "'type'", "=>", "'callback'", ",", "'content'", "=>", "$", "answer", ",", "]", ";", "}", "if", "(", "isset", "(", "$", "answer", "[", "'content'", "]", ")", "&&", "isset", "(", "$", "answer", "[", "'quick_replies'", "]", ")", ")", "{", "$", "answer", "[", "'content'", "]", "=", "(", "array", ")", "$", "answer", "[", "'content'", "]", ";", "$", "answer", "[", "'content'", "]", "[", "'quick_replies'", "]", "=", "$", "answer", "[", "'quick_replies'", "]", ";", "unset", "(", "$", "answer", "[", "'quick_replies'", "]", ")", ";", "}", "// Cast attachment key to other messages", "if", "(", "(", "$", "index", "===", "'attachment'", "||", "isset", "(", "$", "answer", "[", "'attachment'", "]", ")", ")", ")", "{", "$", "answer", "=", "$", "this", "->", "parseAttachmentMessage", "(", "$", "index", ",", "$", "answer", ")", ";", "}", "// Parse answer when possible.", "// Iterate through supported message type and return if answer is supported", "if", "(", "$", "this", "->", "isParsable", "(", "$", "answer", ")", "&&", "$", "index", "!==", "'quick_replies'", ")", "{", "if", "(", "isset", "(", "$", "answer", "[", "'type'", "]", ")", ")", "{", "$", "parser", "=", "$", "this", "->", "typeClasses", "[", "$", "answer", "[", "'type'", "]", "]", ";", "$", "parsedAnswer", "=", "$", "parser", "::", "load", "(", "$", "answer", "[", "'content'", "]", ",", "[", "'skip_detection'", "=>", "true", "]", ")", ";", "if", "(", "$", "parsedAnswer", "!==", "false", ")", "{", "$", "answer", "=", "$", "parsedAnswer", ";", "}", "}", "else", "{", "foreach", "(", "$", "this", "->", "typeClasses", "as", "$", "type", "=>", "$", "parser", ")", "{", "// If not supported, it will return false, otherwise, return parsed data", "$", "parsedAnswer", "=", "$", "parser", "::", "load", "(", "$", "answer", ")", ";", "if", "(", "$", "parsedAnswer", "!==", "false", ")", "{", "$", "answer", "=", "$", "parsedAnswer", ";", "break", ";", "}", "}", "}", "}", "if", "(", "$", "index", "===", "'quick_replies'", ")", "{", "$", "parsed", "[", "$", "previous_index", "]", "=", "(", "array", ")", "$", "parsed", "[", "$", "previous_index", "]", ";", "$", "parsed", "[", "$", "previous_index", "]", "[", "'content'", "]", "[", "'quick_replies'", "]", "=", "$", "answer", ";", "}", "$", "parsed", "[", "$", "index", "]", "=", "$", "answer", ";", "$", "previous_index", "=", "$", "index", ";", "}", "unset", "(", "$", "parsed", "[", "'quick_replies'", "]", ")", ";", "return", "$", "parsed", ";", "}" ]
Parse the answers to correct FB Format.
[ "Parse", "the", "answers", "to", "correct", "FB", "Format", "." ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Core/Model.php#L207-L279
226,576
gigaai/framework
src/Core/Model.php
Model.parseAttachmentMessage
private function parseAttachmentMessage($index, $answer) { $templateType = null; if (isset($answer['type'])) { $templateType = $answer['type']; } $attachment = $index === 'attachment' ? $answer : $answer['attachment']; if (isset($attachment['payload']) && isset($attachment['payload']['template_type'])) { $templateType = $attachment['payload']['template_type']; } return [ 'type' => $templateType, 'content' => $answer ]; }
php
private function parseAttachmentMessage($index, $answer) { $templateType = null; if (isset($answer['type'])) { $templateType = $answer['type']; } $attachment = $index === 'attachment' ? $answer : $answer['attachment']; if (isset($attachment['payload']) && isset($attachment['payload']['template_type'])) { $templateType = $attachment['payload']['template_type']; } return [ 'type' => $templateType, 'content' => $answer ]; }
[ "private", "function", "parseAttachmentMessage", "(", "$", "index", ",", "$", "answer", ")", "{", "$", "templateType", "=", "null", ";", "if", "(", "isset", "(", "$", "answer", "[", "'type'", "]", ")", ")", "{", "$", "templateType", "=", "$", "answer", "[", "'type'", "]", ";", "}", "$", "attachment", "=", "$", "index", "===", "'attachment'", "?", "$", "answer", ":", "$", "answer", "[", "'attachment'", "]", ";", "if", "(", "isset", "(", "$", "attachment", "[", "'payload'", "]", ")", "&&", "isset", "(", "$", "attachment", "[", "'payload'", "]", "[", "'template_type'", "]", ")", ")", "{", "$", "templateType", "=", "$", "attachment", "[", "'payload'", "]", "[", "'template_type'", "]", ";", "}", "return", "[", "'type'", "=>", "$", "templateType", ",", "'content'", "=>", "$", "answer", "]", ";", "}" ]
If message starts with `attachment` parameter. We'll keep everything inside that param and only check message type. @return array
[ "If", "message", "starts", "with", "attachment", "parameter", ".", "We", "ll", "keep", "everything", "inside", "that", "param", "and", "only", "check", "message", "type", "." ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Core/Model.php#L287-L305
226,577
gigaai/framework
src/Core/Model.php
Model.isSingularResponse
private function isSingularResponse($answer) { return ( is_string($answer) || is_callable($answer) || array_key_exists('buttons', $answer) || array_key_exists('elements', $answer) || // For Generic or Receipt (is_array($answer) && isset($answer[0]) && is_array($answer[0]) && array_key_exists( 'title', $answer[0] )) || // For Generic isset($answer['text']) || // For Button isset($answer['type']) || // For type => content => isset($answer['attachment']) // For attachment ); }
php
private function isSingularResponse($answer) { return ( is_string($answer) || is_callable($answer) || array_key_exists('buttons', $answer) || array_key_exists('elements', $answer) || // For Generic or Receipt (is_array($answer) && isset($answer[0]) && is_array($answer[0]) && array_key_exists( 'title', $answer[0] )) || // For Generic isset($answer['text']) || // For Button isset($answer['type']) || // For type => content => isset($answer['attachment']) // For attachment ); }
[ "private", "function", "isSingularResponse", "(", "$", "answer", ")", "{", "return", "(", "is_string", "(", "$", "answer", ")", "||", "is_callable", "(", "$", "answer", ")", "||", "array_key_exists", "(", "'buttons'", ",", "$", "answer", ")", "||", "array_key_exists", "(", "'elements'", ",", "$", "answer", ")", "||", "// For Generic or Receipt", "(", "is_array", "(", "$", "answer", ")", "&&", "isset", "(", "$", "answer", "[", "0", "]", ")", "&&", "is_array", "(", "$", "answer", "[", "0", "]", ")", "&&", "array_key_exists", "(", "'title'", ",", "$", "answer", "[", "0", "]", ")", ")", "||", "// For Generic", "isset", "(", "$", "answer", "[", "'text'", "]", ")", "||", "// For Button", "isset", "(", "$", "answer", "[", "'type'", "]", ")", "||", "// For type => content =>", "isset", "(", "$", "answer", "[", "'attachment'", "]", ")", "// For attachment", ")", ";", "}" ]
Check if answers input is single answer @param $answer @return bool
[ "Check", "if", "answers", "input", "is", "single", "answer" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Core/Model.php#L314-L329
226,578
gigaai/framework
src/Core/Model.php
Model.addIntendedAction
public function addIntendedAction($action) { if (empty($this->current_node->type) || $this->current_node->type == 'welcome') { return; } // If it's ->then() intended action. We'll save next action as id if (is_callable($action)) { $related = $this->current_node; $then_node = $this->persistNode([ [ 'type' => 'callback', 'content' => $action, ], ], 'intended', 'IA#' . $related->id); $related->wait = $then_node->id; $related->save(); } else { $this->current_node->wait = $action; $this->current_node->save(); } }
php
public function addIntendedAction($action) { if (empty($this->current_node->type) || $this->current_node->type == 'welcome') { return; } // If it's ->then() intended action. We'll save next action as id if (is_callable($action)) { $related = $this->current_node; $then_node = $this->persistNode([ [ 'type' => 'callback', 'content' => $action, ], ], 'intended', 'IA#' . $related->id); $related->wait = $then_node->id; $related->save(); } else { $this->current_node->wait = $action; $this->current_node->save(); } }
[ "public", "function", "addIntendedAction", "(", "$", "action", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "current_node", "->", "type", ")", "||", "$", "this", "->", "current_node", "->", "type", "==", "'welcome'", ")", "{", "return", ";", "}", "// If it's ->then() intended action. We'll save next action as id", "if", "(", "is_callable", "(", "$", "action", ")", ")", "{", "$", "related", "=", "$", "this", "->", "current_node", ";", "$", "then_node", "=", "$", "this", "->", "persistNode", "(", "[", "[", "'type'", "=>", "'callback'", ",", "'content'", "=>", "$", "action", ",", "]", ",", "]", ",", "'intended'", ",", "'IA#'", ".", "$", "related", "->", "id", ")", ";", "$", "related", "->", "wait", "=", "$", "then_node", "->", "id", ";", "$", "related", "->", "save", "(", ")", ";", "}", "else", "{", "$", "this", "->", "current_node", "->", "wait", "=", "$", "action", ";", "$", "this", "->", "current_node", "->", "save", "(", ")", ";", "}", "}" ]
Add intended action for current node @param $action
[ "Add", "intended", "action", "for", "current", "node" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Core/Model.php#L336-L361
226,579
gigaai/framework
src/Core/Model.php
Model.taggedAs
public function taggedAs($tag) { if (empty($this->current_node)) { return; } $this->current_node->tags = $tag; $this->current_node->save(); }
php
public function taggedAs($tag) { if (empty($this->current_node)) { return; } $this->current_node->tags = $tag; $this->current_node->save(); }
[ "public", "function", "taggedAs", "(", "$", "tag", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "current_node", ")", ")", "{", "return", ";", "}", "$", "this", "->", "current_node", "->", "tags", "=", "$", "tag", ";", "$", "this", "->", "current_node", "->", "save", "(", ")", ";", "}" ]
Tag a node @param $tag
[ "Tag", "a", "node" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Core/Model.php#L368-L376
226,580
gigaai/framework
src/Message/Attachment.php
Attachment.normalize
public function normalize() { $url = $this->getMediaUrl($this->mediaType); return [ 'type' => $this->mediaType, 'content' => [ 'attachment' => [ 'type' => $this->mediaType, 'payload' => [ 'url' => $url, 'is_reusable' => true ] ] ] ]; }
php
public function normalize() { $url = $this->getMediaUrl($this->mediaType); return [ 'type' => $this->mediaType, 'content' => [ 'attachment' => [ 'type' => $this->mediaType, 'payload' => [ 'url' => $url, 'is_reusable' => true ] ] ] ]; }
[ "public", "function", "normalize", "(", ")", "{", "$", "url", "=", "$", "this", "->", "getMediaUrl", "(", "$", "this", "->", "mediaType", ")", ";", "return", "[", "'type'", "=>", "$", "this", "->", "mediaType", ",", "'content'", "=>", "[", "'attachment'", "=>", "[", "'type'", "=>", "$", "this", "->", "mediaType", ",", "'payload'", "=>", "[", "'url'", "=>", "$", "url", ",", "'is_reusable'", "=>", "true", "]", "]", "]", "]", ";", "}" ]
Convert to Facebook format to response @return Array
[ "Convert", "to", "Facebook", "format", "to", "response" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Message/Attachment.php#L47-L63
226,581
gigaai/framework
src/Message/Attachment.php
Attachment.detectMediaType
public function detectMediaType($url) { foreach ($this->availableTypes as $type) { if (starts_with($url, $type . ':')) { return $type; } } if (giga_match('%(.jpg|.png|.bmp|.gif|.jpeg|.tiff|.gif)%', $url)) { return 'image'; } if (giga_match('%(.avi|.flv|.mp4|.mkv|.3gp|.webm|.vob|.mov|.rm|.rmvb)%', $url)) { return 'video'; } if (giga_match('%(.mp3|.wma|.midi|.au)%', $url)) { return 'audio'; } return null; }
php
public function detectMediaType($url) { foreach ($this->availableTypes as $type) { if (starts_with($url, $type . ':')) { return $type; } } if (giga_match('%(.jpg|.png|.bmp|.gif|.jpeg|.tiff|.gif)%', $url)) { return 'image'; } if (giga_match('%(.avi|.flv|.mp4|.mkv|.3gp|.webm|.vob|.mov|.rm|.rmvb)%', $url)) { return 'video'; } if (giga_match('%(.mp3|.wma|.midi|.au)%', $url)) { return 'audio'; } return null; }
[ "public", "function", "detectMediaType", "(", "$", "url", ")", "{", "foreach", "(", "$", "this", "->", "availableTypes", "as", "$", "type", ")", "{", "if", "(", "starts_with", "(", "$", "url", ",", "$", "type", ".", "':'", ")", ")", "{", "return", "$", "type", ";", "}", "}", "if", "(", "giga_match", "(", "'%(.jpg|.png|.bmp|.gif|.jpeg|.tiff|.gif)%'", ",", "$", "url", ")", ")", "{", "return", "'image'", ";", "}", "if", "(", "giga_match", "(", "'%(.avi|.flv|.mp4|.mkv|.3gp|.webm|.vob|.mov|.rm|.rmvb)%'", ",", "$", "url", ")", ")", "{", "return", "'video'", ";", "}", "if", "(", "giga_match", "(", "'%(.mp3|.wma|.midi|.au)%'", ",", "$", "url", ")", ")", "{", "return", "'audio'", ";", "}", "return", "null", ";", "}" ]
Guess media type from URL return mixed
[ "Guess", "media", "type", "from", "URL" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Message/Attachment.php#L70-L91
226,582
gigaai/framework
src/Message/Attachment.php
Attachment.expectedIs
public function expectedIs($type) { // If people set type = message type, return true if (is_array($this->body) && isset($this->body['attachment']) && isset($this->body['attachment']['type'])) { return true; } if (is_string($this->body)) { $fileExtension = $this->detectMediaType($this->body); return $fileExtension === $type; } // If it's string, maybe it's URL. Check the extension if (isset($this->body['attachment']) && is_string($this->body['attachment']['payload']['url'])) { $fileExtension = $this->detectMediaType($this->body['attachment']['payload']['url']); return $fileExtension === $type; } return false; }
php
public function expectedIs($type) { // If people set type = message type, return true if (is_array($this->body) && isset($this->body['attachment']) && isset($this->body['attachment']['type'])) { return true; } if (is_string($this->body)) { $fileExtension = $this->detectMediaType($this->body); return $fileExtension === $type; } // If it's string, maybe it's URL. Check the extension if (isset($this->body['attachment']) && is_string($this->body['attachment']['payload']['url'])) { $fileExtension = $this->detectMediaType($this->body['attachment']['payload']['url']); return $fileExtension === $type; } return false; }
[ "public", "function", "expectedIs", "(", "$", "type", ")", "{", "// If people set type = message type, return true", "if", "(", "is_array", "(", "$", "this", "->", "body", ")", "&&", "isset", "(", "$", "this", "->", "body", "[", "'attachment'", "]", ")", "&&", "isset", "(", "$", "this", "->", "body", "[", "'attachment'", "]", "[", "'type'", "]", ")", ")", "{", "return", "true", ";", "}", "if", "(", "is_string", "(", "$", "this", "->", "body", ")", ")", "{", "$", "fileExtension", "=", "$", "this", "->", "detectMediaType", "(", "$", "this", "->", "body", ")", ";", "return", "$", "fileExtension", "===", "$", "type", ";", "}", "// If it's string, maybe it's URL. Check the extension", "if", "(", "isset", "(", "$", "this", "->", "body", "[", "'attachment'", "]", ")", "&&", "is_string", "(", "$", "this", "->", "body", "[", "'attachment'", "]", "[", "'payload'", "]", "[", "'url'", "]", ")", ")", "{", "$", "fileExtension", "=", "$", "this", "->", "detectMediaType", "(", "$", "this", "->", "body", "[", "'attachment'", "]", "[", "'payload'", "]", "[", "'url'", "]", ")", ";", "return", "$", "fileExtension", "===", "$", "type", ";", "}", "return", "false", ";", "}" ]
Check current message format @return bool
[ "Check", "current", "message", "format" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Message/Attachment.php#L98-L117
226,583
gigaai/framework
src/Message/Attachment.php
Attachment.getMediaUrl
public function getMediaUrl($mediaType) { $url = $this->body; if (is_array($this->body) && isset($this->body['attachment']['payload']['url']) && is_string($this->body['attachment']['payload']['url'])) { $url = $this->body['attachment']['payload']['url']; } $url = str_replace($mediaType . ':', '', $url); return $url; }
php
public function getMediaUrl($mediaType) { $url = $this->body; if (is_array($this->body) && isset($this->body['attachment']['payload']['url']) && is_string($this->body['attachment']['payload']['url'])) { $url = $this->body['attachment']['payload']['url']; } $url = str_replace($mediaType . ':', '', $url); return $url; }
[ "public", "function", "getMediaUrl", "(", "$", "mediaType", ")", "{", "$", "url", "=", "$", "this", "->", "body", ";", "if", "(", "is_array", "(", "$", "this", "->", "body", ")", "&&", "isset", "(", "$", "this", "->", "body", "[", "'attachment'", "]", "[", "'payload'", "]", "[", "'url'", "]", ")", "&&", "is_string", "(", "$", "this", "->", "body", "[", "'attachment'", "]", "[", "'payload'", "]", "[", "'url'", "]", ")", ")", "{", "$", "url", "=", "$", "this", "->", "body", "[", "'attachment'", "]", "[", "'payload'", "]", "[", "'url'", "]", ";", "}", "$", "url", "=", "str_replace", "(", "$", "mediaType", ".", "':'", ",", "''", ",", "$", "url", ")", ";", "return", "$", "url", ";", "}" ]
Get media URL @return String
[ "Get", "media", "URL" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Message/Attachment.php#L124-L135
226,584
CedrickOka/oka-pagination
src/Service/PaginationManager.php
PaginationManager.getManagerConfig
public function getManagerConfig($name) { if ($this->managerBag->has($name)) { $config = $this->managerBag->get($name); if (null === $config['template']) { $config['template'] = $this->defaultManagerConfig['template']; } } elseif (class_exists($name)) { $config = $this->defaultManagerConfig; $config['class'] = $name; } else { throw new \InvalidArgumentException(sprintf('The "%s" configuration key is not attached to a pagination manager.', $name)); } return $config; }
php
public function getManagerConfig($name) { if ($this->managerBag->has($name)) { $config = $this->managerBag->get($name); if (null === $config['template']) { $config['template'] = $this->defaultManagerConfig['template']; } } elseif (class_exists($name)) { $config = $this->defaultManagerConfig; $config['class'] = $name; } else { throw new \InvalidArgumentException(sprintf('The "%s" configuration key is not attached to a pagination manager.', $name)); } return $config; }
[ "public", "function", "getManagerConfig", "(", "$", "name", ")", "{", "if", "(", "$", "this", "->", "managerBag", "->", "has", "(", "$", "name", ")", ")", "{", "$", "config", "=", "$", "this", "->", "managerBag", "->", "get", "(", "$", "name", ")", ";", "if", "(", "null", "===", "$", "config", "[", "'template'", "]", ")", "{", "$", "config", "[", "'template'", "]", "=", "$", "this", "->", "defaultManagerConfig", "[", "'template'", "]", ";", "}", "}", "elseif", "(", "class_exists", "(", "$", "name", ")", ")", "{", "$", "config", "=", "$", "this", "->", "defaultManagerConfig", ";", "$", "config", "[", "'class'", "]", "=", "$", "name", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'The \"%s\" configuration key is not attached to a pagination manager.'", ",", "$", "name", ")", ")", ";", "}", "return", "$", "config", ";", "}" ]
Get pagination manager config @param string $name The pagination manager name @throws \InvalidArgumentException @return array
[ "Get", "pagination", "manager", "config" ]
d31dcdda62a60cc5e679993c90f02c61e8131c92
https://github.com/CedrickOka/oka-pagination/blob/d31dcdda62a60cc5e679993c90f02c61e8131c92/src/Service/PaginationManager.php#L74-L90
226,585
varspool/sphpdox
lib/Sphpdox/Element/Element.php
Element.indent
protected function indent($output, $spaces = 3, $rewrap = false) { if (!$output) { return ''; } $line = 78; $spaces = str_pad(' ', $spaces); if ($rewrap) { $existing_indent = ''; if (preg_match('/^( +)/', $output, $matches)) { $spaces .= $matches[1]; } $output = preg_replace('/^ +/m', '', $output); $output = wordwrap($output, $line - strlen($spaces)); } $output = preg_replace('/^/m', $spaces, $output); return $output; }
php
protected function indent($output, $spaces = 3, $rewrap = false) { if (!$output) { return ''; } $line = 78; $spaces = str_pad(' ', $spaces); if ($rewrap) { $existing_indent = ''; if (preg_match('/^( +)/', $output, $matches)) { $spaces .= $matches[1]; } $output = preg_replace('/^ +/m', '', $output); $output = wordwrap($output, $line - strlen($spaces)); } $output = preg_replace('/^/m', $spaces, $output); return $output; }
[ "protected", "function", "indent", "(", "$", "output", ",", "$", "spaces", "=", "3", ",", "$", "rewrap", "=", "false", ")", "{", "if", "(", "!", "$", "output", ")", "{", "return", "''", ";", "}", "$", "line", "=", "78", ";", "$", "spaces", "=", "str_pad", "(", "' '", ",", "$", "spaces", ")", ";", "if", "(", "$", "rewrap", ")", "{", "$", "existing_indent", "=", "''", ";", "if", "(", "preg_match", "(", "'/^( +)/'", ",", "$", "output", ",", "$", "matches", ")", ")", "{", "$", "spaces", ".=", "$", "matches", "[", "1", "]", ";", "}", "$", "output", "=", "preg_replace", "(", "'/^ +/m'", ",", "''", ",", "$", "output", ")", ";", "$", "output", "=", "wordwrap", "(", "$", "output", ",", "$", "line", "-", "strlen", "(", "$", "spaces", ")", ")", ";", "}", "$", "output", "=", "preg_replace", "(", "'/^/m'", ",", "$", "spaces", ",", "$", "output", ")", ";", "return", "$", "output", ";", "}" ]
Indents the given lines @param string $output @param int $level
[ "Indents", "the", "given", "lines" ]
7867503e1fc0acc47b4512fbd89bf742e03f79ba
https://github.com/varspool/sphpdox/blob/7867503e1fc0acc47b4512fbd89bf742e03f79ba/lib/Sphpdox/Element/Element.php#L44-L65
226,586
gigaai/framework
src/Http/Request.php
Request.load
private function load($simulate = []) { // Get the received data from request $stream = json_decode(file_get_contents('php://input'), true); self::$received = (!empty($stream)) ? $stream : $_REQUEST; if (!empty($simulate)) { self::$received = $simulate; } Conversation::set('request_raw', self::$received); // Load driver to parse request $this->driver = Driver::getInstance(); $this->driver->run(self::$received); Logger::put($stream, 'incoming'); self::$token = Config::get('access_token', self::$token); $this->subscribe(); }
php
private function load($simulate = []) { // Get the received data from request $stream = json_decode(file_get_contents('php://input'), true); self::$received = (!empty($stream)) ? $stream : $_REQUEST; if (!empty($simulate)) { self::$received = $simulate; } Conversation::set('request_raw', self::$received); // Load driver to parse request $this->driver = Driver::getInstance(); $this->driver->run(self::$received); Logger::put($stream, 'incoming'); self::$token = Config::get('access_token', self::$token); $this->subscribe(); }
[ "private", "function", "load", "(", "$", "simulate", "=", "[", "]", ")", "{", "// Get the received data from request", "$", "stream", "=", "json_decode", "(", "file_get_contents", "(", "'php://input'", ")", ",", "true", ")", ";", "self", "::", "$", "received", "=", "(", "!", "empty", "(", "$", "stream", ")", ")", "?", "$", "stream", ":", "$", "_REQUEST", ";", "if", "(", "!", "empty", "(", "$", "simulate", ")", ")", "{", "self", "::", "$", "received", "=", "$", "simulate", ";", "}", "Conversation", "::", "set", "(", "'request_raw'", ",", "self", "::", "$", "received", ")", ";", "// Load driver to parse request", "$", "this", "->", "driver", "=", "Driver", "::", "getInstance", "(", ")", ";", "$", "this", "->", "driver", "->", "run", "(", "self", "::", "$", "received", ")", ";", "Logger", "::", "put", "(", "$", "stream", ",", "'incoming'", ")", ";", "self", "::", "$", "token", "=", "Config", "::", "get", "(", "'access_token'", ",", "self", "::", "$", "token", ")", ";", "$", "this", "->", "subscribe", "(", ")", ";", "}" ]
Setup data and run command based on received data
[ "Setup", "data", "and", "run", "command", "based", "on", "received", "data" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Http/Request.php#L45-L66
226,587
gigaai/framework
src/Http/Request.php
Request.getReceivedData
private function getReceivedData($key = null) { $received = self::$received; if ($key !== null) { if (is_array($received) && isset($received[$key])) { return $received[$key]; } if (isset($received->$key)) { return $received->$key; } return null; } return is_object($received) ? (array)$received : $received; }
php
private function getReceivedData($key = null) { $received = self::$received; if ($key !== null) { if (is_array($received) && isset($received[$key])) { return $received[$key]; } if (isset($received->$key)) { return $received->$key; } return null; } return is_object($received) ? (array)$received : $received; }
[ "private", "function", "getReceivedData", "(", "$", "key", "=", "null", ")", "{", "$", "received", "=", "self", "::", "$", "received", ";", "if", "(", "$", "key", "!==", "null", ")", "{", "if", "(", "is_array", "(", "$", "received", ")", "&&", "isset", "(", "$", "received", "[", "$", "key", "]", ")", ")", "{", "return", "$", "received", "[", "$", "key", "]", ";", "}", "if", "(", "isset", "(", "$", "received", "->", "$", "key", ")", ")", "{", "return", "$", "received", "->", "$", "key", ";", "}", "return", "null", ";", "}", "return", "is_object", "(", "$", "received", ")", "?", "(", "array", ")", "$", "received", ":", "$", "received", ";", "}" ]
Get received request @param null $key @return mixed
[ "Get", "received", "request" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Http/Request.php#L75-L92
226,588
gigaai/framework
src/Http/Request.php
Request.sendMessages
private function sendMessages($messages, $attributes = [], $lead = null) { $accessToken = Config::get('access_token'); if ($accessToken === null && $lead !== null) { $instance = $lead->instance()->first(); if ($instance !== null) { Config::set($instance->meta); } } $batch = []; foreach ($messages as $message) { $message = $this->prepareMessage($message, $attributes, $lead); if ( ! empty($message)) { $batch[] = $message; } } $batch = array_values(array_filter($batch)); $this->driver->sendMessages($batch); }
php
private function sendMessages($messages, $attributes = [], $lead = null) { $accessToken = Config::get('access_token'); if ($accessToken === null && $lead !== null) { $instance = $lead->instance()->first(); if ($instance !== null) { Config::set($instance->meta); } } $batch = []; foreach ($messages as $message) { $message = $this->prepareMessage($message, $attributes, $lead); if ( ! empty($message)) { $batch[] = $message; } } $batch = array_values(array_filter($batch)); $this->driver->sendMessages($batch); }
[ "private", "function", "sendMessages", "(", "$", "messages", ",", "$", "attributes", "=", "[", "]", ",", "$", "lead", "=", "null", ")", "{", "$", "accessToken", "=", "Config", "::", "get", "(", "'access_token'", ")", ";", "if", "(", "$", "accessToken", "===", "null", "&&", "$", "lead", "!==", "null", ")", "{", "$", "instance", "=", "$", "lead", "->", "instance", "(", ")", "->", "first", "(", ")", ";", "if", "(", "$", "instance", "!==", "null", ")", "{", "Config", "::", "set", "(", "$", "instance", "->", "meta", ")", ";", "}", "}", "$", "batch", "=", "[", "]", ";", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "$", "message", "=", "$", "this", "->", "prepareMessage", "(", "$", "message", ",", "$", "attributes", ",", "$", "lead", ")", ";", "if", "(", "!", "empty", "(", "$", "message", ")", ")", "{", "$", "batch", "[", "]", "=", "$", "message", ";", "}", "}", "$", "batch", "=", "array_values", "(", "array_filter", "(", "$", "batch", ")", ")", ";", "$", "this", "->", "driver", "->", "sendMessages", "(", "$", "batch", ")", ";", "}" ]
Send multiple messages @param $messages @param mixed $lead
[ "Send", "multiple", "messages" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Http/Request.php#L240-L265
226,589
gigaai/framework
src/Http/Request.php
Request.getTypeAndPattern
private function getTypeAndPattern($event) { $type = 'text'; $pattern = ''; // For Text Message if (isset($event['message']) && isset($event['message']['text'])) { $pattern = $event['message']['text']; } // For Attachment Message if (isset($event['message']) && isset($event['message']['attachments'])) { $type = 'attachment'; if (isset($event['message']['attachments'][0]['type'])) { $pattern = $event['message']['attachments'][0]['type']; } } // For Payload Message if (isset($event['postback']['payload'])) { $type = 'payload'; $pattern = $event['postback']['payload']; } // For Quick Replies if (isset($event['message']) && isset($event['message']['quick_reply']) && !empty($event['message']['quick_reply']['payload'])) { $type = 'payload'; $pattern = $event['message']['quick_reply']['payload']; } return compact('type', 'pattern'); }
php
private function getTypeAndPattern($event) { $type = 'text'; $pattern = ''; // For Text Message if (isset($event['message']) && isset($event['message']['text'])) { $pattern = $event['message']['text']; } // For Attachment Message if (isset($event['message']) && isset($event['message']['attachments'])) { $type = 'attachment'; if (isset($event['message']['attachments'][0]['type'])) { $pattern = $event['message']['attachments'][0]['type']; } } // For Payload Message if (isset($event['postback']['payload'])) { $type = 'payload'; $pattern = $event['postback']['payload']; } // For Quick Replies if (isset($event['message']) && isset($event['message']['quick_reply']) && !empty($event['message']['quick_reply']['payload'])) { $type = 'payload'; $pattern = $event['message']['quick_reply']['payload']; } return compact('type', 'pattern'); }
[ "private", "function", "getTypeAndPattern", "(", "$", "event", ")", "{", "$", "type", "=", "'text'", ";", "$", "pattern", "=", "''", ";", "// For Text Message", "if", "(", "isset", "(", "$", "event", "[", "'message'", "]", ")", "&&", "isset", "(", "$", "event", "[", "'message'", "]", "[", "'text'", "]", ")", ")", "{", "$", "pattern", "=", "$", "event", "[", "'message'", "]", "[", "'text'", "]", ";", "}", "// For Attachment Message", "if", "(", "isset", "(", "$", "event", "[", "'message'", "]", ")", "&&", "isset", "(", "$", "event", "[", "'message'", "]", "[", "'attachments'", "]", ")", ")", "{", "$", "type", "=", "'attachment'", ";", "if", "(", "isset", "(", "$", "event", "[", "'message'", "]", "[", "'attachments'", "]", "[", "0", "]", "[", "'type'", "]", ")", ")", "{", "$", "pattern", "=", "$", "event", "[", "'message'", "]", "[", "'attachments'", "]", "[", "0", "]", "[", "'type'", "]", ";", "}", "}", "// For Payload Message", "if", "(", "isset", "(", "$", "event", "[", "'postback'", "]", "[", "'payload'", "]", ")", ")", "{", "$", "type", "=", "'payload'", ";", "$", "pattern", "=", "$", "event", "[", "'postback'", "]", "[", "'payload'", "]", ";", "}", "// For Quick Replies", "if", "(", "isset", "(", "$", "event", "[", "'message'", "]", ")", "&&", "isset", "(", "$", "event", "[", "'message'", "]", "[", "'quick_reply'", "]", ")", "&&", "!", "empty", "(", "$", "event", "[", "'message'", "]", "[", "'quick_reply'", "]", "[", "'payload'", "]", ")", ")", "{", "$", "type", "=", "'payload'", ";", "$", "pattern", "=", "$", "event", "[", "'message'", "]", "[", "'quick_reply'", "]", "[", "'payload'", "]", ";", "}", "return", "compact", "(", "'type'", ",", "'pattern'", ")", ";", "}" ]
Get Message Type and Pattern of an Event @param $event @return array
[ "Get", "Message", "Type", "and", "Pattern", "of", "an", "Event" ]
57380d93baf57bfdb8067e96c68ba72e4e993d96
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Http/Request.php#L274-L307
226,590
kevinkhill/FontAwesomePHP
src/FontAwesomeText.php
FontAwesomeText.output
protected function output() { $attrs = ''; $classes = 'fa-layers-text'; $transforms = ''; if (!empty($this->classes) && count($this->classes) > 0) { $classes .= ' ' . implode(' ', $this->classes); } if (!empty($this->attributes) && count($this->attributes) > 0) { foreach ($this->attributes as $attr => $val) { $attrs .= ' ' . $attr . '="' . $val . '"'; } } if (!empty($this->transforms) && count($this->transforms) > 0) { $transformList = array(); foreach ($this->transforms as $transform) { $transformList[] = implode('-', $transform); } $transforms = ' data-fa-transform="' . implode(' ', $transformList) . '"'; } return sprintf(self::TEXT_HTML, $classes, $attrs, $transforms, $this->text); }
php
protected function output() { $attrs = ''; $classes = 'fa-layers-text'; $transforms = ''; if (!empty($this->classes) && count($this->classes) > 0) { $classes .= ' ' . implode(' ', $this->classes); } if (!empty($this->attributes) && count($this->attributes) > 0) { foreach ($this->attributes as $attr => $val) { $attrs .= ' ' . $attr . '="' . $val . '"'; } } if (!empty($this->transforms) && count($this->transforms) > 0) { $transformList = array(); foreach ($this->transforms as $transform) { $transformList[] = implode('-', $transform); } $transforms = ' data-fa-transform="' . implode(' ', $transformList) . '"'; } return sprintf(self::TEXT_HTML, $classes, $attrs, $transforms, $this->text); }
[ "protected", "function", "output", "(", ")", "{", "$", "attrs", "=", "''", ";", "$", "classes", "=", "'fa-layers-text'", ";", "$", "transforms", "=", "''", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "classes", ")", "&&", "count", "(", "$", "this", "->", "classes", ")", ">", "0", ")", "{", "$", "classes", ".=", "' '", ".", "implode", "(", "' '", ",", "$", "this", "->", "classes", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "attributes", ")", "&&", "count", "(", "$", "this", "->", "attributes", ")", ">", "0", ")", "{", "foreach", "(", "$", "this", "->", "attributes", "as", "$", "attr", "=>", "$", "val", ")", "{", "$", "attrs", ".=", "' '", ".", "$", "attr", ".", "'=\"'", ".", "$", "val", ".", "'\"'", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "transforms", ")", "&&", "count", "(", "$", "this", "->", "transforms", ")", ">", "0", ")", "{", "$", "transformList", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "transforms", "as", "$", "transform", ")", "{", "$", "transformList", "[", "]", "=", "implode", "(", "'-'", ",", "$", "transform", ")", ";", "}", "$", "transforms", "=", "' data-fa-transform=\"'", ".", "implode", "(", "' '", ",", "$", "transformList", ")", ".", "'\"'", ";", "}", "return", "sprintf", "(", "self", "::", "TEXT_HTML", ",", "$", "classes", ",", "$", "attrs", ",", "$", "transforms", ",", "$", "this", "->", "text", ")", ";", "}" ]
Outputs the FontAwesomeText object as an HTML string @access protected @return string HTML string of text element
[ "Outputs", "the", "FontAwesomeText", "object", "as", "an", "HTML", "string" ]
e7d12d7422b23a5c3a09715d9ca3e24ff811c073
https://github.com/kevinkhill/FontAwesomePHP/blob/e7d12d7422b23a5c3a09715d9ca3e24ff811c073/src/FontAwesomeText.php#L45-L70
226,591
cviebrock/eloquent-typecast
src/EloquentTypecastTrait.php
EloquentTypecastTrait.bootEloquentTypecastTrait
protected static function bootEloquentTypecastTrait() { $class = get_called_class(); $instance = new $class(); foreach($instance->getCastAttributes() as $attribute=>$type) { static::$mutatorCache[$class][] = $attribute; } }
php
protected static function bootEloquentTypecastTrait() { $class = get_called_class(); $instance = new $class(); foreach($instance->getCastAttributes() as $attribute=>$type) { static::$mutatorCache[$class][] = $attribute; } }
[ "protected", "static", "function", "bootEloquentTypecastTrait", "(", ")", "{", "$", "class", "=", "get_called_class", "(", ")", ";", "$", "instance", "=", "new", "$", "class", "(", ")", ";", "foreach", "(", "$", "instance", "->", "getCastAttributes", "(", ")", "as", "$", "attribute", "=>", "$", "type", ")", "{", "static", "::", "$", "mutatorCache", "[", "$", "class", "]", "[", "]", "=", "$", "attribute", ";", "}", "}" ]
Boot the typecasting trait for a model, which will add all our typecast-able attributes to the mutator cache. This way, they get mutated without us needing to write a mutator function for each one. @return void
[ "Boot", "the", "typecasting", "trait", "for", "a", "model", "which", "will", "add", "all", "our", "typecast", "-", "able", "attributes", "to", "the", "mutator", "cache", ".", "This", "way", "they", "get", "mutated", "without", "us", "needing", "to", "write", "a", "mutator", "function", "for", "each", "one", "." ]
de74d085cd3fbedfaf0bb974041cd60faceb9126
https://github.com/cviebrock/eloquent-typecast/blob/de74d085cd3fbedfaf0bb974041cd60faceb9126/src/EloquentTypecastTrait.php#L23-L33
226,592
cviebrock/eloquent-typecast
src/EloquentTypecastTrait.php
EloquentTypecastTrait.mutateAttribute
protected function mutateAttribute($key, $value) { if ($this->isCastableAttribute($key)) { return $this->castAttribute($key, $value); } return parent::mutateAttribute($key, $value); }
php
protected function mutateAttribute($key, $value) { if ($this->isCastableAttribute($key)) { return $this->castAttribute($key, $value); } return parent::mutateAttribute($key, $value); }
[ "protected", "function", "mutateAttribute", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "$", "this", "->", "isCastableAttribute", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "castAttribute", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "parent", "::", "mutateAttribute", "(", "$", "key", ",", "$", "value", ")", ";", "}" ]
Get the value of an attribute using its mutator. If the attribute is typecast-able, then return the cast value instead. @param string $key @param mixed $value @return mixed @see Illuminate\Database\Eloquent\Model::mutateAttribute()
[ "Get", "the", "value", "of", "an", "attribute", "using", "its", "mutator", ".", "If", "the", "attribute", "is", "typecast", "-", "able", "then", "return", "the", "cast", "value", "instead", "." ]
de74d085cd3fbedfaf0bb974041cd60faceb9126
https://github.com/cviebrock/eloquent-typecast/blob/de74d085cd3fbedfaf0bb974041cd60faceb9126/src/EloquentTypecastTrait.php#L45-L53
226,593
cviebrock/eloquent-typecast
src/EloquentTypecastTrait.php
EloquentTypecastTrait.setAttribute
public function setAttribute($key, $value) { if ($this->castOnSet() && $this->isCastableAttribute($key)) { $value = $this->castAttribute($key, $value); } return parent::setAttribute($key, $value); }
php
public function setAttribute($key, $value) { if ($this->castOnSet() && $this->isCastableAttribute($key)) { $value = $this->castAttribute($key, $value); } return parent::setAttribute($key, $value); }
[ "public", "function", "setAttribute", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "$", "this", "->", "castOnSet", "(", ")", "&&", "$", "this", "->", "isCastableAttribute", "(", "$", "key", ")", ")", "{", "$", "value", "=", "$", "this", "->", "castAttribute", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "parent", "::", "setAttribute", "(", "$", "key", ",", "$", "value", ")", ";", "}" ]
Set a given attribute on the model. If the attribute is typecast-able, then cast the value before setting it. @param string $key @param mixed $value @return void @see Illuminate\Database\Eloquent\Model::setAttribute()
[ "Set", "a", "given", "attribute", "on", "the", "model", ".", "If", "the", "attribute", "is", "typecast", "-", "able", "then", "cast", "the", "value", "before", "setting", "it", "." ]
de74d085cd3fbedfaf0bb974041cd60faceb9126
https://github.com/cviebrock/eloquent-typecast/blob/de74d085cd3fbedfaf0bb974041cd60faceb9126/src/EloquentTypecastTrait.php#L65-L72
226,594
cviebrock/eloquent-typecast
src/EloquentTypecastTrait.php
EloquentTypecastTrait.getAttributeValue
protected function getAttributeValue($key) { $value = parent::getAttributeValue($key); if ($this->isCastableAttribute($key)) { $value = $this->castAttribute($key, $value); } return $value; }
php
protected function getAttributeValue($key) { $value = parent::getAttributeValue($key); if ($this->isCastableAttribute($key)) { $value = $this->castAttribute($key, $value); } return $value; }
[ "protected", "function", "getAttributeValue", "(", "$", "key", ")", "{", "$", "value", "=", "parent", "::", "getAttributeValue", "(", "$", "key", ")", ";", "if", "(", "$", "this", "->", "isCastableAttribute", "(", "$", "key", ")", ")", "{", "$", "value", "=", "$", "this", "->", "castAttribute", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Get a given attribute on the model. If the attribute is typecast-able, then cast the value before getting it. @param string $key @return mixed
[ "Get", "a", "given", "attribute", "on", "the", "model", ".", "If", "the", "attribute", "is", "typecast", "-", "able", "then", "cast", "the", "value", "before", "getting", "it", "." ]
de74d085cd3fbedfaf0bb974041cd60faceb9126
https://github.com/cviebrock/eloquent-typecast/blob/de74d085cd3fbedfaf0bb974041cd60faceb9126/src/EloquentTypecastTrait.php#L81-L91
226,595
cviebrock/eloquent-typecast
src/EloquentTypecastTrait.php
EloquentTypecastTrait.castAttribute
protected function castAttribute($key, $value) { $type = $this->cast[$key]; try { if ( is_null($value) ) { return null; } if ( settype($value, $type) ) { return $value; } throw new EloquentTypecastException("Value could not be cast to type \"$type\"", 1); } catch (\Exception $e) { throw new EloquentTypecastException("Value could not be cast to type \"$type\"", 1); } }
php
protected function castAttribute($key, $value) { $type = $this->cast[$key]; try { if ( is_null($value) ) { return null; } if ( settype($value, $type) ) { return $value; } throw new EloquentTypecastException("Value could not be cast to type \"$type\"", 1); } catch (\Exception $e) { throw new EloquentTypecastException("Value could not be cast to type \"$type\"", 1); } }
[ "protected", "function", "castAttribute", "(", "$", "key", ",", "$", "value", ")", "{", "$", "type", "=", "$", "this", "->", "cast", "[", "$", "key", "]", ";", "try", "{", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "return", "null", ";", "}", "if", "(", "settype", "(", "$", "value", ",", "$", "type", ")", ")", "{", "return", "$", "value", ";", "}", "throw", "new", "EloquentTypecastException", "(", "\"Value could not be cast to type \\\"$type\\\"\"", ",", "1", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "EloquentTypecastException", "(", "\"Value could not be cast to type \\\"$type\\\"\"", ",", "1", ")", ";", "}", "}" ]
Cast an attribute to a PHP variable type. @param string $key @param mixed $value @throws EloquentTypecastException @return mixed
[ "Cast", "an", "attribute", "to", "a", "PHP", "variable", "type", "." ]
de74d085cd3fbedfaf0bb974041cd60faceb9126
https://github.com/cviebrock/eloquent-typecast/blob/de74d085cd3fbedfaf0bb974041cd60faceb9126/src/EloquentTypecastTrait.php#L134-L150
226,596
pug-php/js-phpize
src/JsPhpize/JsPhpizeOptions.php
JsPhpizeOptions.removePatterns
public function removePatterns($removeFunction) { $this->clearPatternsCache(); $this->options['patterns'] = array_filter($this->options['patterns'], $removeFunction); return $this; }
php
public function removePatterns($removeFunction) { $this->clearPatternsCache(); $this->options['patterns'] = array_filter($this->options['patterns'], $removeFunction); return $this; }
[ "public", "function", "removePatterns", "(", "$", "removeFunction", ")", "{", "$", "this", "->", "clearPatternsCache", "(", ")", ";", "$", "this", "->", "options", "[", "'patterns'", "]", "=", "array_filter", "(", "$", "this", "->", "options", "[", "'patterns'", "]", ",", "$", "removeFunction", ")", ";", "return", "$", "this", ";", "}" ]
Remove patterns using a filter function. @param callable $removeFunction @return $this
[ "Remove", "patterns", "using", "a", "filter", "function", "." ]
c41102da1be243ba9439b90af8b7032016585537
https://github.com/pug-php/js-phpize/blob/c41102da1be243ba9439b90af8b7032016585537/src/JsPhpize/JsPhpizeOptions.php#L97-L104
226,597
pug-php/js-phpize
src/JsPhpize/JsPhpizeOptions.php
JsPhpizeOptions.getPatterns
public function getPatterns() { if (!$this->patternsCache) { $this->patternsCache = $this->getOption('patterns'); usort($this->patternsCache, function (Pattern $first, Pattern $second) { return $first->priority - $second->priority; }); } return $this->patternsCache; }
php
public function getPatterns() { if (!$this->patternsCache) { $this->patternsCache = $this->getOption('patterns'); usort($this->patternsCache, function (Pattern $first, Pattern $second) { return $first->priority - $second->priority; }); } return $this->patternsCache; }
[ "public", "function", "getPatterns", "(", ")", "{", "if", "(", "!", "$", "this", "->", "patternsCache", ")", "{", "$", "this", "->", "patternsCache", "=", "$", "this", "->", "getOption", "(", "'patterns'", ")", ";", "usort", "(", "$", "this", "->", "patternsCache", ",", "function", "(", "Pattern", "$", "first", ",", "Pattern", "$", "second", ")", "{", "return", "$", "first", "->", "priority", "-", "$", "second", "->", "priority", ";", "}", ")", ";", "}", "return", "$", "this", "->", "patternsCache", ";", "}" ]
Return cached and ordered patterns list. @return array
[ "Return", "cached", "and", "ordered", "patterns", "list", "." ]
c41102da1be243ba9439b90af8b7032016585537
https://github.com/pug-php/js-phpize/blob/c41102da1be243ba9439b90af8b7032016585537/src/JsPhpize/JsPhpizeOptions.php#L111-L121
226,598
pug-php/js-phpize
src/JsPhpize/JsPhpizeOptions.php
JsPhpizeOptions.getHelperName
public function getHelperName($key) { $helpers = $this->getOption('helpers', []); return is_array($helpers) && isset($helpers[$key]) ? $helpers[$key] : $key; }
php
public function getHelperName($key) { $helpers = $this->getOption('helpers', []); return is_array($helpers) && isset($helpers[$key]) ? $helpers[$key] : $key; }
[ "public", "function", "getHelperName", "(", "$", "key", ")", "{", "$", "helpers", "=", "$", "this", "->", "getOption", "(", "'helpers'", ",", "[", "]", ")", ";", "return", "is_array", "(", "$", "helpers", ")", "&&", "isset", "(", "$", "helpers", "[", "$", "key", "]", ")", "?", "$", "helpers", "[", "$", "key", "]", ":", "$", "key", ";", "}" ]
Retrieve the prefix of specific variables. @return string
[ "Retrieve", "the", "prefix", "of", "specific", "variables", "." ]
c41102da1be243ba9439b90af8b7032016585537
https://github.com/pug-php/js-phpize/blob/c41102da1be243ba9439b90af8b7032016585537/src/JsPhpize/JsPhpizeOptions.php#L163-L170
226,599
CedrickOka/oka-pagination
src/Util/PaginationQuery.php
PaginationQuery.createCountQuery
protected function createCountQuery(array $fields = [], array $criteria = [], $distinct = true) { if ($this->objectManager instanceof \Doctrine\ORM\EntityManager) { /** @var \Doctrine\ORM\QueryBuilder $builder */ $builder = $this->objectManager->createQueryBuilder(); if (empty($fields)) { /** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata $classMetadata */ $classMetadata = $this->objectManager->getClassMetadata($this->className); $identifier = $classMetadata->getIdentifierFieldNames()[0]; } else { $identifier = $fields[0]; // Replace with $identifier = implode(', p.', $fields); } $builder->select($distinct ? $builder->expr()->countDistinct('p.' . $identifier) : $builder->expr()->count('p.' . $identifier)) ->from($this->className, 'p'); } elseif ($this->objectManager instanceof \Doctrine\ODM\MongoDB\DocumentManager) { /** @var \Doctrine\ODM\MongoDB\Query\Builder $builder */ $builder = $this->objectManager->createQueryBuilder($this->className); if (false === empty($fields) && true === $distinct) { $builder->distinct($fields[0]); } $builder->count(); } else { throw new ObjectManagerNotSupportedException(sprintf('Doctrine object manager class "%s" is not supported.', get_class($this->objectManager))); } $this->qbHandler->applyExprFromArray($builder, 'p', $criteria); return $builder->getQuery(); }
php
protected function createCountQuery(array $fields = [], array $criteria = [], $distinct = true) { if ($this->objectManager instanceof \Doctrine\ORM\EntityManager) { /** @var \Doctrine\ORM\QueryBuilder $builder */ $builder = $this->objectManager->createQueryBuilder(); if (empty($fields)) { /** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata $classMetadata */ $classMetadata = $this->objectManager->getClassMetadata($this->className); $identifier = $classMetadata->getIdentifierFieldNames()[0]; } else { $identifier = $fields[0]; // Replace with $identifier = implode(', p.', $fields); } $builder->select($distinct ? $builder->expr()->countDistinct('p.' . $identifier) : $builder->expr()->count('p.' . $identifier)) ->from($this->className, 'p'); } elseif ($this->objectManager instanceof \Doctrine\ODM\MongoDB\DocumentManager) { /** @var \Doctrine\ODM\MongoDB\Query\Builder $builder */ $builder = $this->objectManager->createQueryBuilder($this->className); if (false === empty($fields) && true === $distinct) { $builder->distinct($fields[0]); } $builder->count(); } else { throw new ObjectManagerNotSupportedException(sprintf('Doctrine object manager class "%s" is not supported.', get_class($this->objectManager))); } $this->qbHandler->applyExprFromArray($builder, 'p', $criteria); return $builder->getQuery(); }
[ "protected", "function", "createCountQuery", "(", "array", "$", "fields", "=", "[", "]", ",", "array", "$", "criteria", "=", "[", "]", ",", "$", "distinct", "=", "true", ")", "{", "if", "(", "$", "this", "->", "objectManager", "instanceof", "\\", "Doctrine", "\\", "ORM", "\\", "EntityManager", ")", "{", "/** @var \\Doctrine\\ORM\\QueryBuilder $builder */", "$", "builder", "=", "$", "this", "->", "objectManager", "->", "createQueryBuilder", "(", ")", ";", "if", "(", "empty", "(", "$", "fields", ")", ")", "{", "/** @var \\Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata $classMetadata */", "$", "classMetadata", "=", "$", "this", "->", "objectManager", "->", "getClassMetadata", "(", "$", "this", "->", "className", ")", ";", "$", "identifier", "=", "$", "classMetadata", "->", "getIdentifierFieldNames", "(", ")", "[", "0", "]", ";", "}", "else", "{", "$", "identifier", "=", "$", "fields", "[", "0", "]", ";", "// Replace with $identifier = implode(', p.', $fields);", "}", "$", "builder", "->", "select", "(", "$", "distinct", "?", "$", "builder", "->", "expr", "(", ")", "->", "countDistinct", "(", "'p.'", ".", "$", "identifier", ")", ":", "$", "builder", "->", "expr", "(", ")", "->", "count", "(", "'p.'", ".", "$", "identifier", ")", ")", "->", "from", "(", "$", "this", "->", "className", ",", "'p'", ")", ";", "}", "elseif", "(", "$", "this", "->", "objectManager", "instanceof", "\\", "Doctrine", "\\", "ODM", "\\", "MongoDB", "\\", "DocumentManager", ")", "{", "/** @var \\Doctrine\\ODM\\MongoDB\\Query\\Builder $builder */", "$", "builder", "=", "$", "this", "->", "objectManager", "->", "createQueryBuilder", "(", "$", "this", "->", "className", ")", ";", "if", "(", "false", "===", "empty", "(", "$", "fields", ")", "&&", "true", "===", "$", "distinct", ")", "{", "$", "builder", "->", "distinct", "(", "$", "fields", "[", "0", "]", ")", ";", "}", "$", "builder", "->", "count", "(", ")", ";", "}", "else", "{", "throw", "new", "ObjectManagerNotSupportedException", "(", "sprintf", "(", "'Doctrine object manager class \"%s\" is not supported.'", ",", "get_class", "(", "$", "this", "->", "objectManager", ")", ")", ")", ";", "}", "$", "this", "->", "qbHandler", "->", "applyExprFromArray", "(", "$", "builder", ",", "'p'", ",", "$", "criteria", ")", ";", "return", "$", "builder", "->", "getQuery", "(", ")", ";", "}" ]
Create internal count items query @param array $fields @param array $criteria @param bool $distinct @return \Doctrine\ORM\AbstractQuery|\Doctrine\ODM\MongoDB\Query\Query
[ "Create", "internal", "count", "items", "query" ]
d31dcdda62a60cc5e679993c90f02c61e8131c92
https://github.com/CedrickOka/oka-pagination/blob/d31dcdda62a60cc5e679993c90f02c61e8131c92/src/Util/PaginationQuery.php#L372-L404