本文整理汇总了PHP中Finder类的典型用法代码示例。如果您正苦于以下问题:PHP Finder类的具体用法?PHP Finder怎么用?PHP Finder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Finder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFilenameListIsGenerated
/**
* @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);
}
示例2: testClearCache
public function testClearCache()
{
$dir = Renderer::getCacheDir();
Renderer::clearCache();
$finder = new Finder();
$finder->files()->name('*.php')->in($dir);
$this->assertEquals(0, $finder->count());
}
示例3: addFinder
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;
}
示例4: delete
/**
* 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();
}
示例5: main
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";
}
示例6: getThemes
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;
}
示例7: collectGarbage
/**
* 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;
}
示例8: testFindRecipeFunction
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');
}
示例9: zipFiles
/**
* 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}'.");
}
}
示例10: getWriteDisplay
/**
* 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;
}
示例11: testJoinNtoN
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);
}
示例12: save
/**
* 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;
}
示例13: config
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.");
}
}
示例14: process_form
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();
}
}
示例15: load
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; */
}