- What does puli/url-generator actually do?
- It provides a small abstraction layer that converts Puli resource paths, such as /app/assets/css/style.css, into public URLs that a browser or HTTP client can request. Instead of hardcoding web paths, your code asks a URL generator implementation for the address of a logical resource. The package itself defines the interfaces and integration points rather than a full asset pipeline, so you pair it with a Puli repository and a server or CDN that exposes those resources.
- How do I install puli/url-generator with Composer?
- Install it with composer require puli/url-generator, ideally pinning a version that matches the rest of your Puli packages. Because Puli components are versioned together, check the Composer constraints of puli/manager and any Puli integration you use before upgrading. After installation, run composer dump-autoload if you are not using an optimized autoloader already.
- Does puli/url-generator work with Laravel?
- The package is framework-agnostic: it defines URL generator interfaces that any PHP application can consume, and Laravel is no exception. In a Laravel app you typically bind the generator interface in a service provider and resolve it from the container, or use an existing Puli bridge package to do that wiring for you. There is no Laravel-specific facade shipped inside this package, so expect to write a thin binding yourself.
- How do I configure which URL a Puli resource maps to?
- Configuration lives in the URL generator implementation, not in the interface. A typical setup pairs a Puli repository (which resolves logical resource names to files) with a generator that knows a public base path or host, then appends the resource's path. You register that generator in your service container or bootstrap file so the rest of your code can depend on the interface instead of a concrete class.
- What is the difference between a Puli resource path and a public URL?
- A Puli resource path is a logical name inside your repository, like /app/assets/logo.png, and it is meaningful only to Puli. A public URL is the actual web address a browser uses, which depends on your document root, asset publishing step, or CDN configuration. The URL generator is the bridge between the two, so code can reference resources without knowing where they are physically served from.
- Can I use puli/url-generator to serve assets from a CDN or a different environment?
- Yes, that is the main reason to depend on the abstraction. Because callers only see the URL generator interface, you can swap in an implementation that prefixes a CDN host, a versioned asset directory, or a staging domain without touching application code. This keeps local, staging, and production environments consistent while resource paths stay unchanged.
- Which PHP and Laravel versions are supported?
- Support is determined by the package's composer.json, so check the require section on Packagist for the exact PHP constraint of the release you install. Puli packages were developed in the PHP 5.5 to 7.x era, so older releases may not declare compatibility with modern PHP versions. In a current Laravel project, verify the constraint first and consider whether a maintained asset helper better fits your stack.
- How do I test code that depends on the URL generator interfaces?
- Because the package exposes interfaces, you can create a simple test double that returns a fixed URL for a given resource path and inject it in your tests. That keeps unit tests fast and avoids booting a real Puli repository or filesystem. For integration tests, use a real repository pointed at a fixture directory and assert the generated URLs match the expected public paths.
- Is puli/url-generator maintained, and is it safe for production?
- This package comes from the Puli ecosystem, which has seen little to no recent development, so treat it as a legacy dependency rather than an actively maintained one. The code surface is small and interface-driven, which limits risk, but you should audit the specific version and avoid relying on it for new long-term projects. If you adopt it, pin the version and keep a fallback plan for replacing the abstraction.
- What are the alternatives to puli/url-generator?
- For Laravel applications, the built-in asset() and URL helpers, or packages such as laravel mix, Vite integration, or flysystem-based asset managers, usually cover the same ground with active maintenance. If you only need to map logical names to URLs, a small custom URL generator class implementing your own interface is often simpler than pulling in the Puli stack. Choose Puli specifically when you already use Puli repositories and want resource-aware URL resolution across environments.