JOOMLA中国
  • Joomla中国首页
  • 社区
  • 教程
  • 应用市场
  • B计划
Joomla! Framework TM
  • Namespace
  • Class
  • Tree
  • Deprecated

Namespaces

  • Composer
    • Autoload
  • Joomla
    • Application
      • Cli
        • Output
          • Processor
      • Web
    • Data
    • DI
      • Exception
    • Event
    • Filter
    • Input
    • Ldap
    • Registry
      • Format
    • Session
      • Storage
    • String
    • Uri
    • Utilities
  • None
  • PasswordCompat
    • binary
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Yaml
        • Exception
    • Polyfill
      • Util

Classes

  • Container

Interfaces

  • ContainerAwareInterface
  • ServiceProviderInterface

Traits

  • ContainerAwareTrait
 1 <?php
 2 /**
 3  * Part of the Joomla Framework DI Package
 4  *
 5  * @copyright  Copyright (C) 2013 - 2016 Open Source Matters, Inc. All rights reserved.
 6  * @license    GNU General Public License version 2 or later; see LICENSE
 7  */
 8 
 9 namespace Joomla\DI;
10 
11 use Joomla\DI\Container;
12 
13 /**
14  * Defines the trait for a Container Aware Class.
15  *
16  * @since  1.2
17  *
18  * @note   Traits are available in PHP 5.4+
19  */
20 trait ContainerAwareTrait
21 {
22     /**
23      * DI Container
24      *
25      * @var    Container
26      * @since  1.2
27      */
28     private $container;
29 
30     /**
31      * Get the DI container.
32      *
33      * @return  Container
34      *
35      * @since   1.2
36      *
37      * @throws  \UnexpectedValueException May be thrown if the container has not been set.
38      */
39     public function getContainer()
40     {
41         if ($this->container)
42         {
43             return $this->container;
44         }
45 
46         throw new \UnexpectedValueException('Container not set in ' . __CLASS__);
47     }
48 
49     /**
50      * Set the DI container.
51      *
52      * @param   Container  $container  The DI container.
53      *
54      * @return  mixed  Returns itself to support chaining.
55      *
56      * @since   1.2
57      */
58     public function setContainer(Container $container)
59     {
60         $this->container = $container;
61 
62         return $this;
63     }
64 }
65 
Joomla! Framework TM API documentation generated by ApiGen 2.8.0
Joomla!® and Joomla! Framework™ are trademarks of Open Source Matters, Inc. in the United States and other countries.