protected function hasOrDie($theme) { if (false === $this->has($theme)) { throw CodexException::because("Theme [{$theme}] does not exist"); } return $this; }
protected function query($query) { try { $data = $this->codex->get($query); } catch (Exception $e) { throw $e; } if ($data === null) { throw CodexException::because("Query '{$query}' has no valid result"); } return $data; }
/** * @param null $ext * * @return mixed|\Codex\Codex * @throws \Codex\Exception\CodexException */ function codex($ext = null) { if (!app()->bound('codex')) { //|| !app()->hasBeenBootstrapped()){ throw \Codex\Exception\CodexException::because('Codex is not bound yet'); } /** @var mixed $codex */ $codex = app('codex'); if ($ext === null) { return $codex; } return $codex->{$ext}; }
/** * Defines a point where hooks can hook * * @param string $event The hook name * @param array $args (optional) The arguments to pass along * @param bool $halt (optional) If this hook can halt * * @return array|null */ protected function hookPoint($event, array $args = [], $halt = true) { if (config('codex.dev.enabled', false) === true) { if (array_key_exists($event, static::$hookPoints)) { throw CodexException::because('hook point already exists'); } Arr::add(static::$hooks, $event, static::getDispatcher()->getListeners($event)); $caller = $this->hookPointGetCaller(debug_backtrace(), 1); $caller = array_only($caller, ['function', 'class']); Arr::set(static::$hookPoints, static::getEventName($event), $caller); } return $this->fireEvent($event, $args, $halt); }
public function getVersion() { if ($this->isVersion() === false) { throw CodexException::because("Can not getVersion for Ref {$this->project}/{$this}. The Ref is not a semver. Check by using isVersion() first."); } return $this->version; }
public function setCacheMode($mode) { if ($mode === true) { $mode = self::CACHE_ENABLED; } elseif ($mode === false) { $mode = self::CACHE_DISABLED; } elseif ($mode === null) { $mode = self::CACHE_AUTO; } if (!in_array($mode, [self::CACHE_ENABLED, self::CACHE_DISABLED, self::CACHE_AUTO], true)) { throw CodexException::because('Cache mode not supported: ' . (string) $mode); } $this->mode = $mode; }
public function getSorted($names) { $all = $this->whereIn('name', $names)->sortBy('priority')->replaceProcessors(); $all->each(function ($processor) use($all) { /** @var Processor $annotation */ $annotation = $processor['annotation']; foreach ($annotation->before as $before) { $otherProcessor = $all->where('name', $before)->first(); if ($otherProcessor !== null && false === in_array($annotation->name, $otherProcessor['after'], true)) { $otherProcessor['after'][] = $annotation->name; $all->set($before, $otherProcessor); } } }); $sorter = new Sorter(); foreach ($all as $item) { $sorter->addItem($item['name'], $item['after']); } $sorted = $sorter->sort(); if (count($sorter->getMissing()) > 0) { if (static::$handleMissing === self::MISSING_IGNORED) { } elseif (static::$handleMissing === self::MISSING_THROWS_EXECEPTION) { $dep = array_keys($sorter->getMissing()); $dep = implode(', ', $dep); throw CodexException::because("Sorter encountered a missing dependency for {$dep}"); } } $sorted = array_merge($sorted, array_diff($names, $sorted)); return $sorted; }
public function run() { if ($this->canRun()) { $content = $this->document->getContent(); $this->parseArguments(); $arguments = array_merge([$this->isClosing()], $this->arguments); $result = call_user_func_array($this->getCallable(), $arguments); $content = preg_replace('/' . preg_quote($this->raw, '/') . '/', $result, $content, 1); $this->document->setContent($content); } else { throw CodexException::because("Macro [{$this->cleaned}] cannot call because some properties havent been set. Prevent the Macro from running by using the canRun() method."); } }