protected function doClean($value)
 {
     $mdparser = new ForgeMDParser($value);
     $errors = array();
     if (!$mdparser->getTitle()) {
         $errors[] = new sfValidatorError($this, 'No title found');
     }
     if (!$mdparser->getSection('how-to-use')) {
         $errors[] = new sfValidatorError($this, 'No "How to Use" section found.');
     }
     if (!$mdparser->getSection('description')) {
         $errors[] = new sfValidatorError($this, 'No description found.');
     }
     if (!empty($errors)) {
         throw new sfValidatorErrorSchema($this, array($this->getOption('readme_field') => $errors));
     }
     return $value;
 }
 protected function doClean($values)
 {
     if (is_null($values)) {
         $values = array();
     }
     if (!is_array($values)) {
         throw new InvalidArgumentException('You must pass an array parameter to the clean() method');
     }
     $errors = array();
     # Access repository
     $forge = ForgeGitHubFactory::fetch($values['url']);
     try {
         $forge->initialize($values['url']);
         if ($forge->getReadme()) {
             $mdparser = new ForgeMDParser($forge->getReadme());
         }
         if ($forge->getYaml()) {
             $yaml = new ForgeYamlParser($forge->getYaml());
         }
         $values = $values + array('title' => $yaml->get('name'), 'username' => $yaml->get('author'), 'docsurl' => $yaml->get('docs'), 'demourl' => $yaml->get('demo'), 'githubuser' => $forge->getUser(), 'githubrepo' => $forge->getProject(), 'howtouse' => $mdparser->getSection('how-to-use'), 'screenshot' => $mdparser->getScreenshot(), 'description' => $mdparser->getDescription(), 'tags' => $yaml->get('tags'), 'category' => $yaml->get('category'), 'stabletag' => $yaml->get('current'), 'gitTags' => $forge->getTags(), 'arbitrarySections' => $mdparser->getArbitrarySections(), 'screenshots' => $mdparser->getScreenshots());
     } catch (ForgeException $e) {
         $errors[] = new sfValidatorError($this, $e->getMessage());
     }
     if (!empty($errors)) {
         throw new sfValidatorErrorSchema($this, $errors);
     }
     return $values;
 }
 /**
  * Step 5
  *
  * @author Guillermo Rauch
  **/
 public function executeAdd5(sfWebRequest $request)
 {
     if ($request->isMethod('post')) {
         $addid = $request->getParameter('addid');
         $this->checkStep(4, $addid);
         $gitPath = $this->getUser()->getAttribute('github.path', '', 'plugin.add.' . $addid);
         $gitTags = $this->getUser()->getAttribute('github.tags', array(), 'plugin.add.' . $addid);
         $readme = new ForgeMDParser(file_get_contents($gitPath . '/README.md'));
         $manifest = new ForgeYamlParser(file_get_contents($gitPath . '/package.yml'));
         $params = array('author' => $manifest->get('author'), 'arbitrarySections' => $readme->getArbitrarySections(), 'stabletag' => $manifest->get('current'), 'screenshots' => $readme->getScreenshots(), 'category' => $manifest->get('category'), 'tags' => $manifest->get('tags'), 'gitTags' => $gitTags, 'title' => $manifest->get('name'), 'screenshot' => $readme->getScreenshot(), 'docsurl' => $manifest->get('docs'), 'demourl' => $manifest->get('demo'), 'howtouse' => $readme->getSection('how-to-use'), 'description' => $readme->getDescription());
         $form = new PluginAddStep5Form();
         $form->bind($params);
         if ($form->isValid()) {
             $this->getUser()->setAttribute('step', 5, 'plugin.add.' . $addid);
             $this->getUser()->setAttribute('github.params', $form->getValues(), 'plugin.add.' . $addid);
             return $this->renderJson(array('success' => true, 'status' => 'Verifying JS files'));
         }
         return $this->renderJson($form->toJson());
     }
 }
 /**
  * Step 5
  *
  * @author Guillermo Rauch
  **/
 public function executeAdd5(sfWebRequest $request)
 {
     if ($request->isMethod('post')) {
         $addid = $request->getParameter('addid');
         $this->checkStep(4, $addid);
         $this->getUser()->getAttributeHolder()->getNames();
         $user = $this->getUser()->getAttribute('github.user', null, 'plugin.add.' . $addid);
         $repository = $this->getUser()->getAttribute('github.repository', null, 'plugin.add.' . $addid);
         // the validator just checks if files are in the repos. Because github changed
         // everything with version 3 this needs a complete rewrite.
         if (substr_count($repository, '.git') > 0) {
             $repository = substr($repository, 0, strrpos($repository, '.'));
         }
         $gitPath = '/repos/' . $user . '/' . $repository . '/contents';
         $gitTags = $this->getUser()->getAttribute('github.tags', array(), 'plugin.add.' . $addid);
         $readme = json_decode(GitHubFetcher::fetchContent($gitPath . '/README.md'));
         $readme = new ForgeMDParser(base64_decode(@$readme->content));
         $manifest = json_decode(GitHubFetcher::fetchContent($gitPath . '/package.yml'));
         $manifest = new ForgeYamlParser(base64_decode(@$manifest->content));
         $params = array('author' => $manifest->get('author'), 'arbitrarySections' => $readme->getArbitrarySections(), 'stabletag' => $manifest->get('current'), 'screenshots' => $readme->getScreenshots(), 'category' => $manifest->get('category'), 'tags' => $manifest->get('tags'), 'gitTags' => $gitTags, 'title' => $manifest->get('name'), 'screenshot' => $readme->getScreenshot(), 'docsurl' => $manifest->get('docs'), 'demourl' => $manifest->get('demo'), 'howtouse' => $readme->getSection('how-to-use'), 'description' => $readme->getDescription());
         $form = new PluginAddStep5Form();
         $form->bind($params);
         if ($form->isValid()) {
             $this->getUser()->setAttribute('step', 5, 'plugin.add.' . $addid);
             $this->getUser()->setAttribute('github.params', $form->getValues(), 'plugin.add.' . $addid);
             return $this->renderJson(array('success' => true, 'status' => 'Verifying JS files'));
         }
         return $this->renderJson($form->toJson());
     }
 }