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
25,900
craig-mcmahon/google-helper
src/GoogleHelper/Apps/EmailHelper.php
EmailHelper.setSendAsAlias
public function setSendAsAlias($domain, $user, $name, $address, $replyTo = null, $makeDefault = false) { $url = self::BASE_URL . "{$domain}/{$user}/sendas"; $request = <<<XML <?xml version="1.0" encoding="utf-8"?> <atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:apps="http://schemas.google.com/apps/2006"> <apps:property name="name" value="{$name}" /> <apps:property name="address" value="{$address}" /> XML; if ($replyTo !== null) { $request .= "<apps:property name=\"replyTo\" value=\"{$replyTo}\" />"; } if ($makeDefault) { $request .= "<apps:property name=\"makeDefault\" value=\"true\" />"; } $request .= "</atom:entry>"; $request = new \Google_Http_Request($url, 'POST', array('Content-Type' => 'application/atom+xml'), $request); $httpRequest = $this->helper->getClient() ->getAuth() ->authenticatedRequest($request); return ($httpRequest->getResponseHttpCode() == 201); }
php
public function setSendAsAlias($domain, $user, $name, $address, $replyTo = null, $makeDefault = false) { $url = self::BASE_URL . "{$domain}/{$user}/sendas"; $request = <<<XML <?xml version="1.0" encoding="utf-8"?> <atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:apps="http://schemas.google.com/apps/2006"> <apps:property name="name" value="{$name}" /> <apps:property name="address" value="{$address}" /> XML; if ($replyTo !== null) { $request .= "<apps:property name=\"replyTo\" value=\"{$replyTo}\" />"; } if ($makeDefault) { $request .= "<apps:property name=\"makeDefault\" value=\"true\" />"; } $request .= "</atom:entry>"; $request = new \Google_Http_Request($url, 'POST', array('Content-Type' => 'application/atom+xml'), $request); $httpRequest = $this->helper->getClient() ->getAuth() ->authenticatedRequest($request); return ($httpRequest->getResponseHttpCode() == 201); }
[ "public", "function", "setSendAsAlias", "(", "$", "domain", ",", "$", "user", ",", "$", "name", ",", "$", "address", ",", "$", "replyTo", "=", "null", ",", "$", "makeDefault", "=", "false", ")", "{", "$", "url", "=", "self", "::", "BASE_URL", ".", "\"{$domain}/{$user}/sendas\"", ";", "$", "request", "=", " <<<XML\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<atom:entry xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:apps=\"http://schemas.google.com/apps/2006\">\n <apps:property name=\"name\" value=\"{$name}\" />\n <apps:property name=\"address\" value=\"{$address}\" />\nXML", ";", "if", "(", "$", "replyTo", "!==", "null", ")", "{", "$", "request", ".=", "\"<apps:property name=\\\"replyTo\\\" value=\\\"{$replyTo}\\\" />\"", ";", "}", "if", "(", "$", "makeDefault", ")", "{", "$", "request", ".=", "\"<apps:property name=\\\"makeDefault\\\" value=\\\"true\\\" />\"", ";", "}", "$", "request", ".=", "\"</atom:entry>\"", ";", "$", "request", "=", "new", "\\", "Google_Http_Request", "(", "$", "url", ",", "'POST'", ",", "array", "(", "'Content-Type'", "=>", "'application/atom+xml'", ")", ",", "$", "request", ")", ";", "$", "httpRequest", "=", "$", "this", "->", "helper", "->", "getClient", "(", ")", "->", "getAuth", "(", ")", "->", "authenticatedRequest", "(", "$", "request", ")", ";", "return", "(", "$", "httpRequest", "->", "getResponseHttpCode", "(", ")", "==", "201", ")", ";", "}" ]
Add a Send-as Alias @param string $domain @param string $user @param string $name @param string $address @param string|null $replyTo @param bool $makeDefault @return bool Success
[ "Add", "a", "Send", "-", "as", "Alias" ]
6b877efd7c9827555ecac65ee01e337849db6611
https://github.com/craig-mcmahon/google-helper/blob/6b877efd7c9827555ecac65ee01e337849db6611/src/GoogleHelper/Apps/EmailHelper.php#L71-L95
25,901
shampeak/GraceServer
src/Cache/Cache.php
Cache.setAdapter
public function setAdapter(\Desarrolla2\Cache\Adapter\AdapterInterface $adapter) { return $this->_instance->setAdapter($adapter); }
php
public function setAdapter(\Desarrolla2\Cache\Adapter\AdapterInterface $adapter) { return $this->_instance->setAdapter($adapter); }
[ "public", "function", "setAdapter", "(", "\\", "Desarrolla2", "\\", "Cache", "\\", "Adapter", "\\", "AdapterInterface", "$", "adapter", ")", "{", "return", "$", "this", "->", "_instance", "->", "setAdapter", "(", "$", "adapter", ")", ";", "}" ]
Set Adapter interface @param \Desarrolla2\Cache\Adapter\AdapterInterface $adapter
[ "Set", "Adapter", "interface" ]
e69891de3daae7d228c803c06213eb248fc88594
https://github.com/shampeak/GraceServer/blob/e69891de3daae7d228c803c06213eb248fc88594/src/Cache/Cache.php#L84-L87
25,902
nochso/ORM2
src/DBA/DBA.php
DBA.getLog
public static function getLog($empty = false) { $log = self::$log; if ($empty) { self::emptyLog(); } return $log; }
php
public static function getLog($empty = false) { $log = self::$log; if ($empty) { self::emptyLog(); } return $log; }
[ "public", "static", "function", "getLog", "(", "$", "empty", "=", "false", ")", "{", "$", "log", "=", "self", "::", "$", "log", ";", "if", "(", "$", "empty", ")", "{", "self", "::", "emptyLog", "(", ")", ";", "}", "return", "$", "log", ";", "}" ]
Returns all log entries and optionally removes them @param bool $empty @return LogEntry[]
[ "Returns", "all", "log", "entries", "and", "optionally", "removes", "them" ]
89f9a5c61ad5f575fbdd52990171b52d54f8bfbc
https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/DBA/DBA.php#L116-L123
25,903
JumpGateio/Core
src/JumpGate/Core/Abstracts/Seeder.php
Seeder.truncate
protected function truncate($table) { if ($this->db->connection()->getConfig('driver') === 'mysql') { $this->db->statement('SET FOREIGN_KEY_CHECKS=0;'); $this->db->table($table)->truncate(); $this->db->statement('SET FOREIGN_KEY_CHECKS=1;'); } }
php
protected function truncate($table) { if ($this->db->connection()->getConfig('driver') === 'mysql') { $this->db->statement('SET FOREIGN_KEY_CHECKS=0;'); $this->db->table($table)->truncate(); $this->db->statement('SET FOREIGN_KEY_CHECKS=1;'); } }
[ "protected", "function", "truncate", "(", "$", "table", ")", "{", "if", "(", "$", "this", "->", "db", "->", "connection", "(", ")", "->", "getConfig", "(", "'driver'", ")", "===", "'mysql'", ")", "{", "$", "this", "->", "db", "->", "statement", "(", "'SET FOREIGN_KEY_CHECKS=0;'", ")", ";", "$", "this", "->", "db", "->", "table", "(", "$", "table", ")", "->", "truncate", "(", ")", ";", "$", "this", "->", "db", "->", "statement", "(", "'SET FOREIGN_KEY_CHECKS=1;'", ")", ";", "}", "}" ]
Truncate the existing table of all records. @param string $table
[ "Truncate", "the", "existing", "table", "of", "all", "records", "." ]
485b5cf03b3072267bffbee428b81e48d407d6b6
https://github.com/JumpGateio/Core/blob/485b5cf03b3072267bffbee428b81e48d407d6b6/src/JumpGate/Core/Abstracts/Seeder.php#L22-L29
25,904
praxigento/mobi_mod_downline
Ui/DataProvider/Grid/Transaction/Query.php
Query.getQueryItems
protected function getQueryItems() { /* this is primary query builder, not extender */ $result = parent::getQueryItems(); /* define tables aliases for internal usage (in this method) */ $asAccCred = self::AS_ACC_CREDIT; $asAccDeb = self::AS_ACC_DEBIT; $asDwnlCred = self::AS_DWNL_CRED; $asDwnlDeb = self::AS_DWNL_DEB; /* LEFT JOIN prxgt_dwnl_customer as debit */ $tbl = $this->resource->getTableName(self::E_DWNL_CUST); $as = $asDwnlDeb; $cols = [ self::A_MLM_ID_DEBIT => EDownline::A_MLM_ID ]; $cond = "$as." . EDownline::A_CUSTOMER_REF . '=' . $asAccDeb . '.' . EAccount::A_CUST_ID; $result->joinLeft([$as => $tbl], $cond, $cols); /* LEFT JOIN prxgt_dwnl_customer as credit */ $tbl = $this->resource->getTableName(self::E_DWNL_CUST); $as = $asDwnlCred; $cols = [ self::A_MLM_ID_CREDIT => EDownline::A_MLM_ID ]; $cond = "$as." . EDownline::A_CUSTOMER_REF . '=' . $asAccCred . '.' . EAccount::A_CUST_ID; $result->joinLeft([$as => $tbl], $cond, $cols); /* return result */ return $result; }
php
protected function getQueryItems() { /* this is primary query builder, not extender */ $result = parent::getQueryItems(); /* define tables aliases for internal usage (in this method) */ $asAccCred = self::AS_ACC_CREDIT; $asAccDeb = self::AS_ACC_DEBIT; $asDwnlCred = self::AS_DWNL_CRED; $asDwnlDeb = self::AS_DWNL_DEB; /* LEFT JOIN prxgt_dwnl_customer as debit */ $tbl = $this->resource->getTableName(self::E_DWNL_CUST); $as = $asDwnlDeb; $cols = [ self::A_MLM_ID_DEBIT => EDownline::A_MLM_ID ]; $cond = "$as." . EDownline::A_CUSTOMER_REF . '=' . $asAccDeb . '.' . EAccount::A_CUST_ID; $result->joinLeft([$as => $tbl], $cond, $cols); /* LEFT JOIN prxgt_dwnl_customer as credit */ $tbl = $this->resource->getTableName(self::E_DWNL_CUST); $as = $asDwnlCred; $cols = [ self::A_MLM_ID_CREDIT => EDownline::A_MLM_ID ]; $cond = "$as." . EDownline::A_CUSTOMER_REF . '=' . $asAccCred . '.' . EAccount::A_CUST_ID; $result->joinLeft([$as => $tbl], $cond, $cols); /* return result */ return $result; }
[ "protected", "function", "getQueryItems", "(", ")", "{", "/* this is primary query builder, not extender */", "$", "result", "=", "parent", "::", "getQueryItems", "(", ")", ";", "/* define tables aliases for internal usage (in this method) */", "$", "asAccCred", "=", "self", "::", "AS_ACC_CREDIT", ";", "$", "asAccDeb", "=", "self", "::", "AS_ACC_DEBIT", ";", "$", "asDwnlCred", "=", "self", "::", "AS_DWNL_CRED", ";", "$", "asDwnlDeb", "=", "self", "::", "AS_DWNL_DEB", ";", "/* LEFT JOIN prxgt_dwnl_customer as debit */", "$", "tbl", "=", "$", "this", "->", "resource", "->", "getTableName", "(", "self", "::", "E_DWNL_CUST", ")", ";", "$", "as", "=", "$", "asDwnlDeb", ";", "$", "cols", "=", "[", "self", "::", "A_MLM_ID_DEBIT", "=>", "EDownline", "::", "A_MLM_ID", "]", ";", "$", "cond", "=", "\"$as.\"", ".", "EDownline", "::", "A_CUSTOMER_REF", ".", "'='", ".", "$", "asAccDeb", ".", "'.'", ".", "EAccount", "::", "A_CUST_ID", ";", "$", "result", "->", "joinLeft", "(", "[", "$", "as", "=>", "$", "tbl", "]", ",", "$", "cond", ",", "$", "cols", ")", ";", "/* LEFT JOIN prxgt_dwnl_customer as credit */", "$", "tbl", "=", "$", "this", "->", "resource", "->", "getTableName", "(", "self", "::", "E_DWNL_CUST", ")", ";", "$", "as", "=", "$", "asDwnlCred", ";", "$", "cols", "=", "[", "self", "::", "A_MLM_ID_CREDIT", "=>", "EDownline", "::", "A_MLM_ID", "]", ";", "$", "cond", "=", "\"$as.\"", ".", "EDownline", "::", "A_CUSTOMER_REF", ".", "'='", ".", "$", "asAccCred", ".", "'.'", ".", "EAccount", "::", "A_CUST_ID", ";", "$", "result", "->", "joinLeft", "(", "[", "$", "as", "=>", "$", "tbl", "]", ",", "$", "cond", ",", "$", "cols", ")", ";", "/* return result */", "return", "$", "result", ";", "}" ]
SELECT ... FROM `prxgt_acc_transaction` AS `pat` LEFT JOIN `prxgt_acc_account` AS `paa_db` ON paa_db.id = pat.debit_acc_id LEFT JOIN `customer_entity` AS `ce_db` ON ce_db.entity_id = paa_db.customer_id LEFT JOIN `prxgt_acc_account` AS `paa_cr` ON paa_cr.id = pat.credit_acc_id LEFT JOIN `customer_entity` AS `ce_cr` ON ce_cr.entity_id = paa_cr.customer_id LEFT JOIN `prxgt_acc_type_asset` AS `pata` ON pata.id = paa_db.asset_type_id LEFT JOIN `prxgt_dwnl_customer` AS `dwnlDebit` ON dwnlDebit.customer_ref = paa_db.customer_id LEFT JOIN `prxgt_dwnl_customer` AS `dwnlCredit` ON dwnlCredit.customer_ref = paa_cr.customer_id
[ "SELECT", "...", "FROM", "prxgt_acc_transaction", "AS", "pat", "LEFT", "JOIN", "prxgt_acc_account", "AS", "paa_db", "ON", "paa_db", ".", "id", "=", "pat", ".", "debit_acc_id", "LEFT", "JOIN", "customer_entity", "AS", "ce_db", "ON", "ce_db", ".", "entity_id", "=", "paa_db", ".", "customer_id", "LEFT", "JOIN", "prxgt_acc_account", "AS", "paa_cr", "ON", "paa_cr", ".", "id", "=", "pat", ".", "credit_acc_id", "LEFT", "JOIN", "customer_entity", "AS", "ce_cr", "ON", "ce_cr", ".", "entity_id", "=", "paa_cr", ".", "customer_id", "LEFT", "JOIN", "prxgt_acc_type_asset", "AS", "pata", "ON", "pata", ".", "id", "=", "paa_db", ".", "asset_type_id", "LEFT", "JOIN", "prxgt_dwnl_customer", "AS", "dwnlDebit", "ON", "dwnlDebit", ".", "customer_ref", "=", "paa_db", ".", "customer_id", "LEFT", "JOIN", "prxgt_dwnl_customer", "AS", "dwnlCredit", "ON", "dwnlCredit", ".", "customer_ref", "=", "paa_cr", ".", "customer_id" ]
0f3c276dfff1aa029f9fd205ccfc56f207a2e75b
https://github.com/praxigento/mobi_mod_downline/blob/0f3c276dfff1aa029f9fd205ccfc56f207a2e75b/Ui/DataProvider/Grid/Transaction/Query.php#L66-L97
25,905
vperyod/vperyod.session-handler
src/SessionHandler.php
SessionHandler.newSession
protected function newSession(Request $request) { $factory = $this->sessionFactory; $cookie = $request->getCookieParams(); return $factory->newInstance($cookie); }
php
protected function newSession(Request $request) { $factory = $this->sessionFactory; $cookie = $request->getCookieParams(); return $factory->newInstance($cookie); }
[ "protected", "function", "newSession", "(", "Request", "$", "request", ")", "{", "$", "factory", "=", "$", "this", "->", "sessionFactory", ";", "$", "cookie", "=", "$", "request", "->", "getCookieParams", "(", ")", ";", "return", "$", "factory", "->", "newInstance", "(", "$", "cookie", ")", ";", "}" ]
Create new session @param Request $request PSR7 Request @return Session\Session @access protected
[ "Create", "new", "session" ]
61a607be009296b69bdb328ed3a26940e1b925bb
https://github.com/vperyod/vperyod.session-handler/blob/61a607be009296b69bdb328ed3a26940e1b925bb/src/SessionHandler.php#L87-L92
25,906
MatiasNAmendola/slimpower-slim
src/Libs/Net.php
Net.getLocalIP
public static function getLocalIP() { $s = &$_SERVER; $ipAddress = $s['REMOTE_ADDR']; if (array_key_exists('HTTP_X_FORWARDED_FOR', $s)) { $temp = explode(',', $s['HTTP_X_FORWARDED_FOR']); $ipAddress = array_pop($temp); } $result = $ipAddress == '::1' ? "127.0.0.1" : $ipAddress; return $result; }
php
public static function getLocalIP() { $s = &$_SERVER; $ipAddress = $s['REMOTE_ADDR']; if (array_key_exists('HTTP_X_FORWARDED_FOR', $s)) { $temp = explode(',', $s['HTTP_X_FORWARDED_FOR']); $ipAddress = array_pop($temp); } $result = $ipAddress == '::1' ? "127.0.0.1" : $ipAddress; return $result; }
[ "public", "static", "function", "getLocalIP", "(", ")", "{", "$", "s", "=", "&", "$", "_SERVER", ";", "$", "ipAddress", "=", "$", "s", "[", "'REMOTE_ADDR'", "]", ";", "if", "(", "array_key_exists", "(", "'HTTP_X_FORWARDED_FOR'", ",", "$", "s", ")", ")", "{", "$", "temp", "=", "explode", "(", "','", ",", "$", "s", "[", "'HTTP_X_FORWARDED_FOR'", "]", ")", ";", "$", "ipAddress", "=", "array_pop", "(", "$", "temp", ")", ";", "}", "$", "result", "=", "$", "ipAddress", "==", "'::1'", "?", "\"127.0.0.1\"", ":", "$", "ipAddress", ";", "return", "$", "result", ";", "}" ]
Get local IP @return string
[ "Get", "local", "IP" ]
c78ebbd4124d75ec82fe19b6dd62504da097fd15
https://github.com/MatiasNAmendola/slimpower-slim/blob/c78ebbd4124d75ec82fe19b6dd62504da097fd15/src/Libs/Net.php#L40-L53
25,907
MatiasNAmendola/slimpower-slim
src/Libs/Net.php
Net.isSecure
public static function isSecure() { $s = &$_SERVER; $ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true : false; return $ssl; }
php
public static function isSecure() { $s = &$_SERVER; $ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true : false; return $ssl; }
[ "public", "static", "function", "isSecure", "(", ")", "{", "$", "s", "=", "&", "$", "_SERVER", ";", "$", "ssl", "=", "(", "!", "empty", "(", "$", "s", "[", "'HTTPS'", "]", ")", "&&", "$", "s", "[", "'HTTPS'", "]", "==", "'on'", ")", "?", "true", ":", "false", ";", "return", "$", "ssl", ";", "}" ]
Evaluate the Safety Scope of Application. @return boolean
[ "Evaluate", "the", "Safety", "Scope", "of", "Application", "." ]
c78ebbd4124d75ec82fe19b6dd62504da097fd15
https://github.com/MatiasNAmendola/slimpower-slim/blob/c78ebbd4124d75ec82fe19b6dd62504da097fd15/src/Libs/Net.php#L94-L98
25,908
MatiasNAmendola/slimpower-slim
src/Libs/Net.php
Net.getBasicPath
public static function getBasicPath() { $s = &$_SERVER; $ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true : false; $sp = strtolower($s['SERVER_PROTOCOL']); $protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : ''); $port = $s['SERVER_PORT']; $port = ((!$ssl && $port == '80') || ($ssl && $port == '443')) ? '' : ':' . $port; $host = isset($s['HTTP_X_FORWARDED_HOST']) ? $s['HTTP_X_FORWARDED_HOST'] : (isset($s['HTTP_HOST']) ? $s['HTTP_HOST'] : null); $host = isset($host) ? $host : $s['SERVER_NAME'] . $port; $uri = $protocol . '://' . $host; return $uri; }
php
public static function getBasicPath() { $s = &$_SERVER; $ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true : false; $sp = strtolower($s['SERVER_PROTOCOL']); $protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : ''); $port = $s['SERVER_PORT']; $port = ((!$ssl && $port == '80') || ($ssl && $port == '443')) ? '' : ':' . $port; $host = isset($s['HTTP_X_FORWARDED_HOST']) ? $s['HTTP_X_FORWARDED_HOST'] : (isset($s['HTTP_HOST']) ? $s['HTTP_HOST'] : null); $host = isset($host) ? $host : $s['SERVER_NAME'] . $port; $uri = $protocol . '://' . $host; return $uri; }
[ "public", "static", "function", "getBasicPath", "(", ")", "{", "$", "s", "=", "&", "$", "_SERVER", ";", "$", "ssl", "=", "(", "!", "empty", "(", "$", "s", "[", "'HTTPS'", "]", ")", "&&", "$", "s", "[", "'HTTPS'", "]", "==", "'on'", ")", "?", "true", ":", "false", ";", "$", "sp", "=", "strtolower", "(", "$", "s", "[", "'SERVER_PROTOCOL'", "]", ")", ";", "$", "protocol", "=", "substr", "(", "$", "sp", ",", "0", ",", "strpos", "(", "$", "sp", ",", "'/'", ")", ")", ".", "(", "(", "$", "ssl", ")", "?", "'s'", ":", "''", ")", ";", "$", "port", "=", "$", "s", "[", "'SERVER_PORT'", "]", ";", "$", "port", "=", "(", "(", "!", "$", "ssl", "&&", "$", "port", "==", "'80'", ")", "||", "(", "$", "ssl", "&&", "$", "port", "==", "'443'", ")", ")", "?", "''", ":", "':'", ".", "$", "port", ";", "$", "host", "=", "isset", "(", "$", "s", "[", "'HTTP_X_FORWARDED_HOST'", "]", ")", "?", "$", "s", "[", "'HTTP_X_FORWARDED_HOST'", "]", ":", "(", "isset", "(", "$", "s", "[", "'HTTP_HOST'", "]", ")", "?", "$", "s", "[", "'HTTP_HOST'", "]", ":", "null", ")", ";", "$", "host", "=", "isset", "(", "$", "host", ")", "?", "$", "host", ":", "$", "s", "[", "'SERVER_NAME'", "]", ".", "$", "port", ";", "$", "uri", "=", "$", "protocol", ".", "'://'", ".", "$", "host", ";", "return", "$", "uri", ";", "}" ]
Get basic path @return string URL
[ "Get", "basic", "path" ]
c78ebbd4124d75ec82fe19b6dd62504da097fd15
https://github.com/MatiasNAmendola/slimpower-slim/blob/c78ebbd4124d75ec82fe19b6dd62504da097fd15/src/Libs/Net.php#L104-L115
25,909
itcreator/custom-cmf
Module/System/src/Cmf/System/Application.php
Application.killWww
public function killWww() { $host = $_SERVER['SERVER_NAME']; if (stripos($host, 'www.') === 0) { $host = substr_replace($host, '', 0, 4); $uri = $_SERVER['REQUEST_URI']; header("HTTP/1.1 301 Moved Permanently"); if ('/' == $uri[0]) { header('Location: http://' . $host . $uri); } else { header('Location: http://' . $host . '/' . $uri); } die; } return $this; }
php
public function killWww() { $host = $_SERVER['SERVER_NAME']; if (stripos($host, 'www.') === 0) { $host = substr_replace($host, '', 0, 4); $uri = $_SERVER['REQUEST_URI']; header("HTTP/1.1 301 Moved Permanently"); if ('/' == $uri[0]) { header('Location: http://' . $host . $uri); } else { header('Location: http://' . $host . '/' . $uri); } die; } return $this; }
[ "public", "function", "killWww", "(", ")", "{", "$", "host", "=", "$", "_SERVER", "[", "'SERVER_NAME'", "]", ";", "if", "(", "stripos", "(", "$", "host", ",", "'www.'", ")", "===", "0", ")", "{", "$", "host", "=", "substr_replace", "(", "$", "host", ",", "''", ",", "0", ",", "4", ")", ";", "$", "uri", "=", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ";", "header", "(", "\"HTTP/1.1 301 Moved Permanently\"", ")", ";", "if", "(", "'/'", "==", "$", "uri", "[", "0", "]", ")", "{", "header", "(", "'Location: http://'", ".", "$", "host", ".", "$", "uri", ")", ";", "}", "else", "{", "header", "(", "'Location: http://'", ".", "$", "host", ".", "'/'", ".", "$", "uri", ")", ";", "}", "die", ";", "}", "return", "$", "this", ";", "}" ]
Redirect from www.hostname to hostname @return Application
[ "Redirect", "from", "www", ".", "hostname", "to", "hostname" ]
42fc0535dfa0f641856f06673f6ab596b2020c40
https://github.com/itcreator/custom-cmf/blob/42fc0535dfa0f641856f06673f6ab596b2020c40/Module/System/src/Cmf/System/Application.php#L67-L85
25,910
PenoaksDev/Milky-Framework
src/Milky/Binding/UniversalBuilder.php
UniversalBuilder.resolve
public static function resolve( $key ) { if ( strpos( $key, '\\' ) !== false ) return static::resolveClass( $key ); $key = explode( '.', $key ); if ( $resolver = static::getResolver( $key[0] ) ) return $resolver->resolve( $key[0], implode( '.', array_slice( $key, 1 ) ) ); return null; }
php
public static function resolve( $key ) { if ( strpos( $key, '\\' ) !== false ) return static::resolveClass( $key ); $key = explode( '.', $key ); if ( $resolver = static::getResolver( $key[0] ) ) return $resolver->resolve( $key[0], implode( '.', array_slice( $key, 1 ) ) ); return null; }
[ "public", "static", "function", "resolve", "(", "$", "key", ")", "{", "if", "(", "strpos", "(", "$", "key", ",", "'\\\\'", ")", "!==", "false", ")", "return", "static", "::", "resolveClass", "(", "$", "key", ")", ";", "$", "key", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "if", "(", "$", "resolver", "=", "static", "::", "getResolver", "(", "$", "key", "[", "0", "]", ")", ")", "return", "$", "resolver", "->", "resolve", "(", "$", "key", "[", "0", "]", ",", "implode", "(", "'.'", ",", "array_slice", "(", "$", "key", ",", "1", ")", ")", ")", ";", "return", "null", ";", "}" ]
Attempts to locate a instance or value from the registered resolvers. @param $key @return mixed|null|object
[ "Attempts", "to", "locate", "a", "instance", "or", "value", "from", "the", "registered", "resolvers", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Binding/UniversalBuilder.php#L132-L143
25,911
PenoaksDev/Milky-Framework
src/Milky/Binding/UniversalBuilder.php
UniversalBuilder.resolveClass
public static function resolveClass( $class, $buildOnFailure = false, $parameters = [] ) { if ( !is_string( $class ) ) throw new ResolverException( "Class must be a string" ); if ( $class == Framework::class ) return Framework::fw(); if ( $class == Configuration::class ) return Framework::config(); if ( $class == Logger::class ) return Framework::log(); // TODO Add a few more basic classes foreach ( static::$resolvers as $resolver ) if ( false !== ( $result = $resolver->resolveClass( $class ) ) ) return $result; if ( $buildOnFailure ) return static::buildClass( $class, $parameters ); return null; }
php
public static function resolveClass( $class, $buildOnFailure = false, $parameters = [] ) { if ( !is_string( $class ) ) throw new ResolverException( "Class must be a string" ); if ( $class == Framework::class ) return Framework::fw(); if ( $class == Configuration::class ) return Framework::config(); if ( $class == Logger::class ) return Framework::log(); // TODO Add a few more basic classes foreach ( static::$resolvers as $resolver ) if ( false !== ( $result = $resolver->resolveClass( $class ) ) ) return $result; if ( $buildOnFailure ) return static::buildClass( $class, $parameters ); return null; }
[ "public", "static", "function", "resolveClass", "(", "$", "class", ",", "$", "buildOnFailure", "=", "false", ",", "$", "parameters", "=", "[", "]", ")", "{", "if", "(", "!", "is_string", "(", "$", "class", ")", ")", "throw", "new", "ResolverException", "(", "\"Class must be a string\"", ")", ";", "if", "(", "$", "class", "==", "Framework", "::", "class", ")", "return", "Framework", "::", "fw", "(", ")", ";", "if", "(", "$", "class", "==", "Configuration", "::", "class", ")", "return", "Framework", "::", "config", "(", ")", ";", "if", "(", "$", "class", "==", "Logger", "::", "class", ")", "return", "Framework", "::", "log", "(", ")", ";", "// TODO Add a few more basic classes", "foreach", "(", "static", "::", "$", "resolvers", "as", "$", "resolver", ")", "if", "(", "false", "!==", "(", "$", "result", "=", "$", "resolver", "->", "resolveClass", "(", "$", "class", ")", ")", ")", "return", "$", "result", ";", "if", "(", "$", "buildOnFailure", ")", "return", "static", "::", "buildClass", "(", "$", "class", ",", "$", "parameters", ")", ";", "return", "null", ";", "}" ]
Attempts to locate a class within the registered resolvers. Optionally will build the class on failure. @param string $class @param bool $buildOnFailure @param array $parameters @return mixed|null|object
[ "Attempts", "to", "locate", "a", "class", "within", "the", "registered", "resolvers", ".", "Optionally", "will", "build", "the", "class", "on", "failure", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Binding/UniversalBuilder.php#L154-L176
25,912
PenoaksDev/Milky-Framework
src/Milky/Binding/UniversalBuilder.php
UniversalBuilder.buildClass
public static function buildClass( $class, array $parameters = [] ) { if ( !is_string( $class ) ) throw new BindingException( "Class must be a string" ); if ( static::building( $class ) ) throw new BindingException( "The class [" . $class . "] is already being built." ); static::$buildStack[] = $class; try { $reflector = new \ReflectionClass( $class ); // If the type is not instantiable, the developer is attempting to resolve // an abstract type such as an Interface of Abstract Class and there is // no binding registered for the abstractions so we need to bail out. if ( !$reflector->isInstantiable() ) throw new BindingException( "Target [$class] is not instantiable." ); $constructor = $reflector->getConstructor(); // If there are no constructors, that means there are no dependencies then // we can just resolve the instances of the objects right away. if ( is_null( $constructor ) ) return new $class; $dependencies = $constructor->getParameters(); // Once we have all the constructor's parameters we can create each of the // dependency instances and then use the reflection instances to make a // new instance of this class, injecting the created dependencies in. $parameters = static::keyParametersByArgument( $dependencies, $parameters ); $instances = static::getDependencies( $dependencies, $parameters, $class ); array_pop( static::$buildStack ); /**/ return $reflector->newInstanceArgs( $instances ); } catch ( \ReflectionException $e ) { array_pop( static::$buildStack ); throw new BindingException( "Failed to build [$class]: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() ); } }
php
public static function buildClass( $class, array $parameters = [] ) { if ( !is_string( $class ) ) throw new BindingException( "Class must be a string" ); if ( static::building( $class ) ) throw new BindingException( "The class [" . $class . "] is already being built." ); static::$buildStack[] = $class; try { $reflector = new \ReflectionClass( $class ); // If the type is not instantiable, the developer is attempting to resolve // an abstract type such as an Interface of Abstract Class and there is // no binding registered for the abstractions so we need to bail out. if ( !$reflector->isInstantiable() ) throw new BindingException( "Target [$class] is not instantiable." ); $constructor = $reflector->getConstructor(); // If there are no constructors, that means there are no dependencies then // we can just resolve the instances of the objects right away. if ( is_null( $constructor ) ) return new $class; $dependencies = $constructor->getParameters(); // Once we have all the constructor's parameters we can create each of the // dependency instances and then use the reflection instances to make a // new instance of this class, injecting the created dependencies in. $parameters = static::keyParametersByArgument( $dependencies, $parameters ); $instances = static::getDependencies( $dependencies, $parameters, $class ); array_pop( static::$buildStack ); /**/ return $reflector->newInstanceArgs( $instances ); } catch ( \ReflectionException $e ) { array_pop( static::$buildStack ); throw new BindingException( "Failed to build [$class]: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() ); } }
[ "public", "static", "function", "buildClass", "(", "$", "class", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "if", "(", "!", "is_string", "(", "$", "class", ")", ")", "throw", "new", "BindingException", "(", "\"Class must be a string\"", ")", ";", "if", "(", "static", "::", "building", "(", "$", "class", ")", ")", "throw", "new", "BindingException", "(", "\"The class [\"", ".", "$", "class", ".", "\"] is already being built.\"", ")", ";", "static", "::", "$", "buildStack", "[", "]", "=", "$", "class", ";", "try", "{", "$", "reflector", "=", "new", "\\", "ReflectionClass", "(", "$", "class", ")", ";", "// If the type is not instantiable, the developer is attempting to resolve", "// an abstract type such as an Interface of Abstract Class and there is", "// no binding registered for the abstractions so we need to bail out.", "if", "(", "!", "$", "reflector", "->", "isInstantiable", "(", ")", ")", "throw", "new", "BindingException", "(", "\"Target [$class] is not instantiable.\"", ")", ";", "$", "constructor", "=", "$", "reflector", "->", "getConstructor", "(", ")", ";", "// If there are no constructors, that means there are no dependencies then", "// we can just resolve the instances of the objects right away.", "if", "(", "is_null", "(", "$", "constructor", ")", ")", "return", "new", "$", "class", ";", "$", "dependencies", "=", "$", "constructor", "->", "getParameters", "(", ")", ";", "// Once we have all the constructor's parameters we can create each of the", "// dependency instances and then use the reflection instances to make a", "// new instance of this class, injecting the created dependencies in.", "$", "parameters", "=", "static", "::", "keyParametersByArgument", "(", "$", "dependencies", ",", "$", "parameters", ")", ";", "$", "instances", "=", "static", "::", "getDependencies", "(", "$", "dependencies", ",", "$", "parameters", ",", "$", "class", ")", ";", "array_pop", "(", "static", "::", "$", "buildStack", ")", ";", "/**/", "return", "$", "reflector", "->", "newInstanceArgs", "(", "$", "instances", ")", ";", "}", "catch", "(", "\\", "ReflectionException", "$", "e", ")", "{", "array_pop", "(", "static", "::", "$", "buildStack", ")", ";", "throw", "new", "BindingException", "(", "\"Failed to build [$class]: \"", ".", "$", "e", "->", "getMessage", "(", ")", ".", "\" in \"", ".", "$", "e", "->", "getFile", "(", ")", ".", "\" on line \"", ".", "$", "e", "->", "getLine", "(", ")", ")", ";", "}", "}" ]
Attempts to construct a class @param string $class @param array $parameters @return object @throws BindingException
[ "Attempts", "to", "construct", "a", "class" ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Binding/UniversalBuilder.php#L187-L235
25,913
Dhii/callback-abstract
src/NormalizeMethodCallableCapableTrait.php
NormalizeMethodCallableCapableTrait._normalizeMethodCallable
protected function _normalizeMethodCallable($callable) { if (is_object($callable) && is_callable($callable)) { return array($callable, '__invoke'); } $amtPartsRequired = 2; // Number of parts required for a valid callable $origCallable = $callable; // Preserving the original value for reporting // If stringable, try to separate into parts try { $callable = $this->_normalizeString($callable); $callable = explode('::', $callable, $amtPartsRequired); } catch (InvalidArgumentException $e) { // Just continue } // Normalizing to array $callable = $this->_normalizeArray($callable); $callable = array_slice($callable, 0, $amtPartsRequired); // Array must have exactly 2 parts if (count($callable) !== $amtPartsRequired) { throw $this->_createOutOfRangeException($this->__('The callable must have at least %1$s parts', array($amtPartsRequired)), null, null, $origCallable); } // First value must be an object or string, because stringable objects should be valid targets if (!is_string($callable[0]) && !is_object($callable[0])) { throw $this->_createOutOfRangeException($this->__('The first part must be an object or a string'), null, null, $origCallable); } // The second value must be a string or stringable try { $callable[1] = $this->_normalizeString($callable[1]); } catch (InvalidArgumentException $e) { throw $this->_createOutOfRangeException($this->__('The second part must be a string or stringable'), null, $e, $origCallable); } return $callable; }
php
protected function _normalizeMethodCallable($callable) { if (is_object($callable) && is_callable($callable)) { return array($callable, '__invoke'); } $amtPartsRequired = 2; // Number of parts required for a valid callable $origCallable = $callable; // Preserving the original value for reporting // If stringable, try to separate into parts try { $callable = $this->_normalizeString($callable); $callable = explode('::', $callable, $amtPartsRequired); } catch (InvalidArgumentException $e) { // Just continue } // Normalizing to array $callable = $this->_normalizeArray($callable); $callable = array_slice($callable, 0, $amtPartsRequired); // Array must have exactly 2 parts if (count($callable) !== $amtPartsRequired) { throw $this->_createOutOfRangeException($this->__('The callable must have at least %1$s parts', array($amtPartsRequired)), null, null, $origCallable); } // First value must be an object or string, because stringable objects should be valid targets if (!is_string($callable[0]) && !is_object($callable[0])) { throw $this->_createOutOfRangeException($this->__('The first part must be an object or a string'), null, null, $origCallable); } // The second value must be a string or stringable try { $callable[1] = $this->_normalizeString($callable[1]); } catch (InvalidArgumentException $e) { throw $this->_createOutOfRangeException($this->__('The second part must be a string or stringable'), null, $e, $origCallable); } return $callable; }
[ "protected", "function", "_normalizeMethodCallable", "(", "$", "callable", ")", "{", "if", "(", "is_object", "(", "$", "callable", ")", "&&", "is_callable", "(", "$", "callable", ")", ")", "{", "return", "array", "(", "$", "callable", ",", "'__invoke'", ")", ";", "}", "$", "amtPartsRequired", "=", "2", ";", "// Number of parts required for a valid callable", "$", "origCallable", "=", "$", "callable", ";", "// Preserving the original value for reporting", "// If stringable, try to separate into parts", "try", "{", "$", "callable", "=", "$", "this", "->", "_normalizeString", "(", "$", "callable", ")", ";", "$", "callable", "=", "explode", "(", "'::'", ",", "$", "callable", ",", "$", "amtPartsRequired", ")", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "// Just continue", "}", "// Normalizing to array", "$", "callable", "=", "$", "this", "->", "_normalizeArray", "(", "$", "callable", ")", ";", "$", "callable", "=", "array_slice", "(", "$", "callable", ",", "0", ",", "$", "amtPartsRequired", ")", ";", "// Array must have exactly 2 parts", "if", "(", "count", "(", "$", "callable", ")", "!==", "$", "amtPartsRequired", ")", "{", "throw", "$", "this", "->", "_createOutOfRangeException", "(", "$", "this", "->", "__", "(", "'The callable must have at least %1$s parts'", ",", "array", "(", "$", "amtPartsRequired", ")", ")", ",", "null", ",", "null", ",", "$", "origCallable", ")", ";", "}", "// First value must be an object or string, because stringable objects should be valid targets", "if", "(", "!", "is_string", "(", "$", "callable", "[", "0", "]", ")", "&&", "!", "is_object", "(", "$", "callable", "[", "0", "]", ")", ")", "{", "throw", "$", "this", "->", "_createOutOfRangeException", "(", "$", "this", "->", "__", "(", "'The first part must be an object or a string'", ")", ",", "null", ",", "null", ",", "$", "origCallable", ")", ";", "}", "// The second value must be a string or stringable", "try", "{", "$", "callable", "[", "1", "]", "=", "$", "this", "->", "_normalizeString", "(", "$", "callable", "[", "1", "]", ")", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "throw", "$", "this", "->", "_createOutOfRangeException", "(", "$", "this", "->", "__", "(", "'The second part must be a string or stringable'", ")", ",", "null", ",", "$", "e", ",", "$", "origCallable", ")", ";", "}", "return", "$", "callable", ";", "}" ]
Normalizes a method representation into a format recognizable by PHP as callable. This does not guarantee that the callable will actually be invocable at this time; only that it looks like something that can be invoked. See the second argument of {@see is_callable()). @since [*next-version*] @param string|Stringable|stdClass|Traversable|array $callable The stringable that identifies a static method, or a list, where the first element is a class or class name, and the second is the name of the method. If the list has more than 2 parts, other parts will be removed. The second element may be a Stringable object, and will then be normalized. The first element MUST be a string or object, and will not be normalized. @see is_callable() @throws InvalidArgumentException If the argument is not stringable and not a list. @throws OutOfRangeException If the argument does not contain enough parts to make a callable, if one of the parts is invalid. @return array An array, where the first element is an object or a class name, and the second element is the name of a method.
[ "Normalizes", "a", "method", "representation", "into", "a", "format", "recognizable", "by", "PHP", "as", "callable", "." ]
43ed4e99fc6ccdaf46a25d06da482a2fba8d9b19
https://github.com/Dhii/callback-abstract/blob/43ed4e99fc6ccdaf46a25d06da482a2fba8d9b19/src/NormalizeMethodCallableCapableTrait.php#L34-L73
25,914
shgysk8zer0/core_api
traits/ajax_dom.php
AJAX_DOM.open
final public function open( $url = null, array $paramaters = array(), $replace = false, $name = '_blank' ) { $specs = [ 'height' => 500, // The height of the window. Min. value is 100 'width' => 500, // The width of the window. Min. value is 100 'top' => 0, // The top position of the window. 'left' => 0, // The left position of the window. 'resizable' => 1, // Whether or not the window is resizable. IE only 'titlebar' => 0, // Whether or not to display the title bar 'menubar' => 0, // Whether or not to display the menu bar 'toolbar' => 0, // Whether or not to display the browser toolbar. IE and Firefox only 'status' => 0 // Whether or not to add a status bar ]; $specs = array_merge($specs, $paramaters); $this->response['open'] = [ 'url' => $url, 'name' => $name, 'specs' => $specs, 'replace' => $replace ]; return $this; }
php
final public function open( $url = null, array $paramaters = array(), $replace = false, $name = '_blank' ) { $specs = [ 'height' => 500, // The height of the window. Min. value is 100 'width' => 500, // The width of the window. Min. value is 100 'top' => 0, // The top position of the window. 'left' => 0, // The left position of the window. 'resizable' => 1, // Whether or not the window is resizable. IE only 'titlebar' => 0, // Whether or not to display the title bar 'menubar' => 0, // Whether or not to display the menu bar 'toolbar' => 0, // Whether or not to display the browser toolbar. IE and Firefox only 'status' => 0 // Whether or not to add a status bar ]; $specs = array_merge($specs, $paramaters); $this->response['open'] = [ 'url' => $url, 'name' => $name, 'specs' => $specs, 'replace' => $replace ]; return $this; }
[ "final", "public", "function", "open", "(", "$", "url", "=", "null", ",", "array", "$", "paramaters", "=", "array", "(", ")", ",", "$", "replace", "=", "false", ",", "$", "name", "=", "'_blank'", ")", "{", "$", "specs", "=", "[", "'height'", "=>", "500", ",", "// The height of the window. Min. value is 100", "'width'", "=>", "500", ",", "// The width of the window. Min. value is 100", "'top'", "=>", "0", ",", "// The top position of the window.", "'left'", "=>", "0", ",", "// The left position of the window.", "'resizable'", "=>", "1", ",", "// Whether or not the window is resizable. IE only", "'titlebar'", "=>", "0", ",", "// Whether or not to display the title bar", "'menubar'", "=>", "0", ",", "// Whether or not to display the menu bar", "'toolbar'", "=>", "0", ",", "// Whether or not to display the browser toolbar. IE and Firefox only", "'status'", "=>", "0", "// Whether or not to add a status bar", "]", ";", "$", "specs", "=", "array_merge", "(", "$", "specs", ",", "$", "paramaters", ")", ";", "$", "this", "->", "response", "[", "'open'", "]", "=", "[", "'url'", "=>", "$", "url", ",", "'name'", "=>", "$", "name", ",", "'specs'", "=>", "$", "specs", ",", "'replace'", "=>", "$", "replace", "]", ";", "return", "$", "this", ";", "}" ]
Open a popup using JavaScript @param string $url Specifies the URL of the page to open @param array $paramaters See comments on $specs @param bool $replace Creates a new entry or replaces the current entry in the history list @param string $name Specifies the target attribute or the name of the window @return self @see http://www.w3schools.com/jsref/met_win_open.asp @example $resp->open('example.com', ['width' => 900], false, '_top')
[ "Open", "a", "popup", "using", "JavaScript" ]
9e9b8baf761af874b95256ad2462e55fbb2b2e58
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/ajax_dom.php#L476-L505
25,915
shgysk8zer0/core_api
traits/ajax_dom.php
AJAX_DOM.animate
final public function animate($sel, Array $keyframes, Array $opts) { if (! array_key_exists('animate', $this->response)) { $this->response['animate'] = []; } $this->response['animate'][$sel] = ['keyframes' => $keyframes, 'opts' => $opts]; return $this; }
php
final public function animate($sel, Array $keyframes, Array $opts) { if (! array_key_exists('animate', $this->response)) { $this->response['animate'] = []; } $this->response['animate'][$sel] = ['keyframes' => $keyframes, 'opts' => $opts]; return $this; }
[ "final", "public", "function", "animate", "(", "$", "sel", ",", "Array", "$", "keyframes", ",", "Array", "$", "opts", ")", "{", "if", "(", "!", "array_key_exists", "(", "'animate'", ",", "$", "this", "->", "response", ")", ")", "{", "$", "this", "->", "response", "[", "'animate'", "]", "=", "[", "]", ";", "}", "$", "this", "->", "response", "[", "'animate'", "]", "[", "$", "sel", "]", "=", "[", "'keyframes'", "=>", "$", "keyframes", ",", "'opts'", "=>", "$", "opts", "]", ";", "return", "$", "this", ";", "}" ]
Add animations using `Element.animate` @param String $sel Passed to `document.querySelectorAll` @param Array $keyframes Array of keyframes / steps in animation @param array $opts Array of options, such as duration @return self @see https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats @example $resp->animate('#login-dialog', [ ['transform' => 'none'], ['transform' => 'translateX(5em)scale(0.9)'], ['transform' => 'translateX(-5em)scale(1.1)'], ['transform' => 'none'] ], [ 'duration' => 100, 'iterations' => 5, ]);
[ "Add", "animations", "using", "Element", ".", "animate" ]
9e9b8baf761af874b95256ad2462e55fbb2b2e58
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/ajax_dom.php#L653-L660
25,916
shgysk8zer0/core_api
traits/ajax_dom.php
AJAX_DOM.consoleSetter
final protected function consoleSetter( $method = 'log', array $value = array() ) { if (array_key_exists($method, $this->response)) { if (! is_array($this->response[$method])) { $this->response[$method] = [$this->response[$method]]; } $this->response[$method][] = count($value) === 1 ? current($value) : $value; } else { $this->response[$method] = count($value) == 1 ? current($value) : $value; } return $this; }
php
final protected function consoleSetter( $method = 'log', array $value = array() ) { if (array_key_exists($method, $this->response)) { if (! is_array($this->response[$method])) { $this->response[$method] = [$this->response[$method]]; } $this->response[$method][] = count($value) === 1 ? current($value) : $value; } else { $this->response[$method] = count($value) == 1 ? current($value) : $value; } return $this; }
[ "final", "protected", "function", "consoleSetter", "(", "$", "method", "=", "'log'", ",", "array", "$", "value", "=", "array", "(", ")", ")", "{", "if", "(", "array_key_exists", "(", "$", "method", ",", "$", "this", "->", "response", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "this", "->", "response", "[", "$", "method", "]", ")", ")", "{", "$", "this", "->", "response", "[", "$", "method", "]", "=", "[", "$", "this", "->", "response", "[", "$", "method", "]", "]", ";", "}", "$", "this", "->", "response", "[", "$", "method", "]", "[", "]", "=", "count", "(", "$", "value", ")", "===", "1", "?", "current", "(", "$", "value", ")", ":", "$", "value", ";", "}", "else", "{", "$", "this", "->", "response", "[", "$", "method", "]", "=", "count", "(", "$", "value", ")", "==", "1", "?", "current", "(", "$", "value", ")", ":", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Private method for setting console values which can contain one or more values. I.E., log could take a singe argument and then be called again later. For console methods, set here to make it easier to call multiple times. @param string $method Console method to be setting @param array $value Value to be setting or appending. @return self
[ "Private", "method", "for", "setting", "console", "values", "which", "can", "contain", "one", "or", "more", "values", ".", "I", ".", "E", ".", "log", "could", "take", "a", "singe", "argument", "and", "then", "be", "called", "again", "later", ".", "For", "console", "methods", "set", "here", "to", "make", "it", "easier", "to", "call", "multiple", "times", "." ]
9e9b8baf761af874b95256ad2462e55fbb2b2e58
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/ajax_dom.php#L720-L734
25,917
Revys/revy
src/App/RoutesBase.php
RoutesBase.withLanguage
public static function withLanguage(\Closure $callback, $config = []) { if (\App::runningUnitTests()) { $locale = \App::getLocale(); } else { $locale = request()->segment(1); } if (strlen($locale) <= 2) { Route::group(['prefix' => $locale, 'middleware' => 'lang'], function () use ($callback) { $callback(); }); } }
php
public static function withLanguage(\Closure $callback, $config = []) { if (\App::runningUnitTests()) { $locale = \App::getLocale(); } else { $locale = request()->segment(1); } if (strlen($locale) <= 2) { Route::group(['prefix' => $locale, 'middleware' => 'lang'], function () use ($callback) { $callback(); }); } }
[ "public", "static", "function", "withLanguage", "(", "\\", "Closure", "$", "callback", ",", "$", "config", "=", "[", "]", ")", "{", "if", "(", "\\", "App", "::", "runningUnitTests", "(", ")", ")", "{", "$", "locale", "=", "\\", "App", "::", "getLocale", "(", ")", ";", "}", "else", "{", "$", "locale", "=", "request", "(", ")", "->", "segment", "(", "1", ")", ";", "}", "if", "(", "strlen", "(", "$", "locale", ")", "<=", "2", ")", "{", "Route", "::", "group", "(", "[", "'prefix'", "=>", "$", "locale", ",", "'middleware'", "=>", "'lang'", "]", ",", "function", "(", ")", "use", "(", "$", "callback", ")", "{", "$", "callback", "(", ")", ";", "}", ")", ";", "}", "}" ]
Wraps routes with language prefix @param \Closure $callback @param array $config
[ "Wraps", "routes", "with", "language", "prefix" ]
b2c13f5f7e88eec2681b4ec8a0385e18c28fbfd1
https://github.com/Revys/revy/blob/b2c13f5f7e88eec2681b4ec8a0385e18c28fbfd1/src/App/RoutesBase.php#L36-L49
25,918
kapitchi/KapitchiEntity
src/KapitchiEntity/Mapper/EntityDbAdapterMapper.php
EntityDbAdapterMapper.getIdentifier
protected function getIdentifier($object) { $property = new ReflectionProperty(get_class($object), $this->getPrimaryKey()); $property->setAccessible(true); return $property->getValue($object); }
php
protected function getIdentifier($object) { $property = new ReflectionProperty(get_class($object), $this->getPrimaryKey()); $property->setAccessible(true); return $property->getValue($object); }
[ "protected", "function", "getIdentifier", "(", "$", "object", ")", "{", "$", "property", "=", "new", "ReflectionProperty", "(", "get_class", "(", "$", "object", ")", ",", "$", "this", "->", "getPrimaryKey", "(", ")", ")", ";", "$", "property", "->", "setAccessible", "(", "true", ")", ";", "return", "$", "property", "->", "getValue", "(", "$", "object", ")", ";", "}" ]
check if object has already an identifier @param object $object @return mixed
[ "check", "if", "object", "has", "already", "an", "identifier" ]
69deaeb41d9133422a20ad6f64f0743d66cea8fd
https://github.com/kapitchi/KapitchiEntity/blob/69deaeb41d9133422a20ad6f64f0743d66cea8fd/src/KapitchiEntity/Mapper/EntityDbAdapterMapper.php#L99-L104
25,919
theopera/framework
src/Component/Mail/Mailer.php
Mailer.send
public function send(MailMessage $message) { $this->headers->add(new Header('From', $message->getFrom())); $this->mailer->send($message, $this->headers); }
php
public function send(MailMessage $message) { $this->headers->add(new Header('From', $message->getFrom())); $this->mailer->send($message, $this->headers); }
[ "public", "function", "send", "(", "MailMessage", "$", "message", ")", "{", "$", "this", "->", "headers", "->", "add", "(", "new", "Header", "(", "'From'", ",", "$", "message", "->", "getFrom", "(", ")", ")", ")", ";", "$", "this", "->", "mailer", "->", "send", "(", "$", "message", ",", "$", "this", "->", "headers", ")", ";", "}" ]
Tries to deliver the mail @param \Opera\Component\Mail\MailMessage $message @throws MailException
[ "Tries", "to", "deliver", "the", "mail" ]
fa6165d3891a310faa580c81dee49a63c150c711
https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/Mail/Mailer.php#L52-L57
25,920
theopera/framework
src/Component/Mail/Mailer.php
Mailer.parseAttachments
private function parseAttachments(array $files, string $message, string $contentType, string $hash) : string { $result = []; // The original message $result[] = '--body-mixed-' . $hash; $result[] = new Header('Content-Type', $contentType); $result[] = ''; $result[] = $message; // The attachments foreach ($files as $file) { $headers = new Headers(); $headers->add(new Header('Content-Transfer-Encoding', 'base64')); $headers->add(new Header('Content-Disposition', 'attachment')); $headers->add(new Header('Content-Type', 'application/octet-stream', [ 'filename' => $file->getFilename() ])); $result[] = '--body-mixed-' . $hash; $result[] = $headers; $result[] = ''; $result[] = base64_encode($file->fread($file->getSize())); } return implode("\r\n", $result); }
php
private function parseAttachments(array $files, string $message, string $contentType, string $hash) : string { $result = []; // The original message $result[] = '--body-mixed-' . $hash; $result[] = new Header('Content-Type', $contentType); $result[] = ''; $result[] = $message; // The attachments foreach ($files as $file) { $headers = new Headers(); $headers->add(new Header('Content-Transfer-Encoding', 'base64')); $headers->add(new Header('Content-Disposition', 'attachment')); $headers->add(new Header('Content-Type', 'application/octet-stream', [ 'filename' => $file->getFilename() ])); $result[] = '--body-mixed-' . $hash; $result[] = $headers; $result[] = ''; $result[] = base64_encode($file->fread($file->getSize())); } return implode("\r\n", $result); }
[ "private", "function", "parseAttachments", "(", "array", "$", "files", ",", "string", "$", "message", ",", "string", "$", "contentType", ",", "string", "$", "hash", ")", ":", "string", "{", "$", "result", "=", "[", "]", ";", "// The original message", "$", "result", "[", "]", "=", "'--body-mixed-'", ".", "$", "hash", ";", "$", "result", "[", "]", "=", "new", "Header", "(", "'Content-Type'", ",", "$", "contentType", ")", ";", "$", "result", "[", "]", "=", "''", ";", "$", "result", "[", "]", "=", "$", "message", ";", "// The attachments", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "headers", "=", "new", "Headers", "(", ")", ";", "$", "headers", "->", "add", "(", "new", "Header", "(", "'Content-Transfer-Encoding'", ",", "'base64'", ")", ")", ";", "$", "headers", "->", "add", "(", "new", "Header", "(", "'Content-Disposition'", ",", "'attachment'", ")", ")", ";", "$", "headers", "->", "add", "(", "new", "Header", "(", "'Content-Type'", ",", "'application/octet-stream'", ",", "[", "'filename'", "=>", "$", "file", "->", "getFilename", "(", ")", "]", ")", ")", ";", "$", "result", "[", "]", "=", "'--body-mixed-'", ".", "$", "hash", ";", "$", "result", "[", "]", "=", "$", "headers", ";", "$", "result", "[", "]", "=", "''", ";", "$", "result", "[", "]", "=", "base64_encode", "(", "$", "file", "->", "fread", "(", "$", "file", "->", "getSize", "(", ")", ")", ")", ";", "}", "return", "implode", "(", "\"\\r\\n\"", ",", "$", "result", ")", ";", "}" ]
This will return a message body with the attachments in basecode64 encoding also the original message will be included @param SplFileObject[] $files @param string $message @param string $contentType @param string $hash @return string
[ "This", "will", "return", "a", "message", "body", "with", "the", "attachments", "in", "basecode64", "encoding", "also", "the", "original", "message", "will", "be", "included" ]
fa6165d3891a310faa580c81dee49a63c150c711
https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/Mail/Mailer.php#L70-L97
25,921
romm/configuration_object
Classes/Validation/ValidatorResolver.php
ValidatorResolver.addMixedTypeValidators
protected function addMixedTypeValidators($targetClassName, GenericObjectValidator $validator) { foreach ($this->reflectionService->getClassPropertyNames($targetClassName) as $property) { /* * If the property already is already bound to an object validator, * there is no need to do further checks. */ if ($this->propertyHasObjectValidator($validator, $property)) { continue; } if ($this->propertyIsMixedType($targetClassName, $property)) { /* * The property is mixed, a validator with the `mixedTypes` * option is added, to delegate the validator resolving to * later (when the property is actually filled). */ $objectValidator = $this->createValidator(MixedTypeValidator::class); $validator->addPropertyValidator($property, $objectValidator); } } }
php
protected function addMixedTypeValidators($targetClassName, GenericObjectValidator $validator) { foreach ($this->reflectionService->getClassPropertyNames($targetClassName) as $property) { /* * If the property already is already bound to an object validator, * there is no need to do further checks. */ if ($this->propertyHasObjectValidator($validator, $property)) { continue; } if ($this->propertyIsMixedType($targetClassName, $property)) { /* * The property is mixed, a validator with the `mixedTypes` * option is added, to delegate the validator resolving to * later (when the property is actually filled). */ $objectValidator = $this->createValidator(MixedTypeValidator::class); $validator->addPropertyValidator($property, $objectValidator); } } }
[ "protected", "function", "addMixedTypeValidators", "(", "$", "targetClassName", ",", "GenericObjectValidator", "$", "validator", ")", "{", "foreach", "(", "$", "this", "->", "reflectionService", "->", "getClassPropertyNames", "(", "$", "targetClassName", ")", "as", "$", "property", ")", "{", "/*\n * If the property already is already bound to an object validator,\n * there is no need to do further checks.\n */", "if", "(", "$", "this", "->", "propertyHasObjectValidator", "(", "$", "validator", ",", "$", "property", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "this", "->", "propertyIsMixedType", "(", "$", "targetClassName", ",", "$", "property", ")", ")", "{", "/*\n * The property is mixed, a validator with the `mixedTypes`\n * option is added, to delegate the validator resolving to\n * later (when the property is actually filled).\n */", "$", "objectValidator", "=", "$", "this", "->", "createValidator", "(", "MixedTypeValidator", "::", "class", ")", ";", "$", "validator", "->", "addPropertyValidator", "(", "$", "property", ",", "$", "objectValidator", ")", ";", "}", "}", "}" ]
This function will list the properties of the given class, and filter on the ones that do not have a validator assigned yet. @param string $targetClassName @param GenericObjectValidator $validator
[ "This", "function", "will", "list", "the", "properties", "of", "the", "given", "class", "and", "filter", "on", "the", "ones", "that", "do", "not", "have", "a", "validator", "assigned", "yet", "." ]
d3a40903386c2e0766bd8279337fe6da45cf5ce3
https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Validation/ValidatorResolver.php#L118-L140
25,922
romm/configuration_object
Classes/Validation/ValidatorResolver.php
ValidatorResolver.propertyIsMixedType
protected function propertyIsMixedType($className, $property) { $mixedType = false; $propertySchema = $this->reflectionService->getClassSchema($className)->getProperty($property); if ($this->classIsMixedType($propertySchema['type'])) { $mixedType = true; } else { if ($this->reflectionService->isPropertyTaggedWith($className, $property, MixedTypesService::PROPERTY_ANNOTATION_MIXED_TYPE)) { $tags = $this->reflectionService->getPropertyTagValues($className, $property, MixedTypesService::PROPERTY_ANNOTATION_MIXED_TYPE); $mixedTypeClassName = reset($tags); if ($this->classIsMixedType($mixedTypeClassName)) { $mixedType = true; } } } return $mixedType; }
php
protected function propertyIsMixedType($className, $property) { $mixedType = false; $propertySchema = $this->reflectionService->getClassSchema($className)->getProperty($property); if ($this->classIsMixedType($propertySchema['type'])) { $mixedType = true; } else { if ($this->reflectionService->isPropertyTaggedWith($className, $property, MixedTypesService::PROPERTY_ANNOTATION_MIXED_TYPE)) { $tags = $this->reflectionService->getPropertyTagValues($className, $property, MixedTypesService::PROPERTY_ANNOTATION_MIXED_TYPE); $mixedTypeClassName = reset($tags); if ($this->classIsMixedType($mixedTypeClassName)) { $mixedType = true; } } } return $mixedType; }
[ "protected", "function", "propertyIsMixedType", "(", "$", "className", ",", "$", "property", ")", "{", "$", "mixedType", "=", "false", ";", "$", "propertySchema", "=", "$", "this", "->", "reflectionService", "->", "getClassSchema", "(", "$", "className", ")", "->", "getProperty", "(", "$", "property", ")", ";", "if", "(", "$", "this", "->", "classIsMixedType", "(", "$", "propertySchema", "[", "'type'", "]", ")", ")", "{", "$", "mixedType", "=", "true", ";", "}", "else", "{", "if", "(", "$", "this", "->", "reflectionService", "->", "isPropertyTaggedWith", "(", "$", "className", ",", "$", "property", ",", "MixedTypesService", "::", "PROPERTY_ANNOTATION_MIXED_TYPE", ")", ")", "{", "$", "tags", "=", "$", "this", "->", "reflectionService", "->", "getPropertyTagValues", "(", "$", "className", ",", "$", "property", ",", "MixedTypesService", "::", "PROPERTY_ANNOTATION_MIXED_TYPE", ")", ";", "$", "mixedTypeClassName", "=", "reset", "(", "$", "tags", ")", ";", "if", "(", "$", "this", "->", "classIsMixedType", "(", "$", "mixedTypeClassName", ")", ")", "{", "$", "mixedType", "=", "true", ";", "}", "}", "}", "return", "$", "mixedType", ";", "}" ]
Checks if the given property is a mixed type. First, we check if the type of the property is a class that implements the interface `MixedTypesInterface`. If not, we check if the property has the annotation `@mixedTypesResolver` with a class name that implements the interface `MixedTypesInterface`. If one was found, `true` is returned. @param string $className @param string $property @return bool
[ "Checks", "if", "the", "given", "property", "is", "a", "mixed", "type", "." ]
d3a40903386c2e0766bd8279337fe6da45cf5ce3
https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Validation/ValidatorResolver.php#L184-L204
25,923
Programie/PHPCurl
src/main/php/com/selfcoders/phpcurl/Curl.php
Curl.getHeaderContent
public function getHeaderContent() { if (!$this->headerFileHandle) { return null; } fseek($this->headerFileHandle, 0); $lines = array(); while ($line = trim(fgets($this->headerFileHandle), "\n\r")) { $lines[] = $line; } return $lines; }
php
public function getHeaderContent() { if (!$this->headerFileHandle) { return null; } fseek($this->headerFileHandle, 0); $lines = array(); while ($line = trim(fgets($this->headerFileHandle), "\n\r")) { $lines[] = $line; } return $lines; }
[ "public", "function", "getHeaderContent", "(", ")", "{", "if", "(", "!", "$", "this", "->", "headerFileHandle", ")", "{", "return", "null", ";", "}", "fseek", "(", "$", "this", "->", "headerFileHandle", ",", "0", ")", ";", "$", "lines", "=", "array", "(", ")", ";", "while", "(", "$", "line", "=", "trim", "(", "fgets", "(", "$", "this", "->", "headerFileHandle", ")", ",", "\"\\n\\r\"", ")", ")", "{", "$", "lines", "[", "]", "=", "$", "line", ";", "}", "return", "$", "lines", ";", "}" ]
Get the content of the header output if enabled with enabledHeaderOutput. @return array|null The header output or null if header output was not enabled
[ "Get", "the", "content", "of", "the", "header", "output", "if", "enabled", "with", "enabledHeaderOutput", "." ]
54ef8bba19e87654906f74b14646c1f322ea7241
https://github.com/Programie/PHPCurl/blob/54ef8bba19e87654906f74b14646c1f322ea7241/src/main/php/com/selfcoders/phpcurl/Curl.php#L146-L160
25,924
Programie/PHPCurl
src/main/php/com/selfcoders/phpcurl/Curl.php
Curl.getVerboseContent
public function getVerboseContent() { if (!$this->verboseFileHandle) { return null; } fseek($this->verboseFileHandle, 0); $lines = array(); while ($line = trim(fgets($this->verboseFileHandle), "\n\r")) { $lines[] = $line; } return $lines; }
php
public function getVerboseContent() { if (!$this->verboseFileHandle) { return null; } fseek($this->verboseFileHandle, 0); $lines = array(); while ($line = trim(fgets($this->verboseFileHandle), "\n\r")) { $lines[] = $line; } return $lines; }
[ "public", "function", "getVerboseContent", "(", ")", "{", "if", "(", "!", "$", "this", "->", "verboseFileHandle", ")", "{", "return", "null", ";", "}", "fseek", "(", "$", "this", "->", "verboseFileHandle", ",", "0", ")", ";", "$", "lines", "=", "array", "(", ")", ";", "while", "(", "$", "line", "=", "trim", "(", "fgets", "(", "$", "this", "->", "verboseFileHandle", ")", ",", "\"\\n\\r\"", ")", ")", "{", "$", "lines", "[", "]", "=", "$", "line", ";", "}", "return", "$", "lines", ";", "}" ]
Get the content of the verbose output if enabled with enableVerboseOutput. @return array|null The verbose output or null if verbose mode was not enabled
[ "Get", "the", "content", "of", "the", "verbose", "output", "if", "enabled", "with", "enableVerboseOutput", "." ]
54ef8bba19e87654906f74b14646c1f322ea7241
https://github.com/Programie/PHPCurl/blob/54ef8bba19e87654906f74b14646c1f322ea7241/src/main/php/com/selfcoders/phpcurl/Curl.php#L167-L181
25,925
Programie/PHPCurl
src/main/php/com/selfcoders/phpcurl/Curl.php
Curl.enableVerboseOutput
public function enableVerboseOutput() { $this->verboseFileHandle = tmpfile(); $this->setOpt(CURLOPT_VERBOSE, true); $this->setOpt(CURLOPT_STDERR, $this->verboseFileHandle); }
php
public function enableVerboseOutput() { $this->verboseFileHandle = tmpfile(); $this->setOpt(CURLOPT_VERBOSE, true); $this->setOpt(CURLOPT_STDERR, $this->verboseFileHandle); }
[ "public", "function", "enableVerboseOutput", "(", ")", "{", "$", "this", "->", "verboseFileHandle", "=", "tmpfile", "(", ")", ";", "$", "this", "->", "setOpt", "(", "CURLOPT_VERBOSE", ",", "true", ")", ";", "$", "this", "->", "setOpt", "(", "CURLOPT_STDERR", ",", "$", "this", "->", "verboseFileHandle", ")", ";", "}" ]
Set all future requests of this instance to verbose mode. The content of the verbose output can be retrieved later using getVerboseContent.
[ "Set", "all", "future", "requests", "of", "this", "instance", "to", "verbose", "mode", "." ]
54ef8bba19e87654906f74b14646c1f322ea7241
https://github.com/Programie/PHPCurl/blob/54ef8bba19e87654906f74b14646c1f322ea7241/src/main/php/com/selfcoders/phpcurl/Curl.php#L278-L283
25,926
native5/native5-sdk-client-php
src/Native5/Identity/SecurityUtils.php
SecurityUtils.getSubject
public static function getSubject() { $logger = $GLOBALS['logger']; $app = $GLOBALS['app']; $subject = $app->getSubject(); $logger->debug('Subject authentication status = '.$subject->isAuthenticated()); if ($subject === null) { $subject = Subject::createBuilder()->build(); $app->setSubject($subject); } return $subject; }
php
public static function getSubject() { $logger = $GLOBALS['logger']; $app = $GLOBALS['app']; $subject = $app->getSubject(); $logger->debug('Subject authentication status = '.$subject->isAuthenticated()); if ($subject === null) { $subject = Subject::createBuilder()->build(); $app->setSubject($subject); } return $subject; }
[ "public", "static", "function", "getSubject", "(", ")", "{", "$", "logger", "=", "$", "GLOBALS", "[", "'logger'", "]", ";", "$", "app", "=", "$", "GLOBALS", "[", "'app'", "]", ";", "$", "subject", "=", "$", "app", "->", "getSubject", "(", ")", ";", "$", "logger", "->", "debug", "(", "'Subject authentication status = '", ".", "$", "subject", "->", "isAuthenticated", "(", ")", ")", ";", "if", "(", "$", "subject", "===", "null", ")", "{", "$", "subject", "=", "Subject", "::", "createBuilder", "(", ")", "->", "build", "(", ")", ";", "$", "app", "->", "setSubject", "(", "$", "subject", ")", ";", "}", "return", "$", "subject", ";", "}" ]
getSubject Convienience method to retrieve the subject. Subject is always retrieved from applicationContext. If no subject is found, then a new subject is created with default properties. @static @access public @return void
[ "getSubject", "Convienience", "method", "to", "retrieve", "the", "subject", ".", "Subject", "is", "always", "retrieved", "from", "applicationContext", ".", "If", "no", "subject", "is", "found", "then", "a", "new", "subject", "is", "created", "with", "default", "properties", "." ]
e1f598cf27654d81bb5facace1990b737242a2f9
https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Identity/SecurityUtils.php#L83-L96
25,927
Finesse/QueryScribe
src/Query.php
Query.table
public function table($table, string $alias = null): self { $table = $this->checkStringValue('Argument $table', $table); $this->table = $table; $this->tableAlias = $alias; return $this; }
php
public function table($table, string $alias = null): self { $table = $this->checkStringValue('Argument $table', $table); $this->table = $table; $this->tableAlias = $alias; return $this; }
[ "public", "function", "table", "(", "$", "table", ",", "string", "$", "alias", "=", "null", ")", ":", "self", "{", "$", "table", "=", "$", "this", "->", "checkStringValue", "(", "'Argument $table'", ",", "$", "table", ")", ";", "$", "this", "->", "table", "=", "$", "table", ";", "$", "this", "->", "tableAlias", "=", "$", "alias", ";", "return", "$", "this", ";", "}" ]
Sets the target table. @param string|\Closure|self|StatementInterface $table Not prefixed table name without quotes @param string|null $alias Table alias. Warning! Alias is not allowed in insert, update and delete queries in some of the DBMSs. @return $this @throws InvalidArgumentException @throws InvalidReturnValueException
[ "Sets", "the", "target", "table", "." ]
4edba721e37693780d142229b3ecb0cd4004c7a5
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L81-L88
25,928
Finesse/QueryScribe
src/Query.php
Query.getTableIdentifier
public function getTableIdentifier() { if ($this->tableAlias !== null) { return $this->tableAlias; } if (is_string($this->table)) { return $this->table; } return null; }
php
public function getTableIdentifier() { if ($this->tableAlias !== null) { return $this->tableAlias; } if (is_string($this->table)) { return $this->table; } return null; }
[ "public", "function", "getTableIdentifier", "(", ")", "{", "if", "(", "$", "this", "->", "tableAlias", "!==", "null", ")", "{", "return", "$", "this", "->", "tableAlias", ";", "}", "if", "(", "is_string", "(", "$", "this", "->", "table", ")", ")", "{", "return", "$", "this", "->", "table", ";", "}", "return", "null", ";", "}" ]
Returns the identifier which the target table can be appealed to. @return string|null Alias or table name. Null if the target table has no string name.
[ "Returns", "the", "identifier", "which", "the", "target", "table", "can", "be", "appealed", "to", "." ]
4edba721e37693780d142229b3ecb0cd4004c7a5
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L95-L104
25,929
Finesse/QueryScribe
src/Query.php
Query.addUpdate
public function addUpdate(array $values): self { foreach ($values as $column => $value) { if (!is_string($column)) { return $this->handleException(InvalidArgumentException::create( 'Argument $values indexes', $column, ['string'] )); } $value = $this->checkScalarOrNullValue('Argument $values['.$column.']', $value); $this->update[$column] = $value; } return $this; }
php
public function addUpdate(array $values): self { foreach ($values as $column => $value) { if (!is_string($column)) { return $this->handleException(InvalidArgumentException::create( 'Argument $values indexes', $column, ['string'] )); } $value = $this->checkScalarOrNullValue('Argument $values['.$column.']', $value); $this->update[$column] = $value; } return $this; }
[ "public", "function", "addUpdate", "(", "array", "$", "values", ")", ":", "self", "{", "foreach", "(", "$", "values", "as", "$", "column", "=>", "$", "value", ")", "{", "if", "(", "!", "is_string", "(", "$", "column", ")", ")", "{", "return", "$", "this", "->", "handleException", "(", "InvalidArgumentException", "::", "create", "(", "'Argument $values indexes'", ",", "$", "column", ",", "[", "'string'", "]", ")", ")", ";", "}", "$", "value", "=", "$", "this", "->", "checkScalarOrNullValue", "(", "'Argument $values['", ".", "$", "column", ".", "']'", ",", "$", "value", ")", ";", "$", "this", "->", "update", "[", "$", "column", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Adds values that should be updated @param mixed[]|\Closure[]|self[]|StatementInterface[] $values Fields to update. The indexes are the columns names, the values are the values. @return $this @throws InvalidArgumentException @throws InvalidReturnValueException
[ "Adds", "values", "that", "should", "be", "updated" ]
4edba721e37693780d142229b3ecb0cd4004c7a5
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L115-L131
25,930
Finesse/QueryScribe
src/Query.php
Query.makeEmptyCopy
public function makeEmptyCopy(): self { $query = $this->constructEmptyCopy(); $query->setClosureResolver($this->closureResolver); return $query; }
php
public function makeEmptyCopy(): self { $query = $this->constructEmptyCopy(); $query->setClosureResolver($this->closureResolver); return $query; }
[ "public", "function", "makeEmptyCopy", "(", ")", ":", "self", "{", "$", "query", "=", "$", "this", "->", "constructEmptyCopy", "(", ")", ";", "$", "query", "->", "setClosureResolver", "(", "$", "this", "->", "closureResolver", ")", ";", "return", "$", "query", ";", "}" ]
Makes an empty self copy with dependencies. @return static
[ "Makes", "an", "empty", "self", "copy", "with", "dependencies", "." ]
4edba721e37693780d142229b3ecb0cd4004c7a5
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L179-L184
25,931
Finesse/QueryScribe
src/Query.php
Query.makeCopyForCriteriaGroup
public function makeCopyForCriteriaGroup(): self { $query = $this->makeEmptyCopy(); $query->table = $this->table; $query->tableAlias = $this->tableAlias; return $query; }
php
public function makeCopyForCriteriaGroup(): self { $query = $this->makeEmptyCopy(); $query->table = $this->table; $query->tableAlias = $this->tableAlias; return $query; }
[ "public", "function", "makeCopyForCriteriaGroup", "(", ")", ":", "self", "{", "$", "query", "=", "$", "this", "->", "makeEmptyCopy", "(", ")", ";", "$", "query", "->", "table", "=", "$", "this", "->", "table", ";", "$", "query", "->", "tableAlias", "=", "$", "this", "->", "tableAlias", ";", "return", "$", "query", ";", "}" ]
Makes a self copy with dependencies for passing to a criteria group callback. @return static
[ "Makes", "a", "self", "copy", "with", "dependencies", "for", "passing", "to", "a", "criteria", "group", "callback", "." ]
4edba721e37693780d142229b3ecb0cd4004c7a5
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L201-L207
25,932
Finesse/QueryScribe
src/Query.php
Query.apply
public function apply(callable $transform): self { $result = $transform($this) ?? $this; if ($result instanceof self) { return $result; } return $this->handleException(InvalidReturnValueException::create( 'The transform function return value', $result, ['null', self::class] )); }
php
public function apply(callable $transform): self { $result = $transform($this) ?? $this; if ($result instanceof self) { return $result; } return $this->handleException(InvalidReturnValueException::create( 'The transform function return value', $result, ['null', self::class] )); }
[ "public", "function", "apply", "(", "callable", "$", "transform", ")", ":", "self", "{", "$", "result", "=", "$", "transform", "(", "$", "this", ")", "??", "$", "this", ";", "if", "(", "$", "result", "instanceof", "self", ")", "{", "return", "$", "result", ";", "}", "return", "$", "this", "->", "handleException", "(", "InvalidReturnValueException", "::", "create", "(", "'The transform function return value'", ",", "$", "result", ",", "[", "'null'", ",", "self", "::", "class", "]", ")", ")", ";", "}" ]
Modifies this query by passing it through a transform function. Warning! In contrast to the other methods, this method can both change this object and return a new object. The returned query is the only query guaranteed to be a proper result query. @param callable $transform The function. It recieves this query object as the first argument. It must either change the given object or return a new query object. @return static Result query object @throws InvalidReturnValueException If the callback return value is wrong
[ "Modifies", "this", "query", "by", "passing", "it", "through", "a", "transform", "function", "." ]
4edba721e37693780d142229b3ecb0cd4004c7a5
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L220-L233
25,933
Finesse/QueryScribe
src/Query.php
Query.checkStringValue
protected function checkStringValue(string $name, $value) { if ( !is_string($value) && !($value instanceof \Closure) && !($value instanceof self) && !($value instanceof StatementInterface) ) { return $this->handleException(InvalidArgumentException::create( $name, $value, ['string', \Closure::class, self::class, StatementInterface::class] )); } if ($value instanceof \Closure) { return $this->resolveSubQueryClosure($value); } return $value; }
php
protected function checkStringValue(string $name, $value) { if ( !is_string($value) && !($value instanceof \Closure) && !($value instanceof self) && !($value instanceof StatementInterface) ) { return $this->handleException(InvalidArgumentException::create( $name, $value, ['string', \Closure::class, self::class, StatementInterface::class] )); } if ($value instanceof \Closure) { return $this->resolveSubQueryClosure($value); } return $value; }
[ "protected", "function", "checkStringValue", "(", "string", "$", "name", ",", "$", "value", ")", "{", "if", "(", "!", "is_string", "(", "$", "value", ")", "&&", "!", "(", "$", "value", "instanceof", "\\", "Closure", ")", "&&", "!", "(", "$", "value", "instanceof", "self", ")", "&&", "!", "(", "$", "value", "instanceof", "StatementInterface", ")", ")", "{", "return", "$", "this", "->", "handleException", "(", "InvalidArgumentException", "::", "create", "(", "$", "name", ",", "$", "value", ",", "[", "'string'", ",", "\\", "Closure", "::", "class", ",", "self", "::", "class", ",", "StatementInterface", "::", "class", "]", ")", ")", ";", "}", "if", "(", "$", "value", "instanceof", "\\", "Closure", ")", "{", "return", "$", "this", "->", "resolveSubQueryClosure", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Check that value is suitable for being a "string or subquery" property of a query. Retrieves the closure subquery. @param string $name Value name @param string|\Closure|self|StatementInterface $value @return string|self|StatementInterface @throws InvalidArgumentException @throws InvalidReturnValueException
[ "Check", "that", "value", "is", "suitable", "for", "being", "a", "string", "or", "subquery", "property", "of", "a", "query", ".", "Retrieves", "the", "closure", "subquery", "." ]
4edba721e37693780d142229b3ecb0cd4004c7a5
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L256-L276
25,934
Finesse/QueryScribe
src/Query.php
Query.checkIntOrNullValue
protected function checkIntOrNullValue(string $name, $value) { if ( $value !== null && !is_numeric($value) && !($value instanceof \Closure) && !($value instanceof self) && !($value instanceof StatementInterface) ) { return $this->handleException(InvalidArgumentException::create( $name, $value, ['integer', \Closure::class, self::class, StatementInterface::class, 'null'] )); } if (is_numeric($value)) { $value = (int)$value; } elseif ($value instanceof \Closure) { return $this->resolveSubQueryClosure($value); } return $value; }
php
protected function checkIntOrNullValue(string $name, $value) { if ( $value !== null && !is_numeric($value) && !($value instanceof \Closure) && !($value instanceof self) && !($value instanceof StatementInterface) ) { return $this->handleException(InvalidArgumentException::create( $name, $value, ['integer', \Closure::class, self::class, StatementInterface::class, 'null'] )); } if (is_numeric($value)) { $value = (int)$value; } elseif ($value instanceof \Closure) { return $this->resolveSubQueryClosure($value); } return $value; }
[ "protected", "function", "checkIntOrNullValue", "(", "string", "$", "name", ",", "$", "value", ")", "{", "if", "(", "$", "value", "!==", "null", "&&", "!", "is_numeric", "(", "$", "value", ")", "&&", "!", "(", "$", "value", "instanceof", "\\", "Closure", ")", "&&", "!", "(", "$", "value", "instanceof", "self", ")", "&&", "!", "(", "$", "value", "instanceof", "StatementInterface", ")", ")", "{", "return", "$", "this", "->", "handleException", "(", "InvalidArgumentException", "::", "create", "(", "$", "name", ",", "$", "value", ",", "[", "'integer'", ",", "\\", "Closure", "::", "class", ",", "self", "::", "class", ",", "StatementInterface", "::", "class", ",", "'null'", "]", ")", ")", ";", "}", "if", "(", "is_numeric", "(", "$", "value", ")", ")", "{", "$", "value", "=", "(", "int", ")", "$", "value", ";", "}", "elseif", "(", "$", "value", "instanceof", "\\", "Closure", ")", "{", "return", "$", "this", "->", "resolveSubQueryClosure", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Check that value is suitable for being a "int or null or subquery" property of a query. Retrieves the closure subquery. @param string $name Value name @param int|\Closure|self|StatementInterface|null $value @return int|self|StatementInterface|null @throws InvalidArgumentException @throws InvalidReturnValueException
[ "Check", "that", "value", "is", "suitable", "for", "being", "a", "int", "or", "null", "or", "subquery", "property", "of", "a", "query", ".", "Retrieves", "the", "closure", "subquery", "." ]
4edba721e37693780d142229b3ecb0cd4004c7a5
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L288-L311
25,935
Finesse/QueryScribe
src/Query.php
Query.checkScalarOrNullValue
protected function checkScalarOrNullValue(string $name, $value) { if ( $value !== null && !is_scalar($value) && !($value instanceof \Closure) && !($value instanceof self) && !($value instanceof StatementInterface) ) { return $this->handleException(InvalidArgumentException::create( $name, $value, ['scalar', \Closure::class, self::class, StatementInterface::class, 'null'] )); } if ($value instanceof \Closure) { return $this->resolveSubQueryClosure($value); } return $value; }
php
protected function checkScalarOrNullValue(string $name, $value) { if ( $value !== null && !is_scalar($value) && !($value instanceof \Closure) && !($value instanceof self) && !($value instanceof StatementInterface) ) { return $this->handleException(InvalidArgumentException::create( $name, $value, ['scalar', \Closure::class, self::class, StatementInterface::class, 'null'] )); } if ($value instanceof \Closure) { return $this->resolveSubQueryClosure($value); } return $value; }
[ "protected", "function", "checkScalarOrNullValue", "(", "string", "$", "name", ",", "$", "value", ")", "{", "if", "(", "$", "value", "!==", "null", "&&", "!", "is_scalar", "(", "$", "value", ")", "&&", "!", "(", "$", "value", "instanceof", "\\", "Closure", ")", "&&", "!", "(", "$", "value", "instanceof", "self", ")", "&&", "!", "(", "$", "value", "instanceof", "StatementInterface", ")", ")", "{", "return", "$", "this", "->", "handleException", "(", "InvalidArgumentException", "::", "create", "(", "$", "name", ",", "$", "value", ",", "[", "'scalar'", ",", "\\", "Closure", "::", "class", ",", "self", "::", "class", ",", "StatementInterface", "::", "class", ",", "'null'", "]", ")", ")", ";", "}", "if", "(", "$", "value", "instanceof", "\\", "Closure", ")", "{", "return", "$", "this", "->", "resolveSubQueryClosure", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Check that value is suitable for being a "scalar or null or subquery" property of a query. Retrieves the closure subquery. @param string $name Value name @param mixed|\Closure|self|StatementInterface|null $value @return mixed|self|StatementInterface|null @throws InvalidArgumentException @throws InvalidReturnValueException
[ "Check", "that", "value", "is", "suitable", "for", "being", "a", "scalar", "or", "null", "or", "subquery", "property", "of", "a", "query", ".", "Retrieves", "the", "closure", "subquery", "." ]
4edba721e37693780d142229b3ecb0cd4004c7a5
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L323-L344
25,936
Finesse/QueryScribe
src/Query.php
Query.checkSubQueryValue
protected function checkSubQueryValue(string $name, $value) { if ( !($value instanceof \Closure) && !($value instanceof self) && !($value instanceof StatementInterface) ) { return $this->handleException(InvalidArgumentException::create( $name, $value, [\Closure::class, self::class, StatementInterface::class] )); } if ($value instanceof \Closure) { $value = $this->resolveSubQueryClosure($value); } return $value; }
php
protected function checkSubQueryValue(string $name, $value) { if ( !($value instanceof \Closure) && !($value instanceof self) && !($value instanceof StatementInterface) ) { return $this->handleException(InvalidArgumentException::create( $name, $value, [\Closure::class, self::class, StatementInterface::class] )); } if ($value instanceof \Closure) { $value = $this->resolveSubQueryClosure($value); } return $value; }
[ "protected", "function", "checkSubQueryValue", "(", "string", "$", "name", ",", "$", "value", ")", "{", "if", "(", "!", "(", "$", "value", "instanceof", "\\", "Closure", ")", "&&", "!", "(", "$", "value", "instanceof", "self", ")", "&&", "!", "(", "$", "value", "instanceof", "StatementInterface", ")", ")", "{", "return", "$", "this", "->", "handleException", "(", "InvalidArgumentException", "::", "create", "(", "$", "name", ",", "$", "value", ",", "[", "\\", "Closure", "::", "class", ",", "self", "::", "class", ",", "StatementInterface", "::", "class", "]", ")", ")", ";", "}", "if", "(", "$", "value", "instanceof", "\\", "Closure", ")", "{", "$", "value", "=", "$", "this", "->", "resolveSubQueryClosure", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Check that value is suitable for being a subquery property of a query. Retrieves the closure subquery. @param string $name Value name @param \Closure|self|StatementInterface $value @return self|StatementInterface @throws InvalidArgumentException @throws InvalidReturnValueException
[ "Check", "that", "value", "is", "suitable", "for", "being", "a", "subquery", "property", "of", "a", "query", ".", "Retrieves", "the", "closure", "subquery", "." ]
4edba721e37693780d142229b3ecb0cd4004c7a5
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L355-L374
25,937
Dhii/callback-abstract
src/CreateReflectionForCallableCapableTrait.php
CreateReflectionForCallableCapableTrait._createReflectionForCallable
protected function _createReflectionForCallable($callable) { $callable = $this->_normalizeCallable($callable); // String or closure means function if (is_string($callable) || ($callable instanceof Closure)) { return $this->_createReflectionFunction($callable); } // Otherwise array, which means method $object = $callable[0]; $class = is_string($object) ? $object : get_class($object); $method = $callable[1]; return $this->_createReflectionMethod($class, $method); }
php
protected function _createReflectionForCallable($callable) { $callable = $this->_normalizeCallable($callable); // String or closure means function if (is_string($callable) || ($callable instanceof Closure)) { return $this->_createReflectionFunction($callable); } // Otherwise array, which means method $object = $callable[0]; $class = is_string($object) ? $object : get_class($object); $method = $callable[1]; return $this->_createReflectionMethod($class, $method); }
[ "protected", "function", "_createReflectionForCallable", "(", "$", "callable", ")", "{", "$", "callable", "=", "$", "this", "->", "_normalizeCallable", "(", "$", "callable", ")", ";", "// String or closure means function", "if", "(", "is_string", "(", "$", "callable", ")", "||", "(", "$", "callable", "instanceof", "Closure", ")", ")", "{", "return", "$", "this", "->", "_createReflectionFunction", "(", "$", "callable", ")", ";", "}", "// Otherwise array, which means method", "$", "object", "=", "$", "callable", "[", "0", "]", ";", "$", "class", "=", "is_string", "(", "$", "object", ")", "?", "$", "object", ":", "get_class", "(", "$", "object", ")", ";", "$", "method", "=", "$", "callable", "[", "1", "]", ";", "return", "$", "this", "->", "_createReflectionMethod", "(", "$", "class", ",", "$", "method", ")", ";", "}" ]
Creates a reflection for the given callable. @since [*next-version*] @param callable|Stringable|array $callable The callable, or an object that represents a function FQN, or a callable-like array where the method is stringable. @throws InvalidArgumentException If the callable type is invalid. @throws OutOfRangeException If the callable format is wrong. @throws ReflectionException If a reflection could not be created. @return ReflectionFunction|ReflectionMethod The reflection.
[ "Creates", "a", "reflection", "for", "the", "given", "callable", "." ]
43ed4e99fc6ccdaf46a25d06da482a2fba8d9b19
https://github.com/Dhii/callback-abstract/blob/43ed4e99fc6ccdaf46a25d06da482a2fba8d9b19/src/CreateReflectionForCallableCapableTrait.php#L34-L49
25,938
horntell/php-sdk
lib/guzzle/GuzzleHttp/Subscriber/Mock.php
Mock.addMultiple
public function addMultiple(array $items) { foreach ($items as $item) { if ($item instanceof RequestException) { $this->addException($item); } else { $this->addResponse($item); } } }
php
public function addMultiple(array $items) { foreach ($items as $item) { if ($item instanceof RequestException) { $this->addException($item); } else { $this->addResponse($item); } } }
[ "public", "function", "addMultiple", "(", "array", "$", "items", ")", "{", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "if", "(", "$", "item", "instanceof", "RequestException", ")", "{", "$", "this", "->", "addException", "(", "$", "item", ")", ";", "}", "else", "{", "$", "this", "->", "addResponse", "(", "$", "item", ")", ";", "}", "}", "}" ]
Add multiple items to the queue @param array $items Items to add
[ "Add", "multiple", "items", "to", "the", "queue" ]
e5205e9396a21b754d5651a8aa5898da5922a1b7
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Subscriber/Mock.php#L125-L134
25,939
zetta-code/doctrine-util
src/Common/DebugSql.php
DebugSql.getParamsArray
private static function getParamsArray($paramObj) { $parameters = array(); foreach ($paramObj as $val) { /* @var $val \Doctrine\ORM\Query\Parameter */ $parameters[$val->getName()] = $val->getValue(); } return $parameters; }
php
private static function getParamsArray($paramObj) { $parameters = array(); foreach ($paramObj as $val) { /* @var $val \Doctrine\ORM\Query\Parameter */ $parameters[$val->getName()] = $val->getValue(); } return $parameters; }
[ "private", "static", "function", "getParamsArray", "(", "$", "paramObj", ")", "{", "$", "parameters", "=", "array", "(", ")", ";", "foreach", "(", "$", "paramObj", "as", "$", "val", ")", "{", "/* @var $val \\Doctrine\\ORM\\Query\\Parameter */", "$", "parameters", "[", "$", "val", "->", "getName", "(", ")", "]", "=", "$", "val", "->", "getValue", "(", ")", ";", "}", "return", "$", "parameters", ";", "}" ]
Get query params list @param ArrayCollection $paramObj @return array
[ "Get", "query", "params", "list" ]
40cf1d12c89001f85e68c7508d1b86fa1b90f00c
https://github.com/zetta-code/doctrine-util/blob/40cf1d12c89001f85e68c7508d1b86fa1b90f00c/src/Common/DebugSql.php#L26-L35
25,940
zetta-code/doctrine-util
src/Common/DebugSql.php
DebugSql.getFullSQL
public static function getFullSQL($query) { $sql = $query->getSql(); $paramsList = self::getListParamsByDql($query->getDql()); $paramsArr = self::getParamsArray($query->getParameters()); $fullSql = ''; for ($i = 0; $i < strlen($sql); $i++) { if ($sql[$i] == '?') { $nameParam = array_shift($paramsList); if (!isset($paramsArr[$nameParam])) { $fullSql .= ':' . $nameParam; } elseif (is_string($paramsArr[$nameParam])) { $fullSql .= '"' . addslashes($paramsArr[$nameParam]) . '"'; } elseif (is_array($paramsArr[$nameParam])) { $sqlArr = ''; foreach ($paramsArr[$nameParam] as $var) { if (!empty($sqlArr)) $sqlArr .= ','; if (is_string($var)) { $sqlArr .= '"' . addslashes($var) . '"'; } else $sqlArr .= $var; } $fullSql .= $sqlArr; } elseif (is_object($paramsArr[$nameParam])) { switch (get_class($paramsArr[$nameParam])) { case 'DateTime': $fullSql .= '\'' . $paramsArr[$nameParam]->format('Y-m-d H:i:s') . '\''; break; default: $fullSql .= $paramsArr[$nameParam]->getId(); } } else $fullSql .= $paramsArr[$nameParam]; } else { $fullSql .= $sql[$i]; } } return $fullSql; }
php
public static function getFullSQL($query) { $sql = $query->getSql(); $paramsList = self::getListParamsByDql($query->getDql()); $paramsArr = self::getParamsArray($query->getParameters()); $fullSql = ''; for ($i = 0; $i < strlen($sql); $i++) { if ($sql[$i] == '?') { $nameParam = array_shift($paramsList); if (!isset($paramsArr[$nameParam])) { $fullSql .= ':' . $nameParam; } elseif (is_string($paramsArr[$nameParam])) { $fullSql .= '"' . addslashes($paramsArr[$nameParam]) . '"'; } elseif (is_array($paramsArr[$nameParam])) { $sqlArr = ''; foreach ($paramsArr[$nameParam] as $var) { if (!empty($sqlArr)) $sqlArr .= ','; if (is_string($var)) { $sqlArr .= '"' . addslashes($var) . '"'; } else $sqlArr .= $var; } $fullSql .= $sqlArr; } elseif (is_object($paramsArr[$nameParam])) { switch (get_class($paramsArr[$nameParam])) { case 'DateTime': $fullSql .= '\'' . $paramsArr[$nameParam]->format('Y-m-d H:i:s') . '\''; break; default: $fullSql .= $paramsArr[$nameParam]->getId(); } } else $fullSql .= $paramsArr[$nameParam]; } else { $fullSql .= $sql[$i]; } } return $fullSql; }
[ "public", "static", "function", "getFullSQL", "(", "$", "query", ")", "{", "$", "sql", "=", "$", "query", "->", "getSql", "(", ")", ";", "$", "paramsList", "=", "self", "::", "getListParamsByDql", "(", "$", "query", "->", "getDql", "(", ")", ")", ";", "$", "paramsArr", "=", "self", "::", "getParamsArray", "(", "$", "query", "->", "getParameters", "(", ")", ")", ";", "$", "fullSql", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "strlen", "(", "$", "sql", ")", ";", "$", "i", "++", ")", "{", "if", "(", "$", "sql", "[", "$", "i", "]", "==", "'?'", ")", "{", "$", "nameParam", "=", "array_shift", "(", "$", "paramsList", ")", ";", "if", "(", "!", "isset", "(", "$", "paramsArr", "[", "$", "nameParam", "]", ")", ")", "{", "$", "fullSql", ".=", "':'", ".", "$", "nameParam", ";", "}", "elseif", "(", "is_string", "(", "$", "paramsArr", "[", "$", "nameParam", "]", ")", ")", "{", "$", "fullSql", ".=", "'\"'", ".", "addslashes", "(", "$", "paramsArr", "[", "$", "nameParam", "]", ")", ".", "'\"'", ";", "}", "elseif", "(", "is_array", "(", "$", "paramsArr", "[", "$", "nameParam", "]", ")", ")", "{", "$", "sqlArr", "=", "''", ";", "foreach", "(", "$", "paramsArr", "[", "$", "nameParam", "]", "as", "$", "var", ")", "{", "if", "(", "!", "empty", "(", "$", "sqlArr", ")", ")", "$", "sqlArr", ".=", "','", ";", "if", "(", "is_string", "(", "$", "var", ")", ")", "{", "$", "sqlArr", ".=", "'\"'", ".", "addslashes", "(", "$", "var", ")", ".", "'\"'", ";", "}", "else", "$", "sqlArr", ".=", "$", "var", ";", "}", "$", "fullSql", ".=", "$", "sqlArr", ";", "}", "elseif", "(", "is_object", "(", "$", "paramsArr", "[", "$", "nameParam", "]", ")", ")", "{", "switch", "(", "get_class", "(", "$", "paramsArr", "[", "$", "nameParam", "]", ")", ")", "{", "case", "'DateTime'", ":", "$", "fullSql", ".=", "'\\''", ".", "$", "paramsArr", "[", "$", "nameParam", "]", "->", "format", "(", "'Y-m-d H:i:s'", ")", ".", "'\\''", ";", "break", ";", "default", ":", "$", "fullSql", ".=", "$", "paramsArr", "[", "$", "nameParam", "]", "->", "getId", "(", ")", ";", "}", "}", "else", "$", "fullSql", ".=", "$", "paramsArr", "[", "$", "nameParam", "]", ";", "}", "else", "{", "$", "fullSql", ".=", "$", "sql", "[", "$", "i", "]", ";", "}", "}", "return", "$", "fullSql", ";", "}" ]
Get SQL from query @param \Doctrine\ORM\Query $query @return string
[ "Get", "SQL", "from", "query" ]
40cf1d12c89001f85e68c7508d1b86fa1b90f00c
https://github.com/zetta-code/doctrine-util/blob/40cf1d12c89001f85e68c7508d1b86fa1b90f00c/src/Common/DebugSql.php#L43-L86
25,941
koolkode/config
src/YamlConfigurationLoader.php
YamlConfigurationLoader.loadSource
protected function loadSource(\SplFileInfo $source, array $params = []) { $cfg = @file_get_contents($source->getPathname()); if($cfg === false) { throw new \RuntimeException(sprintf('Configuration source not found: "%s"', $source->getPathname())); } $replacements = []; foreach($params as $k => $v) { $replacements['%' . $k . '%'] = trim($v); } return trim(strtr($cfg, $replacements)); }
php
protected function loadSource(\SplFileInfo $source, array $params = []) { $cfg = @file_get_contents($source->getPathname()); if($cfg === false) { throw new \RuntimeException(sprintf('Configuration source not found: "%s"', $source->getPathname())); } $replacements = []; foreach($params as $k => $v) { $replacements['%' . $k . '%'] = trim($v); } return trim(strtr($cfg, $replacements)); }
[ "protected", "function", "loadSource", "(", "\\", "SplFileInfo", "$", "source", ",", "array", "$", "params", "=", "[", "]", ")", "{", "$", "cfg", "=", "@", "file_get_contents", "(", "$", "source", "->", "getPathname", "(", ")", ")", ";", "if", "(", "$", "cfg", "===", "false", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Configuration source not found: \"%s\"'", ",", "$", "source", "->", "getPathname", "(", ")", ")", ")", ";", "}", "$", "replacements", "=", "[", "]", ";", "foreach", "(", "$", "params", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "replacements", "[", "'%'", ".", "$", "k", ".", "'%'", "]", "=", "trim", "(", "$", "v", ")", ";", "}", "return", "trim", "(", "strtr", "(", "$", "cfg", ",", "$", "replacements", ")", ")", ";", "}" ]
Loads the contents of the given file and replaces %-delimited placeholders with the given values. @param \SplFileInfo $source @param array<string, mixed> $params @return string @throws \RuntimeException When the file could not be accessed.
[ "Loads", "the", "contents", "of", "the", "given", "file", "and", "replaces", "%", "-", "delimited", "placeholders", "with", "the", "given", "values", "." ]
ad97d80f6e4ae5f8925839488abf2d9bfcb6d7f6
https://github.com/koolkode/config/blob/ad97d80f6e4ae5f8925839488abf2d9bfcb6d7f6/src/YamlConfigurationLoader.php#L49-L66
25,942
SetBased/php-abc-language-resolver-core
src/CoreLanguageResolver.php
CoreLanguageResolver.resolveLanId
private function resolveLanId(): void { $codes = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? null); // If HTTP_ACCEPT_LANGUAGE is not set or empty return the default language. if (empty($codes)) $this->lanIdDefault; $map = Abc::$babel->getInternalLanguageMap(); // Try to find the language code. Examples: en, en-US, zh, zh-Hans. // BTW We assume HTTP_ACCEPT_LANGUAGE is sorted properly. foreach ($codes as &$code) { // The official language code for Dutch in the Netherlands is nl-NL (with hyphen). But in practice we encounter // nl_NL, nl_nl, nl-nl. Therefore, internal language codes are in lower case and with hyphen. // Remove sorting weight, replace underscore with dash, and convert to lower case. $code = strtolower(str_replace('_', '-', strtok($code, ';'))); if (isset($map[$code])) { $this->lanId = $map[$code]; return; } } // We did not find the language code. Try without county code. Examples: en, zh. foreach ($codes as $code) { $code = substr($code, 0, 2); if (isset($map[$code])) { $this->lanId = $map[$code]; return; } } // We did not find the language code. Use the ID of the default language. $this->lanId = $this->lanIdDefault; }
php
private function resolveLanId(): void { $codes = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? null); // If HTTP_ACCEPT_LANGUAGE is not set or empty return the default language. if (empty($codes)) $this->lanIdDefault; $map = Abc::$babel->getInternalLanguageMap(); // Try to find the language code. Examples: en, en-US, zh, zh-Hans. // BTW We assume HTTP_ACCEPT_LANGUAGE is sorted properly. foreach ($codes as &$code) { // The official language code for Dutch in the Netherlands is nl-NL (with hyphen). But in practice we encounter // nl_NL, nl_nl, nl-nl. Therefore, internal language codes are in lower case and with hyphen. // Remove sorting weight, replace underscore with dash, and convert to lower case. $code = strtolower(str_replace('_', '-', strtok($code, ';'))); if (isset($map[$code])) { $this->lanId = $map[$code]; return; } } // We did not find the language code. Try without county code. Examples: en, zh. foreach ($codes as $code) { $code = substr($code, 0, 2); if (isset($map[$code])) { $this->lanId = $map[$code]; return; } } // We did not find the language code. Use the ID of the default language. $this->lanId = $this->lanIdDefault; }
[ "private", "function", "resolveLanId", "(", ")", ":", "void", "{", "$", "codes", "=", "explode", "(", "','", ",", "$", "_SERVER", "[", "'HTTP_ACCEPT_LANGUAGE'", "]", "??", "null", ")", ";", "// If HTTP_ACCEPT_LANGUAGE is not set or empty return the default language.", "if", "(", "empty", "(", "$", "codes", ")", ")", "$", "this", "->", "lanIdDefault", ";", "$", "map", "=", "Abc", "::", "$", "babel", "->", "getInternalLanguageMap", "(", ")", ";", "// Try to find the language code. Examples: en, en-US, zh, zh-Hans.", "// BTW We assume HTTP_ACCEPT_LANGUAGE is sorted properly.", "foreach", "(", "$", "codes", "as", "&", "$", "code", ")", "{", "// The official language code for Dutch in the Netherlands is nl-NL (with hyphen). But in practice we encounter", "// nl_NL, nl_nl, nl-nl. Therefore, internal language codes are in lower case and with hyphen.", "// Remove sorting weight, replace underscore with dash, and convert to lower case.", "$", "code", "=", "strtolower", "(", "str_replace", "(", "'_'", ",", "'-'", ",", "strtok", "(", "$", "code", ",", "';'", ")", ")", ")", ";", "if", "(", "isset", "(", "$", "map", "[", "$", "code", "]", ")", ")", "{", "$", "this", "->", "lanId", "=", "$", "map", "[", "$", "code", "]", ";", "return", ";", "}", "}", "// We did not find the language code. Try without county code. Examples: en, zh.", "foreach", "(", "$", "codes", "as", "$", "code", ")", "{", "$", "code", "=", "substr", "(", "$", "code", ",", "0", ",", "2", ")", ";", "if", "(", "isset", "(", "$", "map", "[", "$", "code", "]", ")", ")", "{", "$", "this", "->", "lanId", "=", "$", "map", "[", "$", "code", "]", ";", "return", ";", "}", "}", "// We did not find the language code. Use the ID of the default language.", "$", "this", "->", "lanId", "=", "$", "this", "->", "lanIdDefault", ";", "}" ]
Resolves the ID of the language in which the response must be drafted.
[ "Resolves", "the", "ID", "of", "the", "language", "in", "which", "the", "response", "must", "be", "drafted", "." ]
122b76d75c89caa4b6ef2bcbae260eddd5c3d33a
https://github.com/SetBased/php-abc-language-resolver-core/blob/122b76d75c89caa4b6ef2bcbae260eddd5c3d33a/src/CoreLanguageResolver.php#L55-L97
25,943
praxigento/mobi_mod_downline
Plugin/Magento/Quote/Model/Quote.php
Quote.aroundGetCustomerGroupId
public function aroundGetCustomerGroupId( \Magento\Quote\Model\Quote $subject, \Closure $proceed ) { /* call parent to get group ID and to process other around-plugins */ $result = $proceed(); if ($result == \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID) { /* check referral code in registry for guest visitors */ $code = $this->hlpReferral->getReferralCode(); if ($code) { /* return referral group id if code exists */ $result = $this->hlpConfig->getReferralsGroupReferrals(); } } return $result; }
php
public function aroundGetCustomerGroupId( \Magento\Quote\Model\Quote $subject, \Closure $proceed ) { /* call parent to get group ID and to process other around-plugins */ $result = $proceed(); if ($result == \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID) { /* check referral code in registry for guest visitors */ $code = $this->hlpReferral->getReferralCode(); if ($code) { /* return referral group id if code exists */ $result = $this->hlpConfig->getReferralsGroupReferrals(); } } return $result; }
[ "public", "function", "aroundGetCustomerGroupId", "(", "\\", "Magento", "\\", "Quote", "\\", "Model", "\\", "Quote", "$", "subject", ",", "\\", "Closure", "$", "proceed", ")", "{", "/* call parent to get group ID and to process other around-plugins */", "$", "result", "=", "$", "proceed", "(", ")", ";", "if", "(", "$", "result", "==", "\\", "Magento", "\\", "Customer", "\\", "Model", "\\", "GroupManagement", "::", "NOT_LOGGED_IN_ID", ")", "{", "/* check referral code in registry for guest visitors */", "$", "code", "=", "$", "this", "->", "hlpReferral", "->", "getReferralCode", "(", ")", ";", "if", "(", "$", "code", ")", "{", "/* return referral group id if code exists */", "$", "result", "=", "$", "this", "->", "hlpConfig", "->", "getReferralsGroupReferrals", "(", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Replace NOT_LOGGED_IN group for referral customers. @param \Magento\Quote\Model\Quote $subject @param \Closure $proceed @return int|mixed
[ "Replace", "NOT_LOGGED_IN", "group", "for", "referral", "customers", "." ]
0f3c276dfff1aa029f9fd205ccfc56f207a2e75b
https://github.com/praxigento/mobi_mod_downline/blob/0f3c276dfff1aa029f9fd205ccfc56f207a2e75b/Plugin/Magento/Quote/Model/Quote.php#L35-L50
25,944
Mandarin-Medien/MMCmfRoutingBundle
EventListener/AutoNodeRouteUpdateListener.php
AutoNodeRouteUpdateListener.prePersist
public function prePersist(LifecycleEventArgs $args) { // update child routes $entity = $args->getEntity(); if ( $entity instanceof RoutableNodeInterface && $entity->hasAutoNodeRouteGeneration() ) { $routeManager = $this->container->get('mm_cmf_routing.node_route_manager'); $entity->addRoute($routeManager->generateAutoNodeRoute($entity)); } return; }
php
public function prePersist(LifecycleEventArgs $args) { // update child routes $entity = $args->getEntity(); if ( $entity instanceof RoutableNodeInterface && $entity->hasAutoNodeRouteGeneration() ) { $routeManager = $this->container->get('mm_cmf_routing.node_route_manager'); $entity->addRoute($routeManager->generateAutoNodeRoute($entity)); } return; }
[ "public", "function", "prePersist", "(", "LifecycleEventArgs", "$", "args", ")", "{", "// update child routes", "$", "entity", "=", "$", "args", "->", "getEntity", "(", ")", ";", "if", "(", "$", "entity", "instanceof", "RoutableNodeInterface", "&&", "$", "entity", "->", "hasAutoNodeRouteGeneration", "(", ")", ")", "{", "$", "routeManager", "=", "$", "this", "->", "container", "->", "get", "(", "'mm_cmf_routing.node_route_manager'", ")", ";", "$", "entity", "->", "addRoute", "(", "$", "routeManager", "->", "generateAutoNodeRoute", "(", "$", "entity", ")", ")", ";", "}", "return", ";", "}" ]
prePersist Event whenever a new Node is created, also create automatically a new NodeRoute @param LifecycleEventArgs $args
[ "prePersist", "Event", "whenever", "a", "new", "Node", "is", "created", "also", "create", "automatically", "a", "new", "NodeRoute" ]
7db1b03f5e120bd473486c0be6ab76c6146cd2d0
https://github.com/Mandarin-Medien/MMCmfRoutingBundle/blob/7db1b03f5e120bd473486c0be6ab76c6146cd2d0/EventListener/AutoNodeRouteUpdateListener.php#L41-L55
25,945
Mandarin-Medien/MMCmfRoutingBundle
EventListener/AutoNodeRouteUpdateListener.php
AutoNodeRouteUpdateListener.onFlush
public function onFlush(OnFlushEventArgs $args) { $unit = $args->getEntityManager()->getUnitOfWork(); $routeManager = $this->container->get('mm_cmf_routing.node_route_manager'); foreach($unit->getScheduledEntityUpdates() as $entity) { if( $entity instanceof RoutableNodeInterface && $entity->hasAutoNodeRouteGeneration() ) { $hasNodeRoute = false; $routeGenerated = false; foreach ($entity->getRoutes() as $route) { if($route instanceof AutoNodeRoute) { $hasNodeRoute = true; break; } } if(!$hasNodeRoute) { $routeManager = $this->container->get('mm_cmf_routing.node_route_manager'); $entity->addRoute($routeManager->generateAutoNodeRoute($entity)); $routeGenerated = true; } // check if Node::name has changed $changed = $unit->getEntityChangeSet($entity); if( array_key_exists('name', $changed) || array_key_exists('parent', $changed) || $routeGenerated ) { // update all child AutoNodeRoutes $routeManager->getAutoNodeRoutesRecursive($entity); $unit->computeChangeSets(); } } } }
php
public function onFlush(OnFlushEventArgs $args) { $unit = $args->getEntityManager()->getUnitOfWork(); $routeManager = $this->container->get('mm_cmf_routing.node_route_manager'); foreach($unit->getScheduledEntityUpdates() as $entity) { if( $entity instanceof RoutableNodeInterface && $entity->hasAutoNodeRouteGeneration() ) { $hasNodeRoute = false; $routeGenerated = false; foreach ($entity->getRoutes() as $route) { if($route instanceof AutoNodeRoute) { $hasNodeRoute = true; break; } } if(!$hasNodeRoute) { $routeManager = $this->container->get('mm_cmf_routing.node_route_manager'); $entity->addRoute($routeManager->generateAutoNodeRoute($entity)); $routeGenerated = true; } // check if Node::name has changed $changed = $unit->getEntityChangeSet($entity); if( array_key_exists('name', $changed) || array_key_exists('parent', $changed) || $routeGenerated ) { // update all child AutoNodeRoutes $routeManager->getAutoNodeRoutesRecursive($entity); $unit->computeChangeSets(); } } } }
[ "public", "function", "onFlush", "(", "OnFlushEventArgs", "$", "args", ")", "{", "$", "unit", "=", "$", "args", "->", "getEntityManager", "(", ")", "->", "getUnitOfWork", "(", ")", ";", "$", "routeManager", "=", "$", "this", "->", "container", "->", "get", "(", "'mm_cmf_routing.node_route_manager'", ")", ";", "foreach", "(", "$", "unit", "->", "getScheduledEntityUpdates", "(", ")", "as", "$", "entity", ")", "{", "if", "(", "$", "entity", "instanceof", "RoutableNodeInterface", "&&", "$", "entity", "->", "hasAutoNodeRouteGeneration", "(", ")", ")", "{", "$", "hasNodeRoute", "=", "false", ";", "$", "routeGenerated", "=", "false", ";", "foreach", "(", "$", "entity", "->", "getRoutes", "(", ")", "as", "$", "route", ")", "{", "if", "(", "$", "route", "instanceof", "AutoNodeRoute", ")", "{", "$", "hasNodeRoute", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "$", "hasNodeRoute", ")", "{", "$", "routeManager", "=", "$", "this", "->", "container", "->", "get", "(", "'mm_cmf_routing.node_route_manager'", ")", ";", "$", "entity", "->", "addRoute", "(", "$", "routeManager", "->", "generateAutoNodeRoute", "(", "$", "entity", ")", ")", ";", "$", "routeGenerated", "=", "true", ";", "}", "// check if Node::name has changed", "$", "changed", "=", "$", "unit", "->", "getEntityChangeSet", "(", "$", "entity", ")", ";", "if", "(", "array_key_exists", "(", "'name'", ",", "$", "changed", ")", "||", "array_key_exists", "(", "'parent'", ",", "$", "changed", ")", "||", "$", "routeGenerated", ")", "{", "// update all child AutoNodeRoutes", "$", "routeManager", "->", "getAutoNodeRoutesRecursive", "(", "$", "entity", ")", ";", "$", "unit", "->", "computeChangeSets", "(", ")", ";", "}", "}", "}", "}" ]
onFlush Event for persisting all NodeRoutes that needs an update @param OnFlushEventArgs $args
[ "onFlush", "Event", "for", "persisting", "all", "NodeRoutes", "that", "needs", "an", "update" ]
7db1b03f5e120bd473486c0be6ab76c6146cd2d0
https://github.com/Mandarin-Medien/MMCmfRoutingBundle/blob/7db1b03f5e120bd473486c0be6ab76c6146cd2d0/EventListener/AutoNodeRouteUpdateListener.php#L63-L106
25,946
TuumPHP/View
src/Renderer.php
Renderer.block
public function block($file, $data = []) { $block = clone($this); $block->layout_file = null; return $block->doRender($file, $data); }
php
public function block($file, $data = []) { $block = clone($this); $block->layout_file = null; return $block->doRender($file, $data); }
[ "public", "function", "block", "(", "$", "file", ",", "$", "data", "=", "[", "]", ")", "{", "$", "block", "=", "clone", "(", "$", "this", ")", ";", "$", "block", "->", "layout_file", "=", "null", ";", "return", "$", "block", "->", "doRender", "(", "$", "file", ",", "$", "data", ")", ";", "}" ]
render a block, without default layout. @param string $file @param array $data @return string
[ "render", "a", "block", "without", "default", "layout", "." ]
b82b20d7b8ee66b2bdbe4eb0d95fabd9bafe4b21
https://github.com/TuumPHP/View/blob/b82b20d7b8ee66b2bdbe4eb0d95fabd9bafe4b21/src/Renderer.php#L157-L162
25,947
OliverMonneke/pennePHP
src/Time/DateTime.php
DateTime.add
public function add($string) { $this->timestamp = $this->getTimestamp() + $this->evaluateDateString($string); return $this; }
php
public function add($string) { $this->timestamp = $this->getTimestamp() + $this->evaluateDateString($string); return $this; }
[ "public", "function", "add", "(", "$", "string", ")", "{", "$", "this", "->", "timestamp", "=", "$", "this", "->", "getTimestamp", "(", ")", "+", "$", "this", "->", "evaluateDateString", "(", "$", "string", ")", ";", "return", "$", "this", ";", "}" ]
Add a specific period @param string $string The period to add @return DateTime
[ "Add", "a", "specific", "period" ]
dd0de7944685a3f1947157e1254fc54b55ff9942
https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Time/DateTime.php#L94-L99
25,948
OliverMonneke/pennePHP
src/Time/DateTime.php
DateTime.sub
public function sub($string) { $this->timestamp = $this->getTimestamp() - $this->evaluateDateString($string); return $this; }
php
public function sub($string) { $this->timestamp = $this->getTimestamp() - $this->evaluateDateString($string); return $this; }
[ "public", "function", "sub", "(", "$", "string", ")", "{", "$", "this", "->", "timestamp", "=", "$", "this", "->", "getTimestamp", "(", ")", "-", "$", "this", "->", "evaluateDateString", "(", "$", "string", ")", ";", "return", "$", "this", ";", "}" ]
Subtract a specific period @param string $string The period @return DateTime
[ "Subtract", "a", "specific", "period" ]
dd0de7944685a3f1947157e1254fc54b55ff9942
https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Time/DateTime.php#L108-L113
25,949
OliverMonneke/pennePHP
src/Time/DateTime.php
DateTime.evaluateDateString
protected function evaluateDateString($string) { $seconds = 1; $matches = []; preg_match('/^([0-9]*)([s|M|h|d|m|y])$/', $string, $matches); switch ($matches[2]) { case 's': $seconds = $matches[1]; break; case 'M': $seconds = $this->evaluateDateString(60 * $matches[1] . 's'); break; case 'h': $seconds = $this->evaluateDateString(60 * $matches[1] . 'M'); break; case 'd': $seconds = $this->evaluateDateString(24 * $matches[1] . 'h'); break; case 'm': $seconds = $this->evaluateDateString(30 * $matches[1] . 'd'); break; case 'y': $seconds = $this->evaluateDateString(12 * $matches[1] . 'm'); break; } return $seconds; }
php
protected function evaluateDateString($string) { $seconds = 1; $matches = []; preg_match('/^([0-9]*)([s|M|h|d|m|y])$/', $string, $matches); switch ($matches[2]) { case 's': $seconds = $matches[1]; break; case 'M': $seconds = $this->evaluateDateString(60 * $matches[1] . 's'); break; case 'h': $seconds = $this->evaluateDateString(60 * $matches[1] . 'M'); break; case 'd': $seconds = $this->evaluateDateString(24 * $matches[1] . 'h'); break; case 'm': $seconds = $this->evaluateDateString(30 * $matches[1] . 'd'); break; case 'y': $seconds = $this->evaluateDateString(12 * $matches[1] . 'm'); break; } return $seconds; }
[ "protected", "function", "evaluateDateString", "(", "$", "string", ")", "{", "$", "seconds", "=", "1", ";", "$", "matches", "=", "[", "]", ";", "preg_match", "(", "'/^([0-9]*)([s|M|h|d|m|y])$/'", ",", "$", "string", ",", "$", "matches", ")", ";", "switch", "(", "$", "matches", "[", "2", "]", ")", "{", "case", "'s'", ":", "$", "seconds", "=", "$", "matches", "[", "1", "]", ";", "break", ";", "case", "'M'", ":", "$", "seconds", "=", "$", "this", "->", "evaluateDateString", "(", "60", "*", "$", "matches", "[", "1", "]", ".", "'s'", ")", ";", "break", ";", "case", "'h'", ":", "$", "seconds", "=", "$", "this", "->", "evaluateDateString", "(", "60", "*", "$", "matches", "[", "1", "]", ".", "'M'", ")", ";", "break", ";", "case", "'d'", ":", "$", "seconds", "=", "$", "this", "->", "evaluateDateString", "(", "24", "*", "$", "matches", "[", "1", "]", ".", "'h'", ")", ";", "break", ";", "case", "'m'", ":", "$", "seconds", "=", "$", "this", "->", "evaluateDateString", "(", "30", "*", "$", "matches", "[", "1", "]", ".", "'d'", ")", ";", "break", ";", "case", "'y'", ":", "$", "seconds", "=", "$", "this", "->", "evaluateDateString", "(", "12", "*", "$", "matches", "[", "1", "]", ".", "'m'", ")", ";", "break", ";", "}", "return", "$", "seconds", ";", "}" ]
Convert string to seconds @param string $string The string @return int
[ "Convert", "string", "to", "seconds" ]
dd0de7944685a3f1947157e1254fc54b55ff9942
https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Time/DateTime.php#L122-L150
25,950
eliasis-framework/wp-plugin-rating
src/controller/class-main.php
Main.get_plugin_rating
public function get_plugin_rating( $slug, $ratings = null ) { $ratings = $ratings ?: [ 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 1, ]; $plugins_url = Component::WP_Plugin_Rating()->getOption( 'url', 'wp-plugins' ); $url = $plugins_url . $slug . '/reviews/#new-post'; $data['plugin-url-review'] = $url; if ( Plugin::exists( 'WP_Plugin_Info' ) ) { $info = Plugin::WP_Plugin_Info()->getControllerInstance( 'Main' ); $rating = $info->get( 'ratings', $slug ); $ratings = ( false !== $rating ) ? $rating : $ratings; } $total = 0; $voters = array_sum( $ratings ); foreach ( $ratings as $stars => $votes ) { $total += $stars * $votes; } $rating = $total ? $total / $voters : 0; $data['stars'] = $this->prepare_stars( $rating ); $this->render( $data ); }
php
public function get_plugin_rating( $slug, $ratings = null ) { $ratings = $ratings ?: [ 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 1, ]; $plugins_url = Component::WP_Plugin_Rating()->getOption( 'url', 'wp-plugins' ); $url = $plugins_url . $slug . '/reviews/#new-post'; $data['plugin-url-review'] = $url; if ( Plugin::exists( 'WP_Plugin_Info' ) ) { $info = Plugin::WP_Plugin_Info()->getControllerInstance( 'Main' ); $rating = $info->get( 'ratings', $slug ); $ratings = ( false !== $rating ) ? $rating : $ratings; } $total = 0; $voters = array_sum( $ratings ); foreach ( $ratings as $stars => $votes ) { $total += $stars * $votes; } $rating = $total ? $total / $voters : 0; $data['stars'] = $this->prepare_stars( $rating ); $this->render( $data ); }
[ "public", "function", "get_plugin_rating", "(", "$", "slug", ",", "$", "ratings", "=", "null", ")", "{", "$", "ratings", "=", "$", "ratings", "?", ":", "[", "1", "=>", "0", ",", "2", "=>", "0", ",", "3", "=>", "0", ",", "4", "=>", "0", ",", "5", "=>", "1", ",", "]", ";", "$", "plugins_url", "=", "Component", "::", "WP_Plugin_Rating", "(", ")", "->", "getOption", "(", "'url'", ",", "'wp-plugins'", ")", ";", "$", "url", "=", "$", "plugins_url", ".", "$", "slug", ".", "'/reviews/#new-post'", ";", "$", "data", "[", "'plugin-url-review'", "]", "=", "$", "url", ";", "if", "(", "Plugin", "::", "exists", "(", "'WP_Plugin_Info'", ")", ")", "{", "$", "info", "=", "Plugin", "::", "WP_Plugin_Info", "(", ")", "->", "getControllerInstance", "(", "'Main'", ")", ";", "$", "rating", "=", "$", "info", "->", "get", "(", "'ratings'", ",", "$", "slug", ")", ";", "$", "ratings", "=", "(", "false", "!==", "$", "rating", ")", "?", "$", "rating", ":", "$", "ratings", ";", "}", "$", "total", "=", "0", ";", "$", "voters", "=", "array_sum", "(", "$", "ratings", ")", ";", "foreach", "(", "$", "ratings", "as", "$", "stars", "=>", "$", "votes", ")", "{", "$", "total", "+=", "$", "stars", "*", "$", "votes", ";", "}", "$", "rating", "=", "$", "total", "?", "$", "total", "/", "$", "voters", ":", "0", ";", "$", "data", "[", "'stars'", "]", "=", "$", "this", "->", "prepare_stars", "(", "$", "rating", ")", ";", "$", "this", "->", "render", "(", "$", "data", ")", ";", "}" ]
Get plugin Rating. @param string $slug → WordPress plugin slug. @param array $ratings → default ratings if plugin not exists.
[ "Get", "plugin", "Rating", "." ]
6fbdb0d5f83357d1de0c6796936c023cbdd33d4e
https://github.com/eliasis-framework/wp-plugin-rating/blob/6fbdb0d5f83357d1de0c6796936c023cbdd33d4e/src/controller/class-main.php#L30-L68
25,951
eliasis-framework/wp-plugin-rating
src/controller/class-main.php
Main.prepare_stars
protected function prepare_stars( $rating ) { $stars = []; $full_star = (int) floor( $rating ); $half_star = ( ( $rating - $full_star ) > 0 ) ? true : false; for ( $i = 0; $i < $full_star; $i++ ) { $stars[] = 'filled'; } if ( $half_star ) { $stars[] = 'half'; } for ( $i = 0; $i < ( 5 - $full_star ); $i++ ) { $stars[] = 'empty'; } return array_reverse( $stars ); }
php
protected function prepare_stars( $rating ) { $stars = []; $full_star = (int) floor( $rating ); $half_star = ( ( $rating - $full_star ) > 0 ) ? true : false; for ( $i = 0; $i < $full_star; $i++ ) { $stars[] = 'filled'; } if ( $half_star ) { $stars[] = 'half'; } for ( $i = 0; $i < ( 5 - $full_star ); $i++ ) { $stars[] = 'empty'; } return array_reverse( $stars ); }
[ "protected", "function", "prepare_stars", "(", "$", "rating", ")", "{", "$", "stars", "=", "[", "]", ";", "$", "full_star", "=", "(", "int", ")", "floor", "(", "$", "rating", ")", ";", "$", "half_star", "=", "(", "(", "$", "rating", "-", "$", "full_star", ")", ">", "0", ")", "?", "true", ":", "false", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "full_star", ";", "$", "i", "++", ")", "{", "$", "stars", "[", "]", "=", "'filled'", ";", "}", "if", "(", "$", "half_star", ")", "{", "$", "stars", "[", "]", "=", "'half'", ";", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "(", "5", "-", "$", "full_star", ")", ";", "$", "i", "++", ")", "{", "$", "stars", "[", "]", "=", "'empty'", ";", "}", "return", "array_reverse", "(", "$", "stars", ")", ";", "}" ]
Prepare states for each star. @param float|int $rating → plugin rating. @return array $rating → state for the five stars
[ "Prepare", "states", "for", "each", "star", "." ]
6fbdb0d5f83357d1de0c6796936c023cbdd33d4e
https://github.com/eliasis-framework/wp-plugin-rating/blob/6fbdb0d5f83357d1de0c6796936c023cbdd33d4e/src/controller/class-main.php#L77-L96
25,952
eliasis-framework/wp-plugin-rating
src/controller/class-main.php
Main.render
protected function render( $data ) { $template = Component::WP_Plugin_Rating()->getOption( 'path', 'template' ); $this->view->renderizate( $template, 'component', $data ); }
php
protected function render( $data ) { $template = Component::WP_Plugin_Rating()->getOption( 'path', 'template' ); $this->view->renderizate( $template, 'component', $data ); }
[ "protected", "function", "render", "(", "$", "data", ")", "{", "$", "template", "=", "Component", "::", "WP_Plugin_Rating", "(", ")", "->", "getOption", "(", "'path'", ",", "'template'", ")", ";", "$", "this", "->", "view", "->", "renderizate", "(", "$", "template", ",", "'component'", ",", "$", "data", ")", ";", "}" ]
Renderizate admin page. @param array $data → data to render in the view.
[ "Renderizate", "admin", "page", "." ]
6fbdb0d5f83357d1de0c6796936c023cbdd33d4e
https://github.com/eliasis-framework/wp-plugin-rating/blob/6fbdb0d5f83357d1de0c6796936c023cbdd33d4e/src/controller/class-main.php#L103-L108
25,953
ivopetkov/data-object
src/DataListToArrayTrait.php
DataListToArrayTrait.toArray
public function toArray(): array { $this->internalDataListUpdate(); // Copied from DataObjectToArrayTrait. Do not modify here !!! $toArray = function($object) use (&$toArray) { $result = []; $vars = get_object_vars($object); foreach ($vars as $name => $value) { if ($name !== 'internalDataObjectData') { $reflectionProperty = new \ReflectionProperty($object, $name); if ($reflectionProperty->isPublic()) { $result[$name] = null; } } } if (isset($object->internalDataObjectData)) { foreach ($object->internalDataObjectData as $name => $value) { $result[substr($name, 1)] = null; } } ksort($result); foreach ($result as $name => $null) { $value = $object instanceof \ArrayAccess ? $object[$name] : (isset($object->$name) ? $object->$name : null); if (is_object($value)) { if (method_exists($value, 'toArray')) { $result[$name] = $value->toArray(); } else { if ($value instanceof \DateTime) { $result[$name] = $value->format('c'); } else { $propertyVars = $toArray($value); foreach ($propertyVars as $propertyVarName => $propertyVarValue) { if (is_object($propertyVarValue)) { $propertyVars[$propertyVarName] = $toArray($propertyVarValue); } } $result[$name] = $propertyVars; } } } else { $result[$name] = $value; } } return $result; }; $result = []; foreach ($this->internalDataListData as $index => $object) { $object = $this->internalDataListUpdateValueIfNeeded($this->internalDataListData, $index); if (method_exists($object, 'toArray')) { $result[] = $object->toArray(); } else { $result[] = $toArray($object); } } return $result; }
php
public function toArray(): array { $this->internalDataListUpdate(); // Copied from DataObjectToArrayTrait. Do not modify here !!! $toArray = function($object) use (&$toArray) { $result = []; $vars = get_object_vars($object); foreach ($vars as $name => $value) { if ($name !== 'internalDataObjectData') { $reflectionProperty = new \ReflectionProperty($object, $name); if ($reflectionProperty->isPublic()) { $result[$name] = null; } } } if (isset($object->internalDataObjectData)) { foreach ($object->internalDataObjectData as $name => $value) { $result[substr($name, 1)] = null; } } ksort($result); foreach ($result as $name => $null) { $value = $object instanceof \ArrayAccess ? $object[$name] : (isset($object->$name) ? $object->$name : null); if (is_object($value)) { if (method_exists($value, 'toArray')) { $result[$name] = $value->toArray(); } else { if ($value instanceof \DateTime) { $result[$name] = $value->format('c'); } else { $propertyVars = $toArray($value); foreach ($propertyVars as $propertyVarName => $propertyVarValue) { if (is_object($propertyVarValue)) { $propertyVars[$propertyVarName] = $toArray($propertyVarValue); } } $result[$name] = $propertyVars; } } } else { $result[$name] = $value; } } return $result; }; $result = []; foreach ($this->internalDataListData as $index => $object) { $object = $this->internalDataListUpdateValueIfNeeded($this->internalDataListData, $index); if (method_exists($object, 'toArray')) { $result[] = $object->toArray(); } else { $result[] = $toArray($object); } } return $result; }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "$", "this", "->", "internalDataListUpdate", "(", ")", ";", "// Copied from DataObjectToArrayTrait. Do not modify here !!!", "$", "toArray", "=", "function", "(", "$", "object", ")", "use", "(", "&", "$", "toArray", ")", "{", "$", "result", "=", "[", "]", ";", "$", "vars", "=", "get_object_vars", "(", "$", "object", ")", ";", "foreach", "(", "$", "vars", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "$", "name", "!==", "'internalDataObjectData'", ")", "{", "$", "reflectionProperty", "=", "new", "\\", "ReflectionProperty", "(", "$", "object", ",", "$", "name", ")", ";", "if", "(", "$", "reflectionProperty", "->", "isPublic", "(", ")", ")", "{", "$", "result", "[", "$", "name", "]", "=", "null", ";", "}", "}", "}", "if", "(", "isset", "(", "$", "object", "->", "internalDataObjectData", ")", ")", "{", "foreach", "(", "$", "object", "->", "internalDataObjectData", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "result", "[", "substr", "(", "$", "name", ",", "1", ")", "]", "=", "null", ";", "}", "}", "ksort", "(", "$", "result", ")", ";", "foreach", "(", "$", "result", "as", "$", "name", "=>", "$", "null", ")", "{", "$", "value", "=", "$", "object", "instanceof", "\\", "ArrayAccess", "?", "$", "object", "[", "$", "name", "]", ":", "(", "isset", "(", "$", "object", "->", "$", "name", ")", "?", "$", "object", "->", "$", "name", ":", "null", ")", ";", "if", "(", "is_object", "(", "$", "value", ")", ")", "{", "if", "(", "method_exists", "(", "$", "value", ",", "'toArray'", ")", ")", "{", "$", "result", "[", "$", "name", "]", "=", "$", "value", "->", "toArray", "(", ")", ";", "}", "else", "{", "if", "(", "$", "value", "instanceof", "\\", "DateTime", ")", "{", "$", "result", "[", "$", "name", "]", "=", "$", "value", "->", "format", "(", "'c'", ")", ";", "}", "else", "{", "$", "propertyVars", "=", "$", "toArray", "(", "$", "value", ")", ";", "foreach", "(", "$", "propertyVars", "as", "$", "propertyVarName", "=>", "$", "propertyVarValue", ")", "{", "if", "(", "is_object", "(", "$", "propertyVarValue", ")", ")", "{", "$", "propertyVars", "[", "$", "propertyVarName", "]", "=", "$", "toArray", "(", "$", "propertyVarValue", ")", ";", "}", "}", "$", "result", "[", "$", "name", "]", "=", "$", "propertyVars", ";", "}", "}", "}", "else", "{", "$", "result", "[", "$", "name", "]", "=", "$", "value", ";", "}", "}", "return", "$", "result", ";", "}", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "internalDataListData", "as", "$", "index", "=>", "$", "object", ")", "{", "$", "object", "=", "$", "this", "->", "internalDataListUpdateValueIfNeeded", "(", "$", "this", "->", "internalDataListData", ",", "$", "index", ")", ";", "if", "(", "method_exists", "(", "$", "object", ",", "'toArray'", ")", ")", "{", "$", "result", "[", "]", "=", "$", "object", "->", "toArray", "(", ")", ";", "}", "else", "{", "$", "result", "[", "]", "=", "$", "toArray", "(", "$", "object", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns the list data converted as an array. @return array The list data converted as an array. @throws \InvalidArgumentException
[ "Returns", "the", "list", "data", "converted", "as", "an", "array", "." ]
024039017fd9e6e3aca6edbad79aaf45764b8991
https://github.com/ivopetkov/data-object/blob/024039017fd9e6e3aca6edbad79aaf45764b8991/src/DataListToArrayTrait.php#L24-L81
25,954
rrolt/activehelper
src/Digithis/Activehelper/Activehelper.php
Activehelper.link
public function link($routes, $url, $value = '', $attributes = array('class' => 'active')) { if(empty($value)) { $value = $url; } $output = '<a href="'.$url.'"'; if($this->is($routes)) { $output.= $this->putAttributes($attributes); } $output.= '>'.$value.'</a>'; return $output; }
php
public function link($routes, $url, $value = '', $attributes = array('class' => 'active')) { if(empty($value)) { $value = $url; } $output = '<a href="'.$url.'"'; if($this->is($routes)) { $output.= $this->putAttributes($attributes); } $output.= '>'.$value.'</a>'; return $output; }
[ "public", "function", "link", "(", "$", "routes", ",", "$", "url", ",", "$", "value", "=", "''", ",", "$", "attributes", "=", "array", "(", "'class'", "=>", "'active'", ")", ")", "{", "if", "(", "empty", "(", "$", "value", ")", ")", "{", "$", "value", "=", "$", "url", ";", "}", "$", "output", "=", "'<a href=\"'", ".", "$", "url", ".", "'\"'", ";", "if", "(", "$", "this", "->", "is", "(", "$", "routes", ")", ")", "{", "$", "output", ".=", "$", "this", "->", "putAttributes", "(", "$", "attributes", ")", ";", "}", "$", "output", ".=", "'>'", ".", "$", "value", ".", "'</a>'", ";", "return", "$", "output", ";", "}" ]
Generate link with active state. @param array $routes @param string $url @param string $value @param array $attributes @return string
[ "Generate", "link", "with", "active", "state", "." ]
eb29ef0aee8944a391be2b886579effb648e4909
https://github.com/rrolt/activehelper/blob/eb29ef0aee8944a391be2b886579effb648e4909/src/Digithis/Activehelper/Activehelper.php#L38-L55
25,955
rrolt/activehelper
src/Digithis/Activehelper/Activehelper.php
Activehelper.is
public function is() { $this->routes = array(); foreach(func_get_args() as $param) { if(!is_array($param)) { $this->routes[] = $param; continue; } foreach ($param as $p) { $this->routes[] = $p; } } $this->request = Request::path(); $this->parseRoutes(); foreach($this->routes as $route) { if(!Request::is($route)) { continue; } foreach($this->bad_routes as $bad_route) { if(str_is($bad_route, $this->request)) { return false; } } return true; } return false; }
php
public function is() { $this->routes = array(); foreach(func_get_args() as $param) { if(!is_array($param)) { $this->routes[] = $param; continue; } foreach ($param as $p) { $this->routes[] = $p; } } $this->request = Request::path(); $this->parseRoutes(); foreach($this->routes as $route) { if(!Request::is($route)) { continue; } foreach($this->bad_routes as $bad_route) { if(str_is($bad_route, $this->request)) { return false; } } return true; } return false; }
[ "public", "function", "is", "(", ")", "{", "$", "this", "->", "routes", "=", "array", "(", ")", ";", "foreach", "(", "func_get_args", "(", ")", "as", "$", "param", ")", "{", "if", "(", "!", "is_array", "(", "$", "param", ")", ")", "{", "$", "this", "->", "routes", "[", "]", "=", "$", "param", ";", "continue", ";", "}", "foreach", "(", "$", "param", "as", "$", "p", ")", "{", "$", "this", "->", "routes", "[", "]", "=", "$", "p", ";", "}", "}", "$", "this", "->", "request", "=", "Request", "::", "path", "(", ")", ";", "$", "this", "->", "parseRoutes", "(", ")", ";", "foreach", "(", "$", "this", "->", "routes", "as", "$", "route", ")", "{", "if", "(", "!", "Request", "::", "is", "(", "$", "route", ")", ")", "{", "continue", ";", "}", "foreach", "(", "$", "this", "->", "bad_routes", "as", "$", "bad_route", ")", "{", "if", "(", "str_is", "(", "$", "bad_route", ",", "$", "this", "->", "request", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
Get current state. @return boolean
[ "Get", "current", "state", "." ]
eb29ef0aee8944a391be2b886579effb648e4909
https://github.com/rrolt/activehelper/blob/eb29ef0aee8944a391be2b886579effb648e4909/src/Digithis/Activehelper/Activehelper.php#L62-L103
25,956
rrolt/activehelper
src/Digithis/Activehelper/Activehelper.php
Activehelper.parseRoutes
private function parseRoutes() { $this->bad_routes = array(); foreach($this->routes as $r => $route) { if (strpos($route, 'not:') !== false) { $bad_route = substr($route, strpos($route, "not:")+4); $this->bad_routes[] = $bad_route; unset($this->routes[$r]); } } }
php
private function parseRoutes() { $this->bad_routes = array(); foreach($this->routes as $r => $route) { if (strpos($route, 'not:') !== false) { $bad_route = substr($route, strpos($route, "not:")+4); $this->bad_routes[] = $bad_route; unset($this->routes[$r]); } } }
[ "private", "function", "parseRoutes", "(", ")", "{", "$", "this", "->", "bad_routes", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "routes", "as", "$", "r", "=>", "$", "route", ")", "{", "if", "(", "strpos", "(", "$", "route", ",", "'not:'", ")", "!==", "false", ")", "{", "$", "bad_route", "=", "substr", "(", "$", "route", ",", "strpos", "(", "$", "route", ",", "\"not:\"", ")", "+", "4", ")", ";", "$", "this", "->", "bad_routes", "[", "]", "=", "$", "bad_route", ";", "unset", "(", "$", "this", "->", "routes", "[", "$", "r", "]", ")", ";", "}", "}", "}" ]
Separate routes in clean routes and excluded routes. @param array $route @return void
[ "Separate", "routes", "in", "clean", "routes", "and", "excluded", "routes", "." ]
eb29ef0aee8944a391be2b886579effb648e4909
https://github.com/rrolt/activehelper/blob/eb29ef0aee8944a391be2b886579effb648e4909/src/Digithis/Activehelper/Activehelper.php#L126-L141
25,957
rrolt/activehelper
src/Digithis/Activehelper/Activehelper.php
Activehelper.putAttributes
private function putAttributes($attributes) { $output = ''; foreach($attributes as $attribute => $value) { $output.= ' '.$attribute. '="'.$value.'"'; } return $output; }
php
private function putAttributes($attributes) { $output = ''; foreach($attributes as $attribute => $value) { $output.= ' '.$attribute. '="'.$value.'"'; } return $output; }
[ "private", "function", "putAttributes", "(", "$", "attributes", ")", "{", "$", "output", "=", "''", ";", "foreach", "(", "$", "attributes", "as", "$", "attribute", "=>", "$", "value", ")", "{", "$", "output", ".=", "' '", ".", "$", "attribute", ".", "'=\"'", ".", "$", "value", ".", "'\"'", ";", "}", "return", "$", "output", ";", "}" ]
Attributes to string. @param array $attributes @return string
[ "Attributes", "to", "string", "." ]
eb29ef0aee8944a391be2b886579effb648e4909
https://github.com/rrolt/activehelper/blob/eb29ef0aee8944a391be2b886579effb648e4909/src/Digithis/Activehelper/Activehelper.php#L149-L159
25,958
Vectrex/vxPHP
src/File/FilesystemFile.php
FilesystemFile.getMimetype
public function getMimetype($force = false) { if(!isset($this->mimetype) || $force) { $this->mimetype = MimeTypeGetter::get($this->folder->getPath() . $this->filename); } return $this->mimetype; }
php
public function getMimetype($force = false) { if(!isset($this->mimetype) || $force) { $this->mimetype = MimeTypeGetter::get($this->folder->getPath() . $this->filename); } return $this->mimetype; }
[ "public", "function", "getMimetype", "(", "$", "force", "=", "false", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "mimetype", ")", "||", "$", "force", ")", "{", "$", "this", "->", "mimetype", "=", "MimeTypeGetter", "::", "get", "(", "$", "this", "->", "folder", "->", "getPath", "(", ")", ".", "$", "this", "->", "filename", ")", ";", "}", "return", "$", "this", "->", "mimetype", ";", "}" ]
retrieve mime type requires MimeTypeGetter @param bool $force forces re-read of mime type
[ "retrieve", "mime", "type", "requires", "MimeTypeGetter" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L102-L109
25,959
Vectrex/vxPHP
src/File/FilesystemFile.php
FilesystemFile.move
public function move(FilesystemFolder $destination) { // already in destination folder, nothing to do if($destination !== $this->folder) { $oldpath = $this->folder->getPath() . $this->filename; $newpath = $destination->getPath() . $this->filename; if(@rename($oldpath, $newpath)) { $this->clearCacheEntries(); // set new folder reference $this->folder = $destination; // re-read fileinfo $this->fileInfo = new \SplFileInfo($newpath); self::$instances[$newpath] = $this; unset(self::$instances[$oldpath]); // @todo: check necessity of chmod @chmod($newpath, 0666 & ~umask()); } else { throw new FilesystemFileException("Moving from '$oldpath' to '$newpath' failed.", FilesystemFileException::FILE_RENAME_FAILED); } } return $this; }
php
public function move(FilesystemFolder $destination) { // already in destination folder, nothing to do if($destination !== $this->folder) { $oldpath = $this->folder->getPath() . $this->filename; $newpath = $destination->getPath() . $this->filename; if(@rename($oldpath, $newpath)) { $this->clearCacheEntries(); // set new folder reference $this->folder = $destination; // re-read fileinfo $this->fileInfo = new \SplFileInfo($newpath); self::$instances[$newpath] = $this; unset(self::$instances[$oldpath]); // @todo: check necessity of chmod @chmod($newpath, 0666 & ~umask()); } else { throw new FilesystemFileException("Moving from '$oldpath' to '$newpath' failed.", FilesystemFileException::FILE_RENAME_FAILED); } } return $this; }
[ "public", "function", "move", "(", "FilesystemFolder", "$", "destination", ")", "{", "// already in destination folder, nothing to do", "if", "(", "$", "destination", "!==", "$", "this", "->", "folder", ")", "{", "$", "oldpath", "=", "$", "this", "->", "folder", "->", "getPath", "(", ")", ".", "$", "this", "->", "filename", ";", "$", "newpath", "=", "$", "destination", "->", "getPath", "(", ")", ".", "$", "this", "->", "filename", ";", "if", "(", "@", "rename", "(", "$", "oldpath", ",", "$", "newpath", ")", ")", "{", "$", "this", "->", "clearCacheEntries", "(", ")", ";", "// set new folder reference", "$", "this", "->", "folder", "=", "$", "destination", ";", "// re-read fileinfo", "$", "this", "->", "fileInfo", "=", "new", "\\", "SplFileInfo", "(", "$", "newpath", ")", ";", "self", "::", "$", "instances", "[", "$", "newpath", "]", "=", "$", "this", ";", "unset", "(", "self", "::", "$", "instances", "[", "$", "oldpath", "]", ")", ";", "// @todo: check necessity of chmod", "@", "chmod", "(", "$", "newpath", ",", "0666", "&", "~", "umask", "(", ")", ")", ";", "}", "else", "{", "throw", "new", "FilesystemFileException", "(", "\"Moving from '$oldpath' to '$newpath' failed.\"", ",", "FilesystemFileException", "::", "FILE_RENAME_FAILED", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
move file into new folder, orphaned cache entries are deleted, new cache entries are not generated @param FilesystemFolder $destination @return \vxPHP\File\FilesystemFile @throws FilesystemFileException
[ "move", "file", "into", "new", "folder", "orphaned", "cache", "entries", "are", "deleted", "new", "cache", "entries", "are", "not", "generated" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L220-L257
25,960
Vectrex/vxPHP
src/File/FilesystemFile.php
FilesystemFile.renameCacheEntries
protected function renameCacheEntries($to) { if(($cachePath = $this->folder->getCachePath(TRUE))) { $di = new \DirectoryIterator($cachePath); foreach($di as $fileinfo) { $filename = $fileinfo->getFilename(); if( $fileinfo->isDot() || !$fileinfo->isFile() || strpos($filename, $this->filename) !== 0 ) { continue; } $renamed = substr_replace($filename, $to, 0, strlen($this->filename)); rename($fileinfo->getRealPath(), $fileinfo->getPath() . DIRECTORY_SEPARATOR . $renamed); } } }
php
protected function renameCacheEntries($to) { if(($cachePath = $this->folder->getCachePath(TRUE))) { $di = new \DirectoryIterator($cachePath); foreach($di as $fileinfo) { $filename = $fileinfo->getFilename(); if( $fileinfo->isDot() || !$fileinfo->isFile() || strpos($filename, $this->filename) !== 0 ) { continue; } $renamed = substr_replace($filename, $to, 0, strlen($this->filename)); rename($fileinfo->getRealPath(), $fileinfo->getPath() . DIRECTORY_SEPARATOR . $renamed); } } }
[ "protected", "function", "renameCacheEntries", "(", "$", "to", ")", "{", "if", "(", "(", "$", "cachePath", "=", "$", "this", "->", "folder", "->", "getCachePath", "(", "TRUE", ")", ")", ")", "{", "$", "di", "=", "new", "\\", "DirectoryIterator", "(", "$", "cachePath", ")", ";", "foreach", "(", "$", "di", "as", "$", "fileinfo", ")", "{", "$", "filename", "=", "$", "fileinfo", "->", "getFilename", "(", ")", ";", "if", "(", "$", "fileinfo", "->", "isDot", "(", ")", "||", "!", "$", "fileinfo", "->", "isFile", "(", ")", "||", "strpos", "(", "$", "filename", ",", "$", "this", "->", "filename", ")", "!==", "0", ")", "{", "continue", ";", "}", "$", "renamed", "=", "substr_replace", "(", "$", "filename", ",", "$", "to", ",", "0", ",", "strlen", "(", "$", "this", "->", "filename", ")", ")", ";", "rename", "(", "$", "fileinfo", "->", "getRealPath", "(", ")", ",", "$", "fileinfo", "->", "getPath", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "renamed", ")", ";", "}", "}", "}" ]
updates names of cache entries @param string $to new filename
[ "updates", "names", "of", "cache", "entries" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L264-L285
25,961
Vectrex/vxPHP
src/File/FilesystemFile.php
FilesystemFile.delete
public function delete() { if(@unlink($this->getPath())) { $this->deleteCacheEntries(); self::unsetInstance($this->getPath()); } else { throw new FilesystemFileException("Delete of file '{$this->getPath()}' failed.", FilesystemFileException::FILE_DELETE_FAILED); } }
php
public function delete() { if(@unlink($this->getPath())) { $this->deleteCacheEntries(); self::unsetInstance($this->getPath()); } else { throw new FilesystemFileException("Delete of file '{$this->getPath()}' failed.", FilesystemFileException::FILE_DELETE_FAILED); } }
[ "public", "function", "delete", "(", ")", "{", "if", "(", "@", "unlink", "(", "$", "this", "->", "getPath", "(", ")", ")", ")", "{", "$", "this", "->", "deleteCacheEntries", "(", ")", ";", "self", "::", "unsetInstance", "(", "$", "this", "->", "getPath", "(", ")", ")", ";", "}", "else", "{", "throw", "new", "FilesystemFileException", "(", "\"Delete of file '{$this->getPath()}' failed.\"", ",", "FilesystemFileException", "::", "FILE_DELETE_FAILED", ")", ";", "}", "}" ]
deletes file and removes instance from lookup array @throws FilesystemFileException
[ "deletes", "file", "and", "removes", "instance", "from", "lookup", "array" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L291-L301
25,962
Vectrex/vxPHP
src/File/FilesystemFile.php
FilesystemFile.deleteCacheEntries
protected function deleteCacheEntries() { if(($cachePath = $this->folder->getCachePath(TRUE))) { $di = new \DirectoryIterator($cachePath); foreach($di as $fileinfo) { if( $fileinfo->isDot() || !$fileinfo->isFile() || strpos($fileinfo->getFilename(), $this->filename) !== 0 ) { continue; } unlink($fileinfo->getRealPath()); } } }
php
protected function deleteCacheEntries() { if(($cachePath = $this->folder->getCachePath(TRUE))) { $di = new \DirectoryIterator($cachePath); foreach($di as $fileinfo) { if( $fileinfo->isDot() || !$fileinfo->isFile() || strpos($fileinfo->getFilename(), $this->filename) !== 0 ) { continue; } unlink($fileinfo->getRealPath()); } } }
[ "protected", "function", "deleteCacheEntries", "(", ")", "{", "if", "(", "(", "$", "cachePath", "=", "$", "this", "->", "folder", "->", "getCachePath", "(", "TRUE", ")", ")", ")", "{", "$", "di", "=", "new", "\\", "DirectoryIterator", "(", "$", "cachePath", ")", ";", "foreach", "(", "$", "di", "as", "$", "fileinfo", ")", "{", "if", "(", "$", "fileinfo", "->", "isDot", "(", ")", "||", "!", "$", "fileinfo", "->", "isFile", "(", ")", "||", "strpos", "(", "$", "fileinfo", "->", "getFilename", "(", ")", ",", "$", "this", "->", "filename", ")", "!==", "0", ")", "{", "continue", ";", "}", "unlink", "(", "$", "fileinfo", "->", "getRealPath", "(", ")", ")", ";", "}", "}", "}" ]
cleans up cache entries associated with "original" file
[ "cleans", "up", "cache", "entries", "associated", "with", "original", "file" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L307-L324
25,963
Vectrex/vxPHP
src/File/FilesystemFile.php
FilesystemFile.getCacheInfo
public function getCacheInfo() { if(($cachePath = $this->folder->getCachePath(TRUE))) { $size = 0; $count = 0; $di = new \DirectoryIterator($cachePath); foreach($di as $fileinfo) { if( $fileinfo->isDot() || !$fileinfo->isFile() || strpos($fileinfo->getFilename(), $this->filename) !== 0 ) { continue; } ++$count; $size += $fileinfo->getSize(); } return ['count' => $count, 'totalSize' => $size]; } return FALSE; }
php
public function getCacheInfo() { if(($cachePath = $this->folder->getCachePath(TRUE))) { $size = 0; $count = 0; $di = new \DirectoryIterator($cachePath); foreach($di as $fileinfo) { if( $fileinfo->isDot() || !$fileinfo->isFile() || strpos($fileinfo->getFilename(), $this->filename) !== 0 ) { continue; } ++$count; $size += $fileinfo->getSize(); } return ['count' => $count, 'totalSize' => $size]; } return FALSE; }
[ "public", "function", "getCacheInfo", "(", ")", "{", "if", "(", "(", "$", "cachePath", "=", "$", "this", "->", "folder", "->", "getCachePath", "(", "TRUE", ")", ")", ")", "{", "$", "size", "=", "0", ";", "$", "count", "=", "0", ";", "$", "di", "=", "new", "\\", "DirectoryIterator", "(", "$", "cachePath", ")", ";", "foreach", "(", "$", "di", "as", "$", "fileinfo", ")", "{", "if", "(", "$", "fileinfo", "->", "isDot", "(", ")", "||", "!", "$", "fileinfo", "->", "isFile", "(", ")", "||", "strpos", "(", "$", "fileinfo", "->", "getFilename", "(", ")", ",", "$", "this", "->", "filename", ")", "!==", "0", ")", "{", "continue", ";", "}", "++", "$", "count", ";", "$", "size", "+=", "$", "fileinfo", "->", "getSize", "(", ")", ";", "}", "return", "[", "'count'", "=>", "$", "count", ",", "'totalSize'", "=>", "$", "size", "]", ";", "}", "return", "FALSE", ";", "}" ]
retrieve information about cached files @return array information
[ "retrieve", "information", "about", "cached", "files" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L339-L360
25,964
Vectrex/vxPHP
src/File/FilesystemFile.php
FilesystemFile.getFilesystemFilesInFolder
public static function getFilesystemFilesInFolder(FilesystemFolder $folder) { $files = []; $glob = glob($folder->getPath() . '*', GLOB_NOSORT); if($glob !== FALSE) { foreach($glob as $f) { if(!is_dir($f)) { if(!isset(self::$instances[$f])) { self::$instances[$f] = new self(basename($f), $folder); } $files[] = self::$instances[$f]; } } } return $files; }
php
public static function getFilesystemFilesInFolder(FilesystemFolder $folder) { $files = []; $glob = glob($folder->getPath() . '*', GLOB_NOSORT); if($glob !== FALSE) { foreach($glob as $f) { if(!is_dir($f)) { if(!isset(self::$instances[$f])) { self::$instances[$f] = new self(basename($f), $folder); } $files[] = self::$instances[$f]; } } } return $files; }
[ "public", "static", "function", "getFilesystemFilesInFolder", "(", "FilesystemFolder", "$", "folder", ")", "{", "$", "files", "=", "[", "]", ";", "$", "glob", "=", "glob", "(", "$", "folder", "->", "getPath", "(", ")", ".", "'*'", ",", "GLOB_NOSORT", ")", ";", "if", "(", "$", "glob", "!==", "FALSE", ")", "{", "foreach", "(", "$", "glob", "as", "$", "f", ")", "{", "if", "(", "!", "is_dir", "(", "$", "f", ")", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "instances", "[", "$", "f", "]", ")", ")", "{", "self", "::", "$", "instances", "[", "$", "f", "]", "=", "new", "self", "(", "basename", "(", "$", "f", ")", ",", "$", "folder", ")", ";", "}", "$", "files", "[", "]", "=", "self", "::", "$", "instances", "[", "$", "f", "]", ";", "}", "}", "}", "return", "$", "files", ";", "}" ]
return all filesystem files instances within a certain folder @param FilesystemFolder $folder @return Array filesystem files
[ "return", "all", "filesystem", "files", "instances", "within", "a", "certain", "folder" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L368-L389
25,965
squareproton/Bond
src/Bond/Pg/Result.php
Result.setFetchOptions
public function setFetchOptions( $fetchOptions ) { // set fetchOptions if( $fetchOptions === null ) { return $this->fetchOptions; } if( !is_integer($fetchOptions) ) { throw new BadTypeException( $fetchOptions, 'int' ); } $fetchOptions += $fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC ) ? 0 : self::TYPE_DEFAULT; $fetchOptions += $fetchOptions & ( self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT ) ? 0 : self::FLATTEN_DEFAULT; $fetchOptions += $fetchOptions & ( self::STYLE_ASSOC | self::STYLE_NUM ) ? 0 : self::STYLE_DEFAULT; $fetchOptions += $fetchOptions & ( self::FETCH_SINGLE | self::FETCH_MULTIPLE ) ? 0 : self::FETCH_DEFAULT; $fetchOptions += $fetchOptions & ( self::CACHE | self::CACHE_NOT ) ? 0 : self::CACHE_DEFAULT; // flatten $flatten = (bool) ( $fetchOptions & self::FLATTEN_IF_POSSIBLE ) && ( $this->numFields() === 1 ); $this->buildFetchCallback( $fetchOptions, $flatten ); $this->fetchOptions = $fetchOptions; return $this; }
php
public function setFetchOptions( $fetchOptions ) { // set fetchOptions if( $fetchOptions === null ) { return $this->fetchOptions; } if( !is_integer($fetchOptions) ) { throw new BadTypeException( $fetchOptions, 'int' ); } $fetchOptions += $fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC ) ? 0 : self::TYPE_DEFAULT; $fetchOptions += $fetchOptions & ( self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT ) ? 0 : self::FLATTEN_DEFAULT; $fetchOptions += $fetchOptions & ( self::STYLE_ASSOC | self::STYLE_NUM ) ? 0 : self::STYLE_DEFAULT; $fetchOptions += $fetchOptions & ( self::FETCH_SINGLE | self::FETCH_MULTIPLE ) ? 0 : self::FETCH_DEFAULT; $fetchOptions += $fetchOptions & ( self::CACHE | self::CACHE_NOT ) ? 0 : self::CACHE_DEFAULT; // flatten $flatten = (bool) ( $fetchOptions & self::FLATTEN_IF_POSSIBLE ) && ( $this->numFields() === 1 ); $this->buildFetchCallback( $fetchOptions, $flatten ); $this->fetchOptions = $fetchOptions; return $this; }
[ "public", "function", "setFetchOptions", "(", "$", "fetchOptions", ")", "{", "// set fetchOptions", "if", "(", "$", "fetchOptions", "===", "null", ")", "{", "return", "$", "this", "->", "fetchOptions", ";", "}", "if", "(", "!", "is_integer", "(", "$", "fetchOptions", ")", ")", "{", "throw", "new", "BadTypeException", "(", "$", "fetchOptions", ",", "'int'", ")", ";", "}", "$", "fetchOptions", "+=", "$", "fetchOptions", "&", "(", "self", "::", "TYPE_DETECT", "|", "self", "::", "TYPE_AGNOSTIC", ")", "?", "0", ":", "self", "::", "TYPE_DEFAULT", ";", "$", "fetchOptions", "+=", "$", "fetchOptions", "&", "(", "self", "::", "FLATTEN_IF_POSSIBLE", "|", "self", "::", "FLATTEN_PREVENT", ")", "?", "0", ":", "self", "::", "FLATTEN_DEFAULT", ";", "$", "fetchOptions", "+=", "$", "fetchOptions", "&", "(", "self", "::", "STYLE_ASSOC", "|", "self", "::", "STYLE_NUM", ")", "?", "0", ":", "self", "::", "STYLE_DEFAULT", ";", "$", "fetchOptions", "+=", "$", "fetchOptions", "&", "(", "self", "::", "FETCH_SINGLE", "|", "self", "::", "FETCH_MULTIPLE", ")", "?", "0", ":", "self", "::", "FETCH_DEFAULT", ";", "$", "fetchOptions", "+=", "$", "fetchOptions", "&", "(", "self", "::", "CACHE", "|", "self", "::", "CACHE_NOT", ")", "?", "0", ":", "self", "::", "CACHE_DEFAULT", ";", "// flatten", "$", "flatten", "=", "(", "bool", ")", "(", "$", "fetchOptions", "&", "self", "::", "FLATTEN_IF_POSSIBLE", ")", "&&", "(", "$", "this", "->", "numFields", "(", ")", "===", "1", ")", ";", "$", "this", "->", "buildFetchCallback", "(", "$", "fetchOptions", ",", "$", "flatten", ")", ";", "$", "this", "->", "fetchOptions", "=", "$", "fetchOptions", ";", "return", "$", "this", ";", "}" ]
Set the result fetchOptions @param int Bitmask @return Bond\Pg\Resource
[ "Set", "the", "result", "fetchOptions" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Result.php#L155-L181
25,966
squareproton/Bond
src/Bond/Pg/Result.php
Result.buildFetchCallback
private function buildFetchCallback( $fetchOptions, $flatten ) { $original = $this->fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM ); $new = $fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM ); // nothing has changed - don't need to change the callback if( $original === $new ) { return false; } // only fetch assoc if we're configured for it and we aren't flattening (which would destroy it anyway) $this->fetchType = ( $fetchOptions & self::STYLE_ASSOC and !$flatten ) ? PGSQL_ASSOC : PGSQL_NUM; // types and keys // determine types - this could be enabled to automatically convert types (to something other than a string) // off by default as the performance hit has yet to be determined if( $fetchOptions & self::TYPE_DETECT ) { $typeCallbacks = $this->getFieldTypeCallbacks(); if( $this->fetchType === PGSQL_ASSOC ) { $keys = array_keys( $typeCallbacks ); } else { $keys = range(0, count($typeCallbacks) - 1); } // flatten if( $flatten ) { $typeCallback = array_pop( $typeCallbacks ); $this->fetchCallback = function( $row ) use ( $keys, $typeCallback ) { return call_user_func( $typeCallback, $row[0] ); }; } else { $this->fetchCallback = function( $row ) use ( $keys, $typeCallbacks ) { return array_combine( $keys, array_map( 'call_user_func', $typeCallbacks, $row ) ); }; } } elseif( $flatten ) { $this->fetchCallback = function( $row ) { return array_shift( $row ); }; } else { $this->fetchCallback = function( $row ) { return $row; }; } return true; }
php
private function buildFetchCallback( $fetchOptions, $flatten ) { $original = $this->fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM ); $new = $fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM ); // nothing has changed - don't need to change the callback if( $original === $new ) { return false; } // only fetch assoc if we're configured for it and we aren't flattening (which would destroy it anyway) $this->fetchType = ( $fetchOptions & self::STYLE_ASSOC and !$flatten ) ? PGSQL_ASSOC : PGSQL_NUM; // types and keys // determine types - this could be enabled to automatically convert types (to something other than a string) // off by default as the performance hit has yet to be determined if( $fetchOptions & self::TYPE_DETECT ) { $typeCallbacks = $this->getFieldTypeCallbacks(); if( $this->fetchType === PGSQL_ASSOC ) { $keys = array_keys( $typeCallbacks ); } else { $keys = range(0, count($typeCallbacks) - 1); } // flatten if( $flatten ) { $typeCallback = array_pop( $typeCallbacks ); $this->fetchCallback = function( $row ) use ( $keys, $typeCallback ) { return call_user_func( $typeCallback, $row[0] ); }; } else { $this->fetchCallback = function( $row ) use ( $keys, $typeCallbacks ) { return array_combine( $keys, array_map( 'call_user_func', $typeCallbacks, $row ) ); }; } } elseif( $flatten ) { $this->fetchCallback = function( $row ) { return array_shift( $row ); }; } else { $this->fetchCallback = function( $row ) { return $row; }; } return true; }
[ "private", "function", "buildFetchCallback", "(", "$", "fetchOptions", ",", "$", "flatten", ")", "{", "$", "original", "=", "$", "this", "->", "fetchOptions", "&", "(", "self", "::", "TYPE_DETECT", "|", "self", "::", "TYPE_AGNOSTIC", "|", "self", "::", "FLATTEN_IF_POSSIBLE", "|", "self", "::", "FLATTEN_PREVENT", "|", "self", "::", "STYLE_ASSOC", "|", "self", "::", "STYLE_NUM", ")", ";", "$", "new", "=", "$", "fetchOptions", "&", "(", "self", "::", "TYPE_DETECT", "|", "self", "::", "TYPE_AGNOSTIC", "|", "self", "::", "FLATTEN_IF_POSSIBLE", "|", "self", "::", "FLATTEN_PREVENT", "|", "self", "::", "STYLE_ASSOC", "|", "self", "::", "STYLE_NUM", ")", ";", "// nothing has changed - don't need to change the callback", "if", "(", "$", "original", "===", "$", "new", ")", "{", "return", "false", ";", "}", "// only fetch assoc if we're configured for it and we aren't flattening (which would destroy it anyway)", "$", "this", "->", "fetchType", "=", "(", "$", "fetchOptions", "&", "self", "::", "STYLE_ASSOC", "and", "!", "$", "flatten", ")", "?", "PGSQL_ASSOC", ":", "PGSQL_NUM", ";", "// types and keys", "// determine types - this could be enabled to automatically convert types (to something other than a string)", "// off by default as the performance hit has yet to be determined", "if", "(", "$", "fetchOptions", "&", "self", "::", "TYPE_DETECT", ")", "{", "$", "typeCallbacks", "=", "$", "this", "->", "getFieldTypeCallbacks", "(", ")", ";", "if", "(", "$", "this", "->", "fetchType", "===", "PGSQL_ASSOC", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "typeCallbacks", ")", ";", "}", "else", "{", "$", "keys", "=", "range", "(", "0", ",", "count", "(", "$", "typeCallbacks", ")", "-", "1", ")", ";", "}", "// flatten", "if", "(", "$", "flatten", ")", "{", "$", "typeCallback", "=", "array_pop", "(", "$", "typeCallbacks", ")", ";", "$", "this", "->", "fetchCallback", "=", "function", "(", "$", "row", ")", "use", "(", "$", "keys", ",", "$", "typeCallback", ")", "{", "return", "call_user_func", "(", "$", "typeCallback", ",", "$", "row", "[", "0", "]", ")", ";", "}", ";", "}", "else", "{", "$", "this", "->", "fetchCallback", "=", "function", "(", "$", "row", ")", "use", "(", "$", "keys", ",", "$", "typeCallbacks", ")", "{", "return", "array_combine", "(", "$", "keys", ",", "array_map", "(", "'call_user_func'", ",", "$", "typeCallbacks", ",", "$", "row", ")", ")", ";", "}", ";", "}", "}", "elseif", "(", "$", "flatten", ")", "{", "$", "this", "->", "fetchCallback", "=", "function", "(", "$", "row", ")", "{", "return", "array_shift", "(", "$", "row", ")", ";", "}", ";", "}", "else", "{", "$", "this", "->", "fetchCallback", "=", "function", "(", "$", "row", ")", "{", "return", "$", "row", ";", "}", ";", "}", "return", "true", ";", "}" ]
Build a row processing callback based on the TYPE_DETECT and row flattening @param bool $flatten @return Callable
[ "Build", "a", "row", "processing", "callback", "based", "on", "the", "TYPE_DETECT", "and", "row", "flattening" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Result.php#L188-L249
25,967
squareproton/Bond
src/Bond/Pg/Result.php
Result.getFetchOptions
public function getFetchOptions( &$humanReadable = null ) { // aid to result fetching debugging // get fetch options in a human readable format if( func_num_args() ) { $humanReadable = []; $refl = new \ReflectionClass( __CLASS__ ); foreach( $refl->getConstants() as $name => $value ) { if( $value & $this->fetchOptions and strpos( $name, 'DEFAULT' ) === false ) { $humanReadable[] = $name; } } } return $this->fetchOptions; }
php
public function getFetchOptions( &$humanReadable = null ) { // aid to result fetching debugging // get fetch options in a human readable format if( func_num_args() ) { $humanReadable = []; $refl = new \ReflectionClass( __CLASS__ ); foreach( $refl->getConstants() as $name => $value ) { if( $value & $this->fetchOptions and strpos( $name, 'DEFAULT' ) === false ) { $humanReadable[] = $name; } } } return $this->fetchOptions; }
[ "public", "function", "getFetchOptions", "(", "&", "$", "humanReadable", "=", "null", ")", "{", "// aid to result fetching debugging", "// get fetch options in a human readable format", "if", "(", "func_num_args", "(", ")", ")", "{", "$", "humanReadable", "=", "[", "]", ";", "$", "refl", "=", "new", "\\", "ReflectionClass", "(", "__CLASS__", ")", ";", "foreach", "(", "$", "refl", "->", "getConstants", "(", ")", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "&", "$", "this", "->", "fetchOptions", "and", "strpos", "(", "$", "name", ",", "'DEFAULT'", ")", "===", "false", ")", "{", "$", "humanReadable", "[", "]", "=", "$", "name", ";", "}", "}", "}", "return", "$", "this", "->", "fetchOptions", ";", "}" ]
Return the bitmask @return
[ "Return", "the", "bitmask" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Result.php#L255-L269
25,968
squareproton/Bond
src/Bond/Pg/Result.php
Result.fetch
public function fetch( $options = null, $keyResultsByColumn = null ) { $this->setFetchOptions( $options ); // caching if( $this->fetchOptions & self::CACHE ) { // get a cache key for the passed options (we only care about those options that will modify the returned result) $cacheKey = $this->fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM | self::FETCH_SINGLE | self::FETCH_MULTIPLE ); if( isset( $this->cacheFetch[$cacheKey] ) ) { return $this->cacheFetch[$cacheKey]; } } // build output $output = array(); // build output array // slight repetition of code here to help us avoid the isset( $types ) check for every row (there might be a __lot__ of rows so this adds up). pg_result_seek( $this->resource, 0 ); if( null === $keyResultsByColumn ) { while( $row = pg_fetch_array( $this->resource, NULL, $this->fetchType ) ) { $output[] = call_user_func( $this->fetchCallback, $row ); } } else { while( $row = pg_fetch_array( $this->resource, NULL, $this->fetchType ) ) { $row = call_user_func( $this->fetchCallback, $row ); $output[$row[$keyResultsByColumn]] = $row; } } // populate the numRows cache as we've now got this information as standard if( !isset( $this->numRows ) ) { $this->numRows = count( $output ); } $this->fetchRowNumber = $this->numRows; // single result behaviour if( $this->fetchOptions & self::FETCH_SINGLE ) { if( $this->numRows() == 0 and $this->numFields() > 1 ) { $output = array(); } elseif( $this->numRows() <= 1 ) { $output = array_pop( $output ); // perhaps we should be returning a exception you call $singleResult and there is > 1 rows returned from the db } else { throw new MoreThanOneRowReturnedException( "{$this->numRows()} returned, FETCH_SINGLE doesn't apply here." ); } } // cache population if( isset($cacheKey) ) { $this->cacheFetch[$cacheKey] = $output; } return $output; }
php
public function fetch( $options = null, $keyResultsByColumn = null ) { $this->setFetchOptions( $options ); // caching if( $this->fetchOptions & self::CACHE ) { // get a cache key for the passed options (we only care about those options that will modify the returned result) $cacheKey = $this->fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM | self::FETCH_SINGLE | self::FETCH_MULTIPLE ); if( isset( $this->cacheFetch[$cacheKey] ) ) { return $this->cacheFetch[$cacheKey]; } } // build output $output = array(); // build output array // slight repetition of code here to help us avoid the isset( $types ) check for every row (there might be a __lot__ of rows so this adds up). pg_result_seek( $this->resource, 0 ); if( null === $keyResultsByColumn ) { while( $row = pg_fetch_array( $this->resource, NULL, $this->fetchType ) ) { $output[] = call_user_func( $this->fetchCallback, $row ); } } else { while( $row = pg_fetch_array( $this->resource, NULL, $this->fetchType ) ) { $row = call_user_func( $this->fetchCallback, $row ); $output[$row[$keyResultsByColumn]] = $row; } } // populate the numRows cache as we've now got this information as standard if( !isset( $this->numRows ) ) { $this->numRows = count( $output ); } $this->fetchRowNumber = $this->numRows; // single result behaviour if( $this->fetchOptions & self::FETCH_SINGLE ) { if( $this->numRows() == 0 and $this->numFields() > 1 ) { $output = array(); } elseif( $this->numRows() <= 1 ) { $output = array_pop( $output ); // perhaps we should be returning a exception you call $singleResult and there is > 1 rows returned from the db } else { throw new MoreThanOneRowReturnedException( "{$this->numRows()} returned, FETCH_SINGLE doesn't apply here." ); } } // cache population if( isset($cacheKey) ) { $this->cacheFetch[$cacheKey] = $output; } return $output; }
[ "public", "function", "fetch", "(", "$", "options", "=", "null", ",", "$", "keyResultsByColumn", "=", "null", ")", "{", "$", "this", "->", "setFetchOptions", "(", "$", "options", ")", ";", "// caching", "if", "(", "$", "this", "->", "fetchOptions", "&", "self", "::", "CACHE", ")", "{", "// get a cache key for the passed options (we only care about those options that will modify the returned result)", "$", "cacheKey", "=", "$", "this", "->", "fetchOptions", "&", "(", "self", "::", "TYPE_DETECT", "|", "self", "::", "TYPE_AGNOSTIC", "|", "self", "::", "FLATTEN_IF_POSSIBLE", "|", "self", "::", "FLATTEN_PREVENT", "|", "self", "::", "STYLE_ASSOC", "|", "self", "::", "STYLE_NUM", "|", "self", "::", "FETCH_SINGLE", "|", "self", "::", "FETCH_MULTIPLE", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "cacheFetch", "[", "$", "cacheKey", "]", ")", ")", "{", "return", "$", "this", "->", "cacheFetch", "[", "$", "cacheKey", "]", ";", "}", "}", "// build output", "$", "output", "=", "array", "(", ")", ";", "// build output array", "// slight repetition of code here to help us avoid the isset( $types ) check for every row (there might be a __lot__ of rows so this adds up).", "pg_result_seek", "(", "$", "this", "->", "resource", ",", "0", ")", ";", "if", "(", "null", "===", "$", "keyResultsByColumn", ")", "{", "while", "(", "$", "row", "=", "pg_fetch_array", "(", "$", "this", "->", "resource", ",", "NULL", ",", "$", "this", "->", "fetchType", ")", ")", "{", "$", "output", "[", "]", "=", "call_user_func", "(", "$", "this", "->", "fetchCallback", ",", "$", "row", ")", ";", "}", "}", "else", "{", "while", "(", "$", "row", "=", "pg_fetch_array", "(", "$", "this", "->", "resource", ",", "NULL", ",", "$", "this", "->", "fetchType", ")", ")", "{", "$", "row", "=", "call_user_func", "(", "$", "this", "->", "fetchCallback", ",", "$", "row", ")", ";", "$", "output", "[", "$", "row", "[", "$", "keyResultsByColumn", "]", "]", "=", "$", "row", ";", "}", "}", "// populate the numRows cache as we've now got this information as standard", "if", "(", "!", "isset", "(", "$", "this", "->", "numRows", ")", ")", "{", "$", "this", "->", "numRows", "=", "count", "(", "$", "output", ")", ";", "}", "$", "this", "->", "fetchRowNumber", "=", "$", "this", "->", "numRows", ";", "// single result behaviour", "if", "(", "$", "this", "->", "fetchOptions", "&", "self", "::", "FETCH_SINGLE", ")", "{", "if", "(", "$", "this", "->", "numRows", "(", ")", "==", "0", "and", "$", "this", "->", "numFields", "(", ")", ">", "1", ")", "{", "$", "output", "=", "array", "(", ")", ";", "}", "elseif", "(", "$", "this", "->", "numRows", "(", ")", "<=", "1", ")", "{", "$", "output", "=", "array_pop", "(", "$", "output", ")", ";", "// perhaps we should be returning a exception you call $singleResult and there is > 1 rows returned from the db", "}", "else", "{", "throw", "new", "MoreThanOneRowReturnedException", "(", "\"{$this->numRows()} returned, FETCH_SINGLE doesn't apply here.\"", ")", ";", "}", "}", "// cache population", "if", "(", "isset", "(", "$", "cacheKey", ")", ")", "{", "$", "this", "->", "cacheFetch", "[", "$", "cacheKey", "]", "=", "$", "output", ";", "}", "return", "$", "output", ";", "}" ]
Here be the magic! @param int Bitmask of the options @param mixed The column name we want our output to be keyed by @return mixed
[ "Here", "be", "the", "magic!" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Result.php#L277-L344
25,969
squareproton/Bond
src/Bond/Pg/Result.php
Result.getFieldTypeCallbacks
public function getFieldTypeCallbacks() { $types = array(); $numFields = $this->numFields(); for( $i = 0; $i < $numFields; $i++ ) { $types[pg_field_name( $this->resource, $i )] = TypeConversionFactory::get( pg_field_type( $this->resource, $i ), $this ); } return $types; }
php
public function getFieldTypeCallbacks() { $types = array(); $numFields = $this->numFields(); for( $i = 0; $i < $numFields; $i++ ) { $types[pg_field_name( $this->resource, $i )] = TypeConversionFactory::get( pg_field_type( $this->resource, $i ), $this ); } return $types; }
[ "public", "function", "getFieldTypeCallbacks", "(", ")", "{", "$", "types", "=", "array", "(", ")", ";", "$", "numFields", "=", "$", "this", "->", "numFields", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "numFields", ";", "$", "i", "++", ")", "{", "$", "types", "[", "pg_field_name", "(", "$", "this", "->", "resource", ",", "$", "i", ")", "]", "=", "TypeConversionFactory", "::", "get", "(", "pg_field_type", "(", "$", "this", "->", "resource", ",", "$", "i", ")", ",", "$", "this", ")", ";", "}", "return", "$", "types", ";", "}" ]
Return a array of php callbacks to be applied to a result set @param array $types
[ "Return", "a", "array", "of", "php", "callbacks", "to", "be", "applied", "to", "a", "result", "set" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Result.php#L350-L363
25,970
linpax/microphp-framework
src/cli/CliResolver.php
CliResolver.getOption
public function getOption($char = '', $name = '', $required = null) { if (!$char && !$name) { return false; } if ($char && (1 < strlen($char) || 1 !== preg_match('/^\w$/', $char))) { return false; } if ($name && (1 !== preg_match('/^\w+$/', $name))) { return false; } switch ($required) { case true: $char = $char ? $char.':' : $char; $name = $name ? $name.':' : $name; break; case false: $char = $char ? $char.'::' : $char; $name = $name ? $name.'::' : $name; break; } $argv = ($opts = getopt($char, [$name])) ? array_shift($opts) : []; return is_array($argv) ? array_shift($argv) : $argv; }
php
public function getOption($char = '', $name = '', $required = null) { if (!$char && !$name) { return false; } if ($char && (1 < strlen($char) || 1 !== preg_match('/^\w$/', $char))) { return false; } if ($name && (1 !== preg_match('/^\w+$/', $name))) { return false; } switch ($required) { case true: $char = $char ? $char.':' : $char; $name = $name ? $name.':' : $name; break; case false: $char = $char ? $char.'::' : $char; $name = $name ? $name.'::' : $name; break; } $argv = ($opts = getopt($char, [$name])) ? array_shift($opts) : []; return is_array($argv) ? array_shift($argv) : $argv; }
[ "public", "function", "getOption", "(", "$", "char", "=", "''", ",", "$", "name", "=", "''", ",", "$", "required", "=", "null", ")", "{", "if", "(", "!", "$", "char", "&&", "!", "$", "name", ")", "{", "return", "false", ";", "}", "if", "(", "$", "char", "&&", "(", "1", "<", "strlen", "(", "$", "char", ")", "||", "1", "!==", "preg_match", "(", "'/^\\w$/'", ",", "$", "char", ")", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "name", "&&", "(", "1", "!==", "preg_match", "(", "'/^\\w+$/'", ",", "$", "name", ")", ")", ")", "{", "return", "false", ";", "}", "switch", "(", "$", "required", ")", "{", "case", "true", ":", "$", "char", "=", "$", "char", "?", "$", "char", ".", "':'", ":", "$", "char", ";", "$", "name", "=", "$", "name", "?", "$", "name", ".", "':'", ":", "$", "name", ";", "break", ";", "case", "false", ":", "$", "char", "=", "$", "char", "?", "$", "char", ".", "'::'", ":", "$", "char", ";", "$", "name", "=", "$", "name", "?", "$", "name", ".", "'::'", ":", "$", "name", ";", "break", ";", "}", "$", "argv", "=", "(", "$", "opts", "=", "getopt", "(", "$", "char", ",", "[", "$", "name", "]", ")", ")", "?", "array_shift", "(", "$", "opts", ")", ":", "[", "]", ";", "return", "is_array", "(", "$", "argv", ")", "?", "array_shift", "(", "$", "argv", ")", ":", "$", "argv", ";", "}" ]
Get arguments from command line @access public @param string $char -a .. -z option char @param string $name --optionName_string @param bool|null $required Required value? @return mixed
[ "Get", "arguments", "from", "command", "line" ]
11f3370f3f64c516cce9b84ecd8276c6e9ae8df9
https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/cli/CliResolver.php#L58-L81
25,971
stubbles/stubbles-streams
src/main/php/filter/FilteredOutputStream.php
FilteredOutputStream.writeLines
public function writeLines(array $bytes): int { $bytesWritten = 0; foreach ($bytes as $line) { $bytesWritten += $this->writeLine($line); } return $bytesWritten; }
php
public function writeLines(array $bytes): int { $bytesWritten = 0; foreach ($bytes as $line) { $bytesWritten += $this->writeLine($line); } return $bytesWritten; }
[ "public", "function", "writeLines", "(", "array", "$", "bytes", ")", ":", "int", "{", "$", "bytesWritten", "=", "0", ";", "foreach", "(", "$", "bytes", "as", "$", "line", ")", "{", "$", "bytesWritten", "+=", "$", "this", "->", "writeLine", "(", "$", "line", ")", ";", "}", "return", "$", "bytesWritten", ";", "}" ]
writes given bytes and appends a line break after each one @param string[] $bytes @return int amount of written bytes @since 3.2.0
[ "writes", "given", "bytes", "and", "appends", "a", "line", "break", "after", "each", "one" ]
99b0dace5fcf71584d1456b4b5408017b896bdf5
https://github.com/stubbles/stubbles-streams/blob/99b0dace5fcf71584d1456b4b5408017b896bdf5/src/main/php/filter/FilteredOutputStream.php#L79-L87
25,972
gplcart/export
controllers/Settings.php
Settings.setDataEditSettings
protected function setDataEditSettings() { $header = $this->getData('settings.header'); if (is_array($header)) { $string = ''; foreach ($header as $key => $value) { $string .= "$key $value" . PHP_EOL; } $this->setData('settings.header', trim($string)); } }
php
protected function setDataEditSettings() { $header = $this->getData('settings.header'); if (is_array($header)) { $string = ''; foreach ($header as $key => $value) { $string .= "$key $value" . PHP_EOL; } $this->setData('settings.header', trim($string)); } }
[ "protected", "function", "setDataEditSettings", "(", ")", "{", "$", "header", "=", "$", "this", "->", "getData", "(", "'settings.header'", ")", ";", "if", "(", "is_array", "(", "$", "header", ")", ")", "{", "$", "string", "=", "''", ";", "foreach", "(", "$", "header", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "string", ".=", "\"$key $value\"", ".", "PHP_EOL", ";", "}", "$", "this", "->", "setData", "(", "'settings.header'", ",", "trim", "(", "$", "string", ")", ")", ";", "}", "}" ]
Prepare data before rendering
[ "Prepare", "data", "before", "rendering" ]
b4d93c7a2bd6653f12231fb30d36601ea00fc926
https://github.com/gplcart/export/blob/b4d93c7a2bd6653f12231fb30d36601ea00fc926/controllers/Settings.php#L37-L50
25,973
gplcart/export
controllers/Settings.php
Settings.validateHeaderSettings
protected function validateHeaderSettings() { $errors = $header = array(); $lines = gplcart_string_explode_multiline($this->getSubmitted('header', '')); foreach ($lines as $pos => $line) { $pos++; $data = array_filter(array_map('trim', explode(' ', $line, 2))); if (count($data) != 2) { $errors[] = $pos; continue; } list($key, $label) = $data; if (preg_match('/^[a-z_]+$/', $key) !== 1) { $errors[] = $pos; continue; } $header[$key] = $label; } if (empty($errors)) { $this->setSubmitted('header', $header); } else { $vars = array('@num' => implode(',', $errors)); $this->setError('header', $this->text('Error on line @num', $vars)); } }
php
protected function validateHeaderSettings() { $errors = $header = array(); $lines = gplcart_string_explode_multiline($this->getSubmitted('header', '')); foreach ($lines as $pos => $line) { $pos++; $data = array_filter(array_map('trim', explode(' ', $line, 2))); if (count($data) != 2) { $errors[] = $pos; continue; } list($key, $label) = $data; if (preg_match('/^[a-z_]+$/', $key) !== 1) { $errors[] = $pos; continue; } $header[$key] = $label; } if (empty($errors)) { $this->setSubmitted('header', $header); } else { $vars = array('@num' => implode(',', $errors)); $this->setError('header', $this->text('Error on line @num', $vars)); } }
[ "protected", "function", "validateHeaderSettings", "(", ")", "{", "$", "errors", "=", "$", "header", "=", "array", "(", ")", ";", "$", "lines", "=", "gplcart_string_explode_multiline", "(", "$", "this", "->", "getSubmitted", "(", "'header'", ",", "''", ")", ")", ";", "foreach", "(", "$", "lines", "as", "$", "pos", "=>", "$", "line", ")", "{", "$", "pos", "++", ";", "$", "data", "=", "array_filter", "(", "array_map", "(", "'trim'", ",", "explode", "(", "' '", ",", "$", "line", ",", "2", ")", ")", ")", ";", "if", "(", "count", "(", "$", "data", ")", "!=", "2", ")", "{", "$", "errors", "[", "]", "=", "$", "pos", ";", "continue", ";", "}", "list", "(", "$", "key", ",", "$", "label", ")", "=", "$", "data", ";", "if", "(", "preg_match", "(", "'/^[a-z_]+$/'", ",", "$", "key", ")", "!==", "1", ")", "{", "$", "errors", "[", "]", "=", "$", "pos", ";", "continue", ";", "}", "$", "header", "[", "$", "key", "]", "=", "$", "label", ";", "}", "if", "(", "empty", "(", "$", "errors", ")", ")", "{", "$", "this", "->", "setSubmitted", "(", "'header'", ",", "$", "header", ")", ";", "}", "else", "{", "$", "vars", "=", "array", "(", "'@num'", "=>", "implode", "(", "','", ",", "$", "errors", ")", ")", ";", "$", "this", "->", "setError", "(", "'header'", ",", "$", "this", "->", "text", "(", "'Error on line @num'", ",", "$", "vars", ")", ")", ";", "}", "}" ]
Validate header mapping
[ "Validate", "header", "mapping" ]
b4d93c7a2bd6653f12231fb30d36601ea00fc926
https://github.com/gplcart/export/blob/b4d93c7a2bd6653f12231fb30d36601ea00fc926/controllers/Settings.php#L113-L144
25,974
sndsgd/http
src/http/request/BodyDecoder.php
BodyDecoder.addDecoder
public static function addDecoder(string $class, string ...$contentTypes) { $interface = decoder\DecoderInterface::class; if (!is_subclass_of($class, $interface)) { throw new \InvalidArgumentException( "invalid value provided for 'class'; ". "expecting the name of a class that implements '$interface'" ); } foreach ($contentTypes as $type) { static::$decoders[$class] = $type; } }
php
public static function addDecoder(string $class, string ...$contentTypes) { $interface = decoder\DecoderInterface::class; if (!is_subclass_of($class, $interface)) { throw new \InvalidArgumentException( "invalid value provided for 'class'; ". "expecting the name of a class that implements '$interface'" ); } foreach ($contentTypes as $type) { static::$decoders[$class] = $type; } }
[ "public", "static", "function", "addDecoder", "(", "string", "$", "class", ",", "string", "...", "$", "contentTypes", ")", "{", "$", "interface", "=", "decoder", "\\", "DecoderInterface", "::", "class", ";", "if", "(", "!", "is_subclass_of", "(", "$", "class", ",", "$", "interface", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"invalid value provided for 'class'; \"", ".", "\"expecting the name of a class that implements '$interface'\"", ")", ";", "}", "foreach", "(", "$", "contentTypes", "as", "$", "type", ")", "{", "static", "::", "$", "decoders", "[", "$", "class", "]", "=", "$", "type", ";", "}", "}" ]
Replace existing decoders, or add additional decoders @param string $class The nme of the decoder class @param string ...$contentTypes The content types the decoder can handle
[ "Replace", "existing", "decoders", "or", "add", "additional", "decoders" ]
e7f82010a66c6d3241a24ea82baf4593130c723b
https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/request/BodyDecoder.php#L27-L40
25,975
sndsgd/http
src/http/request/BodyDecoder.php
BodyDecoder.getDecoder
protected function getDecoder( string $stream, string $contentType, int $contentLength, decoder\DecoderOptions $options ) { $type = \sndsgd\Str::before($contentType, ";"); if (!isset(static::$decoders[$type])) { throw new exception\BadRequestException( "failed to decode request body; ". "unknown content-type '$contentType'" ); } $class = static::$decoders[$type]; return new $class($stream, $contentType, $contentLength, $options); }
php
protected function getDecoder( string $stream, string $contentType, int $contentLength, decoder\DecoderOptions $options ) { $type = \sndsgd\Str::before($contentType, ";"); if (!isset(static::$decoders[$type])) { throw new exception\BadRequestException( "failed to decode request body; ". "unknown content-type '$contentType'" ); } $class = static::$decoders[$type]; return new $class($stream, $contentType, $contentLength, $options); }
[ "protected", "function", "getDecoder", "(", "string", "$", "stream", ",", "string", "$", "contentType", ",", "int", "$", "contentLength", ",", "decoder", "\\", "DecoderOptions", "$", "options", ")", "{", "$", "type", "=", "\\", "sndsgd", "\\", "Str", "::", "before", "(", "$", "contentType", ",", "\";\"", ")", ";", "if", "(", "!", "isset", "(", "static", "::", "$", "decoders", "[", "$", "type", "]", ")", ")", "{", "throw", "new", "exception", "\\", "BadRequestException", "(", "\"failed to decode request body; \"", ".", "\"unknown content-type '$contentType'\"", ")", ";", "}", "$", "class", "=", "static", "::", "$", "decoders", "[", "$", "type", "]", ";", "return", "new", "$", "class", "(", "$", "stream", ",", "$", "contentType", ",", "$", "contentLength", ",", "$", "options", ")", ";", "}" ]
Stubbable method for creating a decoder instance @param string $stream @param string $contentType @param int $contentLength @param \sndsgd\http\data\DecoderOptions $options @return \sndsgd\http\data\decoder\DecoderInterface @throws \sndsgd\http\exception\BadRequestException
[ "Stubbable", "method", "for", "creating", "a", "decoder", "instance" ]
e7f82010a66c6d3241a24ea82baf4593130c723b
https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/request/BodyDecoder.php#L81-L98
25,976
ezra-obiwale/dSCore
src/Form/Filterer.php
Filterer.checkMessage
private function checkMessage($defMsg, array $options) { if (is_array($options) && isset($options['message'])) return $options['message'] ? $options['message'] : null; return $defMsg; }
php
private function checkMessage($defMsg, array $options) { if (is_array($options) && isset($options['message'])) return $options['message'] ? $options['message'] : null; return $defMsg; }
[ "private", "function", "checkMessage", "(", "$", "defMsg", ",", "array", "$", "options", ")", "{", "if", "(", "is_array", "(", "$", "options", ")", "&&", "isset", "(", "$", "options", "[", "'message'", "]", ")", ")", "return", "$", "options", "[", "'message'", "]", "?", "$", "options", "[", "'message'", "]", ":", "null", ";", "return", "$", "defMsg", ";", "}" ]
Checks if a custom message exists or returns the default @param string $defMsg Default message of the filter @param array $options Element filter Options @return string
[ "Checks", "if", "a", "custom", "message", "exists", "or", "returns", "the", "default" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Filterer.php#L75-L80
25,977
ezra-obiwale/dSCore
src/Form/Filterer.php
Filterer.required
public function required($options) { if ((is_array($options) || (!is_array($options) && $options))) { if ((is_array($this->elementData) && (empty($this->elementData) || (empty($this->elementData[0]) && count($this->elementData) === 1))) || (!is_array($this->elementData) && trim($this->elementData) === '')) { if (is_bool($options)) $this->addError('Field is required'); else if (is_array($options) && isset($options['message'])) { $this->addError($options['message']); } else $this->addError((!is_array($options) && !is_object($options)) ? $options : 'Field is required'); return false; } return true; } return true; }
php
public function required($options) { if ((is_array($options) || (!is_array($options) && $options))) { if ((is_array($this->elementData) && (empty($this->elementData) || (empty($this->elementData[0]) && count($this->elementData) === 1))) || (!is_array($this->elementData) && trim($this->elementData) === '')) { if (is_bool($options)) $this->addError('Field is required'); else if (is_array($options) && isset($options['message'])) { $this->addError($options['message']); } else $this->addError((!is_array($options) && !is_object($options)) ? $options : 'Field is required'); return false; } return true; } return true; }
[ "public", "function", "required", "(", "$", "options", ")", "{", "if", "(", "(", "is_array", "(", "$", "options", ")", "||", "(", "!", "is_array", "(", "$", "options", ")", "&&", "$", "options", ")", ")", ")", "{", "if", "(", "(", "is_array", "(", "$", "this", "->", "elementData", ")", "&&", "(", "empty", "(", "$", "this", "->", "elementData", ")", "||", "(", "empty", "(", "$", "this", "->", "elementData", "[", "0", "]", ")", "&&", "count", "(", "$", "this", "->", "elementData", ")", "===", "1", ")", ")", ")", "||", "(", "!", "is_array", "(", "$", "this", "->", "elementData", ")", "&&", "trim", "(", "$", "this", "->", "elementData", ")", "===", "''", ")", ")", "{", "if", "(", "is_bool", "(", "$", "options", ")", ")", "$", "this", "->", "addError", "(", "'Field is required'", ")", ";", "else", "if", "(", "is_array", "(", "$", "options", ")", "&&", "isset", "(", "$", "options", "[", "'message'", "]", ")", ")", "{", "$", "this", "->", "addError", "(", "$", "options", "[", "'message'", "]", ")", ";", "}", "else", "$", "this", "->", "addError", "(", "(", "!", "is_array", "(", "$", "options", ")", "&&", "!", "is_object", "(", "$", "options", ")", ")", "?", "$", "options", ":", "'Field is required'", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}", "return", "true", ";", "}" ]
Makes an element required @param string $name Name of the element to filter @param boolean|string|array $options Boolean indicates required or not. String indicates required with custom message. Array indicates required and has options @return boolean
[ "Makes", "an", "element", "required" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Filterer.php#L90-L105
25,978
ezra-obiwale/dSCore
src/Form/Filterer.php
Filterer.match
public function match(array $options) { if (isset($options['element'])) { if (isset($this->data[$options['element']])) { if ($this->elementData == $this->data[$options['element']]) { return true; } } else { return true; } } else if (isset($options['value'])) { if ($this->elementData == $options['value']) { return true; } } $this->addError($this->checkMessage('Values mismatch', $options)); return false; }
php
public function match(array $options) { if (isset($options['element'])) { if (isset($this->data[$options['element']])) { if ($this->elementData == $this->data[$options['element']]) { return true; } } else { return true; } } else if (isset($options['value'])) { if ($this->elementData == $options['value']) { return true; } } $this->addError($this->checkMessage('Values mismatch', $options)); return false; }
[ "public", "function", "match", "(", "array", "$", "options", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'element'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "$", "options", "[", "'element'", "]", "]", ")", ")", "{", "if", "(", "$", "this", "->", "elementData", "==", "$", "this", "->", "data", "[", "$", "options", "[", "'element'", "]", "]", ")", "{", "return", "true", ";", "}", "}", "else", "{", "return", "true", ";", "}", "}", "else", "if", "(", "isset", "(", "$", "options", "[", "'value'", "]", ")", ")", "{", "if", "(", "$", "this", "->", "elementData", "==", "$", "options", "[", "'value'", "]", ")", "{", "return", "true", ";", "}", "}", "$", "this", "->", "addError", "(", "$", "this", "->", "checkMessage", "(", "'Values mismatch'", ",", "$", "options", ")", ")", ";", "return", "false", ";", "}" ]
Checks if the value of the element matches the given option @param string $name Name of the element to filter @param array $options Keys may include [message] @return boolean @throws \Exception
[ "Checks", "if", "the", "value", "of", "the", "element", "matches", "the", "given", "option" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Filterer.php#L114-L131
25,979
ezra-obiwale/dSCore
src/Form/Filterer.php
Filterer.email
public function email(array $options) { if (empty($this->elementData) || filter_var($this->elementData, FILTER_VALIDATE_EMAIL)) { $this->elementData = filter_var($this->elementData, FILTER_SANITIZE_EMAIL); return true; } $this->addError($this->checkMessage('Invalid email adddress', $options)); return false; }
php
public function email(array $options) { if (empty($this->elementData) || filter_var($this->elementData, FILTER_VALIDATE_EMAIL)) { $this->elementData = filter_var($this->elementData, FILTER_SANITIZE_EMAIL); return true; } $this->addError($this->checkMessage('Invalid email adddress', $options)); return false; }
[ "public", "function", "email", "(", "array", "$", "options", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "elementData", ")", "||", "filter_var", "(", "$", "this", "->", "elementData", ",", "FILTER_VALIDATE_EMAIL", ")", ")", "{", "$", "this", "->", "elementData", "=", "filter_var", "(", "$", "this", "->", "elementData", ",", "FILTER_SANITIZE_EMAIL", ")", ";", "return", "true", ";", "}", "$", "this", "->", "addError", "(", "$", "this", "->", "checkMessage", "(", "'Invalid email adddress'", ",", "$", "options", ")", ")", ";", "return", "false", ";", "}" ]
Checks if the value of the element is a valid email address @param string $name Name of the element to filter @param array $options Keys may include [message] @return boolean
[ "Checks", "if", "the", "value", "of", "the", "element", "is", "a", "valid", "email", "address" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Filterer.php#L165-L173
25,980
ezra-obiwale/dSCore
src/Form/Filterer.php
Filterer.url
public function url(array $options) { if (empty($this->elementData) || filter_var($this->elementData, FILTER_VALIDATE_URL)) { $this->elementData = filter_var($this->elementData, FILTER_SANITIZE_URL); return true; } $this->addError($this->checkMessage('Value is not a valid url', $options)); return false; }
php
public function url(array $options) { if (empty($this->elementData) || filter_var($this->elementData, FILTER_VALIDATE_URL)) { $this->elementData = filter_var($this->elementData, FILTER_SANITIZE_URL); return true; } $this->addError($this->checkMessage('Value is not a valid url', $options)); return false; }
[ "public", "function", "url", "(", "array", "$", "options", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "elementData", ")", "||", "filter_var", "(", "$", "this", "->", "elementData", ",", "FILTER_VALIDATE_URL", ")", ")", "{", "$", "this", "->", "elementData", "=", "filter_var", "(", "$", "this", "->", "elementData", ",", "FILTER_SANITIZE_URL", ")", ";", "return", "true", ";", "}", "$", "this", "->", "addError", "(", "$", "this", "->", "checkMessage", "(", "'Value is not a valid url'", ",", "$", "options", ")", ")", ";", "return", "false", ";", "}" ]
Checks if the values of the element is a valid url @param string $name Name of the element to filter @param array $options Keys may include [message] @return boolean
[ "Checks", "if", "the", "values", "of", "the", "element", "is", "a", "valid", "url" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Filterer.php#L181-L189
25,981
ezra-obiwale/dSCore
src/Form/Filterer.php
Filterer.alpha
public function alpha(array $options) { if (!$options['regex']) $options['regex'] = ($options['acceptSpace']) ? '/[^a-zA-Z\s]/' : '/[^a-zA-Z]/'; if (!preg_match($options['regex'], $this->elementData)) return true; $this->addError($this->checkMessage('Value can only contain alphabets', $options)); return false; }
php
public function alpha(array $options) { if (!$options['regex']) $options['regex'] = ($options['acceptSpace']) ? '/[^a-zA-Z\s]/' : '/[^a-zA-Z]/'; if (!preg_match($options['regex'], $this->elementData)) return true; $this->addError($this->checkMessage('Value can only contain alphabets', $options)); return false; }
[ "public", "function", "alpha", "(", "array", "$", "options", ")", "{", "if", "(", "!", "$", "options", "[", "'regex'", "]", ")", "$", "options", "[", "'regex'", "]", "=", "(", "$", "options", "[", "'acceptSpace'", "]", ")", "?", "'/[^a-zA-Z\\s]/'", ":", "'/[^a-zA-Z]/'", ";", "if", "(", "!", "preg_match", "(", "$", "options", "[", "'regex'", "]", ",", "$", "this", "->", "elementData", ")", ")", "return", "true", ";", "$", "this", "->", "addError", "(", "$", "this", "->", "checkMessage", "(", "'Value can only contain alphabets'", ",", "$", "options", ")", ")", ";", "return", "false", ";", "}" ]
Checks if the contents of the element are all alphabets @param string $name Name of the element to filter @param array $options Keys may include [message] @return boolean
[ "Checks", "if", "the", "contents", "of", "the", "element", "are", "all", "alphabets" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Filterer.php#L197-L205
25,982
ezra-obiwale/dSCore
src/Form/Filterer.php
Filterer.decimal
public function decimal(array $options) { if (ctype_digit($this->elementData)) return true; $this->addError($this->checkMessage('Value can only contain numbers and a dot', $options)); return false; }
php
public function decimal(array $options) { if (ctype_digit($this->elementData)) return true; $this->addError($this->checkMessage('Value can only contain numbers and a dot', $options)); return false; }
[ "public", "function", "decimal", "(", "array", "$", "options", ")", "{", "if", "(", "ctype_digit", "(", "$", "this", "->", "elementData", ")", ")", "return", "true", ";", "$", "this", "->", "addError", "(", "$", "this", "->", "checkMessage", "(", "'Value can only contain numbers and a dot'", ",", "$", "options", ")", ")", ";", "return", "false", ";", "}" ]
Checks if the content of the element is decimal @param string $name Name of the element to filter @param array $options Keys may include [message] @return boolean
[ "Checks", "if", "the", "content", "of", "the", "element", "is", "decimal" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Filterer.php#L229-L235
25,983
ezra-obiwale/dSCore
src/Form/Filterer.php
Filterer.greaterThan
public function greaterThan(array $options) { if (isset($options['element'])) { if (isset($this->data[$options['element']])) { $than = ' "' . $this->cleanElement($options['element']) . '"'; if ($this->elementData > $this->data[$options['element']] || (empty($this->elementData) && $this->elementData !== 0)) { return true; } } } else if (isset($options['value'])) { $than = $options['value']; if ($this->elementData > $options['value']) { return true; } } $this->addError($this->checkMessage('Value must be greater than ' . $than, $options)); return false; }
php
public function greaterThan(array $options) { if (isset($options['element'])) { if (isset($this->data[$options['element']])) { $than = ' "' . $this->cleanElement($options['element']) . '"'; if ($this->elementData > $this->data[$options['element']] || (empty($this->elementData) && $this->elementData !== 0)) { return true; } } } else if (isset($options['value'])) { $than = $options['value']; if ($this->elementData > $options['value']) { return true; } } $this->addError($this->checkMessage('Value must be greater than ' . $than, $options)); return false; }
[ "public", "function", "greaterThan", "(", "array", "$", "options", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'element'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "$", "options", "[", "'element'", "]", "]", ")", ")", "{", "$", "than", "=", "' \"'", ".", "$", "this", "->", "cleanElement", "(", "$", "options", "[", "'element'", "]", ")", ".", "'\"'", ";", "if", "(", "$", "this", "->", "elementData", ">", "$", "this", "->", "data", "[", "$", "options", "[", "'element'", "]", "]", "||", "(", "empty", "(", "$", "this", "->", "elementData", ")", "&&", "$", "this", "->", "elementData", "!==", "0", ")", ")", "{", "return", "true", ";", "}", "}", "}", "else", "if", "(", "isset", "(", "$", "options", "[", "'value'", "]", ")", ")", "{", "$", "than", "=", "$", "options", "[", "'value'", "]", ";", "if", "(", "$", "this", "->", "elementData", ">", "$", "options", "[", "'value'", "]", ")", "{", "return", "true", ";", "}", "}", "$", "this", "->", "addError", "(", "$", "this", "->", "checkMessage", "(", "'Value must be greater than '", ".", "$", "than", ",", "$", "options", ")", ")", ";", "return", "false", ";", "}" ]
Checks if the value of the element is greater than the given value @param string $name Name of the element to filter @param array $options Keys may include [message] @return boolean
[ "Checks", "if", "the", "value", "of", "the", "element", "is", "greater", "than", "the", "given", "value" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Filterer.php#L258-L275
25,984
ezra-obiwale/dSCore
src/Form/Filterer.php
Filterer.lessThan
public function lessThan(array $options) { if (isset($options['element'])) { if (isset($this->data[$options['element']])) { $than = ' "' . $this->cleanElement($options['element']) . '"'; if ($this->elementData < $this->data[$options['element']]) { return true; } } } else if (isset($options['value'])) { $than = $options['value']; if ($this->elementData < $options['value']) { return true; } } $this->addError($this->checkMessage('Value must be less than ' . $than, $options)); return false; }
php
public function lessThan(array $options) { if (isset($options['element'])) { if (isset($this->data[$options['element']])) { $than = ' "' . $this->cleanElement($options['element']) . '"'; if ($this->elementData < $this->data[$options['element']]) { return true; } } } else if (isset($options['value'])) { $than = $options['value']; if ($this->elementData < $options['value']) { return true; } } $this->addError($this->checkMessage('Value must be less than ' . $than, $options)); return false; }
[ "public", "function", "lessThan", "(", "array", "$", "options", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'element'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "$", "options", "[", "'element'", "]", "]", ")", ")", "{", "$", "than", "=", "' \"'", ".", "$", "this", "->", "cleanElement", "(", "$", "options", "[", "'element'", "]", ")", ".", "'\"'", ";", "if", "(", "$", "this", "->", "elementData", "<", "$", "this", "->", "data", "[", "$", "options", "[", "'element'", "]", "]", ")", "{", "return", "true", ";", "}", "}", "}", "else", "if", "(", "isset", "(", "$", "options", "[", "'value'", "]", ")", ")", "{", "$", "than", "=", "$", "options", "[", "'value'", "]", ";", "if", "(", "$", "this", "->", "elementData", "<", "$", "options", "[", "'value'", "]", ")", "{", "return", "true", ";", "}", "}", "$", "this", "->", "addError", "(", "$", "this", "->", "checkMessage", "(", "'Value must be less than '", ".", "$", "than", ",", "$", "options", ")", ")", ";", "return", "false", ";", "}" ]
Checks if the value of the element is less than the given value @param string $name Name of the element to filter @param array $options Keys may include [message] @return boolean
[ "Checks", "if", "the", "value", "of", "the", "element", "is", "less", "than", "the", "given", "value" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Filterer.php#L283-L300
25,985
ezra-obiwale/dSCore
src/Form/Filterer.php
Filterer.minLength
public function minLength(array $options) { if ($options['value'] && strlen($this->elementData) >= $options['value']) return true; $this->addError($this->checkMessage('Length must not be less than ' . $options['value'], $options)); return false; }
php
public function minLength(array $options) { if ($options['value'] && strlen($this->elementData) >= $options['value']) return true; $this->addError($this->checkMessage('Length must not be less than ' . $options['value'], $options)); return false; }
[ "public", "function", "minLength", "(", "array", "$", "options", ")", "{", "if", "(", "$", "options", "[", "'value'", "]", "&&", "strlen", "(", "$", "this", "->", "elementData", ")", ">=", "$", "options", "[", "'value'", "]", ")", "return", "true", ";", "$", "this", "->", "addError", "(", "$", "this", "->", "checkMessage", "(", "'Length must not be less than '", ".", "$", "options", "[", "'value'", "]", ",", "$", "options", ")", ")", ";", "return", "false", ";", "}" ]
Checks if the length of the value of the element is not less than the required length @param string $name Name of the element to filter @param array $options Keys may include [message] @return boolean
[ "Checks", "if", "the", "length", "of", "the", "value", "of", "the", "element", "is", "not", "less", "than", "the", "required", "length" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Filterer.php#L308-L314
25,986
CodeBlastr/queue
src/Shell/QueueShell.php
QueueShell.main
public function main() { $this->out('CodeBlastr Queue Plugin:'); $this->hr(); $this->out('Usage:'); $this->out(' cake CodeBlastr.Queue help'); $this->out(' -> Display this Help message'); // $this->out(' cake Queue.Queue add <taskname>'); // $this->out(' -> Try to call the cli add() function on a task'); // $this->out(' -> tasks may or may not provide this functionality.'); $this->out(' cake Queue.Queue runworker'); $this->out(' -> run a queue worker, which will look for a pending task it can execute.'); $this->out(' -> the worker will always try to find jobs matching its installed Tasks'); $this->out(' -> see "Available Tasks" below.'); $this->out(' cake Queue.Queue runworker'); $this->out(' -> run a queue worker, which will look for a pending task it can execute.'); $this->out(' -> the worker will always try to find jobs matching its installed Tasks'); $this->out(' -> see "Available Tasks" below.'); $this->out(' cake Queue.Queue stats'); $this->out(' -> Display some general Statistics.'); $this->out(' cake Queue.Queue clean'); $this->out(' -> Manually call cleanup function to delete task data of completed tasks.'); }
php
public function main() { $this->out('CodeBlastr Queue Plugin:'); $this->hr(); $this->out('Usage:'); $this->out(' cake CodeBlastr.Queue help'); $this->out(' -> Display this Help message'); // $this->out(' cake Queue.Queue add <taskname>'); // $this->out(' -> Try to call the cli add() function on a task'); // $this->out(' -> tasks may or may not provide this functionality.'); $this->out(' cake Queue.Queue runworker'); $this->out(' -> run a queue worker, which will look for a pending task it can execute.'); $this->out(' -> the worker will always try to find jobs matching its installed Tasks'); $this->out(' -> see "Available Tasks" below.'); $this->out(' cake Queue.Queue runworker'); $this->out(' -> run a queue worker, which will look for a pending task it can execute.'); $this->out(' -> the worker will always try to find jobs matching its installed Tasks'); $this->out(' -> see "Available Tasks" below.'); $this->out(' cake Queue.Queue stats'); $this->out(' -> Display some general Statistics.'); $this->out(' cake Queue.Queue clean'); $this->out(' -> Manually call cleanup function to delete task data of completed tasks.'); }
[ "public", "function", "main", "(", ")", "{", "$", "this", "->", "out", "(", "'CodeBlastr Queue Plugin:'", ")", ";", "$", "this", "->", "hr", "(", ")", ";", "$", "this", "->", "out", "(", "'Usage:'", ")", ";", "$", "this", "->", "out", "(", "'\tcake CodeBlastr.Queue help'", ")", ";", "$", "this", "->", "out", "(", "'\t\t-> Display this Help message'", ")", ";", "// $this->out('\tcake Queue.Queue add <taskname>');", "// $this->out('\t\t-> Try to call the cli add() function on a task');", "// $this->out('\t\t-> tasks may or may not provide this functionality.');", "$", "this", "->", "out", "(", "'\tcake Queue.Queue runworker'", ")", ";", "$", "this", "->", "out", "(", "'\t\t-> run a queue worker, which will look for a pending task it can execute.'", ")", ";", "$", "this", "->", "out", "(", "'\t\t-> the worker will always try to find jobs matching its installed Tasks'", ")", ";", "$", "this", "->", "out", "(", "'\t\t-> see \"Available Tasks\" below.'", ")", ";", "$", "this", "->", "out", "(", "'\tcake Queue.Queue runworker'", ")", ";", "$", "this", "->", "out", "(", "'\t\t-> run a queue worker, which will look for a pending task it can execute.'", ")", ";", "$", "this", "->", "out", "(", "'\t\t-> the worker will always try to find jobs matching its installed Tasks'", ")", ";", "$", "this", "->", "out", "(", "'\t\t-> see \"Available Tasks\" below.'", ")", ";", "$", "this", "->", "out", "(", "'\tcake Queue.Queue stats'", ")", ";", "$", "this", "->", "out", "(", "'\t\t-> Display some general Statistics.'", ")", ";", "$", "this", "->", "out", "(", "'\tcake Queue.Queue clean'", ")", ";", "$", "this", "->", "out", "(", "'\t\t-> Manually call cleanup function to delete task data of completed tasks.'", ")", ";", "}" ]
Output some basic usage Info. @return void
[ "Output", "some", "basic", "usage", "Info", "." ]
8bc37c429406cce1b99c2c9e9dc1a83ad2b0b435
https://github.com/CodeBlastr/queue/blob/8bc37c429406cce1b99c2c9e9dc1a83ad2b0b435/src/Shell/QueueShell.php#L52-L74
25,987
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Image/GdImage.php
GdImage.dispose
public final function dispose() { if ( $this->disposed ) { return; } if ( \is_resource( $this->r ) ) { \imagedestroy( $this->r ); } $this->r = null; $this->size = null; $this->colors = []; $this->mimeType = null; $this->_file = null; $this->disposed = true; }
php
public final function dispose() { if ( $this->disposed ) { return; } if ( \is_resource( $this->r ) ) { \imagedestroy( $this->r ); } $this->r = null; $this->size = null; $this->colors = []; $this->mimeType = null; $this->_file = null; $this->disposed = true; }
[ "public", "final", "function", "dispose", "(", ")", "{", "if", "(", "$", "this", "->", "disposed", ")", "{", "return", ";", "}", "if", "(", "\\", "is_resource", "(", "$", "this", "->", "r", ")", ")", "{", "\\", "imagedestroy", "(", "$", "this", "->", "r", ")", ";", "}", "$", "this", "->", "r", "=", "null", ";", "$", "this", "->", "size", "=", "null", ";", "$", "this", "->", "colors", "=", "[", "]", ";", "$", "this", "->", "mimeType", "=", "null", ";", "$", "this", "->", "_file", "=", "null", ";", "$", "this", "->", "disposed", "=", "true", ";", "}" ]
Disposes the current image resource.
[ "Disposes", "the", "current", "image", "resource", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Image/GdImage.php#L77-L97
25,988
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Image/GdImage.php
GdImage.output
public final function output( int $quality = 60, string $filename = null ) { \header( 'Expires: 0' ); \header( 'Cache-Control: private' ); \header( 'Pragma: cache' ); if ( empty( $filename ) ) { $filename = \basename( $this->_file ); } else { $filename = \basename( $filename ); } if ( ! empty( $filename ) ) { \header( "Content-Disposition: inline; filename=\"{$filename}\"" ); $mime = MimeTypeTool::GetByFileName( $filename ); \header( "Content-Type: {$mime}" ); switch ( $mime ) { case 'image/png': \imagepng( $this->r ); break; case 'image/gif': \imagegif( $this->r ); break; default: \imagejpeg( $this->r, null, $quality ); break; } exit; } \header( "Content-Type: {$this->mimeType}" ); switch ( $this->mimeType ) { case 'image/png': \imagepng( $this->r ); break; case 'image/gif': \imagegif( $this->r ); break; default: \imagejpeg( $this->r, null, $quality ); break; } exit; }
php
public final function output( int $quality = 60, string $filename = null ) { \header( 'Expires: 0' ); \header( 'Cache-Control: private' ); \header( 'Pragma: cache' ); if ( empty( $filename ) ) { $filename = \basename( $this->_file ); } else { $filename = \basename( $filename ); } if ( ! empty( $filename ) ) { \header( "Content-Disposition: inline; filename=\"{$filename}\"" ); $mime = MimeTypeTool::GetByFileName( $filename ); \header( "Content-Type: {$mime}" ); switch ( $mime ) { case 'image/png': \imagepng( $this->r ); break; case 'image/gif': \imagegif( $this->r ); break; default: \imagejpeg( $this->r, null, $quality ); break; } exit; } \header( "Content-Type: {$this->mimeType}" ); switch ( $this->mimeType ) { case 'image/png': \imagepng( $this->r ); break; case 'image/gif': \imagegif( $this->r ); break; default: \imagejpeg( $this->r, null, $quality ); break; } exit; }
[ "public", "final", "function", "output", "(", "int", "$", "quality", "=", "60", ",", "string", "$", "filename", "=", "null", ")", "{", "\\", "header", "(", "'Expires: 0'", ")", ";", "\\", "header", "(", "'Cache-Control: private'", ")", ";", "\\", "header", "(", "'Pragma: cache'", ")", ";", "if", "(", "empty", "(", "$", "filename", ")", ")", "{", "$", "filename", "=", "\\", "basename", "(", "$", "this", "->", "_file", ")", ";", "}", "else", "{", "$", "filename", "=", "\\", "basename", "(", "$", "filename", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "filename", ")", ")", "{", "\\", "header", "(", "\"Content-Disposition: inline; filename=\\\"{$filename}\\\"\"", ")", ";", "$", "mime", "=", "MimeTypeTool", "::", "GetByFileName", "(", "$", "filename", ")", ";", "\\", "header", "(", "\"Content-Type: {$mime}\"", ")", ";", "switch", "(", "$", "mime", ")", "{", "case", "'image/png'", ":", "\\", "imagepng", "(", "$", "this", "->", "r", ")", ";", "break", ";", "case", "'image/gif'", ":", "\\", "imagegif", "(", "$", "this", "->", "r", ")", ";", "break", ";", "default", ":", "\\", "imagejpeg", "(", "$", "this", "->", "r", ",", "null", ",", "$", "quality", ")", ";", "break", ";", "}", "exit", ";", "}", "\\", "header", "(", "\"Content-Type: {$this->mimeType}\"", ")", ";", "switch", "(", "$", "this", "->", "mimeType", ")", "{", "case", "'image/png'", ":", "\\", "imagepng", "(", "$", "this", "->", "r", ")", ";", "break", ";", "case", "'image/gif'", ":", "\\", "imagegif", "(", "$", "this", "->", "r", ")", ";", "break", ";", "default", ":", "\\", "imagejpeg", "(", "$", "this", "->", "r", ",", "null", ",", "$", "quality", ")", ";", "break", ";", "}", "exit", ";", "}" ]
Outputs the current image, including all required HTTP headers and exit the script. @param integer $quality Image quality if it is an JPEG image. (1-100) @param string $filename Output image file name for HTTP headers.
[ "Outputs", "the", "current", "image", "including", "all", "required", "HTTP", "headers", "and", "exit", "the", "script", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Image/GdImage.php#L244-L297
25,989
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Image/GdImage.php
GdImage.negate
public final function negate( bool $internal = false ) : GdImage { if ( ! $internal ) { $clon = clone $this; return $clon->negate( true ); } $w = $this->getWidth(); $h = $this->getHeight(); $im = \imagecreatetruecolor( $w, $h ); for ( $y = 0; $y < $h; ++$y ) { for ( $x = 0; $x < $w; $x++ ) { $colors = \imagecolorsforindex( $this->r, \imagecolorat( $this->r, $x, $y ) ); $r = 255 - $colors[ 'red' ]; $g = 255 - $colors[ 'green' ]; $b = 255 - $colors[ 'blue' ]; $newColor = \imagecolorallocate( $im, $r, $g, $b ); \imagesetpixel( $im, $x, $y, $newColor ); } } \imagedestroy( $this->r ); $this->r = null; $this->r = $im; return $this; }
php
public final function negate( bool $internal = false ) : GdImage { if ( ! $internal ) { $clon = clone $this; return $clon->negate( true ); } $w = $this->getWidth(); $h = $this->getHeight(); $im = \imagecreatetruecolor( $w, $h ); for ( $y = 0; $y < $h; ++$y ) { for ( $x = 0; $x < $w; $x++ ) { $colors = \imagecolorsforindex( $this->r, \imagecolorat( $this->r, $x, $y ) ); $r = 255 - $colors[ 'red' ]; $g = 255 - $colors[ 'green' ]; $b = 255 - $colors[ 'blue' ]; $newColor = \imagecolorallocate( $im, $r, $g, $b ); \imagesetpixel( $im, $x, $y, $newColor ); } } \imagedestroy( $this->r ); $this->r = null; $this->r = $im; return $this; }
[ "public", "final", "function", "negate", "(", "bool", "$", "internal", "=", "false", ")", ":", "GdImage", "{", "if", "(", "!", "$", "internal", ")", "{", "$", "clon", "=", "clone", "$", "this", ";", "return", "$", "clon", "->", "negate", "(", "true", ")", ";", "}", "$", "w", "=", "$", "this", "->", "getWidth", "(", ")", ";", "$", "h", "=", "$", "this", "->", "getHeight", "(", ")", ";", "$", "im", "=", "\\", "imagecreatetruecolor", "(", "$", "w", ",", "$", "h", ")", ";", "for", "(", "$", "y", "=", "0", ";", "$", "y", "<", "$", "h", ";", "++", "$", "y", ")", "{", "for", "(", "$", "x", "=", "0", ";", "$", "x", "<", "$", "w", ";", "$", "x", "++", ")", "{", "$", "colors", "=", "\\", "imagecolorsforindex", "(", "$", "this", "->", "r", ",", "\\", "imagecolorat", "(", "$", "this", "->", "r", ",", "$", "x", ",", "$", "y", ")", ")", ";", "$", "r", "=", "255", "-", "$", "colors", "[", "'red'", "]", ";", "$", "g", "=", "255", "-", "$", "colors", "[", "'green'", "]", ";", "$", "b", "=", "255", "-", "$", "colors", "[", "'blue'", "]", ";", "$", "newColor", "=", "\\", "imagecolorallocate", "(", "$", "im", ",", "$", "r", ",", "$", "g", ",", "$", "b", ")", ";", "\\", "imagesetpixel", "(", "$", "im", ",", "$", "x", ",", "$", "y", ",", "$", "newColor", ")", ";", "}", "}", "\\", "imagedestroy", "(", "$", "this", "->", "r", ")", ";", "$", "this", "->", "r", "=", "null", ";", "$", "this", "->", "r", "=", "$", "im", ";", "return", "$", "this", ";", "}" ]
Creates a negative of current image. @param boolean $internal Do not create a new instance? @return \Beluga\Drawing\Image\GdImage
[ "Creates", "a", "negative", "of", "current", "image", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Image/GdImage.php#L377-L413
25,990
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Image/GdImage.php
GdImage.cropRect
public final function cropRect( Rectangle $rect, bool $internal = true ) : IImage { $thumb = \imagecreatetruecolor( $rect->size->getWidth(), $rect->size->getHeight() ); if ( $this->mimeType == 'image/gif' || $this->mimeType == 'image/png') { \imagealphablending( $thumb, false ); \imagesavealpha( $thumb, true ); } \imagecopyresampled( $thumb, # $dst_image $this->r, # $src_image 0, # $dst_x 0, # $dst_y $rect->point->x, # $src_x $rect->point->y, # $src_y $rect->size->getWidth(), # $dst_w $rect->size->getHeight(), # $dst_h $rect->size->getWidth(), # $src_w $rect->size->getHeight() # $src_h ); if ( $internal ) { $this->size->setHeight( $rect->size->getHeight() ); $this->size->setWidth ( $rect->size->getWidth() ); if ( \is_resource( $this->r ) ) { \imagedestroy( $this->r ); $this->r = null; } $this->r = $thumb; return $this; } return new GdImage( $thumb, $rect->size, $this->mimeType, $this->_file ); }
php
public final function cropRect( Rectangle $rect, bool $internal = true ) : IImage { $thumb = \imagecreatetruecolor( $rect->size->getWidth(), $rect->size->getHeight() ); if ( $this->mimeType == 'image/gif' || $this->mimeType == 'image/png') { \imagealphablending( $thumb, false ); \imagesavealpha( $thumb, true ); } \imagecopyresampled( $thumb, # $dst_image $this->r, # $src_image 0, # $dst_x 0, # $dst_y $rect->point->x, # $src_x $rect->point->y, # $src_y $rect->size->getWidth(), # $dst_w $rect->size->getHeight(), # $dst_h $rect->size->getWidth(), # $src_w $rect->size->getHeight() # $src_h ); if ( $internal ) { $this->size->setHeight( $rect->size->getHeight() ); $this->size->setWidth ( $rect->size->getWidth() ); if ( \is_resource( $this->r ) ) { \imagedestroy( $this->r ); $this->r = null; } $this->r = $thumb; return $this; } return new GdImage( $thumb, $rect->size, $this->mimeType, $this->_file ); }
[ "public", "final", "function", "cropRect", "(", "Rectangle", "$", "rect", ",", "bool", "$", "internal", "=", "true", ")", ":", "IImage", "{", "$", "thumb", "=", "\\", "imagecreatetruecolor", "(", "$", "rect", "->", "size", "->", "getWidth", "(", ")", ",", "$", "rect", "->", "size", "->", "getHeight", "(", ")", ")", ";", "if", "(", "$", "this", "->", "mimeType", "==", "'image/gif'", "||", "$", "this", "->", "mimeType", "==", "'image/png'", ")", "{", "\\", "imagealphablending", "(", "$", "thumb", ",", "false", ")", ";", "\\", "imagesavealpha", "(", "$", "thumb", ",", "true", ")", ";", "}", "\\", "imagecopyresampled", "(", "$", "thumb", ",", "# $dst_image", "$", "this", "->", "r", ",", "# $src_image", "0", ",", "# $dst_x", "0", ",", "# $dst_y", "$", "rect", "->", "point", "->", "x", ",", "# $src_x", "$", "rect", "->", "point", "->", "y", ",", "# $src_y", "$", "rect", "->", "size", "->", "getWidth", "(", ")", ",", "# $dst_w", "$", "rect", "->", "size", "->", "getHeight", "(", ")", ",", "# $dst_h", "$", "rect", "->", "size", "->", "getWidth", "(", ")", ",", "# $src_w", "$", "rect", "->", "size", "->", "getHeight", "(", ")", "# $src_h", ")", ";", "if", "(", "$", "internal", ")", "{", "$", "this", "->", "size", "->", "setHeight", "(", "$", "rect", "->", "size", "->", "getHeight", "(", ")", ")", ";", "$", "this", "->", "size", "->", "setWidth", "(", "$", "rect", "->", "size", "->", "getWidth", "(", ")", ")", ";", "if", "(", "\\", "is_resource", "(", "$", "this", "->", "r", ")", ")", "{", "\\", "imagedestroy", "(", "$", "this", "->", "r", ")", ";", "$", "this", "->", "r", "=", "null", ";", "}", "$", "this", "->", "r", "=", "$", "thumb", ";", "return", "$", "this", ";", "}", "return", "new", "GdImage", "(", "$", "thumb", ",", "$", "rect", "->", "size", ",", "$", "this", "->", "mimeType", ",", "$", "this", "->", "_file", ")", ";", "}" ]
Crop the defined image part and returns the current or new image instance. @param \Beluga\Drawing\Rectangle $rect @param boolean $internal Do not create a new instance? @return \Beluga\Drawing\Image\IImage
[ "Crop", "the", "defined", "image", "part", "and", "returns", "the", "current", "or", "new", "image", "instance", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Image/GdImage.php#L640-L680
25,991
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Image/GdImage.php
GdImage.contract
public final function contract( int $percent, bool $internal = true ) : IImage { if ( $percent < 1 || $percent >= 100 ) { throw new ArgumentError( 'percent', $percent, 'Drawing.Image', 'Image dimension contraction must produce a smaller, non zero sized image!' ); } $newWidth = \intval( \floor( $this->getWidth() * $percent / 100 ) ); $newHeight = \intval( \floor( $this->getHeight() * $percent / 100 ) ); if ( $this->isTrueColor() ) { $dst = \imagecreatetruecolor( $newWidth, $newHeight ); } else { $dst = \imagecreate( $newWidth, $newHeight ); } if ( $this->canUseTransparency() ) { \imagealphablending( $dst, false ); \imagesavealpha( $dst, true ); } \imagecopyresized( $dst, $this->r, 0, 0, 0, 0, $newWidth, $newHeight, $this->getWidth(), $this->getHeight() ); if ( $internal ) { if ( ! \is_null( $this->r ) ) { \imagedestroy( $this->r ); $this->r = null; } $this->r = $dst; $this->size->setWidth( $newWidth ); $this->size->setHeight( $newHeight ); return $this; } return new GdImage( $dst, new Size( $newWidth, $newHeight ), $this->mimeType, $this->_file ); }
php
public final function contract( int $percent, bool $internal = true ) : IImage { if ( $percent < 1 || $percent >= 100 ) { throw new ArgumentError( 'percent', $percent, 'Drawing.Image', 'Image dimension contraction must produce a smaller, non zero sized image!' ); } $newWidth = \intval( \floor( $this->getWidth() * $percent / 100 ) ); $newHeight = \intval( \floor( $this->getHeight() * $percent / 100 ) ); if ( $this->isTrueColor() ) { $dst = \imagecreatetruecolor( $newWidth, $newHeight ); } else { $dst = \imagecreate( $newWidth, $newHeight ); } if ( $this->canUseTransparency() ) { \imagealphablending( $dst, false ); \imagesavealpha( $dst, true ); } \imagecopyresized( $dst, $this->r, 0, 0, 0, 0, $newWidth, $newHeight, $this->getWidth(), $this->getHeight() ); if ( $internal ) { if ( ! \is_null( $this->r ) ) { \imagedestroy( $this->r ); $this->r = null; } $this->r = $dst; $this->size->setWidth( $newWidth ); $this->size->setHeight( $newHeight ); return $this; } return new GdImage( $dst, new Size( $newWidth, $newHeight ), $this->mimeType, $this->_file ); }
[ "public", "final", "function", "contract", "(", "int", "$", "percent", ",", "bool", "$", "internal", "=", "true", ")", ":", "IImage", "{", "if", "(", "$", "percent", "<", "1", "||", "$", "percent", ">=", "100", ")", "{", "throw", "new", "ArgumentError", "(", "'percent'", ",", "$", "percent", ",", "'Drawing.Image'", ",", "'Image dimension contraction must produce a smaller, non zero sized image!'", ")", ";", "}", "$", "newWidth", "=", "\\", "intval", "(", "\\", "floor", "(", "$", "this", "->", "getWidth", "(", ")", "*", "$", "percent", "/", "100", ")", ")", ";", "$", "newHeight", "=", "\\", "intval", "(", "\\", "floor", "(", "$", "this", "->", "getHeight", "(", ")", "*", "$", "percent", "/", "100", ")", ")", ";", "if", "(", "$", "this", "->", "isTrueColor", "(", ")", ")", "{", "$", "dst", "=", "\\", "imagecreatetruecolor", "(", "$", "newWidth", ",", "$", "newHeight", ")", ";", "}", "else", "{", "$", "dst", "=", "\\", "imagecreate", "(", "$", "newWidth", ",", "$", "newHeight", ")", ";", "}", "if", "(", "$", "this", "->", "canUseTransparency", "(", ")", ")", "{", "\\", "imagealphablending", "(", "$", "dst", ",", "false", ")", ";", "\\", "imagesavealpha", "(", "$", "dst", ",", "true", ")", ";", "}", "\\", "imagecopyresized", "(", "$", "dst", ",", "$", "this", "->", "r", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "newWidth", ",", "$", "newHeight", ",", "$", "this", "->", "getWidth", "(", ")", ",", "$", "this", "->", "getHeight", "(", ")", ")", ";", "if", "(", "$", "internal", ")", "{", "if", "(", "!", "\\", "is_null", "(", "$", "this", "->", "r", ")", ")", "{", "\\", "imagedestroy", "(", "$", "this", "->", "r", ")", ";", "$", "this", "->", "r", "=", "null", ";", "}", "$", "this", "->", "r", "=", "$", "dst", ";", "$", "this", "->", "size", "->", "setWidth", "(", "$", "newWidth", ")", ";", "$", "this", "->", "size", "->", "setHeight", "(", "$", "newHeight", ")", ";", "return", "$", "this", ";", "}", "return", "new", "GdImage", "(", "$", "dst", ",", "new", "Size", "(", "$", "newWidth", ",", "$", "newHeight", ")", ",", "$", "this", "->", "mimeType", ",", "$", "this", "->", "_file", ")", ";", "}" ]
Reduce the original image size by the specified percentage value. @param int $percent The percentage value. @param bool $internal Do not create a new instance? @return \Beluga\Drawing\Image\IImage @throws \Beluga\ArgumentError If $percent is lower than 1 oder greater than 99.
[ "Reduce", "the", "original", "image", "size", "by", "the", "specified", "percentage", "value", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Image/GdImage.php#L735-L789
25,992
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Image/GdImage.php
GdImage.contractToMaxSize
public final function contractToMaxSize( Size $maxsize, bool $internal = true ) : IImage { if ( $maxsize->getWidth() >= $this->size->getWidth() && $maxsize->getHeight() >= $this->size->getHeight() ) { return $this->returnSelf( $internal ); } $newSize = new Size( $this->size->getWidth(), $this->size->getHeight() ); $newSize->reduceToMaxSize( $maxsize ); return $this->createImageAfterResize( $newSize, $internal ); }
php
public final function contractToMaxSize( Size $maxsize, bool $internal = true ) : IImage { if ( $maxsize->getWidth() >= $this->size->getWidth() && $maxsize->getHeight() >= $this->size->getHeight() ) { return $this->returnSelf( $internal ); } $newSize = new Size( $this->size->getWidth(), $this->size->getHeight() ); $newSize->reduceToMaxSize( $maxsize ); return $this->createImageAfterResize( $newSize, $internal ); }
[ "public", "final", "function", "contractToMaxSize", "(", "Size", "$", "maxsize", ",", "bool", "$", "internal", "=", "true", ")", ":", "IImage", "{", "if", "(", "$", "maxsize", "->", "getWidth", "(", ")", ">=", "$", "this", "->", "size", "->", "getWidth", "(", ")", "&&", "$", "maxsize", "->", "getHeight", "(", ")", ">=", "$", "this", "->", "size", "->", "getHeight", "(", ")", ")", "{", "return", "$", "this", "->", "returnSelf", "(", "$", "internal", ")", ";", "}", "$", "newSize", "=", "new", "Size", "(", "$", "this", "->", "size", "->", "getWidth", "(", ")", ",", "$", "this", "->", "size", "->", "getHeight", "(", ")", ")", ";", "$", "newSize", "->", "reduceToMaxSize", "(", "$", "maxsize", ")", ";", "return", "$", "this", "->", "createImageAfterResize", "(", "$", "newSize", ",", "$", "internal", ")", ";", "}" ]
Reduce the original image size by holding the image size proportion, to fit best the declared maximum size. @param \Beluga\Drawing\Size $maxsize @param bool $internal Do not create a new instance? @return \Beluga\Drawing\Image\IImage @throws \Beluga\ArgumentError If $maxsize is empty. or bigger than current image
[ "Reduce", "the", "original", "image", "size", "by", "holding", "the", "image", "size", "proportion", "to", "fit", "best", "the", "declared", "maximum", "size", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Image/GdImage.php#L800-L815
25,993
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Image/GdImage.php
GdImage.drawSingleBorder
public final function drawSingleBorder( $borderColor, bool $internal = true ) : IImage { $borderColor = $this->getGdColorObject( $borderColor, 'bordercolor' ); if ( $internal ) { \imagerectangle( $this->r, 1, 1, $this->getWidth() - 2, $this->getHeight() - 2, $borderColor->getGdValue() ); return $this; } $res = clone $this; \imagerectangle( $res->r, 1, 1, $this->getWidth() - 2, $this->getHeight() - 2, $borderColor->getGdValue() ); return $res; }
php
public final function drawSingleBorder( $borderColor, bool $internal = true ) : IImage { $borderColor = $this->getGdColorObject( $borderColor, 'bordercolor' ); if ( $internal ) { \imagerectangle( $this->r, 1, 1, $this->getWidth() - 2, $this->getHeight() - 2, $borderColor->getGdValue() ); return $this; } $res = clone $this; \imagerectangle( $res->r, 1, 1, $this->getWidth() - 2, $this->getHeight() - 2, $borderColor->getGdValue() ); return $res; }
[ "public", "final", "function", "drawSingleBorder", "(", "$", "borderColor", ",", "bool", "$", "internal", "=", "true", ")", ":", "IImage", "{", "$", "borderColor", "=", "$", "this", "->", "getGdColorObject", "(", "$", "borderColor", ",", "'bordercolor'", ")", ";", "if", "(", "$", "internal", ")", "{", "\\", "imagerectangle", "(", "$", "this", "->", "r", ",", "1", ",", "1", ",", "$", "this", "->", "getWidth", "(", ")", "-", "2", ",", "$", "this", "->", "getHeight", "(", ")", "-", "2", ",", "$", "borderColor", "->", "getGdValue", "(", ")", ")", ";", "return", "$", "this", ";", "}", "$", "res", "=", "clone", "$", "this", ";", "\\", "imagerectangle", "(", "$", "res", "->", "r", ",", "1", ",", "1", ",", "$", "this", "->", "getWidth", "(", ")", "-", "2", ",", "$", "this", "->", "getHeight", "(", ")", "-", "2", ",", "$", "borderColor", "->", "getGdValue", "(", ")", ")", ";", "return", "$", "res", ";", "}" ]
Draws a single border with defined color around the image. @param string|array|\Beluga\Drawing\ColorGD|\Beluga\Drawing\Color $borderColor @param bool $internal Do not create a new instance? @return \Beluga\Drawing\Image\IImage
[ "Draws", "a", "single", "border", "with", "defined", "color", "around", "the", "image", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Image/GdImage.php#L1121-L1141
25,994
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Image/GdImage.php
GdImage.drawDoubleBorder
public final function drawDoubleBorder( $innerBorderColor, $outerBorderColor, bool $internal = true) : IImage { $innerBorderColor = $this->getGdColorObject( $innerBorderColor, 'bordercolor' ); $outerBorderColor = $this->getGdColorObject( $outerBorderColor, 'outerbordercolor' ); if ( $internal ) { \imagerectangle( $this->r, 0, 0, $this->getWidth() - 1, $this->getHeight() - 1, $outerBorderColor->getGdValue() ); \imagerectangle( $this->r, 1, 1, $this->getWidth() - 2, $this->getHeight() - 2, $innerBorderColor->getGdValue() ); return $this; } $res = clone $this; \imagerectangle( $res->r, 0, 0, $this->getWidth() - 1, $this->getHeight() - 1, $outerBorderColor->getGdValue() ); \imagerectangle( $res->r, 1, 1, $this->getWidth() - 2, $this->getHeight() - 2, $innerBorderColor->getGdValue() ); return $res; }
php
public final function drawDoubleBorder( $innerBorderColor, $outerBorderColor, bool $internal = true) : IImage { $innerBorderColor = $this->getGdColorObject( $innerBorderColor, 'bordercolor' ); $outerBorderColor = $this->getGdColorObject( $outerBorderColor, 'outerbordercolor' ); if ( $internal ) { \imagerectangle( $this->r, 0, 0, $this->getWidth() - 1, $this->getHeight() - 1, $outerBorderColor->getGdValue() ); \imagerectangle( $this->r, 1, 1, $this->getWidth() - 2, $this->getHeight() - 2, $innerBorderColor->getGdValue() ); return $this; } $res = clone $this; \imagerectangle( $res->r, 0, 0, $this->getWidth() - 1, $this->getHeight() - 1, $outerBorderColor->getGdValue() ); \imagerectangle( $res->r, 1, 1, $this->getWidth() - 2, $this->getHeight() - 2, $innerBorderColor->getGdValue() ); return $res; }
[ "public", "final", "function", "drawDoubleBorder", "(", "$", "innerBorderColor", ",", "$", "outerBorderColor", ",", "bool", "$", "internal", "=", "true", ")", ":", "IImage", "{", "$", "innerBorderColor", "=", "$", "this", "->", "getGdColorObject", "(", "$", "innerBorderColor", ",", "'bordercolor'", ")", ";", "$", "outerBorderColor", "=", "$", "this", "->", "getGdColorObject", "(", "$", "outerBorderColor", ",", "'outerbordercolor'", ")", ";", "if", "(", "$", "internal", ")", "{", "\\", "imagerectangle", "(", "$", "this", "->", "r", ",", "0", ",", "0", ",", "$", "this", "->", "getWidth", "(", ")", "-", "1", ",", "$", "this", "->", "getHeight", "(", ")", "-", "1", ",", "$", "outerBorderColor", "->", "getGdValue", "(", ")", ")", ";", "\\", "imagerectangle", "(", "$", "this", "->", "r", ",", "1", ",", "1", ",", "$", "this", "->", "getWidth", "(", ")", "-", "2", ",", "$", "this", "->", "getHeight", "(", ")", "-", "2", ",", "$", "innerBorderColor", "->", "getGdValue", "(", ")", ")", ";", "return", "$", "this", ";", "}", "$", "res", "=", "clone", "$", "this", ";", "\\", "imagerectangle", "(", "$", "res", "->", "r", ",", "0", ",", "0", ",", "$", "this", "->", "getWidth", "(", ")", "-", "1", ",", "$", "this", "->", "getHeight", "(", ")", "-", "1", ",", "$", "outerBorderColor", "->", "getGdValue", "(", ")", ")", ";", "\\", "imagerectangle", "(", "$", "res", "->", "r", ",", "1", ",", "1", ",", "$", "this", "->", "getWidth", "(", ")", "-", "2", ",", "$", "this", "->", "getHeight", "(", ")", "-", "2", ",", "$", "innerBorderColor", "->", "getGdValue", "(", ")", ")", ";", "return", "$", "res", ";", "}" ]
Draws a double border with defined colors around the image. @param string|array|\Beluga\Drawing\ColorGD|\Beluga\Drawing\Color $innerBorderColor @param string|array|\Beluga\Drawing\ColorGD|\Beluga\Drawing\Color $outerBorderColor @param bool $internal Do not create a new instance? @return \Beluga\Drawing\Image\IImage
[ "Draws", "a", "double", "border", "with", "defined", "colors", "around", "the", "image", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Image/GdImage.php#L1151-L1166
25,995
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Image/GdImage.php
GdImage.drawText
public final function drawText( string $text, $font, $fontSize, $color, Point $point, bool $internal = true ) : IImage { $color = $this->getGdColorObject( $color, 'textcolor' ); if ( ! empty( $font ) && \file_exists( $font ) ) { if ( $internal ) { \imagettftext( $this->r, $fontSize, 0, $point->x, $point->y, $color->getGdValue(), $font, $text ); return $this; } $res = clone $this; \imagettftext( $res->r, $fontSize, 0, $point->x, $point->y, $color->getGdValue(), $font, $text ); return $res; } if ( $internal ) { \imagestring( $this->r, $fontSize, $point->x, $point->y, $text, $color->getGdValue() ); return $this; } $res = clone $this; \imagestring( $res->r, $fontSize, $point->x, $point->y, $text, $color->getGdValue() ); return $res; }
php
public final function drawText( string $text, $font, $fontSize, $color, Point $point, bool $internal = true ) : IImage { $color = $this->getGdColorObject( $color, 'textcolor' ); if ( ! empty( $font ) && \file_exists( $font ) ) { if ( $internal ) { \imagettftext( $this->r, $fontSize, 0, $point->x, $point->y, $color->getGdValue(), $font, $text ); return $this; } $res = clone $this; \imagettftext( $res->r, $fontSize, 0, $point->x, $point->y, $color->getGdValue(), $font, $text ); return $res; } if ( $internal ) { \imagestring( $this->r, $fontSize, $point->x, $point->y, $text, $color->getGdValue() ); return $this; } $res = clone $this; \imagestring( $res->r, $fontSize, $point->x, $point->y, $text, $color->getGdValue() ); return $res; }
[ "public", "final", "function", "drawText", "(", "string", "$", "text", ",", "$", "font", ",", "$", "fontSize", ",", "$", "color", ",", "Point", "$", "point", ",", "bool", "$", "internal", "=", "true", ")", ":", "IImage", "{", "$", "color", "=", "$", "this", "->", "getGdColorObject", "(", "$", "color", ",", "'textcolor'", ")", ";", "if", "(", "!", "empty", "(", "$", "font", ")", "&&", "\\", "file_exists", "(", "$", "font", ")", ")", "{", "if", "(", "$", "internal", ")", "{", "\\", "imagettftext", "(", "$", "this", "->", "r", ",", "$", "fontSize", ",", "0", ",", "$", "point", "->", "x", ",", "$", "point", "->", "y", ",", "$", "color", "->", "getGdValue", "(", ")", ",", "$", "font", ",", "$", "text", ")", ";", "return", "$", "this", ";", "}", "$", "res", "=", "clone", "$", "this", ";", "\\", "imagettftext", "(", "$", "res", "->", "r", ",", "$", "fontSize", ",", "0", ",", "$", "point", "->", "x", ",", "$", "point", "->", "y", ",", "$", "color", "->", "getGdValue", "(", ")", ",", "$", "font", ",", "$", "text", ")", ";", "return", "$", "res", ";", "}", "if", "(", "$", "internal", ")", "{", "\\", "imagestring", "(", "$", "this", "->", "r", ",", "$", "fontSize", ",", "$", "point", "->", "x", ",", "$", "point", "->", "y", ",", "$", "text", ",", "$", "color", "->", "getGdValue", "(", ")", ")", ";", "return", "$", "this", ";", "}", "$", "res", "=", "clone", "$", "this", ";", "\\", "imagestring", "(", "$", "res", "->", "r", ",", "$", "fontSize", ",", "$", "point", "->", "x", ",", "$", "point", "->", "y", ",", "$", "text", ",", "$", "color", "->", "getGdValue", "(", ")", ")", ";", "return", "$", "res", ";", "}" ]
Draws a text at declared position into current image. @param string $text The text that should be drawn. @param string $font The font that should be used. For example: For GdImage you can define here the path of the *.ttf font file or NULL. If you define null the parameter $fontSize declares the size + font (1-4). If a path is defined here $fontSize should declare the size in points. @param int $fontSize The size of the font. @param string|array|\Beluga\Drawing\Color|\Beluga\Drawing\ColorGD $color The text color @param \Beluga\Drawing\Point $point The top left point where to start the text @param bool $internal Do not create a new instance? @return \Beluga\Drawing\Image\IImage
[ "Draws", "a", "text", "at", "declared", "position", "into", "current", "image", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Image/GdImage.php#L1187-L1217
25,996
net-tools/core
src/Containers/PersistentCache.php
PersistentCache.commit
public function commit() { if ( $this->_initialized && $this->_dirty ) { $this->_saveCache(); $this->_dirty = false; } }
php
public function commit() { if ( $this->_initialized && $this->_dirty ) { $this->_saveCache(); $this->_dirty = false; } }
[ "public", "function", "commit", "(", ")", "{", "if", "(", "$", "this", "->", "_initialized", "&&", "$", "this", "->", "_dirty", ")", "{", "$", "this", "->", "_saveCache", "(", ")", ";", "$", "this", "->", "_dirty", "=", "false", ";", "}", "}" ]
Commit cache content updates to storage
[ "Commit", "cache", "content", "updates", "to", "storage" ]
51446641cee22c0cf53d2b409c76cc8bd1a187e7
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Containers/PersistentCache.php#L157-L164
25,997
k3ssen/BaseAdminBundle
Controller/CrudController.php
CrudController.redirectToRoute
protected function redirectToRoute(string $route, $parameters = [], int $status = 302): RedirectResponse { return $this->redirect($this->generateUrl($route, $parameters), $status); }
php
protected function redirectToRoute(string $route, $parameters = [], int $status = 302): RedirectResponse { return $this->redirect($this->generateUrl($route, $parameters), $status); }
[ "protected", "function", "redirectToRoute", "(", "string", "$", "route", ",", "$", "parameters", "=", "[", "]", ",", "int", "$", "status", "=", "302", ")", ":", "RedirectResponse", "{", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "generateUrl", "(", "$", "route", ",", "$", "parameters", ")", ",", "$", "status", ")", ";", "}" ]
Returns a RedirectResponse to the given route with the given parameters. Overwrites Controller-trait to allow parameters as object as well.
[ "Returns", "a", "RedirectResponse", "to", "the", "given", "route", "with", "the", "given", "parameters", ".", "Overwrites", "Controller", "-", "trait", "to", "allow", "parameters", "as", "object", "as", "well", "." ]
d0af699b097f48d92883713eafd36ee9069460bb
https://github.com/k3ssen/BaseAdminBundle/blob/d0af699b097f48d92883713eafd36ee9069460bb/Controller/CrudController.php#L36-L39
25,998
k3ssen/BaseAdminBundle
Controller/CrudController.php
CrudController.isDeletable
protected function isDeletable($object): bool { $em = $this->getEntityManager(); $em->beginTransaction(); try { // if an object is softdeleteable, then set 'deletedAt' first, so that a 'hard-delete' will be attempted. if ($object instanceof SoftDeleteableInterface) { $object->setDeletedAt(new \DateTime()); } $em->remove($object); $em->flush(); $em->rollback(); return true; } catch (ForeignKeyConstraintViolationException $exception) { $em->rollback(); return false; } }
php
protected function isDeletable($object): bool { $em = $this->getEntityManager(); $em->beginTransaction(); try { // if an object is softdeleteable, then set 'deletedAt' first, so that a 'hard-delete' will be attempted. if ($object instanceof SoftDeleteableInterface) { $object->setDeletedAt(new \DateTime()); } $em->remove($object); $em->flush(); $em->rollback(); return true; } catch (ForeignKeyConstraintViolationException $exception) { $em->rollback(); return false; } }
[ "protected", "function", "isDeletable", "(", "$", "object", ")", ":", "bool", "{", "$", "em", "=", "$", "this", "->", "getEntityManager", "(", ")", ";", "$", "em", "->", "beginTransaction", "(", ")", ";", "try", "{", "// if an object is softdeleteable, then set 'deletedAt' first, so that a 'hard-delete' will be attempted.", "if", "(", "$", "object", "instanceof", "SoftDeleteableInterface", ")", "{", "$", "object", "->", "setDeletedAt", "(", "new", "\\", "DateTime", "(", ")", ")", ";", "}", "$", "em", "->", "remove", "(", "$", "object", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "$", "em", "->", "rollback", "(", ")", ";", "return", "true", ";", "}", "catch", "(", "ForeignKeyConstraintViolationException", "$", "exception", ")", "{", "$", "em", "->", "rollback", "(", ")", ";", "return", "false", ";", "}", "}" ]
Tries to delete an object without actually deleting it. Returns false if ForeignKeyConstraintViolationException would be thrown; true otherwise.
[ "Tries", "to", "delete", "an", "object", "without", "actually", "deleting", "it", ".", "Returns", "false", "if", "ForeignKeyConstraintViolationException", "would", "be", "thrown", ";", "true", "otherwise", "." ]
d0af699b097f48d92883713eafd36ee9069460bb
https://github.com/k3ssen/BaseAdminBundle/blob/d0af699b097f48d92883713eafd36ee9069460bb/Controller/CrudController.php#L111-L128
25,999
rutger-speksnijder/restphp
src/RestPHP/Configuration.php
Configuration.createFromFile
public function createFromFile($file) { // Check if the file exists if (!$file || !file_exists($file)) { throw new \Exception("Configuration file \"{$file}\" could not be found."); } // Include the file while suppressing warnings // - so we can check if we could include it $config = @include($file); if (!$config) { throw new \Exception("Configuration file \"{$file}\" could not be included."); } // Set the properties $this->useAuthorization = $config['useAuthorization']; $this->authorizationMode = $config['authorizationMode']; $this->redirectAuthorization = $config['redirectAuthorization']; $this->authorizationForm = $config['authorizationForm']; $this->dsn = $config['dsn']; $this->username = $config['username']; $this->password = $config['password']; $this->responseType = $config['responseType']; $this->clientResponseType = $config['clientResponseType']; return $this; }
php
public function createFromFile($file) { // Check if the file exists if (!$file || !file_exists($file)) { throw new \Exception("Configuration file \"{$file}\" could not be found."); } // Include the file while suppressing warnings // - so we can check if we could include it $config = @include($file); if (!$config) { throw new \Exception("Configuration file \"{$file}\" could not be included."); } // Set the properties $this->useAuthorization = $config['useAuthorization']; $this->authorizationMode = $config['authorizationMode']; $this->redirectAuthorization = $config['redirectAuthorization']; $this->authorizationForm = $config['authorizationForm']; $this->dsn = $config['dsn']; $this->username = $config['username']; $this->password = $config['password']; $this->responseType = $config['responseType']; $this->clientResponseType = $config['clientResponseType']; return $this; }
[ "public", "function", "createFromFile", "(", "$", "file", ")", "{", "// Check if the file exists", "if", "(", "!", "$", "file", "||", "!", "file_exists", "(", "$", "file", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Configuration file \\\"{$file}\\\" could not be found.\"", ")", ";", "}", "// Include the file while suppressing warnings", "// - so we can check if we could include it", "$", "config", "=", "@", "include", "(", "$", "file", ")", ";", "if", "(", "!", "$", "config", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Configuration file \\\"{$file}\\\" could not be included.\"", ")", ";", "}", "// Set the properties", "$", "this", "->", "useAuthorization", "=", "$", "config", "[", "'useAuthorization'", "]", ";", "$", "this", "->", "authorizationMode", "=", "$", "config", "[", "'authorizationMode'", "]", ";", "$", "this", "->", "redirectAuthorization", "=", "$", "config", "[", "'redirectAuthorization'", "]", ";", "$", "this", "->", "authorizationForm", "=", "$", "config", "[", "'authorizationForm'", "]", ";", "$", "this", "->", "dsn", "=", "$", "config", "[", "'dsn'", "]", ";", "$", "this", "->", "username", "=", "$", "config", "[", "'username'", "]", ";", "$", "this", "->", "password", "=", "$", "config", "[", "'password'", "]", ";", "$", "this", "->", "responseType", "=", "$", "config", "[", "'responseType'", "]", ";", "$", "this", "->", "clientResponseType", "=", "$", "config", "[", "'clientResponseType'", "]", ";", "return", "$", "this", ";", "}" ]
Creates a configuration object by loading the parameters from a file. This file has to be a PHP file returning an array with the parameters. @param string $file The path to the file. @throws Exception Throws an exception if the file can't be found. @throws Exception Throws an exception if the file could not be included. @return $this The current object.
[ "Creates", "a", "configuration", "object", "by", "loading", "the", "parameters", "from", "a", "file", ".", "This", "file", "has", "to", "be", "a", "PHP", "file", "returning", "an", "array", "with", "the", "parameters", "." ]
326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d
https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/Configuration.php#L123-L148