• Stars
    star
    150
  • Rank 247,323 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 11 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Composer Package which installs the PhantomJS binary (Linux, Windows, Mac) into /bin of your project.

phantomjs-installer

Latest Stable Version Total Downloads Build Status License

A Composer package which installs the PhantomJS binary (Linux, Windows, Mac) into /bin of your project.

Table of Contents

Installation

To install PhantomJS as a local, per-project dependency to your project, simply add a dependency on jakoch/phantomjs-installer to your project's composer.json file.

{
    "require": {
        "jakoch/phantomjs-installer": "^3"
    },
    "config": {
        "bin-dir": "bin"
    },
    "scripts": {
        "post-install-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ],
        "post-update-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ]
    }
}

For a development dependency, change require to require-dev.

The default download source used is: https://bitbucket.org/ariya/phantomjs/downloads/ You might change it by setting a custom CDN URL, which is explained in the section "Downloading from a mirror".

By setting the Composer configuration directive bin-dir, the vendor binaries will be installed into the defined folder. Important! Composer will install the binaries into vendor\bin by default.

The scripts section is necessary, because currently Composer does not pass events to the handler scripts of dependencies. If you leave it away, you might execute the installer manually.

Now, assuming that the scripts section is set up as required, the PhantomJS binary will be installed into the /bin folder and updated alongside the project's Composer dependencies.

How to require specific versions of PhantomJS?

The environment and server variable PHANTOMJS_VERSION enables you specify the version requirement at the time of packaging.

You can also set the phantomjs-version in the extra section of your composer.json:

 "extra": {
   "jakoch/phantomjs-installer": {
     "phantomjs-version": "2.1.1"
   }
 }

The search order for the version is 1) $_ENV, 2) $_SERVER, 3) composer.json (extra section), 4) fallback to v2.1.1 (hardcoded latest version).

How does this work internally?

  1. Fetching the PhantomJS Installer

In your composer.json you require the package "phantomjs-installer". The package is fetched by composer and stored into ./vendor/jakoch/phantomjs-installer. It contains only one file the PhantomInstaller\\Installer.

  1. Platform-specific download of PhantomJS

The PhantomInstaller\\Installer is run as a "post-install-cmd". That's why you need the "scripts" section in your "composer.json". The installer creates a new composer in-memory package "phantomjs", detects your OS and downloads the correct Phantom version to the folder ./vendor/jakoch/phantomjs. All PhantomJS files reside there, especially the examples.

  1. Installation into /bin folder

The binary is then copied from ./vendor/jakoch/phantomjs to your composer configured bin-dir folder.

  1. Generation of PhantomBinary

The installer generates a PHP file PhantomInstaller\\PhantomBinary and inserts the path to the binary.

PhantomBinary

To access the binary and its folder easily, the class PhantomBinary is created automatically during installation.

The class defines the constants BIN and DIR:

  • BIN is the full-path to the PhantomJS binary file, e.g. /your_project/bin/phantomjs
  • DIR is the folder of the binary, e.g. /your_project/bin

Both constants are also accessible via their getter-methods getBin() and getDir().

Usage:

use PhantomInstaller\PhantomBinary;

// get values with class constants

$bin = PhantomInstaller\PhantomBinary::BIN;
$dir = PhantomInstaller\PhantomBinary::DIR;

// get values with static functions

$bin = PhantomInstaller\PhantomBinary::getBin();
$dir = PhantomInstaller\PhantomBinary::getDir();

This feature is similar to location.js of the phantomjs module for Node.

Override platform requirements

The environment and server variables PHANTOMJS_PLATFORM and PHANTOMJS_BITSIZE enable you to override the platform requirements at the time of packaging. This decouples the packaging system from the target system. It allows to package on Linux for MacOSX or on Windows for Linux.

Possible values for

  • PHANTOMJS_PLATFORM are: macosx, windows, linux.
  • PHANTOMJS_BITSIZE are: 32or 64.

Downloading from a mirror

You can override the default download location of the PhantomJS binary file by setting it in one of these locations. Listed in order of precedence (highest first):

  • The environment variable PHANTOMJS_CDNURL
  • The server variable PHANTOMJS_CDNURL
  • In your composer.json by using $['extra']['jakoch/phantomjs-installer']['cdnurl']:
 "extra": {
   "jakoch/phantomjs-installer": {
     "cdnurl": "https://github.com/Medium/phantomjs/releases/download/v1.9.19/"
   }
 },

Default Download Location

The default download location is Bitbucket: https://api.bitbucket.org/2.0/repositories/ariya/phantomjs/downloads/. You don't need to set it explicitly. It's used, when PHANTOMJS_CDNURL is not set.

Mirrors

You might use one of the following mirror URLs as a value for PHANTOMJS_CDNURL:

  • https://cnpmjs.org/downloads/ - USA, San Mateo (47.88.189.193)
  • https://npm.taobao.org/mirrors/phantomjs/ - China, Hangzhou (114.55.80.225)
  • https://github.com/Medium/phantomjs/ - USA, San Francisco (192.30.253.113)

This list of mirrors is not complete. If you know another mirror, please don't hesitate to add it here.

The mirror URLs are also not hardcoded, except for the Github URL. This enables you to point to any PhantomJS mirror or download folder you like. For instance, you could point to the URL of the download folder of your company, where the binaries are stored: PHANTOMJS_CDNURL=https://cdn.company.com/downloads/phantomjs/.

Automatic download retrying with version lowering on 404

In case downloading an archive fails with HttpStatusCode 404 (resource not found), the downloader will automatically lower the version to the next available version and retry. The number of retries is determined by the number of hardcoded PhantomJS versions in getPhantomJSVersions(). This feature was added, because of the problems with v2.0.0 not being available for all platforms (see issue #25).

More Repositories

1

awesome-composer

😎 A curated awesome list for Composer, Packagist, Satis, Plugins, Scripts, Composer related resources, tutorials.
860
star
2

csgo-cli

CS:GO Console shows your user account, stats and latest matches. It also uploads demo sharecodes to csstats.gg.
C++
35
star
3

jupyter-devbox

A Docker DevBox for Jupyter Notebook's with a focus on Computer Vision, Machine Learning, Finance, Statistics and Visualization.
Jupyter Notebook
15
star
4

composer-fastfetch

The Composer Plugin FastFetch downloads packages fast and in parallel into your Composer cache. [WIP]
PHP
13
star
5

nginx-conf

A Nginx Config parser and generator.
PHP
11
star
6

csgo-config

CS:GO Config is an updateable team config with support for personal settings.
Batchfile
9
star
7

php-hhvm

php-hhvm + travis-ci = ❤
Shell
9
star
8

cpp-devbox

C++ DevBox is a docker devcontainer for C++ development. Based on Debian with LLVM, GCC, VulkanSDK, Mesa, CMake, VCPKG, mold, zsh.
Dockerfile
8
star
9

OMeta-PHP

OMeta: an Object-Oriented Language for Pattern Matching. PHP implementation of OMeta/JS.
PHP
8
star
10

reaper-toolbox

Reaper Toolbox is an installer for Reaper DAW which includes additional plugins, like SWS and repack, out-of-the-box.
Inno Setup
8
star
11

editor

A simple in-browser editor for PHP. Created with CodeMirror3, jQuery2, Bootstrap3.
HTML
6
star
12

Goldstandard-for-PHP

A PHP CodeSniffer ruleset known as "Koch's Goldstandard for PHP".
PHP
5
star
13

asciidoc-cheatsheet

Demonstration of the Asciidoc rendering on Github. Using Powerman's AsciiDoc CheatSheet for Asciidoc v8.6.6.
4
star
14

PHPTracRPC

A PHP library to interact with the Trac Bugtracker API via remote procedure calls.
PHP
4
star
15

stsplus

STSORBIT PLUS (STSPLUS) - will track the space shuttle or any satellite for which orbital data (TLEs) are available
4
star
16

phpunit-headless

Headless is a PhantomJS and SlimerJS integration for PHPUnit.
JavaScript
3
star
17

one_monokai_theme_for_qtcreator

One Monokai Theme for Qt Creator 4+
Batchfile
3
star
18

wikifolio_universe

Das gesamte wikifolio.com Anlageuniversum als SQLite Datenbank.
Shell
1
star
19

cpuinfo_cmake

cpuinfo script for cmake
C++
1
star
20

stackoverflow-notes

repository of various pieces of source code i posted on stackoverflow
PHP
1
star