The
tap
function accepts two arguments: an arbitrary $value
and a closure. The $value
will be passed to the closure and then be returned by the tap
function. The return value of the closure is irrelevant:<?php $user = tap(User::first(), function ($user) {
$user->name = 'taylor';
$user->save();
});
<?php return Octane::invokeRoute($request, $request->getMethod(), '/'.$request->path());
}
return tap($this->sandbox->make(Kernel::class)->handle($request), function ($response) use ($request) {
$this->dispatchEvent($this->sandbox, new RequestHandled($this->sandbox, $request, $response));
});
}
<?php $record = $this->table->get($key);
if ($this->recordIsFalseOrExpired($record)) {
return tap($value, fn ($value) => $this->put($key, $value, static::ONE_YEAR));
}
return tap((int) (unserialize($record['value']) + $value), function ($value) use ($key, $record) {
<?php return tap($value, fn ($value) => $this->put($key, $value, static::ONE_YEAR));
}
return tap((int) (unserialize($record['value']) + $value), function ($value) use ($key, $record) {
$this->put($key, $value, $record['expiration'] - Carbon::now()->getTimestamp());
});
}
<?php protected function ensureRoadRunnerBinaryMeetsRequirements($roadRunnerBinary)
{
$version = tap(new Process([$roadRunnerBinary, '--version'], base_path()))
->run()
->getOutput();
<?php protected function downloadRoadRunnerBinary()
{
tap(new Process(array_filter([
(new PhpExecutableFinder)->find(),
'./vendor/bin/rr',
'get-binary',
'-n',
'--ansi',
]), base_path(), null, null, null))->mustRun(
fn ($type, $buffer) => $this->output->write($buffer)
);
<?php );
}
return tap(new Process([
(new ExecutableFinder)->find('node'),
'file-watcher.js',
json_encode(collect(config('octane.watch'))->map(fn ($path) => base_path($path))),
], realpath(__DIR__.'/../../../bin'), null, null, null))->start();
}
<?php ['roadrunner', 'swoole'],
);
return (int) ! tap(match ($server) {
'swoole' => $this->installSwooleServer(),
'roadrunner' => $this->installRoadRunnerServer(),
default => $this->invalidServer($server),
}, function ($installed) use ($server) {
if ($installed) {
$this->updateEnvironmentFile($server);
$this->callSilent('vendor:publish', ['--tag' => 'octane-config', '--force' => true]);
$this->info('Octane installed successfully.');
}
});
}
<?php $this->forgetEnvironmentVariables();
$server = tap(new Process(array_filter([
$roadRunnerBinary,
'-c', $this->configPath(),
'-o', 'http.address='.$this->option('host').':'.$this->option('port'),
'-o', 'server.command='.(new PhpExecutableFinder)->find().' ./vendor/bin/roadrunner-worker',
'-o', 'http.pool.num_workers='.$this->workerCount(),
'-o', 'http.pool.max_jobs='.$this->option('max-requests'),
'-o', 'rpc.listen=tcp://'.$this->option('host').':'.$this->rpcPort(),
'-o', 'http.pool.supervisor.exec_ttl='.$this->maxExecutionTime(),
'-o', 'http.static.dir=public',
'-o', 'http.middleware='.config('octane.roadrunner.http_middleware', 'static'),
'-o', 'logs.mode=production',
'-o', app()->environment('local') ? 'logs.level=debug' : 'logs.level=warning',
'-o', 'logs.output=stdout',
'-o', 'logs.encoding=json',
'serve',
]), base_path(), [
'APP_ENV' => app()->environment(),
'APP_BASE_PATH' => base_path(),
'LARAVEL_OCTANE' => 1,
]))->start();
$serverStateFile->writeProcessId($server->getPid());
<?php $this->forgetEnvironmentVariables();
$server = tap(new Process([
(new PhpExecutableFinder)->find(), 'swoole-server', $serverStateFile->path(),
], realpath(__DIR__.'/../../bin'), [
'APP_ENV' => app()->environment(),
'APP_BASE_PATH' => base_path(),
'LARAVEL_OCTANE' => 1,
]))->start();
return $this->runServer($server, $inspector, 'swoole');
}
<?php default => $this->invalidServer($server),
};
return ! tap($isRunning, function ($isRunning) {
$isRunning
? $this->info('Octane server is running.')
: $this->info('Octane server is not running.');
});
}
<?php {
$config = $event->sandbox->make('config');
tap($event->sandbox->make('translator'), function ($translator) use ($config) {
$translator->setLocale($config->get('app.locale'));
$translator->setFallback($config->get('app.fallback_locale'));
});
}
}
<?php public function handle($event): void
{
if ($event->exception) {
tap($event->sandbox, function ($sandbox) use ($event) {
if ($event->exception instanceof DdException) {
return;
}
if ($sandbox->environment('local', 'testing')) {
Stream::throwable($event->exception);
}
$sandbox[ExceptionHandler::class]->report($event->exception);
});
}
}
}
<?php ],
] = $this->serverStateFile->read();
tap($this->processFactory->createProcess([
$this->findRoadRunnerBinary(),
'reset',
'-o', "rpc.listen=tcp://$host:$rpcPort",
], base_path()))->start()->waitUntil(function ($type, $buffer) {
if ($type === Process::ERR) {
throw new RuntimeException('Cannot reload RoadRunner: '.$buffer);
}
<?php protected function bootWorker($server)
{
try {
return tap(new Worker(
new ApplicationFactory($this->basePath),
$this->workerState->client = new SwooleClient
))->boot([
'octane.cacheTable' => $this->workerState->cacheTable,
Server::class => $server,
WorkerState::class => $this->workerState,
<?php $exception = new Exception('foo');
$exceptionHandler = tap(Mockery::mock(ExceptionHandler::class), fn ($mock) => $mock
->shouldReceive('report')
->once()
->with($exception));
Mockery::mock('alias:'.Stream::class)
->shouldReceive('throwable')