Commit 37863755 authored by Sean Madsen's avatar Sean Madsen

format code to pass civilint

parent af957011
......@@ -2,6 +2,6 @@
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
class AppCache extends HttpCache
{
class AppCache extends HttpCache {
}
......@@ -3,68 +3,60 @@
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
];
class AppKernel extends Kernel {
public function registerBundles() {
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], TRUE)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
return $bundles;
}
public function getRootDir() {
return __DIR__;
}
public function getRootDir()
{
return __DIR__;
}
public function getCacheDir() {
return dirname(__DIR__) . '/var/cache/' . $this->getEnvironment();
}
public function getCacheDir()
{
return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
}
public function getLogDir() {
return dirname(__DIR__) . '/var/logs';
}
public function getLogDir()
{
return dirname(__DIR__).'/var/logs';
}
public function registerContainerConfiguration(LoaderInterface $loader) {
$loader->load($this->getRootDir() . '/config/config_' . $this->getEnvironment() . '.yml');
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
protected function buildContainer() {
$container = parent::buildContainer();
if ($container->hasParameter('mkdocs_path')) {
$_ENV['PATH'] = $container->getParameter('mkdocs_path')
. PATH_SEPARATOR . getenv('PATH');
putenv("PATH=" . $_ENV['PATH']);
}
protected function buildContainer()
{
$container = parent::buildContainer();
if ($container->hasParameter('mkdocs_path')) {
$_ENV['PATH'] = $container->getParameter('mkdocs_path')
. PATH_SEPARATOR . getenv('PATH');
putenv("PATH=" . $_ENV['PATH']);
}
if (!$container->hasParameter('publisher_repos_dir')) {
// This isn't really a good place to put it because it gets deleted
// whenever you clear the cache.
$container->setParameter('publisher_repos_dir',
$container->getParameter('kernel.cache_dir') . '/repos'
);
}
return $container;
if (!$container->hasParameter('publisher_repos_dir')) {
// This isn't really a good place to put it because it gets deleted
// whenever you clear the cache.
$container->setParameter('publisher_repos_dir', $container->getParameter('kernel.cache_dir') . '/repos'
);
}
return $container;
}
}
......@@ -6,7 +6,7 @@ use Composer\Autoload\ClassLoader;
/**
* @var ClassLoader $loader
*/
$loader = require __DIR__.'/../vendor/autoload.php';
$loader = require __DIR__ . '/../vendor/autoload.php';
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
......
......@@ -4,6 +4,5 @@ namespace AppBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AppBundle extends Bundle
{
class AppBundle extends Bundle {
}
......@@ -9,23 +9,19 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class DocsListCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('docs:list')
->setDescription('List available books');
}
class DocsListCommand extends ContainerAwareCommand {
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var \AppBundle\BookLoader $books */
$books = $this->getContainer()->get('book.loader');
$table = new Table($output);
$table->setHeaders(array('book', 'lang', 'repo', 'branch'));
$table->addRows($books->findAsList());
$table->render();
}
protected function configure() {
$this->setName('docs:list')->setDescription('List available books');
}
protected function execute(InputInterface $input, OutputInterface $output) {
/** @var \AppBundle\BookLoader $books */
$books = $this->getContainer()->get('book.loader');
$table = new Table($output);
$table->setHeaders(array('book', 'lang', 'repo', 'branch'));
$table->addRows($books->findAsList());
$table->render();
}
}
......@@ -8,47 +8,56 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class DocsPublishCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('docs:publish')
->setDescription('...')
->addArgument('paths', InputArgument::IS_ARRAY,
'One or more book expressions ("book/lang/branch"). (Default: all)');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var \AppBundle\BookLoader $books */
$books = $this->getContainer()->get('book.loader');
/** @var \AppBundle\Utils\Publisher $publisher */
$publisher = $this->getContainer()->get('publisher');
class DocsPublishCommand extends ContainerAwareCommand {
$rows = $books->findAsList();
protected function configure() {
$this
->setName('docs:publish')
->setDescription('...')
->addArgument(
'paths',
InputArgument::IS_ARRAY,
'One or more book expressions ("book/lang/branch"). (Default: all)');
}
if (empty($rows)) {
$output->writeln("<error>No books found</error>");
}
protected function execute(InputInterface $input, OutputInterface $output) {
/** @var \AppBundle\BookLoader $books */
$books = $this->getContainer()->get('book.loader');
$rowKeys = $input->getArgument('paths') ? $input->getArgument('paths') : array_keys($rows);
/** @var \AppBundle\Utils\Publisher $publisher */
$publisher = $this->getContainer()->get('publisher');
foreach ($rowKeys as $rowKey) {
$row = $rows[$rowKey];
$output->writeln("");
$output->writeln(sprintf("Publish [%s/%s/%s] (from %s)",
$row['book'], $row['lang'], $row['branch'], $row['repo']));
$rows = $books->findAsList();
$publisher->publish($row['book'], $row['lang'], $row['branch']);
if (empty($rows)) {
$output->writeln("<error>No books found</error>");
}
foreach ($publisher->getMessages() as $message) {
$output->writeln($message['label'] . ': ' . $message['content']);
}
$publisher->clearMessages();
if ($input->getArgument('paths')) {
$rowKeys = $input->getArgument('paths');
}
else {
$rowKeys = array_keys($rows);
}
}
foreach ($rowKeys as $rowKey) {
$row = $rows[$rowKey];
$output->writeln("");
$output->writeln(sprintf(
"Publish [%s/%s/%s] (from %s)",
$row['book'],
$row['lang'],
$row['branch'],
$row['repo'])
);
$publisher->publish($row['book'], $row['lang'], $row['branch']);
foreach ($publisher->getMessages() as $message) {
$output->writeln($message['label'] . ': ' . $message['content']);
}
$publisher->clearMessages();
}
}
}
......@@ -16,83 +16,93 @@ use Symfony\Component\Console\Output\OutputInterface;
* This is a dumb wrapper around `mkdocs serve`. It basically just cd's into the
* appropriate folder and then passes-through the args.
*/
class DocsServeCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('docs:serve')
->setDescription('Run the builtin docs development server')
->addOption('dev-addr', 'a', InputOption::VALUE_OPTIONAL,
'IP address and port to serve documentation')
->addOption('strict', 's', InputOption::VALUE_NONE,
'Enable strict mode. This will cause MkDocs to abort the build on any warnings.')
->addOption('theme', 't', InputOption::VALUE_OPTIONAL,
'The theme to use when building your documentation [cosmo|cyborg|readthedocs|yeti|journal|bootstrap|readable|united|simplex|flatly|spacelab|amelia|cerulean|slate|mkdocs')
->addOption('livereload', null, InputOption::VALUE_NONE,
'Enable the live reloading in the development server.')
->addOption('no-livereload', null, InputOption::VALUE_NONE,
'Enable the live reloading in the development server.')
->addOption('quiet', 'q', InputOption::VALUE_NONE,
'Silence warnings')// ->addOption('verbose', 'v', InputOption::VALUE_NONE, 'Enable verbose output')
->addArgument('[book/lang/[branch]]', InputArgument::REQUIRED,
'A book expression (e.g. "dev/en/master" or "user/fr/4.6"). The [book] and [lang] are mandatory. If [branch] is specified, it will be checked out.')
;
class DocsServeCommand extends ContainerAwareCommand {
protected function configure() {
$this->setName('docs:serve');
$this->setDescription('Run the builtin docs development server');
$this->addOption('dev-addr', 'a', InputOption::VALUE_OPTIONAL,
'IP address and port to serve documentation');
$this->addOption('strict', 's', InputOption::VALUE_NONE,
'Enable strict mode. This will cause MkDocs to abort the build on any'
. 'warnings.');
$this->addOption('theme', 't', InputOption::VALUE_OPTIONAL,
'The theme to use when building your documentation (e.g. readthedocs)');
$this->addOption('livereload', NULL, InputOption::VALUE_NONE,
'Enable the live reloading in the development server.');
$this->addOption('no-livereload', NULL, InputOption::VALUE_NONE,
'Disable the live reloading in the development server.');
$this->addOption('quiet', 'q', InputOption::VALUE_NONE,
'Silence warnings');
$this->addArgument('[book/lang/[branch]]', InputArgument::REQUIRED,
'A book expression (e.g. "dev/en/master" or "user/fr/4.6"). '
. 'The [book] and [lang] are mandatory. '
. 'If [branch] is specified, it will be checked out.');
}
protected function execute(InputInterface $input, OutputInterface $output) {
if (preg_match(';^(\w+)/(\w+)?$;', $input->getArgument('[book/lang/[branch]]'), $matches)) {
$book = $matches[1];
$lang = $matches[2];
$branch = NULL;
}
elseif (preg_match(';^(\w+)/(\w+)/(\w+)$;', $input->getArgument('[book/lang/[branch]]'), $matches)) {
$book = $matches[1];
$lang = $matches[2];
$branch = $matches[3];
}
else {
$output->writeln("<error>Malformed [book/lang/branch]</error>");
return 1;
}
$repoDir = $this->getContainer()->getParameter('publisher_repos_dir') . "/$book/$lang";
if (file_exists($repoDir)) {
$output->writeln("<info>Found git repo for $book/$lang in \"$repoDir\"</info>");
}
else {
$output->writeln("<error>Failed to find git repo for $book/$lang in \"$repoDir\".</error>");
$output->writeln("<error>Perhaps you should run \"docs:publish\" first?</error>");
return 1;
}
$command = 'mkdocs serve';
foreach (array('dev-addr', 'theme') as $option) {
if ($input->getOption($option)) {
$command .= " --{$option} " . escapeshellarg($input->getOption($option));
}
}
foreach (array('strict', 'livereload', 'no-livereload', 'quiet') as $option) {
if ($input->getOption($option)) {
$command .= " --{$option}";
}
}
protected function execute(InputInterface $input, OutputInterface $output)
{
if (preg_match(';^(\w+)/(\w+)?$;', $input->getArgument('[book/lang/[branch]]'), $matches)) {
$book = $matches[1];
$lang = $matches[2];
$branch = NULL;
} elseif (preg_match(';^(\w+)/(\w+)/(\w+)$;', $input->getArgument('[book/lang/[branch]]'), $matches)) {
$book = $matches[1];
$lang = $matches[2];
$branch = $matches[3];
} else {
$output->writeln("<error>Malformed [book/lang/branch]</error>");
return 1;
}
$repoDir = $this->getContainer()->getParameter('publisher_repos_dir') . "/$book/$lang";
if (file_exists($repoDir)) {
$output->writeln("<info>Found git repo for $book/$lang in \"$repoDir\"</info>");
} else {
$output->writeln("<error>Failed to find git repo for $book/$lang in \"$repoDir\".</error>");
$output->writeln("<error>Perhaps you should run \"docs:publish\" first?</error>");
return 1;
}
$command = 'mkdocs serve';
foreach (array('dev-addr', 'theme') as $option) {
if ($input->getOption($option)) {
$command .= " --{$option} " . escapeshellarg($input->getOption($option));
}
}
foreach (array('strict', 'livereload', 'no-livereload', 'quiet') as $option) {
if ($input->getOption($option) ) {
$command .= " --{$option}";
}
}
if ($branch) {
$output->writeln("<info>Check out branch \"$branch\"</info>");
self::passthruOK($repoDir, "git checkout $branch");
}
$output->writeln("<info>Launch \"$command\"</info>");
self::passthruOK($repoDir, $command);
if ($branch) {
$output->writeln("<info>Check out branch \"$branch\"</info>");
self::passthruOK($repoDir, "git checkout $branch");
}
$output->writeln("<info>Launch \"$command\"</info>");
self::passthruOK($repoDir, $command);
}
protected function passthruOK($newcwd, $command) {
$oldcwd = getcwd();
chdir($newcwd);
passthru($command, $return);
chdir($oldcwd);
if ($return) {
throw new \RuntimeException("Received error from command ($command)");
}
protected function passthruOK($newcwd, $command) {
$oldcwd = getcwd();
chdir($newcwd);
passthru($command, $return);
chdir($oldcwd);
if ($return) {
throw new \RuntimeException("Received error from command ($command)");
}
}
}
<?php
//
//
// namespace AppBundle\Controller;
//
//
// use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
// use Symfony\Bundle\FrameworkBundle\Controller\Controller;
// use Symfony\Component\HttpFoundation\Request;
//
//
// class DefaultController extends Controller
// {
// /**
......
......@@ -10,75 +10,70 @@ use Symfony\Component\Finder\Finder;
use Symfony\Component\Yaml\Parser;
//@TODO Make the errors that will occur if the slugs don't pass the regexp more obvious to the user
/**
* @TODO Make the errors that will occur if the slugs don't pass the regexp
* more obvious to the user
*/
class PublishController extends Controller {
class PublishController extends Controller
{
/**
* @Route("/admin/publish")
*/
public function PublishInstructionsAction()
{
return $this->render('AppBundle:Publish:publish.html.twig');
}
/**
* @Route("/admin/publish/{book}/{lang}/{branch}", requirements={
* "lang":"[[:alpha:]]{2}",
* "book":"[[:alpha:]\-]+",
* "branch":"[[:alnum:]\-\.]+",
* })
*/
public function PublishAction(Request $request, $lang, $book, $branch)
{
$publisher = $this->get('publisher');
$publisher->publish($book, $lang, $branch);
$content['messages'] = $publisher->getMessages();
return $this->render('AppBundle:Publish:publish.html.twig', $content);
}
/**
* @Route("/admin/listen")
*/
public function ListenAction(Request $request)
{
$body = $request->getContent();
$event = $request->headers->get('X-GitHub-Event');
$payload = json_decode($body);
/**
* @Route("/admin/publish")
*/
public function PublishInstructionsAction() {
return $this->render('AppBundle:Publish:publish.html.twig');
}
/**
* @Route("/admin/publish/{book}/{lang}/{branch}", requirements={
* "lang":"[[:alpha:]]{2}",
* "book":"[[:alpha:]\-]+",
* "branch":"[[:alnum:]\-\.]+",
* })
*/
public function PublishAction(Request $request, $lang, $book, $branch) {
$publisher = $this->get('publisher');
$publisher->publish($book, $lang, $branch);
$content['messages'] = $publisher->getMessages();
return $this->render('AppBundle:Publish:publish.html.twig', $content);
}
/**
* @Route("/admin/listen")
*/
public function ListenAction(Request $request) {
$body = $request->getContent();
$event = $request->headers->get('X-GitHub-Event');
$payload = json_decode($body);
$books = $this->get('book.loader')->find();
$books = $this->get('book.loader')->find();
$processor = $this->get('github.hook.processor');
$processor->process($event, $payload);
if(!$processor->published){
return new Response('Something went wrong during publishing.', 200); // @TODO Add more appropriate error code
}
$messages = $processor->getMessages();
$subject = $processor->getSubject();
$recipients = $processor->getRecipients();
$mail = \Swift_Message::newInstance()
$processor = $this->get('github.hook.processor');
$processor->process($event, $payload);
if (!$processor->published) {
return new Response('Something went wrong during publishing.', 200);
// @TODO Add more appropriate error code
}
$messages = $processor->getMessages();
$subject = $processor->getSubject();
$recipients = $processor->getRecipients();
$mail = \Swift_Message::newInstance()
->setSubject("[CiviCRM docs] $subject")
->setFrom('no-reply@civicrm.org')
->setTo($recipients)
->setBody(
$this->renderView(
'Emails/notify.html.twig', array(
'branch' => $processor->publisher->branch,
'book' => $processor->publisher->book,
'lang' => $processor->publisher->lang,
'messages' => $processor->publisher->getMessages()
)
),
'text/html'
$this->renderView(
'Emails/notify.html.twig',
array(
'branch' => $processor->publisher->branch,
'book' => $processor->publisher->book,
'lang' => $processor->publisher->lang,
'messages' => $processor->publisher->getMessages(),
)
), 'text/html'
);
$this->get('mailer')->send($mail);
return new Response($subject, 200);
$this->get('mailer')->send($mail);
return new Response($subject, 200);
}
}
}
......@@ -8,55 +8,60 @@ use Symfony\Component\Yaml\Parser;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Intl\ResourceBundle\RegionBundle;
class ReadController extends Controller
{
/**
* @Route("/{path}")
*/
public function RedirectAction($path)
{
//If path is the recognised name of a book, then redirect to the stable path of the book, else redirect to the home page.
$k = $this->get('kernel');
$fs = $this->get('filesystem');
$bookConfigFile = $k->getRootDir()."/config/books/{$path}.yml";
if (!$fs->exists($bookConfigFile)) {
return $this->redirect("/");
}
return $this->redirect("{$path}/en/stable");
}
// $k = $this->get('kernel');
// if(substr( $path, -1)=='/'){
// return new Response(file_get_contents($k->getCacheDir()."/{$path}index.html"));
// }else{
// return new Response(file_get_contents($k->getCacheDir()."/$path"));
// }
// //return $this->render('AppBundle:Read:read.html.twig');
/**
* @Route("/")
*/
public function HomeAction()
{
$k = $this->get('kernel');
// This seems like a kind of hacky way to find the locales, but not sure what a better way would be.
$locales = json_decode(file_get_contents($k->getRootDir().'/../vendor/symfony/symfony/src/Symfony/Component/Intl/Resources/data/locales/en.json'), true);
$finder = new Finder();
$yaml = new Parser();
$books = $this->get('book.loader')->find();
return $this->render('AppBundle:Read:home.html.twig', array(
'books' => $books,
'locales' => $locales['Names'])
);
class ReadController extends Controller {
/**
* @Route("/{path}")
*/
public function RedirectAction($path) {
//If path is the recognised name of a book, then redirect to the
//stable path of the book, else redirect to the home page.
$k = $this->get('kernel');
$fs = $this->get('filesystem');
$bookConfigFile = $k->getRootDir() . "/config/books/{$path}.yml";
if (!$fs->exists($bookConfigFile)) {
return $this->redirect("/");
}
return $this->redirect("{$path}/en/stable");
}
// $k = $this->get('kernel');
// if(substr( $path, -1)=='/'){
// return new Response(file_get_contents($k->getCacheDir()."/{$path}index.html"));
// }else{
// return new Response(file_get_contents($k->getCacheDir()."/$path"));
// }
// //return $this->render('AppBundle:Read:read.html.twig');
/**
* @Route("/")
*/
public function HomeAction() {
$k = $this->get('kernel');
// This seems like a kind of hacky way to find the locales, but not
// sure what a better way would be.
$locales = json_decode(file_get_contents(
$k->getRootDir()
. '/../vendor/symfony/symfony/src/Symfony/Component/Intl/Resources/data/locales/en.json'
), TRUE);
$finder = new Finder();
$yaml = new Parser();
$books = $this->get('book.loader')->find();
return $this->render('AppBundle:Read:home.html.twig', array(
'books' => $books,
'locales' => $locales['Names'])
);
}
// $k = $this->get('kernel');
// if(substr( $path, -1)=='/'){
// return new Response(file_get_contents($k->getCacheDir()."/{$path}index.html"));
// }else{
// return new Response(file_get_contents($k->getCacheDir()."/$path"));
// }
// //return $this->render('AppBundle:Read:read.html.twig');
// $k = $this->get('kernel');
// if(substr( $path, -1)=='/'){
// return new Response(file_get_contents($k->getCacheDir()."/{$path}index.html"));
// }else{
// return new Response(file_get_contents($k->getCacheDir()."/$path"));
// }
// //return $this->render('AppBundle:Read:read.html.twig');
}
......@@ -4,13 +4,12 @@ namespace AppBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class NotifyControllerTest extends WebTestCase
{
public function testNotify()
{
$client = static::createClient();
class NotifyControllerTest extends WebTestCase {
$crawler = $client->request('GET', '/Notify');
}
public function