php8.5
Home/ Manual/ yaf / yaf_loader/ Yaf_Loader::getNamespacePath

Yaf_Loader::getNamespacePath

PHP function Edit on GitHub ✎

(Yaf >=3.2.0)

Retrieve the library path of a class

Description

Yaf_Loader::getNamespacePath(string $class_name): string

Retrieve the library directory a class would be looked up in.

Parameters

class_name

The class name whose library directory is requested.

Return Values

The local library directory if the class belongs to a registered local namespace, otherwise the global library directory (falling back to the local one when the global one is not set).

Examples

Yaf_Loader::getNamespacePath example

php
<?php
$app    = new Yaf_Application(__DIR__ . "/conf/application.ini");
$loader = Yaf_Loader::getInstance();

$loader->registerLocalNamespace("Models");
$loader->setLibraryPath("/usr/local/share/yaf/library", true);

/* "Models" is a registered local namespace */
echo $loader->getNamespacePath("Models_Product"), PHP_EOL;

/* other classes fall back to the global library directory */
echo $loader->getNamespacePath("Vendor_Payment"), PHP_EOL;
?>

The above example will output something similar to:

output
/var/www/shop/application/library
/usr/local/share/yaf/library

See Also

  • Yaf_Loader::isLocalName
  • Yaf_Loader::getLibraryPath

Source: reference/yaf/yaf_loader/getnamespacepath.xml · from the official PHP manual (php/doc-en)