示例#1
0
 /**
  * Test that macros aren't shared between classes.
  */
 public function testInheritance()
 {
     $this->assertFalse(Format::hasMethod('foobar'));
     $this->assertFalse(Path::hasMethod('foobar'));
     Format::macro('foobar', function () {
     });
     $this->assertTrue(Format::hasMethod('foobar'));
     $this->assertFalse(Path::hasMethod('foobar'));
 }
示例#2
0
 /**
  * Register a file into memory and return an instantiated object.
  *
  * @uses Titon\Utility\Path
  *
  * @param string $key
  * @param array $params
  * @param bool $store
  * @return object
  */
 public static function &factory($key, array $params = [], $store = true)
 {
     if (static::has($key)) {
         return static::get($key);
     }
     $namespace = Path::toNamespace($key);
     $reflection = new ReflectionClass($namespace);
     $object = $reflection->newInstanceArgs($params);
     if ($store) {
         $object = static::set($object, $key);
     }
     return $object;
 }
示例#3
0
 /**
  * Validate input has an extension and is in the whitelist.
  *
  * @uses Titon\Utility\Loader
  *
  * @param string $input
  * @param string|array $extensions
  * @return bool
  */
 public static function ext($input, $extensions = array('gif', 'jpeg', 'png', 'jpg'))
 {
     if (is_array($input) && isset($input['name'])) {
         $input = $input['name'];
     }
     return in_array(Path::ext($input), (array) $extensions, true);
 }
示例#4
0
 /**
  * Store the module key and path.
  *
  * @param string $path
  */
 public function __construct($path)
 {
     $this->_path = Path::ds($path, true);
     parent::__construct();
 }
示例#5
0
 function ext($string)
 {
     return Path::ext($string);
 }
示例#6
0
 /**
  * Return the file system path to the class.
  *
  * @return string
  */
 public function filePath()
 {
     return Path::toPath(get_class($this->_class));
 }
示例#7
0
 /**
  * Test that converting a namespace to a path works correctly.
  */
 public function testToPath()
 {
     $this->assertEquals(DS . 'test' . DS . 'namespace' . DS . 'ClassName.php', Path::toPath('\\test\\namespace\\ClassName'));
     $this->assertEquals(DS . 'test' . DS . 'namespace' . DS . 'Class' . DS . 'Name.php', Path::toPath('\\test\\namespace\\Class_Name'));
     $this->assertEquals(DS . 'Test' . DS . 'NameSpace' . DS . 'ClassName.php', Path::toPath('\\Test\\NameSpace\\ClassName'));
     $this->assertEquals(DS . 'Test' . DS . 'NameSpace' . DS . 'Class' . DS . 'Name.php', Path::toPath('\\Test\\NameSpace\\Class_Name'));
     $this->assertEquals(DS . 'test' . DS . 'namespace' . DS . 'ClassName.PHP', Path::toPath('\\test\\namespace\\ClassName', 'PHP'));
     $this->assertEquals(DS . 'test' . DS . 'namespace' . DS . 'Class' . DS . 'Name.PHP', Path::toPath('\\test\\namespace\\Class_Name', 'PHP'));
     $this->assertEquals(TEST_DIR . DS . 'test' . DS . 'namespace' . DS . 'ClassName.php', Path::toPath('\\test\\namespace\\ClassName', 'php', TEST_DIR));
     $this->assertEquals(TEST_DIR . DS . 'test' . DS . 'namespace' . DS . 'Class' . DS . 'Name.php', Path::toPath('\\test\\namespace\\Class_Name', 'php', TEST_DIR));
     $this->assertEquals(VENDOR_DIR . DS . 'test' . DS . 'namespace' . DS . 'ClassName.php', Path::toPath('\\test\\namespace\\ClassName', 'php', VENDOR_DIR));
     $this->assertEquals(VENDOR_DIR . DS . 'test' . DS . 'namespace' . DS . 'Class' . DS . 'Name.php', Path::toPath('\\test\\namespace\\Class_Name', 'php', VENDOR_DIR));
 }
示例#8
0
文件: Application.php 项目: titon/mvc
 /**
  * Create symbolic links to the webroot folder within each module.
  * This allows for direct static asset handling.
  *
  * @param string $web
  * @throws \Titon\Mvc\Exception\AssetSymlinkException
  */
 public function createLinks($web)
 {
     $web = Path::ds($web, true);
     foreach ($this->getModules() as $key => $module) {
         $moduleWeb = $module->getPath() . 'web' . Path::SEPARATOR;
         if (!file_exists($moduleWeb)) {
             continue;
         }
         $targetLink = $web . $key . Path::SEPARATOR;
         // Create symlink if folder doesn't exist
         if (!file_exists($targetLink)) {
             symlink($moduleWeb, $targetLink);
             // Throw an error if file exists but is not a symlink
         } else {
             if (is_file($targetLink) && !is_link($targetLink)) {
                 throw new AssetSymlinkException(sprintf('Webroot folder %s must not exist so that static assets can be symlinked', $key));
             }
         }
     }
 }
示例#9
0
文件: Relation.php 项目: titon/model
 /**
  * Generate a foreign key column name by inflecting a class name.
  *
  * @param string $class
  * @return string
  */
 public function buildForeignKey($class)
 {
     if (strpos($class, '\\') !== false) {
         $class = Path::className($class);
     }
     return Inflector::underscore($class) . '_id';
 }