ReadOnlyTraitLaravel/src/ReadOnlyTrait.php

173 lines
3.4 KiB
PHP
Raw Normal View History

2016-03-28 11:15:08 -07:00
<?php
namespace MichaelAChrisco\ReadOnly;
use Illuminate\Database\Eloquent\Builder;
use MichaelAChrisco\ReadOnly\ReadOnlyException;
2016-03-28 11:15:08 -07:00
trait ReadOnlyTrait {
static function readOnly($class){
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
}
/**
* throws ReadOnlyException on create
* @method create
* @param array $attributes
*
*/
static function create(array $attributes = []){
ReadOnlyTrait::readOnly(get_called_class());
}
/**
* throws ReadOnlyException on forceCreate
* @method forceCreate
* @param array $attributes
*
*/
static function forceCreate(array $attributes){
ReadOnlyTrait::readOnly(get_called_class());
}
/**
* throws ReadOnlyException on save
* @method save
* @param array $options
*
*/
2016-03-28 11:15:08 -07:00
public function save(array $options = []){
ReadOnlyTrait::readOnly(get_called_class());
2016-03-28 11:15:08 -07:00
}
/**
* throws ReadOnlyException on update
* @method update
* @param [type] $attributes
* @param $options
*
*/
2016-03-28 11:15:08 -07:00
public function update(array $attributes = [], array $options = []){
ReadOnlyTrait::readOnly(get_called_class());
2016-03-28 11:15:08 -07:00
}
/**
* throws ReadOnlyException on firstOrCreate
* @method firstOrCreate
* @param array $arr
*
*/
2016-03-28 11:15:08 -07:00
static function firstOrCreate(array $arr){
ReadOnlyTrait::readOnly(get_called_class());
2016-03-28 11:15:08 -07:00
}
/**
* throws ReadOnlyException on firstOrNew
* @method firstOrNew
* @param array $arr
*
*/
2016-03-28 11:15:08 -07:00
static function firstOrNew(array $arr){
ReadOnlyTrait::readOnly(get_called_class());
2016-03-28 11:15:08 -07:00
}
/**
* throws ReadOnlyException on delete
* @method delete
*
*/
2016-03-28 11:15:08 -07:00
public function delete(){
ReadOnlyTrait::readOnly(get_called_class());
2016-03-28 11:15:08 -07:00
}
/**
* throws ReadOnlyException on destroy
* @method destroy
* @param mixed $ids
*
*/
2016-03-28 11:15:08 -07:00
static function destroy($ids){
ReadOnlyTrait::readOnly(get_called_class());
2016-03-28 11:15:08 -07:00
}
/**
* throws ReadOnlyException on restore
* @method restore
*
*/
2016-03-28 11:15:08 -07:00
public function restore(){
ReadOnlyTrait::readOnly(get_called_class());
2016-03-28 11:15:08 -07:00
}
/**
* throws ReadOnlyException on forceDelete
* @method forceDelete
*
*/
2016-03-28 11:15:08 -07:00
public function forceDelete(){
ReadOnlyTrait::readOnly(get_called_class());
2016-03-28 11:15:08 -07:00
}
2016-12-09 06:37:13 -08:00
/**
* throws ReadOnlyException on performDeleteOnModel
2016-12-09 06:37:13 -08:00
* @method performDeleteOnModel
*
2016-12-09 06:37:13 -08:00
*/
public function performDeleteOnModel(){
ReadOnlyTrait::readOnly(get_called_class());
2016-12-09 06:37:13 -08:00
}
/**
* throws ReadOnlyException on push
2016-12-09 06:37:13 -08:00
* @method push
*
2016-12-09 06:37:13 -08:00
*/
public function push(){
ReadOnlyTrait::readOnly(get_called_class());
2016-12-09 06:37:13 -08:00
}
/**
* throws ReadOnlyException on finishSave
2016-12-09 06:37:13 -08:00
* @method finishSave
*
2016-12-09 06:37:13 -08:00
*/
public function finishSave(array $options){
ReadOnlyTrait::readOnly(get_called_class());
2016-12-09 06:37:13 -08:00
}
/**
* throws ReadOnlyException on performUpdate
2016-12-09 06:37:13 -08:00
* @method performUpdate
*
2016-12-09 06:37:13 -08:00
*/
public function performUpdate(Builder $query, array $options = []){
ReadOnlyTrait::readOnly(get_called_class());
2016-12-09 06:37:13 -08:00
}
/**
* throws ReadOnlyException on touch
2016-12-09 06:37:13 -08:00
* @method touch
*
2016-12-09 06:37:13 -08:00
*/
public function touch(){
ReadOnlyTrait::readOnly(get_called_class());
2016-12-09 06:37:13 -08:00
}
/**
* throws ReadOnlyException on insert
* @method insert
*
*/
public function insert(){
ReadOnlyTrait::readOnly(get_called_class());
}
/**
* throws ReadOnlyException on truncate
* @method truncate
*
*/
public function truncate(){
ReadOnlyTrait::readOnly(get_called_class());
}
2016-03-28 11:15:08 -07:00
}