Ejemplo n.º 1
0
 /**
  * Try to load/generate source class to check if it is valid or not.
  *
  * @param string $className
  * @param \Magento\Framework\Code\Generator\EntityAbstract $generator
  * @return void
  * @throws \Magento\Framework\Exception
  */
 protected function tryToLoadSourceClass($className, $generator)
 {
     $sourceClassName = $generator->getSourceClassName();
     if (!$this->definedClasses->classLoadable($sourceClassName)) {
         if ($this->generateClass($sourceClassName) !== self::GENERATION_SUCCESS) {
             throw new \Magento\Framework\Exception(sprintf('Source class "%s" for "%s" generation does not exist.', $sourceClassName, $className));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Perform validation surrounding source and result classes and entity type
  *
  * @param string $resultEntityType
  * @param string $sourceClassName
  * @param string $resultClass
  * @return string|bool
  */
 protected function shouldSkipGeneration($resultEntityType, $sourceClassName, $resultClass)
 {
     if (!$resultEntityType || !$sourceClassName) {
         return self::GENERATION_ERROR;
     } else {
         if ($this->definedClasses->isClassLoadableFromDisc($resultClass)) {
             return self::GENERATION_SKIP;
         } else {
             if (!isset($this->_generatedEntities[$resultEntityType])) {
                 throw new \InvalidArgumentException('Unknown generation entity.');
             }
         }
     }
     return false;
 }
 /**
  * Perform validation surrounding source and result classes and entity type
  *
  * @param string $resultEntityType
  * @param string $sourceClassName
  * @param string $resultClass
  * @return string|bool
  */
 protected function shouldSkipGeneration($resultEntityType, $sourceClassName, $resultClass)
 {
     if (!$resultEntityType || !$sourceClassName) {
         return self::GENERATION_ERROR;
     } else {
         if ($this->definedClasses->isClassLoadableFromDisc($resultClass)) {
             $generatedFileName = $this->_ioObject->generateResultFileName($resultClass);
             /**
              * Must handle two edge cases: a competing process has generated the class and written it to disc already,
              * or the class exists in committed code, despite matching pattern to be generated.
              */
             if ($this->_ioObject->fileExists($generatedFileName) && !$this->definedClasses->isClassLoadableFromMemory($resultClass)) {
                 $this->_ioObject->includeFile($generatedFileName);
             }
             return self::GENERATION_SKIP;
         } else {
             if (!isset($this->_generatedEntities[$resultEntityType])) {
                 throw new \InvalidArgumentException('Unknown generation entity.');
             }
         }
     }
     return false;
 }
Ejemplo n.º 4
0
 public function testClassNotLoadable()
 {
     $this->assertFalse($this->model->isClassLoadable('Class\\Does\\Not\\Exist'));
 }