コード例 #1
0
ファイル: App.php プロジェクト: kissthink/MiniFramework
 /**
  * 构造
  * 
  */
 protected function __construct()
 {
     $this->_exception = Exceptions::getInstance();
     $this->_exception->throwExceptions(SHOW_ERROR);
     $this->_params = Params::getInstance();
     $this->getRouter();
 }
コード例 #2
0
ファイル: View.php プロジェクト: kissthink/MiniFramework
 /**
  * 构造
  */
 function __construct()
 {
     $this->_exception = Exceptions::getInstance();
     $this->_request = Request::getInstance();
     $app = App::getInstance();
     $this->_controller = $app->controller;
     $this->_action = $app->action;
 }
コード例 #3
0
 /**
  * 构造
  * 
  * @param array $params => array (
  *     host     => (string) 主机,默认值为空
  *     port     => (int) 端口,默认值为空
  *     
  *     prefix   => (string) 缓存名前缀,默认值为空
  * )
  * @return Cache_Abstract
  */
 public function __construct($params)
 {
     $this->_exception = Exceptions::getInstance();
     if (!is_array($params)) {
         if ($this->_exception->throwExceptions()) {
             throw new Exception('Adapter params must be in an array.');
         } else {
             $this->_exception->sendHttpStatus(500);
         }
     }
     $this->_params = $params;
 }
コード例 #4
0
ファイル: Router.php プロジェクト: kissthink/MiniFramework
 /**
  * 构造
  * 
  */
 public function __construct()
 {
     $this->_exception = Exceptions::getInstance();
     $this->_request = Request::getInstance();
     $exceptions = Exceptions::getInstance();
     if (false === strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'])) {
         //Rewrite
         $this->_routeType = 'rewrite';
         $this->_uriArray = $this->parseUrlToArray();
         $controller = isset($this->_uriArray[1]) && !empty($this->_uriArray[1]) ? $this->_uriArray[1] : 'index';
         $action = isset($this->_uriArray[2]) && !empty($this->_uriArray[2]) ? $this->_uriArray[2] : 'index';
     } else {
         //GET
         $this->_routeType = 'get';
         if (empty($_SERVER['QUERY_STRING'])) {
             $controller = 'index';
             $action = 'index';
         } else {
             parse_str($_SERVER['QUERY_STRING'], $urlParams);
             $controller = isset($urlParams['c']) ? $urlParams['c'] : 'index';
             $action = isset($urlParams['a']) ? $urlParams['a'] : 'index';
         }
     }
     if ($this->checkRoute($controller)) {
         $this->_controller = $controller;
     } else {
         if ($exceptions->throwExceptions()) {
             throw new Exception('Controller "' . $controller . '" not found.');
         } else {
             $exceptions->sendHttpStatus(404);
         }
     }
     if ($this->checkRoute($action)) {
         $this->_action = strtolower($action);
     } else {
         if ($exceptions->throwExceptions()) {
             throw new Exception('Action "' . $action . '" does not exist.');
         } else {
             $exceptions->sendHttpStatus(404);
         }
     }
 }
コード例 #5
0
ファイル: Cache.php プロジェクト: sujinw/MiniFramework
 /**
  * 工厂模式获取缓存实例
  * 
  * @param string $adapter
  * @param array $params
  */
 public static function factory($adapter = 'Memcache', $params = array())
 {
     $exceptions = Exceptions::getInstance();
     if (!is_array($params)) {
         if ($exceptions->throwExceptions()) {
             throw new Exception('Adapter params must be in an array.');
         } else {
             $exceptions->sendHttpStatus(500);
         }
     }
     if (!is_string($adapter) || empty($adapter)) {
         if ($exceptions->throwExceptions()) {
             throw new Exception('Adapter name must be specified in a string.');
         } else {
             $exceptions->sendHttpStatus(500);
         }
     }
     $adapterName = 'Cache_' . ucwords($adapter);
     if (!class_exists($adapterName, false)) {
         $adapterPath = MINI_PATH . DIRECTORY_SEPARATOR . 'Library' . DIRECTORY_SEPARATOR . 'Cache';
         $adapterFile = $adapterPath . DIRECTORY_SEPARATOR . $adapterName . '.php';
         if (!file_exists($adapterFile)) {
             if ($exceptions->throwExceptions()) {
                 throw new Exception('Adapter "' . $adapterName . '" not found.');
             } else {
                 $exceptions->sendHttpStatus(500);
             }
         }
         require_once $adapterFile;
     }
     $cacheAdapter = new $adapterName($params);
     if (!$cacheAdapter instanceof Cache_Abstract) {
         if ($exceptions->throwExceptions()) {
             throw new Exception('Adapter class "' . $adapterName . '" does not extend Cache_Abstract.');
         } else {
             $exceptions->sendHttpStatus(500);
         }
     }
     return $cacheAdapter;
 }
コード例 #6
0
 /**
  * 构造
  * 
  * @param array $params => array (
  *     host         => (string) 主机,默认值为localhost
  *     dbname       => (string) 数据库名
  *     username     => (string) 用户名
  *     passwd       => (string) 密码
  * 
  *     port         => (string) 端口
  *     charset      => (string) 字符集编码,默认值为utf8
  *     persistent   => (boolean) 是否启用持久连接,默认值为false
  * )
  * @return Db_Abstract
  */
 public function __construct($params)
 {
     $this->_exception = Exceptions::getInstance();
     if (!is_array($params)) {
         if ($this->_exception->throwExceptions()) {
             throw new Exception('Adapter params must be in an array.');
         } else {
             $this->_exception->sendHttpStatus(500);
         }
     }
     if (!isset($params['charset'])) {
         $params['charset'] = 'utf8';
     }
     if (!isset($params['persistent'])) {
         $params['persistent'] = false;
     }
     $this->_params = $params;
 }