public static function showHttpErrorDocument($status_code) { // Charcoal_ParamTrait::validateInteger( 1, $status_code ); $status_code = ui($status_code); // HTML $html_file = $status_code . '.html'; // アプリケーション以下のerror_docを検索 $html_file_path = Charcoal_ResourceLocator::getApplicationPath('error_doc', $html_file); if (!is_file($html_file_path)) { // log_info( 'system,debug,error',"エラードキュメント($html_file_path)は存在しません。", 'framework'); // プロジェクト以下のerror_docを検索 $html_file_path = Charcoal_ResourceLocator::getProjectPath('error_doc', $html_file); if (!is_file($html_file_path)) { // log_debug( 'system,debug,error',"エラードキュメント($html_file_path)は存在しません。", 'framework'); // フレームワーク以下のerror_docを検索 $html_file_path = Charcoal_ResourceLocator::getFrameworkPath('error_doc', $html_file); if (!is_file($html_file_path)) { // log_warning( 'system,debug,error',"エラードキュメント($html_file_path)は存在しません。", 'framework'); } } } // 読み込みと表示 if (is_file($html_file_path)) { readfile($html_file_path); print "<br>"; } }
/** * Initialize instance * * @param Charcoal_Config $config configuration data */ public function configure($config) { parent::configure($config); $session_name = $config->getString('session_name', ''); $save_path = $config->getString('save_path', '', TRUE); $lifetime = $config->getInteger('lifetime', 0); $valid_path = $config->getString('valid_path', ''); $valid_domain = $config->getString('valid_domain', ''); $ssl_only = $config->getBoolean('ssl_only', FALSE); $save_path = us($save_path); $lifetime = ui($lifetime); $ssl_only = ub($ssl_only); $session_name = us($session_name); // デフォルトのセッション保存先 if (!$save_path || !is_dir($save_path)) { $save_path = Charcoal_ResourceLocator::getApplicationPath('sessions'); } // セッション初期化処理 // session_set_cookie_params( $lifetime, "$valid_path", "$valid_domain", $ssl_only ); session_save_path($save_path); // $session_name = session_name( $session_name ? $session_name : APPLICATION ); session_name("PHPSESSID"); //session_regenerate_id( TRUE ); if ($this->getSandbox()->isDebug()) { log_debug("session", "session_name:{$session_name}", self::TAG); log_debug("session", "save_path:{$save_path}", self::TAG); log_debug("session", "lifetime:{$lifetime}", self::TAG); log_debug("session", "valid_path:{$valid_path}", self::TAG); log_debug("session", "valid_domain:{$valid_domain}", self::TAG); log_debug("session", "ssl_only:{$ssl_only}", self::TAG); } // メンバーに保存 $this->save_path = $save_path; }
public static function processMacro($env, $value) { Charcoal_ParamTrait::validateIsA(1, 'Charcoal_IEnvironment', $env); if (is_array($value) || $value instanceof Traversable) { $new_array = array(); foreach ($value as $key => $value) { $value = is_string($value) ? self::processMacro($env, $value) : $value; $new_array[$key] = $value; } return $new_array; } $value = us($value); if (!is_string($value)) { return $value; } if (strpos($value, '%') === FALSE) { return $value; } if (!self::$static_macro_defs) { self::$static_macro_defs = array('%APPLICATION_DIR%' => CHARCOAL_WEBAPP_DIR . '/' . CHARCOAL_PROJECT . '/app/' . CHARCOAL_APPLICATION, '%PROJECT_DIR%' => CHARCOAL_WEBAPP_DIR . '/' . CHARCOAL_PROJECT, '%WEBAPP_DIR%' => CHARCOAL_WEBAPP_DIR, '%CHARCOAL_HOME%' => CHARCOAL_HOME, '%PROJECT%' => CHARCOAL_PROJECT, '%APPLICATION%' => CHARCOAL_APPLICATION, '%BASE_DIR%' => CHARCOAL_BASE_DIR, '%CACHE_DIR%' => CHARCOAL_CACHE_DIR, '%TMP_DIR%' => CHARCOAL_TMP_DIR); } // fill static values $value = strtr($value, self::$static_macro_defs); // set runtime values $request_path = $env->get('%REQUEST_PATH%'); $runtime_macro_defs = array('%REQUEST_PATH_REAL%' => str_replace(':', '/', substr($request_path, 2))); // fill runtime values $value = strtr($value, $runtime_macro_defs); return $value; }
/** * Initialize instance * * @param Charcoal_Config $config configuration data */ public function configure($config) { parent::configure($config); $default_cache_root = Charcoal_ResourceLocator::getApplicationPath(s('cache')); $this->_cache_root = $config->getString('cache_root', $default_cache_root, TRUE); $this->_default_duration = $config->getInteger('default_duration', 0); $this->_cache_root_dir = new Charcoal_File($this->_cache_root); log_debug("system, debug, cache", "cache_root=[{$this->_cache_root}]"); log_debug("system, debug, cache", "default_duration=[{$this->_default_duration}]"); }
/** * Initialize instance * * @param Charcoal_Config $config configuration data */ public function configure($config) { parent::configure($config); $this->setPostActions(array('remove_event', 'remove_task')); $this->scenario_dir = $config->getString('scenario_dir', Charcoal_ResourceLocator::getApplicationPath('scenario'), TRUE); if ($this->getSandbox()->isDebug()) { log_debug("debug,event", "Task[{$this}] post_actions: " . $this->getPostActions(), "post_actions"); log_debug("debug,event", "scenario_dir: {$this->scenario_dir}"); } }
public function toString() { $keyword_file = Charcoal_ResourceLocator::getFrameworkPath('data', 'php.kwd'); $file = $this->_file; $line = $this->_line; $p = new Charcoal_PhpSourceParser(); $p->init($keyword_file); $tokens = $p->parse($this->_file); $html = Charcoal_PhpSourceRenderer::render($tokens, '%4d:', NULL, $line - $this->_range, $line + $this->_range); return $html; }
public function load($debug_mode, $profile_name) { $config_file = "{$profile_name}.profile.ini"; try { // get profile directory path $profile_dir = Charcoal_ResourceLocator::getApplicationFile('config/profile'); // make config file object $config_file = new Charcoal_File($config_file, $profile_dir); // check if profile directory exists if (!$profile_dir->exists()) { if ($debug_mode) { echo "profile directory not exists: [{$profile_dir}]" . eol(); } log_error("debug,config,profile", "profile directory not exists: [{$profile_dir}]"); _throw(new Charcoal_ProfileDirectoryNotFoundException($profile_dir)); } // throw exception when config file is not found if (!$config_file->isFile() || !$config_file->canRead()) { if ($debug_mode) { echo "profile config file not exists or not readable: [{$config_file}]" . eol(); } log_error("debug,config,profile", "profile config file not exists or not readable: [{$config_file}]"); _throw(new Charcoal_ProfileConfigFileNotFoundException($config_file)); } // parse config file // log_debug( "debug,config,profile", "profile", "parsing config file: [$config_file]" ); $config_file = $config_file->getAbsolutePath(); if ($debug_mode) { echo "executing parse_ini_file: [{$config_file}]" . eol(); } $config = @parse_ini_file($config_file, FALSE); if ($config === FALSE) { if ($debug_mode) { echo "profile config file format error: [{$config_file}]" . eol(); } log_error("debug,config,profile", "profile config file format error: [{$config_file}]"); _throw(new Charcoal_ProfileConfigFileFormatException($config_file)); } if ($debug_mode) { echo "executed parse_ini_file: " . ad($config) . eol(); } // log_debug( "profile", "profile", "parse_ini_file: " . print_r($config,TRUE) ); // 設定を保存 parent::mergeArray($config); // log_debug( "debug,config,profile", "profile", "marged profile:" . print_r($config,TRUE) ); } catch (Exception $ex) { // log_debug( "system,error,debug", "catch $e" ); _catch($ex); _throw(new Charcoal_ProfileLoadingException($config_file, $profile_name, $ex)); } }
/** * セットアップ */ public function setUp($action, $context) { $action = us($action); switch ($action) { case "get_empty_data": case "get_integer_data": case "get_string_data": case "get_array_data": case "get_boolean_data": case "get_float_data": case "get_object_data": case "set_duration": case "delete": case "delete_wildcard": case "delete_regex": case "touch": case "touch_wildcard": case "touch_regex": $cache_driver = $context->createObject('file', 'cache_driver', 'Charcoal_ICacheDriver'); $this->cache_root = Charcoal_ResourceLocator::getPath('%CHARCOAL_HOME%/tmp/test/cache/'); $config['cache_root'] = $this->cache_root; $config = new Charcoal_Config($this->getSandbox()->getEnvironment(), $config); $cache_driver->configure($config); $this->cache_driver = $cache_driver; $cache_files = glob($this->cache_root . '/*'); if ($cache_files && is_array($cache_files)) { foreach ($cache_files as $cache) { $file = new Charcoal_File(s($cache)); $name = $file->getName(); $ext = $file->getExtension(); if ($file->exists() && $file->isFile() && in_array($ext, array("meta", "data"))) { $file->delete(); echo "removed cache file: [{$cache}]" . eol(); } } } break; default: break; } }
/** * execute tests */ public function test($action, $context) { $action = us($action); $temp_dir = Charcoal_ResourceLocator::getApplicationPath(s('tmp')); switch ($action) { case "get_section": $ini_data = parse_ini_file($temp_dir . '/test.ini', true); $config = new Charcoal_Config($this->getSandbox()->getEnvironment(), $ini_data); $first_section = $config->getSection(s('first_section')); $second_section = $config->getSection(s('second_section')); $third_section = $config->getSection(s('third_section')); $this->assertEquals(1, $first_section['one']); $this->assertEquals(5, $first_section['five']); $this->assertEquals('BIRD', $first_section['animal']); $this->assertEquals("/usr/local/bin", $second_section['path']); $this->assertEquals("http://www.example.com/~username", $second_section['URL']); $this->assertEquals(array("5.0", "5.1", "5.2", "5.3"), $third_section['phpversion']); return TRUE; } return FALSE; }
/** * List models * * @param Charcoal_Sandbox $sandbox * @param int $find_path * * @return Charcoal_ITableModel[] */ public function listModels($sandbox, $find_path) { // get root path of framework,project,web_app $dir_framework = Charcoal_ResourceLocator::getFrameworkPath(); $dir_project = Charcoal_ResourceLocator::getProjectPath(); $dir_application = Charcoal_ResourceLocator::getApplicationPath(); // get module root path of framework,project,web_app $dir_framework_module = $dir_framework . '/module'; $dir_project_module = $dir_project . '/module'; $dir_application_module = $dir_application . '/module'; $config_target_list = array(); if (Charcoal_System::isAnyBitSet($find_path, Charcoal_EnumFindPath::FIND_PATH_FRAMEWORK)) { $config_target_list[] = $dir_framework . '/config/table_model'; $config_target_list[] = $dir_framework_module . '/config/table_model'; } if (Charcoal_System::isAnyBitSet($find_path, Charcoal_EnumFindPath::FIND_PATH_PROJECT)) { $config_target_list[] = $dir_project . '/config/table_model'; $config_target_list[] = $dir_project_module . '/config/table_model'; } if (Charcoal_System::isAnyBitSet($find_path, Charcoal_EnumFindPath::FIND_PATH_APPLICATION)) { $config_target_list[] = $dir_application . '/config/table_model'; $config_target_list[] = $dir_application_module . '/config/table_model'; } // find model names in target directory $table_model_names = array(); foreach ($config_target_list as $path) { $found_models = $sandbox->getRegistry()->listObjects($path, 'table_model'); $table_model_names = array_merge($table_model_names, $found_models); } // convert model name into table model instance $table_models = array(); foreach ($table_model_names as $model_name) { $model = $this->getModel($model_name); if ($model && $model instanceof Charcoal_ITableModel) { $table_models[$model_name] = $model; } } return $table_models; }
/** * execute exception handlers * * @param Exception $e exception to handle * * @return boolean TRUE means the exception is handled, otherwise FALSE */ public function handleException($e) { Charcoal_ParamTrait::validateException(1, $e); if ($e instanceof Charcoal_HttpStatusException) { $status_code = $e->getStatusCode(); // ヘッダ文字列 $status_message_file = Charcoal_ResourceLocator::getFrameworkPath('preset', 'status_messages.ini'); if (!is_file($status_message_file)) { // log_warning( 'system,debug,error', 'framework',"ステータスメッセージファイル($status_message_file)が存在しません。"); } $status_messages = parse_ini_file($status_message_file, FALSE); if (FALSE === $status_messages) { // log_warning( 'system,debug,error', 'framework',"ステータスメッセージファイル($status_message_file)の読み込みに失敗しました。"); } $header_msg = isset($status_messages[$status_code]) ? $status_messages[$status_code] : ''; // HTTPバージョン文字列 $http_ver = $this->http_version; // ヘッダ出力 header("HTTP/{$http_ver} {$status_code} {$header_msg}", true, $status_code); log_error('system,debug,error', "HTTP/1.0 {$status_code} {$header_msg}", 'framework'); } return FALSE; }
/** * イベントを処理する * * @param Charcoal_IEventContext $context * * @return boolean */ public function processEvent($context) { $request = $context->getRequest(); // パラメータを取得 $database = us($request->getString('p2')); $table = us($request->getString('p3')); $out_dir = us($request->getString('p4')); //======================================= // Confirm input parameters //======================================= if (!empty($database) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $database)) { print "Parameter 2(database name) is wrong: {$database}" . PHP_EOL; return b(true); } if (!empty($table) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $table)) { print "Parameter 3(table name) is wrong: {$table}" . PHP_EOL; return b(true); } if (!empty($table) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $table)) { print "Parameter 4(output directory path) is wrong: {$out_dir}" . PHP_EOL; return b(true); } //======================================= // output directory //======================================= if (empty($out_dir)) { $out_dir = getcwd() ? getcwd() : Charcoal_ResourceLocator::getFrameworkPath('tmp'); } //======================================= // Send new project event //======================================= /** @var Charcoal_IEvent $event */ $event_path = 'generate_model_event@:charcoal:db:generate:model'; $event = $context->createEvent($event_path, array($database, $table, $out_dir)); $context->pushEvent($event); return b(true); }
/** * load events in module directory * * @param Charcoal_ITaskManager $task_manager * * @return int count of loaded events */ public function loadEvents($task_manager) { $loadedevents = NULL; $root_path = $this->getObjectPath(); //================================== // load event source code //================================== $real_path = $root_path->getRealPath(); $webapp_path = Charcoal_ResourceLocator::getApplicationPath('module' . $real_path); $project_path = Charcoal_ResourceLocator::getProjectPath('module' . $real_path); $framework_path = Charcoal_ResourceLocator::getFrameworkPath('module' . $real_path); $event_class_suffix = 'Event.class.php'; if (is_dir($webapp_path) && ($dh = opendir($webapp_path))) { while (($file = readdir($dh)) !== FALSE) { if ($file === '.' || $file === '..') { continue; } if (strpos($file, $event_class_suffix) !== FALSE) { $loadedevents[] = $this->loadEvent($root_path, "{$webapp_path}/{$file}", $task_manager); } } closedir($dh); } if (is_dir($project_path) && ($dh = opendir($project_path))) { while (($file = readdir($dh)) !== FALSE) { if ($file === '.' || $file === '..') { continue; } if (strpos($file, $event_class_suffix) !== FALSE) { $loadedevents[] = $this->loadEvent($root_path, "{$project_path}/{$file}", $task_manager); } } closedir($dh); } if (is_dir($framework_path) && ($dh = opendir($framework_path))) { while (($file = readdir($dh)) !== FALSE) { if ($file === '.' || $file === '..') { continue; } if (strpos($file, $event_class_suffix) !== FALSE) { $loadedevents[] = $this->loadEvent($root_path, "{$framework_path}/{$file}", $task_manager); } } closedir($dh); } //================================== // create and register events //================================== // load events from config file // log_info( "system,debug", "module", "loading events in module file:" . $this->events ); if ($this->events) { foreach ($this->events as $event) { $event_path = $event . '@' . $root_path->getVirtualPath(); $event = $this->getSandbox()->createEvent($event_path); // log_info( "system,debug", "module", "created event[" . get_class($event) . "/$event_path] in module[$root_path]"); $loadedevents[] = $event; } } // log_info( "system,debug", "module", "loaded events: " . print_r($loadedevents,true) ); return count($loadedevents); }
/** * Get framework/project/application file * * @param Charcoal_String $virtual_path virtual path including macro key like '%BASE_DIR%', '%WEBAPP_DIR%', etc. * @param Charcoal_Object $value cache data to save * * @return Charcoal_File file object * * [macro keyword sample] * * macro keyword | return value(real path) * ---------------------|------------------------------------------------ * %APPLICATION_DIR% | (web_app_root)/webapp/(project_name)/app/(application name)/ * %PROJECT_DIR% | (web_app_root)/webapp/(project_name)/ * %WEBAPP_DIR% | (web_app_root)/webapp/ * * * @see Charcoal_ResourceLocator * */ public function getFile($virtual_path, $filename = NULL) { // Charcoal_ParamTrait::validateString( 1, $virtual_path ); // Charcoal_ParamTrait::validateString( 2, $filename, TRUE ); return Charcoal_ResourceLocator::getFile($this->getSandbox()->getEnvironment(), $virtual_path, $filename); }
public static function loadConfig($sandbox, $obj_path, $type_name) { // Charcoal_ParamTrait::validateSandbox( 1, $sandbox ); // Charcoal_ParamTrait::validateStringOrObject( 2, 'Charcoal_ObjectPath', $obj_path ); // Charcoal_ParamTrait::validateString( 3, $type_name ); if (!$obj_path instanceof Charcoal_ObjectPath) { $obj_path = new Charcoal_ObjectPath($obj_path); } $object_name = $obj_path->getObjectName(); // log_info( "system", "config", "loading object config: path=[$obj_path] type=[$type_name]" ); // get root path of framework,project,web_app $dir_framework = Charcoal_ResourceLocator::getFrameworkPath(); $dir_project = Charcoal_ResourceLocator::getProjectPath(); $dir_application = Charcoal_ResourceLocator::getApplicationPath(); // get module root path of framework,project,web_app $dir_framework_module = $dir_framework . '/module'; $dir_project_module = $dir_project . '/module'; $dir_application_module = $dir_application . '/module'; // get real path(relative path) $real_path = $obj_path->getRealPath(); // config target set $config_target_list = NULL; // config base name $config_basename = $object_name ? $object_name . '.' . $type_name : $type_name; // read under global config folder $config_name = '/' . $type_name . '/' . $config_basename; $config_target_list[] = $dir_framework . '/config' . $config_name; $config_target_list[] = $dir_project . '/config' . $config_name; $config_target_list[] = $dir_application . '/config' . $config_name; // read under global config folder(relative path) if (strlen($real_path) > 0) { $config_name = '/' . $type_name . $real_path . '/' . $config_basename; $config_target_list[] = $dir_framework . '/config' . $config_name; $config_target_list[] = $dir_project . '/config' . $config_name; $config_target_list[] = $dir_application . '/config' . $config_name; } // read under global server folder $config_name = '/server/' . CHARCOAL_PROFILE . '/' . $type_name . '/' . $config_basename; $config_target_list[] = $dir_project . '/config' . $config_name; $config_target_list[] = $dir_application . '/config' . $config_name; // read under server config folder if (strlen($real_path) > 0) { $config_name = '/server/' . CHARCOAL_PROFILE . '/' . $type_name . $real_path . '/' . $config_basename; $config_target_list[] = $dir_project . '/config' . $config_name; $config_target_list[] = $dir_application . '/config' . $config_name; } // read under modules directory(current object path) $config_name = strlen($real_path) > 0 ? $real_path . '/' . $config_basename : '/' . $config_basename; $config_target_list[] = $dir_framework_module . $config_name; $config_target_list[] = $dir_project_module . $config_name; $config_target_list[] = $dir_application_module . $config_name; // read under modules directory(current procedure path) $request = Charcoal_Framework::getRequest(); if ($request) { $request_path = us($request->getProcedurePath()); $pos = strpos($request_path, '@'); if ($pos !== FALSE) { $virt_dir = substr($request_path, $pos + 1); if (strlen($virt_dir) > 0) { $proc_dir = str_replace(':', '/', $virt_dir); $config_target_list[] = $dir_application_module . $proc_dir . '/' . $config_basename; } } } // get registry from sandbox $registry = $sandbox->getRegistry(); // load all config files $config = $registry->get($config_target_list, $obj_path, $type_name); // import if (isset($config['import'])) { $import = $config['import']; $data = self::loadConfig($sandbox, $import, $type_name); if ($data) { $config = array_merge($config, $data); } } return $config; }
/** * create class loader * * @param string $obj_path class loader's object path to create * * @return Charcoal_IClassLoader class loader object */ public function createClassLoader($obj_path) { // Charcoal_ParamTrait::validateStringOrObjectPath( 1, $obj_path ); $class_loader = NULL; try { $obj_path = is_string($obj_path) ? new Charcoal_ObjectPath($obj_path) : $obj_path; // Configをロード $config = Charcoal_ConfigLoader::loadConfig($this, $obj_path, 'class_loader'); $config = new Charcoal_Config($this->environment, $config); // クラス名を取得 $class_name = $config->getString('class_name'); if ($class_name === NULL) { _throw(new Charcoal_ClassLoaderConfigException($obj_path, 'class_name', 'mandatory')); } $class_name = us($class_name); // project directory $project_dir = Charcoal_ResourceLocator::getProjectPath(); // ソースの取り込み $source_path = $project_dir . '/app/' . CHARCOAL_APPLICATION . '/class/class_loader/' . $class_name . '.class.php'; if (is_readable($source_path)) { /** @noinspection PhpIncludeInspection */ include $source_path; } else { $source_path = $project_dir . '/class/class_loader/' . $class_name . '.class.php'; if (is_readable($source_path)) { /** @noinspection PhpIncludeInspection */ include $source_path; } } // クラスローダのインスタンス生成 $klass = new Charcoal_Class($class_name); /** @var Charcoal_IClassLoader $class_loader */ $class_loader = $klass->newInstance(); $class_loader->setSandbox($this); // インタフェース確認 $interface = new Charcoal_Interface('Charcoal_IClassLoader'); $interface->validateImplements($class_loader); // log_info( 'system', "factory", "クラスローダ[" . us($object_path) . "]を作成しました。" ); } catch (Exception $ex) { _catch($ex); _throw(new Charcoal_CreateClassLoaderException($obj_path, $ex)); } return $class_loader; }
/** * create file * * @param string|Charcoal_String $contents * @param Charcoal_File $dir * @param string|Charcoal_String $file_name * * @return Charcoal_File */ public function create($contents, $dir = null, $file_name = null) { if ($file_name === null) { $tmp_filename = Charcoal_System::hash() . '.tmp'; } if ($dir === null) { $dir = Charcoal_ResourceLocator::getFile($this->getSandbox()->getEnvironment(), "%TMP_DIR%"); } $tmp_file = new Charcoal_File($file_name, $dir); if ($tmp_file->isDirectory()) { _throw(new Charcoal_FileSystemComponentException('specified path is directory.')); } if ($tmp_file->exists()) { _throw(new Charcoal_FileSystemComponentException('specified file is already exists.')); } if ($this->overwrite) { if ($tmp_file->exists() && !$tmp_file->canWrite()) { _throw(new Charcoal_FileSystemComponentException('specified file is not writeable.')); } } try { // create file $tmp_file->makeFile($this->mode, $contents, TRUE); $this->file = $tmp_file; return $tmp_file; } catch (Exception $e) { _catch($e); _throw(new Charcoal_TempFileComponentException(s('creating file failed.'), $e)); } return null; }
/** * イベントを処理する */ public function processEvent($context) { $request = $context->getRequest(); $response = $context->getResponse(); $sequence = $context->getSequence(); $procedure = $context->getProcedure(); $space_count = 30; // パラメータを取得 $target = $request->getString('p2'); $out_dir = $request->getString('p3'); //======================================= // Split project / application //======================================= list($project_name, $app_name, $module_path, $task_name) = explode('/', $target . '///'); //======================================= // Confirm input parameters //======================================= if (!empty($project_name) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $project_name)) { _throw(new Charcoal_InvalidShellArgumentException($project_name, 'p2')); } if (!empty($module_path) && !preg_match('/^[@:0-9a-zA-Z_\\-]*$/', $module_path)) { _throw(new Charcoal_InvalidShellArgumentException($module_path, 'p2')); } if (!empty($app_name) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $app_name)) { _throw(new Charcoal_InvalidShellArgumentException($app_name, 'p2')); } if (!empty($task_name) && !preg_match('/^[@:0-9a-zA-Z_\\-]*$/', $task_name)) { _throw(new Charcoal_InvalidShellArgumentException($task_name, 'p2')); } if (!empty($task_name) && (empty($module_path) || empty($app_name) || empty($project_name))) { _throw(new Charcoal_InvalidShellArgumentException($target, 'p2')); } if (empty($task_name) && !empty($module_path) && (empty($app_name) || empty($project_name))) { _throw(new Charcoal_InvalidShellArgumentException($target, 'p2')); } if (empty($task_name) && empty($module_path) && !empty($app_name) && empty($project_name)) { _throw(new Charcoal_InvalidShellArgumentException($target, 'p2')); } //======================================= // output directory //======================================= if (empty($out_dir)) { $out_dir = getcwd() ? getcwd() : Charcoal_ResourceLocator::getFrameworkPath('tmp'); } //======================================= // Send new project event //======================================= if (!empty($project_name)) { $event_path = 'new_project_event@:charcoal:new:project'; $event = $context->createEvent($event_path, array($project_name, $out_dir)); $context->pushEvent($event); } //======================================= // Send new application event //======================================= if (!empty($app_name)) { $event_path = 'new_app_event@:charcoal:new:app'; $event = $context->createEvent($event_path, array($app_name, $project_name, $out_dir)); $context->pushEvent($event); } //======================================= // Send new module event //======================================= if (!empty($module_path)) { $event_path = 'new_module_event@:charcoal:new:module'; $event = $context->createEvent($event_path, array($module_path, $app_name, $project_name, $out_dir)); $context->pushEvent($event); } //======================================= // Send new task event //======================================= if (!empty($task_name)) { $event_path = 'new_task_event@:charcoal:new:task'; $event = $context->createEvent($event_path, array($task_name, $module_path, $app_name, $project_name, $out_dir)); $context->pushEvent($event); } return b(true); }
/** * Get as hash map value * * @param string $key key string for hash map * @param array $default_value default value * @param bool $process_macro if TRUE, value will be replaced by keywords, FALSE otherwise * * @return Charcoal_HashMap */ public function getHashMap($key, $default_value = NULL, $process_macro = FALSE) { // Charcoal_ParamTrait::validateString( 1, $key ); // Charcoal_ParamTrait::validateVector( 2, $default_value, TRUE ); // Charcoal_ParamTrait::validateBoolean( 3, $process_macro ); $key = us($key); $items = parent::getHashMap($key, $default_value); if ($items === NULL) { return NULL; } // remove empty entry foreach ($items as $key => $item) { if (empty($item)) { unset($items[$key]); } } if ($process_macro) { $items = Charcoal_ResourceLocator::processMacro($this->env, $items); } return m($items); }