Download the PHP package sqonk/phext-context without Composer

On this page you can find all versions of the php package sqonk/phext-context. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phext-context

PHEXT Context

Minimum PHP Version

Contexts create a block level scope on a resource and automatically manage the creation and cleanup of that resource irrespective of any exceptions that arise while in use, the primary intention being to help remove the possibility of resource leaks. On top of that they aid in keeping your code lean by automating the standard logic involved with operating such resources.

They are a pseudo implementation of the context managers in Python. While PHP 7 and earlier do not currently allow for a 1:1 elegant solution, the below interpretation makes use of function callbacks to achieve something similar.

While alternative implementations make clever use of generators and 'yield' to push the resources to a 1-cycle foreach loop, the readability is somewhat lost when you follow the code.

This implementation attempts to keep the code readable and be self-explanatory as to what is happening when being studied by another person, even if it is a little more verbose.

In many of the methods a special dedicated error handler is temporarily injected to convert PHP errors into raised Exceptions. Keep in mind that while inside a context manager any standard error handling systems your code is using will be overriden until the manager exits back into to the parent scope.

Install

Via Composer

Context Features

Out of the box the library supports the following managers for:

Available Methods

file

Open a file in the desired mode and then pass it to the callback. The callback should accept one parameter, which is the file handle (resource).

Exceptions and errors can be thrown but the file will be safely closed off.

Example:

tmpfile

Open a temporary file and pass it to the callback. The callback should accept one parameter, which is the file handle (resource).

Exceptions and errors can be thrown but the file will be safely closed off.

Example:

stream

Open a file in 'read' mode and download the contents in chunks, passing each chunk to the callback as it is received.

The default read chunk size is 1024 * 1024, which can be adjusted by passing in your own chunk multiplier. Just be aware that what ever value you pass in will be squared to form the final chunk size.

This method uses a file context as its parent context manager and thus does not introduce any further exception handling.

Example:

image

Open a image resource (using GD) and pass it to the callback. The callback should accept just one parameter: the image resouce.

Example:

new_image

Create a new image resource (using GD) with the specified width and height and pass it to the callback.

The callback should accept just one parameter: the image resouce.

Example:

supress_errors

Perform a block of code in the callback and ignore all possible errors and exceptions that occur.

Example:

no_output

Perform a block of code while preventing any output to std out (console in CLI SAPI or the browser for the web.)

captured_output

Perform a block of code from within a nested output buffer and return the result from ob_get_contents().

Example:

pdo_transaction

Execute and attempt to commit a PDO database transaction. If an error is thrown at any point the transaction will be rolled back.

Example:

mysql_transaction

Execute and attempt to commit a MySQL database transaction. If an error is thrown at any point the transaction will be rolled back.

curl

Initialise a cURL handle. This curl handle is set to the given URL but no further options are set.

zip

Open a zip file at the specified location and in the desired mode, then pass it to the callback. The callback should accept one parameter, which is the zip handle (resource).

The default behaviour is to open or create a zip archive for outputting data to. The mode can be changed by passing in the relevant ZipArchive constant.

Exceptions and errors will be thrown but the file will be safely closed off.

Credits

Theo Howell

License

The MIT License (MIT). Please see License File for more information.


All versions of phext-context with dependencies

PHP Build Version
Package Version
Requires php Version ^8
sqonk/phext-core Version ^1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sqonk/phext-context contains the following files

Loading the files please wait ....