Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kompatibilita s PHP 7.2 #20

Merged
merged 5 commits into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,16 @@ language: php
sudo: false

env:
- NETTE=2.1
- NETTE=2.2
- NETTE=2.3
- NETTE=2.4
- NETTE=master

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm

matrix:
exclude:
- php: 5.4
env: NETTE=2.4
- php: 5.5
env: NETTE=2.4
allow_failures:
- php: hhvm

Expand All @@ -42,4 +32,4 @@ after_failure:

cache:
directories:
- $HOME/.composer/cache
- $HOME/.composer/cache
29 changes: 6 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,16 @@
"source": "https://github.com/skaut/SkautisNette"
},
"require": {
"php": ">=5.3.0",
"php": ">=5.6",
"skautis/skautis": "~2.0@dev",
"nette/di": "~2.1@dev",
"nette/http": "~2.1@dev"
"nette/di": "^2.4@dev",
"nette/http": "^2.4@dev",
"nette/utils": "^2.4@dev"
},
"require-dev": {
"nette/tester": "~1.3",
"nette/nette": "~2.1@dev",
"nette/application": "~2.1@dev",
"nette/bootstrap": "~2.1@dev",
"nette/caching": "~2.1@dev",
"nette/component-model": "~2.1@dev",
"nette/database": "~2.1@dev",
"nette/deprecated": "~2.1@dev",
"nette/finder": "~2.1@dev",
"nette/forms": "~2.1@dev",
"nette/mail": "~2.1@dev",
"nette/neon": "~2.1@dev",
"nette/php-generator": "~2.1@dev",
"nette/reflection": "~2.1@dev",
"nette/robot-loader": "~2.1@dev",
"nette/safe-stream": "~2.1@dev",
"nette/security": "~2.1@dev",
"nette/tokenizer": "~2.1@dev",
"nette/utils": "~2.1@dev",
"latte/latte": "~2.1@dev",
"tracy/tracy": "~2.1@dev"
"nette/nette": "^2.4@dev",
"nette/utils": "^2.4@dev"
},
"suggest": {
"tracy/tracy": "to enable skautis panel for Tracy debug bar.",
Expand Down
62 changes: 13 additions & 49 deletions src/SkautisExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Nette;
use Nette\DI\Config;
use Skautis;
use Tracy\Debugger;


/**
Expand All @@ -16,13 +18,13 @@ class SkautisExtension extends Nette\DI\CompilerExtension
{

/** @var array */
public $defaults = array(
public $defaults = [
'applicationId' => NULL,
'testMode' => FALSE,
'profiler' => NULL,
'cache' => TRUE,
'compression' => TRUE,
);
];


public function loadConfiguration()
Expand All @@ -32,66 +34,28 @@ public function loadConfiguration()
$config['profiler'] = isset($config['profiler']) ? $config['profiler'] : !empty($container->parameters['debugMode']);

$container->addDefinition($this->prefix('config'))
->setClass('Skautis\Config', array($config['applicationId'], $config['testMode'], $config['cache'], $config['compression']));
->setClass(Skautis\Config::class, array($config['applicationId'], $config['testMode'], $config['cache'], $config['compression']));

$container->addDefinition($this->prefix('webServiceFactory'))
->setClass('Skautis\Wsdl\WebServiceFactory');
->setClass(Skautis\Wsdl\WebServiceFactory::class);

$manager = $container->addDefinition($this->prefix('wsdlManager'))
->setClass('Skautis\Wsdl\WsdlManager');
->setClass(Skautis\Wsdl\WsdlManager::class);

$container->addDefinition($this->prefix('session'))
->setClass('Skautis\Nette\SessionAdapter');
->setClass(SessionAdapter::class);

$container->addDefinition($this->prefix('user'))
->setClass('Skautis\User');
->setClass(Skautis\User::class);

$container->addDefinition($this->prefix('skautis'))
->setClass('Skautis\Skautis');
->setClass(Skautis\Skautis::class);

if ($config['profiler'] && (class_exists('Tracy\Debugger') || class_exists('Nette\Diagnostics\Debugger'))) {
if ($config['profiler'] && class_exists(Debugger::class)) {
$panel = $container->addDefinition($this->prefix('panel'))
->setClass('Skautis\Nette\Tracy\Panel');
$manager->addSetup(array($panel, 'register'), array($manager));
->setClass(Skautis\Nette\Tracy\Panel::class);
$manager->addSetup([$panel, 'register'], array($manager));
}
}


/**
* BC with nette/di <2.3
* @param string $name
* @param array $args
* @return mixed
*/
public function __call($name, $args)
{
if ($name === 'validateConfig') {
return call_user_func_array(array($this, '_validateConfig'), $args);
}
return parent::__call($name, $args);
}


/**
* Checks whether $config contains only $expected items and returns combined array.
* BC with nette/di <2.3
* @param array $expected configuration keys
* @param array|NULL $config to validate
* @param string|NULL $name configuration section name
* @return array
* @throws Nette\InvalidStateException
*/
private function _validateConfig(array $expected, array $config = NULL, $name = NULL)
{
if (func_num_args() === 1) {
$config = $this->config;
}
if ($extra = array_diff_key((array) $config, $expected)) {
$name = $name ?: $this->name;
$extra = implode(", $name.", array_keys($extra));
throw new Nette\InvalidStateException("Unknown configuration option $name.$extra.");
}
return Config\Helpers::merge($config, $expected);
}

}
31 changes: 5 additions & 26 deletions src/Tracy/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,22 @@
use Skautis\Wsdl\WsdlManager;
use Tracy;


if (!interface_exists('Tracy\IBarPanel') && interface_exists('Nette\Diagnostics\IBarPanel')) {
// BC with Nette 2.1
class_alias('Nette\Diagnostics\IBarPanel', 'Tracy\IBarPanel');
}


/**
* Skautis panel for Tracy.
*
* @author Hána František
*/
class Panel extends Nette\Object implements Tracy\IBarPanel
class Panel implements Tracy\IBarPanel
{
use Nette\SmartObject;

/** @var string */
private $htmlPrefix;

/** @var string */
private $debuggerClass;
private $htmlPrefix = 'tracy';

/** @var array */
private $queries = array();


public function __construct()
{
if (!class_exists('Tracy\Debugger') && class_exists('Nette\Diagnostics\Debugger')) {
$this->htmlPrefix = 'nette';
$this->debuggerClass = 'Nette\Diagnostics\Debugger';
} else {
$this->htmlPrefix = 'tracy';
$this->debuggerClass = 'Tracy\Debugger';
}
}


/**
* Registers event listener on WebService objects via WsdlManager
*
Expand All @@ -54,7 +33,7 @@ public function register(WsdlManager $wsdlManager)
{
$wsdlManager->addWebServiceListener(WebService::EVENT_SUCCESS, array($this, 'logEvent'));
$wsdlManager->addWebServiceListener(WebService::EVENT_FAILURE, array($this, 'logEvent'));
call_user_func(array($this->debuggerClass, 'getBar'))->addPanel($this);
Tracy\Debugger::getBar()->addPanel($this);
}


Expand Down Expand Up @@ -136,7 +115,7 @@ protected function prepareTrace(array $trace)
*/
protected function dump($object)
{
return call_user_func(array($this->debuggerClass, 'dump'), $object, TRUE);
return Tracy\Debugger::dump($object, TRUE);
}


Expand Down
6 changes: 4 additions & 2 deletions tests/SkautisNette/SkautisExtension.debug.phpt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

use Tester\Assert;
use Skautis\Skautis;
use Skautis\Nette\Tracy\Panel;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -13,6 +15,6 @@ $configurator->addConfig(__DIR__ . '/files/config.neon');
$container = $configurator->createContainer();

Assert::false($container->isCreated('skautis.panel'));
Assert::type('Skautis\Skautis', $container->getService('skautis.skautis'));
Assert::type(Skautis::class, $container->getService('skautis.skautis'));
Assert::true($container->isCreated('skautis.panel'));
Assert::type('Skautis\Nette\Tracy\Panel', $container->getService('skautis.panel'));
Assert::type(Panel::class, $container->getService('skautis.panel'));
4 changes: 2 additions & 2 deletions tests/SkautisNette/SkautisExtension.production.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Tester\Assert;

use Skautis\Skautis;

require __DIR__ . '/../bootstrap.php';

Expand All @@ -12,5 +12,5 @@ $configurator->setDebugMode(FALSE);
$configurator->addConfig(__DIR__ . '/files/config.neon');
$container = $configurator->createContainer();

Assert::type('Skautis\Skautis', $container->getService('skautis.skautis'));
Assert::type(Skautis::class, $container->getService('skautis.skautis'));
Assert::false($container->hasService('skautis.panel'));
33 changes: 0 additions & 33 deletions tests/composer-nette-2.1.json

This file was deleted.

37 changes: 0 additions & 37 deletions tests/composer-nette-2.2.json

This file was deleted.

37 changes: 0 additions & 37 deletions tests/composer-nette-2.3.json

This file was deleted.

3 changes: 2 additions & 1 deletion tests/composer-nette-2.4.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"source": "https://github.com/skaut/SkautisNette"
},
"require": {
"php": ">=5.3.0",
"php": ">=5.6",
"skautis/skautis": "~2.0@dev",
"nette/utils": "2.4.*",
"nette/di": "2.4.*",
"nette/http": "2.4.*"
},
Expand Down