Ejemplo n.º 1
0
 /**
  * Initialize bootstrap
  */
 public static function init()
 {
     $autoload = \Config::get('bootstrap.assets.autoload', false);
     if (!$autoload) {
         return;
     }
     $path = \Config::get('bootstrap.assets.path', '');
     $use_min = \Config::get('bootstrap.assets.use_min', true);
     $css_file = $path . 'bootstrap';
     $js_file = $path . 'bootstrap';
     if ($use_min) {
         $css_file .= '.min';
         $js_file .= '.min';
     }
     $css_file .= '.css';
     $js_file .= '.js';
     // See if Casset package is used.
     if (\Package::loaded('casset')) {
         \Casset::css($css_file, !$use_min);
         \Casset::js($js_file, !$use_min);
     } else {
         \Asset::css($css_file);
         \Asset::js($js_file);
     }
 }
Ejemplo n.º 2
0
 /**
  * Initialize class and forge a Sprockets Instance
  */
 public function __construct()
 {
     !\Package::loaded('sprockets') and \Package::load('sprockets');
     // When in console mode, DOCROOT is the path to the project root, not the public/
     $config = array('asset_compile_dir' => DOCROOT . 'public/assets/', 'force_minify' => true);
     static::$sprockets = \Sprockets::forge('default', $config);
 }
Ejemplo n.º 3
0
 /**
  * Queue job
  *
  * @param	mixed		$id			Supplier id
  * @param	string		$method		Method to run
  * @param	integer		$delay
  * @param	integer		$ttr		Time limit
  * @return	null
  */
 public function execute($id, $method, $delay = 0, $ttr = 300)
 {
     // Cast id
     is_numeric($id) and $id = (int) $id;
     // Job data
     $data = array('id' => $id, 'cached' => (bool) \Cli::option('cached', \Cli::option('c', false)), 'force' => (bool) \Cli::option('force', \Cli::option('f', false)), 'method' => $method);
     // Execute job immediately
     $execute = (bool) \Cli::option('execute', \Cli::option('e', false));
     // Use Queue if available (greater performance)
     if (\Package::loaded('queue')) {
         // Create queue data
         if ($execute) {
             // Initialize logger
             $logger = clone \Log::instance();
             // Get original handler
             $handler = $logger->popHandler();
             $handler->pushProcessor(new \Monolog\Processor\PsrLogMessageProcessor());
             $logger->pushHandler($handler);
             // Console handler
             $handler = new \Monolog\Handler\ConsoleHandler(\Monolog\Logger::NOTICE);
             $formatter = new \Monolog\Formatter\LineFormatter("%message% - %context%" . PHP_EOL, "Y-m-d H:i:s");
             $handler->setFormatter($formatter);
             $logger->pushHandler($handler);
             // Add other handlers to logger through Event trigger
             \Event::instance('queue')->trigger('logger', $logger);
             $queue = array('supplier', array('driver' => 'direct', 'logger' => $logger));
         } else {
             $queue = 'supplier';
         }
         $options = array('delay' => $delay, 'ttr' => $ttr);
         // Push job and data to queue
         \Queue::push($queue, 'Indigo\\Erp\\Stock\\Job_Supplier', $data, $options);
     } else {
         try {
             $job = new Job_Supplier();
             return $job->execute(null, $data);
         } catch (\Exception $e) {
             // TODO: process exceptions
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Pass in test-friendly configs
  */
 public function __construct()
 {
     $this->config = array(array('asset_root_dir' => __DIR__ . '/assets/root/', 'asset_compile_dir' => __DIR__ . '/assets/compiled/', 'cache_dir' => __DIR__ . '/assets/cache/', 'js_dir' => 'js/', 'css_dir' => 'css/', 'force_minify' => false), array('asset_root_dir' => __DIR__ . '/assets/root/', 'asset_compile_dir' => __DIR__ . '/assets/compiled/', 'cache_dir' => __DIR__ . '/assets/cache/', 'js_dir' => 'js/', 'css_dir' => 'css/', 'force_minify' => true));
     !Package::loaded('sprockets') and Package::load('sprockets');
 }
Ejemplo n.º 5
0
 protected function _available(array $available)
 {
     $count = array(0, 0);
     foreach ($available as $key => $value) {
         if (!empty($value) && is_array($value)) {
             $count[$key > 0 ? 1 : $key] += count($value);
             $value = array('key' => $key, 'ids' => $value, 'supplier_id' => $this->model->id);
             // Get job and queue
             $job = $this->get_config('available.job', 'Indigo\\Erp\\Stock\\Job_Supplier_Available');
             $queue = $this->get_config('available.queue', 'update');
             // Use Queue if available (greater performance)
             if (\Package::loaded('queue')) {
                 \Queue::push($queue, $job, $value);
             } else {
                 try {
                     $job = new $job();
                     $job->execute(null, $value);
                 } catch (\Exception $e) {
                 }
             }
         }
     }
     return $count;
 }
Ejemplo n.º 6
0
 /**
  * Locates a given file in the search paths.
  *
  * @param   string  $dir       Directory to look in
  * @param   string  $file      File to find
  * @param   string  $ext       File extension
  * @param   bool    $multiple  Whether to find multiple files
  * @param   bool    $cache     Whether to cache this path or not
  * @return  mixed  Path, or paths, or false
  */
 public function locate($dir, $file, $ext = '.php', $multiple = false, $cache = true)
 {
     $found = $multiple ? array() : false;
     // absolute path requested?
     if ($file[0] === '/' or substr($file, 1, 2) === ':\\') {
         // if the base file does not exist, stick the extension to the back of it
         if (!is_file($file)) {
             $file .= $ext;
         }
         if (!is_file($file)) {
             // at this point, found would be either empty array or false
             return $found;
         }
         return $multiple ? array($file) : $file;
     }
     // determine the cache prefix
     if ($multiple) {
         // make sure cache is not used if the loaded package and module list is changed
         $cachekey = '';
         class_exists('Module', false) and $cachekey .= implode('|', \Module::loaded());
         $cachekey .= '|';
         class_exists('Package', false) and $cachekey .= implode('|', \Package::loaded());
         $cache_id = md5($cachekey) . '.';
     } else {
         $cache_id = 'S.';
     }
     $paths = array();
     // If a filename contains a :: then it is trying to be found in a namespace.
     // This is sometimes used to load a view from a non-loaded module.
     if ($pos = strripos($file, '::')) {
         // get the namespace path
         if ($path = \Autoloader::namespace_path('\\' . ucfirst(substr($file, 0, $pos)))) {
             $cache_id .= substr($file, 0, $pos);
             // and strip the classes directory as we need the module root
             $paths = array(substr($path, 0, -8));
             // strip the namespace from the filename
             $file = substr($file, $pos + 2);
         }
     } else {
         $paths = $this->paths;
         // get extra information of the active request
         if (class_exists('Request', false) and $request = \Request::active()) {
             $request->module and $cache_id .= $request->module;
             $paths = array_merge($request->get_paths(), $paths);
         }
     }
     // Merge in the flash paths then reset the flash paths
     $paths = array_merge($this->flash_paths, $paths);
     $this->clear_flash();
     $file = $this->prep_path($dir) . $file . $ext;
     $cache_id .= $file;
     if ($cache and $cached_path = $this->from_cache($cache_id)) {
         return $cached_path;
     }
     foreach ($paths as $dir) {
         $file_path = $dir . $file;
         if (is_file($file_path)) {
             if (!$multiple) {
                 $found = $file_path;
                 break;
             }
             $found[] = $file_path;
         }
     }
     if (!empty($found) and $cache) {
         $this->add_to_cache($cache_id, $found);
     }
     return $found;
 }