[
  {
    "path": ".gitignore",
    "content": ".editorconfig\n.env.php\n/build\n/vendor\n/bin"
  },
  {
    "path": "README.md",
    "content": "# PhantomMagick\n\n### For PhantomMagick version 1, please use the [1.0.2 branch](https://github.com/anam-hossain/phantommagick/tree/1.0.2)!\n\nPhantomMagick provides a simple API to ease the process of converting HTML to PDF or images. It's especially handy for things like generating invoices or capturing screenshots of websites. It's framework agnostic but it does provide a facade for simple use in Laravel 4/5.\n\n## Features\n\n- Convert HTML to a PDF\n- Convert HTML to an image (PNG, JPG or GIF)\n- Support multipage PDFs\n- Capture a web page as a screenshot\n- Save PDF or image to local disk or to the cloud (S3, Dropbox or Rackspace)\n- Framework agnostic, with optional Laravel integration\n\n## Requirements\n\n- PHP 5.5+\n- [PhantomJS](http://phantomjs.org)\n\n## Installation\n\nPhantomMagick is available via Composer:\n\n```bash\n$ composer require anam/phantommagick\n```\n\n## Dependencies\n\n[PhantomJS](http://phantomjs.org/download.html) must be installed to use PhantomMagick.\n\nThere are few ways to install PhantomJS:\n\n##### Install binary manually\n\nYou can download the official PhantomJS binary from the following link:\n\n[http://phantomjs.org/download.html](http://phantomjs.org/download.html).\n\n##### Install binary through Composer\n\nSimply pull in the `anam/phantomjs-linux-x86-binary` package to get the up-to-date PhantomJS binary for 64-bit Linux systems.\n\n```bash\ncomposer require anam/phantomjs-linux-x86-binary\n```\n\n## Integrations\n\n##### Laravel 4 and Laravel 5 integrations\nAlthough `PhantomMagick` is framework agnostic, it does support Laravel out of the box and comes with a Service provider and Facade for easy integration.\n\nAfter you have installed the PhantomMagick, open the `config/app.php` file which is included with Laravel and add the following lines.\n\nIn the `$providers` array add the following service provider.\n\n```php\n'Anam\\PhantomMagick\\ConverterServiceProvider'\n```\n\nAdd the facade of this package to the `$aliases` array.\n\n```php\n'Converter' => 'Anam\\PhantomMagick\\Facades\\Converter'\n```\n\nYou can now use this facade in place of instantiating the converter yourself in the following examples.\n\n## Usage\n\n### PDF conversion\n\n```php\n$conv = new \\Anam\\PhantomMagick\\Converter();\n$conv->source('http://google.com')\n    ->toPdf()\n    ->save('/your/destination/path/google.pdf');\n```\n\n##### Multipage PDFs\n\n```php\nuse Anam\\PhantomMagick\\Converter;\n\n$conv = new Converter();\n$conv->addPage('<html><body><h1>Welcome to PhantomMagick</h1></body></html>')\n    ->addPage('http://facebook.com')\n    ->addPage('/html/file/from/local/drive/example.html')\n    ->save('/your/destination/path/multipage.pdf');\n```\n\nPlease note with multipage PDFs:\n- Only absolute paths are supported, so avoid relative paths\n- Inline styles or inline style stylesheets are recommended\n\n### Image conversion\n\nPhantomMagick supports HTML to PNG/JPG/GIF conversion.\n\n```php\n$conv = new \\Anam\\PhantomMagick\\Converter();\n$conv->source('http://google.com')\n    ->toPng()\n    ->save('/your/destination/path/google.png');\n```\n\n###### HTML to PNG\n\n```php\n$conv->toPng()\n```\n\n###### HTML to JPG\n\n```php\n$conv->toJpg()\n```\n\n###### HTML to GIF\n\n```php\n$conv->toGif()\n```\n\n### Download file\n\n```php\nuse Anam\\PhantomMagick\\Converter;\n\nConverter::make('http://google.com')\n    ->toPdf()\n    ->download('google.pdf');\n\nConverter::make('http://yahoo.com')\n    ->toPng()\n    ->download('yahoo.png');\n```\n\nTo display in the browser instead of forcing the file to be download, you can pass a second parameter to the method.\n\n```php\n$conv->download('google.pdf', true);\n```\nor just simply call:\n\n```php\n$conv->serve();\n```\n\n## Save to cloud\n\nPhantomMagick leverages [Flysystem](http://flysystem.thephpleague.com) to save converted files in the cloud. \n\nPhantomMagick currently supports:\n- Amazon S3\n- Dropbox\n- Rackspace\n\n##### Amazon S3\n\nFirst install the required S3 dependencies through Composer.\n\n```bash\ncomposer require aws/aws-sdk-php\ncomposer require league/flysystem-aws-s3-v3\n```\n\n```php\nuse Anam\\PhantomMagick\\Converter;\nuse Aws\\S3\\S3Client;\n\n$client = S3Client::factory([\n    'credentials' => [\n        'key'    => 'AWS_KEY',\n        'secret' => 'AWS_SECRET',\n    ],\n    'region' => 'your-region',\n    'version' => 'latest',\n]);\n\n$conv = new Converter();\n$conv->adapter($client, 'bucket-name', 'optional/path/prefix')\n    ->acl('public')\n    ->source('http://google.com')\n    ->toPdf()\n    ->save('google.pdf');\n```\n\n##### Dropbox\nFirst install the required Dropbox dependencies through Composer.\n\n```bash\ncomposer require dropox/dropbox-sdk\ncomposer require flysystem-dropbox\n```\n\n```php\nuse Anam\\PhantomMagick\\Converter;\nuse Dropbox\\Client;\n\n$client = new Client('DROPBOX_TOKEN', 'DROPBOX_APP');\n\n$conv = new Converter();\n$conv->adapter($client)\n    ->source('https://google.com')\n    ->toPdf()\n    ->save('dropbox_example.pdf');\n```\n\n##### Rackspace\nFirst install the required Rackspace dependencies through Composer.\n\n```bash\ncomposer require rackspace/php-opencloud\ncomposer require league/flysystem-rackspace\n```\n\n```php\nuse Anam\\PhantomMagick\\Converter;\nuse OpenCloud\\OpenStack;\nuse OpenCloud\\Rackspace;\n\n$client = new OpenStack(Rackspace::US_IDENTITY_ENDPOINT, array(\n    'username' => 'RACKSPACE_USERNAME',\n    'password' => 'RACKSPACE_PASSWORD'\n));\n\n$store = $client->objectStoreService('cloudFiles', 'SYD');\n$container = $store->getContainer('phantom-magick');\n\n$conv = new Converter();\n$conv->adapter($container)\n    ->source('https://google.com')\n    ->toPdf()\n    ->save('rackspace_example.pdf');\n```\n\n### Settings\n\n#### Global options\n###### Binary\nYou can set the path of the `phantomjs` binary if you've installed it yourself manually, or the `phantomjs` command is not available in your shell. If you installed it through Composer (with the `anam/phantomjs-linux-x86-binary` package) PhantomMagick will be smart enough to find the file automatically.\n\n```php\n$conv->setBinary('/phantomjs/binary/path/phantomjs');\n```\n###### Data Source\nPhantomMagick only supports HTML and data can be provided via an URL or from the local disk. If you need to use raw HTML data, you can use multipage PDF conversion. However raw data does have some limitations; it does not support relative paths and it only supports inline styles and internal CSS.\n\n```php\nnew Converter('/Path/to/file/example.html');\n// or\nConverter::make('/Path/to/file/example.html');\n//or\n$conv->source('/Path/to/file/example.html');\n// or\n$conv->source('http://google.com');\n```\n\nFor raw HTML:\n\n```php\n$conv->addPage('<html><body><h1>Raw HTML</h1></body></html>');\n```\n\n#### PDF options\n\n###### Format\nFormat is optional. Supported formats are: 'A3', 'A4', 'A5', 'Legal', 'Letter', 'Tabloid'.\n```php\n$conv->format('A4');\n```\n###### Margin\nMargin is optional and defaults to 1cm.\n\n```php\narray('margin' => '1cm')\n```\n\n###### Orientation\nOrientation ('portrait', 'landscape') is optional and defaults to 'portrait'.\n\n```php\n$conv->portrait();\n$conv->landscape();\n```\n###### zoomFactor\nzoomFactor is optional and defaults to 1 (where 1 is 100% zoom).\n\n```php\narray('zoomfactor' => 1)\n```\n\n###### Custom width and height\nCustom dimension is optional. Supported formats are `cm`, `px` and `in`.\n\n```php\narray('width' => '900px', height => '700px')\n```\n\n##### Example\n\n```php\n$options = [\n  'format' => 'A4',\n  'zoomfactor' => 1,\n  'orientation' => 'portrait',\n  'margin' => '1cm'\n];\n\n$conv->setPdfOptions($options);\n// or\n$conv->pdfOptions($options);\n// or\n$conv->toPdf($options);\n\n```\n#### Image options\n\n###### Width\nWidth is optional and defaults to 1280px (720p) and only intergers are accepted.\n\n```php\n$conv->width(1280);\n```\n\n###### Height\nHeight is optional and only integers are accepted.\n\n```php\n$conv->height(1280);\n```\n\n**Note:** If only width is given full webpage will be rendered. However, if both width and height is given the image will be clipped to the given width and height.\n\n###### Quality\nQuality is optional and defaults to 80. The quality must be between 1-100.\n\n```php\n$conv->quality(90);\n```\n\n#####Example\n\n```php\n$options = [\n  'width' => 1280,\n  'quality' => 90\n];\n\n$conv->setImageOptions($options);\n// or\n$conv->imageOptions($options);\n// or\n$conv->toPng($options);\n// or\n$conv->toJpg($options);\n// or\n$conv->toGif($options);\n```\n\n## Credits\n\n- [Anam Hossain](https://github.com/anam-hossain)\n- [All Contributors](https://github.com/anam-hossain/phantommagick/graphs/contributors)\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE](http://opensource.org/licenses/MIT) for more information.\n"
  },
  {
    "path": "composer.json",
    "content": "{\n    \"name\": \"anam/phantommagick\",\n    \"description\": \"PhantomMagick provides a simple API to ease the process of converting HTML to PDF or images\",\n    \"keywords\": [\n        \"Pdf\",\n        \"Html to pdf\",\n        \"html to image\",\n        \"Html 2 pdf\",\n        \"Html 2 jpg\",\n        \"html to png\",\n        \"Screen capture\",\n        \"invoice\",\n        \"Laravel pdf\",\n        \"Laravel\",\n        \"Phantomjs\",\n        \"pdf converter\",\n        \"image converter\",\n        \"converter\",\n        \"Phantom\"\n    ],\n    \"homepage\": \"https://github.com/anam-hossain/phantommagick\",\n    \"license\": \"MIT\",\n    \"authors\": [\n        {\n            \"name\": \"Anam hossain\",\n            \"email\": \"enam33@gmail.com\"\n        }\n    ],\n    \"require\": {\n        \"php\": \">=5.4.0\",\n        \"league/flysystem\": \"~1.0\"\n    },\n    \"require-dev\": {\n        \"mockery/mockery\": \"~0.9\",\n        \"phpunit/phpunit\": \"~4.4\"\n    },\n    \"autoload\": {\n        \"psr-4\": {\n            \"Anam\\\\PhantomMagick\\\\\" : \"src/\" \n        }\n    },\n    \"autoload-dev\": {\n        \"psr-4\": {\n            \"Anam\\\\PhantomMagick\\\\Test\\\\\": \"tests\"\n        }\n    }\n}"
  },
  {
    "path": "phpunit.xml.dist",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit \n    colors=\"true\"\n    convertErrorsToExceptions=\"true\"\n    convertNoticesToExceptions=\"true\"\n    convertWarningsToExceptions=\"true\"\n    stopOnError=\"false\"\n    stopOnFailure=\"false\" \n    bootstrap=\"vendor/autoload.php\">\n    <testsuites>\n        <testsuite name=\"all\">\n            <directory suffix=\"Test.php\">tests/</directory>\n        </testsuite>\n    </testsuites>\n    <filter>\n        <whitelist>\n            <directory suffix=\".php\">src/</directory>\n        </whitelist>\n    </filter>\n    <logging>\n        <log type=\"tap\" target=\"build/report.tap\"/>\n        <log type=\"junit\" target=\"build/report.junit.xml\"/>\n        <log type=\"coverage-html\" target=\"build/coverage\" charset=\"UTF-8\" yui=\"true\" highlight=\"true\"/>\n        <log type=\"coverage-text\" target=\"build/coverage.txt\"/>\n        <log type=\"coverage-clover\" target=\"build/logs/clover.xml\"/>\n    </logging>\n</phpunit>"
  },
  {
    "path": "src/Adapter.php",
    "content": "<?php\nnamespace Anam\\PhantomMagick;\n\nuse Exception;\nuse InvalidArgumentException;\n\nclass Adapter\n{\n    /**\n     * The driver of the Filesystem\n     *\n     * @var string\n     */\n    protected $driver = 'local';\n\n    /**\n     * Filesystem client. S3|Dropbox|Rackspace.\n     *\n     * @var mixed\n     */\n    protected $client;\n\n    /**\n     * Client related options\n     *\n     * @var array\n     */\n    protected $args;\n\n    /**\n     * Constructor\n     *\n     * @param mixed $client\n     * @param array  $args\n     */\n    public function __construct($client, array $args = [])\n    {\n        $this->client = $client;\n        $this->args = $args;\n    }\n\n    /**\n     * Set the Filesystem driver\n     *\n     * @param string $driver\n     */\n    public function setDriver($driver)\n    {\n        $this->driver = $driver;\n    }\n\n    /**\n     * Get the driver\n     *\n     * @return string\n     */\n    public function getDriver()\n    {\n        return $this->driver;\n    }\n\n    /**\n     * Determine which Flysystem adapter required\n     *\n     * @return mixed\n     */\n    public function pick()\n    {\n        // Amazon S3\n        if ($this->client instanceof \\Aws\\S3\\S3Client) {\n            $this->setDriver('s3');\n\n            return $this->s3();\n        }\n\n        // Dropbox\n        if ($this->client instanceof \\Dropbox\\Client) {\n            $this->setDriver('dropbox');\n\n            return $this->dropbox();\n        }\n\n        // Rackspace cloudFiles\n        if ($this->client instanceof \\OpenCloud\\ObjectStore\\Resource\\Container) {\n            $this->setDriver('rackspace');\n\n            return $this->rackspace();\n        }\n    }\n\n    /**\n     * Create a new AwsS3Adapter instance.\n     *\n     * @return mixed\n     */\n    public function s3()\n    {\n        $pathPrefix = '';\n\n        if (! isset($this->args[0])) {\n            throw new InvalidArgumentException('S3 Bucket name is required');\n        }\n\n        $bucket = $this->args[0];\n\n        if (isset($this->args[1]) && $this->args[1]) {\n            $pathPrefix = $this->args[1];\n        }\n\n        return new \\League\\Flysystem\\AwsS3v3\\AwsS3Adapter($this->client, $bucket, $pathPrefix);\n    }\n\n    /**\n     * Create a new DropboxAdapter instance.\n     *\n     * @return \\League\\Flysystem\\Dropbox\\DropboxAdapter\n     */\n    public function dropbox()\n    {\n        $prefix = null;\n\n        if (isset($this->args[0])) {\n            $prefix = $this->args[0];\n        }\n\n        return new \\League\\Flysystem\\Dropbox\\DropboxAdapter($this->client, $prefix);\n    }\n\n    /**\n     * Create a new RackspaceAdapter instance.\n     *\n     * @return \\League\\Flysystem\\Rackspace\\RackspaceAdapter\n     */\n    public function rackspace()\n    {\n        return new \\League\\Flysystem\\Rackspace\\RackspaceAdapter($this->client);\n    }\n}\n"
  },
  {
    "path": "src/Converter.php",
    "content": "<?php\nnamespace Anam\\PhantomMagick;\n\nuse Exception;\nuse RuntimeException;\nuse InvalidArgumentException;\nuse Anam\\PhantomMagick\\Exception\\FileFormatNotSupportedException;\nuse Anam\\PhantomMagick\\Adapter;\nuse League\\Flysystem\\Filesystem;\n\nclass Converter extends Runner\n{\n    /**\n     * The driver of the Filesystem\n     *\n     * @var string\n     */\n    protected $driver = 'local';\n\n    /**\n     * The visibily of the file\n     *\n     * @var string\n     */\n    protected $acl = 'private';\n\n    /**\n     * The Filesystem instance.\n     *\n     * @var \\League\\Flysystem\\Filesystem  $filesystem\n     */\n    protected $filesystem;\n\n    /**\n     * The temporary directory path\n     *\n     * @var string\n     */\n    protected $tempFilePath;\n\n    /**\n     * The source of the html data.\n     * Source might be the physical file path or URL.\n     *\n     * @var string\n     */\n    protected $source;\n\n    /**\n     * The output file format\n     *\n     * @var string\n     */\n    private static $format = 'pdf';\n\n    /**\n     * Multiple HTML pages.\n     *\n     * @var array\n     */\n    protected $pages = [];\n\n    /**\n     * Indicates if the conversion is multi pages or not.\n     *\n     * @var boolean\n     */\n    protected static $multiPage = false;\n\n    /**\n     * The conversion scripts.\n     *\n     * @var array\n     */\n    protected static $scripts = [];\n\n    /**\n     * Default PDF settings\n     *\n     * @var array\n     */\n    protected static $pdfOptions = [\n        //Supported formats are: 'A3', 'A4', 'A5', 'Legal', 'Letter', 'Tabloid'\n        'format'        => 'A4',\n        // 1 = 100% zoom\n        'zoomfactor'    => 1,\n        'quality'       => '70',\n        //Orientation: 'portrait', 'landscape'\n        'orientation'   => 'portrait',\n        'margin'        => '1cm'\n    ];\n\n    /**\n     * Default Image settings\n     *\n     * @var array\n     */\n    protected static $imageOptions = [\n        // Dimension in pixels.\n        // if only width is given full webpage will render\n        // if both width and height is given,\n        // the image will be clipped to given width and height\n        'dimension'     => '1280px',\n        // 1 = 100% zoom\n        'zoomfactor'    => 1,\n        'quality'       => '80'\n    ];\n\n    /**\n     * Supported image formats\n     *\n     * @var array\n     */\n    protected static $imageFormats = [\n        'png' => '.png',\n        'jpg' => '.jpg',\n        'gif' => '.gif'\n    ];\n\n    /**\n     * Supported Paper sizes.\n     * Only use in PDF conversion\n     *\n     * @var array\n     */\n    protected static $paperSizes = [\n        'A3',\n        'A4',\n        'A5',\n        'Legal',\n        'Letter',\n        'Tabloid'\n    ];\n\n    /**\n     * Initialize the Converter\n     *\n     * @param string  $source  source of the data file\n     */\n    public function __construct($source = null)\n    {\n        $this->initialize();\n\n        if ($source) {\n            $this->setSource($source);\n        }\n\n        parent::__construct();\n    }\n\n    /**\n     * Initialize the converter settings\n     *\n     * @return void\n     */\n    private function initialize()\n    {\n        self::$scripts['converter'] = dirname(__FILE__) . '/scripts/phantom_magick.js';\n    }\n\n    /**\n     * Create a new Converter instance.\n     *\n     * @param  string $source  Source of the data file\n     * @return Converter\n     */\n    public static function make($source)\n    {\n        return new self($source);\n    }\n\n    /**\n     * Pick appropriate Flysystem adapter for a client\n     *\n     * @param  mixed $client\n     * @return $this\n     */\n    public function adapter($client)\n    {\n        $args = func_get_args();\n\n        array_shift($args);\n\n        $adapter = new Adapter($client, $args);\n\n        $this->filesystem = new Filesystem($adapter->pick());\n\n        $this->driver = $adapter->getDriver();\n\n        return $this;\n    }\n\n    /**\n     * Set visibility\n     *\n     * @param  string $acl\n     * @return $this\n     */\n    public function acl($acl)\n    {\n        $this->acl = $acl;\n\n        return $this;\n    }\n\n    /**\n     * Set PhantomJS binary location\n     *\n     * @param string $binary phantomsjs location\n     * @return $this\n     **/\n    public function setBinary($binary)\n    {\n        $this->binary = $binary;\n\n        return $this;\n    }\n\n    /**\n     * Get the Executable PhantomJS binary source\n     *\n     * @return string\n     */\n\n    public function getBinary()\n    {\n        return $this->binary;\n    }\n\n    /**\n     * Get the driver of the filesystem\n     *\n     * @return string\n     */\n\n    public function getDriver()\n    {\n        return $this->driver;\n    }\n\n\n    /**\n     * Set the temporary file path\n     *\n     * @param string $filename\n     * @return void\n     */\n    public function setTempFilePath($filename)\n    {\n        $this->tempFilePath = $filename;\n    }\n\n    /**\n     * Get the temporary file location\n     *\n     * @return string\n     */\n    public function getTempFilePath()\n    {\n        return $this->tempFilePath;\n    }\n\n    /**\n     * Get the conversion scripts\n     *\n     * @return array\n     */\n    public function getScript()\n    {\n        return self::$scripts['converter'];\n    }\n\n    /**\n     * Set the data source\n     *\n     * @param string $source\n     * @return $this\n     */\n    public function setSource($source)\n    {\n        $this->source = $source;\n\n        return $this;\n    }\n\n    /**\n     * Get the data source\n     *\n     * @return string\n     */\n    public function getSource()\n    {\n        return $this->source;\n    }\n\n    /**\n     * Alias of the setSource()\n     *\n     * @param  string $source\n     * @return string\n     */\n    public function source($source)\n    {\n        return $this->setSource($source);\n    }\n\n    /**\n     * Prepare converter for pdf conversion\n     *\n     * @param  array  $options PDF settings\n     * @return $this\n     */\n    public function toPdf(array $options = [])\n    {\n        $this->pdfOptions($options);\n\n        $this->setTempFilePath(sys_get_temp_dir() . '/' . uniqid(rand()) . '.pdf');\n\n        return $this;\n    }\n\n    /**\n     * Prepare converter for PNG conversion\n     *\n     * @param  array  $options Image settings\n     * @return $this\n     */\n    public function toPng(array $options = [])\n    {\n        return $this->prepareImage($options, $format = 'png');\n    }\n\n    /**\n     * Prepare converter for JPG conversion\n     *\n     * @param  array  $options Image settings\n     * @return $this\n     */\n    public function toJpg(array $options = [])\n    {\n        return $this->prepareImage($options, $format = 'jpg');\n    }\n\n    /**\n     * Prepare converter for GIF conversion\n     *\n     * @param  array  $options Image settings\n     * @return $this\n     */\n    public function toGif(array $options = [])\n    {\n        return $this->prepareImage($options, $format = 'gif');\n    }\n\n    /**\n     * Prepare converter for Image conversion\n     *\n     * @param  array  $options Image settings\n     * @param string $format Image format JPG|PNG|GIF\n     *\n     * @return $this\n     */\n    public function toImage($options, $format = 'png')\n    {\n        return $this->prepareImage($options, $format);\n    }\n\n    /**\n     * Prepare converter for Image conversion\n     *\n     * @param  array  $options Image settings\n     * @param string $format Image format JPG|PNG|GIF\n     *\n     * @return $this\n     */\n\n    public function prepareImage($options, $format = 'png')\n    {\n        $format = strtolower($format);\n\n        if (! array_key_exists($format, self::$imageFormats)) {\n            throw new FileFormatNotSupportedException(\"{$format} file format not Supported.\");\n        }\n\n        self::$format = $format;\n\n        $this->imageOptions($options);\n\n        $this->setTempFilePath(sys_get_temp_dir() . '/' . uniqid(rand()) . self::$imageFormats[$format]);\n\n        return $this;\n    }\n\n    /**\n     * Add HTMl page\n     *\n     * @param string $page Data file path|URL|Raw html code\n     */\n    public function addPage($page)\n    {\n        self::$multiPage = true;\n\n        if (count($this->pages)) {\n            $this->pageBreak();\n        }\n\n        $this->pushContent($page);\n\n        return $this;\n    }\n\n    /**\n     * Add multiple pages\n     *\n     * @param array $pages Data files paths|URLs|Raw HTML code\n     * @return $this\n     */\n    public function addPages(array $pages)\n    {\n        self::$multiPage = true;\n\n        foreach ($pages as $page) {\n            if (count($this->pages)) {\n                $this->pageBreak();\n            }\n\n            $this->pushContent($page);\n        }\n\n        return $this;\n    }\n\n    /**\n     * Push data to pages\n     *\n     * @param  string $page file path|URL|Raw HTML\n     * @return void\n     */\n    public function pushContent($page)\n    {\n        // @file_get_contents will not throw any exception due to @ symbol\n        // file_get_contents will try to load file from physical path or from an URL\n        // and will return the content as string\n        // If failed, it will return false.\n\n        $content = @file_get_contents($page);\n\n        // Perhaps raw HTML content.\n        if (! $content) {\n            $content = $page;\n        }\n\n        array_push($this->pages, $content);\n    }\n\n    /**\n     * Get pages\n     *\n     * @return array\n     */\n    public function getPages()\n    {\n       return $this->pages;\n    }\n\n    /**\n     * Add page break to pages\n     *\n     * @return void\n     */\n    public function pageBreak()\n    {\n        $content = '<div style=\"page-break-after:always;\"><!-- page break --></div>';\n\n        array_push($this->pages, $content);\n    }\n\n    /**\n     * Add contents to the tempfile file.\n     *\n     * @param  string $content\n     * @return void\n     */\n    protected function put($content)\n    {\n        $this->createTempFile();\n\n        file_put_contents($this->getTempFilePath(), $content, FILE_APPEND);\n    }\n\n    /**\n     * Create a temporary html file for converting mutipages pdf\n     *\n     * @return string\n     */\n    protected function createTempFile()\n    {\n        $this->setTempFilePath(sys_get_temp_dir() . '/' . uniqid(rand()) . '.html');\n\n        if (! touch($this->getTempFilePath())) {\n            throw new RuntimeException('Unable to create file in temp directory: '. sys_get_temp_dir());\n        }\n\n        return $this->getTempFilePath();\n    }\n\n    /**\n     * Force download file when conversion is completed\n     *\n     * @param  string  $downloadAs filename\n     * @param  boolean $inline     Show file in browser or not\n     * @return void\n     */\n    public function download($downloadAs = null, $inline = false)\n    {\n        // Force \"local\" driver.\n        $this->driver = 'local';\n\n        $filename = $this->getTempFilePath();\n\n        if (self::$multiPage) {\n            $this->put(implode('', $this->pages));\n            $this->resetPages();\n\n            $filename = dirname($this->getTempFilePath()) . \"/\" . basename($this->getTempFilePath(), \".html\") . \".pdf\";\n        }\n\n        $result = $this->save($filename);\n\n        // Log warning or errors using PHP system logger\n        if (trim($result)) {\n            error_log($result);\n        }\n\n        $pathParts = pathinfo($filename);\n\n        $downloadAs = $downloadAs? $downloadAs : $pathParts['basename'];\n        $contentDisposition = $inline? 'inline' : 'attachment';\n        $contentType = $this->contentType($pathParts['extension']);\n\n        if (! file_exists($filename)) {\n            error_log(\"Conversion failed.\");\n            return \"Conversion failed.\";\n        }\n\n        header('Content-Description: File Transfer');\n        header(\"Content-Type: {$contentType}\");\n        header(\"Content-Disposition: {$contentDisposition}; filename={$downloadAs}\");\n        header('Expires: 0');\n        header('Cache-Control: must-revalidate');\n        header('Pragma: public');\n        header('Content-Length: ' . filesize($filename));\n        readfile($filename);\n\n        unlink($filename);\n        $this->clearTempFiles();\n\n        exit;\n    }\n\n    /**\n     * Download and display the file in browser\n     *\n     * @return void\n     */\n    public function serve()\n    {\n        $this->download(null, true);\n    }\n\n    /**\n     * Save PDF|Image to the given file path if driver is local.\n     * or Save file in cloud with provided filename\n     *\n     * @param string $filename full physical path with filename for local driver or just filename for cloud.\n     * @return mixed\n     **/\n\n    public function save($filename = null)\n    {\n        if ($this->driver == 'local' && ! $filename) {\n            throw new InvalidArgumentException(\"Filename can not be empty. Please provide a full physical path with filename.\");\n        }\n\n        if (! $filename) {\n            $pathParts = pathinfo($this->getSource());\n            $filename = $pathParts['filename'] . '.' . self::$format;\n\n            if (self::$multiPage) {\n                $filename = uniqid('phantom_magick') . '.' . self::$format;\n            }\n        }\n\n        if ($this->driver == 'local') {\n            return $this->saveLocal($filename);\n        }\n\n        return $this->saveCloud($filename);\n    }\n\n    /**\n     * Save PDF|Image to the given file path.\n     *\n     * @param string $filename full physical path with filename\n     * @return mixed\n     **/\n    public function saveLocal($filename)\n    {\n        if (self::$multiPage) {\n            if (count($this->pages)) {\n                $this->put(implode('', $this->pages));\n            }\n\n            return $this->run(self::$scripts['converter'], $this->getTempFilePath(), $filename, self::$pdfOptions);\n        }\n\n        // Single page pdf\n        if (self::$format === 'pdf') {\n            return $this->run(self::$scripts['converter'], $this->getSource(), $filename, self::$pdfOptions);\n        }\n\n        // Image\n        return $this->run(self::$scripts['converter'], $this->getSource(), $filename, self::$imageOptions);\n    }\n\n    /**\n     * Save PDF|Image to the cloud.\n     *\n     * @param string $filename.\n     * @return mixed\n     **/\n    public function saveCloud($filename)\n    {\n        $tempFilename = $this->getTempFilePath();\n\n        // Multi page pdf\n        if (self::$multiPage) {\n            if (count($this->pages)) {\n                $this->put(implode('', $this->pages));\n            }\n\n            $tempFilename = dirname($this->getTempFilePath()) . \"/\" . basename($this->getTempFilePath(), \".html\") . \".pdf\";\n\n            $this->run(self::$scripts['converter'], $this->getTempFilePath(), $tempFilename, self::$pdfOptions);\n\n        } elseif (self::$format === 'pdf') {\n            $this->run(self::$scripts['converter'], $this->getSource(), $tempFilename, self::$pdfOptions);\n        } else {\n            $this->run(self::$scripts['converter'], $this->getSource(), $tempFilename, self::$imageOptions);\n        }\n\n        if (file_exists($tempFilename)) {\n            $contents = file_get_contents($tempFilename);\n\n            unlink($tempFilename);\n\n            return $this->filesystem->put($filename, $contents, ['visibility' => $this->acl]);\n        }\n    }\n\n    /**\n     * Set the PDF options\n     *\n     * @param array $options\n     * @return $this\n     */\n    public function setPdfOptions(array $options)\n    {\n        $this->pdfOptions($options);\n\n        return $this;\n    }\n\n    /**\n     * Get PDF options\n     *\n     * @return $array\n     */\n    public function getPdfOptions()\n    {\n        return self::$pdfOptions;\n    }\n\n    /**\n     * Update PDF settings\n     *\n     * @param  array  $options\n     * @return $this\n     */\n    public function pdfOptions(array $options)\n    {\n        foreach ($options as $key => $option) {\n            if (isset(self::$pdfOptions[$key])) {\n                self::$pdfOptions[$key] = $option;\n            }\n        }\n\n        // Custom paper width and height will replace the default format.\n        if (isset($options['width']) && isset($options['height'])) {\n            // ex. 10cm*5cm, 1200px*1000px, 10in*5in, 900*600\n            // note: without unit (i.e 900*600) will use px.\n            self::$pdfOptions['format'] = $options['width'] . '*' . $options['height'];\n        }\n\n        return $this;\n    }\n\n    /**\n     * Set the Image options\n     *\n     * @param array $options\n     * @return $this\n     */\n    public function setImageOptions(array $options)\n    {\n        $this->imageOptions($options);\n\n        return $this;\n    }\n\n    /**\n     * Get Image settings\n     *\n     * @return $array\n     */\n    public function getImageOptions()\n    {\n        return self::$imageOptions;\n    }\n\n    /**\n     * Update image settings\n     *\n     * @param  array  $options\n     * @return $this\n     */\n\n    public function imageOptions(array $options)\n    {\n        foreach ($options as $key => $option) {\n            if (isset(self::$imageOptions[$key])) {\n                self::$imageOptions[$key] = $option;\n            }\n        }\n\n        if (isset($options['width']) && isset($options['height'])) {\n            // Only digits accepted\n            if (! ctype_digit($options['width'])) {\n                throw new Exception('Width must be a number');\n            }\n\n            if (! ctype_digit($options['height'])) {\n                throw new Exception('Height must be a number');\n            }\n\n            self::$imageOptions['dimension'] = $options['width'] . 'px' . '*' . $options['height'] . 'px';\n        } elseif (isset($options['width'])) {\n            if (! ctype_digit($options['width'])) {\n                throw new Exception('Width must be a number');\n            }\n\n            self::$imageOptions['dimension'] = $options['width'] . 'px';\n        }\n\n        return $this;\n    }\n\n    /**\n     * Set the Paper format for PDF conversion\n     * @return $this\n     */\n    public function format($format)\n    {\n        if (! in_array($format, self::$paperSizes)) {\n            throw new Exception('Paper format not supported.');\n        }\n\n        self::$pdfOptions['format'] = $format;\n\n        return $this;\n    }\n\n    /**\n     * Set the Portrait orientation\n     * Only use in PDF conversion\n     * @return $this\n     */\n    public function portrait()\n    {\n        self::$pdfOptions['orientation'] = 'portrait';\n\n        return $this;\n    }\n\n    /**\n     * Set the Landscape orientation\n     * Only use in PDF conversion\n     * @return $this\n     */\n    public function landscape()\n    {\n        self::$pdfOptions['orientation'] = 'landscape';\n\n        return $this;\n    }\n\n    /**\n     * Set the Width\n     * Only use in Image conversion\n     * @return $this\n     */\n    public function width($width)\n    {\n        if (! ctype_digit($width)) {\n            throw new Exception('Width must be a number');\n        }\n\n        $dimension = explode(\"*\", self::$imageOptions['dimension']);\n\n        $dimension[0] = $width . 'px';\n\n        self::$imageOptions['dimension'] = implode(\"*\", $dimension);\n\n        return $this;\n    }\n\n    /**\n     * Set the Height\n     * Only use in Image conversion\n     * @return $this\n     */\n    public function height($height)\n    {\n        if (! ctype_digit($height)) {\n            throw new Exception('Height must be a number');\n        }\n\n        $dimension = explode(\"*\", self::$imageOptions['dimension']);\n\n        $dimension[1] = $height . 'px';\n\n        self::$imageOptions['dimension'] = implode(\"*\", $dimension);\n\n        return $this;\n    }\n\n    /**\n     * Set the Image quality\n     * Only used in Image conversion\n     * @return $this\n     */\n    public function quality($quality = 80)\n    {\n        if (! ($quality >=1 && $quality <=100)) {\n            throw new Exception('Quality must be between 1-100');\n        }\n\n        self::$imageOptions['quality'] = $quality;\n\n        return $this;\n    }\n\n    /**\n     * Determine file mime\n     *\n     * @param  string $ext\n     * @return string\n     */\n    public function contentType($ext)\n    {\n        switch ($ext) {\n            case 'pdf':\n                return 'application/pdf';\n\n            case 'jpg':\n                return 'image/jpeg';\n\n            case 'png':\n                return 'image/png';\n\n            case 'gif':\n                return 'image/gif';\n\n            default:\n                return 'application/pdf';\n        }\n    }\n\n    /**\n     * Reset pages\n     * @return void\n     */\n    public function resetPages()\n    {\n        $this->pages = [];\n    }\n\n    /**\n     * Remove temporary files\n     *\n     * @return void\n     */\n    public function clearTempFiles()\n    {\n        if (file_exists($this->getTempFilePath())) {\n            unlink($this->getTempFilePath());\n        }\n    }\n\n    public function __destruct()\n    {\n        $this->clearTempFiles();\n    }\n}\n"
  },
  {
    "path": "src/ConverterServiceProvider.php",
    "content": "<?php\nnamespace Anam\\PhantomMagick;\n\nuse Illuminate\\Support\\ServiceProvider;\n\nclass ConverterServiceProvider extends ServiceProvider\n{\n    public function register()\n    {\n        $this->app->bind('converter', function() {\n            return new \\Anam\\PhantomMagick\\Converter;\n        });\n    }\n}\n"
  },
  {
    "path": "src/Exception/FileFormatNotSupportedException.php",
    "content": "<?php\n\nnamespace Anam\\Html2PdfConverter\\Exception;\n\nuse Exception;\n\nclass FileFormatNotSupportedException extends Exception\n{\n\n}\n"
  },
  {
    "path": "src/Exception/FileNotFoundException.php",
    "content": "<?php\n\nnamespace Anam\\Html2PdfConverter\\Exception;\n\nuse Exception;\n\nclass FileNotFoundException extends Exception\n{\n\n}\n"
  },
  {
    "path": "src/Facades/Converter.php",
    "content": "<?php\nnamespace Anam\\PhantomMagick\\Facades;\n\nuse Illuminate\\Support\\Facades\\Facade;\n\nclass Converter extends Facade\n{\n    protected static function getFacadeAccessor() { return 'converter'; }\n}\n"
  },
  {
    "path": "src/Runner.php",
    "content": "<?php\nnamespace Anam\\PhantomMagick;\n\nuse Exception;\nuse Anam\\PhantomMagick\\Str;\n\nclass Runner\n{\n    /**\n     * Executable phantomjs binary path\n     *\n     * @var string\n     */\n    protected $binary = 'phantomjs';\n\n    /**\n     * Executable phantomjs binary path\n     *\n     * @var string\n     */\n    protected $alternateBinary;\n\n    /**\n     * Phantomjs command with arguments\n     *\n     * @var string\n     */\n    protected $command;\n\n    /**\n     * Constructor\n     *\n     * @param string $binary\n     */\n    public function __construct($binary = null)\n    {\n        if ($binary !== null) {\n            $this->binary = $binary;\n        }\n\n        if (class_exists('\\Anam\\PhantomLinux\\Path')) {\n            $this->setAlternateBinary(\\Anam\\PhantomLinux\\Path::binaryPath());\n        }\n    }\n\n    /**\n     * Set Alternate Binary\n     *\n     * @param string $binary\n     *\n     * @return void\n     **/\n    public function setAlternateBinary($binary)\n    {\n        $this->alternateBinary = $binary;\n    }\n\n    /**\n     * Get Alternate binary\n     *\n     * @return string\n     **/\n    public function getAlternateBinary()\n    {\n       return $this->alternateBinary;\n    }\n\n    /**\n     * Set shell command\n     *\n     * @param string $command\n     *\n     * @return void\n     **/\n    public function setCommand($command)\n    {\n        $this->command = $command;\n    }\n\n    /**\n     * Get PhantomJS shell command\n     *\n     * @return string\n     **/\n    public function getCommand()\n    {\n       return $this->command;\n    }\n\n    /**\n     * Run the phantomjs command\n     * @param  string $script  Conversion script\n     * @param  string $source  Data file location\n     * @param  string $output  Output file location\n     * @param  array  $options\n     * @return string\n     */\n    public function run($script, $source, $output, array $options = array())\n    {\n        $binary = $this->pickBinary();\n\n        $arguments = ['script' => $script, 'source' => $source, 'output' => $output] + $options;\n\n        $arguments = $this->escapeShellArguments($arguments);\n\n        $this->setCommand(escapeshellcmd(\"{$binary} --ssl-protocol=any --ignore-ssl-errors=yes \") . implode(' ', $arguments));\n\n        return shell_exec($this->getCommand());\n    }\n\n    /**\n     * Escape shell arguments\n     *\n     * @param  array  $arguments\n     * @return array\n     */\n    private function escapeShellArguments(array $arguments)\n    {\n        foreach ($arguments as $key => $argument) {\n            $arguments[$key] = escapeshellarg($argument);\n        }\n\n        return $arguments;\n    }\n\n    /**\n     * Check phantomjs is installed or not\n     *\n     * @param  string $binary  Binary location\n     * @return boolean\n     */\n    public function verifyBinary($binary)\n    {\n        $uname = strtolower(php_uname());\n\n        if (Str::contains($uname, 'darwin')) {\n            if (! shell_exec(escapeshellcmd(\"command -v {$binary} >/dev/null 2>&1\"))) {\n                return false;\n            }\n        } elseif (Str::contains($uname, 'win')) {\n            if (! shell_exec(escapeshellcmd(\"{$binary}\"))) {\n                return false;\n            }\n        } elseif (Str::contains($uname, 'linux')) {\n            if (! shell_exec(escapeshellcmd(\"which {$binary}\"))) {\n                return false;\n            }\n        } else {\n            throw new \\RuntimeException(\"Unknown operating system.\");\n        }\n\n        return true;\n    }\n\n    /**\n     * Choose binary\n     *\n     * @return string\n     */\n    public function pickBinary()\n    {\n        if ($this->binary != 'phantomjs') {\n            if (! $this->verifyBinary($this->binary)) {\n                throw new Exception('Binary does not exist');\n            }\n\n            return $this->binary;\n        }\n\n\n        if (! $this->verifyBinary($this->binary)) {\n\n            if (! $this->verifyBinary($this->getAlternateBinary())) {\n                throw new Exception('Binary does not exist');\n            }\n\n            $this->binary = $this->getAlternateBinary();\n        }\n\n        return $this->binary;\n    }\n}\n"
  },
  {
    "path": "src/Str.php",
    "content": "<?php\nnamespace Anam\\PhantomMagick;\n\nclass Str\n{\n   /**\n     * This method is the part of illuminate/support package.\n     * visit: https://github.com/illuminate/support for more info.\n     *\n     * Determine if a given string contains a given substring.\n     *\n     * @param  string  $haystack\n     * @param  string|array  $needles\n     * @return bool\n     */\n    public static function contains($haystack, $needles)\n    {\n        foreach ((array) $needles as $needle) {\n            if ($needle != '' && strpos($haystack, $needle) !== false) {\n                return true;\n            }\n        }\n\n        return false;\n    }\n}\n"
  },
  {
    "path": "src/scripts/phantom_magick.js",
    "content": "var page = require('webpage').create(),\n    system = require('system'),\n    quality = system.args[5] || '70',\n    orientation = system.args[6] || 'portrait',\n    margin = system.args[7] || '1cm',\n    address, output, size;\n\nif (system.args.length < 3 || system.args.length > 8) {\n    console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom] [orientation] [margin] [quality]');\n    console.log('  paper (pdf output) examples: \"5in*7.5in\", \"10cm*20cm\", \"A4\", \"Letter\"');\n    console.log('  image (png/jpg output) examples: \"1920px\" entire page, window width 1920px');\n    console.log('                                   \"800px*600px\" window, clipped to 800x600');\n    phantom.exit(1);\n} else {\n    address = system.args[1];\n    output = system.args[2];\n    page.viewportSize = { width: 1280, height: 720 };\n    if (system.args.length > 3 && system.args[2].substr(-4) === \".pdf\") {\n        size = system.args[3].split('*');\n        page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: margin }\n                                           : { format: system.args[3], orientation: orientation, margin: margin };\n    } else if (system.args.length > 3 && system.args[3].substr(-2) === \"px\") {\n        size = system.args[3].split('*');\n        if (size.length === 2) {\n            pageWidth = parseInt(size[0], 10);\n            pageHeight = parseInt(size[1], 10);\n            page.viewportSize = { width: pageWidth, height: pageHeight };\n            page.clipRect = { top: 0, left: 0, width: pageWidth, height: pageHeight };\n        } else {\n            // If a number received, instead of width and height,\n            // Try to use best width and height by inspecting the number.\n            console.log(\"size:\", system.args[3]);\n            pageWidth = parseInt(system.args[3], 10);\n            pageHeight = parseInt(pageWidth * 3/4, 10); // it's as good an assumption as any\n            console.log (\"pageHeight:\",pageHeight);\n            page.viewportSize = { width: pageWidth, height: pageHeight };\n        }\n    }\n    if (system.args.length > 4) {\n        page.zoomFactor = system.args[4];\n    }\n    \n    // Add better error reporting when url fails to load. \n    page.onResourceError = function(resourceError) {\n        page.reason = resourceError.errorString;\n        page.reason_url = resourceError.url;\n    };\n    \n    page.open(address, function (status) {\n        if (status !== 'success') {\n            console.log('Unable to load the address!');\n            console.log(\n                \"Error opening url \\\"\" + page.reason_url\n                                + \"\\\": \" + page.reason\n            );\n            phantom.exit(1);\n        } else {\n            window.setTimeout(function () {\n                page.render(output, {quality: quality});\n                phantom.exit();\n            }, 200);\n        }\n    });\n}\n"
  },
  {
    "path": "tests/AdapterTest.php",
    "content": "<?php\nnamespace Anam\\PhantomMagick\\Test;\n\nuse Exception;\nuse RuntimeException;\nuse InvalidArgumentException;\nuse Anam\\PhantomMagick\\Adapter;\n\nclass AdapterTest extends \\PHPUnit_Framework_TestCase\n{\n    protected $adapter;\n\n    public function setUp()\n    {\n\n    }\n\n    /**\n     * @expectedException InvalidArgumentException\n     */\n    public function testAmazonS3AdapterWillThrowInvalidArgumentException()\n    {\n        throw new InvalidArgumentException(\"Bucket is required\");\n    }\n}\n"
  },
  {
    "path": "tests/ConverterTest.php",
    "content": "<?php\nnamespace Anam\\PhantomMagick\\Test;\n\nuse Exception;\nuse RuntimeException;\nuse Mockery;\nuse Anam\\PhantomMagick\\Converter;\nuse League\\Flysystem\\Filesystem;\nuse Anam\\PhantomMagick\\Adapter;\nuse Anam\\PhantomMagick\\Exception\\FileFormatNotSupportedException;\nuse Aws\\S3\\S3Client;\n\nclass ConverterTest extends \\PHPUnit_Framework_TestCase\n{\n    use PrivateAndProtectedMethodsAccessibleTrait;\n\n    protected $converter;\n\n    protected $pdfOptions = [\n        'format'        => 'A3',\n        'zoomfactor'    => 2,\n        'quality'       => '100',\n        'orientation'   => 'landscape',\n        'margin'        => '2cm'\n\n    ];\n\n    protected $imageOptions = [\n        'dimension'     => '1000px',\n        'zoomfactor'    => 2,\n        'quality'       => '90'\n    ];\n\n    public function setUp()\n    {\n        $this->converter = new Converter();\n    }\n\n    public function testInitialize()\n    {\n        $this->invokeMethod($this->converter, 'initialize');\n\n        $this->assertContains('phantom_magick.js', $this->converter->getScript(), 'Verify that phantom_magick.js is used');\n    }\n\n    public function testMake()\n    {\n        $this->assertInstanceOf('Anam\\PhantomMagick\\Converter', Converter::make('http://code-chunk.com'), 'Check Converter::make() method returning the instance of \\Anam\\PhantomMagick\\Converter');\n    }\n\n    public function testSetSource()\n    {\n        $this->converter->setSource('http://code-chunk.com');\n\n        $this->assertEquals('http://code-chunk.com', $this->converter->getSource());\n    }\n\n    public function testGetSource()\n    {\n        $this->converter->setSource('http://code-chunk.com');\n        $this->assertEquals('http://code-chunk.com', $this->converter->getSource());\n    }\n\n    public function testSource()\n    {\n        $this->converter->source('http://code-chunk.com');\n\n        $this->assertEquals('http://code-chunk.com', $this->converter->getSource());\n    }\n\n    public function testDefaultFileSystemDriverIsLocal()\n    {\n        $this->assertEquals('local', $this->converter->getDriver());\n    }\n\n    public function testFileSystemDriverIsS3WhenS3ClientIsUsedAsClient()\n    {\n        $client = S3Client::factory(array(\n            'key'    => 'dummy-key-123',\n            'secret' => 'dummy-secret-123'\n        ));\n\n        $this->converter->adapter($client, 'dummy-bucket');\n\n        $this->assertEquals('s3', $this->converter->getDriver());\n    }\n\n    public function testGetTempFilePath()\n    {\n        $path = '/dummy/file/path';\n\n        $this->converter->setTempFilePath($path);\n\n        $this->assertEquals($path, $this->converter->getTempFilePath());\n    }\n\n    public function testPdfOptions()\n    {\n        $this->converter->pdfOptions($this->pdfOptions);\n\n        $this->assertEquals($this->pdfOptions, $this->converter->getPdfOptions());\n    }\n\n    public function testImageOptions()\n    {\n        $options = [\n            'dimension'     => '900px',\n            'zoomfactor'    => 1,\n        ];\n\n        $this->converter->imageOptions($options);\n\n        $this->assertArrayHasKey('quality', $this->converter->getImageOptions());\n    }\n\n    public function testContentType()\n    {\n        $mime = $this->converter->contentType('pdf');\n\n        $this->assertEquals('application/pdf', $mime);\n    }\n\n    public function testPagesIsEmpty()\n    {\n        $this->assertTrue(empty($this->converter->getPages()));\n    }\n\n    public function testPagesIsNotEmpty()\n    {\n        $this->converter->addPage('http://google.com');\n\n        $this->assertFalse(empty($this->converter->getPages()));\n    }\n\n    public function testPushContents()\n    {\n        $pages = ['<html><body><h1>Phantom magick</h1></body></html>'];\n\n        $this->converter->pushContent($pages[0]);\n\n        $this->assertEquals($pages, $this->converter->getPages());\n    }\n\n    public function testPageBreak()\n    {\n        $pages = [\n            '<html><body><h1>Phantom magick</h1></body></html>',\n            '<div style=\"page-break-after:always;\"><!-- page break --></div>'\n        ];\n\n        $this->converter->pushContent($pages[0]);\n\n        $this->converter->pageBreak();\n\n        $this->assertEquals($pages, $this->converter->getPages());\n    }\n\n    public function testAddPages()\n    {\n        $expected = [\n            '<html><body><h1>Page 1</h1></body></html>',\n            '<div style=\"page-break-after:always;\"><!-- page break --></div>',\n            '<html><body><h1>Page 2</h1></body></html>',\n        ];\n\n        $pages = [\n            '<html><body><h1>Page 1</h1></body></html>',\n            '<html><body><h1>Page 2</h1></body></html>'\n        ];\n\n        $this->converter->addPages($pages);\n\n        $this->assertEquals($expected, $this->converter->getPages());\n    }\n\n    public function testToPdf()\n    {\n        $this->converter->toPdf($this->pdfOptions);\n\n        // Check pdf options is set properly\n        $this->assertEquals($this->pdfOptions, $this->converter->getPdfOptions());\n\n        // Check .pdf extension is set\n        $this->assertContains('.pdf', $this->converter->getTempFilePath());\n\n    }\n\n    public function testToPng()\n    {\n        $this->converter->toPng($this->imageOptions);\n\n        $this->assertEquals($this->imageOptions, $this->converter->getImageOptions());\n\n        // Check .png extension is set\n        $this->assertContains('.png', $this->converter->getTempFilePath());\n\n    }\n\n    public function testToJpg()\n    {\n        $this->converter->toJpg($this->imageOptions);\n\n        $this->assertEquals($this->imageOptions, $this->converter->getImageOptions());\n\n        // Check .png extension is set\n        $this->assertContains('.jpg', $this->converter->getTempFilePath());\n\n    }\n\n    public function testToGif()\n    {\n        $this->converter->toGif($this->imageOptions);\n\n        $this->assertEquals($this->imageOptions, $this->converter->getImageOptions());\n\n        // Check .png extension is set\n        $this->assertContains('.gif', $this->converter->getTempFilePath());\n\n    }\n\n}\n"
  },
  {
    "path": "tests/PrivateAndProtectedMethodsAccessibleTrait.php",
    "content": "<?php\nnamespace Anam\\PhantomMagick\\Test;\n\ntrait PrivateAndProtectedMethodsAccessibleTrait\n{\n    /**\n     * Call protected/private method of a class.\n     *\n     * @param object &$object    Instantiated object that we will run method on.\n     * @param string $methodName Method name to call\n     * @param array  $parameters Array of parameters to pass into method.\n     *\n     * @return mixed Method return.\n     */\n    public function invokeMethod(&$object, $methodName, array $parameters = array())\n    {\n        $reflection = new \\ReflectionClass(get_class($object));\n        $method = $reflection->getMethod($methodName);\n        $method->setAccessible(true);\n\n        return $method->invokeArgs($object, $parameters);\n    }\n}\n"
  },
  {
    "path": "tests/RunnerTest.php",
    "content": "<?php\nnamespace Anam\\PhantomMagick\\Test;\n\nuse Exception;\nuse RuntimeException;\nuse InvalidArgumentException;\nuse Anam\\PhantomMagick\\Runner;\n\nclass RunnerTest extends \\PHPUnit_Framework_TestCase\n{\n    protected $runner;\n\n    public function setUp()\n    {\n        $this->runner = new Runner();\n    }\n\n    /**\n     * Runner tests\n     */\n    public function testVerifyBinary()\n    {\n        $this->assertTrue(true);\n    }\n\n}\n"
  },
  {
    "path": "tests/test_page.html",
    "content": "<html>\n\t<head>\n\t\t<title>PhantomMagick</title>\n\t</head>\n\t<body>\n\t\t<h1>Testing PhantomMagick</h1>\n\t\t<p>\n\t\t\tLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.\n\t\t</p>\n\t</body>\n</html>"
  }
]