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

Missing dynamic return type for Nette\Http\Session::getSection() #77

Open
KacerCZ opened this issue Aug 31, 2021 · 4 comments
Open

Missing dynamic return type for Nette\Http\Session::getSection() #77

KacerCZ opened this issue Aug 31, 2021 · 4 comments

Comments

@KacerCZ
Copy link

KacerCZ commented Aug 31, 2021

Method Nette\Http\Session::getSection() has optional second parameter which can change class of returned object.
This extension does not support it and always returns Nette\Http\SessionSection class.

@lukasojd
Copy link

+1

@TomasVotruba
Copy link
Contributor

Hi, could you provide PHP code examples of these 2 states? (I don't use Nette on this level)
I might try to add the extension then 👍

@KacerCZ
Copy link
Author

KacerCZ commented Feb 4, 2022

Here is the definition of method: https://github.com/nette/http/blob/04224e7fd25c70390419b463f4e2b26042ea5e2a/src/Http/Session.php#L314

In following examples $sessionHandler is instance of \Nette\Http\Session.

Example using default class for session section:

$section = $sessionHandler->getSection('mySection');

Variable $section contains instance of \Nette\Http\SessionSection.

Example using diferent class for session section:

class MySection extends \Nette\Http\SessionSection {}

$section = $sessionHandler->getSection('mySection', MySection::class);

Variable $section contains instance of MySection.

@lulco
Copy link
Contributor

lulco commented Apr 14, 2023

see https://github.com/phpstan/phpstan-nette/blob/1.1.x/stubs/ComponentModel/Container.stub

I think this is similar case and you can handle it with stub. I think something like this:

/**
  * @template T of \Nette\Http\SessionSection
  * @phpstan-param class-string<T> $class
  * @phpstan-return T
  */
public function getSection(string $section, string $class = SessionSection::class): \Nette\Http\SessionSection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants