* @link https://book.cakephp.org/5/en/core-libraries/app.html#finding-paths-to-namespaces */ public static function path(string $type, ?string $plugin = null): array { if ($plugin === null) { return (array)Configure::read('App.paths.' . $type); } return match ($type) { 'templates' => [Plugin::templatePath($plugin)], 'locales' => [Plugin::path($plugin) . 'resources' . DIRECTORY_SEPARATOR . 'locales' . DIRECTORY_SEPARATOR], default => throw new CakeException(sprintf( 'Invalid type `%s`. Only path types `templates` and `locales` are supported for plugins.', $type, )) }; } /** * Gets the path to a class type in the application or a plugin. * * Example: * * ``` * App::classPath('Model/Table'); * ``` * * Will return the path for tables - e.g. `src/Model/Table/`. * * ``` * App::classPath('Model/Table', 'My/Plugin'); * ``` * * Will return the plugin based path for those. * * @param string $type Package type. * @param string|null $plugin Plugin name. * @return array */ public static function classPath(string $type, ?string $plugin = null): array { if ($plugin !== null) { return [ Plugin::classPath($plugin) . $type . DIRECTORY_SEPARATOR, ]; } return [APP . $type . DIRECTORY_SEPARATOR]; } /** * Returns the full path to a package inside the CakePHP core * * Usage: * * ``` * App::core('Cache/Engine'); * ``` * * Will return the full path to the cache engines package. * * @param string $type Package type. * @return array Full path to package */ public static function core(string $type): array { if ($type === 'templates') { return [CORE_PATH . 'templates' . DIRECTORY_SEPARATOR]; } return [CAKE . str_replace('/', DIRECTORY_SEPARATOR, $type) . DIRECTORY_SEPARATOR]; } }