Skip to content

Commit

Permalink
Merge pull request #2 from Xety/rename-methods
Browse files Browse the repository at this point in the history
Rename the all config methods with the `Config` suffix to avoid conflict names
  • Loading branch information
Emeric authored Jun 2, 2017
2 parents 9624dce + 4014daa commit cf3f7f5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 52 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MyClass extends Configurator
}
```

You can also setup a default configuration if you want:
If you want to setup a default configuration for your class, just do the following :
```php
<?php
class MyClass extends Configurator
Expand All @@ -50,11 +50,11 @@ class MyClass extends Configurator

| Name | Description |
|------|-------------|
|[set](#configuratorset)|Set the values to the options array.|
|[get](#configuratorget)|Get all the options with their values.|
|[flush](#configuratorflush)|Flush a list of options from the config array.|
|[merge](#configuratormerge)|Merge the values to the options array.|
|[clear](#configuratorclear)|Clear all options stored.|
|[setConfig](#configuratorsetconfig)|Set the values to the options array.|
|[getConfig](#configuratorgetconfig)|Get all the options with their values.|
|[flushConfig](#configuratorflushconfig)|Flush a list of options from the config array.|
|[mergeConfig](#configuratormergeconfig)|Merge the values to the options array.|
|[clearConfig](#configuratorclearconfig)|Clear all options stored.|
|[setOption](#configuratorsetoption)|Set a value to the given option.|
|[getOption](#configuratorgetoption)|Get an option value.|
|[hasOption](#configuratorhasoption)|Check if the option exist.|
Expand All @@ -67,9 +67,9 @@ class MyClass extends Configurator



### Configurator::set
### Configurator::setConfig
```php
public set (array $values)
public setConfig (array $values)
```

**Description**
Expand All @@ -89,9 +89,9 @@ This function will replace all the configuration options.



### Configurator::get
### Configurator::getConfig
```php
public get (void)
public getConfig (void)
```

**Description**
Expand All @@ -112,9 +112,9 @@ Get all the options with their values.



### Configurator::flush
### Configurator::flushConfig
```php
public flush (string ...$filter)
public flushConfig (string ...$filter)
```

**Description**
Expand All @@ -123,7 +123,7 @@ Flush a list of options from the options array.

Usage:
```php
$this->flush('key1', 'key2', 'key3');
$this->flushConfig('key1', 'key2', 'key3');
```

**Parameters**
Expand All @@ -138,9 +138,9 @@ $this->flush('key1', 'key2', 'key3');



### Configurator::merge
### Configurator::mergeConfig
```php
public merge (array $values, bool $invert = false)
public mergeConfig (array $values, bool $invert = false)
```

**Description**
Expand All @@ -161,9 +161,9 @@ Merge the values to the options array.



### Configurator::clear
### Configurator::clearConfig
```php
public clear (void)
public clearConfig (void)
```

**Description**
Expand Down
12 changes: 6 additions & 6 deletions src/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class Configurator implements ConfiguratorInterface, ConfiguratorOption
*
* @return \Xety\Configurator\Configurator
*/
public function set(array $values): Configurator
public function setConfig(array $values): Configurator
{
$this->config = $values;

Expand All @@ -39,7 +39,7 @@ public function set(array $values): Configurator
*
* @return array
*/
public function get(): array
public function getConfig(): array
{
return $this->config;
}
Expand All @@ -52,7 +52,7 @@ public function get(): array
*
* @return \Xety\Configurator\Configurator
*/
public function merge(array $values, bool $invert = false): Configurator
public function mergeConfig(array $values, bool $invert = false): Configurator
{
$this->config = ($invert) ? array_merge($values, $this->config) : array_merge($this->config, $values);

Expand All @@ -71,7 +71,7 @@ public function merge(array $values, bool $invert = false): Configurator
*
* @return \Xety\Configurator\Configurator
*/
public function flush(string ...$filter): Configurator
public function flushConfig(string ...$filter): Configurator
{
$filter = array_flip($filter);
$this->config = array_diff_key($this->config, $filter);
Expand All @@ -84,7 +84,7 @@ public function flush(string ...$filter): Configurator
*
* @return \Xety\Configurator\Configurator
*/
public function clear(): Configurator
public function clearConfig(): Configurator
{
$this->config = [];

Expand Down Expand Up @@ -270,7 +270,7 @@ public function transientOption(string $name, $value): Configurator
{
$this->validateName($name);

return $this->merge([$name => $value]);
return $this->mergeConfig([$name => $value]);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Interfaces/ConfiguratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ interface ConfiguratorInterface
*
* @param array $values The values to push into the config.
*/
public function set(array $values);
public function setConfig(array $values);

/**
* Get all the options.
*
* @return array
*/
public function get();
public function getConfig();

/**
* Merge the values to the options array, or the current options in
Expand All @@ -25,12 +25,12 @@ public function get();
* @param array $values The values to merge in the config.
* @param bool $invert Invert the merge by merging the actual config into the values.
*/
public function merge(array $values, bool $invert);
public function mergeConfig(array $values, bool $invert);

/**
* Flush a list of options from the config array.
*
* @param string ...$filter List of options to remove from the options array.
*/
public function flush(string ...$filter);
public function flushConfig(string ...$filter);
}
50 changes: 25 additions & 25 deletions tests/ConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public function testSet()
]
];

$result = $this->configurator->set($options);
$result = $this->configurator->setConfig($options);

$this->assertSame($options, $result->get());
$this->assertSame($options, $result->getConfig());
}

/**
Expand All @@ -57,7 +57,7 @@ public function testSetOption()
];

$result = $this->configurator->setOption('foo', 'bar');
$this->assertSame($options, $result->get());
$this->assertSame($options, $result->getConfig());

$options = [
'foo' => [
Expand All @@ -66,11 +66,11 @@ public function testSetOption()
];

$this->configurator->setOption('foo', ['bar' => 'bez']);
$this->assertSame($options, $this->configurator->get());
$this->assertSame($options, $this->configurator->getConfig());

$this->configurator->setOption('foo', 'bar');
$this->configurator->setOption('foo', 'bar2');
$this->assertSame(['foo' => 'bar2'], $this->configurator->get());
$this->assertSame(['foo' => 'bar2'], $this->configurator->getConfig());
}

/**
Expand Down Expand Up @@ -112,15 +112,15 @@ public function testMerge()
],
'par' => 'dar'
];
$result = $this->configurator->set($options);
$result = $this->configurator->setConfig($options);

$merge = [
'foo' => 'bar2',
'baz' => [
'ter'
]
];
$this->configurator->merge($merge);
$this->configurator->mergeConfig($merge);

$expected = [
'foo' => 'bar2',
Expand All @@ -129,7 +129,7 @@ public function testMerge()
],
'par' => 'dar'
];
$this->assertSame($expected, $this->configurator->get());
$this->assertSame($expected, $this->configurator->getConfig());
}

/**
Expand All @@ -148,7 +148,7 @@ public function testMergeWithInvert()
'far'
]
];
$result = $this->configurator->set($options);
$result = $this->configurator->setConfig($options);

$merge = [
'foo' => 'bar2',
Expand All @@ -157,7 +157,7 @@ public function testMergeWithInvert()
],
'par' => 'dar'
];
$this->configurator->merge($merge, true);
$this->configurator->mergeConfig($merge, true);

$expected = [
'foo' => 'bar',
Expand All @@ -169,7 +169,7 @@ public function testMergeWithInvert()
],
'par' => 'dar'
];
$this->assertSame($expected, $this->configurator->get());
$this->assertSame($expected, $this->configurator->getConfig());
}

/**
Expand All @@ -191,7 +191,7 @@ public function testConsumeOption()
],
'par' => 'dar'
];
$this->configurator->set($options);
$this->configurator->setConfig($options);

$result = $this->configurator->consumeOption('foo');
$this->assertSame('bar', $result);
Expand All @@ -212,7 +212,7 @@ public function testConsumeOption()
$expected = [
'par' => 'dar'
];
$this->assertSame($expected, $this->configurator->get());
$this->assertSame($expected, $this->configurator->getConfig());
}

/**
Expand All @@ -222,7 +222,7 @@ public function testConsumeOption()
*/
public function testConsumeOptionDoesNotExist()
{
$this->configurator->set(['foo' => 'bar']);
$this->configurator->setConfig(['foo' => 'bar']);
$this->assertNull($this->configurator->consumeOption('unknown'));
}

Expand All @@ -244,9 +244,9 @@ public function testFlush()
],
'par' => 'dar'
];
$this->configurator->set($options);
$result = $this->configurator->flush('foo', 'baz');
$this->assertSame(['par' => 'dar'], $result->get());
$this->configurator->setConfig($options);
$result = $this->configurator->flushConfig('foo', 'baz');
$this->assertSame(['par' => 'dar'], $result->getConfig());
}

/**
Expand All @@ -267,9 +267,9 @@ public function testClear()
],
'par' => 'dar'
];
$this->configurator->set($options);
$result = $this->configurator->clear();
$this->assertSame([], $result->get());
$this->configurator->setConfig($options);
$result = $this->configurator->clearConfig();
$this->assertSame([], $result->getConfig());
}

/**
Expand All @@ -288,7 +288,7 @@ public function testPushOption()
]
]
];
$this->configurator->set($options);
$this->configurator->setConfig($options);

$class = new \stdClass();

Expand All @@ -311,7 +311,7 @@ public function testPushOption()
'class' => $class
]
];
$this->assertSame($expected, $result->get());
$this->assertSame($expected, $result->getConfig());
}

/**
Expand All @@ -337,7 +337,7 @@ public function testTransientOption()
'foo' => 'bar',
'par' => 'tor'
];
$this->configurator->set($options);
$this->configurator->setConfig($options);

$result = $this->configurator->transientOption('tor', 'bar');

Expand All @@ -346,7 +346,7 @@ public function testTransientOption()
'par' => 'tor',
'tor' => 'bar'
];
$this->assertSame($expected, $result->get());
$this->assertSame($expected, $result->getConfig());

$result = $this->configurator->transientOption('foo', 'bar2');

Expand All @@ -355,7 +355,7 @@ public function testTransientOption()
'par' => 'tor',
'tor' => 'bar'
];
$this->assertSame($expected, $result->get());
$this->assertSame($expected, $result->getConfig());
}

/**
Expand Down

0 comments on commit cf3f7f5

Please sign in to comment.