Skip to content

Commit

Permalink
corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
schpill committed Jun 14, 2017
1 parent 555c609 commit 5275c5a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 109 deletions.
88 changes: 2 additions & 86 deletions lib/octal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
36 changes: 13 additions & 23 deletions lib/octalia.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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();

Expand Down Expand Up @@ -797,6 +805,7 @@ public function model($row = [])
}

$class = '\\Octo\\' . $class;

$model = new $class($row);
$self = $this;

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down

0 comments on commit 5275c5a

Please sign in to comment.