PHP code example of jasminecms / jasmine

1. Go to this page and download the library: Download jasminecms/jasmine 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/ */

    

jasminecms / jasmine example snippets


Route::prefix('jasmine')->group(fn() => Jasmine::routes());

Route::prefix('jasmine')->group(fn() => Jasmine::apiRoutes());

Jasmine::registerLocales(['en', 'he']);

Jasmine::registerBreadable(\App\Models\MyModel::class);

Jasmine::registerPage(\App\Pages\Home::class);

Jasmine::registerInterfaceLocale('he', 'path/to/locale.json');

Jasmine::registerCustomStyle('/path/to/style.css');
Jasmine::registerCustomJs('/path/to/app.js');

// internal
\Jasmine::registerSideBarMenuItem('settings', fn() => [
    'title'    => __('Settings'),
    'icon'   => 'bi-link-45deg text-danger',
    'href'     => route('jasmine.my.route', 'my-param-value'),
    'is-route' => ['r' => 'jasmine.my.route', 'p' => ['my-param' => 'my-param-value']],
], 70);

// external
\Jasmine::registerSideBarMenuItem('site-triple', fn() => [
    'href'   => 'https://triple.co.il',
    'title'  => 'Triple',
    'icon'   => 'bi-link-45deg text-danger',
    'target' => '_blank',
], 100);

Jasmine::registerOauth2Sso(
    'Facebook', //name
    'https://www.facebook.com/images/fb_icon_325x325.png', //icon
    '{client_id}',
    '{client_secret}',
    'https://www.facebook.com/v3.3/dialog/oauth',
    'https://graph.facebook.com/v3.3/oauth/access_token',
    ['email'],
    false, // accepts boolean or callback
    function ($token) {
        $token = json_decode($token, true);
        
        $res = Http::asJson()->get('https://graph.facebook.com/v3.3/me', [
            'access_token' => $token['access_token'],
            'fields'       => 'name,email',
        ]);
        
        return [
            'name'  => $res->json('name'),
            'email' => $res->json('email'),
        ];
    },
);

        Jasmine::registerTranslationService('ai', function (string $source, string $target, array $values) {
            $data = array_combine(array_keys($values), array_column($values, 'value'));

            $lc2Label = function (string $lc) {
                return match ($lc) {
                    'en' => 'English',
                    'he' => 'Hebrew',
                    default => $lc,
                };
            };

            $fromLang = $lc2Label($source);
            $toLang = $lc2Label($target);

            $req = Prism::text()
                ->using(Provider::Gemini, 'gemini-2.0-flash')
                ->withMaxTokens(32768)
                ->withSystemPrompt(implode(' ', [
                    'You are a professional translator,',
                    'you try to use a gender neutral language when possible,',
                    'you have a good understanding of JSON objects',
                    'no notes, comments, explanations or other information, just JSON',
                ]))
                ->withMessages([
                    new UserMessage("Translate my JSON object from $fromLang to $toLang, translate all values only (not keys), leave any urls untouched"),
                    new UserMessage(json_encode($data, JSON_UNESCAPED_UNICODE)),
                ]);

            $res = $req->asText();

            preg_match('#\{(?:[^{}]|(?R))*\}#s', $res->text, $matches);
            $translated = json_decode($matches[0] ?? '{}', true);

            return $translated;
        });