Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Protected Member Functions
GenerateDevUrnCommand Class Reference
Inheritance diagram for GenerateDevUrnCommand:

Protected Member Functions

 configure ()
 
 execute (InputInterface $input, OutputInterface $output)
 

Detailed Description

Definition at line 19 of file GenerateDevUrnCommand.php.

Member Function Documentation

◆ configure()

configure ( )
protected

Configures the current command.

Returns
void

Definition at line 26 of file GenerateDevUrnCommand.php.

27  {
28  $this->setName('generate:urn-catalog')
29  ->setDescription('This command generates an URN catalog to enable PHPStorm to recognize and highlight URNs.')
30  ->addArgument('path', InputArgument::REQUIRED, 'path to PHPStorm misc.xml file (typically located in [ProjectRoot]/.idea/misc.xml)')
31  ->addOption(
32  "force",
33  'f',
34  InputOption::VALUE_NONE,
35  'forces creation of misc.xml file if not found in the path given.'
36  );
37  }

◆ execute()

execute ( InputInterface  $input,
OutputInterface  $output 
)
protected

Executes the current command.

Parameters
InputInterface$input
OutputInterface$output
Returns
void
Exceptions

Definition at line 47 of file GenerateDevUrnCommand.php.

48  {
49  $miscXmlFilePath = $input->getArgument('path') . DIRECTORY_SEPARATOR . "misc.xml";
50  $miscXmlFile = realpath($miscXmlFilePath);
51  $force = $input->getOption('force');
52 
53  if ($miscXmlFile === false) {
54  if ($force == true) {
55  // create file and refresh realpath
56  $xml = "<project version=\"4\"/>";
57  file_put_contents($miscXmlFilePath, $xml);
58  $miscXmlFile = realpath($miscXmlFilePath);
59  } else {
60  $exceptionMessage = "misc.xml not found in given path '{$miscXmlFilePath}'";
61  LoggingUtil::getInstance()->getLogger(GenerateDevUrnCommand::class)
62  ->error($exceptionMessage);
63  throw new TestFrameworkException($exceptionMessage);
64  }
65  }
66  $dom = new \DOMDocument('1.0');
67  $dom->preserveWhiteSpace = false;
68  $dom->formatOutput = true;
69  $dom->loadXML(file_get_contents($miscXmlFile));
70 
71  //Locate ProjectResources node, create one if none are found.
72  $nodeForWork = null;
73  foreach($dom->getElementsByTagName('component') as $child) {
74  if ($child->getAttribute('name') === 'ProjectResources') {
75  $nodeForWork = $child;
76  }
77  }
78  if ($nodeForWork === null) {
79  $project = $dom->getElementsByTagName('project')->item(0);
80  $nodeForWork = $dom->createElement('component');
81  $nodeForWork->setAttribute('name', 'ProjectResources');
82  $project->appendChild($nodeForWork);
83  }
84 
85  //Extract url=>location mappings that already exist, add MFTF URNs and reappend
86  $resources = [];
87  $resourceNodes = $nodeForWork->getElementsByTagName('resource');
88  $resourceCount = $resourceNodes->length;
89  for ($i = 0; $i < $resourceCount; $i++) {
90  $child = $resourceNodes[0];
91  $resources[$child->getAttribute('url')] = $child->getAttribute('location');
92  $child->parentNode->removeChild($child);
93  }
94 
95  $resources = array_merge($resources, $this->generateResourcesArray());
96 
97  foreach ($resources as $url => $location) {
98  $resourceNode = $dom->createElement('resource');
99  $resourceNode->setAttribute('url', $url);
100  $resourceNode->setAttribute('location', $location);
101  $nodeForWork->appendChild($resourceNode);
102  }
103 
104  //Save output
105  $dom->save($miscXmlFile);
106  $output->writeln("MFTF URN mapping successfully added to {$miscXmlFile}.");
107  }
$i
Definition: gallery.phtml:31

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