public function validate($schema = '')
    {
        $forced = $this->valid;
        $this->valid = true;

        try {
            switch ($this->sourceType) {
                case self::SOURCE_FILE:
                if (!file_exists($this->source)) {
                        throw new Exception("File " . $this->source . " not found.");
                    }
                    if (!is_readable($this->source)) {
                        throw new Exception("Unable to read file " . $this->source);
                    }
                    if (!preg_match("/\.zip$/", basename($this->source))) {
                        throw new Exception("Wrong file extension in " . $this->source . ", zip extension is expected");
                    }
                    if (!tao_helpers_File::securityCheck($this->source)) {
                        throw new Exception($this->source . " seems to contain some security issues");
                    }
                    break;

                case self::SOURCE_FLYFILE:
                    /** @var File $this->source */
                    if (! $this->source->exists()) {
                        throw new Exception('Source file does not exists ("' . $this->source->getBasename() . '").');
                    }
                    if (!preg_match("/\.zip$/", $this->source->getBasename())) {
                        throw new Exception('Wrong file extension in ' . $this->source->getBasename() . ', zip extension is expected.');
                    }
                    if (! $this->content = $this->source->read()) {
                        throw new Exception('Unable to read file ("' . $this->source->getBasename() . '").');
                    }
                    break;

                default:
                    throw new Exception("File cannot be handled by package parser.");
                    break;
            }
        } catch (Exception $e) {
            if ($forced) {
                throw $e;
            } else {
                $this->addError($e);
            }
        }

        if ($this->valid && !$forced) {
            $this->valid = false;
            $this->valid = $this->isValidArchive();
        }

        return $this->valid;
    }
public function validate($schema = '')
    {
        $forced = $this->valid;
        $this->valid = true;

        try {
            switch ($this->sourceType) {
                case self::SOURCE_FILE:
                if (!file_exists($this->source)) {
                        throw new Exception("File " . $this->source . " not found.");
                    }
                    if (!is_readable($this->source)) {
                        throw new Exception("Unable to read file " . $this->source);
                    }
                    if (!preg_match("/\.zip$/", basename($this->source))) {
                        throw new Exception("Wrong file extension in " . $this->source . ", zip extension is expected");
                    }
                    if (!tao_helpers_File::securityCheck($this->source)) {
                        throw new Exception($this->source . " seems to contain some security issues");
                    }
                    break;

                case self::SOURCE_FLYFILE:
                    /** @var File $this->source */
                    if (! $this->source->exists()) {
                        throw new Exception('Source file does not exists ("' . $this->source->getBasename() . '").');
                    }
                    if (!preg_match("/\.zip$/", $this->source->getBasename())) {
                        throw new Exception('Wrong file extension in ' . $this->source->getBasename() . ', zip extension is expected.');
                    }
                    if (! $this->content = $this->source->read()) {
                        throw new Exception('Unable to read file ("' . $this->source->getBasename() . '").');
                    }
                    break;

                default:
                    throw new Exception("File cannot be handled by package parser.");
                    break;
            }
        } catch (Exception $e) {
            if ($forced) {
                throw $e;
            } else {
                $this->addError($e);
            }
        }

        if ($this->valid && !$forced) {
            $this->valid = false;
            $this->valid = $this->isValidArchive();
        }

        return $this->valid;
    }
public function validate ( $ schema = '' ) { $ forced = $ this -> valid ; $ this -> valid = true ; try { switch ( $ this -> sourceType ) { case self :: SOURCE_FILE : if ( ! file_exists ( $ this -> source ) ) { throw new Exception ( "File " . $ this -> source . " not found." ) ; } if ( ! is_readable ( $ this -> source ) ) { throw new Exception ( "Unable to read file " . $ this -> source ) ; } if ( ! preg_match ( "/\.zip$/" , basename ( $ this -> source ) ) ) { throw new Exception ( "Wrong file extension in " . $ this -> source . ", zip extension is expected" ) ; } if ( ! tao_helpers_File :: securityCheck ( $ this -> source ) ) { throw new Exception ( $ this -> source . " seems to contain some security issues" ) ; } break ; case self :: SOURCE_FLYFILE : /** @var File $this->source */ if ( ! $ this -> source -> exists ( ) ) { throw new Exception ( 'Source file does not exists ("' . $ this -> source -> getBasename ( ) . '").' ) ; } if ( ! preg_match ( "/\.zip$/" , $ this -> source -> getBasename ( ) ) ) { throw new Exception ( 'Wrong file extension in ' . $ this -> source -> getBasename ( ) . ', zip extension is expected.' ) ; } if ( ! $ this -> content = $ this -> source -> read ( ) ) { throw new Exception ( 'Unable to read file ("' . $ this -> source -> getBasename ( ) . '").' ) ; } break ; default : throw new Exception ( "File cannot be handled by package parser." ) ; break ; } } catch ( Exception $ e ) { if ( $ forced ) { throw $ e ; } else { $ this -> addError ( $ e ) ; } } if ( $ this -> valid && ! $ forced ) { $ this -> valid = false ; $ this -> valid = $ this -> isValidArchive ( ) ; } return $ this -> valid ; }
Validate the zip archive. Local and remote file are allowed.
- Check if file is found
- Check content is not empty
- Check extension as zip
- In case of local, check path security
- Then validate archive

@param string $schema
@return bool
@throws Exception
Validate the zip archive . Local and remote file are allowed . - Check if file is found - Check content is not empty - Check extension as zip - In case of local check path security - Then validate archive