code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
public function uri(string $uri): self
{
$this->options['resource_uri'] = $uri;
return $this;
}
|
Set the URI fragment, if different from the resource type.
@param string $uri
@return $this
|
uri
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ResourceRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ResourceRegistration.php
|
Apache-2.0
|
public function middleware(string ...$middleware): self
{
$this->options['middleware'] = array_merge(
Arr::wrap($this->options['middleware'] ?? []),
$middleware
);
return $this;
}
|
Add middleware.
@param string ...$middleware
@return $this
|
middleware
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ResourceRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ResourceRegistration.php
|
Apache-2.0
|
public function id(?string $constraint): self
{
$this->options['id'] = $constraint;
return $this;
}
|
@param string|null $constraint
@return $this
|
id
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ResourceRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ResourceRegistration.php
|
Apache-2.0
|
public function __construct(ResolverInterface $resolver, ?IlluminateRoute $route)
{
$this->resolver = $resolver;
$this->route = $route;
}
|
Route constructor.
@param ResolverInterface $resolver
@param IlluminateRoute|null $route
the route, if one was successfully matched.
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public function substituteBindings(StoreInterface $store): void
{
/** Cache the ID values so that we still have access to them. */
$tempResourceId = $this->getResourceId();
$tempProcessId = $this->getProcessId();
$this->resourceId = isset($tempResourceId) ? $tempResourceId : false;
$this->processId = isset($tempProcessId) ? $tempProcessId : false;
/** Bind the domain record. */
if (!empty($this->resourceId) || '0' === $this->resourceId) {
$this->route->setParameter(
ResourceRegistrar::PARAM_RESOURCE_ID,
$store->findOrFail($this->getResourceType(), $this->resourceId)
);
}
/** Bind the async process. */
if (!empty($this->processId) || '0' === $this->processId) {
$this->route->setParameter(
ResourceRegistrar::PARAM_PROCESS_ID,
$store->findOrFail($this->getProcessType(), $this->processId)
);
}
}
|
Substitute the route bindings onto the Laravel route.
@param StoreInterface $store
@return void
@throws ResourceNotFoundException
|
substituteBindings
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public function setCodec(Codec $codec): self
{
$this->codec = $codec;
return $this;
}
|
Set the matched codec.
@param Codec $codec
@return $this
|
setCodec
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public function getCodec(): Codec
{
if (!$this->hasCodec()) {
throw new RuntimeException('Codec cannot be obtained before content negotiation.');
}
return $this->codec;
}
|
Get the matched codec.
@return Codec
|
getCodec
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public function getType(): string
{
$type = $this->getTypes()[0] ?? null;
if (!$type) {
throw new RuntimeException('Expecting at least one PHP type.');
}
return $type;
}
|
Get the domain record type for the route.
For routes that support polymorphic types, the first PHP type that is
registered will be returned.
@return string
@deprecated 2.0 use `getTypes()` as some routes may support polymorphic types.
|
getType
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public function getTypes(): array
{
/** If we have resolved a specific record for the route, we know the exact class. */
if ($resource = $this->getResource()) {
return [get_class($resource)];
}
$resourceType = $this->getResourceType();
if (!$type = $this->resolver->getType($resourceType)) {
throw new RuntimeException("JSON API resource type {$resourceType} is not registered.");
}
return (array) $type;
}
|
Get the domain record types for the route.
As some routes support polymorphic types, this method returns an array of PHP types.
@return string[]
|
getTypes
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public function getResourceType(): ?string
{
return $this->parameter(ResourceRegistrar::PARAM_RESOURCE_TYPE);
}
|
What is the resource type of the route?
@return string|null
the resource type
|
getResourceType
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public function getResourceId(): ?string
{
if (is_null($this->resourceId)) {
return $this->parameter(ResourceRegistrar::PARAM_RESOURCE_ID);
}
return $this->resourceId ?: null;
}
|
What is the resource id of the route?
@return string|null
|
getResourceId
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public function getResource()
{
$resource = $this->parameter(ResourceRegistrar::PARAM_RESOURCE_ID);
return is_object($resource) ? $resource : null;
}
|
Get the domain object binding for the route.
@return mixed|null
|
getResource
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public function getRelationshipName(): ?string
{
return $this->parameter(ResourceRegistrar::PARAM_RELATIONSHIP_NAME);
}
|
Get the relationship name for the route.
@return string|null
|
getRelationshipName
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public function getInverseResourceType(): ?string
{
return $this->parameter(ResourceRegistrar::PARAM_RELATIONSHIP_INVERSE_TYPE);
}
|
Get the the inverse resource type for the route.
For example, a `GET /posts/1/author`, the string returned by this method
would be `users` if the related author is a `users` JSON API resource type.
@return string|null
|
getInverseResourceType
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public function getProcessType(): ?string
{
return $this->parameter(ResourceRegistrar::PARAM_PROCESS_TYPE);
}
|
Get the process resource type for the route.
@return string|null
|
getProcessType
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public function getProcessId(): ?string
{
if (is_null($this->processId)) {
return $this->parameter(ResourceRegistrar::PARAM_PROCESS_ID);
}
return $this->processId ?: null;
}
|
Get the process id for the route.
@return string|null
|
getProcessId
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public function getProcess(): ?AsynchronousProcess
{
$process = $this->parameter(ResourceRegistrar::PARAM_PROCESS_ID);
return ($process instanceof AsynchronousProcess) ? $process : null;
}
|
Get the process binding for the route.
@return AsynchronousProcess|null
|
getProcess
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
private function parameter(string $name, $default = null)
{
return $this->route ? $this->route->parameter($name, $default) : null;
}
|
@param string $name
@param mixed $default
@return mixed
|
parameter
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/Route.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/Route.php
|
Apache-2.0
|
public static function related($resourceType, $relationship)
{
return "$resourceType.relationships.$relationship";
}
|
@param $resourceType
@param $relationship
@return string
|
related
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RouteName.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RouteName.php
|
Apache-2.0
|
public static function readRelationship($resourceType, $relationship)
{
return self::related($resourceType, $relationship) . ".read";
}
|
@param $resourceType
@param $relationship
@return string
|
readRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RouteName.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RouteName.php
|
Apache-2.0
|
public static function replaceRelationship($resourceType, $relationship)
{
return self::related($resourceType, $relationship) . ".replace";
}
|
@param $resourceType
@param $relationship
@return string
|
replaceRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RouteName.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RouteName.php
|
Apache-2.0
|
public static function addRelationship($resourceType, $relationship)
{
return self::related($resourceType, $relationship) . ".add";
}
|
@param $resourceType
@param $relationship
@return string
|
addRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RouteName.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RouteName.php
|
Apache-2.0
|
public static function removeRelationship($resourceType, $relationship)
{
return self::related($resourceType, $relationship) . ".remove";
}
|
@param $resourceType
@param $relationship
@return string
|
removeRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RouteName.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RouteName.php
|
Apache-2.0
|
public function __construct(Registrar $router, array $options = [], array $defaults = [])
{
$this->router = $router;
$this->options = $options;
$this->defaults = $defaults;
}
|
RouteRegistrar constructor.
@param Registrar $router
@param array $options
@param array $defaults
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RouteRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RouteRegistrar.php
|
Apache-2.0
|
public function __call($name, $arguments)
{
return call_user_func_array([$this->route(), $name], $arguments);
}
|
@param $name
@param $arguments
@return mixed
|
__call
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RouteRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RouteRegistrar.php
|
Apache-2.0
|
public function resource(string $resourceType, array $options = []): ResourceRegistration
{
return new ResourceRegistration(
$this->router,
$resourceType,
array_merge($this->options, $options)
);
}
|
Register routes for the supplied resource type
@param string $resourceType
@param array $options
@return ResourceRegistration
|
resource
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RouteRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RouteRegistrar.php
|
Apache-2.0
|
public function __construct(Router $router, RouteRegistrar $registrar, array $defaults = [])
{
parent::__construct($router);
$this->registrar = $registrar;
$this->defaults = $defaults;
}
|
CustomRegistration constructor.
@param Router $router
@param RouteRegistrar $registrar
@param array $defaults
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RouteRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RouteRegistration.php
|
Apache-2.0
|
public function controller(string $controller): self
{
$this->controller = $controller;
return $this;
}
|
Set the controller for the route.
@param string $controller
@return $this
|
controller
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RouteRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RouteRegistration.php
|
Apache-2.0
|
public function field(string $field, ?string $inverse = null): self
{
$this->defaults = array_merge($this->defaults, [
ResourceRegistrar::PARAM_RELATIONSHIP_NAME => $field,
ResourceRegistrar::PARAM_RELATIONSHIP_INVERSE_TYPE => $inverse ?: Str::plural($field),
]);
return $this;
}
|
Set the route's relationship field name and inverse resource type.
@param string $field
@param string|null $inverse
@return $this
|
field
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RouteRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RouteRegistration.php
|
Apache-2.0
|
public function __construct(?array $allowed = null)
{
$this->all = is_null($allowed);
$this->allowed = collect($allowed)->combine($allowed);
}
|
AllowedFilterParameters constructor.
@param array|null $allowed
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/AbstractAllowedRule.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/AbstractAllowedRule.php
|
Apache-2.0
|
public function allow(string ...$params): self
{
$this->all = false;
foreach ($params as $param) {
$this->allowed->put($param, $param);
}
return $this;
}
|
Add allowed parameters.
@param string ...$params
@return $this
|
allow
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/AbstractAllowedRule.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/AbstractAllowedRule.php
|
Apache-2.0
|
public function forget(string ...$params): self
{
$this->allowed->forget($params);
return $this;
}
|
Forget an allowed parameter.
@param string ...$params
@return $this
|
forget
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/AbstractAllowedRule.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/AbstractAllowedRule.php
|
Apache-2.0
|
protected function allowed(string $param): bool
{
return $this->allowed->has($param);
}
|
Is the parameter allowed?
@param string $param
@return bool
|
allowed
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/AbstractAllowedRule.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/AbstractAllowedRule.php
|
Apache-2.0
|
public function __construct(?array $allowed = null)
{
$this->all = is_null($allowed);
$this->allowed = collect($allowed);
}
|
AllowedFieldSets constructor.
@param array|null $allowed
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/AllowedFieldSets.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/AllowedFieldSets.php
|
Apache-2.0
|
public function allow(string $resourceType, ?array $fields = null): self
{
$this->all = false;
$this->allowed[$resourceType] = $fields;
return $this;
}
|
Allow fields for a resource type.
@param string $resourceType
@param string[]|null $fields
the allowed fields, empty array for none allowed, or null for all allowed.
@return $this
|
allow
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/AllowedFieldSets.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/AllowedFieldSets.php
|
Apache-2.0
|
public function any(string ...$resourceTypes): self
{
foreach ($resourceTypes as $resourceType) {
$this->allow($resourceType, null);
}
return $this;
}
|
Allow any fields for the specified resource type.
@param string ...$resourceTypes
@return $this
|
any
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/AllowedFieldSets.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/AllowedFieldSets.php
|
Apache-2.0
|
public function none(string ...$resourceTypes): self
{
foreach ($resourceTypes as $resourceType) {
$this->allow($resourceType, []);
}
return $this;
}
|
Allow no fields for the specified resource type.
@param string ...$resourceTypes
@return $this
|
none
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/AllowedFieldSets.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/AllowedFieldSets.php
|
Apache-2.0
|
protected function allowed(string $resourceType, string $fields): bool
{
return $this->notAllowed($resourceType, $fields)->isEmpty();
}
|
Are the fields allowed for the specified resource type?
@param string $resourceType
@param string $fields
@return bool
|
allowed
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/AllowedFieldSets.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/AllowedFieldSets.php
|
Apache-2.0
|
protected function notAllowed(string $resourceType, string $fields): Collection
{
$fields = collect(explode(',', $fields));
if (!$this->allowed->has($resourceType)) {
return $fields;
}
$allowed = $this->allowed->get($resourceType);
if (is_null($allowed)) {
return collect();
}
$allowed = collect((array) $allowed);
return $fields->reject(function ($value) use ($allowed) {
return $allowed->contains($value);
});
}
|
Get the invalid fields for the resource type.
@param string $resourceType
@param string $fields
@return Collection
|
notAllowed
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/AllowedFieldSets.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/AllowedFieldSets.php
|
Apache-2.0
|
protected function invalid(): Collection
{
if (!is_array($this->value)) {
return collect();
}
return collect($this->value)->map(function ($value, $key) {
return $this->notAllowed($key, $value);
})->flatMap(function (Collection $fields, $type) {
return $fields->map(function ($field) use ($type) {
return "{$type}.{$field}";
});
});
}
|
Get the fields that are invalid.
@return Collection
|
invalid
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/AllowedFieldSets.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/AllowedFieldSets.php
|
Apache-2.0
|
private function accept(string $value, string $format): bool
{
$date = DateTime::createFromFormat($format, $value);
return $date instanceof DateTime;
}
|
@param string $value
@param string $format
@return bool
|
accept
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/DateTimeIso8601.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/DateTimeIso8601.php
|
Apache-2.0
|
public function __construct(string ...$types)
{
$this->types = $types;
}
|
HasOne constructor.
@param string ...$types
the expected resource types.
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/HasOne.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/HasOne.php
|
Apache-2.0
|
protected function accept(?array $data): bool
{
if (is_null($data)) {
return true;
}
return $this->acceptType($data);
}
|
Accept the data value.
@param array|null $data
@return bool
|
accept
|
php
|
cloudcreativity/laravel-json-api
|
src/Rules/HasOne.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Rules/HasOne.php
|
Apache-2.0
|
protected function getRelationshipSelfUrl(object $resource, string $field): string
{
return sprintf(
'%s/%s/%s',
$this->getSelfSubUrl($resource),
DocumentInterface::KEYWORD_RELATIONSHIPS,
Str::dasherize($field)
);
}
|
@param object $resource
@param string $field
@return string
|
getRelationshipSelfUrl
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/DashCaseRelationUrls.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/DashCaseRelationUrls.php
|
Apache-2.0
|
protected function getRelationshipRelatedUrl(object $resource, string $name): string
{
return $this->getSelfSubUrl($resource) . '/' . Str::dasherize($name);
}
|
@param object $resource
@param string $name
@return string
|
getRelationshipRelatedUrl
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/DashCaseRelationUrls.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/DashCaseRelationUrls.php
|
Apache-2.0
|
public static function cast($value): self
{
if ($value instanceof self) {
return $value;
}
if (is_string($value)) {
return self::fromString($value);
}
throw new UnexpectedValueException('Unexpected relationship path value.');
}
|
@param RelationshipPath|string $value
@return RelationshipPath
|
cast
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/RelationshipPath.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/RelationshipPath.php
|
Apache-2.0
|
public function toString(): string
{
return implode('.', $this->names);
}
|
Fluent to string method.
@return string
|
toString
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/RelationshipPath.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/RelationshipPath.php
|
Apache-2.0
|
public function first(): string
{
return $this->names[0];
}
|
Get the first name.
@return string
|
first
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/RelationshipPath.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/RelationshipPath.php
|
Apache-2.0
|
public function skip(int $num): ?self
{
$names = Collection::make($this->names)->skip($num);
if ($names->isNotEmpty()) {
return new self(...$names);
}
return null;
}
|
@param int $num
@return $this|null
|
skip
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/RelationshipPath.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/RelationshipPath.php
|
Apache-2.0
|
public function __construct(
FactoryInterface $factory,
SchemaProviderInterface $provider,
?SchemaFields $fields = null,
) {
parent::__construct($factory);
$this->provider = $provider;
$this->fields = $fields ?? new SchemaFields();
}
|
Schema constructor.
@param FactoryInterface $factory
@param SchemaProviderInterface $provider
@param SchemaFields|null $fields
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/Schema.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/Schema.php
|
Apache-2.0
|
public function __construct(ContainerInterface $container, FactoryInterface $factory, ?SchemaFields $fields = null)
{
$this->container = $container;
$this->factory = $factory;
$this->fields = $fields ?? new SchemaFields();
}
|
SchemaContainer constructor.
@param ContainerInterface $container
@param FactoryInterface $factory
@param SchemaFields|null $fields
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaContainer.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaContainer.php
|
Apache-2.0
|
public static function make(?QueryParametersInterface $parameters): self
{
if ($parameters) {
return new self(
$parameters->getIncludePaths(),
$parameters->getFieldSets(),
);
}
return new self();
}
|
Make a new schema fields from encoding parameters.
@param QueryParametersInterface|null $parameters
@return static
|
make
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaFields.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaFields.php
|
Apache-2.0
|
public function __construct(?iterable $paths = null, ?iterable $fieldSets = null)
{
if (null !== $paths) {
foreach ($paths as $path) {
$path = RelationshipPath::cast($path);
foreach ($path as $key => $relationship) {
$curPath = (0 === $key) ? '' : $path->take($key)->toString();
$this->fastRelationships[$curPath][$relationship] = true;
$this->fastRelationshipLists[$curPath][$relationship] = $relationship;
}
}
}
if (null !== $fieldSets) {
foreach ($fieldSets as $type => $fieldList) {
$fieldList = \is_string($fieldList) ? \explode(static::FIELD_SEPARATOR, $fieldList) : $fieldList;
foreach ($fieldList as $field) {
$this->fastFields[$type][$field] = true;
$this->fastFieldLists[$type][$field] = $field;
}
}
}
}
|
SchemaFields constructor.
@param iterable|null $paths
@param iterable|null $fieldSets
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaFields.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaFields.php
|
Apache-2.0
|
public function isRelationshipRequested(string $currentPath, string $relationship): bool
{
return isset($this->fastRelationships[$currentPath][$relationship]);
}
|
@param string $currentPath
@param string $relationship
@return bool
|
isRelationshipRequested
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaFields.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaFields.php
|
Apache-2.0
|
public function isFieldRequested(string $type, string $field): bool
{
return \array_key_exists($type, $this->fastFields) === false ? true : isset($this->fastFields[$type][$field]);
}
|
@param string $type
@param string $field
@return bool
|
isFieldRequested
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaFields.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaFields.php
|
Apache-2.0
|
public function getRequestedFields(string $type): ?array
{
return $this->fastFieldLists[$type] ?? null;
}
|
@param string $type
@return array|null
|
getRequestedFields
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaFields.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaFields.php
|
Apache-2.0
|
protected function getRelationshipSelfUrl(object $resource, string $field): string
{
return $this->getSelfSubUrl($resource) . '/' . DocumentInterface::KEYWORD_RELATIONSHIPS . '/' . $field;
}
|
Get the relationship self url.
@param object $resource
@param string $field
@return string
|
getRelationshipSelfUrl
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaProvider.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaProvider.php
|
Apache-2.0
|
protected function getRelationshipRelatedUrl(object $resource, string $field): string
{
return $this->getSelfSubUrl($resource) . '/' . $field;
}
|
Get the relationship related url.
@param object $resource
@param string $field
@return string
|
getRelationshipRelatedUrl
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaProvider.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaProvider.php
|
Apache-2.0
|
protected function createLink(string $subHref, ?array $meta = null, bool $treatAsHref = false): LinkInterface
{
return $this->factory->createLink(!$treatAsHref, $subHref, !empty($meta), $meta);
}
|
Create a link.
This method was on the v1 schema provider, so is provided here for backwards compatibility.
@param string $subHref
@param null|mixed $meta
@param bool $treatAsHref
@return LinkInterface
|
createLink
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaProvider.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaProvider.php
|
Apache-2.0
|
public static function make(string $resourceType, string $field, array $relation): self
{
return new self($resourceType, $field, $relation);
}
|
Fluent constructor.
@param string $resourceType
@param string $field
@param array $relation
@return static
|
make
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaProviderRelation.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaProviderRelation.php
|
Apache-2.0
|
public function __construct(string $resourceType, string $field, array $relation)
{
$this->resourceType = $resourceType;
$this->field = $field;
$this->relation = $relation;
}
|
SchemaProviderRelation constructor.
@param string $resourceType
@param string $field
@param array $relation
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaProviderRelation.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaProviderRelation.php
|
Apache-2.0
|
public function showData(): bool
{
if (!isset($this->relation[SchemaProviderInterface::SHOW_DATA])) {
return array_key_exists(SchemaProviderInterface::DATA, $this->relation);
}
$value = $this->relation[SchemaProviderInterface::SHOW_DATA];
if (is_bool($value)) {
return $value;
}
throw new RuntimeException(sprintf(
'Show data on resource "%s" relation "%s" must be a boolean.',
$this->resourceType,
$this->field,
));
}
|
Should the data member be shown?
@return bool
|
showData
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaProviderRelation.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaProviderRelation.php
|
Apache-2.0
|
public function data()
{
return $this->relation[SchemaProviderInterface::DATA] ?? null;
}
|
Get the data member.
@return mixed
|
data
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaProviderRelation.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaProviderRelation.php
|
Apache-2.0
|
public function showSelfLink(): ?bool
{
$value = $this->relation[SchemaProviderInterface::SHOW_SELF] ?? null;
if (null === $value || is_bool($value)) {
return $value;
}
throw new RuntimeException(sprintf(
'Show self link on resource "%s" relation "%s" must be a boolean.',
$this->resourceType,
$this->field,
));
}
|
Should the self link be shown?
@return bool|null
|
showSelfLink
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaProviderRelation.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaProviderRelation.php
|
Apache-2.0
|
public function showRelatedLink(): ?bool
{
$value = $this->relation[SchemaProviderInterface::SHOW_RELATED] ?? null;
if (null === $value || is_bool($value)) {
return $value;
}
throw new RuntimeException(sprintf(
'Show related link on resource "%s" relation "%s" must be a boolean.',
$this->resourceType,
$this->field,
));
}
|
Should the related link be shown?
@return bool|null
|
showRelatedLink
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaProviderRelation.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaProviderRelation.php
|
Apache-2.0
|
public function hasMeta(): bool
{
$value = $this->meta();
return !empty($value);
}
|
Does the relationship have meta?
@return bool
|
hasMeta
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaProviderRelation.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaProviderRelation.php
|
Apache-2.0
|
public function meta()
{
return $this->relation[SchemaProviderInterface::META] ?? null;
}
|
Get the relationship meta.
@return mixed
|
meta
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaProviderRelation.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaProviderRelation.php
|
Apache-2.0
|
public function parse(): array
{
$values = [];
$showSelfLink = $this->showSelfLink();
$showRelatedLink = $this->showRelatedLink();
if ($this->showData()) {
$values[SchemaInterface::RELATIONSHIP_DATA] = $this->data();
}
if (is_bool($showSelfLink)) {
$values[SchemaInterface::RELATIONSHIP_LINKS_SELF] = $showSelfLink;
}
if (is_bool($showRelatedLink)) {
$values[SchemaInterface::RELATIONSHIP_LINKS_RELATED] = $showRelatedLink;
}
if ($this->hasMeta()) {
$values[SchemaInterface::RELATIONSHIP_META] = $this->meta();
}
return $values;
}
|
Parse the legacy neomerx relation to a new one.
@return array
|
parse
|
php
|
cloudcreativity/laravel-json-api
|
src/Schema/SchemaProviderRelation.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Schema/SchemaProviderRelation.php
|
Apache-2.0
|
public function api($apiName = null, $host = null, array $parameters = [])
{
/** @var Repository $repo */
$repo = app(Repository::class);
return $repo->createApi(
$apiName ?: LaravelJsonApi::$defaultApi,
$host,
$parameters
);
}
|
Get an API by name.
@param string|null $apiName
@param string|null $host
@param array $parameters
@return Api
@throws RuntimeException
if the API name is invalid.
|
api
|
php
|
cloudcreativity/laravel-json-api
|
src/Services/JsonApiService.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Services/JsonApiService.php
|
Apache-2.0
|
public function currentRoute(): Route
{
return app(Route::class);
}
|
Get the current JSON API route.
@return Route
|
currentRoute
|
php
|
cloudcreativity/laravel-json-api
|
src/Services/JsonApiService.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Services/JsonApiService.php
|
Apache-2.0
|
public function requestApi()
{
if (!app()->bound('json-api.inbound')) {
return null;
}
return app('json-api.inbound');
}
|
Get the API that is handling the inbound HTTP request.
@return Api|null
the API, or null if the there is no inbound JSON API HTTP request.
|
requestApi
|
php
|
cloudcreativity/laravel-json-api
|
src/Services/JsonApiService.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Services/JsonApiService.php
|
Apache-2.0
|
public function requestApiOrDefault($host = null, array $parameters = [])
{
return $this->requestApi() ?: $this->api(null, $host, $parameters);
}
|
Get either the request API or the default API.
@param string|null $host
@param array $parameters
@return Api
|
requestApiOrDefault
|
php
|
cloudcreativity/laravel-json-api
|
src/Services/JsonApiService.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Services/JsonApiService.php
|
Apache-2.0
|
public function requestApiOrFail()
{
if (!$api = $this->requestApi()) {
throw new RuntimeException('No JSON API handling the inbound request.');
}
return $api;
}
|
@return Api
@throws RuntimeException
if there is no JSON API handling the inbound request.
|
requestApiOrFail
|
php
|
cloudcreativity/laravel-json-api
|
src/Services/JsonApiService.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Services/JsonApiService.php
|
Apache-2.0
|
public function register($apiName, $options = [], ?Closure $routes = null): ApiRegistration
{
/** @var JsonApiRegistrar $registrar */
$registrar = app('json-api.registrar');
return $registrar->api($apiName, $options, $routes);
}
|
Register the routes for an API.
@param $apiName
@param array|Closure $options
@param Closure|null $routes
@return ApiRegistration
|
register
|
php
|
cloudcreativity/laravel-json-api
|
src/Services/JsonApiService.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Services/JsonApiService.php
|
Apache-2.0
|
public function add(string $type, string $id, $record): void
{
if (!is_object($record) && !is_bool($record)) {
throw new InvalidArgumentException('Expecting an object or a boolean to add to the identity map.');
}
$existing = $this->lookup($type, $id);
if (is_object($existing) && is_bool($record)) {
throw new InvalidArgumentException('Attempting to push a boolean into the map in place of an object.');
}
$this->map[$this->key($type, $id)] = $record;
}
|
Add a record to the identity map for a resource identifier.
The record can either be a boolean (the result of a store's `exists()` check), or the actual
record itself. However, a boolean cannot be inserted into the map if the map already holds the
record itself.
@param string $type
@param string $id
@param mixed|bool $record
@return void
|
add
|
php
|
cloudcreativity/laravel-json-api
|
src/Store/IdentityMap.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Store/IdentityMap.php
|
Apache-2.0
|
public function exists(string $type, string $id): ?bool
{
$record = $this->lookup($type, $id);
return is_object($record) ? true : $record;
}
|
Does the identity map know that ths supplied identifier exists?
@param string $type
@param string $id
@return bool|null
the answer, or null if the identity map does not know
|
exists
|
php
|
cloudcreativity/laravel-json-api
|
src/Store/IdentityMap.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Store/IdentityMap.php
|
Apache-2.0
|
public function find(string $type, string $id)
{
$record = $this->lookup($type, $id);
if (false === $record) {
return false;
}
return is_object($record) ? $record : null;
}
|
Get the record from the identity map.
@param string $type
@param string $id
@return object|bool|null
the record, false if it is known not to exist, or null if the identity map does not have the object.
|
find
|
php
|
cloudcreativity/laravel-json-api
|
src/Store/IdentityMap.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Store/IdentityMap.php
|
Apache-2.0
|
private function lookup(string $type, string $id)
{
$key = $this->key($type, $id);
return $this->map[$key] ?? null;
}
|
@param string $type
@param string $id
@return mixed|bool|null
|
lookup
|
php
|
cloudcreativity/laravel-json-api
|
src/Store/IdentityMap.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Store/IdentityMap.php
|
Apache-2.0
|
private function key(string $type, string $id): string
{
return "{$type}:{$id}";
}
|
@param string $type
@param string $id
@return string
|
key
|
php
|
cloudcreativity/laravel-json-api
|
src/Store/IdentityMap.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Store/IdentityMap.php
|
Apache-2.0
|
private function adapterForHasMany($resourceType, $relationshipName): HasManyAdapterInterface
{
$adapter = $this->adapterFor($resourceType)->getRelated($relationshipName);
if (!$adapter instanceof HasManyAdapterInterface) {
throw new RuntimeException("Expecting a has-many relationship adapter.");
}
return $adapter;
}
|
@param $resourceType
@param $relationshipName
@return HasManyAdapterInterface
|
adapterForHasMany
|
php
|
cloudcreativity/laravel-json-api
|
src/Store/Store.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Store/Store.php
|
Apache-2.0
|
public function render($request, Throwable $e)
{
if ($this->isJsonApi($request, $e)) {
return $this->renderJsonApi($request, $e);
}
return parent::render($request, $e);
}
|
@param \Illuminate\Http\Request $request
@param Throwable $e
@return \Symfony\Component\HttpFoundation\Response
|
render
|
php
|
cloudcreativity/laravel-json-api
|
src/Testing/TestExceptionHandler.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Testing/TestExceptionHandler.php
|
Apache-2.0
|
public static function camelize($data)
{
return collect($data)->mapWithKeys(function ($value, $key) {
$key = Str::camelize($key);
if (is_array($value)) {
return [$key => static::camelize($value)];
}
return [$key => $value];
})->all();
}
|
Recursively camelize all keys in the provided array.
@param array|null $data
@return array
|
camelize
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Arr.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Arr.php
|
Apache-2.0
|
public static function dasherize($data)
{
return collect($data)->mapWithKeys(function ($value, $key) {
$key = Str::dasherize($key);
if (is_array($value)) {
return [$key => static::dasherize($value)];
}
return [$key => $value];
})->all();
}
|
Recursively dasherize all keys in the provided array.
@param array|null $data
@return array
|
dasherize
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Arr.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Arr.php
|
Apache-2.0
|
public static function decamelize($data)
{
return collect($data)->mapWithKeys(function ($value, $key) {
$key = Str::decamelize($key);
if (is_array($value)) {
return [$key => static::decamelize($value)];
}
return [$key => $value];
})->all();
}
|
Recursively decamelize all keys in the provided array.
@param array|null $data
@return array
|
decamelize
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Arr.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Arr.php
|
Apache-2.0
|
public static function underscore($data)
{
return collect($data)->mapWithKeys(function ($value, $key) {
$key = Str::underscore($key);
if (is_array($value)) {
return [$key => static::underscore($value)];
}
return [$key => $value];
})->all();
}
|
Recursively underscore all keys in the provided array.
@param array|null $data
@return array
|
underscore
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Arr.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Arr.php
|
Apache-2.0
|
public static function decode($content, $assoc = false, $depth = 512, $options = 0)
{
$decoded = \json_decode($content, $assoc, $depth, $options);
if (JSON_ERROR_NONE !== json_last_error()) {
throw InvalidJsonException::create();
}
if (!$assoc && !is_object($decoded)) {
throw new DocumentRequiredException();
}
if ($assoc && !is_array($decoded)) {
throw new InvalidJsonException(null, 'JSON is not an array.');
}
return $decoded;
}
|
Decode a JSON string.
@param string $content
@param bool $assoc
@param int $depth
@param int $options
@return object|array
@throws InvalidJsonException
|
decode
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Helpers.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Helpers.php
|
Apache-2.0
|
public static function doesRequestHaveBody($request)
{
if (self::hasHeader($request, 'Transfer-Encoding')) {
return true;
};
if (1 > self::getHeader($request, 'Content-Length')) {
return false;
}
return true;
}
|
Does the HTTP request contain body content?
"The presence of a message-body in a request is signaled by the inclusion of a Content-Length or
Transfer-Encoding header field in the request's message-headers."
https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3
However, some browsers send a Content-Length header with an empty string for e.g. GET requests
without any message-body. Therefore rather than checking for the existence of a Content-Length
header, we will allow an empty value to indicate that the request does not contain body.
@param RequestInterface|SymfonyRequest $request
@return bool
|
doesRequestHaveBody
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Helpers.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Helpers.php
|
Apache-2.0
|
public static function doesResponseHaveBody($request, $response)
{
if ('HEAD' === strtoupper($request->getMethod())) {
return false;
}
$status = $response->getStatusCode();
if ((100 <= $status && 200 > $status) || 204 === $status || 304 === $status) {
return false;
}
if (self::hasHeader($response, 'Transfer-Encoding')) {
return true;
};
if (!$contentLength = self::getHeader($response, 'Content-Length')) {
return false;
}
return 0 < $contentLength[0];
}
|
Does the HTTP response contain body content?
"For response messages, whether or not a message-body is included with a message is dependent
on both the request method and the response status code (section 6.1.1). All responses to the
HEAD request method MUST NOT include a message-body, even though the presence of entity-header
fields might lead one to believe they do. All 1xx (informational), 204 (no content), and 304
(not modified) responses MUST NOT include a message-body. All other responses do include a
message-body, although it MAY be of zero length."
https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3
@param RequestInterface|SymfonyRequest $request
@param ResponseInterface|SymfonyResponse $response
@return bool
|
doesResponseHaveBody
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Helpers.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Helpers.php
|
Apache-2.0
|
public static function wantsJsonApi($request)
{
$acceptable = $request->getAcceptableContentTypes();
return isset($acceptable[0]) && IlluminateStr::contains($acceptable[0], MediaType::JSON_API_SUB_TYPE);
}
|
Does the request want JSON API content?
@param SymfonyRequest $request
@return bool
|
wantsJsonApi
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Helpers.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Helpers.php
|
Apache-2.0
|
public static function isJsonApi($request)
{
return IlluminateStr::contains($request->headers->get('Content-Type'), MediaType::JSON_API_SUB_TYPE);
}
|
Has the request sent JSON API content?
@param SymfonyRequest $request
@return bool
|
isJsonApi
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Helpers.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Helpers.php
|
Apache-2.0
|
public static function httpErrorStatus($errors, ?int $default = null): int
{
if (\is_null($default)) {
$default = SymfonyResponse::HTTP_BAD_REQUEST;
}
if ($errors instanceof ErrorInterface) {
$errors = [$errors];
}
$statuses = collect($errors)->reject(function (ErrorInterface $error) {
return is_null($error->getStatus());
})->map(function (ErrorInterface $error) {
return (int) $error->getStatus();
})->unique();
if (2 > count($statuses)) {
return $statuses->first() ?: $default;
}
$only4xx = $statuses->every(function (int $status) {
return 400 <= $status && 499 >= $status;
});
return $only4xx ? SymfonyResponse::HTTP_BAD_REQUEST : SymfonyResponse::HTTP_INTERNAL_SERVER_ERROR;
}
|
Get the most applicable HTTP status code.
When a server encounters multiple problems for a single request, the most generally applicable HTTP error
code SHOULD be used in the response. For instance, 400 Bad Request might be appropriate for multiple
4xx errors or 500 Internal Server Error might be appropriate for multiple 5xx errors.
@param iterable|ErrorInterface $errors
@param int|null $default
@return int
@see https://jsonapi.org/format/#errors
@deprecated 3.0.0 use `Document\Error\Errors::getStatus()`
|
httpErrorStatus
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Helpers.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Helpers.php
|
Apache-2.0
|
private static function getHeader($message, $key)
{
if ($message instanceof MessageInterface) {
return $message->getHeader($key)[0] ?? null;
}
return $message->headers->get($key);
}
|
@param MessageInterface|SymfonyRequest|SymfonyResponse $message
@param $key
@return mixed
|
getHeader
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Helpers.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Helpers.php
|
Apache-2.0
|
private static function hasHeader($message, $key)
{
if ($message instanceof MessageInterface) {
return $message->hasHeader($key);
}
return $message->headers->has($key);
}
|
@param MessageInterface|SymfonyRequest|SymfonyResponse $message
@param $key
@return mixed
|
hasHeader
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Helpers.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Helpers.php
|
Apache-2.0
|
protected function invoke(string $hook, ...$arguments)
{
if (!method_exists($this, $hook)) {
return null;
}
$result = $this->{$hook}(...$arguments);
return $this->isInvokedResult($result) ? $result : null;
}
|
Invoke a hook.
@param string $hook
@param mixed ...$arguments
@return mixed|null
|
invoke
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/InvokesHooks.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/InvokesHooks.php
|
Apache-2.0
|
protected function invokeMany(iterable $hooks, ...$arguments)
{
foreach ($hooks as $hook) {
$result = $this->invoke($hook, ...$arguments);
if (!is_null($result)) {
return $result;
}
}
return null;
}
|
Invoke multiple hooks.
@param iterable $hooks
@param mixed ...$arguments
@return mixed|null
|
invokeMany
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/InvokesHooks.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/InvokesHooks.php
|
Apache-2.0
|
public static function dasherize($value)
{
if (isset(self::$dasherized[$value])) {
return self::$dasherized[$value];
}
return self::$dasherized[$value] = str_replace('_', '-', self::decamelize($value));
}
|
Replaces underscores or camel case with dashes.
@param string $value
@return string
|
dasherize
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Str.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Str.php
|
Apache-2.0
|
public static function decamelize($value)
{
if (isset(self::$decamelized[$value])) {
return self::$decamelized[$value];
}
return self::$decamelized[$value] = strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1_', $value));
}
|
Converts a camel case string into all lower case separated by underscores.
@param string $value
@return string
|
decamelize
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Str.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Str.php
|
Apache-2.0
|
public static function underscore($value)
{
if (isset(self::$underscored[$value])) {
return self::$underscored[$value];
}
return self::$underscored[$value] = str_replace('-', '_', self::decamelize($value));
}
|
Converts a camel case or dasherized string into a lower cased and underscored string.
@param $value
@return string
|
underscore
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Str.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Str.php
|
Apache-2.0
|
public static function camelize($value)
{
if (isset(self::$camelized[$value])) {
return self::$camelized[$value];
}
return self::$camelized[$value] = lcfirst(self::classify($value));
}
|
Gets the lower camel case form of a string.
@param string $value
@return string
|
camelize
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Str.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Str.php
|
Apache-2.0
|
public static function classify($value)
{
if (isset(self::$classified[$value])) {
return self::$classified[$value];
}
$converted = ucwords(str_replace(['-', '_'], ' ', $value));
return self::$classified[$value] = str_replace(' ', '', $converted);
}
|
Gets the upper camel case form of a string.
@param string $value
@return string
|
classify
|
php
|
cloudcreativity/laravel-json-api
|
src/Utils/Str.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Utils/Str.php
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.