/** * Constructor * * @param Norm\Cursor $entries Entries that we want to page */ public function __construct(Cursor $entries) { $this->entries = $entries; $this->app = App::getInstance(); $configCollection = $this->app->config('norm.collections'); if (isset($configCollection['default'])) { if (isset($configCollection['default']['limit'])) { $this->limit = $configCollection['default']['limit']; } } $this->baseUrl = URL::current(); }
/** * Initialize the provider * * @return void */ public function initialize() { // Get current machine hostname $this->hostname = $hostname = gethostname(); // Bind the Application instance to our class property $this->app = $app = App::getInstance(); // Bind the configuration path to our class property $this->configPath = realpath($app->config('config.path')); // Get the current mode of application, and bind it to our class property $this->mode = $app->config('mode'); // Override mode configuration $this->mergeModeConfig(); // Determine if there's array contain local machine name in 'local' array key of the options given if (isset($this->options['local'])) { foreach ($this->options['local'] as $host) { if ($host === $hostname) { $this->env = 'local'; $this->mergeEnvConfig(); break; } } } // Determine if there's array contain remote machine name in 'remote' array key of the options given if (is_null($this->env) and isset($this->options['remote'])) { foreach ($this->options['remote'] as $host) { if ($host === $hostname) { $this->env = 'remote'; $this->mergeEnvConfig(); break; } } } // Let's merge our own unique configuration based on our hostname $this->mergeHostConfig(); }
/** * [fetch description] * * @param [type] $template [description] * * @return [type] [description] */ public function fetch($template) { $app = App::getInstance(); if (empty($template)) { return $this->data['body']; } else { if ($app->theme) { $template = $app->theme->resolve($template, $this) ?: $template; } $html = parent::fetch($template); $layoutTemplate = null; if ($this->layout) { if ($app->theme) { $layoutTemplate = $app->theme->resolve($this->layout, $this->layoutView); } else { $layoutTemplate = $this->layout; } } if ($layoutTemplate) { $this->layoutView->replace($this->all()); $this->layoutView->set('body', $html); return $this->layoutView->render($layoutTemplate); } else { return $html; } } }
public function authenticate(array $options = array()) { $app = App::getInstance(); try { if (!empty($_GET['error'])) { throw new Exception($_GET['error']); } if (empty($_GET['code'])) { $url = \URL::create($this->options['authUrl'], array('response_type' => 'code', 'client_id' => $this->options['clientId'], 'redirect_uri' => $this->options['redirectUri'], 'scope' => @$this->options['scope'], 'state' => ''), $this->options['baseUrl']); return \App::getInstance()->redirect($url); } else { if (empty($_GET['keep'])) { $app->session->reset(); } else { $app->session->reset(array('lifetime' => 365 * 24 * 60 * 60)); } $this->exchangeCodeForToken($_GET['code']); $me = $this->fetchRemoteUser(); $user = $this->authenticateRemoteUser($me); $_SESSION['user'] = $user; return $user; } } catch (Stop $e) { return; } catch (Exception $e) { if ($e instanceof \Norm\Filter\FilterException) { $error = 'Caught filter error! Please contact Administrator'; } else { $error = $e->getMessage(); } $url = \URL::create($this->options['unauthorizedUri'], array('error' => $error)); return \App::getInstance()->redirect($url); } }
public function __construct($clazz, $config = NULL) { $this->app = \Bono\App::getInstance(); $this->clazz = $clazz; $collection = \Norm\Norm::factory($clazz); $this->schema = $collection->schema(); $globalConfig = $this->app->config('component.table'); if (!isset($config['actions'])) { if (isset($globalConfig['mapping'][$clazz]['actions'])) { $config['actions'] = $globalConfig['mapping'][$clazz]['actions']; } elseif (isset($globalConfig['default']['actions'])) { $config['actions'] = $globalConfig['default']['actions']; } else { $config['actions'] = array('read' => NULL, 'update' => NULL, 'delete' => NULL); } } if (!isset($config['columns'])) { if (isset($globalConfig['mapping'][$clazz]['columns'])) { $config['columns'] = $globalConfig['mapping'][$clazz]['columns']; } elseif (isset($globalConfig['default']['columns'])) { $config['columns'] = $globalConfig['default']['columns']; } } if (empty($this->schema) && empty($config['columns'])) { throw new \Exception('Plain table needs collection schema or "component.table" configuration!'); } $this->config = $config; $this->view = new \Slim\View(); $this->view->setTemplatesDirectory(realpath(dirname(__FILE__) . '/../../../templates')); $this->view->set('self', $this); }
public function handle($e) { $app = App::getInstance(); while (ob_get_level() > 0) { ob_end_clean(); } // header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500); if ($app->config('bono.debug') !== true) { if (isset($app->response)) { $app->response->setStatus(500); } if (isset($app->theme)) { $view = $app->theme->getView(); $errorTemplate = 'error'; } else { $view = new View(); $errorTemplate = '../templates/error.php'; if (is_readable($errorTemplate)) { $view->setTemplatesDirectory('.'); } } return $view->display($errorTemplate, array('error' => $e), 500); } return call_user_func_array(array($app->whoops, Run::EXCEPTION_HANDLER), func_get_args()); }
public function __construct($config) { parent::__construct($config); $app = \Bono\App::getInstance(); $d = explode(DIRECTORY_SEPARATOR . 'src', __DIR__); $this->addBaseDirectory($d[0], 5); $this->resolveAssetPath('vendor/img'); $appConfig = $app->config('application'); $app->filter('page.title', function ($key) use($app, $appConfig) { if (isset($app->controller)) { $module = Inflector::humanize($app->controller->getClass()); return $key . ' - ' . $module; } return $key; }); $app->filter('page.header', function ($key) use($appConfig) { if (isset($appConfig['title'])) { return $appConfig['title']; } return $key; }); $app->filter('page.subheader', function ($key) use($app, $appConfig) { if (isset($app->controller)) { return Inflector::humanize($app->controller->getClass()); } if (isset($appConfig['subtitle'])) { return $appConfig['subtitle']; } return $key; }); }
public function __construct(Request $request, Response $response) { $this->app = App::getInstance(); $this->request = $request; $this->response = $response; $this->state = []; }
public function __construct($config) { $config['baseDirectories'] = array(dirname(dirname(dirname(dirname(__FILE__))))); // var_dump($config); // exit; parent::__construct($config); // $app->filter('css', function($file) { // if ($this->app->config('bono.debug')) { // $src = $this->getPath(substr($file, 1)); // $dest = dirname($_SERVER['SCRIPT_FILENAME']).$file; // if ($this->overwrite || !is_readable($dest)) { // $dir = dirname($dest); // if (!is_readable($dir)) { // mkdir($dir, 0755, 1); // } // copy($src, $dest); // } // } // return $file; // }, 1); $app = App::getInstance(); $app->filter('table', function ($entries) use($app) { // $t = new PlainTable($app->controller->clazz); // return $t->show($entries); }); $app->filter('form', function ($entry) use($app) { // $f = new PlainForm($app->controller->clazz); // return $f->renderFields($entry); }); $app->filter('form.ro', function ($entry) use($app) { // $f = new PlainForm($app->controller->clazz); // return $f->renderReadonlyFields($entry); }); }
/** * Get the container behind the facade. * * @return mixed */ public static function getFacadeContainer() { if (is_null(static::$container)) { static::$container = App::getInstance()->kraken; } return static::$container; }
/** * Alias to choice * * @param string $word Word to translate * @param array $count Which one should translate take for current choice? * @param string $param Parameter / placeholder that would be attached to the line * * @return string Translated word */ function c($keyWord, $count = 1, $param = array()) { $translator = App::getInstance()->translator; if (is_null($translator)) { throw new Exception('Undefined translator, please register LangProvider.'); } return $translator->choice($keyWord, $count, $param); }
/** * Initialize the provider * * @return void */ public function initialize() { $app = $this->app; $app->container->singleton('cache', function ($app) { $config = App::getInstance()->config('cache'); $cacheManager = new \KrisanAlfa\Cache\Cache($app); return $cacheManager->driver($config['driver']); }); }
public function __construct($clazz, $config = NULL) { $this->app = \Bono\App::getInstance(); $this->clazz = $clazz; $collection = \Norm\Norm::factory($clazz); $this->schema = $collection->schema(); $this->globalConfig = $this->app->config('component.form'); $this->config = isset($this->globalConfig['mapping'][$this->clazz]) ? $this->globalConfig['mapping'][$this->clazz] : NULL; }
public function __construct($config) { $this->options = @$config['options'] ?: array(); parent::__construct($config); $app = \Bono\App::getInstance(); $d = explode(DIRECTORY_SEPARATOR . 'src', __DIR__); $this->addBaseDirectory($d[0], 5); $this->resolveAssetPath('vendor/bootstrap'); $appConfig = $app->config('application'); }
protected static function opts($key = null) { if (is_null(static::$options)) { static::$options = App::getInstance()['bind9'] ?: []; } if (0 === func_num_args()) { return static::$options; } else { return isset(static::$options[$key]) ? static::$options[$key] : null; } }
public function show($options = null) { unset($_SESSION['notification']); if (is_null($options)) { return $this->show(array('level' => 'error')) . "\n" . $this->show(array('level' => 'info')); } $messages = $this->query($options); if (!empty($messages)) { return App::getInstance()->theme->partial('components/alert', array('options' => $options, 'messages' => $messages)); } }
public function formatInput($value, $entry = null) { $app = App::getInstance(); if ($value instanceof TypeDateTime) { $value = date("d-m-Y", strtotime($value->__toString())); } if ($this['readonly']) { return '<span class="field">' . $value . '</span>'; } return $app->theme->partial($this->getPartialTemplate(), array('id' => uniqid('date_'), 'value' => $value, 'entry' => $entry, 'self' => $this)); }
public function __construct(array $options = []) { $options = App::getInstance()['nginx'] ?: []; parent::__construct($options); $this->routeMap(['GET'], '/', [$this, 'search']); $this->routeMap(['POST'], '/', [$this, 'create']); $this->routeMap(['DELETE'], '/', [$this, 'delete']); $this->routeMap(['GET'], '/reload', [$this, 'reload']); $this->routeMap(['POST'], '/{normalized}/upstream', [$this, 'upstreamCreate']); $this->routeMap(['DELETE'], '/{normalized}/upstream', [$this, 'upstreamDelete']); }
public function body($template = null, $data = null) { if (func_num_args() === 0) { return $this->message->getBody(); } $data['app'] = \Bono\App::getInstance(); if (is_string($template)) { $this->message->setBody(App::getInstance()->theme->partial('emails/' . $template, $data)); } else { throw new \Exception('Unimplemented yet!'); } return $this; }
/** * [display description] * * @return [type] [description] */ public function display($template) { $app = App::getInstance(); $data = $this->data->all(); unset($data['flash']); unset($data['app']); foreach (array_keys($data) as $key) { if ($key[0] === '_') { unset($data[$key]); } } $app->response->headers['content-type'] = $this->contentType; echo \JsonKit\JsonKit::encode($data); }
/** * Constructor * * @param array $options Theme options */ public function __construct(array $options = array()) { // prepare default options $defaultOptions = array('cachePath' => 'cache'); $options = array_merge($defaultOptions, $options); $this->options = $options; // call parent constructor parent::__construct($options); // set blade-theme module dir as one of base directory $directory = explode(DIRECTORY_SEPARATOR . 'src', __DIR__); $directory = reset($directory); $this->addBaseDirectory($directory, 5); $this->app = App::getInstance(); }
/** * Get specific view of this theme, I use Blade View Engine * * @return KrisanAlfa\Blade\BladeView */ public function getView() { if (is_null($this->view)) { $appPath = $this->app->config('app.path'); if (!is_null($appPath)) { $this->options['cachePath'] = $appPath . DIRECTORY_SEPARATOR . $this->options['cachePath']; } if (!is_dir($this->options['cachePath'])) { mkdir($this->options['cachePath'], 0755, true); } $this->options['viewPaths'] = $this->arrayFlatten($this->baseDirectories); $this->view = new BladeView($this->options); } return $this->view; }
/** * Merge configuration from application and given configuration file path * * @param string $path Path of configuration file * * @return void */ protected function mergeConfig($path) { // Only do if configuration file is readable if (is_readable($path)) { $config = (require_once $path); // Only do if configuration file return an array if (is_array($config)) { foreach ($config as $key => $value) { // Only do if value is not empty and not null if ($value) { $this->app->config($key, $value); } } } } }
public function resolve($options) { $app = App::getInstance(); $configPath = null; if (isset($this->options['collectionPath'])) { if (is_callable($this->options['collectionPath'])) { $configPath = call_user_func($this->options['collectionPath']); } else { $configPath = $this->options['collectionPath']; } } if (!is_readable($configPath)) { $configPath = rtrim($app->config('config.path'), '/') . '/collections/' . $options['name'] . '.php'; } if (is_readable($configPath)) { return include $configPath; } }
/** * Constructor */ public function __construct($options) { $this->app = App::getInstance(); if (isset($options['view'])) { if (is_callable($options['view'])) { $view = $options['view']; $this->view = $view(); } } else { $this->view = new View(); if (isset($options['partialTemplatePath'])) { $partialTemplatePath = $options['partialTemplatePath']; } else { $partialTemplatePath = dirname(dirname(dirname(dirname(__DIR__)))) . '/partials'; } $this->view->setTemplatesDirectory($partialTemplatePath); } }
/** * [__construct description] */ public function __construct() { $list = null; $app = App::getInstance(); $config = array(); try { $list = scandir($app->config('config.path')); } catch (\Exception $e) { throw new \Exception("The path of configuration file doesn't found", 33); } foreach ($list as $fileName) { if ($fileName != '.' && $fileName != '..') { $content = (include_once $app->config('config.path') . '/' . $fileName); $fileName = preg_replace('/\\.php$/i', '', $fileName); $config[$fileName] = $content; } } $this->config = $config; }
/** * Initalizer a.k.a the class constructor * Leave the third arguments empty if you won't use any layout * * @param array $options Options for BladeView * * @return KrisanAlfa\Blade\BladeView */ public function __construct(array $options) { parent::__construct(); $this->app = App::getInstance(); $this->container = new Container(); $viewPaths = $this->resolvePath($options['viewPaths']); $this->container->singleton('view.paths', function () use($viewPaths) { return $viewPaths; }); $cachePath = $options['cachePath']; $this->container->singleton('cache.path', function () use($cachePath) { return $cachePath; }); $this->registerFilesystem(); $this->registerEvents(); $this->registerEngineResolver(); $this->registerViewFinder(); $this->registerFactory(); $this->instance = $this->container->make('view'); }
public function handle() { $app = App::getInstance(); if ($app->config('bono.debug') !== true) { if (isset($app->response)) { $app->response->setStatus(404); } if (isset($app->theme)) { $view = $app->theme->getView(); $errorTemplate = 'notFound'; } else { $view = new View(); $errorTemplate = '../templates/notFound.php'; if (is_readable($errorTemplate)) { $view->setTemplatesDirectory('.'); } } return $view->display($errorTemplate, array(), 404); } $app->whoops->sendHttpCode(404); return call_user_func(array($app->whoops, Run::EXCEPTION_HANDLER), new RuntimeException("404 Resource not found")); }
public function formatReadonly($value, $entry = null) { $label = $this->formatPlain($value, $entry) ?: ' '; return App::getInstance()->theme->partial('_schema.string', array('label' => $this['label'], 'name' => $this['name'], 'value' => htmlentities($label), 'readonly' => true, 'entry' => $entry)); }
/** * Create an instance of the file cache driver. * * @return \Illuminate\Cache\FileStore */ protected function createFileDriver() { $config = App::getInstance()->config('cache'); return $this->repository(new FileStore(new \Illuminate\Filesystem\Filesystem(), $config['path'])); }