コード例 #1
0
ファイル: div.php プロジェクト: alterebro/mosquito
 /**
  * Constructor
  *
  * @param string $src
  * @param mixed $items
  * @param array $ignore
  * @return div
  */
 public function __construct($src = null, $items = null, $ignore = array())
 {
     // Enabling system vars
     if (self::$__parse_level < 2) {
         self::enableSystemVar('div' . DIV_TAG_VAR_MEMBER_DELIMITER . 'version');
         self::enableSystemVar('div' . DIV_TAG_VAR_MEMBER_DELIMITER . 'post');
         self::enableSystemVar('div' . DIV_TAG_VAR_MEMBER_DELIMITER . 'get');
         self::enableSystemVar('div' . DIV_TAG_VAR_MEMBER_DELIMITER . 'now');
     }
     // Generate internal and random ignore tag (security reasons)
     $this->__ignore_secret_tag = uniqid();
     // Validate the current dialect
     if (self::$__dialect_checked == false) {
         $r = self::isValidCurrentDialect();
         if ($r !== true) {
             self::error('Current dialect is invalid: ' . $r, DIV_ERROR_FATAL);
         }
         self::$__dialect_checked = true;
     }
     $classname = get_class($this);
     self::$__packages_by_class[$classname] = $this->__packages;
     if (is_null(self::$__super_class)) {
         self::$__super_class = $this->getSuperParent();
     }
     if (is_null(self::$__parent_method_names)) {
         self::$__parent_method_names = get_class_methods(self::$__super_class);
     }
     $this->__id = ++self::$__last_id;
     if (self::$__log_mode) {
         $this->logger('Building instance #' . $this->__id . ' of ' . $classname . '...');
     }
     // Calling the beforeBuild hook
     $this->beforeBuild($src, $items);
     if (is_null($items) && !is_null($this->__items)) {
         $items = $this->__items;
     }
     $this->__items_orig = $items;
     $decode = true;
     $discardfs = self::$__discard_file_system;
     if (is_null($src)) {
         if ($classname != self::$__super_class && is_null($this->__src)) {
             $src = $classname;
         }
         if (!is_null($this->__src)) {
             $src = $this->__src;
         }
     }
     if (is_null($items)) {
         $items = $src;
         $items = str_replace('.' . DIV_DEFAULT_TPL_FILE_EXT, '', $items);
         $decode = false;
     }
     if (!$discardfs) {
         if (self::isString($items)) {
             if (strlen($items . '.' . DIV_DEFAULT_DATA_FILE_EXT) < 255) {
                 $exists = false;
                 if (self::fileExists($items)) {
                     $items = self::getFileContents($items);
                     $exists = true;
                 } elseif (self::fileExists($items . '.' . DIV_DEFAULT_DATA_FILE_EXT)) {
                     $items = self::getFileContents($items . '.' . DIV_DEFAULT_DATA_FILE_EXT);
                     $exists = true;
                 }
                 if ($exists === true || $decode === true) {
                     $items = self::jsonDecode($items);
                 }
                 /*
                  * if ($exists === true)
                  * break;
                  */
             } else {
                 $items = self::jsonDecode($items);
             }
         }
     }
     if (is_object($items)) {
         if (method_exists($items, '__toString')) {
             $itemstr = "{$items}";
             if (!isset($items->value)) {
                 $items->value = $itemstr;
             }
             $items->_to_string = $itemstr;
         }
         $items = get_object_vars($items);
     }
     if (!$discardfs) {
         $src = $this->loadTemplate($src);
     }
     if (!is_array($items)) {
         $items = array();
     }
     $this->__src = $src;
     $this->__src_original = $src;
     $this->__items = $items;
     if (self::isString($ignore)) {
         $ignore = explode(',', $ignore);
     }
     if (isset($ignore[0])) {
         foreach ($ignore as $key => $val) {
             $this->__ignore[$val] = true;
         }
     }
     // Calling the afterBuild hook
     $this->afterBuild();
     // Enabling methods
     if (is_null(self::$__allowed_methods)) {
         $keys = explode(",", DIV_PHP_ALLOWED_METHODS);
         self::$__allowed_methods = array_combine($keys, $keys);
         if (self::$__super_class != $classname) {
             $keys = array_diff(get_class_methods($classname), get_class_methods(self::$__super_class));
             if (isset($keys[0])) {
                 self::$__allowed_methods = array_merge(self::$__allowed_methods, array_combine($keys, $keys));
             }
         }
     }
     // Pre-defined subparsers
     self::setSubParser('parse', 'subParse_parse');
     self::setSubParser('html_wysiwyg', 'subParse_html_wysiwyg');
 }