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
, andtmpDir
with ease. - Resource Metadata Generator: Use a generator to efficiently fetch metadata for resources in your application.
The Meta
class provides access to application metadata, including directory paths:
use BEAR\AppMeta\Meta;
// Initialize with your application's namespace
$appMeta = new Meta('MyVendor\HelloWorld');
// Access metadata properties
echo $appMeta->name; // MyVendor\HelloWorld
echo $appMeta->appDir; // /path/to/MyVendor/HelloWorld/src
echo $appMeta->logDir; // /path/to/MyVendor/HelloWorld/var/log
echo $appMeta->tmpDir; // /path/to/MyVendor/HelloWorld/var/tmp
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
}