PHP code example of shyguy81 / food-choice-core

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

    

shyguy81 / food-choice-core example snippets


use Shyguy\FoodChoiceCore\Service\SuggestionEngine;
use Shyguy\FoodChoiceCore\Port\RepositoryInterface;

// Injecter un adapter implémentant RepositoryInterface
$repo = ...;
$engine = new SuggestionEngine($repo);
$suggestion = $engine->suggestOne();

use Shyguy\FoodChoiceCore\Service\WeeklyMenuService;
use Shyguy\FoodChoiceCore\Service\FoodSearchService;

$repo = /* implémentation de RepositoryInterface */;

$weekly = new WeeklyMenuService($repo);
$menu = $weekly->generateWeeklyMenu(14);
foreach ($menu as $day => $food) {
	echo $day . ': ' . ($food?->name ?? 'Pas de suggestion') . "\n";
}

$search = new FoodSearchService($repo);
foreach ($search->searchByName('pizza', 5) as $f) {
	echo $f->name . " ({$f->category})\n";
}