Skip to content

Commit

Permalink
Merge pull request #5 from RiKap/patch-1
Browse files Browse the repository at this point in the history
Upgrade to Nette 3.0
  • Loading branch information
paveljanda authored Aug 20, 2019
2 parents 8de4c35 + f658a1b commit 1728018
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

install:
- composer install --no-interaction --prefer-source
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
}
},
"require": {
"nette/di" : "^2.3|^2.4",
"nette/application" : "^2.3|^2.4",
"nette/http" : "^2.3|^2.4"
"nette/di" : "^3.0",
"nette/application" : "^3.0",
"nette/http" : "^3.0"
},
"require-dev": {
"nette/tester" : "~1.7",
"nette/tester" : "~2.2.0",
"mockery/mockery" : "dev-master"
},
"minimum-stability": "dev"
Expand Down
35 changes: 19 additions & 16 deletions src/DI/SimpleHttpAuthExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,43 @@
namespace Ublaboo\SimpleHttpAuth\DI;

use Nette;
use Nette\Schema\Expect;
use Nette\Schema\Schema;

class SimpleHttpAuthExtension extends Nette\DI\CompilerExtension
{

private $defaults = [
'username' => '',
'password' => '',
'consoleAuth' => TRUE,
'presenters' => []
];
public function getConfigSchema(): Schema
{
return Expect::structure([
'username' => Expect::string(NULL),
'password' => Expect::string(NULL),
'consoleAuth' => Expect::bool(true),
'presenters' => Expect::array(),
]);
}


public function loadConfiguration()
{
$config = $this->_getConfig();

$builder = $this->getContainerBuilder();
$config = $this->config;

$builder->addDefinition($this->prefix('simpleHttpAuth'))
->setClass('Ublaboo\SimpleHttpAuth\SimpleHttpAuth')
->addTag('run')
->setClass(\Ublaboo\SimpleHttpAuth\SimpleHttpAuth::class)
->setArguments([
$config['username'],
$config['password'],
$config['presenters'],
$config['consoleAuth'],
$config->username,
$config->password,
$config->presenters,
$config->consoleAuth,
$builder->parameters['consoleMode'],
]);
}


private function _getConfig()
public function afterCompile(Nette\PhpGenerator\ClassType $class)
{
return $this->validateConfig($this->defaults, $this->config);
$class->getMethod('initialize')->addBody('$this->getService(?);', [$this->prefix('simpleHttpAuth')]);
}

}
4 changes: 2 additions & 2 deletions src/SimpleHttpAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Nette;

class SimpleHttpAuth extends Nette\DI\CompilerExtension
class SimpleHttpAuth
{

/**
Expand Down Expand Up @@ -77,7 +77,7 @@ public function __construct(
/**
* Eccapt either all presenter or just the specified ones
*/
if (empty($presenters) || in_array($request->getPresenterName(), $presenters)) {
if (empty($presenters) || (isset($request['presenter']) && in_array($request['presenter'], $presenters))) {
$this->authenticate($username, $password);
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
require __DIR__ . '/../vendor/autoload.php';

Tester\Environment::setup();
Tester\Environment::bypassFinals();

date_default_timezone_set('Europe/Prague');
4 changes: 3 additions & 1 deletion tests/cases/SimpleHttpAuthTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ final class SimpleHttpAuthTest extends Tester\TestCase

$this->router->shouldReceive('match')
->withArgs([$this->request])
->andReturn($this->appRequest);
->andReturn([
'presenter' => $return_presenter,
]);
}


Expand Down

0 comments on commit 1728018

Please sign in to comment.