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
Add support for custom streams and paths #118
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
dfc38f8
Do not use realtive paths with single dot
lisachenko 82ac9a1
Enable checking for eof for phar archives, because there is a bug wit…
lisachenko dc1f2f8
More straightforward implementation of stream filter for better reada…
lisachenko 1cd6fcc
Use strpos for absolute path checking. This check also verifies prese…
lisachenko 5a20b31
Add prebuilCache option to disable check for writable directory and t…
lisachenko e392932
Fix a bug when date modification equals to cache creation date
lisachenko ad253ef
Use PathResolver instead of realpath() and stream_resolve_include_pat…
lisachenko 1b884fa
Delay initialization of AOP loader to speed up loading of system clas…
lisachenko 7edb756
Simplify configuration merging, do not require recursive replace
lisachenko 71d4766
Improve performance of rewriting URLs by using static variables and c…
lisachenko 34d4740
Direct call of filters for warmup command to avoid influence of prebu…
lisachenko f82f8a8
Add an empty line before returns and update phpDoc
lisachenko 93b36b9
Add test case for PathResolver and fix some bugs in the logic
lisachenko 985d00c
Use dynamic constant for cache dir instead of full path in the source…
lisachenko 40490bc
Simplify path resolve check for normal files, this also fixes issue w…
lisachenko 0b0e5b8
Add a failover for non-existent files to manual path calculation and …
lisachenko 5ccb7ed
Merge branch 'master' into feature/phar-support
lisachenko 1fe8c35
Sync header with master branch
lisachenko File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,13 +38,6 @@ class SourceTransformingLoader extends PhpStreamFilter implements LoadTimeWeaver | |
*/ | ||
protected $data = ''; | ||
|
||
/** | ||
* Filter bucket resource | ||
* | ||
* @var null|resource | ||
*/ | ||
protected $bucket = null; | ||
|
||
/** | ||
* List of transformers | ||
* | ||
|
@@ -100,23 +93,17 @@ public function filter($in, $out, &$consumed, $closing) | |
{ | ||
while ($bucket = stream_bucket_make_writeable($in)) { | ||
$this->data .= $bucket->data; | ||
$this->bucket = $bucket; | ||
$consumed = 0; | ||
} | ||
|
||
if ($closing) { | ||
$consumed += strlen($this->data); | ||
if ($closing || feof($this->stream)) { | ||
$consumed = strlen($this->data); | ||
|
||
// $this->stream contains pointer to the source | ||
$metadata = new StreamMetaData($this->stream); | ||
$metadata->source = $this->data; | ||
|
||
$metadata = new StreamMetaData($this->stream, $this->data); | ||
$this->transformCode($metadata); | ||
$this->bucket->data = $metadata->source; | ||
$this->bucket->datalen = strlen($this->bucket->data); | ||
if (!empty($this->bucket->data)) { | ||
stream_bucket_append($out, $this->bucket); | ||
} | ||
|
||
$bucket = stream_bucket_new($this->stream, $metadata->source); | ||
stream_bucket_append($out, $bucket); | ||
|
||
return PSFS_PASS_ON; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be more readable to leave a line before the return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good, need to clean the source code and make a single line before returns. |
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* Go! AOP framework | ||
* | ||
* @copyright Copyright 2014, Lisachenko Alexander <lisachenko.it@gmail.com> | ||
* | ||
* This source file is subject to the license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Go\Instrument; | ||
|
||
/** | ||
* Special class for resolving path for different file systems, wrappers, etc | ||
* | ||
* @see http://stackoverflow.com/questions/4049856/replace-phps-realpath/4050444 | ||
* @see http://bugs.php.net/bug.php?id=52769 | ||
*/ | ||
class PathResolver | ||
{ | ||
|
||
/** | ||
* Custom replacement for realpath() and stream_resolve_include_path() | ||
* | ||
* @param string|array $somePath Path without normalization or array of paths | ||
* @param bool $shouldCheckExistence Flag for checking existence of resolved filename | ||
* | ||
* @return array|bool|string | ||
*/ | ||
public static function realpath($somePath, $shouldCheckExistence = false) | ||
{ | ||
$normalized = null; | ||
if (is_array($somePath)) { | ||
return array_map(array(__CLASS__, __FUNCTION__), $somePath); | ||
} | ||
// Trick to get scheme name and path in one action. If no scheme, then there will be only one part | ||
$components = explode('://', $somePath, 2); | ||
list ($pathScheme, $path) = isset($components[1]) ? $components : array(null, $components[0]); | ||
|
||
// Optimization to bypass complex logic for simple paths (eg. not in phar archives) | ||
if (!$pathScheme && ($fastPath = stream_resolve_include_path($somePath))) { | ||
return $fastPath; | ||
} | ||
|
||
$isRelative = !$pathScheme && ($path[0] !== '/') && ($path[1] !== ':'); | ||
if ($isRelative) { | ||
$path = getcwd() . DIRECTORY_SEPARATOR . $path; | ||
} | ||
|
||
// resolve path parts (single dot, double dot and double delimiters) | ||
$path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path); | ||
if (strpos($path, '.') !== false) { | ||
$parts = explode(DIRECTORY_SEPARATOR, $path); | ||
$absolutes = array(); | ||
foreach ($parts as $part) { | ||
if ('.' == $part) { | ||
continue; | ||
} elseif ('..' == $part) { | ||
array_pop($absolutes); | ||
} else { | ||
$absolutes[] = $part; | ||
} | ||
} | ||
$path = implode(DIRECTORY_SEPARATOR, $absolutes); | ||
} | ||
|
||
if ($pathScheme) { | ||
$path = "{$pathScheme}://{$path}"; | ||
} | ||
|
||
if ($shouldCheckExistence && !file_exists($path)) { | ||
return false; | ||
} | ||
|
||
return $path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leave a line break before the return