PHP code example of bannerstop / planar

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

    

bannerstop / planar example snippets


use Bannerstop\Planar\Contract\PlanarInterface;
use Bannerstop\Planar\Factory\PlanarFactory;
use Bannerstop\Planar\Factory\ItemFactory;
use Bannerstop\Planar\Factory\OnlineDesignerFactory;
use Bannerstop\Planar\Factory\PageFactory;
use Bannerstop\Planar\Factory\BoxFactory;

// Initialize Factories
$planarFactory = new PlanarFactory();
$itemFactory = new ItemFactory();
$pageFactory = new PageFactory();
$boxFactory = new BoxFactory();
$onlineDesignerFactory = new OnlineDesignerFactory();

// Create a Page with bleed and safety distance
$bleed = $boxFactory->create(top: 5, right: 5, bottom: 5, left: 5); // 5mm all sides
$safetyDistance = $boxFactory->create(top: 10, right: 10, bottom: 10, left: 10);
$page = $pageFactory->create(
    width: 1000,
    height: 2000,
    label: 'Front',
    bleed: $bleed,
    safetyDistance: $safetyDistance
);

// Create an Item
$onlineDesigner = $onlineDesignerFactory->create(enabled: true, webProductId: 123, templateId: 456);
$item = $itemFactory->create(
    spark: 'spark_code_123',
    onlineDesigner: $onlineDesigner,
    itemNo: 1,
    sku: 'SKU-BANNER-1',
    name: 'Custom Vinyl Banner',
    quantity: 1,
    thumbnail: null,
    printable: true,
    subtotal: 49.99,
    currency: 'EUR',
    details: [], // Details
    pages: [$page] // Pages
);

// Final Planar Object
$planar = $planarFactory->create(
    version: PlanarInterface::VERSION,
    items: [$item]
);

use Bannerstop\Planar\Service\PlanarSerializerService;

$serializerService = new PlanarSerializerService();

// Serialize to JSON
$json = $serializerService->serialize(planar: $planar);
echo $json;

// Deserialize from JSON
$deserializedPlanar = $serializerService->deserialize(json: $json);

use Bannerstop\Planar\Contract\PlanarInterface;
use Bannerstop\Planar\Contract\ItemInterface;

function processPrintOrder(PlanarInterface $planar) {
    echo "PLANAR version: " . $planar->getVersion() . PHP_EOL;

    foreach ($planar->getItems() as $item) {
        if ($item->isPrintable()) {
            echo "Processing printable item: " . $item->getName() . PHP_EOL;
        }
    }
}