Add asset mapper from file or directory path

@param string $sourcePath File or directory path
@param string $targetPath Target path

@return AssetMapper
438702
public function load($sourcePath, $targetPath)
  {
    $mapper = new AssetMapper();
    $mapper->map($sourcePath, $targetPath);

    return $mapper;
  }
1294208
public function moveTo($targetPath)
        {
            if ($this->moved) {
                throw new \RuntimeException('Uploaded file already moved');
            }

            if (!is_string($targetPath) || $targetPath === '') {
                throw new \InvalidArgumentException('Target path must be a non empty string');
            }

            $stream = $this->getStream();
            $file   = $stream->getMetadata('uri');

            if (is_dir($targetPath)) {
                
                if (!is_writable($targetPath)) {
                    throw new \InvalidArgumentException('Target path is not writable');
                }
                $target = rtrim($targetPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $this->clientFilename;
                
            } else {
                
                if (!is_writable(dirname($targetPath))) {
                    throw new \InvalidArgumentException('Target path is not writable');
                }
                $target = $targetPath;

            }
            
            if (!copy($file, $target)) {
                throw new \RuntimeException(sprintf('Error coping uploaded file %1s to %2s', $this->clientFilename, $targetPath));
            }
        
            $this->moved = true;
            if (!$this->moved) {
                throw new \RuntimeException(sprintf('Uploaded file could not be moved to %s', $targetPath));
            }
        }
877574
public function move($sourcePath, $destinationPath)
    {
        list($sourceDir) = Uri\split($sourcePath);
        list($destinationDir, $destinationName) = Uri\split($destinationPath);

        if ($sourceDir === $destinationDir) {
            // If this is a 'local' rename, it means we can just trigger a rename.
            $sourceNode = $this->getNodeForPath($sourcePath);
            $sourceNode->setName($destinationName);
        } else {
            $newParentNode = $this->getNodeForPath($destinationDir);
            $moveSuccess = false;
            if ($newParentNode instanceof IMoveTarget) {
                // The target collection may be able to handle the move
                $sourceNode = $this->getNodeForPath($sourcePath);
                $moveSuccess = $newParentNode->moveInto($destinationName, $sourcePath, $sourceNode);
            }
            if (!$moveSuccess) {
                $this->copy($sourcePath, $destinationPath);
                $this->getNodeForPath($sourcePath)->delete();
            }
        }
        $this->markDirty($sourceDir);
        $this->markDirty($destinationDir);
    }
520219
protected function importAsset($absolutePath, $relativePath)
    {
        /** @var AssetHandler $assetHandler */
        foreach ($this->assetHandlers as $assetHandler) {
            if ($assetHandler->isApplicable($relativePath)) {
                $info = $assetHandler->handle($absolutePath, $relativePath);

                if ($relativePath != ltrim($info['uri'], '/')) {
                    $this->setItemContent(str_replace($relativePath, $info['uri'], $this->getItemContent()));
                }

                //Break chain of asset handler, first applicable is taken
                return;
            }
        }
        throw new AssetManagerException('Unable to import auxiliary & dependency files. No asset handler applicable to file : ' . $relativePath);
    }
646538
public function getAssetRenderer($baseUrl = null, $basePath = null)
    {
        if ($this->jsRenderer === null) {
            $this->jsRenderer = new AssetsRenderer($this, $baseUrl, $basePath);
        }

        return $this->jsRenderer;
    }
929476
@Override
    public T addAsLibrary(Asset resource, ArchivePath target) throws IllegalArgumentException {
        Validate.notNull(resource, "Resource must be specified");
        Validate.notNull(target, "Target must be specified");

        ArchivePath location = new BasicPath(getLibraryPath(), target);
        return add(resource, location);
    }
1261586
public static function listFilePaths ( $targetPath ) {
        if ( is_file($targetPath) === true ) {
            return array($targetPath);
        }

        if ( !is_dir($targetPath) || !($dh = opendir($targetPath)) ) {
            return array();
        }

        $fileList = array();
        while ( ($fileName = readdir($dh)) !== false ) {
            if ( $fileName === '.' || $fileName === '..' ) {
                continue;
            }

            $realPath = realpath($targetPath) . '/' . $fileName;

            if ( is_dir($realPath) === true ) {
                $fileList = array_merge($fileList, self::listFilePaths($realPath));
            } else {
                $fileList[] = $realPath;
            }
        }
        closedir($dh);
        sort($fileList);

        return $fileList;
    }
717969
public function mapAssetLocation($path)
    {
        $url = URL::to('/' . ltrim($path, '/'))->getRelativeUrl();
        $this->setAssetURL($url);
    }
1167469
public function generateFile(string $targetPath, string $templateName, array $variables)
    {
        $variables = array_merge($variables, [
            'helper' => $this->twigHelper,
        ]);

        $this->addOperation($targetPath, $templateName, $variables);
    }
617456
public function importFile (string $assetPathToMap) : void
    {
        try {
            $filePath = $this->namespaceRegistry->getFilePath(Asset::createFromAssetPath($assetPathToMap));

            if (\is_file($filePath))
            {
                $map = \json_decode(\file_get_contents($filePath), true);

                if (null !== $map)
                {
                    $this->importMap(
                        \dirname($assetPathToMap),
                        $map
                    );
                }
            }
        }
        catch (AssetsException $e)
        {
            if (null !== $this->logger)
            {
                $this->logger->error("Could not load dependency map at {path}.", [
                    "path" => $assetPathToMap,
                    "error" => $e->getMessage(),
                ]);
            }
        }
    }
861928
@Override
    public T addAsWebResource(Asset resource, String target) throws IllegalArgumentException {
        Validate.notNull(resource, "Resource should be specified");
        Validate.notNull(target, "Target should be specified");

        return addAsWebResource(resource, new BasicPath(target));
    }
817014
public static function asset(string $path, string $assetKey = null): Redirect
    {
        return self::temporary(Route::asset($path, $assetKey));
    }
132434
private function createPackageDefinition($basePath, array $baseUrls, Reference $version)
    {
        if ($basePath && $baseUrls) {
            throw new \LogicException('An asset package cannot have base URLs and base paths.');
        }

        $package = new ChildDefinition($baseUrls ? 'assets.url_package' : 'assets.path_package');
        $package
            ->setPublic(false)
            ->replaceArgument(0, $baseUrls ?: $basePath)
            ->replaceArgument(1, $version)
        ;

        return $package;
    }
223298
public function copy($sourcePath, $destinationPath)
    {
        $sourceNode = $this->getNodeForPath($sourcePath);

        // grab the dirname and basename components
        list($destinationDir, $destinationName) = Uri\split($destinationPath);

        $destinationParent = $this->getNodeForPath($destinationDir);
        // Check if the target can handle the copy itself. If not, we do it ourselves.
        if (!$destinationParent instanceof ICopyTarget || !$destinationParent->copyInto($destinationName, $sourcePath, $sourceNode)) {
            $this->copyNode($sourceNode, $destinationParent, $destinationName);
        }

        $this->markDirty($destinationDir);
    }
1157662
public void addSourcePath(File sourcePath) {
		if (this.sourcePath == null) {
			this.sourcePath = new ArrayList<>();
		}
		this.sourcePath.add(sourcePath);
	}
469234
public function addVendor($vendorPath)
    {
        $dir = $vendorPath . '/composer';
        if (file_exists($file = $dir . '/autoload_namespaces.php')) {
            $map = require $file;
            foreach ($map as $namespace => $path) {
                if (isset($this->namespacePool[$namespace])) continue;
                $this->loader->set($namespace, $path);
                $this->namespacePool[$namespace] = true;
            }
        }
        if (file_exists($file = $dir . '/autoload_psr4.php')) {
            $map = require $file;
            foreach ($map as $namespace => $path) {
                if (isset($this->psr4Pool[$namespace])) continue;
                $this->loader->setPsr4($namespace, $path);
                $this->psr4Pool[$namespace] = true;
            }
        }
        if (file_exists($file = $dir . '/autoload_classmap.php')) {
            $classMap = require $file;
            if ($classMap) {
                $classMapDiff = array_diff_key($classMap, $this->classMapPool);
                $this->loader->addClassMap($classMapDiff);
                $this->classMapPool += array_fill_keys(array_keys($classMapDiff), true);
            }
        }
        if (file_exists($file = $dir . '/autoload_files.php')) {
            $includeFiles = require $file;
            foreach ($includeFiles as $includeFile) {
                $relativeFile = $this->stripVendorDir($includeFile, $vendorPath);
                if (isset($this->includeFilesPool[$relativeFile])) continue;
                require $includeFile;
                $this->includeFilesPool[$relativeFile] = true;
            }
        }
    }
1075791
public function build($basePath)
    {
        $cache = new PuliResourceCollectionCache($this->cacheDir.'gui-icons.css', $this->debug);

        $resources = $this->resourceFinder->findByType('phlexible/icons');

        if (!$cache->isFresh($resources)) {
            $content = $this->buildIcons($resources, $basePath);

            $cache->write($content);

            if (!$this->debug) {
                $this->compressor->compressFile((string) $cache);
            }
        }

        return new Asset((string) $cache);
    }