Installation:
composer require denisyu-1/articulate-symfony
Ensure Articulate\Symfony\ArticulateSymfonyBundle is enabled in config/bundles.php.
Configuration:
Create config/packages/articulate.yaml with a basic setup:
articulate:
connection:
dsn: '%env(resolve:DATABASE_URL)%'
paths:
entities: '%kernel.project_dir%/src/Entity'
migrations: '%kernel.project_dir%/migrations/Articulate'
First Use Case:
Define an entity (e.g., src/Entity/Book.php):
namespace App\Entity;
use Articulate\Modules\Entity\Entity;
#[Entity]
class Book
{
#[Id]
private int $id;
#[Column]
private string $title;
}
Run migrations:
bin/console articulate:migrate
EntityManager: Inject EntityManager into services for CRUD operations:
use Articulate\Modules\EntityManager\EntityManager;
final class BookService
{
public function __construct(private EntityManager $em) {}
public function createBook(string $title): Book
{
$book = new Book();
$book->title = $title;
$this->em->persist($book);
$this->em->flush();
return $book;
}
}
Connection: Use Articulate\Connection for raw queries:
use Articulate\Connection;
final class RawQueryService
{
public function __construct(private Connection $connection) {}
public function fetchBooks(): array
{
return $this->connection->query('SELECT * FROM books')->fetchAll();
}
}
Entity Lifecycle:
#[Entity], #[Id], and #[Column] attributes.EntityManager::persist(), flush(), and remove() for changes.Migrations:
bin/console articulate:diff.bin/console articulate:migrate.Validation:
bin/console articulate:validate.Caching:
result, statement) for performance.Symfony Forms: Bind entities to forms using EntityType:
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
$builder->add('book', EntityType::class, [
'class' => Book::class,
'choice_label' => 'title',
]);
Doctrine Bridge: If using Doctrine, map Articulate entities to Doctrine entities for hybrid workflows (requires custom logic).
Entity Naming:
Book → books). Override with #[Table(name: "custom_name")].Migration Conflicts:
articulate:diff before articulate:migrate to avoid schema mismatches.Caching Quirks:
cache:clear) after schema changes to avoid stale queries.second_level_ttl) may cause stale data if TTL is too long.Debugging:
logging: enabled: true) for SQL queries and errors.bin/console articulate:validate to catch entity definition issues early.Custom Attributes:
Extend Articulate’s attributes (e.g., #[Index], #[Unique]) for advanced schema control.
Environment-Specific Configs:
Override articulate.yaml per environment (e.g., articulate_test.yaml) for testing.
Event Listeners:
Attach listeners to EntityManager for pre/post-persist/remove logic:
$em->getEventManager()->addEventListener(
EntityEvents::PRE_PERSIST,
fn($event) => $event->getEntity()->setCreatedAt(new \DateTime())
);
Performance:
EntityManager::createQueryBuilder() for complex queries:
$books = $this->em->createQueryBuilder(Book::class)
->where('title LIKE :title')
->setParameter('title', '%PHP%')
->getQuery()
->getResult();
Testing:
EntityManager::beginTransaction()/rollback() for transactional tests:
$this->em->beginTransaction();
try {
$this->em->persist($book);
$this->em->flush();
$this->em->commit();
} catch (\Exception $e) {
$this->em->rollback();
}
How can I help you explore Laravel packages today?