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)

No description

static Method
generateDeleteAllMethod(ModelCollection $modelCollection)

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

static Method
generateDeleteMethod(ModelCollection $modelCollection)

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)

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

static Method
generateUpdateMethod(ModelCollection $modelCollection, array|null $updatableProperties = 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($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 34
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 354
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 377
static Method generateCreateMethod(Model $model, array|null $editableProperties = null)

No description

Parameters

Model $model
array|null $editableProperties

Return Value

Method

at line 589
static Method generateDeleteAllMethod(ModelCollection $modelCollection)

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

Parameters

ModelCollection $modelCollection

Return Value

Method

at line 525
static Method generateDeleteMethod(ModelCollection $modelCollection)

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

Parameters

ModelCollection $modelCollection

Return Value

Method

at line 214
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 279
static Method generateReadMethod(ModelCollection $modelCollection, array|null $exposedProperties = null)

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

Parameters

ModelCollection $modelCollection
array|null $exposedProperties

Return Value

Method

at line 450
static Method generateUpdateMethod(ModelCollection $modelCollection, array|null $updatableProperties = null)

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

Parameters

ModelCollection $modelCollection
array|null $updatableProperties

Return Value

Method

at line 146
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 161
static protected array|float|int|string|null sanitizeInputByType($input, string $schemaType)

Cleans/Sanitizes value based in the datatype in the schemaType

Parameters

$input
string $schemaType

database schema data type of value

Return Value

array|float|int|string|null

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

Translates between webservice and database types

Parameters

string $dbType

Return Value

string