Download the PHP package marknotton/agent without Composer

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

Agent: An extension to Jens Segers Agent tool for querying user agent data.

Installation

Official Documentation

This really is just an extension to Jens Segers Agent utility. Refer to their documentation for all available methods.

Whilst I have tried to keep this plugin as lean as possible, I have extended Jens Segers Agent utility by including a couple of my own methods...

Check

Check to determine the users browser and version type is a match.

Example 1:

true if the users current browser matches either browser name

Example 2:

You can use most comparison operators to match against the browsers version.

true if browser version is equal to 100:

true if browser version is not equal to 100:

true if browser version is less than 100:

true if browser version is greater than 100:

true if browser version is less than or equal to 100:

true if browser version is greater than or equal to 100:

Example 3:

You can add multiple criteria for your check. true if any criteria is a match:

Example 5:

You may also negate a check by prefixing a not string. true if the users current browser is not IE version 9 or above.

User agent whitelist:

If the User Agent contains any whitelist exceptions, even with partial matches, then the Check method will always return true. This can be useful for allowing certain bots to pass the Check method.

You can mange the whitelist by creating an agent.php config file in your projects configs directory:

or via the CMS plugin settings:

User Agent Whitelist

Version

Jens Segers original version method required a property name (browser, platform, os, etc...); and the return value would resolve to a full schema version:

I have found in most cases getting the major browser version would suffice. So instead of the previous example you can return a 'floored' version number where the browser is the assumed default argument.

You can still get full version or a floated version number like so:

Redirect

Redirect users to a new template/url if the user agent doesn't match any of the check method criteria:

Data

To set the user agents device name, version and device type directly to an element. Use Crafts attr method to render common data attributes.

The end result will look like something like this:

But why would you want this? This opens up some options for browser specific styling within your CSS; and this server side approach will omit flashes of unstyled content (FOUC) or layout shifts because styling rules aren't dependant on Javascript during page load. This means you can confidently use something like this in your CSS:

agent.js

There is a small IIFE agent.min.js (< 0.7k) file that can be injected directly into the <head>. You'll need to enable this via the plugin settings.

Agent CMS Toggle Option

This will define global properties to the window object for the browser name, version, and different device types.

window.browser.name string
window.browser.version int
window.device string
window.isPhone bool
window.isTable bool
window.isDesktop bool

Alternatively you can register the the agent.min.js asset manually:

Twig:

Php:

Change Log & Breaking Changes

There have been many changes since the previous version of Agent 1.2.0. Some for performance, some for sanity. Arguably some practices used in the previous version were over engineered for no obvious gains. These changes could be breaking, that require small syntax tweaks to resolve on older projects. Please review the "4.0.0 - 2022-09-11" change log for suggestions and fixes.


All versions of agent with dependencies

PHP Build Version
Package Version
Requires craftcms/cms Version ^3.0|^4.0|^5.0
jenssegers/agent Version ^2.6.4
php Version ^7.2.5|^8.0
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 marknotton/agent contains the following files

Loading the files please wait ....