Ubuntu

­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ # Properties Properties containing additional information about your Application and can be built based on Themes, Plugins or Libraries. The Properties itself are immutable and only grant access to values after they were injected into the Package-class. Properties are added to the Package-class and automatically added as a Service to the primary Container. To access Properties in your application via Container you can use the class constant `Package::PROPERTIES`: ```php get(Package::PROPERTIES); return true; } } ``` A specific instance of your Properties will use the following data: | Properties method | Theme - style.css | Plugin - file header | Library - composer.json | | --- | --- | --- | --- | | Properties::author() | Author | Author | authors[0].name | | Properties::authorUri() | Author URI | Author URI | authors[0].homepage | | Properties::description() | Description | Description | description | | Properties::domainPath() | Domain Path | Domain Path | extra.modularity.domainPath | | Properties::name() | Theme Name | Plugin Name | extra.modularity.name | | Properties::textDomain() | Text Domain | Text Domain | extra.modularity.textDomain | | Properties::uri() | Theme URI | Plugin URI | extra.modularity.uri | | Properties::version() | Version | Version | version
extra.modularity.version | | Properties::requiresWp() | Requires at least | Requires at least | extra.modularity.requiresWp | | Properties::requiresPhp() | Requires PHP | Requires PHP | require.php
require-dev.php | | Properties::baseUrl() | WP_Theme::get_stylesheet_directory_uri() | plugins_url() | | | Properties::network() | | Network | | | Properties::status() | Status | | | | Properties::tags() | Tags | | keywords | | Properties::template() | Template | | | ### Accessing connected packages' properties When we have packages connected via `Package::connect()`, to access connected packages' properties, we could do that using a container key whose format is: `sprintf('%s.%s', $connectedPackage->name(), Package::PROPERTIES)`. ## PluginProperties Inside your Plugin you can use the following code to automatically generate Properties based on the [Plugins Header](https://developer.wordpress.org/reference/functions/get_plugin_data/): ```php withBaseUrl($url); ``` Please note that `withBaseUrl()` will only work if a base URL is not set already, otherwise it will throw an exception. Additionally, `LibraryProperties` will have the following public API: - `LibraryProperties::tags(): array` - returns a list of keywords defined in composer.json.