-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from stefanzweifel/dev/core-changes
Rebuilding Core and more (Tests, New Exception Handling)
- Loading branch information
Showing
123 changed files
with
5,766 additions
and
1,570 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
|
||
namespace Screeenly\Core\Client; | ||
|
||
use Illuminate\Contracts\Config\Repository as Config; | ||
use Screeenly\Core\Exception\UnavailableHostException; | ||
use Screeenly\Core\Ping; | ||
use Screeenly\Core\Screeenshot\Screenshot; | ||
|
||
abstract class AbstractClient implements ClientInterface | ||
{ | ||
/** | ||
* Config Repository | ||
* @var Illuminate\Contracts\Config\Repository | ||
*/ | ||
protected $config; | ||
|
||
/** | ||
* Screenshot Instance | ||
* @var Screeenly\Core\Screeenshot\Screenshot | ||
*/ | ||
protected $screenshot; | ||
|
||
/** | ||
* Browser Height | ||
* @var int | ||
*/ | ||
protected $height; | ||
|
||
/** | ||
* Browser Width | ||
* @var int | ||
*/ | ||
protected $width; | ||
|
||
/** | ||
* Browser Viewport Height | ||
* @var integer | ||
*/ | ||
protected $viewportHeight = 768; | ||
|
||
public function __construct(Config $config, Screenshot $screenshot) | ||
{ | ||
$this->config = $config; | ||
$this->screenshot = $screenshot; | ||
|
||
// Set default values for height and width | ||
$this->setHeight(null); | ||
$this->setWidth(null); | ||
} | ||
|
||
/** | ||
* Set Browser Height | ||
* @param int $height | ||
*/ | ||
public function setHeight($height) | ||
{ | ||
return $this->height = $height; | ||
} | ||
|
||
/** | ||
* Set Browser Width | ||
* @param int $width | ||
*/ | ||
public function setWidth($width) | ||
{ | ||
if (is_null($width)) { | ||
$width = $this->config->get('screeenly.core.screenshot_width'); | ||
} | ||
|
||
return $this->width = $width; | ||
} | ||
|
||
/** | ||
* Return Viewport Height | ||
* @return int | ||
*/ | ||
public function getViewportHeight() | ||
{ | ||
return $this->viewportHeight; | ||
} | ||
|
||
/** | ||
* Return Height | ||
* @return int | ||
*/ | ||
public function getHeight() | ||
{ | ||
return $this->height; | ||
} | ||
|
||
/** | ||
* Return Width | ||
* @return int | ||
*/ | ||
public function getWidth() | ||
{ | ||
return $this->width; | ||
} | ||
|
||
/** | ||
* Check if requested URL is available | ||
* @return void | ||
*/ | ||
public function isUrlAvailable() | ||
{ | ||
$url = $this->screenshot->getRequestUrl(); | ||
$ping = app()->make(Ping::class); | ||
|
||
if ($ping->isUp($url) === false) { | ||
throw new UnavailableHostException("The URL {$url} is unavailable.", 422); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Create an empty file for testing purposes. | ||
* (Should be replaced by a virtual file system) | ||
* @param string $path | ||
* @return void | ||
*/ | ||
public function createTestFile($path) | ||
{ | ||
\File::put(public_path($path), 'foo'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Screeenly\Core\Client; | ||
|
||
interface ClientInterface | ||
{ | ||
/** | ||
* Boot Headless Browser | ||
* Perfect to setup default values | ||
* @return void | ||
*/ | ||
public function boot(); | ||
|
||
/** | ||
* Method to capture a Screenshot | ||
* @param string $url | ||
* @param mixed $key | ||
* @return Screeenly\Core\Screeenshot\Screenshot | ||
*/ | ||
public function capture($url, $key = null); | ||
} |
Oops, something went wrong.