FOF30\Container\Container::getInstance PHP Method

getInstance() public static method

Pass the value 'tempInstance' => true in the $values array to get a temporary instance. Otherwise you will get the cached instance of the previously created container.
public static getInstance ( string $component, array $values = [], string $section = 'auto' ) : Container
$component string The component you want to get a container for, e.g. com_foobar.
$values array Container configuration overrides you want to apply. Optional.
$section string The application section (site, admin) you want to fetch. Any other value results in auto-detection.
return Container
    public static function &getInstance($component, array $values = array(), $section = 'auto')
    {
        $tempInstance = false;
        if (isset($values['tempInstance'])) {
            $tempInstance = $values['tempInstance'];
            unset($values['tempInstance']);
        }
        if ($tempInstance) {
            return self::makeInstance($component, $values, $section);
        }
        $signature = md5($component . '@' . $section);
        if (!isset(self::$instances[$signature])) {
            self::$instances[$signature] = self::makeInstance($component, $values, $section);
        }
        return self::$instances[$signature];
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Public constructor. Initialises the protected members as well.
  *
  * @param array $config
  */
 public function __construct($config = array())
 {
     $container = Container::getInstance('com_akeeba');
     $config['update_component'] = 'pkg_akeeba';
     $config['update_sitename'] = 'Akeeba Backup Core';
     $config['update_site'] = 'http://cdn.akeebabackup.com/updates/pkgakeebacore.xml';
     $config['update_extraquery'] = '';
     $isPro = defined('AKEEBA_PRO') ? AKEEBA_PRO : 0;
     $dlid = $container->params->get('update_dlid', '');
     // If I have a valid Download ID I will need to use a non-blank extra_query in Joomla! 3.2+
     if (preg_match('/^([0-9]{1,}:)?[0-9a-f]{32}$/i', $dlid)) {
         // Even if the user entered a Download ID in the Core version. Let's switch his update channel to Professional
         $isPro = true;
     }
     if ($isPro) {
         $config['update_sitename'] = 'Akeeba Backup Professional';
         $config['update_site'] = 'http://cdn.akeebabackup.com/updates/pkgakeebapro.xml';
         $config['update_extraquery'] = 'dlid=' . $dlid;
     }
     parent::__construct($config);
     $this->container = $container;
     $this->extension_id = $this->findExtensionId('pkg_akeeba', 'package');
     if (empty($this->extension_id)) {
         $this->createFakePackageExtension();
         $this->extension_id = $this->findExtensionId('pkg_akeeba', 'package');
     }
 }
All Usage Examples Of FOF30\Container\Container::getInstance