phramework / jsonapi

jsonapi implementation for phramework
https://phramework.github.io/jsonapi/
Apache License 2.0
4 stars 2 forks source link

isA proposal #37

Open nohponex opened 8 years ago

nohponex commented 8 years ago

Each resource model should define a method bool isA(string $class, string $id, $resourceObject = null) also each resource model should define zero or more classes

<?php
const CLASSES = [
    'ADMINISTRATOR',
    'MODERATOR'
];

literal values of the classes can be constants

In this way we can have a standard method to check the definitions and the criteria for each resource's classes (and/or states).

The resource model is responsible to implement isA method in order to return true or false for each of the available classes.

Examples:

<?php
$isAdministrator = User::isA('ADMINISTRATOR', $user->id);

$isNotAdministrator = !User::isA('ADMINISTRATOR', $user->id, $user);

//if $resourceObject argument is available and provided we can eliminate call to resource model's `getById` method,
//isA` may require to make additional calls (meta etc) to fetch all required data to reach a decision about a certain class.
nohponex commented 8 years ago

An alternative name may be better, "CLASSES" is confusing

tchronis commented 8 years ago

How about ENTITY ?

nohponex commented 8 years ago

How about ENTITY ?

We need something that shows that some resources of that type share common properties, i.e. the form a group or a class.

I would prefer class but it's confusing for the developers since we are working with OOP