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 container($container, $file, $content = null, $basename = null, $name = null)
 {
     $content = file_get_contents($file);
     if (is_null($basename)) {
         $basename = basename($file);
     }
     if (is_null($name)) {
         $name = preg_replace('#\\..+$#', '', $basename);
     }
     if (is_null($container)) {
         $container = preg_replace('#([/\\\\])(?:[^/\\\\]+)(\\..+?)$#', '$1$2.container', FileHelper::cleanPath($file));
         $container = file_exists($container) ? file_get_contents($container) : '{content}';
     }
     $camelCase = preg_replace_callback('#[-_]([a-z])#', function ($match) {
         return strtoupper($match[1]);
     }, $name);
     $replace = array('{file}' => $file, '{basename}' => $basename, '{name}' => $name, '{camelCase}' => $camelCase, '{CamelCase}' => ucfirst($camelCase));
     $container = preg_replace_callback('#(\\t*){content}#', function ($match) use($content) {
         return $match[1] . str_replace("\n", "\n" . $match[1], $content);
     }, $container);
     return str_replace(array_keys($replace), array_values($replace), $container);
 }