Skip to content

Commit

Permalink
Format Code
Browse files Browse the repository at this point in the history
  • Loading branch information
3x1io authored and github-actions[bot] committed Nov 27, 2024
1 parent c93fa60 commit 3308b3e
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 149 deletions.
6 changes: 3 additions & 3 deletions config/filament-cms-behance.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return [
"behance" => [
"username" => env('BEHANCE_USERNAME', '3x1'),
]
'behance' => [
'username' => env('BEHANCE_USERNAME', '3x1'),
],
];
32 changes: 12 additions & 20 deletions src/Browser/Actions/CreateBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ class CreateBrowser
private ?Chrome $dusk;

public function __construct(
private string $type='web',
private bool $show=false
)
{
private string $type = 'web',
private bool $show = false
) {
$this->dusk = new Chrome($this->type);

try {
if (!$this->show) {
if (! $this->show) {
$this->dusk->headless()
->disableGpu()
->noSandbox();
Expand All @@ -36,29 +35,22 @@ public function __construct(
}
}

/**
* @return void
*/
private function agent(): void
{
if ($this->type === 'web') {
$webAgent = "Mozilla/5.0 (X11; Linux x86_64) ";
$webAgent .= "AppleWebKit/537.36 (KHTML, like Gecko) ";
$webAgent .= "Chrome/111.0.0.0 Safari/537.36";
$webAgent = 'Mozilla/5.0 (X11; Linux x86_64) ';
$webAgent .= 'AppleWebKit/537.36 (KHTML, like Gecko) ';
$webAgent .= 'Chrome/111.0.0.0 Safari/537.36';
$this->dusk->userAgent($webAgent);
}
else {
$mobileAgent = "Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) ";
$mobileAgent .= "AppleWebKit/537.36 (KHTML, like Gecko) ";
$mobileAgent .= "Chrome/59.0.3071.125 Mobile Safari/537.36";
} else {
$mobileAgent = 'Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) ';
$mobileAgent .= 'AppleWebKit/537.36 (KHTML, like Gecko) ';
$mobileAgent .= 'Chrome/59.0.3071.125 Mobile Safari/537.36';
$this->dusk->userAgent($mobileAgent);
}
}

/**
* @return Chrome|null
*/
public function dusk(): Chrome|null
public function dusk(): ?Chrome
{
return $this->dusk;
}
Expand Down
66 changes: 18 additions & 48 deletions src/Browser/Chrome.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<?php

namespace TomatoPHP\FilamentCmsBehance\Browser;

use Closure;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Illuminate\Support\Collection;
use Laravel\Dusk\Chrome\SupportsChrome;
use Facebook\WebDriver\WebDriverPlatform;
use Laravel\Dusk\Concerns\ProvidesBrowser;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\WebDriverBrowserType;
use Facebook\WebDriver\Remote\WebDriverCapabilityType;

/**
*
* @property RemoteWebDriver $getDriver
* @property Collection $arguments
* @property int $requestTimeout
Expand All @@ -40,46 +37,32 @@
* @property static remote()
* @property static headless()
* @property static setConnectTimeout(int $timeout)
*
* @method browse(Closure $callback): Browser
* @method close()
*/
class Chrome
{
use ProvidesBrowser,
SupportsChrome;

use ProvidesBrowser;
use SupportsChrome;

/**
* @var RemoteWebDriver
*/
public RemoteWebDriver $getDriver;


/**
* A list of remote web driver arguments.
*
* @var Collection
*/
protected Collection $arguments;


/**
* Set the maximum time of a request to remote WebDriver server.
*
* @var int
*/
protected int $requestTimeout = 50000;

/**
* Set the maximum time of a connection to remote WebDriver server.
*
* @var int
*/
protected int $connectTimeout = 50000;




/**
* Initialises the dusk browser and starts the chrome driver.
*
Expand All @@ -92,8 +75,7 @@ public function __construct(
* @var string
*/
protected string $callerName
)
{
) {
$this->arguments = Collection::make();
}

Expand All @@ -109,11 +91,11 @@ public function start(): static
return $this;
}


/**
* Stop Browser
*
* @return $this
*
* @throws \Exception
*/
public function stop(): static
Expand Down Expand Up @@ -163,7 +145,6 @@ public function headless(): static
return $this->addArgument('--headless');
}


/**
* Set Remote Port
*
Expand Down Expand Up @@ -209,7 +190,7 @@ public function noSandbox(): static
*
* @return $this
*/
public function noZygote():static
public function noZygote(): static
{
return $this->noSandbox()->addArgument('--no-zygote');
}
Expand All @@ -219,17 +200,16 @@ public function noZygote():static
*
* @return $this
*/
public function ignoreSslErrors():static
public function ignoreSslErrors(): static
{
return $this->addArgument('--ignore-certificate-errors');
}

/**
* Set the initial browser window size.
*
* @param int $width the browser width in pixels
* @param int $height the browser height in pixels
*
* @param int $width the browser width in pixels
* @param int $height the browser height in pixels
* @return $this
*/
public function windowSize(int $width, int $height): static
Expand All @@ -240,8 +220,7 @@ public function windowSize(int $width, int $height): static
/**
* Set the user proxy IP.
*
* @param string $ip the user proxy IP
*
* @param string $ip the user proxy IP
* @return $this
*/
public function proxyServer(string $ip): static
Expand All @@ -252,7 +231,6 @@ public function proxyServer(string $ip): static
/**
* Set user Agent for selected browser.
*
* @param string $useragent
* @return $this
*/
public function userAgent(string $useragent): static
Expand Down Expand Up @@ -290,20 +268,17 @@ public function disableInfobars(): static
return $this->addArgument('disable-infobars');
}


/**
* Set The Browser Data Base Path
*
* @param string $path
* @return $this
*/
public function browserData(string $path):static
public function browserData(string $path): static
{
return $this->addArgument('--user-data-dir=' . $path);
}

/**
* @param string $id
* @return $this
*/
public function setProfile(string $id): static
Expand All @@ -314,12 +289,11 @@ public function setProfile(string $id): static
/**
* Add a browser option.
*
* @param string $argument
* @return $this
*/
protected function addArgument(string $argument): static
{
if (!$this->arguments->contains($argument)) {
if (! $this->arguments->contains($argument)) {
$this->arguments->push($argument);
}

Expand All @@ -328,15 +302,13 @@ protected function addArgument(string $argument): static

/**
* Create the RemoteWebDriver instance.
*
* @return RemoteWebDriver
*/
public function driver(): RemoteWebDriver
{
$options = (new ChromeOptions())->addArguments($this->arguments->toArray());
$options = (new ChromeOptions)->addArguments($this->arguments->toArray());
$options->setExperimentalOption('excludeSwitches', ['enable-automation']);

$this->getDriver = RemoteWebDriver::create(
$this->getDriver = RemoteWebDriver::create(
'http://localhost:9515',
DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY,
Expand All @@ -351,8 +323,6 @@ public function driver(): RemoteWebDriver

/**
* Get the browser caller name.
*
* @return string
*/
protected function getCallerName(): string
{
Expand Down
1 change: 0 additions & 1 deletion src/FilamentCmsBehancePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class FilamentCmsBehancePlugin implements Plugin
{

public function getId(): string
{
return 'filament-cms-behance';
Expand Down
9 changes: 4 additions & 5 deletions src/FilamentCmsBehanceServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@

use Illuminate\Support\ServiceProvider;


class FilamentCmsBehanceServiceProvider extends ServiceProvider
{
public function register(): void
{
//Register Config file
$this->mergeConfigFrom(__DIR__.'/../config/filament-cms-behance.php', 'filament-cms-behance');
$this->mergeConfigFrom(__DIR__ . '/../config/filament-cms-behance.php', 'filament-cms-behance');

//Publish Config
$this->publishes([
__DIR__.'/../config/filament-cms-behance.php' => config_path('filament-cms-behance.php'),
__DIR__ . '/../config/filament-cms-behance.php' => config_path('filament-cms-behance.php'),
], 'filament-cms-behance-config');

//Register Langs
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'filament-cms-behance');
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'filament-cms-behance');

//Publish Lang
$this->publishes([
__DIR__.'/../resources/lang' => base_path('lang/vendor/filament-cms-behance'),
__DIR__ . '/../resources/lang' => base_path('lang/vendor/filament-cms-behance'),
], 'filament-cms-behance-lang');
}

Expand Down
21 changes: 11 additions & 10 deletions src/Jobs/BehanceMetaGetterJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@
namespace TomatoPHP\FilamentCmsBehance\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class BehanceMetaGetterJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;

/**
* Create a new job instance.
*/
public function __construct(
public ?string $username=null,
public ?string $url=null,
public ?int $userId=null,
public ?string $userType=null,
public ?string $panel=null,
)
{
public ?string $username = null,
public ?string $url = null,
public ?int $userId = null,
public ?string $userType = null,
public ?string $panel = null,
) {
//
}

Expand All @@ -32,7 +33,7 @@ public function __construct(
*/
public function handle(): void
{
if($this->username || $this->url){
if ($this->username || $this->url) {
$be = new \TomatoPHP\FilamentCms\Services\Behance(
username: $this->username,
url: $this->url,
Expand Down
Loading

0 comments on commit 3308b3e

Please sign in to comment.