Skip to content

Commit

Permalink
Fixed compatibility with php 5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
foxycode committed Oct 17, 2017
1 parent 5f82fdf commit d0d0f45
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 33 deletions.
14 changes: 4 additions & 10 deletions app/Forms/SignInFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Nette;
use Nette\Application\UI\Form;
use Nette\Security\User;
use Nette\Utils\ArrayHash;
use Nextras;

/**
* @method onLoggedIn(Nette\Security\User $user)
* @method onLoggedIn(User $user)
*/
final class SignInFormFactory
{
Expand All @@ -20,14 +21,11 @@ final class SignInFormFactory
public $onLoggedIn = [];

/**
* @var Nette\Security\User
* @var User
*/
private $user;

/**
* @param Nette\Security\User $user
*/
public function __construct(Nette\Security\User $user)
public function __construct(User $user)
{
$this->user = $user;
}
Expand Down Expand Up @@ -55,10 +53,6 @@ public function create()
return $form;
}

/**
* @param Form $form
* @param ArrayHash $values
*/
public function formSuccess(Form $form, ArrayHash $values)
{
if ($values->remember) {
Expand Down
6 changes: 4 additions & 2 deletions app/Forms/UserCreateFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ final class UserCreateFormFactory
*/
private $userManager;


public function __construct(UserManager $userManager)
{
$this->userManager = $userManager;
}

public function create(): Form
/**
* @return Form
*/
public function create()
{
$form = new Form;
$form->setRenderer(new Nextras\Forms\Rendering\Bs3FormRenderer)
Expand Down
8 changes: 7 additions & 1 deletion app/Forms/WikiEditFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ public function __construct(Config $config)
$this->config = $config;
}

public function create(?string $page, string $document): Form
/**
* @param null|string $page
* @param string $document
*
* @return Form
*/
public function create($page, $document)
{
$form = new Form;
$form->setRenderer(new Nextras\Forms\Rendering\Bs3FormRenderer)
Expand Down
2 changes: 1 addition & 1 deletion app/Libs/CommonMark/TableDocumentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class TableDocumentProcessor implements DocumentProcessorInterface
{
public function processDocument(Document $document): void
public function processDocument(Document $document)
{
$walker = $document->walker();
while ($event = $walker->next()) {
Expand Down
13 changes: 11 additions & 2 deletions app/Libs/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ public function __construct($arr)

/**
* Get Wiki page path on disk based on url path.
*
* @param null|string $wikiPath
*
* @return string
*/
public function getPageFilePath(?string $wikiPath): string
public function getPageFilePath($wikiPath)
{
if (!$wikiPath) {
$wikiPath = $this->defaultPage;
Expand All @@ -38,7 +42,12 @@ public function getPageFilePath(?string $wikiPath): string
return vsprintf('%s/%s.md', [$this->pageDir, $wikiPath]);
}

public function getUserFilePath(string $username): string
/**
* @param string $username
*
* @return string
*/
public function getUserFilePath($username)
{
return vsprintf('%s/%s.neon', [$this->userDir, $username]);
}
Expand Down
1 change: 0 additions & 1 deletion app/Libs/Security/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ final class Authenticator implements IAuthenticator
*/
private $userManager;


public function __construct(UserManager $userManager)
{
$this->userManager = $userManager;
Expand Down
23 changes: 18 additions & 5 deletions app/Libs/Security/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,38 @@ final class User implements IIdentity
*/
private $roles;


public function __construct(string $username, string $name, array $roles)
/**
* @param string $username
* @param string $name
* @param array $roles
*/
public function __construct($username, $name, array $roles)
{
$this->username = $username;
$this->name = $name;
$this->roles = $roles;
}

public function getId(): string
/**
* @return string
*/
public function getId()
{
return $this->username;
}

public function getName(): string
/**
* @return string
*/
public function getName()
{
return $this->name;
}

public function getRoles(): array
/**
* @return array
*/
public function getRoles()
{
return $this->roles;
}
Expand Down
34 changes: 27 additions & 7 deletions app/Libs/Security/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ final class UserManager
*/
private $config;


public function __construct(Config $config)
{
$this->config = $config;
}

public function getData(string $username): array
/**
* @param string $username
*
* @return array
* @throws UserNotFoundException
*/
public function getData($username)
{
$file = $this->config->getUserFilePath($username);
if (!is_file($file)) {
Expand All @@ -30,14 +35,27 @@ public function getData(string $username): array
return Neon::decode(FileSystem::read($file));
}

public function getUser(string $username): User
/**
* @param string $username
*
* @return User
*/
public function getUser($username)
{
$data = $this->getData($username);

return new User($data['username'], $data['name'], $data['roles']);
}

public function create(string $username, string $name, string $password): User
/**
* @param string $username
* @param string $name
* @param string $password
*
* @return User
* @throws UserExistsException
*/
public function create($username, $name, $password)
{
$roles = ['admin'];

Expand All @@ -57,7 +75,11 @@ public function create(string $username, string $name, string $password): User
return new User($username, $name, $roles);
}

public function changePassword(string $username, string $password): void
/**
* @param string $username
* @param string $password
*/
public function changePassword($username, $password)
{
$data = $this->getData($username);
$data['password'] = Passwords::hash($password);
Expand All @@ -66,12 +88,10 @@ public function changePassword(string $username, string $password): void
}
}


final class UserExistsException extends \Exception
{
}


final class UserNotFoundException extends \Exception
{
}
5 changes: 3 additions & 2 deletions app/Presenters/ErrorPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ final class ErrorPresenter implements Nette\Application\IPresenter
{
use Nette\SmartObject;

/** @var ILogger */
/**
* @var ILogger
*/
private $logger;


public function __construct(ILogger $logger)
{
$this->logger = $logger;
Expand Down
1 change: 0 additions & 1 deletion app/Presenters/SignPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ final class SignPresenter extends BasePresenter
*/
public $signInFormFactory;


public function createComponentSignInForm()
{
$this->signInFormFactory->onLoggedIn[] = function ($user) {
Expand Down
5 changes: 4 additions & 1 deletion app/Presenters/UserCreatePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ final class UserCreatePresenter extends BasePresenter
*/
public $userCreateFormFactory;

protected function createComponentUserCreateForm(): Form
/**
* @return Form
*/
protected function createComponentUserCreateForm()
{
$this->userCreateFormFactory->onCreate[] = function ($identity) {
$this->getUser()->login($identity);
Expand Down

0 comments on commit d0d0f45

Please sign in to comment.