Compiles all sprites

@return int Number of images merged
974173
public function compile()
    {
        // Path prefix
        $prefix = $this->getNewPrefix();
        // List of images
        $data = $this->getList();

        // sizes
        $sizes = [];
        foreach ($this->providers as $provider) {
            if ($provider instanceof SizeProviderInterface) {
                $sizes = array_merge($sizes, $provider->getSizes());
            }
        }

        $num = 0;
        $scss = [];
        foreach ($data as $name => $list) {
            // Sprite size
            $size = !isset($sizes[$name]) ? null : $sizes[$name];
            $size = $this->getSize($name, $size);
            if (is_array($size)) {
                $border = $size[1];
                $sizeH = isset($size[2]) ? $size[2] : $size[0];
                $sizeW = $size[0];
            } else {
                $border = static::BORDER_WIDTH;
                $sizeH = $sizeW = $size;
            }
            $scss[] = $this->compileFile($prefix, $name, $list, [$sizeW, $sizeH], $border);
            $num += count($list);
        }

        // Populating template
        $template = file_get_contents($this->template);
        $scss = str_replace(
            static::TEMPLATE_NEEDLE, join("\n", $scss), $template
        );

        // Creating global classes
        if (static::CREATE_CLASSES) {
            foreach ($data as $name => $list) {
                $scss .= '.#{$' . static::NAMESPACE_NAME . '}';
                $scss .= ', .#{$' . static::NAMESPACE_NAME . '}-' . $name . ' {' . "\n";
                $scss .= '@include ' . static::PREFIX_SPRITE . $name . ';' . "\n";
                $scss .= '};' . "\n";
            }
        }

        // Writing the file
        file_put_contents($this->stylePath, $scss);

        return $num;
    }
1021996
public function compileHeaders()
    {
        if (count($this->attachement) > 0) {
            $this->headers[] = "Content-type: multipart/mixed; boundary=\"{$this->boundary}\"" . self::END;

            foreach ($this->attachement as $file) {
                $filename = basename($file);
                $this->headers[] = "--" . $this->boundary;
                $this->headers[] = "Content-Type: application/octet-stream; name=\"{$filename}\"";
                $this->headers[] = "Content-Transfer-Encoding: base64";
                $this->headers[] = "Content-Disposition: attachment" . self::END;
                $this->headers[] = chunk_split(base64_encode(file_get_contents($file)));
            }

            $this->headers[] = "--" . $this->boundary;
        }

        return implode(self::END, $this->headers).self::END;
    }
1007924
public function all()
    {
        $all = [];

        foreach ($this->style as $style) {
            $all = array_merge($all, $this->convertToCodes($style->all()));
        }

        return $all;
    }
1121110
protected function compileAllFiles(){
        $preloader = new ClassPreloader(new PrettyPrinter, new Parser(new Lexer), $this->getTraverser());


        $handle = $preloader->prepareOutput($this->getContainer()->getCompiledPath());
        foreach ($this->getAllFiles() as $file) {
            try {
                fwrite($handle, $preloader->getCode($file, false)."\n");
            } catch (SkipFileException $ex) {
                //
            }
        }

        fclose($handle);
    }
328315
public function generate(): array
    {
        // create temporay directory
        $tempDir = new Tempdir('sprite');
        $tempDir->addPlugin(new ListFiles);

        // get basic info about video
        $ffprobe  = FFProbe::create()->format($this->getSource());
        $duration = (float)$ffprobe->get('duration');

        // check if sample rate is high enough to reach desired minimum amount of thumbnails
        if ($duration <= $this->getMinThumbs()) {
            // we only have a 1 second resolution, so we can't get lower than 1 obviously
            $this->setRate(1);
        } else {
            if ($duration / $this->getRate() < $this->getMinThumbs()) {
                // sample rate too high, let's adjust rate a little
                $this->setRate((int)floor($duration / $this->getMinThumbs()));
            }
        }

        $this->thumbnailer
            ->setSource($this->getSource())
            ->setWidth($this->getWidth())
            ->setDestination($tempDir->getPath());

        // capture images to tempdir
        for ($i = 0; $i <= $duration; $i += $this->getRate()) {
            $this->thumbnailer->run($i, (int)floor($i / $this->getRate()));
        }

        if (!empty($this->outputImageDirectory)) {
            foreach ($tempDir->listFiles() as $image) {
                copy($tempDir->getPath() . $image['path'], $this->outputImageDirectory . $image['basename']);
            }
        }

        // combine all images to one sprite with quadratic tiling
        $gridSize   = ceil(sqrt(count($tempDir->listFiles())));
        $firstImage = Image::make(sprintf('%s/0001.jpg', $tempDir->getPath()));
        $spriteFile = sprintf('%s/%s.jpg',
            $this->getOutputDirectory(),
            $this->getPrefix()
        );

        $spriteUrl = empty($this->getUrlPrefix())
            ? basename($spriteFile)
            : sprintf('%s/%s', $this->getUrlPrefix(), basename($spriteFile));

        $cmd = sprintf('montage %1$s/*.jpg -tile %2$dx -geometry %3$dx%4$d+0+0 %5$s',
            $tempDir->getPath(),
            $gridSize,
            $firstImage->width(),
            $firstImage->height(),
            $spriteFile
        );

        $proc = new Process($cmd);
        $proc->run();

        if (!$proc->isSuccessful()) {
            throw new \RuntimeException($proc->getErrorOutput());
        }

        // create WebVTT output
        $vttFile = sprintf('%s/%s.vtt',
            $this->getOutputDirectory(),
            $this->getPrefix()
        );

        $vtt      = new WebvttFile();
        $numFiles = count($tempDir->listFiles());

        for ($i = 0; $i < $numFiles; $i++) {
            $start = $i * $this->getRate();
            $end   = ($i + 1) * $this->getRate();
            $x     = ($i % $gridSize) * $firstImage->width();
            $y     = floor($i / $gridSize) * $firstImage->height();

            $vtt->addCue(new WebvttCue(
                    $this->secondsToCue($start),
                    $this->secondsToCue($end),
                    sprintf('%s#xywh=%d,%d,%d,%d',
                        $spriteUrl,
                        $x,
                        $y,
                        $firstImage->width(),
                        $firstImage->height()
                    )
                )
            );
        }

        $vtt->build();
        $vtt->save($vttFile);

        return [
            'vttFile' => $vttFile,
            'sprite'  => $spriteFile,
        ];
    }
995676
public function compile()
    {
        $this->doLoad();

        $data = (array) $this->data;

        $this->removeKey($data, 'include');
        $this->removeKey($data, '__META__');

        return var_export($data, true);
    }
327943
protected function compile()
    {
        $templateContent = file_get_contents($this->file);

        foreach ($this->patternCollection as $pattern) {
            $templateContent = $pattern->setContent($templateContent)
                ->render();
        }

        if (false === file_put_contents($this->fileCompiled, $templateContent)) {
            throw new \Exception('Cannot write compiled template file!');
        }
    }
543744
public function to_css() {
        $content = implode(';', $this->scssprepend);
        if (!empty($this->scssfile)) {
            $content .= file_get_contents($this->scssfile);
        }
        $content .= implode(';', $this->scsscontent);
        return $this->compile($content);
    }
1318922
function compile() {
		$code = $this->match_code($this->value) ;

		$id = $this->varid() ;

		if ( $this->optional ) {
			$code = PHPBuilder::build()
				->l(
				$this->save($id),
				$code->replace( array( 'FAIL' => $this->restore($id,true) ))
				);
		}

		if ( $this->zero_or_more ) {
			$code = PHPBuilder::build()
				->b( 'while (true)',
					$this->save($id),
					$code->replace( array(
						'MATCH' => NULL,
						'FAIL' =>
							$this->restore($id,true)
							->l( 'break;' )
					))
				)
				->l(
				'MATCH'
				);
		}

		if ( $this->one_or_more ) {
			$code = PHPBuilder::build()
				->l(
				'$count = 0;'
				)
				->b( 'while (true)',
					$this->save($id),
					$code->replace( array(
						'MATCH' => NULL,
						'FAIL' =>
							$this->restore($id,true)
							->l( 'break;' )
					)),
					'$count += 1;'
				)
				->b( 'if ($count > 0)', 'MATCH' )
				->b( 'else',            'FAIL' );
		}

		if ( $this->positive_lookahead ) {
			$code = PHPBuilder::build()
				->l(
				$this->save($id),
				$code->replace( array(
					'MATCH' =>
						$this->restore($id)
						->l( 'MATCH' ),
					'FAIL' =>
						$this->restore($id)
						->l( 'FAIL' )
				)));
		}

		if ( $this->negative_lookahead ) {
			$code = PHPBuilder::build()
				->l(
				$this->save($id),
				$code->replace( array(
					'MATCH' =>
						$this->restore($id)
						->l( 'FAIL' ),
					'FAIL' =>
						$this->restore($id)
						->l( 'MATCH' )
				)));
		}

		if ( $this->tag && !($this instanceof TokenRecurse ) ) {
			$code = PHPBuilder::build()
				->l(
				'$stack[] = $result; $result = $this->construct( $matchrule, "'.$this->tag.'" ); ',
				$code->replace(array(
					'MATCH' => PHPBuilder::build()
						->l(
						'$subres = $result; $result = array_pop($stack);',
						'$this->store( $result, $subres, \''.$this->tag.'\' );',
						'MATCH'
						),
					'FAIL' => PHPBuilder::build()
						->l(
						'$result = array_pop($stack);',
						'FAIL'
						)
				)));
		}

		return $code ;
	}
937355
protected function compile()
    {
        $this->headers = array_merge(
            $this->csp(),
            $this->featurePolicy(),
            $this->hpkp(),
            $this->hsts(),
            $this->expectCT(),
            $this->clearSiteData(),
            $this->miscellaneous()
        );

        $this->compiled = true;
    }
794532
public function compile() {
		foreach ($this->_params as $key => $value) {
			if (!strpos($key, ':')) {
				continue;
			}
			unset($this->_params[$key]);
			$this->_meta[$key] = $value;
		}

		$this->_match = $this->_params;

		if ($this->_template === '/' || $this->_template === '') {
			$this->_pattern = '@^/*$@';
			return;
		}
		$this->_pattern = "@^{$this->_template}\$@";
		$match = '@([/.])?\{:([^:}]+):?((?:[^{]+?(?:\{[0-9,]+\})?)*?)\}@S';

		if ($this->_config['unicode']) {
			$this->_pattern .= 'u';
		}
		preg_match_all($match, $this->_pattern, $m);

		if (!$tokens = $m[0]) {
			return;
		}
		$slashes = $m[1];
		$params = $m[2];
		$regexs = $m[3];
		unset($m);
		$this->_keys = [];

		foreach ($params as $i => $param) {
			$this->_keys[$param] = $param;
			$this->_pattern = $this->_regex($regexs[$i], $param, $tokens[$i], $slashes[$i]);
		}
		$this->_defaults += array_intersect_key($this->_params, $this->_keys);
		$this->_match = array_diff_key($this->_params, $this->_defaults);
	}
454404
protected function compile()
	{		
		// Get the pattern model collection
		$colPattern = \PatternModel::findVisibleByPid($this->objElement->id);

		if ($colPattern === null)
		{
			return;
		}
		
		// Get correct content element id (included content element) see #37
		$intPid = ($this->origId) ? $this->origId : $this->id;
		
		// Get the data
		$colData = \DataModel::findByPid($intPid);

		if ($colData !== null)
		{
			foreach ($colData as $objData)
			{
				$arrData[$objData->pattern] = $objData;
			}							
		}

		// Prepare values for every pattern
		foreach($colPattern as $objPattern)
		{
			if (!Pattern::hasOutput($objPattern->type))
			{
				continue;
			}
			
			$strClass = Pattern::findClass($objPattern->type);
				
			if (!class_exists($strClass))
			{
				System::log('Pattern element class "'.$strClass.'" (pattern element "'.$objPattern->type.'") does not exist', __METHOD__, TL_ERROR);
			}
			else
			{
				$objPatternClass = new $strClass($objPattern);
				$objPatternClass->pid = $intPid;
				$objPatternClass->Template = $this->Template;
				$objPatternClass->data = $arrData[$objPattern->alias];
		
				$objPatternClass->compile();
			}
		}
	}
199294
public static function compiles()
    {
        return [
            base_path('vendor\kodicms\laravel-assets\src\Contracts\MetaInterface.php'),
            base_path('vendor\kodicms\laravel-assets\src\Contracts\AssetsInterface.php'),
            base_path('vendor\kodicms\laravel-assets\src\Contracts\PackageManagerInterface.php'),
            base_path('vendor\kodicms\laravel-assets\src\Contracts\AssetElementInterface.php'),
            base_path('vendor\kodicms\laravel-assets\src\Contracts\PackageInterface.php'),
            base_path('vendor\kodicms\laravel-assets\src\Contracts\SocialMediaTagsInterface.php'),
            base_path('vendor\kodicms\laravel-assets\src\Traits\Groups.php'),
            base_path('vendor\kodicms\laravel-assets\src\Traits\Vars.php'),
            base_path('vendor\kodicms\laravel-assets\src\Traits\Packages.php'),
            base_path('vendor\kodicms\laravel-assets\src\Traits\Styles.php'),
            base_path('vendor\kodicms\laravel-assets\src\Traits\Scripts.php'),
            base_path('vendor\kodicms\laravel-assets\src\AssetElement.php'),
            base_path('vendor\kodicms\laravel-assets\src\Css.php'),
            base_path('vendor\kodicms\laravel-assets\src\Javascript.php'),
            base_path('vendor\kodicms\laravel-assets\src\Html.php'),
            base_path('vendor\kodicms\laravel-assets\src\Meta.php'),
            base_path('vendor\kodicms\laravel-assets\src\Package.php'),
            base_path('vendor\kodicms\laravel-assets\src\PackageManager.php'),
            base_path('vendor\kodicms\laravel-assets\src\Assets.php'),
            base_path('vendor\kodicms\laravel-assets\src\Facades\Meta.php'),
        ];
    }
64627
function compile() {
		
		// if no setContent() then load the from file
		if (!$this->getContent()) {
			
			// if no setTemplate() then use default template file
			if (!$this->getTemplate()) {
				$this->setTemplate($this->config['dir_template'] . '/' . $this->name . $this->config['extension']);
			}
			
			$this->_setContentFromFile();
		}
		
		$this->_compile();
		
		return $this;
	}
1295339
public function compilePaginations()
	{
		foreach ($this->site->getPaginations() as $pagination) 
		{
			$template = $this->twig->loadTemplate( 'index.html.tpl' );
			$content = $template->render(array('site' => $this->site, 'pagination' => $pagination));
			$this->createFile($content, $pagination);
		}
	}
1368070
protected function compile()
	{
		if (substr($this->url, 0, 7) == 'mailto:')
		{
			$this->url = \String::encodeEmail($this->url);
		}
		else
		{
			$this->url = ampersand($this->url);
		}

		if ($this->linkTitle == '')
		{
			$this->linkTitle = $this->url;
		}

		if (strncmp($this->rel, 'lightbox', 8) !== 0)
		{
			$this->Template->attribute = ' rel="'. $this->rel .'"';
		}
		else
		{
			$this->Template->attribute = ' data-lightbox="'. substr($this->rel, 9, -1) .'"';
		}

		// Override the link target
		if ($this->target)
		{
			$this->Template->target = ' target="_blank"';
		}

		if($this->cssID[1] == '')
		{
			$cssID = $this->cssID;
			$cssID[1] = 'btn-default';
			$this->cssID = $cssID;
		}

		if($this->icon)
		{
			$this->Template->icon = Icons::generateIcon($this->icon);
		}

		// add data attributes
		$this->dataAttributes = deserialize($this->dataAttributes, true);

		if(!empty($this->dataAttributes))
		{
			$attributes = array();

			foreach($this->dataAttributes as $attribute)
			{
				if(trim($attribute['value']) != '' && $attribute['name'] != '')
				{

					$attributes[] = 'data-' . $attribute['name'] . '=' . $attribute['value'];
				}
			}

			$this->Template->attribute = trim($this->attribute . ' ' . implode(' ', $attributes));
		}

		$this->Template->rel = $this->rel; // Backwards compatibility
		$this->Template->href = $this->url;
		$this->Template->link = $this->linkTitle;
		$this->Template->linkTitle = specialchars($this->titleText ?: $this->linkTitle);
	}
1317359
public function compile()
    {
        $indent         = '    ';
        $caseStatements = array();
        $getters        = array();
        $instances      = $this->dumper->getAllInjectedDefinitions();

        /* @var $instance GeneratorInstance */
        foreach ($instances as $name => $instance) {
            $getter = $this->normalizeAlias($name);
            $constructor = $instance->getConstructor();
            $instantiatorParams = $this->buildParams($instance->getParams());

            if ('__construct' !== $constructor) {
                // Constructor callback
                if (is_callable($constructor)) {
                    $callback = $constructor;

                    if (is_array($callback)) {
                        $class = (is_object($callback[0])) ? get_class($callback[0]) : $callback[0];
                        $method = $callback[1];
                    } elseif (is_string($callback) && strpos($callback, '::') !== false) {
                        list($class, $method) = explode('::', $callback, 2);
                    }

                    $callback = var_export(array($class, $method), true);

                    if (count($instantiatorParams)) {
                        $creation = sprintf('$object = call_user_func(%s, %s);', $callback, implode(', ', $instantiatorParams));
                    } else {
                        $creation = sprintf('$object = call_user_func(%s);', $callback);
                    }
                } else if (is_string($constructor) && strpos($constructor, '->') !== false) {
                    list($class, $method) = explode('->', $constructor, 2);

                    if (!class_exists($class)) {
                        throw new InvalidArgumentException('No class found: ' . $class);
                    }

                    $factoryGetter = $this->normalizeAlias($class);

                    if (count($instantiatorParams)) {
                        $creation = sprintf('$object = $this->' . $factoryGetter . '()->%s(%s);', $method, implode(', ', $instantiatorParams));
                    } else {
                        $creation = sprintf('$object = $this->' . $factoryGetter . '()->%s();', $method);
                    }
                } else {
                    throw new InvalidArgumentException('Invalid instantiator supplied for class: ' . $name);
                }
            } else {
                $className = '\\' . trim($this->reduceAlias($name), '\\');

                if (count($instantiatorParams)) {
                    $creation = sprintf('$object = new %s(%s);', $className, implode(', ', $instantiatorParams));
                } else {
                    $creation = sprintf('$object = new %s();', $className);
                }
            }


            // Create method call code
            if ($instance->isShared()) {
                $creation .= "\n\nif (\$isShared) {\n" . $indent
                    . '$this->instanceManager->addSharedInstance($object, \'' . $instance->getName() . '\');'
                    . "\n}\n";
            }
            $methods = '';

            foreach ($instance->getMethods() as $methodData) {
                $methodName   = $methodData['method'];
                $methodParams = $methodData['params'];
                // Create method parameter representation
                $params = $this->buildParams($methodParams);

                if (count($params)) {
                    $methods .= sprintf("\$object->%s(%s);\n", $methodName, implode(', ', $params));
                }
            }

            $storage = '';

            // Start creating getter
            $getterBody = '';

            // Creation and method calls
            $getterBody .= sprintf("%s\n", $creation);
            $getterBody .= $methods;

            // Stored service
            $getterBody .= $storage;

            // End getter body
            $getterBody .= "return \$object;\n";

            $getterDef = new MethodGenerator();
            $getterDef->setName($getter);
            $getterDef->setParameter('isShared');
            $getterDef->setVisibility(MethodGenerator::VISIBILITY_PROTECTED);
            $getterDef->setBody($getterBody);
            $getters[] = $getterDef;

            // Build case statement and store
            $statement = '';
            $statement .= sprintf("%scase '%s':\n", $indent, $name);
            $statement .= sprintf("%sreturn \$this->%s(%s);\n", str_repeat($indent, 2), $getter, '$isShared');

            $caseStatements[] = $statement;
        }

        // Build switch statement
        $switch = sprintf(
            "if (%s) {\n%sreturn parent::newInstance(%s, %s, %s);\n}\n",
            '$params',
            $indent,
            '$name',
            '$params',
            '$isShared'
        );
        $switch .= sprintf(
            "switch (%s) {\n%s\n", '$name', implode("\n", $caseStatements)
        );
        $switch .= sprintf(
            "%sdefault:\n%sreturn parent::newInstance(%s, %s, %s);\n",
            $indent,
            str_repeat($indent, 2),
            '$name',
            '$params',
            '$isShared'
        );
        $switch .= "}\n\n";

        // Build newInstance() method
        $nameParam   = new ParameterGenerator();
        $nameParam->setName('name');

        $paramsParam = new ParameterGenerator();
        $paramsParam
            ->setName('params')
            ->setType('array')
            ->setDefaultValue(array());

        $isSharedParam = new ParameterGenerator();
        $isSharedParam
            ->setName('isShared')
            ->setDefaultValue(true);

        $get = new MethodGenerator();
        $get->setName('newInstance');
        $get->setParameters(array(
            $nameParam,
            $paramsParam,
            $isSharedParam,
        ));
        $get->setBody($switch);

        // Create class code generation object
        $container = $this->getClassGenerator();
        $container
            ->setName($this->containerClass)
            ->setExtendedClass('Di')
            ->addMethods(array($get))
            ->addMEthods($getters);

        // Create PHP file code generation object
        $classFile = $this->getFileGenerator();

        $classFile->setClass($container);
        $classFile->setUse('Zend\Di\Di');

        if (null !== $this->namespace) {
            $classFile->setNamespace($this->namespace);
        }

        return $classFile;
    }