Skip to content

Use constructor property promotion in module Ui #37032

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

Open
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/code/Magento/Ui/Block/Component/StepsWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
*/
namespace Magento\Ui\Block\Component;

use Magento\Framework\View\Element\Template;
use Magento\Ui\Block\Component\StepsWizard\StepInterface;

/**
* Multi steps wizard block
*
* @api
* @since 100.0.2
*/
class StepsWizard extends \Magento\Framework\View\Element\Template
class StepsWizard extends Template
{
/**
* Wizard step template
Expand All @@ -26,12 +29,12 @@ class StepsWizard extends \Magento\Framework\View\Element\Template
protected $initData = [];

/**
* @var null|\Magento\Ui\Block\Component\StepsWizard\StepInterface[]
* @var null|StepInterface[]
*/
private $steps;

/**
* @return \Magento\Ui\Block\Component\StepsWizard\StepInterface[]
* @return StepInterface[]
*/
public function getSteps()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
*/
namespace Magento\Ui\Block\Component\StepsWizard;

use Magento\Framework\View\Element\Template;

/**
* Abstract block for multi-step wizard UI
*/
abstract class StepAbstract extends \Magento\Framework\View\Element\Template implements StepInterface
abstract class StepAbstract extends Template implements StepInterface
{
/**
* @inheritdoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
*/
namespace Magento\Ui\Block\Component\StepsWizard;

use Magento\Framework\View\Element\BlockInterface;

/**
* Interface for multi-step wizard blocks
*
* @api
* @since 100.0.2
*/
interface StepInterface extends \Magento\Framework\View\Element\BlockInterface
interface StepInterface extends BlockInterface
{
/**
* Get step caption
Expand Down
8 changes: 1 addition & 7 deletions app/code/Magento/Ui/Block/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,17 @@
*/
class Logger extends Template
{
/**
* @var Config
*/
protected $config;

/**
* @param Template\Context $context
* @param Config $config
* @param array $data
*/
public function __construct(
Template\Context $context,
Config $config,
protected readonly Config $config,
array $data = []
) {
parent::__construct($context, $data);
$this->config = $config;
}

/**
Expand Down
17 changes: 8 additions & 9 deletions app/code/Magento/Ui/Block/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\UiComponentInterface;
use Magento\Ui\Component\AbstractComponent;
use Magento\Ui\Model\UiComponentGenerator;

/**
* This block is wrapper for UI component, this done in order to save compatibility with old widgets mechanism
*/
class Wrapper extends \Magento\Framework\View\Element\Template
class Wrapper extends Template
{
/**
* @var UiComponentGenerator
*/
private $uiComponentGenerator;

/**
* Wrapper constructor.
* @param Template\Context $context
* @param UiComponentGenerator $uiComponentGenerator
* @param array $data
*/
public function __construct(Template\Context $context, UiComponentGenerator $uiComponentGenerator, array $data = [])
public function __construct(
Template\Context $context,
private readonly UiComponentGenerator $uiComponentGenerator,
array $data = []
)
{
parent::__construct($context, $data);
$this->uiComponentGenerator = $uiComponentGenerator;
}

/**
Expand Down Expand Up @@ -86,7 +85,7 @@ private function addDataToChildComponents(UiComponentInterface $uiComponent, arr
*/
public function renderApp($data = [])
{
/** @var \Magento\Ui\Component\AbstractComponent $uiComponent */
/** @var AbstractComponent $uiComponent */
$uiComponent = $this->uiComponentGenerator
->generateUiComponent($this->getData('uiComponent'), $this->getLayout());
$this->injectDataInDataSource($uiComponent, $this->getData());
Expand Down
19 changes: 4 additions & 15 deletions app/code/Magento/Ui/Block/Wysiwyg/ActiveEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Ui\Block\Wysiwyg;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Ui\Model;
Expand All @@ -15,20 +16,10 @@
* @api
* @since 101.1.0
*/
class ActiveEditor extends \Magento\Framework\View\Element\Template
class ActiveEditor extends Template
{
const DEFAULT_EDITOR_PATH = 'mage/adminhtml/wysiwyg/tiny_mce/tinymce5Adapter';

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @var array
*/
private $availableAdapterPaths;

/**
* ActiveEditor constructor.
* @param Context $context
Expand All @@ -38,13 +29,11 @@ class ActiveEditor extends \Magento\Framework\View\Element\Template
*/
public function __construct(
Context $context,
ScopeConfigInterface $scopeConfig,
$availableAdapterPaths = [],
private readonly ScopeConfigInterface $scopeConfig,
private $availableAdapterPaths = [],
array $data = []
) {
parent::__construct($context, $data);
$this->scopeConfig = $scopeConfig;
$this->availableAdapterPaths = $availableAdapterPaths;
}

/**
Expand Down
18 changes: 2 additions & 16 deletions app/code/Magento/Ui/Component/AbstractComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@
*/
abstract class AbstractComponent extends DataObject implements UiComponentInterface
{
/**
* Render context
*
* @var ContextInterface
*/
protected $context;

/**
* @var UiComponentInterface[]
*/
protected $components;

/**
* @var array
*/
Expand All @@ -52,12 +40,10 @@ abstract class AbstractComponent extends DataObject implements UiComponentInterf
* @param array $data
*/
public function __construct(
ContextInterface $context,
array $components = [],
protected readonly ContextInterface $context,
protected array $components = [],
array $data = []
) {
$this->context = $context;
$this->components = $components;
$this->_data = array_replace_recursive($this->_data, $data);
$this->initObservers($this->_data);
}
Expand Down
11 changes: 3 additions & 8 deletions app/code/Magento/Ui/Component/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Ui\Component;

use JsonSerializable;
use Magento\Framework\View\Element\UiComponent\ContextInterface;

/**
Expand All @@ -14,25 +15,19 @@ class Action extends AbstractComponent
{
const NAME = 'action';

/**
* @var array|\JsonSerializable
*/
protected $actions;

/**
* @param ContextInterface $context
* @param array $components
* @param array $data
* @param array|\JsonSerializable $actions
* @param array|JsonSerializable $actions
*/
public function __construct(
ContextInterface $context,
array $components = [],
array $data = [],
$actions = null
protected $actions = null
) {
parent::__construct($context, $components, $data);
$this->actions = $actions;
}

/**
Expand Down
19 changes: 4 additions & 15 deletions app/code/Magento/Ui/Component/Bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Ui\Api\BookmarkManagementInterface;
use Magento\Ui\Api\BookmarkRepositoryInterface;
use Magento\Ui\Api\Data\BookmarkInterface;

/**
* Class Bookmark
Expand All @@ -17,21 +18,11 @@ class Bookmark extends AbstractComponent
{
const NAME = 'bookmark';

/**
* @var BookmarkRepositoryInterface
*/
protected $bookmarkRepository;

/**
* @var FilterBuilder
*/
protected $filterBuilder;

/**
* @var BookmarkManagementInterface
*/
protected $bookmarkManagement;

/**
* @param ContextInterface $context
* @param BookmarkRepositoryInterface $bookmarkRepository
Expand All @@ -41,14 +32,12 @@ class Bookmark extends AbstractComponent
*/
public function __construct(
ContextInterface $context,
BookmarkRepositoryInterface $bookmarkRepository,
BookmarkManagementInterface $bookmarkManagement,
protected readonly BookmarkRepositoryInterface $bookmarkRepository,
protected readonly BookmarkManagementInterface $bookmarkManagement,
array $components = [],
array $data = []
) {
parent::__construct($context, $components, $data);
$this->bookmarkRepository = $bookmarkRepository;
$this->bookmarkManagement = $bookmarkManagement;
}

/**
Expand All @@ -72,7 +61,7 @@ public function prepare()
$config = [];
if (!empty($namespace)) {
$bookmarks = $this->bookmarkManagement->loadByNamespace($namespace);
/** @var \Magento\Ui\Api\Data\BookmarkInterface $bookmark */
/** @var BookmarkInterface $bookmark */
foreach ($bookmarks->getItems() as $bookmark) {
if ($bookmark->isCurrent()) {
$config['activeIndex'] = $bookmark->getIdentifier();
Expand Down
30 changes: 8 additions & 22 deletions app/code/Magento/Ui/Component/Control/ActionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,13 @@ class ActionPool implements ActionPoolInterface
*/
const ACTIONS_PAGE_TOOLBAR = 'page.actions.toolbar';

/**
* Render context
*
* @var Context
*/
protected $context;

/**
* Actions pool
*
* @var Item[]
*/
protected $items;

/**
* Button factory
*
* @var ItemFactory
*/
protected $itemFactory;

/**
* @var AbstractBlock
*/
Expand All @@ -53,10 +39,10 @@ class ActionPool implements ActionPoolInterface
* @param Context $context
* @param ItemFactory $itemFactory
*/
public function __construct(Context $context, ItemFactory $itemFactory)
{
$this->context = $context;
$this->itemFactory = $itemFactory;
public function __construct(
protected readonly Context $context,
protected readonly ItemFactory $itemFactory
) {
}

/**
Expand Down Expand Up @@ -120,9 +106,9 @@ public function update($key, array $data)
/**
* Add html block
*
* @param string $type
* @param string $name
* @param array $arguments
* @param string $type
* @param string $name
* @param array $arguments
* @return void
*/
public function addHtmlBlock($type, $name = '', array $arguments = [])
Expand All @@ -144,7 +130,7 @@ public function addHtmlBlock($type, $name = '', array $arguments = [])
protected function createContainer($key, UiComponentInterface $view)
{
$container = $this->context->getPageLayout()->createBlock(
\Magento\Ui\Component\Control\Container::class,
Container::class,
'container-' . $view->getName() . '-' . $key,
[
'data' => [
Expand Down
7 changes: 1 addition & 6 deletions app/code/Magento/Ui/Component/Control/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
*/
class Button extends Template implements ControlInterface
{
/**
* @var Random
*/
private $random;

/**
* @var SecureHtmlRenderer
*/
Expand All @@ -36,7 +31,7 @@ class Button extends Template implements ControlInterface
public function __construct(
Context $context,
array $data = [],
?Random $random = null,
private ?Random $random = null,
?SecureHtmlRenderer $htmlRenderer = null
) {
parent::__construct($context, $data);
Expand Down
Loading