/**
  * @requires PHP 5.6
  */
 public function testFilenameListIsGenerated()
 {
     $sfFinder = $this->getMockBuilder('\\Symfony\\Component\\Finder\\Finder')->disableOriginalConstructor()->getMock();
     $filesystem = $this->getMockBuilder('\\Helmich\\TypoScriptLint\\Util\\Filesystem')->disableOriginalConstructor()->getMock();
     $fib = $this->getMockBuilder('SplFileInfo')->disableOriginalConstructor();
     $fi1 = $fib->getMock();
     $fi1->expects($this->any())->method('isFile')->willReturn(FALSE);
     $fi2 = $fib->getMock();
     $fi2->expects($this->any())->method('isFile')->willReturn(TRUE);
     $fi3 = $fib->getMock();
     $fi3->expects($this->any())->method('isFile')->willReturn(TRUE);
     $fi4 = $fib->getMock();
     $fi4->expects($this->any())->method('getPathname')->willReturn('directory/file3');
     $fi5 = $fib->getMock();
     $fi5->expects($this->any())->method('getPathname')->willReturn('directory/file4');
     $sfFinder->expects($this->once())->method('files')->willReturnSelf();
     $sfFinder->expects($this->once())->method('in')->with('directory');
     $sfFinder->expects($this->once())->method('getIterator')->willReturn(new \ArrayObject([$fi4, $fi5]));
     $finder = new Finder($sfFinder, $filesystem);
     $filesystem->expects($this->at(0))->method('openFile')->with('directory')->willReturn($fi1);
     $filesystem->expects($this->at(1))->method('openFile')->with('file1')->willReturn($fi2);
     $filesystem->expects($this->at(2))->method('openFile')->with('file2')->willReturn($fi3);
     $filenames = $finder->getFilenames(['directory', 'file1', 'file2']);
     $this->assertEquals(['directory/file3', 'directory/file4', 'file1', 'file2'], $filenames);
 }
Exemple #2
0
 public function testClearCache()
 {
     $dir = Renderer::getCacheDir();
     Renderer::clearCache();
     $finder = new Finder();
     $finder->files()->name('*.php')->in($dir);
     $this->assertEquals(0, $finder->count());
 }
 /**
  * Shows user's profile.
  *
  * @param int $id
  *
  * @return \yii\web\Response
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionShow($id)
 {
     $profile = $this->finder->findProfileById($id);
     if ($profile === null) {
         throw new NotFoundHttpException();
     }
     return $this->render('show', ['profile' => $profile]);
 }
Exemple #4
0
 public function addFinder(Finder $finder)
 {
     if (!empty($this->finders[$finder->getName()])) {
         throw new ServiceBuilderException("Duplicate finder name '{$finder->getName()}' for entity '{$this->name}'");
     }
     foreach ($finder->getColumns() as $finderColumn) {
         if (empty($this->properties[$finderColumn->getName()])) {
             //throw new ServiceBuilderException("Finder column '{$finderColumn->getName()}' is not a property for entity '$this->name'");
         }
     }
     $this->finders[$finder->getName()] = $finder;
 }
Exemple #5
0
 /**
  * Deletes a directory
  *
  * @param boolean $recursive
  *
  * @return boolean
  */
 public function delete($recursive = false)
 {
     if (!$recursive) {
         return parent::delete();
     }
     $finder = new Finder();
     $contents = $finder->listContents($this->path);
     foreach ($contents as $item) {
         $item->delete(true);
     }
     return parent::delete();
 }
Exemple #6
0
function main()
{
    $fridge_csv_path = isset($argv[1]) ? $argv[1] : 'fridge.csv';
    $recipe_json_path = isset($argv[2]) ? $argv[2] : 'recipes.js';
    $ingredients = array_map('str_getcsv', file($fridge_csv_path));
    $recipes = json_decode(file_get_contents($recipe_json_path), 1);
    $fridge = new Fridge();
    $fridge->fillFromArray($ingredients);
    $finder = new Finder($fridge);
    $recipeToday = $finder->findRecipe($recipes);
    echo $recipeToday . "\n";
}
 protected function getThemes()
 {
     $themes = array();
     $dir = $this->container->getParameter('kernel.root_dir') . '/../web/themes';
     $finder = new Finder();
     foreach ($finder->directories()->in($dir)->depth('== 0') as $directory) {
         $theme = $this->getTheme($directory->getBasename());
         if ($theme) {
             $themes[] = $theme;
         }
     }
     return $themes;
 }
Exemple #8
0
 /**
  * Randomly runs garbage collection on the image directory
  *
  * @return bool
  */
 public function collectGarbage()
 {
     if (!mt_rand(1, $this->gcFreq) == 1) {
         return false;
     }
     $this->createFolderIfMissing();
     $finder = new Finder();
     $criteria = sprintf('<= now - %s minutes', $this->expiration);
     $finder->in($this->webPath . '/' . $this->imageFolder)->date($criteria);
     foreach ($finder->files() as $file) {
         unlink($file->getPathname());
     }
     return true;
 }
Exemple #9
0
 /**
  * @param int $maxLines zero means all
  * @return array of strings
  */
 public function getAll($maxLines = 0)
 {
     $output = array();
     foreach ($this->finder->orderByMTime() as $value) {
         $output = array_merge($output, array_reverse(file($value)));
     }
     if ($maxLines > 0) {
         $output = array_slice($output, 0, $maxLines);
     }
     array_walk($output, function (&$item) {
         $item = htmlspecialchars($item);
     });
     return $output;
 }
Exemple #10
0
 public function testFindRecipeFunction()
 {
     $fridge = $this->getFridge();
     $idealRecipes = $this->getRecipesData();
     $finder = new Finder($fridge);
     $result1 = $finder->findRecipe($idealRecipes);
     $this->assertEquals($result1, 'grilled cheese on toast');
     $newRecipe2 = array('name' => 'extra cheese and peanut butter on bread', 'ingredients' => array(0 => array('item' => 'bread', 'amount' => '2', 'unit' => 'slices'), 1 => array('item' => 'cheese', 'amount' => '10', 'unit' => 'slices'), 2 => array('item' => 'peanut butter', 'amount' => '250', 'unit' => 'grams')));
     $result2 = $finder->findRecipe(array_merge($idealRecipes, array($newRecipe2)));
     $this->assertEquals($result2, 'extra cheese and peanut butter on bread');
     $newRecipe3 = array('name' => 'expired salad', 'ingredients' => array(0 => array('item' => 'mixed salad', 'amount' => '200', 'unit' => 'grams')));
     $result3 = $finder->findRecipe(array($newRecipe3));
     $this->assertEquals($result3, 'Order Takeout');
 }
Exemple #11
0
 /**
  * Zip files
  *
  * @param string $targetDir Target dir path
  * @param array  $files     Files to zip
  *
  * @throws \Exception
  */
 private function zipFiles($targetDir, $files)
 {
     $zip = new \ZipArchive();
     $zipName = pathinfo($files[0], PATHINFO_FILENAME);
     $zipPath = FileSystem::getUniquePath($targetDir . DIRECTORY_SEPARATOR . $zipName . ".zip");
     if ($zip->open($zipPath, \ZipArchive::CREATE)) {
         foreach ($files as $file) {
             $path = $targetDir . DIRECTORY_SEPARATOR . $file;
             if (is_dir($path)) {
                 $zip->addEmptyDir($file);
                 foreach (Finder::find("*")->from($path) as $item) {
                     $name = $file . DIRECTORY_SEPARATOR . substr_replace($item->getPathname(), "", 0, strlen($path) + 1);
                     if ($item->isDir()) {
                         $zip->addEmptyDir($name);
                     } else {
                         $zip->addFile($item->getRealPath(), $name);
                     }
                 }
             } else {
                 $zip->addFile($path, $file);
             }
         }
         $zip->close();
     } else {
         throw new \Exception("Can not create ZIP archive '{$zipPath}' from '{$targetDir}'.");
     }
 }
Exemple #12
0
 /**
  * show the data in an input element for editing
  *
  * @return string
  */
 protected function getWriteDisplay()
 {
     $selectedOptionNames = explode(', ', $this->value);
     $output = Html::startTag('div', ['class' => $this->class]);
     $connectedClassName = $this->fieldinfo->getConnectedClass();
     /** @var BaseConnectionObject $connObj */
     $connObj = new $connectedClassName();
     $class = $connObj->getOtherClass($this->fieldinfo->getClass());
     $obj = Factory::createObject($class);
     $connectedFieldName = $this->fieldinfo->getFieldsOfConnectedClass();
     $table = DB::table($obj->getTable());
     $result = Finder::create($class)->find([$table->getColumn($connectedFieldName), $table->getColumn('LK')]);
     foreach ($result as $row) {
         $params = [];
         $params['value'] = $row['LK'];
         $params['type']  = 'checkbox';
         $params['class'] = 'checkbox';
         $params['name']  = $this->name . '[]';
         if (in_array($row[$connectedFieldName], $selectedOptionNames)) {
             $params['checked'] = 'checked';
         }
         $output .= Html::startTag('p') . Html::singleTag('input', $params) . " " . $row[$connectedFieldName] . Html::endTag('p');
     }
     $output .= Html::endTag('div');
     return $output;
 }
 public function testJoinNtoN()
 {
     $finder = Finder::like()->like_user->user;
     $schema = new Schemas\Infered();
     $query = $schema->generateQuery($finder);
     $this->assertEquals('SELECT like.*, like_user.*, user.* FROM like INNER JOIN like_user ON like_user.like_id = like.id INNER JOIN user ON like_user.user_id = user.id', (string) $query);
 }
Exemple #14
0
 /**
  * Formats the output and saved it to disc.
  *
  * @param   string     $identifier  filename
  * @param   $contents  $contents    language array to save
  * @return  bool       \File::update result
  */
 public function save($identifier, $contents)
 {
     // store the current filename
     $file = $this->file;
     // save it
     $return = parent::save($identifier, $contents);
     // existing file? saved? and do we need to flush the opcode cache?
     if ($file == $this->file and $return and static::$flush_needed) {
         if ($this->file[0] !== '/' and (!isset($this->file[1]) or $this->file[1] !== ':')) {
             // locate the file
             if ($pos = strripos($identifier, '::')) {
                 // get the namespace path
                 if ($file = \Autoloader::namespace_path('\\' . ucfirst(substr($identifier, 0, $pos)))) {
                     // strip the namespace from the filename
                     $identifier = substr($identifier, $pos + 2);
                     // strip the classes directory as we need the module root
                     $file = substr($file, 0, -8) . 'lang' . DS . $identifier;
                 } else {
                     // invalid namespace requested
                     return false;
                 }
             } else {
                 $file = \Finder::search('lang', $identifier);
             }
         }
         // make sure we have a fallback
         $file or $file = APPPATH . 'lang' . DS . $identifier;
         // flush the opcode caches that are active
         static::$uses_opcache and opcache_invalidate($file, true);
         static::$uses_apc and apc_compile_file($file);
     }
     return $return;
 }
    public static function config($args, $build = true)
    {
        $args = self::_clear_args($args);
        $file = strtolower(array_shift($args));
        $config = array();
        // load the config
        if ($paths = \Finder::search('config', $file, '.php', true)) {
            // Reverse the file list so that we load the core configs first and
            // the app can override anything.
            $paths = array_reverse($paths);
            foreach ($paths as $path) {
                $config = \Fuel::load($path) + $config;
            }
        }
        unset($path);
        // We always pass in fields to a config, so lets sort them out here.
        foreach ($args as $conf) {
            // Each paramater for a config is seperated by the : character
            $parts = explode(":", $conf);
            // We must have the 'name:value' if nothing else!
            if (count($parts) >= 2) {
                $config[$parts[0]] = $parts[1];
            }
        }
        $overwrite = \Cli::option('o') or \Cli::option('overwrite');
        $content = <<<CONF
<?php
/**
 * Fuel is a fast, lightweight, community driven PHP5 framework.
 *
 * @package\t\tFuel
 * @version\t\t1.0
 * @author\t\tFuel Development Team
 * @license\t\tMIT License
 * @copyright\t2011 Fuel Development Team
 * @link\t\thttp://fuelphp.com
 */


CONF;
        $content .= 'return ' . str_replace('  ', "\t", var_export($config, true)) . ';';
        $content .= <<<CONF


/* End of file {$file}.php */
CONF;
        $path = APPPATH . 'config' . DS . $file . '.php';
        if (!$overwrite and is_file($path)) {
            throw new Exception("APPPATH/config/{$file}.php already exist, please use -overwrite option to force update");
        }
        $path = pathinfo($path);
        try {
            \File::update($path['dirname'], $path['basename'], $content);
            \Cli::write("Created config: APPPATH/config/{$file}.php", 'green');
        } catch (\InvalidPathException $e) {
            throw new Exception("Invalid basepath, cannot update at " . APPPATH . "config" . DS . "{$file}.php");
        } catch (\FileAccessException $e) {
            throw new Exception(APPPATH . "config" . DS . $file . ".php could not be written.");
        }
    }
 private function process_form()
 {
     $domain = Request::getPost('domain');
     if (strlen($domain) < 1) {
         return;
     }
     $this->set_body('form_success', true);
     $url = CrawlerURL::instance($domain);
     $domain = $url->getDomain();
     $link = "{$domain}/";
     $domainObject = Finder::instance('Domain')->setNameFilter($domain)->getDomain();
     if (!$domainObject) {
         $domainObject = Mutator::instance('Domain', 'Create')->setData($domain)->execute();
     }
     $linkObject = Finder::instance('Link')->setNameFilter($link)->getLink();
     if (!$linkObject) {
         $linkObject = Mutator::instance('Link', 'Create')->setData($link)->execute();
     }
     $crawlSiteQueueObject = Finder::instance('CrawlSiteQueue')->setDomainFilter($domainObject->getID())->setStatusFilter(CrawlSiteQueue::$IS_UNCRAWLED)->getCrawlSiteQueue();
     if (!$crawlSiteQueueObject) {
         Mutator::instance('CrawlSiteQueue', 'Create')->setData($domainObject, CrawlSiteQueue::$IS_UNCRAWLED)->execute();
     }
     $crawlPageQueueObject = Finder::instance('CrawlPageQueue')->setDomainFilter($domainObject->getID())->setLinkFilter($linkObject->getID())->setStatusFilter(CrawlPageQueue::$IS_UNCRAWLED)->getCrawlPageQueue();
     if (!$crawlPageQueueObject) {
         Mutator::instance('CrawlPageQueue', 'Create')->setData($domainObject, $linkObject, CrawlPageQueue::$IS_UNCRAWLED)->execute();
     }
 }
 public function load($resource, $type = null)
 {
     if (true === $this->loaded) {
         throw new \RuntimeException('Do not add this loader twice');
     }
     //$modules = $this->doctrine->getRepository('MaximCMSBundle:Module')->findBy(array("activated" => 1));
     $collection = new RouteCollection();
     /* FIND ROUTING FILES IN BUNDLES AND LOAD THOSE */
     $exclude = array("CMSBundle", "InstallBundle", "AdminBundle");
     $names = array("routing.yml", "routing_admin.yml");
     for ($i = 0; $i < count($names); $i++) {
         $finder = new Finder();
         $finder->name($names[$i]);
         foreach ($finder->in(__DIR__ . "/../../")->exclude($exclude) as $file) {
             $locator = new FileLocator(array(substr($file, 0, count($file) - (strlen($names[$i]) + 1))));
             $loader = new YamlFileLoader($locator);
             $collection->addCollection($loader->load($names[$i]));
         }
     }
     return $collection;
     /*if (true === $this->loaded) {
                 throw new \RuntimeException('Do not add this loader twice');
             }
     
             $collection = new RouteCollection();
                                      echo "hi";
             // get all Bundles
             $bundles = $this->container->getParameter('kernel.bundles');
             foreach($bundles as $bundle) {
                 if(isset($bundle)) {
     
                        echo $bundle;
     
                 }
             }
     
     
             /*$resource = '@AcmeDemoBundle/Resources/config/import_routing.yml';
             $type = 'yaml';
     
             $importedRoutes = $this->import($resource, $type);
     
             $collection->addCollection($importedRoutes);
     
             return $collection;          */
 }
 /**
  * @param \Elastica_Index $index
  * @param Parameters $parameter
  */
 public function __construct(\Elastica_Index $index, Parameters $parameters)
 {
     $this->addColumn('name', t('Area name'), true, 'link');
     $this->addColumn('town', t('Town name'));
     $this->addColumn('canton', t('Canton'));
     $this->addColumn('user', t('User'));
     parent::__construct($index, 'area', $parameters);
 }
Exemple #19
0
 /**
  * @return array
  */
 public static function getInstalledPhps()
 {
     static $phps;
     if (!isset($phps)) {
         $phps = [];
         $finder = new Finder();
         $finder->directories()->in('/opt/phpbrew/php')->depth('== 0');
         foreach ($finder as $file) {
             $phpbin = $file->getPathname() . '/bin/php';
             if (!file_exists($phpbin)) {
                 continue;
             }
             $phps[] = $file->getFilename();
         }
     }
     return $phps;
 }
Exemple #20
0
 /**
  * Loads a view as a string
  * Used by Base_Controller->render() method to load a view
  *
  * @param	string	View name to load
  * @param	sring	Directory where is the view
  *
  * @return	string	The load view
  *
  */
 public static function load($name, $directory = 'views')
 {
     $file = Finder::find_file($name, $directory, true);
     if (empty($file)) {
         show_error('Theme error : <b>The file "' . $directory . '/' . $name . '" cannot be found.</b>');
     }
     $string = file_get_contents(array_shift($file));
     return $string;
 }
 /**
  * {@inheritdoc}
  */
 public function all() : MapInterface
 {
     $files = Finder::create()->in($this->path);
     $map = new Map('string', FileInterface::class);
     foreach ($files as $file) {
         $map = $map->put($file->getRelativePathname(), $this->get($file->getRelativePathname()));
     }
     return $map;
 }
Exemple #22
0
 /**
  * set data
  */
 public function setData()
 {
     $obj = Factory::createObject('News');
     $table = DB::table($obj->getTable());
     $limit = new base_database_Limit(10);
     $order = DB::order($table->getColumn('firstEditTime'));
     $finder = Finder::create('news')->setOrder($order)->setlimit($limit);
     $this->data = $finder->find();
 }
 /**
  * Finds the given config files
  *
  * @param   bool  $multiple  Whether to load multiple files or not
  * @return  array
  */
 protected function find_file()
 {
     $paths = \Finder::search('config', $this->file, $this->ext, true);
     $paths = array_merge(\Finder::search('config/' . \Fuel::$env, $this->file, $this->ext, true), $paths);
     if (count($paths) > 0) {
         return array_reverse($paths);
     }
     throw new \ConfigException(sprintf('File "%s" does not exist.', $this->file));
 }
Exemple #24
0
 /**
  * Constructor.
  *
  * @access  public
  * @param   int  $latency    Latency (in seconds).
  * @return  void
  */
 public function __construct($latency = null)
 {
     parent::__construct();
     $this->_on = new \Hoa\Core\Event\Listener($this, array('new', 'modify', 'move'));
     if (null !== $latency) {
         $this->setLatency($latency);
     }
     return;
 }
Exemple #25
0
 /**
  * Load a Language from Identifier
  *
  * @param string $langIdentifier
  *
  * @return bool
  *
  * @since 1.0.0
  */
 public function loadLanguageIdentifier($langIdentifier, $suffix = '')
 {
     $lang_path = Finder::getInstance()->getPath($langIdentifier, $suffix . '.ini');
     if (file_exists($lang_path)) {
         $this->strings = empty($this->strings) ? parse_ini_file($lang_path) : array_merge($this->strings, parse_ini_file($lang_path));
         return true;
     }
     return false;
 }
 public function getDomain()
 {
     if (!isset($this->domain)) {
         $domain = Finder::instance('Domain')->setNameFilter($this->site)->getDomain();
         if (!$domain) {
             trigger_error("CrawlerSite tried to pull an invalid domain {$this->site}!");
         }
         $this->domain = $domain;
     }
     return $this->domain;
 }
 /**
  * @param \Elastica_Index $index
  * @param Parameters $parameter
  */
 public function __construct(\Elastica_Index $index, Parameters $parameters)
 {
     $this->addColumn('name_la', t('Latin name'));
     $this->addColumn('name', t('German name'));
     $this->addColumn('user', t('User'));
     $this->addColumn('inventory', t('Inventory'), true, 'link', array($this, 'permission'));
     $this->addColumn('town', t('Town name'));
     $this->addColumn('canton', t('Canton'));
     $this->addColumn('date', t('Observation date'), true, 'date');
     $this->addColumn('redlist', t('Red list'), false, 'translate');
     Finder::__construct($index, 'sighting', $parameters);
 }
Exemple #28
0
 public function mapFieldValue($value)
 {
     $obj = Factory::createObject('vendor');
     $table = DB::table($obj->getTable());
     $where = DB::where($table->getColumn('name'), DB::term($value));
     $finder = Finder::create('vendor')->setWhere($where);
     $result = $finder->find(array($table->getColumn('LK')));
     if (count($result) > 1) {
         throw new base_exception_Mapper(TMS('medexchange.exception.mapper.vendorDuplicatedEntry'));
     }
     $lkArray = $result[0];
     return $lkArray['LK'];
 }
 private function parseCSV()
 {
     $ignoreFirstLine = $this->csvParsingOptions['ignoreFirstLine'];
     $finder = new Finder();
     $finder->files()->in($this->csvParsingOptions['finder_in'])->name($this->csvParsingOptions['finder_name']);
     foreach ($finder as $file) {
         $csv = $file;
     }
     $rows = array();
     if (($handle = fopen($csv->getRealPath(), "r")) !== FALSE) {
         $i = 0;
         while (($data = fgetcsv($handle, null, ";")) !== FALSE) {
             $i++;
             if ($ignoreFirstLine && $i == 1) {
                 continue;
             }
             $rows[] = $data;
         }
         fclose($handle);
     }
     return $rows;
 }
Exemple #30
0
 /**
  * Return array of existing backup files 
  * @param string $path
  * @return array of SplFileInfo 
  */
 public function getBackups($path)
 {
     $files = array();
     $finder = Finder::findFiles('*.zip')->in($path . 'backups/');
     try {
         foreach ($finder->orderByName() as $file) {
             $files[] = $file->getBasename();
         }
         return array_reverse($files);
     } catch (UnexpectedValueException $e) {
         return array();
     }
 }