This repository has been archived by the owner on Mar 27, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented extension types (fixes #33).
An extension type is specified by preceeding a class name with a colon, eg: `:Foo\Bar`. The parser produces an `ExtensionType` instance with the class name set to `Foo\Bar`. Attributes are supported, and are passed to the `ExtensionType` instance unmodified, eg: `:Foo\Bar { myAttribute: true }`. Support for arbitrary attributes required modification of `Parser::parseAttributes()`, the `$supportedAttributes` parameter is now nullable to indicate that there is no restriction on the supported attribute names. `ExtensionType` exposes two methods: * `className()` which returns a ClassName instance; and * `attributes()` which returns the attributes array.
- Loading branch information
Showing
5 changed files
with
156 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Typhax package. | ||
* | ||
* Copyright © 2012 Erin Millard | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Eloquent\Typhax\Type; | ||
|
||
use Eloquent\Cosmos\ClassName; | ||
use Icecave\Visita\Host; | ||
|
||
class ExtensionType extends Host implements Type | ||
{ | ||
/** | ||
* @param ClassName $className | ||
* @param array $attributes | ||
*/ | ||
public function __construct(ClassName $className, array $attributes) | ||
{ | ||
$this->className = $className; | ||
$this->attributes = $attributes; | ||
} | ||
|
||
/** | ||
* @return ClassName | ||
*/ | ||
public function className() | ||
{ | ||
return $this->className; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function attributes() | ||
{ | ||
return $this->attributes; | ||
} | ||
|
||
private $className; | ||
private $attributes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Typhax package. | ||
* | ||
* Copyright © 2012 Erin Millard | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Eloquent\Typhax\Type; | ||
|
||
use Eloquent\Cosmos\ClassName; | ||
use PHPUnit_Framework_TestCase; | ||
|
||
class ExtensionTypeTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function testExtensionType() | ||
{ | ||
$className = ClassName::fromString('foo'); | ||
$attributes = array('foo' => 'bar'); | ||
|
||
$type = new ExtensionType($className, $attributes); | ||
|
||
$this->assertSame($className, $type->className()); | ||
$this->assertSame($attributes, $type->attributes()); | ||
} | ||
} |