Skip to content

Commit

Permalink
Made Slingshot optional
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wright <tom@inflatablecookie.com>
  • Loading branch information
betterthanclay committed Jul 17, 2024
1 parent d67a00a commit d3af221
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Made Slingshot optional

## v0.10.25 (2024-04-29)
* Fixed re-adding early-bound instances to container

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ namespace Some\Other\Code
}
```

Note, if your plugin has a constructor with parameters, you will need to add <code>decodelabs/slingshot</code> to your project to allow Veneer to instantiate it.


## Licensing
Veneer is licensed under the MIT License. See [LICENSE](./LICENSE) for the full license text.
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@

"decodelabs/exceptional": "^0.4",
"decodelabs/glitch-support": "^0.4",
"decodelabs/slingshot": "^0.1.1",

"psr/container": "^2"
},
"require-dev": {
"composer-runtime-api": "^2.2",

"decodelabs/pandora": "^0.2.11",
"decodelabs/slingshot": "^0.1.1",
"decodelabs/phpstan-decodelabs": "^0.6"
},
"suggest": {
"decodelabs/slingshot": "Complex plugin instantiation support"
},
"autoload": {
"psr-4": {
"DecodeLabs\\": "src/"
Expand All @@ -33,7 +36,7 @@
],
"extra": {
"branch-alias": {
"dev-develop": "0.10.x-dev"
"dev-develop": "0.11.x-dev"
}
}
}
16 changes: 15 additions & 1 deletion src/Veneer/Binding.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,27 @@ public function resolveDeferral(
$method = $ref->getMethod('__construct');
$method->setAccessible(true);

// Return value doc mismatch
// @phpstan-ignore-next-line
if (!$closure = $method->getClosure($instance)) {
throw Exceptional::Logic(
'Unable to get closure for constructor of ' . $this->providerClass
);
}

(new Slingshot($container))->invoke($closure);
if (class_exists(Slingshot::class)) {
// Invoke constructor with Slingshot
(new Slingshot($container))->invoke($closure);
} else {
if (!empty($method->getParameters())) {
throw Exceptional::ComponentUnavailable(
'Cannot resolve plugin constructor dependencies without Slingshot'
);
}

// Invoke constructor directly
$closure();
}

// Load plugins
$this->loadPlugins();
Expand Down

0 comments on commit d3af221

Please sign in to comment.