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
partition
stringclasses
1 value
mako-framework/framework
src/mako/chrono/stopwatch/Stopwatch.php
Stopwatch.lap
public function lap(): float { $last = end($this->laps); $time = $last->stop(); $this->start(); return $time; }
php
public function lap(): float { $last = end($this->laps); $time = $last->stop(); $this->start(); return $time; }
[ "public", "function", "lap", "(", ")", ":", "float", "{", "$", "last", "=", "end", "(", "$", "this", "->", "laps", ")", ";", "$", "time", "=", "$", "last", "->", "stop", "(", ")", ";", "$", "this", "->", "start", "(", ")", ";", "return", "$",...
Starts a new lap and returns the time of the previous lap. @return float
[ "Starts", "a", "new", "lap", "and", "returns", "the", "time", "of", "the", "previous", "lap", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/chrono/stopwatch/Stopwatch.php#L75-L84
train
mako-framework/framework
src/mako/chrono/stopwatch/Stopwatch.php
Stopwatch.getElapsedTime
public function getElapsedTime(): float { $last = end($this->laps); return ($last->isRunning() ? microtime(true) : $last->getStopTime()) - $this->laps[0]->getStartTime(); }
php
public function getElapsedTime(): float { $last = end($this->laps); return ($last->isRunning() ? microtime(true) : $last->getStopTime()) - $this->laps[0]->getStartTime(); }
[ "public", "function", "getElapsedTime", "(", ")", ":", "float", "{", "$", "last", "=", "end", "(", "$", "this", "->", "laps", ")", ";", "return", "(", "$", "last", "->", "isRunning", "(", ")", "?", "microtime", "(", "true", ")", ":", "$", "last", ...
Get elapsed time. @return float
[ "Get", "elapsed", "time", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/chrono/stopwatch/Stopwatch.php#L91-L96
train
mako-framework/framework
src/mako/chrono/stopwatch/Stopwatch.php
Stopwatch.stop
public function stop(): float { $last = end($this->laps); $last->stop(); return $last->getStopTime() - $this->laps[0]->getStartTime(); }
php
public function stop(): float { $last = end($this->laps); $last->stop(); return $last->getStopTime() - $this->laps[0]->getStartTime(); }
[ "public", "function", "stop", "(", ")", ":", "float", "{", "$", "last", "=", "end", "(", "$", "this", "->", "laps", ")", ";", "$", "last", "->", "stop", "(", ")", ";", "return", "$", "last", "->", "getStopTime", "(", ")", "-", "$", "this", "->"...
Stops the timer and returns the elapsed time. @return float
[ "Stops", "the", "timer", "and", "returns", "the", "elapsed", "time", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/chrono/stopwatch/Stopwatch.php#L103-L110
train
mako-framework/framework
src/mako/database/midgard/relations/ManyToMany.php
ManyToMany.alongWith
public function alongWith(array $columns) { foreach($columns as $key => $value) { if(strpos($value, '.') === false) { $columns[$key] = $this->getJunctionTable() . '.' . $value; } } $this->alongWith = $columns; return $this; }
php
public function alongWith(array $columns) { foreach($columns as $key => $value) { if(strpos($value, '.') === false) { $columns[$key] = $this->getJunctionTable() . '.' . $value; } } $this->alongWith = $columns; return $this; }
[ "public", "function", "alongWith", "(", "array", "$", "columns", ")", "{", "foreach", "(", "$", "columns", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "strpos", "(", "$", "value", ",", "'.'", ")", "===", "false", ")", "{", "$", "co...
Columns to include with the result. @param array $columns Columns @return $this
[ "Columns", "to", "include", "with", "the", "result", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/relations/ManyToMany.php#L77-L90
train
mako-framework/framework
src/mako/database/midgard/relations/ManyToMany.php
ManyToMany.getJunctionTable
protected function getJunctionTable() { if($this->junctionTable === null) { $tables = [$this->parent->getTable(), $this->model->getTable()]; sort($tables); $this->junctionTable = implode('_', $tables); } return $this->junctionTable; }
php
protected function getJunctionTable() { if($this->junctionTable === null) { $tables = [$this->parent->getTable(), $this->model->getTable()]; sort($tables); $this->junctionTable = implode('_', $tables); } return $this->junctionTable; }
[ "protected", "function", "getJunctionTable", "(", ")", "{", "if", "(", "$", "this", "->", "junctionTable", "===", "null", ")", "{", "$", "tables", "=", "[", "$", "this", "->", "parent", "->", "getTable", "(", ")", ",", "$", "this", "->", "model", "->...
Returns the the junction table. @return string
[ "Returns", "the", "the", "junction", "table", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/relations/ManyToMany.php#L124-L136
train
mako-framework/framework
src/mako/database/midgard/relations/ManyToMany.php
ManyToMany.getJunctionKey
protected function getJunctionKey() { if($this->junctionKey === null) { $this->junctionKey = $this->model->getForeignKey(); } return $this->junctionKey; }
php
protected function getJunctionKey() { if($this->junctionKey === null) { $this->junctionKey = $this->model->getForeignKey(); } return $this->junctionKey; }
[ "protected", "function", "getJunctionKey", "(", ")", "{", "if", "(", "$", "this", "->", "junctionKey", "===", "null", ")", "{", "$", "this", "->", "junctionKey", "=", "$", "this", "->", "model", "->", "getForeignKey", "(", ")", ";", "}", "return", "$",...
Returns the the junction key. @return string
[ "Returns", "the", "the", "junction", "key", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/relations/ManyToMany.php#L143-L151
train
mako-framework/framework
src/mako/database/midgard/relations/ManyToMany.php
ManyToMany.junctionJoin
protected function junctionJoin(): void { $this->join($this->getJunctionTable(), $this->getJunctionTable() . '.' . $this->getJunctionKey(), '=', $this->model->getTable() . '.' . $this->model->getPrimaryKey()); }
php
protected function junctionJoin(): void { $this->join($this->getJunctionTable(), $this->getJunctionTable() . '.' . $this->getJunctionKey(), '=', $this->model->getTable() . '.' . $this->model->getPrimaryKey()); }
[ "protected", "function", "junctionJoin", "(", ")", ":", "void", "{", "$", "this", "->", "join", "(", "$", "this", "->", "getJunctionTable", "(", ")", ",", "$", "this", "->", "getJunctionTable", "(", ")", ".", "'.'", ".", "$", "this", "->", "getJunction...
Joins the junction table.
[ "Joins", "the", "junction", "table", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/relations/ManyToMany.php#L156-L159
train
mako-framework/framework
src/mako/database/midgard/relations/ManyToMany.php
ManyToMany.eagerLoad
public function eagerLoad(array &$results, string $relation, ?Closure $criteria, array $includes): void { $this->model->setIncludes($includes); $grouped = []; if($criteria !== null) { $criteria($this); } $foreignKey = $this->getForeignKey(); foreach($this->eagerLoadChunked($this->keys($results)) as $related) { $grouped[$related->getRawColumnValue($foreignKey)][] = $related; unset($related->$foreignKey); // Unset as its not a part of the record } foreach($results as $result) { $result->setRelated($relation, $this->createResultSet($grouped[$result->getPrimaryKeyValue()] ?? [])); } }
php
public function eagerLoad(array &$results, string $relation, ?Closure $criteria, array $includes): void { $this->model->setIncludes($includes); $grouped = []; if($criteria !== null) { $criteria($this); } $foreignKey = $this->getForeignKey(); foreach($this->eagerLoadChunked($this->keys($results)) as $related) { $grouped[$related->getRawColumnValue($foreignKey)][] = $related; unset($related->$foreignKey); // Unset as its not a part of the record } foreach($results as $result) { $result->setRelated($relation, $this->createResultSet($grouped[$result->getPrimaryKeyValue()] ?? [])); } }
[ "public", "function", "eagerLoad", "(", "array", "&", "$", "results", ",", "string", "$", "relation", ",", "?", "Closure", "$", "criteria", ",", "array", "$", "includes", ")", ":", "void", "{", "$", "this", "->", "model", "->", "setIncludes", "(", "$",...
Eager loads related records and matches them with their parent records. @param array &$results Parent records @param string $relation Relation name @param \Closure|null $criteria Relation criteria @param array $includes Includes passed from the parent record
[ "Eager", "loads", "related", "records", "and", "matches", "them", "with", "their", "parent", "records", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/relations/ManyToMany.php#L192-L216
train
mako-framework/framework
src/mako/database/midgard/relations/ManyToMany.php
ManyToMany.getJunctionKeys
protected function getJunctionKeys($id): array { $ids = []; foreach((is_array($id) ? $id : [$id]) as $value) { if($value instanceof $this->model) { $value = $value->getPrimaryKeyValue(); } $ids[] = $value; } return $ids; }
php
protected function getJunctionKeys($id): array { $ids = []; foreach((is_array($id) ? $id : [$id]) as $value) { if($value instanceof $this->model) { $value = $value->getPrimaryKeyValue(); } $ids[] = $value; } return $ids; }
[ "protected", "function", "getJunctionKeys", "(", "$", "id", ")", ":", "array", "{", "$", "ids", "=", "[", "]", ";", "foreach", "(", "(", "is_array", "(", "$", "id", ")", "?", "$", "id", ":", "[", "$", "id", "]", ")", "as", "$", "value", ")", ...
Returns an array of ids. @param mixed $id Id, model or an array of ids and/or models @return array
[ "Returns", "an", "array", "of", "ids", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/relations/ManyToMany.php#L244-L259
train
mako-framework/framework
src/mako/database/midgard/relations/ManyToMany.php
ManyToMany.link
public function link($id, array $attributes = []): bool { $success = true; $foreignKey = $this->getForeignKey(); $foreignKeyValue = $this->parent->getPrimaryKeyValue(); $junctionKey = $this->getJunctionKey(); foreach($this->getJunctionKeys($id) as $key => $id) { $columns = [$foreignKey => $foreignKeyValue, $junctionKey => $id]; $success = $success && $this->junction()->insert($columns + $this->getJunctionAttributes($key, $attributes)); } return $success; }
php
public function link($id, array $attributes = []): bool { $success = true; $foreignKey = $this->getForeignKey(); $foreignKeyValue = $this->parent->getPrimaryKeyValue(); $junctionKey = $this->getJunctionKey(); foreach($this->getJunctionKeys($id) as $key => $id) { $columns = [$foreignKey => $foreignKeyValue, $junctionKey => $id]; $success = $success && $this->junction()->insert($columns + $this->getJunctionAttributes($key, $attributes)); } return $success; }
[ "public", "function", "link", "(", "$", "id", ",", "array", "$", "attributes", "=", "[", "]", ")", ":", "bool", "{", "$", "success", "=", "true", ";", "$", "foreignKey", "=", "$", "this", "->", "getForeignKey", "(", ")", ";", "$", "foreignKeyValue", ...
Links related records. @param mixed $id Id, model or an array of ids and/or models @param array $attributes Junction attributes @return bool
[ "Links", "related", "records", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/relations/ManyToMany.php#L285-L303
train
mako-framework/framework
src/mako/database/midgard/relations/ManyToMany.php
ManyToMany.updateLink
public function updateLink($id, array $attributes): bool { $success = true; $foreignKey = $this->getForeignKey(); $foreignKeyValue = $this->parent->getPrimaryKeyValue(); $junctionKey = $this->getJunctionKey(); foreach($this->getJunctionKeys($id) as $key => $id) { $success = $success && (bool) $this->junction()->where($foreignKey, '=', $foreignKeyValue)->where($junctionKey, '=', $id)->update($this->getJunctionAttributes($key, $attributes)); } return $success; }
php
public function updateLink($id, array $attributes): bool { $success = true; $foreignKey = $this->getForeignKey(); $foreignKeyValue = $this->parent->getPrimaryKeyValue(); $junctionKey = $this->getJunctionKey(); foreach($this->getJunctionKeys($id) as $key => $id) { $success = $success && (bool) $this->junction()->where($foreignKey, '=', $foreignKeyValue)->where($junctionKey, '=', $id)->update($this->getJunctionAttributes($key, $attributes)); } return $success; }
[ "public", "function", "updateLink", "(", "$", "id", ",", "array", "$", "attributes", ")", ":", "bool", "{", "$", "success", "=", "true", ";", "$", "foreignKey", "=", "$", "this", "->", "getForeignKey", "(", ")", ";", "$", "foreignKeyValue", "=", "$", ...
Updates junction attributes. @param mixed $id Id, model or an array of ids and/or models @param array $attributes Junction attributes @return bool
[ "Updates", "junction", "attributes", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/relations/ManyToMany.php#L312-L328
train
mako-framework/framework
src/mako/database/midgard/relations/ManyToMany.php
ManyToMany.unlink
public function unlink($id = null): bool { $query = $this->junction()->where($this->getForeignKey(), '=', $this->parent->getPrimaryKeyValue()); if($id !== null) { $query->in($this->getJunctionKey(), $this->getJunctionKeys($id)); } return (bool) $query->delete(); }
php
public function unlink($id = null): bool { $query = $this->junction()->where($this->getForeignKey(), '=', $this->parent->getPrimaryKeyValue()); if($id !== null) { $query->in($this->getJunctionKey(), $this->getJunctionKeys($id)); } return (bool) $query->delete(); }
[ "public", "function", "unlink", "(", "$", "id", "=", "null", ")", ":", "bool", "{", "$", "query", "=", "$", "this", "->", "junction", "(", ")", "->", "where", "(", "$", "this", "->", "getForeignKey", "(", ")", ",", "'='", ",", "$", "this", "->", ...
Unlinks related records. @param mixed $id Id, model or an array of ids and/or models @return bool
[ "Unlinks", "related", "records", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/relations/ManyToMany.php#L336-L346
train
mako-framework/framework
src/mako/database/midgard/relations/ManyToMany.php
ManyToMany.synchronize
public function synchronize(array $ids): bool { $success = true; $keys = $this->getJunctionKeys($ids); // Fetch existing links $existing = $this->junction()->where($this->getForeignKey(), '=', $this->parent->getPrimaryKeyValue())->select([$this->getJunctionKey()])->all()->pluck($this->getJunctionKey()); // Link new relations if(!empty($diff = array_diff($keys, $existing))) { $success = $success && $this->link($diff); } // Unlink old relations if(!empty($diff = array_diff($existing, $keys))) { $success = $success && $this->unlink($diff); } // Return status return $success; }
php
public function synchronize(array $ids): bool { $success = true; $keys = $this->getJunctionKeys($ids); // Fetch existing links $existing = $this->junction()->where($this->getForeignKey(), '=', $this->parent->getPrimaryKeyValue())->select([$this->getJunctionKey()])->all()->pluck($this->getJunctionKey()); // Link new relations if(!empty($diff = array_diff($keys, $existing))) { $success = $success && $this->link($diff); } // Unlink old relations if(!empty($diff = array_diff($existing, $keys))) { $success = $success && $this->unlink($diff); } // Return status return $success; }
[ "public", "function", "synchronize", "(", "array", "$", "ids", ")", ":", "bool", "{", "$", "success", "=", "true", ";", "$", "keys", "=", "$", "this", "->", "getJunctionKeys", "(", "$", "ids", ")", ";", "// Fetch existing links", "$", "existing", "=", ...
Synchronize related records. @param array $ids An array of ids and/or models @return bool
[ "Synchronize", "related", "records", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/relations/ManyToMany.php#L354-L381
train
mako-framework/framework
src/mako/application/cli/commands/server/Server.php
Server.findAvailablePort
protected function findAvailablePort(int $port): ?int { $attempts = 0; while($attempts++ < static::MAX_PORTS_TO_TRY) { if(($socket = @fsockopen('localhost', $port, $errorNumber, $errorString, 0.1)) === false) { return $port; } fclose($socket); $port++; } return null; }
php
protected function findAvailablePort(int $port): ?int { $attempts = 0; while($attempts++ < static::MAX_PORTS_TO_TRY) { if(($socket = @fsockopen('localhost', $port, $errorNumber, $errorString, 0.1)) === false) { return $port; } fclose($socket); $port++; } return null; }
[ "protected", "function", "findAvailablePort", "(", "int", "$", "port", ")", ":", "?", "int", "{", "$", "attempts", "=", "0", ";", "while", "(", "$", "attempts", "++", "<", "static", "::", "MAX_PORTS_TO_TRY", ")", "{", "if", "(", "(", "$", "socket", "...
Tries to find an avaiable port closest to the desired port. @param int $port Desired port number @return int|null
[ "Tries", "to", "find", "an", "avaiable", "port", "closest", "to", "the", "desired", "port", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/commands/server/Server.php#L71-L88
train
mako-framework/framework
src/mako/http/Request.php
Request.stripLocaleSegment
protected function stripLocaleSegment(array $languages, string $path): string { foreach($languages as $key => $language) { if($path === '/' . $key || strpos($path, '/' . $key . '/') === 0) { $this->language = $language; $this->languagePrefix = $key; $path = '/' . ltrim(mb_substr($path, (mb_strlen($key) + 1)), '/'); break; } } return $path; }
php
protected function stripLocaleSegment(array $languages, string $path): string { foreach($languages as $key => $language) { if($path === '/' . $key || strpos($path, '/' . $key . '/') === 0) { $this->language = $language; $this->languagePrefix = $key; $path = '/' . ltrim(mb_substr($path, (mb_strlen($key) + 1)), '/'); break; } } return $path; }
[ "protected", "function", "stripLocaleSegment", "(", "array", "$", "languages", ",", "string", "$", "path", ")", ":", "string", "{", "foreach", "(", "$", "languages", "as", "$", "key", "=>", "$", "language", ")", "{", "if", "(", "$", "path", "===", "'/'...
Strips the locale segment from the path. @param array $languages Locale segments @param string $path Path @return string
[ "Strips", "the", "locale", "segment", "from", "the", "path", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Request.php#L235-L252
train
mako-framework/framework
src/mako/http/Request.php
Request.determinePath
protected function determinePath(array $languages): string { $path = '/'; $server = $this->server->all(); if(isset($server['PATH_INFO'])) { $path = $server['PATH_INFO']; } elseif(isset($server['REQUEST_URI'])) { if($path = parse_url($server['REQUEST_URI'], PHP_URL_PATH)) { // Remove base path from the request path $basePath = pathinfo($server['SCRIPT_NAME'], PATHINFO_DIRNAME); if($basePath !== '/' && stripos($path, $basePath) === 0) { $path = mb_substr($path, mb_strlen($basePath)); } // Remove "/index.php" from the path if(stripos($path, '/' . $this->scriptName) === 0) { $path = mb_substr($path, (strlen($this->scriptName) + 1)); } $path = rawurldecode($path); } } return $this->stripLocaleSegment($languages, $path); }
php
protected function determinePath(array $languages): string { $path = '/'; $server = $this->server->all(); if(isset($server['PATH_INFO'])) { $path = $server['PATH_INFO']; } elseif(isset($server['REQUEST_URI'])) { if($path = parse_url($server['REQUEST_URI'], PHP_URL_PATH)) { // Remove base path from the request path $basePath = pathinfo($server['SCRIPT_NAME'], PATHINFO_DIRNAME); if($basePath !== '/' && stripos($path, $basePath) === 0) { $path = mb_substr($path, mb_strlen($basePath)); } // Remove "/index.php" from the path if(stripos($path, '/' . $this->scriptName) === 0) { $path = mb_substr($path, (strlen($this->scriptName) + 1)); } $path = rawurldecode($path); } } return $this->stripLocaleSegment($languages, $path); }
[ "protected", "function", "determinePath", "(", "array", "$", "languages", ")", ":", "string", "{", "$", "path", "=", "'/'", ";", "$", "server", "=", "$", "this", "->", "server", "->", "all", "(", ")", ";", "if", "(", "isset", "(", "$", "server", "[...
Determines the request path. @param array $languages Locale segments @return string
[ "Determines", "the", "request", "path", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Request.php#L260-L295
train
mako-framework/framework
src/mako/http/Request.php
Request.determineMethod
protected function determineMethod(): string { $this->realMethod = $method = strtoupper($this->server->get('REQUEST_METHOD', 'GET')); if($method === 'POST') { return strtoupper($this->post->get('REQUEST_METHOD_OVERRIDE', $this->server->get('HTTP_X_HTTP_METHOD_OVERRIDE', 'POST'))); } return $method; }
php
protected function determineMethod(): string { $this->realMethod = $method = strtoupper($this->server->get('REQUEST_METHOD', 'GET')); if($method === 'POST') { return strtoupper($this->post->get('REQUEST_METHOD_OVERRIDE', $this->server->get('HTTP_X_HTTP_METHOD_OVERRIDE', 'POST'))); } return $method; }
[ "protected", "function", "determineMethod", "(", ")", ":", "string", "{", "$", "this", "->", "realMethod", "=", "$", "method", "=", "strtoupper", "(", "$", "this", "->", "server", "->", "get", "(", "'REQUEST_METHOD'", ",", "'GET'", ")", ")", ";", "if", ...
Determines the request method. @return string
[ "Determines", "the", "request", "method", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Request.php#L302-L312
train
mako-framework/framework
src/mako/http/Request.php
Request.getContentType
public function getContentType(): string { if($this->contentType === null) { $this->contentType = rtrim(strtok((string) $this->headers->get('content-type'), ';')); } return $this->contentType; }
php
public function getContentType(): string { if($this->contentType === null) { $this->contentType = rtrim(strtok((string) $this->headers->get('content-type'), ';')); } return $this->contentType; }
[ "public", "function", "getContentType", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "contentType", "===", "null", ")", "{", "$", "this", "->", "contentType", "=", "rtrim", "(", "strtok", "(", "(", "string", ")", "$", "this", "->", "he...
Returns the content type of the request body. An empty string will be returned if the header is missing. @return string
[ "Returns", "the", "content", "type", "of", "the", "request", "body", ".", "An", "empty", "string", "will", "be", "returned", "if", "the", "header", "is", "missing", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Request.php#L320-L328
train
mako-framework/framework
src/mako/http/Request.php
Request.setAttribute
public function setAttribute(string $name, $value): void { Arr::set($this->attributes, $name, $value); }
php
public function setAttribute(string $name, $value): void { Arr::set($this->attributes, $name, $value); }
[ "public", "function", "setAttribute", "(", "string", "$", "name", ",", "$", "value", ")", ":", "void", "{", "Arr", "::", "set", "(", "$", "this", "->", "attributes", ",", "$", "name", ",", "$", "value", ")", ";", "}" ]
Sets a request attribute. @param string $name Attribute name @param mixed $value Attribute value
[ "Sets", "a", "request", "attribute", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Request.php#L366-L369
train
mako-framework/framework
src/mako/http/Request.php
Request.getRawBody
public function getRawBody(): string { if($this->rawBody === null) { $this->rawBody = file_get_contents('php://input'); } return $this->rawBody; }
php
public function getRawBody(): string { if($this->rawBody === null) { $this->rawBody = file_get_contents('php://input'); } return $this->rawBody; }
[ "public", "function", "getRawBody", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "rawBody", "===", "null", ")", "{", "$", "this", "->", "rawBody", "=", "file_get_contents", "(", "'php://input'", ")", ";", "}", "return", "$", "this", "->"...
Returns the raw request body. @return string
[ "Returns", "the", "raw", "request", "body", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Request.php#L388-L396
train
mako-framework/framework
src/mako/http/Request.php
Request.getBody
public function getBody(): Parameters { if($this->parsedBody === null) { $this->parsedBody = new Body($this->getRawBody(), $this->getContentType()); } return $this->parsedBody; }
php
public function getBody(): Parameters { if($this->parsedBody === null) { $this->parsedBody = new Body($this->getRawBody(), $this->getContentType()); } return $this->parsedBody; }
[ "public", "function", "getBody", "(", ")", ":", "Parameters", "{", "if", "(", "$", "this", "->", "parsedBody", "===", "null", ")", "{", "$", "this", "->", "parsedBody", "=", "new", "Body", "(", "$", "this", "->", "getRawBody", "(", ")", ",", "$", "...
Returns the parsed request body. @return \mako\http\request\Body
[ "Returns", "the", "parsed", "request", "body", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Request.php#L473-L481
train
mako-framework/framework
src/mako/http/Request.php
Request.getData
public function getData(): Parameters { if($this->realMethod === 'GET') { return $this->getQuery(); } elseif($this->realMethod === 'POST' && $this->hasFormData()) { return $this->getPost(); } return $this->getBody(); }
php
public function getData(): Parameters { if($this->realMethod === 'GET') { return $this->getQuery(); } elseif($this->realMethod === 'POST' && $this->hasFormData()) { return $this->getPost(); } return $this->getBody(); }
[ "public", "function", "getData", "(", ")", ":", "Parameters", "{", "if", "(", "$", "this", "->", "realMethod", "===", "'GET'", ")", "{", "return", "$", "this", "->", "getQuery", "(", ")", ";", "}", "elseif", "(", "$", "this", "->", "realMethod", "===...
Returns the data of the current request method. @return \mako\http\request\Parameters
[ "Returns", "the", "data", "of", "the", "current", "request", "method", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Request.php#L505-L517
train
mako-framework/framework
src/mako/http/Request.php
Request.getIp
public function getIp(): string { if($this->ip === null) { $ip = $this->server->get('REMOTE_ADDR'); if(!empty($this->trustedProxies)) { $ips = $this->server->get('HTTP_X_FORWARDED_FOR'); if(!empty($ips)) { $ips = array_map('trim', explode(',', $ips)); foreach($ips as $key => $value) { foreach($this->trustedProxies as $trustedProxy) { if(IP::inRange($value, $trustedProxy)) { unset($ips[$key]); break; } } } $ip = end($ips); } } $this->ip = (filter_var($ip, FILTER_VALIDATE_IP) !== false) ? $ip : '127.0.0.1'; } return $this->ip; }
php
public function getIp(): string { if($this->ip === null) { $ip = $this->server->get('REMOTE_ADDR'); if(!empty($this->trustedProxies)) { $ips = $this->server->get('HTTP_X_FORWARDED_FOR'); if(!empty($ips)) { $ips = array_map('trim', explode(',', $ips)); foreach($ips as $key => $value) { foreach($this->trustedProxies as $trustedProxy) { if(IP::inRange($value, $trustedProxy)) { unset($ips[$key]); break; } } } $ip = end($ips); } } $this->ip = (filter_var($ip, FILTER_VALIDATE_IP) !== false) ? $ip : '127.0.0.1'; } return $this->ip; }
[ "public", "function", "getIp", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "ip", "===", "null", ")", "{", "$", "ip", "=", "$", "this", "->", "server", "->", "get", "(", "'REMOTE_ADDR'", ")", ";", "if", "(", "!", "empty", "(", "$...
Returns the ip of the client that made the request. @return string
[ "Returns", "the", "ip", "of", "the", "client", "that", "made", "the", "request", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Request.php#L534-L569
train
mako-framework/framework
src/mako/http/Request.php
Request.getBaseURL
public function getBaseURL(): string { if($this->baseURL === null) { // Get the protocol $protocol = $this->isSecure() ? 'https://' : 'http://'; // Get the server name and port if(($host = $this->server->get('HTTP_HOST')) === null) { $host = $this->server->get('SERVER_NAME'); $port = $this->server->get('SERVER_PORT'); if($port !== null && $port != 80) { $host = $host . ':' . $port; } } // Put them all together along with the base path $this->baseURL = $protocol . $host . $this->getBasePath(); } return $this->baseURL; }
php
public function getBaseURL(): string { if($this->baseURL === null) { // Get the protocol $protocol = $this->isSecure() ? 'https://' : 'http://'; // Get the server name and port if(($host = $this->server->get('HTTP_HOST')) === null) { $host = $this->server->get('SERVER_NAME'); $port = $this->server->get('SERVER_PORT'); if($port !== null && $port != 80) { $host = $host . ':' . $port; } } // Put them all together along with the base path $this->baseURL = $protocol . $host . $this->getBasePath(); } return $this->baseURL; }
[ "public", "function", "getBaseURL", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "baseURL", "===", "null", ")", "{", "// Get the protocol", "$", "protocol", "=", "$", "this", "->", "isSecure", "(", ")", "?", "'https://'", ":", "'http://'",...
Returns the base url of the request. @return string
[ "Returns", "the", "base", "url", "of", "the", "request", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Request.php#L633-L661
train
mako-framework/framework
src/mako/http/request/Headers.php
Headers.has
public function has(string $name): bool { return isset($this->headers[$this->normalizeName($name)]); }
php
public function has(string $name): bool { return isset($this->headers[$this->normalizeName($name)]); }
[ "public", "function", "has", "(", "string", "$", "name", ")", ":", "bool", "{", "return", "isset", "(", "$", "this", "->", "headers", "[", "$", "this", "->", "normalizeName", "(", "$", "name", ")", "]", ")", ";", "}" ]
Returns true if the header exists and false if not. @param string $name Header name @return bool
[ "Returns", "true", "if", "the", "header", "exists", "and", "false", "if", "not", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/request/Headers.php#L125-L128
train
mako-framework/framework
src/mako/http/request/Headers.php
Headers.parseAcceptHeader
protected function parseAcceptHeader(?string $headerValue): array { $groupedAccepts = []; if(empty($headerValue)) { return $groupedAccepts; } // Collect acceptable values foreach(explode(',', $headerValue) as $accept) { $quality = 1; if(strpos($accept, ';')) { // We have a quality so we need to split some more [$accept, $quality] = explode(';', $accept, 2); // Strip the "q=" part so that we're left with only the numeric value $quality = substr(trim($quality), 2); } $groupedAccepts[$quality][] = trim($accept); } // Sort in descending order of preference krsort($groupedAccepts); // Flatten array and return it return array_merge(...array_values($groupedAccepts)); }
php
protected function parseAcceptHeader(?string $headerValue): array { $groupedAccepts = []; if(empty($headerValue)) { return $groupedAccepts; } // Collect acceptable values foreach(explode(',', $headerValue) as $accept) { $quality = 1; if(strpos($accept, ';')) { // We have a quality so we need to split some more [$accept, $quality] = explode(';', $accept, 2); // Strip the "q=" part so that we're left with only the numeric value $quality = substr(trim($quality), 2); } $groupedAccepts[$quality][] = trim($accept); } // Sort in descending order of preference krsort($groupedAccepts); // Flatten array and return it return array_merge(...array_values($groupedAccepts)); }
[ "protected", "function", "parseAcceptHeader", "(", "?", "string", "$", "headerValue", ")", ":", "array", "{", "$", "groupedAccepts", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "headerValue", ")", ")", "{", "return", "$", "groupedAccepts", ";", "}"...
Parses a accpet header and returns the values in descending order of preference. @param string|null $headerValue Header value @return array
[ "Parses", "a", "accpet", "header", "and", "returns", "the", "values", "in", "descending", "order", "of", "preference", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/request/Headers.php#L168-L204
train
mako-framework/framework
src/mako/pixl/processors/traits/CalculateNewDimensionsTrait.php
CalculateNewDimensionsTrait.calculateNewDimensions
protected function calculateNewDimensions($width, $height, $oldWidth, $oldHeight, $aspectRatio) { if($height === null) { $newWidth = round($oldWidth * ($width / 100)); $newHeight = round($oldHeight * ($width / 100)); } else { if($aspectRatio === Image::RESIZE_AUTO) { // Calculate smallest size based on given height and width while maintaining aspect ratio $percentage = min(($width / $oldWidth), ($height / $oldHeight)); $newWidth = round($oldWidth * $percentage); $newHeight = round($oldHeight * $percentage); } elseif($aspectRatio === Image::RESIZE_WIDTH) { // Base new size on given width while maintaining aspect ratio $newWidth = $width; $newHeight = round($oldHeight * ($width / $oldWidth)); } elseif($aspectRatio === Image::RESIZE_HEIGHT) { // Base new size on given height while maintaining aspect ratio $newWidth = round($oldWidth * ($height / $oldHeight)); $newHeight = $height; } else { // Ignone aspect ratio $newWidth = $width; $newHeight = $height; } } return [$newWidth, $newHeight]; }
php
protected function calculateNewDimensions($width, $height, $oldWidth, $oldHeight, $aspectRatio) { if($height === null) { $newWidth = round($oldWidth * ($width / 100)); $newHeight = round($oldHeight * ($width / 100)); } else { if($aspectRatio === Image::RESIZE_AUTO) { // Calculate smallest size based on given height and width while maintaining aspect ratio $percentage = min(($width / $oldWidth), ($height / $oldHeight)); $newWidth = round($oldWidth * $percentage); $newHeight = round($oldHeight * $percentage); } elseif($aspectRatio === Image::RESIZE_WIDTH) { // Base new size on given width while maintaining aspect ratio $newWidth = $width; $newHeight = round($oldHeight * ($width / $oldWidth)); } elseif($aspectRatio === Image::RESIZE_HEIGHT) { // Base new size on given height while maintaining aspect ratio $newWidth = round($oldWidth * ($height / $oldHeight)); $newHeight = $height; } else { // Ignone aspect ratio $newWidth = $width; $newHeight = $height; } } return [$newWidth, $newHeight]; }
[ "protected", "function", "calculateNewDimensions", "(", "$", "width", ",", "$", "height", ",", "$", "oldWidth", ",", "$", "oldHeight", ",", "$", "aspectRatio", ")", "{", "if", "(", "$", "height", "===", "null", ")", "{", "$", "newWidth", "=", "round", ...
Calculates new image dimensions. @param int $width Desired image width @param int $height Desired image height @param int $oldWidth Old image width @param int $oldHeight Old image height @param int $aspectRatio Aspect ratio @return array
[ "Calculates", "new", "image", "dimensions", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/pixl/processors/traits/CalculateNewDimensionsTrait.php#L32-L74
train
mako-framework/framework
src/mako/http/routing/Dispatcher.php
Dispatcher.registerMiddleware
public function registerMiddleware(string $name, string $middleware, ?int $priority = null): Dispatcher { $this->middleware[$name] = $middleware; if($priority !== null) { $this->middlewarePriority[$name] = $priority; } return $this; }
php
public function registerMiddleware(string $name, string $middleware, ?int $priority = null): Dispatcher { $this->middleware[$name] = $middleware; if($priority !== null) { $this->middlewarePriority[$name] = $priority; } return $this; }
[ "public", "function", "registerMiddleware", "(", "string", "$", "name", ",", "string", "$", "middleware", ",", "?", "int", "$", "priority", "=", "null", ")", ":", "Dispatcher", "{", "$", "this", "->", "middleware", "[", "$", "name", "]", "=", "$", "mid...
Registers middleware. @param string $name Middleware name @param string $middleware Middleware class name @param int|null $priority Middleware priority @return \mako\http\routing\Dispatcher
[ "Registers", "middleware", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Dispatcher.php#L137-L147
train
mako-framework/framework
src/mako/http/routing/Dispatcher.php
Dispatcher.resolveMiddleware
protected function resolveMiddleware(string $middleware): array { [$name, $parameters] = $this->parseFunction($middleware); if(!isset($this->middleware[$name])) { throw new RuntimeException(vsprintf('No middleware named [ %s ] has been registered.', [$middleware])); } return ['name' => $name, 'middleware' => $this->middleware[$name], 'parameters' => $parameters]; }
php
protected function resolveMiddleware(string $middleware): array { [$name, $parameters] = $this->parseFunction($middleware); if(!isset($this->middleware[$name])) { throw new RuntimeException(vsprintf('No middleware named [ %s ] has been registered.', [$middleware])); } return ['name' => $name, 'middleware' => $this->middleware[$name], 'parameters' => $parameters]; }
[ "protected", "function", "resolveMiddleware", "(", "string", "$", "middleware", ")", ":", "array", "{", "[", "$", "name", ",", "$", "parameters", "]", "=", "$", "this", "->", "parseFunction", "(", "$", "middleware", ")", ";", "if", "(", "!", "isset", "...
Resolves the middleware. @param string $middleware middleware @throws \RuntimeException @return array
[ "Resolves", "the", "middleware", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Dispatcher.php#L169-L179
train
mako-framework/framework
src/mako/http/routing/Dispatcher.php
Dispatcher.orderMiddlewareByPriority
protected function orderMiddlewareByPriority(array $middleware): array { if(empty($this->middlewarePriority)) { return $middleware; } $priority = array_intersect_key($this->middlewarePriority, $middleware) + array_fill_keys(array_keys(array_diff_key($middleware, $this->middlewarePriority)), static::MIDDLEWARE_DEFAULT_PRIORITY); // Sort the priority map using stable sorting $position = 0; foreach($priority as $key => $value) { $priority[$key] = [$position++, $value]; } uasort($priority, function($a, $b) { return $a[1] === $b[1] ? ($a[0] > $b[0] ? 1 : -1) : ($a[1] > $b[1] ? 1 : -1); }); foreach($priority as $key => $value) { $priority[$key] = $value[1]; } // Return sorted middleware list return array_merge($priority, $middleware); }
php
protected function orderMiddlewareByPriority(array $middleware): array { if(empty($this->middlewarePriority)) { return $middleware; } $priority = array_intersect_key($this->middlewarePriority, $middleware) + array_fill_keys(array_keys(array_diff_key($middleware, $this->middlewarePriority)), static::MIDDLEWARE_DEFAULT_PRIORITY); // Sort the priority map using stable sorting $position = 0; foreach($priority as $key => $value) { $priority[$key] = [$position++, $value]; } uasort($priority, function($a, $b) { return $a[1] === $b[1] ? ($a[0] > $b[0] ? 1 : -1) : ($a[1] > $b[1] ? 1 : -1); }); foreach($priority as $key => $value) { $priority[$key] = $value[1]; } // Return sorted middleware list return array_merge($priority, $middleware); }
[ "protected", "function", "orderMiddlewareByPriority", "(", "array", "$", "middleware", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "this", "->", "middlewarePriority", ")", ")", "{", "return", "$", "middleware", ";", "}", "$", "priority", "=", "ar...
Orders resolved middleware by priority. @param array $middleware Array of middleware @return array
[ "Orders", "resolved", "middleware", "by", "priority", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Dispatcher.php#L187-L218
train
mako-framework/framework
src/mako/http/routing/Dispatcher.php
Dispatcher.addMiddlewareToStack
protected function addMiddlewareToStack(Onion $onion, array $middleware): void { if(empty($middleware) === false) { // Resolve middleware $resolved = []; foreach($middleware as $layer) { $layer = $this->resolveMiddleware($layer); $resolved[$layer['name']][] = $layer; } // Add ordered middleware to stack foreach($this->orderMiddlewareByPriority($resolved) as $name) { foreach($name as $layer) { $onion->addLayer($layer['middleware'], $layer['parameters']); } } } }
php
protected function addMiddlewareToStack(Onion $onion, array $middleware): void { if(empty($middleware) === false) { // Resolve middleware $resolved = []; foreach($middleware as $layer) { $layer = $this->resolveMiddleware($layer); $resolved[$layer['name']][] = $layer; } // Add ordered middleware to stack foreach($this->orderMiddlewareByPriority($resolved) as $name) { foreach($name as $layer) { $onion->addLayer($layer['middleware'], $layer['parameters']); } } } }
[ "protected", "function", "addMiddlewareToStack", "(", "Onion", "$", "onion", ",", "array", "$", "middleware", ")", ":", "void", "{", "if", "(", "empty", "(", "$", "middleware", ")", "===", "false", ")", "{", "// Resolve middleware", "$", "resolved", "=", "...
Adds route middleware to the stack. @param \mako\onion\Onion $onion Middleware stack @param array $middleware Array of middleware
[ "Adds", "route", "middleware", "to", "the", "stack", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Dispatcher.php#L226-L251
train
mako-framework/framework
src/mako/http/routing/Dispatcher.php
Dispatcher.executeClosure
protected function executeClosure(Closure $closure, array $parameters): Response { return $this->response->setBody($this->container->call($closure, $parameters)); }
php
protected function executeClosure(Closure $closure, array $parameters): Response { return $this->response->setBody($this->container->call($closure, $parameters)); }
[ "protected", "function", "executeClosure", "(", "Closure", "$", "closure", ",", "array", "$", "parameters", ")", ":", "Response", "{", "return", "$", "this", "->", "response", "->", "setBody", "(", "$", "this", "->", "container", "->", "call", "(", "$", ...
Executes a closure action. @param \Closure $closure Closure @param array $parameters Parameters @return \mako\http\Response
[ "Executes", "a", "closure", "action", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Dispatcher.php#L260-L263
train
mako-framework/framework
src/mako/http/routing/Dispatcher.php
Dispatcher.executeController
protected function executeController(string $controller, array $parameters): Response { if(strpos($controller, '::') === false) { $method = '__invoke'; } else { [$controller, $method] = explode('::', $controller, 2); } $controller = $this->container->get($controller); // Execute the before action method if we have one if(method_exists($controller, 'beforeAction')) { $returnValue = $this->container->call([$controller, 'beforeAction']); } if(empty($returnValue)) { // The before action method didn't return any data so we can set the // response body to whatever the route action returns $this->response->setBody($this->container->call([$controller, $method], $parameters)); // Execute the after action method if we have one if(method_exists($controller, 'afterAction')) { $this->container->call([$controller, 'afterAction']); } } else { // The before action method returned data so we'll set the response body to whatever it returned $this->response->setBody($returnValue); } return $this->response; }
php
protected function executeController(string $controller, array $parameters): Response { if(strpos($controller, '::') === false) { $method = '__invoke'; } else { [$controller, $method] = explode('::', $controller, 2); } $controller = $this->container->get($controller); // Execute the before action method if we have one if(method_exists($controller, 'beforeAction')) { $returnValue = $this->container->call([$controller, 'beforeAction']); } if(empty($returnValue)) { // The before action method didn't return any data so we can set the // response body to whatever the route action returns $this->response->setBody($this->container->call([$controller, $method], $parameters)); // Execute the after action method if we have one if(method_exists($controller, 'afterAction')) { $this->container->call([$controller, 'afterAction']); } } else { // The before action method returned data so we'll set the response body to whatever it returned $this->response->setBody($returnValue); } return $this->response; }
[ "protected", "function", "executeController", "(", "string", "$", "controller", ",", "array", "$", "parameters", ")", ":", "Response", "{", "if", "(", "strpos", "(", "$", "controller", ",", "'::'", ")", "===", "false", ")", "{", "$", "method", "=", "'__i...
Executes a controller action. @param string $controller Controller @param array $parameters Parameters @return \mako\http\Response
[ "Executes", "a", "controller", "action", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Dispatcher.php#L272-L314
train
mako-framework/framework
src/mako/http/routing/Dispatcher.php
Dispatcher.executeAction
protected function executeAction(Route $route): Response { $action = $route->getAction(); $parameters = $route->getParameters(); if($action instanceof Closure) { return $this->executeClosure($action, $parameters); } return $this->executeController($action, $parameters); }
php
protected function executeAction(Route $route): Response { $action = $route->getAction(); $parameters = $route->getParameters(); if($action instanceof Closure) { return $this->executeClosure($action, $parameters); } return $this->executeController($action, $parameters); }
[ "protected", "function", "executeAction", "(", "Route", "$", "route", ")", ":", "Response", "{", "$", "action", "=", "$", "route", "->", "getAction", "(", ")", ";", "$", "parameters", "=", "$", "route", "->", "getParameters", "(", ")", ";", "if", "(", ...
Executes the route action. @param \mako\http\routing\Route $route Route @return \mako\http\Response
[ "Executes", "the", "route", "action", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Dispatcher.php#L322-L334
train
mako-framework/framework
src/mako/http/routing/Dispatcher.php
Dispatcher.dispatch
public function dispatch(Route $route): Response { $onion = new Onion($this->container, null, MiddlewareInterface::class); $this->addMiddlewareToStack($onion, array_merge($this->globalMiddleware, $route->getMiddleware())); return $onion->peel(function() use ($route) { return $this->executeAction($route); }, [$this->request, $this->response]); }
php
public function dispatch(Route $route): Response { $onion = new Onion($this->container, null, MiddlewareInterface::class); $this->addMiddlewareToStack($onion, array_merge($this->globalMiddleware, $route->getMiddleware())); return $onion->peel(function() use ($route) { return $this->executeAction($route); }, [$this->request, $this->response]); }
[ "public", "function", "dispatch", "(", "Route", "$", "route", ")", ":", "Response", "{", "$", "onion", "=", "new", "Onion", "(", "$", "this", "->", "container", ",", "null", ",", "MiddlewareInterface", "::", "class", ")", ";", "$", "this", "->", "addMi...
Dispatches the route and returns the response. @param \mako\http\routing\Route $route Route @return \mako\http\Response
[ "Dispatches", "the", "route", "and", "returns", "the", "response", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Dispatcher.php#L342-L352
train
mako-framework/framework
src/mako/session/Session.php
Session.commit
public function commit(): void { // Replace old flash data with new $this->sessionData['mako.flashdata'] = $this->flashData; // Write session data if(!$this->destroyed) { $this->store->write($this->sessionId, $this->sessionData, $this->options['data_ttl']); } }
php
public function commit(): void { // Replace old flash data with new $this->sessionData['mako.flashdata'] = $this->flashData; // Write session data if(!$this->destroyed) { $this->store->write($this->sessionId, $this->sessionData, $this->options['data_ttl']); } }
[ "public", "function", "commit", "(", ")", ":", "void", "{", "// Replace old flash data with new", "$", "this", "->", "sessionData", "[", "'mako.flashdata'", "]", "=", "$", "this", "->", "flashData", ";", "// Write session data", "if", "(", "!", "$", "this", "-...
Writes data to session store.
[ "Writes", "data", "to", "session", "store", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/session/Session.php#L194-L206
train
mako-framework/framework
src/mako/session/Session.php
Session.setCookie
protected function setCookie(): void { if($this->options['cookie_options']['secure'] && !$this->request->isSecure()) { throw new RuntimeException('Attempted to set a secure cookie over a non-secure connection.'); } $this->response->getCookies()->addSigned($this->options['name'], $this->sessionId, $this->options['cookie_ttl'], $this->options['cookie_options']); }
php
protected function setCookie(): void { if($this->options['cookie_options']['secure'] && !$this->request->isSecure()) { throw new RuntimeException('Attempted to set a secure cookie over a non-secure connection.'); } $this->response->getCookies()->addSigned($this->options['name'], $this->sessionId, $this->options['cookie_ttl'], $this->options['cookie_options']); }
[ "protected", "function", "setCookie", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "options", "[", "'cookie_options'", "]", "[", "'secure'", "]", "&&", "!", "$", "this", "->", "request", "->", "isSecure", "(", ")", ")", "{", "throw", "ne...
Adds a session cookie to the response. @throws \RuntimeException
[ "Adds", "a", "session", "cookie", "to", "the", "response", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/session/Session.php#L234-L242
train
mako-framework/framework
src/mako/session/Session.php
Session.loadData
protected function loadData(): void { $data = $this->store->read($this->sessionId); $this->sessionData = $data === false ? [] : $data; }
php
protected function loadData(): void { $data = $this->store->read($this->sessionId); $this->sessionData = $data === false ? [] : $data; }
[ "protected", "function", "loadData", "(", ")", ":", "void", "{", "$", "data", "=", "$", "this", "->", "store", "->", "read", "(", "$", "this", "->", "sessionId", ")", ";", "$", "this", "->", "sessionData", "=", "$", "data", "===", "false", "?", "["...
Loads the session data.
[ "Loads", "the", "session", "data", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/session/Session.php#L247-L252
train
mako-framework/framework
src/mako/session/Session.php
Session.regenerateId
public function regenerateId(bool $keepOld = false): string { // Delete old data if we don't want to keep it if(!$keepOld) { $this->store->delete($this->sessionId); } // Generate a new id and set a new cookie $this->sessionId = $this->generateId(); $this->setCookie(); // Return the new session id return $this->sessionId; }
php
public function regenerateId(bool $keepOld = false): string { // Delete old data if we don't want to keep it if(!$keepOld) { $this->store->delete($this->sessionId); } // Generate a new id and set a new cookie $this->sessionId = $this->generateId(); $this->setCookie(); // Return the new session id return $this->sessionId; }
[ "public", "function", "regenerateId", "(", "bool", "$", "keepOld", "=", "false", ")", ":", "string", "{", "// Delete old data if we don't want to keep it", "if", "(", "!", "$", "keepOld", ")", "{", "$", "this", "->", "store", "->", "delete", "(", "$", "this"...
Regenerate the session id and returns it. @param bool $keepOld Keep the session data associated with the old session id? @return string
[ "Regenerate", "the", "session", "id", "and", "returns", "it", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/session/Session.php#L270-L288
train
mako-framework/framework
src/mako/session/Session.php
Session.getAndPut
public function getAndPut(string $key, $value, $default = null) { $storedValue = $this->get($key, $default); $this->put($key, $value); return $storedValue; }
php
public function getAndPut(string $key, $value, $default = null) { $storedValue = $this->get($key, $default); $this->put($key, $value); return $storedValue; }
[ "public", "function", "getAndPut", "(", "string", "$", "key", ",", "$", "value", ",", "$", "default", "=", "null", ")", "{", "$", "storedValue", "=", "$", "this", "->", "get", "(", "$", "key", ",", "$", "default", ")", ";", "$", "this", "->", "pu...
Gets a value from the session and replaces it. @param string $key Session key @param mixed $value Session data @param mixed $default Default value @return mixed
[ "Gets", "a", "value", "from", "the", "session", "and", "replaces", "it", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/session/Session.php#L342-L349
train
mako-framework/framework
src/mako/session/Session.php
Session.getAndRemove
public function getAndRemove(string $key, $default = null) { $storedValue = $this->get($key, $default); $this->remove($key); return $storedValue; }
php
public function getAndRemove(string $key, $default = null) { $storedValue = $this->get($key, $default); $this->remove($key); return $storedValue; }
[ "public", "function", "getAndRemove", "(", "string", "$", "key", ",", "$", "default", "=", "null", ")", "{", "$", "storedValue", "=", "$", "this", "->", "get", "(", "$", "key", ",", "$", "default", ")", ";", "$", "this", "->", "remove", "(", "$", ...
Gets a value from the session and removes it. @param string $key Session key @param mixed $default Default value @return mixed
[ "Gets", "a", "value", "from", "the", "session", "and", "removes", "it", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/session/Session.php#L358-L365
train
mako-framework/framework
src/mako/session/Session.php
Session.reflash
public function reflash(array $keys = []): void { $flashData = $this->sessionData['mako.flashdata'] ?? []; $flashData = empty($keys) ? $flashData : array_intersect_key($flashData, array_flip($keys)); $this->flashData = array_merge($this->flashData, $flashData); }
php
public function reflash(array $keys = []): void { $flashData = $this->sessionData['mako.flashdata'] ?? []; $flashData = empty($keys) ? $flashData : array_intersect_key($flashData, array_flip($keys)); $this->flashData = array_merge($this->flashData, $flashData); }
[ "public", "function", "reflash", "(", "array", "$", "keys", "=", "[", "]", ")", ":", "void", "{", "$", "flashData", "=", "$", "this", "->", "sessionData", "[", "'mako.flashdata'", "]", "??", "[", "]", ";", "$", "flashData", "=", "empty", "(", "$", ...
Extends the lifetime of the flash data by one request. @param array $keys Keys to preserve
[ "Extends", "the", "lifetime", "of", "the", "flash", "data", "by", "one", "request", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/session/Session.php#L427-L434
train
mako-framework/framework
src/mako/session/Session.php
Session.generateOneTimeToken
public function generateOneTimeToken(): string { if(!empty($this->sessionData['mako.tokens'])) { $this->sessionData['mako.tokens'] = array_slice($this->sessionData['mako.tokens'], 0, (static::MAX_TOKENS - 1)); } else { $this->sessionData['mako.tokens'] = []; } $token = $this->generateId(); array_unshift($this->sessionData['mako.tokens'], $token); return $token; }
php
public function generateOneTimeToken(): string { if(!empty($this->sessionData['mako.tokens'])) { $this->sessionData['mako.tokens'] = array_slice($this->sessionData['mako.tokens'], 0, (static::MAX_TOKENS - 1)); } else { $this->sessionData['mako.tokens'] = []; } $token = $this->generateId(); array_unshift($this->sessionData['mako.tokens'], $token); return $token; }
[ "public", "function", "generateOneTimeToken", "(", ")", ":", "string", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "sessionData", "[", "'mako.tokens'", "]", ")", ")", "{", "$", "this", "->", "sessionData", "[", "'mako.tokens'", "]", "=", "array...
Returns random security token. @return string
[ "Returns", "random", "security", "token", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/session/Session.php#L472-L488
train
mako-framework/framework
src/mako/session/Session.php
Session.validateOneTimeToken
public function validateOneTimeToken(string $token): bool { if(!empty($this->sessionData['mako.tokens'])) { foreach($this->sessionData['mako.tokens'] as $key => $value) { if(hash_equals($value, $token)) { unset($this->sessionData['mako.tokens'][$key]); return true; } } } return false; }
php
public function validateOneTimeToken(string $token): bool { if(!empty($this->sessionData['mako.tokens'])) { foreach($this->sessionData['mako.tokens'] as $key => $value) { if(hash_equals($value, $token)) { unset($this->sessionData['mako.tokens'][$key]); return true; } } } return false; }
[ "public", "function", "validateOneTimeToken", "(", "string", "$", "token", ")", ":", "bool", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "sessionData", "[", "'mako.tokens'", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "sessionData", ...
Validates security token. @param string $token Security token @return bool
[ "Validates", "security", "token", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/session/Session.php#L496-L512
train
mako-framework/framework
src/mako/http/routing/traits/ControllerHelperTrait.php
ControllerHelperTrait.redirectResponse
protected function redirectResponse(string $location, array $routeParams = [], array $queryParams = [], string $separator = '&', $language = true): Redirect { if($this->routes->hasNamedRoute($location)) { $location = $this->urlBuilder->toRoute($location, $routeParams, $queryParams, $separator, $language); } return new Redirect($location); }
php
protected function redirectResponse(string $location, array $routeParams = [], array $queryParams = [], string $separator = '&', $language = true): Redirect { if($this->routes->hasNamedRoute($location)) { $location = $this->urlBuilder->toRoute($location, $routeParams, $queryParams, $separator, $language); } return new Redirect($location); }
[ "protected", "function", "redirectResponse", "(", "string", "$", "location", ",", "array", "$", "routeParams", "=", "[", "]", ",", "array", "$", "queryParams", "=", "[", "]", ",", "string", "$", "separator", "=", "'&'", ",", "$", "language", "=", "true",...
Returns a redirect response container. @param string $location Location @param array $routeParams Route parameters @param array $queryParams Associative array used to build URL-encoded query string @param string $separator Argument separator @param mixed $language Request language @return \mako\http\response\senders\Redirect
[ "Returns", "a", "redirect", "response", "container", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/traits/ControllerHelperTrait.php#L47-L55
train
mako-framework/framework
src/mako/http/routing/traits/ControllerHelperTrait.php
ControllerHelperTrait.streamResponse
protected function streamResponse(Closure $stream, ?string $contentType = null, ?string $charset = null): Stream { return new Stream($stream, $contentType, $charset); }
php
protected function streamResponse(Closure $stream, ?string $contentType = null, ?string $charset = null): Stream { return new Stream($stream, $contentType, $charset); }
[ "protected", "function", "streamResponse", "(", "Closure", "$", "stream", ",", "?", "string", "$", "contentType", "=", "null", ",", "?", "string", "$", "charset", "=", "null", ")", ":", "Stream", "{", "return", "new", "Stream", "(", "$", "stream", ",", ...
Returns a stream response container. @param \Closure $stream Stream @param string|null $contentType Content type @param string|null $charset Character set @return \mako\http\response\senders\Stream
[ "Returns", "a", "stream", "response", "container", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/traits/ControllerHelperTrait.php#L65-L68
train
mako-framework/framework
src/mako/http/routing/traits/ControllerHelperTrait.php
ControllerHelperTrait.jsonResponse
protected function jsonResponse($data, int $options = 0, ?int $status = null, ?string $charset = null): JSON { return new JSON($data, $options, $status, $charset); }
php
protected function jsonResponse($data, int $options = 0, ?int $status = null, ?string $charset = null): JSON { return new JSON($data, $options, $status, $charset); }
[ "protected", "function", "jsonResponse", "(", "$", "data", ",", "int", "$", "options", "=", "0", ",", "?", "int", "$", "status", "=", "null", ",", "?", "string", "$", "charset", "=", "null", ")", ":", "JSON", "{", "return", "new", "JSON", "(", "$",...
Returns a JSON response builder. @param mixed $data Data @param int $options JSON encode coptions @param int|null $status Status code @param string|null $charset Character set @return \mako\http\response\builders\JSON
[ "Returns", "a", "JSON", "response", "builder", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/traits/ControllerHelperTrait.php#L79-L82
train
mako-framework/framework
src/mako/database/midgard/relations/BelongsTo.php
BelongsTo.getRelated
public function getRelated() { if($this->parent->getRawColumnValue($this->getForeignKey()) === null) { return false; } return $this->first(); }
php
public function getRelated() { if($this->parent->getRawColumnValue($this->getForeignKey()) === null) { return false; } return $this->first(); }
[ "public", "function", "getRelated", "(", ")", "{", "if", "(", "$", "this", "->", "parent", "->", "getRawColumnValue", "(", "$", "this", "->", "getForeignKey", "(", ")", ")", "===", "null", ")", "{", "return", "false", ";", "}", "return", "$", "this", ...
Returns related a record from the database. @return \mako\database\midgard\ORM|false
[ "Returns", "related", "a", "record", "from", "the", "database", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/relations/BelongsTo.php#L115-L123
train
mako-framework/framework
src/mako/application/services/SessionService.php
SessionService.getDatabaseStore
protected function getDatabaseStore(Container $container, array $config, $classWhitelist) { return new Database($container->get(DatabaseConnectionManager::class)->connection($config['configuration']), $config['table'], $classWhitelist); }
php
protected function getDatabaseStore(Container $container, array $config, $classWhitelist) { return new Database($container->get(DatabaseConnectionManager::class)->connection($config['configuration']), $config['table'], $classWhitelist); }
[ "protected", "function", "getDatabaseStore", "(", "Container", "$", "container", ",", "array", "$", "config", ",", "$", "classWhitelist", ")", "{", "return", "new", "Database", "(", "$", "container", "->", "get", "(", "DatabaseConnectionManager", "::", "class", ...
Returns a database store instance. @param \mako\syringe\Container $container Container @param array $config Store configuration @param bool|array $classWhitelist Class whitelist @return \mako\session\stores\Database
[ "Returns", "a", "database", "store", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/services/SessionService.php#L37-L40
train
mako-framework/framework
src/mako/application/services/SessionService.php
SessionService.getFileStore
protected function getFileStore(Container $container, array $config, $classWhitelist) { return new File($container->get(FileSystem::class), $config['path'], $classWhitelist); }
php
protected function getFileStore(Container $container, array $config, $classWhitelist) { return new File($container->get(FileSystem::class), $config['path'], $classWhitelist); }
[ "protected", "function", "getFileStore", "(", "Container", "$", "container", ",", "array", "$", "config", ",", "$", "classWhitelist", ")", "{", "return", "new", "File", "(", "$", "container", "->", "get", "(", "FileSystem", "::", "class", ")", ",", "$", ...
Returns a file store instance. @param \mako\syringe\Container $container Container @param array $config Store configuration @param bool|array $classWhitelist Class whitelist @return \mako\session\stores\File
[ "Returns", "a", "file", "store", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/services/SessionService.php#L50-L53
train
mako-framework/framework
src/mako/application/services/SessionService.php
SessionService.getRedisStore
protected function getRedisStore(Container $container, array $config, $classWhitelist) { return new Redis($container->get(RedisConnectionManager::class)->connection($config['configuration']), $classWhitelist); }
php
protected function getRedisStore(Container $container, array $config, $classWhitelist) { return new Redis($container->get(RedisConnectionManager::class)->connection($config['configuration']), $classWhitelist); }
[ "protected", "function", "getRedisStore", "(", "Container", "$", "container", ",", "array", "$", "config", ",", "$", "classWhitelist", ")", "{", "return", "new", "Redis", "(", "$", "container", "->", "get", "(", "RedisConnectionManager", "::", "class", ")", ...
Returns a redis store instance. @param \mako\syringe\Container $container Container @param array $config Store configuration @param bool|array $classWhitelist Class whitelist @return \mako\session\stores\Redis
[ "Returns", "a", "redis", "store", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/services/SessionService.php#L76-L79
train
mako-framework/framework
src/mako/application/services/SessionService.php
SessionService.getStore
protected function getStore(Container $container, array $config, $classWhitelist) { $config = $config['configurations'][$config['configuration']]; switch($config['type']) { case 'database': return $this->getDatabaseStore($container, $config, $classWhitelist); break; case 'file': return $this->getFileStore($container, $config, $classWhitelist); break; case 'null': return $this->getNullStore($container, $config, $classWhitelist); break; case 'redis': return $this->getRedisStore($container, $config, $classWhitelist); break; } }
php
protected function getStore(Container $container, array $config, $classWhitelist) { $config = $config['configurations'][$config['configuration']]; switch($config['type']) { case 'database': return $this->getDatabaseStore($container, $config, $classWhitelist); break; case 'file': return $this->getFileStore($container, $config, $classWhitelist); break; case 'null': return $this->getNullStore($container, $config, $classWhitelist); break; case 'redis': return $this->getRedisStore($container, $config, $classWhitelist); break; } }
[ "protected", "function", "getStore", "(", "Container", "$", "container", ",", "array", "$", "config", ",", "$", "classWhitelist", ")", "{", "$", "config", "=", "$", "config", "[", "'configurations'", "]", "[", "$", "config", "[", "'configuration'", "]", "]...
Returns a session store instance. @param \mako\syringe\Container $container Container @param array $config Session configuration @param bool|array $classWhitelist Class whitelist @return \mako\session\stores\StoreInterface
[ "Returns", "a", "session", "store", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/services/SessionService.php#L89-L108
train
mako-framework/framework
src/mako/gatekeeper/repositories/user/UserRepository.php
UserRepository.setIdentifier
public function setIdentifier(string $identifier): void { if(!in_array($identifier, ['email', 'username', 'id'])) { throw new InvalidArgumentException(vsprintf('Invalid identifier [ %s ].', [$identifier])); } $this->identifier = $identifier; }
php
public function setIdentifier(string $identifier): void { if(!in_array($identifier, ['email', 'username', 'id'])) { throw new InvalidArgumentException(vsprintf('Invalid identifier [ %s ].', [$identifier])); } $this->identifier = $identifier; }
[ "public", "function", "setIdentifier", "(", "string", "$", "identifier", ")", ":", "void", "{", "if", "(", "!", "in_array", "(", "$", "identifier", ",", "[", "'email'", ",", "'username'", ",", "'id'", "]", ")", ")", "{", "throw", "new", "InvalidArgumentE...
Sets the user identifier. @param string $identifier User identifier @throws \InvalidArgumentException
[ "Sets", "the", "user", "identifier", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/repositories/user/UserRepository.php#L79-L87
train
mako-framework/framework
src/mako/gatekeeper/repositories/user/UserRepository.php
UserRepository.setAuthorizer
protected function setAuthorizer($user) { if($user !== false && $this->authorizer !== null && $user instanceof AuthorizableInterface) { $user->setAuthorizer($this->authorizer); } return $user; }
php
protected function setAuthorizer($user) { if($user !== false && $this->authorizer !== null && $user instanceof AuthorizableInterface) { $user->setAuthorizer($this->authorizer); } return $user; }
[ "protected", "function", "setAuthorizer", "(", "$", "user", ")", "{", "if", "(", "$", "user", "!==", "false", "&&", "$", "this", "->", "authorizer", "!==", "null", "&&", "$", "user", "instanceof", "AuthorizableInterface", ")", "{", "$", "user", "->", "se...
Sets the authorizer. @param \mako\gatekeeper\entities\user\User|bool $user User @return \mako\gatekeeper\entities\user\User|bool
[ "Sets", "the", "authorizer", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/repositories/user/UserRepository.php#L95-L103
train
mako-framework/framework
src/mako/gatekeeper/repositories/user/UserRepository.php
UserRepository.getByActionToken
public function getByActionToken(string $token) { return $this->setAuthorizer($this->getModel()->where('action_token', '=', $token)->first()); }
php
public function getByActionToken(string $token) { return $this->setAuthorizer($this->getModel()->where('action_token', '=', $token)->first()); }
[ "public", "function", "getByActionToken", "(", "string", "$", "token", ")", "{", "return", "$", "this", "->", "setAuthorizer", "(", "$", "this", "->", "getModel", "(", ")", "->", "where", "(", "'action_token'", ",", "'='", ",", "$", "token", ")", "->", ...
Fetches a user by its action token. @param string $token Action token @return \mako\gatekeeper\entities\user\User|bool
[ "Fetches", "a", "user", "by", "its", "action", "token", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/repositories/user/UserRepository.php#L132-L135
train
mako-framework/framework
src/mako/gatekeeper/repositories/user/UserRepository.php
UserRepository.getByAccessToken
public function getByAccessToken(string $token) { return $this->setAuthorizer($this->getModel()->where('access_token', '=', $token)->first()); }
php
public function getByAccessToken(string $token) { return $this->setAuthorizer($this->getModel()->where('access_token', '=', $token)->first()); }
[ "public", "function", "getByAccessToken", "(", "string", "$", "token", ")", "{", "return", "$", "this", "->", "setAuthorizer", "(", "$", "this", "->", "getModel", "(", ")", "->", "where", "(", "'access_token'", ",", "'='", ",", "$", "token", ")", "->", ...
Fetches a user by its access token. @param string $token Access token @return \mako\gatekeeper\entities\user\User|bool
[ "Fetches", "a", "user", "by", "its", "access", "token", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/repositories/user/UserRepository.php#L143-L146
train
mako-framework/framework
src/mako/gatekeeper/repositories/user/UserRepository.php
UserRepository.getByEmail
public function getByEmail(string $email) { return $this->setAuthorizer($this->getModel()->where('email', '=', $email)->first()); }
php
public function getByEmail(string $email) { return $this->setAuthorizer($this->getModel()->where('email', '=', $email)->first()); }
[ "public", "function", "getByEmail", "(", "string", "$", "email", ")", "{", "return", "$", "this", "->", "setAuthorizer", "(", "$", "this", "->", "getModel", "(", ")", "->", "where", "(", "'email'", ",", "'='", ",", "$", "email", ")", "->", "first", "...
Fetches a user by its email address. @param string $email Email address @return \mako\gatekeeper\entities\user\User|bool
[ "Fetches", "a", "user", "by", "its", "email", "address", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/repositories/user/UserRepository.php#L154-L157
train
mako-framework/framework
src/mako/gatekeeper/repositories/user/UserRepository.php
UserRepository.getByUsername
public function getByUsername(string $username) { return $this->setAuthorizer($this->getModel()->where('username', '=', $username)->first()); }
php
public function getByUsername(string $username) { return $this->setAuthorizer($this->getModel()->where('username', '=', $username)->first()); }
[ "public", "function", "getByUsername", "(", "string", "$", "username", ")", "{", "return", "$", "this", "->", "setAuthorizer", "(", "$", "this", "->", "getModel", "(", ")", "->", "where", "(", "'username'", ",", "'='", ",", "$", "username", ")", "->", ...
Fetches a user by its username. @param string $username Username @return \mako\gatekeeper\entities\user\User|bool
[ "Fetches", "a", "user", "by", "its", "username", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/repositories/user/UserRepository.php#L165-L168
train
mako-framework/framework
src/mako/gatekeeper/repositories/user/UserRepository.php
UserRepository.getById
public function getById(int $id) { return $this->setAuthorizer($this->getModel()->where('id', '=', $id)->first()); }
php
public function getById(int $id) { return $this->setAuthorizer($this->getModel()->where('id', '=', $id)->first()); }
[ "public", "function", "getById", "(", "int", "$", "id", ")", "{", "return", "$", "this", "->", "setAuthorizer", "(", "$", "this", "->", "getModel", "(", ")", "->", "where", "(", "'id'", ",", "'='", ",", "$", "id", ")", "->", "first", "(", ")", ")...
Fetches a user by its id. @param int $id User id @return \mako\gatekeeper\entities\user\User|bool
[ "Fetches", "a", "user", "by", "its", "id", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/repositories/user/UserRepository.php#L176-L179
train
mako-framework/framework
src/mako/pixl/Image.php
Image.resize
public function resize($width, $height = null, $aspectRatio = Image::RESIZE_IGNORE): Image { $this->processor->resize($width, $height, $aspectRatio); return $this; }
php
public function resize($width, $height = null, $aspectRatio = Image::RESIZE_IGNORE): Image { $this->processor->resize($width, $height, $aspectRatio); return $this; }
[ "public", "function", "resize", "(", "$", "width", ",", "$", "height", "=", "null", ",", "$", "aspectRatio", "=", "Image", "::", "RESIZE_IGNORE", ")", ":", "Image", "{", "$", "this", "->", "processor", "->", "resize", "(", "$", "width", ",", "$", "he...
Resizes the image to the chosen size. @param int $width Width of the image @param int $height Height of the image @param int $aspectRatio Aspect ratio @return \mako\pixl\Image
[ "Resizes", "the", "image", "to", "the", "chosen", "size", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/pixl/Image.php#L221-L226
train
mako-framework/framework
src/mako/pixl/Image.php
Image.crop
public function crop($width, $height, $x, $y): Image { $this->processor->crop($width, $height, $x, $y); return $this; }
php
public function crop($width, $height, $x, $y): Image { $this->processor->crop($width, $height, $x, $y); return $this; }
[ "public", "function", "crop", "(", "$", "width", ",", "$", "height", ",", "$", "x", ",", "$", "y", ")", ":", "Image", "{", "$", "this", "->", "processor", "->", "crop", "(", "$", "width", ",", "$", "height", ",", "$", "x", ",", "$", "y", ")",...
Crops the image. @param int $width Width of the crop @param int $height Height of the crop @param int $x The X coordinate of the cropped region's top left corner @param int $y The Y coordinate of the cropped region's top left corner @return \mako\pixl\Image
[ "Crops", "the", "image", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/pixl/Image.php#L237-L242
train
mako-framework/framework
src/mako/pixl/Image.php
Image.watermark
public function watermark($file, $position = Image::WATERMARK_TOP_LEFT, $opacity = 100): Image { // Check if the image exists if(file_exists($file) === false) { throw new RuntimeException(vsprintf('The watermark image [ %s ] does not exist.', [$file])); } // Make sure that opacity is between 0 and 100 $opacity = max(min((int) $opacity, 100), 0); // Add watermark to the image $this->processor->watermark($file, $position, $opacity); return $this; }
php
public function watermark($file, $position = Image::WATERMARK_TOP_LEFT, $opacity = 100): Image { // Check if the image exists if(file_exists($file) === false) { throw new RuntimeException(vsprintf('The watermark image [ %s ] does not exist.', [$file])); } // Make sure that opacity is between 0 and 100 $opacity = max(min((int) $opacity, 100), 0); // Add watermark to the image $this->processor->watermark($file, $position, $opacity); return $this; }
[ "public", "function", "watermark", "(", "$", "file", ",", "$", "position", "=", "Image", "::", "WATERMARK_TOP_LEFT", ",", "$", "opacity", "=", "100", ")", ":", "Image", "{", "// Check if the image exists", "if", "(", "file_exists", "(", "$", "file", ")", "...
Adds a watermark to the image. @param string $file Path to the image file @param int $position Position of the watermark @param int $opacity Opacity of the watermark in percent @throws \RuntimeException @return \mako\pixl\Image
[ "Adds", "a", "watermark", "to", "the", "image", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/pixl/Image.php#L266-L284
train
mako-framework/framework
src/mako/pixl/Image.php
Image.brightness
public function brightness($level = 50): Image { // Normalize brighness level $level = min(max($level, -100), 100); // Adjust brightness $this->processor->brightness($level); return $this; }
php
public function brightness($level = 50): Image { // Normalize brighness level $level = min(max($level, -100), 100); // Adjust brightness $this->processor->brightness($level); return $this; }
[ "public", "function", "brightness", "(", "$", "level", "=", "50", ")", ":", "Image", "{", "// Normalize brighness level", "$", "level", "=", "min", "(", "max", "(", "$", "level", ",", "-", "100", ")", ",", "100", ")", ";", "// Adjust brightness", "$", ...
Adjust image brightness. @param int $level Brightness level (-100 to 100) @return \mako\pixl\Image
[ "Adjust", "image", "brightness", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/pixl/Image.php#L292-L303
train
mako-framework/framework
src/mako/pixl/Image.php
Image.border
public function border($color = '#000', $thickness = 5): Image { $this->processor->border($color, $thickness); return $this; }
php
public function border($color = '#000', $thickness = 5): Image { $this->processor->border($color, $thickness); return $this; }
[ "public", "function", "border", "(", "$", "color", "=", "'#000'", ",", "$", "thickness", "=", "5", ")", ":", "Image", "{", "$", "this", "->", "processor", "->", "border", "(", "$", "color", ",", "$", "thickness", ")", ";", "return", "$", "this", ";...
Adds a border to the image. @param string $color Hex code for the color @param int $thickness Thickness of the frame in pixels @return \mako\pixl\Image
[ "Adds", "a", "border", "to", "the", "image", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/pixl/Image.php#L396-L401
train
mako-framework/framework
src/mako/pixl/Image.php
Image.getImageBlob
public function getImageBlob($type = null, $quality = 95) { return $this->processor->getImageBlob($type, $this->normalizeImageQuality($quality)); }
php
public function getImageBlob($type = null, $quality = 95) { return $this->processor->getImageBlob($type, $this->normalizeImageQuality($quality)); }
[ "public", "function", "getImageBlob", "(", "$", "type", "=", "null", ",", "$", "quality", "=", "95", ")", "{", "return", "$", "this", "->", "processor", "->", "getImageBlob", "(", "$", "type", ",", "$", "this", "->", "normalizeImageQuality", "(", "$", ...
Returns a string containing the image. @param string $type Image type @param int $quality Image quality 1-100 @return string
[ "Returns", "a", "string", "containing", "the", "image", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/pixl/Image.php#L410-L413
train
mako-framework/framework
src/mako/pixl/Image.php
Image.save
public function save($file = null, $quality = 95): void { $file = $file ?? $this->image; // Mage sure that the file or directory is writable if(file_exists($file)) { if(!is_writable($file)) { throw new RuntimeException(vsprintf('The file [ %s ] isn\'t writable.', [$file])); } } else { $pathInfo = pathinfo($file); if(!is_writable($pathInfo['dirname'])) { throw new RuntimeException(vsprintf('The directory [ %s ] isn\'t writable.', [$pathInfo['dirname']])); } } // Save the image $this->processor->save($file, $this->normalizeImageQuality($quality)); }
php
public function save($file = null, $quality = 95): void { $file = $file ?? $this->image; // Mage sure that the file or directory is writable if(file_exists($file)) { if(!is_writable($file)) { throw new RuntimeException(vsprintf('The file [ %s ] isn\'t writable.', [$file])); } } else { $pathInfo = pathinfo($file); if(!is_writable($pathInfo['dirname'])) { throw new RuntimeException(vsprintf('The directory [ %s ] isn\'t writable.', [$pathInfo['dirname']])); } } // Save the image $this->processor->save($file, $this->normalizeImageQuality($quality)); }
[ "public", "function", "save", "(", "$", "file", "=", "null", ",", "$", "quality", "=", "95", ")", ":", "void", "{", "$", "file", "=", "$", "file", "??", "$", "this", "->", "image", ";", "// Mage sure that the file or directory is writable", "if", "(", "f...
Saves image to file. @param string $file Path to the image file @param int $quality Image quality 1-100 @throws \RuntimeException
[ "Saves", "image", "to", "file", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/pixl/Image.php#L422-L448
train
mako-framework/framework
src/mako/http/response/senders/File.php
File.getContenType
protected function getContenType(): string { return $this->contentType ?? ($this->fileSystem->info($this->filePath)->getMimeType() ?? 'application/octet-stream'); }
php
protected function getContenType(): string { return $this->contentType ?? ($this->fileSystem->info($this->filePath)->getMimeType() ?? 'application/octet-stream'); }
[ "protected", "function", "getContenType", "(", ")", ":", "string", "{", "return", "$", "this", "->", "contentType", "??", "(", "$", "this", "->", "fileSystem", "->", "info", "(", "$", "this", "->", "filePath", ")", "->", "getMimeType", "(", ")", "??", ...
Returns the content type. @return string
[ "Returns", "the", "content", "type", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/response/senders/File.php#L187-L190
train
mako-framework/framework
src/mako/http/response/senders/File.php
File.calculateRange
protected function calculateRange(string $range) { // Remove the "range=" part of the header value $range = substr($range, 6); // Split the range starting and ending points $range = explode('-', $range, 2); // Check that the range contains two values if(count($range) !== 2) { return false; } // Determine start and ending points $end = $range[1] === '' ? $this->fileSize - 1 : $range[1]; if($range[0] === '') { $start = $this->fileSize - $end; $end = $this->fileSize - 1; } else { $start = $range[0]; } $start = (int) $start; $end = (int) $end; // Check that the range is satisfiable if($start > $end || $end + 1 > $this->fileSize) { return false; } // Return the range return ['start' => $start, 'end' => $end]; }
php
protected function calculateRange(string $range) { // Remove the "range=" part of the header value $range = substr($range, 6); // Split the range starting and ending points $range = explode('-', $range, 2); // Check that the range contains two values if(count($range) !== 2) { return false; } // Determine start and ending points $end = $range[1] === '' ? $this->fileSize - 1 : $range[1]; if($range[0] === '') { $start = $this->fileSize - $end; $end = $this->fileSize - 1; } else { $start = $range[0]; } $start = (int) $start; $end = (int) $end; // Check that the range is satisfiable if($start > $end || $end + 1 > $this->fileSize) { return false; } // Return the range return ['start' => $start, 'end' => $end]; }
[ "protected", "function", "calculateRange", "(", "string", "$", "range", ")", "{", "// Remove the \"range=\" part of the header value", "$", "range", "=", "substr", "(", "$", "range", ",", "6", ")", ";", "// Split the range starting and ending points", "$", "range", "=...
Calculates the content range that should be served. @param string $range Request range @return array|false
[ "Calculates", "the", "content", "range", "that", "should", "be", "served", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/response/senders/File.php#L198-L242
train
mako-framework/framework
src/mako/common/traits/FunctionParserTrait.php
FunctionParserTrait.parseFunction
protected function parseFunction(string $function, ?bool $namedParameters = null): array { if(strpos($function, '(') === false) { return [$function, []]; } $function = $this->splitFunctionAndParameters($function); if($namedParameters === null) { $namedParameters = preg_match('/^"[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"\s*:/', $function[1]) === 1; } $parameters = json_decode(($namedParameters ? '{' . $function[1] . '}' : '[' . $function[1] . ']'), true); if($parameters === null && json_last_error() !== JSON_ERROR_NONE) { throw new RuntimeException('Failed to decode function parameters.'); } return [$function[0], $parameters]; }
php
protected function parseFunction(string $function, ?bool $namedParameters = null): array { if(strpos($function, '(') === false) { return [$function, []]; } $function = $this->splitFunctionAndParameters($function); if($namedParameters === null) { $namedParameters = preg_match('/^"[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"\s*:/', $function[1]) === 1; } $parameters = json_decode(($namedParameters ? '{' . $function[1] . '}' : '[' . $function[1] . ']'), true); if($parameters === null && json_last_error() !== JSON_ERROR_NONE) { throw new RuntimeException('Failed to decode function parameters.'); } return [$function[0], $parameters]; }
[ "protected", "function", "parseFunction", "(", "string", "$", "function", ",", "?", "bool", "$", "namedParameters", "=", "null", ")", ":", "array", "{", "if", "(", "strpos", "(", "$", "function", ",", "'('", ")", "===", "false", ")", "{", "return", "["...
Parses custom "function calls". The return value is an array consisting of the function name and parameters. @param string $function Function @param bool|null $namedParameters Are we expecting named parameters? @throws \RuntimeException @return array
[ "Parses", "custom", "function", "calls", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/common/traits/FunctionParserTrait.php#L52-L74
train
mako-framework/framework
src/mako/cli/input/helpers/Select.php
Select.buildOptionsList
protected function buildOptionsList(array $options): string { $output = ''; foreach($options as $key => $option) { $output .= ($key + 1) . ') ' . $option . PHP_EOL; } return $output . '> '; }
php
protected function buildOptionsList(array $options): string { $output = ''; foreach($options as $key => $option) { $output .= ($key + 1) . ') ' . $option . PHP_EOL; } return $output . '> '; }
[ "protected", "function", "buildOptionsList", "(", "array", "$", "options", ")", ":", "string", "{", "$", "output", "=", "''", ";", "foreach", "(", "$", "options", "as", "$", "key", "=>", "$", "option", ")", "{", "$", "output", ".=", "(", "$", "key", ...
Returns a list of options. @param array $options Options @return string
[ "Returns", "a", "list", "of", "options", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cli/input/helpers/Select.php#L56-L66
train
mako-framework/framework
src/mako/syringe/Container.php
Container.parseHint
protected function parseHint($hint): string { if(is_array($hint)) { [$hint, $alias] = $hint; $this->aliases[$alias] = $hint; } return $hint; }
php
protected function parseHint($hint): string { if(is_array($hint)) { [$hint, $alias] = $hint; $this->aliases[$alias] = $hint; } return $hint; }
[ "protected", "function", "parseHint", "(", "$", "hint", ")", ":", "string", "{", "if", "(", "is_array", "(", "$", "hint", ")", ")", "{", "[", "$", "hint", ",", "$", "alias", "]", "=", "$", "hint", ";", "$", "this", "->", "aliases", "[", "$", "a...
Parse the hint parameter. @param string|array $hint Type hint or array contaning both type hint and alias @return string
[ "Parse", "the", "hint", "parameter", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L75-L85
train
mako-framework/framework
src/mako/syringe/Container.php
Container.register
public function register($hint, $class, bool $singleton = false): void { $this->hints[$this->parseHint($hint)] = ['class' => $class, 'singleton' => $singleton]; }
php
public function register($hint, $class, bool $singleton = false): void { $this->hints[$this->parseHint($hint)] = ['class' => $class, 'singleton' => $singleton]; }
[ "public", "function", "register", "(", "$", "hint", ",", "$", "class", ",", "bool", "$", "singleton", "=", "false", ")", ":", "void", "{", "$", "this", "->", "hints", "[", "$", "this", "->", "parseHint", "(", "$", "hint", ")", "]", "=", "[", "'cl...
Register a type hint. @param string|array $hint Type hint or array contaning both type hint and alias @param string|\Closure $class Class name or closure @param bool $singleton Should we return the same instance every time?
[ "Register", "a", "type", "hint", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L94-L97
train
mako-framework/framework
src/mako/syringe/Container.php
Container.registerInstance
public function registerInstance($hint, object $instance): void { $this->instances[$this->parseHint($hint)] = $instance; }
php
public function registerInstance($hint, object $instance): void { $this->instances[$this->parseHint($hint)] = $instance; }
[ "public", "function", "registerInstance", "(", "$", "hint", ",", "object", "$", "instance", ")", ":", "void", "{", "$", "this", "->", "instances", "[", "$", "this", "->", "parseHint", "(", "$", "hint", ")", "]", "=", "$", "instance", ";", "}" ]
Register a singleton instance. @param string|array $hint Type hint or array contaning both type hint and alias @param object $instance Class instance
[ "Register", "a", "singleton", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L116-L119
train
mako-framework/framework
src/mako/syringe/Container.php
Container.replaceInstances
protected function replaceInstances(string $hint): void { if(isset($this->replacers[$hint])) { $instance = $this->get($hint); foreach($this->replacers[$hint] as $replacer) { $replacer($instance); } } }
php
protected function replaceInstances(string $hint): void { if(isset($this->replacers[$hint])) { $instance = $this->get($hint); foreach($this->replacers[$hint] as $replacer) { $replacer($instance); } } }
[ "protected", "function", "replaceInstances", "(", "string", "$", "hint", ")", ":", "void", "{", "if", "(", "isset", "(", "$", "this", "->", "replacers", "[", "$", "hint", "]", ")", ")", "{", "$", "instance", "=", "$", "this", "->", "get", "(", "$",...
Replaces previously resolved instances. @param string $hint Type hint
[ "Replaces", "previously", "resolved", "instances", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L149-L160
train
mako-framework/framework
src/mako/syringe/Container.php
Container.onReplace
public function onReplace(string $hint, callable $replacer, ?string $eventName = null): void { $hint = $this->resolveAlias($hint); $eventName === null ? ($this->replacers[$hint][] = $replacer) : ($this->replacers[$hint][$eventName] = $replacer); }
php
public function onReplace(string $hint, callable $replacer, ?string $eventName = null): void { $hint = $this->resolveAlias($hint); $eventName === null ? ($this->replacers[$hint][] = $replacer) : ($this->replacers[$hint][$eventName] = $replacer); }
[ "public", "function", "onReplace", "(", "string", "$", "hint", ",", "callable", "$", "replacer", ",", "?", "string", "$", "eventName", "=", "null", ")", ":", "void", "{", "$", "hint", "=", "$", "this", "->", "resolveAlias", "(", "$", "hint", ")", ";"...
Registers replacers. @param string $hint Type hint @param callable $replacer Instance replacer @param string|null $eventName Event name
[ "Registers", "replacers", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L169-L174
train
mako-framework/framework
src/mako/syringe/Container.php
Container.replace
public function replace(string $hint, $class, bool $singleton = false): void { $hint = $this->resolveAlias($hint); if(!isset($this->hints[$hint])) { throw new ContainerException(vsprintf('Unable to replace [ %s ] as it hasn\'t been registered.', [$hint])); } $this->hints[$hint]['class'] = $class; if($singleton) { unset($this->instances[$hint]); } $this->replaceInstances($hint); }
php
public function replace(string $hint, $class, bool $singleton = false): void { $hint = $this->resolveAlias($hint); if(!isset($this->hints[$hint])) { throw new ContainerException(vsprintf('Unable to replace [ %s ] as it hasn\'t been registered.', [$hint])); } $this->hints[$hint]['class'] = $class; if($singleton) { unset($this->instances[$hint]); } $this->replaceInstances($hint); }
[ "public", "function", "replace", "(", "string", "$", "hint", ",", "$", "class", ",", "bool", "$", "singleton", "=", "false", ")", ":", "void", "{", "$", "hint", "=", "$", "this", "->", "resolveAlias", "(", "$", "hint", ")", ";", "if", "(", "!", "...
Replaces a registered type hint. @param string $hint Type hint @param string|\Closure $class Class name or closure @param bool $singleton Are we replacing a singleton? @throws \mako\syringe\exceptions\ContainerException
[ "Replaces", "a", "registered", "type", "hint", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L184-L201
train
mako-framework/framework
src/mako/syringe/Container.php
Container.replaceInstance
public function replaceInstance(string $hint, object $instance): void { $hint = $this->resolveAlias($hint); if(!isset($this->instances[$hint])) { throw new ContainerException(vsprintf('Unable to replace [ %s ] as it hasn\'t been registered.', [$hint])); } $this->instances[$hint] = $instance; $this->replaceInstances($hint); }
php
public function replaceInstance(string $hint, object $instance): void { $hint = $this->resolveAlias($hint); if(!isset($this->instances[$hint])) { throw new ContainerException(vsprintf('Unable to replace [ %s ] as it hasn\'t been registered.', [$hint])); } $this->instances[$hint] = $instance; $this->replaceInstances($hint); }
[ "public", "function", "replaceInstance", "(", "string", "$", "hint", ",", "object", "$", "instance", ")", ":", "void", "{", "$", "hint", "=", "$", "this", "->", "resolveAlias", "(", "$", "hint", ")", ";", "if", "(", "!", "isset", "(", "$", "this", ...
Replaces a singleton instance. @param string $hint Type hint @param object $instance Class instance @throws \mako\syringe\exceptions\ContainerException
[ "Replaces", "a", "singleton", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L221-L233
train
mako-framework/framework
src/mako/syringe/Container.php
Container.mergeParameters
protected function mergeParameters(array $reflectionParameters, array $providedParameters): array { // Make reflection parameter array associative $associativeReflectionParameters = []; foreach($reflectionParameters as $value) { $associativeReflectionParameters[$value->getName()] = $value; } // Make the provided parameter array associative $associativeProvidedParameters = []; foreach($providedParameters as $key => $value) { if(is_int($key)) { $associativeProvidedParameters[$reflectionParameters[$key]->getName()] = $value; } else { $associativeProvidedParameters[$key] = $value; } } // Return merged parameters return array_replace($associativeReflectionParameters, $associativeProvidedParameters); }
php
protected function mergeParameters(array $reflectionParameters, array $providedParameters): array { // Make reflection parameter array associative $associativeReflectionParameters = []; foreach($reflectionParameters as $value) { $associativeReflectionParameters[$value->getName()] = $value; } // Make the provided parameter array associative $associativeProvidedParameters = []; foreach($providedParameters as $key => $value) { if(is_int($key)) { $associativeProvidedParameters[$reflectionParameters[$key]->getName()] = $value; } else { $associativeProvidedParameters[$key] = $value; } } // Return merged parameters return array_replace($associativeReflectionParameters, $associativeProvidedParameters); }
[ "protected", "function", "mergeParameters", "(", "array", "$", "reflectionParameters", ",", "array", "$", "providedParameters", ")", ":", "array", "{", "// Make reflection parameter array associative", "$", "associativeReflectionParameters", "=", "[", "]", ";", "foreach",...
Merges the provided parameters with the reflection parameters. @param array $reflectionParameters Reflection parameters @param array $providedParameters Provided parameters @return array
[ "Merges", "the", "provided", "parameters", "with", "the", "reflection", "parameters", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L265-L295
train
mako-framework/framework
src/mako/syringe/Container.php
Container.getDeclaringFunction
protected function getDeclaringFunction(ReflectionParameter $parameter): string { $declaringFunction = $parameter->getDeclaringFunction(); if($declaringFunction->isClosure()) { return 'Closure'; } if(($class = $parameter->getDeclaringClass()) === null) { return $declaringFunction->getName(); } return $class->getName() . '::' . $declaringFunction->getName(); }
php
protected function getDeclaringFunction(ReflectionParameter $parameter): string { $declaringFunction = $parameter->getDeclaringFunction(); if($declaringFunction->isClosure()) { return 'Closure'; } if(($class = $parameter->getDeclaringClass()) === null) { return $declaringFunction->getName(); } return $class->getName() . '::' . $declaringFunction->getName(); }
[ "protected", "function", "getDeclaringFunction", "(", "ReflectionParameter", "$", "parameter", ")", ":", "string", "{", "$", "declaringFunction", "=", "$", "parameter", "->", "getDeclaringFunction", "(", ")", ";", "if", "(", "$", "declaringFunction", "->", "isClos...
Returns the name of the declaring function. @param \ReflectionParameter $parameter ReflectionParameter instance @return string
[ "Returns", "the", "name", "of", "the", "declaring", "function", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L303-L318
train
mako-framework/framework
src/mako/syringe/Container.php
Container.resolveParameters
protected function resolveParameters(array $reflectionParameters, array $providedParameters, ?ReflectionClass $class = null): array { if(empty($reflectionParameters)) { return array_values($providedParameters); } // Merge provided parameters with the ones we got using reflection $parameters = $this->mergeParameters($reflectionParameters, $providedParameters); // Loop through the parameters and resolve the ones that need resolving foreach($parameters as $key => $parameter) { if($parameter instanceof ReflectionParameter) { $parameters[$key] = $this->resolveParameter($parameter, $class); } } // Return resolved parameters return array_values($parameters); }
php
protected function resolveParameters(array $reflectionParameters, array $providedParameters, ?ReflectionClass $class = null): array { if(empty($reflectionParameters)) { return array_values($providedParameters); } // Merge provided parameters with the ones we got using reflection $parameters = $this->mergeParameters($reflectionParameters, $providedParameters); // Loop through the parameters and resolve the ones that need resolving foreach($parameters as $key => $parameter) { if($parameter instanceof ReflectionParameter) { $parameters[$key] = $this->resolveParameter($parameter, $class); } } // Return resolved parameters return array_values($parameters); }
[ "protected", "function", "resolveParameters", "(", "array", "$", "reflectionParameters", ",", "array", "$", "providedParameters", ",", "?", "ReflectionClass", "$", "class", "=", "null", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "reflectionParameters"...
Resolve parameters. @param array $reflectionParameters Reflection parameters @param array $providedParameters Provided Parameters @param \ReflectionClass|null $class ReflectionClass instance @return array
[ "Resolve", "parameters", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L384-L408
train
mako-framework/framework
src/mako/syringe/Container.php
Container.reflectionFactory
protected function reflectionFactory(string $class, array $parameters): object { $class = new ReflectionClass($class); // Check that it's possible to instantiate the class if(!$class->isInstantiable()) { throw new UnableToInstantiateException(vsprintf('Unable to create a [ %s ] instance.', [$class->getName()])); } // Get the class constructor $constructor = $class->getConstructor(); // If we don't have a constructor then we'll just return a new instance if($constructor === null) { return $class->newInstance(); } // The class had a constructor so we'll return a new instance using our resolved parameters return $class->newInstanceArgs($this->resolveParameters($constructor->getParameters(), $parameters, $class)); }
php
protected function reflectionFactory(string $class, array $parameters): object { $class = new ReflectionClass($class); // Check that it's possible to instantiate the class if(!$class->isInstantiable()) { throw new UnableToInstantiateException(vsprintf('Unable to create a [ %s ] instance.', [$class->getName()])); } // Get the class constructor $constructor = $class->getConstructor(); // If we don't have a constructor then we'll just return a new instance if($constructor === null) { return $class->newInstance(); } // The class had a constructor so we'll return a new instance using our resolved parameters return $class->newInstanceArgs($this->resolveParameters($constructor->getParameters(), $parameters, $class)); }
[ "protected", "function", "reflectionFactory", "(", "string", "$", "class", ",", "array", "$", "parameters", ")", ":", "object", "{", "$", "class", "=", "new", "ReflectionClass", "(", "$", "class", ")", ";", "// Check that it's possible to instantiate the class", "...
Creates a class instance using reflection. @param string $class Class name @param array $parameters Constructor parameters @throws \mako\syringe\exceptions\UnableToInstantiateException @return object
[ "Creates", "a", "class", "instance", "using", "reflection", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L445-L470
train
mako-framework/framework
src/mako/syringe/Container.php
Container.factory
public function factory($class, array $parameters = []): object { // Instantiate class if($class instanceof Closure) { $instance = $this->closureFactory($class, $parameters); } else { $instance = $this->reflectionFactory($class, $parameters); } // Inject container using setter if the class is container aware if($this->isContainerAware($instance)) { $instance->setContainer($this); } // Return the instance return $instance; }
php
public function factory($class, array $parameters = []): object { // Instantiate class if($class instanceof Closure) { $instance = $this->closureFactory($class, $parameters); } else { $instance = $this->reflectionFactory($class, $parameters); } // Inject container using setter if the class is container aware if($this->isContainerAware($instance)) { $instance->setContainer($this); } // Return the instance return $instance; }
[ "public", "function", "factory", "(", "$", "class", ",", "array", "$", "parameters", "=", "[", "]", ")", ":", "object", "{", "// Instantiate class", "if", "(", "$", "class", "instanceof", "Closure", ")", "{", "$", "instance", "=", "$", "this", "->", "c...
Creates a class instance. @param string|\Closure $class Class name or closure @param array $parameters Constructor parameters @return object
[ "Creates", "a", "class", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L479-L502
train
mako-framework/framework
src/mako/syringe/Container.php
Container.has
public function has(string $class): bool { $class = $this->resolveAlias($class); return (isset($this->hints[$class]) || isset($this->instances[$class])); }
php
public function has(string $class): bool { $class = $this->resolveAlias($class); return (isset($this->hints[$class]) || isset($this->instances[$class])); }
[ "public", "function", "has", "(", "string", "$", "class", ")", ":", "bool", "{", "$", "class", "=", "$", "this", "->", "resolveAlias", "(", "$", "class", ")", ";", "return", "(", "isset", "(", "$", "this", "->", "hints", "[", "$", "class", "]", "...
Returns true if the class is registered in the container false if not. @param string $class Class name @return bool
[ "Returns", "true", "if", "the", "class", "is", "registered", "in", "the", "container", "false", "if", "not", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L510-L515
train
mako-framework/framework
src/mako/syringe/Container.php
Container.isSingleton
public function isSingleton(string $class): bool { $class = $this->resolveAlias($class); return isset($this->instances[$class]) || (isset($this->hints[$class]) && $this->hints[$class]['singleton'] === true); }
php
public function isSingleton(string $class): bool { $class = $this->resolveAlias($class); return isset($this->instances[$class]) || (isset($this->hints[$class]) && $this->hints[$class]['singleton'] === true); }
[ "public", "function", "isSingleton", "(", "string", "$", "class", ")", ":", "bool", "{", "$", "class", "=", "$", "this", "->", "resolveAlias", "(", "$", "class", ")", ";", "return", "isset", "(", "$", "this", "->", "instances", "[", "$", "class", "]"...
Returns TRUE if a class has been registered as a singleton and FALSE if not. @param string $class Class name @return bool
[ "Returns", "TRUE", "if", "a", "class", "has", "been", "registered", "as", "a", "singleton", "and", "FALSE", "if", "not", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L534-L539
train
mako-framework/framework
src/mako/syringe/Container.php
Container.get
public function get(string $class, array $parameters = [], bool $reuseInstance = true): object { $class = $this->resolveAlias($class); // If a singleton instance exists then we'll just return it if($reuseInstance && isset($this->instances[$class])) { return $this->instances[$class]; } // Create new instance $instance = $this->factory($this->resolveHint($class), $parameters); // Store the instance if its registered as a singleton if($reuseInstance && isset($this->hints[$class]) && $this->hints[$class]['singleton']) { $this->instances[$class] = $instance; } // Return the instance return $instance; }
php
public function get(string $class, array $parameters = [], bool $reuseInstance = true): object { $class = $this->resolveAlias($class); // If a singleton instance exists then we'll just return it if($reuseInstance && isset($this->instances[$class])) { return $this->instances[$class]; } // Create new instance $instance = $this->factory($this->resolveHint($class), $parameters); // Store the instance if its registered as a singleton if($reuseInstance && isset($this->hints[$class]) && $this->hints[$class]['singleton']) { $this->instances[$class] = $instance; } // Return the instance return $instance; }
[ "public", "function", "get", "(", "string", "$", "class", ",", "array", "$", "parameters", "=", "[", "]", ",", "bool", "$", "reuseInstance", "=", "true", ")", ":", "object", "{", "$", "class", "=", "$", "this", "->", "resolveAlias", "(", "$", "class"...
Returns a class instance. @param string $class Class name @param array $parameters Constructor parameters @param bool $reuseInstance Reuse existing instance? @return object
[ "Returns", "a", "class", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L549-L574
train
mako-framework/framework
src/mako/syringe/Container.php
Container.call
public function call(callable $callable, array $parameters = []) { if(is_array($callable)) { $reflection = new ReflectionMethod($callable[0], $callable[1]); } else { $reflection = new ReflectionFunction($callable); } return $callable(...$this->resolveParameters($reflection->getParameters(), $parameters)); }
php
public function call(callable $callable, array $parameters = []) { if(is_array($callable)) { $reflection = new ReflectionMethod($callable[0], $callable[1]); } else { $reflection = new ReflectionFunction($callable); } return $callable(...$this->resolveParameters($reflection->getParameters(), $parameters)); }
[ "public", "function", "call", "(", "callable", "$", "callable", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "if", "(", "is_array", "(", "$", "callable", ")", ")", "{", "$", "reflection", "=", "new", "ReflectionMethod", "(", "$", "callable...
Execute a callable and inject its dependencies. @param callable $callable Callable @param array $parameters Parameters @return mixed
[ "Execute", "a", "callable", "and", "inject", "its", "dependencies", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/Container.php#L595-L607
train
mako-framework/framework
src/mako/database/midgard/Query.php
Query.get
public function get($id, array $columns = []) { if(!empty($columns)) { $this->select($columns); } return $this->where($this->model->getPrimaryKey(), '=', $id)->first(); }
php
public function get($id, array $columns = []) { if(!empty($columns)) { $this->select($columns); } return $this->where($this->model->getPrimaryKey(), '=', $id)->first(); }
[ "public", "function", "get", "(", "$", "id", ",", "array", "$", "columns", "=", "[", "]", ")", "{", "if", "(", "!", "empty", "(", "$", "columns", ")", ")", "{", "$", "this", "->", "select", "(", "$", "columns", ")", ";", "}", "return", "$", "...
Returns a record using the value of its primary key. @param int|string $id Primary key @param array $columns Columns to select @return \mako\database\midgard\ORM
[ "Returns", "a", "record", "using", "the", "value", "of", "its", "primary", "key", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/Query.php#L213-L221
train
mako-framework/framework
src/mako/database/midgard/Query.php
Query.including
public function including($includes) { if($includes === false) { $this->model->setIncludes([]); } else { $includes = (array) $includes; $currentIncludes = $this->model->getIncludes(); if(!empty($currentIncludes)) { $withCriterion = array_filter(array_keys($includes), 'is_string'); if(!empty($withCriterion)) { foreach($currentIncludes as $key => $value) { if(in_array($value, $withCriterion)) { unset($currentIncludes[$key]); // Unset relations that have previously been set without a criterion closure } } } $includes = array_merge($currentIncludes, $includes); } $this->model->setIncludes(array_unique($includes, SORT_REGULAR)); } return $this; }
php
public function including($includes) { if($includes === false) { $this->model->setIncludes([]); } else { $includes = (array) $includes; $currentIncludes = $this->model->getIncludes(); if(!empty($currentIncludes)) { $withCriterion = array_filter(array_keys($includes), 'is_string'); if(!empty($withCriterion)) { foreach($currentIncludes as $key => $value) { if(in_array($value, $withCriterion)) { unset($currentIncludes[$key]); // Unset relations that have previously been set without a criterion closure } } } $includes = array_merge($currentIncludes, $includes); } $this->model->setIncludes(array_unique($includes, SORT_REGULAR)); } return $this; }
[ "public", "function", "including", "(", "$", "includes", ")", "{", "if", "(", "$", "includes", "===", "false", ")", "{", "$", "this", "->", "model", "->", "setIncludes", "(", "[", "]", ")", ";", "}", "else", "{", "$", "includes", "=", "(", "array",...
Adds relations to eager load. @param string|array|bool $includes Relation or array of relations to eager load @return $this
[ "Adds", "relations", "to", "eager", "load", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/Query.php#L229-L263
train
mako-framework/framework
src/mako/database/midgard/Query.php
Query.excluding
public function excluding($excludes) { if($excludes === true) { $this->model->setIncludes([]); } else { $excludes = (array) $excludes; $includes = $this->model->getIncludes(); foreach($excludes as $key => $relation) { if(is_string($relation) && isset($includes[$relation])) { unset($includes[$relation], $excludes[$key]); // Unset relations that may have been set with a criterion closure } } $this->model->setIncludes(array_udiff($includes, $excludes, function($a, $b) { return $a === $b ? 0 : -1; })); } return $this; }
php
public function excluding($excludes) { if($excludes === true) { $this->model->setIncludes([]); } else { $excludes = (array) $excludes; $includes = $this->model->getIncludes(); foreach($excludes as $key => $relation) { if(is_string($relation) && isset($includes[$relation])) { unset($includes[$relation], $excludes[$key]); // Unset relations that may have been set with a criterion closure } } $this->model->setIncludes(array_udiff($includes, $excludes, function($a, $b) { return $a === $b ? 0 : -1; })); } return $this; }
[ "public", "function", "excluding", "(", "$", "excludes", ")", "{", "if", "(", "$", "excludes", "===", "true", ")", "{", "$", "this", "->", "model", "->", "setIncludes", "(", "[", "]", ")", ";", "}", "else", "{", "$", "excludes", "=", "(", "array", ...
Removes relations to eager load. @param string|array|bool $excludes Relation or array of relations to exclude from eager loading @return $this
[ "Removes", "relations", "to", "eager", "load", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/Query.php#L271-L298
train
mako-framework/framework
src/mako/database/midgard/Query.php
Query.hydrateModel
protected function hydrateModel(array $result) { $model = $this->model->getClass(); return new $model($result, true, false, true); }
php
protected function hydrateModel(array $result) { $model = $this->model->getClass(); return new $model($result, true, false, true); }
[ "protected", "function", "hydrateModel", "(", "array", "$", "result", ")", "{", "$", "model", "=", "$", "this", "->", "model", "->", "getClass", "(", ")", ";", "return", "new", "$", "model", "(", "$", "result", ",", "true", ",", "false", ",", "true",...
Returns a hydrated model. @param array $result Database result @return \mako\database\midgard\ORM
[ "Returns", "a", "hydrated", "model", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/Query.php#L306-L311
train
mako-framework/framework
src/mako/database/midgard/Query.php
Query.parseIncludes
protected function parseIncludes() { $includes = ['this' => [], 'forward' => []]; foreach($this->model->getIncludes() as $include => $criteria) { if(is_numeric($include)) { $include = $criteria; $criteria = null; } if(($position = strpos($include, '.')) === false) { $includes['this'][$include] = $criteria; } else { if($criteria === null) { $includes['forward'][substr($include, 0, $position)][] = substr($include, $position + 1); } else { $includes['forward'][substr($include, 0, $position)][substr($include, $position + 1)] = $criteria; } } } return $includes; }
php
protected function parseIncludes() { $includes = ['this' => [], 'forward' => []]; foreach($this->model->getIncludes() as $include => $criteria) { if(is_numeric($include)) { $include = $criteria; $criteria = null; } if(($position = strpos($include, '.')) === false) { $includes['this'][$include] = $criteria; } else { if($criteria === null) { $includes['forward'][substr($include, 0, $position)][] = substr($include, $position + 1); } else { $includes['forward'][substr($include, 0, $position)][substr($include, $position + 1)] = $criteria; } } } return $includes; }
[ "protected", "function", "parseIncludes", "(", ")", "{", "$", "includes", "=", "[", "'this'", "=>", "[", "]", ",", "'forward'", "=>", "[", "]", "]", ";", "foreach", "(", "$", "this", "->", "model", "->", "getIncludes", "(", ")", "as", "$", "include",...
Parses includes. @return array
[ "Parses", "includes", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/Query.php#L318-L348
train
mako-framework/framework
src/mako/database/midgard/Query.php
Query.loadIncludes
protected function loadIncludes(array $results): void { $includes = $this->parseIncludes(); foreach($includes['this'] as $include => $criteria) { $forward = $includes['forward'][$include] ?? []; $results[0]->$include()->eagerLoad($results, $include, $criteria, $forward); } }
php
protected function loadIncludes(array $results): void { $includes = $this->parseIncludes(); foreach($includes['this'] as $include => $criteria) { $forward = $includes['forward'][$include] ?? []; $results[0]->$include()->eagerLoad($results, $include, $criteria, $forward); } }
[ "protected", "function", "loadIncludes", "(", "array", "$", "results", ")", ":", "void", "{", "$", "includes", "=", "$", "this", "->", "parseIncludes", "(", ")", ";", "foreach", "(", "$", "includes", "[", "'this'", "]", "as", "$", "include", "=>", "$",...
Load includes. @param array $results Loaded records
[ "Load", "includes", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/Query.php#L355-L365
train
mako-framework/framework
src/mako/database/midgard/Query.php
Query.hydrateModelsAndLoadIncludes
protected function hydrateModelsAndLoadIncludes($results) { $hydrated = []; foreach($results as $result) { $hydrated[] = $this->hydrateModel($result); } $this->loadIncludes($hydrated); return $hydrated; }
php
protected function hydrateModelsAndLoadIncludes($results) { $hydrated = []; foreach($results as $result) { $hydrated[] = $this->hydrateModel($result); } $this->loadIncludes($hydrated); return $hydrated; }
[ "protected", "function", "hydrateModelsAndLoadIncludes", "(", "$", "results", ")", "{", "$", "hydrated", "=", "[", "]", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "hydrated", "[", "]", "=", "$", "this", "->", "hydrateModel",...
Returns hydrated models. @param mixed $results Database results @return array
[ "Returns", "hydrated", "models", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/Query.php#L373-L385
train
mako-framework/framework
src/mako/database/midgard/Query.php
Query.first
public function first() { $result = $this->fetchFirst(PDO::FETCH_ASSOC); if($result !== false) { return $this->hydrateModelsAndLoadIncludes([$result])[0]; } return false; }
php
public function first() { $result = $this->fetchFirst(PDO::FETCH_ASSOC); if($result !== false) { return $this->hydrateModelsAndLoadIncludes([$result])[0]; } return false; }
[ "public", "function", "first", "(", ")", "{", "$", "result", "=", "$", "this", "->", "fetchFirst", "(", "PDO", "::", "FETCH_ASSOC", ")", ";", "if", "(", "$", "result", "!==", "false", ")", "{", "return", "$", "this", "->", "hydrateModelsAndLoadIncludes",...
Returns a single record from the database. @return \mako\database\midgard\ORM|false
[ "Returns", "a", "single", "record", "from", "the", "database", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/Query.php#L392-L402
train
mako-framework/framework
src/mako/database/midgard/Query.php
Query.all
public function all() { $results = $this->fetchAll(false, PDO::FETCH_ASSOC); if(!empty($results)) { $results = $this->hydrateModelsAndLoadIncludes($results); } return $this->createResultSet($results); }
php
public function all() { $results = $this->fetchAll(false, PDO::FETCH_ASSOC); if(!empty($results)) { $results = $this->hydrateModelsAndLoadIncludes($results); } return $this->createResultSet($results); }
[ "public", "function", "all", "(", ")", "{", "$", "results", "=", "$", "this", "->", "fetchAll", "(", "false", ",", "PDO", "::", "FETCH_ASSOC", ")", ";", "if", "(", "!", "empty", "(", "$", "results", ")", ")", "{", "$", "results", "=", "$", "this"...
Returns a result set from the database. @return \mako\database\midgard\ResultSet
[ "Returns", "a", "result", "set", "from", "the", "database", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/Query.php#L420-L430
train
mako-framework/framework
src/mako/database/midgard/Query.php
Query.scope
public function scope(string $scope, ...$arguments) { $this->model->{Str::underscored2camel($scope) . 'Scope'}(...array_merge([$this], $arguments)); return $this; }
php
public function scope(string $scope, ...$arguments) { $this->model->{Str::underscored2camel($scope) . 'Scope'}(...array_merge([$this], $arguments)); return $this; }
[ "public", "function", "scope", "(", "string", "$", "scope", ",", "...", "$", "arguments", ")", "{", "$", "this", "->", "model", "->", "{", "Str", "::", "underscored2camel", "(", "$", "scope", ")", ".", "'Scope'", "}", "(", "...", "array_merge", "(", ...
Calls a scope method on the model. @param string $scope Scope @param mixed ...$arguments Arguments @return $this
[ "Calls", "a", "scope", "method", "on", "the", "model", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/Query.php#L465-L470
train
mako-framework/framework
src/mako/http/routing/Router.php
Router.registerConstraint
public function registerConstraint(string $name, string $constraint): Router { $this->constraints[$name] = $constraint; return $this; }
php
public function registerConstraint(string $name, string $constraint): Router { $this->constraints[$name] = $constraint; return $this; }
[ "public", "function", "registerConstraint", "(", "string", "$", "name", ",", "string", "$", "constraint", ")", ":", "Router", "{", "$", "this", "->", "constraints", "[", "$", "name", "]", "=", "$", "constraint", ";", "return", "$", "this", ";", "}" ]
Registers constraint. @param string $name Constraint name @param string $constraint Constraint class name @return \mako\http\routing\Router
[ "Registers", "constraint", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Router.php#L87-L92
train
mako-framework/framework
src/mako/http/routing/Router.php
Router.matches
protected function matches(Route $route, string $path): bool { if(preg_match($route->getRegex(), $path, $parameters) > 0) { $filtered = []; foreach($parameters as $key => $value) { if(is_string($key)) { $filtered[$key] = $value; } } $route->setParameters($filtered); return true; } return false; }
php
protected function matches(Route $route, string $path): bool { if(preg_match($route->getRegex(), $path, $parameters) > 0) { $filtered = []; foreach($parameters as $key => $value) { if(is_string($key)) { $filtered[$key] = $value; } } $route->setParameters($filtered); return true; } return false; }
[ "protected", "function", "matches", "(", "Route", "$", "route", ",", "string", "$", "path", ")", ":", "bool", "{", "if", "(", "preg_match", "(", "$", "route", "->", "getRegex", "(", ")", ",", "$", "path", ",", "$", "parameters", ")", ">", "0", ")",...
Returns TRUE if the route matches the request path and FALSE if not. @param \mako\http\routing\Route $route Route @param string $path Request path @return bool
[ "Returns", "TRUE", "if", "the", "route", "matches", "the", "request", "path", "and", "FALSE", "if", "not", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Router.php#L114-L134
train
mako-framework/framework
src/mako/http/routing/Router.php
Router.constraintFactory
protected function constraintFactory(string $constraint): ConstraintInterface { [$constraint, $parameters] = $this->parseFunction($constraint); if(!isset($this->constraints[$constraint])) { throw new RuntimeException(vsprintf('No constraint named [ %s ] has been registered.', [$constraint])); } $constraint = $this->container->get($this->constraints[$constraint], $parameters); return $constraint; }
php
protected function constraintFactory(string $constraint): ConstraintInterface { [$constraint, $parameters] = $this->parseFunction($constraint); if(!isset($this->constraints[$constraint])) { throw new RuntimeException(vsprintf('No constraint named [ %s ] has been registered.', [$constraint])); } $constraint = $this->container->get($this->constraints[$constraint], $parameters); return $constraint; }
[ "protected", "function", "constraintFactory", "(", "string", "$", "constraint", ")", ":", "ConstraintInterface", "{", "[", "$", "constraint", ",", "$", "parameters", "]", "=", "$", "this", "->", "parseFunction", "(", "$", "constraint", ")", ";", "if", "(", ...
Constraint factory. @param string $constraint Constraint @throws \RuntimeException @return \mako\http\routing\constraints\ConstraintInterface
[ "Constraint", "factory", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Router.php#L143-L155
train
mako-framework/framework
src/mako/http/routing/Router.php
Router.constraintsAreSatisfied
protected function constraintsAreSatisfied(Route $route): bool { foreach(array_merge($this->globalConstraints, $route->getConstraints()) as $constraint) { if($this->constraintFactory($constraint)->isSatisfied() === false) { return false; } } return true; }
php
protected function constraintsAreSatisfied(Route $route): bool { foreach(array_merge($this->globalConstraints, $route->getConstraints()) as $constraint) { if($this->constraintFactory($constraint)->isSatisfied() === false) { return false; } } return true; }
[ "protected", "function", "constraintsAreSatisfied", "(", "Route", "$", "route", ")", ":", "bool", "{", "foreach", "(", "array_merge", "(", "$", "this", "->", "globalConstraints", ",", "$", "route", "->", "getConstraints", "(", ")", ")", "as", "$", "constrain...
Returns true if all the route constraints are satisfied and false if not. @param \mako\http\routing\Route $route Route @return bool
[ "Returns", "true", "if", "all", "the", "route", "constraints", "are", "satisfied", "and", "false", "if", "not", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Router.php#L163-L174
train