Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
ComplexParameter Class Reference

Public Member Functions

 __construct ($name, $pattern=self::DEFAULT_PATTERN)
 
 getFromArray ($input)
 
 getFromString ($string)
 
 mergeFromArgv ($server, array $into=[])
 

Data Fields

const DEFAULT_PATTERN = '/^\-\-%s=(.+)$/'
 

Detailed Description

A parser for complex parameters in command-line arguments

Transforms parameter formatted as a URL query string into an array

Definition at line 14 of file ComplexParameter.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $name,
  $pattern = self::DEFAULT_PATTERN 
)

Constructor

Parameters
string$name
string$pattern

Definition at line 41 of file ComplexParameter.php.

42  {
43  $this->name = $name;
44  $this->pcre = sprintf($pattern, preg_quote($name, '/'));
45  }
$pattern
Definition: website.php:22
if(!isset($_GET['name'])) $name
Definition: log.php:14

Member Function Documentation

◆ getFromArray()

getFromArray (   $input)

Searches and parses the value from an array of arguments

Parameters
string[]$input
Returns
array

Definition at line 53 of file ComplexParameter.php.

54  {
55  foreach ($input as $row) {
56  $result = $this->getFromString($row);
57  if ($result) {
58  return $result;
59  }
60  }
61  return [];
62  }

◆ getFromString()

getFromString (   $string)

Parses the value from a specified argument string

Parameters
string$string
Returns
array

Definition at line 70 of file ComplexParameter.php.

71  {
72  if (preg_match($this->pcre, $string, $matches)) {
73  parse_str($matches[1], $result);
74  return $result;
75  }
76  return [];
77  }

◆ mergeFromArgv()

mergeFromArgv (   $server,
array  $into = [] 
)

Searches the value parameter in an "argv" array and merges it recursively into specified array

Parameters
array$server
array$into
Returns
array

Definition at line 86 of file ComplexParameter.php.

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  }
$value
Definition: gender.phtml:16

Field Documentation

◆ DEFAULT_PATTERN

const DEFAULT_PATTERN = '/^\-\-%s=(.+)$/'

Default regex pattern for searching the parameter

Definition at line 19 of file ComplexParameter.php.


The documentation for this class was generated from the following file: