Exemplo n.º 1
0
 public function testConversions()
 {
     // Windows to unix style paths:
     $this->assertEquals('some/directory/file', Utilities::convertPath('some\\directory\\file'));
     $this->assertEquals('///', Utilities::convertPath('\\\\\\'));
     // CamelCase to lisp-case
     $this->assertEquals('do-stuff', Utilities::camelCaseToDashes('DoStuff'));
     $this->assertEquals('do-more-stuff', Utilities::camelCaseToDashes('doMoreStuff'));
     $this->assertEquals('h-t-m-l', Utilities::camelCaseToDashes('HTML'));
     // CamelCase to snake_case
     $this->assertEquals('do_stuff', Utilities::camelCaseToUnderscores('DoStuff'));
     $this->assertEquals('do_more_stuff', Utilities::camelCaseToUnderscores('doMoreStuff'));
     $this->assertEquals('h_t_m_l', Utilities::camelCaseToUnderscores('HTML'));
     // lisp-case to CamelCase
     $this->assertEquals('DoStuff', Utilities::dashesToCamelCase('do-stuff'));
     $this->assertEquals('DoMoreStuff', Utilities::dashesToCamelCase('do-more-stuff'));
     $this->assertEquals('HTML', Utilities::dashesToCamelCase('h-t-m-l'));
     $this->assertEquals('TEst', Utilities::dashesToCamelCase('t----est'));
     // snake_case to CamelCase
     $this->assertEquals('DoStuff', Utilities::underscoresToCamelCase('do_stuff'));
     $this->assertEquals('DoMoreStuff', Utilities::underscoresToCamelCase('do_more_stuff'));
     $this->assertEquals('HTML', Utilities::underscoresToCamelCase('h_t_m_l'));
     $this->assertEquals('TEst', Utilities::underscoresToCamelCase('t____est'));
     // Slugs
     $this->assertEquals('my-post-title', Utilities::stringToDashes('My Post-Title1234'));
 }
Exemplo n.º 2
0
Arquivo: App.php Projeto: jivoo/jivoo
 /**
  * Create application.
  * @param string $appPath Path to app-directory containing at least an
  * 'app.json' configuration file.
  * @param string $userPath Path to user-directory.
  * @param string $entryScript Name of entry script, e.g. 'index.php'.
  */
 public function __construct($appPath, $userPath, $entryScript = 'index.php')
 {
     parent::__construct();
     $this->logger = ErrorHandler::getInstance()->getLogger();
     $appPath = Utilities::convertPath($appPath);
     $userPath = Utilities::convertPath($userPath);
     $manifestFile = $appPath . '/app.json';
     if (file_exists($manifestFile)) {
         $manifest = Json::decodeFile($manifestFile);
         $manifest = array_merge($this->defaultManifest, $manifest);
     } else {
         $this->logger->error('Invalid application. "app.json" not found. Configuring default application.');
         $this->noManifest = true;
         $manifest = $this->defaultManifest;
     }
     $this->manifest = $manifest;
     $this->m = new ModuleLoader();
     $this->paths = new Paths(Paths::convertPath(getcwd()), $userPath);
     $this->paths->app = $appPath;
     $this->paths->user = $userPath;
     //     $this->basePath = dirname($_SERVER['SCRIPT_NAME']);
     $this->entryScript = $entryScript;
     // Temporary work-around for weird SCRIPT_NAME.
     // When url contains a trailing dot such as
     // /app/index.php/admin./something
     // SCRIPT_NAME returns /app/index.php/admin./something instead of expected
     // /app/index.php
     $script = explode('/', $_SERVER['SCRIPT_NAME']);
     while (count($script) > 0) {
         if ($script[count($script) - 1] == $entryScript) {
             break;
         }
         array_pop($script);
     }
     $this->basePath = dirname(implode('/', $script));
     // END work-around
     $this->name = $manifest['name'];
     $this->version = $manifest['version'];
     $this->namespace = $manifest['namespace'];
     Autoloader::getInstance()->addPath($this->namespace, $this->p('app'));
     $this->paths->Jivoo = \Jivoo\PATH;
     $this->paths->Core = \Jivoo\PATH . '/Core';
     $file = new PhpStore($this->p('user/config.php'));
     $this->config = new Document();
     $this->config['user'] = new Config($file);
 }
Exemplo n.º 3
0
Arquivo: Paths.php Projeto: jivoo/core
 /**
  * Convert an internal path.
  * @param string $ipath Internal path, e.g. 'key/followed/by/subpath'.
  * @param string $context Optional context for relative paths (paths starting
  * with './'). The default is the {@see $basePath}.
  */
 public function p($ipath, $context = null)
 {
     $ipath = Utilities::convertPath($ipath);
     if (!isset($context)) {
         $context = $this->basePath;
     }
     if ($ipath == '') {
         return $context;
     }
     $splits = explode('/', $ipath, 2);
     $key = $splits[0];
     $path = '';
     if (isset($splits[1])) {
         $path = $splits[1];
     }
     if ($key == '.') {
         return self::combinePaths($context, $path);
     }
     return self::combinePaths($this->__get($key), $path);
 }