public function trigger($event, array $args = [], $method = null) { $eventName = $this->getEventName($event); $handlers = array_merge(isset($this->events[$eventName]) ? $this->events[$eventName]->getEventHandlers() : [], isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : []); $this->triggers[$eventName] = isset($this->triggers[$eventName]) ? $this->triggers[$eventName] + 1 : 1; if (!$handlers) { return null; } /** * Handlers are not chained anymore. * They are interrupted only if handler returns false. */ foreach ($handlers as $handler) { if (is_string($handler)) { $handler = Reflect::create($handler, $args); } if (is_callable($handler)) { Reflect::call($handler, $args); } else { if (is_object($handler)) { Reflect::method($handler, 'handle', $args); } } } return $this; }
public function allPermissions(callable $callable = null) { $permissionTable = $this->getPermissionableTable(); $repository = $this->getRepository(); $relation = $this->hasMany((new Entity($repository))->setTable($permissionTable))->foreignKey('id')->fill('allPermissions')->addSelect(['`' . $permissionTable . '`.*']); if ($callable) { $query = $relation->getRightEntity()->getQuery(); Reflect::call($callable, [$query, $relation, $this]); } return $relation; }
/** * */ public function registerExceptionHandler() { $whoops = new Run(); $whoops->pushHandler(function ($exception) { $whitelist = config('rollbar.whitelist'); if (config('rollbar.access_token') && Reflect::call($whitelist)) { Rollbar::init(['access_token' => config('rollbar.access_token'), 'report_suppressed' => config('rollbar.report_suppressed', true)]); Rollbar::report_exception($exception); } $this->handleException($exception); }); $whoops->register(); }
/** * @param $table * @param null $on * @param null $where * * @return $this */ public function join($table, $on = null, $where = null) { if ($table instanceof Relation) { if (is_callable($on)) { /** * Is this needed? */ Reflect::call($on, [$table, $table->getQuery()]); } $table->mergeToQuery($this->getQuery()); } else { $this->getQuery()->join($table, $on, $where); } return $this; }
/** * */ public function with($relation, $callback = null) { if ($relation == $this) { return $this; } if (is_callable($callback)) { Reflect::call($callback, [$relation, $relation->getQuery()]); } if ($relation instanceof Relation) { $this->with[] = $relation; } else { $this->with[] = $this->{$relation}(); } return $this; }
public function reflect(callable $callable, $entity, $query = null) { Reflect::call($callable, [$query ?? $this->getQuery(), $this, $entity]); }
/** * @return mixed */ public function translationsFallback(callable $callable = null) { $translaTable = $this->getTable() . $this->getTranslatableTableSuffix; $repository = $this->getRepository(); $relation = $this->hasMany((new Entity($repository))->setTable($translaTable)->setAlias($translaTable . '_f'))->foreignKey('id')->fill('_translations')->addSelect(['`' . $translaTable . '`.*'])->leftJoin(); if ($callable) { $query = $relation->getRightEntity()->getQuery(); Reflect::call($callable, [$query, $relation, $this]); $this->addTranslatableFallbackConditionIfNot($relation); } else { $this->addTranslatableFallbackCondition($relation); } return $relation; }