Example #1
0
 /**
  * Find all plugins defined in your Kohana codebase
  */
 public function find_plugins()
 {
     $paths = Kohana::include_paths();
     foreach ($paths as $path) {
         $dir = $path . self::$plugins_dir;
         //if there's no plugin dir skip to the next path
         if (!file_exists($dir)) {
             continue;
         }
         // Instantiate a new directory iterator object
         $directory = new DirectoryIterator($dir);
         if ($directory->isDir()) {
             foreach ($directory as $plugin) {
                 // Is directory?
                 if ($plugin->isDir() && !$plugin->isDot()) {
                     // if there's no plugin.php in this folder, ignore it
                     if (!file_exists($plugin->getPath() . DIRECTORY_SEPARATOR . $directory->getBasename() . DIRECTORY_SEPARATOR . 'plugin.php')) {
                         continue;
                     }
                     // Store plugin in our pool
                     self::$plugins_pool[$plugin->getFilename()]['plugin'] = ucfirst($plugin->getFilename());
                     self::$plugins_pool[$plugin->getFilename()]['path'] = $plugin->getPath() . DIRECTORY_SEPARATOR . $directory->getBasename();
                 }
             }
         }
     }
     return $this;
 }
 /**
  * Returns the identifier of the current cache entry pointed to by the cache
  * entry iterator.
  *
  * @return string
  * @api
  */
 public function key()
 {
     if ($this->cacheFilesIterator === null) {
         $this->rewind();
     }
     return $this->cacheFilesIterator->getBasename($this->cacheEntryFileExtension);
 }
 private function compileFile(\DirectoryIterator $file)
 {
     $tag = file_get_contents($file->getPathname());
     $tagName = $file->getBasename('.html');
     $jsFunc = $this->extractJsFunction($tag, $tagName);
     $tagHtml = $this->removeJsFromTag($tag, $tagName);
     $tagHtml = str_replace('"', '\\"', $tagHtml);
     $tagHtml = preg_replace("/\r|\n/", "", $tagHtml);
     return 'riot.tag("' . $tagName . '", "' . $tagHtml . '", ' . $jsFunc . ');';
 }
Example #4
0
 /**
  * Overwrite in children to parse files according to our style.
  * @param array $listing
  * @param DirectoryIterator $item
  */
 public function pushItem(&$listing, DirectoryIterator $entry)
 {
     if (substr($filename = $entry->getFilename(), -4) == '.css') {
         // a reset stylesheet, always used
         if (strpos($stylename = $entry->getBasename('.css'), 'tripoli') !== FALSE) {
         } else {
             array_push($listing, $stylename);
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function getBaseFiles()
 {
     $iterator = new \DirectoryIterator($this->getLanguageBasePath() . DIRECTORY_SEPARATOR . $this->baselanguage);
     $files = array();
     while ($iterator->valid()) {
         if (!$iterator->isDot() && $iterator->isFile() && $this->isValidSourceFile($iterator->getPathname()) && $this->isNotFileToSkip($iterator->getBasename())) {
             $files[] = $iterator->getFilename();
         }
         $iterator->next();
     }
     $this->baseFiles = $files;
 }
Example #6
0
 /**
  * Returns a list of all template names.
  *
  * @return string[]
  */
 protected function getTemplateNames()
 {
     /** @var \RecursiveDirectoryIterator $files */
     $files = new \DirectoryIterator(dirname(__FILE__) . '/../../../../data/templates');
     $template_names = array();
     while ($files->valid()) {
         $name = $files->getBasename();
         // skip abstract files
         if (!$files->isDir() || in_array($name, array('.', '..'))) {
             $files->next();
             continue;
         }
         $template_names[] = $name;
         $files->next();
     }
     return $template_names;
 }
Example #7
0
 /**
  * Returns a list of all template names.
  *
  * @return string[]
  */
 public function getAllNames()
 {
     /** @var \RecursiveDirectoryIterator $files */
     $files = new \DirectoryIterator($this->getTemplatePath());
     $template_names = array();
     while ($files->valid()) {
         $name = $files->getBasename();
         // skip abstract files
         if (!$files->isDir() || in_array($name, array('.', '..'))) {
             $files->next();
             continue;
         }
         $template_names[] = $name;
         $files->next();
     }
     return $template_names;
 }
Example #8
0
 /**
  * Executes the transformation process.
  *
  * @throws Zend_Console_Getopt_Exception
  *
  * @return void
  */
 public function execute()
 {
     if ($this->getQuiet()) {
         return;
     }
     echo 'Available themes:' . PHP_EOL;
     /** @var RecursiveDirectoryIterator $files */
     $files = new DirectoryIterator(dirname(__FILE__) . '/../../../../data/themes');
     while ($files->valid()) {
         $name = $files->getBasename();
         // skip abstract files
         if (!$files->isDir() || in_array($name, array('.', '..'))) {
             $files->next();
             continue;
         }
         echo '* ' . $name . PHP_EOL;
         $files->next();
     }
     echo PHP_EOL;
 }
 /**
  * Returns a list of all template names.
  *
  * @return string[]
  */
 protected function getTemplateNames()
 {
     // TODO: this directory needs to come from the parameter set in the DIC in the ServiceProvider
     $template_dir = dirname(__FILE__) . '/../../../../data/templates';
     if (!file_exists($template_dir)) {
         //Vendored installation
         $template_dir = dirname(__FILE__) . '/../../../../../../templates';
     }
     /** @var \RecursiveDirectoryIterator $files */
     $files = new \DirectoryIterator($template_dir);
     $template_names = array();
     while ($files->valid()) {
         $name = $files->getBasename();
         // skip abstract files
         if (!$files->isDir() || in_array($name, array('.', '..'))) {
             $files->next();
             continue;
         }
         $template_names[] = $name;
         $files->next();
     }
     return $template_names;
 }
Example #10
0
 /**
  * @param string $src_dir
  * @param string $dst_dir
  *
  * @throws \Exception
  */
 protected static function copyHooksDir($src_dir, $dst_dir)
 {
     $fs = new Filesystem();
     $fs->mirror($src_dir, $dst_dir, null, ['override' => true]);
     $file = new \DirectoryIterator($src_dir);
     $mask = umask();
     while ($file->valid()) {
         if ($file->isFile() && is_executable($file->getPathname())) {
             $fs->chmod("{$dst_dir}/" . $file->getBasename(), 0777, $mask);
         }
         $file->next();
     }
 }
<?php

$targetDir = __DIR__ . DIRECTORY_SEPARATOR . md5('directoryIterator::getbasename2');
mkdir($targetDir);
touch($targetDir . DIRECTORY_SEPARATOR . 'getBasename_test.txt');
$dir = new DirectoryIterator($targetDir . DIRECTORY_SEPARATOR);
while (!$dir->isFile()) {
    $dir->next();
}
echo $dir->getBasename(array());
$targetDir = __DIR__ . DIRECTORY_SEPARATOR . md5('directoryIterator::getbasename2');
unlink($targetDir . DIRECTORY_SEPARATOR . 'getBasename_test.txt');
rmdir($targetDir);
 /**
  * @param \DirectoryIterator $fileInfo
  *
  * @return bool
  */
 private function isValidDir(\DirectoryIterator $fileInfo)
 {
     return $fileInfo->isDir() && !$fileInfo->isDot() && stripos($fileInfo->getBasename(), '.') !== 0;
 }
 /**
  * Does garbage collection
  *
  * @return void
  * @api
  */
 public function collectGarbage()
 {
     if ($this->frozen === TRUE) {
         return;
     }
     for ($directoryIterator = new \DirectoryIterator($this->cacheDirectory); $directoryIterator->valid(); $directoryIterator->next()) {
         if ($directoryIterator->isDot()) {
             continue;
         }
         if ($this->isCacheFileExpired($directoryIterator->getPathname())) {
             $this->remove($directoryIterator->getBasename($this->cacheEntryFileExtension));
         }
     }
 }
<?php

$targetDir = __DIR__ . DIRECTORY_SEPARATOR . md5('directoryIterator::getbasename1');
mkdir($targetDir);
touch($targetDir . DIRECTORY_SEPARATOR . 'getBasename_test.txt');
$dir = new DirectoryIterator($targetDir . DIRECTORY_SEPARATOR);
while (!$dir->isFile()) {
    $dir->next();
}
echo $dir->getBasename('.txt');
$targetDir = __DIR__ . DIRECTORY_SEPARATOR . md5('directoryIterator::getbasename1');
unlink($targetDir . DIRECTORY_SEPARATOR . 'getBasename_test.txt');
rmdir($targetDir);
Example #15
0
 /**
  * Get basename of file (without extension
  * @return string
  */
 public function getBasename()
 {
     return parent::getBasename('.' . $this->getExtension());
 }
 /**
  * @param \DirectoryIterator $vendorPath
  *
  * @return bool
  */
 private function isValidExtensionDir(\DirectoryIterator $vendorPath)
 {
     return $vendorPath->isDir() && !$vendorPath->isDot() && stripos($vendorPath->getBasename(), '.') !== 0;
     // skip dot directories e.g. .git
 }
/**
 * Automatically find and create drush aliases on the server.
 * @param  array $aliases  array of drush aliases
 */
function _elmsln_alises_build_server(&$aliases, &$authorities = array())
{
    // static cache assembled aliases as this can get tripped often
    static $pulledaliases = array();
    static $pulledauthorities = array();
    static $config = array();
    // check for pervasive cache if static is empty
    if (empty($pulledaliases)) {
        // assumption here is that it lives where we expect
        // change this line if that's not the case though we really don't
        // support changes to that part of the install routine
        $cfg = file_get_contents('/var/www/elmsln/config/scripts/drush-create-site/config.cfg');
        $lines = explode("\n", $cfg);
        // read each line of the config file
        foreach ($lines as $line) {
            // make sure this line isn't a comment and has a = in it
            if (strpos($line, '#') !== 0 && strpos($line, '=')) {
                $tmp = explode('=', $line);
                // ensure we have 2 settings before doing this
                if (count($tmp) == 2) {
                    // never pass around the dbsu
                    if (!in_array($tmp[0], array('dbsu', 'dbsupw'))) {
                        // strip encapsulation if it exists
                        $config[$tmp[0]] = str_replace('"', '', str_replace("'", '', $tmp[1]));
                    }
                }
            }
        }
        // support the fact that $elmsln is used to reference in many bash vars
        foreach ($config as $key => $value) {
            if (strpos($value, '$elmsln') !== FALSE) {
                $config[$key] = str_replace('$elmsln', $config['elmsln'], $value);
            }
        }
        // base address of all domains
        $address = $config['address'];
        // your web root
        $root = $config['stacks'] . '/';
        // calculate the stacks we have
        $stacks = array();
        $stackfinder = new DirectoryIterator("{$root}");
        while ($stackfinder->valid()) {
            // Look for directories that are stacks
            if ($stackfinder->isDir() && !$stackfinder->isDot() && !$stackfinder->isLink()) {
                $stacks[] = $stackfinder->getBasename();
            }
            $stackfinder->next();
        }
        // loop through known stacks
        foreach ($stacks as $stack) {
            // step through sites directory assuming it isn't the 'default'
            if ($stack != 'default' && is_dir("{$root}{$stack}/sites/{$stack}")) {
                try {
                    $stackdir = new DirectoryIterator("{$root}{$stack}/sites/{$stack}");
                    while ($stackdir->valid()) {
                        // Look for directories containing a 'settings.php' file
                        if ($stackdir->isDir() && !$stackdir->isDot() && !$stackdir->isLink()) {
                            $group = $stackdir->getBasename();
                            // only include stack if it has things we can step through
                            // this helps avoid issues of unused stacks throwing errors
                            if (file_exists("{$root}{$stack}/sites/{$stack}/{$group}")) {
                                // build root alias for the stack
                                $pulledauthorities[$stack] = array('root' => $root . $stack, 'uri' => "{$stack}.{$address}");
                                // step through sites directory
                                if (is_dir("{$root}{$stack}/sites/{$stack}/{$group}")) {
                                    $site = new DirectoryIterator("{$root}{$stack}/sites/{$stack}/{$group}");
                                    while ($site->valid()) {
                                        // Look for directories containing a 'settings.php' file
                                        if ($site->isDir() && !$site->isDot() && !$site->isLink()) {
                                            if (file_exists($site->getPathname() . '/settings.php')) {
                                                // Add site alias
                                                $basename = $site->getBasename();
                                                // test that this isn't actually something like coursename = host
                                                if ($basename == $config['host'] && !is_dir("{$root}{$stack}/sites/{$stack}/{$group}/{$group}")) {
                                                    $pulledaliases["{$stack}.{$basename}"] = array('root' => $root . $stack, 'uri' => "{$stack}.{$address}");
                                                } else {
                                                    $pulledaliases["{$stack}.{$basename}"] = array('root' => $root . $stack, 'uri' => "{$stack}.{$address}.{$basename}");
                                                }
                                            }
                                        }
                                        $site->next();
                                    }
                                }
                            }
                        }
                        $stackdir->next();
                    }
                } catch (Exception $e) {
                    // that tool doesn't have a directory, oh well
                }
            }
        }
    }
    $aliases = $pulledaliases;
    $authorities = $pulledauthorities;
    return $config;
}
 /**
  * returns true if $fileinfo describes a model file
  *
  * @param DirectoryIterator $fileinfo
  * @return bool
  */
 protected function _isModelFile(DirectoryIterator $fileinfo)
 {
     $isModel = !$fileinfo->isDot() && !$fileinfo->isLink() && $fileinfo->isFile() && !preg_match('/filter\\.php/i', $fileinfo->getBasename()) && !preg_match('/abstract\\.php/i', $fileinfo->getBasename());
     return $isModel;
 }