/** * If we're publishing, returns proper php */ public function obj($fieldName, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null) { $value = parent::obj($fieldName, $arguments, $forceReturnedObject, $cache, $cacheName); // if we're publishing and this variable is qualified, output php code instead if ($this->failover && $this->liveVars && isset($this->varName) && LivePubHelper::is_publishing() && $this->isLiveVar($fieldName)) { $accessor = "get{$fieldName}"; $php = ''; // find out how we got the data if ($this->failover instanceof ArrayData) { $php = '$' . $this->varName . '["' . $fieldName . '"]'; } elseif (is_callable(array($this->failover, $fieldName))) { // !@TODO respect arguments $php = '$' . $this->varName . '->' . $fieldName . '()'; } elseif (is_callable(array($this->failover, $accessor))) { // !@TODO respect arguments $php = '$' . $this->varName . '->' . $accessor . '()'; } elseif (isset($this->failover, $fieldName)) { $php = '$' . $this->varName . '->' . $fieldName; } // return the appropriate php if ($php) { if (is_object($value)) { if ($value instanceof ViewableWrapper) { LivePubHelper::$init_code[] = '<?php $' . $value->getVar() . ' = ' . $php . ' ?>'; } // !@TODO: only other option is DataObjectSet - check that this is handled right } else { $value = in_array($fieldName, $this->liveVarsUnescaped) ? '<?php echo ' . $php . '; ?>' : '<?php echo htmlentities(' . $php . '); ?>'; if ($forceReturnedObject) { $value = new HTMLText($value); } } } } return $value; }
/** * checks that ViewableWrapper works in normal mode */ public function testWrapperUnpublished() { if (LivePubHelper::is_publishing()) { LivePubHelper::stop_pub(); } // test an array $o = $this->getArrayWrapper(); $this->assertEquals($o->a, 'b'); $this->assertEquals($o->b, 5); $this->assertNotNull($o->c); $this->assertTrue($o->c instanceof ViewableWrapper); $this->assertEquals($o->c->e, 'f'); $this->assertNotNull($o->d); $this->assertTrue($o->d instanceof ViewableWrapper); $this->assertEquals($o->d->h, 'i'); $this->assertTrue($o->e instanceof ArrayList); $this->assertEquals($this->getTestTemplate()->process($o), 'A=b, B=5, C.E=f, D.H=i, E=12'); // test an object $o = $this->getObjectWrapper(); $this->assertEquals($o->a, 'b'); $this->assertEquals($o->b, 5); $this->assertNotNull($o->c); $this->assertTrue($o->c instanceof ViewableWrapper); $this->assertEquals($o->c->e, 'f'); $this->assertNotNull($o->d); $this->assertTrue($o->d instanceof ViewableWrapper); $this->assertEquals($o->d->h, 'i'); $this->assertTrue($o->e instanceof ArrayList); $this->assertEquals($this->getTestTemplate()->process($o), 'A=b, B=5, C.E=f, D.H=i, E=12'); }
/** * called when publishing is done */ public static function stop_pub() { self::$is_publishing = false; }
function LPH_EndIf() { if (LivePubHelper::is_publishing()) { return '<?php endif; ?>'; } }