class ModelCRUD

Helper class to define webservice methods.

Constants

DEFAULT_EXCLUDE_PROPERTIES

WRITE_EXCLUDE_PROPERTIES

Methods

static array
create(Model $model, array $functions)

Creates a generic CRUD interface for a Model

static Method
generateCountMethod(ModelCollection $modelCollection)

Wrapper for "count_all" - this will NOT apply any read/write checks

static Method
generateCreateMethod(Model $model, array|null $editableProperties = null, bool|null $uuidIdentifaction = null)

No description

static Method
generateDeleteAllMethod(ModelCollection $modelCollection)

Will delete all models in batch. Does NOT perform access check

static Method
generateDeleteMethod(ModelCollection $modelCollection, bool|null $uuidIdentifaction = null)

Wrapper for $model->delete() - will perform can_write check

static Method
generateReadAllMethod(ModelCollection $modelCollection, array|null $exposedProperties = null, array|null $scopedProperties = null)

Wrapper for "$modelCollection->all()" will not perform rights checks, you can pass a scoped collection which implies your rights

static Method
generateReadMethod(ModelCollection $modelCollection, array|null $exposedProperties = null, bool|null $uuidIdentifaction = null)

Wrapper for "model->find_all_by_id()" - Will perform can_read() Check

static ModelMethod
generateUpdateMethod(ModelCollection $modelCollection, array|null $updatableProperties = null, bool|null $uuidIdentifaction = null)

Wrapper for Model Update, will check can_write() before update

static array
sanitizeInputArrayByType(array $inputData, array $schema)

Cleans/Sanitizes $value based in the datatype in the schema definition

static array|float|int|string|null
sanitizeInputByType(mixed $input, string $schemaType)

Cleans/Sanitizes value based in the datatype in the schemaType

static string
translatePropertyType(string $dbType)

Translates between webservice and database types

Details

at line 37
static array create(Model $model, array $functions)

Creates a generic CRUD interface for a Model

Parameters

Model $model
array $functions

= ['create'=>[model property names], 'read'=>[model property names], 'read_all'=>[model property names], 'update'=> [model property names], 'delete'=>true, 'delete_all'=>true, 'count'=>true] for create, update, read and read_all an array which defines properties to be exposed for delete, delete_all and count just true or false waehter models can be deleted via primary key ALL functions are set to false by default, only set functions you want to expose

Return Value

array

array with the CRUD functions for the model

at line 391
static Method generateCountMethod(ModelCollection $modelCollection)

Wrapper for "count_all" - this will NOT apply any read/write checks

Parameters

ModelCollection $modelCollection

Return Value

Method

at line 413
static Method generateCreateMethod(Model $model, array|null $editableProperties = null, bool|null $uuidIdentifaction = null)

No description

Parameters

Model $model
array|null $editableProperties
bool|null $uuidIdentifaction

Return Value

Method

at line 692
static Method generateDeleteAllMethod(ModelCollection $modelCollection)

Will delete all models in batch. Does NOT perform access check

Parameters

ModelCollection $modelCollection

Return Value

Method

at line 611
static Method generateDeleteMethod(ModelCollection $modelCollection, bool|null $uuidIdentifaction = null)

Wrapper for $model->delete() - will perform can_write check

Parameters

ModelCollection $modelCollection
bool|null $uuidIdentifaction

Return Value

Method

at line 235
static Method generateReadAllMethod(ModelCollection $modelCollection, array|null $exposedProperties = null, array|null $scopedProperties = null)

Wrapper for "$modelCollection->all()" will not perform rights checks, you can pass a scoped collection which implies your rights

Parameters

ModelCollection $modelCollection
array|null $exposedProperties
array|null $scopedProperties

Return Value

Method

at line 300
static Method generateReadMethod(ModelCollection $modelCollection, array|null $exposedProperties = null, bool|null $uuidIdentifaction = null)

Wrapper for "model->find_all_by_id()" - Will perform can_read() Check

Parameters

ModelCollection $modelCollection
array|null $exposedProperties
bool|null $uuidIdentifaction

Null = Available/BackwardsCompatible, True = Only UUID, False = No UUID

Return Value

Method

at line 502
static ModelMethod generateUpdateMethod(ModelCollection $modelCollection, array|null $updatableProperties = null, bool|null $uuidIdentifaction = null)

Wrapper for Model Update, will check can_write() before update

Parameters

ModelCollection $modelCollection
array|null $updatableProperties
bool|null $uuidIdentifaction

Return Value

ModelMethod

at line 149
static protected array sanitizeInputArrayByType(array $inputData, array $schema)

Cleans/Sanitizes $value based in the datatype in the schema definition

Parameters

array $inputData
array $schema

Return Value

array

at line 168
static protected array|float|int|string|null sanitizeInputByType(mixed $input, string $schemaType)

Cleans/Sanitizes value based in the datatype in the schemaType

Parameters

mixed $input
string $schemaType

database schema data type of value

Return Value

array|float|int|string|null

at line 108
static protected string translatePropertyType(string $dbType)

Translates between webservice and database types

Parameters

string $dbType

Return Value

string