PHP code example of damarbob / starcore

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

    

damarbob / starcore example snippets


// app/Config/Star.php

protected string $activeModules = 'Blog,Auth,Shop';

protected string $activeDevModules = 'DebugToolbar,Generator';

public bool $safeMode = true;

use StarCore\Service\HyperHooks;

// Register an action (side-effect)
HyperHooks::getInstance()->register('user.login', function($user) {
    log_message('info', 'User logged in: ' . $user->id);
});

// Register a filter (modify value)
HyperHooks::getInstance()->register('content.render', function($content) {
    return strtoupper($content);
});

// Trigger an action
$hooks = service('hooks');
$hooks->action('user.login', [$currentUser]);

// Apply filters
$content = "hello world";
$content = $hooks->filter('content.render', $content); // Returns "HELLO WORLD"

// Returns the value of 'header' from 'Hooks/Frontend.php'
$headerHook = hook('Frontend.header');



use StarCore\Star\HyperHook;

return [
    'header' => new HyperHook('header', 'Header Hook', 'This hook is used to display the header.'),
    'footer' => new HyperHook('footer', 'Footer Hook', 'This hook is used to display the footer.'),
];

// modules/Blog/Hooks/Greetings.php
return [
    'welcome' => new HyperHook('welcome', 'Welcome Message', 'Welcome back, {name}!'),
];

// Returns "Welcome back, John!"
echo hook('Greetings.welcome', ['name' => 'John']);

modules/
  Blog/
    Config/
      Routes.php
    Controllers/
    Models/
    Views/
    Hooks/
    init.php

modules/
  .star-dev/
    DebugToolbar/
      Config/
        Routes.php
      Controllers/
      Models/
      Views/
      Hooks/
      init.php