<?php
//ini_set('max_execution_time',300);
ini_set('error_reporting',1);ini_set('display_errors', 1);

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use OfficeBrain\CustomBundle\ThemeBundle\AppKernel\AppCustomKernel;

class AppKernel extends Kernel {
    
    protected $objAppCustomKernel;
    /*
    public function __construct()
    {
      parent::__construct();
      
    }
    */
    public function registerBundles() {
        $bundles = array(
            /** Start of Symfony Core Bundles **/
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(),
            //new Tedivm\StashBundle\TedivmStashBundle(),
            new Liuggio\ExcelBundle\LiuggioExcelBundle(),
            new Snc\RedisBundle\SncRedisBundle(),
            new Pv\RecaptchaBundle\PvRecaptchaBundle(),
            /** End of Symfony Core Bundles **/
            
            /** Start of Project Bundles **/
            new OfficeBrain\Bundle\CoreBundle\OfficeBrainCoreBundle(),
            new OfficeBrain\Bundle\PageBundle\OfficeBrainPageBundle(),
            new OfficeBrain\Bundle\ThemeBundle\OfficeBrainThemeBundle(),
            new OfficeBrain\Bundle\QueueBundle\OfficeBrainQueueBundle(),
            new OfficeBrain\Bundle\CacheBundle\OfficeBrainCacheBundle(),
            new OfficeBrain\Bundle\ProductBundle\OfficeBrainProductBundle(),
            new OfficeBrain\Bundle\SearchBundle\OfficeBrainSearchBundle(),
            new OfficeBrain\Bundle\SolrBundle\OfficeBrainSolrBundle(),
            new OfficeBrain\Bundle\MarginBundle\OfficeBrainMarginBundle(),
            new OfficeBrain\Bundle\AccessManagementBundle\OfficeBrainAccessManagementBundle(),
            new OfficeBrain\Bundle\UserBundle\OfficeBrainUserBundle(),
            new OfficeBrain\Bundle\ServiceGroupBundle\OfficeBrainServiceGroupBundle(),
            new OfficeBrain\Bundle\CompareProductBundle\OfficeBrainCompareProductBundle(),
            new OfficeBrain\Bundle\WishListBundle\OfficeBrainWishListBundle(),
            new OfficeBrain\Bundle\QuoteBundle\OfficeBrainQuoteBundle(),
            new OfficeBrain\Bundle\OrderBundle\OfficeBrainOrderBundle(),
            new OfficeBrain\Bundle\RequestInfoBundle\OfficeBrainRequestInfoBundle(),
            new OfficeBrain\Bundle\ShippingBundle\OfficeBrainShippingBundle(),
            new OfficeBrain\Bundle\ShoppingCartBundle\OfficeBrainShoppingCartBundle(),
            new OfficeBrain\Bundle\CompanyBundle\OfficeBrainCompanyBundle(),
            new OfficeBrain\Bundle\FeedBackBundle\OfficeBrainFeedBackBundle(),
            new OfficeBrain\Bundle\CategoryBundle\OfficeBrainCategoryBundle(),
            new OfficeBrain\Bundle\SubShopBundle\OfficeBrainSubShopBundle(),
            new OfficeBrain\Bundle\EmailBundle\OfficeBrainEmailBundle(),
            new OfficeBrain\Bundle\ActivityBundle\OfficeBrainActivityBundle(),
            new OfficeBrain\Bundle\BannerBundle\OfficeBrainBannerBundle(),
            new OfficeBrain\Bundle\FlyerBundle\OfficeBrainFlyerBundle(),
            new OfficeBrain\Bundle\ProductTagBundle\OfficeBrainProductTagBundle(),
            new OfficeBrain\Bundle\CouponBundle\OfficeBrainCouponBundle(),
            new OfficeBrain\Bundle\QuickQuoteBundle\OfficeBrainQuickQuoteBundle(),
            new OfficeBrain\Bundle\ImageBundle\OfficeBrainImageBundle(),
            new Payum\Bundle\PayumBundle\PayumBundle(),
            //new OfficeBrain\Bundle\SitemapBundle\OfficeBrainSitemapBundle(),
            new OfficeBrain\Bundle\CmsBundle\OfficeBrainCmsBundle(),
            new OfficeBrain\Bundle\ObSolrOperationBundle\OfficeBrainObSolrOperationBundle(),
            /** Start of Project Bundles **/
            
            new OfficeBrain\Bundle\RequestQuoteBundle\OfficeBrainRequestQuoteBundle(),
            new OfficeBrain\Bundle\ShippingEstimatorBundle\OfficeBrainShippingEstimatorBundle(),
            new OfficeBrain\Bundle\AttributeBundle\OfficeBrainAttributeBundle(),
            new Avalanche\Bundle\ImagineBundle\AvalancheImagineBundle(),
            new OfficeBrain\Bundle\GiftCertificateBundle\OfficeBrainGiftCertificateBundle(),
            new OfficeBrain\Bundle\RewardReferralBundle\OfficeBrainRewardReferralBundle(),
            new OfficeBrain\Bundle\ReportBundle\OfficeBrainReportBundle(),
            //         	new Webfactory\Bundle\PiwikBundle\WebfactoryPiwikBundle(),
            new OfficeBrain\Bundle\EcatalogueBundle\OfficeBrainEcatalogueBundle(),
            new OfficeBrain\Bundle\PaymentBundle\OfficeBrainPaymentBundle(),
            new OfficeBrain\Bundle\PrioritizeSupplierBundle\OfficeBrainPrioritizeSupplierBundle(),
            new FOS\OAuthServerBundle\FOSOAuthServerBundle(),
            new OfficeBrain\Bundle\OauthBundle\OfficeBrainOauthBundle(),
            new OfficeBrain\Bundle\BlogBundle\OfficeBrainBlogBundle(),
            new OfficeBrain\Bundle\TaxBundle\OfficeBrainTaxBundle(),
            new OfficeBrain\Bundle\SeoBundle\OfficeBrainSeoBundle(),
            new OfficeBrain\Bundle\SocialMediaBundle\OfficeBrainSocialMediaBundle(),
            new OfficeBrain\CustomBundle\MigrationBundle\OfficeBrainCustomBundleMigrationBundle(),
            new OfficeBrain\Bundle\SupplierComplianceBundle\OfficeBrainSupplierComplianceBundle(),
            new OfficeBrain\Bundle\HomeSectionBundle\OfficeBrainHomeSectionBundle(),
            new OfficeBrain\Bundle\FlipBookBundle\OfficeBrainFlipBookBundle(),
            new OfficeBrain\Bundle\SettingBundle\OfficeBrainSettingBundle(),
        );
        
        //$this->objAppCustomKernel = new AppCustomKernel();
        $arrCustomBundle=AppCustomKernel::registerCustomBundles();
        
        $bundles = array_merge($bundles, $this->loadExternalVendorBundle(),$arrCustomBundle);
        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        if (!defined('__ENV__'))
            define('__ENV__', $this->getEnvironment());

        if (!defined('__PHP_VERSION__')){
        	$php_version = explode(".",phpversion());
        	$php_version = $php_version[0].$php_version[1];
        	define('__PHP_VERSION__', $php_version);// for uploading  file in curl  (product import)
        }

        return $bundles;
    }

    /**
     * below method is used to manage and load external Bundles only.
     * we will only write here the extenrnal vendor bundle which we require only.
     */
    public function loadExternalVendorBundle() {
        return array(new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
          new JMS\SerializerBundle\JMSSerializerBundle(),
          new Nelmio\SolariumBundle\NelmioSolariumBundle(),
          new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
          new FOS\JsRoutingBundle\FOSJsRoutingBundle(), /*           * * Bundle to enable routing in javascript ** */
          new Bazinga\Bundle\JsTranslationBundle\BazingaJsTranslationBundle(), /*           * * Bundle to enable translation in javascript ** */
          new Stfalcon\Bundle\TinymceBundle\StfalconTinymceBundle(),
		  new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
          new Gregwar\CaptchaBundle\GregwarCaptchaBundle(),
          new FOS\RestBundle\FOSRestBundle(),
        );
    }

    public function registerContainerConfiguration(LoaderInterface $loader) {
        $loader->load($this->getRootDir() . '/config/config.yml');
    }

    protected function initializeContainer() {
        parent::initializeContainer();
        // if (PHP_SAPI == 'cli') {
            $this->getContainer()->enterScope('request');
            $request_object = new \Symfony\Component\HttpFoundation\Request();
            $this->getContainer()->set('request', $request_object, 'request');
            $this->getContainer()->get('office_brain_access_management.access_configuration')->PrepareAccessAndConfigurationRulesForCli($this->getContainer()->get('request'));
        // }
    }
}
