- public function __construct(FileLocator $locator, PackageInterface $package, array $config, string $tag, string $output, array $filters) {
- //Save locator
- $this->locator = $locator;
-
- //Save assets package
- $this->package = $package;
-
- //Set name
- $this->name = $config['name'];
-
- //Set scheme
- $this->scheme = $config['scheme'];
-
- //Set timeout
- $this->timeout = $config['timeout'];
-
- //Set agent
- $this->agent = $config['agent'];
-
- //Set redirect
- $this->redirect = $config['redirect'];
-
- //Set tag
- $this->tag = $tag;
-
- //Set output
- $this->output = $output;
-
- //Set filters
- $this->filters = $filters;
+ //TODO: change config to name and get other values from RAPSYSPACK_REDIRECT, RAPSYSPACK_SCHEME, RAPSYSPACK_TIMEOUT, RAPSYSPACK_AGENT env variables ?
+ public function __construct(protected FileLocator $locator, protected PackageInterface $package, protected array $config, protected string $tag, protected string $output, protected array $filters) {
+ //Set ctx
+ $this->ctx = stream_context_create(
+ [
+ 'http' => [
+ #'header' => ['Referer: https://www.openstreetmap.org/'],
+ //TODO: set as bundle env config
+ 'max_redirects' => $config['redirect']?:5,
+ //TODO: set as bundle env config
+ 'timeout' => $config['timeout']?:(int)ini_get('default_socket_timeout'),
+ #'user_agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36',
+ //TODO: set as bundle env config
+ 'user_agent' => $config['agent']?:(string)ini_get('user_agent')?:'rapsys_pack/2.0.0',
+ ]
+ ]
+ );