Installation:
composer require symfony-cmf/resource
Ensure your project uses PHP 7.1/7.2 and Symfony (tested with Symfony 4.x, though legacy support exists).
Dependencies:
puli and phpcr_odm bundles in config/bundles.php:
return [
// ...
Symfony\Cmf\Resource\PuliResourceBundle::class => ['all' => true],
Symfony\Cmf\Bundle\PhpcrBundle\PhpcrBundle::class => ['all' => true],
Puli\Bundle\PuliBundle::class => ['all' => true],
];
First Use Case: Locate a resource (e.g., a document) from PHPCR using Puli:
use Symfony\Cmf\Resource\PuliResource\PuliResourceLocator;
use Puli\Resource\ResourceInterface;
$locator = $container->get(PuliResourceLocator::class);
$resource = $locator->getResource('/path/to/document.xml'); // Returns ResourceInterface
Resource Resolution:
PuliResourceLocator to fetch resources from PHPCR via Puli.$resource = $locator->getResource('/templates/home.html.twig');
$content = $resource->getContent(); // Stream or string content
Integration with Symfony Components:
{{ resource.content|raw }} {# Render raw content #}
$response = new StreamedResponse(function () use ($resource) {
$resource->rewind();
stream_copy_to_stream($resource, $this->get('response')->getBody());
});
Event-Driven Extensions:
puli.resource.located events to intercept/resource resolution:
$dispatcher->addListener('puli.resource.located', function (ResourceLocatedEvent $event) {
if ($event->getResource()->getPath() === '/special/path') {
$event->setResource($customResource);
}
});
PHPCR + Puli Sync:
PuliResourceManager to sync PHPCR nodes with Puli resources:
$manager = $container->get('puli.resource.manager');
$manager->sync(); // Syncs PHPCR changes to Puli
ResourceLocator implementations for non-PHPCR backends (e.g., filesystem).ResourceInterface in unit tests:
$mockResource = $this->createMock(ResourceInterface::class);
$mockResource->method('getContent')->willReturn('mocked content');
Deprecation Warnings:
AssetComponent for static assets.ClassNotFoundException for internal APIs).PHPCR Dependency:
// Throws if PHPCR session is invalid
$locator->getResource('/nonexistent/path');
Resource Paths:
/path/) vs. no slashes (/path) may cause ResourceNotFoundException.Event System:
puli.resource.located are internal and may change. Avoid relying on them in production.Enable Puli Debugging:
# config/packages/puli.yaml
puli:
debug: true
Logs resource resolution steps to Symfony’s debug toolbar.
Check PHPCR Session: Verify the session is active:
$session = $container->get('phpcr.odm.session');
if (!$session->isLive()) {
throw new \RuntimeException('PHPCR session is not connected!');
}
Custom Resource Locators:
Extend AbstractResourceLocator to support new backends:
class CustomLocator extends AbstractResourceLocator
{
public function getResource($path)
{
return new FilesystemResource('/custom/path/' . $path);
}
}
Puli Resource Adapters:
Create adapters to bridge other storage systems (e.g., S3) with Puli’s ResourceInterface.
Configuration Overrides:
Override Puli’s default resource manager in config/packages/puli.yaml:
puli:
resource_manager: your_custom.manager.service_id
ResourceInterface Polymorphism:
Implement custom methods on your resource classes (e.g., getMetadata()) for domain-specific logic.$resources = $locator->getResources(['/path1', '/path2']);
Symfony\Component\Asset\Packages for hybrid PHPCR/filesystem setups.How can I help you explore Laravel packages today?