RouteBootstrap.php 1.93 KB
<?php

namespace App\Bootstrap;

use App\BootstrapInterface;
use App\Constants\Services;
use Phalcon\Config;
use Phalcon\DiInterface;
use PhalconRest\Api;
use Google_Client;
use Google_Service_AnalyticsReporting;

class RouteBootstrap implements BootstrapInterface
{
    public function run(Api $api, DiInterface $di, Config $config)
    {
        $api->get('/', function() use ($api) {

            /** @var \Phalcon\Mvc\View\Simple $view */
            $view = $api->di->get(Services::VIEW);

            return $view->render('general/index');
        });

        $api->get('/proxy.html', function() use ($api, $config) {

            /** @var \Phalcon\Mvc\View\Simple $view */
            $view = $api->di->get(Services::VIEW);

            $view->setVar('client', $config->clientHostName);
            return $view->render('general/proxy');
        });

        $api->get('/documentation.html', function() use ($api, $config) {

            /** @var \Phalcon\Mvc\View\Simple $view */
            $view = $api->di->get(Services::VIEW);

            $view->setVar('title', $config->application->title);
            $view->setVar('description', $config->application->description);
            $view->setVar('documentationPath', $config->hostName . '/export/documentation.json');
            return $view->render('general/documentation');
        });

        $api->get('/test.html', function() use ($api) {

            /** @var \Phalcon\Mvc\View\Simple $view */
            $view = $api->di->get(Services::VIEW);

            $client = new Google_Client();
            $api_key = 'AIzaSyCXzrwqxLN2bCvBhw2cJfdeEu9aj1aH5b8';
            $client->setDeveloperKey($api_key);
            $analytics = new Google_Service_AnalyticsReporting($client);

            $var_2 = var_dump($analytics);

            $msg = "testing fine";

            return $view->render('general/test', [
                'var1' => $msg,
                'var2' => $var_2
            ]);
        });
    }
}