Skip to content

Commit

Permalink
improve Spyc dependency loading
Browse files Browse the repository at this point in the history
Spyc is a common dependency. To avoid double class loading, inject a
“class_exists” check around the Spyc class definition. It’s not
bullet-proof but should help in some situations at least.

fixes #832
issue #811
fixes #542
  • Loading branch information
eteubert committed Feb 16, 2016
1 parent 415db64 commit 28faad6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bin/fix_spyc_loading.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
$spyc_class_file = "vendor/mustangostang/spyc/Spyc.php";

$handle = fopen($spyc_class_file, "r+");
$content = fread($handle, filesize($spyc_class_file));

// if the check has not already been added only
if (!stripos($content, "if (!class_exists('Spyc'))")) {
$content = str_replace("class Spyc", "if (!class_exists('Spyc')) {\nclass Spyc", $content);
$content .= "\n}\n";

rewind($handle);
fwrite($handle, $content);
}

fclose($handle);
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@
"pear/pear_exception": "1.0.*@dev",
"podlove/comment-introspection": "dev-master",
"phpunit/phpunit": "4.7.*"
},
"scripts": {
"post-update-cmd": [ "php bin/fix_spyc_loading.php" ],
"post-install-cmd": [ "php bin/fix_spyc_loading.php" ]
}
}

0 comments on commit 28faad6

Please sign in to comment.