Пример #1
0
 function execute()
 {
     if (!is_dir($this->_source_dir)) {
         throw new Command_Exception("Invalid source dir: \"{$this->_source_dir}\".");
     }
     echo "processing source documents...";
     $book = new Doc_Book(Helper_YAML::load("{$this->_source_dir}/toc.yaml"), $this->_source_dir);
     echo "ok\n";
     $this->_output_dir = "{$this->_output_dir}/{$book->name}";
     if (!is_dir($this->_output_dir)) {
         Helper_FileSys::mkdirs($this->_output_dir);
     }
     $this->_output_dir = trim(realpath($this->_output_dir), '/\\');
     switch ($this->_docmode) {
         case 'online':
             $this->_buildOnlineDocuments($book);
             break;
         case 'chm':
             $this->_buildCHMDocuments($book);
             break;
         case 'pdf':
             $this->_buildPDFDocuments($book);
             break;
         case 'html':
         default:
             exit('invalid docmode:' . $this->_docmode);
     }
 }
Пример #2
0
 /**
  * 从配置文件创建表单
  */
 protected static function _createFromConfig($action, $config_name)
 {
     $form = new Form_Common('form', $action);
     $filename = rtrim(dirname(__FILE__), '/\\') . DS . $config_name . '.yaml.php';
     $form->loadFromConfig(Helper_YAML::loadCached($filename));
     return $form;
 }
Пример #3
0
 static function loadConfig($filename, $name)
 {
     $path = dirname(dirname(__FILE__)) . '/_configs/' . $filename;
     if (is_file($path)) {
         $path = realpath($path);
         Helper_YAML::load();
     }
 }
Пример #4
0
 function __construct($action)
 {
     // 调用父类的构造函数
     parent::__construct("form1", $action);
     // 从配置文件载入表单
     $filename = rtrim(dirname(__FILE__), '/\\') . DS . 'user_form.yaml';
     $this->loadFromConfig(Helper_YAML::loadCached($filename));
     // 添加表单验证
     //$this->addValidations(Users::meta());
 }
Пример #5
0
 function __construct($action)
 {
     // 调用父类的构造函数
     parent::__construct("form_changepassword", $action);
     // 从配置文件载入表单
     $filename = rtrim(dirname(__FILE__), '/\\') . DS . 'changepassword_form.yaml';
     $this->loadFromConfig(Helper_YAML::loadCached($filename));
     $this['old_password']->addValidations(array($this, 'checkPasswordLen'), '密码长度只能在4-32位之间');
     $this['new_password']->addValidations(array($this, 'checkPasswordLen'), '密码长度只能在4-32位之间');
     $this['new_password2']->addValidations(array($this, 'checkSecPasswd'), '两次输入的密码必须一致');
     //$this->addValidations(Users::meta());
 }
Пример #6
0
 /**
  * 从配置文件中生成新闻表单
  *
  * @param string $action 表单的url
  * @param string $config 配置文件的名字
  * @return object 表单对象
  */
 static function _createFormConfig($action, $config)
 {
     $form = new Form_Admin_News('create_news', $action);
     $fileName = dirname(__FILE__) . DS . "{$config}";
     $form->loadFromConfig(Helper_YAML::load($fileName));
     $form->addValidations(News::meta());
     //查询类别
     $sort = NewSort::find()->order('name ASC')->getAll();
     $sort = Helper_Array::toHashmap($sort, 'id', 'name');
     $form['newbody']['sort_id']->items = $sort;
     return $form;
 }
Пример #7
0
 function __construct($config_name = 'default', $udi = null, $model = null, $has_file = null, $must = false)
 {
     parent::__construct('form_' . $config_name, url($udi), 'post');
     if ($has_file) {
         $this->enctype = self::ENCTYPE_MULTIPART;
         $this->has_file = $has_file;
         $this->must = $must;
     }
     $file_name = $config_name . '_form.yaml';
     $filename = rtrim(dirname(__FILE__), '/\\') . DS . $file_name;
     $this->loadFromConfig(Helper_YAML::loadCached($filename));
     $this->addValidations(QDB_ActiveRecord_Meta::instance($model));
 }
Пример #8
0
 function actionUpdateDSN()
 {
     $dsn = array();
     foreach ($_POST as $key => $value) {
         $arr = explode('_', $key);
         if (count($arr) == 3 && $arr[1] == 'dsn') {
             $dsn[$arr[0]][$arr[2]] = $value;
         }
     }
     $filename = rtrim($this->_managed_app->ROOT_DIR(), '/\\') . '/config/database.yaml';
     file_put_contents($filename, Helper_YAML::dump($dsn), LOCK_EX);
     $this->app->setFlashMessage('成功更新数据库配置');
     return new QView_Redirect($this->context->url(null, 'setdsn') . "#tab_{$section}");
 }
Пример #9
0
 function testLoadFromConfig()
 {
     $form = new QForm('form1', self::URL1, QForm::POST);
     $this->assertEquals('form1', $form->id);
     $this->assertEquals('form1', $form->name);
     $this->assertEquals(self::URL1, $form->action);
     $this->assertEquals(QForm::POST, $form->method);
     $config = Helper_YAML::load(FIXTURE_DIR . '/form/form1.yaml');
     $form->loadFromConfig($config);
     $this->assertEquals('form1', $form->id);
     $this->assertEquals('form1-name', $form->name);
     $this->assertEquals(self::URL2, $form->action);
     $this->assertEquals(QForm::GET, $form->method);
 }
Пример #10
0
 /**
  * 从配置文件中生成新闻表单
  *
  * @param string $action 表单的url
  * @param string $config 配置文件的名字
  * @return object 表单对象
  */
 static function _createFormConfig($id, $action, $config)
 {
     $form = new Form_Admin_Sort($id, $action);
     $fileName = dirname(__FILE__) . DS . "{$config}";
     $form->loadFromConfig(Helper_YAML::load($fileName));
     //查询父类的id号
     if ('article' == $id) {
         $form->addValidations(Articlesorts::meta());
         $form['name']->_label = '文章分类名称';
         $parent = Articlesorts::find("name =?", '茶与文化')->setColumns('id')->asArray()->query();
     } else {
         $form->addValidations(NewSort::meta());
         $parent = NewSort::find("name =?", '业界动态')->setColumns('id')->asArray()->query();
     }
     $form['parent_id']->value = $parent['id'];
     return $form;
 }
Пример #11
0
 /**
  * 从配置文件中创建表单
  * @param string $action     表单的url	
  * @param string $configName  配置文件的名字
  * @return Form_Tea $form
  */
 protected static function _createFormConfig($action, $configName)
 {
     $form = new Form_Admin_Tea('tea_form', $action);
     $filename = rtrim(dirname(__FILE__), '/\\') . DS . $configName;
     $form->loadFromConfig(Helper_YAML::load($filename));
     $form->addValidations(Tea::meta());
     //图片的路径
     $form['thumb_filename']->dir = Q::ini('appini/teapics/img_dir');
     //上传图片的限制
     $types = Q::normalize(Q::ini('appini/teapics/upload_allowed_types'));
     $size = intval(Q::ini('appini/teapics/upload_allowed_size') * 1024);
     $dim = Q::ini('appini/teapics/img_pic_width') . 'x' . Q::ini('appini/teapics/img_pic_height');
     $form['postfile']->_tips = sprintf($form['postfile']->_tips, implode('/', $types), $size / 1024, $dim);
     //        茶叶类别
     //       $teatype = new TeaType();
     //       $form['type_id']->items=$teatype->list;
     $form->selectUploadElement('postfile')->uploadAllowedSize($size)->uploadAllowedTypes($types)->enableSkipUpload();
     return $form;
 }
Пример #12
0
 protected function setUp()
 {
     $rules = Helper_YAML::load(FIXTURE_DIR . '/mvc/routes.yaml');
     foreach ($rules as $route_name => $rule) {
         $index = 0;
         foreach ($rule['tests_url'] as $test) {
             $this->_tests_url["{$route_name}-{$index}"] = $test;
             $index++;
         }
         unset($rules[$route_name]['tests_url']);
         $index = 0;
         foreach ($rule['tests_args'] as $test) {
             $this->_tests_args["{$route_name}:{$index}"] = $test;
             $index++;
         }
         unset($rules[$route_name]['tests_args']);
     }
     Q::changeIni('routes', $rules);
 }
Пример #13
0
 /**
  * 从配置文件中生成新闻表单
  * @param string $id 表单的id 号
  * @param string $action 表单的url
  * @param string $config 配置文件的名字
  * @return object 表单对象
  */
 static function _createFormConfig($id, $action, $config)
 {
     $form = new Form_Admin_News($id, $action);
     $fileName = dirname(__FILE__) . DS . "{$config}";
     $form->loadFromConfig(Helper_YAML::load($fileName));
     //验证的模型选择
     if ($id == 'news') {
         $form->addValidations(News::meta());
     } else {
         $form->addValidations(Articles::meta());
     }
     //类别表的选择
     if ('news' == $id) {
         $news = new News();
         $form['sort_id']->items = $news->sorts;
     } else {
         $article = new Articles();
         $form['sort_id']->items = $article->sorts;
     }
     return $form;
 }
Пример #14
0
 /**
  * 载入配置文件内容
  *
  * @param array $app_config
  *
  * @return array
  */
 static function loadConfigFiles(array $app_config)
 {
     $ext = !empty($app_config['CONFIG_FILE_EXTNAME']) ? $app_config['CONFIG_FILE_EXTNAME'] : 'yaml';
     $cfg = $app_config['CONFIG_DIR'];
     $run_mode = strtolower($app_config['RUN_MODE']);
     $files = array("{$cfg}/environment.{$ext}" => 'global', "{$cfg}/database.{$ext}" => 'db_dsn_pool', "{$cfg}/acl.{$ext}" => 'acl_global', "{$cfg}/environments/{$run_mode}.{$ext}" => 'global', "{$cfg}/app.{$ext}" => 'appini', "{$cfg}/routes.{$ext}" => 'routes');
     $replace = array();
     foreach ($app_config as $key => $value) {
         if (!is_array($value)) {
             $replace["%{$key}%"] = $value;
         }
     }
     $config = (require Q_DIR . '/_config/default_config.php');
     foreach ($files as $filename => $scope) {
         if (!file_exists($filename)) {
             continue;
         }
         $contents = Helper_YAML::load($filename, $replace);
         if ($scope == 'global') {
             $config = array_merge($config, $contents);
         } else {
             if (!isset($config[$scope])) {
                 $config[$scope] = array();
             }
             $config[$scope] = array_merge($config[$scope], $contents);
         }
     }
     if (!empty($config['db_dsn_pool'][$run_mode])) {
         $config['db_dsn_pool']['default'] = $config['db_dsn_pool'][$run_mode];
     }
     return $config;
 }
Пример #15
0
 /**
  * 从一个 YAML 文件载入表单设置和元素
  *
  * @param string $filename 要载入的配置文件
  * @param bollean $cached 是否缓存配置文件
  *
  * @return QForm 返回表单对象本身,实现连贯接口
  */
 function loadFromConfigFile($filename, $cached = true)
 {
     if ($cached) {
         $config = Helper_YAML::loadCached($filename);
     } else {
         $config = Helper_YAML::load($filename);
     }
     return $this->loadFromConfig($config);
 }
Пример #16
0
 function build($source_dir)
 {
     $source_dir = rtrim($source_dir, '/\\');
     $this->book = new Guide_Doc_Book(Helper_YAML::load("{$source_dir}/toc.yaml"), $source_dir);
     return $this;
 }
Пример #17
0
// $Id: ut_common.php 2252 2009-02-17 14:31:24Z dualface $
/**
 * 单元测试公用初始化文件
 */
date_default_timezone_set('Asia/Shanghai');
error_reporting(E_ALL | E_STRICT);
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Framework/TestSuite.php';
require dirname(__FILE__) . '/../../library/q.php';
Q::changeIni('runtime_cache_dir', dirname(__FILE__) . '/../../tmp');
Q::changeIni('log_writer_dir', dirname(__FILE__) . '/../../tmp');
define('FIXTURE_DIR', dirname(dirname(__FILE__)) . DS . 'fixture');
/**
 * 载入数据库连接信息
 */
$dsn_pool = Helper_YAML::load(FIXTURE_DIR . '/database.yaml');
Q::replaceIni('db_dsn_pool', $dsn_pool);
PHPUnit_Util_Filter::addDirectoryToFilter(dirname(dirname(__FILE__)));
abstract class QTest_UnitTest_Abstract extends PHPUnit_Framework_TestCase
{
    protected function assertEmpty($var, $msg = '')
    {
        $this->assertTrue(empty($var), $msg);
    }
    protected function assertNotEmpty($var, $msg = '')
    {
        $this->assertTrue(!empty($var), $msg);
    }
}
abstract class QTest_UnitTest_TestSuite_Abstract extends PHPUnit_Framework_TestSuite
{
Пример #18
0
 /**
  * 载入指定模块的缓存文件,但不使用缓存
  *
  * @param string $module_name
  * @param array $app_config
  *
  * @return array
  */
 static function loadModuleConfig($module_name, array $app_config)
 {
     $run_mode = !empty($app_config['RUN_MODE']) ? $app_config['RUN_MODE'] : Q::RUN_MODE_DEPLOY;
     $extname = !empty($app_config['CONFIG_FILE_EXTNAME']) ? $app_config['CONFIG_FILE_EXTNAME'] : 'yaml';
     $root_dir = $app_config['ROOT_DIR'];
     // 载入配置文件,并替换配置文件中的宏
     if ($module_name != self::DEFAULT_MODULE_NAME) {
         $module_name = strtolower(preg_replace('/[^a-z0-9_]+/i', '', $module_name));
         $root = "{$root_dir}/config/modules/{$module_name}";
         $files = array("{$root}/{$module_name}_module.{$extname}" => 'global', "{$root}/environments/{$run_mode}.{$extname}" => 'global');
     } else {
         $root = "{$root_dir}/config";
         $files = array("{$root}/environment.{$extname}" => 'global', "{$root}/database.{$extname}" => 'db_dsn_pool', "{$root}/acl.{$extname}" => 'acl_global_act', "{$root}/environments/{$run_mode}.{$extname}" => 'global', "{$root}/app.{$extname}" => 'appini', "{$root}/routes.{$extname}" => 'routes');
     }
     $replace = array();
     foreach ($app_config as $key => $value) {
         $replace["%{$key}%"] = $value;
     }
     $config = array();
     foreach ($files as $filename => $scope) {
         if (!file_exists($filename)) {
             continue;
         }
         $contents = Helper_YAML::load($filename, $replace);
         if ($scope == 'global') {
             $config = array_merge_recursive($config, $contents);
         } else {
             if (!isset($config[$scope])) {
                 $config[$scope] = array();
             }
             $config[$scope] = array_merge_recursive($config[$scope], $contents);
         }
     }
     if (!empty($config['db_dsn_pool'][$run_mode])) {
         $config['db_dsn_pool']['default'] = $config['db_dsn_pool'][$run_mode];
     }
     return $config;
 }