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
29,000
rosasurfer/ministruts
src/Application.php
Application.setupExceptionHandling
protected function setupExceptionHandling($value) { $enabled = true; // default if (is_bool($value) || is_int($value)) { $enabled = (bool) $value; } elseif (is_string($value)) { $value = trim(strtolower($value)); $enabled = ($value=='0' || $value=='off' || $value=='false'); } $enabled && ErrorHandler::setupExceptionHandling(); }
php
protected function setupExceptionHandling($value) { $enabled = true; // default if (is_bool($value) || is_int($value)) { $enabled = (bool) $value; } elseif (is_string($value)) { $value = trim(strtolower($value)); $enabled = ($value=='0' || $value=='off' || $value=='false'); } $enabled && ErrorHandler::setupExceptionHandling(); }
[ "protected", "function", "setupExceptionHandling", "(", "$", "value", ")", "{", "$", "enabled", "=", "true", ";", "// default", "if", "(", "is_bool", "(", "$", "value", ")", "||", "is_int", "(", "$", "value", ")", ")", "{", "$", "enabled", "=", "(", "bool", ")", "$", "value", ";", "}", "elseif", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "value", "=", "trim", "(", "strtolower", "(", "$", "value", ")", ")", ";", "$", "enabled", "=", "(", "$", "value", "==", "'0'", "||", "$", "value", "==", "'off'", "||", "$", "value", "==", "'false'", ")", ";", "}", "$", "enabled", "&&", "ErrorHandler", "::", "setupExceptionHandling", "(", ")", ";", "}" ]
Setup the application's exception handling. @param bool|int|string $value - configuration value as passed to the framework loader
[ "Setup", "the", "application", "s", "exception", "handling", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/Application.php#L348-L358
29,001
rosasurfer/ministruts
src/Application.php
Application.loadGlobals
protected function loadGlobals($value) { $enabled = false; // default if (is_bool($value) || is_int($value)) { $enabled = (bool) $value; } elseif (is_string($value)) { $value = trim(strtolower($value)); $enabled = ($value=='1' || $value=='on' || $value=='true'); } if ($enabled && !function_exists('booltostr')) { // prevent multiple includes include(MINISTRUTS_ROOT.'/src/globals.php'); } }
php
protected function loadGlobals($value) { $enabled = false; // default if (is_bool($value) || is_int($value)) { $enabled = (bool) $value; } elseif (is_string($value)) { $value = trim(strtolower($value)); $enabled = ($value=='1' || $value=='on' || $value=='true'); } if ($enabled && !function_exists('booltostr')) { // prevent multiple includes include(MINISTRUTS_ROOT.'/src/globals.php'); } }
[ "protected", "function", "loadGlobals", "(", "$", "value", ")", "{", "$", "enabled", "=", "false", ";", "// default", "if", "(", "is_bool", "(", "$", "value", ")", "||", "is_int", "(", "$", "value", ")", ")", "{", "$", "enabled", "=", "(", "bool", ")", "$", "value", ";", "}", "elseif", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "value", "=", "trim", "(", "strtolower", "(", "$", "value", ")", ")", ";", "$", "enabled", "=", "(", "$", "value", "==", "'1'", "||", "$", "value", "==", "'on'", "||", "$", "value", "==", "'true'", ")", ";", "}", "if", "(", "$", "enabled", "&&", "!", "function_exists", "(", "'booltostr'", ")", ")", "{", "// prevent multiple includes", "include", "(", "MINISTRUTS_ROOT", ".", "'/src/globals.php'", ")", ";", "}", "}" ]
Map common definitions in namespace "\rosasurfer" to the global namespace. @param mixed $value - configuration value as passed to the framework loader
[ "Map", "common", "definitions", "in", "namespace", "\\", "rosasurfer", "to", "the", "global", "namespace", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/Application.php#L366-L378
29,002
rosasurfer/ministruts
src/Application.php
Application.replaceComposer
protected function replaceComposer($value) { $enabled = false; // default if (is_bool($value) || is_int($value)) { $enabled = (bool) $value; } elseif (is_string($value)) { $value = trim(strtolower($value)); $enabled = ($value=='1' || $value=='on' || $value=='true'); } if ($enabled) { // replace Composer } }
php
protected function replaceComposer($value) { $enabled = false; // default if (is_bool($value) || is_int($value)) { $enabled = (bool) $value; } elseif (is_string($value)) { $value = trim(strtolower($value)); $enabled = ($value=='1' || $value=='on' || $value=='true'); } if ($enabled) { // replace Composer } }
[ "protected", "function", "replaceComposer", "(", "$", "value", ")", "{", "$", "enabled", "=", "false", ";", "// default", "if", "(", "is_bool", "(", "$", "value", ")", "||", "is_int", "(", "$", "value", ")", ")", "{", "$", "enabled", "=", "(", "bool", ")", "$", "value", ";", "}", "elseif", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "value", "=", "trim", "(", "strtolower", "(", "$", "value", ")", ")", ";", "$", "enabled", "=", "(", "$", "value", "==", "'1'", "||", "$", "value", "==", "'on'", "||", "$", "value", "==", "'true'", ")", ";", "}", "if", "(", "$", "enabled", ")", "{", "// replace Composer", "}", "}" ]
Replace an existing Composer class loader. @param mixed $value - configuration value as passed to the framework loader
[ "Replace", "an", "existing", "Composer", "class", "loader", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/Application.php#L386-L398
29,003
rosasurfer/ministruts
src/ministruts/HttpSession.php
HttpSession.init
protected function init($suppressHeadersAlreadySentError = false) { /** * PHP laesst sich ohne weiteres manipulierte Session-IDs unterschieben, solange diese keine ungueltigen Zeichen * enthalten (IDs wie PHPSESSID=111 werden anstandslos akzeptiert). Wenn session_start() zurueckkehrt, gibt es mit * den vorhandenen PHP-Mitteln keine vernuenftige Moeglichkeit mehr, festzustellen, ob die Session-ID von PHP oder * (kuenstlich?) vom User generiert wurde. Daher wird in dieser Methode jede neue Session mit einer zusaetzliche * Markierung versehen. Fehlt diese Markierung nach Rueckkehr von session_start(), wurde die ID nicht von PHP * generiert. Aus Sicherheitsgruenden wird eine solche Session verworfen und eine neue ID erzeugt. */ $request = $this->request; // Session-Cookie auf Application beschraenken, um mehrere Projekte je Domain zu ermoeglichen $params = session_get_cookie_params(); session_set_cookie_params($params['lifetime'], $request->getApplicationBaseUri(), $params['domain' ], $params['secure' ], $params['httponly']); // Session starten bzw. fortsetzen try { session_start(); // TODO: Handle the case when a session was already started elsewhere? } catch (PHPError $error) { if (preg_match('/The session id contains illegal characters/', $error->getMessage())) { session_regenerate_id(); // neue ID generieren } else if (preg_match('/- headers already sent (by )?\(output started at /', $error->getMessage())) { if (!$suppressHeadersAlreadySentError) throw $error; } else { throw $error; } } // Inhalt der Session pruefen // TODO: Session verwerfen, wenn der User zwischen Cookie- und URL-Uebertragung wechselt if (sizeof($_SESSION) == 0) { // 0 bedeutet, die Session ist (fuer diese Methode) neu $sessionName = session_name(); $sessionId = session_id(); // pruefen, woher die ID kommt ... // TODO: Verwendung von $_COOKIE und $_REQUEST ist unsicher if (isset($_COOKIE [$sessionName]) && $_COOKIE [$sessionName] == $sessionId) $fromUser = true; // ID kommt vom Cookie elseif (isset($_REQUEST[$sessionName]) && $_REQUEST[$sessionName] == $sessionId) $fromUser = true; // ID kommt aus GET/POST else $fromUser = false; $this->reset($fromUser); // if $fromUser=TRUE: generate new session id } else { // vorhandene Session fortgesetzt $this->new = false; } }
php
protected function init($suppressHeadersAlreadySentError = false) { /** * PHP laesst sich ohne weiteres manipulierte Session-IDs unterschieben, solange diese keine ungueltigen Zeichen * enthalten (IDs wie PHPSESSID=111 werden anstandslos akzeptiert). Wenn session_start() zurueckkehrt, gibt es mit * den vorhandenen PHP-Mitteln keine vernuenftige Moeglichkeit mehr, festzustellen, ob die Session-ID von PHP oder * (kuenstlich?) vom User generiert wurde. Daher wird in dieser Methode jede neue Session mit einer zusaetzliche * Markierung versehen. Fehlt diese Markierung nach Rueckkehr von session_start(), wurde die ID nicht von PHP * generiert. Aus Sicherheitsgruenden wird eine solche Session verworfen und eine neue ID erzeugt. */ $request = $this->request; // Session-Cookie auf Application beschraenken, um mehrere Projekte je Domain zu ermoeglichen $params = session_get_cookie_params(); session_set_cookie_params($params['lifetime'], $request->getApplicationBaseUri(), $params['domain' ], $params['secure' ], $params['httponly']); // Session starten bzw. fortsetzen try { session_start(); // TODO: Handle the case when a session was already started elsewhere? } catch (PHPError $error) { if (preg_match('/The session id contains illegal characters/', $error->getMessage())) { session_regenerate_id(); // neue ID generieren } else if (preg_match('/- headers already sent (by )?\(output started at /', $error->getMessage())) { if (!$suppressHeadersAlreadySentError) throw $error; } else { throw $error; } } // Inhalt der Session pruefen // TODO: Session verwerfen, wenn der User zwischen Cookie- und URL-Uebertragung wechselt if (sizeof($_SESSION) == 0) { // 0 bedeutet, die Session ist (fuer diese Methode) neu $sessionName = session_name(); $sessionId = session_id(); // pruefen, woher die ID kommt ... // TODO: Verwendung von $_COOKIE und $_REQUEST ist unsicher if (isset($_COOKIE [$sessionName]) && $_COOKIE [$sessionName] == $sessionId) $fromUser = true; // ID kommt vom Cookie elseif (isset($_REQUEST[$sessionName]) && $_REQUEST[$sessionName] == $sessionId) $fromUser = true; // ID kommt aus GET/POST else $fromUser = false; $this->reset($fromUser); // if $fromUser=TRUE: generate new session id } else { // vorhandene Session fortgesetzt $this->new = false; } }
[ "protected", "function", "init", "(", "$", "suppressHeadersAlreadySentError", "=", "false", ")", "{", "/**\n * PHP laesst sich ohne weiteres manipulierte Session-IDs unterschieben, solange diese keine ungueltigen Zeichen\n * enthalten (IDs wie PHPSESSID=111 werden anstandslos akzeptiert). Wenn session_start() zurueckkehrt, gibt es mit\n * den vorhandenen PHP-Mitteln keine vernuenftige Moeglichkeit mehr, festzustellen, ob die Session-ID von PHP oder\n * (kuenstlich?) vom User generiert wurde. Daher wird in dieser Methode jede neue Session mit einer zusaetzliche\n * Markierung versehen. Fehlt diese Markierung nach Rueckkehr von session_start(), wurde die ID nicht von PHP\n * generiert. Aus Sicherheitsgruenden wird eine solche Session verworfen und eine neue ID erzeugt.\n */", "$", "request", "=", "$", "this", "->", "request", ";", "// Session-Cookie auf Application beschraenken, um mehrere Projekte je Domain zu ermoeglichen", "$", "params", "=", "session_get_cookie_params", "(", ")", ";", "session_set_cookie_params", "(", "$", "params", "[", "'lifetime'", "]", ",", "$", "request", "->", "getApplicationBaseUri", "(", ")", ",", "$", "params", "[", "'domain'", "]", ",", "$", "params", "[", "'secure'", "]", ",", "$", "params", "[", "'httponly'", "]", ")", ";", "// Session starten bzw. fortsetzen", "try", "{", "session_start", "(", ")", ";", "// TODO: Handle the case when a session was already started elsewhere?", "}", "catch", "(", "PHPError", "$", "error", ")", "{", "if", "(", "preg_match", "(", "'/The session id contains illegal characters/'", ",", "$", "error", "->", "getMessage", "(", ")", ")", ")", "{", "session_regenerate_id", "(", ")", ";", "// neue ID generieren", "}", "else", "if", "(", "preg_match", "(", "'/- headers already sent (by )?\\(output started at /'", ",", "$", "error", "->", "getMessage", "(", ")", ")", ")", "{", "if", "(", "!", "$", "suppressHeadersAlreadySentError", ")", "throw", "$", "error", ";", "}", "else", "{", "throw", "$", "error", ";", "}", "}", "// Inhalt der Session pruefen", "// TODO: Session verwerfen, wenn der User zwischen Cookie- und URL-Uebertragung wechselt", "if", "(", "sizeof", "(", "$", "_SESSION", ")", "==", "0", ")", "{", "// 0 bedeutet, die Session ist (fuer diese Methode) neu", "$", "sessionName", "=", "session_name", "(", ")", ";", "$", "sessionId", "=", "session_id", "(", ")", ";", "// pruefen, woher die ID kommt ...", "// TODO: Verwendung von $_COOKIE und $_REQUEST ist unsicher", "if", "(", "isset", "(", "$", "_COOKIE", "[", "$", "sessionName", "]", ")", "&&", "$", "_COOKIE", "[", "$", "sessionName", "]", "==", "$", "sessionId", ")", "$", "fromUser", "=", "true", ";", "// ID kommt vom Cookie", "elseif", "(", "isset", "(", "$", "_REQUEST", "[", "$", "sessionName", "]", ")", "&&", "$", "_REQUEST", "[", "$", "sessionName", "]", "==", "$", "sessionId", ")", "$", "fromUser", "=", "true", ";", "// ID kommt aus GET/POST", "else", "$", "fromUser", "=", "false", ";", "$", "this", "->", "reset", "(", "$", "fromUser", ")", ";", "// if $fromUser=TRUE: generate new session id", "}", "else", "{", "// vorhandene Session fortgesetzt", "$", "this", "->", "new", "=", "false", ";", "}", "}" ]
Start and initialize the session. @param bool $suppressHeadersAlreadySentError [optional] - whether to suppress "headers already sent" errors (default: no)
[ "Start", "and", "initialize", "the", "session", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/HttpSession.php#L60-L113
29,004
rosasurfer/ministruts
src/ministruts/HttpSession.php
HttpSession.reset
public function reset($regenerateId) { if (!is_bool($regenerateId)) throw new IllegalTypeException('Illegal type of parameter $regenerateId: '.gettype($regenerateId)); if ($regenerateId) { // assign new id, delete old file session_regenerate_id(true); } // empty the session $this->removeAttribute(\array_keys($_SESSION)); // initialize the session $request = $this->request; // TODO: $request->getHeader() einbauen $_SESSION['__SESSION_CREATED__' ] = microtime(true); $_SESSION['__SESSION_IP__' ] = $request->getRemoteAddress(); // TODO: forwarded remote IP einbauen $_SESSION['__SESSION_USERAGENT__'] = $request->getHeaderValue('User-Agent'); $this->new = true; }
php
public function reset($regenerateId) { if (!is_bool($regenerateId)) throw new IllegalTypeException('Illegal type of parameter $regenerateId: '.gettype($regenerateId)); if ($regenerateId) { // assign new id, delete old file session_regenerate_id(true); } // empty the session $this->removeAttribute(\array_keys($_SESSION)); // initialize the session $request = $this->request; // TODO: $request->getHeader() einbauen $_SESSION['__SESSION_CREATED__' ] = microtime(true); $_SESSION['__SESSION_IP__' ] = $request->getRemoteAddress(); // TODO: forwarded remote IP einbauen $_SESSION['__SESSION_USERAGENT__'] = $request->getHeaderValue('User-Agent'); $this->new = true; }
[ "public", "function", "reset", "(", "$", "regenerateId", ")", "{", "if", "(", "!", "is_bool", "(", "$", "regenerateId", ")", ")", "throw", "new", "IllegalTypeException", "(", "'Illegal type of parameter $regenerateId: '", ".", "gettype", "(", "$", "regenerateId", ")", ")", ";", "if", "(", "$", "regenerateId", ")", "{", "// assign new id, delete old file", "session_regenerate_id", "(", "true", ")", ";", "}", "// empty the session", "$", "this", "->", "removeAttribute", "(", "\\", "array_keys", "(", "$", "_SESSION", ")", ")", ";", "// initialize the session", "$", "request", "=", "$", "this", "->", "request", ";", "// TODO: $request->getHeader() einbauen", "$", "_SESSION", "[", "'__SESSION_CREATED__'", "]", "=", "microtime", "(", "true", ")", ";", "$", "_SESSION", "[", "'__SESSION_IP__'", "]", "=", "$", "request", "->", "getRemoteAddress", "(", ")", ";", "// TODO: forwarded remote IP einbauen", "$", "_SESSION", "[", "'__SESSION_USERAGENT__'", "]", "=", "$", "request", "->", "getHeaderValue", "(", "'User-Agent'", ")", ";", "$", "this", "->", "new", "=", "true", ";", "}" ]
Reset this session to a clean and new state. @param bool $regenerateId - whether to generate a new session id and to delete an old session file
[ "Reset", "this", "session", "to", "a", "clean", "and", "new", "state", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/HttpSession.php#L121-L139
29,005
rosasurfer/ministruts
src/ministruts/HttpSession.php
HttpSession.setAttribute
public function setAttribute($key, $value) { if (!is_string($key)) throw new IllegalTypeException('Illegal type of parameter $key: '.gettype($key)); if ($value !== null) { $_SESSION[$key] = $value; } else { $this->removeAttribute($key); } }
php
public function setAttribute($key, $value) { if (!is_string($key)) throw new IllegalTypeException('Illegal type of parameter $key: '.gettype($key)); if ($value !== null) { $_SESSION[$key] = $value; } else { $this->removeAttribute($key); } }
[ "public", "function", "setAttribute", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "!", "is_string", "(", "$", "key", ")", ")", "throw", "new", "IllegalTypeException", "(", "'Illegal type of parameter $key: '", ".", "gettype", "(", "$", "key", ")", ")", ";", "if", "(", "$", "value", "!==", "null", ")", "{", "$", "_SESSION", "[", "$", "key", "]", "=", "$", "value", ";", "}", "else", "{", "$", "this", "->", "removeAttribute", "(", "$", "key", ")", ";", "}", "}" ]
Speichert in der Session unter dem angegebenen Schluessel einen Wert. Ein unter dem selben Schluessel schon vorhandener Wert wird ersetzt. Ist der uebergebene Wert NULL, hat dies den selben Effekt wie der Aufruf von HttpSession::removeAttribute($key) @param string $key - Schluessel, unter dem der Wert gespeichert wird @param mixed $value - der zu speichernde Wert
[ "Speichert", "in", "der", "Session", "unter", "dem", "angegebenen", "Schluessel", "einen", "Wert", ".", "Ein", "unter", "dem", "selben", "Schluessel", "schon", "vorhandener", "Wert", "wird", "ersetzt", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/HttpSession.php#L198-L207
29,006
locomotivemtl/charcoal-core
src/Charcoal/Source/Expression.php
Expression.setCondition
public function setCondition($condition) { if ($condition === null) { $this->condition = $condition; return $this; } if (!is_string($condition)) { throw new InvalidArgumentException( 'Custom expression must be a string.' ); } $condition = trim($condition); if ($condition === '') { $condition = null; } $this->condition = $condition; return $this; }
php
public function setCondition($condition) { if ($condition === null) { $this->condition = $condition; return $this; } if (!is_string($condition)) { throw new InvalidArgumentException( 'Custom expression must be a string.' ); } $condition = trim($condition); if ($condition === '') { $condition = null; } $this->condition = $condition; return $this; }
[ "public", "function", "setCondition", "(", "$", "condition", ")", "{", "if", "(", "$", "condition", "===", "null", ")", "{", "$", "this", "->", "condition", "=", "$", "condition", ";", "return", "$", "this", ";", "}", "if", "(", "!", "is_string", "(", "$", "condition", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Custom expression must be a string.'", ")", ";", "}", "$", "condition", "=", "trim", "(", "$", "condition", ")", ";", "if", "(", "$", "condition", "===", "''", ")", "{", "$", "condition", "=", "null", ";", "}", "$", "this", "->", "condition", "=", "$", "condition", ";", "return", "$", "this", ";", "}" ]
Set the custom query expression. @param string|null $condition The custom query expression. @throws InvalidArgumentException If the parameter is not a valid string expression. @return self
[ "Set", "the", "custom", "query", "expression", "." ]
db3a7af547ccf96efe2d9be028b252bc8646f5d5
https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Expression.php#L78-L98
29,007
dereuromark/cakephp-feedback
src/Store/FilesystemStore.php
FilesystemStore.saveFile
protected function saveFile(array $object, $location) { //Serialize and save the object to a store in the Cake's tmp dir. if (!file_exists($location)) { if (!mkdir($location, 0770, true)) { //Throw error, directory is requird throw new NotFoundException('Could not create directory to save feedbacks in. Please provide write rights to webserver user on directory: ' . $location); } } if (file_put_contents($location . $object['filename'], serialize($object))) { //Add filename to data return true; } return false; }
php
protected function saveFile(array $object, $location) { //Serialize and save the object to a store in the Cake's tmp dir. if (!file_exists($location)) { if (!mkdir($location, 0770, true)) { //Throw error, directory is requird throw new NotFoundException('Could not create directory to save feedbacks in. Please provide write rights to webserver user on directory: ' . $location); } } if (file_put_contents($location . $object['filename'], serialize($object))) { //Add filename to data return true; } return false; }
[ "protected", "function", "saveFile", "(", "array", "$", "object", ",", "$", "location", ")", "{", "//Serialize and save the object to a store in the Cake's tmp dir.", "if", "(", "!", "file_exists", "(", "$", "location", ")", ")", "{", "if", "(", "!", "mkdir", "(", "$", "location", ",", "0770", ",", "true", ")", ")", "{", "//Throw error, directory is requird", "throw", "new", "NotFoundException", "(", "'Could not create directory to save feedbacks in. Please provide write rights to webserver user on directory: '", ".", "$", "location", ")", ";", "}", "}", "if", "(", "file_put_contents", "(", "$", "location", ".", "$", "object", "[", "'filename'", "]", ",", "serialize", "(", "$", "object", ")", ")", ")", "{", "//Add filename to data", "return", "true", ";", "}", "return", "false", ";", "}" ]
Auxiliary function that saves the file @param array $object @param string $location @return bool
[ "Auxiliary", "function", "that", "saves", "the", "file" ]
0bd774fda38b3cdd05db8c07a06a526d3ba81879
https://github.com/dereuromark/cakephp-feedback/blob/0bd774fda38b3cdd05db8c07a06a526d3ba81879/src/Store/FilesystemStore.php#L56-L70
29,008
rosasurfer/ministruts
src/net/http/CurlHttpClient.php
CurlHttpClient.send
public function send(HttpRequest $request) { if (!is_resource($this->hCurl)) $this->hCurl = curl_init(); $response = new CurlHttpResponse(); $options = $this->prepareCurlOptions($request, $response); // CURLOPT_FOLLOWLOCATION funktioniert nur bei deaktiviertem "open_basedir"-Setting if (!ini_get('open_basedir')) { if ($this->isFollowRedirects()) { $options[CURLOPT_FOLLOWLOCATION] = true; } elseif (isset($options[CURLOPT_FOLLOWLOCATION]) && $options[CURLOPT_FOLLOWLOCATION]) { $this->setFollowRedirects(true); } if ($this->isFollowRedirects()) { !isset($options[CURLOPT_MAXREDIRS]) && $options[CURLOPT_MAXREDIRS]=$this->maxRedirects; } } if ($request->getMethod() == 'POST') { $options[CURLOPT_POST ] = true; $options[CURLOPT_URL ] = substr($request->getUrl(), 0, strpos($request->getUrl(), '?')); $options[CURLOPT_POSTFIELDS] = strstr($request->getUrl(), '?'); } curl_setopt_array($this->hCurl, $options); // Request ausfuehren if (curl_exec($this->hCurl) === false) throw new IOException('cURL error '.self::getError($this->hCurl).','.NL.'URL: '.$request->getUrl()); $status = curl_getinfo($this->hCurl, CURLINFO_HTTP_CODE); $response->setStatus($status); // ggf. manuellen Redirect ausfuehren (falls "open_basedir" aktiviert ist) if (($status==301 || $status==302) && $this->isFollowRedirects() && ini_get('open_basedir')) { if ($this->manualRedirects >= $this->maxRedirects) throw new IOException('CURL error: maxRedirects limit exceeded - '.$this->maxRedirects.', URL: '.$request->getUrl()); $this->manualRedirects++; /** @var string $location */ $location = $response->getHeader('Location'); // TODO: relative Redirects abfangen Logger::log('Performing manual redirect to: '.$location, L_INFO); // TODO: verschachtelte IOExceptions abfangen $request = new HttpRequest($location); $response = $this->send($request); } return $response; }
php
public function send(HttpRequest $request) { if (!is_resource($this->hCurl)) $this->hCurl = curl_init(); $response = new CurlHttpResponse(); $options = $this->prepareCurlOptions($request, $response); // CURLOPT_FOLLOWLOCATION funktioniert nur bei deaktiviertem "open_basedir"-Setting if (!ini_get('open_basedir')) { if ($this->isFollowRedirects()) { $options[CURLOPT_FOLLOWLOCATION] = true; } elseif (isset($options[CURLOPT_FOLLOWLOCATION]) && $options[CURLOPT_FOLLOWLOCATION]) { $this->setFollowRedirects(true); } if ($this->isFollowRedirects()) { !isset($options[CURLOPT_MAXREDIRS]) && $options[CURLOPT_MAXREDIRS]=$this->maxRedirects; } } if ($request->getMethod() == 'POST') { $options[CURLOPT_POST ] = true; $options[CURLOPT_URL ] = substr($request->getUrl(), 0, strpos($request->getUrl(), '?')); $options[CURLOPT_POSTFIELDS] = strstr($request->getUrl(), '?'); } curl_setopt_array($this->hCurl, $options); // Request ausfuehren if (curl_exec($this->hCurl) === false) throw new IOException('cURL error '.self::getError($this->hCurl).','.NL.'URL: '.$request->getUrl()); $status = curl_getinfo($this->hCurl, CURLINFO_HTTP_CODE); $response->setStatus($status); // ggf. manuellen Redirect ausfuehren (falls "open_basedir" aktiviert ist) if (($status==301 || $status==302) && $this->isFollowRedirects() && ini_get('open_basedir')) { if ($this->manualRedirects >= $this->maxRedirects) throw new IOException('CURL error: maxRedirects limit exceeded - '.$this->maxRedirects.', URL: '.$request->getUrl()); $this->manualRedirects++; /** @var string $location */ $location = $response->getHeader('Location'); // TODO: relative Redirects abfangen Logger::log('Performing manual redirect to: '.$location, L_INFO); // TODO: verschachtelte IOExceptions abfangen $request = new HttpRequest($location); $response = $this->send($request); } return $response; }
[ "public", "function", "send", "(", "HttpRequest", "$", "request", ")", "{", "if", "(", "!", "is_resource", "(", "$", "this", "->", "hCurl", ")", ")", "$", "this", "->", "hCurl", "=", "curl_init", "(", ")", ";", "$", "response", "=", "new", "CurlHttpResponse", "(", ")", ";", "$", "options", "=", "$", "this", "->", "prepareCurlOptions", "(", "$", "request", ",", "$", "response", ")", ";", "// CURLOPT_FOLLOWLOCATION funktioniert nur bei deaktiviertem \"open_basedir\"-Setting", "if", "(", "!", "ini_get", "(", "'open_basedir'", ")", ")", "{", "if", "(", "$", "this", "->", "isFollowRedirects", "(", ")", ")", "{", "$", "options", "[", "CURLOPT_FOLLOWLOCATION", "]", "=", "true", ";", "}", "elseif", "(", "isset", "(", "$", "options", "[", "CURLOPT_FOLLOWLOCATION", "]", ")", "&&", "$", "options", "[", "CURLOPT_FOLLOWLOCATION", "]", ")", "{", "$", "this", "->", "setFollowRedirects", "(", "true", ")", ";", "}", "if", "(", "$", "this", "->", "isFollowRedirects", "(", ")", ")", "{", "!", "isset", "(", "$", "options", "[", "CURLOPT_MAXREDIRS", "]", ")", "&&", "$", "options", "[", "CURLOPT_MAXREDIRS", "]", "=", "$", "this", "->", "maxRedirects", ";", "}", "}", "if", "(", "$", "request", "->", "getMethod", "(", ")", "==", "'POST'", ")", "{", "$", "options", "[", "CURLOPT_POST", "]", "=", "true", ";", "$", "options", "[", "CURLOPT_URL", "]", "=", "substr", "(", "$", "request", "->", "getUrl", "(", ")", ",", "0", ",", "strpos", "(", "$", "request", "->", "getUrl", "(", ")", ",", "'?'", ")", ")", ";", "$", "options", "[", "CURLOPT_POSTFIELDS", "]", "=", "strstr", "(", "$", "request", "->", "getUrl", "(", ")", ",", "'?'", ")", ";", "}", "curl_setopt_array", "(", "$", "this", "->", "hCurl", ",", "$", "options", ")", ";", "// Request ausfuehren", "if", "(", "curl_exec", "(", "$", "this", "->", "hCurl", ")", "===", "false", ")", "throw", "new", "IOException", "(", "'cURL error '", ".", "self", "::", "getError", "(", "$", "this", "->", "hCurl", ")", ".", "','", ".", "NL", ".", "'URL: '", ".", "$", "request", "->", "getUrl", "(", ")", ")", ";", "$", "status", "=", "curl_getinfo", "(", "$", "this", "->", "hCurl", ",", "CURLINFO_HTTP_CODE", ")", ";", "$", "response", "->", "setStatus", "(", "$", "status", ")", ";", "// ggf. manuellen Redirect ausfuehren (falls \"open_basedir\" aktiviert ist)", "if", "(", "(", "$", "status", "==", "301", "||", "$", "status", "==", "302", ")", "&&", "$", "this", "->", "isFollowRedirects", "(", ")", "&&", "ini_get", "(", "'open_basedir'", ")", ")", "{", "if", "(", "$", "this", "->", "manualRedirects", ">=", "$", "this", "->", "maxRedirects", ")", "throw", "new", "IOException", "(", "'CURL error: maxRedirects limit exceeded - '", ".", "$", "this", "->", "maxRedirects", ".", "', URL: '", ".", "$", "request", "->", "getUrl", "(", ")", ")", ";", "$", "this", "->", "manualRedirects", "++", ";", "/** @var string $location */", "$", "location", "=", "$", "response", "->", "getHeader", "(", "'Location'", ")", ";", "// TODO: relative Redirects abfangen", "Logger", "::", "log", "(", "'Performing manual redirect to: '", ".", "$", "location", ",", "L_INFO", ")", ";", "// TODO: verschachtelte IOExceptions abfangen", "$", "request", "=", "new", "HttpRequest", "(", "$", "location", ")", ";", "$", "response", "=", "$", "this", "->", "send", "(", "$", "request", ")", ";", "}", "return", "$", "response", ";", "}" ]
Fuehrt den uebergebenen Request aus und gibt die empfangene Antwort zurueck. @param HttpRequest $request @return HttpResponse @throws IOException wenn ein Fehler auftritt
[ "Fuehrt", "den", "uebergebenen", "Request", "aus", "und", "gibt", "die", "empfangene", "Antwort", "zurueck", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/net/http/CurlHttpClient.php#L181-L226
29,009
rosasurfer/ministruts
src/net/http/CurlHttpClient.php
CurlHttpClient.prepareCurlOptions
protected function prepareCurlOptions(HttpRequest $request, CurlHttpResponse $response) { $options = [CURLOPT_URL => $request->getUrl()] + $this->options; $options += [CURLOPT_TIMEOUT => $this->timeout ]; $options += [CURLOPT_USERAGENT => $this->userAgent ]; $options += [CURLOPT_ENCODING => '' ]; // empty string activates all supported encodings if (!isset($options[CURLOPT_WRITEHEADER])) $options += [CURLOPT_HEADERFUNCTION => [$response, 'writeHeader']]; if (!isset($options[CURLOPT_FILE])) // overrides CURLOPT_RETURNTRANSFER $options += [CURLOPT_WRITEFUNCTION => [$response, 'writeContent']]; foreach ($request->getHeaders() as $key => $value) { // add all specified request headers $options[CURLOPT_HTTPHEADER][] = $key.': '.$value; } return $options; }
php
protected function prepareCurlOptions(HttpRequest $request, CurlHttpResponse $response) { $options = [CURLOPT_URL => $request->getUrl()] + $this->options; $options += [CURLOPT_TIMEOUT => $this->timeout ]; $options += [CURLOPT_USERAGENT => $this->userAgent ]; $options += [CURLOPT_ENCODING => '' ]; // empty string activates all supported encodings if (!isset($options[CURLOPT_WRITEHEADER])) $options += [CURLOPT_HEADERFUNCTION => [$response, 'writeHeader']]; if (!isset($options[CURLOPT_FILE])) // overrides CURLOPT_RETURNTRANSFER $options += [CURLOPT_WRITEFUNCTION => [$response, 'writeContent']]; foreach ($request->getHeaders() as $key => $value) { // add all specified request headers $options[CURLOPT_HTTPHEADER][] = $key.': '.$value; } return $options; }
[ "protected", "function", "prepareCurlOptions", "(", "HttpRequest", "$", "request", ",", "CurlHttpResponse", "$", "response", ")", "{", "$", "options", "=", "[", "CURLOPT_URL", "=>", "$", "request", "->", "getUrl", "(", ")", "]", "+", "$", "this", "->", "options", ";", "$", "options", "+=", "[", "CURLOPT_TIMEOUT", "=>", "$", "this", "->", "timeout", "]", ";", "$", "options", "+=", "[", "CURLOPT_USERAGENT", "=>", "$", "this", "->", "userAgent", "]", ";", "$", "options", "+=", "[", "CURLOPT_ENCODING", "=>", "''", "]", ";", "// empty string activates all supported encodings", "if", "(", "!", "isset", "(", "$", "options", "[", "CURLOPT_WRITEHEADER", "]", ")", ")", "$", "options", "+=", "[", "CURLOPT_HEADERFUNCTION", "=>", "[", "$", "response", ",", "'writeHeader'", "]", "]", ";", "if", "(", "!", "isset", "(", "$", "options", "[", "CURLOPT_FILE", "]", ")", ")", "// overrides CURLOPT_RETURNTRANSFER", "$", "options", "+=", "[", "CURLOPT_WRITEFUNCTION", "=>", "[", "$", "response", ",", "'writeContent'", "]", "]", ";", "foreach", "(", "$", "request", "->", "getHeaders", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "// add all specified request headers", "$", "options", "[", "CURLOPT_HTTPHEADER", "]", "[", "]", "=", "$", "key", ".", "': '", ".", "$", "value", ";", "}", "return", "$", "options", ";", "}" ]
Create a cUrl options array for the current request. @param HttpRequest $request @param CurlHttpResponse $response @return array - resulting options
[ "Create", "a", "cUrl", "options", "array", "for", "the", "current", "request", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/net/http/CurlHttpClient.php#L237-L253
29,010
rosasurfer/ministruts
src/net/http/CurlHttpClient.php
CurlHttpClient.getError
protected static function getError($hCurl) { $errorNo = curl_errno($hCurl); $errorStr = curl_error($hCurl); if (isset(self::$errors[$errorNo])) { $errorNo = self::$errors[$errorNo]; } else { Logger::log('Unknown CURL error code: '.$errorNo, L_WARN); } return $errorNo.' ('.$errorStr.')'; }
php
protected static function getError($hCurl) { $errorNo = curl_errno($hCurl); $errorStr = curl_error($hCurl); if (isset(self::$errors[$errorNo])) { $errorNo = self::$errors[$errorNo]; } else { Logger::log('Unknown CURL error code: '.$errorNo, L_WARN); } return $errorNo.' ('.$errorStr.')'; }
[ "protected", "static", "function", "getError", "(", "$", "hCurl", ")", "{", "$", "errorNo", "=", "curl_errno", "(", "$", "hCurl", ")", ";", "$", "errorStr", "=", "curl_error", "(", "$", "hCurl", ")", ";", "if", "(", "isset", "(", "self", "::", "$", "errors", "[", "$", "errorNo", "]", ")", ")", "{", "$", "errorNo", "=", "self", "::", "$", "errors", "[", "$", "errorNo", "]", ";", "}", "else", "{", "Logger", "::", "log", "(", "'Unknown CURL error code: '", ".", "$", "errorNo", ",", "L_WARN", ")", ";", "}", "return", "$", "errorNo", ".", "' ('", ".", "$", "errorStr", ".", "')'", ";", "}" ]
Gibt eine Beschreibung des letzten CURL-Fehlers zurueck. @param resource $hCurl - CURL-Handle @return string
[ "Gibt", "eine", "Beschreibung", "des", "letzten", "CURL", "-", "Fehlers", "zurueck", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/net/http/CurlHttpClient.php#L263-L275
29,011
timble/kodekit
code/template/helper/behavior.php
TemplateHelperBehavior.validator
public function validator($config = array()) { $config = new ObjectConfigJson($config); $config->append(array( 'debug' => \Kodekit::getInstance()->isDebug(), 'selector' => '.k-js-form-controller', 'options_callback' => null, 'options' => array( 'ignoreTitle' => true, 'onsubmit' => false // We run the validation ourselves ) )); $html = ''; if(!static::isLoaded('validator')) { $html .= $this->kodekit(); $html .= '<ktml:script src="assets://js/'.($config->debug ? 'build/' : 'min/').'jquery.validate.js" />'; static::setLoaded('validator'); } $options = (string) $config->options; $signature = md5('validator-'.$config->selector.$config->options_callback.$options); if (!static::isLoaded($signature)) { if ($config->options_callback) { $options = $config->options_callback.'('.$options.')'; } $html .= "<script> kQuery(function($){ $('$config->selector').on('k:validate', function(event){ if(!$(this).valid() || $(this).validate().pendingRequest !== 0) { event.preventDefault(); } }).validate($options); }); </script>"; static::setLoaded($signature); } return $html; }
php
public function validator($config = array()) { $config = new ObjectConfigJson($config); $config->append(array( 'debug' => \Kodekit::getInstance()->isDebug(), 'selector' => '.k-js-form-controller', 'options_callback' => null, 'options' => array( 'ignoreTitle' => true, 'onsubmit' => false // We run the validation ourselves ) )); $html = ''; if(!static::isLoaded('validator')) { $html .= $this->kodekit(); $html .= '<ktml:script src="assets://js/'.($config->debug ? 'build/' : 'min/').'jquery.validate.js" />'; static::setLoaded('validator'); } $options = (string) $config->options; $signature = md5('validator-'.$config->selector.$config->options_callback.$options); if (!static::isLoaded($signature)) { if ($config->options_callback) { $options = $config->options_callback.'('.$options.')'; } $html .= "<script> kQuery(function($){ $('$config->selector').on('k:validate', function(event){ if(!$(this).valid() || $(this).validate().pendingRequest !== 0) { event.preventDefault(); } }).validate($options); }); </script>"; static::setLoaded($signature); } return $html; }
[ "public", "function", "validator", "(", "$", "config", "=", "array", "(", ")", ")", "{", "$", "config", "=", "new", "ObjectConfigJson", "(", "$", "config", ")", ";", "$", "config", "->", "append", "(", "array", "(", "'debug'", "=>", "\\", "Kodekit", "::", "getInstance", "(", ")", "->", "isDebug", "(", ")", ",", "'selector'", "=>", "'.k-js-form-controller'", ",", "'options_callback'", "=>", "null", ",", "'options'", "=>", "array", "(", "'ignoreTitle'", "=>", "true", ",", "'onsubmit'", "=>", "false", "// We run the validation ourselves", ")", ")", ")", ";", "$", "html", "=", "''", ";", "if", "(", "!", "static", "::", "isLoaded", "(", "'validator'", ")", ")", "{", "$", "html", ".=", "$", "this", "->", "kodekit", "(", ")", ";", "$", "html", ".=", "'<ktml:script src=\"assets://js/'", ".", "(", "$", "config", "->", "debug", "?", "'build/'", ":", "'min/'", ")", ".", "'jquery.validate.js\" />'", ";", "static", "::", "setLoaded", "(", "'validator'", ")", ";", "}", "$", "options", "=", "(", "string", ")", "$", "config", "->", "options", ";", "$", "signature", "=", "md5", "(", "'validator-'", ".", "$", "config", "->", "selector", ".", "$", "config", "->", "options_callback", ".", "$", "options", ")", ";", "if", "(", "!", "static", "::", "isLoaded", "(", "$", "signature", ")", ")", "{", "if", "(", "$", "config", "->", "options_callback", ")", "{", "$", "options", "=", "$", "config", "->", "options_callback", ".", "'('", ".", "$", "options", ".", "')'", ";", "}", "$", "html", ".=", "\"<script>\n kQuery(function($){\n $('$config->selector').on('k:validate', function(event){\n if(!$(this).valid() || $(this).validate().pendingRequest !== 0) {\n event.preventDefault();\n }\n }).validate($options);\n });\n </script>\"", ";", "static", "::", "setLoaded", "(", "$", "signature", ")", ";", "}", "return", "$", "html", ";", "}" ]
Loads the Forms.Validator class and connects it to Kodekit.Controller.Form @param array|ObjectConfig $config @return string The html output
[ "Loads", "the", "Forms", ".", "Validator", "class", "and", "connects", "it", "to", "Kodekit", ".", "Controller", ".", "Form" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/template/helper/behavior.php#L398-L444
29,012
timble/kodekit
code/template/helper/behavior.php
TemplateHelperBehavior.tree
public function tree($config = array()) { $config = new ObjectConfigJson($config); $config->append(array( 'debug' => false, 'element' => '', 'selected' => '', 'list' => array() ))->append(array( 'options_callback' => null, 'options' => array( 'selected' => $config->selected ) )); $html = ''; /** * Loading the assets, if not already loaded */ if (!static::isLoaded('tree')) { $html .= $this->kodekit(); $html .= '<ktml:script src="assets://js/'.($config->debug ? 'build/' : 'min/').'kodekit.tree.js" />'; static::setLoaded('tree'); } /** * Parse and validate list data, if any. And load the inline js that initiates the tree on specified html element */ $signature = md5('tree-'.$config->element); if($config->element && !static::isLoaded($signature)) { /** * If there's a list set, but no 'data' in the js options, parse it */ if(isset($config->list) && !isset($config->options->data)) { $data = array(); foreach($config->list as $item) { $parts = explode('/', $item->path); array_pop($parts); // remove current id $data[] = array( 'label' => $item->title, 'id' => (int)$item->id, 'level' => (int)$item->level, 'path' => $item->path, 'parent' => (int)array_pop($parts) ); } $config->options->append(array('data' => $data)); } /** * Validate that the data is the right format */ elseif(isset($config->options->data, $config->options->data[0])) { $data = $config->options->data[0]; $required = array('label', 'id', 'level', 'path', 'parent'); foreach($required as $key) { if(!isset($data[$key])) { throw new \InvalidArgumentException('Data must contain required param: '.$key); } } } $options = (string) $config->options; if ($config->options_callback) { $options = $config->options_callback.'('.$options.')'; } $html .= '<script> kQuery(function($){ new Kodekit.Tree('.json_encode($config->element).', '.$options.'); });</script>'; static::setLoaded($signature); } return $html; }
php
public function tree($config = array()) { $config = new ObjectConfigJson($config); $config->append(array( 'debug' => false, 'element' => '', 'selected' => '', 'list' => array() ))->append(array( 'options_callback' => null, 'options' => array( 'selected' => $config->selected ) )); $html = ''; /** * Loading the assets, if not already loaded */ if (!static::isLoaded('tree')) { $html .= $this->kodekit(); $html .= '<ktml:script src="assets://js/'.($config->debug ? 'build/' : 'min/').'kodekit.tree.js" />'; static::setLoaded('tree'); } /** * Parse and validate list data, if any. And load the inline js that initiates the tree on specified html element */ $signature = md5('tree-'.$config->element); if($config->element && !static::isLoaded($signature)) { /** * If there's a list set, but no 'data' in the js options, parse it */ if(isset($config->list) && !isset($config->options->data)) { $data = array(); foreach($config->list as $item) { $parts = explode('/', $item->path); array_pop($parts); // remove current id $data[] = array( 'label' => $item->title, 'id' => (int)$item->id, 'level' => (int)$item->level, 'path' => $item->path, 'parent' => (int)array_pop($parts) ); } $config->options->append(array('data' => $data)); } /** * Validate that the data is the right format */ elseif(isset($config->options->data, $config->options->data[0])) { $data = $config->options->data[0]; $required = array('label', 'id', 'level', 'path', 'parent'); foreach($required as $key) { if(!isset($data[$key])) { throw new \InvalidArgumentException('Data must contain required param: '.$key); } } } $options = (string) $config->options; if ($config->options_callback) { $options = $config->options_callback.'('.$options.')'; } $html .= '<script> kQuery(function($){ new Kodekit.Tree('.json_encode($config->element).', '.$options.'); });</script>'; static::setLoaded($signature); } return $html; }
[ "public", "function", "tree", "(", "$", "config", "=", "array", "(", ")", ")", "{", "$", "config", "=", "new", "ObjectConfigJson", "(", "$", "config", ")", ";", "$", "config", "->", "append", "(", "array", "(", "'debug'", "=>", "false", ",", "'element'", "=>", "''", ",", "'selected'", "=>", "''", ",", "'list'", "=>", "array", "(", ")", ")", ")", "->", "append", "(", "array", "(", "'options_callback'", "=>", "null", ",", "'options'", "=>", "array", "(", "'selected'", "=>", "$", "config", "->", "selected", ")", ")", ")", ";", "$", "html", "=", "''", ";", "/**\n * Loading the assets, if not already loaded\n */", "if", "(", "!", "static", "::", "isLoaded", "(", "'tree'", ")", ")", "{", "$", "html", ".=", "$", "this", "->", "kodekit", "(", ")", ";", "$", "html", ".=", "'<ktml:script src=\"assets://js/'", ".", "(", "$", "config", "->", "debug", "?", "'build/'", ":", "'min/'", ")", ".", "'kodekit.tree.js\" />'", ";", "static", "::", "setLoaded", "(", "'tree'", ")", ";", "}", "/**\n * Parse and validate list data, if any. And load the inline js that initiates the tree on specified html element\n */", "$", "signature", "=", "md5", "(", "'tree-'", ".", "$", "config", "->", "element", ")", ";", "if", "(", "$", "config", "->", "element", "&&", "!", "static", "::", "isLoaded", "(", "$", "signature", ")", ")", "{", "/**\n * If there's a list set, but no 'data' in the js options, parse it\n */", "if", "(", "isset", "(", "$", "config", "->", "list", ")", "&&", "!", "isset", "(", "$", "config", "->", "options", "->", "data", ")", ")", "{", "$", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "config", "->", "list", "as", "$", "item", ")", "{", "$", "parts", "=", "explode", "(", "'/'", ",", "$", "item", "->", "path", ")", ";", "array_pop", "(", "$", "parts", ")", ";", "// remove current id", "$", "data", "[", "]", "=", "array", "(", "'label'", "=>", "$", "item", "->", "title", ",", "'id'", "=>", "(", "int", ")", "$", "item", "->", "id", ",", "'level'", "=>", "(", "int", ")", "$", "item", "->", "level", ",", "'path'", "=>", "$", "item", "->", "path", ",", "'parent'", "=>", "(", "int", ")", "array_pop", "(", "$", "parts", ")", ")", ";", "}", "$", "config", "->", "options", "->", "append", "(", "array", "(", "'data'", "=>", "$", "data", ")", ")", ";", "}", "/**\n * Validate that the data is the right format\n */", "elseif", "(", "isset", "(", "$", "config", "->", "options", "->", "data", ",", "$", "config", "->", "options", "->", "data", "[", "0", "]", ")", ")", "{", "$", "data", "=", "$", "config", "->", "options", "->", "data", "[", "0", "]", ";", "$", "required", "=", "array", "(", "'label'", ",", "'id'", ",", "'level'", ",", "'path'", ",", "'parent'", ")", ";", "foreach", "(", "$", "required", "as", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "data", "[", "$", "key", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Data must contain required param: '", ".", "$", "key", ")", ";", "}", "}", "}", "$", "options", "=", "(", "string", ")", "$", "config", "->", "options", ";", "if", "(", "$", "config", "->", "options_callback", ")", "{", "$", "options", "=", "$", "config", "->", "options_callback", ".", "'('", ".", "$", "options", ".", "')'", ";", "}", "$", "html", ".=", "'<script>\n kQuery(function($){\n new Kodekit.Tree('", ".", "json_encode", "(", "$", "config", "->", "element", ")", ".", "', '", ".", "$", "options", ".", "');\n });</script>'", ";", "static", "::", "setLoaded", "(", "$", "signature", ")", ";", "}", "return", "$", "html", ";", "}" ]
Loads the Kodekit customized jQtree behavior and renders a sidebar-nav list useful in split views @see http://mbraak.github.io/jqTree/ @note If no 'element' option is passed, then only assets will be loaded. @param array|ObjectConfig $config @throws \InvalidArgumentException @return string The html output
[ "Loads", "the", "Kodekit", "customized", "jQtree", "behavior", "and", "renders", "a", "sidebar", "-", "nav", "list", "useful", "in", "split", "views" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/template/helper/behavior.php#L631-L715
29,013
rosasurfer/ministruts
src/console/io/Output.php
Output.out
public function out($message) { $message = printPretty($message, $return=true); $hStream = CLI ? \STDOUT : fopen('php://stdout', 'a'); fwrite($hStream, $message); if (!CLI) fclose($hStream); }
php
public function out($message) { $message = printPretty($message, $return=true); $hStream = CLI ? \STDOUT : fopen('php://stdout', 'a'); fwrite($hStream, $message); if (!CLI) fclose($hStream); }
[ "public", "function", "out", "(", "$", "message", ")", "{", "$", "message", "=", "printPretty", "(", "$", "message", ",", "$", "return", "=", "true", ")", ";", "$", "hStream", "=", "CLI", "?", "\\", "STDOUT", ":", "fopen", "(", "'php://stdout'", ",", "'a'", ")", ";", "fwrite", "(", "$", "hStream", ",", "$", "message", ")", ";", "if", "(", "!", "CLI", ")", "fclose", "(", "$", "hStream", ")", ";", "}" ]
Write a message to STDOUT. @param mixed $message
[ "Write", "a", "message", "to", "STDOUT", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/console/io/Output.php#L22-L28
29,014
rosasurfer/ministruts
src/console/io/Output.php
Output.error
public function error($message) { $message = printPretty($message, $return=true); $hStream = CLI ? \STDERR : fopen('php://stderr', 'a'); fwrite($hStream, $message); if (!CLI) fclose($hStream); }
php
public function error($message) { $message = printPretty($message, $return=true); $hStream = CLI ? \STDERR : fopen('php://stderr', 'a'); fwrite($hStream, $message); if (!CLI) fclose($hStream); }
[ "public", "function", "error", "(", "$", "message", ")", "{", "$", "message", "=", "printPretty", "(", "$", "message", ",", "$", "return", "=", "true", ")", ";", "$", "hStream", "=", "CLI", "?", "\\", "STDERR", ":", "fopen", "(", "'php://stderr'", ",", "'a'", ")", ";", "fwrite", "(", "$", "hStream", ",", "$", "message", ")", ";", "if", "(", "!", "CLI", ")", "fclose", "(", "$", "hStream", ")", ";", "}" ]
Write a message to STDERR. @param mixed $message
[ "Write", "a", "message", "to", "STDERR", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/console/io/Output.php#L36-L42
29,015
rosasurfer/ministruts
src/net/http/HeaderParser.php
HeaderParser.parseLines
public function parseLines($data) { $lines = explode("\n", $data); foreach ($lines as $line) $this->parseLine($line); return $this; }
php
public function parseLines($data) { $lines = explode("\n", $data); foreach ($lines as $line) $this->parseLine($line); return $this; }
[ "public", "function", "parseLines", "(", "$", "data", ")", "{", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "data", ")", ";", "foreach", "(", "$", "lines", "as", "$", "line", ")", "$", "this", "->", "parseLine", "(", "$", "line", ")", ";", "return", "$", "this", ";", "}" ]
Parst einen uebergebenen Headerblock. @param string $data - rohe Headerdaten @return $this
[ "Parst", "einen", "uebergebenen", "Headerblock", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/net/http/HeaderParser.php#L27-L34
29,016
rosasurfer/ministruts
src/net/http/HeaderParser.php
HeaderParser.parseLine
public function parseLine($line) { $line = trim($line, "\r\n"); if (preg_match('/^([\w-]+):\s+(.+)/', $line, $matches)) { $name = strtolower($matches[1]); $value = $matches[2]; $this->currentHeader = $name; if (isset($this->headers[$name])) { if (!is_array($this->headers[$name])) { $this->headers[$name] = [$this->headers[$name]]; } $this->headers[$name][] = $value; } else { $this->headers[$name] = $value; } } elseif (preg_match('/^\s+(.+)$/', $line, $matches) && $this->currentHeader !== null) { if (is_array($this->headers[$this->currentHeader])) { $lastKey = sizeof($this->headers[$this->currentHeader]) - 1; $this->headers[$this->currentHeader][$lastKey] .= $matches[1]; } else { $this->headers[$this->currentHeader] .= $matches[1]; } } return $this; }
php
public function parseLine($line) { $line = trim($line, "\r\n"); if (preg_match('/^([\w-]+):\s+(.+)/', $line, $matches)) { $name = strtolower($matches[1]); $value = $matches[2]; $this->currentHeader = $name; if (isset($this->headers[$name])) { if (!is_array($this->headers[$name])) { $this->headers[$name] = [$this->headers[$name]]; } $this->headers[$name][] = $value; } else { $this->headers[$name] = $value; } } elseif (preg_match('/^\s+(.+)$/', $line, $matches) && $this->currentHeader !== null) { if (is_array($this->headers[$this->currentHeader])) { $lastKey = sizeof($this->headers[$this->currentHeader]) - 1; $this->headers[$this->currentHeader][$lastKey] .= $matches[1]; } else { $this->headers[$this->currentHeader] .= $matches[1]; } } return $this; }
[ "public", "function", "parseLine", "(", "$", "line", ")", "{", "$", "line", "=", "trim", "(", "$", "line", ",", "\"\\r\\n\"", ")", ";", "if", "(", "preg_match", "(", "'/^([\\w-]+):\\s+(.+)/'", ",", "$", "line", ",", "$", "matches", ")", ")", "{", "$", "name", "=", "strtolower", "(", "$", "matches", "[", "1", "]", ")", ";", "$", "value", "=", "$", "matches", "[", "2", "]", ";", "$", "this", "->", "currentHeader", "=", "$", "name", ";", "if", "(", "isset", "(", "$", "this", "->", "headers", "[", "$", "name", "]", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "this", "->", "headers", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "headers", "[", "$", "name", "]", "=", "[", "$", "this", "->", "headers", "[", "$", "name", "]", "]", ";", "}", "$", "this", "->", "headers", "[", "$", "name", "]", "[", "]", "=", "$", "value", ";", "}", "else", "{", "$", "this", "->", "headers", "[", "$", "name", "]", "=", "$", "value", ";", "}", "}", "elseif", "(", "preg_match", "(", "'/^\\s+(.+)$/'", ",", "$", "line", ",", "$", "matches", ")", "&&", "$", "this", "->", "currentHeader", "!==", "null", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "headers", "[", "$", "this", "->", "currentHeader", "]", ")", ")", "{", "$", "lastKey", "=", "sizeof", "(", "$", "this", "->", "headers", "[", "$", "this", "->", "currentHeader", "]", ")", "-", "1", ";", "$", "this", "->", "headers", "[", "$", "this", "->", "currentHeader", "]", "[", "$", "lastKey", "]", ".=", "$", "matches", "[", "1", "]", ";", "}", "else", "{", "$", "this", "->", "headers", "[", "$", "this", "->", "currentHeader", "]", ".=", "$", "matches", "[", "1", "]", ";", "}", "}", "return", "$", "this", ";", "}" ]
Parst eine einzelne Headerzeile. @param string $line - Headerzeile @return $this
[ "Parst", "eine", "einzelne", "Headerzeile", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/net/http/HeaderParser.php#L44-L73
29,017
timble/kodekit
code/dispatcher/authenticator/cookie.php
DispatcherAuthenticatorCookie.authenticateRequest
public function authenticateRequest(DispatcherContext $context) { $session = $context->getUser()->getSession(); $request = $context->getRequest(); if(!$session->isActive()) { if ($request->getCookies()->has($this->getConfig()->cookie_name)) { //Logging the user by auto-start the session $this->loginUser(); //Perform CSRF authentication parent::authenticateRequest($context); return true; } } }
php
public function authenticateRequest(DispatcherContext $context) { $session = $context->getUser()->getSession(); $request = $context->getRequest(); if(!$session->isActive()) { if ($request->getCookies()->has($this->getConfig()->cookie_name)) { //Logging the user by auto-start the session $this->loginUser(); //Perform CSRF authentication parent::authenticateRequest($context); return true; } } }
[ "public", "function", "authenticateRequest", "(", "DispatcherContext", "$", "context", ")", "{", "$", "session", "=", "$", "context", "->", "getUser", "(", ")", "->", "getSession", "(", ")", ";", "$", "request", "=", "$", "context", "->", "getRequest", "(", ")", ";", "if", "(", "!", "$", "session", "->", "isActive", "(", ")", ")", "{", "if", "(", "$", "request", "->", "getCookies", "(", ")", "->", "has", "(", "$", "this", "->", "getConfig", "(", ")", "->", "cookie_name", ")", ")", "{", "//Logging the user by auto-start the session", "$", "this", "->", "loginUser", "(", ")", ";", "//Perform CSRF authentication", "parent", "::", "authenticateRequest", "(", "$", "context", ")", ";", "return", "true", ";", "}", "}", "}" ]
Authenticate using the cookie session id If a session cookie is found and the session session is not active it will be auto-started. @param DispatcherContext $context A dispatcher context object @return boolean Returns TRUE if the authentication explicitly succeeded.
[ "Authenticate", "using", "the", "cookie", "session", "id" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/dispatcher/authenticator/cookie.php#L70-L88
29,018
rinvex/cortex-tenants
src/Http/Controllers/Adminarea/TenantsController.php
TenantsController.import
public function import(Tenant $tenant, ImportRecordsDataTable $importRecordsDataTable) { return $importRecordsDataTable->with([ 'resource' => $tenant, 'tabs' => 'adminarea.tenants.tabs', 'url' => route('adminarea.tenants.stash'), 'id' => "adminarea-tenants-{$tenant->getRouteKey()}-import-table", ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
php
public function import(Tenant $tenant, ImportRecordsDataTable $importRecordsDataTable) { return $importRecordsDataTable->with([ 'resource' => $tenant, 'tabs' => 'adminarea.tenants.tabs', 'url' => route('adminarea.tenants.stash'), 'id' => "adminarea-tenants-{$tenant->getRouteKey()}-import-table", ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
[ "public", "function", "import", "(", "Tenant", "$", "tenant", ",", "ImportRecordsDataTable", "$", "importRecordsDataTable", ")", "{", "return", "$", "importRecordsDataTable", "->", "with", "(", "[", "'resource'", "=>", "$", "tenant", ",", "'tabs'", "=>", "'adminarea.tenants.tabs'", ",", "'url'", "=>", "route", "(", "'adminarea.tenants.stash'", ")", ",", "'id'", "=>", "\"adminarea-tenants-{$tenant->getRouteKey()}-import-table\"", ",", "]", ")", "->", "render", "(", "'cortex/foundation::adminarea.pages.datatable-dropzone'", ")", ";", "}" ]
Import tenants. @param \Cortex\Tenants\Models\Tenant $tenant @param \Cortex\Foundation\DataTables\ImportRecordsDataTable $importRecordsDataTable @return \Illuminate\View\View
[ "Import", "tenants", "." ]
b837a3d14fd4cf6bfb35f41c61ef41ee9a05a34a
https://github.com/rinvex/cortex-tenants/blob/b837a3d14fd4cf6bfb35f41c61ef41ee9a05a34a/src/Http/Controllers/Adminarea/TenantsController.php#L65-L73
29,019
rinvex/cortex-tenants
src/Http/Controllers/Adminarea/TenantsController.php
TenantsController.destroy
public function destroy(Tenant $tenant) { $tenant->delete(); return intend([ 'url' => route('adminarea.tenants.index'), 'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/tenants::common.tenant'), 'identifier' => $tenant->name])], ]); }
php
public function destroy(Tenant $tenant) { $tenant->delete(); return intend([ 'url' => route('adminarea.tenants.index'), 'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/tenants::common.tenant'), 'identifier' => $tenant->name])], ]); }
[ "public", "function", "destroy", "(", "Tenant", "$", "tenant", ")", "{", "$", "tenant", "->", "delete", "(", ")", ";", "return", "intend", "(", "[", "'url'", "=>", "route", "(", "'adminarea.tenants.index'", ")", ",", "'with'", "=>", "[", "'warning'", "=>", "trans", "(", "'cortex/foundation::messages.resource_deleted'", ",", "[", "'resource'", "=>", "trans", "(", "'cortex/tenants::common.tenant'", ")", ",", "'identifier'", "=>", "$", "tenant", "->", "name", "]", ")", "]", ",", "]", ")", ";", "}" ]
Destroy given tenant. @param \Cortex\Tenants\Models\Tenant $tenant @throws \Exception @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
[ "Destroy", "given", "tenant", "." ]
b837a3d14fd4cf6bfb35f41c61ef41ee9a05a34a
https://github.com/rinvex/cortex-tenants/blob/b837a3d14fd4cf6bfb35f41c61ef41ee9a05a34a/src/Http/Controllers/Adminarea/TenantsController.php#L231-L239
29,020
rosasurfer/ministruts
src/debug/DebugHelper.php
DebugHelper.fixTrace
public static function fixTrace(array $trace, $file='unknown', $line=0) { // check if the stacktrace is already fixed if ($trace && isset($trace[0]['fixed'])) return $trace; // Fix an incomplete frame[0][line] if parameters are provided and $file matches (e.g. with SimpleXMLElement). if ($file!='unknown' && $line) { if (isset($trace[0]['file']) && $trace[0]['file']==$file) { if (isset($trace[0]['line']) && $trace[0]['line']===0) { $trace[0]['line'] = $line; } } } // Add a frame for the main script to the bottom (end of array). $trace[] = ['function' => '{main}']; // Move FILE and LINE fields down (to the end) by one position. for ($i=sizeof($trace); $i--;) { if (isset($trace[$i-1]['file'])) $trace[$i]['file'] = $trace[$i-1]['file']; else unset($trace[$i]['file']); if (isset($trace[$i-1]['line'])) $trace[$i]['line'] = $trace[$i-1]['line']; else unset($trace[$i]['line']); $trace[$i]['fixed'] = true; } // Add location details from parameters to frame[0] only if they differ from the old values (now in frame[1]) if (!isset($trace[1]['file']) || !isset($trace[1]['line']) || $trace[1]['file']!=$file || $trace[1]['line']!=$line) { $trace[0]['file'] = $file; // test with: $trace[0]['line'] = $line; // \SQLite3::enableExceptions(true|false); } // \SQLite3::exec($invalid_sql); else { unset($trace[0]['file'], $trace[0]['line']); // otherwise delete them } // Remove the last frame (the one we added for the main script) if it now points to an unknown location (PHP core). $size = sizeof($trace); if (!isset($trace[$size-1]['file'])) { \array_pop($trace); } return $trace; /** * TODO: fix wrong stack frames originating from calls to virtual static functions * * phalcon\mvc\Model::__callStatic() [php-phalcon] * vokuro\models\Users::findFirstByEmail() # line 27, file: F:\Projekte\phalcon\sample-apps\vokuro\app\library\Auth\Auth.php * vokuro\auth\Auth->check() # line 27, file: F:\Projekte\phalcon\sample-apps\vokuro\app\library\Auth\Auth.php */ }
php
public static function fixTrace(array $trace, $file='unknown', $line=0) { // check if the stacktrace is already fixed if ($trace && isset($trace[0]['fixed'])) return $trace; // Fix an incomplete frame[0][line] if parameters are provided and $file matches (e.g. with SimpleXMLElement). if ($file!='unknown' && $line) { if (isset($trace[0]['file']) && $trace[0]['file']==$file) { if (isset($trace[0]['line']) && $trace[0]['line']===0) { $trace[0]['line'] = $line; } } } // Add a frame for the main script to the bottom (end of array). $trace[] = ['function' => '{main}']; // Move FILE and LINE fields down (to the end) by one position. for ($i=sizeof($trace); $i--;) { if (isset($trace[$i-1]['file'])) $trace[$i]['file'] = $trace[$i-1]['file']; else unset($trace[$i]['file']); if (isset($trace[$i-1]['line'])) $trace[$i]['line'] = $trace[$i-1]['line']; else unset($trace[$i]['line']); $trace[$i]['fixed'] = true; } // Add location details from parameters to frame[0] only if they differ from the old values (now in frame[1]) if (!isset($trace[1]['file']) || !isset($trace[1]['line']) || $trace[1]['file']!=$file || $trace[1]['line']!=$line) { $trace[0]['file'] = $file; // test with: $trace[0]['line'] = $line; // \SQLite3::enableExceptions(true|false); } // \SQLite3::exec($invalid_sql); else { unset($trace[0]['file'], $trace[0]['line']); // otherwise delete them } // Remove the last frame (the one we added for the main script) if it now points to an unknown location (PHP core). $size = sizeof($trace); if (!isset($trace[$size-1]['file'])) { \array_pop($trace); } return $trace; /** * TODO: fix wrong stack frames originating from calls to virtual static functions * * phalcon\mvc\Model::__callStatic() [php-phalcon] * vokuro\models\Users::findFirstByEmail() # line 27, file: F:\Projekte\phalcon\sample-apps\vokuro\app\library\Auth\Auth.php * vokuro\auth\Auth->check() # line 27, file: F:\Projekte\phalcon\sample-apps\vokuro\app\library\Auth\Auth.php */ }
[ "public", "static", "function", "fixTrace", "(", "array", "$", "trace", ",", "$", "file", "=", "'unknown'", ",", "$", "line", "=", "0", ")", "{", "// check if the stacktrace is already fixed", "if", "(", "$", "trace", "&&", "isset", "(", "$", "trace", "[", "0", "]", "[", "'fixed'", "]", ")", ")", "return", "$", "trace", ";", "// Fix an incomplete frame[0][line] if parameters are provided and $file matches (e.g. with SimpleXMLElement).", "if", "(", "$", "file", "!=", "'unknown'", "&&", "$", "line", ")", "{", "if", "(", "isset", "(", "$", "trace", "[", "0", "]", "[", "'file'", "]", ")", "&&", "$", "trace", "[", "0", "]", "[", "'file'", "]", "==", "$", "file", ")", "{", "if", "(", "isset", "(", "$", "trace", "[", "0", "]", "[", "'line'", "]", ")", "&&", "$", "trace", "[", "0", "]", "[", "'line'", "]", "===", "0", ")", "{", "$", "trace", "[", "0", "]", "[", "'line'", "]", "=", "$", "line", ";", "}", "}", "}", "// Add a frame for the main script to the bottom (end of array).", "$", "trace", "[", "]", "=", "[", "'function'", "=>", "'{main}'", "]", ";", "// Move FILE and LINE fields down (to the end) by one position.", "for", "(", "$", "i", "=", "sizeof", "(", "$", "trace", ")", ";", "$", "i", "--", ";", ")", "{", "if", "(", "isset", "(", "$", "trace", "[", "$", "i", "-", "1", "]", "[", "'file'", "]", ")", ")", "$", "trace", "[", "$", "i", "]", "[", "'file'", "]", "=", "$", "trace", "[", "$", "i", "-", "1", "]", "[", "'file'", "]", ";", "else", "unset", "(", "$", "trace", "[", "$", "i", "]", "[", "'file'", "]", ")", ";", "if", "(", "isset", "(", "$", "trace", "[", "$", "i", "-", "1", "]", "[", "'line'", "]", ")", ")", "$", "trace", "[", "$", "i", "]", "[", "'line'", "]", "=", "$", "trace", "[", "$", "i", "-", "1", "]", "[", "'line'", "]", ";", "else", "unset", "(", "$", "trace", "[", "$", "i", "]", "[", "'line'", "]", ")", ";", "$", "trace", "[", "$", "i", "]", "[", "'fixed'", "]", "=", "true", ";", "}", "// Add location details from parameters to frame[0] only if they differ from the old values (now in frame[1])", "if", "(", "!", "isset", "(", "$", "trace", "[", "1", "]", "[", "'file'", "]", ")", "||", "!", "isset", "(", "$", "trace", "[", "1", "]", "[", "'line'", "]", ")", "||", "$", "trace", "[", "1", "]", "[", "'file'", "]", "!=", "$", "file", "||", "$", "trace", "[", "1", "]", "[", "'line'", "]", "!=", "$", "line", ")", "{", "$", "trace", "[", "0", "]", "[", "'file'", "]", "=", "$", "file", ";", "// test with:", "$", "trace", "[", "0", "]", "[", "'line'", "]", "=", "$", "line", ";", "// \\SQLite3::enableExceptions(true|false);", "}", "// \\SQLite3::exec($invalid_sql);", "else", "{", "unset", "(", "$", "trace", "[", "0", "]", "[", "'file'", "]", ",", "$", "trace", "[", "0", "]", "[", "'line'", "]", ")", ";", "// otherwise delete them", "}", "// Remove the last frame (the one we added for the main script) if it now points to an unknown location (PHP core).", "$", "size", "=", "sizeof", "(", "$", "trace", ")", ";", "if", "(", "!", "isset", "(", "$", "trace", "[", "$", "size", "-", "1", "]", "[", "'file'", "]", ")", ")", "{", "\\", "array_pop", "(", "$", "trace", ")", ";", "}", "return", "$", "trace", ";", "/**\n * TODO: fix wrong stack frames originating from calls to virtual static functions\n *\n * phalcon\\mvc\\Model::__callStatic() [php-phalcon]\n * vokuro\\models\\Users::findFirstByEmail() # line 27, file: F:\\Projekte\\phalcon\\sample-apps\\vokuro\\app\\library\\Auth\\Auth.php\n * vokuro\\auth\\Auth->check() # line 27, file: F:\\Projekte\\phalcon\\sample-apps\\vokuro\\app\\library\\Auth\\Auth.php\n */", "}" ]
Take a regular PHP stacktrace and create a fixed and more readable Java-like one. @param array $trace - regular PHP stacktrace @param string $file [optional] - name of the file where the stacktrace was generated @param int $line [optional] - line of the file where the stacktrace was generated @return array - new fixed stacktrace @example original stacktrace: <pre> require_once() # line 5, file: /var/www/phalcon/vokuro/vendor/autoload.php include_once() # line 21, file: /var/www/phalcon/vokuro/app/config/loader.php include() # line 26, file: /var/www/phalcon/vokuro/public/index.php {main} </pre> new stacktrace: <pre> require_once() [php] include_once() # line 5, file: /var/www/phalcon/vokuro/vendor/autoload.php include() # line 21, file: /var/www/phalcon/vokuro/app/config/loader.php {main} # line 26, file: /var/www/phalcon/vokuro/public/index.php </pre>
[ "Take", "a", "regular", "PHP", "stacktrace", "and", "create", "a", "fixed", "and", "more", "readable", "Java", "-", "like", "one", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/debug/DebugHelper.php#L51-L102
29,021
rosasurfer/ministruts
src/debug/DebugHelper.php
DebugHelper.formatTrace
public static function formatTrace(array $trace, $indent = '') { $appRoot = self::di('config')['app.dir.root']; $result = ''; $size = sizeof($trace); $callLen = $lineLen = 0; for ($i=0; $i < $size; $i++) { // align FILE and LINE $frame = &$trace[$i]; $call = self::getFQFunctionName($frame, $nsLowerCase=true); if ($call!='{main}' && !strEndsWith($call, '{closure}')) $call.='()'; $callLen = max($callLen, strlen($call)); $frame['call'] = $call; $frame['line'] = isset($frame['line']) ? ' # line '.$frame['line'].',' : ''; $lineLen = max($lineLen, strlen($frame['line'])); if (isset($frame['file'])) $frame['file'] = ' file: '.(!$appRoot ? $frame['file'] : strRightFrom($frame['file'], $appRoot.DIRECTORY_SEPARATOR, 1, false, $frame['file'])); elseif (strStartsWith($call, 'phalcon\\')) $frame['file'] = ' [php-phalcon]'; else $frame['file'] = ' [php]'; } if ($appRoot) { $trace[] = ['call'=>'', 'line'=>'', 'file'=>' file base: '.$appRoot]; $i++; } for ($i=0; $i < $size; $i++) { $result .= $indent.str_pad($trace[$i]['call'], $callLen).' '.str_pad($trace[$i]['line'], $lineLen).$trace[$i]['file'].NL; } return $result; }
php
public static function formatTrace(array $trace, $indent = '') { $appRoot = self::di('config')['app.dir.root']; $result = ''; $size = sizeof($trace); $callLen = $lineLen = 0; for ($i=0; $i < $size; $i++) { // align FILE and LINE $frame = &$trace[$i]; $call = self::getFQFunctionName($frame, $nsLowerCase=true); if ($call!='{main}' && !strEndsWith($call, '{closure}')) $call.='()'; $callLen = max($callLen, strlen($call)); $frame['call'] = $call; $frame['line'] = isset($frame['line']) ? ' # line '.$frame['line'].',' : ''; $lineLen = max($lineLen, strlen($frame['line'])); if (isset($frame['file'])) $frame['file'] = ' file: '.(!$appRoot ? $frame['file'] : strRightFrom($frame['file'], $appRoot.DIRECTORY_SEPARATOR, 1, false, $frame['file'])); elseif (strStartsWith($call, 'phalcon\\')) $frame['file'] = ' [php-phalcon]'; else $frame['file'] = ' [php]'; } if ($appRoot) { $trace[] = ['call'=>'', 'line'=>'', 'file'=>' file base: '.$appRoot]; $i++; } for ($i=0; $i < $size; $i++) { $result .= $indent.str_pad($trace[$i]['call'], $callLen).' '.str_pad($trace[$i]['line'], $lineLen).$trace[$i]['file'].NL; } return $result; }
[ "public", "static", "function", "formatTrace", "(", "array", "$", "trace", ",", "$", "indent", "=", "''", ")", "{", "$", "appRoot", "=", "self", "::", "di", "(", "'config'", ")", "[", "'app.dir.root'", "]", ";", "$", "result", "=", "''", ";", "$", "size", "=", "sizeof", "(", "$", "trace", ")", ";", "$", "callLen", "=", "$", "lineLen", "=", "0", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "size", ";", "$", "i", "++", ")", "{", "// align FILE and LINE", "$", "frame", "=", "&", "$", "trace", "[", "$", "i", "]", ";", "$", "call", "=", "self", "::", "getFQFunctionName", "(", "$", "frame", ",", "$", "nsLowerCase", "=", "true", ")", ";", "if", "(", "$", "call", "!=", "'{main}'", "&&", "!", "strEndsWith", "(", "$", "call", ",", "'{closure}'", ")", ")", "$", "call", ".=", "'()'", ";", "$", "callLen", "=", "max", "(", "$", "callLen", ",", "strlen", "(", "$", "call", ")", ")", ";", "$", "frame", "[", "'call'", "]", "=", "$", "call", ";", "$", "frame", "[", "'line'", "]", "=", "isset", "(", "$", "frame", "[", "'line'", "]", ")", "?", "' # line '", ".", "$", "frame", "[", "'line'", "]", ".", "','", ":", "''", ";", "$", "lineLen", "=", "max", "(", "$", "lineLen", ",", "strlen", "(", "$", "frame", "[", "'line'", "]", ")", ")", ";", "if", "(", "isset", "(", "$", "frame", "[", "'file'", "]", ")", ")", "$", "frame", "[", "'file'", "]", "=", "' file: '", ".", "(", "!", "$", "appRoot", "?", "$", "frame", "[", "'file'", "]", ":", "strRightFrom", "(", "$", "frame", "[", "'file'", "]", ",", "$", "appRoot", ".", "DIRECTORY_SEPARATOR", ",", "1", ",", "false", ",", "$", "frame", "[", "'file'", "]", ")", ")", ";", "elseif", "(", "strStartsWith", "(", "$", "call", ",", "'phalcon\\\\'", ")", ")", "$", "frame", "[", "'file'", "]", "=", "' [php-phalcon]'", ";", "else", "$", "frame", "[", "'file'", "]", "=", "' [php]'", ";", "}", "if", "(", "$", "appRoot", ")", "{", "$", "trace", "[", "]", "=", "[", "'call'", "=>", "''", ",", "'line'", "=>", "''", ",", "'file'", "=>", "' file base: '", ".", "$", "appRoot", "]", ";", "$", "i", "++", ";", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "size", ";", "$", "i", "++", ")", "{", "$", "result", ".=", "$", "indent", ".", "str_pad", "(", "$", "trace", "[", "$", "i", "]", "[", "'call'", "]", ",", "$", "callLen", ")", ".", "' '", ".", "str_pad", "(", "$", "trace", "[", "$", "i", "]", "[", "'line'", "]", ",", "$", "lineLen", ")", ".", "$", "trace", "[", "$", "i", "]", "[", "'file'", "]", ".", "NL", ";", "}", "return", "$", "result", ";", "}" ]
Return a formatted and human-readable version of a stacktrace. @param array $trace - stacktrace @param string $indent [optional] - indent the formatted lines by this value (default: empty string) @return string
[ "Return", "a", "formatted", "and", "human", "-", "readable", "version", "of", "a", "stacktrace", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/debug/DebugHelper.php#L113-L147
29,022
rosasurfer/ministruts
src/debug/DebugHelper.php
DebugHelper.getFQFunctionName
public static function getFQFunctionName(array $frame, $nsLowerCase = false) { $class = $function = ''; if (isset($frame['function'])) { $function = $frame['function']; if (isset($frame['class'])) { $class = $frame['class']; if ($nsLowerCase && is_int($pos=strrpos($class, '\\'))) $class = strtolower(substr($class, 0, $pos)).substr($class, $pos); $class = $class.$frame['type']; } elseif ($nsLowerCase && is_int($pos=strrpos($function, '\\'))) { $function = strtolower(substr($function, 0, $pos)).substr($function, $pos); } } return $class.$function; }
php
public static function getFQFunctionName(array $frame, $nsLowerCase = false) { $class = $function = ''; if (isset($frame['function'])) { $function = $frame['function']; if (isset($frame['class'])) { $class = $frame['class']; if ($nsLowerCase && is_int($pos=strrpos($class, '\\'))) $class = strtolower(substr($class, 0, $pos)).substr($class, $pos); $class = $class.$frame['type']; } elseif ($nsLowerCase && is_int($pos=strrpos($function, '\\'))) { $function = strtolower(substr($function, 0, $pos)).substr($function, $pos); } } return $class.$function; }
[ "public", "static", "function", "getFQFunctionName", "(", "array", "$", "frame", ",", "$", "nsLowerCase", "=", "false", ")", "{", "$", "class", "=", "$", "function", "=", "''", ";", "if", "(", "isset", "(", "$", "frame", "[", "'function'", "]", ")", ")", "{", "$", "function", "=", "$", "frame", "[", "'function'", "]", ";", "if", "(", "isset", "(", "$", "frame", "[", "'class'", "]", ")", ")", "{", "$", "class", "=", "$", "frame", "[", "'class'", "]", ";", "if", "(", "$", "nsLowerCase", "&&", "is_int", "(", "$", "pos", "=", "strrpos", "(", "$", "class", ",", "'\\\\'", ")", ")", ")", "$", "class", "=", "strtolower", "(", "substr", "(", "$", "class", ",", "0", ",", "$", "pos", ")", ")", ".", "substr", "(", "$", "class", ",", "$", "pos", ")", ";", "$", "class", "=", "$", "class", ".", "$", "frame", "[", "'type'", "]", ";", "}", "elseif", "(", "$", "nsLowerCase", "&&", "is_int", "(", "$", "pos", "=", "strrpos", "(", "$", "function", ",", "'\\\\'", ")", ")", ")", "{", "$", "function", "=", "strtolower", "(", "substr", "(", "$", "function", ",", "0", ",", "$", "pos", ")", ")", ".", "substr", "(", "$", "function", ",", "$", "pos", ")", ";", "}", "}", "return", "$", "class", ".", "$", "function", ";", "}" ]
Return the fully qualified function or method name of a stacktrace's frame. @param array $frame - frame @param bool $nsLowerCase [optional] - whether the namespace part of the name to return in lower case (default: no) @return string - fully qualified name (without trailing parentheses)
[ "Return", "the", "fully", "qualified", "function", "or", "method", "name", "of", "a", "stacktrace", "s", "frame", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/debug/DebugHelper.php#L158-L175
29,023
rosasurfer/ministruts
src/debug/DebugHelper.php
DebugHelper.composeBetterMessage
public static function composeBetterMessage(\Exception $exception, $indent = '') { if ($exception instanceof PHPError) { $result = $exception->getSimpleType(); } else { $class = get_class($exception); $namespace = strtolower(strLeftTo($class, '\\', -1, true, '')); $basename = simpleClassName($class); $result = $indent.$namespace.$basename; if ($exception instanceof \ErrorException) // A PHP error exception not created $result .= '('.self::errorLevelToStr($exception->getSeverity()).')'; // by the framework. } $message = $exception->getMessage(); if (strlen($indent)) { $lines = explode(NL, normalizeEOL($message)); // indent multiline messages $eom = ''; if (strEndsWith($message, NL)) { \array_pop($lines); $eom = NL; } $message = join(NL.$indent, $lines).$eom; } $result .= (strlen($message) ? ': ':'').$message; return $result; }
php
public static function composeBetterMessage(\Exception $exception, $indent = '') { if ($exception instanceof PHPError) { $result = $exception->getSimpleType(); } else { $class = get_class($exception); $namespace = strtolower(strLeftTo($class, '\\', -1, true, '')); $basename = simpleClassName($class); $result = $indent.$namespace.$basename; if ($exception instanceof \ErrorException) // A PHP error exception not created $result .= '('.self::errorLevelToStr($exception->getSeverity()).')'; // by the framework. } $message = $exception->getMessage(); if (strlen($indent)) { $lines = explode(NL, normalizeEOL($message)); // indent multiline messages $eom = ''; if (strEndsWith($message, NL)) { \array_pop($lines); $eom = NL; } $message = join(NL.$indent, $lines).$eom; } $result .= (strlen($message) ? ': ':'').$message; return $result; }
[ "public", "static", "function", "composeBetterMessage", "(", "\\", "Exception", "$", "exception", ",", "$", "indent", "=", "''", ")", "{", "if", "(", "$", "exception", "instanceof", "PHPError", ")", "{", "$", "result", "=", "$", "exception", "->", "getSimpleType", "(", ")", ";", "}", "else", "{", "$", "class", "=", "get_class", "(", "$", "exception", ")", ";", "$", "namespace", "=", "strtolower", "(", "strLeftTo", "(", "$", "class", ",", "'\\\\'", ",", "-", "1", ",", "true", ",", "''", ")", ")", ";", "$", "basename", "=", "simpleClassName", "(", "$", "class", ")", ";", "$", "result", "=", "$", "indent", ".", "$", "namespace", ".", "$", "basename", ";", "if", "(", "$", "exception", "instanceof", "\\", "ErrorException", ")", "// A PHP error exception not created", "$", "result", ".=", "'('", ".", "self", "::", "errorLevelToStr", "(", "$", "exception", "->", "getSeverity", "(", ")", ")", ".", "')'", ";", "// by the framework.", "}", "$", "message", "=", "$", "exception", "->", "getMessage", "(", ")", ";", "if", "(", "strlen", "(", "$", "indent", ")", ")", "{", "$", "lines", "=", "explode", "(", "NL", ",", "normalizeEOL", "(", "$", "message", ")", ")", ";", "// indent multiline messages", "$", "eom", "=", "''", ";", "if", "(", "strEndsWith", "(", "$", "message", ",", "NL", ")", ")", "{", "\\", "array_pop", "(", "$", "lines", ")", ";", "$", "eom", "=", "NL", ";", "}", "$", "message", "=", "join", "(", "NL", ".", "$", "indent", ",", "$", "lines", ")", ".", "$", "eom", ";", "}", "$", "result", ".=", "(", "strlen", "(", "$", "message", ")", "?", "': '", ":", "''", ")", ".", "$", "message", ";", "return", "$", "result", ";", "}" ]
Return a more readable version of an exception's message. @param \Exception $exception - any exception (not only RosasurferExceptions) @param string $indent [optional] - indent lines by this value (default: empty string) @return string - message
[ "Return", "a", "more", "readable", "version", "of", "an", "exception", "s", "message", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/debug/DebugHelper.php#L186-L213
29,024
rosasurfer/ministruts
src/debug/DebugHelper.php
DebugHelper.getBetterTraceAsString
public static function getBetterTraceAsString(\Exception $exception, $indent = '') { if ($exception instanceof IRosasurferException) $trace = $exception->getBetterTrace(); else $trace = self::fixTrace($exception->getTrace(), $exception->getFile(), $exception->getLine()); $result = self::formatTrace($trace, $indent); if ($cause=$exception->getPrevious()) { // recursively add stacktraces of nested exceptions $message = trim(self::composeBetterMessage($cause, $indent)); $result .= NL.$indent.'caused by'.NL.$indent.$message.NL.NL; $result .= self::{__FUNCTION__}($cause, $indent); // recursion } return $result; }
php
public static function getBetterTraceAsString(\Exception $exception, $indent = '') { if ($exception instanceof IRosasurferException) $trace = $exception->getBetterTrace(); else $trace = self::fixTrace($exception->getTrace(), $exception->getFile(), $exception->getLine()); $result = self::formatTrace($trace, $indent); if ($cause=$exception->getPrevious()) { // recursively add stacktraces of nested exceptions $message = trim(self::composeBetterMessage($cause, $indent)); $result .= NL.$indent.'caused by'.NL.$indent.$message.NL.NL; $result .= self::{__FUNCTION__}($cause, $indent); // recursion } return $result; }
[ "public", "static", "function", "getBetterTraceAsString", "(", "\\", "Exception", "$", "exception", ",", "$", "indent", "=", "''", ")", "{", "if", "(", "$", "exception", "instanceof", "IRosasurferException", ")", "$", "trace", "=", "$", "exception", "->", "getBetterTrace", "(", ")", ";", "else", "$", "trace", "=", "self", "::", "fixTrace", "(", "$", "exception", "->", "getTrace", "(", ")", ",", "$", "exception", "->", "getFile", "(", ")", ",", "$", "exception", "->", "getLine", "(", ")", ")", ";", "$", "result", "=", "self", "::", "formatTrace", "(", "$", "trace", ",", "$", "indent", ")", ";", "if", "(", "$", "cause", "=", "$", "exception", "->", "getPrevious", "(", ")", ")", "{", "// recursively add stacktraces of nested exceptions", "$", "message", "=", "trim", "(", "self", "::", "composeBetterMessage", "(", "$", "cause", ",", "$", "indent", ")", ")", ";", "$", "result", ".=", "NL", ".", "$", "indent", ".", "'caused by'", ".", "NL", ".", "$", "indent", ".", "$", "message", ".", "NL", ".", "NL", ";", "$", "result", ".=", "self", "::", "{", "__FUNCTION__", "}", "(", "$", "cause", ",", "$", "indent", ")", ";", "// recursion", "}", "return", "$", "result", ";", "}" ]
Return a more readable version of an exception's stacktrace. The representation also contains information about nested exceptions. @param \Exception $exception - any exception (not only RosasurferExceptions) @param string $indent [optional] - indent the resulting lines by this value (default: empty string) @return string - readable stacktrace
[ "Return", "a", "more", "readable", "version", "of", "an", "exception", "s", "stacktrace", ".", "The", "representation", "also", "contains", "information", "about", "nested", "exceptions", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/debug/DebugHelper.php#L225-L237
29,025
rosasurfer/ministruts
src/debug/DebugHelper.php
DebugHelper.errorLevelToStr
public static function errorLevelToStr($level) { if (!is_int($level)) throw new IllegalTypeException('Illegal type of parameter $level: '.gettype($level)); $levels = [ E_ERROR => 'E_ERROR', // 1 E_WARNING => 'E_WARNING', // 2 E_PARSE => 'E_PARSE', // 4 E_NOTICE => 'E_NOTICE', // 8 E_CORE_ERROR => 'E_CORE_ERROR', // 16 E_CORE_WARNING => 'E_CORE_WARNING', // 32 E_COMPILE_ERROR => 'E_COMPILE_ERROR', // 64 E_COMPILE_WARNING => 'E_COMPILE_WARNING', // 128 E_USER_ERROR => 'E_USER_ERROR', // 256 E_USER_WARNING => 'E_USER_WARNING', // 512 E_USER_NOTICE => 'E_USER_NOTICE', // 1024 E_STRICT => 'E_STRICT', // 2048 E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', // 4096 E_DEPRECATED => 'E_DEPRECATED', // 8192 E_USER_DEPRECATED => 'E_USER_DEPRECATED', // 16384 ]; if (!$level) $levels = ['0']; // 0 else if (($level & E_ALL) == E_ALL) $levels = ['E_ALL']; // 32767 else if (($level & (E_ALL & ~E_DEPRECATED)) == (E_ALL & ~E_DEPRECATED)) $levels = ['E_ALL & ~E_DEPRECATED']; // 24575 else { foreach ($levels as $key => $value) { if ($level & $key) continue; unset($levels[$key]); } } return join('|', $levels); }
php
public static function errorLevelToStr($level) { if (!is_int($level)) throw new IllegalTypeException('Illegal type of parameter $level: '.gettype($level)); $levels = [ E_ERROR => 'E_ERROR', // 1 E_WARNING => 'E_WARNING', // 2 E_PARSE => 'E_PARSE', // 4 E_NOTICE => 'E_NOTICE', // 8 E_CORE_ERROR => 'E_CORE_ERROR', // 16 E_CORE_WARNING => 'E_CORE_WARNING', // 32 E_COMPILE_ERROR => 'E_COMPILE_ERROR', // 64 E_COMPILE_WARNING => 'E_COMPILE_WARNING', // 128 E_USER_ERROR => 'E_USER_ERROR', // 256 E_USER_WARNING => 'E_USER_WARNING', // 512 E_USER_NOTICE => 'E_USER_NOTICE', // 1024 E_STRICT => 'E_STRICT', // 2048 E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', // 4096 E_DEPRECATED => 'E_DEPRECATED', // 8192 E_USER_DEPRECATED => 'E_USER_DEPRECATED', // 16384 ]; if (!$level) $levels = ['0']; // 0 else if (($level & E_ALL) == E_ALL) $levels = ['E_ALL']; // 32767 else if (($level & (E_ALL & ~E_DEPRECATED)) == (E_ALL & ~E_DEPRECATED)) $levels = ['E_ALL & ~E_DEPRECATED']; // 24575 else { foreach ($levels as $key => $value) { if ($level & $key) continue; unset($levels[$key]); } } return join('|', $levels); }
[ "public", "static", "function", "errorLevelToStr", "(", "$", "level", ")", "{", "if", "(", "!", "is_int", "(", "$", "level", ")", ")", "throw", "new", "IllegalTypeException", "(", "'Illegal type of parameter $level: '", ".", "gettype", "(", "$", "level", ")", ")", ";", "$", "levels", "=", "[", "E_ERROR", "=>", "'E_ERROR'", ",", "// 1", "E_WARNING", "=>", "'E_WARNING'", ",", "// 2", "E_PARSE", "=>", "'E_PARSE'", ",", "// 4", "E_NOTICE", "=>", "'E_NOTICE'", ",", "// 8", "E_CORE_ERROR", "=>", "'E_CORE_ERROR'", ",", "// 16", "E_CORE_WARNING", "=>", "'E_CORE_WARNING'", ",", "// 32", "E_COMPILE_ERROR", "=>", "'E_COMPILE_ERROR'", ",", "// 64", "E_COMPILE_WARNING", "=>", "'E_COMPILE_WARNING'", ",", "// 128", "E_USER_ERROR", "=>", "'E_USER_ERROR'", ",", "// 256", "E_USER_WARNING", "=>", "'E_USER_WARNING'", ",", "// 512", "E_USER_NOTICE", "=>", "'E_USER_NOTICE'", ",", "// 1024", "E_STRICT", "=>", "'E_STRICT'", ",", "// 2048", "E_RECOVERABLE_ERROR", "=>", "'E_RECOVERABLE_ERROR'", ",", "// 4096", "E_DEPRECATED", "=>", "'E_DEPRECATED'", ",", "// 8192", "E_USER_DEPRECATED", "=>", "'E_USER_DEPRECATED'", ",", "// 16384", "]", ";", "if", "(", "!", "$", "level", ")", "$", "levels", "=", "[", "'0'", "]", ";", "// 0", "else", "if", "(", "(", "$", "level", "&", "E_ALL", ")", "==", "E_ALL", ")", "$", "levels", "=", "[", "'E_ALL'", "]", ";", "// 32767", "else", "if", "(", "(", "$", "level", "&", "(", "E_ALL", "&", "~", "E_DEPRECATED", ")", ")", "==", "(", "E_ALL", "&", "~", "E_DEPRECATED", ")", ")", "$", "levels", "=", "[", "'E_ALL & ~E_DEPRECATED'", "]", ";", "// 24575", "else", "{", "foreach", "(", "$", "levels", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "level", "&", "$", "key", ")", "continue", ";", "unset", "(", "$", "levels", "[", "$", "key", "]", ")", ";", "}", "}", "return", "join", "(", "'|'", ",", "$", "levels", ")", ";", "}" ]
Return a human-readable form of the specified error reporting level. @param int $level - error reporting level @return string
[ "Return", "a", "human", "-", "readable", "form", "of", "the", "specified", "error", "reporting", "level", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/debug/DebugHelper.php#L247-L278
29,026
timble/kodekit
code/object/bootstrapper/bootstrapper.php
ObjectBootstrapper.registerFile
public function registerFile($path) { $hash = md5($path); if(!isset($this->_files[$hash])) { $this->_files[$hash] = $path; } return $this; }
php
public function registerFile($path) { $hash = md5($path); if(!isset($this->_files[$hash])) { $this->_files[$hash] = $path; } return $this; }
[ "public", "function", "registerFile", "(", "$", "path", ")", "{", "$", "hash", "=", "md5", "(", "$", "path", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_files", "[", "$", "hash", "]", ")", ")", "{", "$", "this", "->", "_files", "[", "$", "hash", "]", "=", "$", "path", ";", "}", "return", "$", "this", ";", "}" ]
Register a configuration file to be bootstrapped @param string $path The absolute path to the file @return ObjectBootstrapper
[ "Register", "a", "configuration", "file", "to", "be", "bootstrapped" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/object/bootstrapper/bootstrapper.php#L415-L424
29,027
timble/kodekit
code/object/bootstrapper/bootstrapper.php
ObjectBootstrapper.getComponents
public function getComponents($domain = null) { $components = $result = array_keys($this->_components); if($domain) { foreach($components as $key => $component) { if(strpos($component, 'com://'.$domain) === false) { unset($components[$key]); } } } return $components; }
php
public function getComponents($domain = null) { $components = $result = array_keys($this->_components); if($domain) { foreach($components as $key => $component) { if(strpos($component, 'com://'.$domain) === false) { unset($components[$key]); } } } return $components; }
[ "public", "function", "getComponents", "(", "$", "domain", "=", "null", ")", "{", "$", "components", "=", "$", "result", "=", "array_keys", "(", "$", "this", "->", "_components", ")", ";", "if", "(", "$", "domain", ")", "{", "foreach", "(", "$", "components", "as", "$", "key", "=>", "$", "component", ")", "{", "if", "(", "strpos", "(", "$", "component", ",", "'com://'", ".", "$", "domain", ")", "===", "false", ")", "{", "unset", "(", "$", "components", "[", "$", "key", "]", ")", ";", "}", "}", "}", "return", "$", "components", ";", "}" ]
Get the registered components @param string $domain The component domain. Domain is optional and can be NULL @return array
[ "Get", "the", "registered", "components" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/object/bootstrapper/bootstrapper.php#L432-L447
29,028
timble/kodekit
code/object/bootstrapper/bootstrapper.php
ObjectBootstrapper.getComponentManifest
public function getComponentManifest($name, $domain = null) { $result = false; $paths = $this->getComponentPaths($name, $domain); if(!empty($paths)) { $path = $paths[0]; if(!isset($this->_manifests[$path]) || is_array($this->_manifests[$path])) { if($paths = $this->getComponentPaths($name, $domain)) { $info = $this->getObject('object.config.factory')->fromFile($path . '/component.json'); $this->_manifests[$path] = $info; } else $this->_manifests[$path] = false; } $result = $this->_manifests[$path]; } return $result; }
php
public function getComponentManifest($name, $domain = null) { $result = false; $paths = $this->getComponentPaths($name, $domain); if(!empty($paths)) { $path = $paths[0]; if(!isset($this->_manifests[$path]) || is_array($this->_manifests[$path])) { if($paths = $this->getComponentPaths($name, $domain)) { $info = $this->getObject('object.config.factory')->fromFile($path . '/component.json'); $this->_manifests[$path] = $info; } else $this->_manifests[$path] = false; } $result = $this->_manifests[$path]; } return $result; }
[ "public", "function", "getComponentManifest", "(", "$", "name", ",", "$", "domain", "=", "null", ")", "{", "$", "result", "=", "false", ";", "$", "paths", "=", "$", "this", "->", "getComponentPaths", "(", "$", "name", ",", "$", "domain", ")", ";", "if", "(", "!", "empty", "(", "$", "paths", ")", ")", "{", "$", "path", "=", "$", "paths", "[", "0", "]", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_manifests", "[", "$", "path", "]", ")", "||", "is_array", "(", "$", "this", "->", "_manifests", "[", "$", "path", "]", ")", ")", "{", "if", "(", "$", "paths", "=", "$", "this", "->", "getComponentPaths", "(", "$", "name", ",", "$", "domain", ")", ")", "{", "$", "info", "=", "$", "this", "->", "getObject", "(", "'object.config.factory'", ")", "->", "fromFile", "(", "$", "path", ".", "'/component.json'", ")", ";", "$", "this", "->", "_manifests", "[", "$", "path", "]", "=", "$", "info", ";", "}", "else", "$", "this", "->", "_manifests", "[", "$", "path", "]", "=", "false", ";", "}", "$", "result", "=", "$", "this", "->", "_manifests", "[", "$", "path", "]", ";", "}", "return", "$", "result", ";", "}" ]
Get manifest for a registered component @link https://en.wikipedia.org/wiki/Manifest_file @param string $name The component name @param string $domain The component domain. Domain is optional and can be NULL @return ObjectConfigJson|false Returns the component manifest or FALSE if the component couldn't be found.
[ "Get", "manifest", "for", "a", "registered", "component" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/object/bootstrapper/bootstrapper.php#L495-L518
29,029
timble/kodekit
code/event/subscriber/factory.php
EventSubscriberFactory.registerSubscriber
public function registerSubscriber($identifier, array $config = array()) { $result = false; //Create the complete identifier if a partial identifier was passed if (is_string($identifier) && strpos($identifier, '.') === false) { $identifier = $this->getIdentifier()->toArray(); $identifier['path'] = array('event', 'subscriber'); $identifier['name'] = $identifier; } $identifier = $this->getIdentifier($identifier); $class = $this->getObject('manager')->getClass($identifier); if(!$class || !array_key_exists('Kodekit\Library\EventSubscriberInterface', class_implements($class))) { throw new \UnexpectedValueException( 'Event Subscriber: '.$identifier.' does not implement Kodekit\Library\EventSubscriberInterface' ); } if (!isset($this->__subscribers[(string)$identifier])) { $listeners = call_user_func(array($class, 'getEventListeners'));/*$class::getEventListeners();*/ if (!empty($listeners)) { $identifier->getConfig()->merge($config); foreach($listeners as $listener) { $this->__listeners[$listener][] = $identifier; } } $this->__subscribers[(string)$identifier] = true; } return $result; }
php
public function registerSubscriber($identifier, array $config = array()) { $result = false; //Create the complete identifier if a partial identifier was passed if (is_string($identifier) && strpos($identifier, '.') === false) { $identifier = $this->getIdentifier()->toArray(); $identifier['path'] = array('event', 'subscriber'); $identifier['name'] = $identifier; } $identifier = $this->getIdentifier($identifier); $class = $this->getObject('manager')->getClass($identifier); if(!$class || !array_key_exists('Kodekit\Library\EventSubscriberInterface', class_implements($class))) { throw new \UnexpectedValueException( 'Event Subscriber: '.$identifier.' does not implement Kodekit\Library\EventSubscriberInterface' ); } if (!isset($this->__subscribers[(string)$identifier])) { $listeners = call_user_func(array($class, 'getEventListeners'));/*$class::getEventListeners();*/ if (!empty($listeners)) { $identifier->getConfig()->merge($config); foreach($listeners as $listener) { $this->__listeners[$listener][] = $identifier; } } $this->__subscribers[(string)$identifier] = true; } return $result; }
[ "public", "function", "registerSubscriber", "(", "$", "identifier", ",", "array", "$", "config", "=", "array", "(", ")", ")", "{", "$", "result", "=", "false", ";", "//Create the complete identifier if a partial identifier was passed", "if", "(", "is_string", "(", "$", "identifier", ")", "&&", "strpos", "(", "$", "identifier", ",", "'.'", ")", "===", "false", ")", "{", "$", "identifier", "=", "$", "this", "->", "getIdentifier", "(", ")", "->", "toArray", "(", ")", ";", "$", "identifier", "[", "'path'", "]", "=", "array", "(", "'event'", ",", "'subscriber'", ")", ";", "$", "identifier", "[", "'name'", "]", "=", "$", "identifier", ";", "}", "$", "identifier", "=", "$", "this", "->", "getIdentifier", "(", "$", "identifier", ")", ";", "$", "class", "=", "$", "this", "->", "getObject", "(", "'manager'", ")", "->", "getClass", "(", "$", "identifier", ")", ";", "if", "(", "!", "$", "class", "||", "!", "array_key_exists", "(", "'Kodekit\\Library\\EventSubscriberInterface'", ",", "class_implements", "(", "$", "class", ")", ")", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "'Event Subscriber: '", ".", "$", "identifier", ".", "' does not implement Kodekit\\Library\\EventSubscriberInterface'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "__subscribers", "[", "(", "string", ")", "$", "identifier", "]", ")", ")", "{", "$", "listeners", "=", "call_user_func", "(", "array", "(", "$", "class", ",", "'getEventListeners'", ")", ")", ";", "/*$class::getEventListeners();*/", "if", "(", "!", "empty", "(", "$", "listeners", ")", ")", "{", "$", "identifier", "->", "getConfig", "(", ")", "->", "merge", "(", "$", "config", ")", ";", "foreach", "(", "$", "listeners", "as", "$", "listener", ")", "{", "$", "this", "->", "__listeners", "[", "$", "listener", "]", "[", "]", "=", "$", "identifier", ";", "}", "}", "$", "this", "->", "__subscribers", "[", "(", "string", ")", "$", "identifier", "]", "=", "true", ";", "}", "return", "$", "result", ";", "}" ]
Register an subscriber @param string $identifier A subscriber identifier string @param array $config An optional associative array of configuration options @throws \UnexpectedValueException @return bool Returns TRUE on success, FALSE on failure.
[ "Register", "an", "subscriber" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/event/subscriber/factory.php#L88-L127
29,030
timble/kodekit
code/dispatcher/behavior/limitable.php
DispatcherBehaviorLimitable._beforeGet
protected function _beforeGet(DispatcherContext $context) { $controller = $this->getController(); if($controller instanceof ControllerModellable) { $controller->getModel()->getState()->setProperty('limit', 'default', $this->getConfig()->default); $limit = $this->getRequest()->query->get('limit', 'int'); // Set to default if there is no limit. This is done for both unique and non-unique states // so that limit can be transparently used on unique state requests rendering lists. if(empty($limit)) { $limit = $this->getConfig()->default; } if($this->getConfig()->max && $limit > $this->getConfig()->max) { $limit = $this->getConfig()->max; } $this->getRequest()->query->limit = $limit; $controller->getModel()->getState()->limit = $limit; } }
php
protected function _beforeGet(DispatcherContext $context) { $controller = $this->getController(); if($controller instanceof ControllerModellable) { $controller->getModel()->getState()->setProperty('limit', 'default', $this->getConfig()->default); $limit = $this->getRequest()->query->get('limit', 'int'); // Set to default if there is no limit. This is done for both unique and non-unique states // so that limit can be transparently used on unique state requests rendering lists. if(empty($limit)) { $limit = $this->getConfig()->default; } if($this->getConfig()->max && $limit > $this->getConfig()->max) { $limit = $this->getConfig()->max; } $this->getRequest()->query->limit = $limit; $controller->getModel()->getState()->limit = $limit; } }
[ "protected", "function", "_beforeGet", "(", "DispatcherContext", "$", "context", ")", "{", "$", "controller", "=", "$", "this", "->", "getController", "(", ")", ";", "if", "(", "$", "controller", "instanceof", "ControllerModellable", ")", "{", "$", "controller", "->", "getModel", "(", ")", "->", "getState", "(", ")", "->", "setProperty", "(", "'limit'", ",", "'default'", ",", "$", "this", "->", "getConfig", "(", ")", "->", "default", ")", ";", "$", "limit", "=", "$", "this", "->", "getRequest", "(", ")", "->", "query", "->", "get", "(", "'limit'", ",", "'int'", ")", ";", "// Set to default if there is no limit. This is done for both unique and non-unique states", "// so that limit can be transparently used on unique state requests rendering lists.", "if", "(", "empty", "(", "$", "limit", ")", ")", "{", "$", "limit", "=", "$", "this", "->", "getConfig", "(", ")", "->", "default", ";", "}", "if", "(", "$", "this", "->", "getConfig", "(", ")", "->", "max", "&&", "$", "limit", ">", "$", "this", "->", "getConfig", "(", ")", "->", "max", ")", "{", "$", "limit", "=", "$", "this", "->", "getConfig", "(", ")", "->", "max", ";", "}", "$", "this", "->", "getRequest", "(", ")", "->", "query", "->", "limit", "=", "$", "limit", ";", "$", "controller", "->", "getModel", "(", ")", "->", "getState", "(", ")", "->", "limit", "=", "$", "limit", ";", "}", "}" ]
Sets a maximum and a default limit for GET requests @param DispatcherContext $context The active command context @return void
[ "Sets", "a", "maximum", "and", "a", "default", "limit", "for", "GET", "requests" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/dispatcher/behavior/limitable.php#L45-L68
29,031
timble/kodekit
code/template/helper/abstract.php
TemplateHelperAbstract.setTemplate
public function setTemplate($template) { if(!$template instanceof TemplateInterface) { if(empty($template) || (is_string($template) && strpos($template, '.') === false) ) { $identifier = $this->getIdentifier()->toArray(); $identifier['path'] = array('template'); $identifier['name'] = $template; $identifier = $this->getIdentifier($identifier); } else $identifier = $this->getIdentifier($template); $template = $identifier; } $this->__template = $template; return $this->__template; }
php
public function setTemplate($template) { if(!$template instanceof TemplateInterface) { if(empty($template) || (is_string($template) && strpos($template, '.') === false) ) { $identifier = $this->getIdentifier()->toArray(); $identifier['path'] = array('template'); $identifier['name'] = $template; $identifier = $this->getIdentifier($identifier); } else $identifier = $this->getIdentifier($template); $template = $identifier; } $this->__template = $template; return $this->__template; }
[ "public", "function", "setTemplate", "(", "$", "template", ")", "{", "if", "(", "!", "$", "template", "instanceof", "TemplateInterface", ")", "{", "if", "(", "empty", "(", "$", "template", ")", "||", "(", "is_string", "(", "$", "template", ")", "&&", "strpos", "(", "$", "template", ",", "'.'", ")", "===", "false", ")", ")", "{", "$", "identifier", "=", "$", "this", "->", "getIdentifier", "(", ")", "->", "toArray", "(", ")", ";", "$", "identifier", "[", "'path'", "]", "=", "array", "(", "'template'", ")", ";", "$", "identifier", "[", "'name'", "]", "=", "$", "template", ";", "$", "identifier", "=", "$", "this", "->", "getIdentifier", "(", "$", "identifier", ")", ";", "}", "else", "$", "identifier", "=", "$", "this", "->", "getIdentifier", "(", "$", "template", ")", ";", "$", "template", "=", "$", "identifier", ";", "}", "$", "this", "->", "__template", "=", "$", "template", ";", "return", "$", "this", "->", "__template", ";", "}" ]
Sets the template object @param TemplateInterface $template @return $this
[ "Sets", "the", "template", "object" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/template/helper/abstract.php#L85-L105
29,032
timble/kodekit
code/controller/behavior/editable.php
ControllerBehaviorEditable.getReferrer
public function getReferrer(ControllerContextModel $context) { if($context->request->cookies->has($this->_cookie_name)) { $referrer = $context->request->cookies->get($this->_cookie_name, 'url'); $referrer = $this->getObject('lib:http.url', array('url' => $referrer)); } else $referrer = $this->findReferrer($context); return $referrer; }
php
public function getReferrer(ControllerContextModel $context) { if($context->request->cookies->has($this->_cookie_name)) { $referrer = $context->request->cookies->get($this->_cookie_name, 'url'); $referrer = $this->getObject('lib:http.url', array('url' => $referrer)); } else $referrer = $this->findReferrer($context); return $referrer; }
[ "public", "function", "getReferrer", "(", "ControllerContextModel", "$", "context", ")", "{", "if", "(", "$", "context", "->", "request", "->", "cookies", "->", "has", "(", "$", "this", "->", "_cookie_name", ")", ")", "{", "$", "referrer", "=", "$", "context", "->", "request", "->", "cookies", "->", "get", "(", "$", "this", "->", "_cookie_name", ",", "'url'", ")", ";", "$", "referrer", "=", "$", "this", "->", "getObject", "(", "'lib:http.url'", ",", "array", "(", "'url'", "=>", "$", "referrer", ")", ")", ";", "}", "else", "$", "referrer", "=", "$", "this", "->", "findReferrer", "(", "$", "context", ")", ";", "return", "$", "referrer", ";", "}" ]
Get the referrer @param ControllerContextModel $context A controller context object @return HttpUrl A HttpUrl object
[ "Get", "the", "referrer" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/controller/behavior/editable.php#L98-L108
29,033
timble/kodekit
code/controller/behavior/editable.php
ControllerBehaviorEditable.isLockable
public function isLockable() { $controller = $this->getMixer(); if($controller instanceof ControllerModellable) { if($this->getModel()->getState()->isUnique()) { $entity = $this->getModel()->fetch(); if($entity->isLockable()) { return true; } } } return false; }
php
public function isLockable() { $controller = $this->getMixer(); if($controller instanceof ControllerModellable) { if($this->getModel()->getState()->isUnique()) { $entity = $this->getModel()->fetch(); if($entity->isLockable()) { return true; } } } return false; }
[ "public", "function", "isLockable", "(", ")", "{", "$", "controller", "=", "$", "this", "->", "getMixer", "(", ")", ";", "if", "(", "$", "controller", "instanceof", "ControllerModellable", ")", "{", "if", "(", "$", "this", "->", "getModel", "(", ")", "->", "getState", "(", ")", "->", "isUnique", "(", ")", ")", "{", "$", "entity", "=", "$", "this", "->", "getModel", "(", ")", "->", "fetch", "(", ")", ";", "if", "(", "$", "entity", "->", "isLockable", "(", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Check if the resource is lockable @return bool Returns TRUE if the resource is can be locked, FALSE otherwise.
[ "Check", "if", "the", "resource", "is", "lockable" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/controller/behavior/editable.php#L224-L241
29,034
timble/kodekit
code/controller/behavior/editable.php
ControllerBehaviorEditable._afterRead
protected function _afterRead(ControllerContextModel $context) { $entity = $context->result; //Add the notice if the resource is locked if($this->canEdit() && $entity->isLockable() && $entity->isLocked()) { //Prevent a re-render of the message if($context->request->getUrl() != $context->request->getReferrer()) { if($entity->isLockable() && $entity->isLocked()) { $user = $entity->getLocker(); $date = $this->getObject('date', array('date' => $entity->locked_on)); $message = $this->getObject('translator')->translate( 'Locked by {name} {date}', array('name' => $user->getName(), 'date' => $date->humanize()) ); $context->response->addMessage($message, 'notice'); } } } }
php
protected function _afterRead(ControllerContextModel $context) { $entity = $context->result; //Add the notice if the resource is locked if($this->canEdit() && $entity->isLockable() && $entity->isLocked()) { //Prevent a re-render of the message if($context->request->getUrl() != $context->request->getReferrer()) { if($entity->isLockable() && $entity->isLocked()) { $user = $entity->getLocker(); $date = $this->getObject('date', array('date' => $entity->locked_on)); $message = $this->getObject('translator')->translate( 'Locked by {name} {date}', array('name' => $user->getName(), 'date' => $date->humanize()) ); $context->response->addMessage($message, 'notice'); } } } }
[ "protected", "function", "_afterRead", "(", "ControllerContextModel", "$", "context", ")", "{", "$", "entity", "=", "$", "context", "->", "result", ";", "//Add the notice if the resource is locked", "if", "(", "$", "this", "->", "canEdit", "(", ")", "&&", "$", "entity", "->", "isLockable", "(", ")", "&&", "$", "entity", "->", "isLocked", "(", ")", ")", "{", "//Prevent a re-render of the message", "if", "(", "$", "context", "->", "request", "->", "getUrl", "(", ")", "!=", "$", "context", "->", "request", "->", "getReferrer", "(", ")", ")", "{", "if", "(", "$", "entity", "->", "isLockable", "(", ")", "&&", "$", "entity", "->", "isLocked", "(", ")", ")", "{", "$", "user", "=", "$", "entity", "->", "getLocker", "(", ")", ";", "$", "date", "=", "$", "this", "->", "getObject", "(", "'date'", ",", "array", "(", "'date'", "=>", "$", "entity", "->", "locked_on", ")", ")", ";", "$", "message", "=", "$", "this", "->", "getObject", "(", "'translator'", ")", "->", "translate", "(", "'Locked by {name} {date}'", ",", "array", "(", "'name'", "=>", "$", "user", "->", "getName", "(", ")", ",", "'date'", "=>", "$", "date", "->", "humanize", "(", ")", ")", ")", ";", "$", "context", "->", "response", "->", "addMessage", "(", "$", "message", ",", "'notice'", ")", ";", "}", "}", "}", "}" ]
Add a lock flash message if the resource is locked @param ControllerContextModel $context A command context object @return void
[ "Add", "a", "lock", "flash", "message", "if", "the", "resource", "is", "locked" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/controller/behavior/editable.php#L426-L448
29,035
timble/kodekit
code/object/set.php
ObjectSet.filter
public function filter(/*Callable*/ $filter) { $result = clone $this; foreach ($this as $object) { if (call_user_func($filter, $object) === false) { $result->remove($object); } } return $result; }
php
public function filter(/*Callable*/ $filter) { $result = clone $this; foreach ($this as $object) { if (call_user_func($filter, $object) === false) { $result->remove($object); } } return $result; }
[ "public", "function", "filter", "(", "/*Callable*/", "$", "filter", ")", "{", "$", "result", "=", "clone", "$", "this", ";", "foreach", "(", "$", "this", "as", "$", "object", ")", "{", "if", "(", "call_user_func", "(", "$", "filter", ",", "$", "object", ")", "===", "false", ")", "{", "$", "result", "->", "remove", "(", "$", "object", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Filter the set using a callback If the callback returns FALSE the object will not be included in the resulting object set. @param Callable $filter A callback that will handle the filtering @return ObjectSet Returns an object subset
[ "Filter", "the", "set", "using", "a", "callback" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/object/set.php#L105-L116
29,036
symbiote/silverstripe-seed
code/dataobjects/CustomMenuBlockItem.php
CustomMenuBlockItem.stageChildren
public function stageChildren($showAll = false) { $baseClass = $this->class; $staged = $baseClass::get() ->filter('ParentID', (int)$this->owner->ID) ->exclude('ID', (int)$this->owner->ID); $this->owner->extend("augmentStageChildren", $staged, $showAll); return $staged; }
php
public function stageChildren($showAll = false) { $baseClass = $this->class; $staged = $baseClass::get() ->filter('ParentID', (int)$this->owner->ID) ->exclude('ID', (int)$this->owner->ID); $this->owner->extend("augmentStageChildren", $staged, $showAll); return $staged; }
[ "public", "function", "stageChildren", "(", "$", "showAll", "=", "false", ")", "{", "$", "baseClass", "=", "$", "this", "->", "class", ";", "$", "staged", "=", "$", "baseClass", "::", "get", "(", ")", "->", "filter", "(", "'ParentID'", ",", "(", "int", ")", "$", "this", "->", "owner", "->", "ID", ")", "->", "exclude", "(", "'ID'", ",", "(", "int", ")", "$", "this", "->", "owner", "->", "ID", ")", ";", "$", "this", "->", "owner", "->", "extend", "(", "\"augmentStageChildren\"", ",", "$", "staged", ",", "$", "showAll", ")", ";", "return", "$", "staged", ";", "}" ]
Overridden to use this->class instead of base class
[ "Overridden", "to", "use", "this", "-", ">", "class", "instead", "of", "base", "class" ]
bda0c1dab0d4cd7d8ca9a94b1a804562ecfc831d
https://github.com/symbiote/silverstripe-seed/blob/bda0c1dab0d4cd7d8ca9a94b1a804562ecfc831d/code/dataobjects/CustomMenuBlockItem.php#L88-L96
29,037
timble/kodekit
code/database/iterator/recursive.php
DatabaseIteratorRecursive._createInnerIterator
protected static function _createInnerIterator(DatabaseRowsetInterface $rowset) { $iterator = new \RecursiveArrayIterator($rowset->getIterator()); $iterator = new \RecursiveCachingIterator($iterator, \CachingIterator::TOSTRING_USE_KEY); return $iterator; }
php
protected static function _createInnerIterator(DatabaseRowsetInterface $rowset) { $iterator = new \RecursiveArrayIterator($rowset->getIterator()); $iterator = new \RecursiveCachingIterator($iterator, \CachingIterator::TOSTRING_USE_KEY); return $iterator; }
[ "protected", "static", "function", "_createInnerIterator", "(", "DatabaseRowsetInterface", "$", "rowset", ")", "{", "$", "iterator", "=", "new", "\\", "RecursiveArrayIterator", "(", "$", "rowset", "->", "getIterator", "(", ")", ")", ";", "$", "iterator", "=", "new", "\\", "RecursiveCachingIterator", "(", "$", "iterator", ",", "\\", "CachingIterator", "::", "TOSTRING_USE_KEY", ")", ";", "return", "$", "iterator", ";", "}" ]
Create a recursive iterator from a rowset @param DatabaseRowsetInterface $rowset @return \RecursiveIterator
[ "Create", "a", "recursive", "iterator", "from", "a", "rowset" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/database/iterator/recursive.php#L92-L98
29,038
timble/kodekit
code/dispatcher/authenticator/jwt.php
DispatcherAuthenticatorJwt.createToken
public function createToken(UserInterface $user = null) { if(!$user) { $user = $this->getObject('user'); } $token = $this->getObject('lib:http.token') ->setSubject($user->getId()) ->sign($this->getSecret()); return $token; }
php
public function createToken(UserInterface $user = null) { if(!$user) { $user = $this->getObject('user'); } $token = $this->getObject('lib:http.token') ->setSubject($user->getId()) ->sign($this->getSecret()); return $token; }
[ "public", "function", "createToken", "(", "UserInterface", "$", "user", "=", "null", ")", "{", "if", "(", "!", "$", "user", ")", "{", "$", "user", "=", "$", "this", "->", "getObject", "(", "'user'", ")", ";", "}", "$", "token", "=", "$", "this", "->", "getObject", "(", "'lib:http.token'", ")", "->", "setSubject", "(", "$", "user", "->", "getId", "(", ")", ")", "->", "sign", "(", "$", "this", "->", "getSecret", "(", ")", ")", ";", "return", "$", "token", ";", "}" ]
Create a new signed JWT authorisation token If not user passed, the context user object will be used. @param UserInterface $user The user object. Default NULL @return string The signed authorisation token
[ "Create", "a", "new", "signed", "JWT", "authorisation", "token" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/dispatcher/authenticator/jwt.php#L182-L193
29,039
rosasurfer/ministruts
src/monitor/FileDependency.php
FileDependency.create
public static function create($fileNames) { if (!is_array($fileNames)) { if (!is_string($fileNames)) throw new IllegalTypeException('Illegal type of parameter $fileNames: '.gettype($fileNames)); if (!strlen($fileNames)) throw new InvalidArgumentException('Invalid argument $fileNames: '.$fileNames); $fileNames = [$fileNames]; } if (!$fileNames) throw new InvalidArgumentException('Invalid argument $fileNames: '.$fileNames); $dependency = null; foreach ($fileNames as $name) { if (!$dependency) $dependency = new static($name); else $dependency = $dependency->andDependency(new static($name)); } return $dependency; }
php
public static function create($fileNames) { if (!is_array($fileNames)) { if (!is_string($fileNames)) throw new IllegalTypeException('Illegal type of parameter $fileNames: '.gettype($fileNames)); if (!strlen($fileNames)) throw new InvalidArgumentException('Invalid argument $fileNames: '.$fileNames); $fileNames = [$fileNames]; } if (!$fileNames) throw new InvalidArgumentException('Invalid argument $fileNames: '.$fileNames); $dependency = null; foreach ($fileNames as $name) { if (!$dependency) $dependency = new static($name); else $dependency = $dependency->andDependency(new static($name)); } return $dependency; }
[ "public", "static", "function", "create", "(", "$", "fileNames", ")", "{", "if", "(", "!", "is_array", "(", "$", "fileNames", ")", ")", "{", "if", "(", "!", "is_string", "(", "$", "fileNames", ")", ")", "throw", "new", "IllegalTypeException", "(", "'Illegal type of parameter $fileNames: '", ".", "gettype", "(", "$", "fileNames", ")", ")", ";", "if", "(", "!", "strlen", "(", "$", "fileNames", ")", ")", "throw", "new", "InvalidArgumentException", "(", "'Invalid argument $fileNames: '", ".", "$", "fileNames", ")", ";", "$", "fileNames", "=", "[", "$", "fileNames", "]", ";", "}", "if", "(", "!", "$", "fileNames", ")", "throw", "new", "InvalidArgumentException", "(", "'Invalid argument $fileNames: '", ".", "$", "fileNames", ")", ";", "$", "dependency", "=", "null", ";", "foreach", "(", "$", "fileNames", "as", "$", "name", ")", "{", "if", "(", "!", "$", "dependency", ")", "$", "dependency", "=", "new", "static", "(", "$", "name", ")", ";", "else", "$", "dependency", "=", "$", "dependency", "->", "andDependency", "(", "new", "static", "(", "$", "name", ")", ")", ";", "}", "return", "$", "dependency", ";", "}" ]
Erzeugt eine neue FileDependency, die eine oder mehrere Dateien ueberwacht. @param mixed $fileNames - einzelner Dateiname (String) oder Array von Dateinamen @return Dependency
[ "Erzeugt", "eine", "neue", "FileDependency", "die", "eine", "oder", "mehrere", "Dateien", "ueberwacht", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/monitor/FileDependency.php#L76-L92
29,040
rosasurfer/ministruts
src/monitor/FileDependency.php
FileDependency.isValid
public function isValid() { // TODO: stat-Cache bei wiederholten Aufrufen loeschen, siehe clearstatcache() if (file_exists($this->fileName)) { if ($this->lastModified !== filemtime($this->fileName)) return false; } elseif ($this->lastModified !== null) { return false; } return true; }
php
public function isValid() { // TODO: stat-Cache bei wiederholten Aufrufen loeschen, siehe clearstatcache() if (file_exists($this->fileName)) { if ($this->lastModified !== filemtime($this->fileName)) return false; } elseif ($this->lastModified !== null) { return false; } return true; }
[ "public", "function", "isValid", "(", ")", "{", "// TODO: stat-Cache bei wiederholten Aufrufen loeschen, siehe clearstatcache()", "if", "(", "file_exists", "(", "$", "this", "->", "fileName", ")", ")", "{", "if", "(", "$", "this", "->", "lastModified", "!==", "filemtime", "(", "$", "this", "->", "fileName", ")", ")", "return", "false", ";", "}", "elseif", "(", "$", "this", "->", "lastModified", "!==", "null", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Ob die der Abhaengigkeit zugrunde liegende Datei weiterhin unveraendert ist. @return bool - TRUE, wenn die Datei sich nicht geaendert hat. FALSE, wenn die Datei sich geaendert hat.
[ "Ob", "die", "der", "Abhaengigkeit", "zugrunde", "liegende", "Datei", "weiterhin", "unveraendert", "ist", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/monitor/FileDependency.php#L101-L113
29,041
timble/kodekit
code/template/helper/select.php
TemplateHelperSelect.options
public function options( $config = array() ) { $config = new ObjectConfig($config); $config->append(array( 'entity' => array(), 'name' => 'id', 'value' => 'id', 'label' => 'id', 'disabled' => null, 'attribs' => array(), )); $options = array(); foreach($config->entity as $entity) { $option = array( 'id' => isset($entity->{$config->name}) ? $entity->{$config->name} : null, 'name' => $config->name, 'disabled' => $config->disabled, 'attribs' => ObjectConfig::unbox($config->attribs), 'value' => $entity->{$config->value}, 'label' => $entity->{$config->label}, ); if($config->entity instanceof \RecursiveIteratorIterator) { $option['level'] = $config->entity->getDepth() + 1; } $options[] = $this->option($option); } return $options; }
php
public function options( $config = array() ) { $config = new ObjectConfig($config); $config->append(array( 'entity' => array(), 'name' => 'id', 'value' => 'id', 'label' => 'id', 'disabled' => null, 'attribs' => array(), )); $options = array(); foreach($config->entity as $entity) { $option = array( 'id' => isset($entity->{$config->name}) ? $entity->{$config->name} : null, 'name' => $config->name, 'disabled' => $config->disabled, 'attribs' => ObjectConfig::unbox($config->attribs), 'value' => $entity->{$config->value}, 'label' => $entity->{$config->label}, ); if($config->entity instanceof \RecursiveIteratorIterator) { $option['level'] = $config->entity->getDepth() + 1; } $options[] = $this->option($option); } return $options; }
[ "public", "function", "options", "(", "$", "config", "=", "array", "(", ")", ")", "{", "$", "config", "=", "new", "ObjectConfig", "(", "$", "config", ")", ";", "$", "config", "->", "append", "(", "array", "(", "'entity'", "=>", "array", "(", ")", ",", "'name'", "=>", "'id'", ",", "'value'", "=>", "'id'", ",", "'label'", "=>", "'id'", ",", "'disabled'", "=>", "null", ",", "'attribs'", "=>", "array", "(", ")", ",", ")", ")", ";", "$", "options", "=", "array", "(", ")", ";", "foreach", "(", "$", "config", "->", "entity", "as", "$", "entity", ")", "{", "$", "option", "=", "array", "(", "'id'", "=>", "isset", "(", "$", "entity", "->", "{", "$", "config", "->", "name", "}", ")", "?", "$", "entity", "->", "{", "$", "config", "->", "name", "}", ":", "null", ",", "'name'", "=>", "$", "config", "->", "name", ",", "'disabled'", "=>", "$", "config", "->", "disabled", ",", "'attribs'", "=>", "ObjectConfig", "::", "unbox", "(", "$", "config", "->", "attribs", ")", ",", "'value'", "=>", "$", "entity", "->", "{", "$", "config", "->", "value", "}", ",", "'label'", "=>", "$", "entity", "->", "{", "$", "config", "->", "label", "}", ",", ")", ";", "if", "(", "$", "config", "->", "entity", "instanceof", "\\", "RecursiveIteratorIterator", ")", "{", "$", "option", "[", "'level'", "]", "=", "$", "config", "->", "entity", "->", "getDepth", "(", ")", "+", "1", ";", "}", "$", "options", "[", "]", "=", "$", "this", "->", "option", "(", "$", "option", ")", ";", "}", "return", "$", "options", ";", "}" ]
Generates a select option list @param array $config An optional array with configuration options @return array An array of objects containing the option attributes
[ "Generates", "a", "select", "option", "list" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/template/helper/select.php#L65-L93
29,042
timble/kodekit
code/template/helper/select.php
TemplateHelperSelect.radiolist
public function radiolist($config = array()) { $config = new ObjectConfigJson($config); $config->append(array( 'options' => array(), 'legend' => null, 'name' => 'id', 'selected' => null, 'translate' => false, 'attribs' => array(), )); $translator = $this->getObject('translator'); $attribs = $this->buildAttributes($config->attribs); $html = array(); $html[] = '<fieldset name="'. $config->name .'" '. $attribs .'>'; if(isset($config->legend)) { $html[] = '<legend>'.$config->translate ? $translator->translate( $config->legend ) : $config->legend.'</legend>'; } foreach($config->options as $option) { $value = $option->value; $label = $config->translate ? $translator->translate( $option->label ) : $option->label; $extra = ($value == $config->selected ? 'checked="checked"' : ''); if(isset($option->disabled) && $option->disabled) { $extra .= 'disabled="disabled"'; } if(isset($option->attribs)) { $attribs = $this->buildAttributes($option->attribs); } $html[] = '<label class="radio" for="'.$config->name.$option->id.'">'; $html[] = '<input type="radio" name="'.$config->name.'" id="'.$config->name.$option->id.'" value="'.$value.'" '.$extra.' '.$attribs.' />'; $html[] = $label; $html[] = '</label>'; } $html[] = '</fieldset>'; return implode(PHP_EOL, $html); }
php
public function radiolist($config = array()) { $config = new ObjectConfigJson($config); $config->append(array( 'options' => array(), 'legend' => null, 'name' => 'id', 'selected' => null, 'translate' => false, 'attribs' => array(), )); $translator = $this->getObject('translator'); $attribs = $this->buildAttributes($config->attribs); $html = array(); $html[] = '<fieldset name="'. $config->name .'" '. $attribs .'>'; if(isset($config->legend)) { $html[] = '<legend>'.$config->translate ? $translator->translate( $config->legend ) : $config->legend.'</legend>'; } foreach($config->options as $option) { $value = $option->value; $label = $config->translate ? $translator->translate( $option->label ) : $option->label; $extra = ($value == $config->selected ? 'checked="checked"' : ''); if(isset($option->disabled) && $option->disabled) { $extra .= 'disabled="disabled"'; } if(isset($option->attribs)) { $attribs = $this->buildAttributes($option->attribs); } $html[] = '<label class="radio" for="'.$config->name.$option->id.'">'; $html[] = '<input type="radio" name="'.$config->name.'" id="'.$config->name.$option->id.'" value="'.$value.'" '.$extra.' '.$attribs.' />'; $html[] = $label; $html[] = '</label>'; } $html[] = '</fieldset>'; return implode(PHP_EOL, $html); }
[ "public", "function", "radiolist", "(", "$", "config", "=", "array", "(", ")", ")", "{", "$", "config", "=", "new", "ObjectConfigJson", "(", "$", "config", ")", ";", "$", "config", "->", "append", "(", "array", "(", "'options'", "=>", "array", "(", ")", ",", "'legend'", "=>", "null", ",", "'name'", "=>", "'id'", ",", "'selected'", "=>", "null", ",", "'translate'", "=>", "false", ",", "'attribs'", "=>", "array", "(", ")", ",", ")", ")", ";", "$", "translator", "=", "$", "this", "->", "getObject", "(", "'translator'", ")", ";", "$", "attribs", "=", "$", "this", "->", "buildAttributes", "(", "$", "config", "->", "attribs", ")", ";", "$", "html", "=", "array", "(", ")", ";", "$", "html", "[", "]", "=", "'<fieldset name=\"'", ".", "$", "config", "->", "name", ".", "'\" '", ".", "$", "attribs", ".", "'>'", ";", "if", "(", "isset", "(", "$", "config", "->", "legend", ")", ")", "{", "$", "html", "[", "]", "=", "'<legend>'", ".", "$", "config", "->", "translate", "?", "$", "translator", "->", "translate", "(", "$", "config", "->", "legend", ")", ":", "$", "config", "->", "legend", ".", "'</legend>'", ";", "}", "foreach", "(", "$", "config", "->", "options", "as", "$", "option", ")", "{", "$", "value", "=", "$", "option", "->", "value", ";", "$", "label", "=", "$", "config", "->", "translate", "?", "$", "translator", "->", "translate", "(", "$", "option", "->", "label", ")", ":", "$", "option", "->", "label", ";", "$", "extra", "=", "(", "$", "value", "==", "$", "config", "->", "selected", "?", "'checked=\"checked\"'", ":", "''", ")", ";", "if", "(", "isset", "(", "$", "option", "->", "disabled", ")", "&&", "$", "option", "->", "disabled", ")", "{", "$", "extra", ".=", "'disabled=\"disabled\"'", ";", "}", "if", "(", "isset", "(", "$", "option", "->", "attribs", ")", ")", "{", "$", "attribs", "=", "$", "this", "->", "buildAttributes", "(", "$", "option", "->", "attribs", ")", ";", "}", "$", "html", "[", "]", "=", "'<label class=\"radio\" for=\"'", ".", "$", "config", "->", "name", ".", "$", "option", "->", "id", ".", "'\">'", ";", "$", "html", "[", "]", "=", "'<input type=\"radio\" name=\"'", ".", "$", "config", "->", "name", ".", "'\" id=\"'", ".", "$", "config", "->", "name", ".", "$", "option", "->", "id", ".", "'\" value=\"'", ".", "$", "value", ".", "'\" '", ".", "$", "extra", ".", "' '", ".", "$", "attribs", ".", "' />'", ";", "$", "html", "[", "]", "=", "$", "label", ";", "$", "html", "[", "]", "=", "'</label>'", ";", "}", "$", "html", "[", "]", "=", "'</fieldset>'", ";", "return", "implode", "(", "PHP_EOL", ",", "$", "html", ")", ";", "}" ]
Generates an HTML radio list @param array|ObjectConfig $config An optional array with configuration options @return string Html
[ "Generates", "an", "HTML", "radio", "list" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/template/helper/select.php#L175-L221
29,043
timble/kodekit
code/view/json.php
ViewJson._createResource
protected function _createResource(ModelEntityInterface $entity, array $config = array()) { $config = array_merge(array( 'links' => true, 'relationships' => true ), $config); $data = array( 'type' => $this->_callCustomMethod($entity, 'type') ?: StringInflector::pluralize($entity->getIdentifier()->name), 'id' => $this->_callCustomMethod($entity, 'id') ?: $entity->{$entity->getIdentityKey()}, 'attributes' => $this->_callCustomMethod($entity, 'attributes') ?: $entity->toArray() ); if (isset($this->_fields[$data['type']])) { $fields = array_flip($this->_fields[$data['type']]); $data['attributes'] = array_intersect_key($data['attributes'], $fields); } if ($config['links']) { $links = $this->_callCustomMethod($entity, 'links') ?: array('self' => (string)$this->_getEntityRoute($entity)); if ($links) { $data['links'] = $links; } } if ($config['relationships']) { $relationships = $this->_callCustomMethod($entity, 'relationships'); if ($relationships) { $data['relationships'] = $relationships; } } return $data; }
php
protected function _createResource(ModelEntityInterface $entity, array $config = array()) { $config = array_merge(array( 'links' => true, 'relationships' => true ), $config); $data = array( 'type' => $this->_callCustomMethod($entity, 'type') ?: StringInflector::pluralize($entity->getIdentifier()->name), 'id' => $this->_callCustomMethod($entity, 'id') ?: $entity->{$entity->getIdentityKey()}, 'attributes' => $this->_callCustomMethod($entity, 'attributes') ?: $entity->toArray() ); if (isset($this->_fields[$data['type']])) { $fields = array_flip($this->_fields[$data['type']]); $data['attributes'] = array_intersect_key($data['attributes'], $fields); } if ($config['links']) { $links = $this->_callCustomMethod($entity, 'links') ?: array('self' => (string)$this->_getEntityRoute($entity)); if ($links) { $data['links'] = $links; } } if ($config['relationships']) { $relationships = $this->_callCustomMethod($entity, 'relationships'); if ($relationships) { $data['relationships'] = $relationships; } } return $data; }
[ "protected", "function", "_createResource", "(", "ModelEntityInterface", "$", "entity", ",", "array", "$", "config", "=", "array", "(", ")", ")", "{", "$", "config", "=", "array_merge", "(", "array", "(", "'links'", "=>", "true", ",", "'relationships'", "=>", "true", ")", ",", "$", "config", ")", ";", "$", "data", "=", "array", "(", "'type'", "=>", "$", "this", "->", "_callCustomMethod", "(", "$", "entity", ",", "'type'", ")", "?", ":", "StringInflector", "::", "pluralize", "(", "$", "entity", "->", "getIdentifier", "(", ")", "->", "name", ")", ",", "'id'", "=>", "$", "this", "->", "_callCustomMethod", "(", "$", "entity", ",", "'id'", ")", "?", ":", "$", "entity", "->", "{", "$", "entity", "->", "getIdentityKey", "(", ")", "}", ",", "'attributes'", "=>", "$", "this", "->", "_callCustomMethod", "(", "$", "entity", ",", "'attributes'", ")", "?", ":", "$", "entity", "->", "toArray", "(", ")", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_fields", "[", "$", "data", "[", "'type'", "]", "]", ")", ")", "{", "$", "fields", "=", "array_flip", "(", "$", "this", "->", "_fields", "[", "$", "data", "[", "'type'", "]", "]", ")", ";", "$", "data", "[", "'attributes'", "]", "=", "array_intersect_key", "(", "$", "data", "[", "'attributes'", "]", ",", "$", "fields", ")", ";", "}", "if", "(", "$", "config", "[", "'links'", "]", ")", "{", "$", "links", "=", "$", "this", "->", "_callCustomMethod", "(", "$", "entity", ",", "'links'", ")", "?", ":", "array", "(", "'self'", "=>", "(", "string", ")", "$", "this", "->", "_getEntityRoute", "(", "$", "entity", ")", ")", ";", "if", "(", "$", "links", ")", "{", "$", "data", "[", "'links'", "]", "=", "$", "links", ";", "}", "}", "if", "(", "$", "config", "[", "'relationships'", "]", ")", "{", "$", "relationships", "=", "$", "this", "->", "_callCustomMethod", "(", "$", "entity", ",", "'relationships'", ")", ";", "if", "(", "$", "relationships", ")", "{", "$", "data", "[", "'relationships'", "]", "=", "$", "relationships", ";", "}", "}", "return", "$", "data", ";", "}" ]
Creates a resource object specified by JSON API @see http://jsonapi.org/format/#document-resource-objects @param ModelEntityInterface $entity Document row @param array $config Resource configuration. @return array The array with data to be encoded to json
[ "Creates", "a", "resource", "object", "specified", "by", "JSON", "API" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/view/json.php#L189-L225
29,044
timble/kodekit
code/view/json.php
ViewJson._includeResource
protected function _includeResource(ModelEntityInterface $entity) { $cache = $entity->getIdentifier()->name.'-'.$entity->getHandle(); if (!isset($this->_included_resources[$cache])) { $this->_included_resources[$cache] = $this->_createResource($entity, array('relationships' => false)); } $resource = $this->_included_resources[$cache]; return array( 'data' => array( 'type' => $resource['type'], 'id' => $resource['id'] ) ); }
php
protected function _includeResource(ModelEntityInterface $entity) { $cache = $entity->getIdentifier()->name.'-'.$entity->getHandle(); if (!isset($this->_included_resources[$cache])) { $this->_included_resources[$cache] = $this->_createResource($entity, array('relationships' => false)); } $resource = $this->_included_resources[$cache]; return array( 'data' => array( 'type' => $resource['type'], 'id' => $resource['id'] ) ); }
[ "protected", "function", "_includeResource", "(", "ModelEntityInterface", "$", "entity", ")", "{", "$", "cache", "=", "$", "entity", "->", "getIdentifier", "(", ")", "->", "name", ".", "'-'", ".", "$", "entity", "->", "getHandle", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_included_resources", "[", "$", "cache", "]", ")", ")", "{", "$", "this", "->", "_included_resources", "[", "$", "cache", "]", "=", "$", "this", "->", "_createResource", "(", "$", "entity", ",", "array", "(", "'relationships'", "=>", "false", ")", ")", ";", "}", "$", "resource", "=", "$", "this", "->", "_included_resources", "[", "$", "cache", "]", ";", "return", "array", "(", "'data'", "=>", "array", "(", "'type'", "=>", "$", "resource", "[", "'type'", "]", ",", "'id'", "=>", "$", "resource", "[", "'id'", "]", ")", ")", ";", "}" ]
Creates a resource object and returns a resource identifier object specified by JSON API @see http://jsonapi.org/format/#document-resource-identifier-objects @param ModelEntityInterface $entity @return array
[ "Creates", "a", "resource", "object", "and", "returns", "a", "resource", "identifier", "object", "specified", "by", "JSON", "API" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/view/json.php#L234-L250
29,045
timble/kodekit
code/view/json.php
ViewJson._includeCollection
protected function _includeCollection(ModelEntityInterface $entities) { $result = array('data' => array()); foreach ($entities as $entity) { $relation = $this->_includeResource($entity); $result['data'][] = $relation['data']; } return $result; }
php
protected function _includeCollection(ModelEntityInterface $entities) { $result = array('data' => array()); foreach ($entities as $entity) { $relation = $this->_includeResource($entity); $result['data'][] = $relation['data']; } return $result; }
[ "protected", "function", "_includeCollection", "(", "ModelEntityInterface", "$", "entities", ")", "{", "$", "result", "=", "array", "(", "'data'", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "entities", "as", "$", "entity", ")", "{", "$", "relation", "=", "$", "this", "->", "_includeResource", "(", "$", "entity", ")", ";", "$", "result", "[", "'data'", "]", "[", "]", "=", "$", "relation", "[", "'data'", "]", ";", "}", "return", "$", "result", ";", "}" ]
Creates resource objects and returns an array of resource identifier objects specified by JSON API @see http://jsonapi.org/format/#document-resource-identifier-objects @param ModelEntityInterface $entities @return array
[ "Creates", "resource", "objects", "and", "returns", "an", "array", "of", "resource", "identifier", "objects", "specified", "by", "JSON", "API" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/view/json.php#L259-L270
29,046
timble/kodekit
code/view/json.php
ViewJson._callCustomMethod
protected function _callCustomMethod(ModelEntityInterface $entity, $method) { $result = false; $name = StringInflector::singularize($entity->getIdentifier()->name); $method = '_get'.ucfirst($name).ucfirst($method); if ($method !== '_getEntity'.ucfirst($method) && method_exists($this, $method)) { $result = $this->$method($entity); } return $result; }
php
protected function _callCustomMethod(ModelEntityInterface $entity, $method) { $result = false; $name = StringInflector::singularize($entity->getIdentifier()->name); $method = '_get'.ucfirst($name).ucfirst($method); if ($method !== '_getEntity'.ucfirst($method) && method_exists($this, $method)) { $result = $this->$method($entity); } return $result; }
[ "protected", "function", "_callCustomMethod", "(", "ModelEntityInterface", "$", "entity", ",", "$", "method", ")", "{", "$", "result", "=", "false", ";", "$", "name", "=", "StringInflector", "::", "singularize", "(", "$", "entity", "->", "getIdentifier", "(", ")", "->", "name", ")", ";", "$", "method", "=", "'_get'", ".", "ucfirst", "(", "$", "name", ")", ".", "ucfirst", "(", "$", "method", ")", ";", "if", "(", "$", "method", "!==", "'_getEntity'", ".", "ucfirst", "(", "$", "method", ")", "&&", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "{", "$", "result", "=", "$", "this", "->", "$", "method", "(", "$", "entity", ")", ";", "}", "return", "$", "result", ";", "}" ]
Calls a custom method per entity name to modify resource objects If the entity is of type foo and the method is links, this method will return the results of _getFooLinks method if possible @param ModelEntityInterface $entity @param string $method @return mixed Method results or false if the method not exists
[ "Calls", "a", "custom", "method", "per", "entity", "name", "to", "modify", "resource", "objects" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/view/json.php#L282-L293
29,047
timble/kodekit
code/view/json.php
ViewJson._getEntityRoute
protected function _getEntityRoute(ModelEntityInterface $entity) { $package = $this->getIdentifier()->package; $view = $entity->getIdentifier()->name; return $this->getRoute(sprintf('component=%s&view=%s&slug=%s&format=json', $package, $view, $entity->slug)); }
php
protected function _getEntityRoute(ModelEntityInterface $entity) { $package = $this->getIdentifier()->package; $view = $entity->getIdentifier()->name; return $this->getRoute(sprintf('component=%s&view=%s&slug=%s&format=json', $package, $view, $entity->slug)); }
[ "protected", "function", "_getEntityRoute", "(", "ModelEntityInterface", "$", "entity", ")", "{", "$", "package", "=", "$", "this", "->", "getIdentifier", "(", ")", "->", "package", ";", "$", "view", "=", "$", "entity", "->", "getIdentifier", "(", ")", "->", "name", ";", "return", "$", "this", "->", "getRoute", "(", "sprintf", "(", "'component=%s&view=%s&slug=%s&format=json'", ",", "$", "package", ",", "$", "view", ",", "$", "entity", "->", "slug", ")", ")", ";", "}" ]
Provides a default entity link It can be overridden by creating a _getFooLinks method where foo is the entity type @param ModelEntityInterface $entity @return string
[ "Provides", "a", "default", "entity", "link" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/view/json.php#L303-L309
29,048
timble/kodekit
code/view/json.php
ViewJson._convertRelativeLinks
protected function _convertRelativeLinks(ViewContextInterface $context) { if (is_array($context->content) || $context->content instanceof \Traversable) { $this->_processLinks($context->content); } }
php
protected function _convertRelativeLinks(ViewContextInterface $context) { if (is_array($context->content) || $context->content instanceof \Traversable) { $this->_processLinks($context->content); } }
[ "protected", "function", "_convertRelativeLinks", "(", "ViewContextInterface", "$", "context", ")", "{", "if", "(", "is_array", "(", "$", "context", "->", "content", ")", "||", "$", "context", "->", "content", "instanceof", "\\", "Traversable", ")", "{", "$", "this", "->", "_processLinks", "(", "$", "context", "->", "content", ")", ";", "}", "}" ]
Converts links in the content from relative to absolute @param ViewContextInterface $context
[ "Converts", "links", "in", "the", "content", "from", "relative", "to", "absolute" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/view/json.php#L316-L321
29,049
timble/kodekit
code/view/json.php
ViewJson._processLinks
protected function _processLinks(&$array) { $base = $this->getUrl()->toString(HttpUrl::AUTHORITY); foreach ($array as $key => &$value) { if ($key === 'links') { foreach ($array['links'] as $k => $v) { if (strpos($v, ':/') === false) { $array['links'][$k] = $base.$v; } } } elseif (is_array($value)) { $this->_processLinks($value); } elseif (in_array($key, $this->_text_fields, true)) { $array[$key] = $this->_processText($value); } } }
php
protected function _processLinks(&$array) { $base = $this->getUrl()->toString(HttpUrl::AUTHORITY); foreach ($array as $key => &$value) { if ($key === 'links') { foreach ($array['links'] as $k => $v) { if (strpos($v, ':/') === false) { $array['links'][$k] = $base.$v; } } } elseif (is_array($value)) { $this->_processLinks($value); } elseif (in_array($key, $this->_text_fields, true)) { $array[$key] = $this->_processText($value); } } }
[ "protected", "function", "_processLinks", "(", "&", "$", "array", ")", "{", "$", "base", "=", "$", "this", "->", "getUrl", "(", ")", "->", "toString", "(", "HttpUrl", "::", "AUTHORITY", ")", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "&", "$", "value", ")", "{", "if", "(", "$", "key", "===", "'links'", ")", "{", "foreach", "(", "$", "array", "[", "'links'", "]", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "strpos", "(", "$", "v", ",", "':/'", ")", "===", "false", ")", "{", "$", "array", "[", "'links'", "]", "[", "$", "k", "]", "=", "$", "base", ".", "$", "v", ";", "}", "}", "}", "elseif", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "this", "->", "_processLinks", "(", "$", "value", ")", ";", "}", "elseif", "(", "in_array", "(", "$", "key", ",", "$", "this", "->", "_text_fields", ",", "true", ")", ")", "{", "$", "array", "[", "$", "key", "]", "=", "$", "this", "->", "_processText", "(", "$", "value", ")", ";", "}", "}", "}" ]
Converts links in the content array from relative to absolute @param \Traversable|array $array
[ "Converts", "links", "in", "the", "content", "array", "from", "relative", "to", "absolute" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/view/json.php#L328-L350
29,050
timble/kodekit
code/object/manager/manager.php
ObjectManager.isMultiton
public function isMultiton($identifier) { $result = false; $class = $this->getClass($identifier); if($class) { $result = array_key_exists(__NAMESPACE__.'\ObjectMultiton', class_implements($class)); } return $result; }
php
public function isMultiton($identifier) { $result = false; $class = $this->getClass($identifier); if($class) { $result = array_key_exists(__NAMESPACE__.'\ObjectMultiton', class_implements($class)); } return $result; }
[ "public", "function", "isMultiton", "(", "$", "identifier", ")", "{", "$", "result", "=", "false", ";", "$", "class", "=", "$", "this", "->", "getClass", "(", "$", "identifier", ")", ";", "if", "(", "$", "class", ")", "{", "$", "result", "=", "array_key_exists", "(", "__NAMESPACE__", ".", "'\\ObjectMultiton'", ",", "class_implements", "(", "$", "class", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Check if the object is a multiton @param mixed $identifier An object that implements the ObjectInterface, an ObjectIdentifier or valid identifier string @return boolean Returns TRUE if the object is a singleton, FALSE otherwise.
[ "Check", "if", "the", "object", "is", "a", "multiton" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/object/manager/manager.php#L474-L485
29,051
rosasurfer/ministruts
src/ministruts/Request.php
Request.getFiles
public function getFiles() { static $files; if (!isset($files)) { $normalizeLevel = function(array $file) use (&$normalizeLevel) { if (isset($file['name']) && is_array($file['name'])) { $properties = \array_keys($file); $normalized = []; foreach (\array_keys($file['name']) as $name) { foreach ($properties as $property) { $normalized[$name][$property] = $file[$property][$name]; } $normalized[$name] = $normalizeLevel($normalized[$name]); } $file = $normalized; } return $file; }; $files = []; if (isset($_FILES)) { foreach ($_FILES as $key => $file) { $files[$key] = $normalizeLevel($file); } } } return $files; }
php
public function getFiles() { static $files; if (!isset($files)) { $normalizeLevel = function(array $file) use (&$normalizeLevel) { if (isset($file['name']) && is_array($file['name'])) { $properties = \array_keys($file); $normalized = []; foreach (\array_keys($file['name']) as $name) { foreach ($properties as $property) { $normalized[$name][$property] = $file[$property][$name]; } $normalized[$name] = $normalizeLevel($normalized[$name]); } $file = $normalized; } return $file; }; $files = []; if (isset($_FILES)) { foreach ($_FILES as $key => $file) { $files[$key] = $normalizeLevel($file); } } } return $files; }
[ "public", "function", "getFiles", "(", ")", "{", "static", "$", "files", ";", "if", "(", "!", "isset", "(", "$", "files", ")", ")", "{", "$", "normalizeLevel", "=", "function", "(", "array", "$", "file", ")", "use", "(", "&", "$", "normalizeLevel", ")", "{", "if", "(", "isset", "(", "$", "file", "[", "'name'", "]", ")", "&&", "is_array", "(", "$", "file", "[", "'name'", "]", ")", ")", "{", "$", "properties", "=", "\\", "array_keys", "(", "$", "file", ")", ";", "$", "normalized", "=", "[", "]", ";", "foreach", "(", "\\", "array_keys", "(", "$", "file", "[", "'name'", "]", ")", "as", "$", "name", ")", "{", "foreach", "(", "$", "properties", "as", "$", "property", ")", "{", "$", "normalized", "[", "$", "name", "]", "[", "$", "property", "]", "=", "$", "file", "[", "$", "property", "]", "[", "$", "name", "]", ";", "}", "$", "normalized", "[", "$", "name", "]", "=", "$", "normalizeLevel", "(", "$", "normalized", "[", "$", "name", "]", ")", ";", "}", "$", "file", "=", "$", "normalized", ";", "}", "return", "$", "file", ";", "}", ";", "$", "files", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "_FILES", ")", ")", "{", "foreach", "(", "$", "_FILES", "as", "$", "key", "=>", "$", "file", ")", "{", "$", "files", "[", "$", "key", "]", "=", "$", "normalizeLevel", "(", "$", "file", ")", ";", "}", "}", "}", "return", "$", "files", ";", "}" ]
Return an object-oriented representation of the uploaded files. The broken PHP array structure of uploaded files is converted to regular file arrays. @TODO: convert file data to {@link UploadedFile} instances @return array - associative array of files
[ "Return", "an", "object", "-", "oriented", "representation", "of", "the", "uploaded", "files", ".", "The", "broken", "PHP", "array", "structure", "of", "uploaded", "files", "is", "converted", "to", "regular", "file", "arrays", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L272-L297
29,052
rosasurfer/ministruts
src/ministruts/Request.php
Request.getHostname
public function getHostname() { if (!empty($_SERVER['HTTP_HOST'])) { $httpHost = strtolower(trim($_SERVER['HTTP_HOST'])); // nginx doesn't set $_SERVER[SERVER_NAME] if (strlen($httpHost)) // automatically to $_SERVER[HTTP_HOST] return $httpHost; } return $_SERVER['SERVER_NAME']; }
php
public function getHostname() { if (!empty($_SERVER['HTTP_HOST'])) { $httpHost = strtolower(trim($_SERVER['HTTP_HOST'])); // nginx doesn't set $_SERVER[SERVER_NAME] if (strlen($httpHost)) // automatically to $_SERVER[HTTP_HOST] return $httpHost; } return $_SERVER['SERVER_NAME']; }
[ "public", "function", "getHostname", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ")", ")", "{", "$", "httpHost", "=", "strtolower", "(", "trim", "(", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ")", ")", ";", "// nginx doesn't set $_SERVER[SERVER_NAME]", "if", "(", "strlen", "(", "$", "httpHost", ")", ")", "// automatically to $_SERVER[HTTP_HOST]", "return", "$", "httpHost", ";", "}", "return", "$", "_SERVER", "[", "'SERVER_NAME'", "]", ";", "}" ]
Return the host name the request was made to. @return string - host name @example <pre> $request->getUrl(): "http://a.domain.tld/path/application/module/foo/bar.html?key=value" $request->getHostname(): "a.domain.tld" </pre>
[ "Return", "the", "host", "name", "the", "request", "was", "made", "to", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L311-L318
29,053
rosasurfer/ministruts
src/ministruts/Request.php
Request.resolveBaseUriVar
private function resolveBaseUriVar() { $envName = 'APP_BASE_URI'; $envValue = null; if (!isset($_SERVER[$envName])) $envName = 'REDIRECT_'.$envName; while (isset($_SERVER[$envName])) { $envValue = $_SERVER[$envName]; $envName = 'REDIRECT_'.$envName; } return $envValue; }
php
private function resolveBaseUriVar() { $envName = 'APP_BASE_URI'; $envValue = null; if (!isset($_SERVER[$envName])) $envName = 'REDIRECT_'.$envName; while (isset($_SERVER[$envName])) { $envValue = $_SERVER[$envName]; $envName = 'REDIRECT_'.$envName; } return $envValue; }
[ "private", "function", "resolveBaseUriVar", "(", ")", "{", "$", "envName", "=", "'APP_BASE_URI'", ";", "$", "envValue", "=", "null", ";", "if", "(", "!", "isset", "(", "$", "_SERVER", "[", "$", "envName", "]", ")", ")", "$", "envName", "=", "'REDIRECT_'", ".", "$", "envName", ";", "while", "(", "isset", "(", "$", "_SERVER", "[", "$", "envName", "]", ")", ")", "{", "$", "envValue", "=", "$", "_SERVER", "[", "$", "envName", "]", ";", "$", "envName", "=", "'REDIRECT_'", ".", "$", "envName", ";", "}", "return", "$", "envValue", ";", "}" ]
Resolve the value of an existing APP_BASE_URI server variable. Considers existing redirection values. @return string|null - value or NULL if the variable is not defined
[ "Resolve", "the", "value", "of", "an", "existing", "APP_BASE_URI", "server", "variable", ".", "Considers", "existing", "redirection", "values", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L487-L499
29,054
rosasurfer/ministruts
src/ministruts/Request.php
Request.getQueryString
public function getQueryString() { // The variable $_SERVER['QUERY_STRING'] is set by the server and can differ from the transmitted query string. // It might hold additional parameters added by the server or it might be empty (e.g. on a mis-configured nginx). if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING'])) { $query = $_SERVER['QUERY_STRING']; } else { $query = strRightFrom($_SERVER['REQUEST_URI'], '?'); } return $query; }
php
public function getQueryString() { // The variable $_SERVER['QUERY_STRING'] is set by the server and can differ from the transmitted query string. // It might hold additional parameters added by the server or it might be empty (e.g. on a mis-configured nginx). if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING'])) { $query = $_SERVER['QUERY_STRING']; } else { $query = strRightFrom($_SERVER['REQUEST_URI'], '?'); } return $query; }
[ "public", "function", "getQueryString", "(", ")", "{", "// The variable $_SERVER['QUERY_STRING'] is set by the server and can differ from the transmitted query string.", "// It might hold additional parameters added by the server or it might be empty (e.g. on a mis-configured nginx).", "if", "(", "isset", "(", "$", "_SERVER", "[", "'QUERY_STRING'", "]", ")", "&&", "strlen", "(", "$", "_SERVER", "[", "'QUERY_STRING'", "]", ")", ")", "{", "$", "query", "=", "$", "_SERVER", "[", "'QUERY_STRING'", "]", ";", "}", "else", "{", "$", "query", "=", "strRightFrom", "(", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ",", "'?'", ")", ";", "}", "return", "$", "query", ";", "}" ]
Return the query string of the request's URL. @return string @example <pre> $request->getUrl(): "http://a.domain.tld/path/application/module/foo/bar.html?key=value" $request->getQueryString(): "key=value" </pre>
[ "Return", "the", "query", "string", "of", "the", "request", "s", "URL", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L513-L524
29,055
rosasurfer/ministruts
src/ministruts/Request.php
Request.getRemoteHostname
public function getRemoteHostname() { static $hostname = null; if (!$hostname) { /** @var string $hostname */ $hostname = NetTools::getHostByAddress($this->getRemoteAddress()); } return $hostname; }
php
public function getRemoteHostname() { static $hostname = null; if (!$hostname) { /** @var string $hostname */ $hostname = NetTools::getHostByAddress($this->getRemoteAddress()); } return $hostname; }
[ "public", "function", "getRemoteHostname", "(", ")", "{", "static", "$", "hostname", "=", "null", ";", "if", "(", "!", "$", "hostname", ")", "{", "/** @var string $hostname */", "$", "hostname", "=", "NetTools", "::", "getHostByAddress", "(", "$", "this", "->", "getRemoteAddress", "(", ")", ")", ";", "}", "return", "$", "hostname", ";", "}" ]
Return the name of the host the request was made from. @return string - host name
[ "Return", "the", "name", "of", "the", "host", "the", "request", "was", "made", "from", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L542-L549
29,056
rosasurfer/ministruts
src/ministruts/Request.php
Request.getContentType
public function getContentType() { $contentType = $this->getHeaderValue('Content-Type'); if ($contentType) { $headers = explode(',', $contentType, 2); $contentType = \array_shift($headers); $values = explode(';', $contentType, 2); $contentType = trim(\array_shift($values)); } return $contentType; }
php
public function getContentType() { $contentType = $this->getHeaderValue('Content-Type'); if ($contentType) { $headers = explode(',', $contentType, 2); $contentType = \array_shift($headers); $values = explode(';', $contentType, 2); $contentType = trim(\array_shift($values)); } return $contentType; }
[ "public", "function", "getContentType", "(", ")", "{", "$", "contentType", "=", "$", "this", "->", "getHeaderValue", "(", "'Content-Type'", ")", ";", "if", "(", "$", "contentType", ")", "{", "$", "headers", "=", "explode", "(", "','", ",", "$", "contentType", ",", "2", ")", ";", "$", "contentType", "=", "\\", "array_shift", "(", "$", "headers", ")", ";", "$", "values", "=", "explode", "(", "';'", ",", "$", "contentType", ",", "2", ")", ";", "$", "contentType", "=", "trim", "(", "\\", "array_shift", "(", "$", "values", ")", ")", ";", "}", "return", "$", "contentType", ";", "}" ]
Return the "Content-Type" header of the request. If multiple "Content-Type" headers have been transmitted the first one is returned. @return string|null - "Content-Type" header or NULL if no "Content-Type" header was transmitted.
[ "Return", "the", "Content", "-", "Type", "header", "of", "the", "request", ".", "If", "multiple", "Content", "-", "Type", "headers", "have", "been", "transmitted", "the", "first", "one", "is", "returned", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L597-L608
29,057
rosasurfer/ministruts
src/ministruts/Request.php
Request.isSessionAttribute
public function isSessionAttribute($key) { if ($this->isSession() || $this->hasSessionId()) return $this->getSession()->isAttribute($key); return false; }
php
public function isSessionAttribute($key) { if ($this->isSession() || $this->hasSessionId()) return $this->getSession()->isAttribute($key); return false; }
[ "public", "function", "isSessionAttribute", "(", "$", "key", ")", "{", "if", "(", "$", "this", "->", "isSession", "(", ")", "||", "$", "this", "->", "hasSessionId", "(", ")", ")", "return", "$", "this", "->", "getSession", "(", ")", "->", "isAttribute", "(", "$", "key", ")", ";", "return", "false", ";", "}" ]
Whether a session attribute of the specified name exists. If no session exists none is started. @param string $key - key @return bool
[ "Whether", "a", "session", "attribute", "of", "the", "specified", "name", "exists", ".", "If", "no", "session", "exists", "none", "is", "started", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L640-L644
29,058
rosasurfer/ministruts
src/ministruts/Request.php
Request.hasSessionId
public function hasSessionId() { $name = session_name(); if (ini_get_bool('session.use_cookies')) if (isset($_COOKIE[$name])) return true; if (!ini_get_bool('session.use_only_cookies')) if (isset($_REQUEST[$name])) return true; return false; }
php
public function hasSessionId() { $name = session_name(); if (ini_get_bool('session.use_cookies')) if (isset($_COOKIE[$name])) return true; if (!ini_get_bool('session.use_only_cookies')) if (isset($_REQUEST[$name])) return true; return false; }
[ "public", "function", "hasSessionId", "(", ")", "{", "$", "name", "=", "session_name", "(", ")", ";", "if", "(", "ini_get_bool", "(", "'session.use_cookies'", ")", ")", "if", "(", "isset", "(", "$", "_COOKIE", "[", "$", "name", "]", ")", ")", "return", "true", ";", "if", "(", "!", "ini_get_bool", "(", "'session.use_only_cookies'", ")", ")", "if", "(", "isset", "(", "$", "_REQUEST", "[", "$", "name", "]", ")", ")", "return", "true", ";", "return", "false", ";", "}" ]
Whether a valid session id was transmitted with the request. An invalid id is a URL based session id when the php.ini setting 'session.use_only_cookies' is enabled. @return bool
[ "Whether", "a", "valid", "session", "id", "was", "transmitted", "with", "the", "request", ".", "An", "invalid", "id", "is", "a", "URL", "based", "session", "id", "when", "the", "php", ".", "ini", "setting", "session", ".", "use_only_cookies", "is", "enabled", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L673-L685
29,059
rosasurfer/ministruts
src/ministruts/Request.php
Request.destroySession
public function destroySession() { if (session_status() == PHP_SESSION_ACTIVE) { // unset all session variables $_SESSION = []; // delete the session cookie if (ini_get_bool('session.use_cookies')) { $params = session_get_cookie_params(); setcookie($name=session_name(), $value='', $expire=time()-1*DAY, $params['path' ], $params['domain' ], $params['secure' ], $params['httponly']); } session_destroy(); // TODO: check if SID is reset } }
php
public function destroySession() { if (session_status() == PHP_SESSION_ACTIVE) { // unset all session variables $_SESSION = []; // delete the session cookie if (ini_get_bool('session.use_cookies')) { $params = session_get_cookie_params(); setcookie($name=session_name(), $value='', $expire=time()-1*DAY, $params['path' ], $params['domain' ], $params['secure' ], $params['httponly']); } session_destroy(); // TODO: check if SID is reset } }
[ "public", "function", "destroySession", "(", ")", "{", "if", "(", "session_status", "(", ")", "==", "PHP_SESSION_ACTIVE", ")", "{", "// unset all session variables", "$", "_SESSION", "=", "[", "]", ";", "// delete the session cookie", "if", "(", "ini_get_bool", "(", "'session.use_cookies'", ")", ")", "{", "$", "params", "=", "session_get_cookie_params", "(", ")", ";", "setcookie", "(", "$", "name", "=", "session_name", "(", ")", ",", "$", "value", "=", "''", ",", "$", "expire", "=", "time", "(", ")", "-", "1", "*", "DAY", ",", "$", "params", "[", "'path'", "]", ",", "$", "params", "[", "'domain'", "]", ",", "$", "params", "[", "'secure'", "]", ",", "$", "params", "[", "'httponly'", "]", ")", ";", "}", "session_destroy", "(", ")", ";", "// TODO: check if SID is reset", "}", "}" ]
Destroy the current session and it's data.
[ "Destroy", "the", "current", "session", "and", "it", "s", "data", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L691-L706
29,060
rosasurfer/ministruts
src/ministruts/Request.php
Request.getHeader
public function getHeader($name) { if (!is_string($name)) throw new IllegalTypeException('Illegal type of parameter $name: '.gettype($name)); $headers = $this->getHeaders($name); return \array_shift($headers); }
php
public function getHeader($name) { if (!is_string($name)) throw new IllegalTypeException('Illegal type of parameter $name: '.gettype($name)); $headers = $this->getHeaders($name); return \array_shift($headers); }
[ "public", "function", "getHeader", "(", "$", "name", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", ")", "throw", "new", "IllegalTypeException", "(", "'Illegal type of parameter $name: '", ".", "gettype", "(", "$", "name", ")", ")", ";", "$", "headers", "=", "$", "this", "->", "getHeaders", "(", "$", "name", ")", ";", "return", "\\", "array_shift", "(", "$", "headers", ")", ";", "}" ]
Gibt den Wert des angegebenen Headers zurueck. Wurden mehrere Header dieses Namens uebertragen, wird der Wert des ersten uebertragenen Headers zurueckgegeben. @param string $name - Name des Headers @return string|null - Wert oder NULL, wenn kein Header dieses Namens uebertragen wurde
[ "Gibt", "den", "Wert", "des", "angegebenen", "Headers", "zurueck", ".", "Wurden", "mehrere", "Header", "dieses", "Namens", "uebertragen", "wird", "der", "Wert", "des", "ersten", "uebertragenen", "Headers", "zurueckgegeben", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L717-L722
29,061
rosasurfer/ministruts
src/ministruts/Request.php
Request.getAttribute
public function getAttribute($key) { if (key_exists($key, $this->attributes)) return $this->attributes[$key]; return null; }
php
public function getAttribute($key) { if (key_exists($key, $this->attributes)) return $this->attributes[$key]; return null; }
[ "public", "function", "getAttribute", "(", "$", "key", ")", "{", "if", "(", "key_exists", "(", "$", "key", ",", "$", "this", "->", "attributes", ")", ")", "return", "$", "this", "->", "attributes", "[", "$", "key", "]", ";", "return", "null", ";", "}" ]
Gibt den im Request-Context unter dem angegebenen Schluessel gespeicherten Wert zurueck oder NULL, wenn unter diesem Schluessel kein Wert existiert. @param string $key - Schluessel, unter dem der Wert im Context gespeichert ist @return mixed - der gespeicherte Wert oder NULL
[ "Gibt", "den", "im", "Request", "-", "Context", "unter", "dem", "angegebenen", "Schluessel", "gespeicherten", "Wert", "zurueck", "oder", "NULL", "wenn", "unter", "diesem", "Schluessel", "kein", "Wert", "existiert", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L842-L846
29,062
rosasurfer/ministruts
src/ministruts/Request.php
Request.setCookie
public function setCookie($name, $value, $expires = 0, $path = null) { if (!is_string($name)) throw new IllegalTypeException('Illegal type of parameter $name: '.gettype($name)); if (!is_int($expires)) throw new IllegalTypeException('Illegal type of parameter $expires: '.gettype($expires)); if ($expires < 0) throw new InvalidArgumentException('Invalid argument $expires: '.$expires); $value = (string)$value; if ($path === null) $path = $this->getApplicationBaseUri(); if (!is_string($path)) throw new IllegalTypeException('Illegal type of parameter $path: '.gettype($path)); \setcookie($name, $value, $expires, $path); }
php
public function setCookie($name, $value, $expires = 0, $path = null) { if (!is_string($name)) throw new IllegalTypeException('Illegal type of parameter $name: '.gettype($name)); if (!is_int($expires)) throw new IllegalTypeException('Illegal type of parameter $expires: '.gettype($expires)); if ($expires < 0) throw new InvalidArgumentException('Invalid argument $expires: '.$expires); $value = (string)$value; if ($path === null) $path = $this->getApplicationBaseUri(); if (!is_string($path)) throw new IllegalTypeException('Illegal type of parameter $path: '.gettype($path)); \setcookie($name, $value, $expires, $path); }
[ "public", "function", "setCookie", "(", "$", "name", ",", "$", "value", ",", "$", "expires", "=", "0", ",", "$", "path", "=", "null", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", ")", "throw", "new", "IllegalTypeException", "(", "'Illegal type of parameter $name: '", ".", "gettype", "(", "$", "name", ")", ")", ";", "if", "(", "!", "is_int", "(", "$", "expires", ")", ")", "throw", "new", "IllegalTypeException", "(", "'Illegal type of parameter $expires: '", ".", "gettype", "(", "$", "expires", ")", ")", ";", "if", "(", "$", "expires", "<", "0", ")", "throw", "new", "InvalidArgumentException", "(", "'Invalid argument $expires: '", ".", "$", "expires", ")", ";", "$", "value", "=", "(", "string", ")", "$", "value", ";", "if", "(", "$", "path", "===", "null", ")", "$", "path", "=", "$", "this", "->", "getApplicationBaseUri", "(", ")", ";", "if", "(", "!", "is_string", "(", "$", "path", ")", ")", "throw", "new", "IllegalTypeException", "(", "'Illegal type of parameter $path: '", ".", "gettype", "(", "$", "path", ")", ")", ";", "\\", "setcookie", "(", "$", "name", ",", "$", "value", ",", "$", "expires", ",", "$", "path", ")", ";", "}" ]
Setzt einen Cookie mit den angegebenen Daten. @param string $name - Name des Cookies @param mixed $value - der zu speichernde Wert (wird zu String gecastet) @param int $expires - Lebenszeit des Cookies (0: bis zum Schliessen des Browsers) @param string $path [optional] - Pfad, fuer den der Cookie gueltig sein soll (default: whole domain)
[ "Setzt", "einen", "Cookie", "mit", "den", "angegebenen", "Daten", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L891-L904
29,063
rosasurfer/ministruts
src/ministruts/Request.php
Request.getActionMessage
public function getActionMessage($key = null) { $messages = $this->getAttribute(ACTION_MESSAGES_KEY); if ($key === null) { // return the first one if ($messages) { foreach ($messages as $message) return $message; } } elseif (key_exists($key, $messages)) { // return the specified one return $messages[$key]; } return $this->getActionError($key); // look-up separately stored ActionErrors }
php
public function getActionMessage($key = null) { $messages = $this->getAttribute(ACTION_MESSAGES_KEY); if ($key === null) { // return the first one if ($messages) { foreach ($messages as $message) return $message; } } elseif (key_exists($key, $messages)) { // return the specified one return $messages[$key]; } return $this->getActionError($key); // look-up separately stored ActionErrors }
[ "public", "function", "getActionMessage", "(", "$", "key", "=", "null", ")", "{", "$", "messages", "=", "$", "this", "->", "getAttribute", "(", "ACTION_MESSAGES_KEY", ")", ";", "if", "(", "$", "key", "===", "null", ")", "{", "// return the first one", "if", "(", "$", "messages", ")", "{", "foreach", "(", "$", "messages", "as", "$", "message", ")", "return", "$", "message", ";", "}", "}", "elseif", "(", "key_exists", "(", "$", "key", ",", "$", "messages", ")", ")", "{", "// return the specified one", "return", "$", "messages", "[", "$", "key", "]", ";", "}", "return", "$", "this", "->", "getActionError", "(", "$", "key", ")", ";", "// look-up separately stored ActionErrors", "}" ]
Return the ActionMessage for the specified key or the first ActionMessage if no key was given. @param string $key [optional] @return string|null - ActionMessage
[ "Return", "the", "ActionMessage", "for", "the", "specified", "key", "or", "the", "first", "ActionMessage", "if", "no", "key", "was", "given", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L937-L949
29,064
rosasurfer/ministruts
src/ministruts/Request.php
Request.getActionMessages
public function getActionMessages() { $messages = $this->getAttribute(ACTION_MESSAGES_KEY); if ($messages === null) $messages = []; $errors = $this->getActionErrors(); return \array_merge($messages, $errors); }
php
public function getActionMessages() { $messages = $this->getAttribute(ACTION_MESSAGES_KEY); if ($messages === null) $messages = []; $errors = $this->getActionErrors(); return \array_merge($messages, $errors); }
[ "public", "function", "getActionMessages", "(", ")", "{", "$", "messages", "=", "$", "this", "->", "getAttribute", "(", "ACTION_MESSAGES_KEY", ")", ";", "if", "(", "$", "messages", "===", "null", ")", "$", "messages", "=", "[", "]", ";", "$", "errors", "=", "$", "this", "->", "getActionErrors", "(", ")", ";", "return", "\\", "array_merge", "(", "$", "messages", ",", "$", "errors", ")", ";", "}" ]
Return all existing ActionMessages, including ActionErrors. @return array
[ "Return", "all", "existing", "ActionMessages", "including", "ActionErrors", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L957-L964
29,065
rosasurfer/ministruts
src/ministruts/Request.php
Request.isActionMessage
public function isActionMessage($keys = null) { $messages = $this->getAttribute(ACTION_MESSAGES_KEY); if (!$messages) return $this->isActionError($keys); if (is_string($keys)) $keys = [$keys]; if (is_array($keys)) { foreach ($keys as $key) { if (key_exists($key, $messages)) return true; } if ($keys) return $this->isActionError($keys); $keys = null; } if (is_null($keys)) return true; throw new IllegalTypeException('Illegal type of parameter $keys: '.gettype($keys)); }
php
public function isActionMessage($keys = null) { $messages = $this->getAttribute(ACTION_MESSAGES_KEY); if (!$messages) return $this->isActionError($keys); if (is_string($keys)) $keys = [$keys]; if (is_array($keys)) { foreach ($keys as $key) { if (key_exists($key, $messages)) return true; } if ($keys) return $this->isActionError($keys); $keys = null; } if (is_null($keys)) return true; throw new IllegalTypeException('Illegal type of parameter $keys: '.gettype($keys)); }
[ "public", "function", "isActionMessage", "(", "$", "keys", "=", "null", ")", "{", "$", "messages", "=", "$", "this", "->", "getAttribute", "(", "ACTION_MESSAGES_KEY", ")", ";", "if", "(", "!", "$", "messages", ")", "return", "$", "this", "->", "isActionError", "(", "$", "keys", ")", ";", "if", "(", "is_string", "(", "$", "keys", ")", ")", "$", "keys", "=", "[", "$", "keys", "]", ";", "if", "(", "is_array", "(", "$", "keys", ")", ")", "{", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "key_exists", "(", "$", "key", ",", "$", "messages", ")", ")", "return", "true", ";", "}", "if", "(", "$", "keys", ")", "return", "$", "this", "->", "isActionError", "(", "$", "keys", ")", ";", "$", "keys", "=", "null", ";", "}", "if", "(", "is_null", "(", "$", "keys", ")", ")", "return", "true", ";", "throw", "new", "IllegalTypeException", "(", "'Illegal type of parameter $keys: '", ".", "gettype", "(", "$", "keys", ")", ")", ";", "}" ]
Whether an ActionMessage exists for one of the specified keys, or for any key if no key was given. @param string|string[] $keys [optional] - message keys @return bool
[ "Whether", "an", "ActionMessage", "exists", "for", "one", "of", "the", "specified", "keys", "or", "for", "any", "key", "if", "no", "key", "was", "given", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L974-L994
29,066
rosasurfer/ministruts
src/ministruts/Request.php
Request.setActionMessage
public function setActionMessage($key, $message) { if (!isset($message)) { unset($this->attributes[ACTION_MESSAGES_KEY][$key]); } elseif (is_string($message)) { $this->attributes[ACTION_MESSAGES_KEY][$key] = $message; } else throw new IllegalTypeException('Illegal type of parameter $message: '.gettype($message)); }
php
public function setActionMessage($key, $message) { if (!isset($message)) { unset($this->attributes[ACTION_MESSAGES_KEY][$key]); } elseif (is_string($message)) { $this->attributes[ACTION_MESSAGES_KEY][$key] = $message; } else throw new IllegalTypeException('Illegal type of parameter $message: '.gettype($message)); }
[ "public", "function", "setActionMessage", "(", "$", "key", ",", "$", "message", ")", "{", "if", "(", "!", "isset", "(", "$", "message", ")", ")", "{", "unset", "(", "$", "this", "->", "attributes", "[", "ACTION_MESSAGES_KEY", "]", "[", "$", "key", "]", ")", ";", "}", "elseif", "(", "is_string", "(", "$", "message", ")", ")", "{", "$", "this", "->", "attributes", "[", "ACTION_MESSAGES_KEY", "]", "[", "$", "key", "]", "=", "$", "message", ";", "}", "else", "throw", "new", "IllegalTypeException", "(", "'Illegal type of parameter $message: '", ".", "gettype", "(", "$", "message", ")", ")", ";", "}" ]
Store or delete an ActionMessage for the specified key. @param string $key - message key @param string $message - message; if NULL the message for the specified key is deleted (an ActionError with the same key is not deleted)
[ "Store", "or", "delete", "an", "ActionMessage", "for", "the", "specified", "key", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L1004-L1012
29,067
rosasurfer/ministruts
src/ministruts/Request.php
Request.removeActionMessages
public function removeActionMessages(...$keys) { $messages = $this->getAttribute(ACTION_MESSAGES_KEY); $dropped = []; foreach ($keys as $key) { if (isset($messages[$key])) $dropped[$key] = $messages[$key]; unset($this->attributes[ACTION_MESSAGES_KEY][$key]); } if ($keys) return $dropped; unset($this->attributes[ACTION_MESSAGES_KEY]); return $messages; }
php
public function removeActionMessages(...$keys) { $messages = $this->getAttribute(ACTION_MESSAGES_KEY); $dropped = []; foreach ($keys as $key) { if (isset($messages[$key])) $dropped[$key] = $messages[$key]; unset($this->attributes[ACTION_MESSAGES_KEY][$key]); } if ($keys) return $dropped; unset($this->attributes[ACTION_MESSAGES_KEY]); return $messages; }
[ "public", "function", "removeActionMessages", "(", "...", "$", "keys", ")", "{", "$", "messages", "=", "$", "this", "->", "getAttribute", "(", "ACTION_MESSAGES_KEY", ")", ";", "$", "dropped", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "messages", "[", "$", "key", "]", ")", ")", "$", "dropped", "[", "$", "key", "]", "=", "$", "messages", "[", "$", "key", "]", ";", "unset", "(", "$", "this", "->", "attributes", "[", "ACTION_MESSAGES_KEY", "]", "[", "$", "key", "]", ")", ";", "}", "if", "(", "$", "keys", ")", "return", "$", "dropped", ";", "unset", "(", "$", "this", "->", "attributes", "[", "ACTION_MESSAGES_KEY", "]", ")", ";", "return", "$", "messages", ";", "}" ]
Delete the ActionMessages with the specified keys. @param string[] ...$keys - zero or more message keys to delete; without a key all ActionMessages are deleted (ActionErrors with the same keys are not deleted @return array - the deleted ActionMessages
[ "Delete", "the", "ActionMessages", "with", "the", "specified", "keys", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L1023-L1037
29,068
rosasurfer/ministruts
src/ministruts/Request.php
Request.getActionError
public function getActionError($key = null) { $errors = $this->getAttribute(ACTION_ERRORS_KEY); if ($key === null) { // return the first one if ($errors) { foreach ($errors as $error) return $error; } } elseif (key_exists($key, $errors)) { // return the specified one return $errors[$key]; } return null; }
php
public function getActionError($key = null) { $errors = $this->getAttribute(ACTION_ERRORS_KEY); if ($key === null) { // return the first one if ($errors) { foreach ($errors as $error) return $error; } } elseif (key_exists($key, $errors)) { // return the specified one return $errors[$key]; } return null; }
[ "public", "function", "getActionError", "(", "$", "key", "=", "null", ")", "{", "$", "errors", "=", "$", "this", "->", "getAttribute", "(", "ACTION_ERRORS_KEY", ")", ";", "if", "(", "$", "key", "===", "null", ")", "{", "// return the first one", "if", "(", "$", "errors", ")", "{", "foreach", "(", "$", "errors", "as", "$", "error", ")", "return", "$", "error", ";", "}", "}", "elseif", "(", "key_exists", "(", "$", "key", ",", "$", "errors", ")", ")", "{", "// return the specified one", "return", "$", "errors", "[", "$", "key", "]", ";", "}", "return", "null", ";", "}" ]
Return the ActionError for the specified key or the first ActionError if no key was given. @param string $key [optional] @return string|null - ActionError
[ "Return", "the", "ActionError", "for", "the", "specified", "key", "or", "the", "first", "ActionError", "if", "no", "key", "was", "given", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L1047-L1059
29,069
rosasurfer/ministruts
src/ministruts/Request.php
Request.isActionError
public function isActionError($keys = null) { $errors = $this->getAttribute(ACTION_ERRORS_KEY); if (!$errors) return false; if (is_string($keys)) $keys = [$keys]; if (is_array($keys)) { foreach ($keys as $key) { if (key_exists($key, $errors)) return true; } if ($keys) return false; $keys = null; } if (is_null($keys)) return true; throw new IllegalTypeException('Illegal type of parameter $keys: '.gettype($keys)); }
php
public function isActionError($keys = null) { $errors = $this->getAttribute(ACTION_ERRORS_KEY); if (!$errors) return false; if (is_string($keys)) $keys = [$keys]; if (is_array($keys)) { foreach ($keys as $key) { if (key_exists($key, $errors)) return true; } if ($keys) return false; $keys = null; } if (is_null($keys)) return true; throw new IllegalTypeException('Illegal type of parameter $keys: '.gettype($keys)); }
[ "public", "function", "isActionError", "(", "$", "keys", "=", "null", ")", "{", "$", "errors", "=", "$", "this", "->", "getAttribute", "(", "ACTION_ERRORS_KEY", ")", ";", "if", "(", "!", "$", "errors", ")", "return", "false", ";", "if", "(", "is_string", "(", "$", "keys", ")", ")", "$", "keys", "=", "[", "$", "keys", "]", ";", "if", "(", "is_array", "(", "$", "keys", ")", ")", "{", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "key_exists", "(", "$", "key", ",", "$", "errors", ")", ")", "return", "true", ";", "}", "if", "(", "$", "keys", ")", "return", "false", ";", "$", "keys", "=", "null", ";", "}", "if", "(", "is_null", "(", "$", "keys", ")", ")", "return", "true", ";", "throw", "new", "IllegalTypeException", "(", "'Illegal type of parameter $keys: '", ".", "gettype", "(", "$", "keys", ")", ")", ";", "}" ]
Whether an ActionError exists for one of the specified keys or for any key if no key was given. @param string|string[] $keys [optional] - error keys @return bool
[ "Whether", "an", "ActionError", "exists", "for", "one", "of", "the", "specified", "keys", "or", "for", "any", "key", "if", "no", "key", "was", "given", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L1082-L1102
29,070
rosasurfer/ministruts
src/ministruts/Request.php
Request.setActionError
public function setActionError($key, $message) { if (!isset($message)) { unset($this->attributes[ACTION_ERRORS_KEY][$key]); } elseif (is_string($message)) { $this->attributes[ACTION_ERRORS_KEY][$key] = $message; } else throw new IllegalTypeException('Illegal type of parameter $message: '.gettype($message)); }
php
public function setActionError($key, $message) { if (!isset($message)) { unset($this->attributes[ACTION_ERRORS_KEY][$key]); } elseif (is_string($message)) { $this->attributes[ACTION_ERRORS_KEY][$key] = $message; } else throw new IllegalTypeException('Illegal type of parameter $message: '.gettype($message)); }
[ "public", "function", "setActionError", "(", "$", "key", ",", "$", "message", ")", "{", "if", "(", "!", "isset", "(", "$", "message", ")", ")", "{", "unset", "(", "$", "this", "->", "attributes", "[", "ACTION_ERRORS_KEY", "]", "[", "$", "key", "]", ")", ";", "}", "elseif", "(", "is_string", "(", "$", "message", ")", ")", "{", "$", "this", "->", "attributes", "[", "ACTION_ERRORS_KEY", "]", "[", "$", "key", "]", "=", "$", "message", ";", "}", "else", "throw", "new", "IllegalTypeException", "(", "'Illegal type of parameter $message: '", ".", "gettype", "(", "$", "message", ")", ")", ";", "}" ]
Store or delete an ActionError for the specified key. @param string $key - error key @param string $message - error message; if NULL the error for the specified key is deleted
[ "Store", "or", "delete", "an", "ActionError", "for", "the", "specified", "key", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L1111-L1119
29,071
rosasurfer/ministruts
src/ministruts/Request.php
Request.removeActionErrors
public function removeActionErrors(...$keys) { $errors = $this->getAttribute(ACTION_ERRORS_KEY); $dropped = []; foreach ($keys as $key) { if (isset($errors[$key])) $dropped[$key] = $errors[$key]; unset($this->attributes[ACTION_ERRORS_KEY][$key]); } if ($keys) return $dropped; unset($this->attributes[ACTION_ERRORS_KEY]); return $errors; }
php
public function removeActionErrors(...$keys) { $errors = $this->getAttribute(ACTION_ERRORS_KEY); $dropped = []; foreach ($keys as $key) { if (isset($errors[$key])) $dropped[$key] = $errors[$key]; unset($this->attributes[ACTION_ERRORS_KEY][$key]); } if ($keys) return $dropped; unset($this->attributes[ACTION_ERRORS_KEY]); return $errors; }
[ "public", "function", "removeActionErrors", "(", "...", "$", "keys", ")", "{", "$", "errors", "=", "$", "this", "->", "getAttribute", "(", "ACTION_ERRORS_KEY", ")", ";", "$", "dropped", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "errors", "[", "$", "key", "]", ")", ")", "$", "dropped", "[", "$", "key", "]", "=", "$", "errors", "[", "$", "key", "]", ";", "unset", "(", "$", "this", "->", "attributes", "[", "ACTION_ERRORS_KEY", "]", "[", "$", "key", "]", ")", ";", "}", "if", "(", "$", "keys", ")", "return", "$", "dropped", ";", "unset", "(", "$", "this", "->", "attributes", "[", "ACTION_ERRORS_KEY", "]", ")", ";", "return", "$", "errors", ";", "}" ]
Delete the ActionErrors with the specified keys. @param string[] ...$keys - zero or more error keys to delete; without a key all ActionErrors are deleted @return array - the deleted ActionErrors
[ "Delete", "the", "ActionErrors", "with", "the", "specified", "keys", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Request.php#L1129-L1143
29,072
timble/kodekit
code/controller/toolbar/actionbar.php
ControllerToolbarActionbar._afterRead
protected function _afterRead(ControllerContext $context) { $controller = $this->getController(); if($controller->isEditable() && $controller->canSave()) { $this->addCommand('save'); } if($controller->isEditable() && $controller->canApply()) { $this->addCommand('apply'); } if($controller->isEditable() && $controller->canCancel()) { $this->addCommand('cancel', array('attribs' => array('data-novalidate' => 'novalidate'))); } }
php
protected function _afterRead(ControllerContext $context) { $controller = $this->getController(); if($controller->isEditable() && $controller->canSave()) { $this->addCommand('save'); } if($controller->isEditable() && $controller->canApply()) { $this->addCommand('apply'); } if($controller->isEditable() && $controller->canCancel()) { $this->addCommand('cancel', array('attribs' => array('data-novalidate' => 'novalidate'))); } }
[ "protected", "function", "_afterRead", "(", "ControllerContext", "$", "context", ")", "{", "$", "controller", "=", "$", "this", "->", "getController", "(", ")", ";", "if", "(", "$", "controller", "->", "isEditable", "(", ")", "&&", "$", "controller", "->", "canSave", "(", ")", ")", "{", "$", "this", "->", "addCommand", "(", "'save'", ")", ";", "}", "if", "(", "$", "controller", "->", "isEditable", "(", ")", "&&", "$", "controller", "->", "canApply", "(", ")", ")", "{", "$", "this", "->", "addCommand", "(", "'apply'", ")", ";", "}", "if", "(", "$", "controller", "->", "isEditable", "(", ")", "&&", "$", "controller", "->", "canCancel", "(", ")", ")", "{", "$", "this", "->", "addCommand", "(", "'cancel'", ",", "array", "(", "'attribs'", "=>", "array", "(", "'data-novalidate'", "=>", "'novalidate'", ")", ")", ")", ";", "}", "}" ]
Add default toolbar commands and set the toolbar title . @param ControllerContext $context A controller context object
[ "Add", "default", "toolbar", "commands", "and", "set", "the", "toolbar", "title", "." ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/controller/toolbar/actionbar.php#L42-L57
29,073
timble/kodekit
code/model/database.php
ModelDatabase.setTable
public function setTable($table) { if(!($table instanceof DatabaseTableInterface)) { if(is_string($table) && strpos($table, '.') === false ) { $identifier = $this->getIdentifier()->toArray(); $identifier['path'] = array('database', 'table'); $identifier['name'] = StringInflector::pluralize(StringInflector::underscore($table)); $identifier = $this->getIdentifier($identifier); } else $identifier = $this->getIdentifier($table); if($identifier->path[1] != 'table') { throw new \UnexpectedValueException('Identifier: '.$identifier.' is not a table identifier'); } $table = $identifier; } $this->_table = $table; return $this; }
php
public function setTable($table) { if(!($table instanceof DatabaseTableInterface)) { if(is_string($table) && strpos($table, '.') === false ) { $identifier = $this->getIdentifier()->toArray(); $identifier['path'] = array('database', 'table'); $identifier['name'] = StringInflector::pluralize(StringInflector::underscore($table)); $identifier = $this->getIdentifier($identifier); } else $identifier = $this->getIdentifier($table); if($identifier->path[1] != 'table') { throw new \UnexpectedValueException('Identifier: '.$identifier.' is not a table identifier'); } $table = $identifier; } $this->_table = $table; return $this; }
[ "public", "function", "setTable", "(", "$", "table", ")", "{", "if", "(", "!", "(", "$", "table", "instanceof", "DatabaseTableInterface", ")", ")", "{", "if", "(", "is_string", "(", "$", "table", ")", "&&", "strpos", "(", "$", "table", ",", "'.'", ")", "===", "false", ")", "{", "$", "identifier", "=", "$", "this", "->", "getIdentifier", "(", ")", "->", "toArray", "(", ")", ";", "$", "identifier", "[", "'path'", "]", "=", "array", "(", "'database'", ",", "'table'", ")", ";", "$", "identifier", "[", "'name'", "]", "=", "StringInflector", "::", "pluralize", "(", "StringInflector", "::", "underscore", "(", "$", "table", ")", ")", ";", "$", "identifier", "=", "$", "this", "->", "getIdentifier", "(", "$", "identifier", ")", ";", "}", "else", "$", "identifier", "=", "$", "this", "->", "getIdentifier", "(", "$", "table", ")", ";", "if", "(", "$", "identifier", "->", "path", "[", "1", "]", "!=", "'table'", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "'Identifier: '", ".", "$", "identifier", ".", "' is not a table identifier'", ")", ";", "}", "$", "table", "=", "$", "identifier", ";", "}", "$", "this", "->", "_table", "=", "$", "table", ";", "return", "$", "this", ";", "}" ]
Method to set a table object attached to the model @param mixed $table An object that implements ObjectInterface, ObjectIdentifier object or valid identifier string @throws \UnexpectedValueException If the identifier is not a table identifier @return ModelDatabase
[ "Method", "to", "set", "a", "table", "object", "attached", "to", "the", "model" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/model/database.php#L168-L192
29,074
timble/kodekit
code/dispatcher/request/transport/data.php
DispatcherRequestTransportData.receive
public function receive(DispatcherRequestInterface $request) { if($request->getContentType() == 'application/x-www-form-urlencoded') { if (in_array($request->getMethod(), array('PUT', 'DELETE', 'PATCH'))) { parse_str($request->getContent(), $data); $request->getData()->add($data); } } if(in_array($request->getContentType(), array('application/json', 'application/x-json', 'application/vnd.api+json'))) { if(in_array($request->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) { $data = array(); if ($content = $request->getContent()) { $data = json_decode($content, true); } if ($data) { $request->getData()->add($data); } // Transform the JSON API request payloads if($request->getContentType() == 'application/vnd.api+json') { if (is_array($request->data->data)) { $data = $request->data->data; if (isset($data['attributes']) && is_array($data['attributes'])) { $request->data->add($data['attributes']); } } } } } }
php
public function receive(DispatcherRequestInterface $request) { if($request->getContentType() == 'application/x-www-form-urlencoded') { if (in_array($request->getMethod(), array('PUT', 'DELETE', 'PATCH'))) { parse_str($request->getContent(), $data); $request->getData()->add($data); } } if(in_array($request->getContentType(), array('application/json', 'application/x-json', 'application/vnd.api+json'))) { if(in_array($request->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) { $data = array(); if ($content = $request->getContent()) { $data = json_decode($content, true); } if ($data) { $request->getData()->add($data); } // Transform the JSON API request payloads if($request->getContentType() == 'application/vnd.api+json') { if (is_array($request->data->data)) { $data = $request->data->data; if (isset($data['attributes']) && is_array($data['attributes'])) { $request->data->add($data['attributes']); } } } } } }
[ "public", "function", "receive", "(", "DispatcherRequestInterface", "$", "request", ")", "{", "if", "(", "$", "request", "->", "getContentType", "(", ")", "==", "'application/x-www-form-urlencoded'", ")", "{", "if", "(", "in_array", "(", "$", "request", "->", "getMethod", "(", ")", ",", "array", "(", "'PUT'", ",", "'DELETE'", ",", "'PATCH'", ")", ")", ")", "{", "parse_str", "(", "$", "request", "->", "getContent", "(", ")", ",", "$", "data", ")", ";", "$", "request", "->", "getData", "(", ")", "->", "add", "(", "$", "data", ")", ";", "}", "}", "if", "(", "in_array", "(", "$", "request", "->", "getContentType", "(", ")", ",", "array", "(", "'application/json'", ",", "'application/x-json'", ",", "'application/vnd.api+json'", ")", ")", ")", "{", "if", "(", "in_array", "(", "$", "request", "->", "getMethod", "(", ")", ",", "array", "(", "'POST'", ",", "'PUT'", ",", "'DELETE'", ",", "'PATCH'", ")", ")", ")", "{", "$", "data", "=", "array", "(", ")", ";", "if", "(", "$", "content", "=", "$", "request", "->", "getContent", "(", ")", ")", "{", "$", "data", "=", "json_decode", "(", "$", "content", ",", "true", ")", ";", "}", "if", "(", "$", "data", ")", "{", "$", "request", "->", "getData", "(", ")", "->", "add", "(", "$", "data", ")", ";", "}", "// Transform the JSON API request payloads", "if", "(", "$", "request", "->", "getContentType", "(", ")", "==", "'application/vnd.api+json'", ")", "{", "if", "(", "is_array", "(", "$", "request", "->", "data", "->", "data", ")", ")", "{", "$", "data", "=", "$", "request", "->", "data", "->", "data", ";", "if", "(", "isset", "(", "$", "data", "[", "'attributes'", "]", ")", "&&", "is_array", "(", "$", "data", "[", "'attributes'", "]", ")", ")", "{", "$", "request", "->", "data", "->", "add", "(", "$", "data", "[", "'attributes'", "]", ")", ";", "}", "}", "}", "}", "}", "}" ]
Set the request data @param DispatcherRequestInterface $request
[ "Set", "the", "request", "data" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/dispatcher/request/transport/data.php#L27-L66
29,075
rosasurfer/ministruts
src/db/ConnectionPool.php
ConnectionPool.getConnector
public static function getConnector($id = null) { $me = self::me(); if ($id === null) { // a single db project if (!$me->default) throw new IllegalStateException('Invalid default database configuration: null'); $connector = $me->default; } elseif (isset($me->pool[$id])) { // is the connection already known? $connector = $me->pool[$id]; } else { // no, get the connection's config /** @var ConfigInterface $config */ $config = self::di('config'); $options = $config->get('db.'.$id, []); if (!is_array($options)) throw new IllegalTypeException('Invalid config value "db.'.$id.'": '.gettype($options).' (not array)'); if (!$options) throw new IllegalStateException('No configuration found for database alias "'.$id.'"'); // resolve the class name to use for the connector $className = $options['connector']; unset($options['connector']); $className = str_replace('/', '\\', $className); if ($className[0]=='\\') $className = substr($className, 1); // check known aliases for a match $lName = strtolower($className); if (isset(self::$aliases[$lName])) $className = self::$aliases[$lName]; // instantiate and save a new connector $me->pool[$id] = $connector = Connector::create($className, $options); } return $connector; }
php
public static function getConnector($id = null) { $me = self::me(); if ($id === null) { // a single db project if (!$me->default) throw new IllegalStateException('Invalid default database configuration: null'); $connector = $me->default; } elseif (isset($me->pool[$id])) { // is the connection already known? $connector = $me->pool[$id]; } else { // no, get the connection's config /** @var ConfigInterface $config */ $config = self::di('config'); $options = $config->get('db.'.$id, []); if (!is_array($options)) throw new IllegalTypeException('Invalid config value "db.'.$id.'": '.gettype($options).' (not array)'); if (!$options) throw new IllegalStateException('No configuration found for database alias "'.$id.'"'); // resolve the class name to use for the connector $className = $options['connector']; unset($options['connector']); $className = str_replace('/', '\\', $className); if ($className[0]=='\\') $className = substr($className, 1); // check known aliases for a match $lName = strtolower($className); if (isset(self::$aliases[$lName])) $className = self::$aliases[$lName]; // instantiate and save a new connector $me->pool[$id] = $connector = Connector::create($className, $options); } return $connector; }
[ "public", "static", "function", "getConnector", "(", "$", "id", "=", "null", ")", "{", "$", "me", "=", "self", "::", "me", "(", ")", ";", "if", "(", "$", "id", "===", "null", ")", "{", "// a single db project", "if", "(", "!", "$", "me", "->", "default", ")", "throw", "new", "IllegalStateException", "(", "'Invalid default database configuration: null'", ")", ";", "$", "connector", "=", "$", "me", "->", "default", ";", "}", "elseif", "(", "isset", "(", "$", "me", "->", "pool", "[", "$", "id", "]", ")", ")", "{", "// is the connection already known?", "$", "connector", "=", "$", "me", "->", "pool", "[", "$", "id", "]", ";", "}", "else", "{", "// no, get the connection's config", "/** @var ConfigInterface $config */", "$", "config", "=", "self", "::", "di", "(", "'config'", ")", ";", "$", "options", "=", "$", "config", "->", "get", "(", "'db.'", ".", "$", "id", ",", "[", "]", ")", ";", "if", "(", "!", "is_array", "(", "$", "options", ")", ")", "throw", "new", "IllegalTypeException", "(", "'Invalid config value \"db.'", ".", "$", "id", ".", "'\": '", ".", "gettype", "(", "$", "options", ")", ".", "' (not array)'", ")", ";", "if", "(", "!", "$", "options", ")", "throw", "new", "IllegalStateException", "(", "'No configuration found for database alias \"'", ".", "$", "id", ".", "'\"'", ")", ";", "// resolve the class name to use for the connector", "$", "className", "=", "$", "options", "[", "'connector'", "]", ";", "unset", "(", "$", "options", "[", "'connector'", "]", ")", ";", "$", "className", "=", "str_replace", "(", "'/'", ",", "'\\\\'", ",", "$", "className", ")", ";", "if", "(", "$", "className", "[", "0", "]", "==", "'\\\\'", ")", "$", "className", "=", "substr", "(", "$", "className", ",", "1", ")", ";", "// check known aliases for a match", "$", "lName", "=", "strtolower", "(", "$", "className", ")", ";", "if", "(", "isset", "(", "self", "::", "$", "aliases", "[", "$", "lName", "]", ")", ")", "$", "className", "=", "self", "::", "$", "aliases", "[", "$", "lName", "]", ";", "// instantiate and save a new connector", "$", "me", "->", "pool", "[", "$", "id", "]", "=", "$", "connector", "=", "Connector", "::", "create", "(", "$", "className", ",", "$", "options", ")", ";", "}", "return", "$", "connector", ";", "}" ]
Return the connector instance for the specified connection identifier. @param string $id [optional] - connection identifier @return IConnector - database adapter for the specified identifier
[ "Return", "the", "connector", "instance", "for", "the", "specified", "connection", "identifier", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/db/ConnectionPool.php#L64-L95
29,076
locomotivemtl/charcoal-core
src/Charcoal/Loader/CollectionLoaderFactoryTrait.php
CollectionLoaderFactoryTrait.collectionLoaderFactory
public function collectionLoaderFactory() { if (!isset($this->collectionLoaderFactory)) { throw new RuntimeException(sprintf( 'Collection Loader Factory is not defined for [%s]', get_class($this) )); } return $this->collectionLoaderFactory; }
php
public function collectionLoaderFactory() { if (!isset($this->collectionLoaderFactory)) { throw new RuntimeException(sprintf( 'Collection Loader Factory is not defined for [%s]', get_class($this) )); } return $this->collectionLoaderFactory; }
[ "public", "function", "collectionLoaderFactory", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "collectionLoaderFactory", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Collection Loader Factory is not defined for [%s]'", ",", "get_class", "(", "$", "this", ")", ")", ")", ";", "}", "return", "$", "this", "->", "collectionLoaderFactory", ";", "}" ]
Retrieve the collection loader factory. @throws RuntimeException If the collection loader factory is missing. @return FactoryInterface
[ "Retrieve", "the", "collection", "loader", "factory", "." ]
db3a7af547ccf96efe2d9be028b252bc8646f5d5
https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Loader/CollectionLoaderFactoryTrait.php#L40-L50
29,077
locomotivemtl/charcoal-core
src/Charcoal/Loader/CollectionLoaderFactoryTrait.php
CollectionLoaderFactoryTrait.createCollectionLoaderWith
public function createCollectionLoaderWith(array $args = null, callable $callback = null) { $factory = $this->collectionLoaderFactory(); return $factory->create($factory->defaultClass(), $args, $callback); }
php
public function createCollectionLoaderWith(array $args = null, callable $callback = null) { $factory = $this->collectionLoaderFactory(); return $factory->create($factory->defaultClass(), $args, $callback); }
[ "public", "function", "createCollectionLoaderWith", "(", "array", "$", "args", "=", "null", ",", "callable", "$", "callback", "=", "null", ")", "{", "$", "factory", "=", "$", "this", "->", "collectionLoaderFactory", "(", ")", ";", "return", "$", "factory", "->", "create", "(", "$", "factory", "->", "defaultClass", "(", ")", ",", "$", "args", ",", "$", "callback", ")", ";", "}" ]
Create a model collection loader with optional constructor arguments and a post-creation callback. @param array|null $args Optional. Constructor arguments. @param callable|null $callback Optional. Called at creation. @return CollectionLoader
[ "Create", "a", "model", "collection", "loader", "with", "optional", "constructor", "arguments", "and", "a", "post", "-", "creation", "callback", "." ]
db3a7af547ccf96efe2d9be028b252bc8646f5d5
https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Loader/CollectionLoaderFactoryTrait.php#L59-L64
29,078
timble/kodekit
code/manifest/manifest.php
Manifest.getAuthors
public function getAuthors() { $result = false; if($this->__manifest !== false) { $authors = $this->__manifest->get('authors', array()); $result = ObjectConfig::unbox($authors); } return $result; }
php
public function getAuthors() { $result = false; if($this->__manifest !== false) { $authors = $this->__manifest->get('authors', array()); $result = ObjectConfig::unbox($authors); } return $result; }
[ "public", "function", "getAuthors", "(", ")", "{", "$", "result", "=", "false", ";", "if", "(", "$", "this", "->", "__manifest", "!==", "false", ")", "{", "$", "authors", "=", "$", "this", "->", "__manifest", "->", "get", "(", "'authors'", ",", "array", "(", ")", ")", ";", "$", "result", "=", "ObjectConfig", "::", "unbox", "(", "$", "authors", ")", ";", "}", "return", "$", "result", ";", "}" ]
Get the homepage @return array|false Returns FALSE if the manifest doesn't exist
[ "Get", "the", "homepage" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/manifest/manifest.php#L112-L122
29,079
timble/kodekit
code/manifest/manifest.php
Manifest.__isset
final public function __isset($name) { $result = false; if($this->__manifest !== false) { $result = $this->__manifest->has($name); } return $result; }
php
final public function __isset($name) { $result = false; if($this->__manifest !== false) { $result = $this->__manifest->has($name); } return $result; }
[ "final", "public", "function", "__isset", "(", "$", "name", ")", "{", "$", "result", "=", "false", ";", "if", "(", "$", "this", "->", "__manifest", "!==", "false", ")", "{", "$", "result", "=", "$", "this", "->", "__manifest", "->", "has", "(", "$", "name", ")", ";", "}", "return", "$", "result", ";", "}" ]
Test existence of a manifest option @param string $name @return bool
[ "Test", "existence", "of", "a", "manifest", "option" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/manifest/manifest.php#L146-L154
29,080
locomotivemtl/charcoal-core
src/Charcoal/Model/Service/ModelLoader.php
ModelLoader.load
public function load($ident, $useCache = true, $reloadObj = false) { if (!$useCache) { return $this->loadFromSource($ident); } $cacheKey = $this->cacheKey($ident); $cacheItem = $this->cachePool->getItem($cacheKey); if (!$reloadObj) { if ($cacheItem->isHit()) { $data = $cacheItem->get(); $obj = $this->factory->create($this->objType); $obj->setData($data); return $obj; } } $obj = $this->loadFromSource($ident); $data = ($obj->id() ? $obj->data() : []); $cacheItem->set($data); $this->cachePool->save($cacheItem); return $obj; }
php
public function load($ident, $useCache = true, $reloadObj = false) { if (!$useCache) { return $this->loadFromSource($ident); } $cacheKey = $this->cacheKey($ident); $cacheItem = $this->cachePool->getItem($cacheKey); if (!$reloadObj) { if ($cacheItem->isHit()) { $data = $cacheItem->get(); $obj = $this->factory->create($this->objType); $obj->setData($data); return $obj; } } $obj = $this->loadFromSource($ident); $data = ($obj->id() ? $obj->data() : []); $cacheItem->set($data); $this->cachePool->save($cacheItem); return $obj; }
[ "public", "function", "load", "(", "$", "ident", ",", "$", "useCache", "=", "true", ",", "$", "reloadObj", "=", "false", ")", "{", "if", "(", "!", "$", "useCache", ")", "{", "return", "$", "this", "->", "loadFromSource", "(", "$", "ident", ")", ";", "}", "$", "cacheKey", "=", "$", "this", "->", "cacheKey", "(", "$", "ident", ")", ";", "$", "cacheItem", "=", "$", "this", "->", "cachePool", "->", "getItem", "(", "$", "cacheKey", ")", ";", "if", "(", "!", "$", "reloadObj", ")", "{", "if", "(", "$", "cacheItem", "->", "isHit", "(", ")", ")", "{", "$", "data", "=", "$", "cacheItem", "->", "get", "(", ")", ";", "$", "obj", "=", "$", "this", "->", "factory", "->", "create", "(", "$", "this", "->", "objType", ")", ";", "$", "obj", "->", "setData", "(", "$", "data", ")", ";", "return", "$", "obj", ";", "}", "}", "$", "obj", "=", "$", "this", "->", "loadFromSource", "(", "$", "ident", ")", ";", "$", "data", "=", "(", "$", "obj", "->", "id", "(", ")", "?", "$", "obj", "->", "data", "(", ")", ":", "[", "]", ")", ";", "$", "cacheItem", "->", "set", "(", "$", "data", ")", ";", "$", "this", "->", "cachePool", "->", "save", "(", "$", "cacheItem", ")", ";", "return", "$", "obj", ";", "}" ]
Retrieve an object, by its key, from its source or from the cache. When the cache is enabled, only the object's _data_ is stored. This prevents issues when unserializing a class that might have dependencies. @param string|integer $ident The object identifier to load. @param boolean $useCache If FALSE, ignore the cached object. Defaults to TRUE. @param boolean $reloadObj If TRUE, refresh the cached object. Defaults to FALSE. @return ModelInterface
[ "Retrieve", "an", "object", "by", "its", "key", "from", "its", "source", "or", "from", "the", "cache", "." ]
db3a7af547ccf96efe2d9be028b252bc8646f5d5
https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/ModelLoader.php#L212-L237
29,081
locomotivemtl/charcoal-core
src/Charcoal/Model/Service/ModelLoader.php
ModelLoader.loadFromSource
private function loadFromSource($ident) { $obj = $this->factory->create($this->objType); if ($this->objKey) { $obj->loadFrom($this->objKey, $ident); } else { $obj->load($ident); } return $obj; }
php
private function loadFromSource($ident) { $obj = $this->factory->create($this->objType); if ($this->objKey) { $obj->loadFrom($this->objKey, $ident); } else { $obj->load($ident); } return $obj; }
[ "private", "function", "loadFromSource", "(", "$", "ident", ")", "{", "$", "obj", "=", "$", "this", "->", "factory", "->", "create", "(", "$", "this", "->", "objType", ")", ";", "if", "(", "$", "this", "->", "objKey", ")", "{", "$", "obj", "->", "loadFrom", "(", "$", "this", "->", "objKey", ",", "$", "ident", ")", ";", "}", "else", "{", "$", "obj", "->", "load", "(", "$", "ident", ")", ";", "}", "return", "$", "obj", ";", "}" ]
Load an objet from its soure. @param string|integer $ident The object identifier to load. @return ModelInterface
[ "Load", "an", "objet", "from", "its", "soure", "." ]
db3a7af547ccf96efe2d9be028b252bc8646f5d5
https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/ModelLoader.php#L245-L255
29,082
locomotivemtl/charcoal-core
src/Charcoal/Model/Service/ModelLoader.php
ModelLoader.cacheKey
private function cacheKey($ident) { if ($this->objKey === null) { $model = $this->factory->get($this->objType); $this->setObjKey($model->key()); } $cacheKey = 'object/'.str_replace('/', '.', $this->objType.'.'.$this->objKey.'.'.$ident); return $cacheKey; }
php
private function cacheKey($ident) { if ($this->objKey === null) { $model = $this->factory->get($this->objType); $this->setObjKey($model->key()); } $cacheKey = 'object/'.str_replace('/', '.', $this->objType.'.'.$this->objKey.'.'.$ident); return $cacheKey; }
[ "private", "function", "cacheKey", "(", "$", "ident", ")", "{", "if", "(", "$", "this", "->", "objKey", "===", "null", ")", "{", "$", "model", "=", "$", "this", "->", "factory", "->", "get", "(", "$", "this", "->", "objType", ")", ";", "$", "this", "->", "setObjKey", "(", "$", "model", "->", "key", "(", ")", ")", ";", "}", "$", "cacheKey", "=", "'object/'", ".", "str_replace", "(", "'/'", ",", "'.'", ",", "$", "this", "->", "objType", ".", "'.'", ".", "$", "this", "->", "objKey", ".", "'.'", ".", "$", "ident", ")", ";", "return", "$", "cacheKey", ";", "}" ]
Generate a cache key. @param string|integer $ident The object identifier to load. @return string
[ "Generate", "a", "cache", "key", "." ]
db3a7af547ccf96efe2d9be028b252bc8646f5d5
https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/ModelLoader.php#L263-L273
29,083
locomotivemtl/charcoal-core
src/Charcoal/Model/Service/ModelLoader.php
ModelLoader.setObjKey
private function setObjKey($objKey) { if (empty($objKey) && !is_numeric($objKey)) { $this->objKey = null; return $this; } if (!is_string($objKey)) { throw new InvalidArgumentException( 'Can not set model loader object type: not a string' ); } $this->objKey = $objKey; return $this; }
php
private function setObjKey($objKey) { if (empty($objKey) && !is_numeric($objKey)) { $this->objKey = null; return $this; } if (!is_string($objKey)) { throw new InvalidArgumentException( 'Can not set model loader object type: not a string' ); } $this->objKey = $objKey; return $this; }
[ "private", "function", "setObjKey", "(", "$", "objKey", ")", "{", "if", "(", "empty", "(", "$", "objKey", ")", "&&", "!", "is_numeric", "(", "$", "objKey", ")", ")", "{", "$", "this", "->", "objKey", "=", "null", ";", "return", "$", "this", ";", "}", "if", "(", "!", "is_string", "(", "$", "objKey", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Can not set model loader object type: not a string'", ")", ";", "}", "$", "this", "->", "objKey", "=", "$", "objKey", ";", "return", "$", "this", ";", "}" ]
Set the object key. @param string $objKey The object key to use for laoding. @throws InvalidArgumentException If the object key is not a string. @return ModelLoader Chainable
[ "Set", "the", "object", "key", "." ]
db3a7af547ccf96efe2d9be028b252bc8646f5d5
https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/ModelLoader.php#L306-L321
29,084
nicebooks-com/isbn
src/Isbn.php
Isbn.to10
public function to10() : Isbn { if (! $this->is13) { return $this; } return new Isbn(Internal\Converter::convertIsbn13to10($this->isbn), false); }
php
public function to10() : Isbn { if (! $this->is13) { return $this; } return new Isbn(Internal\Converter::convertIsbn13to10($this->isbn), false); }
[ "public", "function", "to10", "(", ")", ":", "Isbn", "{", "if", "(", "!", "$", "this", "->", "is13", ")", "{", "return", "$", "this", ";", "}", "return", "new", "Isbn", "(", "Internal", "\\", "Converter", "::", "convertIsbn13to10", "(", "$", "this", "->", "isbn", ")", ",", "false", ")", ";", "}" ]
Returns a copy of this Isbn, converted to ISBN-10. @return Isbn The ISBN-10. @throws Exception\IsbnNotConvertibleException If this is an ISBN-13 not starting with 978.
[ "Returns", "a", "copy", "of", "this", "Isbn", "converted", "to", "ISBN", "-", "10", "." ]
f5ceb662e517b21e30c9dfa53c4d74823849232d
https://github.com/nicebooks-com/isbn/blob/f5ceb662e517b21e30c9dfa53c4d74823849232d/src/Isbn.php#L114-L121
29,085
nicebooks-com/isbn
src/Isbn.php
Isbn.to13
public function to13() : Isbn { if ($this->is13) { return $this; } return new Isbn(Internal\Converter::convertIsbn10to13($this->isbn), true); }
php
public function to13() : Isbn { if ($this->is13) { return $this; } return new Isbn(Internal\Converter::convertIsbn10to13($this->isbn), true); }
[ "public", "function", "to13", "(", ")", ":", "Isbn", "{", "if", "(", "$", "this", "->", "is13", ")", "{", "return", "$", "this", ";", "}", "return", "new", "Isbn", "(", "Internal", "\\", "Converter", "::", "convertIsbn10to13", "(", "$", "this", "->", "isbn", ")", ",", "true", ")", ";", "}" ]
Returns a copy of this Isbn, converted to ISBN-13. @return Isbn The ISBN-13.
[ "Returns", "a", "copy", "of", "this", "Isbn", "converted", "to", "ISBN", "-", "13", "." ]
f5ceb662e517b21e30c9dfa53c4d74823849232d
https://github.com/nicebooks-com/isbn/blob/f5ceb662e517b21e30c9dfa53c4d74823849232d/src/Isbn.php#L128-L135
29,086
nicebooks-com/isbn
src/Isbn.php
Isbn.getGroupIdentifier
public function getGroupIdentifier() : string { if ($this->rangeInfo === null) { throw IsbnException::unknownGroup($this->isbn); } return $this->rangeInfo->groupIdentifier; }
php
public function getGroupIdentifier() : string { if ($this->rangeInfo === null) { throw IsbnException::unknownGroup($this->isbn); } return $this->rangeInfo->groupIdentifier; }
[ "public", "function", "getGroupIdentifier", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "rangeInfo", "===", "null", ")", "{", "throw", "IsbnException", "::", "unknownGroup", "(", "$", "this", "->", "isbn", ")", ";", "}", "return", "$", "this", "->", "rangeInfo", "->", "groupIdentifier", ";", "}" ]
Returns the group identifier. The group or country identifier identifies a national or geographic grouping of publishers. For ISBN-13, the identifier includes the GS1 (EAN) prefix, for example "978-2". For the equivalent ISBN-10, the identifier would be "2". @return string @throws IsbnException If this ISBN is not in a recognized group.
[ "Returns", "the", "group", "identifier", "." ]
f5ceb662e517b21e30c9dfa53c4d74823849232d
https://github.com/nicebooks-com/isbn/blob/f5ceb662e517b21e30c9dfa53c4d74823849232d/src/Isbn.php#L190-L197
29,087
nicebooks-com/isbn
src/Isbn.php
Isbn.getGroupName
public function getGroupName() : string { if ($this->rangeInfo === null) { throw IsbnException::unknownGroup($this->isbn); } return $this->rangeInfo->groupName; }
php
public function getGroupName() : string { if ($this->rangeInfo === null) { throw IsbnException::unknownGroup($this->isbn); } return $this->rangeInfo->groupName; }
[ "public", "function", "getGroupName", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "rangeInfo", "===", "null", ")", "{", "throw", "IsbnException", "::", "unknownGroup", "(", "$", "this", "->", "isbn", ")", ";", "}", "return", "$", "this", "->", "rangeInfo", "->", "groupName", ";", "}" ]
Returns the group name. @return string @throws IsbnException If this ISBN is not in a recognized group.
[ "Returns", "the", "group", "name", "." ]
f5ceb662e517b21e30c9dfa53c4d74823849232d
https://github.com/nicebooks-com/isbn/blob/f5ceb662e517b21e30c9dfa53c4d74823849232d/src/Isbn.php#L206-L213
29,088
nicebooks-com/isbn
src/Isbn.php
Isbn.getPublisherIdentifier
public function getPublisherIdentifier() : string { if ($this->rangeInfo === null) { throw IsbnException::unknownGroup($this->isbn); } if ($this->rangeInfo->parts === null) { throw IsbnException::unknownRange($this->isbn); } return $this->rangeInfo->parts[$this->is13 ? 2 : 1]; }
php
public function getPublisherIdentifier() : string { if ($this->rangeInfo === null) { throw IsbnException::unknownGroup($this->isbn); } if ($this->rangeInfo->parts === null) { throw IsbnException::unknownRange($this->isbn); } return $this->rangeInfo->parts[$this->is13 ? 2 : 1]; }
[ "public", "function", "getPublisherIdentifier", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "rangeInfo", "===", "null", ")", "{", "throw", "IsbnException", "::", "unknownGroup", "(", "$", "this", "->", "isbn", ")", ";", "}", "if", "(", "$", "this", "->", "rangeInfo", "->", "parts", "===", "null", ")", "{", "throw", "IsbnException", "::", "unknownRange", "(", "$", "this", "->", "isbn", ")", ";", "}", "return", "$", "this", "->", "rangeInfo", "->", "parts", "[", "$", "this", "->", "is13", "?", "2", ":", "1", "]", ";", "}" ]
Returns the publisher identifier. The publisher identifier identifies a particular publisher within a group. @return string @throws IsbnException If this ISBN is not in a recognized group or range.
[ "Returns", "the", "publisher", "identifier", "." ]
f5ceb662e517b21e30c9dfa53c4d74823849232d
https://github.com/nicebooks-com/isbn/blob/f5ceb662e517b21e30c9dfa53c4d74823849232d/src/Isbn.php#L224-L235
29,089
timble/kodekit
code/filter/abstract.php
FilterAbstract.getInstance
public static function getInstance(ObjectConfigInterface $config, ObjectManagerInterface $manager) { //Create the singleton $class = $manager->getClass($config->object_identifier); $instance = new $class($config); if($instance instanceof FilterTraversable) { $instance = $instance->decorate('lib:filter.iterator'); } return $instance; }
php
public static function getInstance(ObjectConfigInterface $config, ObjectManagerInterface $manager) { //Create the singleton $class = $manager->getClass($config->object_identifier); $instance = new $class($config); if($instance instanceof FilterTraversable) { $instance = $instance->decorate('lib:filter.iterator'); } return $instance; }
[ "public", "static", "function", "getInstance", "(", "ObjectConfigInterface", "$", "config", ",", "ObjectManagerInterface", "$", "manager", ")", "{", "//Create the singleton", "$", "class", "=", "$", "manager", "->", "getClass", "(", "$", "config", "->", "object_identifier", ")", ";", "$", "instance", "=", "new", "$", "class", "(", "$", "config", ")", ";", "if", "(", "$", "instance", "instanceof", "FilterTraversable", ")", "{", "$", "instance", "=", "$", "instance", "->", "decorate", "(", "'lib:filter.iterator'", ")", ";", "}", "return", "$", "instance", ";", "}" ]
Create filter and decorate it with FilterIterator if the filter implements FilterTraversable @param ObjectConfigInterface $config Configuration options @param ObjectManagerInterface $manager A ObjectManagerInterface object @return FilterInterface @see FilterTraversable
[ "Create", "filter", "and", "decorate", "it", "with", "FilterIterator", "if", "the", "filter", "implements", "FilterTraversable" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/filter/abstract.php#L82-L93
29,090
timble/kodekit
code/database/query/abstract.php
DatabaseQueryAbstract.getDriver
public function getDriver() { if(!$this->__driver instanceof DatabaseDriverInterface) { $this->__driver = $this->getObject($this->__driver); if(!$this->__driver instanceof DatabaseDriverInterface) { throw new \UnexpectedValueException( 'Driver: '.get_class($this->__driver).' does not implement DatabaseDriverInterface' ); } } return $this->__driver; }
php
public function getDriver() { if(!$this->__driver instanceof DatabaseDriverInterface) { $this->__driver = $this->getObject($this->__driver); if(!$this->__driver instanceof DatabaseDriverInterface) { throw new \UnexpectedValueException( 'Driver: '.get_class($this->__driver).' does not implement DatabaseDriverInterface' ); } } return $this->__driver; }
[ "public", "function", "getDriver", "(", ")", "{", "if", "(", "!", "$", "this", "->", "__driver", "instanceof", "DatabaseDriverInterface", ")", "{", "$", "this", "->", "__driver", "=", "$", "this", "->", "getObject", "(", "$", "this", "->", "__driver", ")", ";", "if", "(", "!", "$", "this", "->", "__driver", "instanceof", "DatabaseDriverInterface", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "'Driver: '", ".", "get_class", "(", "$", "this", "->", "__driver", ")", ".", "' does not implement DatabaseDriverInterface'", ")", ";", "}", "}", "return", "$", "this", "->", "__driver", ";", "}" ]
Gets the database driver @throws \\UnexpectedValueException If the driver doesn't implement DatabaseDriverInterface @return DatabaseDriverInterface
[ "Gets", "the", "database", "driver" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/database/query/abstract.php#L106-L121
29,091
rosasurfer/ministruts
src/ministruts/Page.php
Page.get
public static function get($name, $altValue = null) { $page = self::me(); if (\key_exists($name, $page->properties)) return $page->properties[$name]; return $altValue; }
php
public static function get($name, $altValue = null) { $page = self::me(); if (\key_exists($name, $page->properties)) return $page->properties[$name]; return $altValue; }
[ "public", "static", "function", "get", "(", "$", "name", ",", "$", "altValue", "=", "null", ")", "{", "$", "page", "=", "self", "::", "me", "(", ")", ";", "if", "(", "\\", "key_exists", "(", "$", "name", ",", "$", "page", "->", "properties", ")", ")", "return", "$", "page", "->", "properties", "[", "$", "name", "]", ";", "return", "$", "altValue", ";", "}" ]
Lookup and return a property stored in the instance. @param string $name - property name @param mixed $altValue [optional] - value to return if no such property exists @return mixed - value
[ "Lookup", "and", "return", "a", "property", "stored", "in", "the", "instance", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/ministruts/Page.php#L51-L58
29,092
timble/kodekit
code/template/engine/abstract.php
TemplateEngineAbstract.renderPartial
public function renderPartial($url, array $data = array()) { //Qualify relative template url if(!parse_url($url, PHP_URL_SCHEME)) { if(!$template = end($this->__stack)) { throw new \RuntimeException('Cannot qualify partial template url'); } $basepath = dirname($template); //Resolve relative path if($path = trim('.', dirname($url))) { $count = 0; $total = count(explode('/', $path)); while ($count++ < $total) { $basepath = dirname($basepath); } $basename = $url; } else $basename = basename($url); $url = $basepath. '/' .$basename; } if(array_search($url, $this->__stack)) { throw new \RuntimeException(sprintf( 'Template recursion detected while importing "%s" in "%s"', $url )); } $type = pathinfo( $this->locateSource($url), PATHINFO_EXTENSION); $data = array_merge((array) $this->getData(), $data); //If the partial requires a different engine create it and delegate if(!in_array($type, $this->getFileTypes())) { $result = $this->getObject('template.engine.factory') ->createEngine($type, array('functions' => $this->getFunctions())) ->render($url, $data); } else $result = $this->render($url, $data); //Remove the template from the stack array_pop($this->__stack); return $result; }
php
public function renderPartial($url, array $data = array()) { //Qualify relative template url if(!parse_url($url, PHP_URL_SCHEME)) { if(!$template = end($this->__stack)) { throw new \RuntimeException('Cannot qualify partial template url'); } $basepath = dirname($template); //Resolve relative path if($path = trim('.', dirname($url))) { $count = 0; $total = count(explode('/', $path)); while ($count++ < $total) { $basepath = dirname($basepath); } $basename = $url; } else $basename = basename($url); $url = $basepath. '/' .$basename; } if(array_search($url, $this->__stack)) { throw new \RuntimeException(sprintf( 'Template recursion detected while importing "%s" in "%s"', $url )); } $type = pathinfo( $this->locateSource($url), PATHINFO_EXTENSION); $data = array_merge((array) $this->getData(), $data); //If the partial requires a different engine create it and delegate if(!in_array($type, $this->getFileTypes())) { $result = $this->getObject('template.engine.factory') ->createEngine($type, array('functions' => $this->getFunctions())) ->render($url, $data); } else $result = $this->render($url, $data); //Remove the template from the stack array_pop($this->__stack); return $result; }
[ "public", "function", "renderPartial", "(", "$", "url", ",", "array", "$", "data", "=", "array", "(", ")", ")", "{", "//Qualify relative template url", "if", "(", "!", "parse_url", "(", "$", "url", ",", "PHP_URL_SCHEME", ")", ")", "{", "if", "(", "!", "$", "template", "=", "end", "(", "$", "this", "->", "__stack", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Cannot qualify partial template url'", ")", ";", "}", "$", "basepath", "=", "dirname", "(", "$", "template", ")", ";", "//Resolve relative path", "if", "(", "$", "path", "=", "trim", "(", "'.'", ",", "dirname", "(", "$", "url", ")", ")", ")", "{", "$", "count", "=", "0", ";", "$", "total", "=", "count", "(", "explode", "(", "'/'", ",", "$", "path", ")", ")", ";", "while", "(", "$", "count", "++", "<", "$", "total", ")", "{", "$", "basepath", "=", "dirname", "(", "$", "basepath", ")", ";", "}", "$", "basename", "=", "$", "url", ";", "}", "else", "$", "basename", "=", "basename", "(", "$", "url", ")", ";", "$", "url", "=", "$", "basepath", ".", "'/'", ".", "$", "basename", ";", "}", "if", "(", "array_search", "(", "$", "url", ",", "$", "this", "->", "__stack", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Template recursion detected while importing \"%s\" in \"%s\"'", ",", "$", "url", ")", ")", ";", "}", "$", "type", "=", "pathinfo", "(", "$", "this", "->", "locateSource", "(", "$", "url", ")", ",", "PATHINFO_EXTENSION", ")", ";", "$", "data", "=", "array_merge", "(", "(", "array", ")", "$", "this", "->", "getData", "(", ")", ",", "$", "data", ")", ";", "//If the partial requires a different engine create it and delegate", "if", "(", "!", "in_array", "(", "$", "type", ",", "$", "this", "->", "getFileTypes", "(", ")", ")", ")", "{", "$", "result", "=", "$", "this", "->", "getObject", "(", "'template.engine.factory'", ")", "->", "createEngine", "(", "$", "type", ",", "array", "(", "'functions'", "=>", "$", "this", "->", "getFunctions", "(", ")", ")", ")", "->", "render", "(", "$", "url", ",", "$", "data", ")", ";", "}", "else", "$", "result", "=", "$", "this", "->", "render", "(", "$", "url", ",", "$", "data", ")", ";", "//Remove the template from the stack", "array_pop", "(", "$", "this", "->", "__stack", ")", ";", "return", "$", "result", ";", "}" ]
Render a partial template This method merges the data passed in with the data from the parent template. If the partial template has different file type the method will try to allocate it by jumping out of the local template scope. @param string $url The template url @param array $data The data to pass to the template @throws \RuntimeException If a partial template url could not be fully qualified @return string The rendered template content
[ "Render", "a", "partial", "template" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/template/engine/abstract.php#L139-L190
29,093
timble/kodekit
code/template/engine/abstract.php
TemplateEngineAbstract.renderDebug
public function renderDebug($source) { $template = end($this->__stack); if($this->getObject('filter.path')->validate($template)) { $path = $this->locateSource($template); } else { $path = ''; } //Render debug comments if($this->isDebug()) { $type = $this->getIdentifier()->getName(); $path = str_replace(rtrim(\Kodekit::getInstance()->getRootPath(), '/').'/', '', $path); $format = PHP_EOL.'<!--BEGIN '.$type.':render '.$path.' -->'.PHP_EOL; $format .= '%s'; $format .= PHP_EOL.'<!--END '.$type.':render '.$path.' -->'.PHP_EOL; $source = sprintf($format, trim($source)); } return $source; }
php
public function renderDebug($source) { $template = end($this->__stack); if($this->getObject('filter.path')->validate($template)) { $path = $this->locateSource($template); } else { $path = ''; } //Render debug comments if($this->isDebug()) { $type = $this->getIdentifier()->getName(); $path = str_replace(rtrim(\Kodekit::getInstance()->getRootPath(), '/').'/', '', $path); $format = PHP_EOL.'<!--BEGIN '.$type.':render '.$path.' -->'.PHP_EOL; $format .= '%s'; $format .= PHP_EOL.'<!--END '.$type.':render '.$path.' -->'.PHP_EOL; $source = sprintf($format, trim($source)); } return $source; }
[ "public", "function", "renderDebug", "(", "$", "source", ")", "{", "$", "template", "=", "end", "(", "$", "this", "->", "__stack", ")", ";", "if", "(", "$", "this", "->", "getObject", "(", "'filter.path'", ")", "->", "validate", "(", "$", "template", ")", ")", "{", "$", "path", "=", "$", "this", "->", "locateSource", "(", "$", "template", ")", ";", "}", "else", "{", "$", "path", "=", "''", ";", "}", "//Render debug comments", "if", "(", "$", "this", "->", "isDebug", "(", ")", ")", "{", "$", "type", "=", "$", "this", "->", "getIdentifier", "(", ")", "->", "getName", "(", ")", ";", "$", "path", "=", "str_replace", "(", "rtrim", "(", "\\", "Kodekit", "::", "getInstance", "(", ")", "->", "getRootPath", "(", ")", ",", "'/'", ")", ".", "'/'", ",", "''", ",", "$", "path", ")", ";", "$", "format", "=", "PHP_EOL", ".", "'<!--BEGIN '", ".", "$", "type", ".", "':render '", ".", "$", "path", ".", "' -->'", ".", "PHP_EOL", ";", "$", "format", ".=", "'%s'", ";", "$", "format", ".=", "PHP_EOL", ".", "'<!--END '", ".", "$", "type", ".", "':render '", ".", "$", "path", ".", "' -->'", ".", "PHP_EOL", ";", "$", "source", "=", "sprintf", "(", "$", "format", ",", "trim", "(", "$", "source", ")", ")", ";", "}", "return", "$", "source", ";", "}" ]
Render debug information @param string $source The template source @return string The rendered template source
[ "Render", "debug", "information" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/template/engine/abstract.php#L198-L222
29,094
timble/kodekit
code/template/engine/abstract.php
TemplateEngineAbstract.locateSource
public function locateSource($url) { if (!$file = $this->getObject('template.locator.factory')->locate($url)) { throw new \InvalidArgumentException(sprintf('The template "%s" cannot be located.', $url)); } return $file; }
php
public function locateSource($url) { if (!$file = $this->getObject('template.locator.factory')->locate($url)) { throw new \InvalidArgumentException(sprintf('The template "%s" cannot be located.', $url)); } return $file; }
[ "public", "function", "locateSource", "(", "$", "url", ")", "{", "if", "(", "!", "$", "file", "=", "$", "this", "->", "getObject", "(", "'template.locator.factory'", ")", "->", "locate", "(", "$", "url", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'The template \"%s\" cannot be located.'", ",", "$", "url", ")", ")", ";", "}", "return", "$", "file", ";", "}" ]
Locate a template file, given it's url. @param string $url The template url @throws \InvalidArgumentException If the template could not be located @throws \RuntimeException If a partial template url could not be fully qualified @return string The template real path
[ "Locate", "a", "template", "file", "given", "it", "s", "url", "." ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/template/engine/abstract.php#L232-L239
29,095
rosasurfer/ministruts
src/exception/RosasurferExceptionTrait.php
RosasurferExceptionTrait.addMessage
public function addMessage($message) { $this->message = trim(trim($this->message).NL.$message); return $this; }
php
public function addMessage($message) { $this->message = trim(trim($this->message).NL.$message); return $this; }
[ "public", "function", "addMessage", "(", "$", "message", ")", "{", "$", "this", "->", "message", "=", "trim", "(", "trim", "(", "$", "this", "->", "message", ")", ".", "NL", ".", "$", "message", ")", ";", "return", "$", "this", ";", "}" ]
Add a message to the exception's existing message. Used to add additional information to an existing message. @param string $message @return $this
[ "Add", "a", "message", "to", "the", "exception", "s", "existing", "message", ".", "Used", "to", "add", "additional", "information", "to", "an", "existing", "message", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/exception/RosasurferExceptionTrait.php#L32-L35
29,096
rosasurfer/ministruts
src/exception/RosasurferExceptionTrait.php
RosasurferExceptionTrait.getBetterMessage
public function getBetterMessage() { if (!$this->betterMessage) $this->betterMessage = DebugHelper::composeBetterMessage($this); return $this->betterMessage; }
php
public function getBetterMessage() { if (!$this->betterMessage) $this->betterMessage = DebugHelper::composeBetterMessage($this); return $this->betterMessage; }
[ "public", "function", "getBetterMessage", "(", ")", "{", "if", "(", "!", "$", "this", "->", "betterMessage", ")", "$", "this", "->", "betterMessage", "=", "DebugHelper", "::", "composeBetterMessage", "(", "$", "this", ")", ";", "return", "$", "this", "->", "betterMessage", ";", "}" ]
Return the exception's message in a more readable way. @return string - message
[ "Return", "the", "exception", "s", "message", "in", "a", "more", "readable", "way", "." ]
9d27f93dd53d2d626c75c92cfde9d004bab34d30
https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/exception/RosasurferExceptionTrait.php#L59-L63
29,097
timble/kodekit
code/dispatcher/authenticator/csrf.php
DispatcherAuthenticatorCsrf.getToken
public function getToken() { if(!isset($this->__token)) { $token = false; $request = $this->getObject('request'); if($request->headers->has('X-XSRF-Token')) { $token = $request->headers->get('X-XSRF-Token'); } if($request->headers->has('X-CSRF-Token')) { $token = $request->headers->get('X-CSRF-Token'); } if($request->data->has('csrf_token')) { $token = $request->data->get('csrf_token', 'sha1'); } $this->__token = $token; } return $this->__token; }
php
public function getToken() { if(!isset($this->__token)) { $token = false; $request = $this->getObject('request'); if($request->headers->has('X-XSRF-Token')) { $token = $request->headers->get('X-XSRF-Token'); } if($request->headers->has('X-CSRF-Token')) { $token = $request->headers->get('X-CSRF-Token'); } if($request->data->has('csrf_token')) { $token = $request->data->get('csrf_token', 'sha1'); } $this->__token = $token; } return $this->__token; }
[ "public", "function", "getToken", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "__token", ")", ")", "{", "$", "token", "=", "false", ";", "$", "request", "=", "$", "this", "->", "getObject", "(", "'request'", ")", ";", "if", "(", "$", "request", "->", "headers", "->", "has", "(", "'X-XSRF-Token'", ")", ")", "{", "$", "token", "=", "$", "request", "->", "headers", "->", "get", "(", "'X-XSRF-Token'", ")", ";", "}", "if", "(", "$", "request", "->", "headers", "->", "has", "(", "'X-CSRF-Token'", ")", ")", "{", "$", "token", "=", "$", "request", "->", "headers", "->", "get", "(", "'X-CSRF-Token'", ")", ";", "}", "if", "(", "$", "request", "->", "data", "->", "has", "(", "'csrf_token'", ")", ")", "{", "$", "token", "=", "$", "request", "->", "data", "->", "get", "(", "'csrf_token'", ",", "'sha1'", ")", ";", "}", "$", "this", "->", "__token", "=", "$", "token", ";", "}", "return", "$", "this", "->", "__token", ";", "}" ]
Return the CSRF request token @return string The CSRF token or NULL if no token could be found
[ "Return", "the", "CSRF", "request", "token" ]
4c376f8873f8d10c55e3d290616ff622605cd246
https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/dispatcher/authenticator/csrf.php#L51-L74
29,098
locomotivemtl/charcoal-core
src/Charcoal/Model/Service/ModelBuilder.php
ModelBuilder.build
public function build($objType, $metadataIdent = null, $sourceIdent = null) { $metadata = $this->createMetadata($objType, $metadataIdent); $source = $this->createSource($metadata, $sourceIdent); $args = array_merge($this->factory->arguments(), [ 'metadata' => $metadata, 'source' => $source ]); $model = $this->factory->create($objType, $args); $model->source()->setModel($model); return $model; }
php
public function build($objType, $metadataIdent = null, $sourceIdent = null) { $metadata = $this->createMetadata($objType, $metadataIdent); $source = $this->createSource($metadata, $sourceIdent); $args = array_merge($this->factory->arguments(), [ 'metadata' => $metadata, 'source' => $source ]); $model = $this->factory->create($objType, $args); $model->source()->setModel($model); return $model; }
[ "public", "function", "build", "(", "$", "objType", ",", "$", "metadataIdent", "=", "null", ",", "$", "sourceIdent", "=", "null", ")", "{", "$", "metadata", "=", "$", "this", "->", "createMetadata", "(", "$", "objType", ",", "$", "metadataIdent", ")", ";", "$", "source", "=", "$", "this", "->", "createSource", "(", "$", "metadata", ",", "$", "sourceIdent", ")", ";", "$", "args", "=", "array_merge", "(", "$", "this", "->", "factory", "->", "arguments", "(", ")", ",", "[", "'metadata'", "=>", "$", "metadata", ",", "'source'", "=>", "$", "source", "]", ")", ";", "$", "model", "=", "$", "this", "->", "factory", "->", "create", "(", "$", "objType", ",", "$", "args", ")", ";", "$", "model", "->", "source", "(", ")", "->", "setModel", "(", "$", "model", ")", ";", "return", "$", "model", ";", "}" ]
Build a model, pre-initializing its metadata and its source. By default, the name of the "obj type" (the model class name) is used to determine the metadata ident to load. To load a custom metadata for the object, use the `$metadataIdent` argument. By default, the object's _default_ source (from its metadata) is used as source. To load a custom source for the object, use the `$sourceIdent` argument. @param string $objType The object type of the Model. @param string|null $metadataIdent Optional. The metadata ident of the object. @param string|null $sourceIdent Optional. The custom source ident to load as source. @return \Charcoal\Model\ModelInterface
[ "Build", "a", "model", "pre", "-", "initializing", "its", "metadata", "and", "its", "source", "." ]
db3a7af547ccf96efe2d9be028b252bc8646f5d5
https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/ModelBuilder.php#L60-L71
29,099
locomotivemtl/charcoal-core
src/Charcoal/Source/StorableTrait.php
StorableTrait.setId
public function setId($id) { if (!is_scalar($id)) { throw new InvalidArgumentException(sprintf( 'ID for "%s" must be a scalar (integer, float, string, or boolean); received %s', get_class($this), (is_object($id) ? get_class($id) : gettype($id)) )); } $key = $this->key(); if ($key === 'id') { $this->id = $id; } else { $this[$key] = $id; } return $this; }
php
public function setId($id) { if (!is_scalar($id)) { throw new InvalidArgumentException(sprintf( 'ID for "%s" must be a scalar (integer, float, string, or boolean); received %s', get_class($this), (is_object($id) ? get_class($id) : gettype($id)) )); } $key = $this->key(); if ($key === 'id') { $this->id = $id; } else { $this[$key] = $id; } return $this; }
[ "public", "function", "setId", "(", "$", "id", ")", "{", "if", "(", "!", "is_scalar", "(", "$", "id", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'ID for \"%s\" must be a scalar (integer, float, string, or boolean); received %s'", ",", "get_class", "(", "$", "this", ")", ",", "(", "is_object", "(", "$", "id", ")", "?", "get_class", "(", "$", "id", ")", ":", "gettype", "(", "$", "id", ")", ")", ")", ")", ";", "}", "$", "key", "=", "$", "this", "->", "key", "(", ")", ";", "if", "(", "$", "key", "===", "'id'", ")", "{", "$", "this", "->", "id", "=", "$", "id", ";", "}", "else", "{", "$", "this", "[", "$", "key", "]", "=", "$", "id", ";", "}", "return", "$", "this", ";", "}" ]
Set the object's unique ID. The actual property set depends on `key()`. @param mixed $id The object's ID. @throws InvalidArgumentException If the argument is not scalar. @return self
[ "Set", "the", "object", "s", "unique", "ID", "." ]
db3a7af547ccf96efe2d9be028b252bc8646f5d5
https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/StorableTrait.php#L57-L75