コード例 #1
0
ファイル: Melody.php プロジェクト: TomzxForks/melody
 private function assertTrustedResource(Resource $resource, RunConfiguration $runConfiguration, UserConfiguration $userConfiguration)
 {
     if ($resource instanceof LocalResource || $runConfiguration->isTrusted() || in_array($resource->getMetadata()->getOwner(), $userConfiguration->getTrustedUsers()) || in_array($resource->getSignature(), $userConfiguration->getTrustedSignatures())) {
         return;
     }
     throw new TrustException($resource);
 }
コード例 #2
0
ファイル: Runner.php プロジェクト: ArthurHlt/melody
    private function getRemoteBootstrap(Resource $resource)
    {
        $template = <<<TEMPLATE
{{ head }}
?>{{ code }}

TEMPLATE;
        return strtr($template, array('{{ head }}' => $this->getHead(), '{{ code }}' => $resource->getContent()));
    }
コード例 #3
0
ファイル: ResourceParser.php プロジェクト: TomzxForks/melody
 public function parseResource(Resource $resource)
 {
     preg_match(self::MELODY_PATTERN, $resource->getContent(), $matches);
     if (!$matches) {
         throw new ParseException('Impossible to parse the content of the document.');
     }
     try {
         return Yaml::parse($matches['config']);
     } catch (YamlException $e) {
         throw new ParseException('The front matter is not a valid Yaml.', 0, $e);
     }
 }
コード例 #4
0
ファイル: RunCommand.php プロジェクト: TomzxForks/melody
    private function confirmTrust(Resource $resource, InputInterface $input, OutputInterface $output)
    {
        $dialog = $this->getHelperSet()->get('dialog');
        $message = <<<EOT
<comment>You are running an untrusted resource</comment>
  <info>URL:            </info> %s
  <info>Revision:       </info> #%d
  <info>Owner:          </info> %s
  <info>Created at:     </info> %s
  <info>Last update:    </info> %s

EOT;
        $output->writeln(sprintf($message, $resource->getMetadata()->getUri(), $resource->getMetadata()->getRevision(), $resource->getMetadata()->getOwner(), $resource->getMetadata()->getCreatedAt()->format(\DateTime::RSS), $resource->getMetadata()->getUpdatedAt()->format(\DateTime::RSS)));
        $actions = array('abort', 'continue', 'show-code');
        $defaultAction = 'abort';
        $actionLabels = array_map(function ($action) use($defaultAction) {
            if ($action === $defaultAction) {
                return sprintf('<%1$s>%2$s</%1$s>', 'default', $action);
            }
            return $action;
        }, $actions);
        $defaultStyle = clone $output->getFormatter()->getStyle('question');
        $defaultStyle->setOptions(array('reverse'));
        $output->getFormatter()->setStyle('default', $defaultStyle);
        $question = new Question(sprintf('<question>What do you want to do (%s)?</question> ', implode(', ', $actionLabels)), $defaultAction);
        $question->setAutocompleterValues($actions);
        $action = $this->getHelper('question')->ask($input, $output, $question);
        if ($action === 'show-code') {
            $output->writeln(PHP_EOL . $resource->getContent() . PHP_EOL);
            return $dialog->askConfirmation($output, '<question>Do you want to continue [y/N]?</question> ', false);
        }
        return $action === 'continue';
    }