New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Add support for importing remote functions and tasks #297
Conversation
27b6181
to
bc9b6f4
Compare
👏 Great job! Excited to see the results! I'm currently using a custom method involving a Maybe interesting:
|
bc9b6f4
to
65b9d9d
Compare
Feature seems interesting however I fail to see what are the pros and cons over regular composer usage? What is it trying to solve or why should I use it? Current doc is not helping in this regard. Will it loose static analysis abilities and autocompletion on IDE? Does it need imported packages to be prefixed to avoid collision with castor own classes? |
e5b6e61
to
16499b3
Compare
Mainly DX, some people that use castor don't know PHP and its ecosystem, tell them to use composer and do a specific setup for that is not wanted, where we could provide extensions developer to only add a single line in their README to copy/paste for the end user.
We want to provide optional features that some project need and some doesn't without bloating current castor with too many deps and features Also some people want specific features for their needs in castor, as they used it in many projects, but on our side we do not want to maintain those features, having this would allow those people to create their own extension maintain it according to their needs for their multiples projects (and even other users if published on composer)
Files will be download / cached in a directory relative to the castor.php file (
I don't think so, PHP / Composer in this regard will load the first class available so it should be safe. However there may be problem when current castor and extension loaded have a different version that need specific features. But this is definitely something that we want to work on to avoid as less pain as possible |
It should be embed, otherwise people will need php and composer in their system to use extension which defeat the purpose of having a static binary |
Thanks @TheoD02 for your quick feedback, I took some time this morning to implement your suggestions: |
39b6258
to
033a616
Compare
My guess was that it would try to redeclare and fail so it would need to be dynamically prefixed while importing. The same way Rector have to do it. I've tried and it indeed failed running With <?php
namespace greetings;
use Castor\Attribute\AsTask;
use function Castor\import;
import('composer://symfony/string');
#[AsTask]
function hello(): void
{
}
|
Thinking out loud, I'm wondering if there could be an apporach to dynamically download and autoload on demand the missing functions by hooking into the Something like: use AcmeCorp\HelloWorld\HelloWorld;
spl_autoload_register(function() {
// Transform FQCN into a packagist package name (e.g AcmeCorp\HelloWorld\HelloWorld into acme-corp/hello-world)
// composer require package-name
require_once __DIR__ . '/.castor/vendor/autoload.php';
});
HelloWorld::hello('test'); That would require a clear convention on Namespace -> Package Name mapping for castor packages and calling extra package helpers through classes but usage would feel frictionless and implementation less complex. No more custom I've tinkered around supporting autoimport of undefined function calls too but logic has to reside in the exception handler (which could have side effects) and there's no way to retrieved the passed undefined fuction call arguments in the use function Hello\World\hello; // in __DIR__ . '/hello.php'
set_exception_handler(function (Error $error) {
if (preg_match('/Call to undefined function (.+)\(\)/', $error->getMessage(), $matches)) {
// Transform Hello\World\hello to package name hello/world
// composer require hello/world
call_user_func($functionFQN, ...$args);
}
});
hello('test'); I wish there would be a |
7ab05e8
to
2f480c9
Compare
2f480c9
to
abbfcc3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very very good ! I like it a lot 💛
thankkkkkkkks!
Few niptick, but nothing hard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some words about the autoloader?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⬆️ No a blocker for now
...Examples/Fingerprint/FingerprintTaskWithAFingerprintAndForceTest.php.output_not_runnable.txt
Outdated
Show resolved
Hide resolved
abbfcc3
to
5b27af8
Compare
059e1a7
to
8ea6a8a
Compare
PR rebased, with a new commit fixing almost all feedback from lyrixx + a refactor of the import layer:
For example, before, when trying to importing a simple castor file with a wrong path: and now: |
9a2247a
to
7163aaa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼 Thanks. Only 2/3 little nitpick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⬆️ No a blocker for now
7163aaa
to
c39567d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼 Let's merge it 🎉🎉🎉
And iterate
Thanks |
Thanks @pyrech can wait to test this 🚀🚀🚀 |
Replace #136 (too much conflicts and I wanted to keep a trace of the previous implementation).
This new implementation use Composer as described in #136 (comment).
composer.json
,composer.lock
files and dependencies are stored in.castor/vendor
directory at the root of the Castor project. A.gitignore
is automatically created in it to ignore everything from git so it's invisible from users.See the documentation to understand how imports work: https://github.com/jolicode/castor/blob/import-with-composer/doc/going-further/extending-castor/remote-imports.md
The third commit add a "cache" layer to avoid calling Composer when nothing have changed in the imports.
Todo: