/**
  * @param string $sAssetFileType
  * @return array
  * @throws \InvalidArgumentException
  * @throws \DomainException
  */
 public function getCachedAssetsFiles($sAssetFileType)
 {
     if (!\AssetsBundle\AssetFile\AssetFile::assetFileTypeExists($sAssetFileType)) {
         throw new \InvalidArgumentException('Asset file type "' . $sAssetFileType . '" is not valid');
     }
     //Production
     if ($this->getOptions()->isProduction()) {
         $oAssetFilesCacheManager = $this->getAssetFilesCacheManager();
         //Production cached asset files do not exist
         if (!$oAssetFilesCacheManager->hasProductionCachedAssetFiles($sAssetFileType)) {
             switch ($sAssetFileType) {
                 case \AssetsBundle\AssetFile\AssetFile::ASSET_JS:
                     $this->cacheJsAssetFiles();
                     break;
                 case \AssetsBundle\AssetFile\AssetFile::ASSET_CSS:
                     $this->cacheCssAssetFiles();
                     break;
                 default:
                     throw new \DomainException('Only "' . \AssetsBundle\AssetFile\AssetFile::ASSET_JS . '" & "' . \AssetsBundle\AssetFile\AssetFile::ASSET_CSS . '" assets file type can be retrieved');
             }
         }
         return $oAssetFilesCacheManager->getProductionCachedAssetFiles($sAssetFileType);
     } else {
         switch ($sAssetFileType) {
             case \AssetsBundle\AssetFile\AssetFile::ASSET_JS:
                 return $this->cacheJsAssetFiles();
             case \AssetsBundle\AssetFile\AssetFile::ASSET_CSS:
                 return $this->cacheCssAssetFiles();
             default:
                 throw new \DomainException('Only "' . \AssetsBundle\AssetFile\AssetFile::ASSET_JS . '" & "' . \AssetsBundle\AssetFile\AssetFile::ASSET_CSS . '" assets file type can be retrieved');
         }
     }
 }
 /**
  * @see \Zend\ServiceManager\FactoryInterface::createService()
  * @param \Zend\ServiceManager\ServiceLocatorInterface $oServiceLocator
  * @throws \UnexpectedValueException
  * @return \AssetsBundle\Service\ServiceOptions
  */
 public function createService(\Zend\ServiceManager\ServiceLocatorInterface $oServiceLocator)
 {
     $aConfiguration = $oServiceLocator->get('Config');
     if (!isset($aConfiguration['assets_bundle'])) {
         throw new \UnexpectedValueException('AssetsBundle configuration is undefined');
     }
     $aOptions = $aConfiguration['assets_bundle'];
     if ($aOptions instanceof \Traversable) {
         $aOptions = \Zend\Stdlib\ArrayUtils::iteratorToArray($aOptions);
     } elseif (!is_array($aOptions)) {
         throw new \InvalidArgumentException('"assets_bundle" configuration expects an array or Traversable object; received "' . (is_object($aOptions) ? get_class($aOptions) : gettype($aOptions)) . '"');
     }
     //Define base URL of the application
     if (!isset($aOptions['baseUrl'])) {
         if (($oRequest = $oServiceLocator->get('request')) instanceof \Zend\Http\PhpEnvironment\Request) {
             $aOptions['baseUrl'] = $oRequest->getBaseUrl();
         } else {
             $oRequest = new \Zend\Http\PhpEnvironment\Request();
             $aOptions['baseUrl'] = $oRequest->getBaseUrl();
         }
     }
     //Retrieve filters
     if (isset($aOptions['view_helper_plugins'])) {
         $aViewHelperPlugins = $aOptions['view_helper_plugins'];
         if ($aViewHelperPlugins instanceof \Traversable) {
             $aViewHelperPlugins = \Zend\Stdlib\ArrayUtils::iteratorToArray($aOptions);
         } elseif (!is_array($aViewHelperPlugins)) {
             throw new \InvalidArgumentException('Assets bundle "filters" option expects an array or Traversable object; received "' . (is_object($aViewHelperPlugins) ? get_class($aViewHelperPlugins) : gettype($aViewHelperPlugins)) . '"');
         }
         $oViewHelperPluginManager = $oServiceLocator->get('ViewHelperManager');
         foreach ($aViewHelperPlugins as $sAssetFileType => $oViewHelperPlugin) {
             if (!\AssetsBundle\AssetFile\AssetFile::assetFileTypeExists($sAssetFileType)) {
                 throw new \LogicException('Asset file type "' . $sAssetFileType . '" is not valid');
             }
             if (is_string($oViewHelperPlugin)) {
                 if ($oViewHelperPluginManager->has($oViewHelperPlugin)) {
                     $oViewHelperPlugin = $oViewHelperPluginManager->get($oViewHelperPlugin);
                 } elseif (class_exists($oViewHelperPlugin)) {
                     $oViewHelperPlugin = new $oViewHelperPlugin();
                 } else {
                     throw new \LogicException('View helper plugin "' . $oViewHelperPlugin . '" is not a registered service or an existing class');
                 }
                 if ($oViewHelperPlugin instanceof \Zend\View\Helper\HelperInterface) {
                     $aViewHelperPlugins[$sAssetFileType] = $oViewHelperPlugin;
                 } else {
                     throw new \LogicException('View helper plugin expects an instance of "\\Zend\\View\\Helper\\HelperInterface", "' . get_class($oViewHelperPlugin) . '" given');
                 }
             }
         }
         $aOptions['view_helper_plugins'] = $aViewHelperPlugins;
     }
     //Unset filters
     unset($aOptions['filters']);
     return new \AssetsBundle\Service\ServiceOptions($aOptions);
 }
 /**
  * @param string $sAssetFileType
  * @return array
  * @throws \InvalidArgumentException
  * @throws \LogicException
  */
 public function getProductionCachedAssetFiles($sAssetFileType)
 {
     if (!\AssetsBundle\AssetFile\AssetFile::assetFileTypeExists($sAssetFileType)) {
         throw new \InvalidArgumentException('Asset file type "' . $sAssetFileType . '" is not valid');
     }
     if (in_array($sAssetFileType, array(\AssetsBundle\AssetFile\AssetFile::ASSET_CSS, \AssetsBundle\AssetFile\AssetFile::ASSET_JS))) {
         $sCacheFileName = $this->getOptions()->getCacheFileName();
         $sCacheFileExtension = \AssetsBundle\AssetFile\AssetFile::getAssetFileDefaultExtension($sAssetFileType);
         if (file_exists($sCachedAssetFile = $this->getOptions()->getCachePath() . DIRECTORY_SEPARATOR . $sCacheFileName . '.' . $sCacheFileExtension)) {
             $aAssetFiles = array();
             foreach (glob($this->getOptions()->getCachePath() . DIRECTORY_SEPARATOR . $sCacheFileName . '*.' . $sCacheFileExtension) as $sAssetFilePath) {
                 $aAssetFiles[] = new \AssetsBundle\AssetFile\AssetFile(array('asset_file_path' => $sAssetFilePath, 'asset_file_type' => $sAssetFileType));
             }
             return $aAssetFiles;
         }
         throw new \LogicException('Production cached asset files do not exist for asset file type "' . $sAssetFileType . '"');
     }
     throw new \InvalidArgumentException(__METHOD__ . 'allows "' . \AssetsBundle\AssetFile\AssetFile::ASSET_CSS . '" & "' . \AssetsBundle\AssetFile\AssetFile::ASSET_JS . '" asset file type, "' . $sAssetFileType . '" given');
 }
 /**
  * @param string $sAssetFileType
  * @return \AssetsBundle\AssetFile\AssetFile
  * @throws \InvalidArgumentException
  */
 protected function createTmpAssetFile($sAssetFileType)
 {
     if (!\AssetsBundle\AssetFile\AssetFile::assetFileTypeExists($sAssetFileType)) {
         throw new \InvalidArgumentException('Asset file type "' . $sAssetFileType . '" is not valid');
     }
     // Create tmp asset file
     \Zend\Stdlib\ErrorHandler::start();
     $sTmpAssetFilePath = tempnam($this->getOptions()->getTmpDirPath(), $sAssetFileType . '_' . uniqid());
     \Zend\Stdlib\ErrorHandler::stop(true);
     $this->tmpAssetFilesPathes[] = $sTmpAssetFilePath;
     return new \AssetsBundle\AssetFile\AssetFile(array('asset_file_type' => $sAssetFileType, 'asset_file_path' => $sTmpAssetFilePath));
 }
 /**
  * @param string $sAssetFileType
  * @return \Zend\View\Helper\HelperInterface
  * @throws \LogicException
  * @throws \InvalidArgumentException
  */
 public function getViewHelperPluginForAssetFileType($sAssetFileType)
 {
     if (\AssetsBundle\AssetFile\AssetFile::assetFileTypeExists($sAssetFileType)) {
         if (!is_array($this->view_helper_plugins)) {
             throw new \LogicException('View helper plugins are undefined');
         }
         if (isset($this->view_helper_plugins[$sAssetFileType]) && $this->view_helper_plugins[$sAssetFileType] instanceof \Zend\View\Helper\HelperInterface) {
             return $this->view_helper_plugins[$sAssetFileType];
         }
         throw new \InvalidArgumentException('View helper plugin for asset file type "' . $sAssetFileType . '" is undefined');
     }
 }
 /**
  * Check if assets configuration is the same as last saved configuration
  *
  * @param  array $aAssetsType
  * @return boolean
  * @throws \RuntimeException
  * @throws \LogicException
  */
 public function assetsConfigurationHasChanged(array $aAssetsType = null)
 {
     $aAssetsType = $aAssetsType ? array_unique($aAssetsType) : array(\AssetsBundle\AssetFile\AssetFile::ASSET_CSS, \AssetsBundle\AssetFile\AssetFile::ASSET_LESS, \AssetsBundle\AssetFile\AssetFile::ASSET_JS, \AssetsBundle\AssetFile\AssetFile::ASSET_MEDIA);
     //Retrieve saved onfiguration file
     if (file_exists($sConfigFilePath = $this->getConfigurationFilePath())) {
         \Zend\Stdlib\ErrorHandler::start();
         $aConfig = (include $sConfigFilePath);
         \Zend\Stdlib\ErrorHandler::stop(true);
         if ($aConfig === false || !is_array($aConfig)) {
             throw new \RuntimeException('Unable to get file content from file "' . $sConfigFilePath . '"');
         }
         //Get assets configuration
         $aAssets = $this->getOptions()->getAssets();
         //Check if configuration has changed for each type of asset
         foreach ($aAssetsType as $sAssetType) {
             if (!\AssetsBundle\AssetFile\AssetFile::assetFileTypeExists($sAssetType)) {
                 throw new \LogicException('Asset type "' . $sAssetType . '" does not exist');
             }
             if (empty($aAssets[$sAssetType]) && !empty($aConfig[$sAssetType])) {
                 return true;
             } elseif (!empty($aAssets[$sAssetType])) {
                 if (empty($aConfig[$sAssetType])) {
                     return true;
                 } elseif (array_diff($aAssets[$sAssetType], $aConfig[$sAssetType]) || array_diff($aConfig[$sAssetType], $aAssets[$sAssetType])) {
                     return true;
                 }
             }
         }
         return false;
     }
     return true;
 }