From 5ddce0c770b437bfe084b2e727e7c6412c281334 Mon Sep 17 00:00:00 2001 From: Bastien Date: Thu, 27 Mar 2014 14:08:00 +0100 Subject: [PATCH] __FILE and __DIR constants --- src/sbp/sbp.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/sbp/sbp.php b/src/sbp/sbp.php index 9675551..c5655e7 100644 --- a/src/sbp/sbp.php +++ b/src/sbp/sbp.php @@ -295,6 +295,14 @@ static public function parse($content) $content = preg_replace('#^(\s*<\?php)(\s)#', '$1 '.self::COMMENT.(is_null(static::$lastParsedFile) ? '' : '/*:'.static::$lastParsedFile.':*/').'$2', $content, 1, $count); $content = preg_replace_callback('#'.self::COMMENTS.'|'.self::stringRegex().'|\?'.'>.*<\?php#sU', array(get_class(), 'replaceString'), $content); //$validsubst = self::validSubst(); + $__file = is_null(static::$lastParsedFile) ? null : realpath(static::$lastParsedFile); + if($__file === false) + { + $__file = static::$lastParsedFile; + } + $__dir = is_null($__file) ? null : dirname($__file); + $__file = var_export($__file, true); + $__dir = var_export($__dir, true); $validComments = self::validSubst('(?:'.implode('|', $GLOBALS['commentStrings']).')'); if(!$count) { @@ -346,6 +354,16 @@ static public function parse($content) => array(get_class(), 'parseClass'), + /************************/ + /* Constantes spéciales */ + /************************/ + '#(?!<[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff$]|::|->)__FILE(?![a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff])#' + => $__file, + + '#(?!<[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff$]|::|->)__DIR(?![a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff])#' + => $__dir, + + /**************/ /* Constantes */ /**************/