Source of file Controller.php

Size: 1,829 Bytes - Last Modified: 2015-12-22T09:12:14-05:00

../src/Controller.php

1234567891011121314151617181920212223242526272829303132333435363738394041424344
Covered by 3 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
45
Covered by 3 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
46
Covered by 3 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
47
Covered by 3 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
48
Covered by 3 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
495051
Covered by 3 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
52
Covered by 3 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
535455
Covered by 3 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
56
Covered by 3 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
57
Covered by 3 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
5859
Covered by 3 test(s):
  • MvcLite\ControllerTest::testInit
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
606162636465666768
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
6970717273747576
Covered by 2 test(s):
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
7778
<?php
/**
 * Base Controller
 *
 * @category    PHP
 * @package     MvcLite
 * @subpackage  Controller
 * @since       File available since release 1.0.1
 * @author      Cory Collier <corycollier@corycollier.com>
 */

namespace MvcLite;

use MvcLite\Traits\Request as RequestTrait;
use MvcLite\Traits\Response as ResponseTrait;
use MvcLite\Traits\Session as SessionTrait;
use MvcLite\Traits\Filepath as FilepathTrait;
use MvcLite\Traits\View as ViewTrait;

/**
 * Base Controller
 *
 * @category    PHP
 * @package     MvcLite
 * @subpackage  Controller
 * @since       Class available since release 1.0.1
 * @author      Cory Collier <corycollier@corycollier.com>
 */
class Controller extends ObjectAbstract
{
    use RequestTrait;
    use ResponseTrait;
    use SessionTrait;
    use FilepathTrait;
    use ViewTrait;

    /**
     * Hook run immediately after the constructing of a controller.
     *
     * @return MvcLite\Controller Returns $this, for object-chaining.
     */
    public function init()
    {
        $request    = $this->getRequest();
        $controller = $request->getParam('controller');
        $action     = $request->getParam('action');
        $view       = $this->getView();
        $path       = $this->filepath([APP_PATH, 'view', 'scripts', $controller]);

        // setup the view
        $view->addViewScriptPath($path);
        $view->setScript($action);

        // if the request is not ajax, then setup the layout
        if (!$request->isAjax()) {
            $view->setLayout('default');
        }

        return $this;
    }

    /**
     * Hook run before the dispatching of a request is started.
     */
    public function preDispatch()
    {

    }

    /**
     * Hook run after the dispatching of a request is completed.
     */
    public function postDispatch()
    {

    }
}