bear / app-meta
AppMeta is a utility class that manages application metadata such as directory paths and resource information. It provides easy access to application directories (appDir, logDir, tmpDir) and resource metadata via a generator.
Requires
- php: ^8.1
- bear/resource: ^1.0
- koriym/psr4list: ^1.0.2
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.4
- phpunit/phpunit: ^9.6
This package is auto-updated.
Last update: 2026-08-24 00:23:38 UTC
README
BEAR.AppMeta is a lightweight library for managing application metadata in PHP. It provides a simple way to access application directory paths and resource metadata, making it easier to organize and retrieve essential information about your application.
Features
- Application Metadata Management: Retrieve directory paths such as
appDir,logDir,tmpDir, andbuildDirwith ease. - Resource Metadata Generator: Use a generator to efficiently fetch metadata for resources in your application.
Usage
Accessing Application Metadata
use BEAR\AppMeta\Meta; $appMeta = new Meta('MyVendor\HelloWorld');
name— the application namespace (MyVendor\HelloWorld)appDir— the application directorytmpDir— data the running application writeslogDir— log filesbuildDir— artifacts a build generates once and every run reads (compiled DI scripts, templates)
Pass $appDir, $tmpDir or $logDir to the constructor to override. Meta::create() takes a writable base for a read-only tree or an archive:
$appMeta = Meta::create('MyVendor\HelloWorld', 'prod-app', $appDir, '/mnt/write');
Environment reading belongs to the application, not Meta.
Libraries: take paths from the injected Meta
Do not bind a path read from a Meta into compiled or cached code - the artifact may run somewhere else. Inject AbstractAppMeta and read paths at runtime; a restored Meta re-points them to the current location.
Fetching Resource Metadata
Use the getGenerator() method to retrieve metadata for resources. This method returns a generator, making it memory-efficient for large applications.
// Fetch metadata for all resources foreach ($appMeta->getGenerator('*') as $resourceMeta) { var_dump($resourceMeta->uriPath); // app://self/one var_dump($resourceMeta->class); // FakeVendor\HelloWorld\Resource\App\One var_dump($resourceMeta->file); // /path/to/src/Resource/App/One.php } // Fetch metadata for resources in the 'app' namespace foreach ($appMeta->getGenerator('app') as $resourceMeta) { var_dump($resourceMeta->uriPath); // /one var_dump($resourceMeta->class); // FakeVendor\HelloWorld\Resource\App\One var_dump($resourceMeta->file); // /path/to/src/Resource/App/One.php }