src/Silex/Framework/Command/AssetsInstallCommand.php
protected function execute( InputInterface $input, OutputInterface $output )
    {
        $targetArg = rtrim($input->getArgument('target'), '/');

        if (!is_dir($targetArg)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'The target directory "%s" does not exist.',
                    $input->getArgument('target')
                )
            );
        }

        $filesystem = $this->getApplication()->getService('filesystem');

        // Create the bundles directory otherwise symlink will fail.
        $bundlesDir = $targetArg.'/assets/';
        $filesystem->mkdir($bundlesDir, 0777);

        // relative implies symlink
        $symlink = $input->getOption('symlink') || $input->getOption('relative');

        if ($symlink) {
            $output->writeln(
                'Trying to install assets as <comment>symbolic links</comment>.'
            );
        } else {
            $output->writeln(
                'Installing assets as <comment>hard copies</comment>.'
            );
        }

        $assetsConfig = $this->getContainer()['config']['assets'];
        $bundlesBaseDir = $assetsConfig['default_base_dir'];
        $publicPath = $assetsConfig['public_path'];

        foreach ($assetsConfig['resources_path'] as $bundle) {
            if (is_dir(
                $originDir = $bundlesBaseDir . DIRECTORY_SEPARATOR . $bundle .
                DIRECTORY_SEPARATOR . $publicPath
            )
                || is_dir($originDir = $bundle . DIRECTORY_SEPARATOR . $publicPath)
            ) {
                $targetDir = $bundlesDir . preg_replace(
                    '/assets$/', '', strtolower($bundle)
                );

                $output->writeln(
                    sprintf(
                        'Installing assets for <comment>%s</comment> into ' .
                        '<comment>%s</comment>', $bundle, $targetDir
                    )
                );

                $filesystem->remove($targetDir);

                if ($symlink) {
                    if ($input->getOption('relative')) {
                        $relativeOriginDir = $filesystem->makePathRelative(
                            $originDir, realpath($bundlesDir)
                        );
                    } else {
                        $relativeOriginDir = $originDir;
                    }

                    try {
                        $filesystem->symlink($relativeOriginDir, $targetDir);
                        if (!file_exists($targetDir)) {
                            throw new IOException('Symbolic link is broken');
                        }
                        $output->writeln(
                            'The assets were installed using symbolic links.'
                        );
                    } catch (IOException $e) {
                        if (!$input->getOption('relative')) {
                            $this->_hardCopy($originDir, $targetDir);
                            $output->writeln(
                                'It looks like your system doesn\'t support ' .
                                'symbolic links, so the assets were installed ' .
                                'by copying them.'
                            );
                        }

                        // try again without the relative option
                        try {
                            $filesystem->symlink($originDir, $targetDir);
                            if (!file_exists($targetDir)) {
                                throw new IOException('Symbolic link is broken');
                            }
                            $output->writeln(
                                'It looks like your system doesn\'t support ' .
                                'relative symbolic links, so the assets were ' .
                                'installed by using absolute symbolic links.'
                            );
                        } catch (IOException $e) {
                            $this->_hardCopy($originDir, $targetDir);
                            $output->writeln(
                                'It looks like your system doesn\'t support ' .
                                'symbolic links, so the assets were installed ' .
                                'by copying them.'
                            );
                        }
                    }
                } else {
                    $this->_hardCopy($originDir, $targetDir);
                }
            }
        }
    }
protected function execute( InputInterface $input, OutputInterface $output )
    {
        $targetArg = rtrim($input->getArgument('target'), '/');

        if (!is_dir($targetArg)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'The target directory "%s" does not exist.',
                    $input->getArgument('target')
                )
            );
        }

        $filesystem = $this->getApplication()->getService('filesystem');

        // Create the bundles directory otherwise symlink will fail.
        $bundlesDir = $targetArg.'/assets/';
        $filesystem->mkdir($bundlesDir, 0777);

        // relative implies symlink
        $symlink = $input->getOption('symlink') || $input->getOption('relative');

        if ($symlink) {
            $output->writeln(
                'Trying to install assets as <comment>symbolic links</comment>.'
            );
        } else {
            $output->writeln(
                'Installing assets as <comment>hard copies</comment>.'
            );
        }

        $assetsConfig = $this->getContainer()['config']['assets'];
        $bundlesBaseDir = $assetsConfig['default_base_dir'];
        $publicPath = $assetsConfig['public_path'];

        foreach ($assetsConfig['resources_path'] as $bundle) {
            if (is_dir(
                $originDir = $bundlesBaseDir . DIRECTORY_SEPARATOR . $bundle .
                DIRECTORY_SEPARATOR . $publicPath
            )
                || is_dir($originDir = $bundle . DIRECTORY_SEPARATOR . $publicPath)
            ) {
                $targetDir = $bundlesDir . preg_replace(
                    '/assets$/', '', strtolower($bundle)
                );

                $output->writeln(
                    sprintf(
                        'Installing assets for <comment>%s</comment> into ' .
                        '<comment>%s</comment>', $bundle, $targetDir
                    )
                );

                $filesystem->remove($targetDir);

                if ($symlink) {
                    if ($input->getOption('relative')) {
                        $relativeOriginDir = $filesystem->makePathRelative(
                            $originDir, realpath($bundlesDir)
                        );
                    } else {
                        $relativeOriginDir = $originDir;
                    }

                    try {
                        $filesystem->symlink($relativeOriginDir, $targetDir);
                        if (!file_exists($targetDir)) {
                            throw new IOException('Symbolic link is broken');
                        }
                        $output->writeln(
                            'The assets were installed using symbolic links.'
                        );
                    } catch (IOException $e) {
                        if (!$input->getOption('relative')) {
                            $this->_hardCopy($originDir, $targetDir);
                            $output->writeln(
                                'It looks like your system doesn\'t support ' .
                                'symbolic links, so the assets were installed ' .
                                'by copying them.'
                            );
                        }

                        // try again without the relative option
                        try {
                            $filesystem->symlink($originDir, $targetDir);
                            if (!file_exists($targetDir)) {
                                throw new IOException('Symbolic link is broken');
                            }
                            $output->writeln(
                                'It looks like your system doesn\'t support ' .
                                'relative symbolic links, so the assets were ' .
                                'installed by using absolute symbolic links.'
                            );
                        } catch (IOException $e) {
                            $this->_hardCopy($originDir, $targetDir);
                            $output->writeln(
                                'It looks like your system doesn\'t support ' .
                                'symbolic links, so the assets were installed ' .
                                'by copying them.'
                            );
                        }
                    }
                } else {
                    $this->_hardCopy($originDir, $targetDir);
                }
            }
        }
    }
Executes command

@param InputInterface  $input  Command input
@param OutputInterface $output Console output

@return void