-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resource type is now dynamic when not specified. (#29)
* Make type dynamic when it is not specified for a resource.
- Loading branch information
Showing
5 changed files
with
36 additions
and
35 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
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 |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
|
||
namespace Mango\Bundle\JsonApiBundle\Configuration; | ||
|
||
use Mango\Bundle\JsonApiBundle\Util\StringUtil; | ||
|
||
/** | ||
* @author Steffen Brem <[email protected]> | ||
*/ | ||
|
@@ -32,10 +34,6 @@ class Resource | |
*/ | ||
public function __construct($type, $showLinkSelf = null) | ||
{ | ||
if (null === $type) { | ||
throw new \RuntimeException('A JSON-API resource must have a type defined and cannot be "null".'); | ||
} | ||
|
||
$this->type = $type; | ||
|
||
if (null !== $showLinkSelf) { | ||
|
@@ -44,10 +42,17 @@ public function __construct($type, $showLinkSelf = null) | |
} | ||
|
||
/** | ||
* @param null|object $object | ||
* | ||
* @return string | ||
*/ | ||
public function getType() | ||
public function getType($object) | ||
{ | ||
if (!$this->type) { | ||
$reflectionClass = new \ReflectionClass($object); | ||
return StringUtil::dasherize($reflectionClass->getShortName()); | ||
} | ||
|
||
return $this->type; | ||
} | ||
|
||
|
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