<commit_before>Controllers
===========

Using a base controller
-----------------------

Flint makes it easy to have controllers behave like in Symfony. This is done by having a 
base controller ``Flint\Controller\Controller`` which implements most of the methods
found in the base controller from Symfony

.. code-block:: php

    <?php

    namespace Skeleton\Controller;

    use Flint\Controller\Controller;

    class DefaultController extends Controller
    {
        public function indexAction()
        {
            return $this->render('index.html.twig');
        }

        public function showAction($id)
        {
            // Theoretic example where the application is used inside an action.
            $model = $this->app['repository']->get($id);

            return $this->render('show.html.twig', compact('model'));
        }
    }

ApplicationAware controllers
----------------------------

The base controller gets the ``Application`` injected into it because it implements a
special interface called ``Flint\ApplicationAwareInterface``. The default behaviour
with injecting the ``Application`` or ``Request`` is kept intact if they are typehinted
in the actions parameters.<commit_msg>add code example for normal method injected variables<commit_after>Controllers
===========

Using a base controller
-----------------------

Flint makes it easy to have controllers behave like in Symfony. This is done by having a 
base controller ``Flint\Controller\Controller`` which implements most of the methods
found in the base controller from Symfony

.. code-block:: php

    <?php

    namespace Skeleton\Controller;

    use Flint\Controller\Controller;

    class DefaultController extends Controller
    {
        public function indexAction()
        {
            return $this->render('index.html.twig');
        }

        public function showAction($id)
        {
            // Theoretic example where the application is used inside an action.
            $model = $this->app['repository']->get($id);

            return $this->render('show.html.twig', compact('model'));
        }
    }

ApplicationAware controllers
----------------------------

The base controller gets the ``Application`` injected into it because it implements a
special interface called ``Flint\ApplicationAwareInterface``. The default behaviour
with injecting the ``Application`` or ``Request`` is kept intact if they are typehinted
in the actions parameters.

.. code-block:: php

    <?php

    namespace Skeleton\Controller;

    use Flint\Application;
    use Flint\Controller\Controller;
    use Symfony\Component\HttpFoundation\Request;

    class DefaultController extends Controller
    {
        public function indexAction(Request $request, Application $app)
        {
            // Request is injected when method is called by ControllerResolver
            // Application is also injected.
        }
    }
{'fraction_non_alphanumeric': 0.11861501542680837, 'fraction_numerical': 0.0, 'mean_word_length': 2.6248447204968945, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4970027', 'n_tokens_mistral': 698, 'n_tokens_neox': 658, 'n_words': 262}