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 update($record, array $relationship, QueryParametersInterface $parameters) { $relation = $this->getRelation($record, $this->key); if ($related = $this->findToOne($relationship)) { $relation->associate($related); } else { $relation->dissociate(); } }
@param Model $record @param array $relationship @param QueryParametersInterface $parameters @return void
update
php
cloudcreativity/laravel-json-api
src/Eloquent/BelongsTo.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/BelongsTo.php
Apache-2.0
public function replace($record, array $relationship, QueryParametersInterface $parameters) { $this->update($record, $relationship, $parameters); $record->save(); return $record; }
@param Model $record @param array $relationship @param QueryParametersInterface $parameters @return Model
replace
php
cloudcreativity/laravel-json-api
src/Eloquent/BelongsTo.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/BelongsTo.php
Apache-2.0
public function update($record, array $relationship, QueryParametersInterface $parameters) { $related = $this->findRelated($record, $relationship); $relation = $this->getRelation($record, $this->key); if ($relation instanceof Relations\BelongsToMany) { $relation->sync($related); return; } else { $this->sync($relation, $record->{$this->key}, $related); } // do not refresh as we expect the resource adapter to refresh the record. }
@param Model $record @param array $relationship @param QueryParametersInterface $parameters @return void
update
php
cloudcreativity/laravel-json-api
src/Eloquent/HasMany.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/HasMany.php
Apache-2.0
public function replace($record, array $relationship, QueryParametersInterface $parameters) { $this->update($record, $relationship, $parameters); $record->refresh(); // in case the relationship has been cached. return $record; }
@param Model $record @param array $relationship @param QueryParametersInterface $parameters @return Model
replace
php
cloudcreativity/laravel-json-api
src/Eloquent/HasMany.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/HasMany.php
Apache-2.0
public function add($record, array $relationship, QueryParametersInterface $parameters) { $related = $this->findRelated($record, $relationship); $relation = $this->getRelation($record, $this->key); $existing = $relation ->getQuery() ->whereKey($related->modelKeys()) ->get(); $relation->saveMany($related->diff($existing)); $record->refresh(); // in case the relationship has been cached. return $record; }
Add records to the relationship. Note that the spec says that duplicates MUST NOT be added. The default Laravel behaviour is to add duplicates, therefore we need to do some work to ensure that we only add the records that are not already in the relationship. @param Model $record @param array $relationship @param QueryParametersInterface $parameters @return Model
add
php
cloudcreativity/laravel-json-api
src/Eloquent/HasMany.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/HasMany.php
Apache-2.0
public function remove($record, array $relationship, QueryParametersInterface $parameters) { $related = $this->findRelated($record, $relationship); $relation = $this->getRelation($record, $this->key); if ($relation instanceof Relations\BelongsToMany) { $relation->detach($related); } else { $this->detach($relation, $related); } $record->refresh(); // in case the relationship has been cached return $record; }
@param Model $record @param array $relationship @param QueryParametersInterface $parameters @return Model
remove
php
cloudcreativity/laravel-json-api
src/Eloquent/HasMany.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/HasMany.php
Apache-2.0
protected function sync($relation, Collection $existing, Collection $updated) { $add = collect($updated)->reject(function ($model) use ($existing) { return $existing->contains($model); }); $remove = $existing->reject(function ($model) use ($updated) { return $updated->contains($model); }); if ($remove->isNotEmpty()) { $this->detach($relation, $remove); } $relation->saveMany($add); }
@param Relations\HasMany|Relations\MorphMany $relation @param Collection $existing @param $updated
sync
php
cloudcreativity/laravel-json-api
src/Eloquent/HasMany.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/HasMany.php
Apache-2.0
protected function detach($relation, Collection $remove) { /** @var Model $model */ foreach ($remove as $model) { $model->setAttribute($relation->getForeignKeyName(), null)->save(); } }
@param Relations\HasMany|Relations\MorphMany $relation @param Collection $remove
detach
php
cloudcreativity/laravel-json-api
src/Eloquent/HasMany.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/HasMany.php
Apache-2.0
protected function findRelated($record, array $relationship) { $inverse = $this->getRelation($record, $this->key)->getRelated(); $related = $this->findToMany($relationship); $related = collect($related)->filter(function ($model) use ($inverse) { return $model instanceof $inverse; }); return new Collection($related); }
Find the related models for a JSON API relationship object. We look up the models via the store. These then have to be filtered to ensure they are of the correct model type, because this has-many relation might be used in a polymorphic has-many JSON API relation. @todo this is currently inefficient for polymorphic relationships. We need to be able to filter the resource identifiers by the expected resource type before looking them up via the store. @param $record @param array $relationship @return Collection
findRelated
php
cloudcreativity/laravel-json-api
src/Eloquent/HasMany.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/HasMany.php
Apache-2.0
private function clear(Model $current, $relation) { if ($relation instanceof Relations\MorphOne) { $current->setAttribute($relation->getMorphType(), null); } $current->setAttribute($relation->getForeignKeyName(), null)->save(); }
Clear the relation. @param Model $current @param $relation
clear
php
cloudcreativity/laravel-json-api
src/Eloquent/HasOne.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/HasOne.php
Apache-2.0
public function withFieldName($name) { foreach ($this->adapters as $adapter) { $adapter->withFieldName($name); } }
Set the relationship name. @param $name @return void
withFieldName
php
cloudcreativity/laravel-json-api
src/Eloquent/MorphHasMany.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/MorphHasMany.php
Apache-2.0
protected function fillAttributes($record, Collection $attributes) { $record->fill( $this->deserializeAttributes($attributes, $record) ); }
Fill JSON API attributes into a model. @param Model $record @param $attributes
fillAttributes
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/DeserializesAttributes.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/DeserializesAttributes.php
Apache-2.0
protected function modelKeyForField($field, $model) { if (isset($this->attributes[$field])) { return $this->attributes[$field]; } $key = $model::$snakeAttributes ? Str::underscore($field) : Str::camelize($field); return $this->attributes[$field] = $key; }
Convert a JSON API resource field name to a model key. @param $field @param Model $model @return string
modelKeyForField
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/DeserializesAttributes.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/DeserializesAttributes.php
Apache-2.0
protected function deserializeAttributes($attributes, $record) { return collect($attributes)->filter(function ($v, $field) use ($record) { return $this->isFillableAttribute($field, $record); })->mapWithKeys(function ($value, $field) use ($record) { $key = $this->modelKeyForField($field, $record); return [$key => $this->deserializeAttribute($value, $field, $record)]; })->all(); }
Deserialize fillable attributes. @param $attributes @param $record @return array
deserializeAttributes
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/DeserializesAttributes.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/DeserializesAttributes.php
Apache-2.0
protected function deserializeAttribute($value, $field, $record) { if ($this->isDateAttribute($field, $record)) { return $this->deserializeDate($value, $field, $record); } $method = 'deserialize' . Str::classify($field) . 'Field'; if (method_exists($this, $method)) { return $this->{$method}($value, $record); } return $value; }
Deserialize a value obtained from the resource's attributes. @param $value the value that the client provided. @param $field the attribute key for the value @param Model $record @return Carbon|null
deserializeAttribute
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/DeserializesAttributes.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/DeserializesAttributes.php
Apache-2.0
protected function deserializeDate($value, $field, $record) { return !is_null($value) ? new Carbon($value) : null; }
Convert a JSON date into a PHP date time object. @param $value the value in the JSON API resource attribute field. @param string $field the JSON API field name being deserialized. @param Model $record the domain record being filled. @return Carbon|null
deserializeDate
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/DeserializesAttributes.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/DeserializesAttributes.php
Apache-2.0
protected function isDateAttribute($field, $record) { if (empty($this->dates)) { return in_array($this->modelKeyForField($field, $record), $record->getDates(), true); } return in_array($field, $this->dates, true); }
Is this resource key a date attribute? @param $field @param Model $record @return bool
isDateAttribute
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/DeserializesAttributes.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/DeserializesAttributes.php
Apache-2.0
protected function isFillableAttribute($field, $record) { return $this->isFillable($field, $record) && !$this->isRelation($field); }
Is the field a fillable attribute? @param string $field @param mixed $record @return bool
isFillableAttribute
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/DeserializesAttributes.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/DeserializesAttributes.php
Apache-2.0
protected function filterWithScopes($query, Collection $filters): void { foreach ($filters as $name => $value) { if ($scope = $this->modelScopeForFilter($name)) { $this->filterWithScope($query, $scope, $value); } } }
@param $query @param Collection $filters @return void
filterWithScopes
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/FiltersModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/FiltersModels.php
Apache-2.0
protected function filterWithScope($query, string $scope, $value): void { $query->{$scope}($value); }
@param $query @param string $scope @param $value @return void
filterWithScope
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/FiltersModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/FiltersModels.php
Apache-2.0
protected function modelScopeForFilter(string $name): ?string { /** If the developer has specified a scope for this filter, use that. */ if (array_key_exists($name, $this->filterScopes)) { return $this->filterScopes[$name]; } /** If it matches our default `id` filter, we ignore it. */ if ($name === $this->filterKeyForIds()) { return null; } return $this->guessScope($name); }
@param string $name the JSON API filter name. @return string|null
modelScopeForFilter
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/FiltersModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/FiltersModels.php
Apache-2.0
protected function guessScope(string $name): string { /** Use a scope that matches the JSON API filter name. */ if ($this->doesScopeExist($name)) { return Str::camelize($name); } $key = $this->modelKeyForField($name, $this->model); /** Use a scope that matches the model key for the JSON API field name. */ if ($this->doesScopeExist($key)) { return Str::camelize($key); } /** Or use Eloquent's `where*` magic method */ return 'where' . Str::classify($key); }
Guess the scope to use for a named JSON API filter. @param string $name @return string
guessScope
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/FiltersModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/FiltersModels.php
Apache-2.0
private function doesScopeExist(string $name): bool { return method_exists($this->model, 'scope' . Str::classify($name)); }
Does the named scope exist on the model? @param string $name @return bool
doesScopeExist
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/FiltersModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/FiltersModels.php
Apache-2.0
protected function with($query, QueryParametersInterface $parameters) { $query->with($this->getRelationshipPaths( (array) $parameters->getIncludePaths() )); }
Add eager loading to the query. @param Builder $query @param QueryParametersInterface $parameters @return void
with
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/IncludesModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/IncludesModels.php
Apache-2.0
protected function load($record, QueryParametersInterface $parameters) { $relationshipPaths = $this->getRelationshipPaths($parameters->getIncludePaths()); $record->loadMissing($relationshipPaths); }
Add eager loading to a record. @param Model $record @param QueryParametersInterface $parameters
load
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/IncludesModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/IncludesModels.php
Apache-2.0
protected function getRelationshipPaths($includePaths) { return $this ->convertIncludePaths($includePaths) ->merge($this->defaultWith) ->unique() ->all(); }
Get the relationship paths to eager load. @param Collection|array $includePaths the JSON API resource paths to be included. @return array
getRelationshipPaths
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/IncludesModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/IncludesModels.php
Apache-2.0
protected function convertIncludePaths($includePaths) { return collect($includePaths)->map(function ($path) { return $this->convertIncludePath($path); })->flatten()->filter()->values(); }
@param Collection|array $includePaths @return Collection
convertIncludePaths
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/IncludesModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/IncludesModels.php
Apache-2.0
protected function convertIncludePath($path) { if (array_key_exists($path, $this->includePaths)) { return $this->includePaths[$path] ?: null; } return collect(explode('.', $path))->map(function ($segment) { return $this->modelRelationForField($segment); })->implode('.'); }
Convert a JSON API include path to a model relationship path. @param $path @return string|null
convertIncludePath
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/IncludesModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/IncludesModels.php
Apache-2.0
protected function modelRelationForField($field) { return $this->camelCaseRelations ? Str::camelize($field) : Str::underscore($field); }
Convert a JSON API field name to an Eloquent model relation name. According to the PSR1 spec, method names on classes MUST be camel case. However, there seem to be some Laravel developers who snake case relationship methods on their models, so that the method name matches the snake case format of attributes (column values). The `$camelCaseRelations` property controls the behaviour of this conversion: - If `true`, a field name of `user-history` or `user_history` will expect the Eloquent model relation method to be `userHistory`. - If `false`, a field name of `user-history` or `user_history` will expect the Eloquent model relation method to be `user_history`. I.e. if PSR1 is not being followed, the best guess is that method names are snake case. If the developer has different conversion logic, they should overload this method and implement it themselves. @param string $field the JSON API field name. @return string the expected relation name on the Eloquent model.
modelRelationForField
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/IncludesModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/IncludesModels.php
Apache-2.0
protected function getRelation($record, $key) { $relation = $record->{$key}(); if (!$relation || !$this->acceptRelation($relation)) { throw new RuntimeException(sprintf( 'JSON API relation %s cannot be used for an Eloquent %s relation.', class_basename($this), class_basename($relation) )); } return $relation; }
Get the relation from the model. @param Model $record @param string $key @return Relation|Builder
getRelation
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/QueriesRelations.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/QueriesRelations.php
Apache-2.0
protected function acceptRelation($relation) { return $relation instanceof Relation; }
Is the supplied Eloquent relation acceptable for this JSON API relation? @param Relation $relation @return bool
acceptRelation
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/QueriesRelations.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/QueriesRelations.php
Apache-2.0
protected function requiresInverseAdapter($record, QueryParametersInterface $parameters) { return !empty($parameters->getFilteringParameters()) || !empty($parameters->getSortParameters()) || !empty($parameters->getPaginationParameters()) || !empty($parameters->getIncludePaths()); }
Does the query need to be passed to the inverse adapter? @param $record @param QueryParametersInterface $parameters @return bool
requiresInverseAdapter
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/QueriesRelations.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/QueriesRelations.php
Apache-2.0
protected function adapterFor($relation) { $adapter = $this->getStore()->adapterFor($relation->getModel()); if (!$adapter instanceof AbstractAdapter) { throw new RuntimeException('Expecting inverse resource adapter to be an Eloquent adapter.'); } return $adapter; }
Get an Eloquent adapter for the supplied record's relationship. @param Relation|Builder $relation @return AbstractAdapter
adapterFor
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/QueriesRelations.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/QueriesRelations.php
Apache-2.0
protected function fillAttributes($record, Collection $attributes) { $field = $this->getSoftDeleteField($record); $attributesArr = $attributes->toArray(); if (Arr::has($attributesArr, $field)) { $this->fillSoftDelete($record, $field, Arr::get($attributesArr, $field)); } $record->fill( $this->deserializeAttributes(Arr::except($attributesArr, $field), $record) ); }
@param Model $record @param Collection $attributes
fillAttributes
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/SoftDeletesModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/SoftDeletesModels.php
Apache-2.0
protected function fillSoftDelete(Model $record, $field, $value) { $value = $this->deserializeSoftDelete( $value, $field, $record ); $record->forceFill([ $this->getSoftDeleteKey($record) => $value, ]); }
Fill the soft delete value if it has been provided. @param Model $record @param string $field @param mixed $value
fillSoftDelete
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/SoftDeletesModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/SoftDeletesModels.php
Apache-2.0
protected function deserializeSoftDelete($value, $field, $record) { if (collect([true, false, 1, 0, '1', '0'])->containsStrict($value)) { return $value ? Carbon::now() : null; } return $this->deserializeAttribute($value, $field, $record); }
Deserialize the provided value for the soft delete attribute. If a boolean is provided, we interpret the soft delete value as now. We check for all the boolean values accepted by the Laravel boolean validator. @param $value @param $field @param $record @return Carbon|null
deserializeSoftDelete
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/SoftDeletesModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/SoftDeletesModels.php
Apache-2.0
protected function softDeleteField() { return property_exists($this, 'softDeleteField') ? $this->softDeleteField : null; }
The JSON API field name that is used for the soft delete value. If none is set, defaults to the camel-case version of the model's `deleted_at` column, e.g. `deletedAt`. @return string|null
softDeleteField
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/SoftDeletesModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/SoftDeletesModels.php
Apache-2.0
protected function getSoftDeleteField(Model $record) { if ($field = $this->softDeleteField()) { return $field; } $key = $this->getSoftDeleteKey($record); return Str::camelize($key); }
Get the JSON API field that is used for the soft-delete value. @param Model $record @return string
getSoftDeleteField
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/SoftDeletesModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/SoftDeletesModels.php
Apache-2.0
protected function getSoftDeleteKey(Model $record) { return $record->getDeletedAtColumn(); }
Get the model key that should be used for the soft-delete value. @param Model $record @return string
getSoftDeleteKey
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/SoftDeletesModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/SoftDeletesModels.php
Apache-2.0
protected function sort($query, array $sortBy) { /** @var SortParameterInterface $param */ foreach ($sortBy as $param) { $this->sortBy($query, $param); } }
Apply sort parameters to the query. @param Builder $query @param SortParameterInterface[] $sortBy @return void
sort
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/SortsModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/SortsModels.php
Apache-2.0
protected function defaultSort() { return collect($this->defaultSort)->map(function ($param) { $desc = ($param[0] === '-'); $field = ltrim($param, '-'); return new SortParameter($field, !$desc); })->all(); }
Get sort parameters to use when the client has not provided a sort order. @return array
defaultSort
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/SortsModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/SortsModels.php
Apache-2.0
protected function sortBy($query, SortParameterInterface $param) { $direction = $param->isAscending() ? 'asc' : 'desc'; $method = 'sortBy' . Str::classify($param->getField()); if (method_exists($this, $method)) { $this->{$method}($query, $direction); return; } $column = $this->getQualifiedSortColumn($query, $param->getField()); $query->orderBy($column, $direction); }
@param Builder $query @param SortParameterInterface $param @return void
sortBy
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/SortsModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/SortsModels.php
Apache-2.0
protected function getQualifiedSortColumn($query, $field) { $key = $this->getSortColumn($field, $query->getModel()); return $query->getModel()->qualifyColumn($key); }
@param Builder $query @param string $field @return string
getQualifiedSortColumn
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/SortsModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/SortsModels.php
Apache-2.0
protected function getSortColumn($field, Model $model) { /** If there is a custom mapping, return that */ if (isset($this->sortColumns[$field])) { return $this->sortColumns[$field]; } return $model::$snakeAttributes ? Str::underscore($field) : Str::camelize($field); }
Get the table column to use for the specified search field. @param string $field @param Model $model @return string
getSortColumn
php
cloudcreativity/laravel-json-api
src/Eloquent/Concerns/SortsModels.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/Concerns/SortsModels.php
Apache-2.0
public function getRootObject($data): ?object { if ($data instanceof Generator) { throw new RuntimeException('Generators are not supported as resource collections.'); } if (null === $data || $this->isResource($data)) { return $data; } $value = $this->getRootObjectFromIterable($data); if (null === $value || $this->isResource($value)) { return $value; } throw new RuntimeException( sprintf('Unexpected data type: %s.', get_debug_type($value)), ); }
@param object|iterable|null $data @return object|null
getRootObject
php
cloudcreativity/laravel-json-api
src/Encoder/DataAnalyser.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/DataAnalyser.php
Apache-2.0
public function getIncludePaths($data): array { $includePaths = []; $root = $this->getRootObject($data); if (null !== $root) { $includePaths = $this->container->getSchema($root)->getIncludePaths(); } return $includePaths; }
@param object|iterable|null $data @return array
getIncludePaths
php
cloudcreativity/laravel-json-api
src/Encoder/DataAnalyser.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/DataAnalyser.php
Apache-2.0
private function getRootObjectFromIterable(iterable $data): ?object { if (is_array($data)) { return $data[0] ?? null; } if ($data instanceof Enumerable) { return $data->first(); } if ($data instanceof Iterator) { $data->rewind(); return $data->valid() ? $data->current() : null; } foreach ($data as $value) { return $value; } return null; }
@param iterable $data @return object|null
getRootObjectFromIterable
php
cloudcreativity/laravel-json-api
src/Encoder/DataAnalyser.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/DataAnalyser.php
Apache-2.0
public static function assertInstance(EncoderInterface $encoder): self { if ($encoder instanceof self) { return $encoder; } throw new RuntimeException('Expecting an extended encoder instance.'); }
Assert that the encoder is an extended encoder. @param EncoderInterface $encoder @return Encoder
assertInstance
php
cloudcreativity/laravel-json-api
src/Encoder/Encoder.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/Encoder.php
Apache-2.0
public function __construct( FactoryInterface $factory, SchemaContainerInterface $container, DataAnalyser $dataAnalyser ) { parent::__construct($factory, $container); $this->dataAnalyser = $dataAnalyser; }
Encoder constructor. @param FactoryInterface $factory @param SchemaContainerInterface $container @param DataAnalyser $dataAnalyser
__construct
php
cloudcreativity/laravel-json-api
src/Encoder/Encoder.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/Encoder.php
Apache-2.0
public function withEncodingParameters(?QueryParametersInterface $parameters): self { if ($parameters) { $this ->withIncludedPaths($parameters->getIncludePaths()) ->withFieldSets($parameters->getFieldSets() ?? []); } return $this; }
Set the encoding parameters. @param QueryParametersInterface|null $parameters @return $this
withEncodingParameters
php
cloudcreativity/laravel-json-api
src/Encoder/Encoder.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/Encoder.php
Apache-2.0
public function withIncludedPaths(?iterable $paths): EncoderInterface { parent::withIncludedPaths($paths ?? []); $this->hasIncludePaths = (null !== $paths); return $this; }
@param iterable|null $paths @return $this
withIncludedPaths
php
cloudcreativity/laravel-json-api
src/Encoder/Encoder.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/Encoder.php
Apache-2.0
public function withEncoderOptions(?EncoderOptions $options): self { if ($options) { $this ->withEncodeOptions($options->getOptions()) ->withEncodeDepth($options->getDepth()) ->withUrlPrefix($options->getUrlPrefix()); } return $this; }
Set the encoder options. @param EncoderOptions|null $options @return $this
withEncoderOptions
php
cloudcreativity/laravel-json-api
src/Encoder/Encoder.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/Encoder.php
Apache-2.0
protected function encodeDataToArray($data): array { if (false === $this->hasIncludePaths) { if ($data instanceof Generator) { $data = iterator_to_array($data); } parent::withIncludedPaths($this->dataAnalyser->getIncludePaths($data)); $this->hasIncludePaths = true; } return parent::encodeDataToArray($data); }
@param iterable|object|null $data @return array
encodeDataToArray
php
cloudcreativity/laravel-json-api
src/Encoder/Encoder.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/Encoder.php
Apache-2.0
public function __construct(int $options = 0, ?string $urlPrefix = null, int $depth = 512) { $this->options = $options; $this->depth = $depth; $this->urlPrefix = $urlPrefix; }
EncoderOptions constructor. @param int $options @param string|null $urlPrefix @param int $depth
__construct
php
cloudcreativity/laravel-json-api
src/Encoder/EncoderOptions.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/EncoderOptions.php
Apache-2.0
public function getOptions(): int { return $this->options; }
@link http://php.net/manual/en/function.json-encode.php @return int
getOptions
php
cloudcreativity/laravel-json-api
src/Encoder/EncoderOptions.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/EncoderOptions.php
Apache-2.0
public function getDepth(): int { return $this->depth; }
@link http://php.net/manual/en/function.json-encode.php @return int
getDepth
php
cloudcreativity/laravel-json-api
src/Encoder/EncoderOptions.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/EncoderOptions.php
Apache-2.0
public static function cast($value): self { $status = null; if ($value instanceof JsonApiException) { $status = $value->getHttpCode(); $value = $value->getErrors(); } if ($value instanceof ErrorInterface) { $value = [$value]; } if (!is_iterable($value)) { throw new \UnexpectedValueException('Invalid Neomerx error collection.'); } $errors = new self(...collect($value)->values()); $errors->setDefaultStatus($status); return $errors; }
Cast a value to an errors document. @param ErrorInterface|iterable|JsonApiException $value @return Errors
cast
php
cloudcreativity/laravel-json-api
src/Encoder/Neomerx/Document/Errors.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/Neomerx/Document/Errors.php
Apache-2.0
public function setDefaultStatus(?int $status): self { $this->defaultHttpStatus = $status; return $this; }
Set the default HTTP status. @param int|null $status @return $this
setDefaultStatus
php
cloudcreativity/laravel-json-api
src/Encoder/Neomerx/Document/Errors.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Encoder/Neomerx/Document/Errors.php
Apache-2.0
public function __construct( RequestInterface $request, ?ResponseInterface $response = null, ?Exception $previous = null ) { parent::__construct( $previous ? $previous->getMessage() : 'Client encountered an error.', $response ? $response->getStatusCode() : 0, $previous ); $this->request = $request; $this->response = $response; }
ClientException constructor. @param RequestInterface $request @param ResponseInterface|null $response @param Exception|null $previous
__construct
php
cloudcreativity/laravel-json-api
src/Exceptions/ClientException.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/ClientException.php
Apache-2.0
public function getErrors() { if (!is_null($this->errors)) { return collect($this->errors); } try { $this->errors = $this->parse(); } catch (Exception $ex) { $this->errors = []; } return collect($this->errors); }
Get any JSON API errors that are in the response. @return Collection
getErrors
php
cloudcreativity/laravel-json-api
src/Exceptions/ClientException.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/ClientException.php
Apache-2.0
private function parse() { if (!$this->response) { return []; } $body = json_decode((string) $this->response->getBody(), true); return isset($body['errors']) ? $body['errors'] : []; }
Parse JSON API errors out of the response body. @return array
parse
php
cloudcreativity/laravel-json-api
src/Exceptions/ClientException.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/ClientException.php
Apache-2.0
public function __construct(?Exception $previous = null) { parent::__construct( null, 'Expecting request to contain a JSON API document.', self::HTTP_CODE_BAD_REQUEST, $previous ); }
DocumentRequiredException constructor. @param Exception|null $previous
__construct
php
cloudcreativity/laravel-json-api
src/Exceptions/DocumentRequiredException.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/DocumentRequiredException.php
Apache-2.0
protected function getDefaultTitle($status): ?string { if ($status && isset(Response::$statusTexts[$status])) { return Response::$statusTexts[$status]; } return null; }
@param string|null $status @return string|null
getDefaultTitle
php
cloudcreativity/laravel-json-api
src/Exceptions/ExceptionParser.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/ExceptionParser.php
Apache-2.0
public function isJsonApi($request, Throwable $e) { if (Helpers::wantsJsonApi($request)) { return true; } /** @var Route $route */ $route = app(JsonApiService::class)->currentRoute(); return $route->hasCodec() && $route->getCodec()->willEncode(); }
Does the HTTP request require a JSON API error response? This method determines if we need to render a JSON API error response for the client. We need to do this if the client has requested JSON API via its Accept header. @param Request $request @param Throwable $e @return bool
isJsonApi
php
cloudcreativity/laravel-json-api
src/Exceptions/HandlesErrors.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/HandlesErrors.php
Apache-2.0
public function renderJsonApi($request, Throwable $e) { $headers = ($e instanceof HttpException) ? $e->getHeaders() : []; return json_api()->exceptions()->parse($e)->toResponse($request)->withHeaders($headers); }
Render an exception as a JSON API error response. @param Request $request @param Throwable $e @return Response
renderJsonApi
php
cloudcreativity/laravel-json-api
src/Exceptions/HandlesErrors.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/HandlesErrors.php
Apache-2.0
protected function prepareJsonApiException(JsonApiException $ex) { $error = Collection::make($ex->getErrors())->map( fn(ErrorInterface $err) => $err->getDetail() ?: $err->getTitle() )->filter()->first(); return new HttpException($ex->getHttpCode(), $error, $ex); }
Prepare JSON API exception for non-JSON API rendering. @param JsonApiException $ex @return HttpException
prepareJsonApiException
php
cloudcreativity/laravel-json-api
src/Exceptions/HandlesErrors.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/HandlesErrors.php
Apache-2.0
public static function create($defaultHttpCode = self::HTTP_CODE_BAD_REQUEST, ?Exception $previous = null) { return new self(json_last_error(), json_last_error_msg(), $defaultHttpCode, $previous); }
@param int $defaultHttpCode @param Exception|null $previous @return InvalidJsonException
create
php
cloudcreativity/laravel-json-api
src/Exceptions/InvalidJsonException.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/InvalidJsonException.php
Apache-2.0
public function __construct( $jsonError = null, $jsonErrorMessage = null, $defaultHttpCode = self::HTTP_CODE_BAD_REQUEST, ?Exception $previous = null ) { parent::__construct([], $defaultHttpCode, $previous); $this->jsonError = $jsonError; $this->jsonErrorMessage = $jsonErrorMessage; $this->addError($this->createError()); }
InvalidJsonException constructor. @param int|null $jsonError @param string|null $jsonErrorMessage @param int $defaultHttpCode @param Exception|null $previous
__construct
php
cloudcreativity/laravel-json-api
src/Exceptions/InvalidJsonException.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/InvalidJsonException.php
Apache-2.0
public static function make($errors, ?Throwable $previous = null): self { return new self($errors, $previous); }
Fluent constructor. @param Errors|Error $errors @param Throwable|null $previous @return static
make
php
cloudcreativity/laravel-json-api
src/Exceptions/JsonApiException.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/JsonApiException.php
Apache-2.0
public function __construct($errors, ?Throwable $previous = null, array $headers = []) { parent::__construct('JSON API error', 0, $previous); $this->errors = Errors::cast($errors); $this->headers = $headers; }
JsonApiException constructor. @param Errors|Error $errors @param Throwable|null $previous @param array $headers
__construct
php
cloudcreativity/laravel-json-api
src/Exceptions/JsonApiException.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/JsonApiException.php
Apache-2.0
public function __construct( string $type, string $id, ?Exception $previous = null, int $code = 0, array $headers = [] ) { parent::__construct("Resource {$type} with id {$id} does not exist.", $previous, $code, $headers); $this->type = $type; $this->id = $id; }
ResourceNotFoundException constructor. @param string $type @param string $id @param Exception|null $previous @param int $code @param array $headers
__construct
php
cloudcreativity/laravel-json-api
src/Exceptions/ResourceNotFoundException.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/ResourceNotFoundException.php
Apache-2.0
public static function create(ValidatorInterface $validator): self { $ex = new self($validator->getErrors()); $ex->validator = $validator; return $ex; }
Create a validation exception from a validator. @param ValidatorInterface $validator @return ValidationException
create
php
cloudcreativity/laravel-json-api
src/Exceptions/ValidationException.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/ValidationException.php
Apache-2.0
public function __construct($errors, $defaultHttpCode = self::DEFAULT_HTTP_CODE, ?Exception $previous = null) { parent::__construct( $errors, Helpers::httpErrorStatus($errors, $defaultHttpCode), $previous ); }
ValidationException constructor. @param ErrorInterface|ErrorInterface[]|ErrorCollection $errors @param string|int|null $defaultHttpCode @param Exception|null $previous
__construct
php
cloudcreativity/laravel-json-api
src/Exceptions/ValidationException.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Exceptions/ValidationException.php
Apache-2.0
public function createResolver($apiName, array $config) { $factoryName = isset($config['resolver']) ? $config['resolver'] : ResolverFactory::class; $factory = $this->container->make($factoryName); if ($factory instanceof ResolverInterface) { return $factory; } if (!is_callable($factory)) { throw new RuntimeException("Factory {$factoryName} cannot be invoked."); } $resolver = $factory($apiName, $config); if (!$resolver instanceof ResolverInterface) { throw new RuntimeException("Factory {$factoryName} did not create a resolver instance."); } return $resolver; }
Create a resolver. @param string $apiName @param array $config @return ResolverInterface
createResolver
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createLaravelSchemaContainer(ContainerInterface $container): SchemaContainer { return new SchemaContainer($container, $this); }
Create the custom Laravel JSON:API schema container. @param ContainerInterface $container @return SchemaContainer
createLaravelSchemaContainer
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createLaravelEncoder(ContainerInterface $container): Encoder { return new Encoder( $this, $this->createLaravelSchemaContainer($container), new DataAnalyser($container), ); }
Create the custom Laravel JSON:API schema container. @param ContainerInterface $container @return Encoder
createLaravelEncoder
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createClient( $httpClient, ContainerInterface $container, SerializerInterface $encoder ): ClientInterface { return new GuzzleClient( $httpClient, $this->createLaravelSchemaContainer($container), new ClientSerializer($encoder, $this) ); }
@param mixed $httpClient @param ContainerInterface $container @param SerializerInterface $encoder @return ClientInterface
createClient
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createPage( $data, ?LinkInterface $first = null, ?LinkInterface $previous = null, ?LinkInterface $next = null, ?LinkInterface $last = null, $meta = null, ?string $metaKey = null ): PageInterface { return new Page($data, $first, $previous, $next, $last, $meta, $metaKey); }
@param mixed $data @param LinkInterface|null $first @param LinkInterface|null $previous @param LinkInterface|null $next @param LinkInterface|null $last @param mixed|null $meta @param string|null $metaKey @return PageInterface
createPage
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createResponseFactory(Api $api): Responses { return new Responses( $this->container->make(Factory::class), $api, $this->container->make(Route::class), $this->container->make('json-api.exceptions') ); }
Create a response factory. @param Api $api @return Responses
createResponseFactory
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createQueryParameters( ?array $includePaths = null, ?array $fieldSets = null, ?array $sortParameters = null, ?array $pagingParameters = null, ?array $filteringParameters = null, ?array $unrecognizedParams = null ) { return new QueryParameters( $includePaths, $fieldSets, $sortParameters, $pagingParameters, $filteringParameters, $unrecognizedParams ); }
@param array|null $includePaths @param array|null $fieldSets @param array|null $sortParameters @param array|null $pagingParameters @param array|null $filteringParameters @param array|null $unrecognizedParams @return QueryParameters
createQueryParameters
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createNewResourceDocumentValidator( object $document, string $expectedType, bool $clientIds ): Validation\Spec\CreateResourceValidator { $store = $this->container->make(StoreInterface::class); $errors = $this->createErrorTranslator(); return new Validation\Spec\CreateResourceValidator( $store, $errors, $document, $expectedType, $clientIds ); }
Create a validator to check that a resource document complies with the JSON API specification. @param object $document @param string $expectedType @param bool $clientIds whether client ids are supported. @return Validation\Spec\CreateResourceValidator
createNewResourceDocumentValidator
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createExistingResourceDocumentValidator( object $document, string $expectedType, string $expectedId ): Validation\Spec\UpdateResourceValidator { $store = $this->container->make(StoreInterface::class); $errors = $this->createErrorTranslator(); return new Validation\Spec\UpdateResourceValidator( $store, $errors, $document, $expectedType, $expectedId ); }
Create a validator to check that a resource document complies with the JSON API specification. @param object $document @param string $expectedType @param string $expectedId @return Validation\Spec\UpdateResourceValidator
createExistingResourceDocumentValidator
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createRelationshipDocumentValidator(object $document): Validation\Spec\RelationValidator { return new Validation\Spec\RelationValidator( $this->container->make(StoreInterface::class), $this->createErrorTranslator(), $document ); }
Create a validator to check that a relationship document complies with the JSON API specification. @param object $document @return Validation\Spec\RelationValidator
createRelationshipDocumentValidator
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createErrorTranslator(): ErrorTranslator { return new ErrorTranslator( $this->container->make(Translator::class) ); }
Create an error translator. @return ErrorTranslator
createErrorTranslator
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createCodec(ContainerInterface $container, Encoding $encoding, ?Decoding $decoding): Codec { return new Codec($this, $this->createMediaTypeParser(), $container, $encoding, $decoding); }
@param ContainerInterface $container @param Encoding $encoding @param Decoding|null $decoding @return Codec
createCodec
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createValidator( array $data, array $rules, array $messages = [], array $customAttributes = [], ?Closure $callback = null ): ValidatorInterface { $translator = $this->createErrorTranslator(); return new Validation\Validator( $this->makeValidator($data, $rules, $messages, $customAttributes), $translator, $callback ); }
Create a Laravel validator that has JSON API error objects. @param array $data @param array $rules @param array $messages @param array $customAttributes @param Closure|null $callback a closure for creating an error, that will be bound to the error translator. @return ValidatorInterface
createValidator
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createResourceValidator( ResourceObject $resource, array $rules, array $messages = [], array $customAttributes = [] ) { return $this->createValidator( $resource->all(), $rules, $messages, $customAttributes, function ($key, $detail, $failed) use ($resource) { return $this->invalidResource( $resource->pointer($key, '/data'), $detail, $failed ); } ); }
Create a JSON API resource object validator. @param ResourceObject $resource @param array $rules @param array $messages @param array $customAttributes @return ValidatorInterface
createResourceValidator
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createRelationshipValidator( ResourceObject $resource, array $rules, array $messages = [], array $customAttributes = [] ) { return $this->createValidator( $resource->all(), $rules, $messages, $customAttributes, function ($key, $detail, $failed) use ($resource) { return $this->invalidResource( $resource->pointerForRelationship($key, '/data'), $detail, $failed ); } ); }
Create a JSON API relationship validator. @param ResourceObject $resource the resource object, containing only the relationship field. @param array $rules @param array $messages @param array $customAttributes @return ValidatorInterface
createRelationshipValidator
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createDeleteValidator( array $data, array $rules, array $messages = [], array $customAttributes = [] ) { return $this->createValidator( $data, $rules, $messages, $customAttributes, function ($key, $detail) { return $this->resourceCannotBeDeleted($detail); } ); }
@param array $data @param array $rules @param array $messages @param array $customAttributes @return ValidatorInterface
createDeleteValidator
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
public function createQueryValidator( array $data, array $rules, array $messages = [], array $customAttributes = [] ) { return $this->createValidator( $data, $rules, $messages, $customAttributes, function ($key, $detail, $failed) { return $this->invalidQueryParameter($key, $detail, $failed); } ); }
Create a query validator. @param array $data @param array $rules @param array $messages @param array $customAttributes @return ValidatorInterface
createQueryValidator
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
protected function makeValidator( array $data, array $rules, array $messages = [], array $customAttributes = [] ) { return $this->container ->make(ValidatorFactoryContract::class) ->make($data, $rules, $messages, $customAttributes); }
@param array $data @param array $rules @param array $messages @param array $customAttributes @return Validator
makeValidator
php
cloudcreativity/laravel-json-api
src/Factories/Factory.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Factories/Factory.php
Apache-2.0
protected function checkAcceptTypes(AcceptHeaderInterface $header, EncodingList $supported): Encoding { if (!$codec = $supported->acceptable($header)) { throw $this->notAcceptable($header); } return $codec; }
@param AcceptHeaderInterface $header @param EncodingList $supported @return Encoding @throws HttpException
checkAcceptTypes
php
cloudcreativity/laravel-json-api
src/Http/ContentNegotiator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/ContentNegotiator.php
Apache-2.0
protected function checkContentType(HeaderInterface $header, DecodingList $supported): Decoding { if (!$decoder = $supported->forHeader($header)) { throw $this->unsupportedMediaType(); } return $decoder; }
@param HeaderInterface $header @param DecodingList $supported @return Decoding @throws HttpException
checkContentType
php
cloudcreativity/laravel-json-api
src/Http/ContentNegotiator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/ContentNegotiator.php
Apache-2.0
protected function notAcceptable(AcceptHeaderInterface $header): HttpException { return new HttpException( self::HTTP_NOT_ACCEPTABLE, "The requested resource is capable of generating only content not acceptable " . "according to the Accept headers sent in the request." ); }
Get the exception if the Accept header is not acceptable. @param AcceptHeaderInterface $header @return HttpException @todo add translation
notAcceptable
php
cloudcreativity/laravel-json-api
src/Http/ContentNegotiator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/ContentNegotiator.php
Apache-2.0
protected function isMediaType(HeaderInterface $header, string $mediaType): bool { $mediaType = MediaType::parse(0, $mediaType); return collect($header->getMediaTypes())->contains(function (MediaTypeInterface $check) use ($mediaType) { return $check->equalsTo($mediaType); }); }
@param HeaderInterface $header @param string $mediaType @return bool
isMediaType
php
cloudcreativity/laravel-json-api
src/Http/ContentNegotiator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/ContentNegotiator.php
Apache-2.0
protected function isJsonApi(HeaderInterface $header): bool { return $this->isMediaType($header, MediaTypeInterface::JSON_API_MEDIA_TYPE); }
Is the header the JSON API media-type? @param HeaderInterface $header @return bool
isJsonApi
php
cloudcreativity/laravel-json-api
src/Http/ContentNegotiator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/ContentNegotiator.php
Apache-2.0
protected function unsupportedMediaType(): HttpException { return new HttpException( self::HTTP_UNSUPPORTED_MEDIA_TYPE, 'The request entity has a media type which the server or resource does not support.' ); }
Get the exception if the Content-Type header media type is not supported. @return HttpException @todo add translation
unsupportedMediaType
php
cloudcreativity/laravel-json-api
src/Http/ContentNegotiator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/ContentNegotiator.php
Apache-2.0
protected function reply() { return \response()->jsonApi($this->apiName()); }
Get the responses factory. This will return the responses factory for the API handling the inbound HTTP request. If you are using this trait in a context where there is no API handling the inbound HTTP request, you can specify the API to use by setting the `api` property on the implementing class. @return Responses
reply
php
cloudcreativity/laravel-json-api
src/Http/Controllers/CreatesResponses.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Controllers/CreatesResponses.php
Apache-2.0
public function index(StoreInterface $store, FetchResources $request) { $result = $this->doSearch($store, $request); if ($this->isResponse($result)) { return $result; } return $this->reply()->content($result); }
Index action. @param StoreInterface $store @param FetchResources $request @return Response
index
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 read(StoreInterface $store, FetchResource $request) { $result = $this->doRead($store, $request); if ($this->isResponse($result)) { return $result; } return $this->reply()->content($result); }
Read resource action. @param StoreInterface $store @param FetchResource $request @return Response
read
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