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
Added a new collector for Hooks #8327
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* 2007-2017 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2017 PrestaShop SA | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Core\Module; | ||
|
||
/** | ||
* Define what should be a module. | ||
* Note:We don't typeHint on old Module class to not create hard dependency with Legacy. | ||
*/ | ||
interface ModuleInterface | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
/** | ||
* 2007-2017 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2017 PrestaShop SA | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShopBundle\DataCollector; | ||
|
||
use Symfony\Component\HttpKernel\DataCollector\DataCollector; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* Collect all information about Legacy hooks and make it available | ||
* in the Symfony Web profiler. | ||
*/ | ||
final class HookDataCollector extends DataCollector | ||
{ | ||
/** | ||
* @var HookRegistry | ||
*/ | ||
private $registry; | ||
|
||
public function __construct(HookRegistry $registry) | ||
{ | ||
$this->registry = $registry; | ||
} | ||
|
||
/** | ||
* @{inheritdoc} | ||
*/ | ||
public function collect(Request $request, Response $response, \Exception $exception = null) | ||
{ | ||
$hooks = $this->registry->getHooks(); | ||
$calledHooks = $this->registry->getCalledHooks(); | ||
$notCalledHooks = $this->registry->getNotCalledHooks(); | ||
$this->data = array( | ||
'hooks' => $this->stringifyHookArguments($hooks), | ||
'calledHooks' => $this->stringifyHookArguments($calledHooks), | ||
'notCalledHooks' => $this->stringifyHookArguments($notCalledHooks), | ||
); | ||
} | ||
|
||
/** | ||
* Return the list of every dispatched legacy hooks during one request. | ||
* @return array | ||
*/ | ||
public function getHooks() | ||
{ | ||
return $this->data['hooks']; | ||
} | ||
|
||
/** | ||
* Return the list of every called legacy hooks during one request. | ||
* @return array | ||
*/ | ||
public function getCalledHooks() | ||
{ | ||
return $this->data['calledHooks']; | ||
} | ||
|
||
/** | ||
* Return the list of every uncalled legacy hooks during oHookne request. | ||
* @return array | ||
*/ | ||
public function getNotCalledHooks() | ||
{ | ||
return $this->data['notCalledHooks']; | ||
} | ||
|
||
/** | ||
* @{inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'ps.hooks_collector'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this value should be stored in a constant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? this value is only reused on service declaration. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way I see it, constants are not (only) about reuse, they are also about not having important pieces of information stored as literals buried in the code. One of the advantages of constants is that they are declared at the top of the class in an organized manner, which in my opinion improves clarity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, this don't apply here, this information is totaly useless for the developer and will increase what we call "visual debt" :) |
||
} | ||
|
||
/** | ||
* @param array $hooksList | ||
* @return array a better representation of arguments for HTML rendering. | ||
*/ | ||
private function stringifyHookArguments(array &$hooksList) | ||
{ | ||
foreach ($hooksList as &$hookList) { | ||
foreach ($hookList as &$hook) { | ||
$hook['args'] = $this->varToString($hook['args']); | ||
foreach ($hook['modules'] as &$modulesByType) { | ||
foreach ($modulesByType as &$module) { | ||
if (array_key_exists('args', $module)) { | ||
$module['args'] = $this->varToString($module['args']); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return $hooksList; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we add this interface? If the legacy class is supposed to disappear, I do not understand this change.