phramework/jsonapi doc
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo

Namespaces

  • Phramework
    • JSONAPI
      • Controller
        • POST
      • Model
      • Viewers

Classes

  • Controller
  • Fields
  • Filter
  • FilterAttribute
  • FilterJSONAttribute
  • Model
  • Page
  • Relationship
  • RelationshipResource
  • Resource
  • Sort
  • Util
  • ValidationModel

Class Relationship

JSONAPI relationship class

Namespace: Phramework\JSONAPI
License: Apache-2.0
Author: Xenofon Spafaridis nohponex@gmail.com
Since: 0.0.0
Located at Relationship.php

Methods summary

public
# __construct( string $modelClass, integer $type = Relationship::TYPE_TO_ONE, string|null $recordDataAttribute = null, callable|object|null $callbacks = null, integer $flags = Relationship::FLAG_DEFAULT )

Parameters

$modelClass
Class path of relationship resource model
$type
*[Optional] Relationship type
$recordDataAttribute
*[Optional] Attribute name in record containing relationship data
$callbacks

*[Optional] Callable method can be used to fetch relationship data, see TODO

$flags
*[Optional] Relationship flags

Throws

Exception
When modelClass doesn't extend Phramework\JSONAPI\Model
Exception
When is not null, callable or object of callables

Example

getValidationModel() {
    return (object) [
        'author' => new Relationship(
            Tag::class,
            Relationship::TYPE_TO_ONE,
            'author-user_id'
        );
    ];
}

getValidationModel() {
    return (object) [
        'tag' => new Relationship(
            Tag::class,
            Relationship::TYPE_TO_MANY,
            null,
            [Tag::class, 'getRelationshipByArticle']
        );
    ];
}

getValidationModel() {
    return (object) [
        'tag' => new Relationship(
            Tag::class,
            Relationship::TYPE_TO_MANY,
            null,
            (object) [
                 'GET'  => [Tag::class, 'getRelationshipByArticle'],
                 'POST' => [Tag::class, 'postRelationshipByArticle']
            ]
        );
    ];
}

public mixed
# __get( string $name )

Parameters

$name

Returns

mixed

Throws

Exception
public
# __set( string $name, $value )

Parameters

$name
$value

Returns


$this

Throws

Exception

Constants summary

integer FLAG_DEFAULT
# 0
integer FLAG_ATTRIBUTES

Deprecated

because relationships should not have attributes
# 1
integer FLAG_DATA
# 2
integer FLAG_INCLUDE_BY_DEFAULT

Include relationship by default

Include relationship by default

# 32
integer TYPE_TO_ONE

Relationship type to one resource.

Relationship type to one resource.

# 1
integer TYPE_TO_MANY

Relationship type to zero, one or more resources.

Relationship type to zero, one or more resources.

# 2

Properties summary

protected string $modelClass

Class path of relationship resource model

Class path of relationship resource model

#
protected integer $type

The type of relationship from the resource to relationship resource

The type of relationship from the resource to relationship resource

#
protected string|null $recordDataAttribute

Attribute name in record containing relationship data

Attribute name in record containing relationship data

#
protected object $callbacks

Callable method can be used to fetch relationship data, see TODO

Callable method can be used to fetch relationship data, see TODO

#
protected integer $flags

Relationship flags

Relationship flags

#

Magic properties

public read-only string $modelClass
public read-only integer $type
public read-only string|null $recordDataAttribute
public read-only object $callbacks
public read-only integer $flags
phramework/jsonapi doc API documentation generated by ApiGen