ReadOnlyTraitLaravel/src/ReadOnlyTrait.php

185 lines
4.6 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 {
/**
* throws ReadOnlyException on create
* @method create
* @param array $attributes
*
*/
static function create(array $attributes = []){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
}
/**
* throws ReadOnlyException on forceCreate
* @method forceCreate
* @param array $attributes
*
*/
static function forceCreate(array $attributes){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
}
/**
* throws ReadOnlyException on save
* @method save
* @param array $options
*
*/
2016-03-28 11:15:08 -07:00
public function save(array $options = []){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$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 = []){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$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){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$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){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$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(){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$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){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$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(){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$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(){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$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(){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$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(){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$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){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$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 = []){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$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(){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
2016-12-09 06:37:13 -08:00
}
/**
* throws ReadOnlyException on insert
* @method insert
*
*/
public function insert(){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
}
/**
* throws ReadOnlyException on truncate
* @method truncate
*
*/
public function truncate(){
$class = get_called_class();
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
}
2016-03-28 11:15:08 -07:00
}