public function __construct(Application $app) { $app->getAppInfo()->clearCache(); $app->cache = $app->config = []; $app->collectorList = null; $app->getBootstrapInstance()->bootstrap($app); }
/** * Returns the active database connection * * @return \Opis\Database\Connection */ public static function getConnection() { if (static::$connection === null) { return static::$app->connection(); } return static::$app->collect('Connections')->get(static::$connection); }
public function uninstall(Application $app) { $schema = $app->schema(); $schema->drop('role_permissions'); $schema->drop('user_roles'); $schema->drop('permissions'); $schema->drop('users'); $schema->drop('roles'); }
/** * Validate a CSRF token * * @param string $value Token * * @return boolean */ public function validate($value) { $tokens = $this->app->session()->get($this->sessionKey, array()); $key = array_search($value, $tokens); if ($key !== false) { unset($tokens[$key]); $this->app->session()->set($this->sessionKey, $tokens); return true; } return false; }
/** * Constructor * * @param \Opis\Colibri\Application $app */ public function __construct(Application $app) { $this->app = $app; $specials = array('app' => $app, 'request' => $app->request(), 'response' => $app->response(), 't' => $app->getTranslator(), 'lang' => $app->getTranslator()->getLanguage(), 'view' => $app->getViewRouter()); parent::__construct($app->collect('Routes'), $app->collect('Dispatchers'), null, $specials); $this->getRouteCollection()->notFound(function ($path) use($app) { return new NotFound($app->view('error.404', array('path' => $path))); })->accessDenied(function ($path) use($app) { return new AccessDenied($app->view('error.403', array('path' => $path))); }); $this->getRouteCollection()->setRouter($this); }
/** * Translate a sentence * * @param string $sentence * @param array $placeholders (optional) * @param string|null $lang (optional) * * @return string */ public function translate($sentence, $placeholders = array(), $lang = null) { if ($lang === null) { $lang = $this->language; } if (!isset($this->translations[$lang])) { $this->translations[$lang] = $this->app->translations()->read($lang, array()); } $translation =& $this->translations[$lang]; if (isset($translation[$sentence])) { $sentence = $translation[$sentence]; } return $this->placeholder->replace($sentence, $placeholders); }
/** * Route path * * @param \Opis\HttpRouting\Path $path * * @return mixed */ public function route(BasePath $path) { $router = new AliasRouter($this->app->collect('RouteAliases')); $alias = $router->route(new AliasPath($path->path())); if ($alias !== null) { $path = new Path((string) $alias, $path->domain(), $path->method(), $path->isSecure(), $path->request()); } $this->path = $path; $result = parent::route($path); $response = $path->request()->response(); $response->body($result); $response->send(); return $result; }
/** * Get a list of commands * * @return array */ public function commands() { $commands = array(); $list = $this->app->collect('Commands')->getList(); foreach ($list as $name => $builder) { try { $command = call_user_func_array($builder, array()); if ($command instanceof Command) { $command->setApp($this->app); $commands[$name] = $command; } } catch (Excepion $e) { } } return $commands; }
/** * @return Application */ function app() : Application { static $app; if ($app === null) { $app = Application::getInstance(); } return $app; }
/** * Collect items * * @param string $type * * @return @return \Opis\Colibri\Collectors\AbstractCollector * * @throws \Exception */ public function collect($type) { if (null === $this->app->config()->read("collectors.{$type}")) { throw new \Exception('Unknown collector type "' . $type . '"'); } $collector = $this->container()->make($type, array($this->app)); return $this->dispatch(new CollectorEntry($type, $collector)); }
/** * Unregister module's assets * * @param string $module * * @return boolean */ public function unregisterAssets($module) { $module = $this->toModuleId($module); if ($this->isEnabled($module)) { return false; } $path = $this->app->info()->assetsPath() . '/module/' . $module; if (!file_exists($path) || !is_link($path)) { return false; } return unlink($path); }
/** * Stringify * * @return string */ public function __toString() { if ($this->renderedContent === null) { try { $this->renderedContent = $this->app->render($this); if (!is_string($this->renderedContent)) { $this->renderedContent = (string) $this->renderedContent; } } catch (Exception $e) { $this->renderedContent = (string) $e; } } return $this->renderedContent; }
/** * Generates a CSRF token * * @return string */ public function csrfToken() { return $this->app->csrfToken(); }
public function __construct() { $this->instances[Application::class] = Application::getInstance(); }
/** * Uninstall the module * * @return boolean */ public function uninstall() { return $this->app->getModuleManager()->uninstall($this->module); }
/** * Constructor * * @param \Opis\Colibri\Application $app */ public function __construct(Application $app) { $this->app = $app; parent::__construct($app->collect('Validators')->getList()); }
/** * Validator's callback * * @param string $token * @return boolean */ protected function validateCsrf($token) { return $this->app->csrfValidate($token); }
* * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================ */ use Opis\Colibri\Application; use Whoops\Run as WhoopsRun; use Whoops\Handler\JsonResponseHandler; use Whoops\Handler\PrettyPageHandler; use Whoops\Handler\PlainTextHandler; use Whoops\Util\Misc; error_reporting(-1); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); ini_set('opcache.enable', 0); $loader = (require_once 'vendor/autoload.php'); if (getenv('APP_PRODUCTION') === false) { $whoops = new WhoopsRun(); if (Misc::isCommandLine()) { $whoops->pushHandler(new PlainTextHandler()); } elseif (Misc::isAjaxRequest()) { $whoops->pushHandler(new JsonResponseHandler()); } else { $whoops->pushHandler(new PrettyPageHandler()); } $whoops->register(); } $app = new Application(__DIR__, $loader); return $app->bootstrap();
/** * Constructor * * @param \Opis\Colibri\Application $app */ public function __construct(Application $app) { $this->app = $this->param = $app; parent::__construct($app->collect('Views'), $app->collect('ViewEngines')); }
public function disable(Application $app) { $app->getCollectorManager()->unregisterCollector('permissions'); }