Passed
Push — master ( 2c00e3...23ee15 )
by Aimeos
04:25 queued 01:06
created

Command::addConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2014-2016
6
 * @package symfony
7
 * @subpackage Command
8
 */
9
10
11
namespace Aimeos\ShopBundle\Command;
12
13
use Symfony\Component\Console\Command\Command as SfCommand;
14
use Symfony\Component\Console\Input\InputInterface;
15
16
17
18
/**
19
 * Abstract command class with common methods.
20
 *
21
 * @package symfony
22
 * @subpackage Command
23
 */
24
abstract class Command extends SfCommand
25
{
26
	/**
27
	 * Adds the configuration options from the input object to the given context
28
	 *
29
	 * @param \Aimeos\MShop\ContextIface $ctx Context object
30
	 * @param InputInterface $input Input object
31
	 */
32
	protected function addConfig( \Aimeos\MShop\ContextIface $ctx, InputInterface $input ) : \Aimeos\MShop\ContextIface
33
	{
34
		$config = $ctx->config();
35
36
		foreach( (array) $input->getOption( 'option' ) as $option )
37
		{
38
			list( $name, $value ) = explode( ':', $option );
39
			$config->set( $name, $value );
40
		}
41
42
		return $ctx;
43
	}
44
45
46
	/**
47
	 * Returns the enabled site items which may be limited by the input arguments.
48
	 *
49
	 * @param \Aimeos\MShop\ContextIface $context Context item object
50
	 * @param InputInterface $input Input object
51
	 * @return \Aimeos\Map List of site items implementing \Aimeos\MShop\Locale\Item\Site\Interface
52
	 */
53
	protected function getSiteItems( \Aimeos\MShop\ContextIface $context, InputInterface $input ) : \Aimeos\Map
54
	{
55
		$manager = \Aimeos\MShop::create( $context, 'locale/site' );
56
		$search = $manager->filter();
57
58
		if( ( $codes = (string) $input->getArgument( 'site' ) ) !== '' ) {
59
			$search->setConditions( $search->compare( '==', 'locale.site.code', explode( ' ', $codes ) ) );
60
		}
61
62
		return $manager->search( $search );
63
	}
64
}
65