|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016 |
|
6
|
|
|
* @package Slim |
|
7
|
|
|
* @subpackage Command |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Aimeos\Slim\Command; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Aimeos base command class |
|
15
|
|
|
* |
|
16
|
|
|
* @package Slim |
|
17
|
|
|
* @subpackage Command |
|
18
|
|
|
*/ |
|
19
|
|
|
class Base |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Returns the command options given by the user |
|
23
|
|
|
* |
|
24
|
|
|
* @param array &$params List of parameters |
|
25
|
|
|
* @return array Associative list of option name and value(s) |
|
26
|
|
|
*/ |
|
27
|
|
|
protected static function getOptions( array &$params ) : array |
|
28
|
|
|
{ |
|
29
|
|
|
$options = array(); |
|
30
|
|
|
|
|
31
|
|
|
foreach( $params as $key => $option ) |
|
32
|
|
|
{ |
|
33
|
|
|
if( $option === '--help' ) { |
|
34
|
|
|
throw new Exception(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if( strncmp( $option, '--', 2 ) === 0 && ( $pos = strpos( $option, '=', 2 ) ) !== false ) |
|
38
|
|
|
{ |
|
39
|
|
|
$name = substr( $option, 2, $pos - 2 ); |
|
40
|
|
|
|
|
41
|
|
|
if( isset( $options[$name] ) ) |
|
42
|
|
|
{ |
|
43
|
|
|
$options[$name] = (array) $options[$name]; |
|
44
|
|
|
$options[$name][] = substr( $option, $pos + 1 ); |
|
45
|
|
|
} |
|
46
|
|
|
else |
|
47
|
|
|
{ |
|
48
|
|
|
$options[$name] = substr( $option, $pos + 1 ); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
unset( $params[$key] ); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $options; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns the locale site items for the given site code string |
|
61
|
|
|
* |
|
62
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $ctx Context object |
|
63
|
|
|
* @param string|null $sites List of site codes separated by a space |
|
64
|
|
|
* @return \Aimeos\Map List of site items implementing \Aimeos\MShop\Locale\Item\Site\Interface |
|
65
|
|
|
*/ |
|
66
|
|
|
protected static function getSiteItems( \Aimeos\MShop\Context\Item\Iface $ctx, string $sites = null ) : \Aimeos\Map |
|
67
|
|
|
{ |
|
68
|
|
|
$manager = \Aimeos\MShop::create( $ctx, 'locale/site' ); |
|
69
|
|
|
$search = $manager->createSearch(); |
|
70
|
|
|
|
|
71
|
|
|
if( is_scalar( $sites ) && $sites != '' ) { |
|
72
|
|
|
$sites = explode( ' ', $sites ); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
if( !empty( $sites ) ) { |
|
76
|
|
|
$search->setConditions( $search->compare( '==', 'locale.site.code', $sites ) ); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return $manager->searchItems( $search ); |
|
80
|
|
|
} |
|
81
|
|
|
} |