Gregwar\Formidable\Form::parse PHP Method

parse() protected method

Parses the form contents to build objects
protected parse ( )
    protected function parse()
    {
        $formidable = $this;
        $generate = function () use($formidable) {
            // Parses the contents
            $parser = $formidable->getFactory()->getParser($formidable->getContent());
            $formidable->isCached = false;
            return $parser;
        };
        if ($this->cache) {
            $formInfos = array('path' => $this->path, 'content' => $this->content);
            $cacheFile = sha1(serialize($formInfos));
            $conditions = array();
            if ($this->path !== null) {
                $conditions['younger-than'] = $this->path;
            }
            $cacheData = $this->cache->getOrCreate($cacheFile, $conditions, function ($cacheFile) use($generate) {
                $parserData = $generate();
                file_put_contents($cacheFile, serialize($parserData));
            });
            $this->originalParserData = unserialize($cacheData);
        } else {
            $this->originalParserData = $generate();
        }
        $this->reset();
    }