Skip to content

Process multiple namespaces for class names and configuration#25

Merged
Ocramius merged 13 commits intolaminas:1.8.xfrom
kliker02:at/namespace-feature-bc
Jun 27, 2022
Merged

Process multiple namespaces for class names and configuration#25
Ocramius merged 13 commits intolaminas:1.8.xfrom
kliker02:at/namespace-feature-bc

Conversation

@kliker02
Copy link
Copy Markdown

@kliker02 kliker02 commented Jun 21, 2022

Q A
BC Break no
New Feature yes

Description

New feature, in accordance with the issue https://github.com/laminas/laminas-mvc-plugin-flashmessenger/issues/3

Fixes #3

tokelex added 5 commits June 21, 2022 18:06
Signed-off-by: Aleksandr <laker.tv@bk.ru>
…config or actual in this version - multidimensional array config
Signed-off-by: Aleksandr <laker.tv@bk.ru>
Signed-off-by: Aleksandr <laker.tv@bk.ru>
@kliker02 kliker02 marked this pull request as draft June 22, 2022 09:18
Signed-off-by: Aleksandr <laker.tv@bk.ru>
@kliker02 kliker02 marked this pull request as ready for review June 22, 2022 15:24
Comment thread src/View/Helper/FlashMessenger.php Outdated
protected $pluginFlashMessenger;

/** @var array<string, FlashMessengerNamespace> */
protected $namespaces = [];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is newly introduced, let's make it private to avoid abuse

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's briefly document (in the docblock) that the keys are the namespace names

Comment thread src/View/Helper/FlashMessenger.php Outdated
* @return FlashMessenger
*/
public function setMessageCloseString($messageCloseString)
public function setMessageCloseString($messageCloseString, string $namespace = 'default')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have the string 'default' in a private const, to prevent copy-paste mistakes, and ease future refactoring

Copy link
Copy Markdown
Author

@kliker02 kliker02 Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I've understood 'default' is a namespace name from Laminas\Mvc\Plugin\FlashMessenger\FlashMessenge::NAMESPACE_DEFAULT

Comment thread src/View/Helper/FlashMessenger.php Outdated
$objNamespace = $this->getNamespace($namespace);
if ($objNamespace !== null) {
return $objNamespace->getClasses();
} else {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else not needed here.

I suggest we remove the negation though:

if ($objNamespace === null) {
    return $this->classMessages[$namespace] ?? '';
}

return $objNamespace->getClasses();

Comment thread src/View/Helper/FlashMessenger.php Outdated

private function getClasses(string $namespace): string
{
$objNamespace = $this->getNamespace($namespace);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid $objNamespace (which is hungarian notation), let's instead use string $namespaceName as input parameter, and then just $namespace for the object form?

Comment thread src/View/Helper/FlashMessenger.php Outdated
{
$this->messageOpenFormat = (string) $messageOpenFormat;
$objNamespace = $this->getNamespace($namespace);
if ($objNamespace !== null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to other locations in the patch:

  • else can be omitted when redundant
  • write the positive conditional first, rather than adding a negation (reduces mental overhead when reading)

Comment thread src/View/Helper/FlashMessengerFactory.php Outdated
Comment on lines +38 to +44
/** @var string|array<string,string|array> $property */
foreach ($configHelper as $property) {
if (is_array($property)) {
$isArrayOneDimensial = false;
break;
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to a private function

Comment thread src/View/Helper/FlashMessengerNamespace.php
Comment thread src/View/Helper/FlashMessengerNamespace.php Outdated
Comment thread src/View/Helper/FlashMessengerFactory.php
@Ocramius
Copy link
Copy Markdown
Member

BTW, overall much better solution than previous approach! Nicely done, @kliker02!

@Ocramius Ocramius added this to the 1.8.0 milestone Jun 23, 2022
@kliker02 kliker02 marked this pull request as draft June 23, 2022 17:15
tokelex added 5 commits June 23, 2022 20:18
Signed-off-by: Aleksandr <laker.tv@bk.ru>
Signed-off-by: Aleksandr <laker.tv@bk.ru>
Signed-off-by: Aleksandr <laker.tv@bk.ru>
@kliker02 kliker02 requested a review from Ocramius June 27, 2022 08:40
Copy link
Copy Markdown
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Would need @froschdesign to provide feedback on how to document this new feature though, since that should be part of this patch

Comment thread src/View/Helper/FlashMessenger.php Outdated
Comment thread src/View/Helper/FlashMessengerFactory.php Outdated
Comment thread src/View/Helper/FlashMessengerFactory.php Outdated
Comment thread src/View/Helper/FlashMessengerFactory.php Outdated
Comment thread src/View/Helper/FlashMessengerFactory.php Outdated
Comment thread src/View/Helper/FlashMessengerNamespace.php
Comment thread src/View/Helper/FlashMessengerNamespace.php
Comment thread src/View/Helper/FlashMessenger.php
tokelex added 2 commits June 27, 2022 17:50
Signed-off-by: Aleksandr <laker.tv@bk.ru>
Signed-off-by: Aleksandr <laker.tv@bk.ru>
@kliker02 kliker02 marked this pull request as ready for review June 27, 2022 15:05
@Ocramius Ocramius self-assigned this Jun 27, 2022
@Ocramius Ocramius changed the title Process multiple namespaces Process multiple namespaces for class names and configuration Jun 27, 2022
Copy link
Copy Markdown
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢 thanks @kliker02!

@kliker02 kliker02 deleted the at/namespace-feature-bc branch June 29, 2022 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

view_helper_config flashmessenger key to support multiple namespaces.

4 participants