-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(MethodClassReflectionExtension): Fix bug with how many_many 'thro…
…ugh' logic works - Github Issue #13 - Update documentation to include known limitations
- Loading branch information
1 parent
7fadf20
commit d0feb04
Showing
3 changed files
with
19 additions
and
8 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 |
---|---|---|
|
@@ -127,14 +127,24 @@ private function createMethods(ClassReflection $classReflection): array | |
|
||
foreach ($componentNameValueMap as $methodName => $type) { | ||
if (is_array($type)) { | ||
if (!isset($type['through'])) { | ||
throw new Exception('Unknown array format. Expected string or array with "through".'); | ||
if ($componentType !== 'many_many') { | ||
throw new Exception('Cannot use array format for "'.$componentType.'" component type.'); | ||
} | ||
if (!isset($type['through']) || | ||
!isset($type['from']) || | ||
!isset($type['to'])) { | ||
throw new Exception('Unknown array format. Expected string or array with "through", "from" and "to".'); | ||
} | ||
// Example data: | ||
// array(3) {["through" => "SilverStripe\Assets\Shortcodes\FileLink"] | ||
// ["from" => "Parent"] | ||
// ["to" => "Linked"] | ||
$type = $type['through']; | ||
$toClass = $type['to']; | ||
$throughClass = $type['through']; | ||
$throughClassHasOne = ConfigHelper::get($throughClass, 'has_one'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
silbinarywolf
Author
Contributor
|
||
if ($throughClassHasOne && isset($throughClassHasOne[$toClass])) { | ||
$type = $throughClassHasOne[$toClass]; | ||
} | ||
} | ||
// Ignore parameters | ||
$type = explode('(', $type, 2); | ||
|
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
Looks good :D