SlideShare uma empresa Scribd logo
1 de 31
Киев
             15 сентября 2012




Magento DI
Software Entropy

Pull-approach and its problems

Push-approach

Magento Object Manager
Software entropy
Software entropy cycle
Pull-approach
Mage::getModel(“Mage_Cms_Model_Page”)

Mage::getSingleton(“Mage_Cms_Model_Page”)
class Mage_Cms_Model_Page
{
   public function __construct()
   {
     $this->_idFieldName = Mage::getResourceSingleton($this->_resourceName);
   }

    public function getAvailableStatuses()
    {
      $statuses = new Varien_Object(array(
          self::STATUS_ENABLED => Mage::helper('Mage_Cms_Helper_Data')->__('Enabled')
          self::STATUS_DISABLED => Mage::helper('Mage_Cms_Helper_Data')        ->__(„Disabled')
      ));
      Mage::dispatchEvent('cms_page_get_available_statuses', array('statuses' => $statuses));
    }
}
class Mage_Cms_Model_PageTest extends PHPUnit_Framework_TestCase
{
   public function setUp()
   {
     $this->_page = new Mage_Cms_Model_Page();
   }
}
class Mage_Cms_Model_PageTest extends PHPUnit_Framework_TestCase
{
   public function setUp()
   {
        Mage::setResourceSingleton(„Page_Resource‟, $this->getMock(„Page_Resource‟));
        $this->_page = new Mage_Cms_Model_Page();
    }

    public function testProcessDoesSomething()
    {
      Mage::setHelper(„Mage_Cms_Helper_Data‟, $this->getMock(„Mage_Cms_Helper_Data‟));
      $this->assertSomething($this->_page->process());
    }
}
Mage::getXXX() ===
Push-approach
class Mage_Core_Model_Abstract
{
   public function __construct(array $data = array())
   {
     parent::__construct($data);
     $this->_construct();
   }
}
class Mage_Core_Model_Abstract
{
   public function __construct(
     Mage_Core_Model_Event_Manager $eventDispatcher,
     Mage_Core_Model_Cache $cacheManager,
     Mage_Core_Model_Resource_Abstract $resource = null,
     Varien_Data_Collection_Db $resourceCollection = null,
     array $data = array()
   ){
     $this->_eventDispatcher = $eventDispatcher;
     $this->_cacheManager = $cacheManager;
     $this->_resource = $resource;
     $this->_resourceCollection = $resourceCollection;

        parent::__construct($data);
        $this->__construct();
    }
}
Mage::getXXX()


Mage_Some_Class::__construct()
   Magento_ObjectManager
Magento Object Manager
interface Magento_ObjectManager
{
    public function get($className, $arguments);

    public function create($className, $arguments);
}
ZendDi
class Mage_Core_Model_Abstract
{
   public function __construct(
     Mage_Core_Model_Event_Manager $eventDispatcher,
     Mage_Core_Model_Cache $cacheManager,
     Mage_Core_Model_Resource_Abstract $resource = null,
     Varien_Data_Collection_Db $resourceCollection = null,
     array $data = array()
   ){
     $this->_eventDispatcher = $eventDispatcher;
     $this->_cacheManager = $cacheManager;
     $this->_resource = $resource;
     $this->_resourceCollection = $resourceCollection;

        parent::__construct($data);
        $this->__construct();
    }
}
<config>
  <global>
    <di>
       <Mage_Core_Model_Cache>
          <parameters>
            <cacheDir>/path/to/cache/dir</cacheDir>
          </parameters>
       </Mage_Core_Model_Cache>
    </di>
  </global>
</config>
<di>
  <Magento_Data_Structure>
     <shared>0</shared>
  </Magento_Data_Structure>
</di>
public function __construct(Some_Interface $processor)
<adminhtml>
  <di>
     <preferences>
       <Some_Interface>Some_Backend_Implementation</Some_Interface>
     </preferences>
  </di>
</adminhtml>
<api>
  <di>
     <preferences>
       <Some_Interface>Some_Api_Implementation</Some_Interface>
     </preferences>
  </di>
</api>
INJECTABLES               -   NON-INJECTABLES
 Varien_Db_Adapter
                               Mage_Catalog_Model_Product
 Mage_Core_Model_Cache
                               Mage_Wishlist_Model_Wishlist
 Mage_Core_Model_Config
class Varien_Data_Collection
{
   //...
    public function getNewEmptyItem()
   {
       return Mage::getModel($this->_itemObjectClass);
   }
    //...
}
class Varien_Data_Collection
{
   public function __construct(Magento_ObjectFactory $factory)
   {
     $this->_itemFactory = $factory;
   }

    //...
    public function getNewEmptyItem()
    {
        return $this->_itemFactory->create();
    }
    //...
}
class Mage_Catalog_Model_Product_Factory implements Magento_ObjectManager_Factory
{
   protected $_objectManager;

    public function __construct(Magento_ObjectManager $objectManager)
    {
      $this->_objectManager = $objectManager;
    }

    public function createFromArray(array $arguments = array())
    {
      return $this->_objectManager->create('Mage_Catalog_Model_Product', $arguments);
    }
}
class Mage_Review_Model_Observer
{
   public function processDeletedProduct (Varien_Event_Observer $observer)
   {
     $productId = $observer->getEvent()->getProduct()->getId();

        if ($productId) {
           Mage::getResourceSingleton('Mage_Review_Model_Resource_Review')
              ->deleteReviewsByProductId($productId);
        }
    }
}
class Mage_Review_Model_Observer
{
   public function __construct(Mage_Review_Model_Resource_Review $review)
   {
     $this->_reviewResource = $reviewResource;
   }

    //...
}
<di>
  <Mage_Review_Model_Observer>
     <parameters>
       <review>
          Mage_Review_Model_Resource_Review_Proxy
       </review>
     </parameters>
  </ Mage_Review_Model_Observer >
</di>
class Mage_Review_Model_Resource_Review_Proxy
   extends Mage_Review_Model_Resource_Review
{
   public function __construct(Magento_ObjectManager $objectManager)
   {
     $this->_objectManager = $objectManager;
   }

    public function deleteReviewByProductId($productId)
    {
      return $this->_objectManager
        ->get('Mage_Review_Model_Resource_Review ')
        ->deleteReviewByProductId();
    }
}

Mais conteúdo relacionado

Mais procurados

Building complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and ReactBuilding complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and ReactJonne Kats
 
WooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWordCamp Indonesia
 
AngularJS Services
AngularJS ServicesAngularJS Services
AngularJS ServicesEyal Vardi
 
Aug 3-2012 - StiltSoft - 10 features for JIRA admin
Aug 3-2012 - StiltSoft - 10 features for JIRA adminAug 3-2012 - StiltSoft - 10 features for JIRA admin
Aug 3-2012 - StiltSoft - 10 features for JIRA adminTeamlead
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS RoutingEyal Vardi
 
WordPress plugin #3
WordPress plugin #3WordPress plugin #3
WordPress plugin #3giwoolee
 
Special Events: Beyond Custom Events
Special Events: Beyond Custom EventsSpecial Events: Beyond Custom Events
Special Events: Beyond Custom EventsBrandon Aaron
 
jQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a TreejQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a Treeadamlogic
 
WordPress Capabilities Magic
WordPress Capabilities MagicWordPress Capabilities Magic
WordPress Capabilities Magicmannieschumpert
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS OverviewEyal Vardi
 
Optimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page AppsOptimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page AppsMorgan Stone
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesEyal Vardi
 
Magento2&amp;java script (2)
Magento2&amp;java script (2)Magento2&amp;java script (2)
Magento2&amp;java script (2)EvgeniyKapelko1
 
Php update and delet operation
Php update and delet operationPhp update and delet operation
Php update and delet operationsyeda zoya mehdi
 

Mais procurados (20)

Building complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and ReactBuilding complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and React
 
WooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda Bagus
 
AngularJS Services
AngularJS ServicesAngularJS Services
AngularJS Services
 
Aug 3-2012 - StiltSoft - 10 features for JIRA admin
Aug 3-2012 - StiltSoft - 10 features for JIRA adminAug 3-2012 - StiltSoft - 10 features for JIRA admin
Aug 3-2012 - StiltSoft - 10 features for JIRA admin
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
 
WordPress plugin #3
WordPress plugin #3WordPress plugin #3
WordPress plugin #3
 
Mysocial databasequeries
Mysocial databasequeriesMysocial databasequeries
Mysocial databasequeries
 
Mysocial databasequeries
Mysocial databasequeriesMysocial databasequeries
Mysocial databasequeries
 
Special Events: Beyond Custom Events
Special Events: Beyond Custom EventsSpecial Events: Beyond Custom Events
Special Events: Beyond Custom Events
 
Special Events
Special EventsSpecial Events
Special Events
 
jQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a TreejQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a Tree
 
WordPress Capabilities Magic
WordPress Capabilities MagicWordPress Capabilities Magic
WordPress Capabilities Magic
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
 
Optimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page AppsOptimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page Apps
 
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
 
Borrados
BorradosBorrados
Borrados
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource Services
 
Magento2&amp;java script (2)
Magento2&amp;java script (2)Magento2&amp;java script (2)
Magento2&amp;java script (2)
 
Php update and delet operation
Php update and delet operationPhp update and delet operation
Php update and delet operation
 

Semelhante a Magento Dependency Injection

Magento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request FlowMagento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request FlowVrann Tulika
 
Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic ComponentsMateusz Tymek
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperGary Hockin
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ EtsyNishan Subedi
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf Conference
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsSam Hennessy
 
(PHPers Wrocław #5) How to write valuable unit test?
(PHPers Wrocław #5) How to write valuable unit test?(PHPers Wrocław #5) How to write valuable unit test?
(PHPers Wrocław #5) How to write valuable unit test?RST Software Masters
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Leonardo Proietti
 
Key Insights into Development Design Patterns for Magento 2 - Magento Live UK
Key Insights into Development Design Patterns for Magento 2 - Magento Live UKKey Insights into Development Design Patterns for Magento 2 - Magento Live UK
Key Insights into Development Design Patterns for Magento 2 - Magento Live UKMax Pronko
 
Magento Performance Toolkit
Magento Performance ToolkitMagento Performance Toolkit
Magento Performance ToolkitSergii Shymko
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web servicesMichelangelo van Dam
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologyDaniel Knell
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
Utilization of zend an ultimate alternate for intense data processing
Utilization of zend  an ultimate alternate for intense data processingUtilization of zend  an ultimate alternate for intense data processing
Utilization of zend an ultimate alternate for intense data processingCareer at Elsner
 
Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Pavel Novitsky
 

Semelhante a Magento Dependency Injection (20)

Magento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request FlowMagento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request Flow
 
Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic Components
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 Developer
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Growing up with Magento
Growing up with MagentoGrowing up with Magento
Growing up with Magento
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
(PHPers Wrocław #5) How to write valuable unit test?
(PHPers Wrocław #5) How to write valuable unit test?(PHPers Wrocław #5) How to write valuable unit test?
(PHPers Wrocław #5) How to write valuable unit test?
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
Min-Maxing Software Costs
Min-Maxing Software CostsMin-Maxing Software Costs
Min-Maxing Software Costs
 
Lithium Best
Lithium Best Lithium Best
Lithium Best
 
Key Insights into Development Design Patterns for Magento 2 - Magento Live UK
Key Insights into Development Design Patterns for Magento 2 - Magento Live UKKey Insights into Development Design Patterns for Magento 2 - Magento Live UK
Key Insights into Development Design Patterns for Magento 2 - Magento Live UK
 
Magento Performance Toolkit
Magento Performance ToolkitMagento Performance Toolkit
Magento Performance Toolkit
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web services
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Utilization of zend an ultimate alternate for intense data processing
Utilization of zend  an ultimate alternate for intense data processingUtilization of zend  an ultimate alternate for intense data processing
Utilization of zend an ultimate alternate for intense data processing
 
Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)
 

Último

ab-initio-training basics and architecture
ab-initio-training basics and architectureab-initio-training basics and architecture
ab-initio-training basics and architecturesaipriyacoool
 
👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...
👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...
👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...karishmasinghjnh
 
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...kumaririma588
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Peaches App development presentation deck
Peaches App development presentation deckPeaches App development presentation deck
Peaches App development presentation decktbatkhuu1
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Call Girls Jalgaon Just Call 8617370543Top Class Call Girl Service Available
Call Girls Jalgaon Just Call 8617370543Top Class Call Girl Service AvailableCall Girls Jalgaon Just Call 8617370543Top Class Call Girl Service Available
Call Girls Jalgaon Just Call 8617370543Top Class Call Girl Service AvailableNitya salvi
 
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...nirzagarg
 
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRL
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRLHingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRL
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRLNitya salvi
 
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...SUHANI PANDEY
 
Top Rated Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Call Girls in Nagpur High Profile
 
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...amitlee9823
 
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...gajnagarg
 
Q4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentationQ4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentationZenSeloveres
 
➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men 🔝jhansi🔝 Escorts S...
➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men  🔝jhansi🔝   Escorts S...➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men  🔝jhansi🔝   Escorts S...
➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men 🔝jhansi🔝 Escorts S...amitlee9823
 
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...amitlee9823
 
Sector 105, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 105, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 105, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 105, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)amitlee9823
 
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.Nitya salvi
 

Último (20)

ab-initio-training basics and architecture
ab-initio-training basics and architectureab-initio-training basics and architecture
ab-initio-training basics and architecture
 
👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...
👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...
👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...
 
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Peaches App development presentation deck
Peaches App development presentation deckPeaches App development presentation deck
Peaches App development presentation deck
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Call Girls Jalgaon Just Call 8617370543Top Class Call Girl Service Available
Call Girls Jalgaon Just Call 8617370543Top Class Call Girl Service AvailableCall Girls Jalgaon Just Call 8617370543Top Class Call Girl Service Available
Call Girls Jalgaon Just Call 8617370543Top Class Call Girl Service Available
 
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
 
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRL
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRLHingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRL
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRL
 
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
 
Top Rated Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
 
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
 
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
 
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman MuscatAbortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
 
Q4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentationQ4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentation
 
➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men 🔝jhansi🔝 Escorts S...
➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men  🔝jhansi🔝   Escorts S...➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men  🔝jhansi🔝   Escorts S...
➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men 🔝jhansi🔝 Escorts S...
 
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
 
Sector 105, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 105, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 105, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 105, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.
 

Magento Dependency Injection

  • 1. Киев 15 сентября 2012 Magento DI
  • 2. Software Entropy Pull-approach and its problems Push-approach Magento Object Manager
  • 7. class Mage_Cms_Model_Page { public function __construct() { $this->_idFieldName = Mage::getResourceSingleton($this->_resourceName); } public function getAvailableStatuses() { $statuses = new Varien_Object(array( self::STATUS_ENABLED => Mage::helper('Mage_Cms_Helper_Data')->__('Enabled') self::STATUS_DISABLED => Mage::helper('Mage_Cms_Helper_Data') ->__(„Disabled') )); Mage::dispatchEvent('cms_page_get_available_statuses', array('statuses' => $statuses)); } }
  • 8. class Mage_Cms_Model_PageTest extends PHPUnit_Framework_TestCase { public function setUp() { $this->_page = new Mage_Cms_Model_Page(); } }
  • 9. class Mage_Cms_Model_PageTest extends PHPUnit_Framework_TestCase { public function setUp() { Mage::setResourceSingleton(„Page_Resource‟, $this->getMock(„Page_Resource‟)); $this->_page = new Mage_Cms_Model_Page(); } public function testProcessDoesSomething() { Mage::setHelper(„Mage_Cms_Helper_Data‟, $this->getMock(„Mage_Cms_Helper_Data‟)); $this->assertSomething($this->_page->process()); } }
  • 12. class Mage_Core_Model_Abstract { public function __construct(array $data = array()) { parent::__construct($data); $this->_construct(); } }
  • 13. class Mage_Core_Model_Abstract { public function __construct( Mage_Core_Model_Event_Manager $eventDispatcher, Mage_Core_Model_Cache $cacheManager, Mage_Core_Model_Resource_Abstract $resource = null, Varien_Data_Collection_Db $resourceCollection = null, array $data = array() ){ $this->_eventDispatcher = $eventDispatcher; $this->_cacheManager = $cacheManager; $this->_resource = $resource; $this->_resourceCollection = $resourceCollection; parent::__construct($data); $this->__construct(); } }
  • 16. interface Magento_ObjectManager { public function get($className, $arguments); public function create($className, $arguments); }
  • 17.
  • 19. class Mage_Core_Model_Abstract { public function __construct( Mage_Core_Model_Event_Manager $eventDispatcher, Mage_Core_Model_Cache $cacheManager, Mage_Core_Model_Resource_Abstract $resource = null, Varien_Data_Collection_Db $resourceCollection = null, array $data = array() ){ $this->_eventDispatcher = $eventDispatcher; $this->_cacheManager = $cacheManager; $this->_resource = $resource; $this->_resourceCollection = $resourceCollection; parent::__construct($data); $this->__construct(); } }
  • 20. <config> <global> <di> <Mage_Core_Model_Cache> <parameters> <cacheDir>/path/to/cache/dir</cacheDir> </parameters> </Mage_Core_Model_Cache> </di> </global> </config>
  • 21. <di> <Magento_Data_Structure> <shared>0</shared> </Magento_Data_Structure> </di>
  • 23. <adminhtml> <di> <preferences> <Some_Interface>Some_Backend_Implementation</Some_Interface> </preferences> </di> </adminhtml> <api> <di> <preferences> <Some_Interface>Some_Api_Implementation</Some_Interface> </preferences> </di> </api>
  • 24. INJECTABLES - NON-INJECTABLES Varien_Db_Adapter Mage_Catalog_Model_Product Mage_Core_Model_Cache Mage_Wishlist_Model_Wishlist Mage_Core_Model_Config
  • 25. class Varien_Data_Collection { //... public function getNewEmptyItem() { return Mage::getModel($this->_itemObjectClass); } //... }
  • 26. class Varien_Data_Collection { public function __construct(Magento_ObjectFactory $factory) { $this->_itemFactory = $factory; } //... public function getNewEmptyItem() { return $this->_itemFactory->create(); } //... }
  • 27. class Mage_Catalog_Model_Product_Factory implements Magento_ObjectManager_Factory { protected $_objectManager; public function __construct(Magento_ObjectManager $objectManager) { $this->_objectManager = $objectManager; } public function createFromArray(array $arguments = array()) { return $this->_objectManager->create('Mage_Catalog_Model_Product', $arguments); } }
  • 28. class Mage_Review_Model_Observer { public function processDeletedProduct (Varien_Event_Observer $observer) { $productId = $observer->getEvent()->getProduct()->getId(); if ($productId) { Mage::getResourceSingleton('Mage_Review_Model_Resource_Review') ->deleteReviewsByProductId($productId); } } }
  • 29. class Mage_Review_Model_Observer { public function __construct(Mage_Review_Model_Resource_Review $review) { $this->_reviewResource = $reviewResource; } //... }
  • 30. <di> <Mage_Review_Model_Observer> <parameters> <review> Mage_Review_Model_Resource_Review_Proxy </review> </parameters> </ Mage_Review_Model_Observer > </di>
  • 31. class Mage_Review_Model_Resource_Review_Proxy extends Mage_Review_Model_Resource_Review { public function __construct(Magento_ObjectManager $objectManager) { $this->_objectManager = $objectManager; } public function deleteReviewByProductId($productId) { return $this->_objectManager ->get('Mage_Review_Model_Resource_Review ') ->deleteReviewByProductId(); } }