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;
 }
 protected function doClean($value)
 {
     $yamlparser = new ForgeYamlParser($value);
     $errors = array();
     if (!$yamlparser->get('stable')) {
         $errors[] = new sfValidatorError($this, 'No stable Git tag found');
     }
     if (!$yamlparser->get('stable')) {
         $errors[] = new sfValidatorError($this, 'No stable Git tag found');
     }
     if (!$yamlparser->get('category') || TermPeer::retrieveCategoryByTitle($yamlparser->get('category'))) {
         $errors[] = new sfValidatorError($this, 'No category provided, or category not found.');
     }
     if (!$yamlparser->get('tags')) {
         $errors[] = new sfValidatorError($this, 'No tags provided.');
     }
     if (!empty($errors)) {
         throw new sfValidatorErrorSchema($this, array($this->getOption('yaml_field') => $errors));
     }
     return $value;
 }
示例#3
0
 /**
  * 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());
     }
 }
示例#4
0
 /**
  * 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());
     }
 }