PHP code example of nubitio / admin-bundle

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

    

nubitio / admin-bundle example snippets


use ApiPlatform\Metadata\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Nubit\ApiPlatform\Doctrine\Money\MoneyColumns;
use Nubit\Platform\Money\Money;
use Symfony\Component\Serializer\Attribute\Ignore;

#[ApiResource]
class Invoice
{
    // Name the embedded property something other than the exposed field, mark
    // it #[Ignore], and set columnPrefix — see MoneyColumns for why.
    #[ORM\Embedded(class: MoneyColumns::class, columnPrefix: 'total_')]
    #[Ignore]
    private MoneyColumns $totalColumns;

    public function getTotal(): ?Money
    {
        return $this->totalColumns->toMoney();
    }

    public function setTotal(?Money $total): void
    {
        $this->totalColumns = MoneyColumns::fromMoney($total);
    }
}

$unit  = Money::of('19.99', 'EUR');
$line  = $unit->multipliedBy(3);                          // exact, no rounding needed
$tax   = $line->multipliedBy('0.21', RoundingMode::HalfUp);
$total = $line->plus($tax);

// Splitting without losing a cent:
[$a, $b, $c] = $total->allocate([1, 1, 1]);               // always sums back to $total

#[ApiResource(
    order: ['id' => 'DESC'],
    paginationPartial: true,
    paginationViaCursor: [['field' => 'id', 'direction' => 'DESC']],
)]
#[ApiFilter(RangeFilter::class, properties: ['id'])]
#[ApiFilter(OrderFilter::class, properties: ['id' => 'DESC'])]
#[GridScale(cursorField: 'id', exactCount: false, inlineExportLimit: 5000)]
class StockMovement { … }

#[ApiResource]                       // → invoice.read, invoice.create, invoice.update, invoice.delete
#[Authorized(actions: ['approve'], limited: ['approve' => 'total'])]
class Invoice { … }

#[RowScoped(field: 'warehouse', claim: 'warehouses')]
class StockMovement { … }

$this->denyAccessUnlessGranted('invoice.approve', $invoice);

#[ApiResource]
#[Printable(template: InvoiceTemplate::class, numberProperty: 'number')]
class Invoice { … }

final class InvoiceTemplate implements DocumentTemplateInterface
{
    public function render(object $resource, DocumentRenderContext $context): string
    {
        // Return HTML. The context carries the document number, the issue
        // instant and the display timezone, so the same template renders
        // identically from a request, a worker and a test.
    }
}

#[ApiResource]
#[Importable(fields: ['sku', 'name', 'price'], naturalKey: ['sku'], 

#[EmbeddedLines(
    parentProperty: 'document',
    normalizationGroups: ['document:read'],
)]
#[ORM\Entity]
class SalesDocumentLine { ... }

// src/Runtime/AppRuntimeConfigProvider.php
final readonly class AppRuntimeConfigProvider implements RuntimeConfigProviderInterface
{
    public function getConfig(): array
    {
        return [
            'ui' => ['showBranchPicker' => false],
            'defaults' => ['currency' => 'USD'],
        ];
    }
}

#[Auditable]                       // or #[Auditable(resource: 'products')]
#[ORM\Entity]
class Product { ... }

use Nubit\ApiPlatform\Attribute\Exportable;

#[ApiResource]
#[ApiFilter(DataGridFilter::class)]
#[Exportable]
class Product { /* … */ }

#[Exportable(operations: ['_api_/products{._format}_get_collection'])]  // collection only

use Nubit\Platform\Notification\Contract\NotificationDispatcherInterface;
use Nubit\Platform\Notification\NotificationMessage;

$dispatcher->dispatch(new NotificationMessage(
    recipient: $user->getUserIdentifier(),   // a plain identifier string, not a User FK
    subject: 'Invoice INV-0042 confirmed',
    body: 'The invoice was confirmed and is awaiting payment.',
    channels: ['email', 'in_app'],           // [] means every registered channel
    context: ['html' => $renderedHtml],      // channel-specific extras
));
yaml
nubit_admin:
    resource: '@NubitAdminBundle/config/routes.php'
bash
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
yaml
nubit_admin:
    backup:
        enabled: true
        storage:
            filesystem: null          # FilesystemOperator service id; overrides local_directory
            local_directory: '%kernel.project_dir%/var/backups'
        pg_dump_binary: pg_dump       # must be on PATH
        timeout_seconds: 300