PHP code example of rosalana / core

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


use Rosalana\Core\Support\Config;

// Add or update a config section
Config::new('basecamp')
    ->add('secret',"env('ROSALANA_APP_SECRET', 'secret')")
    ->comment(
        'Connection settings for Basecamp (central server).',
        'Basecamp Connection'
    )
    ->save();

// Update a published version tag
Config::get('published')
    ->set('rosalana/xx', '1.0.0')
    ->save();

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\Pipeline;

Pipeline::resolve('user.login')->extend(MyLoginHandler::class);

use Rosalana\Core\Facades\Pipeline;

Pipeline::extendIfExists('user.login', fn ($response, $next) => /* do something */);

use Rosalana\Core\Facades\Pipeline;

Pipeline::resolve('user.login')->run($request);

$response = Basecamp::get('/users/1');

$response = Basecamp::withAuth()
    ->withPipeline('user.login')
    ->post('/login', $credentials);

$response = Basecamp::to('app-name')
    ->withAuth()
    ->post('/projects', $payload);

$response = Basecamp::to('app-name')
    ->users()
    ->find(1);

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()
            ->withPipeline('user.login')
            ->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::users()->get(1);
Basecamp::users()->login(['email' => '[email protected]', 'password' => '...']);

use Rosalana\Core\Facades\Outpost;

// Send to all apps (except yourself)
Outpost::send('user.registered', [
    'email' => '[email protected]',
]);

// Send to a specific app
Outpost::to('app')->send('user.registered', [...]);

// Send to multiple apps
Outpost::to(['app1', 'app2'])->send('user.registered', [...]);

// Send to all except specific apps
Outpost::except('app')->send('user.registered', [...]);

Outpost::receive('user.registered', App\Listeners\UserRegisteredListener::class);

// Only receive from one app
Outpost::from('app')->receive('user.registered', ...);

// Receive from multiple apps
Outpost::from(['app1', 'app2'])->receive('user.registered', ...);

// Receive from all apps except one
Outpost::except('app')->receive('user.registered', ...);

$packet->alias; // e.g. 'user.registered'
$packet->origin; // the app that sent the packet
$packet->target; // the app that should receive the packet
$packet->user(); // the basecamp user|null
$packet->payload; // data sent in the packet

public function handle(Packet $packet)
{
    $email = $packet->payload['email'];
    $localUser = Accounts::users()->toLocal($packet->user()); // return local user|null
}
bash
php artisan rosalana:publish