Create a new build target.

@param string $target Name of the target file. The extension will be inferred based on the last extension.
@param array $config Config data for the target. Should contain files, filters and theme key.
970796
public function addTarget($target, array $config)
    {
        $ext = $this->getExt($target);
        $config += [
            'files' => [],
            'filters' => [],
            'theme' => false,
            'extend' => false,
            'require' => [],
        ];
        if (!empty($config['paths'])) {
            $config['paths'] = array_map(array($this, '_replacePathConstants'), (array)$config['paths']);
        }
        $this->_targets[$target] = $config;
    }
633056
public function compile($config = array())
    {
        $config = new AnConfig($config);

        $config->append(array(
            'parse_urls' => true,
            'compress' => true,
            'import' => array(),
            'force' => false,
            'output' => null, //required
            'input' => null, //required
        ));

        $less = new lessc();
        $less->setPreserveComments(!$config->compress);
        if ($config->compress) {
            $less->setFormatter('compressed');
        }
        $config['import'] = $config['import'];
        $less->setImportDir($config['import']);
        $cache_file = ANPATH_CACHE.'/less-'.md5($config->input);

        if (file_exists($cache_file)) {
            $cache = unserialize(file_get_contents($cache_file));
        } else {
            $cache = $config->input;
        }

        $force = $config->force;

        //if output doesn't exsit then force compile
        if (!is_readable($config->output)) {
            $force = true;
        }

        //check if any of the import folder have changed or
        //if yes then re-compile
        if (is_array($cache)) {
            foreach ($config['import'] as $path) {
                if (is_readable($path) &&
                        filemtime($path) > $cache['updated']) {
                    $force = true;
                    break;
                }
            }
        }
        try {
            $new_cache = $less->cachedCompile($cache, $force);
        } catch (Exception $e) {
            print $e->getMessage();

            return;
        }
        if (!is_array($cache) || $new_cache['updated'] > $cache['updated']) {
            if ($config->parse_urls) {
                $new_cache['compiled'] = $this->_parseUrls($new_cache['compiled'], $config->import);
            }

            //store the cache
            file_put_contents($cache_file, serialize($new_cache));
            //store the compiled file
            //create a directory if
            if (!file_exists(dirname($config->output))) {
                mkdir(dirname($config->output), 0755);
            }
            file_put_contents($config->output, $new_cache['compiled']);
        }
    }
1029237
public function buildFileName(AssetTarget $target)
    {
        $file = $target->name();
        if ($target->isThemed() && $this->theme) {
            $file = $this->theme . '-' . $file;
        }
        return $file;
    }
888088
public function setConfig($config)
    {
        $this->config = $config;
        $this->factory = new Factory($config);
        $this->AssetBuild->setConfig($config);
    }
551717
public function initLoader(Config $config)
    {
        $loader = new Loader();
        $loader->registerDirs(
            [
                $config->application->libraryDir,
                $config->application->pluginDir,
                $config->application->taskDir
            ]
        )->register();
    }
434243
public function setConfig(array $config, $file = null)
    {
        $file = !empty($file) ? $file : $this->fileCache;
        if (file_exists($file)) {
            unlink($file);
        }
        (new PhpArray())
                ->setUseBracketArraySyntax(true)
                ->toFile($file, $config);
    }
378285
protected function copyDirectory($source, $target)
    {
        new Rah_Eien_Action_Stat($source, 'rd');
        new Rah_Eien_Action_Stat($target, 'wd');

        $files = new RecursiveDirectoryIterator($source);
        $file = new RecursiveIteratorIterator($files, RecursiveIteratorIterator::SELF_FIRST);

        while ($file->valid())
        {
            if ($file->isDot() === false)
            {
                $name = $target.'/'.$file->getSubPathName();

                if ($file->isDir())
                {
                    if (@mkdir($name) === false)
                    {
                        throw new Rah_Eien_Exception('Unable to create a directory: '.$name);
                    }
                }
                else
                {
                    $this->copyFile($file->getPathname(), $name);
                }
            }

            $file->next();
        }
    }
216131
protected function applyTargetFieldConfig(array $config)
    {
        if (!isset($config['targetField']) || !is_string($config['targetField'])) {
            throw new UnexpectedValueException($this->translate(
                'Relation field configuration should contain target field name and name should be a string.'
            ));
        }
        $this->targetFieldName = $config['targetField'];
    }
601346
public function mergeWithConfig(array &$target, $config_key, $default = [], $recursive = true)
    {
        if ($recursive) {
            $target = array_merge_recursive($target, $this->config($config_key, $default));
        } else {
            $target = array_merge($target, $this->config($config_key, $default));
        }
    }
424292
private function mkdir($target)
    {
        if (\is_dir($target)) {
            return;
        }

        if (! $this->file->mkdir($target)) {
            $this->output->writeln("<error>[$target] could not be created. Please check directory permissions.</error>");
        }
    }
1247549
protected function copy($source, $target): void
    {
        // skip, if not exists
        if (!file_exists($source)) {
            return;
        }
        // skip, if target exists
        if (is_file($target) && !is_dir($target)) {
            $this->installer->getIo()->write(
                sprintf('  - File <comment>%s</comment> already exists', $target),
                true,
                IOInterface::VERBOSE
            );
            return;
        }

        // Check the renaming of file for direct moving (file-to-file)
        $isRenameFile = substr($target, -1) !== '/' && !is_dir($source);

        if (file_exists($target) && !is_dir($target) && !$isRenameFile) {
            throw new \InvalidArgumentException('Destination directory is not a directory');
        }

        try {
            if ($isRenameFile) {
                $this->getFilesystem()->mkdir(\dirname($target));
            } else {
                $this->getFilesystem()->mkdir($target);
            }
        } catch (IOException $e) {
            throw new \InvalidArgumentException(
                sprintf('Could not create directory `%s`', $target)
            );
        }

        if (false === file_exists($source)) {
            throw new \InvalidArgumentException(
                sprintf('Source directory or file `%s` does not exist', $source)
            );
        }

        if (is_dir($source)) {
            $finder = new Finder;
            $finder->files()->in($source);

            foreach ($finder as $file) {
                try {
                    $this->getFilesystem()->copy($file, $target . DS . $file->getRelativePathname());
                } catch (IOException $e) {
                    throw new \InvalidArgumentException(
                        sprintf('Could not copy `%s`', $file->getBaseName())
                    );
                }
            }
        } else {
            try {
                if ($isRenameFile) {
                    $this->getFilesystem()->copy($source, $target);
                } else {
                    $this->getFilesystem()->copy($source, $target . '/' . basename($source));
                }
            } catch (IOException $e) {
                throw new \InvalidArgumentException(sprintf('Could not copy `%s`', $source));
            }
        }

        $this->installer->getIo()->write(
            sprintf('  - Copied file(s) from <comment>%s</comment> to <comment>%s</comment>', $source, $target),
            true,
            IOInterface::VERBOSE
        );
    }
193249
public function configureId($target, $attr)
    {
        if (isset($attr['id']) && $attr['id'] !== null) {
            $this->project->addReference($attr['id'], $target);
        }
    }
46684
public static function createFromTarget(TargetInterface $target, $options = [])
  {
    try {
      $info = $target->getOptions();
      $launchers = ['drush-launcher', 'drush.launcher', 'drush'];
      $binary = 'which ' . implode(' || which ', $launchers);

      $info = trim($target->exec('$(' . $binary . ') -r ' . $info['root'] . ' status --format=json'));
      $info = \Drutiny\Utility::jsonDecodeDirty($info, TRUE);

      // Hack for Acquia Cloud to force use drush9 if drush version reported is v9.
      if (Comparator::greaterThanOrEqualTo($info['drush-version'], '9.0.0')) {
        array_unshift($launchers, 'drush9');
        $binary = 'which ' . implode(' || which ', $launchers);
      }

      $binary = trim($target->exec($binary));
      $info = trim($target->exec($binary . ' -r ' . $info['root'] . ' status --format=json'));
      $info = json_decode($info, TRUE);
    }
    catch (ProcessFailedException $e) {
      Container::getLogger()->error($e->getProcess()->getOutput());
      throw $e;
    }

    switch (TRUE) {
      case Comparator::greaterThanOrEqualTo($info['drush-version'], '9.0.0'):
        $driver = Drush9Driver::createFromTarget($target, $binary);
        break;

      default:
        $driver = DrushDriver::createFromTarget($target, $binary);
    }
    $driver->setOptions($options);
    return $driver;
  }
1199329
private function setConfig($config)
	{
		foreach ($config as $key => $value) {
			$this->setConfigParam($key, $value);
		}

	}
719779
public static function filterConfig(array $config, $target = 'PHP')
	{
		$filteredConfig = [];
		foreach ($config as $name => $value)
		{
			if ($value instanceof FilterableConfigValue)
			{
				$value = $value->filterConfig($target);
				if (!isset($value))
				{
					continue;
				}
			}
			if (is_array($value))
			{
				$value = self::filterConfig($value, $target);
			}
			$filteredConfig[$name] = $value;
		}

		return $filteredConfig;
	}
1073920
private function copy($source, $target)
    {
        $files = $this->listFiles($source, $target);

        foreach ($files as $newPath => $oldPath) {
            if (!file_exists($newPath)) {
                if (is_dir($oldPath)) {
                    mkdir($newPath, 0755, true);
                } else {
                    copy($oldPath, $newPath);
                }
            }
        }
    }
905735
public function setConfig(array $config)
    {
        foreach ($config as $name => $value) {
            $setter = 'set' . ucfirst($name);

            call_user_func_array(array($this, $setter), array($value));
        }
    }