Skip to content
This repository has been archived by the owner on Dec 27, 2018. It is now read-only.

Commit

Permalink
Merge e099101 into 3d2d21b
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Aug 30, 2016
2 parents 3d2d21b + e099101 commit 1f2df8e
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 122 deletions.
54 changes: 31 additions & 23 deletions src/Options.php → src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
use Dflydev\DotAccessData\Data;

/**
* Class Options.
* Class Config.
*/
class Options
class Config
{
/**
* Options.
* Config.
*
* @var Data
*/
protected $options;
protected $data;
/**
* Source directory.
*
Expand All @@ -34,11 +34,11 @@ class Options
*/
protected $destinationDir;
/**
* Default options.
* Default data.
*
* @var array
*/
protected static $defaultOptions = [
protected static $defaultData = [
'site' => [
'title' => 'PHPoole',
'baseline' => 'A PHPoole website',
Expand Down Expand Up @@ -91,59 +91,59 @@ class Options
];

/**
* Options constructor.
* Config constructor.
*
* @param Options|array|null $options
* @param Config|array|null $config
*/
public function __construct($options = null)
public function __construct($config = null)
{
$data = new Data(self::$defaultOptions);
if ($options instanceof self) {
$data->importData($options->getAll());
} elseif (is_array($options)) {
$data->import($options);
$data = new Data(self::$defaultData);
if ($config instanceof self) {
$data->importData($config->getAll());
} elseif (is_array($config)) {
$data->import($config);
}
$this->setFromData($data);
}

/**
* Set options.
* Set config data.
*
* @param Data $data
*
* @return $this
*/
protected function setFromData(Data $data)
{
if ($this->options !== $data) {
$this->options = $data;
if ($this->data !== $data) {
$this->data = $data;
}

return $this;
}

/**
* Get options.
* Get config data.
*
* @return Data
*/
public function getAll()
{
return $this->options;
return $this->data;
}

/**
* Get options as array.
* Get data as array.
*
* @return array
*/
public function getAllAsArray()
{
return $this->options->export();
return $this->data->export();
}

/**
* return an option value.
* Return a config value.
*
* @param string $key
* @param string $default
Expand All @@ -152,10 +152,12 @@ public function getAllAsArray()
*/
public function get($key, $default = '')
{
return $this->options->get($key, $default);
return $this->data->get($key, $default);
}

/**
* Set source directory.
*
* @param null $sourceDir
*
* @throws \Exception
Expand All @@ -176,6 +178,8 @@ public function setSourceDir($sourceDir = null)
}

/**
* Get source directory.
*
* @return string
*/
public function getSourceDir()
Expand All @@ -184,6 +188,8 @@ public function getSourceDir()
}

/**
* Set destination directory.
*
* @param null $destinationDir
*
* @throws \Exception
Expand All @@ -204,6 +210,8 @@ public function setDestinationDir($destinationDir = null)
}

/**
* Get destination directory.
*
* @return string
*/
public function getDestinationDir()
Expand Down
8 changes: 4 additions & 4 deletions src/Generator/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
*/
class Alias implements GeneratorInterface
{
/* @var \PHPoole\Options */
protected $options;
/* @var \PHPoole\Config */
protected $config;

/**
* {@inheritdoc}
*/
public function __construct(\PHPoole\Options $options)
public function __construct(\PHPoole\Config $config)
{
$this->options = $options;
$this->config = $config;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Generator/ExternalBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
*/
class ExternalBody implements GeneratorInterface
{
/* @var \PHPoole\Options */
protected $options;
/* @var \PHPoole\Config */
protected $config;

/**
* {@inheritdoc}
*/
public function __construct(\PHPoole\Options $options)
public function __construct(\PHPoole\Config $config)
{
$this->options = $options;
$this->config = $config;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Generator/GeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
interface GeneratorInterface
{
/**
* Give Options to object.
* Give config to object.
*
* @param \PHPoole\Options $options
* @param \PHPoole\Config $config
*
* @return void
*/
public function __construct(\PHPoole\Options $options);
public function __construct(\PHPoole\Config $config);

/**
* @param \PHPoole\Page\Collection $pageCollection
Expand Down
12 changes: 6 additions & 6 deletions src/Generator/Homepage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace PHPoole\Generator;

use PHPoole\Options;
use PHPoole\Config;
use PHPoole\Page\Collection as PageCollection;
use PHPoole\Page\NodeType;
use PHPoole\Page\Page;
Expand All @@ -18,15 +18,15 @@
*/
class Homepage implements GeneratorInterface
{
/* @var \PHPoole\Options */
protected $options;
/* @var \PHPoole\Config */
protected $config;

/**
* {@inheritdoc}
*/
public function __construct(\PHPoole\Options $options)
public function __construct(\PHPoole\Config $config)
{
$this->options = $options;
$this->config = $config;
}

/**
Expand All @@ -39,7 +39,7 @@ public function generate(PageCollection $pageCollection, \Closure $messageCallba
if (!$pageCollection->has('index')) {
$filteredPages = $pageCollection->filter(function (Page $page) {
return $page->getNodeType() === null
&& $page->getSection() == $this->options->get('site.paginate.homepage.section')
&& $page->getSection() == $this->config->get('site.paginate.homepage.section')
&& !empty($page->getBody());
});
$pages = $filteredPages->sortByDate()->toArray();
Expand Down
12 changes: 6 additions & 6 deletions src/Generator/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace PHPoole\Generator;

use PHPoole\Options;
use PHPoole\Config;
use PHPoole\Page\Collection as PageCollection;
use PHPoole\Page\NodeType;
use PHPoole\Page\Page;
Expand All @@ -18,15 +18,15 @@
*/
class Pagination implements GeneratorInterface
{
/* @var \PHPoole\Options */
protected $options;
/* @var \PHPoole\Config */
protected $config;

/**
* {@inheritdoc}
*/
public function __construct(\PHPoole\Options $options)
public function __construct(\PHPoole\Config $config)
{
$this->options = $options;
$this->config = $config;
}

/**
Expand All @@ -42,7 +42,7 @@ public function generate(PageCollection $pageCollection, \Closure $messageCallba

/* @var $page Page */
foreach ($filteredPages as $page) {
$paginate = $this->options->get('site.paginate');
$paginate = $this->config->get('site.paginate');

$disabled = array_key_exists('disabled', $paginate) && $paginate['disabled'];
if ($disabled) {
Expand Down
8 changes: 4 additions & 4 deletions src/Generator/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
*/
class Section implements GeneratorInterface
{
/* @var \PHPoole\Options */
protected $options;
/* @var \PHPoole\Config */
protected $config;

/**
* {@inheritdoc}
*/
public function __construct(\PHPoole\Options $options)
public function __construct(\PHPoole\Config $config)
{
$this->options = $options;
$this->config = $config;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Generator/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/
class Taxonomy implements GeneratorInterface
{
/* @var \PHPoole\Options */
protected $options;
/* @var \PHPoole\Config */
protected $config;
/* @var TaxonomyCollection */
protected $taxonomies;
/* @var PageCollection */
Expand All @@ -34,9 +34,9 @@ class Taxonomy implements GeneratorInterface
/**
* {@inheritdoc}
*/
public function __construct(\PHPoole\Options $options)
public function __construct(\PHPoole\Config $config)
{
$this->options = $options;
$this->config = $config;
}

/**
Expand All @@ -47,8 +47,8 @@ public function generate(PageCollection $pageCollection, \Closure $messageCallba
$this->pageCollection = $pageCollection;
$this->generatedPages = new PageCollection();

if (array_key_exists('taxonomies', $this->options->get('site'))) {
$this->siteTaxonomies = $this->options->get('site.taxonomies');
if (array_key_exists('taxonomies', $this->config->get('site'))) {
$this->siteTaxonomies = $this->config->get('site.taxonomies');

// is taxonomies disabled
if (array_key_exists('disabled', $this->siteTaxonomies) && $this->siteTaxonomies['disabled']) {
Expand Down
8 changes: 4 additions & 4 deletions src/Generator/TitleReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
*/
class TitleReplace implements GeneratorInterface
{
/* @var \PHPoole\Options */
protected $options;
/* @var \PHPoole\Config */
protected $config;

/**
* {@inheritdoc}
*/
public function __construct(\PHPoole\Options $options)
public function __construct(\PHPoole\Config $config)
{
$this->options = $options;
$this->config = $config;
}

/**
Expand Down
Loading

0 comments on commit 1f2df8e

Please sign in to comment.