Download the PHP package kwai/jsonapi without Composer
On this page you can find all versions of the php package kwai/jsonapi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package jsonapi
kwai-jsonapi
A JSON:API serializer for PHP classes using PHP attributes.
Currently, this library has no support for links.
Installation
`
Requirements
PHP attributes are used to serialize a PHP class to a JSONAPI resource. So, the PHP version must be at least 8.0. There are no other external dependencies.
Documentation
[JSONAPI/Resource]
The "JSONAPI/Resource" attribute is used to set the type of the resource.
- The type argument is required.
- This attribute can only be applied to a class.
- By default, the id is retrieved from the id property. Use the id argument to use a method or a property with another name.
``
[JSONAPI/Attribute]
The "JSONAPI/Attribute" attribute is used to set an attribute of a resource.
- This attribute can be applied to a property or a method of a class.
- The name argument can be used to give a name to the property.
- When applied to a method, the name argument is required.
`` Properties may be private. A method must be public.
With a Person instance like this:
`` The result will be:
`
[JSONAPI/Relationship]
The "JSONAPI/Relationship" is used to map a relationship.
- This attribute can be applied to a property or a method.
- The name argument can be used to give a name to the relationship.
- When no name argument is set for a property, the name of the property will be used.
- When applied to a method, the name argument is required.
`` Properties may be private. A method must be public.
The linked resource must contain a JSONAPI\Resource attribute. If not, a JSONAPI\Exception will be thrown. A relationship can also be an array.
With the given PHP code:
``
The result of the serializing will be:
`
Serializing
The JSONAPI\Document class is used to serialize an object or an array to a JSON:API structure.
``
Meta
Meta information can be set with the setMeta method.
``