Skip to content

Instantly share code, notes, and snippets.

@mzeis
Last active August 29, 2015 14:13
Show Gist options
  • Save mzeis/11a7231cd67a5216ec47 to your computer and use it in GitHub Desktop.
Save mzeis/11a7231cd67a5216ec47 to your computer and use it in GitHub Desktop.
How to (not) intercept the Customer Data Interface

Cyrill suggested the content of the method reflection with

\Zend_Debug::dump([
    $methodReflection->getNamespaceName(),
    $methodReflection->getName(),
    $methodReflection->getFileName()
]);

The result is:

array (size=3)
  0 => string '' (length=0)
  1 => string '___callParent' (length=13)
  2 => string '/var/www/magento2/var/generation/Magento/Customer/Model/Data/Customer/Interceptor.php' (length=85)
<?php # app/code/Mzeis/Customer/Model/Data/Customer.php
namespace Mzeis\Customer\Model\Data;
class Customer
{
public function afterGetFirstname(\Magento\Customer\Api\Data\CustomerInterface $customer, $result)
{
return '|' . $result . '|';
}
}
<?xml version="1.0"?>
<!-- app/code/Mzeis/Customer/etc/di.xml -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Magento\Customer\Api\Data\CustomerInterface">
<plugin name="mzeisCustomer" type="Mzeis\Customer\Model\Data\Customer" sortOrder="1" />
</type>
</config>
Each getter must have description with @return annotation.
#0 /var/www/magento2/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php(288): Magento\Framework\Reflection\TypeProcessor->getGetterReturnType(Object(Zend\Code\Reflection\MethodReflection))
#1 /var/www/magento2/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php(257): Magento\Framework\Reflection\DataObjectProcessor->getMethodMapViaReflection('Magento\\Custome...')
#2 /var/www/magento2/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php(75): Magento\Framework\Reflection\DataObjectProcessor->getMethodsMap('Magento\\Custome...')
#3 /var/www/magento2/lib/internal/Magento/Framework/Api/ExtensibleDataObjectConverter.php(39): Magento\Framework\Reflection\DataObjectProcessor->buildOutputDataArray(Object(Magento\Customer\Model\Data\Customer\Interceptor), 'Magento\\Custome...')
#4 /var/www/magento2/app/code/Magento/Customer/Model/Customer/Mapper.php(38): Magento\Framework\Api\ExtensibleDataObjectConverter->toNestedArray(Object(Magento\Customer\Model\Data\Customer\Interceptor))
#5 /var/www/magento2/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php(33): Magento\Customer\Model\Customer\Mapper->toFlatArray(Object(Magento\Customer\Model\Data\Customer\Interceptor))
#6 /var/www/magento2/var/generation/Magento/Customer/Controller/Adminhtml/Index/Edit/Interceptor.php(117): Magento\Customer\Controller\Adminhtml\Index\Edit->execute()
#7 /var/www/magento2/lib/internal/Magento/Framework/App/Action/Action.php(99): Magento\Customer\Controller\Adminhtml\Index\Edit\Interceptor->execute()
#8 /var/www/magento2/app/code/Magento/Backend/App/AbstractAction.php(221): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#9 [internal function]: Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http))
#10 /var/www/magento2/var/generation/Magento/Customer/Controller/Adminhtml/Index/Edit/Interceptor.php(48): call_user_func_array(Array, Array)
#11 /var/www/magento2/lib/internal/Magento/Framework/Interception/Chain/Chain.php(64): Magento\Customer\Controller\Adminhtml\Index\Edit\Interceptor->___callParent('dispatch', Array)
#12 /var/www/magento2/lib/internal/Magento/Framework/Interception/Chain/Chain.php(57): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Custome...', 'dispatch', Object(Magento\Customer\Controller\Adminhtml\Index\Edit\Interceptor), Array, 'adminAuthentica...')
#13 /var/www/magento2/app/code/Magento/Backend/App/Action/Plugin/Authentication.php(94): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#14 [internal function]: Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Customer\Controller\Adminhtml\Index\Edit\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#15 /var/www/magento2/lib/internal/Magento/Framework/Interception/Chain/Chain.php(62): call_user_func_array(Array, Array)
#16 /var/www/magento2/lib/internal/Magento/Framework/Interception/Chain/Chain.php(57): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Custome...', 'dispatch', Object(Magento\Customer\Controller\Adminhtml\Index\Edit\Interceptor), Array, 'designLoader')
#17 /var/www/magento2/app/code/Magento/Core/App/Action/Plugin/Design.php(38): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#18 [internal function]: Magento\Core\App\Action\Plugin\Design->aroundDispatch(Object(Magento\Customer\Controller\Adminhtml\Index\Edit\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#19 /var/www/magento2/lib/internal/Magento/Framework/Interception/Chain/Chain.php(62): call_user_func_array(Array, Array)
#20 /var/www/magento2/var/generation/Magento/Customer/Controller/Adminhtml/Index/Edit/Interceptor.php(90): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Custome...', 'dispatch', Object(Magento\Customer\Controller\Adminhtml\Index\Edit\Interceptor), Array, 'adminMassaction...')
#21 /var/www/magento2/app/code/Magento/Backend/App/Action/Plugin/MassactionKey.php(32): Magento\Customer\Controller\Adminhtml\Index\Edit\Interceptor->Magento\Customer\Controller\Adminhtml\Index\Edit\{closure}(Object(Magento\Framework\App\Request\Http))
#22 [internal function]: Magento\Backend\App\Action\Plugin\MassactionKey->aroundDispatch(Object(Magento\Customer\Controller\Adminhtml\Index\Edit\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#23 /var/www/magento2/var/generation/Magento/Customer/Controller/Adminhtml/Index/Edit/Interceptor.php(95): call_user_func_array(Array, Array)
#24 /var/www/magento2/var/generation/Magento/Customer/Controller/Adminhtml/Index/Edit/Interceptor.php(132): Magento\Customer\Controller\Adminhtml\Index\Edit\Interceptor->___callPlugins('dispatch', Array, Array)
#25 /var/www/magento2/lib/internal/Magento/Framework/App/FrontController.php(44): Magento\Customer\Controller\Adminhtml\Index\Edit\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#26 [internal function]: Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#27 /var/www/magento2/var/generation/Magento/Framework/App/FrontController/Interceptor.php(48): call_user_func_array(Array, Array)
#28 /var/www/magento2/lib/internal/Magento/Framework/Interception/Chain/Chain.php(64): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#29 /var/www/magento2/var/generation/Magento/Framework/App/FrontController/Interceptor.php(90): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#30 /var/www/magento2/lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php(62): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\App\FrontController\{closure}(Object(Magento\Framework\App\Request\Http))
#31 [internal function]: Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#32 /var/www/magento2/var/generation/Magento/Framework/App/FrontController/Interceptor.php(95): call_user_func_array(Array, Array)
#33 /var/www/magento2/var/generation/Magento/Framework/App/FrontController/Interceptor.php(119): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#34 /var/www/magento2/lib/internal/Magento/Framework/App/Http.php(114): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#35 /var/www/magento2/lib/internal/Magento/Framework/App/Bootstrap.php(244): Magento\Framework\App\Http->launch()
#36 /var/www/magento2/index.php(38): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#37 {main}
@mzeis
Copy link
Author

mzeis commented Jan 14, 2015

@fooman: yes, this did the trick. Did you already suggest it to the Magento team?

@fooman
Copy link

fooman commented Jan 19, 2015

@mzeis not yet - I believe there was some work ongoing to fix another issue (something to do with __wakeup) and wanted to wait for that to see if that solves the same issue but will create a pull request so this doesn't get lost.

@fooman
Copy link

fooman commented Jan 19, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment