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 Illuminate\Http\Client\Response;
use Rosalana\Core\Facades\Basecamp;

public function register()
{
    Basecamp::after('user.login', function (Response $response) {
        // Handle post-login logic
    });
}

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
}

App::context()->get(); // Get full app context
App::context()->put('app', ['foo' => 'bar']);

App::context()->put($user, ['foo' => 'bar']);
App::context()->get($user); // ['foo' => 'bar']
App::context()->get('user.1.foo'); // 'bar'
App::context()->get([User::class, 1]); // ['foo' => 'bar']
App::context()->get([User::class, 1, 'foo']); // 'bar'

// Find all users with a specific role
App::context()->find('user.*', ['role' => 'admin']);

// Find the first user with a specific role
[$key, $user] = App::context()->findFirst('user.*', ['role' => 'admin']);

App::context()->invalidate('user.1.foo'); // Remove only one attribute
App::context()->invalidate('user.1'); // Remove entire user context
App::context()->flush(User::class); // Flush all entries for the User class (not implemented yet)

App::hooks()->on('context:update', function ($data) {
    // Run custom logic after context is updated
});

App::hooks()->onContextUpdate(function ($data) {
    // works like above
});

App::hooks()->run('context:update', [
    'key' => 'context.app',
    'path' => 'foo',
    'value' => 'bar',
    'previous' => null,
]);
bash
php artisan rosalana:publish