public function testGetAll() { $container = new Container(); $services = array('test1' => 'test 1', 'test2' => new \DateTime(), 'test3' => $this, 'test4' => null); foreach ($services as $key => $definition) { $container[$key] = function () use($definition) { return $definition; }; } $this->assertEquals($services, $container->getAll()); }
/** * Load & return the content for this page. * * This is not the preferred way of doing this, it is better to use the * `ContentLoader` directly within the controller. However, sometimes this * method makes view building for listings far less complex. * * @todo Figure out a way to not statically call the service container to * adhere to our coding standards. * * @return Content */ public function getContent() { if (!$this->_content) { $this->_content = Container::get('cms.page.content_loader')->load($this); } return $this->_content; }
/** * Get a service. * * For shared services, this invokes `SharedServiceIdentifier`, returning * the closure within it. * * @param string $id Identifier for the service * @return mixed The service definition */ public function offsetGet($id) { if (!$this->isShared($id)) { $raw = $this->raw($id); return $raw($this); } return parent::offsetGet($id); }
/** * @todo investigate whether or not it's possible to inject the heading columns rather than call * it statically */ public function __construct() { $this->_heading = array_values(Container::get('product.upload.csv_heading')->getSimpleColumns()); }
/** * Get the user loader from the service container. This is a pretty dirty * fix to let us access the user's properties instead of just an id number * in the $this->_createdBy property. * * @see https://github.com/messagedigital/cog/issues/179 * * @return unknown The user loader */ protected function _getUserLoader() { if (null === self::$_userLoader) { // Get the user loader statically from the service container. Sorry about this :( self::$_userLoader = Container::get('user.loader'); } return self::$_userLoader; }
public function testInitialiseGetsDefaultServiceContainerInstance() { $container = ServiceContainer::instance(); $loader = $this->getLoader(vfsStream::url(self::VFS_ROOT_DIR)); $loader->initialise(); $this->assertInternalType('object', $container['class.loader']); }
/** * Get the unit associated with this order. * * The unit is loaded with the revision ID stored on this item, so the * options should match. * * The unit is only loaded once per Item instance, unless `$reload` is * passed as true. * * @todo Make this not access the service container statically! * * @param boolean $reload True to force a reload of the Unit instance * * @return \Message\Mothership\Commerce\Product\Unit\Unit */ public function getUnit($reload = false) { if (!$this->_unit || $reload) { $this->_unit = Container::get('product.unit.loader')->includeInvisible(true)->includeOutOfStock(true)->getByID($this->unitID, $this->unitRevision); } return $this->_unit; }
/** * Get a new instance of a field. * * @param string $type The field type to get * @param string $name The name to use for the field * @param string|null $label The optional label for the field * * @return Group * * @throws \InvalidArgumentException If the field type does not exist */ public function getField($type, $name, $label = null) { $label = $label ?: ucfirst($name); $field = clone Container::get('field.collection')->get($type); $field->setName($name)->setLabel($label); $field->setTranslationKey($this->_baseTransKey); return $field; }
/** * Initialises the application & sets up a service definition for the * autoloader class. * * @see _setDefaults * * @return Loader Returns $this for chainability */ public function initialise() { $this->_setDefaults(); // Create the service container if not already created if (!isset($this->_services)) { $this->setServiceContainer(ServiceContainer::instance()); } // Set up service definition for the autoloader $autoloader = $this->_autoloader; $this->_services['class.loader'] = function () use($autoloader) { return $autoloader; }; return $this; }