This repository was archived by the owner on Mar 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathPhantomJsServiceProvider.php
70 lines (57 loc) · 1.71 KB
/
PhantomJsServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Josh\Component\PhantomJs;
use Illuminate\Support\ServiceProvider;
class PhantomJsServiceProvider extends ServiceProvider
{
/**
* Publish config file
*
* @author Alireza Josheghani <josheghani.dev@gmail.com>
* @since 7 May 2017
* @return void
*/
public function boot() : void
{
$this->publishes([ __DIR__ . '/../config.php' => config_path( 'phantomjs.php' ) ]);
}
/**
* Register package to ur project
*
* @author Alireza Josheghani <josheghani.dev@gmail.com>
* @since 7 May 2017
* @return void
*/
public function register() : void
{
$this->app->singleton('phantomjs', function(){
return $this->getClient();
});
}
/**
* Get phantomjs client
*
* @author Alireza Josheghani <josheghani.dev@gmail.com>
* @since 8 May 2017
* @return PhantomJs
*/
protected function getClient() : PhantomJs
{
$client = new PhantomJs;
if(file_exists(config_path('phantomjs.php'))){
$config = config('phantomjs');
if(! empty($config['binary_path']) && ! is_null($config['binary_path'])){
$client->setBinaryPath($config['binary_path']);
}
if(! empty($config['options']) && ! is_null($config['options'])){
$client->setOptions($config['options']);
}
if(! empty($config['debug']) && ! is_null($config['debug'])){
$client->setDebug($config['debug']);
}
if(! empty($config['cache']) && ! is_null($config['cache'])){
$client->setCache($config['cache']);
}
}
return $client;
}
}