From 5275c5a5925bc5e14a47002d06dc494c7da50e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Plusquellec?= Date: Wed, 14 Jun 2017 11:27:49 +0200 Subject: [PATCH] corrections --- lib/octal.php | 88 ++----------------------------------------------- lib/octalia.php | 36 ++++++++------------ 2 files changed, 15 insertions(+), 109 deletions(-) diff --git a/lib/octal.php b/lib/octal.php index f9b6c73..b8a1c50 100644 --- a/lib/octal.php +++ b/lib/octal.php @@ -143,94 +143,10 @@ public function setEntityField($field) * deleted * get * count + * query + * fetch * make_model */ - public function on($event, callable $callable) - { - return $this->orm()->on($event, $callable, $this); - } - - public function hook(callable $callable) - { - return call_user_func_array($callable, [$this->orm()]); - } - - public static function makeModel(callable $callable) - { - $instance = maker(get_called_class(), [], false); - - return $instance->orm()->on('make_model', $callable, $instance); - } - - public static function booting(callable $callable) - { - $instance = maker(get_called_class(), [], false); - - return $instance->orm()->on('booting', $callable, $instance); - } - - public static function booted(callable $callable) - { - $instance = maker(get_called_class(), [], false); - - return $instance->orm()->on('booted', $callable, $instance); - } - - public static function saving(callable $callable) - { - $instance = maker(get_called_class(), [], false); - - return $instance->orm()->on('saving', $callable, $instance); - } - - public static function saved(callable $callable) - { - $instance = maker(get_called_class(), [], false); - - return $instance->orm()->on('saved', $callable, $instance); - } - - public static function creating(callable $callable) - { - $instance = maker(get_called_class(), [], false); - - return $instance->orm()->on('creating', $callable, $instance); - } - - public static function created(callable $callable) - { - $instance = maker(get_called_class(), [], false); - - return $instance->orm()->on('created', $callable, $instance); - } - - public static function updating(callable $callable) - { - $instance = maker(get_called_class(), [], false); - - return $instance->orm()->on('updating', $callable, $instance); - } - - public static function updated(callable $callable) - { - $instance = maker(get_called_class(), [], false); - - return $instance->orm()->on('updated', $callable, $instance); - } - - public static function deleting(callable $callable) - { - $instance = maker(get_called_class(), [], false); - - return $instance->orm()->on('deleting', $callable, $instance); - } - - public static function deleted(callable $callable) - { - $instance = maker(get_called_class(), [], false); - - return $instance->orm()->on('deleted', $callable, $instance); - } public static function __callStatic($m, $a) { diff --git a/lib/octalia.php b/lib/octalia.php index e6489ff..4ea4668 100644 --- a/lib/octalia.php +++ b/lib/octalia.php @@ -366,7 +366,9 @@ public function store($data = []) { $data = is_object($data) ? $data->toArray() : $data; - return $this->model($data)->save(); + $row = $this->model($data)->save(); + + return $row; } public function persist($data) @@ -411,7 +413,9 @@ public function save($data, $model = true) $this->reset(); - if ($data = $this->fire('saving', $data, true) === false) return false; + $data = $this->fire('saving', $data, true); + + if ($data === false) return false; $id = isAke($data, 'id', null); @@ -433,7 +437,9 @@ public function save($data, $model = true) private function insert(array $data, $model = true) { - if ($data = $this->fire('creating', $data, true) === false) return false; + $data = $this->fire('creating', $data, true); + + if ($data === false) return false; $this->add($data, false); @@ -442,7 +448,9 @@ private function insert(array $data, $model = true) private function modify(array $data, $model = true) { - if ($data = $this->fire('updating', $data, true) === false) return false; + $data = $this->fire('updating', $data, true); + + if ($data === false) return false; $data['updated_at'] = time(); @@ -797,6 +805,7 @@ public function model($row = []) } $class = '\\Octo\\' . $class; + $model = new $class($row); $self = $this; @@ -3262,14 +3271,11 @@ public function fire($event, $concern = null, $return = false) { $entity = actual("entity.{$this->db}.{$this->table}"); - $continue = true; - if (is_object($entity)) { $methods = get_class_methods($entity); $method = 'event' . Strings::camelize($event); if (in_array($method, $methods)) { - $continue = false; $result = $entity->$method($concern, $this); if ($return) { @@ -3278,22 +3284,6 @@ public function fire($event, $concern = null, $return = false) } } - if (!$continue) { - return $concern; - } - - $key = 'octalia.' . - lcfirst(Strings::camelize($this->db . '_' . $this->table)) - . '.' . $event; - - if (Fly::has($key)) { - $result = Fly::listen($key, $concern, $this); - - if ($return) { - return $result; - } - } - return $concern; }