Skip to content
This repository has been archived by the owner on Feb 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from hboomsma/feature/codestyle
Browse files Browse the repository at this point in the history
codestyle
  • Loading branch information
nicoschoenmaker committed Jan 27, 2016
2 parents d3abf5a + 08d3183 commit dd3df4a
Show file tree
Hide file tree
Showing 21 changed files with 147 additions and 119 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/vendor/
/cache/
/.buildpath
/.project
/.settings/
/composer.lock
/phpcs.xml
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@
},
"minimum-stability": "stable",
"autoload": {
"psr-0": {
"Hostnet\\HnDependencyInjectionPlugin": "src/"
"psr-4": {
"Hostnet\\HnDependencyInjectionPlugin\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Hostnet\\HnDependencyInjectionPlugin\\": "test/"
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@
namespace Hostnet\HnDependencyInjectionPlugin;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\TerminableInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\Config\ConfigCache as Symfony2ConfigCache;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Use this class as your superclass for your ApplicationConfiguration
Expand Down Expand Up @@ -61,8 +55,9 @@ public function getConfigCache()
public function handle(
Request $request,
$type = HttpKernelInterface::MASTER_REQUEST,
$catch = true)
{
$catch = true
) {

return $this->getKernel()->handle($request, $type, $catch);
}

Expand All @@ -77,8 +72,8 @@ public function getCLIApplication()
public function terminate(
Request $request,
Response $response
)
{
) {

return $this->getKernel()->terminate($request, $response);
}

Expand All @@ -96,7 +91,9 @@ private function getKernel()
throw new \RuntimeException(
sprintf(
'The kernel that was built should have been of CachedKernelInterface, got %s',
get_class($this->kernel)));
get_class($this->kernel)
)
);
}
}
return $this->kernel;
Expand All @@ -122,4 +119,4 @@ public function getContainer()
{
return $this->getKernel()->getContainer();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public function isOptional()
/**
* @see \Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface::warmUp()
*/
public function warmUp($cacheDir)
public function warmUp($cache_dir)
{
if ($this->configuration && ! \sfContext::hasInstance()) {
\sfContext::createInstance($this->configuration);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ interface CachedKernelInterface extends KernelInterface
* @return bool Whether the cache is still fresh
*/
public function isFresh();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ protected function get($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON
return $config->getContainer()->get($id, $invalid_behavior);
}
throw new \DomainException(
'Your app config should extend ApplicationConfiguration');
'Your app config should extend ApplicationConfiguration'
);
}
/**
* Shortcut to return the Doctrine Registry service.
Expand All @@ -58,6 +59,7 @@ protected function getParameter($name)
return $config->getContainer()->getParameter($name);
}
throw new \DomainException(
'Your app config should extend ApplicationConfiguration');
'Your app config should extend ApplicationConfiguration'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class ConfigCache extends \sfConfigCache
{

// @codingStandardsIgnoreStart
/**
* Constructor overridden to enforce stricter typing
*
Expand All @@ -21,6 +22,7 @@ public function __construct(ApplicationConfiguration $configuration)
{
parent::__construct($configuration);
}
// @codingStandardsIgnoreEnd

/**
* @see sfConfigCache::checkConfig()
Expand All @@ -42,10 +44,11 @@ private function writeDatabaseCache($config_path)
$handler = $this->createDatabaseHandler();
if (! ($handler instanceof HnDatabaseConfigHandler)) {
throw new \RuntimeException(
'Someone created a handler of incorrect type ' . get_class($handler));
'Someone created a handler of incorrect type ' . get_class($handler)
);
}
$full_path = \sfConfig::get('sf_root_dir') . '/' . $config_path;
$data = $handler->execute();
$data = $handler->execute();

$cache = $this->getCacheName($config_path);
$this->writeCacheFile($config_path, $cache, $data);
Expand All @@ -63,4 +66,4 @@ protected function createDatabaseHandler()
return new HnDatabaseConfigHandler($this->configuration->getContainer());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function onKernelResponse(FilterResponseEvent $event)
&& (!$event->getRequest()->isXmlHttpRequest()) // Prevent Ajax from creating another bar
) {
$this->url = $response_headers->get('x-debug-token-link');
$link = json_encode($response_headers->get('x-debug-token-link'));
$link = json_encode($response_headers->get('x-debug-token-link'));
echo <<<JAVASCRIPT
<script>
(function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private function getAlias(QueryBuilder $builder)
public function init()
{
$has_max_record_limit = ($this->getMaxRecordLimit() !== false);
$max_record_limit = $this->getMaxRecordLimit();
$max_record_limit = $this->getMaxRecordLimit();

$builder = $this->getNewQueryBuilder();
$builder->setFirstResult(0);
Expand All @@ -66,7 +66,9 @@ public function init()
throw new \RuntimeException(
sprintf(
'The indice [0][1] is supposed to have the count in it! %s',
json_encode($result)));
json_encode($result)
)
);
}
$count = $result[0][1];
$this->setNbResults($has_max_record_limit ? min($count, $max_record_limit) : $count);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<?php
namespace Hostnet\HnDependencyInjectionPlugin;

use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Symfony\Bridge\Doctrine\RegistryInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

/**
* Alternative for the \sfDatabaseConfigHandler, it reads the config in the
Expand Down Expand Up @@ -68,7 +63,7 @@ public function execute()
}
// compile data
return sprintf(
"<?php\n" . "// auto-generated by hnDatabaseConfigHandler\n// date: %s\n\n%s\n",
"<?php\n// auto-generated by hnDatabaseConfigHandler\n// date: %s\n\n%s\n",
date('Y/m/d H:i:s'),
$output
);
Expand Down Expand Up @@ -145,7 +140,6 @@ private function getPropelClass()
}

/**
* @todo make the mysql bit dynamic
* @param Connection $connection
*/
private function format11DSN(Connection $connection)
Expand Down Expand Up @@ -183,28 +177,25 @@ private function format11DSN(Connection $connection)
*/
private function getPropel12DriverName(Driver $driver)
{
switch($driver->getName()) {
switch ($driver->getName()) {
case 'pdo_mysql':
if (extension_loaded('mysql')) {
return 'mysql';
} elseif(extension_loaded('mysqli')) {
} elseif (extension_loaded('mysqli')) {
return 'mysqli';
} else {
throw new \RuntimeException('The mysql and mysqli extension both not loaded, need one of them.');
}
throw new \RuntimeException('The mysql and mysqli extension both not loaded, need one of them.');
case 'pdo_pgsql':
if (extension_loaded('pgsql')) {
return 'pgsql';
} else {
throw new \RuntimeException('The pgsql extension is not loaded.');
}
throw new \RuntimeException('The pgsql extension is not loaded.');
return 'pgsql';
case 'pdo_sqlite':
if (function_exists('sqlite_open')) {
return 'sqlite';
} else {
throw new \RuntimeException('The sqlite extension is not loaded.');
}
throw new \RuntimeException('The sqlite extension is not loaded.');
default:
throw new \DomainException(sprintf('Unknown driver "%s"', $driver->getName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,23 @@ public function fallbackToSymfony1()
$context = \sfContext::createInstance($configuration);
try {
$context->dispatch();
} catch(\sfError404Exception $e) {
} catch (\sfError404Exception $e) {
// The page was actually not found in sf1, wrap it up nicely
throw new NotFoundHttpException('Unable to match route in symfony1 fallback', $e);
} catch(\sfStopException $e) {
} catch (\sfStopException $e) {
return $this->createSymfony2Response($context);
}

$code = 0;
return $this->createSymfony2Response($context);
}

/**
* @param \sfContext context
* @return Response
*/
private function createSymfony2Response(\sfContext $context)
{
$code = 0;
$response = new Response();

if ($context->getResponse() instanceof \sfWebResponse) {
Expand All @@ -113,14 +123,18 @@ public function fallbackToSymfony1()
// properly, because this response is overwriting the sf1 response if the content of the body is less than
// 4kb large due to output buffering.
if (($code === 302 || $code === 304)) {
// @codingStandardsIgnoreStart
$response->setStatusCode($code, Response::$statusTexts[$code]);
// @codingStandardsIgnoreEnd
$response->headers->set('Location', $web_response->getHttpHeader('Location'));
}
}

// Symfony1 will usually send headers for us
// Check if found response code is a known sf2 response code
// @codingStandardsIgnoreStart
if (!isset(Response::$statusTexts[$code])) {
// @codingStandardsIgnoreEnd
// Lets keep sf2 busy with an empty response. For some ajax
// requests it doesn't give a valid code, but thats why the
// 200 status code.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
namespace Hostnet\HnDependencyInjectionPlugin;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\Kernel;

/**
Expand All @@ -32,14 +31,16 @@ class Symfony1Kernel extends Kernel implements CachedKernelInterface
public function __construct(\sfApplicationConfiguration $configuration)
{
$environment = \sfConfig::get('sf_environment');
$debug = in_array($environment,
$debug = in_array(
$environment,
array(
'dev',
'ontw',
'test'
));
parent::__construct($environment, $debug);
$this->configuration = $configuration;
)
);
parent::__construct($environment, $debug);
$this->configuration = $configuration;
}

public function getConfiguration()
Expand Down Expand Up @@ -114,12 +115,12 @@ protected function getContainerLoader(ContainerInterface $container)
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__ . '/config/services.yml');
if($this->isDebug()) {
if ($this->isDebug()) {
// Also add the debug services
$loader->load(__DIR__ . '/config/services_debug.yml');
}

$path = $this->getConfigDir();
$path = $this->getConfigDir();
$resource = 'config_' . $this->environment . '.yml';
if (! file_exists($path . '/' . $resource)) {
$resource = 'config.yml';
Expand All @@ -137,4 +138,4 @@ protected function buildContainer()
$this->is_fresh = false;
return parent::buildContainer();
}
}
}
File renamed without changes.
22 changes: 11 additions & 11 deletions test/ApplicationConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
use Hostnet\HnDependencyInjectionPlugin\ApplicationConfiguration;
namespace Hostnet\HnDependencyInjectionPlugin;

class ApplicationConfigurationTest extends PHPUnit_Framework_TestCase
class ApplicationConfigurationTest extends \PHPUnit_Framework_TestCase
{
public function testGetConfigCache()
{
$config = new ApplicationConfiguration('test', true);
$cache = $config->getConfigCache();
$this->assertInstanceOf('Hostnet\HnDependencyInjectionPlugin\ConfigCache', $cache);
public function testGetConfigCache()
{
$config = new ApplicationConfiguration('test', true);
$cache = $config->getConfigCache();
$this->assertInstanceOf('Hostnet\HnDependencyInjectionPlugin\ConfigCache', $cache);

// And only one is made
$this->assertTrue($cache === $config->getConfigCache());
}
}
// And only one is made
$this->assertTrue($cache === $config->getConfigCache());
}
}
Loading

0 comments on commit dd3df4a

Please sign in to comment.