public function checkModuleValidity(UploadedFile $file, ExecutionContextInterface $context)
    {
        $modulePath = $this->unzipModule($file);

        if ($modulePath !== false) {
            try {
                // get the first directory
                $moduleFiles = $this->getDirContents($modulePath);
                if (\count($moduleFiles['directories']) !== 1) {
                    throw new Exception(
                        Translator::getInstance()->trans(
                            "Your zip must contain 1 root directory which is the root folder directory of your module"
                        )
                    );
                }

                $moduleDirectory = $moduleFiles['directories'][0];

                $this->modulePath = sprintf('%s/%s', $modulePath, $moduleDirectory);

                $moduleValidator = new ModuleValidator($this->modulePath);

                $moduleValidator->validate();

                $this->moduleDefinition = $moduleValidator->getModuleDefinition();
            } catch (Exception $ex) {
                $context->addViolation(
                    Translator::getInstance()->trans(
                        "The module is not valid : %message",
                        ['%message' => $ex->getMessage()]
                    )
                );
            }
        }
    }
public function checkModuleValidity(UploadedFile $file, ExecutionContextInterface $context)
    {
        $modulePath = $this->unzipModule($file);

        if ($modulePath !== false) {
            try {
                // get the first directory
                $moduleFiles = $this->getDirContents($modulePath);
                if (\count($moduleFiles['directories']) !== 1) {
                    throw new Exception(
                        Translator::getInstance()->trans(
                            "Your zip must contain 1 root directory which is the root folder directory of your module"
                        )
                    );
                }

                $moduleDirectory = $moduleFiles['directories'][0];

                $this->modulePath = sprintf('%s/%s', $modulePath, $moduleDirectory);

                $moduleValidator = new ModuleValidator($this->modulePath);

                $moduleValidator->validate();

                $this->moduleDefinition = $moduleValidator->getModuleDefinition();
            } catch (Exception $ex) {
                $context->addViolation(
                    Translator::getInstance()->trans(
                        "The module is not valid : %message",
                        ['%message' => $ex->getMessage()]
                    )
                );
            }
        }
    }
public function checkModuleValidity ( UploadedFile $ file , ExecutionContextInterface $ context ) { $ modulePath = $ this -> unzipModule ( $ file ) ; if ( $ modulePath !== false ) { try { // get the first directory $ moduleFiles = $ this -> getDirContents ( $ modulePath ) ; if ( \ count ( $ moduleFiles [ 'directories' ] ) !== 1 ) { throw new Exception ( Translator :: getInstance ( ) -> trans ( "Your zip must contain 1 root directory which is the root folder directory of your module" ) ) ; } $ moduleDirectory = $ moduleFiles [ 'directories' ] [ 0 ] ; $ this -> modulePath = sprintf ( '%s/%s' , $ modulePath , $ moduleDirectory ) ; $ moduleValidator = new ModuleValidator ( $ this -> modulePath ) ; $ moduleValidator -> validate ( ) ; $ this -> moduleDefinition = $ moduleValidator -> getModuleDefinition ( ) ; } catch ( Exception $ ex ) { $ context -> addViolation ( Translator :: getInstance ( ) -> trans ( "The module is not valid : %message" , [ '%message' => $ ex -> getMessage ( ) ] ) ) ; } } }
Check module validity

@param UploadedFile              $file
@param ExecutionContextInterface $context
Check module validity