Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GeneratedClassesAutoloader.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Framework\Code\Generator\Io;
10 
15 {
19  private $generatorIo;
20 
24  private $generators;
25 
30  public function __construct(array $generators, Io $generatorIo)
31  {
32  foreach ($generators as $generator) {
33  if (!($generator instanceof GeneratorInterface)) {
34  throw new \InvalidArgumentException(
35  sprintf(
36  "Instance of '%s' is expected, instance of '%s' is received",
37  \Magento\Framework\TestFramework\Unit\Autoloader\GeneratorInterface::class,
38  get_class($generator)
39  )
40  );
41  }
42  }
43  $this->generators = $generators;
44  $this->generatorIo = $generatorIo;
45  }
46 
53  public function load($className)
54  {
55  $classSourceFile = $this->generatorIo->generateResultFileName($className);
56  if ($this->generatorIo->fileExists($classSourceFile)) {
57  include $classSourceFile;
58  return true;
59  } else {
60  foreach ($this->generators as $generator) {
61  $content = $generator->generate($className);
62  if ($content) {
63  $this->generatorIo->makeResultFileDirectory($className);
64  $this->generatorIo->writeResultFile($classSourceFile, $content);
65  include $classSourceFile;
66  return true;
67  }
68  };
69  }
70 
71  return false;
72  }
73 }
$generatorIo
Definition: autoload.php:15
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31