Example #1
0
 public static function quickAccessConstants($content, $caller)
 {
     $validSubst = call_user_func(array($caller, 'getValidStringSurrogates'));
     $validComments = call_user_func(array($caller, 'getValidComments'));
     $lastParsedFile = call_user_func(array($caller, 'getLastParsedFile'));
     $__file = is_null($lastParsedFile) ? null : FileHelper::cleanPath($lastParsedFile);
     $__dir = is_null($__file) ? null : dirname($__file);
     $__file = call_user_func(array($caller, 'includeString'), $__file);
     $__dir = call_user_func(array($caller, 'includeString'), $__dir);
     $__server = array('QUERY_STRING', 'AUTH_USER', 'AUTH_PW', 'PATH_INFO', 'REQUEST_METHOD', 'USER_AGENT' => 'HTTP_USER_AGENT', 'REFERER' => 'HTTP_REFERER', 'HOST' => 'HTTP_HOST', 'URI' => 'REQUEST_URI', 'IP' => 'REMOTE_ADDR');
     foreach ($__server as $key => $value) {
         if (is_int($key)) {
             $key = $value;
         }
         $content = preg_replace(static::constantPattern($key), '$_SERVER[' . call_user_func(array($caller, 'includeString'), $value) . ']', $content);
     }
     /************************/
     /* Constantes spéciales */
     /************************/
     $content = preg_replace(static::constantPattern('FILE'), $__file, $content);
     $content = preg_replace(static::constantPattern('DIR'), $__dir, $content);
     foreach (array('CLASS', 'FUNCTION', 'LINE', 'METHOD', 'NAMESPACE', 'TRAIT') as $constant) {
         $content = preg_replace(static::constantPattern($constant), '__' . $constant . '__', $content);
     }
     return $content;
 }
Example #2
0
 public function testFileHelper()
 {
     $tmp = $this->getTmp();
     copy(__DIR__ . '/../files/.src/return.php', $tmp . '_return.sbp.php');
     copy(__DIR__ . '/../../bootstrap.php', $tmp . '_bootstrap.sbp.php');
     Sbp::fileParse($tmp . '_return.sbp.php', $tmp . '__return.sbp.php');
     $source = FileHelper::getSbpSource($tmp . '__return.sbp.php');
     $this->assertTrue(file_exists($source));
     $this->assertSame($source, FileHelper::cleanPath($tmp . '_return.sbp.php'));
 }
Example #3
0
 public static function fileParse($source, $destination = null)
 {
     if (is_null($destination)) {
         $destination = $source;
     }
     if (!is_readable($source)) {
         throw new SbpException($source . ' is not readable, try :\\nchmod ' . FileHelper::matchingLetter($source) . '+r ' . $source, 1);
     }
     if (!is_writable($dir = dirname($destination))) {
         throw new SbpException($dir . ' is not writable, try :\\nchmod ' . FileHelper::matchingLetter($dir) . '+w ' . $dir, 1);
     }
     static::$lastParsedFile = $source;
     $writed = file_put_contents($destination, static::parse(file_get_contents($source)));
     static::$lastParsedFile = null;
     return $writed;
 }