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
protected function loadFromProperties(Registry $registry, ReflectionClass $class): array { $fields = []; foreach ($class->getProperties() as $property) { $propertyName = $property->getName(); $type = $property->getType(); $fieldType = $this->convertReflectionType($registry, $type); $metadata = []; $defaultProperties = $class->getDefaultProperties(); $metadata['property'] = ($property->getAttributes(Property::class)[0] ?? null) ?->newInstance() ?? new Property(); $metadata['property']->name = $propertyName; $metadata['property']->guarded = ! $property->isPublic(); if (array_key_exists($propertyName, $defaultProperties)) { $metadata['property']->hasDefault = true; $metadata['property']->defaultValue = $defaultProperties[$propertyName]; } else { $metadata['property']->hasDefault = false; } $field = new StructField($property->getName(), $fieldType, $metadata); $fields[] = $field; } return $fields; }
@param Registry $registry @param ReflectionClass $class @return StructField[]
loadFromProperties
php
bixuehujin/blink
src/serializer/ClassTypeLoader.php
https://github.com/bixuehujin/blink/blob/master/src/serializer/ClassTypeLoader.php
MIT
protected function loadFromMethods(Registry $registry, ReflectionClass $class): array { $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC); $fields = []; foreach ($methods as $method) { /** @var ReflectionAttribute|null $attribute */ $attribute = $method->getAttributes(ComputedProperty::class)[0] ?? null; if ($attribute) { /** @var ComputedProperty $property */ $property = $attribute->newInstance(); $property->getter = $method->getName(); $type = $method->getReturnType(); $fieldType = $this->convertReflectionType($registry, $type); $field = new StructField($property->name, $fieldType, [ 'property' => $property, ]); $fields[] = $field; } } return $fields; }
@param Registry $registry @param ReflectionClass $class @return StructField[]
loadFromMethods
php
bixuehujin/blink
src/serializer/ClassTypeLoader.php
https://github.com/bixuehujin/blink/blob/master/src/serializer/ClassTypeLoader.php
MIT
public function __construct(Registry $typing, array $normalizers) { $this->typing = $typing; foreach ($normalizers as $normalizer) { if ($normalizer instanceof SerializerAware) { $normalizer->setSerializer($this); } $this->normalizers[] = $normalizer; } }
Serializer constructor. @param Registry $typing @param Normalizer[] $normalizers
__construct
php
bixuehujin/blink
src/serializer/Serializer.php
https://github.com/bixuehujin/blink/blob/master/src/serializer/Serializer.php
MIT
public function normalize($data, Type $type): mixed { if ($type instanceof AnyType) { return $data; } return $this->getNormalizer($type->getName())->normalize($data, $type); }
@param mixed $data @param Type $type @return mixed
normalize
php
bixuehujin/blink
src/serializer/Serializer.php
https://github.com/bixuehujin/blink/blob/master/src/serializer/Serializer.php
MIT
public function serialize(mixed $data, Type|string $type): string { if (is_string($type)) { $type = $this->typing->parse($type); } $normalized = $this->normalize($data, $type); return Json::encode($normalized, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); }
@param mixed $data @param Type|string $type @return string
serialize
php
bixuehujin/blink
src/serializer/Serializer.php
https://github.com/bixuehujin/blink/blob/master/src/serializer/Serializer.php
MIT
public function deserialize(mixed $source, Type|string $type) { if (is_string($type)) { $type = $this->typing->parse($type); } return $this->denormalize($source, $type); }
@param mixed $source @param Type|string $type @return mixed
deserialize
php
bixuehujin/blink
src/serializer/Serializer.php
https://github.com/bixuehujin/blink/blob/master/src/serializer/Serializer.php
MIT
protected function newTypeError($data, Type $type) { return new \InvalidArgumentException(sprintf( "Unexpected type error, unable to normalize type of '%s' to '%s'", $this->getPhpType($data), $type->getDeclaration(), )); }
@param mixed $data @param Type $type @return \Exception
newTypeError
php
bixuehujin/blink
src/serializer/normalizer/NormalizerHelpers.php
https://github.com/bixuehujin/blink/blob/master/src/serializer/normalizer/NormalizerHelpers.php
MIT
protected function normalizeFiles($files) { foreach ($files as $name => $info) { $this->loadFilesRecursive($name, $info['name'], $info['tmp_name'], $info['type'], $info['size'], $info['error']); } return $this->_files; }
Normalize the PHP $_FILE array. @param array $files @return array
normalizeFiles
php
bixuehujin/blink
src/server/CgiServer.php
https://github.com/bixuehujin/blink/blob/master/src/server/CgiServer.php
MIT
function app($service = null) { if ($service === null) { return Container::$global; } else { return Container::$global->get($service); } }
Helper function to get application instance or registered application services. @param string|class-string|null $service @return \blink\di\Container
app
php
bixuehujin/blink
src/support/helpers.php
https://github.com/bixuehujin/blink/blob/master/src/support/helpers.php
MIT
function config(string $name): mixed { return Container::$global->get($name); }
Returns the configuration value by it's name. @param string $name @return mixed
config
php
bixuehujin/blink
src/support/helpers.php
https://github.com/bixuehujin/blink/blob/master/src/support/helpers.php
MIT
function logger() { return Container::$global->get('log'); }
Helper function to get log service. @return \blink\logging\Logger
logger
php
bixuehujin/blink
src/support/helpers.php
https://github.com/bixuehujin/blink/blob/master/src/support/helpers.php
MIT
function session() { return Container::$global->get('session'); }
Helper function to get session service. @return \blink\session\Contract
session
php
bixuehujin/blink
src/support/helpers.php
https://github.com/bixuehujin/blink/blob/master/src/support/helpers.php
MIT
function auth() { return Container::$global->get('auth'); }
Helper function to get auth service. @return \blink\auth\Contract
auth
php
bixuehujin/blink
src/support/helpers.php
https://github.com/bixuehujin/blink/blob/master/src/support/helpers.php
MIT
function request() { return Container::$global->get(\blink\http\Request::class); }
Helper function to get current request. @return \blink\http\Request
request
php
bixuehujin/blink
src/support/helpers.php
https://github.com/bixuehujin/blink/blob/master/src/support/helpers.php
MIT
function response() { return Container::$global->get(\blink\http\Response::class); }
Helper function to get current response. @return \blink\http\Response
response
php
bixuehujin/blink
src/support/helpers.php
https://github.com/bixuehujin/blink/blob/master/src/support/helpers.php
MIT
function abort($status, $message = null) { throw new HttpException($status, $message); }
Abort the current request. @param $status @param string $message @return never @throws \blink\core\HttpException
abort
php
bixuehujin/blink
src/support/helpers.php
https://github.com/bixuehujin/blink/blob/master/src/support/helpers.php
MIT
function env($name, $default = null) { $value = getenv($name); if ($value === false) { return $default; } switch (strtolower($value)) { case 'true': case '(true)': return true; case 'false': case '(false)': return false; case 'empty': case '(empty)': return ''; case 'null': case '(null)': return; } return $value; }
Returns env configuration by it's name. @param string $name @param mixed $default @return mixed
env
php
bixuehujin/blink
src/support/helpers.php
https://github.com/bixuehujin/blink/blob/master/src/support/helpers.php
MIT
public static function encode($value, $options = null) { if ($options === null) { $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE; } $json = json_encode($value, $options); static::handleJsonError(json_last_error()); return $json; }
Encodes the given value into a JSON string. @param $value @param int $options @return string @throws InvalidParamException if there is any encoding error
encode
php
bixuehujin/blink
src/support/Json.php
https://github.com/bixuehujin/blink/blob/master/src/support/Json.php
MIT
public static function decode($json, $asArray = true) { if (is_array($json)) { throw new InvalidParamException('Invalid JSON data.'); } $decode = json_decode((string) $json, $asArray); static::handleJsonError(json_last_error()); return $decode; }
Decodes the given JSON string into a PHP data structure. @param string $json the JSON string to be decoded @param boolean $asArray whether to return objects in terms of associative arrays. @return mixed the PHP data @throws InvalidParamException if there is any decoding error
decode
php
bixuehujin/blink
src/support/Json.php
https://github.com/bixuehujin/blink/blob/master/src/support/Json.php
MIT
public function actingAs(Authenticatable $actor): static { $this->request->user($actor); return $this; }
Set the currently logged in user to identifier. @param Authenticatable $actor @return static @throws InvalidParamException @throws InvalidValueException
actingAs
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function actor(): ?Authenticatable { return $this->request->user(); }
Returns the currently logged in user. @return Authenticatable|null
actor
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function withFiles(array $files) { foreach ($files as $key => $file) { if (!is_file($file)) { throw new InvalidParamException(sprintf("The file: '$file' does not exists.")); } $target = new File(); $target->name = basename($file); $target->size = filesize($file); $target->type = (new \finfo())->file($file, FILEINFO_MIME_TYPE); $target->tmpName = $file; $target->error = UPLOAD_ERR_OK; $this->request->files->set($key, $target); } return $this; }
Send the request with specified files. @param array $files @return $this
withFiles
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function get($uri, array $headers = []) { list($uri, $query) = $this->normalizeUri($uri); return $this->doRequest('GET', $uri, $query, [], [], $headers, ''); }
Visit the given URI with a GET request. @param string $uri @param array $headers @return $this
get
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function post($uri, array $data = [], array $headers = []) { list($uri, $query) = $this->normalizeUri($uri); return $this->doRequest('POST', $uri, $query, [], [], $headers, $data); }
Visit the given URI with a POST request. @param string $uri @param array $data @param array $headers @return $this
post
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function put($uri, array $data = [], array $headers = []) { list($uri, $query) = $this->normalizeUri($uri); return $this->doRequest('PUT', $uri, $query, [], [], $headers, $data); }
Visit the given URI with a PUT request. @param string $uri @param array $data @param array $headers @return $this
put
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function patch($uri, array $data = [], array $headers = []) { list($uri, $query) = $this->normalizeUri($uri); return $this->doRequest('PATCH', $uri, $query, [], [], $headers, $data); }
Visit the given URI with a PATCH request. @param string $uri @param array $data @param array $headers @return $this
patch
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function delete($uri, array $data = [], array $headers = []) { list($uri, $query) = $this->normalizeUri($uri); return $this->doRequest('DELETE', $uri, $query, [], [], $headers, $data); }
Visit the given URI with a DELETE request. @param string $uri @param array $data @param array $headers @return $this
delete
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function getResponse(): ResponseInterface { return $this->response; }
Returns the underlying response. @return ResponseInterface
getResponse
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function seeJson(array $data = null, $negate = false) { if (is_null($data)) { $this->phpunit->assertJson( (string)$this->response->getBody(), "Failed asserting that JSON returned [{$this->request->uri->path}]." ); return $this; } return $this->seeJsonContains($data, $negate); }
Assert that the response contains JSON. @param array|null $data @param bool $negate @return $this
seeJson
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
protected function seeJsonContains(array $data, $negate = false) { $method = $negate ? 'assertFalse' : 'assertTrue'; $actual = json_encode($this->sortRecursive(json_decode((string)$this->response->getBody(), true))); foreach ($this->sortRecursive($data) as $key => $value) { $expected = $this->formatToExpectedJson($key, $value); $this->phpunit->{$method}( strpos($actual, $expected) !== false, ($negate ? 'Found unexpected' : 'Unable to find') . " JSON fragment [{$expected}] within [{$actual}]." ); } return $this; }
Assert that the response contains the given JSON. @param array $data @param bool $negate @return $this
seeJsonContains
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function seeStatusCode($status) { $this->phpunit->assertEquals($status, $this->response->statusCode); return $this; }
Asserts that the status code of the response matches the given code. @param int $status @return $this
seeStatusCode
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function seeContent($content) { $this->phpunit->assertEquals($content, (string)$this->response->getBody()); return $this; }
Asserts the content of the response matches the given value. @param $content @return $this
seeContent
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function dontSeeJson(array $data = null) { return $this->seeJson($data, true); }
Assert that the response doesn't contain JSON. @param array|null $data @return $this
dontSeeJson
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function seeJsonEquals(array $data) { $actual = json_encode($this->sortRecursive(json_decode((string)$this->response->getBody(), true))); $this->phpunit->assertEquals(json_encode($this->sortRecursive($data)), $actual); return $this; }
Assert that the response contains an exact JSON array. @param array $data @return $this
seeJsonEquals
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function seeJsonStructure(array $structure = null, $responseData = null) { if (is_null($structure)) { return $this->seeJson(); } if (!$responseData) { $responseData = json_decode((string)$this->response->getBody(), true); } foreach ($structure as $key => $value) { if (is_array($value) && $key === '*') { $this->phpunit->assertIsArray($responseData); foreach ($responseData as $responseDataItem) { $this->seeJsonStructure($structure['*'], $responseDataItem); } } elseif (is_array($value)) { $this->phpunit->assertArrayHasKey($key, $responseData); $this->seeJsonStructure($structure[$key], $responseData[$key]); } else { $this->phpunit->assertArrayHasKey($value, $responseData); } } return $this; }
Assert that the JSON response has a given structure. @param array|null $structure @param array|null $responseData @return $this
seeJsonStructure
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function seeHeader($name, $value = null) { $headers = $this->response->headers; $this->phpunit->assertTrue($headers->has($name), "Header [{$name}] not present on response."); if (!is_null($value)) { $values = $headers->get($name); $strValues = implode(', ', $values); $this->phpunit->assertTrue( in_array($value, $values, true), "Header [{$name}] was found, but value [{$strValues}] does not match [{$value}]." ); } return $this; }
Asserts that the response contains the given header and equals the optional value. @param string $name @param mixed $value @return $this
seeHeader
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function seeCookie($name, $value = null) { $cookie = $this->response->cookies->get($name); $this->phpunit->assertTrue((boolean)$cookie, "Cookie [{$cookie}] not present on response."); if ($cookie && !is_null($value)) { $this->phpunit->assertEquals( $cookie->value, $value, "Cookie [{$name}] was found, but value [{$cookie->value}] does not match [{$value}]." ); } return $this; }
Asserts that the response contains the given cookie and equals the optional value. @param string $name @param mixed $value @return $this
seeCookie
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function dumpHeaders() { $headers = $this->response->headers; if ($headers->count() && $this->isVerbose()) { $class = debug_backtrace()[1]; printf("\ndump headers in %s::%s():\n", $class['class'], $class['function']); foreach ($headers as $key => $values) { echo $key, ': ', implode(',', $values), "\n"; } } return $this; }
Dump the response headers for debug purpose. @return $this
dumpHeaders
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function dumpCookies() { $cookies = $this->response->cookies; if ($cookies->count() && $this->isVerbose()) { $class = debug_backtrace()[1]; printf("\ndump cookies in %s::%s():\n", $class['class'], $class['function']); foreach ($cookies as $key => $value) { echo $key, '=> ', $value, "\n"; } } return $this; }
Dump the response cookies for debug purpose. @return $this
dumpCookies
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function dumpJson() { if ($this->isVerbose()) { $json = $this->asJson(); $class = debug_backtrace()[1]; printf("\ndump json in %s::%s():\n", $class['class'], $class['function']); var_export($json); } return $this; }
Dump the response json for debug purpose. @return $this
dumpJson
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function asJson($asArray = true) { if (!$this->isJsonMessage($this->response->headers)) { throw new \RuntimeException('The response is not a valid json response'); } return json_decode((string)$this->response->getBody(), $asArray); }
Returns the response as json. @param boolean $asArray Converts object to associative arrays, defaults to true. @return mixed
asJson
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
private function sortRecursive(array $array) { foreach ($array as &$value) { if (is_array($value)) { $value = $this->sortRecursive($value); } } if ($this->isAssoc($array)) { ksort($array); } else { sort($array); } return $array; }
Recursively sort an array by keys and values. @param array $array @return array
sortRecursive
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
private function isAssoc(array $array) { $keys = array_keys($array); return array_keys($keys) !== $keys; }
Determines if an array is associative. @param array $array @return bool
isAssoc
php
bixuehujin/blink
src/testing/RequestActor.php
https://github.com/bixuehujin/blink/blob/master/src/testing/RequestActor.php
MIT
public function actor() { return new RequestActor($this, $this->createApplication()); }
Returns a new request actor for testing. @return RequestActor @since 0.3.0
actor
php
bixuehujin/blink
src/testing/TestCase.php
https://github.com/bixuehujin/blink/blob/master/src/testing/TestCase.php
MIT
protected function parseScalarType(array $tokens, int $pos): Type { $token = $tokens[$pos]; $token->expect(Token::TEXT); return $this->registry->getType($token->getValue()); }
@param Token[] $tokens @param int $pos @return Type
parseScalarType
php
bixuehujin/blink
src/typing/Parser.php
https://github.com/bixuehujin/blink/blob/master/src/typing/Parser.php
MIT
protected function findSubTokens(array $tokens, array $stopTypes, int $pos): array { $angles = $parentheses = []; for ($endPos = $pos; ; $endPos++) { $token = $tokens[$endPos] ?? null; if (!$token) { break; } if ($token->is(Token::OPEN_ANGLE)) { $angles[] = $endPos; } elseif ($token->is(Token::OPEN_PARENTHESES)) { $parentheses[] = $endPos; } elseif ($token->is(Token::CLOSE_ANGLE)) { array_pop($angles); } elseif ($token->is(Token::CLOSE_PARENTHESES)) { array_pop($parentheses); } if ($token->isAny($stopTypes) && empty($angles) && empty($parentheses)) { break; } } if (!empty($angles)) { throw new SyntaxException('The token < is not properly closed'); } if (!empty($parentheses)) { throw new SyntaxException('The token ( is not properly closed'); } return array_slice($tokens, $pos, $endPos - $pos); }
@param Token[] $tokens @param int $pos @return Token[]
findSubTokens
php
bixuehujin/blink
src/typing/Parser.php
https://github.com/bixuehujin/blink/blob/master/src/typing/Parser.php
MIT
public function parseInternal(array $tokens): Type { $pos = 0; if (count($tokens) === 1) { return $this->parseScalarType($tokens, $pos); } if ($tokens[$pos]->is(Token::TEXT)) { return $this->parseSimpleType($tokens); } elseif ($tokens[0]->is(Token::OPEN_PARENTHESES)) { return $this->parseTupleType($tokens); } else { throw new SyntaxException('Unexpected token ' . $tokens[0]->type()); } }
@param Token[] $tokens @param int $pos @return Type @throws SyntaxException
parseInternal
php
bixuehujin/blink
src/typing/Parser.php
https://github.com/bixuehujin/blink/blob/master/src/typing/Parser.php
MIT
protected function parseSimpleType(array $tokens): Type { $pos = 0; $endPos = count($tokens) - 1; while ($endPos > $pos) { $token = $tokens[$pos]; $next = $tokens[$pos + 1]; if ($next->is(Token::OPEN_ANGLE)) { $token->expect(Token::TEXT); $subTokens = $this->findSubTokens($tokens, [Token::CLOSE_ANGLE], $pos + 1); $parameterTypes = $this->parseGenericParameterTypes(array_slice($subTokens, 1)); $subType = $this->registry->genericOf($token->getValue(), $parameterTypes); if (!isset($type)) { $type = $subType; } elseif ($type instanceof UnionType) { $type->appendType($subType); } else { $type = new UnionType( $type, $subType, ); } $pos += count($subTokens) + 1; } elseif ($next->is(Token::UNION)) { $subTokens = $this->findSubTokens($tokens, [Token::UNION], $pos + 2); $subType = $this->parseInternal($subTokens); if (!isset($type)) { $type = $this->registry->unionOf( $this->parseScalarType($tokens, $pos), $subType, ); } elseif ($type instanceof UnionType) { $type->appendType($subType); } else { $type = $this->registry->unionOf( $type, $subType, ); } $pos += count($subTokens) + 1; } else { throw new SyntaxException('Unexpected token ' . $next->type()); } } return $type; }
@param Token[] $tokens @return Type @throws SyntaxException
parseSimpleType
php
bixuehujin/blink
src/typing/Parser.php
https://github.com/bixuehujin/blink/blob/master/src/typing/Parser.php
MIT
public function structOf(string $name, array $fields): Type { return new StructType($name, $fields); }
@param string $name @param StructField[] $fields @return Type
structOf
php
bixuehujin/blink
src/typing/Registry.php
https://github.com/bixuehujin/blink/blob/master/src/typing/Registry.php
MIT
public function getType(string $name): Type { $type = $this->types[$name] ?? null; if ($type) { return $type; } if ($type = $this->loadType($name)) { $this->types[$name] = $type; return $type; } throw new InvalidParamException("Unknown type: " . $name); }
Returns a Type by it's name. @param string $name @return Type
getType
php
bixuehujin/blink
src/typing/Registry.php
https://github.com/bixuehujin/blink/blob/master/src/typing/Registry.php
MIT
public function getDeclaration(): string { return $this->getName(); }
Returns the text representation of the type. @return string
getDeclaration
php
bixuehujin/blink
src/typing/Type.php
https://github.com/bixuehujin/blink/blob/master/src/typing/Type.php
MIT
public function newInstance(array $parameters): GenericType { $allowedParameters = $this->allowedParameters(); $givenParameters = count($parameters); $name = $this->getName(); if ($givenParameters !== $allowedParameters) { throw new SyntaxException("The generic type: $name accepts $allowedParameters parameters, $givenParameters was given"); } $type = clone $this; $type->parameterTypes = $parameters; return $type; }
@param Type[] $parameters @return GenericType @throws SyntaxException
newInstance
php
bixuehujin/blink
src/typing/types/GenericType.php
https://github.com/bixuehujin/blink/blob/master/src/typing/types/GenericType.php
MIT
public function testEvaluateMathExpressions(Expr $expr, mixed $result): void { $evaluator = new Evaluator(); $variables = [ 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, ]; $this->assertEquals($result, $evaluator->evaluate($expr, $variables)); }
@param Expr $expr @param mixed $result @dataProvider mathExpressionCases
testEvaluateMathExpressions
php
bixuehujin/blink
tests/expression/EvaluatorTest.php
https://github.com/bixuehujin/blink/blob/master/tests/expression/EvaluatorTest.php
MIT
public function testEvaluateFunctions(Expr $expr, mixed $result): void { $evaluator = new Evaluator(); $this->assertEquals($result, $evaluator->evaluate($expr, ['a' => 'foo', 'b' => 'bar'])); }
@param Expr $expr @param mixed $result @return void @dataProvider functionCases
testEvaluateFunctions
php
bixuehujin/blink
tests/expression/EvaluatorTest.php
https://github.com/bixuehujin/blink/blob/master/tests/expression/EvaluatorTest.php
MIT
public function testTokenize(string $definition, array $expected): void { $tokenizer = new Tokenizer(); $tokens = $tokenizer->tokenize($definition); $tokens = array_map(fn (Token $token) => $token->toArray(), $tokens); $this->assertEquals($expected, $tokens); }
@param string $definition @param array $expected @dataProvider typeTokenizeCases
testTokenize
php
bixuehujin/blink
tests/typing/ParserTest.php
https://github.com/bixuehujin/blink/blob/master/tests/typing/ParserTest.php
MIT
public function showLoginForm() { return view('auth.login'); }
Show the application's login form. @return \Illuminate\View\View
showLoginForm
php
laravel/ui
auth-backend/AuthenticatesUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/AuthenticatesUsers.php
MIT
public function login(Request $request) { $this->validateLogin($request); // If the class is using the ThrottlesLogins trait, we can automatically throttle // the login attempts for this application. We'll key this by the username and // the IP address of the client making these requests into this application. if (method_exists($this, 'hasTooManyLoginAttempts') && $this->hasTooManyLoginAttempts($request)) { $this->fireLockoutEvent($request); return $this->sendLockoutResponse($request); } if ($this->attemptLogin($request)) { if ($request->hasSession()) { $request->session()->put('auth.password_confirmed_at', time()); } return $this->sendLoginResponse($request); } // If the login attempt was unsuccessful we will increment the number of attempts // to login and redirect the user back to the login form. Of course, when this // user surpasses their maximum number of attempts they will get locked out. $this->incrementLoginAttempts($request); return $this->sendFailedLoginResponse($request); }
Handle a login request to the application. @param \Illuminate\Http\Request $request @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse @throws \Illuminate\Validation\ValidationException
login
php
laravel/ui
auth-backend/AuthenticatesUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/AuthenticatesUsers.php
MIT
protected function validateLogin(Request $request) { $request->validate([ $this->username() => 'required|string', 'password' => 'required|string', ]); }
Validate the user login request. @param \Illuminate\Http\Request $request @return void @throws \Illuminate\Validation\ValidationException
validateLogin
php
laravel/ui
auth-backend/AuthenticatesUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/AuthenticatesUsers.php
MIT
protected function attemptLogin(Request $request) { return $this->guard()->attempt( $this->credentials($request), $request->boolean('remember') ); }
Attempt to log the user into the application. @param \Illuminate\Http\Request $request @return bool
attemptLogin
php
laravel/ui
auth-backend/AuthenticatesUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/AuthenticatesUsers.php
MIT
protected function credentials(Request $request) { return $request->only($this->username(), 'password'); }
Get the needed authorization credentials from the request. @param \Illuminate\Http\Request $request @return array
credentials
php
laravel/ui
auth-backend/AuthenticatesUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/AuthenticatesUsers.php
MIT
protected function sendLoginResponse(Request $request) { $request->session()->regenerate(); $this->clearLoginAttempts($request); if ($response = $this->authenticated($request, $this->guard()->user())) { return $response; } return $request->wantsJson() ? new JsonResponse([], 204) : redirect()->intended($this->redirectPath()); }
Send the response after the user was authenticated. @param \Illuminate\Http\Request $request @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
sendLoginResponse
php
laravel/ui
auth-backend/AuthenticatesUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/AuthenticatesUsers.php
MIT
protected function authenticated(Request $request, $user) { // }
The user has been authenticated. @param \Illuminate\Http\Request $request @param mixed $user @return mixed
authenticated
php
laravel/ui
auth-backend/AuthenticatesUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/AuthenticatesUsers.php
MIT
protected function sendFailedLoginResponse(Request $request) { throw ValidationException::withMessages([ $this->username() => [trans('auth.failed')], ]); }
Get the failed login response instance. @param \Illuminate\Http\Request $request @return \Symfony\Component\HttpFoundation\Response @throws \Illuminate\Validation\ValidationException
sendFailedLoginResponse
php
laravel/ui
auth-backend/AuthenticatesUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/AuthenticatesUsers.php
MIT
public function username() { return 'email'; }
Get the login username to be used by the controller. @return string
username
php
laravel/ui
auth-backend/AuthenticatesUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/AuthenticatesUsers.php
MIT
public function logout(Request $request) { $this->guard()->logout(); $request->session()->invalidate(); $request->session()->regenerateToken(); if ($response = $this->loggedOut($request)) { return $response; } return $request->wantsJson() ? new JsonResponse([], 204) : redirect('/'); }
Log the user out of the application. @param \Illuminate\Http\Request $request @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
logout
php
laravel/ui
auth-backend/AuthenticatesUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/AuthenticatesUsers.php
MIT
protected function loggedOut(Request $request) { // }
The user has logged out of the application. @param \Illuminate\Http\Request $request @return mixed
loggedOut
php
laravel/ui
auth-backend/AuthenticatesUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/AuthenticatesUsers.php
MIT
protected function guard() { return Auth::guard(); }
Get the guard to be used during authentication. @return \Illuminate\Contracts\Auth\StatefulGuard
guard
php
laravel/ui
auth-backend/AuthenticatesUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/AuthenticatesUsers.php
MIT
public function showConfirmForm() { return view('auth.passwords.confirm'); }
Display the password confirmation view. @return \Illuminate\View\View
showConfirmForm
php
laravel/ui
auth-backend/ConfirmsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ConfirmsPasswords.php
MIT
public function confirm(Request $request) { $request->validate($this->rules(), $this->validationErrorMessages()); $this->resetPasswordConfirmationTimeout($request); return $request->wantsJson() ? new JsonResponse([], 204) : redirect()->intended($this->redirectPath()); }
Confirm the given user's password. @param \Illuminate\Http\Request $request @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
confirm
php
laravel/ui
auth-backend/ConfirmsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ConfirmsPasswords.php
MIT
protected function resetPasswordConfirmationTimeout(Request $request) { $request->session()->put('auth.password_confirmed_at', time()); }
Reset the password confirmation timeout. @param \Illuminate\Http\Request $request @return void
resetPasswordConfirmationTimeout
php
laravel/ui
auth-backend/ConfirmsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ConfirmsPasswords.php
MIT
protected function rules() { return [ 'password' => 'required|current_password:web', ]; }
Get the password confirmation validation rules. @return array
rules
php
laravel/ui
auth-backend/ConfirmsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ConfirmsPasswords.php
MIT
protected function validationErrorMessages() { return []; }
Get the password confirmation validation error messages. @return array
validationErrorMessages
php
laravel/ui
auth-backend/ConfirmsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ConfirmsPasswords.php
MIT
public function redirectPath() { if (method_exists($this, 'redirectTo')) { return $this->redirectTo(); } return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home'; }
Get the post register / login redirect path. @return string
redirectPath
php
laravel/ui
auth-backend/RedirectsUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/RedirectsUsers.php
MIT
public function showRegistrationForm() { return view('auth.register'); }
Show the application registration form. @return \Illuminate\View\View
showRegistrationForm
php
laravel/ui
auth-backend/RegistersUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/RegistersUsers.php
MIT
public function register(Request $request) { $this->validator($request->all())->validate(); event(new Registered($user = $this->create($request->all()))); $this->guard()->login($user); if ($response = $this->registered($request, $user)) { return $response; } return $request->wantsJson() ? new JsonResponse([], 201) : redirect($this->redirectPath()); }
Handle a registration request for the application. @param \Illuminate\Http\Request $request @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
register
php
laravel/ui
auth-backend/RegistersUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/RegistersUsers.php
MIT
protected function guard() { return Auth::guard(); }
Get the guard to be used during registration. @return \Illuminate\Contracts\Auth\StatefulGuard
guard
php
laravel/ui
auth-backend/RegistersUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/RegistersUsers.php
MIT
protected function registered(Request $request, $user) { // }
The user has been registered. @param \Illuminate\Http\Request $request @param mixed $user @return mixed
registered
php
laravel/ui
auth-backend/RegistersUsers.php
https://github.com/laravel/ui/blob/master/auth-backend/RegistersUsers.php
MIT
public function showResetForm(Request $request) { $token = $request->route()->parameter('token'); return view('auth.passwords.reset')->with( ['token' => $token, 'email' => $request->email] ); }
Display the password reset view for the given token. If no token is present, display the link request form. @param \Illuminate\Http\Request $request @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
showResetForm
php
laravel/ui
auth-backend/ResetsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ResetsPasswords.php
MIT
public function reset(Request $request) { $request->validate($this->rules(), $this->validationErrorMessages()); // Here we will attempt to reset the user's password. If it is successful we // will update the password on an actual user model and persist it to the // database. Otherwise we will parse the error and return the response. $response = $this->broker()->reset( $this->credentials($request), function ($user, $password) { $this->resetPassword($user, $password); } ); // If the password was successfully reset, we will redirect the user back to // the application's home authenticated view. If there is an error we can // redirect them back to where they came from with their error message. return $response == Password::PASSWORD_RESET ? $this->sendResetResponse($request, $response) : $this->sendResetFailedResponse($request, $response); }
Reset the given user's password. @param \Illuminate\Http\Request $request @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
reset
php
laravel/ui
auth-backend/ResetsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ResetsPasswords.php
MIT
protected function rules() { return [ 'token' => 'required', 'email' => 'required|email', 'password' => ['required', 'confirmed', Rules\Password::defaults()], ]; }
Get the password reset validation rules. @return array
rules
php
laravel/ui
auth-backend/ResetsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ResetsPasswords.php
MIT
protected function validationErrorMessages() { return []; }
Get the password reset validation error messages. @return array
validationErrorMessages
php
laravel/ui
auth-backend/ResetsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ResetsPasswords.php
MIT
protected function credentials(Request $request) { return $request->only( 'email', 'password', 'password_confirmation', 'token' ); }
Get the password reset credentials from the request. @param \Illuminate\Http\Request $request @return array
credentials
php
laravel/ui
auth-backend/ResetsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ResetsPasswords.php
MIT
protected function resetPassword($user, $password) { $this->setUserPassword($user, $password); $user->setRememberToken(Str::random(60)); $user->save(); event(new PasswordReset($user)); $this->guard()->login($user); }
Reset the given user's password. @param \Illuminate\Contracts\Auth\CanResetPassword $user @param string $password @return void
resetPassword
php
laravel/ui
auth-backend/ResetsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ResetsPasswords.php
MIT
protected function setUserPassword($user, $password) { $user->password = Hash::make($password); }
Set the user's password. @param \Illuminate\Contracts\Auth\CanResetPassword $user @param string $password @return void
setUserPassword
php
laravel/ui
auth-backend/ResetsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ResetsPasswords.php
MIT
protected function sendResetResponse(Request $request, $response) { if ($request->wantsJson()) { return new JsonResponse(['message' => trans($response)], 200); } return redirect($this->redirectPath()) ->with('status', trans($response)); }
Get the response for a successful password reset. @param \Illuminate\Http\Request $request @param string $response @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
sendResetResponse
php
laravel/ui
auth-backend/ResetsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ResetsPasswords.php
MIT
protected function sendResetFailedResponse(Request $request, $response) { if ($request->wantsJson()) { throw ValidationException::withMessages([ 'email' => [trans($response)], ]); } return redirect()->back() ->withInput($request->only('email')) ->withErrors(['email' => trans($response)]); }
Get the response for a failed password reset. @param \Illuminate\Http\Request $request @param string $response @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
sendResetFailedResponse
php
laravel/ui
auth-backend/ResetsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ResetsPasswords.php
MIT
public function broker() { return Password::broker(); }
Get the broker to be used during password reset. @return \Illuminate\Contracts\Auth\PasswordBroker
broker
php
laravel/ui
auth-backend/ResetsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ResetsPasswords.php
MIT
protected function guard() { return Auth::guard(); }
Get the guard to be used during password reset. @return \Illuminate\Contracts\Auth\StatefulGuard
guard
php
laravel/ui
auth-backend/ResetsPasswords.php
https://github.com/laravel/ui/blob/master/auth-backend/ResetsPasswords.php
MIT
public function showLinkRequestForm() { return view('auth.passwords.email'); }
Display the form to request a password reset link. @return \Illuminate\View\View
showLinkRequestForm
php
laravel/ui
auth-backend/SendsPasswordResetEmails.php
https://github.com/laravel/ui/blob/master/auth-backend/SendsPasswordResetEmails.php
MIT
public function sendResetLinkEmail(Request $request) { $this->validateEmail($request); // We will send the password reset link to this user. Once we have attempted // to send the link, we will examine the response then see the message we // need to show to the user. Finally, we'll send out a proper response. $response = $this->broker()->sendResetLink( $this->credentials($request) ); return $response == Password::RESET_LINK_SENT ? $this->sendResetLinkResponse($request, $response) : $this->sendResetLinkFailedResponse($request, $response); }
Send a reset link to the given user. @param \Illuminate\Http\Request $request @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
sendResetLinkEmail
php
laravel/ui
auth-backend/SendsPasswordResetEmails.php
https://github.com/laravel/ui/blob/master/auth-backend/SendsPasswordResetEmails.php
MIT
protected function validateEmail(Request $request) { $request->validate(['email' => 'required|email']); }
Validate the email for the given request. @param \Illuminate\Http\Request $request @return void
validateEmail
php
laravel/ui
auth-backend/SendsPasswordResetEmails.php
https://github.com/laravel/ui/blob/master/auth-backend/SendsPasswordResetEmails.php
MIT
protected function credentials(Request $request) { return $request->only('email'); }
Get the needed authentication credentials from the request. @param \Illuminate\Http\Request $request @return array
credentials
php
laravel/ui
auth-backend/SendsPasswordResetEmails.php
https://github.com/laravel/ui/blob/master/auth-backend/SendsPasswordResetEmails.php
MIT
protected function sendResetLinkResponse(Request $request, $response) { return $request->wantsJson() ? new JsonResponse(['message' => trans($response)], 200) : back()->with('status', trans($response)); }
Get the response for a successful password reset link. @param \Illuminate\Http\Request $request @param string $response @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
sendResetLinkResponse
php
laravel/ui
auth-backend/SendsPasswordResetEmails.php
https://github.com/laravel/ui/blob/master/auth-backend/SendsPasswordResetEmails.php
MIT
protected function sendResetLinkFailedResponse(Request $request, $response) { if ($request->wantsJson()) { throw ValidationException::withMessages([ 'email' => [trans($response)], ]); } return back() ->withInput($request->only('email')) ->withErrors(['email' => trans($response)]); }
Get the response for a failed password reset link. @param \Illuminate\Http\Request $request @param string $response @return \Illuminate\Http\RedirectResponse @throws \Illuminate\Validation\ValidationException
sendResetLinkFailedResponse
php
laravel/ui
auth-backend/SendsPasswordResetEmails.php
https://github.com/laravel/ui/blob/master/auth-backend/SendsPasswordResetEmails.php
MIT
public function broker() { return Password::broker(); }
Get the broker to be used during password reset. @return \Illuminate\Contracts\Auth\PasswordBroker
broker
php
laravel/ui
auth-backend/SendsPasswordResetEmails.php
https://github.com/laravel/ui/blob/master/auth-backend/SendsPasswordResetEmails.php
MIT
protected function hasTooManyLoginAttempts(Request $request) { return $this->limiter()->tooManyAttempts( $this->throttleKey($request), $this->maxAttempts() ); }
Determine if the user has too many failed login attempts. @param \Illuminate\Http\Request $request @return bool
hasTooManyLoginAttempts
php
laravel/ui
auth-backend/ThrottlesLogins.php
https://github.com/laravel/ui/blob/master/auth-backend/ThrottlesLogins.php
MIT
protected function incrementLoginAttempts(Request $request) { $this->limiter()->hit( $this->throttleKey($request), $this->decayMinutes() * 60 ); }
Increment the login attempts for the user. @param \Illuminate\Http\Request $request @return void
incrementLoginAttempts
php
laravel/ui
auth-backend/ThrottlesLogins.php
https://github.com/laravel/ui/blob/master/auth-backend/ThrottlesLogins.php
MIT
protected function sendLockoutResponse(Request $request) { $seconds = $this->limiter()->availableIn( $this->throttleKey($request) ); throw ValidationException::withMessages([ $this->username() => [trans('auth.throttle', [ 'seconds' => $seconds, 'minutes' => ceil($seconds / 60), ])], ])->status(Response::HTTP_TOO_MANY_REQUESTS); }
Redirect the user after determining they are locked out. @param \Illuminate\Http\Request $request @return \Symfony\Component\HttpFoundation\Response @throws \Illuminate\Validation\ValidationException
sendLockoutResponse
php
laravel/ui
auth-backend/ThrottlesLogins.php
https://github.com/laravel/ui/blob/master/auth-backend/ThrottlesLogins.php
MIT
protected function clearLoginAttempts(Request $request) { $this->limiter()->clear($this->throttleKey($request)); }
Clear the login locks for the given user credentials. @param \Illuminate\Http\Request $request @return void
clearLoginAttempts
php
laravel/ui
auth-backend/ThrottlesLogins.php
https://github.com/laravel/ui/blob/master/auth-backend/ThrottlesLogins.php
MIT
protected function fireLockoutEvent(Request $request) { event(new Lockout($request)); }
Fire an event when a lockout occurs. @param \Illuminate\Http\Request $request @return void
fireLockoutEvent
php
laravel/ui
auth-backend/ThrottlesLogins.php
https://github.com/laravel/ui/blob/master/auth-backend/ThrottlesLogins.php
MIT