Exemple #1
0
 /**
  *## Iterate and Process
  * All the magic happens here, whils it looks complicated this is essentially a directory iterator
  * that creates an array of filenames, with a corresponding Phrocco object that can look after rendering itself.
  *
  **/
 public function process()
 {
     $dir_iterator = new PhroccoIterator($this->options["i"]);
     $iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $file) {
         if (!$iterator->isDot() && in_array($iterator->getExtension(), $this->extensions[$this->options["l"]])) {
             $base_path = $this->options["i"];
             $rpath = str_replace($base_path, "", $file->getPath());
             $phrocco = new Phrocco($this->options["l"], $file);
             if (!$this->options["o"]) {
                 $output_dir = $file->getPath();
             } else {
                 $output_dir = $this->options["o"];
             }
             if ($rpath != $file->getPath()) {
                 $output_dir .= "/" . $rpath;
             }
             /**
              *### Check that we can write
              * This block ensures that the output directory exists. If it doesn't we'll try and create it before giving up.
              **/
             if (!is_writable($output_dir)) {
                 try {
                     mkdir($output_dir, 0777, true);
                 } catch (Exception $e) {
                     if (!is_writable($output_dir)) {
                         throw new \Exception("Invalid Output Directory - Couldn't Create Because of Permissions");
                     }
                 }
             }
             /**
              *### Build the documentation tree
              * This block builds the documentation file layout to mirror the code files scanned.
              **/
             $file_out = $output_dir . "/" . $file->getBasename($iterator->getExtension()) . "html";
             $phrocco->output_file = $file_out;
             $subpath = $iterator->getSubPath();
             $phrocco->path = (!empty($subpath) ? "./" : '') . $subpath;
             $this->group[$file->getBasename()] = $phrocco;
             $subpath .= !empty($subpath) ? '/' : '';
             $this->sources[] = array("url" => $subpath . $file->getBasename($iterator->getExtension()) . "html", "name" => $file->getBasename(), "level" => $iterator->getDepth(), "folder" => $iterator->getSubPath());
         }
     }
 }
 protected function countThemePages($path)
 {
     $result = 0;
     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
     $it->setMaxDepth(1);
     while ($it->valid()) {
         if (!$it->isDot() && !$it->isDir() && $it->getExtension() == 'htm') {
             $result++;
         }
         $it->next();
     }
     return $result;
 }
Exemple #3
0
 public function __construct($options)
 {
     $sources = array();
     $this->options = $options + $this->defaults;
     $dir_iterator = new PhroccoIterator($this->options["i"]);
     $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $file) {
         if (!$iterator->isDot() && in_array($iterator->getExtension(), $this->extensions[$this->options["l"]])) {
             $base_path = $this->options["i"];
             $rpath = str_replace($base_path, "", $file->getPath());
             $phrocco = new Phrocco($this->options["l"], $file);
             if (!$this->options["o"]) {
                 $output_dir = $file->getPath();
             } else {
                 $output_dir = $this->options["o"];
             }
             if ($rpath != $file->getPath()) {
                 $output_dir .= "/" . $rpath;
             }
             if (!is_writable($output_dir)) {
                 @mkdir($output_dir, 0777, true);
             }
             if (!is_writable($output_dir)) {
                 throw new Exception("Invalid Output Directory - Couldn't Create Because of Permissions");
             }
             $file_out = $output_dir . "/" . $file->getBasename($iterator->getExtension()) . "html";
             $phrocco->output_file = $file_out;
             $subpath = $iterator->getSubPath();
             $phrocco->path = (!empty($subpath) ? "./" : '') . $subpath;
             $this->group[$file->getBasename()] = $phrocco;
             $subpath .= !empty($subpath) ? '/' : '';
             $this->sources[] = array("url" => $subpath . $file->getBasename($iterator->getExtension()) . "html", "name" => $file->getBasename());
         }
     }
     foreach ($this->group as $name => $file) {
         $file->sources = $this->sources;
         echo "*** Processing: " . $name . "\n";
         $file->render();
     }
 }
Exemple #4
0
 public function getFiles($dirname = '')
 {
     $arr_folder = array();
     $count = 0;
     $folder = UPLOAD_DIR;
     $folder .= DIRECTORY_SEPARATOR . $dirname;
     if (is_dir($folder)) {
         $dir = new RecursiveDirectoryIterator($folder);
         $iter = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST);
         while ($iter->valid()) {
             if (!$iter->isDot()) {
                 if ($iter->getDepth() < $this->maxDepth) {
                     $item = array();
                     $item['id'] = $count;
                     $item['size'] = $iter->getSize();
                     $item['type'] = $iter->getType();
                     $item['ext'] = $iter->getExtension();
                     $item['pathname'] = $iter->getSubPathName();
                     $item['filename'] = $iter->getFilename();
                     $item['parent'] = '/' . $dirname;
                     $item['Exec'] = $iter->isExecutable();
                     $item['sub'] = '';
                     $count++;
                     $arr_folder[] = $item;
                 }
             }
             $iter->next();
         }
         return $arr_folder;
     }
     if (is_file($folder)) {
         $file = file_get_contents($folder);
         if (empty($file)) {
             return ' ';
         }
         return $file;
     }
 }
$binaryFilename = "bin/{$binary}";
if (file_exists($pharFilename)) {
    Phar::unlinkArchive($pharFilename);
}
if (file_exists($binaryFilename)) {
    Phar::unlinkArchive($binaryFilename);
}
$phar = new Phar($pharFilename, FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO, $binary);
$phar->startBuffering();
$directories = array('src', 'vendor', 'scripts');
foreach ($directories as $dirname) {
    $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname));
    while ($iterator->valid()) {
        if ($iterator->isFile()) {
            $path = $iterator->getPathName();
            if ('php' == strtolower($iterator->getExtension())) {
                $contents = php_strip_whitespace($path);
                $phar->addFromString($path, $contents);
            } else {
                $phar->addFile($path);
            }
        }
        $iterator->next();
    }
}
$stub = "#!/usr/bin/env php\n" . $phar->createDefaultStub($scriptFilename);
$phar->setStub($stub);
$phar->compressFiles(Phar::GZ);
$phar->stopBuffering();
rename($pharFilename, $binaryFilename);
chmod($binaryFilename, 0775);