Volkszaehler\Router::handle PHP Method

handle() public method

Handle the request Source: Symfony\Component\HttpKernel\HttpKernel
public handle ( Request $request, integer $type = HttpKernelInterface::MASTER_REQUEST, boolean $catch = true ) : Response
$request Symfony\Component\HttpFoundation\Request A Request instance
$type integer The type of the request (for Symfony compatibility, not implemented)
$catch boolean Whether to catch exceptions or not
return Symfony\Component\HttpFoundation\Response A Response instance
    public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
    {
        try {
            // initialize view to ensure StreamedResponse->streamed is false
            $this->view = null;
            // initialize entity manager
            if (null == $this->em || !$this->em->isOpen()) {
                $this->em = self::createEntityManager();
            }
            return $this->handleRaw($request, $type);
        } catch (\Exception $e) {
            if (false === $catch) {
                throw $e;
            }
            return $this->handleException($e, $request, $type);
        }
    }

Usage Example

 * @copyright Copyright (c) 2011, The volkszaehler.org project
 * @package default
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */
/*
 * This file is part of volkzaehler.org
 *
 * volkzaehler.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * volkzaehler.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
 */
namespace Volkszaehler;

use Symfony\Component\HttpFoundation\Request;
define('VZ_DIR', realpath(__DIR__ . '/..'));
require VZ_DIR . '/lib/bootstrap.php';
$router = new Router();
// create Request from PHP global variables
$request = Request::createFromGlobals();
// handle request
$response = $router->handle($request);
$response->send();