Jonny Wenmoth 9 лет назад
Родитель
Сommit
c6890e8b65
100 измененных файлов с 2002 добавлено и 1911 удалено
  1. 1 0
      .gitignore
  2. 5 0
      .travis.yml
  3. 1 1
      LICENSE
  4. 10 13
      composer.json
  5. 10 13
      src/Cache/CacheInterface.php
  6. 28 30
      src/Cache/FileCache.php
  7. 45 95
      src/Client.php
  8. 22 38
      src/ClientInterface.php
  9. 6 11
      src/DependencyInjection/ServiceContainer.php
  10. 26 35
      src/Engine.php
  11. 2 2
      src/Exception/InvalidExecutableException.php
  12. 2 2
      src/Exception/InvalidMethodException.php
  13. 2 2
      src/Exception/InvalidUrlException.php
  14. 2 2
      src/Exception/NotExistsException.php
  15. 2 2
      src/Exception/NotWritableException.php
  16. 2 2
      src/Exception/PhantomJsException.php
  17. 2 2
      src/Exception/ProcedureFailedException.php
  18. 2 2
      src/Exception/RequirementException.php
  19. 4 7
      src/Exception/SyntaxException.php
  20. 34 0
      src/Http/Request.php
  21. 33 0
      src/Http/Response.php
  22. 33 0
      src/Http/StreamResponse.php
  23. 93 119
      src/HttpOLD/AbstractRequest.php
  24. 1 2
      src/HttpOLD/CaptureRequest.php
  25. 0 0
      src/HttpOLD/CaptureRequestInterface.php
  26. 20 21
      src/HttpOLD/MessageFactory.php
  27. 14 15
      src/HttpOLD/MessageFactoryInterface.php
  28. 34 67
      src/HttpOLD/PdfRequest.php
  29. 12 35
      src/HttpOLD/PdfRequestInterface.php
  30. 6 8
      src/HttpOLD/Request.php
  31. 30 53
      src/HttpOLD/RequestInterface.php
  32. 31 50
      src/HttpOLD/Response.php
  33. 15 25
      src/HttpOLD/ResponseInterface.php
  34. 148 0
      src/IO/InputInterface.php
  35. 242 0
      src/IO/InputTrait.php
  36. 147 0
      src/IO/OutputInterface.php
  37. 226 0
      src/IO/OutputTrait.php
  38. 41 0
      src/IO/StreamInput.php
  39. 41 0
      src/IO/StreamOutput.php
  40. 0 68
      src/JonnyW/PhantomJs/Procedure/Input.php
  41. 0 20
      src/JonnyW/PhantomJs/Procedure/InputInterface.php
  42. 0 110
      src/JonnyW/PhantomJs/Procedure/Output.php
  43. 0 26
      src/JonnyW/PhantomJs/Procedure/OutputInterface.php
  44. 0 21
      src/JonnyW/PhantomJs/Resources/procedures/page_clip_rect.partial
  45. 0 3
      src/JonnyW/PhantomJs/Resources/procedures/page_custom_headers.partial
  46. 0 16
      src/JonnyW/PhantomJs/Resources/procedures/page_open.partial
  47. 0 49
      src/JonnyW/PhantomJs/Resources/procedures/page_paper_size.partial
  48. 0 14
      src/JonnyW/PhantomJs/Resources/procedures/page_viewport_size.partial
  49. 0 27
      src/JonnyW/PhantomJs/Resources/procedures/procedure_capture.partial
  50. 0 25
      src/JonnyW/PhantomJs/Resources/procedures/procedure_pdf.partial
  51. 4 3
      src/Parser/JsonParser.php
  52. 2 2
      src/Parser/ParserInterface.php
  53. 16 23
      src/Procedure/ChainProcedureLoader.php
  54. 23 34
      src/Procedure/Procedure.php
  55. 24 39
      src/Procedure/ProcedureCompiler.php
  56. 9 15
      src/Procedure/ProcedureCompilerInterface.php
  57. 5 11
      src/Procedure/ProcedureFactory.php
  58. 1 2
      src/Procedure/ProcedureFactoryInterface.php
  59. 6 8
      src/Procedure/ProcedureInterface.php
  60. 11 12
      src/Procedure/ProcedureLoader.php
  61. 7 8
      src/Procedure/ProcedureLoaderFactory.php
  62. 3 3
      src/Procedure/ProcedureLoaderFactoryInterface.php
  63. 7 6
      src/Procedure/ProcedureLoaderInterface.php
  64. 13 16
      src/Procedure/ProcedureValidator.php
  65. 6 4
      src/Procedure/ProcedureValidatorInterface.php
  66. 0 0
      src/Resources/config/config.yml
  67. 1 0
      src/Resources/config/services.yml
  68. 0 0
      src/Resources/procedures/global_variables.partial
  69. 41 24
      src/Resources/procedures/http_default.proc
  70. 1 1
      src/Resources/procedures/page_body_styles.partial
  71. 9 0
      src/Resources/procedures/page_clip_rect.partial
  72. 5 6
      src/Resources/procedures/page_cookies.partial
  73. 3 0
      src/Resources/procedures/page_custom_headers.partial
  74. 0 0
      src/Resources/procedures/page_on_error.partial
  75. 1 1
      src/Resources/procedures/page_on_resource_received.partial
  76. 0 0
      src/Resources/procedures/page_on_resource_requested.partial
  77. 0 0
      src/Resources/procedures/page_on_resource_timeout.partial
  78. 2 0
      src/Resources/procedures/page_open.partial
  79. 37 0
      src/Resources/procedures/page_paper_size.partial
  80. 1 1
      src/Resources/procedures/page_settings.partial
  81. 9 0
      src/Resources/procedures/page_viewport_size.partial
  82. 9 0
      src/Resources/procedures/page_zoom_factor.partial
  83. 1 1
      src/Resources/procedures/phantom_on_error.partial
  84. 1 1
      src/Resources/procedures/procedure_http.partial
  85. 25 0
      src/Resources/procedures/procedure_stream.partial
  86. 55 8
      src/Resources/procedures/stream_default.proc
  87. 2 2
      src/Resources/procedures/validator.proc
  88. 0 0
      src/Resources/validators/esprima-2.0.0.js
  89. 6 4
      src/StringUtils.php
  90. 5 6
      src/Template/TemplateRenderer.php
  91. 5 4
      src/Template/TemplateRendererInterface.php
  92. 2 2
      src/Test/TestCase.php
  93. 111 228
      src/Tests/Integration/ClientTest.php
  94. 16 43
      src/Tests/Integration/Procedure/ProcedureCompilerTest.php
  95. 17 36
      src/Tests/Integration/Procedure/ProcedureValidatorTest.php
  96. 27 66
      src/Tests/Unit/Cache/FileCacheTest.php
  97. 32 44
      src/Tests/Unit/ClientTest.php
  98. 11 50
      src/Tests/Unit/EngineTest.php
  99. 44 122
      src/Tests/Unit/Http/CaptureRequestTest.php
  100. 11 42
      src/Tests/Unit/Http/MessageFactoryTest.php

+ 1 - 0
.gitignore

@@ -1,4 +1,5 @@
 .DS_Store
+.php_cs.cache
 composer.phar
 composer.lock
 vendor/

+ 5 - 0
.travis.yml

@@ -10,6 +10,11 @@ php:
   - 5.5
   - 5.6
 
+branches:
+  only:
+  - master
+  - stable
+
 before_script:
   - composer self-update
   - composer install

+ 1 - 1
LICENSE

@@ -1,7 +1,7 @@
 The MIT License
 ===============
 
-Copyright (c) 2013 Jonny Wenmoth
+Copyright (c) 2016 Jonny Wenmoth
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal

+ 10 - 13
composer.json

@@ -13,12 +13,13 @@
     ],
     "minimum-stability": "stable",
     "require": {
-        "php": ">=5.3.0",
+        "php": ">=5.6.0",
         "symfony/config": "~2.3|~3.0",
         "symfony/dependency-injection": "~2.3|~3.0",
         "symfony/filesystem": "~2.3|~3.0",
         "symfony/yaml": "~2.3|~3.0",
         "twig/twig": "~1.16",
+        "guzzlehttp/psr7": "~1.3",
         "jakoch/phantomjs-installer": "^2.1"
     },
     "require-dev": {
@@ -27,20 +28,16 @@
         "smalot/pdfparser": "~0.9"
     },
     "autoload": {
-        "psr-0": {
-            "JonnyW\\PhantomJs\\": "src"
-        },
-		"classmap": ["src/"]
+        "psr-4": {
+            "JonnyW\\PhantomJs\\": "src/"
+        }
+    },
+    "autoload-dev": {
+        "psr-4": {
+            "Tests\\JonnyW\\PhantomJS\\": "tests/"
+        }
     },
     "config": {
         "bin-dir": "bin"
-    },
-    "scripts": {
-        "post-install-cmd": [
-            "PhantomInstaller\\Installer::installPhantomJS"
-        ],
-        "post-update-cmd": [
-            "PhantomInstaller\\Installer::installPhantomJS"
-        ]
     }
 }

+ 10 - 13
src/JonnyW/PhantomJs/Cache/CacheInterface.php → src/Cache/CacheInterface.php

@@ -6,10 +6,11 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Cache;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -18,9 +19,9 @@ interface CacheInterface
     /**
      * Write data to storage.
      *
-     * @access public
-     * @param  string $id
-     * @param  string $data
+     * @param string $id
+     * @param string $data
+     *
      * @return string
      */
     public function save($id, $data);
@@ -28,27 +29,23 @@ interface CacheInterface
     /**
      * Fetch data from file.
      *
-     * @access public
-     * @param  string $id
-     * @return void
+     * @param string $id
      */
     public function fetch($id);
 
     /**
      * Delete data from storage.
      *
-     * @access public
-     * @param  string $id
-     * @return void
+     * @param string $id
      */
     public function delete($id);
 
     /**
      * Data exists in storage.
      *
-     * @access public
-     * @param  string  $id
-     * @return boolean
+     * @param string $id
+     *
+     * @return bool
      */
     public function exists($id);
 }

+ 28 - 30
src/JonnyW/PhantomJs/Cache/FileCache.php → src/Cache/FileCache.php

@@ -6,6 +6,7 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Cache;
 
 use JonnyW\PhantomJs\StringUtils;
@@ -13,32 +14,29 @@ use JonnyW\PhantomJs\Exception\NotWritableException;
 use JonnyW\PhantomJs\Exception\NotExistsException;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class FileCache implements CacheInterface
 {
     /**
-     * Default write directory
+     * Default write directory.
      *
      * @var string
-     * @access protected
      */
     protected $directory;
 
     /**
-     * Default write extension
+     * Default write extension.
      *
      * @var string
-     * @access protected
      */
     protected $extension;
 
     /**
      * Internal constructor.
      *
-     * @access public
      * @param string $directory
      * @param string $extension
      */
@@ -51,10 +49,11 @@ class FileCache implements CacheInterface
     /**
      * Write data to storage.
      *
-     * @access public
-     * @param  string                                           $id
-     * @param  string                                           $data
+     * @param string $id
+     * @param string $data
+     *
      * @return string
+     *
      * @throws \JonnyW\PhantomJs\Exception\NotWritableException
      */
     public function save($id, $data)
@@ -66,7 +65,6 @@ class FileCache implements CacheInterface
         }
 
         if ($this->writeData($file, $data) === false) {
-
             $this->delete($file);
 
             throw new NotWritableException(sprintf('Data could not be written to file on system. Please make sure that file is writeable: %s', $file));
@@ -78,9 +76,10 @@ class FileCache implements CacheInterface
     /**
      * Fetch data from file.
      *
-     * @access public
-     * @param  string                                         $id
+     * @param string $id
+     *
      * @return mixed|void
+     *
      * @throws \JonnyW\PhantomJs\Exception\NotExistsException
      */
     public function fetch($id)
@@ -97,9 +96,7 @@ class FileCache implements CacheInterface
     /**
      * Delete data from storage.
      *
-     * @access public
-     * @param  string $id
-     * @return void
+     * @param string $id
      */
     public function delete($id)
     {
@@ -113,9 +110,9 @@ class FileCache implements CacheInterface
     /**
      * Data exists in storage.
      *
-     * @access public
-     * @param  string  $id
-     * @return boolean
+     * @param string $id
+     *
+     * @return bool
      */
     public function exists($id)
     {
@@ -125,9 +122,9 @@ class FileCache implements CacheInterface
     /**
      * Is data writeable.
      *
-     * @access protected
      * @param $file
-     * @return boolean
+     *
+     * @return bool
      */
     protected function isWritable($file)
     {
@@ -137,10 +134,10 @@ class FileCache implements CacheInterface
     /**
      * Write data to file.
      *
-     * @access protected
-     * @param  string  $file
-     * @param  string  $data
-     * @return boolean
+     * @param string $file
+     * @param string $data
+     *
+     * @return bool
      */
     protected function writeData($file, $data)
     {
@@ -150,8 +147,8 @@ class FileCache implements CacheInterface
     /**
      * Read data from file.
      *
-     * @access protected
-     * @param  string $file
+     * @param string $file
+     *
      * @return mixed
      */
     protected function readData($file)
@@ -160,11 +157,12 @@ class FileCache implements CacheInterface
     }
 
     /**
-     * Get filename
+     * Get filename.
+     *
+     * @param string $id
      *
-     * @access protected
-     * @param  string                                           $id
      * @return string
+     *
      * @throws \JonnyW\PhantomJs\Exception\NotWritableException
      */
     protected function getFileName($id)
@@ -176,7 +174,7 @@ class FileCache implements CacheInterface
         $dirName = dirname($id);
 
         if (!file_exists($id) && $dirName === '.') {
-             return sprintf('%1$s/%2$s', $this->directory, $id);
+            return sprintf('%1$s/%2$s', $this->directory, $id);
         }
 
         if (!file_exists($id) && !is_writable($dirName)) {

+ 45 - 95
src/JonnyW/PhantomJs/Client.php → src/Client.php

@@ -6,17 +6,16 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs;
 
 use JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface;
 use JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface;
-use JonnyW\PhantomJs\Http\MessageFactoryInterface;
-use JonnyW\PhantomJs\Http\RequestInterface;
-use JonnyW\PhantomJs\Http\ResponseInterface;
-use JonnyW\PhantomJs\DependencyInjection\ServiceContainer;
+use JonnyW\PhantomJs\IO\InputInterface;
+use JonnyW\PhantomJs\IO\OutputInterface;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -25,16 +24,14 @@ class Client implements ClientInterface
     /**
      * Client.
      *
-     * @var \JonnyW\PhantomJs\ClientInterface
-     * @access private
+     * @var \JonnyW\PhantomJs\Client\ClientInterface
      */
-    private static $instance;
+    protected static $instance;
 
     /**
      * PhantomJs engine.
      *
      * @var \JonnyW\PhantomJs\Engine
-     * @access protected
      */
     protected $engine;
 
@@ -42,7 +39,6 @@ class Client implements ClientInterface
      * Procedure loader.
      *
      * @var \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface
-     * @access protected
      */
     protected $procedureLoader;
 
@@ -50,62 +46,45 @@ class Client implements ClientInterface
      * Procedure validator.
      *
      * @var \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface
-     * @access protected
      */
     protected $procedureCompiler;
 
     /**
-     * Message factory.
-     *
-     * @var \JonnyW\PhantomJs\Http\MessageFactoryInterface
-     * @access protected
-     */
-    protected $messageFactory;
-
-    /**
-     * Procedure template
+     * Procedure template.
      *
      * @var string
-     * @access protected
      */
     protected $procedure;
 
     /**
-     * Internal constructor
+     * Internal constructor.
      *
-     * @access public
-     * @param  \JonnyW\PhantomJs\Engine                               $engine
-     * @param  \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface   $procedureLoader
-     * @param  \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface $procedureCompiler
-     * @param  \JonnyW\PhantomJs\Http\MessageFactoryInterface         $messageFactory
-     * @return void
+     * @param \JonnyW\PhantomJs\Engine                               $engine
+     * @param \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface   $procedureLoader
+     * @param \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface $procedureCompiler
      */
-    public function __construct(Engine $engine, ProcedureLoaderInterface $procedureLoader, ProcedureCompilerInterface $procedureCompiler, MessageFactoryInterface $messageFactory)
+    public function __construct(Engine $engine, ProcedureLoaderInterface $procedureLoader, ProcedureCompilerInterface $procedureCompiler)
     {
-        $this->engine            = $engine;
-        $this->procedureLoader   = $procedureLoader;
+        $this->engine = $engine;
+        $this->procedureLoader = $procedureLoader;
         $this->procedureCompiler = $procedureCompiler;
-        $this->messageFactory    = $messageFactory;
-        $this->procedure         = 'http_default';
+        $this->procedure = 'default';
     }
 
     /**
-     * Get singleton instance
+     * Get singleton instance.
      *
-     * @access public
-     * @return \JonnyW\PhantomJs\Client
+     * @return \JonnyW\PhantomJs\Client\ClientInterface
      */
     public static function getInstance()
     {
         if (!self::$instance instanceof ClientInterface) {
-
             $serviceContainer = ServiceContainer::getInstance();
 
             self::$instance = new static(
                 $serviceContainer->get('engine'),
                 $serviceContainer->get('procedure_loader'),
-                $serviceContainer->get('procedure_compiler'),
-                $serviceContainer->get('message_factory')
+                $serviceContainer->get('procedure_compiler')
             );
         }
 
@@ -113,31 +92,37 @@ class Client implements ClientInterface
     }
 
     /**
-     * Get PhantomJs engine.
+     * Run client.
      *
-     * @access public
-     * @return \JonnyW\PhantomJs\Engine
+     * @param \JonnyW\PhantomJs\IO\InputInterface  $input
+     * @param \JonnyW\PhantomJs\IO\OutputInterface $output
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
      */
-    public function getEngine()
+    public function run(InputInterface $input, OutputInterface $output)
     {
-        return $this->engine;
+        $procedure = $this->procedureLoader->load($this->procedure);
+
+        $this->procedureCompiler->compile($procedure, $input);
+
+        $procedure->run($input, $output);
+
+        return $output;
     }
 
     /**
-     * Get message factory instance
+     * Get PhantomJs engine.
      *
-     * @access public
-     * @return \JonnyW\PhantomJs\Http\MessageFactoryInterface
+     * @return \JonnyW\PhantomJs\Engine
      */
-    public function getMessageFactory()
+    public function getEngine()
     {
-        return $this->messageFactory;
+        return $this->engine;
     }
 
     /**
-     * Get procedure loader instance
+     * Get procedure loader instance.
      *
-     * @access public
      * @return \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface
      */
     public function getProcedureLoader()
@@ -146,41 +131,19 @@ class Client implements ClientInterface
     }
 
     /**
-     * Send request
-     *
-     * @access public
-     * @param  \JonnyW\PhantomJs\Http\RequestInterface  $request
-     * @param  \JonnyW\PhantomJs\Http\ResponseInterface $response
-     * @return \JonnyW\PhantomJs\Http\ResponseInterface
-     */
-    public function send(RequestInterface $request, ResponseInterface $response)
-    {
-        $procedure = $this->procedureLoader->load($this->procedure);
-
-        $this->procedureCompiler->compile($procedure, $request);
-
-        $procedure->run($request, $response);
-
-        return $response;
-    }
-
-    /**
-     * Get log.
+     * Get procedure compiler.
      *
-     * @access public
-     * @return string
+     * @return \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface
      */
-    public function getLog()
+    public function getProcedureCompiler()
     {
-        return $this->getEngine()->getLog();
+        return $this->procedureCompiler;
     }
 
     /**
      * Set procedure template.
      *
-     * @access public
-     * @param  string $procedure
-     * @return void
+     * @param string $procedure
      */
     public function setProcedure($procedure)
     {
@@ -190,7 +153,6 @@ class Client implements ClientInterface
     /**
      * Get procedure template.
      *
-     * @access public
      * @return string
      */
     public function getProcedure()
@@ -199,24 +161,12 @@ class Client implements ClientInterface
     }
 
     /**
-     * Get procedure compiler.
-     *
-     * @access public
-     * @return \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface
-     */
-    public function getProcedureCompiler()
-    {
-        return $this->procedureCompiler;
-    }
-
-    /**
-     * Set lazy request flag.
+     * Get log.
      *
-     * @access public
-     * @return void
+     * @return string
      */
-    public function isLazy()
+    public function getLog()
     {
-        $this->procedure = 'http_lazy';
+        return $this->getEngine()->getLog();
     }
 }

+ 22 - 38
src/JonnyW/PhantomJs/ClientInterface.php → src/ClientInterface.php

@@ -6,89 +6,73 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs;
 
-use JonnyW\PhantomJs\Http\RequestInterface;
-use JonnyW\PhantomJs\Http\ResponseInterface;
+use JonnyW\PhantomJs\IO\InputInterface;
+use JonnyW\PhantomJs\IO\OutputInterface;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 interface ClientInterface
 {
     /**
-     * Get singleton instance
+     * Get singleton instance.
      *
-     * @access public
-     * @return \JonnyW\PhantomJs\ClientInterface
+     * @return \JonnyW\PhantomJs\Client\ClientInterface
      */
     public static function getInstance();
 
     /**
      * Get engine instance.
      *
-     * @access public
      * @return \JonnyW\PhantomJs\Engine
      */
     public function getEngine();
 
     /**
-     * Get message factory instance
-     *
-     * @access public
-     * @return \JonnyW\PhantomJs\Http\MessageFactoryInterface
-     */
-    public function getMessageFactory();
-
-    /**
-     * Get procedure loader instance
+     * Get procedure loader instance.
      *
-     * @access public
      * @return \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface
      */
     public function getProcedureLoader();
 
     /**
-     * Send request
+     * Get procedure compiler.
      *
-     * @access public
-     * @param \JonnyW\PhantomJs\Http\RequestInterface  $request
-     * @param \JonnyW\PhantomJs\Http\ResponseInterface $response
+     * @return \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface
      */
-    public function send(RequestInterface $request, ResponseInterface $response);
-
-    /**
-     * Get log.
-     *
-     * @access public
-     * @return string
-     */
-    public function getLog();
+    public function getProcedureCompiler();
 
     /**
      * Set procedure template.
      *
-     * @access public
-     * @param  string $procedure
-     * @return void
+     * @param string $procedure
      */
     public function setProcedure($procedure);
 
     /**
      * Get procedure template.
      *
-     * @access public
      * @return string
      */
     public function getProcedure();
 
     /**
-     * Set lazy request flag.
+     * Run client.
      *
-     * @access public
-     * @return void
+     * @param \JonnyW\PhantomJs\IO\InputInterface  $input
+     * @param \JonnyW\PhantomJs\IO\OutputInterface $output
      */
-    public function isLazy();
+    public function run(InputInterface $input, OutputInterface $output);
+
+    /**
+     * Get log.
+     *
+     * @return string
+     */
+    public function getLog();
 }

+ 6 - 11
src/JonnyW/PhantomJs/DependencyInjection/ServiceContainer.php → src/DependencyInjection/ServiceContainer.php

@@ -6,6 +6,7 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\DependencyInjection;
 
 use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -13,31 +14,28 @@ use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
 use Symfony\Component\Config\FileLocator;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class ServiceContainer extends ContainerBuilder
 {
     /**
-     * Service container instance
+     * Service container instance.
      *
      * @var \JonnyW\PhantomJs\DependencyInjection\ServiceContainer
-     * @access private
      */
     private static $instance;
 
     /**
-     * Get singleton instance
+     * Get singleton instance.
      *
-     * @access public
      * @return \JonnyW\PhantomJs\Client
      */
     public static function getInstance()
     {
-        if (!self::$instance instanceof ServiceContainer) {
-
-            self::$instance = new ServiceContainer();
+        if (!self::$instance instanceof self) {
+            self::$instance = new self();
             self::$instance->load();
         }
 
@@ -46,9 +44,6 @@ class ServiceContainer extends ContainerBuilder
 
     /**
      * Load service container.
-     *
-     * @access public
-     * @return void
      */
     public function load()
     {

+ 26 - 35
src/JonnyW/PhantomJs/Engine.php → src/Engine.php

@@ -6,38 +6,38 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs;
 
 use JonnyW\PhantomJs\Exception\InvalidExecutableException;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class Engine
 {
+    const VERSION = 4;
+
     /**
      * Executable path.
      *
      * @var string
-     * @access protected
      */
     protected $path;
 
     /**
      * Debug flag.
      *
-     * @var boolean
-     * @access protected
+     * @var bool
      */
     protected $debug;
 
     /**
      * Cache flag.
      *
-     * @var boolean
-     * @access protected
+     * @var bool
      */
     protected $cache;
 
@@ -45,27 +45,22 @@ class Engine
      * PhantomJs run options.
      *
      * @var array
-     * @access protected
      */
     protected $options;
 
     /**
-     * Log info
+     * Log info.
      *
      * @var string
-     * @access protected
      */
     protected $log;
 
     /**
-     * Internal constructor
-     *
-     * @access public
-     * @return void
+     * Internal constructor.
      */
     public function __construct()
     {
-        $this->path    = 'bin/phantomjs';
+        $this->path = 'bin/phantomjs';
         $this->options = array();
 
         $this->debug = false;
@@ -76,12 +71,11 @@ class Engine
      * Get PhantomJs run command with
      * loader run options.
      *
-     * @access public
      * @return string
      */
     public function getCommand()
     {
-        $path    = $this->getPath();
+        $path = $this->getPath();
         $options = $this->getOptions();
 
         $this->validateExecutable($path);
@@ -100,8 +94,8 @@ class Engine
     /**
      * Set path.
      *
-     * @access public
-     * @param  string                   $path
+     * @param string $path
+     *
      * @return \JonnyW\PhantomJs\Client
      */
     public function setPath($path)
@@ -116,7 +110,6 @@ class Engine
     /**
      * Get path.
      *
-     * @access public
      * @return string
      */
     public function getPath()
@@ -127,8 +120,8 @@ class Engine
     /**
      * Set PhantomJs run options.
      *
-     * @access public
-     * @param  array                    $options
+     * @param array $options
+     *
      * @return \JonnyW\PhantomJs\Client
      */
     public function setOptions(array $options)
@@ -141,7 +134,6 @@ class Engine
     /**
      * Get PhantomJs run options.
      *
-     * @access public
      * @return array
      */
     public function getOptions()
@@ -152,8 +144,8 @@ class Engine
     /**
      * Add single PhantomJs run option.
      *
-     * @access public
-     * @param  string                   $option
+     * @param string $option
+     *
      * @return \JonnyW\PhantomJs\Client
      */
     public function addOption($option)
@@ -168,8 +160,8 @@ class Engine
     /**
      * Debug.
      *
-     * @access public
-     * @param  boolean                  $doDebug
+     * @param bool $doDebug
+     *
      * @return \JonnyW\PhantomJs\Client
      */
     public function debug($doDebug)
@@ -182,8 +174,8 @@ class Engine
     /**
      * Cache.
      *
-     * @access public
-     * @param  boolean                  $doCache
+     * @param bool $doCache
+     *
      * @return \JonnyW\PhantomJs\Client
      */
     public function cache($doCache)
@@ -196,8 +188,8 @@ class Engine
     /**
      * Log info.
      *
-     * @access public
-     * @param  string                   $info
+     * @param string $info
+     *
      * @return \JonnyW\PhantomJs\Client
      */
     public function log($info)
@@ -210,7 +202,6 @@ class Engine
     /**
      * Get log info.
      *
-     * @access public
      * @return string
      */
     public function getLog()
@@ -221,7 +212,6 @@ class Engine
     /**
      * Clear log info.
      *
-     * @access public
      * @return \JonnyW\PhantomJs\Client
      */
     public function clearLog()
@@ -234,9 +224,10 @@ class Engine
     /**
      * Validate execuable file.
      *
-     * @access private
-     * @param  string                                                 $file
-     * @return boolean
+     * @param string $file
+     *
+     * @return bool
+     *
      * @throws \JonnyW\PhantomJs\Exception\InvalidExecutableException
      */
     private function validateExecutable($file)

+ 2 - 2
src/JonnyW/PhantomJs/Exception/InvalidExecutableException.php → src/Exception/InvalidExecutableException.php

@@ -6,14 +6,14 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Exception;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class InvalidExecutableException extends PhantomJsException
 {
-
 }

+ 2 - 2
src/JonnyW/PhantomJs/Exception/InvalidMethodException.php → src/Exception/InvalidMethodException.php

@@ -6,14 +6,14 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Exception;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class InvalidMethodException extends PhantomJsException
 {
-
 }

+ 2 - 2
src/JonnyW/PhantomJs/Exception/InvalidUrlException.php → src/Exception/InvalidUrlException.php

@@ -6,14 +6,14 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Exception;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class InvalidUrlException extends PhantomJsException
 {
-
 }

+ 2 - 2
src/JonnyW/PhantomJs/Exception/NotExistsException.php → src/Exception/NotExistsException.php

@@ -6,14 +6,14 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Exception;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class NotExistsException extends PhantomJsException
 {
-
 }

+ 2 - 2
src/JonnyW/PhantomJs/Exception/NotWritableException.php → src/Exception/NotWritableException.php

@@ -6,14 +6,14 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Exception;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class NotWritableException extends PhantomJsException
 {
-
 }

+ 2 - 2
src/JonnyW/PhantomJs/Exception/PhantomJsException.php → src/Exception/PhantomJsException.php

@@ -6,14 +6,14 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Exception;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class PhantomJsException extends \Exception
 {
-
 }

+ 2 - 2
src/JonnyW/PhantomJs/Exception/ProcedureFailedException.php → src/Exception/ProcedureFailedException.php

@@ -6,14 +6,14 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Exception;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class ProcedureFailedException extends PhantomJsException
 {
-
 }

+ 2 - 2
src/JonnyW/PhantomJs/Exception/RequirementException.php → src/Exception/RequirementException.php

@@ -6,14 +6,14 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Exception;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class RequirementException extends PhantomJsException
 {
-
 }

+ 4 - 7
src/JonnyW/PhantomJs/Exception/SyntaxException.php → src/Exception/SyntaxException.php

@@ -6,10 +6,11 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Exception;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -19,17 +20,14 @@ class SyntaxException extends PhantomJsException
      * Error storage.
      *
      * @var array
-     * @access protected
      */
     protected $errors;
 
     /**
      * Internal constructor.
      *
-     * @access public
-     * @param  string $exception
-     * @param  array  $errors    (default: array())
-     * @return void
+     * @param string $exception
+     * @param array  $errors    (default: array())
      */
     public function __construct($exception, array $errors = array())
     {
@@ -41,7 +39,6 @@ class SyntaxException extends PhantomJsException
     /**
      * Get errors.
      *
-     * @access public
      * @return array
      */
     public function getErrors()

+ 34 - 0
src/Http/Request.php

@@ -0,0 +1,34 @@
+<?php
+
+/*
+ * This file is part of the php-phantomjs.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace JonnyW\PhantomJs\Http;
+
+use GuzzleHttp\Psr7\Request as BaseRequest;
+use JonnyW\PhantomJs\IO\Input\InputInterface;
+
+/**
+ * PHP PhantomJs.
+ *
+ * @author Jon Wenmoth <contact@jonnyw.me>
+ */
+class Request extends BaseRequest implements InputInterface
+{
+    use \GuzzleHttp\Psr7\MessageTrait;
+    use \JonnyW\PhantomJs\IO\Input\InputTrait;
+
+    /**
+     * Get input type.
+     *
+     * @return string
+     */
+    public function getType()
+    {
+        return 'http';
+    }
+}

+ 33 - 0
src/Http/Response.php

@@ -0,0 +1,33 @@
+<?php
+
+/*
+ * This file is part of the php-phantomjs.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace JonnyW\PhantomJs\Http;
+
+use GuzzleHttp\Psr7\Response as BaseResponse;
+
+/**
+ * PHP PhantomJs.
+ *
+ * @author Jon Wenmoth <contact@jonnyw.me>
+ */
+class Response extends BaseResponse implements OutputInterface
+{
+    use \GuzzleHttp\Psr7\MessageTrait;
+    use \JonnyW\PhantomJs\IO\Output\OutputTrait;
+
+    /**
+     * Get input type.
+     *
+     * @return string
+     */
+    public function getType()
+    {
+        return 'http';
+    }
+}

+ 33 - 0
src/Http/StreamResponse.php

@@ -0,0 +1,33 @@
+<?php
+
+/*
+ * This file is part of the php-phantomjs.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace JonnyW\PhantomJs\Http;
+
+use GuzzleHttp\Psr7\Response as BaseResponse;
+
+/**
+ * PHP PhantomJs.
+ *
+ * @author Jon Wenmoth <contact@jonnyw.me>
+ */
+class StreamResponse extends BaseResponse implements OutputInterface
+{
+    use \GuzzleHttp\Psr7\MessageTrait;
+    use \JonnyW\PhantomJs\IO\Output\OutputTrait;
+
+    /**
+     * Get input type.
+     *
+     * @return string
+     */
+    public function getType()
+    {
+        return 'http_stream';
+    }
+}

+ 93 - 119
src/JonnyW/PhantomJs/Http/AbstractRequest.php → src/HttpOLD/AbstractRequest.php

@@ -13,66 +13,58 @@ use JonnyW\PhantomJs\Exception\InvalidMethodException;
 use JonnyW\PhantomJs\Procedure\InputInterface;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
-abstract class AbstractRequest
-    implements RequestInterface, InputInterface
+abstract class AbstractRequest implements RequestInterface, InputInterface
 {
     /**
-     * Headers
+     * Headers.
      *
      * @var array
-     * @access protected
      */
     protected $headers;
 
     /**
-     * Settings
+     * Settings.
      *
      * @var array
-     * @access protected
      */
     protected $settings;
 
     /**
-     * Cookies
+     * Cookies.
      *
      * @var array
-     * @access protected
      */
     protected $cookies;
 
     /**
-     * Request data
+     * Request data.
      *
      * @var array
-     * @access protected
      */
     protected $data;
 
     /**
-     * Request URL
+     * Request URL.
      *
      * @var string
-     * @access protected
      */
     protected $url;
 
     /**
-     * Request method
+     * Request method.
      *
      * @var string
-     * @access protected
      */
     protected $method;
 
     /**
-     * Timeout period
+     * Timeout period.
      *
      * @var int
-     * @access protected
      */
     protected $timeout;
 
@@ -80,7 +72,6 @@ abstract class AbstractRequest
      * Page load delay time.
      *
      * @var int
-     * @access protected
      */
     protected $delay;
 
@@ -88,7 +79,6 @@ abstract class AbstractRequest
      * Viewport width.
      *
      * @var int
-     * @access protected
      */
     protected $viewportWidth;
 
@@ -96,7 +86,6 @@ abstract class AbstractRequest
      * Viewport height.
      *
      * @var int
-     * @access protected
      */
     protected $viewportHeight;
 
@@ -104,31 +93,29 @@ abstract class AbstractRequest
      * Body styles.
      *
      * @var array
-     * @access protected
      */
     protected $bodyStyles;
 
     /**
-     * Internal constructor
+     * Internal constructor.
      *
-     * @access public
      * @param string $url     (default: null)
      * @param string $method  (default: RequestInterface::METHOD_GET)
      * @param int    $timeout (default: 5000)
      */
     public function __construct($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000)
     {
-        $this->headers         = array();
-        $this->data            = array();
-        $this->bodyStyles      = array();
-        $this->settings        = array();
-        $this->delay           = 0;
-        $this->viewportWidth   = 0;
-        $this->viewportHeight  = 0;
+        $this->headers = array();
+        $this->data = array();
+        $this->bodyStyles = array();
+        $this->settings = array();
+        $this->delay = 0;
+        $this->viewportWidth = 0;
+        $this->viewportHeight = 0;
 
         $this->cookies = array(
-            'add'    => array(),
-            'delete' => array()
+            'add' => array(),
+            'delete' => array(),
         );
 
         $this->setMethod($method);
@@ -140,19 +127,20 @@ abstract class AbstractRequest
     }
 
     /**
-     * Set request method
+     * Set request method.
+     *
+     * @param string $method
      *
-     * @access public
-     * @param  string                                             $method
      * @return \JonnyW\PhantomJs\Http\AbstractRequest
+     *
      * @throws \JonnyW\PhantomJs\Exception\InvalidMethodException
      */
     public function setMethod($method)
     {
-        $method     = strtoupper($method);
+        $method = strtoupper($method);
         $reflection = new \ReflectionClass('\JonnyW\PhantomJs\Http\RequestInterface');
 
-        if (!$reflection->hasConstant('METHOD_' . $method)) {
+        if (!$reflection->hasConstant('METHOD_'.$method)) {
             throw new InvalidMethodException(sprintf('Invalid method provided: %s', $method));
         }
 
@@ -162,9 +150,8 @@ abstract class AbstractRequest
     }
 
     /**
-     * Get request method
+     * Get request method.
      *
-     * @access public
      * @return string
      */
     public function getMethod()
@@ -173,10 +160,10 @@ abstract class AbstractRequest
     }
 
     /**
-     * Set timeout period
+     * Set timeout period.
+     *
+     * @param int $timeout
      *
-     * @access public
-     * @param  int                                    $timeout
      * @return \JonnyW\PhantomJs\Http\AbstractRequest
      */
     public function setTimeout($timeout)
@@ -187,9 +174,8 @@ abstract class AbstractRequest
     }
 
     /**
-     * Get timeout period
+     * Get timeout period.
      *
-     * @access public
      * @return int
      */
     public function getTimeout()
@@ -204,8 +190,8 @@ abstract class AbstractRequest
     /**
      * Set page load delay time (seconds).
      *
-     * @access public
-     * @param  int                                    $delay
+     * @param int $delay
+     *
      * @return \JonnyW\PhantomJs\Http\AbstractRequest
      */
     public function setDelay($delay)
@@ -218,7 +204,6 @@ abstract class AbstractRequest
     /**
      * Get page load delay time (seconds).
      *
-     * @access public
      * @return int
      */
     public function getDelay()
@@ -229,14 +214,12 @@ abstract class AbstractRequest
     /**
      * Set viewport size.
      *
-     * @access public
-     * @param  int  $width
-     * @param  int  $height
-     * @return void
+     * @param int $width
+     * @param int $height
      */
     public function setViewportSize($width, $height)
     {
-        $this->viewportWidth  = (int) $width;
+        $this->viewportWidth = (int) $width;
         $this->viewportHeight = (int) $height;
 
         return $this;
@@ -245,7 +228,6 @@ abstract class AbstractRequest
     /**
      * Get viewport width.
      *
-     * @access public
      * @return int
      */
     public function getViewportWidth()
@@ -256,7 +238,6 @@ abstract class AbstractRequest
     /**
      * Get viewport height.
      *
-     * @access public
      * @return int
      */
     public function getViewportHeight()
@@ -265,10 +246,10 @@ abstract class AbstractRequest
     }
 
     /**
-     * Set request URL
+     * Set request URL.
+     *
+     * @param string $url
      *
-     * @access public
-     * @param  string                                 $url
      * @return \JonnyW\PhantomJs\Http\AbstractRequest
      */
     public function setUrl($url)
@@ -281,9 +262,8 @@ abstract class AbstractRequest
     /**
      * Get request URL
      *  - Assembles query string for GET
-     *  and HEAD requests
+     *  and HEAD requests.
      *
-     * @access public
      * @return string
      */
     public function getUrl()
@@ -295,7 +275,6 @@ abstract class AbstractRequest
         $url = $this->url;
 
         if (count($this->data)) {
-
             $url .= false === strpos($url, '?') ? '?' : '&';
             $url .= http_build_query($this->data);
         }
@@ -305,9 +284,8 @@ abstract class AbstractRequest
 
     /**
      * Get content body
-     *  - Returns query string if not GET or HEAD
+     *  - Returns query string if not GET or HEAD.
      *
-     * @access public
      * @return string
      */
     public function getBody()
@@ -320,10 +298,10 @@ abstract class AbstractRequest
     }
 
     /**
-     * Set request data
+     * Set request data.
+     *
+     * @param array $data
      *
-     * @access public
-     * @param  array                                  $data
      * @return \JonnyW\PhantomJs\Http\AbstractRequest
      */
     public function setRequestData(array $data)
@@ -334,10 +312,10 @@ abstract class AbstractRequest
     }
 
     /**
-     * Get request data
+     * Get request data.
+     *
+     * @param bool $flat
      *
-     * @access public
-     * @param  boolean $flat
      * @return array
      */
     public function getRequestData($flat = true)
@@ -350,10 +328,10 @@ abstract class AbstractRequest
     }
 
     /**
-     * Set headers
+     * Set headers.
+     *
+     * @param array $headers
      *
-     * @access public
-     * @param  array                                  $headers
      * @return \JonnyW\PhantomJs\Http\AbstractRequest
      */
     public function setHeaders(array $headers)
@@ -362,11 +340,11 @@ abstract class AbstractRequest
     }
 
     /**
-     * Add single header
+     * Add single header.
+     *
+     * @param string $header
+     * @param string $value
      *
-     * @access public
-     * @param  string                                 $header
-     * @param  string                                 $value
      * @return \JonnyW\PhantomJs\Http\AbstractRequest
      */
     public function addHeader($header, $value)
@@ -377,10 +355,10 @@ abstract class AbstractRequest
     }
 
     /**
-     * Merge headers with existing
+     * Merge headers with existing.
+     *
+     * @param array $headers
      *
-     * @access public
-     * @param  array                                  $headers
      * @return \JonnyW\PhantomJs\Http\AbstractRequest
      */
     public function addHeaders(array $headers)
@@ -391,10 +369,10 @@ abstract class AbstractRequest
     }
 
     /**
-     * Get request headers
+     * Get request headers.
+     *
+     * @param string $format
      *
-     * @access public
-     * @param  string       $format
      * @return array|string
      */
     public function getHeaders($format = 'default')
@@ -407,11 +385,11 @@ abstract class AbstractRequest
     }
 
     /**
-     * Add single setting
+     * Add single setting.
+     *
+     * @param string $setting
+     * @param string $value
      *
-     * @access public
-     * @param  string                                 $setting
-     * @param  string                                 $value
      * @return \JonnyW\PhantomJs\Http\AbstractRequest
      */
     public function addSetting($setting, $value)
@@ -422,9 +400,8 @@ abstract class AbstractRequest
     }
 
     /**
-     * Get settings
+     * Get settings.
      *
-     * @access public
      * @return array
      */
     public function getSettings()
@@ -435,14 +412,14 @@ abstract class AbstractRequest
     /**
      * Add cookie.
      *
-     * @access public
-     * @param  string                                 $name
-     * @param  mixed                                  $value
-     * @param  string                                 $path
-     * @param  string                                 $domain
-     * @param  bool                                   $httpOnly (default: true)
-     * @param  bool                                   $secure   (default: false)
-     * @param  int                                    $expires  (default: null)
+     * @param string $name
+     * @param mixed  $value
+     * @param string $path
+     * @param string $domain
+     * @param bool   $httpOnly (default: true)
+     * @param bool   $secure   (default: false)
+     * @param int    $expires  (default: null)
+     *
      * @return \JonnyW\PhantomJs\Http\AbstractRequest
      */
     public function addCookie($name, $value, $path, $domain, $httpOnly = true, $secure = false, $expires = null)
@@ -452,13 +429,13 @@ abstract class AbstractRequest
         };
 
         $this->cookies['add'][] = array_filter(array(
-            'name'     => $name,
-            'value'    => $value,
-            'path'     => $path,
-            'domain'   => $domain,
+            'name' => $name,
+            'value' => $value,
+            'path' => $path,
+            'domain' => $domain,
             'httponly' => $httpOnly,
-            'secure'   => $secure,
-            'expires'  => $expires
+            'secure' => $secure,
+            'expires' => $expires,
         ), $filter);
 
         return $this;
@@ -467,8 +444,8 @@ abstract class AbstractRequest
     /**
      * Delete cookie.
      *
-     * @access public
-     * @param  string                                 $name
+     * @param string $name
+     *
      * @return \JonnyW\PhantomJs\Http\AbstractRequest
      */
     public function deleteCookie($name)
@@ -479,9 +456,8 @@ abstract class AbstractRequest
     }
 
     /**
-     * Get cookies
+     * Get cookies.
      *
-     * @access public
      * @return array
      */
     public function getCookies()
@@ -490,10 +466,10 @@ abstract class AbstractRequest
     }
 
     /**
-     * Set body styles
+     * Set body styles.
+     *
+     * @param array $styles
      *
-     * @access public
-     * @param  array                                  $styles
      * @return \JonnyW\PhantomJs\Http\AbstractRequest
      */
     public function setBodyStyles(array $styles)
@@ -504,10 +480,10 @@ abstract class AbstractRequest
     }
 
     /**
-     * Get body styles
+     * Get body styles.
+     *
+     * @param string $format (default: 'default')
      *
-     * @access public
-     * @param  string       $format (default: 'default')
      * @return array|string
      */
     public function getBodyStyles($format = 'default')
@@ -521,12 +497,12 @@ abstract class AbstractRequest
 
     /**
      * Flatten data into single
-     * dimensional array
+     * dimensional array.
+     *
+     * @param array  $data
+     * @param string $prefix
+     * @param string $format
      *
-     * @access protected
-     * @param  array  $data
-     * @param  string $prefix
-     * @param  string $format
      * @return array
      */
     protected function flattenData(array $data, $prefix = '', $format = '%s')
@@ -534,11 +510,9 @@ abstract class AbstractRequest
         $flat = array();
 
         foreach ($data as $name => $value) {
-
-            $ref = $prefix . sprintf($format, $name);
+            $ref = $prefix.sprintf($format, $name);
 
             if (is_array($value)) {
-
                 $flat += $this->flattenData($value, $ref, '[%s]');
                 continue;
             }

+ 1 - 2
src/JonnyW/PhantomJs/Http/CaptureRequest.php → src/HttpOLD/CaptureRequest.php

@@ -16,8 +16,7 @@ use JonnyW\PhantomJs\Exception\NotWritableException;
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
-class CaptureRequest extends AbstractRequest
-    implements CaptureRequestInterface
+class CaptureRequest extends AbstractRequest implements CaptureRequestInterface
 {
     /**
      * Request type.

+ 0 - 0
src/JonnyW/PhantomJs/Http/CaptureRequestInterface.php → src/HttpOLD/CaptureRequestInterface.php


+ 20 - 21
src/JonnyW/PhantomJs/Http/MessageFactory.php → src/HttpOLD/MessageFactory.php

@@ -6,33 +6,33 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Http;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class MessageFactory implements MessageFactoryInterface
 {
     /**
-     * Client instance
-     *
-     * @var \JonnyW\PhantomJs\Http\MessageFactory
-     * @access private
+     * Internal constructor.
      */
-    private static $instance;
+    public function __construct()
+    {
+        @trigger_error(__CLASS__.' is deprecated since version 4.6 and will be removed in 5.0.', E_USER_DEPRECATED);
+    }
 
     /**
      * Get singleton instance.
      *
-     * @access public
      * @return \JonnyW\PhantomJs\Http\MessageFactory
      */
     public static function getInstance()
     {
         if (!self::$instance instanceof MessageFactoryInterface) {
-            self::$instance = new MessageFactory();
+            self::$instance = new self();
         }
 
         return self::$instance;
@@ -41,10 +41,10 @@ class MessageFactory implements MessageFactoryInterface
     /**
      * Create request instance.
      *
-     * @access public
-     * @param  string                         $url
-     * @param  string                         $method
-     * @param  int                            $timeout
+     * @param string $url
+     * @param string $method
+     * @param int    $timeout
+     *
      * @return \JonnyW\PhantomJs\Http\Request
      */
     public function createRequest($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000)
@@ -55,10 +55,10 @@ class MessageFactory implements MessageFactoryInterface
     /**
      * Create capture request instance.
      *
-     * @access public
-     * @param  string                                $url
-     * @param  string                                $method
-     * @param  int                                   $timeout
+     * @param string $url
+     * @param string $method
+     * @param int    $timeout
+     *
      * @return \JonnyW\PhantomJs\Http\CaptureRequest
      */
     public function createCaptureRequest($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000)
@@ -69,10 +69,10 @@ class MessageFactory implements MessageFactoryInterface
     /**
      * Create PDF request instance.
      *
-     * @access public
-     * @param  string                            $url
-     * @param  string                            $method
-     * @param  int                               $timeout
+     * @param string $url
+     * @param string $method
+     * @param int    $timeout
+     *
      * @return \JonnyW\PhantomJs\Http\PdfRequest
      */
     public function createPdfRequest($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000)
@@ -83,7 +83,6 @@ class MessageFactory implements MessageFactoryInterface
     /**
      * Create response instance.
      *
-     * @access public
      * @return \JonnyW\PhantomJs\Http\Response
      */
     public function createResponse()

+ 14 - 15
src/JonnyW/PhantomJs/Http/MessageFactoryInterface.php → src/HttpOLD/MessageFactoryInterface.php

@@ -6,10 +6,11 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Http;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -18,7 +19,6 @@ interface MessageFactoryInterface
     /**
      * Get singleton instance.
      *
-     * @access public
      * @return \JonnyW\PhantomJs\Http\MessageFactoryInterface
      */
     public static function getInstance();
@@ -26,10 +26,10 @@ interface MessageFactoryInterface
     /**
      * Create request instance.
      *
-     * @access public
-     * @param  string                                  $url     (default: null)
-     * @param  string                                  $method  (default: RequestInterface::METHOD_GET)
-     * @param  int                                     $timeout (default: 5000)
+     * @param string $url     (default: null)
+     * @param string $method  (default: RequestInterface::METHOD_GET)
+     * @param int    $timeout (default: 5000)
+     *
      * @return \JonnyW\PhantomJs\Http\RequestInterface
      */
     public function createRequest($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000);
@@ -37,10 +37,10 @@ interface MessageFactoryInterface
     /**
      * Create capture request instance.
      *
-     * @access public
-     * @param  string                                  $url     (default: null)
-     * @param  string                                  $method  (default: RequestInterface::METHOD_GET)
-     * @param  int                                     $timeout (default: 5000)
+     * @param string $url     (default: null)
+     * @param string $method  (default: RequestInterface::METHOD_GET)
+     * @param int    $timeout (default: 5000)
+     *
      * @return \JonnyW\PhantomJs\Http\RequestInterface
      */
     public function createCaptureRequest($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000);
@@ -48,10 +48,10 @@ interface MessageFactoryInterface
     /**
      * Create PDF request instance.
      *
-     * @access public
-     * @param  string                            $url
-     * @param  string                            $method
-     * @param  int                               $timeout
+     * @param string $url
+     * @param string $method
+     * @param int    $timeout
+     *
      * @return \JonnyW\PhantomJs\Http\PdfRequest
      */
     public function createPdfRequest($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000);
@@ -59,7 +59,6 @@ interface MessageFactoryInterface
     /**
      * Create response instance.
      *
-     * @access public
      * @return \JonnyW\PhantomJs\Http\ResponseInterface
      */
     public function createResponse();

+ 34 - 67
src/JonnyW/PhantomJs/Http/PdfRequest.php → src/HttpOLD/PdfRequest.php

@@ -10,96 +10,86 @@
 namespace JonnyW\PhantomJs\Http;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
-class PdfRequest extends CaptureRequest
-    implements PdfRequestInterface
+class PdfRequest extends CaptureRequest implements PdfRequestInterface
 {
     /**
-     * Paper width
+     * Paper width.
      *
      * @var int
-     * @access protected
      */
     protected $paperWidth;
 
     /**
-     * Paper height
+     * Paper height.
      *
      * @var int
-     * @access protected
      */
     protected $paperHeight;
 
     /**
-     * Format
+     * Format.
      *
      * @var string
-     * @access protected
      */
     protected $format;
 
     /**
-     * Orientation
+     * Orientation.
      *
      * @var string
-     * @access protected
      */
     protected $orientation;
 
     /**
-     * Margin
+     * Margin.
      *
      * @var string|array
-     * @access protected
      */
     protected $margin;
 
     /**
-     * Repeating header
+     * Repeating header.
      *
      * @var array
-     * @access protected
      */
     protected $header;
 
     /**
-     * Repeating footer
+     * Repeating footer.
      *
      * @var array
-     * @access protected
      */
     protected $footer;
 
     /**
-     * Internal constructor
+     * Internal constructor.
+     *
+     * @param string $url     (default: null)
+     * @param string $method  (default: RequestInterface::METHOD_GET)
+     * @param int    $timeout (default: 5000)
      *
-     * @access public
-     * @param  string                                $url     (default: null)
-     * @param  string                                $method  (default: RequestInterface::METHOD_GET)
-     * @param  int                                   $timeout (default: 5000)
      * @return \JonnyW\PhantomJs\Http\CaptureRequest
      */
     public function __construct($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000)
     {
         parent::__construct($url, $method, $timeout);
 
-        $this->paperWidth  = '';
+        $this->paperWidth = '';
         $this->paperHeight = '';
-        $this->margin      = '1cm';
-        $this->format      = 'A4';
+        $this->margin = '1cm';
+        $this->format = 'A4';
         $this->orientation = 'portrait';
-        $this->header      = array();
-        $this->footer      = array();
-
+        $this->header = array();
+        $this->footer = array();
     }
 
     /**
-     * Get request type
+     * Get request type.
      *
-     * @access public
      * @return string
      */
     public function getType()
@@ -114,9 +104,7 @@ class PdfRequest extends CaptureRequest
     /**
      * Set paper width.
      *
-     * @access public
-     * @param  string $width
-     * @return void
+     * @param string $width
      */
     public function setPaperWidth($width)
     {
@@ -126,7 +114,6 @@ class PdfRequest extends CaptureRequest
     /**
      * Get paper width.
      *
-     * @access public
      * @return string
      */
     public function getPaperWidth()
@@ -137,9 +124,7 @@ class PdfRequest extends CaptureRequest
     /**
      * Set paper height.
      *
-     * @access public
-     * @param  string $height
-     * @return void
+     * @param string $height
      */
     public function setPaperHeight($height)
     {
@@ -149,7 +134,6 @@ class PdfRequest extends CaptureRequest
     /**
      * Get paper height.
      *
-     * @access public
      * @return string
      */
     public function getPaperHeight()
@@ -160,23 +144,19 @@ class PdfRequest extends CaptureRequest
     /**
      * Set paper size.
      *
-     * @access public
-     * @param  string $width
-     * @param  string $height
-     * @return void
+     * @param string $width
+     * @param string $height
      */
     public function setPaperSize($width, $height)
     {
-        $this->paperWidth  = $width;
+        $this->paperWidth = $width;
         $this->paperHeight = $height;
     }
 
     /**
      * Set format.
      *
-     * @access public
-     * @param  string $format
-     * @return void
+     * @param string $format
      */
     public function setFormat($format)
     {
@@ -186,7 +166,6 @@ class PdfRequest extends CaptureRequest
     /**
      * Get format.
      *
-     * @access public
      * @return string
      */
     public function getFormat()
@@ -197,9 +176,7 @@ class PdfRequest extends CaptureRequest
     /**
      * Set orientation.
      *
-     * @access public
-     * @param  string $orientation
-     * @return void
+     * @param string $orientation
      */
     public function setOrientation($orientation)
     {
@@ -209,7 +186,6 @@ class PdfRequest extends CaptureRequest
     /**
      * Get orientation.
      *
-     * @access public
      * @return string
      */
     public function getOrientation()
@@ -220,9 +196,7 @@ class PdfRequest extends CaptureRequest
     /**
      * Set margin.
      *
-     * @access public
-     * @param  string|array $margin
-     * @return void
+     * @param string|array $margin
      */
     public function setMargin($margin)
     {
@@ -232,7 +206,6 @@ class PdfRequest extends CaptureRequest
     /**
      * Get margin.
      *
-     * @access public
      * @return string|array
      */
     public function getMargin()
@@ -243,23 +216,20 @@ class PdfRequest extends CaptureRequest
     /**
      * Set repeating header.
      *
-     * @access public
-     * @param  string $content
-     * @param  string $height  (default: '1cm')
-     * @return void
+     * @param string $content
+     * @param string $height  (default: '1cm')
      */
     public function setRepeatingHeader($content, $height = '1cm')
     {
         $this->header = array(
             'content' => $content,
-            'height'  => $height
+            'height' => $height,
         );
     }
 
     /**
      * Get repeating header.
      *
-     * @access public
      * @return array
      */
     public function getRepeatingHeader()
@@ -270,23 +240,20 @@ class PdfRequest extends CaptureRequest
     /**
      * Set repeating footer.
      *
-     * @access public
-     * @param  string $content
-     * @param  string $height  (default: '1cm')
-     * @return void
+     * @param string $content
+     * @param string $height  (default: '1cm')
      */
     public function setRepeatingFooter($content, $height = '1cm')
     {
         $this->footer = array(
             'content' => $content,
-            'height'  => $height
+            'height' => $height,
         );
     }
 
     /**
      * Get repeating footer.
      *
-     * @access public
      * @return array
      */
     public function getRepeatingFooter()

+ 12 - 35
src/JonnyW/PhantomJs/Http/PdfRequestInterface.php → src/HttpOLD/PdfRequestInterface.php

@@ -10,7 +10,7 @@
 namespace JonnyW\PhantomJs\Http;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -19,16 +19,13 @@ interface PdfRequestInterface
     /**
      * Set paper width.
      *
-     * @access public
-     * @param  string $width
-     * @return void
+     * @param string $width
      */
     public function setPaperWidth($width);
 
     /**
      * Get paper width.
      *
-     * @access public
      * @return string
      */
     public function getPaperWidth();
@@ -36,16 +33,13 @@ interface PdfRequestInterface
     /**
      * Set paper height.
      *
-     * @access public
-     * @param  string $height
-     * @return void
+     * @param string $height
      */
     public function setPaperHeight($height);
 
     /**
      * Get paper height.
      *
-     * @access public
      * @return string
      */
     public function getPaperHeight();
@@ -53,26 +47,21 @@ interface PdfRequestInterface
     /**
      * Set paper size.
      *
-     * @access public
-     * @param  string $width
-     * @param  string $height
-     * @return void
+     * @param string $width
+     * @param string $height
      */
     public function setPaperSize($width, $height);
 
     /**
      * Set format.
      *
-     * @access public
-     * @param  string $format
-     * @return void
+     * @param string $format
      */
     public function setFormat($format);
 
     /**
      * Get format.
      *
-     * @access public
      * @return string
      */
     public function getFormat();
@@ -80,16 +69,13 @@ interface PdfRequestInterface
     /**
      * Set orientation.
      *
-     * @access public
-     * @param  string $orientation
-     * @return void
+     * @param string $orientation
      */
     public function setOrientation($orientation);
 
     /**
      * Get orientation.
      *
-     * @access public
      * @return string
      */
     public function getOrientation();
@@ -97,16 +83,13 @@ interface PdfRequestInterface
     /**
      * Set margin.
      *
-     * @access public
-     * @param  string $margin
-     * @return void
+     * @param string $margin
      */
     public function setMargin($margin);
 
     /**
      * Get margin.
      *
-     * @access public
      * @return string
      */
     public function getMargin();
@@ -114,17 +97,14 @@ interface PdfRequestInterface
     /**
      * Set repeating header.
      *
-     * @access public
-     * @param  string $content
-     * @param  string $height  (default: '1cm')
-     * @return void
+     * @param string $content
+     * @param string $height  (default: '1cm')
      */
     public function setRepeatingHeader($content, $height = '1cm');
 
     /**
      * Get repeating header.
      *
-     * @access public
      * @return array
      */
     public function getRepeatingHeader();
@@ -132,17 +112,14 @@ interface PdfRequestInterface
     /**
      * Set repeating footer.
      *
-     * @access public
-     * @param  string $content
-     * @param  string $height  (default: '1cm')
-     * @return void
+     * @param string $content
+     * @param string $height  (default: '1cm')
      */
     public function setRepeatingFooter($content, $height = '1cm');
 
     /**
      * Get repeating footer.
      *
-     * @access public
      * @return array
      */
     public function getRepeatingFooter();

+ 6 - 8
src/JonnyW/PhantomJs/Http/Request.php → src/HttpOLD/Request.php

@@ -10,24 +10,22 @@
 namespace JonnyW\PhantomJs\Http;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class Request extends AbstractRequest
 {
     /**
-     * Request type
+     * Request type.
      *
      * @var string
-     * @access protected
      */
     protected $type;
 
     /**
-     * Get request type
+     * Get request type.
      *
-     * @access public
      * @return string
      */
     public function getType()
@@ -40,10 +38,10 @@ class Request extends AbstractRequest
     }
 
     /**
-     * Set request type
+     * Set request type.
+     *
+     * @param string $type
      *
-     * @access public
-     * @param  string                                 $type
      * @return \JonnyW\PhantomJs\Http\AbstractRequest
      */
     public function setType($type)

+ 30 - 53
src/JonnyW/PhantomJs/Http/RequestInterface.php → src/HttpOLD/RequestInterface.php

@@ -10,60 +10,55 @@
 namespace JonnyW\PhantomJs\Http;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 interface RequestInterface
 {
     const METHOD_OPTIONS = 'OPTIONS';
-    const METHOD_GET     = 'GET';
-    const METHOD_HEAD    = 'HEAD';
-    const METHOD_POST    = 'POST';
-    const METHOD_PUT     = 'PUT';
-    const METHOD_DELETE  = 'DELETE';
-    const METHOD_PATCH   = 'PATCH';
+    const METHOD_GET = 'GET';
+    const METHOD_HEAD = 'HEAD';
+    const METHOD_POST = 'POST';
+    const METHOD_PUT = 'PUT';
+    const METHOD_DELETE = 'DELETE';
+    const METHOD_PATCH = 'PATCH';
 
     const REQUEST_TYPE_DEFAULT = 'default';
     const REQUEST_TYPE_CAPTURE = 'capture';
-    const REQUEST_TYPE_PDF     = 'pdf';
+    const REQUEST_TYPE_PDF = 'pdf';
 
     /**
-     * Get request type
+     * Get request type.
      *
-     * @access public
      * @return string
      */
     public function getType();
 
     /**
-     * Set request method
+     * Set request method.
      *
-     * @access public
      * @param string $method
      */
     public function setMethod($method);
 
     /**
-     * Get request method
+     * Get request method.
      *
-     * @access public
      * @return string
      */
     public function getMethod();
 
     /**
-     * Set timeout period
+     * Set timeout period.
      *
-     * @access public
      * @param int $timeout
      */
     public function setTimeout($timeout);
 
     /**
-     * Get timeout period
+     * Get timeout period.
      *
-     * @access public
      * @return int
      */
     public function getTimeout();
@@ -71,7 +66,6 @@ interface RequestInterface
     /**
      * Set page load delay time.
      *
-     * @access public
      * @param int $delay
      */
     public function setDelay($delay);
@@ -79,7 +73,6 @@ interface RequestInterface
     /**
      * Get page load delay time.
      *
-     * @access public
      * @return int
      */
     public function getDelay();
@@ -87,17 +80,14 @@ interface RequestInterface
     /**
      * Set viewport size.
      *
-     * @access public
-     * @param  int  $width
-     * @param  int  $height
-     * @return void
+     * @param int $width
+     * @param int $height
      */
     public function setViewportSize($width, $height);
 
     /**
      * Get viewport width.
      *
-     * @access public
      * @return int
      */
     public function getViewportWidth();
@@ -105,113 +95,100 @@ interface RequestInterface
     /**
      * Get viewport height.
      *
-     * @access public
      * @return int
      */
     public function getViewportHeight();
 
     /**
-     * Set request URL
+     * Set request URL.
      *
-     * @access public
      * @param string $url
      */
     public function setUrl($url);
 
     /**
-     * Get request URL
+     * Get request URL.
      *
-     * @access public
      * @return string
      */
     public function getUrl();
 
     /**
-     * Get content body
+     * Get content body.
      *
-     * @access public
      * @return string
      */
     public function getBody();
 
     /**
-     * Set request data
+     * Set request data.
      *
-     * @access public
      * @param array $data
      */
     public function setRequestData(array $data);
 
     /**
-     * Get request data
+     * Get request data.
+     *
+     * @param bool $flat
      *
-     * @access public
-     * @param  boolean $flat
      * @return array
      */
     public function getRequestData($flat = true);
 
     /**
-     * Set headers
+     * Set headers.
      *
-     * @access public
      * @param array $headers
      */
     public function setHeaders(array $headers);
 
     /**
-     * Add single header
+     * Add single header.
      *
-     * @access public
      * @param string $header
      * @param string $value
      */
     public function addHeader($header, $value);
 
     /**
-     * Merge headers with existing
+     * Merge headers with existing.
      *
-     * @access public
      * @param array $headers
      */
     public function addHeaders(array $headers);
 
     /**
-     * Get request headers
+     * Get request headers.
      *
-     * @access public
      * @return array|string
      */
     public function getHeaders();
 
     /**
-     * Get settings
+     * Get settings.
      *
-     * @access public
      * @return array|string
      */
     public function getSettings();
 
     /**
-     * Get cookies
+     * Get cookies.
      *
-     * @access public
      * @return array|string
      */
     public function getCookies();
 
     /**
-     * Set body styles
+     * Set body styles.
      *
-     * @access public
      * @param array $styles
      */
     public function setBodyStyles(array $styles);
 
     /**
-     * Get body styles
+     * Get body styles.
      *
-     * @access public
      * @return array|string
      */
     public function getBodyStyles();

+ 31 - 50
src/JonnyW/PhantomJs/Http/Response.php → src/HttpOLD/Response.php

@@ -6,93 +6,84 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Http;
 
 use JonnyW\PhantomJs\Procedure\OutputInterface;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
-class Response
-    implements ResponseInterface, OutputInterface
+class Response implements ResponseInterface, OutputInterface
 {
     /**
-     * Http headers array
+     * Http headers array.
      *
      * @var array
-     * @access public
      */
     public $headers;
 
     /**
-     * Response int
+     * Response int.
      *
      * @var string
-     * @access public
      */
     public $status;
 
     /**
-     * Response body
+     * Response body.
      *
      * @var string
-     * @access public
      */
     public $content;
 
     /**
-     * Response content type header
+     * Response content type header.
      *
      * @var string
-     * @access public
      */
     public $contentType;
 
     /**
-     * Requested URL
+     * Requested URL.
      *
      * @var string
-     * @access public
      */
     public $url;
 
     /**
-     * Redirected URL
+     * Redirected URL.
      *
      * @var string
-     * @access public
      */
     public $redirectURL;
 
     /**
-     * Request time string
+     * Request time string.
      *
      * @var string
-     * @access public
      */
     public $time;
 
     /**
-     * Console messages
+     * Console messages.
      *
      * @var array
-     * @access public
      */
     public $console;
 
     /**
-     * Import response data
+     * Import response data.
+     *
+     * @param array $data
      *
-     * @access public
-     * @param  array                           $data
      * @return \JonnyW\PhantomJs\Http\Response
      */
     public function import(array $data)
     {
         foreach ($data as $param => $value) {
-
             if ($param === 'headers') {
                 continue;
             }
@@ -112,16 +103,15 @@ class Response
     }
 
     /**
-     * Set headers array
+     * Set headers array.
+     *
+     * @param array $headers
      *
-     * @access protected
-     * @param  array                           $headers
      * @return \JonnyW\PhantomJs\Http\Response
      */
     protected function setHeaders(array $headers)
     {
         foreach ($headers as $header) {
-
             if (isset($header['name']) && isset($header['value'])) {
                 $this->headers[$header['name']] = $header['value'];
             }
@@ -131,9 +121,8 @@ class Response
     }
 
     /**
-     * Get HTTP headers array
+     * Get HTTP headers array.
      *
-     * @access public
      * @return array
      */
     public function getHeaders()
@@ -142,10 +131,10 @@ class Response
     }
 
     /**
-     * Get HTTP header value for code
+     * Get HTTP header value for code.
+     *
+     * @param string $code
      *
-     * @access public
-     * @param  string $code
      * @return mixed
      */
     public function getHeader($code)
@@ -158,10 +147,9 @@ class Response
     }
 
     /**
-     * Get response status code
+     * Get response status code.
      *
-     * @access public
-     * @return integer
+     * @return int
      */
     public function getStatus()
     {
@@ -169,9 +157,8 @@ class Response
     }
 
     /**
-     * Get page content from response
+     * Get page content from response.
      *
-     * @access public
      * @return string
      */
     public function getContent()
@@ -180,9 +167,8 @@ class Response
     }
 
     /**
-     * Get content type header
+     * Get content type header.
      *
-     * @access public
      * @return string
      */
     public function getContentType()
@@ -191,9 +177,8 @@ class Response
     }
 
     /**
-     * Get request URL
+     * Get request URL.
      *
-     * @access public
      * @return string
      */
     public function getUrl()
@@ -202,9 +187,8 @@ class Response
     }
 
     /**
-     * Get redirect URL (if redirected)
+     * Get redirect URL (if redirected).
      *
-     * @access public
      * @return string
      */
     public function getRedirectUrl()
@@ -214,10 +198,9 @@ class Response
 
     /**
      * Is response a redirect
-     *  - Checks status codes
+     *  - Checks status codes.
      *
-     * @access public
-     * @return boolean
+     * @return bool
      */
     public function isRedirect()
     {
@@ -227,9 +210,8 @@ class Response
     }
 
     /**
-     * Get time string
+     * Get time string.
      *
-     * @access public
      * @return string
      */
     public function getTime()
@@ -238,9 +220,8 @@ class Response
     }
 
     /**
-     * Get console messages
+     * Get console messages.
      *
-     * @access public
      * @return array
      */
     public function getConsole()

+ 15 - 25
src/JonnyW/PhantomJs/Http/ResponseInterface.php → src/HttpOLD/ResponseInterface.php

@@ -10,89 +10,79 @@
 namespace JonnyW\PhantomJs\Http;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 interface ResponseInterface
 {
     /**
-     * Import response data
-     *
-     * @access public
+     * Import response data.
      */
     public function import(array $data);
 
     /**
-     * Get HTTP headers array
+     * Get HTTP headers array.
      *
-     * @access public
      * @return array
      */
     public function getHeaders();
 
     /**
-     * Get HTTP header value for code
+     * Get HTTP header value for code.
+     *
+     * @param string $code
      *
-     * @access public
-     * @param  string $code
      * @return mixed
      */
     public function getHeader($code);
 
     /**
-     * Get response status code
+     * Get response status code.
      *
-     * @access public
-     * @return integer
+     * @return int
      */
     public function getStatus();
 
     /**
-     * Get page content from respone
+     * Get page content from respone.
      *
-     * @access public
      * @return string
      */
     public function getContent();
 
     /**
-     * Get content type header
+     * Get content type header.
      *
-     * @access public
      * @return string
      */
     public function getContentType();
 
     /**
-     * Get request URL
+     * Get request URL.
      *
-     * @access public
      * @return string
      */
     public function getUrl();
 
     /**
-     * Get redirect URL (if redirected)
+     * Get redirect URL (if redirected).
      *
-     * @access public
      * @return string
      */
     public function getRedirectUrl();
 
     /**
      * Is response a redirect
-     *  - Checks status codes
+     *  - Checks status codes.
      *
-     * @access public
-     * @return boolean
+     * @return bool
      */
     public function isRedirect();
 
     /**
-     * Get time string
+     * Get time string.
      *
-     * @access public
      * @return string
      */
     public function getTime();

+ 148 - 0
src/IO/InputInterface.php

@@ -0,0 +1,148 @@
+<?php
+
+/*
+ * This file is part of the php-phantomjs.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace JonnyW\PhantomJs\IO;
+
+use Psr\Http\Message\MessageInterface;
+
+/**
+ * PHP PhantomJs.
+ *
+ * @author Jon Wenmoth <contact@jonnyw.me>
+ */
+interface InputInterface extends MessageInterface
+{
+    /**
+     * Create new input with
+     * added custom setting.
+     *
+     * @param string $name
+     * @param mixed  $value
+     *
+     * @return \JonnyW\PhantomJs\IO\InputInterface
+     */
+    public function withCustom($name, $value);
+
+    /**
+     * Create new input with
+     * custom setting removed.
+     *
+     * @param string $name
+     *
+     * @return \JonnyW\PhantomJs\IO\InputInterface
+     */
+    public function withoutCustom($name);
+
+    /**
+     * Get custom setting.
+     *
+     * @param string $name
+     *
+     * @return mixed
+     */
+    public function getCustom($name);
+    
+    /**
+     * Has cookie.
+     *
+     * @param string $cookie
+     *
+     * @return bool
+     */
+    public function hasCookie($cookie);
+
+    /**
+     * Get single added cookie.
+     *
+     * @param string $cookie
+     *
+     * @return \JonnyW\PhantomJs\Page\Cookie|null
+     */
+    public function getCookie($cookie);
+
+    /**
+     * Get all added cookies.
+     *
+     * @return array
+     */
+    public function getCookies();
+
+    /**
+     * Create new input with
+     * added cookie.
+     *
+     * @param \JonnyW\PhantomJs\Page\Cookie $cookie
+     *
+     * @return \JonnyW\PhantomJs\IO\InputInterface
+     */
+    public function withCookie(Cookie $cookie);
+
+    /**
+     * Create new input with cookie
+     * removed and flagged for delete.
+     *
+     * @param string $cookie
+     *
+     * @return \JonnyW\PhantomJs\IO\InputInterface
+     */
+    public function withoutCookie($cookie);
+
+    /**
+     * Has setting.
+     *
+     * @param string $setting
+     *
+     * @return bool
+     */
+    public function hasSetting($setting);
+
+    /**
+     * Get single setting.
+     *
+     * @param string $setting
+     *
+     * @return mixed
+     */
+    public function getSetting($setting);
+
+    /**
+     * Get all settings.
+     *
+     * @return array
+     */
+    public function getSettings();
+
+    /**
+     * Create new input with
+     * added setting.
+     *
+     * @param string $setting
+     * @param mixed  $value
+     *
+     * @return \JonnyW\PhantomJs\IO\InputInterface
+     */
+    public function withSetting($setting, $value);
+
+    /**
+     * Create new input with setting
+     * removed.
+     *
+     * @param string $setting
+     *
+     * @return \JonnyW\PhantomJs\IO\InputInterface
+     */
+    public function withoutSetting($setting);
+
+    /**
+     * Get input type.
+     *
+     * @return string
+     */
+    public function getType();
+}

+ 242 - 0
src/IO/InputTrait.php

@@ -0,0 +1,242 @@
+<?php
+
+/*
+ * This file is part of the php-phantomjs.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace JonnyW\PhantomJs\IO;
+
+use JonnyW\PhantomJs\Page\Cookie;
+
+/**
+ * PHP PhantomJs.
+ *
+ * @author Jon Wenmoth <contact@jonnyw.me>
+ */
+trait InputTrait
+{
+    /**
+     * Cookies.
+     *
+     * @var array
+     */
+    private $cookies = [
+        'add' => [],
+        'remove' => [],
+    ];
+
+    /**
+     * Settings.
+     *
+     * (default value: [])
+     *
+     * @var array
+     */
+    private $settings = [];
+
+    /**
+     * Custom input settings.
+     *
+     * (default value: [])
+     *
+     * @var array
+     */
+    private $custom = [];
+
+    /**
+     * Create new input with
+     * added custom setting.
+     *
+     * @param string $name
+     * @param mixed  $value
+     *
+     * @return \JonnyW\PhantomJs\IO\InputInterface
+     */
+    public function withCustom($name, $value)
+    {
+        $new = clone $this;
+        $new->custom[$name] = $value;
+
+        return $new;
+    }
+
+    /**
+     * Create new input with
+     * custom setting removed.
+     *
+     * @param string $name
+     *
+     * @return \JonnyW\PhantomJs\IO\InputInterface
+     */
+    public function withoutCustom($name)
+    {
+        $new = clone $this;
+
+        unset($new->custom[$name]);
+
+        return $new;
+    }
+
+    /**
+     * Get custom setting.
+     *
+     * @param string $name
+     *
+     * @return mixed
+     */
+    public function getCustom($name)
+    {
+        if (isset($this->custom[$name])) {
+            return $this->custom[$name];
+        }
+
+        return '';
+    }
+
+    /**
+     * Has cookie.
+     *
+     * @param string $cookie
+     *
+     * @return bool
+     */
+    public function hasCookie($cookie)
+    {
+        return isset($this->cookies['add'][$cookie]);
+    }
+
+    /**
+     * Get single added cookie.
+     *
+     * @param string $cookie
+     *
+     * @return \JonnyW\PhantomJs\Page\Cookie|null
+     */
+    public function getCookie($cookie)
+    {
+        if (isset($this->cookies['add'][$cookie])) {
+            return $this->cookies['add'][$cookie];
+        }
+
+        return null;
+    }
+
+    /**
+     * Get all cookies.
+     *
+     * @return array
+     */
+    public function getCookies()
+    {
+        return $this->cookies;
+    }
+
+    /**
+     * Create new input with
+     * added cookie.
+     *
+     * @param \JonnyW\PhantomJs\Page\Cookie $cookie
+     *
+     * @return \JonnyW\PhantomJs\IO\InputInterface
+     */
+    public function withCookie(Cookie $cookie)
+    {
+        $new = clone $this;
+        $new->cookies['add'][$cookie->getName()] = $cookie;
+
+        return $new;
+    }
+
+    /**
+     * Create new input with cookie
+     * removed and flagged for delete.
+     *
+     * @param string $cookie
+     *
+     * @return \JonnyW\PhantomJs\IO\InputInterface
+     */
+    public function withoutCookie($cookie)
+    {
+        $new = clone $this;
+        $new->cookies['remove'][] = $cookie;
+
+        unset($new->cookies['add'][$cookie]);
+
+        return $new;
+    }
+
+    /**
+     * Has setting.
+     *
+     * @param string $setting
+     *
+     * @return bool
+     */
+    public function hasSetting($setting)
+    {
+        return isset($this->settings[$setting]);
+    }
+
+    /**
+     * Get single setting.
+     *
+     * @param string $setting
+     *
+     * @return mixed
+     */
+    public function getSetting($setting)
+    {
+        if (isset($this->settings[$setting])) {
+            return $this->settings[$setting];
+        }
+
+        return null;
+    }
+
+    /**
+     * Get all settings.
+     *
+     * @return array
+     */
+    public function getSettings()
+    {
+        return $this->settings;
+    }
+
+    /**
+     * Create new input with
+     * added setting.
+     *
+     * @param string $setting
+     * @param mixed  $value
+     *
+     * @return \JonnyW\PhantomJs\IO\InputInterface
+     */
+    public function withSetting($setting, $value)
+    {
+        $new = clone $this;
+        $new->settings[$setting] = $value;
+
+        return $new;
+    }
+
+    /**
+     * Create new input with setting
+     * removed.
+     *
+     * @param string $setting
+     *
+     * @return \JonnyW\PhantomJs\IO\InputInterface
+     */
+    public function withoutSetting($setting)
+    {
+        $new = clone $this;
+
+        unset($new->settings[$setting]);
+
+        return $new;
+    }
+}

+ 147 - 0
src/IO/OutputInterface.php

@@ -0,0 +1,147 @@
+<?php
+
+/*
+ * This file is part of the php-phantomjs.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace JonnyW\PhantomJs\IO;
+
+use Psr\Http\Message\MessageInterface;
+use JonnyW\PhantomJs\Page\PaperSize;
+use JonnyW\PhantomJs\Page\ZoomFactor;
+use JonnyW\PhantomJs\Page\ViewportSize;
+
+/**
+ * PHP PhantomJs.
+ *
+ * @author Jon Wenmoth <contact@jonnyw.me>
+ */
+interface OutputInterface extends MessageInterface
+{
+    /**
+     * Create new output instance
+     * with viewport size set.
+     *
+     * @param \JonnyW\PhantomJs\Page\ViewportSize $size
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withViewportSize(ViewportSize $size);
+
+    /**
+     * Create new output instance
+     * and unset viewport size.
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withoutViewportSize();
+
+    /**
+     * Get viewport size.
+     *
+     * @return \JonnyW\PhantomJs\Page\ViewportSize
+     */
+    public function getViewportSize();
+
+    /**
+     * Create new output instance
+     * with paper size set.
+     *
+     * @param \JonnyW\PhantomJs\Page\PaperSize $size
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withPaperSize(PaperSize $size);
+
+    /**
+     * Create new output instance
+     * and unset paper size.
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withoutPaperSize();
+
+    /**
+     * Get paper size.
+     *
+     * @return \JonnyW\PhantomJs\Page\PaperSize
+     */
+    public function getPaperSize();
+
+    /**
+     * Create new output instance
+     * with zoom factor set.
+     *
+     * @param \JonnyW\PhantomJs\Page\ZoomFactor $zoom
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withZoomFactor(ZoomFactor $zoom);
+
+    /**
+     * Create new output instance
+     * and unset zoom factor.
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withoutZoomFactor();
+
+    /**
+     * Get zoom factor.
+     *
+     * @return \JonnyW\PhantomJs\Page\ZoomFactor
+     */
+    public function getZoomFactor();
+
+    /**
+     * Create new output instance
+     * with clip rect set.
+     *
+     * @param \JonnyW\PhantomJs\Page\ClipRect $zoom
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withClipRect(ClipRect $zoom);
+
+    /**
+     * Create new output instance
+     * and unset clip rect.
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withoutClipRect();
+
+    /**
+     * Get clip rect.
+     *
+     * @return \JonnyW\PhantomJs\Page\ClipRect
+     */
+    public function getClipRect();
+
+    /**
+     * Create new output instance
+     * with log entry added.
+     *
+     * @param string $line
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withLog($entry);
+
+    /**
+     * Get log data.
+     *
+     * @return array
+     */
+    public function getLogs();
+
+    /**
+     * Get input type.
+     *
+     * @return string
+     */
+    public function getType();
+}

+ 226 - 0
src/IO/OutputTrait.php

@@ -0,0 +1,226 @@
+<?php
+
+/*
+ * This file is part of the php-phantomjs.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace JonnyW\PhantomJs\IO;
+
+use JonnyW\PhantomJs\Page\PaperSize;
+use JonnyW\PhantomJs\Page\ZoomFactor;
+use JonnyW\PhantomJs\Page\ViewportSize;
+
+/**
+ * PHP PhantomJs.
+ *
+ * @author Jon Wenmoth <contact@jonnyw.me>
+ */
+trait OutputTrait
+{
+    /**
+     * Output logs.
+     *
+     * @var array
+     */
+    private $logs = [];
+
+    /**
+     * Settings.
+     *
+     * @var array
+     */
+    private $settings = [];
+
+    /**
+     * Create new output instance
+     * with viewport size set.
+     *
+     * @param \JonnyW\PhantomJs\Page\ViewportSize $size
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withViewportSize(ViewportSize $size)
+    {
+        $new = clone $this;
+        $new->settings['page.viewportSize'] = $size;
+
+        return $new;
+    }
+
+    /**
+     * Create new output instance
+     * and unset viewport size.
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withoutViewportSize()
+    {
+        $new = clone $this;
+
+        unset($new->settings['page.viewportSize']);
+
+        return $new;
+    }
+
+    /**
+     * Get viewport size.
+     *
+     * @return \JonnyW\PhantomJs\Page\ViewportSize
+     */
+    public function getViewportSize()
+    {
+        return $this->settings['page.viewportSize'];
+    }
+
+    /**
+     * Create new output instance
+     * with paper size set.
+     *
+     * @param \JonnyW\PhantomJs\Page\PaperSize $size
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withPaperSize(PaperSize $size)
+    {
+        $new = clone $this;
+        $new->settings['page.paperSize'] = $size;
+
+        return $new;
+    }
+
+    /**
+     * Create new output instance
+     * and unset paper size.
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withoutPaperSize()
+    {
+        $new = clone $this;
+
+        unset($new->settings['page.paperSize']);
+
+        return $new;
+    }
+
+    /**
+     * Get paper size.
+     *
+     * @return \JonnyW\PhantomJs\Page\PaperSize
+     */
+    public function getPaperSize()
+    {
+        return $this->settings['page.paperSize'];
+    }
+
+    /**
+     * Create new output instance
+     * with zoom factor set.
+     *
+     * @param \JonnyW\PhantomJs\Page\ZoomFactor $zoom
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withZoomFactor(ZoomFactor $zoom)
+    {
+        $new = clone $this;
+        $new->settings['page.zoomFactor'] = $zoom;
+
+        return $new;
+    }
+
+    /**
+     * Create new output instance
+     * and unset zoom factor.
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withoutZoomFactor()
+    {
+        $new = clone $this;
+
+        unset($new->settings['page.zoomFactor']);
+
+        return $new;
+    }
+
+    /**
+     * Get zoom factor.
+     *
+     * @return \JonnyW\PhantomJs\Page\ZoomFactor
+     */
+    public function getZoomFactor()
+    {
+        return $this->settings['page.zoomFactor'];
+    }
+
+    /**
+     * Create new output instance
+     * with clip rect set.
+     *
+     * @param \JonnyW\PhantomJs\Page\ClipRect $zoom
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withClipRect(ClipRect $zoom)
+    {
+        $new = clone $this;
+        $new->settings['page.clipRect'] = $zoom;
+
+        return $new;
+    }
+
+    /**
+     * Create new output instance
+     * and unset clip rect.
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withoutClipRect()
+    {
+        $new = clone $this;
+
+        unset($new->settings['page.clipRect']);
+
+        return $new;
+    }
+
+    /**
+     * Get clip rect.
+     *
+     * @return \JonnyW\PhantomJs\Page\ClipRect
+     */
+    public function getClipRect()
+    {
+        return $this->settings['page.clipRect'];
+    }
+
+    /**
+     * Create new output instance
+     * with log entry added.
+     *
+     * @param string $line
+     *
+     * @return \JonnyW\PhantomJs\IO\OutputInterface
+     */
+    public function withLog($entry)
+    {
+        $new = clone $this;
+        $new->logs[] = $entry;
+
+        return $new;
+    }
+
+    /**
+     * Get log data.
+     *
+     * @return array
+     */
+    public function getLogs()
+    {
+        return $this->logs;
+    }
+}

+ 41 - 0
src/IO/StreamInput.php

@@ -0,0 +1,41 @@
+<?php
+
+/*
+ * This file is part of the php-phantomjs.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace JonnyW\PhantomJs\IO;
+
+/**
+ * PHP PhantomJs.
+ *
+ * @author Jon Wenmoth <contact@jonnyw.me>
+ */
+class StreamInput implements InputInterface
+{
+    use \GuzzleHttp\Psr7\MessageTrait;
+    use \JonnyW\PhantomJs\IO\InputTrait;
+
+    /**
+     * Internal constructor.
+     *
+     * @param string|null|resource|StreamInterface $body
+     */
+    public function __construct($body)
+    {
+        $this->stream = \GuzzleHttp\Psr7\stream_for($body);
+    }
+
+    /**
+     * Get input type.
+     *
+     * @return string
+     */
+    public function getType()
+    {
+        return 'stream';
+    }
+}

+ 41 - 0
src/IO/StreamOutput.php

@@ -0,0 +1,41 @@
+<?php
+
+/*
+ * This file is part of the php-phantomjs.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace JonnyW\PhantomJs\IO;
+
+/**
+ * PHP PhantomJs.
+ *
+ * @author Jon Wenmoth <contact@jonnyw.me>
+ */
+class StreamOutput implements OutputInterface
+{
+    use \GuzzleHttp\Psr7\MessageTrait;
+    use \JonnyW\PhantomJs\IO\OutputTrait;
+
+    /**
+     * Internal constructor.
+     *
+     * @param string|null|resource|StreamInterface $body
+     */
+    public function __construct($body)
+    {
+        $this->stream = \GuzzleHttp\Psr7\stream_for($body);
+    }
+
+    /**
+     * Get output type.
+     *
+     * @return string
+     */
+    public function getType()
+    {
+        return 'stream';
+    }
+}

+ 0 - 68
src/JonnyW/PhantomJs/Procedure/Input.php

@@ -1,68 +0,0 @@
-<?php
-
-/*
- * This file is part of the php-phantomjs.
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace JonnyW\PhantomJs\Procedure;
-
-/**
- * PHP PhantomJs
- *
- * @author Jon Wenmoth <contact@jonnyw.me>
- */
-class Input implements InputInterface
-{
-    /**
-     * Data storage.
-     *
-     * @var array
-     * @access protected
-     */
-    protected $data;
-
-    /**
-     * Internal constructor.
-     *
-     * @access public
-     * @return void
-     */
-    public function __construct()
-    {
-        $this->data = array();
-    }
-
-    /**
-     * Set data value.
-     *
-     * @access public
-     * @param  string                            $name
-     * @param  mixed                             $value
-     * @return \JonnyW\PhantomJs\Procedure\Input
-     */
-    public function set($name, $value)
-    {
-        $this->data[$name] = $value;
-
-        return $this;
-    }
-
-    /**
-     * Get data value.
-     *
-     * @access public
-     * @param  string $name
-     * @return mixed
-     */
-    public function get($name)
-    {
-        if (isset($this->data[$name])) {
-            return $this->data[$name];
-        }
-
-        return '';
-    }
-}

+ 0 - 20
src/JonnyW/PhantomJs/Procedure/InputInterface.php

@@ -1,20 +0,0 @@
-<?php
-
-/*
- * This file is part of the php-phantomjs.
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace JonnyW\PhantomJs\Procedure;
-
-/**
- * PHP PhantomJs
- *
- * @author Jon Wenmoth <contact@jonnyw.me>
- */
-interface InputInterface
-{
-
-}

+ 0 - 110
src/JonnyW/PhantomJs/Procedure/Output.php

@@ -1,110 +0,0 @@
-<?php
-
-/*
- * This file is part of the php-phantomjs.
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace JonnyW\PhantomJs\Procedure;
-
-/**
- * PHP PhantomJs
- *
- * @author Jon Wenmoth <contact@jonnyw.me>
- */
-class Output implements OutputInterface
-{
-    /**
-     * Output data.
-     *
-     * @var array
-     * @access protected
-     */
-    protected $data;
-
-    /**
-     * Output logs.
-     *
-     * @var array
-     * @access protected
-     */
-    protected $logs;
-
-    /**
-     * Internal constructor.
-     *
-     * @access public
-     * @return void
-     */
-    public function __construct()
-    {
-        $this->data = array();
-        $this->logs = array();
-    }
-
-    /**
-     * Import data.
-     *
-     * @param array $data
-     * @access public
-     */
-    public function import(array $data)
-    {
-        $this->data = $data;
-    }
-
-    /**
-     * Set data value.
-     *
-     * @access public
-     * @param  string                             $name
-     * @param  mixed                              $value
-     * @return \JonnyW\PhantomJs\Procedure\Output
-     */
-    public function set($name, $value)
-    {
-        $this->data[$name] = $value;
-
-        return $this;
-    }
-
-    /**
-     * Get data value.
-     *
-     * @access public
-     * @param  string $name
-     * @return mixed
-     */
-    public function get($name)
-    {
-        if (isset($this->data[$name])) {
-            return $this->data[$name];
-        }
-
-        return '';
-    }
-
-    /**
-     * Log data.
-     *
-     * @access public
-     * @param string $data
-     */
-    public function log($data)
-    {
-        $this->logs[] = $data;
-    }
-
-    /**
-     * Get log data.
-     *
-     * @access public
-     * @return array
-     */
-    public function getLogs()
-    {
-        return $this->logs;
-    }
-}

+ 0 - 26
src/JonnyW/PhantomJs/Procedure/OutputInterface.php

@@ -1,26 +0,0 @@
-<?php
-
-/*
- * This file is part of the php-phantomjs.
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace JonnyW\PhantomJs\Procedure;
-
-/**
- * PHP PhantomJs
- *
- * @author Jon Wenmoth <contact@jonnyw.me>
- */
-interface OutputInterface
-{
-    /**
-     * Import data.
-     *
-     * @param array $data
-     * @access public
-     */
-    public function import(array $data);
-}

+ 0 - 21
src/JonnyW/PhantomJs/Resources/procedures/page_clip_rect.partial

@@ -1,21 +0,0 @@
-
-{% if input.getType() == 'capture' or input.getType() == 'pdf' %}
-
-var rectTop    = {{ input.getRectTop() }},
-    rectLeft   = {{ input.getRectLeft() }},
-    rectWidth  = {{ input.getRectWidth() }},
-    rectHeight = {{ input.getRectHeight() }};
-
-if(rectWidth && rectHeight) {
-    
-    debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Set capture clipping size ~ top: ' + rectTop + ' left: ' + rectLeft + ' ' + rectWidth + 'x' + rectHeight);
-    
-    page.clipRect = {
-        top: rectTop,
-        left: rectLeft,
-        width: rectWidth,
-        height: rectHeight
-    };
-}
-
-{% endif %}

+ 0 - 3
src/JonnyW/PhantomJs/Resources/procedures/page_custom_headers.partial

@@ -1,3 +0,0 @@
-
-page.customHeaders = {{ input.getHeaders()|json_encode(constant('JSON_FORCE_OBJECT')) }};
-

+ 0 - 16
src/JonnyW/PhantomJs/Resources/procedures/page_open.partial

@@ -1,16 +0,0 @@
-
-var delay = {{ input.getDelay() }};
-
-if(!delay) {
-    return procedure.execute(status);
-}
-
-debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Delaying page render for ' + delay + ' second(s)');
-
-window.setTimeout(function () { 
-
-    debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Rendering page after delaying for ' + delay + ' second(s)');
-    procedure.execute(status); 
-
-}, (delay * 1000));
-

+ 0 - 49
src/JonnyW/PhantomJs/Resources/procedures/page_paper_size.partial

@@ -1,49 +0,0 @@
-
-{% if input.getType() == 'pdf' %}
-
-    var paperWidth       = '{{ input.getPaperWidth() }}',
-        paperHeight      = '{{ input.getPaperHeight() }}',
-        paperFormat      = '{{ input.getFormat() }}',
-        paperOrientation = '{{ input.getOrientation() }}',
-        paperMargin      = {{ input.getMargin()|json_encode(constant('JSON_FORCE_OBJECT')) }},
-        header           = {{ input.getRepeatingHeader()|json_encode(constant('JSON_FORCE_OBJECT')) }},
-        footer           = {{ input.getRepeatingFooter()|json_encode(constant('JSON_FORCE_OBJECT')) }};
-
-    if(paperWidth && paperHeight) {
-        
-        debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Set page size ~ width: ' + paperWidth + ' height: ' + paperHeight + ' margin: ' + paperMargin);
-        
-        var paperSize = { 
-            width:  paperWidth, 
-            height: paperHeight, 
-            margin: paperMargin
-        };
-
-    } else {
-        
-        debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Set page size ~ format: ' + paperFormat + ' orientation: ' + paperOrientation + ' margin: ' + paperMargin);
-        
-        var paperSize = { 
-            format:      paperFormat, 
-            orientation: paperOrientation, 
-            margin:      paperMargin
-        };
-    }
-    
-    paperSize.header = {
-        height: header.height,
-        contents: phantom.callback(function(pageNum, pageTotal) {
-            return header.content.replace('%pageNum%', pageNum).replace('%pageTotal%', pageTotal);
-        })
-    };
-    
-    paperSize.footer = {
-        height: footer.height,
-        contents: phantom.callback(function(pageNum, pageTotal) {
-            return footer.content.replace('%pageNum%', pageNum).replace('%pageTotal%', pageTotal);
-        })
-    };
-    
-    page.paperSize = paperSize;
-
-{% endif %}

+ 0 - 14
src/JonnyW/PhantomJs/Resources/procedures/page_viewport_size.partial

@@ -1,14 +0,0 @@
-
-var viewportWidth  = {{ input.getViewportWidth() }},
-    viewportHeight = {{ input.getViewportHeight() }};
-
-if(viewportWidth && viewportHeight) {
-    
-    debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Set viewport size ~ width: ' + viewportWidth + ' height: ' + viewportHeight);
-    
-    page.viewportSize = {
-        width: viewportWidth,
-        height: viewportHeight
-    };
-}
-

+ 0 - 27
src/JonnyW/PhantomJs/Resources/procedures/procedure_capture.partial

@@ -1,27 +0,0 @@
-
-if (status === 'success') {
-
-    try {
-    
-        page.render('{{ input.getOutputFile() }}', {
-            format: '{{ input.getFormat() }}',
-            quality: {{ input.getQuality() }},
-        });
-
-        response.content = page.evaluate(function () {
-            return document.getElementsByTagName('html')[0].innerHTML
-        });
-
-    } catch(e) {
-
-        response.status  = 500;
-        response.content = e.message;
-    }
-}
-
-response.console = logs;
-
-system.stderr.write(debug.join('\\n') + '\\n');
-system.stdout.write(JSON.stringify(response, undefined, 4));
-
-phantom.exit();

+ 0 - 25
src/JonnyW/PhantomJs/Resources/procedures/procedure_pdf.partial

@@ -1,25 +0,0 @@
-
-if (status === 'success') {
-    
-    try {
-    
-        page.render('{{ input.getOutputFile() }}');
-        
-        response.content = page.evaluate(function () {
-            return document.getElementsByTagName('html')[0].innerHTML
-        });
-    
-    } catch(e) {
-
-        response.status  = 500;
-        response.content = e.message;
-    }
-}
-
-response.console = logs;
-
-system.stderr.write(debug.join('\\n') + '\\n');
-system.stdout.write(JSON.stringify(response, undefined, 4));
-
-phantom.exit();
-

+ 4 - 3
src/JonnyW/PhantomJs/Parser/JsonParser.php → src/Parser/JsonParser.php

@@ -6,10 +6,11 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Parser;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -18,8 +19,8 @@ class JsonParser implements ParserInterface
     /**
      * Parse json string into array.
      *
-     * @access public
-     * @param  string    $data
+     * @param string $data
+     *
      * @return \stdClass
      */
     public function parse($data)

+ 2 - 2
src/JonnyW/PhantomJs/Parser/ParserInterface.php → src/Parser/ParserInterface.php

@@ -6,10 +6,11 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Parser;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -18,7 +19,6 @@ interface ParserInterface
     /**
      * Parse data.
      *
-     * @access public
      * @param mixed $data
      */
     public function parse($data);

+ 16 - 23
src/JonnyW/PhantomJs/Procedure/ChainProcedureLoader.php → src/Procedure/ChainProcedureLoader.php

@@ -6,10 +6,11 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Procedure;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -19,14 +20,12 @@ class ChainProcedureLoader implements ProcedureLoaderInterface
      * Procedure loader storage.
      *
      * @var array
-     * @access protected
      */
     protected $procedureLoaders;
 
     /**
      * Internal constructor.
      *
-     * @access public
      * @param array $procedureLoaders
      */
     public function __construct(array $procedureLoaders)
@@ -37,9 +36,7 @@ class ChainProcedureLoader implements ProcedureLoaderInterface
     /**
      * Add procedure loader.
      *
-     * @access public
-     * @param  \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $procedureLoader
-     * @return void
+     * @param \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $procedureLoader
      */
     public function addLoader(ProcedureLoaderInterface $procedureLoader)
     {
@@ -49,24 +46,22 @@ class ChainProcedureLoader implements ProcedureLoaderInterface
     /**
      * Load procedure instance by id.
      *
-     * @access public
-     * @param  string                                         $id
+     * @param string $id
+     *
      * @throws \InvalidArgumentException
+     *
      * @return \JonnyW\PhantomJs\Procedure\ProcedureInterface
      */
     public function load($id)
     {
-        /** @var \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $loader **/
+        /** @var \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $loader * */
         foreach ($this->procedureLoaders as $loader) {
-
             try {
-
                 $procedure = $loader->load($id);
 
                 return $procedure;
-
-            } catch (\Exception $e) {}
-
+            } catch (\Exception $e) {
+            }
         }
 
         throw new \InvalidArgumentException(sprintf('No valid procedure loader could be found to load the \'%s\' procedure.', $id));
@@ -75,25 +70,23 @@ class ChainProcedureLoader implements ProcedureLoaderInterface
     /**
      * Load procedure template by id.
      *
-     * @access public
-     * @param  string                    $id
-     * @param  string                    $extension (default: 'proc')
+     * @param string $id
+     * @param string $extension (default: 'proc')
+     *
      * @throws \InvalidArgumentException
+     *
      * @return string
      */
     public function loadTemplate($id, $extension = 'proc')
     {
-        /** @var \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $loader **/
+        /** @var \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $loader * */
         foreach ($this->procedureLoaders as $loader) {
-
             try {
-
                 $template = $loader->loadTemplate($id, $extension);
 
                 return $template;
-
-            } catch (\Exception $e) {}
-
+            } catch (\Exception $e) {
+            }
         }
 
         throw new \InvalidArgumentException(sprintf('No valid procedure loader could be found to load the \'%s\' procedure template.', $id));

+ 23 - 34
src/JonnyW/PhantomJs/Procedure/Procedure.php → src/Procedure/Procedure.php

@@ -6,28 +6,30 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Procedure;
 
 use JonnyW\PhantomJs\Engine;
 use JonnyW\PhantomJs\Cache\CacheInterface;
 use JonnyW\PhantomJs\Parser\ParserInterface;
 use JonnyW\PhantomJs\Template\TemplateRendererInterface;
+use JonnyW\PhantomJs\IO\InputInterface;
+use JonnyW\PhantomJs\IO\OutputInterface;
 use JonnyW\PhantomJs\Exception\NotWritableException;
 use JonnyW\PhantomJs\Exception\ProcedureFailedException;
 use JonnyW\PhantomJs\StringUtils;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class Procedure implements ProcedureInterface
 {
     /**
-     * PhantomJS engine
+     * PhantomJS engine.
      *
      * @var \JonnyW\PhantomJs\Engine
-     * @access protected
      */
     protected $engine;
 
@@ -35,7 +37,6 @@ class Procedure implements ProcedureInterface
      * Parser instance.
      *
      * @var \JonnyW\PhantomJs\Parser\ParserInterface
-     * @access protected
      */
     protected $parser;
 
@@ -43,7 +44,6 @@ class Procedure implements ProcedureInterface
      * Cache handler instance.
      *
      * @var \JonnyW\PhantomJs\Cache\CacheInterface
-     * @access protected
      */
     protected $cacheHandler;
 
@@ -51,7 +51,6 @@ class Procedure implements ProcedureInterface
      * Template renderer.
      *
      * @var \JonnyW\PhantomJs\Template\TemplateRendererInterface
-     * @access protected
      */
     protected $renderer;
 
@@ -59,14 +58,12 @@ class Procedure implements ProcedureInterface
      * Procedure template.
      *
      * @var string
-     * @access protected
      */
     protected $template;
 
     /**
      * Internal constructor.
      *
-     * @access public
      * @param \JonnyW\PhantomJs\Engine                             $engine
      * @param \JonnyW\PhantomJs\Parser\ParserInterface             $parser
      * @param \JonnyW\PhantomJs\Cache\CacheInterface               $cacheHandler
@@ -74,34 +71,32 @@ class Procedure implements ProcedureInterface
      */
     public function __construct(Engine $engine, ParserInterface $parser, CacheInterface $cacheHandler, TemplateRendererInterface $renderer)
     {
-        $this->engine       = $engine;
-        $this->parser       = $parser;
+        $this->engine = $engine;
+        $this->parser = $parser;
         $this->cacheHandler = $cacheHandler;
-        $this->renderer     = $renderer;
+        $this->renderer = $renderer;
     }
 
     /**
      * Run procedure.
      *
-     * @access public
-     * @param  \JonnyW\PhantomJs\Procedure\InputInterface           $input
-     * @param  \JonnyW\PhantomJs\Procedure\OutputInterface          $output
+     * @param \JonnyW\PhantomJs\IO\InputInterface  $input
+     * @param \JonnyW\PhantomJs\IO\OutputInterface $output
+     *
      * @throws \JonnyW\PhantomJs\Exception\ProcedureFailedException
      * @throws \JonnyW\PhantomJs\Exception\NotWritableException
-     * @return void
      */
     public function run(InputInterface $input, OutputInterface $output)
     {
         try {
-
             $executable = $this->write(
-                $this->compile($input)
+                $this->compile($input, $output)
             );
 
             $descriptorspec = array(
                 array('pipe', 'r'),
                 array('pipe', 'w'),
-                array('pipe', 'w')
+                array('pipe', 'w'),
             );
 
             $process = proc_open(escapeshellcmd(sprintf('%s %s', $this->engine->getCommand(), $executable)), $descriptorspec, $pipes, null, null);
@@ -111,7 +106,7 @@ class Procedure implements ProcedureInterface
             }
 
             $result = stream_get_contents($pipes[1]);
-            $log    = stream_get_contents($pipes[2]);
+            $log = stream_get_contents($pipes[2]);
 
             fclose($pipes[0]);
             fclose($pipes[1]);
@@ -126,11 +121,9 @@ class Procedure implements ProcedureInterface
             $this->engine->log($log);
 
             $this->remove($executable);
-
         } catch (NotWritableException $e) {
             throw $e;
         } catch (\Exception $e) {
-
             if (isset($executable)) {
                 $this->remove($executable);
             }
@@ -142,8 +135,8 @@ class Procedure implements ProcedureInterface
     /**
      * Set procedure template.
      *
-     * @access public
-     * @param  string                                $template
+     * @param string $template
+     *
      * @return \JonnyW\PhantomJs\Procedure\Procedure
      */
     public function setTemplate($template)
@@ -156,7 +149,6 @@ class Procedure implements ProcedureInterface
     /**
      * Get procedure template.
      *
-     * @access public
      * @return string
      */
     public function getTemplate()
@@ -167,20 +159,19 @@ class Procedure implements ProcedureInterface
     /**
      * Compile procedure.
      *
-     * @access public
-     * @param  \JonnyW\PhantomJs\Procedure\InputInterface $input
-     * @return void
+     * @param \JonnyW\PhantomJs\IO\InputInterface  $input
+     * @param \JonnyW\PhantomJs\IO\OutputInterface $output
      */
-    public function compile(InputInterface $input)
+    public function compile(InputInterface $input, OutputInterface $output)
     {
-       return $this->renderer->render($this->getTemplate(), array('input' => $input));
+        return $this->renderer->render($this->getTemplate(), array('input' => $input, 'output' => $output));
     }
 
     /**
      * Write compiled procedure to cache.
      *
-     * @access protected
-     * @param  string $compiled
+     * @param string $compiled
+     *
      * @return string
      */
     protected function write($compiled)
@@ -191,9 +182,7 @@ class Procedure implements ProcedureInterface
     /**
      * Remove procedure script cache.
      *
-     * @access protected
-     * @param  string $filePath
-     * @return void
+     * @param string $filePath
      */
     protected function remove($filePath)
     {

+ 24 - 39
src/JonnyW/PhantomJs/Procedure/ProcedureCompiler.php → src/Procedure/ProcedureCompiler.php

@@ -11,58 +11,54 @@ namespace JonnyW\PhantomJs\Procedure;
 
 use JonnyW\PhantomJs\Cache\CacheInterface;
 use JonnyW\PhantomJs\Template\TemplateRendererInterface;
+use JonnyW\PhantomJs\IO\InputInterface;
+use JonnyW\PhantomJs\IO\OutputInterface;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class ProcedureCompiler implements ProcedureCompilerInterface
 {
     /**
-     * Procedure loader
+     * Procedure loader.
      *
      * @var \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface
-     * @access protected
      */
     protected $procedureLoader;
 
     /**
-     * Procedure validator
+     * Procedure validator.
      *
      * @var \JonnyW\PhantomJs\Procedure\ProcedureValidatorInterface
-     * @access protected
      */
     protected $procedureValidator;
 
     /**
-     * Cache handler
+     * Cache handler.
      *
      * @var \JonnyW\PhantomJs\Cache\CacheInterface
-     * @access protected
      */
     protected $cacheHandler;
 
     /**
-     * Renderer
+     * Renderer.
      *
      * @var \JonnyW\PhantomJs\Template\TemplateRendererInterface
-     * @access protected
      */
     protected $renderer;
 
     /**
-     * Cache enabled
+     * Cache enabled.
      *
-     * @var boolean
-     * @access protected
+     * @var bool
      */
     protected $cacheEnabled;
 
     /**
-     * Internal constructor
+     * Internal constructor.
      *
-     * @access public
      * @param \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface    $procedureLoader
      * @param \JonnyW\PhantomJs\Procedure\ProcedureValidatorInterface $procedureValidator
      * @param \JonnyW\PhantomJs\Cache\CacheInterface                  $cacheHandler
@@ -71,38 +67,36 @@ class ProcedureCompiler implements ProcedureCompilerInterface
     public function __construct(ProcedureLoaderInterface $procedureLoader, ProcedureValidatorInterface $procedureValidator,
         CacheInterface $cacheHandler, TemplateRendererInterface $renderer)
     {
-        $this->procedureLoader    = $procedureLoader;
+        $this->procedureLoader = $procedureLoader;
         $this->procedureValidator = $procedureValidator;
-        $this->cacheHandler       = $cacheHandler;
-        $this->renderer           = $renderer;
-        $this->cacheEnabled       = true;
+        $this->cacheHandler = $cacheHandler;
+        $this->renderer = $renderer;
+        $this->cacheEnabled = true;
     }
 
     /**
      * Compile partials into procedure.
      *
-     * @access public
-     * @param  \JonnyW\PhantomJs\Procedure\ProcedureInterface $procedure
-     * @param  \JonnyW\PhantomJs\Procedure\InputInterface     $input
-     * @return void
+     * @param \JonnyW\PhantomJs\Procedure\ProcedureInterface $procedure
+     * @param \JonnyW\PhantomJs\IO\InputInterface            $input
+     * @param \JonnyW\PhantomJs\IO\OutputInterface           $output
      */
-    public function compile(ProcedureInterface $procedure, InputInterface $input)
+    public function compile(ProcedureInterface $procedure, InputInterface $input, OutputInterface $output)
     {
-        $cacheKey = sprintf('phantomjs_%s_%s', $input->getType(), md5($procedure->getTemplate()));
+        $cacheKey = sprintf('phantomjs_%s_%s_%s', $input->getType(), $output->getType(), md5($procedure->getTemplate()));
 
         if ($this->cacheEnabled && $this->cacheHandler->exists($cacheKey)) {
             $template = $this->cacheHandler->fetch($cacheKey);
         }
 
         if (empty($template)) {
-
-            $template  = $this->renderer
-                ->render($procedure->getTemplate(), array('engine' => $this, 'procedure_type' => $input->getType()));
+            $template = $this->renderer
+                ->render($procedure->getTemplate(), array('engine' => $this, 'procedure_type' => $output->getType()));
 
             $test = clone $procedure;
             $test->setTemplate($template);
 
-            $compiled = $test->compile($input);
+            $compiled = $test->compile($input, $output);
 
             $this->procedureValidator->validate($compiled);
 
@@ -117,8 +111,8 @@ class ProcedureCompiler implements ProcedureCompilerInterface
     /**
      * Load partial template.
      *
-     * @access public
-     * @param  string $name
+     * @param string $name
+     *
      * @return string
      */
     public function load($name)
@@ -128,9 +122,6 @@ class ProcedureCompiler implements ProcedureCompilerInterface
 
     /**
      * Enable cache.
-     *
-     * @access public
-     * @return void
      */
     public function enableCache()
     {
@@ -139,9 +130,6 @@ class ProcedureCompiler implements ProcedureCompilerInterface
 
     /**
      * Disable cache.
-     *
-     * @access public
-     * @return void
      */
     public function disableCache()
     {
@@ -150,9 +138,6 @@ class ProcedureCompiler implements ProcedureCompilerInterface
 
     /**
      * Clear cache.
-     *
-     * @access public
-     * @return void
      */
     public function clearCache()
     {

+ 9 - 15
src/JonnyW/PhantomJs/Procedure/ProcedureCompilerInterface.php → src/Procedure/ProcedureCompilerInterface.php

@@ -9,8 +9,11 @@
 
 namespace JonnyW\PhantomJs\Procedure;
 
+use JonnyW\PhantomJs\IO\InputInterface;
+use JonnyW\PhantomJs\IO\OutputInterface;
+
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -19,42 +22,33 @@ interface ProcedureCompilerInterface
     /**
      * Compile partials into procedure.
      *
-     * @access public
      * @param \JonnyW\PhantomJs\Procedure\ProcedureInterface $procedure
-     * @param \JonnyW\PhantomJs\Procedure\InputInterface     $input
+     * @param \JonnyW\PhantomJs\IO\InputInterface            $input
+     * @param \JonnyW\PhantomJs\IO\OutputInterface           $output
      */
-    public function compile(ProcedureInterface $procedure, InputInterface $input);
+    public function compile(ProcedureInterface $procedure, InputInterface $input, OutputInterface $output);
 
     /**
      * Load partial template.
      *
-     * @access public
-     * @param  string $name
+     * @param string $name
+     *
      * @return string
      */
     public function load($name);
 
     /**
      * Enable cache.
-     *
-     * @access public
-     * @return void
      */
     public function enableCache();
 
     /**
      * Disable cache.
-     *
-     * @access public
-     * @return void
      */
     public function disableCache();
 
     /**
      * Clear cache.
-     *
-     * @access public
-     * @return void
      */
     public function clearCache();
 }

+ 5 - 11
src/JonnyW/PhantomJs/Procedure/ProcedureFactory.php → src/Procedure/ProcedureFactory.php

@@ -15,17 +15,16 @@ use JonnyW\PhantomJs\Parser\ParserInterface;
 use JonnyW\PhantomJs\Template\TemplateRendererInterface;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class ProcedureFactory implements ProcedureFactoryInterface
 {
     /**
-     * PhantomJS engine
+     * PhantomJS engine.
      *
      * @var \JonnyW\PhantomJs\Engine
-     * @access protected
      */
     protected $engine;
 
@@ -33,7 +32,6 @@ class ProcedureFactory implements ProcedureFactoryInterface
      * Parser.
      *
      * @var \JonnyW\PhantomJs\Parser\ParserInterface
-     * @access protected
      */
     protected $parser;
 
@@ -41,7 +39,6 @@ class ProcedureFactory implements ProcedureFactoryInterface
      * Cache handler.
      *
      * @var \JonnyW\PhantomJs\Cache\CacheInterface
-     * @access protected
      */
     protected $cacheHandler;
 
@@ -49,14 +46,12 @@ class ProcedureFactory implements ProcedureFactoryInterface
      * Template renderer.
      *
      * @var \JonnyW\PhantomJs\Template\TemplateRendererInterface
-     * @access protected
      */
     protected $renderer;
 
     /**
      * Internal constructor.
      *
-     * @access public
      * @param \JonnyW\PhantomJs\Engine                             $engine
      * @param \JonnyW\PhantomJs\Parser\ParserInterface             $parser
      * @param \JonnyW\PhantomJs\Cache\CacheInterface               $cacheHandler
@@ -64,16 +59,15 @@ class ProcedureFactory implements ProcedureFactoryInterface
      */
     public function __construct(Engine $engine, ParserInterface $parser, CacheInterface $cacheHandler, TemplateRendererInterface $renderer)
     {
-        $this->engine       = $engine;
-        $this->parser       = $parser;
+        $this->engine = $engine;
+        $this->parser = $parser;
         $this->cacheHandler = $cacheHandler;
-        $this->renderer     = $renderer;
+        $this->renderer = $renderer;
     }
 
     /**
      * Create new procedure instance.
      *
-     * @access public
      * @return \JonnyW\PhantomJs\Procedure\Procedure
      */
     public function createProcedure()

+ 1 - 2
src/JonnyW/PhantomJs/Procedure/ProcedureFactoryInterface.php → src/Procedure/ProcedureFactoryInterface.php

@@ -10,7 +10,7 @@
 namespace JonnyW\PhantomJs\Procedure;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -19,7 +19,6 @@ interface ProcedureFactoryInterface
     /**
      * Create new procedure instance.
      *
-     * @access public
      * @return \JonnyW\PhantomJs\Procedure\ProcedureInterface
      */
     public function createProcedure();

+ 6 - 8
src/JonnyW/PhantomJs/Procedure/ProcedureInterface.php → src/Procedure/ProcedureInterface.php

@@ -6,10 +6,11 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Procedure;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -18,16 +19,14 @@ interface ProcedureInterface
     /**
      * Run procedure.
      *
-     * @access public
-     * @param \JonnyW\PhantomJs\Procedure\InputInterface  $input
-     * @param \JonnyW\PhantomJs\Procedure\OutputInterface $output
+     * @param \JonnyW\PhantomJs\IO\InputInterface  $input
+     * @param \JonnyW\PhantomJs\IO\OutputInterface $output
      */
     public function run(InputInterface $input, OutputInterface $output);
 
     /**
      * Set procedure template.
      *
-     * @access public
      * @param string $template
      */
     public function setTemplate($template);
@@ -35,7 +34,6 @@ interface ProcedureInterface
     /**
      * Get procedure template.
      *
-     * @access public
      * @return string
      */
     public function getTemplate();
@@ -43,8 +41,8 @@ interface ProcedureInterface
     /**
      * Compile procedure.
      *
-     * @access public
-     * @param  \JonnyW\PhantomJs\Procedure\InputInterface $input
+     * @param \JonnyW\PhantomJs\IO\InputInterface $input
+     *
      * @return string
      */
     public function compile(InputInterface $input);

+ 11 - 12
src/JonnyW/PhantomJs/Procedure/ProcedureLoader.php → src/Procedure/ProcedureLoader.php

@@ -6,13 +6,14 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Procedure;
 
 use Symfony\Component\Config\FileLocatorInterface;
 use JonnyW\PhantomJs\Exception\NotExistsException;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -22,7 +23,6 @@ class ProcedureLoader implements ProcedureLoaderInterface
      * Procedure factory.
      *
      * @var \JonnyW\PhantomJs\Procedure\ProcedureFactoryInterface
-     * @access protected
      */
     protected $procedureFactory;
 
@@ -30,28 +30,26 @@ class ProcedureLoader implements ProcedureLoaderInterface
      * File locator.
      *
      * @var \Symfony\Component\Config\FileLocatorInterface
-     * @access protected
      */
     protected $locator;
 
     /**
      * Internal constructor.
      *
-     * @access public
      * @param \JonnyW\PhantomJs\Procedure\ProcedureFactoryInterface $procedureFactory
      * @param \Symfony\Component\Config\FileLocatorInterface        $locator
      */
     public function __construct(ProcedureFactoryInterface $procedureFactory, FileLocatorInterface $locator)
     {
         $this->procedureFactory = $procedureFactory;
-        $this->locator          = $locator;
+        $this->locator = $locator;
     }
 
     /**
      * Load procedure instance by id.
      *
-     * @access public
-     * @param  string                                         $id
+     * @param string $id
+     *
      * @return \JonnyW\PhantomJs\Procedure\ProcedureInterface
      */
     public function load($id)
@@ -67,9 +65,9 @@ class ProcedureLoader implements ProcedureLoaderInterface
     /**
      * Load procedure template by id.
      *
-     * @access public
-     * @param  string $id
-     * @param  string $extension (default: 'proc')
+     * @param string $id
+     * @param string $extension (default: 'proc')
+     *
      * @return string
      */
     public function loadTemplate($id, $extension = 'proc')
@@ -82,9 +80,10 @@ class ProcedureLoader implements ProcedureLoaderInterface
     /**
      * Load procedure file content.
      *
-     * @access protected
-     * @param  string                                         $file
+     * @param string $file
+     *
      * @return string
+     *
      * @throws \InvalidArgumentException
      * @throws \JonnyW\PhantomJs\Exception\NotExistsException
      */

+ 7 - 8
src/JonnyW/PhantomJs/Procedure/ProcedureLoaderFactory.php → src/Procedure/ProcedureLoaderFactory.php

@@ -12,7 +12,7 @@ namespace JonnyW\PhantomJs\Procedure;
 use Symfony\Component\Config\FileLocator;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -22,14 +22,12 @@ class ProcedureLoaderFactory implements ProcedureLoaderFactoryInterface
      * Procedure factory.
      *
      * @var \JonnyW\PhantomJs\Procedure\ProcedureFactoryInterface
-     * @access protected
      */
     protected $procedureFactory;
 
     /**
      * Internal constructor.
      *
-     * @access public
      * @param \JonnyW\PhantomJs\Procedure\ProcedureFactoryInterface $procedureFactory
      */
     public function __construct(ProcedureFactoryInterface $procedureFactory)
@@ -40,14 +38,14 @@ class ProcedureLoaderFactory implements ProcedureLoaderFactoryInterface
     /**
      * Create procedure loader instance.
      *
-     * @access public
-     * @param  string                                      $directory
+     * @param string $directory
+     *
      * @return \JonnyW\PhantomJs\Procedure\ProcedureLoader
      */
     public function createProcedureLoader($directory)
     {
         $procedureFactory = $this->procedureFactory;
-        $fileLocator      = $this->createFileLocator($directory);
+        $fileLocator = $this->createFileLocator($directory);
 
         $procedureLoader = new ProcedureLoader(
             $procedureFactory,
@@ -60,9 +58,10 @@ class ProcedureLoaderFactory implements ProcedureLoaderFactoryInterface
     /**
      * Create file locator instance.
      *
-     * @access protected
-     * @param  string                                $directory
+     * @param string $directory
+     *
      * @return \Symfony\Component\Config\FileLocator
+     *
      * @throws \InvalidArgumentException
      */
     protected function createFileLocator($directory)

+ 3 - 3
src/JonnyW/PhantomJs/Procedure/ProcedureLoaderFactoryInterface.php → src/Procedure/ProcedureLoaderFactoryInterface.php

@@ -10,7 +10,7 @@
 namespace JonnyW\PhantomJs\Procedure;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -19,8 +19,8 @@ interface ProcedureLoaderFactoryInterface
     /**
      * Create procedure loader instance.
      *
-     * @access public
-     * @param  string                                               $directory
+     * @param string $directory
+     *
      * @return \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface
      */
     public function createProcedureLoader($directory);

+ 7 - 6
src/JonnyW/PhantomJs/Procedure/ProcedureLoaderInterface.php → src/Procedure/ProcedureLoaderInterface.php

@@ -6,10 +6,11 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Procedure;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -18,8 +19,8 @@ interface ProcedureLoaderInterface
     /**
      * Load procedure instance by id.
      *
-     * @access public
-     * @param  string                                         $id
+     * @param string $id
+     *
      * @return \JonnyW\PhantomJs\Procedure\ProcedureInterface
      */
     public function load($id);
@@ -27,9 +28,9 @@ interface ProcedureLoaderInterface
     /**
      * Load procedure template by id.
      *
-     * @access public
-     * @param  string $id
-     * @param  string $extension (default: 'proc')
+     * @param string $id
+     * @param string $extension (default: 'proc')
+     *
      * @return string
      */
     public function loadTemplate($id, $extension = 'proc');

+ 13 - 16
src/JonnyW/PhantomJs/Procedure/ProcedureValidator.php → src/Procedure/ProcedureValidator.php

@@ -6,6 +6,7 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Procedure;
 
 use JonnyW\PhantomJs\Validator\EngineInterface;
@@ -13,7 +14,7 @@ use JonnyW\PhantomJs\Exception\SyntaxException;
 use JonnyW\PhantomJs\Exception\RequirementException;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -23,37 +24,35 @@ class ProcedureValidator implements ProcedureValidatorInterface
      * Procedure loader.
      *
      * @var \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface
-     * @access protected
      */
     protected $procedureLoader;
 
     /**
-     * Validator engine
+     * Validator engine.
      *
      * @var \JonnyW\PhantomJs\Validator\EngineInterface
-     * @access protected
      */
     protected $engine;
 
     /**
      * Internal constructor.
      *
-     * @access public
      * @param \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $procedureLoader
      * @param \JonnyW\PhantomJs\Validator\EngineInterface          $engine
      */
     public function __construct(ProcedureLoaderInterface $procedureLoader, EngineInterface $engine)
     {
         $this->procedureLoader = $procedureLoader;
-        $this->engine          = $engine;
+        $this->engine = $engine;
     }
 
     /**
      * Validate procedure.
      *
-     * @access public
-     * @param  string                                                   $procedure
-     * @return boolean
+     * @param string $procedure
+     *
+     * @return bool
+     *
      * @throws \JonnyW\PhantomJs\Exception\ProcedureValidationException
      */
     public function validate($procedure)
@@ -67,14 +66,13 @@ class ProcedureValidator implements ProcedureValidatorInterface
     /**
      * Validate syntax.
      *
-     * @access protected
-     * @param  string                                      $procedure
-     * @return void
+     * @param string $procedure
+     *
      * @throws \JonnyW\PhantomJs\Exception\SyntaxException
      */
     protected function validateSyntax($procedure)
     {
-        $input  = new Input();
+        $input = new Input();
         $output = new Output();
 
         $input->set('procedure', $procedure);
@@ -93,9 +91,8 @@ class ProcedureValidator implements ProcedureValidatorInterface
     /**
      * validateRequirements function.
      *
-     * @access protected
-     * @param  string                                           $procedure
-     * @return void
+     * @param string $procedure
+     *
      * @throws \JonnyW\PhantomJs\Exception\RequirementException
      */
     protected function validateRequirements($procedure)

+ 6 - 4
src/JonnyW/PhantomJs/Procedure/ProcedureValidatorInterface.php → src/Procedure/ProcedureValidatorInterface.php

@@ -6,10 +6,11 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Procedure;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -18,9 +19,10 @@ interface ProcedureValidatorInterface
     /**
      * Validate procedure.
      *
-     * @access public
-     * @param  string                                                   $procedure
-     * @return boolean
+     * @param string $procedure
+     *
+     * @return bool
+     *
      * @throws \JonnyW\PhantomJs\Exception\ProcedureValidationException
      */
     public function validate($procedure);

+ 0 - 0
src/JonnyW/PhantomJs/Resources/config/config.yml → src/Resources/config/config.yml


+ 1 - 0
src/JonnyW/PhantomJs/Resources/config/services.yml → src/Resources/config/services.yml

@@ -86,6 +86,7 @@ services:
     phantomjs.http.message_factory:
         class: "%phantomjs.http.message_factory.class%"
         public: false
+        deprecated: "The '%service_id%' service is deprecated since version 4.6 and will be removed in 5.0."
 
 ################
 ### PARSING ####

+ 0 - 0
src/JonnyW/PhantomJs/Resources/procedures/global_variables.partial → src/Resources/procedures/global_variables.partial


+ 41 - 24
src/JonnyW/PhantomJs/Resources/procedures/http_lazy.proc → src/Resources/procedures/http_default.proc

@@ -34,6 +34,11 @@ var page       = require('webpage').create(),
  */
 [[ engine.load('page_viewport_size') ]]
 
+/**
+ * Define zoom factor.
+ */
+[[ engine.load('page_zoom_factor') ]]
+
 /**
  * Define custom headers.
  */
@@ -63,8 +68,10 @@ page.onResourceRequested = function (req) {
     
     [[ engine.load('page_on_resource_requested') ]]
     
-    resources++;
-    window.clearTimeout(timeout);
+    {% if output.lazy %}
+        resources++;
+        window.clearTimeout(timeout);
+    {% endif %}
 };
 
 /**
@@ -72,21 +79,23 @@ page.onResourceRequested = function (req) {
  */
 page.onResourceReceived = function (res) {
     
-    var resource = res; // To be removed in version 5.0
-    
     [[ engine.load('page_on_resource_received') ]]
     
-    if(!res.stage || res.stage === 'end') {
-        
-        resources--;
-        
-        if (resources === 0) {
+    {% if output.lazy %}
+
+        if(!res.stage || res.stage === 'end') {
+            
+            resources--;
             
-            timeout = window.setTimeout(function() {
-                procedure.execute('success');
-            }, 300);
+            if (resources === 0) {
+                
+                timeout = window.setTimeout(function() {
+                    [[ engine.load('page_open') ]]
+                }, 300);
+            }
         }
-    }
+
+    {% endif %}
 };
 
 /**
@@ -103,24 +112,32 @@ phantom.onError = function(msg, trace) {
     [[ engine.load('phantom_on_error') ]]
 };
 
+/**
+ * Execute procedure
+ */
+procedure.execute = function (status) {
+    [[ engine.load( 'procedure_' ~ output.type ) ]]
+};
+
 /**
  * Open page
  */
-page.open ('{{ input.getUrl() }}', '{{ input.getMethod() }}', '{{ input.getBody() }}', function (status) {
+page.open('{{ input.requestTarget }}', '{{ input.method }}', '{{ input.body }}', function (status) {
     
     [[ engine.load('page_body_styles') ]]
+    
+    {% if output.lazy %}
 
-    window.setTimeout(function () { 
-        procedure.execute(status); 
-    }, {{ input.getTimeout() - 200 }});
-});
+        debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Delaying page render until resources have loaded');
+        
+        window.setTimeout(function () { 
+            [[ engine.load('page_open') ]]
+        }, {{ input.timeout - 200 }});
 
-/**
- * Execute procedure
- */
-procedure.execute = function (status) {
-    [[ engine.load( 'procedure_' ~ procedure_type ) ]]
-};
+    {% else %}
+        [[ engine.load('page_open') ]]
+    {% endif %}
+});
 
 {% endautoescape %}
 [% endautoescape %]

+ 1 - 1
src/JonnyW/PhantomJs/Resources/procedures/page_body_styles.partial → src/Resources/procedures/page_body_styles.partial

@@ -1,7 +1,7 @@
 
 page.evaluate(function() {
     
-    var styles = {{ input.getBodyStyles()|json_encode(constant('JSON_FORCE_OBJECT')) }};
+    var styles = {{ output.styles|json_encode(constant('JSON_FORCE_OBJECT')) }};
     
     for(var property in styles) {
         document.body.style[property] = styles[property];

+ 9 - 0
src/Resources/procedures/page_clip_rect.partial

@@ -0,0 +1,9 @@
+
+{% if output.clipRect %}
+    
+    var clipRect = {{ output.clipRect|json_encode(constant('JSON_FORCE_OBJECT')) }};
+    
+    debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Set clipping size ~ ' + JSON.stringify(clipRect));
+    page.clipRect = clipRect;
+
+{% endif %}

+ 5 - 6
src/JonnyW/PhantomJs/Resources/procedures/page_cookies.partial → src/Resources/procedures/page_cookies.partial

@@ -1,20 +1,19 @@
 
-var cookies = {{ input.getCookies()|json_encode() }};
+var cookies = {{ input.cookies|json_encode }};
 
-cookies.delete.forEach(function(name) {
+cookies.remove.forEach(function(cookie) {
     
-    if(name == '*') {
+    if(cookie == '*') {
         page.clearCookies();
         debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Deleted all cookies');
     } else {
         
-        if(page.deleteCookie(name)) {
-            debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Deleted cookie ' + name);
+        if(page.deleteCookie(cookie)) {
+            debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Deleted cookie ' + cookie);
         }
     }
 });
 
-
 cookies.add.forEach(function(cookie) {
     
     if(page.addCookie(cookie)) {

+ 3 - 0
src/Resources/procedures/page_custom_headers.partial

@@ -0,0 +1,3 @@
+
+page.customHeaders = {{ input.headers|json_encode(constant('JSON_FORCE_OBJECT')) }};
+

+ 0 - 0
src/JonnyW/PhantomJs/Resources/procedures/page_on_error.partial → src/Resources/procedures/page_on_error.partial


+ 1 - 1
src/JonnyW/PhantomJs/Resources/procedures/page_on_resource_received.partial → src/Resources/procedures/page_on_resource_received.partial

@@ -1,5 +1,5 @@
 
 if(!response.status) {
-    response = resource;
+    response = res;
 }
 

+ 0 - 0
src/JonnyW/PhantomJs/Resources/procedures/page_on_resource_requested.partial → src/Resources/procedures/page_on_resource_requested.partial


+ 0 - 0
src/JonnyW/PhantomJs/Resources/procedures/page_on_resource_timeout.partial → src/Resources/procedures/page_on_resource_timeout.partial


+ 2 - 0
src/Resources/procedures/page_open.partial

@@ -0,0 +1,2 @@
+
+procedure.execute(status);

+ 37 - 0
src/Resources/procedures/page_paper_size.partial

@@ -0,0 +1,37 @@
+
+{% if output.paperSize %}
+    
+    var paperSize = {{ output.paperSize|json_encode(constant('JSON_FORCE_OBJECT')) }},
+        layout = paperSize.layout;
+    
+    debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Set paper size ~ ' + JSON.stringify(layout));
+    
+    {% if paperSize.header %}
+        
+        debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Set paper size header');
+        
+        layout.header = {
+            height: paperSize.header.height,
+            contents: phantom.callback(function(pageNum, pageTotal) {
+                return paperSize.header.content.replace('%pageNum%', pageNum).replace('%pageTotal%', pageTotal);
+            })
+        };
+    
+    {% endif %}
+
+    {% if paperSize.footer %}
+        
+        debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Set paper size footer');
+        
+        layout.footer = {
+            height: paperSize.footer.height,
+            contents: phantom.callback(function(pageNum, pageTotal) {
+                return paperSize.footer.content.replace('%pageNum%', pageNum).replace('%pageTotal%', pageTotal);
+            })
+        };
+        
+    {% endif %}
+    
+    page.paperSize = layout;
+
+{% endif %}

+ 1 - 1
src/JonnyW/PhantomJs/Resources/procedures/page_settings.partial → src/Resources/procedures/page_settings.partial

@@ -1,5 +1,5 @@
 
-var settings = {{ input.getSettings()|json_encode(constant('JSON_FORCE_OBJECT')) }};
+var settings = {{ input.settings|json_encode(constant('JSON_FORCE_OBJECT')) }};
 
 for(var prop in settings) {
     

+ 9 - 0
src/Resources/procedures/page_viewport_size.partial

@@ -0,0 +1,9 @@
+
+{% if output.viewportSize %}
+    
+    var viewportSize = {{ output.viewportSize|json_encode(constant('JSON_FORCE_OBJECT')) }};
+    
+    debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Set viewport size ~ ' + JSON.stringify(viewportSize));
+    page.viewportSize = viewportSize;
+    
+{% endif %}

+ 9 - 0
src/Resources/procedures/page_zoom_factor.partial

@@ -0,0 +1,9 @@
+
+{% if output.zoomFactor %}
+
+    var zoomFactor  = {{ output.zoomFactor|json_encode(constant('JSON_FORCE_OBJECT')) }};
+    
+    debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Set zoom factor ~ ' + JSON.stringify(zoomFactor));
+    page.zoomFactor = zoomFactor.zoom;
+
+{% endif %}

+ 1 - 1
src/JonnyW/PhantomJs/Resources/procedures/phantom_on_error.partial → src/Resources/procedures/phantom_on_error.partial

@@ -9,6 +9,6 @@ response.status  = 500;
 response.content = msg;
 response.console = stack;
 
-system.stdout.write(JSON.stringify(response, undefined, 4));
+system.stdout.write(JSON.stringify(response));
 phantom.exit(1);
 

+ 1 - 1
src/JonnyW/PhantomJs/Resources/procedures/procedure_default.partial → src/Resources/procedures/procedure_http.partial

@@ -17,7 +17,7 @@ if (status === 'success') {
 response.console = logs;
 
 system.stderr.write(debug.join('\\n') + '\\n');
-system.stdout.write(JSON.stringify(response, undefined, 4));
+system.stdout.write(JSON.stringify(response));
 
 phantom.exit();
 

+ 25 - 0
src/Resources/procedures/procedure_stream.partial

@@ -0,0 +1,25 @@
+
+if (status === 'success') {
+
+    try {
+
+        response.content = page.renderBuffer({
+            format: '{{ output.format }}',
+            quality: {{ output.quality }},
+        });
+        
+        page.close();
+
+    } catch(e) {
+
+        response.status  = 500;
+        response.content = e.message;
+    }
+}
+
+response.console = logs;
+
+system.stderr.write(debug.join('\\n') + '\\n');
+system.stdout.write(JSON.stringify(response));
+
+phantom.exit();

+ 55 - 8
src/JonnyW/PhantomJs/Resources/procedures/http_default.proc → src/Resources/procedures/stream_default.proc

@@ -10,7 +10,9 @@ var page       = require('webpage').create(),
     response   = {},
     debug      = [],
     logs       = [],
-    procedure  = {};
+    procedure  = {},
+    resources  = 0,
+    timeout;
 
 /**
  * Global variables
@@ -32,6 +34,11 @@ var page       = require('webpage').create(),
  */
 [[ engine.load('page_viewport_size') ]]
 
+/**
+ * Define zoom factor.
+ */
+[[ engine.load('page_zoom_factor') ]]
+
 /**
  * Define custom headers.
  */
@@ -57,15 +64,38 @@ page.onResourceTimeout = function (error) {
 /**
  * On resource requested
  */
-page.onResourceRequested = function (resource) {
+page.onResourceRequested = function (req) {
+    
     [[ engine.load('page_on_resource_requested') ]]
+    
+    {% if output.lazy %}
+        resources++;
+        window.clearTimeout(timeout);
+    {% endif %}
 };
 
 /**
  * On resource received
  */
-page.onResourceReceived = function (resource) {
+page.onResourceReceived = function (res) {
+    
     [[ engine.load('page_on_resource_received') ]]
+    
+    {% if output.lazy %}
+
+        if(!res.stage || res.stage === 'end') {
+            
+            resources--;
+            
+            if (resources === 0) {
+                
+                timeout = window.setTimeout(function() {
+                    [[ engine.load('page_open') ]]
+                }, 300);
+            }
+        }
+
+    {% endif %}
 };
 
 /**
@@ -83,19 +113,36 @@ phantom.onError = function(msg, trace) {
 };
 
 /**
- * Open page
+ * On load finished
  */
-page.open ('{{ input.getUrl() }}', '{{ input.getMethod() }}', '{{ input.getBody() }}', function (status) {
+page.onLoadFinished = function(status) {
+    
     [[ engine.load('page_body_styles') ]]
-    [[ engine.load('page_open') ]]
-});
+    
+    {% if output.lazy %}
+
+        debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Delaying page render until resources have loaded');
+        
+        window.setTimeout(function () { 
+            [[ engine.load('page_open') ]]
+        }, {{ input.timeout - 200 }});
+
+    {% else %}
+        [[ engine.load('page_open') ]]
+    {% endif %}
+};
 
 /**
  * Execute procedure
  */
 procedure.execute = function (status) {
-    [[ engine.load( 'procedure_' ~ procedure_type ) ]]
+    [[ engine.load( 'procedure_' ~ output.type ) ]]
 };
 
+/**
+ * Set page content
+ */
+page.setContent('{{ input.body }}');
+
 {% endautoescape %}
 [% endautoescape %]

+ 2 - 2
src/JonnyW/PhantomJs/Resources/procedures/validator.proc → src/Resources/procedures/validator.proc

@@ -1,4 +1,4 @@
-{% autoescape false %}
+ {% autoescape false %}
 
 {{ input.get('engine') }}
 
@@ -21,7 +21,7 @@ try {
 }
 
 system.stdout.write(
-  JSON.stringify(syntax, undefined, 4)
+  JSON.stringify(syntax)
 );
 
 phantom.exit();

+ 0 - 0
src/JonnyW/PhantomJs/Resources/validators/esprima-2.0.0.js → src/Resources/validators/esprima-2.0.0.js


+ 6 - 4
src/JonnyW/PhantomJs/StringUtils.php → src/StringUtils.php

@@ -6,21 +6,23 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 final class StringUtils
 {
     /**
-     * Generate random string
+     * Generate random string.
      *
      * @static
-     * @access public
-     * @param  int    $length (default: 20)
+     *
+     * @param int $length (default: 20)
+     *
      * @return string
      */
     public static function random($length = 20)

+ 5 - 6
src/JonnyW/PhantomJs/Template/TemplateRenderer.php → src/Template/TemplateRenderer.php

@@ -6,10 +6,11 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Template;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -19,14 +20,12 @@ class TemplateRenderer implements TemplateRendererInterface
      * Twig environment instance.
      *
      * @var \Twig_Environment
-     * @access protected
      */
     protected $twig;
 
     /**
      * Internal constructor.
      *
-     * @access public
      * @param \Twig_Environment $twig
      */
     public function __construct(\Twig_Environment $twig)
@@ -37,9 +36,9 @@ class TemplateRenderer implements TemplateRendererInterface
     /**
      * Render template.
      *
-     * @access public
-     * @param  string $template
-     * @param  array  $context  (default: array())
+     * @param string $template
+     * @param array  $context  (default: array())
+     *
      * @return string
      */
     public function render($template, array $context = array())

+ 5 - 4
src/JonnyW/PhantomJs/Template/TemplateRendererInterface.php → src/Template/TemplateRendererInterface.php

@@ -6,10 +6,11 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Template;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -18,9 +19,9 @@ interface TemplateRendererInterface
     /**
      * Render template.
      *
-     * @access public
-     * @param  string $template
-     * @param  array  $context  (default: array())
+     * @param string $template
+     * @param array  $context  (default: array())
+     *
      * @return string
      */
     public function render($template, array $context = array());

+ 2 - 2
src/JonnyW/PhantomJs/Test/TestCase.php → src/Test/TestCase.php

@@ -6,12 +6,13 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Test;
 
 use JonnyW\PhantomJs\DependencyInjection\ServiceContainer;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
@@ -20,7 +21,6 @@ class TestCase extends \PHPUnit_Framework_TestCase
     /**
      * Get dependency injection container.
      *
-     * @access public
      * @return \JonnyW\PhantomJs\DependencyInjection\ServiceContainer
      */
     public function getContainer()

+ 111 - 228
src/JonnyW/PhantomJs/Tests/Integration/ClientTest.php → src/Tests/Integration/ClientTest.php

@@ -6,6 +6,7 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Tests\Integration;
 
 use JonnyW\PhantomJs\Test\TestCase;
@@ -13,38 +14,33 @@ use JonnyW\PhantomJs\Client;
 use JonnyW\PhantomJs\DependencyInjection\ServiceContainer;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class ClientTest extends TestCase
 {
     /**
-     * Test filename
+     * Test filename.
      *
      * @var string
-     * @access protected
      */
     protected $filename;
 
     /**
-     * Test directory
+     * Test directory.
      *
      * @var string
-     * @access protected
      */
     protected $directory;
 
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++++++ TESTS ++++++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++++++ TESTS ++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Test additional procedures can be loaded
      * through chain loader.
-     *
-     * @access public
-     * @return void
      */
     public function testAdditionalProceduresCanBeLoadedThroughChainLoader()
     {
@@ -58,13 +54,13 @@ EOF;
         $this->writeProcedure($procedure);
 
         $procedureLoaderFactory = $this->getContainer()->get('procedure_loader_factory');
-        $procedureLoader        = $procedureLoaderFactory->createProcedureLoader($this->directory);
+        $procedureLoader = $procedureLoaderFactory->createProcedureLoader($this->directory);
 
         $client = $this->getClient();
         $client->setProcedure('test');
         $client->getProcedureLoader()->addLoader($procedureLoader);
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $client->send($request, $response);
@@ -75,10 +71,7 @@ EOF;
     /**
      * Test additional procedures can be loaded
      * through chain loader if procedures
-     * contain comments
-     *
-     * @access public
-     * @return void
+     * contain comments.
      */
     public function testAdditionalProceduresCanBeLoadedThroughChainLoaderIfProceduresContainComments()
     {
@@ -96,13 +89,13 @@ EOF;
         $this->writeProcedure($procedure);
 
         $procedureLoaderFactory = $this->getContainer()->get('procedure_loader_factory');
-        $procedureLoader        = $procedureLoaderFactory->createProcedureLoader($this->directory);
+        $procedureLoader = $procedureLoaderFactory->createProcedureLoader($this->directory);
 
         $client = $this->getClient();
         $client->setProcedure('test');
         $client->getProcedureLoader()->addLoader($procedureLoader);
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $client->send($request, $response);
@@ -113,9 +106,6 @@ EOF;
     /**
      * Test syntax exception is thrown if request
      * procedure contains syntax error.
-     *
-     * @access public
-     * @return void
      */
     public function testSyntaxExceptionIsThrownIfRequestProcedureContainsSyntaxError()
     {
@@ -123,20 +113,20 @@ EOF;
 
         $content = 'TEST_PROCEDURE';
 
-        $procedure = <<<EOF
+        $procedure = <<<'EOF'
     console.log(;
 EOF;
 
         $this->writeProcedure($procedure);
 
         $procedureLoaderFactory = $this->getContainer()->get('procedure_loader_factory');
-        $procedureLoader        = $procedureLoaderFactory->createProcedureLoader($this->directory);
+        $procedureLoader = $procedureLoaderFactory->createProcedureLoader($this->directory);
 
         $client = $this->getClient();
         $client->setProcedure('test');
         $client->getProcedureLoader()->addLoader($procedureLoader);
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $client->send($request, $response);
@@ -145,15 +135,12 @@ EOF;
     /**
      * Test response contains 200 status code if page
      * is successfully loaded.
-     *
-     * @access public
-     * @return void
      */
     public function testResponseContains200StatusCodeIfPageIsSuccessfullyLoaded()
     {
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -167,22 +154,19 @@ EOF;
     /**
      * Test response contains 200 status code if
      * request URL contains reserved characters.
-     *
-     * @access public
-     * @return void
      */
     public function testResponseContains200StatusCodeIfRequestUrlContainsReservedCharacters()
     {
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
         $request->setUrl('http://www.jonnyw.kiwi/tests/test-default.php');
         $request->setRequestData(array(
             'test1' => 'http://test.com',
-            'test2' => 'A string with an \' ) / # some other invalid [ characters.'
+            'test2' => 'A string with an \' ) / # some other invalid [ characters.',
         ));
 
         $client->send($request, $response);
@@ -193,15 +177,12 @@ EOF;
     /**
      * Test response contains valid body if page is
      * successfully loaded.
-     *
-     * @access public
-     * @return void
      */
     public function testResponseContainsValidBodyIfPageIsSuccessfullyLoaded()
     {
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -213,16 +194,13 @@ EOF;
     }
 
     /**
-     * Test can set user agent in settings
-     *
-     * @access public
-     * @return void
+     * Test can set user agent in settings.
      */
     public function testCanSetUserAgentInSettings()
     {
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -235,16 +213,13 @@ EOF;
     }
 
     /**
-     * Test can add cookies to request
-     *
-     * @access public
-     * @return void
+     * Test can add cookies to request.
      */
     public function testCanAddCookiesToRequest()
     {
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -258,20 +233,17 @@ EOF;
 
     /**
      * Test can load cookies from
-     * persistent cookie file
-     *
-     * @access public
-     * @return void
+     * persistent cookie file.
      */
     public function testCanLoadCookiesFromPersistentCookieFile()
     {
         $this->filename = 'cookies.txt';
-        $file = ($this->directory . '/' . $this->filename);
+        $file = ($this->directory.'/'.$this->filename);
 
         $client = $this->getClient();
-        $client->getEngine()->addOption('--cookies-file=' . $file);
+        $client->getEngine()->addOption('--cookies-file='.$file);
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $expireAt = strtotime('16-Nov-2020 00:00:00');
@@ -287,20 +259,17 @@ EOF;
 
     /**
      * Test can delete cookie from
-     * persistent cookie file
-     *
-     * @access public
-     * @return void
+     * persistent cookie file.
      */
     public function testCanDeleteCookieFromPersistentCookieFile()
     {
         $this->filename = 'cookies.txt';
-        $file = ($this->directory . '/' . $this->filename);
+        $file = ($this->directory.'/'.$this->filename);
 
         $client = $this->getClient();
-        $client->getEngine()->addOption('--cookies-file=' . $file);
+        $client->getEngine()->addOption('--cookies-file='.$file);
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $expireAt = strtotime('16-Nov-2020 00:00:00');
@@ -323,20 +292,17 @@ EOF;
 
     /**
      * Test can delete all cookies from
-     * persistent cookie file
-     *
-     * @access public
-     * @return void
+     * persistent cookie file.
      */
     public function testCanDeleteAllCookiesFromPersistentCookieFile()
     {
         $this->filename = 'cookies.txt';
-        $file = ($this->directory . '/' . $this->filename);
+        $file = ($this->directory.'/'.$this->filename);
 
         $client = $this->getClient();
-        $client->getEngine()->addOption('--cookies-file=' . $file);
+        $client->getEngine()->addOption('--cookies-file='.$file);
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $expireAt = strtotime('16-Nov-2020 00:00:00');
@@ -362,15 +328,12 @@ EOF;
     /**
      * Test response contains console error if a
      * javascript error exists on the page.
-     *
-     * @access public
-     * @return void
      */
     public function testResponseContainsConsoleErrorIfAJavascriptErrorExistsOnThePage()
     {
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -387,15 +350,12 @@ EOF;
     /**
      * Test response contains console trace if a
      * javascript error exists on the page.
-     *
-     * @access public
-     * @return void
      */
     public function testResponseContainsConsoleTraceIfAJavascriptErrorExistsOnThePage()
     {
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -410,15 +370,12 @@ EOF;
 
     /**
      * Test response contains headers.
-     *
-     * @access public
-     * @return void
      */
     public function testResponseContainsHeaders()
     {
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -432,15 +389,12 @@ EOF;
     /**
      * Test redirect URL is set in response
      * if request is redirected.
-     *
-     * @access public
-     * @return void
      */
     public function testRedirectUrlIsSetInResponseIfRequestIsRedirected()
     {
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -453,22 +407,19 @@ EOF;
 
     /**
      * Test POST request sends request data.
-     *
-     * @access public
-     * @return void
      */
     public function testPostRequestSendsRequestData()
     {
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('POST');
         $request->setUrl('http://www.jonnyw.kiwi/tests/test-post.php');
         $request->setRequestData(array(
             'test1' => 'http://test.com',
-            'test2' => 'A string with an \' ) / # some other invalid [ characters.'
+            'test2' => 'A string with an \' ) / # some other invalid [ characters.',
         ));
 
         $client->send($request, $response);
@@ -480,18 +431,15 @@ EOF;
     /**
      * Test capture request saves file to
      * to local disk.
-     *
-     * @access public
-     * @return void
      */
     public function testCaptureRequestSavesFileToLocalDisk()
     {
         $this->filename = 'test.jpg';
-        $file = ($this->directory . '/' . $this->filename);
+        $file = ($this->directory.'/'.$this->filename);
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createCaptureRequest();
+        $request = $client->getMessageFactory()->createCaptureRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -506,21 +454,18 @@ EOF;
     /**
      * Test capture request saves file to
      * disk with correct capture dimensions.
-     *
-     * @access public
-     * @return void
      */
     public function testCaptureRequestSavesFileToDiskWithCorrectCaptureDimensions()
     {
         $this->filename = 'test.jpg';
-        $file = ($this->directory . '/' . $this->filename);
+        $file = ($this->directory.'/'.$this->filename);
 
-        $width  = 200;
+        $width = 200;
         $height = 400;
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createCaptureRequest();
+        $request = $client->getMessageFactory()->createCaptureRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -539,18 +484,15 @@ EOF;
     /**
      * Test PDF request saves pdf to
      * to local disk.
-     *
-     * @access public
-     * @return void
      */
     public function testPdfRequestSavesPdfToLocalDisk()
     {
         $this->filename = 'test.pdf';
-        $file = ($this->directory . '/' . $this->filename);
+        $file = ($this->directory.'/'.$this->filename);
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createPdfRequest();
+        $request = $client->getMessageFactory()->createPdfRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -565,21 +507,18 @@ EOF;
     /**
      * Test PDF request saves file to
      * disk with correct paper size.
-     *
-     * @access public
-     * @return void
      */
     public function testPdfRequestSavesFileToDiskWithCorrectPaperSize()
     {
         $this->filename = 'test.pdf';
-        $file = ($this->directory . '/' . $this->filename);
+        $file = ($this->directory.'/'.$this->filename);
 
-        $width  = 20;
+        $width = 20;
         $height = 30;
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createPdfRequest();
+        $request = $client->getMessageFactory()->createPdfRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -592,8 +531,8 @@ EOF;
 
         $pdf = \ZendPdf\PdfDocument::load($file);
 
-        $pdfWidth  = round(($pdf->pages[0]->getWidth() * 0.0352777778));
-        $pdfHeight = round(($pdf->pages[0]->getHeight()  * 0.0352777778));
+        $pdfWidth = round(($pdf->pages[0]->getWidth() * 0.0352777778));
+        $pdfHeight = round(($pdf->pages[0]->getHeight() * 0.0352777778));
 
         $this->assertEquals($width, $pdfWidth);
         $this->assertEquals($height, $pdfHeight);
@@ -602,18 +541,15 @@ EOF;
     /**
      * Test PDF request saves file to
      * disk with correct format size.
-     *
-     * @access public
-     * @return void
      */
     public function testPdfRequestSavesFileToDiskWithCorrectFormatSize()
     {
         $this->filename = 'test.pdf';
-        $file = ($this->directory . '/' . $this->filename);
+        $file = ($this->directory.'/'.$this->filename);
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createPdfRequest();
+        $request = $client->getMessageFactory()->createPdfRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -626,8 +562,8 @@ EOF;
 
         $pdf = \ZendPdf\PdfDocument::load($file);
 
-        $pdfWidth  = round(($pdf->pages[0]->getWidth() * 0.0352777778));
-        $pdfHeight = round(($pdf->pages[0]->getHeight()  * 0.0352777778));
+        $pdfWidth = round(($pdf->pages[0]->getWidth() * 0.0352777778));
+        $pdfHeight = round(($pdf->pages[0]->getHeight() * 0.0352777778));
 
         $this->assertEquals(21, $pdfWidth);
         $this->assertEquals(30, $pdfHeight);
@@ -636,18 +572,15 @@ EOF;
     /**
      * Test PDF request saves file to
      * disk with correct orientation.
-     *
-     * @access public
-     * @return void
      */
     public function testPdfRequestSavesFileToDiskWithCorrectOrientation()
     {
         $this->filename = 'test.pdf';
-        $file = ($this->directory . '/' . $this->filename);
+        $file = ($this->directory.'/'.$this->filename);
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createPdfRequest();
+        $request = $client->getMessageFactory()->createPdfRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -661,8 +594,8 @@ EOF;
 
         $pdf = \ZendPdf\PdfDocument::load($file);
 
-        $pdfWidth  = round(($pdf->pages[0]->getWidth() * 0.0352777778));
-        $pdfHeight = round(($pdf->pages[0]->getHeight()  * 0.0352777778));
+        $pdfWidth = round(($pdf->pages[0]->getWidth() * 0.0352777778));
+        $pdfHeight = round(($pdf->pages[0]->getHeight() * 0.0352777778));
 
         $this->assertEquals(30, $pdfWidth);
         $this->assertEquals(21, $pdfHeight);
@@ -670,19 +603,16 @@ EOF;
 
     /**
      * Test can set repeating header
-     * for PDF request
-     *
-     * @access public
-     * @return void
+     * for PDF request.
      */
     public function testCanSetRepeatingHeaderForPDFRequest()
     {
         $this->filename = 'test.pdf';
-        $file = ($this->directory . '/' . $this->filename);
+        $file = ($this->directory.'/'.$this->filename);
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createPdfRequest();
+        $request = $client->getMessageFactory()->createPdfRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -697,7 +627,7 @@ EOF;
         $client->send($request, $response);
 
         $parser = new \Smalot\PdfParser\Parser();
-        $pdf    = $parser->parseFile($file);
+        $pdf = $parser->parseFile($file);
 
         $text = str_replace(' ', '', $pdf->getText());
 
@@ -706,19 +636,16 @@ EOF;
 
     /**
      * Test can set repeating footer
-     * for PDF request
-     *
-     * @access public
-     * @return void
+     * for PDF request.
      */
     public function testCanSetRepeatingFooterForPDFRequest()
     {
         $this->filename = 'test.pdf';
-        $file = ($this->directory . '/' . $this->filename);
+        $file = ($this->directory.'/'.$this->filename);
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createPdfRequest();
+        $request = $client->getMessageFactory()->createPdfRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -733,7 +660,7 @@ EOF;
         $client->send($request, $response);
 
         $parser = new \Smalot\PdfParser\Parser();
-        $pdf    = $parser->parseFile($file);
+        $pdf = $parser->parseFile($file);
 
         $text = str_replace(' ', '', $pdf->getText());
 
@@ -744,18 +671,15 @@ EOF;
      * Test set viewport size sets
      * size of viewport in default
      * request.
-     *
-     * @access public
-     * @return void
      */
     public function testSetViewportSizeSetsSizeOfViewportInDefaultRequest()
     {
-        $width  = 100;
+        $width = 100;
         $height = 200;
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -775,18 +699,15 @@ EOF;
      * Test set viewport size sets
      * size of viewport in capture
      * request.
-     *
-     * @access public
-     * @return void
      */
     public function testSetViewportSizeSetsSizeOfViewportInCaptureRequest()
     {
-        $width  = 100;
+        $width = 100;
         $height = 200;
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createCaptureRequest();
+        $request = $client->getMessageFactory()->createCaptureRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -805,9 +726,6 @@ EOF;
     /**
      * Test delay logs start time
      * in client for default request.
-     *
-     * @access public
-     * @return void
      */
     public function testDelayLogsStartTimeInClientForDefaultRequest()
     {
@@ -815,7 +733,7 @@ EOF;
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -834,9 +752,6 @@ EOF;
     /**
      * Test delay logs end time
      * in client for default request.
-     *
-     * @access public
-     * @return void
      */
     public function testDelayLogsEndTimeInClientForDefaultRequest()
     {
@@ -844,7 +759,7 @@ EOF;
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -863,9 +778,6 @@ EOF;
     /**
      * Test delay delays page render for
      * specified time for default request.
-     *
-     * @access public
-     * @return void
      */
     public function testDelayDelaysPageRenderForSpecifiedTimeForDefaultRequest()
     {
@@ -873,7 +785,7 @@ EOF;
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -882,23 +794,20 @@ EOF;
 
         $client->send($request, $response);
 
-        $logs = explode("\\n", $client->getLog());
+        $logs = explode('\\n', $client->getLog());
 
         $startIndex = $this->getLogEntryIndex($logs, 'Delaying page render for');
-        $endIndex   = $this->getLogEntryIndex($logs, 'Rendering page after');
+        $endIndex = $this->getLogEntryIndex($logs, 'Rendering page after');
 
-        $startTime = strtotime(substr($logs[$startIndex], 0 , 19));
-        $endTime   = strtotime(substr($logs[$endIndex], 0 , 19));
+        $startTime = strtotime(substr($logs[$startIndex], 0, 19));
+        $endTime = strtotime(substr($logs[$endIndex], 0, 19));
 
-        $this->assertSame(($startTime+$delay), $endTime);
+        $this->assertSame(($startTime + $delay), $endTime);
     }
 
     /**
      * Test delay logs start time
      * in client for capture request.
-     *
-     * @access public
-     * @return void
      */
     public function testDelayLogsStartTimeInClientForCaptureRequest()
     {
@@ -906,7 +815,7 @@ EOF;
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createCaptureRequest();
+        $request = $client->getMessageFactory()->createCaptureRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -915,7 +824,7 @@ EOF;
 
         $client->send($request, $response);
 
-        $logs = explode("\\n", $client->getLog());
+        $logs = explode('\\n', $client->getLog());
 
         $startIndex = $this->getLogEntryIndex($logs, 'Delaying page render for');
 
@@ -925,9 +834,6 @@ EOF;
     /**
      * Test delay logs end time
      * in client for capture request.
-     *
-     * @access public
-     * @return void
      */
     public function testDelayLogsEndTimeInClientForCaptureRequest()
     {
@@ -935,7 +841,7 @@ EOF;
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createCaptureRequest();
+        $request = $client->getMessageFactory()->createCaptureRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -944,7 +850,7 @@ EOF;
 
         $client->send($request, $response);
 
-        $logs = explode("\\n", $client->getLog());
+        $logs = explode('\\n', $client->getLog());
 
         $endIndex = $this->getLogEntryIndex($logs, 'Rendering page after');
 
@@ -954,9 +860,6 @@ EOF;
     /**
      * Test delay delays page render for
      * specified time for capture request.
-     *
-     * @access public
-     * @return void
      */
     public function testDelayDelaysPageRenderForSpecifiedTimeForCaptureRequest()
     {
@@ -964,7 +867,7 @@ EOF;
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createCaptureRequest();
+        $request = $client->getMessageFactory()->createCaptureRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -973,30 +876,27 @@ EOF;
 
         $client->send($request, $response);
 
-        $logs = explode("\\n", $client->getLog());
+        $logs = explode('\\n', $client->getLog());
 
         $startIndex = $this->getLogEntryIndex($logs, 'Delaying page render for');
-        $endIndex   = $this->getLogEntryIndex($logs, 'Rendering page after');
+        $endIndex = $this->getLogEntryIndex($logs, 'Rendering page after');
 
-        $startTime = strtotime(substr($logs[$startIndex], 0 , 19));
-        $endTime   = strtotime(substr($logs[$endIndex], 0 , 19));
+        $startTime = strtotime(substr($logs[$startIndex], 0, 19));
+        $endTime = strtotime(substr($logs[$endIndex], 0, 19));
 
-        $this->assertSame(($startTime+$delay), $endTime);
+        $this->assertSame(($startTime + $delay), $endTime);
     }
 
     /**
      * Test lazy request returns content after
-     * all resources are loaded
-     *
-     * @access public
-     * @return void
+     * all resources are loaded.
      */
     public function testLazyRequestReturnsResourcesAfterAllResourcesAreLoaded()
     {
         $client = $this->getClient();
         $client->isLazy();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -1011,17 +911,14 @@ EOF;
     /**
      * Test content is returned for lazy request
      * if timeout is reached before resource is
-     * loaded
-     *
-     * @access public
-     * @return void
+     * loaded.
      */
     public function testContentIsReturnedForLazyRequestIfTimeoutIsReachedBeforeResourceIsLoaded()
     {
         $client = $this->getClient();
         $client->isLazy();
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -1036,16 +933,13 @@ EOF;
     /**
      * Test debug logs debug info to
      * client log.
-     *
-     * @access public
-     * @return void
      */
     public function testDebugLogsDebugInfoToClientLog()
     {
         $client = $this->getClient();
         $client->getEngine()->debug(true);
 
-        $request  = $client->getMessageFactory()->createRequest();
+        $request = $client->getMessageFactory()->createRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -1058,19 +952,16 @@ EOF;
 
     /**
      * Test test can set page
-     * background color
-     *
-     * @access public
-     * @return void
+     * background color.
      */
     public function testCanSetPageBackgroundColor()
     {
         $this->filename = 'test.jpg';
-        $file = ($this->directory . '/' . $this->filename);
+        $file = ($this->directory.'/'.$this->filename);
 
         $client = $this->getClient();
 
-        $request  = $client->getMessageFactory()->createCaptureRequest();
+        $request = $client->getMessageFactory()->createCaptureRequest();
         $response = $client->getMessageFactory()->createResponse();
 
         $request->setMethod('GET');
@@ -1083,9 +974,9 @@ EOF;
         $this->assertContains('body style="background-color: red;"', $response->getContent());
     }
 
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++ TEST ENTITIES ++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++ TEST ENTITIES ++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Get client instance.
@@ -1106,19 +997,16 @@ EOF;
         return $client;
     }
 
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++++ UTILITIES ++++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++++ UTILITIES ++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Set up test environment.
-     *
-     * @access public
-     * @return void
      */
     public function setUp()
     {
-        $this->filename  = 'test.proc';
+        $this->filename = 'test.proc';
         $this->directory = sys_get_temp_dir();
 
         if (!is_writable($this->directory)) {
@@ -1128,9 +1016,6 @@ EOF;
 
     /**
      * Tear down test environment.
-     *
-     * @access public
-     * @return void
      */
     public function tearDown()
     {
@@ -1144,7 +1029,6 @@ EOF;
     /**
      * Get test filename.
      *
-     * @access public
      * @return string
      */
     public function getFilename()
@@ -1155,8 +1039,8 @@ EOF;
     /**
      * Write procedure body to file.
      *
-     * @access public
-     * @param  string $data
+     * @param string $data
+     *
      * @return string
      */
     public function writeProcedure($procedure)
@@ -1171,15 +1055,14 @@ EOF;
     /**
      * Get log entry index.
      *
-     * @access public
-     * @param  array     $logs
-     * @param  string    $search
+     * @param array  $logs
+     * @param string $search
+     *
      * @return int|false
      */
     public function getLogEntryIndex(array $logs, $search)
     {
         foreach ($logs as $index => $log) {
-
             $pos = stripos($log, $search);
 
             if ($pos !== false) {

+ 16 - 43
src/JonnyW/PhantomJs/Tests/Integration/Procedure/ProcedureCompilerTest.php → src/Tests/Integration/Procedure/ProcedureCompilerTest.php

@@ -6,6 +6,7 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Tests\Integration\Procedure;
 
 use JonnyW\PhantomJs\Http\Request;
@@ -13,22 +14,18 @@ use JonnyW\PhantomJs\Procedure\ProcedureCompiler;
 use JonnyW\PhantomJs\DependencyInjection\ServiceContainer;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class ProcedureCompilerTest extends \PHPUnit_Framework_TestCase
 {
-
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++++++ TESTS ++++++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++++++ TESTS ++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
-     * Test can compile procedure
-     *
-     * @access public
-     * @return void
+     * Test can compile procedure.
      */
     public function testCanCompileProcedure()
     {
@@ -48,9 +45,6 @@ class ProcedureCompilerTest extends \PHPUnit_Framework_TestCase
     /**
      * Test procedure is loaded from cache
      * if cache is enabled.
-     *
-     * @access public
-     * @return void
      */
     public function testProcedureIsLoadedFromCacheIfCacheIsEnabled()
     {
@@ -82,9 +76,6 @@ class ProcedureCompilerTest extends \PHPUnit_Framework_TestCase
     /**
      * Test procedure is not loaded from
      * cache if cache is disabled.
-     *
-     * @access public
-     * @return void
      */
     public function testProcedureIsNotLoadedFromCacheIfCacheIsDisabled()
     {
@@ -115,9 +106,6 @@ class ProcedureCompilerTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test procedure cache can be cleared.
-     *
-     * @access public
-     * @return void
      */
     public function testProcedureCacheCanBeCleared()
     {
@@ -149,15 +137,12 @@ class ProcedureCompilerTest extends \PHPUnit_Framework_TestCase
     /**
      * Test syntax exception is thrown if compiled
      * template is not valid.
-     *
-     * @access public
-     * @return void
      */
     public function testSyntaxExceptionIsThrownIfCompiledTemplateIsNotValid()
     {
         $this->setExpectedException('\JonnyW\PhantomJs\Exception\SyntaxException');
 
-        $template = <<<EOF
+        $template = <<<'EOF'
     console.log(;
 EOF;
         $procedure = $this->getProcedure('http_default');
@@ -168,17 +153,15 @@ EOF;
 
         $compiler = $this->getProcedureCompiler();
         $compiler->compile($procedure, $request);
-
     }
 
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++ TEST ENTITIES ++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++ TEST ENTITIES ++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Get procedure compiler.
      *
-     * @access protected
      * @return \JonnyW\PhantomJs\Procedure\ProcedureCompiler
      */
     protected function getProcedureCompiler()
@@ -198,8 +181,8 @@ EOF;
     /**
      * getProcedure function.
      *
-     * @access protected
-     * @param  string                                         $id
+     * @param string $id
+     *
      * @return \JonnyW\PhantomJs\Procedure\ProcedureInterface
      */
     protected function getProcedure($id)
@@ -208,9 +191,8 @@ EOF;
     }
 
     /**
-     * Get request
+     * Get request.
      *
-     * @access protected
      * @return \JonnyW\PhantomJs\Http\Request
      */
     protected function getRequest()
@@ -220,15 +202,12 @@ EOF;
         return $request;
     }
 
-/** +++++++++++++++++++++++++++++++ **/
-/** ++++++++++ UTILITIES ++++++++++ **/
-/** +++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++ **/
+    /** ++++++++++ UTILITIES ++++++++++ **/
+    /** +++++++++++++++++++++++++++++++ **/
 
     /**
      * Set up tasks.
-     *
-     * @access protected
-     * @return void
      */
     protected function setUp()
     {
@@ -239,9 +218,6 @@ EOF;
 
     /**
      * Tear down tasks.
-     *
-     * @access protected
-     * @return void
      */
     protected function tearDown()
     {
@@ -252,9 +228,6 @@ EOF;
 
     /**
      * Clean up cache files.
-     *
-     * @access protected
-     * @return void
      */
     protected function cleanup()
     {

+ 17 - 36
src/JonnyW/PhantomJs/Tests/Integration/Procedure/ProcedureValidatorTest.php → src/Tests/Integration/Procedure/ProcedureValidatorTest.php

@@ -6,6 +6,7 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Tests\Integration\Procedure;
 
 use Symfony\Component\Config\FileLocator;
@@ -17,31 +18,27 @@ use JonnyW\PhantomJs\Validator\Esprima;
 use JonnyW\PhantomJs\Validator\EngineInterface;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class ProcedureValidatorTest extends \PHPUnit_Framework_TestCase
 {
-
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++++++ TESTS ++++++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++++++ TESTS ++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Test syntax exception is
      * thrown if procedure contains
      * syntax error.
-     *
-     * @access public
-     * @return void
      */
     public function testProcedureSyntaxExceptionIsThrownIfProcedureContainsSyntaxError()
     {
         $this->setExpectedException('\JonnyW\PhantomJs\Exception\SyntaxException');
 
         $procedureLoader = $this->getProcedureLoader();
-        $esprima         = $this->getEsprima();
+        $esprima = $this->getEsprima();
 
         $validator = $this->getValidator($procedureLoader, $esprima);
         $validator->validate('return false; var');
@@ -49,20 +46,15 @@ class ProcedureValidatorTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test syntax exception contains errors.
-     *
-     * @access public
-     * @return void
      */
     public function testSyntaxExceptionContainsErrors()
     {
         $procedureLoader = $this->getProcedureLoader();
-        $esprima         = $this->getEsprima();
+        $esprima = $this->getEsprima();
 
         try {
-
             $validator = $this->getValidator($procedureLoader, $esprima);
             $validator->validate('return false; var');
-
         } catch (\JonnyW\PhantomJs\Exception\SyntaxException $e) {
             $this->assertNotEmpty($e->getErrors());
         }
@@ -72,31 +64,25 @@ class ProcedureValidatorTest extends \PHPUnit_Framework_TestCase
      * Test requirement exception is thrown
      * if procedure does not contain phantom
      * exit statement.
-     *
-     * @access public
-     * @return void
      */
     public function testRequirementExceptionIsThrownIfProcedureDoesNotContainPhanomtExitStatement()
     {
         $this->setExpectedException('\JonnyW\PhantomJs\Exception\RequirementException');
 
         $procedureLoader = $this->getProcedureLoader();
-        $esprima         = $this->getEsprima();
+        $esprima = $this->getEsprima();
 
         $validator = $this->getValidator($procedureLoader, $esprima);
         $validator->validate('var test = function () { console.log("ok"); }');
     }
 
     /**
-     * Test true is returned if procedure is valid
-     *
-     * @access public
-     * @return void
+     * Test true is returned if procedure is valid.
      */
     public function testTrueIsReturnedIfProcedureIsValid()
     {
         $procedureLoader = $this->getProcedureLoader();
-        $esprima         = $this->getEsprima();
+        $esprima = $this->getEsprima();
 
         $validator = $this->getValidator($procedureLoader, $esprima);
 
@@ -106,30 +92,27 @@ class ProcedureValidatorTest extends \PHPUnit_Framework_TestCase
     /**
      * Test procedure is valid if procedure
      * has comments.
-     *
-     * @access public
-     * @return void
      */
     public function testProcedureIsValidIfProcedureHasComments()
     {
         $procedureLoader = $this->getProcedureLoader();
-        $esprima         = $this->getEsprima();
+        $esprima = $this->getEsprima();
 
         $validator = $this->getValidator($procedureLoader, $esprima);
 
         $this->assertTrue($validator->validate('/** * Test comment **/ var test = function () { console.log("ok"); }; phantom.exit(1);'));
     }
 
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++ TEST ENTITIES ++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++ TEST ENTITIES ++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Get procedure validator.
      *
-     * @access protected
-     * @param  \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $procedureLoader
-     * @param  \JonnyW\PhantomJs\Validator\EngineInterface          $engine
+     * @param \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $procedureLoader
+     * @param \JonnyW\PhantomJs\Validator\EngineInterface          $engine
+     *
      * @return \JonnyW\PhantomJs\Procedure\ProcedureValidator
      */
     protected function getValidator(ProcedureLoaderInterface $procedureLoader, EngineInterface $engine)
@@ -142,7 +125,6 @@ class ProcedureValidatorTest extends \PHPUnit_Framework_TestCase
     /**
      * Get procedure loader.
      *
-     * @access protected
      * @return \JonnyW\PhantomJs\Procedure\ProcedureLoader
      */
     protected function getProcedureLoader()
@@ -153,7 +135,6 @@ class ProcedureValidatorTest extends \PHPUnit_Framework_TestCase
     /**
      * Get esprima.
      *
-     * @access protected
      * @return \JonnyW\PhantomJs\Validator\Esprima
      */
     protected function getEsprima()

+ 27 - 66
src/JonnyW/PhantomJs/Tests/Unit/Cache/FileCacheTest.php → src/Tests/Unit/Cache/FileCacheTest.php

@@ -6,43 +6,39 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Tests\Unit\Cache;
 
 use JonnyW\PhantomJs\Cache\FileCache;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class FileCacheTest extends \PHPUnit_Framework_TestCase
 {
     /**
-     * Test filename
+     * Test filename.
      *
      * @var string
-     * @access protected
      */
     protected $filename;
 
     /**
-     * Test directory
+     * Test directory.
      *
      * @var string
-     * @access protected
      */
     protected $directory;
 
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++++++ TESTS ++++++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++++++ TESTS ++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Test false is returned if file
      * does not exist.
-     *
-     * @access public
-     * @return void
      */
     public function testFalseIsReturnedIfFileDoesNotExist()
     {
@@ -53,9 +49,6 @@ class FileCacheTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test true is returned if file does exist.
-     *
-     * @access public
-     * @return void
      */
     public function testTrueIsReturnedIfFileDoesExist()
     {
@@ -69,8 +62,6 @@ class FileCacheTest extends \PHPUnit_Framework_TestCase
     /**
      * Test not writable exception is thrown if file
      * cannot be saved due to write permissions.
-     *
-     * @return void
      */
     public function testNotWritableExceptionIsThrownIfFileCannotBeSavedDueToWritePermissions()
     {
@@ -83,14 +74,11 @@ class FileCacheTest extends \PHPUnit_Framework_TestCase
     /**
      * Test test file location is returned
      * if file is successfully saved.
-     *
-     * @access public
-     * @return void
      */
     public function testFileLocationIsReturnedIfFileIsSuccessfullySaved()
     {
-        $fileCache  = $this->getFileCache($this->directory, 'txt');
-        $file       = $fileCache->save($this->filename, 'Test');
+        $fileCache = $this->getFileCache($this->directory, 'txt');
+        $file = $fileCache->save($this->filename, 'Test');
 
         $this->assertInternalType('string', $file);
         $this->assertFileExists($file);
@@ -98,15 +86,12 @@ class FileCacheTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test file can be saved
-     * with directory path
-     *
-     * @access public
-     * @return void
+     * with directory path.
      */
     public function testFileCanBeSavedWithDirectoryPath()
     {
-        $fileCache  = $this->getFileCache('', 'txt');
-        $file       = $fileCache->save($this->directory, 'Test');
+        $fileCache = $this->getFileCache('', 'txt');
+        $file = $fileCache->save($this->directory, 'Test');
 
         $this->assertSame(dirname($file), $this->directory);
 
@@ -116,31 +101,25 @@ class FileCacheTest extends \PHPUnit_Framework_TestCase
     /**
      * Test not writable exception is thrown
      * if directory path is not writable.
-     *
-     * @access public
-     * @return void
      */
     public function testNotWritableExceptionIsThrownIfDirectoryPathIsNotWritable()
     {
         $this->setExpectedException('\JonnyW\PhantomJs\Exception\NotWritableException');
 
-        $fileCache  = $this->getFileCache($this->directory, 'txt');
-        $file       = $fileCache->save('/This/Directory/Is/Not/Writable/', 'Test');
+        $fileCache = $this->getFileCache($this->directory, 'txt');
+        $file = $fileCache->save('/This/Directory/Is/Not/Writable/', 'Test');
     }
 
     /**
      * Test file can be saved with absolute
      * path.
-     *
-     * @access public
-     * @return void
      */
     public function testFileCanBeSavedWithAbsolutePath()
     {
         $test = sprintf('%1$s/%2$s', $this->directory, 'new-file.txt');
 
         $fileCache = $this->getFileCache('', 'txt');
-        $file      = $fileCache->save($test, 'Test');
+        $file = $fileCache->save($test, 'Test');
 
         $this->assertSame($test, $file);
 
@@ -149,10 +128,7 @@ class FileCacheTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test not exists exception is thrown when
-     * fetching data that doesn't exsit
-     *
-     * @access public
-     * @return void
+     * fetching data that doesn't exsit.
      */
     public function testNotExistsExceptionIsThrownIfWhenFetchingDataThatDoesntExist()
     {
@@ -165,9 +141,6 @@ class FileCacheTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test data can be fetched from cache.
-     *
-     * @access public
-     * @return void
      */
     public function testDataCanBeFetchedFromCache()
     {
@@ -183,9 +156,6 @@ class FileCacheTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test data can be deleted from cache.
-     *
-     * @access public
-     * @return void
      */
     public function testDataCanBeDeletedFromCache()
     {
@@ -202,9 +172,6 @@ class FileCacheTest extends \PHPUnit_Framework_TestCase
      * Test data can be deleted from
      * cache using wildcard.
      *.
-     *
-     * @access public
-     * @return void
      */
     public function testDataCanBeDeletedFromCacheUsingWildcard()
     {
@@ -219,15 +186,16 @@ class FileCacheTest extends \PHPUnit_Framework_TestCase
         $this->assertFileNotExists($file2);
     }
 
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++ TEST ENTITIES ++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++ TEST ENTITIES ++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
-     * Get file write instance
+     * Get file write instance.
+     *
+     * @param string $directory
+     * @param string $extension
      *
-     * @param  string                            $directory
-     * @param  string                            $extension
      * @return \JonnyW\PhantomJs\Cache\FileCache
      */
     protected function getFileCache($directory, $extension)
@@ -237,19 +205,16 @@ class FileCacheTest extends \PHPUnit_Framework_TestCase
         return $fileCache;
     }
 
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++++ UTILITIES ++++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++++ UTILITIES ++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Set up test environment.
-     *
-     * @access public
-     * @return void
      */
     public function setUp()
     {
-        $this->filename  = 'test.txt';
+        $this->filename = 'test.txt';
         $this->directory = sys_get_temp_dir();
 
         if (!is_writable($this->directory)) {
@@ -259,9 +224,6 @@ class FileCacheTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Tear down test environment.
-     *
-     * @access public
-     * @return void
      */
     public function tearDown()
     {
@@ -275,7 +237,6 @@ class FileCacheTest extends \PHPUnit_Framework_TestCase
     /**
      * Get test filename.
      *
-     * @access public
      * @return string
      */
     public function getFilename()

+ 32 - 44
src/JonnyW/PhantomJs/Tests/Unit/ClientTest.php → src/Tests/Unit/ClientTest.php

@@ -6,6 +6,7 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Tests\Unit;
 
 use JonnyW\PhantomJs\Client;
@@ -15,23 +16,19 @@ use JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface;
 use JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class ClientTest extends \PHPUnit_Framework_TestCase
 {
-
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++++++ TESTS ++++++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++++++ TESTS ++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Test can get client through
      * factory method.
-     *
-     * @access public
-     * @return void
      */
     public function testCanGetClientThroughFactoryMethod()
     {
@@ -40,15 +37,13 @@ class ClientTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test can get engine.
-     *
-     * @return void
      */
     public function testCanGetEngne()
     {
-        $engine             = $this->getEngine();
-        $procedureLoader    = $this->getProcedureLoader();
-        $procedureCompiler  = $this->getProcedureCompiler();
-        $messageFactory     = $this->getMessageFactory();
+        $engine = $this->getEngine();
+        $procedureLoader = $this->getProcedureLoader();
+        $procedureCompiler = $this->getProcedureCompiler();
+        $messageFactory = $this->getMessageFactory();
 
         $client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory);
 
@@ -56,16 +51,14 @@ class ClientTest extends \PHPUnit_Framework_TestCase
     }
 
     /**
-     * Test can get message factory
-     *
-     * @return void
+     * Test can get message factory.
      */
     public function testCanGetMessageFactory()
     {
-        $engine             = $this->getEngine();
-        $procedureLoader    = $this->getProcedureLoader();
-        $procedureCompiler  = $this->getProcedureCompiler();
-        $messageFactory     = $this->getMessageFactory();
+        $engine = $this->getEngine();
+        $procedureLoader = $this->getProcedureLoader();
+        $procedureCompiler = $this->getProcedureCompiler();
+        $messageFactory = $this->getMessageFactory();
 
         $client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory);
 
@@ -74,32 +67,31 @@ class ClientTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test can get procedure loader.
-     *
-     * @return void
      */
     public function testCanGetProcedureLoader()
     {
-        $engine             = $this->getEngine();
-        $procedureLoader    = $this->getProcedureLoader();
-        $procedureCompiler  = $this->getProcedureCompiler();
-        $messageFactory     = $this->getMessageFactory();
+        $engine = $this->getEngine();
+        $procedureLoader = $this->getProcedureLoader();
+        $procedureCompiler = $this->getProcedureCompiler();
+        $messageFactory = $this->getMessageFactory();
 
         $client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory);
 
         $this->assertInstanceOf('\JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface', $client->getProcedureLoader());
     }
 
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++ TEST ENTITIES ++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++ TEST ENTITIES ++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
-     * Get client instance
+     * Get client instance.
+     *
+     * @param \JonnyW\PhantomJs\Engine                               $engine
+     * @param \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface   $procedureLoader
+     * @param \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface $procedureCompiler
+     * @param \JonnyW\PhantomJs\Http\MessageFactoryInterface         $messageFactory
      *
-     * @param  \JonnyW\PhantomJs\Engine                               $engine
-     * @param  \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface   $procedureLoader
-     * @param  \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface $procedureCompiler
-     * @param  \JonnyW\PhantomJs\Http\MessageFactoryInterface         $messageFactory
      * @return \JonnyW\PhantomJs\Client
      */
     protected function getClient(Engine $engine, ProcedureLoaderInterface $procedureLoader, ProcedureCompilerInterface $procedureCompiler, MessageFactoryInterface $messageFactory)
@@ -109,14 +101,13 @@ class ClientTest extends \PHPUnit_Framework_TestCase
         return $client;
     }
 
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++ MOCKS / STUBS ++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++ MOCKS / STUBS ++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
-     * Get engine
+     * Get engine.
      *
-     * @access protected
      * @return \JonnyW\PhantomJs\Engine
      */
     protected function getEngine()
@@ -127,9 +118,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
     }
 
     /**
-     * Get message factory
+     * Get message factory.
      *
-     * @access protected
      * @return \JonnyW\PhantomJs\Http\MessageFactoryInterface
      */
     protected function getMessageFactory()
@@ -142,7 +132,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
     /**
      * Get procedure loader.
      *
-     * @access protected
      * @return \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface
      */
     protected function getProcedureLoader()
@@ -155,7 +144,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
     /**
      * Get procedure validator.
      *
-     * @access protected
      * @return \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface
      */
     protected function getProcedureCompiler()

+ 11 - 50
src/JonnyW/PhantomJs/Tests/Unit/EngineTest.php → src/Tests/Unit/EngineTest.php

@@ -6,28 +6,25 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Tests\Unit;
 
 use JonnyW\PhantomJs\Engine;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class EngineTest extends \PHPUnit_Framework_TestCase
 {
-
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++++++ TESTS ++++++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++++++ TESTS ++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Test invalid executable exception is thrown
      * if phantom JS path is invalid.
-     *
-     * @access public
-     * @return void
      */
     public function testInvalidExecutableExceptionIsThrownIfPhantomJSPathIsInvalid()
     {
@@ -40,9 +37,6 @@ class EngineTest extends \PHPUnit_Framework_TestCase
     /**
      * Test default phantom JS path is returned
      * if no custom path is set.
-     *
-     * @access public
-     * @return void
      */
     public function testDefaultPhantomJSPathIsReturnedIfNoCustomPathIsSet()
     {
@@ -53,9 +47,6 @@ class EngineTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test can log data.
-     *
-     * @access public
-     * @return void
      */
     public function testCanLogData()
     {
@@ -69,9 +60,6 @@ class EngineTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test can clear log.
-     *
-     * @access public
-     * @return void
      */
     public function testCanClearLog()
     {
@@ -86,15 +74,12 @@ class EngineTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test can add run option.
-     *
-     * @access public
-     * @return void
      */
     public function testCanAddRunOption()
     {
         $options = array(
             'option1',
-            'option2'
+            'option2',
         );
 
         $engine = $this->getEngine();
@@ -109,9 +94,6 @@ class EngineTest extends \PHPUnit_Framework_TestCase
     /**
      * Test invalid executable exception is thrown when
      * building command if path to phantom JS is valid.
-     *
-     * @access public
-     * @return void
      */
     public function testInvalidExecutableExceptionIsThrownWhenBuildingCommandIfPathToPhantomJSIsInvalid()
     {
@@ -127,10 +109,7 @@ class EngineTest extends \PHPUnit_Framework_TestCase
     }
 
     /**
-     * Test command contains phantom JS executable
-     *
-     * @access public
-     * @return void
+     * Test command contains phantom JS executable.
      */
     public function testCommandContainsPhantomJSExecutable()
     {
@@ -141,9 +120,6 @@ class EngineTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test debug flag can be set.
-     *
-     * @access public
-     * @return void
      */
     public function testDebugFlagCanBeSet()
     {
@@ -156,9 +132,6 @@ class EngineTest extends \PHPUnit_Framework_TestCase
     /**
      * Test debug flag is not set if
      * debugging is not enabled.
-     *
-     * @access public
-     * @return void
      */
     public function testDebugFlagIsNotSetIfDebuggingIsNotEnabled()
     {
@@ -170,9 +143,6 @@ class EngineTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test disk cache flag can be set.
-     *
-     * @access public
-     * @return void
      */
     public function testDiskCacheFlagCanBeSet()
     {
@@ -185,9 +155,6 @@ class EngineTest extends \PHPUnit_Framework_TestCase
     /**
      * Test disk cache flag is not set if
      * caching is not enabled.
-     *
-     * @access public
-     * @return void
      */
     public function testDiskCacheFlagIsNotSetIfCachingIsNotEnabled()
     {
@@ -199,9 +166,6 @@ class EngineTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test command contains run options.
-     *
-     * @access public
-     * @return void
      */
     public function testCommandContainsRunOptions()
     {
@@ -224,9 +188,6 @@ class EngineTest extends \PHPUnit_Framework_TestCase
     /**
      * Test debug flag is set if runs options
      * are also set.
-     *
-     * @access public
-     * @return void
      */
     public function testDebugFlagIsSetIfRunOptionsAreAlsoSet()
     {
@@ -242,12 +203,12 @@ class EngineTest extends \PHPUnit_Framework_TestCase
         $this->assertContains('--debug=true', $command);
     }
 
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++ TEST ENTITIES ++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++ TEST ENTITIES ++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
-     * Get client instance
+     * Get client instance.
      *
      * @return \JonnyW\PhantomJs\Engine
      */

+ 44 - 122
src/JonnyW/PhantomJs/Tests/Unit/Http/CaptureRequestTest.php → src/Tests/Unit/Http/CaptureRequestTest.php

@@ -6,29 +6,26 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Tests\Unit\Http;
 
 use JonnyW\PhantomJs\Http\CaptureRequest;
 use JonnyW\PhantomJs\Http\RequestInterface;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 {
-
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++++++ TESTS ++++++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++++++ TESTS ++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Test capture type is returned by default
      * if no type is set.
-     *
-     * @access public
-     * @return void
      */
     public function testCaptureTypeIsReturnedByDefaultIfNotTypeIsSet()
     {
@@ -39,9 +36,6 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test custom type can be set.
-     *
-     * @access public
-     * @return void
      */
     public function testCustomTypeCanBeSet()
     {
@@ -55,13 +49,10 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test URL can be set via constructor.
-     *
-     * @access public
-     * @return void
      */
     public function testUrlCanBeSetViaConstructor()
     {
-        $url            = 'http://test.com';
+        $url = 'http://test.com';
         $captureRequest = $this->getCaptureRequest($url);
 
         $this->assertEquals($url, $captureRequest->getUrl());
@@ -69,13 +60,10 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test method can be set via constructor.
-     *
-     * @access public
-     * @return void
      */
     public function testMethodCanBeSetViaConstructor()
     {
-        $method         = 'GET';
+        $method = 'GET';
         $captureRequest = $this->getCaptureRequest(null, $method);
 
         $this->assertEquals($method, $captureRequest->getMethod());
@@ -83,13 +71,10 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test timeout can be set via constructor.
-     *
-     * @access public
-     * @return void
      */
     public function testTimeoutCanBeSetViaConstructor()
     {
-        $timeout        = 100000;
+        $timeout = 100000;
         $captureRequest = $this->getCaptureRequest('http://test.com', 'GET', $timeout);
 
         $this->assertEquals($timeout, $captureRequest->getTimeout());
@@ -98,9 +83,6 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
     /**
      * Test invalid method is thrown if method
      * is invalid.
-     *
-     * @access public
-     * @return void
      */
     public function testInvalidMethodIsThrownIfMethodIsInvalid()
     {
@@ -112,13 +94,10 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test rect width can be set.
-     *
-     * @access public
-     * @return void
      */
     public function testRectWidthCanBeSet()
     {
-        $width  = 100;
+        $width = 100;
         $height = 200;
 
         $captureRequest = $this->getCaptureRequest();
@@ -129,13 +108,10 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test rect height can be set.
-     *
-     * @access public
-     * @return void
      */
     public function testRectHeightCanBeSet()
     {
-        $width  = 100;
+        $width = 100;
         $height = 200;
 
         $captureRequest = $this->getCaptureRequest();
@@ -146,15 +122,12 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test rect top can be set.
-     *
-     * @access public
-     * @return void
      */
     public function testRectTopCanBeSet()
     {
-        $width  = 100;
+        $width = 100;
         $height = 200;
-        $top    = 50;
+        $top = 50;
 
         $captureRequest = $this->getCaptureRequest();
         $captureRequest->setCaptureDimensions($width, $height, $top);
@@ -164,15 +137,12 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test rect left can be set.
-     *
-     * @access public
-     * @return void
      */
     public function testRectLeftCanBeSet()
     {
-        $width  = 100;
+        $width = 100;
         $height = 200;
-        $left   = 50;
+        $left = 50;
 
         $captureRequest = $this->getCaptureRequest();
         $captureRequest->setCaptureDimensions($width, $height, 0, $left);
@@ -183,9 +153,6 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
     /**
      * Test URL does not contain query params if
      * mehtod is not HEAD or GET.
-     *
-     * @access public
-     * @return void
      */
     public function testUrlDoesNotContainQueryParamsIfMethodIsNotHeadOrGet()
     {
@@ -193,7 +160,7 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
         $data = array(
             'test_param1' => 'Testing1',
-            'test_param2' => 'Testing2'
+            'test_param2' => 'Testing2',
         );
 
         $captureRequest = $this->getCaptureRequest();
@@ -207,9 +174,6 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
     /**
      * Test URL does contain query params if mehthod
      * is GET.
-     *
-     * @access public
-     * @return void
      */
     public function testUrlDoesContainQueryParamsIfMethodIsGet()
     {
@@ -217,7 +181,7 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
         $data = array(
             'test_param1' => 'Testing1',
-            'test_param2' => 'Testing2'
+            'test_param2' => 'Testing2',
         );
 
         $captureRequest = $this->getCaptureRequest();
@@ -225,7 +189,7 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
         $captureRequest->setUrl($url);
         $captureRequest->setRequestData($data);
 
-        $expectedUrl = $url . '?test_param1=Testing1&test_param2=Testing2';
+        $expectedUrl = $url.'?test_param1=Testing1&test_param2=Testing2';
 
         $this->assertEquals($expectedUrl, $captureRequest->getUrl());
     }
@@ -233,9 +197,6 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
     /**
      * Test URL does contain query params if method
      * is HEAD.
-     *
-     * @access public
-     * @return void
      */
     public function testUrlDoesContainQueryParamsIfMethodIsHead()
     {
@@ -243,7 +204,7 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
         $data = array(
             'test_param1' => 'Testing1',
-            'test_param2' => 'Testing2'
+            'test_param2' => 'Testing2',
         );
 
         $captureRequest = $this->getCaptureRequest();
@@ -251,7 +212,7 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
         $captureRequest->setUrl($url);
         $captureRequest->setRequestData($data);
 
-        $expectedUrl = $url . '?test_param1=Testing1&test_param2=Testing2';
+        $expectedUrl = $url.'?test_param1=Testing1&test_param2=Testing2';
 
         $this->assertEquals($expectedUrl, $captureRequest->getUrl());
     }
@@ -259,9 +220,6 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
     /**
      * Test query params are appended to URL if
      * URL contains existng query params.
-     *
-     * @access public
-     * @return void
      */
     public function testQueryParamsAreAppendedToUrlIfUrlContainsExistingQueryParams()
     {
@@ -269,7 +227,7 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
         $data = array(
             'test_param1' => 'Testing1',
-            'test_param2' => 'Testing2'
+            'test_param2' => 'Testing2',
         );
 
         $captureRequest = $this->getCaptureRequest();
@@ -277,7 +235,7 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
         $captureRequest->setUrl($url);
         $captureRequest->setRequestData($data);
 
-        $expectedUrl = $url . '&test_param1=Testing1&test_param2=Testing2';
+        $expectedUrl = $url.'&test_param1=Testing1&test_param2=Testing2';
 
         $this->assertEquals($expectedUrl, $captureRequest->getUrl());
     }
@@ -285,15 +243,12 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
     /**
      * Test request contains no body if method
      * is GET.
-     *
-     * @access public
-     * @return void
      */
     public function testRequestContainsNoBodyIfMethodIsGet()
     {
         $data = array(
             'test_param1' => 'Testing1',
-            'test_param2' => 'Testing2'
+            'test_param2' => 'Testing2',
         );
 
         $captureRequest = $this->getCaptureRequest();
@@ -306,15 +261,12 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
     /**
      * Test request contains no body if method
      * is HEAD.
-     *
-     * @access public
-     * @return void
      */
     public function testRequestContainsNoBodyIfMethodIsHead()
     {
         $data = array(
             'test_param1' => 'Testing1',
-            'test_param2' => 'Testing2'
+            'test_param2' => 'Testing2',
         );
 
         $captureRequest = $this->getCaptureRequest();
@@ -327,15 +279,12 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
     /**
      * Test request contains a body if method is
      * not HEAD or GET.
-     *
-     * @access public
-     * @return void
      */
     public function testRequestContainsABodyIfMethodIsNotHeadOrGet()
     {
         $data = array(
             'test_param1' => 'Testing1',
-            'test_param2' => 'Testing2'
+            'test_param2' => 'Testing2',
         );
 
         $captureRequest = $this->getCaptureRequest();
@@ -349,9 +298,6 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test request data can be flattened.
-     *
-     * @access public
-     * @return void
      */
     public function testRequestDataCanBeFalttened()
     {
@@ -359,17 +305,17 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
             'test_param1' => 'Testing1',
             'test_param2' => array(
                 'Testing2',
-                'Testing3'
-            )
+                'Testing3',
+            ),
         );
 
         $captureRequest = $this->getCaptureRequest();
         $captureRequest->setRequestData($data);
 
         $flatData = array(
-            'test_param1'    => 'Testing1',
+            'test_param1' => 'Testing1',
             'test_param2[0]' => 'Testing2',
-            'test_param2[1]' => 'Testing3'
+            'test_param2[1]' => 'Testing3',
         );
 
         $this->assertEquals($flatData, $captureRequest->getRequestData(true));
@@ -377,9 +323,6 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test raw request data can be accessed.
-     *
-     * @access public
-     * @return void
      */
     public function testRawRequestDataCanBeAccessed()
     {
@@ -387,8 +330,8 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
             'test_param1' => 'Testing1',
             'test_param2' => array(
                 'Testing2',
-                'Testing3'
-            )
+                'Testing3',
+            ),
         );
 
         $captureRequest = $this->getCaptureRequest();
@@ -399,19 +342,16 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test headers can be added.
-     *
-     * @access public
-     * @return void
      */
     public function testHeadersCanBeAdded()
     {
         $existingHeaders = array(
-            'Header1' => 'Header 1'
+            'Header1' => 'Header 1',
         );
 
         $newHeaders = array(
             'Header2' => 'Header 2',
-            'Header3' => 'Header 3'
+            'Header3' => 'Header 3',
         );
 
         $captureRequest = $this->getCaptureRequest();
@@ -425,16 +365,13 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test headers can be accessed in
-     * JSON format
-     *
-     * @access public
-     * @return void
+     * JSON format.
      */
     public function testHeadersCanBeAccessedInJsonFormat()
     {
         $headers = array(
             'Header1' => 'Header 1',
-            'Header2' => 'Header 2'
+            'Header2' => 'Header 2',
         );
 
         $captureRequest = $this->getCaptureRequest();
@@ -447,15 +384,12 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test raw headers can be accessed.
-     *
-     * @access public
-     * @return void
      */
     public function testRawHeadersCanBeAccessed()
     {
         $headers = array(
             'Header1' => 'Header 1',
-            'Header2' => 'Header 2'
+            'Header2' => 'Header 2',
         );
 
         $captureRequest = $this->getCaptureRequest();
@@ -467,9 +401,6 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
     /**
      * Test not writable exception is thrown if
      * output path is not writable.
-     *
-     * @access public
-     * @return void
      */
     public function testNotWritableExceptonIsThrownIfOutputPathIsNotWritable()
     {
@@ -483,9 +414,6 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test can set output file.
-     *
-     * @access public
-     * @return void
      */
     public function testCanSetOutputFile()
     {
@@ -499,13 +427,10 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test can set viewport width.
-     *
-     * @access public
-     * @return void
      */
     public function testCanSetViewportWidth()
     {
-        $width  = 100;
+        $width = 100;
         $height = 200;
 
         $caputreRequest = $this->getCaptureRequest();
@@ -516,13 +441,10 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test can set viewport height.
-     *
-     * @access public
-     * @return void
      */
     public function testCanSetViewportHeight()
     {
-        $width  = 100;
+        $width = 100;
         $height = 200;
 
         $caputreRequest = $this->getCaptureRequest();
@@ -531,17 +453,17 @@ class CaptureRequestTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals($height, $caputreRequest->getViewportHeight());
     }
 
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++ TEST ENTITIES ++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++ TEST ENTITIES ++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Get capture request instance.
      *
-     * @access protected
-     * @param  string                                $url     (default: null)
-     * @param  string                                $method  (default: RequestInterface::METHOD_GET)
-     * @param  int                                   $timeout (default: 5000)
+     * @param string $url     (default: null)
+     * @param string $method  (default: RequestInterface::METHOD_GET)
+     * @param int    $timeout (default: 5000)
+     *
      * @return \JonnyW\PhantomJs\Http\CaptureRequest
      */
     protected function getCaptureRequest($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000)

+ 11 - 42
src/JonnyW/PhantomJs/Tests/Unit/Http/MessageFactoryTest.php → src/Tests/Unit/Http/MessageFactoryTest.php

@@ -6,27 +6,24 @@
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
+
 namespace JonnyW\PhantomJs\Tests\Unit\Http;
 
 use JonnyW\PhantomJs\Http\MessageFactory;
 
 /**
- * PHP PhantomJs
+ * PHP PhantomJs.
  *
  * @author Jon Wenmoth <contact@jonnyw.me>
  */
 class MessageFactoryTest extends \PHPUnit_Framework_TestCase
 {
-
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++++++ TESTS ++++++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++++++ TESTS ++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Test factory method creates message factory.
-     *
-     * @access public
-     * @return void
      */
     public function testFactoryMethodCreatesMessageFactory()
     {
@@ -35,9 +32,6 @@ class MessageFactoryTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test can create request.
-     *
-     * @access public
-     * @return void
      */
     public function testCanCreateRequest()
     {
@@ -48,57 +42,45 @@ class MessageFactoryTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test can create request with URL.
-     *
-     * @access public
-     * @return void
      */
     public function testCanCreateRequestWithUrl()
     {
         $url = 'http://test.com';
 
         $messageFactory = $this->getMessageFactory();
-        $request        = $messageFactory->createRequest($url);
+        $request = $messageFactory->createRequest($url);
 
         $this->assertEquals($url, $request->getUrl());
     }
 
     /**
      * Test can create request with method.
-     *
-     * @access public
-     * @return void
      */
     public function testCanCreateRequestWithMethod()
     {
         $method = 'POST';
 
         $messageFactory = $this->getMessageFactory();
-        $request        = $messageFactory->createRequest(null, $method);
+        $request = $messageFactory->createRequest(null, $method);
 
         $this->assertEquals($method, $request->getMethod());
     }
 
     /**
      * Test can create request with timeout.
-     *
-     * @access public
-     * @return void
      */
     public function testCanCreateRequestWithTimeout()
     {
         $timeout = 123456789;
 
         $messageFactory = $this->getMessageFactory();
-        $request        = $messageFactory->createRequest(null, 'GET', $timeout);
+        $request = $messageFactory->createRequest(null, 'GET', $timeout);
 
         $this->assertEquals($timeout, $request->getTimeout());
     }
 
     /**
      * Test can create capture request.
-     *
-     * @access public
-     * @return void
      */
     public function testCanCreateCaptureRequest()
     {
@@ -109,9 +91,6 @@ class MessageFactoryTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test can create capture request with URL.
-     *
-     * @access public
-     * @return void
      */
     public function testCanCreateCaptureRequestWithUrl()
     {
@@ -126,9 +105,6 @@ class MessageFactoryTest extends \PHPUnit_Framework_TestCase
     /**
      * Test can create capture request
      * with method.
-     *
-     * @access public
-     * @return void
      */
     public function testCanCreateCaptureRequestWithMethod()
     {
@@ -142,9 +118,6 @@ class MessageFactoryTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test can create capture request with timeout.
-     *
-     * @access public
-     * @return void
      */
     public function testCanCreateCaptureRequestWithTimeout()
     {
@@ -158,9 +131,6 @@ class MessageFactoryTest extends \PHPUnit_Framework_TestCase
 
     /**
      * Test can create response.
-     *
-     * @access public
-     * @return void
      */
     public function testCanCreateResponse()
     {
@@ -169,14 +139,13 @@ class MessageFactoryTest extends \PHPUnit_Framework_TestCase
         $this->assertInstanceOf('\JonnyW\PhantomJs\Http\Response', $messageFactory->createResponse());
     }
 
-/** +++++++++++++++++++++++++++++++++++ **/
-/** ++++++++++ TEST ENTITIES ++++++++++ **/
-/** +++++++++++++++++++++++++++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
+    /** ++++++++++ TEST ENTITIES ++++++++++ **/
+    /** +++++++++++++++++++++++++++++++++++ **/
 
     /**
      * Get message factory instance.
      *
-     * @access protected
      * @return \JonnyW\PhantomJs\Http\MessageFactory
      */
     protected function getMessageFactory()

Некоторые файлы не были показаны из-за большого количества измененных файлов