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.
- 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.
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.
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.
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
}
