Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg-web committed Oct 24, 2016
1 parent 1e3ba21 commit 1893d5f
Show file tree
Hide file tree
Showing 39 changed files with 867 additions and 511 deletions.
43 changes: 43 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the OverblogThriftBundle package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

require_once __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php';

use SLLH\StyleCIBridge\ConfigBridge;
use Symfony\CS\Fixer\Contrib\HeaderCommentFixer;

$header = <<<EOF
This file is part of the OverblogThriftBundle package.
(c) Overblog <http://github.com/overblog/>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;

// PHP-CS-Fixer 1.x
if (method_exists('Symfony\CS\Fixer\Contrib\HeaderCommentFixer', 'getHeader')) {
HeaderCommentFixer::setHeader($header);
}

$config = ConfigBridge::create();

// PHP-CS-Fixer 2.x
if (method_exists($config, 'setRules')) {
$config->setRules(array_merge($config->getRules(), [
'header_comment' => ['header' => $header]
]));
}

return $config
->setUsingCache(true)
->fixers(array_merge($config->getFixers(), ['header_comment']))
;
7 changes: 7 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
preset: symfony
enabled:
- ordered_use
- short_array_syntax

disabled:
- unalign_equals
53 changes: 30 additions & 23 deletions Api/Extensions/BaseExtension.php
Original file line number Diff line number Diff line change
@@ -1,82 +1,87 @@
<?php

/*
* This file is part of the OverblogThriftBundle package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Symfony extension for Thrift Extension
* Symfony extension for Thrift Extension.
*
* @category Bundle
* @package InternalApi
*
* @author Vincent Bouzeran <[email protected]>
* @author Yannick Le Guédart <[email protected]>
* @copyright 2011 Overblog
*/

namespace Overblog\ThriftBundle\Api\Extensions;

use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Symfony extension for Thrift Extension
* Symfony extension for Thrift Extension.
*
* @category Bundle
* @package InternalApi
* @subpackage Base extension
*
* @author Vincent Bouzeran <[email protected]>
* @author Yannick Le Guédart <[email protected]>
*/

abstract class BaseExtension
{
/**
* Injected SF2 container
* Injected SF2 container.
*
* @var type
*/
protected $_container;

/**
* Thrift Factory
* Thrift Factory.
*
* @var type
*/
protected $factory;

/**
* Constructor
* Constructor.
*
* @param ContainerInterface $container
*/

public function __construct(ContainerInterface $container)
{
$this->_container = $container;
$this->factory = $container->get('thrift.factory');
}

/**
* Returns a service from the injected container
* Returns a service from the injected container.
*
* @param string $service
*
* @return mixed
*/

public function get($service)
{
return $this->_container->get($service);
}

/**
* Set a service to the injected container
* Set a service to the injected container.
*
* @param string $id, The service id
* @param mixed $service, The service
* @param string $id, The service id
* @param mixed $service, The service
*/

public function set($id, $service)
{
$this->_container->set($id, $service);
}

/**
* Returns a parameter from the injected container
* Returns a parameter from the injected container.
*
* @param string $name
*
Expand All @@ -88,13 +93,15 @@ public function getParameter($name)
}

/**
* Get instance of Thrift Model classes
* @param string $classe
* @param mixed $param
* Get instance of Thrift Model classes.
*
* @param string $class
* @param mixed $param
*
* @return mixed
*/
public function getInstance($classe, $param = null)
public function getInstance($class, $param = null)
{
return $this->factory->getInstance($classe, $param);
return $this->factory->getInstance($class, $param);
}
}
47 changes: 28 additions & 19 deletions CacheWarmer/ThriftCompileCacheWarmer.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
<?php

namespace Overblog\ThriftBundle\CacheWarmer;
/*
* This file is part of the OverblogThriftBundle package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\ClassLoader\ClassMapGenerator;
namespace Overblog\ThriftBundle\CacheWarmer;

use Overblog\ThriftBundle\Compiler\ThriftCompiler;
use Overblog\ThriftBundle\Exception\CompilerException;
use Symfony\Component\ClassLoader\ClassMapGenerator;
use Symfony\Component\Filesystem\Filesystem;

/**
* Generate Thrift model in cache warmer
* Generate Thrift model in cache warmer.
*
* @author Xavier HAUSHERR
*/

class ThriftCompileCacheWarmer
{
private $rootDir;
Expand All @@ -21,18 +29,19 @@ class ThriftCompileCacheWarmer
private $services;

/**
* Cache Suffix for thrift compiled files
* Cache Suffix for thrift compiled files.
*/
const CACHE_SUFFIX = 'thrift';

/**
* Register dependencies
* Register dependencies.
*
* @param string $cacheDir
* @param string $rootDir
* @param Array $path
* @param Array $services
* @param array $path
* @param array $services
*/
public function __construct($cacheDir, $rootDir, $path, Array $services)
public function __construct($cacheDir, $rootDir, $path, array $services)
{
$this->cacheDir = $cacheDir;
$this->rootDir = $rootDir;
Expand All @@ -41,10 +50,13 @@ public function __construct($cacheDir, $rootDir, $path, Array $services)
}

/**
* Return definition path
* Return definition path.
*
* @param string $definition
* @param string $definitionPath
*
* @throws \Exception
*
* @return string
*/
public function getDefinitionPath($definition, $definitionPath)
Expand All @@ -57,7 +69,7 @@ public function getDefinitionPath($definition, $definitionPath)
}

/**
* Compile Thrift Model
* Compile Thrift Model.
*/
public function compile()
{
Expand All @@ -66,8 +78,7 @@ public function compile()
$cacheDir = sprintf('%s/%s', $this->cacheDir, self::CACHE_SUFFIX);

// We compile for every Service
foreach($this->services as $config)
{
foreach ($this->services as $config) {
$definitionPath = $this->getDefinitionPath(
$config['definition'],
$config['definitionPath']
Expand All @@ -87,8 +98,7 @@ public function compile()
$compile = $compiler->compile($definitionPath, $config['server']);

// Compilation Error
if(false === $compile)
{
if (false === $compile) {
throw new \RuntimeException(
sprintf('Unable to compile Thrift definition %s.', $definitionPath),
0,
Expand All @@ -100,12 +110,11 @@ public function compile()
// Check if thrift cache directory exists
$fs = new Filesystem();

if(!$fs->exists($cacheDir))
{
if (!$fs->exists($cacheDir)) {
$fs->mkdir($cacheDir);
}

// Generate ClassMap
ClassMapGenerator::dump($cacheDir, sprintf('%s/classes.map', $cacheDir));
}
}
}
33 changes: 22 additions & 11 deletions Client/Client.php
Original file line number Diff line number Diff line change
@@ -1,54 +1,65 @@
<?php

/*
* This file is part of the OverblogThriftBundle package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Overblog\ThriftBundle\Client;

/**
* Abstract class for create a client
* Abstract class for create a client.
*
* @author Xavier HAUSHERR
*/

abstract class Client
{
/**
* Config handler
* Config handler.
*
* @var array
*/
protected $config;

/**
* Socket instance
* Socket instance.
*
* @var Thrift\Transport\TSocket
*/
protected $socket;

/**
* Register dependencies
* Register dependencies.
*
* @param array $config
*/
public function __construct(Array $config)
public function __construct(array $config)
{
$this->config = $config;
}

/**
* Return socket
* Return socket.
*
* @return Thrift\Transport\TSocket
*/
public function getSocket()
{
if(is_null($this->socket))
{
if (is_null($this->socket)) {
$this->socket = $this->createSocket();
}

return $this->socket;
}

/**
* Insctanciate socket
* Insctanciate socket.
*
* @return Thrift\Transport\TSocket
*/
abstract protected function createSocket();
}
}
Loading

0 comments on commit 1893d5f

Please sign in to comment.