PHP code example of mades / summer-craft-service-hub

1. Go to this page and download the library: Download mades/summer-craft-service-hub 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/ */

    

mades / summer-craft-service-hub example snippets


$config->services[Logger::class] = ComponentConfig::forClass(FileLogger::class);
$config->services[HtmlParser::class] = ComponentConfig::forClass(DomHtmlParser::class);

class Article extends Record
{
    public ?int $id = null;
    public string $title = '';
    public string $body = '';
}

/** @extends RelationalStorage<Article> */
class ArticleRepository extends RelationalStorage
{
    public function __construct(RequestScope $scope)
    {
        parent::__construct($scope, new RelationalStorageConfig(
            Article::class,
            RelationalDatabaseHandler::class, // which handler service to run on
            'articles',
            'id',
            ['id'],
        ));
    }

    public function newInstance(): Article
    {
        return Article::emptyRecord();
    }
}

$repository = $scope->get(ArticleRepository::class);

$article = $repository->findOne(['id' => 42]);
$recent = $repository->find(
    ['published' => 1],
    ['order' => ['id' => 'desc'], 'limit' => ['count' => 10]],
);

$article->title = 'Renamed';
$repository->save($article);

$scope->get(Logger::class)->info('Article saved', ['id' => $article->id]);