PHP code example of matatirosoln / doctrine-odata-bundle
1. Go to this page and download the library: Download matatirosoln/doctrine-odata-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/ */
matatirosoln / doctrine-odata-bundle example snippets
use Matatirosoln\DoctrineOdataBundle\Service\ScriptService;
class MyController
{
public function __construct(private readonly ScriptService $scripts) {}
public function run(): void
{
// Plain string parameter
$result = $this->scripts->run('SendWelcomeEmail', '[email protected]');
// Array parameter — automatically JSON-encoded
$result = $this->scripts->run('ProcessOrder', [
'orderId' => 'abc-123',
'notify' => true,
]);
// No parameter
$result = $this->scripts->run('NightlyCleanup');
}
}
use Matatirosoln\DoctrineOdataBundle\Exception\ScriptException;
try {
$this->scripts->run('ValidateRecord', $id);
} catch (ScriptException $e) {
// $e->scriptName — the script that was called
// $e->scriptCode — the non-zero result code returned by FileMaker
// $e->resultParameter — the raw result parameter string from FileMaker
}
use Matatirosoln\DoctrineOdataBundle\Service\ContainerService;
use Matatirosoln\SqlToOdata\Support\KeyValue;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/document')]
class DocumentController extends AbstractController
{
public function __construct(private readonly ContainerService $containers) {}
// Download the raw bytes of a container field and return them as a response
#[Route('/{id}/download', name: 'document_download')]
public function download(string $id, Document $document): Response
{
$content = $this->containers->download($document->attachment);
return new Response($content, Response::HTTP_OK, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="document.pdf"',
]);
}
// Stream a large file directly to the browser without loading it into memory
#[Route('/{id}/stream', name: 'document_stream')]
public function stream(string $id, Document $document): StreamedResponse
{
return new StreamedResponse(function () use ($document) {
$this->containers->downloadToStream($document->attachment, fopen('php://output', 'wb'));
}, Response::HTTP_OK, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="document.pdf"',
]);
}
// Upload binary content from a request to a container field
#[Route('/{id}/upload', name: 'document_upload', methods: ['POST'])]
public function upload(string $id, Request $request): Response
{
$content = $request->getContent();
$keyValue = new KeyValue($id, quoted: true);
$this->containers->upload('Document', $keyValue, 'Attachment', $content, 'application/pdf');
return new Response(null, Response::HTTP_NO_CONTENT);
}
// Upload directly from a file path (MIME type auto-detected if omitted)
#[Route('/{id}/upload-file', name: 'document_upload_file', methods: ['POST'])]
public function uploadFile(string $id, string $filePath): Response
{
$keyValue = new KeyValue($id, quoted: true);
$this->containers->uploadFile('Document', $keyValue, 'Attachment', $filePath);
return new Response(null, Response::HTTP_NO_CONTENT);
}
}
use Matatirosoln\DoctrineOdataBundle\Service\ValueListService;
class MyFormType extends AbstractType
{
public function __construct(private readonly ValueListService $valueLists) {}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('status', ChoiceType::class, [
'choices' => $this->valueLists->get('Status'),
// returns e.g. ['Active' => 'Active', 'Inactive' => 'Inactive']
]);
$builder->add('assignee', ChoiceType::class, [
'choices' => $this->valueLists->choices('Users'),
// dynamic list: ['Alice Smith' => 'uuid-...', 'Bob Jones' => 'uuid-...']
]);
}
}
use Matatirosoln\DoctrineOdataBundle\Service\EntityGeneratorService;
$plan = $this->generator->plan('Users', 'Users\User');
// Inspect the plan before writing
echo $plan->entityClass; // App\Entity\Users\User
echo $plan->entityCode; // rendered PHP source
// Write files to disk
$this->generator->writeFile($plan->entityFile, $plan->entityCode);
$this->generator->writeFile($plan->repositoryFile, $plan->repositoryCode);
#[ORM\Table(name: 'User')]
#[ORM\Entity(repositoryClass: UserRepository::class)]
class User
{
#[ORM\Id]
#[ORM\Column(name: '__pk_UserID', type: Types::GUID)]
public private(set) string $id {
get => $this->id;
set => $this->id = $value;
}
#[ORM\Column(name: 'Name', type: Types::STRING, length: 255)]
public string $name {
get => $this->name;
set => $this->name = trim($value);
}
#[ORM\Column(name: 'City', type: Types::STRING, length: 255)]
public string $city {
get => $this->city;
set => $this->city = trim($value);
}
public function __construct(string $id)
{
$this->id = $id;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.