本文整理汇总了PHP中data::autoType方法的典型用法代码示例。如果您正苦于以下问题:PHP data::autoType方法的具体用法?PHP data::autoType怎么用?PHP data::autoType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类data
的用法示例。
在下文中一共展示了data::autoType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAutotypeActing
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: fromXml
/**
* 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: makeUsable
/**
* 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: __construct
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: xml2Array
/**
* 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);
}