/** * Returns a collection of Foo instances according to * the configuration section. */ public function &process(__ConfigurationSection &$section) { $return_value = array(); $foobars = $section->getSections(); foreach ($foobars as &$foobar) { $foo = new Foo(); $foo->setBar($foobar->getAttribute('bar')); $return_value[] = $foo; } return $return_value; }
/** * Gets the 'foo_with_inline' service. * * This service is shared. * This method always returns the same instance of the service. * * @return \Foo A Foo instance. */ protected function getFooWithInlineService() { $this->services['foo_with_inline'] = $instance = new \Foo(); $instance->setBar($this->get('inlined')); return $instance; }
/** * Gets the 'foo_with_inline' service. * * This service is shared. * This method always returns the same instance of the service. * * @return \Foo A Foo instance */ protected function getFooWithInlineService() { $a = new \Bar(); $this->services['foo_with_inline'] = $instance = new \Foo(); $a->setBaz($this->get('baz')); $a->pub = 'pub'; $instance->setBar($a); return $instance; }
/** * Gets the 'foo_with_inline' service. * * This service is shared. * This method always returns the same instance of the service. * * @return \Foo A Foo instance */ protected function getFooWithInlineService() { $this->services['foo_with_inline'] = $instance = new \Foo(); $instance->setBar(${($_ = isset($this->services['inlined']) ? $this->services['inlined'] : $this->getInlinedService()) && false ?: '_'}); return $instance; }
<?php require_once 'pb_proto_foo.php'; $foo = new Foo(); $foo->setBar(1); $foo->setBaz('two'); $foo->appendSpam(3.0); $foo->appendSpam(4.0); $packed = $foo->serializeToString(); $foo->reset(); try { $foo->parseFromString($packed); } catch (Exception $ex) { die('Upss.. there is a bug in this example'); } $foo->dump();