teon/symfony

PHP library of common components for Symfony-based applications

v0.3.1 2015-12-06 15:40 UTC

README

PHP library with basic functionality for Symfony-based applications.

How to start using it?

Add these contents to your composer.json:

composer require teon/symfony

Add to your Symfony project

app/AppKernel.php:

<?php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            //...
            new Teon\Symfony\TeonSymfonyBundle(),
            //...
        );

        //...

        return $bundles;
    }

    //...
}

app/AppKernel.php - option no.2:

<?php

use Teon\Symfony\HttpKernel\BaseKernel;

use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends BaseKernel
{
    public function registerBundles()
    {
        $bundles = array(
            //...
            new Teon\Symfony\TeonSymfonyBundle(),
            //...
        );

        //...

        return $bundles;
    }

    //...
}

Use as base of your controllers

MyAbstractController:

<?php

namespace Your\Project\Controller;

use Teon\Symfony\Controller\BaseController;

abstract class MyAbstractController extends BaseController
{
}

MyActualController:

<?php

namespace Your\Project\Controller;

class MyActualController extends MyAbstractController
{
}

Cache and logs chmodding

If you want to chmod to 777 your log and cache dirs automatically, add this to composer.json too:

    "scripts": {
        "post-install-cmd": [
            ...,
            "Teon\\Symfony\\Composer\\ScriptHandler\\CacheChmod777::cacheChmod777",
            "Teon\\Symfony\\Composer\\ScriptHandler\\LogChmod777::logChmod777"
        ],
        "post-update-cmd": [
            ...,
            "Teon\\Symfony\\Composer\\ScriptHandler\\CacheChmod777::cacheChmod777",
            "Teon\\Symfony\\Composer\\ScriptHandler\\LogChmod777::logChmod777"
        ]
    },

Use prepared app.php and app_dev.php

Remove your app/console and replace it with this (DO NOT FORGET THE SHEBANG!):

#!/usr/bin/env php
<?php
define('TEON_SYMFONY_APP_ROOT', dirname(realpath(__DIR__)));
require(TEON_SYMFONY_APP_ROOT .'/vendor/teon/symfony/app/console');

Remove your web/app.php and replace it with this:

<?php
define('TEON_SYMFONY_APP_ROOT', dirname(realpath(__DIR__)));
require(TEON_SYMFONY_APP_ROOT .'/vendor/teon/symfony/web/app.php');

Remove your web/app_dev.php and replace it with this:

<?php
define('TEON_SYMFONY_APP_ROOT', dirname(realpath(__DIR__)));
require(TEON_SYMFONY_APP_ROOT .'/vendor/teon/symfony/web/app_dev.php');

Now create dev-auth.php file in your project's root directory. See web/dev-auth.php-SAMPLE for sample.

Use development autoloader - vendor-dev/...

Projects using composer all have a common shortcoming: it is very inconvenient to develop your project AND its dependencies at the same time. Usually creating symlinks is suggested, from vendor/COMPANY/LIBRARY to somewhereelse/COMPANY/LIBRARY. This is awkward at best, and generally very tiresome.

We offer an alternative: use autoloader-dev.php provided with this package.

Autoloader-dev - how does it work?

So, in your project, you probaby have vendor/ directory where content is maintained by composer, as usual. Now, if you create another directory on the same level called vendor-dev/, and populate it with vendor/package contents (like in vendor/), this autoloader WILL LOAD CLASSES BEFORE COMPOSER'S LOADER KICKS IN.

Autoloader-dev - how to use it?

If you are using web/app_dev.php provided with teon/symfony package, you are already set. Just create vendor-dev/ next to your vendor/ directory and clone your library that you need to work on. Example:

mkdir -p vendor-dev/teon
git clone https://github.com/teonsystems/php-symfony vendor-dev/teon/symfony

Autoloader-dev - .gitignore warning

You should NOT add vendor-dev/ to your .gitignore file! When you are done with your development, your vendor-dev should be empty and every library/package should be pushed and tagged and referenced in your main composer.json, or your co-developers and/or users will not be able to use fresh versions of your projects, as code will be missing.

Autoloader-dev - symlinks are not supported

Symlinks are currently not supported. If you were willing to manage symlinks in the first place, why not just manage them in vendor/ directory directly?