Compiling a HTSL file into a HTML or PHP file.

@api

@access public

@param  string $fromFile
@param  string $toFile

@return int|string
335024
public function compile( string$fromFile, string$toFile='' )
	{
		$fromFile= $this->getFilePath($fromFile);

		$result= $this->execute(new FileBuffer($this,$fromFile));

		if( $toFile ){
			return file_put_contents($toFile,$result);
		}else{
			return $result;
		}
	}
1308993
public static void copyFileStreams(final File fromFile, final File toFile) throws IOException {
        if (!fromFile.exists()) {
            return;
        }

        Files.copy(fromFile.toPath(), toFile.toPath(),
            StandardCopyOption.REPLACE_EXISTING,
            StandardCopyOption.COPY_ATTRIBUTES);
    }
1068792
private function copyDir($from, $to)
    {
        mkdir($to, 0777, true);
        
        $items = new FilesystemIterator($from);

        foreach ($items as $item)
        {
            $pattern = preg_quote($from, "/");
            $Key = preg_replace("/^{$pattern}/", "", $item);

            $subFrom = strval($item);
            $subTo   = $to.$Key;
            
            if (filetype($item) == 'dir')
            {
                $this->copyDir($subFrom, $subTo);
            } else {
                $this->copyFile($subFrom, $subTo);
            }
        }

        return true;
    }
1186026
public function copy($from, $to, $fromCopyRef = null)
    {
        $call = 'fileops/copy';
        $params = array(
            'root' => $this->root,
            'from_path' => $this->normalisePath($from),
            'to_path' => $this->normalisePath($to),
        );
        
        if ($fromCopyRef) {
            $params['from_path'] = null;
            $params['from_copy_ref'] = $fromCopyRef;
        }
        
        $response = $this->fetch('POST', self::API_URL, $call, $params);
        return $response;
    }
575702
public function copyFile( $from, $to )
	{
		$this->connection->checkConnection();
		$temp	= uniqid( time() ).".temp";
		$reader	= new Net_FTP_Reader( $this->connection );
		$reader->setPath( $this->getPath() );
		if( !$reader->getFile( $from, $temp ) )
			throw new RuntimeException( 'File "'.$from.'" could not be received.' );
		if( !$this->putFile( $temp, $to ) )
		{
			unlink( $temp );
			throw new RuntimeException( 'File "'.$from.'" could not be stored.' );
		}
		unlink( $temp );
		return TRUE;
	}
1124219
public function createLink($from, $to)
    {
        if (File::exists($from)) {
            if (!File::exists($to)) {
                try {
                    symlink($from, $to);
                } catch (\Exception $e) {
                    throw new \Exception("Cannot create symlink from $from to $to");
                }
            }
        }
    }
140488
public function byRevision(string $from, string $to = ''): Log
    {
        $this->since = ' ' . escapeshellarg($from) . '..'
                     . (empty($to) ? '' : escapeshellarg($to));
        return $this;
    }
605997
public function copyFolder( $from, $to )
	{
		$this->connection->checkConnection();
		$this->createFolder( $to );
		$reader	= new Net_FTP_Reader( $this->connection );
		$list	= $reader->getList( $from, TRUE );
		foreach( $list as $entry )
		{
			if( $entry['isdir'] )
				$this->createFolder( $to."/".$entry['name'] );
			else
				$this->copyFile( $from."/".$entry['name'], $to."/".$entry['name'] );
		}
		return TRUE;
	}
26847
protected static function to_webp_sources(string &$from, &$to) {
		// Validate the source.
		ref\file::path($from, true);
		if (! $from) {
			$from = '';
			return false;
		}

		// We can only convert JPEG, PNG, and GIF sources.
		$info = mime::finfo($from);
		if (! \in_array($info['mime'], array('image/jpeg', 'image/gif', 'image/png'), true)) {
			$from = '';
			return false;
		}

		// Build a destination if we need to.
		if (null !== $to) {
			ref\cast::string($to, true);

			// If this is just a file name, throw it in from's dir.
			if (false === \strpos($to, '/')) {
				$to = "{$info['dirname']}/$to";
			}
			ref\file::path($to, false);
			if ('.webp' !== \substr(\strtolower($to), -5)) {
				$to = '';
				return false;
			}
		}
		// Just swap extensions with the source.
		else {
			$to = "{$info['dirname']}/{$info['filename']}.webp";
		}

		return true;
	}
815324
public function compile($outFile)
    {
        // compile routes to php file as a cache.
        usort($this->mux->routes, array('Pux\\MuxCompiler', 'sort_routes'));

        $code = $this->mux->export();

        return file_put_contents($outFile, '<?php return '.$code.'; /* version */');
    }
1252470
private function doDiff(Diff $diff, ElementtypeStructure $fromStructure = null, ElementtypeStructure $toStructure = null)
    {
        $rii = new \RecursiveIteratorIterator($fromStructure->getIterator(), \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($rii as $fromNode) {
            /* @var $fromNode ElementtypeStructureNode */

            if ($toNode = $toStructure->getNode($fromNode->getDsId())) {
                if (implode('_', $toNode->getRepeatableDsIdPath()) !== implode('_', $fromNode->getRepeatableDsIdPath())) {
                    $diff->addMoved($fromNode, $toNode);
                }
            } else {
                $diff->addRemoved($fromNode);
            }
        }

        $rii = new \RecursiveIteratorIterator($toStructure->getIterator(), \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($rii as $toNode) {
            /* @var $toNode \Phlexible\Bundle\ElementtypeBundle\Model\ElementtypeStructureNode */

            if (!$fromStructure->getNode($toNode->getDsId())) {
                $diff->addAdded($toNode);
            }
        }

        return $diff;
    }
833859
protected function getPaginatedMetaFiles($from , $to)
    {
        if ( $from > $to ) {
            throw new InvalidException('Start page for metafiles must be inferior to end page');
        }

        $ret = array();
        try {
            $result = $this->getSoapClient()->GetMetafiles(array(
                'fromPage' => ( integer ) $from ,
                'toPage'   => ( integer ) $to ,
            ));
        } catch ( SoapException $ex ) {
            throw new MetafilesException('Error while retrieving the document from Livedocx service' , $ex);
        }
        if ( isset($result->GetMetafilesResult->string) ) {
            $pageCounter = ( integer ) $from;
            if ( is_array($result->GetMetafilesResult->string) ) {
                foreach ( $result->GetMetafilesResult->string as $string ) {
                    $ret[ $pageCounter ] = base64_decode($string);
                    $pageCounter ++;
                }
            } else {
                $ret[ $pageCounter ] = base64_decode($result->GetMetafilesResult->string);
            }
        }

        return $ret;
    }
931337
public static function text($text, $outfile = false, $level = Constants::QR_ECLEVEL_L, $size = 3, $margin = 4)
    {
        $enc = QRencode::factory($level, $size, $margin);
        return $enc->encode($text, $outfile);
    }
870173
public void copyFile(DocFile fromFile) throws DocFileIOException {
        try (OutputStream output = openOutputStream()) {
            try (InputStream input = fromFile.openInputStream()) {
                byte[] bytearr = new byte[1024];
                int len;
                while ((len = read(fromFile, input, bytearr)) != -1) {
                    write(this, output, bytearr, len);
                }
            } catch (IOException e) {
                throw new DocFileIOException(fromFile, DocFileIOException.Mode.READ, e);
            }
        } catch (IOException e) {
            throw new DocFileIOException(this, DocFileIOException.Mode.WRITE, e);
        }
    }
730057
public function pack($from, $to)
    {
        if (($gzip = gzopen($to, 'wb')) === false) {
            throw new Exception('Unable create compressed file.');
        }

        if (($source = fopen($from, 'rb')) === false) {
            throw new Exception('Unable open the compression source file.');
        }

        while (!feof($source)) {
            $content = fread($source, 4096);
            gzwrite($gzip, $content, strlen($content));
        }

        gzclose($gzip);
        fclose($source);
    }
1287519
public static function convert($input, $from, $to)
    {
        if (!method_exists(self::class, $to)) {
            return $input;
        }
        
        if (in_array($from, ['camel', 'pascal'])) {
            $converted = self::$from($input);
            $converted = preg_replace('/([a-z])([A-Z])/', '$1 $2', $converted);
            $converted = preg_replace('/(\D)?(\d+)(\D)?/', '$1 $2 $3', $converted);
            return self::$to($converted);
        }
        
        if (method_exists(self::class, $from)) {
            return self::$to(self::$from($input));
        }
        
        return self::$to($input);
    }
447798
public function registerFile($type, $from, $to)
	{
		if (!isset($this->registered_files[$type]))
			$this->registered_files[$type] = array();

		$this->registered_files[$type][$from] = $to;
	}