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/http/routing/Router.php
Router.redirectRoute
protected function redirectRoute(string $requestPath): Route { return new Route([], '', function(Request $request) use ($requestPath) { $url = $request->getBaseURL() . ($request->isClean() ? '' : '/' . $request->getScriptName()) . rtrim('/' . $request->getLanguagePrefix(), '/') . $requestPath . '/'; $query = $request->getQuery()->all(); if(!empty($query)) { $url .= '?' . http_build_query($query, '', '&', PHP_QUERY_RFC3986); } return (new Redirect($url))->setStatus(301); }); }
php
protected function redirectRoute(string $requestPath): Route { return new Route([], '', function(Request $request) use ($requestPath) { $url = $request->getBaseURL() . ($request->isClean() ? '' : '/' . $request->getScriptName()) . rtrim('/' . $request->getLanguagePrefix(), '/') . $requestPath . '/'; $query = $request->getQuery()->all(); if(!empty($query)) { $url .= '?' . http_build_query($query, '', '&', PHP_QUERY_RFC3986); } return (new Redirect($url))->setStatus(301); }); }
[ "protected", "function", "redirectRoute", "(", "string", "$", "requestPath", ")", ":", "Route", "{", "return", "new", "Route", "(", "[", "]", ",", "''", ",", "function", "(", "Request", "$", "request", ")", "use", "(", "$", "requestPath", ")", "{", "$"...
Returns a route with a closure action that redirects to the correct URL. @param string $requestPath The requested path @return \mako\http\routing\Route
[ "Returns", "a", "route", "with", "a", "closure", "action", "that", "redirects", "to", "the", "correct", "URL", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Router.php#L182-L197
train
mako-framework/framework
src/mako/http/routing/Router.php
Router.getAllowedMethodsForMatchingRoutes
protected function getAllowedMethodsForMatchingRoutes(string $requestPath): array { $methods = []; foreach($this->routes->getRoutes() as $route) { if($this->matches($route, $requestPath) && $this->constraintsAreSatisfied($route)) { $methods = array_merge($methods, $route->getMethods()); } } return array_unique($methods); }
php
protected function getAllowedMethodsForMatchingRoutes(string $requestPath): array { $methods = []; foreach($this->routes->getRoutes() as $route) { if($this->matches($route, $requestPath) && $this->constraintsAreSatisfied($route)) { $methods = array_merge($methods, $route->getMethods()); } } return array_unique($methods); }
[ "protected", "function", "getAllowedMethodsForMatchingRoutes", "(", "string", "$", "requestPath", ")", ":", "array", "{", "$", "methods", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "routes", "->", "getRoutes", "(", ")", "as", "$", "route", ")",...
Returns an array of all allowed request methods for the requested route. @param string $requestPath The requested path @return array
[ "Returns", "an", "array", "of", "all", "allowed", "request", "methods", "for", "the", "requested", "route", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Router.php#L205-L218
train
mako-framework/framework
src/mako/http/routing/Router.php
Router.optionsRoute
protected function optionsRoute(string $requestPath): Route { $allowedMethods = $this->getAllowedMethodsForMatchingRoutes($requestPath); return new Route([], '', function(Response $response) use ($allowedMethods): void { $response->getHeaders()->add('Allow', implode(',', $allowedMethods)); }); }
php
protected function optionsRoute(string $requestPath): Route { $allowedMethods = $this->getAllowedMethodsForMatchingRoutes($requestPath); return new Route([], '', function(Response $response) use ($allowedMethods): void { $response->getHeaders()->add('Allow', implode(',', $allowedMethods)); }); }
[ "protected", "function", "optionsRoute", "(", "string", "$", "requestPath", ")", ":", "Route", "{", "$", "allowedMethods", "=", "$", "this", "->", "getAllowedMethodsForMatchingRoutes", "(", "$", "requestPath", ")", ";", "return", "new", "Route", "(", "[", "]",...
Returns a route with a closure action that sets the allow header. @param string $requestPath The requested path @return \mako\http\routing\Route
[ "Returns", "a", "route", "with", "a", "closure", "action", "that", "sets", "the", "allow", "header", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Router.php#L226-L234
train
mako-framework/framework
src/mako/http/routing/Router.php
Router.route
public function route(Request $request): Route { $requestMethod = $request->getMethod(); $requestPath = $request->getPath(); foreach($this->routes->getRoutesByMethod($requestMethod) as $route) { if($this->matches($route, $requestPath) && $this->constraintsAreSatisfied($route)) { // Redirect to URL with trailing slash if the route should have one if($route->hasTrailingSlash() && !empty($requestPath) && substr($requestPath, -1) !== '/') { return $this->redirectRoute($requestPath); } // If this is an "OPTIONS" request then we'll collect all the allowed request methods // from all routes matching the requested path. We'll then add an "allows" header // to the matched route if($requestMethod === 'OPTIONS') { return $this->optionsRoute($requestPath); } // Assign the route to the request $request->setRoute($route); // Return the matched route and parameters return $route; } } // Check if there are any routes that match the pattern and constaints for other request methods if(!empty(($allowedMethods = $this->getAllowedMethodsForMatchingRoutes($requestPath)))) { throw new MethodNotAllowedException($allowedMethods); } // No routes matched so we'll throw a not found exception throw new NotFoundException($requestMethod . ': ' . $requestPath); }
php
public function route(Request $request): Route { $requestMethod = $request->getMethod(); $requestPath = $request->getPath(); foreach($this->routes->getRoutesByMethod($requestMethod) as $route) { if($this->matches($route, $requestPath) && $this->constraintsAreSatisfied($route)) { // Redirect to URL with trailing slash if the route should have one if($route->hasTrailingSlash() && !empty($requestPath) && substr($requestPath, -1) !== '/') { return $this->redirectRoute($requestPath); } // If this is an "OPTIONS" request then we'll collect all the allowed request methods // from all routes matching the requested path. We'll then add an "allows" header // to the matched route if($requestMethod === 'OPTIONS') { return $this->optionsRoute($requestPath); } // Assign the route to the request $request->setRoute($route); // Return the matched route and parameters return $route; } } // Check if there are any routes that match the pattern and constaints for other request methods if(!empty(($allowedMethods = $this->getAllowedMethodsForMatchingRoutes($requestPath)))) { throw new MethodNotAllowedException($allowedMethods); } // No routes matched so we'll throw a not found exception throw new NotFoundException($requestMethod . ': ' . $requestPath); }
[ "public", "function", "route", "(", "Request", "$", "request", ")", ":", "Route", "{", "$", "requestMethod", "=", "$", "request", "->", "getMethod", "(", ")", ";", "$", "requestPath", "=", "$", "request", "->", "getPath", "(", ")", ";", "foreach", "(",...
Matches and returns the appropriate route along with its parameters. @param \mako\http\Request $request Request @throws \mako\http\exceptions\MethodNotAllowedException @throws \mako\http\exceptions\NotFoundException @return \mako\http\routing\Route
[ "Matches", "and", "returns", "the", "appropriate", "route", "along", "with", "its", "parameters", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/routing/Router.php#L244-L290
train
mako-framework/framework
src/mako/security/crypto/CryptoManager.php
CryptoManager.instantiate
protected function instantiate(string $configuration): Crypto { if(!isset($this->configurations[$configuration])) { throw new RuntimeException(vsprintf('[ %s ] has not been defined in the crypto configuration.', [$configuration])); } $configuration = $this->configurations[$configuration]; return new Crypto($this->factory($configuration['library'], $configuration), $this->container->get(Signer::class)); }
php
protected function instantiate(string $configuration): Crypto { if(!isset($this->configurations[$configuration])) { throw new RuntimeException(vsprintf('[ %s ] has not been defined in the crypto configuration.', [$configuration])); } $configuration = $this->configurations[$configuration]; return new Crypto($this->factory($configuration['library'], $configuration), $this->container->get(Signer::class)); }
[ "protected", "function", "instantiate", "(", "string", "$", "configuration", ")", ":", "Crypto", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "configurations", "[", "$", "configuration", "]", ")", ")", "{", "throw", "new", "RuntimeException", "(",...
Returns a crypto instance. @param string $configuration Configuration name @throws \RuntimeException @return \mako\security\crypto\Crypto
[ "Returns", "a", "crypto", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/security/crypto/CryptoManager.php#L47-L57
train
mako-framework/framework
src/mako/onion/Onion.php
Onion.addLayer
public function addLayer(string $class, ?array $parameters = null, bool $inner = true): int { $this->parameters[$class] = $parameters; return $inner ? array_unshift($this->layers, $class) : array_push($this->layers, $class); }
php
public function addLayer(string $class, ?array $parameters = null, bool $inner = true): int { $this->parameters[$class] = $parameters; return $inner ? array_unshift($this->layers, $class) : array_push($this->layers, $class); }
[ "public", "function", "addLayer", "(", "string", "$", "class", ",", "?", "array", "$", "parameters", "=", "null", ",", "bool", "$", "inner", "=", "true", ")", ":", "int", "{", "$", "this", "->", "parameters", "[", "$", "class", "]", "=", "$", "para...
Add a new middleware layer. @param string $class Class @param array|null $parameters Middleware parameters @param bool $inner Add an inner layer? @return int
[ "Add", "a", "new", "middleware", "layer", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/onion/Onion.php#L84-L89
train
mako-framework/framework
src/mako/onion/Onion.php
Onion.buildCoreClosure
protected function buildCoreClosure(object $object): Closure { return function(...$arguments) use ($object) { $callable = $object instanceof Closure ? $object : [$object, $this->method]; return $callable(...$arguments); }; }
php
protected function buildCoreClosure(object $object): Closure { return function(...$arguments) use ($object) { $callable = $object instanceof Closure ? $object : [$object, $this->method]; return $callable(...$arguments); }; }
[ "protected", "function", "buildCoreClosure", "(", "object", "$", "object", ")", ":", "Closure", "{", "return", "function", "(", "...", "$", "arguments", ")", "use", "(", "$", "object", ")", "{", "$", "callable", "=", "$", "object", "instanceof", "Closure",...
Builds the core closure. @param object $object The object that we're decorating @return \Closure
[ "Builds", "the", "core", "closure", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/onion/Onion.php#L121-L129
train
mako-framework/framework
src/mako/onion/Onion.php
Onion.buildLayerClosure
protected function buildLayerClosure(object $layer, Closure $next): Closure { return function(...$arguments) use ($layer, $next) { return $layer->execute(...array_merge($arguments, [$next])); }; }
php
protected function buildLayerClosure(object $layer, Closure $next): Closure { return function(...$arguments) use ($layer, $next) { return $layer->execute(...array_merge($arguments, [$next])); }; }
[ "protected", "function", "buildLayerClosure", "(", "object", "$", "layer", ",", "Closure", "$", "next", ")", ":", "Closure", "{", "return", "function", "(", "...", "$", "arguments", ")", "use", "(", "$", "layer", ",", "$", "next", ")", "{", "return", "...
Builds a layer closure. @param object $layer Middleware object @param \Closure $next The next middleware layer @return \Closure
[ "Builds", "a", "layer", "closure", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/onion/Onion.php#L138-L144
train
mako-framework/framework
src/mako/onion/Onion.php
Onion.middlewareFactory
protected function middlewareFactory(string $middleware, array $parameters): object { // Merge middleware parameters $parameters = $this->mergeParameters($parameters, $middleware); // Create middleware instance $middleware = $this->container->get($middleware, $parameters); // Check if the middleware implements the expected interface if($this->expectedInterface !== null && ($middleware instanceof $this->expectedInterface) === false) { throw new OnionException(vsprintf('The Onion instance expects the middleware to be an instance of [ %s ].', [$this->expectedInterface])); } // Return middleware instance return $middleware; }
php
protected function middlewareFactory(string $middleware, array $parameters): object { // Merge middleware parameters $parameters = $this->mergeParameters($parameters, $middleware); // Create middleware instance $middleware = $this->container->get($middleware, $parameters); // Check if the middleware implements the expected interface if($this->expectedInterface !== null && ($middleware instanceof $this->expectedInterface) === false) { throw new OnionException(vsprintf('The Onion instance expects the middleware to be an instance of [ %s ].', [$this->expectedInterface])); } // Return middleware instance return $middleware; }
[ "protected", "function", "middlewareFactory", "(", "string", "$", "middleware", ",", "array", "$", "parameters", ")", ":", "object", "{", "// Merge middleware parameters", "$", "parameters", "=", "$", "this", "->", "mergeParameters", "(", "$", "parameters", ",", ...
Middleware factory. @param string $middleware Middleware class name @param array $parameters Middleware parameters @throws \mako\onion\OnionException @return object
[ "Middleware", "factory", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/onion/Onion.php#L166-L186
train
mako-framework/framework
src/mako/onion/Onion.php
Onion.peel
public function peel(object $object, array $parameters = [], array $middlewareParameters = []) { $next = $this->buildCoreClosure($object); foreach($this->layers as $layer) { $middleware = $this->middlewareFactory($layer, $middlewareParameters); $next = $this->buildLayerClosure($middleware, $next); } return $next(...$parameters); }
php
public function peel(object $object, array $parameters = [], array $middlewareParameters = []) { $next = $this->buildCoreClosure($object); foreach($this->layers as $layer) { $middleware = $this->middlewareFactory($layer, $middlewareParameters); $next = $this->buildLayerClosure($middleware, $next); } return $next(...$parameters); }
[ "public", "function", "peel", "(", "object", "$", "object", ",", "array", "$", "parameters", "=", "[", "]", ",", "array", "$", "middlewareParameters", "=", "[", "]", ")", "{", "$", "next", "=", "$", "this", "->", "buildCoreClosure", "(", "$", "object",...
Executes the middleware stack. @param object $object The object that we're decorating @param array $parameters Parameters @param array $middlewareParameters Middleware parameters @return mixed
[ "Executes", "the", "middleware", "stack", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/onion/Onion.php#L196-L208
train
mako-framework/framework
src/mako/application/cli/commands/migrations/traits/RollbackTrait.php
RollbackTrait.rollback
public function rollback(?int $batches = null): void { $migrations = $this->getMigrated($batches); if($migrations->isEmpty()) { $this->write('<blue>There are no migrations to roll back.</blue>'); return; } foreach($migrations as $migration) { $this->runMigration($migration, 'down'); } $this->write('Rolled back the following migrations:' . PHP_EOL); $this->outputMigrationList($migrations->getItems()); }
php
public function rollback(?int $batches = null): void { $migrations = $this->getMigrated($batches); if($migrations->isEmpty()) { $this->write('<blue>There are no migrations to roll back.</blue>'); return; } foreach($migrations as $migration) { $this->runMigration($migration, 'down'); } $this->write('Rolled back the following migrations:' . PHP_EOL); $this->outputMigrationList($migrations->getItems()); }
[ "public", "function", "rollback", "(", "?", "int", "$", "batches", "=", "null", ")", ":", "void", "{", "$", "migrations", "=", "$", "this", "->", "getMigrated", "(", "$", "batches", ")", ";", "if", "(", "$", "migrations", "->", "isEmpty", "(", ")", ...
Rolls back n batches. @param int|null $batches Number of batches to roll back
[ "Rolls", "back", "n", "batches", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/commands/migrations/traits/RollbackTrait.php#L22-L41
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.rule
public static function rule(string $ruleName, ...$parameters): string { if(empty($parameters)) { return $ruleName; } return $ruleName . '(' . substr(json_encode($parameters), 1, -1) . ')'; }
php
public static function rule(string $ruleName, ...$parameters): string { if(empty($parameters)) { return $ruleName; } return $ruleName . '(' . substr(json_encode($parameters), 1, -1) . ')'; }
[ "public", "static", "function", "rule", "(", "string", "$", "ruleName", ",", "...", "$", "parameters", ")", ":", "string", "{", "if", "(", "empty", "(", "$", "parameters", ")", ")", "{", "return", "$", "ruleName", ";", "}", "return", "$", "ruleName", ...
Rule builder. @param string $ruleName Rule name @param mixed ...$parameters Rule parameters @return string
[ "Rule", "builder", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L224-L232
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.saveOriginalFieldNames
protected function saveOriginalFieldNames(array $fields, string $field): void { foreach($fields as $expanded) { $this->originalFieldNames[$expanded] = $field; } }
php
protected function saveOriginalFieldNames(array $fields, string $field): void { foreach($fields as $expanded) { $this->originalFieldNames[$expanded] = $field; } }
[ "protected", "function", "saveOriginalFieldNames", "(", "array", "$", "fields", ",", "string", "$", "field", ")", ":", "void", "{", "foreach", "(", "$", "fields", "as", "$", "expanded", ")", "{", "$", "this", "->", "originalFieldNames", "[", "$", "expanded...
Saves original field name along with the expanded field name. @param array $fields Expanded field names @param string $field Original field name
[ "Saves", "original", "field", "name", "along", "with", "the", "expanded", "field", "name", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L265-L271
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.expandFields
protected function expandFields(array $ruleSets): array { $expanded = []; foreach($ruleSets as $field => $ruleSet) { if($this->hasWilcard($field) === false) { $expanded = array_merge_recursive($expanded, [$field => $ruleSet]); continue; } if(!empty($fields = Arr::expandKey($this->input, $field))) { $this->saveOriginalFieldNames($fields, $field); $fields = array_fill_keys($fields, $ruleSet); } $expanded = array_merge_recursive($expanded, $fields); } return $expanded; }
php
protected function expandFields(array $ruleSets): array { $expanded = []; foreach($ruleSets as $field => $ruleSet) { if($this->hasWilcard($field) === false) { $expanded = array_merge_recursive($expanded, [$field => $ruleSet]); continue; } if(!empty($fields = Arr::expandKey($this->input, $field))) { $this->saveOriginalFieldNames($fields, $field); $fields = array_fill_keys($fields, $ruleSet); } $expanded = array_merge_recursive($expanded, $fields); } return $expanded; }
[ "protected", "function", "expandFields", "(", "array", "$", "ruleSets", ")", ":", "array", "{", "$", "expanded", "=", "[", "]", ";", "foreach", "(", "$", "ruleSets", "as", "$", "field", "=>", "$", "ruleSet", ")", "{", "if", "(", "$", "this", "->", ...
Expands fields. @param array $ruleSets Rule sets @return array
[ "Expands", "fields", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L290-L314
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.addRules
public function addRules(string $field, array $ruleSet): Validator { $this->ruleSets = array_merge_recursive($this->ruleSets, $this->expandFields([$field => $ruleSet])); return $this; }
php
public function addRules(string $field, array $ruleSet): Validator { $this->ruleSets = array_merge_recursive($this->ruleSets, $this->expandFields([$field => $ruleSet])); return $this; }
[ "public", "function", "addRules", "(", "string", "$", "field", ",", "array", "$", "ruleSet", ")", ":", "Validator", "{", "$", "this", "->", "ruleSets", "=", "array_merge_recursive", "(", "$", "this", "->", "ruleSets", ",", "$", "this", "->", "expandFields"...
Adds validation rules to input field. @param string $field Input field @param array $ruleSet Rule set @return \mako\validator\Validator
[ "Adds", "validation", "rules", "to", "input", "field", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L323-L328
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.addRulesIf
public function addRulesIf(string $field, array $ruleSet, $condition): Validator { if($condition instanceof Closure) { $condition = $condition(); } return $condition ? $this->addRules($field, $ruleSet) : $this; }
php
public function addRulesIf(string $field, array $ruleSet, $condition): Validator { if($condition instanceof Closure) { $condition = $condition(); } return $condition ? $this->addRules($field, $ruleSet) : $this; }
[ "public", "function", "addRulesIf", "(", "string", "$", "field", ",", "array", "$", "ruleSet", ",", "$", "condition", ")", ":", "Validator", "{", "if", "(", "$", "condition", "instanceof", "Closure", ")", "{", "$", "condition", "=", "$", "condition", "("...
Adds validation rules to input field if the condition is met. @param string $field Input field @param array $ruleSet Rule set @param bool|\Closure $condition Condition @return \mako\validator\Validator
[ "Adds", "validation", "rules", "to", "input", "field", "if", "the", "condition", "is", "met", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L338-L346
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.parseRule
protected function parseRule(string $rule): object { $package = null; if(preg_match('/^([a-z-]+)::(.*)/', $rule, $matches) === 1) { $package = $matches[1]; } [$name, $parameters] = $this->parseFunction($rule, false); return (object) compact('name', 'parameters', 'package'); }
php
protected function parseRule(string $rule): object { $package = null; if(preg_match('/^([a-z-]+)::(.*)/', $rule, $matches) === 1) { $package = $matches[1]; } [$name, $parameters] = $this->parseFunction($rule, false); return (object) compact('name', 'parameters', 'package'); }
[ "protected", "function", "parseRule", "(", "string", "$", "rule", ")", ":", "object", "{", "$", "package", "=", "null", ";", "if", "(", "preg_match", "(", "'/^([a-z-]+)::(.*)/'", ",", "$", "rule", ",", "$", "matches", ")", "===", "1", ")", "{", "$", ...
Parses the rule. @param string $rule Rule @return object
[ "Parses", "the", "rule", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L354-L366
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.getRuleClassName
protected function getRuleClassName(string $name): string { if(!isset($this->rules[$name])) { throw new RuntimeException(vsprintf('Call to undefined validation rule [ %s ].', [$name])); } return $this->rules[$name]; }
php
protected function getRuleClassName(string $name): string { if(!isset($this->rules[$name])) { throw new RuntimeException(vsprintf('Call to undefined validation rule [ %s ].', [$name])); } return $this->rules[$name]; }
[ "protected", "function", "getRuleClassName", "(", "string", "$", "name", ")", ":", "string", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "rules", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "RuntimeException", "(", "vsprintf", "(", ...
Returns the rule class name. @param string $name Rule name @throws \RuntimeException @return string
[ "Returns", "the", "rule", "class", "name", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L375-L383
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.ruleFactory
protected function ruleFactory(string $name, array $parameters): RuleInterface { return $this->container->get($this->getRuleClassName($name), $parameters); }
php
protected function ruleFactory(string $name, array $parameters): RuleInterface { return $this->container->get($this->getRuleClassName($name), $parameters); }
[ "protected", "function", "ruleFactory", "(", "string", "$", "name", ",", "array", "$", "parameters", ")", ":", "RuleInterface", "{", "return", "$", "this", "->", "container", "->", "get", "(", "$", "this", "->", "getRuleClassName", "(", "$", "name", ")", ...
Creates a rule instance. @param string $name Rule name @param array $parameters Rule parameters @return \mako\validator\rules\RuleInterface
[ "Creates", "a", "rule", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L392-L395
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.getErrorMessage
protected function getErrorMessage(RuleInterface $rule, string $field, object $parsedRule): string { $field = $this->getOriginalFieldName($field); if($this->i18n !== null && $rule instanceof I18nAwareInterface) { return $rule->setI18n($this->i18n)->getTranslatedErrorMessage($field, $parsedRule->name, $parsedRule->package); } return $rule->getErrorMessage($field); }
php
protected function getErrorMessage(RuleInterface $rule, string $field, object $parsedRule): string { $field = $this->getOriginalFieldName($field); if($this->i18n !== null && $rule instanceof I18nAwareInterface) { return $rule->setI18n($this->i18n)->getTranslatedErrorMessage($field, $parsedRule->name, $parsedRule->package); } return $rule->getErrorMessage($field); }
[ "protected", "function", "getErrorMessage", "(", "RuleInterface", "$", "rule", ",", "string", "$", "field", ",", "object", "$", "parsedRule", ")", ":", "string", "{", "$", "field", "=", "$", "this", "->", "getOriginalFieldName", "(", "$", "field", ")", ";"...
Returns the error message. @param \mako\validator\rules\RuleInterface $rule Rule @param string $field Field name @param object $parsedRule Parsed rule @return string
[ "Returns", "the", "error", "message", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L416-L426
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.validateField
protected function validateField(string $field, string $rule): bool { $parsedRule = $this->parseRule($rule); $rule = $this->ruleFactory($parsedRule->name, $parsedRule->parameters); // Just return true if the input field is empty and the rule doesn't validate empty input if($this->isInputFieldEmpty($inputValue = Arr::get($this->input, $field)) && $rule->validateWhenEmpty() === false) { return true; } // Validate input if($rule->validate($inputValue, $this->input) === false) { $this->errors[$field] = $this->getErrorMessage($rule, $field, $parsedRule); return $this->isValid = false; } return true; }
php
protected function validateField(string $field, string $rule): bool { $parsedRule = $this->parseRule($rule); $rule = $this->ruleFactory($parsedRule->name, $parsedRule->parameters); // Just return true if the input field is empty and the rule doesn't validate empty input if($this->isInputFieldEmpty($inputValue = Arr::get($this->input, $field)) && $rule->validateWhenEmpty() === false) { return true; } // Validate input if($rule->validate($inputValue, $this->input) === false) { $this->errors[$field] = $this->getErrorMessage($rule, $field, $parsedRule); return $this->isValid = false; } return true; }
[ "protected", "function", "validateField", "(", "string", "$", "field", ",", "string", "$", "rule", ")", ":", "bool", "{", "$", "parsedRule", "=", "$", "this", "->", "parseRule", "(", "$", "rule", ")", ";", "$", "rule", "=", "$", "this", "->", "ruleFa...
Validates the field using the specified rule. @param string $field Field name @param string $rule Rule @return bool
[ "Validates", "the", "field", "using", "the", "specified", "rule", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L435-L458
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.process
protected function process(): array { foreach($this->ruleSets as $field => $ruleSet) { // Ensure that we don't have any duplicated rules for a field $ruleSet = array_unique($ruleSet); // Validate field and stop as soon as one of the rules fail foreach($ruleSet as $rule) { if($this->validateField($field, $rule) === false) { break; } } } return [$this->isValid, $this->errors]; }
php
protected function process(): array { foreach($this->ruleSets as $field => $ruleSet) { // Ensure that we don't have any duplicated rules for a field $ruleSet = array_unique($ruleSet); // Validate field and stop as soon as one of the rules fail foreach($ruleSet as $rule) { if($this->validateField($field, $rule) === false) { break; } } } return [$this->isValid, $this->errors]; }
[ "protected", "function", "process", "(", ")", ":", "array", "{", "foreach", "(", "$", "this", "->", "ruleSets", "as", "$", "field", "=>", "$", "ruleSet", ")", "{", "// Ensure that we don't have any duplicated rules for a field", "$", "ruleSet", "=", "array_unique"...
Processes all validation rules and returns an array containing the validation status and potential error messages. @return array
[ "Processes", "all", "validation", "rules", "and", "returns", "an", "array", "containing", "the", "validation", "status", "and", "potential", "error", "messages", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L466-L486
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.isValid
public function isValid(?array &$errors = null): bool { [$isValid, $errors] = $this->process(); return $isValid === true; }
php
public function isValid(?array &$errors = null): bool { [$isValid, $errors] = $this->process(); return $isValid === true; }
[ "public", "function", "isValid", "(", "?", "array", "&", "$", "errors", "=", "null", ")", ":", "bool", "{", "[", "$", "isValid", ",", "$", "errors", "]", "=", "$", "this", "->", "process", "(", ")", ";", "return", "$", "isValid", "===", "true", "...
Returns true if all rules passed and false if validation failed. @param array|null &$errors If $errors is provided, then it is filled with all the error messages @return bool
[ "Returns", "true", "if", "all", "rules", "passed", "and", "false", "if", "validation", "failed", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L494-L499
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.isInvalid
public function isInvalid(?array &$errors = null): bool { [$isValid, $errors] = $this->process(); return $isValid === false; }
php
public function isInvalid(?array &$errors = null): bool { [$isValid, $errors] = $this->process(); return $isValid === false; }
[ "public", "function", "isInvalid", "(", "?", "array", "&", "$", "errors", "=", "null", ")", ":", "bool", "{", "[", "$", "isValid", ",", "$", "errors", "]", "=", "$", "this", "->", "process", "(", ")", ";", "return", "$", "isValid", "===", "false", ...
Returns false if all rules passed and true if validation failed. @param array|null &$errors If $errors is provided, then it is filled with all the error messages @return bool
[ "Returns", "false", "if", "all", "rules", "passed", "and", "true", "if", "validation", "failed", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L507-L512
train
mako-framework/framework
src/mako/validator/Validator.php
Validator.validate
public function validate(): array { if($this->isInvalid()) { throw new ValidationException($this->errors, 'Invalid input.'); } $validated = []; foreach(array_keys($this->ruleSets) as $validatedKey) { if(Arr::has($this->input, $validatedKey)) { Arr::set($validated, $validatedKey, Arr::get($this->input, $validatedKey)); } } return $validated; }
php
public function validate(): array { if($this->isInvalid()) { throw new ValidationException($this->errors, 'Invalid input.'); } $validated = []; foreach(array_keys($this->ruleSets) as $validatedKey) { if(Arr::has($this->input, $validatedKey)) { Arr::set($validated, $validatedKey, Arr::get($this->input, $validatedKey)); } } return $validated; }
[ "public", "function", "validate", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "isInvalid", "(", ")", ")", "{", "throw", "new", "ValidationException", "(", "$", "this", "->", "errors", ",", "'Invalid input.'", ")", ";", "}", "$", "validat...
Validates the input and returns an array containing validated data. @throws \mako\validator\ValidationException @return array
[ "Validates", "the", "input", "and", "returns", "an", "array", "containing", "validated", "data", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/Validator.php#L520-L538
train
mako-framework/framework
src/mako/error/handlers/web/ProductionHandler.php
ProductionHandler.getStatusCodeAndMessage
protected function getStatusCodeAndMessage(Throwable $exception): array { if($exception instanceof HttpException) { $message = $exception->getMessage(); } if(empty($message)) { $message = 'An error has occurred while processing your request.'; } return ['code' => $this->getStatusCode($exception), 'message' => $message]; }
php
protected function getStatusCodeAndMessage(Throwable $exception): array { if($exception instanceof HttpException) { $message = $exception->getMessage(); } if(empty($message)) { $message = 'An error has occurred while processing your request.'; } return ['code' => $this->getStatusCode($exception), 'message' => $message]; }
[ "protected", "function", "getStatusCodeAndMessage", "(", "Throwable", "$", "exception", ")", ":", "array", "{", "if", "(", "$", "exception", "instanceof", "HttpException", ")", "{", "$", "message", "=", "$", "exception", "->", "getMessage", "(", ")", ";", "}...
Returns status code and message. @param \Throwable $exception Exception @return array
[ "Returns", "status", "code", "and", "message", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/error/handlers/web/ProductionHandler.php#L75-L88
train
mako-framework/framework
src/mako/error/handlers/web/ProductionHandler.php
ProductionHandler.getExceptionAsXml
protected function getExceptionAsXml(Throwable $exception): string { $details = $this->getStatusCodeAndMessage($exception); $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><error />"); $xml->addChild('code', $details['code']); $xml->addChild('message', $details['message']); return $xml->asXML(); }
php
protected function getExceptionAsXml(Throwable $exception): string { $details = $this->getStatusCodeAndMessage($exception); $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><error />"); $xml->addChild('code', $details['code']); $xml->addChild('message', $details['message']); return $xml->asXML(); }
[ "protected", "function", "getExceptionAsXml", "(", "Throwable", "$", "exception", ")", ":", "string", "{", "$", "details", "=", "$", "this", "->", "getStatusCodeAndMessage", "(", "$", "exception", ")", ";", "$", "xml", "=", "simplexml_load_string", "(", "\"<?x...
Return a XML representation of the exception. @param \Throwable $exception Exception @return string
[ "Return", "a", "XML", "representation", "of", "the", "exception", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/error/handlers/web/ProductionHandler.php#L107-L118
train
mako-framework/framework
src/mako/error/handlers/web/ProductionHandler.php
ProductionHandler.getExceptionAsRenderedView
protected function getExceptionAsRenderedView(Throwable $exception): string { $view = 'error'; if($exception instanceof HttpException) { $code = $exception->getCode(); if($this->view->exists('mako-error::' . $code)) { $view = $code; } } return $this->view->render('mako-error::' . $view); }
php
protected function getExceptionAsRenderedView(Throwable $exception): string { $view = 'error'; if($exception instanceof HttpException) { $code = $exception->getCode(); if($this->view->exists('mako-error::' . $code)) { $view = $code; } } return $this->view->render('mako-error::' . $view); }
[ "protected", "function", "getExceptionAsRenderedView", "(", "Throwable", "$", "exception", ")", ":", "string", "{", "$", "view", "=", "'error'", ";", "if", "(", "$", "exception", "instanceof", "HttpException", ")", "{", "$", "code", "=", "$", "exception", "-...
Returns a rendered error view. @param \Throwable $exception Exception @return string
[ "Returns", "a", "rendered", "error", "view", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/error/handlers/web/ProductionHandler.php#L126-L141
train
mako-framework/framework
src/mako/error/handlers/web/ProductionHandler.php
ProductionHandler.getBody
protected function getBody(Throwable $exception): string { if($this->returnAsJson()) { $this->response->setType('application/json'); return $this->getExceptionAsJson($exception); } if($this->returnAsXml()) { $this->response->setType('application/xml'); return $this->getExceptionAsXml($exception); } $this->response->setType('text/html'); return $this->getExceptionAsRenderedView($exception); }
php
protected function getBody(Throwable $exception): string { if($this->returnAsJson()) { $this->response->setType('application/json'); return $this->getExceptionAsJson($exception); } if($this->returnAsXml()) { $this->response->setType('application/xml'); return $this->getExceptionAsXml($exception); } $this->response->setType('text/html'); return $this->getExceptionAsRenderedView($exception); }
[ "protected", "function", "getBody", "(", "Throwable", "$", "exception", ")", ":", "string", "{", "if", "(", "$", "this", "->", "returnAsJson", "(", ")", ")", "{", "$", "this", "->", "response", "->", "setType", "(", "'application/json'", ")", ";", "retur...
Returns a response body. @param \Throwable $exception Exception @return string
[ "Returns", "a", "response", "body", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/error/handlers/web/ProductionHandler.php#L149-L168
train
mako-framework/framework
src/mako/gatekeeper/adapters/Adapter.php
Adapter.createUser
public function createUser(string $email, string $username, string $password, bool $activate = false, array $properties = []): User { $properties = [ 'email' => $email, 'username' => $username, 'password' => $password, 'activated' => $activate ? 1 : 0, ] + $properties; return $this->userRepository->createUser($properties); }
php
public function createUser(string $email, string $username, string $password, bool $activate = false, array $properties = []): User { $properties = [ 'email' => $email, 'username' => $username, 'password' => $password, 'activated' => $activate ? 1 : 0, ] + $properties; return $this->userRepository->createUser($properties); }
[ "public", "function", "createUser", "(", "string", "$", "email", ",", "string", "$", "username", ",", "string", "$", "password", ",", "bool", "$", "activate", "=", "false", ",", "array", "$", "properties", "=", "[", "]", ")", ":", "User", "{", "$", "...
Creates a new user and returns the user object. @param string $email Email address @param string $username Username @param string $password Password @param bool $activate Will activate the user if set to true @param array $properties Additional user properties @return \mako\gatekeeper\entities\user\User
[ "Creates", "a", "new", "user", "and", "returns", "the", "user", "object", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/adapters/Adapter.php#L113-L124
train
mako-framework/framework
src/mako/gatekeeper/adapters/Adapter.php
Adapter.createGroup
public function createGroup(string $name, array $properties = []): Group { $properties = [ 'name' => $name, ] + $properties; return $this->groupRepository->createGroup($properties); }
php
public function createGroup(string $name, array $properties = []): Group { $properties = [ 'name' => $name, ] + $properties; return $this->groupRepository->createGroup($properties); }
[ "public", "function", "createGroup", "(", "string", "$", "name", ",", "array", "$", "properties", "=", "[", "]", ")", ":", "Group", "{", "$", "properties", "=", "[", "'name'", "=>", "$", "name", ",", "]", "+", "$", "properties", ";", "return", "$", ...
Creates a new group and returns the group object. @param string $name Group name @param array $properties Additional group properties @return \mako\gatekeeper\entities\group\Group
[ "Creates", "a", "new", "group", "and", "returns", "the", "group", "object", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/adapters/Adapter.php#L133-L141
train
mako-framework/framework
src/mako/gatekeeper/adapters/Adapter.php
Adapter.activateUser
public function activateUser(string $token) { $user = $this->userRepository->getByActionToken($token); if($user === false) { return false; } $user->activate(); $user->generateActionToken(); $user->save(); return $user; }
php
public function activateUser(string $token) { $user = $this->userRepository->getByActionToken($token); if($user === false) { return false; } $user->activate(); $user->generateActionToken(); $user->save(); return $user; }
[ "public", "function", "activateUser", "(", "string", "$", "token", ")", "{", "$", "user", "=", "$", "this", "->", "userRepository", "->", "getByActionToken", "(", "$", "token", ")", ";", "if", "(", "$", "user", "===", "false", ")", "{", "return", "fals...
Activates a user based on the provided auth token. @param string $token Auth token @return \mako\gatekeeper\entities\user\User|bool
[ "Activates", "a", "user", "based", "on", "the", "provided", "auth", "token", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/adapters/Adapter.php#L149-L165
train
mako-framework/framework
src/mako/application/cli/commands/migrations/Command.php
Command.findApplicationMigrations
protected function findApplicationMigrations(): array { $migrations = []; foreach($this->fileSystem->glob($this->application->getPath() . '/migrations/*.php') as $migration) { $migrations[] = (object) ['package' => null, 'version' => $this->getBasename($migration)]; } return $migrations; }
php
protected function findApplicationMigrations(): array { $migrations = []; foreach($this->fileSystem->glob($this->application->getPath() . '/migrations/*.php') as $migration) { $migrations[] = (object) ['package' => null, 'version' => $this->getBasename($migration)]; } return $migrations; }
[ "protected", "function", "findApplicationMigrations", "(", ")", ":", "array", "{", "$", "migrations", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "fileSystem", "->", "glob", "(", "$", "this", "->", "application", "->", "getPath", "(", ")", "."...
Returns all application migrations. @return array
[ "Returns", "all", "application", "migrations", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/commands/migrations/Command.php#L139-L149
train
mako-framework/framework
src/mako/application/cli/commands/migrations/Command.php
Command.findPackageMigrations
protected function findPackageMigrations(): array { $migrations = []; foreach($this->application->getPackages() as $package) { foreach($this->fileSystem->glob($package->getPath() . '/src/migrations/*.php') as $migration) { $migrations[] = (object) ['package' => $package->getName(), 'version' => $this->getBasename($migration)]; } } return $migrations; }
php
protected function findPackageMigrations(): array { $migrations = []; foreach($this->application->getPackages() as $package) { foreach($this->fileSystem->glob($package->getPath() . '/src/migrations/*.php') as $migration) { $migrations[] = (object) ['package' => $package->getName(), 'version' => $this->getBasename($migration)]; } } return $migrations; }
[ "protected", "function", "findPackageMigrations", "(", ")", ":", "array", "{", "$", "migrations", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "application", "->", "getPackages", "(", ")", "as", "$", "package", ")", "{", "foreach", "(", "$", ...
Returns all package migrations. @return array
[ "Returns", "all", "package", "migrations", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/commands/migrations/Command.php#L156-L169
train
mako-framework/framework
src/mako/application/cli/commands/migrations/Command.php
Command.getFullyQualifiedMigration
protected function getFullyQualifiedMigration(object $migration): string { if(empty($migration->package)) { return $this->application->getNamespace(true) . '\\migrations\\' . $migration->version; } return $this->application->getPackage($migration->package)->getClassNamespace(true) . '\\migrations\\' . $migration->version; }
php
protected function getFullyQualifiedMigration(object $migration): string { if(empty($migration->package)) { return $this->application->getNamespace(true) . '\\migrations\\' . $migration->version; } return $this->application->getPackage($migration->package)->getClassNamespace(true) . '\\migrations\\' . $migration->version; }
[ "protected", "function", "getFullyQualifiedMigration", "(", "object", "$", "migration", ")", ":", "string", "{", "if", "(", "empty", "(", "$", "migration", "->", "package", ")", ")", "{", "return", "$", "this", "->", "application", "->", "getNamespace", "(",...
Returns the fully qualified class name of a migration. @param object $migration Migration @return string
[ "Returns", "the", "fully", "qualified", "class", "name", "of", "a", "migration", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/commands/migrations/Command.php#L187-L195
train
mako-framework/framework
src/mako/application/cli/commands/migrations/Command.php
Command.getMigrationsFilteredByConnection
protected function getMigrationsFilteredByConnection(): array { $migrations = $this->findMigrations(); $connectionName = $this->getConnectionName(); $defaultConnectionName = $this->getDefaultConnectionName(); foreach($migrations as $key => $migration) { $migrationConnectionName = (new ReflectionClass($this->getFullyQualifiedMigration($migration))) ->newInstanceWithoutConstructor() ->getConnectionName() ?? $defaultConnectionName; if($connectionName !== $migrationConnectionName) { unset($migrations[$key]); } } return $migrations; }
php
protected function getMigrationsFilteredByConnection(): array { $migrations = $this->findMigrations(); $connectionName = $this->getConnectionName(); $defaultConnectionName = $this->getDefaultConnectionName(); foreach($migrations as $key => $migration) { $migrationConnectionName = (new ReflectionClass($this->getFullyQualifiedMigration($migration))) ->newInstanceWithoutConstructor() ->getConnectionName() ?? $defaultConnectionName; if($connectionName !== $migrationConnectionName) { unset($migrations[$key]); } } return $migrations; }
[ "protected", "function", "getMigrationsFilteredByConnection", "(", ")", ":", "array", "{", "$", "migrations", "=", "$", "this", "->", "findMigrations", "(", ")", ";", "$", "connectionName", "=", "$", "this", "->", "getConnectionName", "(", ")", ";", "$", "de...
Returns migrations filtered by connection name. @return array
[ "Returns", "migrations", "filtered", "by", "connection", "name", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/commands/migrations/Command.php#L202-L223
train
mako-framework/framework
src/mako/application/cli/commands/migrations/Command.php
Command.getMigrated
protected function getMigrated(?int $batches = null): ResultSet { $query = $this->builder(); if($batches !== null && $batches > 0) { $query->where('batch', '>', ($this->builder()->max('batch') - $batches)); } return $query->select(['version', 'package'])->descending('version')->all(); }
php
protected function getMigrated(?int $batches = null): ResultSet { $query = $this->builder(); if($batches !== null && $batches > 0) { $query->where('batch', '>', ($this->builder()->max('batch') - $batches)); } return $query->select(['version', 'package'])->descending('version')->all(); }
[ "protected", "function", "getMigrated", "(", "?", "int", "$", "batches", "=", "null", ")", ":", "ResultSet", "{", "$", "query", "=", "$", "this", "->", "builder", "(", ")", ";", "if", "(", "$", "batches", "!==", "null", "&&", "$", "batches", ">", "...
Returns migrations that have been run. @param int|null $batches Number of batches fetch @return \mako\database\query\ResultSet
[ "Returns", "migrations", "that", "have", "been", "run", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/commands/migrations/Command.php#L231-L241
train
mako-framework/framework
src/mako/application/cli/commands/migrations/Command.php
Command.getOutstanding
protected function getOutstanding(): array { $migrations = $this->getMigrationsFilteredByConnection(); if(!empty($migrations)) { foreach($this->getMigrated() as $migrated) { foreach($migrations as $key => $migration) { if($migrated->package === $migration->package && $migrated->version === $migration->version) { unset($migrations[$key]); } } } usort($migrations, function($a, $b) { return strcmp($a->version, $b->version); }); } return $migrations; }
php
protected function getOutstanding(): array { $migrations = $this->getMigrationsFilteredByConnection(); if(!empty($migrations)) { foreach($this->getMigrated() as $migrated) { foreach($migrations as $key => $migration) { if($migrated->package === $migration->package && $migrated->version === $migration->version) { unset($migrations[$key]); } } } usort($migrations, function($a, $b) { return strcmp($a->version, $b->version); }); } return $migrations; }
[ "protected", "function", "getOutstanding", "(", ")", ":", "array", "{", "$", "migrations", "=", "$", "this", "->", "getMigrationsFilteredByConnection", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "migrations", ")", ")", "{", "foreach", "(", "$", "t...
Returns an array of all outstanding migrations. @return array
[ "Returns", "an", "array", "of", "all", "outstanding", "migrations", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/commands/migrations/Command.php#L248-L272
train
mako-framework/framework
src/mako/application/cli/commands/migrations/Command.php
Command.outputMigrationList
protected function outputMigrationList(array $migrations): void { $tableBody = []; foreach($migrations as $migration) { $name = $migration->version; if(!empty($migration->package)) { $name .= ' (' . $migration->package . ')'; } $description = $this->resolve($migration)->getDescription(); $tableBody[] = [$name, $description]; } $this->table(['Migration', 'Description'], $tableBody); }
php
protected function outputMigrationList(array $migrations): void { $tableBody = []; foreach($migrations as $migration) { $name = $migration->version; if(!empty($migration->package)) { $name .= ' (' . $migration->package . ')'; } $description = $this->resolve($migration)->getDescription(); $tableBody[] = [$name, $description]; } $this->table(['Migration', 'Description'], $tableBody); }
[ "protected", "function", "outputMigrationList", "(", "array", "$", "migrations", ")", ":", "void", "{", "$", "tableBody", "=", "[", "]", ";", "foreach", "(", "$", "migrations", "as", "$", "migration", ")", "{", "$", "name", "=", "$", "migration", "->", ...
Outputs a migration list. @param array $migrations Migrations
[ "Outputs", "a", "migration", "list", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/commands/migrations/Command.php#L279-L298
train
mako-framework/framework
src/mako/application/cli/commands/migrations/Command.php
Command.resolve
protected function resolve(object $migration): Migration { return $this->container->get($this->getFullyQualifiedMigration($migration)); }
php
protected function resolve(object $migration): Migration { return $this->container->get($this->getFullyQualifiedMigration($migration)); }
[ "protected", "function", "resolve", "(", "object", "$", "migration", ")", ":", "Migration", "{", "return", "$", "this", "->", "container", "->", "get", "(", "$", "this", "->", "getFullyQualifiedMigration", "(", "$", "migration", ")", ")", ";", "}" ]
Returns a migration instance. @param object $migration Migration meta @return \mako\database\migrations\Migration
[ "Returns", "a", "migration", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/commands/migrations/Command.php#L306-L309
train
mako-framework/framework
src/mako/application/cli/commands/migrations/Command.php
Command.runMigration
protected function runMigration(object $migration, string $method, ?int $batch = null): void { $migrationInstance = $this->resolve($migration); $migrationWrapper = $this->buildMigrationWrapper($migration, $migrationInstance, $method, $batch); if($migrationInstance->useTransaction()) { $migrationInstance->getConnection()->transaction(function() use ($migrationWrapper): void { $migrationWrapper(); }); return; } $migrationWrapper(); }
php
protected function runMigration(object $migration, string $method, ?int $batch = null): void { $migrationInstance = $this->resolve($migration); $migrationWrapper = $this->buildMigrationWrapper($migration, $migrationInstance, $method, $batch); if($migrationInstance->useTransaction()) { $migrationInstance->getConnection()->transaction(function() use ($migrationWrapper): void { $migrationWrapper(); }); return; } $migrationWrapper(); }
[ "protected", "function", "runMigration", "(", "object", "$", "migration", ",", "string", "$", "method", ",", "?", "int", "$", "batch", "=", "null", ")", ":", "void", "{", "$", "migrationInstance", "=", "$", "this", "->", "resolve", "(", "$", "migration",...
Executes a migration method. @param object $migration Migration meta @param string $method Migration method @param int|null $batch Batch
[ "Executes", "a", "migration", "method", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/application/cli/commands/migrations/Command.php#L346-L363
train
mako-framework/framework
src/mako/http/Response.php
Response.setType
public function setType(string $contentType, ?string $charset = null): Response { $this->contentType = $contentType; if($charset !== null) { $this->charset = $charset; } return $this; }
php
public function setType(string $contentType, ?string $charset = null): Response { $this->contentType = $contentType; if($charset !== null) { $this->charset = $charset; } return $this; }
[ "public", "function", "setType", "(", "string", "$", "contentType", ",", "?", "string", "$", "charset", "=", "null", ")", ":", "Response", "{", "$", "this", "->", "contentType", "=", "$", "contentType", ";", "if", "(", "$", "charset", "!==", "null", ")...
Sets the response content type. @param string $contentType Content type @param string|null $charset Charset @return \mako\http\Response
[ "Sets", "the", "response", "content", "type", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Response.php#L256-L266
train
mako-framework/framework
src/mako/http/Response.php
Response.clear
public function clear(): Response { $this->clearBody(); $this->headers->clear(); $this->cookies->clear(); return $this; }
php
public function clear(): Response { $this->clearBody(); $this->headers->clear(); $this->cookies->clear(); return $this; }
[ "public", "function", "clear", "(", ")", ":", "Response", "{", "$", "this", "->", "clearBody", "(", ")", ";", "$", "this", "->", "headers", "->", "clear", "(", ")", ";", "$", "this", "->", "cookies", "->", "clear", "(", ")", ";", "return", "$", "...
Clears the response body, cookies and headers. @return \mako\http\Response
[ "Clears", "the", "response", "body", "cookies", "and", "headers", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Response.php#L352-L361
train
mako-framework/framework
src/mako/http/Response.php
Response.sendHeaders
public function sendHeaders(): void { // Send status header $protocol = $this->request->getServer()->get('SERVER_PROTOCOL', 'HTTP/1.1'); header($protocol . ' ' . $this->statusCode . ' ' . $this->statusCodes[$this->statusCode]); // Send content type header $contentType = $this->contentType; if(stripos($contentType, 'text/') === 0 || in_array($contentType, ['application/json', 'application/xml', 'application/rss+xml', 'application/atom+xml'])) { $contentType .= '; charset=' . $this->charset; } header('Content-Type: ' . $contentType); // Send other headers foreach($this->headers->all() as $name => $values) { foreach($values as $value) { header($name . ': ' . $value, false); } } // Send cookie headers foreach($this->cookies->all() as $cookie) { ['raw' => $raw, 'name' => $name, 'value' => $value, 'options' => $options] = $cookie; if($raw) { setrawcookie($name, $value, $options['expires'], $options['path'], $options['domain'], $options['secure'], $options['httponly']); } else { setcookie($name, $value, $options['expires'], $options['path'], $options['domain'], $options['secure'], $options['httponly']); } } }
php
public function sendHeaders(): void { // Send status header $protocol = $this->request->getServer()->get('SERVER_PROTOCOL', 'HTTP/1.1'); header($protocol . ' ' . $this->statusCode . ' ' . $this->statusCodes[$this->statusCode]); // Send content type header $contentType = $this->contentType; if(stripos($contentType, 'text/') === 0 || in_array($contentType, ['application/json', 'application/xml', 'application/rss+xml', 'application/atom+xml'])) { $contentType .= '; charset=' . $this->charset; } header('Content-Type: ' . $contentType); // Send other headers foreach($this->headers->all() as $name => $values) { foreach($values as $value) { header($name . ': ' . $value, false); } } // Send cookie headers foreach($this->cookies->all() as $cookie) { ['raw' => $raw, 'name' => $name, 'value' => $value, 'options' => $options] = $cookie; if($raw) { setrawcookie($name, $value, $options['expires'], $options['path'], $options['domain'], $options['secure'], $options['httponly']); } else { setcookie($name, $value, $options['expires'], $options['path'], $options['domain'], $options['secure'], $options['httponly']); } } }
[ "public", "function", "sendHeaders", "(", ")", ":", "void", "{", "// Send status header", "$", "protocol", "=", "$", "this", "->", "request", "->", "getServer", "(", ")", "->", "get", "(", "'SERVER_PROTOCOL'", ",", "'HTTP/1.1'", ")", ";", "header", "(", "$...
Sends response headers.
[ "Sends", "response", "headers", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Response.php#L378-L422
train
mako-framework/framework
src/mako/http/Response.php
Response.send
public function send(): void { if($this->body instanceof ResponseSenderInterface) { // This is a response sender so we'll just pass it the // request and response instances and let it handle the rest itself $this->body->send($this->request, $this); } else { if($this->body instanceof ResponseBuilderInterface) { $this->body->build($this->request, $this); } $sendBody = true; // Make sure that output buffering is enabled if(ob_get_level() === 0) { ob_start(); } // Cast body to string in case it's an obect implementing __toString $this->body = (string) $this->body; // Check ETag if response cache is enabled if($this->responseCache === true) { $hash = '"' . hash('sha256', $this->body) . '"'; $this->headers->add('ETag', $hash); if(str_replace('-gzip', '', $this->request->getHeaders()->get('If-None-Match')) === $hash) { $this->setStatus(304); $sendBody = false; } } if($sendBody && !in_array($this->statusCode, [100, 101, 102, 204, 304])) { // Start compressed output buffering if output compression is enabled if($this->outputCompression) { ob_start('ob_gzhandler'); } echo $this->body; // If output compression is enabled then we'll have to flush the compressed buffer // so that we can get the compressed content length when setting the content-length header if($this->outputCompression) { ob_end_flush(); } // Add the content-length header if(!$this->headers->has('Transfer-Encoding')) { $this->headers->add('Content-Length', ob_get_length()); } } // Send the headers and flush the output buffer $this->sendHeaders(); ob_end_flush(); } }
php
public function send(): void { if($this->body instanceof ResponseSenderInterface) { // This is a response sender so we'll just pass it the // request and response instances and let it handle the rest itself $this->body->send($this->request, $this); } else { if($this->body instanceof ResponseBuilderInterface) { $this->body->build($this->request, $this); } $sendBody = true; // Make sure that output buffering is enabled if(ob_get_level() === 0) { ob_start(); } // Cast body to string in case it's an obect implementing __toString $this->body = (string) $this->body; // Check ETag if response cache is enabled if($this->responseCache === true) { $hash = '"' . hash('sha256', $this->body) . '"'; $this->headers->add('ETag', $hash); if(str_replace('-gzip', '', $this->request->getHeaders()->get('If-None-Match')) === $hash) { $this->setStatus(304); $sendBody = false; } } if($sendBody && !in_array($this->statusCode, [100, 101, 102, 204, 304])) { // Start compressed output buffering if output compression is enabled if($this->outputCompression) { ob_start('ob_gzhandler'); } echo $this->body; // If output compression is enabled then we'll have to flush the compressed buffer // so that we can get the compressed content length when setting the content-length header if($this->outputCompression) { ob_end_flush(); } // Add the content-length header if(!$this->headers->has('Transfer-Encoding')) { $this->headers->add('Content-Length', ob_get_length()); } } // Send the headers and flush the output buffer $this->sendHeaders(); ob_end_flush(); } }
[ "public", "function", "send", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "body", "instanceof", "ResponseSenderInterface", ")", "{", "// This is a response sender so we'll just pass it the", "// request and response instances and let it handle the rest itself", ...
Send output to browser.
[ "Send", "output", "to", "browser", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/Response.php#L475-L553
train
mako-framework/framework
src/mako/view/compilers/Template.php
Template.collectVerbatims
protected function collectVerbatims(string $template): string { return preg_replace_callback('/{%\s*verbatim\s*%}(.*?){%\s*endverbatim\s*%}/is', function($matches) { $this->verbatims[] = $matches[1]; return static::VERBATIM_PLACEHOLDER; }, $template); }
php
protected function collectVerbatims(string $template): string { return preg_replace_callback('/{%\s*verbatim\s*%}(.*?){%\s*endverbatim\s*%}/is', function($matches) { $this->verbatims[] = $matches[1]; return static::VERBATIM_PLACEHOLDER; }, $template); }
[ "protected", "function", "collectVerbatims", "(", "string", "$", "template", ")", ":", "string", "{", "return", "preg_replace_callback", "(", "'/{%\\s*verbatim\\s*%}(.*?){%\\s*endverbatim\\s*%}/is'", ",", "function", "(", "$", "matches", ")", "{", "$", "this", "->", ...
Collects verbatim blocks and replaces them with a palceholder. @param string $template Template @return string
[ "Collects", "verbatim", "blocks", "and", "replaces", "them", "with", "a", "palceholder", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/compilers/Template.php#L105-L113
train
mako-framework/framework
src/mako/view/compilers/Template.php
Template.insertVerbatims
public function insertVerbatims(string $template): string { foreach($this->verbatims as $verbatim) { $template = preg_replace('/' . static::VERBATIM_PLACEHOLDER . '/', $verbatim, $template, 1); } return $template; }
php
public function insertVerbatims(string $template): string { foreach($this->verbatims as $verbatim) { $template = preg_replace('/' . static::VERBATIM_PLACEHOLDER . '/', $verbatim, $template, 1); } return $template; }
[ "public", "function", "insertVerbatims", "(", "string", "$", "template", ")", ":", "string", "{", "foreach", "(", "$", "this", "->", "verbatims", "as", "$", "verbatim", ")", "{", "$", "template", "=", "preg_replace", "(", "'/'", ".", "static", "::", "VER...
Replaces verbatim placeholders with their original values. @param string $template Template @return string
[ "Replaces", "verbatim", "placeholders", "with", "their", "original", "values", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/compilers/Template.php#L121-L129
train
mako-framework/framework
src/mako/view/compilers/Template.php
Template.extensions
protected function extensions(string $template): string { // Replace first occurance of extends tag with an empty string // and append the template with a view tag if(preg_match('/^{%\s*extends:(.*?)\s*%}/i', $template, $matches) > 0) { $replacement = '<?php $__view__ = $__viewfactory__->create(' . $matches[1] . '); $__renderer__ = $__view__->getRenderer(); ?>'; $template = preg_replace('/^{%\s*extends:(.*?)\s*%}/i', $replacement, $template, 1); $template .= '<?php echo $__view__->render(); ?>'; } return $template; }
php
protected function extensions(string $template): string { // Replace first occurance of extends tag with an empty string // and append the template with a view tag if(preg_match('/^{%\s*extends:(.*?)\s*%}/i', $template, $matches) > 0) { $replacement = '<?php $__view__ = $__viewfactory__->create(' . $matches[1] . '); $__renderer__ = $__view__->getRenderer(); ?>'; $template = preg_replace('/^{%\s*extends:(.*?)\s*%}/i', $replacement, $template, 1); $template .= '<?php echo $__view__->render(); ?>'; } return $template; }
[ "protected", "function", "extensions", "(", "string", "$", "template", ")", ":", "string", "{", "// Replace first occurance of extends tag with an empty string", "// and append the template with a view tag", "if", "(", "preg_match", "(", "'/^{%\\s*extends:(.*?)\\s*%}/i'", ",", ...
Compiles template extensions. @param string $template Template @return string
[ "Compiles", "template", "extensions", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/compilers/Template.php#L150-L165
train
mako-framework/framework
src/mako/view/compilers/Template.php
Template.nospaces
protected function nospaces(string $template): string { // Compile regular nospace blocks $template = preg_replace_callback('/{%\s*nospace\s*%}(.*?){%\s*endnospace\s*%}/is', function($matches) { return trim(preg_replace('/>\s+</', '><', $matches[1])); }, $template); // Compile buffered nospace blocks $template = preg_replace('/{%\s*nospace:buffered\s*%}(.*?){%\s*endnospace\s*%}/is', '<?php ob_start(); ?>$1<?php echo trim(preg_replace(\'/>\s+</\', \'><\', ob_get_clean())); ?>', $template); return $template; }
php
protected function nospaces(string $template): string { // Compile regular nospace blocks $template = preg_replace_callback('/{%\s*nospace\s*%}(.*?){%\s*endnospace\s*%}/is', function($matches) { return trim(preg_replace('/>\s+</', '><', $matches[1])); }, $template); // Compile buffered nospace blocks $template = preg_replace('/{%\s*nospace:buffered\s*%}(.*?){%\s*endnospace\s*%}/is', '<?php ob_start(); ?>$1<?php echo trim(preg_replace(\'/>\s+</\', \'><\', ob_get_clean())); ?>', $template); return $template; }
[ "protected", "function", "nospaces", "(", "string", "$", "template", ")", ":", "string", "{", "// Compile regular nospace blocks", "$", "template", "=", "preg_replace_callback", "(", "'/{%\\s*nospace\\s*%}(.*?){%\\s*endnospace\\s*%}/is'", ",", "function", "(", "$", "match...
Compiles nospace blocks. @param string $template Template @return string
[ "Compiles", "nospace", "blocks", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/compilers/Template.php#L173-L187
train
mako-framework/framework
src/mako/view/compilers/Template.php
Template.captures
protected function captures(string $template): string { return preg_replace_callback('/{%\s*capture:(\$?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*?)\s*%}(.*?){%\s*endcapture\s*%}/is', function($matches) { return '<?php ob_start(); ?>' . $matches[2] . '<?php $' . ltrim($matches[1], '$') . ' = ob_get_clean(); ?>'; }, $template); }
php
protected function captures(string $template): string { return preg_replace_callback('/{%\s*capture:(\$?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*?)\s*%}(.*?){%\s*endcapture\s*%}/is', function($matches) { return '<?php ob_start(); ?>' . $matches[2] . '<?php $' . ltrim($matches[1], '$') . ' = ob_get_clean(); ?>'; }, $template); }
[ "protected", "function", "captures", "(", "string", "$", "template", ")", ":", "string", "{", "return", "preg_replace_callback", "(", "'/{%\\s*capture:(\\$?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*?)\\s*%}(.*?){%\\s*endcapture\\s*%}/is'", ",", "function", "(", "$", "matches"...
Compiles capture blocks. @param string $template Template @return string
[ "Compiles", "capture", "blocks", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/compilers/Template.php#L212-L218
train
mako-framework/framework
src/mako/view/compilers/Template.php
Template.echos
protected function echos(string $template): string { // Closure that matches the "empty else" syntax $emptyElse = function($matches) { if(preg_match('/(.*)((\|\|)|(\s+or\s+))(.+)/', $matches) !== 0) { return preg_replace_callback('/(.*)((\|\|)|(\s+or\s+))(.+)/', function($matches) { return '(empty(' . trim($matches[1]) . ') ? ' . trim($matches[5]) . ' : ' . trim($matches[1]) . ')'; }, $matches); } return $matches; }; // Compiles echo tags return preg_replace_callback('/{{\s*(.*?)\s*}}/', function($matches) use ($emptyElse) { if(preg_match('/raw\s*:(.*)/i', $matches[1]) > 0) { return sprintf('<?php echo %s; ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1))); } elseif(preg_match('/preserve\s*:(.*)/i', $matches[1]) > 0) { return sprintf('<?php echo $this->escapeHTML(%s, $__charset__, false); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1))); } elseif(preg_match('/attribute\s*:(.*)/i', $matches[1]) > 0) { return sprintf('<?php echo $this->escapeAttribute(%s, $__charset__); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1))); } elseif(preg_match('/js\s*:(.*)/i', $matches[1]) > 0) { return sprintf('<?php echo $this->escapeJavascript(%s, $__charset__); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1))); } elseif(preg_match('/css\s*:(.*)/i', $matches[1]) > 0) { return sprintf('<?php echo $this->escapeCSS(%s, $__charset__); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1))); } elseif(preg_match('/url\s*:(.*)/i', $matches[1]) > 0) { return sprintf('<?php echo $this->escapeURL(%s, $__charset__); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1))); } else { return sprintf('<?php echo $this->escapeHTML(%s, $__charset__); ?>', $emptyElse($matches[1])); } }, $template); }
php
protected function echos(string $template): string { // Closure that matches the "empty else" syntax $emptyElse = function($matches) { if(preg_match('/(.*)((\|\|)|(\s+or\s+))(.+)/', $matches) !== 0) { return preg_replace_callback('/(.*)((\|\|)|(\s+or\s+))(.+)/', function($matches) { return '(empty(' . trim($matches[1]) . ') ? ' . trim($matches[5]) . ' : ' . trim($matches[1]) . ')'; }, $matches); } return $matches; }; // Compiles echo tags return preg_replace_callback('/{{\s*(.*?)\s*}}/', function($matches) use ($emptyElse) { if(preg_match('/raw\s*:(.*)/i', $matches[1]) > 0) { return sprintf('<?php echo %s; ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1))); } elseif(preg_match('/preserve\s*:(.*)/i', $matches[1]) > 0) { return sprintf('<?php echo $this->escapeHTML(%s, $__charset__, false); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1))); } elseif(preg_match('/attribute\s*:(.*)/i', $matches[1]) > 0) { return sprintf('<?php echo $this->escapeAttribute(%s, $__charset__); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1))); } elseif(preg_match('/js\s*:(.*)/i', $matches[1]) > 0) { return sprintf('<?php echo $this->escapeJavascript(%s, $__charset__); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1))); } elseif(preg_match('/css\s*:(.*)/i', $matches[1]) > 0) { return sprintf('<?php echo $this->escapeCSS(%s, $__charset__); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1))); } elseif(preg_match('/url\s*:(.*)/i', $matches[1]) > 0) { return sprintf('<?php echo $this->escapeURL(%s, $__charset__); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1))); } else { return sprintf('<?php echo $this->escapeHTML(%s, $__charset__); ?>', $emptyElse($matches[1])); } }, $template); }
[ "protected", "function", "echos", "(", "string", "$", "template", ")", ":", "string", "{", "// Closure that matches the \"empty else\" syntax", "$", "emptyElse", "=", "function", "(", "$", "matches", ")", "{", "if", "(", "preg_match", "(", "'/(.*)((\\|\\|)|(\\s+or\\...
Compiles echos. @param string $template Template @return string
[ "Compiles", "echos", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/compilers/Template.php#L260-L310
train
mako-framework/framework
src/mako/view/compilers/Template.php
Template.compile
public function compile(): void { // Get teplate contents $contents = $this->fileSystem->get($this->template); // Compile template foreach($this->compileOrder as $method) { $contents = $this->$method($contents); } // Store compiled template $this->fileSystem->put($this->cachePath . '/' . md5($this->template) . '.php', trim($contents)); }
php
public function compile(): void { // Get teplate contents $contents = $this->fileSystem->get($this->template); // Compile template foreach($this->compileOrder as $method) { $contents = $this->$method($contents); } // Store compiled template $this->fileSystem->put($this->cachePath . '/' . md5($this->template) . '.php', trim($contents)); }
[ "public", "function", "compile", "(", ")", ":", "void", "{", "// Get teplate contents", "$", "contents", "=", "$", "this", "->", "fileSystem", "->", "get", "(", "$", "this", "->", "template", ")", ";", "// Compile template", "foreach", "(", "$", "this", "-...
Compiles templates into views.
[ "Compiles", "templates", "into", "views", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/view/compilers/Template.php#L315-L331
train
mako-framework/framework
src/mako/validator/ValidatorFactory.php
ValidatorFactory.create
public function create(array $input, array $rules): Validator { $validator = new Validator($input, $rules, $this->i18n, $this->container); foreach($this->rules as $rule => $ruleClass) { $validator->extend($rule, $ruleClass); } return $validator; }
php
public function create(array $input, array $rules): Validator { $validator = new Validator($input, $rules, $this->i18n, $this->container); foreach($this->rules as $rule => $ruleClass) { $validator->extend($rule, $ruleClass); } return $validator; }
[ "public", "function", "create", "(", "array", "$", "input", ",", "array", "$", "rules", ")", ":", "Validator", "{", "$", "validator", "=", "new", "Validator", "(", "$", "input", ",", "$", "rules", ",", "$", "this", "->", "i18n", ",", "$", "this", "...
Creates and returns a validator instance. @param array $input Array to validate @param array $rules Array of validation rules @return \mako\validator\Validator
[ "Creates", "and", "returns", "a", "validator", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/ValidatorFactory.php#L75-L85
train
mako-framework/framework
src/mako/error/handlers/web/DevelopmentHandler.php
DevelopmentHandler.getWhoopsHandler
protected function getWhoopsHandler(): WhoopsHandlerInterface { if($this->returnAsJson()) { return new JsonResponseHandler; } if($this->returnAsXml()) { return new XmlResponseHandler; } $handler = new PrettyPageHandler; $handler->handleUnconditionally(true); $handler->setApplicationPaths([$this->app->getPath()]); $handler->setPageTitle('Error'); $blacklist = $this->app->getConfig()->get('application.error_handler.debug_blacklist'); if(!empty($blacklist)) { foreach($blacklist as $superglobal => $keys) { foreach($keys as $key) { $handler->blacklist($superglobal, $key); } } } return $handler; }
php
protected function getWhoopsHandler(): WhoopsHandlerInterface { if($this->returnAsJson()) { return new JsonResponseHandler; } if($this->returnAsXml()) { return new XmlResponseHandler; } $handler = new PrettyPageHandler; $handler->handleUnconditionally(true); $handler->setApplicationPaths([$this->app->getPath()]); $handler->setPageTitle('Error'); $blacklist = $this->app->getConfig()->get('application.error_handler.debug_blacklist'); if(!empty($blacklist)) { foreach($blacklist as $superglobal => $keys) { foreach($keys as $key) { $handler->blacklist($superglobal, $key); } } } return $handler; }
[ "protected", "function", "getWhoopsHandler", "(", ")", ":", "WhoopsHandlerInterface", "{", "if", "(", "$", "this", "->", "returnAsJson", "(", ")", ")", "{", "return", "new", "JsonResponseHandler", ";", "}", "if", "(", "$", "this", "->", "returnAsXml", "(", ...
Returns a Whoops handler. @return \Whoops\Handler\HandlerInterface
[ "Returns", "a", "Whoops", "handler", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/error/handlers/web/DevelopmentHandler.php#L87-L121
train
mako-framework/framework
src/mako/error/handlers/web/DevelopmentHandler.php
DevelopmentHandler.configureWhoops
protected function configureWhoops(): void { $this->whoops->pushHandler($this->getWhoopsHandler()); $this->whoops->writeToOutput(false); $this->whoops->allowQuit(false); }
php
protected function configureWhoops(): void { $this->whoops->pushHandler($this->getWhoopsHandler()); $this->whoops->writeToOutput(false); $this->whoops->allowQuit(false); }
[ "protected", "function", "configureWhoops", "(", ")", ":", "void", "{", "$", "this", "->", "whoops", "->", "pushHandler", "(", "$", "this", "->", "getWhoopsHandler", "(", ")", ")", ";", "$", "this", "->", "whoops", "->", "writeToOutput", "(", "false", ")...
Configure Whoops.
[ "Configure", "Whoops", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/error/handlers/web/DevelopmentHandler.php#L126-L133
train
mako-framework/framework
src/mako/gatekeeper/authorization/Authorizer.php
Authorizer.policyFactory
protected function policyFactory($entity): PolicyInterface { $entityClass = is_object($entity) ? get_class($entity) : $entity; if(!isset($this->policies[$entityClass])) { throw new AuthorizerException(vsprintf('There is no authorization policy registered for [ %s ] entities.', [$entityClass])); } return $this->container->get($this->policies[$entityClass]); }
php
protected function policyFactory($entity): PolicyInterface { $entityClass = is_object($entity) ? get_class($entity) : $entity; if(!isset($this->policies[$entityClass])) { throw new AuthorizerException(vsprintf('There is no authorization policy registered for [ %s ] entities.', [$entityClass])); } return $this->container->get($this->policies[$entityClass]); }
[ "protected", "function", "policyFactory", "(", "$", "entity", ")", ":", "PolicyInterface", "{", "$", "entityClass", "=", "is_object", "(", "$", "entity", ")", "?", "get_class", "(", "$", "entity", ")", ":", "$", "entity", ";", "if", "(", "!", "isset", ...
Policy factory. @param object|string $entity Entity instance or class name @throws \mako\gatekeeper\authorization\AuthorizerException @return \mako\gatekeeper\authorization\policies\PolicyInterface
[ "Policy", "factory", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/authorization/Authorizer.php#L64-L74
train
mako-framework/framework
src/mako/database/query/ResultSet.php
ResultSet.toArray
public function toArray(): array { $results = []; foreach($this->items as $item) { $results[] = $item->toArray(); } return $results; }
php
public function toArray(): array { $results = []; foreach($this->items as $item) { $results[] = $item->toArray(); } return $results; }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "$", "results", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "items", "as", "$", "item", ")", "{", "$", "results", "[", "]", "=", "$", "item", "->", "toArray", "(", ")", ";...
Returns an array representation of the result set. @return array
[ "Returns", "an", "array", "representation", "of", "the", "result", "set", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/query/ResultSet.php#L67-L77
train
mako-framework/framework
src/mako/validator/rules/IP.php
IP.getFlags
protected function getFlags(): ?int { if($this->version === null) { return null; } switch($this->version) { case 'v4': return FILTER_FLAG_IPV4; case 'v6': return FILTER_FLAG_IPV6; default: throw new RuntimeException(vsprintf('Invalid IP version [ %s ]. The accepted versions are v4 and v6.', [$this->version])); } }
php
protected function getFlags(): ?int { if($this->version === null) { return null; } switch($this->version) { case 'v4': return FILTER_FLAG_IPV4; case 'v6': return FILTER_FLAG_IPV6; default: throw new RuntimeException(vsprintf('Invalid IP version [ %s ]. The accepted versions are v4 and v6.', [$this->version])); } }
[ "protected", "function", "getFlags", "(", ")", ":", "?", "int", "{", "if", "(", "$", "this", "->", "version", "===", "null", ")", "{", "return", "null", ";", "}", "switch", "(", "$", "this", "->", "version", ")", "{", "case", "'v4'", ":", "return",...
Returns the filter flags. @throws \RuntimeException @return int|null
[ "Returns", "the", "filter", "flags", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/rules/IP.php#L53-L69
train
mako-framework/framework
src/mako/cache/stores/Store.php
Store.getPrefixedKey
protected function getPrefixedKey(string $key): string { return empty($this->prefix) ? $key : $this->prefix . '.' . $key; }
php
protected function getPrefixedKey(string $key): string { return empty($this->prefix) ? $key : $this->prefix . '.' . $key; }
[ "protected", "function", "getPrefixedKey", "(", "string", "$", "key", ")", ":", "string", "{", "return", "empty", "(", "$", "this", "->", "prefix", ")", "?", "$", "key", ":", "$", "this", "->", "prefix", ".", "'.'", ".", "$", "key", ";", "}" ]
Returns a prefixed key. @param string $key Key @return string
[ "Returns", "a", "prefixed", "key", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cache/stores/Store.php#L53-L56
train
mako-framework/framework
src/mako/cache/stores/Store.php
Store.getAndPut
public function getAndPut(string $key, $data, int $ttl = 0) { $storedValue = $this->get($key); $this->put($key, $data, $ttl); return $storedValue; }
php
public function getAndPut(string $key, $data, int $ttl = 0) { $storedValue = $this->get($key); $this->put($key, $data, $ttl); return $storedValue; }
[ "public", "function", "getAndPut", "(", "string", "$", "key", ",", "$", "data", ",", "int", "$", "ttl", "=", "0", ")", "{", "$", "storedValue", "=", "$", "this", "->", "get", "(", "$", "key", ")", ";", "$", "this", "->", "put", "(", "$", "key",...
Fetch data from the cache and replace it. @param string $key Cache key @param mixed $data The data to store @param int $ttl Time to live @return mixed
[ "Fetch", "data", "from", "the", "cache", "and", "replace", "it", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cache/stores/Store.php#L79-L86
train
mako-framework/framework
src/mako/cache/stores/Store.php
Store.getAndRemove
public function getAndRemove(string $key) { $storedValue = $this->get($key); if($storedValue !== false) { $this->remove($key); } return $storedValue; }
php
public function getAndRemove(string $key) { $storedValue = $this->get($key); if($storedValue !== false) { $this->remove($key); } return $storedValue; }
[ "public", "function", "getAndRemove", "(", "string", "$", "key", ")", "{", "$", "storedValue", "=", "$", "this", "->", "get", "(", "$", "key", ")", ";", "if", "(", "$", "storedValue", "!==", "false", ")", "{", "$", "this", "->", "remove", "(", "$",...
Fetch data from the cache and remove it. @param string $key Cache key @return mixed
[ "Fetch", "data", "from", "the", "cache", "and", "remove", "it", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/cache/stores/Store.php#L94-L104
train
mako-framework/framework
src/mako/common/ConnectionManager.php
ConnectionManager.connection
public function connection(?string $connection = null) { $connection = $connection ?? $this->default; if(!isset($this->connections[$connection])) { $this->connections[$connection] = $this->connect($connection); } return $this->connections[$connection]; }
php
public function connection(?string $connection = null) { $connection = $connection ?? $this->default; if(!isset($this->connections[$connection])) { $this->connections[$connection] = $this->connect($connection); } return $this->connections[$connection]; }
[ "public", "function", "connection", "(", "?", "string", "$", "connection", "=", "null", ")", "{", "$", "connection", "=", "$", "connection", "??", "$", "this", "->", "default", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "connections", "[", ...
Returns the chosen connection. @param string|null $connection Connection name @return mixed
[ "Returns", "the", "chosen", "connection", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/common/ConnectionManager.php#L45-L55
train
mako-framework/framework
src/mako/common/ConnectionManager.php
ConnectionManager.close
public function close(?string $connection = null): void { $connection = $connection ?? $this->default; if(isset($this->connections[$connection])) { if(method_exists($this->connections[$connection], 'close')) { // Call close on the connection object in case there's a reference // to the connection that won't be garbage collected immediately $this->connections[$connection]->close(); } unset($this->connections[$connection]); } }
php
public function close(?string $connection = null): void { $connection = $connection ?? $this->default; if(isset($this->connections[$connection])) { if(method_exists($this->connections[$connection], 'close')) { // Call close on the connection object in case there's a reference // to the connection that won't be garbage collected immediately $this->connections[$connection]->close(); } unset($this->connections[$connection]); } }
[ "public", "function", "close", "(", "?", "string", "$", "connection", "=", "null", ")", ":", "void", "{", "$", "connection", "=", "$", "connection", "??", "$", "this", "->", "default", ";", "if", "(", "isset", "(", "$", "this", "->", "connections", "...
Closes the chosen connection. @param string|null $connection Connection name
[ "Closes", "the", "chosen", "connection", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/common/ConnectionManager.php#L62-L78
train
mako-framework/framework
src/mako/common/ConnectionManager.php
ConnectionManager.executeAndClose
public function executeAndClose(Closure $closure, ?string $connection = null) { $returnValue = $closure($this->connection($connection)); $this->close($connection); return $returnValue; }
php
public function executeAndClose(Closure $closure, ?string $connection = null) { $returnValue = $closure($this->connection($connection)); $this->close($connection); return $returnValue; }
[ "public", "function", "executeAndClose", "(", "Closure", "$", "closure", ",", "?", "string", "$", "connection", "=", "null", ")", "{", "$", "returnValue", "=", "$", "closure", "(", "$", "this", "->", "connection", "(", "$", "connection", ")", ")", ";", ...
Executes the passed closure using the chosen connection before closing it. @param \Closure $closure Closure to execute @param string|null $connection Connection name @return mixed
[ "Executes", "the", "passed", "closure", "using", "the", "chosen", "connection", "before", "closing", "it", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/common/ConnectionManager.php#L87-L94
train
mako-framework/framework
src/mako/http/response/Cookies.php
Cookies.add
public function add(string $name, string $value, int $ttl = 0, array $options = [], bool $raw = false): Cookies { $expires = ($ttl === 0) ? 0 : (time() + $ttl); $this->cookies[$name] = [ 'raw' => $raw, 'name' => $name, 'value' => $value, 'options' => ['expires' => $expires] + $options + $this->defaults, ]; return $this; }
php
public function add(string $name, string $value, int $ttl = 0, array $options = [], bool $raw = false): Cookies { $expires = ($ttl === 0) ? 0 : (time() + $ttl); $this->cookies[$name] = [ 'raw' => $raw, 'name' => $name, 'value' => $value, 'options' => ['expires' => $expires] + $options + $this->defaults, ]; return $this; }
[ "public", "function", "add", "(", "string", "$", "name", ",", "string", "$", "value", ",", "int", "$", "ttl", "=", "0", ",", "array", "$", "options", "=", "[", "]", ",", "bool", "$", "raw", "=", "false", ")", ":", "Cookies", "{", "$", "expires", ...
Adds a unsigned cookie. @param string $name Cookie name @param string $value Cookie value @param int $ttl Time to live - if omitted or set to 0 the cookie will expire when the browser closes @param array $options Cookie options @param bool $raw Set the cookie without urlencoding the value? @return \mako\http\response\Cookies
[ "Adds", "a", "unsigned", "cookie", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/http/response/Cookies.php#L106-L119
train
mako-framework/framework
src/mako/utility/Arr.php
Arr.get
public static function get(array $array, string $path, $default = null) { $segments = explode('.', $path); foreach($segments as $segment) { if(!is_array($array) || !array_key_exists($segment, $array)) { return $default; } $array = $array[$segment]; } return $array; }
php
public static function get(array $array, string $path, $default = null) { $segments = explode('.', $path); foreach($segments as $segment) { if(!is_array($array) || !array_key_exists($segment, $array)) { return $default; } $array = $array[$segment]; } return $array; }
[ "public", "static", "function", "get", "(", "array", "$", "array", ",", "string", "$", "path", ",", "$", "default", "=", "null", ")", "{", "$", "segments", "=", "explode", "(", "'.'", ",", "$", "path", ")", ";", "foreach", "(", "$", "segments", "as...
Returns value from array using "dot notation". @param array $array Array we're going to search @param string $path Array path @param mixed $default Default return value @return mixed
[ "Returns", "value", "from", "array", "using", "dot", "notation", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/utility/Arr.php#L90-L105
train
mako-framework/framework
src/mako/utility/Arr.php
Arr.expandKey
public static function expandKey(array $array, string $key): array { if(strpos($key, '*') === false) { throw new RuntimeException('The key must contain at least one wildcard character.'); } $keys = (array) $key; start: $expanded = []; foreach($keys as $key) { [$first, $remaining] = array_map('trim', explode('*', $key, 2), ['.', '.']); if(empty($first)) { $value = $array; } elseif(is_array($value = static::get($array, $first)) === false) { continue; } foreach(array_keys($value) as $key) { $expanded[] = trim($first . '.' . $key . '.' . $remaining, '.'); } } if(strpos($remaining, '*') !== false) { $keys = $expanded; goto start; } return $expanded; }
php
public static function expandKey(array $array, string $key): array { if(strpos($key, '*') === false) { throw new RuntimeException('The key must contain at least one wildcard character.'); } $keys = (array) $key; start: $expanded = []; foreach($keys as $key) { [$first, $remaining] = array_map('trim', explode('*', $key, 2), ['.', '.']); if(empty($first)) { $value = $array; } elseif(is_array($value = static::get($array, $first)) === false) { continue; } foreach(array_keys($value) as $key) { $expanded[] = trim($first . '.' . $key . '.' . $remaining, '.'); } } if(strpos($remaining, '*') !== false) { $keys = $expanded; goto start; } return $expanded; }
[ "public", "static", "function", "expandKey", "(", "array", "$", "array", ",", "string", "$", "key", ")", ":", "array", "{", "if", "(", "strpos", "(", "$", "key", ",", "'*'", ")", "===", "false", ")", "{", "throw", "new", "RuntimeException", "(", "'Th...
Expands a wildcard key to an array of "dot notation" keys. @param array $array Array @param string $key Wildcard key @throws \RuntimeException @return array
[ "Expands", "a", "wildcard", "key", "to", "an", "array", "of", "dot", "notation", "keys", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/utility/Arr.php#L184-L224
train
mako-framework/framework
src/mako/gatekeeper/adapters/Session.php
Session.authenticate
protected function authenticate($identifier, $password, $force = false) { $user = $this->userRepository->getByIdentifier($identifier); if($user !== false) { if($this->options['throttling']['enabled'] && $user->isLocked()) { return Gatekeeper::LOGIN_LOCKED; } if($force || $user->validatePassword($password)) { if(!$user->isActivated()) { return Gatekeeper::LOGIN_ACTIVATING; } if($user->isBanned()) { return Gatekeeper::LOGIN_BANNED; } if($this->options['throttling']['enabled']) { $user->resetThrottle(); } $this->user = $user; return true; } else { if($this->options['throttling']['enabled']) { $user->throttle($this->options['throttling']['max_attempts'], $this->options['throttling']['lock_time']); } } } return Gatekeeper::LOGIN_INCORRECT; }
php
protected function authenticate($identifier, $password, $force = false) { $user = $this->userRepository->getByIdentifier($identifier); if($user !== false) { if($this->options['throttling']['enabled'] && $user->isLocked()) { return Gatekeeper::LOGIN_LOCKED; } if($force || $user->validatePassword($password)) { if(!$user->isActivated()) { return Gatekeeper::LOGIN_ACTIVATING; } if($user->isBanned()) { return Gatekeeper::LOGIN_BANNED; } if($this->options['throttling']['enabled']) { $user->resetThrottle(); } $this->user = $user; return true; } else { if($this->options['throttling']['enabled']) { $user->throttle($this->options['throttling']['max_attempts'], $this->options['throttling']['lock_time']); } } } return Gatekeeper::LOGIN_INCORRECT; }
[ "protected", "function", "authenticate", "(", "$", "identifier", ",", "$", "password", ",", "$", "force", "=", "false", ")", "{", "$", "user", "=", "$", "this", "->", "userRepository", "->", "getByIdentifier", "(", "$", "identifier", ")", ";", "if", "(",...
Returns true if the identifier + password combination matches and the user is activated, not locked and not banned. A status code will be retured in all other situations. @param string $identifier User email or username @param string $password User password @param bool $force Skip the password check? @return bool|int
[ "Returns", "true", "if", "the", "identifier", "+", "password", "combination", "matches", "and", "the", "user", "is", "activated", "not", "locked", "and", "not", "banned", ".", "A", "status", "code", "will", "be", "retured", "in", "all", "other", "situations"...
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/adapters/Session.php#L176-L218
train
mako-framework/framework
src/mako/gatekeeper/adapters/Session.php
Session.setRememberMeCookie
protected function setRememberMeCookie(): void { if($this->options['cookie_options']['secure'] && !$this->request->isSecure()) { throw new RuntimeException('Attempted to set a secure cookie over a non-secure connection.'); } $this->response->getCookies()->addSigned($this->options['auth_key'], $this->user->getAccessToken(), (3600 * 24 * 365), $this->options['cookie_options']); }
php
protected function setRememberMeCookie(): void { if($this->options['cookie_options']['secure'] && !$this->request->isSecure()) { throw new RuntimeException('Attempted to set a secure cookie over a non-secure connection.'); } $this->response->getCookies()->addSigned($this->options['auth_key'], $this->user->getAccessToken(), (3600 * 24 * 365), $this->options['cookie_options']); }
[ "protected", "function", "setRememberMeCookie", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "options", "[", "'cookie_options'", "]", "[", "'secure'", "]", "&&", "!", "$", "this", "->", "request", "->", "isSecure", "(", ")", ")", "{", "thr...
Sets a remember me cookie. @throws \RuntimeException
[ "Sets", "a", "remember", "me", "cookie", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/adapters/Session.php#L225-L233
train
mako-framework/framework
src/mako/gatekeeper/adapters/Session.php
Session.forceLogin
public function forceLogin($identifier, $remember = false) { return $this->login($identifier, null, $remember, true); }
php
public function forceLogin($identifier, $remember = false) { return $this->login($identifier, null, $remember, true); }
[ "public", "function", "forceLogin", "(", "$", "identifier", ",", "$", "remember", "=", "false", ")", "{", "return", "$", "this", "->", "login", "(", "$", "identifier", ",", "null", ",", "$", "remember", ",", "true", ")", ";", "}" ]
Login a user without checking the password. Returns true if the identifier exists and the user is activated, not locked and not banned. A status code will be retured in all other situations. @param mixed $identifier User identifier @param bool $remember Set a remember me cookie? @return bool|int
[ "Login", "a", "user", "without", "checking", "the", "password", ".", "Returns", "true", "if", "the", "identifier", "exists", "and", "the", "user", "is", "activated", "not", "locked", "and", "not", "banned", ".", "A", "status", "code", "will", "be", "reture...
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/adapters/Session.php#L283-L286
train
mako-framework/framework
src/mako/gatekeeper/adapters/Session.php
Session.basicAuth
public function basicAuth(bool $clearResponse = false): bool { if($this->isLoggedIn() || $this->login($this->request->getUsername(), $this->request->getPassword()) === true) { return true; } if($clearResponse) { $this->response->clear(); } $this->response->getHeaders()->add('WWW-Authenticate', 'basic'); $this->response->setStatus(401); return false; }
php
public function basicAuth(bool $clearResponse = false): bool { if($this->isLoggedIn() || $this->login($this->request->getUsername(), $this->request->getPassword()) === true) { return true; } if($clearResponse) { $this->response->clear(); } $this->response->getHeaders()->add('WWW-Authenticate', 'basic'); $this->response->setStatus(401); return false; }
[ "public", "function", "basicAuth", "(", "bool", "$", "clearResponse", "=", "false", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "isLoggedIn", "(", ")", "||", "$", "this", "->", "login", "(", "$", "this", "->", "request", "->", "getUsername", ...
Returns a basic authentication response if login is required and null if not. @param bool $clearResponse Clear all previously set headers and cookies from the response? @return bool
[ "Returns", "a", "basic", "authentication", "response", "if", "login", "is", "required", "and", "null", "if", "not", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/gatekeeper/adapters/Session.php#L294-L311
train
mako-framework/framework
src/mako/i18n/I18n.php
I18n.loadInflection
protected function loadInflection(string $language): void { $this->inflections[$language] = $this->loader->loadInflection($language); }
php
protected function loadInflection(string $language): void { $this->inflections[$language] = $this->loader->loadInflection($language); }
[ "protected", "function", "loadInflection", "(", "string", "$", "language", ")", ":", "void", "{", "$", "this", "->", "inflections", "[", "$", "language", "]", "=", "$", "this", "->", "loader", "->", "loadInflection", "(", "$", "language", ")", ";", "}" ]
Loads inflection closure and rules. @param string $language Name of the language pack
[ "Loads", "inflection", "closure", "and", "rules", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/i18n/I18n.php#L147-L150
train
mako-framework/framework
src/mako/i18n/I18n.php
I18n.pluralize
public function pluralize(string $word, ?int $count = null, ?string $language = null): string { $language = $language ?? $this->language; if(!isset($this->inflections[$language])) { $this->loadInflection($language); } if(empty($this->inflections[$language])) { throw new I18nException(vsprintf('The [ %s ] language pack does not include any inflection rules.', [$language])); } $pluralizer = $this->inflections[$language]['pluralize']; return $pluralizer($word, (int) $count, $this->inflections[$language]['rules']); }
php
public function pluralize(string $word, ?int $count = null, ?string $language = null): string { $language = $language ?? $this->language; if(!isset($this->inflections[$language])) { $this->loadInflection($language); } if(empty($this->inflections[$language])) { throw new I18nException(vsprintf('The [ %s ] language pack does not include any inflection rules.', [$language])); } $pluralizer = $this->inflections[$language]['pluralize']; return $pluralizer($word, (int) $count, $this->inflections[$language]['rules']); }
[ "public", "function", "pluralize", "(", "string", "$", "word", ",", "?", "int", "$", "count", "=", "null", ",", "?", "string", "$", "language", "=", "null", ")", ":", "string", "{", "$", "language", "=", "$", "language", "??", "$", "this", "->", "l...
Returns the plural form of a noun. @param string $word Noun to pluralize @param int|null $count Number of nouns @param string|null $language Language rules to use for pluralization @throws \mako\i18n\I18nException @return string
[ "Returns", "the", "plural", "form", "of", "a", "noun", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/i18n/I18n.php#L161-L178
train
mako-framework/framework
src/mako/i18n/I18n.php
I18n.number
public function number(float $number, int $decimals = 0, ?string $decimalPoint = null, ?string $thousandsSeparator = null): string { static $defaults; if(empty($defaults)) { $localeconv = localeconv(); $defaults = [ 'decimal' => $localeconv['decimal_point'] ?: '.', 'thousands' => $localeconv['thousands_sep'] ?: ',', ]; } return number_format($number, $decimals, ($decimalPoint ?: $defaults['decimal']), ($thousandsSeparator ?: $defaults['thousands'])); }
php
public function number(float $number, int $decimals = 0, ?string $decimalPoint = null, ?string $thousandsSeparator = null): string { static $defaults; if(empty($defaults)) { $localeconv = localeconv(); $defaults = [ 'decimal' => $localeconv['decimal_point'] ?: '.', 'thousands' => $localeconv['thousands_sep'] ?: ',', ]; } return number_format($number, $decimals, ($decimalPoint ?: $defaults['decimal']), ($thousandsSeparator ?: $defaults['thousands'])); }
[ "public", "function", "number", "(", "float", "$", "number", ",", "int", "$", "decimals", "=", "0", ",", "?", "string", "$", "decimalPoint", "=", "null", ",", "?", "string", "$", "thousandsSeparator", "=", "null", ")", ":", "string", "{", "static", "$"...
Format number according to locale or desired format. @param float $number Number to format @param int $decimals Number of decimals @param string|null $decimalPoint Decimal point @param string|null $thousandsSeparator Thousands separator @return string
[ "Format", "number", "according", "to", "locale", "or", "desired", "format", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/i18n/I18n.php#L189-L205
train
mako-framework/framework
src/mako/i18n/I18n.php
I18n.loadFromCache
protected function loadFromCache(string $language, string $file): bool { $this->strings[$language] = $this->cache->get('mako.i18n.' . $language); return $this->strings[$language] !== false && isset($this->strings[$language][$file]); }
php
protected function loadFromCache(string $language, string $file): bool { $this->strings[$language] = $this->cache->get('mako.i18n.' . $language); return $this->strings[$language] !== false && isset($this->strings[$language][$file]); }
[ "protected", "function", "loadFromCache", "(", "string", "$", "language", ",", "string", "$", "file", ")", ":", "bool", "{", "$", "this", "->", "strings", "[", "$", "language", "]", "=", "$", "this", "->", "cache", "->", "get", "(", "'mako.i18n.'", "."...
Loads language strings from cache. @param string $language Name of the language pack @param string $file File from which we are loading the strings @return bool
[ "Loads", "language", "strings", "from", "cache", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/i18n/I18n.php#L225-L230
train
mako-framework/framework
src/mako/i18n/I18n.php
I18n.loadStrings
protected function loadStrings(string $language, string $file): void { if($this->cache !== null) { if($this->loadFromCache($language, $file)) { return; } $this->rebuildCache = true; } $this->strings[$language][$file] = $this->loader->loadStrings($language, $file); }
php
protected function loadStrings(string $language, string $file): void { if($this->cache !== null) { if($this->loadFromCache($language, $file)) { return; } $this->rebuildCache = true; } $this->strings[$language][$file] = $this->loader->loadStrings($language, $file); }
[ "protected", "function", "loadStrings", "(", "string", "$", "language", ",", "string", "$", "file", ")", ":", "void", "{", "if", "(", "$", "this", "->", "cache", "!==", "null", ")", "{", "if", "(", "$", "this", "->", "loadFromCache", "(", "$", "langu...
Loads all strings for the language. @param string $language Name of the language pack @param string $file File from which we are loading the strings
[ "Loads", "all", "strings", "for", "the", "language", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/i18n/I18n.php#L238-L251
train
mako-framework/framework
src/mako/i18n/I18n.php
I18n.getStrings
protected function getStrings(string $language, string $file): array { if(!isset($this->strings[$language][$file])) { $this->loadStrings($language, $file); } return $this->strings[$language][$file]; }
php
protected function getStrings(string $language, string $file): array { if(!isset($this->strings[$language][$file])) { $this->loadStrings($language, $file); } return $this->strings[$language][$file]; }
[ "protected", "function", "getStrings", "(", "string", "$", "language", ",", "string", "$", "file", ")", ":", "array", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "strings", "[", "$", "language", "]", "[", "$", "file", "]", ")", ")", "{", ...
Returns all strings from the chosen language file. @param string $language Name of the language pack @param string $file File from which we are getting the strings @return array
[ "Returns", "all", "strings", "from", "the", "chosen", "language", "file", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/i18n/I18n.php#L260-L268
train
mako-framework/framework
src/mako/i18n/I18n.php
I18n.has
public function has(string $key, ?string $language = null): bool { [$file, $string] = $this->parseKey($key); if($string === null) { return false; } $strings = $this->getStrings($language ?? $this->language, $file); return Arr::has($strings, $string) && is_string(Arr::get($strings, $string)); }
php
public function has(string $key, ?string $language = null): bool { [$file, $string] = $this->parseKey($key); if($string === null) { return false; } $strings = $this->getStrings($language ?? $this->language, $file); return Arr::has($strings, $string) && is_string(Arr::get($strings, $string)); }
[ "public", "function", "has", "(", "string", "$", "key", ",", "?", "string", "$", "language", "=", "null", ")", ":", "bool", "{", "[", "$", "file", ",", "$", "string", "]", "=", "$", "this", "->", "parseKey", "(", "$", "key", ")", ";", "if", "("...
Returns TRUE if the string exists and FALSE if not. @param string $key String to translate @param string|null $language Name of the language pack @return bool
[ "Returns", "TRUE", "if", "the", "string", "exists", "and", "FALSE", "if", "not", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/i18n/I18n.php#L277-L289
train
mako-framework/framework
src/mako/i18n/I18n.php
I18n.parsePluralizationTags
protected function parsePluralizationTags(string $string): string { return preg_replace_callback('/\<pluralize:([0-9]+)\>(\w*)\<\/pluralize\>/iu', function($matches) { return $this->pluralize($matches[2], (int) $matches[1]); }, $string); }
php
protected function parsePluralizationTags(string $string): string { return preg_replace_callback('/\<pluralize:([0-9]+)\>(\w*)\<\/pluralize\>/iu', function($matches) { return $this->pluralize($matches[2], (int) $matches[1]); }, $string); }
[ "protected", "function", "parsePluralizationTags", "(", "string", "$", "string", ")", ":", "string", "{", "return", "preg_replace_callback", "(", "'/\\<pluralize:([0-9]+)\\>(\\w*)\\<\\/pluralize\\>/iu'", ",", "function", "(", "$", "matches", ")", "{", "return", "$", "...
Pluralize words between pluralization tags. @param string $string String to parse @return string
[ "Pluralize", "words", "between", "pluralization", "tags", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/i18n/I18n.php#L297-L303
train
mako-framework/framework
src/mako/i18n/I18n.php
I18n.parseNumberTags
protected function parseNumberTags(string $string): string { return preg_replace_callback('/\<number(:([0-9]+)(,(.)(,(.))?)?)?\>([0-9-.e]*)\<\/number\>/iu', function($matches) { return $this->number((float) $matches[7], ($matches[2] ?: 0), $matches[4], $matches[6]); }, $string); }
php
protected function parseNumberTags(string $string): string { return preg_replace_callback('/\<number(:([0-9]+)(,(.)(,(.))?)?)?\>([0-9-.e]*)\<\/number\>/iu', function($matches) { return $this->number((float) $matches[7], ($matches[2] ?: 0), $matches[4], $matches[6]); }, $string); }
[ "protected", "function", "parseNumberTags", "(", "string", "$", "string", ")", ":", "string", "{", "return", "preg_replace_callback", "(", "'/\\<number(:([0-9]+)(,(.)(,(.))?)?)?\\>([0-9-.e]*)\\<\\/number\\>/iu'", ",", "function", "(", "$", "matches", ")", "{", "return", ...
Format numbers between number tags. @param string $string String to parse @return string
[ "Format", "numbers", "between", "number", "tags", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/i18n/I18n.php#L311-L317
train
mako-framework/framework
src/mako/i18n/I18n.php
I18n.get
public function get(string $key, array $vars = [], ?string $language = null): string { [$file, $string] = $this->parseKey($key); if($string === null) { return $key; } $string = Arr::get($this->getStrings($language ?? $this->language, $file), $string, $key); if(!empty($vars)) { $string = vsprintf($string, $vars); if(stripos($string, '</') !== false) { $string = $this->parseTags($string); } } return $string; }
php
public function get(string $key, array $vars = [], ?string $language = null): string { [$file, $string] = $this->parseKey($key); if($string === null) { return $key; } $string = Arr::get($this->getStrings($language ?? $this->language, $file), $string, $key); if(!empty($vars)) { $string = vsprintf($string, $vars); if(stripos($string, '</') !== false) { $string = $this->parseTags($string); } } return $string; }
[ "public", "function", "get", "(", "string", "$", "key", ",", "array", "$", "vars", "=", "[", "]", ",", "?", "string", "$", "language", "=", "null", ")", ":", "string", "{", "[", "$", "file", ",", "$", "string", "]", "=", "$", "this", "->", "par...
Returns the chosen string from the current language. @param string $key String to translate @param array $vars Array of values to replace in the translated text @param string|null $language Name of the language pack @return string
[ "Returns", "the", "chosen", "string", "from", "the", "current", "language", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/i18n/I18n.php#L348-L370
train
mako-framework/framework
src/mako/error/handlers/web/traits/HandlerHelperTrait.php
HandlerHelperTrait.returnAs
protected function returnAs(string $function, array $mimes, string $partial) { if(function_exists($function)) { $responseType = $this->response->getType(); if(in_array($responseType, $mimes) || strpos($responseType, $partial) !== false) { return true; } $accepts = $this->request->getHeaders()->getAcceptableContentTypes(); if(isset($accepts[0]) && (in_array($accepts[0], $mimes) || strpos($accepts[0], $partial) !== false)) { return true; } } return false; }
php
protected function returnAs(string $function, array $mimes, string $partial) { if(function_exists($function)) { $responseType = $this->response->getType(); if(in_array($responseType, $mimes) || strpos($responseType, $partial) !== false) { return true; } $accepts = $this->request->getHeaders()->getAcceptableContentTypes(); if(isset($accepts[0]) && (in_array($accepts[0], $mimes) || strpos($accepts[0], $partial) !== false)) { return true; } } return false; }
[ "protected", "function", "returnAs", "(", "string", "$", "function", ",", "array", "$", "mimes", ",", "string", "$", "partial", ")", "{", "if", "(", "function_exists", "(", "$", "function", ")", ")", "{", "$", "responseType", "=", "$", "this", "->", "r...
Checks if we meet the requirements to return as a specific type. @param string $function Required function @param array $mimes Mimetypes @param string $partial Partial mimetype @return bool
[ "Checks", "if", "we", "meet", "the", "requirements", "to", "return", "as", "a", "specific", "type", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/error/handlers/web/traits/HandlerHelperTrait.php#L35-L55
train
mako-framework/framework
src/mako/error/handlers/web/traits/HandlerHelperTrait.php
HandlerHelperTrait.sendResponse
protected function sendResponse(Response $response, Throwable $exception): void { if($exception instanceof MethodNotAllowedException) { $this->response->getHeaders()->add('Allow', implode(',', $exception->getAllowedMethods())); } $response->send(); }
php
protected function sendResponse(Response $response, Throwable $exception): void { if($exception instanceof MethodNotAllowedException) { $this->response->getHeaders()->add('Allow', implode(',', $exception->getAllowedMethods())); } $response->send(); }
[ "protected", "function", "sendResponse", "(", "Response", "$", "response", ",", "Throwable", "$", "exception", ")", ":", "void", "{", "if", "(", "$", "exception", "instanceof", "MethodNotAllowedException", ")", "{", "$", "this", "->", "response", "->", "getHea...
Sends response and adds any aditional headers. @param \mako\http\Response $response Response @param \Throwable $exception Exception
[ "Sends", "response", "and", "adds", "any", "aditional", "headers", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/error/handlers/web/traits/HandlerHelperTrait.php#L94-L102
train
mako-framework/framework
src/mako/validator/rules/traits/I18nAwareTrait.php
I18nAwareTrait.translateFieldName
protected function translateFieldName(string $field, string $package): string { // Return custom field name if we have one if($this->i18n->has(($i18nKey = $package . 'validate.overrides.fieldnames.' . $field))) { return $this->i18n->get($i18nKey); } // Return field a more human friendly field name return str_replace('_', ' ', $field); }
php
protected function translateFieldName(string $field, string $package): string { // Return custom field name if we have one if($this->i18n->has(($i18nKey = $package . 'validate.overrides.fieldnames.' . $field))) { return $this->i18n->get($i18nKey); } // Return field a more human friendly field name return str_replace('_', ' ', $field); }
[ "protected", "function", "translateFieldName", "(", "string", "$", "field", ",", "string", "$", "package", ")", ":", "string", "{", "// Return custom field name if we have one", "if", "(", "$", "this", "->", "i18n", "->", "has", "(", "(", "$", "i18nKey", "=", ...
Returns a translated field name. @param string $field Field name @param string $package Package prefix @return string
[ "Returns", "a", "translated", "field", "name", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/rules/traits/I18nAwareTrait.php#L55-L67
train
mako-framework/framework
src/mako/validator/rules/traits/I18nAwareTrait.php
I18nAwareTrait.getI18nParameters
protected function getI18nParameters(string $field, string $package): array { if(property_exists($this, 'i18nParameters')) { $parameters = array_map(function($value) { return is_array($value) ? implode(', ', $value) : $value; }, array_intersect_key(get_object_vars($this), array_flip($this->i18nParameters))); if(property_exists($this, 'i18nFieldNameParameters')) { foreach($this->i18nFieldNameParameters as $i18nField) { $parameters[$i18nField] = $this->translateFieldName($parameters[$i18nField], $package); } } return array_merge([$field], array_values($parameters)); } return [$field]; }
php
protected function getI18nParameters(string $field, string $package): array { if(property_exists($this, 'i18nParameters')) { $parameters = array_map(function($value) { return is_array($value) ? implode(', ', $value) : $value; }, array_intersect_key(get_object_vars($this), array_flip($this->i18nParameters))); if(property_exists($this, 'i18nFieldNameParameters')) { foreach($this->i18nFieldNameParameters as $i18nField) { $parameters[$i18nField] = $this->translateFieldName($parameters[$i18nField], $package); } } return array_merge([$field], array_values($parameters)); } return [$field]; }
[ "protected", "function", "getI18nParameters", "(", "string", "$", "field", ",", "string", "$", "package", ")", ":", "array", "{", "if", "(", "property_exists", "(", "$", "this", ",", "'i18nParameters'", ")", ")", "{", "$", "parameters", "=", "array_map", "...
Gets the i18n parameters. @param string $field Field name @param string $package Package prefix @return array
[ "Gets", "the", "i18n", "parameters", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/validator/rules/traits/I18nAwareTrait.php#L76-L97
train
mako-framework/framework
src/mako/database/connections/Connection.php
Connection.getConnectionOptions
protected function getConnectionOptions(): array { return $this->options + [ PDO::ATTR_PERSISTENT => $this->usePersistentConnection, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_STRINGIFY_FETCHES => false, PDO::ATTR_EMULATE_PREPARES => false, ]; }
php
protected function getConnectionOptions(): array { return $this->options + [ PDO::ATTR_PERSISTENT => $this->usePersistentConnection, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_STRINGIFY_FETCHES => false, PDO::ATTR_EMULATE_PREPARES => false, ]; }
[ "protected", "function", "getConnectionOptions", "(", ")", ":", "array", "{", "return", "$", "this", "->", "options", "+", "[", "PDO", "::", "ATTR_PERSISTENT", "=>", "$", "this", "->", "usePersistentConnection", ",", "PDO", "::", "ATTR_ERRMODE", "=>", "PDO", ...
Returns the connection options. @return array
[ "Returns", "the", "connection", "options", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/connections/Connection.php#L278-L288
train
mako-framework/framework
src/mako/database/connections/Connection.php
Connection.connect
protected function connect(): PDO { // Connect to the database try { $pdo = new PDO($this->dsn, $this->username, $this->password, $this->getConnectionOptions()); } catch(PDOException $e) { throw new RuntimeException(vsprintf('Failed to connect to the [ %s ] database. %s', [$this->name, $e->getMessage()])); } // Run queries foreach($this->onConnectQueries as $query) { $pdo->exec($query); } // Return PDO instance return $pdo; }
php
protected function connect(): PDO { // Connect to the database try { $pdo = new PDO($this->dsn, $this->username, $this->password, $this->getConnectionOptions()); } catch(PDOException $e) { throw new RuntimeException(vsprintf('Failed to connect to the [ %s ] database. %s', [$this->name, $e->getMessage()])); } // Run queries foreach($this->onConnectQueries as $query) { $pdo->exec($query); } // Return PDO instance return $pdo; }
[ "protected", "function", "connect", "(", ")", ":", "PDO", "{", "// Connect to the database", "try", "{", "$", "pdo", "=", "new", "PDO", "(", "$", "this", "->", "dsn", ",", "$", "this", "->", "username", ",", "$", "this", "->", "password", ",", "$", "...
Creates a PDO instance. @throws \RuntimeException @return \PDO
[ "Creates", "a", "PDO", "instance", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/connections/Connection.php#L296-L319
train
mako-framework/framework
src/mako/database/connections/Connection.php
Connection.prepareQueryForLog
protected function prepareQueryForLog(string $query, array $params): string { return preg_replace_callback('/\?/', function() use (&$params) { $param = array_shift($params); if(is_int($param) || is_float($param)) { return $param; } elseif(is_bool(($param))) { return $param ? 'TRUE' : 'FALSE'; } elseif(is_object($param)) { return get_class($param); } elseif(is_null($param)) { return 'NULL'; } elseif(is_resource($param)) { return 'resource'; } else { return $this->pdo->quote($param); } }, $query); }
php
protected function prepareQueryForLog(string $query, array $params): string { return preg_replace_callback('/\?/', function() use (&$params) { $param = array_shift($params); if(is_int($param) || is_float($param)) { return $param; } elseif(is_bool(($param))) { return $param ? 'TRUE' : 'FALSE'; } elseif(is_object($param)) { return get_class($param); } elseif(is_null($param)) { return 'NULL'; } elseif(is_resource($param)) { return 'resource'; } else { return $this->pdo->quote($param); } }, $query); }
[ "protected", "function", "prepareQueryForLog", "(", "string", "$", "query", ",", "array", "$", "params", ")", ":", "string", "{", "return", "preg_replace_callback", "(", "'/\\?/'", ",", "function", "(", ")", "use", "(", "&", "$", "params", ")", "{", "$", ...
Prepares query for logging. @param string $query SQL query @param array $params Query paramaters @return string
[ "Prepares", "query", "for", "logging", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/connections/Connection.php#L355-L386
train
mako-framework/framework
src/mako/database/connections/Connection.php
Connection.log
protected function log(string $query, array $params, float $start): void { $time = microtime(true) - $start; $query = $this->prepareQueryForLog($query, $params); $this->log[] = ['query' => $query, 'time' => $time]; }
php
protected function log(string $query, array $params, float $start): void { $time = microtime(true) - $start; $query = $this->prepareQueryForLog($query, $params); $this->log[] = ['query' => $query, 'time' => $time]; }
[ "protected", "function", "log", "(", "string", "$", "query", ",", "array", "$", "params", ",", "float", "$", "start", ")", ":", "void", "{", "$", "time", "=", "microtime", "(", "true", ")", "-", "$", "start", ";", "$", "query", "=", "$", "this", ...
Adds a query to the query log. @param string $query SQL query @param array $params Query parameters @param float $start Start time in microseconds
[ "Adds", "a", "query", "to", "the", "query", "log", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/connections/Connection.php#L395-L402
train
mako-framework/framework
src/mako/database/connections/Connection.php
Connection.prepareQueryAndParams
protected function prepareQueryAndParams(string $query, array $params): array { // Replace IN clause placeholder with escaped values replace: if(strpos($query, '([?])') !== false) { foreach($params as $key => $value) { if(is_array($value)) { array_splice($params, $key, 1, $value); $query = preg_replace('/\(\[\?\]\)/', '(' . trim(str_repeat('?, ', count($value)), ', ') . ')', $query, 1); goto replace; } } } // Return query and parameters return [$query, $params]; }
php
protected function prepareQueryAndParams(string $query, array $params): array { // Replace IN clause placeholder with escaped values replace: if(strpos($query, '([?])') !== false) { foreach($params as $key => $value) { if(is_array($value)) { array_splice($params, $key, 1, $value); $query = preg_replace('/\(\[\?\]\)/', '(' . trim(str_repeat('?, ', count($value)), ', ') . ')', $query, 1); goto replace; } } } // Return query and parameters return [$query, $params]; }
[ "protected", "function", "prepareQueryAndParams", "(", "string", "$", "query", ",", "array", "$", "params", ")", ":", "array", "{", "// Replace IN clause placeholder with escaped values", "replace", ":", "if", "(", "strpos", "(", "$", "query", ",", "'([?])'", ")",...
Prepare query and params. @param string $query SQL Query @param array $params Query parameters @return array
[ "Prepare", "query", "and", "params", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/connections/Connection.php#L429-L453
train
mako-framework/framework
src/mako/database/connections/Connection.php
Connection.isConnectionLostAndShouldItBeReestablished
protected function isConnectionLostAndShouldItBeReestablished(): bool { return ($this->reconnect === true && $this->inTransaction() === false && $this->isAlive() === false); }
php
protected function isConnectionLostAndShouldItBeReestablished(): bool { return ($this->reconnect === true && $this->inTransaction() === false && $this->isAlive() === false); }
[ "protected", "function", "isConnectionLostAndShouldItBeReestablished", "(", ")", ":", "bool", "{", "return", "(", "$", "this", "->", "reconnect", "===", "true", "&&", "$", "this", "->", "inTransaction", "(", ")", "===", "false", "&&", "$", "this", "->", "isA...
Should we try to reestablish the connection? @return bool
[ "Should", "we", "try", "to", "reestablish", "the", "connection?" ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/connections/Connection.php#L460-L463
train
mako-framework/framework
src/mako/database/connections/Connection.php
Connection.bindParameter
protected function bindParameter(PDOStatement $statement, int $key, $value): void { if(is_string($value)) { $type = PDO::PARAM_STR; } elseif(is_int($value)) { $type = PDO::PARAM_INT; } elseif(is_bool($value)) { $type = PDO::PARAM_BOOL; } elseif(is_null($value)) { $type = PDO::PARAM_NULL; } elseif(is_object($value) && $value instanceof TypeInterface) { $value = $value->getValue(); $type = $value->getType(); } elseif(is_resource($value)) { $type = PDO::PARAM_LOB; } else { $type = PDO::PARAM_STR; } $statement->bindValue($key + 1, $value, $type); }
php
protected function bindParameter(PDOStatement $statement, int $key, $value): void { if(is_string($value)) { $type = PDO::PARAM_STR; } elseif(is_int($value)) { $type = PDO::PARAM_INT; } elseif(is_bool($value)) { $type = PDO::PARAM_BOOL; } elseif(is_null($value)) { $type = PDO::PARAM_NULL; } elseif(is_object($value) && $value instanceof TypeInterface) { $value = $value->getValue(); $type = $value->getType(); } elseif(is_resource($value)) { $type = PDO::PARAM_LOB; } else { $type = PDO::PARAM_STR; } $statement->bindValue($key + 1, $value, $type); }
[ "protected", "function", "bindParameter", "(", "PDOStatement", "$", "statement", ",", "int", "$", "key", ",", "$", "value", ")", ":", "void", "{", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "type", "=", "PDO", "::", "PARAM_STR", "...
Binds parameter to the prepared statement. @param \PDOStatement $statement PDO statement @param int $key Parameter key @param mixed $value Parameter value
[ "Binds", "parameter", "to", "the", "prepared", "statement", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/connections/Connection.php#L472-L506
train
mako-framework/framework
src/mako/database/connections/Connection.php
Connection.execute
protected function execute(array $prepared): bool { if($this->enableLog) { $start = microtime(true); } $result = $prepared['statement']->execute(); if($this->enableLog) { $this->log($prepared['query'], $prepared['params'], $start); } return $result; }
php
protected function execute(array $prepared): bool { if($this->enableLog) { $start = microtime(true); } $result = $prepared['statement']->execute(); if($this->enableLog) { $this->log($prepared['query'], $prepared['params'], $start); } return $result; }
[ "protected", "function", "execute", "(", "array", "$", "prepared", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "enableLog", ")", "{", "$", "start", "=", "microtime", "(", "true", ")", ";", "}", "$", "result", "=", "$", "prepared", "[", "'s...
Executes the prepared query and returns TRUE on success or FALSE on failure. @param array $prepared Prepared query @return bool
[ "Executes", "the", "prepared", "query", "and", "returns", "TRUE", "on", "success", "or", "FALSE", "on", "failure", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/connections/Connection.php#L560-L575
train
mako-framework/framework
src/mako/database/connections/Connection.php
Connection.query
public function query(string $query, array $params = []): bool { return $this->execute($this->prepare($query, $params)); }
php
public function query(string $query, array $params = []): bool { return $this->execute($this->prepare($query, $params)); }
[ "public", "function", "query", "(", "string", "$", "query", ",", "array", "$", "params", "=", "[", "]", ")", ":", "bool", "{", "return", "$", "this", "->", "execute", "(", "$", "this", "->", "prepare", "(", "$", "query", ",", "$", "params", ")", ...
Executes the query and returns TRUE on success or FALSE on failure. @param string $query SQL query @param array $params Query parameters @return bool
[ "Executes", "the", "query", "and", "returns", "TRUE", "on", "success", "or", "FALSE", "on", "failure", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/connections/Connection.php#L584-L587
train
mako-framework/framework
src/mako/database/connections/Connection.php
Connection.queryAndCount
public function queryAndCount(string $query, array $params = []): int { $prepared = $this->prepare($query, $params); $this->execute($prepared); return $prepared['statement']->rowCount(); }
php
public function queryAndCount(string $query, array $params = []): int { $prepared = $this->prepare($query, $params); $this->execute($prepared); return $prepared['statement']->rowCount(); }
[ "public", "function", "queryAndCount", "(", "string", "$", "query", ",", "array", "$", "params", "=", "[", "]", ")", ":", "int", "{", "$", "prepared", "=", "$", "this", "->", "prepare", "(", "$", "query", ",", "$", "params", ")", ";", "$", "this", ...
Executes the query and return number of affected rows. @param string $query SQL query @param array $params Query parameters @return int
[ "Executes", "the", "query", "and", "return", "number", "of", "affected", "rows", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/connections/Connection.php#L596-L603
train
mako-framework/framework
src/mako/database/connections/Connection.php
Connection.column
public function column(string $query, array $params = []) { $prepared = $this->prepare($query, $params); $this->execute($prepared); return $prepared['statement']->fetchColumn(); }
php
public function column(string $query, array $params = []) { $prepared = $this->prepare($query, $params); $this->execute($prepared); return $prepared['statement']->fetchColumn(); }
[ "public", "function", "column", "(", "string", "$", "query", ",", "array", "$", "params", "=", "[", "]", ")", "{", "$", "prepared", "=", "$", "this", "->", "prepare", "(", "$", "query", ",", "$", "params", ")", ";", "$", "this", "->", "execute", ...
Returns the value of the first column of the first row of the result set. @param string $query SQL query @param array $params Query parameters @return mixed
[ "Returns", "the", "value", "of", "the", "first", "column", "of", "the", "first", "row", "of", "the", "result", "set", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/connections/Connection.php#L612-L619
train
mako-framework/framework
src/mako/database/connections/Connection.php
Connection.first
public function first(string $query, array $params = [], ...$fetchMode) { $prepared = $this->prepare($query, $params); $this->execute($prepared); if(!empty($fetchMode)) { $prepared['statement']->setFetchMode(...$fetchMode); } return $prepared['statement']->fetch(); }
php
public function first(string $query, array $params = [], ...$fetchMode) { $prepared = $this->prepare($query, $params); $this->execute($prepared); if(!empty($fetchMode)) { $prepared['statement']->setFetchMode(...$fetchMode); } return $prepared['statement']->fetch(); }
[ "public", "function", "first", "(", "string", "$", "query", ",", "array", "$", "params", "=", "[", "]", ",", "...", "$", "fetchMode", ")", "{", "$", "prepared", "=", "$", "this", "->", "prepare", "(", "$", "query", ",", "$", "params", ")", ";", "...
Returns the first row of the result set. @param string $query SQL query @param array $params Query params @param mixed ...$fetchMode Fetch mode @return mixed
[ "Returns", "the", "first", "row", "of", "the", "result", "set", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/connections/Connection.php#L653-L665
train
mako-framework/framework
src/mako/database/connections/Connection.php
Connection.transaction
public function transaction(Closure $queries) { try { $this->beginTransaction(); $returnValue = $queries($this); $this->commitTransaction(); } catch(PDOException $e) { $this->rollBackTransaction(); throw $e; } return $returnValue; }
php
public function transaction(Closure $queries) { try { $this->beginTransaction(); $returnValue = $queries($this); $this->commitTransaction(); } catch(PDOException $e) { $this->rollBackTransaction(); throw $e; } return $returnValue; }
[ "public", "function", "transaction", "(", "Closure", "$", "queries", ")", "{", "try", "{", "$", "this", "->", "beginTransaction", "(", ")", ";", "$", "returnValue", "=", "$", "queries", "(", "$", "this", ")", ";", "$", "this", "->", "commitTransaction", ...
Executes queries and rolls back the transaction if any of them fail. @param \Closure $queries Queries @throws \PDOException @return mixed
[ "Executes", "queries", "and", "rolls", "back", "the", "transaction", "if", "any", "of", "them", "fail", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/connections/Connection.php#L840-L858
train
mako-framework/framework
src/mako/database/midgard/ResultSet.php
ResultSet.protect
public function protect($column): void { foreach($this->items as $item) { $item->protect($column); } }
php
public function protect($column): void { foreach($this->items as $item) { $item->protect($column); } }
[ "public", "function", "protect", "(", "$", "column", ")", ":", "void", "{", "foreach", "(", "$", "this", "->", "items", "as", "$", "item", ")", "{", "$", "item", "->", "protect", "(", "$", "column", ")", ";", "}", "}" ]
Excludes the chosen columns and relations from array and json representations of the collection. @param string|array|bool $column Column or relation to hide from the
[ "Excludes", "the", "chosen", "columns", "and", "relations", "from", "array", "and", "json", "representations", "of", "the", "collection", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/ResultSet.php#L35-L41
train
mako-framework/framework
src/mako/database/midgard/ResultSet.php
ResultSet.expose
public function expose($column): void { foreach($this->items as $item) { $item->expose($column); } }
php
public function expose($column): void { foreach($this->items as $item) { $item->expose($column); } }
[ "public", "function", "expose", "(", "$", "column", ")", ":", "void", "{", "foreach", "(", "$", "this", "->", "items", "as", "$", "item", ")", "{", "$", "item", "->", "expose", "(", "$", "column", ")", ";", "}", "}" ]
Exposes the chosen columns and relations in the array and json representations of the collection. @param string|array|bool $column Column or relation to hide from the
[ "Exposes", "the", "chosen", "columns", "and", "relations", "in", "the", "array", "and", "json", "representations", "of", "the", "collection", "." ]
35600160f83cdff5b0459823f54c8d4c5cb602a4
https://github.com/mako-framework/framework/blob/35600160f83cdff5b0459823f54c8d4c5cb602a4/src/mako/database/midgard/ResultSet.php#L48-L54
train