我正在寻找类似的东西:http://knplabs.com/blog/give-your-projects-a-gaufrette谢谢。
只是使用Gaufrette,我也这样做(即使在ZF2项目)!
php composer.phar require knplabs/gaufrette:0.1.*
您可以在应用程序的任何地方使用它,并最终通过在YourNamespaceModule#getServiceConfig
中定义它来将其作为服务使用:
namespace YourNamespace;
use ZendModuleManagerFeatureServiceProviderInterface;
use ZendModuleManagerFeatureConfigProviderInterface;
use ZendServiceManagerServiceLocatorInterface;
use GaufretteFilesystem;
use GaufretteAdapterLocal as LocalFs;
class Module implements ServiceProviderInterface, ConfigProviderInterface
{
public function getConfig()
{
return array(
'your_namespace' => array(
'filesystem' => array(
'base_path' => 'data/files',
),
),
);
}
public function getServiceConfig()
{
return array(
'factories' => array(
'YourNamespaceFilesystem' => function (ServiceLocatorInterface $sl) {
$config = $sl->get('Config');
$basePath = $config['your_namespace']['filesystem']['base_path'];
return new Filesystem(new LocalFs($basePath, true));
},
),
);
}
}
然后您可以在整个应用程序中使用服务YourNamespaceFilesystem
。
我也使用它与SymfonyFilesystem
一起处理文件移动/复制/检查操作。并不是所有东西都必须来自Zend Framework 2才能在ZF2应用中使用。