Download the PHP package machinateur/the-printer without Composer

On this page you can find all versions of the php package machinateur/the-printer. 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 the-printer

machinateur/the-printer

The printer, a prototype. Create PDF documents and images from HTML content using puppeteer and headless-chrome.

This repository contains the express app (node) and a PHP client implementation with stream support.

The PHP SDK has zero package dependencies, to keep it as simple as possible.

Requirements

Installation

Note that the express app is also bundled with the composer package.

Advantages

Usage

Running the express app

Run

or

to launch the express app. Make sure to install the dependencies first.

Supported CLI args and environment variables

The following arguments are supported, with respective fallback to the env-var.

Calling from PHP

From PHP the bundled client provided in this composer package may be used to interact with the express app. It has to be running for this to work.

Create and return a document from php

The following example will render a document (in A5 format without header/footer) and return it directly to the output buffer.

You can use the \Machinateur\ThePrinter\Client::documentBinary() method instead, to get the output as a binary string. It's always possible to write to a stream resource and process/read it later, to save memory. If no buffer is provided, it is created as temporary stream and has to be closed by the implementor. The PDF documents do not support JavaScript execution before rendering. This is a engine limitation.

Create and return an image from php

The following example does about the same thing, but with a (full-page) screenshot.

As with the \Machinateur\ThePrinter\Client::document() method, there is a \Machinateur\ThePrinter\Client::imageBinary() method to retrieve the buffer as string blob. The provided HTML content is set as the page content directly. Keep in mind that JavaScript is disabled in case you rely on it for rendering. That setting can be controlled from the --no-script option or using the APP_ENABLE_JAVASCRIPT env-var.

Calling from other languages

It's totally possible to interact with the express app from other programming languages as well. Just use the supported endpoints directly via your favourite HTTP client. The response content will be a binary stream of the mime-type from the response header. In case of an error (request format or something else) the response will be a json object of type {Error&{statusCode?:number}} where trace is removed when not in debug mode.

Using HTTP files

Find details on the available endpoints and their options in the HTTP files contained in this repository.

TODO

Supported endpoints

POST /document

Create a PDF document from the provided content string.

Configuration:

Further reference:

POST /image

Create an image from the provided content string.

Configuration:

Further reference:

Development

Setup

To set this project up from scratch for development, run the following commands:

Running tests

Execute the PHPUnit test-suite using the following command:

All tests are stored at ./tests under the \Machinateur\ThePrinter\Tests\... namespace.

The configuration is stored in phpunit.xml.dist.

Running tests in multiple PHP versions

It's possible to run the tests in different versions of PHP without the need to install all those versions locally. Thanks to docker, this can be done using a single command:

See this guide for some more details.

Generate coverage

Execute the PHPUnit test-suite and gain coverage insights using the following command:

This command uses the text UI of PHPUnit exclusively.

About ProcessTestCase

The class \Machinateur\ThePrinter\Tests\ProcessTestCase is a custom \PHPUnit\Framework\TestCase that supports managing a background process that is started and stopped with the test class itself.

While this can impact the test-suite performance quite heavily, if used excessively and depending on the type of background process.

This is utilized to enable a functional test using node as background process running the the-printer.js server. The test is located at `` and holds some other interesting details, discussed below.

About ServerTestCase

The class \Machinateur\ThePrinter\Tests\Server\ServerTestCase is a variant of the ProcessTestCase that specifically uses the PHP built-in webserver. This can be useful, if a test requires a mocked webserver.

This is utilized to mock server responses for actual testing of the curl calls within the \Machinateur\ThePrinter\Stream\Connection.

Embedded PHPT test-suite

The project-level test-suite embeds a separate test-suite as part of the \Machinateur\ThePrinter\Tests\Result\ResultTest, where some separate PHPT tests are loaded.

You can find other examples of such tests being used, for example in the PHP curl extension itself.

Thanks to PHPUnit's built-in support for the ancient PHPT format, although somewhat thinly documented, they were really easy to integrate.

The PHPT tests are used to test the accuracy of actual printing results (image and document) using imagick. This comes with some drawbacks and was an experimental approach in the beginning. It can serve as an example for real world use-cases of this "digital print server".

Feel free to browse the code and have a look yourself. Improvements and creative additions are always welcomed.

Managing control files

The comparison (aka. control) files for PHPT tests are stored under tests/Result/res/.

Running static analysis

To execute PhpStan for static analysis, call the following composer script:

This command maps to ./vendor/bin/phpstan analyze using the phpstan.neon file from the project root.

Generating phpdoc

It's possible to generate phpdoc with phpDocumentor:

The resulting documentation will be placed in docs/, the case is located at var/phpdoc/, both are ignored from git.

License

It's MIT.


All versions of the-printer with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
ext-json Version *
ext-curl Version *
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 machinateur/the-printer contains the following files

Loading the files please wait ....