Skip to content

Commit

Permalink
Nette 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar authored and Milan Felix 艩ulc committed Jul 6, 2019
1 parent 8af9c79 commit 304c352
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
11 changes: 6 additions & 5 deletions README.md
Expand Up @@ -22,11 +22,12 @@ Middlewares for [Apitte](https://github.com/apitte/core).

## Version

| State | Version | Branch | PHP | Composer |
|-------------|--------------|----------|----------|-------------------------------------------------|
| development | `^0.6.0` | `master` | `>= 7.1` | `minimum-stability: dev`, `prefer-stable: true` |
| stable | `^0.5.0` | `master` | `>= 7.1` | |
| stable | `^0.3.0` | `master` | `>= 5.6` | |
| State | Version | Branch | Nette | PHP |
|-------------|---------|----------|-------|---------|
| dev | `^0.7` | `master` | 3.0+ | `^7.2` |
| stable | `^0.6` | `master` | 3.0+ | `^7.2` |
| stable | `^0.5` | `master` | 2.4 | `>=7.1` |
| stable | `^0.3` | `master` | 2.4 | `>=5.6` |

## Maintainers

Expand Down
10 changes: 3 additions & 7 deletions composer.json
Expand Up @@ -17,13 +17,12 @@
}
],
"require": {
"php": ">= 7.1",
"php": "^7.2",
"apitte/core": "^0.6.0",
"contributte/middlewares": "^0.6.0|^0.7.0|^0.8.0"
"contributte/middlewares": "^0.9.0"
},
"require-dev": {
"mockery/mockery": "^0.9.9",
"nette/di": "~2.4.15",
"ninjify/nunjuck": "^0.2.0",
"ninjify/qa": "^0.8.0",
"phpstan/extension-installer": "^1.0",
Expand All @@ -32,9 +31,6 @@
"phpstan/phpstan-shim": "^0.11",
"phpstan/phpstan-strict-rules": "^0.11"
},
"conflict": {
"nette/di": "<2.4.15"
},
"autoload": {
"psr-4": {
"Apitte\\Middlewares\\": "src"
Expand All @@ -47,7 +43,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "0.6.x-dev"
"dev-master": "0.7.x-dev"
}
}
}
42 changes: 23 additions & 19 deletions src/DI/MiddlewaresPlugin.php
Expand Up @@ -2,28 +2,32 @@

namespace Apitte\Middlewares\DI;

use Apitte\Core\DI\Plugin\AbstractPlugin;
use Apitte\Core\DI\Plugin\PluginCompiler;
use Apitte\Core\DI\Plugin\Plugin;
use Apitte\Middlewares\ApiMiddleware;
use Contributte\Middlewares\AutoBasePathMiddleware;
use Contributte\Middlewares\DI\MiddlewaresExtension;
use Contributte\Middlewares\TracyMiddleware;

class MiddlewaresPlugin extends AbstractPlugin
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use stdClass;

/**
* @property-read stdClass $config
*/
class MiddlewaresPlugin extends Plugin
{

public const PLUGIN_NAME = 'middlewares';

/** @var mixed[] */
protected $defaults = [
'tracy' => true,
'autobasepath' => true,
];
public static function getName(): string
{
return 'middlewares';
}

public function __construct(PluginCompiler $compiler)
protected function getConfigSchema(): Schema
{
parent::__construct($compiler);
$this->name = self::PLUGIN_NAME;
return Expect::structure([
'tracy' => Expect::bool(true),
'autobasepath' => Expect::bool(true),
]);
}

/**
Expand All @@ -32,16 +36,16 @@ public function __construct(PluginCompiler $compiler)
public function loadPluginConfiguration(): void
{
$builder = $this->getContainerBuilder();
$global = $this->compiler->getExtension()->getConfig();
$config = $this->getConfig();
$globalConfig = $this->compiler->getExtension()->getConfig();
$config = $this->config;

if ($config['tracy'] === true) {
if ($config->tracy) {
$builder->addDefinition($this->prefix('tracy'))
->setFactory(TracyMiddleware::class . '::factory', [$global['debug']])
->setFactory(TracyMiddleware::class . '::factory', [$globalConfig->debug])
->addTag(MiddlewaresExtension::MIDDLEWARE_TAG, ['priority' => 100]);
}

if ($config['autobasepath'] === true) {
if ($config->autobasepath) {
$builder->addDefinition($this->prefix('autobasepath'))
->setFactory(AutoBasePathMiddleware::class)
->addTag(MiddlewaresExtension::MIDDLEWARE_TAG, ['priority' => 200]);
Expand Down

0 comments on commit 304c352

Please sign in to comment.