Exemplo n.º 1
0
 /**
  * Register specific services for the module
  *
  * @package     base-app
  * @version     2.0
  *
  * @param object $di dependency Injector
  *
  * @return void
  */
 public function registerServices(\Phalcon\DiInterface $di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         //Create/Get an EventManager
         $eventsManager = new \Phalcon\Events\Manager();
         //Attach a listener
         $eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) {
             //controller or action doesn't exist
             if ($event->getType() == 'beforeException') {
                 switch ($exception->getCode()) {
                     case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                     case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                         $dispatcher->forward(array('controller' => 'index', 'action' => 'notFound'));
                         return false;
                 }
             }
         });
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         //Set default namespace to documentation module
         $dispatcher->setDefaultNamespace("Baseapp\\Documentation\\Controllers");
         //Bind the EventsManager to the dispatcher
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     //Registering the view component
     $di->set('view', function () use($di) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(\Baseapp\Library\Tool::registerEngines($view, $di));
         return $view;
     });
 }
Exemplo n.º 2
0
 /**
  * After Action
  *
  * @package     base-app
  * @version     2.0
  */
 public function afterExecuteRoute($dispatcher)
 {
     // Set final title
     $this->tag->setTitleSeparator(' | ');
     $this->tag->appendTitle($this->config->app->name);
     // Set scripts
     $this->view->setVar('scripts', $this->scripts);
     // Minify css and js collection
     \Baseapp\Library\Tool::assetsMinification();
 }
Exemplo n.º 3
0
 /**
  * After Action
  *
  * @package     base-app
  * @version     2.0
  */
 public function afterExecuteRoute($dispatcher)
 {
     // Set final title and description
     $this->tag->setTitleSeparator(' | ');
     $this->tag->appendTitle($this->config->app->name);
     $this->view->setVar('siteDesc', mb_substr($this->filter->sanitize($this->siteDesc, 'string'), 0, 200, 'utf-8'));
     // Set scripts
     $this->view->setVar('scripts', $this->scripts);
     // Minify css and js collection
     \Baseapp\Library\Tool::assetsMinification();
 }
Exemplo n.º 4
0
 /**
  * After Action
  *
  * @package     base-app
  * @version     2.0
  */
 public function afterExecuteRoute($dispatcher)
 {
     // Set final title and description
     $this->tag->setTitleSeparator(' | ');
     $this->tag->appendTitle($this->config->app->name);
     $this->view->setVar('siteDesc', mb_substr($this->filter->sanitize($this->siteDesc, 'string'), 0, 200, 'utf-8'));
     // Set scripts
     $scripts = array('$(document).ready(function() { $("pre code").each(function(i, e) {hljs.highlightBlock(e)}); });');
     $this->view->setVar('scripts', array_merge($this->scripts, $scripts));
     // Minify css and js collection
     \Baseapp\Library\Tool::assetsMinification();
 }
Exemplo n.º 5
0
 /**
  * Minify css and js collection
  *
  * @package     base-app
  * @version     2.0
  */
 public function assetAction()
 {
     foreach (array('css', 'js') as $asset) {
         foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ROOT_PATH . '/public/' . $asset, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
             if (!$item->isDir() && ($item->getExtension() == 'css' || $item->getExtension() == 'js')) {
                 $subPath = $iterator->getSubPathName();
                 $dir = strstr($subPath, $item->getFilename(), true);
                 $add = 'add' . ucfirst($asset);
                 $this->assets->{$add}($asset . '/' . $dir . $item->getFilename());
             }
         }
     }
     // Minify css and js collection
     \Baseapp\Library\Tool::assetsMinification();
 }
Exemplo n.º 6
0
 /**
  * Dynamically generate form fields with Semantic Ui classes
  * and error messages.
  * @TODO This is work in progress
  *
  * @param $type
  * @param $name
  * @param bool|FALSE $value
  * @param bool|FALSE $extras
  * @param bool|FALSE $error
  * @return string
  */
 public static function formField($type, $name, $value = FALSE, $extras = FALSE, $error = FALSE)
 {
     $tag = Tag;
     switch ($type) {
         case 'text':
             return '<label for="' . $name . '">' . Tool::label($name) . '</label>
             <div class="ui field' . $error == TRUE ? ' error' : '' . '">
             ' . $tag->textField(array($name, 'value' => $value, $extras)) . $error == TRUE ? '<span class="ui red pointing above label">' . $error . '</span>' : '' . '
             </div>';
             break;
         case 'password':
             break;
         case 'textarea':
             break;
         case 'checkbox':
             break;
     }
 }
Exemplo n.º 7
0
 /**
  * After Action
  *
  */
 public function afterExecuteRoute($dispatcher)
 {
     // Set final title
     $this->tag->setTitleSeparator(' | ');
     $this->tag->appendTitle($this->config->app->name);
     $this->view->setVars(array('scripts' => $this->scripts, 'pageName' => $this->pageName, 'base_url' => $this->config->app->base_uri, 'admin_url' => $this->config->app->admin_uri . '/'));
     // Set scripts
     //        $this->view->setVar('scripts', $this->scripts);
     // Minify css and js collection
     \Baseapp\Library\Tool::assetsMinification();
 }
Exemplo n.º 8
0
 /**
  * Catch the exception and log it, display pretty view
  *
  * @param \Exception $e
  */
 public static function exception(\Exception $e)
 {
     $config = \Phalcon\DI::getDefault()->getShared('config');
     $errors = array('error' => get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage(), 'info' => $e->getFile() . '[' . $e->getLine() . ']', 'debug' => "Trace: \n" . $e->getTraceAsString() . "\n");
     if ($config->app->env == "development") {
         // Display debug output
         $debug = new \Phalcon\Debug();
         $debug->onUncaughtException($e);
     } else {
         // Display pretty view of the error
         $di = new \Phalcon\DI\FactoryDefault();
         $view = new \Phalcon\Mvc\View\Simple();
         $view->setDI($di);
         $view->setViewsDir(APP_PATH . '/app/frontend/views/');
         $view->registerEngines(\Baseapp\Library\Tool::registerEngines($view, $di));
         echo $view->render('error', array('i18n' => I18n::instance(), 'config' => $config));
         // Log errors to file and send email with errors to admin
         \Baseapp\Bootstrap::log($errors);
     }
 }