Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding support for calling closures before doing a ray request #859

Merged
merged 6 commits into from
Nov 7, 2023

Conversation

SebastiaanKloos
Copy link
Contributor

I want to call an Apple Script to start Ray if not already active before doing any requests to Ray.

With the PR you would be able to add this to your service provider

use Spatie\Ray\Ray;

Ray::beforeSendRequest(function () {
    $script = '
        set appBundleID to "be.spatie.ray"

        tell application "System Events"
            if not (exists (processes whose bundle identifier is appBundleID)) then
                tell application "Ray" to activate
                delay 1
            end if
        end tell
    ';

    $escapedScript = escapeshellarg($script);
    $command = "osascript -e $escapedScript";

    $output = shell_exec($command);
});

@SebastiaanKloos SebastiaanKloos changed the title adding support for calling functions before doing a ray request adding support for calling closures before doing a ray request Nov 7, 2023
@riasvdv
Copy link
Member

riasvdv commented Nov 7, 2023

Can you add a test that verifies the closure gets called?

@SebastiaanKloos
Copy link
Contributor Author

Can you add a test that verifies the closure gets called?

@riasvdv test added!

@riasvdv riasvdv merged commit af6c700 into spatie:main Nov 7, 2023
21 checks passed
@riasvdv
Copy link
Member

riasvdv commented Nov 7, 2023

Thanks!

@bhaidar
Copy link

bhaidar commented Jan 12, 2024

Hey @SebastiaanKloos I am getting an error that beforeSendRequest doesn't exist. I've already imported Ray class.

Any idea what's happening here?

  Method beforeSendRequest does not exist.

  at vendor/spatie/macroable/src/Macroable.php:40
     36▕ 
     37▕     public static function __callStatic($method, $parameters)
     38▕     {
     39▕         if (! static::hasMacro($method)) {
  ➜  40▕             throw new BadMethodCallException("Method {$method} does not exist.");
     41▕         }
     42▕ 
     43▕         $macro = static::$macros[$method];
     44▕ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants