Kdyby\Console problém s integraci a puštěním
- wicked
- Člen | 290
Zdravím Vás všechny,
po delší době jsem utekl zpět k PHP a Nette, ale mám takový menší problém … Jak jinak :)
Jedná se mi o integraci Kdyby/console respektive jeji funkčnost.
Postupoval jsem podle navodu na gitu
Composer
"require": {
"php": ">= 5.3.7",
"nette/application": "~2.3.6",
"nette/bootstrap": "~2.3.0",
"nette/caching": "~2.3.0",
"nette/database": "~2.3.0",
"nette/di": "~2.3.0",
"nette/finder": "~2.3.0",
"nette/forms": "~2.3.0",
"nette/http": "~2.3.0",
"nette/mail": "~2.3.0",
"nette/robot-loader": "~2.3.0",
"nette/safe-stream": "~2.3.0",
"nette/security": "~2.3.0",
"nette/utils": "~2.3.0",
"latte/latte": "~2.3.0",
"tracy/tracy": "~2.3.0",
"dg/adminer-custom": "~1.6",
"kdyby/console": "dev-master",
"kdyby/events": "dev-master",
"kdyby/autowired": "dev-master",
"nextras/forms": "dev-master",
"o5/grido": "dev-master",
"jkuchar/pdfresponse": "dev-master"
},
Config.neon
#
# SECURITY WARNING: it is CRITICAL that this file & directory are NOT accessible directly via a web browser!
#
# If you don't protect this directory from direct web access, anybody will be able to see your passwords.
# http://nette.org/security-warning
#
parameters:
php:
date.timezone: Europe/Prague
nette:
application:
errorPresenter: Error
mapping:
*: App\*Module\Presenters\*Presenter
session:
expiration: 14 days
autoStart: true
debugger: true
latte:
macros:
- Nextras\Forms\Bridges\Latte\Macros\BS3InputMacros
debugger:
email: info@jirickajakub.cz
services:
router: App\RouterFactory::createRouter
- App\Model\UserManager
- App\Model\IpModel
- App\Model\BlacklistModel
- App\Model\BlacklistcheckModel
extensions:
console: Kdyby\Console\DI\ConsoleExtension
autowired: Kdyby\Autowired\DI\AutowiredExtension
console:
url: https://admin.jirickajakub.cz
commands:
- App\Console\BlacklistCommand
A samotný blacklistcommand:
<?php
namespace App\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Nette;
use App\Model;
use Nette\Mail\SmtpMailer;
use Nette\Mail\Message;
use Tracy\Debugger;
class BlacklistCommand extends Command {
/** @var \App\Model\IpModel @inject */
public $ip;
/** @var \App\Model\BlacklistModel @inject */
public $blacklist;
/** @var \App\Model\BlacklistcheckModel @inject */
public $blacklistCheck;
protected function configure() {
$this->setName('blacklist')->setDescription('Kontrola blacklistu');
}
protected function execute(InputInterface $input, OutputInterface $output) {
try {
// Nastaveni datetime
$datetime = new Nette\Utils\DateTime();
$blacklist = $this->blacklist->findAll()->where("stav", "1");
$ip = $this->ip->findAll()->where("stav", "1");
foreach ($blacklist as $b) {
foreach ($ip as $i) {
$reverse_ip = implode(".", array_reverse(explode(".", $i->ip)));
if (checkdnsrr($reverse_ip . "." . $b->nazev . ".", "A")) {
#kod pro ulozeni do db - NOK
$this->blacklistCheck->insert(array(
"blacklist_id" => $b->id,
"ip_id" => $i->id,
"status" => "0",
"vytvoreno" => $datetime
));
} else {
#kod pro ulozeni do db - OK
$this->blacklistCheck->insert(array(
"blacklist_id" => $b->id,
"ip_id" => $i->id,
"status" => "1",
"vytvoreno" => $datetime
));
}
}
}
$output->writeLn(new Nette\Utils\DateTime() . '<info>[OK] - BlacklistCheck</info>');
return 0;
} catch (\Exception $exc) {
$output->writeLn(new Nette\Utils\DateTime() . '<error>BlacklistCheck - ' . $exc->getMessage() . '</error>');
return 1;
}
}
}
Ale kdyz pustim pres terminal, dostanu tuhle chybu:
root@server:~# php /var/www/clients/client2/admin.jirickajakub.cz/web/www/index.php
Parse error: syntax error, unexpected T_USE, expecting T_FUNCTION in /var/www/clients/client2/web27/web/app/presenters/BasePresenter.php on line 16
exception 'ErrorException' with message 'syntax error, unexpected T_USE, expecting T_FUNCTION' in /var/www/clients/client2/web27/web/app/presenters/BasePresenter.php:16
Stack trace:
#0 [internal function]: Tracy\Debugger::shutdownHandler()
#1 {main}
(stored in /var/www/clients/client2/web27/web/app/../log/exception--2015-10-27--20-24--b13f4f3335.html)
root@server:~#
Kdyz ale odstranim vsechno z basepresenteru, vyhodi to zase jiny presenter …
Nette: 2.3.7
PHP: 5.4.45
Nenapadá Vás někoho něco?
Děkuji
Editoval wicked (28. 10. 2015 15:55)
- wicked
- Člen | 290
CZechBoY napsal(a):
Tak pošli ještě ten BasePresenter :)
Jenže jak jsem už říkal, tam nic extra není :)
<?php
namespace App\Presenters;
use Nette,
App\Model;
/**
* Base presenter for all application presenters.
* @author Jiřička Jakub <info@jirickajakub.cz>
* @package Admin
*/
abstract class BasePresenter extends Nette\Application\UI\Presenter {
// Import Autowired extension
use \Kdyby\Autowired\AutowireProperties;
use \Kdyby\Autowired\AutowireComponentFactories;
// Startup function for loging
public function startup() {
parent::startup();
if (!$this->user->isLoggedIn()) {
$this->flashMessage('Musíte být přihlášeni!', 'alert alert-danger');
$this->redirect('Sign:in', ['backlink' => $this->storeRequest()]);
}
}
// Signout function
public function handleSignOut() {
$this->getUser()->logout();
$this->flashMessage('Byly jste úspěšně odhlášeni!', 'alert alert-success');
$this->redirect('Sign:in');
}
}
Navíc když nechám prázdný tělo, tak si to najde zase jiný presenter kde hlasí nějakou chybu …
- David Matějka
- Moderator | 6445
A nemas tam vice verzi php a php
ukazuje na 5.3? ta chybova
hlaska tomu totiz opravdu odpovida, viz https://3v4l.org/lotFs
- wicked
- Člen | 290
David Matějka napsal(a):
A nemas tam vice verzi php a
php
ukazuje na 5.3? ta chybova hlaska tomu totiz opravdu odpovida, viz https://3v4l.org/lotFs
No .. .koukam ze je to krapet slozitejsi s tim PHP …
Tracy mě ukazuje 5.4.45
Ale terminal vyhodi 5.3.22
Takze tady bude asi ten problem …