Download the PHP package fg/essence without Composer
On this page you can find all versions of the php package fg/essence. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package essence
Essence is a simple PHP library to extract media information from websites, like youtube videos, twitter statuses or blog articles.
If you were already using Essence 2.x.x, you should take a look at the migration guide.
Installation
Example
Essence is designed to be really easy to use. Using the main class of the library, you can retrieve information in just those few lines:
Then, just do anything you want with the data:
What you get
Using Essence, you will mainly interact with Media objects. Media is a simple container for all the information that are fetched from an URL.
Here are the default properties it provides:
- type
- version
- url
- title
- description
- authorName
- authorUrl
- providerName
- providerUrl
- cacheAge
- thumbnailUrl
- thumbnailWidth
- thumbnailHeight
- html
- width
- height
These properties were gathered from the OEmbed and OpenGraph specifications, and merged together in a united interface. Based on such standards, these properties should be a solid starting point.
However, "non-standard" properties can and will also be setted.
Here is how you can manipulate the Media properties:
Note that Essence will always try to fill the html
property when it is not available.
Advanced usage
The Essence class provides some useful utility functions to ensure you will get some information.
Extracting URLs
The crawl()
and crawlUrl()
methods let you crawl extractable URLs from a web page, either directly from its source, or from its URL (in which case Essence will take care of fetching the source).
For example, here is how you could get the URL of all videos in a blog post:
You can then get information from all the extracted URLs:
Replacing URLs in text
Essence can replace any extractable URL in a text by information about it.
By default, any URL will be replaced by the html
property of the found Media.
But you can do more by passing a callback to control which information will replace the URL:
This makes it easy to build rich templates or even to integrate a templating engine:
Configuring providers
It is possible to pass some options to the providers.
For example, OEmbed providers accepts the maxwidth
and maxheight
parameters, as specified in the OEmbed spec.
Other providers will just ignore the options they don't handle.
Configuration
Essence currently supports 68 specialized providers:
Plus the OEmbed
and OpenGraph
providers, which can be used to extract any URL.
You can configure these providers on instanciation:
You can also disable the default ones:
You will find the default configuration in the standard DI container of Essence (see the following part).
Customization
Almost everything in Essence can be configured through dependency injection. Under the hoods, the constructor uses a dependency injection container to return a fully configured instance of Essence.
To customize the Essence behavior, the easiest way is to configure injection settings when building Essence:
The default injection settings are defined in the Standard container class.
Try it out
Once you've installed essence, you should try to run ./cli/essence.php
in a terminal.
This script allows you to test Essence quickly:
Third-party libraries
If you're interested in embedding videos, you should take a look at the Multiplayer lib. It allows you to build customizable embed codes painlessly:
All versions of essence with dependencies
essence/dom Version ~1.0.0
essence/http Version ~1.0.0
fg/parkour Version ~1.1.0