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