diff --git a/README.md b/README.md index 2c820b7..54ebd4c 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,14 @@ A library to interact with the Phantom JS Cloud The library will generate the JSON Object. This object can be later sent as a HTTP Request with Guzzle or other HTTP Client for PHP. + +The library does not make HTTP requests - this library only generates the JSON you can use as a payload when you make your HTTP requests. + +### TODO - What we plan next for this code +* find a general way to generate the JSON with out the NULL arguments +* have a directory structure that will allow you to separate PhantomJS classes from helper classes +* migrate public arguments to protected arguments where possible and use setters and getters. +* integrate an HTTP client ( like GUZZLE HTTP ) +* add unit testing +* see TODO's in the class comments +* add examples in the documentation \ No newline at end of file diff --git a/composer.json b/composer.json index 4891d47..ca53d98 100644 --- a/composer.json +++ b/composer.json @@ -1,20 +1,19 @@ { - "name": "cfv1000/phantomjs-cloud", - "description": "PhantomJS Cloud API based on Guzzle", - "type": "library", - "require": { - "guzzlehttp/guzzle": "^6.2" - }, - "authors": [ - { - "name": "Flaviu Chelaru", - "email": "flaviu.chelaru@gmail.com" - } - ], - "autoload": { - "psr-4": { - "PhantomJS\\" : "src/" - } - }, - "minimum-stability": "stable" + "name": "cfv1000/phantomjs-cloud", + "description": "PhantomJS Cloud API based on Guzzle", + "type": "library", + "require": { + }, + "authors": [ + { + "name": "Flaviu Chelaru", + "email": "flaviu.chelaru@gmail.com" + } + ], + "autoload": { + "psr-4": { + "PhantomJS\\": "src/" + } + }, + "minimum-stability": "stable" } diff --git a/composer.lock b/composer.lock deleted file mode 100644 index 3b6c276..0000000 --- a/composer.lock +++ /dev/null @@ -1,246 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" - ], - "content-hash": "81f5d0f0539ea9ce8710385974edc329", - "packages": [ - { - "name": "guzzlehttp/guzzle", - "version": "6.2.3", - "source": { - "type": "git", - "url": "https://github.com/guzzle/guzzle.git", - "reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/8d6c6cc55186db87b7dc5009827429ba4e9dc006", - "reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006", - "shasum": "" - }, - "require": { - "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.4", - "php": ">=5.5" - }, - "require-dev": { - "ext-curl": "*", - "phpunit/phpunit": "^4.0", - "psr/log": "^1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "6.2-dev" - } - }, - "autoload": { - "files": [ - "src/functions_include.php" - ], - "psr-4": { - "GuzzleHttp\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Guzzle is a PHP HTTP client library", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "client", - "curl", - "framework", - "http", - "http client", - "rest", - "web service" - ], - "time": "2017-02-28T22:50:30+00:00" - }, - { - "name": "guzzlehttp/promises", - "version": "v1.3.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/promises.git", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "shasum": "" - }, - "require": { - "php": ">=5.5.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Promise\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Guzzle promises library", - "keywords": [ - "promise" - ], - "time": "2016-12-20T10:07:11+00:00" - }, - { - "name": "guzzlehttp/psr7", - "version": "1.4.2", - "source": { - "type": "git", - "url": "https://github.com/guzzle/psr7.git", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", - "shasum": "" - }, - "require": { - "php": ">=5.4.0", - "psr/http-message": "~1.0" - }, - "provide": { - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Psr7\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Tobias Schultze", - "homepage": "https://github.com/Tobion" - } - ], - "description": "PSR-7 message implementation that also provides common utility methods", - "keywords": [ - "http", - "message", - "request", - "response", - "stream", - "uri", - "url" - ], - "time": "2017-03-20T17:10:46+00:00" - }, - { - "name": "psr/http-message", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", - "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" - ], - "time": "2016-08-06T14:39:51+00:00" - } - ], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": [], - "platform-dev": [] -} diff --git a/src/Cookie.php b/src/Cookie.php index abad8c3..0d67aa5 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -3,6 +3,8 @@ /** * Class Cookie * @package PhantomJS + * + * @see http://php.net/manual/ro/function.setcookie.php */ class Cookie { diff --git a/src/PageRequest.php b/src/PageRequest.php index 7ae602b..f8f5eaf 100644 --- a/src/PageRequest.php +++ b/src/PageRequest.php @@ -40,7 +40,7 @@ class PageRequest * required. the target page you wish to load * @var string */ - public $url; + protected $url; /** * if specified, will be used as the content of the page you are loading (no network request will be made for the url). @@ -74,7 +74,7 @@ class PageRequest * * @var string */ - public $renderType; + public $renderType = self::RENDER_TYPE_JPEG; /** * adjustable parameters for when making network requests to the url specified diff --git a/src/PageResponse.php b/src/PageResponse.php index c534b9a..9695d0b 100644 --- a/src/PageResponse.php +++ b/src/PageResponse.php @@ -54,7 +54,7 @@ class PageResponse public $pageRequest; /** - * @var any + * @var */ public $scriptOutput; diff --git a/src/PdfHeaderFooter.php b/src/PdfHeaderFooter.php index 4334aa4..b4c16a8 100644 --- a/src/PdfHeaderFooter.php +++ b/src/PdfHeaderFooter.php @@ -10,7 +10,7 @@ class PdfHeaderFooter { /** * if specified, this is used for the first page (instead of the repeating) - * @var stringw + * @var string */ public $firstPage; diff --git a/src/PdfOptions.php b/src/PdfOptions.php index cbf852c..0b2be3b 100644 --- a/src/PdfOptions.php +++ b/src/PdfOptions.php @@ -24,10 +24,11 @@ class PdfOptions * Border is optional and defaults to 0. * A non-uniform border can be specified in the form {left: '2cm', top: '2cm', right: '2cm', bottom: '3cm'} * Use of px is strongly recommended. + * TODO Build an object to represent the data * * @var int|array */ - public $border; + public $border = 0; /** * set the DPI for pdf generation. diff --git a/src/ProxyCustomOptions.php b/src/ProxyCustomOptions.php index 72d215c..0d715be 100644 --- a/src/ProxyCustomOptions.php +++ b/src/ProxyCustomOptions.php @@ -27,7 +27,9 @@ class ProxyCustomOptions public $host; /** - * type of the proxy server. default is http available types are http, socks5, and none + * type of the proxy server. + * default is http + * available types are http, socks5, and none * * @var string */ diff --git a/src/RequestSettings.php b/src/RequestSettings.php index 060667b..b845f12 100644 --- a/src/RequestSettings.php +++ b/src/RequestSettings.php @@ -131,7 +131,7 @@ class RequestSettings * * @var int */ - public $waitInterval; + public $waitInterval = 1000; /** * set to true to enable web security. default is false diff --git a/src/ScriptPjscMeta.php b/src/ScriptPjscMeta.php index 172c02f..66b423b 100644 --- a/src/ScriptPjscMeta.php +++ b/src/ScriptPjscMeta.php @@ -14,19 +14,19 @@ class ScriptPjscMeta * * @var boolean */ - public $forceFinish; + public $forceFinish = false; /** * set to false by default. if true, will delay rendering until you set it back to false. good if you are waiting on an AJAX event. * * @var boolean */ - public $manualWait; + public $manualWait = false; /** * allows you to override specific pageRequest options with values you compute in your script (based on the document at runtime) * - * @var ClipRectangleOptions[] + * @var ClipRectangleOptions */ public $optionsOverrides; diff --git a/src/UserRequest.php b/src/UserRequest.php index a6d8fc4..8a83b70 100644 --- a/src/UserRequest.php +++ b/src/UserRequest.php @@ -33,24 +33,37 @@ class UserRequest * beta: the latest backend we are testing (phantomjs v2.5b). * * You can also specify an exact backend: phantom 2.1.1 or phantom 2.5beta. - * + * TODO add constants for possible values * @var */ - public $backend; + public $backend = 'default'; /** * setting this forces the value of the outputAsJson parameter, regardless of what the last page's value of outputAsJson was set to. default is undefined. * * @var boolean */ - public $outputAsJSON; + public $outputAsJSON = false; + + /** + * UserRequest constructor. + * @param null|PageRequest|string $pageRequest + */ + public function __construct($pageRequest = null) + { + if ($pageRequest instanceof PageRequest) { + $this->addPageRequest($pageRequest); + } elseif ($pageRequest !== null) { + $this->addPageRequest(new PageRequest($pageRequest)); + } + } /** * @param PageRequest $page * * @return int */ - public function addPage(PageRequest $page) + public function addPageRequest(PageRequest $page) { return array_push($this->pages, $page); }