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 create(StoreInterface $store, CreateResource $request)
{
$record = $this->transaction(function () use ($store, $request) {
return $this->doCreate($store, $request);
});
if ($this->isResponse($record)) {
return $record;
}
return $this->reply()->created($record);
}
|
Create resource action.
@param StoreInterface $store
@param CreateResource $request
@return Response
|
create
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
public function update(StoreInterface $store, UpdateResource $request)
{
$record = $this->transaction(function () use ($store, $request) {
return $this->doUpdate($store, $request);
});
if ($this->isResponse($record)) {
return $record;
}
return $this->reply()->updated($record);
}
|
Update resource action.
@param StoreInterface $store
@param UpdateResource $request
@return Response
|
update
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
public function delete(StoreInterface $store, DeleteResource $request)
{
$result = $this->transaction(function () use ($store, $request) {
return $this->doDelete($store, $request);
});
if ($this->isResponse($result)) {
return $result;
}
return $this->reply()->deleted($result);
}
|
Delete resource action.
@param StoreInterface $store
@param DeleteResource $request
@return Response
|
delete
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
public function readRelatedResource(StoreInterface $store, FetchRelated $request)
{
$record = $request->getRecord();
$result = $this->beforeReadingRelationship($record, $request);
if ($this->isResponse($result)) {
return $result;
}
$related = $store->queryRelated(
$record,
$request->getRelationshipName(),
$request->getEncodingParameters()
);
$records = ($related instanceof PageInterface) ? $related->getData() : $related;
$result = $this->afterReadingRelationship($record, $records, $request);
if ($this->isInvokedResult($result)) {
return $result;
}
return $this->reply()->content($related);
}
|
Read related resource action.
@param StoreInterface $store
@param FetchRelated $request
@return Response
|
readRelatedResource
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
public function readRelationship(StoreInterface $store, FetchRelationship $request)
{
$record = $request->getRecord();
$result = $this->beforeReadingRelationship($record, $request);
if ($this->isResponse($result)) {
return $result;
}
$related = $store->queryRelationship(
$record,
$request->getRelationshipName(),
$request->getEncodingParameters()
);
$records = ($related instanceof PageInterface) ? $related->getData() : $related;
$result = $this->afterReadingRelationship($record, $records, $request);
if ($this->isInvokedResult($result)) {
return $result;
}
return $this->reply()->relationship($related);
}
|
Read relationship data action.
@param StoreInterface $store
@param FetchRelationship $request
@return Response
|
readRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
public function replaceRelationship(StoreInterface $store, UpdateRelationship $request)
{
$result = $this->transaction(function () use ($store, $request) {
return $this->doReplaceRelationship($store, $request);
});
if ($this->isResponse($result)) {
return $result;
}
return $this->reply()->noContent();
}
|
Replace relationship data action.
@param StoreInterface $store
@param UpdateRelationship $request
@return Response
|
replaceRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
public function addToRelationship(StoreInterface $store, UpdateRelationship $request)
{
$result = $this->transaction(function () use ($store, $request) {
return $this->doAddToRelationship($store, $request);
});
if ($this->isResponse($result)) {
return $result;
}
return $this->reply()->noContent();
}
|
Add to relationship data action.
@param StoreInterface $store
@param UpdateRelationship $request
@return Response
|
addToRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
public function removeFromRelationship(StoreInterface $store, UpdateRelationship $request)
{
$result = $this->transaction(function () use ($store, $request) {
return $this->doRemoveFromRelationship($store, $request);
});
if ($this->isResponse($result)) {
return $result;
}
return $this->reply()->noContent();
}
|
Remove from relationship data action.
@param StoreInterface $store
@param UpdateRelationship $request
@return Response
|
removeFromRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
public function processes(StoreInterface $store, FetchProcesses $request)
{
$result = $store->queryRecords(
$request->getProcessType(),
$request->getEncodingParameters()
);
return $this->reply()->content($result);
}
|
Read processes action.
@param StoreInterface $store
@param FetchProcesses $request
@return Response
|
processes
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
public function process(StoreInterface $store, FetchProcess $request)
{
$record = $store->readRecord(
$request->getProcess(),
$request->getEncodingParameters()
);
return $this->reply()->process($record);
}
|
Read a process action.
@param StoreInterface $store
@param FetchProcess $request
@return Response
|
process
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
public function withConnection(?string $connection): self
{
$this->connection = $connection;
return $this;
}
|
@param string|null $connection
@return $this
@deprecated 2.0.0 will be moved to middleware
|
withConnection
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
public function withTransactions(): self
{
$this->useTransactions = true;
return $this;
}
|
@return $this
@deprecated 2.0.0 will be moved to middleware
|
withTransactions
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
public function withoutTransactions(): self
{
$this->useTransactions = false;
return $this;
}
|
@return $this
@deprecated 2.0.0 will be moved to middleware
|
withoutTransactions
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
protected function doSearch(StoreInterface $store, FetchResources $request)
{
if ($result = $this->invoke('searching', $request)) {
return $result;
}
$found = $store->queryRecords($request->getResourceType(), $request->getEncodingParameters());
$records = ($found instanceof PageInterface) ? $found->getData() : $found;
if ($result = $this->invoke('searched', $records, $request)) {
return $result;
}
return $found;
}
|
Search resources.
@param StoreInterface $store
@param FetchResources $request
@return mixed
|
doSearch
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
protected function doRead(StoreInterface $store, FetchResource $request)
{
$record = $request->getRecord();
if ($result = $this->invoke('reading', $record, $request)) {
return $result;
}
/** We pass to the store for filtering, eager loading etc. */
$record = $store->readRecord($record, $request->getEncodingParameters());
if ($result = $this->invoke('didRead', $record, $request)) {
return $result;
}
return $record;
}
|
Read a resource.
@param StoreInterface $store
@param FetchResource $request
@return mixed
|
doRead
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
protected function doCreate(StoreInterface $store, CreateResource $request)
{
if ($response = $this->beforeCommit($request)) {
return $response;
}
$record = $store->createRecord(
$request->getResourceType(),
$request->all(),
$request->getEncodingParameters()
);
return $this->afterCommit($request, $record, false) ?: $record;
}
|
Create a resource.
@param StoreInterface $store
@param CreateResource $request
@return mixed
the created record, an asynchronous process, or a HTTP response.
|
doCreate
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
protected function doUpdate(StoreInterface $store, UpdateResource $request)
{
if ($response = $this->beforeCommit($request)) {
return $response;
}
$record = $store->updateRecord(
$request->getRecord(),
$request->all(),
$request->getEncodingParameters()
);
return $this->afterCommit($request, $record, true) ?: $record;
}
|
Update a resource.
@param StoreInterface $store
@param UpdateResource $request
@return mixed
the updated record, an asynchronous process, or a HTTP response.
|
doUpdate
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
protected function doDelete(StoreInterface $store, DeleteResource $request)
{
$record = $request->getRecord();
if ($response = $this->invoke('deleting', $record, $request)) {
return $response;
}
$result = $store->deleteRecord($record, $request->getEncodingParameters());
return $this->invoke('deleted', $record, $request) ?: $result;
}
|
Delete a resource.
@param StoreInterface $store
@param DeleteResource $request
@return mixed|null
an HTTP response, an asynchronous process, content to return, or null.
|
doDelete
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
protected function doReplaceRelationship(StoreInterface $store, UpdateRelationship $request)
{
$record = $request->getRecord();
$name = Str::classify($field = $request->getRelationshipName());
if ($result = $this->invokeMany(['replacing', "replacing{$name}"], $record, $request)) {
return $result;
}
$record = $store->replaceRelationship(
$record,
$field,
$request->all(),
$request->getEncodingParameters()
);
return $this->invokeMany(["replaced{$name}", "replaced"], $record, $request) ?: $record;
}
|
Replace a relationship.
@param StoreInterface $store
@param UpdateRelationship $request
@return mixed
|
doReplaceRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
protected function doAddToRelationship(StoreInterface $store, UpdateRelationship $request)
{
$record = $request->getRecord();
$name = Str::classify($field = $request->getRelationshipName());
if ($result = $this->invokeMany(['adding', "adding{$name}"], $record, $request)) {
return $result;
}
$record = $store->addToRelationship(
$record,
$field,
$request->all(),
$request->getEncodingParameters()
);
return $this->invokeMany(["added{$name}", "added"], $record, $request) ?: $record;
}
|
Add to a relationship.
@param StoreInterface $store
@param UpdateRelationship $request
@return mixed
|
doAddToRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
protected function doRemoveFromRelationship(StoreInterface $store, UpdateRelationship $request)
{
$record = $request->getRecord();
$name = Str::classify($field = $request->getRelationshipName());
if ($result = $this->invokeMany(['removing', "removing{$name}"], $record, $request)) {
return $result;
}
$record = $store->removeFromRelationship(
$record,
$field,
$request->all(),
$request->getEncodingParameters()
);
return $this->invokeMany(["removed{$name}", "removed"], $record, $request) ?: $record;
}
|
Remove from a relationship.
@param StoreInterface $store
@param UpdateRelationship $request
@return mixed
|
doRemoveFromRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
protected function transaction(Closure $closure)
{
if (!$this->useTransactions()) {
return $closure();
}
return app('db')->connection($this->connection())->transaction($closure);
}
|
Execute the closure within an optional transaction.
@param Closure $closure
@return mixed
@deprecated 2.0.0 will be moved to middleware
|
transaction
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
protected function isResponse($value)
{
return $value instanceof Response || $value instanceof Responsable;
}
|
Can the controller return the provided value?
@param $value
@return bool
|
isResponse
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
private function connection(): ?string
{
if ($this->connection) {
return $this->connection;
}
return json_api()->getConnection();
}
|
@return string|null
@deprecated 2.0.0 will be moved to middleware
|
connection
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
private function useTransactions(): bool
{
if (is_bool($this->useTransactions)) {
return $this->useTransactions;
}
return json_api()->hasTransactions();
}
|
@return bool
@deprecated 2.0.0 transactions will be moved to middleware
|
useTransactions
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
private function beforeCommit($request)
{
$record = ($request instanceof UpdateResource) ? $request->getRecord() : null;
if ($result = $this->invoke('saving', $record, $request)) {
return $result;
}
return is_null($record) ?
$this->invoke('creating', $request) :
$this->invoke('updating', $record, $request);
}
|
@param CreateResource|UpdateResource $request
@return mixed|null
|
beforeCommit
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
private function afterCommit($request, $record, $updating)
{
$method = !$updating ? 'created' : 'updated';
if ($result = $this->invoke($method, $record, $request)) {
return $result;
}
return $this->invoke('saved', $record, $request);
}
|
@param CreateResource|UpdateResource $request
@param $record
@param $updating
@return mixed|null
|
afterCommit
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
private function beforeReadingRelationship($record, $request)
{
$field = Str::classify($request->getRelationshipName());
$hooks = ['readingRelationship', "reading{$field}"];
return $this->invokeMany($hooks, $record, $request);
}
|
@param $record
@param FetchRelated|FetchRelationship $request
@return mixed|null
|
beforeReadingRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
private function afterReadingRelationship($record, $related, $request)
{
$field = Str::classify($request->getRelationshipName());
$hooks = ["didRead{$field}", 'didReadRelationship'];
return $this->invokeMany($hooks, $record, $related, $request);
}
|
@param $record
@param $related
the related resources that will be in the response.
@param FetchRelated|FetchRelationship $request
@return mixed|null
|
afterReadingRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Controllers/JsonApiController.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/JsonApiController.php
|
Apache-2.0
|
public function __construct(string $name, array $mediaTypes)
{
foreach ($mediaTypes as $mediaType) {
if (!$mediaType instanceof MediaTypeInterface) {
throw new InvalidArgumentException('Expecting only media type objects.');
}
}
$this->name = $name;
$this->mediaTypes = $mediaTypes;
}
|
Header constructor.
@param string $name
@param MediaTypeInterface[] $mediaTypes
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Headers/Header.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Headers/Header.php
|
Apache-2.0
|
public function __construct(AcceptHeaderInterface $accept, ?HeaderInterface $contentType = null)
{
$this->accept = $accept;
$this->contentType = $contentType;
}
|
HeaderParameters constructor.
@param AcceptHeaderInterface $accept
@param HeaderInterface|null $contentType
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Headers/HeaderParameters.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Headers/HeaderParameters.php
|
Apache-2.0
|
private function getHeader(ServerRequestInterface $request, string $name): string
{
$value = $request->getHeader($name);
if (empty($value) === false) {
$value = $value[0];
if (empty($value) === false) {
return $value;
}
}
return MediaTypeInterface::JSON_API_MEDIA_TYPE;
}
|
@param ServerRequestInterface $request
@param string $name
@return string
|
getHeader
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Headers/HeaderParametersParser.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Headers/HeaderParametersParser.php
|
Apache-2.0
|
public function parse(string $mediaType): MediaTypeInterface
{
return $this->parser->parseContentTypeHeader($mediaType);
}
|
Parse a string media type to a media type object.
@param string $mediaType
@return MediaTypeInterface
|
parse
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Headers/MediaTypeParser.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Headers/MediaTypeParser.php
|
Apache-2.0
|
public function __construct(ContainerInterface $container, Route $route)
{
$this->container = $container;
$this->route = $route;
}
|
Authorize constructor.
@param ContainerInterface $container
@param Route $route
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/Authorize.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/Authorize.php
|
Apache-2.0
|
public function handle($request, Closure $next, $authorizer)
{
$authorizer = $this->container->getAuthorizerByName($authorizer);
$record = $this->route->getResource();
if ($field = $this->route->getRelationshipName()) {
$this->authorizeRelationship(
$authorizer,
$request,
$record,
$field
);
} else if ($record) {
$this->authorizeResource($authorizer, $request, $record);
} else {
$this->authorize($authorizer, $request, $this->route->getType());
}
return $next($request);
}
|
Handle the request.
@param Request $request
@param Closure $next
@param string $authorizer
@return mixed
@throws AuthorizationException
@throws AuthenticationException
|
handle
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/Authorize.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/Authorize.php
|
Apache-2.0
|
protected function authorize(AuthorizerInterface $authorizer, $request, string $type): void
{
if ($request->isMethod('POST')) {
$authorizer->create($type, $request);
return;
}
$authorizer->index($type, $request);
}
|
@param AuthorizerInterface $authorizer
@param Request $request
@param string $type
@throws AuthenticationException
@throws AuthorizationException
|
authorize
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/Authorize.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/Authorize.php
|
Apache-2.0
|
protected function authorizeResource(AuthorizerInterface $authorizer, $request, $record): void
{
if ($request->isMethod('PATCH')) {
$authorizer->update($record, $request);
return;
}
if ($request->isMethod('DELETE')) {
$authorizer->delete($record, $request);
return;
}
$authorizer->read($record, $request);
}
|
@param AuthorizerInterface $authorizer
@param Request $request
@param $record
@throws AuthenticationException
@throws AuthorizationException
|
authorizeResource
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/Authorize.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/Authorize.php
|
Apache-2.0
|
protected function authorizeRelationship(AuthorizerInterface $authorizer, $request, $record, string $field): void
{
if ($this->isModifyRelationship($request)) {
$authorizer->modifyRelationship($record, $field, $request);
return;
}
$authorizer->readRelationship($record, $field, $request);
}
|
Authorize a relationship request.
@param AuthorizerInterface $authorizer
@param $request
@param $record
@param string $field
@throws AuthenticationException
@throws AuthorizationException
|
authorizeRelationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/Authorize.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/Authorize.php
|
Apache-2.0
|
public function handle($request, Closure $next, string $namespace)
{
/** Build and register the API. */
$api = $this->bindApi(
$namespace,
$request->getSchemeAndHttpHost() . $request->getBaseUrl(),
$request->route()->parameters
);
/** Substitute route bindings. */
$this->substituteBindings($api);
/** Set up the Laravel paginator to read from JSON API request instead */
$this->bindPageResolver();
return $next($request);
}
|
Start JSON API support.
This middleware:
- Loads the configuration for the named API that this request is being routed to.
- Registers the API in the service container.
- Substitutes bindings on the route.
- Overrides the Laravel current page resolver so that it uses the JSON API page parameter.
@param Request $request
@param Closure $next
@param string $namespace
the API namespace, as per your JSON API configuration.
@return mixed
|
handle
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/BootJsonApi.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/BootJsonApi.php
|
Apache-2.0
|
protected function bindApi(string $namespace, string $host, array $parameters = []): Api
{
/** @var Repository $repository */
$repository = $this->container->make(Repository::class);
$api = $repository->createApi($namespace, $host, $parameters);
$this->container->instance(Api::class, $api);
$this->container->alias(Api::class, 'json-api.inbound');
return $api;
}
|
Build the API instance and bind it into the container.
@param string $namespace
@param string $host
@param array $parameters
@return Api
|
bindApi
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/BootJsonApi.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/BootJsonApi.php
|
Apache-2.0
|
protected function bindPageResolver(): void
{
/** Override the current page resolution */
AbstractPaginator::currentPageResolver(function ($pageName) {
$pagination = app(QueryParametersInterface::class)->getPaginationParameters() ?: [];
return $pagination[$pageName] ?? null;
});
}
|
Override the page resolver to read the page parameter from the JSON API request.
@return void
|
bindPageResolver
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/BootJsonApi.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/BootJsonApi.php
|
Apache-2.0
|
public function __construct(Container $container, Factory $factory, Route $route)
{
$this->container = $container;
$this->factory = $factory;
$this->route = $route;
}
|
NegotiateContent constructor.
@param Container $container
@param Factory $factory
@param Route $route
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/NegotiateContent.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/NegotiateContent.php
|
Apache-2.0
|
public function handle($request, \Closure $next, ?string $default = null)
{
$api = $this->container->make(Api::class);
/** @var HeaderParametersInterface $headers */
$headers = $this->container->make(HeaderParametersInterface::class);
$contentType = $headers->getContentTypeHeader();
$codec = $this->factory->createCodec(
$api->getContainer(),
$this->matchEncoding($api, $request, $headers->getAcceptHeader(), $default),
$decoder = $contentType ? $this->matchDecoder($api, $request, $contentType, $default) : null
);
$this->matched($codec);
if (!$contentType && $this->isExpectingContent($request)) {
throw new DocumentRequiredException();
}
return $next($request);
}
|
Handle the request.
@param Request $request
@param \Closure $next
@param string|null $default
the default negotiator to use if there is not one for the resource type.
@return mixed
@throws HttpException
|
handle
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/NegotiateContent.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/NegotiateContent.php
|
Apache-2.0
|
protected function matchEncoding(
Api $api,
$request,
AcceptHeaderInterface $accept,
?string $defaultNegotiator
): Encoding
{
$negotiator = $this
->negotiator($api->getContainer(), $this->responseResourceType(), $defaultNegotiator)
->withRequest($request)
->withApi($api);
if ($this->willSeeMany($request)) {
return $negotiator->encodingForMany($accept);
}
return $negotiator->encoding($accept, $this->route->getResource());
}
|
@param Api $api
@param Request $request
@param AcceptHeaderInterface $accept
@param string|null $defaultNegotiator
@return Encoding
|
matchEncoding
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/NegotiateContent.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/NegotiateContent.php
|
Apache-2.0
|
protected function matchDecoder(
Api $api,
$request,
HeaderInterface $contentType,
?string $defaultNegotiator
): ?Decoding
{
$negotiator = $this
->negotiator($api->getContainer(), $this->route->getResourceType(), $defaultNegotiator)
->withRequest($request)
->withApi($api);
$resource = $this->route->getResource();
if ($resource && $field = $this->route->getRelationshipName()) {
return $negotiator->decodingForRelationship($contentType, $resource, $field);
}
return $negotiator->decoding($contentType, $resource);
}
|
@param Api $api
@param Request $request
@param HeaderInterface $contentType
@param string|null $defaultNegotiator
@return Decoding|null
|
matchDecoder
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/NegotiateContent.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/NegotiateContent.php
|
Apache-2.0
|
protected function responseResourceType(): ?string
{
return $this->route->getInverseResourceType() ?: $this->route->getResourceType();
}
|
Get the resource type that will be in the response.
@return string|null
|
responseResourceType
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/NegotiateContent.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/NegotiateContent.php
|
Apache-2.0
|
protected function negotiator(
ContainerInterface $container,
?string $resourceType,
?string $default
): ContentNegotiatorInterface
{
if ($resourceType && $negotiator = $container->getContentNegotiatorByResourceType($resourceType)) {
return $negotiator;
}
if ($default) {
return $container->getContentNegotiatorByName($default);
}
return $this->defaultNegotiator();
}
|
@param ContainerInterface $container
@param string|null $resourceType
@param string|null $default
@return ContentNegotiatorInterface
|
negotiator
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/NegotiateContent.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/NegotiateContent.php
|
Apache-2.0
|
protected function defaultNegotiator(): ContentNegotiatorInterface
{
return $this->factory->createContentNegotiator();
}
|
Get the default content negotiator.
@return ContentNegotiatorInterface
|
defaultNegotiator
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/NegotiateContent.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/NegotiateContent.php
|
Apache-2.0
|
protected function matched(Codec $codec): void
{
$this->route->setCodec($codec);
}
|
Apply the matched codec.
@param Codec $codec
|
matched
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/NegotiateContent.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/NegotiateContent.php
|
Apache-2.0
|
public function willSeeOne($request): bool
{
if ($this->route->isRelationship()) {
return false;
}
if ($this->route->isResource()) {
return true;
}
return $request->isMethod('POST');
}
|
Will the response contain a specific resource?
E.g. for a `posts` resource, this is invoked on the following URLs:
- `POST /posts`
- `GET /posts/1`
- `PATCH /posts/1`
- `DELETE /posts/1`
I.e. a response that may contain a specified resource.
@param Request $request
@return bool
|
willSeeOne
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/NegotiateContent.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/NegotiateContent.php
|
Apache-2.0
|
public function willSeeMany($request): bool
{
return !$this->willSeeOne($request);
}
|
Will the response contain zero-to-many of a resource?
E.g. for a `posts` resource, this is invoked on the following URLs:
- `/posts`
- `/comments/1/posts`
I.e. a response that will contain zero to many of the posts resource.
@param Request $request
@return bool
|
willSeeMany
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/NegotiateContent.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/NegotiateContent.php
|
Apache-2.0
|
protected function isExpectingContent($request): bool
{
$methods = $this->route->isNotRelationship() ? ['POST', 'PATCH'] : ['POST', 'PATCH', 'DELETE'];
return \in_array($request->getMethod(), $methods);
}
|
Is data expected for the supplied request?
If the JSON API request is any of the following, a JSON API document
is expected to be set on the request:
- Create resource
- Update resource
- Replace resource relationship
- Add to resource relationship
- Remove from resource relationship
@param Request $request
@return bool
|
isExpectingContent
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Middleware/NegotiateContent.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Middleware/NegotiateContent.php
|
Apache-2.0
|
public function __construct(
?array $includePaths = null,
?array $fieldSets = null,
?array $sortParameters = null,
?array $pagingParameters = null,
?array $filteringParameters = null,
?array $unrecognizedParams = null
) {
$this->fieldSets = $fieldSets;
$this->includePaths = $includePaths;
$this->sortParameters = $this->assertSortParameters($sortParameters);
$this->pagingParameters = $pagingParameters;
$this->unrecognizedParams = $unrecognizedParams;
$this->filteringParameters = $filteringParameters;
}
|
QueryParameters constructor.
@param string[]|null $includePaths
@param array|null $fieldSets
@param SortParameterInterface[]|null $sortParameters
@param array|null $pagingParameters
@param array|null $filteringParameters
@param array|null $unrecognizedParams
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Query/QueryParameters.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Query/QueryParameters.php
|
Apache-2.0
|
private function assertSortParameters(?array $sortParameters): ?array
{
if (null === $sortParameters) {
return null;
}
foreach ($sortParameters as $sortParameter) {
if (!$sortParameter instanceof SortParameterInterface) {
throw new \InvalidArgumentException('Expecting only sort parameter objects for the sort field.');
}
}
return $sortParameters;
}
|
@param array|null $sortParameters
@return array|null
|
assertSortParameters
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Query/QueryParameters.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Query/QueryParameters.php
|
Apache-2.0
|
private function getIncludeParameters(array $parameters, string $message): ?array
{
if (!array_key_exists(BaseQueryParser::PARAM_INCLUDE, $parameters)) {
return null;
}
// convert null to empty array, as the client has specified no include parameters.
if (null === $parameters[BaseQueryParser::PARAM_INCLUDE]) {
return [];
}
return $this->iteratorToArray($this->getIncludePaths($parameters, $message));
}
|
Parse include parameters.
@param array $parameters
@param string $message
@return array|null
|
getIncludeParameters
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Query/QueryParametersParser.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Query/QueryParametersParser.php
|
Apache-2.0
|
private function getFieldParameters(array $parameters, string $message): ?array
{
if (!array_key_exists(BaseQueryParser::PARAM_FIELDS, $parameters)) {
return null;
}
// convert null to empty array, as the client has specified no sparse fields
if (null === $parameters[BaseQueryParser::PARAM_FIELDS]) {
return [];
}
$fieldSets = [];
foreach ($this->getFields($parameters, $message) as $type => $fieldList) {
$fieldSets[$type] = $this->iteratorToArray($fieldList);
}
return $fieldSets;
}
|
Parse sparse field sets
@param array $parameters
@param string $message
@return array|null
|
getFieldParameters
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Query/QueryParametersParser.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Query/QueryParametersParser.php
|
Apache-2.0
|
private function getSortParameters(array $parameters, string $message): ?array
{
if (!array_key_exists(BaseQueryParser::PARAM_SORT, $parameters)) {
return null;
}
// convert null to empty array, as the client has specified no sort parameters.
if (null === $parameters[BaseQueryParser::PARAM_SORT]) {
return [];
}
$values = [];
foreach ($this->getSorts($parameters, $message) as $field => $isAsc) {
$values[] = new SortParameter($field, $isAsc);
}
return $values;
}
|
Parse sort parameters.
@param array $parameters
@param string $message
@return SortParameter[]|null
|
getSortParameters
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Query/QueryParametersParser.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Query/QueryParametersParser.php
|
Apache-2.0
|
private function getUnrecognizedParameters(array $parameters): ?array
{
unset(
$parameters[BaseQueryParser::PARAM_INCLUDE],
$parameters[BaseQueryParser::PARAM_FIELDS],
$parameters[BaseQueryParser::PARAM_SORT],
$parameters[BaseQueryParser::PARAM_PAGE],
$parameters[BaseQueryParser::PARAM_FILTER],
);
return empty($parameters) ? null : $parameters;
}
|
Parse unrecognized parameters.
@param array $parameters
@return array|null
|
getUnrecognizedParameters
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Query/QueryParametersParser.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Query/QueryParametersParser.php
|
Apache-2.0
|
public function __construct(string $field, bool $isAscending = true)
{
if (empty($field)) {
throw new InvalidArgumentException('Expecting a non-empty sort field name.');
}
$this->field = $field;
$this->isAscending = $isAscending;
}
|
SortParameter constructor.
@param string $field
@param bool $isAscending
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Query/SortParameter.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Query/SortParameter.php
|
Apache-2.0
|
protected function validateDocumentCompliance($document, ?ValidatorFactoryInterface $validators): void
{
$this->passes(
$this->factory->createNewResourceDocumentValidator(
$document,
$this->getResourceType(),
$validators && $validators->supportsClientIds()
)
);
}
|
Validate the JSON API document complies with the spec.
@param object $document
@param ValidatorFactoryInterface|null $validators
|
validateDocumentCompliance
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/CreateResource.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/CreateResource.php
|
Apache-2.0
|
protected function validateDocumentCompliance($document): void
{
$this->passes(
$this->factory->createExistingResourceDocumentValidator(
$document,
$this->getResourceType(),
$this->getResourceId()
)
);
}
|
Validate the JSON API document complies with the spec.
@param object $document
@return void
|
validateDocumentCompliance
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/UpdateResource.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/UpdateResource.php
|
Apache-2.0
|
public function __construct(
Request $httpRequest,
ContainerInterface $container,
Factory $factory,
Route $route
) {
$this->request = $httpRequest;
$this->factory = $factory;
$this->container = $container;
$this->route = $route;
}
|
ValidatedRequest constructor.
@param Request $httpRequest
@param ContainerInterface $container
@param Factory $factory
@param Route $route
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/ValidatedRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/ValidatedRequest.php
|
Apache-2.0
|
public function get($key, $default = null)
{
return Arr::get($this->all(), $key, $default);
}
|
Get an item from the JSON API document using "dot" notation.
@param string $key
@param mixed $default
@return mixed
|
get
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/ValidatedRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/ValidatedRequest.php
|
Apache-2.0
|
public function all()
{
if (is_array($this->data)) {
return $this->data;
}
return $this->data = $this->route->getCodec()->all($this->request);
}
|
Get the JSON API document as an array.
@return array
|
all
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/ValidatedRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/ValidatedRequest.php
|
Apache-2.0
|
public function query($key = null, $default = null)
{
return $this->request->query($key, $default);
}
|
Get parsed query parameters.
@param string|null $key
@param string|array|null $default
@return string|array|null
|
query
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/ValidatedRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/ValidatedRequest.php
|
Apache-2.0
|
public function decode()
{
return $this->route
->getCodec()
->document($this->request);
}
|
Get the JSON API document as an object.
@return object
|
decode
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/ValidatedRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/ValidatedRequest.php
|
Apache-2.0
|
public function decodeOrFail()
{
if (!$document = $this->decode()) {
throw new DocumentRequiredException();
}
return $document;
}
|
Get the JSON API document as an object.
@return object
|
decodeOrFail
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/ValidatedRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/ValidatedRequest.php
|
Apache-2.0
|
public function getType()
{
return $this->route->getType();
}
|
Get the domain record type that is subject of the request.
@return string
|
getType
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/ValidatedRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/ValidatedRequest.php
|
Apache-2.0
|
public function getResourceType()
{
return $this->route->getResourceType();
}
|
Get the resource type that the request is for.
@return string|null
|
getResourceType
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/ValidatedRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/ValidatedRequest.php
|
Apache-2.0
|
protected function validateDocument()
{
// no-op
}
|
Validate the JSON API document.
@return void
@throws JsonApiException
|
validateDocument
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/ValidatedRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/ValidatedRequest.php
|
Apache-2.0
|
protected function passes($validator)
{
if ($validator->fails()) {
$this->failedValidation($validator);
}
}
|
Run the validation and throw an exception if it fails.
@param DocumentValidatorInterface|ValidatorInterface $validator
@throws ValidationException
|
passes
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/ValidatedRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/ValidatedRequest.php
|
Apache-2.0
|
protected function failedValidation($validator)
{
if ($validator instanceof ValidatorInterface) {
throw ValidationException::create($validator);
}
throw new ValidationException($validator->getErrors());
}
|
@param DocumentValidatorInterface|ValidatorInterface $validator
@throws ValidationException
|
failedValidation
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/ValidatedRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/ValidatedRequest.php
|
Apache-2.0
|
protected function getValidators()
{
return $this->container->getValidatorsByResourceType($this->getResourceType());
}
|
Get the resource validators.
@return ValidatorFactoryInterface|null
|
getValidators
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/ValidatedRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/ValidatedRequest.php
|
Apache-2.0
|
protected function getInverseValidators()
{
return $this->container->getValidatorsByResourceType(
$this->route->getInverseResourceType()
);
}
|
Get the inverse resource validators.
@return ValidatorFactoryInterface|null
|
getInverseValidators
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/ValidatedRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/ValidatedRequest.php
|
Apache-2.0
|
public function getProcessId(): string
{
return $this->getRoute()->getProcessId();
}
|
Get the resource id that the request is for.
@return string
|
getProcessId
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/Concerns/ProcessRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/Concerns/ProcessRequest.php
|
Apache-2.0
|
public function getProcess(): AsynchronousProcess
{
if (!$process = $this->getRoute()->getProcess()) {
throw new RuntimeException('Expecting process binding to be substituted.');
}
return $process;
}
|
Get the domain record that the request relates to.
@return AsynchronousProcess
|
getProcess
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/Concerns/ProcessRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/Concerns/ProcessRequest.php
|
Apache-2.0
|
public function getRelationshipName(): string
{
return $this->getRoute()->getRelationshipName();
}
|
Get the relationship name that the request is for.
@return string
|
getRelationshipName
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/Concerns/RelationshipRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/Concerns/RelationshipRequest.php
|
Apache-2.0
|
public function getResourceId(): string
{
return $this->getRoute()->getResourceId();
}
|
Get the resource id that the request is for.
@return string
|
getResourceId
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/Concerns/ResourceRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/Concerns/ResourceRequest.php
|
Apache-2.0
|
public function getRecord()
{
if (!$record = $this->getRoute()->getResource()) {
throw new RuntimeException('Expecting resource binding to be substituted.');
}
return $record;
}
|
Get the domain record that the request relates to.
@return mixed
|
getRecord
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Requests/Concerns/ResourceRequest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Requests/Concerns/ResourceRequest.php
|
Apache-2.0
|
public function __construct(
Factory $factory,
Api $api,
Route $route,
ExceptionParserInterface $exceptions
) {
$this->factory = $factory;
$this->api = $api;
$this->route = $route;
$this->exceptions = $exceptions;
}
|
Responses constructor.
@param Factory $factory
@param Api $api
the API that is sending the responses.
@param Route $route
@param ExceptionParserInterface $exceptions
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function withMediaType(string $mediaType): self
{
if (!$encoding = $this->api->getEncodings()->find($mediaType)) {
throw new InvalidArgumentException(
"Media type {$mediaType} is not valid for API {$this->api->getName()}."
);
}
$codec = $this->factory->createCodec(
$this->api->getContainer(),
$encoding,
null
);
return $this->withCodec($codec);
}
|
Send a response with the supplied media type content.
@param string $mediaType
@return $this
|
withMediaType
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function withEncoding(
int $options = 0,
int $depth = 512,
string $mediaType = MediaTypeInterface::JSON_API_MEDIA_TYPE
): self {
$encoding = Encoding::create(
$mediaType,
$options,
$this->api->getUrl()->toString(),
$depth
);
$codec = $this->factory->createCodec(
$this->api->getContainer(),
$encoding,
null
);
return $this->withCodec($codec);
}
|
Set the encoding options.
@param int $options
@param int $depth
@param string|null $mediaType
@return $this
|
withEncoding
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function withEncodingParameters(?QueryParametersInterface $parameters): self
{
$this->parameters = $parameters;
return $this;
}
|
Set the encoding parameters to use.
@param QueryParametersInterface|null $parameters
@return $this
|
withEncodingParameters
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function statusCode(int $statusCode, array $headers = []): Response
{
return $this->getCodeResponse($statusCode, $headers);
}
|
@param int $statusCode
@param array $headers
@return Response
|
statusCode
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function meta($meta, int $statusCode = self::HTTP_OK, array $headers = []): Response
{
return $this->getMetaResponse($meta, $statusCode, $headers);
}
|
@param mixed $meta
@param int $statusCode
@param array $headers
@return Response
|
meta
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function noData(array $links = [], $meta = null, $statusCode = self::HTTP_OK, array $headers = []): Response
{
$encoder = $this->getEncoder();
$content = $encoder->withLinks($links)->encodeMeta($meta ?: []);
return $this->createJsonApiResponse($content, $statusCode, $headers, true);
}
|
@param array $links
@param mixed $meta
@param int $statusCode
@param array $headers
@return Response
|
noData
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function content(
$data,
array $links = [],
$meta = null,
int $statusCode = self::HTTP_OK,
array $headers = []
): Response {
return $this->getContentResponseBackwardsCompat($data, $statusCode, $links, $meta, $headers);
}
|
@param $data
@param array $links
@param mixed $meta
@param int $statusCode
@param array $headers
@return Response
|
content
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function getContentResponseBackwardsCompat(
$data,
int $statusCode = self::HTTP_OK,
?array $links = null,
$meta = null,
array $headers = []
): Response
{
if ($data instanceof PageInterface) {
[$data, $meta, $links] = $this->extractPage($data, $meta, $links);
}
$this->getEncoder()->withLinks($links ?? [])->withMeta($meta);
return parent::getContentResponse($data, $statusCode, $headers);
}
|
Get response with regular JSON:API Document in body.
This method provides backwards compatibility with the `getContentResponse()` method
from the Neomerx 1.x package.
@param array|object $data
@param int $statusCode
@param array|null $links
@param mixed|null $meta
@param array $headers
@return Response
|
getContentResponseBackwardsCompat
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function created($resource = null, array $links = [], $meta = null, array $headers = []): Response
{
if ($this->isNoContent($resource, $links, $meta)) {
return $this->noContent();
}
if (is_null($resource)) {
return $this->noData($links, $meta, self::HTTP_OK, $headers);
}
if ($this->isAsync($resource)) {
return $this->accepted($resource, $links, $meta, $headers);
}
return $this->getCreatedResponseBackwardsCompat($resource, $links, $meta, $headers);
}
|
@param $resource
@param array $links
@param mixed $meta
@param array $headers
@return Response
|
created
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function getCreatedResponseBackwardsCompat(
$resource,
array $links = [],
$meta = null,
array $headers = []
): Response
{
$this->getEncoder()->withLinks($links)->withMeta($meta);
$url = $this
->getResourceSelfLink($resource)
->getStringRepresentation($this->getUrlPrefix());
return $this->getCreatedResponse($resource, $url, $headers);
}
|
@param $resource
@param array $links
@param null $meta
@param array $headers
@return Response
|
getCreatedResponseBackwardsCompat
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function updated(
$resource = null,
array $links = [],
$meta = null,
array $headers = []
): Response {
return $this->getResourceResponse($resource, $links, $meta, $headers);
}
|
Return a response for a resource update request.
@param $resource
@param array $links
@param mixed $meta
@param array $headers
@return Response
|
updated
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function deleted(
$resource = null,
array $links = [],
$meta = null,
array $headers = []
): Response {
return $this->getResourceResponse($resource, $links, $meta, $headers);
}
|
Return a response for a resource delete request.
@param mixed|null $resource
@param array $links
@param mixed|null $meta
@param array $headers
@return Response
|
deleted
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function accepted(AsynchronousProcess $job, array $links = [], $meta = null, array $headers = []): Response
{
$url = $this
->getResourceSelfLink($job)
->getStringRepresentation($this->getUrlPrefix());
$headers['Content-Location'] = $url;
return $this->getContentResponseBackwardsCompat($job, Response::HTTP_ACCEPTED, $links, $meta, $headers);
}
|
@param AsynchronousProcess $job
@param array $links
@param null $meta
@param array $headers
@return Response
|
accepted
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function process(AsynchronousProcess $job, array $links = [], $meta = null, array $headers = [])
{
if (!$job->isPending() && $location = $job->getLocation()) {
$headers['Location'] = $location;
return $this->createJsonApiResponse(null, Response::HTTP_SEE_OTHER, $headers);
}
return $this->getContentResponseBackwardsCompat($job, self::HTTP_OK, $links, $meta, $headers);
}
|
@param AsynchronousProcess $job
@param array $links
@param mixed|null $meta
@param array $headers
@return RedirectResponse|mixed
|
process
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function relationship(
$data,
array $links = [],
$meta = null,
$statusCode = 200,
array $headers = []
): Response {
return $this->getIdentifiersResponseBackwardsCompat($data, $statusCode, $links, $meta, $headers);
}
|
@param $data
@param array $links
@param mixed $meta
@param int $statusCode
@param array $headers
@return Response
|
relationship
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function getIdentifiersResponseBackwardsCompat(
$data,
int $statusCode = self::HTTP_OK,
?array $links = null,
$meta = null,
array $headers = []
): Response {
if ($data instanceof PageInterface) {
[$data, $meta, $links] = $this->extractPage($data, $meta, $links);
}
$this->getEncoder()->withLinks($links)->withMeta($meta);
return parent::getIdentifiersResponse($data, $statusCode, $headers);
}
|
@param array|object $data
@param int $statusCode
@param array|null $links
@param mixed|null $meta
@param array $headers
@return Response
|
getIdentifiersResponseBackwardsCompat
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function error($error, ?int $defaultStatusCode = null, array $headers = []): Response
{
if (!$error instanceof ErrorInterface) {
$error = $this->factory->createDocumentMapper()->createError(
Error::cast($error)
);
}
if (!$error instanceof ErrorInterface) {
throw new UnexpectedValueException('Expecting an error object or array.');
}
return $this->errors([$error], $defaultStatusCode, $headers);
}
|
Create a response containing a single error.
@param Error|ErrorInterface|array $error
@param int|null $defaultStatusCode
@param array $headers
@return Response
|
error
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
public function errors(iterable $errors, ?int $defaultStatusCode = null, array $headers = []): Response
{
$errors = $this->factory->createDocumentMapper()->createErrors($errors);
$statusCode = Helpers::httpErrorStatus($errors, $defaultStatusCode);
return $this->getErrorResponse($errors, $statusCode, $headers);
}
|
Create a response containing multiple errors.
@param iterable $errors
@param int|null $defaultStatusCode
@param array $headers
@return Response
|
errors
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
protected function getResourceResponse($resource, array $links = [], $meta = null, array $headers = []): Response
{
if ($this->isNoContent($resource, $links, $meta)) {
return $this->noContent();
}
if (is_null($resource)) {
return $this->noData($links, $meta, self::HTTP_OK, $headers);
}
if ($this->isAsync($resource)) {
return $this->accepted($resource, $links, $meta, $headers);
}
return $this->getContentResponseBackwardsCompat($resource, self::HTTP_OK, $links, $meta, $headers);
}
|
@param $resource
@param array $links
@param mixed|null $meta
@param array $headers
@return Response
|
getResourceResponse
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
protected function createEncoder(): Encoder
{
$encoder = $this
->getCodec()
->getEncoder();
$encoder
->withUrlPrefix($this->getUrlPrefix())
->withEncodingParameters($this->parameters);
return $encoder;
}
|
Create a new and configured encoder.
@return Encoder
|
createEncoder
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.