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 serializeData($data, $includePaths = null, ?array $fieldsets = null) { $params = new QueryParameters($includePaths ? (array) $includePaths : null, $fieldsets); return $this->broadcastEncoder()->serializeData($data, $params); }
@param $data @param string|string[]|null $includePaths @param array|null $fieldsets @return array
serializeData
php
cloudcreativity/laravel-json-api
src/Broadcasting/BroadcastsData.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Broadcasting/BroadcastsData.php
Apache-2.0
public function __construct(SchemaContainerInterface $schemas, ClientSerializer $serializer) { $this->schemas = $schemas; $this->serializer = $serializer; $this->links = false; $this->options = []; }
AbstractClient constructor. @param SchemaContainerInterface $schemas @param ClientSerializer $serializer
__construct
php
cloudcreativity/laravel-json-api
src/Client/AbstractClient.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/AbstractClient.php
Apache-2.0
protected function resourceUri($resourceType, $resourceId = null) { return $resourceId ? "$resourceType/$resourceId" : $resourceType; }
Get the path for a resource type, or resource type and id. @param string $resourceType @param string|null $resourceId @return string
resourceUri
php
cloudcreativity/laravel-json-api
src/Client/AbstractClient.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/AbstractClient.php
Apache-2.0
protected function relatedUri($resourceType, $resourceId, $relationship) { return $this->resourceUri($resourceType, $resourceId) . '/' . $relationship; }
Get the path for reading the related resource in a relationship. @param $resourceType @param $resourceId @param $relationship @return string
relatedUri
php
cloudcreativity/laravel-json-api
src/Client/AbstractClient.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/AbstractClient.php
Apache-2.0
protected function relationshipUri($resourceType, $resourceId, $relationship) { return $this->resourceUri($resourceType, $resourceId) . '/relationships/' . $relationship; }
Get the path for a resource's relationship. @param $resourceType @param $resourceId @param $relationship @return string
relationshipUri
php
cloudcreativity/laravel-json-api
src/Client/AbstractClient.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/AbstractClient.php
Apache-2.0
protected function jsonApiHeaders($body = false) { $headers = ['Accept' => MediaType::JSON_API_MEDIA_TYPE]; if ($body) { $headers['Content-Type'] = MediaType::JSON_API_MEDIA_TYPE; } return $headers; }
@param bool $body whether HTTP request body is being sent. @return array
jsonApiHeaders
php
cloudcreativity/laravel-json-api
src/Client/AbstractClient.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/AbstractClient.php
Apache-2.0
protected function queryParameters($parameters) { if ($parameters instanceof QueryParametersInterface) { return QueryParameters::cast($parameters)->toArray(); } return $parameters; }
@param QueryParametersInterface|array $parameters @return array
queryParameters
php
cloudcreativity/laravel-json-api
src/Client/AbstractClient.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/AbstractClient.php
Apache-2.0
public function __construct(SerializerInterface $serializer, Factory $factory) { $this->serializer = $serializer; $this->factory = $factory; $this->links = false; $this->includePaths = null; $this->fieldsets = null; $this->compoundDocuments = false; }
ClientSerializer constructor. @param SerializerInterface $serializer @param Factory $factory
__construct
php
cloudcreativity/laravel-json-api
src/Client/ClientSerializer.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/ClientSerializer.php
Apache-2.0
public function withFieldsets($resourceType, $fields) { $fieldsets = $this->fieldsets ?: []; if ($fields) { $fieldsets[$resourceType] = (array) $fields; } else { unset($fieldsets[$resourceType]); } $copy = clone $this; $copy->fieldsets = $fieldsets ?: null; return $copy; }
@param string $resourceType @param string|string[] $fields @return ClientSerializer
withFieldsets
php
cloudcreativity/laravel-json-api
src/Client/ClientSerializer.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/ClientSerializer.php
Apache-2.0
public function serialize($record, $meta = null, array $links = []) { $serializer = $this->setupSerializer(); $serializer->withMeta($meta)->withLinks($links); $serialized = $serializer->serializeData($record, $this->createEncodingParameters()); $resourceLinks = null; if (empty($serialized['data']['id'])) { unset($serialized['data']['id']); $resourceLinks = false; // links will not be valid so strip them out. } $resource = $this->parsePrimaryResource($serialized['data'], $resourceLinks); $document = ['data' => $resource]; if (isset($serialized['included']) && $this->doesSerializeCompoundDocuments()) { $document['included'] = $this->parseIncludedResources($serialized['included']); } return $document; }
Serialize a domain record. @param $record @param mixed|null $meta @param mixed|null $links @return array
serialize
php
cloudcreativity/laravel-json-api
src/Client/ClientSerializer.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/ClientSerializer.php
Apache-2.0
public function serializeRelated($related, $meta = null, array $links = []) { $serializer = $this->setupSerializer(); $serializer->withMeta($meta)->withLinks($links); return $serializer->serializeIdentifiers($related); }
Serialize related record(s). @param object|iterable|array|null $related @param mixed|null $meta @param array $links @return array
serializeRelated
php
cloudcreativity/laravel-json-api
src/Client/ClientSerializer.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/ClientSerializer.php
Apache-2.0
protected function parsePrimaryResource(array $resource, $links = null) { return $this->parseResource($resource, true, $links); }
@param array $resource @param bool|null $links @return array
parsePrimaryResource
php
cloudcreativity/laravel-json-api
src/Client/ClientSerializer.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/ClientSerializer.php
Apache-2.0
protected function parseResources(array $resources, $primary = false) { return collect($resources)->map(function (array $resource) use ($primary) { return $this->parseResource($resource, $primary); }); }
@param array $resources @param bool $primary @return Collection
parseResources
php
cloudcreativity/laravel-json-api
src/Client/ClientSerializer.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/ClientSerializer.php
Apache-2.0
protected function parseResource(array $resource, $primary = false, $links = null) { if (false === $links || $this->doesRemoveLinks()) { unset($resource['links']); } $relationships = isset($resource['relationships']) ? $this->parseRelationships($resource['relationships'], $primary, $links) : []; if ($relationships) { $resource['relationships'] = $relationships; } else { unset($resource['relationships']); } return $resource; }
@param array $resource @param bool $primary @param bool|null $links @return array
parseResource
php
cloudcreativity/laravel-json-api
src/Client/ClientSerializer.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/ClientSerializer.php
Apache-2.0
protected function parseRelationships(array $relationships, $primary = false, $links = null) { return collect($relationships)->reject(function (array $relation) use ($primary) { return $primary && !array_key_exists('data', $relation); })->map(function (array $relation) use ($primary, $links) { return $this->parseRelationship($relation, $primary, $links); })->filter()->all(); }
@param array $relationships @param bool $primary @param bool|null $links @return array
parseRelationships
php
cloudcreativity/laravel-json-api
src/Client/ClientSerializer.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/ClientSerializer.php
Apache-2.0
protected function parseRelationship(array $relationship, $primary = false, $links = null) { if (false === $links || $this->doesRemoveLinks()) { unset($relationship['links']); } return $relationship ?: null; }
@param array $relationship @param bool $primary @param null $links @return array|null
parseRelationship
php
cloudcreativity/laravel-json-api
src/Client/ClientSerializer.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/ClientSerializer.php
Apache-2.0
public function __construct( Client $http, SchemaContainerInterface $schemas, ClientSerializer $serializer ) { parent::__construct($schemas, $serializer); $this->http = $http; }
GuzzleClient constructor. @param Client $http @param SchemaContainerInterface $schemas @param ClientSerializer $serializer
__construct
php
cloudcreativity/laravel-json-api
src/Client/GuzzleClient.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Client/GuzzleClient.php
Apache-2.0
public function didDecode(string ...$mediaTypes): bool { return app('json-api') ->currentRoute() ->getCodec() ->decodes(...$mediaTypes); }
Were any of the supplied media types decoded? @param string ...$mediaTypes @return bool
didDecode
php
cloudcreativity/laravel-json-api
src/Codec/ChecksMediaTypes.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/ChecksMediaTypes.php
Apache-2.0
public function didNotDecode(string ...$mediaTypes): bool { return !$this->didDecode(...$mediaTypes); }
Were none of the supplied media types decoded? @param string ...$mediaTypes @return bool
didNotDecode
php
cloudcreativity/laravel-json-api
src/Codec/ChecksMediaTypes.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/ChecksMediaTypes.php
Apache-2.0
public function willEncode(string ...$mediaTypes): bool { return app('json-api') ->currentRoute() ->getCodec() ->encodes(...$mediaTypes); }
Will any of the supplied media types be encoded? @param string ...$mediaTypes @return bool
willEncode
php
cloudcreativity/laravel-json-api
src/Codec/ChecksMediaTypes.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/ChecksMediaTypes.php
Apache-2.0
public function willNotEncode(string ...$mediaTypes): bool { return !$this->willEncode(...$mediaTypes); }
Will none of the supplied media types be encoded? @param string ...$mediaTypes @return bool
willNotEncode
php
cloudcreativity/laravel-json-api
src/Codec/ChecksMediaTypes.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/ChecksMediaTypes.php
Apache-2.0
public function __construct( Factory $factory, MediaTypeParser $mediaTypeParser, ContainerInterface $container, Encoding $encoding, ?Decoding $decoding ) { $this->factory = $factory; $this->mediaTypeParser = $mediaTypeParser; $this->container = $container; $this->encoding = $encoding; $this->decoding = $decoding; }
Codec constructor. @param Factory $factory @param MediaTypeParser $mediaTypeParser @param ContainerInterface $container @param Encoding $encoding @param Decoding|null $decoding
__construct
php
cloudcreativity/laravel-json-api
src/Codec/Codec.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Codec.php
Apache-2.0
public function willEncode(): bool { return $this->encoding->hasOptions(); }
Will the codec encode JSON API content? @return bool
willEncode
php
cloudcreativity/laravel-json-api
src/Codec/Codec.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Codec.php
Apache-2.0
public function willNotEncode(): bool { return !$this->willEncode(); }
Will the codec not encode JSON API content? @return bool
willNotEncode
php
cloudcreativity/laravel-json-api
src/Codec/Codec.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Codec.php
Apache-2.0
public function encodes(string ...$mediaTypes): bool { $encoding = $this->getEncodingMediaType(); return Collection::make($mediaTypes)->contains( fn($mediaType) => $encoding->equalsTo($this->mediaTypeParser->parse($mediaType)) ); }
Does the codec encode any of the supplied media types? @param string ...$mediaTypes @return bool
encodes
php
cloudcreativity/laravel-json-api
src/Codec/Codec.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Codec.php
Apache-2.0
public function canDecodeJsonApi(): bool { if (!$this->decoding) { return false; } return $this->decoding->isJsonApi(); }
Will the codec decode JSON API content? @return bool
canDecodeJsonApi
php
cloudcreativity/laravel-json-api
src/Codec/Codec.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Codec.php
Apache-2.0
public function cannotDecodeJsonApi(): bool { return !$this->canDecodeJsonApi(); }
Will the codec not decode JSON API content? @return bool
cannotDecodeJsonApi
php
cloudcreativity/laravel-json-api
src/Codec/Codec.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Codec.php
Apache-2.0
public function decodes(string ...$mediaTypes): bool { if (!$decoding = $this->getDecodingMediaType()) { return false; } return Collection::make($mediaTypes)->contains( fn($mediaType) => $decoding->equalsTo($this->mediaTypeParser->parse($mediaType)) ); }
Does the codec decode any of the supplied media types? @param string ...$mediaTypes @return bool
decodes
php
cloudcreativity/laravel-json-api
src/Codec/Codec.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Codec.php
Apache-2.0
public function document($request): ?\stdClass { if ($this->cannotDecodeJsonApi()) { return null; } return $this->decoding->getJsonApiDecoder()->document($request); }
Decode a JSON API document from the request content. @param $request @return \stdClass|null
document
php
cloudcreativity/laravel-json-api
src/Codec/Codec.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Codec.php
Apache-2.0
public function all($request): array { return $this->decoding ? $this->decoding->getDecoder()->decode($request) : []; }
Retrieve array input from the request. @param $request @return array
all
php
cloudcreativity/laravel-json-api
src/Codec/Codec.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Codec.php
Apache-2.0
public static function create($mediaType, $decoder): self { if (is_string($mediaType)) { $mediaType = MediaTypeParser::make()->parse($mediaType); } if (!$mediaType instanceof MediaTypeInterface) { throw new \InvalidArgumentException('Expecting a media type object or string.'); } if (is_string($decoder)) { $decoder = app($decoder); } if (!$decoder instanceof DecoderInterface) { throw new \InvalidArgumentException('Expecting a decoder or decoder service name.'); } return new self($mediaType, $decoder); }
Create a decoding. @param string|MediaTypeInterface $mediaType @param string|DecoderInterface $decoder @return Decoding
create
php
cloudcreativity/laravel-json-api
src/Codec/Decoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Decoding.php
Apache-2.0
public static function fromArray($key, $value): self { if (is_numeric($key)) { $key = $value; $value = new JsonApiDecoder(); } return self::create($key, $value); }
@param $key @param $value @return Decoding
fromArray
php
cloudcreativity/laravel-json-api
src/Codec/Decoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Decoding.php
Apache-2.0
public function __construct(MediaTypeInterface $mediaType, DecoderInterface $decoder) { $this->mediaType = $mediaType; $this->decoder = $decoder; }
Decoding constructor. @param MediaTypeInterface $mediaType @param DecoderInterface $decoder
__construct
php
cloudcreativity/laravel-json-api
src/Codec/Decoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Decoding.php
Apache-2.0
public function isJsonApi(): bool { return $this->decoder instanceof JsonApiDecoder; }
Will the decoding decode JSON API content? @return bool
isJsonApi
php
cloudcreativity/laravel-json-api
src/Codec/Decoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Decoding.php
Apache-2.0
public function prepend(Decoding ...$decodings): self { $copy = clone $this; array_unshift($copy->stack, ...$decodings); return $copy; }
Return a new instance with the supplied decodings added to the beginning of the stack. @param Decoding ...$decodings @return DecodingList
prepend
php
cloudcreativity/laravel-json-api
src/Codec/DecodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/DecodingList.php
Apache-2.0
public function push(Decoding ...$decodings): self { $copy = new self(); $copy->stack = Collection::make($this->stack)->merge($decodings)->all(); return $copy; }
Return a new instance with the supplied decodings added to the end of the stack. @param Decoding ...$decodings @return DecodingList
push
php
cloudcreativity/laravel-json-api
src/Codec/DecodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/DecodingList.php
Apache-2.0
public function merge(DecodingList $decodings): self { $copy = new self(); $copy->stack = Collection::make($this->stack)->merge($decodings->stack)->all(); return $copy; }
Return a new instance with the supplied decodings merged. @param DecodingList $decodings @return DecodingList
merge
php
cloudcreativity/laravel-json-api
src/Codec/DecodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/DecodingList.php
Apache-2.0
public function when(bool $test, $decodings): self { if (!$test) { return $this; } if ($decodings instanceof \Closure) { return $decodings($this); } $decodings = $decodings instanceof Decoding ? [$decodings] : $decodings; return $this->push(...$decodings); }
Push decodings if the truth test evaluates to true. @param bool $test @param Decoding|iterable|\Closure $decodings @return DecodingList
when
php
cloudcreativity/laravel-json-api
src/Codec/DecodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/DecodingList.php
Apache-2.0
public function unless(bool $test, $decodings): self { return $this->when(true !== $test, $decodings); }
Push decodings if the truth test does not evaluate to true. @param bool $test @param $decodings @return DecodingList
unless
php
cloudcreativity/laravel-json-api
src/Codec/DecodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/DecodingList.php
Apache-2.0
public function find(string $mediaType): ?Decoding { return $this->equalsTo(MediaTypeParser::make()->parse($mediaType)); }
Find a matching decoding by media type. @param string $mediaType @return Decoding|null
find
php
cloudcreativity/laravel-json-api
src/Codec/DecodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/DecodingList.php
Apache-2.0
public function equalsTo(MediaTypeInterface $mediaType): ?Decoding { return Collection::make($this->stack)->first(function (Decoding $decoding) use ($mediaType) { return $decoding->equalsTo($mediaType); }); }
Get the decoding that matches the supplied media type. @param MediaTypeInterface $mediaType @return Decoding|null
equalsTo
php
cloudcreativity/laravel-json-api
src/Codec/DecodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/DecodingList.php
Apache-2.0
public function forHeader(HeaderInterface $header): ?Decoding { foreach ($header->getMediaTypes() as $mediaType) { if ($decoding = $this->equalsTo($mediaType)) { return $decoding; } } return null; }
@param HeaderInterface $header @return Decoding|null
forHeader
php
cloudcreativity/laravel-json-api
src/Codec/DecodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/DecodingList.php
Apache-2.0
public static function create( $mediaType, int $options = 0, ?string $urlPrefix = null, int $depth = 512 ): self { if (!$mediaType instanceof MediaTypeInterface) { $mediaType = MediaTypeParser::make()->parse($mediaType); } return new self($mediaType, new EncoderOptions($options, $urlPrefix, $depth)); }
Create an encoding that will encode JSON API content. @param string|MediaTypeInterface $mediaType @param int $options @param string|null $urlPrefix @param int $depth @return Encoding
create
php
cloudcreativity/laravel-json-api
src/Codec/Encoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Encoding.php
Apache-2.0
public static function jsonApi(int $options = 0, ?string $urlPrefix = null, int $depth = 512): self { return self::create( MediaTypeInterface::JSON_API_MEDIA_TYPE, $options, $urlPrefix, $depth ); }
Create an encoding for the JSON API media type. @param int $options @param string|null $urlPrefix @param int $depth @return Encoding
jsonApi
php
cloudcreativity/laravel-json-api
src/Codec/Encoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Encoding.php
Apache-2.0
public static function custom($mediaType): self { if (!$mediaType instanceof MediaTypeInterface) { $mediaType = MediaTypeParser::make()->parse($mediaType); } return new self($mediaType, null); }
Create an encoding that will not encode JSON API content. @param string|MediaTypeInterface $mediaType @return Encoding
custom
php
cloudcreativity/laravel-json-api
src/Codec/Encoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Encoding.php
Apache-2.0
public static function fromArray($key, $value, ?string $urlPrefix = null): self { if (is_numeric($key)) { $key = $value; $value = 0; } return (false === $value) ? self::custom($key) : self::create($key, $value, $urlPrefix); }
@param $key @param $value @param string|null $urlPrefix @return Encoding
fromArray
php
cloudcreativity/laravel-json-api
src/Codec/Encoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Encoding.php
Apache-2.0
public function __construct(MediaTypeInterface $mediaType, ?EncoderOptions $options) { $this->mediaType = $mediaType; $this->options = $options; }
Encoding constructor. @param MediaTypeInterface $mediaType @param EncoderOptions|null $options the encoding options, if the encoding to JSON API content is supported.
__construct
php
cloudcreativity/laravel-json-api
src/Codec/Encoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Encoding.php
Apache-2.0
public function getOptions(): ?EncoderOptions { return $this->options; }
Get the options, if the media type returns JSON API encoded content. @return EncoderOptions|null
getOptions
php
cloudcreativity/laravel-json-api
src/Codec/Encoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Encoding.php
Apache-2.0
public function hasOptions(): bool { return !is_null($this->options); }
Will the encoding encode JSON API content? @return bool
hasOptions
php
cloudcreativity/laravel-json-api
src/Codec/Encoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Encoding.php
Apache-2.0
public function is(string ...$mediaTypes): bool { $mediaTypes = Collection::make($mediaTypes)->map( fn($mediaType) => MediaTypeParser::make()->parse($mediaType) ); return $this->any(...$mediaTypes); }
Is the encoding for any of the supplied media types? @param string ...$mediaTypes @return bool
is
php
cloudcreativity/laravel-json-api
src/Codec/Encoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Encoding.php
Apache-2.0
public function matchesTo(MediaTypeInterface $mediaType): bool { return $this->getMediaType()->matchesTo($mediaType); }
Does the encoding match the supplied media type? @param MediaTypeInterface $mediaType @return bool
matchesTo
php
cloudcreativity/laravel-json-api
src/Codec/Encoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Encoding.php
Apache-2.0
public function accept(AcceptMediaTypeInterface $mediaType): bool { // if quality factor 'q' === 0 it means this type is not acceptable (RFC 2616 #3.9) if (0 === $mediaType->getQuality()) { return false; } return $this->matchesTo($mediaType); }
Is the encoding acceptable? @param AcceptMediaTypeInterface $mediaType @return bool
accept
php
cloudcreativity/laravel-json-api
src/Codec/Encoding.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/Encoding.php
Apache-2.0
public static function fromArray(iterable $config, ?string $urlPrefix = null): self { $values = Collection::make($config) ->map(fn($value, $key) => Encoding::fromArray($key, $value, $urlPrefix)) ->values(); return new self(...$values); }
Create encodings from array config. @param iterable $config @param string|null $urlPrefix @return EncodingList
fromArray
php
cloudcreativity/laravel-json-api
src/Codec/EncodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/EncodingList.php
Apache-2.0
public static function createCustom(...$mediaTypes): self { $encodings = new self(); $encodings->stack = Collection::make($mediaTypes)->map( fn($mediaType) => Encoding::custom($mediaType) )->all(); return $encodings; }
Create encodings that will not encode JSON API content. @param string|MediaTypeInterface ...$mediaTypes @return EncodingList
createCustom
php
cloudcreativity/laravel-json-api
src/Codec/EncodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/EncodingList.php
Apache-2.0
public function prepend(Encoding ...$encodings): self { $copy = clone $this; array_unshift($copy->stack, ...$encodings); return $copy; }
Return a new instance with the supplied encodings added to the beginning of the stack. @param Encoding ...$encodings @return EncodingList
prepend
php
cloudcreativity/laravel-json-api
src/Codec/EncodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/EncodingList.php
Apache-2.0
public function push(Encoding ...$encodings): self { $copy = new self(); $copy->stack = Collection::make($this->stack)->merge($encodings)->all(); return $copy; }
Return a new instance with the supplied encodings added to the end of the stack. @param Encoding ...$encodings @return EncodingList
push
php
cloudcreativity/laravel-json-api
src/Codec/EncodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/EncodingList.php
Apache-2.0
public function merge(EncodingList $encodings): self { $copy = new self(); $copy->stack = Collection::make($this->stack)->merge($encodings->stack)->all(); return $copy; }
Return a new instance with the supplied encodings merged. @param EncodingList $encodings @return EncodingList
merge
php
cloudcreativity/laravel-json-api
src/Codec/EncodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/EncodingList.php
Apache-2.0
public function withCustom(...$mediaTypes): self { return $this->merge(self::createCustom(...$mediaTypes)); }
Return a new instance with the supplied custom encodings added to the end of the stack. A custom encoding is one that does not encode to JSON API. @param mixed ...$mediaTypes @return EncodingList
withCustom
php
cloudcreativity/laravel-json-api
src/Codec/EncodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/EncodingList.php
Apache-2.0
public function when(bool $test, $encodings): self { if (!$test || is_null($encodings)) { return $this; } if ($encodings instanceof \Closure) { return $encodings($this); } if (is_string($encodings)) { $encodings = Encoding::custom($encodings); } $encodings = $encodings instanceof Encoding ? [$encodings] : $encodings; return $this->push(...$encodings); }
Push encodings if the truth test evaluates to true. @param bool $test @param Encoding|string|iterable|\Closure|null $encodings @return EncodingList
when
php
cloudcreativity/laravel-json-api
src/Codec/EncodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/EncodingList.php
Apache-2.0
public function unless(bool $test, $encodings): self { return $this->when(true !== $test, $encodings); }
Push encodings if the truth test does not evaluate to true. @param bool $test @param Encoding|string|iterable|\Closure|null $encodings @return EncodingList
unless
php
cloudcreativity/laravel-json-api
src/Codec/EncodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/EncodingList.php
Apache-2.0
public function optional($encoding): self { if (is_string($encoding)) { $encoding = Encoding::custom($encoding); } return $encoding ? $this->push($encoding) : $this; }
@param Encoding|string|null $encoding @return EncodingList
optional
php
cloudcreativity/laravel-json-api
src/Codec/EncodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/EncodingList.php
Apache-2.0
public function find(string $mediaType): ?Encoding { return $this->matchesTo(MediaTypeParser::make()->parse($mediaType)); }
Find a matching encoding by media type. @param string $mediaType @return Encoding|null
find
php
cloudcreativity/laravel-json-api
src/Codec/EncodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/EncodingList.php
Apache-2.0
public function matchesTo(MediaTypeInterface $mediaType): ?Encoding { return Collection::make($this->stack)->first(function (Encoding $encoding) use ($mediaType) { return $encoding->matchesTo($mediaType); }); }
Get the encoding that matches the supplied media type. @param MediaTypeInterface $mediaType @return Encoding|null
matchesTo
php
cloudcreativity/laravel-json-api
src/Codec/EncodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/EncodingList.php
Apache-2.0
public function acceptable(AcceptHeaderInterface $accept): ?Encoding { foreach ($accept->getMediaTypes() as $mediaType) { if ($encoding = $this->matchesTo($mediaType)) { return $encoding; } } return null; }
Get the acceptable encoding for the supplied Accept header. @param AcceptHeaderInterface $accept @return Encoding|null
acceptable
php
cloudcreativity/laravel-json-api
src/Codec/EncodingList.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Codec/EncodingList.php
Apache-2.0
public function __construct(Filesystem $files, Repository $apiRepository) { parent::__construct($files); $this->apiRepository = $apiRepository; $this->stubsDirectory = __DIR__ . '/../../../stubs'; }
AbstractGeneratorCommand constructor. @param Filesystem $files @param Repository $apiRepository
__construct
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
protected function getNameInput() { if (!$this->isByResource()) { return $this->getResourceName(); } return $this->type; }
Get the desired class name from the input. @return string
getNameInput
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
protected function buildClass($name) { $stub = $this->files->get($this->getStub()); $this->replaceNamespace($stub, $name) ->replaceClassName($stub, $name) ->replaceResourceType($stub) ->replaceApplicationNamespace($stub) ->replaceRecord($stub) ->replaceModelNamespace($stub); return $stub; }
Build the class with the given name. @param string $name @return string
buildClass
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
protected function getArguments() { return [ ['resource', InputArgument::REQUIRED, "The resource for which a {$this->type} class will be generated."], ['api', InputArgument::OPTIONAL, "The API that the resource belongs to."], ]; }
Get the console command arguments. @return array
getArguments
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
protected function getOptions() { if ($this->isIndependent) { return []; } return [ ['eloquent', 'e', InputOption::VALUE_NONE, 'Use Eloquent classes.'], ['no-eloquent', 'N', InputOption::VALUE_NONE, 'Do not use Eloquent classes.'], ]; }
Get the console command options. @return array
getOptions
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
protected function getStub() { if ($this->isIndependent) { return $this->getStubFor('independent'); } if ($this->isEloquent()) { return $this->getStubFor('eloquent'); } return $this->getStubFor('abstract'); }
Get the stub file for the generator. @return string
getStub
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
protected function getResourceName() { $name = ucwords($this->getResourceInput()); if ($this->isByResource()) { return IlluminateStr::plural($name); } return $name; }
Get the resource name @return string
getResourceName
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
protected function replaceResourceType(&$stub) { $resource = $this->getResourceName(); $stub = str_replace('dummyResourceType', Str::dasherize($resource), $stub); return $this; }
Replace the value of the resource type string. @param mixed $stub @return $this
replaceResourceType
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
protected function replaceRecord(&$stub) { $resource = $this->getResourceName(); $stub = str_replace('DummyRecord', Str::classify(IlluminateStr::singular($resource)), $stub); return $this; }
Replace the value of the model class name. @param $stub @return $this
replaceRecord
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
protected function replaceApplicationNamespace(&$stub) { $namespace = rtrim($this->laravel->getNamespace(), '\\'); $stub = str_replace('DummyApplicationNamespace', $namespace, $stub); return $this; }
Replace the value of the application namespace. @param $stub @return $this
replaceApplicationNamespace
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
protected function replaceClassName(&$stub, $name) { $stub = $this->replaceClass($stub, $name); return $this; }
Replace the class name. @param $stub @return $this
replaceClassName
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
private function replaceModelNamespace(&$stub) { $modelNamespace = $this->getApi()->getModelNamespace() ?? rtrim($this->laravel->getNamespace(), "\\"); $stub = str_replace('DummyModelNamespace', $modelNamespace, $stub); return $this; }
Replace the model namespace name. @param $stub @return $this
replaceModelNamespace
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
protected function getStubFor($implementationType) { return sprintf( '%s/%s/%s.stub', $this->stubsDirectory, $implementationType, Str::dasherize($this->type) ); }
Get the stub for specific generator type @param string $implementationType @return string
getStubFor
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
protected function isEloquent() { if ($this->isIndependent) { return false; } if ($this->option('no-eloquent')) { return false; } return $this->option('eloquent') ?: $this->getApi()->isEloquent(); }
Determine whether a resource is eloquent or not @return boolean
isEloquent
php
cloudcreativity/laravel-json-api
src/Console/Commands/AbstractGeneratorCommand.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/AbstractGeneratorCommand.php
Apache-2.0
protected function getArguments() { return [ ['name', InputArgument::REQUIRED, "The authorizer name or resource type."], ['api', InputArgument::OPTIONAL, "The API that the resource belongs to."], ]; }
Get the console command arguments. @return array
getArguments
php
cloudcreativity/laravel-json-api
src/Console/Commands/MakeAuthorizer.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/MakeAuthorizer.php
Apache-2.0
protected function getOptions() { return [ ['resource', 'r', InputOption::VALUE_NONE, 'Generate a resource-specific authorizer.'], ]; }
Get the console command options. @return array
getOptions
php
cloudcreativity/laravel-json-api
src/Console/Commands/MakeAuthorizer.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/MakeAuthorizer.php
Apache-2.0
protected function getArguments() { return [ ['name', InputArgument::REQUIRED, "The content negotiator name or resource type."], ['api', InputArgument::OPTIONAL, "The API that the content negotiator belongs to."], ]; }
Get the console command arguments. @return array
getArguments
php
cloudcreativity/laravel-json-api
src/Console/Commands/MakeContentNegotiator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/MakeContentNegotiator.php
Apache-2.0
protected function getOptions() { return [ ['resource', 'r', InputOption::VALUE_NONE, 'Generate a resource-specific content negotiator.'], ]; }
Get the console command options. @return array
getOptions
php
cloudcreativity/laravel-json-api
src/Console/Commands/MakeContentNegotiator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/MakeContentNegotiator.php
Apache-2.0
public function handle() { $resourceParameter = [ 'resource' => $this->argument('resource'), 'api' => $this->argument('api'), ]; $eloquentParameters = array_merge($resourceParameter, [ '--eloquent' => $this->option('eloquent'), '--no-eloquent' => $this->option('no-eloquent'), ]); $commands = collect($this->commands); /** Just tell the user, if no files are created */ if ($commands->isEmpty()) { $this->info('No files created.'); return 0; } /** Filter out any commands the user asked os to. */ if ($this->option('only') || $this->option('except')) { $type = $this->option('only') ? 'only' : 'except'; $commands = $this->filterCommands($commands, $type); } /** Run commands that cannot accept Eloquent parameters. */ $notEloquent = ['make:json-api:validators']; if (!$this->runCommandsWithParameters($commands->only($notEloquent), $resourceParameter)) { return 1; } /** Run commands that can accept Eloquent parameters. */ $eloquent = ['make:json-api:adapter', 'make:json-api:schema']; if (!$this->runCommandsWithParameters($commands->only($eloquent), $eloquentParameters)) { return 1; } /** Authorizer */ if ($this->option('auth')) { $this->call('make:json-api:authorizer', [ 'name' => $this->argument('resource'), 'api' => $this->argument('api'), '--resource' => true, ]); } /** Content Negotiator */ if ($this->option('content-negotiator')) { $this->call('make:json-api:content-negotiator', [ 'name' => $this->argument('resource'), 'api' => $this->argument('api'), '--resource' => true, ]); } /** Give the user a digial high-five. */ $this->comment('All done, keep doing what you do.'); return 0; }
Execute the console command. @return int
handle
php
cloudcreativity/laravel-json-api
src/Console/Commands/MakeResource.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/MakeResource.php
Apache-2.0
private function filterCommands(Collection $commands, $type) { $baseCommandName = 'make:json-api:'; $filterValues = explode(',', $this->option($type)); $targetCommands = collect($filterValues) ->map(function ($target) use ($baseCommandName) { return $baseCommandName . strtolower(trim($target)); }); return $commands->{$type}($targetCommands->toArray()); }
Filters out commands using either 'except' or 'only' filter. @param Collection $commands @param string $type @return Collection
filterCommands
php
cloudcreativity/laravel-json-api
src/Console/Commands/MakeResource.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/MakeResource.php
Apache-2.0
private function runCommandsWithParameters(Collection $commands, array $parameters) { foreach ($commands->keys() as $command) { if (0 !== $this->call($command, $parameters)) { return false; } } return true; }
Runs the given commands and passes them all the given parameters. @param Collection $commands @param array $parameters @return bool
runCommandsWithParameters
php
cloudcreativity/laravel-json-api
src/Console/Commands/MakeResource.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Console/Commands/MakeResource.php
Apache-2.0
public function document($request): \stdClass { return json_decode($request->getContent()); }
Decode a JSON API document from a request. JSON API request content MUST be decoded as an object, as it is not possible to validate that the request content complies with the JSON API spec if it is JSON decoded to an associative array. If the decoder is unable to return an object when decoding content, it MUST throw a HTTP exception or a JSON API exception. @param Request $request @return \stdClass the JSON API document. @throws JsonApiException @throws \LogicException if the decoder does not decode JSON API content.
document
php
cloudcreativity/laravel-json-api
src/Decoder/JsonApiDecoder.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Decoder/JsonApiDecoder.php
Apache-2.0
public function createError(Error $error): ErrorInterface { $about = $error->getLinks()[DocumentInterface::KEYWORD_ERRORS_ABOUT] ?? null; $meta = $error->getMeta(); return new \Neomerx\JsonApi\Schema\Error( $error->getId(), $about ? $this->createLink($about) : null, null, $error->getStatus(), $error->getCode(), $error->getTitle(), $error->getDetail(), $error->getSource(), !empty($meta), $meta, ); }
Map a Laravel JSON:API error to a Neomerx error. @param Error $error @return ErrorInterface
createError
php
cloudcreativity/laravel-json-api
src/Document/Mapper.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Mapper.php
Apache-2.0
public function castError($error): ErrorInterface { if ($error instanceof ErrorInterface) { return $error; } return $this->createError(Error::cast($error)); }
Cast an error to a Neomerx error. @param ErrorInterface|Error|array $error @return ErrorInterface
castError
php
cloudcreativity/laravel-json-api
src/Document/Mapper.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Mapper.php
Apache-2.0
public function createErrors(iterable $errors): array { if ($errors instanceof ErrorCollection) { return $errors->getArrayCopy(); } $converted = []; foreach ($errors as $error) { $converted[] = $this->castError($error); } return $converted; }
Create an error collection. @param iterable $errors @return ErrorInterface[]
createErrors
php
cloudcreativity/laravel-json-api
src/Document/Mapper.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Mapper.php
Apache-2.0
private function createLink(Link $link): LinkInterface { $meta = $link->getMeta(); return $this->factory->createLink( false, $link->getHref(), !empty($meta), $meta, ); }
Map a Laravel JSON:API link to a Neomerx link. @param Link $link @return LinkInterface
createLink
php
cloudcreativity/laravel-json-api
src/Document/Mapper.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Mapper.php
Apache-2.0
public static function create(array $data): self { if (!isset($data['type'])) { throw new \InvalidArgumentException('Expecting a resource type.'); } return new self( $data['type'], $data['id'] ?? null, $data['attributes'] ?? [], $data['relationships'] ?? [], $data['meta'] ?? [], $data['links'] ?? [] ); }
Create a resource object from the data member of a JSON document. @param array $data @return ResourceObject
create
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function __construct( string $type, ?string $id, array $attributes, array $relationships = [], array $meta = [], array $links = [] ) { if (empty($type)) { throw new \InvalidArgumentException('Expecting a non-empty string.'); } $this->type = $type; $this->id = $id ?: null; $this->attributes = $attributes; $this->relationships = $relationships; $this->meta = $meta; $this->links = $links; $this->normalize(); }
ResourceObject constructor. @param string $type @param string|null $id @param array $attributes @param array $relationships @param array $meta @param array $links
__construct
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function withType(string $type): self { if (empty($type)) { throw new \InvalidArgumentException('Expecting a non-empty string.'); } $copy = clone $this; $copy->type = $type; $copy->normalize(); return $copy; }
Return a new instance with the specified type. @param string $type @return ResourceObject
withType
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function withId(?string $id): self { $copy = clone $this; $copy->id = $id ?: null; $copy->normalize(); return $copy; }
Return a new instance with the specified id. @param string|null $id @return ResourceObject
withId
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function withoutId(): self { return $this->withId(null); }
Return a new instance without an id. @return ResourceObject
withoutId
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function isAttribute(string $field): bool { return array_key_exists($field, $this->attributes); }
Is the field an attribute? @param string $field @return bool
isAttribute
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function withAttributes($attributes): self { $copy = clone $this; $copy->attributes = collect($attributes)->all(); $copy->normalize(); return $copy; }
Return a new instance with the provided attributes. @param array|Collection $attributes @return ResourceObject
withAttributes
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function withoutAttributes(): self { return $this->withAttributes([]); }
Return a new instance without attributes. @return ResourceObject
withoutAttributes
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function isRelationship(string $field): bool { return array_key_exists($field, $this->relationships); }
Is the field a relationship? @param string $field @return bool
isRelationship
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function withRelationships($relationships): self { $copy = clone $this; $copy->relationships = collect($relationships)->all(); $copy->normalize(); return $copy; }
Return a new instance with the provided relationships. @param array|Collection $relationships @return ResourceObject
withRelationships
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0