Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Anahkiasen committed Jun 24, 2016
2 parents 3e35b11 + ce092b5 commit dbcade2
Show file tree
Hide file tree
Showing 38 changed files with 1,348 additions and 1,024 deletions.
3 changes: 0 additions & 3 deletions .bowerrc

This file was deleted.

19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
root = true

[**]
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true

[composer.json]
indent_style = tab

[*.yml]
indent_style = space

[package.json]
indent_style = space
indent_size = 2
58 changes: 37 additions & 21 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
<?php
use Symfony\CS\Config\Config;
use Symfony\CS\Finder\DefaultFinder;
use Symfony\CS\FixerInterface;
use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = DefaultFinder::create()->in(['app', 'tests/unit/Semver']);
require 'vendor/autoload.php';

$finder = Finder::create()->in([
'app',
'tests',
]);

return Config::create()
->level(FixerInterface::SYMFONY_LEVEL)
->fixers([
'ereg_to_preg',
'multiline_spaces_before_semicolon',
'newline_after_open_tag',
'no_blank_lines_before_namespace',
'ordered_use',
'php4_constructor',
'phpdoc_order',
'-phpdoc_params',
'short_array_syntax',
'short_echo_tag',
'strict',
'strict_param',
])
->setUsingCache(true)
->finder($finder);
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'align_double_arrow' => false,
'align_equals' => false,
'concat_with_spaces' => false,
'ereg_to_preg' => true,
'header_comment' => false,
'linebreak_after_opening_tag' => true,
'long_array_syntax' => false,
'no_blank_lines_before_namespace' => false,
'no_multiline_whitespace_before_semicolons' => true,
'no_php4_constructor' => true,
'no_short_echo_tag' => true,
'no_useless_return' => true,
'not_operator_with_space' => false,
'not_operator_with_successor_space' => false,
'ordered_imports' => true,
'php_unit_construct' => true,
'php_unit_strict' => false,
'phpdoc_order' => true,
'phpdoc_property' => true,
'phpdoc_var_to_type' => false,
'psr0' => true,
'short_array_syntax' => true,
'strict_comparison' => true,
'strict_param' => true,
])
->finder($finder);
36 changes: 21 additions & 15 deletions app/Semver/Application.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?php

namespace Semver;

use League\Container\ContainerInterface;
use League\Container\ServiceProvider;
use League\Container\Container;
use League\Container\ReflectionContainer;
use League\Container\ServiceProvider\AbstractServiceProvider;
use League\Route\Dispatcher;
use League\Route\RouteCollection;
use Symfony\Component\HttpFoundation\Request;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response;
use Zend\Diactoros\Response\SapiEmitter;

class Application
{
/**
* @var ContainerInterface
* @var Container
*/
private $container;

Expand All @@ -29,11 +33,12 @@ class Application
];

/**
* @param ContainerInterface $container
* @param Container $container
*/
public function __construct(ContainerInterface $container)
public function __construct(Container $container)
{
$this->container = $container;
$this->container->delegate(new ReflectionContainer());

$this->setupProviders();
}
Expand All @@ -43,14 +48,15 @@ public function __construct(ContainerInterface $container)
*/
public function run()
{
/** @var Dispatcher $dispatcher */
/* @type Request $request */
$dispatcher = $this->container->get(RouteCollection::class)->getDispatcher();
$request = $this->container->get(Request::class);
/* @var Dispatcher $dispatcher */
/* @type ServerRequestInterface $request */
$request = $this->container->get(ServerRequestInterface::class);
$response = new Response();
$dispatcher = $this->container->get(RouteCollection::class);

$response = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo());
$response = $dispatcher->dispatch($request, $response);

$response->send();
(new SapiEmitter())->emit($response);
}

/**
Expand All @@ -59,18 +65,18 @@ public function run()
private function setupProviders()
{
foreach ($this->serviceProviders as &$serviceProvider) {
/** @var ServiceProvider $serviceProvider */
/** @var AbstractServiceProvider $serviceProvider */
$serviceProvider = new $serviceProvider();
$serviceProvider->setContainer($this->container);
}

// Register the service providers.
array_walk($this->serviceProviders, function (ServiceProvider $serviceProvider) {
array_walk($this->serviceProviders, function (AbstractServiceProvider $serviceProvider) {
$this->container->addServiceProvider($serviceProvider);
});

// Call the boot methods.
array_walk($this->serviceProviders, function (ServiceProvider $serviceProvider) {
array_walk($this->serviceProviders, function (AbstractServiceProvider $serviceProvider) {
if (method_exists($serviceProvider, 'boot')) {
$this->container->call([$serviceProvider, 'boot']);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Semver\Contracts\Repositories;

use Packagist\Api\Result\Package\Version;
Expand Down
1 change: 1 addition & 0 deletions app/Semver/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Semver\Http\Controllers;

use League\Plates\Engine;
Expand Down
23 changes: 12 additions & 11 deletions app/Semver/Http/Controllers/PackageController.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
<?php

namespace Semver\Http\Controllers;

use Composer\Package\BasePackage;
use Psr\Http\Message\ServerRequestInterface;
use Semver\Services\Packagist\Packagist;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use UnexpectedValueException;
use Zend\Diactoros\Response\JsonResponse;

class PackageController
{
/**
* @var Request
* @var Packagist
*/
private $request;
private $packagist;

/**
* @var Packagist
* @var ServerRequestInterface
*/
private $packagist;
private $request;

/**
* @param Packagist $packagist
* @param Request $request
* @param Packagist $packagist
* @param ServerRequestInterface $request
*/
public function __construct(Packagist $packagist, Request $request)
public function __construct(Packagist $packagist, ServerRequestInterface $request)
{
$this->packagist = $packagist;
$this->request = $request;
Expand Down Expand Up @@ -55,7 +56,7 @@ public function matchVersions($vendor, $package)
{
$this->configureMinimumStability();

$constraint = $this->request->get('constraint', '*');
$constraint = $this->request->getAttribute('constraint', '*');
$versions = $this->packagist->getMatchingVersions($vendor, $package, $constraint);

return new JsonResponse($versions);
Expand All @@ -66,7 +67,7 @@ public function matchVersions($vendor, $package)
*/
protected function configureMinimumStability()
{
$minimumStability = $this->request->get('minimum-stability', 'stable');
$minimumStability = $this->request->getAttribute('minimum-stability', 'stable');
if (!in_array($minimumStability, array_keys(BasePackage::$stabilities), true)) {
throw new UnexpectedValueException(sprintf('Unsupported value for minimum-stability: %s', $minimumStability));
}
Expand Down
14 changes: 8 additions & 6 deletions app/Semver/Http/Support/RequestServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?php

namespace Semver\Http\Support;

use League\Container\ServiceProvider;
use Symfony\Component\HttpFoundation\Request;
use League\Container\ServiceProvider\AbstractServiceProvider;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\ServerRequestFactory;

class RequestServiceProvider extends ServiceProvider
class RequestServiceProvider extends AbstractServiceProvider
{
/**
* @var array
*/
protected $provides = [
Request::class,
ServerRequestInterface::class,
];

/**
Expand All @@ -19,8 +21,8 @@ class RequestServiceProvider extends ServiceProvider
public function register()
{
// Bind the Symfony request to the container.
$this->container->singleton(Request::class, function () {
return Request::createFromGlobals();
$this->container->share(ServerRequestInterface::class, function () {
return ServerRequestFactory::fromGlobals();
});
}
}
30 changes: 17 additions & 13 deletions app/Semver/Http/Support/RoutesServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

namespace Semver\Http\Support;

use League\Container\ServiceProvider;
use League\Container\ServiceProvider\AbstractServiceProvider;
use League\Route\RouteCollection;
use League\Route\Strategy\UriStrategy;
use League\Route\Strategy\ParamStrategy;

class RoutesServiceProvider extends ServiceProvider
class RoutesServiceProvider extends AbstractServiceProvider
{
/**
* @var array
Expand All @@ -15,14 +16,6 @@ class RoutesServiceProvider extends ServiceProvider
'routes.file',
];

/**
* @param RouteCollection $router
*/
public function boot(RouteCollection $router)
{
include $this->container->get('routes.file');
}

/**
* Register method,.
*/
Expand All @@ -33,11 +26,22 @@ public function register()
});

// Bind a route collection to the container.
$this->container->singleton(RouteCollection::class, function () {
$this->container->share(RouteCollection::class, function () {
$strategy = new ParamStrategy();
$strategy->setContainer($this->container);

$routes = new RouteCollection($this->container);
$routes->setStrategy(new UriStrategy());
$routes->setStrategy($strategy);

return $routes;
});
}

/**
* {@inheritdoc}
*/
public function boot(RouteCollection $router)
{
include $this->container->get('routes.file');
}
}
5 changes: 3 additions & 2 deletions app/Semver/Services/Cache/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

namespace Semver\Services\Cache;

use Illuminate\Cache\FileStore;
use Illuminate\Cache\Repository as IlluminateCache;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Filesystem\Filesystem;
use League\Container\ServiceProvider as BaseServiceProvider;
use League\Container\ServiceProvider\AbstractServiceProvider as BaseServiceProvider;

class ServiceProvider extends BaseServiceProvider
{
Expand All @@ -23,7 +24,7 @@ class ServiceProvider extends BaseServiceProvider
*/
public function register()
{
$this->container->singleton(Repository::class, function () {
$this->container->share(Repository::class, function () {
$store = new FileStore(new Filesystem(), $this->container->get('paths.cache'));

return new IlluminateCache($store);
Expand Down
6 changes: 4 additions & 2 deletions app/Semver/Services/Error/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

namespace Semver\Services\Error;

use ErrorException;
use Exception;
use League\Container\ServiceProvider as BaseServiceProvider;
use League\Container\ServiceProvider\AbstractServiceProvider as BaseServiceProvider;
use League\Container\ServiceProvider\BootableServiceProviderInterface;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run;

class ServiceProvider extends BaseServiceProvider
class ServiceProvider extends BaseServiceProvider implements BootableServiceProviderInterface
{
/**
* @var array
Expand Down
Loading

0 comments on commit dbcade2

Please sign in to comment.