-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add system to import functions from remote #136
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,58 @@ | ||
# Import remote functions | ||
|
||
Castor can import functions from your filesystem but also from a remote resource. | ||
|
||
## Importing functions | ||
|
||
When importing functions from a remote resource, Castor will download the files | ||
and store them in `$HOME/.castor/remote/`. | ||
|
||
### From a GitHub repository | ||
|
||
To import functions from a GitHub repository, pass a path to the `import()` | ||
function, formatted like this: | ||
|
||
``` | ||
github://<user>/<repository>/<path of the php file to import>@<version> | ||
``` | ||
|
||
Here is an example: | ||
|
||
```php | ||
use function Castor\import; | ||
|
||
import('github://pyrech/castor-setup-php/castor.php@main'); | ||
|
||
#[AsTask()] | ||
function hello(): void | ||
{ | ||
\pyrech\helloWorld(); | ||
} | ||
``` | ||
|
||
> **Note** | ||
> If path of the file is empty, it will import the `castor.php` file at the root | ||
> of the repository. | ||
|
||
## Trusting remote resource | ||
|
||
For security reasons, each time your Castor project tries to import a remote | ||
resource, Castor will warn you to ask if you trust it. | ||
|
||
For each remote resource, Castor will ask you what to do. You can either: | ||
- `not now`: Castor will **not import** the function but will **ask you again** | ||
next time ; | ||
- `never`: Castor will **not import** the function and will persist your choice | ||
to **not ask you again** in the future ; | ||
- `only this time`: Castor will **import** the function but will ask you again the | ||
next time ; | ||
- `always`: Castor will **import** the function and will persist your choice | ||
to **not ask you again** in the future. | ||
|
||
You can also pass the `--trust` (or `--no-trust`) options to automatically trust | ||
(or not) **all** remote resources without being asked for. | ||
|
||
> **Warning** | ||
> The `--trust` option should be used with caution as it could lead to malicious | ||
> code execution. The main use case of this option is to be used in a Continuous | ||
> Integration environment. |
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,15 @@ | ||
<?php | ||
|
||
namespace import; | ||
|
||
use Castor\Attribute\AsTask; | ||
|
||
use function Castor\import; | ||
|
||
import('github://pyrech/castor-setup-php/castor.php@main'); | ||
|
||
#[AsTask(description: 'Use a function imported from a remote repository')] | ||
function hello(): void | ||
{ | ||
\pyrech\helloWorld(); | ||
} |
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
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,7 @@ | ||
<?php | ||
|
||
namespace Castor\Remote\Exception; | ||
|
||
class ImportError extends \RuntimeException | ||
{ | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Castor\Remote\Exception; | ||
|
||
class InvalidImportUrl extends \RuntimeException | ||
{ | ||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace Castor\Remote\Exception; | ||
|
||
class NotTrusted extends \RuntimeException | ||
{ | ||
public function __construct( | ||
public readonly string $url, | ||
) { | ||
parent::__construct("The remote resource {$url} is not trusted."); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should document what
version
could be. A branch? A tag? A commit hash?