nachonerd / silex-finder-provider
这是一个Silex服务提供商,同时也是Symfony Finder的包装器
1.1.1
2015-09-11 23:47 UTC
Requires
- php: >=5.4.0
- silex/silex: ^1.3
- symfony/finder: ^2.7
Requires (Dev)
- phpunit/phpunit: 4.7.*
- squizlabs/php_codesniffer: 2.*
This package is not auto-updated.
Last update: 2024-09-28 18:05:24 UTC
README
许可证
GPL-3.0
需求
安装
composer require nachonerd/silex-finder-provider
使用方法
在您的初始Silex文件(index.php等)中包含以下行代码:
... $app->register(new \NachoNerd\Silex\Finder\Provider()); ...
现在您可以通过 $app['nn.finder'] 访问finder的实例。
示例
<?php require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); // Considering the config.yml files is in the same directory as index.php $app->register(new \NachoNerd\Silex\Finder\Provider()); ... $finder = $app["nn.finder"]; $finder->files()->in(__DIR__); foreach ($finder as $file) { // Dump the absolute path var_dump($file->getRealpath()); // Dump the relative path to the file, omitting the filename var_dump($file->getRelativePath()); // Dump the relative path to the file var_dump($file->getRelativePathname()); } ...
版本 1.1.0 中有什么新功能?
添加了新的降序排序方法
原始finder中的方法都是升序排序。我添加了降序排序方法。
- sortByModifiedTimeDesc
<?php require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); // Considering the config.yml files is in the same directory as index.php $app->register(new \NachoNerd\Silex\Finder\Provider()); ... $finder = $app["nn.finder"]; $finder->files()->sortByModifiedTimeDesc()->in(__DIR__); foreach ($finder as $file) { // Dump the absolute path var_dump($file->getRealpath()); } ...
- sortByChangedTimeDesc
<?php require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); // Considering the config.yml files is in the same directory as index.php $app->register(new \NachoNerd\Silex\Finder\Provider()); ... $finder = $app["nn.finder"]; $finder->files()->sortByChangedTimeDesc()->in(__DIR__); foreach ($finder as $file) { // Dump the absolute path var_dump($file->getRealpath()); } ...
- sortByAccessedTimeDesc
<?php require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); // Considering the config.yml files is in the same directory as index.php $app->register(new \NachoNerd\Silex\Finder\Provider()); ... $finder = $app["nn.finder"]; $finder->files()->sortByAccessedTimeDesc()->in(__DIR__); foreach ($finder as $file) { // Dump the absolute path var_dump($file->getRealpath()); } ...
- sortByTypeDesc
<?php require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); // Considering the config.yml files is in the same directory as index.php $app->register(new \NachoNerd\Silex\Finder\Provider()); ... $finder = $app["nn.finder"]; $finder->files()->sortByTypeDesc()->in(__DIR__); foreach ($finder as $file) { // Dump the absolute path var_dump($file->getRealpath()); } ...
- sortByNameDesc
<?php require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); // Considering the config.yml files is in the same directory as index.php $app->register(new \NachoNerd\Silex\Finder\Provider()); ... $finder = $app["nn.finder"]; $finder->files()->sortByNameDesc()->in(__DIR__); foreach ($finder as $file) { // Dump the absolute path var_dump($file->getRealpath()); } ...
添加了获取N个第一个文件或目录的方法
现在您可以获取前N个文件或目录。如果您将此新方法与新的降序排序方法结合使用,则可以获取最后首先的文件或目录。
<?php require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); // Considering the config.yml files is in the same directory as index.php $app->register(new \NachoNerd\Silex\Finder\Provider()); ... $finder = $app["nn.finder"]; $finder->files()->sortByChangedTimeDesc()->in(__DIR__); $finder = $finder->getNFirst(10); foreach ($finder as $file) { // Dump the absolute path var_dump($file->getRealpath()); } ...
<?php require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); // Considering the config.yml files is in the same directory as index.php $app->register(new \NachoNerd\Silex\Finder\Provider()); ... $finder = $app["nn.finder"]; $finder->files()->in(__DIR__); $finder = $finder->getNFirst(10); foreach ($finder as $file) { // Dump the absolute path var_dump($file->getRealpath()); } ...