PHP code example of inviqa / magento-symfony-container

1. Go to this page and download the library: Download inviqa/magento-symfony-container library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

inviqa / magento-symfony-container example snippets


namespace Inviqa\Acme;

use Inviqa\Acme\Catalog;
use Inviqa\Mailer;

class Checkout
{
    private $catalog;
    
    private $mailer;

    public function __construct(Catalog $catalog, Mailer $mailer)
    {
        $this->catalog = $catalog;
        $this->mailer = $mailer;
    }
    
    public function process()
    {
        // checkout processing rules
    }
}

namespace Inviqa\Acme

interface Catalog
{
    public function process(Products $products = null);
    public function start();
}

class Inviqa_Acme_IndexController
{
    use Inviqa_SymfonyContainer_Helper_ServiceProvider;

    public function indexAction()
    {
        $this->getService('acme.checkout')->process();
        
        $this->loadLayout();
        $this->renderLayout();
    }
}

$container = Mage::helper('inviqa_symfonyContainer/containerProvider')->getContainer();

class Acme_Service
{
    public function __construct(SomeSerivce $someService, $amazonPaymentsTitle, $secureBaseUrl)
    {
        $this->_secureBaseUrl = $secureBaseUrl; // will have value of e.g: https://my-magento.dev/  
    }
}

    /**
     * @var Mage_Catalog_Model_Product
     */
    private $catalog;

    /**
     * @var Mage_Sales_Model_Order
     */
    private $order;

    /**
     * @param Mage_Catalog_Model_Product $catalog
     * @param Mage_Sales_Model_Order $order
     */
    public function __dependencies(
        Mage_Catalog_Model_Product $catalog,
        Mage_Sales_Model_Order $order
    ) {
        $this->catalog = $catalog;
        $this->order = $order;
    }

    function __construct()
    {
        Mage::getSingleton('inviqa_symfonyContainer/serviceInjector')->setupDepdendencies($this);
        parent::__construct();
    }

class Inviqa_DependencyInjection_Model_Observer
{
    /** @var CustomCompilerPass */
    private $customCompilerPass;

    public function __construct()
    {
        $this->customCompilerPass = new CustomCompilerPass();
    }

    public function onBeforeContainerGenerator(Varien_Event_Observer $observer)
    {
        /** @var Configuration $generatorConfig */
        $generatorConfig = $observer->getData('generator_config');

        $generatorConfig->addCompilerPass($this->customCompilerPass);
    }
}