Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup cores #18

Merged
merged 2 commits into from
Feb 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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