zero-to-prod / stream-context
A wrapper for stream_context_create()
Fund package maintenance!
Github
Requires
- php: >=8.1
- ext-openssl: *
- zero-to-prod/data-model: ^81.0
- zero-to-prod/dynamic-setter: ^71.0
- zero-to-prod/package-helper: ^1.1.3
- zero-to-prod/transformable: ^71.0
Requires (Dev)
- phpunit/phpunit: <12.0
README
Contents
- Introduction
- Requirements
- Installation
- Documentation Publishing
- Usage
- Local Development
- Contributing
Introduction
A wrapper for the stream_context_create()
method.
It provides classes that define all the options for this method.
Requirements
- PHP 7.1 or higher.
Installation
Install Zerotoprod\StreamContext
via Composer:
composer require zero-to-prod/stream-context
This will add the package to your project’s dependencies and create an autoloader entry for it.
Documentation Publishing
You can publish this README to your local documentation directory.
This can be useful for providing documentation for AI agents.
This can be done using the included script:
# Publish to default location (./docs/zero-to-prod/stream-context) vendor/bin/zero-to-prod-stream-context # Publish to custom directory vendor/bin/zero-to-prod-stream-context /path/to/your/docs
Automatic Documentation Publishing
You can automatically publish documentation by adding the following to your composer.json
:
{ "scripts": { "post-install-cmd": [ "zero-to-prod-stream-context" ], "post-update-cmd": [ "zero-to-prod-stream-context" ] } }
Usage
use Zerotoprod\StreamContext\StreamContext; use Zerotoprod\StreamContext\DataModels\Options; use Zerotoprod\StreamContext\DataModels\Http; $client = stream_socket_client( 'ssl://neverssl.com:443', $error_code, $error_message, 30, STREAM_CLIENT_CONNECT, StreamContext::create([ Options::http => [ Http::method => 'GET', Http::header => "Accept-language: en\r\n"."Cookie: foo=bar", Http::proxy => 'proxy' ], ['options'] ])->context ); fclose($client);
Supported Protocols
- HTTP: Customize request methods, headers, user-agent, and more.
- FTP: Manage file transfers with options like overwrite, resume position, and proxy.
- SSL: Configure SSL/TLS options including peer verification, certificates, and more.
- Phar: Set options like compression and metadata for Phar archives.
- Zip: Handle encrypted Zip files with password options.
- Zlib: Control compression levels for zlib streams.
Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page if you want to contribute.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Create a new Pull Request.