Using Symfony’s Routing component with annotations in your custom app

This was a bit of a pain to get going originally, but once it’s up, it works great!

I used composer which generated the autoload.php file used at the top, and from there I used Symfony2’s ClassLoader for autoloading my own annotation classes & other classes which are being scanned & reflected.

Code below;

<?

require_once( "vendor/autoload.php" );

use Doctrine\Common\Annotations\AnnotationRegistry;
 use Doctrine\Common\Annotations\FileCacheReader;
 use Doctrine\Common\Annotations\AnnotationReader;
 use Symfony\Component\Config\FileLocator;
 use Symfony\Component\Routing\Loader\AnnotationClassLoader;
 use Symfony\Component\Routing\Route;
 use Symfony\Component\ClassLoader\UniversalClassLoader;

// ------------------------------------------------------------------------------

class MyAnnotationClassLoader extends AnnotationClassLoader {

protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
 {
 // TODO: Implement configureRoute() method.
 echo 'configure route here' . "\n";
 }
 }

$loader = new UniversalClassLoader();
 $loader->registerNamespace('Symfony', __DIR__.'/vendor/symfony/routing');
 $loader->registerNamespace('Entities', __DIR__.'/controllers');
 $loader->register();

AnnotationRegistry::registerLoader(array($loader, "loadClass"));

// ------------------------------------------------------------------------------

$reader = new FileCacheReader(
 new AnnotationReader(),
 __DIR__ . "/cache",
 $debug = true
 );

$locator = new FileLocator();
 $annotationLoader = new MyAnnotationClassLoader($reader);

$dirLoader = new \Symfony\Component\Routing\Loader\AnnotationDirectoryLoader($locator, $annotationLoader);
 $routes = $dirLoader->load(__DIR__ . '/controllers');

print_r($routes);

Basically you need to make sure your classes are saved as per http://symfony.com/PSR0, and then you can start going ahead and using the @Route(…) annotation as needed.

See;

Vagrant / Chef

http://robin.wenglewski.de/posts/2013/03/16/automatically-deploy-applications-and-infrastructure/
http://docs-v1.vagrantup.com/v1/docs/getting-started/provisioning.html

Awesome >> http://leopard.in.ua/2013/01/04/chef-solo-getting-started-part-1/
http://leopard.in.ua/2013/01/05/chef-solo-getting-started-part-2/

http://wiki.opscode.com/plugins/viewsource/viewpagesrc.action?pageId=1179893

http://jbbarth.com/posts/2011-03-20-vagrant-provisioning-with-chefsolo.html

Vagrant boxes: http://www.vagrantbox.es/

Debugging: http://docs-v1.vagrantup.com/v1/docs/debugging.html

$ VAGRANT_LOG=INFO vagrant up

For;

FATAL: LoadError: no such file to load -- treetop

Do:

sudo gem install treetop

To sort out;

FATAL: ArgumentError: wrong number of arguments (2 for 1)

Do (previous version of ruby (1.8.7) has a bug in it):

sudo aptitude install ruby1.9.1-full

To get rid of;

[default] Running provisioner: Vagrant::Provisioners::ChefSolo... The chef binary (either `chef-solo` or `chef-client`) was not found on the VM and is required for chef provisioning. Please verify that chef is installed and that the binary is available on the PATH.

Do;

$ vagrant ssh
$ sudo gem install chef --no-rdoc --no-ri

When using librarian-chef, update librarian, then remove librarian 0.0.26;

sudo gem uninstall librarian
 (choose to remove v0.0.26)
sudo gem install librarian-chef

.

.

Uploadify & PHP Sessions

Secured sites need the following parameter passed across;

session_id: <?= session_id() ?>

And somewhere in the code it should pick this up out of the $_REQUEST variable and set it … basically the problem lies in flash (what uploadify uses) not using the same session data as your browser, thus in flash’s eyes you seem logged out and it can’t do much in the way of sending files to where they need to go.