Fix deepclone, generation and file loading bugs
This commit is contained in:
parent
b1c679edce
commit
6029e70bff
4
generate
4
generate
@ -64,8 +64,8 @@ software, even if advised of the possibility of such damage.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (file_exists('vendor/autoload.php')) {
|
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
|
||||||
require_once('vendor/autoload.php');
|
require_once(__DIR__ . '/vendor/autoload.php');
|
||||||
} elseif (file_exists('daux.phar')) {
|
} elseif (file_exists('daux.phar')) {
|
||||||
define('PHAR_DIR', __DIR__);
|
define('PHAR_DIR', __DIR__);
|
||||||
require_once("phar://" . __DIR__ . "/daux.phar/vendor/autoload.php");
|
require_once("phar://" . __DIR__ . "/daux.phar/vendor/autoload.php");
|
||||||
|
@ -105,13 +105,14 @@ class Compiler
|
|||||||
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_files.php'));
|
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_files.php'));
|
||||||
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_namespaces.php'));
|
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_namespaces.php'));
|
||||||
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_real.php'));
|
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_real.php'));
|
||||||
$staticAutoload = new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_static.php');
|
|
||||||
if ($staticAutoload->isFile()) {
|
|
||||||
$this->addFile($phar, $staticAutoload);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/ClassLoader.php'));
|
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/ClassLoader.php'));
|
||||||
|
|
||||||
|
if (file_exists(__DIR__ . '/../vendor/composer/autoload_static.php')) {
|
||||||
|
$content = file_get_contents(__DIR__ . '/../vendor/composer/autoload_static.php');
|
||||||
|
$content = str_replace('__DIR__ . \'/../..\' . \'/daux\'', 'PHAR_DIR . \'/daux\'', $content);
|
||||||
|
$phar->addFromString('vendor/composer/autoload_static.php', $content);
|
||||||
|
}
|
||||||
|
|
||||||
$content = file_get_contents(__DIR__ . '/../vendor/composer/autoload_psr4.php');
|
$content = file_get_contents(__DIR__ . '/../vendor/composer/autoload_psr4.php');
|
||||||
$content = str_replace('$baseDir . \'/daux\'', 'PHAR_DIR . \'/daux\'', $content);
|
$content = str_replace('$baseDir . \'/daux\'', 'PHAR_DIR . \'/daux\'', $content);
|
||||||
$phar->addFromString('vendor/composer/autoload_psr4.php', $content);
|
$phar->addFromString('vendor/composer/autoload_psr4.php', $content);
|
||||||
|
@ -184,21 +184,34 @@ class Processor implements DocumentProcessorInterface
|
|||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function setNull($object, $property) {
|
||||||
|
$prop = new \ReflectionProperty(get_class($object), $property);
|
||||||
|
$prop->setAccessible(true);
|
||||||
|
$prop->setValue($object, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Heading $node
|
* @param Heading $node
|
||||||
* @return Node[]
|
* @return Node[]
|
||||||
*/
|
*/
|
||||||
protected function cloneChildren(Heading $node)
|
protected function cloneChildren(Heading $node)
|
||||||
{
|
{
|
||||||
$deepCopy = new DeepCopy();
|
|
||||||
|
|
||||||
$firstClone = clone $node;
|
$firstClone = clone $node;
|
||||||
|
|
||||||
// We have no choice but to hack into the system to reset the parent, to avoid cloning the complete tree
|
// We have no choice but to hack into the
|
||||||
$method = new ReflectionMethod(get_class($firstClone), 'setParent');
|
// system to reset the parent, previous and next
|
||||||
$method->setAccessible(true);
|
$this->setNull($firstClone, 'parent');
|
||||||
$method->invoke($firstClone, null);
|
$this->setNull($firstClone, 'previous');
|
||||||
|
$this->setNull($firstClone, 'next');
|
||||||
|
|
||||||
|
// Also, the child elements need to know the next parents
|
||||||
|
foreach ($firstClone->children() as $subnode) {
|
||||||
|
$method = new ReflectionMethod(get_class($subnode), 'setParent');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
$method->invoke($subnode, $firstClone);
|
||||||
|
}
|
||||||
|
|
||||||
|
$deepCopy = new DeepCopy();
|
||||||
return $deepCopy->copy($firstClone)->children();
|
return $deepCopy->copy($firstClone)->children();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user