Scope of Change
Usecase: Standalone scripts.
Rationale
$ xp query.script.php 'mysql://localhost' 'select 1'
*** Error for argument #1: Exception lang.Error (Class 'rdbms\DriverManager' not found)
If not inside a directory where we've configured and run Composer, we will need to type xp -m /path/to/rdbms/module query.script.php ... (and figure out transitive dependencies) ourselves.
Functionality
The class or script needs to be able to declare what modules it requires. These could be loaded via the composer global project (with all its downsides)
<?php namespace github_users;
use text\json\StreamInput from 'xp-forge/json';
use util\data\Sequence from 'xp-forge/sequence';
use util\cmd\Console from 'xp-framework/core';
use util\log\{LogCategory, ConsoleAppender} from 'xp-framework/logging';
use webservices\rest\{Endpoint, Links} from 'xp-framework/rest';
class GitHubApi extends Endpoint {
public function __construct(string $token) {
parent::__construct('https://api.github.com/');
$this->with(['Authorization' => 'token '.$token, 'User-Agent' => nameof($this)]);
}
public function paged(string $resource): iterable {
do {
$response= $this->resource($resource)->accepting('application/json')->get();
yield from (new StreamInput($response->stream()))->elements();
$links= new Links($response->header('Link'));
$resource= $links->uri(['rel' => 'next']);
} while ($resource);
}
}
$api= new GitHubApi(getenv('GITHUB_TOKEN'));
if (in_array('-v', $argv)) {
$api->setTrace((new LogCategory())->withAppender(new ConsoleAppender()));
}
Sequence::of($api->paged('orgs/1and1/members?per_page=50'))
->each(function($user) { Console::writeLine($user['type'], ' ', $user['login']); })
;
Security considerations
Speed impact
Dependencies
Related documents
TypeScript modules / import and export:
Groovy
Composer global downsides / discussion:
Scope of Change
Usecase: Standalone scripts.
Rationale
If not inside a directory where we've configured and run Composer, we will need to type
xp -m /path/to/rdbms/module query.script.php ...(and figure out transitive dependencies) ourselves.Functionality
The class or script needs to be able to declare what modules it requires. These could be loaded via the composer global project (with all its downsides)
Security considerations
Speed impact
Dependencies
-cp/-m.Related documents
TypeScript modules / import and export:
Groovy
Composer global downsides / discussion: