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.
Installs: 432 354
Dependents: 11
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- php: ^8.0
- bear/resource: ^1.0
- koriym/psr4list: ^1.0.2
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.4
- phpunit/phpunit: ^9.5.10
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
, andtmpDir
with ease. - Resource Metadata Generator: Use a generator to efficiently fetch metadata for resources in your application.
Usage
Accessing Application Metadata
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
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 }