Skip to content

Commit

Permalink
simplify dir structure and namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
alcohol committed Oct 19, 2016
1 parent bf0a825 commit 9b6c58a
Show file tree
Hide file tree
Showing 25 changed files with 101 additions and 103 deletions.
23 changes: 20 additions & 3 deletions bin/satis
@@ -1,9 +1,26 @@
#!/usr/bin/env php
<?php

require __DIR__.'/../src/bootstrap.php';
/*
* This file is part of composer/satis.
*
* (c) Composer <https://github.com/composer>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

use Composer\Satis\Console\Application;
function includeIfExists($file)
{
if (file_exists($file)) {
return include $file;
}
}

$application = new Application();
if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__.'/../../../autoload.php'))) {
print('You must set up the project dependencies using Composer before you can use Satis.');
exit(1);
}

$application = new Composer\Satis\Console\Application();
$application->run();
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -25,10 +25,10 @@
"symfony/console": "^2.1 || ^3.0.4"
},
"autoload": {
"psr-0": { "Composer\\Satis": "src/" }
"psr-4": { "Composer\\Satis\\": "src" }
},
"autoload-dev": {
"psr-0": { "Composer\\Test\\Satis": "tests/" }
"psr-4": { "Composer\\Satis\\": "tests" }
},
"require-dev": {
"phpunit/phpunit": "^4.5 || ^5.0.5",
Expand Down
30 changes: 15 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions phpunit.xml.dist
Expand Up @@ -3,19 +3,19 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.6/phpunit.xsd"
backupGlobals="false"
bootstrap="tests/bootstrap.php"
bootstrap="vendor/autoload.php"
colors="true"
>

<testsuites>
<testsuite name="Satis Test Suite">
<directory>./tests/Composer/</directory>
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src/Composer/</directory>
<directory>src</directory>
</whitelist>
</filter>

Expand Down
Expand Up @@ -37,35 +37,27 @@ class ArchiveBuilder extends Builder
public function dump(array $packages)
{
$helper = new ArchiveBuilderHelper($this->output, $this->config['archive']);

$directory = $helper->getDirectory($this->outputDir);

$this->output->writeln(sprintf("<info>Creating local downloads in '%s'</info>", $directory));

$basedir = $helper->getDirectory($this->outputDir);
$this->output->writeln(sprintf("<info>Creating local downloads in '%s'</info>", $basedir));
$format = isset($this->config['archive']['format']) ? $this->config['archive']['format'] : 'zip';
$endpoint = isset($this->config['archive']['prefix-url']) ? $this->config['archive']['prefix-url'] : $this->config['homepage'];

$includeArchiveChecksum = isset($this->config['archive']['checksum']) ? (bool) $this->config['archive']['checksum'] : true;

$composerConfig = $this->composer->getConfig();
$factory = new Factory();

/* @var \Composer\Downloader\DownloadManager $downloadManager */
$downloadManager = $this->composer->getDownloadManager();

/* @var \Composer\Package\Archiver\ArchiveManager $archiveManager */
$archiveManager = $factory->createArchiveManager($composerConfig, $downloadManager);

$archiveManager->setOverwriteFiles(false);

shuffle($packages);

$progressBar = null;
$hasStarted = false;
$verbosity = $this->output->getVerbosity();
$isStats = $this->input->getOption('stats') && OutputInterface::VERBOSITY_NORMAL == $verbosity;
$renderProgress = $this->input->getOption('stats') && OutputInterface::VERBOSITY_NORMAL == $verbosity;

if ($isStats) {
if ($renderProgress) {
$packageCount = 0;

foreach ($packages as $package) {
Expand All @@ -76,8 +68,7 @@ public function dump(array $packages)

$progressBar = new ProgressBar($this->output, $packageCount);
$progressBar->setFormat(
' %current%/%max% [%bar%] %percent:3s%% - '
. "Installing %packageName% (%packageVersion%)"
' %current%/%max% [%bar%] %percent:3s%% - Installing %packageName% (%packageVersion%)'
);
}

Expand All @@ -87,7 +78,7 @@ public function dump(array $packages)
continue;
}

if ($isStats) {
if ($renderProgress) {
$progressBar->setMessage($package->getName(), 'packageName');
$progressBar->setMessage($package->getPrettyVersion(), 'packageVersion');

Expand All @@ -102,33 +93,37 @@ public function dump(array $packages)
}

try {
if ($isStats) {
if ($renderProgress) {
$this->output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
}

if ('pear-library' === $package->getType()) {
// PEAR packages are archives already
$filesystem = new Filesystem();
$packageName = $archiveManager->getPackageFilename($package);
$path =
realpath($directory).'/'.$packageName.'.'.
pathinfo($package->getDistUrl(), PATHINFO_EXTENSION);
$path = sprintf(
'%s/%s.%s',
realpath($basedir),
$packageName,
pathinfo($package->getDistUrl(), PATHINFO_EXTENSION))
;

if (!file_exists($path)) {
$downloadDir = sys_get_temp_dir().'/composer_archiver/'.$packageName;
$filesystem->ensureDirectoryExists($downloadDir);

$downloadManager->download($package, $downloadDir, false);

$filesystem->ensureDirectoryExists($directory);
$filesystem->ensureDirectoryExists($basedir);
$filesystem->rename($downloadDir.'/'.pathinfo($package->getDistUrl(), PATHINFO_BASENAME), $path);
$filesystem->removeDirectory($downloadDir);
}

// Set archive format to `file` to tell composer to download it as is
$archiveFormat = 'file';
} else {
$path = $archiveManager->archive($package, $format, $directory);
$path = $archiveManager->archive($package, $format, $basedir);
$archiveFormat = $format;
}

$archive = basename($path);
$distUrl = sprintf('%s/%s/%s', $endpoint, $this->config['archive']['directory'], $archive);
$package->setDistType($archiveFormat);
Expand All @@ -140,11 +135,11 @@ public function dump(array $packages)

$package->setDistReference($package->getSourceReference());

if ($isStats) {
if ($renderProgress) {
$this->output->setVerbosity($verbosity);
}
} catch (\Exception $exception) {
if ($isStats) {
if ($renderProgress) {
$this->output->setVerbosity($verbosity);
}

Expand All @@ -154,12 +149,12 @@ public function dump(array $packages)
$this->output->writeln(sprintf("<error>Skipping Exception '%s'.</error>", $exception->getMessage()));
}

if ($isStats) {
if ($renderProgress) {
$progressBar->advance();
}
}

if ($isStats) {
if ($renderProgress) {
$progressBar->clear();
$this->output->writeln('');
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -164,6 +164,9 @@ private function dumpPackageIncludeJson(array $packages, $includesUrl, $hashAlgo
*
* @param string $path
* @param string $contents
*
* @throws \UnexpectedValueException
* @throws \Exception
*/
private function writeToFile($path, $contents)
{
Expand Down
Expand Up @@ -95,15 +95,15 @@ public function setTwigEnvironment(\Twig_Environment $twig)
* Gets the twig environment.
*
* Creates default if needed.
*
*
* @return \Twig_Environment
*/
private function getTwigEnvironment()
{
if (null === $this->twig) {
$twigTemplate = isset($this->config['twig-template']) ? $this->config['twig-template'] : null;

$templateDir = $twigTemplate ? pathinfo($twigTemplate, PATHINFO_DIRNAME) : __DIR__.'/../../../../views';
$templateDir = $twigTemplate ? pathinfo($twigTemplate, PATHINFO_DIRNAME) : __DIR__.'/../../views';
$loader = new \Twig_Loader_Filesystem($templateDir);
$this->twig = new \Twig_Environment($loader);
}
Expand Down
Expand Up @@ -15,7 +15,7 @@
use Composer\Factory;
use Composer\IO\ConsoleIO;
use Composer\IO\IOInterface;
use Composer\Satis\Command;
use Composer\Satis\Console\Command;
use Composer\Satis\Satis;
use Composer\Util\ErrorHandler;
use Symfony\Component\Console\Application as BaseApplication;
Expand All @@ -29,6 +29,7 @@ class Application extends BaseApplication
{
/** @var IOInterface */
protected $io;

/** @var Composer */
protected $composer;

Expand Down
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Composer\Satis\Command;
namespace Composer\Satis\Console\Command;

use Composer\Factory;
use Composer\IO\NullIO;
Expand Down
Expand Up @@ -9,7 +9,7 @@
* the LICENSE file that was distributed with this source code.
*/

namespace Composer\Satis\Command;
namespace Composer\Satis\Console\Command;

use Composer\Command\BaseCommand;
use Composer\Config;
Expand Down Expand Up @@ -281,7 +281,7 @@ private function check($configFile)

$data = json_decode($content);

$schemaFile = __DIR__.'/../../../../res/satis-schema.json';
$schemaFile = __DIR__ . '/../../../res/satis-schema.json';
$schema = json_decode(file_get_contents($schemaFile));
$validator = new Validator();
$validator->check($data, $schema);
Expand Down
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Composer\Satis\Command;
namespace Composer\Satis\Console\Command;

use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
Expand Up @@ -9,7 +9,7 @@
* the LICENSE file that was distributed with this source code.
*/

namespace Composer\Satis\Command;
namespace Composer\Satis\Console\Command;

use Composer\Command\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 9b6c58a

Please sign in to comment.