This Bundle has been created to show how to create a custom Annotation in deSymfony 2013 Conference.
You will find more information about Annotations at Annotations: it’s not a part of my program, but it’s my program.
This bundle provides an easy way to disable an Action or a Controller. You will be able to disable directly, after a date/time, until a date/time or by a date/time range. You also be able to show a disabled message or redirect the request to another route.
If you're using the bin/vendors.php
method to manage your vendor libraries,
add the following entries to the deps
in the root of your project file:
[FerrandiniDisableBundle]
git=http://github.com/aferrandini/DisableBundle.git
target=/bundles/Ferrandini/Bundle/DisableBundle
Next, update your vendors by running:
$ ./bin/vendors
Finally, add the following entry to your autoloader:
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'Ferrandini' => __DIR__.'/../vendor/bundles',
));
Composer is a project dependency manager for PHP. You have to list
your dependencies in a composer.json
file:
{
"require": {
"aferrandini/disable-bundle": "dev-master"
}
}
To actually install DisableBundle in your project, download the composer binary and run it:
wget http://getcomposer.org/composer.phar
# or
curl -O http://getcomposer.org/composer.phar
php composer.phar install
Finally, enable the bundle in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Ferrandini\Bundle\DisableBundle\FerrandiniDisableBundle(),
);
}
This Bundle provides an easy way to disable a Controller or an Action as you can see in the following examples.
<?php
namespace Foo\Bundle\FooBundle\Controller;
use Ferrandini\Bundle\DisableBundle\Annotations\Disable;
/**
* @Disable()
*/
class FooController {
}
<?php
namespace Foo\Bundle\FooBundle\Controller;
use Ferrandini\Bundle\DisableBundle\Annotations\Disable;
class FooController {
/**
* @Disable()
*/
public function fooAction()
{
// ...
}
}
<?php
namespace Foo\Bundle\FooBundle\Controller;
use Ferrandini\Bundle\DisableBundle\Annotations\Disable;
/**
* @Disable(message="This controller has been disabled with DisableBundle")
*/
class FooController {
}
The date/time has to be defined as a PHP supported date and time format. You can see the supported formats in Supported Date and Time Formats
<?php
namespace Foo\Bundle\FooBundle\Controller;
use Ferrandini\Bundle\DisableBundle\Annotations\Disable;
/**
* @Disable(until="2013-11-11 11:11")
*/
class FooController {
}
<?php
namespace Foo\Bundle\FooBundle\Controller;
use Ferrandini\Bundle\DisableBundle\Annotations\Disable;
/**
* @Disable(after="2013-11-11 11:11")
*/
class FooController {
}
<?php
namespace Foo\Bundle\FooBundle\Controller;
use Ferrandini\Bundle\DisableBundle\Annotations\Disable;
/**
* @Disable(until="2013-06-11", after="2013-11-11")
*/
class FooController {
}
The route should be a defined route name in the routing configuration.
<?php
namespace Foo\Bundle\FooBundle\Controller;
use Ferrandini\Bundle\DisableBundle\Annotations\Disable;
/**
* @Disable(redirect="_welcome")
*/
class FooController {
}
<?php
namespace Foo\Bundle\FooBundle\Controller;
use Ferrandini\Bundle\DisableBundle\Annotations\Disable;
/**
* @Disable(statusCode=404)
*/
class FooController {
}