code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public static function from_request($http_method=NULL, $http_url=NULL, $parameters=NULL) { $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") ? 'http' : 'https'; $http_url = ($http_url) ? $http_url : $scheme . '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI']; $http_method = ($http_method) ? $http_method : $_SERVER['REQUEST_METHOD']; // We weren't handed any parameters, so let's find the ones relevant to // this request. // If you run XML-RPC or similar you should use this to provide your own // parsed parameter-list if (!$parameters) { // Find request headers $request_headers = OAuthUtil::get_headers(); // Parse the query-string to find GET parameters $parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']); // It's a POST request of the proper content-type, so parse POST // parameters and add those overriding any duplicates from GET if ($http_method == "POST" && isset($request_headers['Content-Type']) && strstr($request_headers['Content-Type'], 'application/x-www-form-urlencoded') ) { $post_data = OAuthUtil::parse_parameters( file_get_contents(self::$POST_INPUT) ); $parameters = array_merge($parameters, $post_data); } // We have a Authorization-header with OAuth data. Parse the header // and add those overriding any duplicates from GET or POST if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') { $header_parameters = OAuthUtil::split_header( $request_headers['Authorization'] ); $parameters = array_merge($parameters, $header_parameters); } } return new OAuthRequest($http_method, $http_url, $parameters); }
attempt to build up a request from what was passed to the server
from_request
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) { $parameters = ($parameters) ? $parameters : array(); $defaults = array("oauth_version" => OAuthRequest::$version, "oauth_nonce" => OAuthRequest::generate_nonce(), "oauth_timestamp" => OAuthRequest::generate_timestamp(), "oauth_consumer_key" => $consumer->key); if ($token) $defaults['oauth_token'] = $token->key; $parameters = array_merge($defaults, $parameters); return new OAuthRequest($http_method, $http_url, $parameters); }
pretty much a helper function to set up the request
from_consumer_and_token
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
public function get_signable_parameters() { // Grab all parameters $params = $this->parameters; // Remove oauth_signature if present // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.") if (isset($params['oauth_signature'])) { unset($params['oauth_signature']); } return OAuthUtil::build_http_query($params); }
The request parameters, sorted and concatenated into a normalized string. @return string
get_signable_parameters
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
public function get_signature_base_string() { $parts = array( $this->get_normalized_http_method(), $this->get_normalized_http_url(), $this->get_signable_parameters() ); $parts = OAuthUtil::urlencode_rfc3986($parts); return implode('&', $parts); }
Returns the base string of this request The base string defined as the method, the url and the parameters (normalized), each urlencoded and the concated with &.
get_signature_base_string
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
public function get_normalized_http_url() { $parts = parse_url($this->http_url); $scheme = (isset($parts['scheme'])) ? $parts['scheme'] : 'http'; $port = (isset($parts['port'])) ? $parts['port'] : (($scheme == 'https') ? '443' : '80'); $host = (isset($parts['host'])) ? strtolower($parts['host']) : ''; $path = (isset($parts['path'])) ? $parts['path'] : ''; if (($scheme == 'https' && $port != '443') || ($scheme == 'http' && $port != '80')) { $host = "$host:$port"; } return "$scheme://$host$path"; }
parses the url and rebuilds it to be scheme://host/path
get_normalized_http_url
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
public function to_url() { $post_data = $this->to_postdata(); $out = $this->get_normalized_http_url(); if ($post_data) { $out .= '?'.$post_data; } return $out; }
builds a url usable for a GET request
to_url
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
public function to_postdata() { return OAuthUtil::build_http_query($this->parameters); }
builds the data one would send in a POST request
to_postdata
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
public function fetch_request_token(&$request) { $this->get_version($request); $consumer = $this->get_consumer($request); // no token required for the initial token request $token = NULL; $this->check_signature($request, $consumer, $token); // Rev A change $callback = $request->get_parameter('oauth_callback'); $new_token = $this->data_store->new_request_token($consumer, $callback); return $new_token; }
process a request_token request returns the request token on success
fetch_request_token
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
public function fetch_access_token(&$request) { $this->get_version($request); $consumer = $this->get_consumer($request); // requires authorized request token $token = $this->get_token($request, $consumer, "request"); $this->check_signature($request, $consumer, $token); // Rev A change $verifier = $request->get_parameter('oauth_verifier'); $new_token = $this->data_store->new_access_token($token, $consumer, $verifier); return $new_token; }
process an access_token request returns the access token on success
fetch_access_token
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
public function verify_request(&$request) { $this->get_version($request); $consumer = $this->get_consumer($request); $token = $this->get_token($request, $consumer, "access"); $this->check_signature($request, $consumer, $token); return array($consumer, $token); }
verify an api call, checks all the parameters
verify_request
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
private function get_signature_method($request) { $signature_method = $request instanceof OAuthRequest ? $request->get_parameter("oauth_signature_method") : NULL; if (!$signature_method) { // According to chapter 7 ("Accessing Protected Ressources") the signature-method // parameter is required, and we can't just fallback to PLAINTEXT throw new OAuthException('No signature method parameter. This parameter is required'); } if (!in_array($signature_method, array_keys($this->signature_methods))) { throw new OAuthException( "Signature method '$signature_method' not supported " . "try one of the following: " . implode(", ", array_keys($this->signature_methods)) ); } return $this->signature_methods[$signature_method]; }
figure out the signature with some defaults
get_signature_method
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
private function get_consumer($request) { $consumer_key = $request instanceof OAuthRequest ? $request->get_parameter("oauth_consumer_key") : NULL; if (!$consumer_key) { throw new OAuthException("Invalid consumer key"); } $consumer = $this->data_store->lookup_consumer($consumer_key); if (!$consumer) { throw new OAuthException("Invalid consumer"); } return $consumer; }
try to find the consumer for the provided request's consumer key
get_consumer
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
private function get_token($request, $consumer, $token_type="access") { $token_field = $request instanceof OAuthRequest ? $request->get_parameter('oauth_token') : NULL; $token = $this->data_store->lookup_token( $consumer, $token_type, $token_field ); if (!$token) { throw new OAuthException("Invalid $token_type token: $token_field"); } return $token; }
try to find the token for the provided request's token key
get_token
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
private function check_signature($request, $consumer, $token) { // this should probably be in a different method $timestamp = $request instanceof OAuthRequest ? $request->get_parameter('oauth_timestamp') : NULL; $nonce = $request instanceof OAuthRequest ? $request->get_parameter('oauth_nonce') : NULL; $this->check_timestamp($timestamp); $this->check_nonce($consumer, $token, $nonce, $timestamp); $signature_method = $this->get_signature_method($request); $signature = $request->get_parameter('oauth_signature'); $valid_sig = $signature_method->check_signature( $request, $consumer, $token, $signature ); if (!$valid_sig) { throw new OAuthException("Invalid signature"); } }
all-in-one function to check the signature on a request should guess the signature method appropriately
check_signature
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
private function check_timestamp($timestamp) { if( ! $timestamp ) throw new OAuthException( 'Missing timestamp parameter. The parameter is required' ); // verify that timestamp is recentish $now = time(); if (abs($now - $timestamp) > $this->timestamp_threshold) { throw new OAuthException( "Expired timestamp, yours $timestamp, ours $now" ); } }
check that the timestamp is new enough
check_timestamp
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
private function check_nonce($consumer, $token, $nonce, $timestamp) { if( ! $nonce ) throw new OAuthException( 'Missing nonce parameter. The parameter is required' ); // verify that the nonce is uniqueish $found = $this->data_store->lookup_nonce( $consumer, $token, $nonce, $timestamp ); if ($found) { throw new OAuthException("Nonce already used: $nonce"); } }
check that the nonce is not repeated
check_nonce
php
Yelp/yelp-api
v2/php/lib/OAuth.php
https://github.com/Yelp/yelp-api/blob/master/v2/php/lib/OAuth.php
MIT
public function info($string) { $this->output->writeln("<info>$string</info>"); }
Write a string as information output. @param string $string @return void
info
php
bixuehujin/blink
src/console/Command.php
https://github.com/bixuehujin/blink/blob/master/src/console/Command.php
MIT
public function line($string) { $this->output->writeln($string); }
Write a string as standard output. @param string $string @return void
line
php
bixuehujin/blink
src/console/Command.php
https://github.com/bixuehujin/blink/blob/master/src/console/Command.php
MIT
public function comment($string) { $this->output->writeln("<comment>$string</comment>"); }
Write a string as comment output. @param string $string @return void
comment
php
bixuehujin/blink
src/console/Command.php
https://github.com/bixuehujin/blink/blob/master/src/console/Command.php
MIT
public function question($string) { $this->output->writeln("<question>$string</question>"); }
Write a string as question output. @param string $string @return void
question
php
bixuehujin/blink
src/console/Command.php
https://github.com/bixuehujin/blink/blob/master/src/console/Command.php
MIT
public function error($string) { $this->output->writeln("<error>$string</error>"); }
Write a string as error output. @param string $string @return void
error
php
bixuehujin/blink
src/console/Command.php
https://github.com/bixuehujin/blink/blob/master/src/console/Command.php
MIT
public function warn($string) { $style = new OutputFormatterStyle('yellow'); $this->output->getFormatter()->setStyle('warning', $style); $this->output->writeln("<warning>$string</warning>"); }
Write a string as warning output. @param string $string @return void
warn
php
bixuehujin/blink
src/console/Command.php
https://github.com/bixuehujin/blink/blob/master/src/console/Command.php
MIT
public function __construct($message = '', $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, \Exception $previous = null) { parent::__construct($message, $code, $severity, $filename, $lineno, $previous); if (function_exists('xdebug_get_function_stack')) { $phpCompatibleTrace = []; $trace = array_slice(array_reverse(xdebug_get_function_stack()), 3, -1); foreach ($trace as &$frame) { if (!isset($frame['function'])) { $frame['function'] = 'unknown'; } // XDebug < 2.1.1: http://bugs.xdebug.org/view.php?id=695 if (!isset($frame['type']) || $frame['type'] === 'static') { $frame['type'] = '::'; } elseif ($frame['type'] === 'dynamic') { $frame['type'] = '->'; } // XDebug has a different key name if (isset($frame['params']) && !isset($frame['args'])) { $frame['args'] = $frame['params']; } $phpCompatibleTrace[] = $frame; } $ref = new \ReflectionProperty('Exception', 'trace'); $ref->setAccessible(true); $ref->setValue($this, $phpCompatibleTrace); } }
Constructs the exception. @link http://php.net/manual/en/errorexception.construct.php @param $message [optional] @param $code [optional] @param $severity [optional] @param $filename [optional] @param $lineno [optional] @param $previous [optional]
__construct
php
bixuehujin/blink
src/core/ErrorException.php
https://github.com/bixuehujin/blink/blob/master/src/core/ErrorException.php
MIT
public static function isFatalError($error) { return isset($error['type']) && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING], true); }
Returns if error is one of fatal type. @param array $error error got from error_get_last() @return boolean if error is one of fatal type
isFatalError
php
bixuehujin/blink
src/core/ErrorException.php
https://github.com/bixuehujin/blink/blob/master/src/core/ErrorException.php
MIT
public function getName() { $names = [ E_ERROR => 'PHP Fatal Error', E_PARSE => 'PHP Parse Error', E_CORE_ERROR => 'PHP Core Error', E_COMPILE_ERROR => 'PHP Compile Error', E_USER_ERROR => 'PHP User Error', E_WARNING => 'PHP Warning', E_CORE_WARNING => 'PHP Core Warning', E_COMPILE_WARNING => 'PHP Compile Warning', E_USER_WARNING => 'PHP User Warning', E_STRICT => 'PHP Strict Warning', E_NOTICE => 'PHP Notice', E_RECOVERABLE_ERROR => 'PHP Recoverable Error', E_DEPRECATED => 'PHP Deprecated Warning', ]; return isset($names[$this->getCode()]) ? $names[$this->getCode()] : 'Error'; }
@return string the user-friendly name of this exception
getName
php
bixuehujin/blink
src/core/ErrorException.php
https://github.com/bixuehujin/blink/blob/master/src/core/ErrorException.php
MIT
public function unregister() { restore_error_handler(); restore_exception_handler(); }
Unregisters this error handler by restoring the PHP error and exception handlers.
unregister
php
bixuehujin/blink
src/core/ErrorHandler.php
https://github.com/bixuehujin/blink/blob/master/src/core/ErrorHandler.php
MIT
public function getName() { return 'Exception'; }
@return string the user-friendly name of this exception
getName
php
bixuehujin/blink
src/core/Exception.php
https://github.com/bixuehujin/blink/blob/master/src/core/Exception.php
MIT
public function __construct($status, $message = null, $code = 0, \Exception $previous = null) { $this->statusCode = $status; if ($message === null && isset(Response::$httpStatuses[$status])) { $message = Response::$httpStatuses[$status]; } parent::__construct($message, $code, $previous); }
Constructor. @param integer $status HTTP status code, such as 404, 500, etc. @param string $message error message @param integer $code error code @param \Exception $previous The previous exception used for the exception chaining.
__construct
php
bixuehujin/blink
src/core/HttpException.php
https://github.com/bixuehujin/blink/blob/master/src/core/HttpException.php
MIT
public function getName() { if (isset(Response::$httpStatuses[$this->statusCode])) { return Response::$httpStatuses[$this->statusCode]; } else { return 'Error'; } }
@return string the user-friendly name of this exception
getName
php
bixuehujin/blink
src/core/HttpException.php
https://github.com/bixuehujin/blink/blob/master/src/core/HttpException.php
MIT
public function getName() { return 'Invalid Call'; }
@return string the user-friendly name of this exception
getName
php
bixuehujin/blink
src/core/InvalidCallException.php
https://github.com/bixuehujin/blink/blob/master/src/core/InvalidCallException.php
MIT
public function getName() { return 'Invalid Configuration'; }
@return string the user-friendly name of this exception
getName
php
bixuehujin/blink
src/core/InvalidConfigException.php
https://github.com/bixuehujin/blink/blob/master/src/core/InvalidConfigException.php
MIT
public function getName() { return 'Invalid Parameter'; }
@return string the user-friendly name of this exception
getName
php
bixuehujin/blink
src/core/InvalidParamException.php
https://github.com/bixuehujin/blink/blob/master/src/core/InvalidParamException.php
MIT
public function getName() { return 'Invalid Return Value'; }
@return string the user-friendly name of this exception
getName
php
bixuehujin/blink
src/core/InvalidValueException.php
https://github.com/bixuehujin/blink/blob/master/src/core/InvalidValueException.php
MIT
public function getName() { return 'Not Supported'; }
@return string the user-friendly name of this exception
getName
php
bixuehujin/blink
src/core/NotSupportedException.php
https://github.com/bixuehujin/blink/blob/master/src/core/NotSupportedException.php
MIT
public function getName() { return 'Unknown Method'; }
@return string the user-friendly name of this exception
getName
php
bixuehujin/blink
src/core/UnknownMethodException.php
https://github.com/bixuehujin/blink/blob/master/src/core/UnknownMethodException.php
MIT
public function getName() { return 'Unknown Property'; }
@return string the user-friendly name of this exception
getName
php
bixuehujin/blink
src/core/UnknownPropertyException.php
https://github.com/bixuehujin/blink/blob/master/src/core/UnknownPropertyException.php
MIT
public function where(string|Expr $column, $operator = null, mixed $value = null) { if (func_num_args() === 2) { $value = $operator; $operator = '=='; } return $this->whereInternal($column, $operator, $value); }
@param Expr|string $column @param mixed|null $operator @param mixed|null $value @return $this
where
php
bixuehujin/blink
src/database/Query.php
https://github.com/bixuehujin/blink/blob/master/src/database/Query.php
MIT
public function orWhere(string|Expr $column, $operator = null, mixed $value = null) { if (func_num_args() === 2) { $value = $operator; $operator = '=='; } return $this->whereInternal($column, $operator, $value, true); }
@param Expr|string $column @param mixed|null $operator @param mixed|null $value @return $this
orWhere
php
bixuehujin/blink
src/database/Query.php
https://github.com/bixuehujin/blink/blob/master/src/database/Query.php
MIT
public function make(string $name, array $parameters = [], array $config = []) { // $concrete = $this->aliases[$name] ?? $name; $definition = $this->loadDefinition($name); if (! $definition) { throw new Exception("Unable to load definition for '$name'"); } if (isset($this->loadingItems[$name])) { throw new Exception('circular reference detected on making ' . $name); } $this->loadingItems[$name] = true; if ($factory = $definition->getFactory()) { $value = $factory(); } else { $value = $this->createObjectInternal($definition, $parameters, $config); } unset($this->loadingItems[$name]); return $value; }
@template T @param class-string<T> $name @param array $parameters @param array $config @return T @throws Exception
make
php
bixuehujin/blink
src/di/Container.php
https://github.com/bixuehujin/blink/blob/master/src/di/Container.php
MIT
public function make2($type, $arguments = []) { if (is_string($type)) { return $this->make($type, $arguments); } elseif (is_callable($type)) { return $type(); } elseif (is_object($type)) { return $type; } elseif (is_array($type) && isset($type['class'])) { $className = $type['class']; unset($type['class']); return $this->make($className, $arguments, $type); } elseif (is_array($type)) { throw new InvalidConfigException('Object configuration must be an array containing a "class" element.'); } else { throw new InvalidConfigException("Unsupported configuration type: " . gettype($type)); } }
@param mixed $type @param array $arguments @return mixed @throws Exception @deprecated
make2
php
bixuehujin/blink
src/di/Container.php
https://github.com/bixuehujin/blink/blob/master/src/di/Container.php
MIT
protected function injectProperties(object $object, array $properties) { foreach ($properties as $property) { $name = $property->getName(); if ($referentName = $property->getReferentName()) { $value = $this->get($referentName); } else { $value = $property->getDefault(); } if ($setter = $property->getSetter()) { $object->$setter($value); } elseif ($property->isGuarded()) { $reflector = new ReflectionProperty($object, $name); $reflector->setAccessible(true); $reflector->setValue($object, $value); } else { $object->$name = $value; } } }
@param object $object @param Reference[] $properties @throws Exception @throws NotFoundException @throws ReflectionException
injectProperties
php
bixuehujin/blink
src/di/Container.php
https://github.com/bixuehujin/blink/blob/master/src/di/Container.php
MIT
public function has($id) { $definition = $this->loadDefinition($id); if ($definition) { return true; } foreach ($this->delegates as $delegate) { if ($delegate->has($id)) { return true; } } return false; }
Returns true if the container can return an entry for the given identifier. Returns false otherwise. `has($id)` returning true does not mean that `get($id)` will not throw an exception. It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. @param string $id Identifier of the entry to look for. @return bool
has
php
bixuehujin/blink
src/di/Container.php
https://github.com/bixuehujin/blink/blob/master/src/di/Container.php
MIT
public function get($id) { $id = $this->aliases[$id] ?? $id; if (array_key_exists($id, $this->loadedItems)) { return $this->loadedItems[$id]; } if ($this->loadDefinition($id)) { return $this->loadedItems[$id] = $this->make($id); } foreach ($this->delegates as $delegate) { if ($delegate->has($id)) { return $delegate->get($id); } } throw new NotFoundException("No entry was found for identifier: $id"); }
Finds an entry of the container by its identifier and returns it. @param string $id Identifier of the entry to look for. @return mixed Entry. @throws Exception Error while retrieving the entry. @throws NotFoundException No entry was found for **this** identifier.
get
php
bixuehujin/blink
src/di/Container.php
https://github.com/bixuehujin/blink/blob/master/src/di/Container.php
MIT
public function set(string $id, mixed $value): void { $id = $this->aliases[$id] ?? $id; $this->loadedItems[$id] = $value; }
Sets an entry of the container by its identifier. @param string $id @param mixed $value @return void
set
php
bixuehujin/blink
src/di/Container.php
https://github.com/bixuehujin/blink/blob/master/src/di/Container.php
MIT
public function add($provider) { if (! $provider instanceof ServiceProvider) { $provider = $this->get($provider); } $provider->register($this); }
Add a new service provider to the container. @param ServiceProvider|string $provider
add
php
bixuehujin/blink
src/di/Container.php
https://github.com/bixuehujin/blink/blob/master/src/di/Container.php
MIT
public function call($callback, $arguments = []) { $caller = $this->getCallerReflector($callback); if (is_array($callback) && count($callback) === 2 && $caller instanceof ReflectionMethod && ! $caller->isStatic()) { $callback[0] = $this->make($callback[0]); } $parameters = $caller->getParameters(); $dependencies = $this->getMethodDependencies($parameters, $arguments); return call_user_func_array($callback, $dependencies); }
Call the given callback or class method with dependency injection. @param callable $callback @param array $arguments @return mixed
call
php
bixuehujin/blink
src/di/Container.php
https://github.com/bixuehujin/blink/blob/master/src/di/Container.php
MIT
protected function getMethodDependencies(array $parameters, array $arguments = []): array { $dependencies = []; foreach ($parameters as $parameter) { $name = $parameter->getName(); if (array_key_exists($name, $arguments)) { $dependencies[] = $arguments[$name]; } elseif ($typeName = $this->getInjectableType($parameter->getType())) { $dependencies[] = $arguments[$typeName] ?? $this->get($typeName); } elseif ($parameter->isDefaultValueAvailable()) { $dependencies[] = $parameter->getDefaultValue(); } else { throw new InvalidParamException('Missing required argument: ' . $parameter->getName()); } } return $dependencies; }
@param ReflectionParameter[] $parameters @param array $arguments @return array
getMethodDependencies
php
bixuehujin/blink
src/di/Container.php
https://github.com/bixuehujin/blink/blob/master/src/di/Container.php
MIT
public function loadDefinition(string $name): ?ConfigDefinition { return $this->definitions[$name] ?? null; }
@param string $name @return ConfigDefinition|null
loadDefinition
php
bixuehujin/blink
src/di/config/ConfigContainer.php
https://github.com/bixuehujin/blink/blob/master/src/di/config/ConfigContainer.php
MIT
public function get($id) { $definition = $this->loadDefinition($id); if (! $definition) { // If the config is not defined, we will return the config value directly. return $this->configMap[$id] ?? null; } assert($definition instanceof ConfigDefinition); $name = $definition->name(); if ($definition->isRequired() && !array_key_exists($name, $this->configMap)) { throw new Exception("The config '$name' is required"); } return $this->configMap[$name] ?? $definition->defaultValue(); }
Finds an entry of the container by its identifier and returns it. @param string $id Identifier of the entry to look for. @return mixed Entry. @throws Exception Error while retrieving the entry. @throws NotFoundException No entry was found for **this** identifier.
get
php
bixuehujin/blink
src/di/config/ConfigContainer.php
https://github.com/bixuehujin/blink/blob/master/src/di/config/ConfigContainer.php
MIT
public function has($id) { return isset($this->definitions[$id]) || isset($this->configMap[$id]); }
Returns true if the container can return an entry for the given identifier. Returns false otherwise. `has($id)` returning true does not mean that `get($id)` will not throw an exception. It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. @param string $id Identifier of the entry to look for. @return bool
has
php
bixuehujin/blink
src/di/config/ConfigContainer.php
https://github.com/bixuehujin/blink/blob/master/src/di/config/ConfigContainer.php
MIT
public function __construct(string $name, mixed $default = null) { $this->name = $name; $this->default = $default; }
ConfigDefinition constructor. @param string $name @param mixed $default
__construct
php
bixuehujin/blink
src/di/config/ConfigDefinition.php
https://github.com/bixuehujin/blink/blob/master/src/di/config/ConfigDefinition.php
MIT
public function attach(string $eventClass, callable $handler) { $this->listeners[$eventClass][] = $handler; }
Attach a handler to the given eventClass. @param string $eventClass @param callable $handler
attach
php
bixuehujin/blink
src/eventbus/EventBus.php
https://github.com/bixuehujin/blink/blob/master/src/eventbus/EventBus.php
MIT
public function dispatch(object $event) { $listeners = $this->getListenersForEvent($event); foreach ($listeners as $listener) { if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) { return $event; } $listener($event); } return $event; }
Dispatch a event. @param object $event @return object
dispatch
php
bixuehujin/blink
src/eventbus/EventBus.php
https://github.com/bixuehujin/blink/blob/master/src/eventbus/EventBus.php
MIT
public function dispatch(object $event) { $this->events[] = $event; return $event; }
Dispatch event to the transaction. @param object $event @return object
dispatch
php
bixuehujin/blink
src/eventbus/Transaction.php
https://github.com/bixuehujin/blink/blob/master/src/eventbus/Transaction.php
MIT
public function all(): array { return $this->cookies; }
Returns all cookies. @return Cookie[] @since 0.3.0
all
php
bixuehujin/blink
src/http/CookieBag.php
https://github.com/bixuehujin/blink/blob/master/src/http/CookieBag.php
MIT
public function get($name): ?Cookie { return isset($this->cookies[$name]) ? $this->cookies[$name] : null; }
Returns a cookie by name. @param string $name @return Cookie|null
get
php
bixuehujin/blink
src/http/CookieBag.php
https://github.com/bixuehujin/blink/blob/master/src/http/CookieBag.php
MIT
public function add(Cookie $cookie): void { $this->cookies[$cookie->name] = $cookie; }
Add a cookie to the bag. @param Cookie $cookie
add
php
bixuehujin/blink
src/http/CookieBag.php
https://github.com/bixuehujin/blink/blob/master/src/http/CookieBag.php
MIT
public function has(string $name): bool { return isset($this->cookies[$name]); }
Returns whether a cookie is exists. @param string $name @return bool
has
php
bixuehujin/blink
src/http/CookieBag.php
https://github.com/bixuehujin/blink/blob/master/src/http/CookieBag.php
MIT
public function remove(string $name): void { unset($this->cookies[$name]); }
Remove a cookie by name. @param string $name
remove
php
bixuehujin/blink
src/http/CookieBag.php
https://github.com/bixuehujin/blink/blob/master/src/http/CookieBag.php
MIT
public function get($name) { if (isset($this->files[$name])) { return [$this->files[$name]]; } $results = []; foreach ($this->files as $key => $file) { if (strpos($key, "{$name}[") === 0) { $results[] = $file; } } return $results; }
Returns files by its name. @param $name @return File[]
get
php
bixuehujin/blink
src/http/FileBag.php
https://github.com/bixuehujin/blink/blob/master/src/http/FileBag.php
MIT
public function first($name) { if (isset($this->files[$name])) { return $this->files[$name]; } foreach ($this->files as $key => $file) { if (strpos($key, "{$name}[") === 0) { return $file; } } }
Returns the first file by its name. @param $name @return File|null
first
php
bixuehujin/blink
src/http/FileBag.php
https://github.com/bixuehujin/blink/blob/master/src/http/FileBag.php
MIT
public function setBody($body) { if ($body instanceof StreamInterface) { $this->_body = $body; } else { $this->_body = new Stream('php://memory', 'rw+'); } }
Sets the body of the message. @param $body
setBody
php
bixuehujin/blink
src/http/MessageTrait.php
https://github.com/bixuehujin/blink/blob/master/src/http/MessageTrait.php
MIT
public function is($method) { return $this->method === strtoupper($method); }
Returns whether the request method is the given $method. @param $method @return bool
is
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function match($pattern) { return preg_match($pattern, $this->uri->path); }
Checks whether the path of the request match the given pattern. @param $pattern @return boolean
match
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function secure() { return 'https' === $this->uri->scheme; }
Returns whether this request is secure. @return boolean
secure
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function setPayload($body = []): void { if (!$body instanceof ParamBag) { $body = new ParamBag($body); } $this->_body = $body; }
Sets the request body. @param mixed $body
setPayload
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function setFiles($files = []) { if (!$files instanceof FileBag) { $files = new FileBag($files); } $this->_files = $files; }
Defines the setter for files property. @param array $files
setFiles
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function getFiles() { if ($this->_files === null) { $this->_files = new FileBag(); } return $this->_files; }
Defines the getter for files property. @return FileBag
getFiles
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function setCookies($cookies) { if (!$cookies instanceof CookieBag) { $cookies = new CookieBag(CookieBag::normalize($cookies)); } $this->_cookies = $cookies; }
Defines the setter for cookie property. @param $cookies
setCookies
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function getCookies() { if ($this->_cookies === null) { $this->_cookies = new CookieBag(); } return $this->_cookies; }
Defines the getter for cookies property. @return CookieBag
getCookies
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function host() { return $this->getUri()->getAuthority(); }
Returns the host part of the request url, egg. rethinkphp.com:8888 @return string
host
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function root() { if ($host = $this->host()) { return $this->uri->scheme . '://' . $host; } else { return ''; } }
Returns the root url of the request url, egg. http://rethinkphp.com:8888 @return string
root
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function url($withParams = true) { if ($withParams) { return (string)$this->uri; } else { return $this->root() . $this->uri->path; } }
Returns the url of the request. @param bool $withParams Returns with query params. @return string
url
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function getContentType() { $contentType = $this->headers->first('Content-Type'); if (($pos = strpos($contentType, ';')) !== false) { $contentType = substr($contentType, 0, $pos); } return $contentType; }
Returns the Content-Type of the request without it's parameters. @return string
getContentType
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function getContentTypeParams() { $contentType = $this->headers->first('Content-Type'); $contentTypeParams = []; if ($contentType) { $contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType); $contentTypePartsLength = count($contentTypeParts); for ($i = 1; $i < $contentTypePartsLength; $i++) { $paramParts = explode('=', $contentTypeParts[$i]); $contentTypeParams[strtolower($paramParts[0])] = $paramParts[1]; } } return $contentTypeParams; }
Returns parameters of the Content-Type header. @return array
getContentTypeParams
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function ip() { if ($ip = $this->headers->first('X-Forwarded-For')) { return $ip; } else { return $this->serverParams['remote_addr'] ?? null; } }
Returns the client ip address of the request. @return null|string
ip
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function has($key) { return $this->params->has($key) || $this->payload->has($key); }
Returns whether has an input value by key. @param $key @return boolean
has
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function input($key, $default = null) { if (($value = $this->params->get($key)) !== null) { return $value; } if (($value = $this->payload->get($key)) !== null) { return $value; } return $default; }
Gets a input value by key. @param $key @param null $default @return mixed
input
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function setSession($session) { $this->_session = $session; }
Sets the session of the request. @param $session
setSession
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function getSession() { if ($this->_session === false) { $sessionId = is_callable($this->sessionKey) ? call_user_func( $this->sessionKey, $this ) : $this->headers->first($this->sessionKey); if ($session = session()->get($sessionId)) { $this->_session = $session; } else { $this->_session = null; } } return $this->_session; }
Returns the current session associated to the request. @return \blink\session\Session|null
getSession
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function user($user = null) { if ($user !== null) { $this->_user = $user; return; } return $this->_user; }
Gets or sets the authenticated user for this request. @param Authenticatable $user @return \blink\auth\Authenticatable|null
user
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function guest() { return $this->user() === null; }
Returns the whether the request is a guest request. @return bool
guest
php
bixuehujin/blink
src/http/Request.php
https://github.com/bixuehujin/blink/blob/master/src/http/Request.php
MIT
public function redirect($url, $statusCode = 302) { if (strpos($url, '/') === 0 && strpos($url, '//') !== 0) { $url = request()->root() . $url; } $this->status($statusCode); $this->headers->set('Location', $url); }
Redirects to the specified url. @param string $url @param int $statusCode @since 0.2.0
redirect
php
bixuehujin/blink
src/http/Response.php
https://github.com/bixuehujin/blink/blob/master/src/http/Response.php
MIT
public function getCookies() { if (!$this->_cookies) { $this->_cookies = new CookieBag(); } return $this->_cookies; }
Returns the cookies that should be sent with the response. @return CookieBag
getCookies
php
bixuehujin/blink
src/http/Response.php
https://github.com/bixuehujin/blink/blob/master/src/http/Response.php
MIT
public function __construct($stream, $mode = 'r') { $this->setStream($stream, $mode); }
@param string|resource $stream @param string $mode Mode with which to open stream @throws InvalidArgumentException
__construct
php
bixuehujin/blink
src/http/Stream.php
https://github.com/bixuehujin/blink/blob/master/src/http/Stream.php
MIT
private function setStream($stream, $mode = 'r') { $error = null; $resource = $stream; if (is_string($stream)) { set_error_handler(function ($e) use (&$error) { $error = $e; }, E_WARNING); $resource = fopen($stream, $mode); restore_error_handler(); } if ($error) { throw new InvalidArgumentException('Invalid stream reference provided'); } if (! is_resource($resource) || 'stream' !== get_resource_type($resource)) { throw new InvalidArgumentException( 'Invalid stream provided; must be a string stream identifier or stream resource' ); } if ($stream !== $resource) { $this->stream = $stream; } $this->resource = $resource; }
Set the internal stream resource. @param string|resource $stream String stream target or stream resource. @param string $mode Resource mode for stream target. @throws InvalidArgumentException for invalid streams or resources.
setStream
php
bixuehujin/blink
src/http/Stream.php
https://github.com/bixuehujin/blink/blob/master/src/http/Stream.php
MIT
protected function addRoute(MiddlewareStack $stack, array $verbs, string $path, $handler): Route { return $this->router->addRoute($stack, $verbs, $this->prefix . $path, $handler); }
Add a new route in the group. @param MiddlewareStack $stack @param array $verbs @param string $path @param mixed $handler @return Route
addRoute
php
bixuehujin/blink
src/routing/Group.php
https://github.com/bixuehujin/blink/blob/master/src/routing/Group.php
MIT
public function __construct(MiddlewareStack $stack, array $verbs, string $path, $handler) { $this->stack = clone $stack; $this->verbs = $verbs; $this->path = $path; $this->handler = $handler; }
Route constructor. @param array $verbs @param string $path @param mixed $handler
__construct
php
bixuehujin/blink
src/routing/Route.php
https://github.com/bixuehujin/blink/blob/master/src/routing/Route.php
MIT
public function name(string $name): self { $this->name = $name; return $this; }
Sets name of the route. @param string $name @return $this
name
php
bixuehujin/blink
src/routing/Route.php
https://github.com/bixuehujin/blink/blob/master/src/routing/Route.php
MIT
public function group(string $prefix, callable $callback): self { $group = new Group($this, $this->stack, $prefix); $callback($group); return $this; }
Add a group of routes with a callback. @param string $prefix @param callable $callback @return $this
group
php
bixuehujin/blink
src/routing/Router.php
https://github.com/bixuehujin/blink/blob/master/src/routing/Router.php
MIT
public function addRoute(MiddlewareStack $stack, array $verbs, string $path, $handler): Route { $route = new Route($stack, $verbs, $path, $handler); $this->routes[spl_object_id($route)] = $route; return $route; }
Add a new route. @param MiddlewareStack $stack @param array $verbs @param string $path @param mixed $handler @return Route
addRoute
php
bixuehujin/blink
src/routing/Router.php
https://github.com/bixuehujin/blink/blob/master/src/routing/Router.php
MIT
public function dispatch(string $verb, string $path): Route { $info = $this->getDispatcher()->dispatch($verb, $path); if ($info[0] === Dispatcher::NOT_FOUND) { throw new RouteNotFoundException($path); } elseif ($info[0] === Dispatcher::METHOD_NOT_ALLOWED) { throw new MethodNotAllowedException("$verb method is not allowed for $path", $info[1]); } $route = $this->routes[$info[1]]; return $route->withArguments($info[2]); }
@param string $verb @param string $path @return Route
dispatch
php
bixuehujin/blink
src/routing/Router.php
https://github.com/bixuehujin/blink/blob/master/src/routing/Router.php
MIT
public function get(string $path, $handler): Route { return $this->addRoute($this->stack, ['GET', 'HEAD'], $path, $handler); }
Register a GET route. @param string $path @param mixed $handler @return Route
get
php
bixuehujin/blink
src/routing/RouterMethods.php
https://github.com/bixuehujin/blink/blob/master/src/routing/RouterMethods.php
MIT
public function post(string $path, $handler): Route { return $this->addRoute($this->stack, ['POST'], $path, $handler); }
Register a POST route. @param string $path @param mixed $handler @return Route
post
php
bixuehujin/blink
src/routing/RouterMethods.php
https://github.com/bixuehujin/blink/blob/master/src/routing/RouterMethods.php
MIT
public function put(string $path, $handler): Route { return $this->addRoute($this->stack, ['PUT'], $path, $handler); }
Register a PUT route. @param string $path @param mixed $handler @return Route
put
php
bixuehujin/blink
src/routing/RouterMethods.php
https://github.com/bixuehujin/blink/blob/master/src/routing/RouterMethods.php
MIT
public function patch(string $path, $handler): Route { return $this->addRoute($this->stack, ['PATCH'], $path, $handler); }
Register a PATCH route. @param string $path @param mixed $handler @return Route
patch
php
bixuehujin/blink
src/routing/RouterMethods.php
https://github.com/bixuehujin/blink/blob/master/src/routing/RouterMethods.php
MIT
public function delete(string $path, $handler): Route { return $this->addRoute($this->stack, ['DELETE'], $path, $handler); }
Register a DELETE route. @param string $path @param mixed $handler @return Route
delete
php
bixuehujin/blink
src/routing/RouterMethods.php
https://github.com/bixuehujin/blink/blob/master/src/routing/RouterMethods.php
MIT
public function options(string $path, $handler): Route { return $this->addRoute($this->stack, ['OPTIONS'], $path, $handler); }
Register a OPTIONS route. @param string $path @param mixed $handler @return Route
options
php
bixuehujin/blink
src/routing/RouterMethods.php
https://github.com/bixuehujin/blink/blob/master/src/routing/RouterMethods.php
MIT
public function add(MiddlewareInterface $middleware): self { $this->chain[] = $middleware; return $this; }
Adds middleware to the chain. @param MiddlewareInterface $middleware @return static
add
php
bixuehujin/blink
src/routing/middleware/MiddlewareStack.php
https://github.com/bixuehujin/blink/blob/master/src/routing/middleware/MiddlewareStack.php
MIT
protected function buildStack(): RequestHandlerInterface { $chain = $this->defaultHandler; foreach ($this->chain as $middleware) { $chain = $this->wrap($middleware, $chain); } return $chain; }
Builds the request handler chain. @return RequestHandlerInterface
buildStack
php
bixuehujin/blink
src/routing/middleware/MiddlewareStack.php
https://github.com/bixuehujin/blink/blob/master/src/routing/middleware/MiddlewareStack.php
MIT