Ejemplo n.º 1
0
 /**
  * @return PHPoole
  */
 public function getPHPoole()
 {
     $messageCallback = function ($code, $message = '', $itemsCount = 0, $itemsMax = 0, $verbose = true) {
         switch (true) {
             case $code == 'CREATE' || $code == 'CONVERT' || $code == 'GENERATE' || $code == 'RENDER' || $code == 'COPY':
                 $this->wlAnnonce($message);
                 break;
             case $code == 'CREATE_PROGRESS' || $code == 'CONVERT_PROGRESS' || $code == 'GENERATE_PROGRESS' || $code == 'RENDER_PROGRESS' || $code == 'COPY_PROGRESS':
                 if ($itemsCount > 0 && $verbose !== false) {
                     $this->wlDone(sprintf("\r  (%u/%u) %s", $itemsCount, $itemsMax, $message));
                     break;
                 }
                 $this->wlDone("  {$message}");
                 break;
         }
     };
     if (!$this->phpoole instanceof PHPoole) {
         if (!file_exists($this->getPath() . '/' . self::CONFIG_FILE)) {
             $this->wlError('Config file (phpoole.yml) not found!');
             exit(2);
         }
         try {
             $options = (new Yaml())->parse(file_get_contents($this->getPath() . '/' . self::CONFIG_FILE));
             $this->phpoole = new PHPoole($options, $messageCallback);
             $this->phpoole->setSourceDir($this->getPath());
             $this->phpoole->setDestDir($this->getPath());
         } catch (\Exception $e) {
             $this->wlError($e->getMessage());
             exit(2);
         }
     }
     return $this->phpoole;
 }
Ejemplo n.º 2
0
#!/usr/local/bin/php
<?php 
if (php_sapi_name() !== 'cli') {
    return;
}
date_default_timezone_set('Europe/Paris');
require_once 'vendor/autoload.php';
use PHPoole\PHPoole;
use Symfony\Component\Yaml\Yaml;
$getopt = getopt('e::');
$options = Yaml::parse(file_get_contents('phpoole.yml'));
$options_dev = ['site' => ['baseurl' => 'http://localhost:8000']];
$prod = isset($getopt['e']) && $getopt['e'] == 'prod' ? true : false;
$options = !$prod ? array_replace_recursive($options, $options_dev) : $options;
$phpoole = new PHPoole($options);
$phpoole->build();
if (!$prod) {
    echo "Start server http://localhost:8000\n";
    echo "Ctrl-C to stop it\n";
    exec('php -S localhost:8000 -t _site');
}