コード例 #1
0
ファイル: dataTest.php プロジェクト: cepharum/txf
 public function testAutotypeActing()
 {
     $this->assertEquals(null, data::autoType('null'));
     $this->assertEquals(null, data::autoType('nULl'));
     $this->assertEquals(0, data::autoType('0'));
     $this->assertEquals(100, data::autoType('100'));
     $this->assertEquals(-100, data::autoType("-100 \n\r "));
     $this->assertEquals(0.0, data::autoType(' 0.0'));
     $this->assertEquals(123.4, data::autoType("\t 123.4 "));
     $this->assertEquals(-123.465, data::autoType("\t -123.465 "));
     $this->assertEquals(false, data::autoType('fALse'));
     $this->assertEquals(false, data::autoType('nO'));
     $this->assertEquals(false, data::autoType('oFf'));
     $this->assertEquals(true, data::autoType('trUe'));
     $this->assertEquals(true, data::autoType('YeS'));
     $this->assertEquals(true, data::autoType('oN'));
 }
コード例 #2
0
ファイル: thread.php プロジェクト: cepharum/txf
 /**
  * Extends current thread by provided XML.
  *
  * @param SimpleXMLElement|string $xml XML document used to extend current thread
  * @return thread current instance
  */
 public function fromXml($xml)
 {
     if (is_string($xml) || $xml instanceof string) {
         $xml = simplexml_load_string(trim($xml));
     }
     if ($xml instanceof \SimpleXMLElement) {
         foreach ($xml as $name => $data) {
             $attributes = $xml->attributes();
             if ($data instanceof \SimpleXMLElement && $data->count()) {
                 $this->__get($name)->fromXml($data);
             } else {
                 $this->__set($this->___valueName, data::autoType(strval($data), $attributes->type));
                 if ($attributes->default) {
                     $this->__set($this->___specialValueName, $attributes->default);
                 }
             }
             if ($attributes->label) {
                 $this->__set($this->___labelName, $attributes->label);
             }
         }
     }
     return $this;
 }
コード例 #3
0
ファイル: session.php プロジェクト: cepharum/txf
 /**
  * Restores variable space from current snapshot made to be storable in
  * session.
  */
 protected final function makeUsable()
 {
     if (trim($this->storable)) {
         if (data::autoType(config::get('session.encrypt', false), 'boolean')) {
             try {
                 $space = unserialize(crypt::create()->decrypt($this->storable));
             } catch (\InvalidArgumentException $e) {
                 log::warning('session lost due to failed decryption, might be okay if browser lost cookie in between');
                 $space = array();
             }
         } else {
             $space = unserialize($this->storable);
         }
         if (is_array($space)) {
             $this->usable = $space;
         }
         $this->storable = null;
     }
     if (!is_array($this->usable)) {
         $this->usable = array();
     }
 }
コード例 #4
0
ファイル: application.php プロジェクト: cepharum/txf
 protected function __construct(context $context)
 {
     $this->context = $context;
     $envApplicationName = getenv('TXF_APPLICATION');
     $this->gotNameFromEnvironment = !!$envApplicationName;
     /*
      * extract selected application and source
      */
     // choose source of application/script selector
     $frames = $context->getRequestedScriptUri($this->usedProxy);
     if (empty($frames)) {
         throw new http_exception(400, 'Request missing application. Check your setup!');
     }
     // extract information on application folder and name
     if ($this->gotNameFromEnvironment) {
         $this->name = $envApplicationName;
     } else {
         $this->name = array_shift($frames);
     }
     if ($this->name == 'txf') {
         throw new http_exception(404, 'Requested application doesn\'t exist.');
     }
     // add some derived properties for conveniently addressing application
     $this->pathname = path::glue($context->installationPathname, $this->name);
     // find selected script's pathname and name
     if (empty($frames)) {
         $this->script = 'index.php';
     } else {
         $script = array();
         while (count($frames)) {
             $script[] = array_shift($frames);
             $pathname = path::glue($this->pathname, implode('/', $script));
             if (is_file($pathname)) {
                 break;
             }
             if (is_file("{$pathname}.php")) {
                 $script[] = array_pop($script) . '.php';
                 break;
             }
         }
         $this->script = implode('/', $script);
     }
     // extract additional selectors to be available in script
     if (txf::getContextMode() == txf::CTXMODE_REWRITTEN) {
         $this->selectors = $frames;
     } else {
         $this->selectors = explode('/', $_SERVER['PATH_INFO']);
     }
     $urlDecodeSelector = !!getenv('TXF_URLDECODE_SELECTORS');
     $this->selectors = array_map(function ($a) use($urlDecodeSelector) {
         if ($urlDecodeSelector) {
             $a = urldecode($a);
         }
         return data::autoType(trim($a));
     }, $this->selectors);
     // prepare application's base URL
     if ($this->gotNameFromEnvironment) {
         $this->url = $context->url;
     } else {
         $this->url = path::glue($context->url, $this->name);
     }
 }
コード例 #5
0
ファイル: set.php プロジェクト: cepharum/txf
 /**
  * Converts XML-notated data into array.
  *
  * @param \SimpleXMLElement $xml XML thread to convert
  * @param array $level array to be extended/replaced by extracted XML data
  * @return array array representing data found in XML
  */
 protected static function xml2Array(\SimpleXMLElement $xml, $level = array())
 {
     $overlay = array();
     foreach ($xml->children() as $sub) {
         // get name of element to convert
         $name = $sub->getName();
         // want to extend some existing data of element?
         $extend = trim($sub['extend']);
         $extend = $extend ? preg_match('/^on|yes|true|y|extend$/i', $extend) : array_key_exists($name, $overlay);
         // prepare to actually extend some existing data
         if (array_key_exists($name, $overlay)) {
             $existing = $overlay[$name];
         } else {
             if (array_key_exists($name, $level)) {
                 $existing = $level[$name];
             } else {
                 $existing = array();
                 $extend = false;
             }
         }
         if ($extend) {
             // start new set initially containing previously collected sole element
             $overlay[$name] = is_array($existing) && !static::isHash($existing) ? $existing : array($existing);
         }
         // get described data of current element
         $value = self::xml2Array($sub, $extend || !is_array($existing) ? array() : $existing);
         if ($extend) {
             // merge with existing data
             $overlay[$name][] = $value;
         } else {
             // set data replacing some existing data
             $overlay[$name] = $value;
         }
     }
     // apply created overlay to initially provided level of data
     foreach ($overlay as $name => $value) {
         $level[$name] = $value;
     }
     if (count($level)) {
         return $level;
     }
     if ((string) $xml === '') {
         return array();
     }
     return data::autoType(_S($xml, 'utf-8')->asUtf8);
 }