Exemple #1
0
 /**
  * @param $templateName
  * @param $type
  * @throws \pff\Exception\ModuleException
  * @internal param ModuleManager $mm
  * @return array
  */
 private static function checkMobile($templateName, $type)
 {
     $mm = ServiceContainer::get('modulemanager');
     if ($mm->isLoaded('mobile_views')) {
         /** @var \pff\modules\MobileViews $mobileViews */
         $mobileViews = $mm->getModule('mobile_views');
         if ($mobileViews->isMobile() || $mobileViews->getMobileViewOnly()) {
             $tmp = explode('.', $templateName);
             $tmp[0] .= '_mobile';
             $tempTemplateName = implode('.', $tmp);
             if ($type == 'php') {
                 $templatePath = ROOT . DS . 'app' . DS . 'views' . DS . $tempTemplateName;
             } else {
                 // smarty
                 $templatePath = ROOT . DS . 'app' . DS . 'views' . DS . 'smarty' . DS . 'templates' . DS . $tempTemplateName;
             }
             if (file_exists($templatePath)) {
                 return $tempTemplateName;
             } else {
                 return $templateName;
             }
         } else {
             return $templateName;
         }
     } else {
         return $templateName;
     }
 }
Exemple #2
0
 /**
  * @internal param string $url The request URL
  * @internal param Config $config
  * @internal param ModuleManager $moduleManager
  * @internal param HookManager $hookManager
  */
 public function __construct()
 {
     $this->_config = ServiceContainer::get('config');
     $this->_hookManager = ServiceContainer::get('hookmanager');
     $this->_moduleManager = ServiceContainer::get('modulemanager');
     $this->_helperManager = ServiceContainer::get('helpermanager');
 }
 /**
  * Executed before the system startup
  *
  * @return mixed
  */
 public function doBeforeSystem()
 {
     $this->db = ServiceContainer::get('dm');
     session_set_save_handler(array($this, "_open"), array($this, "_close"), array($this, "_read"), array($this, "_write"), array($this, "_destroy"), array($this, "_gc"));
     if (session_status() == PHP_SESSION_NONE) {
         session_start();
     }
 }
Exemple #4
0
 public function __construct($templateName)
 {
     $this->_app = ServiceContainer::get('app');
     $this->_templateFile = $templateName;
     $this->_publicFolder = $this->_app->getExternalPath() . 'app' . DS . 'public' . DS;
     $this->_cssFolder = $this->_app->getExternalPath() . 'app' . DS . 'public' . DS . 'css' . DS;
     $this->_imgFolder = $this->_app->getExternalPath() . 'app' . DS . 'public' . DS . 'img' . DS;
     $this->_jsFolder = $this->_app->getExternalPath() . 'app' . DS . 'public' . DS . 'js' . DS;
     $this->_filesFolder = $this->_app->getExternalPath() . 'app' . DS . 'public' . DS . 'files' . DS;
     $this->_vendorFolder = $this->_app->getExternalPath() . 'app' . DS . 'vendor' . DS;
     $this->updatePaths();
 }
Exemple #5
0
 public function __construct($confFile = 'pff2-monolog/module.conf.local.yaml')
 {
     $this->loadConfig($confFile);
     $this->monolog = new Logger($this->defaultChannelName);
     if ($this->enableFile) {
         $this->monolog->pushHandler(new StreamHandler(ROOT . '/app/logs/' . date("Y-m-d") . '-' . $this->loggerFileName . '.txt'), Logger::INFO);
     }
     if ($this->enableFirePHP && ServiceContainer::get('config')->getConfigData('development_environment')) {
         $this->monolog->pushHandler(new FirePHPHandler());
     }
     if ($this->addFileInfo) {
         $this->monolog->pushProcessor(new IntrospectionProcessor());
     }
 }
 private function initDm()
 {
     $config = new Configuration();
     $conn = new Connection($this->_config->getConfigData('mongo_server'));
     if (true === $this->_config->getConfigData('development_environment')) {
         $cache = new ArrayCache();
         $config->setAutoGenerateHydratorClasses(true);
         $config->setAutoGenerateProxyClasses(true);
     } else {
         $cache = new ApcCache(array('prefix' => $this->_app->getConfig()->getConfigData('app_name')));
         $config->setAutoGenerateHydratorClasses(false);
         $config->setAutoGenerateProxyClasses(false);
     }
     $config->setMetadataCacheImpl($cache);
     $config->setProxyDir(ROOT . DS . 'app' . DS . 'proxies');
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir(ROOT . DS . 'app' . DS . 'hydrators');
     $config->setHydratorNamespace('Hydrators');
     $config->setDefaultDB($this->_config->getConfigData('mongo_dbName'));
     $config->setMetadataDriverImpl(AnnotationDriver::create(ROOT . DS . 'app' . DS . 'models'));
     AnnotationDriver::registerAnnotationClasses();
     $this->_dm = DocumentManager::create($conn, $config);
     ServiceContainer::set()['dm'] = $this->_dm;
 }
Exemple #7
0
 public static function initPimple()
 {
     if (ServiceContainer::$pimple === null) {
         ServiceContainer::$pimple = new Container();
     }
 }
Exemple #8
0
 /**
  * Initializes Doctrine entity manager
  */
 private function initORM()
 {
     $this->_em = ServiceContainer::get('dm');
 }
 private function initORM()
 {
     $config_pff = ServiceContainer::get('config');
     if (true === $config_pff->getConfigData('development_environment')) {
         $cache = new ArrayCache();
     } elseif ($this->redis) {
         $redis = new \Redis();
         if (!$redis->connect($this->redis_host, $this->redis_port)) {
             throw new PffException("Cannot connect to redis", 500);
         }
         if ($this->redis_password != '') {
             if (!$redis->auth($this->redis_password)) {
                 throw new PffException("Cannot auth to redis", 500);
             }
         }
         $cache = new RedisCache();
         $cache->setRedis($redis);
         $cache->setNamespace($this->_app->getConfig()->getConfigData('app_name'));
     } else {
         $cache = new ApcuCache();
         $cache->setNamespace($this->_app->getConfig()->getConfigData('app_name'));
     }
     $config = new Configuration();
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     $config->setResultCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver(ROOT . DS . 'app' . DS . 'models');
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setProxyDir(ROOT . DS . 'app' . DS . 'proxies');
     $config->setProxyNamespace('pff\\proxies');
     if (true === $config_pff->getConfigData('development_environment')) {
         $config->setAutoGenerateProxyClasses(true);
         $connectionOptions = $config_pff->getConfigData('databaseConfigDev');
     } else {
         $config->setAutoGenerateProxyClasses(false);
         $connectionOptions = $config_pff->getConfigData('databaseConfig');
     }
     $this->db = EntityManager::create($connectionOptions, $config);
     ServiceContainer::set()['dm'] = $this->db;
     $platform = $this->db->getConnection()->getDatabasePlatform();
     $platform->registerDoctrineTypeMapping('enum', 'string');
 }
Exemple #10
0
 /**
  * @param $moduleName
  * @return mixed
  * @throws ModuleException
  * @throws \pff\Exception\ConfigException
  */
 private static function getModuleConf($moduleName)
 {
     $key = ServiceContainer::get('config')->getConfigData('app_name') . '-config-' . md5($moduleName);
     if (extension_loaded('apc') && apc_exists($key)) {
         $moduleConf = apc_fetch($key);
         return $moduleConf;
     } else {
         $moduleFilePathUser = ROOT . DS . 'app' . DS . 'modules' . DS . $moduleName . DS . 'module.yaml';
         $moduleFilePathPff = ROOT_LIB . DS . 'src' . DS . 'modules' . DS . $moduleName . DS . 'module.yaml';
         $moduleComposerPath = ROOT . DS . 'modules' . DS . $moduleName . DS . 'module.yaml';
         if (file_exists($moduleFilePathUser)) {
             $moduleFilePath = $moduleFilePathUser;
         } elseif (file_exists($moduleComposerPath)) {
             $moduleFilePath = $moduleComposerPath;
         } elseif (file_exists($moduleFilePathPff)) {
             $moduleFilePath = $moduleFilePathPff;
         } else {
             throw new ModuleException("Specified module \"" . $moduleName . "\" does not exist");
         }
         try {
             $moduleConf = ServiceContainer::get('yamlparser')->parse(file_get_contents($moduleFilePath));
         } catch (ParseException $e) {
             throw new ModuleException("Unable to parse module configuration\n                                                file for {$moduleName}: " . $e->getMessage());
         }
         if (extension_loaded('apc') && !apc_exists($key)) {
             apc_store($key, $moduleConf);
         }
         return $moduleConf;
     }
 }
Exemple #11
0
/**
 * General bootstrap operations for the framework.
 *
 * @author paolo.fagni<at>gmail.com
 */
\pff\Core\ServiceContainer::initPimple();
\pff\Core\ServiceContainer::set()['config'] = function ($c) {
    return new \pff\Config();
};
\pff\Core\ServiceContainer::set()['hookmanager'] = function ($c) {
    return new \pff\Core\HookManager();
};
\pff\Core\ServiceContainer::set()['modulemanager'] = function ($c) {
    return new \pff\Core\ModuleManager();
};
\pff\Core\ServiceContainer::set()['helpermanager'] = function ($c) {
    return new \pff\Core\HelperManager();
};
\pff\Core\ServiceContainer::set()['app'] = function ($c) {
    return new \pff\App();
};
\pff\Core\ServiceContainer::set()['yamlparser'] = function ($c) {
    return new \Symfony\Component\Yaml\Parser();
};
$app = \pff\Core\ServiceContainer::get('app');
$app->setUrl($url);
$app->setErrorReporting();
$app->removeMagicQuotes();
$app->unregisterGlobals();
\pff\Core\ServiceContainer::get('modulemanager')->initModules();
// @codeCoverageIgnoreStop
Exemple #12
0
 public function __construct()
 {
     $this->_config = ServiceContainer::get('config');
 }
 /**
  * @param AModel $user
  * @param $idGroup
  * @return mixed
  * @throws \Exception
  *
  * SUBSCRIBE AN USER TO A GROUP, AND TO THE LIST IT BELONGS TO
  */
 public function subscribeToGroup(AModel $user, $idGroup)
 {
     $this->checkLogin();
     $request = $this->getRequestUserData($user);
     try {
         $status = $this->client->subscribeToGroup($request, $idGroup);
     } catch (\Exception $e) {
         throw $e;
     }
     /** @var EntityManager $em */
     $em = ServiceContainer::get("dm");
     $this->setField($user, $this->remoteIdField, (int) trim($status));
     $em->flush();
     $em->clear();
     return $status;
 }