1. Go to this page and download the library: Download rosalana/core library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rosalana / core example snippets
namespace Rosalana\Core\Providers;
use Rosalana\Core\Contracts\Package;
class Core implements Package
{
public function resolvePublished(): bool
{
// Self determining if the package is published
}
public function publish(): array
{
// Define what publish and how
// (CLI will handle publish all automatically)
return [
'stuff' => [
'label' => 'Publish some stuff',
'run' => function () {
// Process publishing...
}
],
];
}
}
use Rosalana\Core\Facades\Trace;
Trace::start('operation.name');
// Your operation logic here
$trace = Trace::finish();
$phase = Trace::phase('sub-operation');
// Your sub-operation logic here
$phase->close(); // Optional manual close
use Rosalana\Core\Services\Basecamp\Service;
class UsersService extends Service
{
public function find(int $id)
{
return $this->manager
->withAuth()
->get("users/{$id}");
}
public function all()
{
return $this->manager
->withAuth()
->get('users');
}
}
use Rosalana\Core\Services\Basecamp\Manager;
public function register()
{
$this->app->resolving('rosalana.basecamp', function (Manager $manager) {
$manager->registerService('users', new UsersService());
});
}
Basecamp::timeout(10); // Set custom timeout (seconds)
Basecamp::retry(3); // Retry failed requests (times)
Basecamp::ghost(); // Skip onSuccess callback
Basecamp::version('v2'); // Use specific API version
Basecamp::mock(); // Mock the request (for testing)
Basecamp::fallback(function (\Exception $e) {
return SomeResponse; // Return a Response instance to recover
})->get('/users');
use Rosalana\Core\Facades\Outpost;
Outpost::to('app-slug');
Outpost::to(['app1', 'app2']);
Outpost::broadcast(); // to all apps except yourself
Outpost::broadcast()->except('app-slug'); // to all except specific app
public function request(Message $message)
{
// You can quickly respond to the sender
$message->confirm([...]);
$message->fail([...]);
$message->unreachable([...]);
// Check if the message is from a specific app
$message->isFrom('app-slug');
$message->payload('key', 'default');
// Get the promise of the message (for advanced usage)
// you can override the promises or reject them
$message->promise();
}
public function register()
{
Outpost::receive('group.action:status', function (Message $message) {
// Handle incoming request
});
Outpost::receiveSilently('group.action:status', function (Message $message) {
// Handle incoming request silently
});
}
Outpost::receive('group.action:status', function (Message $message) {
return $message->event(function (Message $message) {
// Handle the event logic here
})->broadcast();
});
use Rosalana\Core\Services\Outpost\Service;
use Rosalana\Core\Services\Outpost\Message;
class ProjectService extends Service
{
public function link(string $target, array $payload)
{
return $this->manager
->to($target)
->request('project.link', $payload)
->onConfirm(function (Message $message) {
// Handle confirmation
});
}
}
use Rosalana\Core\Services\Outpost\Manager;
public function register()
{
$this->app->resolving('rosalana.outpost', function (Manager $manager) {
$manager->registerService('project', new ProjectService());
});
}
$scope->get('foo', 'default'); // Get value with default
$scope->put('nested.foo', 'bar'); // Set value
$scope->has('foo'); // Check if key exists
$scope->receive(); // Get all data in the scope
App::context()->all(); // Get full app context
App::context()->raw(); // Get raw Redis data
$scope->forget('foo'); // Remove only one attribute
$scope->clear(); // Remove whole scope
App::context()->flush(); // Remove whole context
// In rosalana/roles — without dependency on rosalana/accounts
Event::listen('Rosalana\\Accounts\\Events\\UserLoggedIn', function ($event) {
// React to user login
});
use Rosalana\Core\Events\ContextUpdated;
use Illuminate\Support\Facades\Event;
Event::listen(ContextUpdated::class, function (ContextUpdated $event) {
logger("Context updated: {$event->path} in scope {$event->scope}");
});
bash
php artisan rosalana:publish
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.