Download the PHP package jahuty/snippets-php without Composer

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

CircleCI codecov

jahuty-php

Welcome to the PHP SDK for Jahuty's API!

Installation

This library requires PHP 7.3+.

It is multi-platform, and we strive to make it run equally well on Windows, Linux, and OSX.

It should be installed via Composer. To do so, add the following line to the require section of your composer.json file, and run composer update:

Usage

Instantiate the library with your API key and use the snippets->render() method to render your snippet:

Then, output the render's content by casting it to a string or using its getContent() method:

In an HTML view:

You can also use tags to select a collection of snippets with the snippets->allRenders() method:

Content versions

By default, this library will render a snippet's published content. If you'd like to render its latest staged content instead, you can use the prefer_latest configuration option at the client or render level:

Parameters

You can pass parameters into your renders using the params configuration option:

The parameters above would be equivalent to assigning the variables below in your snippet:

If you're rendering a collection of snippets, the first dimension of the params key determines the parameters' scope. Use the asterisk key (*) to pass the same parameters to all snippets, or use the snippet id as key to pass parameters to a specific snippet.

The two parameter lists will be recursively merged, and the snippet's parameters will take precedence. In the example below, the variable foo will be assigned the value "bar" for all snippets, except for snippet 1, where it will be assigned the value "qux":

Tracking renders

You can use the render() method's location configuration option to report the absolute URL where a snippet is being rendered. This helps your team preview their changes, and it helps you find and replace deprecated snippets.

Note, locations are only reported when a request is sent to Jahuty's API. As a result, locations will not be reported in some scenarios. For example, if the call to render() results in a cache hit, a request will not sent to Jahuty's API, and the location will not be reported.

This configuration option is not supported by the allRenders() method.

Caching

Caching controls how frequently this library requests content from Jahuty's API.

Caching in memory (default)

By default, Jahuty uses an in-memory cache to avoid requesting the same render more than once during the same request lifecycle. For example:

The in-memory cache only persists for the duration of the original request, however. At the end of the request's lifecycle, the cache will be discarded. To store renders across requests, you need a persistent cache.

Caching persistently

A persistent cache allows renders to be cached across multiple requests. This reduces the number of synchronous network requests to Jahuty's API and improves your application's response time.

To configure a persistent cache, pass a PSR-16 CacheInterface implementation to the client via the cache configuration option:

The persistent cache implementation you choose and configure is up to you. There are many libraries available, and most frameworks provide their own. Any PSR-16 compatible implementation will do.

Expiring

There are three methods for configuring a render's Time to Live (TTL), the amount of time between when a it is stored and when it's considered stale. From lowest-to-highest precedence, the methods are:

  1. configuring your caching implementation,
  2. configuring this library's default TTL, and
  3. configuring a render's TTL.

Configuring your caching implementation

You can usually configure your caching implementation with a default TTL. If no other TTL is configured, this library will defer to the caching implementation's default TTL. How exactly you configure this depends on the library you choose.

Configuring this library's default TTL

You can configure a default TTL for all of this library's renders by passing an integer number of seconds or a DateInterval instance via the client's ttl configuration option:

If this library's default TTL is set, it will take precedence over the default TTL of the caching implementation.

Configuring a render's TTL

You can configure one render's TTL by passing an integer number of seconds or a DateInterval instance via its ttl configuration option:

If a render's TTL is set, it will take precedence over the library's default TTL and the caching implementation's TTL.

Caching collections

By default, this library will cache each render returned by allRenders():

This is a powerful feature. By using tags and the allRenders() method, you can render and cache the content of an entire application with a single network request.

Further, when allRenders() can be called periodically outside your request cycle (e.g., in a background job), you can turn your persistent cache into your content storage mechanism. You can render and cache your dynamic content as frequently as your like without any hit to your application's response time.

Disabling caching

You can disable caching, even the default in-memory caching, by passing a ttl of zero (0) or a negative integer (e.g., -1) via any of the methods described above. For example:

Errors

If Jahuty's API returns any status code other than 2xx, a Jahuty\Exception\Error will be thrown:

That's it!

License

This library is licensed under the MIT license.

Contributing

Contributions are welcome! If you spot an error, please open an issue or let us know.


All versions of snippets-php with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3
guzzlehttp/guzzle Version ^6.3
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 jahuty/snippets-php contains the following files

Loading the files please wait ....