Esempio n. 1
0
File: App.php Progetto: ovide/phest
 /**
  * Constructs the app.
  *
  * Checks singleton instance
  * Adds a dependency injector if none provided
  * Sets the notFound handler
  *
  * @param  FactoryDefault    $dependencyInjector
  * @throws \RuntimeException
  */
 public function __construct($dependencyInjector = null)
 {
     if (self::$app === null) {
         if ($dependencyInjector === null) {
             $dependencyInjector = new FactoryDefault();
         }
         $dependencyInjector->setShared('response', Response::class);
         $dependencyInjector->setShared('router', Router::class);
         if (!$dependencyInjector->has('eventsManager')) {
             $dependencyInjector->setShared('eventsManager', \Phalcon\Events\Manager::class);
         }
         if (!$dependencyInjector->has('request')) {
             $dependencyInjector->setShared('request', \Phalcon\Http\Request::class);
         }
         parent::__construct($dependencyInjector);
         self::$app = $this;
         $this->setEventsManager($dependencyInjector->getShared('eventsManager'));
         $this->addHeaderHandler(new HeaderHandler\Accept());
         $app = self::$app;
         $this->_errorHandler = function (\Exception $ex) {
             return $this->errorHandler($ex);
         };
         $this->_notFoundHandler = function () {
             return $this->notFoundHandler();
         };
     } else {
         throw new \RuntimeException("Can't instance App more than once");
     }
 }
Esempio n. 2
0
 /**
  * 初始化view
  */
 protected function initView()
 {
     $config = $this->config;
     $debug = $this->debug;
     $this->di->setShared('view', function () use($config, $debug) {
         $view = new View();
         $view->setViewsDir($config->application->viewsDir);
         $viewEngines = ['.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'];
         if ($config->offsetExists('volt')) {
             $viewEngines['.volt'] = function ($view, $di) use($config, $debug) {
                 $volt = new VoltEngine($view, $di);
                 $volt->setOptions(array('compiledPath' => $config->volt->cacheDir, 'compiledExtension' => ".compiled", 'compiledSeparator' => '_', 'compileAlways' => $debug));
                 $compiler = $volt->getCompiler();
                 foreach ($config->volt->extension as $k => $v) {
                     $compiler->addExtension($v);
                 }
                 foreach ($config->volt->func as $k => $v) {
                     $compiler->addFunction($k, $v);
                 }
                 $filterList = $config->volt->filter;
                 foreach ($filterList as $k => $v) {
                     $compiler->addFilter($k, $v);
                 }
                 return $volt;
             };
         }
         $view->registerEngines($viewEngines);
         return $view;
     });
 }
Esempio n. 3
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     /**
      * Create default DI.
      */
     $di = new DI\FactoryDefault();
     /**
      * Get config.
      */
     $this->_config = Config::factory();
     if (!$this->_config->installed) {
         define('CHECK_REQUIREMENTS', true);
         require_once PUBLIC_PATH . '/requirements.php';
     }
     /**
      * Setup Registry.
      */
     $registry = new Registry();
     $registry->modules = array_merge([self::SYSTEM_DEFAULT_MODULE, 'user'], $this->_config->modules->toArray());
     $registry->widgets = $this->_config->widgets->toArray();
     $registry->directories = (object) ['engine' => ROOT_PATH . '/app/engine/', 'modules' => ROOT_PATH . '/app/modules/', 'plugins' => ROOT_PATH . '/app/plugins/', 'widgets' => ROOT_PATH . '/app/widgets/', 'libraries' => ROOT_PATH . '/app/libraries/'];
     $di->set('registry', $registry);
     // Store config in the DI container.
     $di->setShared('config', $this->_config);
     parent::__construct($di);
 }
Esempio n. 4
0
 /**
  * Bootstrap constructor.
  */
 public function __construct()
 {
     $di = new FactoryDefault();
     $em = new EventsManager();
     $em->enablePriorities(true);
     $config = $this->initConfig();
     // Register the configuration itself as a service
     $di->setShared('config', $config);
     $this->app = new Application();
     $this->initLogger($di, $config, $em);
     $this->initLoader($di, $config, $em);
     foreach ($this->loaders as $service) {
         $serviceName = ucfirst($service);
         $this->{'init' . $serviceName}($di, $config, $em);
     }
     $di->setShared('eventsManager', $em);
     $di->setShared('app', $this->app);
     $this->app->setEventsManager($em);
     $this->app->setDI($di);
 }
Esempio n. 5
0
 /**
  * Constructor of the App
  */
 public function __construct()
 {
     $di = new DI\FactoryDefault();
     $this->_config = config('config');
     $registry = new Registry();
     $registry->directories = (object) ['modules' => APP_PATH . '/modules/', 'engine' => APP_PATH . '/engine/', 'library' => APP_PATH . '/library/'];
     $di->set('registry', $registry);
     $di->setShared('config', $this->_config);
     $eventsManager = new EventsManager();
     $this->setEventsManager($eventsManager);
     $this->_initLogger($di, $this->_config);
     $this->_initLoader($di, $this->_config, $eventsManager);
     foreach ($this->_loaders as $service) {
         $serviceName = ucfirst($service);
         $eventsManager->fire('init:before' . $serviceName, null);
         $result = $this->{'_init' . $serviceName}($di, $this->_config, $eventsManager);
         $eventsManager->fire('init:after' . $serviceName, $result);
     }
     $di->setShared('eventsManager', $eventsManager);
     $this->_noAuthPages = array();
 }
Esempio n. 6
0
 private function mvcDi()
 {
     $c = $this->config();
     $di = new FactoryDefault();
     //TODO:url
     //Register a session container
     $di->setShared('session', function () use($c) {
         $session = new SessionAdapter();
         session_set_cookie_params(0, '/', $c->hostname);
         $session->start();
         return $session;
     });
     //Register rendering mechanism
     $di->setShared('view', function () {
         $view = new View();
         $view->registerEngines(['.phtml' => 'PhalconZ\\Lib\\PhpViewEngine']);
         return $view;
     });
     $di->setShared('config', $this->config());
     $di->set('router', $this->mvcRouter());
     $this->database($di);
     return $di;
 }
Esempio n. 7
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     /**
      * Create default DI.
      */
     $di = new DI\FactoryDefault();
     /**
      * Get config.
      */
     $this->_config = Config::factory();
     /**
      * Adding modules to registry to load.
      * Module namespace - directory will be load from here.
      */
     $registry = new PhRegistry();
     $registry->modules = array_merge([self::SYSTEM_DEFAULT_MODULE], $this->_config->modules->toArray());
     $registry->directories = (object) ['engine' => ROOT_PATH . '/app/engine/', 'modules' => ROOT_PATH . '/app/modules/'];
     $di->set('registry', $registry);
     /**
      * Store config in the DI container.
      */
     $di->setShared('config', $this->_config);
     parent::__construct($di);
 }
Esempio n. 8
0
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;
use Phalcon\Session\Adapter\Files as SessionAdapter;
use Phalcon\Filter;
use App\Lib\Facebook\Facebook;
use App\Lib\OAuth\ApiStorage;
/**
 * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
 */
$di = new FactoryDefault();
/**
 * Set shared config.
 */
$di->setShared('config', function () use($config) {
    return $config;
});
/**
 * The URL component is used to generate all kind of urls in the application.
 */
$di->setShared('url', function () use($config) {
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});
/**
 * Database connection is created based in the parameters defined in the configuration file.
 */
$di->setShared('db', function () use($config) {
    $dbConfig = $config->database->toArray();
    $adapter = $dbConfig['adapter'];
Esempio n. 9
0
use Phalcon\Mvc\View;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;
use Phalcon\Session\Adapter\Files as SessionAdapter;
use Phalcon\Flash\Direct as Flash;
$di = new FactoryDefault();
$di->set('dispatcher', function () {
    $dispatcher = new Dispatcher();
    $dispatcher->setDefaultNamespace("TestApp\\Controllers");
    return $dispatcher;
});
$di->setShared('url', function () use($config) {
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});
$di->setShared('view', function () use($config) {
    $view = new View();
    $view->setViewsDir($config->application->viewsDir);
    $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
        $volt = new VoltEngine($view, $di);
        $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
        return $volt;
    }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
    return $view;
});
$di->setShared('db', function () use($config) {
    $dbConfig = $config->database->toArray();
    $adapter = $dbConfig['adapter'];
Esempio n. 10
0
/**
 * The URL component is used to generate all kind of urls in the application
 */
$di->set('url', function () use($config) {
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);
    return $url;
}, true);
/**
 * Setting up the view component
 */
$di->setShared('view', function () use($config) {
    $view = new View();
    $view->setViewsDir($config->application->viewsDir);
    $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
        $volt = new VoltEngine($view, $di);
        $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
        return $volt;
    }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
    return $view;
});
/**
 * Database connection is created based in the parameters defined in the configuration file
 */
$di->set('db', function () use($config) {
    return new DbAdapter($config->database->toArray());
});
/**
 * If the configuration specify the use of metadata adapter use it or use memory otherwise
 */
$di->set('modelsMetadata', function () {
    return new MetaDataAdapter();
Esempio n. 11
0
        });
    } else {
        if ($config->database->modelsMetadata == 'Xcache') {
            $di->set('modelsMetadata', function () {
                $metaData = new Phalcon\Mvc\Model\Metadata\Xcache(array('prefix' => 'igo', 'lifetime' => 86400));
                return $metaData;
            });
        }
    }
}
/**
 * Start the session the first time some component request the session service
 */
$di->setShared('session', function () {
    $session = new SessionAdapter();
    session_name('sessionIGO');
    $session->start();
    return $session;
});
/**
* Ajout du routing pour le navigateur construit, en utilisant les paramètres REST plutot que KVP.
*/
$di->set('router', function () {
    $router = new \Phalcon\Mvc\Router();
    //Define a route
    $router->add("/contexte/{contexte}", array("controller" => "igo", "action" => "contexte", "contexteid" => 1));
    $router->add("/configuration/{configuration}", array("controller" => "igo", "action" => "configuration", "configuration" => 1));
    $router->add("/couche/{coucheId}", array("controller" => "igo", "action" => "couche", "coucheid" => 1));
    $router->add("/groupe/{groupeId}", array("controller" => "igo", "action" => "groupe", "coucheid" => 1));
    $router->setDefaults(array('controller' => 'index', 'action' => 'index'));
    return $router;
});
Esempio n. 12
0
if ((bool) $config->develop->debug === true) {
    $debug = new \Phalcon\Debug();
    $debug->listen();
    define('DEBUG', true);
} else {
    define('DEBUG', false);
}
// Setup the view component
$di->set('view', function () {
    $view = new View();
    $view->setViewsDir(APP_PATH . 'app/views/');
    $view->registerEngines(array(".volt" => 'Phalcon\\Mvc\\View\\Engine\\Volt', ".phtml" => 'Phalcon\\Mvc\\View\\Engine\\Volt'));
    return $view;
});
$di->set('elements', function () {
    return new Elements();
});
// Setup a base URI
$di->set('url', function () use($config) {
    $url = new UrlProvider();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});
// Set session
$di->setShared('session', function () {
    $session = new Session();
    $session->start();
    return $session;
});
$debug = new \Phalcon\Debug();
$debug->listen();
Esempio n. 13
0
 /**
  * Execute Phalcon Developer Tools
  *
  * @param  string             $path The path to the Phalcon Developer Tools
  * @param  string             $ip   Optional IP address for securing Developer Tools
  * @return void
  * @throws \Exception         if Phalcon extension is not installed
  * @throws \Exception         if Phalcon version is not compatible Developer Tools
  * @throws \Phalcon\Exception if Application config could not be loaded
  */
 public static function main($path, $ip = null)
 {
     if (!extension_loaded('phalcon')) {
         throw new \Exception("Phalcon extension isn't installed, follow these instructions to install it: " . 'https://docs.phalconphp.com/en/latest/reference/install.html');
     }
     if ($ip !== null) {
         self::$ip = $ip;
     }
     if (!defined('TEMPLATE_PATH')) {
         define('TEMPLATE_PATH', $path . '/templates');
     }
     $basePath = dirname(getcwd());
     // Dirs for search config file
     $configDirs = array($basePath . '/config/', $basePath . '/app/config/', $basePath . '/apps/frontend/config/', $basePath . '/apps/backend/config/');
     $config = null;
     foreach ($configDirs as $configPath) {
         if (file_exists($configPath . 'config.ini')) {
             $config = new ConfigIni($configPath . 'config.ini');
             break;
         } elseif (file_exists($configPath . 'config.php')) {
             $config = (include $configPath . 'config.php');
             if (is_array($config)) {
                 $config = new Config($config);
             }
             break;
         } elseif (file_exists($configPath . 'config.yaml')) {
             $config = new YamlConfig($configPath . 'config.yaml');
             break;
         } elseif (file_exists($configPath . 'config.json')) {
             $config = new JsonConfig($configPath . 'config.json');
             break;
         }
     }
     if (null === $config) {
         throw new Exception(sprintf("Configuration file couldn't be loaded! Scanned dirs: %s", implode(', ', $configDirs)));
     }
     $loader = new Loader();
     $loader->registerDirs(array($path . '/scripts/', $path . '/scripts/Phalcon/Web/Tools/controllers/'));
     $loader->registerNamespaces(array('Phalcon' => $path . '/scripts/'));
     $loader->register();
     if (Version::getId() < Script::COMPATIBLE_VERSION) {
         throw new \Exception(sprintf("Your Phalcon version isn't compatible with Developer Tools, download the latest at: %s", Script::DOC_DOWNLOAD_URL));
     }
     try {
         $di = new FactoryDefault();
         $di->setShared('view', function () use($path) {
             $view = new View();
             $view->setViewsDir($path . '/scripts/Phalcon/Web/Tools/views/');
             return $view;
         });
         $di->setShared('config', $config);
         $di->setShared('url', function () use($config) {
             $url = new Url();
             if (isset($config->application->baseUri)) {
                 $baseUri = $config->application->baseUri;
             } elseif (isset($config->baseUri)) {
                 $baseUri = $config->baseUri;
             } else {
                 $baseUri = '/';
             }
             $url->setBaseUri($baseUri);
             return $url;
         });
         $di->setShared('flash', function () {
             return new Flash(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning'));
         });
         $di->setShared('db', function () use($config) {
             if (isset($config->database->adapter)) {
                 $adapter = $config->database->adapter;
             } else {
                 $adapter = 'Mysql';
             }
             if (is_object($config->database)) {
                 $configArray = $config->database->toArray();
             } else {
                 $configArray = $config->database;
             }
             $className = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter;
             unset($configArray['adapter']);
             return new $className($configArray);
         });
         self::$di = $di;
         $app = new Application();
         $app->setDi($di);
         echo $app->handle()->getContent();
     } catch (Exception $e) {
         echo get_class($e), ': ', $e->getMessage(), "<br>";
         echo nl2br($e->getTraceAsString());
     } catch (\PDOException $e) {
         echo get_class($e), ': ', $e->getMessage(), "<br>";
         echo nl2br($e->getTraceAsString());
     }
 }
Esempio n. 14
0
 * Database connection is created based in the parameters defined in the configuration file
 */
$di->set('db', function () use($config) {
    return new DbAdapter($config->toArray());
});
$di->set('mailgun', function () use($config) {
    return $config->mailgun;
});
/**
 * If the configuration specify the use of metadata adapter use it or use memory otherwise
 */
$di->set('modelsMetadata', function () {
    return new MetaDataAdapter();
});
/**
 * Start the session the first time some component request the session service
 */
$di->setShared('session', function () {
    $session = new SessionAdapter();
    //check if session hasnt already started
    if ($session->session_id != "") {
        $session->start();
    }
    return $session;
});
/**
 * Setup flash messages for alerts
 */
$di->set('flash', function () {
    return new \Phalcon\Flash\Session(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-warning'));
}, true);
Esempio n. 15
0
/**
 * The URL component is used to generate all kinds of URLs in the application
 */
$di->set('url', function () {
    $url = new UrlResolver();
    $url->setBaseUri('/@@name@@/');
    return $url;
});
/**
 * Setting up the view component
 */
$di->setShared('view', function () use($config) {
    $view = new View();
    $view->setViewsDir($config->application->viewsDir);
    $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
        $volt = new VoltEngine($view, $di);
        $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
        return $volt;
    }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
    return $view;
});
/**
 * Database connection is created based in the parameters defined in the configuration file
 */
$di->set('db', function () use($config) {
    return new DbAdapter($config->database->toArray());
});
/**
 * If the configuration specify the use of metadata adapter use it or use memory otherwise
 */
$di->set('modelsMetadata', function () {
    return new MetaDataAdapter();
Esempio n. 16
0
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;
use Phalcon\Session\Adapter\Files as SessionAdapter;
/**
 * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
 */
$di = new FactoryDefault();
/**
 * The URL component is used to generate all kind of urls in the application
 */
$di->setShared('url', function () use($config) {
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});
/**
 * Setting up the view component
 */
$di->setShared('view', function () use($config) {
    $view = new View();
    return $view;
});
/**
 * Database connection is created based in the parameters defined in the configuration file
 */
$di->setShared('db', function () use($config) {
    $dbConfig = $config->database->toArray();
    $adapter = $dbConfig['adapter'];
};
*/
/**
 * The URL component is used to generate all kind of urls in the application
 */
$di->set('url', function () use($config) {
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});
// <editor-fold defaultstate="collapsed" desc="user-description">
/**
 * Database connection is created based in the parameters defined in the configuration file
 */
$di->setShared('niuniudb', function () use($config) {
    return new MysqlPdo(array("host" => $config->niudatabase->host, "username" => $config->niudatabase->username, "password" => $config->niudatabase->password, "dbname" => $config->niudatabase->dbname, "options" => array()));
});
// the main db for oauth token/ client
$di->setShared('db', function () use($config) {
    return new MysqlPdo(array("host" => $config->oauthdb->host, "username" => $config->oauthdb->username, "password" => $config->oauthdb->password, "dbname" => $config->oauthdb->dbname, "options" => array()));
});
$di->setShared('oauthredis', function () use($config) {
    $redis = new BackendRedis(new Phalcon\Cache\Frontend\Json(array("lifetime" => 1800)), array('host' => $config->redis->host, 'port' => $config->redis->port, 'auth' => $config->redis->auth, 'index' => 0, 'persistent' => false));
    return $redis;
});
$di->setShared('oauthcode', function () use($config) {
    $redis = new BackendRedis(new Phalcon\Cache\Frontend\Json(array("lifetime" => 1800)), array('host' => $config->redis->host, 'port' => $config->redis->port, 'auth' => $config->redis->auth, 'index' => 1, 'persistent' => false));
    return $redis;
});
$di->setShared('oauthtoken', function () use($config) {
    $redis = new BackendRedis(new Phalcon\Cache\Frontend\Json(array("lifetime" => 3600)), array('host' => $config->redis->host, 'port' => $config->redis->port, 'auth' => $config->redis->auth, 'index' => 2, 'persistent' => false));
Esempio n. 18
0
use Phalcon\Http\Response\Cookies;
use Library\Phalcon\Events\Manager as EventsManager;
use Plugin\Exception as ExceptionPlugin;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Mvc\View\Engine\Volt;
$di = new FactoryDefault();
$di['config'] = $config;
$di['session'] = function () {
    $session = new SessionAdapter();
    $session->start();
    return $session;
};
$di->set('httpClient', '\\Guzzle\\Http\\Client');
$di['modelsManager'] = '\\Library\\Phalcon\\Mvc\\Model\\Manager';
$di->setShared('db', ['className' => '\\Phalcon\\Db\\Adapter\\Pdo\\Mysql', 'arguments' => [['type' => 'parameter', 'value' => $config->database->toArray()]]]);
$di->setShared('modelsMetadata', ['className' => $config->cache->metadata->className, 'arguments' => [['type' => 'parameter', 'value' => $config->cache->metadata->options->toArray()]]]);
$di->setShared('modelsCacheFrontend', ['className' => $config->cache->models->frontend->className, 'arguments' => [['type' => 'parameter', 'value' => $config->cache->models->frontend->options->toArray()]]]);
$di->setShared('servicesCacheFrontend', ['className' => $config->cache->services->frontend->className, 'arguments' => [['type' => 'parameter', 'value' => $config->cache->services->frontend->options->toArray()]]]);
$di->setShared('viewCacheFrontend', ['className' => $config->cache->view->frontend->className, 'arguments' => [['type' => 'parameter', 'value' => $config->cache->view->frontend->options->toArray()]]]);
$di->setShared('modelsCache', ['className' => $config->cache->models->backend->className, 'arguments' => [['type' => 'service', 'name' => 'modelsCacheFrontend'], ['type' => 'parameter', 'value' => $config->cache->models->backend->options->toArray()]]]);
$di->setShared('servicesCache', ['className' => $config->cache->services->backend->className, 'arguments' => [['type' => 'service', 'name' => 'servicesCacheFrontend'], ['type' => 'parameter', 'value' => $config->cache->services->backend->options->toArray()]]]);
$di->setShared('viewCache', ['className' => $config->cache->view->backend->className, 'arguments' => [['type' => 'service', 'name' => 'viewCacheFrontend'], ['type' => 'parameter', 'value' => $config->cache->view->backend->options->toArray()]]]);
$di->setShared('eventsManager', '\\Library\\Phalcon\\Events\\Manager');
$di->setShared('dispatcher', function () use($di) {
    /** @var EventsManager $evManager */
    $evManager = $di->getShared('eventsManager');
    $evManager->attach('dispatch', new ExceptionPlugin());
    $dispatcher = new Dispatcher();
    $dispatcher->setEventsManager($evManager);
    return $dispatcher;
Esempio n. 19
0
 /**
  * Register services used by the frontend application
  *
  * @param $di
  */
 public function registerServices(FactoryDefault $di)
 {
     $config = $this->config();
     /**
      * register the dispatcher
      */
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         /*$eventManager = new Manager();
                     $eventManager->attach('dispatch', new \Acl('frontend'));
         
                     $dispatcher->setEventsManager($eventManager);*/
         $dispatcher->setDefaultNamespace('app\\frontend\\controllers');
         return $dispatcher;
     });
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di->set('url', function () use($config) {
         $url = new UrlResolver();
         $url->setBaseUri($config->application->baseUri);
         return $url;
     }, true);
     $di->setShared('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->application->viewsDir);
         $view->registerEngines(['.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(['compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_']);
             /**
              * add functions to compiler
              */
             VoltHelper::registerViewFunctions($volt, VoltHelper::getUtil(['ng']));
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php']);
         return $view;
     });
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di->set('db', function () use($config) {
         return new MysqlAdapter($config->database->toArray());
     });
     /**
      * If the configuration specify the use of metadata adapter use it or use memory otherwise
      */
     $di->set('modelsMetadata', function () {
         return new MetaDataAdapter();
     });
     /**
      * Start the session the first time some component request the session service
      */
     $di->setShared('session', function () {
         $session = new SessionAdapter();
         $session->start();
         return $session;
     });
     /**
      * Set the auth component
      */
     $di->set('auth', function () {
         $auth = new Auth();
         $auth->setSuccessUrl('/index/index');
         $auth->setFailUrl('session/login');
         return $auth;
     });
     //        /**
     //         * List of assets that need to be loaded
     //         */
     //        $di->setShared('asset_config', function () {
     //            return require_once(APP_PATH . '/frontend/config/assets.php');
     //        });
 }
Esempio n. 20
0
use Phalcon\Mvc\Application;
use Phalcon\DI\FactoryDefault;
use Phalcon\Mvc\Url as UrlProvider;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
use Phalcon\Http\Response\Cookies;
use Phalcon\Session\Adapter\Files;
require "../app/config/Config.php";
try {
    // Register an autoloader
    $loader = new Loader();
    $loader->registerDirs(array('../app/controllers/', '../app/models/', '../app/config/', '../app/libraries/'))->register();
    // Create a DI
    $di = new FactoryDefault();
    // return DB config
    $di->setShared('config', function () use($config) {
        return $config;
    });
    // Database
    $di->set('db', function () use($di) {
        $dbconfig = $di->get('config')->get('db')->toArray();
        $db = new DbAdapter($dbconfig);
        return $db;
    });
    // Setup the view component
    $di->set('view', function () {
        $view = new View();
        $view->setViewsDir('../app/views/');
        $view->registerEngines([".volt" => 'Phalcon\\Mvc\\View\\Engine\\Volt']);
        return $view;
    });
    // Setup a base URI so that all generated URIs include the "tutorial" folder
Esempio n. 21
0
 */
$di = new FactoryDefault();
/**
 * Return array of the Collections, which define a group of routes, from
 * routes/collections.  These will be mounted into the app itself later.
 */
$di->set('collections', function () {
    return include './routes/routeLoader.php';
});
/**
 * $di's setShared method provides a singleton instance.
 * If the second parameter is a function, then the service is lazy-loaded
 * on its first instantiation.
 */
$di->setShared('config', function () {
    return new IniConfig("config/config.ini");
});
// As soon as we request the session service, it will be started.
$di->setShared('session', function () {
    $session = new \Phalcon\Session\Adapter\Files();
    $session->start();
    return $session;
});
$di->set('modelsCache', function () {
    //Cache data for one day by default
    $frontCache = new \Phalcon\Cache\Frontend\Data(array('lifetime' => 3600));
    //File cache settings
    $cache = new \Phalcon\Cache\Backend\File($frontCache, array('cacheDir' => __DIR__ . '/cache/'));
    return $cache;
});
/**
Esempio n. 22
0
 */
$di->set('url', function () use($config) {
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);
    return $url;
}, true);
/**
 * Setting up the view component
 */
$di->setShared('view', function () use($config) {
    $view = new View();
    $view->setViewsDir($config->application->viewsDir);
    $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
        $volt = new VoltEngine($view, $di);
        $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
        $volt->getCompiler()->addFilter('t', function ($resolvedArgs, $exprArgs) use($di) {
            return '$this->getDI()->get("translate")->_(' . $resolvedArgs . ')';
        });
        return $volt;
    }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
    return $view;
});
/**
 * Database connection is created based in the parameters defined in the configuration file
 */
$di->set('db', function () use($config) {
    return new DbAdapter($config->database->toArray());
});
/**
 * If the configuration specify the use of metadata adapter use it or use memory otherwise
 */
Esempio n. 23
0
/**
 * Services are globally registered in this file
 *
 * @var \Phalcon\Config $config
 */
use Phalcon\Mvc\View\Simple as View;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Di\FactoryDefault;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
$di = new FactoryDefault();
/**
 * Sets the view component
 */
$di->setShared('view', function () use($config) {
    $view = new View();
    $view->setViewsDir($config->application->viewsDir);
    return $view;
});
/**
 * The URL component is used to generate all kind of urls in the application
 */
$di->set('url', function () use($config) {
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});
/**
 * Database connection is created based in the parameters defined in the configuration file
 */
$di->set('db', function () use($config) {
    return new DbAdapter($config->database->toArray());
Esempio n. 24
0
use Phalcon\Crypt;
use Phalcon\Security;
$T = new \PHPBenchTime\Timer();
$T->start();
/**
 * The DI is our direct injector.
 * It will store pointers to all of our services
 * and we will insert it into all of our controllers.
 *
 * @var DefaultDI
 */
$di = new DefaultDI();
$di->setShared('request', function () {
    // $request = new \PhalconRest\Libraries\Request\Request();
    $request = new Request();
    // we expect inputs to be camel, so we convert to snake for server side
    $request->defaultCaseFormat = 'snake';
    return $request;
});
// stopwatch service to track
$di->setShared('stopwatch', function () use($T) {
    // start the stopwatch
    return $T;
});
// hold messages that should be returned to the client
$di->setShared('messageBag', function () {
    return new \PhalconRest\Libraries\MessageBag\MessageBag();
});
/**
 * Return array of the Collections, which define a group of routes, from
 * routes/collections.
Esempio n. 25
0
/**
 * Start the session the first time some component request the session service
 */
$di->set('session', function () use($di) {
    $sessionAdapter = $di->get('config')->application->session->adapter;
    $session = new $sessionAdapter($di->get('config')->application->session->options->toArray());
    $session->start();
    return $session;
}, true);
/**
 * This service controls the initialization of models, keeping record of relations
 * between the different models of the application.
 */
$di->setShared('collectionManager', function () use($eventsManager) {
    $collectionManager = new CollectionManager();
    $collectionManager->setEventsManager($eventsManager);
    return $collectionManager;
});
$di->setShared('modelsManager', function () use($eventsManager) {
    $modelsManager = new ModelsManager();
    $modelsManager->setEventsManager($eventsManager);
    return $modelsManager;
});
// Set the views cache service
$di->set('viewCache', function () use($di) {
    $config = $di->get('config');
    if ($config->application->debug) {
        return new MemoryBackend(new FrontendNone());
    } else {
        // Cache data for one day by default
        $frontCache = new FrontendOutput(['lifetime' => $config->cache->lifetime]);
Esempio n. 26
0
        //        "password" => "haha",
        //        "dbname"   => "anj",
        //        "options" => array(
        //            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4'
        //        )
        //    )
        //);
        //      //// Assign the eventsManager to the db adapter instance
        //$connection->setEventsManager($eventsManager);
        //      //return $connection;
        return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => "localhost", "username" => "root", "password" => "haha", "dbname" => "anj", "options" => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4')));
    };
    // Setup a base URI so that all generated URIs include the "tutorial" folder
    //$di->set('url', function () {
    //$url = new UrlProvider();
    //$url->setBaseUri('/public/index.php?_url=/');
    //return $url;
    //});
    $di->setShared('session', function () {
        $session = new Phalcon\Session\Adapter\Files();
        $session->start();
        return $session;
    });
    // Handle the request
    $application = new Application($di);
    $application->registerModules(array('frontend' => array('className' => 'Multiple\\Frontend\\Module', 'path' => '../apps/frontend/Module.php'), 'backend' => array('className' => 'Multiple\\Backend\\Module', 'path' => '../apps/backend/Module.php')));
    //require "/../app/controllers/BaseController.php";
    echo $application->handle()->getContent();
} catch (\Exception $e) {
    echo "PhalconException: ", $e->getMessage();
}
Esempio n. 27
0
 */
$di = new FactoryDefault();
/**
 * The URL component is used to generate all kind of urls in the application
 */
$di->set('url', function () use($config) {
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);
    return $url;
}, true);
/**
 * The Dispatcher component
 */
$di->setShared('dispatcher', function () use($di) {
    $eventsManager = $di->getShared('eventsManager');
    $dispatcher = new Dispatcher();
    $dispatcher->setEventsManager($eventsManager);
    return $dispatcher;
});
/**
 * Setting up the view component
 */
$di->set('view', function () use($config) {
    $view = new View();
    $view->setViewsDir($config->application->viewsDir);
    $view->setRenderLevel(View::LEVEL_ACTION_VIEW);
    $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
        $volt = new VoltEngine($view, $di);
        $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_', 'compileAlways' => true));
        //add filter functions
        $compiler = $volt->getCompiler();
        $compiler->addFilter('uniform_time', function ($resolvedArgs, $exprAgs) {
Esempio n. 28
0
use Phalcon\Db\Adapter\Pdo\Mysql as PdoMysql;
use Phalcon\Paginator\Adapter\Model as PaginatorModel;
use Phalcon\Session\Adapter\Files as Session;
require __DIR__ . '../../vendor/autoload.php';
// Use Loader() to autoload classes
$loader = new Loader();
//Register dirs from which the autoloader should load classes
$loader->registerDirs(array(__DIR__ . '/models/', __DIR__ . '/library/'))->register();
//New Dependency Injector
$di = new FactoryDefault();
//Run config.php
require __DIR__ . '/config/config.php';
// Start the session the first time when some component request the session service
$di->setShared('session', function () {
    $session = new Session();
    $session->start();
    return $session;
});
//Set shared Facebook SDK
$di->setShared('facebook', function () {
    return new Facebook\Facebook(['app_id' => '976309079106997', 'app_secret' => '3d08707832a17ab10369f4f0643618aa', 'default_graph_version' => 'v2.4']);
});
//Set request object
$di->set("request", "Phalcon\\Http\\Request", true);
//Instantiate Phalcon Micro framework
$app = new Micro();
$app->setDI($di);
//Create response object
$response = new Response();
/**
 * Get random image
Esempio n. 29
0
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;
use Phalcon\Session\Adapter\Files as SessionAdapter;
/**
 * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
 */
$di = new FactoryDefault();
/**
 * Register config
 */
$di->setShared('config', $config);
/**
 * Registering a dispatcher
 */
$di->set('dispatcher', function () {
    $dispatcher = new \Phalcon\Mvc\Dispatcher();
    $dispatcher->setDefaultNamespace('Tools\\Controllers');
    return $dispatcher;
});
/**
 * Register routers
 */
$di->setShared('router', function () use($config) {
    $router = new \Phalcon\Mvc\Router();
    $router->removeExtraSlashes(true);
    $router->setDefaults(array('namespace' => 'Tools\\Controllers', 'controller' => 'index', 'action' => 'index'));
Esempio n. 30
0
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Di\FactoryDefault;
use Phalcon\Session\Adapter\Files as SessionAdapter;
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;
use Phalcon\Mvc\View;
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
/**
 * The FactoryDefault Dependency Injector automatically registers the right services to provide a full stack framework
 */
$di = new FactoryDefault();
/**
 * Registering a router
 */
$di->setShared('router', function () {
    $router = new Router();
    $router->setDefaultModule('core');
    $router->setDefaultNamespace('Phlame\\Core\\Controllers');
    return $router;
});
/**
 * The URL component is used to generate all kinds of URLs in the application
 */
$di->setShared('url', function () use($config) {
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});
/**
 * Setting up the view component
 */
//$di->setShared('view', function () use ($config) {
//$view = new View();