예제 #1
0
 /**
  * @return void
  */
 protected function matchRoute()
 {
     if (isset($this->routeCollection)) {
         $context = new WebRequestContext();
         $context->fromWebRequest($this->request);
         $matcher = new RouteMatcher($this->routeCollection, $context);
         try {
             Logger::debug('Looking for route match: ' . $this->request->getPathInfo());
             $parameters = $matcher->match($this->request->getPathInfo());
             if (is_array($matcher->getRouteOption('parameters'))) {
                 $this->parameters = array_merge($this->parameters, $matcher->getRouteOption('parameters'));
             }
         } catch (ResourceNotFoundException $ex) {
             // Use our DefaultController
             $parameters = $this->getDefaultController();
         }
     } else {
         // no route to match against, so use the DefaultController
         $parameters = $this->getDefaultController();
     }
     if (!isset($parameters)) {
         Logger::alert('Route not found');
     } else {
         $this->parseRouteParameters($parameters);
         Logger::debug('Route matched: ' . $this->route);
     }
 }
예제 #2
0
 /**
  * Instantiate a new CliProject object
  *
  * @param null  $request the action request notation
  * @param array $parameters parameters to pass to the action
  *
  * @throws SynergyException
  */
 public function __construct($request = null, array $parameters = array())
 {
     register_tick_function(array(&$this, "checkExit"));
     // Check this is coming from the CLI
     if (PHP_SAPI !== 'cli') {
         throw new SynergyException(sprintf('%s must be run from command line project', __CLASS__));
     }
     // Store or build the request
     $this->parameters = $parameters;
     if (!is_null($request)) {
         $this->request = $request;
     } else {
         $this->args = ArgumentParser::parseArguments();
         $this->request = $this->args->getRequest();
     }
     Logger::debug('CliProject started (pid=' . getmypid() . ')');
     if (is_null($this->args->getRequest())) {
         Logger::emergency('No controller request provided');
         exit(1);
     }
     $this->registerSignalHandler();
     if ($this->args->arg('app')) {
         $this->setAppDir($this->args->arg('app'));
     }
     if ($this->args->arg('conf')) {
         $this->setConfigFilename($this->args->arg('conf'));
     }
     parent::__construct();
 }
예제 #3
0
 public function __destruct()
 {
     if (isset($this->process_pid)) {
         Logger::alert('Daemon process ' . getmypid() . ' ended');
     } else {
         Logger::debug('parent process ' . getmypid() . ' ended');
     }
     parent::__destruct();
 }
예제 #4
0
 /**
  * Save a cached file of the output
  *
  * @param $content
  */
 protected function writeCacheFile($content)
 {
     $dir = $this->temp_dir . DIRECTORY_SEPARATOR . 'synergy';
     Logger::debug('Synergy cache dir: ' . $dir);
     if (!is_dir($dir)) {
         Tools::mkdir($dir);
     }
     $file = $dir . DIRECTORY_SEPARATOR . md5($this->request->getUri()) . '.syn';
     $fh = fopen($file, 'w');
     fputs($fh, $content, strlen($content));
     @fclose($fh);
     if (!$this->isDev && $this->useGzip()) {
         Logger::info('Compressing response');
         $zp = gzopen($file . '.gz', 'w9');
         gzwrite($zp, $content);
         gzclose($zp);
         // remove gzip file if it's bigger than the unzipped file
         if (filesize($file . '.gz') > filesize($file)) {
             unlink($file . '.gz');
         }
     }
 }
예제 #5
0
 /**
  * Location of the template cache directory
  *
  * @param string $dir absolute location of the template cache directory
  *
  * @return void
  */
 public function setCacheDir($dir)
 {
     $dir .= DIRECTORY_SEPARATOR . 'smarty';
     Logger::debug("Smarty cache dir set to: " . $dir);
     parent::setCacheDir($dir);
 }
예제 #6
0
 /**
  * Try to match an asset file in our templateDir
  *
  * @param string $matchDir
  * @param string $file
  *
  * @return WebAsset|void
  */
 protected function matchAsset($matchDir, $file)
 {
     if (strpos($file, '_synergy_')) {
         // internal asset request
         $matchDir = SYNERGY_LIBRARY_PATH . DIRECTORY_SEPARATOR . 'View' . DIRECTORY_SEPARATOR . '_synergy_';
         $file = substr($file, 10);
     }
     $testfile = $matchDir . $file;
     if (file_exists($testfile) && is_readable($testfile)) {
         $asset = new WebAsset($testfile);
         Logger::debug("Asset found: {$file}");
         return $asset;
     }
 }
예제 #7
0
 /**
  * filename of the main config file
  *
  * @param string $filename filename of the main config file
  *
  * @return void
  * @throws InvalidArgumentException
  */
 public function setConfigFilename($filename)
 {
     if (!file_exists($filename)) {
         throw new InvalidArgumentException(sprintf("Missing file %s", $filename));
     } else {
         if (!is_readable($filename)) {
             throw new InvalidArgumentException(sprintf("File %s not readable", $filename));
         } else {
             $extension = pathinfo($filename, PATHINFO_EXTENSION);
             switch (strtolower($extension)) {
                 case 'yml':
                     $this->configFilename = $filename;
                     $this->options = \Spyc::YAMLLoad($filename);
                     Logger::debug('Config file: ' . $filename);
                     break;
                 default:
                     throw new InvalidArgumentException(sprintf("Config file format is not supported", $filename));
             }
         }
     }
 }