Ejemplo n.º 1
0
}
$stylePath = array_shift($arguments);
// Check if the style path is a directory
if (!is_dir($stylePath)) {
    echo Cli::getColoredString('This path is not a directory', 'red'), "\n";
    exit;
}
$stylePath = realpath($stylePath);
// Error handler
function defaultErrorHandler($level, $message, $file, $line)
{
    throw new Exception("{$message} ({$file}:{$line})");
}
set_error_handler('defaultErrorHandler');
// Initialize the logger
$logger = Logger::getInstance();
$fileListener = new StdoutListener();
$logger->addListener($fileListener);
// Generate the style
echo Cli::getColoredString('Generating ... ', 'yellow');
try {
    $stylesheetHelper = new \Neolao\Site\Helper\View\StylesheetHelper();
    $stylesheetHelper->basePath = $stylePath;
    $stylesheetHelper->generate();
    $javascriptHelper = new \Neolao\Site\Helper\View\JavascriptHelper();
    $javascriptHelper->basePath = $stylePath;
    $javascriptHelper->generate();
    echo Cli::getColoredString('OK', 'green'), "\n";
} catch (\Exception $error) {
    echo Cli::getColoredString('ERROR', 'red'), "\n";
    echo $error->getMessage(), "\n";
Ejemplo n.º 2
0
 /**
  * Static method "getInstance"
  */
 public function testGetInstance()
 {
     $this->assert->object(\Neolao\Logger::getInstance())->isInstanceOf('\\Neolao\\Logger')->isIdenticalTo(\Neolao\Logger::getInstance());
 }
Ejemplo n.º 3
0
 /**
  * Get the logger instance
  *
  * @return  \Neolao\Logger          Logger instance
  */
 public function main()
 {
     $logger = Logger::getInstance();
     return $logger;
 }
Ejemplo n.º 4
0
 /**
  * Compile the file with SASS
  *
  * @param   string  $sassFilePath   The SASS file path
  * @param   string  $filePath       The compiled file path
  */
 protected function _sassCompile($sassFilePath, $filePath)
 {
     // The compiled file must be writable
     if (!is_writable($filePath)) {
         $logger = Logger::getInstance();
         $logger->warning('The file ' . $filePath . ' is not writable');
         return;
     }
     // The SASS file must be readable
     if (!is_readable($sassFilePath)) {
         $logger = Logger::getInstance();
         $logger->warning('The file ' . $sassFilePath . ' is not readable');
         return;
     }
     // Compile
     $options = ['syntax' => 'scss'];
     try {
         //$parser = new \SassParser($options);
         //$content = $parser->toCss($sassFilePath);
         $parser = new \scssc();
         $parser->setImportPaths(dirname($sassFilePath) . '/');
         $source = file_get_contents($sassFilePath);
         $content = $parser->compile($source);
         file_put_contents($filePath, $content);
     } catch (\Exception $error) {
         $logger = Logger::getInstance();
         $logger->warning('Unable to compile ' . $filePath . ': ' . $error->getMessage());
     }
 }
Ejemplo n.º 5
0
 /**
  * The current user instance
  *
  * @var mixed
  */
 protected function get_currentUser()
 {
     // If the current user is not set, then check the cookie
     try {
         if (is_null($this->_currentUser)) {
             if (isset($_COOKIE[$this->_identityKey]) && isset($_COOKIE[$this->_sessionKey])) {
                 $identity = $_COOKIE[$this->_identityKey];
                 $sessionId = $_COOKIE[$this->_sessionKey];
                 // Get the user instance and user session id
                 $user = $this->getUserByIdentity($identity);
                 $userSessionId = $this->getSessionId($user);
                 // Compare the user session id with the session cookie
                 if ($userSessionId === $sessionId) {
                     $this->currentUser = $user;
                 }
             }
         }
     } catch (Exception $exception) {
         $logger = Logger::getInstance();
         $logger->error($exception->getMessage());
         $logger->error($exception->getTraceAsString());
     }
     return $this->_currentUser;
 }
Ejemplo n.º 6
0
 /**
  * Generate a snapshot of the javascripts
  */
 public function generate()
 {
     $javascriptsDirectory = realpath($this->basePath) . '/javascripts';
     $generatedDirectory = realpath($this->basePath) . '/generated-js';
     // Get JS files
     $filePaths = FileSystem::rglob('*.js', $javascriptsDirectory . '/');
     // Minify the original files
     // They must be readable
     foreach ($filePaths as $filePath) {
         if (!is_readable($filePath)) {
             $logger = Logger::getInstance();
             $logger->warning('The file ' . $filePath . ' is not readable');
             return;
         }
         // Get the file name and the directory paths
         $fileName = pathinfo($filePath, PATHINFO_FILENAME);
         $fileDirectory = pathinfo($filePath, PATHINFO_DIRNAME);
         $fileSubDirectory = substr($fileDirectory, strlen($javascriptsDirectory));
         $fileGeneratedDirectory = $generatedDirectory . $fileSubDirectory;
         // Create the generated directory if necessary
         if (!is_dir($fileGeneratedDirectory)) {
             mkdir($fileGeneratedDirectory, 0777 - umask(), true);
         }
         // Get the file content
         $fileContent = file_get_contents($filePath);
         // Get the checksum
         $checksum = md5($fileContent);
         // Minify
         $generatedFilePath = $fileGeneratedDirectory . '/' . $fileName . '.' . $checksum . '.js';
         $minified = Minifier::minify($fileContent);
         file_put_contents($generatedFilePath, $minified);
         // Save the version
         $versionPath = $fileGeneratedDirectory . '/' . $fileName . '.version.txt';
         if (file_exists($versionPath) && !is_writable($versionPath)) {
             $logger = Logger::getInstance();
             $logger->warning('The file ' . $versionPath . ' is not writable');
             return;
         }
         file_put_contents($versionPath, $checksum);
     }
 }