@@ -104,13 +104,13 @@ abstract class Presenter extends Control implements Application\IPresenter
104104 private bool $ startupCheck = false ;
105105 private ?Nette \Application \Request $ lastCreatedRequest ;
106106 private ?array $ lastCreatedRequestFlag ;
107- private Nette \Http \IRequest $ httpRequest ;
108- private Nette \Http \IResponse $ httpResponse ;
109- private ?Nette \Http \Session $ session = null ;
110- private ?Nette \Application \IPresenterFactory $ presenterFactory = null ;
111- private ?Nette \Routing \Router $ router = null ;
112- private ?Nette \Security \User $ user = null ;
113- private ?TemplateFactory $ templateFactory = null ;
107+ private readonly Nette \Http \IRequest $ httpRequest ;
108+ private readonly Nette \Http \IResponse $ httpResponse ;
109+ private readonly ?Nette \Http \Session $ session ;
110+ private readonly ?Nette \Application \IPresenterFactory $ presenterFactory ;
111+ private readonly ?Nette \Routing \Router $ router ;
112+ private readonly ?Nette \Security \User $ user ;
113+ private readonly ?TemplateFactory $ templateFactory ;
114114 private Nette \Http \UrlScript $ refUrlCache ;
115115
116116
@@ -806,7 +806,7 @@ protected function createRequest(
806806 $ presenter = $ module . $ sep . $ presenter ;
807807 }
808808
809- if (! $ this ->presenterFactory ) {
809+ if (empty ( $ this ->presenterFactory ) ) {
810810 throw new Nette \InvalidStateException ('Unable to create link to other presenter, service PresenterFactory has not been set. ' );
811811 }
812812
@@ -985,7 +985,7 @@ protected function requestToUrl(Application\Request $request, ?bool $relative =
985985 $ this ->refUrlCache = new Http \UrlScript ($ url ->getHostUrl () . $ url ->getScriptPath ());
986986 }
987987
988- if (! $ this ->router ) {
988+ if (empty ( $ this ->router ) ) {
989989 throw new Nette \InvalidStateException ('Unable to generate URL, service Router has not been set. ' );
990990 }
991991
@@ -1374,11 +1374,8 @@ final public function injectPrimary(
13741374 ?Http \Session $ session = null ,
13751375 ?Nette \Security \User $ user = null ,
13761376 ?TemplateFactory $ templateFactory = null ,
1377- ) {
1378- if (isset ($ this ->presenterFactory )) {
1379- throw new Nette \InvalidStateException ('Method ' . __METHOD__ . ' is intended for initialization and should not be called more than once. ' );
1380- }
1381-
1377+ ): void
1378+ {
13821379 $ this ->presenterFactory = $ presenterFactory ;
13831380 $ this ->router = $ router ;
13841381 $ this ->httpRequest = $ httpRequest ;
@@ -1403,7 +1400,7 @@ final public function getHttpResponse(): Http\IResponse
14031400
14041401 final public function getSession (?string $ namespace = null ): Http \Session |Http \SessionSection
14051402 {
1406- if (! $ this ->session ) {
1403+ if (empty ( $ this ->session ) ) {
14071404 throw new Nette \InvalidStateException ('Service Session has not been set. ' );
14081405 }
14091406
@@ -1415,20 +1412,12 @@ final public function getSession(?string $namespace = null): Http\Session|Http\S
14151412
14161413 final public function getUser (): Nette \Security \User
14171414 {
1418- if (!$ this ->user ) {
1419- throw new Nette \InvalidStateException ('Service User has not been set. ' );
1420- }
1421-
1422- return $ this ->user ;
1415+ return $ this ->user ?? throw new Nette \InvalidStateException ('Service User has not been set. ' );
14231416 }
14241417
14251418
14261419 final public function getTemplateFactory (): TemplateFactory
14271420 {
1428- if (!$ this ->templateFactory ) {
1429- throw new Nette \InvalidStateException ('Service TemplateFactory has not been set. ' );
1430- }
1431-
1432- return $ this ->templateFactory ;
1421+ return $ this ->templateFactory ?? throw new Nette \InvalidStateException ('Service TemplateFactory has not been set. ' );
14331422 }
14341423}
0 commit comments