generated from boboko/starter
Feat: Updating COntrollers to remove business logic moved to boboko/core
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Catalog;
|
||||
|
||||
/**
|
||||
* Presentation shaping — how a product listing/grid card is built from
|
||||
* ProductService's localized array shape (list()/getById()/random() all
|
||||
* return it). Deliberately not in boboko-core: `href` depends on this
|
||||
* storefront's own routes, and another app built on the same core package
|
||||
* could want an entirely different card shape. Kept in one place so
|
||||
* HomeController/CategoryController don't each hand-write the same
|
||||
* name/price/image/href mapping.
|
||||
*/
|
||||
final class ProductCard
|
||||
{
|
||||
/**
|
||||
* @param array $product One item from ProductService's localized array shape.
|
||||
* @return array{name: ?string, price: ?float, image: ?string, href: string}
|
||||
*/
|
||||
public static function fromIndexed(array $product): array
|
||||
{
|
||||
return [
|
||||
'name' => $product['name'],
|
||||
'price' => $product['price'],
|
||||
'image' => $product['media'][0]['url'] ?? null,
|
||||
'href' => route('product.show', ['id' => $product['id']]),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user