Skip to content

Commit

Permalink
Save the parsed file name
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Mar 24, 2014
1 parent 9b664b7 commit e5cb515
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/sbp/sbp.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class sbp
const SAME_DIR = 0x01;

static protected $destination = self::SAME_DIR;
static protected $lastParsedFile = null;

static public function writeIn($directory = self::SAME_DIR)
{
Expand Down Expand Up @@ -224,7 +225,10 @@ static public function fileParse($from, $to = null)
throw new sbpException($dir." is not writable, try :\nchmod ".static::fileMatchnigLetter($dir)."+w ".$dir, 1);
return false;
}
return file_put_contents($to, self::parse(file_get_contents($from)));
static::$lastParsedFile = $from;
$writed = file_put_contents($to, self::parse(file_get_contents($from)));
static::$lastParsedFile = null;
return $writed;
}

static public function fileExists($file, &$phpFile = null)
Expand Down Expand Up @@ -254,6 +258,14 @@ static public function fileExists($file, &$phpFile = null)
return false;
}

static public function sbpFromFile($file)
{
if(preg_match('#/*:(.+):*/#U', file_get_contents($file), $match))
{
return $match[1];
}
}

static public function includeFile($file)
{
if(!self::fileExists($file, $phpFile))
Expand All @@ -280,7 +292,7 @@ static public function parse($content)
$GLOBALS['commentStrings'] = array();
$content = str_replace(self::SUBST, self::SUBST.self::SUBST, $content);
$content = preg_replace('#<\?(?!php)#', '<?php', $content);
$content = preg_replace('#^(\s*<\?php)(\s)#', '$1 '.self::COMMENT.'$2', $content, 1, $count);
$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();
$validComments = self::validSubst('(?:'.implode('|', $GLOBALS['commentStrings']).')');
Expand Down

0 comments on commit e5cb515

Please sign in to comment.