Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ComplexParameter.php
Go to the documentation of this file.
1 <?php
8 
15 {
19  const DEFAULT_PATTERN = '/^\-\-%s=(.+)$/';
20 
26  private $name;
27 
33  private $pcre;
34 
41  public function __construct($name, $pattern = self::DEFAULT_PATTERN)
42  {
43  $this->name = $name;
44  $this->pcre = sprintf($pattern, preg_quote($name, '/'));
45  }
46 
53  public function getFromArray($input)
54  {
55  foreach ($input as $row) {
56  $result = $this->getFromString($row);
57  if ($result) {
58  return $result;
59  }
60  }
61  return [];
62  }
63 
70  public function getFromString($string)
71  {
72  if (preg_match($this->pcre, $string, $matches)) {
73  parse_str($matches[1], $result);
74  return $result;
75  }
76  return [];
77  }
78 
86  public function mergeFromArgv($server, array $into = [])
87  {
88  $result = $into;
89  if (isset($server['argv'])) {
90  $value = $this->getFromArray($server['argv']);
91  $result = array_replace_recursive($into, $value);
92  }
93  return $result;
94  }
95 }
$pattern
Definition: website.php:22
__construct($name, $pattern=self::DEFAULT_PATTERN)
$value
Definition: gender.phtml:16