digitalkaoz / gaufrette-browser-bundle
This bundle provides an integration of the KnpMenu library
Installs: 267
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- aferrandini/urlizer: 1.0.0
- knplabs/knp-gaufrette-bundle: ~0.1
Requires (Dev)
Suggests
- sensio/framework-extra-bundle: for using the param-converters for file and directory
This package is not auto-updated.
Last update: 2024-12-21 16:10:17 UTC
README
This Bundle allows you to browse a Gaufrette Filesystem like a Doctrine Connection. It tries to wrap Doctrine ObjectRepositories and Entities around Gaufrette Files.
Installation
Install it with Composer
{ "require" : { "digitalkaoz/gaufrette-browser-bundle" : "dev-master@dev" } }
Active the Bundle in your Kernel
// application/AppKernel.php public function registerBundles() { return array( // ... new rs\GaufretteBrowserBundle\rsGaufretteBrowserBundle(), // ... ); }
Import the Routing
rs_gaufrette_browser: resource: "@rsGaufretteBrowserBundle/Resources/config/routing.xml" prefix: /gaufrette/browser
Configuration
Create a Gaufrette Filesystem (see https://github.com/KnpLabs/KnpGaufretteBundle for more Installation and Configuration)
knp_gaufrette: adapters: default: local: directory: /your/path/ filesystems: default: adapter: default alias: default_filesystem stream_wrapper: ~
Connect the Browser to the Filesystem
rs_gaufrette_browser: filesystem: default_filesystem #the gaufrette filesystem alias to use
The Full Config Reference
rs_gaufrette_browser: file_pattern: "/\.(jpg|gif|jpeg|png)$/" # a valid regular expression to filter for file-extensions filesystem: default_filesystem # the gaufrette filesystem alias to use file_class: Your\File\Class # should extend rs\GaufretteBrowserBundle\Entity\File directory_class: Your\Directory\Class # should extend rs\GaufretteBrowserBundle\Entity\Directory
Usage
Goto http://your.domain/gaufrette/browser and browse the filesystem
Querying for Directories or Files
Using the Repository Implementations:
$this->get('rs_gaufrette_browser.repository.directory')->findBy(array('prefix'=>'/foo')); #only search folders that starts with /foo $this->get('rs_gaufrette_browser.repository.file')->findBy(array('suffix'=>'/\.xls/')); #only search .xls files $this->get('rs_gaufrette_browser.repository.file')->find('/foo/bar.png'); #find one file $this->get('rs_gaufrette_browser.repository.file')->findOneBy(array('prefix'=>'/foo', 'suffix' => '/\.xls/')); #find one file named /foo/*.xls
Using the ParamConverters
Using ParamConverters for Directory
and File
is quiet simple:
/** * @ParamConverter("folder", class="rs\GaufretteBrowserBundle\Entity\Directory", options={"id" = "slug"}) */ public function myCustomDirectoryAction(Request $request, Directory $folder){} /** * @ParamConverter("file", class="rs\GaufretteBrowserBundle\Entity\File", options={"id" = "slug"}) */ public function myCustomFileAction(Request $request, File $file){}
Hooking into Events
Everything inside the Controller-Actions is build up with Events.
The following Events exists
final class GaufretteBrowserEvents { const DIRECTORY_SHOW = 'gaufrette.directory.show'; const DIRECTORY_INDEX = 'gaufrette.directory.index'; const FILE_SHOW = 'gaufrette.file.show'; const FILE_INDEX = 'gaufrette.file.index'; }
Hook your own Functionality into default Controllers
implement the Subscriber
class MyEventSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( GaufretteBrowserEvents::DIRECTORY_INDEX => 'myCustomAction' ); } public function myCustomAction(DirectoryControllerEvent $event) { $event->addDirectory($myCustomDirectory); $event->removeDirectory($unwantedDirectory); $event->addTemplateData('myCustomVar', 'foobar'); } }
and TAG the Service
<service id="my.custom.event_subscriber" class="\MyEventSubscriber"> <tag name="kernel.event_subscriber" /> </service>
Tests
everything is well unit tested:
phpunit
view builds on Travis: https://travis-ci.org/digitalkaoz/GaufretteBrowserBundle
TODO
- better Tree Initialization of Directories (maybe https://github.com/KnpLabs/materialized-path)
- Javascript-Tree to Browse Files more sophisticated (maybe http://jquery.bassistance.de/treeview/demo/)
- better File Detail Pages
- functional Tests
- allow more gaufrette-filesystem instances
- more powerful Repository Queries