/**
  * Listener wykonywany przy dodawaniu nowego zasobu
  *
  * @param HtmlDocument $doc
  * @param string $type
  * @param string $name
  *
  * @throws \UnexpectedValueException
  */
 public function createResOnAdd(HtmlDocument $doc, $type, $name)
 {
     $allowed = array('javascript', 'stylesheet');
     if (!in_array($type, $allowed)) {
         throw new \UnexpectedValueException($type . 'is unexpected');
     }
     $options = $this->options;
     $closure = function (CombineResourceAbstract $res) use($type, $options) {
         switch ($type) {
             case 'javascript':
                 $combine = new JavaScriptCombineFiles();
                 break;
             case 'stylesheet':
                 $combine = new StyleSheetCombineFiles();
                 break;
         }
         if (!empty($options['cache_db_dir'])) {
             $cacheDb = $options['cache_db_dir'] . '.db';
         } else {
             $cacheDb = $options['web_cache_dir'] . '.db';
         }
         $combine->setInputDir($options['web_dir'])->setOutputDir($options['web_cache_dir'])->setOutputBaseUrl($options['web_cache_url'])->setOutputForceRefresh($options['cache_refresh'])->setOutputLifeTime($options['cache_lifetime'])->setOutputStrategy('manual')->setCacheDb(CombineFilesCacheDB::openFile($cacheDb));
         if ($type == 'stylesheet') {
             $combine->setLessImportDirs($options['less_import_dirs']);
             $combine->setLessVariables($options['less_variables']);
             $combine->setScssImportDirs($options['scss_import_dirs']);
             $combine->setScssVariables($options['scss_variables']);
         }
         $res->setCombineObject($combine);
         $urlManager = new UrlManager();
         $urlManager->setBaseUrl($options['web_url']);
         $urlManager->setVersioning($options['versioning_enable'], $options['versioning_version'], $options['versioning_timestamp']);
         if ($options['cdn_enable']) {
             if ($type == 'javascript') {
                 $urlManager->setDomainPath($options['cdn_javascript']);
             } elseif ($type == 'stylesheet') {
                 $urlManager->setDomainPath($options['cdn_css']);
             }
         }
         $res->setUrlManager($urlManager);
     };
     $manager = $doc->resources($type);
     switch ($type) {
         case 'javascript':
             $manager->setOnAdd($name, function (JavaScriptResource $res) use($closure) {
                 $closure($res);
             });
             break;
         case 'stylesheet':
             $manager->setOnAdd($name, function (StyleSheetResource $res) use($closure) {
                 $closure($res);
             });
             break;
     }
 }