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/database/midgard/ResultSet.php
ResultSet.include
public function include($includes) { $items = $this->items; (function() use ($includes, $items): void { $this->including($includes)->loadIncludes($items); })->bindTo($this->items[0]->builder(), Query::class)(); return $this; }
php
public function include($includes) { $items = $this->items; (function() use ($includes, $items): void { $this->including($includes)->loadIncludes($items); })->bindTo($this->items[0]->builder(), Query::class)(); return $this; }
[ "public", "function", "include", "(", "$", "includes", ")", "{", "$", "items", "=", "$", "this", "->", "items", ";", "(", "function", "(", ")", "use", "(", "$", "includes", ",", "$", "items", ")", ":", "void", "{", "$", "this", "->", "including", ...
Eager loads relations on the collection. @param string|array $includes Relation or array of relations to eager load @return $this
[ "Eager", "loads", "relations", "on", "the", "collection", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/ResultSet.php#L62-L72
train
mako-framework/framework
src/mako/redis/Redis.php
Redis.createClusterClient
protected function createClusterClient(string $server): Redis { [$server, $port] = explode(':', $server, 2); $isPersistent = $this->connection->isPersistent(); $timeout = $this->connection->getTimeout(); $name = $this->connection->getName(); $connection = new Connection($server, $port, $isPersistent, $timeout, $name); return new static($connection, ['password' => $this->password, 'database' => $this->database]); }
php
protected function createClusterClient(string $server): Redis { [$server, $port] = explode(':', $server, 2); $isPersistent = $this->connection->isPersistent(); $timeout = $this->connection->getTimeout(); $name = $this->connection->getName(); $connection = new Connection($server, $port, $isPersistent, $timeout, $name); return new static($connection, ['password' => $this->password, 'database' => $this->database]); }
[ "protected", "function", "createClusterClient", "(", "string", "$", "server", ")", ":", "Redis", "{", "[", "$", "server", ",", "$", "port", "]", "=", "explode", "(", "':'", ",", "$", "server", ",", "2", ")", ";", "$", "isPersistent", "=", "$", "this"...
Creates a cluster client. @param string $server Server string @return \mako\redis\Redis
[ "Creates", "a", "cluster", "client", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/redis/Redis.php#L144-L157
train
mako-framework/framework
src/mako/redis/Redis.php
Redis.handleErrorResponse
protected function handleErrorResponse(string $response) { $response = substr($response, 1); [$type, $error] = explode(' ', $response, 2); switch($type) { case 'MOVED': case 'ASK': return $this->getClusterClient($error)->sendCommandAndGetResponse($this->lastCommand); break; default: throw new RedisException(vsprintf('%s.', [$response])); } }
php
protected function handleErrorResponse(string $response) { $response = substr($response, 1); [$type, $error] = explode(' ', $response, 2); switch($type) { case 'MOVED': case 'ASK': return $this->getClusterClient($error)->sendCommandAndGetResponse($this->lastCommand); break; default: throw new RedisException(vsprintf('%s.', [$response])); } }
[ "protected", "function", "handleErrorResponse", "(", "string", "$", "response", ")", "{", "$", "response", "=", "substr", "(", "$", "response", ",", "1", ")", ";", "[", "$", "type", ",", "$", "error", "]", "=", "explode", "(", "' '", ",", "$", "respo...
Handles redis error responses. @param string $response Error response @throws \mako\redis\RedisException @return mixed
[ "Handles", "redis", "error", "responses", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/redis/Redis.php#L184-L199
train
mako-framework/framework
src/mako/redis/Redis.php
Redis.handleBulkResponse
protected function handleBulkResponse(string $response): ?string { if($response === '$-1') { return null; } $length = (int) substr($response, 1); return substr($this->connection->read($length + static::CRLF_LENGTH), 0, - static::CRLF_LENGTH); }
php
protected function handleBulkResponse(string $response): ?string { if($response === '$-1') { return null; } $length = (int) substr($response, 1); return substr($this->connection->read($length + static::CRLF_LENGTH), 0, - static::CRLF_LENGTH); }
[ "protected", "function", "handleBulkResponse", "(", "string", "$", "response", ")", ":", "?", "string", "{", "if", "(", "$", "response", "===", "'$-1'", ")", "{", "return", "null", ";", "}", "$", "length", "=", "(", "int", ")", "substr", "(", "$", "r...
Handles a bulk response. @param string $response Redis response @return string|null
[ "Handles", "a", "bulk", "response", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/redis/Redis.php#L229-L239
train
mako-framework/framework
src/mako/redis/Redis.php
Redis.handleMultiBulkResponse
protected function handleMultiBulkResponse(string $response): ?array { if($response === '*-1') { return null; } $data = []; $count = (int) substr($response, 1); for($i = 0; $i < $count; $i++) { $data[] = $this->getResponse(); } return $data; }
php
protected function handleMultiBulkResponse(string $response): ?array { if($response === '*-1') { return null; } $data = []; $count = (int) substr($response, 1); for($i = 0; $i < $count; $i++) { $data[] = $this->getResponse(); } return $data; }
[ "protected", "function", "handleMultiBulkResponse", "(", "string", "$", "response", ")", ":", "?", "array", "{", "if", "(", "$", "response", "===", "'*-1'", ")", "{", "return", "null", ";", "}", "$", "data", "=", "[", "]", ";", "$", "count", "=", "("...
Handles a multi-bulk response. @param string $response Redis response @return array|null
[ "Handles", "a", "multi", "-", "bulk", "response", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/redis/Redis.php#L247-L264
train
mako-framework/framework
src/mako/redis/Redis.php
Redis.getResponse
protected function getResponse() { $response = trim($this->connection->readLine()); switch(substr($response, 0, 1)) { case '-': // error reply return $this->handleErrorResponse($response); break; case '+': // status reply return $this->handleStatusResponse($response); break; case ':': // integer reply return $this->handleIntegerResponse($response); break; case '$': // bulk reply return $this->handleBulkResponse($response); break; case '*': // multi-bulk reply return $this->handleMultiBulkResponse($response); break; default: throw new RedisException(vsprintf('Unable to handle server response [ %s ].', [$response])); } }
php
protected function getResponse() { $response = trim($this->connection->readLine()); switch(substr($response, 0, 1)) { case '-': // error reply return $this->handleErrorResponse($response); break; case '+': // status reply return $this->handleStatusResponse($response); break; case ':': // integer reply return $this->handleIntegerResponse($response); break; case '$': // bulk reply return $this->handleBulkResponse($response); break; case '*': // multi-bulk reply return $this->handleMultiBulkResponse($response); break; default: throw new RedisException(vsprintf('Unable to handle server response [ %s ].', [$response])); } }
[ "protected", "function", "getResponse", "(", ")", "{", "$", "response", "=", "trim", "(", "$", "this", "->", "connection", "->", "readLine", "(", ")", ")", ";", "switch", "(", "substr", "(", "$", "response", ",", "0", ",", "1", ")", ")", "{", "case...
Returns response from redis server. @throws \mako\redis\RedisException @return mixed
[ "Returns", "response", "from", "redis", "server", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/redis/Redis.php#L272-L296
train
mako-framework/framework
src/mako/redis/Redis.php
Redis.sendCommandToServer
protected function sendCommandToServer(string $command): void { $this->lastCommand = $command; $this->connection->write($command); }
php
protected function sendCommandToServer(string $command): void { $this->lastCommand = $command; $this->connection->write($command); }
[ "protected", "function", "sendCommandToServer", "(", "string", "$", "command", ")", ":", "void", "{", "$", "this", "->", "lastCommand", "=", "$", "command", ";", "$", "this", "->", "connection", "->", "write", "(", "$", "command", ")", ";", "}" ]
Sends command to server. @param string $command Command
[ "Sends", "command", "to", "server", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/redis/Redis.php#L303-L308
train
mako-framework/framework
src/mako/redis/Redis.php
Redis.pipeline
public function pipeline(Closure $pipeline): array { // Enable pipelining $this->pipelined = true; // Build commands $pipeline($this); // Send all commands to server and fetch responses $responses = []; $commands = count($this->commands); $this->sendCommandToServer(implode('', $this->commands)); for($i = 0; $i < $commands; $i++) { $responses[] = $this->getResponse(); } // Reset pipelining $this->commands = []; $this->pipelined = false; // Return array of responses return $responses; }
php
public function pipeline(Closure $pipeline): array { // Enable pipelining $this->pipelined = true; // Build commands $pipeline($this); // Send all commands to server and fetch responses $responses = []; $commands = count($this->commands); $this->sendCommandToServer(implode('', $this->commands)); for($i = 0; $i < $commands; $i++) { $responses[] = $this->getResponse(); } // Reset pipelining $this->commands = []; $this->pipelined = false; // Return array of responses return $responses; }
[ "public", "function", "pipeline", "(", "Closure", "$", "pipeline", ")", ":", "array", "{", "// Enable pipelining", "$", "this", "->", "pipelined", "=", "true", ";", "// Build commands", "$", "pipeline", "(", "$", "this", ")", ";", "// Send all commands to server...
Pipeline commands. @param \Closure $pipeline Pipelined commands @return array
[ "Pipeline", "commands", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/redis/Redis.php#L316-L348
train
mako-framework/framework
src/mako/redis/Redis.php
Redis.buildCommand
protected function buildCommand(string $name): array { $command = strtoupper(str_replace('_', ' ', Str::camel2underscored($name))); if(strpos($command, ' ') === false) { return [$command]; } $command = explode(' ', $command, 2); if(strpos($command[1], ' ') !== false) { $command[1] = str_replace(' ', '-', $command[1]); } return $command; }
php
protected function buildCommand(string $name): array { $command = strtoupper(str_replace('_', ' ', Str::camel2underscored($name))); if(strpos($command, ' ') === false) { return [$command]; } $command = explode(' ', $command, 2); if(strpos($command[1], ' ') !== false) { $command[1] = str_replace(' ', '-', $command[1]); } return $command; }
[ "protected", "function", "buildCommand", "(", "string", "$", "name", ")", ":", "array", "{", "$", "command", "=", "strtoupper", "(", "str_replace", "(", "'_'", ",", "' '", ",", "Str", "::", "camel2underscored", "(", "$", "name", ")", ")", ")", ";", "if...
Builds command from method name. @param string $name Method name @return array
[ "Builds", "command", "from", "method", "name", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/redis/Redis.php#L369-L386
train
mako-framework/framework
src/mako/cli/output/helpers/Table.php
Table.isValidInput
protected function isValidInput(array $columnNames, array $rows): bool { $columns = count($columnNames); if(!empty($rows)) { foreach($rows as $row) { if(count($row) !== $columns) { return false; } } } return true; }
php
protected function isValidInput(array $columnNames, array $rows): bool { $columns = count($columnNames); if(!empty($rows)) { foreach($rows as $row) { if(count($row) !== $columns) { return false; } } } return true; }
[ "protected", "function", "isValidInput", "(", "array", "$", "columnNames", ",", "array", "$", "rows", ")", ":", "bool", "{", "$", "columns", "=", "count", "(", "$", "columnNames", ")", ";", "if", "(", "!", "empty", "(", "$", "rows", ")", ")", "{", ...
Checks if the number of cells in each row matches the number of columns. @param array $columnNames Array of column names @param array $rows Array of rows @return bool
[ "Checks", "if", "the", "number", "of", "cells", "in", "each", "row", "matches", "the", "number", "of", "columns", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cli/output/helpers/Table.php#L62-L78
train
mako-framework/framework
src/mako/cli/output/helpers/Table.php
Table.getColumnWidths
protected function getColumnWidths(array $columnNames, array $rows): array { $columnWidths = []; // First we'll get the width of the column names foreach(array_values($columnNames) as $key => $value) { $columnWidths[$key] = $this->stringWidthWithoutFormatting($value); } // Then we'll go through each row and check if the cells are wider than the column names foreach($rows as $row) { foreach(array_values($row) as $key => $value) { $width = $this->stringWidthWithoutFormatting($value); if($width > $columnWidths[$key]) { $columnWidths[$key] = $width; } } } // Return array of column widths return $columnWidths; }
php
protected function getColumnWidths(array $columnNames, array $rows): array { $columnWidths = []; // First we'll get the width of the column names foreach(array_values($columnNames) as $key => $value) { $columnWidths[$key] = $this->stringWidthWithoutFormatting($value); } // Then we'll go through each row and check if the cells are wider than the column names foreach($rows as $row) { foreach(array_values($row) as $key => $value) { $width = $this->stringWidthWithoutFormatting($value); if($width > $columnWidths[$key]) { $columnWidths[$key] = $width; } } } // Return array of column widths return $columnWidths; }
[ "protected", "function", "getColumnWidths", "(", "array", "$", "columnNames", ",", "array", "$", "rows", ")", ":", "array", "{", "$", "columnWidths", "=", "[", "]", ";", "// First we'll get the width of the column names", "foreach", "(", "array_values", "(", "$", ...
Returns an array containing the maximum width of each column. @param array $columnNames Array of column names @param array $rows Array of rows @return array
[ "Returns", "an", "array", "containing", "the", "maximum", "width", "of", "each", "column", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cli/output/helpers/Table.php#L87-L116
train
mako-framework/framework
src/mako/cli/output/helpers/Table.php
Table.buildRowSeparator
protected function buildRowSeparator(array $columnWidths, string $separator = '-'): string { $columns = count($columnWidths); return str_repeat($separator, array_sum($columnWidths) + (($columns * 4) - ($columns - 1))) . PHP_EOL; }
php
protected function buildRowSeparator(array $columnWidths, string $separator = '-'): string { $columns = count($columnWidths); return str_repeat($separator, array_sum($columnWidths) + (($columns * 4) - ($columns - 1))) . PHP_EOL; }
[ "protected", "function", "buildRowSeparator", "(", "array", "$", "columnWidths", ",", "string", "$", "separator", "=", "'-'", ")", ":", "string", "{", "$", "columns", "=", "count", "(", "$", "columnWidths", ")", ";", "return", "str_repeat", "(", "$", "sepa...
Builds a row separator. @param array $columnWidths Array of column widths @param string $separator Separator character @return string
[ "Builds", "a", "row", "separator", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cli/output/helpers/Table.php#L125-L130
train
mako-framework/framework
src/mako/cli/output/helpers/Table.php
Table.buildTableRow
protected function buildTableRow(array $colums, array $columnWidths): string { $cells = []; foreach(array_values($colums) as $key => $value) { $cells[] = $value . str_repeat(' ', $columnWidths[$key] - $this->stringWidthWithoutFormatting($value)); } return '| ' . implode(' | ', $cells) . ' |' . PHP_EOL; }
php
protected function buildTableRow(array $colums, array $columnWidths): string { $cells = []; foreach(array_values($colums) as $key => $value) { $cells[] = $value . str_repeat(' ', $columnWidths[$key] - $this->stringWidthWithoutFormatting($value)); } return '| ' . implode(' | ', $cells) . ' |' . PHP_EOL; }
[ "protected", "function", "buildTableRow", "(", "array", "$", "colums", ",", "array", "$", "columnWidths", ")", ":", "string", "{", "$", "cells", "=", "[", "]", ";", "foreach", "(", "array_values", "(", "$", "colums", ")", "as", "$", "key", "=>", "$", ...
Builds a table row. @param array $colums Array of column values @param array $columnWidths Array of column widths @return string
[ "Builds", "a", "table", "row", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cli/output/helpers/Table.php#L139-L149
train
mako-framework/framework
src/mako/gatekeeper/entities/group/Group.php
Group.addUser
public function addUser(User $user): bool { if(!$this->isPersisted) { throw new LogicException('You can only add a user to a group that exist in the database.'); } if(!$user->isPersisted()) { throw new LogicException('You can only add a user that exist in the database to a group.'); } return $this->users()->link($user); }
php
public function addUser(User $user): bool { if(!$this->isPersisted) { throw new LogicException('You can only add a user to a group that exist in the database.'); } if(!$user->isPersisted()) { throw new LogicException('You can only add a user that exist in the database to a group.'); } return $this->users()->link($user); }
[ "public", "function", "addUser", "(", "User", "$", "user", ")", ":", "bool", "{", "if", "(", "!", "$", "this", "->", "isPersisted", ")", "{", "throw", "new", "LogicException", "(", "'You can only add a user to a group that exist in the database.'", ")", ";", "}"...
Adds a user to the group. @param \mako\gatekeeper\entities\user\User $user User @throws \LogicException @return bool
[ "Adds", "a", "user", "to", "the", "group", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/entities/group/Group.php#L82-L95
train
mako-framework/framework
src/mako/gatekeeper/entities/group/Group.php
Group.removeUser
public function removeUser(User $user): bool { if(!$this->isPersisted) { throw new LogicException('You can only remove a user from a group that exist in the database.'); } if(!$user->isPersisted()) { throw new LogicException('You can only remove a user that exist in the database from a group.'); } return $this->users()->unlink($user); }
php
public function removeUser(User $user): bool { if(!$this->isPersisted) { throw new LogicException('You can only remove a user from a group that exist in the database.'); } if(!$user->isPersisted()) { throw new LogicException('You can only remove a user that exist in the database from a group.'); } return $this->users()->unlink($user); }
[ "public", "function", "removeUser", "(", "User", "$", "user", ")", ":", "bool", "{", "if", "(", "!", "$", "this", "->", "isPersisted", ")", "{", "throw", "new", "LogicException", "(", "'You can only remove a user from a group that exist in the database.'", ")", ";...
Removes a user from the group. @param \mako\gatekeeper\entities\user\User $user User @throws \LogicException @return bool
[ "Removes", "a", "user", "from", "the", "group", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/entities/group/Group.php#L104-L117
train
mako-framework/framework
src/mako/gatekeeper/entities/group/Group.php
Group.isMember
public function isMember(User $user) { if(!$this->isPersisted) { throw new LogicException('You can only check if a user is a member of a group that exist in the database.'); } if(!$user->isPersisted()) { throw new LogicException('You can only check if a user that exist in the database is a member of a group.'); } return $this->users()->where($user->getPrimaryKey(), '=', $user->getPrimaryKeyValue())->count() > 0; }
php
public function isMember(User $user) { if(!$this->isPersisted) { throw new LogicException('You can only check if a user is a member of a group that exist in the database.'); } if(!$user->isPersisted()) { throw new LogicException('You can only check if a user that exist in the database is a member of a group.'); } return $this->users()->where($user->getPrimaryKey(), '=', $user->getPrimaryKeyValue())->count() > 0; }
[ "public", "function", "isMember", "(", "User", "$", "user", ")", "{", "if", "(", "!", "$", "this", "->", "isPersisted", ")", "{", "throw", "new", "LogicException", "(", "'You can only check if a user is a member of a group that exist in the database.'", ")", ";", "}...
Returns TRUE if a user is a member of the group and FALSE if not. @param \mako\gatekeeper\entities\user\User $user User @throws \LogicException @return bool
[ "Returns", "TRUE", "if", "a", "user", "is", "a", "member", "of", "the", "group", "and", "FALSE", "if", "not", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/entities/group/Group.php#L126-L139
train
mako-framework/framework
src/mako/cli/output/helpers/UnorderedList.php
UnorderedList.buildList
protected function buildList(array $items, string $marker, int $nestingLevel = 0): string { $list = ''; foreach($items as $item) { if(is_array($item)) { $list .= $this->buildList($item, $marker, $nestingLevel + 1); } else { $list .= $this->buildListItem($item, $marker, $nestingLevel); } } return $list; }
php
protected function buildList(array $items, string $marker, int $nestingLevel = 0): string { $list = ''; foreach($items as $item) { if(is_array($item)) { $list .= $this->buildList($item, $marker, $nestingLevel + 1); } else { $list .= $this->buildListItem($item, $marker, $nestingLevel); } } return $list; }
[ "protected", "function", "buildList", "(", "array", "$", "items", ",", "string", "$", "marker", ",", "int", "$", "nestingLevel", "=", "0", ")", ":", "string", "{", "$", "list", "=", "''", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "...
Builds an unordered list. @param array $items Items @param string $marker Item marker @param int $nestingLevel Nesting level @return string
[ "Builds", "an", "unordered", "list", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cli/output/helpers/UnorderedList.php#L67-L84
train
mako-framework/framework
src/mako/application/cli/commands/cache/Command.php
Command.checkConfigurationExistence
protected function checkConfigurationExistence(string $configuration): bool { $configurations = array_keys($this->config->get('cache.configurations')); if(!in_array($configuration, $configurations)) { $message = 'The [ ' . $configuration . ' ] configuration does not exist.'; if(($suggestion = $this->suggest($configuration, $configurations)) !== null) { $message .= ' Did you mean [ ' . $suggestion . ' ]?'; } $this->error($message); return false; } return true; }
php
protected function checkConfigurationExistence(string $configuration): bool { $configurations = array_keys($this->config->get('cache.configurations')); if(!in_array($configuration, $configurations)) { $message = 'The [ ' . $configuration . ' ] configuration does not exist.'; if(($suggestion = $this->suggest($configuration, $configurations)) !== null) { $message .= ' Did you mean [ ' . $suggestion . ' ]?'; } $this->error($message); return false; } return true; }
[ "protected", "function", "checkConfigurationExistence", "(", "string", "$", "configuration", ")", ":", "bool", "{", "$", "configurations", "=", "array_keys", "(", "$", "this", "->", "config", "->", "get", "(", "'cache.configurations'", ")", ")", ";", "if", "("...
Checks if the configuration exists. @param string $configuration Configuration name @return bool
[ "Checks", "if", "the", "configuration", "exists", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/commands/cache/Command.php#L55-L74
train
mako-framework/framework
src/mako/pixl/processors/GD.php
GD.getImageInfo
protected function getImageInfo($file) { $imageInfo = getimagesize($file); if($imageInfo === false) { throw new RuntimeException(vsprintf('Unable to process the image [ %s ].', [$file])); } return $imageInfo; }
php
protected function getImageInfo($file) { $imageInfo = getimagesize($file); if($imageInfo === false) { throw new RuntimeException(vsprintf('Unable to process the image [ %s ].', [$file])); } return $imageInfo; }
[ "protected", "function", "getImageInfo", "(", "$", "file", ")", "{", "$", "imageInfo", "=", "getimagesize", "(", "$", "file", ")", ";", "if", "(", "$", "imageInfo", "===", "false", ")", "{", "throw", "new", "RuntimeException", "(", "vsprintf", "(", "'Una...
Collects information about the image. @param string $file Path to image file @throws \RuntimeException @return resource
[ "Collects", "information", "about", "the", "image", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/pixl/processors/GD.php#L129-L139
train
mako-framework/framework
src/mako/pixl/processors/GD.php
GD.createImageResource
protected function createImageResource($image, $imageInfo) { switch($imageInfo[2]) { case IMAGETYPE_JPEG: return imagecreatefromjpeg($image); break; case IMAGETYPE_GIF: return imagecreatefromgif($image); break; case IMAGETYPE_PNG: return imagecreatefrompng($image); break; default: throw new RuntimeException(vsprintf('Unable to open [ %s ]. Unsupported image type.', [pathinfo($image, PATHINFO_EXTENSION)])); } }
php
protected function createImageResource($image, $imageInfo) { switch($imageInfo[2]) { case IMAGETYPE_JPEG: return imagecreatefromjpeg($image); break; case IMAGETYPE_GIF: return imagecreatefromgif($image); break; case IMAGETYPE_PNG: return imagecreatefrompng($image); break; default: throw new RuntimeException(vsprintf('Unable to open [ %s ]. Unsupported image type.', [pathinfo($image, PATHINFO_EXTENSION)])); } }
[ "protected", "function", "createImageResource", "(", "$", "image", ",", "$", "imageInfo", ")", "{", "switch", "(", "$", "imageInfo", "[", "2", "]", ")", "{", "case", "IMAGETYPE_JPEG", ":", "return", "imagecreatefromjpeg", "(", "$", "image", ")", ";", "brea...
Creates an image resource that we can work with. @param string $image Path to image file @param array $imageInfo Image info @throws \RuntimeException @return resource
[ "Creates", "an", "image", "resource", "that", "we", "can", "work", "with", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/pixl/processors/GD.php#L149-L165
train
mako-framework/framework
src/mako/pixl/processors/GD.php
GD.hexToRgb
protected function hexToRgb($hex) { $hex = str_replace('#', '', $hex); if(preg_match('/^([a-f0-9]{3}){1,2}$/i', $hex) === 0) { throw new InvalidArgumentException(vsprintf('Invalid HEX value [ %s ].', [$hex])); } if(strlen($hex) === 3) { $r = hexdec(str_repeat(substr($hex, 0, 1), 2)); $g = hexdec(str_repeat(substr($hex, 1, 1), 2)); $b = hexdec(str_repeat(substr($hex, 2, 1), 2)); } else { $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); } return ['r' => $r, 'g' => $g, 'b' => $b]; }
php
protected function hexToRgb($hex) { $hex = str_replace('#', '', $hex); if(preg_match('/^([a-f0-9]{3}){1,2}$/i', $hex) === 0) { throw new InvalidArgumentException(vsprintf('Invalid HEX value [ %s ].', [$hex])); } if(strlen($hex) === 3) { $r = hexdec(str_repeat(substr($hex, 0, 1), 2)); $g = hexdec(str_repeat(substr($hex, 1, 1), 2)); $b = hexdec(str_repeat(substr($hex, 2, 1), 2)); } else { $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); } return ['r' => $r, 'g' => $g, 'b' => $b]; }
[ "protected", "function", "hexToRgb", "(", "$", "hex", ")", "{", "$", "hex", "=", "str_replace", "(", "'#'", ",", "''", ",", "$", "hex", ")", ";", "if", "(", "preg_match", "(", "'/^([a-f0-9]{3}){1,2}$/i'", ",", "$", "hex", ")", "===", "0", ")", "{", ...
Converts HEX value to an RGB array. @param string $hex HEX value @throws \InvalidArgumentException @return array
[ "Converts", "HEX", "value", "to", "an", "RGB", "array", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/pixl/processors/GD.php#L174-L197
train
mako-framework/framework
src/mako/redis/Connection.php
Connection.createConnection
protected function createConnection(string $host, int $port, bool $persistent, int $timeout) { try { if($persistent) { return pfsockopen('tcp://' . $host, $port, $errNo, $errStr, $timeout); } return fsockopen('tcp://' . $host, $port, $errNo, $errStr, $timeout); } catch(Throwable $e) { $message = $this->name === null ? 'Failed to connect' : vsprintf('Failed to connect to [ %s ]', [$this->name]); throw new RedisException(vsprintf('%s. %s', [$message, $e->getMessage()]), (int) $errNo); } }
php
protected function createConnection(string $host, int $port, bool $persistent, int $timeout) { try { if($persistent) { return pfsockopen('tcp://' . $host, $port, $errNo, $errStr, $timeout); } return fsockopen('tcp://' . $host, $port, $errNo, $errStr, $timeout); } catch(Throwable $e) { $message = $this->name === null ? 'Failed to connect' : vsprintf('Failed to connect to [ %s ]', [$this->name]); throw new RedisException(vsprintf('%s. %s', [$message, $e->getMessage()]), (int) $errNo); } }
[ "protected", "function", "createConnection", "(", "string", "$", "host", ",", "int", "$", "port", ",", "bool", "$", "persistent", ",", "int", "$", "timeout", ")", "{", "try", "{", "if", "(", "$", "persistent", ")", "{", "return", "pfsockopen", "(", "'t...
Creates a socket connection to the server. @param string $host Redis host @param int $port Redis port @param bool $persistent Should the connection be persistent? @param int $timeout Timeout in seconds @throws \mako\redis\RedisException @return resource
[ "Creates", "a", "socket", "connection", "to", "the", "server", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/redis/Connection.php#L110-L127
train
mako-framework/framework
src/mako/redis/Connection.php
Connection.readLine
public function readLine(): string { $line = fgets($this->connection); if($line === false || $line === '') { throw new RedisException($this->appendReadErrorReason('Failed to read line from the server.')); } return $line; }
php
public function readLine(): string { $line = fgets($this->connection); if($line === false || $line === '') { throw new RedisException($this->appendReadErrorReason('Failed to read line from the server.')); } return $line; }
[ "public", "function", "readLine", "(", ")", ":", "string", "{", "$", "line", "=", "fgets", "(", "$", "this", "->", "connection", ")", ";", "if", "(", "$", "line", "===", "false", "||", "$", "line", "===", "''", ")", "{", "throw", "new", "RedisExcep...
Gets line from the server. @throws \mako\redis\RedisException @return string
[ "Gets", "line", "from", "the", "server", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/redis/Connection.php#L181-L191
train
mako-framework/framework
src/mako/redis/Connection.php
Connection.read
public function read(int $bytes): string { $bytesLeft = $bytes; $data = ''; do { $chunk = fread($this->connection, min($bytesLeft, 4096)); if($chunk === false || $chunk === '') { throw new RedisException($this->appendReadErrorReason('Failed to read data from the server.')); } $data .= $chunk; $bytesLeft = $bytes - strlen($data); } while($bytesLeft > 0); return $data; }
php
public function read(int $bytes): string { $bytesLeft = $bytes; $data = ''; do { $chunk = fread($this->connection, min($bytesLeft, 4096)); if($chunk === false || $chunk === '') { throw new RedisException($this->appendReadErrorReason('Failed to read data from the server.')); } $data .= $chunk; $bytesLeft = $bytes - strlen($data); } while($bytesLeft > 0); return $data; }
[ "public", "function", "read", "(", "int", "$", "bytes", ")", ":", "string", "{", "$", "bytesLeft", "=", "$", "bytes", ";", "$", "data", "=", "''", ";", "do", "{", "$", "chunk", "=", "fread", "(", "$", "this", "->", "connection", ",", "min", "(", ...
Reads n bytes from the server. @param int $bytes Number of bytes to read @throws \mako\redis\RedisException @return string
[ "Reads", "n", "bytes", "from", "the", "server", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/redis/Connection.php#L200-L222
train
mako-framework/framework
src/mako/redis/Connection.php
Connection.write
public function write(string $data): int { $totalBytesWritten = 0; $bytesLeft = strlen($data); do { $totalBytesWritten += $bytesWritten = fwrite($this->connection, $data); if($bytesWritten === false || $bytesWritten === 0) { throw new RedisException('Failed to write data to the server.'); } $bytesLeft -= $bytesWritten; $data = substr($data, $bytesWritten); } while($bytesLeft > 0); return $totalBytesWritten; }
php
public function write(string $data): int { $totalBytesWritten = 0; $bytesLeft = strlen($data); do { $totalBytesWritten += $bytesWritten = fwrite($this->connection, $data); if($bytesWritten === false || $bytesWritten === 0) { throw new RedisException('Failed to write data to the server.'); } $bytesLeft -= $bytesWritten; $data = substr($data, $bytesWritten); } while($bytesLeft > 0); return $totalBytesWritten; }
[ "public", "function", "write", "(", "string", "$", "data", ")", ":", "int", "{", "$", "totalBytesWritten", "=", "0", ";", "$", "bytesLeft", "=", "strlen", "(", "$", "data", ")", ";", "do", "{", "$", "totalBytesWritten", "+=", "$", "bytesWritten", "=", ...
Writes data to the server. @param string $data Data to write @throws \mako\redis\RedisException @return int
[ "Writes", "data", "to", "the", "server", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/redis/Connection.php#L231-L253
train
mako-framework/framework
src/mako/reactor/traits/SuggestionTrait.php
SuggestionTrait.suggest
protected function suggest(string $string, array $alternatives): ?string { $suggestion = false; foreach($alternatives as $alternative) { similar_text($string, $alternative, $similarity); if($similarity > 66 && ($suggestion === false || $suggestion['similarity'] < $similarity)) { $suggestion = ['string' => $alternative, 'similarity' => $similarity]; } } return $suggestion === false ? null : $suggestion['string']; }
php
protected function suggest(string $string, array $alternatives): ?string { $suggestion = false; foreach($alternatives as $alternative) { similar_text($string, $alternative, $similarity); if($similarity > 66 && ($suggestion === false || $suggestion['similarity'] < $similarity)) { $suggestion = ['string' => $alternative, 'similarity' => $similarity]; } } return $suggestion === false ? null : $suggestion['string']; }
[ "protected", "function", "suggest", "(", "string", "$", "string", ",", "array", "$", "alternatives", ")", ":", "?", "string", "{", "$", "suggestion", "=", "false", ";", "foreach", "(", "$", "alternatives", "as", "$", "alternative", ")", "{", "similar_text"...
Returns the string that resembles the provided string the most. NULL is returned if no string with a similarity of 66% or more is found. @param string $string String @param array $alternatives Alternatives @return string|null
[ "Returns", "the", "string", "that", "resembles", "the", "provided", "string", "the", "most", ".", "NULL", "is", "returned", "if", "no", "string", "with", "a", "similarity", "of", "66%", "or", "more", "is", "found", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/traits/SuggestionTrait.php#L27-L42
train
mako-framework/framework
src/mako/cli/output/helpers/traits/HelperTrait.php
HelperTrait.stringWidthWithoutFormatting
protected function stringWidthWithoutFormatting(string $string): int { return (int) mb_strwidth($this->formatter !== null ? $this->formatter->stripTags($string) : $string); }
php
protected function stringWidthWithoutFormatting(string $string): int { return (int) mb_strwidth($this->formatter !== null ? $this->formatter->stripTags($string) : $string); }
[ "protected", "function", "stringWidthWithoutFormatting", "(", "string", "$", "string", ")", ":", "int", "{", "return", "(", "int", ")", "mb_strwidth", "(", "$", "this", "->", "formatter", "!==", "null", "?", "$", "this", "->", "formatter", "->", "stripTags",...
Returns the width of the string without formatting. @param string $string String to strip @return int
[ "Returns", "the", "width", "of", "the", "string", "without", "formatting", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cli/output/helpers/traits/HelperTrait.php#L25-L28
train
mako-framework/framework
src/mako/gatekeeper/authorization/traits/AuthorizableTrait.php
AuthorizableTrait.can
public function can(string $action, $entity): bool { return $this->authorizer->can($this, $action, $entity); }
php
public function can(string $action, $entity): bool { return $this->authorizer->can($this, $action, $entity); }
[ "public", "function", "can", "(", "string", "$", "action", ",", "$", "entity", ")", ":", "bool", "{", "return", "$", "this", "->", "authorizer", "->", "can", "(", "$", "this", ",", "$", "action", ",", "$", "entity", ")", ";", "}" ]
Returns true if allowed to perform the action on the entity and false if not. @param string $action Action @param object|string $entity Entity @return bool
[ "Returns", "true", "if", "allowed", "to", "perform", "the", "action", "on", "the", "entity", "and", "false", "if", "not", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/authorization/traits/AuthorizableTrait.php#L44-L47
train
mako-framework/framework
src/mako/database/query/Join.php
Join.on
public function on($column1, ?string $operator = null, $column2 = null, string $separator = 'AND'): Join { if($column1 instanceof Closure) { $join = new self; $column1($join); $this->conditions[] = [ 'type' => 'nestedJoinCondition', 'join' => $join, 'separator' => $separator, ]; } else { $this->conditions[] = [ 'type' => 'joinCondition', 'column1' => $column1, 'operator' => $operator, 'column2' => $column2, 'separator' => $separator, ]; } return $this; }
php
public function on($column1, ?string $operator = null, $column2 = null, string $separator = 'AND'): Join { if($column1 instanceof Closure) { $join = new self; $column1($join); $this->conditions[] = [ 'type' => 'nestedJoinCondition', 'join' => $join, 'separator' => $separator, ]; } else { $this->conditions[] = [ 'type' => 'joinCondition', 'column1' => $column1, 'operator' => $operator, 'column2' => $column2, 'separator' => $separator, ]; } return $this; }
[ "public", "function", "on", "(", "$", "column1", ",", "?", "string", "$", "operator", "=", "null", ",", "$", "column2", "=", "null", ",", "string", "$", "separator", "=", "'AND'", ")", ":", "Join", "{", "if", "(", "$", "column1", "instanceof", "Closu...
Adds a ON condition to the join. @param string $column1 Column name @param string|null $operator Operator @param string|\mako\database\query\Raw||null $column2 Column name @param string $separator Condition separator @return \mako\database\query\Join
[ "Adds", "a", "ON", "condition", "to", "the", "join", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/query/Join.php#L91-L119
train
mako-framework/framework
src/mako/database/query/Join.php
Join.onRaw
public function onRaw($column1, string $operator, string $raw, string $separator = 'AND'): Join { return $this->on($column1, $operator, new Raw($raw), $separator); }
php
public function onRaw($column1, string $operator, string $raw, string $separator = 'AND'): Join { return $this->on($column1, $operator, new Raw($raw), $separator); }
[ "public", "function", "onRaw", "(", "$", "column1", ",", "string", "$", "operator", ",", "string", "$", "raw", ",", "string", "$", "separator", "=", "'AND'", ")", ":", "Join", "{", "return", "$", "this", "->", "on", "(", "$", "column1", ",", "$", "...
Adds a raw ON condition to the join. @param string $column1 Column name @param string $operator Operator @param string $raw Raw SQL @param string $separator Condition separator @return \mako\database\query\Join
[ "Adds", "a", "raw", "ON", "condition", "to", "the", "join", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/query/Join.php#L130-L133
train
mako-framework/framework
src/mako/database/query/Join.php
Join.orOn
public function orOn($column1, ?string $operator = null, $column2 = null): Join { return $this->on($column1, $operator, $column2, 'OR'); }
php
public function orOn($column1, ?string $operator = null, $column2 = null): Join { return $this->on($column1, $operator, $column2, 'OR'); }
[ "public", "function", "orOn", "(", "$", "column1", ",", "?", "string", "$", "operator", "=", "null", ",", "$", "column2", "=", "null", ")", ":", "Join", "{", "return", "$", "this", "->", "on", "(", "$", "column1", ",", "$", "operator", ",", "$", ...
Adds a OR ON condition to the join. @param string $column1 Column name @param string|null $operator Operator @param string|mako\database\query\Raw||null $column2 Column name @return \mako\database\query\Join
[ "Adds", "a", "OR", "ON", "condition", "to", "the", "join", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/query/Join.php#L143-L146
train
mako-framework/framework
src/mako/database/query/Join.php
Join.orOnRaw
public function orOnRaw($column1, string $operator, string $raw): Join { return $this->onRaw($column1, $operator, $raw, 'OR'); }
php
public function orOnRaw($column1, string $operator, string $raw): Join { return $this->onRaw($column1, $operator, $raw, 'OR'); }
[ "public", "function", "orOnRaw", "(", "$", "column1", ",", "string", "$", "operator", ",", "string", "$", "raw", ")", ":", "Join", "{", "return", "$", "this", "->", "onRaw", "(", "$", "column1", ",", "$", "operator", ",", "$", "raw", ",", "'OR'", "...
Adds a raw OR ON condition to the join. @param string $column1 Column name @param string $operator Operator @param string $raw Raw SQL @return \mako\database\query\Join
[ "Adds", "a", "raw", "OR", "ON", "condition", "to", "the", "join", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/query/Join.php#L156-L159
train
mako-framework/framework
src/mako/event/Event.php
Event.override
public function override(string $name, $handler): void { $this->clear($name); $this->register($name, $handler); }
php
public function override(string $name, $handler): void { $this->clear($name); $this->register($name, $handler); }
[ "public", "function", "override", "(", "string", "$", "name", ",", "$", "handler", ")", ":", "void", "{", "$", "this", "->", "clear", "(", "$", "name", ")", ";", "$", "this", "->", "register", "(", "$", "name", ",", "$", "handler", ")", ";", "}" ...
Overrides an event. @param string $name Event name @param string|\Closure $handler Event handler
[ "Overrides", "an", "event", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/event/Event.php#L94-L99
train
mako-framework/framework
src/mako/event/Event.php
Event.executeHandler
protected function executeHandler($handler, array $parameters) { if($handler instanceof Closure) { return $this->executeClosureHandler($handler, $parameters); } $handler = $this->resolveHandler($handler); return $this->executeClassHandler($handler, $parameters); }
php
protected function executeHandler($handler, array $parameters) { if($handler instanceof Closure) { return $this->executeClosureHandler($handler, $parameters); } $handler = $this->resolveHandler($handler); return $this->executeClassHandler($handler, $parameters); }
[ "protected", "function", "executeHandler", "(", "$", "handler", ",", "array", "$", "parameters", ")", "{", "if", "(", "$", "handler", "instanceof", "Closure", ")", "{", "return", "$", "this", "->", "executeClosureHandler", "(", "$", "handler", ",", "$", "p...
Executes the event handler and returns the response. @param string|\Closure $handler Event handler @param array $parameters Parameters @return mixed
[ "Executes", "the", "event", "handler", "and", "returns", "the", "response", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/event/Event.php#L143-L153
train
mako-framework/framework
src/mako/event/Event.php
Event.trigger
public function trigger(string $name, array $parameters = [], bool $break = false): array { $returnValues = []; if(isset($this->events[$name])) { foreach($this->events[$name] as $handler) { $returnValues[] = $last = $this->executeHandler($handler, $parameters); if($break && $last === false) { break; } } } return $returnValues; }
php
public function trigger(string $name, array $parameters = [], bool $break = false): array { $returnValues = []; if(isset($this->events[$name])) { foreach($this->events[$name] as $handler) { $returnValues[] = $last = $this->executeHandler($handler, $parameters); if($break && $last === false) { break; } } } return $returnValues; }
[ "public", "function", "trigger", "(", "string", "$", "name", ",", "array", "$", "parameters", "=", "[", "]", ",", "bool", "$", "break", "=", "false", ")", ":", "array", "{", "$", "returnValues", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "...
Runs all closures for an event and returns an array contaning the return values of each event handler. @param string $name Event name @param array $parameters Parameters @param bool $break Break if one of the closures returns false? @return array
[ "Runs", "all", "closures", "for", "an", "event", "and", "returns", "an", "array", "contaning", "the", "return", "values", "of", "each", "event", "handler", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/event/Event.php#L164-L182
train
mako-framework/framework
src/mako/database/ConnectionManager.php
ConnectionManager.normalizeDriverName
protected function normalizeDriverName(string $driver): string { foreach($this->driverAliases as $normalized => $aliases) { if(in_array($driver, $aliases)) { return $normalized; } } return $driver; }
php
protected function normalizeDriverName(string $driver): string { foreach($this->driverAliases as $normalized => $aliases) { if(in_array($driver, $aliases)) { return $normalized; } } return $driver; }
[ "protected", "function", "normalizeDriverName", "(", "string", "$", "driver", ")", ":", "string", "{", "foreach", "(", "$", "this", "->", "driverAliases", "as", "$", "normalized", "=>", "$", "aliases", ")", "{", "if", "(", "in_array", "(", "$", "driver", ...
Returns the normalized driver name. @param string $driver Driver name @return string
[ "Returns", "the", "normalized", "driver", "name", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/ConnectionManager.php#L105-L116
train
mako-framework/framework
src/mako/database/ConnectionManager.php
ConnectionManager.connect
protected function connect(string $connectionName): Connection { if(!isset($this->configurations[$connectionName])) { throw new RuntimeException(vsprintf('[ %s ] has not been defined in the database configuration.', [$connectionName])); } $config = $this->configurations[$connectionName]; $driver = $this->normalizeDriverName(explode(':', $config['dsn'], 2)[0]); $compiler = $this->getQueryCompilerClass($driver); $helper = $this->getQueryBuilderHelperClass($driver); $connection = $this->getConnectionClass($driver); return new $connection($connectionName, $compiler, $helper, $config); }
php
protected function connect(string $connectionName): Connection { if(!isset($this->configurations[$connectionName])) { throw new RuntimeException(vsprintf('[ %s ] has not been defined in the database configuration.', [$connectionName])); } $config = $this->configurations[$connectionName]; $driver = $this->normalizeDriverName(explode(':', $config['dsn'], 2)[0]); $compiler = $this->getQueryCompilerClass($driver); $helper = $this->getQueryBuilderHelperClass($driver); $connection = $this->getConnectionClass($driver); return new $connection($connectionName, $compiler, $helper, $config); }
[ "protected", "function", "connect", "(", "string", "$", "connectionName", ")", ":", "Connection", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "configurations", "[", "$", "connectionName", "]", ")", ")", "{", "throw", "new", "RuntimeException", "(...
Connects to the chosen database and returns the connection. @param string $connectionName Connection name @throws \RuntimeException @return \mako\database\connections\Connection
[ "Connects", "to", "the", "chosen", "database", "and", "returns", "the", "connection", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/ConnectionManager.php#L202-L220
train
mako-framework/framework
src/mako/database/ConnectionManager.php
ConnectionManager.getLogs
public function getLogs(bool $groupedByConnection = true): array { $logs = []; if($groupedByConnection) { foreach($this->connections as $connection) { $logs[$connection->getName()] = $connection->getLog(); } } else { foreach($this->connections as $connection) { $logs = array_merge($logs, $connection->getLog()); } } return $logs; }
php
public function getLogs(bool $groupedByConnection = true): array { $logs = []; if($groupedByConnection) { foreach($this->connections as $connection) { $logs[$connection->getName()] = $connection->getLog(); } } else { foreach($this->connections as $connection) { $logs = array_merge($logs, $connection->getLog()); } } return $logs; }
[ "public", "function", "getLogs", "(", "bool", "$", "groupedByConnection", "=", "true", ")", ":", "array", "{", "$", "logs", "=", "[", "]", ";", "if", "(", "$", "groupedByConnection", ")", "{", "foreach", "(", "$", "this", "->", "connections", "as", "$"...
Returns the query log for all connections. @param bool $groupedByConnection Group logs by connection? @return array
[ "Returns", "the", "query", "log", "for", "all", "connections", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/ConnectionManager.php#L239-L259
train
mako-framework/framework
src/mako/cli/Environment.php
Environment.getDimensionsForUnixLike
protected function getDimensionsForUnixLike(): ?array { // Attempt to get dimensions from environment if(($width = getenv('COLUMNS')) !== false && ($height = getenv('LINES')) !== false) { return ['width' => (int) $width, 'height' => (int) $height]; } // Attempt to get dimensions from stty exec('stty size', $output, $status); if($status === 0 && preg_match('/^([0-9]+) ([0-9]+)$/', current($output), $matches)) { return ['width' => (int) $matches[2], 'height' => (int) $matches[1]]; } // All attempts failed so we'll just return null return null; }
php
protected function getDimensionsForUnixLike(): ?array { // Attempt to get dimensions from environment if(($width = getenv('COLUMNS')) !== false && ($height = getenv('LINES')) !== false) { return ['width' => (int) $width, 'height' => (int) $height]; } // Attempt to get dimensions from stty exec('stty size', $output, $status); if($status === 0 && preg_match('/^([0-9]+) ([0-9]+)$/', current($output), $matches)) { return ['width' => (int) $matches[2], 'height' => (int) $matches[1]]; } // All attempts failed so we'll just return null return null; }
[ "protected", "function", "getDimensionsForUnixLike", "(", ")", ":", "?", "array", "{", "// Attempt to get dimensions from environment", "if", "(", "(", "$", "width", "=", "getenv", "(", "'COLUMNS'", ")", ")", "!==", "false", "&&", "(", "$", "height", "=", "get...
Attempts to get dimensions for Unix-like platforms. @return array|null
[ "Attempts", "to", "get", "dimensions", "for", "Unix", "-", "like", "platforms", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cli/Environment.php#L58-L79
train
mako-framework/framework
src/mako/cli/Environment.php
Environment.hasAnsiSupport
public function hasAnsiSupport(): bool { if($this->hasAnsiSupport === null) { $this->hasAnsiSupport = PHP_OS_FAMILY !== 'Windows' || (getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON'); } return $this->hasAnsiSupport; }
php
public function hasAnsiSupport(): bool { if($this->hasAnsiSupport === null) { $this->hasAnsiSupport = PHP_OS_FAMILY !== 'Windows' || (getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON'); } return $this->hasAnsiSupport; }
[ "public", "function", "hasAnsiSupport", "(", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "hasAnsiSupport", "===", "null", ")", "{", "$", "this", "->", "hasAnsiSupport", "=", "PHP_OS_FAMILY", "!==", "'Windows'", "||", "(", "getenv", "(", "'ANSICON'...
Do we have ANSI support? @return bool
[ "Do", "we", "have", "ANSI", "support?" ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cli/Environment.php#L118-L126
train
mako-framework/framework
src/mako/reactor/Dispatcher.php
Dispatcher.checkForInvalidArguments
protected function checkForInvalidArguments(CommandInterface $command, array $providedArguments, array $globalOptions): void { $commandArguments = array_keys($command->getCommandArguments() + $command->getCommandOptions()); $defaultAndGlobalOptions = array_merge(['arg0', 'arg1'], $globalOptions); foreach(array_keys($providedArguments) as $name) { if(!in_array($name, $defaultAndGlobalOptions) && !in_array($name, $commandArguments)) { if(strpos($name, 'arg') === 0) { throw new InvalidArgumentException(vsprintf('Invalid argument [ %s ].', [$name]), $name); } throw new InvalidOptionException(vsprintf('Invalid option [ %s ].', [$name]), $name, $this->suggest($name, $commandArguments)); } } }
php
protected function checkForInvalidArguments(CommandInterface $command, array $providedArguments, array $globalOptions): void { $commandArguments = array_keys($command->getCommandArguments() + $command->getCommandOptions()); $defaultAndGlobalOptions = array_merge(['arg0', 'arg1'], $globalOptions); foreach(array_keys($providedArguments) as $name) { if(!in_array($name, $defaultAndGlobalOptions) && !in_array($name, $commandArguments)) { if(strpos($name, 'arg') === 0) { throw new InvalidArgumentException(vsprintf('Invalid argument [ %s ].', [$name]), $name); } throw new InvalidOptionException(vsprintf('Invalid option [ %s ].', [$name]), $name, $this->suggest($name, $commandArguments)); } } }
[ "protected", "function", "checkForInvalidArguments", "(", "CommandInterface", "$", "command", ",", "array", "$", "providedArguments", ",", "array", "$", "globalOptions", ")", ":", "void", "{", "$", "commandArguments", "=", "array_keys", "(", "$", "command", "->", ...
Checks for invalid arguments or options. @param \mako\reactor\CommandInterface $command Command arguments @param array $providedArguments Provided arguments @param array $globalOptions Global options @throws \mako\reactor\exceptions\InvalidArgumentException @throws \mako\reactor\exceptions\InvalidOptionException
[ "Checks", "for", "invalid", "arguments", "or", "options", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/Dispatcher.php#L75-L93
train
mako-framework/framework
src/mako/reactor/Dispatcher.php
Dispatcher.checkForMissingArgumentsOrOptions
protected function checkForMissingArgumentsOrOptions(array $commandArguments, array $providedArguments, string $exception): void { $providedArguments = array_keys($providedArguments); foreach($commandArguments as $name => $details) { if(isset($details['optional']) && $details['optional'] === false && !in_array($name, $providedArguments)) { $type = $exception === MissingArgumentException::class ? 'argument' : 'option'; throw new $exception(vsprintf('Missing required %s [ %s ].', [$type, $name]), $name); } } }
php
protected function checkForMissingArgumentsOrOptions(array $commandArguments, array $providedArguments, string $exception): void { $providedArguments = array_keys($providedArguments); foreach($commandArguments as $name => $details) { if(isset($details['optional']) && $details['optional'] === false && !in_array($name, $providedArguments)) { $type = $exception === MissingArgumentException::class ? 'argument' : 'option'; throw new $exception(vsprintf('Missing required %s [ %s ].', [$type, $name]), $name); } } }
[ "protected", "function", "checkForMissingArgumentsOrOptions", "(", "array", "$", "commandArguments", ",", "array", "$", "providedArguments", ",", "string", "$", "exception", ")", ":", "void", "{", "$", "providedArguments", "=", "array_keys", "(", "$", "providedArgum...
Checks for missing required arguments or options. @param array $commandArguments Command arguments @param array $providedArguments Provided arguments @param string $exception Exception to throw @throws \mako\reactor\exceptions\ArgumentException
[ "Checks", "for", "missing", "required", "arguments", "or", "options", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/Dispatcher.php#L103-L116
train
mako-framework/framework
src/mako/reactor/Dispatcher.php
Dispatcher.checkForMissingArguments
protected function checkForMissingArguments(CommandInterface $command, array $providedArguments): void { $this->checkForMissingArgumentsOrOptions($command->getCommandArguments(), $providedArguments, MissingArgumentException::class); }
php
protected function checkForMissingArguments(CommandInterface $command, array $providedArguments): void { $this->checkForMissingArgumentsOrOptions($command->getCommandArguments(), $providedArguments, MissingArgumentException::class); }
[ "protected", "function", "checkForMissingArguments", "(", "CommandInterface", "$", "command", ",", "array", "$", "providedArguments", ")", ":", "void", "{", "$", "this", "->", "checkForMissingArgumentsOrOptions", "(", "$", "command", "->", "getCommandArguments", "(", ...
Checks for missing required arguments. @param \mako\reactor\CommandInterface $command Command instance @param array $providedArguments Provided arguments
[ "Checks", "for", "missing", "required", "arguments", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/Dispatcher.php#L124-L127
train
mako-framework/framework
src/mako/reactor/Dispatcher.php
Dispatcher.checkForMissingOptions
protected function checkForMissingOptions(CommandInterface $command, array $providedArguments): void { $this->checkForMissingArgumentsOrOptions($command->getCommandOptions(), $providedArguments, MissingOptionException::class); }
php
protected function checkForMissingOptions(CommandInterface $command, array $providedArguments): void { $this->checkForMissingArgumentsOrOptions($command->getCommandOptions(), $providedArguments, MissingOptionException::class); }
[ "protected", "function", "checkForMissingOptions", "(", "CommandInterface", "$", "command", ",", "array", "$", "providedArguments", ")", ":", "void", "{", "$", "this", "->", "checkForMissingArgumentsOrOptions", "(", "$", "command", "->", "getCommandOptions", "(", ")...
Checks for missing required options. @param \mako\reactor\CommandInterface $command Command instance @param array $providedArguments Provided arguments
[ "Checks", "for", "missing", "required", "options", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/Dispatcher.php#L135-L138
train
mako-framework/framework
src/mako/reactor/Dispatcher.php
Dispatcher.checkArgumentsAndOptions
protected function checkArgumentsAndOptions(CommandInterface $command, array $providedArguments, array $globalOptions): void { if($command->isStrict()) { $this->checkForInvalidArguments($command, $providedArguments, $globalOptions); } $this->checkForMissingArguments($command, $providedArguments); $this->checkForMissingOptions($command, $providedArguments); }
php
protected function checkArgumentsAndOptions(CommandInterface $command, array $providedArguments, array $globalOptions): void { if($command->isStrict()) { $this->checkForInvalidArguments($command, $providedArguments, $globalOptions); } $this->checkForMissingArguments($command, $providedArguments); $this->checkForMissingOptions($command, $providedArguments); }
[ "protected", "function", "checkArgumentsAndOptions", "(", "CommandInterface", "$", "command", ",", "array", "$", "providedArguments", ",", "array", "$", "globalOptions", ")", ":", "void", "{", "if", "(", "$", "command", "->", "isStrict", "(", ")", ")", "{", ...
Checks arguments and options. @param \mako\reactor\CommandInterface $command Command instance @param array $providedArguments Provided arguments @param array $globalOptions Global options
[ "Checks", "arguments", "and", "options", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/Dispatcher.php#L147-L157
train
mako-framework/framework
src/mako/reactor/Dispatcher.php
Dispatcher.convertArgumentsToCamelCase
protected function convertArgumentsToCamelCase(array $arguments): array { return array_combine(array_map(function($key) { return Str::underscored2camel(str_replace('-', '_', $key)); }, array_keys($arguments)), array_values($arguments)); }
php
protected function convertArgumentsToCamelCase(array $arguments): array { return array_combine(array_map(function($key) { return Str::underscored2camel(str_replace('-', '_', $key)); }, array_keys($arguments)), array_values($arguments)); }
[ "protected", "function", "convertArgumentsToCamelCase", "(", "array", "$", "arguments", ")", ":", "array", "{", "return", "array_combine", "(", "array_map", "(", "function", "(", "$", "key", ")", "{", "return", "Str", "::", "underscored2camel", "(", "str_replace...
Converts arguments to camel case. @param array $arguments Arguments @return array
[ "Converts", "arguments", "to", "camel", "case", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/Dispatcher.php#L165-L171
train
mako-framework/framework
src/mako/reactor/Dispatcher.php
Dispatcher.dispatch
public function dispatch(string $command, array $arguments, array $globalOptions): int { $command = $this->resolve($command); $this->checkArgumentsAndOptions($command, $arguments, $globalOptions); $returnValue = $this->execute($command, $arguments); return is_int($returnValue) ? $returnValue : CommandInterface::STATUS_SUCCESS; }
php
public function dispatch(string $command, array $arguments, array $globalOptions): int { $command = $this->resolve($command); $this->checkArgumentsAndOptions($command, $arguments, $globalOptions); $returnValue = $this->execute($command, $arguments); return is_int($returnValue) ? $returnValue : CommandInterface::STATUS_SUCCESS; }
[ "public", "function", "dispatch", "(", "string", "$", "command", ",", "array", "$", "arguments", ",", "array", "$", "globalOptions", ")", ":", "int", "{", "$", "command", "=", "$", "this", "->", "resolve", "(", "$", "command", ")", ";", "$", "this", ...
Dispatches the command. @param string $command Command class @param array $arguments Command arguments @param array $globalOptions Global options @return int
[ "Dispatches", "the", "command", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/Dispatcher.php#L193-L202
train
mako-framework/framework
src/mako/database/midgard/traits/TimestampedTrait.php
TimestampedTrait.touch
public function touch(): bool { if($this->isPersisted) { $this->columns[$this->getUpdatedAtColumn()] = null; return $this->save(); } return false; }
php
public function touch(): bool { if($this->isPersisted) { $this->columns[$this->getUpdatedAtColumn()] = null; return $this->save(); } return false; }
[ "public", "function", "touch", "(", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "isPersisted", ")", "{", "$", "this", "->", "columns", "[", "$", "this", "->", "getUpdatedAtColumn", "(", ")", "]", "=", "null", ";", "return", "$", "this", "-...
Allows you to update the "updated at" timestamp without modifying any data. @return bool
[ "Allows", "you", "to", "update", "the", "updated", "at", "timestamp", "without", "modifying", "any", "data", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/traits/TimestampedTrait.php#L170-L180
train
mako-framework/framework
src/mako/database/midgard/traits/TimestampedTrait.php
TimestampedTrait.touchRelated
protected function touchRelated(): void { foreach($this->getRelationsToTouch() as $touch) { $touch = explode('.', $touch); $relation = $this->{array_shift($touch)}(); foreach($touch as $nested) { $related = $relation->first(); if($related === false) { continue 2; } $relation = $related->$nested(); } $relation->update([$relation->getModel()->getUpdatedAtColumn() => null]); } }
php
protected function touchRelated(): void { foreach($this->getRelationsToTouch() as $touch) { $touch = explode('.', $touch); $relation = $this->{array_shift($touch)}(); foreach($touch as $nested) { $related = $relation->first(); if($related === false) { continue 2; } $relation = $related->$nested(); } $relation->update([$relation->getModel()->getUpdatedAtColumn() => null]); } }
[ "protected", "function", "touchRelated", "(", ")", ":", "void", "{", "foreach", "(", "$", "this", "->", "getRelationsToTouch", "(", ")", "as", "$", "touch", ")", "{", "$", "touch", "=", "explode", "(", "'.'", ",", "$", "touch", ")", ";", "$", "relati...
Touches related records.
[ "Touches", "related", "records", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/traits/TimestampedTrait.php#L185-L207
train
mako-framework/framework
src/mako/view/ViewFactory.php
ViewFactory.setCharset
public function setCharset(string $charset): ViewFactory { $this->globalVariables['__charset__'] = $this->charset = $charset; return $this; }
php
public function setCharset(string $charset): ViewFactory { $this->globalVariables['__charset__'] = $this->charset = $charset; return $this; }
[ "public", "function", "setCharset", "(", "string", "$", "charset", ")", ":", "ViewFactory", "{", "$", "this", "->", "globalVariables", "[", "'__charset__'", "]", "=", "$", "this", "->", "charset", "=", "$", "charset", ";", "return", "$", "this", ";", "}"...
Sets the charset. @param string $charset Charset @return \mako\view\ViewFactory
[ "Sets", "the", "charset", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/ViewFactory.php#L128-L133
train
mako-framework/framework
src/mako/view/ViewFactory.php
ViewFactory.extend
public function extend(string $extension, $renderer): ViewFactory { $this->renderers = [$extension => $renderer] + $this->renderers; return $this; }
php
public function extend(string $extension, $renderer): ViewFactory { $this->renderers = [$extension => $renderer] + $this->renderers; return $this; }
[ "public", "function", "extend", "(", "string", "$", "extension", ",", "$", "renderer", ")", ":", "ViewFactory", "{", "$", "this", "->", "renderers", "=", "[", "$", "extension", "=>", "$", "renderer", "]", "+", "$", "this", "->", "renderers", ";", "retu...
Registers a custom view renderer. @param string $extension Extension handled by the renderer @param string|\Closure $renderer Renderer class or closure that creates a renderer instance @return \mako\view\ViewFactory
[ "Registers", "a", "custom", "view", "renderer", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/ViewFactory.php#L142-L147
train
mako-framework/framework
src/mako/view/ViewFactory.php
ViewFactory.assign
public function assign(string $name, $value): ViewFactory { $this->globalVariables[$name] = $value; return $this; }
php
public function assign(string $name, $value): ViewFactory { $this->globalVariables[$name] = $value; return $this; }
[ "public", "function", "assign", "(", "string", "$", "name", ",", "$", "value", ")", ":", "ViewFactory", "{", "$", "this", "->", "globalVariables", "[", "$", "name", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Assign a global view variable that will be available in all views. @param string $name Variable name @param mixed $value View variable @return \mako\view\ViewFactory
[ "Assign", "a", "global", "view", "variable", "that", "will", "be", "available", "in", "all", "views", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/ViewFactory.php#L156-L161
train
mako-framework/framework
src/mako/view/ViewFactory.php
ViewFactory.autoAssign
public function autoAssign($view, callable $variables): ViewFactory { foreach((array) $view as $name) { $this->autoAssignVariables[$name] = $variables; } return $this; }
php
public function autoAssign($view, callable $variables): ViewFactory { foreach((array) $view as $name) { $this->autoAssignVariables[$name] = $variables; } return $this; }
[ "public", "function", "autoAssign", "(", "$", "view", ",", "callable", "$", "variables", ")", ":", "ViewFactory", "{", "foreach", "(", "(", "array", ")", "$", "view", "as", "$", "name", ")", "{", "$", "this", "->", "autoAssignVariables", "[", "$", "nam...
Assign variables that should be auto assigned to views upon creation. @param string $view View name or array of view names @param callable $variables Callable that returns an array of variables @return \mako\view\ViewFactory
[ "Assign", "variables", "that", "should", "be", "auto", "assigned", "to", "views", "upon", "creation", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/ViewFactory.php#L170-L178
train
mako-framework/framework
src/mako/view/ViewFactory.php
ViewFactory.getViewPathAndExtension
protected function getViewPathAndExtension(string $view, bool $throwException = true) { if(!isset($this->viewCache[$view])) { // Loop throught the avaiable extensions and check if the view exists foreach($this->renderers as $extension => $renderer) { $paths = $this->getCascadingFilePaths($view, $extension); foreach($paths as $path) { if($this->fileSystem->has($path)) { return $this->viewCache[$view] = [$path, $extension]; } } } // We didn't find the view so we'll throw an exception or return false if($throwException) { throw new ViewException(vsprintf('The [ %s ] view does not exist.', [$view])); } return false; } return $this->viewCache[$view]; }
php
protected function getViewPathAndExtension(string $view, bool $throwException = true) { if(!isset($this->viewCache[$view])) { // Loop throught the avaiable extensions and check if the view exists foreach($this->renderers as $extension => $renderer) { $paths = $this->getCascadingFilePaths($view, $extension); foreach($paths as $path) { if($this->fileSystem->has($path)) { return $this->viewCache[$view] = [$path, $extension]; } } } // We didn't find the view so we'll throw an exception or return false if($throwException) { throw new ViewException(vsprintf('The [ %s ] view does not exist.', [$view])); } return false; } return $this->viewCache[$view]; }
[ "protected", "function", "getViewPathAndExtension", "(", "string", "$", "view", ",", "bool", "$", "throwException", "=", "true", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "viewCache", "[", "$", "view", "]", ")", ")", "{", "// Loop throug...
Returns an array containing the view path and the renderer we should use. @param string $view View @param bool $throwException Throw exception if view doesn't exist? @throws \mako\view\ViewException @return array|bool
[ "Returns", "an", "array", "containing", "the", "view", "path", "and", "the", "renderer", "we", "should", "use", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/ViewFactory.php#L188-L218
train
mako-framework/framework
src/mako/view/ViewFactory.php
ViewFactory.rendererFactory
protected function rendererFactory($renderer): RendererInterface { return $renderer instanceof Closure ? $this->container->call($renderer) : $this->container->get($renderer); }
php
protected function rendererFactory($renderer): RendererInterface { return $renderer instanceof Closure ? $this->container->call($renderer) : $this->container->get($renderer); }
[ "protected", "function", "rendererFactory", "(", "$", "renderer", ")", ":", "RendererInterface", "{", "return", "$", "renderer", "instanceof", "Closure", "?", "$", "this", "->", "container", "->", "call", "(", "$", "renderer", ")", ":", "$", "this", "->", ...
Creates a renderer instance. @param string|\Closure $renderer Renderer class or closure @return \mako\view\renderers\RendererInterface
[ "Creates", "a", "renderer", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/ViewFactory.php#L226-L229
train
mako-framework/framework
src/mako/view/ViewFactory.php
ViewFactory.resolveRenderer
protected function resolveRenderer(string $extension): RendererInterface { if(!isset($this->rendererInstances[$extension])) { $this->rendererInstances[$extension] = $this->rendererFactory($this->renderers[$extension]); } return $this->rendererInstances[$extension]; }
php
protected function resolveRenderer(string $extension): RendererInterface { if(!isset($this->rendererInstances[$extension])) { $this->rendererInstances[$extension] = $this->rendererFactory($this->renderers[$extension]); } return $this->rendererInstances[$extension]; }
[ "protected", "function", "resolveRenderer", "(", "string", "$", "extension", ")", ":", "RendererInterface", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "rendererInstances", "[", "$", "extension", "]", ")", ")", "{", "$", "this", "->", "rendererIn...
Returns a renderer instance. @param string $extension Extension associated with the renderer @return \mako\view\renderers\RendererInterface
[ "Returns", "a", "renderer", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/ViewFactory.php#L237-L245
train
mako-framework/framework
src/mako/view/ViewFactory.php
ViewFactory.getAutoAssignVariablesForView
protected function getAutoAssignVariablesForView(string $view): array { if(!isset($this->autoAssignVariables[$view])) { return []; } return ($this->autoAssignVariables[$view])(); }
php
protected function getAutoAssignVariablesForView(string $view): array { if(!isset($this->autoAssignVariables[$view])) { return []; } return ($this->autoAssignVariables[$view])(); }
[ "protected", "function", "getAutoAssignVariablesForView", "(", "string", "$", "view", ")", ":", "array", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "autoAssignVariables", "[", "$", "view", "]", ")", ")", "{", "return", "[", "]", ";", "}", "r...
Returns view specific auto assign variables. @param string $view View @return array
[ "Returns", "view", "specific", "auto", "assign", "variables", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/ViewFactory.php#L264-L272
train
mako-framework/framework
src/mako/view/ViewFactory.php
ViewFactory.mergeVariables
protected function mergeVariables(string $view, array $variables): array { return $variables + $this->getAutoAssignVariables($view) + $this->globalVariables; }
php
protected function mergeVariables(string $view, array $variables): array { return $variables + $this->getAutoAssignVariables($view) + $this->globalVariables; }
[ "protected", "function", "mergeVariables", "(", "string", "$", "view", ",", "array", "$", "variables", ")", ":", "array", "{", "return", "$", "variables", "+", "$", "this", "->", "getAutoAssignVariables", "(", "$", "view", ")", "+", "$", "this", "->", "g...
Returns array where variables have been merged in order of importance. @param string $view View @param array $variables View variables @return array
[ "Returns", "array", "where", "variables", "have", "been", "merged", "in", "order", "of", "importance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/ViewFactory.php#L292-L295
train
mako-framework/framework
src/mako/view/ViewFactory.php
ViewFactory.create
public function create(string $view, array $variables = []): View { [$path, $extension] = $this->getViewPathAndExtension($view); return new View($path, $this->mergeVariables($view, $variables), $this->resolveRenderer($extension)); }
php
public function create(string $view, array $variables = []): View { [$path, $extension] = $this->getViewPathAndExtension($view); return new View($path, $this->mergeVariables($view, $variables), $this->resolveRenderer($extension)); }
[ "public", "function", "create", "(", "string", "$", "view", ",", "array", "$", "variables", "=", "[", "]", ")", ":", "View", "{", "[", "$", "path", ",", "$", "extension", "]", "=", "$", "this", "->", "getViewPathAndExtension", "(", "$", "view", ")", ...
Creates and returns a view instance. @param string $view View @param array $variables View variables @return \mako\view\View
[ "Creates", "and", "returns", "a", "view", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/ViewFactory.php#L304-L309
train
mako-framework/framework
src/mako/view/ViewFactory.php
ViewFactory.render
public function render(string $view, array $variables = []): string { return $this->create($view, $variables)->render(); }
php
public function render(string $view, array $variables = []): string { return $this->create($view, $variables)->render(); }
[ "public", "function", "render", "(", "string", "$", "view", ",", "array", "$", "variables", "=", "[", "]", ")", ":", "string", "{", "return", "$", "this", "->", "create", "(", "$", "view", ",", "$", "variables", ")", "->", "render", "(", ")", ";", ...
Creates and returns a rendered view. @param string $view View @param array $variables View variables @return string
[ "Creates", "and", "returns", "a", "rendered", "view", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/ViewFactory.php#L318-L321
train
mako-framework/framework
src/mako/syringe/ClassInspector.php
ClassInspector.getTraits
public static function getTraits($class, bool $autoload = true): array { // Fetch all traits used by a class and its parents $traits = []; do { $traits += class_uses($class, $autoload); } while($class = get_parent_class($class)); // Find all traits used by the traits $search = $traits; $searched = []; while(!empty($search)) { $trait = array_pop($search); if(isset($searched[$trait])) { continue; } $traits += $search += class_uses($trait, $autoload); $searched[$trait] = $trait; } // Return complete list of traits used by the class return $traits; }
php
public static function getTraits($class, bool $autoload = true): array { // Fetch all traits used by a class and its parents $traits = []; do { $traits += class_uses($class, $autoload); } while($class = get_parent_class($class)); // Find all traits used by the traits $search = $traits; $searched = []; while(!empty($search)) { $trait = array_pop($search); if(isset($searched[$trait])) { continue; } $traits += $search += class_uses($trait, $autoload); $searched[$trait] = $trait; } // Return complete list of traits used by the class return $traits; }
[ "public", "static", "function", "getTraits", "(", "$", "class", ",", "bool", "$", "autoload", "=", "true", ")", ":", "array", "{", "// Fetch all traits used by a class and its parents", "$", "traits", "=", "[", "]", ";", "do", "{", "$", "traits", "+=", "clas...
Returns an array of all traits used by a class. @param string|object $class Class name or class instance @param bool $autoload Autoload @return array
[ "Returns", "an", "array", "of", "all", "traits", "used", "by", "a", "class", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/syringe/ClassInspector.php#L28-L63
train
mako-framework/framework
src/mako/http/routing/traits/AuthorizationTrait.php
AuthorizationTrait.authorize
protected function authorize(string $action, $entity): void { if($this->authorizer->can($this->gatekeeper->getUser(), $action, $entity) === false) { throw new ForbiddenException; } }
php
protected function authorize(string $action, $entity): void { if($this->authorizer->can($this->gatekeeper->getUser(), $action, $entity) === false) { throw new ForbiddenException; } }
[ "protected", "function", "authorize", "(", "string", "$", "action", ",", "$", "entity", ")", ":", "void", "{", "if", "(", "$", "this", "->", "authorizer", "->", "can", "(", "$", "this", "->", "gatekeeper", "->", "getUser", "(", ")", ",", "$", "action...
Throws a ForbiddenException if the user is not allowed to perform the action on the entity. @param string $action Action @param object|string $entity Entity instance or class name @throws \mako\http\exceptions\ForbiddenException
[ "Throws", "a", "ForbiddenException", "if", "the", "user", "is", "not", "allowed", "to", "perform", "the", "action", "on", "the", "entity", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/traits/AuthorizationTrait.php#L26-L32
train
mako-framework/framework
src/mako/database/midgard/traits/OptimisticLockingTrait.php
OptimisticLockingTrait.reload
public function reload(): bool { if($this->isPersisted) { $model = static::get($this->getPrimaryKeyValue()); if($model !== false) { $this->original = $this->columns = $model->getRawColumnValues(); $this->related = $model->getRelated(); return true; } } return false; }
php
public function reload(): bool { if($this->isPersisted) { $model = static::get($this->getPrimaryKeyValue()); if($model !== false) { $this->original = $this->columns = $model->getRawColumnValues(); $this->related = $model->getRelated(); return true; } } return false; }
[ "public", "function", "reload", "(", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "isPersisted", ")", "{", "$", "model", "=", "static", "::", "get", "(", "$", "this", "->", "getPrimaryKeyValue", "(", ")", ")", ";", "if", "(", "$", "model", ...
Reloads the record from the database. @return bool
[ "Reloads", "the", "record", "from", "the", "database", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/traits/OptimisticLockingTrait.php#L83-L100
train
mako-framework/framework
src/mako/reactor/exceptions/InvalidOptionException.php
InvalidOptionException.getMessageWithSuggestion
public function getMessageWithSuggestion(): string { $message = $this->getMessage(); if($this->suggestion !== null) { $message .= ' Did you mean [ ' . $this->suggestion . ' ]?'; } return $message; }
php
public function getMessageWithSuggestion(): string { $message = $this->getMessage(); if($this->suggestion !== null) { $message .= ' Did you mean [ ' . $this->suggestion . ' ]?'; } return $message; }
[ "public", "function", "getMessageWithSuggestion", "(", ")", ":", "string", "{", "$", "message", "=", "$", "this", "->", "getMessage", "(", ")", ";", "if", "(", "$", "this", "->", "suggestion", "!==", "null", ")", "{", "$", "message", ".=", "' Did you mea...
Returns the exception message with a suggestion. @return string
[ "Returns", "the", "exception", "message", "with", "a", "suggestion", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/exceptions/InvalidOptionException.php#L57-L67
train
mako-framework/framework
src/mako/http/request/Files.php
Files.normalizeMultiUpload
protected function normalizeMultiUpload(array $files): array { $normalized = []; $keys = array_keys($files); $count = count($files['name']); for($i = 0; $i < $count; $i++) { foreach($keys as $key) { $normalized[$i][$key] = $files[$key][$i]; } } return $normalized; }
php
protected function normalizeMultiUpload(array $files): array { $normalized = []; $keys = array_keys($files); $count = count($files['name']); for($i = 0; $i < $count; $i++) { foreach($keys as $key) { $normalized[$i][$key] = $files[$key][$i]; } } return $normalized; }
[ "protected", "function", "normalizeMultiUpload", "(", "array", "$", "files", ")", ":", "array", "{", "$", "normalized", "=", "[", "]", ";", "$", "keys", "=", "array_keys", "(", "$", "files", ")", ";", "$", "count", "=", "count", "(", "$", "files", "[...
Normalizes a multi file upload array to a more manageable format. @param array $files File upload array @return array
[ "Normalizes", "a", "multi", "file", "upload", "array", "to", "a", "more", "manageable", "format", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/request/Files.php#L46-L63
train
mako-framework/framework
src/mako/view/renderers/Template.php
Template.needToCompile
protected function needToCompile(string $view, string $compiled): bool { return !$this->fileSystem->has($compiled) || $this->fileSystem->lastModified($compiled) < $this->fileSystem->lastModified($view); }
php
protected function needToCompile(string $view, string $compiled): bool { return !$this->fileSystem->has($compiled) || $this->fileSystem->lastModified($compiled) < $this->fileSystem->lastModified($view); }
[ "protected", "function", "needToCompile", "(", "string", "$", "view", ",", "string", "$", "compiled", ")", ":", "bool", "{", "return", "!", "$", "this", "->", "fileSystem", "->", "has", "(", "$", "compiled", ")", "||", "$", "this", "->", "fileSystem", ...
Returns TRUE if the template needs to be compiled and FALSE if not. @param string $view View path @param string $compiled Compiled view path @return bool
[ "Returns", "TRUE", "if", "the", "template", "needs", "to", "be", "compiled", "and", "FALSE", "if", "not", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/renderers/Template.php#L86-L89
train
mako-framework/framework
src/mako/view/renderers/Template.php
Template.compile
protected function compile(string $view): void { (new Compiler($this->fileSystem, $this->cachePath, $view))->compile(); }
php
protected function compile(string $view): void { (new Compiler($this->fileSystem, $this->cachePath, $view))->compile(); }
[ "protected", "function", "compile", "(", "string", "$", "view", ")", ":", "void", "{", "(", "new", "Compiler", "(", "$", "this", "->", "fileSystem", ",", "$", "this", "->", "cachePath", ",", "$", "view", ")", ")", "->", "compile", "(", ")", ";", "}...
Compiles view. @param string $view View path
[ "Compiles", "view", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/renderers/Template.php#L96-L99
train
mako-framework/framework
src/mako/view/renderers/Template.php
Template.output
public function output(string $name): void { $parent = $this->close(); $output = current($this->blocks[$name]); unset($this->blocks[$name]); if(!empty($parent)) { $output = str_replace('__PARENT__', $parent, $output); } echo $output; }
php
public function output(string $name): void { $parent = $this->close(); $output = current($this->blocks[$name]); unset($this->blocks[$name]); if(!empty($parent)) { $output = str_replace('__PARENT__', $parent, $output); } echo $output; }
[ "public", "function", "output", "(", "string", "$", "name", ")", ":", "void", "{", "$", "parent", "=", "$", "this", "->", "close", "(", ")", ";", "$", "output", "=", "current", "(", "$", "this", "->", "blocks", "[", "$", "name", "]", ")", ";", ...
Output a template block. @param string $name Block name
[ "Output", "a", "template", "block", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/renderers/Template.php#L126-L140
train
mako-framework/framework
src/mako/http/request/UploadedFile.php
UploadedFile.getErrorMessage
public function getErrorMessage(): string { switch($this->errorCode) { case UPLOAD_ERR_OK: return 'There is no error, the file was successfully uploaded.'; case UPLOAD_ERR_INI_SIZE: return 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; case UPLOAD_ERR_FORM_SIZE: return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'; case UPLOAD_ERR_PARTIAL: return 'The uploaded file was only partially uploaded.'; case UPLOAD_ERR_NO_FILE: return 'No file was uploaded.'; case UPLOAD_ERR_NO_TMP_DIR: return 'Missing a temporary folder.'; case UPLOAD_ERR_CANT_WRITE: return 'Failed to write file to disk.'; case UPLOAD_ERR_EXTENSION: return 'A PHP extension stopped the file upload.'; default: return 'Unknown upload error.'; } }
php
public function getErrorMessage(): string { switch($this->errorCode) { case UPLOAD_ERR_OK: return 'There is no error, the file was successfully uploaded.'; case UPLOAD_ERR_INI_SIZE: return 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; case UPLOAD_ERR_FORM_SIZE: return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'; case UPLOAD_ERR_PARTIAL: return 'The uploaded file was only partially uploaded.'; case UPLOAD_ERR_NO_FILE: return 'No file was uploaded.'; case UPLOAD_ERR_NO_TMP_DIR: return 'Missing a temporary folder.'; case UPLOAD_ERR_CANT_WRITE: return 'Failed to write file to disk.'; case UPLOAD_ERR_EXTENSION: return 'A PHP extension stopped the file upload.'; default: return 'Unknown upload error.'; } }
[ "public", "function", "getErrorMessage", "(", ")", ":", "string", "{", "switch", "(", "$", "this", "->", "errorCode", ")", "{", "case", "UPLOAD_ERR_OK", ":", "return", "'There is no error, the file was successfully uploaded.'", ";", "case", "UPLOAD_ERR_INI_SIZE", ":",...
Returns a human friendly error message. @return string
[ "Returns", "a", "human", "friendly", "error", "message", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/request/UploadedFile.php#L129-L152
train
mako-framework/framework
src/mako/http/request/UploadedFile.php
UploadedFile.moveTo
public function moveTo(string $path): bool { if($this->hasError()) { throw new UploadException(vsprintf('%s', [$this->getErrorMessage()]), $this->getErrorCode()); } if($this->isUploaded() === false) { throw new UploadException('The file that you\'re trying to move was not uploaded.', -1); } return $this->moveUploadedFile($path); }
php
public function moveTo(string $path): bool { if($this->hasError()) { throw new UploadException(vsprintf('%s', [$this->getErrorMessage()]), $this->getErrorCode()); } if($this->isUploaded() === false) { throw new UploadException('The file that you\'re trying to move was not uploaded.', -1); } return $this->moveUploadedFile($path); }
[ "public", "function", "moveTo", "(", "string", "$", "path", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "hasError", "(", ")", ")", "{", "throw", "new", "UploadException", "(", "vsprintf", "(", "'%s'", ",", "[", "$", "this", "->", "getErrorMe...
Moves the file to the desired path. @param string $path Storage path @throws \mako\http\request\exceptions\UploadException @return bool
[ "Moves", "the", "file", "to", "the", "desired", "path", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/request/UploadedFile.php#L182-L195
train
mako-framework/framework
src/mako/database/query/compilers/traits/JsonPathBuilderTrait.php
JsonPathBuilderTrait.buildJsonPath
protected function buildJsonPath(array $segments): string { $path = ''; foreach($segments as $segment) { if(is_numeric($segment)) { $path .= '[' . $segment . ']'; } else { $path .= '.' . '"' . str_replace(['"', "'"], ['\\\"', "''"], $segment) . '"'; } } return '$' . $path; }
php
protected function buildJsonPath(array $segments): string { $path = ''; foreach($segments as $segment) { if(is_numeric($segment)) { $path .= '[' . $segment . ']'; } else { $path .= '.' . '"' . str_replace(['"', "'"], ['\\\"', "''"], $segment) . '"'; } } return '$' . $path; }
[ "protected", "function", "buildJsonPath", "(", "array", "$", "segments", ")", ":", "string", "{", "$", "path", "=", "''", ";", "foreach", "(", "$", "segments", "as", "$", "segment", ")", "{", "if", "(", "is_numeric", "(", "$", "segment", ")", ")", "{...
Builds a JSON path. @param array $segments Path segments @return string
[ "Builds", "a", "JSON", "path", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/query/compilers/traits/JsonPathBuilderTrait.php#L26-L43
train
mako-framework/framework
src/mako/cache/CacheManager.php
CacheManager.fileFactory
protected function fileFactory(array $configuration): File { return (new File($this->container->get(FileSystem::class), $configuration['path'], $this->classWhitelist))->setPrefix($configuration['prefix'] ?? ''); }
php
protected function fileFactory(array $configuration): File { return (new File($this->container->get(FileSystem::class), $configuration['path'], $this->classWhitelist))->setPrefix($configuration['prefix'] ?? ''); }
[ "protected", "function", "fileFactory", "(", "array", "$", "configuration", ")", ":", "File", "{", "return", "(", "new", "File", "(", "$", "this", "->", "container", "->", "get", "(", "FileSystem", "::", "class", ")", ",", "$", "configuration", "[", "'pa...
File store factory. @param array $configuration Configuration @return \mako\cache\stores\File
[ "File", "store", "factory", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cache/CacheManager.php#L85-L88
train
mako-framework/framework
src/mako/cache/CacheManager.php
CacheManager.databaseFactory
protected function databaseFactory(array $configuration): Database { return (new Database($this->container->get(DatabaseConnectionManager::class)->connection($configuration['configuration']), $configuration['table'], $this->classWhitelist))->setPrefix($configuration['prefix'] ?? ''); }
php
protected function databaseFactory(array $configuration): Database { return (new Database($this->container->get(DatabaseConnectionManager::class)->connection($configuration['configuration']), $configuration['table'], $this->classWhitelist))->setPrefix($configuration['prefix'] ?? ''); }
[ "protected", "function", "databaseFactory", "(", "array", "$", "configuration", ")", ":", "Database", "{", "return", "(", "new", "Database", "(", "$", "this", "->", "container", "->", "get", "(", "DatabaseConnectionManager", "::", "class", ")", "->", "connecti...
Database store factory. @param array $configuration Configuration @return \mako\cache\stores\Database
[ "Database", "store", "factory", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cache/CacheManager.php#L96-L99
train
mako-framework/framework
src/mako/cache/CacheManager.php
CacheManager.redisFactory
protected function redisFactory(array $configuration): Redis { return (new Redis($this->container->get(RedisConnectionManager::class)->connection($configuration['configuration']), $this->classWhitelist))->setPrefix($configuration['prefix'] ?? ''); }
php
protected function redisFactory(array $configuration): Redis { return (new Redis($this->container->get(RedisConnectionManager::class)->connection($configuration['configuration']), $this->classWhitelist))->setPrefix($configuration['prefix'] ?? ''); }
[ "protected", "function", "redisFactory", "(", "array", "$", "configuration", ")", ":", "Redis", "{", "return", "(", "new", "Redis", "(", "$", "this", "->", "container", "->", "get", "(", "RedisConnectionManager", "::", "class", ")", "->", "connection", "(", ...
Redis store factory. @param array $configuration Configuration @return \mako\cache\stores\Redis
[ "Redis", "store", "factory", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cache/CacheManager.php#L140-L143
train
mako-framework/framework
src/mako/cache/CacheManager.php
CacheManager.instantiate
protected function instantiate(string $configuration) { if(!isset($this->configurations[$configuration])) { throw new RuntimeException(vsprintf('[ %s ] has not been defined in the cache configuration.', [$configuration])); } $configuration = $this->configurations[$configuration]; return $this->factory($configuration['type'], $configuration); }
php
protected function instantiate(string $configuration) { if(!isset($this->configurations[$configuration])) { throw new RuntimeException(vsprintf('[ %s ] has not been defined in the cache configuration.', [$configuration])); } $configuration = $this->configurations[$configuration]; return $this->factory($configuration['type'], $configuration); }
[ "protected", "function", "instantiate", "(", "string", "$", "configuration", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "configurations", "[", "$", "configuration", "]", ")", ")", "{", "throw", "new", "RuntimeException", "(", "vsprintf", "(...
Returns a cache instance. @param string $configuration Configuration name @throws \RuntimeException @return \mako\cache\stores\StoreInterface
[ "Returns", "a", "cache", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cache/CacheManager.php#L196-L206
train
mako-framework/framework
src/mako/database/midgard/traits/NullableTrait.php
NullableTrait.setEmptyNullablesToNull
protected function setEmptyNullablesToNull(array $values): array { $nullables = $this->getNullableColumns(); foreach($values as $column => $value) { if($value === '' && in_array($column, $nullables)) { $values[$column] = null; } } return $values; }
php
protected function setEmptyNullablesToNull(array $values): array { $nullables = $this->getNullableColumns(); foreach($values as $column => $value) { if($value === '' && in_array($column, $nullables)) { $values[$column] = null; } } return $values; }
[ "protected", "function", "setEmptyNullablesToNull", "(", "array", "$", "values", ")", ":", "array", "{", "$", "nullables", "=", "$", "this", "->", "getNullableColumns", "(", ")", ";", "foreach", "(", "$", "values", "as", "$", "column", "=>", "$", "value", ...
Will replace empty strings with null if the column is nullable. @param array $values Values @return array
[ "Will", "replace", "empty", "strings", "with", "null", "if", "the", "column", "is", "nullable", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/traits/NullableTrait.php#L36-L49
train
mako-framework/framework
src/mako/utility/Str.php
Str.underscored2camel
public static function underscored2camel(string $string, bool $upper = false): string { return preg_replace_callback(($upper ? '/(?:^|_)(.?)/u' : '/_(.?)/u'), function($matches) { return mb_strtoupper($matches[1]); }, $string); }
php
public static function underscored2camel(string $string, bool $upper = false): string { return preg_replace_callback(($upper ? '/(?:^|_)(.?)/u' : '/_(.?)/u'), function($matches) { return mb_strtoupper($matches[1]); }, $string); }
[ "public", "static", "function", "underscored2camel", "(", "string", "$", "string", ",", "bool", "$", "upper", "=", "false", ")", ":", "string", "{", "return", "preg_replace_callback", "(", "(", "$", "upper", "?", "'/(?:^|_)(.?)/u'", ":", "'/_(.?)/u'", ")", "...
Converts underscored to camel case. @param string $string The input string @param bool $upper Return upper case camelCase? @return string
[ "Converts", "underscored", "to", "camel", "case", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/utility/Str.php#L201-L204
train
mako-framework/framework
src/mako/utility/Str.php
Str.slug
public static function slug(string $string): string { return rawurlencode(mb_strtolower(preg_replace('/\s{1,}/', '-', trim(preg_replace('/[\x0-\x1F\x21-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]/', '', $string))))); }
php
public static function slug(string $string): string { return rawurlencode(mb_strtolower(preg_replace('/\s{1,}/', '-', trim(preg_replace('/[\x0-\x1F\x21-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]/', '', $string))))); }
[ "public", "static", "function", "slug", "(", "string", "$", "string", ")", ":", "string", "{", "return", "rawurlencode", "(", "mb_strtolower", "(", "preg_replace", "(", "'/\\s{1,}/'", ",", "'-'", ",", "trim", "(", "preg_replace", "(", "'/[\\x0-\\x1F\\x21-\\x2C\\...
Creates a URL friendly string. @param string $string The input string @return string
[ "Creates", "a", "URL", "friendly", "string", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/utility/Str.php#L245-L248
train
mako-framework/framework
src/mako/utility/Str.php
Str.autolink
public static function autolink(string $string, array $attributes = []): string { return preg_replace_callback('#\b(?<!href="|">)[a-z]+://\S+(?:/|\b)#i', function($matches) use ($attributes) { return (new HTML())->tag('a', ['href' => $matches[0]] + $attributes, $matches[0]); }, $string); }
php
public static function autolink(string $string, array $attributes = []): string { return preg_replace_callback('#\b(?<!href="|">)[a-z]+://\S+(?:/|\b)#i', function($matches) use ($attributes) { return (new HTML())->tag('a', ['href' => $matches[0]] + $attributes, $matches[0]); }, $string); }
[ "public", "static", "function", "autolink", "(", "string", "$", "string", ",", "array", "$", "attributes", "=", "[", "]", ")", ":", "string", "{", "return", "preg_replace_callback", "(", "'#\\b(?<!href=\"|\">)[a-z]+://\\S+(?:/|\\b)#i'", ",", "function", "(", "$", ...
Converts URLs in a text into clickable links. @param string $string Text to scan for links @param array $attributes Anchor attributes @return string
[ "Converts", "URLs", "in", "a", "text", "into", "clickable", "links", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/utility/Str.php#L284-L290
train
mako-framework/framework
src/mako/utility/Str.php
Str.mask
public static function mask(string $string, int $visible = 3, string $mask = '*'): string { if($visible === 0) { return str_repeat($mask, mb_strlen($string)); } $visible = mb_substr($string, -$visible); return str_pad($visible, (mb_strlen($string) + (strlen($visible) - mb_strlen($visible))), $mask, STR_PAD_LEFT); }
php
public static function mask(string $string, int $visible = 3, string $mask = '*'): string { if($visible === 0) { return str_repeat($mask, mb_strlen($string)); } $visible = mb_substr($string, -$visible); return str_pad($visible, (mb_strlen($string) + (strlen($visible) - mb_strlen($visible))), $mask, STR_PAD_LEFT); }
[ "public", "static", "function", "mask", "(", "string", "$", "string", ",", "int", "$", "visible", "=", "3", ",", "string", "$", "mask", "=", "'*'", ")", ":", "string", "{", "if", "(", "$", "visible", "===", "0", ")", "{", "return", "str_repeat", "(...
Returns a masked string where only the last n characters are visible. @param string $string String to mask @param int $visible Number of characters to show @param string $mask Character used to replace remaining characters @return string
[ "Returns", "a", "masked", "string", "where", "only", "the", "last", "n", "characters", "are", "visible", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/utility/Str.php#L300-L310
train
mako-framework/framework
src/mako/utility/Str.php
Str.increment
public static function increment(string $string, int $start = 1, string $separator = '_'): string { preg_match('/(.+)' . preg_quote($separator) . '([0-9]+)$/', $string, $matches); return isset($matches[2]) ? $matches[1] . $separator . ((int) $matches[2] + 1) : $string . $separator . $start; }
php
public static function increment(string $string, int $start = 1, string $separator = '_'): string { preg_match('/(.+)' . preg_quote($separator) . '([0-9]+)$/', $string, $matches); return isset($matches[2]) ? $matches[1] . $separator . ((int) $matches[2] + 1) : $string . $separator . $start; }
[ "public", "static", "function", "increment", "(", "string", "$", "string", ",", "int", "$", "start", "=", "1", ",", "string", "$", "separator", "=", "'_'", ")", ":", "string", "{", "preg_match", "(", "'/(.+)'", ".", "preg_quote", "(", "$", "separator", ...
Increments a string by appending a number to it or increasing the number. @param string $string String to increment @param int $start Starting number @param string $separator Separator @return string
[ "Increments", "a", "string", "by", "appending", "a", "number", "to", "it", "or", "increasing", "the", "number", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/utility/Str.php#L320-L325
train
mako-framework/framework
src/mako/http/response/senders/Stream.php
Stream.flush
public function flush(?string $chunk, bool $flushEmpty = false): void { if($this->isCGI) { if(!empty($chunk)) { echo $chunk; flush(); } } else { if(!empty($chunk) || $flushEmpty === true) { printf("%x\r\n%s\r\n", strlen($chunk), $chunk); flush(); } } }
php
public function flush(?string $chunk, bool $flushEmpty = false): void { if($this->isCGI) { if(!empty($chunk)) { echo $chunk; flush(); } } else { if(!empty($chunk) || $flushEmpty === true) { printf("%x\r\n%s\r\n", strlen($chunk), $chunk); flush(); } } }
[ "public", "function", "flush", "(", "?", "string", "$", "chunk", ",", "bool", "$", "flushEmpty", "=", "false", ")", ":", "void", "{", "if", "(", "$", "this", "->", "isCGI", ")", "{", "if", "(", "!", "empty", "(", "$", "chunk", ")", ")", "{", "e...
Flushes a chunck of data. @param string|null $chunk Chunck of data to flush @param bool $flushEmpty Flush empty chunk?
[ "Flushes", "a", "chunck", "of", "data", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/response/senders/Stream.php#L103-L123
train
mako-framework/framework
src/mako/http/response/senders/Stream.php
Stream.flow
protected function flow(): void { // Erase output buffers and disable output buffering while(ob_get_level() > 0) ob_end_clean(); // Send the stream $stream = $this->stream; $stream($this); // Send empty chunk to tell the client that we're done $this->flush(null, true); }
php
protected function flow(): void { // Erase output buffers and disable output buffering while(ob_get_level() > 0) ob_end_clean(); // Send the stream $stream = $this->stream; $stream($this); // Send empty chunk to tell the client that we're done $this->flush(null, true); }
[ "protected", "function", "flow", "(", ")", ":", "void", "{", "// Erase output buffers and disable output buffering", "while", "(", "ob_get_level", "(", ")", ">", "0", ")", "ob_end_clean", "(", ")", ";", "// Send the stream", "$", "stream", "=", "$", "this", "->"...
Sends the stream.
[ "Sends", "the", "stream", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/response/senders/Stream.php#L128-L143
train
mako-framework/framework
src/mako/cli/output/helpers/ProgressBar.php
ProgressBar.buildProgressBar
protected function buildProgressBar(float $percent): string { $fill = (int) floor($percent * $this->width); $progressBar = str_pad($this->progress, strlen($this->items), '0', STR_PAD_LEFT) . '/' . $this->items . ' '; $progressBar .= str_repeat($this->filledTemplate, $fill); $progressBar .= str_repeat($this->emptyTemplate, ($this->width - $fill)); $progressBar .= str_pad(' ' . ((int) ($percent * 100)) . '% ', 6, ' ', STR_PAD_LEFT); return $progressBar; }
php
protected function buildProgressBar(float $percent): string { $fill = (int) floor($percent * $this->width); $progressBar = str_pad($this->progress, strlen($this->items), '0', STR_PAD_LEFT) . '/' . $this->items . ' '; $progressBar .= str_repeat($this->filledTemplate, $fill); $progressBar .= str_repeat($this->emptyTemplate, ($this->width - $fill)); $progressBar .= str_pad(' ' . ((int) ($percent * 100)) . '% ', 6, ' ', STR_PAD_LEFT); return $progressBar; }
[ "protected", "function", "buildProgressBar", "(", "float", "$", "percent", ")", ":", "string", "{", "$", "fill", "=", "(", "int", ")", "floor", "(", "$", "percent", "*", "$", "this", "->", "width", ")", ";", "$", "progressBar", "=", "str_pad", "(", "...
Builds the progressbar. @param float $percent Percent to fill @return string
[ "Builds", "the", "progressbar", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cli/output/helpers/ProgressBar.php#L145-L158
train
mako-framework/framework
src/mako/cli/output/helpers/ProgressBar.php
ProgressBar.draw
public function draw(): void { // Don't draw progess bar if there are 0 items if($this->items === 0) { return; } // Calculate percent $percent = (float) min(($this->progress / $this->items), 1); // Build progress bar $progressBar = $this->buildProgressBar($percent); // Draw progressbar $this->output->write("\r" . $this->prefix . $progressBar); // If we're done then we'll add a newline to the output if($this->progress === $this->items) { $this->output->write(PHP_EOL); } }
php
public function draw(): void { // Don't draw progess bar if there are 0 items if($this->items === 0) { return; } // Calculate percent $percent = (float) min(($this->progress / $this->items), 1); // Build progress bar $progressBar = $this->buildProgressBar($percent); // Draw progressbar $this->output->write("\r" . $this->prefix . $progressBar); // If we're done then we'll add a newline to the output if($this->progress === $this->items) { $this->output->write(PHP_EOL); } }
[ "public", "function", "draw", "(", ")", ":", "void", "{", "// Don't draw progess bar if there are 0 items", "if", "(", "$", "this", "->", "items", "===", "0", ")", "{", "return", ";", "}", "// Calculate percent", "$", "percent", "=", "(", "float", ")", "min"...
Draws the progressbar.
[ "Draws", "the", "progressbar", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cli/output/helpers/ProgressBar.php#L163-L190
train
mako-framework/framework
src/mako/cli/output/helpers/ProgressBar.php
ProgressBar.advance
public function advance(): void { $this->progress++; if($this->progress === $this->items || ($this->progress % $this->redrawRate) === 0) { $this->draw(); } }
php
public function advance(): void { $this->progress++; if($this->progress === $this->items || ($this->progress % $this->redrawRate) === 0) { $this->draw(); } }
[ "public", "function", "advance", "(", ")", ":", "void", "{", "$", "this", "->", "progress", "++", ";", "if", "(", "$", "this", "->", "progress", "===", "$", "this", "->", "items", "||", "(", "$", "this", "->", "progress", "%", "$", "this", "->", ...
Move progress forward and redraws the progressbar.
[ "Move", "progress", "forward", "and", "redraws", "the", "progressbar", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cli/output/helpers/ProgressBar.php#L195-L203
train
mako-framework/framework
src/mako/application/cli/Application.php
Application.reactorFactory
protected function reactorFactory(): Reactor { return new Reactor($this->container->get(Input::class), $this->container->get(Output::class), $this->container); }
php
protected function reactorFactory(): Reactor { return new Reactor($this->container->get(Input::class), $this->container->get(Output::class), $this->container); }
[ "protected", "function", "reactorFactory", "(", ")", ":", "Reactor", "{", "return", "new", "Reactor", "(", "$", "this", "->", "container", "->", "get", "(", "Input", "::", "class", ")", ",", "$", "this", "->", "container", "->", "get", "(", "Output", "...
Creates a reactor instance. @return \mako\reactor\Reactor
[ "Creates", "a", "reactor", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/Application.php#L80-L83
train
mako-framework/framework
src/mako/application/cli/Application.php
Application.registerGlobalReactorOptions
protected function registerGlobalReactorOptions(): void { $this->reactor->registerGlobalOption('env', 'Overrides the Mako environment', function(Config $config, $option): void { putenv('MAKO_ENV=' . $option); $config->setEnvironment($option); }, 'init'); $this->reactor->registerGlobalOption('mute', 'Mutes all output', function(Output $output): void { $output->mute(); }, 'init'); }
php
protected function registerGlobalReactorOptions(): void { $this->reactor->registerGlobalOption('env', 'Overrides the Mako environment', function(Config $config, $option): void { putenv('MAKO_ENV=' . $option); $config->setEnvironment($option); }, 'init'); $this->reactor->registerGlobalOption('mute', 'Mutes all output', function(Output $output): void { $output->mute(); }, 'init'); }
[ "protected", "function", "registerGlobalReactorOptions", "(", ")", ":", "void", "{", "$", "this", "->", "reactor", "->", "registerGlobalOption", "(", "'env'", ",", "'Overrides the Mako environment'", ",", "function", "(", "Config", "$", "config", ",", "$", "option...
Registers global reactor options.
[ "Registers", "global", "reactor", "options", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/Application.php#L100-L113
train
mako-framework/framework
src/mako/application/cli/Application.php
Application.startReactor
protected function startReactor(): void { $this->container->registerSingleton([Input::class, 'input'], function() { return $this->inputFactory(); }); $this->container->registerSingleton([Output::class, 'output'], function() { return $this->outputFactory(); }); $this->reactor = $this->reactorFactory(); // Set logo $this->reactor->setLogo($this->loadLogo()); // Register global options $this->registerGlobalReactorOptions(); // Handle initialization options $this->reactor->handleGlobalOptions('init'); }
php
protected function startReactor(): void { $this->container->registerSingleton([Input::class, 'input'], function() { return $this->inputFactory(); }); $this->container->registerSingleton([Output::class, 'output'], function() { return $this->outputFactory(); }); $this->reactor = $this->reactorFactory(); // Set logo $this->reactor->setLogo($this->loadLogo()); // Register global options $this->registerGlobalReactorOptions(); // Handle initialization options $this->reactor->handleGlobalOptions('init'); }
[ "protected", "function", "startReactor", "(", ")", ":", "void", "{", "$", "this", "->", "container", "->", "registerSingleton", "(", "[", "Input", "::", "class", ",", "'input'", "]", ",", "function", "(", ")", "{", "return", "$", "this", "->", "inputFact...
Starts the reactor.
[ "Starts", "the", "reactor", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/Application.php#L118-L143
train
mako-framework/framework
src/mako/application/cli/Application.php
Application.getCommands
protected function getCommands(): array { // Define core commands $commands = [ 'app.generate_key' => GenerateKey::class, 'app.generate_secret' => GenerateSecret::class, ]; if($this->container->has(Routes::class)) { $commands = array_merge($commands, [ 'app.routes' => ListRoutes::class, 'server' => Server::class, ]); } if($this->container->has(CacheManager::class)) { $commands = array_merge($commands, [ 'cache.remove' => Remove::class, 'cache.clear' => Clear::class, ]); } if($this->container->has(DatabaseConnectionManager::class)) { $commands = array_merge($commands, [ 'migrate.create' => Create::class, 'migrate.status' => Status::class, 'migrate.up' => Up::class, 'migrate.down' => Down::class, 'migrate.reset' => Reset::class, ]); } // Add application commands $commands += $this->config->get('application.commands'); // Add package commands foreach($this->packages as $package) { $commands += $package->getCommands(); } // Return commands return $commands; }
php
protected function getCommands(): array { // Define core commands $commands = [ 'app.generate_key' => GenerateKey::class, 'app.generate_secret' => GenerateSecret::class, ]; if($this->container->has(Routes::class)) { $commands = array_merge($commands, [ 'app.routes' => ListRoutes::class, 'server' => Server::class, ]); } if($this->container->has(CacheManager::class)) { $commands = array_merge($commands, [ 'cache.remove' => Remove::class, 'cache.clear' => Clear::class, ]); } if($this->container->has(DatabaseConnectionManager::class)) { $commands = array_merge($commands, [ 'migrate.create' => Create::class, 'migrate.status' => Status::class, 'migrate.up' => Up::class, 'migrate.down' => Down::class, 'migrate.reset' => Reset::class, ]); } // Add application commands $commands += $this->config->get('application.commands'); // Add package commands foreach($this->packages as $package) { $commands += $package->getCommands(); } // Return commands return $commands; }
[ "protected", "function", "getCommands", "(", ")", ":", "array", "{", "// Define core commands", "$", "commands", "=", "[", "'app.generate_key'", "=>", "GenerateKey", "::", "class", ",", "'app.generate_secret'", "=>", "GenerateSecret", "::", "class", ",", "]", ";",...
Returns all registered commands. @return array
[ "Returns", "all", "registered", "commands", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/Application.php#L160-L214
train
mako-framework/framework
src/mako/utility/Collection.php
Collection.get
public function get($key, $default = null) { if(array_key_exists($key, $this->items)) { return $this->items[$key]; } return $default; }
php
public function get($key, $default = null) { if(array_key_exists($key, $this->items)) { return $this->items[$key]; } return $default; }
[ "public", "function", "get", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "items", ")", ")", "{", "return", "$", "this", "->", "items", "[", "$", "key", "]", ...
Returns an item from the collection. @param int|string $key Key @param mixed $default Default value @return mixed
[ "Returns", "an", "item", "from", "the", "collection", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/utility/Collection.php#L118-L126
train
mako-framework/framework
src/mako/utility/Collection.php
Collection.offsetGet
public function offsetGet($offset) { if(array_key_exists($offset, $this->items)) { return $this->items[$offset]; } throw new OutOfBoundsException(vsprintf('Undefined offset [ %s ].', [$offset])); }
php
public function offsetGet($offset) { if(array_key_exists($offset, $this->items)) { return $this->items[$offset]; } throw new OutOfBoundsException(vsprintf('Undefined offset [ %s ].', [$offset])); }
[ "public", "function", "offsetGet", "(", "$", "offset", ")", "{", "if", "(", "array_key_exists", "(", "$", "offset", ",", "$", "this", "->", "items", ")", ")", "{", "return", "$", "this", "->", "items", "[", "$", "offset", "]", ";", "}", "throw", "n...
Returns the value at the specified offset. @param mixed $offset The offset to retrieve @throws \OutOfBoundsException @return mixed
[ "Returns", "the", "value", "at", "the", "specified", "offset", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/utility/Collection.php#L164-L172
train
mako-framework/framework
src/mako/utility/Collection.php
Collection.sort
public function sort(callable $comparator, bool $maintainIndexAssociation = true): bool { return $maintainIndexAssociation ? uasort($this->items, $comparator) : usort($this->items, $comparator); }
php
public function sort(callable $comparator, bool $maintainIndexAssociation = true): bool { return $maintainIndexAssociation ? uasort($this->items, $comparator) : usort($this->items, $comparator); }
[ "public", "function", "sort", "(", "callable", "$", "comparator", ",", "bool", "$", "maintainIndexAssociation", "=", "true", ")", ":", "bool", "{", "return", "$", "maintainIndexAssociation", "?", "uasort", "(", "$", "this", "->", "items", ",", "$", "comparat...
Sorts the collection using the specified comparator callable and returns TRUE on success and FALSE on failure. @param callable $comparator Comparator callable @param bool $maintainIndexAssociation Maintain index association? @return bool
[ "Sorts", "the", "collection", "using", "the", "specified", "comparator", "callable", "and", "returns", "TRUE", "on", "success", "and", "FALSE", "on", "failure", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/utility/Collection.php#L286-L289
train
mako-framework/framework
src/mako/utility/Collection.php
Collection.each
public function each(callable $callable): void { foreach($this->items as $key => $value) { $this->items[$key] = $callable($value, $key); } }
php
public function each(callable $callable): void { foreach($this->items as $key => $value) { $this->items[$key] = $callable($value, $key); } }
[ "public", "function", "each", "(", "callable", "$", "callable", ")", ":", "void", "{", "foreach", "(", "$", "this", "->", "items", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "items", "[", "$", "key", "]", "=", "$", "callab...
Applies the callable on all items in the collection. @param callable $callable Callable
[ "Applies", "the", "callable", "on", "all", "items", "in", "the", "collection", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/utility/Collection.php#L325-L331
train
mako-framework/framework
src/mako/utility/Collection.php
Collection.filter
public function filter(?callable $callable = null) { if($callable === null) { return new static(array_filter($this->items)); } return new static(array_filter($this->items, $callable, ARRAY_FILTER_USE_BOTH)); }
php
public function filter(?callable $callable = null) { if($callable === null) { return new static(array_filter($this->items)); } return new static(array_filter($this->items, $callable, ARRAY_FILTER_USE_BOTH)); }
[ "public", "function", "filter", "(", "?", "callable", "$", "callable", "=", "null", ")", "{", "if", "(", "$", "callable", "===", "null", ")", "{", "return", "new", "static", "(", "array_filter", "(", "$", "this", "->", "items", ")", ")", ";", "}", ...
Returns a new filtered collection. @param callable|null $callable Filter @return static
[ "Returns", "a", "new", "filtered", "collection", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/utility/Collection.php#L355-L363
train
mako-framework/framework
src/mako/reactor/traits/FireTrait.php
FireTrait.buildCommand
protected function buildCommand(string $command, bool $background = false, bool $sameEnvironment = true): string { if($sameEnvironment && strpos($command, '--env=') === false && ($environment = $this->app->getEnvironment()) !== null) { $command .= ' --env=' . $environment; } $command = PHP_BINARY . ' ' . $this->buildReactorPath() . ' ' . $command . ' 2>&1'; if(DIRECTORY_SEPARATOR === '\\') { if($background) { $command = '/b ' . $command; } return 'start ' . $command; } if($background) { $command .= ' &'; } return $command; }
php
protected function buildCommand(string $command, bool $background = false, bool $sameEnvironment = true): string { if($sameEnvironment && strpos($command, '--env=') === false && ($environment = $this->app->getEnvironment()) !== null) { $command .= ' --env=' . $environment; } $command = PHP_BINARY . ' ' . $this->buildReactorPath() . ' ' . $command . ' 2>&1'; if(DIRECTORY_SEPARATOR === '\\') { if($background) { $command = '/b ' . $command; } return 'start ' . $command; } if($background) { $command .= ' &'; } return $command; }
[ "protected", "function", "buildCommand", "(", "string", "$", "command", ",", "bool", "$", "background", "=", "false", ",", "bool", "$", "sameEnvironment", "=", "true", ")", ":", "string", "{", "if", "(", "$", "sameEnvironment", "&&", "strpos", "(", "$", ...
Returns command that we're going to execute. @param string $command Command @param bool $background Is it a background process? @param bool $sameEnvironment Run command using the same environment?
[ "Returns", "command", "that", "we", "re", "going", "to", "execute", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/traits/FireTrait.php#L42-L67
train
mako-framework/framework
src/mako/reactor/traits/FireTrait.php
FireTrait.fire
protected function fire(string $command, Closure $handler, bool $sameEnvironment = true): int { $process = popen($this->buildCommand($command, false, $sameEnvironment), 'r'); while(!feof($process)) { $handler(fread($process, 4096)); } return pclose($process); }
php
protected function fire(string $command, Closure $handler, bool $sameEnvironment = true): int { $process = popen($this->buildCommand($command, false, $sameEnvironment), 'r'); while(!feof($process)) { $handler(fread($process, 4096)); } return pclose($process); }
[ "protected", "function", "fire", "(", "string", "$", "command", ",", "Closure", "$", "handler", ",", "bool", "$", "sameEnvironment", "=", "true", ")", ":", "int", "{", "$", "process", "=", "popen", "(", "$", "this", "->", "buildCommand", "(", "$", "com...
Runs command as a separate process and feeds output to handler. @param string $command Command @param \Closure $handler Output handler @param bool $sameEnvironment Run command using the same environment? @return int
[ "Runs", "command", "as", "a", "separate", "process", "and", "feeds", "output", "to", "handler", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/traits/FireTrait.php#L77-L87
train
mako-framework/framework
src/mako/reactor/traits/FireTrait.php
FireTrait.fireAndForget
protected function fireAndForget(string $command, bool $sameEnvironment = true): void { pclose(popen($this->buildCommand($command, true, $sameEnvironment), 'r')); }
php
protected function fireAndForget(string $command, bool $sameEnvironment = true): void { pclose(popen($this->buildCommand($command, true, $sameEnvironment), 'r')); }
[ "protected", "function", "fireAndForget", "(", "string", "$", "command", ",", "bool", "$", "sameEnvironment", "=", "true", ")", ":", "void", "{", "pclose", "(", "popen", "(", "$", "this", "->", "buildCommand", "(", "$", "command", ",", "true", ",", "$", ...
Starts command as a background process. @param string $command Command @param bool $sameEnvironment Run command using the same environment?
[ "Starts", "command", "as", "a", "background", "process", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/traits/FireTrait.php#L95-L98
train
mako-framework/framework
src/mako/reactor/Reactor.php
Reactor.registerGlobalOption
public function registerGlobalOption(string $name, string $description, Closure $handler, string $group = 'default'): void { $this->options[$group][$name] = ['description' => $description, 'handler' => $handler]; }
php
public function registerGlobalOption(string $name, string $description, Closure $handler, string $group = 'default'): void { $this->options[$group][$name] = ['description' => $description, 'handler' => $handler]; }
[ "public", "function", "registerGlobalOption", "(", "string", "$", "name", ",", "string", "$", "description", ",", "Closure", "$", "handler", ",", "string", "$", "group", "=", "'default'", ")", ":", "void", "{", "$", "this", "->", "options", "[", "$", "gr...
Register a global reactor option. @param string $name Option name @param string $description Option description @param \Closure $handler Option handler @param string $group Option group
[ "Register", "a", "global", "reactor", "option", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/Reactor.php#L125-L128
train
mako-framework/framework
src/mako/reactor/Reactor.php
Reactor.handleGlobalOptions
public function handleGlobalOptions(string $group = 'default'): void { if(isset($this->options[$group])) { foreach($this->options[$group] as $name => $option) { $input = $this->input->getArgument($name); if(!empty($input)) { $handler = $option['handler']; $this->container->call($handler, ['option' => $input]); } } } }
php
public function handleGlobalOptions(string $group = 'default'): void { if(isset($this->options[$group])) { foreach($this->options[$group] as $name => $option) { $input = $this->input->getArgument($name); if(!empty($input)) { $handler = $option['handler']; $this->container->call($handler, ['option' => $input]); } } } }
[ "public", "function", "handleGlobalOptions", "(", "string", "$", "group", "=", "'default'", ")", ":", "void", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "$", "group", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "optio...
Handles global reactor options. @param string $group Option group
[ "Handles", "global", "reactor", "options", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/reactor/Reactor.php#L145-L161
train