/** * 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; }
/** * Initialize instance * * @param Charcoal_Config $config configuration data */ public function configure($config) { parent::configure($config); $this->task_manager = us($config->getString('task_manager', '')); $this->forward_target = us($config->getString('forward_target', '')); $this->modules = uv($config->getArray('modules', array())); $this->events = uv($config->getArray('events', array())); $this->debug_mode = ub($config->getBoolean('debug_mode', FALSE)); $this->log_enabled = ub($config->getBoolean('log_enabled')); $this->log_level = us($config->getString('log_level')); $this->log_loggers = uv($config->getArray('log_loggers')); // eventsに記載しているイベントのモジュールも読み込む if (is_array($this->events)) { foreach ($this->events as $event) { $pos = strpos($event, "@"); if ($pos !== FALSE) { $this->modules[] = substr($event, $pos); } } } if ($this->getSandbox()->isDebug()) { log_info("system, debug, config", "task_manager:" . $this->task_manager, self::TAG); log_info("system, debug, config", "forward_target:" . $this->forward_target, self::TAG); log_info("system, debug, config", "modules:" . print_r($this->modules, true), self::TAG); log_info("system, debug, config", "events:" . print_r($this->events, true), self::TAG); log_info("system, debug, config", "debug_mode" . $this->debug_mode, self::TAG); log_info("system, debug, config", "log_enabled" . $this->log_enabled, self::TAG); log_info("system, debug, config", "log_level" . $this->log_level, self::TAG); log_info("system, debug, config", "log_loggers" . print_r($this->log_loggers, true), self::TAG); } }
/** * Process events * * @param Charcoal_IEventContext $context event context * * @return boolean|Charcoal_Boolean */ public function processEvent($context) { // check if the access is granted $auth = $this->isAuthorized($context); if (ub($auth) !== TRUE) { // create security fault event /** @var Charcoal_Event $event */ $event = $this->getSandbox()->createEvent('security_fault'); $context->pushEvent($event); return b(TRUE); } // check permissions $has_permission = $this->hasPermission($context); if (ub($has_permission) !== TRUE) { $event = $this->permissionDenied($context); if ($event) { return $event; } /** @var Charcoal_Event $event */ $event = $this->getSandbox()->createEvent('permission_denied'); $context->pushEvent($event); return b(TRUE); } return $this->processEventSecure($context); }
/** * initialize exception handler list */ public function init() { // if this object is already initialized, do nothing if ($this->init) { return TRUE; } // if our sandbox is not loaded, do nothing if (!$this->sandbox->isLoaded()) { return FALSE; } // read initialization options from sandbox profile $this->log_enabled = ub($this->sandbox->getProfile()->getBoolean('LOG_ENABLED', FALSE)); $this->log_level = us($this->sandbox->getProfile()->getString('LOG_LEVEL', 'W')); $this->log_no_buffer = ub($this->sandbox->getProfile()->getBoolean('LOG_NO_BUFFER', FALSE)); $this->log_tag_filters = uv($this->sandbox->getProfile()->getArray('LOG_TAG_FILTERS', array())); $this->log_loggers = uv($this->sandbox->getProfile()->getArray('LOG_LOGGERS', array())); $this->loggers = array(); // create loggers on demand if ($this->log_loggers) { foreach ($this->log_loggers as $logger_name) { if (strlen($logger_name) === 0) { continue; } if (!isset($this->loggers[$logger_name])) { $logger = $this->sandbox->createObject($logger_name, 'logger', array(), 'Charcoal_ILogger'); self::register($logger_name, $logger); } else { log_warning("system,debug,error", "Logger[{$logger_name}] is already registered!"); } } } $this->init = TRUE; return TRUE; }
/** * Initialize instance * * @param Charcoal_Config $config configuration data */ public function configure($config) { parent::configure($config); $this->debug_mode = ub($config->getBoolean('debug_mode', FALSE)); $this->smarty->caching = 0; //$config->getBoolean( 'caching' )->unbox(); $this->smarty->compile_check = ub($config->getBoolean('compile_check', FALSE)); $this->smarty->template_dir = us($config->getString('template_dir', '', TRUE)); $this->smarty->compile_dir = us($config->getString('compile_dir', '', TRUE)); $this->smarty->config_dir = us($config->getString('config_dir', '', TRUE)); $this->smarty->cache_dir = us($config->getString('cache_dir', '', TRUE)); $this->smarty->left_delimiter = us($config->getString('left_delimiter', '{', FALSE)); $this->smarty->right_delimiter = us($config->getString('right_delimiter', '}', FALSE)); // $this->smarty->default_modifiers = $config->getArray( 'default_modifiers', array() )->unbox(); $plugins_dir = uv($config->getArray('plugins_dir', array(), TRUE)); // add default plugins_dir: Smarty/Smarty/plugins $reflector = new ReflectionClass($this->smarty); $plugins_dir[] = dirname($reflector->getFileName()) . '/plugins'; $this->smarty->plugins_dir = $plugins_dir; log_debug("smarty", "smarty->plugins_dir=" . print_r($this->smarty->plugins_dir, true), self::TAG); log_debug("smarty", "smarty=" . spl_object_hash($this->smarty), self::TAG); if ($this->debug_mode) { $smarty_options = array('caching' => $this->smarty->caching, 'compile_check' => $this->smarty->compile_check, 'template_dir' => $this->smarty->template_dir, 'compile_dir' => $this->smarty->compile_dir, 'config_dir' => $this->smarty->config_dir, 'cache_dir' => $this->smarty->cache_dir, 'default_modifiers' => $this->smarty->default_modifiers, 'plugins_dir' => $this->smarty->plugins_dir, 'left_delimiter' => $this->smarty->left_delimiter, 'right_delimiter' => $this->smarty->right_delimiter); ad($smarty_options); foreach ($smarty_options as $key => $value) { log_debug('system, debug, smarty', "smarty option: [{$key}]=" . Charcoal_System::toString($value)); } } }
/** * Constructor * * @param string|Charcoal_String $section * @param string|Charcoal_String $action * @param boolean|Charcoal_Boolean $success If TRUE, the test succeeded */ public function __construct($section, $action, $success) { parent::__construct(); $this->section = us($section); $this->action = us($action); $this->success = ub($success); }
/** * Generate RDBMS-specific SQL for CREATE TABLE * * @param Charcoal_ITableModel $model table model object related with th query * @param boolean|Charcoal_Boolean $if_not_exists If TRUE, output SQL includes "IF NOT EXISTS" wuth "CREATE TABLE" * * @return string SQL */ public function buildCreateTableSQL($model, $if_not_exists = false) { Charcoal_ParamTrait::validateIsA(1, 'Charcoal_ITableModel', $model); Charcoal_ParamTrait::validateBoolean(2, $if_not_exists); try { $field_list = $model->getFieldList(); $SQL_pk_list = array(); $SQL_field_list = array(); foreach ($field_list as $name) { $name = s($name); $pk = $model->getAnnotationValue($name, s('pk')); $type = $model->getAnnotationValue($name, s('type')); $notnull = $model->getAnnotationValue($name, s('notnull')); $charset = $model->getAnnotationValue($name, s('charset')); $serial = $model->getAnnotationValue($name, s('serial')); $default = $model->getAnnotationValue($name, s('default')); $comment = $model->getAnnotationValue($name, s('comment')); /** @var Charcoal_AnnotationValue $type */ $type_name = $this->mapType($type->getValue()); $field_expr = "`{$name}` {$type_name}"; if ($pk) { $SQL_pk_list[] = "`{$name}`"; if ($notnull) { $field_expr .= ' NOT NULL'; } if ($serial) { $field_expr .= ' AUTO_INCREMENT'; } if ($comment) { $field_expr .= " COMMENT '" . $comment->getValue() . "'"; } } else { if ($default) { $field_expr .= ' DEFAULT ' . $default->getValue(); } if ($charset) { $field_expr .= " CHARACTER SET {$charset}"; } if ($notnull) { $field_expr .= ' NOT NULL'; } if ($comment) { $field_expr .= " COMMENT '" . $comment->getValue() . "'"; } } $SQL_field_list[] = $field_expr; } $SQL_field_list = implode(",\n", $SQL_field_list); $SQL_pk_list = implode(',', $SQL_pk_list); $table_name = $model->getTableName(); $if_not_exists = ub($if_not_exists) ? 'IF NOT EXISTS' : ''; $sql = "CREATE TABLE {$if_not_exists} `{$table_name}` (\n {$SQL_field_list} \n ,PRIMARY KEY( {$SQL_pk_list} ) )"; log_debug("debug,sql,smart_gateway", "buildCreateTableSQL result: {$sql}", self::TAG); return $sql; } catch (Exception $e) { _throw(new Charcoal_SQLBuilderException("MySQL_SQLBuilder#buildCreateTableSQL failed")); } return ''; }
/** * Initialize instance * * @param Charcoal_Config $config configuration data */ public function configure($config) { parent::configure($config); $enable_cahche = $config->getBoolean('enable_cahche', true); $cache_dir = $config->getString('cache_dir', CHARCOAL_CACHE_DIR . '/simplepie', TRUE); $duration = $config->getInteger('duration', 1800); $this->simple_pie->enable_cache(ub($enable_cahche)); $this->simple_pie->set_cache_location(us($cache_dir)); $this->simple_pie->set_cache_duration(ui($duration)); }
/** * Initialize instance * * @param Charcoal_Config $config configuration data */ public function configure($config) { parent::configure($config); $encoding = $config->getString('encoding', 'utf8'); $indent = $config->getBoolean('indent', true); $output_xhtml = $config->getBoolean('output-xhtml', true); $output_html = $config->getBoolean('output-html', true); $wrap = $config->getInteger('wrap', 200); $show_body_only = $config->getBoolean('show-body-only', true); $clean = $config->getBoolean('clean', false); $this->config = array('indent' => ub($indent), 'output-xhtml' => ub($output_xhtml), 'output-html' => ub($output_html), 'wrap' => ui($wrap), 'show-body-only' => ub($show_body_only), 'clean' => ub($clean)); $this->encoding = us($encoding); }
/** * Constructor * * @param Charcoal_String|string $sandbox_name * @param boolean|NULL $debug * @param array $config */ public function __construct($sandbox_name, $debug = NULL, $config = NULL) { // Charcoal_ParamTrait::validateString( 1, $sandbox_name ); // Charcoal_ParamTrait::validateBoolean( 2, $debug, TRUE ); // Charcoal_ParamTrait::validatRawArray( 3, $config, TRUE ); $this->sandbox_name = $sandbox_name; $this->debug = $debug ? ub($debug) : FALSE; $this->registry = isset($config['registry']) ? $config['registry'] : new Charcoal_FileSystemRegistry($this); $this->codebase = isset($config['codebase']) ? $config['codebase'] : new Charcoal_PlainCodebase($this); $this->container = isset($config['container']) ? $config['container'] : new Charcoal_DIContainer($this); $this->environment = isset($config['environment']) ? $config['environment'] : $this->getDefaultEnvironment(); $this->profile = isset($config['profile']) ? $config['profile'] : new Charcoal_SandboxProfile($this); }
/** * parse XML * * @param Charcoal_String|string $data Chunk of data to parse * @param Charcoal_Boolean|bool $is_final If set and TRUE, data is the last piece of data sent in this parse. * * @return bool Returns 1 on success or 0 on failure. */ public function parse($data, $is_final = false) { Charcoal_ParamTrait::validateString(1, $data); Charcoal_ParamTrait::validateBoolean(2, $is_final); if (!$this->parser) { _throw(new PhpXmlParserComponentException('parser object is not created')); } return xml_parse($this->parser, us($data), ub($is_final)); }
/** * Inserts HTML line breaks before all newlines in a string * * @param bool $is_xhtml Whether to use XHTML compatible line breaks or not. * * @return Charcoal_String this object */ public function nl2br($is_xhtml = true) { $this->value = nl2br($this->value, ub($is_xhtml)); return $this; }
/** * Merge with hashmap * * @param array $array hash map data to merge * @param boolean $overwrite TRUE means overwrite if the original element exists */ public function mergeHashMap($map, $overwrite = TRUE) { // Charcoal_ParamTrait::validateHashMap( 1, $map ); // Charcoal_ParamTrait::validateBoolean( 2, $overwrite ); $overwrite = ub($overwrite); if ($overwrite) { foreach ($map as $key => $value) { $this->offsetSet($key, $value); } } }
public function autoCommit($on) { $on = ub($on); try { Charcoal_ParamTrait::validateBoolean(1, $on); // 接続処理 $this->connect(); $this->getConnection()->setAttribute(PDO::ATTR_AUTOCOMMIT, $on); } catch (Exception $e) { _catch($e); _throw(new Charcoal_DBDataSourceException(__METHOD__ . " Failed.", $e)); } }
/** * Initialize instance * * @param Charcoal_Config $config configuration data */ public function configure($config) { $switcher = new Charcoal_ErrorReportingSwitcher(0, E_DEPRECATED); parent::configure($config); if (is_array($config) || $config === NULL) { $config = new Chacoal_Config($config); } // ========================================= // QdMail設定 // ========================================= // エラーを画面に出力するか $qdmail_error_display = $config->getBoolean('qdmail.error_display', FALSE); $this->qdmail->errorDisplay(ub($qdmail_error_display)); // ログ設定 $qdmail_log_level = $config->getInteger('qdmail.log_level', 0); $qdmail_log_path = $config->getString('qdmail.log_path', '', TRUE); $qdmail_log_filename = $config->getString('qdmail.log_filename', '', TRUE); $this->qdmail->logLevel(ui($qdmail_log_level)); $this->qdmail->logPath(us($qdmail_log_path)); $this->qdmail->logFilename("/" . $qdmail_log_filename); // エラーログ設定 $qdmail_error_display = $config->getBoolean('qdmail.error_display', FALSE); $qdmail_error_log_level = $config->getInteger('qdmail.error_log_level', 0); $qdmail_error_log_path = $config->getString('qdmail.error_log_path', '', TRUE); $qdmail_error_log_filename = $config->getString('qdmail.error_log_filename', '', TRUE); $this->qdmail->errorDisplay(ub($qdmail_error_display)); $this->qdmail->errorlogLevel(ui($qdmail_error_log_level)); $this->qdmail->errorlogPath(us($qdmail_error_log_path)); $this->qdmail->errorlogFilename("/" . $qdmail_error_log_filename); // ========================================= // QdSMTP設定 // ========================================= $qdsmtp = $config->getBoolean('qdsmtp', FALSE); if (!$qdsmtp) { $this->qdmail->smtp(false); } else { // エラーを画面に出力するか $qdsmtp_error_display = $config->getBoolean('qdsmtp.error_display', FALSE); $this->qdmail->smtpObject()->error_display = ub($qdsmtp_error_display); // ログ設定 $qdsmtp_log_level = $config->getInteger('qdsmtp.log_level', 0); $qdsmtp_log_filename = $config->getString('qdsmtp.log_filename', '', TRUE); $qdsmtp_error_log_level = $config->getInteger('qdsmtp.error_log_level', 0); $qdsmtp_error_log_filename = $config->getString('qdsmtp.error_log_filename', '', TRUE); $qdsmtp_error_display = $config->getBoolean('qdsmtp.error_display', FALSE); $this->qdmail->smtpObject()->logLevel(ui($qdsmtp_log_level)); $this->qdmail->smtpObject()->logFilename(us($qdsmtp_log_filename)); $this->qdmail->smtpObject()->errorlogLevel(ui($qdsmtp_error_log_level)); $this->qdmail->smtpObject()->errorlogFilename(us($qdsmtp_error_log_filename)); $this->qdmail->smtpObject()->error_display = $qdsmtp_error_display; // サーバ設定 $qdsmtp_host = $config->getString('qdsmtp.host', ''); $qdsmtp_port = $config->getString('qdsmtp.port', ''); $qdsmtp_from = $config->getString('qdsmtp.from', ''); $qdsmtp_protocol = $config->getString('qdsmtp.protocol', ''); $qdsmtp_user = $config->getString('qdsmtp.user', ''); $qdsmtp_pass = $config->getString('qdsmtp.pass', ''); $options = array('host' => us($qdsmtp_host), 'port' => us($qdsmtp_port), 'from' => us($qdsmtp_from), 'protocol' => us($qdsmtp_protocol), 'user' => us($qdsmtp_user), 'pass' => us($qdsmtp_pass)); $this->qdmail->smtp(true); $result = $this->qdmail->smtpServer($options); if ($result === FALSE) { _throw(new Charcoal_QdmailException($this->qdmail)); } } log_debug("debug, qdmail_sender", "component configs are:" . print_r($config, true)); }
public function setHttpOnly($httponly) { $this->httponly = ub($httponly); }
public function validate($sequence, $form_token, $throws = TRUE) { Charcoal_ParamTrait::validateIsA(1, 'Charcoal_ISequence', $sequence); Charcoal_ParamTrait::validateString(2, $form_token); Charcoal_ParamTrait::validateBoolean(3, $throws); $throws = ub($throws); log_debug("debug", "sequence: " . print_r($sequence, true)); log_debug("debug", "form_token: " . print_r($form_token, true)); if ($this->getSandbox()->isDebug() && $this->debug_mode) { ad($sequence, array('title' => "sequence")); } $token_key = $this->token_key; log_debug("debug", "token_key: " . print_r($token_key, true)); if ($this->getSandbox()->isDebug() && $this->debug_mode) { ad($token_key, array('title' => "token_key", "type" => "div")); } // get token container from session. $token_list = $sequence->get(s($token_key)); if ($this->getSandbox()->isDebug() && $this->debug_mode) { ad($token_list, array('title' => "token list")); } log_debug("debug", "token_list: " . print_r($token_list, true)); if ($token_list === NULL || !is_array($token_list)) { $token_list = array(); } // find token from token list. $token_index = NULL; foreach ($token_list as $idx => $token) { log_info("debug", "token: {$token}"); if ($this->getSandbox()->isDebug() && $this->debug_mode) { ad($token, array('title' => "token", "type" => "div")); } if ($token == $form_token) { $token_index = $idx; break; } } if ($token_index === NULL) { // illegal access log_warning("system, debug", "token not found: {$form_token}"); if ($this->getSandbox()->isDebug() && $this->debug_mode) { ad($form_token, array('title' => "token not found", "type" => "div")); } if ($throws) { _throw(new Charcoal_FormTokenValidationException('token not found in sequence:' . $form_token), FALSE); } return FALSE; } else { // authorized access log_debug("debug", "token accepted: {$form_token}"); if ($this->getSandbox()->isDebug() && $this->debug_mode) { ad($form_token, array('title' => "token accepted", "type" => "div")); } // erase token from token list to prevent duplicate form submission. unset($token_list[$token_index]); } // update token list in sequence. $sequence->set($token_key, $token_list); // the event was successfully processed. return TRUE; }
/** * Set overwrite mode * * @param Charcoal_Boolean $overwrite TRUE if the temporary file should be overwritten, FALSE otherwise. */ public function setOverwrite(Charcoal_Boolean $overwrite) { $this->_overwrite = ub($overwrite); }
/** * Merge all elements in a HashMap object into container * * @param Charcoal_IRequest $request Request object to merge * @param Charcoal_Boolean $overwrite If TRUE, container values will be overwrited by properties data. */ public function mergeRequest($request, $overwrite = TRUE) { // Charcoal_ParamTrait::validateIsA( 1, 'Charcoal_IRequest', $request ); // Charcoal_ParamTrait::validateRawBool( 2, $overwrite ); $overwrite = ub($overwrite); if ($overwrite) { foreach ($request as $key => $value) { $this->values[$key] = $value; } } }
/** * Applies logical operation 'OR' on this object * * @param boolean $target operator target */ public function operateOr($target) { $this->value |= ub($target); }
/** * Generate RDBMS-specific SQL for DROP TABLE * * @param Charcoal_ITableModel $model table model object related with th query * @param boolean|Charcoal_Boolean $if_exists If TRUE, output SQL includes "IF EXISTS" wuth "DROP TABLE" * * @return string SQL */ public function buildDropTableSQL($model, $if_exists = false) { Charcoal_ParamTrait::validateIsA(1, 'Charcoal_ITableModel', $model); Charcoal_ParamTrait::validateBoolean(2, $if_exists); $table_name = $model->getTableName(); $if_exists = ub($if_exists) ? 'IF EXISTS' : ''; $sql = "DROP TABLE {$if_exists} `{$table_name}`"; return $sql; }
/** * Set overwrite mode * * @param bool|Charcoal_Boolean $overwrite TRUE if the temporary file should be overwritten, FALSE otherwise. */ public function setOverwrite($overwrite) { Charcoal_ParamTrait::validateBoolean(1, $overwrite); $this->overwrite = ub($overwrite); }