PHP Documentation
This commit is contained in:
parent
aa73578efe
commit
b0f74d8dc8
|
@ -5,14 +5,34 @@ namespace Gist\Api;
|
||||||
use GuzzleHttp\Client as BaseClient;
|
use GuzzleHttp\Client as BaseClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Client
|
* Class Client.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class Client extends BaseClient
|
class Client extends BaseClient
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* URI of creation
|
||||||
|
*
|
||||||
|
* @const string
|
||||||
|
*/
|
||||||
const CREATE = '/en/api/create';
|
const CREATE = '/en/api/create';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URI of updating
|
||||||
|
*
|
||||||
|
* @const string
|
||||||
|
*/
|
||||||
const UPDATE = '/en/api/update/{gist}';
|
const UPDATE = '/en/api/update/{gist}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a gist
|
||||||
|
*
|
||||||
|
* @param string $title The title
|
||||||
|
* @param string $type The type
|
||||||
|
* @param string $content The content
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function create($title, $type, $content)
|
public function create($title, $type, $content)
|
||||||
{
|
{
|
||||||
$response = $this->post(
|
$response = $this->post(
|
||||||
|
@ -35,8 +55,15 @@ class Client extends BaseClient
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones and update a gist
|
||||||
|
*
|
||||||
|
* @param string $gist Gist's ID
|
||||||
|
* @param string $content The content
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function update($gist, $content)
|
public function update($gist, $content)
|
||||||
{
|
|
||||||
$response = $this->post(
|
$response = $this->post(
|
||||||
str_replace('{gist}', $gist, self::UPDATE),
|
str_replace('{gist}', $gist, self::UPDATE),
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -5,16 +5,23 @@ namespace Gist;
|
||||||
use Silex\Application as SilexApplication;
|
use Silex\Application as SilexApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated The static version should be avoided, use DI instead.
|
* @deprecated The static version should be avoided, use DI instead
|
||||||
*/
|
*/
|
||||||
class Application extends SilexApplication
|
class Application extends SilexApplication
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Creates an instance of Application.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
*
|
||||||
|
* @return Application
|
||||||
|
*/
|
||||||
public static function getInstance()
|
public static function getInstance()
|
||||||
{
|
{
|
||||||
static $app;
|
static $app;
|
||||||
|
|
||||||
if (null === $app) {
|
if (null === $app) {
|
||||||
$app = new static;
|
$app = new static();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $app;
|
return $app;
|
||||||
|
|
|
@ -8,8 +8,16 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class CreateCommand.
|
||||||
|
*
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
class CreateCommand extends Command
|
class CreateCommand extends Command
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$types = implode(', ', $this->getTypes());
|
$types = implode(', ', $this->getTypes());
|
||||||
|
@ -45,6 +53,9 @@ EOF
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
//$output->writeln(sprintf('<comment>%s</comment> bar.', 'test'));
|
//$output->writeln(sprintf('<comment>%s</comment> bar.', 'test'));
|
||||||
|
@ -98,6 +109,11 @@ EOF
|
||||||
$output->writeln(json_encode($gist));
|
$output->writeln(json_encode($gist));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of types.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function getTypes()
|
protected function getTypes()
|
||||||
{
|
{
|
||||||
$types = array(
|
$types = array(
|
||||||
|
|
|
@ -10,8 +10,16 @@ use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Helper\Table;
|
use Symfony\Component\Console\Helper\Table;
|
||||||
use GitWrapper\GitException;
|
use GitWrapper\GitException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class StatsCommand;
|
||||||
|
*
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
class StatsCommand extends Command
|
class StatsCommand extends Command
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -23,6 +31,9 @@ EOF
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$gistService = $this->getSilexApplication()['gist'];
|
$gistService = $this->getSilexApplication()['gist'];
|
||||||
|
|
|
@ -8,8 +8,16 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class UpdateCommand.
|
||||||
|
*
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
class UpdateCommand extends Command
|
class UpdateCommand extends Command
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$types = implode(', ', $this->getTypes());
|
$types = implode(', ', $this->getTypes());
|
||||||
|
@ -44,6 +52,9 @@ EOF
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
//$output->writeln(sprintf('<comment>%s</comment> bar.', 'test'));
|
//$output->writeln(sprintf('<comment>%s</comment> bar.', 'test'));
|
||||||
|
@ -90,6 +101,11 @@ EOF
|
||||||
$output->writeln(json_encode($gist));
|
$output->writeln(json_encode($gist));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of types.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function getTypes()
|
protected function getTypes()
|
||||||
{
|
{
|
||||||
$types = array(
|
$types = array(
|
||||||
|
|
|
@ -7,16 +7,27 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Knp\Command\Command;
|
use Knp\Command\Command;
|
||||||
use Symfony\Component\Console\Question\Question;
|
use Symfony\Component\Console\Question\Question;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class UserCreateCommand.
|
||||||
|
*
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
class UserCreateCommand extends Command
|
class UserCreateCommand extends Command
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('user:create')
|
->setName('user:create')
|
||||||
->setDescription('Create a user')
|
->setDescription('Create a user')
|
||||||
->setHelp("");
|
->setHelp('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$helper = $this->getHelper('question');
|
$helper = $this->getHelper('question');
|
||||||
|
|
|
@ -10,7 +10,8 @@ use Gist\Model\GistQuery;
|
||||||
use Gist\Form\ApiUpdateGistForm;
|
use Gist\Form\ApiUpdateGistForm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ApiController
|
* Class ApiController.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class ApiController extends Controller
|
class ApiController extends Controller
|
||||||
|
|
|
@ -9,23 +9,42 @@ use Gist\Model\GistQuery;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Controller
|
* Class Controller.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class Controller
|
class Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var Application
|
||||||
|
*/
|
||||||
protected $app;
|
protected $app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __construct.
|
||||||
|
*
|
||||||
|
* @param Application $app
|
||||||
|
*/
|
||||||
public function __construct(Application $app)
|
public function __construct(Application $app)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the application.
|
||||||
|
*
|
||||||
|
* @return Application
|
||||||
|
*/
|
||||||
public function getApp()
|
public function getApp()
|
||||||
{
|
{
|
||||||
return $this->app;
|
return $this->app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a 404 response.
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
protected function notFoundResponse()
|
protected function notFoundResponse()
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$app = $this->getApp();
|
||||||
|
@ -39,6 +58,15 @@ class Controller
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the default options of a gist view.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param string $gist Gist's ID
|
||||||
|
* @param string $commit The commit ID
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function getViewOptions(Request $request, $gist, $commit)
|
protected function getViewOptions(Request $request, $gist, $commit)
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$app = $this->getApp();
|
||||||
|
@ -67,6 +95,13 @@ class Controller
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the content of the gist depending of the commit and its history.
|
||||||
|
*
|
||||||
|
* @param Gist $gist
|
||||||
|
* @param mixed $commit
|
||||||
|
* @param mixed $history
|
||||||
|
*/
|
||||||
protected function getContentByCommit(Gist $gist, &$commit, $history)
|
protected function getContentByCommit(Gist $gist, &$commit, $history)
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$app = $this->getApp();
|
||||||
|
@ -90,6 +125,11 @@ class Controller
|
||||||
return $app['gist']->getContent($gist, $commit);
|
return $app['gist']->getContent($gist, $commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the connected user.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function getUser()
|
public function getUser()
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$app = $this->getApp();
|
||||||
|
@ -110,6 +150,14 @@ class Controller
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a view.
|
||||||
|
*
|
||||||
|
* @param string $template
|
||||||
|
* @param array $params
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function render($template, array $params = null)
|
public function render($template, array $params = null)
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$app = $this->getApp();
|
||||||
|
|
|
@ -10,11 +10,19 @@ use GitWrapper\GitException;
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class EditController
|
* Class EditController.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class EditController extends Controller
|
class EditController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Creation page.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function createAction(Request $request)
|
public function createAction(Request $request)
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$app = $this->getApp();
|
||||||
|
@ -44,6 +52,13 @@ class EditController extends Controller
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cloning page.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function cloneAction(Request $request, $gist, $commit)
|
public function cloneAction(Request $request, $gist, $commit)
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$app = $this->getApp();
|
||||||
|
|
|
@ -7,15 +7,21 @@ use Gist\Model\User;
|
||||||
use Gist\Form\UserRegisterForm;
|
use Gist\Form\UserRegisterForm;
|
||||||
use Gist\Form\UserLoginForm;
|
use Gist\Form\UserLoginForm;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Security\Core\SecurityContext;
|
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class LoginController
|
* Class LoginController.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class LoginController extends Controller
|
class LoginController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Registration page.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function registerAction(Request $request)
|
public function registerAction(Request $request)
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$app = $this->getApp();
|
||||||
|
@ -54,13 +60,20 @@ class LoginController extends Controller
|
||||||
return $this->render(
|
return $this->render(
|
||||||
'Login/register.html.twig',
|
'Login/register.html.twig',
|
||||||
[
|
[
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'error' => isset($error) ? $error : '',
|
'error' => isset($error) ? $error : '',
|
||||||
'success' => isset($success) ? $success : '',
|
'success' => isset($success) ? $success : '',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Login page.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function loginAction(Request $request)
|
public function loginAction(Request $request)
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$app = $this->getApp();
|
||||||
|
@ -87,7 +100,7 @@ class LoginController extends Controller
|
||||||
return $this->render(
|
return $this->render(
|
||||||
'Login/login.html.twig',
|
'Login/login.html.twig',
|
||||||
[
|
[
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'error' => isset($error) ? $error : '',
|
'error' => isset($error) ? $error : '',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,16 +3,24 @@
|
||||||
namespace Gist\Controller;
|
namespace Gist\Controller;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Gist\Model\GistQuery;
|
|
||||||
use Gist\Form\DeleteGistForm;
|
use Gist\Form\DeleteGistForm;
|
||||||
use Gist\Form\FilterGistForm;
|
use Gist\Form\FilterGistForm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class MyController
|
* Class MyController.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class MyController extends Controller
|
class MyController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* "My" page.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param int $page
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function myAction(Request $request, $page)
|
public function myAction(Request $request, $page)
|
||||||
{
|
{
|
||||||
$page = (int) $page;
|
$page = (int) $page;
|
||||||
|
@ -64,11 +72,11 @@ class MyController extends Controller
|
||||||
return $this->render(
|
return $this->render(
|
||||||
'My/my.html.twig',
|
'My/my.html.twig',
|
||||||
array(
|
array(
|
||||||
'gists' => $gists,
|
'gists' => $gists,
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'deleteForm' => $deleteForm->createView(),
|
'deleteForm' => $deleteForm->createView(),
|
||||||
'filterForm' => $filterForm->createView(),
|
'filterForm' => $filterForm->createView(),
|
||||||
'deleted' => !empty($deleted),
|
'deleted' => !empty($deleted),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,21 @@ use Gist\Model\Gist;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ViewController
|
* Class ViewController.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class ViewController extends Controller
|
class ViewController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* View action.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param string $gist Gist's ID
|
||||||
|
* @param string $commit The commit
|
||||||
|
*
|
||||||
|
* @return string|Response
|
||||||
|
*/
|
||||||
public function viewAction(Request $request, $gist, $commit)
|
public function viewAction(Request $request, $gist, $commit)
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$app = $this->getApp();
|
||||||
|
@ -27,6 +37,15 @@ class ViewController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Embed action.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param string $gist Gist's ID
|
||||||
|
* @param string $commit The commit
|
||||||
|
*
|
||||||
|
* @return string|Response
|
||||||
|
*/
|
||||||
public function embedAction(Request $request, $gist, $commit)
|
public function embedAction(Request $request, $gist, $commit)
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$app = $this->getApp();
|
||||||
|
@ -40,6 +59,15 @@ class ViewController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JS embed action.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param string $gist Gist's ID
|
||||||
|
* @param string $commit The commit
|
||||||
|
*
|
||||||
|
* @return string|Response
|
||||||
|
*/
|
||||||
public function embedJsAction(Request $request, $gist, $commit)
|
public function embedJsAction(Request $request, $gist, $commit)
|
||||||
{
|
{
|
||||||
$viewOptions = $this->getViewOptions($request, $gist, $commit);
|
$viewOptions = $this->getViewOptions($request, $gist, $commit);
|
||||||
|
@ -53,6 +81,15 @@ class ViewController extends Controller
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Raw action.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param string $gist Gist's ID
|
||||||
|
* @param string $commit The commit
|
||||||
|
*
|
||||||
|
* @return string|Response
|
||||||
|
*/
|
||||||
public function rawAction(Request $request, $gist, $commit)
|
public function rawAction(Request $request, $gist, $commit)
|
||||||
{
|
{
|
||||||
$viewOptions = $this->getViewOptions($request, $gist, $commit);
|
$viewOptions = $this->getViewOptions($request, $gist, $commit);
|
||||||
|
@ -70,6 +107,15 @@ class ViewController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download action.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param string $gist Gist's ID
|
||||||
|
* @param string $commit The commit
|
||||||
|
*
|
||||||
|
* @return string|Response
|
||||||
|
*/
|
||||||
public function downloadAction(Request $request, $gist, $commit)
|
public function downloadAction(Request $request, $gist, $commit)
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$app = $this->getApp();
|
||||||
|
@ -94,6 +140,14 @@ class ViewController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Revisions action.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param string $gist Gist's ID
|
||||||
|
*
|
||||||
|
* @return string|Response
|
||||||
|
*/
|
||||||
public function revisionsAction(Request $request, $gist)
|
public function revisionsAction(Request $request, $gist)
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$app = $this->getApp();
|
||||||
|
|
|
@ -3,17 +3,23 @@
|
||||||
namespace Gist;
|
namespace Gist;
|
||||||
|
|
||||||
use Silex\ControllerResolver as BaseControllerResolver;
|
use Silex\ControllerResolver as BaseControllerResolver;
|
||||||
use Gist\Application;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DecoratorControllerResolver
|
* Class DecoratorControllerResolver.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class ControllerResolver extends BaseControllerResolver
|
class ControllerResolver extends BaseControllerResolver
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Instanciates a controller.
|
||||||
|
*
|
||||||
|
* @param string $class
|
||||||
|
*
|
||||||
|
* @return Gist\Controller
|
||||||
|
*/
|
||||||
protected function instantiateController($class)
|
protected function instantiateController($class)
|
||||||
{
|
{
|
||||||
return new $class($this->app);
|
return new $class($this->app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,15 +6,34 @@ use Symfony\Component\Form\FormFactory;
|
||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AbstractForm
|
* Class AbstractForm.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
abstract class AbstractForm
|
abstract class AbstractForm
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The builder.
|
||||||
|
*
|
||||||
|
* @var Symfony\Component\Form\FormBuilder
|
||||||
|
*/
|
||||||
protected $builder;
|
protected $builder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The translator.
|
||||||
|
*
|
||||||
|
* @var Translator
|
||||||
|
*/
|
||||||
protected $translator;
|
protected $translator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __construct.
|
||||||
|
*
|
||||||
|
* @param FormFactory $formFactory
|
||||||
|
* @param Translator $translator
|
||||||
|
* @param mixed $data
|
||||||
|
* @param array $formFactoryOptions
|
||||||
|
*/
|
||||||
public function __construct(FormFactory $formFactory, Translator $translator, $data = null, $formFactoryOptions = array())
|
public function __construct(FormFactory $formFactory, Translator $translator, $data = null, $formFactoryOptions = array())
|
||||||
{
|
{
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
|
@ -22,15 +41,32 @@ abstract class AbstractForm
|
||||||
$this->builder = $formFactory->createNamedBuilder($this->getName(), 'form', $data, $formFactoryOptions);
|
$this->builder = $formFactory->createNamedBuilder($this->getName(), 'form', $data, $formFactoryOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the form from the builder.
|
||||||
|
*
|
||||||
|
* @return Symfony\Component\Form\Form
|
||||||
|
*/
|
||||||
public function getForm()
|
public function getForm()
|
||||||
{
|
{
|
||||||
return $this->builder->getForm();
|
return $this->builder->getForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the form's name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return 'form';
|
return 'form';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the form.
|
||||||
|
*
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return Symfony\Component\Form\FormBuilder
|
||||||
|
*/
|
||||||
abstract public function build(array $options = array());
|
abstract public function build(array $options = array());
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,15 @@
|
||||||
namespace Gist\Form;
|
namespace Gist\Form;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ApiCreateGistForm
|
* Class ApiCreateGistForm.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class ApiCreateGistForm extends CreateGistForm
|
class ApiCreateGistForm extends CreateGistForm
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function build(array $options = array())
|
public function build(array $options = array())
|
||||||
{
|
{
|
||||||
parent::build($options);
|
parent::build($options);
|
||||||
|
|
|
@ -3,11 +3,15 @@
|
||||||
namespace Gist\Form;
|
namespace Gist\Form;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ApiUpdateGistForm
|
* Class ApiUpdateGistForm.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class ApiUpdateGistForm extends ApiCreateGistForm
|
class ApiUpdateGistForm extends ApiCreateGistForm
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function build(array $options = array())
|
public function build(array $options = array())
|
||||||
{
|
{
|
||||||
parent::build($options);
|
parent::build($options);
|
||||||
|
|
|
@ -3,11 +3,15 @@
|
||||||
namespace Gist\Form;
|
namespace Gist\Form;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CreateGistForm
|
* Class CreateGistForm.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class CloneGistForm extends CreateGistForm
|
class CloneGistForm extends CreateGistForm
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function build(array $options = array())
|
public function build(array $options = array())
|
||||||
{
|
{
|
||||||
parent::build($options);
|
parent::build($options);
|
||||||
|
|
|
@ -5,11 +5,15 @@ namespace Gist\Form;
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CreateGistForm
|
* Class CreateGistForm.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class CreateGistForm extends AbstractForm
|
class CreateGistForm extends AbstractForm
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function build(array $options = array())
|
public function build(array $options = array())
|
||||||
{
|
{
|
||||||
$this->builder->add(
|
$this->builder->add(
|
||||||
|
@ -69,6 +73,11 @@ class CreateGistForm extends AbstractForm
|
||||||
return $this->builder;
|
return $this->builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the types for generating the form.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function getTypes()
|
protected function getTypes()
|
||||||
{
|
{
|
||||||
$types = array(
|
$types = array(
|
||||||
|
@ -78,7 +87,7 @@ class CreateGistForm extends AbstractForm
|
||||||
'php' => '',
|
'php' => '',
|
||||||
'sql' => '',
|
'sql' => '',
|
||||||
'xml' => '',
|
'xml' => '',
|
||||||
'yaml'=> '',
|
'yaml' => '',
|
||||||
'perl' => '',
|
'perl' => '',
|
||||||
'c' => '',
|
'c' => '',
|
||||||
'asp' => '',
|
'asp' => '',
|
||||||
|
|
|
@ -5,11 +5,15 @@ namespace Gist\Form;
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DeleteGistForm
|
* Class DeleteGistForm.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class DeleteGistForm extends AbstractForm
|
class DeleteGistForm extends AbstractForm
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function build(array $options = array())
|
public function build(array $options = array())
|
||||||
{
|
{
|
||||||
$this->builder->add(
|
$this->builder->add(
|
||||||
|
@ -28,6 +32,9 @@ class DeleteGistForm extends AbstractForm
|
||||||
return $this->builder;
|
return $this->builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return 'delete';
|
return 'delete';
|
||||||
|
|
|
@ -5,11 +5,15 @@ namespace Gist\Form;
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CreateGistForm
|
* Class CreateGistForm.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class FilterGistForm extends AbstractForm
|
class FilterGistForm extends AbstractForm
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function build(array $options = array())
|
public function build(array $options = array())
|
||||||
{
|
{
|
||||||
$this->builder->add(
|
$this->builder->add(
|
||||||
|
@ -45,6 +49,11 @@ class FilterGistForm extends AbstractForm
|
||||||
return $this->builder;
|
return $this->builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the types for generating the form.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function getTypes()
|
protected function getTypes()
|
||||||
{
|
{
|
||||||
$types = array(
|
$types = array(
|
||||||
|
@ -55,7 +64,7 @@ class FilterGistForm extends AbstractForm
|
||||||
'php' => '',
|
'php' => '',
|
||||||
'sql' => '',
|
'sql' => '',
|
||||||
'xml' => '',
|
'xml' => '',
|
||||||
'yaml'=> '',
|
'yaml' => '',
|
||||||
'perl' => '',
|
'perl' => '',
|
||||||
'c' => '',
|
'c' => '',
|
||||||
'asp' => '',
|
'asp' => '',
|
||||||
|
@ -72,6 +81,9 @@ class FilterGistForm extends AbstractForm
|
||||||
return $types;
|
return $types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return 'filter';
|
return 'filter';
|
||||||
|
|
|
@ -5,11 +5,15 @@ namespace Gist\Form;
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UserLoginForm
|
* Class UserLoginForm.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class UserLoginForm extends AbstractForm
|
class UserLoginForm extends AbstractForm
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function build(array $options = array())
|
public function build(array $options = array())
|
||||||
{
|
{
|
||||||
$this->builder->add(
|
$this->builder->add(
|
||||||
|
@ -63,6 +67,9 @@ class UserLoginForm extends AbstractForm
|
||||||
return $this->builder;
|
return $this->builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
|
|
|
@ -5,11 +5,15 @@ namespace Gist\Form;
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UserRegisterForm
|
* Class UserRegisterForm.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class UserRegisterForm extends AbstractForm
|
class UserRegisterForm extends AbstractForm
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function build(array $options = array())
|
public function build(array $options = array())
|
||||||
{
|
{
|
||||||
$this->builder->add(
|
$this->builder->add(
|
||||||
|
|
|
@ -4,8 +4,20 @@ namespace Gist\Model;
|
||||||
|
|
||||||
use Gist\Model\Base\Gist as BaseGist;
|
use Gist\Model\Base\Gist as BaseGist;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Gist.
|
||||||
|
*
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
class Gist extends BaseGist
|
class Gist extends BaseGist
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Hydrates the gist with array data.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return Gist
|
||||||
|
*/
|
||||||
public function hydrateWith(array $data)
|
public function hydrateWith(array $data)
|
||||||
{
|
{
|
||||||
if (isset($data['title'])) {
|
if (isset($data['title'])) {
|
||||||
|
@ -21,11 +33,21 @@ class Gist extends BaseGist
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a unique filename.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function generateFilename()
|
public function generateFilename()
|
||||||
{
|
{
|
||||||
$this->setFile(uniqid());
|
$this->setFile(uniqid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the type for Geshi.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getGeshiType()
|
public function getGeshiType()
|
||||||
{
|
{
|
||||||
$data = array(
|
$data = array(
|
||||||
|
@ -35,6 +57,11 @@ class Gist extends BaseGist
|
||||||
return str_replace(array_keys($data), array_values($data), $this->getType());
|
return str_replace(array_keys($data), array_values($data), $this->getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the extension depending of the type.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getTypeAsExtension()
|
public function getTypeAsExtension()
|
||||||
{
|
{
|
||||||
$data = array(
|
$data = array(
|
||||||
|
|
|
@ -5,14 +5,9 @@ namespace Gist\Model;
|
||||||
use Gist\Model\Base\GistQuery as BaseGistQuery;
|
use Gist\Model\Base\GistQuery as BaseGistQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skeleton subclass for performing query and update operations on the 'gist' table.
|
* Class GistQuery.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* You should add additional methods to this class to meet the
|
|
||||||
* application requirements. This class will only be generated as
|
|
||||||
* long as it does not already exist in the output directory.
|
|
||||||
*
|
*
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class GistQuery extends BaseGistQuery
|
class GistQuery extends BaseGistQuery
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,18 +6,36 @@ use Gist\Model\Base\User as BaseUser;
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
use Propel\Runtime\Connection\ConnectionInterface;
|
use Propel\Runtime\Connection\ConnectionInterface;
|
||||||
|
.
|
||||||
|
/**
|
||||||
|
* Class User.
|
||||||
|
*
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
class User extends BaseUser implements UserInterface
|
class User extends BaseUser implements UserInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Erases credentials.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function eraseCredentials()
|
public function eraseCredentials()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns roles.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function getRoles()
|
public function getRoles()
|
||||||
{
|
{
|
||||||
return explode(',', parent::getRoles());
|
return explode(',', parent::getRoles());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function getGists(Criteria $criteria = null, ConnectionInterface $con = null)
|
public function getGists(Criteria $criteria = null, ConnectionInterface $con = null)
|
||||||
{
|
{
|
||||||
if ($criteria === null) {
|
if ($criteria === null) {
|
||||||
|
@ -27,6 +45,15 @@ class User extends BaseUser implements UserInterface
|
||||||
return parent::getGists($criteria, $con);
|
return parent::getGists($criteria, $con);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a pager of the user's gists.
|
||||||
|
*
|
||||||
|
* @param int $page
|
||||||
|
* @param array $options
|
||||||
|
* @param int $maxPerPage
|
||||||
|
*
|
||||||
|
* @return Propel\Runtime\Util\PropelModelPager
|
||||||
|
*/
|
||||||
public function getGistsPager($page, $options = array(), $maxPerPage = 10)
|
public function getGistsPager($page, $options = array(), $maxPerPage = 10)
|
||||||
{
|
{
|
||||||
$query = GistQuery::create()
|
$query = GistQuery::create()
|
||||||
|
|
|
@ -5,14 +5,9 @@ namespace Gist\Model;
|
||||||
use Gist\Model\Base\UserQuery as BaseUserQuery;
|
use Gist\Model\Base\UserQuery as BaseUserQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skeleton subclass for performing query and update operations on the 'user' table.
|
* Class UserQuery.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* You should add additional methods to this class to meet the
|
|
||||||
* application requirements. This class will only be generated as
|
|
||||||
* long as it does not already exist in the output directory.
|
|
||||||
*
|
*
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class UserQuery extends BaseUserQuery
|
class UserQuery extends BaseUserQuery
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,30 +7,42 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
|
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||||
use Symfony\Component\Security\Http\HttpUtils;
|
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
||||||
use Symfony\Component\Routing\Generator\UrlGenerator;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AuthenticationListener
|
* Class AuthenticationListener.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class AuthenticationListener implements ListenerInterface
|
class AuthenticationListener implements ListenerInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var TokenStorageInterface
|
||||||
|
*/
|
||||||
protected $tokenStorage;
|
protected $tokenStorage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var AuthenticationManagerInterface
|
||||||
|
*/
|
||||||
protected $authenticationManager;
|
protected $authenticationManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __construct.
|
||||||
|
*
|
||||||
|
* @param TokenStorageInterface $tokenStorage
|
||||||
|
* @param AuthenticationManagerInterface $authenticationManager
|
||||||
|
*/
|
||||||
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager)
|
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager)
|
||||||
{
|
{
|
||||||
$this->tokenStorage = $tokenStorage;
|
$this->tokenStorage = $tokenStorage;
|
||||||
$this->authenticationManager = $authenticationManager;
|
$this->authenticationManager = $authenticationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param GetResponseEvent $event
|
||||||
|
*/
|
||||||
public function handle(GetResponseEvent $event)
|
public function handle(GetResponseEvent $event)
|
||||||
{
|
{
|
||||||
$request = $event->getRequest();
|
$request = $event->getRequest();
|
||||||
$username = $request->get('_username');
|
$username = $request->get('_username');
|
||||||
$password = $request->get('_password');
|
$password = $request->get('_password');
|
||||||
|
|
||||||
|
|
|
@ -9,18 +9,32 @@ use Gist\Service\UserProvider;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AuthenticationProvider
|
* Class AuthenticationProvider.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class AuthenticationProvider implements AuthenticationProviderInterface
|
class AuthenticationProvider implements AuthenticationProviderInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var UserProvider
|
||||||
|
*/
|
||||||
protected $userProvider;
|
protected $userProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __construct.
|
||||||
|
*
|
||||||
|
* @param UserProvider $userProvider
|
||||||
|
*/
|
||||||
public function __construct(UserProvider $userProvider)
|
public function __construct(UserProvider $userProvider)
|
||||||
{
|
{
|
||||||
$this->userProvider = $userProvider;
|
$this->userProvider = $userProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authenticates.
|
||||||
|
*
|
||||||
|
* @param TokenInterface $token
|
||||||
|
*/
|
||||||
public function authenticate(TokenInterface $token)
|
public function authenticate(TokenInterface $token)
|
||||||
{
|
{
|
||||||
$user = $this->userProvider->loadUserByUsername($token->getUser());
|
$user = $this->userProvider->loadUserByUsername($token->getUser());
|
||||||
|
@ -42,6 +56,13 @@ class AuthenticationProvider implements AuthenticationProviderInterface
|
||||||
throw new AuthenticationException('Authentication failed.');
|
throw new AuthenticationException('Authentication failed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if the token instance is supported.
|
||||||
|
*
|
||||||
|
* @param TokenInterface $token
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function supports(TokenInterface $token)
|
public function supports(TokenInterface $token)
|
||||||
{
|
{
|
||||||
return $token instanceof UsernamePasswordToken;
|
return $token instanceof UsernamePasswordToken;
|
||||||
|
|
|
@ -7,11 +7,17 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class LogoutSuccessHandler
|
* Class LogoutSuccessHandler.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class LogoutSuccessHandler implements LogoutSuccessHandlerInterface
|
class LogoutSuccessHandler implements LogoutSuccessHandlerInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return RedirectResponse
|
||||||
|
*/
|
||||||
public function onLogoutSuccess(Request $request)
|
public function onLogoutSuccess(Request $request)
|
||||||
{
|
{
|
||||||
$targetUrl = $request->query->get('target_url') ? $request->query->get('target_url') : '/';
|
$targetUrl = $request->query->get('target_url') ? $request->query->get('target_url') : '/';
|
||||||
|
@ -19,4 +25,3 @@ class LogoutSuccessHandler implements LogoutSuccessHandlerInterface
|
||||||
return new RedirectResponse($targetUrl);
|
return new RedirectResponse($targetUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,19 +11,40 @@ use Gist\Model\GistQuery;
|
||||||
use Gist\Model\User;
|
use Gist\Model\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Gist
|
* Class Gist.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class Gist
|
class Gist
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected $gistPath;
|
protected $gistPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var GitWrapper
|
||||||
|
*/
|
||||||
protected $gitWrapper;
|
protected $gitWrapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var GitWorkingCopy
|
||||||
|
*/
|
||||||
protected $gitWorkingCopy;
|
protected $gitWorkingCopy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var GeSHi
|
||||||
|
*/
|
||||||
protected $geshi;
|
protected $geshi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __construct.
|
||||||
|
*
|
||||||
|
* @param mixed $gistPath
|
||||||
|
* @param GitWrapper $gitWrapper
|
||||||
|
* @param GitWorkingCopy $gitWorkingCopy
|
||||||
|
* @param GeSHi $geshi
|
||||||
|
*/
|
||||||
public function __construct($gistPath, GitWrapper $gitWrapper, GitWorkingCopy $gitWorkingCopy, GeSHi $geshi)
|
public function __construct($gistPath, GitWrapper $gitWrapper, GitWorkingCopy $gitWorkingCopy, GeSHi $geshi)
|
||||||
{
|
{
|
||||||
$this->gistPath = $gistPath;
|
$this->gistPath = $gistPath;
|
||||||
|
@ -32,11 +53,23 @@ class Gist
|
||||||
$this->geshi = $geshi;
|
$this->geshi = $geshi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a collection of gists.
|
||||||
|
*
|
||||||
|
* @return Propel\Runtime\Collection\ObjectCollection
|
||||||
|
*/
|
||||||
public function getGists()
|
public function getGists()
|
||||||
{
|
{
|
||||||
return GistQuery::create()->find();
|
return GistQuery::create()->find();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the history of a Gist.
|
||||||
|
*
|
||||||
|
* @param GistModel $gist
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function getHistory(GistModel $gist)
|
public function getHistory(GistModel $gist)
|
||||||
{
|
{
|
||||||
$command = GitCommand::getInstance('log', '--format=medium', $gist->getFile());
|
$command = GitCommand::getInstance('log', '--format=medium', $gist->getFile());
|
||||||
|
@ -49,7 +82,7 @@ class Gist
|
||||||
|
|
||||||
$history = [];
|
$history = [];
|
||||||
|
|
||||||
for ($i = count($commits) - 1; $i >= 0; $i--) {
|
for ($i = count($commits) - 1; $i >= 0; --$i) {
|
||||||
$commit = trim($commits[$i][1]);
|
$commit = trim($commits[$i][1]);
|
||||||
|
|
||||||
$command = GitCommand::getInstance('show', '--no-color', $commit);
|
$command = GitCommand::getInstance('show', '--no-color', $commit);
|
||||||
|
@ -75,6 +108,14 @@ class Gist
|
||||||
return $history;
|
return $history;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the content of a gist.
|
||||||
|
*
|
||||||
|
* @param GistModel $gist
|
||||||
|
* @param string $commit
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getContent(GistModel $gist, $commit)
|
public function getContent(GistModel $gist, $commit)
|
||||||
{
|
{
|
||||||
$command = GitCommand::getInstance('cat-file', '-p', $commit.':'.$gist->getFile());
|
$command = GitCommand::getInstance('cat-file', '-p', $commit.':'.$gist->getFile());
|
||||||
|
@ -84,6 +125,15 @@ class Gist
|
||||||
return str_replace("\r\n", "\n", $this->gitWrapper->run($command));
|
return str_replace("\r\n", "\n", $this->gitWrapper->run($command));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a gist.
|
||||||
|
*
|
||||||
|
* @param GistModel $gist
|
||||||
|
* @param array $data
|
||||||
|
* @param mixed $user
|
||||||
|
*
|
||||||
|
* @return GistModel
|
||||||
|
*/
|
||||||
public function create(GistModel $gist, array $data, $user = null)
|
public function create(GistModel $gist, array $data, $user = null)
|
||||||
{
|
{
|
||||||
$gist->hydrateWith($data);
|
$gist->hydrateWith($data);
|
||||||
|
@ -104,6 +154,14 @@ class Gist
|
||||||
return $gist;
|
return $gist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a commit.
|
||||||
|
*
|
||||||
|
* @param GistModel $gist
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return GistModel
|
||||||
|
*/
|
||||||
public function commit(GistModel $gist, array $data)
|
public function commit(GistModel $gist, array $data)
|
||||||
{
|
{
|
||||||
file_put_contents($this->gistPath.'/'.$gist->getFile(), $data['content']);
|
file_put_contents($this->gistPath.'/'.$gist->getFile(), $data['content']);
|
||||||
|
@ -115,6 +173,14 @@ class Gist
|
||||||
return $gist;
|
return $gist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Highlight the content.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function highlight($type, $content)
|
public function highlight($type, $content)
|
||||||
{
|
{
|
||||||
$this->geshi->set_source($content);
|
$this->geshi->set_source($content);
|
||||||
|
|
|
@ -5,11 +5,19 @@ namespace Gist\Service;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SaltGenerator
|
* Class SaltGenerator.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class SaltGenerator
|
class SaltGenerator
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Generates a random salt.
|
||||||
|
*
|
||||||
|
* @param int $length
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function generate($length = 32)
|
public function generate($length = 32)
|
||||||
{
|
{
|
||||||
if (!is_numeric($length)) {
|
if (!is_numeric($length)) {
|
||||||
|
|
|
@ -9,24 +9,43 @@ use Symfony\Component\Security\Core\User\UserProviderInterface;
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
||||||
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
||||||
use Gist\Service\SaltGenerator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UserProvider
|
* Class UserProvider.
|
||||||
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class UserProvider implements UserProviderInterface
|
class UserProvider implements UserProviderInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var MessageDigestPasswordEncoder
|
||||||
|
*/
|
||||||
protected $encoder;
|
protected $encoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SaltGenerator
|
||||||
|
*/
|
||||||
protected $saltGenerator;
|
protected $saltGenerator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __construct.
|
||||||
|
*
|
||||||
|
* @param MessageDigestPasswordEncoder $encoder
|
||||||
|
* @param SaltGenerator $saltGenerator
|
||||||
|
*/
|
||||||
public function __construct(MessageDigestPasswordEncoder $encoder, SaltGenerator $saltGenerator)
|
public function __construct(MessageDigestPasswordEncoder $encoder, SaltGenerator $saltGenerator)
|
||||||
{
|
{
|
||||||
$this->encoder = $encoder;
|
$this->encoder = $encoder;
|
||||||
$this->saltGenerator = $saltGenerator;
|
$this->saltGenerator = $saltGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter of encoder.
|
||||||
|
*
|
||||||
|
* @param MessageDigestPasswordEncoder $encoder
|
||||||
|
*
|
||||||
|
* @return UserProvider
|
||||||
|
*/
|
||||||
public function setEncoder(MessageDigestPasswordEncoder $encoder)
|
public function setEncoder(MessageDigestPasswordEncoder $encoder)
|
||||||
{
|
{
|
||||||
$this->encoder = $encoder;
|
$this->encoder = $encoder;
|
||||||
|
@ -34,11 +53,23 @@ class UserProvider implements UserProviderInterface
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter of encoder.
|
||||||
|
*
|
||||||
|
* @return MessageDigestPasswordEncoder
|
||||||
|
*/
|
||||||
public function getEncoder()
|
public function getEncoder()
|
||||||
{
|
{
|
||||||
return $this->encoder;
|
return $this->encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter of saltGenerator.
|
||||||
|
*
|
||||||
|
* @param SaltGenerator $saltGenerator
|
||||||
|
*
|
||||||
|
* @return UserProvider
|
||||||
|
*/
|
||||||
public function setSaltGenerator(SaltGenerator $saltGenerator)
|
public function setSaltGenerator(SaltGenerator $saltGenerator)
|
||||||
{
|
{
|
||||||
$this->saltGenerator = $saltGenerator;
|
$this->saltGenerator = $saltGenerator;
|
||||||
|
@ -46,11 +77,23 @@ class UserProvider implements UserProviderInterface
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter of saltGenerator.
|
||||||
|
*
|
||||||
|
* @return SaltGenerator
|
||||||
|
*/
|
||||||
public function getSaltGenerator()
|
public function getSaltGenerator()
|
||||||
{
|
{
|
||||||
return $this->saltGenerator;
|
return $this->saltGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given username is a user.
|
||||||
|
*
|
||||||
|
* @param string $username
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function userExists($username)
|
public function userExists($username)
|
||||||
{
|
{
|
||||||
return UserQuery::create()
|
return UserQuery::create()
|
||||||
|
@ -58,11 +101,24 @@ class UserProvider implements UserProviderInterface
|
||||||
->count() > 0;
|
->count() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a User.
|
||||||
|
*
|
||||||
|
* @return User
|
||||||
|
*/
|
||||||
public function createUser()
|
public function createUser()
|
||||||
{
|
{
|
||||||
return new User();
|
return new User();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers an user.
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
* @param string $password
|
||||||
|
*
|
||||||
|
* @return User
|
||||||
|
*/
|
||||||
public function registerUser(User $user, $password)
|
public function registerUser(User $user, $password)
|
||||||
{
|
{
|
||||||
$user->setSalt($this->saltGenerator->generate());
|
$user->setSalt($this->saltGenerator->generate());
|
||||||
|
@ -75,6 +131,14 @@ class UserProvider implements UserProviderInterface
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an user.
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
* @param string $password
|
||||||
|
*
|
||||||
|
* @return User
|
||||||
|
*/
|
||||||
public function updateUserPassword(User $user, $password)
|
public function updateUserPassword(User $user, $password)
|
||||||
{
|
{
|
||||||
$user
|
$user
|
||||||
|
@ -84,6 +148,13 @@ class UserProvider implements UserProviderInterface
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a user by his username.
|
||||||
|
*
|
||||||
|
* @param string $username
|
||||||
|
*
|
||||||
|
* @return User
|
||||||
|
*/
|
||||||
public function loadUserByUsername($username)
|
public function loadUserByUsername($username)
|
||||||
{
|
{
|
||||||
$user = UserQuery::create()->findOneByUsername($username);
|
$user = UserQuery::create()->findOneByUsername($username);
|
||||||
|
@ -95,6 +166,13 @@ class UserProvider implements UserProviderInterface
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh an user.
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
*
|
||||||
|
* @return User
|
||||||
|
*/
|
||||||
public function refreshUser(UserInterface $user)
|
public function refreshUser(UserInterface $user)
|
||||||
{
|
{
|
||||||
if (!$user instanceof User) {
|
if (!$user instanceof User) {
|
||||||
|
@ -104,6 +182,13 @@ class UserProvider implements UserProviderInterface
|
||||||
return $this->loadUserByUsername($user->getUsername());
|
return $this->loadUserByUsername($user->getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the class is supported.
|
||||||
|
*
|
||||||
|
* @param string $class
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function supportsClass($class)
|
public function supportsClass($class)
|
||||||
{
|
{
|
||||||
return $class === 'Gist\Model\User';
|
return $class === 'Gist\Model\User';
|
||||||
|
|
Loading…
Reference in a new issue