Skip to content
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

Remove support for HHVM #158

Open
wants to merge 1 commit into
base: master
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
7 changes: 0 additions & 7 deletions Patchwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@ function always($value)

Utils\markMissedCallables();

if (Utils\runningOnHHVM()) {
# no preprocessor needed on HHVM;
# just let Patchwork become a wrapper for fb_intercept()
spl_autoload_register('Patchwork\CallRerouting\deployQueue');
return;
}

CodeManipulation\Stream::discoverOtherWrapper();
CodeManipulation\Stream::wrap();

Expand Down
32 changes: 9 additions & 23 deletions src/CallRerouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ function connect($source, callable $target, Handle $handle = null, $partOfWildca
}
} else {
$handle = queueConnection($source, $target, $handle);
if (Utils\runningOnHHVM()) {
connectOnHHVM("$class::$method", $handle);
}
}
}
attachExistenceAssertion($handle, $source);
Expand Down Expand Up @@ -166,22 +163,13 @@ function validate($function, $partOfWildcard = false)
if ($reflection->isInternal() && !in_array($name, Config\getRedefinableInternals())) {
throw new Exceptions\NotUserDefined($function);
}
if (Utils\runningOnHHVM()) {
if ($reflection->isInternal()) {
throw new Exceptions\InternalsNotSupportedOnHHVM($function);
}
return;
}
if (!$reflection->isInternal() && !inPreprocessedFile($function) && !$partOfWildcard) {
throw new Exceptions\DefinedTooEarly($function);
}
}

function inPreprocessedFile($callable)
{
if (Utils\runningOnHHVM()) {
return true;
}
if (Utils\isOwnName(Utils\callableToString($callable))) {
return false;
}
Expand All @@ -196,9 +184,6 @@ function connectFunction($function, callable $target, Handle $handle = null)
$routes = &State::$routes[null][$function];
$offset = Utils\append($routes, [$target, $handle]);
$handle->addReference($routes[$offset]);
if (Utils\runningOnHHVM()) {
connectOnHHVM($function, $handle);
}
return $handle;
}

Expand Down Expand Up @@ -236,18 +221,13 @@ function connectMethod($function, callable $target, Handle $handle = null)
$reflection = Utils\reflectCallable($function);
$declaringClass = $reflection->getDeclaringClass();
$class = $declaringClass->getName();
if (!Utils\runningOnHHVM()) {
$aliases = $declaringClass->getTraitAliases();
if (isset($aliases[$method])) {
list($trait, $method) = explode('::', $aliases[$method]);
}
$aliases = $declaringClass->getTraitAliases();
if (isset($aliases[$method])) {
list($trait, $method) = explode('::', $aliases[$method]);
}
$routes = &State::$routes[$class][$method];
$offset = Utils\append($routes, [$target, $handle]);
$handle->addReference($routes[$offset]);
if (Utils\runningOnHHVM()) {
connectOnHHVM("$class::$method", $handle);
}
return $handle;
}

Expand Down Expand Up @@ -361,6 +341,9 @@ function relay(array $args = null)
return $result;
}

/**
* @deprecated 2.2.0
*/
function connectOnHHVM($function, Handle $handle)
{
fb_intercept($function, function($name, $obj, $args, $data, &$done) {
Expand All @@ -380,6 +363,9 @@ function connectOnHHVM($function, Handle $handle)
$handle->addExpirationHandler(getHHVMExpirationHandler($function));
}

/**
* @deprecated 2.2.0
*/
function getHHVMExpirationHandler($function)
{
return function() use ($function) {
Expand Down
3 changes: 3 additions & 0 deletions src/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class InternalMethodsNotSupported extends CallbackException
protected $message = "Methods of internal classes (such as %s) are not yet redefinable in Patchwork 2.1.";
}

/**
* @deprecated 2.2.0
*/
class InternalsNotSupportedOnHHVM extends CallbackException
{
protected $message = "As of version 2.1, Patchwork cannot redefine internal functions and methods (such as %s) on HHVM.";
Expand Down
17 changes: 5 additions & 12 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function generatorsSupported()
return version_compare(PHP_VERSION, "5.5", ">=");
}

/**
* @deprecated 2.2.0
*/
function runningOnHHVM()
{
return defined("HHVM_VERSION");
Expand Down Expand Up @@ -235,18 +238,8 @@ function getUserDefinedMethods()
static $traitCount = 0;
$classes = getUserDefinedClasses();
$traits = getUserDefinedTraits();
if (runningOnHHVM()) {
# cannot rely on the order of get_declared_classes()
static $previousClasses = [];
static $previousTraits = [];
$newClasses = array_diff($classes, $previousClasses);
$newTraits = array_diff($traits, $previousTraits);
$previousClasses = $classes;
$previousTraits = $traits;
} else {
$newClasses = array_slice($classes, $classCount);
$newTraits = array_slice($traits, $traitCount);
}
$newClasses = array_slice($classes, $classCount);
$newTraits = array_slice($traits, $traitCount);
foreach (array_merge($newClasses, $newTraits) as $newClass) {
foreach (get_class_methods($newClass) as $method) {
$result[] = $newClass . '::' . $method;
Expand Down
2 changes: 1 addition & 1 deletion tests/inheritance-delayed-redefinition.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Inheriting method patches + delayed redefinition (suspected HHVM issue)
Inheriting method patches + delayed redefinition

--FILE--
<?php
Expand Down
4 changes: 0 additions & 4 deletions tests/internals.phpt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
--TEST--
Redefinition of internal functions

--SKIPIF--
<?php !defined('HHVM_VERSION')
or die('skip because the redefinition of internals is not yet implemented for HHVM') ?>

--FILE--
<?php

Expand Down
4 changes: 0 additions & 4 deletions tests/language-constructs.phpt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
--TEST--
Redefining language constructs like die(), echo, require_once etc. (https://github.com/antecedent/patchwork/issues/59)

--SKIPIF--
<?php !defined('HHVM_VERSION')
or die('skip because the redefinition of language constructs is not yet implemented for HHVM') ?>

--FILE--
<?php

Expand Down
24 changes: 9 additions & 15 deletions tests/patchability.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@ function functionThatIsNotPreprocessed()

assert(Patchwork\hasMissed('functionThatIsNotPreprocessed'));

if (!Patchwork\Utils\runningOnHHVM()) {
expectException('Patchwork\Exceptions\DefinedTooEarly', function() {
Patchwork\replace("functionThatIsNotPreprocessed", Patchwork\always(null));
});
}
expectException('Patchwork\Exceptions\DefinedTooEarly', function() {
Patchwork\replace("functionThatIsNotPreprocessed", Patchwork\always(null));
});

$h = Patchwork\replace("functionThatIsNotDefined", Patchwork\always(null));
Patchwork\assertEventuallyDefined($h);

if (!Patchwork\Utils\runningOnHHVM()) {
expectException('Patchwork\Exceptions\DefinedTooEarly', function() {
Patchwork\replaceLater("functionThatIsNotPreprocessed", Patchwork\always(null));
});
}
expectException('Patchwork\Exceptions\DefinedTooEarly', function() {
Patchwork\replaceLater("functionThatIsNotPreprocessed", Patchwork\always(null));
});

Patchwork\replaceLater("getInteger", function() {
return 42;
Expand All @@ -43,11 +39,9 @@ assert(getInteger() === 42);

require __DIR__ . "/includes/Singleton.php";

if (!Patchwork\Utils\runningOnHHVM()) {
expectException('Patchwork\Exceptions\DefinedTooEarly', function() {
Patchwork\replace("Singleton::getInstance", Patchwork\always(null));
});
}
expectException('Patchwork\Exceptions\DefinedTooEarly', function() {
Patchwork\replace("Singleton::getInstance", Patchwork\always(null));
});

$h = Patchwork\replace('anotherUndefinedFunction', Patchwork\always(null));
Patchwork\assertEventuallyDefined($h);
Expand Down
3 changes: 0 additions & 3 deletions tests/splat.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ https://github.com/antecedent/patchwork/issues/56
version_compare(PHP_VERSION, "5.6", ">=")
or die("skip because this bug only occurs in PHP 5.6 and up");

!defined('HHVM_VERSION')
or die('skip because the redefinition of internals is not yet implemented for HHVM');

?>

--FILE--
Expand Down
Loading