Pack an item.
@param array $assetEncoders the list of encoders to use in packing (configure the item packer)
@param boolean $nestedResourcesInclusion
@return ItemPack of the item. It can be serialized directly.
@throws common_Exception
428518
public function pack($assetEncoders = array(), $nestedResourcesInclusion = true)
    {

        try {
            //call the factory to get the itemPacker implementation
            $itemPacker = $this->getItemPacker();

            $itemPacker->setAssetEncoders($assetEncoders);
            $itemPacker->setNestedResourcesInclusion($nestedResourcesInclusion);

            //then create the pack
            $itemPack = $itemPacker->packItem($this->item, $this->lang, $this->getStorageDirectory());

        } catch (Exception $e) {
            throw new common_Exception('The item ' . $this->item->getUri() . ' cannot be packed : ' . $e->getMessage());
        }

        return $itemPack;
    }
565580
public function registerDefaultEncoders(EncoderRegistry $encoders): EncoderRegistry
    {
        $encoders->registerDefaultObjectEncoder(new ObjectEncoder($encoders, $this->propertyNameFormatter));
        $encoders->registerDefaultScalarEncoder(new ScalarEncoder());
        $encoders->registerEncoder('array', new ArrayEncoder($encoders));
        $dateTimeEncoder = new DateTimeEncoder($this->dateTimeFormat);
        $encoders->registerEncoder(DateTime::class, $dateTimeEncoder);
        $encoders->registerEncoder(DateTimeImmutable::class, $dateTimeEncoder);
        $encoders->registerEncoder(DateTimeInterface::class, $dateTimeEncoder);

        return $encoders;
    }
929252
protected static function getUrlFileDependencyName(AssetTypeInterface $assetType, array $composer, $dependency)
    {
        $prefix = isset($composer['name'])
            ? substr($composer['name'], \strlen($assetType->getComposerVendorName()) + 1).'-'
            : '';

        return $prefix.$dependency.'-file';
    }
102819
public function linkContentKeyToAsset($asset, $contentKey)
    {
        $assetId = Utilities::getEntityId(
            $asset,
            'WindowsAzure\MediaServices\Models\Asset'
        );
        $assetId = urlencode($assetId);

        $contentKeyId = Utilities::getEntityId(
            $contentKey,
            'WindowsAzure\MediaServices\Models\ContentKey'
        );

        $contentKeyId = urlencode($contentKeyId);

        $contentWriter = new \XMLWriter();
        $contentWriter->openMemory();
        $contentWriter->writeElementNS(
            'data',
            'uri',
            Resources::DS_XML_NAMESPACE,
            $this->getUri()."ContentKeys('{$contentKeyId}')"
        );

        $method = Resources::HTTP_POST;
        $path = "Assets('{$assetId}')/\$links/ContentKeys";
        $headers = [
            Resources::CONTENT_TYPE => Resources::XML_CONTENT_TYPE,
        ];
        $postParams = [];
        $queryParams = [];
        $statusCode = Resources::STATUS_NO_CONTENT;
        $body = $contentWriter->outputMemory();

        $this->sendHttp(
            $method,
            $headers,
            $queryParams,
            $postParams,
            $path,
            $statusCode,
            $body
        );
    }
589532
public static function applyAssetVariablesToCombinerFilters($filters)
    {
        $theme = CmsTheme::getActiveTheme();

        if (!$theme){
            return;
        }

        if (!$theme->hasCustomData()) {
            return;
        }

        $assetVars = $theme->getCustomData()->getAssetVariables();

        foreach ($filters as $filter) {
            if (method_exists($filter, 'setPresets')) {
                $filter->setPresets($assetVars);
            }
        }
    }
289780
private function loadPackageAssets($packageVariant, Package $package)
	{
		$variants = $package->getVariants();
		$requiredVariant = $variants[$packageVariant];

		if (isset($requiredVariant['scripts'])) {
			$scripts = [];
			foreach ($requiredVariant['scripts'] as $script) {
				$scripts[] = new Asset($package, $script);
			}
			$this->assetsLoader->addScripts($scripts);
		}

		if (isset($requiredVariant['styles'])) {
			$styles = [];
			foreach ($requiredVariant['styles'] as $style) {
				$styles[] = new Asset($package, $style);
			}
			$this->assetsLoader->addStyles($styles);
		}
	}
375772
public function writeToFile($filePath)
    {
        $out = @fopen($filePath,"w");

        if (!$out){
            throw new AssetException($this->token,
                "The asset '".$this->token."' could not be written to path '$filePath'. Check the path is valid and the directory exists.");
        }

        $stream = $this->getStream();

        if (!$stream){
            throw new AssetException($this->token,
                "The asset '".$this->token."' could not provide a valid stream.'");
        }

        while(!feof($stream)){
            $bytes = fread($stream, 8192);
            fwrite($out, $bytes);
        }

        fclose($stream);
        fclose($out);
    }
40342
private function configureWebpackAssets(ContainerBuilder $container, array $config): void
    {
        $assetsFile = $config['file'];
        $cacheId = $config['cache']['service_id'];
        $cacheKey = $config['cache']['key'];
        $cacheEnabled = $config['cache']['enabled'];
        $cacheEnabled = null !== $cacheEnabled
            ? $cacheEnabled
            : !$container->getParameter('kernel.debug');

        $container->setParameter('fxp_require_asset.webpack.adapter.assets.file', $assetsFile);
        $container->setParameter('fxp_require_asset.webpack.adapter.assets.cache_key', $cacheKey);

        if ($cacheEnabled) {
            $container->setAlias('fxp_require_asset.webpack.adapter.assets.cache', $cacheId);
        }
    }
1200803
public function setAssets($Assets)
    {
        if (! is_object($Assets) || ! $Assets instanceof Assets) {
            throw new \InvalidArgumentException(
                'The Assets Interface must be a valid Assets Object'
            );
        }
        $this->Assets = $Assets;

        return true;
    }
122263
public function load(array $configs, ContainerBuilder $container)
    {
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('assetic.xml');
        $loader->load('templating_twig.xml');
        $loader->load('templating_php.xml');

        $def = $container->getDefinition('assetic.parameter_bag');
        if (method_exists($def, 'setFactory')) {
            // to be inlined in assetic.xml when dependency on Symfony DependencyInjection is bumped to 2.6
            $def->setFactory(array(new Reference('service_container'), 'getParameterBag'));
        } else {
            // to be removed when dependency on Symfony DependencyInjection is bumped to 2.6
            $def->setFactoryService('service_container');
            $def->setFactoryMethod('getParameterBag');
        }

        $processor = new Processor();
        $configuration = $this->getConfiguration($configs, $container);
        $config = $processor->processConfiguration($configuration, $configs);

        $container->setParameter('assetic.debug', $config['debug']);
        $container->setParameter('assetic.use_controller', $config['use_controller']['enabled']);
        $container->setParameter('assetic.enable_profiler', $config['use_controller']['profiler']);
        $container->setParameter('assetic.read_from', $config['read_from']);
        $container->setParameter('assetic.write_to', $config['write_to']);
        $container->setParameter('assetic.variables', $config['variables']);

        $container->setParameter('assetic.java.bin', $config['java']);
        $container->setParameter('assetic.node.bin', $config['node']);
        $container->setParameter('assetic.node.paths', $config['node_paths']);
        $container->setParameter('assetic.ruby.bin', $config['ruby']);
        $container->setParameter('assetic.sass.bin', $config['sass']);
        $container->setParameter('assetic.reactjsx.bin', $config['reactjsx']);

        // register formulae
        $formulae = array();
        foreach ($config['assets'] as $name => $formula) {
            $formulae[$name] = array($formula['inputs'], $formula['filters'], $formula['options']);
        }

        if ($formulae) {
            $container->getDefinition('assetic.config_resource')->replaceArgument(0, $formulae);
        } else {
            $container->removeDefinition('assetic.config_loader');
            $container->removeDefinition('assetic.config_resource');
        }

        // register filters
        foreach ($config['filters'] as $name => $filter) {
            if (isset($filter['resource'])) {
                $loader->load($container->getParameterBag()->resolveValue($filter['resource']));
                unset($filter['resource']);
            } else {
                $loader->load('filters/'.$name.'.xml');
            }

            if (isset($filter['file'])) {
                $container->getDefinition('assetic.filter.'.$name)->setFile($filter['file']);
                unset($filter['file']);
            }

            if (isset($filter['apply_to'])) {
                if (!is_array($filter['apply_to'])) {
                    $filter['apply_to'] = array($filter['apply_to']);
                }

                foreach ($filter['apply_to'] as $i => $pattern) {
                    $worker = new DefinitionDecorator('assetic.worker.ensure_filter');
                    $worker->replaceArgument(0, '/'.$pattern.'/');
                    $worker->replaceArgument(1, new Reference('assetic.filter.'.$name));
                    $worker->addTag('assetic.factory_worker');

                    $container->setDefinition('assetic.filter.'.$name.'.worker'.$i, $worker);
                }

                unset($filter['apply_to']);
            }

            foreach ($filter as $key => $value) {
                $container->setParameter('assetic.filter.'.$name.'.'.$key, $value);
            }
        }

        // twig functions
        $container->setParameter('assetic.twig_extension.functions', $config['twig']['functions']);

        // choose dynamic or static
        if ($useController = $container->getParameterBag()->resolveValue($container->getParameterBag()->get('assetic.use_controller'))) {
            $loader->load('controller.xml');
            $container->getDefinition('assetic.helper.dynamic')->addTag('templating.helper', array('alias' => 'assetic'));
            $container->removeDefinition('assetic.helper.static');
        } else {
            $container->getDefinition('assetic.helper.static')->addTag('templating.helper', array('alias' => 'assetic'));
            $container->removeDefinition('assetic.helper.dynamic');
        }

        $container->setParameter('assetic.bundles', $config['bundles']);

        if ($config['workers']['cache_busting']['enabled']) {
            $container->getDefinition('assetic.worker.cache_busting')->addTag('assetic.factory_worker');
        }
    }
602405
public function combine($type, &$files)
	{
		$basePath = realpath($this->getOption('basePath'));
		if(empty($basePath))return $files;
		$cacheName = $this->createCachePath($this->getOption('cacheFileName')?$this->getOption('cacheFileName'):$this->createFileName($type,$files)).'.'.$type;
		$this->setOption('coreUrl',$this->coreUrl);
		$minifier = new AssetsMinifier($this->options);
		$cacheUrl = $minifier->compress($type, $files, $cacheName);
		if(!empty($files))
		array_walk($files, function(&$value, $key) use($cacheUrl) {
			$value = $cacheUrl;
		});
		$this->cached[$type] = $cacheUrl;
	}
617072
public function create(array $aliases): CompressionMethodManager
    {
        $compressionMethods = [];
        foreach ($aliases as $alias) {
            if (\array_key_exists($alias, $this->compressionMethods)) {
                $compressionMethods[] = $this->compressionMethods[$alias];
            } else {
                throw new \InvalidArgumentException(\sprintf('The compression method with the alias "%s" is not supported.', $alias));
            }
        }

        return CompressionMethodManager::create($compressionMethods);
    }
541407
protected function packDefaults(SchemaBuilder $builder, array $overwriteDefaults = []): array
    {
        //Defined compositions
        $compositions = $this->getCompositions($builder);

        //User defined default values
        $userDefined = $overwriteDefaults + $this->getDefaults();

        //We need mutators to normalize default values
        $mutators = $this->getMutators();

        $defaults = [];
        foreach ($this->getFields() as $field => $type) {
            $default = is_array($type) ? [] : null;

            if (array_key_exists($field, $userDefined)) {
                //No merge to keep fields order intact
                $default = $userDefined[$field];
            }

            //Registering default values
            $defaults[$field] = $this->mutateValue(
                $builder,
                $compositions,
                $userDefined,
                $mutators,
                $field,
                $default
            );
        }

        return $defaults;
    }
455014
public function pack(){

        try{
            //call the factory to get the itemPacker implementation
            $testPacker = $this->getTestPacker();

            //then create the pack
            $testPack = $testPacker->packTest($this->test);

        } catch(Exception $e){
            throw new common_Exception('The test '. $this->test->getUri() .' cannot be packed : ' . $e->getMessage());
        }

        return $testPack;
    }
536235
protected function mergeCollections(Asset $compiledAsset, Collection $passedCollection)
    {
        $compiledNames = [];

        $mergedCollection = (new Collection())->setGroup($compiledAsset->group());

        foreach ($compiledAsset->collection() as $asset) {
            $compiledNames[$asset->name()] = $asset;
        }

        $compiledAssetAdded = false;

        foreach ($passedCollection as $asset) {

            // asset is not in compiled asset
            if (!isset($compiledNames[$asset->name()])) {
                $mergedCollection->append($asset);
                continue;
            }

            if ($compiledAssetAdded) {
                continue;
            }

            $mergedCollection->append($compiledAsset);

            $compiledAssetAdded = true;
        }

        return $mergedCollection;
    }
366197
protected function getAssetType($asset, array $availables, $type)
    {
        $type = null === $type
            ? $this->findAssetType($asset, $availables)
            : $this->formatAssetType($type);

        if (null !== $type) {
            return $type;
        }

        throw new InvalidArgumentException(sprintf('The asset type is required for the asset "%s"', $asset));
    }
577065
public static function create(array $properties): WeightEmbeddableInterface
    {
        if (array_key_exists(WeightEmbeddableInterface::EMBEDDED_PROP_UNIT, $properties)) {
            return new self(
                $properties[WeightEmbeddableInterface::EMBEDDED_PROP_UNIT],
                $properties[WeightEmbeddableInterface::EMBEDDED_PROP_VALUE]
            );
        }

        return new self(...array_values($properties));
    }