From b0f74d8dc81eeca7dcedc21a62abe0c545941bcd Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sun, 13 Nov 2016 00:44:23 +0100 Subject: [PATCH] PHP Documentation --- src/Gist/Api/Client.php | 33 ++++++- src/Gist/Application.php | 11 ++- src/Gist/Command/CreateCommand.php | 18 +++- src/Gist/Command/StatsCommand.php | 13 ++- src/Gist/Command/UpdateCommand.php | 18 +++- src/Gist/Command/UserCreateCommand.php | 15 +++- src/Gist/Controller/ApiController.php | 3 +- src/Gist/Controller/Controller.php | 52 ++++++++++- src/Gist/Controller/EditController.php | 17 +++- src/Gist/Controller/LoginController.php | 25 ++++-- src/Gist/Controller/MyController.php | 30 ++++--- src/Gist/Controller/ViewController.php | 56 +++++++++++- src/Gist/ControllerResolver.php | 12 ++- src/Gist/Form/AbstractForm.php | 38 +++++++- src/Gist/Form/ApiCreateGistForm.php | 6 +- src/Gist/Form/ApiUpdateGistForm.php | 6 +- src/Gist/Form/CloneGistForm.php | 6 +- src/Gist/Form/CreateGistForm.php | 13 ++- src/Gist/Form/DeleteGistForm.php | 13 ++- src/Gist/Form/FilterGistForm.php | 16 +++- src/Gist/Form/UserLoginForm.php | 11 ++- src/Gist/Form/UserRegisterForm.php | 6 +- src/Gist/Model/Gist.php | 27 ++++++ src/Gist/Model/GistQuery.php | 9 +- src/Gist/Model/User.php | 29 ++++++- src/Gist/Model/UserQuery.php | 9 +- src/Gist/Security/AuthenticationListener.php | 28 ++++-- src/Gist/Security/AuthenticationProvider.php | 25 +++++- src/Gist/Security/LogoutSuccessHandler.php | 9 +- src/Gist/Service/Gist.php | 70 ++++++++++++++- src/Gist/Service/SaltGenerator.php | 10 ++- src/Gist/Service/UserProvider.php | 91 +++++++++++++++++++- 32 files changed, 643 insertions(+), 82 deletions(-) diff --git a/src/Gist/Api/Client.php b/src/Gist/Api/Client.php index 844fd24..fb62ac2 100644 --- a/src/Gist/Api/Client.php +++ b/src/Gist/Api/Client.php @@ -5,14 +5,34 @@ namespace Gist\Api; use GuzzleHttp\Client as BaseClient; /** - * Class Client + * Class Client. + * * @author Simon Vieille */ class Client extends BaseClient { + /** + * URI of creation + * + * @const string + */ const CREATE = '/en/api/create'; + + /** + * URI of updating + * + * @const string + */ 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) { $response = $this->post( @@ -34,9 +54,16 @@ class Client extends BaseClient return []; } - + + /** + * Clones and update a gist + * + * @param string $gist Gist's ID + * @param string $content The content + * + * @return array + */ public function update($gist, $content) - { $response = $this->post( str_replace('{gist}', $gist, self::UPDATE), array( diff --git a/src/Gist/Application.php b/src/Gist/Application.php index 0df6d7a..609be4d 100644 --- a/src/Gist/Application.php +++ b/src/Gist/Application.php @@ -5,16 +5,23 @@ namespace Gist; 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 { + /** + * Creates an instance of Application. + * + * @static + * + * @return Application + */ public static function getInstance() { static $app; if (null === $app) { - $app = new static; + $app = new static(); } return $app; diff --git a/src/Gist/Command/CreateCommand.php b/src/Gist/Command/CreateCommand.php index a3c9551..7aa7027 100644 --- a/src/Gist/Command/CreateCommand.php +++ b/src/Gist/Command/CreateCommand.php @@ -8,8 +8,16 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +/** + * class CreateCommand. + * + * @author Simon Vieille + */ class CreateCommand extends Command { + /** + * {@inheritdoc} + */ protected function configure() { $types = implode(', ', $this->getTypes()); @@ -45,6 +53,9 @@ EOF ); } + /** + * {@inheritdoc} + */ protected function execute(InputInterface $input, OutputInterface $output) { //$output->writeln(sprintf('%s bar.', 'test')); @@ -88,7 +99,7 @@ EOF return true; } - + if ($input->getOption('show-id')) { $output->writeln($gist['gist']['Id']); @@ -98,6 +109,11 @@ EOF $output->writeln(json_encode($gist)); } + /** + * Returns the list of types. + * + * @return array + */ protected function getTypes() { $types = array( diff --git a/src/Gist/Command/StatsCommand.php b/src/Gist/Command/StatsCommand.php index 9e013c6..8e8ad3d 100644 --- a/src/Gist/Command/StatsCommand.php +++ b/src/Gist/Command/StatsCommand.php @@ -10,8 +10,16 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Helper\Table; use GitWrapper\GitException; +/** + * class StatsCommand; + * + * @author Simon Vieille + */ class StatsCommand extends Command { + /** + * {@inheritdoc} + */ protected function configure() { $this @@ -22,7 +30,10 @@ Show stats about GIST EOF ); } - + + /** + * {@inheritdoc} + */ protected function execute(InputInterface $input, OutputInterface $output) { $gistService = $this->getSilexApplication()['gist']; diff --git a/src/Gist/Command/UpdateCommand.php b/src/Gist/Command/UpdateCommand.php index a1e3dd5..ef09a00 100644 --- a/src/Gist/Command/UpdateCommand.php +++ b/src/Gist/Command/UpdateCommand.php @@ -8,8 +8,16 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +/** + * class UpdateCommand. + * + * @author Simon Vieille + */ class UpdateCommand extends Command { + /** + * {@inheritdoc} + */ protected function configure() { $types = implode(', ', $this->getTypes()); @@ -44,6 +52,9 @@ EOF ); } + /** + * {@inheritdoc} + */ protected function execute(InputInterface $input, OutputInterface $output) { //$output->writeln(sprintf('%s bar.', 'test')); @@ -80,7 +91,7 @@ EOF return true; } - + if ($input->getOption('show-id')) { $output->writeln($gist['gist']['Id']); @@ -90,6 +101,11 @@ EOF $output->writeln(json_encode($gist)); } + /** + * Returns the list of types. + * + * @return array + */ protected function getTypes() { $types = array( diff --git a/src/Gist/Command/UserCreateCommand.php b/src/Gist/Command/UserCreateCommand.php index 28e6a73..50b1b36 100644 --- a/src/Gist/Command/UserCreateCommand.php +++ b/src/Gist/Command/UserCreateCommand.php @@ -7,16 +7,27 @@ use Symfony\Component\Console\Output\OutputInterface; use Knp\Command\Command; use Symfony\Component\Console\Question\Question; +/** + * Class UserCreateCommand. + * + * @author Simon Vieille + */ class UserCreateCommand extends Command { + /** + * {@inheritdoc} + */ protected function configure() { $this ->setName('user:create') ->setDescription('Create a user') - ->setHelp(""); + ->setHelp(''); } + /** + * {@inheritdoc} + */ protected function execute(InputInterface $input, OutputInterface $output) { $helper = $this->getHelper('question'); @@ -28,7 +39,7 @@ class UserCreateCommand extends Command while (trim($username) === '') { $question = new Question('Username: ', ''); $username = $helper->ask($input, $output, $question); - + if ($userProvider->userExists($username)) { $output->writeln('This username is already used.'); $username = ''; diff --git a/src/Gist/Controller/ApiController.php b/src/Gist/Controller/ApiController.php index bdaf33c..5b86bbe 100644 --- a/src/Gist/Controller/ApiController.php +++ b/src/Gist/Controller/ApiController.php @@ -10,7 +10,8 @@ use Gist\Model\GistQuery; use Gist\Form\ApiUpdateGistForm; /** - * Class ApiController + * Class ApiController. + * * @author Simon Vieille */ class ApiController extends Controller diff --git a/src/Gist/Controller/Controller.php b/src/Gist/Controller/Controller.php index b68ab24..c96d8d0 100644 --- a/src/Gist/Controller/Controller.php +++ b/src/Gist/Controller/Controller.php @@ -9,23 +9,42 @@ use Gist\Model\GistQuery; use Symfony\Component\HttpFoundation\Response; /** - * Class Controller + * Class Controller. + * * @author Simon Vieille */ class Controller { + /** + * @var Application + */ protected $app; + /** + * __construct. + * + * @param Application $app + */ public function __construct(Application $app) { $this->app = $app; } + /** + * Returns the application. + * + * @return Application + */ public function getApp() { return $this->app; } + /** + * Returns a 404 response. + * + * @return Response + */ protected function notFoundResponse() { $app = $this->getApp(); @@ -38,7 +57,16 @@ class Controller 404 ); } - + + /** + * 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) { $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) { $app = $this->getApp(); @@ -90,6 +125,11 @@ class Controller return $app['gist']->getContent($gist, $commit); } + /** + * Returns the connected user. + * + * @return mixed + */ public function getUser() { $app = $this->getApp(); @@ -110,6 +150,14 @@ class Controller return $user; } + /** + * Renders a view. + * + * @param string $template + * @param array $params + * + * @return string + */ public function render($template, array $params = null) { $app = $this->getApp(); diff --git a/src/Gist/Controller/EditController.php b/src/Gist/Controller/EditController.php index d368ade..348e989 100644 --- a/src/Gist/Controller/EditController.php +++ b/src/Gist/Controller/EditController.php @@ -10,11 +10,19 @@ use GitWrapper\GitException; use Symfony\Component\HttpFoundation\RedirectResponse; /** - * Class EditController + * Class EditController. + * * @author Simon Vieille */ class EditController extends Controller { + /** + * Creation page. + * + * @param Request $request + * + * @return string + */ public function createAction(Request $request) { $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) { $app = $this->getApp(); diff --git a/src/Gist/Controller/LoginController.php b/src/Gist/Controller/LoginController.php index 538a688..57723ed 100644 --- a/src/Gist/Controller/LoginController.php +++ b/src/Gist/Controller/LoginController.php @@ -7,15 +7,21 @@ use Gist\Model\User; use Gist\Form\UserRegisterForm; use Gist\Form\UserLoginForm; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Security\Core\SecurityContext; -use Symfony\Component\HttpFoundation\RedirectResponse; /** - * Class LoginController + * Class LoginController. + * * @author Simon Vieille */ class LoginController extends Controller { + /** + * Registration page. + * + * @param Request $request + * + * @return string + */ public function registerAction(Request $request) { $app = $this->getApp(); @@ -54,13 +60,20 @@ class LoginController extends Controller return $this->render( 'Login/register.html.twig', [ - 'form' => $form->createView(), - 'error' => isset($error) ? $error : '', + 'form' => $form->createView(), + 'error' => isset($error) ? $error : '', 'success' => isset($success) ? $success : '', ] ); } + /** + * Login page. + * + * @param Request $request + * + * @return string + */ public function loginAction(Request $request) { $app = $this->getApp(); @@ -87,7 +100,7 @@ class LoginController extends Controller return $this->render( 'Login/login.html.twig', [ - 'form' => $form->createView(), + 'form' => $form->createView(), 'error' => isset($error) ? $error : '', ] ); diff --git a/src/Gist/Controller/MyController.php b/src/Gist/Controller/MyController.php index f83721f..d097b6a 100644 --- a/src/Gist/Controller/MyController.php +++ b/src/Gist/Controller/MyController.php @@ -3,26 +3,34 @@ namespace Gist\Controller; use Symfony\Component\HttpFoundation\Request; -use Gist\Model\GistQuery; use Gist\Form\DeleteGistForm; use Gist\Form\FilterGistForm; /** - * Class MyController + * Class MyController. + * * @author Simon Vieille */ class MyController extends Controller { + /** + * "My" page. + * + * @param Request $request + * @param int $page + * + * @return string + */ public function myAction(Request $request, $page) { - $page = (int) $page; + $page = (int) $page; $app = $this->getApp(); $deleteForm = new DeleteGistForm($app['form.factory'], $app['translator']); $deleteForm = $deleteForm->build()->getForm(); - + $options = array( - 'type' => 'all', + 'type' => 'all', 'cipher' => 'anyway', ); @@ -42,7 +50,7 @@ class MyController extends Controller $options = $filterForm->getData(); } } - + $gists = $this->getUser()->getGistsPager($page, $options); if ($request->isMethod('post')) { @@ -64,11 +72,11 @@ class MyController extends Controller return $this->render( 'My/my.html.twig', array( - 'gists' => $gists, - 'page' => $page, - 'deleteForm' => $deleteForm->createView(), - 'filterForm' => $filterForm->createView(), - 'deleted' => !empty($deleted), + 'gists' => $gists, + 'page' => $page, + 'deleteForm' => $deleteForm->createView(), + 'filterForm' => $filterForm->createView(), + 'deleted' => !empty($deleted), ) ); } diff --git a/src/Gist/Controller/ViewController.php b/src/Gist/Controller/ViewController.php index c4476b5..fd9f262 100644 --- a/src/Gist/Controller/ViewController.php +++ b/src/Gist/Controller/ViewController.php @@ -9,11 +9,21 @@ use Gist\Model\Gist; use Symfony\Component\HttpFoundation\Response; /** - * Class ViewController + * Class ViewController. + * * @author Simon Vieille */ 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) { $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) { $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) { $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) { $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) { $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) { $app = $this->getApp(); diff --git a/src/Gist/ControllerResolver.php b/src/Gist/ControllerResolver.php index 6da4ff3..792c0a3 100644 --- a/src/Gist/ControllerResolver.php +++ b/src/Gist/ControllerResolver.php @@ -3,17 +3,23 @@ namespace Gist; use Silex\ControllerResolver as BaseControllerResolver; -use Gist\Application; /** - * Class DecoratorControllerResolver + * Class DecoratorControllerResolver. + * * @author Simon Vieille */ class ControllerResolver extends BaseControllerResolver { + /** + * Instanciates a controller. + * + * @param string $class + * + * @return Gist\Controller + */ protected function instantiateController($class) { return new $class($this->app); } } - diff --git a/src/Gist/Form/AbstractForm.php b/src/Gist/Form/AbstractForm.php index 16db215..963c4c5 100644 --- a/src/Gist/Form/AbstractForm.php +++ b/src/Gist/Form/AbstractForm.php @@ -6,15 +6,34 @@ use Symfony\Component\Form\FormFactory; use Symfony\Component\Translation\Translator; /** - * Class AbstractForm + * Class AbstractForm. + * * @author Simon Vieille */ abstract class AbstractForm { + /** + * The builder. + * + * @var Symfony\Component\Form\FormBuilder + */ protected $builder; + /** + * The translator. + * + * @var 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()) { $this->translator = $translator; @@ -22,15 +41,32 @@ abstract class AbstractForm $this->builder = $formFactory->createNamedBuilder($this->getName(), 'form', $data, $formFactoryOptions); } + /** + * Returns the form from the builder. + * + * @return Symfony\Component\Form\Form + */ public function getForm() { return $this->builder->getForm(); } + /** + * Returns the form's name. + * + * @return string + */ public function getName() { return 'form'; } + /** + * Builds the form. + * + * @param array $options + * + * @return Symfony\Component\Form\FormBuilder + */ abstract public function build(array $options = array()); } diff --git a/src/Gist/Form/ApiCreateGistForm.php b/src/Gist/Form/ApiCreateGistForm.php index 2f022a2..27f3e4b 100644 --- a/src/Gist/Form/ApiCreateGistForm.php +++ b/src/Gist/Form/ApiCreateGistForm.php @@ -3,11 +3,15 @@ namespace Gist\Form; /** - * Class ApiCreateGistForm + * Class ApiCreateGistForm. + * * @author Simon Vieille */ class ApiCreateGistForm extends CreateGistForm { + /** + * {@inheritdoc} + */ public function build(array $options = array()) { parent::build($options); diff --git a/src/Gist/Form/ApiUpdateGistForm.php b/src/Gist/Form/ApiUpdateGistForm.php index a9d21b1..2594d59 100644 --- a/src/Gist/Form/ApiUpdateGistForm.php +++ b/src/Gist/Form/ApiUpdateGistForm.php @@ -3,11 +3,15 @@ namespace Gist\Form; /** - * Class ApiUpdateGistForm + * Class ApiUpdateGistForm. + * * @author Simon Vieille */ class ApiUpdateGistForm extends ApiCreateGistForm { + /** + * {@inheritdoc} + */ public function build(array $options = array()) { parent::build($options); diff --git a/src/Gist/Form/CloneGistForm.php b/src/Gist/Form/CloneGistForm.php index 733d1c8..9e7101f 100644 --- a/src/Gist/Form/CloneGistForm.php +++ b/src/Gist/Form/CloneGistForm.php @@ -3,11 +3,15 @@ namespace Gist\Form; /** - * Class CreateGistForm + * Class CreateGistForm. + * * @author Simon Vieille */ class CloneGistForm extends CreateGistForm { + /** + * {@inheritdoc} + */ public function build(array $options = array()) { parent::build($options); diff --git a/src/Gist/Form/CreateGistForm.php b/src/Gist/Form/CreateGistForm.php index dba4606..a30e4f8 100644 --- a/src/Gist/Form/CreateGistForm.php +++ b/src/Gist/Form/CreateGistForm.php @@ -5,11 +5,15 @@ namespace Gist\Form; use Symfony\Component\Validator\Constraints\NotBlank; /** - * Class CreateGistForm + * Class CreateGistForm. + * * @author Simon Vieille */ class CreateGistForm extends AbstractForm { + /** + * {@inheritdoc} + */ public function build(array $options = array()) { $this->builder->add( @@ -69,6 +73,11 @@ class CreateGistForm extends AbstractForm return $this->builder; } + /** + * Returns the types for generating the form. + * + * @return array + */ protected function getTypes() { $types = array( @@ -78,7 +87,7 @@ class CreateGistForm extends AbstractForm 'php' => '', 'sql' => '', 'xml' => '', - 'yaml'=> '', + 'yaml' => '', 'perl' => '', 'c' => '', 'asp' => '', diff --git a/src/Gist/Form/DeleteGistForm.php b/src/Gist/Form/DeleteGistForm.php index 01baab0..6656c56 100644 --- a/src/Gist/Form/DeleteGistForm.php +++ b/src/Gist/Form/DeleteGistForm.php @@ -5,11 +5,15 @@ namespace Gist\Form; use Symfony\Component\Validator\Constraints\NotBlank; /** - * Class DeleteGistForm + * Class DeleteGistForm. + * * @author Simon Vieille */ class DeleteGistForm extends AbstractForm { + /** + * {@inheritdoc} + */ public function build(array $options = array()) { $this->builder->add( @@ -22,12 +26,15 @@ class DeleteGistForm extends AbstractForm ), ) ); - + $this->builder->setMethod('POST'); - + return $this->builder; } + /** + * {@inheritdoc} + */ public function getName() { return 'delete'; diff --git a/src/Gist/Form/FilterGistForm.php b/src/Gist/Form/FilterGistForm.php index ce2bcce..d1dcac8 100644 --- a/src/Gist/Form/FilterGistForm.php +++ b/src/Gist/Form/FilterGistForm.php @@ -5,11 +5,15 @@ namespace Gist\Form; use Symfony\Component\Validator\Constraints\NotBlank; /** - * Class CreateGistForm + * Class CreateGistForm. + * * @author Simon Vieille */ class FilterGistForm extends AbstractForm { + /** + * {@inheritdoc} + */ public function build(array $options = array()) { $this->builder->add( @@ -45,6 +49,11 @@ class FilterGistForm extends AbstractForm return $this->builder; } + /** + * Returns the types for generating the form. + * + * @return array + */ protected function getTypes() { $types = array( @@ -55,7 +64,7 @@ class FilterGistForm extends AbstractForm 'php' => '', 'sql' => '', 'xml' => '', - 'yaml'=> '', + 'yaml' => '', 'perl' => '', 'c' => '', 'asp' => '', @@ -72,6 +81,9 @@ class FilterGistForm extends AbstractForm return $types; } + /** + * {@inheritdoc} + */ public function getName() { return 'filter'; diff --git a/src/Gist/Form/UserLoginForm.php b/src/Gist/Form/UserLoginForm.php index 30ceec0..95db29b 100644 --- a/src/Gist/Form/UserLoginForm.php +++ b/src/Gist/Form/UserLoginForm.php @@ -5,11 +5,15 @@ namespace Gist\Form; use Symfony\Component\Validator\Constraints\NotBlank; /** - * Class UserLoginForm + * Class UserLoginForm. + * * @author Simon Vieille */ class UserLoginForm extends AbstractForm { + /** + * {@inheritdoc} + */ public function build(array $options = array()) { $this->builder->add( @@ -45,7 +49,7 @@ class UserLoginForm extends AbstractForm ), ) ); - + $this->builder->add( '_remember_me', 'checkbox', @@ -63,6 +67,9 @@ class UserLoginForm extends AbstractForm return $this->builder; } + /** + * {@inheritdoc} + */ public function getName() { return ''; diff --git a/src/Gist/Form/UserRegisterForm.php b/src/Gist/Form/UserRegisterForm.php index e2807a4..21d9203 100644 --- a/src/Gist/Form/UserRegisterForm.php +++ b/src/Gist/Form/UserRegisterForm.php @@ -5,11 +5,15 @@ namespace Gist\Form; use Symfony\Component\Validator\Constraints\NotBlank; /** - * Class UserRegisterForm + * Class UserRegisterForm. + * * @author Simon Vieille */ class UserRegisterForm extends AbstractForm { + /** + * {@inheritdoc} + */ public function build(array $options = array()) { $this->builder->add( diff --git a/src/Gist/Model/Gist.php b/src/Gist/Model/Gist.php index c0cb024..efb0a45 100644 --- a/src/Gist/Model/Gist.php +++ b/src/Gist/Model/Gist.php @@ -4,8 +4,20 @@ namespace Gist\Model; use Gist\Model\Base\Gist as BaseGist; +/** + * Class Gist. + * + * @author Simon Vieille + */ class Gist extends BaseGist { + /** + * Hydrates the gist with array data. + * + * @param array $data + * + * @return Gist + */ public function hydrateWith(array $data) { if (isset($data['title'])) { @@ -21,11 +33,21 @@ class Gist extends BaseGist return $this; } + /** + * Generates a unique filename. + * + * @return string + */ public function generateFilename() { $this->setFile(uniqid()); } + /** + * Returns the type for Geshi. + * + * @return string + */ public function getGeshiType() { $data = array( @@ -35,6 +57,11 @@ class Gist extends BaseGist return str_replace(array_keys($data), array_values($data), $this->getType()); } + /** + * Returns the extension depending of the type. + * + * @return string + */ public function getTypeAsExtension() { $data = array( diff --git a/src/Gist/Model/GistQuery.php b/src/Gist/Model/GistQuery.php index a2adcca..bd5a95d 100644 --- a/src/Gist/Model/GistQuery.php +++ b/src/Gist/Model/GistQuery.php @@ -5,14 +5,9 @@ namespace Gist\Model; use Gist\Model\Base\GistQuery as BaseGistQuery; /** - * Skeleton subclass for performing query and update operations on the 'gist' table. - * - * - * - * 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. + * Class GistQuery. * + * @author Simon Vieille */ class GistQuery extends BaseGistQuery { diff --git a/src/Gist/Model/User.php b/src/Gist/Model/User.php index 328e2fe..7282af1 100644 --- a/src/Gist/Model/User.php +++ b/src/Gist/Model/User.php @@ -6,18 +6,36 @@ use Gist\Model\Base\User as BaseUser; use Symfony\Component\Security\Core\User\UserInterface; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Connection\ConnectionInterface; - +. +/** + * Class User. + * + * @author Simon Vieille + */ class User extends BaseUser implements UserInterface { + /** + * Erases credentials. + * + * @return void + */ public function eraseCredentials() { } + /** + * Returns roles. + * + * @return array + */ public function getRoles() { return explode(',', parent::getRoles()); } + /** + * {@inheritdoc} + */ public function getGists(Criteria $criteria = null, ConnectionInterface $con = null) { if ($criteria === null) { @@ -27,6 +45,15 @@ class User extends BaseUser implements UserInterface 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) { $query = GistQuery::create() diff --git a/src/Gist/Model/UserQuery.php b/src/Gist/Model/UserQuery.php index e299a08..ec64aef 100644 --- a/src/Gist/Model/UserQuery.php +++ b/src/Gist/Model/UserQuery.php @@ -5,14 +5,9 @@ namespace Gist\Model; use Gist\Model\Base\UserQuery as BaseUserQuery; /** - * Skeleton subclass for performing query and update operations on the 'user' table. - * - * - * - * 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. + * Class UserQuery. * + * @author Simon Vieille */ class UserQuery extends BaseUserQuery { diff --git a/src/Gist/Security/AuthenticationListener.php b/src/Gist/Security/AuthenticationListener.php index 639fced..b180d70 100644 --- a/src/Gist/Security/AuthenticationListener.php +++ b/src/Gist/Security/AuthenticationListener.php @@ -7,36 +7,48 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; 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 */ class AuthenticationListener implements ListenerInterface { + /** + * @var TokenStorageInterface + */ protected $tokenStorage; + /** + * @var AuthenticationManagerInterface + */ protected $authenticationManager; + /** + * __construct. + * + * @param TokenStorageInterface $tokenStorage + * @param AuthenticationManagerInterface $authenticationManager + */ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager) { $this->tokenStorage = $tokenStorage; $this->authenticationManager = $authenticationManager; } + /** + * @param GetResponseEvent $event + */ public function handle(GetResponseEvent $event) { - $request = $event->getRequest(); + $request = $event->getRequest(); $username = $request->get('_username'); $password = $request->get('_password'); if (!empty($username)) { $token = new UsernamePasswordToken($username, $password, 'default'); - + try { $authToken = $this->authenticationManager->authenticate($token); $this->tokenStorage->setToken($token); @@ -46,7 +58,7 @@ class AuthenticationListener implements ListenerInterface $this->tokenStorage->setToken(null); return; - } + } } } } diff --git a/src/Gist/Security/AuthenticationProvider.php b/src/Gist/Security/AuthenticationProvider.php index e0f0b85..3fd4e62 100644 --- a/src/Gist/Security/AuthenticationProvider.php +++ b/src/Gist/Security/AuthenticationProvider.php @@ -9,18 +9,32 @@ use Gist\Service\UserProvider; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; /** - * Class AuthenticationProvider + * Class AuthenticationProvider. + * * @author Simon Vieille */ class AuthenticationProvider implements AuthenticationProviderInterface { + /** + * @var UserProvider + */ protected $userProvider; + /** + * __construct. + * + * @param UserProvider $userProvider + */ public function __construct(UserProvider $userProvider) { $this->userProvider = $userProvider; } + /** + * Authenticates. + * + * @param TokenInterface $token + */ public function authenticate(TokenInterface $token) { $user = $this->userProvider->loadUserByUsername($token->getUser()); @@ -29,7 +43,7 @@ class AuthenticationProvider implements AuthenticationProviderInterface $isValid = $this->userProvider->getEncoder()->isPasswordValid( $user->getPassword(), $token->getCredentials(), - $user->getSalt() + $user->getSalt() ); if (!$isValid) { @@ -42,6 +56,13 @@ class AuthenticationProvider implements AuthenticationProviderInterface throw new AuthenticationException('Authentication failed.'); } + /** + * Returns if the token instance is supported. + * + * @param TokenInterface $token + * + * @return bool + */ public function supports(TokenInterface $token) { return $token instanceof UsernamePasswordToken; diff --git a/src/Gist/Security/LogoutSuccessHandler.php b/src/Gist/Security/LogoutSuccessHandler.php index 537fd0c..018bfde 100644 --- a/src/Gist/Security/LogoutSuccessHandler.php +++ b/src/Gist/Security/LogoutSuccessHandler.php @@ -7,11 +7,17 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; /** - * Class LogoutSuccessHandler + * Class LogoutSuccessHandler. + * * @author Simon Vieille */ class LogoutSuccessHandler implements LogoutSuccessHandlerInterface { + /** + * @param Request $request + * + * @return RedirectResponse + */ public function onLogoutSuccess(Request $request) { $targetUrl = $request->query->get('target_url') ? $request->query->get('target_url') : '/'; @@ -19,4 +25,3 @@ class LogoutSuccessHandler implements LogoutSuccessHandlerInterface return new RedirectResponse($targetUrl); } } - diff --git a/src/Gist/Service/Gist.php b/src/Gist/Service/Gist.php index 234678c..bad53bf 100644 --- a/src/Gist/Service/Gist.php +++ b/src/Gist/Service/Gist.php @@ -11,19 +11,40 @@ use Gist\Model\GistQuery; use Gist\Model\User; /** - * Class Gist + * Class Gist. + * * @author Simon Vieille */ class Gist { + /** + * @var string + */ protected $gistPath; + /** + * @var GitWrapper + */ protected $gitWrapper; + /** + * @var GitWorkingCopy + */ protected $gitWorkingCopy; + /** + * @var 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) { $this->gistPath = $gistPath; @@ -32,11 +53,23 @@ class Gist $this->geshi = $geshi; } + /** + * Returns a collection of gists. + * + * @return Propel\Runtime\Collection\ObjectCollection + */ public function getGists() { return GistQuery::create()->find(); } + /** + * Returns the history of a Gist. + * + * @param GistModel $gist + * + * @return array + */ public function getHistory(GistModel $gist) { $command = GitCommand::getInstance('log', '--format=medium', $gist->getFile()); @@ -49,7 +82,7 @@ class Gist $history = []; - for ($i = count($commits) - 1; $i >= 0; $i--) { + for ($i = count($commits) - 1; $i >= 0; --$i) { $commit = trim($commits[$i][1]); $command = GitCommand::getInstance('show', '--no-color', $commit); @@ -75,6 +108,14 @@ class Gist return $history; } + /** + * Returns the content of a gist. + * + * @param GistModel $gist + * @param string $commit + * + * @return string + */ public function getContent(GistModel $gist, $commit) { $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)); } + /** + * Creates a gist. + * + * @param GistModel $gist + * @param array $data + * @param mixed $user + * + * @return GistModel + */ public function create(GistModel $gist, array $data, $user = null) { $gist->hydrateWith($data); @@ -104,6 +154,14 @@ class Gist return $gist; } + /** + * Makes a commit. + * + * @param GistModel $gist + * @param array $data + * + * @return GistModel + */ public function commit(GistModel $gist, array $data) { file_put_contents($this->gistPath.'/'.$gist->getFile(), $data['content']); @@ -115,6 +173,14 @@ class Gist return $gist; } + /** + * Highlight the content. + * + * @param string $type + * @param string $content + * + * @return string + */ public function highlight($type, $content) { $this->geshi->set_source($content); diff --git a/src/Gist/Service/SaltGenerator.php b/src/Gist/Service/SaltGenerator.php index cc06566..f86a0e0 100644 --- a/src/Gist/Service/SaltGenerator.php +++ b/src/Gist/Service/SaltGenerator.php @@ -5,11 +5,19 @@ namespace Gist\Service; use InvalidArgumentException; /** - * Class SaltGenerator + * Class SaltGenerator. + * * @author Simon Vieille */ class SaltGenerator { + /** + * Generates a random salt. + * + * @param int $length + * + * @return string + */ public function generate($length = 32) { if (!is_numeric($length)) { diff --git a/src/Gist/Service/UserProvider.php b/src/Gist/Service/UserProvider.php index 2289358..cc4521d 100644 --- a/src/Gist/Service/UserProvider.php +++ b/src/Gist/Service/UserProvider.php @@ -9,24 +9,43 @@ use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; -use Gist\Service\SaltGenerator; /** - * Class UserProvider + * Class UserProvider. + * * @author Simon Vieille */ class UserProvider implements UserProviderInterface { + /** + * @var MessageDigestPasswordEncoder + */ protected $encoder; - + + /** + * @var SaltGenerator + */ protected $saltGenerator; + /** + * __construct. + * + * @param MessageDigestPasswordEncoder $encoder + * @param SaltGenerator $saltGenerator + */ public function __construct(MessageDigestPasswordEncoder $encoder, SaltGenerator $saltGenerator) { $this->encoder = $encoder; $this->saltGenerator = $saltGenerator; } + /** + * Setter of encoder. + * + * @param MessageDigestPasswordEncoder $encoder + * + * @return UserProvider + */ public function setEncoder(MessageDigestPasswordEncoder $encoder) { $this->encoder = $encoder; @@ -34,11 +53,23 @@ class UserProvider implements UserProviderInterface return $this; } + /** + * Getter of encoder. + * + * @return MessageDigestPasswordEncoder + */ public function getEncoder() { return $this->encoder; } + /** + * Setter of saltGenerator. + * + * @param SaltGenerator $saltGenerator + * + * @return UserProvider + */ public function setSaltGenerator(SaltGenerator $saltGenerator) { $this->saltGenerator = $saltGenerator; @@ -46,11 +77,23 @@ class UserProvider implements UserProviderInterface return $this; } + /** + * Getter of saltGenerator. + * + * @return SaltGenerator + */ public function getSaltGenerator() { return $this->saltGenerator; } + /** + * Checks if the given username is a user. + * + * @param string $username + * + * @return bool + */ public function userExists($username) { return UserQuery::create() @@ -58,11 +101,24 @@ class UserProvider implements UserProviderInterface ->count() > 0; } + /** + * Creates a User. + * + * @return User + */ public function createUser() { return new User(); } + /** + * Registers an user. + * + * @param User $user + * @param string $password + * + * @return User + */ public function registerUser(User $user, $password) { $user->setSalt($this->saltGenerator->generate()); @@ -75,6 +131,14 @@ class UserProvider implements UserProviderInterface return $user; } + /** + * Updates an user. + * + * @param User $user + * @param string $password + * + * @return User + */ public function updateUserPassword(User $user, $password) { $user @@ -84,6 +148,13 @@ class UserProvider implements UserProviderInterface return $user; } + /** + * Loads a user by his username. + * + * @param string $username + * + * @return User + */ public function loadUserByUsername($username) { $user = UserQuery::create()->findOneByUsername($username); @@ -95,6 +166,13 @@ class UserProvider implements UserProviderInterface return $user; } + /** + * Refresh an user. + * + * @param User $user + * + * @return User + */ public function refreshUser(UserInterface $user) { if (!$user instanceof User) { @@ -104,6 +182,13 @@ class UserProvider implements UserProviderInterface return $this->loadUserByUsername($user->getUsername()); } + /** + * Checks if the class is supported. + * + * @param string $class + * + * @return bool + */ public function supportsClass($class) { return $class === 'Gist\Model\User';