public static function instance() { if (self::$instance == NULL) { self::$instance = new self(); } return self::$instance; }
/** * 注册服务 * @param type $di */ public function registerServices(\Phalcon\DiInterface $di = NULL) { $config = \TConfig::instance()->getModule($this->moduleId); if (php_sapi_name() == 'cli') { //处理CLI模式 $di['dispatcher'] = function () use($config) { $dispatcher = new \Phalcon\Cli\Dispatcher(); if (isset($config['defaultNamespace']) && isset($config['defaultNamespace']['task'])) { $dispatcher->setDefaultNamespace($config['defaultNamespace']); } return $dispatcher; }; } else { //处理WEB模式 $di['dispatcher'] = function () use($config) { $dispatcher = new \Phalcon\Mvc\Dispatcher(); if (isset($config['defaultNamespace']) && isset($config['defaultNamespace']['controller'])) { $dispatcher->setDefaultNamespace($config['defaultNamespace']['controller']); } return $dispatcher; }; //添加视图 $di->set('view', function () use($config) { $view = new \Phalcon\Mvc\View(); $view->setViewsDir($config['autoloadDir']['view']); $view->registerEngines(array('.html' => 'Phalcon\\Mvc\\View\\Engine\\Php')); return $view; }); } }
function __construct($file) { $o = TConfig::factory("ini"); $o->set('env.root', realpath(dirname(__FILE__) . '/../')); $o->load($file); $this->Conf = $o; }
/** * Returns a singleton of a Twig_Environment object. * This is the handle that will be used to load templates * @return Twig_Environment */ private static function getTwig() { if (self::$twig == NULL) { require_once dirname(dirname(__FILE__)) . '/includes/config.php'; Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem(dirname(dirname(__FILE__)) . '/templates'); $params = array('debug' => TRUE, 'strict_variables' => TRUE, 'autoescape' => TRUE); // no cache if (TConfig::templateCachingEnabled()) { $params = array('debug' => TRUE, 'cache' => 'cache', 'strict_variables' => TRUE, 'autoescape' => TRUE); // no cache } self::$twig = new Twig_Environment($loader, $params); // no cache self::$twig->addExtension(new Twig_Extension_Debug()); } // add some useful globals available to all templates return self::$twig; }
public function outputFilter($key, $value) { return parent::outputFilter($key, $value); }
function testFactory() { $o = TConfig::factory("ini"); $this->assertEquals("TConfigIni", get_class($o)); }
return new Phalcon\Db\Adapter\Pdo\Mysql($dbReadConfig); }); } //设置默认数据库连接 $defaultDbKey = 'db' . ucfirst($config->balanceDb->default); $di->set('db', $di->get($defaultDbKey)); $defaultDbKey = 'db' . ucfirst($config->balanceDb->default); $di->set('db_read', $di->get($defaultDbKey . '_read')); //加载DB负载均衡 BalanceDb::config($config->balanceDb->toArray()); //Redis负载均衡 BalanceRedis::config($config->balanceRedis->toArray()); //URL 工具类 TUrl::config($config->url->toArray()); //config 工具类 TConfig::instance()->setAll($config->toArray()); //实例化应用 $application = new \Phalcon\Mvc\Application($di); //注册模块 $modules = array(); foreach ($config->modules as $key => $params) { if ($key == 'default') { continue; } $modules[$key] = array('className' => sprintf('Module\\%s\\Module', ucfirst($key)), 'path' => $params['path']); } $application->registerModules($modules); echo $application->handle()->getContent(); } catch (\Exception $e) { echo $e->getMessage(); }
<?php // https://youtu.be/6qma_lgTI0g require_once dirname(__FILE__) . '/php-activerecord/ActiveRecord.php'; ActiveRecord\Config::initialize(function ($cfg) { require_once dirname(dirname(__FILE__)) . '/includes/config.php'; try { $cfg->set_model_directory(dirname(dirname(__FILE__)) . '/models'); $cfg->set_connections(array('itpl' => 'mysql://' . TConfig::GetDBUser() . ':' . TConfig::GetDBPassword() . '@' . TConfig::GetDBHost() . '/' . TConfig::GetDBName())); $cfg->set_default_connection('itpl'); } catch (Exception $ex) { print $ex->getMessage(); } });
/** * HTTP constructor. * * Creates CURL object and sets default options. * * @param TConfig $TConfig */ public function __construct(TConfig $TConfig) { $this->curl = curl_init(); $this->validate = array(); curl_setopt_array($this->curl, array(CURLOPT_USERAGENT => 'Alliance Scraper made by FRC Team 2228 - PHP CURL', CURLOPT_REFERER => $TConfig->read('url'), CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_RETURNTRANSFER => true)); }