Skip to content

Commit

Permalink
Adding a Type::getBaseType() to hint other part of the framework abou…
Browse files Browse the repository at this point in the history
…t extensions
  • Loading branch information
lorenzo committed Jul 9, 2015
1 parent 7e89611 commit 8488eed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Database/Type.php
Expand Up @@ -163,6 +163,19 @@ public function getName()
return $this->_name;
}

/**
* Returns the base type name that this class is inheriting.
* This is useful when extending base type for adding extra functionality
* but still want the rest of the framework to use the same assumptions it would
* do about the base type it inherits from.
*
* @return string
*/
public function getBaseType()
{
return $this->_name;
}

/**
* Casts given value from a PHP type to one acceptable by database
*
Expand Down
6 changes: 6 additions & 0 deletions tests/TestCase/Database/TypeTest.php
Expand Up @@ -25,6 +25,10 @@
class FooType extends \Cake\Database\Type
{

public function getBaseType()
{
return 'text';
}
}

/**
Expand Down Expand Up @@ -74,6 +78,7 @@ public function testBuildBasicTypes($name)
$type = Type::build($name);
$this->assertInstanceOf('Cake\Database\Type', $type);
$this->assertEquals($name, $type->getName());
$this->assertEquals($name, $type->getBaseType());
}

/**
Expand Down Expand Up @@ -133,6 +138,7 @@ public function testMapAndBuild()
$type = Type::build('foo');
$this->assertInstanceOf($fooType, $type);
$this->assertEquals('foo', $type->getName());
$this->assertEquals('text', $type->getBaseType());
}

/**
Expand Down

0 comments on commit 8488eed

Please sign in to comment.