Skip to content

Commit

Permalink
Merge pull request #18 from jhedstrom/core-cleanup
Browse files Browse the repository at this point in the history
Cleanup cores
  • Loading branch information
jhedstrom committed Feb 26, 2015
2 parents 86472f8 + 5f5f756 commit 44d5e03
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 80 deletions.
5 changes: 5 additions & 0 deletions spec/Drupal/Driver/Cores/Drupal8Spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ function it_is_initializable()
{
$this->shouldHaveType('Drupal\Driver\Cores\Drupal8');
}

function it_should_return_a_random_generator()
{
$this->getRandom()->shouldBeAnInstanceOf('Drupal\Component\Utility\Random');
}
}
41 changes: 41 additions & 0 deletions src/Drupal/Driver/Cores/AbstractCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,51 @@

namespace Drupal\Driver\Cores;

use Drupal\Component\Utility\Random;
use Symfony\Component\DependencyInjection\Container;

abstract class AbstractCore implements CoreInterface {

/**
* System path to the Drupal installation.
*
* @var string
*/
private $drupalRoot;

/**
* URI for the Drupal installation.
*
* @var string
*/
private $uri;

/**
* Random generator.
*
* @var \Drupal\Component\Utility\Random
*/
private $random;

/**
* {@inheritDoc}
*/
public function __construct($drupalRoot, $uri = 'default', Random $random = NULL) {
$this->drupalRoot = realpath($drupalRoot);
$this->uri = $uri;
if (!isset($random)) {
$random = new Random();
}
$this->random = $random;
}

/**
* {@inheritDoc}
*/
public function getRandom() {
return $this->random;
}

/**
* {@inheritDoc}
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Drupal/Driver/Cores/CoreInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Drupal core interface.
*/
interface CoreInterface {

/**
* Instantiate the core interface.
*
Expand All @@ -19,7 +20,7 @@ interface CoreInterface {
* @param \Drupal\Component\Utility\Random $random
* Random string generator.
*/
public function __construct($drupalRoot, $uri = 'default', Random $random);
public function __construct($drupalRoot, $uri = 'default', Random $random = NULL);

/**
* Return random generator.
Expand Down
40 changes: 0 additions & 40 deletions src/Drupal/Driver/Cores/Drupal7.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,11 @@

use Drupal\Component\Utility\Random;
use Drupal\Driver\Exception\BootstrapException;
use Symfony\Component\DependencyInjection\Container;

/**
* Drupal 7 core.
*/
class Drupal7 extends AbstractCore {
/**
* System path to the Drupal installation.
*
* @var string
*/
private $drupalRoot;

/**
* URI for the Drupal installation.
*
* @var string
*/
private $uri;

/**
* Random generator.
*
* @var \Drupal\Component\Utility\Random
*/
private $random;

/**
* {@inheritDoc}
*/
public function __construct($drupalRoot, $uri = 'default', Random $random = NULL) {
$this->drupalRoot = realpath($drupalRoot);
$this->uri = $uri;
if (!isset($random)) {
$random = new Random();
}
$this->random = $random;
}

/**
* {@inheritDoc}
*/
public function getRandom() {
return $this->random;
}

/**
* {@inheritDoc}
Expand Down
39 changes: 0 additions & 39 deletions src/Drupal/Driver/Cores/Drupal8.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,6 @@
* Drupal 8 core.
*/
class Drupal8 extends AbstractCore {
/**
* System path to the Drupal installation.
*
* @var string
*/
private $drupalRoot;

/**
* URI for the Drupal installation.
*
* @var string
*/
private $uri;

/**
* Random generator.
*
* @var \Drupal\Component\Utility\Random
*/
private $random;

/**
* {@inheritDoc}
*/
public function __construct($drupalRoot, $uri = 'default', Random $random = NULL) {
$this->drupalRoot = realpath($drupalRoot);
$this->uri = $uri;
if (!isset($random)) {
$random = new Random();
}
$this->random = $random;
}

/**
* {@inheritDoc}
*/
public function getRandom() {
return $this->random;
}

/**
* {@inheritDoc}
Expand Down

0 comments on commit 44d5e03

Please sign in to comment.