Chris@0: Chris@0: * Marcello Duarte Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Prophecy\Doubler\ClassPatch; Chris@0: Chris@0: use Prophecy\Doubler\Generator\Node\ClassNode; Chris@0: Chris@0: /** Chris@0: * Exception patch for HHVM to remove the stubs from special methods Chris@0: * Chris@0: * @author Christophe Coevoet Chris@0: */ Chris@0: class HhvmExceptionPatch implements ClassPatchInterface Chris@0: { Chris@0: /** Chris@0: * Supports exceptions on HHVM. Chris@0: * Chris@0: * @param ClassNode $node Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function supports(ClassNode $node) Chris@0: { Chris@0: if (!defined('HHVM_VERSION')) { Chris@0: return false; Chris@0: } Chris@0: Chris@0: return 'Exception' === $node->getParentClass() || is_subclass_of($node->getParentClass(), 'Exception'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Removes special exception static methods from the doubled methods. Chris@0: * Chris@0: * @param ClassNode $node Chris@0: * Chris@0: * @return void Chris@0: */ Chris@0: public function apply(ClassNode $node) Chris@0: { Chris@0: if ($node->hasMethod('setTraceOptions')) { Chris@0: $node->getMethod('setTraceOptions')->useParentCode(); Chris@0: } Chris@0: if ($node->hasMethod('getTraceOptions')) { Chris@0: $node->getMethod('getTraceOptions')->useParentCode(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getPriority() Chris@0: { Chris@0: return -50; Chris@0: } Chris@0: }