Преглед изворни кода

Removing outdated docs and examples

Jonny Wenmoth пре 10 година
родитељ
комит
190a113775

+ 0 - 365
doc/advanced.rst

@@ -1,365 +0,0 @@
-Advanced
-========
-
--  `PhantomJS command line options <#phantomjs-command-line-options>`__
--  `Custom PhantomJS scripts <#custom-phantom-js-scripts>`__
--  `Writing a custom script <#writing-a-custom-script>`__
--  `Using custom request parameters in your
-   script <#using-custom-request-parameters-in-your-script>`__
--  `Loading your script <#loading-your-script>`__
-
-PhantomJS command line options
-------------------------------
-
-The PhantomJS API contains a range of command line options that can be
-passed when executing the PhantomJS executable. These can also be passed
-in via the client before a request:
-
-.. code:: php
-
-
-        <?php
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        $client->addOption('--load-images=true');
-        $client->addOption('--ignore-ssl-errors=true');
-        
-        $request  = $client->getMessageFactory()->createRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-
-        $client->send($request, $response);
-
-You can also set a path to a JSON configuration file that contains
-multiple PhantomJS options:
-
-.. code:: php
-
-
-        <?php
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        $client->addOption('--config=/path/to/config.json');
-        
-        $request  = $client->getMessageFactory()->createRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-
-        $client->send($request, $response);
-
-See the `PhantomJS
-Documentation <http://phantomjs.org/api/command-line.html>`__ for a full
-list of command line options.
-
-Custom PhantomJS scripts
-------------------------
-
-In most instances you shouldn't need to worry about the javascript files
-that run the PHP PhantomJS library but there may be times when you want
-to execute your own custom PhantomJS scripts through the client. This
-can be easily achieved by using the built in script loader.
-
-Script files or 'procedures' as they are referred to in the application
-are closely mapped to requests. When you create a default request
-instance, you are essentially running the default javascript procedure
-that comes bundled with the application. When you create a capture
-request you are running the capture procedure.
-
-.. code:: php
-
-
-        <?php
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client->getMessageFactory()->createRequest(); // ~/Resources/procedures/default.proc
-        $client->getMessageFactory()->createCaptureRequest(); // ~/Resources/procedures/capture.proc
-
-Writing a custom script
-~~~~~~~~~~~~~~~~~~~~~~~
-
-The first step in creating your script is to create a procedure file
-somewhere. For the purpose of this guide we will refer to it as
-``my_procedure.proc`` but in reality it can be called anything you like.
-The only requirement is that the file extension must be ``.proc``.
-
-Create the file somewhere and make sure it can be read by your
-application. Make a note of the path to the directory where your file is
-created as you will need this when loading your script which is
-explained later in this guide.
-
-.. code:: shell
-
-        
-        $ touch my_procedure.proc
-        $ chmod 755 my_procedure.proc
-        
-
-Next open your procedure file in your text editor and write your
-PhantomJS script. The `PhantomJS
-documentation <http://phantomjs.org/quick-start.html>`__ has more
-detailed information on writing custom scripts.
-
-.. code:: javascript
-
-        
-        // my_procedure.proc
-
-        var page  = require('webpage').create();
-        
-        page.open ('{{ request.getUrl() }}', '{{ request.getMethod() }}', '{{ request.getBody() }}', function (status) {
-             
-            // It is important that you exit PhantomJS
-            // when your script has run or when you
-            // encounter an error
-            phantom.exit(1);
-        });
-        
-        ...
-        
-
-.. important::
-   Make sure that ``phantom.exit(1);`` is always called after your script has run or if you encounter an error. This requires you to take care when handling PhantomJS errors to ensure that you exit the PhantomJS script, whether the script was successfully executed or not. If you do not call ``phantom.exit(1);`` then PhantomJS will continue to run until your PHP script times out. If you find that your custom script is hanging then this is most likely the cause.
-
-It is a good practice to create a global error handler in your script
-that exits PhantomJS:
-
-.. code:: javascript
-
-
-        // my_procedure.proc
-
-        phantom.onError = function(msg, trace) {
-      
-            phantom.exit(1);
-        };
-        
-        ...
-
-Using custom request parameters in your script
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Before a procedure is executed by the application it is parsed through a
-template parser. The PHP PhantomJS library uses the popular `Twig
-templating engine <https://github.com/fabpot/Twig>`__. This gives you
-access to all the `Twig
-niceness <http://twig.sensiolabs.org/doc/templates.html>`__ which you
-can use in your custom scripts.
-
-You may have noticed in the example above that we have used some Twig
-template tags referencing a request object e.g.
-``{{ request.getUrl() }}``. This is in fact the PHP request instance
-that you created and passed to the client when sending your request,
-which is injected into the Twig template parser. As a result you gain
-full access to all the data contained within the request instance, via
-the data accessor methods.
-
-A default request instance contains the following accessors:
-
-+--------------------------+-----------------------------------------------+------------------------------------+
-| Accessor                 | Description                                   | Twig example                       |
-+==========================+===============================================+====================================+
-| getMethod()              | The request method e.g. GET.                  | {{ request.getMethod() }}          |
-+--------------------------+-----------------------------------------------+------------------------------------+
-| getTimeout()             | The request timeout period in milliseconds.   | {{ request.getTimeout() }}         |
-+--------------------------+-----------------------------------------------+------------------------------------+
-| getDelay()               | The page render delay in seconds.             | {{ request.getDelay() }}           |
-+--------------------------+-----------------------------------------------+------------------------------------+
-| getViewportWidth()       | The viewport width.                           | {{ request.getViewportWidth() }}   |
-+--------------------------+-----------------------------------------------+------------------------------------+
-| getViewportHeight()      | The viewport height.                          | {{ request.getViewportHeight() }}  |
-+--------------------------+-----------------------------------------------+------------------------------------+
-| getUrl()                 | The request URL.                              | {{ request.getUrl() }}             |
-+--------------------------+-----------------------------------------------+------------------------------------+
-| getBody()                | The request body (POST, PUT).                 | {{ request.getBody() }}            |
-+--------------------------+-----------------------------------------------+------------------------------------+
-| getHeaders(\ *format*)   | The request headers.                          | {{ request.getHeaders('json') }}   |
-+--------------------------+-----------------------------------------------+------------------------------------+
-
-A capture request contains a few additional ones:
-
-+--------------------+-------------------------------------------+----------------------------------+
-| Accessor           | Description                               | Twig example                     |
-+====================+===========================================+==================================+
-| getRectTop()       | The x coordinate of the capture region.   | {{ request.getRectTop() }}       |
-+--------------------+-------------------------------------------+----------------------------------+
-| getRectLeft()      | The y coordinate of the capture region.   | {{ request.getRectLeft() }}      |
-+--------------------+-------------------------------------------+----------------------------------+
-| getRectWidth()     | The width of the capture region.          | {{ request.getRectWidth() }}     |
-+--------------------+-------------------------------------------+----------------------------------+
-| getRectHeight()    | The height of the capture region.         | {{ request.getRectHeight() }}    |
-+--------------------+-------------------------------------------+----------------------------------+
-| getCaptureFile()   | The file to save the capture to.          | {{ request.getCaptureFile() }}   |
-+--------------------+-------------------------------------------+----------------------------------+
-
-If you would like to inject additional data into your script through
-custom accessors, simply extend the request class with your own:
-
-.. code:: php
-
-
-        <?php
-
-        use JonnyW\PhantomJs\Message\Request;
-        
-        class CustomRequest extends Request
-        {
-        
-            public function getSomething()
-            {
-                return 'Something!';
-            }
-        }
-
-Now you will be able to access the data in your custom script when using
-your custom request:
-
-.. code:: javascript
-
-        
-        // my_procedure.proc
-
-        var something = '{{ request.getSomething() }}'; // Get something
-        
-        ...
-        
-
-And to use your custom request simply create a new instance of it and
-pass it to the client:
-
-.. code:: php
-
-
-        <?php
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        
-        $response = $client->getMessageFactory()->createResponse();
-        
-        $request  = new CustomRequest();
-        $request->setMethod('GET');
-        $request->setUrl('http://www.google.com');
-        
-        $client->send($request, $response);
-
-Loading your script
-~~~~~~~~~~~~~~~~~~~
-
-Now that you have your custom script and you've added your custom
-request parameters, you may be wondering how to tell the client to
-actually load your script. This is done by creating a procedure loader
-and telling it where to find your script files.
-
-The service container has a factory that makes creating a new procedure
-loader easy:
-
-.. code:: php
-
-
-        <?php
-        
-        use JonnyW\PhantomJs\Client;
-        use JonnyW\PhantomJs\DependencyInjection\ServiceContainer;
-        
-        $location = '/path/to/your/procedure/directory';
-        
-        $serviceContainer = ServiceContainer::getInstance();
-        
-        $procedureLoader = $serviceContainer->get('procedure_loader_factory')
-            ->createProcedureLoader($location);
-            
-        ...
-
-The client contains a chain procedure loader which lets you set multiple
-loaders at the same time. Ultimately this means that you can load your
-custom scripts while still maintaining the ability to load the default
-scripts if you choose.
-
-Now add your procedure loader to the chain loader:
-
-.. code:: php
-
-
-        <?php
-
-        ...
-        
-        $client = Client::getInstance();
-        $client->getProcedureLoader()->addLoader($procedureLoader);
-        
-        ...
-
-The last thing you need to do is to tell the request which script you
-want to load for that request. This is done by setting the request type
-to the name of your procedure file, minus the extension:
-
-.. code:: php
-
-
-        <?php
-
-        ...
-        
-       $request = $client->getMessageFactory()->createRequest();
-       $request->setType('my_procedure');
-        
-        ...
-
-Or if you are using a custom request as outlined in the `custom request
-parameters <#using-custom-request-parameters-in-your-script>`__ section,
-you can implement a ``getType()`` method which returns the name of your
-procedure, eliminating the need to set the request type for each
-request:
-
-.. code:: php
-
-
-    <?php
-
-        use JonnyW\PhantomJs\Message\Request;
-        
-        class CustomRequest extends Request
-        {
-        
-            public function getType()
-            {
-                return 'my_procedure';
-            }
-        }
-
-Below is a full example for clarity:
-
-.. code:: php
-
-
-        <?php
-        
-        use JonnyW\PhantomJs\Client;
-        use JonnyW\PhantomJs\DependencyInjection\ServiceContainer;
-        
-        $location = '/path/to/your/procedure/directory';
-        
-        $serviceContainer = ServiceContainer::getInstance();
-        
-        $procedureLoader = $serviceContainer->get('procedure_loader_factory')
-            ->createProcedureLoader($location);
-            
-        $client = Client::getInstance();
-        $client->getProcedureLoader()->addLoader($procedureLoader);
-        
-        $request = $client->getMessageFactory()->createRequest();
-        $request->setType('my_procedure');
-        
-        $response = $client->getMessageFactory()->createResponse();
-        
-        $client->send($request, $response);
-
-.. important::
-   If you find that your script isn't running or that you are receiving a status of '0' back in the response, chances are you have a syntax error in you script. It pays to turn debugging on in the client ``$client->debug(true)`` which will then give you access to some log information through ``$client->getLog()``.
-
-See more detailed information about
-`troubleshooting https://github.com/jonnnnyw/php-phantomjs/blob/master/doc/troubleshooting.rst>`__.

+ 0 - 128
doc/installation.rst

@@ -1,128 +0,0 @@
-Installation
-============
-
-- `Prerequisites <#prerequisites>`__
-- `Installing via Composer <#installing-via-composer>`__
-- `Custom Installation <#custom-installation>`__
-- `Installing from tarball <#installing-from-tarball>`__
-
-Prerequisites
--------------
-
-PHP PhantomJS requires PHP **5.3.0** or greater to run.
-
-Installing via Composer
------------------------
-
-Install `Composer <https://getcomposer.org/>`__ for your project:
-
-.. code:: shell
-
-        $ curl -s http://getcomposer.org/installer | php
-
-Create a ``composer.json`` file in the root of your project:
-
-.. code:: yaml
-
-        {
-            "require": {
-                "jonnyw/php-phantomjs": "3.*"
-            },
-            "config": {
-                "bin-dir": "bin"
-            },
-            "scripts": {
-                "post-install-cmd": [
-                    "PhantomInstaller\\Installer::installPhantomJS"
-                ],
-                "post-update-cmd": [
-                    "PhantomInstaller\\Installer::installPhantomJS"
-                ]
-            }
-        }
-
-It is important that you have the 'scripts' section shown above in your
-``composer.json`` file as it will install the latest version of
-PhantomJS for your system to your project's bin folder. It is
-recommended that you create a bin folder in the root of your project as
-this is where the PHP PhantomJS library will look for your PhantomJS
-executable. If you would prefer to use a PhantomJS executable in a
-custom location, see the `Custom Installation <#custom-installation>`__
-section.
-
-Finally, install the composer depedencies for your project:
-
-.. code:: shell
-                
-        $ php composer.phar install
-
-Custom Installation
--------------------
-
-If you would prefer to use a custom install location for the PhantomJS
-executable, you simply need to tell the client where to find the
-executable file:
-
-.. code:: php
-
-        use JonnyW\PhantomJs\Client;
-
-        $client = Client::getInstance();
-        $client->setPhantomJs('/path/to/phantomjs');
-
-.. important::
-    The PHP PhantomJS library also requires a `phantomloader` file that comes bundled with the library and is installed to the bin folder defined in your `composer.json` file. If you are setting a custom path to the PhantomJS executable, you need to make sure that the `phantomloader` file can be found in the bin folder it was installed to.
-
-If you would like composer to install all executable files to a custom bin location when installing dependencies, set the bin dir location in your project's `composer.json` file:
-
-.. code:: yaml
-
-        {
-            "config": {
-                "bin-dir": "/path/to/your/projects/bin/dir"
-            }
-        }
-
-You will need to make sure that this directory exists and is writable by
-Composer before running the composer install.
-
-Once you have updated your bin location run composer install to install
-PhantomJS:
-
-.. code:: shell
-                
-        $ php composer.phar install
-
-This should install the correct PhantomJS executable for your system and the required `phantomloader` file to the bin locaiton you defined in your `composer.json` file. 
-
-Now you need to tell the client where to find your bin folder:
-
-.. code:: php
-
-        use JonnyW\PhantomJs\Client;
-
-        $client = Client::getInstance();
-        $client->setBinDir('/path/to/bin/dir');
-
-Installing from tarball
------------------------
-
-The PHP PhantomJS library contains several depedencies in order to
-function so it is recommended that you install it via composer as this
-will handle your dependencies for you. If you do wish to install it from
-a `tarball release <https://github.com/jonnnnyw/php-phantomjs/tags>`__
-then you will need to install the dependencies manually.
-
-The PHP PhantomJS library currently requires the following depdencies:
-
--  `Symfony Config Component <https://github.com/symfony/Config>`__ ~2.5
--  `Symfony Dependency Injection
-   Component <https://github.com/symfony/DependencyInjection>`__ ~2.5
--  `Symfony Filesystem
-   Component <https://github.com/symfony/filesystem>`__ ~2.5
--  `Twig templating Component <https://github.com/fabpot/Twig>`__ ~1.16
--  `PhantomJS <http://phantomjs.org/>`__ ~1.9
-
-Make sure the components are in your include path and that the PhantomJS
-executable is installed to your projects bin folder as mentioned in the
-`Custom Installation <#custom-installation>`__ section.

+ 0 - 129
doc/intro.rst

@@ -1,129 +0,0 @@
-Introduction
-============
-
-| PHP PhantomJS is a flexible PHP library to load pages through the
-PhantomJS
-| headless browser and return the page response. It is handy for testing
-| websites that demand javascript support and also supports screen
-captures.
-
-Feature List
-------------
-
--  Load webpages through the PhantomJS headless browser
--  View detailed response data including page content, headers, status
-   code etc.
--  Handle redirects
--  View javascript console errors
--  View detailed PhantomJS debuged information
--  Save screen captures to local disk
--  Define screen capture x, y, width and height parameters
--  Set viewport size
--  Delay page rendering for a specified time
--  Execute PhantomJS with command line options
--  Easily build and run custom PhantomJS scripts
-
-Prerequisites
--------------
-
-PHP PhantomJS requires PHP **5.3.0** or greater to run.
-
-Installation
-------------
-
-It is recommended that you use Composer to install PHP PhantomJS. First,
-add the following to your project’s ``composer.json`` file:
-
-.. code:: xml
-
-    "scripts": {
-        "post-install-cmd": [
-            "PhantomInstaller\\Installer::installPhantomJS"
-        ],
-        "post-update-cmd": [
-            "PhantomInstaller\\Installer::installPhantomJS"
-        ]
-    }
-
-This will ensure the latest version of PhantomJS is installed for your
-system, in your bin folder. If you haven’t defined your bin folder in
-your composer.json, add the path:
-
-.. code:: xml
-
-    "config": {
-        "bin-dir": "bin"
-    }
-
-Finally, install PHP PhantomJS from the root of your project:
-
-.. code:: shell
-
-    $ composer require "jonnyw/php-phantomjs:3.*"
-
-If you would like to use another installation method or would like to
-see more detailed installation instructions, see the `installation <https://github.com/jonnnnyw/php-phantomjs/blob/master/doc/installation.rst>`__
-documentation.
-
-Basic Usage
------------
-
-The following illustrates how to make a basic GET request and output the
-page content:
-
-.. code:: php
-
-    <?php
-
-    use JonnyW\PhantomJs\Client;
-
-    $client = Client::getInstance();
-
-    /** 
-     * @see JonnyW\PhantomJs\Message\Request 
-     **/
-    $request = $client->getMessageFactory()->createRequest('http://google.com', 'GET');
-
-    /** 
-     * @see JonnyW\PhantomJs\Message\Response 
-     **/
-    $response = $client->getMessageFactory()->createResponse();
-
-    // Send the request
-    $client->send($request, $response);
-
-    if($response->getStatus() === 200) {
-
-        // Dump the requested page content
-        echo $response->getContent();
-    }
-
-And if you would like to save a screen capture to local disk:
-
-.. code:: php
-
-    <?php
-
-    use JonnyW\PhantomJs\Client;
-
-    $client = Client::getInstance();
-
-    /** 
-     * @see JonnyW\PhantomJs\Message\CaptureRequest
-     **/
-    $request = $client->getMessageFactory()->createCaptureRequest('http://google.com', 'GET');
-    $request->setCaptureFile('/path/to/save/capture/file.jpg');
-
-    /** 
-     * @see JonnyW\PhantomJs\Message\Response 
-     **/
-    $response = $client->getMessageFactory()->createResponse();
-
-    // Send the request
-    $client->send($request, $response);
-
-For more detailed examples see the `usage`_ section, or to create
-your own custom scripts check out the `advanced`_ documentation.
-
-.. _usage: https://github.com/jonnnnyw/php-phantomjs/blob/master/doc/usage.rst
-.. _advanced: https://github.com/jonnnnyw/php-phantomjs/blob/master/doc/advanced.rst

+ 0 - 372
doc/troubleshooting.rst

@@ -1,372 +0,0 @@
-Troubleshooting
-===============
-
--  `It's not installing anything to my bin
-   directory <#its-not-installing-anything-to-my-bin-directory>`__
--  `I am getting a InvalidExecutableException when making a
-   request <#i-am-getting-a-invalidexecutableexception-when-making-a-request>`__
--  `I am getting a NotWritableException when making a
-   request <#i-am-getting-a-notwritableexception-when-making-a-request>`__
--  `Why do I need the phantomloader
-   file? <#why-do-i-need-the-phantomloader-file>`__
--  `Why am I getting a status code of 0 in the
-   response? <#why-am-i-getting-a-status-code-of-0-in-the-response>`__
--  `It's not saving my screenshots <#its-not-saving-my-screenshots>`__
--  `Can I set the screenshot size? <#can-i-set-the-screenshot-size>`__
--  `Can I set the viewport size? <#can-i-set-the-viewport-size>`__
--  `How do I debug a request? <#how-do-i-debug-a-request>`__
--  `I am getting SyntaxError: Parse error in the debug
-   log <#i-am-getting-syntaxerror-parse-error-in-the-debug-log>`__
-
-It's not installing anything to my bin directory
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-When installing via composer, as outlined in the `installation
-guide <https://github.com/jonnnnyw/php-phantomjs/blob/master/doc/installation.rst>`__, it is recommended
-that you define the location of the bin folder for your project. This
-can be done by adding the following to your ``composer.json`` file:
-
-.. code:: yaml
-
-        #composer.json
-    
-        {
-            "config": {
-                "bin-dir": "/path/to/your/projects/bin/dir"
-            }
-        }
-
-You need to make sure that this directory exists and is writable before
-you install your composer depedencies.
-
-Once you have defined your bin folder in your ``composer.json`` file,
-run composer install from the root of your project:
-
-.. code:: shell
-
-        #bash
-    
-        $ php composer.phar install
-
-This should install 2 files to your bin folder: ``phantomjs`` and
-``phantomloader``. If you do not have these 2 files in your bin folder
-then check that the folder is writable and run composer install again.
-
-.. important::
-    If you do not define a bin directory in your ``composer.json`` file
-    then the default install location will be ``vendor/bin/``. If you
-    choose to not set a bin folder path then you will need to make sure
-    that this path is set in the client by calling
-    ``$client->setBinDir('vendor/bin');`` before making a request.
-
-I am getting a ``InvalidExecutableException`` when making a request
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-If you have installed via composer, as outlined in the `installation
-guide <https://github.com/jonnnnyw/php-phantomjs/blob/master/doc/installation.rst>`__, then you should
-have 2 files installed in either the ``bin`` or ``vendor/bin/``
-directory, in the root of your project. These files are called
-``phantomjs`` and ``phantomloader``.
-
-Check that these files exist and are executable by your application. If
-they do not exist, see `It's not installing anything to my bin
-directory <#its-not-installing-anything-to-my-bin-directory>`__.
-
-If the PHP PhantomJS library cannot locate either of these files then it
-will throw a ``InvalidExecutableException``. The message in the
-exception should tell you which one it can't execute. If both of these
-files exist and they are executable by your application, you may need to
-set the path to the directory that these files live in before making a
-request:
-
-.. code:: php
-
-        <?php 
-    
-        use JonnyW\PhantomJs\Client;
-    
-        $client = Client::getInstance();
-        $client->setBinDir('/path/to/bin/dir');
-
-I am getting a ``NotWritableException`` when making a request
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-When making a request, the PHP PhantomJS library compiles a temporary
-script file to your system's tmp folder. The location of this folder is
-determined through the use of the ``sys_get_temp_dir()`` function. If
-this directory is not writable by your application then you will receive
-this exception.
-
-Why do I need the ``phantomloader`` file?
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-A proxy loader file is used get around a quirk that PhantomJS has when
-it encounters a syntax error in a script file. By default, if PhantomJS
-encounters a syntax error when loading a script file it will not exit
-execution. This means that PHP PhantomJS will continue to wait for a
-response from PhantomJS until PHP reaches its script execution timeout
-period. This also means you won't get any debug information informing
-you that the PhantomJS script has a syntax error.
-
-To get around this, script files are loaded through a loader script.
-This handles the event of a syntax error and ensures that PhantomJS
-exits when an error is encountered.
-
-The ``phantomloader`` file is required in order for the PHP PhantomJS
-library to run so please make sure that it was installed to your bin
-folder and is readable by your application.
-
-Another reason for getting this exception is when you are trying to save
-screenshots. See `It's not saving my
-screenshots <#its-not-saving-my-screenshots>`__.
-
-Why am I getting a status code of 0 in the response?
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-A status code of 0 in the response object generally means the request
-did not complete successfully. This could mean that the URL you are
-requesting did not return a response or that something happened when
-making the request that did not raise an error in the PHP PhantomJS
-library.
-
-Becuase and exception was not thrown, chances are the issue is with
-PhantomJS itself or at the endpoint you are calling.
-
-One possible reason for this is that your request has timed out before a
-response was returned from the endpoint that you are requesting.
-Depending on what you are requesting, some websites seem to take a while
-to return a response. An example of this is
-`myspace.com <https://myspace.com/>`__ which, at the time of writing
-this, takes a considerable amount of time resolve through PhantomJS.
-
-To work around this you can try increasing the timeout period in the PHP
-PhantomJS client:
-
-.. code:: php
-
-        <?php
-    
-        use JonnyW\PhantomJs\Client;
-    
-        $client = Client::getInstance();
-    
-        $request  = $client->getMessageFactory()->createRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-    
-        $timeout = 20000; // 20 seconds
-    
-        $request->setTimeout($timeout);
-    
-        $client->send($request, $response);
-
-If you are still having a problem then you should enable debugging,
-before you make the request, and check the debug log. This contains a
-dump of information from PhantomJS which could help to track down why
-you are not getting a response.
-
-.. code:: php
-
-        <?php
-    
-        use JonnyW\PhantomJs\Client;
-    
-        $client = Client::getInstance();
-        $client->debug(true); // Set debug flag
-    
-        $request  = $client->getMessageFactory()->createRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-            
-        $client->send($request, $response);
-    
-        echo $client->getLog(); // Output log
-
-You can also try running a test script through your PhantomJS
-executable, from the command line, to see if you get a valid response
-back. Save the following script somewhere:
-
-.. code:: javascript
-
-        //test-script.js
-    
-        var page = require('webpage').create(),
-            url = 'YOUR REQUEST URL', // Change this to the URL you want to request
-            response; 
-    
-        page.onResourceReceived = function (r) {
-            response = r;
-        };
-    
-        phantom.onError = function(msg, trace) {
-    
-            console.log(msg);
-            console.log(trace);
-            phantom.exit(1);
-        };
-    
-        page.open (url, 'GET', '', function (status) {
-            
-            console.log(status);
-            console.log(JSON.stringify(response));
-            phantom.exit();
-        });
-
-And then, assuming you have saved the script above to ``test-script.js``
-in the root of your project and your PhantomJS executable is located at
-``bin/phantomjs``, run the following:
-
-.. code:: shell
-
-        #bash
-    
-        $ bin/phantomjs ./test-script.js
-
-You should see an output of the response from PhantomJS:
-
-.. code:: shell
-
-        #bash
-    
-        success
-        {"contentType":"text/javascript; charset=UTF-8", "headers": ...
-    
-
-If you don't see ``success`` followed by a JSON encoded response object
-then there is something the with the URL you are requesting or your
-PhantomJS executable. Try reinstalling PhantomJS. If you see ``fail``
-instead of ``success``, chances are the URL you are requesting is
-invalid or not resolving.
-
-It's not saving my screenshots
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-When making a capture request you need to make sure that you are setting
-the file location that you want the screenshot saved to, including the
-filename:
-
-.. code:: php
-
-        <?php
-    
-        use JonnyW\PhantomJs\Client;
-    
-        $client = Client::getInstance();
-    
-        $request  = $client->getMessageFactory()->createCaptureRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-    
-        $file = '/path/to/save/your/screen/capture/file.jpg';
-    
-        $request->setCaptureFile($file); // Set the capture file
-    
-        $client->send($request, $response);
-
-The file itself does not need to exist but the parent directory must
-exist and be writable by your application. Check that your application
-has permissions to write files to the directory you are setting for your
-screen captures.
-
-Can I set the screenshot size?
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Yes, you can set the width and height of your capture along with the x
-and y coordinates of where the capture should start from:
-
-.. code:: php
-
-        <?php
-    
-        use JonnyW\PhantomJs\Client;
-    
-        $client = Client::getInstance();
-    
-        $request  = $client->getMessageFactory()->createCaptureRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-    
-        $file = '/path/to/save/your/screen/capture/file.jpg';
-    
-        $top    = 10;
-        $left   = 10;
-        $width  = 200;
-        $height = 400;
-    
-        $request->setCaptureFile($file);
-        $request->setCaptureDimensions($width, $height, $top, $left);
-    
-        $client->send($request, $response);
-
-Can I set the viewport size?
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Yes, you can set the viewport dimensions on both regular and capture
-requests:
-
-.. code:: php
-
-        <?php
-    
-        use JonnyW\PhantomJs\Client;
-    
-        $client = Client::getInstance();
-    
-        $request  = $client->getMessageFactory()->createRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-            
-        $width  = 200;
-        $height = 400;
-    
-        $request->setViewportSize($width, $height); // Set viewport size
-    
-        $client->send($request, $response);
-
-How do I debug a request?
-~~~~~~~~~~~~~~~~~~~~~~~~~
-
-By setting the debug flag to ``true`` on the client, you can get a dump
-of information output from PhantomJS along with some info events added
-by the PHP PhantomJS library:
-
-.. code:: php
-
-        <?php
-    
-        use JonnyW\PhantomJs\Client;
-    
-        $client = Client::getInstance();
-        $client->debug(true); // Set debug flag
-    
-        $request  = $client->getMessageFactory()->createRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-            
-        $client->send($request, $response);
-    
-        echo $client->getLog(); // Output log
-
-You can also get any javacript console errors along with a stack trace
-from the URL you are calling, in the response object:
-
-.. code:: php
-
-        <?php
-    
-        use JonnyW\PhantomJs\Client;
-    
-        $client = Client::getInstance();
-    
-        $request  = $client->getMessageFactory()->createRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-            
-        $client->send($request, $response);
-    
-        var_dump($response->getConsole()); // Outputs array of console errors and stack trace
-
-I am getting ``SyntaxError: Parse error`` in the debug log
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-You will only get this error if the script file that is being run by
-PhantomJS has a syntax error. If you are writing your own `custom
-scripts <https://github.com/jonnnnyw/php-phantomjs/blob/master/doc/advanced.rst#custom-phantomjs-scripts>`__
-then try setting the `debug flag <#how-do-i-debug-a-request>`__ which
-*should* print some more detailed information in the debug log. Also
-check that you aren't setting any parameters to ``null`` in your request
-object as this could be causing a javascript error due to javascript
-variables being set to nothing e.g. ``var width = ,``.

+ 0 - 315
doc/usage.rst

@@ -1,315 +0,0 @@
-Usage
-=====
-
-This page contains some common examples of how to use the PHP PhantomJS
-library.
-
--  `Basic Request <#basic-request>`__
--  `POST Request <#post-request>`__
--  `Other Request Methods <#other-request-methods>`__
--  `Response Data <#response-data>`__
--  `Screen Captures <#screen-captures>`__
--  `Set Viewport Size <#set-viewport-size>`__
--  `Custom Timeout <#custom-timeout>`__
--  `Delay Page Render <#delay-page-render>`__
--  `Custom Run Options <#custom-run-options>`__
-
-Basic Request
--------------
-
-A basic GET request:
-
-.. code:: php
-
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        
-        $request  = $client->getMessageFactory()->createRequest();
-        $response = $client->getMessageFactory()->createResponse();
-        
-        $request->setMethod('GET');
-        $request->setUrl('http://google.com');
-        
-        $client->send($request, $response);
-        
-        if($response->getStatus() === 200) {
-            echo $response->getContent();
-        }
-
-You can also set the URL, request method and timeout period when
-creating a new request instance through the message factory:
-
-.. code:: php
-
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        
-        $request  = $client->getMessageFactory()->createRequest('http://google.com', 'GET', 5000);
-        $response = $client->getMessageFactory()->createResponse();
-            
-        $client->send($request, $response);
-        
-        if($response->getStatus() === 200) {
-            echo $response->getContent();
-        }
-
-POST Request
-------------
-
-A basic POST request:
-
-.. code:: php
-
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        
-        $request  = $client->getMessageFactory()->createRequest();
-        $response = $client->getMessageFactory()->createResponse();
-        
-        $data = array(
-            'param1' => 'Param 1',
-            'param2' => 'Param 2'
-        );
-        
-        $request->setMethod('POST');
-        $request->setUrl('http://google.com');
-        $request->setRequestData($data); // Set post data
-        
-        $client->send($request, $response);
-
-Other Request Methods
----------------------
-
-The PHP PhantomJS library supports the following request methods:
-
--  OPTIONS
--  GET
--  HEAD
--  POST
--  PUT
--  DELETE
--  PATCH
-
-The request method can be set when creating a new request instance
-through the message factory:
-
-.. code:: php
-
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        
-        $request  = $client->getMessageFactory()->createRequest('http://google.com', 'PUT');
-
-Or on the request instance itself:
-
-.. code:: php
-
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        
-        $request  = $client->getMessageFactory()->createRequest();
-        $request->setMethod('PATCH');
-
-Response Data
--------------
-
-A standard response gives you access to the following interface:
-
-+-------------------------+---------------------------------------------------------------------------------------------+---------------+
-| Accessor                | Description                                                                                 | Return Type   |
-+=========================+=============================================================================================+===============+
-| getHeaders()            | Returns an array of all response headers.                                                   | Array         |
-+-------------------------+---------------------------------------------------------------------------------------------+---------------+
-| getHeader(\ *header*)   | Returns the value for a specific response header e.g. Content-Type.                         | Mixed         |
-+-------------------------+---------------------------------------------------------------------------------------------+---------------+
-| getStatus()             | The response status code e.g. 200.                                                          | Int           |
-+-------------------------+---------------------------------------------------------------------------------------------+---------------+
-| getContent()            | The raw page content of the requested page.                                                 | String        |
-+-------------------------+---------------------------------------------------------------------------------------------+---------------+
-| getContentType()        | The content type of the requested page.                                                     | String        |
-+-------------------------+---------------------------------------------------------------------------------------------+---------------+
-| getUrl()                | The URL of the requested page.                                                              | String        |
-+-------------------------+---------------------------------------------------------------------------------------------+---------------+
-| getRedirectUrl()        | If the response was a redirect, this will return the redirect URL.                          | String        |
-+-------------------------+---------------------------------------------------------------------------------------------+---------------+
-| isRedirect()            | Will return true if the response was a redirect or false otherwise.                         | Boolean       |
-+-------------------------+---------------------------------------------------------------------------------------------+---------------+
-| getConsole()            | Returns an array of any javascript errors on the requested page along with a stack trace.   | Array         |
-+-------------------------+---------------------------------------------------------------------------------------------+---------------+
-
-If the response contains a status code of 0, chances are the request
-failed. Check the request `debug
-log <https://github.com/jonnnnyw/php-phantomjs/blob/master/doc/troubleshooting.rst#how-do-i-debug-a-request>`__
-for more detailed information about what may have gone wrong.
-
-Screen Captures
----------------
-
-You can save screen captures of a page to your local disk by creating a
-screen capture request and setting the path you wish to save the file
-to:
-
-.. code:: php
-
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        
-        $request  = $client->getMessageFactory()->createCaptureRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-        
-        $file = '/path/to/save/your/screen/capture/file.jpg';
-        
-        $request->setCaptureFile($file);
-        
-        $client->send($request, $response);
-
-You will need to make sure the directory that you are saving the file to
-exists and is writable by your application.
-
-You can also set the width, height, x and y axis for your screen
-capture:
-
-.. code:: php
-
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        
-        $request  = $client->getMessageFactory()->createCaptureRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-        
-        $file = '/path/to/save/your/screen/capture/file.jpg';
-        
-        $top    = 10;
-        $left   = 10;
-        $width  = 200;
-        $height = 400;
-        
-        $request->setCaptureFile($file);
-        $request->setCaptureDimensions($width, $height, $top, $left);
-        
-        $client->send($request, $response);
-
-Set Viewport Size
------------------
-
-You can easily set the viewport size for a request:
-
-.. code:: php
-
-        <?php
-    
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        
-        $request  = $client->getMessageFactory()->createRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-            
-        $width  = 200;
-        $height = 400;
-        
-        $request->setViewportSize($width, $height);
-        
-        $client->send($request, $response);
-
-Custom Timeout
---------------
-
-By default, each request will timeout after 5 seconds. You can set a
-custom timeout period (in milliseconds) for each request:
-
-.. code:: php
-
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        
-        $request  = $client->getMessageFactory()->createRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-        
-        $timeout = 10000; // 10 seconds
-        
-        $request->setTimeout($timeout);
-        
-        $client->send($request, $response);
-
-Delay Page Render
------------------
-
-Sometimes when taking screen captures you may want to wait until the
-page is completely loaded before saving the capture. In this instance
-you can set a page render delay (in seconds) for the request:
-
-.. code:: php
-
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        
-        $request  = $client->getMessageFactory()->createCaptureRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-        
-        $delay = 5; // 5 seconds
-        
-        $request->setDelay($delay);
-        
-        $client->send($request, $response);
-
-You can set a page render delay for standard requests also.
-
-Custom Run Options
-------------------
-
-The PhantomJS API contains a range of command line options that can be
-passed when executing the PhantomJS executable. These can also be passed
-in via the client before a request:
-
-.. code:: php
-
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        $client->addOption('--load-images=true');
-        $client->addOption('--ignore-ssl-errors=true');
-        
-        $request  = $client->getMessageFactory()->createRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-
-        $client->send($request, $response);
-
-You can also set a path to a JSON configuration file that contains
-multiple PhantomJS options:
-
-.. code:: php
-
-
-        use JonnyW\PhantomJs\Client;
-        
-        $client = Client::getInstance();
-        $client->addOption('--config=/path/to/config.json');
-        
-        $request  = $client->getMessageFactory()->createRequest('http://google.com');
-        $response = $client->getMessageFactory()->createResponse();
-
-        $client->send($request, $response);
-
-See the `PhantomJS
-Documentation <http://phantomjs.org/api/command-line.html>`__ for a full
-list of command line options.

+ 0 - 17
examples/basic-request.php

@@ -1,17 +0,0 @@
-<?php
-
-require '../vendor/autoload.php';
-
-use JonnyW\PhantomJs\Client;
-
-$client = Client::getInstance();
-
-$request  = $client->getMessageFactory()->createRequest();
-$response = $client->getMessageFactory()->createResponse();
-
-$request->setMethod('GET');
-$request->setUrl('http://google.com');
-
-$client->send($request, $response);
-
-var_dump($response);

+ 0 - 31
examples/capture-request.php

@@ -1,31 +0,0 @@
-<?php
-
-require '../vendor/autoload.php';
-
-use JonnyW\PhantomJs\Client;
-
-$client = Client::getInstance();
-
-$request  = $client->getMessageFactory()->createCaptureRequest();
-$response = $client->getMessageFactory()->createResponse();
-
-$top    = 10;
-$left   = 10;
-$width  = 200;
-$height = 400;
-
-$request->setMethod('GET');
-$request->setUrl('http://google.com');
-$request->setCaptureFile(sprintf('%s/file.jpg', sys_get_temp_dir()));
-$request->setCaptureDimensions($width, $height, $top, $left);
-
-$client->send($request, $response);
-
-var_dump($response);
-
-// If the capture dimensions were applied
-// to the request, you will see an information
-// notice in the debug log. This is useful for
-// debugging captures and will always be present,
-// even if debug mode is disabled.
-var_dump($client->getLog());

+ 0 - 8
examples/custom-phantomjs-location.php

@@ -1,8 +0,0 @@
-<?php
-
-require '../vendor/autoload.php';
-
-use JonnyW\PhantomJs\Client;
-
-$client = Client::getInstance();
-$client->setPhantomJs('/path/to/phantomjs'); // PhantomJS executbale file path

+ 0 - 42
examples/custom-script.php

@@ -1,42 +0,0 @@
-<?php
-
-require '../vendor/autoload.php';
-
-use JonnyW\PhantomJs\Client;
-use JonnyW\PhantomJs\DependencyInjection\ServiceContainer;
-
-// Create a file with a custom name 
-// e.g. custom_procedure.proc and save it 
-// somewhere. Set the parameters below to
-// the name of your file and the location of
-// your file. You can have many files in the 
-// same location and you only need to create
-// 1 procedure loader with the path to your
-// files. The only restriction is the extension
-// your files must be .proc
-
-$fileName = 'custom_procedure';
-$filePath = '/path/to/your/procedure/';
-
-$serviceContainer = ServiceContainer::getInstance();
-
-$procedureLoaderFactory = $serviceContainer->get('procedure_loader_factory');
-$procedureLoader        = $procedureLoaderFactory->createProcedureLoader($filePath); // Set the path to your custom procedure(s)
-
-$client = Client::getInstance();
-$client->getProcedureLoader()->addLoader($procedureLoader); // Add new loader with path to you procedures to the chain loader
-
-$request  = $client->getMessageFactory()->createRequest();
-$response = $client->getMessageFactory()->createResponse();
-
-$request->setType($fileName); // Set the request type to the name of your procedure you want to execute for this request
-
-$client->send($request, $response);
-
-var_dump($response);
-
-// If your debug log contains 'SyntaxError: Parse error'
-// then your custom procedure has a javascript error. Try 
-// setting $client->debug(true) before making your request
-// to get more information about your error.
-var_dump($client->getLog());

+ 0 - 21
examples/debug-request.php

@@ -1,21 +0,0 @@
-<?php
-
-require '../vendor/autoload.php';
-
-use JonnyW\PhantomJs\Client;
-
-$client = Client::getInstance();
-$client->debug(true); // Set debug flag
-
-$request  = $client->getMessageFactory()->createRequest();
-$response = $client->getMessageFactory()->createResponse();
-
-$request->setMethod('GET');
-$request->setUrl('http://google.com');
-
-$client->send($request, $response);
-
-// The PhantomJS executable log. Will contain 
-// any script parse errors, script info and 
-// anything else PhantomJS outputs in debug mode.
-var_dump($client->getLog()); 

+ 0 - 28
examples/delay-page-render.php

@@ -1,28 +0,0 @@
-<?php
-
-require '../vendor/autoload.php';
-
-use JonnyW\PhantomJs\Client;
-
-$client = Client::getInstance();
-
-$request  = $client->getMessageFactory()->createCaptureRequest();
-$response = $client->getMessageFactory()->createResponse();
-
-$delay = 5; // Seconds
-
-$request->setMethod('GET');
-$request->setUrl('http://google.com');
-$request->setCaptureFile(sprintf('%s/file.jpg', sys_get_temp_dir()));
-$request->setDelay($delay);
-
-$client->send($request, $response);
-
-var_dump($response);
-
-// A debug info notice will be written to
-// the log when the page render delay starts 
-// and when the page render executes. This is 
-// useful for debugging page render delay and 
-// will always be present, even if debug is disabled.
-var_dump($client->getLog());

+ 0 - 21
examples/javascript-console.php

@@ -1,21 +0,0 @@
-<?php
-
-require '../vendor/autoload.php';
-
-use JonnyW\PhantomJs\Client;
-
-$client = Client::getInstance();
-
-$request  = $client->getMessageFactory()->createRequest();
-$response = $client->getMessageFactory()->createResponse();
-
-$request->setMethod('GET');
-$request->setUrl('http://google.com');
-
-$client->send($request, $response);
-
-// Any javascript errors that show up in 
-// the browser console will appear in 
-// response console data along with stack 
-// trace. console.log() data will not be present.
-var_dump($response->getConsole()); 

+ 0 - 23
examples/post-request.php

@@ -1,23 +0,0 @@
-<?php
-
-require '../vendor/autoload.php';
-
-use JonnyW\PhantomJs\Client;
-
-$client = Client::getInstance();
-
-$request  = $client->getMessageFactory()->createRequest();
-$response = $client->getMessageFactory()->createResponse();
-
-$data = array(
-    'param1' => 'Param 1',
-    'param2' => 'Param 2'
-);
-
-$request->setMethod('POST');
-$request->setUrl('http://google.com');
-$request->setRequestData($data); // Set post data
-
-$client->send($request, $response);
-
-var_dump($response);