sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
public function boot(Application $app) { $app->on(KernelEvents::EXCEPTION, function (GetResponseForExceptionEvent $event) { $e = $event->getException(); if ($e instanceof MethodNotAllowedHttpException && $e->getHeaders()["Allow"] === "OPTIONS") { $event->setException(...
Add OPTIONS method support for all routes @param Application $app
entailment
public function register(Container $app) { $app["cors.allowOrigin"] = "*"; // Defaults to all $app["cors.allowMethods"] = null; // Defaults to all $app["cors.allowHeaders"] = null; // Defaults to all $app["cors.maxAge"] = null; $app["cors.allowCredentials"] = null; $a...
Register the cors function and set defaults @param Container $app
entailment
public function boot(Router $router) { $this->publishes([ __DIR__ . '/Config/version.php' => config_path('version.php'), ], 'version'); $this->app->singleton('version', function ($app) { return new Version($app); }); }
Bootstrap the application services. @param Router $router @return void
entailment
protected function initiate() { $name = $this->name; $data = ['acl' => [], 'actions' => [], 'roles' => []]; $data = \array_merge($data, $this->memory->get("acl_{$name}", [])); // Loop through all the roles and actions in memory and add it to // this ACL instance. $th...
Initiate ACL data from memory. @return $this
entailment
public function allow($roles, $actions, bool $allow = true) { $this->setAuthorization($roles, $actions, $allow); return $this->sync(); }
Assign single or multiple $roles + $actions to have access. @param string|array $roles A string or an array of roles @param string|array $actions A string or an array of action name @param bool $allow @return $this
entailment
public function canIf(string $action): bool { $roles = $this->getUserRoles(); $action = Keyword::make($action); if (\is_null($this->actions->search($action))) { return false; } return $this->checkAuthorization($roles, $action); }
Verify whether current user has sufficient roles to access the actions based on available type of access if the action exist. @param string $action A string of action name @return bool
entailment
public function canAs(Authorizable $user, string $action): bool { $this->setUser($user); $permission = $this->can($action); $this->revokeUser(); return $permission; }
Verify whether current user has sufficient roles to access the actions based on available type of access. @param \Orchestra\Contracts\Authorization\Authorizable $user @param string $action A string of action name @throws \InvalidArgumentException @return bool
entailment
public function canIfAs(Authorizable $user, string $action): bool { $this->setUser($user); $permission = $this->canIf($action); $this->revokeUser(); return $permission; }
Verify whether current user has sufficient roles to access the actions based on available type of access if the action exist. @param \Orchestra\Contracts\Authorization\Authorizable $user @param string $action A string of action name @return bool
entailment
public function sync() { if ($this->attached()) { $name = $this->name; $this->memory->put("acl_{$name}", [ 'acl' => $this->acl, 'actions' => $this->actions->get(), 'roles' => $this->roles->get(), ]); } retu...
Sync memory with ACL instance, make sure anything that added before ->with($memory) got called is appended to memory as well. @return $this
entailment
public function execute(string $type, string $operation, array $parameters = []) { return $this->{$type}->{$operation}(...$parameters); }
Forward call to roles or actions. @param string $type 'roles' or 'actions' @param string $operation @param array $parameters @return \Orchestra\Authorization\Fluent
entailment
protected function resolveDynamicExecution(string $method): array { // Preserve legacy CRUD structure for actions and roles. $method = Str::snake($method, '_'); $matcher = '/^(add|rename|has|get|remove|fill|attach|detach)_(role|action)(s?)$/'; if (! \preg_match($matcher, $method, $m...
Dynamically resolve operation name especially to resolve attach and detach multiple actions or roles. @param string $method @throws \InvalidArgumentException @return array
entailment
protected function resolveOperationName(string $operation, bool $multiple = true): string { if (! $multiple) { return $operation; } elseif (\in_array($operation, ['fill', 'add'])) { return 'attach'; } return 'detach'; }
Dynamically resolve operation name especially when multiple operation was used. @param string $operation @param bool $multiple @return string
entailment
public function setAuthorization(FactoryContract $factory) { $this->acl = $factory->make($this->getAuthorizationName()); return $this; }
Set authorization driver. @param \Orchestra\Contracts\Authorization\Factory $factory @return $this
entailment
protected function can(string $action, ?Authorizable $user = null): bool { return ! \is_null($user) ? $this->acl->canAs($user, $action) : $this->acl->can($action); }
Resolve if authorization can. @param string $action @param \Orchestra\Contracts\Authorization\Authorizable|null $user @return bool
entailment
protected function canIf(string $action, ?Authorizable $user = null): bool { return ! \is_null($user) ? $this->acl->canIfAs($user, $action) : $this->acl->canIf($action); }
Resolve if authorization can if action exists. @param string $action @param \Orchestra\Contracts\Authorization\Authorizable|null $user @return bool
entailment
public function set($key, $value) { if (is_array($value)) { $settings = array_replace($this->defaults, $value); } else { $settings = array_replace($this->defaults, array('value' => $value)); } parent::set($key, $settings); }
Set cookie The second argument may be a single scalar value, in which case it will be merged with the default settings and considered the `value` of the merged result. The second argument may also be an array containing any or all of the keys shown in the default settings above. This array will be merged with the def...
entailment
public function remove($key, $settings = array()) { $settings['value'] = ''; $settings['expires'] = time() - 86400; $this->set($key, array_replace($this->defaults, $settings)); }
Remove cookie Unlike \Slim\Collection, this will actually *set* a cookie with an expiration date in the past. This expiration date will force the client-side cache to remove its cookie with the given name and settings. @param string $key Cookie name @param array $settings Optional cookie settings @api
entailment
public function encrypt(CryptInterface $crypt) { foreach ($this as $name => $settings) { $settings['value'] = $crypt->encrypt($settings['value']); $this->set($name, $settings); } }
Encrypt cookies This method iterates and encrypts data values. @param \Slim\Interfaces\CryptInterface $crypt @api
entailment
public function setHeaders(HeadersInterface &$headers) { foreach ($this->data as $name => $settings) { $this->setHeader($headers, $name, $settings); } }
Serialize this collection of cookies into a raw HTTP header @param \Slim\Interfaces\Http\HeadersInterface $headers @api
entailment
public function setHeader(HeadersInterface &$headers, $name, $value) { $values = array(); if (is_array($value)) { if (isset($value['domain']) && $value['domain']) { $values[] = '; domain=' . $value['domain']; } if (isset($value['path']) && $value...
Set HTTP cookie header This method will construct and set the HTTP `Set-Cookie` header. Slim uses this method instead of PHP's native `setcookie` method. This allows more control of the HTTP header irrespective of the native implementation's dependency on PHP versions. This method accepts the \Slim\Http\Headers objec...
entailment
public function deleteHeader(HeadersInterface &$headers, $name, $value = array()) { $crumbs = ($headers->has('Set-Cookie') ? explode("\n", $headers->get('Set-Cookie')) : array()); $cookies = array(); foreach ($crumbs as $crumb) { if (isset($value['domain']) && $value['domain']) ...
Delete HTTP cookie header This method will construct and set the HTTP `Set-Cookie` header to invalidate a client-side HTTP cookie. If a cookie with the same name (and, optionally, domain) is already set in the HTTP response, it will also be removed. Slim uses this method instead of PHP's native `setcookie` method. Thi...
entailment
public function parseHeader($header) { $header = rtrim($header, "\r\n"); $pieces = preg_split('@\s*[;,]\s*@', $header); $cookies = array(); foreach ($pieces as $cookie) { $cookie = explode('=', $cookie, 2); if (count($cookie) === 2) { $key = ...
Parse cookie header This method will parse the HTTP request's `Cookie` header and extract an associative array of cookie names and values. @param string $header @return array @api
entailment
public function getReasonPhrase() { if (isset(static::$messages[$this->status]) === true) { return static::$messages[$this->status]; } return null; }
Get response reason phrase @return string @api
entailment
public function addHeaders(array $headers) { foreach ($headers as $name => $value) { $this->headers->add($name, $value); } }
Add multiple header values @param array $headers @api
entailment
public function write($body, $overwrite = false) { if ($overwrite === true) { $this->body->close(); $this->body = new \Guzzle\Stream\Stream(fopen('php://temp', 'r+')); } $this->body->write($body); }
Append response body @param string $body Content to append to the current HTTP response body @param bool $overwrite Clear the existing body before writing new content? @api
entailment
public function finalize(\Slim\Interfaces\Http\RequestInterface $request) { $sendBody = true; if (in_array($this->status, array(204, 304)) === true) { $this->headers->remove('Content-Type'); $this->headers->remove('Content-Length'); $sendBody = false; } e...
Finalize response for delivery to client Apply final preparations to the resposne object so that it is suitable for delivery to the client. @param \Slim\Interfaces\Http\RequestInterface $request @return \Slim\Interfaces\Http\Response Self @api
entailment
public function send() { // Send headers if (headers_sent() === false) { if (strpos(PHP_SAPI, 'cgi') === 0) { header(sprintf('Status: %s', $this->getReasonPhrase())); } else { header(sprintf('%s %s', $this->getProtocolVersion(), $this->getReaso...
Send HTTP response headers and body @return \Slim\Interfaces\Http\Response Self @api
entailment
public function redirect($url, $status = 302) { $this->setStatus($status); $this->headers->set('Location', $url); }
Redirect This method prepares the response object to return an HTTP Redirect response to the client. @param string $url The redirect destination @param int $status The redirect HTTP status code @api
entailment
public function getLoginUrl() { // required params $params = array( 'client_id' => $this->getClientId(), 'redirect_uri' => $this->getRedirectUri(), ); // optional params if ($this->getScope()) { $params['scope'] = implode(',', $this->getSco...
Get the login URL for Vkontakte sign in @return string
entailment
public function authenticate($code = null) { if (null === $code) { if (isset($_GET['code'])) { $code = $_GET['code']; } } $url = 'https://oauth.vk.com/access_token?' . http_build_query(array( 'client_id' => $this->getClientId(), ...
Authenticate user and get access token from server @param string $code @return $this
entailment
public function api($method, array $query = array()) { /* Generate query string from array */ foreach ($query as $param => $value) { if (is_array($value)) { // implode values of each nested array with comma $query[$param] = implode(',', $value); ...
Make an API call to https://api.vk.com/method/ @param string $method API method name @param array $query API method params @return mixed The response @throws \Exception
entailment
public function setAccessToken($token) { if (is_string($token)) { $this->accessToken = json_decode($token, true); } else { $this->accessToken = (array)$token; } return $this; }
Set the access token @param string|array $token The access token in json|array format @return $this
entailment
protected function curl($url) { // create curl resource if ($this->persistentConnect) { if (!is_resource(static::$connection)) { static::$connection = curl_init(); } $ch = static::$connection; } else { $ch = curl_init(); ...
Make the curl request to specified url @param string $url The url for curl() function @return mixed The result of curl_exec() function @throws \Exception
entailment
public function keep() { foreach ($this->messages['prev'] as $key => $val) { $this->next($key, $val); } }
Persist flash messages from previous request to the next request @api
entailment
public function offsetGet($offset) { $messages = $this->getMessages(); return isset($messages[$offset]) ? $messages[$offset] : null; }
Offset get @param mixed $offset @return mixed|null The value at specified offset, or null
entailment
public function up() { $datetime = now(); Collection::make([ ['name' => 'Administrator', 'created_at' => $datetime, 'updated_at' => $datetime], ['name' => 'Member', 'created_at' => $datetime, 'updated_at' => $datetime], ])->each(function ($role) { DB::tab...
Run the migrations. @return void
entailment
public function sendResetLink(array $credentials): string { // First we will check to see if we found a user at the given credentials and // if we did not we will redirect back to this current URI with a piece of // "flash" data in the session to indicate to the developers the errors. ...
Send a password reminder to a user. @param array $credentials @return string
entailment
public function offsetUnset($key) { $keys = $this->parseKey($key); $array = &$this->values; while (count($keys) > 1) { $key = array_shift($keys); if (!isset($array[$key]) || !is_array($array[$key])) { return; } $array =& $arr...
Remove nested array value based on a separated key @param string $key
entailment
protected function parseKey($key) { if (!isset($this->keys[$key])) { $this->keys[$key] = explode($this->separator, $key); } return $this->keys[$key]; }
Parse a separated key and cache the result @param string $key @return array
entailment
protected function getValue($key, array $array = array()) { $keys = $this->parseKey($key); while (count($keys) > 0 and !is_null($array)) { $key = array_shift($keys); $array = isset($array[$key]) ? $array[$key] : null; } return $array; }
Get a value from a nested array based on a separated key @param string $key @param array $array @return mixed
entailment
protected function setValue($key, $value, array &$array = array()) { $keys = $this->parseKey($key, $this->separator); $pointer = &$array; while (count($keys) > 0) { $key = array_shift($keys); $pointer[$key] = (isset($pointer[$key]) ? $pointer[$key] : array()); ...
Set nested array values based on a separated key @param string $key @param mixed $value @param array $array @return array
entailment
protected function mergeArrays() { $arrays = func_get_args(); $merged = array(); foreach ($arrays as $array) { foreach ($array as $key => $value) { $merged = $this->setValue($key, $value, $merged); } } return $merged; }
Merge arrays with nested keys into the values store Usage: $this->mergeArrays(array $array [, array $...]) @return array
entailment
protected function flattenArray(array $array, $separator = null) { $flattened = array(); if (is_null($separator)) { $separator = $this->separator; } foreach ($array as $key => $value) { if (is_array($value)) { $flattened = array_merge($flatte...
Flatten a nested array to a separated key @param array $array @param string $separator @return array
entailment
public function setup($event): void { $this->userRoles = null; $this->events->forget('orchestra.auth: roles'); $this->events->listen('orchestra.auth: roles', $event); }
Setup roles event listener. @param \Closure|string $event @return void
entailment
public function roles(): Collection { $user = $this->user(); $userId = 0; // This is a simple check to detect if the user is actually logged-in, // otherwise it's just as the same as setting userId as 0. \is_null($user) || $userId = $user->getAuthIdentifier(); $role...
Get the current user's roles of the application. If the user is a guest, empty array should be returned. @return \Illuminate\Support\Collection
entailment
public function is($roles): bool { $userRoles = $this->roles()->all(); // For a pre-caution, we should return false in events where user // roles not an array. if (! \is_array($userRoles)) { return false; } // We should ensure that all given roles match ...
Determine if current user has the given role. @param string|array $roles @return bool
entailment
protected function getUserRolesFromEventDispatcher(Authenticatable $user = null, $roles = []): Collection { $roles = $this->events->until('orchestra.auth: roles', [$user, $roles]); // It possible that after event are all propagated we don't have a // roles for the user, in this case we shou...
Ger user roles from event dispatcher. @param \Illuminate\Contracts\Auth\Authenticatable $user @param \Illuminate\Support\Collection|array $roles @return \Illuminate\Support\Collection
entailment
protected function resolve($name): PasswordBroker { if (\is_null($config = $this->getConfig($name))) { throw new InvalidArgumentException("Password resetter [{$name}] is not defined."); } // The password broker uses a token repository to validate tokens and send user // ...
Resolve the given broker. @param string $name @return \Illuminate\Contracts\Auth\PasswordBroker
entailment
public function checkAuthorization($roles, $action): bool { $name = $action; $action = $this->actions->search($name); if (\is_null($action)) { throw new InvalidArgumentException("Unable to verify unknown action {$name}."); } $authorized = false; $roles ...
Verify whether given roles has sufficient roles to access the actions based on available type of access. @param string|array $roles A string or an array of roles @param string $action A string of action name @throws \InvalidArgumentException @return bool
entailment
public function setAuthorization($roles, $actions, bool $allow = true): void { $roles = $this->roles->filter($roles); $actions = $this->actions->filter($actions); foreach ($roles as $role) { if (! $this->roles->has($role)) { throw new InvalidArgumentException("Ro...
Assign single or multiple $roles + $actions to have access. @param string|array $roles A string or an array of roles @param string|array $actions A string or an array of action name @param bool $allow @throws \InvalidArgumentException @return void
entailment
protected function assign(?string $role = null, ?string $action = null, bool $allow = true): void { $role = $this->roles->findKey($role); $action = $this->actions->findKey($action); if (! \is_null($role) && ! \is_null($action)) { $this->acl["{$role}:{$action}"] = $allow; ...
Assign a key combination of $roles + $actions to have access. @param string $role A key or string representation of roles @param string $action A key or string representation of action name @param bool $allow @return void
entailment
public function setUser(Authorizable $user) { $userRoles = $user->getRoles(); $this->userRoles = $userRoles; return $this; }
Assign user instance. @param \Orchestra\Contracts\Authorization\Authorizable $user @return $this
entailment
protected function getUserRoles(): Collection { if (! \is_null($this->userRoles)) { return $this->userRoles; } elseif (! $this->auth->guest()) { return $this->auth->roles(); } return new Collection($this->roles->has('guest') ? ['guest'] : []); }
Get all possible user roles. @return \Illuminate\Support\Collection
entailment
public function getCurrentRoute() { if ($this->currentRoute !== null) { return $this->currentRoute; } if (is_array($this->matchedRoutes) && count($this->matchedRoutes) > 0) { return $this->matchedRoutes[0]; } return null; }
Get current route This method will return the current \Slim\Route object. If a route has not been dispatched, but route matching has been completed, the first matching \Slim\Route object will be returned. If route matching has not completed, null will be returned. @return \Slim\Interfaces\RouteInterface|null @api
entailment
public function getMatchedRoutes($httpMethod, $resourceUri, $save = true) { $matchedRoutes = array(); foreach ($this->routes as $route) { if (!$route->supportsHttpMethod($httpMethod) && !$route->supportsHttpMethod("ANY")) { continue; } if ($route-...
Get route objects that match a given HTTP method and URI This method is responsible for finding and returning all \Slim\Interfaces\RouteInterface objects that match a given HTTP method and URI. Slim uses this method to determine which \Slim\Interfaces\RouteInterface objects are candidates to be dispatched for the curr...
entailment
protected function processGroups() { $pattern = ""; $middleware = array(); foreach ($this->routeGroups as $group) { $k = key($group); $pattern .= $k; if (is_array($group[$k])) { $middleware = array_merge($middleware, $group[$k]); ...
Process route groups A helper method for processing the group's pattern and middleware. @return array An array with the elements: pattern, middlewareArr
entailment
public function urlFor($name, $params = array()) { if (!$this->hasNamedRoute($name)) { throw new \RuntimeException('Named route not found for name: ' . $name); } $search = array(); foreach ($params as $key => $value) { $search[] = '#:' . preg_quote($key, '#') ...
Get URL for named route @param string $name The name of the route @param array $params Associative array of URL parameter names and replacement values @return string The URL for the given route populated with provided replacement values @throws \RuntimeException If ...
entailment
public function addNamedRoute($name, RouteInterface $route) { if ($this->hasNamedRoute($name)) { throw new \RuntimeException('Named route already exists with name: ' . $name); } $this->namedRoutes[(string) $name] = $route; }
Add named route @param string $name The route name @param \Slim\Interfaces\RouteInterface $route The route object @throws \RuntimeException If a named route already exists with the same name @api
entailment
public function getNamedRoutes() { if (is_null($this->namedRoutes)) { $this->namedRoutes = array(); foreach ($this->routes as $route) { if ($route->getName() !== null) { $this->addNamedRoute($route->getName(), $route); } ...
Get external iterator for named routes @return \ArrayIterator @api
entailment
protected function render($template, array $data = array()) { // Resolve and verify template file $templatePathname = $this->templateDirectory . DIRECTORY_SEPARATOR . ltrim($template, DIRECTORY_SEPARATOR); if (!is_file($templatePathname)) { throw new \RuntimeException("Cannot ren...
Render template This method will render the specified template file using the current application view. Although this method will work perfectly fine, it is recommended that you create your own custom view class that implements \Slim\ViewInterface instead of using this default view class. This default implementation i...
entailment
public function setCallable($callable) { $matches = array(); if (is_string($callable) && preg_match('!^([^\:]+)\:([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)$!', $callable, $matches)) { $class = $matches[1]; $method = $matches[2]; $callable = function() use ($class,...
Set route callable @param mixed $callable @throws \InvalidArgumentException If argument is not callable @api
entailment
public function getParam($index) { if (!isset($this->params[$index])) { throw new \InvalidArgumentException('Route parameter does not exist at specified index'); } return $this->params[$index]; }
Get route parameter value @param string $index Name of URL parameter @return string @throws \InvalidArgumentException If route parameter does not exist at index @api
entailment
public function setParam($index, $value) { if (!isset($this->params[$index])) { throw new \InvalidArgumentException('Route parameter does not exist at specified index'); } $this->params[$index] = $value; }
Set route parameter value @param string $index Name of URL parameter @param mixed $value The new parameter value @return void @throws \InvalidArgumentException If route parameter does not exist at index @api
entailment
public function appendHttpMethods() { $args = func_get_args(); if(count($args) && is_array($args[0])){ $args = $args[0]; } $this->methods = array_merge($this->methods, $args); }
Append supported HTTP methods (this method accepts an unlimited number of string arguments) @api
entailment
public function via() { $args = func_get_args(); if(count($args) && is_array($args[0])){ $args = $args[0]; } $this->methods = array_merge($this->methods, $args); return $this; }
Append supported HTTP methods (alias for Route::appendHttpMethods) @return \Slim\Route @api
entailment
public function setMiddleware($middleware) { if (is_callable($middleware)) { $this->middleware[] = $middleware; } elseif (is_array($middleware)) { foreach ($middleware as $callable) { if (!is_callable($callable)) { throw new \InvalidArgumen...
Set middleware This method allows middleware to be assigned to a specific Route. If the method argument `is_callable` (including callable arrays!), we directly append the argument to `$this->middleware`. Else, we assume the argument is an array of callables and merge the array with `$this->middleware`. Each middlewar...
entailment
public function matches($resourceUri) { //Convert URL params into regex patterns, construct a regex for this route, init params $patternAsRegex = preg_replace_callback( '#:([\w]+)\+?#', array($this, 'matchesCallback'), str_replace(')', ')?', (string)$this->pattern...
Matches URI? Parse this route's pattern, and then compare it to an HTTP resource URI This method was modeled after the techniques demonstrated by Dan Sosedoff at: http://blog.sosedoff.com/2009/09/20/rails-like-php-url-router/ @param string $resourceUri A Request URI @return bool @api
entailment
protected function matchesCallback($m) { $this->paramNames[] = $m[1]; if (isset($this->conditions[$m[1]])) { return '(?P<' . $m[1] . '>' . $this->conditions[$m[1]] . ')'; } if (substr($m[0], -1) === '+') { $this->paramNamesPath[$m[1]] = 1; return ...
Convert a URL parameter (e.g. ":id", ":id+") into a regular expression @param array $m URL parameters @return string Regular expression for URL parameter
entailment
public function dispatch() { foreach ($this->middleware as $mw) { call_user_func_array($mw, array($this)); } $return = call_user_func_array($this->getCallable(), array_values($this->getParams())); return ($return === false) ? false : true; }
Dispatch route This method invokes the route object's callable. If middleware is registered for the route, each callable middleware is invoked in the order specified. @return bool @api
entailment
public function encrypt($data) { // Get module $module = mcrypt_module_open($this->cipher, '', $this->mode, ''); // Create initialization vector $vector = mcrypt_create_iv(mcrypt_enc_get_iv_size($module), MCRYPT_DEV_URANDOM); // Validate key length $this->validateKe...
Encrypt data @param string $data Unencrypted data @return string Encrypted data @throws \RuntimeException If mcrypt extension not loaded @throws \RuntimeException If encryption module initialization failed @api
entailment
public function decrypt($data) { // Extract components of encrypted data string $parts = explode('|', $data); if (count($parts) !== 3) { return $data; // throw new \RuntimeException('Trying to decrypt invalid data in \Slim\Crypt::decrypt'); } $vector =...
Decrypt data @param string $data Encrypted string @return string Decrypted data @throws \RuntimeException If mcrypt extension not loaded @throws \RuntimeException If decryption module initialization failed @throws \RuntimeException If HMAC integrity verification fails @api
entailment
protected function validateKeyLength($key, $module) { $keySize = strlen($key); $keySizeMin = 1; $keySizeMax = mcrypt_enc_get_key_size($module); $validKeySizes = mcrypt_enc_get_supported_key_sizes($module); if ($validKeySizes) { if (!in_array($keySize, $validKeySiz...
Validate encryption key based on valid key sizes for selected cipher and cipher mode @param string $key Encryption key @param resource $module Encryption module @return void @throws \InvalidArgumentException If key size is invalid for selected cipher
entailment
protected function throwInitError($code, $function) { switch ($code) { case -4: throw new \RuntimeException(sprintf( 'There was a memory allocation problem while calling %s::%s', __CLASS__, $function )); ...
Throw an exception based on a provided exit code @param mixed $code @param string $function @throws \RuntimeException If there was a memory allocation problem @throws \RuntimeException If there was an incorrect key length specified @throws \RuntimeException If an unknown error occured
entailment
protected function runPaginationCountQuery($columns = ['*']) { if ($this->havings) { $query = $this->cloneWithout(['orders', 'limit', 'offset']) ->cloneWithoutBindings(['order']); // We don't need simple columns, only specials // like subselects...
Run a pagination count query. @param array $columns @return array
entailment
public function encrypt(CryptInterface $crypt) { foreach ($this->data as $key => $value) { $this->set($key, $crypt->encrypt($value)); } }
Encrypt set @param \Slim\Interfaces\CryptInterface $crypt @return void @api
entailment
public function getMethod() { // Get actual request method $method = $this->env->get('REQUEST_METHOD'); $methodOverride = $this->headers->get('HTTP_X_HTTP_METHOD_OVERRIDE'); // Detect method override (by HTTP header or POST parameter) if (!empty($methodOverride)) { ...
Get HTTP method @return string @api
entailment
public function getUrl() { $url = $this->getScheme() . '://' . $this->getHost(); if (($this->getScheme() === 'https' && $this->getPort() !== 443) || ($this->getScheme() === 'http' && $this->getPort() !== 80)) { $url .= sprintf(':%s', $this->getPort()); } return $url; ...
Get URL (scheme + host [ + port if non-standard ]) @return string @api
entailment
public function get($key = null, $default = null) { // Parse and cache query parameters if (is_null($this->queryParameters) === true) { $qs = $this->env->get('QUERY_STRING'); if (function_exists('mb_parse_str') === true) { mb_parse_str($qs, $this->queryParame...
Fetch GET query parameter(s) Use this method to fetch a GET request query parameter. If the requested GET query parameter identified by the argument does not exist, NULL is returned. If the argument is omitted, all GET query parameters are returned as an array. @param string $key @param mixed $...
entailment
public function post($key = null, $default = null) { // Parse and cache request body if (is_null($this->body) === true) { $this->body = $_POST; // Parse raw body if form-urlencoded if ($this->isFormData() === true) { $rawBody = (string)$this->getB...
Fetch POST parameter(s) Use this method to fetch a POST body parameter. If the requested POST body parameter identified by the argument does not exist, NULL is returned. If the argument is omitted, all POST body parameters are returned as an array. @param string $key @param mixed $default Defau...
entailment
public function isFormData() { return ($this->getContentType() == '' && $this->getOriginalMethod() === static::METHOD_POST) || in_array($this->getMediaType(), self::$formDataMediaTypes); }
Does the Request body contain parsed form data? @return bool @api
entailment
public function getHost() { $host = $this->headers->get('HTTP_HOST'); if ($host) { if (strpos($host, ':') !== false) { $hostParts = explode(':', $host); return $hostParts[0]; } return $host; } return $this->env->g...
Get Host @return string @api
entailment
public function getScheme() { $isHttps = false; if ($this->headers->has('X_FORWARDED_PROTO') === true) { $headerValue = $this->headers->get('X_FORWARDED_PROTO'); $isHttps = (strtolower($headerValue) === 'https'); } else { $headerValue = $this->env->get('H...
Get Scheme (https or http) @return string @api
entailment
public function getClientIp() { $keys = array('HTTP_X_FORWARDED_FOR', 'CLIENT_IP', 'REMOTE_ADDR'); foreach ($keys as $key) { if ($this->env->has($key) === true) { return $this->env->get($key); } } return null; }
Get client IP address @return string @api
entailment
protected function parsePaths() { if (is_null($this->paths) === true) { // Server params $scriptName = $this->env->get('SCRIPT_NAME'); // <-- "/foo/index.php" $requestUri = $this->env->get('REQUEST_URI'); // <-- "/foo/bar?test=abc" or "/foo/index.php/bar?test=abc" ...
Parse the physical and virtual paths from the request URI @return array
entailment
public function add($key): bool { if (\is_null($key)) { throw new InvalidArgumentException("Can't add NULL to {$this->name}."); } // Type-hint the attribute value of an Eloquent result, if it was // given instead of a string. if ($key instanceof Eloquent) { ...
Add a key to collection. @param \Illuminate\Database\Eloquent\Model|string $key @throws \InvalidArgumentException @return bool
entailment
public function attach($keys): bool { if ($keys instanceof Arrayable) { $keys = $keys->toArray(); } foreach ($keys as $key) { $this->add($key); } return true; }
Add multiple key to collection. @param \Illuminate\Contracts\Support\Arrayable|array $keys @return bool
entailment
public function detach($keys): bool { if ($keys instanceof Arrayable) { $keys = $keys->toArray(); } foreach ($keys as $key) { $this->remove($key); } return true; }
Remove multiple key to collection. @param \Illuminate\Contracts\Support\Arrayable|array $keys @return bool
entailment
public function filter($request): array { if (\is_array($request)) { return $request; } elseif ($request === '*') { return $this->get(); } elseif ($request[0] === '!') { return \array_diff($this->get(), [\substr($request, 1)]); } return [$...
Filter request. @param string|array $request @return array
entailment
public function findKey($name): ?int { $keyword = $this->getKeyword($name); if (! (\is_numeric($name) && $keyword->hasIn($this->items))) { return (string) $keyword->searchIn($this->items); } return $name; }
Find collection key from a name. @param \Orchestra\Support\Keyword|string $name @return int|null
entailment
public function has($key): bool { $key = $this->getKeyword($key)->getSlug(); return ! empty($key) && \in_array($key, $this->items); }
Determine whether a key exists in collection. @param \Orchestra\Support\Keyword|string $key @return bool
entailment
public function rename($from, $to): bool { $key = $this->search($from); if (\is_null($key)) { return false; } $this->items[$key] = $this->getKeyword($to)->getSlug(); return true; }
Rename a key from collection. @param \Orchestra\Support\Keyword|string $from @param \Orchestra\Support\Keyword|string $to @return bool
entailment
public function search($key): ?int { $id = $this->getKeyword($key)->searchIn($this->items); if (false === $id) { return null; } return $id; }
Get the ID from a key. @param \Orchestra\Support\Keyword|string $key @return int|null
entailment
protected function getKeyword($key): Keyword { if ($key instanceof Keyword) { return $key; } if (! isset($this->cachedKeyword[$key])) { $this->cachedKeyword[$key] = Keyword::make($key); } return $this->cachedKeyword[$key]; }
Get keyword instance. @param \Orchestra\Support\Keyword|string $key @return \Orchestra\Support\Keyword
entailment
public function start() { // Initialize new session if a session is not already started if ($this->isStarted() === false) { $this->initialize(); } // Set data source from which session data is loaded, to which session data is saved if (isset($this->dataSource) ==...
Start the session @api
entailment
public function isStarted() { $started = false; if (version_compare(phpversion(), '5.4.0', '>=')) { $started = session_status() === PHP_SESSION_ACTIVE ? true : false; } else { $started = session_id() === '' ? false : true; } return $started; }
Is session started? @return bool @see http://us2.php.net/manual/en/function.session-status.php#113468 Sourced from this comment from on php.net
entailment
public function config($name, $value = null) { if (func_num_args() === 1) { if (is_array($name)) { foreach ($name as $key => $value) { $this['settings'][$key] = $value; } } else { return isset($this['settings'][$name...
Configure Slim Settings This method defines application settings and acts as a setter and a getter. If only one argument is specified and that argument is a string, the value of the setting identified by the first argument will be returned, or NULL if that setting does not exist. If only one argument is specified an...
entailment
protected function mapRoute($args) { $pattern = array_shift($args); $callable = array_pop($args); $route = new \Slim\Route($pattern, $callable, $this['settings']['routes.case_sensitive']); $this['router']->map($route); if (count($args) > 0) { $route->setMiddleware...
Add GET|POST|PUT|PATCH|DELETE route Adds a new route to the router with associated callable. This route will only be invoked when the HTTP request's method matches this route's method. ARGUMENTS: First: string The URL pattern (REQUIRED) In-Between: mixed Anything that returns TRUE for `is_callable` (OPTION...
entailment
public function get() { $args = func_get_args(); return $this->mapRoute($args)->via(\Slim\Http\Request::METHOD_GET, \Slim\Http\Request::METHOD_HEAD); }
Add GET route @return \Slim\Route @api
entailment
public function post() { $args = func_get_args(); return $this->mapRoute($args)->via(\Slim\Http\Request::METHOD_POST); }
Add POST route @return \Slim\Route @api
entailment
public function delete() { $args = func_get_args(); return $this->mapRoute($args)->via(\Slim\Http\Request::METHOD_DELETE); }
Add DELETE route @return \Slim\Route @api
entailment