Pomoc s prechodem z 2.2 na 2.4

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
+
0
-

snazim se migrovat funkcni web z verze 2.2 na 2.4

vyhazuje mi to:

Nette\DI\ServiceCreationException
Service ‚routing.router‘: Multiple services of type App\RouterFactory found: 24_App_RouterFactory, 25_App_RouterFactory

poradite, kde muze byt problem? Popripade si reknete jake dalsi soubory chcete videt

takhle vypada muj config neon

<?php
#
# 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

dibi:
	host: 127.0.0.1
	username: root
	password:
	database: db
	lazy: TRUE


application:
	errorPresenter: Error
	mapping:
		*: App\*Module\Presenters\*Presenter

session:
	expiration: 14 days


services:
	- App\Model\UserManager
	- App\RouterFactory
	router: @App\RouterFactory::createRouter

extensions:
	dibi: Dibi\Bridges\Nette\DibiExtension22
?>
CZechBoY
Člen | 3608
+
0
-

Odeber řádek - App\RouterFactory

+
0
-

po zakomentovani radku se objevila tato chyba:

Service ‚security.user‘: Multiple services of type Nette\Security\IAuthenticator found: 22_App_Model_UserManager, 23_App_Model_UserManager

V pripade ze bych mel zakomentovat i tento radek:.
- App\Model\UserManager

tak pote se objevi

Class App\RouterFactory is static and cannot be instantiated.

CZechBoY
Člen | 3608
+
0
-

Můžeš ukázat hlavičku toho UserManageru? např. class UserManager implements IAuthenticator

CZechBoY
Člen | 3608
+
0
-

Tak ten router zaregistruj takhle:

	router: App\RouterFactory()::createRouter
+
0
-

UserManager je originalni soubor z archivu nette 2.4 (sandbox)

<?php
<?php

namespace App\Model;

use Nette;
use Nette\Security\Passwords;


/**
 * Users management.
 */
class UserManager implements Nette\Security\IAuthenticator
{
	use Nette\SmartObject;

	const
		TABLE_NAME = 'users',
		COLUMN_ID = 'id',
		COLUMN_NAME = 'username',
		COLUMN_PASSWORD_HASH = 'password',
		COLUMN_EMAIL = 'email',
		COLUMN_ROLE = 'role';


	/** @var Nette\Database\Context */
	private $database;


	public function __construct(Nette\Database\Context $database)
	{
		$this->database = $database;
	}


	/**
	 * Performs an authentication.
	 * @return Nette\Security\Identity
	 * @throws Nette\Security\AuthenticationException
	 */
	public function authenticate(array $credentials)
	{
		list($username, $password) = $credentials;

		$row = $this->database->table(self::TABLE_NAME)->where(self::COLUMN_NAME, $username)->fetch();

		if (!$row) {
			throw new Nette\Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);

		} elseif (!Passwords::verify($password, $row[self::COLUMN_PASSWORD_HASH])) {
			throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);

		} elseif (Passwords::needsRehash($row[self::COLUMN_PASSWORD_HASH])) {
			$row->update([
				self::COLUMN_PASSWORD_HASH => Passwords::hash($password),
			]);
		}

		$arr = $row->toArray();
		unset($arr[self::COLUMN_PASSWORD_HASH]);
		return new Nette\Security\Identity($row[self::COLUMN_ID], $row[self::COLUMN_ROLE], $arr);
	}


	/**
	 * Adds new user.
	 * @param  string
	 * @param  string
	 * @param  string
	 * @return void
	 * @throws DuplicateNameException
	 */
	public function add($username, $email, $password)
	{
		try {
			$this->database->table(self::TABLE_NAME)->insert([
				self::COLUMN_NAME => $username,
				self::COLUMN_PASSWORD_HASH => Passwords::hash($password),
				self::COLUMN_EMAIL => $email,
			]);
		} catch (Nette\Database\UniqueConstraintViolationException $e) {
			throw new DuplicateNameException;
		}
	}

}



class DuplicateNameException extends \Exception
{}

?>

jinak jsem provedl zmenu
do obou config.neonu

<?php
#
# 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

dibi:
	host: 127.0.0.1
	username: root
	password:
	database: db
	lazy: TRUE


application:
	errorPresenter: Error
	mapping:
		*: App\*Module\Presenters\*Presenter

session:
	expiration: 14 days


services:
#	- App\Model\UserManager
#	- App\RouterFactory
	router: App\RouterFactory()::createRouter

extensions:
	dibi: Dibi\Bridges\Nette\DibiExtension22
?>

Class App\RouterFactory is static and cannot be instantiated.

Editoval treawouw@docmail.cz (31. 8. 2016 14:41)

CZechBoY
Člen | 3608
+
0
-

Obou config.neon? Máš ještě nějakej další?
Ta metoda createRouter je statická nebo třídní?

+
0
-

config.neon mam lokalni a produkcni, to ja jen zminuju, abychom mohli vyloucit ze upravuji spatny config.neon

public static function createRouter()

RouterFactory.php take pochazi z nette 2.4 sandbox a ja si tam jen prekopiroval svoje routy

Editoval treawouw@docmail.cz (31. 8. 2016 14:47)

CZechBoY
Člen | 3608
+
0
-

A co má v těch ostatních neonech? Definuješ tam nějaký služby nebo jen citlivý údaje jako přihlášení k db atd?

+
0
-

oba config.neony jsou uplne stejny

Editoval treawouw@docmail.cz (31. 8. 2016 14:51)

hitzoR
Člen | 51
+
+2
-

Tak to bude ten problém, proč ti to píše, že máš více instancí IAuthenticator. Protože ho iniciuješ dvakrát. :D V local configu mají být ideálně jen údaje k databázi, případně něco, co je specifické pro daný server.

+
0
-

diky, vyresil jsem to kdyz jsem zacal postupne editovat novy sandbox

ale je to jak rikas hitzoR